// SPDX-License-Identifier: GPL-2.0 /* usb-urb.c is part of the DVB USB library. * * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de) * see dvb-usb-init.c for copyright information. * * This file keeps functions for initializing and handling the * BULK and ISOC USB data transfers in a generic way. * Can be used for DVB-only and also, that's the plan, for * Hybrid USB devices (analog and DVB).
*/ #include"dvb_usb_common.h"
/* URB stuff for streaming */
int usb_urb_reconfig(struct usb_data_stream *stream, struct usb_data_stream_properties *props);
staticvoid usb_urb_complete(struct urb *urb)
{ struct usb_data_stream *stream = urb->context; int ptype = usb_pipetype(urb->pipe); int i;
u8 *b;
switch (urb->status) { case 0: /* success */ case -ETIMEDOUT: /* NAK */ break; case -ECONNRESET: /* kill */ case -ENOENT: case -ESHUTDOWN: return; default: /* error */
dev_dbg_ratelimited(&stream->udev->dev, "%s: urb completion failed=%d\n",
__func__, urb->status); break;
}
b = (u8 *) urb->transfer_buffer; switch (ptype) { case PIPE_ISOCHRONOUS: for (i = 0; i < urb->number_of_packets; i++) { if (urb->iso_frame_desc[i].status != 0)
dev_dbg(&stream->udev->dev, "%s: iso frame descriptor has an error=%d\n",
__func__,
urb->iso_frame_desc[i].status); elseif (urb->iso_frame_desc[i].actual_length > 0)
stream->complete(stream,
b + urb->iso_frame_desc[i].offset,
urb->iso_frame_desc[i].actual_length);
urb->iso_frame_desc[i].status = 0;
urb->iso_frame_desc[i].actual_length = 0;
} break; case PIPE_BULK: if (urb->actual_length > 0)
stream->complete(stream, b, urb->actual_length); break; default:
dev_err(&stream->udev->dev, "%s: unknown endpoint type in completion handler\n",
KBUILD_MODNAME); return;
}
usb_submit_urb(urb, GFP_ATOMIC);
}
int usb_urb_killv2(struct usb_data_stream *stream)
{ int i; for (i = 0; i < stream->urbs_submitted; i++) {
dev_dbg(&stream->udev->dev, "%s: kill urb=%d\n", __func__, i); /* stop the URB */
usb_kill_urb(stream->urb_list[i]);
}
stream->urbs_submitted = 0; return 0;
}
int usb_urb_submitv2(struct usb_data_stream *stream, struct usb_data_stream_properties *props)
{ int i, ret;
if (props) {
ret = usb_urb_reconfig(stream, props); if (ret < 0) return ret;
}
for (i = 0; i < stream->urbs_initialized; i++) {
dev_dbg(&stream->udev->dev, "%s: submit urb=%d\n", __func__, i);
ret = usb_submit_urb(stream->urb_list[i], GFP_ATOMIC); if (ret) {
dev_err(&stream->udev->dev, "%s: could not submit urb no. %d - get them all back\n",
KBUILD_MODNAME, i);
usb_urb_killv2(stream); return ret;
}
stream->urbs_submitted++;
} return 0;
}
staticint usb_urb_free_urbs(struct usb_data_stream *stream)
{ int i;
usb_urb_killv2(stream);
for (i = stream->urbs_initialized - 1; i >= 0; i--) { if (stream->urb_list[i]) {
dev_dbg(&stream->udev->dev, "%s: free urb=%d\n",
__func__, i); /* free the URBs */
usb_free_urb(stream->urb_list[i]);
}
}
stream->urbs_initialized = 0;
return 0;
}
staticint usb_urb_alloc_bulk_urbs(struct usb_data_stream *stream)
{ int i, j;
/* allocate the URBs */ for (i = 0; i < stream->props.count; i++) {
dev_dbg(&stream->udev->dev, "%s: alloc urb=%d\n", __func__, i);
stream->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); if (!stream->urb_list[i]) {
dev_dbg(&stream->udev->dev, "%s: failed\n", __func__); for (j = 0; j < i; j++)
usb_free_urb(stream->urb_list[j]); return -ENOMEM;
}
usb_fill_bulk_urb(stream->urb_list[i],
stream->udev,
usb_rcvbulkpipe(stream->udev,
stream->props.endpoint),
stream->buf_list[i],
stream->props.u.bulk.buffersize,
usb_urb_complete, stream);
stream->urbs_initialized++;
} return 0;
}
staticint usb_urb_alloc_isoc_urbs(struct usb_data_stream *stream)
{ int i, j;
/* allocate the URBs */ for (i = 0; i < stream->props.count; i++) { struct urb *urb; int frame_offset = 0;
dev_dbg(&stream->udev->dev, "%s: alloc urb=%d\n", __func__, i);
stream->urb_list[i] = usb_alloc_urb(
stream->props.u.isoc.framesperurb, GFP_ATOMIC); if (!stream->urb_list[i]) {
dev_dbg(&stream->udev->dev, "%s: failed\n", __func__); for (j = 0; j < i; j++)
usb_free_urb(stream->urb_list[j]); return -ENOMEM;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.