e1000_main.c 149 KB

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