From patchwork Mon Jan 11 13:02:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 360462 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp2505877ejs; Mon, 11 Jan 2021 05:23:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMZ+CAsDuGk5o8tYAWgYtcPxbSxe6mFBq1Zd4dOCLY6NenSRB8a8Z8i4zAiguw53L+dVBW X-Received: by 2002:a50:d491:: with SMTP id s17mr13810685edi.169.1610371408534; Mon, 11 Jan 2021 05:23:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610371408; cv=none; d=google.com; s=arc-20160816; b=z2Gs1X6Z7NjgIgtlpa0dkxB1vov/QxS5X7OTF4qi/0mjIuTFE/U1qekzwiv+7u7tuz 4xEQ/Gj2RtEViKwrbYE9SgUlAPlZyo7GUkTkWR0VeCP8aXRq5vsjRmqaAyMcYv3/2xL3 YzsImABchp/5jOTfTMiSXBGsaIG8adSvGKFm8UwoHMdYpnJbRkNnvJM5bSvmYpu/9w9N X/kOsB3M5TKYWE0NIfWtvwy3RHxvdN2ZoqIXB4XW7RutnNjy15wCBIaXY7vWlqw+sFAZ 3quUvP7ITqYM/xNuOSEV+EQNSFA4Vb3LJ7us1rO4JOqyOgFmFt+J8sY+BJsXcH0+bNEl qncA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UsU2c4HJpc7DKboD/CciCPM+clsUXgFw7oJyezGWgOA=; b=wbY2wVk/UBmythrre9w0tRJ/X2XkL2SYAckQot5h+nv1gCnNYXTWa0Nd41o4pkDGFQ DKlBCleHiMx8GmXkP4OnMIrY1Gq2N/hBHiMKl+m1P2fA/7szNuh+F7t4z3yc1+dQ/00P QQvrttyK3q2mS8rt1SNVSf+/ZTNDfzD3MxlBrVxQ+3lxGlmVkP94/bJV/0Vp0MOgADwq mrKAU7jFcvuuDrYTV+zSbT7G5Cml+GBxoNyviKovifJFbSARCWIVfdl2iH/5kRHfXJQH gG1Ev/XKtFDq7GDLpnSjP8hbteNoLxRg/nnM6x7LoNic8Q+3e7VrB3SrVTYrym5CHxRx Iu7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jExvUIkW; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si6449000ejw.12.2021.01.11.05.23.28; Mon, 11 Jan 2021 05:23:28 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jExvUIkW; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730378AbhAKNWq (ORCPT + 14 others); Mon, 11 Jan 2021 08:22:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:37102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733135AbhAKNSg (ORCPT ); Mon, 11 Jan 2021 08:18:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1A67C2255F; Mon, 11 Jan 2021 13:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610371074; bh=fbNeV+OFVNAnSjGoJE6Mc64L/Ho9ndObvVQwda+8Ki4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jExvUIkWuD9A6zBZkzi2YDiMJDj/zviul1Vr6n9x4RZvzsUOJpjaUGUvcPuNd8eB7 /qnnbtL/7SmzFEHdhArosrFdIubnK6b+bj5n3B2lMjcoWbFWrVUaFswqgaxNMVLEDY l/oiJ3Qqvnwc9g6wTwYd7111Gr8Ypm2jNXGXCZ2s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jerome Brunet Subject: [PATCH 5.10 100/145] usb: gadget: f_uac2: reset wMaxPacketSize Date: Mon, 11 Jan 2021 14:02:04 +0100 Message-Id: <20210111130053.335695412@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130048.499958175@linuxfoundation.org> References: <20210111130048.499958175@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jerome Brunet commit 9389044f27081d6ec77730c36d5bf9a1288bcda2 upstream. With commit 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth") wMaxPacketSize is computed dynamically but the value is never reset. Because of this, the actual maximum packet size can only decrease each time the audio gadget is instantiated. Reset the endpoint maximum packet size and mark wMaxPacketSize as dynamic to solve the problem. Fixes: 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth") Signed-off-by: Jerome Brunet Cc: stable Link: https://lore.kernel.org/r/20201221173531.215169-2-jbrunet@baylibre.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_uac2.c | 69 +++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 14 deletions(-) --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -271,7 +271,7 @@ static struct usb_endpoint_descriptor fs .bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1023), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 1, }; @@ -280,7 +280,7 @@ static struct usb_endpoint_descriptor hs .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1024), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 4, }; @@ -348,7 +348,7 @@ static struct usb_endpoint_descriptor fs .bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1023), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 1, }; @@ -357,7 +357,7 @@ static struct usb_endpoint_descriptor hs .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, - .wMaxPacketSize = cpu_to_le16(1024), + /* .wMaxPacketSize = DYNAMIC */ .bInterval = 4, }; @@ -444,12 +444,28 @@ struct cntrl_range_lay3 { __le32 dRES; } __packed; -static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, +static int set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts, struct usb_endpoint_descriptor *ep_desc, - unsigned int factor, bool is_playback) + enum usb_device_speed speed, bool is_playback) { int chmask, srate, ssize; - u16 max_packet_size; + u16 max_size_bw, max_size_ep; + unsigned int factor; + + switch (speed) { + case USB_SPEED_FULL: + max_size_ep = 1023; + factor = 1000; + break; + + case USB_SPEED_HIGH: + max_size_ep = 1024; + factor = 8000; + break; + + default: + return -EINVAL; + } if (is_playback) { chmask = uac2_opts->p_chmask; @@ -461,10 +477,12 @@ static void set_ep_max_packet_size(const ssize = uac2_opts->c_ssize; } - max_packet_size = num_channels(chmask) * ssize * + max_size_bw = num_channels(chmask) * ssize * DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1))); - ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_packet_size, - le16_to_cpu(ep_desc->wMaxPacketSize))); + ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_size_bw, + max_size_ep)); + + return 0; } /* Use macro to overcome line length limitation */ @@ -670,10 +688,33 @@ afunc_bind(struct usb_configuration *cfg } /* Calculate wMaxPacketSize according to audio bandwidth */ - set_ep_max_packet_size(uac2_opts, &fs_epin_desc, 1000, true); - set_ep_max_packet_size(uac2_opts, &fs_epout_desc, 1000, false); - set_ep_max_packet_size(uac2_opts, &hs_epin_desc, 8000, true); - set_ep_max_packet_size(uac2_opts, &hs_epout_desc, 8000, false); + ret = set_ep_max_packet_size(uac2_opts, &fs_epin_desc, USB_SPEED_FULL, + true); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &fs_epout_desc, USB_SPEED_FULL, + false); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &hs_epin_desc, USB_SPEED_HIGH, + true); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } + + ret = set_ep_max_packet_size(uac2_opts, &hs_epout_desc, USB_SPEED_HIGH, + false); + if (ret < 0) { + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); + return ret; + } if (EPOUT_EN(uac2_opts)) { agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);