e1000_main.c 135 KB

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