23 #include <linux/errno.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
30 #define BUFFER_SIG 0x47653271
35 #ifdef SANITY_CHECK_BUFFERS
36 #define BUFFER_CHECK(bp) do { \
37 if ((bp)->signature != BUFFER_SIG) { \
38 pvr2_trace(PVR2_TRACE_ERROR_LEGS, \
39 "Buffer %p is bad at %s:%d", \
40 (bp),__FILE__,__LINE__); \
41 pvr2_buffer_describe(bp,"BadSig"); \
46 #define BUFFER_CHECK(bp) do {} while(0)
74 struct usb_device *
dev;
112 #ifdef SANITY_CHECK_BUFFERS
113 static void pvr2_buffer_describe(
struct pvr2_buffer *bp,
const char *
msg)
116 "buffer%s%s %p state=%s id=%d status=%d"
117 " stream=%p purb=%p sig=0x%x",
121 (bp ? pvr2_buffer_state_decode(bp->
state) :
"(invalid)"),
125 (bp ? bp->
purb : NULL),
130 static void pvr2_buffer_remove(
struct pvr2_buffer *bp)
159 "/*---TRACE_FLOW---*/"
160 " bufferPool %8s dec cap=%07d cnt=%02d",
161 pvr2_buffer_state_decode(bp->
state),*bcnt,*cnt);
165 static void pvr2_buffer_set_none(
struct pvr2_buffer *bp)
167 unsigned long irq_flags;
172 "/*---TRACE_FLOW---*/ bufferState %p %6s --> %6s",
174 pvr2_buffer_state_decode(bp->
state),
177 pvr2_buffer_remove(bp);
178 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
181 static int pvr2_buffer_set_ready(
struct pvr2_buffer *bp)
184 unsigned long irq_flags;
189 "/*---TRACE_FLOW---*/ bufferState %p %6s --> %6s",
191 pvr2_buffer_state_decode(bp->
state),
195 pvr2_buffer_remove(bp);
201 "/*---TRACE_FLOW---*/"
202 " bufferPool %8s inc cap=%07d cnt=%02d",
203 pvr2_buffer_state_decode(bp->
state),
205 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
209 static void pvr2_buffer_set_idle(
struct pvr2_buffer *bp)
211 unsigned long irq_flags;
216 "/*---TRACE_FLOW---*/ bufferState %p %6s --> %6s",
218 pvr2_buffer_state_decode(bp->
state),
221 pvr2_buffer_remove(bp);
227 "/*---TRACE_FLOW---*/"
228 " bufferPool %8s inc cap=%07d cnt=%02d",
229 pvr2_buffer_state_decode(bp->
state),
231 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
234 static void pvr2_buffer_set_queued(
struct pvr2_buffer *bp)
236 unsigned long irq_flags;
241 "/*---TRACE_FLOW---*/ bufferState %p %6s --> %6s",
243 pvr2_buffer_state_decode(bp->
state),
246 pvr2_buffer_remove(bp);
252 "/*---TRACE_FLOW---*/"
253 " bufferPool %8s inc cap=%07d cnt=%02d",
254 pvr2_buffer_state_decode(bp->
state),
256 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
259 static void pvr2_buffer_wipe(
struct pvr2_buffer *bp)
266 static int pvr2_buffer_init(
struct pvr2_buffer *bp,
274 "/*---TRACE_FLOW---*/ bufferInit %p stream=%p",bp,sp);
280 #ifdef SANITY_CHECK_BUFFERS
281 pvr2_buffer_describe(bp,
"create");
286 static void pvr2_buffer_done(
struct pvr2_buffer *bp)
288 #ifdef SANITY_CHECK_BUFFERS
289 pvr2_buffer_describe(bp,
"delete");
291 pvr2_buffer_wipe(bp);
292 pvr2_buffer_set_none(bp);
297 " bufferDone %p",bp);
300 static int pvr2_stream_buffer_count(
struct pvr2_stream *sp,
unsigned int cnt)
309 "/*---TRACE_FLOW---*/ poolResize "
310 " stream=%p cur=%d adj=%+d",
316 if (cnt > scnt) scnt += 0x20;
342 pvr2_buffer_set_idle(bp);
351 pvr2_buffer_done(bp);
354 if (scnt < sp->buffer_slot_count) {
369 static int pvr2_stream_achieve_buffer_count(
struct pvr2_stream *sp)
377 "/*---TRACE_FLOW---*/"
378 " poolCheck stream=%p cur=%d tgt=%d",
398 static void pvr2_stream_internal_flush(
struct pvr2_stream *sp)
404 pvr2_buffer_wipe(bp1);
411 pvr2_buffer_set_idle(bp1);
414 pvr2_stream_achieve_buffer_count(sp);
418 static void pvr2_stream_init(
struct pvr2_stream *sp)
427 static void pvr2_stream_done(
struct pvr2_stream *sp)
430 pvr2_stream_internal_flush(sp);
431 pvr2_stream_buffer_count(sp,0);
435 static void buffer_complete(
struct urb *
urb)
439 unsigned long irq_flags;
445 "/*---TRACE_FLOW---*/ bufferComplete %p stat=%d cnt=%d",
446 bp,urb->
status,urb->actual_length);
448 if ((!(urb->status)) ||
449 (urb->status == -
ENOENT) ||
457 "stream %p transfer ok"
458 " - fail count reset",sp);
467 "stream %p ignoring error %d"
468 " - fail count increased to %u",
474 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
475 pvr2_buffer_set_ready(bp);
487 pvr2_stream_init(sp);
495 pvr2_stream_done(sp);
500 struct usb_device *
dev,
502 unsigned int tolerance)
505 pvr2_stream_internal_flush(sp);
516 unsigned long irq_flags;
521 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
529 unsigned long irq_flags;
544 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);
559 ret = pvr2_stream_achieve_buffer_count(sp);
580 if (
id < 0)
return NULL;
594 pvr2_stream_internal_flush(sp);
596 pvr2_buffer_set_idle(bp);
599 pvr2_stream_achieve_buffer_count(sp);
616 pvr2_buffer_wipe(bp);
621 pvr2_buffer_set_queued(bp);
623 for (idx = 0; idx < (bp->
max_count) / 4; idx++) {
626 ((
unsigned int *)(bp->
ptr))[idx] = val;
630 usb_fill_bulk_urb(bp->
purb,
646 unsigned long irq_flags;
660 "/*---TRACE_FLOW---*/ bufferPool "
661 " %8s cap cap=%07d cnt=%02d",
662 pvr2_buffer_state_decode(
666 spin_unlock_irqrestore(&sp->
list_lock,irq_flags);