3c515.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. /*
  2. Written 1997-1998 by Donald Becker.
  3. This software may be used and distributed according to the terms
  4. of the GNU General Public License, incorporated herein by reference.
  5. This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.
  6. The author may be reached as becker@scyld.com, or C/O
  7. Scyld Computing Corporation
  8. 410 Severn Ave., Suite 210
  9. Annapolis MD 21403
  10. 2000/2/2- Added support for kernel-level ISAPnP
  11. by Stephen Frost <sfrost@snowman.net> and Alessandro Zummo
  12. Cleaned up for 2.3.x/softnet by Jeff Garzik and Alan Cox.
  13. 2001/11/17 - Added ethtool support (jgarzik)
  14. 2002/10/28 - Locking updates for 2.5 (alan@lxorguk.ukuu.org.uk)
  15. */
  16. #define DRV_NAME "3c515"
  17. #define DRV_VERSION "0.99t-ac"
  18. #define DRV_RELDATE "28-Oct-2002"
  19. static char *version =
  20. DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " becker@scyld.com and others\n";
  21. #define CORKSCREW 1
  22. /* "Knobs" that adjust features and parameters. */
  23. /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  24. Setting to > 1512 effectively disables this feature. */
  25. static int rx_copybreak = 200;
  26. /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
  27. static const int mtu = 1500;
  28. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  29. static int max_interrupt_work = 20;
  30. /* Enable the automatic media selection code -- usually set. */
  31. #define AUTOMEDIA 1
  32. /* Allow the use of fragment bus master transfers instead of only
  33. programmed-I/O for Vortex cards. Full-bus-master transfers are always
  34. enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
  35. the feature may be turned on using 'options'. */
  36. #define VORTEX_BUS_MASTER
  37. /* A few values that may be tweaked. */
  38. /* Keep the ring sizes a power of two for efficiency. */
  39. #define TX_RING_SIZE 16
  40. #define RX_RING_SIZE 16
  41. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  42. #include <linux/module.h>
  43. #include <linux/isapnp.h>
  44. #include <linux/kernel.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/string.h>
  47. #include <linux/errno.h>
  48. #include <linux/in.h>
  49. #include <linux/ioport.h>
  50. #include <linux/slab.h>
  51. #include <linux/skbuff.h>
  52. #include <linux/etherdevice.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/timer.h>
  55. #include <linux/ethtool.h>
  56. #include <linux/bitops.h>
  57. #include <asm/uaccess.h>
  58. #include <asm/io.h>
  59. #include <asm/dma.h>
  60. #define NEW_MULTICAST
  61. #include <linux/delay.h>
  62. #define MAX_UNITS 8
  63. MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
  64. MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
  65. MODULE_LICENSE("GPL");
  66. MODULE_VERSION(DRV_VERSION);
  67. /* "Knobs" for adjusting internal parameters. */
  68. /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
  69. #define DRIVER_DEBUG 1
  70. /* Some values here only for performance evaluation and path-coverage
  71. debugging. */
  72. static int rx_nocopy, rx_copy, queued_packet;
  73. /* Number of times to check to see if the Tx FIFO has space, used in some
  74. limited cases. */
  75. #define WAIT_TX_AVAIL 200
  76. /* Operational parameter that usually are not changed. */
  77. #define TX_TIMEOUT 40 /* Time in jiffies before concluding Tx hung */
  78. /* The size here is somewhat misleading: the Corkscrew also uses the ISA
  79. aliased registers at <base>+0x400.
  80. */
  81. #define CORKSCREW_TOTAL_SIZE 0x20
  82. #ifdef DRIVER_DEBUG
  83. static int corkscrew_debug = DRIVER_DEBUG;
  84. #else
  85. static int corkscrew_debug = 1;
  86. #endif
  87. #define CORKSCREW_ID 10
  88. /*
  89. Theory of Operation
  90. I. Board Compatibility
  91. This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
  92. 3Com's ISA bus adapter for Fast Ethernet. Due to the unique I/O port layout,
  93. it's not practical to integrate this driver with the other EtherLink drivers.
  94. II. Board-specific settings
  95. The Corkscrew has an EEPROM for configuration, but no special settings are
  96. needed for Linux.
  97. III. Driver operation
  98. The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
  99. PCI cards, with the bus master interface extensively modified to work with
  100. the ISA bus.
  101. The card is capable of full-bus-master transfers with separate
  102. lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
  103. DEC Tulip and Intel Speedo3.
  104. This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
  105. receive buffer. This scheme allocates full-sized skbuffs as receive
  106. buffers. The value RX_COPYBREAK is used as the copying breakpoint: it is
  107. chosen to trade-off the memory wasted by passing the full-sized skbuff to
  108. the queue layer for all frames vs. the copying cost of copying a frame to a
  109. correctly-sized skbuff.
  110. IIIC. Synchronization
  111. The driver runs as two independent, single-threaded flows of control. One
  112. is the send-packet routine, which enforces single-threaded use by the netif
  113. layer. The other thread is the interrupt handler, which is single
  114. threaded by the hardware and other software.
  115. IV. Notes
  116. Thanks to Terry Murphy of 3Com for providing documentation and a development
  117. board.
  118. The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
  119. project names. I use these names to eliminate confusion -- 3Com product
  120. numbers and names are very similar and often confused.
  121. The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
  122. This driver only supports ethernet frames because of the recent MTU limit
  123. of 1.5K, but the changes to support 4.5K are minimal.
  124. */
  125. /* Operational definitions.
  126. These are not used by other compilation units and thus are not
  127. exported in a ".h" file.
  128. First the windows. There are eight register windows, with the command
  129. and status registers available in each.
  130. */
  131. #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
  132. #define EL3_CMD 0x0e
  133. #define EL3_STATUS 0x0e
  134. /* The top five bits written to EL3_CMD are a command, the lower
  135. 11 bits are the parameter, if applicable.
  136. Note that 11 parameters bits was fine for ethernet, but the new chips
  137. can handle FDDI length frames (~4500 octets) and now parameters count
  138. 32-bit 'Dwords' rather than octets. */
  139. enum corkscrew_cmd {
  140. TotalReset = 0 << 11, SelectWindow = 1 << 11, StartCoax = 2 << 11,
  141. RxDisable = 3 << 11, RxEnable = 4 << 11, RxReset = 5 << 11,
  142. UpStall = 6 << 11, UpUnstall = (6 << 11) + 1, DownStall = (6 << 11) + 2,
  143. DownUnstall = (6 << 11) + 3, RxDiscard = 8 << 11, TxEnable = 9 << 11,
  144. TxDisable = 10 << 11, TxReset = 11 << 11, FakeIntr = 12 << 11,
  145. AckIntr = 13 << 11, SetIntrEnb = 14 << 11, SetStatusEnb = 15 << 11,
  146. SetRxFilter = 16 << 11, SetRxThreshold = 17 << 11,
  147. SetTxThreshold = 18 << 11, SetTxStart = 19 << 11, StartDMAUp = 20 << 11,
  148. StartDMADown = (20 << 11) + 1, StatsEnable = 21 << 11,
  149. StatsDisable = 22 << 11, StopCoax = 23 << 11,
  150. };
  151. /* The SetRxFilter command accepts the following classes: */
  152. enum RxFilter {
  153. RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8
  154. };
  155. /* Bits in the general status register. */
  156. enum corkscrew_status {
  157. IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
  158. TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
  159. IntReq = 0x0040, StatsFull = 0x0080,
  160. DMADone = 1 << 8, DownComplete = 1 << 9, UpComplete = 1 << 10,
  161. DMAInProgress = 1 << 11, /* DMA controller is still busy. */
  162. CmdInProgress = 1 << 12, /* EL3_CMD is still busy. */
  163. };
  164. /* Register window 1 offsets, the window used in normal operation.
  165. On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
  166. enum Window1 {
  167. TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
  168. RxStatus = 0x18, Timer = 0x1A, TxStatus = 0x1B,
  169. TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
  170. };
  171. enum Window0 {
  172. Wn0IRQ = 0x08,
  173. #if defined(CORKSCREW)
  174. Wn0EepromCmd = 0x200A, /* Corkscrew EEPROM command register. */
  175. Wn0EepromData = 0x200C, /* Corkscrew EEPROM results register. */
  176. #else
  177. Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
  178. Wn0EepromData = 12, /* Window 0: EEPROM results register. */
  179. #endif
  180. };
  181. enum Win0_EEPROM_bits {
  182. EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
  183. EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
  184. EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
  185. };
  186. /* EEPROM locations. */
  187. enum eeprom_offset {
  188. PhysAddr01 = 0, PhysAddr23 = 1, PhysAddr45 = 2, ModelID = 3,
  189. EtherLink3ID = 7,
  190. };
  191. enum Window3 { /* Window 3: MAC/config bits. */
  192. Wn3_Config = 0, Wn3_MAC_Ctrl = 6, Wn3_Options = 8,
  193. };
  194. enum wn3_config {
  195. Ram_size = 7,
  196. Ram_width = 8,
  197. Ram_speed = 0x30,
  198. Rom_size = 0xc0,
  199. Ram_split_shift = 16,
  200. Ram_split = 3 << Ram_split_shift,
  201. Xcvr_shift = 20,
  202. Xcvr = 7 << Xcvr_shift,
  203. Autoselect = 0x1000000,
  204. };
  205. enum Window4 {
  206. Wn4_NetDiag = 6, Wn4_Media = 10, /* Window 4: Xcvr/media bits. */
  207. };
  208. enum Win4_Media_bits {
  209. Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
  210. Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
  211. Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
  212. Media_LnkBeat = 0x0800,
  213. };
  214. enum Window7 { /* Window 7: Bus Master control. */
  215. Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
  216. };
  217. /* Boomerang-style bus master control registers. Note ISA aliases! */
  218. enum MasterCtrl {
  219. PktStatus = 0x400, DownListPtr = 0x404, FragAddr = 0x408, FragLen =
  220. 0x40c,
  221. TxFreeThreshold = 0x40f, UpPktStatus = 0x410, UpListPtr = 0x418,
  222. };
  223. /* The Rx and Tx descriptor lists.
  224. Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
  225. alignment contraint on tx_ring[] and rx_ring[]. */
  226. struct boom_rx_desc {
  227. u32 next;
  228. s32 status;
  229. u32 addr;
  230. s32 length;
  231. };
  232. /* Values for the Rx status entry. */
  233. enum rx_desc_status {
  234. RxDComplete = 0x00008000, RxDError = 0x4000,
  235. /* See boomerang_rx() for actual error bits */
  236. };
  237. struct boom_tx_desc {
  238. u32 next;
  239. s32 status;
  240. u32 addr;
  241. s32 length;
  242. };
  243. struct corkscrew_private {
  244. const char *product_name;
  245. struct list_head list;
  246. struct net_device *our_dev;
  247. /* The Rx and Tx rings are here to keep them quad-word-aligned. */
  248. struct boom_rx_desc rx_ring[RX_RING_SIZE];
  249. struct boom_tx_desc tx_ring[TX_RING_SIZE];
  250. /* The addresses of transmit- and receive-in-place skbuffs. */
  251. struct sk_buff *rx_skbuff[RX_RING_SIZE];
  252. struct sk_buff *tx_skbuff[TX_RING_SIZE];
  253. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  254. unsigned int dirty_rx, dirty_tx;/* The ring entries to be free()ed. */
  255. struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
  256. struct timer_list timer; /* Media selection timer. */
  257. int capabilities ; /* Adapter capabilities word. */
  258. int options; /* User-settable misc. driver options. */
  259. int last_rx_packets; /* For media autoselection. */
  260. unsigned int available_media:8, /* From Wn3_Options */
  261. media_override:3, /* Passed-in media type. */
  262. default_media:3, /* Read from the EEPROM. */
  263. full_duplex:1, autoselect:1, bus_master:1, /* Vortex can only do a fragment bus-m. */
  264. full_bus_master_tx:1, full_bus_master_rx:1, /* Boomerang */
  265. tx_full:1;
  266. spinlock_t lock;
  267. struct device *dev;
  268. };
  269. /* The action to take with a media selection timer tick.
  270. Note that we deviate from the 3Com order by checking 10base2 before AUI.
  271. */
  272. enum xcvr_types {
  273. XCVR_10baseT = 0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
  274. XCVR_100baseFx, XCVR_MII = 6, XCVR_Default = 8,
  275. };
  276. static struct media_table {
  277. char *name;
  278. unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
  279. mask:8, /* The transceiver-present bit in Wn3_Config. */
  280. next:8; /* The media type to try next. */
  281. short wait; /* Time before we check media status. */
  282. } media_tbl[] = {
  283. { "10baseT", Media_10TP, 0x08, XCVR_10base2, (14 * HZ) / 10 },
  284. { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1 * HZ) / 10},
  285. { "undefined", 0, 0x80, XCVR_10baseT, 10000},
  286. { "10base2", 0, 0x10, XCVR_AUI, (1 * HZ) / 10},
  287. { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14 * HZ) / 10},
  288. { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14 * HZ) / 10},
  289. { "MII", 0, 0x40, XCVR_10baseT, 3 * HZ},
  290. { "undefined", 0, 0x01, XCVR_10baseT, 10000},
  291. { "Default", 0, 0xFF, XCVR_10baseT, 10000},
  292. };
  293. #ifdef __ISAPNP__
  294. static struct isapnp_device_id corkscrew_isapnp_adapters[] = {
  295. { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
  296. ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5051),
  297. (long) "3Com Fast EtherLink ISA" },
  298. { } /* terminate list */
  299. };
  300. MODULE_DEVICE_TABLE(isapnp, corkscrew_isapnp_adapters);
  301. static int nopnp;
  302. #endif /* __ISAPNP__ */
  303. static struct net_device *corkscrew_scan(int unit);
  304. static int corkscrew_setup(struct net_device *dev, int ioaddr,
  305. struct pnp_dev *idev, int card_number);
  306. static int corkscrew_open(struct net_device *dev);
  307. static void corkscrew_timer(unsigned long arg);
  308. static int corkscrew_start_xmit(struct sk_buff *skb,
  309. struct net_device *dev);
  310. static int corkscrew_rx(struct net_device *dev);
  311. static void corkscrew_timeout(struct net_device *dev);
  312. static int boomerang_rx(struct net_device *dev);
  313. static irqreturn_t corkscrew_interrupt(int irq, void *dev_id);
  314. static int corkscrew_close(struct net_device *dev);
  315. static void update_stats(int addr, struct net_device *dev);
  316. static struct net_device_stats *corkscrew_get_stats(struct net_device *dev);
  317. static void set_rx_mode(struct net_device *dev);
  318. static const struct ethtool_ops netdev_ethtool_ops;
  319. /*
  320. Unfortunately maximizing the shared code between the integrated and
  321. module version of the driver results in a complicated set of initialization
  322. procedures.
  323. init_module() -- modules / tc59x_init() -- built-in
  324. The wrappers for corkscrew_scan()
  325. corkscrew_scan() The common routine that scans for PCI and EISA cards
  326. corkscrew_found_device() Allocate a device structure when we find a card.
  327. Different versions exist for modules and built-in.
  328. corkscrew_probe1() Fill in the device structure -- this is separated
  329. so that the modules code can put it in dev->init.
  330. */
  331. /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
  332. /* Note: this is the only limit on the number of cards supported!! */
  333. static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1, };
  334. #ifdef MODULE
  335. static int debug = -1;
  336. module_param(debug, int, 0);
  337. module_param_array(options, int, NULL, 0);
  338. module_param(rx_copybreak, int, 0);
  339. module_param(max_interrupt_work, int, 0);
  340. MODULE_PARM_DESC(debug, "3c515 debug level (0-6)");
  341. MODULE_PARM_DESC(options, "3c515: Bits 0-2: media type, bit 3: full duplex, bit 4: bus mastering");
  342. MODULE_PARM_DESC(rx_copybreak, "3c515 copy breakpoint for copy-only-tiny-frames");
  343. MODULE_PARM_DESC(max_interrupt_work, "3c515 maximum events handled per interrupt");
  344. /* A list of all installed Vortex devices, for removing the driver module. */
  345. /* we will need locking (and refcounting) if we ever use it for more */
  346. static LIST_HEAD(root_corkscrew_dev);
  347. int init_module(void)
  348. {
  349. int found = 0;
  350. if (debug >= 0)
  351. corkscrew_debug = debug;
  352. if (corkscrew_debug)
  353. printk(version);
  354. while (corkscrew_scan(-1))
  355. found++;
  356. return found ? 0 : -ENODEV;
  357. }
  358. #else
  359. struct net_device *tc515_probe(int unit)
  360. {
  361. struct net_device *dev = corkscrew_scan(unit);
  362. static int printed;
  363. if (!dev)
  364. return ERR_PTR(-ENODEV);
  365. if (corkscrew_debug > 0 && !printed) {
  366. printed = 1;
  367. printk(version);
  368. }
  369. return dev;
  370. }
  371. #endif /* not MODULE */
  372. static int check_device(unsigned ioaddr)
  373. {
  374. int timer;
  375. if (!request_region(ioaddr, CORKSCREW_TOTAL_SIZE, "3c515"))
  376. return 0;
  377. /* Check the resource configuration for a matching ioaddr. */
  378. if ((inw(ioaddr + 0x2002) & 0x1f0) != (ioaddr & 0x1f0)) {
  379. release_region(ioaddr, CORKSCREW_TOTAL_SIZE);
  380. return 0;
  381. }
  382. /* Verify by reading the device ID from the EEPROM. */
  383. outw(EEPROM_Read + 7, ioaddr + Wn0EepromCmd);
  384. /* Pause for at least 162 us. for the read to take place. */
  385. for (timer = 4; timer >= 0; timer--) {
  386. udelay(162);
  387. if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
  388. break;
  389. }
  390. if (inw(ioaddr + Wn0EepromData) != 0x6d50) {
  391. release_region(ioaddr, CORKSCREW_TOTAL_SIZE);
  392. return 0;
  393. }
  394. return 1;
  395. }
  396. static void cleanup_card(struct net_device *dev)
  397. {
  398. struct corkscrew_private *vp = netdev_priv(dev);
  399. list_del_init(&vp->list);
  400. if (dev->dma)
  401. free_dma(dev->dma);
  402. outw(TotalReset, dev->base_addr + EL3_CMD);
  403. release_region(dev->base_addr, CORKSCREW_TOTAL_SIZE);
  404. if (vp->dev)
  405. pnp_device_detach(to_pnp_dev(vp->dev));
  406. }
  407. static struct net_device *corkscrew_scan(int unit)
  408. {
  409. struct net_device *dev;
  410. static int cards_found = 0;
  411. static int ioaddr;
  412. int err;
  413. #ifdef __ISAPNP__
  414. short i;
  415. static int pnp_cards;
  416. #endif
  417. dev = alloc_etherdev(sizeof(struct corkscrew_private));
  418. if (!dev)
  419. return ERR_PTR(-ENOMEM);
  420. if (unit >= 0) {
  421. sprintf(dev->name, "eth%d", unit);
  422. netdev_boot_setup_check(dev);
  423. }
  424. #ifdef __ISAPNP__
  425. if(nopnp == 1)
  426. goto no_pnp;
  427. for(i=0; corkscrew_isapnp_adapters[i].vendor != 0; i++) {
  428. struct pnp_dev *idev = NULL;
  429. int irq;
  430. while((idev = pnp_find_dev(NULL,
  431. corkscrew_isapnp_adapters[i].vendor,
  432. corkscrew_isapnp_adapters[i].function,
  433. idev))) {
  434. if (pnp_device_attach(idev) < 0)
  435. continue;
  436. if (pnp_activate_dev(idev) < 0) {
  437. printk("pnp activate failed (out of resources?)\n");
  438. pnp_device_detach(idev);
  439. continue;
  440. }
  441. if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0)) {
  442. pnp_device_detach(idev);
  443. continue;
  444. }
  445. ioaddr = pnp_port_start(idev, 0);
  446. irq = pnp_irq(idev, 0);
  447. if (!check_device(ioaddr)) {
  448. pnp_device_detach(idev);
  449. continue;
  450. }
  451. if(corkscrew_debug)
  452. printk ("ISAPNP reports %s at i/o 0x%x, irq %d\n",
  453. (char*) corkscrew_isapnp_adapters[i].driver_data, ioaddr, irq);
  454. printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
  455. inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
  456. /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
  457. SET_NETDEV_DEV(dev, &idev->dev);
  458. pnp_cards++;
  459. err = corkscrew_setup(dev, ioaddr, idev, cards_found++);
  460. if (!err)
  461. return dev;
  462. cleanup_card(dev);
  463. }
  464. }
  465. no_pnp:
  466. #endif /* __ISAPNP__ */
  467. /* Check all locations on the ISA bus -- evil! */
  468. for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20) {
  469. if (!check_device(ioaddr))
  470. continue;
  471. printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
  472. inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
  473. err = corkscrew_setup(dev, ioaddr, NULL, cards_found++);
  474. if (!err)
  475. return dev;
  476. cleanup_card(dev);
  477. }
  478. free_netdev(dev);
  479. return NULL;
  480. }
  481. static const struct net_device_ops netdev_ops = {
  482. .ndo_open = corkscrew_open,
  483. .ndo_stop = corkscrew_close,
  484. .ndo_start_xmit = corkscrew_start_xmit,
  485. .ndo_tx_timeout = corkscrew_timeout,
  486. .ndo_get_stats = corkscrew_get_stats,
  487. .ndo_set_multicast_list = set_rx_mode,
  488. .ndo_change_mtu = eth_change_mtu,
  489. .ndo_set_mac_address = eth_mac_addr,
  490. .ndo_validate_addr = eth_validate_addr,
  491. };
  492. static int corkscrew_setup(struct net_device *dev, int ioaddr,
  493. struct pnp_dev *idev, int card_number)
  494. {
  495. struct corkscrew_private *vp = netdev_priv(dev);
  496. unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
  497. int i;
  498. int irq;
  499. #ifdef __ISAPNP__
  500. if (idev) {
  501. irq = pnp_irq(idev, 0);
  502. vp->dev = &idev->dev;
  503. } else {
  504. irq = inw(ioaddr + 0x2002) & 15;
  505. }
  506. #else
  507. irq = inw(ioaddr + 0x2002) & 15;
  508. #endif
  509. dev->base_addr = ioaddr;
  510. dev->irq = irq;
  511. dev->dma = inw(ioaddr + 0x2000) & 7;
  512. vp->product_name = "3c515";
  513. vp->options = dev->mem_start;
  514. vp->our_dev = dev;
  515. if (!vp->options) {
  516. if (card_number >= MAX_UNITS)
  517. vp->options = -1;
  518. else
  519. vp->options = options[card_number];
  520. }
  521. if (vp->options >= 0) {
  522. vp->media_override = vp->options & 7;
  523. if (vp->media_override == 2)
  524. vp->media_override = 0;
  525. vp->full_duplex = (vp->options & 8) ? 1 : 0;
  526. vp->bus_master = (vp->options & 16) ? 1 : 0;
  527. } else {
  528. vp->media_override = 7;
  529. vp->full_duplex = 0;
  530. vp->bus_master = 0;
  531. }
  532. #ifdef MODULE
  533. list_add(&vp->list, &root_corkscrew_dev);
  534. #endif
  535. printk(KERN_INFO "%s: 3Com %s at %#3x,", dev->name, vp->product_name, ioaddr);
  536. spin_lock_init(&vp->lock);
  537. /* Read the station address from the EEPROM. */
  538. EL3WINDOW(0);
  539. for (i = 0; i < 0x18; i++) {
  540. __be16 *phys_addr = (__be16 *) dev->dev_addr;
  541. int timer;
  542. outw(EEPROM_Read + i, ioaddr + Wn0EepromCmd);
  543. /* Pause for at least 162 us. for the read to take place. */
  544. for (timer = 4; timer >= 0; timer--) {
  545. udelay(162);
  546. if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
  547. break;
  548. }
  549. eeprom[i] = inw(ioaddr + Wn0EepromData);
  550. checksum ^= eeprom[i];
  551. if (i < 3)
  552. phys_addr[i] = htons(eeprom[i]);
  553. }
  554. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  555. if (checksum != 0x00)
  556. printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
  557. printk(" %pM", dev->dev_addr);
  558. if (eeprom[16] == 0x11c7) { /* Corkscrew */
  559. if (request_dma(dev->dma, "3c515")) {
  560. printk(", DMA %d allocation failed", dev->dma);
  561. dev->dma = 0;
  562. } else
  563. printk(", DMA %d", dev->dma);
  564. }
  565. printk(", IRQ %d\n", dev->irq);
  566. /* Tell them about an invalid IRQ. */
  567. if (corkscrew_debug && (dev->irq <= 0 || dev->irq > 15))
  568. printk(KERN_WARNING " *** Warning: this IRQ is unlikely to work! ***\n");
  569. {
  570. char *ram_split[] = { "5:3", "3:1", "1:1", "3:5" };
  571. __u32 config;
  572. EL3WINDOW(3);
  573. vp->available_media = inw(ioaddr + Wn3_Options);
  574. config = inl(ioaddr + Wn3_Config);
  575. if (corkscrew_debug > 1)
  576. printk(KERN_INFO " Internal config register is %4.4x, transceivers %#x.\n",
  577. config, inw(ioaddr + Wn3_Options));
  578. printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
  579. 8 << config & Ram_size,
  580. config & Ram_width ? "word" : "byte",
  581. ram_split[(config & Ram_split) >> Ram_split_shift],
  582. config & Autoselect ? "autoselect/" : "",
  583. media_tbl[(config & Xcvr) >> Xcvr_shift].name);
  584. vp->default_media = (config & Xcvr) >> Xcvr_shift;
  585. vp->autoselect = config & Autoselect ? 1 : 0;
  586. dev->if_port = vp->default_media;
  587. }
  588. if (vp->media_override != 7) {
  589. printk(KERN_INFO " Media override to transceiver type %d (%s).\n",
  590. vp->media_override,
  591. media_tbl[vp->media_override].name);
  592. dev->if_port = vp->media_override;
  593. }
  594. vp->capabilities = eeprom[16];
  595. vp->full_bus_master_tx = (vp->capabilities & 0x20) ? 1 : 0;
  596. /* Rx is broken at 10mbps, so we always disable it. */
  597. /* vp->full_bus_master_rx = 0; */
  598. vp->full_bus_master_rx = (vp->capabilities & 0x20) ? 1 : 0;
  599. /* The 3c51x-specific entries in the device structure. */
  600. dev->netdev_ops = &netdev_ops;
  601. dev->watchdog_timeo = (400 * HZ) / 1000;
  602. dev->ethtool_ops = &netdev_ethtool_ops;
  603. return register_netdev(dev);
  604. }
  605. static int corkscrew_open(struct net_device *dev)
  606. {
  607. int ioaddr = dev->base_addr;
  608. struct corkscrew_private *vp = netdev_priv(dev);
  609. __u32 config;
  610. int i;
  611. /* Before initializing select the active media port. */
  612. EL3WINDOW(3);
  613. if (vp->full_duplex)
  614. outb(0x20, ioaddr + Wn3_MAC_Ctrl); /* Set the full-duplex bit. */
  615. config = inl(ioaddr + Wn3_Config);
  616. if (vp->media_override != 7) {
  617. if (corkscrew_debug > 1)
  618. printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
  619. dev->name, vp->media_override,
  620. media_tbl[vp->media_override].name);
  621. dev->if_port = vp->media_override;
  622. } else if (vp->autoselect) {
  623. /* Find first available media type, starting with 100baseTx. */
  624. dev->if_port = 4;
  625. while (!(vp->available_media & media_tbl[dev->if_port].mask))
  626. dev->if_port = media_tbl[dev->if_port].next;
  627. if (corkscrew_debug > 1)
  628. printk("%s: Initial media type %s.\n",
  629. dev->name, media_tbl[dev->if_port].name);
  630. init_timer(&vp->timer);
  631. vp->timer.expires = jiffies + media_tbl[dev->if_port].wait;
  632. vp->timer.data = (unsigned long) dev;
  633. vp->timer.function = &corkscrew_timer; /* timer handler */
  634. add_timer(&vp->timer);
  635. } else
  636. dev->if_port = vp->default_media;
  637. config = (config & ~Xcvr) | (dev->if_port << Xcvr_shift);
  638. outl(config, ioaddr + Wn3_Config);
  639. if (corkscrew_debug > 1) {
  640. printk("%s: corkscrew_open() InternalConfig %8.8x.\n",
  641. dev->name, config);
  642. }
  643. outw(TxReset, ioaddr + EL3_CMD);
  644. for (i = 20; i >= 0; i--)
  645. if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
  646. break;
  647. outw(RxReset, ioaddr + EL3_CMD);
  648. /* Wait a few ticks for the RxReset command to complete. */
  649. for (i = 20; i >= 0; i--)
  650. if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
  651. break;
  652. outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  653. /* Use the now-standard shared IRQ implementation. */
  654. if (vp->capabilities == 0x11c7) {
  655. /* Corkscrew: Cannot share ISA resources. */
  656. if (dev->irq == 0
  657. || dev->dma == 0
  658. || request_irq(dev->irq, &corkscrew_interrupt, 0,
  659. vp->product_name, dev)) return -EAGAIN;
  660. enable_dma(dev->dma);
  661. set_dma_mode(dev->dma, DMA_MODE_CASCADE);
  662. } else if (request_irq(dev->irq, &corkscrew_interrupt, IRQF_SHARED,
  663. vp->product_name, dev)) {
  664. return -EAGAIN;
  665. }
  666. if (corkscrew_debug > 1) {
  667. EL3WINDOW(4);
  668. printk("%s: corkscrew_open() irq %d media status %4.4x.\n",
  669. dev->name, dev->irq, inw(ioaddr + Wn4_Media));
  670. }
  671. /* Set the station address and mask in window 2 each time opened. */
  672. EL3WINDOW(2);
  673. for (i = 0; i < 6; i++)
  674. outb(dev->dev_addr[i], ioaddr + i);
  675. for (; i < 12; i += 2)
  676. outw(0, ioaddr + i);
  677. if (dev->if_port == 3)
  678. /* Start the thinnet transceiver. We should really wait 50ms... */
  679. outw(StartCoax, ioaddr + EL3_CMD);
  680. EL3WINDOW(4);
  681. outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP | Media_SQE)) |
  682. media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
  683. /* Switch to the stats window, and clear all stats by reading. */
  684. outw(StatsDisable, ioaddr + EL3_CMD);
  685. EL3WINDOW(6);
  686. for (i = 0; i < 10; i++)
  687. inb(ioaddr + i);
  688. inw(ioaddr + 10);
  689. inw(ioaddr + 12);
  690. /* New: On the Vortex we must also clear the BadSSD counter. */
  691. EL3WINDOW(4);
  692. inb(ioaddr + 12);
  693. /* ..and on the Boomerang we enable the extra statistics bits. */
  694. outw(0x0040, ioaddr + Wn4_NetDiag);
  695. /* Switch to register set 7 for normal use. */
  696. EL3WINDOW(7);
  697. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  698. vp->cur_rx = vp->dirty_rx = 0;
  699. if (corkscrew_debug > 2)
  700. printk("%s: Filling in the Rx ring.\n",
  701. dev->name);
  702. for (i = 0; i < RX_RING_SIZE; i++) {
  703. struct sk_buff *skb;
  704. if (i < (RX_RING_SIZE - 1))
  705. vp->rx_ring[i].next =
  706. isa_virt_to_bus(&vp->rx_ring[i + 1]);
  707. else
  708. vp->rx_ring[i].next = 0;
  709. vp->rx_ring[i].status = 0; /* Clear complete bit. */
  710. vp->rx_ring[i].length = PKT_BUF_SZ | 0x80000000;
  711. skb = dev_alloc_skb(PKT_BUF_SZ);
  712. vp->rx_skbuff[i] = skb;
  713. if (skb == NULL)
  714. break; /* Bad news! */
  715. skb->dev = dev; /* Mark as being used by this device. */
  716. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  717. vp->rx_ring[i].addr = isa_virt_to_bus(skb->data);
  718. }
  719. vp->rx_ring[i - 1].next = isa_virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */
  720. outl(isa_virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
  721. }
  722. if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
  723. vp->cur_tx = vp->dirty_tx = 0;
  724. outb(PKT_BUF_SZ >> 8, ioaddr + TxFreeThreshold); /* Room for a packet. */
  725. /* Clear the Tx ring. */
  726. for (i = 0; i < TX_RING_SIZE; i++)
  727. vp->tx_skbuff[i] = NULL;
  728. outl(0, ioaddr + DownListPtr);
  729. }
  730. /* Set receiver mode: presumably accept b-case and phys addr only. */
  731. set_rx_mode(dev);
  732. outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
  733. netif_start_queue(dev);
  734. outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
  735. outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
  736. /* Allow status bits to be seen. */
  737. outw(SetStatusEnb | AdapterFailure | IntReq | StatsFull |
  738. (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
  739. (vp->full_bus_master_rx ? UpComplete : RxComplete) |
  740. (vp->bus_master ? DMADone : 0), ioaddr + EL3_CMD);
  741. /* Ack all pending events, and set active indicator mask. */
  742. outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  743. ioaddr + EL3_CMD);
  744. outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
  745. | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete,
  746. ioaddr + EL3_CMD);
  747. return 0;
  748. }
  749. static void corkscrew_timer(unsigned long data)
  750. {
  751. #ifdef AUTOMEDIA
  752. struct net_device *dev = (struct net_device *) data;
  753. struct corkscrew_private *vp = netdev_priv(dev);
  754. int ioaddr = dev->base_addr;
  755. unsigned long flags;
  756. int ok = 0;
  757. if (corkscrew_debug > 1)
  758. printk("%s: Media selection timer tick happened, %s.\n",
  759. dev->name, media_tbl[dev->if_port].name);
  760. spin_lock_irqsave(&vp->lock, flags);
  761. {
  762. int old_window = inw(ioaddr + EL3_CMD) >> 13;
  763. int media_status;
  764. EL3WINDOW(4);
  765. media_status = inw(ioaddr + Wn4_Media);
  766. switch (dev->if_port) {
  767. case 0:
  768. case 4:
  769. case 5: /* 10baseT, 100baseTX, 100baseFX */
  770. if (media_status & Media_LnkBeat) {
  771. ok = 1;
  772. if (corkscrew_debug > 1)
  773. printk("%s: Media %s has link beat, %x.\n",
  774. dev->name,
  775. media_tbl[dev->if_port].name,
  776. media_status);
  777. } else if (corkscrew_debug > 1)
  778. printk("%s: Media %s is has no link beat, %x.\n",
  779. dev->name,
  780. media_tbl[dev->if_port].name,
  781. media_status);
  782. break;
  783. default: /* Other media types handled by Tx timeouts. */
  784. if (corkscrew_debug > 1)
  785. printk("%s: Media %s is has no indication, %x.\n",
  786. dev->name,
  787. media_tbl[dev->if_port].name,
  788. media_status);
  789. ok = 1;
  790. }
  791. if (!ok) {
  792. __u32 config;
  793. do {
  794. dev->if_port =
  795. media_tbl[dev->if_port].next;
  796. }
  797. while (!(vp->available_media & media_tbl[dev->if_port].mask));
  798. if (dev->if_port == 8) { /* Go back to default. */
  799. dev->if_port = vp->default_media;
  800. if (corkscrew_debug > 1)
  801. printk("%s: Media selection failing, using default %s port.\n",
  802. dev->name,
  803. media_tbl[dev->if_port].name);
  804. } else {
  805. if (corkscrew_debug > 1)
  806. printk("%s: Media selection failed, now trying %s port.\n",
  807. dev->name,
  808. media_tbl[dev->if_port].name);
  809. vp->timer.expires = jiffies + media_tbl[dev->if_port].wait;
  810. add_timer(&vp->timer);
  811. }
  812. outw((media_status & ~(Media_10TP | Media_SQE)) |
  813. media_tbl[dev->if_port].media_bits,
  814. ioaddr + Wn4_Media);
  815. EL3WINDOW(3);
  816. config = inl(ioaddr + Wn3_Config);
  817. config = (config & ~Xcvr) | (dev->if_port << Xcvr_shift);
  818. outl(config, ioaddr + Wn3_Config);
  819. outw(dev->if_port == 3 ? StartCoax : StopCoax,
  820. ioaddr + EL3_CMD);
  821. }
  822. EL3WINDOW(old_window);
  823. }
  824. spin_unlock_irqrestore(&vp->lock, flags);
  825. if (corkscrew_debug > 1)
  826. printk("%s: Media selection timer finished, %s.\n",
  827. dev->name, media_tbl[dev->if_port].name);
  828. #endif /* AUTOMEDIA */
  829. return;
  830. }
  831. static void corkscrew_timeout(struct net_device *dev)
  832. {
  833. int i;
  834. struct corkscrew_private *vp = netdev_priv(dev);
  835. int ioaddr = dev->base_addr;
  836. printk(KERN_WARNING
  837. "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
  838. dev->name, inb(ioaddr + TxStatus),
  839. inw(ioaddr + EL3_STATUS));
  840. /* Slight code bloat to be user friendly. */
  841. if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
  842. printk(KERN_WARNING
  843. "%s: Transmitter encountered 16 collisions -- network"
  844. " network cable problem?\n", dev->name);
  845. #ifndef final_version
  846. printk(" Flags; bus-master %d, full %d; dirty %d current %d.\n",
  847. vp->full_bus_master_tx, vp->tx_full, vp->dirty_tx,
  848. vp->cur_tx);
  849. printk(" Down list %8.8x vs. %p.\n", inl(ioaddr + DownListPtr),
  850. &vp->tx_ring[0]);
  851. for (i = 0; i < TX_RING_SIZE; i++) {
  852. printk(" %d: %p length %8.8x status %8.8x\n", i,
  853. &vp->tx_ring[i],
  854. vp->tx_ring[i].length, vp->tx_ring[i].status);
  855. }
  856. #endif
  857. /* Issue TX_RESET and TX_START commands. */
  858. outw(TxReset, ioaddr + EL3_CMD);
  859. for (i = 20; i >= 0; i--)
  860. if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
  861. break;
  862. outw(TxEnable, ioaddr + EL3_CMD);
  863. dev->trans_start = jiffies;
  864. dev->stats.tx_errors++;
  865. dev->stats.tx_dropped++;
  866. netif_wake_queue(dev);
  867. }
  868. static int corkscrew_start_xmit(struct sk_buff *skb,
  869. struct net_device *dev)
  870. {
  871. struct corkscrew_private *vp = netdev_priv(dev);
  872. int ioaddr = dev->base_addr;
  873. /* Block a timer-based transmit from overlapping. */
  874. netif_stop_queue(dev);
  875. if (vp->full_bus_master_tx) { /* BOOMERANG bus-master */
  876. /* Calculate the next Tx descriptor entry. */
  877. int entry = vp->cur_tx % TX_RING_SIZE;
  878. struct boom_tx_desc *prev_entry;
  879. unsigned long flags;
  880. int i;
  881. if (vp->tx_full) /* No room to transmit with */
  882. return 1;
  883. if (vp->cur_tx != 0)
  884. prev_entry = &vp->tx_ring[(vp->cur_tx - 1) % TX_RING_SIZE];
  885. else
  886. prev_entry = NULL;
  887. if (corkscrew_debug > 3)
  888. printk("%s: Trying to send a packet, Tx index %d.\n",
  889. dev->name, vp->cur_tx);
  890. /* vp->tx_full = 1; */
  891. vp->tx_skbuff[entry] = skb;
  892. vp->tx_ring[entry].next = 0;
  893. vp->tx_ring[entry].addr = isa_virt_to_bus(skb->data);
  894. vp->tx_ring[entry].length = skb->len | 0x80000000;
  895. vp->tx_ring[entry].status = skb->len | 0x80000000;
  896. spin_lock_irqsave(&vp->lock, flags);
  897. outw(DownStall, ioaddr + EL3_CMD);
  898. /* Wait for the stall to complete. */
  899. for (i = 20; i >= 0; i--)
  900. if ((inw(ioaddr + EL3_STATUS) & CmdInProgress) == 0)
  901. break;
  902. if (prev_entry)
  903. prev_entry->next = isa_virt_to_bus(&vp->tx_ring[entry]);
  904. if (inl(ioaddr + DownListPtr) == 0) {
  905. outl(isa_virt_to_bus(&vp->tx_ring[entry]),
  906. ioaddr + DownListPtr);
  907. queued_packet++;
  908. }
  909. outw(DownUnstall, ioaddr + EL3_CMD);
  910. spin_unlock_irqrestore(&vp->lock, flags);
  911. vp->cur_tx++;
  912. if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1)
  913. vp->tx_full = 1;
  914. else { /* Clear previous interrupt enable. */
  915. if (prev_entry)
  916. prev_entry->status &= ~0x80000000;
  917. netif_wake_queue(dev);
  918. }
  919. dev->trans_start = jiffies;
  920. return 0;
  921. }
  922. /* Put out the doubleword header... */
  923. outl(skb->len, ioaddr + TX_FIFO);
  924. dev->stats.tx_bytes += skb->len;
  925. #ifdef VORTEX_BUS_MASTER
  926. if (vp->bus_master) {
  927. /* Set the bus-master controller to transfer the packet. */
  928. outl((int) (skb->data), ioaddr + Wn7_MasterAddr);
  929. outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
  930. vp->tx_skb = skb;
  931. outw(StartDMADown, ioaddr + EL3_CMD);
  932. /* queue will be woken at the DMADone interrupt. */
  933. } else {
  934. /* ... and the packet rounded to a doubleword. */
  935. outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  936. dev_kfree_skb(skb);
  937. if (inw(ioaddr + TxFree) > 1536) {
  938. netif_wake_queue(dev);
  939. } else
  940. /* Interrupt us when the FIFO has room for max-sized packet. */
  941. outw(SetTxThreshold + (1536 >> 2),
  942. ioaddr + EL3_CMD);
  943. }
  944. #else
  945. /* ... and the packet rounded to a doubleword. */
  946. outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  947. dev_kfree_skb(skb);
  948. if (inw(ioaddr + TxFree) > 1536) {
  949. netif_wake_queue(dev);
  950. } else
  951. /* Interrupt us when the FIFO has room for max-sized packet. */
  952. outw(SetTxThreshold + (1536 >> 2), ioaddr + EL3_CMD);
  953. #endif /* bus master */
  954. dev->trans_start = jiffies;
  955. /* Clear the Tx status stack. */
  956. {
  957. short tx_status;
  958. int i = 4;
  959. while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
  960. if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
  961. if (corkscrew_debug > 2)
  962. printk("%s: Tx error, status %2.2x.\n",
  963. dev->name, tx_status);
  964. if (tx_status & 0x04)
  965. dev->stats.tx_fifo_errors++;
  966. if (tx_status & 0x38)
  967. dev->stats.tx_aborted_errors++;
  968. if (tx_status & 0x30) {
  969. int j;
  970. outw(TxReset, ioaddr + EL3_CMD);
  971. for (j = 20; j >= 0; j--)
  972. if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
  973. break;
  974. }
  975. outw(TxEnable, ioaddr + EL3_CMD);
  976. }
  977. outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
  978. }
  979. }
  980. return 0;
  981. }
  982. /* The interrupt handler does all of the Rx thread work and cleans up
  983. after the Tx thread. */
  984. static irqreturn_t corkscrew_interrupt(int irq, void *dev_id)
  985. {
  986. /* Use the now-standard shared IRQ implementation. */
  987. struct net_device *dev = dev_id;
  988. struct corkscrew_private *lp = netdev_priv(dev);
  989. int ioaddr, status;
  990. int latency;
  991. int i = max_interrupt_work;
  992. ioaddr = dev->base_addr;
  993. latency = inb(ioaddr + Timer);
  994. spin_lock(&lp->lock);
  995. status = inw(ioaddr + EL3_STATUS);
  996. if (corkscrew_debug > 4)
  997. printk("%s: interrupt, status %4.4x, timer %d.\n",
  998. dev->name, status, latency);
  999. if ((status & 0xE000) != 0xE000) {
  1000. static int donedidthis;
  1001. /* Some interrupt controllers store a bogus interrupt from boot-time.
  1002. Ignore a single early interrupt, but don't hang the machine for
  1003. other interrupt problems. */
  1004. if (donedidthis++ > 100) {
  1005. printk(KERN_ERR "%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
  1006. dev->name, status, netif_running(dev));
  1007. free_irq(dev->irq, dev);
  1008. dev->irq = -1;
  1009. }
  1010. }
  1011. do {
  1012. if (corkscrew_debug > 5)
  1013. printk("%s: In interrupt loop, status %4.4x.\n",
  1014. dev->name, status);
  1015. if (status & RxComplete)
  1016. corkscrew_rx(dev);
  1017. if (status & TxAvailable) {
  1018. if (corkscrew_debug > 5)
  1019. printk(" TX room bit was handled.\n");
  1020. /* There's room in the FIFO for a full-sized packet. */
  1021. outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
  1022. netif_wake_queue(dev);
  1023. }
  1024. if (status & DownComplete) {
  1025. unsigned int dirty_tx = lp->dirty_tx;
  1026. while (lp->cur_tx - dirty_tx > 0) {
  1027. int entry = dirty_tx % TX_RING_SIZE;
  1028. if (inl(ioaddr + DownListPtr) == isa_virt_to_bus(&lp->tx_ring[entry]))
  1029. break; /* It still hasn't been processed. */
  1030. if (lp->tx_skbuff[entry]) {
  1031. dev_kfree_skb_irq(lp->tx_skbuff[entry]);
  1032. lp->tx_skbuff[entry] = NULL;
  1033. }
  1034. dirty_tx++;
  1035. }
  1036. lp->dirty_tx = dirty_tx;
  1037. outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
  1038. if (lp->tx_full && (lp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
  1039. lp->tx_full = 0;
  1040. netif_wake_queue(dev);
  1041. }
  1042. }
  1043. #ifdef VORTEX_BUS_MASTER
  1044. if (status & DMADone) {
  1045. outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
  1046. dev_kfree_skb_irq(lp->tx_skb); /* Release the transferred buffer */
  1047. netif_wake_queue(dev);
  1048. }
  1049. #endif
  1050. if (status & UpComplete) {
  1051. boomerang_rx(dev);
  1052. outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
  1053. }
  1054. if (status & (AdapterFailure | RxEarly | StatsFull)) {
  1055. /* Handle all uncommon interrupts at once. */
  1056. if (status & RxEarly) { /* Rx early is unused. */
  1057. corkscrew_rx(dev);
  1058. outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
  1059. }
  1060. if (status & StatsFull) { /* Empty statistics. */
  1061. static int DoneDidThat;
  1062. if (corkscrew_debug > 4)
  1063. printk("%s: Updating stats.\n", dev->name);
  1064. update_stats(ioaddr, dev);
  1065. /* DEBUG HACK: Disable statistics as an interrupt source. */
  1066. /* This occurs when we have the wrong media type! */
  1067. if (DoneDidThat == 0 && inw(ioaddr + EL3_STATUS) & StatsFull) {
  1068. int win, reg;
  1069. printk("%s: Updating stats failed, disabling stats as an"
  1070. " interrupt source.\n", dev->name);
  1071. for (win = 0; win < 8; win++) {
  1072. EL3WINDOW(win);
  1073. printk("\n Vortex window %d:", win);
  1074. for (reg = 0; reg < 16; reg++)
  1075. printk(" %2.2x", inb(ioaddr + reg));
  1076. }
  1077. EL3WINDOW(7);
  1078. outw(SetIntrEnb | TxAvailable |
  1079. RxComplete | AdapterFailure |
  1080. UpComplete | DownComplete |
  1081. TxComplete, ioaddr + EL3_CMD);
  1082. DoneDidThat++;
  1083. }
  1084. }
  1085. if (status & AdapterFailure) {
  1086. /* Adapter failure requires Rx reset and reinit. */
  1087. outw(RxReset, ioaddr + EL3_CMD);
  1088. /* Set the Rx filter to the current state. */
  1089. set_rx_mode(dev);
  1090. outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
  1091. outw(AckIntr | AdapterFailure,
  1092. ioaddr + EL3_CMD);
  1093. }
  1094. }
  1095. if (--i < 0) {
  1096. printk(KERN_ERR "%s: Too much work in interrupt, status %4.4x. "
  1097. "Disabling functions (%4.4x).\n", dev->name,
  1098. status, SetStatusEnb | ((~status) & 0x7FE));
  1099. /* Disable all pending interrupts. */
  1100. outw(SetStatusEnb | ((~status) & 0x7FE), ioaddr + EL3_CMD);
  1101. outw(AckIntr | 0x7FF, ioaddr + EL3_CMD);
  1102. break;
  1103. }
  1104. /* Acknowledge the IRQ. */
  1105. outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
  1106. } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
  1107. spin_unlock(&lp->lock);
  1108. if (corkscrew_debug > 4)
  1109. printk("%s: exiting interrupt, status %4.4x.\n", dev->name, status);
  1110. return IRQ_HANDLED;
  1111. }
  1112. static int corkscrew_rx(struct net_device *dev)
  1113. {
  1114. int ioaddr = dev->base_addr;
  1115. int i;
  1116. short rx_status;
  1117. if (corkscrew_debug > 5)
  1118. printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
  1119. inw(ioaddr + EL3_STATUS), inw(ioaddr + RxStatus));
  1120. while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
  1121. if (rx_status & 0x4000) { /* Error, update stats. */
  1122. unsigned char rx_error = inb(ioaddr + RxErrors);
  1123. if (corkscrew_debug > 2)
  1124. printk(" Rx error: status %2.2x.\n",
  1125. rx_error);
  1126. dev->stats.rx_errors++;
  1127. if (rx_error & 0x01)
  1128. dev->stats.rx_over_errors++;
  1129. if (rx_error & 0x02)
  1130. dev->stats.rx_length_errors++;
  1131. if (rx_error & 0x04)
  1132. dev->stats.rx_frame_errors++;
  1133. if (rx_error & 0x08)
  1134. dev->stats.rx_crc_errors++;
  1135. if (rx_error & 0x10)
  1136. dev->stats.rx_length_errors++;
  1137. } else {
  1138. /* The packet length: up to 4.5K!. */
  1139. short pkt_len = rx_status & 0x1fff;
  1140. struct sk_buff *skb;
  1141. skb = dev_alloc_skb(pkt_len + 5 + 2);
  1142. if (corkscrew_debug > 4)
  1143. printk("Receiving packet size %d status %4.4x.\n",
  1144. pkt_len, rx_status);
  1145. if (skb != NULL) {
  1146. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  1147. /* 'skb_put()' points to the start of sk_buff data area. */
  1148. insl(ioaddr + RX_FIFO,
  1149. skb_put(skb, pkt_len),
  1150. (pkt_len + 3) >> 2);
  1151. outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
  1152. skb->protocol = eth_type_trans(skb, dev);
  1153. netif_rx(skb);
  1154. dev->stats.rx_packets++;
  1155. dev->stats.rx_bytes += pkt_len;
  1156. /* Wait a limited time to go to next packet. */
  1157. for (i = 200; i >= 0; i--)
  1158. if (! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
  1159. break;
  1160. continue;
  1161. } else if (corkscrew_debug)
  1162. printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, pkt_len);
  1163. }
  1164. outw(RxDiscard, ioaddr + EL3_CMD);
  1165. dev->stats.rx_dropped++;
  1166. /* Wait a limited time to skip this packet. */
  1167. for (i = 200; i >= 0; i--)
  1168. if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
  1169. break;
  1170. }
  1171. return 0;
  1172. }
  1173. static int boomerang_rx(struct net_device *dev)
  1174. {
  1175. struct corkscrew_private *vp = netdev_priv(dev);
  1176. int entry = vp->cur_rx % RX_RING_SIZE;
  1177. int ioaddr = dev->base_addr;
  1178. int rx_status;
  1179. if (corkscrew_debug > 5)
  1180. printk(" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
  1181. inw(ioaddr + EL3_STATUS), inw(ioaddr + RxStatus));
  1182. while ((rx_status = vp->rx_ring[entry].status) & RxDComplete) {
  1183. if (rx_status & RxDError) { /* Error, update stats. */
  1184. unsigned char rx_error = rx_status >> 16;
  1185. if (corkscrew_debug > 2)
  1186. printk(" Rx error: status %2.2x.\n",
  1187. rx_error);
  1188. dev->stats.rx_errors++;
  1189. if (rx_error & 0x01)
  1190. dev->stats.rx_over_errors++;
  1191. if (rx_error & 0x02)
  1192. dev->stats.rx_length_errors++;
  1193. if (rx_error & 0x04)
  1194. dev->stats.rx_frame_errors++;
  1195. if (rx_error & 0x08)
  1196. dev->stats.rx_crc_errors++;
  1197. if (rx_error & 0x10)
  1198. dev->stats.rx_length_errors++;
  1199. } else {
  1200. /* The packet length: up to 4.5K!. */
  1201. short pkt_len = rx_status & 0x1fff;
  1202. struct sk_buff *skb;
  1203. dev->stats.rx_bytes += pkt_len;
  1204. if (corkscrew_debug > 4)
  1205. printk("Receiving packet size %d status %4.4x.\n",
  1206. pkt_len, rx_status);
  1207. /* Check if the packet is long enough to just accept without
  1208. copying to a properly sized skbuff. */
  1209. if (pkt_len < rx_copybreak
  1210. && (skb = dev_alloc_skb(pkt_len + 4)) != NULL) {
  1211. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  1212. /* 'skb_put()' points to the start of sk_buff data area. */
  1213. memcpy(skb_put(skb, pkt_len),
  1214. isa_bus_to_virt(vp->rx_ring[entry].
  1215. addr), pkt_len);
  1216. rx_copy++;
  1217. } else {
  1218. void *temp;
  1219. /* Pass up the skbuff already on the Rx ring. */
  1220. skb = vp->rx_skbuff[entry];
  1221. vp->rx_skbuff[entry] = NULL;
  1222. temp = skb_put(skb, pkt_len);
  1223. /* Remove this checking code for final release. */
  1224. if (isa_bus_to_virt(vp->rx_ring[entry].addr) != temp)
  1225. printk("%s: Warning -- the skbuff addresses do not match"
  1226. " in boomerang_rx: %p vs. %p / %p.\n",
  1227. dev->name,
  1228. isa_bus_to_virt(vp->
  1229. rx_ring[entry].
  1230. addr), skb->head,
  1231. temp);
  1232. rx_nocopy++;
  1233. }
  1234. skb->protocol = eth_type_trans(skb, dev);
  1235. netif_rx(skb);
  1236. dev->stats.rx_packets++;
  1237. }
  1238. entry = (++vp->cur_rx) % RX_RING_SIZE;
  1239. }
  1240. /* Refill the Rx ring buffers. */
  1241. for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
  1242. struct sk_buff *skb;
  1243. entry = vp->dirty_rx % RX_RING_SIZE;
  1244. if (vp->rx_skbuff[entry] == NULL) {
  1245. skb = dev_alloc_skb(PKT_BUF_SZ);
  1246. if (skb == NULL)
  1247. break; /* Bad news! */
  1248. skb->dev = dev; /* Mark as being used by this device. */
  1249. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  1250. vp->rx_ring[entry].addr = isa_virt_to_bus(skb->data);
  1251. vp->rx_skbuff[entry] = skb;
  1252. }
  1253. vp->rx_ring[entry].status = 0; /* Clear complete bit. */
  1254. }
  1255. return 0;
  1256. }
  1257. static int corkscrew_close(struct net_device *dev)
  1258. {
  1259. struct corkscrew_private *vp = netdev_priv(dev);
  1260. int ioaddr = dev->base_addr;
  1261. int i;
  1262. netif_stop_queue(dev);
  1263. if (corkscrew_debug > 1) {
  1264. printk("%s: corkscrew_close() status %4.4x, Tx status %2.2x.\n",
  1265. dev->name, inw(ioaddr + EL3_STATUS),
  1266. inb(ioaddr + TxStatus));
  1267. printk("%s: corkscrew close stats: rx_nocopy %d rx_copy %d"
  1268. " tx_queued %d.\n", dev->name, rx_nocopy, rx_copy,
  1269. queued_packet);
  1270. }
  1271. del_timer(&vp->timer);
  1272. /* Turn off statistics ASAP. We update lp->stats below. */
  1273. outw(StatsDisable, ioaddr + EL3_CMD);
  1274. /* Disable the receiver and transmitter. */
  1275. outw(RxDisable, ioaddr + EL3_CMD);
  1276. outw(TxDisable, ioaddr + EL3_CMD);
  1277. if (dev->if_port == XCVR_10base2)
  1278. /* Turn off thinnet power. Green! */
  1279. outw(StopCoax, ioaddr + EL3_CMD);
  1280. free_irq(dev->irq, dev);
  1281. outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
  1282. update_stats(ioaddr, dev);
  1283. if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
  1284. outl(0, ioaddr + UpListPtr);
  1285. for (i = 0; i < RX_RING_SIZE; i++)
  1286. if (vp->rx_skbuff[i]) {
  1287. dev_kfree_skb(vp->rx_skbuff[i]);
  1288. vp->rx_skbuff[i] = NULL;
  1289. }
  1290. }
  1291. if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
  1292. outl(0, ioaddr + DownListPtr);
  1293. for (i = 0; i < TX_RING_SIZE; i++)
  1294. if (vp->tx_skbuff[i]) {
  1295. dev_kfree_skb(vp->tx_skbuff[i]);
  1296. vp->tx_skbuff[i] = NULL;
  1297. }
  1298. }
  1299. return 0;
  1300. }
  1301. static struct net_device_stats *corkscrew_get_stats(struct net_device *dev)
  1302. {
  1303. struct corkscrew_private *vp = netdev_priv(dev);
  1304. unsigned long flags;
  1305. if (netif_running(dev)) {
  1306. spin_lock_irqsave(&vp->lock, flags);
  1307. update_stats(dev->base_addr, dev);
  1308. spin_unlock_irqrestore(&vp->lock, flags);
  1309. }
  1310. return &dev->stats;
  1311. }
  1312. /* Update statistics.
  1313. Unlike with the EL3 we need not worry about interrupts changing
  1314. the window setting from underneath us, but we must still guard
  1315. against a race condition with a StatsUpdate interrupt updating the
  1316. table. This is done by checking that the ASM (!) code generated uses
  1317. atomic updates with '+='.
  1318. */
  1319. static void update_stats(int ioaddr, struct net_device *dev)
  1320. {
  1321. /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
  1322. /* Switch to the stats window, and read everything. */
  1323. EL3WINDOW(6);
  1324. dev->stats.tx_carrier_errors += inb(ioaddr + 0);
  1325. dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
  1326. /* Multiple collisions. */ inb(ioaddr + 2);
  1327. dev->stats.collisions += inb(ioaddr + 3);
  1328. dev->stats.tx_window_errors += inb(ioaddr + 4);
  1329. dev->stats.rx_fifo_errors += inb(ioaddr + 5);
  1330. dev->stats.tx_packets += inb(ioaddr + 6);
  1331. dev->stats.tx_packets += (inb(ioaddr + 9) & 0x30) << 4;
  1332. /* Rx packets */ inb(ioaddr + 7);
  1333. /* Must read to clear */
  1334. /* Tx deferrals */ inb(ioaddr + 8);
  1335. /* Don't bother with register 9, an extension of registers 6&7.
  1336. If we do use the 6&7 values the atomic update assumption above
  1337. is invalid. */
  1338. inw(ioaddr + 10); /* Total Rx and Tx octets. */
  1339. inw(ioaddr + 12);
  1340. /* New: On the Vortex we must also clear the BadSSD counter. */
  1341. EL3WINDOW(4);
  1342. inb(ioaddr + 12);
  1343. /* We change back to window 7 (not 1) with the Vortex. */
  1344. EL3WINDOW(7);
  1345. return;
  1346. }
  1347. /* This new version of set_rx_mode() supports v1.4 kernels.
  1348. The Vortex chip has no documented multicast filter, so the only
  1349. multicast setting is to receive all multicast frames. At least
  1350. the chip has a very clean way to set the mode, unlike many others. */
  1351. static void set_rx_mode(struct net_device *dev)
  1352. {
  1353. int ioaddr = dev->base_addr;
  1354. short new_mode;
  1355. if (dev->flags & IFF_PROMISC) {
  1356. if (corkscrew_debug > 3)
  1357. printk("%s: Setting promiscuous mode.\n",
  1358. dev->name);
  1359. new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm;
  1360. } else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
  1361. new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast;
  1362. } else
  1363. new_mode = SetRxFilter | RxStation | RxBroadcast;
  1364. outw(new_mode, ioaddr + EL3_CMD);
  1365. }
  1366. static void netdev_get_drvinfo(struct net_device *dev,
  1367. struct ethtool_drvinfo *info)
  1368. {
  1369. strcpy(info->driver, DRV_NAME);
  1370. strcpy(info->version, DRV_VERSION);
  1371. sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
  1372. }
  1373. static u32 netdev_get_msglevel(struct net_device *dev)
  1374. {
  1375. return corkscrew_debug;
  1376. }
  1377. static void netdev_set_msglevel(struct net_device *dev, u32 level)
  1378. {
  1379. corkscrew_debug = level;
  1380. }
  1381. static const struct ethtool_ops netdev_ethtool_ops = {
  1382. .get_drvinfo = netdev_get_drvinfo,
  1383. .get_msglevel = netdev_get_msglevel,
  1384. .set_msglevel = netdev_set_msglevel,
  1385. };
  1386. #ifdef MODULE
  1387. void cleanup_module(void)
  1388. {
  1389. while (!list_empty(&root_corkscrew_dev)) {
  1390. struct net_device *dev;
  1391. struct corkscrew_private *vp;
  1392. vp = list_entry(root_corkscrew_dev.next,
  1393. struct corkscrew_private, list);
  1394. dev = vp->our_dev;
  1395. unregister_netdev(dev);
  1396. cleanup_card(dev);
  1397. free_netdev(dev);
  1398. }
  1399. }
  1400. #endif /* MODULE */