From patchwork Thu Jan 14 02:52:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71186C433DB for ; Thu, 14 Jan 2021 02:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27D8423406 for ; Thu, 14 Jan 2021 02:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbhANCxu (ORCPT ); Wed, 13 Jan 2021 21:53:50 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54706 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbhANCxu (ORCPT ); Wed, 13 Jan 2021 21:53:50 -0500 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (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 651FDC00EB; Thu, 14 Jan 2021 02:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592769; bh=6wgzOhzl5+BO8jhGk4Dw4TfuXInE5l1og7lus5vjvWo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=iJ79a+tgLpMZVZknwFmmXEW4Te4s8txCkKobcbeZ+iEOjzPfveACQno0JtwejUgwF uyeGuFLf8fygqyruvUS6A0Ly25FtT/zoJTdRMDNGNJEtq+aNb7rWauUQMrMMpIg+yT eRVWun3y83aP7TzTEpn/ZvqYPHG7wWjiLrkj8/X4PDAqMW53FVeHBjc62rSzwTlBfN plE56iTmAHOw6gzP7EIrl8s6bFanzLVIA4EfqBJLqQckX+azmBAqQHOOhXVvAHAldi h5fcTCtCNHBXcZirTjOGeD6ALqbytdGEdX1Q+2yVMnevnQbC1fqlnKyPzQD2Ae43h8 atGKpF6Rzbt9g== Received: from te-lab16 (unknown [10.10.52.11]) (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 73743A005E; Thu, 14 Jan 2021 02:52:46 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:52:46 -0800 Date: Wed, 13 Jan 2021 18:52:46 -0800 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 01/11] usb: ch9: Add USB 3.2 SSP attributes To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org, Chunfeng Yun , Andrew Morton , Rob Gill , Macpaul Lin , Bin Liu , "Alexander A. Klimov" Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In preparation for USB 3.2 dual-lane support, add sublink speed attribute macros and enum usb_ssp_rate. A USB device that operates in SuperSpeed Plus may operate at different speed and lane count. These additional macros and enum values help specifying that. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Convert the sublink speed attribute enum to macros and move it to uapi - Remove usb_sublink_speed struct - To simplify things, use usb_ssp_rate enum to specify the signaling rate generation and lane count - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - Move to include/linux/usb/ch9.h instead of under uapi include/linux/usb/ch9.h | 9 +++++++++ include/uapi/linux/usb/ch9.h | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index 604c6c514a50..86c50907634e 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -36,6 +36,15 @@ #include #include +/* USB 3.2 SuperSpeed Plus phy signaling rate generation and lane count */ + +enum usb_ssp_rate { + USB_SSP_GEN_UNKNOWN = 0, + USB_SSP_GEN_2x1, + USB_SSP_GEN_1x2, + USB_SSP_GEN_2x2, +}; + /** * 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 diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h index 0f865ae4ba89..17ce56198c9a 100644 --- a/include/uapi/linux/usb/ch9.h +++ b/include/uapi/linux/usb/ch9.h @@ -968,9 +968,22 @@ struct usb_ssp_cap_descriptor { __le32 bmSublinkSpeedAttr[1]; /* list of sublink speed attrib entries */ #define USB_SSP_SUBLINK_SPEED_SSID (0xf) /* sublink speed ID */ #define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4) /* Lanespeed exponent */ +#define USB_SSP_SUBLINK_SPEED_LSE_BPS 0 +#define USB_SSP_SUBLINK_SPEED_LSE_KBPS 1 +#define USB_SSP_SUBLINK_SPEED_LSE_MBPS 2 +#define USB_SSP_SUBLINK_SPEED_LSE_GBPS 3 + #define USB_SSP_SUBLINK_SPEED_ST (0x3 << 6) /* Sublink type */ +#define USB_SSP_SUBLINK_SPEED_ST_SYM_RX 0 +#define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX 1 +#define USB_SSP_SUBLINK_SPEED_ST_SYM_TX 2 +#define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX 3 + #define USB_SSP_SUBLINK_SPEED_RSVD (0x3f << 8) /* Reserved */ #define USB_SSP_SUBLINK_SPEED_LP (0x3 << 14) /* Link protocol */ +#define USB_SSP_SUBLINK_SPEED_LP_SS 0 +#define USB_SSP_SUBLINK_SPEED_LP_SSP 1 + #define USB_SSP_SUBLINK_SPEED_LSM (0xff << 16) /* Lanespeed mantissa */ } __attribute__((packed)); From patchwork Thu Jan 14 02:52:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EC43C433DB for ; Thu, 14 Jan 2021 02:53:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0FE223406 for ; Thu, 14 Jan 2021 02:53:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbhANCx6 (ORCPT ); Wed, 13 Jan 2021 21:53:58 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:42054 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbhANCx4 (ORCPT ); Wed, 13 Jan 2021 21:53:56 -0500 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 EEF51401AB; Thu, 14 Jan 2021 02:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592776; bh=6CBDdlrv+A6Ghz+/mqsfBowiJ/NGWn8TeU4qmIgOrsM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=k2qcgG6mJegDsB/AaPRleBbpyT1sbPH5hEuOeh84Gf3hUcuSEzf+hYcMeixC4GwOl a+RzL1peyyUGWYpznLsMljx71aKla3iicgz/pSsGaMEiDuMlq2vdXVNjr0eQcNqZiS b2S7OKCn01vvpmLVqEUAH6kpQfFzR1s096WJX/FDG//52lX5Z85z43j077Ha/TrrvM tuLfg+yo2a1oAYt+NoUMVNVjWmzbdLsN4MsLqn+5WwjI11rJLDFCMcfSPwiFAEpVnT 04EOuw4xAvnra891LwFgxdhFP7GQyGR1V/HU5NBr++V0DIefmW/qMVupJ7danFnBJK 5/MQweRF1WPmg== Received: from te-lab16 (unknown [10.10.52.11]) (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 82ED1A0070; Thu, 14 Jan 2021 02:52:54 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:52:54 -0800 Date: Wed, 13 Jan 2021 18:52:54 -0800 Message-Id: <6f74d446aa164f66fbe4161e28547e28851f6a02.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 02/11] usb: gadget: composite: Use SSP sublink speed macros To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use SuperSpeed Plus sublink speed macros to fill the BOS descriptor sublink speed attributes in the composite driver. They're self-documented so we can remove some of the comments, and this helps with readability by removing the magic numbers. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Use the updated macros - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/gadget/composite.c | 45 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 9a7cc08d6593..bc17302a9e85 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -749,32 +750,34 @@ 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_SSP_SUBLINK_SPEED_LSE_GBPS) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, + USB_SSP_SUBLINK_SPEED_ST_SYM_RX) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, + USB_SSP_SUBLINK_SPEED_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_SSP_SUBLINK_SPEED_LSE_GBPS) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, + USB_SSP_SUBLINK_SPEED_ST_SYM_TX) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, + USB_SSP_SUBLINK_SPEED_LP_SSP) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); } return le16_to_cpu(bos->wTotalLength); From patchwork Thu Jan 14 02:53:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA5E1C433E0 for ; Thu, 14 Jan 2021 02:54:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B255123602 for ; Thu, 14 Jan 2021 02:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727169AbhANCyC (ORCPT ); Wed, 13 Jan 2021 21:54:02 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:42062 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbhANCyC (ORCPT ); Wed, 13 Jan 2021 21:54:02 -0500 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 1080E40216; Thu, 14 Jan 2021 02:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592782; bh=W5K7Y9tO9upMy7kuj5bAb9ijb+sUN5HoyWyT6GbkzzA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PuzCVzFSe8zmqyV2OqFEQe6ra0fSUhJMT82DQyMsWVY+d1Z9UcnMsv5D1VWvtqkvC 2PKcpg4z7eYLXFCsCDiV1aeV1UtEuHzk8sTzNALlCLqpvgsaSnXo2UzlEuEEuAoV07 CvqUCeyLlEMbFdlt/YiujMMhlgfZlE56UjjsoOkXfWKGuuo7I4V7i5MsmXHxp+Tv0j HhvXyWdzupKiwyHlKJYNGmEFzgDrjPpgLLzir+xEp4njxdZnPAE/ORU2hlTklLPsnz F43zgfhjtxhOYuYfSeiJ3sHAZFg+7ihG/OYH/VfFBEDK4Mid8bTcCmwcpmhqYfsbSz jq0IC/cy/nVSg== Received: from te-lab16 (unknown [10.10.52.11]) (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 EE4A7A0070; Thu, 14 Jan 2021 02:53:00 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:00 -0800 Date: Wed, 13 Jan 2021 18:53:00 -0800 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 03/11] usb: gadget: Introduce SSP rates and lanes To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A USB device controller operating in SuperSpeed Plus may support gen2x1, gen1x2, and/or gen2x2. Introduce SuperSpeed Plus signaling rate generation and lane count to usb_gadget with the fields ssp_rate and max_ssp_rate. The gadget driver can use these to setup the device BOS descriptor and select the desire operating speed and number of lanes. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Remove all the sublink speed fields and use only usb_ssp_rate enums - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - Change unsigned fields to unsigned int Changes in v3: - None Changes in v2: - None include/linux/usb/gadget.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index e7351d64f11f..02483c862444 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -339,6 +339,10 @@ 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. + * @ssp_rate: Current connected SuperSpeed Plus signaling rate and lane count. + * @max_ssp_rate: Maximum SuperSpeed Plus signaling rate and lane count the UDC + * can handle. The UDC must support this and all slower speeds and lower + * number of lanes. * @state: the state we are now (attached, suspended, configured, etc) * @name: Identifies the controller hardware type. Used in diagnostics * and sometimes configuration. @@ -406,6 +410,11 @@ struct usb_gadget { struct list_head ep_list; /* of usb_ep */ enum usb_device_speed speed; enum usb_device_speed max_speed; + + /* USB SuperSpeed Plus only */ + enum usb_ssp_rate ssp_rate; + enum usb_ssp_rate max_ssp_rate; + enum usb_device_state state; const char *name; struct device dev; From patchwork Thu Jan 14 02:53:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31BB6C433DB for ; Thu, 14 Jan 2021 02:54:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01DBB23602 for ; Thu, 14 Jan 2021 02:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726640AbhANCyK (ORCPT ); Wed, 13 Jan 2021 21:54:10 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:42078 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbhANCyJ (ORCPT ); Wed, 13 Jan 2021 21:54:09 -0500 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (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 1CDA74023D; Thu, 14 Jan 2021 02:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592789; bh=gQUPNcqLD59RQybV3S857P7GuP31zxyogNTdApKiLWk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PeLGxPG7eqi1qM5VdVVwetkzNm6gcIfJ574VFelIfnFYZDWdjvrnjtj8D39oAryjY DxYKOulPoy1DYj5NnlKlgRG4rST51NcbFZA1i1OG0egH5HNsHmibZ9RBhrouYdw4L0 S8Ri2M999d5ZzmyoP3Hm6u6Q3MTkPqsQWhFLz+JRQXLQEvPCMYz+cYkr5FYw+/4+q7 1ywnNpKORljkV4HF6CmerBY7BwmhL1EAYBsFnqQS5UiwCraSIZm46v58CRdNMMkWYO CmfaCPVdJw+y7GBv6GjSf5ny21BoVJrqsXI5tIBWfhOhrMt1iX3cbgOqK1jJkM3Vtv +zbfATfPsNEUg== Received: from te-lab16 (unknown [10.10.52.11]) (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 0ECD6A005E; Thu, 14 Jan 2021 02:53:07 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:07 -0800 Date: Wed, 13 Jan 2021 18:53:07 -0800 Message-Id: <9b85357cdadc02e3f0d653fd05f89eb46af836e1.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 04/11] usb: gadget: Introduce udc_set_ssp_rate() for SSP To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org, Peter Chen , Lee Jones , Alan Stern , Dejin Zheng , "Ahmed S. Darwish" , Marek Szyprowski Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A SuperSpeed Plus device may operate at different speed and lane count (i.e. gen2x2, gen1x2, or gen2x1). Introduce gadget ops udc_set_ssp_rate() to set the desire corresponding usb_ssp_rate for SuperSpeed Plus capable devices. If the USB device supports different speeds at SuperSpeed Plus, set the device to operate with the maximum number of lanes and speed. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Rename udc_set_num_lanes_and_speed() to udc_set_ssp_rate() - Use usb_ssp_rate enum as a parameter instead of SSID - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - Add identifier name for usb_gadget in gadget ops (*udc_set_num_lanes_and_speed) to avoid checkpatch warning Changes in v3: - None Changes in v2: - None drivers/usb/gadget/udc/core.c | 16 +++++++++++----- include/linux/usb/gadget.h | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 98cf9216f3cb..4173acdcd35b 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1133,12 +1133,18 @@ 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 (s == USB_SPEED_SUPER_PLUS && gadget->ops->udc_set_ssp_rate) + gadget->ops->udc_set_ssp_rate(gadget, gadget->max_ssp_rate); + 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 02483c862444..ee04ef214ce8 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -323,6 +323,8 @@ 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_ssp_rate)(struct usb_gadget *gadget, + enum usb_ssp_rate rate); struct usb_ep *(*match_ep)(struct usb_gadget *, struct usb_endpoint_descriptor *, struct usb_ss_ep_comp_descriptor *); From patchwork Thu Jan 14 02:53:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB28FC433E0 for ; Thu, 14 Jan 2021 02:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99E1923602 for ; Thu, 14 Jan 2021 02:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727072AbhANCyS (ORCPT ); Wed, 13 Jan 2021 21:54:18 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54726 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbhANCyQ (ORCPT ); Wed, 13 Jan 2021 21:54:16 -0500 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 49B8CC00EC; Thu, 14 Jan 2021 02:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592795; bh=B9vUG7TcqjYb+YoXx63KO2ohR6T7y5FbM/ETBsWjuH8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=HYymyQVNf9HDXZujOntOVRj6QN8H6NOpetDaNhNjI517vOJ0xkFhf75GkU36ku/zO 9yXO31e9xHG5+pA6CQcbQRjTxbEt1YKTDfcBhTX9j2dKkSXSoqjAwyAjDexzF1r0GI jWIeTndJWfIG/cHxEx0reGcJHb9SjMfYAnIXzoI1/QxtSqz85ZK6uWGkHn6+2T9pEH ScVj2M+4xMJ3J1sc95D8bSt5ONozaE18ThEDkDE9hiWsiVT+u6XitIE8RpWl5Et+s4 hvWHHj8zLBPfaAg9DKtVOLoQAm1QN5sUSTf3j0tHslUp+jMPTfoYRM2ZdbjMVW8J4A hrveXXnmtLxJg== Received: from te-lab16 (unknown [10.10.52.11]) (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 1BF97A009A; Thu, 14 Jan 2021 02:53:14 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:14 -0800 Date: Wed, 13 Jan 2021 18:53:14 -0800 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 05/11] usb: gadget: composite: Report various SSP sublink speeds To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If a gadget supports SuperSpeed Plus, then it may operate in different sublink speeds. For example, if the gadget supports SuperSpeed Plus gen2x2, then it can support 2 sublink speeds gen1 and gen2. Inform the host of these speeds in the BOS descriptor. Use 1 SSID if the gadget supports up to gen2x1, or not specified: - SSID 0 for symmetric RX/TX sublink speed of 10 Gbps. Use 1 SSID if the gadget supports up to gen1x2: - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. Use 2 SSIDs if the gadget supports up to gen2x2: - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. - SSID 1 for symmetric RX/TX sublink speed of 10 Gbps. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Use gadget->max_ssp_rate instead of all the sublink attribute fields (now removed) in usb_gadget - Use the updated macros - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/gadget/composite.c | 80 +++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index bc17302a9e85..72a9797dbbae 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -735,49 +735,77 @@ 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; + u8 ssac = 1; + u8 ssic; + int i; - ssp_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); - bos->bNumDeviceCaps++; + if (cdev->gadget->max_ssp_rate == USB_SSP_GEN_2x2) + ssac = 3; /* - * Report typical values. + * Paired RX and TX sublink speed attributes share + * the same SSID. */ + ssic = (ssac + 1) / 2 - 1; - le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SSP_CAP_SIZE(1)); - ssp_cap->bLength = USB_DT_USB_SSP_CAP_SIZE(1); + ssp_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); + bos->bNumDeviceCaps++; + + 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) | 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_SSP_SUBLINK_SPEED_LSE_GBPS) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, - USB_SSP_SUBLINK_SPEED_ST_SYM_RX) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, - USB_SSP_SUBLINK_SPEED_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_SSP_SUBLINK_SPEED_LSE_GBPS) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, - USB_SSP_SUBLINK_SPEED_ST_SYM_TX) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, - USB_SSP_SUBLINK_SPEED_LP_SSP) | - FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10)); + /* + * Use 1 SSID if the gadget supports up to gen2x1 or not + * specified: + * - SSID 0 for symmetric RX/TX sublink speed of 10 Gbps. + * + * Use 1 SSID if the gadget supports up to gen1x2: + * - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. + * + * Use 2 SSIDs if the gadget supports up to gen2x2: + * - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. + * - SSID 1 for symmetric RX/TX sublink speed of 10 Gbps. + */ + for (i = 0; i < ssac + 1; i++) { + u8 ssid; + u8 mantissa; + u8 type; + + ssid = i >> 1; + + if (cdev->gadget->max_ssp_rate == USB_SSP_GEN_2x1 || + cdev->gadget->max_ssp_rate == USB_SSP_GEN_UNKNOWN) + mantissa = 10; + else + mantissa = 5 << ssid; + + if (i % 2) + type = USB_SSP_SUBLINK_SPEED_ST_SYM_TX; + else + type = USB_SSP_SUBLINK_SPEED_ST_SYM_RX; + + ssp_cap->bmSublinkSpeedAttr[i] = + cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, ssid) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, + USB_SSP_SUBLINK_SPEED_LSE_GBPS) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST, type) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, + USB_SSP_SUBLINK_SPEED_LP_SSP) | + FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, mantissa)); + } } return le16_to_cpu(bos->wTotalLength); From patchwork Thu Jan 14 02:53:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD1EEC433E0 for ; Thu, 14 Jan 2021 02:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9207D23602 for ; Thu, 14 Jan 2021 02:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727261AbhANCyW (ORCPT ); Wed, 13 Jan 2021 21:54:22 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:42090 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbhANCyW (ORCPT ); Wed, 13 Jan 2021 21:54:22 -0500 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 CF9E04023A; Thu, 14 Jan 2021 02:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592801; bh=vsWXmxEBiia0jKEQvLF01p7PujikY/U7HUMvp6lyUHA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=VFvuWvJql+ceiVFAn8xuFfNjzhzpQk5OKhqigbPVXicvDXc8j4vOBBe/X99s2QAaE HQjJmuhLmBGpGDNv56xfb5gELAINSFxsX4LdB3C7V+jiN6mwNDcPDyyHKd2n+buWFi LcMa45+31sLkR+MbEGpe5t+SlmW0GbcE7W8r5JYo4kyKNsG/2S9CEmuiIqnSV/b7zF 7Zid7rWtkldYkMekknT44DMZTBVZO100U0NMF4m+g1bJs+fNcAhgVqrmmp2kakIc8F OTcbCbtTh6hecXYBcmNs2dk3qMI0tXE1EuLEn0zJcrgNROMWcNYafo2JFirackYUDu qhR8p6jtuWdUg== Received: from te-lab16 (unknown [10.10.52.11]) (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 7A790A0096; Thu, 14 Jan 2021 02:53:20 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:20 -0800 Date: Wed, 13 Jan 2021 18:53:20 -0800 Message-Id: <8caee371128fb35649a7501859690235722f3edd.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 06/11] dt-binding: usb: Include USB SSP rates in GenXxY To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org According to the USB 3.2 spec, a SuperSpeed Plus device can operate at gen2x2, gen2x1, or gen1x2. If the USB controller device supports multiple lanes at different transfer rates, the user can specify the HW capability via these new speed strings: "super-speed-plus-gen2x2" "super-speed-plus-gen2x1" "super-speed-plus-gen1x2" If the argument is simply "super-speed-plus", USB controllers should default to their maximum transfer rate and number of lanes. Signed-off-by: Thinh Nguyen --- Changes in v6: - Update the different maximum_speed enums to the usb.yaml - Remove Reviewed-by: Rob Herring because the commit is updated - Rebase on Greg's usb-testing branch - Update commit message Changes in v5: - Add Reviewed-by: Rob Herring - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - Use "maximum-speed" to include both the num-lane and transfer rate for SSP - Remove "num-lanes" and "lane-speed-mantissa-gbps" properties Changes in v2: - Make "num-lanes" and "lane-speed-mantissa-gbps" common USB properties Documentation/devicetree/bindings/usb/usb.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb.yaml b/Documentation/devicetree/bindings/usb/usb.yaml index ebe7f4275c59..78491e66ed24 100644 --- a/Documentation/devicetree/bindings/usb/usb.yaml +++ b/Documentation/devicetree/bindings/usb/usb.yaml @@ -54,6 +54,9 @@ properties: - high-speed - super-speed - super-speed-plus + - super-speed-plus-gen2x1 + - super-speed-plus-gen1x2 + - super-speed-plus-gen2x2 additionalProperties: true From patchwork Thu Jan 14 02:53:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EA3FC433E0 for ; Thu, 14 Jan 2021 02:54:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E464C23602 for ; Thu, 14 Jan 2021 02:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727198AbhANCya (ORCPT ); Wed, 13 Jan 2021 21:54:30 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54736 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbhANCy2 (ORCPT ); Wed, 13 Jan 2021 21:54:28 -0500 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 0336AC00ED; Thu, 14 Jan 2021 02:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592808; bh=i44cN+Fwn/QwipE4UXmVJdl92aOmzD8Hqi+xNu80LJQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=NlYmJ8qijS+Cvi2J5mlFgVhxbRVZoJi5Z/QsFMx5uVHBy6AzPH0ezLW/8XIHDEoHm y6xw9cH2bdYfB1GzPCfn6KON39VR02xX/WuKmPzurBRTq2ZEiOYA9MKTq0umtT0R31 cf8RXL8j+Oes/LqJqRsEG9L20DuUW6sTkuFR01MvaoeXlFxBp+zZjs69bUmxvN+Uba XlOO1Ha9zbXoIggidc+lgzIxbgr6XVHaxJOlbrBmTxvKzgLDGkU3l9FMoTCYnUWOeD RIp60ljEDXDHHYSoLAVHiRDkNhPv0CDB3g56GgXCFOzKgddm7VX87Q7hpJBMkJbz7K O38u8wXne9/RA== Received: from te-lab16 (unknown [10.10.52.11]) (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 C8E89A0070; Thu, 14 Jan 2021 02:53:26 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:26 -0800 Date: Wed, 13 Jan 2021 18:53:26 -0800 Message-Id: <00ebc3fe93b6120ec3995714e63ccea5103d1408.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 07/11] usb: common: Parse for USB SSP genXxY To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The USB "maximum-speed" property can now take the SSP signaling rate generation and lane count with these new strings: "super-speed-plus-gen2x2" "super-speed-plus-gen2x1" "super-speed-plus-gen1x2" Introduce usb_get_maximum_ssp_rate() to parse for the corresponding usb_ssp_rate enum. The original usb_get_maximum_speed() will return USB_SPEED_SUPER_PLUS if it matches one of these new strings. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Remove usb_get_ssp_num_lanes() and usb_get_ssp_phy_gen() and use usb_get_ssp_rate() to return the corresponding usb_ssp_rate enum instead - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - Create 2 functions to get the SSP gen and number of lanes from "maximum-speed" property - Update usb_get_maximum_speed() to check new SSP strings with genXxY - Update commit message and subject title to reflect the new changes Changes in v3: - Add new function to parse "maximum-speed" for lanes and transfer rate - Remove separate functions getting num_lanes and transfer rate properties Changes in v2: - New commit drivers/usb/common/common.c | 26 +++++++++++++++++++++++++- include/linux/usb/ch9.h | 11 +++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 1433260d99b4..fc21cf2d36f6 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -69,6 +69,13 @@ static const char *const speed_names[] = { [USB_SPEED_SUPER_PLUS] = "super-speed-plus", }; +static const char *const ssp_rate[] = { + [USB_SSP_GEN_UNKNOWN] = "UNKNOWN", + [USB_SSP_GEN_2x1] = "super-speed-plus-gen2x1", + [USB_SSP_GEN_1x2] = "super-speed-plus-gen1x2", + [USB_SSP_GEN_2x2] = "super-speed-plus-gen2x2", +}; + const char *usb_speed_string(enum usb_device_speed speed) { if (speed < 0 || speed >= ARRAY_SIZE(speed_names)) @@ -86,12 +93,29 @@ enum usb_device_speed usb_get_maximum_speed(struct device *dev) if (ret < 0) return USB_SPEED_UNKNOWN; - ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); + ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed); + if (ret > 0) + return USB_SPEED_SUPER_PLUS; + ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); return (ret < 0) ? USB_SPEED_UNKNOWN : ret; } EXPORT_SYMBOL_GPL(usb_get_maximum_speed); +enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev) +{ + const char *maximum_speed; + int ret; + + ret = device_property_read_string(dev, "maximum-speed", &maximum_speed); + if (ret < 0) + return USB_SSP_GEN_UNKNOWN; + + ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed); + return (ret < 0) ? USB_SSP_GEN_UNKNOWN : ret; +} +EXPORT_SYMBOL_GPL(usb_get_maximum_ssp_rate); + 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 86c50907634e..abdd310c77f0 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -71,6 +71,17 @@ 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_maximum_ssp_rate - Get the signaling rate generation and lane count + * of a SuperSpeed Plus capable device. + * @dev: Pointer to the given USB controller device + * + * If the string from "maximum-speed" property is super-speed-plus-genXxY where + * 'X' is the generation number and 'Y' is the number of lanes, then this + * function returns the corresponding enum usb_ssp_rate. + */ +extern enum usb_ssp_rate usb_get_maximum_ssp_rate(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 Jan 14 02:53:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 126E3C433E0 for ; Thu, 14 Jan 2021 02:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFDB6235FA for ; Thu, 14 Jan 2021 02:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbhANCyg (ORCPT ); Wed, 13 Jan 2021 21:54:36 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:42094 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbhANCye (ORCPT ); Wed, 13 Jan 2021 21:54:34 -0500 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (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 F1D1E402D8; Thu, 14 Jan 2021 02:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592814; bh=fDfPQgabA7LNKJzzof1Q4IHo0YlwzjVayE/kTwDlxeg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=RD99WqTig4SDsbngdJzydBbyWkvGx+bmj+PqEzyDQPndSi8RW3P1ZhQOgsTAfSig5 3lg5GaCxy5jZzrsT+s06PZhU3sGY3GGf1Yx0ZNeBUbTLYZM3XDrwmWEqUwNiieIOp4 EwXa7YmkkxJbTt0Dw1MjnaOzDORYAn6//03CnhwBNicUrPovFDdrI+s22Afv3LOFqk G4PlZ77AIirQ/IelyQ9hWAEWuxYBNMZBu+AqjZj40rEpAKs4TOOHP/SaOA900TkTGD Chu+TX0ys4DyfoPLXQ19qxafRcJrstqcUmC4cmePA8d++Xl7rJQPdqTQ/dGdVKKrRq kNttyDKQvqMUg== Received: from te-lab16 (unknown [10.10.52.11]) (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 DD269A005E; Thu, 14 Jan 2021 02:53:32 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:32 -0800 Date: Wed, 13 Jan 2021 18:53:32 -0800 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 08/11] usb: dwc3: core: Check maximum_speed SSP genXxY To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The DWC_usb32 controller supports dual-lane SuperSpeed Plus. Check the maximum_speed property for any limitation in the HW to initialize and validate the maximum number of lanes and speed the device will operate. Currently the controller has no visibility into the HW parameter to determine the maximum number of lanes the HW supports. If the number of lanes is not specified for SSP, then set the default rate to gen2x2 for DWC_usb32 and gen2x1 for DWC_usb31. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Update to check for lane count and gen# via usb_ssp_rate enum - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - Use new common funtions to get SSP Gen and number of lanes Changes in v3: - Use new common function to get maximum-speed - Remove num_lanes and lsm validation since they are no longer separate properties - Replace dwc->maxmum_lsm field with dwc->maximum_ssp_rate for gen1/gen2 Changes in v2: - Use common functions to get num_lanes and lsm properties drivers/usb/dwc3/core.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/gadget.c | 1 + 3 files changed, 40 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 6969196fccd6..931ccf93eabd 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1252,6 +1252,7 @@ static void dwc3_get_properties(struct dwc3 *dwc) hird_threshold = 12; dwc->maximum_speed = usb_get_maximum_speed(dev); + dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); dwc->dr_mode = usb_get_dr_mode(dev); dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); @@ -1423,6 +1424,42 @@ static void dwc3_check_params(struct dwc3 *dwc) } break; } + + /* + * Currently the controller does not have visibility into the HW + * parameter to determine the maximum number of lanes the HW supports. + * If the number of lanes is not specified in the device property, then + * set the default to support dual-lane for DWC_usb32 and single-lane + * for DWC_usb31 for super-speed-plus. + */ + if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { + switch (dwc->max_ssp_rate) { + case USB_SSP_GEN_2x1: + if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_GEN1) + dev_warn(dev, "UDC only supports Gen 1\n"); + break; + case USB_SSP_GEN_1x2: + case USB_SSP_GEN_2x2: + if (DWC3_IP_IS(DWC31)) + dev_warn(dev, "UDC only supports single lane\n"); + break; + case USB_SSP_GEN_UNKNOWN: + default: + switch (hwparam_gen) { + case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2: + if (DWC3_IP_IS(DWC32)) + dwc->max_ssp_rate = USB_SSP_GEN_2x2; + else + dwc->max_ssp_rate = USB_SSP_GEN_2x1; + break; + case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1: + if (DWC3_IP_IS(DWC32)) + dwc->max_ssp_rate = USB_SSP_GEN_1x2; + break; + } + break; + } + } } static int dwc3_probe(struct platform_device *pdev) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index ac290d896638..363c1b84f45f 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -964,6 +964,7 @@ 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) + * @max_ssp_rate: SuperSpeed Plus maximum signaling rate and lane count * @ip: controller's ID * @revision: controller's version of an IP * @version_type: VERSIONTYPE register contents, a sub release of a revision @@ -1127,6 +1128,7 @@ struct dwc3 { u32 u1u2; u32 maximum_speed; u32 gadget_max_speed; + enum usb_ssp_rate max_ssp_rate; u32 ip; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index ff14e5bbd152..494e4eca5460 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3889,6 +3889,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) dwc->revision); dwc->gadget->max_speed = dwc->maximum_speed; + dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; /* * REVISIT: Here we should clear all pending IRQs to be From patchwork Thu Jan 14 02:53:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61403C433DB for ; Thu, 14 Jan 2021 02:54:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26B9B23602 for ; Thu, 14 Jan 2021 02:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727373AbhANCyl (ORCPT ); Wed, 13 Jan 2021 21:54:41 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54746 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbhANCyk (ORCPT ); Wed, 13 Jan 2021 21:54:40 -0500 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 2B60AC00EE; Thu, 14 Jan 2021 02:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592820; bh=qoQaTQxnj9t3RSpThZ24T18s6vZtKp1b4iKEdruM/K4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=MDZvVpkv9pTapZhpdTUv7cybuWkZRmm8xzDeenSfNfALgOEPPeqMMqi/P7bwqZyYO HyL1EvuI29TnxjxISAvgZw3NmOCbwvxym5dMEFQ0xfzCy0xMR134zTFC139O0m92ZF JY/vBAjlcEYtOLKpQCVRB6yEtlqNmCYqk5xbscm4Kn7URY6h5O3ICcWiBXdUEqTb2M qrh+mprE0AboHDIQIs+aOEo6BSFI/O2H7FJtQPWmAJ3Hb9QDkMzEuW49aBiNDdAlqS Ei9KsrcWG0LjUHfZNOK0DkVD3uprRYUCpzHhvOoXCLKuaCnfTMvTWDNIYAqvuas1TN 3TBfWBrhfloow== Received: from te-lab16 (unknown [10.10.52.11]) (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 F0845A007C; Thu, 14 Jan 2021 02:53:38 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:38 -0800 Date: Wed, 13 Jan 2021 18:53:38 -0800 Message-Id: <1bbbb6cd0d80696c0b1c112a225dad0b0efe8b91.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 09/11] usb: dwc3: gadget: Implement setting of SSP rate To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Implement gadget ops udc_set_ssp_rate(). This allows the gadget/core driver to select SSP signaling rate and number of lanes to for DWC_usb32 controller. Signed-off-by: Thinh Nguyen --- Changes in v6: - Update to use usb_ssp_rate enum - Rebase on Greg's usb-testing branch - Update to match with the latest flow in dwc3 for setting speed Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/dwc3/core.h | 5 +++++ drivers/usb/dwc3/gadget.c | 47 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 363c1b84f45f..8f6e71052c6c 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -386,6 +386,8 @@ #define DWC3_GUCTL3_SPLITDISABLE 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) @@ -965,6 +967,8 @@ struct dwc3_scratchpad_array { * @u1u2: only used on revisions <1.83a for workaround * @maximum_speed: maximum speed requested (mainly for testing purposes) * @max_ssp_rate: SuperSpeed Plus maximum signaling rate and lane count + * @gadget_ssp_rate: Gadget driver's maximum supported SuperSpeed Plus signaling + * rate and lane count. * @ip: controller's ID * @revision: controller's version of an IP * @version_type: VERSIONTYPE register contents, a sub release of a revision @@ -1129,6 +1133,7 @@ struct dwc3 { u32 maximum_speed; u32 gadget_max_speed; enum usb_ssp_rate max_ssp_rate; + enum usb_ssp_rate gadget_ssp_rate; u32 ip; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 494e4eca5460..7f06baac8b62 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2038,10 +2038,40 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc) } } +static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) +{ + enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; + u32 reg; + + if (ssp_rate == USB_SSP_GEN_UNKNOWN) + ssp_rate = dwc->max_ssp_rate; + + reg = dwc3_readl(dwc->regs, DWC3_DCFG); + reg &= ~DWC3_DCFG_SPEED_MASK; + reg &= ~DWC3_DCFG_NUMLANES(~0); + + if (ssp_rate == USB_SSP_GEN_1x2) + reg |= DWC3_DCFG_SUPERSPEED; + else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) + reg |= DWC3_DCFG_SUPERSPEED_PLUS; + + if (ssp_rate != USB_SSP_GEN_2x1 && + dwc->max_ssp_rate != USB_SSP_GEN_2x1) + reg |= DWC3_DCFG_NUMLANES(1); + + dwc3_writel(dwc->regs, DWC3_DCFG, reg); +} + static void __dwc3_gadget_set_speed(struct dwc3 *dwc) { u32 reg; + if (dwc->gadget_max_speed == USB_SPEED_SUPER_PLUS && + DWC3_IP_IS(DWC32)) { + __dwc3_gadget_set_ssp_rate(dwc); + return; + } + reg = dwc3_readl(dwc->regs, DWC3_DCFG); reg &= ~(DWC3_DCFG_SPEED_MASK); @@ -2476,6 +2506,17 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, spin_unlock_irqrestore(&dwc->lock, flags); } +static void dwc3_gadget_set_ssp_rate(struct usb_gadget *g, + enum usb_ssp_rate rate) +{ + struct dwc3 *dwc = gadget_to_dwc(g); + unsigned long flags; + + spin_lock_irqsave(&dwc->lock, flags); + dwc->gadget_ssp_rate = rate; + spin_unlock_irqrestore(&dwc->lock, flags); +} + static int dwc3_gadget_vbus_draw(struct usb_gadget *g, unsigned int mA) { struct dwc3 *dwc = gadget_to_dwc(g); @@ -2494,6 +2535,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_ssp_rate = dwc3_gadget_set_ssp_rate, .get_config_params = dwc3_gadget_config_params, .vbus_draw = dwc3_gadget_vbus_draw, }; @@ -3906,7 +3948,10 @@ int dwc3_gadget_init(struct dwc3 *dwc) goto err5; } - dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); + if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) + dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); + else + dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); return 0; From patchwork Thu Jan 14 02:53:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60447C433E0 for ; Thu, 14 Jan 2021 02:54:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F23623602 for ; Thu, 14 Jan 2021 02:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727383AbhANCyr (ORCPT ); Wed, 13 Jan 2021 21:54:47 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54756 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbhANCyq (ORCPT ); Wed, 13 Jan 2021 21:54:46 -0500 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 3EFBDC00E8; Thu, 14 Jan 2021 02:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592826; bh=pG5HGJ4CA0OpJ9fui3M+QSjNOMdND+1UCPEDmGQ8M/I=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=hcjxBTU4IndW7MTNz56bhgaGqajD9+3Rz/cJ1QHoLUTi0xLwdW47vryRoaHo6I3ZB iizT5JuZ6U+Td2wqrSbLf2pX79mjfRUmFUpiaEDjQfOB7oOEsnAStqA5aZW7rIaHKg NS0DuHXIHNtovWMd9qHy3X0MSxkl+8D6vmGslHx1ZU/kwgUbUv6XjIxckH3hbYYphd EOaJzuERWnmEBdgdcLCnGzkEpDoaXDWzxeuKYFLUKdy3IA+58/CTs23hR+tWgHXAoW Cjq7oSwHCsl//ykGDXk1FpEedo1/Q0wX4/6fEmVE+LE7SYXtGJm9544fop9SUCuIrr 8GNHiOgnqjynQ== Received: from te-lab16 (unknown [10.10.52.11]) (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 10AA0A0096; Thu, 14 Jan 2021 02:53:45 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:45 -0800 Date: Wed, 13 Jan 2021 18:53:45 -0800 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 10/11] usb: dwc3: gadget: Track connected SSP rate and lane count To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Track the number of connected lanes and speed in corresponding enum usb_ssp_rate for SuperSpeed Plus capable device. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Update commmit message - Update to report the rate and lane count in usb_ssp_rate enum Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - Update commit with updated field name - No longer use DWC3_LSM_5/10_GBPS macros 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 | 2 ++ drivers/usb/dwc3/gadget.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 8f6e71052c6c..304912e84053 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -461,6 +461,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 7f06baac8b62..f46498f6d794 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2120,6 +2120,12 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc) reg |= DWC3_DCFG_SUPERSPEED_PLUS; } } + + if (DWC3_IP_IS(DWC32) && + dwc->gadget_max_speed > USB_SPEED_UNKNOWN && + dwc->gadget_max_speed < USB_SPEED_SUPER_PLUS) + reg &= ~DWC3_DCFG_NUMLANES(~0); + dwc3_writel(dwc->regs, DWC3_DCFG, reg); } @@ -3370,12 +3376,18 @@ 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->ssp_rate = USB_SSP_GEN_UNKNOWN; + /* * RAMClkSel is reset to 0 after USB reset, so it must be reprogrammed * each time on Connect Done. @@ -3390,6 +3402,11 @@ 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; + + if (lanes > 1) + dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; + else + dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; break; case DWC3_DSTS_SUPERSPEED: /* @@ -3411,6 +3428,11 @@ 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->ssp_rate = USB_SSP_GEN_1x2; + } break; case DWC3_DSTS_HIGHSPEED: dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); @@ -3905,6 +3927,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) dev->platform_data = dwc; dwc->gadget->ops = &dwc3_gadget_ops; dwc->gadget->speed = USB_SPEED_UNKNOWN; + dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; dwc->gadget->sg_supported = true; dwc->gadget->name = "dwc3-gadget"; dwc->gadget->lpm_capable = true; From patchwork Thu Jan 14 02:53:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12018521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44149C433E0 for ; Thu, 14 Jan 2021 02:54:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00EBC23602 for ; Thu, 14 Jan 2021 02:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbhANCyx (ORCPT ); Wed, 13 Jan 2021 21:54:53 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:54762 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727393AbhANCyw (ORCPT ); Wed, 13 Jan 2021 21:54:52 -0500 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 5A421C00EB; Thu, 14 Jan 2021 02:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1610592832; bh=wCECJLxEql/0s9XFULQniV2CTnU6HAwLxidoDcapPFY=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=NePJRzVYOfW6O7u3G2IGSYp5PdQgkOoOJMvcnPDMxxD9s/b2qrCiqLGlfwdSWgT4/ unXP/nQazdl6IZ2thxougUrBNT1oyi6z2fLFx161msuJtLT9uQ4K/yoTbKvRtxYm6a jG66GzYoxnvEqDj51sOwcY4gHBIIJ7MKOZKGpeoebO244jWBzKqzADsVyXjk5rEr39 rQ1CEbFFnahsnwncdLG2UFHNDHWYcvDnQArya35FrgNvT++LD9BF8i4K0VUWGcQD5f N2oL83ovnchEtMO/XPwvMqep5vYNwxZGCQL0aVntEzN1lwvAzb1MU55lplv5MPTBmL mLQ00Jg4N4Xpw== Received: from te-lab16 (unknown [10.10.52.11]) (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 2BD97A007C; Thu, 14 Jan 2021 02:53:51 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 13 Jan 2021 18:53:51 -0800 Date: Wed, 13 Jan 2021 18:53:51 -0800 Message-Id: <4bd3b87df2020330ebfd9962a5a57b19bd3552de.1610592135.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v6 11/11] usb: dwc3: gadget: Set speed only up to the max supported To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The setting of the device speed should be limited by the device's maximum_speed. Check and prevent the driver from attempting to configure higher than the maximum_speed. Signed-off-by: Thinh Nguyen --- Changes in v6: - Rebase on Greg's usb-testing branch - Update to follow the latest change of dwc3 on Greg's usb-testing branch - Update commit message Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/dwc3/gadget.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f46498f6d794..c9abc5e762b6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2064,9 +2064,14 @@ static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) static void __dwc3_gadget_set_speed(struct dwc3 *dwc) { + enum usb_device_speed speed; u32 reg; - if (dwc->gadget_max_speed == USB_SPEED_SUPER_PLUS && + speed = dwc->gadget_max_speed; + if (speed > dwc->maximum_speed) + speed = dwc->maximum_speed; + + if (speed == USB_SPEED_SUPER_PLUS && DWC3_IP_IS(DWC32)) { __dwc3_gadget_set_ssp_rate(dwc); return; @@ -2092,7 +2097,7 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc) !dwc->dis_metastability_quirk) { reg |= DWC3_DCFG_SUPERSPEED; } else { - switch (dwc->gadget_max_speed) { + switch (speed) { case USB_SPEED_LOW: reg |= DWC3_DCFG_LOWSPEED; break; @@ -2112,7 +2117,7 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc) reg |= DWC3_DCFG_SUPERSPEED_PLUS; break; default: - dev_err(dwc->dev, "invalid speed (%d)\n", dwc->gadget_max_speed); + dev_err(dwc->dev, "invalid speed (%d)\n", speed); if (DWC3_IP_IS(DWC3)) reg |= DWC3_DCFG_SUPERSPEED; @@ -2122,8 +2127,8 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc) } if (DWC3_IP_IS(DWC32) && - dwc->gadget_max_speed > USB_SPEED_UNKNOWN && - dwc->gadget_max_speed < USB_SPEED_SUPER_PLUS) + speed > USB_SPEED_UNKNOWN && + speed < USB_SPEED_SUPER_PLUS) reg &= ~DWC3_DCFG_NUMLANES(~0); dwc3_writel(dwc->regs, DWC3_DCFG, reg);