mac8390.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /* mac8390.c: New driver for 8390-based Nubus (or Nubus-alike)
  2. Ethernet cards on Linux */
  3. /* Based on the former daynaport.c driver, by Alan Cox. Some code
  4. taken from or inspired by skeleton.c by Donald Becker, acenic.c by
  5. Jes Sorensen, and ne2k-pci.c by Donald Becker and Paul Gortmaker.
  6. This software may be used and distributed according to the terms of
  7. the GNU Public License, incorporated herein by reference. */
  8. /* 2000-02-28: support added for Dayna and Kinetics cards by
  9. A.G.deWijn@phys.uu.nl */
  10. /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */
  11. /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */
  12. /* 2001-05-15: support for Cabletron ported from old daynaport driver
  13. * and fixed access to Sonic Sys card which masquerades as a Farallon
  14. * by rayk@knightsmanor.org */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/fcntl.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/ioport.h>
  22. #include <linux/nubus.h>
  23. #include <linux/in.h>
  24. #include <linux/slab.h>
  25. #include <linux/string.h>
  26. #include <linux/errno.h>
  27. #include <linux/init.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/bitops.h>
  32. #include <asm/system.h>
  33. #include <asm/io.h>
  34. #include <asm/dma.h>
  35. #include <asm/hwtest.h>
  36. #include <asm/macints.h>
  37. static char version[] =
  38. "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
  39. #define EI_SHIFT(x) (ei_local->reg_offset[x])
  40. #define ei_inb(port) in_8(port)
  41. #define ei_outb(val,port) out_8(port,val)
  42. #define ei_inb_p(port) in_8(port)
  43. #define ei_outb_p(val,port) out_8(port,val)
  44. #include "lib8390.c"
  45. #define WD_START_PG 0x00 /* First page of TX buffer */
  46. #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */
  47. #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */
  48. #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG /* First page of TX buffer */
  49. /* Unfortunately it seems we have to hardcode these for the moment */
  50. /* Shouldn't the card know about this? Does anyone know where to read it off the card? Do we trust the data provided by the card? */
  51. #define DAYNA_8390_BASE 0x80000
  52. #define DAYNA_8390_MEM 0x00000
  53. #define KINETICS_8390_BASE 0x80000
  54. #define KINETICS_8390_MEM 0x00000
  55. #define CABLETRON_8390_BASE 0x90000
  56. #define CABLETRON_8390_MEM 0x00000
  57. enum mac8390_type {
  58. MAC8390_NONE = -1,
  59. MAC8390_APPLE,
  60. MAC8390_ASANTE,
  61. MAC8390_FARALLON, /* Apple, Asante, and Farallon are all compatible */
  62. MAC8390_CABLETRON,
  63. MAC8390_DAYNA,
  64. MAC8390_INTERLAN,
  65. MAC8390_KINETICS,
  66. MAC8390_FOCUS,
  67. MAC8390_SONICSYS,
  68. MAC8390_DAYNA2,
  69. MAC8390_DAYNA3,
  70. };
  71. static const char * cardname[] = {
  72. "apple",
  73. "asante",
  74. "farallon",
  75. "cabletron",
  76. "dayna",
  77. "interlan",
  78. "kinetics",
  79. "focus",
  80. "sonic systems",
  81. "dayna2",
  82. "dayna_lc",
  83. };
  84. static int word16[] = {
  85. 1, /* apple */
  86. 1, /* asante */
  87. 1, /* farallon */
  88. 1, /* cabletron */
  89. 0, /* dayna */
  90. 1, /* interlan */
  91. 0, /* kinetics */
  92. 1, /* focus (??) */
  93. 1, /* sonic systems */
  94. 1, /* dayna2 */
  95. 1, /* dayna-lc */
  96. };
  97. /* on which cards do we use NuBus resources? */
  98. static int useresources[] = {
  99. 1, /* apple */
  100. 1, /* asante */
  101. 1, /* farallon */
  102. 0, /* cabletron */
  103. 0, /* dayna */
  104. 0, /* interlan */
  105. 0, /* kinetics */
  106. 0, /* focus (??) */
  107. 1, /* sonic systems */
  108. 1, /* dayna2 */
  109. 1, /* dayna-lc */
  110. };
  111. extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
  112. extern int mac8390_memsize(unsigned long membase);
  113. extern int mac8390_memtest(struct net_device * dev);
  114. static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
  115. enum mac8390_type type);
  116. static int mac8390_open(struct net_device * dev);
  117. static int mac8390_close(struct net_device * dev);
  118. static void mac8390_no_reset(struct net_device *dev);
  119. /* Sane (32-bit chunk memory read/write) - Apple/Asante/Farallon do this*/
  120. static void sane_get_8390_hdr(struct net_device *dev,
  121. struct e8390_pkt_hdr *hdr, int ring_page);
  122. static void sane_block_input(struct net_device * dev, int count,
  123. struct sk_buff * skb, int ring_offset);
  124. static void sane_block_output(struct net_device * dev, int count,
  125. const unsigned char * buf, const int start_page);
  126. /* dayna_memcpy to and from card */
  127. static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
  128. int from, int count);
  129. static void dayna_memcpy_tocard(struct net_device *dev, int to,
  130. const void *from, int count);
  131. /* Dayna - Dayna/Kinetics use this */
  132. static void dayna_get_8390_hdr(struct net_device *dev,
  133. struct e8390_pkt_hdr *hdr, int ring_page);
  134. static void dayna_block_input(struct net_device *dev, int count,
  135. struct sk_buff *skb, int ring_offset);
  136. static void dayna_block_output(struct net_device *dev, int count,
  137. const unsigned char *buf, int start_page);
  138. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  139. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  140. /* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */
  141. static void slow_sane_get_8390_hdr(struct net_device *dev,
  142. struct e8390_pkt_hdr *hdr, int ring_page);
  143. static void slow_sane_block_input(struct net_device *dev, int count,
  144. struct sk_buff *skb, int ring_offset);
  145. static void slow_sane_block_output(struct net_device *dev, int count,
  146. const unsigned char *buf, int start_page);
  147. static void word_memcpy_tocard(void *tp, const void *fp, int count);
  148. static void word_memcpy_fromcard(void *tp, const void *fp, int count);
  149. enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
  150. {
  151. if (dev->dr_sw == NUBUS_DRSW_ASANTE)
  152. return MAC8390_ASANTE;
  153. if (dev->dr_sw == NUBUS_DRSW_FARALLON)
  154. return MAC8390_FARALLON;
  155. if (dev->dr_sw == NUBUS_DRSW_KINETICS)
  156. return MAC8390_KINETICS;
  157. if (dev->dr_sw == NUBUS_DRSW_DAYNA)
  158. return MAC8390_DAYNA;
  159. if (dev->dr_sw == NUBUS_DRSW_DAYNA2)
  160. return MAC8390_DAYNA2;
  161. if (dev->dr_sw == NUBUS_DRSW_DAYNA_LC)
  162. return MAC8390_DAYNA3;
  163. if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
  164. return MAC8390_CABLETRON;
  165. return MAC8390_NONE;
  166. }
  167. int __init mac8390_memsize(unsigned long membase)
  168. {
  169. unsigned long flags;
  170. int i, j;
  171. local_irq_save(flags);
  172. /* Check up to 32K in 4K increments */
  173. for (i = 0; i < 8; i++) {
  174. volatile unsigned short *m = (unsigned short *) (membase + (i * 0x1000));
  175. /* Unwriteable - we have a fully decoded card and the
  176. RAM end located */
  177. if (hwreg_present(m) == 0)
  178. break;
  179. /* write a distinctive byte */
  180. *m = 0xA5A0 | i;
  181. /* check that we read back what we wrote */
  182. if (*m != (0xA5A0 | i))
  183. break;
  184. /* check for partial decode and wrap */
  185. for (j = 0; j < i; j++) {
  186. volatile unsigned short *p = (unsigned short *) (membase + (j * 0x1000));
  187. if (*p != (0xA5A0 | j))
  188. break;
  189. }
  190. }
  191. local_irq_restore(flags);
  192. /* in any case, we stopped once we tried one block too many,
  193. or once we reached 32K */
  194. return i * 0x1000;
  195. }
  196. struct net_device * __init mac8390_probe(int unit)
  197. {
  198. struct net_device *dev;
  199. volatile unsigned short *i;
  200. int version_disp = 0;
  201. struct nubus_dev * ndev = NULL;
  202. int err = -ENODEV;
  203. struct nubus_dir dir;
  204. struct nubus_dirent ent;
  205. int offset;
  206. static unsigned int slots;
  207. enum mac8390_type cardtype;
  208. /* probably should check for Nubus instead */
  209. if (!MACH_IS_MAC)
  210. return ERR_PTR(-ENODEV);
  211. dev = ____alloc_ei_netdev(0);
  212. if (!dev)
  213. return ERR_PTR(-ENOMEM);
  214. if (unit >= 0)
  215. sprintf(dev->name, "eth%d", unit);
  216. SET_MODULE_OWNER(dev);
  217. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) {
  218. /* Have we seen it already? */
  219. if (slots & (1<<ndev->board->slot))
  220. continue;
  221. slots |= 1<<ndev->board->slot;
  222. if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
  223. continue;
  224. if (version_disp == 0) {
  225. version_disp = 1;
  226. printk(version);
  227. }
  228. dev->irq = SLOT2IRQ(ndev->board->slot);
  229. /* This is getting to be a habit */
  230. dev->base_addr = ndev->board->slot_addr | ((ndev->board->slot&0xf) << 20);
  231. /* Get some Nubus info - we will trust the card's idea
  232. of where its memory and registers are. */
  233. if (nubus_get_func_dir(ndev, &dir) == -1) {
  234. printk(KERN_ERR "%s: Unable to get Nubus functional"
  235. " directory for slot %X!\n",
  236. dev->name, ndev->board->slot);
  237. continue;
  238. }
  239. /* Get the MAC address */
  240. if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) {
  241. printk(KERN_INFO "%s: Couldn't get MAC address!\n",
  242. dev->name);
  243. continue;
  244. } else {
  245. nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
  246. /* Some Sonic Sys cards masquerade as Farallon */
  247. if (cardtype == MAC8390_FARALLON &&
  248. dev->dev_addr[0] == 0x0 &&
  249. dev->dev_addr[1] == 0x40 &&
  250. dev->dev_addr[2] == 0x10) {
  251. /* This is really Sonic Sys card */
  252. cardtype = MAC8390_SONICSYS;
  253. }
  254. }
  255. if (useresources[cardtype] == 1) {
  256. nubus_rewinddir(&dir);
  257. if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) {
  258. printk(KERN_ERR "%s: Memory offset resource"
  259. " for slot %X not found!\n",
  260. dev->name, ndev->board->slot);
  261. continue;
  262. }
  263. nubus_get_rsrc_mem(&offset, &ent, 4);
  264. dev->mem_start = dev->base_addr + offset;
  265. /* yes, this is how the Apple driver does it */
  266. dev->base_addr = dev->mem_start + 0x10000;
  267. nubus_rewinddir(&dir);
  268. if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, &ent) == -1) {
  269. printk(KERN_INFO "%s: Memory length resource"
  270. " for slot %X not found"
  271. ", probing\n",
  272. dev->name, ndev->board->slot);
  273. offset = mac8390_memsize(dev->mem_start);
  274. } else {
  275. nubus_get_rsrc_mem(&offset, &ent, 4);
  276. }
  277. dev->mem_end = dev->mem_start + offset;
  278. } else {
  279. switch (cardtype) {
  280. case MAC8390_KINETICS:
  281. case MAC8390_DAYNA: /* it's the same */
  282. dev->base_addr =
  283. (int)(ndev->board->slot_addr +
  284. DAYNA_8390_BASE);
  285. dev->mem_start =
  286. (int)(ndev->board->slot_addr +
  287. DAYNA_8390_MEM);
  288. dev->mem_end =
  289. dev->mem_start +
  290. mac8390_memsize(dev->mem_start);
  291. break;
  292. case MAC8390_CABLETRON:
  293. dev->base_addr =
  294. (int)(ndev->board->slot_addr +
  295. CABLETRON_8390_BASE);
  296. dev->mem_start =
  297. (int)(ndev->board->slot_addr +
  298. CABLETRON_8390_MEM);
  299. /* The base address is unreadable if 0x00
  300. * has been written to the command register
  301. * Reset the chip by writing E8390_NODMA +
  302. * E8390_PAGE0 + E8390_STOP just to be
  303. * sure
  304. */
  305. i = (void *)dev->base_addr;
  306. *i = 0x21;
  307. dev->mem_end =
  308. dev->mem_start +
  309. mac8390_memsize(dev->mem_start);
  310. break;
  311. default:
  312. printk(KERN_ERR "Card type %s is"
  313. " unsupported, sorry\n",
  314. cardname[cardtype]);
  315. continue;
  316. }
  317. }
  318. /* Do the nasty 8390 stuff */
  319. if (!mac8390_initdev(dev, ndev, cardtype))
  320. break;
  321. }
  322. if (!ndev)
  323. goto out;
  324. err = register_netdev(dev);
  325. if (err)
  326. goto out;
  327. return dev;
  328. out:
  329. free_netdev(dev);
  330. return ERR_PTR(err);
  331. }
  332. #ifdef MODULE
  333. MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
  334. MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
  335. MODULE_LICENSE("GPL");
  336. /* overkill, of course */
  337. static struct net_device *dev_mac8390[15];
  338. int init_module(void)
  339. {
  340. int i;
  341. for (i = 0; i < 15; i++) {
  342. struct net_device *dev = mac8390_probe(-1);
  343. if (IS_ERR(dev))
  344. break;
  345. dev_mac890[i] = dev;
  346. }
  347. if (!i) {
  348. printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n");
  349. return -ENODEV;
  350. }
  351. return 0;
  352. }
  353. void cleanup_module(void)
  354. {
  355. int i;
  356. for (i = 0; i < 15; i++) {
  357. struct net_device *dev = dev_mac890[i];
  358. if (dev) {
  359. unregister_netdev(dev);
  360. free_netdev(dev);
  361. }
  362. }
  363. }
  364. #endif /* MODULE */
  365. static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
  366. enum mac8390_type type)
  367. {
  368. static u32 fwrd4_offsets[16]={
  369. 0, 4, 8, 12,
  370. 16, 20, 24, 28,
  371. 32, 36, 40, 44,
  372. 48, 52, 56, 60
  373. };
  374. static u32 back4_offsets[16]={
  375. 60, 56, 52, 48,
  376. 44, 40, 36, 32,
  377. 28, 24, 20, 16,
  378. 12, 8, 4, 0
  379. };
  380. static u32 fwrd2_offsets[16]={
  381. 0, 2, 4, 6,
  382. 8, 10, 12, 14,
  383. 16, 18, 20, 22,
  384. 24, 26, 28, 30
  385. };
  386. int access_bitmode;
  387. /* Now fill in our stuff */
  388. dev->open = &mac8390_open;
  389. dev->stop = &mac8390_close;
  390. #ifdef CONFIG_NET_POLL_CONTROLLER
  391. dev->poll_controller = __ei_poll;
  392. #endif
  393. /* GAR, ei_status is actually a macro even though it looks global */
  394. ei_status.name = cardname[type];
  395. ei_status.word16 = word16[type];
  396. /* Cabletron's TX/RX buffers are backwards */
  397. if (type == MAC8390_CABLETRON) {
  398. ei_status.tx_start_page = CABLETRON_TX_START_PG;
  399. ei_status.rx_start_page = CABLETRON_RX_START_PG;
  400. ei_status.stop_page = CABLETRON_RX_STOP_PG;
  401. ei_status.rmem_start = dev->mem_start;
  402. ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
  403. } else {
  404. ei_status.tx_start_page = WD_START_PG;
  405. ei_status.rx_start_page = WD_START_PG + TX_PAGES;
  406. ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
  407. ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
  408. ei_status.rmem_end = dev->mem_end;
  409. }
  410. /* Fill in model-specific information and functions */
  411. switch(type) {
  412. case MAC8390_SONICSYS:
  413. /* 16 bit card, register map is reversed */
  414. ei_status.reset_8390 = &mac8390_no_reset;
  415. ei_status.block_input = &slow_sane_block_input;
  416. ei_status.block_output = &slow_sane_block_output;
  417. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  418. ei_status.reg_offset = back4_offsets;
  419. access_bitmode = 0;
  420. break;
  421. case MAC8390_FARALLON:
  422. case MAC8390_APPLE:
  423. case MAC8390_ASANTE:
  424. case MAC8390_DAYNA2:
  425. case MAC8390_DAYNA3:
  426. /* 32 bit card, register map is reversed */
  427. /* sane */
  428. ei_status.reset_8390 = &mac8390_no_reset;
  429. ei_status.block_input = &sane_block_input;
  430. ei_status.block_output = &sane_block_output;
  431. ei_status.get_8390_hdr = &sane_get_8390_hdr;
  432. ei_status.reg_offset = back4_offsets;
  433. access_bitmode = 1;
  434. break;
  435. case MAC8390_CABLETRON:
  436. /* 16 bit card, register map is short forward */
  437. ei_status.reset_8390 = &mac8390_no_reset;
  438. ei_status.block_input = &slow_sane_block_input;
  439. ei_status.block_output = &slow_sane_block_output;
  440. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  441. ei_status.reg_offset = fwrd2_offsets;
  442. access_bitmode = 0;
  443. break;
  444. case MAC8390_DAYNA:
  445. case MAC8390_KINETICS:
  446. /* 16 bit memory */
  447. /* dayna and similar */
  448. ei_status.reset_8390 = &mac8390_no_reset;
  449. ei_status.block_input = &dayna_block_input;
  450. ei_status.block_output = &dayna_block_output;
  451. ei_status.get_8390_hdr = &dayna_get_8390_hdr;
  452. ei_status.reg_offset = fwrd4_offsets;
  453. access_bitmode = 0;
  454. break;
  455. default:
  456. printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]);
  457. return -ENODEV;
  458. }
  459. __NS8390_init(dev, 0);
  460. /* Good, done, now spit out some messages */
  461. printk(KERN_INFO "%s: %s in slot %X (type %s)\n",
  462. dev->name, ndev->board->name, ndev->board->slot, cardname[type]);
  463. printk(KERN_INFO "MAC ");
  464. {
  465. int i;
  466. for (i = 0; i < 6; i++) {
  467. printk("%2.2x", dev->dev_addr[i]);
  468. if (i < 5)
  469. printk(":");
  470. }
  471. }
  472. printk(" IRQ %d, shared memory at %#lx-%#lx, %d-bit access.\n",
  473. dev->irq, dev->mem_start, dev->mem_end-1,
  474. access_bitmode?32:16);
  475. return 0;
  476. }
  477. static int mac8390_open(struct net_device *dev)
  478. {
  479. __ei_open(dev);
  480. if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) {
  481. printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
  482. return -EAGAIN;
  483. }
  484. return 0;
  485. }
  486. static int mac8390_close(struct net_device *dev)
  487. {
  488. free_irq(dev->irq, dev);
  489. __ei_close(dev);
  490. return 0;
  491. }
  492. static void mac8390_no_reset(struct net_device *dev)
  493. {
  494. ei_status.txing = 0;
  495. if (ei_debug > 1)
  496. printk("reset not supported\n");
  497. return;
  498. }
  499. /* dayna_memcpy_fromio/dayna_memcpy_toio */
  500. /* directly from daynaport.c by Alan Cox */
  501. static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
  502. {
  503. volatile unsigned char *ptr;
  504. unsigned char *target=to;
  505. from<<=1; /* word, skip overhead */
  506. ptr=(unsigned char *)(dev->mem_start+from);
  507. /* Leading byte? */
  508. if (from&2) {
  509. *target++ = ptr[-1];
  510. ptr += 2;
  511. count--;
  512. }
  513. while(count>=2)
  514. {
  515. *(unsigned short *)target = *(unsigned short volatile *)ptr;
  516. ptr += 4; /* skip cruft */
  517. target += 2;
  518. count-=2;
  519. }
  520. /* Trailing byte? */
  521. if(count)
  522. *target = *ptr;
  523. }
  524. static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
  525. {
  526. volatile unsigned short *ptr;
  527. const unsigned char *src=from;
  528. to<<=1; /* word, skip overhead */
  529. ptr=(unsigned short *)(dev->mem_start+to);
  530. /* Leading byte? */
  531. if (to&2) { /* avoid a byte write (stomps on other data) */
  532. ptr[-1] = (ptr[-1]&0xFF00)|*src++;
  533. ptr++;
  534. count--;
  535. }
  536. while(count>=2)
  537. {
  538. *ptr++=*(unsigned short *)src; /* Copy and */
  539. ptr++; /* skip cruft */
  540. src += 2;
  541. count-=2;
  542. }
  543. /* Trailing byte? */
  544. if(count)
  545. {
  546. /* card doesn't like byte writes */
  547. *ptr=(*ptr&0x00FF)|(*src << 8);
  548. }
  549. }
  550. /* sane block input/output */
  551. static void sane_get_8390_hdr(struct net_device *dev,
  552. struct e8390_pkt_hdr *hdr, int ring_page)
  553. {
  554. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  555. memcpy_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4);
  556. /* Fix endianness */
  557. hdr->count = swab16(hdr->count);
  558. }
  559. static void sane_block_input(struct net_device *dev, int count,
  560. struct sk_buff *skb, int ring_offset)
  561. {
  562. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  563. unsigned long xfer_start = xfer_base + dev->mem_start;
  564. if (xfer_start + count > ei_status.rmem_end) {
  565. /* We must wrap the input move. */
  566. int semi_count = ei_status.rmem_end - xfer_start;
  567. memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, semi_count);
  568. count -= semi_count;
  569. memcpy_toio(skb->data + semi_count, (char *)ei_status.rmem_start, count);
  570. } else {
  571. memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, count);
  572. }
  573. }
  574. static void sane_block_output(struct net_device *dev, int count,
  575. const unsigned char *buf, int start_page)
  576. {
  577. long shmem = (start_page - WD_START_PG)<<8;
  578. memcpy_toio((char *)dev->mem_start + shmem, buf, count);
  579. }
  580. /* dayna block input/output */
  581. static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  582. {
  583. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  584. dayna_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4);
  585. /* Fix endianness */
  586. hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
  587. }
  588. static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  589. {
  590. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  591. unsigned long xfer_start = xfer_base+dev->mem_start;
  592. /* Note the offset math is done in card memory space which is word
  593. per long onto our space. */
  594. if (xfer_start + count > ei_status.rmem_end)
  595. {
  596. /* We must wrap the input move. */
  597. int semi_count = ei_status.rmem_end - xfer_start;
  598. dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
  599. count -= semi_count;
  600. dayna_memcpy_fromcard(dev, skb->data + semi_count,
  601. ei_status.rmem_start - dev->mem_start,
  602. count);
  603. }
  604. else
  605. {
  606. dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
  607. }
  608. }
  609. static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf,
  610. int start_page)
  611. {
  612. long shmem = (start_page - WD_START_PG)<<8;
  613. dayna_memcpy_tocard(dev, shmem, buf, count);
  614. }
  615. /* Cabletron block I/O */
  616. static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  617. int ring_page)
  618. {
  619. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  620. word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
  621. /* Register endianism - fix here rather than 8390.c */
  622. hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
  623. }
  624. static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  625. int ring_offset)
  626. {
  627. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  628. unsigned long xfer_start = xfer_base+dev->mem_start;
  629. if (xfer_start + count > ei_status.rmem_end)
  630. {
  631. /* We must wrap the input move. */
  632. int semi_count = ei_status.rmem_end - xfer_start;
  633. word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
  634. xfer_base, semi_count);
  635. count -= semi_count;
  636. word_memcpy_fromcard(skb->data + semi_count,
  637. (char *)ei_status.rmem_start, count);
  638. }
  639. else
  640. {
  641. word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
  642. xfer_base, count);
  643. }
  644. }
  645. static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
  646. int start_page)
  647. {
  648. long shmem = (start_page - WD_START_PG)<<8;
  649. word_memcpy_tocard((char *)dev->mem_start + shmem, buf, count);
  650. }
  651. static void word_memcpy_tocard(void *tp, const void *fp, int count)
  652. {
  653. volatile unsigned short *to = tp;
  654. const unsigned short *from = fp;
  655. count++;
  656. count/=2;
  657. while(count--)
  658. *to++=*from++;
  659. }
  660. static void word_memcpy_fromcard(void *tp, const void *fp, int count)
  661. {
  662. unsigned short *to = tp;
  663. const volatile unsigned short *from = fp;
  664. count++;
  665. count/=2;
  666. while(count--)
  667. *to++=*from++;
  668. }