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