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