[PATCH][RFC] tmspci.c using new pci api

From: Arnaldo Carvalho de Melo (acme@conectiva.com.br)
Date: Fri Aug 11 2000 - 10:39:37 EST


Hi,

         Could you please take a look at this patch, converting
drivers/net/tokenring/tmspci.c to the new pci API? It compiles, so it must be
good! 8)

                        - Arnaldo

--- linux-2.4.0-test6/drivers/net/tokenring/tmspci.c Sat Apr 29 03:00:05 2000
+++ linux-2.4.0-test6.acme/drivers/net/tokenring/tmspci.c Fri Aug 11 08:03:53 2000
@@ -16,15 +16,20 @@
  * Maintainer(s):
  * AF Adam Fritzler mid@auk.cx
  *
+ * Contributors:
+ * acme Arnaldo Carvalho de Melo acme@conectiva.com.br
+ *
  * Modification History:
  * 30-Dec-99 AF Split off from the tms380tr driver.
  * 22-Jan-00 AF Updated to use indirect read/writes
+ * 11-Aug-00 acme ported to new PCI API, new style
+ * module init/exit
  *
  * TODO:
  * 1. See if we can use MMIO instead of port accesses
  *
  */
-static const char *version = "tmspci.c: v1.01 22/01/2000 by Adam Fritzler\n";
+static const char *version = "tmspci.c: v1.02 08/11/2000 by Adam Fritzler\n";
 
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -42,30 +47,47 @@
 #include "tms380tr.h"
 
 #define TMS_PCI_IO_EXTENT 32
+#define TMS_PCI_MODULE_NAME "tmspci"
 
 struct cardinfo_table {
- int vendor_id; /* PCI info */
- int device_id;
         int registeroffset; /* SIF offset from dev->base_addr */
         unsigned char nselout[2]; /* NSELOUT vals for 4mb([0]) and 16mb([1]) */
         char *name;
 };
 
-struct cardinfo_table probelist[] = {
- { 0, 0,
- 0x0000, {0x00, 0x00}, "Unknown TMS380 Token Ring Adapter"},
- { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TOKENRING,
- 0x0000, {0x03, 0x01}, "Compaq 4/16 TR PCI"},
- { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_TR,
- 0x0000, {0x03, 0x01}, "SK NET TR 4/16 PCI"},
- { PCI_VENDOR_ID_TCONRAD, PCI_DEVICE_ID_TCONRAD_TOKENRING,
- 0x0000, {0x03, 0x01}, "Thomas-Conrad TC4048 PCI 4/16"},
- { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C339,
- 0x0000, {0x03, 0x01}, "3Com Token Link Velocity"},
- { 0, 0, 0, {0x00, 0x00}, NULL}
+typedef enum {
+ BOARD_COMPAQ_TOKENRING = 0,
+ BOARD_SYSKONNECT_TR,
+ BOARD_TCONRAD_TOKENRING,
+ BOARD_3COM_3C339,
+} board_t;
+
+/* indexed by board_t, above */
+
+struct cardinfo_table board_info[] = {
+ { 0x0000, {0x03, 0x01}, "Compaq 4/16 TR PCI"},
+ { 0x0000, {0x03, 0x01}, "SK NET TR 4/16 PCI"},
+ { 0x0000, {0x03, 0x01}, "Thomas-Conrad TC4048 PCI 4/16"},
+ { 0x0000, {0x03, 0x01}, "3Com Token Link Velocity"},
+};
+
+static struct pci_device_id tms_pci_pci_tbl[] __initdata =
+{
+ { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TOKENRING, PCI_ANY_ID, PCI_ANY_ID,
+ 0, 0, BOARD_COMPAQ_TOKENRING },
+ { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_TR, PCI_ANY_ID, PCI_ANY_ID,
+ 0, 0, BOARD_SYSKONNECT_TR },
+ { PCI_VENDOR_ID_TCONRAD, PCI_DEVICE_ID_TCONRAD_TOKENRING, PCI_ANY_ID, PCI_ANY_ID,
+ 0, 0, BOARD_TCONRAD_TOKENRING },
+ { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C339, PCI_ANY_ID, PCI_ANY_ID,
+ 0, 0, BOARD_3COM_3C339 },
+ {0,}
 };
 
-int tms_pci_probe(void);
+MODULE_DEVICE_TABLE (pci, tms_pci_pci_tbl);
+MODULE_AUTHOR ("Adam Fritzler <mid@auk.cx>");
+MODULE_DESCRIPTION ("TMS380-based PCI token ring cards driver");
+
 static int tms_pci_open(struct net_device *dev);
 static int tms_pci_close(struct net_device *dev);
 static void tms_pci_read_eeprom(struct net_device *dev);
@@ -91,145 +113,86 @@
         outw(val, dev->base_addr + reg);
 }
 
-struct tms_pci_card {
- struct net_device *dev;
- struct pci_dev *pci_dev;
- struct cardinfo_table *cardinfo;
- struct tms_pci_card *next;
-};
-static struct tms_pci_card *tms_pci_card_list = NULL;
-
-
-struct cardinfo_table * __init tms_pci_getcardinfo(unsigned short vendor,
- unsigned short device)
-{
- int cur;
- for (cur = 1; probelist[cur].name != NULL; cur++) {
- if ((probelist[cur].vendor_id == vendor) &&
- (probelist[cur].device_id == device))
- return &probelist[cur];
- }
-
- return NULL;
-}
-
-int __init tms_pci_probe(void)
+int __init tms_pci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
         static int versionprinted = 0;
- struct pci_dev *pdev = NULL ;
         struct net_device *dev;
         struct net_local *tp;
         int i;
+ unsigned long pci_ioaddr;
+ struct cardinfo_table *cardinfo = &board_info[ent->driver_data];
 
- if (!pci_present())
- return (-1); /* No PCI present. */
-
- while ( (pdev=pci_find_class(PCI_CLASS_NETWORK_TOKEN_RING<<8, pdev))) {
- unsigned int pci_irq_line;
- unsigned long pci_ioaddr;
- struct tms_pci_card *card;
- struct cardinfo_table *cardinfo;
-
- if ((cardinfo =
- tms_pci_getcardinfo(pdev->vendor, pdev->device)) == NULL)
- continue;
-
- if (versionprinted++ == 0)
- printk("%s", version);
-
- if (pci_enable_device(pdev))
- continue;
-
- /* Remove I/O space marker in bit 0. */
- pci_irq_line = pdev->irq;
- pci_ioaddr = pci_resource_start (pdev, 0);
-
- if(check_region(pci_ioaddr, TMS_PCI_IO_EXTENT))
- continue;
-
- /* At this point we have found a valid card. */
-
- dev = init_trdev(NULL, 0);
- if (!dev) {
- continue; /*return (-ENOMEM);*/ /* continue; ?? */
- }
-
- request_region(pci_ioaddr, TMS_PCI_IO_EXTENT, cardinfo->name); /* XXX check return */
- if(request_irq(pdev->irq, tms380tr_interrupt, SA_SHIRQ,
- cardinfo->name, dev)) {
- release_region(pci_ioaddr, TMS_PCI_IO_EXTENT);
- /* XXX free trdev */
- continue; /*return (-ENODEV);*/ /* continue; ?? */
- }
-
- /*
- if (load_tms380_module("tmspci.c")) {
- return 0;
- }
- */
-
- pci_ioaddr &= ~3 ;
- dev->base_addr = pci_ioaddr;
- dev->irq = pci_irq_line;
- dev->dma = 0;
-
- printk("%s: %s\n", dev->name, cardinfo->name);
- printk("%s: IO: %#4lx IRQ: %d\n",
- dev->name, dev->base_addr, dev->irq);
- /*
- * Some cards have their TMS SIF registers offset from
- * their given base address. Account for that here.
- */
- dev->base_addr += cardinfo->registeroffset;
+ if (versionprinted++ == 0)
+ printk(KERN_INFO "%s", version);
+
+ if (pci_enable_device(pdev))
+ return -ENODEV;
+
+ pci_ioaddr = pci_resource_start (pdev, 0);
+
+ if (!request_region(pci_ioaddr, TMS_PCI_IO_EXTENT, cardinfo->name))
+ return -EBUSY;
+
+ dev = init_trdev(NULL, 0);
+
+ if (!dev)
+ goto fail_init_trdev;
+
+ if (request_irq(pdev->irq, tms380tr_interrupt, SA_SHIRQ, cardinfo->name, dev))
+ goto fail_request_irq;
+
+ /* if (load_tms380_module("tmspci.c")) return 0; */
+
+ pci_ioaddr &= ~3 ;
+ dev->base_addr = pci_ioaddr;
+ dev->irq = pdev->irq;;
                 
- tms_pci_read_eeprom(dev);
+ printk(KERN_INFO "%s: %s\n", dev->name, cardinfo->name);
+ printk(KERN_INFO "%s: IO: %#4lx IRQ: %d\n", dev->name, dev->base_addr, dev->irq);
+
+ /*
+ * Some cards have their TMS SIF registers offset from
+ * their given base address. Account for that here.
+ */
 
- printk("%s: Ring Station Address: ", dev->name);
- printk("%2.2x", dev->dev_addr[0]);
- for (i = 1; i < 6; i++)
- printk(":%2.2x", dev->dev_addr[i]);
- printk("\n");
+ dev->base_addr += cardinfo->registeroffset;
                 
- if (tmsdev_init(dev)) {
- printk("%s: unable to get memory for dev->priv.\n", dev->name);
- return 0;
- }
-
- tp = (struct net_local *)dev->priv;
- tp->dmalimit = 0; /* XXX: should be the max PCI32 DMA max */
- tp->setnselout = tms_pci_setnselout_pins;
+ tms_pci_read_eeprom(dev);
+
+ printk(KERN_INFO "%s: Ring Station Address: ", dev->name);
+ printk(KERN_INFO "%2.2x", dev->dev_addr[0]);
+
+ for (i = 1; i < 6; i++)
+ printk(KERN_INFO ":%2.2x", dev->dev_addr[i]);
+ printk(KERN_INFO "\n");
                 
- tp->sifreadb = tms_pci_sifreadb;
- tp->sifreadw = tms_pci_sifreadw;
- tp->sifwriteb = tms_pci_sifwriteb;
- tp->sifwritew = tms_pci_sifwritew;
+ if (tmsdev_init(dev))
+ goto fail_tmsdev_init;
+
+ tp = (struct net_local *)dev->priv;
+ tp->dmalimit = 0; /* XXX: should be the max PCI32 DMA max */
+ tp->setnselout = tms_pci_setnselout_pins;
                 
- memcpy(tp->ProductID, cardinfo->name, PROD_ID_SIZE + 1);
+ tp->sifreadb = tms_pci_sifreadb;
+ tp->sifreadw = tms_pci_sifreadw;
+ tp->sifwriteb = tms_pci_sifwriteb;
+ tp->sifwritew = tms_pci_sifwritew;
+ tp->tmspriv = cardinfo;
+ memcpy(tp->ProductID, cardinfo->name, PROD_ID_SIZE + 1);
 
- tp->tmspriv = cardinfo;
+ dev->open = tms_pci_open;
+ dev->stop = tms_pci_close;
 
- dev->open = tms_pci_open;
- dev->stop = tms_pci_close;
+ pdev->driver_data = dev;
+ return 0;
 
- if (register_trdev(dev) == 0) {
- /* Enlist in the card list */
- card = kmalloc(sizeof(struct tms_pci_card), GFP_KERNEL);
- card->next = tms_pci_card_list;
- tms_pci_card_list = card;
- card->dev = dev;
- card->pci_dev = pdev;
- card->cardinfo = cardinfo;
- } else {
- printk("%s: register_trdev() returned non-zero.\n", dev->name);
- kfree(dev->priv);
- kfree(dev);
- return -1;
- }
- }
-
- if (tms_pci_card_list)
- return 0;
- return (-1);
+fail_tmsdev_init:
+fail_request_irq:
+ unregister_netdevice(dev);
+ kfree(dev);
+fail_init_trdev:
+ release_region(pci_ioaddr, TMS_PCI_IO_EXTENT);
+ return -1;
 }
 
 /*
@@ -282,51 +245,48 @@
         return 0;
 }
 
-#ifdef MODULE
-
-int init_module(void)
+static void __exit tms_pci_remove_one(struct pci_dev *pdev)
 {
- /* Probe for cards. */
- if (tms_pci_probe()) {
- printk(KERN_NOTICE "tmspci.c: No cards found.\n");
+ struct net_device *dev = pdev->driver_data;
+
+ /*
+ * If we used a register offset, revert here.
+ */
+
+ if (dev->priv) {
+ struct net_local *tp = (struct net_local *)dev->priv;
+ struct cardinfo_table *cardinfo = (struct cardinfo_table *)tp->tmspriv;
+
+ dev->base_addr -= cardinfo->registeroffset;
         }
- /* lock_tms380_module(); */
- return (0);
+
+ unregister_netdev(dev);
+ release_region(dev->base_addr, TMS_PCI_IO_EXTENT);
+ free_irq(dev->irq, dev);
+ kfree(dev->priv);
+ kfree(dev);
+ /* unlock_tms380_module(); */
 }
 
-void cleanup_module(void)
+static struct pci_driver tms_pci_pci_driver = {
+ name: TMS_PCI_MODULE_NAME,
+ id_table: tms_pci_pci_tbl,
+ probe: tms_pci_init_one,
+ remove: tms_pci_remove_one,
+};
+
+static int __init tms_pci_init_module (void)
 {
- struct net_device *dev;
- struct tms_pci_card *this_card;
+ return pci_module_init(&tms_pci_pci_driver);
+}
 
- while (tms_pci_card_list) {
- dev = tms_pci_card_list->dev;
-
- /*
- * If we used a register offset, revert here.
- */
- if (dev->priv)
- {
- struct net_local *tp;
- struct cardinfo_table *cardinfo;
-
- tp = (struct net_local *)dev->priv;
- cardinfo = (struct cardinfo_table *)tp->tmspriv;
-
- dev->base_addr -= cardinfo->registeroffset;
- }
- unregister_netdev(dev);
- release_region(dev->base_addr, TMS_PCI_IO_EXTENT);
- free_irq(dev->irq, dev);
- kfree(dev->priv);
- kfree(dev);
- this_card = tms_pci_card_list;
- tms_pci_card_list = this_card->next;
- kfree(this_card);
- }
- /* unlock_tms380_module(); */
+static void __exit tms_pci_cleanup_module (void)
+{
+ pci_unregister_driver(&tms_pci_pci_driver);
 }
-#endif /* MODULE */
+
+module_init(tms_pci_init_module);
+module_exit(tms_pci_cleanup_module);
 
 
 /*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 21:00:24 EST