From nobody Fri Dec 19 20:57:27 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EE7F1891A8 for ; Thu, 9 Jan 2025 03:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395017; cv=none; b=MVwWIuK9MHwPGryLiGbCc/qj/bTox3NuQpHk352Jde1ycKFFq/xUkT0k8p75PeoUmn+D6wqRo9hF/JYygFufmwmHSV0IztT7jgqNbnzAbZ7cbNu9WRD64ePYRtBVQNLY4tGw1zwk9daXzTXDVY2lTy5dA/jgyDmJ7s4GBqLuQaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395017; c=relaxed/simple; bh=faUlm+0/aqfwj/ZyUJRA6KayiX/ZHmaYLZuAWi+8Tt8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VWZlsz9H9jk0tmF7I1+zaNhixScjUuiqGf50CqrFHTyMnBDmNUcshPHUNvADbLt0+uCjstb30OfDfXmyAg6ZnEv+Ox/i8APgv5vgaroKwIKTXshMMw1o8hyxesEUGX7Eqos8jcEsWxVC+52wF6dtXoSW3BGvgxOJR2nskWrTxIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gao4ejgX; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gao4ejgX" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2166464e236so13771445ad.1 for ; Wed, 08 Jan 2025 19:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736395015; x=1736999815; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yq1k1+crakqu6xGV6adPZX7kzIgk4M719hbmyURwKps=; b=gao4ejgXK8SeUr0S/m8BAosG1o07awuEi5pj9H44I9Z0v1FWtkhp6h6vV0du/I48yH D5lK6T6rU+i7vNipGt7okEONq5Z2OUXst0Y0WXlGSkBEoo9rRR0j+1qBBrmzuXJz9/yA r5/RhfE56PaWkySKC+emJUwOc+tjByzqTkgm6PdJYr7GF2kWexsbWV7Z+Msw2QRaWMqY BU6rBWG4WOCtZAazaSBxPkzQStMXRUfoj+ewteDBGGZmBSdkpNHaTZ1TbnwhvFMXcRwP fnOBV14hrlX3ilYn9KiX32z7l00VU7DiLzZfvjkDmYCsauPwmE9biAnnlYIfPMGL/tL+ GkPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736395015; x=1736999815; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yq1k1+crakqu6xGV6adPZX7kzIgk4M719hbmyURwKps=; b=fNPvoK2NcKdhZqS9KYBQULe3Oap92sA7fO3svhIbigktpwJXGXi9ye6o8xLUulaK8y l1RGwfLdy0wuI3gJPsMTfChPwB8+oCdrijEP4KVmvXzIWcjU3wETzlvs0zQouProw1pb KWISvduWc1ooziAuSFKw53XsPOZttRo/ZNNeEJ5uEaJ+BjBrZX75j1mYIuMEFN3zLeTP 6465uKlIcDcRyNizjeQCx2xiwf/HPYYTpmqFL/zU942RAuoZ/BgjVmU9IJrpd32+3rin rjqa8PYwnLy2oVBQAXEZsij2l9s5djnoSLB6UWCJ51Per3JSWqFh2C4WhPO8NjyiCq0Y vUFw== X-Forwarded-Encrypted: i=1; AJvYcCXqz/drItT0zvprYI2xCnQYyuOH00bmxKu6327KnlYJIIU2uNFI9hEefJLFc1KV7cDtfXb/C1SaPVwRQuA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq+mti2jp9sTLKFzaPKLdUUXSifDDvknuDsI7KOIgDSPjXjmUf tCAv7MtlwG6x4YjL0ATYf2V1BgZhR1KNa/CYkGqM0y07jQl6cCmoJ3XRy1miqNrBE8nyZoB6fHM C1aU1x0im/T7GiA== X-Google-Smtp-Source: AGHT+IG+uiVZJFTFW1Pc7BABtMZ+mTFebYnx6zwKTzfzwanRWkoXb+6jWySyhgbUQv+K78k1W2dmItnKFD09gYo= X-Received: from plblc11.prod.google.com ([2002:a17:902:fa8b:b0:216:248e:8fab]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e843:b0:215:a3fb:b4d6 with SMTP id d9443c01a7336-21a83f3f50dmr83119925ad.8.1736395015667; Wed, 08 Jan 2025 19:56:55 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:08 +0000 In-Reply-To: <20250109035605.1486717-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-5-guanyulin@google.com> Subject: [PATCH v7 4/5] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing sideband driver only registers sidebands without tracking their active usage. To address this, new apis are introduced to: - mark sideband usage: record the sideband usage information in the USB device driver. - query sideband status: provide a means for other drivers to fetch sideband activity information on a USB host controller. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-sideband.c | 82 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 6 +++ 2 files changed, 88 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index ffa6f1b825ff..d4931315dcf4 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -358,6 +358,88 @@ xhci_sideband_interrupter_id(struct xhci_sideband *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_interrupter_id); =20 +/** + * xhci_sideband_get - record a new active sideband instance + * @sb: sideband instance for this usb device + * + * An active sideband indicates that another entity is currently using the= host + * controller. Inform the usb_device associated with this sideband instanc= e via + * usb_offload_get(). This allows the corresponding drivers to dynamically + * adjust power management actions based on current sideband activities. + * + * Returns 0 on success, negative error otherwise. + */ +int xhci_sideband_get(struct xhci_sideband *sb) +{ + struct usb_device *udev; + struct usb_hcd *hcd; + int ret =3D 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + udev =3D sb->vdev->udev; + device_lock(&udev->dev); + ret =3D usb_offload_get(udev); + device_unlock(&udev->dev); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_get); + +/** + * xhci_sideband_put - record a deactivated sideband instance + * @sb: sideband instance for this usb device + * + * The inverse operation of xhci_sideband_get, which informs the associated + * usb_device via usb_offload_put(). This allows the corresponding drivers= to + * dynamically adjust power management actions based on sideband activitie= s. + * + * Returns 0 on success, negative error otherwise. + */ +int xhci_sideband_put(struct xhci_sideband *sb) +{ + struct usb_device *udev; + struct usb_hcd *hcd; + int ret =3D 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + udev =3D sb->vdev->udev; + device_lock(&udev->dev); + ret =3D usb_offload_put(udev); + device_unlock(&udev->dev); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_put); + +/** + * xhci_sideband_check - check the existence of active sidebands + * @hcd: the host controller driver associated with the target host contro= ller + * + * Allow other drivers, such as usb controller driver, to check if there a= re + * any sideband activity on the host controller. This information could be= used + * for power management or other forms of resource management. + * + * Returns true on any active sideband existence, false otherwise. + */ +bool xhci_sideband_check(struct usb_hcd *hcd) +{ + struct usb_device *udev =3D hcd->self.root_hub; + bool active; + + device_lock(&udev->dev); + active =3D usb_offload_check(udev); + device_unlock(&udev->dev); + + return active; +} +EXPORT_SYMBOL_GPL(xhci_sideband_check); + /** * xhci_sideband_register - register a sideband for a usb device * @intf: usb interface associated with the sideband device diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h index 72aa17eb068d..6de1d9c161a1 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -11,6 +11,7 @@ =20 #include #include +#include =20 #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ =20 @@ -82,6 +83,11 @@ xhci_sideband_get_endpoint_buffer(struct xhci_sideband *= sb, struct usb_host_endpoint *host_ep); struct sg_table * xhci_sideband_get_event_buffer(struct xhci_sideband *sb); + +int xhci_sideband_get(struct xhci_sideband *sb); +int xhci_sideband_put(struct xhci_sideband *sb); +bool xhci_sideband_check(struct usb_hcd *hcd); + int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num); --=20 2.47.1.613.gc27f4b7a9f-goog