e1000_main.c 152 KB

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