atarilance.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /* atarilance.c: Ethernet driver for VME Lance cards on the Atari */
  2. /*
  3. Written 1995/96 by Roman Hodek (Roman.Hodek@informatik.uni-erlangen.de)
  4. This software may be used and distributed according to the terms
  5. of the GNU General Public License, incorporated herein by reference.
  6. This drivers was written with the following sources of reference:
  7. - The driver for the Riebl Lance card by the TU Vienna.
  8. - The modified TUW driver for PAM's VME cards
  9. - The PC-Linux driver for Lance cards (but this is for bus master
  10. cards, not the shared memory ones)
  11. - The Amiga Ariadne driver
  12. v1.0: (in 1.2.13pl4/0.9.13)
  13. Initial version
  14. v1.1: (in 1.2.13pl5)
  15. more comments
  16. deleted some debugging stuff
  17. optimized register access (keep AREG pointing to CSR0)
  18. following AMD, CSR0_STRT should be set only after IDON is detected
  19. use memcpy() for data transfers, that also employs long word moves
  20. better probe procedure for 24-bit systems
  21. non-VME-RieblCards need extra delays in memcpy
  22. must also do write test, since 0xfxe00000 may hit ROM
  23. use 8/32 tx/rx buffers, which should give better NFS performance;
  24. this is made possible by shifting the last packet buffer after the
  25. RieblCard reserved area
  26. v1.2: (in 1.2.13pl8)
  27. again fixed probing for the Falcon; 0xfe01000 hits phys. 0x00010000
  28. and thus RAM, in case of no Lance found all memory contents have to
  29. be restored!
  30. Now possible to compile as module.
  31. v1.3: 03/30/96 Jes Sorensen, Roman (in 1.3)
  32. Several little 1.3 adaptions
  33. When the lance is stopped it jumps back into little-endian
  34. mode. It is therefore necessary to put it back where it
  35. belongs, in big endian mode, in order to make things work.
  36. This might be the reason why multicast-mode didn't work
  37. before, but I'm not able to test it as I only got an Amiga
  38. (we had similar problems with the A2065 driver).
  39. */
  40. static const char version[] = "atarilance.c: v1.3 04/04/96 "
  41. "Roman.Hodek@informatik.uni-erlangen.de\n";
  42. #include <linux/netdevice.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/module.h>
  45. #include <linux/stddef.h>
  46. #include <linux/kernel.h>
  47. #include <linux/string.h>
  48. #include <linux/errno.h>
  49. #include <linux/skbuff.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/init.h>
  52. #include <linux/bitops.h>
  53. #include <asm/setup.h>
  54. #include <asm/irq.h>
  55. #include <asm/atarihw.h>
  56. #include <asm/atariints.h>
  57. #include <asm/io.h>
  58. /* Debug level:
  59. * 0 = silent, print only serious errors
  60. * 1 = normal, print error messages
  61. * 2 = debug, print debug infos
  62. * 3 = debug, print even more debug infos (packet data)
  63. */
  64. #define LANCE_DEBUG 1
  65. #ifdef LANCE_DEBUG
  66. static int lance_debug = LANCE_DEBUG;
  67. #else
  68. static int lance_debug = 1;
  69. #endif
  70. module_param(lance_debug, int, 0);
  71. MODULE_PARM_DESC(lance_debug, "atarilance debug level (0-3)");
  72. MODULE_LICENSE("GPL");
  73. /* Print debug messages on probing? */
  74. #undef LANCE_DEBUG_PROBE
  75. #define DPRINTK(n,a) \
  76. do { \
  77. if (lance_debug >= n) \
  78. printk a; \
  79. } while( 0 )
  80. #ifdef LANCE_DEBUG_PROBE
  81. # define PROBE_PRINT(a) printk a
  82. #else
  83. # define PROBE_PRINT(a)
  84. #endif
  85. /* These define the number of Rx and Tx buffers as log2. (Only powers
  86. * of two are valid)
  87. * Much more rx buffers (32) are reserved than tx buffers (8), since receiving
  88. * is more time critical then sending and packets may have to remain in the
  89. * board's memory when main memory is low.
  90. */
  91. #define TX_LOG_RING_SIZE 3
  92. #define RX_LOG_RING_SIZE 5
  93. /* These are the derived values */
  94. #define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
  95. #define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
  96. #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
  97. #define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
  98. #define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
  99. #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
  100. #define TX_TIMEOUT (HZ/5)
  101. /* The LANCE Rx and Tx ring descriptors. */
  102. struct lance_rx_head {
  103. unsigned short base; /* Low word of base addr */
  104. volatile unsigned char flag;
  105. unsigned char base_hi; /* High word of base addr (unused) */
  106. short buf_length; /* This length is 2s complement! */
  107. volatile short msg_length; /* This length is "normal". */
  108. };
  109. struct lance_tx_head {
  110. unsigned short base; /* Low word of base addr */
  111. volatile unsigned char flag;
  112. unsigned char base_hi; /* High word of base addr (unused) */
  113. short length; /* Length is 2s complement! */
  114. volatile short misc;
  115. };
  116. struct ringdesc {
  117. unsigned short adr_lo; /* Low 16 bits of address */
  118. unsigned char len; /* Length bits */
  119. unsigned char adr_hi; /* High 8 bits of address (unused) */
  120. };
  121. /* The LANCE initialization block, described in databook. */
  122. struct lance_init_block {
  123. unsigned short mode; /* Pre-set mode */
  124. unsigned char hwaddr[6]; /* Physical ethernet address */
  125. unsigned filter[2]; /* Multicast filter (unused). */
  126. /* Receive and transmit ring base, along with length bits. */
  127. struct ringdesc rx_ring;
  128. struct ringdesc tx_ring;
  129. };
  130. /* The whole layout of the Lance shared memory */
  131. struct lance_memory {
  132. struct lance_init_block init;
  133. struct lance_tx_head tx_head[TX_RING_SIZE];
  134. struct lance_rx_head rx_head[RX_RING_SIZE];
  135. char packet_area[0]; /* packet data follow after the
  136. * init block and the ring
  137. * descriptors and are located
  138. * at runtime */
  139. };
  140. /* RieblCard specifics:
  141. * The original TOS driver for these cards reserves the area from offset
  142. * 0xee70 to 0xeebb for storing configuration data. Of interest to us is the
  143. * Ethernet address there, and the magic for verifying the data's validity.
  144. * The reserved area isn't touch by packet buffers. Furthermore, offset 0xfffe
  145. * is reserved for the interrupt vector number.
  146. */
  147. #define RIEBL_RSVD_START 0xee70
  148. #define RIEBL_RSVD_END 0xeec0
  149. #define RIEBL_MAGIC 0x09051990
  150. #define RIEBL_MAGIC_ADDR ((unsigned long *)(((char *)MEM) + 0xee8a))
  151. #define RIEBL_HWADDR_ADDR ((unsigned char *)(((char *)MEM) + 0xee8e))
  152. #define RIEBL_IVEC_ADDR ((unsigned short *)(((char *)MEM) + 0xfffe))
  153. /* This is a default address for the old RieblCards without a battery
  154. * that have no ethernet address at boot time. 00:00:36:04 is the
  155. * prefix for Riebl cards, the 00:00 at the end is arbitrary.
  156. */
  157. static unsigned char OldRieblDefHwaddr[6] = {
  158. 0x00, 0x00, 0x36, 0x04, 0x00, 0x00
  159. };
  160. /* I/O registers of the Lance chip */
  161. struct lance_ioreg {
  162. /* base+0x0 */ volatile unsigned short data;
  163. /* base+0x2 */ volatile unsigned short addr;
  164. unsigned char _dummy1[3];
  165. /* base+0x7 */ volatile unsigned char ivec;
  166. unsigned char _dummy2[5];
  167. /* base+0xd */ volatile unsigned char eeprom;
  168. unsigned char _dummy3;
  169. /* base+0xf */ volatile unsigned char mem;
  170. };
  171. /* Types of boards this driver supports */
  172. enum lance_type {
  173. OLD_RIEBL, /* old Riebl card without battery */
  174. NEW_RIEBL, /* new Riebl card with battery */
  175. PAM_CARD /* PAM card with EEPROM */
  176. };
  177. static char *lance_names[] = {
  178. "Riebl-Card (without battery)",
  179. "Riebl-Card (with battery)",
  180. "PAM intern card"
  181. };
  182. /* The driver's private device structure */
  183. struct lance_private {
  184. enum lance_type cardtype;
  185. struct lance_ioreg *iobase;
  186. struct lance_memory *mem;
  187. int cur_rx, cur_tx; /* The next free ring entry */
  188. int dirty_tx; /* Ring entries to be freed. */
  189. /* copy function */
  190. void *(*memcpy_f)( void *, const void *, size_t );
  191. /* This must be long for set_bit() */
  192. long tx_full;
  193. spinlock_t devlock;
  194. };
  195. /* I/O register access macros */
  196. #define MEM lp->mem
  197. #define DREG IO->data
  198. #define AREG IO->addr
  199. #define REGA(a) (*( AREG = (a), &DREG ))
  200. /* Definitions for packet buffer access: */
  201. #define PKT_BUF_SZ 1544
  202. /* Get the address of a packet buffer corresponding to a given buffer head */
  203. #define PKTBUF_ADDR(head) (((unsigned char *)(MEM)) + (head)->base)
  204. /* Possible memory/IO addresses for probing */
  205. static struct lance_addr {
  206. unsigned long memaddr;
  207. unsigned long ioaddr;
  208. int slow_flag;
  209. } lance_addr_list[] = {
  210. { 0xfe010000, 0xfe00fff0, 0 }, /* RieblCard VME in TT */
  211. { 0xffc10000, 0xffc0fff0, 0 }, /* RieblCard VME in MegaSTE
  212. (highest byte stripped) */
  213. { 0xffe00000, 0xffff7000, 1 }, /* RieblCard in ST
  214. (highest byte stripped) */
  215. { 0xffd00000, 0xffff7000, 1 }, /* RieblCard in ST with hw modif. to
  216. avoid conflict with ROM
  217. (highest byte stripped) */
  218. { 0xffcf0000, 0xffcffff0, 0 }, /* PAMCard VME in TT and MSTE
  219. (highest byte stripped) */
  220. { 0xfecf0000, 0xfecffff0, 0 }, /* Rhotron's PAMCard VME in TT and MSTE
  221. (highest byte stripped) */
  222. };
  223. #define N_LANCE_ADDR ARRAY_SIZE(lance_addr_list)
  224. /* Definitions for the Lance */
  225. /* tx_head flags */
  226. #define TMD1_ENP 0x01 /* end of packet */
  227. #define TMD1_STP 0x02 /* start of packet */
  228. #define TMD1_DEF 0x04 /* deferred */
  229. #define TMD1_ONE 0x08 /* one retry needed */
  230. #define TMD1_MORE 0x10 /* more than one retry needed */
  231. #define TMD1_ERR 0x40 /* error summary */
  232. #define TMD1_OWN 0x80 /* ownership (set: chip owns) */
  233. #define TMD1_OWN_CHIP TMD1_OWN
  234. #define TMD1_OWN_HOST 0
  235. /* tx_head misc field */
  236. #define TMD3_TDR 0x03FF /* Time Domain Reflectometry counter */
  237. #define TMD3_RTRY 0x0400 /* failed after 16 retries */
  238. #define TMD3_LCAR 0x0800 /* carrier lost */
  239. #define TMD3_LCOL 0x1000 /* late collision */
  240. #define TMD3_UFLO 0x4000 /* underflow (late memory) */
  241. #define TMD3_BUFF 0x8000 /* buffering error (no ENP) */
  242. /* rx_head flags */
  243. #define RMD1_ENP 0x01 /* end of packet */
  244. #define RMD1_STP 0x02 /* start of packet */
  245. #define RMD1_BUFF 0x04 /* buffer error */
  246. #define RMD1_CRC 0x08 /* CRC error */
  247. #define RMD1_OFLO 0x10 /* overflow */
  248. #define RMD1_FRAM 0x20 /* framing error */
  249. #define RMD1_ERR 0x40 /* error summary */
  250. #define RMD1_OWN 0x80 /* ownership (set: ship owns) */
  251. #define RMD1_OWN_CHIP RMD1_OWN
  252. #define RMD1_OWN_HOST 0
  253. /* register names */
  254. #define CSR0 0 /* mode/status */
  255. #define CSR1 1 /* init block addr (low) */
  256. #define CSR2 2 /* init block addr (high) */
  257. #define CSR3 3 /* misc */
  258. #define CSR8 8 /* address filter */
  259. #define CSR15 15 /* promiscuous mode */
  260. /* CSR0 */
  261. /* (R=readable, W=writeable, S=set on write, C=clear on write) */
  262. #define CSR0_INIT 0x0001 /* initialize (RS) */
  263. #define CSR0_STRT 0x0002 /* start (RS) */
  264. #define CSR0_STOP 0x0004 /* stop (RS) */
  265. #define CSR0_TDMD 0x0008 /* transmit demand (RS) */
  266. #define CSR0_TXON 0x0010 /* transmitter on (R) */
  267. #define CSR0_RXON 0x0020 /* receiver on (R) */
  268. #define CSR0_INEA 0x0040 /* interrupt enable (RW) */
  269. #define CSR0_INTR 0x0080 /* interrupt active (R) */
  270. #define CSR0_IDON 0x0100 /* initialization done (RC) */
  271. #define CSR0_TINT 0x0200 /* transmitter interrupt (RC) */
  272. #define CSR0_RINT 0x0400 /* receiver interrupt (RC) */
  273. #define CSR0_MERR 0x0800 /* memory error (RC) */
  274. #define CSR0_MISS 0x1000 /* missed frame (RC) */
  275. #define CSR0_CERR 0x2000 /* carrier error (no heartbeat :-) (RC) */
  276. #define CSR0_BABL 0x4000 /* babble: tx-ed too many bits (RC) */
  277. #define CSR0_ERR 0x8000 /* error (RC) */
  278. /* CSR3 */
  279. #define CSR3_BCON 0x0001 /* byte control */
  280. #define CSR3_ACON 0x0002 /* ALE control */
  281. #define CSR3_BSWP 0x0004 /* byte swap (1=big endian) */
  282. /***************************** Prototypes *****************************/
  283. static unsigned long lance_probe1( struct net_device *dev, struct lance_addr
  284. *init_rec );
  285. static int lance_open( struct net_device *dev );
  286. static void lance_init_ring( struct net_device *dev );
  287. static netdev_tx_t lance_start_xmit(struct sk_buff *skb,
  288. struct net_device *dev);
  289. static irqreturn_t lance_interrupt( int irq, void *dev_id );
  290. static int lance_rx( struct net_device *dev );
  291. static int lance_close( struct net_device *dev );
  292. static void set_multicast_list( struct net_device *dev );
  293. static int lance_set_mac_address( struct net_device *dev, void *addr );
  294. static void lance_tx_timeout (struct net_device *dev);
  295. /************************* End of Prototypes **************************/
  296. static void *slow_memcpy( void *dst, const void *src, size_t len )
  297. { char *cto = dst;
  298. const char *cfrom = src;
  299. while( len-- ) {
  300. *cto++ = *cfrom++;
  301. MFPDELAY();
  302. }
  303. return dst;
  304. }
  305. struct net_device * __init atarilance_probe(int unit)
  306. {
  307. int i;
  308. static int found;
  309. struct net_device *dev;
  310. int err = -ENODEV;
  311. if (!MACH_IS_ATARI || found)
  312. /* Assume there's only one board possible... That seems true, since
  313. * the Riebl/PAM board's address cannot be changed. */
  314. return ERR_PTR(-ENODEV);
  315. dev = alloc_etherdev(sizeof(struct lance_private));
  316. if (!dev)
  317. return ERR_PTR(-ENOMEM);
  318. if (unit >= 0) {
  319. sprintf(dev->name, "eth%d", unit);
  320. netdev_boot_setup_check(dev);
  321. }
  322. for( i = 0; i < N_LANCE_ADDR; ++i ) {
  323. if (lance_probe1( dev, &lance_addr_list[i] )) {
  324. found = 1;
  325. err = register_netdev(dev);
  326. if (!err)
  327. return dev;
  328. free_irq(dev->irq, dev);
  329. break;
  330. }
  331. }
  332. free_netdev(dev);
  333. return ERR_PTR(err);
  334. }
  335. /* Derived from hwreg_present() in atari/config.c: */
  336. static noinline int __init addr_accessible(volatile void *regp, int wordflag,
  337. int writeflag)
  338. {
  339. int ret;
  340. unsigned long flags;
  341. long *vbr, save_berr;
  342. local_irq_save(flags);
  343. __asm__ __volatile__ ( "movec %/vbr,%0" : "=r" (vbr) : );
  344. save_berr = vbr[2];
  345. __asm__ __volatile__
  346. ( "movel %/sp,%/d1\n\t"
  347. "movel #Lberr,%2@\n\t"
  348. "moveq #0,%0\n\t"
  349. "tstl %3\n\t"
  350. "bne 1f\n\t"
  351. "moveb %1@,%/d0\n\t"
  352. "nop \n\t"
  353. "bra 2f\n"
  354. "1: movew %1@,%/d0\n\t"
  355. "nop \n"
  356. "2: tstl %4\n\t"
  357. "beq 2f\n\t"
  358. "tstl %3\n\t"
  359. "bne 1f\n\t"
  360. "clrb %1@\n\t"
  361. "nop \n\t"
  362. "moveb %/d0,%1@\n\t"
  363. "nop \n\t"
  364. "bra 2f\n"
  365. "1: clrw %1@\n\t"
  366. "nop \n\t"
  367. "movew %/d0,%1@\n\t"
  368. "nop \n"
  369. "2: moveq #1,%0\n"
  370. "Lberr: movel %/d1,%/sp"
  371. : "=&d" (ret)
  372. : "a" (regp), "a" (&vbr[2]), "rm" (wordflag), "rm" (writeflag)
  373. : "d0", "d1", "memory"
  374. );
  375. vbr[2] = save_berr;
  376. local_irq_restore(flags);
  377. return ret;
  378. }
  379. static const struct net_device_ops lance_netdev_ops = {
  380. .ndo_open = lance_open,
  381. .ndo_stop = lance_close,
  382. .ndo_start_xmit = lance_start_xmit,
  383. .ndo_set_rx_mode = set_multicast_list,
  384. .ndo_set_mac_address = lance_set_mac_address,
  385. .ndo_tx_timeout = lance_tx_timeout,
  386. .ndo_validate_addr = eth_validate_addr,
  387. };
  388. static unsigned long __init lance_probe1( struct net_device *dev,
  389. struct lance_addr *init_rec )
  390. {
  391. volatile unsigned short *memaddr =
  392. (volatile unsigned short *)init_rec->memaddr;
  393. volatile unsigned short *ioaddr =
  394. (volatile unsigned short *)init_rec->ioaddr;
  395. struct lance_private *lp;
  396. struct lance_ioreg *IO;
  397. int i;
  398. static int did_version;
  399. unsigned short save1, save2;
  400. PROBE_PRINT(( "Probing for Lance card at mem %#lx io %#lx\n",
  401. (long)memaddr, (long)ioaddr ));
  402. /* Test whether memory readable and writable */
  403. PROBE_PRINT(( "lance_probe1: testing memory to be accessible\n" ));
  404. if (!addr_accessible( memaddr, 1, 1 )) goto probe_fail;
  405. /* Written values should come back... */
  406. PROBE_PRINT(( "lance_probe1: testing memory to be writable (1)\n" ));
  407. save1 = *memaddr;
  408. *memaddr = 0x0001;
  409. if (*memaddr != 0x0001) goto probe_fail;
  410. PROBE_PRINT(( "lance_probe1: testing memory to be writable (2)\n" ));
  411. *memaddr = 0x0000;
  412. if (*memaddr != 0x0000) goto probe_fail;
  413. *memaddr = save1;
  414. /* First port should be readable and writable */
  415. PROBE_PRINT(( "lance_probe1: testing ioport to be accessible\n" ));
  416. if (!addr_accessible( ioaddr, 1, 1 )) goto probe_fail;
  417. /* and written values should be readable */
  418. PROBE_PRINT(( "lance_probe1: testing ioport to be writeable\n" ));
  419. save2 = ioaddr[1];
  420. ioaddr[1] = 0x0001;
  421. if (ioaddr[1] != 0x0001) goto probe_fail;
  422. /* The CSR0_INIT bit should not be readable */
  423. PROBE_PRINT(( "lance_probe1: testing CSR0 register function (1)\n" ));
  424. save1 = ioaddr[0];
  425. ioaddr[1] = CSR0;
  426. ioaddr[0] = CSR0_INIT | CSR0_STOP;
  427. if (ioaddr[0] != CSR0_STOP) {
  428. ioaddr[0] = save1;
  429. ioaddr[1] = save2;
  430. goto probe_fail;
  431. }
  432. PROBE_PRINT(( "lance_probe1: testing CSR0 register function (2)\n" ));
  433. ioaddr[0] = CSR0_STOP;
  434. if (ioaddr[0] != CSR0_STOP) {
  435. ioaddr[0] = save1;
  436. ioaddr[1] = save2;
  437. goto probe_fail;
  438. }
  439. /* Now ok... */
  440. PROBE_PRINT(( "lance_probe1: Lance card detected\n" ));
  441. goto probe_ok;
  442. probe_fail:
  443. return 0;
  444. probe_ok:
  445. lp = netdev_priv(dev);
  446. MEM = (struct lance_memory *)memaddr;
  447. IO = lp->iobase = (struct lance_ioreg *)ioaddr;
  448. dev->base_addr = (unsigned long)ioaddr; /* informational only */
  449. lp->memcpy_f = init_rec->slow_flag ? slow_memcpy : memcpy;
  450. REGA( CSR0 ) = CSR0_STOP;
  451. /* Now test for type: If the eeprom I/O port is readable, it is a
  452. * PAM card */
  453. if (addr_accessible( &(IO->eeprom), 0, 0 )) {
  454. /* Switch back to Ram */
  455. i = IO->mem;
  456. lp->cardtype = PAM_CARD;
  457. }
  458. else if (*RIEBL_MAGIC_ADDR == RIEBL_MAGIC) {
  459. lp->cardtype = NEW_RIEBL;
  460. }
  461. else
  462. lp->cardtype = OLD_RIEBL;
  463. if (lp->cardtype == PAM_CARD ||
  464. memaddr == (unsigned short *)0xffe00000) {
  465. /* PAMs card and Riebl on ST use level 5 autovector */
  466. if (request_irq(IRQ_AUTO_5, lance_interrupt, 0,
  467. "PAM,Riebl-ST Ethernet", dev)) {
  468. printk( "Lance: request for irq %d failed\n", IRQ_AUTO_5 );
  469. return 0;
  470. }
  471. dev->irq = IRQ_AUTO_5;
  472. }
  473. else {
  474. /* For VME-RieblCards, request a free VME int */
  475. unsigned int irq = atari_register_vme_int();
  476. if (!irq) {
  477. printk( "Lance: request for VME interrupt failed\n" );
  478. return 0;
  479. }
  480. if (request_irq(irq, lance_interrupt, 0, "Riebl-VME Ethernet",
  481. dev)) {
  482. printk( "Lance: request for irq %u failed\n", irq );
  483. return 0;
  484. }
  485. dev->irq = irq;
  486. }
  487. printk("%s: %s at io %#lx, mem %#lx, irq %d%s, hwaddr ",
  488. dev->name, lance_names[lp->cardtype],
  489. (unsigned long)ioaddr,
  490. (unsigned long)memaddr,
  491. dev->irq,
  492. init_rec->slow_flag ? " (slow memcpy)" : "" );
  493. /* Get the ethernet address */
  494. switch( lp->cardtype ) {
  495. case OLD_RIEBL:
  496. /* No ethernet address! (Set some default address) */
  497. memcpy(dev->dev_addr, OldRieblDefHwaddr, ETH_ALEN);
  498. break;
  499. case NEW_RIEBL:
  500. lp->memcpy_f(dev->dev_addr, RIEBL_HWADDR_ADDR, ETH_ALEN);
  501. break;
  502. case PAM_CARD:
  503. i = IO->eeprom;
  504. for( i = 0; i < 6; ++i )
  505. dev->dev_addr[i] =
  506. ((((unsigned short *)MEM)[i*2] & 0x0f) << 4) |
  507. ((((unsigned short *)MEM)[i*2+1] & 0x0f));
  508. i = IO->mem;
  509. break;
  510. }
  511. printk("%pM\n", dev->dev_addr);
  512. if (lp->cardtype == OLD_RIEBL) {
  513. printk( "%s: Warning: This is a default ethernet address!\n",
  514. dev->name );
  515. printk( " Use \"ifconfig hw ether ...\" to set the address.\n" );
  516. }
  517. spin_lock_init(&lp->devlock);
  518. MEM->init.mode = 0x0000; /* Disable Rx and Tx. */
  519. for( i = 0; i < 6; i++ )
  520. MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */
  521. MEM->init.filter[0] = 0x00000000;
  522. MEM->init.filter[1] = 0x00000000;
  523. MEM->init.rx_ring.adr_lo = offsetof( struct lance_memory, rx_head );
  524. MEM->init.rx_ring.adr_hi = 0;
  525. MEM->init.rx_ring.len = RX_RING_LEN_BITS;
  526. MEM->init.tx_ring.adr_lo = offsetof( struct lance_memory, tx_head );
  527. MEM->init.tx_ring.adr_hi = 0;
  528. MEM->init.tx_ring.len = TX_RING_LEN_BITS;
  529. if (lp->cardtype == PAM_CARD)
  530. IO->ivec = IRQ_SOURCE_TO_VECTOR(dev->irq);
  531. else
  532. *RIEBL_IVEC_ADDR = IRQ_SOURCE_TO_VECTOR(dev->irq);
  533. if (did_version++ == 0)
  534. DPRINTK( 1, ( version ));
  535. dev->netdev_ops = &lance_netdev_ops;
  536. /* XXX MSch */
  537. dev->watchdog_timeo = TX_TIMEOUT;
  538. return 1;
  539. }
  540. static int lance_open( struct net_device *dev )
  541. {
  542. struct lance_private *lp = netdev_priv(dev);
  543. struct lance_ioreg *IO = lp->iobase;
  544. int i;
  545. DPRINTK( 2, ( "%s: lance_open()\n", dev->name ));
  546. lance_init_ring(dev);
  547. /* Re-initialize the LANCE, and start it when done. */
  548. REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
  549. REGA( CSR2 ) = 0;
  550. REGA( CSR1 ) = 0;
  551. REGA( CSR0 ) = CSR0_INIT;
  552. /* From now on, AREG is kept to point to CSR0 */
  553. i = 1000000;
  554. while (--i > 0)
  555. if (DREG & CSR0_IDON)
  556. break;
  557. if (i <= 0 || (DREG & CSR0_ERR)) {
  558. DPRINTK( 2, ( "lance_open(): opening %s failed, i=%d, csr0=%04x\n",
  559. dev->name, i, DREG ));
  560. DREG = CSR0_STOP;
  561. return -EIO;
  562. }
  563. DREG = CSR0_IDON;
  564. DREG = CSR0_STRT;
  565. DREG = CSR0_INEA;
  566. netif_start_queue (dev);
  567. DPRINTK( 2, ( "%s: LANCE is open, csr0 %04x\n", dev->name, DREG ));
  568. return 0;
  569. }
  570. /* Initialize the LANCE Rx and Tx rings. */
  571. static void lance_init_ring( struct net_device *dev )
  572. {
  573. struct lance_private *lp = netdev_priv(dev);
  574. int i;
  575. unsigned offset;
  576. lp->tx_full = 0;
  577. lp->cur_rx = lp->cur_tx = 0;
  578. lp->dirty_tx = 0;
  579. offset = offsetof( struct lance_memory, packet_area );
  580. /* If the packet buffer at offset 'o' would conflict with the reserved area
  581. * of RieblCards, advance it */
  582. #define CHECK_OFFSET(o) \
  583. do { \
  584. if (lp->cardtype == OLD_RIEBL || lp->cardtype == NEW_RIEBL) { \
  585. if (((o) < RIEBL_RSVD_START) ? (o)+PKT_BUF_SZ > RIEBL_RSVD_START \
  586. : (o) < RIEBL_RSVD_END) \
  587. (o) = RIEBL_RSVD_END; \
  588. } \
  589. } while(0)
  590. for( i = 0; i < TX_RING_SIZE; i++ ) {
  591. CHECK_OFFSET(offset);
  592. MEM->tx_head[i].base = offset;
  593. MEM->tx_head[i].flag = TMD1_OWN_HOST;
  594. MEM->tx_head[i].base_hi = 0;
  595. MEM->tx_head[i].length = 0;
  596. MEM->tx_head[i].misc = 0;
  597. offset += PKT_BUF_SZ;
  598. }
  599. for( i = 0; i < RX_RING_SIZE; i++ ) {
  600. CHECK_OFFSET(offset);
  601. MEM->rx_head[i].base = offset;
  602. MEM->rx_head[i].flag = TMD1_OWN_CHIP;
  603. MEM->rx_head[i].base_hi = 0;
  604. MEM->rx_head[i].buf_length = -PKT_BUF_SZ;
  605. MEM->rx_head[i].msg_length = 0;
  606. offset += PKT_BUF_SZ;
  607. }
  608. }
  609. /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
  610. static void lance_tx_timeout (struct net_device *dev)
  611. {
  612. struct lance_private *lp = netdev_priv(dev);
  613. struct lance_ioreg *IO = lp->iobase;
  614. AREG = CSR0;
  615. DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",
  616. dev->name, DREG ));
  617. DREG = CSR0_STOP;
  618. /*
  619. * Always set BSWP after a STOP as STOP puts it back into
  620. * little endian mode.
  621. */
  622. REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
  623. dev->stats.tx_errors++;
  624. #ifndef final_version
  625. { int i;
  626. DPRINTK( 2, ( "Ring data: dirty_tx %d cur_tx %d%s cur_rx %d\n",
  627. lp->dirty_tx, lp->cur_tx,
  628. lp->tx_full ? " (full)" : "",
  629. lp->cur_rx ));
  630. for( i = 0 ; i < RX_RING_SIZE; i++ )
  631. DPRINTK( 2, ( "rx #%d: base=%04x blen=%04x mlen=%04x\n",
  632. i, MEM->rx_head[i].base,
  633. -MEM->rx_head[i].buf_length,
  634. MEM->rx_head[i].msg_length ));
  635. for( i = 0 ; i < TX_RING_SIZE; i++ )
  636. DPRINTK( 2, ( "tx #%d: base=%04x len=%04x misc=%04x\n",
  637. i, MEM->tx_head[i].base,
  638. -MEM->tx_head[i].length,
  639. MEM->tx_head[i].misc ));
  640. }
  641. #endif
  642. /* XXX MSch: maybe purge/reinit ring here */
  643. /* lance_restart, essentially */
  644. lance_init_ring(dev);
  645. REGA( CSR0 ) = CSR0_INEA | CSR0_INIT | CSR0_STRT;
  646. netif_trans_update(dev); /* prevent tx timeout */
  647. netif_wake_queue(dev);
  648. }
  649. /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
  650. static netdev_tx_t
  651. lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
  652. {
  653. struct lance_private *lp = netdev_priv(dev);
  654. struct lance_ioreg *IO = lp->iobase;
  655. int entry, len;
  656. struct lance_tx_head *head;
  657. unsigned long flags;
  658. DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",
  659. dev->name, DREG ));
  660. /* The old LANCE chips doesn't automatically pad buffers to min. size. */
  661. len = skb->len;
  662. if (len < ETH_ZLEN)
  663. len = ETH_ZLEN;
  664. /* PAM-Card has a bug: Can only send packets with even number of bytes! */
  665. else if (lp->cardtype == PAM_CARD && (len & 1))
  666. ++len;
  667. if (len > skb->len) {
  668. if (skb_padto(skb, len))
  669. return NETDEV_TX_OK;
  670. }
  671. netif_stop_queue (dev);
  672. /* Fill in a Tx ring entry */
  673. if (lance_debug >= 3) {
  674. printk( "%s: TX pkt type 0x%04x from %pM to %pM"
  675. " data at 0x%08x len %d\n",
  676. dev->name, ((u_short *)skb->data)[6],
  677. &skb->data[6], skb->data,
  678. (int)skb->data, (int)skb->len );
  679. }
  680. /* We're not prepared for the int until the last flags are set/reset. And
  681. * the int may happen already after setting the OWN_CHIP... */
  682. spin_lock_irqsave (&lp->devlock, flags);
  683. /* Mask to ring buffer boundary. */
  684. entry = lp->cur_tx & TX_RING_MOD_MASK;
  685. head = &(MEM->tx_head[entry]);
  686. /* Caution: the write order is important here, set the "ownership" bits
  687. * last.
  688. */
  689. head->length = -len;
  690. head->misc = 0;
  691. lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );
  692. head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;
  693. dev->stats.tx_bytes += skb->len;
  694. dev_kfree_skb( skb );
  695. lp->cur_tx++;
  696. while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {
  697. lp->cur_tx -= TX_RING_SIZE;
  698. lp->dirty_tx -= TX_RING_SIZE;
  699. }
  700. /* Trigger an immediate send poll. */
  701. DREG = CSR0_INEA | CSR0_TDMD;
  702. if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==
  703. TMD1_OWN_HOST)
  704. netif_start_queue (dev);
  705. else
  706. lp->tx_full = 1;
  707. spin_unlock_irqrestore (&lp->devlock, flags);
  708. return NETDEV_TX_OK;
  709. }
  710. /* The LANCE interrupt handler. */
  711. static irqreturn_t lance_interrupt( int irq, void *dev_id )
  712. {
  713. struct net_device *dev = dev_id;
  714. struct lance_private *lp;
  715. struct lance_ioreg *IO;
  716. int csr0, boguscnt = 10;
  717. int handled = 0;
  718. if (dev == NULL) {
  719. DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" ));
  720. return IRQ_NONE;
  721. }
  722. lp = netdev_priv(dev);
  723. IO = lp->iobase;
  724. spin_lock (&lp->devlock);
  725. AREG = CSR0;
  726. while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) &&
  727. --boguscnt >= 0) {
  728. handled = 1;
  729. /* Acknowledge all of the current interrupt sources ASAP. */
  730. DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP |
  731. CSR0_TDMD | CSR0_INEA);
  732. DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n",
  733. dev->name, csr0, DREG ));
  734. if (csr0 & CSR0_RINT) /* Rx interrupt */
  735. lance_rx( dev );
  736. if (csr0 & CSR0_TINT) { /* Tx-done interrupt */
  737. int dirty_tx = lp->dirty_tx;
  738. while( dirty_tx < lp->cur_tx) {
  739. int entry = dirty_tx & TX_RING_MOD_MASK;
  740. int status = MEM->tx_head[entry].flag;
  741. if (status & TMD1_OWN_CHIP)
  742. break; /* It still hasn't been Txed */
  743. MEM->tx_head[entry].flag = 0;
  744. if (status & TMD1_ERR) {
  745. /* There was an major error, log it. */
  746. int err_status = MEM->tx_head[entry].misc;
  747. dev->stats.tx_errors++;
  748. if (err_status & TMD3_RTRY) dev->stats.tx_aborted_errors++;
  749. if (err_status & TMD3_LCAR) dev->stats.tx_carrier_errors++;
  750. if (err_status & TMD3_LCOL) dev->stats.tx_window_errors++;
  751. if (err_status & TMD3_UFLO) {
  752. /* Ackk! On FIFO errors the Tx unit is turned off! */
  753. dev->stats.tx_fifo_errors++;
  754. /* Remove this verbosity later! */
  755. DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n",
  756. dev->name, csr0 ));
  757. /* Restart the chip. */
  758. DREG = CSR0_STRT;
  759. }
  760. } else {
  761. if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF))
  762. dev->stats.collisions++;
  763. dev->stats.tx_packets++;
  764. }
  765. /* XXX MSch: free skb?? */
  766. dirty_tx++;
  767. }
  768. #ifndef final_version
  769. if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
  770. DPRINTK( 0, ( "out-of-sync dirty pointer,"
  771. " %d vs. %d, full=%ld.\n",
  772. dirty_tx, lp->cur_tx, lp->tx_full ));
  773. dirty_tx += TX_RING_SIZE;
  774. }
  775. #endif
  776. if (lp->tx_full && (netif_queue_stopped(dev)) &&
  777. dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
  778. /* The ring is no longer full, clear tbusy. */
  779. lp->tx_full = 0;
  780. netif_wake_queue (dev);
  781. }
  782. lp->dirty_tx = dirty_tx;
  783. }
  784. /* Log misc errors. */
  785. if (csr0 & CSR0_BABL) dev->stats.tx_errors++; /* Tx babble. */
  786. if (csr0 & CSR0_MISS) dev->stats.rx_errors++; /* Missed a Rx frame. */
  787. if (csr0 & CSR0_MERR) {
  788. DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "
  789. "status %04x.\n", dev->name, csr0 ));
  790. /* Restart the chip. */
  791. DREG = CSR0_STRT;
  792. }
  793. }
  794. /* Clear any other interrupt, and set interrupt enable. */
  795. DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |
  796. CSR0_IDON | CSR0_INEA;
  797. DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",
  798. dev->name, DREG ));
  799. spin_unlock (&lp->devlock);
  800. return IRQ_RETVAL(handled);
  801. }
  802. static int lance_rx( struct net_device *dev )
  803. {
  804. struct lance_private *lp = netdev_priv(dev);
  805. int entry = lp->cur_rx & RX_RING_MOD_MASK;
  806. int i;
  807. DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name,
  808. MEM->rx_head[entry].flag ));
  809. /* If we own the next entry, it's a new packet. Send it up. */
  810. while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) {
  811. struct lance_rx_head *head = &(MEM->rx_head[entry]);
  812. int status = head->flag;
  813. if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */
  814. /* There is a tricky error noted by John Murphy,
  815. <murf@perftech.com> to Russ Nelson: Even with full-sized
  816. buffers it's possible for a jabber packet to use two
  817. buffers, with only the last correctly noting the error. */
  818. if (status & RMD1_ENP) /* Only count a general error at the */
  819. dev->stats.rx_errors++; /* end of a packet.*/
  820. if (status & RMD1_FRAM) dev->stats.rx_frame_errors++;
  821. if (status & RMD1_OFLO) dev->stats.rx_over_errors++;
  822. if (status & RMD1_CRC) dev->stats.rx_crc_errors++;
  823. if (status & RMD1_BUFF) dev->stats.rx_fifo_errors++;
  824. head->flag &= (RMD1_ENP|RMD1_STP);
  825. } else {
  826. /* Malloc up new buffer, compatible with net-3. */
  827. short pkt_len = head->msg_length & 0xfff;
  828. struct sk_buff *skb;
  829. if (pkt_len < 60) {
  830. printk( "%s: Runt packet!\n", dev->name );
  831. dev->stats.rx_errors++;
  832. }
  833. else {
  834. skb = netdev_alloc_skb(dev, pkt_len + 2);
  835. if (skb == NULL) {
  836. for( i = 0; i < RX_RING_SIZE; i++ )
  837. if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag &
  838. RMD1_OWN_CHIP)
  839. break;
  840. if (i > RX_RING_SIZE - 2) {
  841. dev->stats.rx_dropped++;
  842. head->flag |= RMD1_OWN_CHIP;
  843. lp->cur_rx++;
  844. }
  845. break;
  846. }
  847. if (lance_debug >= 3) {
  848. u_char *data = PKTBUF_ADDR(head);
  849. printk(KERN_DEBUG "%s: RX pkt type 0x%04x from %pM to %pM "
  850. "data %8ph len %d\n",
  851. dev->name, ((u_short *)data)[6],
  852. &data[6], data, &data[15], pkt_len);
  853. }
  854. skb_reserve( skb, 2 ); /* 16 byte align */
  855. skb_put( skb, pkt_len ); /* Make room */
  856. lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len );
  857. skb->protocol = eth_type_trans( skb, dev );
  858. netif_rx( skb );
  859. dev->stats.rx_packets++;
  860. dev->stats.rx_bytes += pkt_len;
  861. }
  862. }
  863. head->flag |= RMD1_OWN_CHIP;
  864. entry = (++lp->cur_rx) & RX_RING_MOD_MASK;
  865. }
  866. lp->cur_rx &= RX_RING_MOD_MASK;
  867. /* From lance.c (Donald Becker): */
  868. /* We should check that at least two ring entries are free. If not,
  869. we should free one and mark stats->rx_dropped++. */
  870. return 0;
  871. }
  872. static int lance_close( struct net_device *dev )
  873. {
  874. struct lance_private *lp = netdev_priv(dev);
  875. struct lance_ioreg *IO = lp->iobase;
  876. netif_stop_queue (dev);
  877. AREG = CSR0;
  878. DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
  879. dev->name, DREG ));
  880. /* We stop the LANCE here -- it occasionally polls
  881. memory if we don't. */
  882. DREG = CSR0_STOP;
  883. return 0;
  884. }
  885. /* Set or clear the multicast filter for this adaptor.
  886. num_addrs == -1 Promiscuous mode, receive all packets
  887. num_addrs == 0 Normal mode, clear multicast list
  888. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  889. best-effort filtering.
  890. */
  891. static void set_multicast_list( struct net_device *dev )
  892. {
  893. struct lance_private *lp = netdev_priv(dev);
  894. struct lance_ioreg *IO = lp->iobase;
  895. if (netif_running(dev))
  896. /* Only possible if board is already started */
  897. return;
  898. /* We take the simple way out and always enable promiscuous mode. */
  899. DREG = CSR0_STOP; /* Temporarily stop the lance. */
  900. if (dev->flags & IFF_PROMISC) {
  901. /* Log any net taps. */
  902. DPRINTK( 2, ( "%s: Promiscuous mode enabled.\n", dev->name ));
  903. REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */
  904. } else {
  905. short multicast_table[4];
  906. int num_addrs = netdev_mc_count(dev);
  907. int i;
  908. /* We don't use the multicast table, but rely on upper-layer
  909. * filtering. */
  910. memset( multicast_table, (num_addrs == 0) ? 0 : -1,
  911. sizeof(multicast_table) );
  912. for( i = 0; i < 4; i++ )
  913. REGA( CSR8+i ) = multicast_table[i];
  914. REGA( CSR15 ) = 0; /* Unset promiscuous mode */
  915. }
  916. /*
  917. * Always set BSWP after a STOP as STOP puts it back into
  918. * little endian mode.
  919. */
  920. REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
  921. /* Resume normal operation and reset AREG to CSR0 */
  922. REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;
  923. }
  924. /* This is needed for old RieblCards and possible for new RieblCards */
  925. static int lance_set_mac_address( struct net_device *dev, void *addr )
  926. {
  927. struct lance_private *lp = netdev_priv(dev);
  928. struct sockaddr *saddr = addr;
  929. int i;
  930. if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL)
  931. return -EOPNOTSUPP;
  932. if (netif_running(dev)) {
  933. /* Only possible while card isn't started */
  934. DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n",
  935. dev->name ));
  936. return -EIO;
  937. }
  938. memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );
  939. for( i = 0; i < 6; i++ )
  940. MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */
  941. lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 );
  942. /* set also the magic for future sessions */
  943. *RIEBL_MAGIC_ADDR = RIEBL_MAGIC;
  944. return 0;
  945. }
  946. #ifdef MODULE
  947. static struct net_device *atarilance_dev;
  948. static int __init atarilance_module_init(void)
  949. {
  950. atarilance_dev = atarilance_probe(-1);
  951. return PTR_ERR_OR_ZERO(atarilance_dev);
  952. }
  953. static void __exit atarilance_module_exit(void)
  954. {
  955. unregister_netdev(atarilance_dev);
  956. free_irq(atarilance_dev->irq, atarilance_dev);
  957. free_netdev(atarilance_dev);
  958. }
  959. module_init(atarilance_module_init);
  960. module_exit(atarilance_module_exit);
  961. #endif /* MODULE */
  962. /*
  963. * Local variables:
  964. * c-indent-level: 4
  965. * tab-width: 4
  966. * End:
  967. */