atarilance.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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 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 int lance_start_xmit( struct sk_buff *skb, struct net_device *dev );
  288. static irqreturn_t lance_interrupt( int irq, void *dev_id );
  289. static int lance_rx( struct net_device *dev );
  290. static int lance_close( struct net_device *dev );
  291. static void set_multicast_list( struct net_device *dev );
  292. static int lance_set_mac_address( struct net_device *dev, void *addr );
  293. static void lance_tx_timeout (struct net_device *dev);
  294. /************************* End of Prototypes **************************/
  295. static void *slow_memcpy( void *dst, const void *src, size_t len )
  296. { char *cto = dst;
  297. const char *cfrom = src;
  298. while( len-- ) {
  299. *cto++ = *cfrom++;
  300. MFPDELAY();
  301. }
  302. return dst;
  303. }
  304. struct net_device * __init atarilance_probe(int unit)
  305. {
  306. int i;
  307. static int found;
  308. struct net_device *dev;
  309. int err = -ENODEV;
  310. if (!MACH_IS_ATARI || found)
  311. /* Assume there's only one board possible... That seems true, since
  312. * the Riebl/PAM board's address cannot be changed. */
  313. return ERR_PTR(-ENODEV);
  314. dev = alloc_etherdev(sizeof(struct lance_private));
  315. if (!dev)
  316. return ERR_PTR(-ENOMEM);
  317. if (unit >= 0) {
  318. sprintf(dev->name, "eth%d", unit);
  319. netdev_boot_setup_check(dev);
  320. }
  321. for( i = 0; i < N_LANCE_ADDR; ++i ) {
  322. if (lance_probe1( dev, &lance_addr_list[i] )) {
  323. found = 1;
  324. err = register_netdev(dev);
  325. if (!err)
  326. return dev;
  327. free_irq(dev->irq, dev);
  328. break;
  329. }
  330. }
  331. free_netdev(dev);
  332. return ERR_PTR(err);
  333. }
  334. /* Derived from hwreg_present() in atari/config.c: */
  335. static noinline int __init addr_accessible(volatile void *regp, int wordflag,
  336. int writeflag)
  337. {
  338. int ret;
  339. unsigned long flags;
  340. long *vbr, save_berr;
  341. local_irq_save(flags);
  342. __asm__ __volatile__ ( "movec %/vbr,%0" : "=r" (vbr) : );
  343. save_berr = vbr[2];
  344. __asm__ __volatile__
  345. ( "movel %/sp,%/d1\n\t"
  346. "movel #Lberr,%2@\n\t"
  347. "moveq #0,%0\n\t"
  348. "tstl %3\n\t"
  349. "bne 1f\n\t"
  350. "moveb %1@,%/d0\n\t"
  351. "nop \n\t"
  352. "bra 2f\n"
  353. "1: movew %1@,%/d0\n\t"
  354. "nop \n"
  355. "2: tstl %4\n\t"
  356. "beq 2f\n\t"
  357. "tstl %3\n\t"
  358. "bne 1f\n\t"
  359. "clrb %1@\n\t"
  360. "nop \n\t"
  361. "moveb %/d0,%1@\n\t"
  362. "nop \n\t"
  363. "bra 2f\n"
  364. "1: clrw %1@\n\t"
  365. "nop \n\t"
  366. "movew %/d0,%1@\n\t"
  367. "nop \n"
  368. "2: moveq #1,%0\n"
  369. "Lberr: movel %/d1,%/sp"
  370. : "=&d" (ret)
  371. : "a" (regp), "a" (&vbr[2]), "rm" (wordflag), "rm" (writeflag)
  372. : "d0", "d1", "memory"
  373. );
  374. vbr[2] = save_berr;
  375. local_irq_restore(flags);
  376. return ret;
  377. }
  378. static const struct net_device_ops lance_netdev_ops = {
  379. .ndo_open = lance_open,
  380. .ndo_stop = lance_close,
  381. .ndo_start_xmit = lance_start_xmit,
  382. .ndo_set_rx_mode = set_multicast_list,
  383. .ndo_set_mac_address = lance_set_mac_address,
  384. .ndo_tx_timeout = lance_tx_timeout,
  385. .ndo_validate_addr = eth_validate_addr,
  386. .ndo_change_mtu = eth_change_mtu,
  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. dev->trans_start = jiffies; /* prevent tx timeout */
  647. netif_wake_queue(dev);
  648. }
  649. /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
  650. static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
  651. {
  652. struct lance_private *lp = netdev_priv(dev);
  653. struct lance_ioreg *IO = lp->iobase;
  654. int entry, len;
  655. struct lance_tx_head *head;
  656. unsigned long flags;
  657. DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",
  658. dev->name, DREG ));
  659. /* The old LANCE chips doesn't automatically pad buffers to min. size. */
  660. len = skb->len;
  661. if (len < ETH_ZLEN)
  662. len = ETH_ZLEN;
  663. /* PAM-Card has a bug: Can only send packets with even number of bytes! */
  664. else if (lp->cardtype == PAM_CARD && (len & 1))
  665. ++len;
  666. if (len > skb->len) {
  667. if (skb_padto(skb, len))
  668. return NETDEV_TX_OK;
  669. }
  670. netif_stop_queue (dev);
  671. /* Fill in a Tx ring entry */
  672. if (lance_debug >= 3) {
  673. printk( "%s: TX pkt type 0x%04x from %pM to %pM"
  674. " data at 0x%08x len %d\n",
  675. dev->name, ((u_short *)skb->data)[6],
  676. &skb->data[6], skb->data,
  677. (int)skb->data, (int)skb->len );
  678. }
  679. /* We're not prepared for the int until the last flags are set/reset. And
  680. * the int may happen already after setting the OWN_CHIP... */
  681. spin_lock_irqsave (&lp->devlock, flags);
  682. /* Mask to ring buffer boundary. */
  683. entry = lp->cur_tx & TX_RING_MOD_MASK;
  684. head = &(MEM->tx_head[entry]);
  685. /* Caution: the write order is important here, set the "ownership" bits
  686. * last.
  687. */
  688. head->length = -len;
  689. head->misc = 0;
  690. lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );
  691. head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;
  692. dev->stats.tx_bytes += skb->len;
  693. dev_kfree_skb( skb );
  694. lp->cur_tx++;
  695. while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {
  696. lp->cur_tx -= TX_RING_SIZE;
  697. lp->dirty_tx -= TX_RING_SIZE;
  698. }
  699. /* Trigger an immediate send poll. */
  700. DREG = CSR0_INEA | CSR0_TDMD;
  701. if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) ==
  702. TMD1_OWN_HOST)
  703. netif_start_queue (dev);
  704. else
  705. lp->tx_full = 1;
  706. spin_unlock_irqrestore (&lp->devlock, flags);
  707. return NETDEV_TX_OK;
  708. }
  709. /* The LANCE interrupt handler. */
  710. static irqreturn_t lance_interrupt( int irq, void *dev_id )
  711. {
  712. struct net_device *dev = dev_id;
  713. struct lance_private *lp;
  714. struct lance_ioreg *IO;
  715. int csr0, boguscnt = 10;
  716. int handled = 0;
  717. if (dev == NULL) {
  718. DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" ));
  719. return IRQ_NONE;
  720. }
  721. lp = netdev_priv(dev);
  722. IO = lp->iobase;
  723. spin_lock (&lp->devlock);
  724. AREG = CSR0;
  725. while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) &&
  726. --boguscnt >= 0) {
  727. handled = 1;
  728. /* Acknowledge all of the current interrupt sources ASAP. */
  729. DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP |
  730. CSR0_TDMD | CSR0_INEA);
  731. DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n",
  732. dev->name, csr0, DREG ));
  733. if (csr0 & CSR0_RINT) /* Rx interrupt */
  734. lance_rx( dev );
  735. if (csr0 & CSR0_TINT) { /* Tx-done interrupt */
  736. int dirty_tx = lp->dirty_tx;
  737. while( dirty_tx < lp->cur_tx) {
  738. int entry = dirty_tx & TX_RING_MOD_MASK;
  739. int status = MEM->tx_head[entry].flag;
  740. if (status & TMD1_OWN_CHIP)
  741. break; /* It still hasn't been Txed */
  742. MEM->tx_head[entry].flag = 0;
  743. if (status & TMD1_ERR) {
  744. /* There was an major error, log it. */
  745. int err_status = MEM->tx_head[entry].misc;
  746. dev->stats.tx_errors++;
  747. if (err_status & TMD3_RTRY) dev->stats.tx_aborted_errors++;
  748. if (err_status & TMD3_LCAR) dev->stats.tx_carrier_errors++;
  749. if (err_status & TMD3_LCOL) dev->stats.tx_window_errors++;
  750. if (err_status & TMD3_UFLO) {
  751. /* Ackk! On FIFO errors the Tx unit is turned off! */
  752. dev->stats.tx_fifo_errors++;
  753. /* Remove this verbosity later! */
  754. DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n",
  755. dev->name, csr0 ));
  756. /* Restart the chip. */
  757. DREG = CSR0_STRT;
  758. }
  759. } else {
  760. if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF))
  761. dev->stats.collisions++;
  762. dev->stats.tx_packets++;
  763. }
  764. /* XXX MSch: free skb?? */
  765. dirty_tx++;
  766. }
  767. #ifndef final_version
  768. if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
  769. DPRINTK( 0, ( "out-of-sync dirty pointer,"
  770. " %d vs. %d, full=%ld.\n",
  771. dirty_tx, lp->cur_tx, lp->tx_full ));
  772. dirty_tx += TX_RING_SIZE;
  773. }
  774. #endif
  775. if (lp->tx_full && (netif_queue_stopped(dev)) &&
  776. dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
  777. /* The ring is no longer full, clear tbusy. */
  778. lp->tx_full = 0;
  779. netif_wake_queue (dev);
  780. }
  781. lp->dirty_tx = dirty_tx;
  782. }
  783. /* Log misc errors. */
  784. if (csr0 & CSR0_BABL) dev->stats.tx_errors++; /* Tx babble. */
  785. if (csr0 & CSR0_MISS) dev->stats.rx_errors++; /* Missed a Rx frame. */
  786. if (csr0 & CSR0_MERR) {
  787. DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "
  788. "status %04x.\n", dev->name, csr0 ));
  789. /* Restart the chip. */
  790. DREG = CSR0_STRT;
  791. }
  792. }
  793. /* Clear any other interrupt, and set interrupt enable. */
  794. DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |
  795. CSR0_IDON | CSR0_INEA;
  796. DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",
  797. dev->name, DREG ));
  798. spin_unlock (&lp->devlock);
  799. return IRQ_RETVAL(handled);
  800. }
  801. static int lance_rx( struct net_device *dev )
  802. {
  803. struct lance_private *lp = netdev_priv(dev);
  804. int entry = lp->cur_rx & RX_RING_MOD_MASK;
  805. int i;
  806. DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name,
  807. MEM->rx_head[entry].flag ));
  808. /* If we own the next entry, it's a new packet. Send it up. */
  809. while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) {
  810. struct lance_rx_head *head = &(MEM->rx_head[entry]);
  811. int status = head->flag;
  812. if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */
  813. /* There is a tricky error noted by John Murphy,
  814. <murf@perftech.com> to Russ Nelson: Even with full-sized
  815. buffers it's possible for a jabber packet to use two
  816. buffers, with only the last correctly noting the error. */
  817. if (status & RMD1_ENP) /* Only count a general error at the */
  818. dev->stats.rx_errors++; /* end of a packet.*/
  819. if (status & RMD1_FRAM) dev->stats.rx_frame_errors++;
  820. if (status & RMD1_OFLO) dev->stats.rx_over_errors++;
  821. if (status & RMD1_CRC) dev->stats.rx_crc_errors++;
  822. if (status & RMD1_BUFF) dev->stats.rx_fifo_errors++;
  823. head->flag &= (RMD1_ENP|RMD1_STP);
  824. } else {
  825. /* Malloc up new buffer, compatible with net-3. */
  826. short pkt_len = head->msg_length & 0xfff;
  827. struct sk_buff *skb;
  828. if (pkt_len < 60) {
  829. printk( "%s: Runt packet!\n", dev->name );
  830. dev->stats.rx_errors++;
  831. }
  832. else {
  833. skb = netdev_alloc_skb(dev, pkt_len + 2);
  834. if (skb == NULL) {
  835. for( i = 0; i < RX_RING_SIZE; i++ )
  836. if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag &
  837. RMD1_OWN_CHIP)
  838. break;
  839. if (i > RX_RING_SIZE - 2) {
  840. dev->stats.rx_dropped++;
  841. head->flag |= RMD1_OWN_CHIP;
  842. lp->cur_rx++;
  843. }
  844. break;
  845. }
  846. if (lance_debug >= 3) {
  847. u_char *data = PKTBUF_ADDR(head);
  848. printk(KERN_DEBUG "%s: RX pkt type 0x%04x from %pM to %pM "
  849. "data %02x %02x %02x %02x %02x %02x %02x %02x "
  850. "len %d\n",
  851. dev->name, ((u_short *)data)[6],
  852. &data[6], data,
  853. data[15], data[16], data[17], data[18],
  854. data[19], data[20], data[21], data[22],
  855. pkt_len);
  856. }
  857. skb_reserve( skb, 2 ); /* 16 byte align */
  858. skb_put( skb, pkt_len ); /* Make room */
  859. lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len );
  860. skb->protocol = eth_type_trans( skb, dev );
  861. netif_rx( skb );
  862. dev->stats.rx_packets++;
  863. dev->stats.rx_bytes += pkt_len;
  864. }
  865. }
  866. head->flag |= RMD1_OWN_CHIP;
  867. entry = (++lp->cur_rx) & RX_RING_MOD_MASK;
  868. }
  869. lp->cur_rx &= RX_RING_MOD_MASK;
  870. /* From lance.c (Donald Becker): */
  871. /* We should check that at least two ring entries are free. If not,
  872. we should free one and mark stats->rx_dropped++. */
  873. return 0;
  874. }
  875. static int lance_close( struct net_device *dev )
  876. {
  877. struct lance_private *lp = netdev_priv(dev);
  878. struct lance_ioreg *IO = lp->iobase;
  879. netif_stop_queue (dev);
  880. AREG = CSR0;
  881. DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
  882. dev->name, DREG ));
  883. /* We stop the LANCE here -- it occasionally polls
  884. memory if we don't. */
  885. DREG = CSR0_STOP;
  886. return 0;
  887. }
  888. /* Set or clear the multicast filter for this adaptor.
  889. num_addrs == -1 Promiscuous mode, receive all packets
  890. num_addrs == 0 Normal mode, clear multicast list
  891. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  892. best-effort filtering.
  893. */
  894. static void set_multicast_list( struct net_device *dev )
  895. {
  896. struct lance_private *lp = netdev_priv(dev);
  897. struct lance_ioreg *IO = lp->iobase;
  898. if (netif_running(dev))
  899. /* Only possible if board is already started */
  900. return;
  901. /* We take the simple way out and always enable promiscuous mode. */
  902. DREG = CSR0_STOP; /* Temporarily stop the lance. */
  903. if (dev->flags & IFF_PROMISC) {
  904. /* Log any net taps. */
  905. DPRINTK( 2, ( "%s: Promiscuous mode enabled.\n", dev->name ));
  906. REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */
  907. } else {
  908. short multicast_table[4];
  909. int num_addrs = netdev_mc_count(dev);
  910. int i;
  911. /* We don't use the multicast table, but rely on upper-layer
  912. * filtering. */
  913. memset( multicast_table, (num_addrs == 0) ? 0 : -1,
  914. sizeof(multicast_table) );
  915. for( i = 0; i < 4; i++ )
  916. REGA( CSR8+i ) = multicast_table[i];
  917. REGA( CSR15 ) = 0; /* Unset promiscuous mode */
  918. }
  919. /*
  920. * Always set BSWP after a STOP as STOP puts it back into
  921. * little endian mode.
  922. */
  923. REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0);
  924. /* Resume normal operation and reset AREG to CSR0 */
  925. REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;
  926. }
  927. /* This is needed for old RieblCards and possible for new RieblCards */
  928. static int lance_set_mac_address( struct net_device *dev, void *addr )
  929. {
  930. struct lance_private *lp = netdev_priv(dev);
  931. struct sockaddr *saddr = addr;
  932. int i;
  933. if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL)
  934. return -EOPNOTSUPP;
  935. if (netif_running(dev)) {
  936. /* Only possible while card isn't started */
  937. DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n",
  938. dev->name ));
  939. return -EIO;
  940. }
  941. memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );
  942. for( i = 0; i < 6; i++ )
  943. MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */
  944. lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 );
  945. /* set also the magic for future sessions */
  946. *RIEBL_MAGIC_ADDR = RIEBL_MAGIC;
  947. return 0;
  948. }
  949. #ifdef MODULE
  950. static struct net_device *atarilance_dev;
  951. static int __init atarilance_module_init(void)
  952. {
  953. atarilance_dev = atarilance_probe(-1);
  954. return PTR_ERR_OR_ZERO(atarilance_dev);
  955. }
  956. static void __exit atarilance_module_exit(void)
  957. {
  958. unregister_netdev(atarilance_dev);
  959. free_irq(atarilance_dev->irq, atarilance_dev);
  960. free_netdev(atarilance_dev);
  961. }
  962. module_init(atarilance_module_init);
  963. module_exit(atarilance_module_exit);
  964. #endif /* MODULE */
  965. /*
  966. * Local variables:
  967. * c-indent-level: 4
  968. * tab-width: 4
  969. * End:
  970. */