e100.c 76 KB

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