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