e1000_main.c 153 KB

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