From patchwork Fri Sep 25 02:42:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297511 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=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 EA05AC4346E for ; Fri, 25 Sep 2020 02:42:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F21620809 for ; Fri, 25 Sep 2020 02:42:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="lPJZz2hU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727032AbgIYCmK (ORCPT ); Thu, 24 Sep 2020 22:42:10 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50854 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbgIYCmJ (ORCPT ); Thu, 24 Sep 2020 22:42:09 -0400 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 485A540624; Fri, 25 Sep 2020 02:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1601001729; bh=TBeZIl7QPvmU04DUqCJEnXFPm+UzA1btzjRp1kVqZgM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=lPJZz2hUVqHgxGo7PNHBlZ8Yv3lGrmA/kaymSufXHrJUcwzpN9n33Bsoe21pMFZ2V aXpjJ0MlbcheyCTh9XAU8R443EjjZG06FtL3pPoabUqxCcqaQgI/cDL19njHK9vjlO mNFEEnzddDMP+uQqAcjvP5XytlpzfgpOo+UeDI7rXQo9ErpzkkRsjbIY49S4aWIC4F a48VraHfc71+e05Cv/RCaX5Zu9TitHeIMS2uApzy1FhRN+qGOT/PmWN8dP3vcqXna0 oDt5qbFicOzRAEZtGVT0wNqHG7p4cGHd4a61C/SWX86SbDLy0F7ORzMfrPS4eZluly eKnk4YYEFmTtA== 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 9883CA0099; Fri, 25 Sep 2020 02:42:07 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 19:42:07 -0700 Date: Thu, 24 Sep 2020 19:42:07 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v5 04/12] usb: gadget: Set max speed for SSP devices To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org, Peter Chen , Lee Jones , Alan Stern , Dejin Zheng , Jun Li , Marek Szyprowski Cc: John Youn 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 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 | 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 debf54205d22..10c0903cf311 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1117,12 +1117,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 cd9433f5a602..cccf3b0fba0a 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 *);