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