[dahdi-commits] sruffell: linux/trunk r7778 - in /linux/trunk/drivers/dahdi: voicebus/ vpmadt...

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Fri Jan 8 14:48:06 CST 2010


Author: sruffell
Date: Fri Jan  8 14:48:02 2010
New Revision: 7778

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7778
Log:
voicebus: Make 'struct voicebus' embeddable by the client driver strutures.

In addition to making 'struct voicebus' embeddable, also add an
'voicebus_operations' structure.  This was done so that a) remove the "context"
pointer from struct voicebus, and also to show that handle_recieve/transmit are
to be managed together.

Modified:
    linux/trunk/drivers/dahdi/voicebus/GpakCust.c
    linux/trunk/drivers/dahdi/voicebus/voicebus.c
    linux/trunk/drivers/dahdi/voicebus/voicebus.h
    linux/trunk/drivers/dahdi/voicebus/vpmadtreg.h
    linux/trunk/drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c
    linux/trunk/drivers/dahdi/wctdm24xxp/base.c
    linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
    linux/trunk/drivers/dahdi/wcte12xp/base.c
    linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h

Modified: linux/trunk/drivers/dahdi/voicebus/GpakCust.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/GpakCust.c?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/GpakCust.c (original)
+++ linux/trunk/drivers/dahdi/voicebus/GpakCust.c Fri Jan  8 14:48:02 2010
@@ -54,7 +54,7 @@
 static struct vpmadt032 *ifaces[MAX_DSP_CORES];
 
 #define vpm_info(vpm, format, arg...)         \
-        dev_info(&voicebus_get_pci_dev(vpm->vb)->dev , format , ## arg)
+	dev_info(&vpm->vb->pdev->dev , format , ## arg)
 
 static inline struct vpmadt032 *find_iface(const unsigned short dspid)
 {
@@ -609,13 +609,12 @@
 
 	res = vpmadtreg_loadfirmware(vb);
 	if (res) {
-		struct pci_dev *pdev = voicebus_get_pci_dev(vb);
-		dev_printk(KERN_INFO, &pdev->dev, "Failed to load the firmware.\n");
+		dev_info(&vb->pdev->dev, "Failed to load the firmware.\n");
 		return res;
 	}
 	vpm->curpage = -1;
 
-	dev_info(&voicebus_get_pci_dev(vb)->dev, "Booting VPMADT032\n");
+	dev_info(&vb->pdev->dev, "Booting VPMADT032\n");
 	set_bit(VPM150M_SWRESET, &vpm->control);
 	while (test_bit(VPM150M_SWRESET, &vpm->control))
 		msleep(1);

Modified: linux/trunk/drivers/dahdi/voicebus/voicebus.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/voicebus.c?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/voicebus.c (original)
+++ linux/trunk/drivers/dahdi/voicebus/voicebus.c Fri Jan  8 14:48:02 2010
@@ -41,33 +41,17 @@
 #include "vpmadtreg.h"
 #include "GpakCust.h"
 
-#define INTERRUPT 0	/* Run the deferred processing in the ISR. */
-#define TASKLET 1	/* Run in a tasklet. */
-#define TIMER 2		/* Run in a system timer. */
-#define WORKQUEUE 3	/* Run in a workqueue. */
-#ifndef VOICEBUS_DEFERRED
-#define VOICEBUS_DEFERRED INTERRUPT
-#endif
 #if VOICEBUS_DEFERRED == WORKQUEUE
 #define VOICEBUS_ALLOC_FLAGS GFP_KERNEL
 #else
 #define VOICEBUS_ALLOC_FLAGS GFP_ATOMIC
 #endif
 
-/* Define CONFIG_VOICEBUS_SYSFS to create some attributes under the pci device.
- * This is disabled by default because it hasn't been tested on the full range
- * of supported kernels. */
-#undef CONFIG_VOICEBUS_SYSFS
-
 #if VOICEBUS_DEFERRED == TIMER
 #if HZ < 1000
 /* \todo Put an error message here. */
 #endif
 #endif
-
-/*! The number of descriptors in both the tx and rx descriptor ring. */
-#define DRING_SIZE	(1 << 7)  /* Must be a power of 2 */
-#define DRING_MASK	(DRING_SIZE-1)
 
 /* Interrupt status' reported in SR_CSR5 */
 #define TX_COMPLETE_INTERRUPT 		0x00000001
@@ -119,90 +103,9 @@
 	volatile __le32 container; /* Unused */
 } __attribute__((packed));
 
-struct voicebus_descriptor_list {
-	/* Pointer to an array of descriptors to give to hardware. */
-	struct voicebus_descriptor *desc;
-	/* Read completed buffers from the head. */
-	unsigned int 	head;
-	/* Write ready buffers to the tail. */
-	unsigned int 	tail;
-	/* Array to save the kernel virtual address of pending buffers. */
-	void  		*pending[DRING_SIZE];
-	/* PCI Bus address of the descriptor list. */
-	dma_addr_t	desc_dma;
-	/*! The number of buffers currently submitted to the hardware. */
-	atomic_t 	count;
-	/*! The number of bytes to pad each descriptor for cache alignment. */
-	unsigned int	padding;
-};
-
-/**
- * struct voicebus -
- *
- * @tx_idle_vbb:
- * @tx_idle_vbb_dma_addr:
- * @max_latency: Do not allow the driver to automatically insert more than this
- * 		 much latency to the tdm stream by default.
- * @count:	The number of non-idle buffers that we should be expecting.
- */
-struct voicebus {
-	/*! The system pci device for this VoiceBus interface. */
-	struct pci_dev *pdev;
-	/*! Protects access to card registers and this structure. You should
-	 * hold this lock before accessing most of the members of this data
-	 * structure or the card registers. */
-	spinlock_t lock;
-	/*! The size of the transmit and receive buffers for this card. */
-	u32 framesize;
-	/*! The number of u32s in the host system cache line. */
-	u8 cache_line_size;
-	/*! Pool to allocate memory for the tx and rx descriptor rings. */
-	struct voicebus_descriptor_list rxd;
-	struct voicebus_descriptor_list txd;
-	void 		*idle_vbb;
-	dma_addr_t	idle_vbb_dma_addr;
-	/*! Level of debugging information.  0=None, 5=Insane. */
-	atomic_t debuglevel;
-	/*! Cache of buffer objects. */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
-	kmem_cache_t *buffer_cache;
-#else
-	struct kmem_cache *buffer_cache;
-#endif
-	/*! Base address of the VoiceBus interface registers in I/O space. */
-	u32 iobase;
-	/*! The IRQ line for this VoiceBus interface. */
-	unsigned int irq;
-#if VOICEBUS_DEFERRED == WORKQUEUE
-	/*! Process buffers in the context of this workqueue. */
-	struct workqueue_struct *workqueue;
-	/*! Work item to process tx / rx buffers. */
-	struct work_struct workitem;
-#elif VOICEBUS_DEFERRED == TASKLET
-	/*! Process buffers in the context of a tasklet. */
-	struct tasklet_struct 	tasklet;
-#elif VOICEBUS_DEFERRED == TIMER
-	/*! Process buffers in a timer without generating interrupts. */
-	struct timer_list timer;
-#endif
-	/*! Callback function to board specific module to process frames. */
-	void (*handle_receive)(void *vbb, void *context);
-	void (*handle_transmit)(void *vbb, void *context);
-	/*! Data to pass to the receive and transmit callback. */
-	void *context;
-	struct completion stopped_completion;
-	/*! Flags */
-	unsigned long flags;
-	/*! Number of tx buffers to queue up before enabling interrupts. */
-	unsigned int 	min_tx_buffer_count;
-	unsigned int	max_latency;
-	void		*vbb_stash[DRING_SIZE];
-	unsigned int	count;
-};
-
 static inline void handle_transmit(struct voicebus *vb, void *vbb)
 {
-	vb->handle_transmit(vbb, vb->context);
+	vb->ops->handle_transmit(vb, vbb);
 }
 
 /*
@@ -398,41 +301,6 @@
 }
 EXPORT_SYMBOL(voicebus_set_minlatency);
 
-void
-voicebus_get_handlers(struct voicebus *vb, void **handle_receive,
-	void **handle_transmit, void **context)
-{
-	LOCKS_VOICEBUS;
-	BUG_ON(!handle_receive);
-	BUG_ON(!handle_transmit);
-	BUG_ON(!context);
-	VBLOCK(vb);
-	*handle_receive = vb->handle_receive;
-	*handle_transmit = vb->handle_transmit;
-	*context = vb->context;
-	VBUNLOCK(vb);
-	return;
-}
-EXPORT_SYMBOL(voicebus_get_handlers);
-
-void
-voicebus_set_handlers(struct voicebus *vb,
-	void (*handle_receive)(void *buffer, void *context),
-	void (*handle_transmit)(void *buffer, void *context),
-	void *context)
-{
-	LOCKS_VOICEBUS;
-	BUG_ON(!handle_receive);
-	BUG_ON(!handle_transmit);
-	BUG_ON(!context);
-	VBLOCK(vb);
-	vb->handle_receive = handle_receive;
-	vb->handle_transmit = handle_transmit;
-	vb->context = context;
-	VBUNLOCK(vb);
-}
-EXPORT_SYMBOL(voicebus_set_handlers);
-
 /*! \brief Returns the number of buffers currently on the transmit queue. */
 int
 voicebus_current_latency(struct voicebus *vb)
@@ -682,20 +550,6 @@
 	return vbb;
 }
 
-void
-voicebus_setdebuglevel(struct voicebus *vb, u32 level)
-{
-	atomic_set(&vb->debuglevel, level);
-}
-EXPORT_SYMBOL(voicebus_setdebuglevel);
-
-int
-voicebus_getdebuglevel(struct voicebus *vb)
-{
-	return atomic_read(&vb->debuglevel);
-}
-EXPORT_SYMBOL(voicebus_getdebuglevel);
-
 /*! \brief Resets the voicebus hardware interface. */
 static int
 vb_reset_interface(struct voicebus *vb)
@@ -717,7 +571,7 @@
 		pci_access = DEFAULT_PCI_ACCESS | (0x3 << 14);
 		break;
 	default:
-		if (atomic_read(&vb->debuglevel)) {
+		if (*vb->debug) {
 			dev_warn(&vb->pdev->dev, "Host system set a cache "
 				 "size of %d which is not supported. "
 				 "Disabling memory write line and memory "
@@ -1023,10 +877,6 @@
 	int i;
 	void *vbb;
 	int ret;
-
-	WARN_ON(pci_get_drvdata(vb->pdev) != vb);
-	if (pci_get_drvdata(vb->pdev) != vb)
-		return -EFAULT;
 
 	if (!vb_is_stopped(vb))
 		return -EBUSY;
@@ -1235,7 +1085,6 @@
 	kmem_cache_destroy(vb->buffer_cache);
 	release_region(vb->iobase, 0xff);
 	pci_disable_device(vb->pdev);
-	kfree(vb);
 }
 EXPORT_SYMBOL(voicebus_release);
 
@@ -1518,7 +1367,7 @@
 	 * the caller, but this needs more work.... */
 	while ((vb->vbb_stash[0] = vb_get_completed_rxb(vb))) {
 		if (vb->count) {
-			vb->handle_receive(vb->vbb_stash[0], vb->context);
+			vb->ops->handle_receive(vb, vb->vbb_stash[0]);
 			--vb->count;
 		}
 		vb_submit_rxb(vb, vb->vbb_stash[0]);
@@ -1662,45 +1511,26 @@
  * \todo Complete this description.
  */
 int
-voicebus_init(struct pci_dev *pdev, u32 framesize, const char *board_name,
-		  void (*handle_receive)(void *vbb, void *context),
-		  void (*handle_transmit)(void *vbb, void *context),
-		  void *context,
-		  u32 debuglevel,
-		  struct voicebus **vbp
-		  )
+voicebus_init(struct voicebus *vb, const char *board_name)
 {
 	int retval = 0;
-	struct voicebus *vb;
-
-	BUG_ON(NULL == pdev);
+
+	BUG_ON(NULL == vb);
 	BUG_ON(NULL == board_name);
-	BUG_ON(0 == framesize);
-	BUG_ON(NULL == handle_receive);
-	BUG_ON(NULL == handle_transmit);
+	BUG_ON(NULL == vb->ops);
+	BUG_ON(NULL == vb->pdev);
+	BUG_ON(0 == vb->framesize);
+	BUG_ON(NULL == vb->debug);
 
 	/* ----------------------------------------------------------------
 	   Initialize the pure software constructs.
 	   ---------------------------------------------------------------- */
-	*vbp = NULL;
-	vb = kmalloc(sizeof(*vb), GFP_KERNEL);
-	if (NULL == vb) {
-		dev_dbg(&vb->pdev->dev, "Failed to allocate memory for "
-			"voicebus interface.\n");
-		retval = -ENOMEM;
-		goto cleanup;
-	}
-	memset(vb, 0, sizeof(*vb));
-	vb->pdev = pdev;
-	pci_set_drvdata(pdev, vb);
-	voicebus_setdebuglevel(vb, debuglevel);
 	vb->max_latency = VOICEBUS_DEFAULT_MAXLATENCY;
 
 	spin_lock_init(&vb->lock);
 	init_completion(&vb->stopped_completion);
 	set_bit(STOP, &vb->flags);
 	clear_bit(IN_DEFERRED_PROCESSING, &vb->flags);
-	vb->framesize = framesize;
 	vb->min_tx_buffer_count = VOICEBUS_DEFAULT_LATENCY;
 
 #if VOICEBUS_DEFERRED == WORKQUEUE
@@ -1725,10 +1555,6 @@
 	vb->timer.data = (unsigned long)vb;
 #endif
 
-	vb->handle_receive = handle_receive;
-	vb->handle_transmit = handle_transmit;
-	vb->context = context;
-
 	/* \todo This cache should be shared by all instances supported by
 	 * this driver. */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
@@ -1777,7 +1603,7 @@
 		goto cleanup;
 	}
 
-	if (pci_enable_device(pdev)) {
+	if (pci_enable_device(vb->pdev)) {
 		dev_err(&vb->pdev->dev, "Failed call to pci_enable_device.\n");
 		retval = -EIO;
 		goto cleanup;
@@ -1785,12 +1611,12 @@
 
 	/* \todo This driver should be modified to use the memory mapped I/O
 	   as opposed to IO space for portability and performance. */
-	if (0 == (pci_resource_flags(pdev, 0)&IORESOURCE_IO)) {
+	if (0 == (pci_resource_flags(vb->pdev, 0)&IORESOURCE_IO)) {
 		dev_err(&vb->pdev->dev, "BAR0 is not IO Memory.\n");
 		retval = -EIO;
 		goto cleanup;
 	}
-	vb->iobase = pci_resource_start(pdev, 0);
+	vb->iobase = pci_resource_start(vb->pdev, 0);
 	if (NULL == request_region(vb->iobase, 0xff, board_name)) {
 		dev_err(&vb->pdev->dev, "IO Registers are in use by another "
 			"module.\n");
@@ -1812,17 +1638,17 @@
 	/* ----------------------------------------------------------------
 	   Configure the hardware interface.
 	   ---------------------------------------------------------------- */
-	if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+	if (pci_set_dma_mask(vb->pdev, DMA_BIT_MASK(32))) {
 		release_region(vb->iobase, 0xff);
 		dev_warn(&vb->pdev->dev, "No suitable DMA available.\n");
 		goto cleanup;
 	}
 
-	pci_set_master(pdev);
+	pci_set_master(vb->pdev);
 	vb_enable_io_access(vb);
 
 #if VOICEBUS_DEFERRED != TIMER
-	retval = request_irq(pdev->irq, vb_isr, DAHDI_IRQ_SHARED,
+	retval = request_irq(vb->pdev->irq, vb_isr, DAHDI_IRQ_SHARED,
 			     board_name, vb);
 	if (retval) {
 		dev_warn(&vb->pdev->dev, "Failed to request interrupt line.\n");
@@ -1830,17 +1656,12 @@
 	}
 #endif
 
-	*vbp = vb;
 	return retval;
 cleanup:
-	if (NULL == vb)
-		return retval;
 
 #if VOICEBUS_DEFERRED == WORKQUEUE
-
 	if (vb->workqueue)
 		destroy_workqueue(vb->workqueue);
-
 #elif VOICEBUS_DEFERRED == TASKLET
 	tasklet_kill(&vb->tasklet);
 #endif
@@ -1864,7 +1685,6 @@
 	if (vb->pdev)
 		pci_disable_device(vb->pdev);
 
-	kfree(vb);
 	WARN_ON(0 == retval);
 	return retval;
 }
@@ -1878,12 +1698,6 @@
 	return vb->pdev;
 }
 EXPORT_SYMBOL(voicebus_get_pci_dev);
-
-void *voicebus_pci_dev_to_context(struct pci_dev *pdev)
-{
-	return ((struct voicebus *)pci_get_drvdata(pdev))->context;
-}
-EXPORT_SYMBOL(voicebus_pci_dev_to_context);
 
 static spinlock_t loader_list_lock;
 static struct list_head binary_loader_list;

Modified: linux/trunk/drivers/dahdi/voicebus/voicebus.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/voicebus.h?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/voicebus.h (original)
+++ linux/trunk/drivers/dahdi/voicebus/voicebus.h Fri Jan  8 14:48:02 2010
@@ -29,29 +29,86 @@
 #ifndef __VOICEBUS_H__
 #define __VOICEBUS_H__
 
+#define VOICEBUS_DEFAULT_LATENCY	3
+#define VOICEBUS_DEFAULT_MAXLATENCY	25
+#define VOICEBUS_MAXLATENCY_BUMP	6
+
+/*! The number of descriptors in both the tx and rx descriptor ring. */
+#define DRING_SIZE	(1 << 7)  /* Must be a power of 2 */
+#define DRING_MASK	(DRING_SIZE-1)
+
+/* Define CONFIG_VOICEBUS_SYSFS to create some attributes under the pci device.
+ * This is disabled by default because it hasn't been tested on the full range
+ * of supported kernels. */
+#undef CONFIG_VOICEBUS_SYSFS
+
+#define INTERRUPT 0	/* Run the deferred processing in the ISR. */
+#define TASKLET   1	/* Run in a tasklet. */
+#define TIMER	  2	/* Run in a system timer. */
+#define WORKQUEUE 3	/* Run in a workqueue. */
+
+#ifndef VOICEBUS_DEFERRED
+#define VOICEBUS_DEFERRED INTERRUPT
+#endif
+
 struct voicebus;
 
-#define VOICEBUS_DEFAULT_LATENCY 3
-#define VOICEBUS_DEFAULT_MAXLATENCY 25
-#define VOICEBUS_MAXLATENCY_BUMP 6
+struct voicebus_operations {
+	void (*handle_receive)(struct voicebus *vb, void *vbb);
+	void (*handle_transmit)(struct voicebus *vb, void *vbb);
+};
 
-void voicebus_setdebuglevel(struct voicebus *vb, u32 level);
-int voicebus_getdebuglevel(struct voicebus *vb);
-struct pci_dev *voicebus_get_pci_dev(struct voicebus *vb);
-void *voicebus_pci_dev_to_context(struct pci_dev *pdev);
-int voicebus_init(struct pci_dev* pdev, u32 framesize, 
-                  const char *board_name,
-		  void (*handle_receive)(void *buffer, void *context),
-		  void (*handle_transmit)(void *buffer, void *context),
-		  void *context, 
-		  u32 debuglevel,
-		  struct voicebus **vb_p);
-void voicebus_get_handlers(struct voicebus *vb, void **handle_receive,
-	void **handle_transmit, void **context);
-void voicebus_set_handlers(struct voicebus *vb,
-	void (*handle_receive)(void *buffer, void *context),
-	void (*handle_transmit)(void *buffer, void *context),
-	void *context);
+/**
+ * struct voicebus_descriptor_list - A single descriptor list.
+ */
+struct voicebus_descriptor_list {
+	struct voicebus_descriptor *desc;
+	unsigned int 	head;
+	unsigned int 	tail;
+	void  		*pending[DRING_SIZE];
+	dma_addr_t	desc_dma;
+	atomic_t 	count;
+	unsigned int	padding;
+};
+
+/**
+ * struct voicebus - Represents physical interface to voicebus card.
+ *
+ */
+struct voicebus {
+	struct pci_dev		*pdev;
+	spinlock_t		lock;
+	u32 framesize;
+	u8 cache_line_size;
+	struct voicebus_descriptor_list rxd;
+	struct voicebus_descriptor_list txd;
+	void			*idle_vbb;
+	dma_addr_t		idle_vbb_dma_addr;
+	const int		*debug;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
+	kmem_cache_t *buffer_cache;
+#else
+	struct kmem_cache *buffer_cache;
+#endif
+	u32			iobase;
+#if VOICEBUS_DEFERRED == WORKQUEUE
+	struct workqueue_struct *workqueue;
+	struct work_struct	workitem;
+#elif VOICEBUS_DEFERRED == TASKLET
+	struct tasklet_struct 	tasklet;
+#elif VOICEBUS_DEFERRED == TIMER
+	struct timer_list	timer;
+#endif
+	const struct voicebus_operations *ops;
+	struct completion	stopped_completion;
+	unsigned long		flags;
+	unsigned int		min_tx_buffer_count;
+	unsigned int		max_latency;
+	void			*vbb_stash[DRING_SIZE];
+	unsigned int		count;
+};
+
+int voicebus_init(struct voicebus *vb, const char *board_name);
 void voicebus_release(struct voicebus *vb);
 int voicebus_start(struct voicebus *vb);
 int voicebus_stop(struct voicebus *vb);

Modified: linux/trunk/drivers/dahdi/voicebus/vpmadtreg.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/voicebus/vpmadtreg.h?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/voicebus/vpmadtreg.h (original)
+++ linux/trunk/drivers/dahdi/voicebus/vpmadtreg.h Fri Jan  8 14:48:02 2010
@@ -21,9 +21,6 @@
 #ifndef __VPMADTREG_H__
 #define __VPMADTREG_H__
 
-struct vpmadt032;
-struct voicebus;
-
 struct vpmadt_loader {
 	struct module *owner;
 	struct list_head node;

Modified: linux/trunk/drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c (original)
+++ linux/trunk/drivers/dahdi/vpmadt032_loader/dahdi_vpmadt032_loader.c Fri Jan  8 14:48:02 2010
@@ -66,55 +66,59 @@
 
 struct private_context {
 	struct voicebus *vb;
-	void *old_rx;
-	void *old_tx;
-	void *old_context;
 	void *pvt;
 	struct completion done;
 };
 
 static void init_private_context(struct private_context *ctx)
 {
-	memset(ctx, 0, sizeof(ctx));
 	init_completion(&ctx->done);
 }
 
-static void handle_receive(void *vbb, void *context)
+static void handle_receive(struct voicebus *vb, void *vbb)
 {
-	struct private_context *ctx = context;
+	struct private_context *ctx = pci_get_drvdata(vb->pdev);
 	__vpmadt032_receive(ctx->pvt, vbb);
 	if (__vpmadt032_done(ctx->pvt))
 		complete(&ctx->done);
 }
 
-static void handle_transmit(void *vbb, void *context)
+static void handle_transmit(struct voicebus *vb, void *vbb)
 {
-	struct private_context *ctx = context;
+	struct private_context *ctx = pci_get_drvdata(vb->pdev);
 	__vpmadt032_transmit(ctx->pvt, vbb);
 	voicebus_transmit(ctx->vb, vbb);
 }
+
+static const struct voicebus_operations loader_operations = {
+	.handle_receive = handle_receive,
+	.handle_transmit = handle_transmit,
+};
 
 static int vpmadt032_load_firmware(struct voicebus *vb)
 {
 	int ret = 0;
 	struct private_context *ctx;
-	struct pci_dev *pdev = voicebus_get_pci_dev(vb);
+	const struct voicebus_operations *old;
+	void *old_drvdata;
 	might_sleep();
-	ctx = kmalloc(sizeof(struct private_context), GFP_KERNEL);
+	ctx = kzalloc(sizeof(struct private_context), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
 	init_private_context(ctx);
 	ctx->vb = vb;
 	ret = __vpmadt032_start_load(
-			0, pdev->vendor << 16 | pdev->device,
+			0, vb->pdev->vendor << 16 | vb->pdev->device,
 			&ctx->pvt);
 	if (ret)
 		goto error_exit;
-	voicebus_get_handlers(vb, &ctx->old_rx, &ctx->old_tx,
-		&ctx->old_context);
-	voicebus_set_handlers(vb, handle_receive, handle_transmit, ctx);
+	old_drvdata = pci_get_drvdata(vb->pdev);
+	pci_set_drvdata(vb->pdev, ctx);
+	old = vb->ops;
+	vb->ops = &loader_operations;
 	wait_for_completion(&ctx->done);
-	voicebus_set_handlers(vb, ctx->old_rx, ctx->old_tx, ctx->old_context);
+	vb->ops = old;
+	pci_set_drvdata(vb->pdev, old_drvdata);
 	__vpmadt032_cleanup(ctx->pvt);
 error_exit:
 	kfree(ctx);

Modified: linux/trunk/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/base.c Fri Jan  8 14:48:02 2010
@@ -1798,20 +1798,20 @@
 	}
 }
 
-static void handle_receive(void* vbb, void* context)
-{
-	struct wctdm *wc = context;
+static void handle_receive(struct voicebus *vb, void* vbb)
+{
+	struct wctdm *wc = container_of(vb, struct wctdm, vb);
 	wctdm_receiveprep(wc, vbb);
 }
 
-static void handle_transmit(void* vbb, void* context)
-{
-	struct wctdm *wc = context;
+static void handle_transmit(struct voicebus *vb, void* vbb)
+{
+	struct wctdm *wc = container_of(vb, struct wctdm, vb);
 	memset(vbb, 0, SFRAME_SIZE);
 	wctdm_transmitprep(wc, vbb);
 	wctdm_isr_misc(wc);
 	wc->intcount++;
-	voicebus_transmit(wc->vb, vbb);
+	voicebus_transmit(&wc->vb, vbb);
 }
 
 static int wctdm_voicedaa_insane(struct wctdm *wc, int card)
@@ -3268,7 +3268,7 @@
 static int wctdm_initialize(struct wctdm *wc)
 {
 	int x;
-	struct pci_dev *pdev = voicebus_get_pci_dev(wc->vb);
+	struct pci_dev *pdev = wc->vb.pdev;
 
 	/* DAHDI stuff */
 	sprintf(wc->span.name, "WCTDM/%d", wc->pos);
@@ -3663,7 +3663,7 @@
 		wc->vpmadt032->setchanconfig_from_state = setchanconfig_from_state;
 		wc->vpmadt032->options.channels = wc->span.channels;
 		get_default_portconfig(&portconfig);
-		res = vpmadt032_init(wc->vpmadt032, wc->vb);
+		res = vpmadt032_init(wc->vpmadt032, &wc->vb);
 		if (res) {
 			vpmadt032_free(wc->vpmadt032);
 			wc->vpmadt032 = NULL;
@@ -3702,6 +3702,11 @@
 	}
 	kfree(wc);
 }
+
+static const struct voicebus_operations voicebus_operations = {
+	.handle_receive = handle_receive,
+	.handle_transmit = handle_transmit,
+};
 
 static int __devinit wctdm_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -3730,16 +3735,20 @@
 
 	snprintf(wc->board_name, sizeof(wc->board_name)-1, "%s%d",
 		 wctdm_driver.name, i);
-	ret = voicebus_init(pdev, SFRAME_SIZE, wc->board_name,
-		handle_receive, handle_transmit, wc, debug, &wc->vb);
+
+	pci_set_drvdata(pdev, wc);
+	wc->vb.ops = &voicebus_operations;
+	wc->vb.framesize = SFRAME_SIZE;
+	wc->vb.pdev = pdev;
+	wc->vb.debug = &debug;
+	ret = voicebus_init(&wc->vb, wc->board_name);
 	if (ret) {
 		kfree(wc);
 		return ret;
 	}
-	BUG_ON(!wc->vb);
 
 	if (VOICEBUS_DEFAULT_LATENCY != latency) {
-		voicebus_set_minlatency(wc->vb, latency);
+		voicebus_set_minlatency(&wc->vb, latency);
 	}
 
 	spin_lock_init(&wc->reglock);
@@ -3768,17 +3777,15 @@
 
 
 	if (wctdm_initialize(wc)) {
-		voicebus_release(wc->vb);
-		wc->vb = NULL;
+		voicebus_release(&wc->vb);
 		kfree(wc);
 		return -EIO;
 	}
 
-	voicebus_lock_latency(wc->vb);
-
-	if (voicebus_start(wc->vb)) {
+	voicebus_lock_latency(&wc->vb);
+
+	if (voicebus_start(&wc->vb))
 		BUG_ON(1);
-	}
 	
 	/* Now track down what modules are installed */
 	wctdm_locate_modules(wc);
@@ -3797,7 +3804,7 @@
 	printk(KERN_INFO "Found a Wildcard TDM: %s (%d modules)\n",
 	       wc->desc->name, wc->desc->ports);
 	
-	voicebus_unlock_latency(wc->vb);
+	voicebus_unlock_latency(&wc->vb);
 	return 0;
 }
 
@@ -3809,8 +3816,7 @@
 		dahdi_unregister(&wc->span);
 	}
 
-	voicebus_release(wc->vb);
-	wc->vb = NULL;
+	voicebus_release(&wc->vb);
 
 	spin_lock(&ifacelock);
 	for (i = 0; i < WC_MAX_IFACES; i++)
@@ -3824,7 +3830,7 @@
 
 static void __devexit wctdm_remove_one(struct pci_dev *pdev)
 {
-	struct wctdm *wc = voicebus_pci_dev_to_context(pdev);
+	struct wctdm *wc = pci_get_drvdata(pdev);
 	struct vpmadt032 *vpm = wc->vpmadt032;
 
 	if (wc) {
@@ -3834,7 +3840,7 @@
 			flush_scheduled_work();
 		}
 
-		voicebus_stop(wc->vb);
+		voicebus_stop(&wc->vb);
 
 		if (vpm) {
 			vpmadt032_free(wc->vpmadt032);

Modified: linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h (original)
+++ linux/trunk/drivers/dahdi/wctdm24xxp/wctdm24xxp.h Fri Jan  8 14:48:02 2010
@@ -227,7 +227,7 @@
 	int echocanpos;
 	int blinktimer;
 #endif	
-	struct voicebus *vb;
+	struct voicebus vb;
 	struct dahdi_chan *chans[NUM_CARDS];
 	struct dahdi_echocan_state *ec[NUM_CARDS];
 	int initialized;

Modified: linux/trunk/drivers/dahdi/wcte12xp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wcte12xp/base.c?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/wcte12xp/base.c (original)
+++ linux/trunk/drivers/dahdi/wcte12xp/base.c Fri Jan  8 14:48:02 2010
@@ -1186,9 +1186,7 @@
 {
 	int x;
 	int num;
-	struct pci_dev* dev;
-
-	dev = voicebus_get_pci_dev(wc->vb);
+	struct pci_dev *pdev = wc->vb.pdev;
 
 	/* Find position */
 	for (x = 0; x < sizeof(ifaces) / sizeof(ifaces[0]); x++) {
@@ -1210,12 +1208,13 @@
 	set_span_devicetype(wc);
 
 	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
-		"PCI Bus %02d Slot %02d", dev->bus->number, PCI_SLOT(dev->devfn) + 1);
+		"PCI Bus %02d Slot %02d", pdev->bus->number,
+		PCI_SLOT(pdev->devfn) + 1);
 
 	wc->span.owner = THIS_MODULE;
 	wc->span.spanconfig = t1xxp_spanconfig;
 	wc->span.chanconfig = t1xxp_chanconfig;
-	wc->span.irq = dev->irq;
+	wc->span.irq = pdev->irq;
 	wc->span.startup = t1xxp_startup;
 	wc->span.shutdown = t1xxp_shutdown;
 	wc->span.rbsbits = t1xxp_rbsbits;
@@ -1375,7 +1374,7 @@
 
 		wc->vpmadt032->setchanconfig_from_state = setchanconfig_from_state;
 
-		res = vpmadt032_init(wc->vpmadt032, wc->vb);
+		res = vpmadt032_init(wc->vpmadt032, &wc->vb);
 		if (res) {
 			vpmadt032_free(wc->vpmadt032);
 			wc->vpmadt032=NULL;
@@ -1692,21 +1691,19 @@
 	}
 }
 
-static void
-t1_handle_transmit(void* vbb, void* context)
-{
-	struct t1* wc = context;
+static void t1_handle_transmit(struct voicebus *vb, void *vbb)
+{
+	struct t1 *wc = container_of(vb, struct t1, vb);
 	memset(vbb, 0, SFRAME_SIZE);
 	atomic_inc(&wc->txints);
 	t1_transmitprep(wc, vbb);
-	voicebus_transmit(wc->vb, vbb);
+	voicebus_transmit(&wc->vb, vbb);
 	handle_leds(wc);
 }
 
-static void
-t1_handle_receive(void* vbb, void* context)
-{
-	struct t1* wc = context;
+static void t1_handle_receive(struct voicebus *vb, void* vbb)
+{
+	struct t1 *wc = container_of(vb, struct t1, vb);
 	t1_receiveprep(wc, vbb);
 }
 
@@ -1736,6 +1733,11 @@
 	return;
 }
 
+static const struct voicebus_operations voicebus_operations = {
+	.handle_receive = t1_handle_receive,
+	.handle_transmit = t1_handle_transmit,
+};
+
 static int __devinit te12xp_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct t1 *wc;
@@ -1786,9 +1788,13 @@
 #	endif
 
 	snprintf(wc->name, sizeof(wc->name)-1, "wcte12xp%d", index);
-	if ((res = voicebus_init(pdev, SFRAME_SIZE, wc->name,
-				 t1_handle_receive, t1_handle_transmit, wc,
-				 debug, &wc->vb))) {
+	pci_set_drvdata(pdev, wc);
+	wc->vb.ops = &voicebus_operations;
+	wc->vb.pdev = pdev;
+	wc->vb.framesize = SFRAME_SIZE;
+	wc->vb.debug = &debug;
+	res = voicebus_init(&wc->vb, wc->name);
+	if (res) {
 		WARN_ON(1);
 		free_wc(wc);
 		ifaces[index] = NULL;
@@ -1796,11 +1802,11 @@
 	}
 	
 	if (VOICEBUS_DEFAULT_LATENCY != latency) {
-		voicebus_set_minlatency(wc->vb, latency);
-	}
-
-	voicebus_lock_latency(wc->vb);
-	voicebus_start(wc->vb);
+		voicebus_set_minlatency(&wc->vb, latency);
+	}
+
+	voicebus_lock_latency(&wc->vb);
+	voicebus_start(&wc->vb);
 	t1_hardware_post_init(wc);
 
 	for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
@@ -1821,13 +1827,13 @@
 	mod_timer(&wc->timer, jiffies + HZ/5);
 	t1_software_init(wc);
 	module_printk("Found a %s\n", wc->variety);
-	voicebus_unlock_latency(wc->vb);
+	voicebus_unlock_latency(&wc->vb);
 	return 0;
 }
 
 static void __devexit te12xp_remove_one(struct pci_dev *pdev)
 {
-	struct t1 *wc = voicebus_pci_dev_to_context(pdev);
+	struct t1 *wc = pci_get_drvdata(pdev);
 #ifdef VPM_SUPPORT
 	unsigned long flags;
 	struct vpmadt032 *vpm = wc->vpmadt032;
@@ -1847,9 +1853,7 @@
 	flush_scheduled_work();
 	del_timer_sync(&wc->timer);
 
-	BUG_ON(!wc->vb);
-	voicebus_release(wc->vb);
-	wc->vb = NULL;
+	voicebus_release(&wc->vb);
 
 #ifdef VPM_SUPPORT
 	if(vpm) {

Modified: linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h?view=diff&rev=7778&r1=7777&r2=7778
==============================================================================
--- linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h (original)
+++ linux/trunk/drivers/dahdi/wcte12xp/wcte12xp.h Fri Jan  8 14:48:02 2010
@@ -124,7 +124,7 @@
 	struct dahdi_chan *chans[32];					/* Channels */
 	struct dahdi_echocan_state *ec[32];				/* Echocan state for channels */
 	unsigned long ctlreg;
-	struct voicebus* vb;
+	struct voicebus vb;
 	atomic_t txints;
 	int vpm100;
 	struct vpmadt032 *vpmadt032;
@@ -140,6 +140,6 @@
 };
 
 #define t1_info(t1, format, arg...)         \
-        dev_info(&voicebus_get_pci_dev(t1->vb)->dev , format , ## arg)
+	dev_info(&t1->vb.pdev->dev , format , ## arg)
 
 #endif




More information about the dahdi-commits mailing list