From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gregory Haskins Subject: [PATCH 5/7] ioq: add driver-side vbus helpers Date: Mon, 03 Aug 2009 13:17:56 -0400 Message-ID: <20090803171756.17268.22133.stgit@dev.haskins.net> References: <20090803171030.17268.26962.stgit@dev.haskins.net> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: alacrityvm-devel@lists.sourceforge.net, netdev@vger.kernel.org To: linux-kernel@vger.kernel.org Return-path: Received: from victor.provo.novell.com ([137.65.250.26]:50522 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752122AbZHCRSB (ORCPT ); Mon, 3 Aug 2009 13:18:01 -0400 In-Reply-To: <20090803171030.17268.26962.stgit@dev.haskins.net> Sender: netdev-owner@vger.kernel.org List-ID: It will be a common pattern to map an IOQ over the VBUS shared-memory interfaces. Therefore, we provide a helper function to generalize the allocation and registration of an IOQ to make this use case simple and easy. Signed-off-by: Gregory Haskins --- drivers/vbus/bus-proxy.c | 64 +++++++++++++++++++++++++++++++++++++++++++ include/linux/vbus_driver.h | 7 +++++ 2 files changed, 71 insertions(+), 0 deletions(-) diff --git a/drivers/vbus/bus-proxy.c b/drivers/vbus/bus-proxy.c index 3177f9f..88cd904 100644 --- a/drivers/vbus/bus-proxy.c +++ b/drivers/vbus/bus-proxy.c @@ -150,3 +150,67 @@ void vbus_driver_unregister(struct vbus_driver *drv) } EXPORT_SYMBOL_GPL(vbus_driver_unregister); +/* + *--------------------------------- + * driver-side IOQ helper + *--------------------------------- + */ +static void +vbus_driver_ioq_release(struct ioq *ioq) +{ + kfree(ioq->head_desc); + kfree(ioq); +} + +static struct ioq_ops vbus_driver_ioq_ops = { + .release = vbus_driver_ioq_release, +}; + + +int vbus_driver_ioq_alloc(struct vbus_device_proxy *dev, int id, int prio, + size_t count, struct ioq **ioq) +{ + struct ioq *_ioq; + struct ioq_ring_head *head = NULL; + struct shm_signal *signal = NULL; + size_t len = IOQ_HEAD_DESC_SIZE(count); + int ret = -ENOMEM; + + _ioq = kzalloc(sizeof(*_ioq), GFP_KERNEL); + if (!_ioq) + goto error; + + head = kzalloc(len, GFP_KERNEL | GFP_DMA); + if (!head) + goto error; + + head->magic = IOQ_RING_MAGIC; + head->ver = IOQ_RING_VER; + head->count = count; + + ret = dev->ops->shm(dev, id, prio, head, len, + &head->signal, &signal, 0); + if (ret < 0) + goto error; + + ioq_init(_ioq, + &vbus_driver_ioq_ops, + ioq_locality_north, + head, + signal, + count); + + *ioq = _ioq; + + return 0; + + error: + kfree(_ioq); + kfree(head); + + if (signal) + shm_signal_put(signal); + + return ret; +} +EXPORT_SYMBOL_GPL(vbus_driver_ioq_alloc); diff --git a/include/linux/vbus_driver.h b/include/linux/vbus_driver.h index c53e13f..9cfbf60 100644 --- a/include/linux/vbus_driver.h +++ b/include/linux/vbus_driver.h @@ -26,6 +26,7 @@ #include #include +#include struct vbus_device_proxy; struct vbus_driver; @@ -70,4 +71,10 @@ struct vbus_driver { int vbus_driver_register(struct vbus_driver *drv); void vbus_driver_unregister(struct vbus_driver *drv); +/* + * driver-side IOQ helper - allocates device-shm and maps an IOQ on it + */ +int vbus_driver_ioq_alloc(struct vbus_device_proxy *dev, int id, int prio, + size_t ringsize, struct ioq **ioq); + #endif /* _LINUX_VBUS_DRIVER_H */