Lines Matching +full:x +full:- +full:rp
1 // SPDX-License-Identifier: GPL-2.0
106 mon_text_read_wait(struct mon_reader_text *rp, struct file *file);
107 static void mon_text_read_head_t(struct mon_reader_text *rp,
109 static void mon_text_read_head_u(struct mon_reader_text *rp,
111 static void mon_text_read_statset(struct mon_reader_text *rp,
113 static void mon_text_read_intstat(struct mon_reader_text *rp,
115 static void mon_text_read_isostat(struct mon_reader_text *rp,
117 static void mon_text_read_isodesc(struct mon_reader_text *rp,
119 static void mon_text_read_data(struct mon_reader_text *rp,
135 if (ep->xfertype != USB_ENDPOINT_XFER_CONTROL || ev_type != 'S') in mon_text_get_setup()
136 return '-'; in mon_text_get_setup()
138 if (urb->setup_packet == NULL) in mon_text_get_setup()
141 memcpy(ep->setup, urb->setup_packet, SETUP_MAX); in mon_text_get_setup()
155 if (ep->is_in) { in mon_text_get_data()
163 if (urb->num_sgs == 0) { in mon_text_get_data()
164 src = urb->transfer_buffer; in mon_text_get_data()
168 struct scatterlist *sg = urb->sg; in mon_text_get_data()
174 len = min_t(int, sg->length, len); in mon_text_get_data()
178 memcpy(ep->data, src, len); in mon_text_get_data()
193 static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, in mon_text_event() argument
204 if (rp->nevents >= EVENT_MAX || in mon_text_event()
205 (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) { in mon_text_event()
206 rp->r.m_bus->cnt_text_lost++; in mon_text_event()
210 ep->type = ev_type; in mon_text_event()
211 ep->id = (unsigned long) urb; in mon_text_event()
212 ep->busnum = urb->dev->bus->busnum; in mon_text_event()
213 ep->devnum = urb->dev->devnum; in mon_text_event()
214 ep->epnum = usb_endpoint_num(&urb->ep->desc); in mon_text_event()
215 ep->xfertype = usb_endpoint_type(&urb->ep->desc); in mon_text_event()
216 ep->is_in = usb_urb_dir_in(urb); in mon_text_event()
217 ep->tstamp = stamp; in mon_text_event()
218 ep->length = (ev_type == 'S') ? in mon_text_event()
219 urb->transfer_buffer_length : urb->actual_length; in mon_text_event()
221 ep->status = status; in mon_text_event()
223 if (ep->xfertype == USB_ENDPOINT_XFER_INT) { in mon_text_event()
224 ep->interval = urb->interval; in mon_text_event()
225 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) { in mon_text_event()
226 ep->interval = urb->interval; in mon_text_event()
227 ep->start_frame = urb->start_frame; in mon_text_event()
228 ep->error_count = urb->error_count; in mon_text_event()
230 ep->numdesc = urb->number_of_packets; in mon_text_event()
231 if (ep->xfertype == USB_ENDPOINT_XFER_ISOC && in mon_text_event()
232 urb->number_of_packets > 0) { in mon_text_event()
233 if ((ndesc = urb->number_of_packets) > ISODESC_MAX) in mon_text_event()
235 fp = urb->iso_frame_desc; in mon_text_event()
236 dp = ep->isodesc; in mon_text_event()
238 dp->status = fp->status; in mon_text_event()
239 dp->offset = fp->offset; in mon_text_event()
240 dp->length = (ev_type == 'S') ? in mon_text_event()
241 fp->length : fp->actual_length; in mon_text_event()
247 ep->length = urb->transfer_buffer_length; in mon_text_event()
250 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); in mon_text_event()
251 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type, in mon_text_event()
252 rp->r.m_bus); in mon_text_event()
254 rp->nevents++; in mon_text_event()
255 list_add_tail(&ep->e_link, &rp->e_list); in mon_text_event()
256 wake_up(&rp->wait); in mon_text_event()
261 struct mon_reader_text *rp = data; in mon_text_submit() local
262 mon_text_event(rp, urb, 'S', -EINPROGRESS); in mon_text_submit()
267 struct mon_reader_text *rp = data; in mon_text_complete() local
268 mon_text_event(rp, urb, 'C', status); in mon_text_complete()
273 struct mon_reader_text *rp = data; in mon_text_error() local
276 if (rp->nevents >= EVENT_MAX || in mon_text_error()
277 (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) { in mon_text_error()
278 rp->r.m_bus->cnt_text_lost++; in mon_text_error()
282 ep->type = 'E'; in mon_text_error()
283 ep->id = (unsigned long) urb; in mon_text_error()
284 ep->busnum = urb->dev->bus->busnum; in mon_text_error()
285 ep->devnum = urb->dev->devnum; in mon_text_error()
286 ep->epnum = usb_endpoint_num(&urb->ep->desc); in mon_text_error()
287 ep->xfertype = usb_endpoint_type(&urb->ep->desc); in mon_text_error()
288 ep->is_in = usb_urb_dir_in(urb); in mon_text_error()
289 ep->tstamp = mon_get_timestamp(); in mon_text_error()
290 ep->length = 0; in mon_text_error()
291 ep->status = error; in mon_text_error()
293 ep->setup_flag = '-'; in mon_text_error()
294 ep->data_flag = 'E'; in mon_text_error()
296 rp->nevents++; in mon_text_error()
297 list_add_tail(&ep->e_link, &rp->e_list); in mon_text_error()
298 wake_up(&rp->wait); in mon_text_error()
304 static struct mon_event_text *mon_text_fetch(struct mon_reader_text *rp, in mon_text_fetch() argument
310 spin_lock_irqsave(&mbus->lock, flags); in mon_text_fetch()
311 if (list_empty(&rp->e_list)) { in mon_text_fetch()
312 spin_unlock_irqrestore(&mbus->lock, flags); in mon_text_fetch()
315 p = rp->e_list.next; in mon_text_fetch()
317 --rp->nevents; in mon_text_fetch()
318 spin_unlock_irqrestore(&mbus->lock, flags); in mon_text_fetch()
327 struct mon_reader_text *rp; in mon_text_open() local
331 mbus = inode->i_private; in mon_text_open()
333 rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL); in mon_text_open()
334 if (rp == NULL) { in mon_text_open()
335 rc = -ENOMEM; in mon_text_open()
338 INIT_LIST_HEAD(&rp->e_list); in mon_text_open()
339 init_waitqueue_head(&rp->wait); in mon_text_open()
340 mutex_init(&rp->printf_lock); in mon_text_open()
342 rp->printf_size = PRINTF_DFL; in mon_text_open()
343 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL); in mon_text_open()
344 if (rp->printf_buf == NULL) { in mon_text_open()
345 rc = -ENOMEM; in mon_text_open()
349 rp->r.m_bus = mbus; in mon_text_open()
350 rp->r.r_data = rp; in mon_text_open()
351 rp->r.rnf_submit = mon_text_submit; in mon_text_open()
352 rp->r.rnf_error = mon_text_error; in mon_text_open()
353 rp->r.rnf_complete = mon_text_complete; in mon_text_open()
355 snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp); in mon_text_open()
356 rp->e_slab = kmem_cache_create(rp->slab_name, in mon_text_open()
359 if (rp->e_slab == NULL) { in mon_text_open()
360 rc = -ENOMEM; in mon_text_open()
364 mon_reader_add(mbus, &rp->r); in mon_text_open()
366 file->private_data = rp; in mon_text_open()
371 // kmem_cache_destroy(rp->e_slab); in mon_text_open()
373 kfree(rp->printf_buf); in mon_text_open()
375 kfree(rp); in mon_text_open()
381 static ssize_t mon_text_copy_to_user(struct mon_reader_text *rp, in mon_text_copy_to_user() argument
384 const size_t togo = min(nbytes, rp->printf_togo); in mon_text_copy_to_user()
386 if (copy_to_user(buf, &rp->printf_buf[rp->printf_offset], togo)) in mon_text_copy_to_user()
387 return -EFAULT; in mon_text_copy_to_user()
388 rp->printf_togo -= togo; in mon_text_copy_to_user()
389 rp->printf_offset += togo; in mon_text_copy_to_user()
397 struct mon_reader_text *rp = file->private_data; in mon_text_read_t() local
402 mutex_lock(&rp->printf_lock); in mon_text_read_t()
404 if (rp->printf_togo == 0) { in mon_text_read_t()
406 ep = mon_text_read_wait(rp, file); in mon_text_read_t()
408 mutex_unlock(&rp->printf_lock); in mon_text_read_t()
412 ptr.pbuf = rp->printf_buf; in mon_text_read_t()
413 ptr.limit = rp->printf_size; in mon_text_read_t()
415 mon_text_read_head_t(rp, &ptr, ep); in mon_text_read_t()
416 mon_text_read_statset(rp, &ptr, ep); in mon_text_read_t()
417 ptr.cnt += scnprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, in mon_text_read_t()
418 " %d", ep->length); in mon_text_read_t()
419 mon_text_read_data(rp, &ptr, ep); in mon_text_read_t()
421 rp->printf_togo = ptr.cnt; in mon_text_read_t()
422 rp->printf_offset = 0; in mon_text_read_t()
424 kmem_cache_free(rp->e_slab, ep); in mon_text_read_t()
427 ret = mon_text_copy_to_user(rp, buf, nbytes); in mon_text_read_t()
428 mutex_unlock(&rp->printf_lock); in mon_text_read_t()
436 struct mon_reader_text *rp = file->private_data; in mon_text_read_u() local
441 mutex_lock(&rp->printf_lock); in mon_text_read_u()
443 if (rp->printf_togo == 0) { in mon_text_read_u()
445 ep = mon_text_read_wait(rp, file); in mon_text_read_u()
447 mutex_unlock(&rp->printf_lock); in mon_text_read_u()
451 ptr.pbuf = rp->printf_buf; in mon_text_read_u()
452 ptr.limit = rp->printf_size; in mon_text_read_u()
454 mon_text_read_head_u(rp, &ptr, ep); in mon_text_read_u()
455 if (ep->type == 'E') { in mon_text_read_u()
456 mon_text_read_statset(rp, &ptr, ep); in mon_text_read_u()
457 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) { in mon_text_read_u()
458 mon_text_read_isostat(rp, &ptr, ep); in mon_text_read_u()
459 mon_text_read_isodesc(rp, &ptr, ep); in mon_text_read_u()
460 } else if (ep->xfertype == USB_ENDPOINT_XFER_INT) { in mon_text_read_u()
461 mon_text_read_intstat(rp, &ptr, ep); in mon_text_read_u()
463 mon_text_read_statset(rp, &ptr, ep); in mon_text_read_u()
465 ptr.cnt += scnprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, in mon_text_read_u()
466 " %d", ep->length); in mon_text_read_u()
467 mon_text_read_data(rp, &ptr, ep); in mon_text_read_u()
469 rp->printf_togo = ptr.cnt; in mon_text_read_u()
470 rp->printf_offset = 0; in mon_text_read_u()
472 kmem_cache_free(rp->e_slab, ep); in mon_text_read_u()
475 ret = mon_text_copy_to_user(rp, buf, nbytes); in mon_text_read_u()
476 mutex_unlock(&rp->printf_lock); in mon_text_read_u()
480 static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp, in mon_text_read_wait() argument
483 struct mon_bus *mbus = rp->r.m_bus; in mon_text_read_wait()
487 add_wait_queue(&rp->wait, &waita); in mon_text_read_wait()
489 while ((ep = mon_text_fetch(rp, mbus)) == NULL) { in mon_text_read_wait()
490 if (file->f_flags & O_NONBLOCK) { in mon_text_read_wait()
492 remove_wait_queue(&rp->wait, &waita); in mon_text_read_wait()
493 return ERR_PTR(-EWOULDBLOCK); in mon_text_read_wait()
496 * We do not count nwaiters, because ->release is supposed in mon_text_read_wait()
501 remove_wait_queue(&rp->wait, &waita); in mon_text_read_wait()
502 return ERR_PTR(-EINTR); in mon_text_read_wait()
507 remove_wait_queue(&rp->wait, &waita); in mon_text_read_wait()
511 static void mon_text_read_head_t(struct mon_reader_text *rp, in mon_text_read_head_t() argument
516 udir = (ep->is_in ? 'i' : 'o'); in mon_text_read_head_t()
517 switch (ep->xfertype) { in mon_text_read_head_t()
523 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_head_t()
525 ep->id, ep->tstamp, ep->type, in mon_text_read_head_t()
526 utype, udir, ep->devnum, ep->epnum); in mon_text_read_head_t()
529 static void mon_text_read_head_u(struct mon_reader_text *rp, in mon_text_read_head_u() argument
534 udir = (ep->is_in ? 'i' : 'o'); in mon_text_read_head_u()
535 switch (ep->xfertype) { in mon_text_read_head_u()
541 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_head_u()
543 ep->id, ep->tstamp, ep->type, in mon_text_read_head_u()
544 utype, udir, ep->busnum, ep->devnum, ep->epnum); in mon_text_read_head_u()
547 static void mon_text_read_statset(struct mon_reader_text *rp, in mon_text_read_statset() argument
551 if (ep->setup_flag == 0) { /* Setup packet is present and captured */ in mon_text_read_statset()
552 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_statset()
553 " s %02x %02x %04x %04x %04x", in mon_text_read_statset()
554 ep->setup[0], in mon_text_read_statset()
555 ep->setup[1], in mon_text_read_statset()
556 (ep->setup[3] << 8) | ep->setup[2], in mon_text_read_statset()
557 (ep->setup[5] << 8) | ep->setup[4], in mon_text_read_statset()
558 (ep->setup[7] << 8) | ep->setup[6]); in mon_text_read_statset()
559 } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */ in mon_text_read_statset()
560 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_statset()
561 " %c __ __ ____ ____ ____", ep->setup_flag); in mon_text_read_statset()
563 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_statset()
564 " %d", ep->status); in mon_text_read_statset()
568 static void mon_text_read_intstat(struct mon_reader_text *rp, in mon_text_read_intstat() argument
571 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_intstat()
572 " %d:%d", ep->status, ep->interval); in mon_text_read_intstat()
575 static void mon_text_read_isostat(struct mon_reader_text *rp, in mon_text_read_isostat() argument
578 if (ep->type == 'S') { in mon_text_read_isostat()
579 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_isostat()
580 " %d:%d:%d", ep->status, ep->interval, ep->start_frame); in mon_text_read_isostat()
582 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_isostat()
584 ep->status, ep->interval, ep->start_frame, ep->error_count); in mon_text_read_isostat()
588 static void mon_text_read_isodesc(struct mon_reader_text *rp, in mon_text_read_isodesc() argument
595 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_isodesc()
596 " %d", ep->numdesc); in mon_text_read_isodesc()
597 ndesc = ep->numdesc; in mon_text_read_isodesc()
602 dp = ep->isodesc; in mon_text_read_isodesc()
604 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_isodesc()
605 " %d:%u:%u", dp->status, dp->offset, dp->length); in mon_text_read_isodesc()
610 static void mon_text_read_data(struct mon_reader_text *rp, in mon_text_read_data() argument
615 if ((data_len = ep->length) > 0) { in mon_text_read_data()
616 if (ep->data_flag == 0) { in mon_text_read_data()
617 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_data()
623 p->cnt += scnprintf(p->pbuf + p->cnt, in mon_text_read_data()
624 p->limit - p->cnt, in mon_text_read_data()
627 p->cnt += scnprintf(p->pbuf + p->cnt, in mon_text_read_data()
628 p->limit - p->cnt, in mon_text_read_data()
629 "%02x", ep->data[i]); in mon_text_read_data()
631 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_data()
634 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, in mon_text_read_data()
635 " %c\n", ep->data_flag); in mon_text_read_data()
638 p->cnt += scnprintf(p->pbuf + p->cnt, p->limit - p->cnt, "\n"); in mon_text_read_data()
644 struct mon_reader_text *rp = file->private_data; in mon_text_release() local
651 mbus = inode->i_private; in mon_text_release()
653 if (mbus->nreaders <= 0) { in mon_text_release()
658 mon_reader_del(mbus, &rp->r); in mon_text_release()
661 * In theory, e_list is protected by mbus->lock. However, in mon_text_release()
663 * - we are not on reader list anymore, so new events won't be added; in mon_text_release()
664 * - whole mbus may be dropped if it was orphaned. in mon_text_release()
667 /* spin_lock_irqsave(&mbus->lock, flags); */ in mon_text_release()
668 while (!list_empty(&rp->e_list)) { in mon_text_release()
669 p = rp->e_list.next; in mon_text_release()
672 --rp->nevents; in mon_text_release()
673 kmem_cache_free(rp->e_slab, ep); in mon_text_release()
675 /* spin_unlock_irqrestore(&mbus->lock, flags); */ in mon_text_release()
677 kmem_cache_destroy(rp->e_slab); in mon_text_release()
678 kfree(rp->printf_buf); in mon_text_release()
679 kfree(rp); in mon_text_release()
705 int busnum = ubus? ubus->busnum: 0; in mon_text_add()
715 mbus->dent_t = debugfs_create_file(name, 0600, mon_dir, mbus, in mon_text_add()
722 mbus->dent_u = debugfs_create_file(name, 0600, mon_dir, mbus, in mon_text_add()
728 mbus->dent_s = debugfs_create_file(name, 0600, mon_dir, mbus, in mon_text_add()
734 debugfs_remove(mbus->dent_u); in mon_text_add()
735 mbus->dent_u = NULL; in mon_text_add()
738 debugfs_remove(mbus->dent_t); in mon_text_add()
739 mbus->dent_t = NULL; in mon_text_add()
747 debugfs_remove(mbus->dent_u); in mon_text_del()
748 debugfs_remove(mbus->dent_t); in mon_text_del()
749 debugfs_remove(mbus->dent_s); in mon_text_del()