mac8390.c 21 KB

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