diff options
Diffstat (limited to 'drivers/staging/ozwpan')
26 files changed, 1599 insertions, 1674 deletions
diff --git a/drivers/staging/ozwpan/Kbuild b/drivers/staging/ozwpan/Makefile index 6cc84cb3f0a..29529c1a8e3 100644 --- a/drivers/staging/ozwpan/Kbuild +++ b/drivers/staging/ozwpan/Makefile @@ -2,6 +2,7 @@ # Copyright (c) 2011 Ozmo Inc # Released under the GNU General Public License Version 2 (GPLv2). # ----------------------------------------------------------------------------- + obj-$(CONFIG_USB_WPAN_HCD) += ozwpan.o ozwpan-y := \ ozmain.o \ @@ -12,8 +13,4 @@ ozwpan-y := \ ozeltbuf.o \ ozproto.o \ ozcdev.o \ - ozurbparanoia.o \ - oztrace.o \ - ozevent.o - - + ozurbparanoia.o diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO index c2d30a7112f..f32c1c0bc87 100644 --- a/drivers/staging/ozwpan/TODO +++ b/drivers/staging/ozwpan/TODO @@ -1,14 +1,14 @@ TODO: - - review user mode interface and determine if ioctls can be replaced - with something better. correctly export data structures to user mode - if ioctls are still required and allocate ioctl numbers from - ioctl-number.txt. + - Convert event tracing code to in-kernel tracing infrastructure + - Check for remaining ioctl & check if that can be converted into + sysfs entries + - Convert debug prints to appropriate dev_debug or something better + - Modify Kconfig to add CONFIG option for enabling/disabling event + tracing. - check USB HCD implementation is complete and correct. - - remove any debug and trace code. - code review by USB developer community. - testing with as many devices as possible. Please send any patches for this driver to -Rupesh Gujare <rgujare@ozmodevices.com> -Chris Kelly <ckelly@ozmodevices.com> +Shigekatsu Tateno <shigekatsu.tateno@atmel.com> and Greg Kroah-Hartman <gregkh@linuxfoundation.org>. diff --git a/drivers/staging/ozwpan/ozappif.h b/drivers/staging/ozwpan/ozappif.h index 1b59b0748c6..ea1b271fdcd 100644 --- a/drivers/staging/ozwpan/ozappif.h +++ b/drivers/staging/ozwpan/ozappif.h @@ -6,8 +6,6 @@ #ifndef _OZAPPIF_H #define _OZAPPIF_H -#include "ozeventdef.h" - #define OZ_IOCTL_MAGIC 0xf4 struct oz_mac_addr { @@ -30,9 +28,9 @@ struct oz_binding_info { #define OZ_IOCTL_GET_PD_LIST _IOR(OZ_IOCTL_MAGIC, 0, struct oz_pd_list) #define OZ_IOCTL_SET_ACTIVE_PD _IOW(OZ_IOCTL_MAGIC, 1, struct oz_mac_addr) #define OZ_IOCTL_GET_ACTIVE_PD _IOR(OZ_IOCTL_MAGIC, 2, struct oz_mac_addr) -#define OZ_IOCTL_ADD_BINDING _IOW(OZ_IOCTL_MAGIC, 5, struct oz_binding_info) -#define OZ_IOCTL_REMOVE_BINDING _IOW(OZ_IOCTL_MAGIC, 8, struct oz_binding_info) -#define OZ_IOCTL_MAX 9 +#define OZ_IOCTL_ADD_BINDING _IOW(OZ_IOCTL_MAGIC, 3, struct oz_binding_info) +#define OZ_IOCTL_REMOVE_BINDING _IOW(OZ_IOCTL_MAGIC, 4, struct oz_binding_info) +#define OZ_IOCTL_MAX 5 #endif /* _OZAPPIF_H */ diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c index 27325f74ecd..10c0a96ce8b 100644 --- a/drivers/staging/ozwpan/ozcdev.c +++ b/drivers/staging/ozwpan/ozcdev.c @@ -8,18 +8,17 @@ #include <linux/cdev.h> #include <linux/uaccess.h> #include <linux/netdevice.h> +#include <linux/etherdevice.h> #include <linux/poll.h> #include <linux/sched.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" -#include "oztrace.h" #include "ozappif.h" #include "ozeltbuf.h" #include "ozpd.h" #include "ozproto.h" -#include "ozevent.h" -/*------------------------------------------------------------------------------ - */ +#include "ozcdev.h" + #define OZ_RD_BUF_SZ 256 struct oz_cdev { dev_t devnum; @@ -39,15 +38,17 @@ struct oz_serial_ctx { int rd_in; int rd_out; }; -/*------------------------------------------------------------------------------ - */ + static struct oz_cdev g_cdev; -/*------------------------------------------------------------------------------ +static struct class *g_oz_class; + +/* * Context: process and softirq */ static struct oz_serial_ctx *oz_cdev_claim_ctx(struct oz_pd *pd) { struct oz_serial_ctx *ctx; + spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); ctx = (struct oz_serial_ctx *)pd->app_ctx[OZ_APPID_SERIAL-1]; if (ctx) @@ -55,57 +56,60 @@ static struct oz_serial_ctx *oz_cdev_claim_ctx(struct oz_pd *pd) spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); return ctx; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ static void oz_cdev_release_ctx(struct oz_serial_ctx *ctx) { if (atomic_dec_and_test(&ctx->ref_count)) { - oz_trace("Dealloc serial context.\n"); + oz_dbg(ON, "Dealloc serial context\n"); kfree(ctx); } } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -int oz_cdev_open(struct inode *inode, struct file *filp) +static int oz_cdev_open(struct inode *inode, struct file *filp) { - struct oz_cdev *dev; - oz_trace("oz_cdev_open()\n"); - oz_trace("major = %d minor = %d\n", imajor(inode), iminor(inode)); - dev = container_of(inode->i_cdev, struct oz_cdev, cdev); + struct oz_cdev *dev = container_of(inode->i_cdev, struct oz_cdev, cdev); + + oz_dbg(ON, "major = %d minor = %d\n", imajor(inode), iminor(inode)); + filp->private_data = dev; return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -int oz_cdev_release(struct inode *inode, struct file *filp) +static int oz_cdev_release(struct inode *inode, struct file *filp) { - oz_trace("oz_cdev_release()\n"); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, +static ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, loff_t *fpos) { int n; int ix; struct oz_pd *pd; - struct oz_serial_ctx *ctx = 0; + struct oz_serial_ctx *ctx; spin_lock_bh(&g_cdev.lock); pd = g_cdev.active_pd; if (pd) oz_pd_get(pd); spin_unlock_bh(&g_cdev.lock); - if (pd == 0) + if (pd == NULL) return -1; ctx = oz_cdev_claim_ctx(pd); - if (ctx == 0) + if (ctx == NULL) goto out2; n = ctx->rd_in - ctx->rd_out; if (n < 0) @@ -137,29 +141,35 @@ out2: oz_pd_put(pd); return count; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, - loff_t *fpos) +static ssize_t oz_cdev_write(struct file *filp, const char __user *buf, + size_t count, loff_t *fpos) { struct oz_pd *pd; struct oz_elt_buf *eb; - struct oz_elt_info *ei = 0; + struct oz_elt_info *ei; struct oz_elt *elt; struct oz_app_hdr *app_hdr; struct oz_serial_ctx *ctx; + if (count > sizeof(ei->data) - sizeof(*elt) - sizeof(*app_hdr)) + return -EINVAL; + spin_lock_bh(&g_cdev.lock); pd = g_cdev.active_pd; if (pd) oz_pd_get(pd); spin_unlock_bh(&g_cdev.lock); - if (pd == 0) - return -1; + if (pd == NULL) + return -ENXIO; + if (!(pd->state & OZ_PD_S_CONNECTED)) + return -EAGAIN; eb = &pd->elt_buff; ei = oz_elt_info_alloc(eb); - if (ei == 0) { + if (ei == NULL) { count = 0; goto out; } @@ -180,7 +190,7 @@ ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, ctx->tx_seq_num = 1; spin_lock(&eb->lock); if (oz_queue_elt_info(eb, 0, 0, ei) == 0) - ei = 0; + ei = NULL; spin_unlock(&eb->lock); } spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); @@ -194,28 +204,30 @@ out: oz_pd_put(pd); return count; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -static int oz_set_active_pd(u8 *addr) +static int oz_set_active_pd(const u8 *addr) { int rc = 0; struct oz_pd *pd; struct oz_pd *old_pd; + pd = oz_pd_find(addr); if (pd) { spin_lock_bh(&g_cdev.lock); - memcpy(g_cdev.active_addr, addr, ETH_ALEN); + ether_addr_copy(g_cdev.active_addr, addr); old_pd = g_cdev.active_pd; g_cdev.active_pd = pd; spin_unlock_bh(&g_cdev.lock); if (old_pd) oz_pd_put(old_pd); } else { - if (!memcmp(addr, "\0\0\0\0\0\0", sizeof(addr))) { + if (is_zero_ether_addr(addr)) { spin_lock_bh(&g_cdev.lock); pd = g_cdev.active_pd; - g_cdev.active_pd = 0; + g_cdev.active_pd = NULL; memset(g_cdev.active_addr, 0, sizeof(g_cdev.active_addr)); spin_unlock_bh(&g_cdev.lock); @@ -227,12 +239,15 @@ static int oz_set_active_pd(u8 *addr) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +static long oz_cdev_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) { int rc = 0; + if (_IOC_TYPE(cmd) != OZ_IOCTL_MAGIC) return -ENOTTY; if (_IOC_NR(cmd) > OZ_IOCTL_MAX) @@ -248,7 +263,8 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) switch (cmd) { case OZ_IOCTL_GET_PD_LIST: { struct oz_pd_list list; - oz_trace("OZ_IOCTL_GET_PD_LIST\n"); + oz_dbg(ON, "OZ_IOCTL_GET_PD_LIST\n"); + memset(&list, 0, sizeof(list)); list.count = oz_get_pd_list(list.addr, OZ_MAX_PDS); if (copy_to_user((void __user *)arg, &list, sizeof(list))) @@ -257,7 +273,7 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; case OZ_IOCTL_SET_ACTIVE_PD: { u8 addr[ETH_ALEN]; - oz_trace("OZ_IOCTL_SET_ACTIVE_PD\n"); + oz_dbg(ON, "OZ_IOCTL_SET_ACTIVE_PD\n"); if (copy_from_user(addr, (void __user *)arg, ETH_ALEN)) return -EFAULT; rc = oz_set_active_pd(addr); @@ -265,9 +281,9 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; case OZ_IOCTL_GET_ACTIVE_PD: { u8 addr[ETH_ALEN]; - oz_trace("OZ_IOCTL_GET_ACTIVE_PD\n"); + oz_dbg(ON, "OZ_IOCTL_GET_ACTIVE_PD\n"); spin_lock_bh(&g_cdev.lock); - memcpy(addr, g_cdev.active_addr, ETH_ALEN); + ether_addr_copy(addr, g_cdev.active_addr); spin_unlock_bh(&g_cdev.lock); if (copy_to_user((void __user *)arg, addr, ETH_ALEN)) return -EFAULT; @@ -291,14 +307,16 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) +static unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) { unsigned int ret = 0; struct oz_cdev *dev = filp->private_data; - oz_trace("Poll called wait = %p\n", wait); + + oz_dbg(ON, "Poll called wait = %p\n", wait); spin_lock_bh(&dev->lock); if (dev->active_pd) { struct oz_serial_ctx *ctx = oz_cdev_claim_ctx(dev->active_pd); @@ -313,9 +331,10 @@ unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) poll_wait(filp, &dev->rdq, wait); return ret; } -/*------------------------------------------------------------------------------ + +/* */ -const struct file_operations oz_fops = { +static const struct file_operations oz_fops = { .owner = THIS_MODULE, .open = oz_cdev_open, .release = oz_cdev_release, @@ -324,66 +343,97 @@ const struct file_operations oz_fops = { .unlocked_ioctl = oz_cdev_ioctl, .poll = oz_cdev_poll }; -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_cdev_register(void) { int err; + struct device *dev; + memset(&g_cdev, 0, sizeof(g_cdev)); err = alloc_chrdev_region(&g_cdev.devnum, 0, 1, "ozwpan"); if (err < 0) return err; - oz_trace("Alloc dev number %d:%d\n", MAJOR(g_cdev.devnum), - MINOR(g_cdev.devnum)); + oz_dbg(ON, "Alloc dev number %d:%d\n", + MAJOR(g_cdev.devnum), MINOR(g_cdev.devnum)); cdev_init(&g_cdev.cdev, &oz_fops); g_cdev.cdev.owner = THIS_MODULE; g_cdev.cdev.ops = &oz_fops; spin_lock_init(&g_cdev.lock); init_waitqueue_head(&g_cdev.rdq); err = cdev_add(&g_cdev.cdev, g_cdev.devnum, 1); + if (err < 0) { + oz_dbg(ON, "Failed to add cdev\n"); + goto unregister; + } + g_oz_class = class_create(THIS_MODULE, "ozmo_wpan"); + if (IS_ERR(g_oz_class)) { + oz_dbg(ON, "Failed to register ozmo_wpan class\n"); + err = PTR_ERR(g_oz_class); + goto delete; + } + dev = device_create(g_oz_class, NULL, g_cdev.devnum, NULL, "ozwpan"); + if (IS_ERR(dev)) { + oz_dbg(ON, "Failed to create sysfs entry for cdev\n"); + err = PTR_ERR(dev); + goto delete; + } return 0; + +delete: + cdev_del(&g_cdev.cdev); +unregister: + unregister_chrdev_region(g_cdev.devnum, 1); + return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_cdev_deregister(void) { cdev_del(&g_cdev.cdev); unregister_chrdev_region(g_cdev.devnum, 1); + if (g_oz_class) { + device_destroy(g_oz_class, g_cdev.devnum); + class_destroy(g_oz_class); + } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_cdev_init(void) { - oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_SERIAL, 0, 0); oz_app_enable(OZ_APPID_SERIAL, 1); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_cdev_term(void) { - oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_SERIAL, 0, 0); oz_app_enable(OZ_APPID_SERIAL, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ int oz_cdev_start(struct oz_pd *pd, int resume) { struct oz_serial_ctx *ctx; - struct oz_serial_ctx *old_ctx = 0; - oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_SERIAL, 0, resume); + struct oz_serial_ctx *old_ctx; + if (resume) { - oz_trace("Serial service resumed.\n"); + oz_dbg(ON, "Serial service resumed\n"); return 0; } ctx = kzalloc(sizeof(struct oz_serial_ctx), GFP_ATOMIC); - if (ctx == 0) + if (ctx == NULL) return -ENOMEM; atomic_set(&ctx->ref_count, 1); ctx->tx_seq_num = 1; @@ -397,46 +447,48 @@ int oz_cdev_start(struct oz_pd *pd, int resume) spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); } spin_lock(&g_cdev.lock); - if ((g_cdev.active_pd == 0) && - (memcmp(pd->mac_addr, g_cdev.active_addr, ETH_ALEN) == 0)) { + if ((g_cdev.active_pd == NULL) && + ether_addr_equal(pd->mac_addr, g_cdev.active_addr)) { oz_pd_get(pd); g_cdev.active_pd = pd; - oz_trace("Active PD arrived.\n"); + oz_dbg(ON, "Active PD arrived\n"); } spin_unlock(&g_cdev.lock); - oz_trace("Serial service started.\n"); + oz_dbg(ON, "Serial service started\n"); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_cdev_stop(struct oz_pd *pd, int pause) { struct oz_serial_ctx *ctx; - oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_SERIAL, 0, pause); + if (pause) { - oz_trace("Serial service paused.\n"); + oz_dbg(ON, "Serial service paused\n"); return; } spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); ctx = (struct oz_serial_ctx *)pd->app_ctx[OZ_APPID_SERIAL-1]; - pd->app_ctx[OZ_APPID_SERIAL-1] = 0; + pd->app_ctx[OZ_APPID_SERIAL-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); if (ctx) oz_cdev_release_ctx(ctx); spin_lock(&g_cdev.lock); if (pd == g_cdev.active_pd) - g_cdev.active_pd = 0; + g_cdev.active_pd = NULL; else - pd = 0; + pd = NULL; spin_unlock(&g_cdev.lock); if (pd) { oz_pd_put(pd); - oz_trace("Active PD departed.\n"); + oz_dbg(ON, "Active PD departed\n"); } - oz_trace("Serial service stopped.\n"); + oz_dbg(ON, "Serial service stopped\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) @@ -450,8 +502,8 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) int ix; ctx = oz_cdev_claim_ctx(pd); - if (ctx == 0) { - oz_trace("Cannot claim serial context.\n"); + if (ctx == NULL) { + oz_dbg(ON, "Cannot claim serial context\n"); return; } @@ -461,8 +513,8 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) if (app_hdr->elt_seq_num != 0) { if (((ctx->rx_seq_num - app_hdr->elt_seq_num) & 0x80) == 0) { /* Reject duplicate element. */ - oz_trace("Duplicate element:%02x %02x\n", - app_hdr->elt_seq_num, ctx->rx_seq_num); + oz_dbg(ON, "Duplicate element:%02x %02x\n", + app_hdr->elt_seq_num, ctx->rx_seq_num); goto out; } } @@ -475,7 +527,7 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) if (space < 0) space += OZ_RD_BUF_SZ; if (len > space) { - oz_trace("Not enough space:%d %d\n", len, space); + oz_dbg(ON, "Not enough space:%d %d\n", len, space); len = space; } ix = ctx->rd_in; @@ -496,9 +548,3 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt) out: oz_cdev_release_ctx(ctx); } -/*------------------------------------------------------------------------------ - * Context: softirq - */ -void oz_cdev_heartbeat(struct oz_pd *pd) -{ -} diff --git a/drivers/staging/ozwpan/ozcdev.h b/drivers/staging/ozwpan/ozcdev.h index 698014bb8d7..dd11935a093 100644 --- a/drivers/staging/ozwpan/ozcdev.h +++ b/drivers/staging/ozwpan/ozcdev.h @@ -13,6 +13,5 @@ void oz_cdev_term(void); int oz_cdev_start(struct oz_pd *pd, int resume); void oz_cdev_stop(struct oz_pd *pd, int pause); void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt); -void oz_cdev_heartbeat(struct oz_pd *pd); #endif /* _OZCDEV_H */ diff --git a/drivers/staging/ozwpan/ozconfig.h b/drivers/staging/ozwpan/ozconfig.h deleted file mode 100644 index 43e6373a009..00000000000 --- a/drivers/staging/ozwpan/ozconfig.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ---------------------------------------------------------------------------*/ -#ifndef _OZCONFIG_H -#define _OZCONFIG_H - -/* #define WANT_TRACE */ -#ifdef WANT_TRACE -#define WANT_VERBOSE_TRACE -#endif /* #ifdef WANT_TRACE */ -/* #define WANT_URB_PARANOIA */ - -/* #define WANT_PRE_2_6_39 */ -#define WANT_EVENT_TRACE - -/* These defines determine what verbose trace is displayed. */ -#ifdef WANT_VERBOSE_TRACE -/* #define WANT_TRACE_STREAM */ -/* #define WANT_TRACE_URB */ -/* #define WANT_TRACE_CTRL_DETAIL */ -#define WANT_TRACE_HUB -/* #define WANT_TRACE_RX_FRAMES */ -/* #define WANT_TRACE_TX_FRAMES */ -#endif /* WANT_VERBOSE_TRACE */ - -#endif /* _OZCONFIG_H */ diff --git a/drivers/staging/ozwpan/ozdbg.h b/drivers/staging/ozwpan/ozdbg.h new file mode 100644 index 00000000000..b86a2b7e017 --- /dev/null +++ b/drivers/staging/ozwpan/ozdbg.h @@ -0,0 +1,54 @@ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2011 Ozmo Inc + * Released under the GNU General Public License Version 2 (GPLv2). + * ---------------------------------------------------------------------------*/ + +#ifndef _OZDBG_H +#define _OZDBG_H + +#define OZ_WANT_DBG 0 +#define OZ_WANT_VERBOSE_DBG 1 + +#define OZ_DBG_ON 0x0 +#define OZ_DBG_STREAM 0x1 +#define OZ_DBG_URB 0x2 +#define OZ_DBG_CTRL_DETAIL 0x4 +#define OZ_DBG_HUB 0x8 +#define OZ_DBG_RX_FRAMES 0x10 +#define OZ_DBG_TX_FRAMES 0x20 + +#define OZ_DEFAULT_DBG_MASK \ + ( \ + /* OZ_DBG_STREAM | */ \ + /* OZ_DBG_URB | */ \ + /* OZ_DBG_CTRL_DETAIL | */ \ + OZ_DBG_HUB | \ + /* OZ_DBG_RX_FRAMES | */ \ + /* OZ_DBG_TX_FRAMES | */ \ + 0) + +extern unsigned int oz_dbg_mask; + +#define oz_want_dbg(mask) \ + ((OZ_WANT_DBG && (OZ_DBG_##mask == OZ_DBG_ON)) || \ + (OZ_WANT_VERBOSE_DBG && (OZ_DBG_##mask & oz_dbg_mask))) + +#define oz_dbg(mask, fmt, ...) \ +do { \ + if (oz_want_dbg(mask)) \ + pr_debug(fmt, ##__VA_ARGS__); \ +} while (0) + +#define oz_cdev_dbg(cdev, mask, fmt, ...) \ +do { \ + if (oz_want_dbg(mask)) \ + netdev_dbg((cdev)->dev, fmt, ##__VA_ARGS__); \ +} while (0) + +#define oz_pd_dbg(pd, mask, fmt, ...) \ +do { \ + if (oz_want_dbg(mask)) \ + pr_debug(fmt, ##__VA_ARGS__); \ +} while (0) + +#endif /* _OZDBG_H */ diff --git a/drivers/staging/ozwpan/ozeltbuf.c b/drivers/staging/ozwpan/ozeltbuf.c index 988f522475d..bd560c67fc8 100644 --- a/drivers/staging/ozwpan/ozeltbuf.c +++ b/drivers/staging/ozwpan/ozeltbuf.c @@ -3,19 +3,17 @@ * Released under the GNU General Public License Version 2 (GPLv2). * ----------------------------------------------------------------------------- */ -#include <linux/init.h> #include <linux/module.h> #include <linux/netdevice.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" #include "ozeltbuf.h" #include "ozpd.h" -#include "oztrace.h" -/*------------------------------------------------------------------------------ - */ + #define OZ_ELT_INFO_MAGIC_USED 0x35791057 #define OZ_ELT_INFO_MAGIC_FREE 0x78940102 -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ int oz_elt_buf_init(struct oz_elt_buf *buf) @@ -28,13 +26,15 @@ int oz_elt_buf_init(struct oz_elt_buf *buf) spin_lock_init(&buf->lock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_elt_buf_term(struct oz_elt_buf *buf) { struct list_head *e; int i; + /* Free any elements in the order or isoc lists. */ for (i = 0; i < 2; i++) { struct list_head *list; @@ -59,12 +59,14 @@ void oz_elt_buf_term(struct oz_elt_buf *buf) } buf->free_elts = 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) { - struct oz_elt_info *ei = 0; + struct oz_elt_info *ei; + spin_lock_bh(&buf->lock); if (buf->free_elts && buf->elt_pool) { ei = container_of(buf->elt_pool, struct oz_elt_info, link); @@ -72,8 +74,8 @@ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) buf->free_elts--; spin_unlock_bh(&buf->lock); if (ei->magic != OZ_ELT_INFO_MAGIC_FREE) { - oz_trace("oz_elt_info_alloc: ei with bad magic: 0x%x\n", - ei->magic); + oz_dbg(ON, "%s: ei with bad magic: 0x%x\n", + __func__, ei->magic); } } else { spin_unlock_bh(&buf->lock); @@ -82,16 +84,17 @@ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) if (ei) { ei->flags = 0; ei->app_id = 0; - ei->callback = 0; + ei->callback = NULL; ei->context = 0; - ei->stream = 0; + ei->stream = NULL; ei->magic = OZ_ELT_INFO_MAGIC_USED; INIT_LIST_HEAD(&ei->link); INIT_LIST_HEAD(&ei->link_order); } return ei; } -/*------------------------------------------------------------------------------ + +/* * Precondition: oz_elt_buf.lock must be held. * Context: softirq or process */ @@ -104,18 +107,19 @@ void oz_elt_info_free(struct oz_elt_buf *buf, struct oz_elt_info *ei) buf->elt_pool = &ei->link; ei->magic = OZ_ELT_INFO_MAGIC_FREE; } else { - oz_trace("oz_elt_info_free: bad magic ei: %p" - " magic: 0x%x\n", - ei, ei->magic); + oz_dbg(ON, "%s: bad magic ei: %p magic: 0x%x\n", + __func__, ei, ei->magic); } } } + /*------------------------------------------------------------------------------ * Context: softirq */ void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list) { struct list_head *e; + e = list->next; spin_lock_bh(&buf->lock); while (e != list) { @@ -126,16 +130,15 @@ void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list) } spin_unlock_bh(&buf->lock); } -/*------------------------------------------------------------------------------ - */ + int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count) { struct oz_elt_stream *st; - oz_trace("oz_elt_stream_create(0x%x)\n", id); + oz_dbg(ON, "%s: (0x%x)\n", __func__, id); - st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO); - if (st == 0) + st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC); + if (st == NULL) return -ENOMEM; atomic_set(&st->ref_count, 1); st->id = id; @@ -146,13 +149,13 @@ int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count) spin_unlock_bh(&buf->lock); return 0; } -/*------------------------------------------------------------------------------ - */ + int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) { struct list_head *e; - struct oz_elt_stream *st; - oz_trace("oz_elt_stream_delete(0x%x)\n", id); + struct oz_elt_stream *st = NULL; + + oz_dbg(ON, "%s: (0x%x)\n", __func__, id); spin_lock_bh(&buf->lock); e = buf->stream_list.next; while (e != &buf->stream_list) { @@ -161,7 +164,7 @@ int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) list_del(e); break; } - st = 0; + st = NULL; } if (!st) { spin_unlock_bh(&buf->lock); @@ -175,9 +178,8 @@ int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) list_del_init(&ei->link); list_del_init(&ei->link_order); st->buf_count -= ei->length; - oz_trace2(OZ_TRACE_STREAM, "Stream down: %d %d %d\n", - st->buf_count, - ei->length, atomic_read(&st->ref_count)); + oz_dbg(STREAM, "Stream down: %d %d %d\n", + st->buf_count, ei->length, atomic_read(&st->ref_count)); oz_elt_stream_put(st); oz_elt_info_free(buf, ei); } @@ -185,22 +187,21 @@ int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) oz_elt_stream_put(st); return 0; } -/*------------------------------------------------------------------------------ - */ + void oz_elt_stream_get(struct oz_elt_stream *st) { atomic_inc(&st->ref_count); } -/*------------------------------------------------------------------------------ - */ + void oz_elt_stream_put(struct oz_elt_stream *st) { if (atomic_dec_and_test(&st->ref_count)) { - oz_trace("Stream destroyed\n"); + oz_dbg(ON, "Stream destroyed\n"); kfree(st); } } -/*------------------------------------------------------------------------------ + +/* * Precondition: Element buffer lock must be held. * If this function fails the caller is responsible for deallocating the elt * info structure. @@ -208,8 +209,9 @@ void oz_elt_stream_put(struct oz_elt_stream *st) int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id, struct oz_elt_info *ei) { - struct oz_elt_stream *st = 0; + struct oz_elt_stream *st = NULL; struct list_head *e; + if (id) { list_for_each(e, &buf->stream_list) { st = container_of(e, struct oz_elt_stream, link); @@ -242,8 +244,7 @@ int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id, st->buf_count += ei->length; /* Add to list in stream. */ list_add_tail(&ei->link, &st->elt_list); - oz_trace2(OZ_TRACE_STREAM, "Stream up: %d %d\n", - st->buf_count, ei->length); + oz_dbg(STREAM, "Stream up: %d %d\n", st->buf_count, ei->length); /* Check if we have too much buffered for this stream. If so * start dropping elements until we are back in bounds. */ @@ -263,8 +264,7 @@ int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id, &buf->isoc_list : &buf->order_list); return 0; } -/*------------------------------------------------------------------------------ - */ + int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len, unsigned max_len, struct list_head *list) { @@ -272,6 +272,7 @@ int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len, struct list_head *e; struct list_head *el; struct oz_elt_info *ei; + spin_lock_bh(&buf->lock); if (isoc) el = &buf->isoc_list; @@ -293,11 +294,10 @@ int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len, list_del(&ei->link_order); if (ei->stream) { ei->stream->buf_count -= ei->length; - oz_trace2(OZ_TRACE_STREAM, - "Stream down: %d %d\n", - ei->stream->buf_count, ei->length); + oz_dbg(STREAM, "Stream down: %d %d\n", + ei->stream->buf_count, ei->length); oz_elt_stream_put(ei->stream); - ei->stream = 0; + ei->stream = NULL; } INIT_LIST_HEAD(&ei->link_order); list_add_tail(&ei->link, list); @@ -309,18 +309,17 @@ int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len, spin_unlock_bh(&buf->lock); return count; } -/*------------------------------------------------------------------------------ - */ + int oz_are_elts_available(struct oz_elt_buf *buf) { return buf->order_list.next != &buf->order_list; } -/*------------------------------------------------------------------------------ - */ + void oz_trim_elt_pool(struct oz_elt_buf *buf) { - struct list_head *free = 0; + struct list_head *free = NULL; struct list_head *e; + spin_lock_bh(&buf->lock); while (buf->free_elts > buf->max_free_elts) { e = buf->elt_pool; diff --git a/drivers/staging/ozwpan/ozevent.c b/drivers/staging/ozwpan/ozevent.c deleted file mode 100644 index 7f66b4f19b0..00000000000 --- a/drivers/staging/ozwpan/ozevent.c +++ /dev/null @@ -1,195 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ----------------------------------------------------------------------------- - */ -#include "ozconfig.h" -#ifdef WANT_EVENT_TRACE -#include <linux/module.h> -#include <linux/debugfs.h> -#include <linux/jiffies.h> -#include <linux/uaccess.h> -#include "oztrace.h" -#include "ozevent.h" -#include "ozappif.h" -/*------------------------------------------------------------------------------ - * Although the event mask is logically part of the oz_evtdev structure, it is - * needed outside of this file so define it seperately to avoid the need to - * export definition of struct oz_evtdev. - */ -u32 g_evt_mask; -/*------------------------------------------------------------------------------ - */ -#define OZ_MAX_EVTS 2048 /* Must be power of 2 */ -struct oz_evtdev { - struct dentry *root_dir; - int evt_in; - int evt_out; - int missed_events; - int present; - atomic_t users; - spinlock_t lock; - struct oz_event evts[OZ_MAX_EVTS]; -}; - -static struct oz_evtdev g_evtdev; - -/*------------------------------------------------------------------------------ - * Context: process - */ -void oz_event_init(void) -{ - /* Because g_evtdev is static external all fields initally zero so no - * need to reinitialised those. - */ - oz_trace("Event tracing initialized\n"); - spin_lock_init(&g_evtdev.lock); - atomic_set(&g_evtdev.users, 0); -} -/*------------------------------------------------------------------------------ - * Context: process - */ -void oz_event_term(void) -{ - oz_trace("Event tracing terminated\n"); -} -/*------------------------------------------------------------------------------ - * Context: any - */ -void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4) -{ - unsigned long irqstate; - int ix; - spin_lock_irqsave(&g_evtdev.lock, irqstate); - ix = (g_evtdev.evt_in + 1) & (OZ_MAX_EVTS - 1); - if (ix != g_evtdev.evt_out) { - struct oz_event *e = &g_evtdev.evts[g_evtdev.evt_in]; - e->jiffies = jiffies; - e->evt = evt; - e->ctx1 = ctx1; - e->ctx2 = ctx2; - e->ctx3 = (__u32)(unsigned long)ctx3; - e->ctx4 = ctx4; - g_evtdev.evt_in = ix; - } else { - g_evtdev.missed_events++; - } - spin_unlock_irqrestore(&g_evtdev.lock, irqstate); -} -/*------------------------------------------------------------------------------ - * Context: process - */ -static void oz_events_clear(struct oz_evtdev *dev) -{ - unsigned long irqstate; - oz_trace("Clearing events\n"); - spin_lock_irqsave(&dev->lock, irqstate); - dev->evt_in = dev->evt_out = 0; - dev->missed_events = 0; - spin_unlock_irqrestore(&dev->lock, irqstate); -} -#ifdef CONFIG_DEBUG_FS -/*------------------------------------------------------------------------------ - * Context: process - */ -int oz_events_open(struct inode *inode, struct file *filp) -{ - oz_trace("oz_evt_open()\n"); - oz_trace("Open flags: 0x%x\n", filp->f_flags); - if (atomic_add_return(1, &g_evtdev.users) == 1) { - oz_events_clear(&g_evtdev); - return nonseekable_open(inode, filp); - } else { - atomic_dec(&g_evtdev.users); - return -EBUSY; - } -} -/*------------------------------------------------------------------------------ - * Context: process - */ -int oz_events_release(struct inode *inode, struct file *filp) -{ - oz_events_clear(&g_evtdev); - atomic_dec(&g_evtdev.users); - g_evt_mask = 0; - oz_trace("oz_evt_release()\n"); - return 0; -} -/*------------------------------------------------------------------------------ - * Context: process - */ -ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count, - loff_t *fpos) -{ - struct oz_evtdev *dev = &g_evtdev; - int rc = 0; - int nb_evts = count / sizeof(struct oz_event); - int n; - int sz; - - n = dev->evt_in - dev->evt_out; - if (n < 0) - n += OZ_MAX_EVTS; - if (nb_evts > n) - nb_evts = n; - if (nb_evts == 0) - goto out; - n = OZ_MAX_EVTS - dev->evt_out; - if (n > nb_evts) - n = nb_evts; - sz = n * sizeof(struct oz_event); - if (copy_to_user(buf, &dev->evts[dev->evt_out], sz)) { - rc = -EFAULT; - goto out; - } - if (n == nb_evts) - goto out2; - n = nb_evts - n; - if (copy_to_user(buf + sz, dev->evts, n * sizeof(struct oz_event))) { - rc = -EFAULT; - goto out; - } -out2: - dev->evt_out = (dev->evt_out + nb_evts) & (OZ_MAX_EVTS - 1); - rc = nb_evts * sizeof(struct oz_event); -out: - return rc; -} -/*------------------------------------------------------------------------------ - */ -const struct file_operations oz_events_fops = { - .owner = THIS_MODULE, - .open = oz_events_open, - .release = oz_events_release, - .read = oz_events_read, -}; -/*------------------------------------------------------------------------------ - * Context: process - */ -void oz_debugfs_init(void) -{ - struct dentry *parent; - - parent = debugfs_create_dir("ozwpan", NULL); - if (parent == NULL) { - oz_trace("Failed to create debugfs directory ozmo\n"); - return; - } else { - g_evtdev.root_dir = parent; - if (debugfs_create_file("events", S_IRUSR, parent, NULL, - &oz_events_fops) == NULL) - oz_trace("Failed to create file ozmo/events\n"); - if (debugfs_create_x32("event_mask", S_IRUSR | S_IWUSR, parent, - &g_evt_mask) == NULL) - oz_trace("Failed to create file ozmo/event_mask\n"); - } -} -/*------------------------------------------------------------------------------ - * Context: process - */ -void oz_debugfs_remove(void) -{ - debugfs_remove_recursive(g_evtdev.root_dir); -} -#endif /* CONFIG_DEBUG_FS */ -#endif /* WANT_EVENT_TRACE */ diff --git a/drivers/staging/ozwpan/ozevent.h b/drivers/staging/ozwpan/ozevent.h deleted file mode 100644 index 32f6f9859c4..00000000000 --- a/drivers/staging/ozwpan/ozevent.h +++ /dev/null @@ -1,32 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ----------------------------------------------------------------------------- - */ -#ifndef _OZEVENT_H -#define _OZEVENT_H -#include "ozconfig.h" -#include "ozeventdef.h" - -#ifdef WANT_EVENT_TRACE -extern u32 g_evt_mask; -void oz_event_init(void); -void oz_event_term(void); -void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4); -void oz_debugfs_init(void); -void oz_debugfs_remove(void); -#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4) \ - do { \ - if ((1<<(__evt)) & g_evt_mask) \ - oz_event_log2(__evt, __ctx1, __ctx2, __ctx3, __ctx4); \ - } while (0) - -#else -#define oz_event_init() -#define oz_event_term() -#define oz_event_log(__evt, __ctx1, __ctx2, __ctx3, __ctx4) -#define oz_debugfs_init() -#define oz_debugfs_remove() -#endif /* WANT_EVENT_TRACE */ - -#endif /* _OZEVENT_H */ diff --git a/drivers/staging/ozwpan/ozeventdef.h b/drivers/staging/ozwpan/ozeventdef.h deleted file mode 100644 index 4b938981671..00000000000 --- a/drivers/staging/ozwpan/ozeventdef.h +++ /dev/null @@ -1,40 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ----------------------------------------------------------------------------- - */ -#ifndef _OZEVENTDEF_H -#define _OZEVENTDEF_H - -#define OZ_EVT_RX_FRAME 0 -#define OZ_EVT_RX_PROCESS 1 -#define OZ_EVT_TX_FRAME 2 -#define OZ_EVT_TX_ISOC 3 -#define OZ_EVT_URB_SUBMIT 4 -#define OZ_EVT_URB_DONE 5 -#define OZ_EVT_URB_CANCEL 6 -#define OZ_EVT_CTRL_REQ 7 -#define OZ_EVT_CTRL_CNF 8 -#define OZ_EVT_CTRL_LOCAL 9 -#define OZ_EVT_CONNECT_REQ 10 -#define OZ_EVT_CONNECT_RSP 11 -#define OZ_EVT_EP_CREDIT 12 -#define OZ_EVT_EP_BUFFERING 13 -#define OZ_EVT_TX_ISOC_DONE 14 -#define OZ_EVT_TX_ISOC_DROP 15 -#define OZ_EVT_TIMER_CTRL 16 -#define OZ_EVT_TIMER 17 -#define OZ_EVT_PD_STATE 18 -#define OZ_EVT_SERVICE 19 -#define OZ_EVT_DEBUG 20 - -struct oz_event { - __u32 jiffies; - __u8 evt; - __u8 ctx1; - __u16 ctx2; - __u32 ctx3; - __u32 ctx4; -}; - -#endif /* _OZEVENTDEF_H */ diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index 251f07c39a6..30bd9286d47 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -26,31 +26,42 @@ */ #include <linux/platform_device.h> #include <linux/usb.h> -#include <linux/jiffies.h> #include <linux/slab.h> #include <linux/export.h> #include "linux/usb/hcd.h" #include <asm/unaligned.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozusbif.h" -#include "oztrace.h" #include "ozurbparanoia.h" -#include "ozevent.h" -/*------------------------------------------------------------------------------ +#include "ozhcd.h" + +/* * Number of units of buffering to capture for an isochronous IN endpoint before * allowing data to be indicated up. */ -#define OZ_IN_BUFFERING_UNITS 50 +#define OZ_IN_BUFFERING_UNITS 100 + /* Name of our platform device. */ #define OZ_PLAT_DEV_NAME "ozwpan" + /* Maximum number of free urb links that can be kept in the pool. */ #define OZ_MAX_LINK_POOL_SIZE 16 + /* Get endpoint object from the containing link. */ #define ep_from_link(__e) container_of((__e), struct oz_endpoint, link) -/*------------------------------------------------------------------------------ + +/*EP0 timeout before ep0 request is again added to TX queue. (13*8 = 98mSec) + */ +#define EP0_TIMEOUT_COUNTER 13 + +/* Debounce time HCD driver should wait before unregistering. + */ +#define OZ_HUB_DEBOUNCE_TIMEOUT 1500 + +/* * Used to link urbs together and also store some status information for each * urb. * A cache of these are kept in a pool to reduce number of calls to kmalloc. @@ -61,16 +72,18 @@ struct oz_urb_link { struct oz_port *port; u8 req_id; u8 ep_num; - unsigned long submit_jiffies; + unsigned submit_counter; }; /* Holds state information about a USB endpoint. */ +#define OZ_EP_BUFFER_SIZE_ISOC (1024 * 24) +#define OZ_EP_BUFFER_SIZE_INT 512 struct oz_endpoint { struct list_head urb_list; /* List of oz_urb_link items. */ struct list_head link; /* For isoc ep, links in to isoc lists of oz_port. */ - unsigned long last_jiffies; + struct timespec timestamp; int credit; int credit_ceiling; u8 ep_num; @@ -83,6 +96,7 @@ struct oz_endpoint { unsigned flags; int start_frame; }; + /* Bits in the flags field. */ #define OZ_F_EP_BUFFERING 0x1 #define OZ_F_EP_HAVE_STREAM 0x2 @@ -113,6 +127,7 @@ struct oz_port { struct list_head isoc_out_ep; struct list_head isoc_in_ep; }; + #define OZ_PORT_F_PRESENT 0x1 #define OZ_PORT_F_CHANGED 0x2 #define OZ_PORT_F_DYING 0x4 @@ -130,11 +145,12 @@ struct oz_hcd { uint flags; struct usb_hcd *hcd; }; + /* Bits in flags field. */ #define OZ_HDC_F_SUSPENDED 0x1 -/*------------------------------------------------------------------------------ +/* * Static function prototypes. */ static int oz_hcd_start(struct usb_hcd *hcd); @@ -174,7 +190,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, struct urb *urb); static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status); -/*------------------------------------------------------------------------------ + +/* * Static external variables. */ static struct platform_device *g_plat_dev; @@ -188,6 +205,7 @@ static DEFINE_SPINLOCK(g_tasklet_lock); static struct tasklet_struct g_urb_process_tasklet; static struct tasklet_struct g_urb_cancel_tasklet; static atomic_t g_pending_urbs = ATOMIC_INIT(0); +static atomic_t g_usb_frame_number = ATOMIC_INIT(0); static const struct hc_driver g_oz_hc_drv = { .description = g_hcd_name, .product_desc = "Ozmo Devices WPAN", @@ -218,7 +236,8 @@ static struct platform_driver g_oz_plat_drv = { .owner = THIS_MODULE, }, }; -/*------------------------------------------------------------------------------ + +/* * Gets our private context area (which is of type struct oz_hcd) from the * usb_hcd structure. * Context: any @@ -227,7 +246,8 @@ static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd) { return (struct oz_hcd *)hcd->hcd_priv; } -/*------------------------------------------------------------------------------ + +/* * Searches list of ports to find the index of the one with a specified USB * bus address. If none of the ports has the bus address then the connection * port is returned, if there is one or -1 otherwise. @@ -236,20 +256,23 @@ static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd) static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr) { int i; + for (i = 0; i < OZ_NB_PORTS; i++) { if (ozhcd->ports[i].bus_addr == bus_addr) return i; } return ozhcd->conn_port; } -/*------------------------------------------------------------------------------ + +/* * Allocates an urb link, first trying the pool but going to heap if empty. * Context: any */ static struct oz_urb_link *oz_alloc_urb_link(void) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; unsigned long irq_state; + spin_lock_irqsave(&g_link_lock, irq_state); if (g_link_pool) { urbl = container_of(g_link_pool, struct oz_urb_link, link); @@ -257,11 +280,12 @@ static struct oz_urb_link *oz_alloc_urb_link(void) --g_link_pool_size; } spin_unlock_irqrestore(&g_link_lock, irq_state); - if (urbl == 0) + if (urbl == NULL) urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC); return urbl; } -/*------------------------------------------------------------------------------ + +/* * Frees an urb link by putting it in the pool if there is enough space or * deallocating it to heap otherwise. * Context: any @@ -270,19 +294,20 @@ static void oz_free_urb_link(struct oz_urb_link *urbl) { if (urbl) { unsigned long irq_state; + spin_lock_irqsave(&g_link_lock, irq_state); if (g_link_pool_size < OZ_MAX_LINK_POOL_SIZE) { urbl->link.next = g_link_pool; g_link_pool = &urbl->link; - urbl = 0; + urbl = NULL; g_link_pool_size++; } spin_unlock_irqrestore(&g_link_lock, irq_state); - if (urbl) - kfree(urbl); + kfree(urbl); } } -/*------------------------------------------------------------------------------ + +/* * Deallocates all the urb links in the pool. * Context: unknown */ @@ -290,9 +315,10 @@ static void oz_empty_link_pool(void) { struct list_head *e; unsigned long irq_state; + spin_lock_irqsave(&g_link_lock, irq_state); e = g_link_pool; - g_link_pool = 0; + g_link_pool = NULL; g_link_pool_size = 0; spin_unlock_irqrestore(&g_link_lock, irq_state); while (e) { @@ -302,12 +328,13 @@ static void oz_empty_link_pool(void) kfree(urbl); } } -/*------------------------------------------------------------------------------ + +/* * Allocates endpoint structure and optionally a buffer. If a buffer is * allocated it immediately follows the endpoint structure. * Context: softirq */ -static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size) +static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags) { struct oz_endpoint *ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags); @@ -322,15 +349,18 @@ static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size) } return ep; } -/*------------------------------------------------------------------------------ + +/* * Pre-condition: Must be called with g_tasklet_lock held and interrupts * disabled. * Context: softirq or process */ -struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) +static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, + struct urb *urb) { struct oz_urb_link *urbl; struct list_head *e; + list_for_each(e, &ozhcd->urb_cancel_list) { urbl = container_of(e, struct oz_urb_link, link); if (urb == urbl->urb) { @@ -338,25 +368,27 @@ struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) return urbl; } } - return 0; + return NULL; } -/*------------------------------------------------------------------------------ + +/* * This is called when we have finished processing an urb. It unlinks it from * the ep and returns it to the core. * Context: softirq or process */ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, - int status, unsigned long submit_jiffies) + int status) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned long irq_state; - struct oz_urb_link *cancel_urbl = 0; + struct oz_urb_link *cancel_urbl; + spin_lock_irqsave(&g_tasklet_lock, irq_state); usb_hcd_unlink_urb_from_ep(hcd, urb); /* Clear hcpriv which will prevent it being put in the cancel list * in the event that an attempt is made to cancel it. */ - urb->hcpriv = 0; + urb->hcpriv = NULL; /* Walk the cancel list in case the urb is already sitting there. * Since we process the cancel list in a tasklet rather than in * the dequeue function this could happen. @@ -372,16 +404,9 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, */ spin_unlock(&g_tasklet_lock); if (oz_forget_urb(urb)) { - oz_trace("OZWPAN: ERROR Unknown URB %p\n", urb); + oz_dbg(ON, "ERROR Unknown URB %p\n", urb); } else { - static unsigned long last_time; atomic_dec(&g_pending_urbs); - oz_trace2(OZ_TRACE_URB, - "%lu: giveback_urb(%p,%x) %lu %lu pending:%d\n", - jiffies, urb, status, jiffies-submit_jiffies, - jiffies-last_time, atomic_read(&g_pending_urbs)); - last_time = jiffies; - oz_event_log(OZ_EVT_URB_DONE, 0, 0, urb, status); usb_hcd_giveback_urb(hcd, urb, status); } spin_lock(&g_tasklet_lock); @@ -389,17 +414,18 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, if (cancel_urbl) oz_free_urb_link(cancel_urbl); } -/*------------------------------------------------------------------------------ + +/* * Deallocates an endpoint including deallocating any associated stream and * returning any queued urbs to the core. * Context: softirq */ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) { - oz_trace("oz_ep_free()\n"); if (port) { struct list_head list; struct oz_hcd *ozhcd = port->ozhcd; + INIT_LIST_HEAD(&list); if (ep->flags & OZ_F_EP_HAVE_STREAM) oz_usb_stream_delete(port->hpd, ep->ep_num); @@ -411,26 +437,67 @@ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) list_splice_tail(&list, &ozhcd->orphanage); spin_unlock_bh(&ozhcd->hcd_lock); } - oz_trace("Freeing endpoint memory\n"); + oz_dbg(ON, "Freeing endpoint memory\n"); kfree(ep); } -/*------------------------------------------------------------------------------ + +/* + * Context: softirq + */ +static void oz_complete_buffered_urb(struct oz_port *port, + struct oz_endpoint *ep, + struct urb *urb) +{ + int data_len, available_space, copy_len; + + data_len = ep->buffer[ep->out_ix]; + if (data_len <= urb->transfer_buffer_length) + available_space = data_len; + else + available_space = urb->transfer_buffer_length; + + if (++ep->out_ix == ep->buffer_size) + ep->out_ix = 0; + copy_len = ep->buffer_size - ep->out_ix; + if (copy_len >= available_space) + copy_len = available_space; + memcpy(urb->transfer_buffer, &ep->buffer[ep->out_ix], copy_len); + + if (copy_len < available_space) { + memcpy((urb->transfer_buffer + copy_len), ep->buffer, + (available_space - copy_len)); + ep->out_ix = available_space - copy_len; + } else { + ep->out_ix += copy_len; + } + urb->actual_length = available_space; + if (ep->out_ix == ep->buffer_size) + ep->out_ix = 0; + + ep->buffered_units--; + oz_dbg(ON, "Trying to give back buffered frame of size=%d\n", + available_space); + oz_complete_urb(port->ozhcd->hcd, urb, 0); +} + +/* * Context: softirq */ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, struct urb *urb, u8 req_id) { struct oz_urb_link *urbl; - struct oz_endpoint *ep; + struct oz_endpoint *ep = NULL; int err = 0; + if (ep_addr >= OZ_NB_ENDPOINTS) { - oz_trace("Invalid endpoint number in oz_enqueue_ep_urb().\n"); + oz_dbg(ON, "%s: Invalid endpoint number\n", __func__); return -EINVAL; } urbl = oz_alloc_urb_link(); if (!urbl) return -ENOMEM; - urbl->submit_jiffies = jiffies; + urbl->submit_counter = 0; urbl->urb = urb; urbl->req_id = req_id; urbl->ep_num = ep_addr; @@ -443,32 +510,49 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, */ if (urb->unlinked) { spin_unlock_bh(&port->ozhcd->hcd_lock); - oz_trace("urb %p unlinked so complete immediately\n", urb); - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_dbg(ON, "urb %p unlinked so complete immediately\n", urb); + oz_complete_urb(port->ozhcd->hcd, urb, 0); oz_free_urb_link(urbl); return 0; } + if (in_dir) ep = port->in_ep[ep_addr]; else ep = port->out_ep[ep_addr]; - if (ep && port->hpd) { + if (!ep) { + err = -ENOMEM; + goto out; + } + + /*For interrupt endpoint check for buffered data + * & complete urb + */ + if (((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) + && ep->buffered_units > 0) { + oz_free_urb_link(urbl); + spin_unlock_bh(&port->ozhcd->hcd_lock); + oz_complete_buffered_urb(port, ep, urb); + return 0; + } + + if (port->hpd) { list_add_tail(&urbl->link, &ep->urb_list); if (!in_dir && ep_addr && (ep->credit < 0)) { - ep->last_jiffies = jiffies; + getrawmonotonic(&ep->timestamp); ep->credit = 0; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, - 0, 0, ep->credit); } } else { err = -EPIPE; } +out: spin_unlock_bh(&port->ozhcd->hcd_lock); if (err) oz_free_urb_link(urbl); return err; } -/*------------------------------------------------------------------------------ + +/* * Removes an urb from the queue in the endpoint. * Returns 0 if it is found and -EIDRM otherwise. * Context: softirq @@ -476,8 +560,9 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; struct oz_endpoint *ep; + spin_lock_bh(&port->ozhcd->hcd_lock); if (in_dir) ep = port->in_ep[ep_addr]; @@ -485,13 +570,14 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, ep = port->out_ep[ep_addr]; if (ep) { struct list_head *e; + list_for_each(e, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); if (urbl->urb == urb) { list_del_init(e); break; } - urbl = 0; + urbl = NULL; } } spin_unlock_bh(&port->ozhcd->hcd_lock); @@ -499,7 +585,8 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, oz_free_urb_link(urbl); return urbl ? 0 : -EIDRM; } -/*------------------------------------------------------------------------------ + +/* * Finds an urb given its request id. * Context: softirq */ @@ -507,14 +594,15 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, u8 req_id) { struct oz_hcd *ozhcd = port->ozhcd; - struct urb *urb = 0; - struct oz_urb_link *urbl = 0; + struct urb *urb = NULL; + struct oz_urb_link *urbl; struct oz_endpoint *ep; spin_lock_bh(&ozhcd->hcd_lock); ep = port->out_ep[ep_ix]; if (ep) { struct list_head *e; + list_for_each(e, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); if (urbl->req_id == req_id) { @@ -531,7 +619,8 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, oz_free_urb_link(urbl); return urb; } -/*------------------------------------------------------------------------------ + +/* * Pre-condition: Port lock must be held. * Context: softirq */ @@ -545,12 +634,14 @@ static void oz_acquire_port(struct oz_port *port, void *hpd) oz_usb_get(hpd); port->hpd = hpd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static struct oz_hcd *oz_hcd_claim(void) { struct oz_hcd *ozhcd; + spin_lock_bh(&g_hcdlock); ozhcd = g_ozhcd; if (ozhcd) @@ -558,7 +649,8 @@ static struct oz_hcd *oz_hcd_claim(void) spin_unlock_bh(&g_hcdlock); return ozhcd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static inline void oz_hcd_put(struct oz_hcd *ozhcd) @@ -566,7 +658,8 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd) if (ozhcd) usb_put_hcd(ozhcd->hcd); } -/*------------------------------------------------------------------------------ + +/* * This is called by the protocol handler to notify that a PD has arrived. * We allocate a port to associate with the PD and create a structure for * endpoint 0. This port is made the connection port. @@ -578,86 +671,85 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd) * probably very rare indeed. * Context: softirq */ -void *oz_hcd_pd_arrived(void *hpd) +struct oz_port *oz_hcd_pd_arrived(void *hpd) { int i; - void *hport = 0; - struct oz_hcd *ozhcd = 0; + struct oz_port *hport; + struct oz_hcd *ozhcd; struct oz_endpoint *ep; - oz_trace("oz_hcd_pd_arrived()\n"); + ozhcd = oz_hcd_claim(); - if (ozhcd == 0) - return 0; + if (!ozhcd) + return NULL; /* Allocate an endpoint object in advance (before holding hcd lock) to * use for out endpoint 0. */ - ep = oz_ep_alloc(GFP_ATOMIC, 0); + ep = oz_ep_alloc(0, GFP_ATOMIC); + if (!ep) + goto err_put; + spin_lock_bh(&ozhcd->hcd_lock); - if (ozhcd->conn_port >= 0) { - spin_unlock_bh(&ozhcd->hcd_lock); - oz_trace("conn_port >= 0\n"); - goto out; - } + if (ozhcd->conn_port >= 0) + goto err_unlock; + for (i = 0; i < OZ_NB_PORTS; i++) { struct oz_port *port = &ozhcd->ports[i]; + spin_lock(&port->port_lock); - if ((port->flags & OZ_PORT_F_PRESENT) == 0) { + if (!(port->flags & (OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED))) { oz_acquire_port(port, hpd); spin_unlock(&port->port_lock); break; } spin_unlock(&port->port_lock); } - if (i < OZ_NB_PORTS) { - oz_trace("Setting conn_port = %d\n", i); - ozhcd->conn_port = i; - /* Attach out endpoint 0. - */ - ozhcd->ports[i].out_ep[0] = ep; - ep = 0; - hport = &ozhcd->ports[i]; - spin_unlock_bh(&ozhcd->hcd_lock); - if (ozhcd->flags & OZ_HDC_F_SUSPENDED) { - oz_trace("Resuming root hub\n"); - usb_hcd_resume_root_hub(ozhcd->hcd); - } - usb_hcd_poll_rh_status(ozhcd->hcd); - } else { - spin_unlock_bh(&ozhcd->hcd_lock); - } -out: - if (ep) /* ep is non-null if not used. */ - oz_ep_free(0, ep); + if (i == OZ_NB_PORTS) + goto err_unlock; + + ozhcd->conn_port = i; + hport = &ozhcd->ports[i]; + hport->out_ep[0] = ep; + spin_unlock_bh(&ozhcd->hcd_lock); + if (ozhcd->flags & OZ_HDC_F_SUSPENDED) + usb_hcd_resume_root_hub(ozhcd->hcd); + usb_hcd_poll_rh_status(ozhcd->hcd); oz_hcd_put(ozhcd); + return hport; + +err_unlock: + spin_unlock_bh(&ozhcd->hcd_lock); + oz_ep_free(NULL, ep); +err_put: + oz_hcd_put(ozhcd); + return NULL; } -/*------------------------------------------------------------------------------ + +/* * This is called by the protocol handler to notify that the PD has gone away. * We need to deallocate all resources and then request that the root hub is * polled. We release the reference we hold on the PD. * Context: softirq */ -void oz_hcd_pd_departed(void *hport) +void oz_hcd_pd_departed(struct oz_port *port) { - struct oz_port *port = (struct oz_port *)hport; struct oz_hcd *ozhcd; void *hpd; - struct oz_endpoint *ep = 0; + struct oz_endpoint *ep = NULL; - oz_trace("oz_hcd_pd_departed()\n"); - if (port == 0) { - oz_trace("oz_hcd_pd_departed() port = 0\n"); + if (port == NULL) { + oz_dbg(ON, "%s: port = 0\n", __func__); return; } ozhcd = port->ozhcd; - if (ozhcd == 0) + if (ozhcd == NULL) return; /* Check if this is the connection port - if so clear it. */ spin_lock_bh(&ozhcd->hcd_lock); if ((ozhcd->conn_port >= 0) && (port == &ozhcd->ports[ozhcd->conn_port])) { - oz_trace("Clearing conn_port\n"); + oz_dbg(ON, "Clearing conn_port\n"); ozhcd->conn_port = -1; } spin_lock(&port->port_lock); @@ -668,18 +760,19 @@ void oz_hcd_pd_departed(void *hport) oz_clean_endpoints_for_config(ozhcd->hcd, port); spin_lock_bh(&port->port_lock); hpd = port->hpd; - port->hpd = 0; + port->hpd = NULL; port->bus_addr = 0xff; + port->config_num = 0; port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING); port->flags |= OZ_PORT_F_CHANGED; - port->status &= ~USB_PORT_STAT_CONNECTION; + port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE); port->status |= (USB_PORT_STAT_C_CONNECTION << 16); /* If there is an endpont 0 then clear the pointer while we hold * the spinlock be we deallocate it after releasing the lock. */ if (port->out_ep[0]) { ep = port->out_ep[0]; - port->out_ep[0] = 0; + port->out_ep[0] = NULL; } spin_unlock_bh(&port->port_lock); if (ep) @@ -687,7 +780,8 @@ void oz_hcd_pd_departed(void *hport) usb_hcd_poll_rh_status(ozhcd->hcd); oz_usb_put(hpd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ void oz_hcd_pd_reset(void *hpd, void *hport) @@ -696,7 +790,8 @@ void oz_hcd_pd_reset(void *hpd, void *hport) */ struct oz_port *port = (struct oz_port *)hport; struct oz_hcd *ozhcd = port->ozhcd; - oz_trace("PD Reset\n"); + + oz_dbg(ON, "PD Reset\n"); spin_lock_bh(&port->port_lock); port->flags |= OZ_PORT_F_CHANGED; port->status |= USB_PORT_STAT_RESET; @@ -705,25 +800,26 @@ void oz_hcd_pd_reset(void *hpd, void *hport) oz_clean_endpoints_for_config(ozhcd->hcd, port); usb_hcd_poll_rh_status(ozhcd->hcd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, +void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, int length, int offset, int total_size) { struct oz_port *port = (struct oz_port *)hport; struct urb *urb; int err = 0; - oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, status); - oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", - length, offset, total_size); + oz_dbg(ON, "oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", + length, offset, total_size); urb = oz_find_urb_by_id(port, 0, req_id); if (!urb) return; if (status == 0) { int copy_len; int required_size = urb->transfer_buffer_length; + if (required_size > total_size) required_size = total_size; copy_len = required_size-offset; @@ -735,6 +831,7 @@ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, struct usb_ctrlrequest *setup = (struct usb_ctrlrequest *)urb->setup_packet; unsigned wvalue = le16_to_cpu(setup->wValue); + if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id)) err = -ENOMEM; else if (oz_usb_get_desc_req(port->hpd, req_id, @@ -749,54 +846,52 @@ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, } } urb->actual_length = total_size; - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -#ifdef WANT_TRACE static void oz_display_conf_type(u8 t) { switch (t) { case USB_REQ_GET_STATUS: - oz_trace("USB_REQ_GET_STATUS - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_STATUS - cnf\n"); break; case USB_REQ_CLEAR_FEATURE: - oz_trace("USB_REQ_CLEAR_FEATURE - cnf\n"); + oz_dbg(ON, "USB_REQ_CLEAR_FEATURE - cnf\n"); break; case USB_REQ_SET_FEATURE: - oz_trace("USB_REQ_SET_FEATURE - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_FEATURE - cnf\n"); break; case USB_REQ_SET_ADDRESS: - oz_trace("USB_REQ_SET_ADDRESS - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_ADDRESS - cnf\n"); break; case USB_REQ_GET_DESCRIPTOR: - oz_trace("USB_REQ_GET_DESCRIPTOR - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n"); break; case USB_REQ_SET_DESCRIPTOR: - oz_trace("USB_REQ_SET_DESCRIPTOR - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_DESCRIPTOR - cnf\n"); break; case USB_REQ_GET_CONFIGURATION: - oz_trace("USB_REQ_GET_CONFIGURATION - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - cnf\n"); break; case USB_REQ_SET_CONFIGURATION: - oz_trace("USB_REQ_SET_CONFIGURATION - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - cnf\n"); break; case USB_REQ_GET_INTERFACE: - oz_trace("USB_REQ_GET_INTERFACE - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_INTERFACE - cnf\n"); break; case USB_REQ_SET_INTERFACE: - oz_trace("USB_REQ_SET_INTERFACE - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_INTERFACE - cnf\n"); break; case USB_REQ_SYNCH_FRAME: - oz_trace("USB_REQ_SYNCH_FRAME - cnf\n"); + oz_dbg(ON, "USB_REQ_SYNCH_FRAME - cnf\n"); break; } } -#else -#define oz_display_conf_type(__x) -#endif /* WANT_TRACE */ -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, @@ -804,6 +899,7 @@ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, { int rc = 0; struct usb_hcd *hcd = port->ozhcd->hcd; + if (rcode == 0) { port->config_num = config_num; oz_clean_endpoints_for_config(hcd, port); @@ -814,9 +910,10 @@ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, } else { rc = -ENOMEM; } - oz_complete_urb(hcd, urb, rc, 0); + oz_complete_urb(hcd, urb, rc); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, @@ -824,10 +921,12 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, { struct usb_hcd *hcd = port->ozhcd->hcd; int rc = 0; - if (rcode == 0) { + + if ((rcode == 0) && (port->config_num > 0)) { struct usb_host_config *config; struct usb_host_interface *intf; - oz_trace("Set interface %d alt %d\n", if_num, alt); + + oz_dbg(ON, "Set interface %d alt %d\n", if_num, alt); oz_clean_endpoints_for_interface(hcd, port, if_num); config = &urb->dev->config[port->config_num-1]; intf = &config->intf_cache[if_num]->altsetting[alt]; @@ -839,12 +938,13 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, } else { rc = -ENOMEM; } - oz_complete_urb(hcd, urb, rc, 0); + oz_complete_urb(hcd, urb, rc); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, +void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, int data_len) { struct oz_port *port = (struct oz_port *)hport; @@ -854,11 +954,10 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, unsigned windex; unsigned wvalue; - oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, rcode); - oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); + oz_dbg(ON, "oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); urb = oz_find_urb_by_id(port, 0, req_id); if (!urb) { - oz_trace("URB not found\n"); + oz_dbg(ON, "URB not found\n"); return; } setup = (struct usb_ctrlrequest *)urb->setup_packet; @@ -877,36 +976,41 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, (u8)windex, (u8)wvalue); break; default: - oz_complete_urb(hcd, urb, 0, 0); + oz_complete_urb(hcd, urb, 0); } } else { int copy_len; - oz_trace("VENDOR-CLASS - cnf\n"); - if (data_len <= urb->transfer_buffer_length) - copy_len = data_len; - else - copy_len = urb->transfer_buffer_length; - if (copy_len) + + oz_dbg(ON, "VENDOR-CLASS - cnf\n"); + if (data_len) { + if (data_len <= urb->transfer_buffer_length) + copy_len = data_len; + else + copy_len = urb->transfer_buffer_length; memcpy(urb->transfer_buffer, data, copy_len); - urb->actual_length = copy_len; - oz_complete_urb(hcd, urb, 0, 0); + urb->actual_length = copy_len; + } + oz_complete_urb(hcd, urb, 0); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len) +static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, + int data_len) { int space; int copy_len; + if (!ep->buffer) return -1; space = ep->out_ix-ep->in_ix-1; if (space < 0) space += ep->buffer_size; if (space < (data_len+1)) { - oz_trace("Buffer full\n"); + oz_dbg(ON, "Buffer full\n"); return -1; } ep->buffer[ep->in_ix] = (u8)data_len; @@ -928,17 +1032,19 @@ static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len) ep->buffered_units++; return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) +void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) { struct oz_port *port = (struct oz_port *)hport; struct oz_endpoint *ep; struct oz_hcd *ozhcd = port->ozhcd; + spin_lock_bh(&ozhcd->hcd_lock); ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK]; - if (ep == 0) + if (ep == NULL) goto done; switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) { case USB_ENDPOINT_XFER_INT: @@ -949,6 +1055,7 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) struct oz_urb_link, link); struct urb *urb; int copy_len; + list_del_init(&urbl->link); spin_unlock_bh(&ozhcd->hcd_lock); urb = urbl->urb; @@ -959,8 +1066,11 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) copy_len = urb->transfer_buffer_length; memcpy(urb->transfer_buffer, data, copy_len); urb->actual_length = copy_len; - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); return; + } else { + oz_dbg(ON, "buffering frame as URB is not available\n"); + oz_hcd_buffer_data(ep, data, data_len); } break; case USB_ENDPOINT_XFER_ISOC: @@ -970,14 +1080,16 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) done: spin_unlock_bh(&ozhcd->hcd_lock); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static inline int oz_usb_get_frame_number(void) { - return jiffies_to_msecs(get_jiffies_64()); + return atomic_inc_return(&g_usb_frame_number); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_hcd_heartbeat(void *hport) @@ -991,7 +1103,9 @@ int oz_hcd_heartbeat(void *hport) struct list_head *n; struct urb *urb; struct oz_endpoint *ep; - unsigned long now = jiffies; + struct timespec ts, delta; + + getrawmonotonic(&ts); INIT_LIST_HEAD(&xfr_list); /* Check the OUT isoc endpoints to see if any URB data can be sent. */ @@ -1000,62 +1114,54 @@ int oz_hcd_heartbeat(void *hport) ep = ep_from_link(e); if (ep->credit < 0) continue; - ep->credit += (now - ep->last_jiffies); + delta = timespec_sub(ts, ep->timestamp); + ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); if (ep->credit > ep->credit_ceiling) ep->credit = ep->credit_ceiling; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, ep->credit); - ep->last_jiffies = now; + ep->timestamp = ts; while (ep->credit && !list_empty(&ep->urb_list)) { urbl = list_first_entry(&ep->urb_list, struct oz_urb_link, link); urb = urbl->urb; - if (ep->credit < urb->number_of_packets) + if ((ep->credit + 1) < urb->number_of_packets) break; ep->credit -= urb->number_of_packets; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, - ep->credit); - list_del(&urbl->link); - list_add_tail(&urbl->link, &xfr_list); + if (ep->credit < 0) + ep->credit = 0; + list_move_tail(&urbl->link, &xfr_list); } } spin_unlock_bh(&ozhcd->hcd_lock); /* Send to PD and complete URBs. */ list_for_each_safe(e, n, &xfr_list) { - unsigned long t; urbl = container_of(e, struct oz_urb_link, link); urb = urbl->urb; - t = urbl->submit_jiffies; list_del_init(e); urb->error_count = 0; urb->start_frame = oz_usb_get_frame_number(); oz_usb_send_isoc(port->hpd, urbl->ep_num, urb); oz_free_urb_link(urbl); - oz_complete_urb(port->ozhcd->hcd, urb, 0, t); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } /* Check the IN isoc endpoints to see if any URBs can be completed. */ spin_lock_bh(&ozhcd->hcd_lock); list_for_each(e, &port->isoc_in_ep) { struct oz_endpoint *ep = ep_from_link(e); + if (ep->flags & OZ_F_EP_BUFFERING) { - if (ep->buffered_units * OZ_IN_BUFFERING_UNITS) { + if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) { ep->flags &= ~OZ_F_EP_BUFFERING; ep->credit = 0; - oz_event_log(OZ_EVT_EP_CREDIT, - ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); - ep->last_jiffies = now; + ep->timestamp = ts; ep->start_frame = 0; - oz_event_log(OZ_EVT_EP_BUFFERING, - ep->ep_num | USB_DIR_IN, 0, 0, 0); } continue; } - ep->credit += (now - ep->last_jiffies); - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); - ep->last_jiffies = now; + delta = timespec_sub(ts, ep->timestamp); + ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); + ep->timestamp = ts; while (!list_empty(&ep->urb_list)) { struct oz_urb_link *urbl = list_first_entry(&ep->urb_list, @@ -1064,7 +1170,8 @@ int oz_hcd_heartbeat(void *hport) int len = 0; int copy_len; int i; - if (ep->credit < urb->number_of_packets) + + if (ep->credit < urb->number_of_packets) break; if (ep->buffered_units < urb->number_of_packets) break; @@ -1096,11 +1203,8 @@ int oz_hcd_heartbeat(void *hport) urb->error_count = 0; urb->start_frame = ep->start_frame; ep->start_frame += urb->number_of_packets; - list_del(&urbl->link); - list_add_tail(&urbl->link, &xfr_list); + list_move_tail(&urbl->link, &xfr_list); ep->credit -= urb->number_of_packets; - oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, - 0, 0, ep->credit); } } if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep)) @@ -1113,7 +1217,7 @@ int oz_hcd_heartbeat(void *hport) urb = urbl->urb; list_del_init(e); oz_free_urb_link(urbl); - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } /* Check if there are any ep0 requests that have timed out. * If so resent to PD. @@ -1122,15 +1226,16 @@ int oz_hcd_heartbeat(void *hport) if (ep) { struct list_head *e; struct list_head *n; + spin_lock_bh(&ozhcd->hcd_lock); list_for_each_safe(e, n, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); - if (time_after(now, urbl->submit_jiffies+HZ/2)) { - oz_trace("%ld: Request 0x%p timeout\n", - now, urbl->urb); - urbl->submit_jiffies = now; - list_del(e); - list_add_tail(e, &xfr_list); + if (urbl->submit_counter > EP0_TIMEOUT_COUNTER) { + oz_dbg(ON, "Request 0x%p timeout\n", urbl->urb); + list_move_tail(e, &xfr_list); + urbl->submit_counter = 0; + } else { + urbl->submit_counter++; } } if (!list_empty(&ep->urb_list)) @@ -1140,14 +1245,15 @@ int oz_hcd_heartbeat(void *hport) while (e != &xfr_list) { urbl = container_of(e, struct oz_urb_link, link); e = e->next; - oz_trace("Resending request to PD.\n"); + oz_dbg(ON, "Resending request to PD\n"); oz_process_ep0_urb(ozhcd, urbl->urb, GFP_ATOMIC); oz_free_urb_link(urbl); } } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, @@ -1158,7 +1264,10 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, int i; int if_ix = intf->desc.bInterfaceNumber; int request_heartbeat = 0; - oz_trace("interface[%d] = %p\n", if_ix, intf); + + oz_dbg(ON, "interface[%d] = %p\n", if_ix, intf); + if (if_ix >= port->num_iface || port->iface == NULL) + return -ENOMEM; for (i = 0; i < intf->desc.bNumEndpoints; i++) { struct usb_host_endpoint *hep = &intf->endpoint[i]; u8 ep_addr = hep->desc.bEndpointAddress; @@ -1166,14 +1275,20 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, struct oz_endpoint *ep; int buffer_size = 0; - oz_trace("%d bEndpointAddress = %x\n", i, ep_addr); - if ((ep_addr & USB_ENDPOINT_DIR_MASK) && - ((hep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_ISOC)) { - buffer_size = 24*1024; + oz_dbg(ON, "%d bEndpointAddress = %x\n", i, ep_addr); + if (ep_addr & USB_ENDPOINT_DIR_MASK) { + switch (hep->desc.bmAttributes & + USB_ENDPOINT_XFERTYPE_MASK) { + case USB_ENDPOINT_XFER_ISOC: + buffer_size = OZ_EP_BUFFER_SIZE_ISOC; + break; + case USB_ENDPOINT_XFER_INT: + buffer_size = OZ_EP_BUFFER_SIZE_INT; + break; + } } - ep = oz_ep_alloc(mem_flags, buffer_size); + ep = oz_ep_alloc(buffer_size, mem_flags); if (!ep) { oz_clean_endpoints_for_interface(hcd, port, if_ix); return -ENOMEM; @@ -1182,13 +1297,11 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, ep->ep_num = ep_num; if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC) { - oz_trace("wMaxPacketSize = %d\n", - hep->desc.wMaxPacketSize); + oz_dbg(ON, "wMaxPacketSize = %d\n", + usb_endpoint_maxp(&hep->desc)); ep->credit_ceiling = 200; if (ep_addr & USB_ENDPOINT_DIR_MASK) { ep->flags |= OZ_F_EP_BUFFERING; - oz_event_log(OZ_EVT_EP_BUFFERING, - ep->ep_num | USB_DIR_IN, 1, 0, 0); } else { ep->flags |= OZ_F_EP_HAVE_STREAM; if (oz_usb_stream_create(port->hpd, ep_num)) @@ -1220,7 +1333,8 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, @@ -1231,7 +1345,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, int i; struct list_head ep_list; - oz_trace("Deleting endpoints for interface %d\n", if_ix); + oz_dbg(ON, "Deleting endpoints for interface %d\n", if_ix); if (if_ix >= port->num_iface) return; INIT_LIST_HEAD(&ep_list); @@ -1244,19 +1358,17 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, */ if ((mask & (1<<i)) && port->out_ep[i]) { e = &port->out_ep[i]->link; - port->out_ep[i] = 0; + port->out_ep[i] = NULL; /* Remove from isoc list if present. */ - list_del(e); - list_add_tail(e, &ep_list); + list_move_tail(e, &ep_list); } /* Gather IN endpoints. */ if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) { e = &port->in_ep[i]->link; - port->in_ep[i] = 0; - list_del(e); - list_add_tail(e, &ep_list); + port->in_ep[i] = NULL; + list_move_tail(e, &ep_list); } } spin_unlock_bh(&ozhcd->hcd_lock); @@ -1267,7 +1379,8 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, oz_ep_free(port, ep); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_build_endpoints_for_config(struct usb_hcd *hcd, @@ -1277,6 +1390,7 @@ static int oz_build_endpoints_for_config(struct usb_hcd *hcd, struct oz_hcd *ozhcd = port->ozhcd; int i; int num_iface = config->desc.bNumInterfaces; + if (num_iface) { struct oz_interface *iface; @@ -1301,7 +1415,8 @@ fail: oz_clean_endpoints_for_config(hcd, port); return -1; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, @@ -1309,25 +1424,28 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, { struct oz_hcd *ozhcd = port->ozhcd; int i; - oz_trace("Deleting endpoints for configuration.\n"); + + oz_dbg(ON, "Deleting endpoints for configuration\n"); for (i = 0; i < port->num_iface; i++) oz_clean_endpoints_for_interface(hcd, port, i); spin_lock_bh(&ozhcd->hcd_lock); if (port->iface) { - oz_trace("Freeing interfaces object.\n"); + oz_dbg(ON, "Freeing interfaces object\n"); kfree(port->iface); - port->iface = 0; + port->iface = NULL; } port->num_iface = 0; spin_unlock_bh(&ozhcd->hcd_lock); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void *oz_claim_hpd(struct oz_port *port) { - void *hpd = 0; + void *hpd; struct oz_hcd *ozhcd = port->ozhcd; + spin_lock_bh(&ozhcd->hcd_lock); hpd = port->hpd; if (hpd) @@ -1335,7 +1453,8 @@ static void *oz_claim_hpd(struct oz_port *port) spin_unlock_bh(&ozhcd->hcd_lock); return hpd; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, @@ -1345,15 +1464,15 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, unsigned windex; unsigned wvalue; unsigned wlength; - void *hpd = 0; + void *hpd; u8 req_id; int rc = 0; unsigned complete = 0; int port_ix = -1; - struct oz_port *port = 0; + struct oz_port *port = NULL; - oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb); + oz_dbg(URB, "[%s]:(%p)\n", __func__, urb); port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); if (port_ix < 0) { rc = -EPIPE; @@ -1362,8 +1481,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, port = &ozhcd->ports[port_ix]; if (((port->flags & OZ_PORT_F_PRESENT) == 0) || (port->flags & OZ_PORT_F_DYING)) { - oz_trace("Refusing URB port_ix = %d devnum = %d\n", - port_ix, urb->dev->devnum); + oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", + port_ix, urb->dev->devnum); rc = -EPIPE; goto out; } @@ -1374,17 +1493,16 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, windex = le16_to_cpu(setup->wIndex); wvalue = le16_to_cpu(setup->wValue); wlength = le16_to_cpu(setup->wLength); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequestType = %x\n", - setup->bRequestType); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequest = %x\n", setup->bRequest); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wValue = %x\n", wvalue); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wIndex = %x\n", windex); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wLength = %x\n", wlength); + oz_dbg(CTRL_DETAIL, "bRequestType = %x\n", setup->bRequestType); + oz_dbg(CTRL_DETAIL, "bRequest = %x\n", setup->bRequest); + oz_dbg(CTRL_DETAIL, "wValue = %x\n", wvalue); + oz_dbg(CTRL_DETAIL, "wIndex = %x\n", windex); + oz_dbg(CTRL_DETAIL, "wLength = %x\n", wlength); req_id = port->next_req_id++; hpd = oz_claim_hpd(port); - if (hpd == 0) { - oz_trace("Cannot claim port\n"); + if (hpd == NULL) { + oz_dbg(ON, "Cannot claim port\n"); rc = -EPIPE; goto out; } @@ -1394,34 +1512,31 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, */ switch (setup->bRequest) { case USB_REQ_GET_DESCRIPTOR: - oz_trace("USB_REQ_GET_DESCRIPTOR - req\n"); + oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - req\n"); break; case USB_REQ_SET_ADDRESS: - oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, - 0, 0, setup->bRequestType); - oz_trace("USB_REQ_SET_ADDRESS - req\n"); - oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port, - (u8)le16_to_cpu(setup->wValue)); + oz_dbg(ON, "USB_REQ_SET_ADDRESS - req\n"); + oz_dbg(ON, "Port %d address is 0x%x\n", + ozhcd->conn_port, + (u8)le16_to_cpu(setup->wValue)); spin_lock_bh(&ozhcd->hcd_lock); if (ozhcd->conn_port >= 0) { ozhcd->ports[ozhcd->conn_port].bus_addr = (u8)le16_to_cpu(setup->wValue); - oz_trace("Clearing conn_port\n"); + oz_dbg(ON, "Clearing conn_port\n"); ozhcd->conn_port = -1; } spin_unlock_bh(&ozhcd->hcd_lock); complete = 1; break; case USB_REQ_SET_CONFIGURATION: - oz_trace("USB_REQ_SET_CONFIGURATION - req\n"); + oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - req\n"); break; case USB_REQ_GET_CONFIGURATION: /* We short circuit this case and reply directly since * we have the selected configuration number cached. */ - oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, - setup->bRequestType); - oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n"); + oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; *((u8 *)urb->transfer_buffer) = @@ -1435,29 +1550,29 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, /* We short circuit this case and reply directly since * we have the selected interface alternative cached. */ - oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, - setup->bRequestType); - oz_trace("USB_REQ_GET_INTERFACE - reply now\n"); + oz_dbg(ON, "USB_REQ_GET_INTERFACE - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; *((u8 *)urb->transfer_buffer) = port->iface[(u8)windex].alt; - oz_trace("interface = %d alt = %d\n", - windex, port->iface[(u8)windex].alt); + oz_dbg(ON, "interface = %d alt = %d\n", + windex, port->iface[(u8)windex].alt); complete = 1; } else { rc = -EPIPE; } break; case USB_REQ_SET_INTERFACE: - oz_trace("USB_REQ_SET_INTERFACE - req\n"); + oz_dbg(ON, "USB_REQ_SET_INTERFACE - req\n"); break; } } if (!rc && !complete) { int data_len = 0; + if ((setup->bRequestType & USB_DIR_IN) == 0) data_len = wlength; + urb->actual_length = data_len; if (oz_usb_control_req(port->hpd, req_id, setup, urb->transfer_buffer, data_len)) { rc = -ENOMEM; @@ -1480,13 +1595,14 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, oz_usb_put(hpd); out: if (rc || complete) { - oz_trace("Completing request locally\n"); - oz_complete_urb(ozhcd->hcd, urb, rc, 0); + oz_dbg(ON, "Completing request locally\n"); + oz_complete_urb(ozhcd->hcd, urb, rc); } else { oz_usb_request_heartbeat(port->hpd); } } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) @@ -1494,6 +1610,7 @@ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) int rc = 0; struct oz_port *port = urb->hcpriv; u8 ep_addr; + /* When we are paranoid we keep a list of urbs which we check against * before handing one back. This is just for debugging during * development and should be turned off in the released driver. @@ -1519,7 +1636,8 @@ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_urb_process_tasklet(unsigned long unused) @@ -1528,7 +1646,8 @@ static void oz_urb_process_tasklet(unsigned long unused) struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); int rc = 0; - if (ozhcd == 0) + + if (ozhcd == NULL) return; /* This is called from a tasklet so is in softirq context but the urb * list is filled from any context so we need to lock @@ -1545,13 +1664,14 @@ static void oz_urb_process_tasklet(unsigned long unused) oz_free_urb_link(urbl); rc = oz_urb_process(ozhcd, urb); if (rc) - oz_complete_urb(ozhcd->hcd, urb, rc, 0); + oz_complete_urb(ozhcd->hcd, urb, rc); spin_lock_irqsave(&g_tasklet_lock, irq_state); } spin_unlock_irqrestore(&g_tasklet_lock, irq_state); oz_hcd_put(ozhcd); } -/*------------------------------------------------------------------------------ + +/* * This function searches for the urb in any of the lists it could be in. * If it is found it is removed from the list and completed. If the urb is * being processed then it won't be in a list so won't be found. However, the @@ -1562,18 +1682,19 @@ static void oz_urb_process_tasklet(unsigned long unused) */ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl = NULL; struct list_head *e; struct oz_hcd *ozhcd; unsigned long irq_state; u8 ix; - if (port == 0) { - oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb); + + if (port == NULL) { + oz_dbg(ON, "%s: ERROR: (%p) port is null\n", __func__, urb); return; } ozhcd = port->ozhcd; - if (ozhcd == 0) { - oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb); + if (ozhcd == NULL) { + oz_dbg(ON, "%s; ERROR: (%p) ozhcd is null\n", __func__, urb); return; } @@ -1589,7 +1710,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) } } spin_unlock_irqrestore(&g_tasklet_lock, irq_state); - urbl = 0; + urbl = NULL; /* Look in the orphanage. */ @@ -1598,12 +1719,12 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) urbl = container_of(e, struct oz_urb_link, link); if (urbl->urb == urb) { list_del(e); - oz_trace("Found urb in orphanage\n"); + oz_dbg(ON, "Found urb in orphanage\n"); goto out; } } ix = (ep_num & 0xf); - urbl = 0; + urbl = NULL; if ((ep_num & USB_DIR_IN) && ix) urbl = oz_remove_urb(port->in_ep[ix], urb); else @@ -1614,10 +1735,11 @@ out2: if (urbl) { urb->actual_length = 0; oz_free_urb_link(urbl); - oz_complete_urb(ozhcd->hcd, urb, -EPIPE, 0); + oz_complete_urb(ozhcd->hcd, urb, -EPIPE); } } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_urb_cancel_tasklet(unsigned long unused) @@ -1625,7 +1747,8 @@ static void oz_urb_cancel_tasklet(unsigned long unused) unsigned long irq_state; struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); - if (ozhcd == 0) + + if (ozhcd == NULL) return; spin_lock_irqsave(&g_tasklet_lock, irq_state); while (!list_empty(&ozhcd->urb_cancel_list)) { @@ -1643,62 +1766,51 @@ static void oz_urb_cancel_tasklet(unsigned long unused) spin_unlock_irqrestore(&g_tasklet_lock, irq_state); oz_hcd_put(ozhcd); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status) { if (ozhcd) { struct oz_urb_link *urbl; + while (!list_empty(&ozhcd->orphanage)) { urbl = list_first_entry(&ozhcd->orphanage, struct oz_urb_link, link); list_del(&urbl->link); - oz_complete_urb(ozhcd->hcd, urbl->urb, status, 0); + oz_complete_urb(ozhcd->hcd, urbl->urb, status); oz_free_urb_link(urbl); } } } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_hcd_start(struct usb_hcd *hcd) { - oz_trace("oz_hcd_start()\n"); hcd->power_budget = 200; hcd->state = HC_STATE_RUNNING; hcd->uses_new_polling = 1; return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_stop(struct usb_hcd *hcd) { - oz_trace("oz_hcd_stop()\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_shutdown(struct usb_hcd *hcd) { - oz_trace("oz_hcd_shutdown()\n"); } -/*------------------------------------------------------------------------------ - * Context: any - */ -#ifdef WANT_EVENT_TRACE -static u8 oz_get_irq_ctx(void) -{ - u8 irq_info = 0; - if (in_interrupt()) - irq_info |= 1; - if (in_irq()) - irq_info |= 2; - return irq_info; -} -#endif /* WANT_EVENT_TRACE */ -/*------------------------------------------------------------------------------ + +/* * Called to queue an urb for the device. * This function should return a non-zero error code if it fails the urb but * should not call usb_hcd_giveback_urb(). @@ -1708,41 +1820,38 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); - int rc = 0; + int rc; int port_ix; struct oz_port *port; unsigned long irq_state; struct oz_urb_link *urbl; - oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_enqueue(%p)\n", - jiffies, urb); - oz_event_log(OZ_EVT_URB_SUBMIT, oz_get_irq_ctx(), - (u16)urb->number_of_packets, urb, urb->pipe); - if (unlikely(ozhcd == 0)) { - oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n", - jiffies, urb); + + oz_dbg(URB, "%s: (%p)\n", __func__, urb); + if (unlikely(ozhcd == NULL)) { + oz_dbg(URB, "Refused urb(%p) not ozhcd\n", urb); return -EPIPE; } if (unlikely(hcd->state != HC_STATE_RUNNING)) { - oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not running.\n", - jiffies, urb); + oz_dbg(URB, "Refused urb(%p) not running\n", urb); return -EPIPE; } port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); if (port_ix < 0) return -EPIPE; port = &ozhcd->ports[port_ix]; - if (port == 0) + if (port == NULL) return -EPIPE; - if ((port->flags & OZ_PORT_F_PRESENT) == 0) { - oz_trace("Refusing URB port_ix = %d devnum = %d\n", - port_ix, urb->dev->devnum); + if (!(port->flags & OZ_PORT_F_PRESENT) || + (port->flags & OZ_PORT_F_CHANGED)) { + oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", + port_ix, urb->dev->devnum); return -EPIPE; } urb->hcpriv = port; /* Put request in queue for processing by tasklet. */ urbl = oz_alloc_urb_link(); - if (unlikely(urbl == 0)) + if (unlikely(urbl == NULL)) return -ENOMEM; urbl->urb = urb; spin_lock_irqsave(&g_tasklet_lock, irq_state); @@ -1758,16 +1867,18 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, atomic_inc(&g_pending_urbs); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, struct urb *urb) { - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl; struct list_head *e; - if (unlikely(ep == 0)) - return 0; + + if (unlikely(ep == NULL)) + return NULL; list_for_each(e, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); if (urbl->urb == urb) { @@ -1776,29 +1887,27 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, ep->credit -= urb->number_of_packets; if (ep->credit < 0) ep->credit = 0; - oz_event_log(OZ_EVT_EP_CREDIT, - usb_pipein(urb->pipe) ? - (ep->ep_num | USB_DIR_IN) : ep->ep_num, - 0, 0, ep->credit); } return urbl; } } - return 0; + return NULL; } -/*------------------------------------------------------------------------------ + +/* * Called to dequeue a previously submitted urb for the device. * Context: any */ static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); - struct oz_urb_link *urbl = 0; + struct oz_urb_link *urbl; int rc; unsigned long irq_state; - oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb); + + oz_dbg(URB, "%s: (%p)\n", __func__, urb); urbl = oz_alloc_urb_link(); - if (unlikely(urbl == 0)) + if (unlikely(urbl == NULL)) return -ENOMEM; spin_lock_irqsave(&g_tasklet_lock, irq_state); /* The following function checks the urb is still in the queue @@ -1826,31 +1935,33 @@ static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) { - oz_trace("oz_hcd_endpoint_disable\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) { - oz_trace("oz_hcd_endpoint_reset\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_hcd_get_frame_number(struct usb_hcd *hcd) { - oz_trace("oz_hcd_get_frame_number\n"); + oz_dbg(ON, "oz_hcd_get_frame_number\n"); return oz_usb_get_frame_number(); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq * This is called as a consquence of us calling usb_hcd_poll_rh_status() and we * always do that in softirq context. @@ -1860,98 +1971,103 @@ static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf) struct oz_hcd *ozhcd = oz_hcd_private(hcd); int i; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_status_data()\n"); buf[0] = 0; + buf[1] = 0; spin_lock_bh(&ozhcd->hcd_lock); for (i = 0; i < OZ_NB_PORTS; i++) { if (ozhcd->ports[i].flags & OZ_PORT_F_CHANGED) { - oz_trace2(OZ_TRACE_HUB, "Port %d changed\n", i); + oz_dbg(HUB, "Port %d changed\n", i); ozhcd->ports[i].flags &= ~OZ_PORT_F_CHANGED; - buf[0] |= 1<<(i+1); + if (i < 7) + buf[0] |= 1 << (i + 1); + else + buf[1] |= 1 << (i - 7); } } spin_unlock_bh(&ozhcd->hcd_lock); - return buf[0] ? 1 : 0; + if (buf[0] != 0 || buf[1] != 0) + return 2; + else + return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static void oz_get_hub_descriptor(struct usb_hcd *hcd, struct usb_hub_descriptor *desc) { - oz_trace2(OZ_TRACE_HUB, "GetHubDescriptor\n"); memset(desc, 0, sizeof(*desc)); desc->bDescriptorType = 0x29; desc->bDescLength = 9; - desc->wHubCharacteristics = (__force __u16) - __constant_cpu_to_le16(0x0001); + desc->wHubCharacteristics = (__force __u16)cpu_to_le16(0x0001); desc->bNbrPorts = OZ_NB_PORTS; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) { struct oz_port *port; - int err = 0; u8 port_id = (u8)windex; struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned set_bits = 0; unsigned clear_bits = 0; - oz_trace2(OZ_TRACE_HUB, "SetPortFeature\n"); + if ((port_id < 1) || (port_id > OZ_NB_PORTS)) return -EPIPE; port = &ozhcd->ports[port_id-1]; switch (wvalue) { case USB_PORT_FEAT_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); break; case USB_PORT_FEAT_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); break; case USB_PORT_FEAT_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); break; case USB_PORT_FEAT_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); break; case USB_PORT_FEAT_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); set_bits = USB_PORT_STAT_ENABLE | (USB_PORT_STAT_C_RESET<<16); clear_bits = USB_PORT_STAT_RESET; ozhcd->ports[port_id-1].bus_addr = 0; break; case USB_PORT_FEAT_POWER: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n"); + oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); set_bits |= USB_PORT_STAT_POWER; break; case USB_PORT_FEAT_LOWSPEED: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n"); + oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); break; case USB_PORT_FEAT_C_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); break; case USB_PORT_FEAT_C_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); break; case USB_PORT_FEAT_C_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); break; case USB_PORT_FEAT_C_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); break; case USB_PORT_FEAT_C_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); break; case USB_PORT_FEAT_TEST: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n"); + oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); break; case USB_PORT_FEAT_INDICATOR: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n"); + oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); break; default: - oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue); + oz_dbg(HUB, "Other %d\n", wvalue); break; } if (set_bits || clear_bits) { @@ -1960,74 +2076,73 @@ static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) port->status |= set_bits; spin_unlock_bh(&port->port_lock); } - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id, - port->status); - return err; + oz_dbg(HUB, "Port[%d] status = 0x%x\n", port_id, port->status); + return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) { struct oz_port *port; - int err = 0; u8 port_id = (u8)windex; struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned clear_bits = 0; - oz_trace2(OZ_TRACE_HUB, "ClearPortFeature\n"); + if ((port_id < 1) || (port_id > OZ_NB_PORTS)) return -EPIPE; port = &ozhcd->ports[port_id-1]; switch (wvalue) { case USB_PORT_FEAT_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); break; case USB_PORT_FEAT_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); clear_bits = USB_PORT_STAT_ENABLE; break; case USB_PORT_FEAT_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); break; case USB_PORT_FEAT_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); break; case USB_PORT_FEAT_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); break; case USB_PORT_FEAT_POWER: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n"); + oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); clear_bits |= USB_PORT_STAT_POWER; break; case USB_PORT_FEAT_LOWSPEED: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n"); + oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); break; case USB_PORT_FEAT_C_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); clear_bits = (USB_PORT_STAT_C_CONNECTION << 16); break; case USB_PORT_FEAT_C_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); clear_bits = (USB_PORT_STAT_C_ENABLE << 16); break; case USB_PORT_FEAT_C_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); break; case USB_PORT_FEAT_C_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); break; case USB_PORT_FEAT_C_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); clear_bits = (USB_PORT_FEAT_C_RESET << 16); break; case USB_PORT_FEAT_TEST: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n"); + oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); break; case USB_PORT_FEAT_INDICATOR: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n"); + oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); break; default: - oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue); + oz_dbg(HUB, "Other %d\n", wvalue); break; } if (clear_bits) { @@ -2035,37 +2150,40 @@ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) port->status &= ~clear_bits; spin_unlock_bh(&port->port_lock); } - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id, - ozhcd->ports[port_id-1].status); - return err; + oz_dbg(HUB, "Port[%d] status = 0x%x\n", + port_id, ozhcd->ports[port_id-1].status); + return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_get_port_status(struct usb_hcd *hcd, u16 windex, char *buf) { struct oz_hcd *ozhcd; - u32 status = 0; + u32 status; + if ((windex < 1) || (windex > OZ_NB_PORTS)) return -EPIPE; ozhcd = oz_hcd_private(hcd); - oz_trace2(OZ_TRACE_HUB, "GetPortStatus windex = %d\n", windex); + oz_dbg(HUB, "GetPortStatus windex = %d\n", windex); status = ozhcd->ports[windex-1].status; put_unaligned(cpu_to_le32(status), (__le32 *)buf); - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = %x\n", windex, status); + oz_dbg(HUB, "Port[%d] status = %x\n", windex, status); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, u16 windex, char *buf, u16 wlength) { int err = 0; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_control()\n"); + switch (req_type) { case ClearHubFeature: - oz_trace2(OZ_TRACE_HUB, "ClearHubFeature: %d\n", req_type); + oz_dbg(HUB, "ClearHubFeature: %d\n", req_type); break; case ClearPortFeature: err = oz_clear_port_feature(hcd, wvalue, windex); @@ -2074,32 +2192,32 @@ static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, oz_get_hub_descriptor(hcd, (struct usb_hub_descriptor *)buf); break; case GetHubStatus: - oz_trace2(OZ_TRACE_HUB, "GetHubStatus: req_type = 0x%x\n", - req_type); - put_unaligned(__constant_cpu_to_le32(0), (__le32 *)buf); + oz_dbg(HUB, "GetHubStatus: req_type = 0x%x\n", req_type); + put_unaligned(cpu_to_le32(0), (__le32 *)buf); break; case GetPortStatus: err = oz_get_port_status(hcd, windex, buf); break; case SetHubFeature: - oz_trace2(OZ_TRACE_HUB, "SetHubFeature: %d\n", req_type); + oz_dbg(HUB, "SetHubFeature: %d\n", req_type); break; case SetPortFeature: err = oz_set_port_feature(hcd, wvalue, windex); break; default: - oz_trace2(OZ_TRACE_HUB, "Other: %d\n", req_type); + oz_dbg(HUB, "Other: %d\n", req_type); break; } return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_bus_suspend(struct usb_hcd *hcd) { struct oz_hcd *ozhcd; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_suspend()\n"); + ozhcd = oz_hcd_private(hcd); spin_lock_bh(&ozhcd->hcd_lock); hcd->state = HC_STATE_SUSPENDED; @@ -2107,13 +2225,14 @@ static int oz_hcd_bus_suspend(struct usb_hcd *hcd) spin_unlock_bh(&ozhcd->hcd_lock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_bus_resume(struct usb_hcd *hcd) { struct oz_hcd *ozhcd; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_resume()\n"); + ozhcd = oz_hcd_private(hcd); spin_lock_bh(&ozhcd->hcd_lock); ozhcd->flags &= ~OZ_HDC_F_SUSPENDED; @@ -2121,13 +2240,12 @@ static int oz_hcd_bus_resume(struct usb_hcd *hcd) spin_unlock_bh(&ozhcd->hcd_lock); return 0; } -/*------------------------------------------------------------------------------ - */ + static void oz_plat_shutdown(struct platform_device *dev) { - oz_trace("oz_plat_shutdown()\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_plat_probe(struct platform_device *dev) @@ -2136,10 +2254,10 @@ static int oz_plat_probe(struct platform_device *dev) int err; struct usb_hcd *hcd; struct oz_hcd *ozhcd; - oz_trace("oz_plat_probe()\n"); + hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev)); - if (hcd == 0) { - oz_trace("Failed to created hcd object OK\n"); + if (hcd == NULL) { + oz_dbg(ON, "Failed to created hcd object OK\n"); return -ENOMEM; } ozhcd = oz_hcd_private(hcd); @@ -2152,6 +2270,7 @@ static int oz_plat_probe(struct platform_device *dev) spin_lock_init(&ozhcd->hcd_lock); for (i = 0; i < OZ_NB_PORTS; i++) { struct oz_port *port = &ozhcd->ports[i]; + port->ozhcd = ozhcd; port->flags = 0; port->status = 0; @@ -2160,78 +2279,84 @@ static int oz_plat_probe(struct platform_device *dev) } err = usb_add_hcd(hcd, 0, 0); if (err) { - oz_trace("Failed to add hcd object OK\n"); + oz_dbg(ON, "Failed to add hcd object OK\n"); usb_put_hcd(hcd); return -1; } + device_wakeup_enable(hcd->self.controller); + spin_lock_bh(&g_hcdlock); g_ozhcd = ozhcd; spin_unlock_bh(&g_hcdlock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_plat_remove(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct oz_hcd *ozhcd; - oz_trace("oz_plat_remove()\n"); - if (hcd == 0) + + if (hcd == NULL) return -1; ozhcd = oz_hcd_private(hcd); spin_lock_bh(&g_hcdlock); if (ozhcd == g_ozhcd) - g_ozhcd = 0; + g_ozhcd = NULL; spin_unlock_bh(&g_hcdlock); - oz_trace("Clearing orphanage\n"); + oz_dbg(ON, "Clearing orphanage\n"); oz_hcd_clear_orphanage(ozhcd, -EPIPE); - oz_trace("Removing hcd\n"); + oz_dbg(ON, "Removing hcd\n"); usb_remove_hcd(hcd); usb_put_hcd(hcd); oz_empty_link_pool(); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg) { - oz_trace("oz_plat_suspend()\n"); return 0; } -/*------------------------------------------------------------------------------ + + +/* * Context: unknown */ static int oz_plat_resume(struct platform_device *dev) { - oz_trace("oz_plat_resume()\n"); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_hcd_init(void) { int err; + if (usb_disabled()) return -ENODEV; tasklet_init(&g_urb_process_tasklet, oz_urb_process_tasklet, 0); tasklet_init(&g_urb_cancel_tasklet, oz_urb_cancel_tasklet, 0); err = platform_driver_register(&g_oz_plat_drv); - oz_trace("platform_driver_register() returned %d\n", err); + oz_dbg(ON, "platform_driver_register() returned %d\n", err); if (err) goto error; g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1); - if (g_plat_dev == 0) { + if (g_plat_dev == NULL) { err = -ENOMEM; goto error1; } - oz_trace("platform_device_alloc() succeeded\n"); + oz_dbg(ON, "platform_device_alloc() succeeded\n"); err = platform_device_add(g_plat_dev); if (err) goto error2; - oz_trace("platform_device_add() succeeded\n"); + oz_dbg(ON, "platform_device_add() succeeded\n"); return 0; error2: platform_device_put(g_plat_dev); @@ -2240,17 +2365,19 @@ error1: error: tasklet_disable(&g_urb_process_tasklet); tasklet_disable(&g_urb_cancel_tasklet); - oz_trace("oz_hcd_init() failed %d\n", err); + oz_dbg(ON, "oz_hcd_init() failed %d\n", err); return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_hcd_term(void) { - tasklet_disable(&g_urb_process_tasklet); - tasklet_disable(&g_urb_cancel_tasklet); + msleep(OZ_HUB_DEBOUNCE_TIMEOUT); + tasklet_kill(&g_urb_process_tasklet); + tasklet_kill(&g_urb_cancel_tasklet); platform_device_unregister(g_plat_dev); platform_driver_unregister(&g_oz_plat_drv); - oz_trace("Pending urbs:%d\n", atomic_read(&g_pending_urbs)); + oz_dbg(ON, "Pending urbs:%d\n", atomic_read(&g_pending_urbs)); } diff --git a/drivers/staging/ozwpan/ozhcd.h b/drivers/staging/ozwpan/ozhcd.h index 9b30dfd0997..55e97b1c707 100644 --- a/drivers/staging/ozwpan/ozhcd.h +++ b/drivers/staging/ozwpan/ozhcd.h @@ -7,8 +7,8 @@ int oz_hcd_init(void); void oz_hcd_term(void); -void *oz_hcd_pd_arrived(void *ctx); -void oz_hcd_pd_departed(void *ctx); +struct oz_port *oz_hcd_pd_arrived(void *ctx); +void oz_hcd_pd_departed(struct oz_port *hport); void oz_hcd_pd_reset(void *hpd, void *hport); #endif /* _OZHCD_H */ diff --git a/drivers/staging/ozwpan/ozmain.c b/drivers/staging/ozwpan/ozmain.c index 7579645d642..d1a5b7a2c16 100644 --- a/drivers/staging/ozwpan/ozmain.c +++ b/drivers/staging/ozwpan/ozmain.c @@ -3,6 +3,7 @@ * Released under the GNU General Public License Version 2 (GPLv2). * ----------------------------------------------------------------------------- */ + #include <linux/init.h> #include <linux/module.h> #include <linux/timer.h> @@ -10,35 +11,34 @@ #include <linux/netdevice.h> #include <linux/errno.h> #include <linux/ieee80211.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozpd.h" #include "ozproto.h" #include "ozcdev.h" -#include "oztrace.h" -#include "ozevent.h" -/*------------------------------------------------------------------------------ + +unsigned int oz_dbg_mask = OZ_DEFAULT_DBG_MASK; + +/* * The name of the 802.11 mac device. Empty string is the default value but a * value can be supplied as a parameter to the module. An empty string means * bind to nothing. '*' means bind to all netcards - this includes non-802.11 * netcards. Bindings can be added later using an IOCTL. */ -char *g_net_dev = ""; -/*------------------------------------------------------------------------------ +static char *g_net_dev = ""; + +/* * Context: process */ static int __init ozwpan_init(void) { - oz_event_init(); oz_cdev_register(); oz_protocol_init(g_net_dev); oz_app_enable(OZ_APPID_USB, 1); oz_apps_init(); -#ifdef CONFIG_DEBUG_FS - oz_debugfs_init(); -#endif return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static void __exit ozwpan_exit(void) @@ -46,19 +46,14 @@ static void __exit ozwpan_exit(void) oz_protocol_term(); oz_apps_term(); oz_cdev_deregister(); - oz_event_term(); -#ifdef CONFIG_DEBUG_FS - oz_debugfs_remove(); -#endif } -/*------------------------------------------------------------------------------ - */ + module_param(g_net_dev, charp, S_IRUGO); module_init(ozwpan_init); module_exit(ozwpan_exit); MODULE_AUTHOR("Chris Kelly"); MODULE_DESCRIPTION("Ozmo Devices USB over WiFi hcd driver"); -MODULE_VERSION("1.0.9"); +MODULE_VERSION("1.0.13"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c index 04cd57f2a6d..10f1b3ac883 100644 --- a/drivers/staging/ozwpan/ozpd.c +++ b/drivers/staging/ozwpan/ozpd.c @@ -3,52 +3,49 @@ * Released under the GNU General Public License Version 2 (GPLv2). * ----------------------------------------------------------------------------- */ -#include <linux/init.h> + #include <linux/module.h> #include <linux/timer.h> #include <linux/sched.h> #include <linux/netdevice.h> +#include <linux/etherdevice.h> #include <linux/errno.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" #include "ozeltbuf.h" #include "ozpd.h" #include "ozproto.h" -#include "oztrace.h" -#include "ozevent.h" #include "ozcdev.h" #include "ozusbsvc.h" #include <asm/unaligned.h> #include <linux/uaccess.h> #include <net/psnap.h> -/*------------------------------------------------------------------------------ - */ + #define OZ_MAX_TX_POOL_SIZE 6 -/* Maximum number of uncompleted isoc frames that can be pending. - */ -#define OZ_MAX_SUBMITTED_ISOC 16 -/*------------------------------------------------------------------------------ - */ + static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd); static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f); +static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f); static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f); static int oz_send_isoc_frame(struct oz_pd *pd); static void oz_retire_frame(struct oz_pd *pd, struct oz_tx_frame *f); static void oz_isoc_stream_free(struct oz_isoc_stream *st); -static int oz_send_next_queued_frame(struct oz_pd *pd, int *more_data); +static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data); static void oz_isoc_destructor(struct sk_buff *skb); static int oz_def_app_init(void); static void oz_def_app_term(void); static int oz_def_app_start(struct oz_pd *pd, int resume); static void oz_def_app_stop(struct oz_pd *pd, int pause); static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt); -/*------------------------------------------------------------------------------ + +/* * Counts the uncompleted isoc frames submitted to netcard. */ static atomic_t g_submitted_isoc = ATOMIC_INIT(0); + /* Application handler functions. */ -static struct oz_app_if g_app_if[OZ_APPID_MAX] = { +static const struct oz_app_if g_app_if[OZ_APPID_MAX] = { {oz_usb_init, oz_usb_term, oz_usb_start, @@ -63,8 +60,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_def_app_start, oz_def_app_stop, oz_def_app_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_UNUSED1}, {oz_def_app_init, @@ -72,8 +69,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_def_app_start, oz_def_app_stop, oz_def_app_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_UNUSED2}, {oz_cdev_init, @@ -81,74 +78,79 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = { oz_cdev_start, oz_cdev_stop, oz_cdev_rx, - 0, - 0, + NULL, + NULL, OZ_APPID_SERIAL}, }; -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_def_app_init(void) { return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static void oz_def_app_term(void) { } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_def_app_start(struct oz_pd *pd, int resume) { return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_def_app_stop(struct oz_pd *pd, int pause) { } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt) { } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_set_state(struct oz_pd *pd, unsigned state) { pd->state = state; - oz_event_log(OZ_EVT_PD_STATE, 0, 0, 0, state); -#ifdef WANT_TRACE switch (state) { case OZ_PD_S_IDLE: - oz_trace("PD State: OZ_PD_S_IDLE\n"); + oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_IDLE\n"); break; case OZ_PD_S_CONNECTED: - oz_trace("PD State: OZ_PD_S_CONNECTED\n"); + oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_CONNECTED\n"); break; case OZ_PD_S_STOPPED: - oz_trace("PD State: OZ_PD_S_STOPPED\n"); + oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_STOPPED\n"); break; case OZ_PD_S_SLEEP: - oz_trace("PD State: OZ_PD_S_SLEEP\n"); + oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_SLEEP\n"); break; } -#endif /* WANT_TRACE */ } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_get(struct oz_pd *pd) { atomic_inc(&pd->ref_count); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_put(struct oz_pd *pd) @@ -156,12 +158,14 @@ void oz_pd_put(struct oz_pd *pd) if (atomic_dec_and_test(&pd->ref_count)) oz_pd_destroy(pd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -struct oz_pd *oz_pd_alloc(u8 *mac_addr) +struct oz_pd *oz_pd_alloc(const u8 *mac_addr) { struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC); + if (pd) { int i; atomic_set(&pd->ref_count, 2); @@ -170,10 +174,10 @@ struct oz_pd *oz_pd_alloc(u8 *mac_addr) pd->last_rx_pkt_num = 0xffffffff; oz_pd_set_state(pd, OZ_PD_S_IDLE); pd->max_tx_size = OZ_MAX_TX_SIZE; - memcpy(pd->mac_addr, mac_addr, ETH_ALEN); + ether_addr_copy(pd->mac_addr, mac_addr); if (0 != oz_elt_buf_init(&pd->elt_buff)) { kfree(pd); - pd = 0; + pd = NULL; } spin_lock_init(&pd->tx_frame_lock); INIT_LIST_HEAD(&pd->tx_queue); @@ -181,19 +185,34 @@ struct oz_pd *oz_pd_alloc(u8 *mac_addr) pd->last_sent_frame = &pd->tx_queue; spin_lock_init(&pd->stream_lock); INIT_LIST_HEAD(&pd->stream_list); + tasklet_init(&pd->heartbeat_tasklet, oz_pd_heartbeat_handler, + (unsigned long)pd); + tasklet_init(&pd->timeout_tasklet, oz_pd_timeout_handler, + (unsigned long)pd); + hrtimer_init(&pd->heartbeat, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + hrtimer_init(&pd->timeout, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + pd->heartbeat.function = oz_pd_heartbeat_event; + pd->timeout.function = oz_pd_timeout_event; } return pd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ -void oz_pd_destroy(struct oz_pd *pd) +static void oz_pd_free(struct work_struct *work) { struct list_head *e; struct oz_tx_frame *f; struct oz_isoc_stream *st; struct oz_farewell *fwell; - oz_trace("Destroying PD\n"); + struct oz_pd *pd; + + oz_pd_dbg(pd, ON, "Destroying PD\n"); + pd = container_of(work, struct oz_pd, workitem); + /*Disable timer tasklets*/ + tasklet_kill(&pd->heartbeat_tasklet); + tasklet_kill(&pd->timeout_tasklet); /* Delete any streams. */ e = pd->stream_list.next; @@ -208,6 +227,8 @@ void oz_pd_destroy(struct oz_pd *pd) while (e != &pd->tx_queue) { f = container_of(e, struct oz_tx_frame, link); e = e->next; + if (f->skb != NULL) + kfree_skb(f->skb); oz_retire_frame(pd, f); } oz_elt_buf_term(&pd->elt_buff); @@ -230,132 +251,156 @@ void oz_pd_destroy(struct oz_pd *pd) dev_put(pd->net_dev); kfree(pd); } -/*------------------------------------------------------------------------------ + +/* + * Context: softirq or Process + */ +void oz_pd_destroy(struct oz_pd *pd) +{ + if (hrtimer_active(&pd->timeout)) + hrtimer_cancel(&pd->timeout); + if (hrtimer_active(&pd->heartbeat)) + hrtimer_cancel(&pd->heartbeat); + + INIT_WORK(&pd->workitem, oz_pd_free); + if (!schedule_work(&pd->workitem)) + oz_pd_dbg(pd, ON, "failed to schedule workitem\n"); +} + +/* * Context: softirq-serialized */ int oz_services_start(struct oz_pd *pd, u16 apps, int resume) { - struct oz_app_if *ai; + const struct oz_app_if *ai; int rc = 0; - oz_trace("oz_services_start(0x%x) resume(%d)\n", apps, resume); + + oz_pd_dbg(pd, ON, "%s: (0x%x) resume(%d)\n", __func__, apps, resume); for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { if (apps & (1<<ai->app_id)) { if (ai->start(pd, resume)) { rc = -1; - oz_trace("Unabled to start service %d\n", - ai->app_id); + oz_pd_dbg(pd, ON, + "Unable to start service %d\n", + ai->app_id); break; } - oz_polling_lock_bh(); + spin_lock_bh(&g_polling_lock); pd->total_apps |= (1<<ai->app_id); if (resume) pd->paused_apps &= ~(1<<ai->app_id); - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); } } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_services_stop(struct oz_pd *pd, u16 apps, int pause) { - struct oz_app_if *ai; - oz_trace("oz_stop_services(0x%x) pause(%d)\n", apps, pause); + const struct oz_app_if *ai; + + oz_pd_dbg(pd, ON, "%s: (0x%x) pause(%d)\n", __func__, apps, pause); for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { if (apps & (1<<ai->app_id)) { - oz_polling_lock_bh(); + spin_lock_bh(&g_polling_lock); if (pause) { pd->paused_apps |= (1<<ai->app_id); } else { pd->total_apps &= ~(1<<ai->app_id); pd->paused_apps &= ~(1<<ai->app_id); } - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); ai->stop(pd, pause); } } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ void oz_pd_heartbeat(struct oz_pd *pd, u16 apps) { - struct oz_app_if *ai; + const struct oz_app_if *ai; int more = 0; + for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { if (ai->heartbeat && (apps & (1<<ai->app_id))) { if (ai->heartbeat(pd)) more = 1; } } - if (more) - oz_pd_request_heartbeat(pd); + if ((!more) && (hrtimer_active(&pd->heartbeat))) + hrtimer_cancel(&pd->heartbeat); if (pd->mode & OZ_F_ISOC_ANYTIME) { int count = 8; while (count-- && (oz_send_isoc_frame(pd) >= 0)) ; } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_stop(struct oz_pd *pd) { - u16 stop_apps = 0; - oz_trace("oz_pd_stop() State = 0x%x\n", pd->state); + u16 stop_apps; + + oz_dbg(ON, "oz_pd_stop() State = 0x%x\n", pd->state); oz_pd_indicate_farewells(pd); - oz_polling_lock_bh(); + spin_lock_bh(&g_polling_lock); stop_apps = pd->total_apps; pd->total_apps = 0; pd->paused_apps = 0; - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); oz_services_stop(pd, stop_apps, 0); - oz_polling_lock_bh(); + spin_lock_bh(&g_polling_lock); oz_pd_set_state(pd, OZ_PD_S_STOPPED); /* Remove from PD list.*/ list_del(&pd->link); - oz_polling_unlock_bh(); - oz_trace("pd ref count = %d\n", atomic_read(&pd->ref_count)); - oz_timer_delete(pd, 0); + spin_unlock_bh(&g_polling_lock); + oz_dbg(ON, "pd ref count = %d\n", atomic_read(&pd->ref_count)); oz_pd_put(pd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_pd_sleep(struct oz_pd *pd) { int do_stop = 0; - u16 stop_apps = 0; - oz_polling_lock_bh(); + u16 stop_apps; + + spin_lock_bh(&g_polling_lock); if (pd->state & (OZ_PD_S_SLEEP | OZ_PD_S_STOPPED)) { - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); return 0; } - if (pd->keep_alive_j && pd->session_id) { + if (pd->keep_alive && pd->session_id) oz_pd_set_state(pd, OZ_PD_S_SLEEP); - pd->pulse_time_j = jiffies + pd->keep_alive_j; - oz_trace("Sleep Now %lu until %lu\n", - jiffies, pd->pulse_time_j); - } else { + else do_stop = 1; - } + stop_apps = pd->total_apps; - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); if (do_stop) { oz_pd_stop(pd); } else { oz_services_stop(pd, stop_apps, 1); - oz_timer_add(pd, OZ_TIMER_STOP, jiffies + pd->keep_alive_j, 1); + oz_timer_add(pd, OZ_TIMER_STOP, pd->keep_alive); } return do_stop; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) { - struct oz_tx_frame *f = 0; + struct oz_tx_frame *f = NULL; + spin_lock_bh(&pd->tx_frame_lock); if (pd->tx_pool) { f = container_of(pd->tx_pool, struct oz_tx_frame, link); @@ -363,7 +408,7 @@ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) pd->tx_pool_count--; } spin_unlock_bh(&pd->tx_frame_lock); - if (f == 0) + if (f == NULL) f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC); if (f) { f->total_size = sizeof(struct oz_hdr); @@ -372,7 +417,26 @@ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) } return f; } -/*------------------------------------------------------------------------------ + +/* + * Context: softirq or process + */ +static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f) +{ + pd->nb_queued_isoc_frames--; + list_del_init(&f->link); + if (pd->tx_pool_count < OZ_MAX_TX_POOL_SIZE) { + f->link.next = pd->tx_pool; + pd->tx_pool = &f->link; + pd->tx_pool_count++; + } else { + kfree(f); + } + oz_dbg(TX_FRAMES, "Releasing ISOC Frame isoc_nb= %d\n", + pd->nb_queued_isoc_frames); +} + +/* * Context: softirq or process */ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f) @@ -382,18 +446,39 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f) f->link.next = pd->tx_pool; pd->tx_pool = &f->link; pd->tx_pool_count++; - f = 0; + f = NULL; } spin_unlock_bh(&pd->tx_frame_lock); - if (f) - kfree(f); + kfree(f); } -/*------------------------------------------------------------------------------ + +/* + * Context: softirq-serialized + */ +static void oz_set_more_bit(struct sk_buff *skb) +{ + struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); + + oz_hdr->control |= OZ_F_MORE_DATA; +} + +/* + * Context: softirq-serialized + */ +static void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb) +{ + struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); + + oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK; +} + +/* * Context: softirq */ int oz_prepare_frame(struct oz_pd *pd, int empty) { struct oz_tx_frame *f; + if ((pd->mode & OZ_MODE_MASK) != OZ_MODE_TRIGGERED) return -1; if (pd->nb_queued_frames >= OZ_MAX_QUEUED_FRAMES) @@ -401,8 +486,9 @@ int oz_prepare_frame(struct oz_pd *pd, int empty) if (!empty && !oz_are_elts_available(&pd->elt_buff)) return -1; f = oz_tx_frame_alloc(pd); - if (f == 0) + if (f == NULL) return -1; + f->skb = NULL; f->hdr.control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT) | OZ_F_ACK_REQUESTED; ++pd->last_tx_pkt_num; @@ -417,22 +503,24 @@ int oz_prepare_frame(struct oz_pd *pd, int empty) spin_unlock(&pd->tx_frame_lock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) { - struct sk_buff *skb = 0; + struct sk_buff *skb; struct net_device *dev = pd->net_dev; struct oz_hdr *oz_hdr; struct oz_elt *elt; struct list_head *e; + /* Allocate skb with enough space for the lower layers as well * as the space we need. */ skb = alloc_skb(f->total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) - return 0; + if (skb == NULL) + return NULL; /* Reserve the head room for lower layers. */ skb_reserve(skb, LL_RESERVED_SPACE(dev)); @@ -459,15 +547,17 @@ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) return skb; fail: kfree_skb(skb); - return 0; + return NULL; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ static void oz_retire_frame(struct oz_pd *pd, struct oz_tx_frame *f) { struct list_head *e; struct oz_elt_info *ei; + e = f->elt_list.next; while (e != &f->elt_list) { ei = container_of(e, struct oz_elt_info, link); @@ -483,71 +573,114 @@ static void oz_retire_frame(struct oz_pd *pd, struct oz_tx_frame *f) if (pd->elt_buff.free_elts > pd->elt_buff.max_free_elts) oz_trim_elt_pool(&pd->elt_buff); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -static int oz_send_next_queued_frame(struct oz_pd *pd, int *more_data) +static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data) { struct sk_buff *skb; struct oz_tx_frame *f; struct list_head *e; - *more_data = 0; + spin_lock(&pd->tx_frame_lock); e = pd->last_sent_frame->next; if (e == &pd->tx_queue) { spin_unlock(&pd->tx_frame_lock); return -1; } - pd->last_sent_frame = e; - if (e->next != &pd->tx_queue) - *more_data = 1; f = container_of(e, struct oz_tx_frame, link); - skb = oz_build_frame(pd, f); - spin_unlock(&pd->tx_frame_lock); - oz_trace2(OZ_TRACE_TX_FRAMES, "TX frame PN=0x%x\n", f->hdr.pkt_num); - if (skb) { - oz_event_log(OZ_EVT_TX_FRAME, - 0, - (((u16)f->hdr.control)<<8)|f->hdr.last_pkt_num, - 0, f->hdr.pkt_num); - if (dev_queue_xmit(skb) < 0) + + if (f->skb != NULL) { + skb = f->skb; + oz_tx_isoc_free(pd, f); + spin_unlock(&pd->tx_frame_lock); + if (more_data) + oz_set_more_bit(skb); + oz_set_last_pkt_nb(pd, skb); + if ((int)atomic_read(&g_submitted_isoc) < + OZ_MAX_SUBMITTED_ISOC) { + if (dev_queue_xmit(skb) < 0) { + oz_dbg(TX_FRAMES, "Dropping ISOC Frame\n"); + return -1; + } + atomic_inc(&g_submitted_isoc); + oz_dbg(TX_FRAMES, "Sending ISOC Frame, nb_isoc= %d\n", + pd->nb_queued_isoc_frames); + return 0; + } else { + kfree_skb(skb); + oz_dbg(TX_FRAMES, "Dropping ISOC Frame>\n"); return -1; + } } + + pd->last_sent_frame = e; + skb = oz_build_frame(pd, f); + spin_unlock(&pd->tx_frame_lock); + if (!skb) + return -1; + if (more_data) + oz_set_more_bit(skb); + oz_dbg(TX_FRAMES, "TX frame PN=0x%x\n", f->hdr.pkt_num); + if (dev_queue_xmit(skb) < 0) + return -1; + return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ void oz_send_queued_frames(struct oz_pd *pd, int backlog) { - int more; - if (backlog < OZ_MAX_QUEUED_FRAMES) { - if (oz_send_next_queued_frame(pd, &more) >= 0) { - while (more && oz_send_next_queued_frame(pd, &more)) - ; - } else { - if (((pd->mode & OZ_F_ISOC_ANYTIME) == 0) - || (pd->isoc_sent == 0)) { - if (oz_prepare_frame(pd, 1) >= 0) - oz_send_next_queued_frame(pd, &more); - } + while (oz_prepare_frame(pd, 0) >= 0) + backlog++; + + switch (pd->mode & (OZ_F_ISOC_NO_ELTS | OZ_F_ISOC_ANYTIME)) { + + case OZ_F_ISOC_NO_ELTS: { + backlog += pd->nb_queued_isoc_frames; + if (backlog <= 0) + goto out; + if (backlog > OZ_MAX_SUBMITTED_ISOC) + backlog = OZ_MAX_SUBMITTED_ISOC; + break; + } + case OZ_NO_ELTS_ANYTIME: { + if ((backlog <= 0) && (pd->isoc_sent == 0)) + goto out; + break; + } + default: { + if (backlog <= 0) + goto out; + break; } - } else { - oz_send_next_queued_frame(pd, &more); } + while (backlog--) { + if (oz_send_next_queued_frame(pd, backlog) < 0) + break; + } + return; + +out: oz_prepare_frame(pd, 1); + oz_send_next_queued_frame(pd, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_send_isoc_frame(struct oz_pd *pd) { - struct sk_buff *skb = 0; + struct sk_buff *skb; struct net_device *dev = pd->net_dev; struct oz_hdr *oz_hdr; struct oz_elt *elt; struct list_head *e; struct list_head list; int total_size = sizeof(struct oz_hdr); + INIT_LIST_HEAD(&list); oz_select_elts_for_tx(&pd->elt_buff, 1, &total_size, @@ -555,8 +688,8 @@ static int oz_send_isoc_frame(struct oz_pd *pd) if (list.next == &list) return 0; skb = alloc_skb(total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) { - oz_trace("Cannot alloc skb\n"); + if (skb == NULL) { + oz_dbg(ON, "Cannot alloc skb\n"); oz_elt_info_free_chain(&pd->elt_buff, &list); return -1; } @@ -580,20 +713,20 @@ static int oz_send_isoc_frame(struct oz_pd *pd) memcpy(elt, ei->data, ei->length); elt = oz_next_elt(elt); } - oz_event_log(OZ_EVT_TX_ISOC, 0, 0, 0, 0); dev_queue_xmit(skb); oz_elt_info_free_chain(&pd->elt_buff, &list); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) { struct list_head *e; struct oz_tx_frame *f; - struct list_head *first = 0; - struct list_head *last = 0; + struct list_head *first = NULL; + struct list_head *last = NULL; u8 diff; u32 pkt_num; @@ -603,9 +736,11 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) f = container_of(e, struct oz_tx_frame, link); pkt_num = le32_to_cpu(get_unaligned(&f->hdr.pkt_num)); diff = (lpn - (pkt_num & OZ_LAST_PN_MASK)) & OZ_LAST_PN_MASK; - if (diff > OZ_LAST_PN_HALF_CYCLE) + if ((diff > OZ_LAST_PN_HALF_CYCLE) || (pkt_num == 0)) break; - if (first == 0) + oz_dbg(TX_FRAMES, "Releasing pkt_num= %u, nb= %d\n", + pkt_num, pd->nb_queued_frames); + if (first == NULL) first = e; last = e; e = e->next; @@ -614,7 +749,7 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) if (first) { last->next->prev = &pd->tx_queue; pd->tx_queue.next = last->next; - last->next = 0; + last->next = NULL; } pd->last_sent_frame = &pd->tx_queue; spin_unlock(&pd->tx_frame_lock); @@ -624,7 +759,8 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn) oz_retire_frame(pd, f); } } -/*------------------------------------------------------------------------------ + +/* * Precondition: stream_lock must be held. * Context: softirq */ @@ -632,14 +768,16 @@ static struct oz_isoc_stream *pd_stream_find(struct oz_pd *pd, u8 ep_num) { struct list_head *e; struct oz_isoc_stream *st; + list_for_each(e, &pd->stream_list) { st = container_of(e, struct oz_isoc_stream, link); if (st->ep_num == ep_num) return st; } - return 0; + return NULL; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num) @@ -652,28 +790,29 @@ int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num) spin_lock_bh(&pd->stream_lock); if (!pd_stream_find(pd, ep_num)) { list_add(&st->link, &pd->stream_list); - st = 0; + st = NULL; } spin_unlock_bh(&pd->stream_lock); - if (st) - kfree(st); + kfree(st); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ static void oz_isoc_stream_free(struct oz_isoc_stream *st) { - if (st->skb) - kfree_skb(st->skb); + kfree_skb(st->skb); kfree(st); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num) { struct oz_isoc_stream *st; + spin_lock_bh(&pd->stream_lock); st = pd_stream_find(pd, ep_num); if (st) @@ -683,31 +822,32 @@ int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num) oz_isoc_stream_free(st); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: any */ static void oz_isoc_destructor(struct sk_buff *skb) { atomic_dec(&g_submitted_isoc); - oz_event_log(OZ_EVT_TX_ISOC_DONE, atomic_read(&g_submitted_isoc), - 0, skb, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) +int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len) { struct net_device *dev = pd->net_dev; struct oz_isoc_stream *st; u8 nb_units = 0; - struct sk_buff *skb = 0; - struct oz_hdr *oz_hdr = 0; + struct sk_buff *skb = NULL; + struct oz_hdr *oz_hdr = NULL; int size = 0; + spin_lock_bh(&pd->stream_lock); st = pd_stream_find(pd, ep_num); if (st) { skb = st->skb; - st->skb = 0; + st->skb = NULL; nb_units = st->nb_units; st->nb_units = 0; oz_hdr = st->oz_hdr; @@ -720,13 +860,15 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) /* Allocate enough space for max size frame. */ skb = alloc_skb(pd->max_tx_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return 0; /* Reserve the head room for lower layers. */ skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reset_network_header(skb); skb->dev = dev; skb->protocol = htons(OZ_ETHERTYPE); + /* For audio packet set priority to AC_VO */ + skb->priority = 0x7; size = sizeof(struct oz_hdr) + sizeof(struct oz_isoc_large); oz_hdr = (struct oz_hdr *)skb_put(skb, size); } @@ -756,73 +898,117 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) memcpy(oz_hdr, &oz, sizeof(oz)); memcpy(oz_hdr+1, &iso, sizeof(iso)); if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr, - dev->dev_addr, skb->len) < 0) { - kfree_skb(skb); - return -1; + dev->dev_addr, skb->len) < 0) + goto out; + + skb->destructor = oz_isoc_destructor; + /*Queue for Xmit if mode is not ANYTIME*/ + if (!(pd->mode & OZ_F_ISOC_ANYTIME)) { + struct oz_tx_frame *isoc_unit = NULL; + int nb = pd->nb_queued_isoc_frames; + if (nb >= pd->isoc_latency) { + struct list_head *e; + struct oz_tx_frame *f; + oz_dbg(TX_FRAMES, "Dropping ISOC Unit nb= %d\n", + nb); + spin_lock(&pd->tx_frame_lock); + list_for_each(e, &pd->tx_queue) { + f = container_of(e, struct oz_tx_frame, + link); + if (f->skb != NULL) { + oz_tx_isoc_free(pd, f); + break; + } + } + spin_unlock(&pd->tx_frame_lock); + } + isoc_unit = oz_tx_frame_alloc(pd); + if (isoc_unit == NULL) + goto out; + isoc_unit->hdr = oz; + isoc_unit->skb = skb; + spin_lock_bh(&pd->tx_frame_lock); + list_add_tail(&isoc_unit->link, &pd->tx_queue); + pd->nb_queued_isoc_frames++; + spin_unlock_bh(&pd->tx_frame_lock); + oz_dbg(TX_FRAMES, + "Added ISOC Frame to Tx Queue isoc_nb= %d, nb= %d\n", + pd->nb_queued_isoc_frames, pd->nb_queued_frames); + return 0; } + + /*In ANYTIME mode Xmit unit immediately*/ if (atomic_read(&g_submitted_isoc) < OZ_MAX_SUBMITTED_ISOC) { - skb->destructor = oz_isoc_destructor; atomic_inc(&g_submitted_isoc); - oz_event_log(OZ_EVT_TX_ISOC, nb_units, iso.frame_number, - skb, atomic_read(&g_submitted_isoc)); if (dev_queue_xmit(skb) < 0) return -1; - } else { - oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); - kfree_skb(skb); + else + return 0; } + +out: kfree_skb(skb); + return -1; + } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_apps_init(void) { int i; + for (i = 0; i < OZ_APPID_MAX; i++) if (g_app_if[i].init) g_app_if[i].init(); } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_apps_term(void) { int i; + /* Terminate all the apps. */ for (i = 0; i < OZ_APPID_MAX; i++) if (g_app_if[i].term) g_app_if[i].term(); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt) { - struct oz_app_if *ai; + const struct oz_app_if *ai; + if (app_id == 0 || app_id > OZ_APPID_MAX) return; ai = &g_app_if[app_id-1]; ai->rx(pd, elt); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_indicate_farewells(struct oz_pd *pd) { struct oz_farewell *f; - struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1]; + const struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1]; + while (1) { - oz_polling_lock_bh(); + spin_lock_bh(&g_polling_lock); if (list_empty(&pd->farewell_list)) { - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); break; } f = list_first_entry(&pd->farewell_list, struct oz_farewell, link); list_del(&f->link); - oz_polling_unlock_bh(); + spin_unlock_bh(&g_polling_lock); if (ai->farewell) ai->farewell(pd, f->ep_num, f->report, f->len); kfree(f); diff --git a/drivers/staging/ozwpan/ozpd.h b/drivers/staging/ozwpan/ozpd.h index afc77f0260f..ad5fe7a6e61 100644 --- a/drivers/staging/ozwpan/ozpd.h +++ b/drivers/staging/ozwpan/ozpd.h @@ -6,6 +6,7 @@ #ifndef _OZPD_H_ #define _OZPD_H_ +#include <linux/interrupt.h> #include "ozeltbuf.h" /* PD state @@ -21,6 +22,11 @@ #define OZ_TIMER_HEARTBEAT 2 #define OZ_TIMER_STOP 3 +/* + *External spinlock variable + */ +extern spinlock_t g_polling_lock; + /* Data structure that hold information on a frame for transmisson. This is * built when the frame is first transmitted and is used to rebuild the frame * if a re-transmission is required. @@ -29,6 +35,7 @@ struct oz_tx_frame { struct list_head link; struct list_head elt_list; struct oz_hdr hdr; + struct sk_buff *skb; int total_size; }; @@ -46,8 +53,8 @@ struct oz_farewell { struct list_head link; u8 ep_num; u8 index; - u8 report[1]; u8 len; + u8 report[0]; }; /* Data structure that holds information on a specific peripheral device (PD). @@ -67,22 +74,22 @@ struct oz_pd { u8 isoc_sent; u32 last_rx_pkt_num; u32 last_tx_pkt_num; + struct timespec last_rx_timestamp; u32 trigger_pkt_num; - unsigned long pulse_time_j; - unsigned long timeout_time_j; - unsigned long pulse_period_j; - unsigned long presleep_j; - unsigned long keep_alive_j; - unsigned long last_rx_time_j; + unsigned long pulse_time; + unsigned long pulse_period; + unsigned long presleep; + unsigned long keep_alive; struct oz_elt_buf elt_buff; void *app_ctx[OZ_APPID_MAX]; spinlock_t app_lock[OZ_APPID_MAX]; int max_tx_size; - u8 heartbeat_requested; u8 mode; u8 ms_per_isoc; + unsigned isoc_latency; unsigned max_stream_buffering; int nb_queued_frames; + int nb_queued_isoc_frames; struct list_head *tx_pool; int tx_pool_count; spinlock_t tx_frame_lock; @@ -92,11 +99,17 @@ struct oz_pd { spinlock_t stream_lock; struct list_head stream_list; struct net_device *net_dev; + struct hrtimer heartbeat; + struct hrtimer timeout; + u8 timeout_type; + struct tasklet_struct heartbeat_tasklet; + struct tasklet_struct timeout_tasklet; + struct work_struct workitem; }; #define OZ_MAX_QUEUED_FRAMES 4 -struct oz_pd *oz_pd_alloc(u8 *mac_addr); +struct oz_pd *oz_pd_alloc(const u8 *mac_addr); void oz_pd_destroy(struct oz_pd *pd); void oz_pd_get(struct oz_pd *pd); void oz_pd_put(struct oz_pd *pd); @@ -112,10 +125,9 @@ void oz_send_queued_frames(struct oz_pd *pd, int backlog); void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn); int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num); int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num); -int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len); +int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len); void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt); void oz_apps_init(void); void oz_apps_term(void); #endif /* Sentry */ - diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c index ad857eeabbb..11020559919 100644 --- a/drivers/staging/ozwpan/ozproto.c +++ b/drivers/staging/ozwpan/ozproto.c @@ -3,76 +3,57 @@ * Released under the GNU General Public License Version 2 (GPLv2). * ----------------------------------------------------------------------------- */ -#include <linux/init.h> + #include <linux/module.h> #include <linux/timer.h> #include <linux/sched.h> #include <linux/netdevice.h> +#include <linux/etherdevice.h> #include <linux/errno.h> #include <linux/ieee80211.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" #include "ozeltbuf.h" #include "ozpd.h" #include "ozproto.h" #include "ozusbsvc.h" -#include "oztrace.h" + #include "ozappif.h" -#include "ozevent.h" #include <asm/unaligned.h> #include <linux/uaccess.h> #include <net/psnap.h> -/*------------------------------------------------------------------------------ - */ + #define OZ_CF_CONN_SUCCESS 1 #define OZ_CF_CONN_FAILURE 2 #define OZ_DO_STOP 1 #define OZ_DO_SLEEP 2 -/* States of the timer. - */ -#define OZ_TIMER_IDLE 0 -#define OZ_TIMER_SET 1 -#define OZ_TIMER_IN_HANDLER 2 - #define OZ_MAX_TIMER_POOL_SIZE 16 -/*------------------------------------------------------------------------------ - */ struct oz_binding { struct packet_type ptype; char name[OZ_MAX_BINDING_LEN]; - struct oz_binding *next; -}; - -struct oz_timer { struct list_head link; - struct oz_pd *pd; - unsigned long due_time; - int type; }; -/*------------------------------------------------------------------------------ + +/* + * External variable + */ + +DEFINE_SPINLOCK(g_polling_lock); +/* * Static external variables. */ -static DEFINE_SPINLOCK(g_polling_lock); static LIST_HEAD(g_pd_list); -static struct oz_binding *g_binding ; +static LIST_HEAD(g_binding); static DEFINE_SPINLOCK(g_binding_lock); static struct sk_buff_head g_rx_queue; static u8 g_session_id; static u16 g_apps = 0x1; static int g_processing_rx; -static struct timer_list g_timer; -static struct oz_timer *g_cur_timer; -static struct list_head *g_timer_pool; -static int g_timer_pool_count; -static int g_timer_state = OZ_TIMER_IDLE; -static LIST_HEAD(g_timer_list); -/*------------------------------------------------------------------------------ - */ -static void oz_protocol_timer_start(void); -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static u8 oz_get_new_session_id(u8 exclude) @@ -85,7 +66,8 @@ static u8 oz_get_new_session_id(u8 exclude) } return g_session_id; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) @@ -95,10 +77,11 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) struct oz_hdr *oz_hdr; struct oz_elt *elt; struct oz_elt_connect_rsp *body; + int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) + sizeof(struct oz_elt_connect_rsp); skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return; skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reset_network_header(skb); @@ -116,7 +99,6 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT); oz_hdr->last_pkt_num = 0; put_unaligned(0, &oz_hdr->pkt_num); - oz_event_log(OZ_EVT_CONNECT_RSP, 0, 0, 0, 0); elt->type = OZ_ELT_CONNECT_RSP; elt->length = sizeof(struct oz_elt_connect_rsp); memset(body, 0, sizeof(struct oz_elt_connect_rsp)); @@ -126,11 +108,12 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) body->session_id = pd->session_id; put_unaligned(cpu_to_le16(pd->total_apps), &body->apps); } - oz_trace("TX: OZ_ELT_CONNECT_RSP %d", status); + oz_dbg(ON, "TX: OZ_ELT_CONNECT_RSP %d", status); dev_queue_xmit(skb); return; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static void pd_set_keepalive(struct oz_pd *pd, u8 kalive) @@ -139,39 +122,45 @@ static void pd_set_keepalive(struct oz_pd *pd, u8 kalive) switch (kalive & OZ_KALIVE_TYPE_MASK) { case OZ_KALIVE_SPECIAL: - pd->keep_alive_j = - oz_ms_to_jiffies(keep_alive * 1000*60*60*24*20); + pd->keep_alive = keep_alive * 1000*60*60*24*20; break; case OZ_KALIVE_SECS: - pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000); + pd->keep_alive = keep_alive*1000; break; case OZ_KALIVE_MINS: - pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000*60); + pd->keep_alive = keep_alive*1000*60; break; case OZ_KALIVE_HOURS: - pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000*60*60); + pd->keep_alive = keep_alive*1000*60*60; break; default: - pd->keep_alive_j = 0; + pd->keep_alive = 0; } - oz_trace("Keepalive = %lu jiffies\n", pd->keep_alive_j); + oz_dbg(ON, "Keepalive = %lu mSec\n", pd->keep_alive); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -static void pd_set_presleep(struct oz_pd *pd, u8 presleep) +static void pd_set_presleep(struct oz_pd *pd, u8 presleep, u8 start_timer) { if (presleep) - pd->presleep_j = oz_ms_to_jiffies(presleep*100); + pd->presleep = presleep*100; else - pd->presleep_j = OZ_PRESLEEP_TOUT_J; - oz_trace("Presleep time = %lu jiffies\n", pd->presleep_j); + pd->presleep = OZ_PRESLEEP_TOUT; + if (start_timer) { + spin_unlock(&g_polling_lock); + oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep); + spin_lock(&g_polling_lock); + } + oz_dbg(ON, "Presleep time = %lu mSec\n", pd->presleep); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, - u8 *pd_addr, struct net_device *net_dev) + const u8 *pd_addr, struct net_device *net_dev) { struct oz_pd *pd; struct oz_elt_connect_req *body = @@ -179,22 +168,23 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, u8 rsp_status = OZ_STATUS_SUCCESS; u8 stop_needed = 0; u16 new_apps = g_apps; - struct net_device *old_net_dev = 0; - struct oz_pd *free_pd = 0; + struct net_device *old_net_dev = NULL; + struct oz_pd *free_pd = NULL; + if (cur_pd) { pd = cur_pd; spin_lock_bh(&g_polling_lock); } else { - struct oz_pd *pd2 = 0; + struct oz_pd *pd2 = NULL; struct list_head *e; pd = oz_pd_alloc(pd_addr); - if (pd == 0) - return 0; - pd->last_rx_time_j = jiffies; + if (pd == NULL) + return NULL; + getnstimeofday(&pd->last_rx_timestamp); spin_lock_bh(&g_polling_lock); list_for_each(e, &g_pd_list) { pd2 = container_of(e, struct oz_pd, link); - if (memcmp(pd2->mac_addr, pd_addr, ETH_ALEN) == 0) { + if (ether_addr_equal(pd2->mac_addr, pd_addr)) { free_pd = pd; pd = pd2; break; @@ -203,33 +193,44 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, if (pd != pd2) list_add_tail(&pd->link, &g_pd_list); } - if (pd == 0) { + if (pd == NULL) { spin_unlock_bh(&g_polling_lock); - return 0; + return NULL; } if (pd->net_dev != net_dev) { old_net_dev = pd->net_dev; dev_hold(net_dev); pd->net_dev = net_dev; } - oz_trace("Host vendor: %d\n", body->host_vendor); + oz_dbg(ON, "Host vendor: %d\n", body->host_vendor); pd->max_tx_size = OZ_MAX_TX_SIZE; pd->mode = body->mode; pd->pd_info = body->pd_info; if (pd->mode & OZ_F_ISOC_NO_ELTS) { - pd->mode |= OZ_F_ISOC_ANYTIME; pd->ms_per_isoc = body->ms_per_isoc; if (!pd->ms_per_isoc) pd->ms_per_isoc = 4; + + switch (body->ms_isoc_latency & OZ_LATENCY_MASK) { + case OZ_ONE_MS_LATENCY: + pd->isoc_latency = (body->ms_isoc_latency & + ~OZ_LATENCY_MASK) / pd->ms_per_isoc; + break; + case OZ_TEN_MS_LATENCY: + pd->isoc_latency = ((body->ms_isoc_latency & + ~OZ_LATENCY_MASK) * 10) / pd->ms_per_isoc; + break; + default: + pd->isoc_latency = OZ_MAX_TX_QUEUE_ISOC; + } } if (body->max_len_div16) pd->max_tx_size = ((u16)body->max_len_div16)<<4; - oz_trace("Max frame:%u Ms per isoc:%u\n", - pd->max_tx_size, pd->ms_per_isoc); + oz_dbg(ON, "Max frame:%u Ms per isoc:%u\n", + pd->max_tx_size, pd->ms_per_isoc); pd->max_stream_buffering = 3*1024; - pd->timeout_time_j = jiffies + OZ_CONNECTION_TOUT_J; - pd->pulse_period_j = OZ_QUANTUM_J; - pd_set_presleep(pd, body->presleep); + pd->pulse_period = OZ_QUANTUM; + pd_set_presleep(pd, body->presleep, 0); pd_set_keepalive(pd, body->keep_alive); new_apps &= le16_to_cpu(get_unaligned(&body->apps)); @@ -261,9 +262,8 @@ done: u16 resume_apps = new_apps & pd->paused_apps & ~0x1; spin_unlock_bh(&g_polling_lock); oz_pd_set_state(pd, OZ_PD_S_CONNECTED); - oz_timer_delete(pd, OZ_TIMER_STOP); - oz_trace("new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n", - new_apps, pd->total_apps, pd->paused_apps); + oz_dbg(ON, "new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n", + new_apps, pd->total_apps, pd->paused_apps); if (start_apps) { if (oz_services_start(pd, start_apps, 0)) rsp_status = OZ_STATUS_TOO_MANY_PDS; @@ -282,7 +282,7 @@ done: if (stop_needed) oz_pd_stop(pd); oz_pd_put(pd); - pd = 0; + pd = NULL; } if (old_net_dev) dev_put(old_net_dev); @@ -290,22 +290,25 @@ done: oz_pd_destroy(free_pd); return pd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index, - u8 *report, u8 len) + const u8 *report, u8 len) { struct oz_farewell *f; struct oz_farewell *f2; int found = 0; - f = kmalloc(sizeof(struct oz_farewell) + len - 1, GFP_ATOMIC); + + f = kmalloc(sizeof(struct oz_farewell) + len, GFP_ATOMIC); if (!f) return; f->ep_num = ep_num; f->index = index; + f->len = len; memcpy(f->report, report, len); - oz_trace("RX: Adding farewell report\n"); + oz_dbg(ON, "RX: Adding farewell report\n"); spin_lock(&g_polling_lock); list_for_each_entry(f2, &pd->farewell_list, link) { if ((f2->ep_num == ep_num) && (f2->index == index)) { @@ -319,7 +322,8 @@ static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index, if (found) kfree(f2); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static void oz_rx_frame(struct sk_buff *skb) @@ -328,25 +332,22 @@ static void oz_rx_frame(struct sk_buff *skb) u8 *src_addr; struct oz_elt *elt; int length; - struct oz_pd *pd = 0; + struct oz_pd *pd = NULL; struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); + struct timespec current_time; int dup = 0; u32 pkt_num; - oz_event_log(OZ_EVT_RX_PROCESS, 0, - (((u16)oz_hdr->control)<<8)|oz_hdr->last_pkt_num, - 0, oz_hdr->pkt_num); - oz_trace2(OZ_TRACE_RX_FRAMES, - "RX frame PN=0x%x LPN=0x%x control=0x%x\n", - oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control); + oz_dbg(RX_FRAMES, "RX frame PN=0x%x LPN=0x%x control=0x%x\n", + oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control); mac_hdr = skb_mac_header(skb); - src_addr = &mac_hdr[ETH_ALEN] ; + src_addr = &mac_hdr[ETH_ALEN]; length = skb->len; /* Check the version field */ if (oz_get_prot_ver(oz_hdr->control) != OZ_PROTOCOL_VERSION) { - oz_trace("Incorrect protocol version: %d\n", - oz_get_prot_ver(oz_hdr->control)); + oz_dbg(ON, "Incorrect protocol version: %d\n", + oz_get_prot_ver(oz_hdr->control)); goto done; } @@ -354,18 +355,24 @@ static void oz_rx_frame(struct sk_buff *skb) pd = oz_pd_find(src_addr); if (pd) { - pd->last_rx_time_j = jiffies; - oz_timer_add(pd, OZ_TIMER_TOUT, - pd->last_rx_time_j + pd->presleep_j, 1); + if (!(pd->state & OZ_PD_S_CONNECTED)) + oz_pd_set_state(pd, OZ_PD_S_CONNECTED); + getnstimeofday(¤t_time); + if ((current_time.tv_sec != pd->last_rx_timestamp.tv_sec) || + (pd->presleep < MSEC_PER_SEC)) { + oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep); + pd->last_rx_timestamp = current_time; + } if (pkt_num != pd->last_rx_pkt_num) { pd->last_rx_pkt_num = pkt_num; } else { dup = 1; - oz_trace("Duplicate frame\n"); + oz_dbg(ON, "Duplicate frame\n"); } } if (pd && !dup && ((pd->mode & OZ_MODE_MASK) == OZ_MODE_TRIGGERED)) { + oz_dbg(RX_FRAMES, "Received TRIGGER Frame\n"); pd->last_sent_frame = &pd->tx_queue; if (oz_hdr->control & OZ_F_ACK) { /* Retire completed frames */ @@ -376,8 +383,6 @@ static void oz_rx_frame(struct sk_buff *skb) int backlog = pd->nb_queued_frames; pd->trigger_pkt_num = pkt_num; /* Send queued frames */ - while (oz_prepare_frame(pd, 0) >= 0) - ; oz_send_queued_frames(pd, backlog); } } @@ -391,23 +396,22 @@ static void oz_rx_frame(struct sk_buff *skb) break; switch (elt->type) { case OZ_ELT_CONNECT_REQ: - oz_event_log(OZ_EVT_CONNECT_REQ, 0, 0, 0, 0); - oz_trace("RX: OZ_ELT_CONNECT_REQ\n"); + oz_dbg(ON, "RX: OZ_ELT_CONNECT_REQ\n"); pd = oz_connect_req(pd, elt, src_addr, skb->dev); break; case OZ_ELT_DISCONNECT: - oz_trace("RX: OZ_ELT_DISCONNECT\n"); + oz_dbg(ON, "RX: OZ_ELT_DISCONNECT\n"); if (pd) oz_pd_sleep(pd); break; case OZ_ELT_UPDATE_PARAM_REQ: { struct oz_elt_update_param *body = (struct oz_elt_update_param *)(elt + 1); - oz_trace("RX: OZ_ELT_UPDATE_PARAM_REQ\n"); + oz_dbg(ON, "RX: OZ_ELT_UPDATE_PARAM_REQ\n"); if (pd && (pd->state & OZ_PD_S_CONNECTED)) { spin_lock(&g_polling_lock); pd_set_keepalive(pd, body->keepalive); - pd_set_presleep(pd, body->presleep); + pd_set_presleep(pd, body->presleep, 1); spin_unlock(&g_polling_lock); } } @@ -415,7 +419,7 @@ static void oz_rx_frame(struct sk_buff *skb) case OZ_ELT_FAREWELL_REQ: { struct oz_elt_farewell *body = (struct oz_elt_farewell *)(elt + 1); - oz_trace("RX: OZ_ELT_FAREWELL_REQ\n"); + oz_dbg(ON, "RX: OZ_ELT_FAREWELL_REQ\n"); oz_add_farewell(pd, body->ep_num, body->index, body->report, elt->length + 1 - sizeof(*body)); @@ -431,7 +435,7 @@ static void oz_rx_frame(struct sk_buff *skb) } break; default: - oz_trace("RX: Unknown elt %02x\n", elt->type); + oz_dbg(ON, "RX: Unknown elt %02x\n", elt->type); } elt = oz_next_elt(elt); } @@ -440,19 +444,19 @@ done: oz_pd_put(pd); consume_skb(skb); } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_protocol_term(void) { - struct list_head *chain = 0; - del_timer_sync(&g_timer); + struct oz_binding *b, *t; + /* Walk the list of bindings and remove each one. */ spin_lock_bh(&g_binding_lock); - while (g_binding) { - struct oz_binding *b = g_binding; - g_binding = b->next; + list_for_each_entry_safe(b, t, &g_binding, link) { + list_del(&b->link); spin_unlock_bh(&g_binding_lock); dev_remove_pack(&b->ptype); if (b->ptype.dev) @@ -475,21 +479,38 @@ void oz_protocol_term(void) oz_pd_put(pd); spin_lock_bh(&g_polling_lock); } - chain = g_timer_pool; - g_timer_pool = 0; spin_unlock_bh(&g_polling_lock); - while (chain) { - struct oz_timer *t = container_of(chain, struct oz_timer, link); - chain = chain->next; - kfree(t); - } - oz_trace("Protocol stopped\n"); + oz_dbg(ON, "Protocol stopped\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -static void oz_pd_handle_timer(struct oz_pd *pd, int type) +void oz_pd_heartbeat_handler(unsigned long data) { + struct oz_pd *pd = (struct oz_pd *)data; + u16 apps = 0; + + spin_lock_bh(&g_polling_lock); + if (pd->state & OZ_PD_S_CONNECTED) + apps = pd->total_apps; + spin_unlock_bh(&g_polling_lock); + if (apps) + oz_pd_heartbeat(pd, apps); + oz_pd_put(pd); +} + +/* + * Context: softirq + */ +void oz_pd_timeout_handler(unsigned long data) +{ + int type; + struct oz_pd *pd = (struct oz_pd *)data; + + spin_lock_bh(&g_polling_lock); + type = pd->timeout_type; + spin_unlock_bh(&g_polling_lock); switch (type) { case OZ_TIMER_TOUT: oz_pd_sleep(pd); @@ -497,250 +518,100 @@ static void oz_pd_handle_timer(struct oz_pd *pd, int type) case OZ_TIMER_STOP: oz_pd_stop(pd); break; - case OZ_TIMER_HEARTBEAT: { - u16 apps = 0; - spin_lock_bh(&g_polling_lock); - pd->heartbeat_requested = 0; - if (pd->state & OZ_PD_S_CONNECTED) - apps = pd->total_apps; - spin_unlock_bh(&g_polling_lock); - if (apps) - oz_pd_heartbeat(pd, apps); - } - break; } + oz_pd_put(pd); } -/*------------------------------------------------------------------------------ - * Context: softirq + +/* + * Context: Interrupt */ -static void oz_protocol_timer(unsigned long arg) +enum hrtimer_restart oz_pd_heartbeat_event(struct hrtimer *timer) { - struct oz_timer *t; - struct oz_timer *t2; struct oz_pd *pd; - spin_lock_bh(&g_polling_lock); - if (!g_cur_timer) { - /* This happens if we remove the current timer but can't stop - * the timer from firing. In this case just get out. - */ - oz_event_log(OZ_EVT_TIMER, 0, 0, 0, 0); - spin_unlock_bh(&g_polling_lock); - return; - } - g_timer_state = OZ_TIMER_IN_HANDLER; - t = g_cur_timer; - g_cur_timer = 0; - list_del(&t->link); - spin_unlock_bh(&g_polling_lock); - do { - pd = t->pd; - oz_event_log(OZ_EVT_TIMER, 0, t->type, 0, 0); - oz_pd_handle_timer(pd, t->type); - spin_lock_bh(&g_polling_lock); - if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) { - t->link.next = g_timer_pool; - g_timer_pool = &t->link; - g_timer_pool_count++; - t = 0; - } - if (!list_empty(&g_timer_list)) { - t2 = container_of(g_timer_list.next, - struct oz_timer, link); - if (time_before_eq(t2->due_time, jiffies)) - list_del(&t2->link); - else - t2 = 0; - } else { - t2 = 0; - } - spin_unlock_bh(&g_polling_lock); - oz_pd_put(pd); - if (t) - kfree(t); - t = t2; - } while (t); - g_timer_state = OZ_TIMER_IDLE; - oz_protocol_timer_start(); + + pd = container_of(timer, struct oz_pd, heartbeat); + hrtimer_forward_now(timer, ktime_set(pd->pulse_period / + MSEC_PER_SEC, (pd->pulse_period % MSEC_PER_SEC) * NSEC_PER_MSEC)); + oz_pd_get(pd); + tasklet_schedule(&pd->heartbeat_tasklet); + return HRTIMER_RESTART; } -/*------------------------------------------------------------------------------ - * Context: softirq + +/* + * Context: Interrupt */ -static void oz_protocol_timer_start(void) +enum hrtimer_restart oz_pd_timeout_event(struct hrtimer *timer) { - spin_lock_bh(&g_polling_lock); - if (!list_empty(&g_timer_list)) { - g_cur_timer = - container_of(g_timer_list.next, struct oz_timer, link); - if (g_timer_state == OZ_TIMER_SET) { - oz_event_log(OZ_EVT_TIMER_CTRL, 3, - (u16)g_cur_timer->type, 0, - (unsigned)g_cur_timer->due_time); - mod_timer(&g_timer, g_cur_timer->due_time); - } else { - oz_event_log(OZ_EVT_TIMER_CTRL, 4, - (u16)g_cur_timer->type, 0, - (unsigned)g_cur_timer->due_time); - g_timer.expires = g_cur_timer->due_time; - g_timer.function = oz_protocol_timer; - g_timer.data = 0; - add_timer(&g_timer); - } - g_timer_state = OZ_TIMER_SET; - } else { - oz_trace("No queued timers\n"); - } - spin_unlock_bh(&g_polling_lock); + struct oz_pd *pd; + + pd = container_of(timer, struct oz_pd, timeout); + oz_pd_get(pd); + tasklet_schedule(&pd->timeout_tasklet); + return HRTIMER_NORESTART; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ -void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, - int remove) +void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time) { - struct list_head *e; - struct oz_timer *t = 0; - int restart_needed = 0; - oz_event_log(OZ_EVT_TIMER_CTRL, 1, (u16)type, 0, (unsigned)due_time); - spin_lock(&g_polling_lock); - if (remove) { - list_for_each(e, &g_timer_list) { - t = container_of(e, struct oz_timer, link); - if ((t->pd == pd) && (t->type == type)) { - if (g_cur_timer == t) { - restart_needed = 1; - g_cur_timer = 0; - } - list_del(e); - break; - } - t = 0; - } - } - if (!t) { - if (g_timer_pool) { - t = container_of(g_timer_pool, struct oz_timer, link); - g_timer_pool = g_timer_pool->next; - g_timer_pool_count--; + spin_lock_bh(&g_polling_lock); + switch (type) { + case OZ_TIMER_TOUT: + case OZ_TIMER_STOP: + if (hrtimer_active(&pd->timeout)) { + hrtimer_set_expires(&pd->timeout, ktime_set(due_time / + MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * + NSEC_PER_MSEC)); + hrtimer_start_expires(&pd->timeout, HRTIMER_MODE_REL); } else { - t = kmalloc(sizeof(struct oz_timer), GFP_ATOMIC); - } - if (t) { - t->pd = pd; - t->type = type; - oz_pd_get(pd); - } - } - if (t) { - struct oz_timer *t2; - t->due_time = due_time; - list_for_each(e, &g_timer_list) { - t2 = container_of(e, struct oz_timer, link); - if (time_before(due_time, t2->due_time)) { - if (t2 == g_cur_timer) { - g_cur_timer = 0; - restart_needed = 1; - } - break; - } + hrtimer_start(&pd->timeout, ktime_set(due_time / + MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * + NSEC_PER_MSEC), HRTIMER_MODE_REL); } - list_add_tail(&t->link, e); - } - if (g_timer_state == OZ_TIMER_IDLE) - restart_needed = 1; - else if (g_timer_state == OZ_TIMER_IN_HANDLER) - restart_needed = 0; - spin_unlock(&g_polling_lock); - if (restart_needed) - oz_protocol_timer_start(); -} -/*------------------------------------------------------------------------------ - * Context: softirq or process - */ -void oz_timer_delete(struct oz_pd *pd, int type) -{ - struct list_head *chain = 0; - struct oz_timer *t; - struct oz_timer *n; - int restart_needed = 0; - int release = 0; - oz_event_log(OZ_EVT_TIMER_CTRL, 2, (u16)type, 0, 0); - spin_lock(&g_polling_lock); - list_for_each_entry_safe(t, n, &g_timer_list, link) { - if ((t->pd == pd) && ((type == 0) || (t->type == type))) { - if (g_cur_timer == t) { - restart_needed = 1; - g_cur_timer = 0; - del_timer(&g_timer); - } - list_del(&t->link); - release++; - if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) { - t->link.next = g_timer_pool; - g_timer_pool = &t->link; - g_timer_pool_count++; - } else { - t->link.next = chain; - chain = &t->link; - } - if (type) - break; - } - } - if (g_timer_state == OZ_TIMER_IN_HANDLER) - restart_needed = 0; - else if (restart_needed) - g_timer_state = OZ_TIMER_IDLE; - spin_unlock(&g_polling_lock); - if (restart_needed) - oz_protocol_timer_start(); - while (release--) - oz_pd_put(pd); - while (chain) { - t = container_of(chain, struct oz_timer, link); - chain = chain->next; - kfree(t); + pd->timeout_type = type; + break; + case OZ_TIMER_HEARTBEAT: + if (!hrtimer_active(&pd->heartbeat)) + hrtimer_start(&pd->heartbeat, ktime_set(due_time / + MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * + NSEC_PER_MSEC), HRTIMER_MODE_REL); + break; } + spin_unlock_bh(&g_polling_lock); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_pd_request_heartbeat(struct oz_pd *pd) { - unsigned long now = jiffies; - unsigned long t; - spin_lock(&g_polling_lock); - if (pd->heartbeat_requested) { - spin_unlock(&g_polling_lock); - return; - } - if (pd->pulse_period_j) - t = ((now / pd->pulse_period_j) + 1) * pd->pulse_period_j; - else - t = now + 1; - pd->heartbeat_requested = 1; - spin_unlock(&g_polling_lock); - oz_timer_add(pd, OZ_TIMER_HEARTBEAT, t, 0); + oz_timer_add(pd, OZ_TIMER_HEARTBEAT, pd->pulse_period > 0 ? + pd->pulse_period : OZ_QUANTUM); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ -struct oz_pd *oz_pd_find(u8 *mac_addr) +struct oz_pd *oz_pd_find(const u8 *mac_addr) { struct oz_pd *pd; struct list_head *e; + spin_lock_bh(&g_polling_lock); list_for_each(e, &g_pd_list) { pd = container_of(e, struct oz_pd, link); - if (memcmp(pd->mac_addr, mac_addr, ETH_ALEN) == 0) { + if (ether_addr_equal(pd->mac_addr, mac_addr)) { atomic_inc(&pd->ref_count); spin_unlock_bh(&g_polling_lock); return pd; } } spin_unlock_bh(&g_polling_lock); - return 0; + return NULL; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_app_enable(int app_id, int enable) @@ -754,15 +625,15 @@ void oz_app_enable(int app_id, int enable) spin_unlock_bh(&g_polling_lock); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { - oz_event_log(OZ_EVT_RX_FRAME, 0, 0, 0, 0); skb = skb_share_check(skb, GFP_ATOMIC); - if (skb == 0) + if (skb == NULL) return 0; spin_lock_bh(&g_rx_queue.lock); if (g_processing_rx) { @@ -789,56 +660,37 @@ static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev, } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -void oz_binding_add(char *net_dev) +void oz_binding_add(const char *net_dev) { struct oz_binding *binding; - binding = kmalloc(sizeof(struct oz_binding), GFP_ATOMIC); - if (binding) { - binding->ptype.type = __constant_htons(OZ_ETHERTYPE); - binding->ptype.func = oz_pkt_recv; + binding = kzalloc(sizeof(struct oz_binding), GFP_KERNEL); + if (!binding) + return; + + binding->ptype.type = htons(OZ_ETHERTYPE); + binding->ptype.func = oz_pkt_recv; + if (net_dev && *net_dev) { memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN); - if (net_dev && *net_dev) { - oz_trace("Adding binding: %s\n", net_dev); - binding->ptype.dev = - dev_get_by_name(&init_net, net_dev); - if (binding->ptype.dev == 0) { - oz_trace("Netdev %s not found\n", net_dev); - kfree(binding); - binding = 0; - } - } else { - oz_trace("Binding to all netcards\n"); - binding->ptype.dev = 0; - } - if (binding) { - dev_add_pack(&binding->ptype); - spin_lock_bh(&g_binding_lock); - binding->next = g_binding; - g_binding = binding; - spin_unlock_bh(&g_binding_lock); + oz_dbg(ON, "Adding binding: %s\n", net_dev); + binding->ptype.dev = dev_get_by_name(&init_net, net_dev); + if (binding->ptype.dev == NULL) { + oz_dbg(ON, "Netdev %s not found\n", net_dev); + kfree(binding); + return; } } + dev_add_pack(&binding->ptype); + spin_lock_bh(&g_binding_lock); + list_add_tail(&binding->link, &g_binding); + spin_unlock_bh(&g_binding_lock); } -/*------------------------------------------------------------------------------ - * Context: process - */ -static int compare_binding_name(char *s1, char *s2) -{ - int i; - for (i = 0; i < OZ_MAX_BINDING_LEN; i++) { - if (*s1 != *s2) - return 0; - if (!*s1++) - return 1; - s2++; - } - return 1; -} -/*------------------------------------------------------------------------------ + +/* * Context: process */ static void pd_stop_all_for_device(struct net_device *net_dev) @@ -846,6 +698,7 @@ static void pd_stop_all_for_device(struct net_device *net_dev) struct list_head h; struct oz_pd *pd; struct oz_pd *n; + INIT_LIST_HEAD(&h); spin_lock_bh(&g_polling_lock); list_for_each_entry_safe(pd, n, &g_pd_list, link) { @@ -861,38 +714,37 @@ static void pd_stop_all_for_device(struct net_device *net_dev) oz_pd_put(pd); } } -/*------------------------------------------------------------------------------ + +/* * Context: process */ -void oz_binding_remove(char *net_dev) +void oz_binding_remove(const char *net_dev) { - struct oz_binding *binding = 0; - struct oz_binding **link; - oz_trace("Removing binding: %s\n", net_dev); + struct oz_binding *binding; + int found = 0; + + oz_dbg(ON, "Removing binding: %s\n", net_dev); spin_lock_bh(&g_binding_lock); - binding = g_binding; - link = &g_binding; - while (binding) { - if (compare_binding_name(binding->name, net_dev)) { - oz_trace("Binding '%s' found\n", net_dev); - *link = binding->next; + list_for_each_entry(binding, &g_binding, link) { + if (strncmp(binding->name, net_dev, OZ_MAX_BINDING_LEN) == 0) { + oz_dbg(ON, "Binding '%s' found\n", net_dev); + found = 1; break; - } else { - link = &binding; - binding = binding->next; } } spin_unlock_bh(&g_binding_lock); - if (binding) { + if (found) { dev_remove_pack(&binding->ptype); if (binding->ptype.dev) { dev_put(binding->ptype.dev); pd_stop_all_for_device(binding->ptype.dev); } + list_del(&binding->link); kfree(binding); } } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static char *oz_get_next_device_name(char *s, char *dname, int max_size) @@ -906,14 +758,15 @@ static char *oz_get_next_device_name(char *s, char *dname, int max_size) *dname = 0; return s; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_protocol_init(char *devs) { skb_queue_head_init(&g_rx_queue); - if (devs && (devs[0] == '*')) { - oz_binding_add(0); + if (devs[0] == '*') { + oz_binding_add(NULL); } else { char d[32]; while (*devs) { @@ -922,10 +775,10 @@ int oz_protocol_init(char *devs) oz_binding_add(d); } } - init_timer(&g_timer); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_get_pd_list(struct oz_mac_addr *addr, int max_count) @@ -933,25 +786,15 @@ int oz_get_pd_list(struct oz_mac_addr *addr, int max_count) struct oz_pd *pd; struct list_head *e; int count = 0; + spin_lock_bh(&g_polling_lock); list_for_each(e, &g_pd_list) { if (count >= max_count) break; pd = container_of(e, struct oz_pd, link); - memcpy(&addr[count++], pd->mac_addr, ETH_ALEN); + ether_addr_copy((u8 *)&addr[count++], pd->mac_addr); } spin_unlock_bh(&g_polling_lock); return count; } -/*------------------------------------------------------------------------------ -*/ -void oz_polling_lock_bh(void) -{ - spin_lock_bh(&g_polling_lock); -} -/*------------------------------------------------------------------------------ -*/ -void oz_polling_unlock_bh(void) -{ - spin_unlock_bh(&g_polling_lock); -} + diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h index 89aea28bd8d..cb38e02c968 100644 --- a/drivers/staging/ozwpan/ozproto.h +++ b/drivers/staging/ozwpan/ozproto.h @@ -7,28 +7,25 @@ #define _OZPROTO_H #include <asm/byteorder.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozappif.h" #define OZ_ALLOCATED_SPACE(__x) (LL_RESERVED_SPACE(__x)+(__x)->needed_tailroom) -/* Converts millisecs to jiffies. - */ -#define oz_ms_to_jiffies(__x) (((__x)*1000)/HZ) - -/* Quantum milliseconds. - */ -#define OZ_QUANTUM_MS 8 -/* Quantum jiffies - */ -#define OZ_QUANTUM_J (oz_ms_to_jiffies(OZ_QUANTUM_MS)) +/* Quantum in MS */ +#define OZ_QUANTUM 8 /* Default timeouts. */ -#define OZ_CONNECTION_TOUT_J (2*HZ) -#define OZ_PRESLEEP_TOUT_J (11*HZ) +#define OZ_PRESLEEP_TOUT 11 /* Maximun sizes of tx frames. */ -#define OZ_MAX_TX_SIZE 1514 +#define OZ_MAX_TX_SIZE 760 + +/* Maximum number of uncompleted isoc frames that can be pending in network. */ +#define OZ_MAX_SUBMITTED_ISOC 16 + +/* Maximum number of uncompleted isoc frames that can be pending in Tx Queue. */ +#define OZ_MAX_TX_QUEUE_ISOC 32 /* Application handler functions. */ @@ -56,14 +53,17 @@ int oz_protocol_init(char *devs); void oz_protocol_term(void); int oz_get_pd_list(struct oz_mac_addr *addr, int max_count); void oz_app_enable(int app_id, int enable); -struct oz_pd *oz_pd_find(u8 *mac_addr); -void oz_binding_add(char *net_dev); -void oz_binding_remove(char *net_dev); -void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, - int remove); +struct oz_pd *oz_pd_find(const u8 *mac_addr); +void oz_binding_add(const char *net_dev); +void oz_binding_remove(const char *net_dev); +void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time); void oz_timer_delete(struct oz_pd *pd, int type); void oz_pd_request_heartbeat(struct oz_pd *pd); -void oz_polling_lock_bh(void); -void oz_polling_unlock_bh(void); +void oz_pd_heartbeat_handler(unsigned long data); +void oz_pd_timeout_handler(unsigned long data); +enum hrtimer_restart oz_pd_heartbeat_event(struct hrtimer *timer); +enum hrtimer_restart oz_pd_timeout_event(struct hrtimer *timer); +int oz_get_pd_status_list(char *pd_list, int max_count); +int oz_get_binding_list(char *buf, int max_if); #endif /* _OZPROTO_H */ diff --git a/drivers/staging/ozwpan/ozprotocol.h b/drivers/staging/ozwpan/ozprotocol.h index b3e7d77f3ff..9bbb182f277 100644 --- a/drivers/staging/ozwpan/ozprotocol.h +++ b/drivers/staging/ozwpan/ozprotocol.h @@ -65,6 +65,10 @@ struct oz_hdr { #define OZ_LAST_PN_HALF_CYCLE 127 +#define OZ_LATENCY_MASK 0xc0 +#define OZ_ONE_MS_LATENCY 0x40 +#define OZ_TEN_MS_LATENCY 0x80 + /* Connect request data structure. */ struct oz_elt_connect_req { @@ -73,7 +77,7 @@ struct oz_elt_connect_req { u8 pd_info; u8 session_id; u8 presleep; - u8 resv2; + u8 ms_isoc_latency; u8 host_vendor; u8 keep_alive; u16 apps; @@ -89,6 +93,7 @@ struct oz_elt_connect_req { #define OZ_MODE_MASK 0xf #define OZ_F_ISOC_NO_ELTS 0x40 #define OZ_F_ISOC_ANYTIME 0x80 +#define OZ_NO_ELTS_ANYTIME 0xc0 /* Keep alive field. */ @@ -187,7 +192,7 @@ struct oz_get_desc_req { u16 size; u8 req_type; u8 desc_type; - u16 w_index; + __le16 w_index; u8 index; } PACKED; @@ -214,8 +219,8 @@ struct oz_get_desc_rsp { u8 elt_seq_num; u8 type; u8 req_id; - u16 offset; - u16 total_size; + __le16 offset; + __le16 total_size; u8 rcode; u8 data[1]; } PACKED; diff --git a/drivers/staging/ozwpan/oztrace.c b/drivers/staging/ozwpan/oztrace.c deleted file mode 100644 index 353ead24fd7..00000000000 --- a/drivers/staging/ozwpan/oztrace.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ----------------------------------------------------------------------------- - */ -#include "ozconfig.h" -#include "oztrace.h" - -#ifdef WANT_VERBOSE_TRACE -unsigned long trace_flags = - 0 -#ifdef WANT_TRACE_STREAM - | OZ_TRACE_STREAM -#endif /* WANT_TRACE_STREAM */ -#ifdef WANT_TRACE_URB - | OZ_TRACE_URB -#endif /* WANT_TRACE_URB */ - -#ifdef WANT_TRACE_CTRL_DETAIL - | OZ_TRACE_CTRL_DETAIL -#endif /* WANT_TRACE_CTRL_DETAIL */ - -#ifdef WANT_TRACE_HUB - | OZ_TRACE_HUB -#endif /* WANT_TRACE_HUB */ - -#ifdef WANT_TRACE_RX_FRAMES - | OZ_TRACE_RX_FRAMES -#endif /* WANT_TRACE_RX_FRAMES */ - -#ifdef WANT_TRACE_TX_FRAMES - | OZ_TRACE_TX_FRAMES -#endif /* WANT_TRACE_TX_FRAMES */ - ; -#endif /* WANT_VERBOSE_TRACE */ - diff --git a/drivers/staging/ozwpan/oztrace.h b/drivers/staging/ozwpan/oztrace.h deleted file mode 100644 index 8293b24c5a7..00000000000 --- a/drivers/staging/ozwpan/oztrace.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2011 Ozmo Inc - * Released under the GNU General Public License Version 2 (GPLv2). - * ----------------------------------------------------------------------------- - */ -#ifndef _OZTRACE_H_ -#define _OZTRACE_H_ -#include "ozconfig.h" - -#define TRACE_PREFIX KERN_ALERT "OZWPAN: " - -#ifdef WANT_TRACE -#define oz_trace(...) printk(TRACE_PREFIX __VA_ARGS__) -#ifdef WANT_VERBOSE_TRACE -extern unsigned long trace_flags; -#define oz_trace2(_flag, ...) \ - do { if (trace_flags & _flag) printk(TRACE_PREFIX __VA_ARGS__); \ - } while (0) -#else -#define oz_trace2(...) -#endif /* #ifdef WANT_VERBOSE_TRACE */ -#else -#define oz_trace(...) -#define oz_trace2(...) -#endif /* #ifdef WANT_TRACE */ - -#define OZ_TRACE_STREAM 0x1 -#define OZ_TRACE_URB 0x2 -#define OZ_TRACE_CTRL_DETAIL 0x4 -#define OZ_TRACE_HUB 0x8 -#define OZ_TRACE_RX_FRAMES 0x10 -#define OZ_TRACE_TX_FRAMES 0x20 - -#endif /* Sentry */ - diff --git a/drivers/staging/ozwpan/ozurbparanoia.c b/drivers/staging/ozwpan/ozurbparanoia.c index 55b9afbbe47..cf6278a198a 100644 --- a/drivers/staging/ozwpan/ozurbparanoia.c +++ b/drivers/staging/ozwpan/ozurbparanoia.c @@ -4,37 +4,39 @@ * ----------------------------------------------------------------------------- */ #include <linux/usb.h> -#include "ozconfig.h" +#include "ozdbg.h" + #ifdef WANT_URB_PARANOIA + #include "ozurbparanoia.h" -#include "oztrace.h" -/*----------------------------------------------------------------------------- - */ + #define OZ_MAX_URBS 1000 struct urb *g_urb_memory[OZ_MAX_URBS]; int g_nb_urbs; DEFINE_SPINLOCK(g_urb_mem_lock); -/*----------------------------------------------------------------------------- - */ + void oz_remember_urb(struct urb *urb) { unsigned long irq_state; + spin_lock_irqsave(&g_urb_mem_lock, irq_state); if (g_nb_urbs < OZ_MAX_URBS) { g_urb_memory[g_nb_urbs++] = urb; - oz_trace("%lu: urb up = %d %p\n", jiffies, g_nb_urbs, urb); + oz_dbg(ON, "urb up = %d %p\n", g_nb_urbs, urb); } else { - oz_trace("ERROR urb buffer full\n"); + oz_dbg(ON, "ERROR urb buffer full\n"); } spin_unlock_irqrestore(&g_urb_mem_lock, irq_state); } -/*------------------------------------------------------------------------------ + +/* */ int oz_forget_urb(struct urb *urb) { unsigned long irq_state; int i; int rc = -1; + spin_lock_irqsave(&g_urb_mem_lock, irq_state); for (i = 0; i < g_nb_urbs; i++) { if (g_urb_memory[i] == urb) { @@ -42,8 +44,7 @@ int oz_forget_urb(struct urb *urb) if (--g_nb_urbs > i) memcpy(&g_urb_memory[i], &g_urb_memory[i+1], (g_nb_urbs - i) * sizeof(struct urb *)); - oz_trace("%lu: urb down = %d %p\n", - jiffies, g_nb_urbs, urb); + oz_dbg(ON, "urb down = %d %p\n", g_nb_urbs, urb); } } spin_unlock_irqrestore(&g_urb_mem_lock, irq_state); diff --git a/drivers/staging/ozwpan/ozurbparanoia.h b/drivers/staging/ozwpan/ozurbparanoia.h index 00f5a3a81bc..5080ea76f50 100644 --- a/drivers/staging/ozwpan/ozurbparanoia.h +++ b/drivers/staging/ozwpan/ozurbparanoia.h @@ -10,8 +10,8 @@ void oz_remember_urb(struct urb *urb); int oz_forget_urb(struct urb *urb); #else -#define oz_remember_urb(__x) -#define oz_forget_urb(__x) 0 +static inline void oz_remember_urb(struct urb *urb) {} +static inline int oz_forget_urb(struct urb *urb) { return 0; } #endif /* WANT_URB_PARANOIA */ diff --git a/drivers/staging/ozwpan/ozusbif.h b/drivers/staging/ozwpan/ozusbif.h index 3acf5980d7c..4249fa37401 100644 --- a/drivers/staging/ozwpan/ozusbif.h +++ b/drivers/staging/ozwpan/ozusbif.h @@ -21,22 +21,22 @@ int oz_usb_stream_delete(void *hpd, u8 ep_num); /* Request functions. */ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, - u8 *data, int data_len); + const u8 *data, int data_len); int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, - u8 index, u16 windex, int offset, int len); + u8 index, __le16 windex, int offset, int len); int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb); void oz_usb_request_heartbeat(void *hpd); /* Confirmation functions. */ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, - u8 *desc, int length, int offset, int total_size); + const u8 *desc, int length, int offset, int total_size); void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, - u8 *data, int data_len); + const u8 *data, int data_len); /* Indication functions. */ -void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len); +void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len); int oz_hcd_heartbeat(void *hport); diff --git a/drivers/staging/ozwpan/ozusbsvc.c b/drivers/staging/ozwpan/ozusbsvc.c index 8fa7f256ad8..edd44c457a4 100644 --- a/drivers/staging/ozwpan/ozusbsvc.c +++ b/drivers/staging/ozwpan/ozusbsvc.c @@ -10,7 +10,7 @@ * The implementation of this service uses ozhcd.c to implement a USB HCD. * ----------------------------------------------------------------------------- */ -#include <linux/init.h> + #include <linux/module.h> #include <linux/timer.h> #include <linux/sched.h> @@ -18,35 +18,34 @@ #include <linux/errno.h> #include <linux/input.h> #include <asm/unaligned.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" #include "ozeltbuf.h" #include "ozpd.h" #include "ozproto.h" #include "ozusbif.h" #include "ozhcd.h" -#include "oztrace.h" #include "ozusbsvc.h" -#include "ozevent.h" -/*------------------------------------------------------------------------------ + +/* * This is called once when the driver is loaded to initialise the USB service. * Context: process */ int oz_usb_init(void) { - oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_USB, 0, 0); return oz_hcd_init(); } -/*------------------------------------------------------------------------------ + +/* * This is called once when the driver is unloaded to terminate the USB service. * Context: process */ void oz_usb_term(void) { - oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_USB, 0, 0); oz_hcd_term(); } -/*------------------------------------------------------------------------------ + +/* * This is called when the USB service is started or resumed for a PD. * Context: softirq */ @@ -54,18 +53,18 @@ int oz_usb_start(struct oz_pd *pd, int resume) { int rc = 0; struct oz_usb_ctx *usb_ctx; - struct oz_usb_ctx *old_ctx = 0; - oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_USB, 0, resume); + struct oz_usb_ctx *old_ctx; + if (resume) { - oz_trace("USB service resumed.\n"); + oz_dbg(ON, "USB service resumed\n"); return 0; } - oz_trace("USB service started.\n"); + oz_dbg(ON, "USB service started\n"); /* Create a USB context in case we need one. If we find the PD already * has a USB context then we will destroy it. */ usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC); - if (usb_ctx == 0) + if (usb_ctx == NULL) return -ENOMEM; atomic_set(&usb_ctx->ref_count, 1); usb_ctx->pd = pd; @@ -76,12 +75,12 @@ int oz_usb_start(struct oz_pd *pd, int resume) */ spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); old_ctx = pd->app_ctx[OZ_APPID_USB-1]; - if (old_ctx == 0) + if (old_ctx == NULL) pd->app_ctx[OZ_APPID_USB-1] = usb_ctx; oz_usb_get(pd->app_ctx[OZ_APPID_USB-1]); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); if (old_ctx) { - oz_trace("Already have USB context.\n"); + oz_dbg(ON, "Already have USB context\n"); kfree(usb_ctx); usb_ctx = old_ctx; } else if (usb_ctx) { @@ -98,10 +97,10 @@ int oz_usb_start(struct oz_pd *pd, int resume) oz_hcd_pd_reset(usb_ctx, usb_ctx->hport); } else { usb_ctx->hport = oz_hcd_pd_arrived(usb_ctx); - if (usb_ctx->hport == 0) { - oz_trace("USB hub returned null port.\n"); + if (usb_ctx->hport == NULL) { + oz_dbg(ON, "USB hub returned null port\n"); spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); - pd->app_ctx[OZ_APPID_USB-1] = 0; + pd->app_ctx[OZ_APPID_USB-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); oz_usb_put(usb_ctx); rc = -1; @@ -110,25 +109,27 @@ int oz_usb_start(struct oz_pd *pd, int resume) oz_usb_put(usb_ctx); return rc; } -/*------------------------------------------------------------------------------ + +/* * This is called when the USB service is stopped or paused for a PD. * Context: softirq or process */ void oz_usb_stop(struct oz_pd *pd, int pause) { struct oz_usb_ctx *usb_ctx; - oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_USB, 0, pause); + if (pause) { - oz_trace("USB service paused.\n"); + oz_dbg(ON, "USB service paused\n"); return; } spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1]; - pd->app_ctx[OZ_APPID_USB-1] = 0; + pd->app_ctx[OZ_APPID_USB-1] = NULL; spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); if (usb_ctx) { - unsigned long tout = jiffies + HZ; - oz_trace("USB service stopping...\n"); + struct timespec ts, now; + getnstimeofday(&ts); + oz_dbg(ON, "USB service stopping...\n"); usb_ctx->stopped = 1; /* At this point the reference count on the usb context should * be 2 - one from when we created it and one from the hcd @@ -136,17 +137,21 @@ void oz_usb_stop(struct oz_pd *pd, int pause) * should get in but someone may already be in. So wait * until they leave but timeout after 1 second. */ - while ((atomic_read(&usb_ctx->ref_count) > 2) && - time_before(jiffies, tout)) - ; - oz_trace("USB service stopped.\n"); + while ((atomic_read(&usb_ctx->ref_count) > 2)) { + getnstimeofday(&now); + /*Approx 1 Sec. this is not perfect calculation*/ + if (now.tv_sec != ts.tv_sec) + break; + } + oz_dbg(ON, "USB service stopped\n"); oz_hcd_pd_departed(usb_ctx->hport); /* Release the reference taken in oz_usb_start. */ oz_usb_put(usb_ctx); } } -/*------------------------------------------------------------------------------ + +/* * This increments the reference count of the context area for a specific PD. * This ensures this context area does not disappear while still in use. * Context: softirq @@ -154,35 +159,40 @@ void oz_usb_stop(struct oz_pd *pd, int pause) void oz_usb_get(void *hpd) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; + atomic_inc(&usb_ctx->ref_count); } -/*------------------------------------------------------------------------------ + +/* * This decrements the reference count of the context area for a specific PD * and destroys the context area if the reference count becomes zero. - * Context: softirq or process + * Context: irq or process */ void oz_usb_put(void *hpd) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; + if (atomic_dec_and_test(&usb_ctx->ref_count)) { - oz_trace("Dealloc USB context.\n"); + oz_dbg(ON, "Dealloc USB context\n"); oz_pd_put(usb_ctx->pd); kfree(usb_ctx); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_usb_heartbeat(struct oz_pd *pd) { struct oz_usb_ctx *usb_ctx; int rc = 0; + spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1]; if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return rc; if (usb_ctx->stopped) goto done; @@ -193,14 +203,16 @@ done: oz_usb_put(usb_ctx); return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_usb_stream_create(void *hpd, u8 ep_num) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; - oz_trace("oz_usb_stream_create(0x%x)\n", ep_num); + + oz_dbg(ON, "%s: (0x%x)\n", __func__, ep_num); if (pd->mode & OZ_F_ISOC_NO_ELTS) { oz_isoc_stream_create(pd, ep_num); } else { @@ -213,16 +225,18 @@ int oz_usb_stream_create(void *hpd, u8 ep_num) } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_usb_stream_delete(void *hpd, u8 ep_num) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; + if (usb_ctx) { struct oz_pd *pd = usb_ctx->pd; if (pd) { - oz_trace("oz_usb_stream_delete(0x%x)\n", ep_num); + oz_dbg(ON, "%s: (0x%x)\n", __func__, ep_num); if (pd->mode & OZ_F_ISOC_NO_ELTS) { oz_isoc_stream_delete(pd, ep_num); } else { @@ -234,12 +248,14 @@ int oz_usb_stream_delete(void *hpd, u8 ep_num) } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq or process */ void oz_usb_request_heartbeat(void *hpd) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; + if (usb_ctx && usb_ctx->pd) oz_pd_request_heartbeat(usb_ctx->pd); } diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c index 66bd576bb5e..f32d01427f7 100644 --- a/drivers/staging/ozwpan/ozusbsvc1.c +++ b/drivers/staging/ozwpan/ozusbsvc1.c @@ -5,7 +5,6 @@ * This file implements the protocol specific parts of the USB service for a PD. * ----------------------------------------------------------------------------- */ -#include <linux/init.h> #include <linux/module.h> #include <linux/timer.h> #include <linux/sched.h> @@ -13,20 +12,18 @@ #include <linux/errno.h> #include <linux/input.h> #include <asm/unaligned.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozprotocol.h" #include "ozeltbuf.h" #include "ozpd.h" #include "ozproto.h" #include "ozusbif.h" #include "ozhcd.h" -#include "oztrace.h" #include "ozusbsvc.h" -#include "ozevent.h" -/*------------------------------------------------------------------------------ - */ + #define MAX_ISOC_FIXED_DATA (253-sizeof(struct oz_isoc_fixed)) -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_usb_submit_elt(struct oz_elt_buf *eb, struct oz_elt_info *ei, @@ -35,6 +32,7 @@ static int oz_usb_submit_elt(struct oz_elt_buf *eb, struct oz_elt_info *ei, int ret; struct oz_elt *elt = (struct oz_elt *)ei->data; struct oz_app_hdr *app_hdr = (struct oz_app_hdr *)(elt+1); + elt->type = OZ_ELT_APP_DATA; ei->app_id = OZ_APPID_USB; ei->length = elt->length + sizeof(struct oz_elt); @@ -51,11 +49,12 @@ static int oz_usb_submit_elt(struct oz_elt_buf *eb, struct oz_elt_info *ei, spin_unlock_bh(&eb->lock); return ret; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, - u8 index, u16 windex, int offset, int len) + u8 index, __le16 windex, int offset, int len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; @@ -63,15 +62,16 @@ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, struct oz_get_desc_req *body; struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); - oz_trace(" req_type = 0x%x\n", req_type); - oz_trace(" desc_type = 0x%x\n", desc_type); - oz_trace(" index = 0x%x\n", index); - oz_trace(" windex = 0x%x\n", windex); - oz_trace(" offset = 0x%x\n", offset); - oz_trace(" len = 0x%x\n", len); + + oz_dbg(ON, " req_type = 0x%x\n", req_type); + oz_dbg(ON, " desc_type = 0x%x\n", desc_type); + oz_dbg(ON, " index = 0x%x\n", index); + oz_dbg(ON, " windex = 0x%x\n", windex); + oz_dbg(ON, " offset = 0x%x\n", offset); + oz_dbg(ON, " len = 0x%x\n", len); if (len > 200) len = 200; - if (ei == 0) + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_get_desc_req); @@ -86,7 +86,8 @@ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, body->index = index; return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index) @@ -97,7 +98,8 @@ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index) struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_set_config_req *body; - if (ei == 0) + + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_set_config_req); @@ -107,7 +109,8 @@ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index) body->index = index; return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt) @@ -118,7 +121,8 @@ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt) struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_set_interface_req *body; - if (ei == 0) + + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_set_interface_req); @@ -129,7 +133,8 @@ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt) body->alternative = alt; return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, @@ -141,7 +146,8 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_feature_req *body; - if (ei == 0) + + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_feature_req); @@ -153,11 +159,12 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, put_unaligned(feature, &body->feature); return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, - u8 request, __le16 value, __le16 index, u8 *data, int data_len) + u8 request, __le16 value, __le16 index, const u8 *data, int data_len) { struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; struct oz_pd *pd = usb_ctx->pd; @@ -165,7 +172,8 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, struct oz_elt_buf *eb = &pd->elt_buff; struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); struct oz_vendor_class_req *body; - if (ei == 0) + + if (ei == NULL) return -1; elt = (struct oz_elt *)ei->data; elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len; @@ -180,20 +188,18 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, memcpy(body->data, data, data_len); return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, - u8 *data, int data_len) + const u8 *data, int data_len) { unsigned wvalue = le16_to_cpu(setup->wValue); unsigned windex = le16_to_cpu(setup->wIndex); unsigned wlength = le16_to_cpu(setup->wLength); int rc = 0; - oz_event_log(OZ_EVT_CTRL_REQ, setup->bRequest, req_id, - (void *)(((unsigned long)(setup->wValue))<<16 | - ((unsigned long)setup->wIndex)), - setup->bRequestType); + if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { switch (setup->bRequest) { case USB_REQ_GET_DESCRIPTOR: @@ -231,7 +237,8 @@ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) @@ -264,7 +271,7 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) int unit_count; int unit_size; int rem; - if (ei == 0) + if (ei == NULL) return -1; rem = MAX_ISOC_FIXED_DATA; elt = (struct oz_elt *)ei->data; @@ -302,13 +309,15 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ -void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, +static void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, struct oz_usb_hdr *usb_hdr, int len) { struct oz_data *data_hdr = (struct oz_data *)usb_hdr; + switch (data_hdr->format) { case OZ_DATA_F_MULTIPLE_FIXED: { struct oz_multiple_fixed *body = @@ -344,7 +353,8 @@ void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, } } -/*------------------------------------------------------------------------------ + +/* * This is called when the PD has received a USB element. The type of element * is determined and is then passed to an appropriate handler function. * Context: softirq-serialized @@ -359,7 +369,7 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return; /* Context has gone so nothing to do. */ if (usb_ctx->stopped) goto done; @@ -381,7 +391,7 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) u16 offs = le16_to_cpu(get_unaligned(&body->offset)); u16 total_size = le16_to_cpu(get_unaligned(&body->total_size)); - oz_trace("USB_REQ_GET_DESCRIPTOR - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n"); oz_hcd_get_desc_cnf(usb_ctx->hport, body->req_id, body->rcode, body->data, data_len, offs, total_size); @@ -391,14 +401,14 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) struct oz_set_config_rsp *body = (struct oz_set_config_rsp *)usb_hdr; oz_hcd_control_cnf(usb_ctx->hport, body->req_id, - body->rcode, 0, 0); + body->rcode, NULL, 0); } break; case OZ_SET_INTERFACE_RSP: { struct oz_set_interface_rsp *body = (struct oz_set_interface_rsp *)usb_hdr; oz_hcd_control_cnf(usb_ctx->hport, - body->req_id, body->rcode, 0, 0); + body->req_id, body->rcode, NULL, 0); } break; case OZ_VENDOR_CLASS_RSP: { @@ -416,21 +426,23 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt) done: oz_usb_put(usb_ctx); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq, process */ void oz_usb_farewell(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len) { struct oz_usb_ctx *usb_ctx; + spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1]; if (usb_ctx) oz_usb_get(usb_ctx); spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); - if (usb_ctx == 0) + if (usb_ctx == NULL) return; /* Context has gone so nothing to do. */ if (!usb_ctx->stopped) { - oz_trace("Farewell indicated ep = 0x%x\n", ep_num); + oz_dbg(ON, "Farewell indicated ep = 0x%x\n", ep_num); oz_hcd_data_ind(usb_ctx->hport, ep_num, data, len); } oz_usb_put(usb_ctx); |
