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