blob: 90b0c3ed4bb6edede5f2d31fc768e26e9d8dcc68 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Jeff Garzik6aa20a22006-09-13 13:24:59 -040010/* 2000-02-28: support added for Dayna and Kinetics cards by
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 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
Jeff Garzik6aa20a22006-09-13 13:24:59 -040015 * and fixed access to Sonic Sys card which masquerades as a Farallon
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * by rayk@knightsmanor.org */
Finn Thain2964db02007-05-01 22:32:54 +020017/* 2002-12-30: Try to support more cards, some clues from NetBSD driver */
18/* 2003-12-26: Make sure Asante cards always work. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/types.h>
23#include <linux/fcntl.h>
24#include <linux/interrupt.h>
25#include <linux/ptrace.h>
26#include <linux/ioport.h>
27#include <linux/nubus.h>
28#include <linux/in.h>
29#include <linux/slab.h>
30#include <linux/string.h>
31#include <linux/errno.h>
32#include <linux/init.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/skbuff.h>
36#include <linux/bitops.h>
37
38#include <asm/system.h>
39#include <asm/io.h>
40#include <asm/dma.h>
41#include <asm/hwtest.h>
42#include <asm/macints.h>
43
Al Viro8c6270f2006-10-10 00:19:36 +010044static char version[] =
45 "mac8390.c: 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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
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 /* First page of TX buffer */
59
60/* Unfortunately it seems we have to hardcode these for the moment */
61/* 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? */
62
63#define DAYNA_8390_BASE 0x80000
64#define DAYNA_8390_MEM 0x00000
65
Jeff Garzik6aa20a22006-09-13 13:24:59 -040066#define CABLETRON_8390_BASE 0x90000
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define CABLETRON_8390_MEM 0x00000
68
Finn Thain2964db02007-05-01 22:32:54 +020069#define INTERLAN_8390_BASE 0xE0000
70#define INTERLAN_8390_MEM 0xD0000
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072enum mac8390_type {
73 MAC8390_NONE = -1,
74 MAC8390_APPLE,
75 MAC8390_ASANTE,
Finn Thain2964db02007-05-01 22:32:54 +020076 MAC8390_FARALLON,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 MAC8390_CABLETRON,
78 MAC8390_DAYNA,
79 MAC8390_INTERLAN,
80 MAC8390_KINETICS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
83static const char * cardname[] = {
84 "apple",
85 "asante",
86 "farallon",
87 "cabletron",
88 "dayna",
89 "interlan",
90 "kinetics",
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
92
93static int word16[] = {
94 1, /* apple */
95 1, /* asante */
96 1, /* farallon */
97 1, /* cabletron */
98 0, /* dayna */
99 1, /* interlan */
100 0, /* kinetics */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
103/* on which cards do we use NuBus resources? */
104static int useresources[] = {
105 1, /* apple */
106 1, /* asante */
107 1, /* farallon */
108 0, /* cabletron */
109 0, /* dayna */
110 0, /* interlan */
111 0, /* kinetics */
Finn Thain2964db02007-05-01 22:32:54 +0200112};
113
114enum mac8390_access {
115 ACCESS_UNKNOWN = 0,
116 ACCESS_32,
117 ACCESS_16,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
121extern int mac8390_memsize(unsigned long membase);
122extern int mac8390_memtest(struct net_device * dev);
123static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
124 enum mac8390_type type);
125
126static int mac8390_open(struct net_device * dev);
127static int mac8390_close(struct net_device * dev);
128static void mac8390_no_reset(struct net_device *dev);
Finn Thain2964db02007-05-01 22:32:54 +0200129static void interlan_reset(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Finn Thain2964db02007-05-01 22:32:54 +0200131/* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static void sane_get_8390_hdr(struct net_device *dev,
133 struct e8390_pkt_hdr *hdr, int ring_page);
134static void sane_block_input(struct net_device * dev, int count,
135 struct sk_buff * skb, int ring_offset);
136static 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 */
140static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
141 int from, int count);
142static void dayna_memcpy_tocard(struct net_device *dev, int to,
143 const void *from, int count);
144
145/* Dayna - Dayna/Kinetics use this */
146static void dayna_get_8390_hdr(struct net_device *dev,
147 struct e8390_pkt_hdr *hdr, int ring_page);
148static void dayna_block_input(struct net_device *dev, int count,
149 struct sk_buff *skb, int ring_offset);
150static 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 */
157static void slow_sane_get_8390_hdr(struct net_device *dev,
158 struct e8390_pkt_hdr *hdr, int ring_page);
159static void slow_sane_block_input(struct net_device *dev, int count,
160 struct sk_buff *skb, int ring_offset);
161static void slow_sane_block_output(struct net_device *dev, int count,
162 const unsigned char *buf, int start_page);
163static void word_memcpy_tocard(void *tp, const void *fp, int count);
164static void word_memcpy_fromcard(void *tp, const void *fp, int count);
165
166enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
167{
Finn Thain2964db02007-05-01 22:32:54 +0200168 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return MAC8390_NONE;
235}
236
Finn Thain2964db02007-05-01 22:32:54 +0200237enum 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((char *)membase, (char *)&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((char *)membase, (char *)&outdata, 4);
248 /* Now read it back */
249 word_memcpy_fromcard((char *)&indata, (char *)membase, 4);
250 if (outdata == indata)
251 return ACCESS_16;
252 return ACCESS_UNKNOWN;
253}
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255int __init mac8390_memsize(unsigned long membase)
256{
257 unsigned long flags;
258 int i, j;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 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;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 /* 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
289struct net_device * __init mac8390_probe(int unit)
290{
291 struct net_device *dev;
292 volatile unsigned short *i;
293 int version_disp = 0;
294 struct nubus_dev * ndev = NULL;
295 int err = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 struct nubus_dir dir;
298 struct nubus_dirent ent;
299 int offset;
300 static unsigned int slots;
301
302 enum mac8390_type cardtype;
303
304 /* probably should check for Nubus instead */
305
306 if (!MACH_IS_MAC)
307 return ERR_PTR(-ENODEV);
308
Al Viro8c6270f2006-10-10 00:19:36 +0100309 dev = ____alloc_ei_netdev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 if (!dev)
311 return ERR_PTR(-ENOMEM);
312
313 if (unit >= 0)
314 sprintf(dev->name, "eth%d", unit);
315
316 SET_MODULE_OWNER(dev);
317
318 while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) {
319 /* Have we seen it already? */
320 if (slots & (1<<ndev->board->slot))
321 continue;
322 slots |= 1<<ndev->board->slot;
323
324 if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
325 continue;
326
327 if (version_disp == 0) {
328 version_disp = 1;
329 printk(version);
330 }
331
332 dev->irq = SLOT2IRQ(ndev->board->slot);
333 /* This is getting to be a habit */
334 dev->base_addr = ndev->board->slot_addr | ((ndev->board->slot&0xf) << 20);
335
336 /* Get some Nubus info - we will trust the card's idea
337 of where its memory and registers are. */
338
339 if (nubus_get_func_dir(ndev, &dir) == -1) {
340 printk(KERN_ERR "%s: Unable to get Nubus functional"
341 " directory for slot %X!\n",
342 dev->name, ndev->board->slot);
343 continue;
344 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /* Get the MAC address */
347 if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) {
348 printk(KERN_INFO "%s: Couldn't get MAC address!\n",
349 dev->name);
350 continue;
351 } else {
352 nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (useresources[cardtype] == 1) {
356 nubus_rewinddir(&dir);
357 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) {
358 printk(KERN_ERR "%s: Memory offset resource"
359 " for slot %X not found!\n",
360 dev->name, ndev->board->slot);
361 continue;
362 }
363 nubus_get_rsrc_mem(&offset, &ent, 4);
364 dev->mem_start = dev->base_addr + offset;
365 /* yes, this is how the Apple driver does it */
366 dev->base_addr = dev->mem_start + 0x10000;
367 nubus_rewinddir(&dir);
368 if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, &ent) == -1) {
369 printk(KERN_INFO "%s: Memory length resource"
370 " for slot %X not found"
371 ", probing\n",
372 dev->name, ndev->board->slot);
373 offset = mac8390_memsize(dev->mem_start);
374 } else {
375 nubus_get_rsrc_mem(&offset, &ent, 4);
376 }
377 dev->mem_end = dev->mem_start + offset;
378 } else {
379 switch (cardtype) {
380 case MAC8390_KINETICS:
381 case MAC8390_DAYNA: /* it's the same */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400382 dev->base_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 (int)(ndev->board->slot_addr +
384 DAYNA_8390_BASE);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400385 dev->mem_start =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 (int)(ndev->board->slot_addr +
387 DAYNA_8390_MEM);
388 dev->mem_end =
389 dev->mem_start +
390 mac8390_memsize(dev->mem_start);
391 break;
Finn Thain2964db02007-05-01 22:32:54 +0200392 case MAC8390_INTERLAN:
393 dev->base_addr =
394 (int)(ndev->board->slot_addr +
395 INTERLAN_8390_BASE);
396 dev->mem_start =
397 (int)(ndev->board->slot_addr +
398 INTERLAN_8390_MEM);
399 dev->mem_end =
400 dev->mem_start +
401 mac8390_memsize(dev->mem_start);
402 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 case MAC8390_CABLETRON:
404 dev->base_addr =
405 (int)(ndev->board->slot_addr +
406 CABLETRON_8390_BASE);
407 dev->mem_start =
408 (int)(ndev->board->slot_addr +
409 CABLETRON_8390_MEM);
410 /* The base address is unreadable if 0x00
411 * has been written to the command register
412 * Reset the chip by writing E8390_NODMA +
413 * E8390_PAGE0 + E8390_STOP just to be
414 * sure
415 */
416 i = (void *)dev->base_addr;
417 *i = 0x21;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400418 dev->mem_end =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 dev->mem_start +
420 mac8390_memsize(dev->mem_start);
421 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 default:
424 printk(KERN_ERR "Card type %s is"
Finn Thain2964db02007-05-01 22:32:54 +0200425 " unsupported, sorry\n",
426 ndev->board->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 continue;
428 }
429 }
430
431 /* Do the nasty 8390 stuff */
432 if (!mac8390_initdev(dev, ndev, cardtype))
433 break;
434 }
435
436 if (!ndev)
437 goto out;
438 err = register_netdev(dev);
439 if (err)
440 goto out;
441 return dev;
442
443out:
444 free_netdev(dev);
445 return ERR_PTR(err);
446}
447
448#ifdef MODULE
449MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
450MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
451MODULE_LICENSE("GPL");
452
453/* overkill, of course */
454static struct net_device *dev_mac8390[15];
455int init_module(void)
456{
457 int i;
458 for (i = 0; i < 15; i++) {
459 struct net_device *dev = mac8390_probe(-1);
460 if (IS_ERR(dev))
461 break;
462 dev_mac890[i] = dev;
463 }
464 if (!i) {
465 printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n");
466 return -ENODEV;
467 }
468 return 0;
469}
470
471void cleanup_module(void)
472{
473 int i;
474 for (i = 0; i < 15; i++) {
475 struct net_device *dev = dev_mac890[i];
476 if (dev) {
477 unregister_netdev(dev);
478 free_netdev(dev);
479 }
480 }
481}
482
483#endif /* MODULE */
484
485static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
486 enum mac8390_type type)
487{
488 static u32 fwrd4_offsets[16]={
489 0, 4, 8, 12,
490 16, 20, 24, 28,
491 32, 36, 40, 44,
492 48, 52, 56, 60
493 };
494 static u32 back4_offsets[16]={
495 60, 56, 52, 48,
496 44, 40, 36, 32,
497 28, 24, 20, 16,
498 12, 8, 4, 0
499 };
500 static u32 fwrd2_offsets[16]={
501 0, 2, 4, 6,
502 8, 10, 12, 14,
503 16, 18, 20, 22,
504 24, 26, 28, 30
505 };
506
Finn Thain2964db02007-05-01 22:32:54 +0200507 int access_bitmode = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 /* Now fill in our stuff */
510 dev->open = &mac8390_open;
511 dev->stop = &mac8390_close;
512#ifdef CONFIG_NET_POLL_CONTROLLER
Al Viro8c6270f2006-10-10 00:19:36 +0100513 dev->poll_controller = __ei_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514#endif
515
516 /* GAR, ei_status is actually a macro even though it looks global */
517 ei_status.name = cardname[type];
518 ei_status.word16 = word16[type];
519
520 /* Cabletron's TX/RX buffers are backwards */
521 if (type == MAC8390_CABLETRON) {
522 ei_status.tx_start_page = CABLETRON_TX_START_PG;
523 ei_status.rx_start_page = CABLETRON_RX_START_PG;
524 ei_status.stop_page = CABLETRON_RX_STOP_PG;
525 ei_status.rmem_start = dev->mem_start;
526 ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
527 } else {
528 ei_status.tx_start_page = WD_START_PG;
529 ei_status.rx_start_page = WD_START_PG + TX_PAGES;
530 ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
531 ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
532 ei_status.rmem_end = dev->mem_end;
533 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* Fill in model-specific information and functions */
536 switch(type) {
Finn Thain2964db02007-05-01 22:32:54 +0200537 case MAC8390_FARALLON:
538 case MAC8390_APPLE:
539 switch(mac8390_testio(dev->mem_start)) {
540 case ACCESS_UNKNOWN:
541 printk("Don't know how to access card memory!\n");
542 return -ENODEV;
543 break;
544
545 case ACCESS_16:
546 /* 16 bit card, register map is reversed */
547 ei_status.reset_8390 = &mac8390_no_reset;
548 ei_status.block_input = &slow_sane_block_input;
549 ei_status.block_output = &slow_sane_block_output;
550 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
551 ei_status.reg_offset = back4_offsets;
552 break;
553
554 case ACCESS_32:
555 /* 32 bit card, register map is reversed */
556 ei_status.reset_8390 = &mac8390_no_reset;
557 ei_status.block_input = &sane_block_input;
558 ei_status.block_output = &sane_block_output;
559 ei_status.get_8390_hdr = &sane_get_8390_hdr;
560 ei_status.reg_offset = back4_offsets;
561 access_bitmode = 1;
562 break;
563 }
564 break;
565
566 case MAC8390_ASANTE:
567 /* Some Asante cards pass the 32 bit test
568 * but overwrite system memory when run at 32 bit.
569 * so we run them all at 16 bit.
570 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 ei_status.reset_8390 = &mac8390_no_reset;
572 ei_status.block_input = &slow_sane_block_input;
573 ei_status.block_output = &slow_sane_block_output;
574 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
575 ei_status.reg_offset = back4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 break;
Finn Thain2964db02007-05-01 22:32:54 +0200577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 case MAC8390_CABLETRON:
579 /* 16 bit card, register map is short forward */
580 ei_status.reset_8390 = &mac8390_no_reset;
581 ei_status.block_input = &slow_sane_block_input;
582 ei_status.block_output = &slow_sane_block_output;
583 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
584 ei_status.reg_offset = fwrd2_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 break;
Finn Thain2964db02007-05-01 22:32:54 +0200586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 case MAC8390_DAYNA:
588 case MAC8390_KINETICS:
Finn Thain2964db02007-05-01 22:32:54 +0200589 /* 16 bit memory, register map is forward */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 /* dayna and similar */
591 ei_status.reset_8390 = &mac8390_no_reset;
592 ei_status.block_input = &dayna_block_input;
593 ei_status.block_output = &dayna_block_output;
594 ei_status.get_8390_hdr = &dayna_get_8390_hdr;
595 ei_status.reg_offset = fwrd4_offsets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 break;
Finn Thain2964db02007-05-01 22:32:54 +0200597
598 case MAC8390_INTERLAN:
599 /* 16 bit memory, register map is forward */
600 ei_status.reset_8390 = &interlan_reset;
601 ei_status.block_input = &slow_sane_block_input;
602 ei_status.block_output = &slow_sane_block_output;
603 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
604 ei_status.reg_offset = fwrd4_offsets;
605 break;
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 default:
Finn Thain2964db02007-05-01 22:32:54 +0200608 printk(KERN_ERR "Card type %s is unsupported, sorry\n", ndev->board->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return -ENODEV;
610 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400611
Al Viro8c6270f2006-10-10 00:19:36 +0100612 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 /* Good, done, now spit out some messages */
615 printk(KERN_INFO "%s: %s in slot %X (type %s)\n",
616 dev->name, ndev->board->name, ndev->board->slot, cardname[type]);
617 printk(KERN_INFO "MAC ");
618 {
619 int i;
620 for (i = 0; i < 6; i++) {
621 printk("%2.2x", dev->dev_addr[i]);
622 if (i < 5)
623 printk(":");
624 }
625 }
Finn Thain2964db02007-05-01 22:32:54 +0200626 printk(" IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
627 dev->irq, (int)((dev->mem_end - dev->mem_start)/0x1000) * 4,
628 dev->mem_start, access_bitmode?32:16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return 0;
630}
631
632static int mac8390_open(struct net_device *dev)
633{
Al Viro8c6270f2006-10-10 00:19:36 +0100634 __ei_open(dev);
635 if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
637 return -EAGAIN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return 0;
640}
641
642static int mac8390_close(struct net_device *dev)
643{
644 free_irq(dev->irq, dev);
Al Viro8c6270f2006-10-10 00:19:36 +0100645 __ei_close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 return 0;
647}
648
649static void mac8390_no_reset(struct net_device *dev)
650{
651 ei_status.txing = 0;
652 if (ei_debug > 1)
653 printk("reset not supported\n");
654 return;
655}
656
Finn Thain2964db02007-05-01 22:32:54 +0200657static void interlan_reset(struct net_device *dev)
658{
659 unsigned char *target=nubus_slot_addr(IRQ2SLOT(dev->irq));
660 if (ei_debug > 1)
661 printk("Need to reset the NS8390 t=%lu...", jiffies);
662 ei_status.txing = 0;
663 target[0xC0000] = 0;
664 if (ei_debug > 1)
665 printk("reset complete\n");
666 return;
667}
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669/* dayna_memcpy_fromio/dayna_memcpy_toio */
670/* directly from daynaport.c by Alan Cox */
671static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
672{
Al Viro09cc07a2006-01-12 01:06:21 -0800673 volatile unsigned char *ptr;
674 unsigned char *target=to;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 from<<=1; /* word, skip overhead */
Al Viro09cc07a2006-01-12 01:06:21 -0800676 ptr=(unsigned char *)(dev->mem_start+from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* Leading byte? */
678 if (from&2) {
Al Viro09cc07a2006-01-12 01:06:21 -0800679 *target++ = ptr[-1];
680 ptr += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 count--;
682 }
683 while(count>=2)
684 {
Al Viro09cc07a2006-01-12 01:06:21 -0800685 *(unsigned short *)target = *(unsigned short volatile *)ptr;
686 ptr += 4; /* skip cruft */
687 target += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 count-=2;
689 }
690 /* Trailing byte? */
691 if(count)
Al Viro09cc07a2006-01-12 01:06:21 -0800692 *target = *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
696{
697 volatile unsigned short *ptr;
Al Viro09cc07a2006-01-12 01:06:21 -0800698 const unsigned char *src=from;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 to<<=1; /* word, skip overhead */
700 ptr=(unsigned short *)(dev->mem_start+to);
701 /* Leading byte? */
702 if (to&2) { /* avoid a byte write (stomps on other data) */
Al Viro09cc07a2006-01-12 01:06:21 -0800703 ptr[-1] = (ptr[-1]&0xFF00)|*src++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 ptr++;
705 count--;
706 }
707 while(count>=2)
708 {
Al Viro09cc07a2006-01-12 01:06:21 -0800709 *ptr++=*(unsigned short *)src; /* Copy and */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 ptr++; /* skip cruft */
Al Viro09cc07a2006-01-12 01:06:21 -0800711 src += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 count-=2;
713 }
714 /* Trailing byte? */
715 if(count)
716 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 /* card doesn't like byte writes */
Al Viro09cc07a2006-01-12 01:06:21 -0800718 *ptr=(*ptr&0x00FF)|(*src << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720}
721
722/* sane block input/output */
723static void sane_get_8390_hdr(struct net_device *dev,
724 struct e8390_pkt_hdr *hdr, int ring_page)
725{
726 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
727 memcpy_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4);
728 /* Fix endianness */
729 hdr->count = swab16(hdr->count);
730}
731
732static void sane_block_input(struct net_device *dev, int count,
733 struct sk_buff *skb, int ring_offset)
734{
735 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
736 unsigned long xfer_start = xfer_base + dev->mem_start;
737
738 if (xfer_start + count > ei_status.rmem_end) {
739 /* We must wrap the input move. */
740 int semi_count = ei_status.rmem_end - xfer_start;
741 memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, semi_count);
742 count -= semi_count;
743 memcpy_toio(skb->data + semi_count, (char *)ei_status.rmem_start, count);
744 } else {
745 memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, count);
746 }
747}
748
749static void sane_block_output(struct net_device *dev, int count,
750 const unsigned char *buf, int start_page)
751{
752 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 memcpy_toio((char *)dev->mem_start + shmem, buf, count);
755}
756
757/* dayna block input/output */
758static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
759{
760 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
761
762 dayna_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4);
763 /* Fix endianness */
764 hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
765}
766
767static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
768{
769 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
770 unsigned long xfer_start = xfer_base+dev->mem_start;
771
772 /* Note the offset math is done in card memory space which is word
773 per long onto our space. */
774
775 if (xfer_start + count > ei_status.rmem_end)
776 {
777 /* We must wrap the input move. */
778 int semi_count = ei_status.rmem_end - xfer_start;
779 dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
780 count -= semi_count;
781 dayna_memcpy_fromcard(dev, skb->data + semi_count,
782 ei_status.rmem_start - dev->mem_start,
783 count);
784 }
785 else
786 {
787 dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
788 }
789}
790
791static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf,
792 int start_page)
793{
794 long shmem = (start_page - WD_START_PG)<<8;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 dayna_memcpy_tocard(dev, shmem, buf, count);
797}
798
799/* Cabletron block I/O */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400800static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 int ring_page)
802{
803 unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
804 word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
805 /* Register endianism - fix here rather than 8390.c */
806 hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
807}
808
809static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb,
810 int ring_offset)
811{
812 unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
813 unsigned long xfer_start = xfer_base+dev->mem_start;
814
815 if (xfer_start + count > ei_status.rmem_end)
816 {
817 /* We must wrap the input move. */
818 int semi_count = ei_status.rmem_end - xfer_start;
819 word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
820 xfer_base, semi_count);
821 count -= semi_count;
822 word_memcpy_fromcard(skb->data + semi_count,
823 (char *)ei_status.rmem_start, count);
824 }
825 else
826 {
827 word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
828 xfer_base, count);
829 }
830}
831
832static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
833 int start_page)
834{
835 long shmem = (start_page - WD_START_PG)<<8;
836
837 word_memcpy_tocard((char *)dev->mem_start + shmem, buf, count);
838}
839
840static void word_memcpy_tocard(void *tp, const void *fp, int count)
841{
842 volatile unsigned short *to = tp;
843 const unsigned short *from = fp;
844
845 count++;
846 count/=2;
847
848 while(count--)
849 *to++=*from++;
850}
851
852static void word_memcpy_fromcard(void *tp, const void *fp, int count)
853{
854 unsigned short *to = tp;
855 const volatile unsigned short *from = fp;
856
857 count++;
858 count/=2;
859
860 while(count--)
861 *to++=*from++;
862}
863
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400864