From b3c86b81ae638d90ee27a821e962e297ab85cbe4 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Wed, 17 Nov 2010 12:09:10 -0600 Subject: dahdi: register/unregister devices as opposed to individual spans. Increasingly, spans are implemented by devices that support more than a single span. Introduce a 'struct dahdi_device' object which explicitly contains multiple spans. This will also allow a cleaner representation of spans and devices in sysfs since order of arrival will not determine the layout of the devices. This also gives the core of dahdi a way to know the relationship between spans. Signed-off-by: Shaun Ruffell --- drivers/dahdi/wcte12xp/base.c | 52 ++++++++++++++++++++++++++------------- drivers/dahdi/wcte12xp/wcte12xp.h | 1 + 2 files changed, 36 insertions(+), 17 deletions(-) (limited to 'drivers/dahdi/wcte12xp') diff --git a/drivers/dahdi/wcte12xp/base.c b/drivers/dahdi/wcte12xp/base.c index a65b279..037fc9d 100644 --- a/drivers/dahdi/wcte12xp/base.c +++ b/drivers/dahdi/wcte12xp/base.c @@ -705,6 +705,9 @@ static void free_wc(struct t1 *wc) } #endif + kfree(wc->ddev->location); + kfree(wc->ddev->devicetype); + dahdi_free_device(wc->ddev); kfree(wc); } @@ -919,14 +922,23 @@ static void t1xxp_framer_start(struct t1 *wc, struct dahdi_span *span) static void set_span_devicetype(struct t1 *wc) { - strncpy(wc->span.devicetype, wc->variety, - sizeof(wc->span.devicetype) - 1); - + const char *olddevicetype; #if defined(VPM_SUPPORT) - if (wc->vpmadt032) - strncat(wc->span.devicetype, " (VPMADT032)", - sizeof(wc->span.devicetype) - 1); + bool have_vpm = (wc->vpmadt032) ? true : false; +#else + bool have_vpm = false; #endif + olddevicetype = wc->ddev->devicetype; + + wc->ddev->devicetype = kasprintf(GFP_KERNEL, + (have_vpm) ? "%s (VPMADT032)" : "%s", + wc->variety); + + /* On the off chance that we were able to allocate it previously. */ + if (!wc->ddev->devicetype) + wc->ddev->devicetype = olddevicetype; + else + kfree(olddevicetype); } static int t1xxp_startup(struct dahdi_span *span) @@ -1529,6 +1541,7 @@ static const struct dahdi_span_ops t1_span_ops = { static int t1_software_init(struct t1 *wc) { int x; + int res; int num; struct pci_dev *pdev = wc->vb.pdev; @@ -1548,12 +1561,15 @@ static int t1_software_init(struct t1 *wc) num = x; sprintf(wc->span.name, "WCT1/%d", num); snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, num); - wc->span.manufacturer = "Digium"; + wc->ddev->manufacturer = "Digium"; set_span_devicetype(wc); - snprintf(wc->span.location, sizeof(wc->span.location) - 1, - "PCI Bus %02d Slot %02d", pdev->bus->number, - PCI_SLOT(pdev->devfn) + 1); + wc->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d", + pdev->bus->number, + PCI_SLOT(pdev->devfn) + 1); + + if (!wc->ddev->location) + return -ENOMEM; wc->span.irq = pdev->irq; @@ -1579,9 +1595,11 @@ static int t1_software_init(struct t1 *wc) wc->chans[x]->chanpos = x + 1; } wc->span.ops = &t1_span_ops; - if (dahdi_register(&wc->span, 0)) { - t1_info(wc, "Unable to register span with DAHDI\n"); - return -1; + list_add_tail(&wc->span.device_node, &wc->ddev->spans); + res = dahdi_register_device(wc->ddev, &wc->vb.pdev->dev); + if (res) { + t1_info(wc, "Unable to register with DAHDI\n"); + return res; } set_bit(INITIALIZED, &wc->bit_flags); @@ -2256,13 +2274,13 @@ static int __devinit te12xp_init_one(struct pci_dev *pdev, const struct pci_devi return -EIO; } - if (!(wc = kmalloc(sizeof(*wc), GFP_KERNEL))) { + wc = kzalloc(sizeof(*wc), GFP_KERNEL); + if (!wc) return -ENOMEM; - } ifaces[index] = wc; - memset(wc, 0, sizeof(*wc)); wc->ledstate = -1; + wc->ddev = dahdi_create_device(); spin_lock_init(&wc->reglock); INIT_LIST_HEAD(&wc->active_cmds); INIT_LIST_HEAD(&wc->pending_cmds); @@ -2375,7 +2393,7 @@ static void __devexit te12xp_remove_one(struct pci_dev *pdev) if (!wc) return; - dahdi_unregister(&wc->span); + dahdi_unregister_device(wc->ddev); remove_sysfs_files(wc); diff --git a/drivers/dahdi/wcte12xp/wcte12xp.h b/drivers/dahdi/wcte12xp/wcte12xp.h index 5f6dbce..e2d5a6b 100644 --- a/drivers/dahdi/wcte12xp/wcte12xp.h +++ b/drivers/dahdi/wcte12xp/wcte12xp.h @@ -114,6 +114,7 @@ struct t1 { unsigned long bit_flags; unsigned long alarmtimer; unsigned char ledstate; + struct dahdi_device *ddev; struct dahdi_span span; /* Span */ struct dahdi_chan *chans[32]; /* Channels */ struct dahdi_echocan_state *ec[32]; /* Echocan state for channels */ -- cgit v1.2.3