e100.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2006 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. /*
  21. * e100.c: Intel(R) PRO/100 ethernet driver
  22. *
  23. * (Re)written 2003 by scott.feldman@intel.com. Based loosely on
  24. * original e100 driver, but better described as a munging of
  25. * e100, e1000, eepro100, tg3, 8139cp, and other drivers.
  26. *
  27. * References:
  28. * Intel 8255x 10/100 Mbps Ethernet Controller Family,
  29. * Open Source Software Developers Manual,
  30. * http://sourceforge.net/projects/e1000
  31. *
  32. *
  33. * Theory of Operation
  34. *
  35. * I. General
  36. *
  37. * The driver supports Intel(R) 10/100 Mbps PCI Fast Ethernet
  38. * controller family, which includes the 82557, 82558, 82559, 82550,
  39. * 82551, and 82562 devices. 82558 and greater controllers
  40. * integrate the Intel 82555 PHY. The controllers are used in
  41. * server and client network interface cards, as well as in
  42. * LAN-On-Motherboard (LOM), CardBus, MiniPCI, and ICHx
  43. * configurations. 8255x supports a 32-bit linear addressing
  44. * mode and operates at 33Mhz PCI clock rate.
  45. *
  46. * II. Driver Operation
  47. *
  48. * Memory-mapped mode is used exclusively to access the device's
  49. * shared-memory structure, the Control/Status Registers (CSR). All
  50. * setup, configuration, and control of the device, including queuing
  51. * of Tx, Rx, and configuration commands is through the CSR.
  52. * cmd_lock serializes accesses to the CSR command register. cb_lock
  53. * protects the shared Command Block List (CBL).
  54. *
  55. * 8255x is highly MII-compliant and all access to the PHY go
  56. * through the Management Data Interface (MDI). Consequently, the
  57. * driver leverages the mii.c library shared with other MII-compliant
  58. * devices.
  59. *
  60. * Big- and Little-Endian byte order as well as 32- and 64-bit
  61. * archs are supported. Weak-ordered memory and non-cache-coherent
  62. * archs are supported.
  63. *
  64. * III. Transmit
  65. *
  66. * A Tx skb is mapped and hangs off of a TCB. TCBs are linked
  67. * together in a fixed-size ring (CBL) thus forming the flexible mode
  68. * memory structure. A TCB marked with the suspend-bit indicates
  69. * the end of the ring. The last TCB processed suspends the
  70. * controller, and the controller can be restarted by issue a CU
  71. * resume command to continue from the suspend point, or a CU start
  72. * command to start at a given position in the ring.
  73. *
  74. * Non-Tx commands (config, multicast setup, etc) are linked
  75. * into the CBL ring along with Tx commands. The common structure
  76. * used for both Tx and non-Tx commands is the Command Block (CB).
  77. *
  78. * cb_to_use is the next CB to use for queuing a command; cb_to_clean
  79. * is the next CB to check for completion; cb_to_send is the first
  80. * CB to start on in case of a previous failure to resume. CB clean
  81. * up happens in interrupt context in response to a CU interrupt.
  82. * cbs_avail keeps track of number of free CB resources available.
  83. *
  84. * Hardware padding of short packets to minimum packet size is
  85. * enabled. 82557 pads with 7Eh, while the later controllers pad
  86. * with 00h.
  87. *
  88. * IV. Recieve
  89. *
  90. * The Receive Frame Area (RFA) comprises a ring of Receive Frame
  91. * Descriptors (RFD) + data buffer, thus forming the simplified mode
  92. * memory structure. Rx skbs are allocated to contain both the RFD
  93. * and the data buffer, but the RFD is pulled off before the skb is
  94. * indicated. The data buffer is aligned such that encapsulated
  95. * protocol headers are u32-aligned. Since the RFD is part of the
  96. * mapped shared memory, and completion status is contained within
  97. * the RFD, the RFD must be dma_sync'ed to maintain a consistent
  98. * view from software and hardware.
  99. *
  100. * Under typical operation, the receive unit (RU) is start once,
  101. * and the controller happily fills RFDs as frames arrive. If
  102. * replacement RFDs cannot be allocated, or the RU goes non-active,
  103. * the RU must be restarted. Frame arrival generates an interrupt,
  104. * and Rx indication and re-allocation happen in the same context,
  105. * therefore no locking is required. A software-generated interrupt
  106. * is generated from the watchdog to recover from a failed allocation
  107. * senario where all Rx resources have been indicated and none re-
  108. * placed.
  109. *
  110. * V. Miscellaneous
  111. *
  112. * VLAN offloading of tagging, stripping and filtering is not
  113. * supported, but driver will accommodate the extra 4-byte VLAN tag
  114. * for processing by upper layers. Tx/Rx Checksum offloading is not
  115. * supported. Tx Scatter/Gather is not supported. Jumbo Frames is
  116. * not supported (hardware limitation).
  117. *
  118. * MagicPacket(tm) WoL support is enabled/disabled via ethtool.
  119. *
  120. * Thanks to JC (jchapman@katalix.com) for helping with
  121. * testing/troubleshooting the development driver.
  122. *
  123. * TODO:
  124. * o several entry points race with dev->close
  125. * o check for tx-no-resources/stop Q races with tx clean/wake Q
  126. *
  127. * FIXES:
  128. * 2005/12/02 - Michael O'Donnell <Michael.ODonnell at stratus dot com>
  129. * - Stratus87247: protect MDI control register manipulations
  130. */
  131. #include <linux/module.h>
  132. #include <linux/moduleparam.h>
  133. #include <linux/kernel.h>
  134. #include <linux/types.h>
  135. #include <linux/slab.h>
  136. #include <linux/delay.h>
  137. #include <linux/init.h>
  138. #include <linux/pci.h>
  139. #include <linux/dma-mapping.h>
  140. #include <linux/netdevice.h>
  141. #include <linux/etherdevice.h>
  142. #include <linux/mii.h>
  143. #include <linux/if_vlan.h>
  144. #include <linux/skbuff.h>
  145. #include <linux/ethtool.h>
  146. #include <linux/string.h>
  147. #include <asm/unaligned.h>
  148. #define DRV_NAME "e100"
  149. #define DRV_EXT "-NAPI"
  150. #define DRV_VERSION "3.5.16-k2"DRV_EXT
  151. #define DRV_DESCRIPTION "Intel(R) PRO/100 Network Driver"
  152. #define DRV_COPYRIGHT "Copyright(c) 1999-2006 Intel Corporation"
  153. #define PFX DRV_NAME ": "
  154. #define E100_WATCHDOG_PERIOD (2 * HZ)
  155. #define E100_NAPI_WEIGHT 16
  156. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  157. MODULE_AUTHOR(DRV_COPYRIGHT);
  158. MODULE_LICENSE("GPL");
  159. MODULE_VERSION(DRV_VERSION);
  160. static int debug = 3;
  161. module_param(debug, int, 0);
  162. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  163. #define DPRINTK(nlevel, klevel, fmt, args...) \
  164. (void)((NETIF_MSG_##nlevel & nic->msg_enable) && \
  165. printk(KERN_##klevel PFX "%s: %s: " fmt, nic->netdev->name, \
  166. __FUNCTION__ , ## args))
  167. #define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\
  168. PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \
  169. PCI_CLASS_NETWORK_ETHERNET << 8, 0xFFFF00, ich }
  170. static struct pci_device_id e100_id_table[] = {
  171. INTEL_8255X_ETHERNET_DEVICE(0x1029, 0),
  172. INTEL_8255X_ETHERNET_DEVICE(0x1030, 0),
  173. INTEL_8255X_ETHERNET_DEVICE(0x1031, 3),
  174. INTEL_8255X_ETHERNET_DEVICE(0x1032, 3),
  175. INTEL_8255X_ETHERNET_DEVICE(0x1033, 3),
  176. INTEL_8255X_ETHERNET_DEVICE(0x1034, 3),
  177. INTEL_8255X_ETHERNET_DEVICE(0x1038, 3),
  178. INTEL_8255X_ETHERNET_DEVICE(0x1039, 4),
  179. INTEL_8255X_ETHERNET_DEVICE(0x103A, 4),
  180. INTEL_8255X_ETHERNET_DEVICE(0x103B, 4),
  181. INTEL_8255X_ETHERNET_DEVICE(0x103C, 4),
  182. INTEL_8255X_ETHERNET_DEVICE(0x103D, 4),
  183. INTEL_8255X_ETHERNET_DEVICE(0x103E, 4),
  184. INTEL_8255X_ETHERNET_DEVICE(0x1050, 5),
  185. INTEL_8255X_ETHERNET_DEVICE(0x1051, 5),
  186. INTEL_8255X_ETHERNET_DEVICE(0x1052, 5),
  187. INTEL_8255X_ETHERNET_DEVICE(0x1053, 5),
  188. INTEL_8255X_ETHERNET_DEVICE(0x1054, 5),
  189. INTEL_8255X_ETHERNET_DEVICE(0x1055, 5),
  190. INTEL_8255X_ETHERNET_DEVICE(0x1056, 5),
  191. INTEL_8255X_ETHERNET_DEVICE(0x1057, 5),
  192. INTEL_8255X_ETHERNET_DEVICE(0x1059, 0),
  193. INTEL_8255X_ETHERNET_DEVICE(0x1064, 6),
  194. INTEL_8255X_ETHERNET_DEVICE(0x1065, 6),
  195. INTEL_8255X_ETHERNET_DEVICE(0x1066, 6),
  196. INTEL_8255X_ETHERNET_DEVICE(0x1067, 6),
  197. INTEL_8255X_ETHERNET_DEVICE(0x1068, 6),
  198. INTEL_8255X_ETHERNET_DEVICE(0x1069, 6),
  199. INTEL_8255X_ETHERNET_DEVICE(0x106A, 6),
  200. INTEL_8255X_ETHERNET_DEVICE(0x106B, 6),
  201. INTEL_8255X_ETHERNET_DEVICE(0x1091, 7),
  202. INTEL_8255X_ETHERNET_DEVICE(0x1092, 7),
  203. INTEL_8255X_ETHERNET_DEVICE(0x1093, 7),
  204. INTEL_8255X_ETHERNET_DEVICE(0x1094, 7),
  205. INTEL_8255X_ETHERNET_DEVICE(0x1095, 7),
  206. INTEL_8255X_ETHERNET_DEVICE(0x1209, 0),
  207. INTEL_8255X_ETHERNET_DEVICE(0x1229, 0),
  208. INTEL_8255X_ETHERNET_DEVICE(0x2449, 2),
  209. INTEL_8255X_ETHERNET_DEVICE(0x2459, 2),
  210. INTEL_8255X_ETHERNET_DEVICE(0x245D, 2),
  211. INTEL_8255X_ETHERNET_DEVICE(0x27DC, 7),
  212. { 0, }
  213. };
  214. MODULE_DEVICE_TABLE(pci, e100_id_table);
  215. enum mac {
  216. mac_82557_D100_A = 0,
  217. mac_82557_D100_B = 1,
  218. mac_82557_D100_C = 2,
  219. mac_82558_D101_A4 = 4,
  220. mac_82558_D101_B0 = 5,
  221. mac_82559_D101M = 8,
  222. mac_82559_D101S = 9,
  223. mac_82550_D102 = 12,
  224. mac_82550_D102_C = 13,
  225. mac_82551_E = 14,
  226. mac_82551_F = 15,
  227. mac_82551_10 = 16,
  228. mac_unknown = 0xFF,
  229. };
  230. enum phy {
  231. phy_100a = 0x000003E0,
  232. phy_100c = 0x035002A8,
  233. phy_82555_tx = 0x015002A8,
  234. phy_nsc_tx = 0x5C002000,
  235. phy_82562_et = 0x033002A8,
  236. phy_82562_em = 0x032002A8,
  237. phy_82562_ek = 0x031002A8,
  238. phy_82562_eh = 0x017002A8,
  239. phy_unknown = 0xFFFFFFFF,
  240. };
  241. /* CSR (Control/Status Registers) */
  242. struct csr {
  243. struct {
  244. u8 status;
  245. u8 stat_ack;
  246. u8 cmd_lo;
  247. u8 cmd_hi;
  248. u32 gen_ptr;
  249. } scb;
  250. u32 port;
  251. u16 flash_ctrl;
  252. u8 eeprom_ctrl_lo;
  253. u8 eeprom_ctrl_hi;
  254. u32 mdi_ctrl;
  255. u32 rx_dma_count;
  256. };
  257. enum scb_status {
  258. rus_ready = 0x10,
  259. rus_mask = 0x3C,
  260. };
  261. enum ru_state {
  262. RU_SUSPENDED = 0,
  263. RU_RUNNING = 1,
  264. RU_UNINITIALIZED = -1,
  265. };
  266. enum scb_stat_ack {
  267. stat_ack_not_ours = 0x00,
  268. stat_ack_sw_gen = 0x04,
  269. stat_ack_rnr = 0x10,
  270. stat_ack_cu_idle = 0x20,
  271. stat_ack_frame_rx = 0x40,
  272. stat_ack_cu_cmd_done = 0x80,
  273. stat_ack_not_present = 0xFF,
  274. stat_ack_rx = (stat_ack_sw_gen | stat_ack_rnr | stat_ack_frame_rx),
  275. stat_ack_tx = (stat_ack_cu_idle | stat_ack_cu_cmd_done),
  276. };
  277. enum scb_cmd_hi {
  278. irq_mask_none = 0x00,
  279. irq_mask_all = 0x01,
  280. irq_sw_gen = 0x02,
  281. };
  282. enum scb_cmd_lo {
  283. cuc_nop = 0x00,
  284. ruc_start = 0x01,
  285. ruc_load_base = 0x06,
  286. cuc_start = 0x10,
  287. cuc_resume = 0x20,
  288. cuc_dump_addr = 0x40,
  289. cuc_dump_stats = 0x50,
  290. cuc_load_base = 0x60,
  291. cuc_dump_reset = 0x70,
  292. };
  293. enum cuc_dump {
  294. cuc_dump_complete = 0x0000A005,
  295. cuc_dump_reset_complete = 0x0000A007,
  296. };
  297. enum port {
  298. software_reset = 0x0000,
  299. selftest = 0x0001,
  300. selective_reset = 0x0002,
  301. };
  302. enum eeprom_ctrl_lo {
  303. eesk = 0x01,
  304. eecs = 0x02,
  305. eedi = 0x04,
  306. eedo = 0x08,
  307. };
  308. enum mdi_ctrl {
  309. mdi_write = 0x04000000,
  310. mdi_read = 0x08000000,
  311. mdi_ready = 0x10000000,
  312. };
  313. enum eeprom_op {
  314. op_write = 0x05,
  315. op_read = 0x06,
  316. op_ewds = 0x10,
  317. op_ewen = 0x13,
  318. };
  319. enum eeprom_offsets {
  320. eeprom_cnfg_mdix = 0x03,
  321. eeprom_id = 0x0A,
  322. eeprom_config_asf = 0x0D,
  323. eeprom_smbus_addr = 0x90,
  324. };
  325. enum eeprom_cnfg_mdix {
  326. eeprom_mdix_enabled = 0x0080,
  327. };
  328. enum eeprom_id {
  329. eeprom_id_wol = 0x0020,
  330. };
  331. enum eeprom_config_asf {
  332. eeprom_asf = 0x8000,
  333. eeprom_gcl = 0x4000,
  334. };
  335. enum cb_status {
  336. cb_complete = 0x8000,
  337. cb_ok = 0x2000,
  338. };
  339. enum cb_command {
  340. cb_nop = 0x0000,
  341. cb_iaaddr = 0x0001,
  342. cb_config = 0x0002,
  343. cb_multi = 0x0003,
  344. cb_tx = 0x0004,
  345. cb_ucode = 0x0005,
  346. cb_dump = 0x0006,
  347. cb_tx_sf = 0x0008,
  348. cb_cid = 0x1f00,
  349. cb_i = 0x2000,
  350. cb_s = 0x4000,
  351. cb_el = 0x8000,
  352. };
  353. struct rfd {
  354. u16 status;
  355. u16 command;
  356. u32 link;
  357. u32 rbd;
  358. u16 actual_size;
  359. u16 size;
  360. };
  361. struct rx {
  362. struct rx *next, *prev;
  363. struct sk_buff *skb;
  364. dma_addr_t dma_addr;
  365. };
  366. #if defined(__BIG_ENDIAN_BITFIELD)
  367. #define X(a,b) b,a
  368. #else
  369. #define X(a,b) a,b
  370. #endif
  371. struct config {
  372. /*0*/ u8 X(byte_count:6, pad0:2);
  373. /*1*/ u8 X(X(rx_fifo_limit:4, tx_fifo_limit:3), pad1:1);
  374. /*2*/ u8 adaptive_ifs;
  375. /*3*/ u8 X(X(X(X(mwi_enable:1, type_enable:1), read_align_enable:1),
  376. term_write_cache_line:1), pad3:4);
  377. /*4*/ u8 X(rx_dma_max_count:7, pad4:1);
  378. /*5*/ u8 X(tx_dma_max_count:7, dma_max_count_enable:1);
  379. /*6*/ u8 X(X(X(X(X(X(X(late_scb_update:1, direct_rx_dma:1),
  380. tno_intr:1), cna_intr:1), standard_tcb:1), standard_stat_counter:1),
  381. rx_discard_overruns:1), rx_save_bad_frames:1);
  382. /*7*/ u8 X(X(X(X(X(rx_discard_short_frames:1, tx_underrun_retry:2),
  383. pad7:2), rx_extended_rfd:1), tx_two_frames_in_fifo:1),
  384. tx_dynamic_tbd:1);
  385. /*8*/ u8 X(X(mii_mode:1, pad8:6), csma_disabled:1);
  386. /*9*/ u8 X(X(X(X(X(rx_tcpudp_checksum:1, pad9:3), vlan_arp_tco:1),
  387. link_status_wake:1), arp_wake:1), mcmatch_wake:1);
  388. /*10*/ u8 X(X(X(pad10:3, no_source_addr_insertion:1), preamble_length:2),
  389. loopback:2);
  390. /*11*/ u8 X(linear_priority:3, pad11:5);
  391. /*12*/ u8 X(X(linear_priority_mode:1, pad12:3), ifs:4);
  392. /*13*/ u8 ip_addr_lo;
  393. /*14*/ u8 ip_addr_hi;
  394. /*15*/ u8 X(X(X(X(X(X(X(promiscuous_mode:1, broadcast_disabled:1),
  395. wait_after_win:1), pad15_1:1), ignore_ul_bit:1), crc_16_bit:1),
  396. pad15_2:1), crs_or_cdt:1);
  397. /*16*/ u8 fc_delay_lo;
  398. /*17*/ u8 fc_delay_hi;
  399. /*18*/ u8 X(X(X(X(X(rx_stripping:1, tx_padding:1), rx_crc_transfer:1),
  400. rx_long_ok:1), fc_priority_threshold:3), pad18:1);
  401. /*19*/ u8 X(X(X(X(X(X(X(addr_wake:1, magic_packet_disable:1),
  402. fc_disable:1), fc_restop:1), fc_restart:1), fc_reject:1),
  403. full_duplex_force:1), full_duplex_pin:1);
  404. /*20*/ u8 X(X(X(pad20_1:5, fc_priority_location:1), multi_ia:1), pad20_2:1);
  405. /*21*/ u8 X(X(pad21_1:3, multicast_all:1), pad21_2:4);
  406. /*22*/ u8 X(X(rx_d102_mode:1, rx_vlan_drop:1), pad22:6);
  407. u8 pad_d102[9];
  408. };
  409. #define E100_MAX_MULTICAST_ADDRS 64
  410. struct multi {
  411. u16 count;
  412. u8 addr[E100_MAX_MULTICAST_ADDRS * ETH_ALEN + 2/*pad*/];
  413. };
  414. /* Important: keep total struct u32-aligned */
  415. #define UCODE_SIZE 134
  416. struct cb {
  417. u16 status;
  418. u16 command;
  419. u32 link;
  420. union {
  421. u8 iaaddr[ETH_ALEN];
  422. u32 ucode[UCODE_SIZE];
  423. struct config config;
  424. struct multi multi;
  425. struct {
  426. u32 tbd_array;
  427. u16 tcb_byte_count;
  428. u8 threshold;
  429. u8 tbd_count;
  430. struct {
  431. u32 buf_addr;
  432. u16 size;
  433. u16 eol;
  434. } tbd;
  435. } tcb;
  436. u32 dump_buffer_addr;
  437. } u;
  438. struct cb *next, *prev;
  439. dma_addr_t dma_addr;
  440. struct sk_buff *skb;
  441. };
  442. enum loopback {
  443. lb_none = 0, lb_mac = 1, lb_phy = 3,
  444. };
  445. struct stats {
  446. u32 tx_good_frames, tx_max_collisions, tx_late_collisions,
  447. tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
  448. tx_multiple_collisions, tx_total_collisions;
  449. u32 rx_good_frames, rx_crc_errors, rx_alignment_errors,
  450. rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
  451. rx_short_frame_errors;
  452. u32 fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
  453. u16 xmt_tco_frames, rcv_tco_frames;
  454. u32 complete;
  455. };
  456. struct mem {
  457. struct {
  458. u32 signature;
  459. u32 result;
  460. } selftest;
  461. struct stats stats;
  462. u8 dump_buf[596];
  463. };
  464. struct param_range {
  465. u32 min;
  466. u32 max;
  467. u32 count;
  468. };
  469. struct params {
  470. struct param_range rfds;
  471. struct param_range cbs;
  472. };
  473. struct nic {
  474. /* Begin: frequently used values: keep adjacent for cache effect */
  475. u32 msg_enable ____cacheline_aligned;
  476. struct net_device *netdev;
  477. struct pci_dev *pdev;
  478. struct rx *rxs ____cacheline_aligned;
  479. struct rx *rx_to_use;
  480. struct rx *rx_to_clean;
  481. struct rfd blank_rfd;
  482. enum ru_state ru_running;
  483. spinlock_t cb_lock ____cacheline_aligned;
  484. spinlock_t cmd_lock;
  485. struct csr __iomem *csr;
  486. enum scb_cmd_lo cuc_cmd;
  487. unsigned int cbs_avail;
  488. struct cb *cbs;
  489. struct cb *cb_to_use;
  490. struct cb *cb_to_send;
  491. struct cb *cb_to_clean;
  492. u16 tx_command;
  493. /* End: frequently used values: keep adjacent for cache effect */
  494. enum {
  495. ich = (1 << 0),
  496. promiscuous = (1 << 1),
  497. multicast_all = (1 << 2),
  498. wol_magic = (1 << 3),
  499. ich_10h_workaround = (1 << 4),
  500. } flags ____cacheline_aligned;
  501. enum mac mac;
  502. enum phy phy;
  503. struct params params;
  504. struct net_device_stats net_stats;
  505. struct timer_list watchdog;
  506. struct timer_list blink_timer;
  507. struct mii_if_info mii;
  508. struct work_struct tx_timeout_task;
  509. enum loopback loopback;
  510. struct mem *mem;
  511. dma_addr_t dma_addr;
  512. dma_addr_t cbs_dma_addr;
  513. u8 adaptive_ifs;
  514. u8 tx_threshold;
  515. u32 tx_frames;
  516. u32 tx_collisions;
  517. u32 tx_deferred;
  518. u32 tx_single_collisions;
  519. u32 tx_multiple_collisions;
  520. u32 tx_fc_pause;
  521. u32 tx_tco_frames;
  522. u32 rx_fc_pause;
  523. u32 rx_fc_unsupported;
  524. u32 rx_tco_frames;
  525. u32 rx_over_length_errors;
  526. u8 rev_id;
  527. u16 leds;
  528. u16 eeprom_wc;
  529. u16 eeprom[256];
  530. spinlock_t mdio_lock;
  531. };
  532. static inline void e100_write_flush(struct nic *nic)
  533. {
  534. /* Flush previous PCI writes through intermediate bridges
  535. * by doing a benign read */
  536. (void)readb(&nic->csr->scb.status);
  537. }
  538. static void e100_enable_irq(struct nic *nic)
  539. {
  540. unsigned long flags;
  541. spin_lock_irqsave(&nic->cmd_lock, flags);
  542. writeb(irq_mask_none, &nic->csr->scb.cmd_hi);
  543. e100_write_flush(nic);
  544. spin_unlock_irqrestore(&nic->cmd_lock, flags);
  545. }
  546. static void e100_disable_irq(struct nic *nic)
  547. {
  548. unsigned long flags;
  549. spin_lock_irqsave(&nic->cmd_lock, flags);
  550. writeb(irq_mask_all, &nic->csr->scb.cmd_hi);
  551. e100_write_flush(nic);
  552. spin_unlock_irqrestore(&nic->cmd_lock, flags);
  553. }
  554. static void e100_hw_reset(struct nic *nic)
  555. {
  556. /* Put CU and RU into idle with a selective reset to get
  557. * device off of PCI bus */
  558. writel(selective_reset, &nic->csr->port);
  559. e100_write_flush(nic); udelay(20);
  560. /* Now fully reset device */
  561. writel(software_reset, &nic->csr->port);
  562. e100_write_flush(nic); udelay(20);
  563. /* Mask off our interrupt line - it's unmasked after reset */
  564. e100_disable_irq(nic);
  565. }
  566. static int e100_self_test(struct nic *nic)
  567. {
  568. u32 dma_addr = nic->dma_addr + offsetof(struct mem, selftest);
  569. /* Passing the self-test is a pretty good indication
  570. * that the device can DMA to/from host memory */
  571. nic->mem->selftest.signature = 0;
  572. nic->mem->selftest.result = 0xFFFFFFFF;
  573. writel(selftest | dma_addr, &nic->csr->port);
  574. e100_write_flush(nic);
  575. /* Wait 10 msec for self-test to complete */
  576. msleep(10);
  577. /* Interrupts are enabled after self-test */
  578. e100_disable_irq(nic);
  579. /* Check results of self-test */
  580. if(nic->mem->selftest.result != 0) {
  581. DPRINTK(HW, ERR, "Self-test failed: result=0x%08X\n",
  582. nic->mem->selftest.result);
  583. return -ETIMEDOUT;
  584. }
  585. if(nic->mem->selftest.signature == 0) {
  586. DPRINTK(HW, ERR, "Self-test failed: timed out\n");
  587. return -ETIMEDOUT;
  588. }
  589. return 0;
  590. }
  591. static void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, u16 data)
  592. {
  593. u32 cmd_addr_data[3];
  594. u8 ctrl;
  595. int i, j;
  596. /* Three cmds: write/erase enable, write data, write/erase disable */
  597. cmd_addr_data[0] = op_ewen << (addr_len - 2);
  598. cmd_addr_data[1] = (((op_write << addr_len) | addr) << 16) |
  599. cpu_to_le16(data);
  600. cmd_addr_data[2] = op_ewds << (addr_len - 2);
  601. /* Bit-bang cmds to write word to eeprom */
  602. for(j = 0; j < 3; j++) {
  603. /* Chip select */
  604. writeb(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
  605. e100_write_flush(nic); udelay(4);
  606. for(i = 31; i >= 0; i--) {
  607. ctrl = (cmd_addr_data[j] & (1 << i)) ?
  608. eecs | eedi : eecs;
  609. writeb(ctrl, &nic->csr->eeprom_ctrl_lo);
  610. e100_write_flush(nic); udelay(4);
  611. writeb(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
  612. e100_write_flush(nic); udelay(4);
  613. }
  614. /* Wait 10 msec for cmd to complete */
  615. msleep(10);
  616. /* Chip deselect */
  617. writeb(0, &nic->csr->eeprom_ctrl_lo);
  618. e100_write_flush(nic); udelay(4);
  619. }
  620. };
  621. /* General technique stolen from the eepro100 driver - very clever */
  622. static u16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
  623. {
  624. u32 cmd_addr_data;
  625. u16 data = 0;
  626. u8 ctrl;
  627. int i;
  628. cmd_addr_data = ((op_read << *addr_len) | addr) << 16;
  629. /* Chip select */
  630. writeb(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
  631. e100_write_flush(nic); udelay(4);
  632. /* Bit-bang to read word from eeprom */
  633. for(i = 31; i >= 0; i--) {
  634. ctrl = (cmd_addr_data & (1 << i)) ? eecs | eedi : eecs;
  635. writeb(ctrl, &nic->csr->eeprom_ctrl_lo);
  636. e100_write_flush(nic); udelay(4);
  637. writeb(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
  638. e100_write_flush(nic); udelay(4);
  639. /* Eeprom drives a dummy zero to EEDO after receiving
  640. * complete address. Use this to adjust addr_len. */
  641. ctrl = readb(&nic->csr->eeprom_ctrl_lo);
  642. if(!(ctrl & eedo) && i > 16) {
  643. *addr_len -= (i - 16);
  644. i = 17;
  645. }
  646. data = (data << 1) | (ctrl & eedo ? 1 : 0);
  647. }
  648. /* Chip deselect */
  649. writeb(0, &nic->csr->eeprom_ctrl_lo);
  650. e100_write_flush(nic); udelay(4);
  651. return le16_to_cpu(data);
  652. };
  653. /* Load entire EEPROM image into driver cache and validate checksum */
  654. static int e100_eeprom_load(struct nic *nic)
  655. {
  656. u16 addr, addr_len = 8, checksum = 0;
  657. /* Try reading with an 8-bit addr len to discover actual addr len */
  658. e100_eeprom_read(nic, &addr_len, 0);
  659. nic->eeprom_wc = 1 << addr_len;
  660. for(addr = 0; addr < nic->eeprom_wc; addr++) {
  661. nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
  662. if(addr < nic->eeprom_wc - 1)
  663. checksum += cpu_to_le16(nic->eeprom[addr]);
  664. }
  665. /* The checksum, stored in the last word, is calculated such that
  666. * the sum of words should be 0xBABA */
  667. checksum = le16_to_cpu(0xBABA - checksum);
  668. if(checksum != nic->eeprom[nic->eeprom_wc - 1]) {
  669. DPRINTK(PROBE, ERR, "EEPROM corrupted\n");
  670. return -EAGAIN;
  671. }
  672. return 0;
  673. }
  674. /* Save (portion of) driver EEPROM cache to device and update checksum */
  675. static int e100_eeprom_save(struct nic *nic, u16 start, u16 count)
  676. {
  677. u16 addr, addr_len = 8, checksum = 0;
  678. /* Try reading with an 8-bit addr len to discover actual addr len */
  679. e100_eeprom_read(nic, &addr_len, 0);
  680. nic->eeprom_wc = 1 << addr_len;
  681. if(start + count >= nic->eeprom_wc)
  682. return -EINVAL;
  683. for(addr = start; addr < start + count; addr++)
  684. e100_eeprom_write(nic, addr_len, addr, nic->eeprom[addr]);
  685. /* The checksum, stored in the last word, is calculated such that
  686. * the sum of words should be 0xBABA */
  687. for(addr = 0; addr < nic->eeprom_wc - 1; addr++)
  688. checksum += cpu_to_le16(nic->eeprom[addr]);
  689. nic->eeprom[nic->eeprom_wc - 1] = le16_to_cpu(0xBABA - checksum);
  690. e100_eeprom_write(nic, addr_len, nic->eeprom_wc - 1,
  691. nic->eeprom[nic->eeprom_wc - 1]);
  692. return 0;
  693. }
  694. #define E100_WAIT_SCB_TIMEOUT 20000 /* we might have to wait 100ms!!! */
  695. #define E100_WAIT_SCB_FAST 20 /* delay like the old code */
  696. static int e100_exec_cmd(struct nic *nic, u8 cmd, dma_addr_t dma_addr)
  697. {
  698. unsigned long flags;
  699. unsigned int i;
  700. int err = 0;
  701. spin_lock_irqsave(&nic->cmd_lock, flags);
  702. /* Previous command is accepted when SCB clears */
  703. for(i = 0; i < E100_WAIT_SCB_TIMEOUT; i++) {
  704. if(likely(!readb(&nic->csr->scb.cmd_lo)))
  705. break;
  706. cpu_relax();
  707. if(unlikely(i > E100_WAIT_SCB_FAST))
  708. udelay(5);
  709. }
  710. if(unlikely(i == E100_WAIT_SCB_TIMEOUT)) {
  711. err = -EAGAIN;
  712. goto err_unlock;
  713. }
  714. if(unlikely(cmd != cuc_resume))
  715. writel(dma_addr, &nic->csr->scb.gen_ptr);
  716. writeb(cmd, &nic->csr->scb.cmd_lo);
  717. err_unlock:
  718. spin_unlock_irqrestore(&nic->cmd_lock, flags);
  719. return err;
  720. }
  721. static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
  722. void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
  723. {
  724. struct cb *cb;
  725. unsigned long flags;
  726. int err = 0;
  727. spin_lock_irqsave(&nic->cb_lock, flags);
  728. if(unlikely(!nic->cbs_avail)) {
  729. err = -ENOMEM;
  730. goto err_unlock;
  731. }
  732. cb = nic->cb_to_use;
  733. nic->cb_to_use = cb->next;
  734. nic->cbs_avail--;
  735. cb->skb = skb;
  736. if(unlikely(!nic->cbs_avail))
  737. err = -ENOSPC;
  738. cb_prepare(nic, cb, skb);
  739. /* Order is important otherwise we'll be in a race with h/w:
  740. * set S-bit in current first, then clear S-bit in previous. */
  741. cb->command |= cpu_to_le16(cb_s);
  742. wmb();
  743. cb->prev->command &= cpu_to_le16(~cb_s);
  744. while(nic->cb_to_send != nic->cb_to_use) {
  745. if(unlikely(e100_exec_cmd(nic, nic->cuc_cmd,
  746. nic->cb_to_send->dma_addr))) {
  747. /* Ok, here's where things get sticky. It's
  748. * possible that we can't schedule the command
  749. * because the controller is too busy, so
  750. * let's just queue the command and try again
  751. * when another command is scheduled. */
  752. if(err == -ENOSPC) {
  753. //request a reset
  754. schedule_work(&nic->tx_timeout_task);
  755. }
  756. break;
  757. } else {
  758. nic->cuc_cmd = cuc_resume;
  759. nic->cb_to_send = nic->cb_to_send->next;
  760. }
  761. }
  762. err_unlock:
  763. spin_unlock_irqrestore(&nic->cb_lock, flags);
  764. return err;
  765. }
  766. static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
  767. {
  768. u32 data_out = 0;
  769. unsigned int i;
  770. unsigned long flags;
  771. /*
  772. * Stratus87247: we shouldn't be writing the MDI control
  773. * register until the Ready bit shows True. Also, since
  774. * manipulation of the MDI control registers is a multi-step
  775. * procedure it should be done under lock.
  776. */
  777. spin_lock_irqsave(&nic->mdio_lock, flags);
  778. for (i = 100; i; --i) {
  779. if (readl(&nic->csr->mdi_ctrl) & mdi_ready)
  780. break;
  781. udelay(20);
  782. }
  783. if (unlikely(!i)) {
  784. printk("e100.mdio_ctrl(%s) won't go Ready\n",
  785. nic->netdev->name );
  786. spin_unlock_irqrestore(&nic->mdio_lock, flags);
  787. return 0; /* No way to indicate timeout error */
  788. }
  789. writel((reg << 16) | (addr << 21) | dir | data, &nic->csr->mdi_ctrl);
  790. for (i = 0; i < 100; i++) {
  791. udelay(20);
  792. if ((data_out = readl(&nic->csr->mdi_ctrl)) & mdi_ready)
  793. break;
  794. }
  795. spin_unlock_irqrestore(&nic->mdio_lock, flags);
  796. DPRINTK(HW, DEBUG,
  797. "%s:addr=%d, reg=%d, data_in=0x%04X, data_out=0x%04X\n",
  798. dir == mdi_read ? "READ" : "WRITE", addr, reg, data, data_out);
  799. return (u16)data_out;
  800. }
  801. static int mdio_read(struct net_device *netdev, int addr, int reg)
  802. {
  803. return mdio_ctrl(netdev_priv(netdev), addr, mdi_read, reg, 0);
  804. }
  805. static void mdio_write(struct net_device *netdev, int addr, int reg, int data)
  806. {
  807. mdio_ctrl(netdev_priv(netdev), addr, mdi_write, reg, data);
  808. }
  809. static void e100_get_defaults(struct nic *nic)
  810. {
  811. struct param_range rfds = { .min = 16, .max = 256, .count = 256 };
  812. struct param_range cbs = { .min = 64, .max = 256, .count = 128 };
  813. pci_read_config_byte(nic->pdev, PCI_REVISION_ID, &nic->rev_id);
  814. /* MAC type is encoded as rev ID; exception: ICH is treated as 82559 */
  815. nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->rev_id;
  816. if(nic->mac == mac_unknown)
  817. nic->mac = mac_82557_D100_A;
  818. nic->params.rfds = rfds;
  819. nic->params.cbs = cbs;
  820. /* Quadwords to DMA into FIFO before starting frame transmit */
  821. nic->tx_threshold = 0xE0;
  822. /* no interrupt for every tx completion, delay = 256us if not 557*/
  823. nic->tx_command = cpu_to_le16(cb_tx | cb_tx_sf |
  824. ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
  825. /* Template for a freshly allocated RFD */
  826. nic->blank_rfd.command = cpu_to_le16(cb_el);
  827. nic->blank_rfd.rbd = 0xFFFFFFFF;
  828. nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
  829. /* MII setup */
  830. nic->mii.phy_id_mask = 0x1F;
  831. nic->mii.reg_num_mask = 0x1F;
  832. nic->mii.dev = nic->netdev;
  833. nic->mii.mdio_read = mdio_read;
  834. nic->mii.mdio_write = mdio_write;
  835. }
  836. static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  837. {
  838. struct config *config = &cb->u.config;
  839. u8 *c = (u8 *)config;
  840. cb->command = cpu_to_le16(cb_config);
  841. memset(config, 0, sizeof(struct config));
  842. config->byte_count = 0x16; /* bytes in this struct */
  843. config->rx_fifo_limit = 0x8; /* bytes in FIFO before DMA */
  844. config->direct_rx_dma = 0x1; /* reserved */
  845. config->standard_tcb = 0x1; /* 1=standard, 0=extended */
  846. config->standard_stat_counter = 0x1; /* 1=standard, 0=extended */
  847. config->rx_discard_short_frames = 0x1; /* 1=discard, 0=pass */
  848. config->tx_underrun_retry = 0x3; /* # of underrun retries */
  849. config->mii_mode = 0x1; /* 1=MII mode, 0=503 mode */
  850. config->pad10 = 0x6;
  851. config->no_source_addr_insertion = 0x1; /* 1=no, 0=yes */
  852. config->preamble_length = 0x2; /* 0=1, 1=3, 2=7, 3=15 bytes */
  853. config->ifs = 0x6; /* x16 = inter frame spacing */
  854. config->ip_addr_hi = 0xF2; /* ARP IP filter - not used */
  855. config->pad15_1 = 0x1;
  856. config->pad15_2 = 0x1;
  857. config->crs_or_cdt = 0x0; /* 0=CRS only, 1=CRS or CDT */
  858. config->fc_delay_hi = 0x40; /* time delay for fc frame */
  859. config->tx_padding = 0x1; /* 1=pad short frames */
  860. config->fc_priority_threshold = 0x7; /* 7=priority fc disabled */
  861. config->pad18 = 0x1;
  862. config->full_duplex_pin = 0x1; /* 1=examine FDX# pin */
  863. config->pad20_1 = 0x1F;
  864. config->fc_priority_location = 0x1; /* 1=byte#31, 0=byte#19 */
  865. config->pad21_1 = 0x5;
  866. config->adaptive_ifs = nic->adaptive_ifs;
  867. config->loopback = nic->loopback;
  868. if(nic->mii.force_media && nic->mii.full_duplex)
  869. config->full_duplex_force = 0x1; /* 1=force, 0=auto */
  870. if(nic->flags & promiscuous || nic->loopback) {
  871. config->rx_save_bad_frames = 0x1; /* 1=save, 0=discard */
  872. config->rx_discard_short_frames = 0x0; /* 1=discard, 0=save */
  873. config->promiscuous_mode = 0x1; /* 1=on, 0=off */
  874. }
  875. if(nic->flags & multicast_all)
  876. config->multicast_all = 0x1; /* 1=accept, 0=no */
  877. /* disable WoL when up */
  878. if(netif_running(nic->netdev) || !(nic->flags & wol_magic))
  879. config->magic_packet_disable = 0x1; /* 1=off, 0=on */
  880. if(nic->mac >= mac_82558_D101_A4) {
  881. config->fc_disable = 0x1; /* 1=Tx fc off, 0=Tx fc on */
  882. config->mwi_enable = 0x1; /* 1=enable, 0=disable */
  883. config->standard_tcb = 0x0; /* 1=standard, 0=extended */
  884. config->rx_long_ok = 0x1; /* 1=VLANs ok, 0=standard */
  885. if(nic->mac >= mac_82559_D101M)
  886. config->tno_intr = 0x1; /* TCO stats enable */
  887. else
  888. config->standard_stat_counter = 0x0;
  889. }
  890. DPRINTK(HW, DEBUG, "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  891. c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
  892. DPRINTK(HW, DEBUG, "[08-15]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  893. c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15]);
  894. DPRINTK(HW, DEBUG, "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  895. c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
  896. }
  897. /********************************************************/
  898. /* Micro code for 8086:1229 Rev 8 */
  899. /********************************************************/
  900. /* Parameter values for the D101M B-step */
  901. #define D101M_CPUSAVER_TIMER_DWORD 78
  902. #define D101M_CPUSAVER_BUNDLE_DWORD 65
  903. #define D101M_CPUSAVER_MIN_SIZE_DWORD 126
  904. #define D101M_B_RCVBUNDLE_UCODE \
  905. {\
  906. 0x00550215, 0xFFFF0437, 0xFFFFFFFF, 0x06A70789, 0xFFFFFFFF, 0x0558FFFF, \
  907. 0x000C0001, 0x00101312, 0x000C0008, 0x00380216, \
  908. 0x0010009C, 0x00204056, 0x002380CC, 0x00380056, \
  909. 0x0010009C, 0x00244C0B, 0x00000800, 0x00124818, \
  910. 0x00380438, 0x00000000, 0x00140000, 0x00380555, \
  911. 0x00308000, 0x00100662, 0x00100561, 0x000E0408, \
  912. 0x00134861, 0x000C0002, 0x00103093, 0x00308000, \
  913. 0x00100624, 0x00100561, 0x000E0408, 0x00100861, \
  914. 0x000C007E, 0x00222C21, 0x000C0002, 0x00103093, \
  915. 0x00380C7A, 0x00080000, 0x00103090, 0x00380C7A, \
  916. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  917. 0x0010009C, 0x00244C2D, 0x00010004, 0x00041000, \
  918. 0x003A0437, 0x00044010, 0x0038078A, 0x00000000, \
  919. 0x00100099, 0x00206C7A, 0x0010009C, 0x00244C48, \
  920. 0x00130824, 0x000C0001, 0x00101213, 0x00260C75, \
  921. 0x00041000, 0x00010004, 0x00130826, 0x000C0006, \
  922. 0x002206A8, 0x0013C926, 0x00101313, 0x003806A8, \
  923. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  924. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  925. 0x00080600, 0x00101B10, 0x00050004, 0x00100826, \
  926. 0x00101210, 0x00380C34, 0x00000000, 0x00000000, \
  927. 0x0021155B, 0x00100099, 0x00206559, 0x0010009C, \
  928. 0x00244559, 0x00130836, 0x000C0000, 0x00220C62, \
  929. 0x000C0001, 0x00101B13, 0x00229C0E, 0x00210C0E, \
  930. 0x00226C0E, 0x00216C0E, 0x0022FC0E, 0x00215C0E, \
  931. 0x00214C0E, 0x00380555, 0x00010004, 0x00041000, \
  932. 0x00278C67, 0x00040800, 0x00018100, 0x003A0437, \
  933. 0x00130826, 0x000C0001, 0x00220559, 0x00101313, \
  934. 0x00380559, 0x00000000, 0x00000000, 0x00000000, \
  935. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  936. 0x00000000, 0x00130831, 0x0010090B, 0x00124813, \
  937. 0x000CFF80, 0x002606AB, 0x00041000, 0x00010004, \
  938. 0x003806A8, 0x00000000, 0x00000000, 0x00000000, \
  939. }
  940. /********************************************************/
  941. /* Micro code for 8086:1229 Rev 9 */
  942. /********************************************************/
  943. /* Parameter values for the D101S */
  944. #define D101S_CPUSAVER_TIMER_DWORD 78
  945. #define D101S_CPUSAVER_BUNDLE_DWORD 67
  946. #define D101S_CPUSAVER_MIN_SIZE_DWORD 128
  947. #define D101S_RCVBUNDLE_UCODE \
  948. {\
  949. 0x00550242, 0xFFFF047E, 0xFFFFFFFF, 0x06FF0818, 0xFFFFFFFF, 0x05A6FFFF, \
  950. 0x000C0001, 0x00101312, 0x000C0008, 0x00380243, \
  951. 0x0010009C, 0x00204056, 0x002380D0, 0x00380056, \
  952. 0x0010009C, 0x00244F8B, 0x00000800, 0x00124818, \
  953. 0x0038047F, 0x00000000, 0x00140000, 0x003805A3, \
  954. 0x00308000, 0x00100610, 0x00100561, 0x000E0408, \
  955. 0x00134861, 0x000C0002, 0x00103093, 0x00308000, \
  956. 0x00100624, 0x00100561, 0x000E0408, 0x00100861, \
  957. 0x000C007E, 0x00222FA1, 0x000C0002, 0x00103093, \
  958. 0x00380F90, 0x00080000, 0x00103090, 0x00380F90, \
  959. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  960. 0x0010009C, 0x00244FAD, 0x00010004, 0x00041000, \
  961. 0x003A047E, 0x00044010, 0x00380819, 0x00000000, \
  962. 0x00100099, 0x00206FFD, 0x0010009A, 0x0020AFFD, \
  963. 0x0010009C, 0x00244FC8, 0x00130824, 0x000C0001, \
  964. 0x00101213, 0x00260FF7, 0x00041000, 0x00010004, \
  965. 0x00130826, 0x000C0006, 0x00220700, 0x0013C926, \
  966. 0x00101313, 0x00380700, 0x00000000, 0x00000000, \
  967. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  968. 0x00080600, 0x00101B10, 0x00050004, 0x00100826, \
  969. 0x00101210, 0x00380FB6, 0x00000000, 0x00000000, \
  970. 0x002115A9, 0x00100099, 0x002065A7, 0x0010009A, \
  971. 0x0020A5A7, 0x0010009C, 0x002445A7, 0x00130836, \
  972. 0x000C0000, 0x00220FE4, 0x000C0001, 0x00101B13, \
  973. 0x00229F8E, 0x00210F8E, 0x00226F8E, 0x00216F8E, \
  974. 0x0022FF8E, 0x00215F8E, 0x00214F8E, 0x003805A3, \
  975. 0x00010004, 0x00041000, 0x00278FE9, 0x00040800, \
  976. 0x00018100, 0x003A047E, 0x00130826, 0x000C0001, \
  977. 0x002205A7, 0x00101313, 0x003805A7, 0x00000000, \
  978. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  979. 0x00000000, 0x00000000, 0x00000000, 0x00130831, \
  980. 0x0010090B, 0x00124813, 0x000CFF80, 0x00260703, \
  981. 0x00041000, 0x00010004, 0x00380700 \
  982. }
  983. /********************************************************/
  984. /* Micro code for the 8086:1229 Rev F/10 */
  985. /********************************************************/
  986. /* Parameter values for the D102 E-step */
  987. #define D102_E_CPUSAVER_TIMER_DWORD 42
  988. #define D102_E_CPUSAVER_BUNDLE_DWORD 54
  989. #define D102_E_CPUSAVER_MIN_SIZE_DWORD 46
  990. #define D102_E_RCVBUNDLE_UCODE \
  991. {\
  992. 0x007D028F, 0x0E4204F9, 0x14ED0C85, 0x14FA14E9, 0x0EF70E36, 0x1FFF1FFF, \
  993. 0x00E014B9, 0x00000000, 0x00000000, 0x00000000, \
  994. 0x00E014BD, 0x00000000, 0x00000000, 0x00000000, \
  995. 0x00E014D5, 0x00000000, 0x00000000, 0x00000000, \
  996. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  997. 0x00E014C1, 0x00000000, 0x00000000, 0x00000000, \
  998. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  999. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1000. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1001. 0x00E014C8, 0x00000000, 0x00000000, 0x00000000, \
  1002. 0x00200600, 0x00E014EE, 0x00000000, 0x00000000, \
  1003. 0x0030FF80, 0x00940E46, 0x00038200, 0x00102000, \
  1004. 0x00E00E43, 0x00000000, 0x00000000, 0x00000000, \
  1005. 0x00300006, 0x00E014FB, 0x00000000, 0x00000000, \
  1006. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1007. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1008. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1009. 0x00906E41, 0x00800E3C, 0x00E00E39, 0x00000000, \
  1010. 0x00906EFD, 0x00900EFD, 0x00E00EF8, 0x00000000, \
  1011. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1012. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1013. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1014. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1015. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1016. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1017. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1018. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1019. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1020. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1021. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1022. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1023. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1024. 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
  1025. }
  1026. static void e100_setup_ucode(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  1027. {
  1028. /* *INDENT-OFF* */
  1029. static struct {
  1030. u32 ucode[UCODE_SIZE + 1];
  1031. u8 mac;
  1032. u8 timer_dword;
  1033. u8 bundle_dword;
  1034. u8 min_size_dword;
  1035. } ucode_opts[] = {
  1036. { D101M_B_RCVBUNDLE_UCODE,
  1037. mac_82559_D101M,
  1038. D101M_CPUSAVER_TIMER_DWORD,
  1039. D101M_CPUSAVER_BUNDLE_DWORD,
  1040. D101M_CPUSAVER_MIN_SIZE_DWORD },
  1041. { D101S_RCVBUNDLE_UCODE,
  1042. mac_82559_D101S,
  1043. D101S_CPUSAVER_TIMER_DWORD,
  1044. D101S_CPUSAVER_BUNDLE_DWORD,
  1045. D101S_CPUSAVER_MIN_SIZE_DWORD },
  1046. { D102_E_RCVBUNDLE_UCODE,
  1047. mac_82551_F,
  1048. D102_E_CPUSAVER_TIMER_DWORD,
  1049. D102_E_CPUSAVER_BUNDLE_DWORD,
  1050. D102_E_CPUSAVER_MIN_SIZE_DWORD },
  1051. { D102_E_RCVBUNDLE_UCODE,
  1052. mac_82551_10,
  1053. D102_E_CPUSAVER_TIMER_DWORD,
  1054. D102_E_CPUSAVER_BUNDLE_DWORD,
  1055. D102_E_CPUSAVER_MIN_SIZE_DWORD },
  1056. { {0}, 0, 0, 0, 0}
  1057. }, *opts;
  1058. /* *INDENT-ON* */
  1059. /*************************************************************************
  1060. * CPUSaver parameters
  1061. *
  1062. * All CPUSaver parameters are 16-bit literals that are part of a
  1063. * "move immediate value" instruction. By changing the value of
  1064. * the literal in the instruction before the code is loaded, the
  1065. * driver can change the algorithm.
  1066. *
  1067. * INTDELAY - This loads the dead-man timer with its inital value.
  1068. * When this timer expires the interrupt is asserted, and the
  1069. * timer is reset each time a new packet is received. (see
  1070. * BUNDLEMAX below to set the limit on number of chained packets)
  1071. * The current default is 0x600 or 1536. Experiments show that
  1072. * the value should probably stay within the 0x200 - 0x1000.
  1073. *
  1074. * BUNDLEMAX -
  1075. * This sets the maximum number of frames that will be bundled. In
  1076. * some situations, such as the TCP windowing algorithm, it may be
  1077. * better to limit the growth of the bundle size than let it go as
  1078. * high as it can, because that could cause too much added latency.
  1079. * The default is six, because this is the number of packets in the
  1080. * default TCP window size. A value of 1 would make CPUSaver indicate
  1081. * an interrupt for every frame received. If you do not want to put
  1082. * a limit on the bundle size, set this value to xFFFF.
  1083. *
  1084. * BUNDLESMALL -
  1085. * This contains a bit-mask describing the minimum size frame that
  1086. * will be bundled. The default masks the lower 7 bits, which means
  1087. * that any frame less than 128 bytes in length will not be bundled,
  1088. * but will instead immediately generate an interrupt. This does
  1089. * not affect the current bundle in any way. Any frame that is 128
  1090. * bytes or large will be bundled normally. This feature is meant
  1091. * to provide immediate indication of ACK frames in a TCP environment.
  1092. * Customers were seeing poor performance when a machine with CPUSaver
  1093. * enabled was sending but not receiving. The delay introduced when
  1094. * the ACKs were received was enough to reduce total throughput, because
  1095. * the sender would sit idle until the ACK was finally seen.
  1096. *
  1097. * The current default is 0xFF80, which masks out the lower 7 bits.
  1098. * This means that any frame which is x7F (127) bytes or smaller
  1099. * will cause an immediate interrupt. Because this value must be a
  1100. * bit mask, there are only a few valid values that can be used. To
  1101. * turn this feature off, the driver can write the value xFFFF to the
  1102. * lower word of this instruction (in the same way that the other
  1103. * parameters are used). Likewise, a value of 0xF800 (2047) would
  1104. * cause an interrupt to be generated for every frame, because all
  1105. * standard Ethernet frames are <= 2047 bytes in length.
  1106. *************************************************************************/
  1107. /* if you wish to disable the ucode functionality, while maintaining the
  1108. * workarounds it provides, set the following defines to:
  1109. * BUNDLESMALL 0
  1110. * BUNDLEMAX 1
  1111. * INTDELAY 1
  1112. */
  1113. #define BUNDLESMALL 1
  1114. #define BUNDLEMAX (u16)6
  1115. #define INTDELAY (u16)1536 /* 0x600 */
  1116. /* do not load u-code for ICH devices */
  1117. if (nic->flags & ich)
  1118. goto noloaducode;
  1119. /* Search for ucode match against h/w rev_id */
  1120. for (opts = ucode_opts; opts->mac; opts++) {
  1121. int i;
  1122. u32 *ucode = opts->ucode;
  1123. if (nic->mac != opts->mac)
  1124. continue;
  1125. /* Insert user-tunable settings */
  1126. ucode[opts->timer_dword] &= 0xFFFF0000;
  1127. ucode[opts->timer_dword] |= INTDELAY;
  1128. ucode[opts->bundle_dword] &= 0xFFFF0000;
  1129. ucode[opts->bundle_dword] |= BUNDLEMAX;
  1130. ucode[opts->min_size_dword] &= 0xFFFF0000;
  1131. ucode[opts->min_size_dword] |= (BUNDLESMALL) ? 0xFFFF : 0xFF80;
  1132. for (i = 0; i < UCODE_SIZE; i++)
  1133. cb->u.ucode[i] = cpu_to_le32(ucode[i]);
  1134. cb->command = cpu_to_le16(cb_ucode | cb_el);
  1135. return;
  1136. }
  1137. noloaducode:
  1138. cb->command = cpu_to_le16(cb_nop | cb_el);
  1139. }
  1140. static inline int e100_exec_cb_wait(struct nic *nic, struct sk_buff *skb,
  1141. void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
  1142. {
  1143. int err = 0, counter = 50;
  1144. struct cb *cb = nic->cb_to_clean;
  1145. if ((err = e100_exec_cb(nic, NULL, e100_setup_ucode)))
  1146. DPRINTK(PROBE,ERR, "ucode cmd failed with error %d\n", err);
  1147. /* must restart cuc */
  1148. nic->cuc_cmd = cuc_start;
  1149. /* wait for completion */
  1150. e100_write_flush(nic);
  1151. udelay(10);
  1152. /* wait for possibly (ouch) 500ms */
  1153. while (!(cb->status & cpu_to_le16(cb_complete))) {
  1154. msleep(10);
  1155. if (!--counter) break;
  1156. }
  1157. /* ack any interupts, something could have been set */
  1158. writeb(~0, &nic->csr->scb.stat_ack);
  1159. /* if the command failed, or is not OK, notify and return */
  1160. if (!counter || !(cb->status & cpu_to_le16(cb_ok))) {
  1161. DPRINTK(PROBE,ERR, "ucode load failed\n");
  1162. err = -EPERM;
  1163. }
  1164. return err;
  1165. }
  1166. static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
  1167. struct sk_buff *skb)
  1168. {
  1169. cb->command = cpu_to_le16(cb_iaaddr);
  1170. memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
  1171. }
  1172. static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  1173. {
  1174. cb->command = cpu_to_le16(cb_dump);
  1175. cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
  1176. offsetof(struct mem, dump_buf));
  1177. }
  1178. #define NCONFIG_AUTO_SWITCH 0x0080
  1179. #define MII_NSC_CONG MII_RESV1
  1180. #define NSC_CONG_ENABLE 0x0100
  1181. #define NSC_CONG_TXREADY 0x0400
  1182. #define ADVERTISE_FC_SUPPORTED 0x0400
  1183. static int e100_phy_init(struct nic *nic)
  1184. {
  1185. struct net_device *netdev = nic->netdev;
  1186. u32 addr;
  1187. u16 bmcr, stat, id_lo, id_hi, cong;
  1188. /* Discover phy addr by searching addrs in order {1,0,2,..., 31} */
  1189. for(addr = 0; addr < 32; addr++) {
  1190. nic->mii.phy_id = (addr == 0) ? 1 : (addr == 1) ? 0 : addr;
  1191. bmcr = mdio_read(netdev, nic->mii.phy_id, MII_BMCR);
  1192. stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR);
  1193. stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR);
  1194. if(!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
  1195. break;
  1196. }
  1197. DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
  1198. if(addr == 32)
  1199. return -EAGAIN;
  1200. /* Selected the phy and isolate the rest */
  1201. for(addr = 0; addr < 32; addr++) {
  1202. if(addr != nic->mii.phy_id) {
  1203. mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
  1204. } else {
  1205. bmcr = mdio_read(netdev, addr, MII_BMCR);
  1206. mdio_write(netdev, addr, MII_BMCR,
  1207. bmcr & ~BMCR_ISOLATE);
  1208. }
  1209. }
  1210. /* Get phy ID */
  1211. id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1);
  1212. id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2);
  1213. nic->phy = (u32)id_hi << 16 | (u32)id_lo;
  1214. DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy);
  1215. /* Handle National tx phys */
  1216. #define NCS_PHY_MODEL_MASK 0xFFF0FFFF
  1217. if((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) {
  1218. /* Disable congestion control */
  1219. cong = mdio_read(netdev, nic->mii.phy_id, MII_NSC_CONG);
  1220. cong |= NSC_CONG_TXREADY;
  1221. cong &= ~NSC_CONG_ENABLE;
  1222. mdio_write(netdev, nic->mii.phy_id, MII_NSC_CONG, cong);
  1223. }
  1224. if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) &&
  1225. (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) &&
  1226. !(nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))) {
  1227. /* enable/disable MDI/MDI-X auto-switching. */
  1228. mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG,
  1229. nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH);
  1230. }
  1231. return 0;
  1232. }
  1233. static int e100_hw_init(struct nic *nic)
  1234. {
  1235. int err;
  1236. e100_hw_reset(nic);
  1237. DPRINTK(HW, ERR, "e100_hw_init\n");
  1238. if(!in_interrupt() && (err = e100_self_test(nic)))
  1239. return err;
  1240. if((err = e100_phy_init(nic)))
  1241. return err;
  1242. if((err = e100_exec_cmd(nic, cuc_load_base, 0)))
  1243. return err;
  1244. if((err = e100_exec_cmd(nic, ruc_load_base, 0)))
  1245. return err;
  1246. if ((err = e100_exec_cb_wait(nic, NULL, e100_setup_ucode)))
  1247. return err;
  1248. if((err = e100_exec_cb(nic, NULL, e100_configure)))
  1249. return err;
  1250. if((err = e100_exec_cb(nic, NULL, e100_setup_iaaddr)))
  1251. return err;
  1252. if((err = e100_exec_cmd(nic, cuc_dump_addr,
  1253. nic->dma_addr + offsetof(struct mem, stats))))
  1254. return err;
  1255. if((err = e100_exec_cmd(nic, cuc_dump_reset, 0)))
  1256. return err;
  1257. e100_disable_irq(nic);
  1258. return 0;
  1259. }
  1260. static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  1261. {
  1262. struct net_device *netdev = nic->netdev;
  1263. struct dev_mc_list *list = netdev->mc_list;
  1264. u16 i, count = min(netdev->mc_count, E100_MAX_MULTICAST_ADDRS);
  1265. cb->command = cpu_to_le16(cb_multi);
  1266. cb->u.multi.count = cpu_to_le16(count * ETH_ALEN);
  1267. for(i = 0; list && i < count; i++, list = list->next)
  1268. memcpy(&cb->u.multi.addr[i*ETH_ALEN], &list->dmi_addr,
  1269. ETH_ALEN);
  1270. }
  1271. static void e100_set_multicast_list(struct net_device *netdev)
  1272. {
  1273. struct nic *nic = netdev_priv(netdev);
  1274. DPRINTK(HW, DEBUG, "mc_count=%d, flags=0x%04X\n",
  1275. netdev->mc_count, netdev->flags);
  1276. if(netdev->flags & IFF_PROMISC)
  1277. nic->flags |= promiscuous;
  1278. else
  1279. nic->flags &= ~promiscuous;
  1280. if(netdev->flags & IFF_ALLMULTI ||
  1281. netdev->mc_count > E100_MAX_MULTICAST_ADDRS)
  1282. nic->flags |= multicast_all;
  1283. else
  1284. nic->flags &= ~multicast_all;
  1285. e100_exec_cb(nic, NULL, e100_configure);
  1286. e100_exec_cb(nic, NULL, e100_multi);
  1287. }
  1288. static void e100_update_stats(struct nic *nic)
  1289. {
  1290. struct net_device_stats *ns = &nic->net_stats;
  1291. struct stats *s = &nic->mem->stats;
  1292. u32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause :
  1293. (nic->mac < mac_82559_D101M) ? (u32 *)&s->xmt_tco_frames :
  1294. &s->complete;
  1295. /* Device's stats reporting may take several microseconds to
  1296. * complete, so where always waiting for results of the
  1297. * previous command. */
  1298. if(*complete == le32_to_cpu(cuc_dump_reset_complete)) {
  1299. *complete = 0;
  1300. nic->tx_frames = le32_to_cpu(s->tx_good_frames);
  1301. nic->tx_collisions = le32_to_cpu(s->tx_total_collisions);
  1302. ns->tx_aborted_errors += le32_to_cpu(s->tx_max_collisions);
  1303. ns->tx_window_errors += le32_to_cpu(s->tx_late_collisions);
  1304. ns->tx_carrier_errors += le32_to_cpu(s->tx_lost_crs);
  1305. ns->tx_fifo_errors += le32_to_cpu(s->tx_underruns);
  1306. ns->collisions += nic->tx_collisions;
  1307. ns->tx_errors += le32_to_cpu(s->tx_max_collisions) +
  1308. le32_to_cpu(s->tx_lost_crs);
  1309. ns->rx_length_errors += le32_to_cpu(s->rx_short_frame_errors) +
  1310. nic->rx_over_length_errors;
  1311. ns->rx_crc_errors += le32_to_cpu(s->rx_crc_errors);
  1312. ns->rx_frame_errors += le32_to_cpu(s->rx_alignment_errors);
  1313. ns->rx_over_errors += le32_to_cpu(s->rx_overrun_errors);
  1314. ns->rx_fifo_errors += le32_to_cpu(s->rx_overrun_errors);
  1315. ns->rx_missed_errors += le32_to_cpu(s->rx_resource_errors);
  1316. ns->rx_errors += le32_to_cpu(s->rx_crc_errors) +
  1317. le32_to_cpu(s->rx_alignment_errors) +
  1318. le32_to_cpu(s->rx_short_frame_errors) +
  1319. le32_to_cpu(s->rx_cdt_errors);
  1320. nic->tx_deferred += le32_to_cpu(s->tx_deferred);
  1321. nic->tx_single_collisions +=
  1322. le32_to_cpu(s->tx_single_collisions);
  1323. nic->tx_multiple_collisions +=
  1324. le32_to_cpu(s->tx_multiple_collisions);
  1325. if(nic->mac >= mac_82558_D101_A4) {
  1326. nic->tx_fc_pause += le32_to_cpu(s->fc_xmt_pause);
  1327. nic->rx_fc_pause += le32_to_cpu(s->fc_rcv_pause);
  1328. nic->rx_fc_unsupported +=
  1329. le32_to_cpu(s->fc_rcv_unsupported);
  1330. if(nic->mac >= mac_82559_D101M) {
  1331. nic->tx_tco_frames +=
  1332. le16_to_cpu(s->xmt_tco_frames);
  1333. nic->rx_tco_frames +=
  1334. le16_to_cpu(s->rcv_tco_frames);
  1335. }
  1336. }
  1337. }
  1338. if(e100_exec_cmd(nic, cuc_dump_reset, 0))
  1339. DPRINTK(TX_ERR, DEBUG, "exec cuc_dump_reset failed\n");
  1340. }
  1341. static void e100_adjust_adaptive_ifs(struct nic *nic, int speed, int duplex)
  1342. {
  1343. /* Adjust inter-frame-spacing (IFS) between two transmits if
  1344. * we're getting collisions on a half-duplex connection. */
  1345. if(duplex == DUPLEX_HALF) {
  1346. u32 prev = nic->adaptive_ifs;
  1347. u32 min_frames = (speed == SPEED_100) ? 1000 : 100;
  1348. if((nic->tx_frames / 32 < nic->tx_collisions) &&
  1349. (nic->tx_frames > min_frames)) {
  1350. if(nic->adaptive_ifs < 60)
  1351. nic->adaptive_ifs += 5;
  1352. } else if (nic->tx_frames < min_frames) {
  1353. if(nic->adaptive_ifs >= 5)
  1354. nic->adaptive_ifs -= 5;
  1355. }
  1356. if(nic->adaptive_ifs != prev)
  1357. e100_exec_cb(nic, NULL, e100_configure);
  1358. }
  1359. }
  1360. static void e100_watchdog(unsigned long data)
  1361. {
  1362. struct nic *nic = (struct nic *)data;
  1363. struct ethtool_cmd cmd;
  1364. DPRINTK(TIMER, DEBUG, "right now = %ld\n", jiffies);
  1365. /* mii library handles link maintenance tasks */
  1366. mii_ethtool_gset(&nic->mii, &cmd);
  1367. if(mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) {
  1368. DPRINTK(LINK, INFO, "link up, %sMbps, %s-duplex\n",
  1369. cmd.speed == SPEED_100 ? "100" : "10",
  1370. cmd.duplex == DUPLEX_FULL ? "full" : "half");
  1371. } else if(!mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) {
  1372. DPRINTK(LINK, INFO, "link down\n");
  1373. }
  1374. mii_check_link(&nic->mii);
  1375. /* Software generated interrupt to recover from (rare) Rx
  1376. * allocation failure.
  1377. * Unfortunately have to use a spinlock to not re-enable interrupts
  1378. * accidentally, due to hardware that shares a register between the
  1379. * interrupt mask bit and the SW Interrupt generation bit */
  1380. spin_lock_irq(&nic->cmd_lock);
  1381. writeb(readb(&nic->csr->scb.cmd_hi) | irq_sw_gen,&nic->csr->scb.cmd_hi);
  1382. e100_write_flush(nic);
  1383. spin_unlock_irq(&nic->cmd_lock);
  1384. e100_update_stats(nic);
  1385. e100_adjust_adaptive_ifs(nic, cmd.speed, cmd.duplex);
  1386. if(nic->mac <= mac_82557_D100_C)
  1387. /* Issue a multicast command to workaround a 557 lock up */
  1388. e100_set_multicast_list(nic->netdev);
  1389. if(nic->flags & ich && cmd.speed==SPEED_10 && cmd.duplex==DUPLEX_HALF)
  1390. /* Need SW workaround for ICH[x] 10Mbps/half duplex Tx hang. */
  1391. nic->flags |= ich_10h_workaround;
  1392. else
  1393. nic->flags &= ~ich_10h_workaround;
  1394. mod_timer(&nic->watchdog, jiffies + E100_WATCHDOG_PERIOD);
  1395. }
  1396. static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
  1397. struct sk_buff *skb)
  1398. {
  1399. cb->command = nic->tx_command;
  1400. /* interrupt every 16 packets regardless of delay */
  1401. if((nic->cbs_avail & ~15) == nic->cbs_avail)
  1402. cb->command |= cpu_to_le16(cb_i);
  1403. cb->u.tcb.tbd_array = cb->dma_addr + offsetof(struct cb, u.tcb.tbd);
  1404. cb->u.tcb.tcb_byte_count = 0;
  1405. cb->u.tcb.threshold = nic->tx_threshold;
  1406. cb->u.tcb.tbd_count = 1;
  1407. cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
  1408. skb->data, skb->len, PCI_DMA_TODEVICE));
  1409. /* check for mapping failure? */
  1410. cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
  1411. }
  1412. static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  1413. {
  1414. struct nic *nic = netdev_priv(netdev);
  1415. int err;
  1416. if(nic->flags & ich_10h_workaround) {
  1417. /* SW workaround for ICH[x] 10Mbps/half duplex Tx hang.
  1418. Issue a NOP command followed by a 1us delay before
  1419. issuing the Tx command. */
  1420. if(e100_exec_cmd(nic, cuc_nop, 0))
  1421. DPRINTK(TX_ERR, DEBUG, "exec cuc_nop failed\n");
  1422. udelay(1);
  1423. }
  1424. err = e100_exec_cb(nic, skb, e100_xmit_prepare);
  1425. switch(err) {
  1426. case -ENOSPC:
  1427. /* We queued the skb, but now we're out of space. */
  1428. DPRINTK(TX_ERR, DEBUG, "No space for CB\n");
  1429. netif_stop_queue(netdev);
  1430. break;
  1431. case -ENOMEM:
  1432. /* This is a hard error - log it. */
  1433. DPRINTK(TX_ERR, DEBUG, "Out of Tx resources, returning skb\n");
  1434. netif_stop_queue(netdev);
  1435. return 1;
  1436. }
  1437. netdev->trans_start = jiffies;
  1438. return 0;
  1439. }
  1440. static int e100_tx_clean(struct nic *nic)
  1441. {
  1442. struct cb *cb;
  1443. int tx_cleaned = 0;
  1444. spin_lock(&nic->cb_lock);
  1445. DPRINTK(TX_DONE, DEBUG, "cb->status = 0x%04X\n",
  1446. nic->cb_to_clean->status);
  1447. /* Clean CBs marked complete */
  1448. for(cb = nic->cb_to_clean;
  1449. cb->status & cpu_to_le16(cb_complete);
  1450. cb = nic->cb_to_clean = cb->next) {
  1451. if(likely(cb->skb != NULL)) {
  1452. nic->net_stats.tx_packets++;
  1453. nic->net_stats.tx_bytes += cb->skb->len;
  1454. pci_unmap_single(nic->pdev,
  1455. le32_to_cpu(cb->u.tcb.tbd.buf_addr),
  1456. le16_to_cpu(cb->u.tcb.tbd.size),
  1457. PCI_DMA_TODEVICE);
  1458. dev_kfree_skb_any(cb->skb);
  1459. cb->skb = NULL;
  1460. tx_cleaned = 1;
  1461. }
  1462. cb->status = 0;
  1463. nic->cbs_avail++;
  1464. }
  1465. spin_unlock(&nic->cb_lock);
  1466. /* Recover from running out of Tx resources in xmit_frame */
  1467. if(unlikely(tx_cleaned && netif_queue_stopped(nic->netdev)))
  1468. netif_wake_queue(nic->netdev);
  1469. return tx_cleaned;
  1470. }
  1471. static void e100_clean_cbs(struct nic *nic)
  1472. {
  1473. if(nic->cbs) {
  1474. while(nic->cbs_avail != nic->params.cbs.count) {
  1475. struct cb *cb = nic->cb_to_clean;
  1476. if(cb->skb) {
  1477. pci_unmap_single(nic->pdev,
  1478. le32_to_cpu(cb->u.tcb.tbd.buf_addr),
  1479. le16_to_cpu(cb->u.tcb.tbd.size),
  1480. PCI_DMA_TODEVICE);
  1481. dev_kfree_skb(cb->skb);
  1482. }
  1483. nic->cb_to_clean = nic->cb_to_clean->next;
  1484. nic->cbs_avail++;
  1485. }
  1486. pci_free_consistent(nic->pdev,
  1487. sizeof(struct cb) * nic->params.cbs.count,
  1488. nic->cbs, nic->cbs_dma_addr);
  1489. nic->cbs = NULL;
  1490. nic->cbs_avail = 0;
  1491. }
  1492. nic->cuc_cmd = cuc_start;
  1493. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean =
  1494. nic->cbs;
  1495. }
  1496. static int e100_alloc_cbs(struct nic *nic)
  1497. {
  1498. struct cb *cb;
  1499. unsigned int i, count = nic->params.cbs.count;
  1500. nic->cuc_cmd = cuc_start;
  1501. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL;
  1502. nic->cbs_avail = 0;
  1503. nic->cbs = pci_alloc_consistent(nic->pdev,
  1504. sizeof(struct cb) * count, &nic->cbs_dma_addr);
  1505. if(!nic->cbs)
  1506. return -ENOMEM;
  1507. for(cb = nic->cbs, i = 0; i < count; cb++, i++) {
  1508. cb->next = (i + 1 < count) ? cb + 1 : nic->cbs;
  1509. cb->prev = (i == 0) ? nic->cbs + count - 1 : cb - 1;
  1510. cb->dma_addr = nic->cbs_dma_addr + i * sizeof(struct cb);
  1511. cb->link = cpu_to_le32(nic->cbs_dma_addr +
  1512. ((i+1) % count) * sizeof(struct cb));
  1513. cb->skb = NULL;
  1514. }
  1515. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs;
  1516. nic->cbs_avail = count;
  1517. return 0;
  1518. }
  1519. static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
  1520. {
  1521. if(!nic->rxs) return;
  1522. if(RU_SUSPENDED != nic->ru_running) return;
  1523. /* handle init time starts */
  1524. if(!rx) rx = nic->rxs;
  1525. /* (Re)start RU if suspended or idle and RFA is non-NULL */
  1526. if(rx->skb) {
  1527. e100_exec_cmd(nic, ruc_start, rx->dma_addr);
  1528. nic->ru_running = RU_RUNNING;
  1529. }
  1530. }
  1531. #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
  1532. static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
  1533. {
  1534. if(!(rx->skb = netdev_alloc_skb(nic->netdev, RFD_BUF_LEN + NET_IP_ALIGN)))
  1535. return -ENOMEM;
  1536. /* Align, init, and map the RFD. */
  1537. skb_reserve(rx->skb, NET_IP_ALIGN);
  1538. memcpy(rx->skb->data, &nic->blank_rfd, sizeof(struct rfd));
  1539. rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
  1540. RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
  1541. if(pci_dma_mapping_error(rx->dma_addr)) {
  1542. dev_kfree_skb_any(rx->skb);
  1543. rx->skb = NULL;
  1544. rx->dma_addr = 0;
  1545. return -ENOMEM;
  1546. }
  1547. /* Link the RFD to end of RFA by linking previous RFD to
  1548. * this one, and clearing EL bit of previous. */
  1549. if(rx->prev->skb) {
  1550. struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data;
  1551. put_unaligned(cpu_to_le32(rx->dma_addr),
  1552. (u32 *)&prev_rfd->link);
  1553. wmb();
  1554. prev_rfd->command &= ~cpu_to_le16(cb_el);
  1555. pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
  1556. sizeof(struct rfd), PCI_DMA_TODEVICE);
  1557. }
  1558. return 0;
  1559. }
  1560. static int e100_rx_indicate(struct nic *nic, struct rx *rx,
  1561. unsigned int *work_done, unsigned int work_to_do)
  1562. {
  1563. struct sk_buff *skb = rx->skb;
  1564. struct rfd *rfd = (struct rfd *)skb->data;
  1565. u16 rfd_status, actual_size;
  1566. if(unlikely(work_done && *work_done >= work_to_do))
  1567. return -EAGAIN;
  1568. /* Need to sync before taking a peek at cb_complete bit */
  1569. pci_dma_sync_single_for_cpu(nic->pdev, rx->dma_addr,
  1570. sizeof(struct rfd), PCI_DMA_FROMDEVICE);
  1571. rfd_status = le16_to_cpu(rfd->status);
  1572. DPRINTK(RX_STATUS, DEBUG, "status=0x%04X\n", rfd_status);
  1573. /* If data isn't ready, nothing to indicate */
  1574. if(unlikely(!(rfd_status & cb_complete)))
  1575. return -ENODATA;
  1576. /* Get actual data size */
  1577. actual_size = le16_to_cpu(rfd->actual_size) & 0x3FFF;
  1578. if(unlikely(actual_size > RFD_BUF_LEN - sizeof(struct rfd)))
  1579. actual_size = RFD_BUF_LEN - sizeof(struct rfd);
  1580. /* Get data */
  1581. pci_unmap_single(nic->pdev, rx->dma_addr,
  1582. RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
  1583. /* this allows for a fast restart without re-enabling interrupts */
  1584. if(le16_to_cpu(rfd->command) & cb_el)
  1585. nic->ru_running = RU_SUSPENDED;
  1586. /* Pull off the RFD and put the actual data (minus eth hdr) */
  1587. skb_reserve(skb, sizeof(struct rfd));
  1588. skb_put(skb, actual_size);
  1589. skb->protocol = eth_type_trans(skb, nic->netdev);
  1590. if(unlikely(!(rfd_status & cb_ok))) {
  1591. /* Don't indicate if hardware indicates errors */
  1592. dev_kfree_skb_any(skb);
  1593. } else if(actual_size > ETH_DATA_LEN + VLAN_ETH_HLEN) {
  1594. /* Don't indicate oversized frames */
  1595. nic->rx_over_length_errors++;
  1596. dev_kfree_skb_any(skb);
  1597. } else {
  1598. nic->net_stats.rx_packets++;
  1599. nic->net_stats.rx_bytes += actual_size;
  1600. nic->netdev->last_rx = jiffies;
  1601. netif_receive_skb(skb);
  1602. if(work_done)
  1603. (*work_done)++;
  1604. }
  1605. rx->skb = NULL;
  1606. return 0;
  1607. }
  1608. static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
  1609. unsigned int work_to_do)
  1610. {
  1611. struct rx *rx;
  1612. int restart_required = 0;
  1613. struct rx *rx_to_start = NULL;
  1614. /* are we already rnr? then pay attention!!! this ensures that
  1615. * the state machine progression never allows a start with a
  1616. * partially cleaned list, avoiding a race between hardware
  1617. * and rx_to_clean when in NAPI mode */
  1618. if(RU_SUSPENDED == nic->ru_running)
  1619. restart_required = 1;
  1620. /* Indicate newly arrived packets */
  1621. for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
  1622. int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
  1623. if(-EAGAIN == err) {
  1624. /* hit quota so have more work to do, restart once
  1625. * cleanup is complete */
  1626. restart_required = 0;
  1627. break;
  1628. } else if(-ENODATA == err)
  1629. break; /* No more to clean */
  1630. }
  1631. /* save our starting point as the place we'll restart the receiver */
  1632. if(restart_required)
  1633. rx_to_start = nic->rx_to_clean;
  1634. /* Alloc new skbs to refill list */
  1635. for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
  1636. if(unlikely(e100_rx_alloc_skb(nic, rx)))
  1637. break; /* Better luck next time (see watchdog) */
  1638. }
  1639. if(restart_required) {
  1640. // ack the rnr?
  1641. writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
  1642. e100_start_receiver(nic, rx_to_start);
  1643. if(work_done)
  1644. (*work_done)++;
  1645. }
  1646. }
  1647. static void e100_rx_clean_list(struct nic *nic)
  1648. {
  1649. struct rx *rx;
  1650. unsigned int i, count = nic->params.rfds.count;
  1651. nic->ru_running = RU_UNINITIALIZED;
  1652. if(nic->rxs) {
  1653. for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
  1654. if(rx->skb) {
  1655. pci_unmap_single(nic->pdev, rx->dma_addr,
  1656. RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
  1657. dev_kfree_skb(rx->skb);
  1658. }
  1659. }
  1660. kfree(nic->rxs);
  1661. nic->rxs = NULL;
  1662. }
  1663. nic->rx_to_use = nic->rx_to_clean = NULL;
  1664. }
  1665. static int e100_rx_alloc_list(struct nic *nic)
  1666. {
  1667. struct rx *rx;
  1668. unsigned int i, count = nic->params.rfds.count;
  1669. nic->rx_to_use = nic->rx_to_clean = NULL;
  1670. nic->ru_running = RU_UNINITIALIZED;
  1671. if(!(nic->rxs = kmalloc(sizeof(struct rx) * count, GFP_ATOMIC)))
  1672. return -ENOMEM;
  1673. memset(nic->rxs, 0, sizeof(struct rx) * count);
  1674. for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
  1675. rx->next = (i + 1 < count) ? rx + 1 : nic->rxs;
  1676. rx->prev = (i == 0) ? nic->rxs + count - 1 : rx - 1;
  1677. if(e100_rx_alloc_skb(nic, rx)) {
  1678. e100_rx_clean_list(nic);
  1679. return -ENOMEM;
  1680. }
  1681. }
  1682. nic->rx_to_use = nic->rx_to_clean = nic->rxs;
  1683. nic->ru_running = RU_SUSPENDED;
  1684. return 0;
  1685. }
  1686. static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
  1687. {
  1688. struct net_device *netdev = dev_id;
  1689. struct nic *nic = netdev_priv(netdev);
  1690. u8 stat_ack = readb(&nic->csr->scb.stat_ack);
  1691. DPRINTK(INTR, DEBUG, "stat_ack = 0x%02X\n", stat_ack);
  1692. if(stat_ack == stat_ack_not_ours || /* Not our interrupt */
  1693. stat_ack == stat_ack_not_present) /* Hardware is ejected */
  1694. return IRQ_NONE;
  1695. /* Ack interrupt(s) */
  1696. writeb(stat_ack, &nic->csr->scb.stat_ack);
  1697. /* We hit Receive No Resource (RNR); restart RU after cleaning */
  1698. if(stat_ack & stat_ack_rnr)
  1699. nic->ru_running = RU_SUSPENDED;
  1700. if(likely(netif_rx_schedule_prep(netdev))) {
  1701. e100_disable_irq(nic);
  1702. __netif_rx_schedule(netdev);
  1703. }
  1704. return IRQ_HANDLED;
  1705. }
  1706. static int e100_poll(struct net_device *netdev, int *budget)
  1707. {
  1708. struct nic *nic = netdev_priv(netdev);
  1709. unsigned int work_to_do = min(netdev->quota, *budget);
  1710. unsigned int work_done = 0;
  1711. int tx_cleaned;
  1712. e100_rx_clean(nic, &work_done, work_to_do);
  1713. tx_cleaned = e100_tx_clean(nic);
  1714. /* If no Rx and Tx cleanup work was done, exit polling mode. */
  1715. if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
  1716. netif_rx_complete(netdev);
  1717. e100_enable_irq(nic);
  1718. return 0;
  1719. }
  1720. *budget -= work_done;
  1721. netdev->quota -= work_done;
  1722. return 1;
  1723. }
  1724. #ifdef CONFIG_NET_POLL_CONTROLLER
  1725. static void e100_netpoll(struct net_device *netdev)
  1726. {
  1727. struct nic *nic = netdev_priv(netdev);
  1728. e100_disable_irq(nic);
  1729. e100_intr(nic->pdev->irq, netdev, NULL);
  1730. e100_tx_clean(nic);
  1731. e100_enable_irq(nic);
  1732. }
  1733. #endif
  1734. static struct net_device_stats *e100_get_stats(struct net_device *netdev)
  1735. {
  1736. struct nic *nic = netdev_priv(netdev);
  1737. return &nic->net_stats;
  1738. }
  1739. static int e100_set_mac_address(struct net_device *netdev, void *p)
  1740. {
  1741. struct nic *nic = netdev_priv(netdev);
  1742. struct sockaddr *addr = p;
  1743. if (!is_valid_ether_addr(addr->sa_data))
  1744. return -EADDRNOTAVAIL;
  1745. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1746. e100_exec_cb(nic, NULL, e100_setup_iaaddr);
  1747. return 0;
  1748. }
  1749. static int e100_change_mtu(struct net_device *netdev, int new_mtu)
  1750. {
  1751. if(new_mtu < ETH_ZLEN || new_mtu > ETH_DATA_LEN)
  1752. return -EINVAL;
  1753. netdev->mtu = new_mtu;
  1754. return 0;
  1755. }
  1756. #ifdef CONFIG_PM
  1757. static int e100_asf(struct nic *nic)
  1758. {
  1759. /* ASF can be enabled from eeprom */
  1760. return((nic->pdev->device >= 0x1050) && (nic->pdev->device <= 0x1057) &&
  1761. (nic->eeprom[eeprom_config_asf] & eeprom_asf) &&
  1762. !(nic->eeprom[eeprom_config_asf] & eeprom_gcl) &&
  1763. ((nic->eeprom[eeprom_smbus_addr] & 0xFF) != 0xFE));
  1764. }
  1765. #endif
  1766. static int e100_up(struct nic *nic)
  1767. {
  1768. int err;
  1769. if((err = e100_rx_alloc_list(nic)))
  1770. return err;
  1771. if((err = e100_alloc_cbs(nic)))
  1772. goto err_rx_clean_list;
  1773. if((err = e100_hw_init(nic)))
  1774. goto err_clean_cbs;
  1775. e100_set_multicast_list(nic->netdev);
  1776. e100_start_receiver(nic, NULL);
  1777. mod_timer(&nic->watchdog, jiffies);
  1778. if((err = request_irq(nic->pdev->irq, e100_intr, IRQF_SHARED,
  1779. nic->netdev->name, nic->netdev)))
  1780. goto err_no_irq;
  1781. netif_wake_queue(nic->netdev);
  1782. netif_poll_enable(nic->netdev);
  1783. /* enable ints _after_ enabling poll, preventing a race between
  1784. * disable ints+schedule */
  1785. e100_enable_irq(nic);
  1786. return 0;
  1787. err_no_irq:
  1788. del_timer_sync(&nic->watchdog);
  1789. err_clean_cbs:
  1790. e100_clean_cbs(nic);
  1791. err_rx_clean_list:
  1792. e100_rx_clean_list(nic);
  1793. return err;
  1794. }
  1795. static void e100_down(struct nic *nic)
  1796. {
  1797. /* wait here for poll to complete */
  1798. netif_poll_disable(nic->netdev);
  1799. netif_stop_queue(nic->netdev);
  1800. e100_hw_reset(nic);
  1801. free_irq(nic->pdev->irq, nic->netdev);
  1802. del_timer_sync(&nic->watchdog);
  1803. netif_carrier_off(nic->netdev);
  1804. e100_clean_cbs(nic);
  1805. e100_rx_clean_list(nic);
  1806. }
  1807. static void e100_tx_timeout(struct net_device *netdev)
  1808. {
  1809. struct nic *nic = netdev_priv(netdev);
  1810. /* Reset outside of interrupt context, to avoid request_irq
  1811. * in interrupt context */
  1812. schedule_work(&nic->tx_timeout_task);
  1813. }
  1814. static void e100_tx_timeout_task(struct net_device *netdev)
  1815. {
  1816. struct nic *nic = netdev_priv(netdev);
  1817. DPRINTK(TX_ERR, DEBUG, "scb.status=0x%02X\n",
  1818. readb(&nic->csr->scb.status));
  1819. e100_down(netdev_priv(netdev));
  1820. e100_up(netdev_priv(netdev));
  1821. }
  1822. static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
  1823. {
  1824. int err;
  1825. struct sk_buff *skb;
  1826. /* Use driver resources to perform internal MAC or PHY
  1827. * loopback test. A single packet is prepared and transmitted
  1828. * in loopback mode, and the test passes if the received
  1829. * packet compares byte-for-byte to the transmitted packet. */
  1830. if((err = e100_rx_alloc_list(nic)))
  1831. return err;
  1832. if((err = e100_alloc_cbs(nic)))
  1833. goto err_clean_rx;
  1834. /* ICH PHY loopback is broken so do MAC loopback instead */
  1835. if(nic->flags & ich && loopback_mode == lb_phy)
  1836. loopback_mode = lb_mac;
  1837. nic->loopback = loopback_mode;
  1838. if((err = e100_hw_init(nic)))
  1839. goto err_loopback_none;
  1840. if(loopback_mode == lb_phy)
  1841. mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR,
  1842. BMCR_LOOPBACK);
  1843. e100_start_receiver(nic, NULL);
  1844. if(!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) {
  1845. err = -ENOMEM;
  1846. goto err_loopback_none;
  1847. }
  1848. skb_put(skb, ETH_DATA_LEN);
  1849. memset(skb->data, 0xFF, ETH_DATA_LEN);
  1850. e100_xmit_frame(skb, nic->netdev);
  1851. msleep(10);
  1852. pci_dma_sync_single_for_cpu(nic->pdev, nic->rx_to_clean->dma_addr,
  1853. RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
  1854. if(memcmp(nic->rx_to_clean->skb->data + sizeof(struct rfd),
  1855. skb->data, ETH_DATA_LEN))
  1856. err = -EAGAIN;
  1857. err_loopback_none:
  1858. mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR, 0);
  1859. nic->loopback = lb_none;
  1860. e100_clean_cbs(nic);
  1861. e100_hw_reset(nic);
  1862. err_clean_rx:
  1863. e100_rx_clean_list(nic);
  1864. return err;
  1865. }
  1866. #define MII_LED_CONTROL 0x1B
  1867. static void e100_blink_led(unsigned long data)
  1868. {
  1869. struct nic *nic = (struct nic *)data;
  1870. enum led_state {
  1871. led_on = 0x01,
  1872. led_off = 0x04,
  1873. led_on_559 = 0x05,
  1874. led_on_557 = 0x07,
  1875. };
  1876. nic->leds = (nic->leds & led_on) ? led_off :
  1877. (nic->mac < mac_82559_D101M) ? led_on_557 : led_on_559;
  1878. mdio_write(nic->netdev, nic->mii.phy_id, MII_LED_CONTROL, nic->leds);
  1879. mod_timer(&nic->blink_timer, jiffies + HZ / 4);
  1880. }
  1881. static int e100_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1882. {
  1883. struct nic *nic = netdev_priv(netdev);
  1884. return mii_ethtool_gset(&nic->mii, cmd);
  1885. }
  1886. static int e100_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1887. {
  1888. struct nic *nic = netdev_priv(netdev);
  1889. int err;
  1890. mdio_write(netdev, nic->mii.phy_id, MII_BMCR, BMCR_RESET);
  1891. err = mii_ethtool_sset(&nic->mii, cmd);
  1892. e100_exec_cb(nic, NULL, e100_configure);
  1893. return err;
  1894. }
  1895. static void e100_get_drvinfo(struct net_device *netdev,
  1896. struct ethtool_drvinfo *info)
  1897. {
  1898. struct nic *nic = netdev_priv(netdev);
  1899. strcpy(info->driver, DRV_NAME);
  1900. strcpy(info->version, DRV_VERSION);
  1901. strcpy(info->fw_version, "N/A");
  1902. strcpy(info->bus_info, pci_name(nic->pdev));
  1903. }
  1904. static int e100_get_regs_len(struct net_device *netdev)
  1905. {
  1906. struct nic *nic = netdev_priv(netdev);
  1907. #define E100_PHY_REGS 0x1C
  1908. #define E100_REGS_LEN 1 + E100_PHY_REGS + \
  1909. sizeof(nic->mem->dump_buf) / sizeof(u32)
  1910. return E100_REGS_LEN * sizeof(u32);
  1911. }
  1912. static void e100_get_regs(struct net_device *netdev,
  1913. struct ethtool_regs *regs, void *p)
  1914. {
  1915. struct nic *nic = netdev_priv(netdev);
  1916. u32 *buff = p;
  1917. int i;
  1918. regs->version = (1 << 24) | nic->rev_id;
  1919. buff[0] = readb(&nic->csr->scb.cmd_hi) << 24 |
  1920. readb(&nic->csr->scb.cmd_lo) << 16 |
  1921. readw(&nic->csr->scb.status);
  1922. for(i = E100_PHY_REGS; i >= 0; i--)
  1923. buff[1 + E100_PHY_REGS - i] =
  1924. mdio_read(netdev, nic->mii.phy_id, i);
  1925. memset(nic->mem->dump_buf, 0, sizeof(nic->mem->dump_buf));
  1926. e100_exec_cb(nic, NULL, e100_dump);
  1927. msleep(10);
  1928. memcpy(&buff[2 + E100_PHY_REGS], nic->mem->dump_buf,
  1929. sizeof(nic->mem->dump_buf));
  1930. }
  1931. static void e100_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1932. {
  1933. struct nic *nic = netdev_priv(netdev);
  1934. wol->supported = (nic->mac >= mac_82558_D101_A4) ? WAKE_MAGIC : 0;
  1935. wol->wolopts = (nic->flags & wol_magic) ? WAKE_MAGIC : 0;
  1936. }
  1937. static int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1938. {
  1939. struct nic *nic = netdev_priv(netdev);
  1940. if(wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
  1941. return -EOPNOTSUPP;
  1942. if(wol->wolopts)
  1943. nic->flags |= wol_magic;
  1944. else
  1945. nic->flags &= ~wol_magic;
  1946. e100_exec_cb(nic, NULL, e100_configure);
  1947. return 0;
  1948. }
  1949. static u32 e100_get_msglevel(struct net_device *netdev)
  1950. {
  1951. struct nic *nic = netdev_priv(netdev);
  1952. return nic->msg_enable;
  1953. }
  1954. static void e100_set_msglevel(struct net_device *netdev, u32 value)
  1955. {
  1956. struct nic *nic = netdev_priv(netdev);
  1957. nic->msg_enable = value;
  1958. }
  1959. static int e100_nway_reset(struct net_device *netdev)
  1960. {
  1961. struct nic *nic = netdev_priv(netdev);
  1962. return mii_nway_restart(&nic->mii);
  1963. }
  1964. static u32 e100_get_link(struct net_device *netdev)
  1965. {
  1966. struct nic *nic = netdev_priv(netdev);
  1967. return mii_link_ok(&nic->mii);
  1968. }
  1969. static int e100_get_eeprom_len(struct net_device *netdev)
  1970. {
  1971. struct nic *nic = netdev_priv(netdev);
  1972. return nic->eeprom_wc << 1;
  1973. }
  1974. #define E100_EEPROM_MAGIC 0x1234
  1975. static int e100_get_eeprom(struct net_device *netdev,
  1976. struct ethtool_eeprom *eeprom, u8 *bytes)
  1977. {
  1978. struct nic *nic = netdev_priv(netdev);
  1979. eeprom->magic = E100_EEPROM_MAGIC;
  1980. memcpy(bytes, &((u8 *)nic->eeprom)[eeprom->offset], eeprom->len);
  1981. return 0;
  1982. }
  1983. static int e100_set_eeprom(struct net_device *netdev,
  1984. struct ethtool_eeprom *eeprom, u8 *bytes)
  1985. {
  1986. struct nic *nic = netdev_priv(netdev);
  1987. if(eeprom->magic != E100_EEPROM_MAGIC)
  1988. return -EINVAL;
  1989. memcpy(&((u8 *)nic->eeprom)[eeprom->offset], bytes, eeprom->len);
  1990. return e100_eeprom_save(nic, eeprom->offset >> 1,
  1991. (eeprom->len >> 1) + 1);
  1992. }
  1993. static void e100_get_ringparam(struct net_device *netdev,
  1994. struct ethtool_ringparam *ring)
  1995. {
  1996. struct nic *nic = netdev_priv(netdev);
  1997. struct param_range *rfds = &nic->params.rfds;
  1998. struct param_range *cbs = &nic->params.cbs;
  1999. ring->rx_max_pending = rfds->max;
  2000. ring->tx_max_pending = cbs->max;
  2001. ring->rx_mini_max_pending = 0;
  2002. ring->rx_jumbo_max_pending = 0;
  2003. ring->rx_pending = rfds->count;
  2004. ring->tx_pending = cbs->count;
  2005. ring->rx_mini_pending = 0;
  2006. ring->rx_jumbo_pending = 0;
  2007. }
  2008. static int e100_set_ringparam(struct net_device *netdev,
  2009. struct ethtool_ringparam *ring)
  2010. {
  2011. struct nic *nic = netdev_priv(netdev);
  2012. struct param_range *rfds = &nic->params.rfds;
  2013. struct param_range *cbs = &nic->params.cbs;
  2014. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  2015. return -EINVAL;
  2016. if(netif_running(netdev))
  2017. e100_down(nic);
  2018. rfds->count = max(ring->rx_pending, rfds->min);
  2019. rfds->count = min(rfds->count, rfds->max);
  2020. cbs->count = max(ring->tx_pending, cbs->min);
  2021. cbs->count = min(cbs->count, cbs->max);
  2022. DPRINTK(DRV, INFO, "Ring Param settings: rx: %d, tx %d\n",
  2023. rfds->count, cbs->count);
  2024. if(netif_running(netdev))
  2025. e100_up(nic);
  2026. return 0;
  2027. }
  2028. static const char e100_gstrings_test[][ETH_GSTRING_LEN] = {
  2029. "Link test (on/offline)",
  2030. "Eeprom test (on/offline)",
  2031. "Self test (offline)",
  2032. "Mac loopback (offline)",
  2033. "Phy loopback (offline)",
  2034. };
  2035. #define E100_TEST_LEN sizeof(e100_gstrings_test) / ETH_GSTRING_LEN
  2036. static int e100_diag_test_count(struct net_device *netdev)
  2037. {
  2038. return E100_TEST_LEN;
  2039. }
  2040. static void e100_diag_test(struct net_device *netdev,
  2041. struct ethtool_test *test, u64 *data)
  2042. {
  2043. struct ethtool_cmd cmd;
  2044. struct nic *nic = netdev_priv(netdev);
  2045. int i, err;
  2046. memset(data, 0, E100_TEST_LEN * sizeof(u64));
  2047. data[0] = !mii_link_ok(&nic->mii);
  2048. data[1] = e100_eeprom_load(nic);
  2049. if(test->flags & ETH_TEST_FL_OFFLINE) {
  2050. /* save speed, duplex & autoneg settings */
  2051. err = mii_ethtool_gset(&nic->mii, &cmd);
  2052. if(netif_running(netdev))
  2053. e100_down(nic);
  2054. data[2] = e100_self_test(nic);
  2055. data[3] = e100_loopback_test(nic, lb_mac);
  2056. data[4] = e100_loopback_test(nic, lb_phy);
  2057. /* restore speed, duplex & autoneg settings */
  2058. err = mii_ethtool_sset(&nic->mii, &cmd);
  2059. if(netif_running(netdev))
  2060. e100_up(nic);
  2061. }
  2062. for(i = 0; i < E100_TEST_LEN; i++)
  2063. test->flags |= data[i] ? ETH_TEST_FL_FAILED : 0;
  2064. msleep_interruptible(4 * 1000);
  2065. }
  2066. static int e100_phys_id(struct net_device *netdev, u32 data)
  2067. {
  2068. struct nic *nic = netdev_priv(netdev);
  2069. if(!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
  2070. data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
  2071. mod_timer(&nic->blink_timer, jiffies);
  2072. msleep_interruptible(data * 1000);
  2073. del_timer_sync(&nic->blink_timer);
  2074. mdio_write(netdev, nic->mii.phy_id, MII_LED_CONTROL, 0);
  2075. return 0;
  2076. }
  2077. static const char e100_gstrings_stats[][ETH_GSTRING_LEN] = {
  2078. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  2079. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  2080. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  2081. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  2082. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  2083. "tx_heartbeat_errors", "tx_window_errors",
  2084. /* device-specific stats */
  2085. "tx_deferred", "tx_single_collisions", "tx_multi_collisions",
  2086. "tx_flow_control_pause", "rx_flow_control_pause",
  2087. "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets",
  2088. };
  2089. #define E100_NET_STATS_LEN 21
  2090. #define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN
  2091. static int e100_get_stats_count(struct net_device *netdev)
  2092. {
  2093. return E100_STATS_LEN;
  2094. }
  2095. static void e100_get_ethtool_stats(struct net_device *netdev,
  2096. struct ethtool_stats *stats, u64 *data)
  2097. {
  2098. struct nic *nic = netdev_priv(netdev);
  2099. int i;
  2100. for(i = 0; i < E100_NET_STATS_LEN; i++)
  2101. data[i] = ((unsigned long *)&nic->net_stats)[i];
  2102. data[i++] = nic->tx_deferred;
  2103. data[i++] = nic->tx_single_collisions;
  2104. data[i++] = nic->tx_multiple_collisions;
  2105. data[i++] = nic->tx_fc_pause;
  2106. data[i++] = nic->rx_fc_pause;
  2107. data[i++] = nic->rx_fc_unsupported;
  2108. data[i++] = nic->tx_tco_frames;
  2109. data[i++] = nic->rx_tco_frames;
  2110. }
  2111. static void e100_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  2112. {
  2113. switch(stringset) {
  2114. case ETH_SS_TEST:
  2115. memcpy(data, *e100_gstrings_test, sizeof(e100_gstrings_test));
  2116. break;
  2117. case ETH_SS_STATS:
  2118. memcpy(data, *e100_gstrings_stats, sizeof(e100_gstrings_stats));
  2119. break;
  2120. }
  2121. }
  2122. static struct ethtool_ops e100_ethtool_ops = {
  2123. .get_settings = e100_get_settings,
  2124. .set_settings = e100_set_settings,
  2125. .get_drvinfo = e100_get_drvinfo,
  2126. .get_regs_len = e100_get_regs_len,
  2127. .get_regs = e100_get_regs,
  2128. .get_wol = e100_get_wol,
  2129. .set_wol = e100_set_wol,
  2130. .get_msglevel = e100_get_msglevel,
  2131. .set_msglevel = e100_set_msglevel,
  2132. .nway_reset = e100_nway_reset,
  2133. .get_link = e100_get_link,
  2134. .get_eeprom_len = e100_get_eeprom_len,
  2135. .get_eeprom = e100_get_eeprom,
  2136. .set_eeprom = e100_set_eeprom,
  2137. .get_ringparam = e100_get_ringparam,
  2138. .set_ringparam = e100_set_ringparam,
  2139. .self_test_count = e100_diag_test_count,
  2140. .self_test = e100_diag_test,
  2141. .get_strings = e100_get_strings,
  2142. .phys_id = e100_phys_id,
  2143. .get_stats_count = e100_get_stats_count,
  2144. .get_ethtool_stats = e100_get_ethtool_stats,
  2145. .get_perm_addr = ethtool_op_get_perm_addr,
  2146. };
  2147. static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2148. {
  2149. struct nic *nic = netdev_priv(netdev);
  2150. return generic_mii_ioctl(&nic->mii, if_mii(ifr), cmd, NULL);
  2151. }
  2152. static int e100_alloc(struct nic *nic)
  2153. {
  2154. nic->mem = pci_alloc_consistent(nic->pdev, sizeof(struct mem),
  2155. &nic->dma_addr);
  2156. return nic->mem ? 0 : -ENOMEM;
  2157. }
  2158. static void e100_free(struct nic *nic)
  2159. {
  2160. if(nic->mem) {
  2161. pci_free_consistent(nic->pdev, sizeof(struct mem),
  2162. nic->mem, nic->dma_addr);
  2163. nic->mem = NULL;
  2164. }
  2165. }
  2166. static int e100_open(struct net_device *netdev)
  2167. {
  2168. struct nic *nic = netdev_priv(netdev);
  2169. int err = 0;
  2170. netif_carrier_off(netdev);
  2171. if((err = e100_up(nic)))
  2172. DPRINTK(IFUP, ERR, "Cannot open interface, aborting.\n");
  2173. return err;
  2174. }
  2175. static int e100_close(struct net_device *netdev)
  2176. {
  2177. e100_down(netdev_priv(netdev));
  2178. return 0;
  2179. }
  2180. static int __devinit e100_probe(struct pci_dev *pdev,
  2181. const struct pci_device_id *ent)
  2182. {
  2183. struct net_device *netdev;
  2184. struct nic *nic;
  2185. int err;
  2186. if(!(netdev = alloc_etherdev(sizeof(struct nic)))) {
  2187. if(((1 << debug) - 1) & NETIF_MSG_PROBE)
  2188. printk(KERN_ERR PFX "Etherdev alloc failed, abort.\n");
  2189. return -ENOMEM;
  2190. }
  2191. netdev->open = e100_open;
  2192. netdev->stop = e100_close;
  2193. netdev->hard_start_xmit = e100_xmit_frame;
  2194. netdev->get_stats = e100_get_stats;
  2195. netdev->set_multicast_list = e100_set_multicast_list;
  2196. netdev->set_mac_address = e100_set_mac_address;
  2197. netdev->change_mtu = e100_change_mtu;
  2198. netdev->do_ioctl = e100_do_ioctl;
  2199. SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
  2200. netdev->tx_timeout = e100_tx_timeout;
  2201. netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
  2202. netdev->poll = e100_poll;
  2203. netdev->weight = E100_NAPI_WEIGHT;
  2204. #ifdef CONFIG_NET_POLL_CONTROLLER
  2205. netdev->poll_controller = e100_netpoll;
  2206. #endif
  2207. strcpy(netdev->name, pci_name(pdev));
  2208. nic = netdev_priv(netdev);
  2209. nic->netdev = netdev;
  2210. nic->pdev = pdev;
  2211. nic->msg_enable = (1 << debug) - 1;
  2212. pci_set_drvdata(pdev, netdev);
  2213. if((err = pci_enable_device(pdev))) {
  2214. DPRINTK(PROBE, ERR, "Cannot enable PCI device, aborting.\n");
  2215. goto err_out_free_dev;
  2216. }
  2217. if(!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  2218. DPRINTK(PROBE, ERR, "Cannot find proper PCI device "
  2219. "base address, aborting.\n");
  2220. err = -ENODEV;
  2221. goto err_out_disable_pdev;
  2222. }
  2223. if((err = pci_request_regions(pdev, DRV_NAME))) {
  2224. DPRINTK(PROBE, ERR, "Cannot obtain PCI resources, aborting.\n");
  2225. goto err_out_disable_pdev;
  2226. }
  2227. if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
  2228. DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n");
  2229. goto err_out_free_res;
  2230. }
  2231. SET_MODULE_OWNER(netdev);
  2232. SET_NETDEV_DEV(netdev, &pdev->dev);
  2233. nic->csr = ioremap(pci_resource_start(pdev, 0), sizeof(struct csr));
  2234. if(!nic->csr) {
  2235. DPRINTK(PROBE, ERR, "Cannot map device registers, aborting.\n");
  2236. err = -ENOMEM;
  2237. goto err_out_free_res;
  2238. }
  2239. if(ent->driver_data)
  2240. nic->flags |= ich;
  2241. else
  2242. nic->flags &= ~ich;
  2243. e100_get_defaults(nic);
  2244. /* locks must be initialized before calling hw_reset */
  2245. spin_lock_init(&nic->cb_lock);
  2246. spin_lock_init(&nic->cmd_lock);
  2247. spin_lock_init(&nic->mdio_lock);
  2248. /* Reset the device before pci_set_master() in case device is in some
  2249. * funky state and has an interrupt pending - hint: we don't have the
  2250. * interrupt handler registered yet. */
  2251. e100_hw_reset(nic);
  2252. pci_set_master(pdev);
  2253. init_timer(&nic->watchdog);
  2254. nic->watchdog.function = e100_watchdog;
  2255. nic->watchdog.data = (unsigned long)nic;
  2256. init_timer(&nic->blink_timer);
  2257. nic->blink_timer.function = e100_blink_led;
  2258. nic->blink_timer.data = (unsigned long)nic;
  2259. INIT_WORK(&nic->tx_timeout_task,
  2260. (void (*)(void *))e100_tx_timeout_task, netdev);
  2261. if((err = e100_alloc(nic))) {
  2262. DPRINTK(PROBE, ERR, "Cannot alloc driver memory, aborting.\n");
  2263. goto err_out_iounmap;
  2264. }
  2265. if((err = e100_eeprom_load(nic)))
  2266. goto err_out_free;
  2267. e100_phy_init(nic);
  2268. memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
  2269. memcpy(netdev->perm_addr, nic->eeprom, ETH_ALEN);
  2270. if(!is_valid_ether_addr(netdev->perm_addr)) {
  2271. DPRINTK(PROBE, ERR, "Invalid MAC address from "
  2272. "EEPROM, aborting.\n");
  2273. err = -EAGAIN;
  2274. goto err_out_free;
  2275. }
  2276. /* Wol magic packet can be enabled from eeprom */
  2277. if((nic->mac >= mac_82558_D101_A4) &&
  2278. (nic->eeprom[eeprom_id] & eeprom_id_wol))
  2279. nic->flags |= wol_magic;
  2280. /* ack any pending wake events, disable PME */
  2281. err = pci_enable_wake(pdev, 0, 0);
  2282. if (err)
  2283. DPRINTK(PROBE, ERR, "Error clearing wake event\n");
  2284. strcpy(netdev->name, "eth%d");
  2285. if((err = register_netdev(netdev))) {
  2286. DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n");
  2287. goto err_out_free;
  2288. }
  2289. DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, "
  2290. "MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
  2291. (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
  2292. netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
  2293. netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
  2294. return 0;
  2295. err_out_free:
  2296. e100_free(nic);
  2297. err_out_iounmap:
  2298. iounmap(nic->csr);
  2299. err_out_free_res:
  2300. pci_release_regions(pdev);
  2301. err_out_disable_pdev:
  2302. pci_disable_device(pdev);
  2303. err_out_free_dev:
  2304. pci_set_drvdata(pdev, NULL);
  2305. free_netdev(netdev);
  2306. return err;
  2307. }
  2308. static void __devexit e100_remove(struct pci_dev *pdev)
  2309. {
  2310. struct net_device *netdev = pci_get_drvdata(pdev);
  2311. if(netdev) {
  2312. struct nic *nic = netdev_priv(netdev);
  2313. unregister_netdev(netdev);
  2314. e100_free(nic);
  2315. iounmap(nic->csr);
  2316. free_netdev(netdev);
  2317. pci_release_regions(pdev);
  2318. pci_disable_device(pdev);
  2319. pci_set_drvdata(pdev, NULL);
  2320. }
  2321. }
  2322. #ifdef CONFIG_PM
  2323. static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
  2324. {
  2325. struct net_device *netdev = pci_get_drvdata(pdev);
  2326. struct nic *nic = netdev_priv(netdev);
  2327. int retval;
  2328. if(netif_running(netdev))
  2329. e100_down(nic);
  2330. e100_hw_reset(nic);
  2331. netif_device_detach(netdev);
  2332. pci_save_state(pdev);
  2333. retval = pci_enable_wake(pdev, pci_choose_state(pdev, state),
  2334. nic->flags & (wol_magic | e100_asf(nic)));
  2335. if (retval)
  2336. DPRINTK(PROBE,ERR, "Error enabling wake\n");
  2337. pci_disable_device(pdev);
  2338. retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
  2339. if (retval)
  2340. DPRINTK(PROBE,ERR, "Error %d setting power state\n", retval);
  2341. return 0;
  2342. }
  2343. static int e100_resume(struct pci_dev *pdev)
  2344. {
  2345. struct net_device *netdev = pci_get_drvdata(pdev);
  2346. struct nic *nic = netdev_priv(netdev);
  2347. int retval;
  2348. retval = pci_set_power_state(pdev, PCI_D0);
  2349. if (retval)
  2350. DPRINTK(PROBE,ERR, "Error waking adapter\n");
  2351. pci_restore_state(pdev);
  2352. /* ack any pending wake events, disable PME */
  2353. retval = pci_enable_wake(pdev, 0, 0);
  2354. if (retval)
  2355. DPRINTK(PROBE,ERR, "Error clearing wake events\n");
  2356. netif_device_attach(netdev);
  2357. if(netif_running(netdev))
  2358. e100_up(nic);
  2359. return 0;
  2360. }
  2361. #endif
  2362. static void e100_shutdown(struct pci_dev *pdev)
  2363. {
  2364. struct net_device *netdev = pci_get_drvdata(pdev);
  2365. struct nic *nic = netdev_priv(netdev);
  2366. int retval;
  2367. #ifdef CONFIG_PM
  2368. retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic | e100_asf(nic)));
  2369. #else
  2370. retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic));
  2371. #endif
  2372. if (retval)
  2373. DPRINTK(PROBE,ERR, "Error enabling wake\n");
  2374. }
  2375. /* ------------------ PCI Error Recovery infrastructure -------------- */
  2376. /**
  2377. * e100_io_error_detected - called when PCI error is detected.
  2378. * @pdev: Pointer to PCI device
  2379. * @state: The current pci conneection state
  2380. */
  2381. static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2382. {
  2383. struct net_device *netdev = pci_get_drvdata(pdev);
  2384. /* Similar to calling e100_down(), but avoids adpater I/O. */
  2385. netdev->stop(netdev);
  2386. /* Detach; put netif into state similar to hotplug unplug. */
  2387. netif_poll_enable(netdev);
  2388. netif_device_detach(netdev);
  2389. pci_disable_device(pdev);
  2390. /* Request a slot reset. */
  2391. return PCI_ERS_RESULT_NEED_RESET;
  2392. }
  2393. /**
  2394. * e100_io_slot_reset - called after the pci bus has been reset.
  2395. * @pdev: Pointer to PCI device
  2396. *
  2397. * Restart the card from scratch.
  2398. */
  2399. static pci_ers_result_t e100_io_slot_reset(struct pci_dev *pdev)
  2400. {
  2401. struct net_device *netdev = pci_get_drvdata(pdev);
  2402. struct nic *nic = netdev_priv(netdev);
  2403. if (pci_enable_device(pdev)) {
  2404. printk(KERN_ERR "e100: Cannot re-enable PCI device after reset.\n");
  2405. return PCI_ERS_RESULT_DISCONNECT;
  2406. }
  2407. pci_set_master(pdev);
  2408. /* Only one device per card can do a reset */
  2409. if (0 != PCI_FUNC(pdev->devfn))
  2410. return PCI_ERS_RESULT_RECOVERED;
  2411. e100_hw_reset(nic);
  2412. e100_phy_init(nic);
  2413. return PCI_ERS_RESULT_RECOVERED;
  2414. }
  2415. /**
  2416. * e100_io_resume - resume normal operations
  2417. * @pdev: Pointer to PCI device
  2418. *
  2419. * Resume normal operations after an error recovery
  2420. * sequence has been completed.
  2421. */
  2422. static void e100_io_resume(struct pci_dev *pdev)
  2423. {
  2424. struct net_device *netdev = pci_get_drvdata(pdev);
  2425. struct nic *nic = netdev_priv(netdev);
  2426. /* ack any pending wake events, disable PME */
  2427. pci_enable_wake(pdev, 0, 0);
  2428. netif_device_attach(netdev);
  2429. if (netif_running(netdev)) {
  2430. e100_open(netdev);
  2431. mod_timer(&nic->watchdog, jiffies);
  2432. }
  2433. }
  2434. static struct pci_error_handlers e100_err_handler = {
  2435. .error_detected = e100_io_error_detected,
  2436. .slot_reset = e100_io_slot_reset,
  2437. .resume = e100_io_resume,
  2438. };
  2439. static struct pci_driver e100_driver = {
  2440. .name = DRV_NAME,
  2441. .id_table = e100_id_table,
  2442. .probe = e100_probe,
  2443. .remove = __devexit_p(e100_remove),
  2444. #ifdef CONFIG_PM
  2445. .suspend = e100_suspend,
  2446. .resume = e100_resume,
  2447. #endif
  2448. .shutdown = e100_shutdown,
  2449. .err_handler = &e100_err_handler,
  2450. };
  2451. static int __init e100_init_module(void)
  2452. {
  2453. if(((1 << debug) - 1) & NETIF_MSG_DRV) {
  2454. printk(KERN_INFO PFX "%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
  2455. printk(KERN_INFO PFX "%s\n", DRV_COPYRIGHT);
  2456. }
  2457. return pci_register_driver(&e100_driver);
  2458. }
  2459. static void __exit e100_cleanup_module(void)
  2460. {
  2461. pci_unregister_driver(&e100_driver);
  2462. }
  2463. module_init(e100_init_module);
  2464. module_exit(e100_cleanup_module);