7 #include <linux/kernel.h>
8 #include <linux/list.h>
10 #include <linux/slab.h>
11 #include <linux/time.h>
12 #include <linux/export.h>
16 #include <asm/uaccess.h>
37 #define EVENT_MAX (4*PAGE_SIZE / sizeof(struct mon_event_text))
45 #define PRINTF_DFL 250
76 #define SLAB_NAME_SZ 30
91 static struct dentry *mon_dir;
93 static void mon_text_ctor(
void *);
133 if (urb->setup_packet ==
NULL)
140 static inline char mon_text_get_data(
struct mon_event_text *ep,
struct urb *urb,
141 int len,
char ev_type,
struct mon_bus *mbus)
158 if (urb->num_sgs == 0) {
159 src = urb->transfer_buffer;
165 if (PageHighMem(sg_page(sg)))
177 static inline unsigned int mon_get_timestamp(
void)
183 stamp = tval.tv_sec & 0xFFF;
184 stamp = stamp * 1000000 + tval.tv_usec;
193 struct usb_iso_packet_descriptor *
fp;
197 stamp = mon_get_timestamp();
201 rp->
r.m_bus->cnt_text_lost++;
206 ep->
id = (
unsigned long) urb;
207 ep->
busnum = urb->dev->bus->busnum;
208 ep->
devnum = urb->dev->devnum;
209 ep->
epnum = usb_endpoint_num(&urb->ep->desc);
210 ep->
xfertype = usb_endpoint_type(&urb->ep->desc);
211 ep->
is_in = usb_urb_dir_in(urb);
213 ep->
length = (ev_type ==
'S') ?
214 urb->transfer_buffer_length : urb->actual_length;
225 ep->
numdesc = urb->number_of_packets;
227 urb->number_of_packets > 0) {
228 if ((ndesc = urb->number_of_packets) >
ISODESC_MAX)
230 fp = urb->iso_frame_desc;
232 for (i = 0; i <
ndesc; i++) {
235 dp->
length = (ev_type ==
'S') ?
236 fp->length : fp->actual_length;
242 ep->
length = urb->transfer_buffer_length;
245 ep->
setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->
r.m_bus);
254 static void mon_text_submit(
void *
data,
struct urb *urb)
260 static void mon_text_complete(
void *
data,
struct urb *urb,
int status)
263 mon_text_event(rp, urb,
'C', status);
266 static void mon_text_error(
void *
data,
struct urb *urb,
int error)
273 rp->
r.m_bus->cnt_text_lost++;
278 ep->
id = (
unsigned long) urb;
279 ep->
busnum = urb->dev->bus->busnum;
280 ep->
devnum = urb->dev->devnum;
281 ep->
epnum = usb_endpoint_num(&urb->ep->desc);
282 ep->
xfertype = usb_endpoint_type(&urb->ep->desc);
283 ep->
is_in = usb_urb_dir_in(urb);
284 ep->
tstamp = mon_get_timestamp();
306 if (list_empty(&rp->
e_list)) {
307 spin_unlock_irqrestore(&mbus->
lock, flags);
313 spin_unlock_irqrestore(&mbus->
lock, flags);
333 INIT_LIST_HEAD(&rp->
e_list);
346 rp->
r.rnf_submit = mon_text_submit;
347 rp->
r.rnf_error = mon_text_error;
348 rp->
r.rnf_complete = mon_text_complete;
382 static ssize_t mon_text_read_t(
struct file *file,
char __user *
buf,
383 size_t nbytes, loff_t *ppos)
389 if (IS_ERR(ep = mon_text_read_wait(rp, file)))
396 mon_text_read_head_t(rp, &
ptr, ep);
397 mon_text_read_statset(rp, &
ptr, ep);
400 mon_text_read_data(rp, &
ptr, ep);
409 static ssize_t mon_text_read_u(
struct file *file,
char __user *buf,
410 size_t nbytes, loff_t *ppos)
416 if (IS_ERR(ep = mon_text_read_wait(rp, file)))
423 mon_text_read_head_u(rp, &
ptr, ep);
424 if (ep->
type ==
'E') {
425 mon_text_read_statset(rp, &
ptr, ep);
427 mon_text_read_isostat(rp, &
ptr, ep);
428 mon_text_read_isodesc(rp, &
ptr, ep);
430 mon_text_read_intstat(rp, &
ptr, ep);
432 mon_text_read_statset(rp, &
ptr, ep);
436 mon_text_read_data(rp, &
ptr, ep);
454 while ((ep = mon_text_fetch(rp, mbus)) ==
NULL) {
467 return ERR_PTR(-
EINTR);
481 udir = (ep->
is_in ?
'i' :
'o');
486 default: utype =
'B';
489 "%lx %u %c %c%c:%03u:%02u",
499 udir = (ep->
is_in ?
'i' :
'o');
504 default: utype =
'B';
507 "%lx %u %c %c%c:%d:%03u:%u",
518 " s %02x %02x %04x %04x %04x",
543 if (ep->
type ==
'S') {
568 for (i = 0; i <
ndesc; i++) {
580 if ((data_len = ep->
length) > 0) {
594 "%02x", ep->
data[i]);
607 static int mon_text_release(
struct inode *inode,
struct file *file)
633 while (!list_empty(&rp->
e_list)) {
652 .open = mon_text_open,
654 .read = mon_text_read_t,
655 .release = mon_text_release,
660 .open = mon_text_open,
662 .read = mon_text_read_u,
663 .release = mon_text_release,
669 enum { NAMESZ = 10 };
671 int busnum = ubus? ubus->busnum: 0;
678 rc =
snprintf(name, NAMESZ,
"%dt", busnum);
688 rc =
snprintf(name, NAMESZ,
"%du", busnum);
696 rc =
snprintf(name, NAMESZ,
"%ds", busnum);
732 static void mon_text_ctor(
void *
mem)
746 if (IS_ERR(mondir)) {
750 if (mondir ==
NULL) {