From patchwork Wed Feb 16 09:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 544067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46E0BC433F5 for ; Wed, 16 Feb 2022 09:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232568AbiBPJu7 (ORCPT ); Wed, 16 Feb 2022 04:50:59 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:47152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232563AbiBPJu6 (ORCPT ); Wed, 16 Feb 2022 04:50:58 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D20D6338 for ; Wed, 16 Feb 2022 01:50:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005024; x=1676541024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Apfz2nzKbjJvi9ro1g+ZhOWJw6oVKwC+F1K6hz+UGYo=; b=EGGcMnvedbA6tEzRwBEjy/klwy7zIR12WzGkXzvcGy7/U9qRQ5amovAu 8kBuuvH0Nd7GwsJHUGByC1kA7a6GyA/rkP7byZqW6NfBv7TOITyKshdBQ qzHcfmqdI3NztrreLOfzJAFFGiNN274aaqUqMGL0cbBSy14cXmBLeldXd 66lRLO3HIpTQ9qArfbPLxs5wlUSqI31vq62x+EhIPQrTpoL8d6Hpoo4rR O7L7DH5tsi35TQ9HeNytAFgO0iHKUSX6B2/ORvys3CBZSq52t3eLasddk mdVy05wVNyIG3gRvjh46FHR5kiDuZPCIOGbYSzqIa9f2OORDsohUTTGeF A==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396947" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396947" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410308" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:21 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 1/9] xhci: dbc: refactor xhci_dbc_init() Date: Wed, 16 Feb 2022 11:51:45 +0200 Message-Id: <20220216095153.1303105-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Refactor xhci_dbc_init(), splitting it into logical parts closer to the Linux device model. - Create the fake dbc device, depends on xhci strucure - Allocate a dbc structure, xhci agnostic - Call xhci_dbc_tty_probe(), similar to actual probe. Adjustments to xhci_dbc_exit and xhci_dbc_remove are also needed as a result to the xhci_dbc_init() changes Mostly non-functional changes, except for creating the dbc sysfs entry earlier, together with the dbc structure. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 124 ++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index ccb0156fcebe..6a437862b498 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -924,49 +924,6 @@ static void xhci_do_dbc_exit(struct xhci_hcd *xhci) spin_unlock_irqrestore(&xhci->lock, flags); } -static int xhci_do_dbc_init(struct xhci_hcd *xhci) -{ - u32 reg; - struct xhci_dbc *dbc; - unsigned long flags; - void __iomem *base; - int dbc_cap_offs; - - base = &xhci->cap_regs->hc_capbase; - dbc_cap_offs = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); - if (!dbc_cap_offs) - return -ENODEV; - - dbc = kzalloc(sizeof(*dbc), GFP_KERNEL); - if (!dbc) - return -ENOMEM; - - dbc->regs = base + dbc_cap_offs; - - /* We will avoid using DbC in xhci driver if it's in use. */ - reg = readl(&dbc->regs->control); - if (reg & DBC_CTRL_DBC_ENABLE) { - kfree(dbc); - return -EBUSY; - } - - spin_lock_irqsave(&xhci->lock, flags); - if (xhci->dbc) { - spin_unlock_irqrestore(&xhci->lock, flags); - kfree(dbc); - return -EBUSY; - } - xhci->dbc = dbc; - spin_unlock_irqrestore(&xhci->lock, flags); - - dbc->xhci = xhci; - dbc->dev = xhci_to_hcd(xhci)->self.sysdev; - INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); - spin_lock_init(&dbc->lock); - - return 0; -} - static ssize_t dbc_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1026,44 +983,95 @@ static ssize_t dbc_store(struct device *dev, static DEVICE_ATTR_RW(dbc); -int xhci_dbc_init(struct xhci_hcd *xhci) +struct xhci_dbc * +xhci_alloc_dbc(struct device *dev, void __iomem *base) { + struct xhci_dbc *dbc; int ret; - struct device *dev = xhci_to_hcd(xhci)->self.controller; - ret = xhci_do_dbc_init(xhci); + dbc = kzalloc(sizeof(*dbc), GFP_KERNEL); + if (!dbc) + return NULL; + + dbc->regs = base; + dbc->dev = dev; + + if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) + return NULL; + + INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); + spin_lock_init(&dbc->lock); + + ret = device_create_file(dev, &dev_attr_dbc); if (ret) - goto init_err3; + goto err; + + return dbc; +err: + kfree(dbc); + return NULL; +} + +/* undo what xhci_alloc_dbc() did */ +void xhci_dbc_remove(struct xhci_dbc *dbc) +{ + if (!dbc) + return; + /* stop hw, stop wq and call dbc->ops->stop() */ + xhci_dbc_stop(dbc); + + /* remove sysfs files */ + device_remove_file(dbc->dev, &dev_attr_dbc); + + kfree(dbc); +} + +int xhci_dbc_init(struct xhci_hcd *xhci) +{ + struct device *dev; + void __iomem *base; + int ret; + int dbc_cap_offs; + + /* create all parameters needed resembling a dbc device */ + dev = xhci_to_hcd(xhci)->self.controller; + base = &xhci->cap_regs->hc_capbase; + + dbc_cap_offs = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); + if (!dbc_cap_offs) + return -ENODEV; + + /* already allocated and in use */ + if (xhci->dbc) + return -EBUSY; + + xhci->dbc = xhci_alloc_dbc(dev, base); + if (!xhci->dbc) + return -ENOMEM; ret = xhci_dbc_tty_probe(xhci); if (ret) goto init_err2; - ret = device_create_file(dev, &dev_attr_dbc); - if (ret) - goto init_err1; - return 0; -init_err1: - xhci_dbc_tty_remove(xhci->dbc); init_err2: xhci_do_dbc_exit(xhci); -init_err3: return ret; } void xhci_dbc_exit(struct xhci_hcd *xhci) { - struct device *dev = xhci_to_hcd(xhci)->self.controller; + unsigned long flags; if (!xhci->dbc) return; - device_remove_file(dev, &dev_attr_dbc); xhci_dbc_tty_remove(xhci->dbc); - xhci_dbc_stop(xhci->dbc); - xhci_do_dbc_exit(xhci); + xhci_dbc_remove(xhci->dbc); + spin_lock_irqsave(&xhci->lock, flags); + xhci->dbc = NULL; + spin_unlock_irqrestore(&xhci->lock, flags); } #ifdef CONFIG_PM From patchwork Wed Feb 16 09:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 543271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F5CAC433EF for ; Wed, 16 Feb 2022 09:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbiBPJvC (ORCPT ); Wed, 16 Feb 2022 04:51:02 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:47228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232570AbiBPJvA (ORCPT ); Wed, 16 Feb 2022 04:51:00 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01669633E for ; Wed, 16 Feb 2022 01:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005025; x=1676541025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gNEJB2Uc7tBrG9pOwxF9bnal5WRJiIURinEqgb4vCVs=; b=jP0Go2IBVGpEnfRFT2qgfJSKe7iX3WL5zO+JSUSTVSM5eTTNmA/o2oIM M7i9jldNDLTYFJ85oEi9jPHRaR7W/1yrLIVrgSdaGr9LSbCMnDzUYbLm4 Cue3vRBBbwA1WeG/0xZbC3EgVWHEk8JnFdsgT4FFJ+jxGO50Q2WNCV9Ov MqYro+RTIDx8T6IEhBDEV213FYoMBf/6n/T54cMvoEsQ5UamY1DZpFXK7 hlx3iHBNu9Gfexmh/sryPStZw1uIVcRQ/SYYIu6uBDG+pag2RN+b0yWfc LY8E89XENOAXWdtgoyUhG+dO47JVmFOlRCvCcLBZmVCmOsF7VyApQVWDP Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396951" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396951" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410312" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:22 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 2/9] xhci: dbc: create and remove dbc structure in dbgtty driver. Date: Wed, 16 Feb 2022 11:51:46 +0200 Message-Id: <20220216095153.1303105-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Turn the dbgtty closer to a device driver by allocating the dbc structure in its own xhci_dbc_tty_probe() function, and freeing it in xhci_dbc_tty_remove() Remove xhci_do_dbc_exit() as its no longer needed. allocate and create the dbc strcuture in xhci_dbc_tty_probe() Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 26 +++----------------------- drivers/usb/host/xhci-dbgcap.h | 5 ++++- drivers/usb/host/xhci-dbgtty.c | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 6a437862b498..f4da5708a40f 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -914,16 +914,6 @@ static void xhci_dbc_handle_events(struct work_struct *work) mod_delayed_work(system_wq, &dbc->event_work, 1); } -static void xhci_do_dbc_exit(struct xhci_hcd *xhci) -{ - unsigned long flags; - - spin_lock_irqsave(&xhci->lock, flags); - kfree(xhci->dbc); - xhci->dbc = NULL; - spin_unlock_irqrestore(&xhci->lock, flags); -} - static ssize_t dbc_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -984,7 +974,7 @@ static ssize_t dbc_store(struct device *dev, static DEVICE_ATTR_RW(dbc); struct xhci_dbc * -xhci_alloc_dbc(struct device *dev, void __iomem *base) +xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *driver) { struct xhci_dbc *dbc; int ret; @@ -995,6 +985,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base) dbc->regs = base; dbc->dev = dev; + dbc->driver = driver; if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) return NULL; @@ -1045,18 +1036,8 @@ int xhci_dbc_init(struct xhci_hcd *xhci) if (xhci->dbc) return -EBUSY; - xhci->dbc = xhci_alloc_dbc(dev, base); - if (!xhci->dbc) - return -ENOMEM; - - ret = xhci_dbc_tty_probe(xhci); - if (ret) - goto init_err2; - - return 0; + ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci); -init_err2: - xhci_do_dbc_exit(xhci); return ret; } @@ -1068,7 +1049,6 @@ void xhci_dbc_exit(struct xhci_hcd *xhci) return; xhci_dbc_tty_remove(xhci->dbc); - xhci_dbc_remove(xhci->dbc); spin_lock_irqsave(&xhci->lock, flags); xhci->dbc = NULL; spin_unlock_irqrestore(&xhci->lock, flags); diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index c70b78d504eb..5d8c7815491c 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -196,8 +196,11 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc) #ifdef CONFIG_USB_XHCI_DBGCAP int xhci_dbc_init(struct xhci_hcd *xhci); void xhci_dbc_exit(struct xhci_hcd *xhci); -int xhci_dbc_tty_probe(struct xhci_hcd *xhci); +int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci); void xhci_dbc_tty_remove(struct xhci_dbc *dbc); +struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, + const struct dbc_driver *driver); +void xhci_dbc_remove(struct xhci_dbc *dbc); struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc, unsigned int direction, gfp_t flags); diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c index eb46e642e87a..18bcc96853ae 100644 --- a/drivers/usb/host/xhci-dbgtty.c +++ b/drivers/usb/host/xhci-dbgtty.c @@ -468,9 +468,9 @@ static const struct dbc_driver dbc_driver = { .disconnect = xhci_dbc_tty_unregister_device, }; -int xhci_dbc_tty_probe(struct xhci_hcd *xhci) +int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd *xhci) { - struct xhci_dbc *dbc = xhci->dbc; + struct xhci_dbc *dbc; struct dbc_port *port; int status; @@ -485,13 +485,22 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci) goto out; } - dbc->driver = &dbc_driver; - dbc->priv = port; + dbc_tty_driver->driver_state = port; + + dbc = xhci_alloc_dbc(dev, base, &dbc_driver); + if (!dbc) { + status = -ENOMEM; + goto out2; + } + dbc->priv = port; - dbc_tty_driver->driver_state = port; + /* get rid of xhci once this is a real driver binding to a device */ + xhci->dbc = dbc; return 0; +out2: + kfree(port); out: /* dbc_tty_exit will be called by module_exit() in the future */ dbc_tty_exit(); @@ -506,8 +515,7 @@ void xhci_dbc_tty_remove(struct xhci_dbc *dbc) { struct dbc_port *port = dbc_to_port(dbc); - dbc->driver = NULL; - dbc->priv = NULL; + xhci_dbc_remove(dbc); kfree(port); /* dbc_tty_exit will be called by module_exit() in the future */ From patchwork Wed Feb 16 09:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 544066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11C68C433F5 for ; Wed, 16 Feb 2022 09:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232550AbiBPJvK (ORCPT ); Wed, 16 Feb 2022 04:51:10 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:47720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232430AbiBPJvJ (ORCPT ); Wed, 16 Feb 2022 04:51:09 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A2A82A0D4C for ; Wed, 16 Feb 2022 01:50:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005044; x=1676541044; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZuvDnbFqESmsABnpoIdbu94q6Dz8Ge7QduTLnsIR4ys=; b=WW7FKxJNgaomJDRex9YCsmchZWK1f8qN3UI2UPoZ4OGv7VKh5hYKvQMW wp0i//b9rmNmXFiehxs3R9ySItBThAp3Ny/P+qudl42oO789ytmuSx/Hi JkAU3QxQJsYl/wkGtbeRJn+LOIh/vyl7kmnvWrYERqruvsh3uhvBc39Mq bacFsReHoILW0IKA7DIA13mSQ/aDnqegWjfX1+k8Bf4mvXQ2B8T9Ht7Xu /PykdKwQyjnWCjKWMTMQHtjbrl26tZwPJtjvsBNhESF+sUm0YbnEOkp3j HivyHuWXyYLUDA/R/+dEc2HmYfiwPR3PxUepHw/4VjiJnqGJp3bb2ui8F g==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396955" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396955" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410319" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:24 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 3/9] xhci: dbc: Rename xhci_dbc_init and xhci_dbc_exit Date: Wed, 16 Feb 2022 11:51:47 +0200 Message-Id: <20220216095153.1303105-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org These names give the impression the functions are related to module init calls, but are in fact creating and removing the dbc fake device Rename them to xhci_create_dbc_dev() and xhci_remove_dbc_dev(). We will need the _init and _exit names for actual dbc module init and exit calls. No functional changes Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 5 +++-- drivers/usb/host/xhci-dbgcap.h | 8 ++++---- drivers/usb/host/xhci.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index f4da5708a40f..46c8f3c187f7 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -1017,7 +1017,8 @@ void xhci_dbc_remove(struct xhci_dbc *dbc) kfree(dbc); } -int xhci_dbc_init(struct xhci_hcd *xhci) + +int xhci_create_dbc_dev(struct xhci_hcd *xhci) { struct device *dev; void __iomem *base; @@ -1041,7 +1042,7 @@ int xhci_dbc_init(struct xhci_hcd *xhci) return ret; } -void xhci_dbc_exit(struct xhci_hcd *xhci) +void xhci_remove_dbc_dev(struct xhci_hcd *xhci) { unsigned long flags; diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index 5d8c7815491c..8b5b363a0719 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -194,8 +194,8 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc) } #ifdef CONFIG_USB_XHCI_DBGCAP -int xhci_dbc_init(struct xhci_hcd *xhci); -void xhci_dbc_exit(struct xhci_hcd *xhci); +int xhci_create_dbc_dev(struct xhci_hcd *xhci); +void xhci_remove_dbc_dev(struct xhci_hcd *xhci); int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci); void xhci_dbc_tty_remove(struct xhci_dbc *dbc); struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, @@ -211,12 +211,12 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci); int xhci_dbc_resume(struct xhci_hcd *xhci); #endif /* CONFIG_PM */ #else -static inline int xhci_dbc_init(struct xhci_hcd *xhci) +static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci) { return 0; } -static inline void xhci_dbc_exit(struct xhci_hcd *xhci) +static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci) { } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index dc357cabb265..ab1b5ff3fc99 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -695,7 +695,7 @@ int xhci_run(struct usb_hcd *hcd) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_run for USB2 roothub"); - xhci_dbc_init(xhci); + xhci_create_dbc_dev(xhci); xhci_debugfs_init(xhci); @@ -725,7 +725,7 @@ static void xhci_stop(struct usb_hcd *hcd) return; } - xhci_dbc_exit(xhci); + xhci_remove_dbc_dev(xhci); spin_lock_irq(&xhci->lock); xhci->xhc_state |= XHCI_STATE_HALTED; From patchwork Wed Feb 16 09:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 543270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8DFEC433EF for ; Wed, 16 Feb 2022 09:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232529AbiBPJvM (ORCPT ); Wed, 16 Feb 2022 04:51:12 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:47790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbiBPJvK (ORCPT ); Wed, 16 Feb 2022 04:51:10 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B111B6336 for ; Wed, 16 Feb 2022 01:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005047; x=1676541047; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zbP6eA+NYLFuMBld7X9Jlia/kBkrwbKyl9COXN/HulM=; b=Ns7F4NrlvgSNHsvAClYS1/vmKgwlFc6AzNmR8qoTn5IrP8Fwyvcjeo+a ly3nKxFekcf06aSoejp/sVQro3xUVLd+luj0Ol536JUB89s4kQuYzX6kJ btSDvVDUT0oHf3P/L9vLUo4YCkXhrk71u/bAzNrZIIWgywn6PQZe18HoO RjQ+WLoveaa4Jy2tmvO+YOqC2mQPl3600vF521N8r/rxhCsc3/z3o346E UaYweMAuTl28PZ5fsrX4bG8TXDaNzJB5CYetFGnDm8YEboyRnihz0ziXG glekd/P66JpKORUAC2sKfKls8bF4ZfxxRU5IQ76fgiSfIVuOi/JCL+G4F w==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396961" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396961" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410332" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:25 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 4/9] xhci: dbc: Don't call dbc_tty_init() on every dbc tty probe Date: Wed, 16 Feb 2022 11:51:48 +0200 Message-Id: <20220216095153.1303105-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The current workaround to call the dbc_tty_init() in probe is not working in case we have several xhci devices with dbc enabled. dbc_tty_init() should be called only once by a module init call when module is loaded. until dbgtty is its own module call dbc_tty_init() from xhci module init call. Same is true for unloading and dbc_tty_exit() Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 10 ++++++++++ drivers/usb/host/xhci-dbgcap.h | 12 +++++++++++- drivers/usb/host/xhci-dbgtty.c | 26 +++++++------------------- drivers/usb/host/xhci.c | 2 ++ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 46c8f3c187f7..e61155fa6379 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -1087,3 +1087,13 @@ int xhci_dbc_resume(struct xhci_hcd *xhci) return ret; } #endif /* CONFIG_PM */ + +int xhci_dbc_init(void) +{ + return dbc_tty_init(); +} + +void xhci_dbc_exit(void) +{ + dbc_tty_exit(); +} diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index 8b5b363a0719..5f3304a06591 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -196,6 +196,10 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc) #ifdef CONFIG_USB_XHCI_DBGCAP int xhci_create_dbc_dev(struct xhci_hcd *xhci); void xhci_remove_dbc_dev(struct xhci_hcd *xhci); +int xhci_dbc_init(void); +void xhci_dbc_exit(void); +int dbc_tty_init(void); +void dbc_tty_exit(void); int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci); void xhci_dbc_tty_remove(struct xhci_dbc *dbc); struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, @@ -219,7 +223,13 @@ static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci) static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci) { } - +static inline int xhci_dbc_init(void) +{ + return 0; +} +static inline void xhci_dbc_exit(void) +{ +} static inline int xhci_dbc_suspend(struct xhci_hcd *xhci) { return 0; diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c index 18bcc96853ae..059b58f48e3a 100644 --- a/drivers/usb/host/xhci-dbgtty.c +++ b/drivers/usb/host/xhci-dbgtty.c @@ -14,9 +14,6 @@ #include "xhci.h" #include "xhci-dbgcap.h" -static int dbc_tty_init(void); -static void dbc_tty_exit(void); - static struct tty_driver *dbc_tty_driver; static inline struct dbc_port *dbc_to_port(struct xhci_dbc *dbc) @@ -474,16 +471,12 @@ int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd * struct dbc_port *port; int status; - /* dbc_tty_init will be called by module init() in the future */ - status = dbc_tty_init(); - if (status) - return status; + if (!dbc_tty_driver) + return -ENODEV; port = kzalloc(sizeof(*port), GFP_KERNEL); - if (!port) { - status = -ENOMEM; - goto out; - } + if (!port) + return -ENOMEM; dbc_tty_driver->driver_state = port; @@ -501,9 +494,7 @@ int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd * return 0; out2: kfree(port); -out: - /* dbc_tty_exit will be called by module_exit() in the future */ - dbc_tty_exit(); + return status; } @@ -517,12 +508,9 @@ void xhci_dbc_tty_remove(struct xhci_dbc *dbc) xhci_dbc_remove(dbc); kfree(port); - - /* dbc_tty_exit will be called by module_exit() in the future */ - dbc_tty_exit(); } -static int dbc_tty_init(void) +int dbc_tty_init(void) { int ret; @@ -552,7 +540,7 @@ static int dbc_tty_init(void) return ret; } -static void dbc_tty_exit(void) +void dbc_tty_exit(void) { if (dbc_tty_driver) { tty_unregister_driver(dbc_tty_driver); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ab1b5ff3fc99..17a561abfab7 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5495,6 +5495,7 @@ static int __init xhci_hcd_init(void) return -ENODEV; xhci_debugfs_create_root(); + xhci_dbc_init(); return 0; } @@ -5506,6 +5507,7 @@ static int __init xhci_hcd_init(void) static void __exit xhci_hcd_fini(void) { xhci_debugfs_remove_root(); + xhci_dbc_exit(); } module_init(xhci_hcd_init); From patchwork Wed Feb 16 09:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 544065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F205C433FE for ; Wed, 16 Feb 2022 09:51:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232505AbiBPJvN (ORCPT ); Wed, 16 Feb 2022 04:51:13 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:47852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232458AbiBPJvK (ORCPT ); Wed, 16 Feb 2022 04:51:10 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B08B2905AA for ; Wed, 16 Feb 2022 01:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005049; x=1676541049; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YhNfXq8U5nUyIuHypm/2SObuAr8yw//O1KiWnYo0XJY=; b=XzBOcOpVZVoodXghUlqmTNxL5IL3FvKTzCYhnPWADTxSJ1fAEWu4Patt nRsweRxZlBNBOMbhB6ggWTwq4aHzSNlZo42bVZDCE2MnUtt6vyk096Rwo lEGkOozTJ/XkjeYK5sVBbCX4xKdhgfM1N2V5ZTTrKHdLqtDKxsY7vgWeU QjQrxUI74HsBgXey4ZcPKI15ATzstgz/mWUc+iVWZcoAllmKIqP5IXxet aOH6R9+I7FVmUAJXoS2+2XYrIjBCw+bz73jEx2hSO5qLqH2r8o93K9hT9 ugWM2TYzLkZldDZ9fQoc6XlDjWIw4++OHvg8OqE/BFi4jMjmahcFMmWWY A==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396964" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396964" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410345" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:27 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 5/9] xhci: dbgtty: use IDR to support several dbc instances. Date: Wed, 16 Feb 2022 11:51:49 +0200 Message-Id: <20220216095153.1303105-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org To support systems with several xhci controllers with active dbc on each xhci we need to use IDR to identify and give an index to each port. Avoid using global struct tty_driver.driver_state for storing dbc port pointer as it won't work with several dbc ports Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.h | 1 + drivers/usb/host/xhci-dbgtty.c | 46 ++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index 5f3304a06591..ca04192fdab1 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -100,6 +100,7 @@ struct dbc_ep { struct dbc_port { struct tty_port port; spinlock_t port_lock; /* port access */ + int minor; struct list_head read_pool; struct list_head read_queue; diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c index 059b58f48e3a..d3acc0829ee5 100644 --- a/drivers/usb/host/xhci-dbgtty.c +++ b/drivers/usb/host/xhci-dbgtty.c @@ -10,11 +10,14 @@ #include #include #include +#include #include "xhci.h" #include "xhci-dbgcap.h" static struct tty_driver *dbc_tty_driver; +static struct idr dbc_tty_minors; +static DEFINE_MUTEX(dbc_tty_minors_lock); static inline struct dbc_port *dbc_to_port(struct xhci_dbc *dbc) { @@ -177,7 +180,14 @@ xhci_dbc_free_requests(struct list_head *head) static int dbc_tty_install(struct tty_driver *driver, struct tty_struct *tty) { - struct dbc_port *port = driver->driver_state; + struct dbc_port *port; + + mutex_lock(&dbc_tty_minors_lock); + port = idr_find(&dbc_tty_minors, tty->index); + mutex_unlock(&dbc_tty_minors_lock); + + if (!port) + return -ENXIO; tty->driver_data = port; @@ -406,6 +416,15 @@ static int xhci_dbc_tty_register_device(struct xhci_dbc *dbc) xhci_dbc_tty_init_port(dbc, port); + mutex_lock(&dbc_tty_minors_lock); + port->minor = idr_alloc(&dbc_tty_minors, port, 0, 64, GFP_KERNEL); + mutex_unlock(&dbc_tty_minors_lock); + + if (port->minor < 0) { + ret = port->minor; + goto err_idr; + } + ret = kfifo_alloc(&port->write_fifo, DBC_WRITE_BUF_SIZE, GFP_KERNEL); if (ret) goto err_exit_port; @@ -421,7 +440,7 @@ static int xhci_dbc_tty_register_device(struct xhci_dbc *dbc) goto err_free_requests; tty_dev = tty_port_register_device(&port->port, - dbc_tty_driver, 0, NULL); + dbc_tty_driver, port->minor, NULL); if (IS_ERR(tty_dev)) { ret = PTR_ERR(tty_dev); goto err_free_requests; @@ -437,6 +456,8 @@ static int xhci_dbc_tty_register_device(struct xhci_dbc *dbc) err_free_fifo: kfifo_free(&port->write_fifo); err_exit_port: + idr_remove(&dbc_tty_minors, port->minor); +err_idr: xhci_dbc_tty_exit_port(port); dev_err(dbc->dev, "can't register tty port, err %d\n", ret); @@ -450,10 +471,14 @@ static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc) if (!port->registered) return; - tty_unregister_device(dbc_tty_driver, 0); + tty_unregister_device(dbc_tty_driver, port->minor); xhci_dbc_tty_exit_port(port); port->registered = false; + mutex_lock(&dbc_tty_minors_lock); + idr_remove(&dbc_tty_minors, port->minor); + mutex_unlock(&dbc_tty_minors_lock); + kfifo_free(&port->write_fifo); xhci_dbc_free_requests(&port->read_pool); xhci_dbc_free_requests(&port->read_queue); @@ -478,9 +503,8 @@ int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci_hcd * if (!port) return -ENOMEM; - dbc_tty_driver->driver_state = port; - dbc = xhci_alloc_dbc(dev, base, &dbc_driver); + if (!dbc) { status = -ENOMEM; goto out2; @@ -514,10 +538,14 @@ int dbc_tty_init(void) { int ret; - dbc_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW | + idr_init(&dbc_tty_minors); + + dbc_tty_driver = tty_alloc_driver(64, TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); - if (IS_ERR(dbc_tty_driver)) + if (IS_ERR(dbc_tty_driver)) { + idr_destroy(&dbc_tty_minors); return PTR_ERR(dbc_tty_driver); + } dbc_tty_driver->driver_name = "dbc_serial"; dbc_tty_driver->name = "ttyDBC"; @@ -536,7 +564,9 @@ int dbc_tty_init(void) if (ret) { pr_err("Can't register dbc tty driver\n"); tty_driver_kref_put(dbc_tty_driver); + idr_destroy(&dbc_tty_minors); } + return ret; } @@ -547,4 +577,6 @@ void dbc_tty_exit(void) tty_driver_kref_put(dbc_tty_driver); dbc_tty_driver = NULL; } + + idr_destroy(&dbc_tty_minors); } From patchwork Wed Feb 16 09:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 543269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37EA0C433EF for ; Wed, 16 Feb 2022 09:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbiBPJvU (ORCPT ); Wed, 16 Feb 2022 04:51:20 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:48352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232458AbiBPJvT (ORCPT ); Wed, 16 Feb 2022 04:51:19 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F3122B3ADE for ; Wed, 16 Feb 2022 01:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005058; x=1676541058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rvCCsufddA+kAOKlClpMx59Cz9OFvn49q/s6jaaq37A=; b=dkQeb/a5kZHudmujGcd0btAbWHvhQ/T1Z1Xunr3ebrU9eL3HE9CX4O4E 6xOvcSZLQ0ntM9Da2Gje1esik4WVxvc0Jd3GcvoBj8Tjr2O1Is4M2Q2d2 nDwG00uuGpAToBI8WrXy9AwfgYYuaOl1Nv7zBvokLqsFV0i5f6+L54K0v jeGi3Kw9KhNe4vxo2o+w6/5b1SMTyW8Aw0KluU5bE6zWSXA7+9w2NAYRi 07xqsbAw+5b94roHSDQ7AWL1noKYupS2m2zP4r9V1bvmBSot0Zk4yX8yf m/vocni5eXFdQMBiCds1WM40Nn3zP0syycKZIv0nDUGbUsAJSZGhFTUaL g==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396965" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396965" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410353" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:29 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH v2 6/9] xhci: Allocate separate command structures for each LPM command Date: Wed, 16 Feb 2022 11:51:50 +0200 Message-Id: <20220216095153.1303105-7-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Every lpm commmand, both for USB 2 and USB 3 devies used the same xhci->lpm_command structure to change max exit latency. xhci->lpm_command is only protected by a hcd->bandwidth mutex, which is not enoungh as USB 2 and USB 3 devices are behind separate HCDs. Simplify code and avoid unnecessary locking risks by allocating separate command structures for each lpm command, just like with all other commands. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 7 ------- drivers/usb/host/xhci.c | 21 ++++++++------------- drivers/usb/host/xhci.h | 2 -- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 0e312066c5c6..7a2dce730e9a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1846,9 +1846,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) xhci->event_ring = NULL; xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed event ring"); - if (xhci->lpm_command) - xhci_free_command(xhci, xhci->lpm_command); - xhci->lpm_command = NULL; if (xhci->cmd_ring) xhci_ring_free(xhci, xhci->cmd_ring); xhci->cmd_ring = NULL; @@ -2488,10 +2485,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) "// Setting command ring address to 0x%016llx", val_64); xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); - xhci->lpm_command = xhci_alloc_command_with_ctx(xhci, true, flags); - if (!xhci->lpm_command) - goto fail; - /* Reserve one command ring TRB for disabling LPM. * Since the USB core grabs the shared usb_bus bandwidth mutex before * disabling LPM, we only need to reserve one TRB for all devices. diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 17a561abfab7..2a58677d9b7a 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4344,6 +4344,10 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, unsigned long flags; int ret; + command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); + if (!command) + return -ENOMEM; + spin_lock_irqsave(&xhci->lock, flags); virt_dev = xhci->devs[udev->slot_id]; @@ -4360,10 +4364,10 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, } /* Attempt to issue an Evaluate Context command to change the MEL. */ - command = xhci->lpm_command; ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); if (!ctrl_ctx) { spin_unlock_irqrestore(&xhci->lock, flags); + xhci_free_command(xhci, command); xhci_warn(xhci, "%s: Could not get input context, bad type.\n", __func__); return -ENOMEM; @@ -4390,6 +4394,9 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, virt_dev->current_mel = max_exit_latency; spin_unlock_irqrestore(&xhci->lock, flags); } + + xhci_free_command(xhci, command); + return ret; } @@ -4510,18 +4517,8 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, exit_latency = xhci_besl_encoding[hird]; spin_unlock_irqrestore(&xhci->lock, flags); - /* USB 3.0 code dedicate one xhci->lpm_command->in_ctx - * input context for link powermanagement evaluate - * context commands. It is protected by hcd->bandwidth - * mutex and is shared by all devices. We need to set - * the max ext latency in USB 2 BESL LPM as well, so - * use the same mutex and xhci_change_max_exit_latency() - */ - mutex_lock(hcd->bandwidth_mutex); ret = xhci_change_max_exit_latency(xhci, udev, exit_latency); - mutex_unlock(hcd->bandwidth_mutex); - if (ret < 0) return ret; spin_lock_irqsave(&xhci->lock, flags); @@ -4549,9 +4546,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, readl(pm_addr); if (udev->usb2_hw_lpm_besl_capable) { spin_unlock_irqrestore(&xhci->lock, flags); - mutex_lock(hcd->bandwidth_mutex); xhci_change_max_exit_latency(xhci, udev, 0); - mutex_unlock(hcd->bandwidth_mutex); readl_poll_timeout(ports[port_num]->addr, pm_val, (pm_val & PORT_PLS_MASK) == XDEV_U0, 100, 10000); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 5a75fe563123..8a0026ee9524 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1812,8 +1812,6 @@ struct xhci_hcd { /* slot enabling and address device helpers */ /* these are not thread safe so use mutex */ struct mutex mutex; - /* For USB 3.0 LPM enable/disable. */ - struct xhci_command *lpm_command; /* Internal mirror of the HW's dcbaa */ struct xhci_virt_device *devs[MAX_HC_SLOTS]; /* For keeping track of bandwidth domains per roothub. */ From patchwork Wed Feb 16 09:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 543268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4708DC433FE for ; Wed, 16 Feb 2022 09:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbiBPJvU (ORCPT ); Wed, 16 Feb 2022 04:51:20 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:48378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232501AbiBPJvT (ORCPT ); Wed, 16 Feb 2022 04:51:19 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D862B4058 for ; Wed, 16 Feb 2022 01:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005059; x=1676541059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V+9dCm9T0wjt9iMjw7yZlCUH+2thn4xfYDYfF7VO+oY=; b=KU5uKaA+kVJzgd7MqJkhoIxi48Cv9XYH387aUAde+lpJN7lOoj94oG5x mwG6w4QyPwlK326n51DbvSmJETt3M5PeztYJCo01+zAoX5HC+FoFzPWNp Fys9568PSwrIvR/puCk0OODazcId6xsvK78aRO3XBYssWeudoiep9IfBq NmfVfPi3Xc0yvhH7ARcpl6uA1O7Ptg75TKBMCCWE1V4vGRLohC3moCS7h rCwwsgYO+irfEg4Ru2zHH68lWI+ofhE6X+ow0Zro8TRwSwnCLsBI6PV3j vuwJbxf/en0hzwCGWuNkPU8rEX+EKjXhAdRkwYSciZHkcePkNKdIZ2t/r A==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396968" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396968" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410361" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:30 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman , Alan Stern Subject: [PATCH v2 7/9] usb: remove Link Powermanagement (LPM) disable before port reset. Date: Wed, 16 Feb 2022 11:51:51 +0200 Message-Id: <20220216095153.1303105-8-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Trying to disable Link Powermanagement (LPM) before port reset is unnecessary and can cause additional delay if host can't communicate with the device, which is often the reason why device is reset in the first place. usb_disable_lpm() will - zero usb U1/U2 timeouts for the hub downstream port - send ENABLE U1/U2 clear feature requests to the connected device. - increase internal reference count for udev->lpm_disable_count There is no need to zero U1/U2 hub port timeouts, or clearing the U1/U2 enable for the connected device before reset. These are set to default by the reset. USB 3.1 section 10.2.2 "HUB Downstream port U1/U2 timers" states that: "the U1 and U2 timeout values for a downstream port reset to the default values when the port receives a SetPortFeature request for a port reset" Set the udev->lpm_disable_count to "1" after port reset, which is the default lpm_disable_count value when allocating udev, representing disabled LPM. Cc: Alan Stern Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 47a1c8bddf86..b8853219833a 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5005,6 +5005,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, retval = usb_get_bos_descriptor(udev); if (!retval) { udev->lpm_capable = usb_device_supports_lpm(udev); + udev->lpm_disable_count = 1; usb_set_lpm_parameters(udev); } } @@ -5928,16 +5929,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) */ usb_disable_usb2_hardware_lpm(udev); - /* Disable LPM while we reset the device and reinstall the alt settings. - * Device-initiated LPM, and system exit latency settings are cleared - * when the device is reset, so we have to set them up again. - */ - ret = usb_unlocked_disable_lpm(udev); - if (ret) { - dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__); - goto re_enumerate_no_bos; - } - bos = udev->bos; udev->bos = NULL; @@ -6042,8 +6033,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) re_enumerate: usb_release_bos_descriptor(udev); udev->bos = bos; -re_enumerate_no_bos: - /* LPM state doesn't matter when we're about to destroy the device. */ hub_port_logical_disconnect(parent_hub, port1); return -ENODEV; } From patchwork Wed Feb 16 09:51:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 544064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBC91C4332F for ; Wed, 16 Feb 2022 09:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbiBPJvV (ORCPT ); Wed, 16 Feb 2022 04:51:21 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:48466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232520AbiBPJvU (ORCPT ); Wed, 16 Feb 2022 04:51:20 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81652B4074 for ; Wed, 16 Feb 2022 01:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005059; x=1676541059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L9IoCPdVPu8QzPwB9ZH3k81wJN+NTTltzRqmgvJF9Y4=; b=n0wS/GRzAev7/3xqU6z3oWCzwzaFzjChuNShXDkH1XdZZ0Qf7Wm1iDIn kkwyWp1KxoezNeR3O13HB1+zthi+hnnE6TO+/I05m5iy7GGDgqADI0bAG dbqvDnZRumER40dGMYupQA1KWT3BBYqs0uZQ4oWe317QQ4qCSh/JpsKES aJCP9CnoZldSDGX4YzGX55GPnB0vyai/9qZ1McJQjXrKafzOhcE7Gsvr2 9pzTRSWEjQWEgCWAvDqqBzxQsCG2pbNnNv4tFiPWg+TJdyyyIpw1GZgfd /RXuZ+G83Pw5x8IE6zP3jnsn63dwztX95ZILDdAR0GQo8rR7eZybWebhf w==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396972" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396972" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410379" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:32 -0800 From: Mathias Nyman To: Cc: , Sergey Shtylyov , Mathias Nyman Subject: [PATCH v2 8/9] usb: host: xhci: drop redundant checks Date: Wed, 16 Feb 2022 11:51:52 +0200 Message-Id: <20220216095153.1303105-9-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Sergey Shtylyov In xhci_endpoint_{disable|reset}() the expression '&vdev->eps[ep_index]' just cannot be NULL, so the checks have no sense at all... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Sergey Shtylyov Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 2a58677d9b7a..33bae434aa94 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3150,8 +3150,6 @@ static void xhci_endpoint_disable(struct usb_hcd *hcd, ep_index = xhci_get_endpoint_index(&host_ep->desc); ep = &vdev->eps[ep_index]; - if (!ep) - goto done; /* wait for hub_tt_work to finish clearing hub TT */ if (ep->ep_state & EP_CLEARING_TT) { @@ -3209,8 +3207,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, return; ep_index = xhci_get_endpoint_index(&host_ep->desc); ep = &vdev->eps[ep_index]; - if (!ep) - return; /* Bail out if toggle is already being cleared by a endpoint reset */ spin_lock_irqsave(&xhci->lock, flags); From patchwork Wed Feb 16 09:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 544063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E027C433EF for ; Wed, 16 Feb 2022 09:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232520AbiBPJvf (ORCPT ); Wed, 16 Feb 2022 04:51:35 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:49000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232478AbiBPJvb (ORCPT ); Wed, 16 Feb 2022 04:51:31 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA19A29C103 for ; Wed, 16 Feb 2022 01:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645005068; x=1676541068; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=99YnMQbApcc0QAzHaMFoAdEXgK/fCyyygtJXRBUm/tc=; b=WQXsblzsf6t+Hq6tYh8HLLlZVruf6bilJBq+OXERPCd2LghY+S+mMUkj Dqn/ut3g4SrnKa3IqBbcC+C90+v/w2d9NV5FzQ6Ed+19ObNP6xwXC3B2j p3Foz/QJpOhD+7DlbFK9uMYQQQJilEYl8qzKBchznl5S/2u7y3oiYH1Ty LbUCmHiHTTMQB1uC3fsi5vuYzxIsvK3uh4b1OsbCRnl2i+ZAulTpTM9bq lM343t5BqYOVhoedQStpmEJ+p8hyZFEr3cI31oB/dhdFMKrhBrOAUZpHl QdMEhwlDHYEm4ZMIGFRWvvhCcIc1QdyadXTv/E8oBRBhvRd38L/4fqz8D g==; X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="249396978" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="249396978" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:50:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="636410414" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2022 01:50:34 -0800 From: Mathias Nyman To: Cc: , kernel test robot , Julia Lawall , Mathias Nyman Subject: [PATCH v2 9/9] usb: xhci: fix minmax.cocci warnings Date: Wed, 16 Feb 2022 11:51:53 +0200 Message-Id: <20220216095153.1303105-10-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> References: <20220216095153.1303105-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: kernel test robot Simplify the code using max(). Generated by: scripts/coccinelle/misc/minmax.cocci Reported-by: kernel test robot Signed-off-by: kernel test robot Signed-off-by: Julia Lawall Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 7a2dce730e9a..f8c2b6c79543 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -433,8 +433,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, (TRBS_PER_SEGMENT - 1); /* Allocate number of segments we needed, or double the ring size */ - num_segs = ring->num_segs > num_segs_needed ? - ring->num_segs : num_segs_needed; + num_segs = max(ring->num_segs, num_segs_needed); ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_segs, ring->cycle_state, ring->type,