From patchwork Sun Jul 26 01:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685397 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 1AAC31709 for ; Sun, 26 Jul 2020 01:36:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0239F206D7 for ; Sun, 26 Jul 2020 01:36:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="CakCpjW5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727101AbgGZBgC (ORCPT ); Sat, 25 Jul 2020 21:36:02 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:44722 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgB (ORCPT ); Sat, 25 Jul 2020 21:36:01 -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 22924C00A4; Sun, 26 Jul 2020 01:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727361; bh=eE8oxEbrpbMIoOoh2lVzF8KdaBmbP4bSXHg6X2TlUDA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=CakCpjW52CCP7Mq4+NanZYcMDG4V+JSxef0+JkwoqOrK/LRRaMwEC4C1OAAXHljHI j2cEQQBjN0JeyjU6Htf5WVo+dHcYZ/5tNtV4nk5qYJgMclyJT9j+KlXkA4jWWvIzST Uu/vKEIiz8krWr+Ud3SdxAmRdgy9hooUEMqBEK6hbMJ4GE3swjk7MNiKM5I/4/I+2t iJXyu3o7D6U8bOvp2HPkF23L4IWH8kXgLrnufyndJupLmmCF5S+MxXbv0yL0oRLr83 lXWWLGFG+e6EYdTzjG9Su1EfduCcSYqEw0JfDXmhe/tSUkSBZ7aL3Jx0bXK0/MEODW zp/8Pc4UzTO2Q== 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 A3BBCA0096; Sun, 26 Jul 2020 01:35:59 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:35:59 -0700 Date: Sat, 25 Jul 2020 18:35:59 -0700 Message-Id: <0ac6bfdfa164df18faf2a91c8c4266aa446d444e.1595727196.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 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 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index 604c6c514a50..01191649a0ad 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 Sun Jul 26 01:36:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685399 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 9570513B4 for ; Sun, 26 Jul 2020 01:36:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D3DF206D7 for ; Sun, 26 Jul 2020 01:36:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="JgJm4Bc7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbgGZBgI (ORCPT ); Sat, 25 Jul 2020 21:36:08 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50668 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgI (ORCPT ); Sat, 25 Jul 2020 21:36:08 -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 1FD2D40141; Sun, 26 Jul 2020 01:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727367; bh=In4vjXQYh/rtDxeA2nUouc6MthDzwKvSAUN2HxNn9iI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=JgJm4Bc7HJHxAJZYsjQyzC355Ku3nPeXPhCR+kSjeG+LWGMqjbzsAC59DU0Wow7ym MiHo2C3UyfiC96RsvFCxxBokXQLLIPs3MwadIz4tAxn8FPJLLTzgdCO4G19m+qGe8N Fkk4wU1v4BI3BqNcG2Z60521z8y3WdstmPhZEbHaThLw87szUIiYOtNHe3bQCne6q1 r0c2uK7+syk6ltWEdUJJN2aQLUkoGJPY9HlW3Ku6zWsW4u4Ri21hUckP8ndSyEcbnR WowHoSAY2bUfmm3Bv0RTquTJlqJxuS58io+frJatRyq/Dr1ka6rk2CcU9C+oNdxuL8 8bBnDo7ul83VA== 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 07522A006F; Sun, 26 Jul 2020 01:36:06 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:05 -0700 Date: Sat, 25 Jul 2020 18:36:05 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - None Changes in v3: - None 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 05b176c82cc5..0aa4cb49aa53 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 Sun Jul 26 01:36:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685401 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 9A14F13A4 for ; Sun, 26 Jul 2020 01:36:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 808C9206D7 for ; Sun, 26 Jul 2020 01:36:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="KcSRA9kg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727861AbgGZBgN (ORCPT ); Sat, 25 Jul 2020 21:36:13 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50676 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgN (ORCPT ); Sat, 25 Jul 2020 21:36:13 -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 35DEF40141; Sun, 26 Jul 2020 01:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727373; bh=3fp/cDREhQGNDw/AkR1n4G4BuiVYAYEHskNxXjnXthk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=KcSRA9kgH0n53DHGuYr8bk3jseHeXqmRpki4DajlBA6Tvnui4sOuwhwJx3w9r1dUI 6x3uf/eLqohTbENOv0Nf8MJZyM2Ufi9aG11thfTjMD8lXT32ilMNR9o07SPHxJVter yly6XglpaNd3XcknW3cnGyEDSqA0/4AuZNNoLfoWcmlUBlYwxI1c19brwo6l7/UYwB PEIElma1zcvXNHvkyCh8fkkILEbCSwKY+BM4/K/PfLCtA5QsEWiObbuxKtYjVlgq/w 7V6Gih2QTxrXa+9OsrcgFI6al0AW2bxMeCV50Xp4SJ+k3gfg/lHr6Wknzt/VZgfP0W fIuzba+t0Oiew== 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 1D1D4A0096; Sun, 26 Jul 2020 01:36:12 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:12 -0700 Date: Sat, 25 Jul 2020 18:36:12 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - Change unsigned fields to unsigned int Changes in v3: - None 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 52ce1f6b8f83..d25aefaacba0 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -339,6 +339,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. @@ -406,6 +415,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 int num_lanes; + unsigned int max_num_lanes; + unsigned int ssac; +#define USB_GADGET_MAX_SSAC 3 + struct usb_sublink_speed sublink_speed[USB_GADGET_MAX_SSAC + 1]; + unsigned int speed_ssid; + unsigned int min_speed_ssid; + unsigned int max_speed_ssid; + enum usb_device_state state; const char *name; struct device dev; From patchwork Sun Jul 26 01:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685403 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 CA6BE13A4 for ; Sun, 26 Jul 2020 01:36:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B36772070E for ; Sun, 26 Jul 2020 01:36:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="k48CT+Lq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbgGZBgW (ORCPT ); Sat, 25 Jul 2020 21:36:22 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:44738 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgV (ORCPT ); Sat, 25 Jul 2020 21:36:21 -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 244FBC00A4; Sun, 26 Jul 2020 01:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727381; bh=IoIpYWUbBgyDgfAVz1ui3L1DGhQB8+u/80SeUDRgvZE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=k48CT+LqSudhiOAAh7n5jEsJwVPOWkGqazLFew7cET273UPsahLma3/M+opAkTCtq Hm4alGCo+RAayErfLXVpq1w6GGn3hLG56EcrvsqB7BDGzAHuXUL/bcQbZfcUAmQ/UT WEJUvVJwdTSfw/dHyaejwxdG9Bh5hj9lDVtrEtRN5MlLNVwAHRMQ3WdlzSImQkKOdm barY+s43VyGfgB+YE95C1pCAGmC74+UBRzr/6pWjNwOhQypWbLfqYM6ZW5H64DY6Mu m1107D5CvVt8DpKMc2VHgla3nOt8G0bxc/lbVazuH/q4Dwm3LnNj8l4Mh3PXrTYf3C vTOiMOmvPRquA== 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 67A19A0099; Sun, 26 Jul 2020 01:36:18 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:18 -0700 Date: Sat, 25 Jul 2020 18:36:18 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 , Lee Jones , Alan Stern , Dejin Zheng , Roger Quadros 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 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 | 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 4f82bcd31fd3..e5f569dc9ee0 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1114,12 +1114,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 d25aefaacba0..3bbd8d7a80ad 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -323,6 +323,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 *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 Sun Jul 26 01:36:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685405 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 3EC2F13A4 for ; Sun, 26 Jul 2020 01:36:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 260ED206D7 for ; Sun, 26 Jul 2020 01:36:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="ZpL2RS7c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727886AbgGZBg1 (ORCPT ); Sat, 25 Jul 2020 21:36:27 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50678 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBg1 (ORCPT ); Sat, 25 Jul 2020 21:36:27 -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 1E82940141; Sun, 26 Jul 2020 01:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727387; bh=87ml2iWRy7mIiJrILI7/dFvJupvPzhVXyAkHikvVucc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZpL2RS7ceWohWYfJVf2KV/uzC8RvomU3/roVK4gBLwOTGRS9GaTtAu2SsHThWE/yH OO/TsTov0QC0XYR78YyBhXOpyDXPyFCWSW3WlmSofrHhjlBP+XWp+NC5AR1AuY5b3c KX1Wne97BPQ5o0/OzQOBD/CZTvAIjJy/c2HVvHgNE4/O+7vhQE6ecICeL57GfkMeX3 6h++sqs6BUZWNztNs7U6ljKfBcCPkn3s+H/s5jAcoSncYmCeFwzhFJEloR9M2b8t6x pTSAqYi4UEuVj40FvLAWoJXR02eSpD+fWz2Crd95sRAS3vvvKmFHXqgiNKkEB3abqX Vt1akyLIitGWg== 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 071F0A0096; Sun, 26 Jul 2020 01:36:26 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:25 -0700 Date: Sat, 25 Jul 2020 18:36:25 -0700 Message-Id: <3a0c19f74becaf011b184aeab966d2125f80f2d9.1595727196.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - None Changes in v3: - None 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 0aa4cb49aa53..2d0b7af4b08f 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 Sun Jul 26 01:36:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685407 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 A6AB913B4 for ; Sun, 26 Jul 2020 01:36:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F1012076C for ; Sun, 26 Jul 2020 01:36:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="e531R2tE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727936AbgGZBgd (ORCPT ); Sat, 25 Jul 2020 21:36:33 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50686 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgd (ORCPT ); Sat, 25 Jul 2020 21:36:33 -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 34FB240141; Sun, 26 Jul 2020 01:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727393; bh=DVOt8I99N7sLMsKH9eN3nOY5VifOBlHSxAaHgvWrwag=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=e531R2tEacIirRuOeCr+eu8kA3UQ2Q/y3Cm2Rtap2Z0YDXST7p3wl3X5vJnuEJ5cY +b4YyTGTI8QXujF9MFAG0vkrMqjmv97TqyK+NLoIUMFwkXQ4Y87ArlyQZ/52NAqRhr 0dNgwCd9Ye3xJUg/1TXCKC++/XAbwcI0+ZtHT+maPToSzdq2Ge6hgum7+c4+yc/s+k glYTIYvQV4Rz080Bm+xJ1j+YGkNAprxHFqhFTJzHZXLHtm5RwXi+FIeSvAyHUl/c5x 23RvlpTVE/0ha9kno6PNzpg6XGU0fL+wda7wthtZtX/E4y08YyiJCc1omp8lvukhSZ VSlynaBd80kuw== 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 1D493A0096; Sun, 26 Jul 2020 01:36:32 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:32 -0700 Date: Sat, 25 Jul 2020 18:36:32 -0700 Message-Id: <3cf8c20044d15dfa5e5113b3a532054b4f96c13f.1595727196.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 06/12] usb: devicetree: Include USB SSP Gen X x Y 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 the USB 3.2 spec, a super-speed-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 Reviewed-by: Rob Herring --- 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/generic.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index ba472e7aefc9..8541b9571f2f 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -3,10 +3,13 @@ Generic USB Properties Optional properties: - maximum-speed: tells USB controllers we want to work up to a certain speed. Valid arguments are "super-speed-plus", - "super-speed", "high-speed", "full-speed" and - "low-speed". In case this isn't passed via DT, USB - controllers should default to their maximum HW - capability. + "super-speed-plus-gen2x2", "super-speed-plus-gen2x1", + "super-speed-plus-gen1x2", "super-speed", "high-speed", + "full-speed" and "low-speed". In case this isn't passed + via DT, USB controllers should default to their maximum + HW capability. Similarly, if the argument is + "super-speed-plus", USB controllers should default to + their maximum transfer rate and number of lanes. - 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 Sun Jul 26 01:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685409 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 E038714E3 for ; Sun, 26 Jul 2020 01:36:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C25992070E for ; Sun, 26 Jul 2020 01:36:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="NiNGvsfo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727982AbgGZBgk (ORCPT ); Sat, 25 Jul 2020 21:36:40 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:44756 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgk (ORCPT ); Sat, 25 Jul 2020 21:36:40 -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 61D5CC00A4; Sun, 26 Jul 2020 01:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727399; bh=B/sN0I1nxMyQzNfkznij0Z+y9CIFuqs1Uu00ejQjuA4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=NiNGvsfo1MGyWwhMZzSBnXhT/51detnj40cuQx2X8hP0q67lD8pIvz2wrLyk7xSCf 2DrLG52dsP3JEEizH4pfhCSI2wZOJZfOZQsyp+eUvxLethsYRjAlRlHsM7DFNZYgN/ voNs6Lpgn209a8SGOqvtJGsVubXY4IMUc56H6QAVw+1Ejzi9p8lPgeiUIRxPxqV4Q4 ErazA6PFOySeRKkj1oY/s1kD3enBCWnLQ5cRl9TCijG5q2V80Ajt7t8I22jPizsoea nO6O0DXAhdE6O0lwU91bDwN+AVzBGHqZuHPhleodGOHFBDJUI8Tp0Z7Sr9n6AkAmxq NTFckgag8l44g== 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 327ECA0096; Sun, 26 Jul 2020 01:36:38 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:38 -0700 Date: Sat, 25 Jul 2020 18:36:38 -0700 Message-Id: <29a706f98413d6dc5df82fd24958ce47da1f0ebf.1595727196.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 07/12] usb: common: Add and update common functions for SSP speeds 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 "maximum-speed" property now can take these new strings for super-speed-plus: "super-speed-plus-gen2x2" "super-speed-plus-gen2x1" "super-speed-plus-gen1x2" As a result, let's do the follow: * Update usb_get_maximum_speed() to parse these new speed strings * Add 2 new common functions to get the Gen number and number of lanes Signed-off-by: Thinh Nguyen --- 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 | 46 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/usb/ch9.h | 30 +++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 1433260d99b4..b3b3972d5be7 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -86,12 +86,56 @@ 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); + if (strncmp("super-speed-plus-gen2x2", maximum_speed, 23) == 0 || + strncmp("super-speed-plus-gen2x1", maximum_speed, 23) == 0 || + strncmp("super-speed-plus-gen1x2", maximum_speed, 23) == 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); +u8 usb_get_ssp_num_lanes(struct device *dev) +{ + const char *maximum_speed; + int ret; + + ret = device_property_read_string(dev, "maximum-speed", &maximum_speed); + if (ret < 0) + return 0; + + if (strncmp("super-speed-plus-gen2x1", maximum_speed, 23) == 0) + return 1; + + if (strncmp("super-speed-plus-gen2x2", maximum_speed, 23) == 0 || + strncmp("super-speed-plus-gen1x2", maximum_speed, 23) == 0) + return 2; + + return 0; +} +EXPORT_SYMBOL_GPL(usb_get_ssp_num_lanes); + +enum usb_phy_gen usb_get_ssp_phy_gen(struct device *dev) +{ + const char *maximum_speed; + int ret; + + ret = device_property_read_string(dev, "maximum-speed", &maximum_speed); + if (ret < 0) + return USB_PHY_GEN_UNKNOWN; + + if (strncmp("super-speed-plus-gen1x2", maximum_speed, 23) == 0) + return USB_PHY_GEN_1; + + if (strncmp("super-speed-plus-gen2x2", maximum_speed, 23) == 0 || + strncmp("super-speed-plus-gen2x1", maximum_speed, 23) == 0) + return USB_PHY_GEN_2; + + return USB_PHY_GEN_UNKNOWN; +} +EXPORT_SYMBOL_GPL(usb_get_ssp_phy_gen); + 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 01191649a0ad..bd13d27551e5 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -57,6 +57,13 @@ enum usb_link_protocol { USB_LP_SSP = 1, }; +/* USB phy signaling rate generation */ +enum usb_phy_gen { + USB_PHY_GEN_UNKNOWN, + USB_PHY_GEN_1, + USB_PHY_GEN_2, +}; + /** * struct usb_sublink_speed - sublink speed attribute * @id: sublink speed attribute ID (SSID) @@ -105,6 +112,29 @@ 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_ssp_num_lanes - Get requested number of lanes for a given + * super-speed-plus capable USB controller. + * @dev: Pointer to the given USB controller device + * + * If the string from "maximum-speed" property is super-speed-plus-genXxY where + * 'Y' is the number of lanes, then this function returns 1 for single lane and + * 2 for dual-lane base on 'Y'. If the number of lanes is not specified, then it + * returns 0. + */ +extern u8 usb_get_ssp_num_lanes(struct device *dev); + +/** + * usb_get_ssp_phy_gen - Get requested phy signaling rate generation for a given + * super-speed-plus capable USB controller. + * @dev: Pointer to the given USB controller device + * + * If the string from "maximum-speed" property is super-speed-plus-genXxY where + * 'X' is the Gen number, then this function returns the corresponding enum + * usb_phy_gen base on 'X'. + */ +extern enum usb_phy_gen usb_get_ssp_phy_gen(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 Sun Jul 26 01:36:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685411 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 9B27C912 for ; Sun, 26 Jul 2020 01:36:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D7712074A for ; Sun, 26 Jul 2020 01:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Nmmg3PEH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgGZBgq (ORCPT ); Sat, 25 Jul 2020 21:36:46 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50704 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgp (ORCPT ); Sat, 25 Jul 2020 21:36:45 -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 5DFA140141; Sun, 26 Jul 2020 01:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727405; bh=2EPOZV44tvt6JK7Xb6/dLzgGkNyOzOYZYxR1XTk+THI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Nmmg3PEHPqax4/AfuEuW7WGhrp7Lottsalh4KiBvjNqgygwHhsz0AzKhJpqrmnNu+ tWoD+w8DJGQBTidH/YSa8E4Pa+d+ytI7Vmf9eiFwi7SLPwWFn5Tqmifij9xxi/sRWG b7LbmBCTflQWZM2sYDw3QTiQaGUGsWOnX6McXiCyCMY9c+K2mJY1HRTOBzVJX1KHlM vN70z5Sn0bLfbyv9mGSJaEhQTsruwDOAafGDCAxHvaiP5OT2Nq6Le01AitdpJDzU7V exULKdcE4AU8zSeOTkBvCMydH2PlVch7U1rrI+PEG1dkWzC5imoRc/TmeL8fRzZBN/ 3drn4z+cOZnAA== 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 46729A009A; Sun, 26 Jul 2020 01:36:44 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:44 -0700 Date: Sat, 25 Jul 2020 18:36:44 -0700 Message-Id: <7cab93ed95248b3b153deebe7694c57b7ffa91dc.1595727196.git.thinhn@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 in the maximum_speed property. 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, then set the default to 2 for DWC_usb32 and 1 for DWC_usb31 for SSP. Signed-off-by: Thinh Nguyen --- 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 | 29 +++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b2ea96d2db04..d3604c74cac5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1268,6 +1268,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) hird_threshold = 12; dwc->maximum_speed = usb_get_maximum_speed(dev); + dwc->maximum_phy_gen = usb_get_ssp_phy_gen(dev); + dwc->maximum_num_lanes = usb_get_ssp_num_lanes(dev); dwc->dr_mode = usb_get_dr_mode(dev); dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); @@ -1436,6 +1438,33 @@ 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 2 for DWC_usb32 and + * 1 for DWC_usb31 for super-speed-plus. + */ + if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) { + if (DWC3_IP_IS(DWC32)) { + if (dwc->maximum_phy_gen == USB_PHY_GEN_UNKNOWN) + dwc->maximum_phy_gen = USB_PHY_GEN_2; + + if (!dwc->maximum_num_lanes) + dwc->maximum_num_lanes = 2; + + } else if (DWC3_IP_IS(DWC31)) { + if (dwc->maximum_num_lanes > 1) + dev_warn(dev, "UDC doesn't support multi-lanes\n"); + + dwc->maximum_phy_gen = USB_PHY_GEN_2; + dwc->maximum_num_lanes = 1; + } + } else { + dwc->maximum_phy_gen = USB_PHY_GEN_UNKNOWN; + dwc->maximum_num_lanes = 0; + } } static int dwc3_probe(struct platform_device *pdev) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 2f04b3e42bf1..3bbfbeaa67d8 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -958,6 +958,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_phy_gen: maximum phy signaling rate + * @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 +990,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 +1122,8 @@ struct dwc3 { u32 nr_scratch; u32 u1u2; u32 maximum_speed; + enum usb_phy_gen maximum_phy_gen; + u8 maximum_num_lanes; u32 ip; @@ -1184,6 +1189,7 @@ struct dwc3 { u8 u1pel; u8 speed; + u8 num_lanes; u8 num_eps; From patchwork Sun Jul 26 01:36:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685413 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 1BABD912 for ; Sun, 26 Jul 2020 01:36:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 031522070E for ; Sun, 26 Jul 2020 01:36:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Kbov/VRt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728060AbgGZBgw (ORCPT ); Sat, 25 Jul 2020 21:36:52 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:44764 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBgw (ORCPT ); Sat, 25 Jul 2020 21:36:52 -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 B0A8CC00A4; Sun, 26 Jul 2020 01:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727411; bh=J/cZTYFQc7GJmEpeGYVEejAFKP3fdn61nUpOic6jVG8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Kbov/VRtl9xoSFIFj5DqgYKfu2FQJ1zb/VHCLKamjQemasWCKoorSI9uERvYkaUfP 984eSd0LCNavy8aFHspoTWRRWwkeew22ZAJyKk02rmge9nvnGlpL7+G1/99Mlb/OWd H8MgXDH65LfpJOpIdSCdYjRCbbnc/ndbm2Gh8zGJTmt59pnH7500YZE3W9GV7MvILc qDAShM/n48MemDbDDAzxTSC9IjtE5DPA+Z+iBCo8wGettXQ8fKG4k/L60p7KSHP1hc ow5e4clbL5fnkhRJS1X1GFhOtGsDqfJJ0fU/edcuveDn/jXv64zjpr/tk2tocj5cSP VkCAqJetX57DQ== 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 5D4AFA0070; Sun, 26 Jul 2020 01:36:50 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:50 -0700 Date: Sat, 25 Jul 2020 18:36:50 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 HW capability from the device maximum_speed property. 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 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 | 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 3bbfbeaa67d8..0ec675327014 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 +/* 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 e44bfc3b5096..3038dae970f3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3686,6 +3686,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_phy_gen == USB_PHY_GEN_2 && + 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_phy_gen == USB_PHY_GEN_1 && + 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 = 5; + else + ssa->mantissa = 10; + + /* 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 Sun Jul 26 01:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685415 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 E8B09912 for ; Sun, 26 Jul 2020 01:36:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D02AA2070E for ; Sun, 26 Jul 2020 01:36:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="YNc25dgN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728120AbgGZBg6 (ORCPT ); Sat, 25 Jul 2020 21:36:58 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50708 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBg6 (ORCPT ); Sat, 25 Jul 2020 21:36:58 -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 AB4D440141; Sun, 26 Jul 2020 01:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727417; bh=KohcknH3N7ogclOpTno5QaJ2O06Q/SO6YoOyDi+16W4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=YNc25dgN7q5QGPonzTFnDd9MuVp41fV/LgNzTZK6sNaQAkbcUBNmcRq+B8BoDx5E/ 2H+eSZF0TWxoDTbcCRHG6EPzrVUVSc/VjIRDr/Mi45q8ZeETNulodiJuK9iQYwfmub yM0Yq7n0Gv4vT+suNWhtsVHIXYZp3XgWIgMNJVIFaZWsm++doWHqVlz0tgpRpQnyXP /bM2Q0tfnJuIDTk0eUFriSMDh+d7NLrplRrVR3kwT40+r+1iQ4DTmi70Ac7wc8Zcz7 8GqpmE4VR/+C9m45HslMMFxKexyCAo/JADkaq/ZxT9zes/aONS/BcDt6VX+A99lqe+ Ft4mO01aBwlfQ== 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 71B22A006F; Sun, 26 Jul 2020 01:36:56 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:36:56 -0700 Date: Sat, 25 Jul 2020 18:36:56 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - None Changes in v3: - None 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 0ec675327014..9466c4c36963 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -385,6 +385,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 3038dae970f3..b7da4e1c81aa 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2333,6 +2333,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 5: + reg |= DWC3_DCFG_SUPERSPEED; + break; + case 10: + 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, @@ -2341,6 +2397,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, }; @@ -3751,7 +3808,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 Sun Jul 26 01:37:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11685417 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 C0126912 for ; Sun, 26 Jul 2020 01:37:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A572C2070E for ; Sun, 26 Jul 2020 01:37:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="azeCWOGl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbgGZBhE (ORCPT ); Sat, 25 Jul 2020 21:37:04 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50714 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBhE (ORCPT ); Sat, 25 Jul 2020 21:37:04 -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 9C6C240141; Sun, 26 Jul 2020 01:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727423; bh=9bgh2AIL5X3+63v18H0ak1MkBkbSw9foGZ7QjuXB304=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=azeCWOGlh+d4fduuENvJIgnDTyiFnzpWzxk204fGR6OXSb/F7nTp9eRXQawr0ABYs /wSt/+8TOJHX23j8QOx8KTxUXrynWg7sVb68f3hiV7/aBcyErWOG/lgqfQMUoJwjwP eVJg9Q0+hWdKsl3Ep3p+pTtGD30OmrOUOx39dqIrxHeuUSBUGYrdtF70wJoBVW25aP 95wMClRT3GVOqp/tb6YkUIoPdpBsjmAE1pj2SGyB/Ya/In3iv6/PfTwvvIGp94VxwK lmo+vz9LSLnWzN+x1X4mztfcVLCZgDpbuEH/NOw8LVDMYgsak9I5LJojmGeqV9iwan WkLX2/hJ5Hasg== 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 85D9FA0096; Sun, 26 Jul 2020 01:37:02 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:37:02 -0700 Date: Sat, 25 Jul 2020 18:37:02 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - None Changes in v3: - None 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 9466c4c36963..4a70b1e4d2a7 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -460,6 +460,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 b7da4e1c81aa..05defaf0f745 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2328,6 +2328,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); @@ -3199,12 +3203,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. @@ -3219,6 +3230,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: /* @@ -3239,7 +3251,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); @@ -3720,6 +3738,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: 11685419 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 E5E0B912 for ; Sun, 26 Jul 2020 01:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE2A62074A for ; Sun, 26 Jul 2020 01:37:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="jOlz0ETX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgGZBhK (ORCPT ); Sat, 25 Jul 2020 21:37:10 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:44770 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgGZBhK (ORCPT ); Sat, 25 Jul 2020 21:37:10 -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 CC42FC00A4; Sun, 26 Jul 2020 01:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1595727429; bh=uhuR//mEvgHtlmhF9eex6xCFPc79tr2ILwVUeXNX0RY=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=jOlz0ETXcSfbxDDWMBe6iwcMfyHRgoOIZ1r4msCS4oWvekR9HeBSbx8TeI09Bfe0v SuPfHcnfL5+N3g9FI5FXFuZEgmXN+7oHYSAXRe3sWBdpBwVNuCzP8pKYrI0HKrXBxz BIM6XiH6vThO3izlGPKhKR6BptUu8P/6ONmSyj4l53FHFCUS6CVoLzdD7ua9dY8FrU Eq6hKHSdSw0u1Tpg9TUw2EW8zKoLFc80NDWuguxscy4Q93ejJYY3RoDvMzK2JO6rxy vK0thEAwU5MWKJCOJk1s3s7clpOg240exXpRN0TJjRUx/xIF7NVvA1OVhVtLnpQ17Z jFDROW5ML6fsQ== 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 9A1B7A006F; Sun, 26 Jul 2020 01:37:08 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sat, 25 Jul 2020 18:37:08 -0700 Date: Sat, 25 Jul 2020 18:37:08 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v4 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 v4: - None Changes in v3: - None 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 05defaf0f745..f62a9519287a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2276,6 +2276,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; @@ -2300,7 +2301,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; @@ -2320,7 +2324,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; @@ -2329,7 +2334,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);