e1000_main.c 135 KB

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