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);