14 static void usb_urb_complete(
struct urb *
urb)
17 int ptype = usb_pipetype(urb->pipe);
21 deb_uxfer(
"'%s' urb completed. status: %d, length: %d/%d, pack_num: %d, errors: %d\n",
22 ptype == PIPE_ISOCHRONOUS ?
"isoc" :
"bulk",
23 urb->status,urb->actual_length,urb->transfer_buffer_length,
24 urb->number_of_packets,urb->error_count);
26 switch (urb->status) {
35 deb_ts(
"urb completition error %d.\n", urb->status);
39 b = (
u8 *) urb->transfer_buffer;
41 case PIPE_ISOCHRONOUS:
42 for (i = 0; i < urb->number_of_packets; i++) {
44 if (urb->iso_frame_desc[i].status != 0)
45 deb_ts(
"iso frame descriptor has an error: %d\n",urb->iso_frame_desc[i].status);
46 else if (urb->iso_frame_desc[i].actual_length > 0)
47 stream->
complete(stream, b + urb->iso_frame_desc[i].offset, urb->iso_frame_desc[i].actual_length);
49 urb->iso_frame_desc[
i].status = 0;
50 urb->iso_frame_desc[
i].actual_length = 0;
55 if (urb->actual_length > 0)
56 stream->
complete(stream, b, urb->actual_length);
59 err(
"unknown endpoint type in completition handler.");
69 deb_ts(
"killing URB no. %d.\n",i);
82 deb_ts(
"submitting URB no. %d\n",i);
84 err(
"could not submit URB no. %d - get them all back",i);
110 static int usb_allocate_stream_buffers(
struct usb_data_stream *stream,
int num,
unsigned long size)
115 deb_mem(
"all in all I will use %lu bytes for streaming\n",num*size);
122 deb_mem(
"not enough memory for urb-buffer allocation.\n");
126 deb_mem(
"buffer %d: %p (dma: %Lu)\n",
132 deb_mem(
"allocation successful\n");
141 if ((i = usb_allocate_stream_buffers(stream,stream->
props.count,
142 stream->
props.u.bulk.buffersize)) < 0)
146 for (i = 0; i < stream->
props.count; i++) {
149 deb_mem(
"not enough memory for urb_alloc_urb!.\n");
150 for (j = 0; j <
i; j++)
155 usb_rcvbulkpipe(stream->
udev,stream->
props.endpoint),
157 stream->
props.u.bulk.buffersize,
158 usb_urb_complete, stream);
160 stream->
urb_list[
i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
171 if ((i = usb_allocate_stream_buffers(stream,stream->
props.count,
172 stream->
props.u.isoc.framesize*stream->
props.u.isoc.framesperurb)) < 0)
176 for (i = 0; i < stream->
props.count; i++) {
182 deb_mem(
"not enough memory for urb_alloc_urb!\n");
183 for (j = 0; j <
i; j++)
190 urb->dev = stream->
udev;
191 urb->context = stream;
193 urb->pipe = usb_rcvisocpipe(stream->
udev,stream->
props.endpoint);
194 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
195 urb->interval = stream->
props.u.isoc.interval;
196 urb->number_of_packets = stream->
props.u.isoc.framesperurb;
197 urb->transfer_buffer_length = stream->
buf_size;
198 urb->transfer_buffer = stream->
buf_list[
i];
201 for (j = 0; j < stream->
props.u.isoc.framesperurb; j++) {
203 urb->iso_frame_desc[
j].length = stream->
props.u.isoc.framesize;
204 frame_offset += stream->
props.u.isoc.framesize;
214 if (stream ==
NULL || props ==
NULL)
222 err(
"there is no data callback - this doesn't make sense.");
226 switch (stream->
props.type) {
228 return usb_bulk_urb_init(stream);
230 return usb_isoc_urb_init(stream);
232 err(
"unknown URB-type for data transfer.");
245 deb_mem(
"freeing URB no. %d.\n",i);