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