Lines Matching full:rp

203 static inline struct mon_bin_hdr *MON_OFF2HDR(const struct mon_reader_bin *rp,  in MON_OFF2HDR()  argument
207 (rp->b_vec[offset / CHUNK_SIZE].ptr + offset % CHUNK_SIZE); in MON_OFF2HDR()
210 #define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0) argument
223 static void mon_buff_area_fill(const struct mon_reader_bin *rp,
225 static int mon_bin_wait_event(struct file *file, struct mon_reader_bin *rp);
298 static unsigned int mon_buff_area_alloc(struct mon_reader_bin *rp, in mon_buff_area_alloc() argument
304 if (rp->b_cnt + size > rp->b_size) in mon_buff_area_alloc()
306 offset = rp->b_in; in mon_buff_area_alloc()
307 rp->b_cnt += size; in mon_buff_area_alloc()
308 if ((rp->b_in += size) >= rp->b_size) in mon_buff_area_alloc()
309 rp->b_in -= rp->b_size; in mon_buff_area_alloc()
323 static unsigned int mon_buff_area_alloc_contiguous(struct mon_reader_bin *rp, in mon_buff_area_alloc_contiguous() argument
330 if (rp->b_cnt + size > rp->b_size) in mon_buff_area_alloc_contiguous()
332 if (rp->b_in + size > rp->b_size) { in mon_buff_area_alloc_contiguous()
338 fill_size = rp->b_size - rp->b_in; in mon_buff_area_alloc_contiguous()
339 if (rp->b_cnt + size + fill_size > rp->b_size) in mon_buff_area_alloc_contiguous()
341 mon_buff_area_fill(rp, rp->b_in, fill_size); in mon_buff_area_alloc_contiguous()
344 rp->b_in = size; in mon_buff_area_alloc_contiguous()
345 rp->b_cnt += size + fill_size; in mon_buff_area_alloc_contiguous()
346 } else if (rp->b_in + size == rp->b_size) { in mon_buff_area_alloc_contiguous()
347 offset = rp->b_in; in mon_buff_area_alloc_contiguous()
348 rp->b_in = 0; in mon_buff_area_alloc_contiguous()
349 rp->b_cnt += size; in mon_buff_area_alloc_contiguous()
351 offset = rp->b_in; in mon_buff_area_alloc_contiguous()
352 rp->b_in += size; in mon_buff_area_alloc_contiguous()
353 rp->b_cnt += size; in mon_buff_area_alloc_contiguous()
362 static void mon_buff_area_shrink(struct mon_reader_bin *rp, unsigned int size) in mon_buff_area_shrink() argument
366 rp->b_cnt -= size; in mon_buff_area_shrink()
367 if (rp->b_in < size) in mon_buff_area_shrink()
368 rp->b_in += rp->b_size; in mon_buff_area_shrink()
369 rp->b_in -= size; in mon_buff_area_shrink()
376 static void mon_buff_area_free(struct mon_reader_bin *rp, unsigned int size) in mon_buff_area_free() argument
380 rp->b_cnt -= size; in mon_buff_area_free()
381 if ((rp->b_out += size) >= rp->b_size) in mon_buff_area_free()
382 rp->b_out -= rp->b_size; in mon_buff_area_free()
385 static void mon_buff_area_fill(const struct mon_reader_bin *rp, in mon_buff_area_fill() argument
390 ep = MON_OFF2HDR(rp, offset); in mon_buff_area_fill()
406 static unsigned int mon_bin_get_data(const struct mon_reader_bin *rp, in mon_bin_get_data() argument
420 mon_copy_to_buff(rp, offset, urb->transfer_buffer, length); in mon_bin_get_data()
435 offset = mon_copy_to_buff(rp, offset, sg_virt(sg), in mon_bin_get_data()
450 static unsigned int mon_bin_collate_isodesc(const struct mon_reader_bin *rp, in mon_bin_collate_isodesc() argument
468 static void mon_bin_get_isodesc(const struct mon_reader_bin *rp, in mon_bin_get_isodesc() argument
477 (rp->b_vec[offset / CHUNK_SIZE].ptr + offset % CHUNK_SIZE); in mon_bin_get_isodesc()
482 if ((offset += sizeof(struct mon_bin_isodesc)) >= rp->b_size) in mon_bin_get_isodesc()
488 static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb, in mon_bin_event() argument
505 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_event()
523 length = mon_bin_collate_isodesc(rp, urb, ndesc); in mon_bin_event()
533 if (length >= rp->b_size/5) in mon_bin_event()
534 length = rp->b_size/5; in mon_bin_event()
551 if (rp->mmap_active) { in mon_bin_event()
552 offset = mon_buff_area_alloc_contiguous(rp, in mon_bin_event()
555 offset = mon_buff_area_alloc(rp, length + PKT_SIZE + lendesc); in mon_bin_event()
558 rp->cnt_lost++; in mon_bin_event()
559 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_event()
563 ep = MON_OFF2HDR(rp, offset); in mon_bin_event()
564 if ((offset += PKT_SIZE) >= rp->b_size) offset = 0; in mon_bin_event()
600 mon_bin_get_isodesc(rp, offset, urb, ev_type, ndesc); in mon_bin_event()
601 if ((offset += lendesc) >= rp->b_size) in mon_bin_event()
602 offset -= rp->b_size; in mon_bin_event()
606 length = mon_bin_get_data(rp, offset, urb, length, in mon_bin_event()
612 mon_buff_area_shrink(rp, delta); in mon_bin_event()
618 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_event()
620 wake_up(&rp->b_wait); in mon_bin_event()
625 struct mon_reader_bin *rp = data; in mon_bin_submit() local
626 mon_bin_event(rp, urb, 'S', -EINPROGRESS); in mon_bin_submit()
631 struct mon_reader_bin *rp = data; in mon_bin_complete() local
632 mon_bin_event(rp, urb, 'C', status); in mon_bin_complete()
637 struct mon_reader_bin *rp = data; in mon_bin_error() local
645 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_error()
647 offset = mon_buff_area_alloc(rp, PKT_SIZE); in mon_bin_error()
650 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_error()
654 ep = MON_OFF2HDR(rp, offset); in mon_bin_error()
671 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_error()
673 wake_up(&rp->b_wait); in mon_bin_error()
679 struct mon_reader_bin *rp; in mon_bin_open() local
695 rp = kzalloc(sizeof(struct mon_reader_bin), GFP_KERNEL); in mon_bin_open()
696 if (rp == NULL) { in mon_bin_open()
700 spin_lock_init(&rp->b_lock); in mon_bin_open()
701 init_waitqueue_head(&rp->b_wait); in mon_bin_open()
702 mutex_init(&rp->fetch_lock); in mon_bin_open()
703 rp->b_size = BUFF_DFL; in mon_bin_open()
705 size = sizeof(struct mon_pgmap) * (rp->b_size/CHUNK_SIZE); in mon_bin_open()
706 if ((rp->b_vec = kzalloc(size, GFP_KERNEL)) == NULL) { in mon_bin_open()
711 if ((rc = mon_alloc_buff(rp->b_vec, rp->b_size/CHUNK_SIZE)) < 0) in mon_bin_open()
714 rp->r.m_bus = mbus; in mon_bin_open()
715 rp->r.r_data = rp; in mon_bin_open()
716 rp->r.rnf_submit = mon_bin_submit; in mon_bin_open()
717 rp->r.rnf_error = mon_bin_error; in mon_bin_open()
718 rp->r.rnf_complete = mon_bin_complete; in mon_bin_open()
720 mon_reader_add(mbus, &rp->r); in mon_bin_open()
722 file->private_data = rp; in mon_bin_open()
727 kfree(rp->b_vec); in mon_bin_open()
729 kfree(rp); in mon_bin_open()
740 static int mon_bin_get_event(struct file *file, struct mon_reader_bin *rp, in mon_bin_get_event() argument
750 mutex_lock(&rp->fetch_lock); in mon_bin_get_event()
752 if ((rc = mon_bin_wait_event(file, rp)) < 0) { in mon_bin_get_event()
753 mutex_unlock(&rp->fetch_lock); in mon_bin_get_event()
757 ep = MON_OFF2HDR(rp, rp->b_out); in mon_bin_get_event()
760 mutex_unlock(&rp->fetch_lock); in mon_bin_get_event()
765 if ((offset = rp->b_out + PKT_SIZE) >= rp->b_size) offset = 0; in mon_bin_get_event()
767 if (copy_from_buf(rp, offset, data, step_len)) { in mon_bin_get_event()
768 mutex_unlock(&rp->fetch_lock); in mon_bin_get_event()
772 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_get_event()
773 mon_buff_area_free(rp, PKT_SIZE + ep->len_cap); in mon_bin_get_event()
774 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_get_event()
775 rp->b_read = 0; in mon_bin_get_event()
777 mutex_unlock(&rp->fetch_lock); in mon_bin_get_event()
783 struct mon_reader_bin *rp = file->private_data; in mon_bin_release() local
784 struct mon_bus* mbus = rp->r.m_bus; in mon_bin_release()
793 mon_reader_del(mbus, &rp->r); in mon_bin_release()
795 mon_free_buff(rp->b_vec, rp->b_size/CHUNK_SIZE); in mon_bin_release()
796 kfree(rp->b_vec); in mon_bin_release()
797 kfree(rp); in mon_bin_release()
806 struct mon_reader_bin *rp = file->private_data; in mon_bin_read() local
816 mutex_lock(&rp->fetch_lock); in mon_bin_read()
818 if ((rc = mon_bin_wait_event(file, rp)) < 0) { in mon_bin_read()
819 mutex_unlock(&rp->fetch_lock); in mon_bin_read()
823 ep = MON_OFF2HDR(rp, rp->b_out); in mon_bin_read()
825 if (rp->b_read < hdrbytes) { in mon_bin_read()
826 step_len = min(nbytes, (size_t)(hdrbytes - rp->b_read)); in mon_bin_read()
827 ptr = ((char *)ep) + rp->b_read; in mon_bin_read()
829 mutex_unlock(&rp->fetch_lock); in mon_bin_read()
834 rp->b_read += step_len; in mon_bin_read()
838 if (rp->b_read >= hdrbytes) { in mon_bin_read()
840 step_len -= rp->b_read - hdrbytes; in mon_bin_read()
843 offset = rp->b_out + PKT_SIZE; in mon_bin_read()
844 offset += rp->b_read - hdrbytes; in mon_bin_read()
845 if (offset >= rp->b_size) in mon_bin_read()
846 offset -= rp->b_size; in mon_bin_read()
847 if (copy_from_buf(rp, offset, buf, step_len)) { in mon_bin_read()
848 mutex_unlock(&rp->fetch_lock); in mon_bin_read()
853 rp->b_read += step_len; in mon_bin_read()
860 if (rp->b_read >= hdrbytes + ep->len_cap) { in mon_bin_read()
861 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_read()
862 mon_buff_area_free(rp, PKT_SIZE + ep->len_cap); in mon_bin_read()
863 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_read()
864 rp->b_read = 0; in mon_bin_read()
867 mutex_unlock(&rp->fetch_lock); in mon_bin_read()
875 static int mon_bin_flush(struct mon_reader_bin *rp, unsigned nevents) in mon_bin_flush() argument
881 mutex_lock(&rp->fetch_lock); in mon_bin_flush()
882 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_flush()
884 if (MON_RING_EMPTY(rp)) in mon_bin_flush()
887 ep = MON_OFF2HDR(rp, rp->b_out); in mon_bin_flush()
888 mon_buff_area_free(rp, PKT_SIZE + ep->len_cap); in mon_bin_flush()
890 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_flush()
891 rp->b_read = 0; in mon_bin_flush()
892 mutex_unlock(&rp->fetch_lock); in mon_bin_flush()
901 static int mon_bin_fetch(struct file *file, struct mon_reader_bin *rp, in mon_bin_fetch() argument
912 mutex_lock(&rp->fetch_lock); in mon_bin_fetch()
914 if ((rc = mon_bin_wait_event(file, rp)) < 0) { in mon_bin_fetch()
915 mutex_unlock(&rp->fetch_lock); in mon_bin_fetch()
919 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_fetch()
920 avail = rp->b_cnt; in mon_bin_fetch()
921 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_fetch()
923 cur_out = rp->b_out; in mon_bin_fetch()
930 ep = MON_OFF2HDR(rp, cur_out); in mon_bin_fetch()
932 mutex_unlock(&rp->fetch_lock); in mon_bin_fetch()
939 if ((cur_out += size) >= rp->b_size) in mon_bin_fetch()
940 cur_out -= rp->b_size; in mon_bin_fetch()
944 mutex_unlock(&rp->fetch_lock); in mon_bin_fetch()
952 static int mon_bin_queued(struct mon_reader_bin *rp) in mon_bin_queued() argument
961 mutex_lock(&rp->fetch_lock); in mon_bin_queued()
963 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_queued()
964 avail = rp->b_cnt; in mon_bin_queued()
965 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_queued()
967 cur_out = rp->b_out; in mon_bin_queued()
971 ep = MON_OFF2HDR(rp, cur_out); in mon_bin_queued()
976 if ((cur_out += size) >= rp->b_size) in mon_bin_queued()
977 cur_out -= rp->b_size; in mon_bin_queued()
981 mutex_unlock(&rp->fetch_lock); in mon_bin_queued()
989 struct mon_reader_bin *rp = file->private_data; in mon_bin_ioctl() local
990 // struct mon_bus* mbus = rp->r.m_bus; in mon_bin_ioctl()
1001 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_ioctl()
1002 if (!MON_RING_EMPTY(rp)) { in mon_bin_ioctl()
1003 ep = MON_OFF2HDR(rp, rp->b_out); in mon_bin_ioctl()
1006 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_ioctl()
1010 mutex_lock(&rp->fetch_lock); in mon_bin_ioctl()
1011 ret = rp->b_size; in mon_bin_ioctl()
1012 mutex_unlock(&rp->fetch_lock); in mon_bin_ioctl()
1043 mutex_lock(&rp->fetch_lock); in mon_bin_ioctl()
1044 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_ioctl()
1045 if (rp->mmap_active) { in mon_bin_ioctl()
1050 mon_free_buff(rp->b_vec, rp->b_size/CHUNK_SIZE); in mon_bin_ioctl()
1051 kfree(rp->b_vec); in mon_bin_ioctl()
1052 rp->b_vec = vec; in mon_bin_ioctl()
1053 rp->b_size = size; in mon_bin_ioctl()
1054 rp->b_read = rp->b_in = rp->b_out = rp->b_cnt = 0; in mon_bin_ioctl()
1055 rp->cnt_lost = 0; in mon_bin_ioctl()
1057 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_ioctl()
1058 mutex_unlock(&rp->fetch_lock); in mon_bin_ioctl()
1063 ret = mon_bin_flush(rp, arg); in mon_bin_ioctl()
1077 ret = mon_bin_get_event(file, rp, getb.hdr, in mon_bin_ioctl()
1094 ret = mon_bin_flush(rp, mfetch.nflush); in mon_bin_ioctl()
1100 ret = mon_bin_fetch(file, rp, mfetch.offvec, mfetch.nfetch); in mon_bin_ioctl()
1114 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_ioctl()
1115 ndropped = rp->cnt_lost; in mon_bin_ioctl()
1116 rp->cnt_lost = 0; in mon_bin_ioctl()
1117 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_ioctl()
1118 nevents = mon_bin_queued(rp); in mon_bin_ioctl()
1140 struct mon_reader_bin *rp = file->private_data; in mon_bin_compat_ioctl() local
1154 ret = mon_bin_get_event(file, rp, compat_ptr(getb.hdr32), in mon_bin_compat_ioctl()
1173 ret = mon_bin_flush(rp, mfetch.nflush32); in mon_bin_compat_ioctl()
1179 ret = mon_bin_fetch(file, rp, compat_ptr(mfetch.offvec32), in mon_bin_compat_ioctl()
1207 struct mon_reader_bin *rp = file->private_data; in mon_bin_poll() local
1212 poll_wait(file, &rp->b_wait, wait); in mon_bin_poll()
1214 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_poll()
1215 if (!MON_RING_EMPTY(rp)) in mon_bin_poll()
1217 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_poll()
1227 struct mon_reader_bin *rp = vma->vm_private_data; in mon_bin_vma_open() local
1230 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_vma_open()
1231 rp->mmap_active++; in mon_bin_vma_open()
1232 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_vma_open()
1239 struct mon_reader_bin *rp = vma->vm_private_data; in mon_bin_vma_close() local
1240 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_vma_close()
1241 rp->mmap_active--; in mon_bin_vma_close()
1242 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_vma_close()
1250 struct mon_reader_bin *rp = vmf->vma->vm_private_data; in mon_bin_vma_fault() local
1255 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_vma_fault()
1257 if (offset >= rp->b_size) { in mon_bin_vma_fault()
1258 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_vma_fault()
1262 pageptr = rp->b_vec[chunk_idx].pg; in mon_bin_vma_fault()
1265 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_vma_fault()
1304 static int mon_bin_wait_event(struct file *file, struct mon_reader_bin *rp) in mon_bin_wait_event() argument
1309 add_wait_queue(&rp->b_wait, &waita); in mon_bin_wait_event()
1312 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_wait_event()
1313 while (MON_RING_EMPTY(rp)) { in mon_bin_wait_event()
1314 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_wait_event()
1318 remove_wait_queue(&rp->b_wait, &waita); in mon_bin_wait_event()
1323 remove_wait_queue(&rp->b_wait, &waita); in mon_bin_wait_event()
1328 spin_lock_irqsave(&rp->b_lock, flags); in mon_bin_wait_event()
1330 spin_unlock_irqrestore(&rp->b_lock, flags); in mon_bin_wait_event()
1333 remove_wait_queue(&rp->b_wait, &waita); in mon_bin_wait_event()