]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
6aa20a22 | 10 | /* 2000-02-28: support added for Dayna and Kinetics cards by |
1da177e4 LT |
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 | |
6aa20a22 | 15 | * and fixed access to Sonic Sys card which masquerades as a Farallon |
1da177e4 | 16 | * by rayk@knightsmanor.org */ |
2964db0f FT |
17 | /* 2002-12-30: Try to support more cards, some clues from NetBSD driver */ |
18 | /* 2003-12-26: Make sure Asante cards always work. */ | |
1da177e4 | 19 | |
1da177e4 LT |
20 | #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 | ||
8c6270f9 AV |
44 | static 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" | |
1da177e4 LT |
54 | |
55 | #define WD_START_PG 0x00 /* First page of TX buffer */ | |
56 | #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */ | |
57 | #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */ | |
58 | #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG /* 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 | ||
6aa20a22 | 66 | #define CABLETRON_8390_BASE 0x90000 |
1da177e4 LT |
67 | #define CABLETRON_8390_MEM 0x00000 |
68 | ||
2964db0f FT |
69 | #define INTERLAN_8390_BASE 0xE0000 |
70 | #define INTERLAN_8390_MEM 0xD0000 | |
71 | ||
1da177e4 LT |
72 | enum mac8390_type { |
73 | MAC8390_NONE = -1, | |
74 | MAC8390_APPLE, | |
75 | MAC8390_ASANTE, | |
2964db0f | 76 | MAC8390_FARALLON, |
1da177e4 LT |
77 | MAC8390_CABLETRON, |
78 | MAC8390_DAYNA, | |
79 | MAC8390_INTERLAN, | |
80 | MAC8390_KINETICS, | |
1da177e4 LT |
81 | }; |
82 | ||
83 | static const char * cardname[] = { | |
84 | "apple", | |
85 | "asante", | |
86 | "farallon", | |
87 | "cabletron", | |
88 | "dayna", | |
89 | "interlan", | |
90 | "kinetics", | |
1da177e4 LT |
91 | }; |
92 | ||
93 | static int word16[] = { | |
94 | 1, /* apple */ | |
95 | 1, /* asante */ | |
96 | 1, /* farallon */ | |
97 | 1, /* cabletron */ | |
98 | 0, /* dayna */ | |
99 | 1, /* interlan */ | |
100 | 0, /* kinetics */ | |
1da177e4 LT |
101 | }; |
102 | ||
103 | /* on which cards do we use NuBus resources? */ | |
104 | static int useresources[] = { | |
105 | 1, /* apple */ | |
106 | 1, /* asante */ | |
107 | 1, /* farallon */ | |
108 | 0, /* cabletron */ | |
109 | 0, /* dayna */ | |
110 | 0, /* interlan */ | |
111 | 0, /* kinetics */ | |
2964db0f FT |
112 | }; |
113 | ||
114 | enum mac8390_access { | |
115 | ACCESS_UNKNOWN = 0, | |
116 | ACCESS_32, | |
117 | ACCESS_16, | |
1da177e4 LT |
118 | }; |
119 | ||
1da177e4 LT |
120 | extern enum mac8390_type mac8390_ident(struct nubus_dev * dev); |
121 | extern int mac8390_memsize(unsigned long membase); | |
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); | |
2964db0f | 129 | static void interlan_reset(struct net_device *dev); |
1da177e4 | 130 | |
2964db0f | 131 | /* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/ |
1da177e4 LT |
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 | enum mac8390_type __init mac8390_ident(struct nubus_dev * dev) | |
167 | { | |
2964db0f FT |
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 | } | |
1da177e4 LT |
234 | return MAC8390_NONE; |
235 | } | |
236 | ||
2964db0f FT |
237 | 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((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 | ||
1da177e4 LT |
255 | int __init mac8390_memsize(unsigned long membase) |
256 | { | |
257 | unsigned long flags; | |
258 | int i, j; | |
6aa20a22 | 259 | |
1da177e4 LT |
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; | |
6aa20a22 | 269 | |
1da177e4 LT |
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 | int version_disp = 0; | |
294 | struct nubus_dev * ndev = NULL; | |
295 | int err = -ENODEV; | |
6aa20a22 | 296 | |
1da177e4 LT |
297 | 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 | ||
8c6270f9 | 309 | dev = ____alloc_ei_netdev(0); |
1da177e4 LT |
310 | 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 | } | |
6aa20a22 | 345 | |
1da177e4 LT |
346 | /* 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); | |
1da177e4 | 353 | } |
6aa20a22 | 354 | |
1da177e4 LT |
355 | 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 */ | |
6aa20a22 | 382 | dev->base_addr = |
1da177e4 LT |
383 | (int)(ndev->board->slot_addr + |
384 | DAYNA_8390_BASE); | |
6aa20a22 | 385 | dev->mem_start = |
1da177e4 LT |
386 | (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; | |
2964db0f FT |
392 | 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; | |
1da177e4 LT |
403 | 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; | |
6aa20a22 | 418 | dev->mem_end = |
1da177e4 LT |
419 | dev->mem_start + |
420 | mac8390_memsize(dev->mem_start); | |
421 | break; | |
6aa20a22 | 422 | |
1da177e4 LT |
423 | default: |
424 | printk(KERN_ERR "Card type %s is" | |
2964db0f FT |
425 | " unsupported, sorry\n", |
426 | ndev->board->name); | |
1da177e4 LT |
427 | 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 | ||
443 | out: | |
444 | free_netdev(dev); | |
445 | return ERR_PTR(err); | |
446 | } | |
447 | ||
448 | #ifdef MODULE | |
449 | MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others"); | |
450 | MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver"); | |
451 | MODULE_LICENSE("GPL"); | |
452 | ||
453 | /* overkill, of course */ | |
454 | static struct net_device *dev_mac8390[15]; | |
455 | int 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 | ||
471 | void 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 | ||
485 | static 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 | ||
2964db0f | 507 | int access_bitmode = 0; |
6aa20a22 | 508 | |
1da177e4 LT |
509 | /* Now fill in our stuff */ |
510 | dev->open = &mac8390_open; | |
511 | dev->stop = &mac8390_close; | |
512 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
8c6270f9 | 513 | dev->poll_controller = __ei_poll; |
1da177e4 LT |
514 | #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 | } | |
6aa20a22 | 534 | |
1da177e4 LT |
535 | /* Fill in model-specific information and functions */ |
536 | switch(type) { | |
1da177e4 LT |
537 | case MAC8390_FARALLON: |
538 | case MAC8390_APPLE: | |
2964db0f FT |
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 | ||
1da177e4 | 566 | case MAC8390_ASANTE: |
2964db0f FT |
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 | */ | |
1da177e4 | 571 | ei_status.reset_8390 = &mac8390_no_reset; |
2964db0f FT |
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; | |
1da177e4 | 575 | ei_status.reg_offset = back4_offsets; |
1da177e4 | 576 | break; |
2964db0f | 577 | |
1da177e4 LT |
578 | 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; | |
1da177e4 | 585 | break; |
2964db0f | 586 | |
1da177e4 LT |
587 | case MAC8390_DAYNA: |
588 | case MAC8390_KINETICS: | |
2964db0f | 589 | /* 16 bit memory, register map is forward */ |
1da177e4 LT |
590 | /* 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; | |
1da177e4 | 596 | break; |
2964db0f FT |
597 | |
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 | ||
1da177e4 | 607 | default: |
2964db0f | 608 | printk(KERN_ERR "Card type %s is unsupported, sorry\n", ndev->board->name); |
1da177e4 LT |
609 | return -ENODEV; |
610 | } | |
6aa20a22 | 611 | |
8c6270f9 | 612 | __NS8390_init(dev, 0); |
1da177e4 LT |
613 | |
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 | } | |
2964db0f FT |
626 | 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); | |
1da177e4 LT |
629 | return 0; |
630 | } | |
631 | ||
632 | static int mac8390_open(struct net_device *dev) | |
633 | { | |
8c6270f9 AV |
634 | __ei_open(dev); |
635 | if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) { | |
1da177e4 LT |
636 | printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq); |
637 | return -EAGAIN; | |
6aa20a22 | 638 | } |
1da177e4 LT |
639 | return 0; |
640 | } | |
641 | ||
642 | static int mac8390_close(struct net_device *dev) | |
643 | { | |
644 | free_irq(dev->irq, dev); | |
8c6270f9 | 645 | __ei_close(dev); |
1da177e4 LT |
646 | return 0; |
647 | } | |
648 | ||
649 | static 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 | ||
2964db0f FT |
657 | static 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 | ||
1da177e4 LT |
669 | /* dayna_memcpy_fromio/dayna_memcpy_toio */ |
670 | /* directly from daynaport.c by Alan Cox */ | |
671 | static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count) | |
672 | { | |
09cc07a5 AV |
673 | volatile unsigned char *ptr; |
674 | unsigned char *target=to; | |
1da177e4 | 675 | from<<=1; /* word, skip overhead */ |
09cc07a5 | 676 | ptr=(unsigned char *)(dev->mem_start+from); |
1da177e4 LT |
677 | /* Leading byte? */ |
678 | if (from&2) { | |
09cc07a5 AV |
679 | *target++ = ptr[-1]; |
680 | ptr += 2; | |
1da177e4 LT |
681 | count--; |
682 | } | |
683 | while(count>=2) | |
684 | { | |
09cc07a5 AV |
685 | *(unsigned short *)target = *(unsigned short volatile *)ptr; |
686 | ptr += 4; /* skip cruft */ | |
687 | target += 2; | |
1da177e4 LT |
688 | count-=2; |
689 | } | |
690 | /* Trailing byte? */ | |
691 | if(count) | |
09cc07a5 | 692 | *target = *ptr; |
1da177e4 LT |
693 | } |
694 | ||
695 | static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count) | |
696 | { | |
697 | volatile unsigned short *ptr; | |
09cc07a5 | 698 | const unsigned char *src=from; |
1da177e4 LT |
699 | 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) */ | |
09cc07a5 | 703 | ptr[-1] = (ptr[-1]&0xFF00)|*src++; |
1da177e4 LT |
704 | ptr++; |
705 | count--; | |
706 | } | |
707 | while(count>=2) | |
708 | { | |
09cc07a5 | 709 | *ptr++=*(unsigned short *)src; /* Copy and */ |
1da177e4 | 710 | ptr++; /* skip cruft */ |
09cc07a5 | 711 | src += 2; |
1da177e4 LT |
712 | count-=2; |
713 | } | |
714 | /* Trailing byte? */ | |
715 | if(count) | |
716 | { | |
1da177e4 | 717 | /* card doesn't like byte writes */ |
09cc07a5 | 718 | *ptr=(*ptr&0x00FF)|(*src << 8); |
1da177e4 LT |
719 | } |
720 | } | |
721 | ||
722 | /* sane block input/output */ | |
723 | static 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 | ||
732 | static 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 | ||
749 | static 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; | |
6aa20a22 | 753 | |
1da177e4 LT |
754 | memcpy_toio((char *)dev->mem_start + shmem, buf, count); |
755 | } | |
756 | ||
757 | /* dayna block input/output */ | |
758 | static 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 | ||
767 | static 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 | ||
791 | static 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; | |
6aa20a22 | 795 | |
1da177e4 LT |
796 | dayna_memcpy_tocard(dev, shmem, buf, count); |
797 | } | |
798 | ||
799 | /* Cabletron block I/O */ | |
6aa20a22 | 800 | static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, |
1da177e4 LT |
801 | 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 | ||
809 | static 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 | ||
832 | static 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 | ||
840 | static 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 | ||
852 | static 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 | ||
6aa20a22 | 864 |