ether1.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /*
  2. * linux/drivers/acorn/net/ether1.c
  3. *
  4. * Copyright (C) 1996-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Acorn ether1 driver (82586 chip) for Acorn machines
  11. *
  12. * We basically keep two queues in the cards memory - one for transmit
  13. * and one for receive. Each has a head and a tail. The head is where
  14. * we/the chip adds packets to be transmitted/received, and the tail
  15. * is where the transmitter has got to/where the receiver will stop.
  16. * Both of these queues are circular, and since the chip is running
  17. * all the time, we have to be careful when we modify the pointers etc
  18. * so that the buffer memory contents is valid all the time.
  19. *
  20. * Change log:
  21. * 1.00 RMK Released
  22. * 1.01 RMK 19/03/1996 Transfers the last odd byte onto/off of the card now.
  23. * 1.02 RMK 25/05/1997 Added code to restart RU if it goes not ready
  24. * 1.03 RMK 14/09/1997 Cleaned up the handling of a reset during the TX interrupt.
  25. * Should prevent lockup.
  26. * 1.04 RMK 17/09/1997 Added more info when initialsation of chip goes wrong.
  27. * TDR now only reports failure when chip reports non-zero
  28. * TDR time-distance.
  29. * 1.05 RMK 31/12/1997 Removed calls to dev_tint for 2.1
  30. * 1.06 RMK 10/02/2000 Updated for 2.3.43
  31. * 1.07 RMK 13/05/2000 Updated for 2.3.99-pre8
  32. */
  33. #include <linux/module.h>
  34. #include <linux/kernel.h>
  35. #include <linux/types.h>
  36. #include <linux/fcntl.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/ioport.h>
  39. #include <linux/in.h>
  40. #include <linux/slab.h>
  41. #include <linux/string.h>
  42. #include <linux/errno.h>
  43. #include <linux/device.h>
  44. #include <linux/init.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/etherdevice.h>
  47. #include <linux/skbuff.h>
  48. #include <linux/bitops.h>
  49. #include <asm/io.h>
  50. #include <asm/dma.h>
  51. #include <asm/ecard.h>
  52. #define __ETHER1_C
  53. #include "ether1.h"
  54. static unsigned int net_debug = NET_DEBUG;
  55. #define BUFFER_SIZE 0x10000
  56. #define TX_AREA_START 0x00100
  57. #define TX_AREA_END 0x05000
  58. #define RX_AREA_START 0x05000
  59. #define RX_AREA_END 0x0fc00
  60. static int ether1_open(struct net_device *dev);
  61. static int ether1_sendpacket(struct sk_buff *skb, struct net_device *dev);
  62. static irqreturn_t ether1_interrupt(int irq, void *dev_id);
  63. static int ether1_close(struct net_device *dev);
  64. static void ether1_setmulticastlist(struct net_device *dev);
  65. static void ether1_timeout(struct net_device *dev);
  66. /* ------------------------------------------------------------------------- */
  67. static char version[] = "ether1 ethernet driver (c) 2000 Russell King v1.07\n";
  68. #define BUS_16 16
  69. #define BUS_8 8
  70. /* ------------------------------------------------------------------------- */
  71. #define DISABLEIRQS 1
  72. #define NORMALIRQS 0
  73. #define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
  74. #define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
  75. static inline unsigned short
  76. ether1_inw_p (struct net_device *dev, int addr, int svflgs)
  77. {
  78. unsigned long flags;
  79. unsigned short ret;
  80. if (svflgs)
  81. local_irq_save (flags);
  82. writeb(addr >> 12, REG_PAGE);
  83. ret = readw(ETHER1_RAM + ((addr & 4095) << 1));
  84. if (svflgs)
  85. local_irq_restore (flags);
  86. return ret;
  87. }
  88. static inline void
  89. ether1_outw_p (struct net_device *dev, unsigned short val, int addr, int svflgs)
  90. {
  91. unsigned long flags;
  92. if (svflgs)
  93. local_irq_save (flags);
  94. writeb(addr >> 12, REG_PAGE);
  95. writew(val, ETHER1_RAM + ((addr & 4095) << 1));
  96. if (svflgs)
  97. local_irq_restore (flags);
  98. }
  99. /*
  100. * Some inline assembler to allow fast transfers on to/off of the card.
  101. * Since this driver depends on some features presented by the ARM
  102. * specific architecture, and that you can't configure this driver
  103. * without specifiing ARM mode, this is not a problem.
  104. *
  105. * This routine is essentially an optimised memcpy from the card's
  106. * onboard RAM to kernel memory.
  107. */
  108. static void
  109. ether1_writebuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
  110. {
  111. unsigned int page, thislen, offset;
  112. void __iomem *addr;
  113. offset = start & 4095;
  114. page = start >> 12;
  115. addr = ETHER1_RAM + (offset << 1);
  116. if (offset + length > 4096)
  117. thislen = 4096 - offset;
  118. else
  119. thislen = length;
  120. do {
  121. int used;
  122. writeb(page, REG_PAGE);
  123. length -= thislen;
  124. __asm__ __volatile__(
  125. "subs %3, %3, #2\n\
  126. bmi 2f\n\
  127. 1: ldr %0, [%1], #2\n\
  128. mov %0, %0, lsl #16\n\
  129. orr %0, %0, %0, lsr #16\n\
  130. str %0, [%2], #4\n\
  131. subs %3, %3, #2\n\
  132. bmi 2f\n\
  133. ldr %0, [%1], #2\n\
  134. mov %0, %0, lsl #16\n\
  135. orr %0, %0, %0, lsr #16\n\
  136. str %0, [%2], #4\n\
  137. subs %3, %3, #2\n\
  138. bmi 2f\n\
  139. ldr %0, [%1], #2\n\
  140. mov %0, %0, lsl #16\n\
  141. orr %0, %0, %0, lsr #16\n\
  142. str %0, [%2], #4\n\
  143. subs %3, %3, #2\n\
  144. bmi 2f\n\
  145. ldr %0, [%1], #2\n\
  146. mov %0, %0, lsl #16\n\
  147. orr %0, %0, %0, lsr #16\n\
  148. str %0, [%2], #4\n\
  149. subs %3, %3, #2\n\
  150. bpl 1b\n\
  151. 2: adds %3, %3, #1\n\
  152. ldreqb %0, [%1]\n\
  153. streqb %0, [%2]"
  154. : "=&r" (used), "=&r" (data)
  155. : "r" (addr), "r" (thislen), "1" (data));
  156. addr = ETHER1_RAM;
  157. thislen = length;
  158. if (thislen > 4096)
  159. thislen = 4096;
  160. page++;
  161. } while (thislen);
  162. }
  163. static void
  164. ether1_readbuffer (struct net_device *dev, void *data, unsigned int start, unsigned int length)
  165. {
  166. unsigned int page, thislen, offset;
  167. void __iomem *addr;
  168. offset = start & 4095;
  169. page = start >> 12;
  170. addr = ETHER1_RAM + (offset << 1);
  171. if (offset + length > 4096)
  172. thislen = 4096 - offset;
  173. else
  174. thislen = length;
  175. do {
  176. int used;
  177. writeb(page, REG_PAGE);
  178. length -= thislen;
  179. __asm__ __volatile__(
  180. "subs %3, %3, #2\n\
  181. bmi 2f\n\
  182. 1: ldr %0, [%2], #4\n\
  183. strb %0, [%1], #1\n\
  184. mov %0, %0, lsr #8\n\
  185. strb %0, [%1], #1\n\
  186. subs %3, %3, #2\n\
  187. bmi 2f\n\
  188. ldr %0, [%2], #4\n\
  189. strb %0, [%1], #1\n\
  190. mov %0, %0, lsr #8\n\
  191. strb %0, [%1], #1\n\
  192. subs %3, %3, #2\n\
  193. bmi 2f\n\
  194. ldr %0, [%2], #4\n\
  195. strb %0, [%1], #1\n\
  196. mov %0, %0, lsr #8\n\
  197. strb %0, [%1], #1\n\
  198. subs %3, %3, #2\n\
  199. bmi 2f\n\
  200. ldr %0, [%2], #4\n\
  201. strb %0, [%1], #1\n\
  202. mov %0, %0, lsr #8\n\
  203. strb %0, [%1], #1\n\
  204. subs %3, %3, #2\n\
  205. bpl 1b\n\
  206. 2: adds %3, %3, #1\n\
  207. ldreqb %0, [%2]\n\
  208. streqb %0, [%1]"
  209. : "=&r" (used), "=&r" (data)
  210. : "r" (addr), "r" (thislen), "1" (data));
  211. addr = ETHER1_RAM;
  212. thislen = length;
  213. if (thislen > 4096)
  214. thislen = 4096;
  215. page++;
  216. } while (thislen);
  217. }
  218. static int
  219. ether1_ramtest(struct net_device *dev, unsigned char byte)
  220. {
  221. unsigned char *buffer = kmalloc (BUFFER_SIZE, GFP_KERNEL);
  222. int i, ret = BUFFER_SIZE;
  223. int max_errors = 15;
  224. int bad = -1;
  225. int bad_start = 0;
  226. if (!buffer)
  227. return 1;
  228. memset (buffer, byte, BUFFER_SIZE);
  229. ether1_writebuffer (dev, buffer, 0, BUFFER_SIZE);
  230. memset (buffer, byte ^ 0xff, BUFFER_SIZE);
  231. ether1_readbuffer (dev, buffer, 0, BUFFER_SIZE);
  232. for (i = 0; i < BUFFER_SIZE; i++) {
  233. if (buffer[i] != byte) {
  234. if (max_errors >= 0 && bad != buffer[i]) {
  235. if (bad != -1)
  236. printk ("\n");
  237. printk (KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
  238. dev->name, buffer[i], byte, i);
  239. ret = -ENODEV;
  240. max_errors --;
  241. bad = buffer[i];
  242. bad_start = i;
  243. }
  244. } else {
  245. if (bad != -1) {
  246. if (bad_start == i - 1)
  247. printk ("\n");
  248. else
  249. printk (" - 0x%04X\n", i - 1);
  250. bad = -1;
  251. }
  252. }
  253. }
  254. if (bad != -1)
  255. printk (" - 0x%04X\n", BUFFER_SIZE);
  256. kfree (buffer);
  257. return ret;
  258. }
  259. static int
  260. ether1_reset (struct net_device *dev)
  261. {
  262. writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
  263. return BUS_16;
  264. }
  265. static int
  266. ether1_init_2(struct net_device *dev)
  267. {
  268. int i;
  269. dev->mem_start = 0;
  270. i = ether1_ramtest (dev, 0x5a);
  271. if (i > 0)
  272. i = ether1_ramtest (dev, 0x1e);
  273. if (i <= 0)
  274. return -ENODEV;
  275. dev->mem_end = i;
  276. return 0;
  277. }
  278. /*
  279. * These are the structures that are loaded into the ether RAM card to
  280. * initialise the 82586
  281. */
  282. /* at 0x0100 */
  283. #define NOP_ADDR (TX_AREA_START)
  284. #define NOP_SIZE (0x06)
  285. static nop_t init_nop = {
  286. 0,
  287. CMD_NOP,
  288. NOP_ADDR
  289. };
  290. /* at 0x003a */
  291. #define TDR_ADDR (0x003a)
  292. #define TDR_SIZE (0x08)
  293. static tdr_t init_tdr = {
  294. 0,
  295. CMD_TDR | CMD_INTR,
  296. NOP_ADDR,
  297. 0
  298. };
  299. /* at 0x002e */
  300. #define MC_ADDR (0x002e)
  301. #define MC_SIZE (0x0c)
  302. static mc_t init_mc = {
  303. 0,
  304. CMD_SETMULTICAST,
  305. TDR_ADDR,
  306. 0,
  307. { { 0, } }
  308. };
  309. /* at 0x0022 */
  310. #define SA_ADDR (0x0022)
  311. #define SA_SIZE (0x0c)
  312. static sa_t init_sa = {
  313. 0,
  314. CMD_SETADDRESS,
  315. MC_ADDR,
  316. { 0, }
  317. };
  318. /* at 0x0010 */
  319. #define CFG_ADDR (0x0010)
  320. #define CFG_SIZE (0x12)
  321. static cfg_t init_cfg = {
  322. 0,
  323. CMD_CONFIG,
  324. SA_ADDR,
  325. 8,
  326. 8,
  327. CFG8_SRDY,
  328. CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
  329. 0,
  330. 0x60,
  331. 0,
  332. CFG13_RETRY(15) | CFG13_SLOTH(2),
  333. 0,
  334. };
  335. /* at 0x0000 */
  336. #define SCB_ADDR (0x0000)
  337. #define SCB_SIZE (0x10)
  338. static scb_t init_scb = {
  339. 0,
  340. SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
  341. CFG_ADDR,
  342. RX_AREA_START,
  343. 0,
  344. 0,
  345. 0,
  346. 0
  347. };
  348. /* at 0xffee */
  349. #define ISCP_ADDR (0xffee)
  350. #define ISCP_SIZE (0x08)
  351. static iscp_t init_iscp = {
  352. 1,
  353. SCB_ADDR,
  354. 0x0000,
  355. 0x0000
  356. };
  357. /* at 0xfff6 */
  358. #define SCP_ADDR (0xfff6)
  359. #define SCP_SIZE (0x0a)
  360. static scp_t init_scp = {
  361. SCP_SY_16BBUS,
  362. { 0, 0 },
  363. ISCP_ADDR,
  364. 0
  365. };
  366. #define RFD_SIZE (0x16)
  367. static rfd_t init_rfd = {
  368. 0,
  369. 0,
  370. 0,
  371. 0,
  372. { 0, },
  373. { 0, },
  374. 0
  375. };
  376. #define RBD_SIZE (0x0a)
  377. static rbd_t init_rbd = {
  378. 0,
  379. 0,
  380. 0,
  381. 0,
  382. ETH_FRAME_LEN + 8
  383. };
  384. #define TX_SIZE (0x08)
  385. #define TBD_SIZE (0x08)
  386. static int
  387. ether1_init_for_open (struct net_device *dev)
  388. {
  389. int i, status, addr, next, next2;
  390. int failures = 0;
  391. unsigned long timeout;
  392. writeb(CTRL_RST|CTRL_ACK, REG_CONTROL);
  393. for (i = 0; i < 6; i++)
  394. init_sa.sa_addr[i] = dev->dev_addr[i];
  395. /* load data structures into ether1 RAM */
  396. ether1_writebuffer (dev, &init_scp, SCP_ADDR, SCP_SIZE);
  397. ether1_writebuffer (dev, &init_iscp, ISCP_ADDR, ISCP_SIZE);
  398. ether1_writebuffer (dev, &init_scb, SCB_ADDR, SCB_SIZE);
  399. ether1_writebuffer (dev, &init_cfg, CFG_ADDR, CFG_SIZE);
  400. ether1_writebuffer (dev, &init_sa, SA_ADDR, SA_SIZE);
  401. ether1_writebuffer (dev, &init_mc, MC_ADDR, MC_SIZE);
  402. ether1_writebuffer (dev, &init_tdr, TDR_ADDR, TDR_SIZE);
  403. ether1_writebuffer (dev, &init_nop, NOP_ADDR, NOP_SIZE);
  404. if (ether1_readw(dev, CFG_ADDR, cfg_t, cfg_command, NORMALIRQS) != CMD_CONFIG) {
  405. printk (KERN_ERR "%s: detected either RAM fault or compiler bug\n",
  406. dev->name);
  407. return 1;
  408. }
  409. /*
  410. * setup circularly linked list of { rfd, rbd, buffer }, with
  411. * all rfds circularly linked, rbds circularly linked.
  412. * First rfd is linked to scp, first rbd is linked to first
  413. * rfd. Last rbd has a suspend command.
  414. */
  415. addr = RX_AREA_START;
  416. do {
  417. next = addr + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
  418. next2 = next + RFD_SIZE + RBD_SIZE + ETH_FRAME_LEN + 10;
  419. if (next2 >= RX_AREA_END) {
  420. next = RX_AREA_START;
  421. init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
  422. priv(dev)->rx_tail = addr;
  423. } else
  424. init_rfd.rfd_command = 0;
  425. if (addr == RX_AREA_START)
  426. init_rfd.rfd_rbdoffset = addr + RFD_SIZE;
  427. else
  428. init_rfd.rfd_rbdoffset = 0;
  429. init_rfd.rfd_link = next;
  430. init_rbd.rbd_link = next + RFD_SIZE;
  431. init_rbd.rbd_bufl = addr + RFD_SIZE + RBD_SIZE;
  432. ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
  433. ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
  434. addr = next;
  435. } while (next2 < RX_AREA_END);
  436. priv(dev)->tx_link = NOP_ADDR;
  437. priv(dev)->tx_head = NOP_ADDR + NOP_SIZE;
  438. priv(dev)->tx_tail = TDR_ADDR;
  439. priv(dev)->rx_head = RX_AREA_START;
  440. /* release reset & give 586 a prod */
  441. priv(dev)->resetting = 1;
  442. priv(dev)->initialising = 1;
  443. writeb(CTRL_RST, REG_CONTROL);
  444. writeb(0, REG_CONTROL);
  445. writeb(CTRL_CA, REG_CONTROL);
  446. /* 586 should now unset iscp.busy */
  447. timeout = jiffies + HZ/2;
  448. while (ether1_readw(dev, ISCP_ADDR, iscp_t, iscp_busy, DISABLEIRQS) == 1) {
  449. if (time_after(jiffies, timeout)) {
  450. printk (KERN_WARNING "%s: can't initialise 82586: iscp is busy\n", dev->name);
  451. return 1;
  452. }
  453. }
  454. /* check status of commands that we issued */
  455. timeout += HZ/10;
  456. while (((status = ether1_readw(dev, CFG_ADDR, cfg_t, cfg_status, DISABLEIRQS))
  457. & STAT_COMPLETE) == 0) {
  458. if (time_after(jiffies, timeout))
  459. break;
  460. }
  461. if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
  462. printk (KERN_WARNING "%s: can't initialise 82586: config status %04X\n", dev->name, status);
  463. printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
  464. ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
  465. ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
  466. ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
  467. ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
  468. failures += 1;
  469. }
  470. timeout += HZ/10;
  471. while (((status = ether1_readw(dev, SA_ADDR, sa_t, sa_status, DISABLEIRQS))
  472. & STAT_COMPLETE) == 0) {
  473. if (time_after(jiffies, timeout))
  474. break;
  475. }
  476. if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
  477. printk (KERN_WARNING "%s: can't initialise 82586: set address status %04X\n", dev->name, status);
  478. printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
  479. ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
  480. ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
  481. ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
  482. ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
  483. failures += 1;
  484. }
  485. timeout += HZ/10;
  486. while (((status = ether1_readw(dev, MC_ADDR, mc_t, mc_status, DISABLEIRQS))
  487. & STAT_COMPLETE) == 0) {
  488. if (time_after(jiffies, timeout))
  489. break;
  490. }
  491. if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
  492. printk (KERN_WARNING "%s: can't initialise 82586: set multicast status %04X\n", dev->name, status);
  493. printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
  494. ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
  495. ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
  496. ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
  497. ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
  498. failures += 1;
  499. }
  500. timeout += HZ;
  501. while (((status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_status, DISABLEIRQS))
  502. & STAT_COMPLETE) == 0) {
  503. if (time_after(jiffies, timeout))
  504. break;
  505. }
  506. if ((status & (STAT_COMPLETE | STAT_OK)) != (STAT_COMPLETE | STAT_OK)) {
  507. printk (KERN_WARNING "%s: can't tdr (ignored)\n", dev->name);
  508. printk (KERN_DEBUG "%s: SCB=[STS=%04X CMD=%04X CBL=%04X RFA=%04X]\n", dev->name,
  509. ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS),
  510. ether1_readw(dev, SCB_ADDR, scb_t, scb_command, NORMALIRQS),
  511. ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS),
  512. ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset, NORMALIRQS));
  513. } else {
  514. status = ether1_readw(dev, TDR_ADDR, tdr_t, tdr_result, DISABLEIRQS);
  515. if (status & TDR_XCVRPROB)
  516. printk (KERN_WARNING "%s: i/f failed tdr: transceiver problem\n", dev->name);
  517. else if ((status & (TDR_SHORT|TDR_OPEN)) && (status & TDR_TIME)) {
  518. #ifdef FANCY
  519. printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d.%d us away\n", dev->name,
  520. status & TDR_SHORT ? "short" : "open", (status & TDR_TIME) / 10,
  521. (status & TDR_TIME) % 10);
  522. #else
  523. printk (KERN_WARNING "%s: i/f failed tdr: cable %s %d clks away\n", dev->name,
  524. status & TDR_SHORT ? "short" : "open", (status & TDR_TIME));
  525. #endif
  526. }
  527. }
  528. if (failures)
  529. ether1_reset (dev);
  530. return failures ? 1 : 0;
  531. }
  532. /* ------------------------------------------------------------------------- */
  533. static int
  534. ether1_txalloc (struct net_device *dev, int size)
  535. {
  536. int start, tail;
  537. size = (size + 1) & ~1;
  538. tail = priv(dev)->tx_tail;
  539. if (priv(dev)->tx_head + size > TX_AREA_END) {
  540. if (tail > priv(dev)->tx_head)
  541. return -1;
  542. start = TX_AREA_START;
  543. if (start + size > tail)
  544. return -1;
  545. priv(dev)->tx_head = start + size;
  546. } else {
  547. if (priv(dev)->tx_head < tail && (priv(dev)->tx_head + size) > tail)
  548. return -1;
  549. start = priv(dev)->tx_head;
  550. priv(dev)->tx_head += size;
  551. }
  552. return start;
  553. }
  554. static int
  555. ether1_open (struct net_device *dev)
  556. {
  557. if (request_irq(dev->irq, ether1_interrupt, 0, "ether1", dev))
  558. return -EAGAIN;
  559. if (ether1_init_for_open (dev)) {
  560. free_irq (dev->irq, dev);
  561. return -EAGAIN;
  562. }
  563. netif_start_queue(dev);
  564. return 0;
  565. }
  566. static void
  567. ether1_timeout(struct net_device *dev)
  568. {
  569. printk(KERN_WARNING "%s: transmit timeout, network cable problem?\n",
  570. dev->name);
  571. printk(KERN_WARNING "%s: resetting device\n", dev->name);
  572. ether1_reset (dev);
  573. if (ether1_init_for_open (dev))
  574. printk (KERN_ERR "%s: unable to restart interface\n", dev->name);
  575. dev->stats.tx_errors++;
  576. netif_wake_queue(dev);
  577. }
  578. static int
  579. ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
  580. {
  581. int tmp, tst, nopaddr, txaddr, tbdaddr, dataddr;
  582. unsigned long flags;
  583. tx_t tx;
  584. tbd_t tbd;
  585. nop_t nop;
  586. if (priv(dev)->restart) {
  587. printk(KERN_WARNING "%s: resetting device\n", dev->name);
  588. ether1_reset(dev);
  589. if (ether1_init_for_open(dev))
  590. printk(KERN_ERR "%s: unable to restart interface\n", dev->name);
  591. else
  592. priv(dev)->restart = 0;
  593. }
  594. if (skb->len < ETH_ZLEN) {
  595. if (skb_padto(skb, ETH_ZLEN))
  596. goto out;
  597. }
  598. /*
  599. * insert packet followed by a nop
  600. */
  601. txaddr = ether1_txalloc (dev, TX_SIZE);
  602. tbdaddr = ether1_txalloc (dev, TBD_SIZE);
  603. dataddr = ether1_txalloc (dev, skb->len);
  604. nopaddr = ether1_txalloc (dev, NOP_SIZE);
  605. tx.tx_status = 0;
  606. tx.tx_command = CMD_TX | CMD_INTR;
  607. tx.tx_link = nopaddr;
  608. tx.tx_tbdoffset = tbdaddr;
  609. tbd.tbd_opts = TBD_EOL | skb->len;
  610. tbd.tbd_link = I82586_NULL;
  611. tbd.tbd_bufl = dataddr;
  612. tbd.tbd_bufh = 0;
  613. nop.nop_status = 0;
  614. nop.nop_command = CMD_NOP;
  615. nop.nop_link = nopaddr;
  616. local_irq_save(flags);
  617. ether1_writebuffer (dev, &tx, txaddr, TX_SIZE);
  618. ether1_writebuffer (dev, &tbd, tbdaddr, TBD_SIZE);
  619. ether1_writebuffer (dev, skb->data, dataddr, skb->len);
  620. ether1_writebuffer (dev, &nop, nopaddr, NOP_SIZE);
  621. tmp = priv(dev)->tx_link;
  622. priv(dev)->tx_link = nopaddr;
  623. /* now reset the previous nop pointer */
  624. ether1_writew(dev, txaddr, tmp, nop_t, nop_link, NORMALIRQS);
  625. local_irq_restore(flags);
  626. /* handle transmit */
  627. /* check to see if we have room for a full sized ether frame */
  628. tmp = priv(dev)->tx_head;
  629. tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
  630. priv(dev)->tx_head = tmp;
  631. dev_kfree_skb (skb);
  632. if (tst == -1)
  633. netif_stop_queue(dev);
  634. out:
  635. return NETDEV_TX_OK;
  636. }
  637. static void
  638. ether1_xmit_done (struct net_device *dev)
  639. {
  640. nop_t nop;
  641. int caddr, tst;
  642. caddr = priv(dev)->tx_tail;
  643. again:
  644. ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
  645. switch (nop.nop_command & CMD_MASK) {
  646. case CMD_TDR:
  647. /* special case */
  648. if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
  649. != (unsigned short)I82586_NULL) {
  650. ether1_writew(dev, SCB_CMDCUCSTART | SCB_CMDRXSTART, SCB_ADDR, scb_t,
  651. scb_command, NORMALIRQS);
  652. writeb(CTRL_CA, REG_CONTROL);
  653. }
  654. priv(dev)->tx_tail = NOP_ADDR;
  655. return;
  656. case CMD_NOP:
  657. if (nop.nop_link == caddr) {
  658. if (priv(dev)->initialising == 0)
  659. printk (KERN_WARNING "%s: strange command complete with no tx command!\n", dev->name);
  660. else
  661. priv(dev)->initialising = 0;
  662. return;
  663. }
  664. if (caddr == nop.nop_link)
  665. return;
  666. caddr = nop.nop_link;
  667. goto again;
  668. case CMD_TX:
  669. if (nop.nop_status & STAT_COMPLETE)
  670. break;
  671. printk (KERN_ERR "%s: strange command complete without completed command\n", dev->name);
  672. priv(dev)->restart = 1;
  673. return;
  674. default:
  675. printk (KERN_WARNING "%s: strange command %d complete! (offset %04X)", dev->name,
  676. nop.nop_command & CMD_MASK, caddr);
  677. priv(dev)->restart = 1;
  678. return;
  679. }
  680. while (nop.nop_status & STAT_COMPLETE) {
  681. if (nop.nop_status & STAT_OK) {
  682. dev->stats.tx_packets++;
  683. dev->stats.collisions += (nop.nop_status & STAT_COLLISIONS);
  684. } else {
  685. dev->stats.tx_errors++;
  686. if (nop.nop_status & STAT_COLLAFTERTX)
  687. dev->stats.collisions++;
  688. if (nop.nop_status & STAT_NOCARRIER)
  689. dev->stats.tx_carrier_errors++;
  690. if (nop.nop_status & STAT_TXLOSTCTS)
  691. printk (KERN_WARNING "%s: cts lost\n", dev->name);
  692. if (nop.nop_status & STAT_TXSLOWDMA)
  693. dev->stats.tx_fifo_errors++;
  694. if (nop.nop_status & STAT_COLLEXCESSIVE)
  695. dev->stats.collisions += 16;
  696. }
  697. if (nop.nop_link == caddr) {
  698. printk (KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->name);
  699. break;
  700. }
  701. caddr = nop.nop_link;
  702. ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
  703. if ((nop.nop_command & CMD_MASK) != CMD_NOP) {
  704. printk (KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->name);
  705. break;
  706. }
  707. if (caddr == nop.nop_link)
  708. break;
  709. caddr = nop.nop_link;
  710. ether1_readbuffer (dev, &nop, caddr, NOP_SIZE);
  711. if ((nop.nop_command & CMD_MASK) != CMD_TX) {
  712. printk (KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->name);
  713. break;
  714. }
  715. }
  716. priv(dev)->tx_tail = caddr;
  717. caddr = priv(dev)->tx_head;
  718. tst = ether1_txalloc (dev, TX_SIZE + TBD_SIZE + NOP_SIZE + ETH_FRAME_LEN);
  719. priv(dev)->tx_head = caddr;
  720. if (tst != -1)
  721. netif_wake_queue(dev);
  722. }
  723. static void
  724. ether1_recv_done (struct net_device *dev)
  725. {
  726. int status;
  727. int nexttail, rbdaddr;
  728. rbd_t rbd;
  729. do {
  730. status = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_status, NORMALIRQS);
  731. if ((status & RFD_COMPLETE) == 0)
  732. break;
  733. rbdaddr = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_rbdoffset, NORMALIRQS);
  734. ether1_readbuffer (dev, &rbd, rbdaddr, RBD_SIZE);
  735. if ((rbd.rbd_status & (RBD_EOF | RBD_ACNTVALID)) == (RBD_EOF | RBD_ACNTVALID)) {
  736. int length = rbd.rbd_status & RBD_ACNT;
  737. struct sk_buff *skb;
  738. length = (length + 1) & ~1;
  739. skb = netdev_alloc_skb(dev, length + 2);
  740. if (skb) {
  741. skb_reserve (skb, 2);
  742. ether1_readbuffer (dev, skb_put (skb, length), rbd.rbd_bufl, length);
  743. skb->protocol = eth_type_trans (skb, dev);
  744. netif_rx (skb);
  745. dev->stats.rx_packets++;
  746. } else
  747. dev->stats.rx_dropped++;
  748. } else {
  749. printk(KERN_WARNING "%s: %s\n", dev->name,
  750. (rbd.rbd_status & RBD_EOF) ? "oversized packet" : "acnt not valid");
  751. dev->stats.rx_dropped++;
  752. }
  753. nexttail = ether1_readw(dev, priv(dev)->rx_tail, rfd_t, rfd_link, NORMALIRQS);
  754. /* nexttail should be rx_head */
  755. if (nexttail != priv(dev)->rx_head)
  756. printk(KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
  757. dev->name, nexttail, priv(dev)->rx_head);
  758. ether1_writew(dev, RFD_CMDEL | RFD_CMDSUSPEND, nexttail, rfd_t, rfd_command, NORMALIRQS);
  759. ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_command, NORMALIRQS);
  760. ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_status, NORMALIRQS);
  761. ether1_writew(dev, 0, priv(dev)->rx_tail, rfd_t, rfd_rbdoffset, NORMALIRQS);
  762. priv(dev)->rx_tail = nexttail;
  763. priv(dev)->rx_head = ether1_readw(dev, priv(dev)->rx_head, rfd_t, rfd_link, NORMALIRQS);
  764. } while (1);
  765. }
  766. static irqreturn_t
  767. ether1_interrupt (int irq, void *dev_id)
  768. {
  769. struct net_device *dev = (struct net_device *)dev_id;
  770. int status;
  771. status = ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS);
  772. if (status) {
  773. ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
  774. SCB_ADDR, scb_t, scb_command, NORMALIRQS);
  775. writeb(CTRL_CA | CTRL_ACK, REG_CONTROL);
  776. if (status & SCB_STCX) {
  777. ether1_xmit_done (dev);
  778. }
  779. if (status & SCB_STCNA) {
  780. if (priv(dev)->resetting == 0)
  781. printk (KERN_WARNING "%s: CU went not ready ???\n", dev->name);
  782. else
  783. priv(dev)->resetting += 1;
  784. if (ether1_readw(dev, SCB_ADDR, scb_t, scb_cbl_offset, NORMALIRQS)
  785. != (unsigned short)I82586_NULL) {
  786. ether1_writew(dev, SCB_CMDCUCSTART, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
  787. writeb(CTRL_CA, REG_CONTROL);
  788. }
  789. if (priv(dev)->resetting == 2)
  790. priv(dev)->resetting = 0;
  791. }
  792. if (status & SCB_STFR) {
  793. ether1_recv_done (dev);
  794. }
  795. if (status & SCB_STRNR) {
  796. if (ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS) & SCB_STRXSUSP) {
  797. printk (KERN_WARNING "%s: RU went not ready: RU suspended\n", dev->name);
  798. ether1_writew(dev, SCB_CMDRXRESUME, SCB_ADDR, scb_t, scb_command, NORMALIRQS);
  799. writeb(CTRL_CA, REG_CONTROL);
  800. dev->stats.rx_dropped++; /* we suspended due to lack of buffer space */
  801. } else
  802. printk(KERN_WARNING "%s: RU went not ready: %04X\n", dev->name,
  803. ether1_readw(dev, SCB_ADDR, scb_t, scb_status, NORMALIRQS));
  804. printk (KERN_WARNING "RU ptr = %04X\n", ether1_readw(dev, SCB_ADDR, scb_t, scb_rfa_offset,
  805. NORMALIRQS));
  806. }
  807. } else
  808. writeb(CTRL_ACK, REG_CONTROL);
  809. return IRQ_HANDLED;
  810. }
  811. static int
  812. ether1_close (struct net_device *dev)
  813. {
  814. ether1_reset (dev);
  815. free_irq(dev->irq, dev);
  816. return 0;
  817. }
  818. /*
  819. * Set or clear the multicast filter for this adaptor.
  820. * num_addrs == -1 Promiscuous mode, receive all packets.
  821. * num_addrs == 0 Normal mode, clear multicast list.
  822. * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  823. * best-effort filtering.
  824. */
  825. static void
  826. ether1_setmulticastlist (struct net_device *dev)
  827. {
  828. }
  829. /* ------------------------------------------------------------------------- */
  830. static void ether1_banner(void)
  831. {
  832. static unsigned int version_printed = 0;
  833. if (net_debug && version_printed++ == 0)
  834. printk(KERN_INFO "%s", version);
  835. }
  836. static const struct net_device_ops ether1_netdev_ops = {
  837. .ndo_open = ether1_open,
  838. .ndo_stop = ether1_close,
  839. .ndo_start_xmit = ether1_sendpacket,
  840. .ndo_set_rx_mode = ether1_setmulticastlist,
  841. .ndo_tx_timeout = ether1_timeout,
  842. .ndo_validate_addr = eth_validate_addr,
  843. .ndo_change_mtu = eth_change_mtu,
  844. .ndo_set_mac_address = eth_mac_addr,
  845. };
  846. static int
  847. ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
  848. {
  849. struct net_device *dev;
  850. int i, ret = 0;
  851. ether1_banner();
  852. ret = ecard_request_resources(ec);
  853. if (ret)
  854. goto out;
  855. dev = alloc_etherdev(sizeof(struct ether1_priv));
  856. if (!dev) {
  857. ret = -ENOMEM;
  858. goto release;
  859. }
  860. SET_NETDEV_DEV(dev, &ec->dev);
  861. dev->irq = ec->irq;
  862. priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  863. if (!priv(dev)->base) {
  864. ret = -ENOMEM;
  865. goto free;
  866. }
  867. if ((priv(dev)->bus_type = ether1_reset(dev)) == 0) {
  868. ret = -ENODEV;
  869. goto free;
  870. }
  871. for (i = 0; i < 6; i++)
  872. dev->dev_addr[i] = readb(IDPROM_ADDRESS + (i << 2));
  873. if (ether1_init_2(dev)) {
  874. ret = -ENODEV;
  875. goto free;
  876. }
  877. dev->netdev_ops = &ether1_netdev_ops;
  878. dev->watchdog_timeo = 5 * HZ / 100;
  879. ret = register_netdev(dev);
  880. if (ret)
  881. goto free;
  882. printk(KERN_INFO "%s: ether1 in slot %d, %pM\n",
  883. dev->name, ec->slot_no, dev->dev_addr);
  884. ecard_set_drvdata(ec, dev);
  885. return 0;
  886. free:
  887. free_netdev(dev);
  888. release:
  889. ecard_release_resources(ec);
  890. out:
  891. return ret;
  892. }
  893. static void ether1_remove(struct expansion_card *ec)
  894. {
  895. struct net_device *dev = ecard_get_drvdata(ec);
  896. ecard_set_drvdata(ec, NULL);
  897. unregister_netdev(dev);
  898. free_netdev(dev);
  899. ecard_release_resources(ec);
  900. }
  901. static const struct ecard_id ether1_ids[] = {
  902. { MANU_ACORN, PROD_ACORN_ETHER1 },
  903. { 0xffff, 0xffff }
  904. };
  905. static struct ecard_driver ether1_driver = {
  906. .probe = ether1_probe,
  907. .remove = ether1_remove,
  908. .id_table = ether1_ids,
  909. .drv = {
  910. .name = "ether1",
  911. },
  912. };
  913. static int __init ether1_init(void)
  914. {
  915. return ecard_register_driver(&ether1_driver);
  916. }
  917. static void __exit ether1_exit(void)
  918. {
  919. ecard_remove_driver(&ether1_driver);
  920. }
  921. module_init(ether1_init);
  922. module_exit(ether1_exit);
  923. MODULE_LICENSE("GPL");