ether1.c 27 KB

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