e1000_main.c 130 KB

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