From patchwork Thu Jul 23 02:12:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2763F13B1 for ; Thu, 23 Jul 2020 02:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E9E920825 for ; Thu, 23 Jul 2020 02:12:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="lXIlIQyA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387741AbgGWCMJ (ORCPT ); Wed, 22 Jul 2020 22:12:09 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:54234 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMJ (ORCPT ); Wed, 22 Jul 2020 22:12:09 -0400 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id EB9DE4017D; Thu, 23 Jul 2020 02:12:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470329; bh=9XQ5SjIbadgCY7STByzhGubx8St7cwRl1Fv8D7kNxO8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=lXIlIQyAY13es9jC0fWHFbqm7cu6tXHTi+VlVL1MizsrxJllOU+HGGzSG3IEpk1LF iU+fUhzOKRVamjsMcXattUA03fZkX/SlE+1xC1ks3ISxud++ejzVyR2x2fqR0O9F/q waWpeke07A6jwJnOONaWycAJ/ifrbPlH7YlrhmuE1kKjNRGdDIsKI3jJljBtqW9KNU y3YqIKiK5layhwZTaygyhHsDxWjTWEHV/7J5FoOj9SF22Z0Zo7q/+LRraZs3kvCNqj Ya8/AzI+Uu87lK7MPqgvzRrVAC68FrCm4D/pCXU8Q4FkLebgcqrOu0VfYXOmSi9baQ zIfsBnU/3K2nw== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id D6E78A0096; Thu, 23 Jul 2020 02:12:07 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:07 -0700 Date: Wed, 22 Jul 2020 19:12:07 -0700 Message-Id: <162ed8c99ee53a3258e434112956533d622a56e4.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 01/12] usb: ch9: Add sublink speed struct To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org USB 3.2 specification supports dual-lane for super-speed-plus. USB devices may operate at different sublink speeds. To avoid using magic numbers and capture the sublink speed better, introduce the usb_sublink_speed structure and various sublink speed attribute enum. See SSP BOS descriptor in USB 3.2 specification section 9.6.2.5 Signed-off-by: Thinh Nguyen --- Changes in v2: - Move to include/linux/usb/ch9.h instead of under uapi include/linux/usb/ch9.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index 58b83066bea4..f87ef9a2f859 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -36,6 +36,49 @@ #include #include +/* USB 3.2 sublink speed attributes */ + +enum usb_lane_speed_exponent { + USB_LSE_BPS = 0, + USB_LSE_KBPS = 1, + USB_LSE_MBPS = 2, + USB_LSE_GBPS = 3, +}; + +enum usb_sublink_type { + USB_ST_SYMMETRIC_RX = 0, + USB_ST_ASYMMETRIC_RX = 1, + USB_ST_SYMMETRIC_TX = 2, + USB_ST_ASYMMETRIC_TX = 3, +}; + +enum usb_link_protocol { + USB_LP_SS = 0, + USB_LP_SSP = 1, +}; + +/** + * struct usb_sublink_speed - sublink speed attribute + * @id: sublink speed attribute ID (SSID) + * @mantissa: lane speed mantissa + * @exponent: lane speed exponent + * @type: sublink type + * @protocol: sublink protocol + * + * Super-speed-plus supports multiple lanes. Use the sublink speed attributes to + * describe the sublink speed. + * + * See USB 3.2 spec section 9.6.2.6 for super-speed-plus capability for more + * information. + */ +struct usb_sublink_speed { + u8 id; + u16 mantissa; + enum usb_lane_speed_exponent exponent; + enum usb_sublink_type type; + enum usb_link_protocol protocol; +}; + /** * usb_ep_type_string() - Returns human readable-name of the endpoint type. * @ep_type: The endpoint type to return human-readable name for. If it's not From patchwork Thu Jul 23 02:12:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A589E912 for ; Thu, 23 Jul 2020 02:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C76D20781 for ; Thu, 23 Jul 2020 02:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="ZNuQGbTo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387742AbgGWCMR (ORCPT ); Wed, 22 Jul 2020 22:12:17 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34896 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMQ (ORCPT ); Wed, 22 Jul 2020 22:12:16 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 1F53AC0086; Thu, 23 Jul 2020 02:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470336; bh=g3qFGdyHzefE9TjujbwQWhfV63HYmsnVbvCtqWTE5Fg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZNuQGbToUoCzfZdyISED6w6j5IY3OzwF2w6rhwNdUCp1cWL3lNFbMq3WPHTVsZGGL PSpw5INfQJHkk0D+YdSJUlkG0GNhVzMBJCdCaj3z7UN4FhZPqe5+MooeDMlzIi03+w MKiMKM9OkS8w+FN3cJGas7m/W0ZJAg/SbfGuqfXzZsQYUsj8g+kGBJ3WqXxw8LoEDk 4risqDVt0WLvrOS1sw4wiPyhAxr/9M6dzNqeUAHbHKUeuEDVdTTSFR6vC9GV/20vFD YKATY96ZhDyuiA3Br2xbYg48SgQbdsUhRIlFTdl70oPjWGCsoV5wO5lttw4ILPGMBa oQiD/qd1PZg6Q== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 84E44A009A; Thu, 23 Jul 2020 02:12:13 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:13 -0700 Date: Wed, 22 Jul 2020 19:12:13 -0700 Message-Id: <9eef0d01c5b742865424be3c1cbe1c055a038178.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 02/12] usb: gadget: composite: Avoid using magic numbers To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Magic numbers are difficult to read. Use macros for super-speed-plus BOS descriptor attributes in the composite driver. They're self-documented. So there's no need to provide comments as we did previously for the magic numbers. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/composite.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 5c1eb96a5c57..a231ae382ac3 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -743,32 +744,30 @@ static int bos_desc(struct usb_composite_dev *cdev) ssp_cap->bReserved = 0; ssp_cap->wReserved = 0; - /* SSAC = 1 (2 attributes) */ - ssp_cap->bmAttributes = cpu_to_le32(1); + ssp_cap->bmAttributes = + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_ATTRIBS, 1) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_IDS, 0)); - /* Min RX/TX Lane Count = 1 */ ssp_cap->wFunctionalitySupport = - cpu_to_le16((1 << 8) | (1 << 12)); + cpu_to_le16(FIELD_PREP(USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID, 0) | + FIELD_PREP(USB_SSP_MIN_RX_LANE_COUNT, 1) | + FIELD_PREP(USB_SSP_MIN_TX_LANE_COUNT, 1)); - /* - * bmSublinkSpeedAttr[0]: - * ST = Symmetric, RX - * LSE = 3 (Gbps) - * LP = 1 (SuperSpeedPlus) - * LSM = 10 (10 Gbps) - */ ssp_cap->bmSublinkSpeedAttr[0] = - cpu_to_le32((3 << 4) | (1 << 14) | (0xa << 16)); - /* - * bmSublinkSpeedAttr[1] = - * ST = Symmetric, TX - * LSE = 3 (Gbps) - * LP = 1 (SuperSpeedPlus) - * LSM = 10 (10 Gbps) - */ + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, + USB_ST_SYMMETRIC_RX) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); + ssp_cap->bmSublinkSpeedAttr[1] = - cpu_to_le32((3 << 4) | (1 << 14) | - (0xa << 16) | (1 << 7)); + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, + USB_ST_SYMMETRIC_TX) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); } return le16_to_cpu(bos->wTotalLength); From patchwork Thu Jul 23 02:12:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DAB51510 for ; Thu, 23 Jul 2020 02:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33EDC2084D for ; Thu, 23 Jul 2020 02:12:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="gm4EW48e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387744AbgGWCMW (ORCPT ); Wed, 22 Jul 2020 22:12:22 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34900 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMW (ORCPT ); Wed, 22 Jul 2020 22:12:22 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 33167C0086; Thu, 23 Jul 2020 02:12:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470342; bh=8T8xqGrW4BMn3q3RIGcfSf9fegmHzZ9Lpul9Gyr55Eg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=gm4EW48eCR/7ueNhdwGAPfWWl2QLU+dtqUhdA36uG5ZBYclzK//ihL3C0/f7OvzCK QvK1bnJxXXiOMgiPPGefrDus+9CWa4H9CTFzEu1ObqFqv0r0dP71U1I8Whc5nHi3Ix mCpgRC1xCqQnKjgoW1dNWMQuFUoFc7kDgtWQcr4zVKdz7nBoZToeKuerMLdyuIS0XN TwWjO/4p5cVBJ27tbbeZ7XNBosf/r3rsbsCvsvxG1aDWcbB/CGHJDepT7I90QAYDlZ +rBTeQaI3ZXcESYJBj99rEbuGB2iAJjTx7TsVUgw2rVV27AXLjt0WFHd67PHxxQGiu TjdSuKKjWeYSA== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 02F0DA009A; Thu, 23 Jul 2020 02:12:21 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:20 -0700 Date: Wed, 22 Jul 2020 19:12:20 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 03/12] usb: gadget: Expose sublink speed attributes To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The USB 3.2 specification supports dual-lane and different transfer rates for super-speed-plus. Devices operating in super-speed-plus can be gen2x1, gen1x2, or gen2x2. A gadget driver may need to know the gadget's sublink speeds to properly setup its transfer requests and describe its capability in its descriptors. To describe the transfer rate in super-speed-plus fully, let's expose the lane count and sublink speed attributes when operating in super-speed-plus. Signed-off-by: Thinh Nguyen --- Changes in v2: - None include/linux/usb/gadget.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 6a178177e4c9..2ab929eed928 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -338,6 +338,15 @@ struct usb_gadget_ops { * @speed: Speed of current connection to USB host. * @max_speed: Maximal speed the UDC can handle. UDC must support this * and all slower speeds. + * @num_lanes: Number of lanes in use. + * @max_num_lanes: Maximum number of lanes the UDC supports. + * @ssac: Sublink speed attribute count. The number of sublink speed + * attributes is ssac + 1. + * @sublink_speed: Array of sublink speed attributes the UDC supports. Sublink + * speed attributes are paired, and an RX followed by a TX attribute. + * @speed_ssid: Current sublink speed attribute ID in use. + * @min_speed_ssid: Sublink speed attribute ID with the minimum speed. + * @max_speed_ssid: Sublink speed attribute ID with the maximum speed. * @state: the state we are now (attached, suspended, configured, etc) * @name: Identifies the controller hardware type. Used in diagnostics * and sometimes configuration. @@ -405,6 +414,17 @@ struct usb_gadget { struct list_head ep_list; /* of usb_ep */ enum usb_device_speed speed; enum usb_device_speed max_speed; + + /* SSP only */ + unsigned num_lanes; + unsigned max_num_lanes; + unsigned ssac; +#define USB_GADGET_MAX_SSAC 3 + struct usb_sublink_speed sublink_speed[USB_GADGET_MAX_SSAC + 1]; + unsigned speed_ssid; + unsigned min_speed_ssid; + unsigned max_speed_ssid; + enum usb_device_state state; const char *name; struct device dev; From patchwork Thu Jul 23 02:12:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A239C13B1 for ; Thu, 23 Jul 2020 02:12:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B27720825 for ; Thu, 23 Jul 2020 02:12:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="jShtVkcf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387745AbgGWCMa (ORCPT ); Wed, 22 Jul 2020 22:12:30 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34918 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCM3 (ORCPT ); Wed, 22 Jul 2020 22:12:29 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id C6817C0086; Thu, 23 Jul 2020 02:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470348; bh=rnAYw+47mEnKZG2Ss6GS1alBDC4HFlgYBgnld3FgN6A=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=jShtVkcfku/GnuSzSrvcAQcsoAexhF27MJVdydy4f3AOp5j/YI7Lyy0Pzb8cZAv8z 4g+19+Kf6Z+3vk4VVSk6Q3BGugh1n7+d3niEzna1JtVPplU4+6zmHpxF14v+CORBWc aPDqvEW8CNxOdhYw86G4pOgFfVfKW6xl7zwZ3YOpNBN3fkN33hRpTENtRBpug4Ah7s L8Zsh/ffWKbFLg98kt5gXy/5ovVlCUwJaz4tZv07Pw8B18h4avRCbfowQequgewpVS m2ZE9//GUj/nw8bBPQqkMVZGVb/hG24G/7ZlHzqik9GcXfONOBbTt74Y9IShHy9sLJ u7O+OWIKU9fhQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 16EA2A009A; Thu, 23 Jul 2020 02:12:27 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:27 -0700 Date: Wed, 22 Jul 2020 19:12:27 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 04/12] usb: gadget: Set max speed for SSP devices To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Peter Chen , Alan Stern , Dejin Zheng , Roger Quadros , Marek Szyprowski Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A super-speed-plus device may operate at different sublink speeds (e.g. gen2x2, gen1x2, or gen2x1). If the USB device supports different sublink speeds at super-speed-plus, set the device to operate at the maximum number of lanes and sublink speed possible. Introduce gadget ops udc_set_num_lanes_and_speed to set the lane count and sublink speed for super-speed-plus capable devices. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/udc/core.c | 24 +++++++++++++++++++----- include/linux/usb/gadget.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 5241603bd008..5fea14cc9dbd 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1112,12 +1112,26 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc) static inline void usb_gadget_udc_set_speed(struct usb_udc *udc, enum usb_device_speed speed) { - if (udc->gadget->ops->udc_set_speed) { - enum usb_device_speed s; + struct usb_gadget *gadget = udc->gadget; + enum usb_device_speed s; - s = min(speed, udc->gadget->max_speed); - udc->gadget->ops->udc_set_speed(udc->gadget, s); - } + if (speed == USB_SPEED_UNKNOWN) + s = gadget->max_speed; + else + s = min(speed, gadget->max_speed); + + /* + * If the UDC supports super-speed-plus and different sublink speeds, + * then set the gadget to the max possible sublink speed for + * super-speed-plus symmetric lanes. + */ + if (s == USB_SPEED_SUPER_PLUS && + gadget->ops->udc_set_num_lanes_and_speed) + gadget->ops->udc_set_num_lanes_and_speed(gadget, + gadget->max_num_lanes, + gadget->max_speed_ssid); + else if (gadget->ops->udc_set_speed) + gadget->ops->udc_set_speed(gadget, s); } /** diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 2ab929eed928..ec4ed17e7bf5 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -322,6 +322,9 @@ struct usb_gadget_ops { struct usb_gadget_driver *); int (*udc_stop)(struct usb_gadget *); void (*udc_set_speed)(struct usb_gadget *, enum usb_device_speed); + void (*udc_set_num_lanes_and_speed)(struct usb_gadget *, + unsigned int num_lanes, + unsigned int ssid); struct usb_ep *(*match_ep)(struct usb_gadget *, struct usb_endpoint_descriptor *, struct usb_ss_ep_comp_descriptor *); From patchwork Thu Jul 23 02:12:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15EE8912 for ; Thu, 23 Jul 2020 02:12:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2148207E8 for ; Thu, 23 Jul 2020 02:12:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="VYP3gihR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387750AbgGWCMf (ORCPT ); Wed, 22 Jul 2020 22:12:35 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34938 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMf (ORCPT ); Wed, 22 Jul 2020 22:12:35 -0400 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id D9D7AC0086; Thu, 23 Jul 2020 02:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470354; bh=SIf2oi48vkagsVD8koUAxyv9aQZjQO8XLh1fJeNP0LE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=VYP3gihR67E7X6CzmlQRTIt/avGovBiyAigqMQT8IeL6aIyJiP9H22tbqwnT2htMh cUMAFA2ZKvwGRcaxdKvdnSUZMc21HWbv0juE+xH34dqd+LGxkwgD4DxNXPIEWCa0wE JjsgZbDZKUYUFidN/qCN0ew3N9GQ8zk/t11HfDAuHDY6FFZOiW1XnnocBDNRTcJjQA 9t04QJGYTXl8QU0thiphWuzyDvv+EuReGJOtP3X3IH7zLE4myvYQaWTK2h7Cauyac3 Bo87iJ2FUk2x9+YYsbpeiIynLdpR8b+AJPi13WVyxaekgFi6N5DHb89HdTQB57Qnp6 jaRj4LFP/DLFw== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id AA034A0099; Thu, 23 Jul 2020 02:12:33 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:33 -0700 Date: Wed, 22 Jul 2020 19:12:33 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 05/12] usb: composite: Properly report sublink speed To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the max sublink speed attributes reported in the gadget structure to write to the super-speed-plus BOS descriptor if available. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/composite.c | 76 +++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index a231ae382ac3..d9fb29a72f94 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -729,45 +729,73 @@ static int bos_desc(struct usb_composite_dev *cdev) /* The SuperSpeedPlus USB Device Capability descriptor */ if (gadget_is_superspeed_plus(cdev->gadget)) { struct usb_ssp_cap_descriptor *ssp_cap; + unsigned int ssac = 1; + unsigned int ssic = 0; + unsigned int min_ssid = 0; + int i; + + if (cdev->gadget->ssac) { + ssac = cdev->gadget->ssac; + + /* + * Paired RX and TX sublink speed attributes share + * the same SSID. + */ + ssic = (ssac + 1) / 2 - 1; + min_ssid = cdev->gadget->min_speed_ssid; + } ssp_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); bos->bNumDeviceCaps++; - /* - * Report typical values. - */ - - le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SSP_CAP_SIZE(1)); - ssp_cap->bLength = USB_DT_USB_SSP_CAP_SIZE(1); + le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SSP_CAP_SIZE(ssac)); + ssp_cap->bLength = USB_DT_USB_SSP_CAP_SIZE(ssac); ssp_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; ssp_cap->bDevCapabilityType = USB_SSP_CAP_TYPE; ssp_cap->bReserved = 0; ssp_cap->wReserved = 0; ssp_cap->bmAttributes = - cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_ATTRIBS, 1) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_IDS, 0)); + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_ATTRIBS, ssac) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_IDS, ssic)); ssp_cap->wFunctionalitySupport = - cpu_to_le16(FIELD_PREP(USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID, 0) | + cpu_to_le16(FIELD_PREP(USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID, min_ssid) | FIELD_PREP(USB_SSP_MIN_RX_LANE_COUNT, 1) | FIELD_PREP(USB_SSP_MIN_TX_LANE_COUNT, 1)); - ssp_cap->bmSublinkSpeedAttr[0] = - cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, - USB_ST_SYMMETRIC_RX) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); - - ssp_cap->bmSublinkSpeedAttr[1] = - cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, - USB_ST_SYMMETRIC_TX) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); + /* + * If the sublink speed attributes are not specified, then the + * default will be a pair symmetric RX/TX sublink speed + * attributes of 10 Gbps. + */ + for (i = 0; i < ssac + 1; i++) { + struct usb_sublink_speed default_ssa; + struct usb_sublink_speed *ptr; + + if (cdev->gadget->ssac) { + ptr = &cdev->gadget->sublink_speed[i]; + } else { + default_ssa.id = i / 2; + default_ssa.protocol = USB_LP_SSP; + default_ssa.exponent = USB_LSE_GBPS; + default_ssa.mantissa = 10; + + if (i % 2) + default_ssa.type = USB_ST_SYMMETRIC_TX; + else + default_ssa.type = USB_ST_SYMMETRIC_RX; + + ptr = &default_ssa; + } + + ssp_cap->bmSublinkSpeedAttr[i] = + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, ptr->id) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, ptr->exponent) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, ptr->type) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, ptr->protocol) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, ptr->mantissa)); + } } return le16_to_cpu(bos->wTotalLength); From patchwork Thu Jul 23 02:12:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E15C912 for ; Thu, 23 Jul 2020 02:12:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3190920781 for ; Thu, 23 Jul 2020 02:12:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="VHJYIk0z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387751AbgGWCMl (ORCPT ); Wed, 22 Jul 2020 22:12:41 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:54258 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMl (ORCPT ); Wed, 22 Jul 2020 22:12:41 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 6BB4040140; Thu, 23 Jul 2020 02:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470361; bh=xKqvu1r3YaFDoRkLO+kOsIi1/taHZrbVYkcWmL76uY4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=VHJYIk0znAUHqwopYigUGvTqIvn35ELDrFsydujyEPYj2FfpaIv3PT86sMIZ476NJ HmKDgF8M01IbBO5t2V6XRI0VciD22kANBuSBem/HWFa7vBc8Eg5L01wL+cmQqfLOQD dZjT3aXvPgqszpiNEaEEfv0N+b5MjfZrnWmkV42VQ3XKtt/j23uFxmIf6FHm08rndt WbcXWS0/JNEwnFH08jDXn+OvUUcrCnng16VKk6yggfLoqKGP59CUkjH+0dYG8PqlTZ RSuaiG8jljCllm/OnkMP/8otcZravcrZaYW+Me7KpQ+Rlnr/qe0/2sR9Q0X2CoCdEm Q3nwxZc0AszYg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 1E2E3A006F; Thu, 23 Jul 2020 02:12:39 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:39 -0700 Date: Wed, 22 Jul 2020 19:12:39 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 06/12] usb: devicetree: Introduce num-lanes and lsm To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org According to USB 3.2 spec, a super-speed-plus device can operate at gen2x2, gen2x1, or gen1x2. Introduce "num-lanes" and "lane-speed-mantissa-gbps" properties for devices operating in super-speed-plus. If the USB controller device supports multiple lanes at different transfer rate, the user can specify the HW capability via these properties. Signed-off-by: Thinh Nguyen --- Changes in v2: - Make "num-lanes" and "lane-speed-mantissa-gbps" common USB properties Documentation/devicetree/bindings/usb/generic.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index ba472e7aefc9..a8253da684af 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -7,6 +7,17 @@ Optional properties: "low-speed". In case this isn't passed via DT, USB controllers should default to their maximum HW capability. + - num-lanes: tells USB controllers that we want to work up to a certain number + of lanes. Valid arguments are 1 or 2. Apply if the + maximum-speed is super-speed-plus. In case this isn't + passed via DT, the USB controllers should default to + their maximum HW capability. + - lane-speed-mantissa-gbps: tells USB controllers that we want the symmetric + lanes to operate up to a certain rate in Gbps. Valid + inputs are 5 or 10 (i.e. Gen 1/Gen 2 transfer rate). + Apply if the maximum-speed is super-speed-plus. In case + this isn't passed via DT, the USB controllers should + default to their maximum HW capability. - dr_mode: tells Dual-Role USB controllers that we want to work on a particular mode. Valid arguments are "host", "peripheral" and "otg". In case this attribute isn't From patchwork Thu Jul 23 02:12:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92612912 for ; Thu, 23 Jul 2020 02:12:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B0EE2086A for ; Thu, 23 Jul 2020 02:12:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="GsAF1Bn9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387754AbgGWCMs (ORCPT ); Wed, 22 Jul 2020 22:12:48 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:54268 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMr (ORCPT ); Wed, 22 Jul 2020 22:12:47 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 8011F40140; Thu, 23 Jul 2020 02:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470367; bh=k9v8smLqRJvUjNhbHk0Lo0a8mlkrSCnenpl6IlnK730=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GsAF1Bn9qJbj7OkixPGwIUz9ER8VZ5Kxj3sl36gUzaAG0piJgFvfz4fUZ5a8tJEZx iy7kU12G/0ljBw1xSB6j/z42irrPpsrTbDdtaqmFIRh6JLvqXHVp8rS9m6NA0Ufk+S BVLgel3Gk/PxR6nYH4DjN6/E1OjSS42+YODWuNnnPPDImC+tbwtLX6DHbsGMTFRsL5 /7nKmF33cz4b+qseIONzXy238jbKdTRcyHRewskFWT8bAtXgQ2DINYxMvNWXBj1wCy waawhHimKqxDJL1e8QugPCJ29yrbGJSw4G0eR12nhaqQkEetZ8s4HhYGHtal8Ygn6a wM4mJOwNpXL6A== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 69FACA009A; Thu, 23 Jul 2020 02:12:46 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:46 -0700 Date: Wed, 22 Jul 2020 19:12:46 -0700 Message-Id: <830743026ec46eacc5f7f28f39d2f1dae413dc05.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 07/12] usb: common: Add functions to get lanes and lsm To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add common functions to get the requested number of lanes and lane speed mantissa from device properties. Signed-off-by: Thinh Nguyen --- Changes in v2: - New commit drivers/usb/common/common.c | 26 ++++++++++++++++++++++++++ include/linux/usb/ch9.h | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 1433260d99b4..871a7326b6b7 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -92,6 +92,32 @@ enum usb_device_speed usb_get_maximum_speed(struct device *dev) } EXPORT_SYMBOL_GPL(usb_get_maximum_speed); +u8 usb_get_num_lanes(struct device *dev) +{ + u8 num_lanes; + int ret; + + ret = device_property_read_u8(dev, "num-lanes", &num_lanes); + if (ret < 0) + return 0; + + return num_lanes; +} +EXPORT_SYMBOL_GPL(usb_get_num_lanes); + +u16 usb_get_lsm(struct device *dev) +{ + u16 lsm; + int ret; + + ret = device_property_read_u16(dev, "lane-speed-mantissa-gbps", &lsm); + if (ret < 0) + return 0; + + return lsm; +} +EXPORT_SYMBOL_GPL(usb_get_lsm); + const char *usb_state_string(enum usb_device_state state) { static const char *const names[] = { diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index f87ef9a2f859..1097c6f8e2ef 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -105,6 +105,25 @@ extern const char *usb_speed_string(enum usb_device_speed speed); */ extern enum usb_device_speed usb_get_maximum_speed(struct device *dev); +/** + * usb_get_num_lanes - Get maximum number of requested lanes for a given USB + * controller. + * @dev: Pointer to the given USB controller device + * + * The function returns the number of requested lanes from the property + * "num-lanes". + */ +extern u8 usb_get_num_lanes(struct device *dev); + +/** + * usb_get_lsm - Get requested lane speed mantissa for a given USB controller. + * @dev: Pointer to the given USB controller device + * + * The function returns the requested symmetric lane speed mantissa in Gbps from + * the property "lane-speed-mantissa-gbps". + */ +extern u16 usb_get_lsm(struct device *dev); + /** * usb_state_string - Returns human readable name for the state. * @state: The state to return a human-readable name for. If it's not From patchwork Thu Jul 23 02:12:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1648912 for ; Thu, 23 Jul 2020 02:12:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B86BA20781 for ; Thu, 23 Jul 2020 02:12:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="FKzG8yb0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387760AbgGWCMy (ORCPT ); Wed, 22 Jul 2020 22:12:54 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:54270 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCMx (ORCPT ); Wed, 22 Jul 2020 22:12:53 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 9350340140; Thu, 23 Jul 2020 02:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470373; bh=NjKXKjVrsRPF+xr4aOsMN1aFJKid3tfuPvj2++Vu3O8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=FKzG8yb01fn+c/AdUbTOrEm8SO2R1ZyRRt9Ch8X9pfrk0ekZGLohMC/g5apqXV0yo vyaO37amiudm2JkI5sAJo78PGvWEmwCBuirTDCNxCl/h0CJuh3rXdJmGbxyzD3+Tn+ Ro50HWGAutGdegkrRd2ph6vRhhRy2F2P2p58NF9NxXmPpTOWk8aoVvPk13vvHA2TOb UcZ4chTawWAdAMTtPxeX8b5yRgu/7R35/xVHwQoDK4NLDays3Ot4kliPjbIOVN9DNO 6GgO7tn2Ldieum5hEYspeyDpRgMxs3WRBaFG4RKDs2lYN8pnor9yJ00rRbIeQRxyFk 9XulZosjm4ARw== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 7D400A009A; Thu, 23 Jul 2020 02:12:52 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:52 -0700 Date: Wed, 22 Jul 2020 19:12:52 -0700 Message-Id: <1b1d1ccf9f28f4d25d0e1437fbf4201f873ccf43.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 08/12] usb: dwc3: Initialize lane count and sublink speed To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org DWC_usb32 supports dual-lane operating at different sublink speeds. Initialize and validate the maximum number of lanes and speed the controller supports captured from the dwc3 device properties. Currently the controller has no visibility into the HW parameter to determine the maximum number of lanes the phy supports. If the number of lanes is not specified, then set the default to 2 for DWC_usb32 and 1 for DWC_usb31 if operate in SSP. Signed-off-by: Thinh Nguyen --- Changes in v2: - Use common functions to get num_lanes and lsm properties drivers/usb/dwc3/core.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 10 ++++++++ 2 files changed, 72 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 25c686a752b0..d9b8e3f8d005 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1275,6 +1275,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) hird_threshold = 12; dwc->maximum_speed = usb_get_maximum_speed(dev); + dwc->maximum_num_lanes = usb_get_num_lanes(dev); + dwc->maximum_lsm = usb_get_lsm(dev); dwc->dr_mode = usb_get_dr_mode(dev); dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); @@ -1426,6 +1428,66 @@ static void dwc3_check_params(struct dwc3 *dwc) break; } + + /* + * If it's not DWC_usb32 IP or speed is less than SSP, no need to + * validate the number of lanes or lane speed mantissa. + * + * Currently the controller does not have visibility into the HW + * parameter to determine the maximum number of lanes the phy supports. + * If the number of lanes is not specified in the device property, then + * set the default to 2 for DWC_usb32 and 1 for DWC_usb31 if the device + * is capable of super-speed-plus. + */ + if (!DWC3_IP_IS(DWC32) || + dwc->maximum_speed < USB_SPEED_SUPER_PLUS) { + if (dwc->maximum_lsm || dwc->maximum_num_lanes) + dev_warn(dev, "Ignore num_lanes and LSM properties\n"); + + if (DWC3_IP_IS(DWC31) && + dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { + dwc->maximum_lsm = DWC3_LSM_10_GBPS; + dwc->maximum_num_lanes = 1; + } else { + dwc->maximum_lsm = DWC3_LSM_UNSPECIFIED; + dwc->maximum_num_lanes = 0; + } + + return; + } + + switch (dwc->maximum_lsm) { + case DWC3_LSM_10_GBPS: + case DWC3_LSM_5_GBPS: + break; + default: + dev_err(dev, "Invalid LSM (%dGbps)\n", dwc->maximum_lsm); + fallthrough; + case DWC3_LSM_UNSPECIFIED: + dwc->maximum_lsm = DWC3_LSM_10_GBPS; + break; + } + + switch (dwc->maximum_num_lanes) { + case 2: + break; + case 1: + if (dwc->maximum_lsm == DWC3_LSM_5_GBPS) { + dev_err(dev, "Invalid num_lanes (%d) and LSM (%dGbps) for %s\n", + dwc->maximum_num_lanes, + dwc->maximum_lsm, + usb_speed_string(dwc->maximum_speed)); + dwc->maximum_lsm = DWC3_LSM_10_GBPS; + } + break; + default: + dev_err(dev, "Invalid number of lanes (%d)\n", + dwc->maximum_num_lanes); + fallthrough; + case 0: + dwc->maximum_num_lanes = 2; + break; + } } static int dwc3_probe(struct platform_device *pdev) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 013f42a2b5dc..0e37a0471e5a 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -40,6 +40,10 @@ #define DWC3_XHCI_RESOURCES_NUM 2 #define DWC3_ISOC_MAX_RETRIES 5 +#define DWC3_LSM_UNSPECIFIED 0 +#define DWC3_LSM_5_GBPS 5 +#define DWC3_LSM_10_GBPS 10 + #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */ #define DWC3_EVENT_BUFFERS_SIZE 4096 #define DWC3_EVENT_TYPE_MASK 0xfe @@ -958,6 +962,8 @@ struct dwc3_scratchpad_array { * @nr_scratch: number of scratch buffers * @u1u2: only used on revisions <1.83a for workaround * @maximum_speed: maximum speed requested (mainly for testing purposes) + * @maximum_lsm: maximum lane speed mantissa in Gbps + * @maximum_num_lanes: maximum number of lanes * @ip: controller's ID * @revision: controller's version of an IP * @version_type: VERSIONTYPE register contents, a sub release of a revision @@ -988,6 +994,7 @@ struct dwc3_scratchpad_array { * @ep0state: state of endpoint zero * @link_state: link state * @speed: device speed (super, high, full, low) + * @num_lanes: number of connected lanes * @hwparams: copy of hwparams registers * @root: debugfs root folder pointer * @regset: debugfs pointer to regdump file @@ -1119,6 +1126,8 @@ struct dwc3 { u32 nr_scratch; u32 u1u2; u32 maximum_speed; + u16 maximum_lsm; + u8 maximum_num_lanes; u32 ip; @@ -1184,6 +1193,7 @@ struct dwc3 { u8 u1pel; u8 speed; + u8 num_lanes; u8 num_eps; From patchwork Thu Jul 23 02:12:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39335912 for ; Thu, 23 Jul 2020 02:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20BBC20825 for ; Thu, 23 Jul 2020 02:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="GkLhf+2s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387762AbgGWCNA (ORCPT ); Wed, 22 Jul 2020 22:13:00 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34956 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCNA (ORCPT ); Wed, 22 Jul 2020 22:13:00 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id C06D1C0086; Thu, 23 Jul 2020 02:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470379; bh=0Af4Y3G9+HLMw9CKf/oJcaLYUvvbvyPsuZ7iiARt+i4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GkLhf+2sISLhXnRoZbj/FN+dytrlOyfHJkj/QNSWSVr7OPtmZz/hFbYJOqWAcORUi xOXfjnY/P49QSbSsrGMaACy7Y0zia2iDhGzCVf37+QN0h7jTWGLwWpo7jfahrKVaJY in7WZEKmbfg1LRlEypztlYSPjBXg/JhFRTuGipeUncLbMbALGgHIAoVwy8XNuuXMIp oRuAVpMGR0NghYX2UmHbr3hDk+tQR5zULupI+24/tjNYAkOCKEnlNQGs0jNRplWIGJ AKPopgMegKu6Gj3nh4FjhAbrI978oH9XP7xrdnTjVMKMLPgYuyx5UnxsiYdlnZJcJC WexoaS1ivPa+A== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 90CFEA0096; Thu, 23 Jul 2020 02:12:58 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:12:58 -0700 Date: Wed, 22 Jul 2020 19:12:58 -0700 Message-Id: <53d6c389f6e63e0cef120b58ba22aa8d6ef5a2aa.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 09/12] usb: dwc3: gadget: Report sublink speed capability To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Report the sublink speed attributes to the usb_gadget structure based on the dwc3 device capability maximum_lsm and maximum_num_lanes. Only DWC_usb32 supports 2 sublink speeds if it can operate with 2 lanes. (i.e. at SSP, it can operate as gen1x2) Note: the SSID DWC3_SSP_SSID_GEN2 and DWC3_SSP_SSID_GEN1 are arbitrary. There's no standard according to the USB 3.2 spec as long as they are unique and within 0-15. Signed-off-by: Thinh Nguyen --- Changes in v2: - Fix missing check for gen1x2 when writing to sublink speed attributes - Minor fix in commit message (first commit sentence ended with comma) drivers/usb/dwc3/core.h | 4 ++++ drivers/usb/dwc3/gadget.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 0e37a0471e5a..b44550173599 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -44,6 +44,10 @@ #define DWC3_LSM_5_GBPS 5 #define DWC3_LSM_10_GBPS 10 +/* Sublink Speed Attribute ID */ +#define DWC3_SSP_SSID_GEN2 2 +#define DWC3_SSP_SSID_GEN1 1 + #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */ #define DWC3_EVENT_BUFFERS_SIZE 4096 #define DWC3_EVENT_TYPE_MASK 0xfe diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 80c3ef134e41..69f64bb324ed 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3662,6 +3662,55 @@ int dwc3_gadget_init(struct dwc3 *dwc) dwc->revision); dwc->gadget.max_speed = dwc->maximum_speed; + dwc->gadget.max_num_lanes = dwc->maximum_num_lanes; + + if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { + struct usb_sublink_speed *ssa; + int i; + + /* + * Multiple sublink speeds are only available to DWC_usb32 + * devices that can operate at gen2x2 max. + */ + if (dwc->maximum_lsm == DWC3_LSM_10_GBPS && + dwc->maximum_num_lanes == 2) { + dwc->gadget.ssac = 3; + dwc->gadget.min_speed_ssid = DWC3_SSP_SSID_GEN1; + dwc->gadget.max_speed_ssid = DWC3_SSP_SSID_GEN2; + } else if (dwc->maximum_lsm == DWC3_LSM_5_GBPS && + dwc->maximum_num_lanes == 2) { + dwc->gadget.ssac = 1; + dwc->gadget.min_speed_ssid = DWC3_SSP_SSID_GEN1; + dwc->gadget.max_speed_ssid = DWC3_SSP_SSID_GEN1; + } else { + dwc->gadget.ssac = 1; + dwc->gadget.min_speed_ssid = DWC3_SSP_SSID_GEN2; + dwc->gadget.max_speed_ssid = DWC3_SSP_SSID_GEN2; + } + + for (i = 0; i < dwc->gadget.ssac + 1; i++) { + ssa = &dwc->gadget.sublink_speed[i]; + + if (dwc->gadget.ssac > 1 && i > 1) + ssa->id = dwc->gadget.max_speed_ssid; + else + ssa->id = dwc->gadget.min_speed_ssid; + + if (ssa->id == DWC3_SSP_SSID_GEN1) + ssa->mantissa = DWC3_LSM_5_GBPS; + else + ssa->mantissa = DWC3_LSM_10_GBPS; + + /* First attribute is RX followed by TX */ + if (i % 2) + ssa->type = USB_ST_SYMMETRIC_TX; + else + ssa->type = USB_ST_SYMMETRIC_RX; + + ssa->exponent = USB_LSE_GBPS; + ssa->protocol = USB_LP_SSP; + } + } /* * REVISIT: Here we should clear all pending IRQs to be From patchwork Thu Jul 23 02:13:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C97E813B1 for ; Thu, 23 Jul 2020 02:13:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1CF720825 for ; Thu, 23 Jul 2020 02:13:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="CIqgSRru" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387764AbgGWCNG (ORCPT ); Wed, 22 Jul 2020 22:13:06 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:54284 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCNG (ORCPT ); Wed, 22 Jul 2020 22:13:06 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id BB9A54017D; Thu, 23 Jul 2020 02:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470385; bh=59WJZFznZ8UTrXda5HJVbyP24xR7Hp9H0N4zrvNP74c=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=CIqgSRruEcp8bN7G147hAnTrDn8re7P5EsQtYuWmpd9o8d0Rt4NnXQG8RIEJltwUO e9YMAtlYmPM0j4K/3NmSqdI4aMiVUdNtSzUN9pY76n6vo/FjcRwpzEmotLvP+ORlkI ACvJf7w5DWtPr3Xsv21QpjSQoLbnlh4ihszXbDUu2Bo7HTAF+ScwNi/W0/RsBnP2Vv I0Kv8AYmL59tledVSwSnJLV76ORUxxlfoxfiVY4xZPIta9d5KSvSg58ewqgkqRPthc kETH+oPtqP1Msl35QKMn/7oKpjQpjHkKyhGj4no3j3ROewdbkZp24+8VYgpKSjHz6r PAN82c18SGSHg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id A4B84A0096; Thu, 23 Jul 2020 02:13:04 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:13:04 -0700 Date: Wed, 22 Jul 2020 19:13:04 -0700 Message-Id: <9447faa8637f73f6954809b386c5a63d76740792.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 10/12] usb: dwc3: gadget: Implement setting of sublink speed To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Implement gadget ops udc_set_num_lanes_and_speed. This allows the gadget/core driver to select number of lanes to use and the sublink speed the controller supports. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/gadget.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index b44550173599..36407a8e67b8 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -389,6 +389,8 @@ #define DWC3_GUCTL2_RST_ACTBITLATER BIT(14) /* Device Configuration Register */ +#define DWC3_DCFG_NUMLANES(n) (((n) & 0x3) << 30) /* DWC_usb32 only */ + #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 69f64bb324ed..5671a6762c83 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2311,6 +2311,62 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, spin_unlock_irqrestore(&dwc->lock, flags); } +static void dwc3_gadget_set_num_lanes_and_speed(struct usb_gadget *g, + unsigned int num_lanes, + unsigned int ssid) +{ + struct dwc3 *dwc = gadget_to_dwc(g); + struct usb_sublink_speed *ssa = NULL; + unsigned int lanes; + unsigned long flags; + u32 reg; + int i; + + spin_lock_irqsave(&dwc->lock, flags); + if (dwc->maximum_speed < USB_SPEED_SUPER_PLUS) + goto done; + + for (i = 0; i < g->ssac + 1; i++) { + if (g->sublink_speed[i].id == ssid) { + ssa = &g->sublink_speed[i]; + break; + } + } + + if (!ssa) { + dev_err(dwc->dev, "SSID not found (%d)\n", ssid); + goto done; + } + + reg = dwc3_readl(dwc->regs, DWC3_DCFG); + reg &= ~DWC3_DCFG_SPEED_MASK; + + switch (ssa->mantissa) { + case DWC3_LSM_5_GBPS: + reg |= DWC3_DCFG_SUPERSPEED; + break; + case DWC3_LSM_10_GBPS: + reg |= DWC3_DCFG_SUPERSPEED_PLUS; + break; + default: + dev_err(dwc->dev, "invalid lane speed mantissa (%d)\n", + ssa->mantissa); + goto done; + } + + /* Lane configuration is only available to DWC_usb32 */ + if (DWC3_IP_IS(DWC32)) { + lanes = clamp_t(unsigned int, num_lanes, 1, + dwc->maximum_num_lanes); + reg &= ~DWC3_DCFG_NUMLANES(~0); + reg |= DWC3_DCFG_NUMLANES(lanes - 1); + } + + dwc3_writel(dwc->regs, DWC3_DCFG, reg); +done: + spin_unlock_irqrestore(&dwc->lock, flags); +} + static const struct usb_gadget_ops dwc3_gadget_ops = { .get_frame = dwc3_gadget_get_frame, .wakeup = dwc3_gadget_wakeup, @@ -2319,6 +2375,7 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { .udc_start = dwc3_gadget_start, .udc_stop = dwc3_gadget_stop, .udc_set_speed = dwc3_gadget_set_speed, + .udc_set_num_lanes_and_speed = dwc3_gadget_set_num_lanes_and_speed, .get_config_params = dwc3_gadget_config_params, }; @@ -3727,7 +3784,12 @@ int dwc3_gadget_init(struct dwc3 *dwc) goto err4; } - dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed); + if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) + dwc3_gadget_set_num_lanes_and_speed(&dwc->gadget, + dwc->maximum_num_lanes, + dwc->gadget.max_speed_ssid); + else + dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed); return 0; From patchwork Thu Jul 23 02:13:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11679575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCB68912 for ; Thu, 23 Jul 2020 02:13:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4751207E8 for ; Thu, 23 Jul 2020 02:13:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="HGt8aNLg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387780AbgGWCNO (ORCPT ); Wed, 22 Jul 2020 22:13:14 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34966 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbgGWCNM (ORCPT ); Wed, 22 Jul 2020 22:13:12 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id E7711C0086; Thu, 23 Jul 2020 02:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470392; bh=ZkNjsqnNI9Dx//BEB5X9/zF/pTQ+dyPlA/7emtjltCs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=HGt8aNLgfwT0g3gyX4NFNiV5q0SxZ/wG69nrVEq4VY/QUALNmvDx/nm4cKkN1daF+ Y0FmdePb4fRiu/9E3VQ6jDGEx72dWizMyll7M3Q8hs1mIyZy0FssBXEv1fNb2vhraS G954ULVP5Vz0iu58BLfc+tsjUZCVBSUo7+fMCrzDN0SH6AAwYGJknM01JpX1Qr9pxy omWO0dQ8GI4A55aHV7Ws/Zs5Go2/FLUX7yD7ErYpNy3J/k8d1cOACDCynbtdAG/CVm XgHemrRNvYrAKUgANjGLOxSC9nBgnoFY3M1BnPr4zcouve1T+DeBUH5KaljWXZiDOk 6UL8WRAzQlHNg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id B880FA0096; Thu, 23 Jul 2020 02:13:10 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:13:10 -0700 Date: Wed, 22 Jul 2020 19:13:10 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 11/12] usb: dwc3: gadget: Track connected lane and sublink speed To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Track the number of lanes connected in gadget->num_lanes and track the current sublink speed attribute ID for super-speed-plus operations. Note: if the device is running in gen1x2, set the gadget->speed to USB_SPEED_SUPER_PLUS. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/gadget.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 36407a8e67b8..84e2150c1c0a 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -464,6 +464,8 @@ #define DWC3_DEVTEN_USBRSTEN BIT(1) #define DWC3_DEVTEN_DISCONNEVTEN BIT(0) +#define DWC3_DSTS_CONNLANES(n) (((n) >> 30) & 0x3) /* DWC_usb32 only */ + /* Device Status Register */ #define DWC3_DSTS_DCNRD BIT(29) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 5671a6762c83..2bc29d74e75a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2306,6 +2306,10 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, reg |= DWC3_DCFG_SUPERSPEED_PLUS; } } + + if (DWC3_IP_IS(DWC32) && speed < USB_SPEED_SUPER_PLUS) + reg &= ~DWC3_DCFG_NUMLANES(~0); + dwc3_writel(dwc->regs, DWC3_DCFG, reg); spin_unlock_irqrestore(&dwc->lock, flags); @@ -3175,12 +3179,19 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) struct dwc3_ep *dep; int ret; u32 reg; + u8 lanes = 1; u8 speed; reg = dwc3_readl(dwc->regs, DWC3_DSTS); speed = reg & DWC3_DSTS_CONNECTSPD; dwc->speed = speed; + if (DWC3_IP_IS(DWC32)) + lanes = DWC3_DSTS_CONNLANES(reg) + 1; + + dwc->gadget.num_lanes = lanes; + dwc->gadget.speed_ssid = 0; + /* * RAMClkSel is reset to 0 after USB reset, so it must be reprogrammed * each time on Connect Done. @@ -3195,6 +3206,7 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); dwc->gadget.ep0->maxpacket = 512; dwc->gadget.speed = USB_SPEED_SUPER_PLUS; + dwc->gadget.speed_ssid = DWC3_SSP_SSID_GEN2; break; case DWC3_DSTS_SUPERSPEED: /* @@ -3215,7 +3227,13 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); dwc->gadget.ep0->maxpacket = 512; - dwc->gadget.speed = USB_SPEED_SUPER; + + if (lanes > 1) { + dwc->gadget.speed = USB_SPEED_SUPER_PLUS; + dwc->gadget.speed_ssid = DWC3_SSP_SSID_GEN1; + } else { + dwc->gadget.speed = USB_SPEED_SUPER; + } break; case DWC3_DSTS_HIGHSPEED: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); @@ -3696,6 +3714,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) dwc->gadget.sg_supported = true; dwc->gadget.name = "dwc3-gadget"; dwc->gadget.lpm_capable = true; + dwc->gadget.num_lanes = 1; /* * FIXME We might be setting max_speed to X-Patchwork-Id: 11679577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45DBB13B1 for ; Thu, 23 Jul 2020 02:13:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E1122084D for ; Thu, 23 Jul 2020 02:13:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="MmZL5jAZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387785AbgGWCNS (ORCPT ); Wed, 22 Jul 2020 22:13:18 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:34976 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387783AbgGWCNS (ORCPT ); Wed, 22 Jul 2020 22:13:18 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 06D65C0089; Thu, 23 Jul 2020 02:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595470398; bh=H7aIfhqlpEyIdQ2h9ZTMFm4HDhY4IPdImewAUIIiH5U=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=MmZL5jAZx9dqTJydpLjYHvvzVlfvbQLuabraHNNTzQdH2WZFC7ibL0DJ49gqbKZbo kzSZwCnShLfjfI39XFIGgCZasNGOpvGfLlUdPp7D+nmkX2OcburcGQR08sP8T1TrSX 9zL++qlKy9fxsBbyAvzEJmSoHIQKrJWxKkMBpgNzq2ZOR3p0fXJIMB7RN7FRtd5Thq aUgMvVCiZ/O+gRqKmGkRpgols60ZiF04qD5j7rsCY/DQolGTRf+2mfZ2yjfYacgraY iC5dqXSAyFPYohKt4b9sif27RiSDWSGg/Ej4ms22ziOM6Q/OhB/z9yJ/aCahgL7zoz +xMapTlhW+zdQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id CC00AA006F; Thu, 23 Jul 2020 02:13:16 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 22 Jul 2020 19:13:16 -0700 Date: Wed, 22 Jul 2020 19:13:16 -0700 Message-Id: <8636b860422de412a954cd7b8a11ef1d73a14538.1595468673.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 12/12] usb: dwc3: gadget: Set speed only up to the max supported To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The setting of device speed should be limited by the device's maximum_speed. This patch adds a check and prevent the driver from attempting to configure higher than the maximum_speed. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/dwc3/gadget.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2bc29d74e75a..9094690f8258 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2254,6 +2254,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, enum usb_device_speed speed) { struct dwc3 *dwc = gadget_to_dwc(g); + enum usb_device_speed selected_speed = speed; unsigned long flags; u32 reg; @@ -2278,7 +2279,10 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, !dwc->dis_metastability_quirk) { reg |= DWC3_DCFG_SUPERSPEED; } else { - switch (speed) { + if (speed > dwc->maximum_speed) + selected_speed = dwc->maximum_speed; + + switch (selected_speed) { case USB_SPEED_LOW: reg |= DWC3_DCFG_LOWSPEED; break; @@ -2298,7 +2302,8 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, reg |= DWC3_DCFG_SUPERSPEED_PLUS; break; default: - dev_err(dwc->dev, "invalid speed (%d)\n", speed); + dev_err(dwc->dev, "invalid speed (%d)\n", + selected_speed); if (DWC3_IP_IS(DWC3)) reg |= DWC3_DCFG_SUPERSPEED; @@ -2307,7 +2312,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, } } - if (DWC3_IP_IS(DWC32) && speed < USB_SPEED_SUPER_PLUS) + if (DWC3_IP_IS(DWC32) && selected_speed < USB_SPEED_SUPER_PLUS) reg &= ~DWC3_DCFG_NUMLANES(~0); dwc3_writel(dwc->regs, DWC3_DCFG, reg);