Commit 91d6d308 authored by David S. Miller's avatar David S. Miller

Sun HME/GEM driver probing cleanups.

parent d241f6b4
......@@ -2923,21 +2923,21 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
return -ENODEV;
}
dev = init_etherdev(NULL, sizeof(*gp));
dev = alloc_etherdev(sizeof(*gp));
if (!dev) {
printk(KERN_ERR PFX "Etherdev init failed, aborting.\n");
printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
if (!request_mem_region(gemreg_base, gemreg_len, dev->name)) {
printk(KERN_ERR PFX "MMIO resource (0x%lx@0x%lx) unavailable, "
"aborting.\n", gemreg_base, gemreg_len);
gp = dev->priv;
if (pci_request_regions(pdev, dev->name)) {
printk(KERN_ERR PFX "Cannot obtain PCI resources, "
"aborting.\n");
goto err_out_free_netdev;
}
gp = dev->priv;
gp->pdev = pdev;
dev->base_addr = (long) pdev;
gp->dev = dev;
......@@ -2970,7 +2970,7 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
if (gp->regs == 0UL) {
printk(KERN_ERR PFX "Cannot map device registers, "
"aborting.\n");
goto err_out_free_mmio_res;
goto err_out_free_res;
}
/* On Apple, we power the chip up now in order for check
......@@ -3006,22 +3006,28 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
goto err_out_iounmap;
}
pci_set_drvdata(pdev, dev);
printk(KERN_INFO "%s: Sun GEM (PCI) 10/100/1000BaseT Ethernet ",
dev->name);
#ifdef CONFIG_ALL_PPC
gp->of_node = pci_device_to_OF_node(pdev);
#endif
if (gem_get_device_address(gp))
goto err_out_iounmap;
goto err_out_free_consistent;
if (register_netdev(dev)) {
printk(KERN_ERR PFX "Cannot register net device, "
"aborting.\n");
goto err_out_free_consistent;
}
printk(KERN_INFO "%s: Sun GEM (PCI) 10/100/1000BaseT Ethernet ",
dev->name);
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],
i == 5 ? ' ' : ':');
printk("\n");
pci_set_drvdata(pdev, dev);
dev->open = gem_open;
dev->stop = gem_close;
dev->hard_start_xmit = gem_start_xmit;
......@@ -3045,6 +3051,12 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
return 0;
err_out_free_consistent:
pci_free_consistent(pdev,
sizeof(struct gem_init_block),
gp->init_block,
gp->gblock_dvma);
err_out_iounmap:
down(&gp->pm_sem);
/* Stop the PM timer & task */
......@@ -3053,13 +3065,13 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
if (gp->hw_running)
gem_shutdown(gp);
up(&gp->pm_sem);
iounmap((void *) gp->regs);
err_out_free_mmio_res:
release_mem_region(gemreg_base, gemreg_len);
err_out_free_res:
pci_release_regions(pdev);
err_out_free_netdev:
unregister_netdev(dev);
kfree(dev);
return -ENODEV;
......@@ -3088,8 +3100,7 @@ static void __devexit gem_remove_one(struct pci_dev *pdev)
gp->init_block,
gp->gblock_dvma);
iounmap((void *) gp->regs);
release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
pci_release_regions(pdev);
kfree(dev);
pci_set_drvdata(pdev, NULL);
......
......@@ -2658,7 +2658,7 @@ static int __init happy_meal_sbus_init(struct sbus_dev *sdev, int is_qfe)
}
err = -ENOMEM;
dev = init_etherdev(NULL, sizeof(struct happy_meal));
dev = alloc_etherdev(sizeof(struct happy_meal));
if (!dev)
goto err_out;
SET_MODULE_OWNER(dev);
......@@ -2666,13 +2666,6 @@ static int __init happy_meal_sbus_init(struct sbus_dev *sdev, int is_qfe)
if (hme_version_printed++ == 0)
printk(KERN_INFO "%s", version);
if (qfe_slot != -1)
printk(KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ",
dev->name, qfe_slot);
else
printk(KERN_INFO "%s: HAPPY MEAL (SBUS) 10/100baseT Ethernet ",
dev->name);
/* If user did not specify a MAC address specifically, use
* the Quattro local-mac-address property...
*/
......@@ -2693,11 +2686,6 @@ static int __init happy_meal_sbus_init(struct sbus_dev *sdev, int is_qfe)
memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
}
for (i = 0; i < 6; i++)
printk("%2.2x%c",
dev->dev_addr[i], i == 5 ? ' ' : ':');
printk("\n");
hp = dev->priv;
memset(hp, 0, sizeof(*hp));
......@@ -2822,17 +2810,38 @@ static int __init happy_meal_sbus_init(struct sbus_dev *sdev, int is_qfe)
*/
happy_meal_set_initial_advertisement(hp);
ether_setup(dev);
if (register_netdev(hp->dev)) {
printk(KERN_ERR "happymeal: Cannot register net device, "
"aborting.\n");
goto err_out_free_consistent;
}
if (qfe_slot != -1)
printk(KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ",
dev->name, qfe_slot);
else
printk(KERN_INFO "%s: HAPPY MEAL (SBUS) 10/100baseT Ethernet ",
dev->name);
for (i = 0; i < 6; i++)
printk("%2.2x%c",
dev->dev_addr[i], i == 5 ? ' ' : ':');
printk("\n");
/* We are home free at this point, link us in to the happy
* device list.
*/
dev->ifindex = dev_new_index();
hp->next_module = root_happy_dev;
root_happy_dev = hp;
return 0;
err_out_free_consistent:
sbus_free_consistent(hp->happy_dev,
PAGE_SIZE,
hp->happy_block,
hp->hblock_dvma);
err_out_iounmap:
if (hp->gregs)
sbus_iounmap(hp->gregs, GREG_REG_SIZE);
......@@ -2846,7 +2855,6 @@ static int __init happy_meal_sbus_init(struct sbus_dev *sdev, int is_qfe)
sbus_iounmap(hp->tcvregs, TCVR_REG_SIZE);
err_out_free_netdev:
unregister_netdev(dev);
kfree(dev);
err_out:
......@@ -2996,7 +3004,7 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
goto err_out;
}
dev = init_etherdev(NULL, sizeof(struct happy_meal));
dev = alloc_etherdev(sizeof(struct happy_meal));
err = -ENOMEM;
if (!dev)
goto err_out;
......@@ -3005,29 +3013,6 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
if (hme_version_printed++ == 0)
printk(KERN_INFO "%s", version);
if (!qfe_slot) {
struct pci_dev *qpdev = qp->quattro_dev;
prom_name[0] = 0;
if (!strncmp(dev->name, "eth", 3)) {
int i = simple_strtoul(dev->name + 3, NULL, 10);
sprintf(prom_name, "-%d", i + 3);
}
printk(KERN_INFO "%s%s: Quattro HME (PCI/CheerIO) 10/100baseT Ethernet ", dev->name, prom_name);
if (qpdev->vendor == PCI_VENDOR_ID_DEC &&
qpdev->device == PCI_DEVICE_ID_DEC_21153)
printk("DEC 21153 PCI Bridge\n");
else
printk("unknown bridge %04x.%04x\n",
qpdev->vendor, qpdev->device);
}
if (qfe_slot != -1)
printk(KERN_INFO "%s: Quattro HME slot %d (PCI/CheerIO) 10/100baseT Ethernet ",
dev->name, qfe_slot);
else
printk(KERN_INFO "%s: HAPPY MEAL (PCI/CheerIO) 10/100BaseT Ethernet ",
dev->name);
dev->base_addr = (long) pdev;
hp = (struct happy_meal *)dev->priv;
......@@ -3049,9 +3034,15 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
printk(KERN_ERR "happymeal(PCI): Cannot find proper PCI device base address.\n");
goto err_out_clear_quattro;
}
if (pci_request_regions(pdev, dev->name)) {
printk(KERN_ERR "happymeal(PCI): Cannot obtain PCI resources, "
"aborting.\n");
goto err_out_clear_quattro;
}
if ((hpreg_base = (unsigned long) ioremap(hpreg_base, 0x8000)) == 0) {
printk(KERN_ERR "happymeal(PCI): Unable to remap card memory.\n");
return -ENODEV;
goto err_out_free_res;
}
for (i = 0; i < 6; i++) {
......@@ -3076,11 +3067,6 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
#endif
}
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i], i == 5 ? ' ' : ':');
printk("\n");
/* Layout registers. */
hp->gregs = (hpreg_base + 0x0000UL);
hp->etxregs = (hpreg_base + 0x2000UL);
......@@ -3159,12 +3145,44 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
*/
happy_meal_set_initial_advertisement(hp);
ether_setup(dev);
if (register_netdev(hp->dev)) {
printk(KERN_ERR "happymeal(PCI): Cannot register net device, "
"aborting.\n");
goto err_out_iounmap;
}
if (!qfe_slot) {
struct pci_dev *qpdev = qp->quattro_dev;
prom_name[0] = 0;
if (!strncmp(dev->name, "eth", 3)) {
int i = simple_strtoul(dev->name + 3, NULL, 10);
sprintf(prom_name, "-%d", i + 3);
}
printk(KERN_INFO "%s%s: Quattro HME (PCI/CheerIO) 10/100baseT Ethernet ", dev->name, prom_name);
if (qpdev->vendor == PCI_VENDOR_ID_DEC &&
qpdev->device == PCI_DEVICE_ID_DEC_21153)
printk("DEC 21153 PCI Bridge\n");
else
printk("unknown bridge %04x.%04x\n",
qpdev->vendor, qpdev->device);
}
if (qfe_slot != -1)
printk(KERN_INFO "%s: Quattro HME slot %d (PCI/CheerIO) 10/100baseT Ethernet ",
dev->name, qfe_slot);
else
printk(KERN_INFO "%s: HAPPY MEAL (PCI/CheerIO) 10/100BaseT Ethernet ",
dev->name);
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i], i == 5 ? ' ' : ':');
printk("\n");
/* We are home free at this point, link us in to the happy
* device list.
*/
dev->ifindex = dev_new_index();
hp->next_module = root_happy_dev;
root_happy_dev = hp;
......@@ -3173,11 +3191,13 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
err_out_iounmap:
iounmap((void *)hp->gregs);
err_out_free_res:
pci_release_regions(pdev);
err_out_clear_quattro:
if (qp != NULL)
qp->happy_meals[qfe_slot] = NULL;
unregister_netdev(dev);
kfree(dev);
err_out:
......@@ -3228,6 +3248,7 @@ static int __init happy_meal_pci_probe(void)
PCI_DEVICE_ID_SUN_HAPPYMEAL, pdev)) != NULL) {
if (pci_enable_device(pdev))
continue;
pci_set_master(pdev);
cards++;
happy_meal_pci_init(pdev);
}
......@@ -3302,6 +3323,7 @@ static void __exit happy_meal_cleanup_module(void)
hp->happy_block,
hp->hblock_dvma);
iounmap((void *)hp->gregs);
pci_release_regions(hp->happy_dev);
}
#endif
kfree(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment