Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * The USB Monitor, inspired by Dave Harding's USBMon. |
| 3 | * |
| 4 | * This is a text format reader. |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/list.h> |
| 9 | #include <linux/usb.h> |
| 10 | #include <linux/time.h> |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 11 | #include <linux/mutex.h> |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/uaccess.h> |
| 14 | |
| 15 | #include "usb_mon.h" |
| 16 | |
| 17 | /* |
| 18 | * No, we do not want arbitrarily long data strings. |
| 19 | * Use the binary interface if you want to capture bulk data! |
| 20 | */ |
| 21 | #define DATA_MAX 32 |
| 22 | |
| 23 | /* |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 24 | * Defined by USB 2.0 clause 9.3, table 9.2. |
| 25 | */ |
| 26 | #define SETUP_MAX 8 |
| 27 | |
| 28 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * This limit exists to prevent OOMs when the user process stops reading. |
Pete Zaitcev | 5b1c674 | 2006-06-09 20:10:10 -0700 | [diff] [blame] | 30 | * If usbmon were available to unprivileged processes, it might be open |
| 31 | * to a local DoS. But we have to keep to root in order to prevent |
| 32 | * password sniffing from HID devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 34 | #define EVENT_MAX (4*PAGE_SIZE / sizeof(struct mon_event_text)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 36 | /* |
| 37 | * Potentially unlimited number; we limit it for similar allocations. |
| 38 | * The usbfs limits this to 128, but we're not quite as generous. |
| 39 | */ |
| 40 | #define ISODESC_MAX 5 |
| 41 | |
| 42 | #define PRINTF_DFL 250 /* with 5 ISOs segs */ |
| 43 | |
| 44 | struct mon_iso_desc { |
| 45 | int status; |
| 46 | unsigned int offset; |
| 47 | unsigned int length; /* Unsigned here, signed in URB. Historic. */ |
| 48 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | struct mon_event_text { |
| 51 | struct list_head e_link; |
| 52 | int type; /* submit, complete, etc. */ |
| 53 | unsigned int pipe; /* Pipe */ |
| 54 | unsigned long id; /* From pointer, most of the time */ |
| 55 | unsigned int tstamp; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 56 | int busnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | int length; /* Depends on type: xfer length or act length */ |
| 58 | int status; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 59 | int interval; |
| 60 | int start_frame; |
| 61 | int error_count; |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 62 | char setup_flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | char data_flag; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 64 | int numdesc; /* Full number */ |
| 65 | struct mon_iso_desc isodesc[ISODESC_MAX]; |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 66 | unsigned char setup[SETUP_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned char data[DATA_MAX]; |
| 68 | }; |
| 69 | |
| 70 | #define SLAB_NAME_SZ 30 |
| 71 | struct mon_reader_text { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 72 | struct kmem_cache *e_slab; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | int nevents; |
| 74 | struct list_head e_list; |
| 75 | struct mon_reader r; /* In C, parent class can be placed anywhere */ |
| 76 | |
| 77 | wait_queue_head_t wait; |
| 78 | int printf_size; |
| 79 | char *printf_buf; |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 80 | struct mutex printf_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | char slab_name[SLAB_NAME_SZ]; |
| 83 | }; |
| 84 | |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 85 | static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */ |
| 86 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 87 | static void mon_text_ctor(void *, struct kmem_cache *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 89 | struct mon_text_ptr { |
| 90 | int cnt, limit; |
| 91 | char *pbuf; |
| 92 | }; |
| 93 | |
| 94 | static struct mon_event_text * |
| 95 | mon_text_read_wait(struct mon_reader_text *rp, struct file *file); |
| 96 | static void mon_text_read_head_t(struct mon_reader_text *rp, |
| 97 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 98 | static void mon_text_read_head_u(struct mon_reader_text *rp, |
| 99 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 100 | static void mon_text_read_statset(struct mon_reader_text *rp, |
| 101 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 102 | static void mon_text_read_intstat(struct mon_reader_text *rp, |
| 103 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 104 | static void mon_text_read_isostat(struct mon_reader_text *rp, |
| 105 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 106 | static void mon_text_read_isodesc(struct mon_reader_text *rp, |
| 107 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 108 | static void mon_text_read_data(struct mon_reader_text *rp, |
| 109 | struct mon_text_ptr *p, const struct mon_event_text *ep); |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* |
| 112 | * mon_text_submit |
| 113 | * mon_text_complete |
| 114 | * |
| 115 | * May be called from an interrupt. |
| 116 | * |
| 117 | * This is called with the whole mon_bus locked, so no additional lock. |
| 118 | */ |
| 119 | |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 120 | static inline char mon_text_get_setup(struct mon_event_text *ep, |
Alan Stern | 4d6cd48 | 2006-08-30 11:35:21 -0400 | [diff] [blame] | 121 | struct urb *urb, char ev_type, struct mon_bus *mbus) |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 122 | { |
| 123 | |
| 124 | if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') |
| 125 | return '-'; |
| 126 | |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 127 | if (urb->dev->bus->uses_dma && |
| 128 | (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { |
Pete Zaitcev | bc50651 | 2005-09-01 14:35:05 -0700 | [diff] [blame] | 129 | return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX); |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 130 | } |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 131 | if (urb->setup_packet == NULL) |
| 132 | return 'Z'; /* '0' would be not as pretty. */ |
| 133 | |
| 134 | memcpy(ep->setup, urb->setup_packet, SETUP_MAX); |
| 135 | return 0; |
| 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, |
Alan Stern | 4d6cd48 | 2006-08-30 11:35:21 -0400 | [diff] [blame] | 139 | int len, char ev_type, struct mon_bus *mbus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
| 141 | int pipe = urb->pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | if (len <= 0) |
| 144 | return 'L'; |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 145 | if (len >= DATA_MAX) |
| 146 | len = DATA_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Pete Zaitcev | b9b0942 | 2005-12-03 21:52:10 -0800 | [diff] [blame] | 148 | if (usb_pipein(pipe)) { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 149 | if (ev_type != 'C') |
Pete Zaitcev | b9b0942 | 2005-12-03 21:52:10 -0800 | [diff] [blame] | 150 | return '<'; |
| 151 | } else { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 152 | if (ev_type != 'S') |
Pete Zaitcev | b9b0942 | 2005-12-03 21:52:10 -0800 | [diff] [blame] | 153 | return '>'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 156 | /* |
| 157 | * The check to see if it's safe to poke at data has an enormous |
| 158 | * number of corner cases, but it seems that the following is |
| 159 | * more or less safe. |
| 160 | * |
Pete Zaitcev | 5b1c674 | 2006-06-09 20:10:10 -0700 | [diff] [blame] | 161 | * We do not even try to look at transfer_buffer, because it can |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 162 | * contain non-NULL garbage in case the upper level promised to |
| 163 | * set DMA for the HCD. |
| 164 | */ |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 165 | if (urb->dev->bus->uses_dma && |
| 166 | (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 167 | return mon_dmapeek(ep->data, urb->transfer_dma, len); |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 168 | } |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 169 | |
| 170 | if (urb->transfer_buffer == NULL) |
| 171 | return 'Z'; /* '0' would be not as pretty. */ |
| 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | memcpy(ep->data, urb->transfer_buffer, len); |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static inline unsigned int mon_get_timestamp(void) |
| 178 | { |
| 179 | struct timeval tval; |
| 180 | unsigned int stamp; |
| 181 | |
| 182 | do_gettimeofday(&tval); |
| 183 | stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s. */ |
| 184 | stamp = stamp * 1000000 + tval.tv_usec; |
| 185 | return stamp; |
| 186 | } |
| 187 | |
| 188 | static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, |
| 189 | char ev_type) |
| 190 | { |
| 191 | struct mon_event_text *ep; |
| 192 | unsigned int stamp; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 193 | struct usb_iso_packet_descriptor *fp; |
| 194 | struct mon_iso_desc *dp; |
| 195 | int i, ndesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | stamp = mon_get_timestamp(); |
| 198 | |
| 199 | if (rp->nevents >= EVENT_MAX || |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 200 | (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | rp->r.m_bus->cnt_text_lost++; |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | ep->type = ev_type; |
| 206 | ep->pipe = urb->pipe; |
| 207 | ep->id = (unsigned long) urb; |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 208 | ep->busnum = urb->dev->bus->busnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | ep->tstamp = stamp; |
| 210 | ep->length = (ev_type == 'S') ? |
| 211 | urb->transfer_buffer_length : urb->actual_length; |
| 212 | /* Collecting status makes debugging sense for submits, too */ |
| 213 | ep->status = urb->status; |
| 214 | |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 215 | if (usb_pipeint(urb->pipe)) { |
| 216 | ep->interval = urb->interval; |
| 217 | } else if (usb_pipeisoc(urb->pipe)) { |
| 218 | ep->interval = urb->interval; |
| 219 | ep->start_frame = urb->start_frame; |
| 220 | ep->error_count = urb->error_count; |
| 221 | } |
| 222 | ep->numdesc = urb->number_of_packets; |
| 223 | if (usb_pipeisoc(urb->pipe) && urb->number_of_packets > 0) { |
| 224 | if ((ndesc = urb->number_of_packets) > ISODESC_MAX) |
| 225 | ndesc = ISODESC_MAX; |
| 226 | fp = urb->iso_frame_desc; |
| 227 | dp = ep->isodesc; |
| 228 | for (i = 0; i < ndesc; i++) { |
| 229 | dp->status = fp->status; |
| 230 | dp->offset = fp->offset; |
| 231 | dp->length = (ev_type == 'S') ? |
| 232 | fp->length : fp->actual_length; |
| 233 | fp++; |
| 234 | dp++; |
| 235 | } |
| 236 | } |
| 237 | |
Alan Stern | 4d6cd48 | 2006-08-30 11:35:21 -0400 | [diff] [blame] | 238 | ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); |
| 239 | ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type, |
| 240 | rp->r.m_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | rp->nevents++; |
| 243 | list_add_tail(&ep->e_link, &rp->e_list); |
| 244 | wake_up(&rp->wait); |
| 245 | } |
| 246 | |
| 247 | static void mon_text_submit(void *data, struct urb *urb) |
| 248 | { |
| 249 | struct mon_reader_text *rp = data; |
| 250 | mon_text_event(rp, urb, 'S'); |
| 251 | } |
| 252 | |
| 253 | static void mon_text_complete(void *data, struct urb *urb) |
| 254 | { |
| 255 | struct mon_reader_text *rp = data; |
| 256 | mon_text_event(rp, urb, 'C'); |
| 257 | } |
| 258 | |
Pete Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 259 | static void mon_text_error(void *data, struct urb *urb, int error) |
| 260 | { |
| 261 | struct mon_reader_text *rp = data; |
| 262 | struct mon_event_text *ep; |
| 263 | |
| 264 | if (rp->nevents >= EVENT_MAX || |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 265 | (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) { |
Pete Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 266 | rp->r.m_bus->cnt_text_lost++; |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | ep->type = 'E'; |
| 271 | ep->pipe = urb->pipe; |
| 272 | ep->id = (unsigned long) urb; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 273 | ep->busnum = 0; |
Pete Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 274 | ep->tstamp = 0; |
| 275 | ep->length = 0; |
| 276 | ep->status = error; |
| 277 | |
| 278 | ep->setup_flag = '-'; |
| 279 | ep->data_flag = 'E'; |
| 280 | |
| 281 | rp->nevents++; |
| 282 | list_add_tail(&ep->e_link, &rp->e_list); |
| 283 | wake_up(&rp->wait); |
| 284 | } |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /* |
| 287 | * Fetch next event from the circular buffer. |
| 288 | */ |
| 289 | static struct mon_event_text *mon_text_fetch(struct mon_reader_text *rp, |
| 290 | struct mon_bus *mbus) |
| 291 | { |
| 292 | struct list_head *p; |
| 293 | unsigned long flags; |
| 294 | |
| 295 | spin_lock_irqsave(&mbus->lock, flags); |
| 296 | if (list_empty(&rp->e_list)) { |
| 297 | spin_unlock_irqrestore(&mbus->lock, flags); |
| 298 | return NULL; |
| 299 | } |
| 300 | p = rp->e_list.next; |
| 301 | list_del(p); |
| 302 | --rp->nevents; |
| 303 | spin_unlock_irqrestore(&mbus->lock, flags); |
| 304 | return list_entry(p, struct mon_event_text, e_link); |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | */ |
| 309 | static int mon_text_open(struct inode *inode, struct file *file) |
| 310 | { |
| 311 | struct mon_bus *mbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct mon_reader_text *rp; |
| 313 | int rc; |
| 314 | |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 315 | mutex_lock(&mon_lock); |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 316 | mbus = inode->i_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 318 | rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (rp == NULL) { |
| 320 | rc = -ENOMEM; |
| 321 | goto err_alloc; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | INIT_LIST_HEAD(&rp->e_list); |
| 324 | init_waitqueue_head(&rp->wait); |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 325 | mutex_init(&rp->printf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | rp->printf_size = PRINTF_DFL; |
| 328 | rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL); |
| 329 | if (rp->printf_buf == NULL) { |
| 330 | rc = -ENOMEM; |
| 331 | goto err_alloc_pr; |
| 332 | } |
| 333 | |
| 334 | rp->r.m_bus = mbus; |
| 335 | rp->r.r_data = rp; |
| 336 | rp->r.rnf_submit = mon_text_submit; |
Pete Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 337 | rp->r.rnf_error = mon_text_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | rp->r.rnf_complete = mon_text_complete; |
| 339 | |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 340 | snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | rp->e_slab = kmem_cache_create(rp->slab_name, |
| 342 | sizeof(struct mon_event_text), sizeof(long), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame^] | 343 | mon_text_ctor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | if (rp->e_slab == NULL) { |
| 345 | rc = -ENOMEM; |
| 346 | goto err_slab; |
| 347 | } |
| 348 | |
| 349 | mon_reader_add(mbus, &rp->r); |
| 350 | |
| 351 | file->private_data = rp; |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 352 | mutex_unlock(&mon_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return 0; |
| 354 | |
| 355 | // err_busy: |
| 356 | // kmem_cache_destroy(rp->e_slab); |
| 357 | err_slab: |
| 358 | kfree(rp->printf_buf); |
| 359 | err_alloc_pr: |
| 360 | kfree(rp); |
| 361 | err_alloc: |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 362 | mutex_unlock(&mon_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return rc; |
| 364 | } |
| 365 | |
| 366 | /* |
| 367 | * For simplicity, we read one record in one system call and throw out |
| 368 | * what does not fit. This means that the following does not work: |
| 369 | * dd if=/dbg/usbmon/0t bs=10 |
| 370 | * Also, we do not allow seeks and do not bother advancing the offset. |
| 371 | */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 372 | static ssize_t mon_text_read_t(struct file *file, char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | size_t nbytes, loff_t *ppos) |
| 374 | { |
| 375 | struct mon_reader_text *rp = file->private_data; |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 376 | struct mon_event_text *ep; |
| 377 | struct mon_text_ptr ptr; |
| 378 | |
| 379 | if (IS_ERR(ep = mon_text_read_wait(rp, file))) |
| 380 | return PTR_ERR(ep); |
| 381 | mutex_lock(&rp->printf_lock); |
| 382 | ptr.cnt = 0; |
| 383 | ptr.pbuf = rp->printf_buf; |
| 384 | ptr.limit = rp->printf_size; |
| 385 | |
| 386 | mon_text_read_head_t(rp, &ptr, ep); |
| 387 | mon_text_read_statset(rp, &ptr, ep); |
| 388 | ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, |
| 389 | " %d", ep->length); |
| 390 | mon_text_read_data(rp, &ptr, ep); |
| 391 | |
| 392 | if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) |
| 393 | ptr.cnt = -EFAULT; |
| 394 | mutex_unlock(&rp->printf_lock); |
| 395 | kmem_cache_free(rp->e_slab, ep); |
| 396 | return ptr.cnt; |
| 397 | } |
| 398 | |
| 399 | static ssize_t mon_text_read_u(struct file *file, char __user *buf, |
| 400 | size_t nbytes, loff_t *ppos) |
| 401 | { |
| 402 | struct mon_reader_text *rp = file->private_data; |
| 403 | struct mon_event_text *ep; |
| 404 | struct mon_text_ptr ptr; |
| 405 | |
| 406 | if (IS_ERR(ep = mon_text_read_wait(rp, file))) |
| 407 | return PTR_ERR(ep); |
| 408 | mutex_lock(&rp->printf_lock); |
| 409 | ptr.cnt = 0; |
| 410 | ptr.pbuf = rp->printf_buf; |
| 411 | ptr.limit = rp->printf_size; |
| 412 | |
| 413 | mon_text_read_head_u(rp, &ptr, ep); |
| 414 | if (ep->type == 'E') { |
| 415 | mon_text_read_statset(rp, &ptr, ep); |
| 416 | } else if (usb_pipeisoc(ep->pipe)) { |
| 417 | mon_text_read_isostat(rp, &ptr, ep); |
| 418 | mon_text_read_isodesc(rp, &ptr, ep); |
| 419 | } else if (usb_pipeint(ep->pipe)) { |
| 420 | mon_text_read_intstat(rp, &ptr, ep); |
| 421 | } else { |
| 422 | mon_text_read_statset(rp, &ptr, ep); |
| 423 | } |
| 424 | ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, |
| 425 | " %d", ep->length); |
| 426 | mon_text_read_data(rp, &ptr, ep); |
| 427 | |
| 428 | if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) |
| 429 | ptr.cnt = -EFAULT; |
| 430 | mutex_unlock(&rp->printf_lock); |
| 431 | kmem_cache_free(rp->e_slab, ep); |
| 432 | return ptr.cnt; |
| 433 | } |
| 434 | |
| 435 | static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp, |
| 436 | struct file *file) |
| 437 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | struct mon_bus *mbus = rp->r.m_bus; |
| 439 | DECLARE_WAITQUEUE(waita, current); |
| 440 | struct mon_event_text *ep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | add_wait_queue(&rp->wait, &waita); |
| 443 | set_current_state(TASK_INTERRUPTIBLE); |
| 444 | while ((ep = mon_text_fetch(rp, mbus)) == NULL) { |
| 445 | if (file->f_flags & O_NONBLOCK) { |
| 446 | set_current_state(TASK_RUNNING); |
| 447 | remove_wait_queue(&rp->wait, &waita); |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 448 | return ERR_PTR(-EWOULDBLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | /* |
| 451 | * We do not count nwaiters, because ->release is supposed |
| 452 | * to be called when all openers are gone only. |
| 453 | */ |
| 454 | schedule(); |
| 455 | if (signal_pending(current)) { |
| 456 | remove_wait_queue(&rp->wait, &waita); |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 457 | return ERR_PTR(-EINTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | set_current_state(TASK_INTERRUPTIBLE); |
| 460 | } |
| 461 | set_current_state(TASK_RUNNING); |
| 462 | remove_wait_queue(&rp->wait, &waita); |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 463 | return ep; |
| 464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 466 | static void mon_text_read_head_t(struct mon_reader_text *rp, |
| 467 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 468 | { |
| 469 | char udir, utype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | udir = usb_pipein(ep->pipe) ? 'i' : 'o'; |
| 472 | switch (usb_pipetype(ep->pipe)) { |
| 473 | case PIPE_ISOCHRONOUS: utype = 'Z'; break; |
| 474 | case PIPE_INTERRUPT: utype = 'I'; break; |
| 475 | case PIPE_CONTROL: utype = 'C'; break; |
| 476 | default: /* PIPE_BULK */ utype = 'B'; |
| 477 | } |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 478 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 479 | "%lx %u %c %c%c:%03u:%02u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | ep->id, ep->tstamp, ep->type, |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 481 | utype, udir, |
| 482 | usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe)); |
| 483 | } |
| 484 | |
| 485 | static void mon_text_read_head_u(struct mon_reader_text *rp, |
| 486 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 487 | { |
| 488 | char udir, utype; |
| 489 | |
| 490 | udir = usb_pipein(ep->pipe) ? 'i' : 'o'; |
| 491 | switch (usb_pipetype(ep->pipe)) { |
| 492 | case PIPE_ISOCHRONOUS: utype = 'Z'; break; |
| 493 | case PIPE_INTERRUPT: utype = 'I'; break; |
| 494 | case PIPE_CONTROL: utype = 'C'; break; |
| 495 | default: /* PIPE_BULK */ utype = 'B'; |
| 496 | } |
| 497 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 498 | "%lx %u %c %c%c:%d:%03u:%u", |
| 499 | ep->id, ep->tstamp, ep->type, |
| 500 | utype, udir, |
| 501 | ep->busnum, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe)); |
| 502 | } |
| 503 | |
| 504 | static void mon_text_read_statset(struct mon_reader_text *rp, |
| 505 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 506 | { |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 507 | |
| 508 | if (ep->setup_flag == 0) { /* Setup packet is present and captured */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 509 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 510 | " s %02x %02x %04x %04x %04x", |
| 511 | ep->setup[0], |
| 512 | ep->setup[1], |
| 513 | (ep->setup[3] << 8) | ep->setup[2], |
| 514 | (ep->setup[5] << 8) | ep->setup[4], |
| 515 | (ep->setup[7] << 8) | ep->setup[6]); |
| 516 | } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 517 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 518 | " %c __ __ ____ ____ ____", ep->setup_flag); |
| 519 | } else { /* No setup for this kind of URB */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 520 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 521 | " %d", ep->status); |
Pete Zaitcev | ae0d6cc | 2005-06-25 14:32:59 -0700 | [diff] [blame] | 522 | } |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void mon_text_read_intstat(struct mon_reader_text *rp, |
| 526 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 527 | { |
| 528 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 529 | " %d:%d", ep->status, ep->interval); |
| 530 | } |
| 531 | |
| 532 | static void mon_text_read_isostat(struct mon_reader_text *rp, |
| 533 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 534 | { |
| 535 | if (ep->type == 'S') { |
| 536 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 537 | " %d:%d:%d", ep->status, ep->interval, ep->start_frame); |
| 538 | } else { |
| 539 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 540 | " %d:%d:%d:%d", |
| 541 | ep->status, ep->interval, ep->start_frame, ep->error_count); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | static void mon_text_read_isodesc(struct mon_reader_text *rp, |
| 546 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 547 | { |
| 548 | int ndesc; /* Display this many */ |
| 549 | int i; |
| 550 | const struct mon_iso_desc *dp; |
| 551 | |
| 552 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 553 | " %d", ep->numdesc); |
| 554 | ndesc = ep->numdesc; |
| 555 | if (ndesc > ISODESC_MAX) |
| 556 | ndesc = ISODESC_MAX; |
| 557 | if (ndesc < 0) |
| 558 | ndesc = 0; |
| 559 | dp = ep->isodesc; |
| 560 | for (i = 0; i < ndesc; i++) { |
| 561 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 562 | " %d:%u:%u", dp->status, dp->offset, dp->length); |
| 563 | dp++; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | static void mon_text_read_data(struct mon_reader_text *rp, |
| 568 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
| 569 | { |
| 570 | int data_len, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | if ((data_len = ep->length) > 0) { |
| 573 | if (ep->data_flag == 0) { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 574 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 575 | " ="); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | if (data_len >= DATA_MAX) |
| 577 | data_len = DATA_MAX; |
| 578 | for (i = 0; i < data_len; i++) { |
| 579 | if (i % 4 == 0) { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 580 | p->cnt += snprintf(p->pbuf + p->cnt, |
| 581 | p->limit - p->cnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | " "); |
| 583 | } |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 584 | p->cnt += snprintf(p->pbuf + p->cnt, |
| 585 | p->limit - p->cnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | "%02x", ep->data[i]); |
| 587 | } |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 588 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
| 589 | "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } else { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 591 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | " %c\n", ep->data_flag); |
| 593 | } |
| 594 | } else { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 595 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static int mon_text_release(struct inode *inode, struct file *file) |
| 600 | { |
| 601 | struct mon_reader_text *rp = file->private_data; |
| 602 | struct mon_bus *mbus; |
| 603 | /* unsigned long flags; */ |
| 604 | struct list_head *p; |
| 605 | struct mon_event_text *ep; |
| 606 | |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 607 | mutex_lock(&mon_lock); |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 608 | mbus = inode->i_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | if (mbus->nreaders <= 0) { |
| 611 | printk(KERN_ERR TAG ": consistency error on close\n"); |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 612 | mutex_unlock(&mon_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | mon_reader_del(mbus, &rp->r); |
| 616 | |
| 617 | /* |
| 618 | * In theory, e_list is protected by mbus->lock. However, |
| 619 | * after mon_reader_del has finished, the following is the case: |
| 620 | * - we are not on reader list anymore, so new events won't be added; |
| 621 | * - whole mbus may be dropped if it was orphaned. |
| 622 | * So, we better not touch mbus. |
| 623 | */ |
| 624 | /* spin_lock_irqsave(&mbus->lock, flags); */ |
| 625 | while (!list_empty(&rp->e_list)) { |
| 626 | p = rp->e_list.next; |
| 627 | ep = list_entry(p, struct mon_event_text, e_link); |
| 628 | list_del(p); |
| 629 | --rp->nevents; |
| 630 | kmem_cache_free(rp->e_slab, ep); |
| 631 | } |
| 632 | /* spin_unlock_irqrestore(&mbus->lock, flags); */ |
| 633 | |
| 634 | kmem_cache_destroy(rp->e_slab); |
| 635 | kfree(rp->printf_buf); |
| 636 | kfree(rp); |
| 637 | |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 638 | mutex_unlock(&mon_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 642 | static const struct file_operations mon_fops_text_t = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | .owner = THIS_MODULE, |
| 644 | .open = mon_text_open, |
| 645 | .llseek = no_llseek, |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 646 | .read = mon_text_read_t, |
| 647 | .release = mon_text_release, |
| 648 | }; |
| 649 | |
| 650 | static const struct file_operations mon_fops_text_u = { |
| 651 | .owner = THIS_MODULE, |
| 652 | .open = mon_text_open, |
| 653 | .llseek = no_llseek, |
| 654 | .read = mon_text_read_u, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | .release = mon_text_release, |
| 656 | }; |
| 657 | |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 658 | int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus) |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 659 | { |
| 660 | struct dentry *d; |
| 661 | enum { NAMESZ = 10 }; |
| 662 | char name[NAMESZ]; |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 663 | int busnum = ubus? ubus->busnum: 0; |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 664 | int rc; |
| 665 | |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 666 | if (ubus != NULL) { |
| 667 | rc = snprintf(name, NAMESZ, "%dt", busnum); |
| 668 | if (rc <= 0 || rc >= NAMESZ) |
| 669 | goto err_print_t; |
| 670 | d = debugfs_create_file(name, 0600, mon_dir, mbus, |
| 671 | &mon_fops_text_t); |
| 672 | if (d == NULL) |
| 673 | goto err_create_t; |
| 674 | mbus->dent_t = d; |
| 675 | } |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 676 | |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 677 | rc = snprintf(name, NAMESZ, "%du", busnum); |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 678 | if (rc <= 0 || rc >= NAMESZ) |
| 679 | goto err_print_u; |
| 680 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_u); |
| 681 | if (d == NULL) |
| 682 | goto err_create_u; |
| 683 | mbus->dent_u = d; |
| 684 | |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 685 | rc = snprintf(name, NAMESZ, "%ds", busnum); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 686 | if (rc <= 0 || rc >= NAMESZ) |
| 687 | goto err_print_s; |
| 688 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat); |
| 689 | if (d == NULL) |
| 690 | goto err_create_s; |
| 691 | mbus->dent_s = d; |
| 692 | |
| 693 | return 1; |
| 694 | |
| 695 | err_create_s: |
| 696 | err_print_s: |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 697 | debugfs_remove(mbus->dent_u); |
| 698 | mbus->dent_u = NULL; |
| 699 | err_create_u: |
| 700 | err_print_u: |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 701 | if (ubus != NULL) { |
| 702 | debugfs_remove(mbus->dent_t); |
| 703 | mbus->dent_t = NULL; |
| 704 | } |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 705 | err_create_t: |
| 706 | err_print_t: |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | void mon_text_del(struct mon_bus *mbus) |
| 711 | { |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 712 | debugfs_remove(mbus->dent_u); |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 713 | if (mbus->dent_t != NULL) |
| 714 | debugfs_remove(mbus->dent_t); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 715 | debugfs_remove(mbus->dent_s); |
| 716 | } |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | /* |
| 719 | * Slab interface: constructor. |
| 720 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 721 | static void mon_text_ctor(void *mem, struct kmem_cache *slab, unsigned long sflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | /* |
| 724 | * Nothing to initialize. No, really! |
| 725 | * So, we fill it with garbage to emulate a reused object. |
| 726 | */ |
| 727 | memset(mem, 0xe5, sizeof(struct mon_event_text)); |
| 728 | } |
| 729 | |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 730 | int __init mon_text_init(void) |
| 731 | { |
| 732 | struct dentry *mondir; |
| 733 | |
| 734 | mondir = debugfs_create_dir("usbmon", NULL); |
| 735 | if (IS_ERR(mondir)) { |
| 736 | printk(KERN_NOTICE TAG ": debugfs is not available\n"); |
| 737 | return -ENODEV; |
| 738 | } |
| 739 | if (mondir == NULL) { |
| 740 | printk(KERN_NOTICE TAG ": unable to create usbmon directory\n"); |
| 741 | return -ENODEV; |
| 742 | } |
| 743 | mon_dir = mondir; |
| 744 | return 0; |
| 745 | } |
| 746 | |
Pete Zaitcev | 21641e3 | 2007-02-20 10:37:52 -0800 | [diff] [blame] | 747 | void mon_text_exit(void) |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 748 | { |
| 749 | debugfs_remove(mon_dir); |
| 750 | } |