Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / net / ethernet / 8390 / mac8390.c
blob2f91ce8dc614945649ffd73a7664f574c6c6b068
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.
7 This software may be used and distributed according to the terms of
8 the GNU Public License, incorporated herein by reference. */
10 /* 2000-02-28: support added for Dayna and Kinetics cards by
11 A.G.deWijn@phys.uu.nl */
12 /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */
13 /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */
14 /* 2001-05-15: support for Cabletron ported from old daynaport driver
15 * and fixed access to Sonic Sys card which masquerades as a Farallon
16 * by rayk@knightsmanor.org */
17 /* 2002-12-30: Try to support more cards, some clues from NetBSD driver */
18 /* 2003-12-26: Make sure Asante cards always work. */
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/fcntl.h>
26 #include <linux/interrupt.h>
27 #include <linux/ptrace.h>
28 #include <linux/ioport.h>
29 #include <linux/nubus.h>
30 #include <linux/in.h>
31 #include <linux/string.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/netdevice.h>
35 #include <linux/etherdevice.h>
36 #include <linux/skbuff.h>
37 #include <linux/bitops.h>
38 #include <linux/io.h>
40 #include <asm/dma.h>
41 #include <asm/hwtest.h>
42 #include <asm/macints.h>
44 static char version[] =
45 "v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
47 #define EI_SHIFT(x) (ei_local->reg_offset[x])
48 #define ei_inb(port) in_8(port)
49 #define ei_outb(val, port) out_8(port, val)
50 #define ei_inb_p(port) in_8(port)
51 #define ei_outb_p(val, port) out_8(port, val)
53 #include "lib8390.c"
55 #define WD_START_PG 0x00 /* First page of TX buffer */
56 #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */
57 #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */
58 #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG
59 /* First page of TX buffer */
62 * Unfortunately it seems we have to hardcode these for the moment
63 * Shouldn't the card know about this?
64 * Does anyone know where to read it off the card?
65 * Do we trust the data provided by the card?
68 #define DAYNA_8390_BASE 0x80000
69 #define DAYNA_8390_MEM 0x00000
71 #define CABLETRON_8390_BASE 0x90000
72 #define CABLETRON_8390_MEM 0x00000
74 #define INTERLAN_8390_BASE 0xE0000
75 #define INTERLAN_8390_MEM 0xD0000
77 enum mac8390_type {
78 MAC8390_NONE = -1,
79 MAC8390_APPLE,
80 MAC8390_ASANTE,
81 MAC8390_FARALLON,
82 MAC8390_CABLETRON,
83 MAC8390_DAYNA,
84 MAC8390_INTERLAN,
85 MAC8390_KINETICS,
88 static const char *cardname[] = {
89 "apple",
90 "asante",
91 "farallon",
92 "cabletron",
93 "dayna",
94 "interlan",
95 "kinetics",
98 static const int word16[] = {
99 1, /* apple */
100 1, /* asante */
101 1, /* farallon */
102 1, /* cabletron */
103 0, /* dayna */
104 1, /* interlan */
105 0, /* kinetics */
108 /* on which cards do we use NuBus resources? */
109 static const int useresources[] = {
110 1, /* apple */
111 1, /* asante */
112 1, /* farallon */
113 0, /* cabletron */
114 0, /* dayna */
115 0, /* interlan */
116 0, /* kinetics */
119 enum mac8390_access {
120 ACCESS_UNKNOWN = 0,
121 ACCESS_32,
122 ACCESS_16,
125 extern int mac8390_memtest(struct net_device *dev);
126 static int mac8390_initdev(struct net_device *dev,
127 struct nubus_rsrc *ndev,
128 enum mac8390_type type);
130 static int mac8390_open(struct net_device *dev);
131 static int mac8390_close(struct net_device *dev);
132 static void mac8390_no_reset(struct net_device *dev);
133 static void interlan_reset(struct net_device *dev);
135 /* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/
136 static void sane_get_8390_hdr(struct net_device *dev,
137 struct e8390_pkt_hdr *hdr, int ring_page);
138 static void sane_block_input(struct net_device *dev, int count,
139 struct sk_buff *skb, int ring_offset);
140 static void sane_block_output(struct net_device *dev, int count,
141 const unsigned char *buf, const int start_page);
143 /* dayna_memcpy to and from card */
144 static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
145 int from, int count);
146 static void dayna_memcpy_tocard(struct net_device *dev, int to,
147 const void *from, int count);
149 /* Dayna - Dayna/Kinetics use this */
150 static void dayna_get_8390_hdr(struct net_device *dev,
151 struct e8390_pkt_hdr *hdr, int ring_page);
152 static void dayna_block_input(struct net_device *dev, int count,
153 struct sk_buff *skb, int ring_offset);
154 static void dayna_block_output(struct net_device *dev, int count,
155 const unsigned char *buf, int start_page);
157 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
158 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
160 #define memcmp_withio(a, b, c) memcmp((a), (void *)(b), (c))
162 /* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */
163 static void slow_sane_get_8390_hdr(struct net_device *dev,
164 struct e8390_pkt_hdr *hdr, int ring_page);
165 static void slow_sane_block_input(struct net_device *dev, int count,
166 struct sk_buff *skb, int ring_offset);
167 static void slow_sane_block_output(struct net_device *dev, int count,
168 const unsigned char *buf, int start_page);
169 static void word_memcpy_tocard(unsigned long tp, const void *fp, int count);
170 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
171 static u32 mac8390_msg_enable;
173 static enum mac8390_type __init mac8390_ident(struct nubus_rsrc *fres)
175 switch (fres->dr_sw) {
176 case NUBUS_DRSW_3COM:
177 switch (fres->dr_hw) {
178 case NUBUS_DRHW_APPLE_SONIC_NB:
179 case NUBUS_DRHW_APPLE_SONIC_LC:
180 case NUBUS_DRHW_SONNET:
181 return MAC8390_NONE;
182 default:
183 return MAC8390_APPLE;
185 break;
187 case NUBUS_DRSW_APPLE:
188 switch (fres->dr_hw) {
189 case NUBUS_DRHW_ASANTE_LC:
190 return MAC8390_NONE;
191 case NUBUS_DRHW_CABLETRON:
192 return MAC8390_CABLETRON;
193 default:
194 return MAC8390_APPLE;
196 break;
198 case NUBUS_DRSW_ASANTE:
199 return MAC8390_ASANTE;
200 break;
202 case NUBUS_DRSW_TECHWORKS:
203 case NUBUS_DRSW_DAYNA2:
204 case NUBUS_DRSW_DAYNA_LC:
205 if (fres->dr_hw == NUBUS_DRHW_CABLETRON)
206 return MAC8390_CABLETRON;
207 else
208 return MAC8390_APPLE;
209 break;
211 case NUBUS_DRSW_FARALLON:
212 return MAC8390_FARALLON;
213 break;
215 case NUBUS_DRSW_KINETICS:
216 switch (fres->dr_hw) {
217 case NUBUS_DRHW_INTERLAN:
218 return MAC8390_INTERLAN;
219 default:
220 return MAC8390_KINETICS;
222 break;
224 case NUBUS_DRSW_DAYNA:
226 * These correspond to Dayna Sonic cards
227 * which use the macsonic driver
229 if (fres->dr_hw == NUBUS_DRHW_SMC9194 ||
230 fres->dr_hw == NUBUS_DRHW_INTERLAN)
231 return MAC8390_NONE;
232 else
233 return MAC8390_DAYNA;
234 break;
236 return MAC8390_NONE;
239 static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
241 unsigned long outdata = 0xA5A0B5B0;
242 unsigned long indata = 0x00000000;
243 /* Try writing 32 bits */
244 memcpy_toio(membase, &outdata, 4);
245 /* Now compare them */
246 if (memcmp_withio(&outdata, membase, 4) == 0)
247 return ACCESS_32;
248 /* Write 16 bit output */
249 word_memcpy_tocard(membase, &outdata, 4);
250 /* Now read it back */
251 word_memcpy_fromcard(&indata, membase, 4);
252 if (outdata == indata)
253 return ACCESS_16;
254 return ACCESS_UNKNOWN;
257 static int __init mac8390_memsize(unsigned long membase)
259 unsigned long flags;
260 int i, j;
262 local_irq_save(flags);
263 /* Check up to 32K in 4K increments */
264 for (i = 0; i < 8; i++) {
265 volatile unsigned short *m = (unsigned short *)(membase + (i * 0x1000));
267 /* Unwriteable - we have a fully decoded card and the
268 RAM end located */
269 if (hwreg_present(m) == 0)
270 break;
272 /* write a distinctive byte */
273 *m = 0xA5A0 | i;
274 /* check that we read back what we wrote */
275 if (*m != (0xA5A0 | i))
276 break;
278 /* check for partial decode and wrap */
279 for (j = 0; j < i; j++) {
280 volatile unsigned short *p = (unsigned short *)(membase + (j * 0x1000));
281 if (*p != (0xA5A0 | j))
282 break;
285 local_irq_restore(flags);
287 * in any case, we stopped once we tried one block too many,
288 * or once we reached 32K
290 return i * 0x1000;
293 static bool __init mac8390_init(struct net_device *dev,
294 struct nubus_rsrc *ndev,
295 enum mac8390_type cardtype)
297 struct nubus_dir dir;
298 struct nubus_dirent ent;
299 int offset;
300 volatile unsigned short *i;
302 printk_once(KERN_INFO pr_fmt("%s"), version);
304 dev->irq = SLOT2IRQ(ndev->board->slot);
305 /* This is getting to be a habit */
306 dev->base_addr = (ndev->board->slot_addr |
307 ((ndev->board->slot & 0xf) << 20));
310 * Get some Nubus info - we will trust the card's idea
311 * of where its memory and registers are.
314 if (nubus_get_func_dir(ndev, &dir) == -1) {
315 pr_err("%s: Unable to get Nubus functional directory for slot %X!\n",
316 dev->name, ndev->board->slot);
317 return false;
320 /* Get the MAC address */
321 if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) {
322 pr_info("%s: Couldn't get MAC address!\n", dev->name);
323 return false;
326 nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
328 if (useresources[cardtype] == 1) {
329 nubus_rewinddir(&dir);
330 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS,
331 &ent) == -1) {
332 pr_err("%s: Memory offset resource for slot %X not found!\n",
333 dev->name, ndev->board->slot);
334 return false;
336 nubus_get_rsrc_mem(&offset, &ent, 4);
337 dev->mem_start = dev->base_addr + offset;
338 /* yes, this is how the Apple driver does it */
339 dev->base_addr = dev->mem_start + 0x10000;
340 nubus_rewinddir(&dir);
341 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH,
342 &ent) == -1) {
343 pr_info("%s: Memory length resource for slot %X not found, probing\n",
344 dev->name, ndev->board->slot);
345 offset = mac8390_memsize(dev->mem_start);
346 } else {
347 nubus_get_rsrc_mem(&offset, &ent, 4);
349 dev->mem_end = dev->mem_start + offset;
350 } else {
351 switch (cardtype) {
352 case MAC8390_KINETICS:
353 case MAC8390_DAYNA: /* it's the same */
354 dev->base_addr = (int)(ndev->board->slot_addr +
355 DAYNA_8390_BASE);
356 dev->mem_start = (int)(ndev->board->slot_addr +
357 DAYNA_8390_MEM);
358 dev->mem_end = dev->mem_start +
359 mac8390_memsize(dev->mem_start);
360 break;
361 case MAC8390_INTERLAN:
362 dev->base_addr = (int)(ndev->board->slot_addr +
363 INTERLAN_8390_BASE);
364 dev->mem_start = (int)(ndev->board->slot_addr +
365 INTERLAN_8390_MEM);
366 dev->mem_end = dev->mem_start +
367 mac8390_memsize(dev->mem_start);
368 break;
369 case MAC8390_CABLETRON:
370 dev->base_addr = (int)(ndev->board->slot_addr +
371 CABLETRON_8390_BASE);
372 dev->mem_start = (int)(ndev->board->slot_addr +
373 CABLETRON_8390_MEM);
374 /* The base address is unreadable if 0x00
375 * has been written to the command register
376 * Reset the chip by writing E8390_NODMA +
377 * E8390_PAGE0 + E8390_STOP just to be
378 * sure
380 i = (void *)dev->base_addr;
381 *i = 0x21;
382 dev->mem_end = dev->mem_start +
383 mac8390_memsize(dev->mem_start);
384 break;
386 default:
387 pr_err("Card type %s is unsupported, sorry\n",
388 ndev->board->name);
389 return false;
393 return true;
396 struct net_device * __init mac8390_probe(int unit)
398 struct net_device *dev;
399 struct nubus_rsrc *ndev = NULL;
400 int err = -ENODEV;
401 struct ei_device *ei_local;
403 static unsigned int slots;
405 enum mac8390_type cardtype;
407 /* probably should check for Nubus instead */
409 if (!MACH_IS_MAC)
410 return ERR_PTR(-ENODEV);
412 dev = ____alloc_ei_netdev(0);
413 if (!dev)
414 return ERR_PTR(-ENOMEM);
416 if (unit >= 0)
417 sprintf(dev->name, "eth%d", unit);
419 for_each_func_rsrc(ndev) {
420 if (ndev->category != NUBUS_CAT_NETWORK ||
421 ndev->type != NUBUS_TYPE_ETHERNET)
422 continue;
424 /* Have we seen it already? */
425 if (slots & (1 << ndev->board->slot))
426 continue;
427 slots |= 1 << ndev->board->slot;
429 cardtype = mac8390_ident(ndev);
430 if (cardtype == MAC8390_NONE)
431 continue;
433 if (!mac8390_init(dev, ndev, cardtype))
434 continue;
436 /* Do the nasty 8390 stuff */
437 if (!mac8390_initdev(dev, ndev, cardtype))
438 break;
441 if (!ndev)
442 goto out;
444 ei_local = netdev_priv(dev);
445 ei_local->msg_enable = mac8390_msg_enable;
447 err = register_netdev(dev);
448 if (err)
449 goto out;
450 return dev;
452 out:
453 free_netdev(dev);
454 return ERR_PTR(err);
457 #ifdef MODULE
458 MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
459 MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
460 MODULE_LICENSE("GPL");
462 static struct net_device *dev_mac8390;
464 int __init init_module(void)
466 dev_mac8390 = mac8390_probe(-1);
467 if (IS_ERR(dev_mac8390)) {
468 pr_warn("mac8390: No card found\n");
469 return PTR_ERR(dev_mac8390);
471 return 0;
474 void __exit cleanup_module(void)
476 unregister_netdev(dev_mac8390);
477 free_netdev(dev_mac8390);
480 #endif /* MODULE */
482 static const struct net_device_ops mac8390_netdev_ops = {
483 .ndo_open = mac8390_open,
484 .ndo_stop = mac8390_close,
485 .ndo_start_xmit = __ei_start_xmit,
486 .ndo_tx_timeout = __ei_tx_timeout,
487 .ndo_get_stats = __ei_get_stats,
488 .ndo_set_rx_mode = __ei_set_multicast_list,
489 .ndo_validate_addr = eth_validate_addr,
490 .ndo_set_mac_address = eth_mac_addr,
491 #ifdef CONFIG_NET_POLL_CONTROLLER
492 .ndo_poll_controller = __ei_poll,
493 #endif
496 static int __init mac8390_initdev(struct net_device *dev,
497 struct nubus_rsrc *ndev,
498 enum mac8390_type type)
500 static u32 fwrd4_offsets[16] = {
501 0, 4, 8, 12,
502 16, 20, 24, 28,
503 32, 36, 40, 44,
504 48, 52, 56, 60
506 static u32 back4_offsets[16] = {
507 60, 56, 52, 48,
508 44, 40, 36, 32,
509 28, 24, 20, 16,
510 12, 8, 4, 0
512 static u32 fwrd2_offsets[16] = {
513 0, 2, 4, 6,
514 8, 10, 12, 14,
515 16, 18, 20, 22,
516 24, 26, 28, 30
519 int access_bitmode = 0;
521 /* Now fill in our stuff */
522 dev->netdev_ops = &mac8390_netdev_ops;
524 /* GAR, ei_status is actually a macro even though it looks global */
525 ei_status.name = cardname[type];
526 ei_status.word16 = word16[type];
528 /* Cabletron's TX/RX buffers are backwards */
529 if (type == MAC8390_CABLETRON) {
530 ei_status.tx_start_page = CABLETRON_TX_START_PG;
531 ei_status.rx_start_page = CABLETRON_RX_START_PG;
532 ei_status.stop_page = CABLETRON_RX_STOP_PG;
533 ei_status.rmem_start = dev->mem_start;
534 ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
535 } else {
536 ei_status.tx_start_page = WD_START_PG;
537 ei_status.rx_start_page = WD_START_PG + TX_PAGES;
538 ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
539 ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
540 ei_status.rmem_end = dev->mem_end;
543 /* Fill in model-specific information and functions */
544 switch (type) {
545 case MAC8390_FARALLON:
546 case MAC8390_APPLE:
547 switch (mac8390_testio(dev->mem_start)) {
548 case ACCESS_UNKNOWN:
549 pr_err("Don't know how to access card memory!\n");
550 return -ENODEV;
552 case ACCESS_16:
553 /* 16 bit card, register map is reversed */
554 ei_status.reset_8390 = mac8390_no_reset;
555 ei_status.block_input = slow_sane_block_input;
556 ei_status.block_output = slow_sane_block_output;
557 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
558 ei_status.reg_offset = back4_offsets;
559 break;
561 case ACCESS_32:
562 /* 32 bit card, register map is reversed */
563 ei_status.reset_8390 = mac8390_no_reset;
564 ei_status.block_input = sane_block_input;
565 ei_status.block_output = sane_block_output;
566 ei_status.get_8390_hdr = sane_get_8390_hdr;
567 ei_status.reg_offset = back4_offsets;
568 access_bitmode = 1;
569 break;
571 break;
573 case MAC8390_ASANTE:
574 /* Some Asante cards pass the 32 bit test
575 * but overwrite system memory when run at 32 bit.
576 * so we run them all at 16 bit.
578 ei_status.reset_8390 = mac8390_no_reset;
579 ei_status.block_input = slow_sane_block_input;
580 ei_status.block_output = slow_sane_block_output;
581 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
582 ei_status.reg_offset = back4_offsets;
583 break;
585 case MAC8390_CABLETRON:
586 /* 16 bit card, register map is short forward */
587 ei_status.reset_8390 = mac8390_no_reset;
588 ei_status.block_input = slow_sane_block_input;
589 ei_status.block_output = slow_sane_block_output;
590 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
591 ei_status.reg_offset = fwrd2_offsets;
592 break;
594 case MAC8390_DAYNA:
595 case MAC8390_KINETICS:
596 /* 16 bit memory, register map is forward */
597 /* dayna and similar */
598 ei_status.reset_8390 = mac8390_no_reset;
599 ei_status.block_input = dayna_block_input;
600 ei_status.block_output = dayna_block_output;
601 ei_status.get_8390_hdr = dayna_get_8390_hdr;
602 ei_status.reg_offset = fwrd4_offsets;
603 break;
605 case MAC8390_INTERLAN:
606 /* 16 bit memory, register map is forward */
607 ei_status.reset_8390 = interlan_reset;
608 ei_status.block_input = slow_sane_block_input;
609 ei_status.block_output = slow_sane_block_output;
610 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
611 ei_status.reg_offset = fwrd4_offsets;
612 break;
614 default:
615 pr_err("Card type %s is unsupported, sorry\n",
616 ndev->board->name);
617 return -ENODEV;
620 __NS8390_init(dev, 0);
622 /* Good, done, now spit out some messages */
623 pr_info("%s: %s in slot %X (type %s)\n",
624 dev->name, ndev->board->name, ndev->board->slot,
625 cardname[type]);
626 pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
627 dev->dev_addr, dev->irq,
628 (unsigned int)(dev->mem_end - dev->mem_start) >> 10,
629 dev->mem_start, access_bitmode ? 32 : 16);
630 return 0;
633 static int mac8390_open(struct net_device *dev)
635 int err;
637 __ei_open(dev);
638 err = request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev);
639 if (err)
640 pr_err("%s: unable to get IRQ %d\n", dev->name, dev->irq);
641 return err;
644 static int mac8390_close(struct net_device *dev)
646 free_irq(dev->irq, dev);
647 __ei_close(dev);
648 return 0;
651 static void mac8390_no_reset(struct net_device *dev)
653 struct ei_device *ei_local = netdev_priv(dev);
655 ei_status.txing = 0;
656 netif_info(ei_local, hw, dev, "reset not supported\n");
659 static void interlan_reset(struct net_device *dev)
661 unsigned char *target = nubus_slot_addr(IRQ2SLOT(dev->irq));
662 struct ei_device *ei_local = netdev_priv(dev);
664 netif_info(ei_local, hw, dev, "Need to reset the NS8390 t=%lu...",
665 jiffies);
666 ei_status.txing = 0;
667 target[0xC0000] = 0;
668 if (netif_msg_hw(ei_local))
669 pr_cont("reset complete\n");
672 /* dayna_memcpy_fromio/dayna_memcpy_toio */
673 /* directly from daynaport.c by Alan Cox */
674 static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from,
675 int count)
677 volatile unsigned char *ptr;
678 unsigned char *target = to;
679 from <<= 1; /* word, skip overhead */
680 ptr = (unsigned char *)(dev->mem_start+from);
681 /* Leading byte? */
682 if (from & 2) {
683 *target++ = ptr[-1];
684 ptr += 2;
685 count--;
687 while (count >= 2) {
688 *(unsigned short *)target = *(unsigned short volatile *)ptr;
689 ptr += 4; /* skip cruft */
690 target += 2;
691 count -= 2;
693 /* Trailing byte? */
694 if (count)
695 *target = *ptr;
698 static void dayna_memcpy_tocard(struct net_device *dev, int to,
699 const void *from, int count)
701 volatile unsigned short *ptr;
702 const unsigned char *src = from;
703 to <<= 1; /* word, skip overhead */
704 ptr = (unsigned short *)(dev->mem_start+to);
705 /* Leading byte? */
706 if (to & 2) { /* avoid a byte write (stomps on other data) */
707 ptr[-1] = (ptr[-1]&0xFF00)|*src++;
708 ptr++;
709 count--;
711 while (count >= 2) {
712 *ptr++ = *(unsigned short *)src; /* Copy and */
713 ptr++; /* skip cruft */
714 src += 2;
715 count -= 2;
717 /* Trailing byte? */
718 if (count) {
719 /* card doesn't like byte writes */
720 *ptr = (*ptr & 0x00FF) | (*src << 8);
724 /* sane block input/output */
725 static void sane_get_8390_hdr(struct net_device *dev,
726 struct e8390_pkt_hdr *hdr, int ring_page)
728 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
729 memcpy_fromio(hdr, dev->mem_start + hdr_start, 4);
730 /* Fix endianness */
731 hdr->count = swab16(hdr->count);
734 static void sane_block_input(struct net_device *dev, int count,
735 struct sk_buff *skb, int ring_offset)
737 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
738 unsigned long xfer_start = xfer_base + dev->mem_start;
740 if (xfer_start + count > ei_status.rmem_end) {
741 /* We must wrap the input move. */
742 int semi_count = ei_status.rmem_end - xfer_start;
743 memcpy_fromio(skb->data, dev->mem_start + xfer_base,
744 semi_count);
745 count -= semi_count;
746 memcpy_fromio(skb->data + semi_count, ei_status.rmem_start,
747 count);
748 } else {
749 memcpy_fromio(skb->data, dev->mem_start + xfer_base, count);
753 static void sane_block_output(struct net_device *dev, int count,
754 const unsigned char *buf, int start_page)
756 long shmem = (start_page - WD_START_PG)<<8;
758 memcpy_toio(dev->mem_start + shmem, buf, count);
761 /* dayna block input/output */
762 static void dayna_get_8390_hdr(struct net_device *dev,
763 struct e8390_pkt_hdr *hdr, int ring_page)
765 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
767 dayna_memcpy_fromcard(dev, hdr, hdr_start, 4);
768 /* Fix endianness */
769 hdr->count = (hdr->count & 0xFF) << 8 | (hdr->count >> 8);
772 static void dayna_block_input(struct net_device *dev, int count,
773 struct sk_buff *skb, int ring_offset)
775 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
776 unsigned long xfer_start = xfer_base+dev->mem_start;
778 /* Note the offset math is done in card memory space which is word
779 per long onto our space. */
781 if (xfer_start + count > ei_status.rmem_end) {
782 /* We must wrap the input move. */
783 int semi_count = ei_status.rmem_end - xfer_start;
784 dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
785 count -= semi_count;
786 dayna_memcpy_fromcard(dev, skb->data + semi_count,
787 ei_status.rmem_start - dev->mem_start,
788 count);
789 } else {
790 dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
794 static void dayna_block_output(struct net_device *dev, int count,
795 const unsigned char *buf,
796 int start_page)
798 long shmem = (start_page - WD_START_PG)<<8;
800 dayna_memcpy_tocard(dev, shmem, buf, count);
803 /* Cabletron block I/O */
804 static void slow_sane_get_8390_hdr(struct net_device *dev,
805 struct e8390_pkt_hdr *hdr,
806 int ring_page)
808 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
809 word_memcpy_fromcard(hdr, dev->mem_start + hdr_start, 4);
810 /* Register endianism - fix here rather than 8390.c */
811 hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
814 static void slow_sane_block_input(struct net_device *dev, int count,
815 struct sk_buff *skb, int ring_offset)
817 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
818 unsigned long xfer_start = xfer_base+dev->mem_start;
820 if (xfer_start + count > ei_status.rmem_end) {
821 /* We must wrap the input move. */
822 int semi_count = ei_status.rmem_end - xfer_start;
823 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
824 semi_count);
825 count -= semi_count;
826 word_memcpy_fromcard(skb->data + semi_count,
827 ei_status.rmem_start, count);
828 } else {
829 word_memcpy_fromcard(skb->data, dev->mem_start + xfer_base,
830 count);
834 static void slow_sane_block_output(struct net_device *dev, int count,
835 const unsigned char *buf, int start_page)
837 long shmem = (start_page - WD_START_PG)<<8;
839 word_memcpy_tocard(dev->mem_start + shmem, buf, count);
842 static void word_memcpy_tocard(unsigned long tp, const void *fp, int count)
844 volatile unsigned short *to = (void *)tp;
845 const unsigned short *from = fp;
847 count++;
848 count /= 2;
850 while (count--)
851 *to++ = *from++;
854 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count)
856 unsigned short *to = tp;
857 const volatile unsigned short *from = (const void *)fp;
859 count++;
860 count /= 2;
862 while (count--)
863 *to++ = *from++;