mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
usbmon: bus zero
Add the "bus zero" feature to the usbmon. If a user process specifies bus with number zero, it receives events from all buses. This is useful when we wish to see initial enumeration when a bus is created, typically after a modprobe. Until now, an application had to loop until a new bus could be open, then start capturing on it. This procedure was cumbersome and could lose initial events. Also, often it's too bothersome to find exactly to which bus a specific device is attached. Paolo Albeni provided the original concept implementation. I added the handling of "bus->monitored" flag and generally fixed it up. Signed-off-by: Pete Zaitcev <zaitcev@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
35d07fd58f
commit
ecb658d387
4 changed files with 116 additions and 84 deletions
|
@ -356,8 +356,10 @@ static inline char mon_bin_get_setup(unsigned char *setupb,
|
||||||
if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
|
if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
|
||||||
return '-';
|
return '-';
|
||||||
|
|
||||||
if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)
|
if (urb->dev->bus->uses_dma &&
|
||||||
|
(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
|
||||||
return mon_dmapeek(setupb, urb->setup_dma, SETUP_LEN);
|
return mon_dmapeek(setupb, urb->setup_dma, SETUP_LEN);
|
||||||
|
}
|
||||||
if (urb->setup_packet == NULL)
|
if (urb->setup_packet == NULL)
|
||||||
return 'Z';
|
return 'Z';
|
||||||
|
|
||||||
|
@ -369,7 +371,8 @@ static char mon_bin_get_data(const struct mon_reader_bin *rp,
|
||||||
unsigned int offset, struct urb *urb, unsigned int length)
|
unsigned int offset, struct urb *urb, unsigned int length)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) {
|
if (urb->dev->bus->uses_dma &&
|
||||||
|
(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
|
||||||
mon_dmapeek_vec(rp, offset, urb->transfer_dma, length);
|
mon_dmapeek_vec(rp, offset, urb->transfer_dma, length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +443,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
|
||||||
/* We use the fact that usb_pipein() returns 0x80 */
|
/* We use the fact that usb_pipein() returns 0x80 */
|
||||||
ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe);
|
ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe);
|
||||||
ep->devnum = usb_pipedevice(urb->pipe);
|
ep->devnum = usb_pipedevice(urb->pipe);
|
||||||
ep->busnum = rp->r.m_bus->u_bus->busnum;
|
ep->busnum = urb->dev->bus->busnum;
|
||||||
ep->id = (unsigned long) urb;
|
ep->id = (unsigned long) urb;
|
||||||
ep->ts_sec = ts.tv_sec;
|
ep->ts_sec = ts.tv_sec;
|
||||||
ep->ts_usec = ts.tv_usec;
|
ep->ts_usec = ts.tv_usec;
|
||||||
|
@ -500,7 +503,7 @@ static void mon_bin_error(void *data, struct urb *urb, int error)
|
||||||
/* We use the fact that usb_pipein() returns 0x80 */
|
/* We use the fact that usb_pipein() returns 0x80 */
|
||||||
ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe);
|
ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe);
|
||||||
ep->devnum = usb_pipedevice(urb->pipe);
|
ep->devnum = usb_pipedevice(urb->pipe);
|
||||||
ep->busnum = rp->r.m_bus->u_bus->busnum;
|
ep->busnum = urb->dev->bus->busnum;
|
||||||
ep->id = (unsigned long) urb;
|
ep->id = (unsigned long) urb;
|
||||||
ep->status = error;
|
ep->status = error;
|
||||||
|
|
||||||
|
@ -515,7 +518,6 @@ static void mon_bin_error(void *data, struct urb *urb, int error)
|
||||||
static int mon_bin_open(struct inode *inode, struct file *file)
|
static int mon_bin_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
struct mon_bus *mbus;
|
struct mon_bus *mbus;
|
||||||
struct usb_bus *ubus;
|
|
||||||
struct mon_reader_bin *rp;
|
struct mon_reader_bin *rp;
|
||||||
size_t size;
|
size_t size;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -525,7 +527,7 @@ static int mon_bin_open(struct inode *inode, struct file *file)
|
||||||
mutex_unlock(&mon_lock);
|
mutex_unlock(&mon_lock);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
if ((ubus = mbus->u_bus) == NULL) {
|
if (mbus != &mon_bus0 && mbus->u_bus == NULL) {
|
||||||
printk(KERN_ERR TAG ": consistency error on open\n");
|
printk(KERN_ERR TAG ": consistency error on open\n");
|
||||||
mutex_unlock(&mon_lock);
|
mutex_unlock(&mon_lock);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
#include "usb_mon.h"
|
#include "usb_mon.h"
|
||||||
#include "../core/hcd.h"
|
#include "../core/hcd.h"
|
||||||
|
|
||||||
static void mon_submit(struct usb_bus *ubus, struct urb *urb);
|
|
||||||
static void mon_complete(struct usb_bus *ubus, struct urb *urb);
|
|
||||||
static void mon_stop(struct mon_bus *mbus);
|
static void mon_stop(struct mon_bus *mbus);
|
||||||
static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus);
|
static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus);
|
||||||
static void mon_bus_drop(struct kref *r);
|
static void mon_bus_drop(struct kref *r);
|
||||||
|
@ -25,6 +23,7 @@ static void mon_bus_init(struct usb_bus *ubus);
|
||||||
|
|
||||||
DEFINE_MUTEX(mon_lock);
|
DEFINE_MUTEX(mon_lock);
|
||||||
|
|
||||||
|
struct mon_bus mon_bus0; /* Pseudo bus meaning "all buses" */
|
||||||
static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */
|
static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -35,22 +34,19 @@ static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */
|
||||||
void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r)
|
void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct usb_bus *ubus;
|
struct list_head *p;
|
||||||
|
|
||||||
spin_lock_irqsave(&mbus->lock, flags);
|
spin_lock_irqsave(&mbus->lock, flags);
|
||||||
if (mbus->nreaders == 0) {
|
if (mbus->nreaders == 0) {
|
||||||
ubus = mbus->u_bus;
|
if (mbus == &mon_bus0) {
|
||||||
if (ubus->monitored) {
|
list_for_each (p, &mon_buses) {
|
||||||
/*
|
struct mon_bus *m1;
|
||||||
* Something is really broken, refuse to go on and
|
m1 = list_entry(p, struct mon_bus, bus_link);
|
||||||
* possibly corrupt ops pointers or worse.
|
m1->u_bus->monitored = 1;
|
||||||
*/
|
}
|
||||||
printk(KERN_ERR TAG ": bus %d is already monitored\n",
|
} else {
|
||||||
ubus->busnum);
|
mbus->u_bus->monitored = 1;
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
ubus->monitored = 1;
|
|
||||||
}
|
}
|
||||||
mbus->nreaders++;
|
mbus->nreaders++;
|
||||||
list_add_tail(&r->r_link, &mbus->r_list);
|
list_add_tail(&r->r_link, &mbus->r_list);
|
||||||
|
@ -80,77 +76,79 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
static void mon_submit(struct usb_bus *ubus, struct urb *urb)
|
static void mon_bus_submit(struct mon_bus *mbus, struct urb *urb)
|
||||||
{
|
{
|
||||||
struct mon_bus *mbus;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
struct mon_reader *r;
|
struct mon_reader *r;
|
||||||
|
|
||||||
mbus = ubus->mon_bus;
|
|
||||||
if (mbus == NULL)
|
|
||||||
goto out_unlocked;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&mbus->lock, flags);
|
spin_lock_irqsave(&mbus->lock, flags);
|
||||||
if (mbus->nreaders == 0)
|
|
||||||
goto out_locked;
|
|
||||||
|
|
||||||
mbus->cnt_events++;
|
mbus->cnt_events++;
|
||||||
list_for_each (pos, &mbus->r_list) {
|
list_for_each (pos, &mbus->r_list) {
|
||||||
r = list_entry(pos, struct mon_reader, r_link);
|
r = list_entry(pos, struct mon_reader, r_link);
|
||||||
r->rnf_submit(r->r_data, urb);
|
r->rnf_submit(r->r_data, urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
spin_unlock_irqrestore(&mbus->lock, flags);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
out_locked:
|
static void mon_submit(struct usb_bus *ubus, struct urb *urb)
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
{
|
||||||
out_unlocked:
|
struct mon_bus *mbus;
|
||||||
return;
|
|
||||||
|
if ((mbus = ubus->mon_bus) != NULL)
|
||||||
|
mon_bus_submit(mbus, urb);
|
||||||
|
mon_bus_submit(&mon_bus0, urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error)
|
static void mon_bus_submit_error(struct mon_bus *mbus, struct urb *urb, int error)
|
||||||
{
|
{
|
||||||
struct mon_bus *mbus;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
struct mon_reader *r;
|
struct mon_reader *r;
|
||||||
|
|
||||||
mbus = ubus->mon_bus;
|
|
||||||
if (mbus == NULL)
|
|
||||||
goto out_unlocked;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&mbus->lock, flags);
|
spin_lock_irqsave(&mbus->lock, flags);
|
||||||
if (mbus->nreaders == 0)
|
|
||||||
goto out_locked;
|
|
||||||
|
|
||||||
mbus->cnt_events++;
|
mbus->cnt_events++;
|
||||||
list_for_each (pos, &mbus->r_list) {
|
list_for_each (pos, &mbus->r_list) {
|
||||||
r = list_entry(pos, struct mon_reader, r_link);
|
r = list_entry(pos, struct mon_reader, r_link);
|
||||||
r->rnf_error(r->r_data, urb, error);
|
r->rnf_error(r->r_data, urb, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
spin_unlock_irqrestore(&mbus->lock, flags);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
out_locked:
|
static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error)
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
{
|
||||||
out_unlocked:
|
struct mon_bus *mbus;
|
||||||
return;
|
|
||||||
|
if ((mbus = ubus->mon_bus) != NULL)
|
||||||
|
mon_bus_submit_error(mbus, urb, error);
|
||||||
|
mon_bus_submit_error(&mon_bus0, urb, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
static void mon_complete(struct usb_bus *ubus, struct urb *urb)
|
static void mon_bus_complete(struct mon_bus *mbus, struct urb *urb)
|
||||||
{
|
{
|
||||||
struct mon_bus *mbus;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
struct mon_reader *r;
|
struct mon_reader *r;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&mbus->lock, flags);
|
||||||
|
mbus->cnt_events++;
|
||||||
|
list_for_each (pos, &mbus->r_list) {
|
||||||
|
r = list_entry(pos, struct mon_reader, r_link);
|
||||||
|
r->rnf_complete(r->r_data, urb);
|
||||||
|
}
|
||||||
|
spin_unlock_irqrestore(&mbus->lock, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mon_complete(struct usb_bus *ubus, struct urb *urb)
|
||||||
|
{
|
||||||
|
struct mon_bus *mbus;
|
||||||
|
|
||||||
mbus = ubus->mon_bus;
|
mbus = ubus->mon_bus;
|
||||||
if (mbus == NULL) {
|
if (mbus == NULL) {
|
||||||
/*
|
/*
|
||||||
|
@ -162,13 +160,8 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irqsave(&mbus->lock, flags);
|
mon_bus_complete(mbus, urb);
|
||||||
mbus->cnt_events++;
|
mon_bus_complete(&mon_bus0, urb);
|
||||||
list_for_each (pos, &mbus->r_list) {
|
|
||||||
r = list_entry(pos, struct mon_reader, r_link);
|
|
||||||
r->rnf_complete(r->r_data, urb);
|
|
||||||
}
|
|
||||||
spin_unlock_irqrestore(&mbus->lock, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int (*unlink_urb) (struct urb *urb, int status); */
|
/* int (*unlink_urb) (struct urb *urb, int status); */
|
||||||
|
@ -179,14 +172,26 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb)
|
||||||
static void mon_stop(struct mon_bus *mbus)
|
static void mon_stop(struct mon_bus *mbus)
|
||||||
{
|
{
|
||||||
struct usb_bus *ubus = mbus->u_bus;
|
struct usb_bus *ubus = mbus->u_bus;
|
||||||
|
struct list_head *p;
|
||||||
|
|
||||||
/*
|
if (mbus == &mon_bus0) {
|
||||||
* A stop can be called for a dissolved mon_bus in case of
|
list_for_each (p, &mon_buses) {
|
||||||
* a reader staying across an rmmod foo_hcd.
|
mbus = list_entry(p, struct mon_bus, bus_link);
|
||||||
*/
|
/*
|
||||||
if (ubus != NULL) {
|
* We do not change nreaders here, so rely on mon_lock.
|
||||||
ubus->monitored = 0;
|
*/
|
||||||
mb();
|
if (mbus->nreaders == 0 && (ubus = mbus->u_bus) != NULL)
|
||||||
|
ubus->monitored = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* A stop can be called for a dissolved mon_bus in case of
|
||||||
|
* a reader staying across an rmmod foo_hcd, so test ->u_bus.
|
||||||
|
*/
|
||||||
|
if (mon_bus0.nreaders == 0 && (ubus = mbus->u_bus) != NULL) {
|
||||||
|
ubus->monitored = 0;
|
||||||
|
mb();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +204,10 @@ static void mon_stop(struct mon_bus *mbus)
|
||||||
static void mon_bus_add(struct usb_bus *ubus)
|
static void mon_bus_add(struct usb_bus *ubus)
|
||||||
{
|
{
|
||||||
mon_bus_init(ubus);
|
mon_bus_init(ubus);
|
||||||
|
mutex_lock(&mon_lock);
|
||||||
|
if (mon_bus0.nreaders != 0)
|
||||||
|
ubus->monitored = 1;
|
||||||
|
mutex_unlock(&mon_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -250,12 +259,7 @@ static struct usb_mon_operations mon_ops_0 = {
|
||||||
static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus)
|
static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
* Never happens, but...
|
|
||||||
*/
|
|
||||||
if (ubus->monitored) {
|
if (ubus->monitored) {
|
||||||
printk(KERN_ERR TAG ": bus %d is dissolved while monitored\n",
|
|
||||||
ubus->busnum);
|
|
||||||
ubus->monitored = 0;
|
ubus->monitored = 0;
|
||||||
mb();
|
mb();
|
||||||
}
|
}
|
||||||
|
@ -263,6 +267,8 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus)
|
||||||
ubus->mon_bus = NULL;
|
ubus->mon_bus = NULL;
|
||||||
mbus->u_bus = NULL;
|
mbus->u_bus = NULL;
|
||||||
mb();
|
mb();
|
||||||
|
|
||||||
|
/* We want synchronize_irq() here, but that needs an argument. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -295,9 +301,8 @@ static void mon_bus_init(struct usb_bus *ubus)
|
||||||
*/
|
*/
|
||||||
mbus->u_bus = ubus;
|
mbus->u_bus = ubus;
|
||||||
ubus->mon_bus = mbus;
|
ubus->mon_bus = mbus;
|
||||||
mbus->uses_dma = ubus->uses_dma;
|
|
||||||
|
|
||||||
mbus->text_inited = mon_text_add(mbus, ubus);
|
mbus->text_inited = mon_text_add(mbus, ubus->busnum);
|
||||||
// mon_bin_add(...)
|
// mon_bin_add(...)
|
||||||
|
|
||||||
mutex_lock(&mon_lock);
|
mutex_lock(&mon_lock);
|
||||||
|
@ -309,6 +314,18 @@ static void mon_bus_init(struct usb_bus *ubus)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mon_bus0_init(void)
|
||||||
|
{
|
||||||
|
struct mon_bus *mbus = &mon_bus0;
|
||||||
|
|
||||||
|
kref_init(&mbus->ref);
|
||||||
|
spin_lock_init(&mbus->lock);
|
||||||
|
INIT_LIST_HEAD(&mbus->r_list);
|
||||||
|
|
||||||
|
mbus->text_inited = mon_text_add(mbus, 0);
|
||||||
|
// mbus->bin_inited = mon_bin_add(mbus, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search a USB bus by number. Notice that USB bus numbers start from one,
|
* Search a USB bus by number. Notice that USB bus numbers start from one,
|
||||||
* which we may later use to identify "all" with zero.
|
* which we may later use to identify "all" with zero.
|
||||||
|
@ -322,6 +339,9 @@ struct mon_bus *mon_bus_lookup(unsigned int num)
|
||||||
struct list_head *p;
|
struct list_head *p;
|
||||||
struct mon_bus *mbus;
|
struct mon_bus *mbus;
|
||||||
|
|
||||||
|
if (num == 0) {
|
||||||
|
return &mon_bus0;
|
||||||
|
}
|
||||||
list_for_each (p, &mon_buses) {
|
list_for_each (p, &mon_buses) {
|
||||||
mbus = list_entry(p, struct mon_bus, bus_link);
|
mbus = list_entry(p, struct mon_bus, bus_link);
|
||||||
if (mbus->u_bus->busnum == num) {
|
if (mbus->u_bus->busnum == num) {
|
||||||
|
@ -341,6 +361,8 @@ static int __init mon_init(void)
|
||||||
if ((rc = mon_bin_init()) != 0)
|
if ((rc = mon_bin_init()) != 0)
|
||||||
goto err_bin;
|
goto err_bin;
|
||||||
|
|
||||||
|
mon_bus0_init();
|
||||||
|
|
||||||
if (usb_mon_register(&mon_ops_0) != 0) {
|
if (usb_mon_register(&mon_ops_0) != 0) {
|
||||||
printk(KERN_NOTICE TAG ": unable to register with the core\n");
|
printk(KERN_NOTICE TAG ": unable to register with the core\n");
|
||||||
rc = -ENODEV;
|
rc = -ENODEV;
|
||||||
|
@ -374,6 +396,7 @@ static void __exit mon_exit(void)
|
||||||
usb_mon_deregister();
|
usb_mon_deregister();
|
||||||
|
|
||||||
mutex_lock(&mon_lock);
|
mutex_lock(&mon_lock);
|
||||||
|
|
||||||
while (!list_empty(&mon_buses)) {
|
while (!list_empty(&mon_buses)) {
|
||||||
p = mon_buses.next;
|
p = mon_buses.next;
|
||||||
mbus = list_entry(p, struct mon_bus, bus_link);
|
mbus = list_entry(p, struct mon_bus, bus_link);
|
||||||
|
@ -397,6 +420,11 @@ static void __exit mon_exit(void)
|
||||||
mon_dissolve(mbus, mbus->u_bus);
|
mon_dissolve(mbus, mbus->u_bus);
|
||||||
kref_put(&mbus->ref, mon_bus_drop);
|
kref_put(&mbus->ref, mon_bus_drop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbus = &mon_bus0;
|
||||||
|
if (mbus->text_inited)
|
||||||
|
mon_text_del(mbus);
|
||||||
|
|
||||||
mutex_unlock(&mon_lock);
|
mutex_unlock(&mon_lock);
|
||||||
|
|
||||||
mon_text_exit();
|
mon_text_exit();
|
||||||
|
|
|
@ -124,8 +124,10 @@ static inline char mon_text_get_setup(struct mon_event_text *ep,
|
||||||
if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
|
if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
|
||||||
return '-';
|
return '-';
|
||||||
|
|
||||||
if (mbus->uses_dma && (urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
|
if (urb->dev->bus->uses_dma &&
|
||||||
|
(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
|
||||||
return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX);
|
return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX);
|
||||||
|
}
|
||||||
if (urb->setup_packet == NULL)
|
if (urb->setup_packet == NULL)
|
||||||
return 'Z'; /* '0' would be not as pretty. */
|
return 'Z'; /* '0' would be not as pretty. */
|
||||||
|
|
||||||
|
@ -160,8 +162,10 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
|
||||||
* contain non-NULL garbage in case the upper level promised to
|
* contain non-NULL garbage in case the upper level promised to
|
||||||
* set DMA for the HCD.
|
* set DMA for the HCD.
|
||||||
*/
|
*/
|
||||||
if (mbus->uses_dma && (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
|
if (urb->dev->bus->uses_dma &&
|
||||||
|
(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
|
||||||
return mon_dmapeek(ep->data, urb->transfer_dma, len);
|
return mon_dmapeek(ep->data, urb->transfer_dma, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (urb->transfer_buffer == NULL)
|
if (urb->transfer_buffer == NULL)
|
||||||
return 'Z'; /* '0' would be not as pretty. */
|
return 'Z'; /* '0' would be not as pretty. */
|
||||||
|
@ -201,7 +205,7 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
|
||||||
ep->type = ev_type;
|
ep->type = ev_type;
|
||||||
ep->pipe = urb->pipe;
|
ep->pipe = urb->pipe;
|
||||||
ep->id = (unsigned long) urb;
|
ep->id = (unsigned long) urb;
|
||||||
ep->busnum = rp->r.m_bus->u_bus->busnum;
|
ep->busnum = urb->dev->bus->busnum;
|
||||||
ep->tstamp = stamp;
|
ep->tstamp = stamp;
|
||||||
ep->length = (ev_type == 'S') ?
|
ep->length = (ev_type == 'S') ?
|
||||||
urb->transfer_buffer_length : urb->actual_length;
|
urb->transfer_buffer_length : urb->actual_length;
|
||||||
|
@ -305,13 +309,11 @@ static struct mon_event_text *mon_text_fetch(struct mon_reader_text *rp,
|
||||||
static int mon_text_open(struct inode *inode, struct file *file)
|
static int mon_text_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
struct mon_bus *mbus;
|
struct mon_bus *mbus;
|
||||||
struct usb_bus *ubus;
|
|
||||||
struct mon_reader_text *rp;
|
struct mon_reader_text *rp;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
mutex_lock(&mon_lock);
|
mutex_lock(&mon_lock);
|
||||||
mbus = inode->i_private;
|
mbus = inode->i_private;
|
||||||
ubus = mbus->u_bus;
|
|
||||||
|
|
||||||
rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL);
|
rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL);
|
||||||
if (rp == NULL) {
|
if (rp == NULL) {
|
||||||
|
@ -335,8 +337,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
|
||||||
rp->r.rnf_error = mon_text_error;
|
rp->r.rnf_error = mon_text_error;
|
||||||
rp->r.rnf_complete = mon_text_complete;
|
rp->r.rnf_complete = mon_text_complete;
|
||||||
|
|
||||||
snprintf(rp->slab_name, SLAB_NAME_SZ, "mon%dt_%lx", ubus->busnum,
|
snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp);
|
||||||
(long)rp);
|
|
||||||
rp->e_slab = kmem_cache_create(rp->slab_name,
|
rp->e_slab = kmem_cache_create(rp->slab_name,
|
||||||
sizeof(struct mon_event_text), sizeof(long), 0,
|
sizeof(struct mon_event_text), sizeof(long), 0,
|
||||||
mon_text_ctor, NULL);
|
mon_text_ctor, NULL);
|
||||||
|
@ -654,14 +655,14 @@ static const struct file_operations mon_fops_text_u = {
|
||||||
.release = mon_text_release,
|
.release = mon_text_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
|
int mon_text_add(struct mon_bus *mbus, int busnum)
|
||||||
{
|
{
|
||||||
struct dentry *d;
|
struct dentry *d;
|
||||||
enum { NAMESZ = 10 };
|
enum { NAMESZ = 10 };
|
||||||
char name[NAMESZ];
|
char name[NAMESZ];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = snprintf(name, NAMESZ, "%dt", ubus->busnum);
|
rc = snprintf(name, NAMESZ, "%dt", busnum);
|
||||||
if (rc <= 0 || rc >= NAMESZ)
|
if (rc <= 0 || rc >= NAMESZ)
|
||||||
goto err_print_t;
|
goto err_print_t;
|
||||||
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_t);
|
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_t);
|
||||||
|
@ -669,7 +670,7 @@ int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
|
||||||
goto err_create_t;
|
goto err_create_t;
|
||||||
mbus->dent_t = d;
|
mbus->dent_t = d;
|
||||||
|
|
||||||
rc = snprintf(name, NAMESZ, "%du", ubus->busnum);
|
rc = snprintf(name, NAMESZ, "%du", busnum);
|
||||||
if (rc <= 0 || rc >= NAMESZ)
|
if (rc <= 0 || rc >= NAMESZ)
|
||||||
goto err_print_u;
|
goto err_print_u;
|
||||||
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_u);
|
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_u);
|
||||||
|
@ -677,7 +678,7 @@ int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
|
||||||
goto err_create_u;
|
goto err_create_u;
|
||||||
mbus->dent_u = d;
|
mbus->dent_u = d;
|
||||||
|
|
||||||
rc = snprintf(name, NAMESZ, "%ds", ubus->busnum);
|
rc = snprintf(name, NAMESZ, "%ds", busnum);
|
||||||
if (rc <= 0 || rc >= NAMESZ)
|
if (rc <= 0 || rc >= NAMESZ)
|
||||||
goto err_print_s;
|
goto err_print_s;
|
||||||
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat);
|
d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat);
|
||||||
|
|
|
@ -23,7 +23,6 @@ struct mon_bus {
|
||||||
struct dentry *dent_s; /* Debugging file */
|
struct dentry *dent_s; /* Debugging file */
|
||||||
struct dentry *dent_t; /* Text interface file */
|
struct dentry *dent_t; /* Text interface file */
|
||||||
struct dentry *dent_u; /* Second text interface file */
|
struct dentry *dent_u; /* Second text interface file */
|
||||||
int uses_dma;
|
|
||||||
|
|
||||||
/* Ref */
|
/* Ref */
|
||||||
int nreaders; /* Under mon_lock AND mbus->lock */
|
int nreaders; /* Under mon_lock AND mbus->lock */
|
||||||
|
@ -53,7 +52,7 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
|
||||||
|
|
||||||
struct mon_bus *mon_bus_lookup(unsigned int num);
|
struct mon_bus *mon_bus_lookup(unsigned int num);
|
||||||
|
|
||||||
int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
|
int /*bool*/ mon_text_add(struct mon_bus *mbus, int busnum);
|
||||||
void mon_text_del(struct mon_bus *mbus);
|
void mon_text_del(struct mon_bus *mbus);
|
||||||
// void mon_bin_add(struct mon_bus *);
|
// void mon_bin_add(struct mon_bus *);
|
||||||
|
|
||||||
|
@ -82,4 +81,6 @@ extern struct mutex mon_lock;
|
||||||
|
|
||||||
extern const struct file_operations mon_fops_stat;
|
extern const struct file_operations mon_fops_stat;
|
||||||
|
|
||||||
|
extern struct mon_bus mon_bus0; /* Only for redundant checks */
|
||||||
|
|
||||||
#endif /* __USB_MON_H */
|
#endif /* __USB_MON_H */
|
||||||
|
|
Loading…
Reference in a new issue