e1000_main.c 146 KB

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