e100.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734
  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-k4"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. /*************************************************************************
  1036. * CPUSaver parameters
  1037. *
  1038. * All CPUSaver parameters are 16-bit literals that are part of a
  1039. * "move immediate value" instruction. By changing the value of
  1040. * the literal in the instruction before the code is loaded, the
  1041. * driver can change the algorithm.
  1042. *
  1043. * INTDELAY - This loads the dead-man timer with its inital value.
  1044. * When this timer expires the interrupt is asserted, and the
  1045. * timer is reset each time a new packet is received. (see
  1046. * BUNDLEMAX below to set the limit on number of chained packets)
  1047. * The current default is 0x600 or 1536. Experiments show that
  1048. * the value should probably stay within the 0x200 - 0x1000.
  1049. *
  1050. * BUNDLEMAX -
  1051. * This sets the maximum number of frames that will be bundled. In
  1052. * some situations, such as the TCP windowing algorithm, it may be
  1053. * better to limit the growth of the bundle size than let it go as
  1054. * high as it can, because that could cause too much added latency.
  1055. * The default is six, because this is the number of packets in the
  1056. * default TCP window size. A value of 1 would make CPUSaver indicate
  1057. * an interrupt for every frame received. If you do not want to put
  1058. * a limit on the bundle size, set this value to xFFFF.
  1059. *
  1060. * BUNDLESMALL -
  1061. * This contains a bit-mask describing the minimum size frame that
  1062. * will be bundled. The default masks the lower 7 bits, which means
  1063. * that any frame less than 128 bytes in length will not be bundled,
  1064. * but will instead immediately generate an interrupt. This does
  1065. * not affect the current bundle in any way. Any frame that is 128
  1066. * bytes or large will be bundled normally. This feature is meant
  1067. * to provide immediate indication of ACK frames in a TCP environment.
  1068. * Customers were seeing poor performance when a machine with CPUSaver
  1069. * enabled was sending but not receiving. The delay introduced when
  1070. * the ACKs were received was enough to reduce total throughput, because
  1071. * the sender would sit idle until the ACK was finally seen.
  1072. *
  1073. * The current default is 0xFF80, which masks out the lower 7 bits.
  1074. * This means that any frame which is x7F (127) bytes or smaller
  1075. * will cause an immediate interrupt. Because this value must be a
  1076. * bit mask, there are only a few valid values that can be used. To
  1077. * turn this feature off, the driver can write the value xFFFF to the
  1078. * lower word of this instruction (in the same way that the other
  1079. * parameters are used). Likewise, a value of 0xF800 (2047) would
  1080. * cause an interrupt to be generated for every frame, because all
  1081. * standard Ethernet frames are <= 2047 bytes in length.
  1082. *************************************************************************/
  1083. /* if you wish to disable the ucode functionality, while maintaining the
  1084. * workarounds it provides, set the following defines to:
  1085. * BUNDLESMALL 0
  1086. * BUNDLEMAX 1
  1087. * INTDELAY 1
  1088. */
  1089. #define BUNDLESMALL 1
  1090. #define BUNDLEMAX (u16)6
  1091. #define INTDELAY (u16)1536 /* 0x600 */
  1092. /* do not load u-code for ICH devices */
  1093. if (nic->flags & ich)
  1094. goto noloaducode;
  1095. /* Search for ucode match against h/w rev_id */
  1096. for (opts = ucode_opts; opts->mac; opts++) {
  1097. int i;
  1098. u32 *ucode = opts->ucode;
  1099. if (nic->mac != opts->mac)
  1100. continue;
  1101. /* Insert user-tunable settings */
  1102. ucode[opts->timer_dword] &= 0xFFFF0000;
  1103. ucode[opts->timer_dword] |= INTDELAY;
  1104. ucode[opts->bundle_dword] &= 0xFFFF0000;
  1105. ucode[opts->bundle_dword] |= BUNDLEMAX;
  1106. ucode[opts->min_size_dword] &= 0xFFFF0000;
  1107. ucode[opts->min_size_dword] |= (BUNDLESMALL) ? 0xFFFF : 0xFF80;
  1108. for (i = 0; i < UCODE_SIZE; i++)
  1109. cb->u.ucode[i] = cpu_to_le32(ucode[i]);
  1110. cb->command = cpu_to_le16(cb_ucode);
  1111. return;
  1112. }
  1113. noloaducode:
  1114. cb->command = cpu_to_le16(cb_nop);
  1115. }
  1116. static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
  1117. struct sk_buff *skb)
  1118. {
  1119. cb->command = cpu_to_le16(cb_iaaddr);
  1120. memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
  1121. }
  1122. static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  1123. {
  1124. cb->command = cpu_to_le16(cb_dump);
  1125. cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
  1126. offsetof(struct mem, dump_buf));
  1127. }
  1128. #define NCONFIG_AUTO_SWITCH 0x0080
  1129. #define MII_NSC_CONG MII_RESV1
  1130. #define NSC_CONG_ENABLE 0x0100
  1131. #define NSC_CONG_TXREADY 0x0400
  1132. #define ADVERTISE_FC_SUPPORTED 0x0400
  1133. static int e100_phy_init(struct nic *nic)
  1134. {
  1135. struct net_device *netdev = nic->netdev;
  1136. u32 addr;
  1137. u16 bmcr, stat, id_lo, id_hi, cong;
  1138. /* Discover phy addr by searching addrs in order {1,0,2,..., 31} */
  1139. for(addr = 0; addr < 32; addr++) {
  1140. nic->mii.phy_id = (addr == 0) ? 1 : (addr == 1) ? 0 : addr;
  1141. bmcr = mdio_read(netdev, nic->mii.phy_id, MII_BMCR);
  1142. stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR);
  1143. stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR);
  1144. if(!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
  1145. break;
  1146. }
  1147. DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
  1148. if(addr == 32)
  1149. return -EAGAIN;
  1150. /* Selected the phy and isolate the rest */
  1151. for(addr = 0; addr < 32; addr++) {
  1152. if(addr != nic->mii.phy_id) {
  1153. mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
  1154. } else {
  1155. bmcr = mdio_read(netdev, addr, MII_BMCR);
  1156. mdio_write(netdev, addr, MII_BMCR,
  1157. bmcr & ~BMCR_ISOLATE);
  1158. }
  1159. }
  1160. /* Get phy ID */
  1161. id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1);
  1162. id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2);
  1163. nic->phy = (u32)id_hi << 16 | (u32)id_lo;
  1164. DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy);
  1165. /* Handle National tx phys */
  1166. #define NCS_PHY_MODEL_MASK 0xFFF0FFFF
  1167. if((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) {
  1168. /* Disable congestion control */
  1169. cong = mdio_read(netdev, nic->mii.phy_id, MII_NSC_CONG);
  1170. cong |= NSC_CONG_TXREADY;
  1171. cong &= ~NSC_CONG_ENABLE;
  1172. mdio_write(netdev, nic->mii.phy_id, MII_NSC_CONG, cong);
  1173. }
  1174. if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) &&
  1175. (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000))) {
  1176. /* enable/disable MDI/MDI-X auto-switching.
  1177. MDI/MDI-X auto-switching is disabled for 82551ER/QM chips */
  1178. if((nic->mac == mac_82551_E) || (nic->mac == mac_82551_F) ||
  1179. (nic->mac == mac_82551_10) || (nic->mii.force_media) ||
  1180. !(nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))
  1181. mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 0);
  1182. else
  1183. mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, NCONFIG_AUTO_SWITCH);
  1184. }
  1185. return 0;
  1186. }
  1187. static int e100_hw_init(struct nic *nic)
  1188. {
  1189. int err;
  1190. e100_hw_reset(nic);
  1191. DPRINTK(HW, ERR, "e100_hw_init\n");
  1192. if(!in_interrupt() && (err = e100_self_test(nic)))
  1193. return err;
  1194. if((err = e100_phy_init(nic)))
  1195. return err;
  1196. if((err = e100_exec_cmd(nic, cuc_load_base, 0)))
  1197. return err;
  1198. if((err = e100_exec_cmd(nic, ruc_load_base, 0)))
  1199. return err;
  1200. if((err = e100_exec_cb(nic, NULL, e100_load_ucode)))
  1201. return err;
  1202. if((err = e100_exec_cb(nic, NULL, e100_configure)))
  1203. return err;
  1204. if((err = e100_exec_cb(nic, NULL, e100_setup_iaaddr)))
  1205. return err;
  1206. if((err = e100_exec_cmd(nic, cuc_dump_addr,
  1207. nic->dma_addr + offsetof(struct mem, stats))))
  1208. return err;
  1209. if((err = e100_exec_cmd(nic, cuc_dump_reset, 0)))
  1210. return err;
  1211. e100_disable_irq(nic);
  1212. return 0;
  1213. }
  1214. static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
  1215. {
  1216. struct net_device *netdev = nic->netdev;
  1217. struct dev_mc_list *list = netdev->mc_list;
  1218. u16 i, count = min(netdev->mc_count, E100_MAX_MULTICAST_ADDRS);
  1219. cb->command = cpu_to_le16(cb_multi);
  1220. cb->u.multi.count = cpu_to_le16(count * ETH_ALEN);
  1221. for(i = 0; list && i < count; i++, list = list->next)
  1222. memcpy(&cb->u.multi.addr[i*ETH_ALEN], &list->dmi_addr,
  1223. ETH_ALEN);
  1224. }
  1225. static void e100_set_multicast_list(struct net_device *netdev)
  1226. {
  1227. struct nic *nic = netdev_priv(netdev);
  1228. DPRINTK(HW, DEBUG, "mc_count=%d, flags=0x%04X\n",
  1229. netdev->mc_count, netdev->flags);
  1230. if(netdev->flags & IFF_PROMISC)
  1231. nic->flags |= promiscuous;
  1232. else
  1233. nic->flags &= ~promiscuous;
  1234. if(netdev->flags & IFF_ALLMULTI ||
  1235. netdev->mc_count > E100_MAX_MULTICAST_ADDRS)
  1236. nic->flags |= multicast_all;
  1237. else
  1238. nic->flags &= ~multicast_all;
  1239. e100_exec_cb(nic, NULL, e100_configure);
  1240. e100_exec_cb(nic, NULL, e100_multi);
  1241. }
  1242. static void e100_update_stats(struct nic *nic)
  1243. {
  1244. struct net_device_stats *ns = &nic->net_stats;
  1245. struct stats *s = &nic->mem->stats;
  1246. u32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause :
  1247. (nic->mac < mac_82559_D101M) ? (u32 *)&s->xmt_tco_frames :
  1248. &s->complete;
  1249. /* Device's stats reporting may take several microseconds to
  1250. * complete, so where always waiting for results of the
  1251. * previous command. */
  1252. if(*complete == le32_to_cpu(cuc_dump_reset_complete)) {
  1253. *complete = 0;
  1254. nic->tx_frames = le32_to_cpu(s->tx_good_frames);
  1255. nic->tx_collisions = le32_to_cpu(s->tx_total_collisions);
  1256. ns->tx_aborted_errors += le32_to_cpu(s->tx_max_collisions);
  1257. ns->tx_window_errors += le32_to_cpu(s->tx_late_collisions);
  1258. ns->tx_carrier_errors += le32_to_cpu(s->tx_lost_crs);
  1259. ns->tx_fifo_errors += le32_to_cpu(s->tx_underruns);
  1260. ns->collisions += nic->tx_collisions;
  1261. ns->tx_errors += le32_to_cpu(s->tx_max_collisions) +
  1262. le32_to_cpu(s->tx_lost_crs);
  1263. ns->rx_length_errors += le32_to_cpu(s->rx_short_frame_errors) +
  1264. nic->rx_over_length_errors;
  1265. ns->rx_crc_errors += le32_to_cpu(s->rx_crc_errors);
  1266. ns->rx_frame_errors += le32_to_cpu(s->rx_alignment_errors);
  1267. ns->rx_over_errors += le32_to_cpu(s->rx_overrun_errors);
  1268. ns->rx_fifo_errors += le32_to_cpu(s->rx_overrun_errors);
  1269. ns->rx_missed_errors += le32_to_cpu(s->rx_resource_errors);
  1270. ns->rx_errors += le32_to_cpu(s->rx_crc_errors) +
  1271. le32_to_cpu(s->rx_alignment_errors) +
  1272. le32_to_cpu(s->rx_short_frame_errors) +
  1273. le32_to_cpu(s->rx_cdt_errors);
  1274. nic->tx_deferred += le32_to_cpu(s->tx_deferred);
  1275. nic->tx_single_collisions +=
  1276. le32_to_cpu(s->tx_single_collisions);
  1277. nic->tx_multiple_collisions +=
  1278. le32_to_cpu(s->tx_multiple_collisions);
  1279. if(nic->mac >= mac_82558_D101_A4) {
  1280. nic->tx_fc_pause += le32_to_cpu(s->fc_xmt_pause);
  1281. nic->rx_fc_pause += le32_to_cpu(s->fc_rcv_pause);
  1282. nic->rx_fc_unsupported +=
  1283. le32_to_cpu(s->fc_rcv_unsupported);
  1284. if(nic->mac >= mac_82559_D101M) {
  1285. nic->tx_tco_frames +=
  1286. le16_to_cpu(s->xmt_tco_frames);
  1287. nic->rx_tco_frames +=
  1288. le16_to_cpu(s->rcv_tco_frames);
  1289. }
  1290. }
  1291. }
  1292. if(e100_exec_cmd(nic, cuc_dump_reset, 0))
  1293. DPRINTK(TX_ERR, DEBUG, "exec cuc_dump_reset failed\n");
  1294. }
  1295. static void e100_adjust_adaptive_ifs(struct nic *nic, int speed, int duplex)
  1296. {
  1297. /* Adjust inter-frame-spacing (IFS) between two transmits if
  1298. * we're getting collisions on a half-duplex connection. */
  1299. if(duplex == DUPLEX_HALF) {
  1300. u32 prev = nic->adaptive_ifs;
  1301. u32 min_frames = (speed == SPEED_100) ? 1000 : 100;
  1302. if((nic->tx_frames / 32 < nic->tx_collisions) &&
  1303. (nic->tx_frames > min_frames)) {
  1304. if(nic->adaptive_ifs < 60)
  1305. nic->adaptive_ifs += 5;
  1306. } else if (nic->tx_frames < min_frames) {
  1307. if(nic->adaptive_ifs >= 5)
  1308. nic->adaptive_ifs -= 5;
  1309. }
  1310. if(nic->adaptive_ifs != prev)
  1311. e100_exec_cb(nic, NULL, e100_configure);
  1312. }
  1313. }
  1314. static void e100_watchdog(unsigned long data)
  1315. {
  1316. struct nic *nic = (struct nic *)data;
  1317. struct ethtool_cmd cmd;
  1318. DPRINTK(TIMER, DEBUG, "right now = %ld\n", jiffies);
  1319. /* mii library handles link maintenance tasks */
  1320. mii_ethtool_gset(&nic->mii, &cmd);
  1321. if(mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) {
  1322. DPRINTK(LINK, INFO, "link up, %sMbps, %s-duplex\n",
  1323. cmd.speed == SPEED_100 ? "100" : "10",
  1324. cmd.duplex == DUPLEX_FULL ? "full" : "half");
  1325. } else if(!mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) {
  1326. DPRINTK(LINK, INFO, "link down\n");
  1327. }
  1328. mii_check_link(&nic->mii);
  1329. /* Software generated interrupt to recover from (rare) Rx
  1330. * allocation failure.
  1331. * Unfortunately have to use a spinlock to not re-enable interrupts
  1332. * accidentally, due to hardware that shares a register between the
  1333. * interrupt mask bit and the SW Interrupt generation bit */
  1334. spin_lock_irq(&nic->cmd_lock);
  1335. writeb(readb(&nic->csr->scb.cmd_hi) | irq_sw_gen,&nic->csr->scb.cmd_hi);
  1336. spin_unlock_irq(&nic->cmd_lock);
  1337. e100_write_flush(nic);
  1338. e100_update_stats(nic);
  1339. e100_adjust_adaptive_ifs(nic, cmd.speed, cmd.duplex);
  1340. if(nic->mac <= mac_82557_D100_C)
  1341. /* Issue a multicast command to workaround a 557 lock up */
  1342. e100_set_multicast_list(nic->netdev);
  1343. if(nic->flags & ich && cmd.speed==SPEED_10 && cmd.duplex==DUPLEX_HALF)
  1344. /* Need SW workaround for ICH[x] 10Mbps/half duplex Tx hang. */
  1345. nic->flags |= ich_10h_workaround;
  1346. else
  1347. nic->flags &= ~ich_10h_workaround;
  1348. mod_timer(&nic->watchdog, jiffies + E100_WATCHDOG_PERIOD);
  1349. }
  1350. static inline void e100_xmit_prepare(struct nic *nic, struct cb *cb,
  1351. struct sk_buff *skb)
  1352. {
  1353. cb->command = nic->tx_command;
  1354. /* interrupt every 16 packets regardless of delay */
  1355. if((nic->cbs_avail & ~15) == nic->cbs_avail)
  1356. cb->command |= cpu_to_le16(cb_i);
  1357. cb->u.tcb.tbd_array = cb->dma_addr + offsetof(struct cb, u.tcb.tbd);
  1358. cb->u.tcb.tcb_byte_count = 0;
  1359. cb->u.tcb.threshold = nic->tx_threshold;
  1360. cb->u.tcb.tbd_count = 1;
  1361. cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
  1362. skb->data, skb->len, PCI_DMA_TODEVICE));
  1363. /* check for mapping failure? */
  1364. cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
  1365. }
  1366. static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  1367. {
  1368. struct nic *nic = netdev_priv(netdev);
  1369. int err;
  1370. if(nic->flags & ich_10h_workaround) {
  1371. /* SW workaround for ICH[x] 10Mbps/half duplex Tx hang.
  1372. Issue a NOP command followed by a 1us delay before
  1373. issuing the Tx command. */
  1374. if(e100_exec_cmd(nic, cuc_nop, 0))
  1375. DPRINTK(TX_ERR, DEBUG, "exec cuc_nop failed\n");
  1376. udelay(1);
  1377. }
  1378. err = e100_exec_cb(nic, skb, e100_xmit_prepare);
  1379. switch(err) {
  1380. case -ENOSPC:
  1381. /* We queued the skb, but now we're out of space. */
  1382. DPRINTK(TX_ERR, DEBUG, "No space for CB\n");
  1383. netif_stop_queue(netdev);
  1384. break;
  1385. case -ENOMEM:
  1386. /* This is a hard error - log it. */
  1387. DPRINTK(TX_ERR, DEBUG, "Out of Tx resources, returning skb\n");
  1388. netif_stop_queue(netdev);
  1389. return 1;
  1390. }
  1391. netdev->trans_start = jiffies;
  1392. return 0;
  1393. }
  1394. static inline int e100_tx_clean(struct nic *nic)
  1395. {
  1396. struct cb *cb;
  1397. int tx_cleaned = 0;
  1398. spin_lock(&nic->cb_lock);
  1399. DPRINTK(TX_DONE, DEBUG, "cb->status = 0x%04X\n",
  1400. nic->cb_to_clean->status);
  1401. /* Clean CBs marked complete */
  1402. for(cb = nic->cb_to_clean;
  1403. cb->status & cpu_to_le16(cb_complete);
  1404. cb = nic->cb_to_clean = cb->next) {
  1405. if(likely(cb->skb != NULL)) {
  1406. nic->net_stats.tx_packets++;
  1407. nic->net_stats.tx_bytes += cb->skb->len;
  1408. pci_unmap_single(nic->pdev,
  1409. le32_to_cpu(cb->u.tcb.tbd.buf_addr),
  1410. le16_to_cpu(cb->u.tcb.tbd.size),
  1411. PCI_DMA_TODEVICE);
  1412. dev_kfree_skb_any(cb->skb);
  1413. cb->skb = NULL;
  1414. tx_cleaned = 1;
  1415. }
  1416. cb->status = 0;
  1417. nic->cbs_avail++;
  1418. }
  1419. spin_unlock(&nic->cb_lock);
  1420. /* Recover from running out of Tx resources in xmit_frame */
  1421. if(unlikely(tx_cleaned && netif_queue_stopped(nic->netdev)))
  1422. netif_wake_queue(nic->netdev);
  1423. return tx_cleaned;
  1424. }
  1425. static void e100_clean_cbs(struct nic *nic)
  1426. {
  1427. if(nic->cbs) {
  1428. while(nic->cbs_avail != nic->params.cbs.count) {
  1429. struct cb *cb = nic->cb_to_clean;
  1430. if(cb->skb) {
  1431. pci_unmap_single(nic->pdev,
  1432. le32_to_cpu(cb->u.tcb.tbd.buf_addr),
  1433. le16_to_cpu(cb->u.tcb.tbd.size),
  1434. PCI_DMA_TODEVICE);
  1435. dev_kfree_skb(cb->skb);
  1436. }
  1437. nic->cb_to_clean = nic->cb_to_clean->next;
  1438. nic->cbs_avail++;
  1439. }
  1440. pci_free_consistent(nic->pdev,
  1441. sizeof(struct cb) * nic->params.cbs.count,
  1442. nic->cbs, nic->cbs_dma_addr);
  1443. nic->cbs = NULL;
  1444. nic->cbs_avail = 0;
  1445. }
  1446. nic->cuc_cmd = cuc_start;
  1447. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean =
  1448. nic->cbs;
  1449. }
  1450. static int e100_alloc_cbs(struct nic *nic)
  1451. {
  1452. struct cb *cb;
  1453. unsigned int i, count = nic->params.cbs.count;
  1454. nic->cuc_cmd = cuc_start;
  1455. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL;
  1456. nic->cbs_avail = 0;
  1457. nic->cbs = pci_alloc_consistent(nic->pdev,
  1458. sizeof(struct cb) * count, &nic->cbs_dma_addr);
  1459. if(!nic->cbs)
  1460. return -ENOMEM;
  1461. for(cb = nic->cbs, i = 0; i < count; cb++, i++) {
  1462. cb->next = (i + 1 < count) ? cb + 1 : nic->cbs;
  1463. cb->prev = (i == 0) ? nic->cbs + count - 1 : cb - 1;
  1464. cb->dma_addr = nic->cbs_dma_addr + i * sizeof(struct cb);
  1465. cb->link = cpu_to_le32(nic->cbs_dma_addr +
  1466. ((i+1) % count) * sizeof(struct cb));
  1467. cb->skb = NULL;
  1468. }
  1469. nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs;
  1470. nic->cbs_avail = count;
  1471. return 0;
  1472. }
  1473. static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
  1474. {
  1475. if(!nic->rxs) return;
  1476. if(RU_SUSPENDED != nic->ru_running) return;
  1477. /* handle init time starts */
  1478. if(!rx) rx = nic->rxs;
  1479. /* (Re)start RU if suspended or idle and RFA is non-NULL */
  1480. if(rx->skb) {
  1481. e100_exec_cmd(nic, ruc_start, rx->dma_addr);
  1482. nic->ru_running = RU_RUNNING;
  1483. }
  1484. }
  1485. #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
  1486. static inline int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
  1487. {
  1488. if(!(rx->skb = dev_alloc_skb(RFD_BUF_LEN + NET_IP_ALIGN)))
  1489. return -ENOMEM;
  1490. /* Align, init, and map the RFD. */
  1491. rx->skb->dev = nic->netdev;
  1492. skb_reserve(rx->skb, NET_IP_ALIGN);
  1493. memcpy(rx->skb->data, &nic->blank_rfd, sizeof(struct rfd));
  1494. rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
  1495. RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
  1496. if(pci_dma_mapping_error(rx->dma_addr)) {
  1497. dev_kfree_skb_any(rx->skb);
  1498. rx->skb = NULL;
  1499. rx->dma_addr = 0;
  1500. return -ENOMEM;
  1501. }
  1502. /* Link the RFD to end of RFA by linking previous RFD to
  1503. * this one, and clearing EL bit of previous. */
  1504. if(rx->prev->skb) {
  1505. struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data;
  1506. put_unaligned(cpu_to_le32(rx->dma_addr),
  1507. (u32 *)&prev_rfd->link);
  1508. wmb();
  1509. prev_rfd->command &= ~cpu_to_le16(cb_el);
  1510. pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
  1511. sizeof(struct rfd), PCI_DMA_TODEVICE);
  1512. }
  1513. return 0;
  1514. }
  1515. static inline int e100_rx_indicate(struct nic *nic, struct rx *rx,
  1516. unsigned int *work_done, unsigned int work_to_do)
  1517. {
  1518. struct sk_buff *skb = rx->skb;
  1519. struct rfd *rfd = (struct rfd *)skb->data;
  1520. u16 rfd_status, actual_size;
  1521. if(unlikely(work_done && *work_done >= work_to_do))
  1522. return -EAGAIN;
  1523. /* Need to sync before taking a peek at cb_complete bit */
  1524. pci_dma_sync_single_for_cpu(nic->pdev, rx->dma_addr,
  1525. sizeof(struct rfd), PCI_DMA_FROMDEVICE);
  1526. rfd_status = le16_to_cpu(rfd->status);
  1527. DPRINTK(RX_STATUS, DEBUG, "status=0x%04X\n", rfd_status);
  1528. /* If data isn't ready, nothing to indicate */
  1529. if(unlikely(!(rfd_status & cb_complete)))
  1530. return -ENODATA;
  1531. /* Get actual data size */
  1532. actual_size = le16_to_cpu(rfd->actual_size) & 0x3FFF;
  1533. if(unlikely(actual_size > RFD_BUF_LEN - sizeof(struct rfd)))
  1534. actual_size = RFD_BUF_LEN - sizeof(struct rfd);
  1535. /* Get data */
  1536. pci_unmap_single(nic->pdev, rx->dma_addr,
  1537. RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
  1538. /* this allows for a fast restart without re-enabling interrupts */
  1539. if(le16_to_cpu(rfd->command) & cb_el)
  1540. nic->ru_running = RU_SUSPENDED;
  1541. /* Pull off the RFD and put the actual data (minus eth hdr) */
  1542. skb_reserve(skb, sizeof(struct rfd));
  1543. skb_put(skb, actual_size);
  1544. skb->protocol = eth_type_trans(skb, nic->netdev);
  1545. if(unlikely(!(rfd_status & cb_ok))) {
  1546. /* Don't indicate if hardware indicates errors */
  1547. dev_kfree_skb_any(skb);
  1548. } else if(actual_size > ETH_DATA_LEN + VLAN_ETH_HLEN) {
  1549. /* Don't indicate oversized frames */
  1550. nic->rx_over_length_errors++;
  1551. dev_kfree_skb_any(skb);
  1552. } else {
  1553. nic->net_stats.rx_packets++;
  1554. nic->net_stats.rx_bytes += actual_size;
  1555. nic->netdev->last_rx = jiffies;
  1556. netif_receive_skb(skb);
  1557. if(work_done)
  1558. (*work_done)++;
  1559. }
  1560. rx->skb = NULL;
  1561. return 0;
  1562. }
  1563. static inline void e100_rx_clean(struct nic *nic, unsigned int *work_done,
  1564. unsigned int work_to_do)
  1565. {
  1566. struct rx *rx;
  1567. int restart_required = 0;
  1568. struct rx *rx_to_start = NULL;
  1569. /* are we already rnr? then pay attention!!! this ensures that
  1570. * the state machine progression never allows a start with a
  1571. * partially cleaned list, avoiding a race between hardware
  1572. * and rx_to_clean when in NAPI mode */
  1573. if(RU_SUSPENDED == nic->ru_running)
  1574. restart_required = 1;
  1575. /* Indicate newly arrived packets */
  1576. for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
  1577. int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
  1578. if(-EAGAIN == err) {
  1579. /* hit quota so have more work to do, restart once
  1580. * cleanup is complete */
  1581. restart_required = 0;
  1582. break;
  1583. } else if(-ENODATA == err)
  1584. break; /* No more to clean */
  1585. }
  1586. /* save our starting point as the place we'll restart the receiver */
  1587. if(restart_required)
  1588. rx_to_start = nic->rx_to_clean;
  1589. /* Alloc new skbs to refill list */
  1590. for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
  1591. if(unlikely(e100_rx_alloc_skb(nic, rx)))
  1592. break; /* Better luck next time (see watchdog) */
  1593. }
  1594. if(restart_required) {
  1595. // ack the rnr?
  1596. writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
  1597. e100_start_receiver(nic, rx_to_start);
  1598. if(work_done)
  1599. (*work_done)++;
  1600. }
  1601. }
  1602. static void e100_rx_clean_list(struct nic *nic)
  1603. {
  1604. struct rx *rx;
  1605. unsigned int i, count = nic->params.rfds.count;
  1606. nic->ru_running = RU_UNINITIALIZED;
  1607. if(nic->rxs) {
  1608. for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
  1609. if(rx->skb) {
  1610. pci_unmap_single(nic->pdev, rx->dma_addr,
  1611. RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
  1612. dev_kfree_skb(rx->skb);
  1613. }
  1614. }
  1615. kfree(nic->rxs);
  1616. nic->rxs = NULL;
  1617. }
  1618. nic->rx_to_use = nic->rx_to_clean = NULL;
  1619. }
  1620. static int e100_rx_alloc_list(struct nic *nic)
  1621. {
  1622. struct rx *rx;
  1623. unsigned int i, count = nic->params.rfds.count;
  1624. nic->rx_to_use = nic->rx_to_clean = NULL;
  1625. nic->ru_running = RU_UNINITIALIZED;
  1626. if(!(nic->rxs = kmalloc(sizeof(struct rx) * count, GFP_ATOMIC)))
  1627. return -ENOMEM;
  1628. memset(nic->rxs, 0, sizeof(struct rx) * count);
  1629. for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
  1630. rx->next = (i + 1 < count) ? rx + 1 : nic->rxs;
  1631. rx->prev = (i == 0) ? nic->rxs + count - 1 : rx - 1;
  1632. if(e100_rx_alloc_skb(nic, rx)) {
  1633. e100_rx_clean_list(nic);
  1634. return -ENOMEM;
  1635. }
  1636. }
  1637. nic->rx_to_use = nic->rx_to_clean = nic->rxs;
  1638. nic->ru_running = RU_SUSPENDED;
  1639. return 0;
  1640. }
  1641. static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
  1642. {
  1643. struct net_device *netdev = dev_id;
  1644. struct nic *nic = netdev_priv(netdev);
  1645. u8 stat_ack = readb(&nic->csr->scb.stat_ack);
  1646. DPRINTK(INTR, DEBUG, "stat_ack = 0x%02X\n", stat_ack);
  1647. if(stat_ack == stat_ack_not_ours || /* Not our interrupt */
  1648. stat_ack == stat_ack_not_present) /* Hardware is ejected */
  1649. return IRQ_NONE;
  1650. /* Ack interrupt(s) */
  1651. writeb(stat_ack, &nic->csr->scb.stat_ack);
  1652. /* We hit Receive No Resource (RNR); restart RU after cleaning */
  1653. if(stat_ack & stat_ack_rnr)
  1654. nic->ru_running = RU_SUSPENDED;
  1655. if(likely(netif_rx_schedule_prep(netdev))) {
  1656. e100_disable_irq(nic);
  1657. __netif_rx_schedule(netdev);
  1658. }
  1659. return IRQ_HANDLED;
  1660. }
  1661. static int e100_poll(struct net_device *netdev, int *budget)
  1662. {
  1663. struct nic *nic = netdev_priv(netdev);
  1664. unsigned int work_to_do = min(netdev->quota, *budget);
  1665. unsigned int work_done = 0;
  1666. int tx_cleaned;
  1667. e100_rx_clean(nic, &work_done, work_to_do);
  1668. tx_cleaned = e100_tx_clean(nic);
  1669. /* If no Rx and Tx cleanup work was done, exit polling mode. */
  1670. if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
  1671. netif_rx_complete(netdev);
  1672. e100_enable_irq(nic);
  1673. return 0;
  1674. }
  1675. *budget -= work_done;
  1676. netdev->quota -= work_done;
  1677. return 1;
  1678. }
  1679. #ifdef CONFIG_NET_POLL_CONTROLLER
  1680. static void e100_netpoll(struct net_device *netdev)
  1681. {
  1682. struct nic *nic = netdev_priv(netdev);
  1683. e100_disable_irq(nic);
  1684. e100_intr(nic->pdev->irq, netdev, NULL);
  1685. e100_tx_clean(nic);
  1686. e100_enable_irq(nic);
  1687. }
  1688. #endif
  1689. static struct net_device_stats *e100_get_stats(struct net_device *netdev)
  1690. {
  1691. struct nic *nic = netdev_priv(netdev);
  1692. return &nic->net_stats;
  1693. }
  1694. static int e100_set_mac_address(struct net_device *netdev, void *p)
  1695. {
  1696. struct nic *nic = netdev_priv(netdev);
  1697. struct sockaddr *addr = p;
  1698. if (!is_valid_ether_addr(addr->sa_data))
  1699. return -EADDRNOTAVAIL;
  1700. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1701. e100_exec_cb(nic, NULL, e100_setup_iaaddr);
  1702. return 0;
  1703. }
  1704. static int e100_change_mtu(struct net_device *netdev, int new_mtu)
  1705. {
  1706. if(new_mtu < ETH_ZLEN || new_mtu > ETH_DATA_LEN)
  1707. return -EINVAL;
  1708. netdev->mtu = new_mtu;
  1709. return 0;
  1710. }
  1711. #ifdef CONFIG_PM
  1712. static int e100_asf(struct nic *nic)
  1713. {
  1714. /* ASF can be enabled from eeprom */
  1715. return((nic->pdev->device >= 0x1050) && (nic->pdev->device <= 0x1057) &&
  1716. (nic->eeprom[eeprom_config_asf] & eeprom_asf) &&
  1717. !(nic->eeprom[eeprom_config_asf] & eeprom_gcl) &&
  1718. ((nic->eeprom[eeprom_smbus_addr] & 0xFF) != 0xFE));
  1719. }
  1720. #endif
  1721. static int e100_up(struct nic *nic)
  1722. {
  1723. int err;
  1724. if((err = e100_rx_alloc_list(nic)))
  1725. return err;
  1726. if((err = e100_alloc_cbs(nic)))
  1727. goto err_rx_clean_list;
  1728. if((err = e100_hw_init(nic)))
  1729. goto err_clean_cbs;
  1730. e100_set_multicast_list(nic->netdev);
  1731. e100_start_receiver(nic, NULL);
  1732. mod_timer(&nic->watchdog, jiffies);
  1733. if((err = request_irq(nic->pdev->irq, e100_intr, SA_SHIRQ,
  1734. nic->netdev->name, nic->netdev)))
  1735. goto err_no_irq;
  1736. netif_wake_queue(nic->netdev);
  1737. netif_poll_enable(nic->netdev);
  1738. /* enable ints _after_ enabling poll, preventing a race between
  1739. * disable ints+schedule */
  1740. e100_enable_irq(nic);
  1741. return 0;
  1742. err_no_irq:
  1743. del_timer_sync(&nic->watchdog);
  1744. err_clean_cbs:
  1745. e100_clean_cbs(nic);
  1746. err_rx_clean_list:
  1747. e100_rx_clean_list(nic);
  1748. return err;
  1749. }
  1750. static void e100_down(struct nic *nic)
  1751. {
  1752. /* wait here for poll to complete */
  1753. netif_poll_disable(nic->netdev);
  1754. netif_stop_queue(nic->netdev);
  1755. e100_hw_reset(nic);
  1756. free_irq(nic->pdev->irq, nic->netdev);
  1757. del_timer_sync(&nic->watchdog);
  1758. netif_carrier_off(nic->netdev);
  1759. e100_clean_cbs(nic);
  1760. e100_rx_clean_list(nic);
  1761. }
  1762. static void e100_tx_timeout(struct net_device *netdev)
  1763. {
  1764. struct nic *nic = netdev_priv(netdev);
  1765. /* Reset outside of interrupt context, to avoid request_irq
  1766. * in interrupt context */
  1767. schedule_work(&nic->tx_timeout_task);
  1768. }
  1769. static void e100_tx_timeout_task(struct net_device *netdev)
  1770. {
  1771. struct nic *nic = netdev_priv(netdev);
  1772. DPRINTK(TX_ERR, DEBUG, "scb.status=0x%02X\n",
  1773. readb(&nic->csr->scb.status));
  1774. e100_down(netdev_priv(netdev));
  1775. e100_up(netdev_priv(netdev));
  1776. }
  1777. static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
  1778. {
  1779. int err;
  1780. struct sk_buff *skb;
  1781. /* Use driver resources to perform internal MAC or PHY
  1782. * loopback test. A single packet is prepared and transmitted
  1783. * in loopback mode, and the test passes if the received
  1784. * packet compares byte-for-byte to the transmitted packet. */
  1785. if((err = e100_rx_alloc_list(nic)))
  1786. return err;
  1787. if((err = e100_alloc_cbs(nic)))
  1788. goto err_clean_rx;
  1789. /* ICH PHY loopback is broken so do MAC loopback instead */
  1790. if(nic->flags & ich && loopback_mode == lb_phy)
  1791. loopback_mode = lb_mac;
  1792. nic->loopback = loopback_mode;
  1793. if((err = e100_hw_init(nic)))
  1794. goto err_loopback_none;
  1795. if(loopback_mode == lb_phy)
  1796. mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR,
  1797. BMCR_LOOPBACK);
  1798. e100_start_receiver(nic, NULL);
  1799. if(!(skb = dev_alloc_skb(ETH_DATA_LEN))) {
  1800. err = -ENOMEM;
  1801. goto err_loopback_none;
  1802. }
  1803. skb_put(skb, ETH_DATA_LEN);
  1804. memset(skb->data, 0xFF, ETH_DATA_LEN);
  1805. e100_xmit_frame(skb, nic->netdev);
  1806. msleep(10);
  1807. if(memcmp(nic->rx_to_clean->skb->data + sizeof(struct rfd),
  1808. skb->data, ETH_DATA_LEN))
  1809. err = -EAGAIN;
  1810. err_loopback_none:
  1811. mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR, 0);
  1812. nic->loopback = lb_none;
  1813. e100_hw_init(nic);
  1814. e100_clean_cbs(nic);
  1815. err_clean_rx:
  1816. e100_rx_clean_list(nic);
  1817. return err;
  1818. }
  1819. #define MII_LED_CONTROL 0x1B
  1820. static void e100_blink_led(unsigned long data)
  1821. {
  1822. struct nic *nic = (struct nic *)data;
  1823. enum led_state {
  1824. led_on = 0x01,
  1825. led_off = 0x04,
  1826. led_on_559 = 0x05,
  1827. led_on_557 = 0x07,
  1828. };
  1829. nic->leds = (nic->leds & led_on) ? led_off :
  1830. (nic->mac < mac_82559_D101M) ? led_on_557 : led_on_559;
  1831. mdio_write(nic->netdev, nic->mii.phy_id, MII_LED_CONTROL, nic->leds);
  1832. mod_timer(&nic->blink_timer, jiffies + HZ / 4);
  1833. }
  1834. static int e100_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1835. {
  1836. struct nic *nic = netdev_priv(netdev);
  1837. return mii_ethtool_gset(&nic->mii, cmd);
  1838. }
  1839. static int e100_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1840. {
  1841. struct nic *nic = netdev_priv(netdev);
  1842. int err;
  1843. mdio_write(netdev, nic->mii.phy_id, MII_BMCR, BMCR_RESET);
  1844. err = mii_ethtool_sset(&nic->mii, cmd);
  1845. e100_exec_cb(nic, NULL, e100_configure);
  1846. return err;
  1847. }
  1848. static void e100_get_drvinfo(struct net_device *netdev,
  1849. struct ethtool_drvinfo *info)
  1850. {
  1851. struct nic *nic = netdev_priv(netdev);
  1852. strcpy(info->driver, DRV_NAME);
  1853. strcpy(info->version, DRV_VERSION);
  1854. strcpy(info->fw_version, "N/A");
  1855. strcpy(info->bus_info, pci_name(nic->pdev));
  1856. }
  1857. static int e100_get_regs_len(struct net_device *netdev)
  1858. {
  1859. struct nic *nic = netdev_priv(netdev);
  1860. #define E100_PHY_REGS 0x1C
  1861. #define E100_REGS_LEN 1 + E100_PHY_REGS + \
  1862. sizeof(nic->mem->dump_buf) / sizeof(u32)
  1863. return E100_REGS_LEN * sizeof(u32);
  1864. }
  1865. static void e100_get_regs(struct net_device *netdev,
  1866. struct ethtool_regs *regs, void *p)
  1867. {
  1868. struct nic *nic = netdev_priv(netdev);
  1869. u32 *buff = p;
  1870. int i;
  1871. regs->version = (1 << 24) | nic->rev_id;
  1872. buff[0] = readb(&nic->csr->scb.cmd_hi) << 24 |
  1873. readb(&nic->csr->scb.cmd_lo) << 16 |
  1874. readw(&nic->csr->scb.status);
  1875. for(i = E100_PHY_REGS; i >= 0; i--)
  1876. buff[1 + E100_PHY_REGS - i] =
  1877. mdio_read(netdev, nic->mii.phy_id, i);
  1878. memset(nic->mem->dump_buf, 0, sizeof(nic->mem->dump_buf));
  1879. e100_exec_cb(nic, NULL, e100_dump);
  1880. msleep(10);
  1881. memcpy(&buff[2 + E100_PHY_REGS], nic->mem->dump_buf,
  1882. sizeof(nic->mem->dump_buf));
  1883. }
  1884. static void e100_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1885. {
  1886. struct nic *nic = netdev_priv(netdev);
  1887. wol->supported = (nic->mac >= mac_82558_D101_A4) ? WAKE_MAGIC : 0;
  1888. wol->wolopts = (nic->flags & wol_magic) ? WAKE_MAGIC : 0;
  1889. }
  1890. static int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1891. {
  1892. struct nic *nic = netdev_priv(netdev);
  1893. if(wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
  1894. return -EOPNOTSUPP;
  1895. if(wol->wolopts)
  1896. nic->flags |= wol_magic;
  1897. else
  1898. nic->flags &= ~wol_magic;
  1899. e100_exec_cb(nic, NULL, e100_configure);
  1900. return 0;
  1901. }
  1902. static u32 e100_get_msglevel(struct net_device *netdev)
  1903. {
  1904. struct nic *nic = netdev_priv(netdev);
  1905. return nic->msg_enable;
  1906. }
  1907. static void e100_set_msglevel(struct net_device *netdev, u32 value)
  1908. {
  1909. struct nic *nic = netdev_priv(netdev);
  1910. nic->msg_enable = value;
  1911. }
  1912. static int e100_nway_reset(struct net_device *netdev)
  1913. {
  1914. struct nic *nic = netdev_priv(netdev);
  1915. return mii_nway_restart(&nic->mii);
  1916. }
  1917. static u32 e100_get_link(struct net_device *netdev)
  1918. {
  1919. struct nic *nic = netdev_priv(netdev);
  1920. return mii_link_ok(&nic->mii);
  1921. }
  1922. static int e100_get_eeprom_len(struct net_device *netdev)
  1923. {
  1924. struct nic *nic = netdev_priv(netdev);
  1925. return nic->eeprom_wc << 1;
  1926. }
  1927. #define E100_EEPROM_MAGIC 0x1234
  1928. static int e100_get_eeprom(struct net_device *netdev,
  1929. struct ethtool_eeprom *eeprom, u8 *bytes)
  1930. {
  1931. struct nic *nic = netdev_priv(netdev);
  1932. eeprom->magic = E100_EEPROM_MAGIC;
  1933. memcpy(bytes, &((u8 *)nic->eeprom)[eeprom->offset], eeprom->len);
  1934. return 0;
  1935. }
  1936. static int e100_set_eeprom(struct net_device *netdev,
  1937. struct ethtool_eeprom *eeprom, u8 *bytes)
  1938. {
  1939. struct nic *nic = netdev_priv(netdev);
  1940. if(eeprom->magic != E100_EEPROM_MAGIC)
  1941. return -EINVAL;
  1942. memcpy(&((u8 *)nic->eeprom)[eeprom->offset], bytes, eeprom->len);
  1943. return e100_eeprom_save(nic, eeprom->offset >> 1,
  1944. (eeprom->len >> 1) + 1);
  1945. }
  1946. static void e100_get_ringparam(struct net_device *netdev,
  1947. struct ethtool_ringparam *ring)
  1948. {
  1949. struct nic *nic = netdev_priv(netdev);
  1950. struct param_range *rfds = &nic->params.rfds;
  1951. struct param_range *cbs = &nic->params.cbs;
  1952. ring->rx_max_pending = rfds->max;
  1953. ring->tx_max_pending = cbs->max;
  1954. ring->rx_mini_max_pending = 0;
  1955. ring->rx_jumbo_max_pending = 0;
  1956. ring->rx_pending = rfds->count;
  1957. ring->tx_pending = cbs->count;
  1958. ring->rx_mini_pending = 0;
  1959. ring->rx_jumbo_pending = 0;
  1960. }
  1961. static int e100_set_ringparam(struct net_device *netdev,
  1962. struct ethtool_ringparam *ring)
  1963. {
  1964. struct nic *nic = netdev_priv(netdev);
  1965. struct param_range *rfds = &nic->params.rfds;
  1966. struct param_range *cbs = &nic->params.cbs;
  1967. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1968. return -EINVAL;
  1969. if(netif_running(netdev))
  1970. e100_down(nic);
  1971. rfds->count = max(ring->rx_pending, rfds->min);
  1972. rfds->count = min(rfds->count, rfds->max);
  1973. cbs->count = max(ring->tx_pending, cbs->min);
  1974. cbs->count = min(cbs->count, cbs->max);
  1975. DPRINTK(DRV, INFO, "Ring Param settings: rx: %d, tx %d\n",
  1976. rfds->count, cbs->count);
  1977. if(netif_running(netdev))
  1978. e100_up(nic);
  1979. return 0;
  1980. }
  1981. static const char e100_gstrings_test[][ETH_GSTRING_LEN] = {
  1982. "Link test (on/offline)",
  1983. "Eeprom test (on/offline)",
  1984. "Self test (offline)",
  1985. "Mac loopback (offline)",
  1986. "Phy loopback (offline)",
  1987. };
  1988. #define E100_TEST_LEN sizeof(e100_gstrings_test) / ETH_GSTRING_LEN
  1989. static int e100_diag_test_count(struct net_device *netdev)
  1990. {
  1991. return E100_TEST_LEN;
  1992. }
  1993. static void e100_diag_test(struct net_device *netdev,
  1994. struct ethtool_test *test, u64 *data)
  1995. {
  1996. struct ethtool_cmd cmd;
  1997. struct nic *nic = netdev_priv(netdev);
  1998. int i, err;
  1999. memset(data, 0, E100_TEST_LEN * sizeof(u64));
  2000. data[0] = !mii_link_ok(&nic->mii);
  2001. data[1] = e100_eeprom_load(nic);
  2002. if(test->flags & ETH_TEST_FL_OFFLINE) {
  2003. /* save speed, duplex & autoneg settings */
  2004. err = mii_ethtool_gset(&nic->mii, &cmd);
  2005. if(netif_running(netdev))
  2006. e100_down(nic);
  2007. data[2] = e100_self_test(nic);
  2008. data[3] = e100_loopback_test(nic, lb_mac);
  2009. data[4] = e100_loopback_test(nic, lb_phy);
  2010. /* restore speed, duplex & autoneg settings */
  2011. err = mii_ethtool_sset(&nic->mii, &cmd);
  2012. if(netif_running(netdev))
  2013. e100_up(nic);
  2014. }
  2015. for(i = 0; i < E100_TEST_LEN; i++)
  2016. test->flags |= data[i] ? ETH_TEST_FL_FAILED : 0;
  2017. msleep_interruptible(4 * 1000);
  2018. }
  2019. static int e100_phys_id(struct net_device *netdev, u32 data)
  2020. {
  2021. struct nic *nic = netdev_priv(netdev);
  2022. if(!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
  2023. data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
  2024. mod_timer(&nic->blink_timer, jiffies);
  2025. msleep_interruptible(data * 1000);
  2026. del_timer_sync(&nic->blink_timer);
  2027. mdio_write(netdev, nic->mii.phy_id, MII_LED_CONTROL, 0);
  2028. return 0;
  2029. }
  2030. static const char e100_gstrings_stats[][ETH_GSTRING_LEN] = {
  2031. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  2032. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  2033. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  2034. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  2035. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  2036. "tx_heartbeat_errors", "tx_window_errors",
  2037. /* device-specific stats */
  2038. "tx_deferred", "tx_single_collisions", "tx_multi_collisions",
  2039. "tx_flow_control_pause", "rx_flow_control_pause",
  2040. "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets",
  2041. };
  2042. #define E100_NET_STATS_LEN 21
  2043. #define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN
  2044. static int e100_get_stats_count(struct net_device *netdev)
  2045. {
  2046. return E100_STATS_LEN;
  2047. }
  2048. static void e100_get_ethtool_stats(struct net_device *netdev,
  2049. struct ethtool_stats *stats, u64 *data)
  2050. {
  2051. struct nic *nic = netdev_priv(netdev);
  2052. int i;
  2053. for(i = 0; i < E100_NET_STATS_LEN; i++)
  2054. data[i] = ((unsigned long *)&nic->net_stats)[i];
  2055. data[i++] = nic->tx_deferred;
  2056. data[i++] = nic->tx_single_collisions;
  2057. data[i++] = nic->tx_multiple_collisions;
  2058. data[i++] = nic->tx_fc_pause;
  2059. data[i++] = nic->rx_fc_pause;
  2060. data[i++] = nic->rx_fc_unsupported;
  2061. data[i++] = nic->tx_tco_frames;
  2062. data[i++] = nic->rx_tco_frames;
  2063. }
  2064. static void e100_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  2065. {
  2066. switch(stringset) {
  2067. case ETH_SS_TEST:
  2068. memcpy(data, *e100_gstrings_test, sizeof(e100_gstrings_test));
  2069. break;
  2070. case ETH_SS_STATS:
  2071. memcpy(data, *e100_gstrings_stats, sizeof(e100_gstrings_stats));
  2072. break;
  2073. }
  2074. }
  2075. static struct ethtool_ops e100_ethtool_ops = {
  2076. .get_settings = e100_get_settings,
  2077. .set_settings = e100_set_settings,
  2078. .get_drvinfo = e100_get_drvinfo,
  2079. .get_regs_len = e100_get_regs_len,
  2080. .get_regs = e100_get_regs,
  2081. .get_wol = e100_get_wol,
  2082. .set_wol = e100_set_wol,
  2083. .get_msglevel = e100_get_msglevel,
  2084. .set_msglevel = e100_set_msglevel,
  2085. .nway_reset = e100_nway_reset,
  2086. .get_link = e100_get_link,
  2087. .get_eeprom_len = e100_get_eeprom_len,
  2088. .get_eeprom = e100_get_eeprom,
  2089. .set_eeprom = e100_set_eeprom,
  2090. .get_ringparam = e100_get_ringparam,
  2091. .set_ringparam = e100_set_ringparam,
  2092. .self_test_count = e100_diag_test_count,
  2093. .self_test = e100_diag_test,
  2094. .get_strings = e100_get_strings,
  2095. .phys_id = e100_phys_id,
  2096. .get_stats_count = e100_get_stats_count,
  2097. .get_ethtool_stats = e100_get_ethtool_stats,
  2098. .get_perm_addr = ethtool_op_get_perm_addr,
  2099. };
  2100. static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2101. {
  2102. struct nic *nic = netdev_priv(netdev);
  2103. return generic_mii_ioctl(&nic->mii, if_mii(ifr), cmd, NULL);
  2104. }
  2105. static int e100_alloc(struct nic *nic)
  2106. {
  2107. nic->mem = pci_alloc_consistent(nic->pdev, sizeof(struct mem),
  2108. &nic->dma_addr);
  2109. return nic->mem ? 0 : -ENOMEM;
  2110. }
  2111. static void e100_free(struct nic *nic)
  2112. {
  2113. if(nic->mem) {
  2114. pci_free_consistent(nic->pdev, sizeof(struct mem),
  2115. nic->mem, nic->dma_addr);
  2116. nic->mem = NULL;
  2117. }
  2118. }
  2119. static int e100_open(struct net_device *netdev)
  2120. {
  2121. struct nic *nic = netdev_priv(netdev);
  2122. int err = 0;
  2123. netif_carrier_off(netdev);
  2124. if((err = e100_up(nic)))
  2125. DPRINTK(IFUP, ERR, "Cannot open interface, aborting.\n");
  2126. return err;
  2127. }
  2128. static int e100_close(struct net_device *netdev)
  2129. {
  2130. e100_down(netdev_priv(netdev));
  2131. return 0;
  2132. }
  2133. static int __devinit e100_probe(struct pci_dev *pdev,
  2134. const struct pci_device_id *ent)
  2135. {
  2136. struct net_device *netdev;
  2137. struct nic *nic;
  2138. int err;
  2139. if(!(netdev = alloc_etherdev(sizeof(struct nic)))) {
  2140. if(((1 << debug) - 1) & NETIF_MSG_PROBE)
  2141. printk(KERN_ERR PFX "Etherdev alloc failed, abort.\n");
  2142. return -ENOMEM;
  2143. }
  2144. netdev->open = e100_open;
  2145. netdev->stop = e100_close;
  2146. netdev->hard_start_xmit = e100_xmit_frame;
  2147. netdev->get_stats = e100_get_stats;
  2148. netdev->set_multicast_list = e100_set_multicast_list;
  2149. netdev->set_mac_address = e100_set_mac_address;
  2150. netdev->change_mtu = e100_change_mtu;
  2151. netdev->do_ioctl = e100_do_ioctl;
  2152. SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
  2153. netdev->tx_timeout = e100_tx_timeout;
  2154. netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
  2155. netdev->poll = e100_poll;
  2156. netdev->weight = E100_NAPI_WEIGHT;
  2157. #ifdef CONFIG_NET_POLL_CONTROLLER
  2158. netdev->poll_controller = e100_netpoll;
  2159. #endif
  2160. strcpy(netdev->name, pci_name(pdev));
  2161. nic = netdev_priv(netdev);
  2162. nic->netdev = netdev;
  2163. nic->pdev = pdev;
  2164. nic->msg_enable = (1 << debug) - 1;
  2165. pci_set_drvdata(pdev, netdev);
  2166. if((err = pci_enable_device(pdev))) {
  2167. DPRINTK(PROBE, ERR, "Cannot enable PCI device, aborting.\n");
  2168. goto err_out_free_dev;
  2169. }
  2170. if(!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  2171. DPRINTK(PROBE, ERR, "Cannot find proper PCI device "
  2172. "base address, aborting.\n");
  2173. err = -ENODEV;
  2174. goto err_out_disable_pdev;
  2175. }
  2176. if((err = pci_request_regions(pdev, DRV_NAME))) {
  2177. DPRINTK(PROBE, ERR, "Cannot obtain PCI resources, aborting.\n");
  2178. goto err_out_disable_pdev;
  2179. }
  2180. if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
  2181. DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n");
  2182. goto err_out_free_res;
  2183. }
  2184. SET_MODULE_OWNER(netdev);
  2185. SET_NETDEV_DEV(netdev, &pdev->dev);
  2186. nic->csr = ioremap(pci_resource_start(pdev, 0), sizeof(struct csr));
  2187. if(!nic->csr) {
  2188. DPRINTK(PROBE, ERR, "Cannot map device registers, aborting.\n");
  2189. err = -ENOMEM;
  2190. goto err_out_free_res;
  2191. }
  2192. if(ent->driver_data)
  2193. nic->flags |= ich;
  2194. else
  2195. nic->flags &= ~ich;
  2196. e100_get_defaults(nic);
  2197. /* locks must be initialized before calling hw_reset */
  2198. spin_lock_init(&nic->cb_lock);
  2199. spin_lock_init(&nic->cmd_lock);
  2200. /* Reset the device before pci_set_master() in case device is in some
  2201. * funky state and has an interrupt pending - hint: we don't have the
  2202. * interrupt handler registered yet. */
  2203. e100_hw_reset(nic);
  2204. pci_set_master(pdev);
  2205. init_timer(&nic->watchdog);
  2206. nic->watchdog.function = e100_watchdog;
  2207. nic->watchdog.data = (unsigned long)nic;
  2208. init_timer(&nic->blink_timer);
  2209. nic->blink_timer.function = e100_blink_led;
  2210. nic->blink_timer.data = (unsigned long)nic;
  2211. INIT_WORK(&nic->tx_timeout_task,
  2212. (void (*)(void *))e100_tx_timeout_task, netdev);
  2213. if((err = e100_alloc(nic))) {
  2214. DPRINTK(PROBE, ERR, "Cannot alloc driver memory, aborting.\n");
  2215. goto err_out_iounmap;
  2216. }
  2217. if((err = e100_eeprom_load(nic)))
  2218. goto err_out_free;
  2219. e100_phy_init(nic);
  2220. memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
  2221. memcpy(netdev->perm_addr, nic->eeprom, ETH_ALEN);
  2222. if(!is_valid_ether_addr(netdev->perm_addr)) {
  2223. DPRINTK(PROBE, ERR, "Invalid MAC address from "
  2224. "EEPROM, aborting.\n");
  2225. err = -EAGAIN;
  2226. goto err_out_free;
  2227. }
  2228. /* Wol magic packet can be enabled from eeprom */
  2229. if((nic->mac >= mac_82558_D101_A4) &&
  2230. (nic->eeprom[eeprom_id] & eeprom_id_wol))
  2231. nic->flags |= wol_magic;
  2232. /* ack any pending wake events, disable PME */
  2233. pci_enable_wake(pdev, 0, 0);
  2234. strcpy(netdev->name, "eth%d");
  2235. if((err = register_netdev(netdev))) {
  2236. DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n");
  2237. goto err_out_free;
  2238. }
  2239. DPRINTK(PROBE, INFO, "addr 0x%lx, irq %d, "
  2240. "MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
  2241. pci_resource_start(pdev, 0), pdev->irq,
  2242. netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
  2243. netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
  2244. return 0;
  2245. err_out_free:
  2246. e100_free(nic);
  2247. err_out_iounmap:
  2248. iounmap(nic->csr);
  2249. err_out_free_res:
  2250. pci_release_regions(pdev);
  2251. err_out_disable_pdev:
  2252. pci_disable_device(pdev);
  2253. err_out_free_dev:
  2254. pci_set_drvdata(pdev, NULL);
  2255. free_netdev(netdev);
  2256. return err;
  2257. }
  2258. static void __devexit e100_remove(struct pci_dev *pdev)
  2259. {
  2260. struct net_device *netdev = pci_get_drvdata(pdev);
  2261. if(netdev) {
  2262. struct nic *nic = netdev_priv(netdev);
  2263. unregister_netdev(netdev);
  2264. e100_free(nic);
  2265. iounmap(nic->csr);
  2266. free_netdev(netdev);
  2267. pci_release_regions(pdev);
  2268. pci_disable_device(pdev);
  2269. pci_set_drvdata(pdev, NULL);
  2270. }
  2271. }
  2272. #ifdef CONFIG_PM
  2273. static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
  2274. {
  2275. struct net_device *netdev = pci_get_drvdata(pdev);
  2276. struct nic *nic = netdev_priv(netdev);
  2277. if(netif_running(netdev))
  2278. e100_down(nic);
  2279. e100_hw_reset(nic);
  2280. netif_device_detach(netdev);
  2281. pci_save_state(pdev);
  2282. pci_enable_wake(pdev, pci_choose_state(pdev, state), nic->flags & (wol_magic | e100_asf(nic)));
  2283. pci_disable_device(pdev);
  2284. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  2285. return 0;
  2286. }
  2287. static int e100_resume(struct pci_dev *pdev)
  2288. {
  2289. struct net_device *netdev = pci_get_drvdata(pdev);
  2290. struct nic *nic = netdev_priv(netdev);
  2291. pci_set_power_state(pdev, PCI_D0);
  2292. pci_restore_state(pdev);
  2293. /* ack any pending wake events, disable PME */
  2294. pci_enable_wake(pdev, 0, 0);
  2295. if(e100_hw_init(nic))
  2296. DPRINTK(HW, ERR, "e100_hw_init failed\n");
  2297. netif_device_attach(netdev);
  2298. if(netif_running(netdev))
  2299. e100_up(nic);
  2300. return 0;
  2301. }
  2302. #endif
  2303. static void e100_shutdown(struct pci_dev *pdev)
  2304. {
  2305. struct net_device *netdev = pci_get_drvdata(pdev);
  2306. struct nic *nic = netdev_priv(netdev);
  2307. #ifdef CONFIG_PM
  2308. pci_enable_wake(pdev, 0, nic->flags & (wol_magic | e100_asf(nic)));
  2309. #else
  2310. pci_enable_wake(pdev, 0, nic->flags & (wol_magic));
  2311. #endif
  2312. }
  2313. static struct pci_driver e100_driver = {
  2314. .name = DRV_NAME,
  2315. .id_table = e100_id_table,
  2316. .probe = e100_probe,
  2317. .remove = __devexit_p(e100_remove),
  2318. #ifdef CONFIG_PM
  2319. .suspend = e100_suspend,
  2320. .resume = e100_resume,
  2321. #endif
  2322. .shutdown = e100_shutdown,
  2323. };
  2324. static int __init e100_init_module(void)
  2325. {
  2326. if(((1 << debug) - 1) & NETIF_MSG_DRV) {
  2327. printk(KERN_INFO PFX "%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
  2328. printk(KERN_INFO PFX "%s\n", DRV_COPYRIGHT);
  2329. }
  2330. return pci_module_init(&e100_driver);
  2331. }
  2332. static void __exit e100_cleanup_module(void)
  2333. {
  2334. pci_unregister_driver(&e100_driver);
  2335. }
  2336. module_init(e100_init_module);
  2337. module_exit(e100_cleanup_module);