Lines Matching refs:sp
135 struct pvr2_stream *sp = bp->stream; in pvr2_buffer_remove() local
138 cnt = &sp->i_count; in pvr2_buffer_remove()
139 bcnt = &sp->i_bcount; in pvr2_buffer_remove()
143 cnt = &sp->q_count; in pvr2_buffer_remove()
144 bcnt = &sp->q_bcount; in pvr2_buffer_remove()
148 cnt = &sp->r_count; in pvr2_buffer_remove()
149 bcnt = &sp->r_bcount; in pvr2_buffer_remove()
168 struct pvr2_stream *sp; in pvr2_buffer_set_none() local
170 sp = bp->stream; in pvr2_buffer_set_none()
176 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_buffer_set_none()
178 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_buffer_set_none()
185 struct pvr2_stream *sp; in pvr2_buffer_set_ready() local
187 sp = bp->stream; in pvr2_buffer_set_ready()
193 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_buffer_set_ready()
194 fl = (sp->r_count == 0); in pvr2_buffer_set_ready()
196 list_add_tail(&bp->list_overhead,&sp->ready_list); in pvr2_buffer_set_ready()
198 (sp->r_count)++; in pvr2_buffer_set_ready()
199 sp->r_bcount += bp->used_count; in pvr2_buffer_set_ready()
204 sp->r_bcount,sp->r_count); in pvr2_buffer_set_ready()
205 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_buffer_set_ready()
212 struct pvr2_stream *sp; in pvr2_buffer_set_idle() local
214 sp = bp->stream; in pvr2_buffer_set_idle()
220 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_buffer_set_idle()
222 list_add_tail(&bp->list_overhead,&sp->idle_list); in pvr2_buffer_set_idle()
224 (sp->i_count)++; in pvr2_buffer_set_idle()
225 sp->i_bcount += bp->max_count; in pvr2_buffer_set_idle()
230 sp->i_bcount,sp->i_count); in pvr2_buffer_set_idle()
231 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_buffer_set_idle()
237 struct pvr2_stream *sp; in pvr2_buffer_set_queued() local
239 sp = bp->stream; in pvr2_buffer_set_queued()
245 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_buffer_set_queued()
247 list_add_tail(&bp->list_overhead,&sp->queued_list); in pvr2_buffer_set_queued()
249 (sp->q_count)++; in pvr2_buffer_set_queued()
250 sp->q_bcount += bp->max_count; in pvr2_buffer_set_queued()
255 sp->q_bcount,sp->q_count); in pvr2_buffer_set_queued()
256 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_buffer_set_queued()
267 struct pvr2_stream *sp, in pvr2_buffer_init() argument
274 "/*---TRACE_FLOW---*/ bufferInit %p stream=%p",bp,sp); in pvr2_buffer_init()
275 bp->stream = sp; in pvr2_buffer_init()
300 static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) in pvr2_stream_buffer_count() argument
306 if (cnt == sp->buffer_total_count) return 0; in pvr2_stream_buffer_count()
311 sp, in pvr2_stream_buffer_count()
312 sp->buffer_total_count, in pvr2_stream_buffer_count()
313 cnt-sp->buffer_total_count); in pvr2_stream_buffer_count()
318 if (cnt > sp->buffer_total_count) { in pvr2_stream_buffer_count()
319 if (scnt > sp->buffer_slot_count) { in pvr2_stream_buffer_count()
323 if (sp->buffer_slot_count) { in pvr2_stream_buffer_count()
324 memcpy(nb,sp->buffers, in pvr2_stream_buffer_count()
325 sp->buffer_slot_count * sizeof(*nb)); in pvr2_stream_buffer_count()
326 kfree(sp->buffers); in pvr2_stream_buffer_count()
328 sp->buffers = nb; in pvr2_stream_buffer_count()
329 sp->buffer_slot_count = scnt; in pvr2_stream_buffer_count()
331 while (sp->buffer_total_count < cnt) { in pvr2_stream_buffer_count()
335 ret = pvr2_buffer_init(bp,sp,sp->buffer_total_count); in pvr2_stream_buffer_count()
340 sp->buffers[sp->buffer_total_count] = bp; in pvr2_stream_buffer_count()
341 (sp->buffer_total_count)++; in pvr2_stream_buffer_count()
345 while (sp->buffer_total_count > cnt) { in pvr2_stream_buffer_count()
347 bp = sp->buffers[sp->buffer_total_count - 1]; in pvr2_stream_buffer_count()
349 sp->buffers[sp->buffer_total_count - 1] = NULL; in pvr2_stream_buffer_count()
350 (sp->buffer_total_count)--; in pvr2_stream_buffer_count()
354 if (scnt < sp->buffer_slot_count) { in pvr2_stream_buffer_count()
357 nb = kmemdup(sp->buffers, scnt * sizeof(*nb), in pvr2_stream_buffer_count()
361 kfree(sp->buffers); in pvr2_stream_buffer_count()
362 sp->buffers = nb; in pvr2_stream_buffer_count()
363 sp->buffer_slot_count = scnt; in pvr2_stream_buffer_count()
369 static int pvr2_stream_achieve_buffer_count(struct pvr2_stream *sp) in pvr2_stream_achieve_buffer_count() argument
374 if (sp->buffer_total_count == sp->buffer_target_count) return 0; in pvr2_stream_achieve_buffer_count()
379 sp,sp->buffer_total_count,sp->buffer_target_count); in pvr2_stream_achieve_buffer_count()
381 if (sp->buffer_total_count < sp->buffer_target_count) { in pvr2_stream_achieve_buffer_count()
382 return pvr2_stream_buffer_count(sp,sp->buffer_target_count); in pvr2_stream_achieve_buffer_count()
386 while ((sp->buffer_total_count - cnt) > sp->buffer_target_count) { in pvr2_stream_achieve_buffer_count()
387 bp = sp->buffers[sp->buffer_total_count - (cnt + 1)]; in pvr2_stream_achieve_buffer_count()
392 pvr2_stream_buffer_count(sp,sp->buffer_total_count - cnt); in pvr2_stream_achieve_buffer_count()
398 static void pvr2_stream_internal_flush(struct pvr2_stream *sp) in pvr2_stream_internal_flush() argument
402 while ((lp = sp->queued_list.next) != &sp->queued_list) { in pvr2_stream_internal_flush()
413 if (sp->buffer_total_count != sp->buffer_target_count) { in pvr2_stream_internal_flush()
414 pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_internal_flush()
418 static void pvr2_stream_init(struct pvr2_stream *sp) in pvr2_stream_init() argument
420 spin_lock_init(&sp->list_lock); in pvr2_stream_init()
421 mutex_init(&sp->mutex); in pvr2_stream_init()
422 INIT_LIST_HEAD(&sp->queued_list); in pvr2_stream_init()
423 INIT_LIST_HEAD(&sp->ready_list); in pvr2_stream_init()
424 INIT_LIST_HEAD(&sp->idle_list); in pvr2_stream_init()
427 static void pvr2_stream_done(struct pvr2_stream *sp) in pvr2_stream_done() argument
429 mutex_lock(&sp->mutex); do { in pvr2_stream_done()
430 pvr2_stream_internal_flush(sp); in pvr2_stream_done()
431 pvr2_stream_buffer_count(sp,0); in pvr2_stream_done()
432 } while (0); mutex_unlock(&sp->mutex); in pvr2_stream_done()
438 struct pvr2_stream *sp; in buffer_complete() local
441 sp = bp->stream; in buffer_complete()
447 spin_lock_irqsave(&sp->list_lock,irq_flags); in buffer_complete()
452 (sp->buffers_processed)++; in buffer_complete()
453 sp->bytes_processed += urb->actual_length; in buffer_complete()
455 if (sp->fail_count) { in buffer_complete()
458 " - fail count reset",sp); in buffer_complete()
459 sp->fail_count = 0; in buffer_complete()
461 } else if (sp->fail_count < sp->fail_tolerance) { in buffer_complete()
464 (sp->fail_count)++; in buffer_complete()
465 (sp->buffers_failed)++; in buffer_complete()
469 sp,urb->status,sp->fail_count); in buffer_complete()
471 (sp->buffers_failed)++; in buffer_complete()
474 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in buffer_complete()
476 if (sp && sp->callback_func) { in buffer_complete()
477 sp->callback_func(sp->callback_data); in buffer_complete()
483 struct pvr2_stream *sp; in pvr2_stream_create() local
484 sp = kzalloc(sizeof(*sp),GFP_KERNEL); in pvr2_stream_create()
485 if (!sp) return sp; in pvr2_stream_create()
486 pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_create: sp=%p",sp); in pvr2_stream_create()
487 pvr2_stream_init(sp); in pvr2_stream_create()
488 return sp; in pvr2_stream_create()
491 void pvr2_stream_destroy(struct pvr2_stream *sp) in pvr2_stream_destroy() argument
493 if (!sp) return; in pvr2_stream_destroy()
494 pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_destroy: sp=%p",sp); in pvr2_stream_destroy()
495 pvr2_stream_done(sp); in pvr2_stream_destroy()
496 kfree(sp); in pvr2_stream_destroy()
499 void pvr2_stream_setup(struct pvr2_stream *sp, in pvr2_stream_setup() argument
504 mutex_lock(&sp->mutex); do { in pvr2_stream_setup()
505 pvr2_stream_internal_flush(sp); in pvr2_stream_setup()
506 sp->dev = dev; in pvr2_stream_setup()
507 sp->endpoint = endpoint; in pvr2_stream_setup()
508 sp->fail_tolerance = tolerance; in pvr2_stream_setup()
509 } while(0); mutex_unlock(&sp->mutex); in pvr2_stream_setup()
512 void pvr2_stream_set_callback(struct pvr2_stream *sp, in pvr2_stream_set_callback() argument
517 mutex_lock(&sp->mutex); in pvr2_stream_set_callback()
519 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_stream_set_callback()
520 sp->callback_data = data; in pvr2_stream_set_callback()
521 sp->callback_func = func; in pvr2_stream_set_callback()
522 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_stream_set_callback()
524 mutex_unlock(&sp->mutex); in pvr2_stream_set_callback()
527 void pvr2_stream_get_stats(struct pvr2_stream *sp, in pvr2_stream_get_stats() argument
532 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_stream_get_stats()
534 stats->buffers_in_queue = sp->q_count; in pvr2_stream_get_stats()
535 stats->buffers_in_idle = sp->i_count; in pvr2_stream_get_stats()
536 stats->buffers_in_ready = sp->r_count; in pvr2_stream_get_stats()
537 stats->buffers_processed = sp->buffers_processed; in pvr2_stream_get_stats()
538 stats->buffers_failed = sp->buffers_failed; in pvr2_stream_get_stats()
539 stats->bytes_processed = sp->bytes_processed; in pvr2_stream_get_stats()
542 sp->buffers_processed = 0; in pvr2_stream_get_stats()
543 sp->buffers_failed = 0; in pvr2_stream_get_stats()
544 sp->bytes_processed = 0; in pvr2_stream_get_stats()
546 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_stream_get_stats()
550 int pvr2_stream_get_buffer_count(struct pvr2_stream *sp) in pvr2_stream_get_buffer_count() argument
552 return sp->buffer_target_count; in pvr2_stream_get_buffer_count()
555 int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt) in pvr2_stream_set_buffer_count() argument
558 if (sp->buffer_target_count == cnt) return 0; in pvr2_stream_set_buffer_count()
559 mutex_lock(&sp->mutex); in pvr2_stream_set_buffer_count()
561 sp->buffer_target_count = cnt; in pvr2_stream_set_buffer_count()
562 ret = pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_set_buffer_count()
564 mutex_unlock(&sp->mutex); in pvr2_stream_set_buffer_count()
568 struct pvr2_buffer *pvr2_stream_get_idle_buffer(struct pvr2_stream *sp) in pvr2_stream_get_idle_buffer() argument
570 struct list_head *lp = sp->idle_list.next; in pvr2_stream_get_idle_buffer()
571 if (lp == &sp->idle_list) return NULL; in pvr2_stream_get_idle_buffer()
575 struct pvr2_buffer *pvr2_stream_get_ready_buffer(struct pvr2_stream *sp) in pvr2_stream_get_ready_buffer() argument
577 struct list_head *lp = sp->ready_list.next; in pvr2_stream_get_ready_buffer()
578 if (lp == &sp->ready_list) return NULL; in pvr2_stream_get_ready_buffer()
582 struct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp,int id) in pvr2_stream_get_buffer() argument
585 if (id >= sp->buffer_total_count) return NULL; in pvr2_stream_get_buffer()
586 return sp->buffers[id]; in pvr2_stream_get_buffer()
589 int pvr2_stream_get_ready_count(struct pvr2_stream *sp) in pvr2_stream_get_ready_count() argument
591 return sp->r_count; in pvr2_stream_get_ready_count()
594 void pvr2_stream_kill(struct pvr2_stream *sp) in pvr2_stream_kill() argument
597 mutex_lock(&sp->mutex); in pvr2_stream_kill()
599 pvr2_stream_internal_flush(sp); in pvr2_stream_kill()
600 while ((bp = pvr2_stream_get_ready_buffer(sp)) != NULL) { in pvr2_stream_kill()
603 if (sp->buffer_total_count != sp->buffer_target_count) { in pvr2_stream_kill()
604 pvr2_stream_achieve_buffer_count(sp); in pvr2_stream_kill()
607 mutex_unlock(&sp->mutex); in pvr2_stream_kill()
618 struct pvr2_stream *sp; in pvr2_buffer_queue() local
620 sp = bp->stream; in pvr2_buffer_queue()
621 mutex_lock(&sp->mutex); in pvr2_buffer_queue()
624 if (!sp->dev) { in pvr2_buffer_queue()
638 sp->dev, // struct usb_device *dev in pvr2_buffer_queue()
640 usb_rcvbulkpipe(sp->dev,sp->endpoint), in pvr2_buffer_queue()
647 mutex_unlock(&sp->mutex); in pvr2_buffer_queue()
655 struct pvr2_stream *sp; in pvr2_buffer_set_buffer() local
657 sp = bp->stream; in pvr2_buffer_set_buffer()
658 mutex_lock(&sp->mutex); in pvr2_buffer_set_buffer()
660 spin_lock_irqsave(&sp->list_lock,irq_flags); in pvr2_buffer_set_buffer()
675 spin_unlock_irqrestore(&sp->list_lock,irq_flags); in pvr2_buffer_set_buffer()
677 mutex_unlock(&sp->mutex); in pvr2_buffer_set_buffer()