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