X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/15331876847019b1a3cdec43dcc19073b6b41dd2..0b0fc306e1e9feb5089fd263862c59534b3531bb:/target/linux/adm5120/files/drivers/usb/host/adm5120-dbg.c diff --git a/target/linux/adm5120/files/drivers/usb/host/adm5120-dbg.c b/target/linux/adm5120/files/drivers/usb/host/adm5120-dbg.c index 817d97548..f3b55f671 100644 --- a/target/linux/adm5120/files/drivers/usb/host/adm5120-dbg.c +++ b/target/linux/adm5120/files/drivers/usb/host/adm5120-dbg.c @@ -1,72 +1,131 @@ /* - * OHCI HCD (Host Controller Driver) for USB. + * ADM5120 HCD (Host Controller Driver) for USB * - * (C) Copyright 1999 Roman Weissgaerber - * (C) Copyright 2000-2002 David Brownell + * Copyright (C) 2007,2008 Gabor Juhos + * + * This file was derived from: drivers/usb/host/ohci-dbg.c + * (C) Copyright 1999 Roman Weissgaerber + * (C) Copyright 2000-2002 David Brownell + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. * - * This file is licenced under the GPL. */ /*-------------------------------------------------------------------------*/ -#ifdef DEBUG +static inline char *ed_typestring(int ed_type) +{ + switch (ed_type) { + case PIPE_CONTROL: + return "ctrl"; + case PIPE_BULK: + return "bulk"; + case PIPE_INTERRUPT: + return "intr"; + case PIPE_ISOCHRONOUS: + return "isoc"; + } + return "(bad ed_type)"; +} + +static inline char *ed_statestring(int state) +{ + switch (state) { + case ED_IDLE: + return "IDLE"; + case ED_UNLINK: + return "UNLINK"; + case ED_OPER: + return "OPER"; + } + return "?STATE"; +} + +static inline char *pipestring(int pipe) +{ + return ed_typestring(usb_pipetype(pipe)); +} + +static inline char *td_pidstring(u32 info) +{ + switch (info & TD_DP) { + case TD_DP_SETUP: + return "SETUP"; + case TD_DP_IN: + return "IN"; + case TD_DP_OUT: + return "OUT"; + } + return "?PID"; +} + +static inline char *td_togglestring(u32 info) +{ + switch (info & TD_T) { + case TD_T_DATA0: + return "DATA0"; + case TD_T_DATA1: + return "DATA1"; + case TD_T_CARRY: + return "CARRY"; + } + return "?TOGGLE"; +} + +/*-------------------------------------------------------------------------*/ -#define edstring(ed_type) ({ char *temp; \ - switch (ed_type) { \ - case PIPE_CONTROL: temp = "ctrl"; break; \ - case PIPE_BULK: temp = "bulk"; break; \ - case PIPE_INTERRUPT: temp = "intr"; break; \ - default: temp = "isoc"; break; \ - }; temp;}) -#define pipestring(pipe) edstring(usb_pipetype(pipe)) +#ifdef DEBUG /* debug| print the main components of an URB * small: 0) header + data packets 1) just header */ static void __attribute__((unused)) -urb_print(struct urb * urb, char * str, int small) +urb_print(struct admhcd *ahcd, struct urb *urb, char *str, int small, int status) { - unsigned int pipe= urb->pipe; + unsigned int pipe = urb->pipe; if (!urb->dev || !urb->dev->bus) { - dbg("%s URB: no dev", str); + admhc_dbg(ahcd, "%s URB: no dev", str); return; } #ifndef ADMHC_VERBOSE_DEBUG - if (urb->status != 0) + if (status != 0) #endif - dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d", - str, - urb, - usb_pipedevice (pipe), - usb_pipeendpoint (pipe), - usb_pipeout(pipe)? "out" : "in", - pipestring(pipe), - urb->transfer_flags, - urb->actual_length, - urb->transfer_buffer_length, - urb->status); + admhc_dbg(ahcd, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d " + "stat=%d\n", + str, + urb, + usb_pipedevice (pipe), + usb_pipeendpoint (pipe), + usb_pipeout(pipe)? "out" : "in", + pipestring(pipe), + urb->transfer_flags, + urb->actual_length, + urb->transfer_buffer_length, + status); #ifdef ADMHC_VERBOSE_DEBUG if (!small) { int i, len; if (usb_pipecontrol(pipe)) { - printk(KERN_DEBUG __FILE__ ": setup(8):"); + admhc_dbg(ahcd, "setup(8):"); for (i = 0; i < 8 ; i++) printk (" %02x", ((__u8 *) urb->setup_packet) [i]); printk ("\n"); } if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) { - printk(KERN_DEBUG __FILE__ ": data(%d/%d):", + admhc_dbg(ahcd, "data(%d/%d):", urb->actual_length, urb->transfer_buffer_length); len = usb_pipeout(pipe)? urb->transfer_buffer_length: urb->actual_length; for (i = 0; i < 16 && i < len; i++) - printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]); - printk ("%s stat:%d\n", i < len? "...": "", urb->status); + printk(" %02x", ((__u8 *)urb->transfer_buffer)[i]); + printk("%s stat:%d\n", i < len? "...": "", status); } } #endif /* ADMHC_VERBOSE_DEBUG */ @@ -83,14 +142,10 @@ urb_print(struct urb * urb, char * str, int small) } while (0); -static void admhc_dump_intr_mask ( - struct admhcd *ahcd, - char *label, - u32 mask, - char **next, - unsigned *size) +static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask, + char **next, unsigned *size) { - admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s\n", + admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", label, mask, (mask & ADMHC_INTR_INTA) ? " INTA" : "", @@ -101,17 +156,15 @@ static void admhc_dump_intr_mask ( (mask & ADMHC_INTR_SO) ? " SO" : "", (mask & ADMHC_INTR_INSM) ? " INSM" : "", (mask & ADMHC_INTR_BABI) ? " BABI" : "", + (mask & ADMHC_INTR_7) ? " !7!" : "", + (mask & ADMHC_INTR_6) ? " !6!" : "", (mask & ADMHC_INTR_RESI) ? " RESI" : "", (mask & ADMHC_INTR_SOFI) ? " SOFI" : "" ); } -static void maybe_print_eds ( - struct admhcd *ahcd, - char *label, - u32 value, - char **next, - unsigned *size) +static void maybe_print_eds(struct admhcd *ahcd, char *label, u32 value, + char **next, unsigned *size) { if (value) admhc_dbg_sw(ahcd, next, size, "%s %08x\n", label, value); @@ -129,7 +182,7 @@ static char *buss2string (int state) case ADMHC_BUSS_SUSPEND: return "suspend"; } - return "(bad state)"; + return "?state"; } static void @@ -152,7 +205,7 @@ admhc_dump_status(struct admhcd *ahcd, char **next, unsigned *size) admhc_dbg_sw(ahcd, next, size, "host_control 0x%08x BUSS=%s%s\n", temp, - buss2string (temp & ADMHC_HC_BUSS), + buss2string(temp & ADMHC_HC_BUSS), (temp & ADMHC_HC_DMAE) ? " DMAE" : "" ); @@ -198,7 +251,7 @@ admhc_dump_roothub( { u32 temp, i; - temp = admhc_get_rhdesc(ahcd); + temp = admhc_read_rhdesc(ahcd); if (temp == ~(u32)0) return; @@ -222,7 +275,7 @@ admhc_dump_roothub( } for (i = 0; i < ahcd->num_ports; i++) { - temp = admhc_get_portstatus(ahcd, i); + temp = admhc_read_portstatus(ahcd, i); dbg_port_sw(ahcd, i, temp, next, size); } } @@ -245,59 +298,30 @@ static const char data1[] = "DATA1"; static void admhc_dump_td(const struct admhcd *ahcd, const char *label, const struct td *td) { - u32 tmp = hc32_to_cpup(ahcd, &td->hwINFO); + u32 tmp; admhc_dbg(ahcd, "%s td %p; urb %p index %d; hwNextTD %08x\n", label, td, td->urb, td->index, hc32_to_cpup(ahcd, &td->hwNextTD)); - if ((td->flags & TD_FLAG_ISO) == 0) { - const char *toggle, *pid; - - switch (tmp & TD_T) { - case TD_T_DATA0: toggle = data0; break; - case TD_T_DATA1: toggle = data1; break; - case TD_T_CARRY: toggle = "CARRY"; break; - default: toggle = "(bad toggle)"; break; - } - switch (tmp & TD_DP) { - case TD_DP_SETUP: pid = "SETUP"; break; - case TD_DP_IN: pid = "IN"; break; - case TD_DP_OUT: pid = "OUT"; break; - default: pid = "(bad pid)"; break; - } - admhc_dbg(ahcd, - " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n", - tmp, - (tmp & TD_OWN) ? " OWN" : "", - TD_CC_GET(tmp), - TD_EC_GET(tmp), - toggle, - pid, - TD_ISI_GET(tmp), - TD_FN_GET(tmp)); - } else { -#if 0 /* TODO: remove */ - unsigned i; - admhc_dbg(ahcd, " info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp, - TD_CC_GET(tmp), - (tmp >> 24) & 0x07, - (tmp & TD_DI) >> 21, - tmp & 0x0000ffff); - admhc_dbg(ahcd, " bp0 %08x be %08x\n", - hc32_to_cpup (ahcd, &td->hwCBP) & ~0x0fff, - hc32_to_cpup (ahcd, &td->hwBE)); -#endif - } + tmp = hc32_to_cpup(ahcd, &td->hwINFO); + admhc_dbg(ahcd, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n", + tmp, + (tmp & TD_OWN) ? " OWN" : "", + TD_CC_GET(tmp), + TD_EC_GET(tmp), + td_togglestring(tmp), + td_pidstring(tmp), + TD_ISI_GET(tmp), + TD_FN_GET(tmp)); tmp = hc32_to_cpup(ahcd, &td->hwCBL); admhc_dbg(ahcd, " dbp %08x; cbl %08x; LEN=%d%s\n", - hc32_to_cpup (ahcd, &td->hwDBP), + hc32_to_cpup(ahcd, &td->hwDBP), tmp, TD_BL_GET(tmp), - (tmp & TD_IE) ? " IE" : "" - ); + (tmp & TD_IE) ? " IE" : ""); } /* caller MUST own hcd spinlock if verbose is set! */ @@ -307,10 +331,10 @@ admhc_dump_ed(const struct admhcd *ahcd, const char *label, { u32 tmp = hc32_to_cpu(ahcd, ed->hwINFO); - admhc_dbg(ahcd, "%s ed %p state 0x%x type %s; next ed %08x\n", + admhc_dbg(ahcd, "%s ed %p %s type %s; next ed %08x\n", label, - ed, ed->state, edstring (ed->type), - hc32_to_cpup (ahcd, &ed->hwNextED)); + ed, ed_statestring(ed->state), ed_typestring(ed->type), + hc32_to_cpup(ahcd, &ed->hwNextED)); admhc_dbg(ahcd, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp, ED_MPS_GET(tmp), @@ -345,9 +369,12 @@ admhc_dump_ed(const struct admhcd *ahcd, const char *label, #else /* ifdef DEBUG */ -static inline void urb_print(struct urb * urb, char * str, int small) {} +static inline void urb_print(struct admhcd *ahcd, struct urb * urb, char * str, + int small) {} static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label, const struct ed *ed, int verbose) {} +static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label, + const struct td *td) {} static inline void admhc_dump(struct admhcd *ahcd, int verbose) {} #undef ADMHC_VERBOSE_DEBUG @@ -363,31 +390,64 @@ static inline void remove_debug_files(struct admhcd *bus) { } #else +static int debug_async_open(struct inode *, struct file *); +static int debug_periodic_open(struct inode *, struct file *); +static int debug_registers_open(struct inode *, struct file *); +static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); +static int debug_close(struct inode *, struct file *); + +static const struct file_operations debug_async_fops = { + .owner = THIS_MODULE, + .open = debug_async_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_periodic_fops = { + .owner = THIS_MODULE, + .open = debug_periodic_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_registers_fops = { + .owner = THIS_MODULE, + .open = debug_registers_open, + .read = debug_output, + .release = debug_close, +}; + +static struct dentry *admhc_debug_root; + +struct debug_buffer { + ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ + struct device *dev; + struct mutex mutex; /* protect filling of buffer */ + size_t count; /* number of characters filled into buffer */ + char *page; +}; + static ssize_t show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed) { - unsigned temp, size = count; + unsigned temp; + unsigned size = count; if (!ed) return 0; -#if 0 - /* print first --> last */ - while (ed->ed_prev) - ed = ed->ed_prev; -#endif - /* dump a snapshot of the bulk or control schedule */ while (ed) { u32 info = hc32_to_cpu(ahcd, ed->hwINFO); u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP); + u32 tailp = hc32_to_cpu(ahcd, ed->hwTailP); struct list_head *entry; struct td *td; temp = scnprintf(buf, size, - "ed/%p %s %cs dev%d ep%d %s%smax %d %08x%s%s %s", + "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s" + " h:%08x t:%08x", ed, - edstring (ed->type), + ed_statestring(ed->state), + ed_typestring (ed->type), (info & ED_SPEED_FULL) ? 'f' : 'l', info & ED_FA_MASK, (info >> ED_EN_SHIFT) & ED_EN_MASK, @@ -397,7 +457,8 @@ show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed) info, (info & ED_SKIP) ? " S" : "", (headp & ED_H) ? " H" : "", - (headp & ED_C) ? data1 : data0); + (headp & ED_C) ? data1 : data0, + headp & ED_MASK,tailp); size -= temp; buf += temp; @@ -410,15 +471,9 @@ show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed) cbl = hc32_to_cpup (ahcd, &td->hwCBL); temp = scnprintf(buf, size, - "\n\ttd %p %s %d %s%scc=%x urb %p (%08x,%08x)", + "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)", td, - ({ char *pid; - switch (info & TD_DP) { - case TD_DP_SETUP: pid = "setup"; break; - case TD_DP_IN: pid = "in"; break; - case TD_DP_OUT: pid = "out"; break; - default: pid = "(bad pid)"; break; - } pid;}), + td_pidstring(info), TD_BL_GET(cbl), (info & TD_OWN) ? "" : "DONE ", (cbl & TD_IE) ? "IE " : "", @@ -433,11 +488,11 @@ show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed) ed = ed->ed_next; } + return count - size; } -static ssize_t -show_async(struct class_device *class_dev, char *buf) +static ssize_t fill_async_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -445,34 +500,21 @@ show_async(struct class_device *class_dev, char *buf) size_t temp; unsigned long flags; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ahcd = hcd_to_admhcd(hcd); - /* display control and bulk lists together, for simplicity */ spin_lock_irqsave(&ahcd->lock, flags); -#if 0 - temp = show_list (ahcd, buf, PAGE_SIZE, ahcd->ed_tails[ED_TAIL_CONTROL]); - temp += show_list (ahcd, buf + temp, PAGE_SIZE - temp, - ahcd->ed_tails[ED_TAIL_BULK]); -#else -#ifdef ED_TAIL_ARRAY - temp = show_list(ahcd, buf, PAGE_SIZE, ahcd->ed_head); -#else - temp = show_list(ahcd, buf, PAGE_SIZE, ahcd->ed_head); -#endif -#endif + temp = show_list(ahcd, buf->page, PAGE_SIZE, ahcd->ed_head); spin_unlock_irqrestore(&ahcd->lock, flags); return temp; } -static CLASS_DEVICE_ATTR(async, S_IRUGO, show_async, NULL); #define DBG_SCHED_LIMIT 64 -static ssize_t -show_periodic(struct class_device *class_dev, char *buf) +static ssize_t fill_periodic_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -487,10 +529,10 @@ show_periodic(struct class_device *class_dev, char *buf) return 0; seen_count = 0; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ahcd = hcd_to_admhcd(hcd); - next = buf; + next = buf->page; size = PAGE_SIZE; temp = scnprintf(next, size, "size = %d\n", NUM_INTS); @@ -565,13 +607,11 @@ show_periodic(struct class_device *class_dev, char *buf) return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); #undef DBG_SCHED_LIMIT -static ssize_t -show_registers(struct class_device *class_dev, char *buf) +static ssize_t fill_registers_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -582,11 +622,11 @@ show_registers(struct class_device *class_dev, char *buf) char *next; u32 rdata; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ahcd = hcd_to_admhcd(hcd); regs = ahcd->regs; - next = buf; + next = buf->page; size = PAGE_SIZE; spin_lock_irqsave(&ahcd->lock, flags); @@ -647,30 +687,156 @@ done: spin_unlock_irqrestore(&ahcd->lock, flags); return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); -static inline void create_debug_files (struct admhcd *ahcd) +static struct debug_buffer *alloc_buffer(struct device *dev, + ssize_t (*fill_func)(struct debug_buffer *)) { - struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev; - int retval; + struct debug_buffer *buf; - retval = class_device_create_file(cldev, &class_device_attr_async); - retval = class_device_create_file(cldev, &class_device_attr_periodic); - retval = class_device_create_file(cldev, &class_device_attr_registers); - admhc_dbg(ahcd, "created debug files\n"); + buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); + + if (buf) { + buf->dev = dev; + buf->fill_func = fill_func; + mutex_init(&buf->mutex); + } + + return buf; +} + +static int fill_buffer(struct debug_buffer *buf) +{ + int ret = 0; + + if (!buf->page) + buf->page = (char *)get_zeroed_page(GFP_KERNEL); + + if (!buf->page) { + ret = -ENOMEM; + goto out; + } + + ret = buf->fill_func(buf); + + if (ret >= 0) { + buf->count = ret; + ret = 0; + } + +out: + return ret; +} + +static ssize_t debug_output(struct file *file, char __user *user_buf, + size_t len, loff_t *offset) +{ + struct debug_buffer *buf = file->private_data; + int ret = 0; + + mutex_lock(&buf->mutex); + if (buf->count == 0) { + ret = fill_buffer(buf); + if (ret != 0) { + mutex_unlock(&buf->mutex); + goto out; + } + } + mutex_unlock(&buf->mutex); + + ret = simple_read_from_buffer(user_buf, len, offset, + buf->page, buf->count); + +out: + return ret; } -static inline void remove_debug_files (struct admhcd *ahcd) +static int debug_close(struct inode *inode, struct file *file) { - struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev; + struct debug_buffer *buf = file->private_data; - class_device_remove_file(cldev, &class_device_attr_async); - class_device_remove_file(cldev, &class_device_attr_periodic); - class_device_remove_file(cldev, &class_device_attr_registers); + if (buf) { + if (buf->page) + free_page((unsigned long)buf->page); + kfree(buf); + } + + return 0; +} + +static int debug_async_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_periodic_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_periodic_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_registers_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_registers_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static inline void create_debug_files(struct admhcd *ahcd) +{ + struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self; + struct device *dev = bus->dev; + + ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root); + if (!ahcd->debug_dir) + goto dir_error; + + ahcd->debug_async = debugfs_create_file("async", S_IRUGO, + ahcd->debug_dir, dev, + &debug_async_fops); + if (!ahcd->debug_async) + goto async_error; + + ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO, + ahcd->debug_dir, dev, + &debug_periodic_fops); + if (!ahcd->debug_periodic) + goto periodic_error; + + ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO, + ahcd->debug_dir, dev, + &debug_registers_fops); + if (!ahcd->debug_registers) + goto registers_error; + + admhc_dbg(ahcd, "created debug files\n"); + return; + +registers_error: + debugfs_remove(ahcd->debug_periodic); +periodic_error: + debugfs_remove(ahcd->debug_async); +async_error: + debugfs_remove(ahcd->debug_dir); +dir_error: + ahcd->debug_periodic = NULL; + ahcd->debug_async = NULL; + ahcd->debug_dir = NULL; +} + +static inline void remove_debug_files(struct admhcd *ahcd) +{ + debugfs_remove(ahcd->debug_registers); + debugfs_remove(ahcd->debug_periodic); + debugfs_remove(ahcd->debug_async); + debugfs_remove(ahcd->debug_dir); } #endif /*-------------------------------------------------------------------------*/ -