From patchwork Fri Jan 12 09:19:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10160123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF807602B3 for ; Fri, 12 Jan 2018 09:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D256288A3 for ; Fri, 12 Jan 2018 09:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 814CB2893C; Fri, 12 Jan 2018 09:21:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, URIBL_GREY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10AE7288A3 for ; Fri, 12 Jan 2018 09:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932489AbeALJTe (ORCPT ); Fri, 12 Jan 2018 04:19:34 -0500 Received: from o1682455182.outbound-mail.sendgrid.net ([168.245.5.182]:2453 "EHLO o1682455182.outbound-mail.sendgrid.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754549AbeALJT0 (ORCPT ); Fri, 12 Jan 2018 04:19:26 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:cc:subject:in-reply-to:references:in-reply-to:references; s=smtpapi; bh=LgUYVyrPUap3ULg3zN10nAStZP4=; b=hm66DilRh87/nAe9SN wMYOxEXHg94ccQZZqzkcGL187N/a0bJ+u77UGVkgPlEqOMOqSnaHVP7YVFVE5537 sKq8QDel7dtanKp5UtboeVWeKfhjH32wUFxGdaoh/496j88AEBgVPw83bSUNxD28 /2F1L2FyKlfp0AujgzZ7N6lIU= Received: by filter0022p3las1.sendgrid.net with SMTP id filter0022p3las1-12416-5A587D9D-17 2018-01-12 09:19:25.585378513 +0000 UTC Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by ismtpd0005p1lon1.sendgrid.net (SG) with ESMTP id DTb3fo0oQ_C4lgV3xZwHzg Fri, 12 Jan 2018 09:19:25.264 +0000 (UTC) From: Kieran Bingham To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Guennadi Liakhovetski , Laurent Pinchart , Olivier BRAUN , Troy Kisky , Kieran Bingham Subject: [RFT PATCH v3 1/6] uvcvideo: Refactor URB descriptors Date: Fri, 12 Jan 2018 09:19:25 +0000 (UTC) Message-Id: <38bb2b10b9d4db1d44cf22d345c064955ddb379e.1515748369.git-series.kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-SG-EID: Tfq0zQjjJFmIKL8hyrOr6KT7wyjsEm7XZZskPfLyBPI1kUvc/uzQ3llI2oXGSWhTGb09eLMXPS8lDE FwsaCP1PzfbYIJYPa5pqa6f2I23ufh/9TtVkPbIkTm3M2K3czOT/6pLRPsSMjoDX/ojo3IM/V9a87T hbusitN+68sWZkWQ0NLMJfuEqq9nrHVnGSqk+/Gks0QIC6ge+W7Vc08lLHauRQjpwPI/TJ9DKNNnuM JU8VK0u9QMCWWXJwf22mn+ Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We currently store three separate arrays for each URB reference we hold. Objectify the data needed to track URBs into a single uvc_urb structure, allowing better object management and tracking of the URB. All accesses to the data pointers through stream, are converted to use a uvc_urb pointer for consistency. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v2: - Re-describe URB context structure - Re-name uvc_urb->{urb_buffer,urb_dma}{buffer,dma} --- drivers/media/usb/uvc/uvc_video.c | 49 +++++++++++++++++++------------- drivers/media/usb/uvc/uvcvideo.h | 18 ++++++++++-- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 73cd44e8bd81..e57c5f52c73b 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1357,14 +1357,16 @@ static void uvc_free_urb_buffers(struct uvc_streaming *stream) unsigned int i; for (i = 0; i < UVC_URBS; ++i) { - if (stream->urb_buffer[i]) { + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + + if (uvc_urb->buffer) { #ifndef CONFIG_DMA_NONCOHERENT usb_free_coherent(stream->dev->udev, stream->urb_size, - stream->urb_buffer[i], stream->urb_dma[i]); + uvc_urb->buffer, uvc_urb->dma); #else - kfree(stream->urb_buffer[i]); + kfree(uvc_urb->buffer); #endif - stream->urb_buffer[i] = NULL; + uvc_urb->buffer = NULL; } } @@ -1402,16 +1404,18 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, /* Retry allocations until one succeed. */ for (; npackets > 1; npackets /= 2) { for (i = 0; i < UVC_URBS; ++i) { + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + stream->urb_size = psize * npackets; #ifndef CONFIG_DMA_NONCOHERENT - stream->urb_buffer[i] = usb_alloc_coherent( + uvc_urb->buffer = usb_alloc_coherent( stream->dev->udev, stream->urb_size, - gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]); + gfp_flags | __GFP_NOWARN, &uvc_urb->dma); #else - stream->urb_buffer[i] = + uvc_urb->buffer = kmalloc(stream->urb_size, gfp_flags | __GFP_NOWARN); #endif - if (!stream->urb_buffer[i]) { + if (!uvc_urb->buffer) { uvc_free_urb_buffers(stream); break; } @@ -1441,13 +1445,15 @@ static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers) uvc_video_stats_stop(stream); for (i = 0; i < UVC_URBS; ++i) { - urb = stream->urb[i]; + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + + urb = uvc_urb->urb; if (urb == NULL) continue; usb_kill_urb(urb); usb_free_urb(urb); - stream->urb[i] = NULL; + uvc_urb->urb = NULL; } if (free_buffers) @@ -1502,6 +1508,8 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, size = npackets * psize; for (i = 0; i < UVC_URBS; ++i) { + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + urb = usb_alloc_urb(npackets, gfp_flags); if (urb == NULL) { uvc_uninit_video(stream, 1); @@ -1514,12 +1522,12 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, ep->desc.bEndpointAddress); #ifndef CONFIG_DMA_NONCOHERENT urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; - urb->transfer_dma = stream->urb_dma[i]; + urb->transfer_dma = uvc_urb->dma; #else urb->transfer_flags = URB_ISO_ASAP; #endif urb->interval = ep->desc.bInterval; - urb->transfer_buffer = stream->urb_buffer[i]; + urb->transfer_buffer = uvc_urb->buffer; urb->complete = uvc_video_complete; urb->number_of_packets = npackets; urb->transfer_buffer_length = size; @@ -1529,7 +1537,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, urb->iso_frame_desc[j].length = psize; } - stream->urb[i] = urb; + uvc_urb->urb = urb; } return 0; @@ -1568,21 +1576,22 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream, size = 0; for (i = 0; i < UVC_URBS; ++i) { + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + urb = usb_alloc_urb(0, gfp_flags); if (urb == NULL) { uvc_uninit_video(stream, 1); return -ENOMEM; } - usb_fill_bulk_urb(urb, stream->dev->udev, pipe, - stream->urb_buffer[i], size, uvc_video_complete, - stream); + usb_fill_bulk_urb(urb, stream->dev->udev, pipe, uvc_urb->buffer, + size, uvc_video_complete, stream); #ifndef CONFIG_DMA_NONCOHERENT urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; - urb->transfer_dma = stream->urb_dma[i]; + urb->transfer_dma = uvc_urb->dma; #endif - stream->urb[i] = urb; + uvc_urb->urb = urb; } return 0; @@ -1673,7 +1682,9 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) /* Submit the URBs. */ for (i = 0; i < UVC_URBS; ++i) { - ret = usb_submit_urb(stream->urb[i], gfp_flags); + struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; + + ret = usb_submit_urb(uvc_urb->urb, gfp_flags); if (ret < 0) { uvc_printk(KERN_ERR, "Failed to submit URB %u " "(%d).\n", i, ret); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 19e725e2bda5..2a5dc7f09463 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -479,6 +479,20 @@ struct uvc_stats_stream { unsigned int max_sof; /* Maximum STC.SOF value */ }; +/** + * struct uvc_urb - URB context management structure + * + * @urb: the URB described by this context structure + * @buffer: memory storage for the URB + * @dma: DMA coherent addressing for the urb_buffer + */ +struct uvc_urb { + struct urb *urb; + + char *buffer; + dma_addr_t dma; +}; + struct uvc_streaming { struct list_head list; struct uvc_device *dev; @@ -521,9 +535,7 @@ struct uvc_streaming { __u32 max_payload_size; } bulk; - struct urb *urb[UVC_URBS]; - char *urb_buffer[UVC_URBS]; - dma_addr_t urb_dma[UVC_URBS]; + struct uvc_urb uvc_urb[UVC_URBS]; unsigned int urb_size; __u32 sequence;