diff options
author | Joe Perches <joe@perches.com> | 2010-01-04 06:53:03 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-01-06 23:44:04 -0500 |
commit | f6de7acc42de909ccc7f00916ddb4d2064f42b67 (patch) | |
tree | 2d482be42a0364625a341273f1f9bc2be0113f4a /drivers | |
parent | 8e4d9696b45d966c7af5b2aeb6f98ff687c58964 (diff) |
drivers/net/mac8390.c: Add mac8390_init function
Reduce indentation, make code a little neater.
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/mac8390.c | 207 |
1 files changed, 105 insertions, 102 deletions
diff --git a/drivers/net/mac8390.c b/drivers/net/mac8390.c index 8f168893caa..c70bd6888c8 100644 --- a/drivers/net/mac8390.c +++ b/drivers/net/mac8390.c | |||
@@ -295,16 +295,114 @@ static int __init mac8390_memsize(unsigned long membase) | |||
295 | return i * 0x1000; | 295 | return i * 0x1000; |
296 | } | 296 | } |
297 | 297 | ||
298 | static 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(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; | ||
398 | } | ||
399 | |||
298 | struct net_device * __init mac8390_probe(int unit) | 400 | struct net_device * __init mac8390_probe(int unit) |
299 | { | 401 | { |
300 | struct net_device *dev; | 402 | struct net_device *dev; |
301 | volatile unsigned short *i; | ||
302 | struct nubus_dev *ndev = NULL; | 403 | struct nubus_dev *ndev = NULL; |
303 | int err = -ENODEV; | 404 | int err = -ENODEV; |
304 | 405 | ||
305 | struct nubus_dir dir; | ||
306 | struct nubus_dirent ent; | ||
307 | int offset; | ||
308 | static unsigned int slots; | 406 | static unsigned int slots; |
309 | 407 | ||
310 | enum mac8390_type cardtype; | 408 | enum mac8390_type cardtype; |
@@ -324,111 +422,16 @@ struct net_device * __init mac8390_probe(int unit) | |||
324 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, | 422 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, |
325 | ndev))) { | 423 | ndev))) { |
326 | /* Have we seen it already? */ | 424 | /* Have we seen it already? */ |
327 | if (slots & (1<<ndev->board->slot)) | 425 | if (slots & (1 << ndev->board->slot)) |
328 | continue; | 426 | continue; |
329 | slots |= 1<<ndev->board->slot; | 427 | slots |= 1 << ndev->board->slot; |
330 | 428 | ||
331 | cardtype = mac8390_ident(ndev); | 429 | cardtype = mac8390_ident(ndev); |
332 | if (cardtype == MAC8390_NONE) | 430 | if (cardtype == MAC8390_NONE) |
333 | continue; | 431 | continue; |
334 | 432 | ||
335 | printk_once(KERN_INFO pr_fmt(version)); | 433 | if (!mac8390_init(dev, ndev, cardtype)) |
336 | |||
337 | dev->irq = SLOT2IRQ(ndev->board->slot); | ||
338 | /* This is getting to be a habit */ | ||
339 | dev->base_addr = (ndev->board->slot_addr | | ||
340 | ((ndev->board->slot & 0xf) << 20)); | ||
341 | |||
342 | /* Get some Nubus info - we will trust the card's idea | ||
343 | of where its memory and registers are. */ | ||
344 | |||
345 | if (nubus_get_func_dir(ndev, &dir) == -1) { | ||
346 | pr_err("%s: Unable to get Nubus functional directory for slot %X!\n", | ||
347 | dev->name, ndev->board->slot); | ||
348 | continue; | ||
349 | } | ||
350 | |||
351 | /* Get the MAC address */ | ||
352 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) { | ||
353 | pr_info("%s: Couldn't get MAC address!\n", dev->name); | ||
354 | continue; | 434 | continue; |
355 | } else { | ||
356 | nubus_get_rsrc_mem(dev->dev_addr, &ent, 6); | ||
357 | } | ||
358 | |||
359 | if (useresources[cardtype] == 1) { | ||
360 | nubus_rewinddir(&dir); | ||
361 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, | ||
362 | &ent) == -1) { | ||
363 | pr_err("%s: Memory offset resource for slot %X not found!\n", | ||
364 | dev->name, ndev->board->slot); | ||
365 | continue; | ||
366 | } | ||
367 | nubus_get_rsrc_mem(&offset, &ent, 4); | ||
368 | dev->mem_start = dev->base_addr + offset; | ||
369 | /* yes, this is how the Apple driver does it */ | ||
370 | dev->base_addr = dev->mem_start + 0x10000; | ||
371 | nubus_rewinddir(&dir); | ||
372 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, | ||
373 | &ent) == -1) { | ||
374 | pr_info("%s: Memory length resource for slot %X not found, probing\n", | ||
375 | dev->name, ndev->board->slot); | ||
376 | offset = mac8390_memsize(dev->mem_start); | ||
377 | } else { | ||
378 | nubus_get_rsrc_mem(&offset, &ent, 4); | ||
379 | } | ||
380 | dev->mem_end = dev->mem_start + offset; | ||
381 | } else { | ||
382 | switch (cardtype) { | ||
383 | case MAC8390_KINETICS: | ||
384 | case MAC8390_DAYNA: /* it's the same */ | ||
385 | dev->base_addr = | ||
386 | (int)(ndev->board->slot_addr + | ||
387 | DAYNA_8390_BASE); | ||
388 | dev->mem_start = | ||
389 | (int)(ndev->board->slot_addr + | ||
390 | DAYNA_8390_MEM); | ||
391 | dev->mem_end = | ||
392 | dev->mem_start + | ||
393 | mac8390_memsize(dev->mem_start); | ||
394 | break; | ||
395 | case MAC8390_INTERLAN: | ||
396 | dev->base_addr = | ||
397 | (int)(ndev->board->slot_addr + | ||
398 | INTERLAN_8390_BASE); | ||
399 | dev->mem_start = | ||
400 | (int)(ndev->board->slot_addr + | ||
401 | INTERLAN_8390_MEM); | ||
402 | dev->mem_end = | ||
403 | dev->mem_start + | ||
404 | mac8390_memsize(dev->mem_start); | ||
405 | break; | ||
406 | case MAC8390_CABLETRON: | ||
407 | dev->base_addr = | ||
408 | (int)(ndev->board->slot_addr + | ||
409 | CABLETRON_8390_BASE); | ||
410 | dev->mem_start = | ||
411 | (int)(ndev->board->slot_addr + | ||
412 | CABLETRON_8390_MEM); | ||
413 | /* The base address is unreadable if 0x00 | ||
414 | * has been written to the command register | ||
415 | * Reset the chip by writing E8390_NODMA + | ||
416 | * E8390_PAGE0 + E8390_STOP just to be | ||
417 | * sure | ||
418 | */ | ||
419 | i = (void *)dev->base_addr; | ||
420 | *i = 0x21; | ||
421 | dev->mem_end = | ||
422 | dev->mem_start + | ||
423 | mac8390_memsize(dev->mem_start); | ||
424 | break; | ||
425 | |||
426 | default: | ||
427 | pr_err("Card type %s is unsupported, sorry\n", | ||
428 | ndev->board->name); | ||
429 | continue; | ||
430 | } | ||
431 | } | ||
432 | 435 | ||
433 | /* Do the nasty 8390 stuff */ | 436 | /* Do the nasty 8390 stuff */ |
434 | if (!mac8390_initdev(dev, ndev, cardtype)) | 437 | if (!mac8390_initdev(dev, ndev, cardtype)) |