e1000_main.c 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that 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., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "e1000.h"
  21. /* Change Log
  22. * 6.0.58 4/20/05
  23. * o Accepted ethtool cleanup patch from Stephen Hemminger
  24. * 6.0.44+ 2/15/05
  25. * o applied Anton's patch to resolve tx hang in hardware
  26. * o Applied Andrew Mortons patch - e1000 stops working after resume
  27. */
  28. char e1000_driver_name[] = "e1000";
  29. static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
  30. #ifndef CONFIG_E1000_NAPI
  31. #define DRIVERNAPI
  32. #else
  33. #define DRIVERNAPI "-NAPI"
  34. #endif
  35. #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
  36. char e1000_driver_version[] = DRV_VERSION;
  37. static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
  38. /* e1000_pci_tbl - PCI Device ID Table
  39. *
  40. * Last entry must be all 0s
  41. *
  42. * Macro expands to...
  43. * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
  44. */
  45. static struct pci_device_id e1000_pci_tbl[] = {
  46. INTEL_E1000_ETHERNET_DEVICE(0x1000),
  47. INTEL_E1000_ETHERNET_DEVICE(0x1001),
  48. INTEL_E1000_ETHERNET_DEVICE(0x1004),
  49. INTEL_E1000_ETHERNET_DEVICE(0x1008),
  50. INTEL_E1000_ETHERNET_DEVICE(0x1009),
  51. INTEL_E1000_ETHERNET_DEVICE(0x100C),
  52. INTEL_E1000_ETHERNET_DEVICE(0x100D),
  53. INTEL_E1000_ETHERNET_DEVICE(0x100E),
  54. INTEL_E1000_ETHERNET_DEVICE(0x100F),
  55. INTEL_E1000_ETHERNET_DEVICE(0x1010),
  56. INTEL_E1000_ETHERNET_DEVICE(0x1011),
  57. INTEL_E1000_ETHERNET_DEVICE(0x1012),
  58. INTEL_E1000_ETHERNET_DEVICE(0x1013),
  59. INTEL_E1000_ETHERNET_DEVICE(0x1014),
  60. INTEL_E1000_ETHERNET_DEVICE(0x1015),
  61. INTEL_E1000_ETHERNET_DEVICE(0x1016),
  62. INTEL_E1000_ETHERNET_DEVICE(0x1017),
  63. INTEL_E1000_ETHERNET_DEVICE(0x1018),
  64. INTEL_E1000_ETHERNET_DEVICE(0x1019),
  65. INTEL_E1000_ETHERNET_DEVICE(0x101A),
  66. INTEL_E1000_ETHERNET_DEVICE(0x101D),
  67. INTEL_E1000_ETHERNET_DEVICE(0x101E),
  68. INTEL_E1000_ETHERNET_DEVICE(0x1026),
  69. INTEL_E1000_ETHERNET_DEVICE(0x1027),
  70. INTEL_E1000_ETHERNET_DEVICE(0x1028),
  71. INTEL_E1000_ETHERNET_DEVICE(0x105E),
  72. INTEL_E1000_ETHERNET_DEVICE(0x105F),
  73. INTEL_E1000_ETHERNET_DEVICE(0x1060),
  74. INTEL_E1000_ETHERNET_DEVICE(0x1075),
  75. INTEL_E1000_ETHERNET_DEVICE(0x1076),
  76. INTEL_E1000_ETHERNET_DEVICE(0x1077),
  77. INTEL_E1000_ETHERNET_DEVICE(0x1078),
  78. INTEL_E1000_ETHERNET_DEVICE(0x1079),
  79. INTEL_E1000_ETHERNET_DEVICE(0x107A),
  80. INTEL_E1000_ETHERNET_DEVICE(0x107B),
  81. INTEL_E1000_ETHERNET_DEVICE(0x107C),
  82. INTEL_E1000_ETHERNET_DEVICE(0x107D),
  83. INTEL_E1000_ETHERNET_DEVICE(0x107E),
  84. INTEL_E1000_ETHERNET_DEVICE(0x107F),
  85. INTEL_E1000_ETHERNET_DEVICE(0x108A),
  86. INTEL_E1000_ETHERNET_DEVICE(0x108B),
  87. INTEL_E1000_ETHERNET_DEVICE(0x108C),
  88. INTEL_E1000_ETHERNET_DEVICE(0x1099),
  89. INTEL_E1000_ETHERNET_DEVICE(0x109A),
  90. INTEL_E1000_ETHERNET_DEVICE(0x10B5),
  91. /* required last entry */
  92. {0,}
  93. };
  94. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  95. int e1000_up(struct e1000_adapter *adapter);
  96. void e1000_down(struct e1000_adapter *adapter);
  97. void e1000_reset(struct e1000_adapter *adapter);
  98. int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
  99. int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
  100. int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
  101. void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
  102. void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
  103. static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
  104. struct e1000_tx_ring *txdr);
  105. static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
  106. struct e1000_rx_ring *rxdr);
  107. static void e1000_free_tx_resources(struct e1000_adapter *adapter,
  108. struct e1000_tx_ring *tx_ring);
  109. static void e1000_free_rx_resources(struct e1000_adapter *adapter,
  110. struct e1000_rx_ring *rx_ring);
  111. void e1000_update_stats(struct e1000_adapter *adapter);
  112. /* Local Function Prototypes */
  113. static int e1000_init_module(void);
  114. static void e1000_exit_module(void);
  115. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  116. static void __devexit e1000_remove(struct pci_dev *pdev);
  117. static int e1000_alloc_queues(struct e1000_adapter *adapter);
  118. #ifdef CONFIG_E1000_MQ
  119. static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
  120. #endif
  121. static int e1000_sw_init(struct e1000_adapter *adapter);
  122. static int e1000_open(struct net_device *netdev);
  123. static int e1000_close(struct net_device *netdev);
  124. static void e1000_configure_tx(struct e1000_adapter *adapter);
  125. static void e1000_configure_rx(struct e1000_adapter *adapter);
  126. static void e1000_setup_rctl(struct e1000_adapter *adapter);
  127. static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
  128. static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
  129. static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
  130. struct e1000_tx_ring *tx_ring);
  131. static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
  132. struct e1000_rx_ring *rx_ring);
  133. static void e1000_set_multi(struct net_device *netdev);
  134. static void e1000_update_phy_info(unsigned long data);
  135. static void e1000_watchdog(unsigned long data);
  136. static void e1000_watchdog_task(struct e1000_adapter *adapter);
  137. static void e1000_82547_tx_fifo_stall(unsigned long data);
  138. static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  139. static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
  140. static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
  141. static int e1000_set_mac(struct net_device *netdev, void *p);
  142. static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
  143. static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
  144. struct e1000_tx_ring *tx_ring);
  145. #ifdef CONFIG_E1000_NAPI
  146. static int e1000_clean(struct net_device *poll_dev, int *budget);
  147. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  148. struct e1000_rx_ring *rx_ring,
  149. int *work_done, int work_to_do);
  150. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  151. struct e1000_rx_ring *rx_ring,
  152. int *work_done, int work_to_do);
  153. #else
  154. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  155. struct e1000_rx_ring *rx_ring);
  156. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  157. struct e1000_rx_ring *rx_ring);
  158. #endif
  159. static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  160. struct e1000_rx_ring *rx_ring,
  161. int cleaned_count);
  162. static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  163. struct e1000_rx_ring *rx_ring,
  164. int cleaned_count);
  165. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  166. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  167. int cmd);
  168. void e1000_set_ethtool_ops(struct net_device *netdev);
  169. static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
  170. static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
  171. static void e1000_tx_timeout(struct net_device *dev);
  172. static void e1000_tx_timeout_task(struct net_device *dev);
  173. static void e1000_smartspeed(struct e1000_adapter *adapter);
  174. static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
  175. struct sk_buff *skb);
  176. static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
  177. static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
  178. static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
  179. static void e1000_restore_vlan(struct e1000_adapter *adapter);
  180. #ifdef CONFIG_PM
  181. static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
  182. static int e1000_resume(struct pci_dev *pdev);
  183. #endif
  184. #ifdef CONFIG_NET_POLL_CONTROLLER
  185. /* for netdump / net console */
  186. static void e1000_netpoll (struct net_device *netdev);
  187. #endif
  188. #ifdef CONFIG_E1000_MQ
  189. /* for multiple Rx queues */
  190. void e1000_rx_schedule(void *data);
  191. #endif
  192. /* Exported from other modules */
  193. extern void e1000_check_options(struct e1000_adapter *adapter);
  194. static struct pci_driver e1000_driver = {
  195. .name = e1000_driver_name,
  196. .id_table = e1000_pci_tbl,
  197. .probe = e1000_probe,
  198. .remove = __devexit_p(e1000_remove),
  199. /* Power Managment Hooks */
  200. #ifdef CONFIG_PM
  201. .suspend = e1000_suspend,
  202. .resume = e1000_resume
  203. #endif
  204. };
  205. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  206. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  207. MODULE_LICENSE("GPL");
  208. MODULE_VERSION(DRV_VERSION);
  209. static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  210. module_param(debug, int, 0);
  211. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  212. /**
  213. * e1000_init_module - Driver Registration Routine
  214. *
  215. * e1000_init_module is the first routine called when the driver is
  216. * loaded. All it does is register with the PCI subsystem.
  217. **/
  218. static int __init
  219. e1000_init_module(void)
  220. {
  221. int ret;
  222. printk(KERN_INFO "%s - version %s\n",
  223. e1000_driver_string, e1000_driver_version);
  224. printk(KERN_INFO "%s\n", e1000_copyright);
  225. ret = pci_module_init(&e1000_driver);
  226. return ret;
  227. }
  228. module_init(e1000_init_module);
  229. /**
  230. * e1000_exit_module - Driver Exit Cleanup Routine
  231. *
  232. * e1000_exit_module is called just before the driver is removed
  233. * from memory.
  234. **/
  235. static void __exit
  236. e1000_exit_module(void)
  237. {
  238. pci_unregister_driver(&e1000_driver);
  239. }
  240. module_exit(e1000_exit_module);
  241. /**
  242. * e1000_irq_disable - Mask off interrupt generation on the NIC
  243. * @adapter: board private structure
  244. **/
  245. static inline void
  246. e1000_irq_disable(struct e1000_adapter *adapter)
  247. {
  248. atomic_inc(&adapter->irq_sem);
  249. E1000_WRITE_REG(&adapter->hw, IMC, ~0);
  250. E1000_WRITE_FLUSH(&adapter->hw);
  251. synchronize_irq(adapter->pdev->irq);
  252. }
  253. /**
  254. * e1000_irq_enable - Enable default interrupt generation settings
  255. * @adapter: board private structure
  256. **/
  257. static inline void
  258. e1000_irq_enable(struct e1000_adapter *adapter)
  259. {
  260. if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
  261. E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
  262. E1000_WRITE_FLUSH(&adapter->hw);
  263. }
  264. }
  265. static void
  266. e1000_update_mng_vlan(struct e1000_adapter *adapter)
  267. {
  268. struct net_device *netdev = adapter->netdev;
  269. uint16_t vid = adapter->hw.mng_cookie.vlan_id;
  270. uint16_t old_vid = adapter->mng_vlan_id;
  271. if(adapter->vlgrp) {
  272. if(!adapter->vlgrp->vlan_devices[vid]) {
  273. if(adapter->hw.mng_cookie.status &
  274. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
  275. e1000_vlan_rx_add_vid(netdev, vid);
  276. adapter->mng_vlan_id = vid;
  277. } else
  278. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  279. if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
  280. (vid != old_vid) &&
  281. !adapter->vlgrp->vlan_devices[old_vid])
  282. e1000_vlan_rx_kill_vid(netdev, old_vid);
  283. }
  284. }
  285. }
  286. /**
  287. * e1000_release_hw_control - release control of the h/w to f/w
  288. * @adapter: address of board private structure
  289. *
  290. * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  291. * For ASF and Pass Through versions of f/w this means that the
  292. * driver is no longer loaded. For AMT version (only with 82573) i
  293. * of the f/w this means that the netowrk i/f is closed.
  294. *
  295. **/
  296. static inline void
  297. e1000_release_hw_control(struct e1000_adapter *adapter)
  298. {
  299. uint32_t ctrl_ext;
  300. uint32_t swsm;
  301. /* Let firmware taken over control of h/w */
  302. switch (adapter->hw.mac_type) {
  303. case e1000_82571:
  304. case e1000_82572:
  305. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  306. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  307. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  308. break;
  309. case e1000_82573:
  310. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  311. E1000_WRITE_REG(&adapter->hw, SWSM,
  312. swsm & ~E1000_SWSM_DRV_LOAD);
  313. default:
  314. break;
  315. }
  316. }
  317. /**
  318. * e1000_get_hw_control - get control of the h/w from f/w
  319. * @adapter: address of board private structure
  320. *
  321. * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  322. * For ASF and Pass Through versions of f/w this means that
  323. * the driver is loaded. For AMT version (only with 82573)
  324. * of the f/w this means that the netowrk i/f is open.
  325. *
  326. **/
  327. static inline void
  328. e1000_get_hw_control(struct e1000_adapter *adapter)
  329. {
  330. uint32_t ctrl_ext;
  331. uint32_t swsm;
  332. /* Let firmware know the driver has taken over */
  333. switch (adapter->hw.mac_type) {
  334. case e1000_82571:
  335. case e1000_82572:
  336. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  337. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  338. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  339. break;
  340. case e1000_82573:
  341. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  342. E1000_WRITE_REG(&adapter->hw, SWSM,
  343. swsm | E1000_SWSM_DRV_LOAD);
  344. break;
  345. default:
  346. break;
  347. }
  348. }
  349. int
  350. e1000_up(struct e1000_adapter *adapter)
  351. {
  352. struct net_device *netdev = adapter->netdev;
  353. int i, err;
  354. /* hardware has been reset, we need to reload some things */
  355. /* Reset the PHY if it was previously powered down */
  356. if(adapter->hw.media_type == e1000_media_type_copper) {
  357. uint16_t mii_reg;
  358. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  359. if(mii_reg & MII_CR_POWER_DOWN)
  360. e1000_phy_reset(&adapter->hw);
  361. }
  362. e1000_set_multi(netdev);
  363. e1000_restore_vlan(adapter);
  364. e1000_configure_tx(adapter);
  365. e1000_setup_rctl(adapter);
  366. e1000_configure_rx(adapter);
  367. /* call E1000_DESC_UNUSED which always leaves
  368. * at least 1 descriptor unused to make sure
  369. * next_to_use != next_to_clean */
  370. for (i = 0; i < adapter->num_rx_queues; i++) {
  371. struct e1000_rx_ring *ring = &adapter->rx_ring[i];
  372. adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
  373. }
  374. #ifdef CONFIG_PCI_MSI
  375. if(adapter->hw.mac_type > e1000_82547_rev_2) {
  376. adapter->have_msi = TRUE;
  377. if((err = pci_enable_msi(adapter->pdev))) {
  378. DPRINTK(PROBE, ERR,
  379. "Unable to allocate MSI interrupt Error: %d\n", err);
  380. adapter->have_msi = FALSE;
  381. }
  382. }
  383. #endif
  384. if((err = request_irq(adapter->pdev->irq, &e1000_intr,
  385. SA_SHIRQ | SA_SAMPLE_RANDOM,
  386. netdev->name, netdev))) {
  387. DPRINTK(PROBE, ERR,
  388. "Unable to allocate interrupt Error: %d\n", err);
  389. return err;
  390. }
  391. #ifdef CONFIG_E1000_MQ
  392. e1000_setup_queue_mapping(adapter);
  393. #endif
  394. adapter->tx_queue_len = netdev->tx_queue_len;
  395. mod_timer(&adapter->watchdog_timer, jiffies);
  396. #ifdef CONFIG_E1000_NAPI
  397. netif_poll_enable(netdev);
  398. #endif
  399. e1000_irq_enable(adapter);
  400. return 0;
  401. }
  402. void
  403. e1000_down(struct e1000_adapter *adapter)
  404. {
  405. struct net_device *netdev = adapter->netdev;
  406. boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
  407. e1000_check_mng_mode(&adapter->hw);
  408. e1000_irq_disable(adapter);
  409. #ifdef CONFIG_E1000_MQ
  410. while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
  411. #endif
  412. free_irq(adapter->pdev->irq, netdev);
  413. #ifdef CONFIG_PCI_MSI
  414. if(adapter->hw.mac_type > e1000_82547_rev_2 &&
  415. adapter->have_msi == TRUE)
  416. pci_disable_msi(adapter->pdev);
  417. #endif
  418. del_timer_sync(&adapter->tx_fifo_stall_timer);
  419. del_timer_sync(&adapter->watchdog_timer);
  420. del_timer_sync(&adapter->phy_info_timer);
  421. #ifdef CONFIG_E1000_NAPI
  422. netif_poll_disable(netdev);
  423. #endif
  424. netdev->tx_queue_len = adapter->tx_queue_len;
  425. adapter->link_speed = 0;
  426. adapter->link_duplex = 0;
  427. netif_carrier_off(netdev);
  428. netif_stop_queue(netdev);
  429. e1000_reset(adapter);
  430. e1000_clean_all_tx_rings(adapter);
  431. e1000_clean_all_rx_rings(adapter);
  432. /* Power down the PHY so no link is implied when interface is down *
  433. * The PHY cannot be powered down if any of the following is TRUE *
  434. * (a) WoL is enabled
  435. * (b) AMT is active
  436. * (c) SoL/IDER session is active */
  437. if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
  438. adapter->hw.media_type == e1000_media_type_copper &&
  439. !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
  440. !mng_mode_enabled &&
  441. !e1000_check_phy_reset_block(&adapter->hw)) {
  442. uint16_t mii_reg;
  443. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  444. mii_reg |= MII_CR_POWER_DOWN;
  445. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
  446. mdelay(1);
  447. }
  448. }
  449. void
  450. e1000_reset(struct e1000_adapter *adapter)
  451. {
  452. uint32_t pba, manc;
  453. uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
  454. /* Repartition Pba for greater than 9k mtu
  455. * To take effect CTRL.RST is required.
  456. */
  457. switch (adapter->hw.mac_type) {
  458. case e1000_82547:
  459. case e1000_82547_rev_2:
  460. pba = E1000_PBA_30K;
  461. break;
  462. case e1000_82571:
  463. case e1000_82572:
  464. pba = E1000_PBA_38K;
  465. break;
  466. case e1000_82573:
  467. pba = E1000_PBA_12K;
  468. break;
  469. default:
  470. pba = E1000_PBA_48K;
  471. break;
  472. }
  473. if((adapter->hw.mac_type != e1000_82573) &&
  474. (adapter->netdev->mtu > E1000_RXBUFFER_8192))
  475. pba -= 8; /* allocate more FIFO for Tx */
  476. if(adapter->hw.mac_type == e1000_82547) {
  477. adapter->tx_fifo_head = 0;
  478. adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
  479. adapter->tx_fifo_size =
  480. (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
  481. atomic_set(&adapter->tx_fifo_stall, 0);
  482. }
  483. E1000_WRITE_REG(&adapter->hw, PBA, pba);
  484. /* flow control settings */
  485. /* Set the FC high water mark to 90% of the FIFO size.
  486. * Required to clear last 3 LSB */
  487. fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
  488. adapter->hw.fc_high_water = fc_high_water_mark;
  489. adapter->hw.fc_low_water = fc_high_water_mark - 8;
  490. adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
  491. adapter->hw.fc_send_xon = 1;
  492. adapter->hw.fc = adapter->hw.original_fc;
  493. /* Allow time for pending master requests to run */
  494. e1000_reset_hw(&adapter->hw);
  495. if(adapter->hw.mac_type >= e1000_82544)
  496. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  497. if(e1000_init_hw(&adapter->hw))
  498. DPRINTK(PROBE, ERR, "Hardware Error\n");
  499. e1000_update_mng_vlan(adapter);
  500. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  501. E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
  502. e1000_reset_adaptive(&adapter->hw);
  503. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  504. if (adapter->en_mng_pt) {
  505. manc = E1000_READ_REG(&adapter->hw, MANC);
  506. manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
  507. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  508. }
  509. }
  510. /**
  511. * e1000_probe - Device Initialization Routine
  512. * @pdev: PCI device information struct
  513. * @ent: entry in e1000_pci_tbl
  514. *
  515. * Returns 0 on success, negative on failure
  516. *
  517. * e1000_probe initializes an adapter identified by a pci_dev structure.
  518. * The OS initialization, configuring of the adapter private structure,
  519. * and a hardware reset occur.
  520. **/
  521. static int __devinit
  522. e1000_probe(struct pci_dev *pdev,
  523. const struct pci_device_id *ent)
  524. {
  525. struct net_device *netdev;
  526. struct e1000_adapter *adapter;
  527. unsigned long mmio_start, mmio_len;
  528. static int cards_found = 0;
  529. int i, err, pci_using_dac;
  530. uint16_t eeprom_data;
  531. uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
  532. if((err = pci_enable_device(pdev)))
  533. return err;
  534. if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
  535. pci_using_dac = 1;
  536. } else {
  537. if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
  538. E1000_ERR("No usable DMA configuration, aborting\n");
  539. return err;
  540. }
  541. pci_using_dac = 0;
  542. }
  543. if((err = pci_request_regions(pdev, e1000_driver_name)))
  544. return err;
  545. pci_set_master(pdev);
  546. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  547. if(!netdev) {
  548. err = -ENOMEM;
  549. goto err_alloc_etherdev;
  550. }
  551. SET_MODULE_OWNER(netdev);
  552. SET_NETDEV_DEV(netdev, &pdev->dev);
  553. pci_set_drvdata(pdev, netdev);
  554. adapter = netdev_priv(netdev);
  555. adapter->netdev = netdev;
  556. adapter->pdev = pdev;
  557. adapter->hw.back = adapter;
  558. adapter->msg_enable = (1 << debug) - 1;
  559. mmio_start = pci_resource_start(pdev, BAR_0);
  560. mmio_len = pci_resource_len(pdev, BAR_0);
  561. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  562. if(!adapter->hw.hw_addr) {
  563. err = -EIO;
  564. goto err_ioremap;
  565. }
  566. for(i = BAR_1; i <= BAR_5; i++) {
  567. if(pci_resource_len(pdev, i) == 0)
  568. continue;
  569. if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  570. adapter->hw.io_base = pci_resource_start(pdev, i);
  571. break;
  572. }
  573. }
  574. netdev->open = &e1000_open;
  575. netdev->stop = &e1000_close;
  576. netdev->hard_start_xmit = &e1000_xmit_frame;
  577. netdev->get_stats = &e1000_get_stats;
  578. netdev->set_multicast_list = &e1000_set_multi;
  579. netdev->set_mac_address = &e1000_set_mac;
  580. netdev->change_mtu = &e1000_change_mtu;
  581. netdev->do_ioctl = &e1000_ioctl;
  582. e1000_set_ethtool_ops(netdev);
  583. netdev->tx_timeout = &e1000_tx_timeout;
  584. netdev->watchdog_timeo = 5 * HZ;
  585. #ifdef CONFIG_E1000_NAPI
  586. netdev->poll = &e1000_clean;
  587. netdev->weight = 64;
  588. #endif
  589. netdev->vlan_rx_register = e1000_vlan_rx_register;
  590. netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
  591. netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
  592. #ifdef CONFIG_NET_POLL_CONTROLLER
  593. netdev->poll_controller = e1000_netpoll;
  594. #endif
  595. strcpy(netdev->name, pci_name(pdev));
  596. netdev->mem_start = mmio_start;
  597. netdev->mem_end = mmio_start + mmio_len;
  598. netdev->base_addr = adapter->hw.io_base;
  599. adapter->bd_number = cards_found;
  600. /* setup the private structure */
  601. if((err = e1000_sw_init(adapter)))
  602. goto err_sw_init;
  603. if((err = e1000_check_phy_reset_block(&adapter->hw)))
  604. DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
  605. if(adapter->hw.mac_type >= e1000_82543) {
  606. netdev->features = NETIF_F_SG |
  607. NETIF_F_HW_CSUM |
  608. NETIF_F_HW_VLAN_TX |
  609. NETIF_F_HW_VLAN_RX |
  610. NETIF_F_HW_VLAN_FILTER;
  611. }
  612. #ifdef NETIF_F_TSO
  613. if((adapter->hw.mac_type >= e1000_82544) &&
  614. (adapter->hw.mac_type != e1000_82547))
  615. netdev->features |= NETIF_F_TSO;
  616. #ifdef NETIF_F_TSO_IPV6
  617. if(adapter->hw.mac_type > e1000_82547_rev_2)
  618. netdev->features |= NETIF_F_TSO_IPV6;
  619. #endif
  620. #endif
  621. if(pci_using_dac)
  622. netdev->features |= NETIF_F_HIGHDMA;
  623. /* hard_start_xmit is safe against parallel locking */
  624. netdev->features |= NETIF_F_LLTX;
  625. adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
  626. /* before reading the EEPROM, reset the controller to
  627. * put the device in a known good starting state */
  628. e1000_reset_hw(&adapter->hw);
  629. /* make sure the EEPROM is good */
  630. if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
  631. DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
  632. err = -EIO;
  633. goto err_eeprom;
  634. }
  635. /* copy the MAC address out of the EEPROM */
  636. if(e1000_read_mac_addr(&adapter->hw))
  637. DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
  638. memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
  639. memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
  640. if(!is_valid_ether_addr(netdev->perm_addr)) {
  641. DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
  642. err = -EIO;
  643. goto err_eeprom;
  644. }
  645. e1000_read_part_num(&adapter->hw, &(adapter->part_num));
  646. e1000_get_bus_info(&adapter->hw);
  647. init_timer(&adapter->tx_fifo_stall_timer);
  648. adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
  649. adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
  650. init_timer(&adapter->watchdog_timer);
  651. adapter->watchdog_timer.function = &e1000_watchdog;
  652. adapter->watchdog_timer.data = (unsigned long) adapter;
  653. INIT_WORK(&adapter->watchdog_task,
  654. (void (*)(void *))e1000_watchdog_task, adapter);
  655. init_timer(&adapter->phy_info_timer);
  656. adapter->phy_info_timer.function = &e1000_update_phy_info;
  657. adapter->phy_info_timer.data = (unsigned long) adapter;
  658. INIT_WORK(&adapter->tx_timeout_task,
  659. (void (*)(void *))e1000_tx_timeout_task, netdev);
  660. /* we're going to reset, so assume we have no link for now */
  661. netif_carrier_off(netdev);
  662. netif_stop_queue(netdev);
  663. e1000_check_options(adapter);
  664. /* Initial Wake on LAN setting
  665. * If APM wake is enabled in the EEPROM,
  666. * enable the ACPI Magic Packet filter
  667. */
  668. switch(adapter->hw.mac_type) {
  669. case e1000_82542_rev2_0:
  670. case e1000_82542_rev2_1:
  671. case e1000_82543:
  672. break;
  673. case e1000_82544:
  674. e1000_read_eeprom(&adapter->hw,
  675. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  676. eeprom_apme_mask = E1000_EEPROM_82544_APM;
  677. break;
  678. case e1000_82546:
  679. case e1000_82546_rev_3:
  680. case e1000_82571:
  681. if(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
  682. e1000_read_eeprom(&adapter->hw,
  683. EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  684. break;
  685. }
  686. /* Fall Through */
  687. default:
  688. e1000_read_eeprom(&adapter->hw,
  689. EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  690. break;
  691. }
  692. if(eeprom_data & eeprom_apme_mask)
  693. adapter->wol |= E1000_WUFC_MAG;
  694. /* reset the hardware with the new settings */
  695. e1000_reset(adapter);
  696. /* If the controller is 82573 and f/w is AMT, do not set
  697. * DRV_LOAD until the interface is up. For all other cases,
  698. * let the f/w know that the h/w is now under the control
  699. * of the driver. */
  700. if (adapter->hw.mac_type != e1000_82573 ||
  701. !e1000_check_mng_mode(&adapter->hw))
  702. e1000_get_hw_control(adapter);
  703. strcpy(netdev->name, "eth%d");
  704. if((err = register_netdev(netdev)))
  705. goto err_register;
  706. DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
  707. cards_found++;
  708. return 0;
  709. err_register:
  710. err_sw_init:
  711. err_eeprom:
  712. iounmap(adapter->hw.hw_addr);
  713. err_ioremap:
  714. free_netdev(netdev);
  715. err_alloc_etherdev:
  716. pci_release_regions(pdev);
  717. return err;
  718. }
  719. /**
  720. * e1000_remove - Device Removal Routine
  721. * @pdev: PCI device information struct
  722. *
  723. * e1000_remove is called by the PCI subsystem to alert the driver
  724. * that it should release a PCI device. The could be caused by a
  725. * Hot-Plug event, or because the driver is going to be removed from
  726. * memory.
  727. **/
  728. static void __devexit
  729. e1000_remove(struct pci_dev *pdev)
  730. {
  731. struct net_device *netdev = pci_get_drvdata(pdev);
  732. struct e1000_adapter *adapter = netdev_priv(netdev);
  733. uint32_t manc;
  734. #ifdef CONFIG_E1000_NAPI
  735. int i;
  736. #endif
  737. flush_scheduled_work();
  738. if(adapter->hw.mac_type >= e1000_82540 &&
  739. adapter->hw.media_type == e1000_media_type_copper) {
  740. manc = E1000_READ_REG(&adapter->hw, MANC);
  741. if(manc & E1000_MANC_SMBUS_EN) {
  742. manc |= E1000_MANC_ARP_EN;
  743. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  744. }
  745. }
  746. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  747. * would have already happened in close and is redundant. */
  748. e1000_release_hw_control(adapter);
  749. unregister_netdev(netdev);
  750. #ifdef CONFIG_E1000_NAPI
  751. for (i = 0; i < adapter->num_rx_queues; i++)
  752. __dev_put(&adapter->polling_netdev[i]);
  753. #endif
  754. if(!e1000_check_phy_reset_block(&adapter->hw))
  755. e1000_phy_hw_reset(&adapter->hw);
  756. kfree(adapter->tx_ring);
  757. kfree(adapter->rx_ring);
  758. #ifdef CONFIG_E1000_NAPI
  759. kfree(adapter->polling_netdev);
  760. #endif
  761. iounmap(adapter->hw.hw_addr);
  762. pci_release_regions(pdev);
  763. #ifdef CONFIG_E1000_MQ
  764. free_percpu(adapter->cpu_netdev);
  765. free_percpu(adapter->cpu_tx_ring);
  766. #endif
  767. free_netdev(netdev);
  768. pci_disable_device(pdev);
  769. }
  770. /**
  771. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  772. * @adapter: board private structure to initialize
  773. *
  774. * e1000_sw_init initializes the Adapter private data structure.
  775. * Fields are initialized based on PCI device information and
  776. * OS network device settings (MTU size).
  777. **/
  778. static int __devinit
  779. e1000_sw_init(struct e1000_adapter *adapter)
  780. {
  781. struct e1000_hw *hw = &adapter->hw;
  782. struct net_device *netdev = adapter->netdev;
  783. struct pci_dev *pdev = adapter->pdev;
  784. #ifdef CONFIG_E1000_NAPI
  785. int i;
  786. #endif
  787. /* PCI config space info */
  788. hw->vendor_id = pdev->vendor;
  789. hw->device_id = pdev->device;
  790. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  791. hw->subsystem_id = pdev->subsystem_device;
  792. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  793. pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
  794. adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  795. adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
  796. hw->max_frame_size = netdev->mtu +
  797. ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  798. hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
  799. /* identify the MAC */
  800. if(e1000_set_mac_type(hw)) {
  801. DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
  802. return -EIO;
  803. }
  804. /* initialize eeprom parameters */
  805. if(e1000_init_eeprom_params(hw)) {
  806. E1000_ERR("EEPROM initialization failed\n");
  807. return -EIO;
  808. }
  809. switch(hw->mac_type) {
  810. default:
  811. break;
  812. case e1000_82541:
  813. case e1000_82547:
  814. case e1000_82541_rev_2:
  815. case e1000_82547_rev_2:
  816. hw->phy_init_script = 1;
  817. break;
  818. }
  819. e1000_set_media_type(hw);
  820. hw->wait_autoneg_complete = FALSE;
  821. hw->tbi_compatibility_en = TRUE;
  822. hw->adaptive_ifs = TRUE;
  823. /* Copper options */
  824. if(hw->media_type == e1000_media_type_copper) {
  825. hw->mdix = AUTO_ALL_MODES;
  826. hw->disable_polarity_correction = FALSE;
  827. hw->master_slave = E1000_MASTER_SLAVE;
  828. }
  829. #ifdef CONFIG_E1000_MQ
  830. /* Number of supported queues */
  831. switch (hw->mac_type) {
  832. case e1000_82571:
  833. case e1000_82572:
  834. /* These controllers support 2 tx queues, but with a single
  835. * qdisc implementation, multiple tx queues aren't quite as
  836. * interesting. If we can find a logical way of mapping
  837. * flows to a queue, then perhaps we can up the num_tx_queue
  838. * count back to its default. Until then, we run the risk of
  839. * terrible performance due to SACK overload. */
  840. adapter->num_tx_queues = 1;
  841. adapter->num_rx_queues = 2;
  842. break;
  843. default:
  844. adapter->num_tx_queues = 1;
  845. adapter->num_rx_queues = 1;
  846. break;
  847. }
  848. adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
  849. adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
  850. DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
  851. adapter->num_rx_queues,
  852. ((adapter->num_rx_queues == 1)
  853. ? ((num_online_cpus() > 1)
  854. ? "(due to unsupported feature in current adapter)"
  855. : "(due to unsupported system configuration)")
  856. : ""));
  857. DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
  858. adapter->num_tx_queues);
  859. #else
  860. adapter->num_tx_queues = 1;
  861. adapter->num_rx_queues = 1;
  862. #endif
  863. if (e1000_alloc_queues(adapter)) {
  864. DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
  865. return -ENOMEM;
  866. }
  867. #ifdef CONFIG_E1000_NAPI
  868. for (i = 0; i < adapter->num_rx_queues; i++) {
  869. adapter->polling_netdev[i].priv = adapter;
  870. adapter->polling_netdev[i].poll = &e1000_clean;
  871. adapter->polling_netdev[i].weight = 64;
  872. dev_hold(&adapter->polling_netdev[i]);
  873. set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
  874. }
  875. spin_lock_init(&adapter->tx_queue_lock);
  876. #endif
  877. atomic_set(&adapter->irq_sem, 1);
  878. spin_lock_init(&adapter->stats_lock);
  879. return 0;
  880. }
  881. /**
  882. * e1000_alloc_queues - Allocate memory for all rings
  883. * @adapter: board private structure to initialize
  884. *
  885. * We allocate one ring per queue at run-time since we don't know the
  886. * number of queues at compile-time. The polling_netdev array is
  887. * intended for Multiqueue, but should work fine with a single queue.
  888. **/
  889. static int __devinit
  890. e1000_alloc_queues(struct e1000_adapter *adapter)
  891. {
  892. int size;
  893. size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
  894. adapter->tx_ring = kmalloc(size, GFP_KERNEL);
  895. if (!adapter->tx_ring)
  896. return -ENOMEM;
  897. memset(adapter->tx_ring, 0, size);
  898. size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
  899. adapter->rx_ring = kmalloc(size, GFP_KERNEL);
  900. if (!adapter->rx_ring) {
  901. kfree(adapter->tx_ring);
  902. return -ENOMEM;
  903. }
  904. memset(adapter->rx_ring, 0, size);
  905. #ifdef CONFIG_E1000_NAPI
  906. size = sizeof(struct net_device) * adapter->num_rx_queues;
  907. adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
  908. if (!adapter->polling_netdev) {
  909. kfree(adapter->tx_ring);
  910. kfree(adapter->rx_ring);
  911. return -ENOMEM;
  912. }
  913. memset(adapter->polling_netdev, 0, size);
  914. #endif
  915. #ifdef CONFIG_E1000_MQ
  916. adapter->rx_sched_call_data.func = e1000_rx_schedule;
  917. adapter->rx_sched_call_data.info = adapter->netdev;
  918. adapter->cpu_netdev = alloc_percpu(struct net_device *);
  919. adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
  920. #endif
  921. return E1000_SUCCESS;
  922. }
  923. #ifdef CONFIG_E1000_MQ
  924. static void __devinit
  925. e1000_setup_queue_mapping(struct e1000_adapter *adapter)
  926. {
  927. int i, cpu;
  928. adapter->rx_sched_call_data.func = e1000_rx_schedule;
  929. adapter->rx_sched_call_data.info = adapter->netdev;
  930. cpus_clear(adapter->rx_sched_call_data.cpumask);
  931. adapter->cpu_netdev = alloc_percpu(struct net_device *);
  932. adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
  933. lock_cpu_hotplug();
  934. i = 0;
  935. for_each_online_cpu(cpu) {
  936. *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
  937. /* This is incomplete because we'd like to assign separate
  938. * physical cpus to these netdev polling structures and
  939. * avoid saturating a subset of cpus.
  940. */
  941. if (i < adapter->num_rx_queues) {
  942. *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
  943. adapter->rx_ring[i].cpu = cpu;
  944. cpu_set(cpu, adapter->cpumask);
  945. } else
  946. *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
  947. i++;
  948. }
  949. unlock_cpu_hotplug();
  950. }
  951. #endif
  952. /**
  953. * e1000_open - Called when a network interface is made active
  954. * @netdev: network interface device structure
  955. *
  956. * Returns 0 on success, negative value on failure
  957. *
  958. * The open entry point is called when a network interface is made
  959. * active by the system (IFF_UP). At this point all resources needed
  960. * for transmit and receive operations are allocated, the interrupt
  961. * handler is registered with the OS, the watchdog timer is started,
  962. * and the stack is notified that the interface is ready.
  963. **/
  964. static int
  965. e1000_open(struct net_device *netdev)
  966. {
  967. struct e1000_adapter *adapter = netdev_priv(netdev);
  968. int err;
  969. /* allocate transmit descriptors */
  970. if ((err = e1000_setup_all_tx_resources(adapter)))
  971. goto err_setup_tx;
  972. /* allocate receive descriptors */
  973. if ((err = e1000_setup_all_rx_resources(adapter)))
  974. goto err_setup_rx;
  975. if((err = e1000_up(adapter)))
  976. goto err_up;
  977. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  978. if((adapter->hw.mng_cookie.status &
  979. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
  980. e1000_update_mng_vlan(adapter);
  981. }
  982. /* If AMT is enabled, let the firmware know that the network
  983. * interface is now open */
  984. if (adapter->hw.mac_type == e1000_82573 &&
  985. e1000_check_mng_mode(&adapter->hw))
  986. e1000_get_hw_control(adapter);
  987. return E1000_SUCCESS;
  988. err_up:
  989. e1000_free_all_rx_resources(adapter);
  990. err_setup_rx:
  991. e1000_free_all_tx_resources(adapter);
  992. err_setup_tx:
  993. e1000_reset(adapter);
  994. return err;
  995. }
  996. /**
  997. * e1000_close - Disables a network interface
  998. * @netdev: network interface device structure
  999. *
  1000. * Returns 0, this is not allowed to fail
  1001. *
  1002. * The close entry point is called when an interface is de-activated
  1003. * by the OS. The hardware is still under the drivers control, but
  1004. * needs to be disabled. A global MAC reset is issued to stop the
  1005. * hardware, and all transmit and receive resources are freed.
  1006. **/
  1007. static int
  1008. e1000_close(struct net_device *netdev)
  1009. {
  1010. struct e1000_adapter *adapter = netdev_priv(netdev);
  1011. e1000_down(adapter);
  1012. e1000_free_all_tx_resources(adapter);
  1013. e1000_free_all_rx_resources(adapter);
  1014. if((adapter->hw.mng_cookie.status &
  1015. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
  1016. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  1017. }
  1018. /* If AMT is enabled, let the firmware know that the network
  1019. * interface is now closed */
  1020. if (adapter->hw.mac_type == e1000_82573 &&
  1021. e1000_check_mng_mode(&adapter->hw))
  1022. e1000_release_hw_control(adapter);
  1023. return 0;
  1024. }
  1025. /**
  1026. * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
  1027. * @adapter: address of board private structure
  1028. * @start: address of beginning of memory
  1029. * @len: length of memory
  1030. **/
  1031. static inline boolean_t
  1032. e1000_check_64k_bound(struct e1000_adapter *adapter,
  1033. void *start, unsigned long len)
  1034. {
  1035. unsigned long begin = (unsigned long) start;
  1036. unsigned long end = begin + len;
  1037. /* First rev 82545 and 82546 need to not allow any memory
  1038. * write location to cross 64k boundary due to errata 23 */
  1039. if (adapter->hw.mac_type == e1000_82545 ||
  1040. adapter->hw.mac_type == e1000_82546) {
  1041. return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
  1042. }
  1043. return TRUE;
  1044. }
  1045. /**
  1046. * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
  1047. * @adapter: board private structure
  1048. * @txdr: tx descriptor ring (for a specific queue) to setup
  1049. *
  1050. * Return 0 on success, negative on failure
  1051. **/
  1052. static int
  1053. e1000_setup_tx_resources(struct e1000_adapter *adapter,
  1054. struct e1000_tx_ring *txdr)
  1055. {
  1056. struct pci_dev *pdev = adapter->pdev;
  1057. int size;
  1058. size = sizeof(struct e1000_buffer) * txdr->count;
  1059. txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
  1060. if(!txdr->buffer_info) {
  1061. DPRINTK(PROBE, ERR,
  1062. "Unable to allocate memory for the transmit descriptor ring\n");
  1063. return -ENOMEM;
  1064. }
  1065. memset(txdr->buffer_info, 0, size);
  1066. /* round up to nearest 4K */
  1067. txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  1068. E1000_ROUNDUP(txdr->size, 4096);
  1069. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1070. if(!txdr->desc) {
  1071. setup_tx_desc_die:
  1072. vfree(txdr->buffer_info);
  1073. DPRINTK(PROBE, ERR,
  1074. "Unable to allocate memory for the transmit descriptor ring\n");
  1075. return -ENOMEM;
  1076. }
  1077. /* Fix for errata 23, can't cross 64kB boundary */
  1078. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1079. void *olddesc = txdr->desc;
  1080. dma_addr_t olddma = txdr->dma;
  1081. DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
  1082. "at %p\n", txdr->size, txdr->desc);
  1083. /* Try again, without freeing the previous */
  1084. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1085. if(!txdr->desc) {
  1086. /* Failed allocation, critical failure */
  1087. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1088. goto setup_tx_desc_die;
  1089. }
  1090. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1091. /* give up */
  1092. pci_free_consistent(pdev, txdr->size, txdr->desc,
  1093. txdr->dma);
  1094. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1095. DPRINTK(PROBE, ERR,
  1096. "Unable to allocate aligned memory "
  1097. "for the transmit descriptor ring\n");
  1098. vfree(txdr->buffer_info);
  1099. return -ENOMEM;
  1100. } else {
  1101. /* Free old allocation, new allocation was successful */
  1102. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1103. }
  1104. }
  1105. memset(txdr->desc, 0, txdr->size);
  1106. txdr->next_to_use = 0;
  1107. txdr->next_to_clean = 0;
  1108. spin_lock_init(&txdr->tx_lock);
  1109. return 0;
  1110. }
  1111. /**
  1112. * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
  1113. * (Descriptors) for all queues
  1114. * @adapter: board private structure
  1115. *
  1116. * If this function returns with an error, then it's possible one or
  1117. * more of the rings is populated (while the rest are not). It is the
  1118. * callers duty to clean those orphaned rings.
  1119. *
  1120. * Return 0 on success, negative on failure
  1121. **/
  1122. int
  1123. e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
  1124. {
  1125. int i, err = 0;
  1126. for (i = 0; i < adapter->num_tx_queues; i++) {
  1127. err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1128. if (err) {
  1129. DPRINTK(PROBE, ERR,
  1130. "Allocation for Tx Queue %u failed\n", i);
  1131. break;
  1132. }
  1133. }
  1134. return err;
  1135. }
  1136. /**
  1137. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  1138. * @adapter: board private structure
  1139. *
  1140. * Configure the Tx unit of the MAC after a reset.
  1141. **/
  1142. static void
  1143. e1000_configure_tx(struct e1000_adapter *adapter)
  1144. {
  1145. uint64_t tdba;
  1146. struct e1000_hw *hw = &adapter->hw;
  1147. uint32_t tdlen, tctl, tipg, tarc;
  1148. uint32_t ipgr1, ipgr2;
  1149. /* Setup the HW Tx Head and Tail descriptor pointers */
  1150. switch (adapter->num_tx_queues) {
  1151. case 2:
  1152. tdba = adapter->tx_ring[1].dma;
  1153. tdlen = adapter->tx_ring[1].count *
  1154. sizeof(struct e1000_tx_desc);
  1155. E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
  1156. E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
  1157. E1000_WRITE_REG(hw, TDLEN1, tdlen);
  1158. E1000_WRITE_REG(hw, TDH1, 0);
  1159. E1000_WRITE_REG(hw, TDT1, 0);
  1160. adapter->tx_ring[1].tdh = E1000_TDH1;
  1161. adapter->tx_ring[1].tdt = E1000_TDT1;
  1162. /* Fall Through */
  1163. case 1:
  1164. default:
  1165. tdba = adapter->tx_ring[0].dma;
  1166. tdlen = adapter->tx_ring[0].count *
  1167. sizeof(struct e1000_tx_desc);
  1168. E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
  1169. E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
  1170. E1000_WRITE_REG(hw, TDLEN, tdlen);
  1171. E1000_WRITE_REG(hw, TDH, 0);
  1172. E1000_WRITE_REG(hw, TDT, 0);
  1173. adapter->tx_ring[0].tdh = E1000_TDH;
  1174. adapter->tx_ring[0].tdt = E1000_TDT;
  1175. break;
  1176. }
  1177. /* Set the default values for the Tx Inter Packet Gap timer */
  1178. if (hw->media_type == e1000_media_type_fiber ||
  1179. hw->media_type == e1000_media_type_internal_serdes)
  1180. tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  1181. else
  1182. tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  1183. switch (hw->mac_type) {
  1184. case e1000_82542_rev2_0:
  1185. case e1000_82542_rev2_1:
  1186. tipg = DEFAULT_82542_TIPG_IPGT;
  1187. ipgr1 = DEFAULT_82542_TIPG_IPGR1;
  1188. ipgr2 = DEFAULT_82542_TIPG_IPGR2;
  1189. break;
  1190. default:
  1191. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  1192. ipgr2 = DEFAULT_82543_TIPG_IPGR2;
  1193. break;
  1194. }
  1195. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  1196. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  1197. E1000_WRITE_REG(hw, TIPG, tipg);
  1198. /* Set the Tx Interrupt Delay register */
  1199. E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
  1200. if (hw->mac_type >= e1000_82540)
  1201. E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
  1202. /* Program the Transmit Control Register */
  1203. tctl = E1000_READ_REG(hw, TCTL);
  1204. tctl &= ~E1000_TCTL_CT;
  1205. tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1206. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1207. E1000_WRITE_REG(hw, TCTL, tctl);
  1208. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
  1209. tarc = E1000_READ_REG(hw, TARC0);
  1210. tarc |= ((1 << 25) | (1 << 21));
  1211. E1000_WRITE_REG(hw, TARC0, tarc);
  1212. tarc = E1000_READ_REG(hw, TARC1);
  1213. tarc |= (1 << 25);
  1214. if (tctl & E1000_TCTL_MULR)
  1215. tarc &= ~(1 << 28);
  1216. else
  1217. tarc |= (1 << 28);
  1218. E1000_WRITE_REG(hw, TARC1, tarc);
  1219. }
  1220. e1000_config_collision_dist(hw);
  1221. /* Setup Transmit Descriptor Settings for eop descriptor */
  1222. adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
  1223. E1000_TXD_CMD_IFCS;
  1224. if (hw->mac_type < e1000_82543)
  1225. adapter->txd_cmd |= E1000_TXD_CMD_RPS;
  1226. else
  1227. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  1228. /* Cache if we're 82544 running in PCI-X because we'll
  1229. * need this to apply a workaround later in the send path. */
  1230. if (hw->mac_type == e1000_82544 &&
  1231. hw->bus_type == e1000_bus_type_pcix)
  1232. adapter->pcix_82544 = 1;
  1233. }
  1234. /**
  1235. * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
  1236. * @adapter: board private structure
  1237. * @rxdr: rx descriptor ring (for a specific queue) to setup
  1238. *
  1239. * Returns 0 on success, negative on failure
  1240. **/
  1241. static int
  1242. e1000_setup_rx_resources(struct e1000_adapter *adapter,
  1243. struct e1000_rx_ring *rxdr)
  1244. {
  1245. struct pci_dev *pdev = adapter->pdev;
  1246. int size, desc_len;
  1247. size = sizeof(struct e1000_buffer) * rxdr->count;
  1248. rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
  1249. if (!rxdr->buffer_info) {
  1250. DPRINTK(PROBE, ERR,
  1251. "Unable to allocate memory for the receive descriptor ring\n");
  1252. return -ENOMEM;
  1253. }
  1254. memset(rxdr->buffer_info, 0, size);
  1255. size = sizeof(struct e1000_ps_page) * rxdr->count;
  1256. rxdr->ps_page = kmalloc(size, GFP_KERNEL);
  1257. if(!rxdr->ps_page) {
  1258. vfree(rxdr->buffer_info);
  1259. DPRINTK(PROBE, ERR,
  1260. "Unable to allocate memory for the receive descriptor ring\n");
  1261. return -ENOMEM;
  1262. }
  1263. memset(rxdr->ps_page, 0, size);
  1264. size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
  1265. rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
  1266. if(!rxdr->ps_page_dma) {
  1267. vfree(rxdr->buffer_info);
  1268. kfree(rxdr->ps_page);
  1269. DPRINTK(PROBE, ERR,
  1270. "Unable to allocate memory for the receive descriptor ring\n");
  1271. return -ENOMEM;
  1272. }
  1273. memset(rxdr->ps_page_dma, 0, size);
  1274. if(adapter->hw.mac_type <= e1000_82547_rev_2)
  1275. desc_len = sizeof(struct e1000_rx_desc);
  1276. else
  1277. desc_len = sizeof(union e1000_rx_desc_packet_split);
  1278. /* Round up to nearest 4K */
  1279. rxdr->size = rxdr->count * desc_len;
  1280. E1000_ROUNDUP(rxdr->size, 4096);
  1281. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1282. if (!rxdr->desc) {
  1283. DPRINTK(PROBE, ERR,
  1284. "Unable to allocate memory for the receive descriptor ring\n");
  1285. setup_rx_desc_die:
  1286. vfree(rxdr->buffer_info);
  1287. kfree(rxdr->ps_page);
  1288. kfree(rxdr->ps_page_dma);
  1289. return -ENOMEM;
  1290. }
  1291. /* Fix for errata 23, can't cross 64kB boundary */
  1292. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1293. void *olddesc = rxdr->desc;
  1294. dma_addr_t olddma = rxdr->dma;
  1295. DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
  1296. "at %p\n", rxdr->size, rxdr->desc);
  1297. /* Try again, without freeing the previous */
  1298. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1299. /* Failed allocation, critical failure */
  1300. if (!rxdr->desc) {
  1301. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1302. DPRINTK(PROBE, ERR,
  1303. "Unable to allocate memory "
  1304. "for the receive descriptor ring\n");
  1305. goto setup_rx_desc_die;
  1306. }
  1307. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1308. /* give up */
  1309. pci_free_consistent(pdev, rxdr->size, rxdr->desc,
  1310. rxdr->dma);
  1311. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1312. DPRINTK(PROBE, ERR,
  1313. "Unable to allocate aligned memory "
  1314. "for the receive descriptor ring\n");
  1315. goto setup_rx_desc_die;
  1316. } else {
  1317. /* Free old allocation, new allocation was successful */
  1318. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1319. }
  1320. }
  1321. memset(rxdr->desc, 0, rxdr->size);
  1322. rxdr->next_to_clean = 0;
  1323. rxdr->next_to_use = 0;
  1324. rxdr->rx_skb_top = NULL;
  1325. rxdr->rx_skb_prev = NULL;
  1326. return 0;
  1327. }
  1328. /**
  1329. * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
  1330. * (Descriptors) for all queues
  1331. * @adapter: board private structure
  1332. *
  1333. * If this function returns with an error, then it's possible one or
  1334. * more of the rings is populated (while the rest are not). It is the
  1335. * callers duty to clean those orphaned rings.
  1336. *
  1337. * Return 0 on success, negative on failure
  1338. **/
  1339. int
  1340. e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
  1341. {
  1342. int i, err = 0;
  1343. for (i = 0; i < adapter->num_rx_queues; i++) {
  1344. err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1345. if (err) {
  1346. DPRINTK(PROBE, ERR,
  1347. "Allocation for Rx Queue %u failed\n", i);
  1348. break;
  1349. }
  1350. }
  1351. return err;
  1352. }
  1353. /**
  1354. * e1000_setup_rctl - configure the receive control registers
  1355. * @adapter: Board private structure
  1356. **/
  1357. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  1358. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  1359. static void
  1360. e1000_setup_rctl(struct e1000_adapter *adapter)
  1361. {
  1362. uint32_t rctl, rfctl;
  1363. uint32_t psrctl = 0;
  1364. #ifdef CONFIG_E1000_PACKET_SPLIT
  1365. uint32_t pages = 0;
  1366. #endif
  1367. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1368. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1369. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  1370. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1371. (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1372. if (adapter->hw.mac_type > e1000_82543)
  1373. rctl |= E1000_RCTL_SECRC;
  1374. if (adapter->hw.tbi_compatibility_on == 1)
  1375. rctl |= E1000_RCTL_SBP;
  1376. else
  1377. rctl &= ~E1000_RCTL_SBP;
  1378. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1379. rctl &= ~E1000_RCTL_LPE;
  1380. else
  1381. rctl |= E1000_RCTL_LPE;
  1382. /* Setup buffer sizes */
  1383. if(adapter->hw.mac_type >= e1000_82571) {
  1384. /* We can now specify buffers in 1K increments.
  1385. * BSIZE and BSEX are ignored in this case. */
  1386. rctl |= adapter->rx_buffer_len << 0x11;
  1387. } else {
  1388. rctl &= ~E1000_RCTL_SZ_4096;
  1389. rctl |= E1000_RCTL_BSEX;
  1390. switch (adapter->rx_buffer_len) {
  1391. case E1000_RXBUFFER_2048:
  1392. default:
  1393. rctl |= E1000_RCTL_SZ_2048;
  1394. rctl &= ~E1000_RCTL_BSEX;
  1395. break;
  1396. case E1000_RXBUFFER_4096:
  1397. rctl |= E1000_RCTL_SZ_4096;
  1398. break;
  1399. case E1000_RXBUFFER_8192:
  1400. rctl |= E1000_RCTL_SZ_8192;
  1401. break;
  1402. case E1000_RXBUFFER_16384:
  1403. rctl |= E1000_RCTL_SZ_16384;
  1404. break;
  1405. }
  1406. }
  1407. #ifdef CONFIG_E1000_PACKET_SPLIT
  1408. /* 82571 and greater support packet-split where the protocol
  1409. * header is placed in skb->data and the packet data is
  1410. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  1411. * In the case of a non-split, skb->data is linearly filled,
  1412. * followed by the page buffers. Therefore, skb->data is
  1413. * sized to hold the largest protocol header.
  1414. */
  1415. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  1416. if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
  1417. PAGE_SIZE <= 16384)
  1418. adapter->rx_ps_pages = pages;
  1419. else
  1420. adapter->rx_ps_pages = 0;
  1421. #endif
  1422. if (adapter->rx_ps_pages) {
  1423. /* Configure extra packet-split registers */
  1424. rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
  1425. rfctl |= E1000_RFCTL_EXTEN;
  1426. /* disable IPv6 packet split support */
  1427. rfctl |= E1000_RFCTL_IPV6_DIS;
  1428. E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
  1429. rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
  1430. psrctl |= adapter->rx_ps_bsize0 >>
  1431. E1000_PSRCTL_BSIZE0_SHIFT;
  1432. switch (adapter->rx_ps_pages) {
  1433. case 3:
  1434. psrctl |= PAGE_SIZE <<
  1435. E1000_PSRCTL_BSIZE3_SHIFT;
  1436. case 2:
  1437. psrctl |= PAGE_SIZE <<
  1438. E1000_PSRCTL_BSIZE2_SHIFT;
  1439. case 1:
  1440. psrctl |= PAGE_SIZE >>
  1441. E1000_PSRCTL_BSIZE1_SHIFT;
  1442. break;
  1443. }
  1444. E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
  1445. }
  1446. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1447. }
  1448. /**
  1449. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  1450. * @adapter: board private structure
  1451. *
  1452. * Configure the Rx unit of the MAC after a reset.
  1453. **/
  1454. static void
  1455. e1000_configure_rx(struct e1000_adapter *adapter)
  1456. {
  1457. uint64_t rdba;
  1458. struct e1000_hw *hw = &adapter->hw;
  1459. uint32_t rdlen, rctl, rxcsum, ctrl_ext;
  1460. #ifdef CONFIG_E1000_MQ
  1461. uint32_t reta, mrqc;
  1462. int i;
  1463. #endif
  1464. if (adapter->rx_ps_pages) {
  1465. rdlen = adapter->rx_ring[0].count *
  1466. sizeof(union e1000_rx_desc_packet_split);
  1467. adapter->clean_rx = e1000_clean_rx_irq_ps;
  1468. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  1469. } else {
  1470. rdlen = adapter->rx_ring[0].count *
  1471. sizeof(struct e1000_rx_desc);
  1472. adapter->clean_rx = e1000_clean_rx_irq;
  1473. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  1474. }
  1475. /* disable receives while setting up the descriptors */
  1476. rctl = E1000_READ_REG(hw, RCTL);
  1477. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  1478. /* set the Receive Delay Timer Register */
  1479. E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
  1480. if (hw->mac_type >= e1000_82540) {
  1481. E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
  1482. if(adapter->itr > 1)
  1483. E1000_WRITE_REG(hw, ITR,
  1484. 1000000000 / (adapter->itr * 256));
  1485. }
  1486. if (hw->mac_type >= e1000_82571) {
  1487. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1488. /* Reset delay timers after every interrupt */
  1489. ctrl_ext |= E1000_CTRL_EXT_CANC;
  1490. #ifdef CONFIG_E1000_NAPI
  1491. /* Auto-Mask interrupts upon ICR read. */
  1492. ctrl_ext |= E1000_CTRL_EXT_IAME;
  1493. #endif
  1494. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1495. E1000_WRITE_REG(hw, IAM, ~0);
  1496. E1000_WRITE_FLUSH(hw);
  1497. }
  1498. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1499. * the Base and Length of the Rx Descriptor Ring */
  1500. switch (adapter->num_rx_queues) {
  1501. #ifdef CONFIG_E1000_MQ
  1502. case 2:
  1503. rdba = adapter->rx_ring[1].dma;
  1504. E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
  1505. E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
  1506. E1000_WRITE_REG(hw, RDLEN1, rdlen);
  1507. E1000_WRITE_REG(hw, RDH1, 0);
  1508. E1000_WRITE_REG(hw, RDT1, 0);
  1509. adapter->rx_ring[1].rdh = E1000_RDH1;
  1510. adapter->rx_ring[1].rdt = E1000_RDT1;
  1511. /* Fall Through */
  1512. #endif
  1513. case 1:
  1514. default:
  1515. rdba = adapter->rx_ring[0].dma;
  1516. E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
  1517. E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
  1518. E1000_WRITE_REG(hw, RDLEN, rdlen);
  1519. E1000_WRITE_REG(hw, RDH, 0);
  1520. E1000_WRITE_REG(hw, RDT, 0);
  1521. adapter->rx_ring[0].rdh = E1000_RDH;
  1522. adapter->rx_ring[0].rdt = E1000_RDT;
  1523. break;
  1524. }
  1525. #ifdef CONFIG_E1000_MQ
  1526. if (adapter->num_rx_queues > 1) {
  1527. uint32_t random[10];
  1528. get_random_bytes(&random[0], 40);
  1529. if (hw->mac_type <= e1000_82572) {
  1530. E1000_WRITE_REG(hw, RSSIR, 0);
  1531. E1000_WRITE_REG(hw, RSSIM, 0);
  1532. }
  1533. switch (adapter->num_rx_queues) {
  1534. case 2:
  1535. default:
  1536. reta = 0x00800080;
  1537. mrqc = E1000_MRQC_ENABLE_RSS_2Q;
  1538. break;
  1539. }
  1540. /* Fill out redirection table */
  1541. for (i = 0; i < 32; i++)
  1542. E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
  1543. /* Fill out hash function seeds */
  1544. for (i = 0; i < 10; i++)
  1545. E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
  1546. mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
  1547. E1000_MRQC_RSS_FIELD_IPV4_TCP);
  1548. E1000_WRITE_REG(hw, MRQC, mrqc);
  1549. }
  1550. /* Multiqueue and packet checksumming are mutually exclusive. */
  1551. if (hw->mac_type >= e1000_82571) {
  1552. rxcsum = E1000_READ_REG(hw, RXCSUM);
  1553. rxcsum |= E1000_RXCSUM_PCSD;
  1554. E1000_WRITE_REG(hw, RXCSUM, rxcsum);
  1555. }
  1556. #else
  1557. /* Enable 82543 Receive Checksum Offload for TCP and UDP */
  1558. if (hw->mac_type >= e1000_82543) {
  1559. rxcsum = E1000_READ_REG(hw, RXCSUM);
  1560. if(adapter->rx_csum == TRUE) {
  1561. rxcsum |= E1000_RXCSUM_TUOFL;
  1562. /* Enable 82571 IPv4 payload checksum for UDP fragments
  1563. * Must be used in conjunction with packet-split. */
  1564. if ((hw->mac_type >= e1000_82571) &&
  1565. (adapter->rx_ps_pages)) {
  1566. rxcsum |= E1000_RXCSUM_IPPCSE;
  1567. }
  1568. } else {
  1569. rxcsum &= ~E1000_RXCSUM_TUOFL;
  1570. /* don't need to clear IPPCSE as it defaults to 0 */
  1571. }
  1572. E1000_WRITE_REG(hw, RXCSUM, rxcsum);
  1573. }
  1574. #endif /* CONFIG_E1000_MQ */
  1575. if (hw->mac_type == e1000_82573)
  1576. E1000_WRITE_REG(hw, ERT, 0x0100);
  1577. /* Enable Receives */
  1578. E1000_WRITE_REG(hw, RCTL, rctl);
  1579. }
  1580. /**
  1581. * e1000_free_tx_resources - Free Tx Resources per Queue
  1582. * @adapter: board private structure
  1583. * @tx_ring: Tx descriptor ring for a specific queue
  1584. *
  1585. * Free all transmit software resources
  1586. **/
  1587. static void
  1588. e1000_free_tx_resources(struct e1000_adapter *adapter,
  1589. struct e1000_tx_ring *tx_ring)
  1590. {
  1591. struct pci_dev *pdev = adapter->pdev;
  1592. e1000_clean_tx_ring(adapter, tx_ring);
  1593. vfree(tx_ring->buffer_info);
  1594. tx_ring->buffer_info = NULL;
  1595. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  1596. tx_ring->desc = NULL;
  1597. }
  1598. /**
  1599. * e1000_free_all_tx_resources - Free Tx Resources for All Queues
  1600. * @adapter: board private structure
  1601. *
  1602. * Free all transmit software resources
  1603. **/
  1604. void
  1605. e1000_free_all_tx_resources(struct e1000_adapter *adapter)
  1606. {
  1607. int i;
  1608. for (i = 0; i < adapter->num_tx_queues; i++)
  1609. e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
  1610. }
  1611. static inline void
  1612. e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
  1613. struct e1000_buffer *buffer_info)
  1614. {
  1615. if(buffer_info->dma) {
  1616. pci_unmap_page(adapter->pdev,
  1617. buffer_info->dma,
  1618. buffer_info->length,
  1619. PCI_DMA_TODEVICE);
  1620. buffer_info->dma = 0;
  1621. }
  1622. if(buffer_info->skb) {
  1623. dev_kfree_skb_any(buffer_info->skb);
  1624. buffer_info->skb = NULL;
  1625. }
  1626. }
  1627. /**
  1628. * e1000_clean_tx_ring - Free Tx Buffers
  1629. * @adapter: board private structure
  1630. * @tx_ring: ring to be cleaned
  1631. **/
  1632. static void
  1633. e1000_clean_tx_ring(struct e1000_adapter *adapter,
  1634. struct e1000_tx_ring *tx_ring)
  1635. {
  1636. struct e1000_buffer *buffer_info;
  1637. unsigned long size;
  1638. unsigned int i;
  1639. /* Free all the Tx ring sk_buffs */
  1640. for(i = 0; i < tx_ring->count; i++) {
  1641. buffer_info = &tx_ring->buffer_info[i];
  1642. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  1643. }
  1644. size = sizeof(struct e1000_buffer) * tx_ring->count;
  1645. memset(tx_ring->buffer_info, 0, size);
  1646. /* Zero out the descriptor ring */
  1647. memset(tx_ring->desc, 0, tx_ring->size);
  1648. tx_ring->next_to_use = 0;
  1649. tx_ring->next_to_clean = 0;
  1650. tx_ring->last_tx_tso = 0;
  1651. writel(0, adapter->hw.hw_addr + tx_ring->tdh);
  1652. writel(0, adapter->hw.hw_addr + tx_ring->tdt);
  1653. }
  1654. /**
  1655. * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
  1656. * @adapter: board private structure
  1657. **/
  1658. static void
  1659. e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
  1660. {
  1661. int i;
  1662. for (i = 0; i < adapter->num_tx_queues; i++)
  1663. e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  1664. }
  1665. /**
  1666. * e1000_free_rx_resources - Free Rx Resources
  1667. * @adapter: board private structure
  1668. * @rx_ring: ring to clean the resources from
  1669. *
  1670. * Free all receive software resources
  1671. **/
  1672. static void
  1673. e1000_free_rx_resources(struct e1000_adapter *adapter,
  1674. struct e1000_rx_ring *rx_ring)
  1675. {
  1676. struct pci_dev *pdev = adapter->pdev;
  1677. e1000_clean_rx_ring(adapter, rx_ring);
  1678. vfree(rx_ring->buffer_info);
  1679. rx_ring->buffer_info = NULL;
  1680. kfree(rx_ring->ps_page);
  1681. rx_ring->ps_page = NULL;
  1682. kfree(rx_ring->ps_page_dma);
  1683. rx_ring->ps_page_dma = NULL;
  1684. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  1685. rx_ring->desc = NULL;
  1686. }
  1687. /**
  1688. * e1000_free_all_rx_resources - Free Rx Resources for All Queues
  1689. * @adapter: board private structure
  1690. *
  1691. * Free all receive software resources
  1692. **/
  1693. void
  1694. e1000_free_all_rx_resources(struct e1000_adapter *adapter)
  1695. {
  1696. int i;
  1697. for (i = 0; i < adapter->num_rx_queues; i++)
  1698. e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
  1699. }
  1700. /**
  1701. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  1702. * @adapter: board private structure
  1703. * @rx_ring: ring to free buffers from
  1704. **/
  1705. static void
  1706. e1000_clean_rx_ring(struct e1000_adapter *adapter,
  1707. struct e1000_rx_ring *rx_ring)
  1708. {
  1709. struct e1000_buffer *buffer_info;
  1710. struct e1000_ps_page *ps_page;
  1711. struct e1000_ps_page_dma *ps_page_dma;
  1712. struct pci_dev *pdev = adapter->pdev;
  1713. unsigned long size;
  1714. unsigned int i, j;
  1715. /* Free all the Rx ring sk_buffs */
  1716. for(i = 0; i < rx_ring->count; i++) {
  1717. buffer_info = &rx_ring->buffer_info[i];
  1718. if(buffer_info->skb) {
  1719. ps_page = &rx_ring->ps_page[i];
  1720. ps_page_dma = &rx_ring->ps_page_dma[i];
  1721. pci_unmap_single(pdev,
  1722. buffer_info->dma,
  1723. buffer_info->length,
  1724. PCI_DMA_FROMDEVICE);
  1725. dev_kfree_skb(buffer_info->skb);
  1726. buffer_info->skb = NULL;
  1727. }
  1728. ps_page = &rx_ring->ps_page[i];
  1729. ps_page_dma = &rx_ring->ps_page_dma[i];
  1730. for (j = 0; j < adapter->rx_ps_pages; j++) {
  1731. if (!ps_page->ps_page[j]) break;
  1732. pci_unmap_page(pdev,
  1733. ps_page_dma->ps_page_dma[j],
  1734. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  1735. ps_page_dma->ps_page_dma[j] = 0;
  1736. put_page(ps_page->ps_page[j]);
  1737. ps_page->ps_page[j] = NULL;
  1738. }
  1739. }
  1740. /* there also may be some cached data in our adapter */
  1741. if (rx_ring->rx_skb_top) {
  1742. dev_kfree_skb(rx_ring->rx_skb_top);
  1743. /* rx_skb_prev will be wiped out by rx_skb_top */
  1744. rx_ring->rx_skb_top = NULL;
  1745. rx_ring->rx_skb_prev = NULL;
  1746. }
  1747. size = sizeof(struct e1000_buffer) * rx_ring->count;
  1748. memset(rx_ring->buffer_info, 0, size);
  1749. size = sizeof(struct e1000_ps_page) * rx_ring->count;
  1750. memset(rx_ring->ps_page, 0, size);
  1751. size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
  1752. memset(rx_ring->ps_page_dma, 0, size);
  1753. /* Zero out the descriptor ring */
  1754. memset(rx_ring->desc, 0, rx_ring->size);
  1755. rx_ring->next_to_clean = 0;
  1756. rx_ring->next_to_use = 0;
  1757. writel(0, adapter->hw.hw_addr + rx_ring->rdh);
  1758. writel(0, adapter->hw.hw_addr + rx_ring->rdt);
  1759. }
  1760. /**
  1761. * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
  1762. * @adapter: board private structure
  1763. **/
  1764. static void
  1765. e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
  1766. {
  1767. int i;
  1768. for (i = 0; i < adapter->num_rx_queues; i++)
  1769. e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  1770. }
  1771. /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
  1772. * and memory write and invalidate disabled for certain operations
  1773. */
  1774. static void
  1775. e1000_enter_82542_rst(struct e1000_adapter *adapter)
  1776. {
  1777. struct net_device *netdev = adapter->netdev;
  1778. uint32_t rctl;
  1779. e1000_pci_clear_mwi(&adapter->hw);
  1780. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1781. rctl |= E1000_RCTL_RST;
  1782. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1783. E1000_WRITE_FLUSH(&adapter->hw);
  1784. mdelay(5);
  1785. if(netif_running(netdev))
  1786. e1000_clean_all_rx_rings(adapter);
  1787. }
  1788. static void
  1789. e1000_leave_82542_rst(struct e1000_adapter *adapter)
  1790. {
  1791. struct net_device *netdev = adapter->netdev;
  1792. uint32_t rctl;
  1793. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1794. rctl &= ~E1000_RCTL_RST;
  1795. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1796. E1000_WRITE_FLUSH(&adapter->hw);
  1797. mdelay(5);
  1798. if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
  1799. e1000_pci_set_mwi(&adapter->hw);
  1800. if(netif_running(netdev)) {
  1801. e1000_configure_rx(adapter);
  1802. /* No need to loop, because 82542 supports only 1 queue */
  1803. struct e1000_rx_ring *ring = &adapter->rx_ring[0];
  1804. adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
  1805. }
  1806. }
  1807. /**
  1808. * e1000_set_mac - Change the Ethernet Address of the NIC
  1809. * @netdev: network interface device structure
  1810. * @p: pointer to an address structure
  1811. *
  1812. * Returns 0 on success, negative on failure
  1813. **/
  1814. static int
  1815. e1000_set_mac(struct net_device *netdev, void *p)
  1816. {
  1817. struct e1000_adapter *adapter = netdev_priv(netdev);
  1818. struct sockaddr *addr = p;
  1819. if(!is_valid_ether_addr(addr->sa_data))
  1820. return -EADDRNOTAVAIL;
  1821. /* 82542 2.0 needs to be in reset to write receive address registers */
  1822. if(adapter->hw.mac_type == e1000_82542_rev2_0)
  1823. e1000_enter_82542_rst(adapter);
  1824. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1825. memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
  1826. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  1827. /* With 82571 controllers, LAA may be overwritten (with the default)
  1828. * due to controller reset from the other port. */
  1829. if (adapter->hw.mac_type == e1000_82571) {
  1830. /* activate the work around */
  1831. adapter->hw.laa_is_present = 1;
  1832. /* Hold a copy of the LAA in RAR[14] This is done so that
  1833. * between the time RAR[0] gets clobbered and the time it
  1834. * gets fixed (in e1000_watchdog), the actual LAA is in one
  1835. * of the RARs and no incoming packets directed to this port
  1836. * are dropped. Eventaully the LAA will be in RAR[0] and
  1837. * RAR[14] */
  1838. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
  1839. E1000_RAR_ENTRIES - 1);
  1840. }
  1841. if(adapter->hw.mac_type == e1000_82542_rev2_0)
  1842. e1000_leave_82542_rst(adapter);
  1843. return 0;
  1844. }
  1845. /**
  1846. * e1000_set_multi - Multicast and Promiscuous mode set
  1847. * @netdev: network interface device structure
  1848. *
  1849. * The set_multi entry point is called whenever the multicast address
  1850. * list or the network interface flags are updated. This routine is
  1851. * responsible for configuring the hardware for proper multicast,
  1852. * promiscuous mode, and all-multi behavior.
  1853. **/
  1854. static void
  1855. e1000_set_multi(struct net_device *netdev)
  1856. {
  1857. struct e1000_adapter *adapter = netdev_priv(netdev);
  1858. struct e1000_hw *hw = &adapter->hw;
  1859. struct dev_mc_list *mc_ptr;
  1860. uint32_t rctl;
  1861. uint32_t hash_value;
  1862. int i, rar_entries = E1000_RAR_ENTRIES;
  1863. /* reserve RAR[14] for LAA over-write work-around */
  1864. if (adapter->hw.mac_type == e1000_82571)
  1865. rar_entries--;
  1866. /* Check for Promiscuous and All Multicast modes */
  1867. rctl = E1000_READ_REG(hw, RCTL);
  1868. if(netdev->flags & IFF_PROMISC) {
  1869. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  1870. } else if(netdev->flags & IFF_ALLMULTI) {
  1871. rctl |= E1000_RCTL_MPE;
  1872. rctl &= ~E1000_RCTL_UPE;
  1873. } else {
  1874. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  1875. }
  1876. E1000_WRITE_REG(hw, RCTL, rctl);
  1877. /* 82542 2.0 needs to be in reset to write receive address registers */
  1878. if(hw->mac_type == e1000_82542_rev2_0)
  1879. e1000_enter_82542_rst(adapter);
  1880. /* load the first 14 multicast address into the exact filters 1-14
  1881. * RAR 0 is used for the station MAC adddress
  1882. * if there are not 14 addresses, go ahead and clear the filters
  1883. * -- with 82571 controllers only 0-13 entries are filled here
  1884. */
  1885. mc_ptr = netdev->mc_list;
  1886. for(i = 1; i < rar_entries; i++) {
  1887. if (mc_ptr) {
  1888. e1000_rar_set(hw, mc_ptr->dmi_addr, i);
  1889. mc_ptr = mc_ptr->next;
  1890. } else {
  1891. E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
  1892. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
  1893. }
  1894. }
  1895. /* clear the old settings from the multicast hash table */
  1896. for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
  1897. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  1898. /* load any remaining addresses into the hash table */
  1899. for(; mc_ptr; mc_ptr = mc_ptr->next) {
  1900. hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
  1901. e1000_mta_set(hw, hash_value);
  1902. }
  1903. if(hw->mac_type == e1000_82542_rev2_0)
  1904. e1000_leave_82542_rst(adapter);
  1905. }
  1906. /* Need to wait a few seconds after link up to get diagnostic information from
  1907. * the phy */
  1908. static void
  1909. e1000_update_phy_info(unsigned long data)
  1910. {
  1911. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1912. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  1913. }
  1914. /**
  1915. * e1000_82547_tx_fifo_stall - Timer Call-back
  1916. * @data: pointer to adapter cast into an unsigned long
  1917. **/
  1918. static void
  1919. e1000_82547_tx_fifo_stall(unsigned long data)
  1920. {
  1921. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1922. struct net_device *netdev = adapter->netdev;
  1923. uint32_t tctl;
  1924. if(atomic_read(&adapter->tx_fifo_stall)) {
  1925. if((E1000_READ_REG(&adapter->hw, TDT) ==
  1926. E1000_READ_REG(&adapter->hw, TDH)) &&
  1927. (E1000_READ_REG(&adapter->hw, TDFT) ==
  1928. E1000_READ_REG(&adapter->hw, TDFH)) &&
  1929. (E1000_READ_REG(&adapter->hw, TDFTS) ==
  1930. E1000_READ_REG(&adapter->hw, TDFHS))) {
  1931. tctl = E1000_READ_REG(&adapter->hw, TCTL);
  1932. E1000_WRITE_REG(&adapter->hw, TCTL,
  1933. tctl & ~E1000_TCTL_EN);
  1934. E1000_WRITE_REG(&adapter->hw, TDFT,
  1935. adapter->tx_head_addr);
  1936. E1000_WRITE_REG(&adapter->hw, TDFH,
  1937. adapter->tx_head_addr);
  1938. E1000_WRITE_REG(&adapter->hw, TDFTS,
  1939. adapter->tx_head_addr);
  1940. E1000_WRITE_REG(&adapter->hw, TDFHS,
  1941. adapter->tx_head_addr);
  1942. E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  1943. E1000_WRITE_FLUSH(&adapter->hw);
  1944. adapter->tx_fifo_head = 0;
  1945. atomic_set(&adapter->tx_fifo_stall, 0);
  1946. netif_wake_queue(netdev);
  1947. } else {
  1948. mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
  1949. }
  1950. }
  1951. }
  1952. /**
  1953. * e1000_watchdog - Timer Call-back
  1954. * @data: pointer to adapter cast into an unsigned long
  1955. **/
  1956. static void
  1957. e1000_watchdog(unsigned long data)
  1958. {
  1959. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1960. /* Do the rest outside of interrupt context */
  1961. schedule_work(&adapter->watchdog_task);
  1962. }
  1963. static void
  1964. e1000_watchdog_task(struct e1000_adapter *adapter)
  1965. {
  1966. struct net_device *netdev = adapter->netdev;
  1967. struct e1000_tx_ring *txdr = adapter->tx_ring;
  1968. uint32_t link;
  1969. e1000_check_for_link(&adapter->hw);
  1970. if (adapter->hw.mac_type == e1000_82573) {
  1971. e1000_enable_tx_pkt_filtering(&adapter->hw);
  1972. if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
  1973. e1000_update_mng_vlan(adapter);
  1974. }
  1975. if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
  1976. !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
  1977. link = !adapter->hw.serdes_link_down;
  1978. else
  1979. link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
  1980. if(link) {
  1981. if(!netif_carrier_ok(netdev)) {
  1982. e1000_get_speed_and_duplex(&adapter->hw,
  1983. &adapter->link_speed,
  1984. &adapter->link_duplex);
  1985. DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
  1986. adapter->link_speed,
  1987. adapter->link_duplex == FULL_DUPLEX ?
  1988. "Full Duplex" : "Half Duplex");
  1989. /* tweak tx_queue_len according to speed/duplex */
  1990. netdev->tx_queue_len = adapter->tx_queue_len;
  1991. adapter->tx_timeout_factor = 1;
  1992. if (adapter->link_duplex == HALF_DUPLEX) {
  1993. switch (adapter->link_speed) {
  1994. case SPEED_10:
  1995. netdev->tx_queue_len = 10;
  1996. adapter->tx_timeout_factor = 8;
  1997. break;
  1998. case SPEED_100:
  1999. netdev->tx_queue_len = 100;
  2000. break;
  2001. }
  2002. }
  2003. netif_carrier_on(netdev);
  2004. netif_wake_queue(netdev);
  2005. mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
  2006. adapter->smartspeed = 0;
  2007. }
  2008. } else {
  2009. if(netif_carrier_ok(netdev)) {
  2010. adapter->link_speed = 0;
  2011. adapter->link_duplex = 0;
  2012. DPRINTK(LINK, INFO, "NIC Link is Down\n");
  2013. netif_carrier_off(netdev);
  2014. netif_stop_queue(netdev);
  2015. mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
  2016. }
  2017. e1000_smartspeed(adapter);
  2018. }
  2019. e1000_update_stats(adapter);
  2020. adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  2021. adapter->tpt_old = adapter->stats.tpt;
  2022. adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
  2023. adapter->colc_old = adapter->stats.colc;
  2024. adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
  2025. adapter->gorcl_old = adapter->stats.gorcl;
  2026. adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
  2027. adapter->gotcl_old = adapter->stats.gotcl;
  2028. e1000_update_adaptive(&adapter->hw);
  2029. #ifdef CONFIG_E1000_MQ
  2030. txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
  2031. #endif
  2032. if (!netif_carrier_ok(netdev)) {
  2033. if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
  2034. /* We've lost link, so the controller stops DMA,
  2035. * but we've got queued Tx work that's never going
  2036. * to get done, so reset controller to flush Tx.
  2037. * (Do the reset outside of interrupt context). */
  2038. schedule_work(&adapter->tx_timeout_task);
  2039. }
  2040. }
  2041. /* Dynamic mode for Interrupt Throttle Rate (ITR) */
  2042. if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
  2043. /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
  2044. * asymmetrical Tx or Rx gets ITR=8000; everyone
  2045. * else is between 2000-8000. */
  2046. uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
  2047. uint32_t dif = (adapter->gotcl > adapter->gorcl ?
  2048. adapter->gotcl - adapter->gorcl :
  2049. adapter->gorcl - adapter->gotcl) / 10000;
  2050. uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
  2051. E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
  2052. }
  2053. /* Cause software interrupt to ensure rx ring is cleaned */
  2054. E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
  2055. /* Force detection of hung controller every watchdog period */
  2056. adapter->detect_tx_hung = TRUE;
  2057. /* With 82571 controllers, LAA may be overwritten due to controller
  2058. * reset from the other port. Set the appropriate LAA in RAR[0] */
  2059. if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
  2060. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  2061. /* Reset the timer */
  2062. mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
  2063. }
  2064. #define E1000_TX_FLAGS_CSUM 0x00000001
  2065. #define E1000_TX_FLAGS_VLAN 0x00000002
  2066. #define E1000_TX_FLAGS_TSO 0x00000004
  2067. #define E1000_TX_FLAGS_IPV4 0x00000008
  2068. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  2069. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  2070. static inline int
  2071. e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2072. struct sk_buff *skb)
  2073. {
  2074. #ifdef NETIF_F_TSO
  2075. struct e1000_context_desc *context_desc;
  2076. struct e1000_buffer *buffer_info;
  2077. unsigned int i;
  2078. uint32_t cmd_length = 0;
  2079. uint16_t ipcse = 0, tucse, mss;
  2080. uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
  2081. int err;
  2082. if(skb_shinfo(skb)->tso_size) {
  2083. if (skb_header_cloned(skb)) {
  2084. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2085. if (err)
  2086. return err;
  2087. }
  2088. hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
  2089. mss = skb_shinfo(skb)->tso_size;
  2090. if(skb->protocol == ntohs(ETH_P_IP)) {
  2091. skb->nh.iph->tot_len = 0;
  2092. skb->nh.iph->check = 0;
  2093. skb->h.th->check =
  2094. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  2095. skb->nh.iph->daddr,
  2096. 0,
  2097. IPPROTO_TCP,
  2098. 0);
  2099. cmd_length = E1000_TXD_CMD_IP;
  2100. ipcse = skb->h.raw - skb->data - 1;
  2101. #ifdef NETIF_F_TSO_IPV6
  2102. } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
  2103. skb->nh.ipv6h->payload_len = 0;
  2104. skb->h.th->check =
  2105. ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
  2106. &skb->nh.ipv6h->daddr,
  2107. 0,
  2108. IPPROTO_TCP,
  2109. 0);
  2110. ipcse = 0;
  2111. #endif
  2112. }
  2113. ipcss = skb->nh.raw - skb->data;
  2114. ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
  2115. tucss = skb->h.raw - skb->data;
  2116. tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
  2117. tucse = 0;
  2118. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  2119. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  2120. i = tx_ring->next_to_use;
  2121. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2122. buffer_info = &tx_ring->buffer_info[i];
  2123. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  2124. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  2125. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  2126. context_desc->upper_setup.tcp_fields.tucss = tucss;
  2127. context_desc->upper_setup.tcp_fields.tucso = tucso;
  2128. context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
  2129. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  2130. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  2131. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  2132. buffer_info->time_stamp = jiffies;
  2133. if (++i == tx_ring->count) i = 0;
  2134. tx_ring->next_to_use = i;
  2135. return 1;
  2136. }
  2137. #endif
  2138. return 0;
  2139. }
  2140. static inline boolean_t
  2141. e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2142. struct sk_buff *skb)
  2143. {
  2144. struct e1000_context_desc *context_desc;
  2145. struct e1000_buffer *buffer_info;
  2146. unsigned int i;
  2147. uint8_t css;
  2148. if(likely(skb->ip_summed == CHECKSUM_HW)) {
  2149. css = skb->h.raw - skb->data;
  2150. i = tx_ring->next_to_use;
  2151. buffer_info = &tx_ring->buffer_info[i];
  2152. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2153. context_desc->upper_setup.tcp_fields.tucss = css;
  2154. context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
  2155. context_desc->upper_setup.tcp_fields.tucse = 0;
  2156. context_desc->tcp_seg_setup.data = 0;
  2157. context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
  2158. buffer_info->time_stamp = jiffies;
  2159. if (unlikely(++i == tx_ring->count)) i = 0;
  2160. tx_ring->next_to_use = i;
  2161. return TRUE;
  2162. }
  2163. return FALSE;
  2164. }
  2165. #define E1000_MAX_TXD_PWR 12
  2166. #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
  2167. static inline int
  2168. e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2169. struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
  2170. unsigned int nr_frags, unsigned int mss)
  2171. {
  2172. struct e1000_buffer *buffer_info;
  2173. unsigned int len = skb->len;
  2174. unsigned int offset = 0, size, count = 0, i;
  2175. unsigned int f;
  2176. len -= skb->data_len;
  2177. i = tx_ring->next_to_use;
  2178. while(len) {
  2179. buffer_info = &tx_ring->buffer_info[i];
  2180. size = min(len, max_per_txd);
  2181. #ifdef NETIF_F_TSO
  2182. /* Workaround for Controller erratum --
  2183. * descriptor for non-tso packet in a linear SKB that follows a
  2184. * tso gets written back prematurely before the data is fully
  2185. * DMAd to the controller */
  2186. if (!skb->data_len && tx_ring->last_tx_tso &&
  2187. !skb_shinfo(skb)->tso_size) {
  2188. tx_ring->last_tx_tso = 0;
  2189. size -= 4;
  2190. }
  2191. /* Workaround for premature desc write-backs
  2192. * in TSO mode. Append 4-byte sentinel desc */
  2193. if(unlikely(mss && !nr_frags && size == len && size > 8))
  2194. size -= 4;
  2195. #endif
  2196. /* work-around for errata 10 and it applies
  2197. * to all controllers in PCI-X mode
  2198. * The fix is to make sure that the first descriptor of a
  2199. * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
  2200. */
  2201. if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2202. (size > 2015) && count == 0))
  2203. size = 2015;
  2204. /* Workaround for potential 82544 hang in PCI-X. Avoid
  2205. * terminating buffers within evenly-aligned dwords. */
  2206. if(unlikely(adapter->pcix_82544 &&
  2207. !((unsigned long)(skb->data + offset + size - 1) & 4) &&
  2208. size > 4))
  2209. size -= 4;
  2210. buffer_info->length = size;
  2211. buffer_info->dma =
  2212. pci_map_single(adapter->pdev,
  2213. skb->data + offset,
  2214. size,
  2215. PCI_DMA_TODEVICE);
  2216. buffer_info->time_stamp = jiffies;
  2217. len -= size;
  2218. offset += size;
  2219. count++;
  2220. if(unlikely(++i == tx_ring->count)) i = 0;
  2221. }
  2222. for(f = 0; f < nr_frags; f++) {
  2223. struct skb_frag_struct *frag;
  2224. frag = &skb_shinfo(skb)->frags[f];
  2225. len = frag->size;
  2226. offset = frag->page_offset;
  2227. while(len) {
  2228. buffer_info = &tx_ring->buffer_info[i];
  2229. size = min(len, max_per_txd);
  2230. #ifdef NETIF_F_TSO
  2231. /* Workaround for premature desc write-backs
  2232. * in TSO mode. Append 4-byte sentinel desc */
  2233. if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
  2234. size -= 4;
  2235. #endif
  2236. /* Workaround for potential 82544 hang in PCI-X.
  2237. * Avoid terminating buffers within evenly-aligned
  2238. * dwords. */
  2239. if(unlikely(adapter->pcix_82544 &&
  2240. !((unsigned long)(frag->page+offset+size-1) & 4) &&
  2241. size > 4))
  2242. size -= 4;
  2243. buffer_info->length = size;
  2244. buffer_info->dma =
  2245. pci_map_page(adapter->pdev,
  2246. frag->page,
  2247. offset,
  2248. size,
  2249. PCI_DMA_TODEVICE);
  2250. buffer_info->time_stamp = jiffies;
  2251. len -= size;
  2252. offset += size;
  2253. count++;
  2254. if(unlikely(++i == tx_ring->count)) i = 0;
  2255. }
  2256. }
  2257. i = (i == 0) ? tx_ring->count - 1 : i - 1;
  2258. tx_ring->buffer_info[i].skb = skb;
  2259. tx_ring->buffer_info[first].next_to_watch = i;
  2260. return count;
  2261. }
  2262. static inline void
  2263. e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2264. int tx_flags, int count)
  2265. {
  2266. struct e1000_tx_desc *tx_desc = NULL;
  2267. struct e1000_buffer *buffer_info;
  2268. uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  2269. unsigned int i;
  2270. if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
  2271. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  2272. E1000_TXD_CMD_TSE;
  2273. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2274. if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
  2275. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  2276. }
  2277. if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
  2278. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  2279. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2280. }
  2281. if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
  2282. txd_lower |= E1000_TXD_CMD_VLE;
  2283. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  2284. }
  2285. i = tx_ring->next_to_use;
  2286. while(count--) {
  2287. buffer_info = &tx_ring->buffer_info[i];
  2288. tx_desc = E1000_TX_DESC(*tx_ring, i);
  2289. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  2290. tx_desc->lower.data =
  2291. cpu_to_le32(txd_lower | buffer_info->length);
  2292. tx_desc->upper.data = cpu_to_le32(txd_upper);
  2293. if(unlikely(++i == tx_ring->count)) i = 0;
  2294. }
  2295. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  2296. /* Force memory writes to complete before letting h/w
  2297. * know there are new descriptors to fetch. (Only
  2298. * applicable for weak-ordered memory model archs,
  2299. * such as IA-64). */
  2300. wmb();
  2301. tx_ring->next_to_use = i;
  2302. writel(i, adapter->hw.hw_addr + tx_ring->tdt);
  2303. }
  2304. /**
  2305. * 82547 workaround to avoid controller hang in half-duplex environment.
  2306. * The workaround is to avoid queuing a large packet that would span
  2307. * the internal Tx FIFO ring boundary by notifying the stack to resend
  2308. * the packet at a later time. This gives the Tx FIFO an opportunity to
  2309. * flush all packets. When that occurs, we reset the Tx FIFO pointers
  2310. * to the beginning of the Tx FIFO.
  2311. **/
  2312. #define E1000_FIFO_HDR 0x10
  2313. #define E1000_82547_PAD_LEN 0x3E0
  2314. static inline int
  2315. e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
  2316. {
  2317. uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
  2318. uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
  2319. E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
  2320. if(adapter->link_duplex != HALF_DUPLEX)
  2321. goto no_fifo_stall_required;
  2322. if(atomic_read(&adapter->tx_fifo_stall))
  2323. return 1;
  2324. if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
  2325. atomic_set(&adapter->tx_fifo_stall, 1);
  2326. return 1;
  2327. }
  2328. no_fifo_stall_required:
  2329. adapter->tx_fifo_head += skb_fifo_len;
  2330. if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
  2331. adapter->tx_fifo_head -= adapter->tx_fifo_size;
  2332. return 0;
  2333. }
  2334. #define MINIMUM_DHCP_PACKET_SIZE 282
  2335. static inline int
  2336. e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
  2337. {
  2338. struct e1000_hw *hw = &adapter->hw;
  2339. uint16_t length, offset;
  2340. if(vlan_tx_tag_present(skb)) {
  2341. if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  2342. ( adapter->hw.mng_cookie.status &
  2343. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
  2344. return 0;
  2345. }
  2346. if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
  2347. struct ethhdr *eth = (struct ethhdr *) skb->data;
  2348. if((htons(ETH_P_IP) == eth->h_proto)) {
  2349. const struct iphdr *ip =
  2350. (struct iphdr *)((uint8_t *)skb->data+14);
  2351. if(IPPROTO_UDP == ip->protocol) {
  2352. struct udphdr *udp =
  2353. (struct udphdr *)((uint8_t *)ip +
  2354. (ip->ihl << 2));
  2355. if(ntohs(udp->dest) == 67) {
  2356. offset = (uint8_t *)udp + 8 - skb->data;
  2357. length = skb->len - offset;
  2358. return e1000_mng_write_dhcp_info(hw,
  2359. (uint8_t *)udp + 8,
  2360. length);
  2361. }
  2362. }
  2363. }
  2364. }
  2365. return 0;
  2366. }
  2367. #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
  2368. static int
  2369. e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  2370. {
  2371. struct e1000_adapter *adapter = netdev_priv(netdev);
  2372. struct e1000_tx_ring *tx_ring;
  2373. unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
  2374. unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
  2375. unsigned int tx_flags = 0;
  2376. unsigned int len = skb->len;
  2377. unsigned long flags;
  2378. unsigned int nr_frags = 0;
  2379. unsigned int mss = 0;
  2380. int count = 0;
  2381. int tso;
  2382. unsigned int f;
  2383. len -= skb->data_len;
  2384. #ifdef CONFIG_E1000_MQ
  2385. tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
  2386. #else
  2387. tx_ring = adapter->tx_ring;
  2388. #endif
  2389. if (unlikely(skb->len <= 0)) {
  2390. dev_kfree_skb_any(skb);
  2391. return NETDEV_TX_OK;
  2392. }
  2393. #ifdef NETIF_F_TSO
  2394. mss = skb_shinfo(skb)->tso_size;
  2395. /* The controller does a simple calculation to
  2396. * make sure there is enough room in the FIFO before
  2397. * initiating the DMA for each buffer. The calc is:
  2398. * 4 = ceil(buffer len/mss). To make sure we don't
  2399. * overrun the FIFO, adjust the max buffer len if mss
  2400. * drops. */
  2401. if(mss) {
  2402. uint8_t hdr_len;
  2403. max_per_txd = min(mss << 2, max_per_txd);
  2404. max_txd_pwr = fls(max_per_txd) - 1;
  2405. /* TSO Workaround for 82571/2 Controllers -- if skb->data
  2406. * points to just header, pull a few bytes of payload from
  2407. * frags into skb->data */
  2408. hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
  2409. if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
  2410. (adapter->hw.mac_type == e1000_82571 ||
  2411. adapter->hw.mac_type == e1000_82572)) {
  2412. unsigned int pull_size;
  2413. pull_size = min((unsigned int)4, skb->data_len);
  2414. if (!__pskb_pull_tail(skb, pull_size)) {
  2415. printk(KERN_ERR "__pskb_pull_tail failed.\n");
  2416. dev_kfree_skb_any(skb);
  2417. return -EFAULT;
  2418. }
  2419. len = skb->len - skb->data_len;
  2420. }
  2421. }
  2422. if((mss) || (skb->ip_summed == CHECKSUM_HW))
  2423. /* reserve a descriptor for the offload context */
  2424. count++;
  2425. count++;
  2426. #else
  2427. if(skb->ip_summed == CHECKSUM_HW)
  2428. count++;
  2429. #endif
  2430. #ifdef NETIF_F_TSO
  2431. /* Controller Erratum workaround */
  2432. if (!skb->data_len && tx_ring->last_tx_tso &&
  2433. !skb_shinfo(skb)->tso_size)
  2434. count++;
  2435. #endif
  2436. count += TXD_USE_COUNT(len, max_txd_pwr);
  2437. if(adapter->pcix_82544)
  2438. count++;
  2439. /* work-around for errata 10 and it applies to all controllers
  2440. * in PCI-X mode, so add one more descriptor to the count
  2441. */
  2442. if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2443. (len > 2015)))
  2444. count++;
  2445. nr_frags = skb_shinfo(skb)->nr_frags;
  2446. for(f = 0; f < nr_frags; f++)
  2447. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
  2448. max_txd_pwr);
  2449. if(adapter->pcix_82544)
  2450. count += nr_frags;
  2451. if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
  2452. e1000_transfer_dhcp_info(adapter, skb);
  2453. local_irq_save(flags);
  2454. if (!spin_trylock(&tx_ring->tx_lock)) {
  2455. /* Collision - tell upper layer to requeue */
  2456. local_irq_restore(flags);
  2457. return NETDEV_TX_LOCKED;
  2458. }
  2459. /* need: count + 2 desc gap to keep tail from touching
  2460. * head, otherwise try next time */
  2461. if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
  2462. netif_stop_queue(netdev);
  2463. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2464. return NETDEV_TX_BUSY;
  2465. }
  2466. if(unlikely(adapter->hw.mac_type == e1000_82547)) {
  2467. if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
  2468. netif_stop_queue(netdev);
  2469. mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
  2470. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2471. return NETDEV_TX_BUSY;
  2472. }
  2473. }
  2474. if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
  2475. tx_flags |= E1000_TX_FLAGS_VLAN;
  2476. tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
  2477. }
  2478. first = tx_ring->next_to_use;
  2479. tso = e1000_tso(adapter, tx_ring, skb);
  2480. if (tso < 0) {
  2481. dev_kfree_skb_any(skb);
  2482. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2483. return NETDEV_TX_OK;
  2484. }
  2485. if (likely(tso)) {
  2486. tx_ring->last_tx_tso = 1;
  2487. tx_flags |= E1000_TX_FLAGS_TSO;
  2488. } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
  2489. tx_flags |= E1000_TX_FLAGS_CSUM;
  2490. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  2491. * 82571 hardware supports TSO capabilities for IPv6 as well...
  2492. * no longer assume, we must. */
  2493. if (likely(skb->protocol == ntohs(ETH_P_IP)))
  2494. tx_flags |= E1000_TX_FLAGS_IPV4;
  2495. e1000_tx_queue(adapter, tx_ring, tx_flags,
  2496. e1000_tx_map(adapter, tx_ring, skb, first,
  2497. max_per_txd, nr_frags, mss));
  2498. netdev->trans_start = jiffies;
  2499. /* Make sure there is space in the ring for the next send. */
  2500. if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
  2501. netif_stop_queue(netdev);
  2502. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2503. return NETDEV_TX_OK;
  2504. }
  2505. /**
  2506. * e1000_tx_timeout - Respond to a Tx Hang
  2507. * @netdev: network interface device structure
  2508. **/
  2509. static void
  2510. e1000_tx_timeout(struct net_device *netdev)
  2511. {
  2512. struct e1000_adapter *adapter = netdev_priv(netdev);
  2513. /* Do the reset outside of interrupt context */
  2514. schedule_work(&adapter->tx_timeout_task);
  2515. }
  2516. static void
  2517. e1000_tx_timeout_task(struct net_device *netdev)
  2518. {
  2519. struct e1000_adapter *adapter = netdev_priv(netdev);
  2520. adapter->tx_timeout_count++;
  2521. e1000_down(adapter);
  2522. e1000_up(adapter);
  2523. }
  2524. /**
  2525. * e1000_get_stats - Get System Network Statistics
  2526. * @netdev: network interface device structure
  2527. *
  2528. * Returns the address of the device statistics structure.
  2529. * The statistics are actually updated from the timer callback.
  2530. **/
  2531. static struct net_device_stats *
  2532. e1000_get_stats(struct net_device *netdev)
  2533. {
  2534. struct e1000_adapter *adapter = netdev_priv(netdev);
  2535. /* only return the current stats */
  2536. return &adapter->net_stats;
  2537. }
  2538. /**
  2539. * e1000_change_mtu - Change the Maximum Transfer Unit
  2540. * @netdev: network interface device structure
  2541. * @new_mtu: new value for maximum frame size
  2542. *
  2543. * Returns 0 on success, negative on failure
  2544. **/
  2545. static int
  2546. e1000_change_mtu(struct net_device *netdev, int new_mtu)
  2547. {
  2548. struct e1000_adapter *adapter = netdev_priv(netdev);
  2549. int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  2550. if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
  2551. (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  2552. DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
  2553. return -EINVAL;
  2554. }
  2555. /* Adapter-specific max frame size limits. */
  2556. switch (adapter->hw.mac_type) {
  2557. case e1000_82542_rev2_0:
  2558. case e1000_82542_rev2_1:
  2559. case e1000_82573:
  2560. if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
  2561. DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
  2562. return -EINVAL;
  2563. }
  2564. break;
  2565. case e1000_82571:
  2566. case e1000_82572:
  2567. #define MAX_STD_JUMBO_FRAME_SIZE 9234
  2568. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  2569. DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
  2570. return -EINVAL;
  2571. }
  2572. break;
  2573. default:
  2574. /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
  2575. break;
  2576. }
  2577. /* since the driver code now supports splitting a packet across
  2578. * multiple descriptors, most of the fifo related limitations on
  2579. * jumbo frame traffic have gone away.
  2580. * simply use 2k descriptors for everything.
  2581. *
  2582. * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  2583. * means we reserve 2 more, this pushes us to allocate from the next
  2584. * larger slab size
  2585. * i.e. RXBUFFER_2048 --> size-4096 slab */
  2586. /* recent hardware supports 1KB granularity */
  2587. if (adapter->hw.mac_type > e1000_82547_rev_2) {
  2588. adapter->rx_buffer_len =
  2589. ((max_frame < E1000_RXBUFFER_2048) ?
  2590. max_frame : E1000_RXBUFFER_2048);
  2591. E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
  2592. } else
  2593. adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  2594. netdev->mtu = new_mtu;
  2595. if(netif_running(netdev)) {
  2596. e1000_down(adapter);
  2597. e1000_up(adapter);
  2598. }
  2599. adapter->hw.max_frame_size = max_frame;
  2600. return 0;
  2601. }
  2602. /**
  2603. * e1000_update_stats - Update the board statistics counters
  2604. * @adapter: board private structure
  2605. **/
  2606. void
  2607. e1000_update_stats(struct e1000_adapter *adapter)
  2608. {
  2609. struct e1000_hw *hw = &adapter->hw;
  2610. unsigned long flags;
  2611. uint16_t phy_tmp;
  2612. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  2613. spin_lock_irqsave(&adapter->stats_lock, flags);
  2614. /* these counters are modified from e1000_adjust_tbi_stats,
  2615. * called from the interrupt context, so they must only
  2616. * be written while holding adapter->stats_lock
  2617. */
  2618. adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
  2619. adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
  2620. adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
  2621. adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
  2622. adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
  2623. adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
  2624. adapter->stats.roc += E1000_READ_REG(hw, ROC);
  2625. adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
  2626. adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
  2627. adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
  2628. adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
  2629. adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
  2630. adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
  2631. adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
  2632. adapter->stats.mpc += E1000_READ_REG(hw, MPC);
  2633. adapter->stats.scc += E1000_READ_REG(hw, SCC);
  2634. adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
  2635. adapter->stats.mcc += E1000_READ_REG(hw, MCC);
  2636. adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
  2637. adapter->stats.dc += E1000_READ_REG(hw, DC);
  2638. adapter->stats.sec += E1000_READ_REG(hw, SEC);
  2639. adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
  2640. adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
  2641. adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
  2642. adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
  2643. adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
  2644. adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
  2645. adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
  2646. adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
  2647. adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
  2648. adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
  2649. adapter->stats.ruc += E1000_READ_REG(hw, RUC);
  2650. adapter->stats.rfc += E1000_READ_REG(hw, RFC);
  2651. adapter->stats.rjc += E1000_READ_REG(hw, RJC);
  2652. adapter->stats.torl += E1000_READ_REG(hw, TORL);
  2653. adapter->stats.torh += E1000_READ_REG(hw, TORH);
  2654. adapter->stats.totl += E1000_READ_REG(hw, TOTL);
  2655. adapter->stats.toth += E1000_READ_REG(hw, TOTH);
  2656. adapter->stats.tpr += E1000_READ_REG(hw, TPR);
  2657. adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
  2658. adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
  2659. adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
  2660. adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
  2661. adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
  2662. adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
  2663. adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
  2664. adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
  2665. /* used for adaptive IFS */
  2666. hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
  2667. adapter->stats.tpt += hw->tx_packet_delta;
  2668. hw->collision_delta = E1000_READ_REG(hw, COLC);
  2669. adapter->stats.colc += hw->collision_delta;
  2670. if(hw->mac_type >= e1000_82543) {
  2671. adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
  2672. adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
  2673. adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
  2674. adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
  2675. adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
  2676. adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
  2677. }
  2678. if(hw->mac_type > e1000_82547_rev_2) {
  2679. adapter->stats.iac += E1000_READ_REG(hw, IAC);
  2680. adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
  2681. adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
  2682. adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
  2683. adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
  2684. adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
  2685. adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
  2686. adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
  2687. adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
  2688. }
  2689. /* Fill out the OS statistics structure */
  2690. adapter->net_stats.rx_packets = adapter->stats.gprc;
  2691. adapter->net_stats.tx_packets = adapter->stats.gptc;
  2692. adapter->net_stats.rx_bytes = adapter->stats.gorcl;
  2693. adapter->net_stats.tx_bytes = adapter->stats.gotcl;
  2694. adapter->net_stats.multicast = adapter->stats.mprc;
  2695. adapter->net_stats.collisions = adapter->stats.colc;
  2696. /* Rx Errors */
  2697. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  2698. adapter->stats.crcerrs + adapter->stats.algnerrc +
  2699. adapter->stats.rlec + adapter->stats.cexterr;
  2700. adapter->net_stats.rx_dropped = 0;
  2701. adapter->net_stats.rx_length_errors = adapter->stats.rlec;
  2702. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  2703. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  2704. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  2705. /* Tx Errors */
  2706. adapter->net_stats.tx_errors = adapter->stats.ecol +
  2707. adapter->stats.latecol;
  2708. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  2709. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  2710. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  2711. /* Tx Dropped needs to be maintained elsewhere */
  2712. /* Phy Stats */
  2713. if(hw->media_type == e1000_media_type_copper) {
  2714. if((adapter->link_speed == SPEED_1000) &&
  2715. (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  2716. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  2717. adapter->phy_stats.idle_errors += phy_tmp;
  2718. }
  2719. if((hw->mac_type <= e1000_82546) &&
  2720. (hw->phy_type == e1000_phy_m88) &&
  2721. !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
  2722. adapter->phy_stats.receive_errors += phy_tmp;
  2723. }
  2724. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  2725. }
  2726. #ifdef CONFIG_E1000_MQ
  2727. void
  2728. e1000_rx_schedule(void *data)
  2729. {
  2730. struct net_device *poll_dev, *netdev = data;
  2731. struct e1000_adapter *adapter = netdev->priv;
  2732. int this_cpu = get_cpu();
  2733. poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
  2734. if (poll_dev == NULL) {
  2735. put_cpu();
  2736. return;
  2737. }
  2738. if (likely(netif_rx_schedule_prep(poll_dev)))
  2739. __netif_rx_schedule(poll_dev);
  2740. else
  2741. e1000_irq_enable(adapter);
  2742. put_cpu();
  2743. }
  2744. #endif
  2745. /**
  2746. * e1000_intr - Interrupt Handler
  2747. * @irq: interrupt number
  2748. * @data: pointer to a network interface device structure
  2749. * @pt_regs: CPU registers structure
  2750. **/
  2751. static irqreturn_t
  2752. e1000_intr(int irq, void *data, struct pt_regs *regs)
  2753. {
  2754. struct net_device *netdev = data;
  2755. struct e1000_adapter *adapter = netdev_priv(netdev);
  2756. struct e1000_hw *hw = &adapter->hw;
  2757. uint32_t icr = E1000_READ_REG(hw, ICR);
  2758. #ifndef CONFIG_E1000_NAPI
  2759. int i;
  2760. #else
  2761. /* Interrupt Auto-Mask...upon reading ICR,
  2762. * interrupts are masked. No need for the
  2763. * IMC write, but it does mean we should
  2764. * account for it ASAP. */
  2765. if (likely(hw->mac_type >= e1000_82571))
  2766. atomic_inc(&adapter->irq_sem);
  2767. #endif
  2768. if (unlikely(!icr)) {
  2769. #ifdef CONFIG_E1000_NAPI
  2770. if (hw->mac_type >= e1000_82571)
  2771. e1000_irq_enable(adapter);
  2772. #endif
  2773. return IRQ_NONE; /* Not our interrupt */
  2774. }
  2775. if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
  2776. hw->get_link_status = 1;
  2777. mod_timer(&adapter->watchdog_timer, jiffies);
  2778. }
  2779. #ifdef CONFIG_E1000_NAPI
  2780. if (unlikely(hw->mac_type < e1000_82571)) {
  2781. atomic_inc(&adapter->irq_sem);
  2782. E1000_WRITE_REG(hw, IMC, ~0);
  2783. E1000_WRITE_FLUSH(hw);
  2784. }
  2785. #ifdef CONFIG_E1000_MQ
  2786. if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
  2787. /* We must setup the cpumask once count == 0 since
  2788. * each cpu bit is cleared when the work is done. */
  2789. adapter->rx_sched_call_data.cpumask = adapter->cpumask;
  2790. atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
  2791. atomic_set(&adapter->rx_sched_call_data.count,
  2792. adapter->num_rx_queues);
  2793. smp_call_async_mask(&adapter->rx_sched_call_data);
  2794. } else {
  2795. printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
  2796. }
  2797. #else /* if !CONFIG_E1000_MQ */
  2798. if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
  2799. __netif_rx_schedule(&adapter->polling_netdev[0]);
  2800. else
  2801. e1000_irq_enable(adapter);
  2802. #endif /* CONFIG_E1000_MQ */
  2803. #else /* if !CONFIG_E1000_NAPI */
  2804. /* Writing IMC and IMS is needed for 82547.
  2805. Due to Hub Link bus being occupied, an interrupt
  2806. de-assertion message is not able to be sent.
  2807. When an interrupt assertion message is generated later,
  2808. two messages are re-ordered and sent out.
  2809. That causes APIC to think 82547 is in de-assertion
  2810. state, while 82547 is in assertion state, resulting
  2811. in dead lock. Writing IMC forces 82547 into
  2812. de-assertion state.
  2813. */
  2814. if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
  2815. atomic_inc(&adapter->irq_sem);
  2816. E1000_WRITE_REG(hw, IMC, ~0);
  2817. }
  2818. for(i = 0; i < E1000_MAX_INTR; i++)
  2819. if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
  2820. !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
  2821. break;
  2822. if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
  2823. e1000_irq_enable(adapter);
  2824. #endif /* CONFIG_E1000_NAPI */
  2825. return IRQ_HANDLED;
  2826. }
  2827. #ifdef CONFIG_E1000_NAPI
  2828. /**
  2829. * e1000_clean - NAPI Rx polling callback
  2830. * @adapter: board private structure
  2831. **/
  2832. static int
  2833. e1000_clean(struct net_device *poll_dev, int *budget)
  2834. {
  2835. struct e1000_adapter *adapter;
  2836. int work_to_do = min(*budget, poll_dev->quota);
  2837. int tx_cleaned, i = 0, work_done = 0;
  2838. /* Must NOT use netdev_priv macro here. */
  2839. adapter = poll_dev->priv;
  2840. /* Keep link state information with original netdev */
  2841. if (!netif_carrier_ok(adapter->netdev))
  2842. goto quit_polling;
  2843. while (poll_dev != &adapter->polling_netdev[i]) {
  2844. i++;
  2845. if (unlikely(i == adapter->num_rx_queues))
  2846. BUG();
  2847. }
  2848. tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
  2849. adapter->clean_rx(adapter, &adapter->rx_ring[i],
  2850. &work_done, work_to_do);
  2851. *budget -= work_done;
  2852. poll_dev->quota -= work_done;
  2853. /* If no Tx and not enough Rx work done, exit the polling mode */
  2854. if((!tx_cleaned && (work_done == 0)) ||
  2855. !netif_running(adapter->netdev)) {
  2856. quit_polling:
  2857. netif_rx_complete(poll_dev);
  2858. e1000_irq_enable(adapter);
  2859. return 0;
  2860. }
  2861. return 1;
  2862. }
  2863. #endif
  2864. /**
  2865. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  2866. * @adapter: board private structure
  2867. **/
  2868. static boolean_t
  2869. e1000_clean_tx_irq(struct e1000_adapter *adapter,
  2870. struct e1000_tx_ring *tx_ring)
  2871. {
  2872. struct net_device *netdev = adapter->netdev;
  2873. struct e1000_tx_desc *tx_desc, *eop_desc;
  2874. struct e1000_buffer *buffer_info;
  2875. unsigned int i, eop;
  2876. boolean_t cleaned = FALSE;
  2877. i = tx_ring->next_to_clean;
  2878. eop = tx_ring->buffer_info[i].next_to_watch;
  2879. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  2880. while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
  2881. for(cleaned = FALSE; !cleaned; ) {
  2882. tx_desc = E1000_TX_DESC(*tx_ring, i);
  2883. buffer_info = &tx_ring->buffer_info[i];
  2884. cleaned = (i == eop);
  2885. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  2886. tx_desc->buffer_addr = 0;
  2887. tx_desc->lower.data = 0;
  2888. tx_desc->upper.data = 0;
  2889. if(unlikely(++i == tx_ring->count)) i = 0;
  2890. }
  2891. #ifdef CONFIG_E1000_MQ
  2892. tx_ring->tx_stats.packets++;
  2893. #endif
  2894. eop = tx_ring->buffer_info[i].next_to_watch;
  2895. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  2896. }
  2897. tx_ring->next_to_clean = i;
  2898. spin_lock(&tx_ring->tx_lock);
  2899. if(unlikely(cleaned && netif_queue_stopped(netdev) &&
  2900. netif_carrier_ok(netdev)))
  2901. netif_wake_queue(netdev);
  2902. spin_unlock(&tx_ring->tx_lock);
  2903. if (adapter->detect_tx_hung) {
  2904. /* Detect a transmit hang in hardware, this serializes the
  2905. * check with the clearing of time_stamp and movement of i */
  2906. adapter->detect_tx_hung = FALSE;
  2907. if (tx_ring->buffer_info[eop].dma &&
  2908. time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
  2909. adapter->tx_timeout_factor * HZ)
  2910. && !(E1000_READ_REG(&adapter->hw, STATUS) &
  2911. E1000_STATUS_TXOFF)) {
  2912. /* detected Tx unit hang */
  2913. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  2914. " Tx Queue <%lu>\n"
  2915. " TDH <%x>\n"
  2916. " TDT <%x>\n"
  2917. " next_to_use <%x>\n"
  2918. " next_to_clean <%x>\n"
  2919. "buffer_info[next_to_clean]\n"
  2920. " time_stamp <%lx>\n"
  2921. " next_to_watch <%x>\n"
  2922. " jiffies <%lx>\n"
  2923. " next_to_watch.status <%x>\n",
  2924. (unsigned long)((tx_ring - adapter->tx_ring) /
  2925. sizeof(struct e1000_tx_ring)),
  2926. readl(adapter->hw.hw_addr + tx_ring->tdh),
  2927. readl(adapter->hw.hw_addr + tx_ring->tdt),
  2928. tx_ring->next_to_use,
  2929. tx_ring->next_to_clean,
  2930. tx_ring->buffer_info[eop].time_stamp,
  2931. eop,
  2932. jiffies,
  2933. eop_desc->upper.fields.status);
  2934. netif_stop_queue(netdev);
  2935. }
  2936. }
  2937. return cleaned;
  2938. }
  2939. /**
  2940. * e1000_rx_checksum - Receive Checksum Offload for 82543
  2941. * @adapter: board private structure
  2942. * @status_err: receive descriptor status and error fields
  2943. * @csum: receive descriptor csum field
  2944. * @sk_buff: socket buffer with received data
  2945. **/
  2946. static inline void
  2947. e1000_rx_checksum(struct e1000_adapter *adapter,
  2948. uint32_t status_err, uint32_t csum,
  2949. struct sk_buff *skb)
  2950. {
  2951. uint16_t status = (uint16_t)status_err;
  2952. uint8_t errors = (uint8_t)(status_err >> 24);
  2953. skb->ip_summed = CHECKSUM_NONE;
  2954. /* 82543 or newer only */
  2955. if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
  2956. /* Ignore Checksum bit is set */
  2957. if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
  2958. /* TCP/UDP checksum error bit is set */
  2959. if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
  2960. /* let the stack verify checksum errors */
  2961. adapter->hw_csum_err++;
  2962. return;
  2963. }
  2964. /* TCP/UDP Checksum has not been calculated */
  2965. if(adapter->hw.mac_type <= e1000_82547_rev_2) {
  2966. if(!(status & E1000_RXD_STAT_TCPCS))
  2967. return;
  2968. } else {
  2969. if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  2970. return;
  2971. }
  2972. /* It must be a TCP or UDP packet with a valid checksum */
  2973. if (likely(status & E1000_RXD_STAT_TCPCS)) {
  2974. /* TCP checksum is good */
  2975. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2976. } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
  2977. /* IP fragment with UDP payload */
  2978. /* Hardware complements the payload checksum, so we undo it
  2979. * and then put the value in host order for further stack use.
  2980. */
  2981. csum = ntohl(csum ^ 0xFFFF);
  2982. skb->csum = csum;
  2983. skb->ip_summed = CHECKSUM_HW;
  2984. }
  2985. adapter->hw_csum_good++;
  2986. }
  2987. /**
  2988. * e1000_clean_rx_irq - Send received data up the network stack; legacy
  2989. * @adapter: board private structure
  2990. **/
  2991. static boolean_t
  2992. #ifdef CONFIG_E1000_NAPI
  2993. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  2994. struct e1000_rx_ring *rx_ring,
  2995. int *work_done, int work_to_do)
  2996. #else
  2997. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  2998. struct e1000_rx_ring *rx_ring)
  2999. #endif
  3000. {
  3001. struct net_device *netdev = adapter->netdev;
  3002. struct pci_dev *pdev = adapter->pdev;
  3003. struct e1000_rx_desc *rx_desc;
  3004. struct e1000_buffer *buffer_info;
  3005. struct sk_buff *skb;
  3006. unsigned long flags;
  3007. uint32_t length;
  3008. uint8_t last_byte;
  3009. unsigned int i;
  3010. boolean_t cleaned = FALSE;
  3011. int cleaned_count = 0;
  3012. i = rx_ring->next_to_clean;
  3013. rx_desc = E1000_RX_DESC(*rx_ring, i);
  3014. while(rx_desc->status & E1000_RXD_STAT_DD) {
  3015. buffer_info = &rx_ring->buffer_info[i];
  3016. #ifdef CONFIG_E1000_NAPI
  3017. if(*work_done >= work_to_do)
  3018. break;
  3019. (*work_done)++;
  3020. #endif
  3021. cleaned = TRUE;
  3022. cleaned_count++;
  3023. pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
  3024. PCI_DMA_FROMDEVICE);
  3025. skb = buffer_info->skb;
  3026. length = le16_to_cpu(rx_desc->length);
  3027. if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
  3028. /* All receives must fit into a single buffer */
  3029. E1000_DBG("%s: Receive packet consumed multiple"
  3030. " buffers\n", netdev->name);
  3031. dev_kfree_skb_irq(skb);
  3032. goto next_desc;
  3033. }
  3034. if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
  3035. last_byte = *(skb->data + length - 1);
  3036. if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
  3037. rx_desc->errors, length, last_byte)) {
  3038. spin_lock_irqsave(&adapter->stats_lock, flags);
  3039. e1000_tbi_adjust_stats(&adapter->hw, &adapter->stats,
  3040. length, skb->data);
  3041. spin_unlock_irqrestore(&adapter->stats_lock,
  3042. flags);
  3043. length--;
  3044. } else {
  3045. dev_kfree_skb_irq(skb);
  3046. goto next_desc;
  3047. }
  3048. }
  3049. /* Good Receive */
  3050. skb_put(skb, length - ETHERNET_FCS_SIZE);
  3051. /* Receive Checksum Offload */
  3052. e1000_rx_checksum(adapter, (uint32_t)(rx_desc->status) |
  3053. ((uint32_t)(rx_desc->errors) << 24),
  3054. rx_desc->csum, skb);
  3055. skb->protocol = eth_type_trans(skb, netdev);
  3056. #ifdef CONFIG_E1000_NAPI
  3057. if(unlikely(adapter->vlgrp &&
  3058. (rx_desc->status & E1000_RXD_STAT_VP))) {
  3059. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3060. le16_to_cpu(rx_desc->special) &
  3061. E1000_RXD_SPC_VLAN_MASK);
  3062. } else {
  3063. netif_receive_skb(skb);
  3064. }
  3065. #else /* CONFIG_E1000_NAPI */
  3066. if(unlikely(adapter->vlgrp &&
  3067. (rx_desc->status & E1000_RXD_STAT_VP))) {
  3068. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3069. le16_to_cpu(rx_desc->special) &
  3070. E1000_RXD_SPC_VLAN_MASK);
  3071. } else {
  3072. netif_rx(skb);
  3073. }
  3074. #endif /* CONFIG_E1000_NAPI */
  3075. netdev->last_rx = jiffies;
  3076. #ifdef CONFIG_E1000_MQ
  3077. rx_ring->rx_stats.packets++;
  3078. rx_ring->rx_stats.bytes += length;
  3079. #endif
  3080. next_desc:
  3081. rx_desc->status = 0;
  3082. /* return some buffers to hardware, one at a time is too slow */
  3083. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3084. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3085. cleaned_count = 0;
  3086. }
  3087. }
  3088. rx_ring->next_to_clean = i;
  3089. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3090. if (cleaned_count)
  3091. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3092. return cleaned;
  3093. }
  3094. /**
  3095. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  3096. * @adapter: board private structure
  3097. **/
  3098. static boolean_t
  3099. #ifdef CONFIG_E1000_NAPI
  3100. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3101. struct e1000_rx_ring *rx_ring,
  3102. int *work_done, int work_to_do)
  3103. #else
  3104. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3105. struct e1000_rx_ring *rx_ring)
  3106. #endif
  3107. {
  3108. union e1000_rx_desc_packet_split *rx_desc;
  3109. struct net_device *netdev = adapter->netdev;
  3110. struct pci_dev *pdev = adapter->pdev;
  3111. struct e1000_buffer *buffer_info;
  3112. struct e1000_ps_page *ps_page;
  3113. struct e1000_ps_page_dma *ps_page_dma;
  3114. struct sk_buff *skb;
  3115. unsigned int i, j;
  3116. uint32_t length, staterr;
  3117. int cleaned_count = 0;
  3118. boolean_t cleaned = FALSE;
  3119. i = rx_ring->next_to_clean;
  3120. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3121. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3122. while(staterr & E1000_RXD_STAT_DD) {
  3123. buffer_info = &rx_ring->buffer_info[i];
  3124. ps_page = &rx_ring->ps_page[i];
  3125. ps_page_dma = &rx_ring->ps_page_dma[i];
  3126. #ifdef CONFIG_E1000_NAPI
  3127. if(unlikely(*work_done >= work_to_do))
  3128. break;
  3129. (*work_done)++;
  3130. #endif
  3131. cleaned = TRUE;
  3132. cleaned_count++;
  3133. pci_unmap_single(pdev, buffer_info->dma,
  3134. buffer_info->length,
  3135. PCI_DMA_FROMDEVICE);
  3136. skb = buffer_info->skb;
  3137. if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
  3138. E1000_DBG("%s: Packet Split buffers didn't pick up"
  3139. " the full packet\n", netdev->name);
  3140. dev_kfree_skb_irq(skb);
  3141. goto next_desc;
  3142. }
  3143. if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
  3144. dev_kfree_skb_irq(skb);
  3145. goto next_desc;
  3146. }
  3147. length = le16_to_cpu(rx_desc->wb.middle.length0);
  3148. if(unlikely(!length)) {
  3149. E1000_DBG("%s: Last part of the packet spanning"
  3150. " multiple descriptors\n", netdev->name);
  3151. dev_kfree_skb_irq(skb);
  3152. goto next_desc;
  3153. }
  3154. /* Good Receive */
  3155. skb_put(skb, length);
  3156. for(j = 0; j < adapter->rx_ps_pages; j++) {
  3157. if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
  3158. break;
  3159. pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
  3160. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  3161. ps_page_dma->ps_page_dma[j] = 0;
  3162. skb_shinfo(skb)->frags[j].page =
  3163. ps_page->ps_page[j];
  3164. ps_page->ps_page[j] = NULL;
  3165. skb_shinfo(skb)->frags[j].page_offset = 0;
  3166. skb_shinfo(skb)->frags[j].size = length;
  3167. skb_shinfo(skb)->nr_frags++;
  3168. skb->len += length;
  3169. skb->data_len += length;
  3170. }
  3171. e1000_rx_checksum(adapter, staterr,
  3172. rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
  3173. skb->protocol = eth_type_trans(skb, netdev);
  3174. if(likely(rx_desc->wb.upper.header_status &
  3175. E1000_RXDPS_HDRSTAT_HDRSP)) {
  3176. adapter->rx_hdr_split++;
  3177. #ifdef HAVE_RX_ZERO_COPY
  3178. skb_shinfo(skb)->zero_copy = TRUE;
  3179. #endif
  3180. }
  3181. #ifdef CONFIG_E1000_NAPI
  3182. if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3183. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3184. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3185. E1000_RXD_SPC_VLAN_MASK);
  3186. } else {
  3187. netif_receive_skb(skb);
  3188. }
  3189. #else /* CONFIG_E1000_NAPI */
  3190. if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3191. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3192. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3193. E1000_RXD_SPC_VLAN_MASK);
  3194. } else {
  3195. netif_rx(skb);
  3196. }
  3197. #endif /* CONFIG_E1000_NAPI */
  3198. netdev->last_rx = jiffies;
  3199. #ifdef CONFIG_E1000_MQ
  3200. rx_ring->rx_stats.packets++;
  3201. rx_ring->rx_stats.bytes += length;
  3202. #endif
  3203. next_desc:
  3204. rx_desc->wb.middle.status_error &= ~0xFF;
  3205. buffer_info->skb = NULL;
  3206. /* return some buffers to hardware, one at a time is too slow */
  3207. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3208. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3209. cleaned_count = 0;
  3210. }
  3211. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3212. }
  3213. rx_ring->next_to_clean = i;
  3214. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3215. if (cleaned_count)
  3216. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3217. return cleaned;
  3218. }
  3219. /**
  3220. * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
  3221. * @adapter: address of board private structure
  3222. **/
  3223. static void
  3224. e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  3225. struct e1000_rx_ring *rx_ring,
  3226. int cleaned_count)
  3227. {
  3228. struct net_device *netdev = adapter->netdev;
  3229. struct pci_dev *pdev = adapter->pdev;
  3230. struct e1000_rx_desc *rx_desc;
  3231. struct e1000_buffer *buffer_info;
  3232. struct sk_buff *skb;
  3233. unsigned int i;
  3234. unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
  3235. i = rx_ring->next_to_use;
  3236. buffer_info = &rx_ring->buffer_info[i];
  3237. while(!buffer_info->skb) {
  3238. skb = dev_alloc_skb(bufsz);
  3239. if(unlikely(!skb)) {
  3240. /* Better luck next round */
  3241. adapter->alloc_rx_buff_failed++;
  3242. break;
  3243. }
  3244. /* Fix for errata 23, can't cross 64kB boundary */
  3245. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3246. struct sk_buff *oldskb = skb;
  3247. DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
  3248. "at %p\n", bufsz, skb->data);
  3249. /* Try again, without freeing the previous */
  3250. skb = dev_alloc_skb(bufsz);
  3251. /* Failed allocation, critical failure */
  3252. if (!skb) {
  3253. dev_kfree_skb(oldskb);
  3254. break;
  3255. }
  3256. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3257. /* give up */
  3258. dev_kfree_skb(skb);
  3259. dev_kfree_skb(oldskb);
  3260. break; /* while !buffer_info->skb */
  3261. } else {
  3262. /* Use new allocation */
  3263. dev_kfree_skb(oldskb);
  3264. }
  3265. }
  3266. /* Make buffer alignment 2 beyond a 16 byte boundary
  3267. * this will result in a 16 byte aligned IP header after
  3268. * the 14 byte MAC header is removed
  3269. */
  3270. skb_reserve(skb, NET_IP_ALIGN);
  3271. skb->dev = netdev;
  3272. buffer_info->skb = skb;
  3273. buffer_info->length = adapter->rx_buffer_len;
  3274. buffer_info->dma = pci_map_single(pdev,
  3275. skb->data,
  3276. adapter->rx_buffer_len,
  3277. PCI_DMA_FROMDEVICE);
  3278. /* Fix for errata 23, can't cross 64kB boundary */
  3279. if (!e1000_check_64k_bound(adapter,
  3280. (void *)(unsigned long)buffer_info->dma,
  3281. adapter->rx_buffer_len)) {
  3282. DPRINTK(RX_ERR, ERR,
  3283. "dma align check failed: %u bytes at %p\n",
  3284. adapter->rx_buffer_len,
  3285. (void *)(unsigned long)buffer_info->dma);
  3286. dev_kfree_skb(skb);
  3287. buffer_info->skb = NULL;
  3288. pci_unmap_single(pdev, buffer_info->dma,
  3289. adapter->rx_buffer_len,
  3290. PCI_DMA_FROMDEVICE);
  3291. break; /* while !buffer_info->skb */
  3292. }
  3293. rx_desc = E1000_RX_DESC(*rx_ring, i);
  3294. rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  3295. if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
  3296. /* Force memory writes to complete before letting h/w
  3297. * know there are new descriptors to fetch. (Only
  3298. * applicable for weak-ordered memory model archs,
  3299. * such as IA-64). */
  3300. wmb();
  3301. writel(i, adapter->hw.hw_addr + rx_ring->rdt);
  3302. }
  3303. if(unlikely(++i == rx_ring->count)) i = 0;
  3304. buffer_info = &rx_ring->buffer_info[i];
  3305. }
  3306. rx_ring->next_to_use = i;
  3307. }
  3308. /**
  3309. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  3310. * @adapter: address of board private structure
  3311. **/
  3312. static void
  3313. e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  3314. struct e1000_rx_ring *rx_ring,
  3315. int cleaned_count)
  3316. {
  3317. struct net_device *netdev = adapter->netdev;
  3318. struct pci_dev *pdev = adapter->pdev;
  3319. union e1000_rx_desc_packet_split *rx_desc;
  3320. struct e1000_buffer *buffer_info;
  3321. struct e1000_ps_page *ps_page;
  3322. struct e1000_ps_page_dma *ps_page_dma;
  3323. struct sk_buff *skb;
  3324. unsigned int i, j;
  3325. i = rx_ring->next_to_use;
  3326. buffer_info = &rx_ring->buffer_info[i];
  3327. ps_page = &rx_ring->ps_page[i];
  3328. ps_page_dma = &rx_ring->ps_page_dma[i];
  3329. while (cleaned_count--) {
  3330. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3331. for(j = 0; j < PS_PAGE_BUFFERS; j++) {
  3332. if (j < adapter->rx_ps_pages) {
  3333. if (likely(!ps_page->ps_page[j])) {
  3334. ps_page->ps_page[j] =
  3335. alloc_page(GFP_ATOMIC);
  3336. if (unlikely(!ps_page->ps_page[j]))
  3337. goto no_buffers;
  3338. ps_page_dma->ps_page_dma[j] =
  3339. pci_map_page(pdev,
  3340. ps_page->ps_page[j],
  3341. 0, PAGE_SIZE,
  3342. PCI_DMA_FROMDEVICE);
  3343. }
  3344. /* Refresh the desc even if buffer_addrs didn't
  3345. * change because each write-back erases
  3346. * this info.
  3347. */
  3348. rx_desc->read.buffer_addr[j+1] =
  3349. cpu_to_le64(ps_page_dma->ps_page_dma[j]);
  3350. } else
  3351. rx_desc->read.buffer_addr[j+1] = ~0;
  3352. }
  3353. skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
  3354. if(unlikely(!skb))
  3355. break;
  3356. /* Make buffer alignment 2 beyond a 16 byte boundary
  3357. * this will result in a 16 byte aligned IP header after
  3358. * the 14 byte MAC header is removed
  3359. */
  3360. skb_reserve(skb, NET_IP_ALIGN);
  3361. skb->dev = netdev;
  3362. buffer_info->skb = skb;
  3363. buffer_info->length = adapter->rx_ps_bsize0;
  3364. buffer_info->dma = pci_map_single(pdev, skb->data,
  3365. adapter->rx_ps_bsize0,
  3366. PCI_DMA_FROMDEVICE);
  3367. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  3368. if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
  3369. /* Force memory writes to complete before letting h/w
  3370. * know there are new descriptors to fetch. (Only
  3371. * applicable for weak-ordered memory model archs,
  3372. * such as IA-64). */
  3373. wmb();
  3374. /* Hardware increments by 16 bytes, but packet split
  3375. * descriptors are 32 bytes...so we increment tail
  3376. * twice as much.
  3377. */
  3378. writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
  3379. }
  3380. if(unlikely(++i == rx_ring->count)) i = 0;
  3381. buffer_info = &rx_ring->buffer_info[i];
  3382. ps_page = &rx_ring->ps_page[i];
  3383. ps_page_dma = &rx_ring->ps_page_dma[i];
  3384. }
  3385. no_buffers:
  3386. rx_ring->next_to_use = i;
  3387. }
  3388. /**
  3389. * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
  3390. * @adapter:
  3391. **/
  3392. static void
  3393. e1000_smartspeed(struct e1000_adapter *adapter)
  3394. {
  3395. uint16_t phy_status;
  3396. uint16_t phy_ctrl;
  3397. if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
  3398. !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
  3399. return;
  3400. if(adapter->smartspeed == 0) {
  3401. /* If Master/Slave config fault is asserted twice,
  3402. * we assume back-to-back */
  3403. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  3404. if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  3405. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  3406. if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  3407. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  3408. if(phy_ctrl & CR_1000T_MS_ENABLE) {
  3409. phy_ctrl &= ~CR_1000T_MS_ENABLE;
  3410. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
  3411. phy_ctrl);
  3412. adapter->smartspeed++;
  3413. if(!e1000_phy_setup_autoneg(&adapter->hw) &&
  3414. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
  3415. &phy_ctrl)) {
  3416. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  3417. MII_CR_RESTART_AUTO_NEG);
  3418. e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
  3419. phy_ctrl);
  3420. }
  3421. }
  3422. return;
  3423. } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
  3424. /* If still no link, perhaps using 2/3 pair cable */
  3425. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  3426. phy_ctrl |= CR_1000T_MS_ENABLE;
  3427. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
  3428. if(!e1000_phy_setup_autoneg(&adapter->hw) &&
  3429. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
  3430. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  3431. MII_CR_RESTART_AUTO_NEG);
  3432. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
  3433. }
  3434. }
  3435. /* Restart process after E1000_SMARTSPEED_MAX iterations */
  3436. if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
  3437. adapter->smartspeed = 0;
  3438. }
  3439. /**
  3440. * e1000_ioctl -
  3441. * @netdev:
  3442. * @ifreq:
  3443. * @cmd:
  3444. **/
  3445. static int
  3446. e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3447. {
  3448. switch (cmd) {
  3449. case SIOCGMIIPHY:
  3450. case SIOCGMIIREG:
  3451. case SIOCSMIIREG:
  3452. return e1000_mii_ioctl(netdev, ifr, cmd);
  3453. default:
  3454. return -EOPNOTSUPP;
  3455. }
  3456. }
  3457. /**
  3458. * e1000_mii_ioctl -
  3459. * @netdev:
  3460. * @ifreq:
  3461. * @cmd:
  3462. **/
  3463. static int
  3464. e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3465. {
  3466. struct e1000_adapter *adapter = netdev_priv(netdev);
  3467. struct mii_ioctl_data *data = if_mii(ifr);
  3468. int retval;
  3469. uint16_t mii_reg;
  3470. uint16_t spddplx;
  3471. unsigned long flags;
  3472. if(adapter->hw.media_type != e1000_media_type_copper)
  3473. return -EOPNOTSUPP;
  3474. switch (cmd) {
  3475. case SIOCGMIIPHY:
  3476. data->phy_id = adapter->hw.phy_addr;
  3477. break;
  3478. case SIOCGMIIREG:
  3479. if(!capable(CAP_NET_ADMIN))
  3480. return -EPERM;
  3481. spin_lock_irqsave(&adapter->stats_lock, flags);
  3482. if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  3483. &data->val_out)) {
  3484. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3485. return -EIO;
  3486. }
  3487. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3488. break;
  3489. case SIOCSMIIREG:
  3490. if(!capable(CAP_NET_ADMIN))
  3491. return -EPERM;
  3492. if(data->reg_num & ~(0x1F))
  3493. return -EFAULT;
  3494. mii_reg = data->val_in;
  3495. spin_lock_irqsave(&adapter->stats_lock, flags);
  3496. if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
  3497. mii_reg)) {
  3498. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3499. return -EIO;
  3500. }
  3501. if(adapter->hw.phy_type == e1000_phy_m88) {
  3502. switch (data->reg_num) {
  3503. case PHY_CTRL:
  3504. if(mii_reg & MII_CR_POWER_DOWN)
  3505. break;
  3506. if(mii_reg & MII_CR_AUTO_NEG_EN) {
  3507. adapter->hw.autoneg = 1;
  3508. adapter->hw.autoneg_advertised = 0x2F;
  3509. } else {
  3510. if (mii_reg & 0x40)
  3511. spddplx = SPEED_1000;
  3512. else if (mii_reg & 0x2000)
  3513. spddplx = SPEED_100;
  3514. else
  3515. spddplx = SPEED_10;
  3516. spddplx += (mii_reg & 0x100)
  3517. ? FULL_DUPLEX :
  3518. HALF_DUPLEX;
  3519. retval = e1000_set_spd_dplx(adapter,
  3520. spddplx);
  3521. if(retval) {
  3522. spin_unlock_irqrestore(
  3523. &adapter->stats_lock,
  3524. flags);
  3525. return retval;
  3526. }
  3527. }
  3528. if(netif_running(adapter->netdev)) {
  3529. e1000_down(adapter);
  3530. e1000_up(adapter);
  3531. } else
  3532. e1000_reset(adapter);
  3533. break;
  3534. case M88E1000_PHY_SPEC_CTRL:
  3535. case M88E1000_EXT_PHY_SPEC_CTRL:
  3536. if(e1000_phy_reset(&adapter->hw)) {
  3537. spin_unlock_irqrestore(
  3538. &adapter->stats_lock, flags);
  3539. return -EIO;
  3540. }
  3541. break;
  3542. }
  3543. } else {
  3544. switch (data->reg_num) {
  3545. case PHY_CTRL:
  3546. if(mii_reg & MII_CR_POWER_DOWN)
  3547. break;
  3548. if(netif_running(adapter->netdev)) {
  3549. e1000_down(adapter);
  3550. e1000_up(adapter);
  3551. } else
  3552. e1000_reset(adapter);
  3553. break;
  3554. }
  3555. }
  3556. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3557. break;
  3558. default:
  3559. return -EOPNOTSUPP;
  3560. }
  3561. return E1000_SUCCESS;
  3562. }
  3563. void
  3564. e1000_pci_set_mwi(struct e1000_hw *hw)
  3565. {
  3566. struct e1000_adapter *adapter = hw->back;
  3567. int ret_val = pci_set_mwi(adapter->pdev);
  3568. if(ret_val)
  3569. DPRINTK(PROBE, ERR, "Error in setting MWI\n");
  3570. }
  3571. void
  3572. e1000_pci_clear_mwi(struct e1000_hw *hw)
  3573. {
  3574. struct e1000_adapter *adapter = hw->back;
  3575. pci_clear_mwi(adapter->pdev);
  3576. }
  3577. void
  3578. e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  3579. {
  3580. struct e1000_adapter *adapter = hw->back;
  3581. pci_read_config_word(adapter->pdev, reg, value);
  3582. }
  3583. void
  3584. e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  3585. {
  3586. struct e1000_adapter *adapter = hw->back;
  3587. pci_write_config_word(adapter->pdev, reg, *value);
  3588. }
  3589. uint32_t
  3590. e1000_io_read(struct e1000_hw *hw, unsigned long port)
  3591. {
  3592. return inl(port);
  3593. }
  3594. void
  3595. e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
  3596. {
  3597. outl(value, port);
  3598. }
  3599. static void
  3600. e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
  3601. {
  3602. struct e1000_adapter *adapter = netdev_priv(netdev);
  3603. uint32_t ctrl, rctl;
  3604. e1000_irq_disable(adapter);
  3605. adapter->vlgrp = grp;
  3606. if(grp) {
  3607. /* enable VLAN tag insert/strip */
  3608. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3609. ctrl |= E1000_CTRL_VME;
  3610. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3611. /* enable VLAN receive filtering */
  3612. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3613. rctl |= E1000_RCTL_VFE;
  3614. rctl &= ~E1000_RCTL_CFIEN;
  3615. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3616. e1000_update_mng_vlan(adapter);
  3617. } else {
  3618. /* disable VLAN tag insert/strip */
  3619. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3620. ctrl &= ~E1000_CTRL_VME;
  3621. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3622. /* disable VLAN filtering */
  3623. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3624. rctl &= ~E1000_RCTL_VFE;
  3625. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3626. if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
  3627. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  3628. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  3629. }
  3630. }
  3631. e1000_irq_enable(adapter);
  3632. }
  3633. static void
  3634. e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
  3635. {
  3636. struct e1000_adapter *adapter = netdev_priv(netdev);
  3637. uint32_t vfta, index;
  3638. if((adapter->hw.mng_cookie.status &
  3639. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  3640. (vid == adapter->mng_vlan_id))
  3641. return;
  3642. /* add VID to filter table */
  3643. index = (vid >> 5) & 0x7F;
  3644. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  3645. vfta |= (1 << (vid & 0x1F));
  3646. e1000_write_vfta(&adapter->hw, index, vfta);
  3647. }
  3648. static void
  3649. e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
  3650. {
  3651. struct e1000_adapter *adapter = netdev_priv(netdev);
  3652. uint32_t vfta, index;
  3653. e1000_irq_disable(adapter);
  3654. if(adapter->vlgrp)
  3655. adapter->vlgrp->vlan_devices[vid] = NULL;
  3656. e1000_irq_enable(adapter);
  3657. if((adapter->hw.mng_cookie.status &
  3658. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  3659. (vid == adapter->mng_vlan_id)) {
  3660. /* release control to f/w */
  3661. e1000_release_hw_control(adapter);
  3662. return;
  3663. }
  3664. /* remove VID from filter table */
  3665. index = (vid >> 5) & 0x7F;
  3666. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  3667. vfta &= ~(1 << (vid & 0x1F));
  3668. e1000_write_vfta(&adapter->hw, index, vfta);
  3669. }
  3670. static void
  3671. e1000_restore_vlan(struct e1000_adapter *adapter)
  3672. {
  3673. e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  3674. if(adapter->vlgrp) {
  3675. uint16_t vid;
  3676. for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  3677. if(!adapter->vlgrp->vlan_devices[vid])
  3678. continue;
  3679. e1000_vlan_rx_add_vid(adapter->netdev, vid);
  3680. }
  3681. }
  3682. }
  3683. int
  3684. e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
  3685. {
  3686. adapter->hw.autoneg = 0;
  3687. /* Fiber NICs only allow 1000 gbps Full duplex */
  3688. if((adapter->hw.media_type == e1000_media_type_fiber) &&
  3689. spddplx != (SPEED_1000 + DUPLEX_FULL)) {
  3690. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  3691. return -EINVAL;
  3692. }
  3693. switch(spddplx) {
  3694. case SPEED_10 + DUPLEX_HALF:
  3695. adapter->hw.forced_speed_duplex = e1000_10_half;
  3696. break;
  3697. case SPEED_10 + DUPLEX_FULL:
  3698. adapter->hw.forced_speed_duplex = e1000_10_full;
  3699. break;
  3700. case SPEED_100 + DUPLEX_HALF:
  3701. adapter->hw.forced_speed_duplex = e1000_100_half;
  3702. break;
  3703. case SPEED_100 + DUPLEX_FULL:
  3704. adapter->hw.forced_speed_duplex = e1000_100_full;
  3705. break;
  3706. case SPEED_1000 + DUPLEX_FULL:
  3707. adapter->hw.autoneg = 1;
  3708. adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
  3709. break;
  3710. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  3711. default:
  3712. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  3713. return -EINVAL;
  3714. }
  3715. return 0;
  3716. }
  3717. #ifdef CONFIG_PM
  3718. static int
  3719. e1000_suspend(struct pci_dev *pdev, pm_message_t state)
  3720. {
  3721. struct net_device *netdev = pci_get_drvdata(pdev);
  3722. struct e1000_adapter *adapter = netdev_priv(netdev);
  3723. uint32_t ctrl, ctrl_ext, rctl, manc, status;
  3724. uint32_t wufc = adapter->wol;
  3725. netif_device_detach(netdev);
  3726. if(netif_running(netdev))
  3727. e1000_down(adapter);
  3728. status = E1000_READ_REG(&adapter->hw, STATUS);
  3729. if(status & E1000_STATUS_LU)
  3730. wufc &= ~E1000_WUFC_LNKC;
  3731. if(wufc) {
  3732. e1000_setup_rctl(adapter);
  3733. e1000_set_multi(netdev);
  3734. /* turn on all-multi mode if wake on multicast is enabled */
  3735. if(adapter->wol & E1000_WUFC_MC) {
  3736. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3737. rctl |= E1000_RCTL_MPE;
  3738. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3739. }
  3740. if(adapter->hw.mac_type >= e1000_82540) {
  3741. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3742. /* advertise wake from D3Cold */
  3743. #define E1000_CTRL_ADVD3WUC 0x00100000
  3744. /* phy power management enable */
  3745. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  3746. ctrl |= E1000_CTRL_ADVD3WUC |
  3747. E1000_CTRL_EN_PHY_PWR_MGMT;
  3748. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3749. }
  3750. if(adapter->hw.media_type == e1000_media_type_fiber ||
  3751. adapter->hw.media_type == e1000_media_type_internal_serdes) {
  3752. /* keep the laser running in D3 */
  3753. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  3754. ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
  3755. E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
  3756. }
  3757. /* Allow time for pending master requests to run */
  3758. e1000_disable_pciex_master(&adapter->hw);
  3759. E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
  3760. E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
  3761. pci_enable_wake(pdev, 3, 1);
  3762. pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
  3763. } else {
  3764. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  3765. E1000_WRITE_REG(&adapter->hw, WUFC, 0);
  3766. pci_enable_wake(pdev, 3, 0);
  3767. pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
  3768. }
  3769. pci_save_state(pdev);
  3770. if(adapter->hw.mac_type >= e1000_82540 &&
  3771. adapter->hw.media_type == e1000_media_type_copper) {
  3772. manc = E1000_READ_REG(&adapter->hw, MANC);
  3773. if(manc & E1000_MANC_SMBUS_EN) {
  3774. manc |= E1000_MANC_ARP_EN;
  3775. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  3776. pci_enable_wake(pdev, 3, 1);
  3777. pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
  3778. }
  3779. }
  3780. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  3781. * would have already happened in close and is redundant. */
  3782. e1000_release_hw_control(adapter);
  3783. pci_disable_device(pdev);
  3784. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3785. return 0;
  3786. }
  3787. static int
  3788. e1000_resume(struct pci_dev *pdev)
  3789. {
  3790. struct net_device *netdev = pci_get_drvdata(pdev);
  3791. struct e1000_adapter *adapter = netdev_priv(netdev);
  3792. uint32_t manc, ret_val;
  3793. pci_set_power_state(pdev, PCI_D0);
  3794. pci_restore_state(pdev);
  3795. ret_val = pci_enable_device(pdev);
  3796. pci_set_master(pdev);
  3797. pci_enable_wake(pdev, PCI_D3hot, 0);
  3798. pci_enable_wake(pdev, PCI_D3cold, 0);
  3799. e1000_reset(adapter);
  3800. E1000_WRITE_REG(&adapter->hw, WUS, ~0);
  3801. if(netif_running(netdev))
  3802. e1000_up(adapter);
  3803. netif_device_attach(netdev);
  3804. if(adapter->hw.mac_type >= e1000_82540 &&
  3805. adapter->hw.media_type == e1000_media_type_copper) {
  3806. manc = E1000_READ_REG(&adapter->hw, MANC);
  3807. manc &= ~(E1000_MANC_ARP_EN);
  3808. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  3809. }
  3810. /* If the controller is 82573 and f/w is AMT, do not set
  3811. * DRV_LOAD until the interface is up. For all other cases,
  3812. * let the f/w know that the h/w is now under the control
  3813. * of the driver. */
  3814. if (adapter->hw.mac_type != e1000_82573 ||
  3815. !e1000_check_mng_mode(&adapter->hw))
  3816. e1000_get_hw_control(adapter);
  3817. return 0;
  3818. }
  3819. #endif
  3820. #ifdef CONFIG_NET_POLL_CONTROLLER
  3821. /*
  3822. * Polling 'interrupt' - used by things like netconsole to send skbs
  3823. * without having to re-enable interrupts. It's not called while
  3824. * the interrupt routine is executing.
  3825. */
  3826. static void
  3827. e1000_netpoll(struct net_device *netdev)
  3828. {
  3829. struct e1000_adapter *adapter = netdev_priv(netdev);
  3830. disable_irq(adapter->pdev->irq);
  3831. e1000_intr(adapter->pdev->irq, netdev, NULL);
  3832. e1000_clean_tx_irq(adapter, adapter->tx_ring);
  3833. #ifndef CONFIG_E1000_NAPI
  3834. adapter->clean_rx(adapter, adapter->rx_ring);
  3835. #endif
  3836. enable_irq(adapter->pdev->irq);
  3837. }
  3838. #endif
  3839. /* e1000_main.c */