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