Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4350916pxu; Mon, 21 Dec 2020 10:11:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzchby3TAKpwNQefHWjrXVSOLGsIHgEZSgP5oQs5A25gHtOSwdjMe06knt4DYUtS9LMF8xt X-Received: by 2002:a17:906:4443:: with SMTP id i3mr14692925ejp.133.1608574274128; Mon, 21 Dec 2020 10:11:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608574274; cv=none; d=google.com; s=arc-20160816; b=R6FcaMaZ9XQhh1zSs42CCguu8d+1xvWPLlEtOyjOdfbbwGcfk8G+PVZOnPq0rYy09G WpxlMM8+Rz+KGbxXtuh7RYzJeNn3goA0ikeFm2/NLdNhxfkm1/Iz4FcmNpwUGLc3ZEUu zg0Xj7GW3u7WdXpNEveusafFLS5qylydUhEdzSHAzTnFzehyyMIU74qzYuaszxginEH1 i3UhxGPfH7GN5rz9OX/1ez/TG45+tMZBeKIJCYrAmnlH9SP65rn0acwsFuJi7Czt9mux mx8qZyfw27UNiOX3kDyMkRv20cxoJbQ4eHQdqLyCgN4Gn7SfhyKO6B2NGrdi7p40hgBJ Oadg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=kLfIraLbwNVZoftJrmdqtP6mIFwB2yCs+x3qC1QWzpMg3/5jhrj1oHhuL03gLMekh8 8ZHQnPowYaEOUBHJbFATefBspBgaf6rSJrcQUovUZIl2bllwi4VyBtMjjuEQCYiBq8Qy /VTD87rmLEzRF/Uud+b5UTUu2VP1YTonNpIZrmeD692Pm7QjEZYIPOOq9Y7CikIwxE4J I3Zv4q7fiLCAr/tI7sG4jOip6391bEpNkId9bTKrxwLL/azCof//UY+N0IbswXkvdKtg 1VfnEbpP7F+MHzz49NSqlN1UTjAPOGySEeAcQfKrFtJ6CmGT3NjlmyMWhPsmqSWZ/8LB vZTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=HFwFklBF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si11287006edy.18.2020.12.21.10.10.51; Mon, 21 Dec 2020 10:11:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=HFwFklBF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbgLUSHg (ORCPT + 99 others); Mon, 21 Dec 2020 13:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbgLUSHg (ORCPT ); Mon, 21 Dec 2020 13:07:36 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948F9C061793 for ; Mon, 21 Dec 2020 10:06:55 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id 23so25766157lfg.10 for ; Mon, 21 Dec 2020 10:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=HFwFklBFejfRIGWkA2tHTHhTKeW2c1LNBGTqxXTKD8QsawAuLODDYMDiuRMSFan+Wm 2rKLN9+sFiXkjIMuxnrl7qH6x2o5G7XG5WNuNvEZjd8hgK8AV3mWH9yCbu+f7C3nn1Qp p1v8v+XYry0BSpgjoRfQIe+M3AyEpCLKrkkzwGR1oCndoh1xWPKmlmvKZhvvoHEbHoZ/ JyTTI2eYgMghTdci/REOKrK2r/LfuBX+gmEwdHYZ7tTT8kxocXTb4Gf01aHgSotTTdE1 hAsD/tagSBGz7mxfgE3xNyotXr7+t1E6zzx1s+2G2unQvXEt07vAx25PyBwuCVaKB0ND X+zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UTSIWNrCdfFZGrfLRZuDMagz0Cnd73ZK/iAZinL3Hdk=; b=J5x+ytcwvCTkkeZxekmd63oqVanwlE/zlERFaOrU9IZod6Ow1f/Ktv11XQWOtNod7N Vn4R92Moy6ww/pryv6yJ7m2IoNLKUP1H+EJEc+Y0aLXuF8b0kpvb1/Rw6m48OvQeoHjZ iGTJOmVjpuPoLlKLNohNZioUpSSlGn3HeElmYIAu9zj+DGCotKQc2jR/s91Mm7XVehqS 7ud/Xl2EDqZAPoM+8O0QzfonvatTOmcVEWIupe+ZINLifwjqWBfAZZR1DZ/vUtZNQYQQ rpL7K6waoJzeFcr6PeEo/ho+JUIX7Xpt0qFhaGPCRxkCv8XVgi+14ds75noDrHQoXThb KqvQ== X-Gm-Message-State: AOAM531dFxAF3GQFlrF3gWi6Sr+5pT3kG5bntzNxKwP5q82dEh/Kmek8 cNUv9Qis60h7qZT7bLpNgJ8fzi5AOeJp80Yr X-Received: by 2002:a17:906:e247:: with SMTP id gq7mr16632490ejb.27.1608572141971; Mon, 21 Dec 2020 09:35:41 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:41 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] usb: gadget: f_uac2: reset wMaxPacketSize Date: Mon, 21 Dec 2020 18:35:28 +0100 Message-Id: <20201221173531.215169-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/usb/gadget/function/f_uac2.c | 69 ++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 3633df6d7610..5d960b6603b6 100644 --- 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_epout_desc = { .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_epout_desc = { .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_epin_desc = { .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_epin_desc = { .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 struct f_uac2_opts *uac2_opts, 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, struct usb_function *fn) } /* 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); -- 2.29.2