Lines Matching refs:sp
120 struct pvr2_stream *sp = bp->stream; in pvr2_buffer_remove() local
123 cnt = &sp->i_count; in pvr2_buffer_remove()
124 bcnt = &sp->i_bcount; in pvr2_buffer_remove()
128 cnt = &sp->q_count; in pvr2_buffer_remove()
129 bcnt = &sp->q_bcount; in pvr2_buffer_remove()
133 cnt = &sp->r_count; in pvr2_buffer_remove()
134 bcnt = &sp->r_bcount; in pvr2_buffer_remove()
152 struct pvr2_stream *sp; in pvr2_buffer_set_none() local
154 sp = bp->stream; in pvr2_buffer_set_none()
160 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_buffer_set_none()
162 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_buffer_set_none()
169 struct pvr2_stream *sp; in pvr2_buffer_set_ready() local
171 sp = bp->stream; in pvr2_buffer_set_ready()
177 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_buffer_set_ready()
178 fl = (sp->r_count == 0); in pvr2_buffer_set_ready()
180 list_add_tail(&bp->list_overhead, &sp->ready_list); in pvr2_buffer_set_ready()
182 (sp->r_count)++; in pvr2_buffer_set_ready()
183 sp->r_bcount += bp->used_count; in pvr2_buffer_set_ready()
187 sp->r_bcount, sp->r_count); in pvr2_buffer_set_ready()
188 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_buffer_set_ready()
195 struct pvr2_stream *sp; in pvr2_buffer_set_idle() local
197 sp = bp->stream; in pvr2_buffer_set_idle()
203 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_buffer_set_idle()
205 list_add_tail(&bp->list_overhead, &sp->idle_list); in pvr2_buffer_set_idle()
207 (sp->i_count)++; in pvr2_buffer_set_idle()
208 sp->i_bcount += bp->max_count; in pvr2_buffer_set_idle()
212 sp->i_bcount, sp->i_count); in pvr2_buffer_set_idle()
213 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_buffer_set_idle()
219 struct pvr2_stream *sp; in pvr2_buffer_set_queued() local
221 sp = bp->stream; in pvr2_buffer_set_queued()
227 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_buffer_set_queued()
229 list_add_tail(&bp->list_overhead, &sp->queued_list); in pvr2_buffer_set_queued()
231 (sp->q_count)++; in pvr2_buffer_set_queued()
232 sp->q_bcount += bp->max_count; in pvr2_buffer_set_queued()
236 sp->q_bcount, sp->q_count); in pvr2_buffer_set_queued()
237 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_buffer_set_queued()
248 struct pvr2_stream *sp, in pvr2_buffer_init() argument
255 "/*---TRACE_FLOW---*/ bufferInit %p stream=%p", bp, sp); in pvr2_buffer_init()
256 bp->stream = sp; in pvr2_buffer_init()
281 static int pvr2_stream_buffer_count(struct pvr2_stream *sp, unsigned int cnt) in pvr2_stream_buffer_count() argument
287 if (cnt == sp->buffer_total_count) return 0; in pvr2_stream_buffer_count()
291 sp, in pvr2_stream_buffer_count()
292 sp->buffer_total_count, in pvr2_stream_buffer_count()
293 cnt-sp->buffer_total_count); in pvr2_stream_buffer_count()
298 if (cnt > sp->buffer_total_count) { in pvr2_stream_buffer_count()
299 if (scnt > sp->buffer_slot_count) { in pvr2_stream_buffer_count()
304 if (sp->buffer_slot_count) { in pvr2_stream_buffer_count()
305 memcpy(nb, sp->buffers, in pvr2_stream_buffer_count()
306 sp->buffer_slot_count * sizeof(*nb)); in pvr2_stream_buffer_count()
307 kfree(sp->buffers); in pvr2_stream_buffer_count()
309 sp->buffers = nb; in pvr2_stream_buffer_count()
310 sp->buffer_slot_count = scnt; in pvr2_stream_buffer_count()
312 while (sp->buffer_total_count < cnt) { in pvr2_stream_buffer_count()
316 ret = pvr2_buffer_init(bp, sp, sp->buffer_total_count); in pvr2_stream_buffer_count()
321 sp->buffers[sp->buffer_total_count] = bp; in pvr2_stream_buffer_count()
322 (sp->buffer_total_count)++; in pvr2_stream_buffer_count()
326 while (sp->buffer_total_count > cnt) { in pvr2_stream_buffer_count()
328 bp = sp->buffers[sp->buffer_total_count - 1]; in pvr2_stream_buffer_count()
330 sp->buffers[sp->buffer_total_count - 1] = NULL; in pvr2_stream_buffer_count()
331 (sp->buffer_total_count)--; in pvr2_stream_buffer_count()
335 if (scnt < sp->buffer_slot_count) { in pvr2_stream_buffer_count()
338 nb = kmemdup(sp->buffers, scnt * sizeof(*nb), in pvr2_stream_buffer_count()
342 kfree(sp->buffers); in pvr2_stream_buffer_count()
343 sp->buffers = nb; in pvr2_stream_buffer_count()
344 sp->buffer_slot_count = scnt; in pvr2_stream_buffer_count()
350 static int pvr2_stream_achieve_buffer_count(struct pvr2_stream *sp) in pvr2_stream_achieve_buffer_count() argument
355 if (sp->buffer_total_count == sp->buffer_target_count) return 0; in pvr2_stream_achieve_buffer_count()
359 sp, sp->buffer_total_count, sp->buffer_target_count); in pvr2_stream_achieve_buffer_count()
361 if (sp->buffer_total_count < sp->buffer_target_count) { in pvr2_stream_achieve_buffer_count()
362 return pvr2_stream_buffer_count(sp, sp->buffer_target_count); in pvr2_stream_achieve_buffer_count()
366 while ((sp->buffer_total_count - cnt) > sp->buffer_target_count) { in pvr2_stream_achieve_buffer_count()
367 bp = sp->buffers[sp->buffer_total_count - (cnt + 1)]; in pvr2_stream_achieve_buffer_count()
372 pvr2_stream_buffer_count(sp, sp->buffer_total_count - cnt); in pvr2_stream_achieve_buffer_count()
378 static void pvr2_stream_internal_flush(struct pvr2_stream *sp) in pvr2_stream_internal_flush() argument
382 while ((lp = sp->queued_list.next) != &sp->queued_list) { in pvr2_stream_internal_flush()
393 if (sp->buffer_total_count != sp->buffer_target_count) { in pvr2_stream_internal_flush()
394 pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_internal_flush()
398 static void pvr2_stream_init(struct pvr2_stream *sp) in pvr2_stream_init() argument
400 spin_lock_init(&sp->list_lock); in pvr2_stream_init()
401 mutex_init(&sp->mutex); in pvr2_stream_init()
402 INIT_LIST_HEAD(&sp->queued_list); in pvr2_stream_init()
403 INIT_LIST_HEAD(&sp->ready_list); in pvr2_stream_init()
404 INIT_LIST_HEAD(&sp->idle_list); in pvr2_stream_init()
407 static void pvr2_stream_done(struct pvr2_stream *sp) in pvr2_stream_done() argument
409 mutex_lock(&sp->mutex); do { in pvr2_stream_done()
410 pvr2_stream_internal_flush(sp); in pvr2_stream_done()
411 pvr2_stream_buffer_count(sp, 0); in pvr2_stream_done()
412 } while (0); mutex_unlock(&sp->mutex); in pvr2_stream_done()
418 struct pvr2_stream *sp; in buffer_complete() local
421 sp = bp->stream; in buffer_complete()
427 spin_lock_irqsave(&sp->list_lock, irq_flags); in buffer_complete()
432 (sp->buffers_processed)++; in buffer_complete()
433 sp->bytes_processed += urb->actual_length; in buffer_complete()
435 if (sp->fail_count) { in buffer_complete()
438 sp); in buffer_complete()
439 sp->fail_count = 0; in buffer_complete()
441 } else if (sp->fail_count < sp->fail_tolerance) { in buffer_complete()
444 (sp->fail_count)++; in buffer_complete()
445 (sp->buffers_failed)++; in buffer_complete()
448 sp, urb->status, sp->fail_count); in buffer_complete()
450 (sp->buffers_failed)++; in buffer_complete()
453 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in buffer_complete()
455 if (sp->callback_func) { in buffer_complete()
456 sp->callback_func(sp->callback_data); in buffer_complete()
462 struct pvr2_stream *sp; in pvr2_stream_create() local
463 sp = kzalloc(sizeof(*sp), GFP_KERNEL); in pvr2_stream_create()
464 if (!sp) return sp; in pvr2_stream_create()
465 pvr2_trace(PVR2_TRACE_INIT, "pvr2_stream_create: sp=%p", sp); in pvr2_stream_create()
466 pvr2_stream_init(sp); in pvr2_stream_create()
467 return sp; in pvr2_stream_create()
470 void pvr2_stream_destroy(struct pvr2_stream *sp) in pvr2_stream_destroy() argument
472 if (!sp) return; in pvr2_stream_destroy()
473 pvr2_trace(PVR2_TRACE_INIT, "pvr2_stream_destroy: sp=%p", sp); in pvr2_stream_destroy()
474 pvr2_stream_done(sp); in pvr2_stream_destroy()
475 kfree(sp); in pvr2_stream_destroy()
478 void pvr2_stream_setup(struct pvr2_stream *sp, in pvr2_stream_setup() argument
483 mutex_lock(&sp->mutex); do { in pvr2_stream_setup()
484 pvr2_stream_internal_flush(sp); in pvr2_stream_setup()
485 sp->dev = dev; in pvr2_stream_setup()
486 sp->endpoint = endpoint; in pvr2_stream_setup()
487 sp->fail_tolerance = tolerance; in pvr2_stream_setup()
488 } while (0); mutex_unlock(&sp->mutex); in pvr2_stream_setup()
491 void pvr2_stream_set_callback(struct pvr2_stream *sp, in pvr2_stream_set_callback() argument
496 mutex_lock(&sp->mutex); in pvr2_stream_set_callback()
498 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_stream_set_callback()
499 sp->callback_data = data; in pvr2_stream_set_callback()
500 sp->callback_func = func; in pvr2_stream_set_callback()
501 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_stream_set_callback()
503 mutex_unlock(&sp->mutex); in pvr2_stream_set_callback()
506 void pvr2_stream_get_stats(struct pvr2_stream *sp, in pvr2_stream_get_stats() argument
511 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_stream_get_stats()
513 stats->buffers_in_queue = sp->q_count; in pvr2_stream_get_stats()
514 stats->buffers_in_idle = sp->i_count; in pvr2_stream_get_stats()
515 stats->buffers_in_ready = sp->r_count; in pvr2_stream_get_stats()
516 stats->buffers_processed = sp->buffers_processed; in pvr2_stream_get_stats()
517 stats->buffers_failed = sp->buffers_failed; in pvr2_stream_get_stats()
518 stats->bytes_processed = sp->bytes_processed; in pvr2_stream_get_stats()
521 sp->buffers_processed = 0; in pvr2_stream_get_stats()
522 sp->buffers_failed = 0; in pvr2_stream_get_stats()
523 sp->bytes_processed = 0; in pvr2_stream_get_stats()
525 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_stream_get_stats()
529 int pvr2_stream_get_buffer_count(struct pvr2_stream *sp) in pvr2_stream_get_buffer_count() argument
531 return sp->buffer_target_count; in pvr2_stream_get_buffer_count()
534 int pvr2_stream_set_buffer_count(struct pvr2_stream *sp, unsigned int cnt) in pvr2_stream_set_buffer_count() argument
537 if (sp->buffer_target_count == cnt) return 0; in pvr2_stream_set_buffer_count()
538 mutex_lock(&sp->mutex); in pvr2_stream_set_buffer_count()
540 sp->buffer_target_count = cnt; in pvr2_stream_set_buffer_count()
541 ret = pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_set_buffer_count()
543 mutex_unlock(&sp->mutex); in pvr2_stream_set_buffer_count()
547 struct pvr2_buffer *pvr2_stream_get_idle_buffer(struct pvr2_stream *sp) in pvr2_stream_get_idle_buffer() argument
549 struct list_head *lp = sp->idle_list.next; in pvr2_stream_get_idle_buffer()
550 if (lp == &sp->idle_list) return NULL; in pvr2_stream_get_idle_buffer()
554 struct pvr2_buffer *pvr2_stream_get_ready_buffer(struct pvr2_stream *sp) in pvr2_stream_get_ready_buffer() argument
556 struct list_head *lp = sp->ready_list.next; in pvr2_stream_get_ready_buffer()
557 if (lp == &sp->ready_list) return NULL; in pvr2_stream_get_ready_buffer()
561 struct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp, int id) in pvr2_stream_get_buffer() argument
564 if (id >= sp->buffer_total_count) return NULL; in pvr2_stream_get_buffer()
565 return sp->buffers[id]; in pvr2_stream_get_buffer()
568 int pvr2_stream_get_ready_count(struct pvr2_stream *sp) in pvr2_stream_get_ready_count() argument
570 return sp->r_count; in pvr2_stream_get_ready_count()
573 void pvr2_stream_kill(struct pvr2_stream *sp) in pvr2_stream_kill() argument
576 mutex_lock(&sp->mutex); in pvr2_stream_kill()
578 pvr2_stream_internal_flush(sp); in pvr2_stream_kill()
579 while ((bp = pvr2_stream_get_ready_buffer(sp)) != NULL) { in pvr2_stream_kill()
582 if (sp->buffer_total_count != sp->buffer_target_count) { in pvr2_stream_kill()
583 pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_kill()
586 mutex_unlock(&sp->mutex); in pvr2_stream_kill()
597 struct pvr2_stream *sp; in pvr2_buffer_queue() local
599 sp = bp->stream; in pvr2_buffer_queue()
600 mutex_lock(&sp->mutex); in pvr2_buffer_queue()
603 if (!sp->dev) { in pvr2_buffer_queue()
617 sp->dev, // struct usb_device *dev in pvr2_buffer_queue()
619 usb_rcvbulkpipe(sp->dev, sp->endpoint), in pvr2_buffer_queue()
626 mutex_unlock(&sp->mutex); in pvr2_buffer_queue()
634 struct pvr2_stream *sp; in pvr2_buffer_set_buffer() local
636 sp = bp->stream; in pvr2_buffer_set_buffer()
637 mutex_lock(&sp->mutex); in pvr2_buffer_set_buffer()
639 spin_lock_irqsave(&sp->list_lock, irq_flags); in pvr2_buffer_set_buffer()
653 spin_unlock_irqrestore(&sp->list_lock, irq_flags); in pvr2_buffer_set_buffer()
655 mutex_unlock(&sp->mutex); in pvr2_buffer_set_buffer()