Lines Matching +full:isoc +full:- +full:in

1 // SPDX-License-Identifier: GPL-2.0
2 /* usb-urb.c is part of the DVB USB library.
4 * Copyright (C) 2004-6 Patrick Boettcher ([email protected])
5 * see dvb-usb-init.c for copyright information.
8 * BULK and ISOC USB data transfers in a generic way.
9 * Can be used for DVB-only and also, that's the plan, for
21 struct usb_data_stream *stream = urb->context; in usb_urb_complete()
22 int ptype = usb_pipetype(urb->pipe); in usb_urb_complete()
26 dev_dbg_ratelimited(&stream->udev->dev, in usb_urb_complete()
28 __func__, ptype == PIPE_ISOCHRONOUS ? "isoc" : "bulk", in usb_urb_complete()
29 urb->status, urb->actual_length, in usb_urb_complete()
30 urb->transfer_buffer_length, in usb_urb_complete()
31 urb->number_of_packets, urb->error_count); in usb_urb_complete()
33 switch (urb->status) { in usb_urb_complete()
35 case -ETIMEDOUT: /* NAK */ in usb_urb_complete()
37 case -ECONNRESET: /* kill */ in usb_urb_complete()
38 case -ENOENT: in usb_urb_complete()
39 case -ESHUTDOWN: in usb_urb_complete()
42 dev_dbg_ratelimited(&stream->udev->dev, in usb_urb_complete()
44 __func__, urb->status); in usb_urb_complete()
48 b = (u8 *) urb->transfer_buffer; in usb_urb_complete()
51 for (i = 0; i < urb->number_of_packets; i++) { in usb_urb_complete()
52 if (urb->iso_frame_desc[i].status != 0) in usb_urb_complete()
53 dev_dbg(&stream->udev->dev, in usb_urb_complete()
56 urb->iso_frame_desc[i].status); in usb_urb_complete()
57 else if (urb->iso_frame_desc[i].actual_length > 0) in usb_urb_complete()
58 stream->complete(stream, in usb_urb_complete()
59 b + urb->iso_frame_desc[i].offset, in usb_urb_complete()
60 urb->iso_frame_desc[i].actual_length); in usb_urb_complete()
62 urb->iso_frame_desc[i].status = 0; in usb_urb_complete()
63 urb->iso_frame_desc[i].actual_length = 0; in usb_urb_complete()
67 if (urb->actual_length > 0) in usb_urb_complete()
68 stream->complete(stream, b, urb->actual_length); in usb_urb_complete()
71 dev_err(&stream->udev->dev, in usb_urb_complete()
72 "%s: unknown endpoint type in completion handler\n", in usb_urb_complete()
82 for (i = 0; i < stream->urbs_submitted; i++) { in usb_urb_killv2()
83 dev_dbg(&stream->udev->dev, "%s: kill urb=%d\n", __func__, i); in usb_urb_killv2()
85 usb_kill_urb(stream->urb_list[i]); in usb_urb_killv2()
87 stream->urbs_submitted = 0; in usb_urb_killv2()
102 for (i = 0; i < stream->urbs_initialized; i++) { in usb_urb_submitv2()
103 dev_dbg(&stream->udev->dev, "%s: submit urb=%d\n", __func__, i); in usb_urb_submitv2()
104 ret = usb_submit_urb(stream->urb_list[i], GFP_ATOMIC); in usb_urb_submitv2()
106 dev_err(&stream->udev->dev, in usb_urb_submitv2()
107 "%s: could not submit urb no. %d - get them all back\n", in usb_urb_submitv2()
112 stream->urbs_submitted++; in usb_urb_submitv2()
123 for (i = stream->urbs_initialized - 1; i >= 0; i--) { in usb_urb_free_urbs()
124 if (stream->urb_list[i]) { in usb_urb_free_urbs()
125 dev_dbg(&stream->udev->dev, "%s: free urb=%d\n", in usb_urb_free_urbs()
128 usb_free_urb(stream->urb_list[i]); in usb_urb_free_urbs()
131 stream->urbs_initialized = 0; in usb_urb_free_urbs()
141 for (i = 0; i < stream->props.count; i++) { in usb_urb_alloc_bulk_urbs()
142 dev_dbg(&stream->udev->dev, "%s: alloc urb=%d\n", __func__, i); in usb_urb_alloc_bulk_urbs()
143 stream->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); in usb_urb_alloc_bulk_urbs()
144 if (!stream->urb_list[i]) { in usb_urb_alloc_bulk_urbs()
145 dev_dbg(&stream->udev->dev, "%s: failed\n", __func__); in usb_urb_alloc_bulk_urbs()
147 usb_free_urb(stream->urb_list[j]); in usb_urb_alloc_bulk_urbs()
148 return -ENOMEM; in usb_urb_alloc_bulk_urbs()
150 usb_fill_bulk_urb(stream->urb_list[i], in usb_urb_alloc_bulk_urbs()
151 stream->udev, in usb_urb_alloc_bulk_urbs()
152 usb_rcvbulkpipe(stream->udev, in usb_urb_alloc_bulk_urbs()
153 stream->props.endpoint), in usb_urb_alloc_bulk_urbs()
154 stream->buf_list[i], in usb_urb_alloc_bulk_urbs()
155 stream->props.u.bulk.buffersize, in usb_urb_alloc_bulk_urbs()
158 stream->urbs_initialized++; in usb_urb_alloc_bulk_urbs()
168 for (i = 0; i < stream->props.count; i++) { in usb_urb_alloc_isoc_urbs()
171 dev_dbg(&stream->udev->dev, "%s: alloc urb=%d\n", __func__, i); in usb_urb_alloc_isoc_urbs()
172 stream->urb_list[i] = usb_alloc_urb( in usb_urb_alloc_isoc_urbs()
173 stream->props.u.isoc.framesperurb, GFP_ATOMIC); in usb_urb_alloc_isoc_urbs()
174 if (!stream->urb_list[i]) { in usb_urb_alloc_isoc_urbs()
175 dev_dbg(&stream->udev->dev, "%s: failed\n", __func__); in usb_urb_alloc_isoc_urbs()
177 usb_free_urb(stream->urb_list[j]); in usb_urb_alloc_isoc_urbs()
178 return -ENOMEM; in usb_urb_alloc_isoc_urbs()
181 urb = stream->urb_list[i]; in usb_urb_alloc_isoc_urbs()
183 urb->dev = stream->udev; in usb_urb_alloc_isoc_urbs()
184 urb->context = stream; in usb_urb_alloc_isoc_urbs()
185 urb->complete = usb_urb_complete; in usb_urb_alloc_isoc_urbs()
186 urb->pipe = usb_rcvisocpipe(stream->udev, in usb_urb_alloc_isoc_urbs()
187 stream->props.endpoint); in usb_urb_alloc_isoc_urbs()
188 urb->transfer_flags = URB_ISO_ASAP; in usb_urb_alloc_isoc_urbs()
189 urb->interval = stream->props.u.isoc.interval; in usb_urb_alloc_isoc_urbs()
190 urb->number_of_packets = stream->props.u.isoc.framesperurb; in usb_urb_alloc_isoc_urbs()
191 urb->transfer_buffer_length = stream->props.u.isoc.framesize * in usb_urb_alloc_isoc_urbs()
192 stream->props.u.isoc.framesperurb; in usb_urb_alloc_isoc_urbs()
193 urb->transfer_buffer = stream->buf_list[i]; in usb_urb_alloc_isoc_urbs()
195 for (j = 0; j < stream->props.u.isoc.framesperurb; j++) { in usb_urb_alloc_isoc_urbs()
196 urb->iso_frame_desc[j].offset = frame_offset; in usb_urb_alloc_isoc_urbs()
197 urb->iso_frame_desc[j].length = in usb_urb_alloc_isoc_urbs()
198 stream->props.u.isoc.framesize; in usb_urb_alloc_isoc_urbs()
199 frame_offset += stream->props.u.isoc.framesize; in usb_urb_alloc_isoc_urbs()
202 stream->urbs_initialized++; in usb_urb_alloc_isoc_urbs()
209 if (stream->state & USB_STATE_URB_BUF) { in usb_free_stream_buffers()
210 while (stream->buf_num) { in usb_free_stream_buffers()
211 stream->buf_num--; in usb_free_stream_buffers()
212 kfree(stream->buf_list[stream->buf_num]); in usb_free_stream_buffers()
216 stream->state &= ~USB_STATE_URB_BUF; in usb_free_stream_buffers()
224 stream->buf_num = 0; in usb_alloc_stream_buffers()
225 stream->buf_size = size; in usb_alloc_stream_buffers()
227 dev_dbg(&stream->udev->dev, in usb_alloc_stream_buffers()
228 "%s: all in all I will use %lu bytes for streaming\n", in usb_alloc_stream_buffers()
231 for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { in usb_alloc_stream_buffers()
232 stream->buf_list[stream->buf_num] = kzalloc(size, GFP_ATOMIC); in usb_alloc_stream_buffers()
233 if (!stream->buf_list[stream->buf_num]) { in usb_alloc_stream_buffers()
234 dev_dbg(&stream->udev->dev, "%s: alloc buf=%d failed\n", in usb_alloc_stream_buffers()
235 __func__, stream->buf_num); in usb_alloc_stream_buffers()
237 return -ENOMEM; in usb_alloc_stream_buffers()
240 dev_dbg(&stream->udev->dev, "%s: alloc buf=%d %p (dma %llu)\n", in usb_alloc_stream_buffers()
241 __func__, stream->buf_num, in usb_alloc_stream_buffers()
242 stream->buf_list[stream->buf_num], in usb_alloc_stream_buffers()
243 (long long)stream->dma_addr[stream->buf_num]); in usb_alloc_stream_buffers()
244 stream->state |= USB_STATE_URB_BUF; in usb_alloc_stream_buffers()
259 if (props->type == USB_BULK) { in usb_urb_reconfig()
260 buf_size = stream->props.u.bulk.buffersize; in usb_urb_reconfig()
261 } else if (props->type == USB_ISOC) { in usb_urb_reconfig()
262 buf_size = props->u.isoc.framesize * props->u.isoc.framesperurb; in usb_urb_reconfig()
264 dev_err(&stream->udev->dev, "%s: invalid endpoint type=%d\n", in usb_urb_reconfig()
265 KBUILD_MODNAME, props->type); in usb_urb_reconfig()
266 return -EINVAL; in usb_urb_reconfig()
269 if (stream->buf_num < props->count || stream->buf_size < buf_size) { in usb_urb_reconfig()
270 dev_err(&stream->udev->dev, in usb_urb_reconfig()
273 return -EINVAL; in usb_urb_reconfig()
277 if (stream->props.type == props->type && in usb_urb_reconfig()
278 stream->props.count == props->count && in usb_urb_reconfig()
279 stream->props.endpoint == props->endpoint) { in usb_urb_reconfig()
280 if (props->type == USB_BULK && in usb_urb_reconfig()
281 props->u.bulk.buffersize == in usb_urb_reconfig()
282 stream->props.u.bulk.buffersize) in usb_urb_reconfig()
284 else if (props->type == USB_ISOC && in usb_urb_reconfig()
285 props->u.isoc.framesperurb == in usb_urb_reconfig()
286 stream->props.u.isoc.framesperurb && in usb_urb_reconfig()
287 props->u.isoc.framesize == in usb_urb_reconfig()
288 stream->props.u.isoc.framesize && in usb_urb_reconfig()
289 props->u.isoc.interval == in usb_urb_reconfig()
290 stream->props.u.isoc.interval) in usb_urb_reconfig()
294 dev_dbg(&stream->udev->dev, "%s: re-alloc urbs\n", __func__); in usb_urb_reconfig()
297 memcpy(&stream->props, props, sizeof(*props)); in usb_urb_reconfig()
298 if (props->type == USB_BULK) in usb_urb_reconfig()
300 else if (props->type == USB_ISOC) in usb_urb_reconfig()
312 return -EINVAL; in usb_urb_initv2()
314 memcpy(&stream->props, props, sizeof(*props)); in usb_urb_initv2()
316 if (!stream->complete) { in usb_urb_initv2()
317 dev_err(&stream->udev->dev, in usb_urb_initv2()
318 "%s: there is no data callback - this doesn't make sense\n", in usb_urb_initv2()
320 return -EINVAL; in usb_urb_initv2()
323 switch (stream->props.type) { in usb_urb_initv2()
325 ret = usb_alloc_stream_buffers(stream, stream->props.count, in usb_urb_initv2()
326 stream->props.u.bulk.buffersize); in usb_urb_initv2()
332 ret = usb_alloc_stream_buffers(stream, stream->props.count, in usb_urb_initv2()
333 stream->props.u.isoc.framesize * in usb_urb_initv2()
334 stream->props.u.isoc.framesperurb); in usb_urb_initv2()
340 dev_err(&stream->udev->dev, in usb_urb_initv2()
341 "%s: unknown urb-type for data transfer\n", in usb_urb_initv2()
343 return -EINVAL; in usb_urb_initv2()