3c515.c 49 KB

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