blob: f68ad6d99ad7563581919fb024c37a4c5259a6e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * The USB Monitor, inspired by Dave Harding's USBMon.
Pete Zaitcevda5ca002005-08-16 15:16:46 -07003 *
4 * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
7#ifndef __USB_MON_H
8#define __USB_MON_H
9
10#include <linux/list.h>
11#include <linux/slab.h>
12#include <linux/kref.h>
13/* #include <linux/usb.h> */ /* We use struct pointers only in this header */
14
15#define TAG "usbmon"
16
17struct mon_bus {
18 struct list_head bus_link;
19 spinlock_t lock;
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080020 struct usb_bus *u_bus;
21
22 int text_inited;
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070023 int bin_inited;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 struct dentry *dent_s; /* Debugging file */
25 struct dentry *dent_t; /* Text interface file */
Pete Zaitcevf1c9e302007-02-24 19:27:33 -080026 struct dentry *dent_u; /* Second text interface file */
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070027 struct device *classdev; /* Device in usbmon class */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 /* Ref */
30 int nreaders; /* Under mon_lock AND mbus->lock */
31 struct list_head r_list; /* Chain of readers (usually one) */
32 struct kref ref; /* Under mon_lock */
33
34 /* Stats */
Pete Zaitcev5b1c6742006-06-09 20:10:10 -070035 unsigned int cnt_events;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 unsigned int cnt_text_lost;
37};
38
39/*
40 * An instance of a process which opened a file (but can fork later)
41 */
42struct mon_reader {
43 struct list_head r_link;
44 struct mon_bus *m_bus;
45 void *r_data; /* Use container_of instead? */
46
47 void (*rnf_submit)(void *data, struct urb *urb);
Pete Zaitcev12e72fe2006-06-09 22:03:32 -070048 void (*rnf_error)(void *data, struct urb *urb, int error);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 void (*rnf_complete)(void *data, struct urb *urb);
50};
51
52void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
53void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
54
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080055struct mon_bus *mon_bus_lookup(unsigned int num);
56
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070057int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080058void mon_text_del(struct mon_bus *mbus);
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070059int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
60void mon_bin_del(struct mon_bus *mbus);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080061
62int __init mon_text_init(void);
Pete Zaitcev21641e32007-02-20 10:37:52 -080063void mon_text_exit(void);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080064int __init mon_bin_init(void);
Pete Zaitcev21641e32007-02-20 10:37:52 -080065void mon_bin_exit(void);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080066
Pete Zaitcev02568392005-08-15 16:53:57 -070067/*
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080068 * DMA interface.
69 *
70 * XXX The vectored side needs a serious re-thinking. Abstracting vectors,
71 * like in Paolo's original patch, produces a double pkmap. We need an idea.
72*/
Pete Zaitcev02568392005-08-15 16:53:57 -070073extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
74
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080075struct mon_reader_bin;
76extern void mon_dmapeek_vec(const struct mon_reader_bin *rp,
77 unsigned int offset, dma_addr_t dma_addr, unsigned int len);
78extern unsigned int mon_copy_to_buff(const struct mon_reader_bin *rp,
79 unsigned int offset, const unsigned char *from, unsigned int len);
80
81/*
82 */
Arjan van de Ven4186ecf2006-01-11 15:55:29 +010083extern struct mutex mon_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -030085extern const struct file_operations mon_fops_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Pete Zaitcevecb658d2007-04-11 13:47:26 -070087extern struct mon_bus mon_bus0; /* Only for redundant checks */
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#endif /* __USB_MON_H */