mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 19:07:52 +00:00
usb: gadget: uvc: queue empty isoc requests if no video buffer is available
[ Upstream commit c3ff12a92b
]
ISOC transfers expect a certain cadence of requests being queued. Not
keeping up with the expected rate of requests results in missed ISOC
transfers (EXDEV). The application layer may or may not produce video
frames to match this expectation, so uvc gadget driver must handle cases
where the application is not queuing up buffers fast enough to fulfill
ISOC requirements.
Currently, uvc gadget driver waits for new video buffer to become available
before queuing up usb requests. With this patch the gadget driver queues up
0 length usb requests whenever there are no video buffers available. The
USB controller's complete callback is used as the limiter for how quickly
the 0 length packets will be queued. Video buffers are still queued as
soon as they become available.
Link: https://lore.kernel.org/CAMHf4WKbi6KBPQztj9FA4kPvESc1fVKrC8G73-cs6tTeQby9=w@mail.gmail.com/
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20230508231103.1621375-1-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
e20a23b342
commit
61c7abd743
1 changed files with 24 additions and 8 deletions
|
@ -386,6 +386,9 @@ static void uvcg_video_pump(struct work_struct *work)
|
||||||
struct uvc_buffer *buf;
|
struct uvc_buffer *buf;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret;
|
int ret;
|
||||||
|
bool buf_int;
|
||||||
|
/* video->max_payload_size is only set when using bulk transfer */
|
||||||
|
bool is_bulk = video->max_payload_size;
|
||||||
|
|
||||||
while (video->ep->enabled) {
|
while (video->ep->enabled) {
|
||||||
/*
|
/*
|
||||||
|
@ -408,20 +411,35 @@ static void uvcg_video_pump(struct work_struct *work)
|
||||||
*/
|
*/
|
||||||
spin_lock_irqsave(&queue->irqlock, flags);
|
spin_lock_irqsave(&queue->irqlock, flags);
|
||||||
buf = uvcg_queue_head(queue);
|
buf = uvcg_queue_head(queue);
|
||||||
if (buf == NULL) {
|
|
||||||
|
if (buf != NULL) {
|
||||||
|
video->encode(req, video, buf);
|
||||||
|
/* Always interrupt for the last request of a video buffer */
|
||||||
|
buf_int = buf->state == UVC_BUF_STATE_DONE;
|
||||||
|
} else if (!(queue->flags & UVC_QUEUE_DISCONNECTED) && !is_bulk) {
|
||||||
|
/*
|
||||||
|
* No video buffer available; the queue is still connected and
|
||||||
|
* we're traferring over ISOC. Queue a 0 length request to
|
||||||
|
* prevent missed ISOC transfers.
|
||||||
|
*/
|
||||||
|
req->length = 0;
|
||||||
|
buf_int = false;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Either queue has been disconnected or no video buffer
|
||||||
|
* available to bulk transfer. Either way, stop processing
|
||||||
|
* further.
|
||||||
|
*/
|
||||||
spin_unlock_irqrestore(&queue->irqlock, flags);
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
video->encode(req, video, buf);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With usb3 we have more requests. This will decrease the
|
* With usb3 we have more requests. This will decrease the
|
||||||
* interrupt load to a quarter but also catches the corner
|
* interrupt load to a quarter but also catches the corner
|
||||||
* cases, which needs to be handled.
|
* cases, which needs to be handled.
|
||||||
*/
|
*/
|
||||||
if (list_empty(&video->req_free) ||
|
if (list_empty(&video->req_free) || buf_int ||
|
||||||
buf->state == UVC_BUF_STATE_DONE ||
|
|
||||||
!(video->req_int_count %
|
!(video->req_int_count %
|
||||||
DIV_ROUND_UP(video->uvc_num_requests, 4))) {
|
DIV_ROUND_UP(video->uvc_num_requests, 4))) {
|
||||||
video->req_int_count = 0;
|
video->req_int_count = 0;
|
||||||
|
@ -441,7 +459,6 @@ static void uvcg_video_pump(struct work_struct *work)
|
||||||
|
|
||||||
/* Endpoint now owns the request */
|
/* Endpoint now owns the request */
|
||||||
req = NULL;
|
req = NULL;
|
||||||
if (buf->state != UVC_BUF_STATE_DONE)
|
|
||||||
video->req_int_count++;
|
video->req_int_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,4 +544,3 @@ int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc)
|
||||||
V4L2_BUF_TYPE_VIDEO_OUTPUT, &video->mutex);
|
V4L2_BUF_TYPE_VIDEO_OUTPUT, &video->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue