From: "Jiri Slaby" <[EMAIL PROTECTED]>

Pci probing functions added, some functions were rewritten.  Use PCI_DEVICE
macro.

Signed-off-by: Jiri Slaby <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 drivers/net/sunhme.c |   79 ++++++++++++++++++++++++++++-------------
 1 files changed, 55 insertions(+), 24 deletions(-)

diff -puN drivers/net/sunhme.c~happtmeal-add-pci-probing drivers/net/sunhme.c
--- devel/drivers/net/sunhme.c~happtmeal-add-pci-probing        2006-03-08 
00:09:31.000000000 -0800
+++ devel-akpm/drivers/net/sunhme.c     2006-03-08 00:09:31.000000000 -0800
@@ -3013,7 +3013,7 @@ static void get_hme_mac_nonsparc(struct 
 }
 #endif /* !(__sparc__) */
 
-static int __init happy_meal_pci_init(struct pci_dev *pdev)
+static int __devinit happy_meal_pci_init(struct pci_dev *pdev)
 {
        struct quattro *qp = NULL;
 #ifdef __sparc__
@@ -3073,6 +3073,7 @@ static int __init happy_meal_pci_init(st
        memset(hp, 0, sizeof(*hp));
 
        hp->happy_dev = pdev;
+       pci_dev_get(pdev);
 
        spin_lock_init(&hp->happy_lock);
 
@@ -3260,6 +3261,7 @@ err_out_free_res:
        pci_release_regions(pdev);
 
 err_out_clear_quattro:
+       pci_dev_put(pdev);
        if (qp != NULL)
                qp->happy_meals[qfe_slot] = NULL;
 
@@ -3304,21 +3306,58 @@ static int __init happy_meal_sbus_probe(
 #endif
 
 #ifdef CONFIG_PCI
-static int __init happy_meal_pci_probe(void)
+static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
+       const struct pci_device_id *id)
 {
-       struct pci_dev *pdev = NULL;
-       int cards = 0;
+       int retval;
+
+       retval = pci_enable_device(pdev);
+       if (retval < 0)
+               goto err;
+
+       pci_set_master(pdev);
+       happy_meal_pci_init(pdev);
+
+       return 0;
+err:
+       return retval;
+}
 
-       while ((pdev = pci_find_device(PCI_VENDOR_ID_SUN,
-                                      PCI_DEVICE_ID_SUN_HAPPYMEAL, pdev)) != 
NULL) {
-               if (pci_enable_device(pdev))
-                       continue;
-               pci_set_master(pdev);
-               cards++;
-               happy_meal_pci_init(pdev);
+static void __devexit happy_meal_pci_remove(struct pci_dev *pdev)
+{
+       struct quattro *tmp, *qp = qfe_pci_list;
+       struct pci_dev *bdev = pdev->bus->self;
+
+       if (qp->quattro_dev == bdev) { /* is it the 1st one? */
+               qfe_pci_list = qp->next;
+               kfree(qp);
+               goto end;
        }
-       return cards;
+
+       for (; qp->next != NULL; qp = qp->next) /* some further? */
+               if (qp->next->quattro_dev == bdev)
+                       break;
+
+       tmp = qp->next; /* kill it, but preserve list */
+       qp->next = qp->next->next;
+       kfree(tmp);
+end:
+       pci_dev_put(pdev);
 }
+
+static struct pci_device_id happy_meal_pci_tbl[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_HAPPYMEAL) },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, happy_meal_pci_tbl);
+
+static struct pci_driver happy_meal_pci_driver = {
+       .name           = "happy_meal_pci",
+       .id_table       = happy_meal_pci_tbl,
+       .probe          = happy_meal_pci_probe,
+       .remove         = __devexit_p(happy_meal_pci_remove)
+};
+
 #endif
 
 static int __init happy_meal_probe(void)
@@ -3337,11 +3376,10 @@ static int __init happy_meal_probe(void)
        cards += happy_meal_sbus_probe();
 #endif
 #ifdef CONFIG_PCI
-       cards += happy_meal_pci_probe();
+       return pci_register_driver(&happy_meal_pci_driver);
+#else
+       return cards ? 0 : -ENODEV;
 #endif
-       if (!cards)
-               return -ENODEV;
-       return 0;
 }
 
 
@@ -3408,14 +3446,7 @@ static void __exit happy_meal_cleanup_mo
        }
 #endif
 #ifdef CONFIG_PCI
-       while (qfe_pci_list) {
-               struct quattro *qfe = qfe_pci_list;
-               struct quattro *next = qfe->next;
-
-               kfree(qfe);
-
-               qfe_pci_list = next;
-       }
+       pci_unregister_driver(&happy_meal_pci_driver);
 #endif
 }
 
_
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to