mac8390.c 21 KB

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