From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3430E20495E; Wed, 6 Nov 2024 19:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921686; cv=none; b=rdbR7ajAGoHR3WeLsZnpvvfWDN3j/YI0vOP2uLVIkr1aX1xGGossByAYjAOeTizIcGA+sB/OmWJEmLIJTBmQrHY4b3/lE+fnLdAdeCdtrXXY8V405XCZfuYV0wltctIlGoDn951Cspqjv1OOhgOMPtRX8SffAu57Aoo7RvSSIGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921686; c=relaxed/simple; bh=Dr4W0Sii3XJwvNgWatq3gw/93pirXbINY05anCpW1vo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lUlPicjdm6N/lLRd3+VeKnUgGN4rMYmMewuK16gFyNEWDsJ4KVgf4cl73SQfkoe24MnvyHKS3g9pRP11RiLig038pq9LzAhG8HdePdm53drTTB3mLO27f59kuJZHkPZc/enQ/4q9tipUQJwUce4i0E5yNF9xxU+867zr3pdkYBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=abhT3L0K; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="abhT3L0K" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A69iRin015629; Wed, 6 Nov 2024 19:34:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 1SYmYOoeYsuimuhpMF1idXjjpx08Xq8JZdrqOu0v8x4=; b=abhT3L0KUYgJHuTO fkhpJ2yKQTGErcF+gUDNlP4TWo37g8hLDKq7qU6l+Q0H+vBbZdV8nVqhqClTfmYV 3aGtoHQ4bWImz3Ift5tzSwqE7+fEpFM9Q7a55g4XfseVQAKG56OKy0QtkH2G0E7F KY1I2gIvlG9o4z2v+i1cZ7KMvEI1oqIBncQG1smb7NHYYxLCwzfA1zPwk44FNzBy NRkmCeuu3rctGadbawHi12qmGl6KiEM8PoTqLP99L4+I2i/54dZueyLjGbrZXRpg 4GOf7LGe+Mpth+uMd0s7LtC/a10wTryu2Qe5T17te/IbVMhQbQpXsXKr42YUbRHg KN0zLg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42q5n8pp6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:30 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYTMM003965 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:28 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 01/30] usb: host: xhci: Repurpose event handler for skipping interrupter events Date: Wed, 6 Nov 2024 11:33:44 -0800 Message-ID: <20241106193413.1730413-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: XKtZdueHgEjvxgJZBWQCKCIC_OrYk1cx X-Proofpoint-ORIG-GUID: XKtZdueHgEjvxgJZBWQCKCIC_OrYk1cx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=877 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 Content-Type: text/plain; charset="utf-8" Depending on the interrupter use case, the OS may only be used to handle the interrupter event ring clean up. In these scenarios, event TRBs don't need to be handled by the OS, so introduce an xhci interrupter flag to tag if the events from an interrupter needs to be handled or not. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 17 +++++++++++++---- drivers/usb/host/xhci.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 9f1e150a1c76..b8f6983b7369 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2931,14 +2931,22 @@ static int handle_tx_event(struct xhci_hcd *xhci, } =20 /* - * This function handles one OS-owned event on the event ring. It may drop - * xhci->lock between event processing (e.g. to pass up port status change= s). + * This function handles one OS-owned event on the event ring, or ignores = one event + * on interrupters which are non-OS owned. It may drop xhci->lock between = event + * processing (e.g. to pass up port status changes). */ static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interr= upter *ir, union xhci_trb *event) { u32 trb_type; =20 + /* + * Some interrupters do not need to handle event TRBs, as they may be + * managed by another entity, but rely on the OS to clean up. + */ + if (ir->skip_events) + return 0; + trace_xhci_handle_event(ir->event_ring, &event->generic); =20 /* @@ -3026,8 +3034,9 @@ static void xhci_clear_interrupt_pending(struct xhci_= interrupter *ir) } =20 /* - * Handle all OS-owned events on an interrupter event ring. It may drop - * and reaquire xhci->lock between event processing. + * Handle all OS-owned events on an interrupter event ring, or skip pendin= g events + * for non OS owned interrupter event ring. It may drop and reacquire xhci= ->lock + * between event processing. */ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupt= er *ir) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 55a81073cf1e..92cde885acd3 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1430,6 +1430,7 @@ struct xhci_interrupter { struct xhci_intr_reg __iomem *ir_set; unsigned int intr_num; bool ip_autoclear; + bool skip_events; u32 isoc_bei_interval; /* For interrupter registers save and restore over suspend/resume */ u32 s3_irq_pending; From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C54A20C327; Wed, 6 Nov 2024 19:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921692; cv=none; b=SkZlN2IUmLsZyiMyZIlKBWUwxQBPuHPuevnzdvGJuMBbmrHe4jezKQUkD6H3WWRIV3KzygpUEbftKodCNpYK19Wx8WzkSyDphaWlp7hS1Xdb63AeWg6oof1JZ+AsOZ0t7yvIWWSOurlEXX+kyLy2sR5VRDgFlNeAK4gv2iGoMXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921692; c=relaxed/simple; bh=laVScmsW6CVoKvh/TcWDw+CWsb55H4jEgaVpghUAmEA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RLGIJReFpwrYYOC9QsYa7mGeebiM/1nnx5PBdEvJIz7DJqdL80Qi3paNzPkCFLGXvftioj/4iqwYZ+g0riiuEb50+lvFGcqUn3Tm4q5EpExS2hNs3YA8JG2MQ1MPQJv1B1gZGl0oCVhS1oj8Zsk/FCrjXyfjLR67voGdfLKQsKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=C3eY1Mhs; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="C3eY1Mhs" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6Fc1wQ006933; Wed, 6 Nov 2024 19:34:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 7XMyWIyAjG0dyYiXJF85kAHL0Q6noKknyTQb8vOivmE=; b=C3eY1MhsH1X4PkTx AiCrZjC4oPDp9T51tEmE27lepe/2QUXdrFZGtmWIv6sCgbcXPiVHFeF81026iDrl bT88+nXMKMLej1B5Io4TGTwM6PBcJ5duWPNRq6gt90y9z5+xmidPOaBCko1OjaYA KtkR2jFZRgGMvltap/mLL8Kip94cDHLyhbTqfBQgPVQFp758U8OVHpu61nU5FbGk 4PBkqqeHkCqKn3LhabDTGPpwodbHANe3t2h4VpuzAhwTme9xdQ2WdfqPsUPpN+Wx mW5qspZy6j2iMNiLK/rv34fOyVaLjP5dRTkF23xY7jxY3tq9yAruOLSrBFr8m5NQ KnpjoA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r07hjg8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:31 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYTOJ027625 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v30 02/30] xhci: sec-intr: add initial api to register a secondary interrupter entity Date: Wed, 6 Nov 2024 11:33:45 -0800 Message-ID: <20241106193413.1730413-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Gup-w5hh67QTmfnu5Ob-flyUJXegeQav X-Proofpoint-ORIG-GUID: Gup-w5hh67QTmfnu5Ob-flyUJXegeQav X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" From: Mathias Nyman Introduce XHCI sec intr, which manages the USB endpoints being requested by a client driver. This is used for when client drivers are attempting to offload USB endpoints to another entity for handling USB transfers. XHCI sec intr will allow for drivers to fetch the required information about the transfer ring, so the user can submit transfers independently. Expose the required APIs for drivers to register and request for a USB endpoint and to manage XHCI secondary interrupters. Driver renaming, multiple ring segment page linking, proper endpoint clean up, and allowing module compilation added by Wesley Cheng to complete original concept code by Mathias Nyman. Signed-off-by: Mathias Nyman Co-developed-by: Wesley Cheng Signed-off-by: Wesley Cheng --- drivers/usb/host/Kconfig | 11 + drivers/usb/host/Makefile | 2 + drivers/usb/host/xhci-sec-intr.c | 438 ++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 4 + include/linux/usb/xhci-sec-intr.h | 70 +++++ 5 files changed, 525 insertions(+) create mode 100644 drivers/usb/host/xhci-sec-intr.c create mode 100644 include/linux/usb/xhci-sec-intr.h diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index d011d6c753ed..a2d549e3e076 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -104,6 +104,17 @@ config USB_XHCI_RZV2M Say 'Y' to enable the support for the xHCI host controller found in Renesas RZ/V2M SoC. =20 +config USB_XHCI_SEC_INTR + tristate "xHCI support for secondary interrupter management" + help + Say 'Y' to enable the support for the xHCI secondary management. + Provide a mechanism for a sideband datapath for payload associated + with audio class endpoints. This allows for an audio DSP to use + xHCI USB endpoints directly, allowing CPU to sleep while playing + audio. This is not the same feature as the audio sideband + capability mentioned within the xHCI specification, and continues + to utilize main system memory for data transfers. + config USB_XHCI_TEGRA tristate "xHCI support for NVIDIA Tegra SoCs" depends on PHY_TEGRA_XUSB diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index be4e5245c52f..d4b127f48cf9 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -32,6 +32,8 @@ endif xhci-rcar-hcd-y +=3D xhci-rcar.o xhci-rcar-hcd-$(CONFIG_USB_XHCI_RZV2M) +=3D xhci-rzv2m.o =20 +obj-$(CONFIG_USB_XHCI_SEC_INTR) +=3D xhci-sec-intr.o + obj-$(CONFIG_USB_PCI) +=3D pci-quirks.o =20 obj-$(CONFIG_USB_EHCI_HCD) +=3D ehci-hcd.o diff --git a/drivers/usb/host/xhci-sec-intr.c b/drivers/usb/host/xhci-sec-i= ntr.c new file mode 100644 index 000000000000..b112c3388368 --- /dev/null +++ b/drivers/usb/host/xhci-sec-intr.c @@ -0,0 +1,438 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * xHCI host controller secondary interrupter management + * + * Provides logic for client drivers that support utilizing xHCI secondary + * interrupters. + * + * Copyright (c) 2023-2024, Intel Corporation. + * + * Author: Mathias Nyman + */ + +#include +#include + +#include "xhci.h" + +/* internal helpers */ +static struct sg_table * +xhci_ring_to_sgtable(struct xhci_sec_intr *si, struct xhci_ring *ring) +{ + struct xhci_segment *seg; + struct sg_table *sgt; + unsigned int n_pages; + struct page **pages; + struct device *dev; + size_t sz; + int i; + + dev =3D xhci_to_hcd(si->xhci)->self.sysdev; + sz =3D ring->num_segs * TRB_SEGMENT_SIZE; + n_pages =3D PAGE_ALIGN(sz) >> PAGE_SHIFT; + pages =3D kvmalloc_array(n_pages, sizeof(struct page *), GFP_KERNEL); + if (!pages) + return NULL; + + sgt =3D kzalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) { + kvfree(pages); + return NULL; + } + + seg =3D ring->first_seg; + if (!seg) + goto err; + /* + * Rings can potentially have multiple segments, create an array that + * carries page references to allocated segments. Utilize the + * sg_alloc_table_from_pages() to create the sg table, and to ensure + * that page links are created. + */ + for (i =3D 0; i < ring->num_segs; i++) { + dma_get_sgtable(dev, sgt, seg->trbs, seg->dma, + TRB_SEGMENT_SIZE); + pages[i] =3D sg_page(sgt->sgl); + sg_free_table(sgt); + seg =3D seg->next; + } + + if (sg_alloc_table_from_pages(sgt, pages, n_pages, 0, sz, GFP_KERNEL)) + goto err; + + /* + * Save first segment dma address to sg dma_address field for the sideband + * client to have access to the IOVA of the ring. + */ + sg_dma_address(sgt->sgl) =3D ring->first_seg->dma; + + return sgt; + +err: + kvfree(pages); + kfree(sgt); + + return NULL; +} + +static void +__xhci_sec_intr_remove_endpoint(struct xhci_sec_intr *si, struct xhci_virt= _ep *ep) +{ + /* + * Issue a stop endpoint command when an endpoint is removed. + * The stop ep cmd handler will handle the ring cleanup. + */ + xhci_stop_endpoint_sync(si->xhci, ep, 0, GFP_KERNEL); + + ep->sec =3D NULL; + si->eps[ep->ep_index] =3D NULL; +} + +/* endpoint api functions */ + +/** + * xhci_sec_intr_add_endpoint - add endpoint to access list + * @si: secondary interrupter instance for this usb device + * @host_ep: usb host endpoint + * + * Adds an endpoint to the list of endpoints utilizing secondary interrupt= ers + * for this usb device. + * After an endpoint is added the client can get the endpoint transfer ring + * buffer by calling xhci_sec_intr_get_endpoint_buffer() + * + * Return: 0 on success, negative error otherwise. + */ +int +xhci_sec_intr_add_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + mutex_lock(&si->mutex); + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D &si->vdev->eps[ep_index]; + + if (ep->ep_state & EP_HAS_STREAMS) { + mutex_unlock(&si->mutex); + return -EINVAL; + } + + /* + * Note, we don't know the DMA mask of the audio DSP device, if its + * smaller than for xhci it won't be able to access the endpoint ring + * buffer. This could be solved by not allowing the audio class driver + * to add the endpoint the normal way, but instead offload it immediately, + * and let this function add the endpoint and allocate the ring buffer + * with the smallest common DMA mask + */ + if (si->eps[ep_index] || ep->sec) { + mutex_unlock(&si->mutex); + return -EBUSY; + } + + ep->sec =3D si; + si->eps[ep_index] =3D ep; + mutex_unlock(&si->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_add_endpoint); + +/** + * xhci_sec_intr_remove_endpoint - remove endpoint from access list + * @si: secondary interrupter instance for this usb device + * @host_ep: usb host endpoint + * + * Removes an endpoint from the list of endpoints utilizing secondary + * interrupters for this usb device. + * Clients should no longer touch the endpoint transfer buffer after + * calling this. + * + * Return: 0 on success, negative error otherwise. + */ +int +xhci_sec_intr_remove_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + mutex_lock(&si->mutex); + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D si->eps[ep_index]; + + if (!ep || !ep->sec || ep->sec !=3D si) { + mutex_unlock(&si->mutex); + return -ENODEV; + } + + __xhci_sec_intr_remove_endpoint(si, ep); + xhci_initialize_ring_info(ep->ring, 1); + mutex_unlock(&si->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_remove_endpoint); + +/** + * xhci_sec_intr_stop_endpoint - stops a client managed endpoint + * @si: secondary interrupter instance for this usb device + * @host_ep: usb host endpoint + * + * Issue a synchronous stop endpoint command to halt any data transfers + * occurring. This also is required before the xHCI controller enters + * suspend. + * + * Return: 0 on success, and negative on failure. + */ +int +xhci_sec_intr_stop_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D si->eps[ep_index]; + + if (!ep || !ep->sec || ep->sec !=3D si) + return -EINVAL; + + return xhci_stop_endpoint_sync(si->xhci, ep, 0, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_stop_endpoint); + +/** + * xhci_sec_intr_get_endpoint_buffer - gets the endpoint transfer buffer a= ddress + * @si: secondary interrupter instance for this usb device + * @host_ep: usb host endpoint + * + * Returns the address of the endpoint buffer where xHC controller reads q= ueued + * transfer TRBs from. This is the starting address of the ringbuffer wher= e the + * client should write TRBs to. + * + * Caller needs to free the returned sg_table + * + * Return: struct sg_table * if successful. NULL otherwise. + */ +struct sg_table * +xhci_sec_intr_get_endpoint_buffer(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D si->eps[ep_index]; + + if (!ep || !ep->sec || ep->sec !=3D si) + return NULL; + + return xhci_ring_to_sgtable(si, ep->ring); +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_get_endpoint_buffer); + +/** + * xhci_sec_intr_get_event_buffer - return the event buffer for this device + * @si: secondary interrupter instance for this usb device + * + * If a secondary xhci interupter is set up for this usb device then this + * function returns the address of the event buffer where xHC writes + * the transfer completion events. + * + * Caller needs to free the returned sg_table + * + * Return: struct sg_table * if successful. NULL otherwise. + */ +struct sg_table * +xhci_sec_intr_get_event_buffer(struct xhci_sec_intr *si) +{ + if (!si || !si->ir) + return NULL; + + return xhci_ring_to_sgtable(si, si->ir->event_ring); +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_get_event_buffer); + +/** + * xhci_sec_intr_create_interrupter - creates a new interrupter + * @si: secondary interrupter instance for this usb device + * @num_seg: number of event ring segments to allocate + * @ip_autoclear: IP autoclearing support such as MSI implemented + * + * Sets up a xhci interrupter that can be used for this sideband accessed = usb + * device. Transfer events for this device can be routed to this interrupt= ers + * event ring by setting the 'Interrupter Target' field correctly when que= ueing + * the transfer TRBs. + * Once this interrupter is created the interrupter target ID can be obtai= ned + * by calling xhci_sec_intr_interrupter_id() + * + * Returns 0 on success, negative error otherwise + */ +int +xhci_sec_intr_create_interrupter(struct xhci_sec_intr *si, int num_seg, + bool ip_autoclear, u32 imod_interval) +{ + int ret =3D 0; + + if (!si || !si->xhci) + return -ENODEV; + + mutex_lock(&si->mutex); + if (si->ir) { + ret =3D -EBUSY; + goto out; + } + + si->ir =3D xhci_create_secondary_interrupter(xhci_to_hcd(si->xhci), + num_seg, imod_interval); + if (!si->ir) { + ret =3D -ENOMEM; + goto out; + } + + si->ir->ip_autoclear =3D ip_autoclear; + /* skip events for secondary interrupters by default */ + si->ir->skip_events =3D true; + +out: + mutex_unlock(&si->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_create_interrupter); + +/** + * xhci_sec_intr_remove_interrupter - remove the secondary interrupter for= a device + * @si: secondary interrupter instance for this usb device + * + * Removes a registered interrupter for a usb device. This would allow fo= r other + * users to utilize this interrupter. + */ +void +xhci_sec_intr_remove_interrupter(struct xhci_sec_intr *si) +{ + if (!si || !si->ir) + return; + + mutex_lock(&si->mutex); + xhci_remove_secondary_interrupter(xhci_to_hcd(si->xhci), si->ir); + + si->ir =3D NULL; + mutex_unlock(&si->mutex); +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_remove_interrupter); + +/** + * xhci_sec_intr_interrupter_id - return the interrupter target id + * @si: secondary interrupter instance for this usb device + * + * If a secondary xhci interrupter is set up for this usb device then this + * function returns the ID used by the interrupter. The client needs + * to write this ID to the 'Interrupter Target' field of the transfer TRBs + * it queues on the endpoints transfer ring to ensure transfer completion = event + * are written by xHC to the correct interrupter event ring. + * + * Returns interrupter id on success, negative error otherwise + */ +int +xhci_sec_intr_interrupter_id(struct xhci_sec_intr *si) +{ + if (!si || !si->ir) + return -ENODEV; + + return si->ir->intr_num; +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_interrupter_id); + +/** + * xhci_sec_intr_register - register a secondary interrupter for a usb dev= ice + * @udev: usb device to be accessed via sideband + * + * Allows for clients to utilize XHCI interrupters and fetch transfer and = event + * ring parameters for executing data transfers. + * + * Return: pointer to a new xhci_sec_intr instance if successful. NULL oth= erwise. + */ +struct xhci_sec_intr * +xhci_sec_intr_register(struct usb_device *udev) +{ + struct usb_hcd *hcd =3D bus_to_hcd(udev->bus); + struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); + struct xhci_virt_device *vdev; + struct xhci_sec_intr *si; + + /* make sure the usb device is connected to a xhci controller */ + if (!udev->slot_id) + return NULL; + + si =3D kzalloc_node(sizeof(*si), GFP_KERNEL, dev_to_node(hcd->self.sysdev= )); + if (!si) + return NULL; + + mutex_init(&si->mutex); + + /* check this device isn't already controlled via sideband */ + spin_lock_irq(&xhci->lock); + + vdev =3D xhci->devs[udev->slot_id]; + + if (!vdev || vdev->sec) { + xhci_warn(xhci, "XHCI sideband for slot %d already in use\n", + udev->slot_id); + spin_unlock_irq(&xhci->lock); + kfree(si); + return NULL; + } + + si->xhci =3D xhci; + si->vdev =3D vdev; + vdev->sec =3D si; + + spin_unlock_irq(&xhci->lock); + + return si; +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_register); + +/** + * xhci_sec_intr_unregister - unregister secondary interrupter for a usb d= evice + * @si: secondary interrupter instance to be unregistered + * + * Unregisters sideband access to a usb device and frees the secondary int= errupter + * instance. + * After this the endpoint and interrupter event buffers should no longer + * be accessed via sideband. The xhci driver can now take over handling + * the buffers. + */ +void +xhci_sec_intr_unregister(struct xhci_sec_intr *si) +{ + struct xhci_hcd *xhci; + int i; + + if (!si) + return; + + xhci =3D si->xhci; + + mutex_lock(&si->mutex); + for (i =3D 0; i < EP_CTX_PER_DEV; i++) + if (si->eps[i]) + __xhci_sec_intr_remove_endpoint(si, si->eps[i]); + mutex_unlock(&si->mutex); + + xhci_sec_intr_remove_interrupter(si); + + spin_lock_irq(&xhci->lock); + si->xhci =3D NULL; + si->vdev->sec =3D NULL; + spin_unlock_irq(&xhci->lock); + + kfree(si); +} +EXPORT_SYMBOL_GPL(xhci_sec_intr_unregister); +MODULE_DESCRIPTION("xHCI sideband driver for secondary interrupter managem= ent"); +MODULE_LICENSE("GPL"); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 92cde885acd3..4a6ca048a14c 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -694,6 +694,8 @@ struct xhci_virt_ep { int next_frame_id; /* Use new Isoch TRB layout needed for extended TBC support */ bool use_extended_tbc; + /* set if this endpoint is controlled via sideband access*/ + struct xhci_sec_intr *sec; }; =20 enum xhci_overhead_type { @@ -756,6 +758,8 @@ struct xhci_virt_device { u16 current_mel; /* Used for the debugfs interfaces. */ void *debugfs_private; + /* set if this device is registered for sideband access */ + struct xhci_sec_intr *sec; }; =20 /* diff --git a/include/linux/usb/xhci-sec-intr.h b/include/linux/usb/xhci-sec= -intr.h new file mode 100644 index 000000000000..f6edb27b1d99 --- /dev/null +++ b/include/linux/usb/xhci-sec-intr.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * xHCI host controller sideband support + * + * Copyright (c) 2023, Intel Corporation. + * + * Author: Mathias Nyman + */ + +#ifndef __LINUX_XHCI_SEC_INTR_H +#define __LINUX_XHCI_SEC_INTR_H + +#include +#include + +#define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ + +struct xhci_sec_intr; + +/** + * struct xhci_sec_intr - representation of a sideband accessed usb device. + * @xhci: The xhci host controller the usb device is connected to + * @vdev: the usb device accessed via sideband + * @eps: array of endpoints controlled via sideband + * @ir: event handling and buffer for sideband accessed device + * @mutex: mutex for sideband operations + * + * FIXME usb device accessed via sideband Keeping track of sideband access= ed usb devices. + */ + +struct xhci_sec_intr { + struct xhci_hcd *xhci; + struct xhci_virt_device *vdev; + struct xhci_virt_ep *eps[EP_CTX_PER_DEV]; + struct xhci_interrupter *ir; + + /* Synchronizing xHCI sec intr operations with client drivers operations = */ + struct mutex mutex; +}; + +struct xhci_sec_intr * +xhci_sec_intr_register(struct usb_device *udev); +void +xhci_sec_intr_unregister(struct xhci_sec_intr *si); +int +xhci_sec_intr_add_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep); +int +xhci_sec_intr_remove_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep); +int +xhci_sec_intr_stop_endpoint(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep); +struct sg_table * +xhci_sec_intr_get_endpoint_buffer(struct xhci_sec_intr *si, + struct usb_host_endpoint *host_ep); +struct sg_table * +xhci_sec_intr_get_event_buffer(struct xhci_sec_intr *si); + +int +xhci_sec_intr_create_interrupter(struct xhci_sec_intr *si, int num_seg, + bool ip_autoclear, u32 imod_interval); + +void +xhci_sec_intr_remove_interrupter(struct xhci_sec_intr *si); + +int +xhci_sec_intr_interrupter_id(struct xhci_sec_intr *si); + +#endif /* __LINUX_XHCI_SIDEBAND_H */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4673C208204; Wed, 6 Nov 2024 19:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921687; cv=none; b=u3d+2INf2rcGJAzU/ARsaZv0Coqr88BwLvNE3YB8mHo4MEFwAiqJ7i0P+VgIluvHV7IrjsR4QlRSMma9ISeJY0kK08e0amPEPOEL1z+AMIFhCdDa3+qOYvFBcKPGMJE8aPTKbec0MqICvIeB5e0N/+A05F9Uaz+R6q42ged9Dvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921687; c=relaxed/simple; bh=2jtMHfHyXevFHVzAbV0oqMyg9jPBqoFChsxrXYcLnek=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=asHl3CRfu0iOY35gbcYDsofzZQxoTfexrPjbdiWqhv/LuGt2hQe1vjSuh5/7jGlPE33vc+r3AgcA7NlZFwUII+y/fkgFZWQhIgwEzAwt54OfC7KuRXapm4+eBZIDHLrEIqRgtChJfPOpgtkV2DJ6qXFsXtENcV/yDujFJ/W0B8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=cHKZmwq3; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="cHKZmwq3" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6ADNU8002680; Wed, 6 Nov 2024 19:34:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= L0KjqXODikZXPjtbEVHii/bHyoAr+VVMPYGDJW8/hSk=; b=cHKZmwq3aqqD2F5W +jlRPk/91RNTEd+EXl1PvOKYcsb1WwKQrZZKQc4voCTygpa7KsrtIkV9XvZ0I4xt 98n7EuCOyAC77hcJ4oHNhpBIA7tHdCyULD2vfGyhX95bEdofUkT+BdE7ZMIAgjNZ gZpksahb+ZoS7a31sNlso7aTlf2xRvzoxGuC2fjUhQJNCAB5tgelD0PyI1tIWL1S 0AqBo8hs3I9qJm0VFGBiVlCcUxRoHryIjNwghKGvaKHAAYp/1orEpdCf7LKdkrAl jKineld0fqjU17CyTutAwHpjmawburDXErKGVVz63+2cMFbdEJTQaAqzj8/6UTi4 xvpINA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y8t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:30 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYTOK027625 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 03/30] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Wed, 6 Nov 2024 11:33:46 -0800 Message-ID: <20241106193413.1730413-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: h9Fi0Xbl-81AVZz2jyCROtbTYzhKTl7f X-Proofpoint-GUID: h9Fi0Xbl-81AVZz2jyCROtbTYzhKTl7f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=909 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" As part of xHCI bus suspend, the xHCI is halted. However, if there are pending events in the secondary event ring, it is observed that the xHCI controller stops responding to further commands upon host or device initiated bus resume. Iterate through all pending events and update the dequeue pointer to the beginning of the event ring. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 7 ++++++- drivers/usb/host/xhci-ring.c | 37 +++++++++++++++++++++++++++++++++--- drivers/usb/host/xhci.c | 2 +- drivers/usb/host/xhci.h | 7 +++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d2900197a49e..f6cfc989e28e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1811,7 +1811,7 @@ xhci_remove_interrupter(struct xhci_hcd *xhci, struct= xhci_interrupter *ir) tmp &=3D ERST_SIZE_MASK; writel(tmp, &ir->ir_set->erst_size); =20 - xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); + xhci_update_erst_dequeue(xhci, ir, true); } } =20 @@ -1854,6 +1854,11 @@ void xhci_remove_secondary_interrupter(struct usb_hc= d *hcd, struct xhci_interrup return; } =20 + /* + * Cleanup secondary interrupter to ensure there are no pending events. + * This also updates event ring dequeue pointer back to the start. + */ + xhci_skip_sec_intr_events(xhci, ir->event_ring, ir); intr_num =3D ir->intr_num; =20 xhci_remove_interrupter(xhci, ir); diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index b8f6983b7369..39b938f9d2da 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2992,9 +2992,9 @@ static int xhci_handle_event_trb(struct xhci_hcd *xhc= i, struct xhci_interrupter * - When all events have finished * - To avoid "Event Ring Full Error" condition */ -static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, - struct xhci_interrupter *ir, - bool clear_ehb) +void xhci_update_erst_dequeue(struct xhci_hcd *xhci, + struct xhci_interrupter *ir, + bool clear_ehb) { u64 temp_64; dma_addr_t deq; @@ -3091,6 +3091,37 @@ static int xhci_handle_events(struct xhci_hcd *xhci,= struct xhci_interrupter *ir return 0; } =20 +/* + * Move the event ring dequeue pointer to skip events kept in the secondary + * event ring. This is used to ensure that pending events in the ring are + * acknowledged, so the xHCI HCD can properly enter suspend/resume. The + * secondary ring is typically maintained by an external component. + */ +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, + struct xhci_ring *ring, struct xhci_interrupter *ir) +{ + union xhci_trb *current_trb; + u64 erdp_reg; + dma_addr_t deq; + + /* disable irq, ack pending interrupt and ack all pending events */ + xhci_disable_interrupter(ir); + + /* last acked event trb is in erdp reg */ + erdp_reg =3D xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + deq =3D (dma_addr_t)(erdp_reg & ERST_PTR_MASK); + if (!deq) { + xhci_err(xhci, "event ring handling not required\n"); + return; + } + + current_trb =3D ir->event_ring->dequeue; + /* read cycle state of the last acked trb to find out CCS */ + ring->cycle_state =3D le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYC= LE; + + xhci_handle_events(xhci, ir); +} + /* * xHCI spec says we can get an interrupt, and if the HC has an error cond= ition, * we might get bad data out of the event ring. Section 4.10.2.7 has a li= st of diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index fdb1b71eeec2..91af00b6b870 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -333,7 +333,7 @@ static int xhci_enable_interrupter(struct xhci_interrup= ter *ir) return 0; } =20 -static int xhci_disable_interrupter(struct xhci_interrupter *ir) +int xhci_disable_interrupter(struct xhci_interrupter *ir) { u32 iman; =20 diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4a6ca048a14c..cde0105a7f1e 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1836,6 +1836,9 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd= , unsigned int segs, u32 imod_interval); void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir); +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, + struct xhci_ring *ring, + struct xhci_interrupter *ir); =20 /* xHCI host controller glue */ typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); @@ -1875,6 +1878,7 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci, struct usb_tt *tt, gfp_t mem_flags); int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, u32 imod_interval); +int xhci_disable_interrupter(struct xhci_interrupter *ir); =20 /* xHCI ring, segment, TRB, and TD functions */ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *= trb); @@ -1920,6 +1924,9 @@ void inc_deq(struct xhci_hcd *xhci, struct xhci_ring = *ring); unsigned int count_trbs(u64 addr, u64 len); int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, gfp_t gfp_flags); +void xhci_update_erst_dequeue(struct xhci_hcd *xhci, + struct xhci_interrupter *ir, + bool clear_ehb); =20 /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9521C20B1E9; Wed, 6 Nov 2024 19:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921688; cv=none; b=oDGK/uTIL7ScoJv2RgOadlwuQ8X3eJn6qNwiL26JtwOzHoIBLecsFZK/crHyVrT95H28cBSeuWl/M1oxo+MfYSbO23NUCAkIqqa287Uw01NfVpcXjTPlWvjxl9e1dOf0ZOEzFcuyaLfT4xeUcfHC/unyI9u6q1q6VGfuKX9JshU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921688; c=relaxed/simple; bh=S6FMCZqhVORDjmGIdqc8rXu1RNcS+gjVrsIOxyBtOW8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aMx9205ptmTp1yOJivwRlPlYnxDVcZ9zMPv8KQRuFASOKv3P3qDNr9+iH/ydgaq10fJe6djd1/71bVNJZCXBOZ3POjFQzkchEB+L6dHSYU0Z89P1FLUGGXA9WW+LpgOZn2+gFxX3G+fAgtEhVCZQTzdkQN+6tTg+Mlsi+9Exlcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=pvQ20/tL; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="pvQ20/tL" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6G9I1g024567; Wed, 6 Nov 2024 19:34:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= bioXrssGHt22KXnwOvG5MvHodH36aHbdDnMMtMovjy4=; b=pvQ20/tLlyO+N0T1 h96RTp1rm2cFCPPaE0mjac2/IefoiEp0OLnEATzAjAX0ronTfi8KFBhRSYBiu6Mk D+kqPLpt7VYUogbjr3kkCq+NlPAVnG7G8n/l0Gj3P4UnrPKq7qpEzfqrVCE8F86h SAfJHCk2+8RTsmI8G12Ad3Bb1PL+qEVpJ8XHGLhy2zCoJEJ0DT89shUdB7BJFcq9 wRWXLBcvvaKmwz9ZIGu8sBiU9AeBMrGxK00527b+sN8gnS/EVNfjZKHiK5WB7jtT gMLLxdovQY3qB/kexRt91lxFbIFNgpG0p6xOCFQfjM8XD1t2jw+N1nqLpPywXHOe wJN88A== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r2ugt4yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:31 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYUC5003973 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 04/30] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Date: Wed, 6 Nov 2024 11:33:47 -0800 Message-ID: <20241106193413.1730413-5-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: gH_O-TLzL0txk96D-5qOX6fYa_B78s-f X-Proofpoint-GUID: gH_O-TLzL0txk96D-5qOX6fYa_B78s-f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 mlxlogscore=760 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Some clients may operate only on a specific XHCI interrupter instance. Allow for the associated class driver to request for the interrupter that it requires. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 24 ++++++++++++++---------- drivers/usb/host/xhci-sec-intr.c | 5 +++-- drivers/usb/host/xhci.h | 2 +- include/linux/usb/xhci-sec-intr.h | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index f6cfc989e28e..598d0b92c6fe 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2338,14 +2338,15 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct = xhci_interrupter *ir, =20 struct xhci_interrupter * xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, - u32 imod_interval) + u32 imod_interval, unsigned int intr_num) { struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); struct xhci_interrupter *ir; unsigned int i; int err =3D -ENOSPC; =20 - if (!xhci->interrupters || xhci->max_interrupters <=3D 1) + if (!xhci->interrupters || xhci->max_interrupters <=3D 1 || + intr_num >=3D xhci->max_interrupters) return NULL; =20 ir =3D xhci_alloc_interrupter(xhci, segs, GFP_KERNEL); @@ -2353,15 +2354,18 @@ xhci_create_secondary_interrupter(struct usb_hcd *h= cd, unsigned int segs, return NULL; =20 spin_lock_irq(&xhci->lock); - - /* Find available secondary interrupter, interrupter 0 is reserved for pr= imary */ - for (i =3D 1; i < xhci->max_interrupters; i++) { - if (xhci->interrupters[i] =3D=3D NULL) { - err =3D xhci_add_interrupter(xhci, ir, i); - break; + if (!intr_num) { + /* Find available secondary interrupter, interrupter 0 is reserved for p= rimary */ + for (i =3D 1; i < xhci->max_interrupters; i++) { + if (!xhci->interrupters[i]) { + err =3D xhci_add_interrupter(xhci, ir, i); + break; + } } + } else { + if (!xhci->interrupters[intr_num]) + err =3D xhci_add_interrupter(xhci, ir, intr_num); } - spin_unlock_irq(&xhci->lock); =20 if (err) { @@ -2377,7 +2381,7 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd= , unsigned int segs, i, imod_interval); =20 xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", - i, xhci->max_interrupters); + ir->intr_num, xhci->max_interrupters); =20 return ir; } diff --git a/drivers/usb/host/xhci-sec-intr.c b/drivers/usb/host/xhci-sec-i= ntr.c index b112c3388368..80d889979f30 100644 --- a/drivers/usb/host/xhci-sec-intr.c +++ b/drivers/usb/host/xhci-sec-intr.c @@ -273,7 +273,7 @@ EXPORT_SYMBOL_GPL(xhci_sec_intr_get_event_buffer); */ int xhci_sec_intr_create_interrupter(struct xhci_sec_intr *si, int num_seg, - bool ip_autoclear, u32 imod_interval) + bool ip_autoclear, u32 imod_interval, int intr_num) { int ret =3D 0; =20 @@ -287,7 +287,8 @@ xhci_sec_intr_create_interrupter(struct xhci_sec_intr *= si, int num_seg, } =20 si->ir =3D xhci_create_secondary_interrupter(xhci_to_hcd(si->xhci), - num_seg, imod_interval); + num_seg, imod_interval, + intr_num); if (!si->ir) { ret =3D -ENOMEM; goto out; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index cde0105a7f1e..a95adbfc583b 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1833,7 +1833,7 @@ void xhci_free_container_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); struct xhci_interrupter * xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, - u32 imod_interval); + u32 imod_interval, unsigned int intr_num); void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir); void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, diff --git a/include/linux/usb/xhci-sec-intr.h b/include/linux/usb/xhci-sec= -intr.h index f6edb27b1d99..6e9b891bdced 100644 --- a/include/linux/usb/xhci-sec-intr.h +++ b/include/linux/usb/xhci-sec-intr.h @@ -59,7 +59,7 @@ xhci_sec_intr_get_event_buffer(struct xhci_sec_intr *si); =20 int xhci_sec_intr_create_interrupter(struct xhci_sec_intr *si, int num_seg, - bool ip_autoclear, u32 imod_interval); + bool ip_autoclear, u32 imod_interval, int intr_num); =20 void xhci_sec_intr_remove_interrupter(struct xhci_sec_intr *si); From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3142208993; Wed, 6 Nov 2024 19:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921686; cv=none; b=hx0S6TER5NxbxpKKkqZoEdQPPPXVxrUqQm6czzlhez7ti+epNUUR3W5eXI/dmNHs0RrNsaguCgKiCFv80hhrfhSr2EF6wKnBvLhoIMekL/tTDDQn3oTEaBwoMvxYRWvY2TizKt3RWvRjo1qjcc0w+bTbRwPwUsUCSnPwv5oIr9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921686; c=relaxed/simple; bh=nh5Iw3wIeZlc3o8MkHLTikKGtch8cks3p+2h+K+8zHE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FGPteICDEMPkxCGxptaIvANil+DYhCtojp7b0TdLrrSphuoD+aPsLzrZp01IXgqSKv7/ghTUx7IX5Y78jrFj4khViAZ5xJox6w2vbRKxYmbiFM1d7QNc97lD00auDRMGaAiu1DomTgPGSDiTsgM7xuM0mXOJ+aWvwrjp/ghevu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=G4dqd6Y9; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="G4dqd6Y9" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6G0X2M010653; Wed, 6 Nov 2024 19:34:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= w/LQsJh9BBw2IrfdXhHrCYc+FRYh+tRIFnuT+7nVT1U=; b=G4dqd6Y9867SGTJ3 BBq0B1D/BSnPBzdQldIwK90WKmrCD6mfh2t4Xl2V45eo29tI9deE9cM5GX7r9t9e 2SqsFAd0+C+wfAIX6Un/4SikrfIKVSn7hFiPfxTF0Pmxp1Qrh4z0GhJbbKbXsuwk FlOUf9rR/DES9UscgNxiyyaSso4E3U8v4QNASFv2/uaOtQZlvTOD1ARsK01b62RI L7w4HY9t57YlmBEXbWaCct6ThJX4IxQfZFTS4axNlS5u+/7WCfypdscz3MEh0zfC Af/3CmLM8QsKo+YACYgdjtgIXoOckc4qHITbF312uTroeEeUFKRazWh7QZtK/sYn hxQqew== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qn73c51k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:31 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYUk9027635 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:30 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 05/30] usb: host: xhci-plat: Set XHCI max interrupters if property is present Date: Wed, 6 Nov 2024 11:33:48 -0800 Message-ID: <20241106193413.1730413-6-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ZYRJUZFSQhCIfMn12nRCm0xWyZK69PmO X-Proofpoint-GUID: ZYRJUZFSQhCIfMn12nRCm0xWyZK69PmO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Some platforms may want to limit the number of XHCI interrupters allocated. This is passed to xhci-plat as a device property. Ensure that this is read and the max_interrupters field is set. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-plat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index e6c9006bd568..3acdbbd9aea3 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -267,6 +267,8 @@ int xhci_plat_probe(struct platform_device *pdev, struc= t device *sysdev, const s =20 device_property_read_u32(tmpdev, "imod-interval-ns", &xhci->imod_interval); + device_property_read_u16(tmpdev, "num-hc-interrupters", + &xhci->max_interrupters); } =20 /* From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9519720B1E6; Wed, 6 Nov 2024 19:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; cv=none; b=upl0G458/vxvlzLAFd88Dr299aHIpVBteophpsl4DsQOaqnqqskHSoR9/e7nyezcmeNT8CuxJUur94R+meE/EE0jER4WXIDaqxilZOFh8ou6E3dz6yG1MwGrBFgi5+/M9TgpYjuEV3yWwGUSgTf5VGBeY2fV5rLBIfotI04fOLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; c=relaxed/simple; bh=1pcPqunoGr8Iz1nPY8OyM/7KGr9R8hMI5tK2JmX/UXA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GwnGvujsp4bPr20zoVJfmjIYmWGt7bTtAwpfMm9DKN5ygXDpb61EN7PWVIF9iQNN1yTNgfVIT7XoXXBMLJf0dO9btQaKAvxajmOXsFW7N1Gz1yC1bSCrKkT2C4pI61XE3Nhdhcp8ZaLGAfyYRZEJa8GjMj2ez6CJUW1k5TzkTG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Ldv+rWxe; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Ldv+rWxe" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6DkajI023174; Wed, 6 Nov 2024 19:34:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= gVt9OnfPmM70gy2yRWUlyVx38DZ3xcJR0hcigrFbJMU=; b=Ldv+rWxel6mcwcG6 wQyKPX+jWNjuxhM4SEqu8UuLjRM87fNqgmw8WcBfiu9lSwv9EOra3yBEeEUtigcm VYGqYhUktR9s2/Q8lw1BRFCrOwwqCptG3q+tEpaFDEROgL4vdZy8v37RAYfELiA5 wYZrdIIpxs28+GLVZmgijAg0DiAOwecQDVLzuYRzgRMbnD3WInB0FyNJwv9nIPRR /I7WBWrZHJ+9CNNO3XenGDLxtmA9wK5Pg1mHG2+UVF7CJvZC+f8TIA6rlJ/3+Sva rLosvzUNUHTjXrmMcGXfG6NAs0qaDCMO67ShqwEYAnBevD29mJuQH1N8W15CntLZ iAKqzQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r07hjg8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:31 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYU9W003977 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:30 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 06/30] usb: dwc3: Specify maximum number of XHCI interrupters Date: Wed, 6 Nov 2024 11:33:49 -0800 Message-ID: <20241106193413.1730413-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 0_m8dmwwgB7wlV-omgMNmX3PhHcKLev4 X-Proofpoint-ORIG-GUID: 0_m8dmwwgB7wlV-omgMNmX3PhHcKLev4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=810 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Allow for the DWC3 host driver to pass along XHCI property that defines how many interrupters to allocate. This is in relation for the number of event rings that can be potentially used by other processors within the system. Acked-by: Thinh Nguyen Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/core.c | 12 ++++++++++++ drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/host.c | 3 +++ 3 files changed, 17 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index de434f78c560..472e4d2774a2 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1660,6 +1660,7 @@ static void dwc3_get_properties(struct dwc3 *dwc) u8 tx_thr_num_pkt_prd =3D 0; u8 tx_max_burst_prd =3D 0; u8 tx_fifo_resize_max_num; + u16 num_hc_interrupters; const char *usb_psy_name; int ret; =20 @@ -1682,6 +1683,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) */ tx_fifo_resize_max_num =3D 6; =20 + /* default to a single XHCI interrupter */ + num_hc_interrupters =3D 1; + dwc->maximum_speed =3D usb_get_maximum_speed(dev); dwc->max_ssp_rate =3D usb_get_maximum_ssp_rate(dev); dwc->dr_mode =3D usb_get_dr_mode(dev); @@ -1735,6 +1739,12 @@ static void dwc3_get_properties(struct dwc3 *dwc) &tx_thr_num_pkt_prd); device_property_read_u8(dev, "snps,tx-max-burst-prd", &tx_max_burst_prd); + device_property_read_u16(dev, "num-hc-interrupters", + &num_hc_interrupters); + /* DWC3 core allowed to have a max of 8 interrupters */ + if (num_hc_interrupters > 8) + num_hc_interrupters =3D 8; + dwc->do_fifo_resize =3D device_property_read_bool(dev, "tx-fifo-resize"); if (dwc->do_fifo_resize) @@ -1823,6 +1833,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->imod_interval =3D 0; =20 dwc->tx_fifo_resize_max_num =3D tx_fifo_resize_max_num; + + dwc->num_hc_interrupters =3D num_hc_interrupters; } =20 /* check whether the core supports IMOD */ diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index eaa55c0cf62f..15a182162ba6 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1082,6 +1082,7 @@ struct dwc3_scratchpad_array { * @tx_max_burst_prd: max periodic ESS transmit burst size * @tx_fifo_resize_max_num: max number of fifos allocated during txfifo re= size * @clear_stall_protocol: endpoint number that requires a delayed status p= hase + * @num_hc_interrupters: number of host controller interrupters * @hsphy_interface: "utmi" or "ulpi" * @connected: true when we're connected to a host, false otherwise * @softconnect: true when gadget connect is called, false when disconnect= runs @@ -1329,6 +1330,7 @@ struct dwc3 { u8 tx_max_burst_prd; u8 tx_fifo_resize_max_num; u8 clear_stall_protocol; + u16 num_hc_interrupters; =20 const char *hsphy_interface; =20 diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index b48e108fc8fe..1c513bf8002e 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -182,6 +182,9 @@ int dwc3_host_init(struct dwc3 *dwc) if (DWC3_VER_IS_WITHIN(DWC3, ANY, 300A)) props[prop_idx++] =3D PROPERTY_ENTRY_BOOL("quirk-broken-port-ped"); =20 + props[prop_idx++] =3D PROPERTY_ENTRY_U16("num-hc-interrupters", + dwc->num_hc_interrupters); + if (prop_idx) { ret =3D device_create_managed_software_node(&xhci->dev, props, NULL); if (ret) { From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F65920BB37; Wed, 6 Nov 2024 19:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; cv=none; b=nTG7lAwsp1/fchti0jkHvS+HGyzdc95iZGenuCEfZ/IQ3zp78SmSE23owRHai/nWOAhG4PNNEqVvbjnkIYa+Iw9d3vKf9QicNjkpTeECaWezvJt3NN9eq2NslN/SlsWEjMDJNZLJUUYgJ28XblAef2hIzmNS58VrlPIBBw9k6I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; c=relaxed/simple; bh=/wBzgNv6xpUz/ZLA8rVS+q7l1axYPeT0H+wezZ9yKCs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Qxz/085xWdG5SmKqnlo0bpG4I8oqhS3blC7Ha1eqHCqg4P2fQwzA0Da8IxoGCXBv8K2vmmS96g5aWqkhmTreO7VqYBXksZceZ5xNjaFUjwKhKf9H4Fnw2+yE8ICWOSORXHWcuWfqyLpCX+xvHYr9lEoYjjXWpws4nnjox+X+kH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=OukaqggG; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OukaqggG" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6FqxDr013161; Wed, 6 Nov 2024 19:34:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 6ZBgdaXJKUel4LEa/FHlUzUIMGn+EiQHJKj2di1CAuA=; b=OukaqggGmnkeWLyO HKh1rNRB4AjvttlbPwpCwedecdyi3ESq88UjlCwgw8pczIJ8WtLkMDT5htP+S/eJ 0npnWZBhssv3TnQgLBy6zl5YuyE1HnGXvWUaT1n/onygItE890w/piCtETOjERQO UB4i8wOb6suUXalCwZkOBo3II/nG9ocZ/9npSk2XXMQfypj0JdX5fUpeuJn3sdUf 3CZzaRlEdc4fVrLNFnOxehsyz0q32QvR/IpJUxBbOY+CAe6cmGKFcUSmyfawI4Bn qAnfc/Hy8iBp/omKi8a2wQVGZp5OEI/8MOAG2rAAhnTicgSWoMVCjmwal9J9ELmq f3qkEg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qp2rv2br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:32 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYVbl003987 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:31 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:30 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 07/30] ALSA: Add USB audio device jack type Date: Wed, 6 Nov 2024 11:33:50 -0800 Message-ID: <20241106193413.1730413-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 8in5fH2d5MpNwkvHxOn2RO-k_Su1baPz X-Proofpoint-ORIG-GUID: 8in5fH2d5MpNwkvHxOn2RO-k_Su1baPz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 bulkscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Add an USB jack type, in order to support notifying of a valid USB audio device. Since USB audio devices can have a slew of different configurations that reach beyond the basic headset and headphone use cases, classify these devices differently. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- include/linux/mod_devicetable.h | 2 +- include/sound/jack.h | 4 +++- include/uapi/linux/input-event-codes.h | 3 ++- sound/core/jack.c | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetabl= e.h index 4338b1b4ac44..82826f5a3741 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -340,7 +340,7 @@ struct pcmcia_device_id { #define INPUT_DEVICE_ID_LED_MAX 0x0f #define INPUT_DEVICE_ID_SND_MAX 0x07 #define INPUT_DEVICE_ID_FF_MAX 0x7f -#define INPUT_DEVICE_ID_SW_MAX 0x10 +#define INPUT_DEVICE_ID_SW_MAX 0x11 #define INPUT_DEVICE_ID_PROP_MAX 0x1f =20 #define INPUT_DEVICE_ID_MATCH_BUS 1 diff --git a/include/sound/jack.h b/include/sound/jack.h index 1ed90e2109e9..bd3f62281c97 100644 --- a/include/sound/jack.h +++ b/include/sound/jack.h @@ -22,6 +22,7 @@ struct input_dev; * @SND_JACK_VIDEOOUT: Video out * @SND_JACK_AVOUT: AV (Audio Video) out * @SND_JACK_LINEIN: Line in + * @SND_JACK_USB: USB audio device * @SND_JACK_BTN_0: Button 0 * @SND_JACK_BTN_1: Button 1 * @SND_JACK_BTN_2: Button 2 @@ -43,6 +44,7 @@ enum snd_jack_types { SND_JACK_VIDEOOUT =3D 0x0010, SND_JACK_AVOUT =3D SND_JACK_LINEOUT | SND_JACK_VIDEOOUT, SND_JACK_LINEIN =3D 0x0020, + SND_JACK_USB =3D 0x0040, =20 /* Kept separate from switches to facilitate implementation */ SND_JACK_BTN_0 =3D 0x4000, @@ -54,7 +56,7 @@ enum snd_jack_types { }; =20 /* Keep in sync with definitions above */ -#define SND_JACK_SWITCH_TYPES 6 +#define SND_JACK_SWITCH_TYPES 7 =20 struct snd_jack { struct list_head kctl_list; diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/in= put-event-codes.h index a4206723f503..f44b9f41d26f 100644 --- a/include/uapi/linux/input-event-codes.h +++ b/include/uapi/linux/input-event-codes.h @@ -924,7 +924,8 @@ #define SW_MUTE_DEVICE 0x0e /* set =3D device disabled */ #define SW_PEN_INSERTED 0x0f /* set =3D pen inserted */ #define SW_MACHINE_COVER 0x10 /* set =3D cover closed */ -#define SW_MAX 0x10 +#define SW_USB_INSERT 0x11 /* set =3D USB audio device connected */ +#define SW_MAX 0x11 #define SW_CNT (SW_MAX+1) =20 /* diff --git a/sound/core/jack.c b/sound/core/jack.c index e4bcecdf89b7..de7c603e92b7 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c @@ -34,6 +34,7 @@ static const int jack_switch_types[SND_JACK_SWITCH_TYPES]= =3D { SW_JACK_PHYSICAL_INSERT, SW_VIDEOOUT_INSERT, SW_LINEIN_INSERT, + SW_USB_INSERT, }; #endif /* CONFIG_SND_JACK_INPUT_DEV */ =20 @@ -241,8 +242,9 @@ static ssize_t jack_kctl_id_read(struct file *file, static const char * const jack_events_name[] =3D { "HEADPHONE(0x0001)", "MICROPHONE(0x0002)", "LINEOUT(0x0004)", "MECHANICAL(0x0008)", "VIDEOOUT(0x0010)", "LINEIN(0x0020)", - "", "", "", "BTN_5(0x0200)", "BTN_4(0x0400)", "BTN_3(0x0800)", - "BTN_2(0x1000)", "BTN_1(0x2000)", "BTN_0(0x4000)", "", + "USB(0x0040)", "", "", "BTN_5(0x0200)", "BTN_4(0x0400)", + "BTN_3(0x0800)", "BTN_2(0x1000)", "BTN_1(0x2000)", "BTN_0(0x4000)", + "", }; =20 /* the recommended buffer size is 256 */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C20A20E33D; Wed, 6 Nov 2024 19:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921695; cv=none; b=kacAEQTSl+q6IMK7YTxAwkeg72dWNdm/m9FkDCxp0DsZVtU7ZzKD2PWVb64OXvvRoZUYshAtxtH0ids+MhcG6HDHTuS60jFgQzWb0d8ewcy4lciNQ7AE+UES4FxvqHPtmq8ILddTupYU9S13e+k7MdquRV2Jbk8jP4s7sLQpJrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921695; c=relaxed/simple; bh=k70C/OKRYCZFuFIjRaJpLF2xmMY3Oq+qu31jhSfCVBE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GD54JT8P8Q7bNsUjEMKHB07nRcaKC/fkDqMkC+wWuEF9dy/F0cizRph7HgsIOeb/BDTwtTGvI3tauK25DB4Rf8W/EbPjZKhRTb5mQEIgt85mj1v3wxcy2XP/I7hYe3e6+sSk9LS8qV0v/r8TM9gzYEbhHlGblXiIxOuNIJLsOBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=UBRC/IGG; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="UBRC/IGG" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6GR5GN024800; Wed, 6 Nov 2024 19:34:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= BoGAuq+z20KYkIjxeuKJM2AyqrqxYINbV2hGYpYCtag=; b=UBRC/IGGSl5Js2h+ Z2dB9xKp20C3x2OJza+atll+bt7JsHriAq37fwgiVtFUEff1fmrPnStnaeAE0hMq PL6CznDjXxPpyMFYwmKRuEG3RYM2z68HE0cojjkiwHbqvEzE/kmMFtlLQZwqTlsa MV8YasMlVLI0sRo4BzpNQmJNpVz5iysZ5rprHLxrxbI0mwaX3hBfhyEUzvM6vbxp 1CkeARzvDY1Xt3hlNRLCfbFmuxKq7pc1G8J8bO857U1FPuWCo81mvvGtPom4ZeFL yIsICnlJfQn9BjxGMx0VAuiEZY9xf4/m1XQ6GI1DUjF7Ec8ZtjheT7xGcRuL29ZF 2+5Dkg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r2ugt501-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:32 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYVfA008643 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:31 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:30 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 08/30] ALSA: usb-audio: Export USB SND APIs for modules Date: Wed, 6 Nov 2024 11:33:51 -0800 Message-ID: <20241106193413.1730413-9-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: J0-z-VXMEo4YmOG2Ar0Ok4w-7bHEzx_d X-Proofpoint-GUID: J0-z-VXMEo4YmOG2Ar0Ok4w-7bHEzx_d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Some vendor modules will utilize useful parsing and endpoint management APIs to start audio playback/capture. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- sound/usb/card.c | 4 +++ sound/usb/endpoint.c | 1 + sound/usb/helper.c | 1 + sound/usb/pcm.c | 75 +++++++++++++++++++++++++++++++------------- sound/usb/pcm.h | 11 +++++++ 5 files changed, 71 insertions(+), 21 deletions(-) diff --git a/sound/usb/card.c b/sound/usb/card.c index 9c411b82a218..a0087bde684c 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -1030,6 +1030,7 @@ int snd_usb_lock_shutdown(struct snd_usb_audio *chip) wake_up(&chip->shutdown_wait); return err; } +EXPORT_SYMBOL_GPL(snd_usb_lock_shutdown); =20 /* autosuspend and unlock the shutdown */ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) @@ -1038,6 +1039,7 @@ void snd_usb_unlock_shutdown(struct snd_usb_audio *ch= ip) if (atomic_dec_and_test(&chip->usage_count)) wake_up(&chip->shutdown_wait); } +EXPORT_SYMBOL_GPL(snd_usb_unlock_shutdown); =20 int snd_usb_autoresume(struct snd_usb_audio *chip) { @@ -1060,6 +1062,7 @@ int snd_usb_autoresume(struct snd_usb_audio *chip) } return 0; } +EXPORT_SYMBOL_GPL(snd_usb_autoresume); =20 void snd_usb_autosuspend(struct snd_usb_audio *chip) { @@ -1073,6 +1076,7 @@ void snd_usb_autosuspend(struct snd_usb_audio *chip) for (i =3D 0; i < chip->num_interfaces; i++) usb_autopm_put_interface(chip->intf[i]); } +EXPORT_SYMBOL_GPL(snd_usb_autosuspend); =20 static int usb_audio_suspend(struct usb_interface *intf, pm_message_t mess= age) { diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 568099467dbb..9a0da986abe2 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -1516,6 +1516,7 @@ int snd_usb_endpoint_prepare(struct snd_usb_audio *ch= ip, mutex_unlock(&chip->mutex); return err; } +EXPORT_SYMBOL_GPL(snd_usb_endpoint_prepare); =20 /* get the current rate set to the given clock by any endpoint */ int snd_usb_endpoint_get_clock_rate(struct snd_usb_audio *chip, int clock) diff --git a/sound/usb/helper.c b/sound/usb/helper.c index 72b671fb2c84..497d2b27fb59 100644 --- a/sound/usb/helper.c +++ b/sound/usb/helper.c @@ -62,6 +62,7 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, v= oid *after, u8 dsubtype } return NULL; } +EXPORT_SYMBOL_GPL(snd_usb_find_csint_desc); =20 /* * Wrapper for usb_control_msg(). diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 08bf535ed163..18467da6fd9e 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -148,6 +148,16 @@ find_format(struct list_head *fmt_list_head, snd_pcm_f= ormat_t format, return found; } =20 +const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t form= at, + unsigned int rate, unsigned int channels, bool strict_match, + struct snd_usb_substream *subs) +{ + return find_format(fmt_list_head, format, rate, channels, strict_match, + subs); +} +EXPORT_SYMBOL_GPL(snd_usb_find_format); + static const struct audioformat * find_substream_format(struct snd_usb_substream *subs, const struct snd_pcm_hw_params *params) @@ -157,6 +167,14 @@ find_substream_format(struct snd_usb_substream *subs, true, subs); } =20 +const struct audioformat * +snd_usb_find_substream_format(struct snd_usb_substream *subs, + const struct snd_pcm_hw_params *params) +{ + return find_substream_format(subs, params); +} +EXPORT_SYMBOL_GPL(snd_usb_find_substream_format); + bool snd_usb_pcm_has_fixed_rate(struct snd_usb_substream *subs) { const struct audioformat *fp; @@ -461,20 +479,9 @@ static void close_endpoints(struct snd_usb_audio *chip, } } =20 -/* - * hw_params callback - * - * allocate a buffer and set the given audio format. - * - * so far we use a physically linear buffer although packetize transfer - * doesn't need a continuous area. - * if sg buffer is supported on the later version of alsa, we'll follow - * that. - */ -static int snd_usb_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params) +int snd_usb_hw_params(struct snd_usb_substream *subs, + struct snd_pcm_hw_params *hw_params) { - struct snd_usb_substream *subs =3D substream->runtime->private_data; struct snd_usb_audio *chip =3D subs->stream->chip; const struct audioformat *fmt; const struct audioformat *sync_fmt; @@ -499,7 +506,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *= substream, if (fmt->implicit_fb) { sync_fmt =3D snd_usb_find_implicit_fb_sync_format(chip, fmt, hw_params, - !substream->stream, + !subs->direction, &sync_fixed_rate); if (!sync_fmt) { usb_audio_dbg(chip, @@ -579,15 +586,28 @@ static int snd_usb_hw_params(struct snd_pcm_substream= *substream, =20 return ret; } +EXPORT_SYMBOL_GPL(snd_usb_hw_params); =20 /* - * hw_free callback + * hw_params callback * - * reset the audio format and release the buffer + * allocate a buffer and set the given audio format. + * + * so far we use a physically linear buffer although packetize transfer + * doesn't need a continuous area. + * if sg buffer is supported on the later version of alsa, we'll follow + * that. */ -static int snd_usb_hw_free(struct snd_pcm_substream *substream) +static int snd_usb_pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { struct snd_usb_substream *subs =3D substream->runtime->private_data; + + return snd_usb_hw_params(subs, hw_params); +} + +int snd_usb_hw_free(struct snd_usb_substream *subs) +{ struct snd_usb_audio *chip =3D subs->stream->chip; =20 snd_media_stop_pipeline(subs); @@ -603,6 +623,19 @@ static int snd_usb_hw_free(struct snd_pcm_substream *s= ubstream) =20 return 0; } +EXPORT_SYMBOL_GPL(snd_usb_hw_free); + +/* + * hw_free callback + * + * reset the audio format and release the buffer + */ +static int snd_usb_pcm_hw_free(struct snd_pcm_substream *substream) +{ + struct snd_usb_substream *subs =3D substream->runtime->private_data; + + return snd_usb_hw_free(subs); +} =20 /* free-wheeling mode? (e.g. dmix) */ static int in_free_wheeling_mode(struct snd_pcm_runtime *runtime) @@ -1746,8 +1779,8 @@ static int snd_usb_substream_capture_trigger(struct s= nd_pcm_substream *substream static const struct snd_pcm_ops snd_usb_playback_ops =3D { .open =3D snd_usb_pcm_open, .close =3D snd_usb_pcm_close, - .hw_params =3D snd_usb_hw_params, - .hw_free =3D snd_usb_hw_free, + .hw_params =3D snd_usb_pcm_hw_params, + .hw_free =3D snd_usb_pcm_hw_free, .prepare =3D snd_usb_pcm_prepare, .trigger =3D snd_usb_substream_playback_trigger, .sync_stop =3D snd_usb_pcm_sync_stop, @@ -1758,8 +1791,8 @@ static const struct snd_pcm_ops snd_usb_playback_ops = =3D { static const struct snd_pcm_ops snd_usb_capture_ops =3D { .open =3D snd_usb_pcm_open, .close =3D snd_usb_pcm_close, - .hw_params =3D snd_usb_hw_params, - .hw_free =3D snd_usb_hw_free, + .hw_params =3D snd_usb_pcm_hw_params, + .hw_free =3D snd_usb_pcm_hw_free, .prepare =3D snd_usb_pcm_prepare, .trigger =3D snd_usb_substream_capture_trigger, .sync_stop =3D snd_usb_pcm_sync_stop, diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h index 388fe2ba346d..c096021adb2b 100644 --- a/sound/usb/pcm.h +++ b/sound/usb/pcm.h @@ -15,4 +15,15 @@ void snd_usb_preallocate_buffer(struct snd_usb_substream= *subs); int snd_usb_audioformat_set_sync_ep(struct snd_usb_audio *chip, struct audioformat *fmt); =20 +const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t form= at, + unsigned int rate, unsigned int channels, bool strict_match, + struct snd_usb_substream *subs); +const struct audioformat * +snd_usb_find_substream_format(struct snd_usb_substream *subs, + const struct snd_pcm_hw_params *params); + +int snd_usb_hw_params(struct snd_usb_substream *subs, + struct snd_pcm_hw_params *hw_params); +int snd_usb_hw_free(struct snd_usb_substream *subs); #endif /* __USBAUDIO_PCM_H */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F57220BB35; Wed, 6 Nov 2024 19:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; cv=none; b=IxDiAZioPXKRKadzeC4A7tU+u5+bBDA3TroLKLYqaUWnvcqnhb1eN3XEiF7RU8YI+ygnbbZuRygzGJGw+HcPuAW3dDUSggW+SUnbaP8EPFPINIvbKtgP3tcsk3ditHHVMrEinH3L0S4SNKUem1YDPIvtH6hNVQjGRnyqrG1xdCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; c=relaxed/simple; bh=8LFfZvsEZtb7Rvtz20t3R2gyJJLgeD0OdIXEJmaqk0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qEUCmog77eox47GzEzKzBpoKiHlmz20IQwntB+9Q/FRNadG/ajJ5hsFqRMFCiJ2TKuz6iCY2pMiFckneJ0hhGyOXGkTU2G34H57N4HYjl5H4WxvL6Vw8aLVwpGInDTAs+NPHUahWxUil5KNDPIzimNzA4Wp/nm3+AegsHdPq5Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=gi/EwZQd; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gi/EwZQd" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6Inm6c028867; Wed, 6 Nov 2024 19:34:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ttnVezO587R3SiE4KfuBdhmGnpXGor59yM9glqfHyt0=; b=gi/EwZQd63p8OXuN ej6rOo4uQlycneIEqSUnsZxwgCWrIWLEJ3WSt1DBqkqPsGGdzPNXWeaexpoK3ZGQ NSjsHBVDAJCoTTKyDD7TOcs6yB9ECeqVzBSAmlDo3+DL8feCPgsrxi3m5paU9gDl CDQk+1ha4xKUg1e3Exo3b6D/WFqzzTI7jyyoSg1oSl5QRNaiT9Y+8PfGSn8fu6jR oqIzqlHahatf+kyLtbLvDwDHrMyvMKajEvLjeJvfpKuqgS46R7z6yGOhJPxU2jb9 S1L8pnMHqwjCZMGJyzXqz2hoxiPnb7Dktn7EanAiFJTs/v+Tt8rWbY2P5r3pvjYO 45YD7w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd28c9r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:32 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYVLi008646 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:31 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:31 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 09/30] ALSA: usb-audio: Check for support for requested audio format Date: Wed, 6 Nov 2024 11:33:52 -0800 Message-ID: <20241106193413.1730413-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: dNnddCKWtpdlRluaTPSRu3QeqYDpfvD3 X-Proofpoint-GUID: dNnddCKWtpdlRluaTPSRu3QeqYDpfvD3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 Content-Type: text/plain; charset="utf-8" Allow for checks on a specific USB audio device to see if a requested PCM format is supported. This is needed for support when playback is initiated by the ASoC USB backend path. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- sound/usb/card.c | 32 ++++++++++++++++++++++++++++++++ sound/usb/card.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index a0087bde684c..6c5b0e02e57b 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -119,6 +119,38 @@ static DEFINE_MUTEX(register_mutex); static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; static struct usb_driver usb_audio_driver; =20 +/* + * Checks to see if requested audio profile, i.e sample rate, # of + * channels, etc... is supported by the substream associated to the + * USB audio device. + */ +struct snd_usb_stream * +snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *= params, + int direction) +{ + struct snd_usb_audio *chip; + struct snd_usb_substream *subs; + struct snd_usb_stream *as; + + /* + * Register mutex is held when populating and clearing usb_chip + * array. + */ + guard(mutex)(®ister_mutex); + chip =3D usb_chip[card_idx]; + + if (chip && enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs =3D &as->substream[direction]; + if (snd_usb_find_substream_format(subs, params)) + return as; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index 6ec95b2edf86..4f4f3f39b7fa 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,7 @@ struct snd_usb_stream { struct list_head list; }; =20 +struct snd_usb_stream * +snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *= params, + int direction); #endif /* __USBAUDIO_CARD_H */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DB1220B1F1; Wed, 6 Nov 2024 19:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921688; cv=none; b=YVt1hoR/P6umA8V1l9D+Qt/gYqyVF9j5I/ozVQ6VM9Bo+XodXFEUVeb7IYxXOz3CCwE+TpB/JGoiXHK6hsqaStYtuqhNnW0EwnU/ma39tz0Nyv/Pvq+qFj83I88RYP80CYzVNnIAp2CDq3AUw0ZKKhRgfIjOAbCjlkRkrDw5VvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921688; c=relaxed/simple; bh=3aKgo1B1SjDxD8PPQOCXFwIWL2yks3KgGJZ11r+01yM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=savabo/vNki8kNbCwi77NAoz3ndWslQwW33+W0q6BFhJ8znWBR/saP3wk5yIFkazVGcYH96aAuyNCubz+65rM/65SzT1qo/iZIlwyONyeu7ObaWDUuXuALNwiCx2dNnsH739b8v/noK64hLb6DTXJT6lywGoVlzDTqIP8v+XghA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=OCsR175x; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OCsR175x" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6ADNU9002680; Wed, 6 Nov 2024 19:34:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= S5Jw2gC1EQgPX91aR8AjH9HQJRC/Jt3vETf9MI+H438=; b=OCsR175xOQKrjKpU ZNNwC3Cy22dq5MJdT0zr14LPrE90ri1q4+kD655F1NfengqXb2DmSRMoLTZtc9rK ThxprDLq6x0TAwjX+r94xGQGAbIydVDyabeyXaaExKSKqpr0V5azVF0Q0Q803oXO /FthQd1CRb+tZINffZ0+2RcII4x1mpK9xRqMJ9xRg8DlmCVYezawCdf2xdrG5p5E SGxGdLjbsufz4oD9U9pujTjcB0teBRSIplBtw/gf+xqxWTYNYH/hxa9H/z/pWQIn vDHadvSAJXoCzETPLZLx/xza91k3WIaQB4fa4cOHGjMdFj3O4Fk65MBq+/RCB9Yi JoW6Jg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:32 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYWF9011967 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:32 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:31 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 10/30] ALSA: usb-audio: Save UAC sample size information Date: Wed, 6 Nov 2024 11:33:53 -0800 Message-ID: <20241106193413.1730413-11-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: qHhC0xB32AH0VAlXaMM1iMCxJlU9-X0n X-Proofpoint-GUID: qHhC0xB32AH0VAlXaMM1iMCxJlU9-X0n X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Within the UAC descriptor, there is information describing the size of a sample (bSubframeSize/bSubslotSize) and the number of relevant bits (bBitResolution). Currently, fmt_bits carries only the bit resolution, however, some offloading entities may also require the overall size of the sample. Save this information in a separate parameter, as depending on the UAC format type, the sample size can not easily be decoded from other existing parameters. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- sound/usb/card.h | 1 + sound/usb/format.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sound/usb/card.h b/sound/usb/card.h index 4f4f3f39b7fa..b65163c60176 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -15,6 +15,7 @@ struct audioformat { unsigned int channels; /* # channels */ unsigned int fmt_type; /* USB audio format type (1-3) */ unsigned int fmt_bits; /* number of significant bits */ + unsigned int fmt_sz; /* overall audio sub frame/slot size */ unsigned int frame_size; /* samples per frame for non-audio */ unsigned char iface; /* interface number */ unsigned char altsetting; /* corresponding alternate setting */ diff --git a/sound/usb/format.c b/sound/usb/format.c index 0cbf1d4fbe6e..f8a93065ad73 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -80,6 +80,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio= *chip, } =20 fp->fmt_bits =3D sample_width; + fp->fmt_sz =3D sample_bytes; =20 if ((pcm_formats =3D=3D 0) && (format =3D=3D 0 || format =3D=3D BIT(UAC_FORMAT_TYPE_I_UNDEFINED))) { From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B3E212178; Wed, 6 Nov 2024 19:34:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; cv=none; b=EvM9ohk6zmE0QmWXR7Ft5NUQ0r1ekJicoarXLAw5qooRGU4Eip7FY1YHqJ25S8YX9j1NCDZhInBwtEAGBGapF7pNRrll8IDISpmrhTLGtCdgQiTMbz0/UKXOeBpsS5ryKN7AAZ+BXiKlcYFo3lgWT1X+anmTLpAfdeAOf+H6nq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; c=relaxed/simple; bh=5KJ7+nlo+guZwES5cAPb8FiXJM3/tZyf/+ePj0k54QI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jCL3/uK1qgG+MWUf6FwpQkcKt8OxC3n31wd0ei45qo8O9/RJd+CyZMh8NPnte0A2CBxf+Hgidw9JrCNo6XZfHuUO2vlbWiXN7y5DREXRGMECkqMdqTrtZJ/auhdqG+x0kwcv0bco/5xR+mHeEAz0RBSwtrVpo/4qHzGk4SZ6WPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=UKMhTHaM; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="UKMhTHaM" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6G9Dmu028492; Wed, 6 Nov 2024 19:34:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= s1yCIbobXIwRRl19rlXryQgqvNgUhDI2Hp1deBw+rA8=; b=UKMhTHaMf13sBP20 rxVSwmixdgiGEON+pi7WlyWpf7B9xr2aZPCGdJA/+aU60yZ1eip4D7ywTReJXBcf pjtv1MsxRn3h9Y4Ogui6st2nrC8iAlEfHskmd8VrKw1ONQ5Gd8STv8NisLTN/ko2 vo6yWV9cfEMfeX/y3mkW6oG6G+MXWXmcrzjN9oJ2faPfDaYCV7ASPPu3AwN8KBRQ j0RUWfNl/WYiLv8QPnZAXxl1oK8wce+1Rwr128kezFvr5pnVWn67JxWlCsK+RWEL UhMUM/ZUcZuYw5EC7W4rDzgnDM5Pr7kHcYW9BgE7xE6fUkM846LxViHHl2vYtE5D W+ejog== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r3c1a2f2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:33 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYWCY008651 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:32 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:31 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 11/30] ALSA: usb-audio: Prevent starting of audio stream if in use Date: Wed, 6 Nov 2024 11:33:54 -0800 Message-ID: <20241106193413.1730413-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: hoIoU7E59B_GwymijPJyAwXT51mc3lBx X-Proofpoint-ORIG-GUID: hoIoU7E59B_GwymijPJyAwXT51mc3lBx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 spamscore=0 phishscore=0 priorityscore=1501 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" With USB audio offloading, an audio session is started from the ASoC platform sound card and PCM devices. Likewise, the USB SND path is still readily available for use, in case the non-offload path is desired. In order to prevent the two entities from attempting to use the USB bus, introduce a flag that determines when either paths are in use. If a PCM device is already in use, the check will return an error to userspace notifying that the stream is currently busy. This ensures that only one path is using the USB substream. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- sound/usb/card.h | 1 + sound/usb/pcm.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/sound/usb/card.h b/sound/usb/card.h index b65163c60176..cdafc9e9cecd 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -165,6 +165,7 @@ struct snd_usb_substream { unsigned int pkt_offset_adj; /* Bytes to drop from beginning of packets (= for non-compliant devices) */ unsigned int stream_offset_adj; /* Bytes to drop from beginning of stream= (for non-compliant devices) */ =20 + unsigned int opened:1; /* pcm device opened */ unsigned int running: 1; /* running status */ unsigned int period_elapsed_pending; /* delay period handling */ =20 diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 18467da6fd9e..b24ee38fad72 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1241,8 +1241,17 @@ static int snd_usb_pcm_open(struct snd_pcm_substream= *substream) struct snd_usb_stream *as =3D snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime =3D substream->runtime; struct snd_usb_substream *subs =3D &as->substream[direction]; + struct snd_usb_audio *chip =3D subs->stream->chip; int ret; =20 + mutex_lock(&chip->mutex); + if (subs->opened) { + mutex_unlock(&chip->mutex); + return -EBUSY; + } + subs->opened =3D 1; + mutex_unlock(&chip->mutex); + runtime->hw =3D snd_usb_hardware; /* need an explicit sync to catch applptr update in low-latency mode */ if (direction =3D=3D SNDRV_PCM_STREAM_PLAYBACK && @@ -1259,13 +1268,23 @@ static int snd_usb_pcm_open(struct snd_pcm_substrea= m *substream) =20 ret =3D setup_hw_info(runtime, subs); if (ret < 0) - return ret; + goto err_open; ret =3D snd_usb_autoresume(subs->stream->chip); if (ret < 0) - return ret; + goto err_open; ret =3D snd_media_stream_init(subs, as->pcm, direction); if (ret < 0) - snd_usb_autosuspend(subs->stream->chip); + goto err_resume; + + return 0; + +err_resume: + snd_usb_autosuspend(subs->stream->chip); +err_open: + mutex_lock(&chip->mutex); + subs->opened =3D 0; + mutex_unlock(&chip->mutex); + return ret; } =20 @@ -1274,6 +1293,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream= *substream) int direction =3D substream->stream; struct snd_usb_stream *as =3D snd_pcm_substream_chip(substream); struct snd_usb_substream *subs =3D &as->substream[direction]; + struct snd_usb_audio *chip =3D subs->stream->chip; int ret; =20 snd_media_stop_pipeline(subs); @@ -1287,6 +1307,9 @@ static int snd_usb_pcm_close(struct snd_pcm_substream= *substream) =20 subs->pcm_substream =3D NULL; snd_usb_autosuspend(subs->stream->chip); + mutex_lock(&chip->mutex); + subs->opened =3D 0; + mutex_unlock(&chip->mutex); =20 return 0; } From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F9AF20C31D; Wed, 6 Nov 2024 19:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921691; cv=none; b=t8Zvu4LETp61MZnnMoPfNv/xy/xCHUy2GE4pexK7nl4SVyh7RlaFXAiToJdFg7PmWxirw6CbKpgoZZgm4jwSPYe8H+ZPpwSWlxhdase2xC+7wwYCCNjVbbL4laXtoxWwBlb9sySjTIoDVsW0mH7heME/0nwtbXNO5oPwE5WFpJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921691; c=relaxed/simple; bh=wr1eUQkYLeCTT69rU/z7H+GkhQQu6kwpaC/MNR5tJHE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R2pS6A7IYMtximEm24etzfGVqK6rxQSlZ4eg3LRAfPUxEyyIooc9qsXGEVRMnn/mEqBSZDtlXOayFUCac+S0QIaevUSBDMyNu4OLeZG/M4QU/I4NA/2UnBcYDMY9jQdk2anOvoUB8NTL5oY48phyR7JlLBDOVQPKXhM2Rgq0Cqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=n6WjOiAw; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="n6WjOiAw" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AGESt015895; Wed, 6 Nov 2024 19:34:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= jbe6qXskD9BnuqT4ZWDvrxcsezobMfsQ2P3d617MWws=; b=n6WjOiAwxWGtrFzh BrlzWJqIKgykNxehQmmPHLu1gkA68nGHdOv6porESPooNHR4JS2rkL/psa+k/XxI VjJzCaXtgagpUEM6dPxXE9xjcDtGCu/g7EWe3eQvWsoKeW9KV26ntWGh9ST4tt8/ 5sfTP+yxUDNXLnFHrd/mHEwZtjCgjeF5AOkYfsTRJpmjDRWNenPdPBKfX+LbeMZs rh8B37u9bu/cSS7GsZ64bT1uEnlodBIQPM5L+/FRaHpWN9wclmDMrhNmGyhxDanA 1MfOeefV7WINy6QGT9alCwMWmN+abk84l9jNGqzvd6SEeWCKgOhhXaaU6oMstJDM BiAfKg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42q5n8pp6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:33 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYWmq008654 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:32 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:32 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 12/30] ASoC: Add SOC USB APIs for adding an USB backend Date: Wed, 6 Nov 2024 11:33:55 -0800 Message-ID: <20241106193413.1730413-13-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: RIn8Ii76hSXVhRPr-LbFFV0DU7ugYi5g X-Proofpoint-ORIG-GUID: RIn8Ii76hSXVhRPr-LbFFV0DU7ugYi5g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 Content-Type: text/plain; charset="utf-8" Some platforms may have support for offloading USB audio devices to a dedicated audio DSP. Introduce a set of APIs that allow for management of USB sound card and PCM devices enumerated by the USB SND class driver. This allows for the ASoC components to be aware of what USB devices are available for offloading. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 97 ++++++++++++++++++ sound/soc/Kconfig | 10 ++ sound/soc/Makefile | 2 + sound/soc/soc-usb.c | 218 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 327 insertions(+) create mode 100644 include/sound/soc-usb.h create mode 100644 sound/soc/soc-usb.c diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h new file mode 100644 index 000000000000..34240321bbca --- /dev/null +++ b/include/sound/soc-usb.h @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#ifndef __LINUX_SND_SOC_USB_H +#define __LINUX_SND_SOC_USB_H + +#include + +/** + * struct snd_soc_usb_device + * @card_idx - sound card index associated with USB device + * @chip_idx - USB sound chip array index + * @cpcm_idx - capture PCM index array associated with USB device + * @ppcm_idx - playback PCM index array associated with USB device + * @num_capture - number of capture streams + * @num_playback - number of playback streams + * @list - list head for SoC USB devices + **/ +struct snd_soc_usb_device { + int card_idx; + int chip_idx; + + /* PCM index arrays */ + unsigned int *cpcm_idx; /* TODO: capture path is not tested yet */ + unsigned int *ppcm_idx; + int num_capture; /* TODO: capture path is not tested yet */ + int num_playback; + + struct list_head list; +}; + +/** + * struct snd_soc_usb + * @list - list head for SND SOC struct list + * @component - reference to ASoC component + * @connection_status_cb - callback to notify connection events + * @priv_data - driver data + **/ +struct snd_soc_usb { + struct list_head list; + struct snd_soc_component *component; + int (*connection_status_cb)(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, + bool connected); + void *priv_data; +}; + +#if IS_ENABLED(CONFIG_SND_SOC_USB) +int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *= sdev); +int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_devic= e *sdev); +void *snd_soc_usb_find_priv_data(struct device *usbdev); + +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *co= mponent, + void *data); +void snd_soc_usb_free_port(struct snd_soc_usb *usb); +void snd_soc_usb_add_port(struct snd_soc_usb *usb); +void snd_soc_usb_remove_port(struct snd_soc_usb *usb); +#else +static inline int snd_soc_usb_connect(struct device *usbdev, + struct snd_soc_usb_device *sdev) +{ + return -ENODEV; +} + +static inline int snd_soc_usb_disconnect(struct device *usbdev, + struct snd_soc_usb_device *sdev) +{ + return -EINVAL; +} + +static inline void *snd_soc_usb_find_priv_data(struct device *usbdev) +{ + return NULL; +} + +static inline struct snd_soc_usb * +snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data) +{ + return ERR_PTR(-ENOMEM); +} + +static inline void snd_soc_usb_free_port(struct snd_soc_usb *usb) +{ } + +static inline void snd_soc_usb_add_port(struct snd_soc_usb *usb) +{ + return -EINVAL; +} + +static inline void snd_soc_usb_remove_port(struct snd_soc_usb *usb) +{ + return -ENODEV; +} +#endif /* IS_ENABLED(CONFIG_SND_SOC_USB) */ +#endif /*__LINUX_SND_SOC_USB_H */ diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index e87bd15a8b43..0823c0cc969b 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig @@ -84,6 +84,16 @@ config SND_SOC_UTILS_KUNIT_TEST config SND_SOC_ACPI tristate =20 +config SND_SOC_USB + tristate "SoC based USB audio offloading" + depends on SND_USB_AUDIO + help + Enable this option if an ASoC platform card has support to handle + USB audio offloading. This enables the SoC USB layer, which will + notifies the ASoC USB DPCM backend DAI link about available USB audio + devices. Based on the notifications, sequences to enable the audio + stream can be taken based on the design. + # All the supported SoCs source "sound/soc/adi/Kconfig" source "sound/soc/amd/Kconfig" diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 775bb38c2ed4..bbfc49f292fd 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile @@ -35,6 +35,8 @@ endif =20 obj-$(CONFIG_SND_SOC_ACPI) +=3D snd-soc-acpi.o =20 +obj-$(CONFIG_SND_SOC_USB) +=3D soc-usb.o + obj-$(CONFIG_SND_SOC) +=3D snd-soc-core.o obj-$(CONFIG_SND_SOC) +=3D codecs/ obj-$(CONFIG_SND_SOC) +=3D generic/ diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c new file mode 100644 index 000000000000..bd2d68164206 --- /dev/null +++ b/sound/soc/soc-usb.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ +#include +#include +#include +#include "../usb/card.h" + +static DEFINE_MUTEX(ctx_mutex); +static LIST_HEAD(usb_ctx_list); + +static struct device_node *snd_soc_find_phandle(struct device *dev) +{ + struct device_node *node; + + node =3D of_parse_phandle(dev->of_node, "usb-soc-be", 0); + if (!node) + return ERR_PTR(-ENODEV); + + return node; +} + +static struct snd_soc_usb *snd_soc_usb_ctx_lookup(struct device_node *node) +{ + struct snd_soc_usb *ctx; + + if (!node) + return NULL; + + mutex_lock(&ctx_mutex); + list_for_each_entry(ctx, &usb_ctx_list, list) { + if (ctx->component->dev->of_node =3D=3D node) { + mutex_unlock(&ctx_mutex); + return ctx; + } + } + mutex_unlock(&ctx_mutex); + + return NULL; +} + +static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + node =3D snd_soc_find_phandle(dev); + if (!IS_ERR(node)) { + ctx =3D snd_soc_usb_ctx_lookup(node); + of_node_put(node); + } else { + ctx =3D snd_soc_usb_ctx_lookup(dev->of_node); + } + + return ctx ? ctx : NULL; +} + +/** + * snd_soc_usb_find_priv_data() - Retrieve private data stored + * @usbdev: device reference + * + * Fetch the private data stored in the USB SND SOC structure. + * + */ +void *snd_soc_usb_find_priv_data(struct device *usbdev) +{ + struct snd_soc_usb *ctx; + + ctx =3D snd_soc_find_usb_ctx(usbdev); + + return ctx ? ctx->priv_data : NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data); + +/** + * snd_soc_usb_allocate_port() - allocate a SOC USB port for offloading su= pport + * @component: USB DPCM backend DAI component + * @num_streams: number of offloading sessions supported + * @data: private data + * + * Allocate and initialize a SOC USB port. The SOC USB port is used to co= mmunicate + * different USB audio devices attached, in order to start audio offloadin= g handled + * by an ASoC entity. USB device plug in/out events are signaled with a + * notification, but don't directly impact the memory allocated for the SO= C USB + * port. + * + */ +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *co= mponent, + void *data) +{ + struct snd_soc_usb *usb; + + usb =3D kzalloc(sizeof(*usb), GFP_KERNEL); + if (!usb) + return ERR_PTR(-ENOMEM); + + usb->component =3D component; + usb->priv_data =3D data; + + return usb; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_allocate_port); + +/** + * snd_soc_usb_free_port() - free a SOC USB port used for offloading suppo= rt + * @usb: allocated SOC USB port + + * Free and remove the SOC USB port from the available list of ports. Thi= s will + * ensure that the communication between USB SND and ASoC is halted. + * + */ +void snd_soc_usb_free_port(struct snd_soc_usb *usb) +{ + snd_soc_usb_remove_port(usb); + kfree(usb); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); + +/** + * snd_soc_usb_add_port() - Add a USB backend port + * @usb: soc usb port to add + * + * Register a USB backend DAI link to the USB SOC framework. Memory is al= located + * as part of the USB backend DAI link. + * + */ +void snd_soc_usb_add_port(struct snd_soc_usb *usb) +{ + mutex_lock(&ctx_mutex); + list_add_tail(&usb->list, &usb_ctx_list); + mutex_unlock(&ctx_mutex); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_add_port); + +/** + * snd_soc_usb_remove_port() - Remove a USB backend port + * @usb: soc usb port to remove + * + * Remove a USB backend DAI link from USB SOC. Memory is freed when USB b= ackend + * DAI is removed, or when snd_soc_usb_free_port() is called. + * + */ +void snd_soc_usb_remove_port(struct snd_soc_usb *usb) +{ + struct snd_soc_usb *ctx, *tmp; + + mutex_lock(&ctx_mutex); + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) { + if (ctx =3D=3D usb) { + list_del(&ctx->list); + break; + } + } + mutex_unlock(&ctx_mutex); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port); + +/** + * snd_soc_usb_connect() - Notification of USB device connection + * @usbdev: USB bus device + * @sdev: USB SND device to add + * + * Notify of a new USB SND device connection. The sdev->card_idx can be u= sed to + * handle how the DPCM backend selects, which device to enable USB offload= ing + * on. + * + */ +int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *= sdev) +{ + struct snd_soc_usb *ctx; + + if (!usbdev) + return -ENODEV; + + ctx =3D snd_soc_find_usb_ctx(usbdev); + if (IS_ERR(ctx)) + return -ENODEV; + + mutex_lock(&ctx_mutex); + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, true); + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_connect); + +/** + * snd_soc_usb_disconnect() - Notification of USB device disconnection + * @usbdev: USB bus device + * @sdev: USB SND device to remove + * + * Notify of a new USB SND device disconnection to the USB backend. + * + */ +int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_devic= e *sdev) +{ + struct snd_soc_usb *ctx; + + if (!usbdev) + return -ENODEV; + + ctx =3D snd_soc_find_usb_ctx(usbdev); + if (IS_ERR(ctx)) + return -ENODEV; + + mutex_lock(&ctx_mutex); + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, false); + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_disconnect); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SoC USB driver for offloading"); From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C48420C326; Wed, 6 Nov 2024 19:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921691; cv=none; b=Kmr9gip3XQEPpJgHsGcxekOJYP7YV8YxiWU0BsJcH6oOQGzEYRvkMkCt0TAdR7J4iyQy2Mhn1lTyFmhDoLK1DIbnJFFC2E0ZdteKu5DeaZ33M2ZHMurjBQpVqlGD7AlG9LiTDgKMebKWRKUqlOUa6rKz0e/VuiZUr8+lwA7oSF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921691; c=relaxed/simple; bh=FiFxYrrPO0f4AZFgLNMhwElfx+Sn2apeIdL47dNx34U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VD8LlXRqRBd8CV7+WBOmUWPMq7ucI0WPrTfBPHEsbuKWGpyvVVyPs5WUHgjIFhtgLp5sqctucYVODf0Pkjbhxcz8c9H4PpSUnnqdPKe0F8KKnURmn28aKmz0ny7mW/07r64W9ZodWqFl4F9rlbdYNv64mj2jr3u4aK9FDzuxLiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=mkAgG0xl; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mkAgG0xl" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A69iDTV004090; Wed, 6 Nov 2024 19:34:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 4SJdymAG2H1VKUMjaN5IwJUm/vorM6te+0pqk5xcZUQ=; b=mkAgG0xlFqjvjbZJ tGLkUW2s02Ar1/a17YTuthRiSCjqO4gSUbrHjx7cpjp0svIIkctGKlMa/LFsFRZE JdH8IQXNc8NVLb5Qf/LCIPYgzr0sgBSU/KVCc8jMHWF9qf1IkIcV7IHkEwYzauxO el6b0Rc+vO7lE0w/aCZvQvr006WGvhYi+RIEpb7dWBS8zEW/G1+91qE17OxPtTQY PJRfgbVgttnjbhUBoRXcFdbCw+s9XNsmERMoQEKZw/uNG/m67z2b+M/CjRl2woeR eyr3b5p+UfffsudBE1HurjLHvYX7/5NVCobib6AEYOYdxZ6c/XcjRLEussNFEwrV pamlDw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qhbucyew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYXXX008657 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:32 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 13/30] ASoC: usb: Add PCM format check API for USB backend Date: Wed, 6 Nov 2024 11:33:56 -0800 Message-ID: <20241106193413.1730413-14-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: _pi9aO-BnIjYJ89iZkq09Gr4aD6TmYsb X-Proofpoint-GUID: _pi9aO-BnIjYJ89iZkq09Gr4aD6TmYsb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Introduce a helper to check if a particular PCM format is supported by the USB audio device connected. If the USB audio device does not have an audio profile which can support the requested format, then notify the USB backend. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 11 +++++++++++ sound/soc/soc-usb.c | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 34240321bbca..db9ff0b4191d 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -48,6 +48,10 @@ struct snd_soc_usb { }; =20 #if IS_ENABLED(CONFIG_SND_SOC_USB) +int snd_soc_usb_find_supported_format(int card_idx, + struct snd_pcm_hw_params *params, + int direction); + int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *= sdev); int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_devic= e *sdev); void *snd_soc_usb_find_priv_data(struct device *usbdev); @@ -58,6 +62,13 @@ void snd_soc_usb_free_port(struct snd_soc_usb *usb); void snd_soc_usb_add_port(struct snd_soc_usb *usb); void snd_soc_usb_remove_port(struct snd_soc_usb *usb); #else +static inline int +snd_soc_usb_find_supported_format(int card_idx, struct snd_pcm_hw_params *= params, + int direction) +{ + return -EINVAL; +} + static inline int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev) { diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index bd2d68164206..c63033468e4a 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -73,6 +73,32 @@ void *snd_soc_usb_find_priv_data(struct device *usbdev) } EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data); =20 +/** + * snd_soc_usb_find_supported_format() - Check if audio format is supported + * @card_idx: USB sound chip array index + * @params: PCM parameters + * @direction: capture or playback + * + * Ensure that a requested audio profile from the ASoC side is able to be + * supported by the USB device. + * + * Return 0 on success, negative on error. + * + */ +int snd_soc_usb_find_supported_format(int card_idx, + struct snd_pcm_hw_params *params, + int direction) +{ + struct snd_usb_stream *as; + + as =3D snd_usb_find_suppported_substream(card_idx, params, direction); + if (!as) + return -EOPNOTSUPP; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_find_supported_format); + /** * snd_soc_usb_allocate_port() - allocate a SOC USB port for offloading su= pport * @component: USB DPCM backend DAI component From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CA6D2101A1; Wed, 6 Nov 2024 19:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; cv=none; b=TLuz2ktyHDWVNnvqDG3+zrDb01y/vluImu1AevTcFXDI7/SiaMGHcla2YP+5TDFmRT3UxFuYoN5P0LVAPIqdO7K3hesJfNC/VW9bWpwSXOERO/R4eRtp+7p6HOIJRoxx6W4Te0rfSw5YPkqpD7fTQyDm4vdZ7uSLea28uWguph8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; c=relaxed/simple; bh=IkMCCmmayPEOkLVBZv1cFnxPTwhINuoT5uWbQVxY0J8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LLqsotoiuzlcWC9WdY+AB+2WIQ6OeN3Y9Tedh6JkqjXlY7fsnNwpD75wqUDd0UQs3IdAiAevIucozUo7Pjb6b21Ye7XivzI6X2r21GVDclqIoNBYNXTNErOirndF+boVti6s6hmB0fwjY4DI1pZwj8t/oImLl5hscL28Fa/uduo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=mE/m/AwA; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mE/m/AwA" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AiTr0004338; Wed, 6 Nov 2024 19:34:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 8f3ltJ7kTNBqD63IJWPrINYxMdkP2wD5fAwRcNzFY10=; b=mE/m/AwAY7ahX25J SYvJOi25KyDSGQiru+E8SheQY2QexBCoY4CMYyiWSvS0LsHvbRIcsFkZM3uWso5+ mzBwJrgUTAHqiejNxurQbnTOZbw2uYzNm/UqS3KHs/vg08ieuN7CCrUCVwNZhyrw Ab6NgcqlSoK5mLTHFji1r0xEyY+6kqkHXJq0qNi9PVlOfrwUIDNVLaAO2weSr+nz n8IVW4HTHy3r6mrM2oswpFVQ8+SVnie29OuuBEyKbkFRo7wdRiUoMIoUU8xfLdW2 lCHkD2UNYi8qjkK74yHHCBml8SrlwjNY5Hp6oCDmoJtm4xwIAbHrgMAq+BniZ51/ jJKxmA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y93-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYXlg030265 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:32 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 14/30] ASoC: usb: Create SOC USB SND jack kcontrol Date: Wed, 6 Nov 2024 11:33:57 -0800 Message-ID: <20241106193413.1730413-15-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: B_tJ_c2LsOAHzVcUksBJry8vSWEa7RU3 X-Proofpoint-GUID: B_tJ_c2LsOAHzVcUksBJry8vSWEa7RU3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=913 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Expose API for creation of a jack control for notifying of available devices that are plugged in/discovered, and that support offloading. This allows for control names to be standardized across implementations of USB audio offloading. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 23 +++++++++++ sound/soc/soc-usb.c | 89 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index db9ff0b4191d..587ea07a8cf5 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -56,6 +56,12 @@ int snd_soc_usb_connect(struct device *usbdev, struct sn= d_soc_usb_device *sdev); int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_devic= e *sdev); void *snd_soc_usb_find_priv_data(struct device *usbdev); =20 +int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack); +int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component); +int snd_soc_usb_enable_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack); + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *co= mponent, void *data); void snd_soc_usb_free_port(struct snd_soc_usb *usb); @@ -86,6 +92,23 @@ static inline void *snd_soc_usb_find_priv_data(struct de= vice *usbdev) return NULL; } =20 +static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component = *component, + struct snd_soc_jack *jack) +{ + return 0; +} + +static inline int snd_soc_usb_disable_offload_jack(struct snd_soc_componen= t *component) +{ + return 0; +} + +static inline int snd_soc_usb_enable_offload_jack(struct snd_soc_component= *component, + struct snd_soc_jack *jack) +{ + return 0; +} + static inline struct snd_soc_usb * snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data) { diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index c63033468e4a..ab914878e101 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -4,7 +4,10 @@ */ #include #include + +#include #include + #include "../usb/card.h" =20 static DEFINE_MUTEX(ctx_mutex); @@ -56,6 +59,92 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct d= evice *dev) return ctx ? ctx : NULL; } =20 +/* SOC USB sound kcontrols */ +/** + * snd_soc_usb_setup_offload_jack() - Create USB offloading jack + * @component: USB DPCM backend DAI component + * @jack: jack structure to create + * + * Creates a jack device for notifying userspace of the availability + * of an offload capable device. + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +{ + int ret; + + ret =3D snd_soc_card_jack_new(component->card, "USB Offload Jack", + SND_JACK_USB, jack); + if (ret < 0) { + dev_err(component->card->dev, "Unable to add USB offload jack: %d\n", + ret); + return ret; + } + + ret =3D snd_soc_component_set_jack(component, jack, NULL); + if (ret) { + dev_err(component->card->dev, "Failed to set jack: %d\n", ret); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_setup_offload_jack); + +/** + * snd_soc_usb_disable_offload_jack() - Disables USB offloading jack + * @component: USB DPCM backend DAI component + * + * Disables the offload jack device, so that further connection events + * won't be notified. + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component) +{ + int ret; + + ret =3D snd_soc_component_set_jack(component, NULL, NULL); + if (ret) { + dev_err(component->card->dev, "Failed to disable jack: %d\n", ret); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_disable_offload_jack); + +/** + * snd_soc_usb_enable_offload_jack() - Enables USB offloading jack + * @component: USB DPCM backend DAI component + * @jack: offload jack to enable + * + * Enables the offload jack device, so that further connection events + * will be notified. This is the complement to + * snd_soc_usb_disable_offload_jack(). + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_enable_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +{ + int ret; + + ret =3D snd_soc_component_set_jack(component, jack, NULL); + if (ret) { + dev_err(component->card->dev, "Failed to enable jack: %d\n", ret); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_enable_offload_jack); + /** * snd_soc_usb_find_priv_data() - Retrieve private data stored * @usbdev: device reference From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53DA720969B; Wed, 6 Nov 2024 19:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921694; cv=none; b=mYujmr5OfIk+BLDME+3DcknqkvDO09mgWoqRvAkUBNgCtAyYQkVhGQyBbbf5Lys1y1+DXj6xYA2rRavFnrF40xFWoEJCDeeUS0+LawgICLNg/5oyr0aBGuiDjZ6Z9hu1O7eOZCAmKELxsQNjTnakYyF0jGUPeInSZot3IYFl86E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921694; c=relaxed/simple; bh=7x7bHut6vXqGEqUsc7FxVF/K8HdtteAuc38g9obK220=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A+6QAOQF+B4fkAnYA4FXtbHOzxmmxSh9hKA0nKKH7TwGLGUOcoDUxglITEfLarFu3xfaOU82Vd2m1yu9GZybx0NKAMs1ik/Esoa2aCxKvjHi4KcvNU/3nBS8PlwwC32+4Q7nzeBVrz8enEwt9SXlhhHyt6Kwy/DgiB+CcK59IJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=c1awKz5M; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="c1awKz5M" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A69plfn015613; Wed, 6 Nov 2024 19:34:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 5ZjvTDYWtRTttajXDi0kuopV3pbkb4YUrXwVSgs6C7Q=; b=c1awKz5Mp7DPfogH CYCYUfH1e6eqC551zUKUfzbiWjgyxf+4J4qrd42uB+lMCJYyNNlggYtebnjE1YDN zDMYvbOk4fkunoHpyeyQl2/QehsuB+xaLqgAhSTiq+ibIjZF/IWTUilbaW4m8aJ2 bm1QVxw7jQDa65X163HqrY56P0w6R6ZGx8YZNWnU53scBb713q/77wMjCBI0PsBd PX3CSrkJ2+xt4AdSUvmr/VEOJCXp+pAU8kSIfdyeOTuVhjz4cpoqJkUX4K98ivsH 0zJvSkCvBxdb81Trlf7MAAfXm+VbMZ7U8opizNgX5eI4v190XmB/achBHjTBZ9vz o0+NeQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42q5n8pp76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYXlh030265 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 15/30] ASoC: usb: Fetch ASoC card and pcm device information Date: Wed, 6 Nov 2024 11:33:58 -0800 Message-ID: <20241106193413.1730413-16-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: yB6Iecy_ZjYMZV-oDVGohcX0NpkGH4rO X-Proofpoint-ORIG-GUID: yB6Iecy_ZjYMZV-oDVGohcX0NpkGH4rO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 Content-Type: text/plain; charset="utf-8" USB SND needs to know how the USB offload path is being routed. This would allow for applications to open the corresponding sound card and pcm device when it wants to take the audio offload path. This callback should return the mapped indexes based on the USB SND device information. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 16 ++++++++++++++++ sound/soc/soc-usb.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 587ea07a8cf5..c3d3e8d62ac5 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -36,6 +36,11 @@ struct snd_soc_usb_device { * @list - list head for SND SOC struct list * @component - reference to ASoC component * @connection_status_cb - callback to notify connection events + * @update_offload_route_info - callback to fetch mapped ASoC card and pcm + * device pair. This is unrelated to the concept + * of DAPM route. The "route" argument carries + * an array used for a kcontrol output and should + * contain two integers, card and pcm device index * @priv_data - driver data **/ struct snd_soc_usb { @@ -44,6 +49,9 @@ struct snd_soc_usb { int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); + int (*update_offload_route_info)(struct snd_soc_component *component, + int card, int pcm, int direction, + long *route); void *priv_data; }; =20 @@ -61,6 +69,8 @@ int snd_soc_usb_setup_offload_jack(struct snd_soc_compone= nt *component, int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component); int snd_soc_usb_enable_offload_jack(struct snd_soc_component *component, struct snd_soc_jack *jack); +int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm, + int direction, long *route); =20 struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *co= mponent, void *data); @@ -109,6 +119,12 @@ static inline int snd_soc_usb_enable_offload_jack(stru= ct snd_soc_component *comp return 0; } =20 +static int snd_soc_usb_update_offload_route(struct device *dev, int card, = int pcm, + int direction, long *route) +{ + return -ENODEV; +} + static inline struct snd_soc_usb * snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data) { diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index ab914878e101..e56826f1df71 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -145,6 +145,40 @@ int snd_soc_usb_enable_offload_jack(struct snd_soc_com= ponent *component, } EXPORT_SYMBOL_GPL(snd_soc_usb_enable_offload_jack); =20 +/** + * snd_soc_usb_update_offload_route - Find active USB offload path + * @dev - USB device to get offload status + * @card - USB card index + * @pcm - USB PCM device index + * @direction - playback or capture direction + * @route - pointer to route output array + * + * Fetch the current status for the USB SND card and PCM device indexes + * specified. The "route" argument should be an array of integers being + * used for a kcontrol output. The first element should have the selected + * card index, and the second element should have the selected pcm device + * index. + */ +int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm, + int direction, long *route) +{ + struct snd_soc_usb *ctx; + int ret =3D -EINVAL; + + ctx =3D snd_soc_find_usb_ctx(dev); + if (!ctx) + return -ENODEV; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->update_offload_route_info) + ret =3D ctx->update_offload_route_info(ctx->component, card, pcm, + direction, route); + mutex_unlock(&ctx_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_update_offload_route); + /** * snd_soc_usb_find_priv_data() - Retrieve private data stored * @usbdev: device reference From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DBCD20EA5F; Wed, 6 Nov 2024 19:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921697; cv=none; b=Ga/b321gnBfo6iGPmQ4ve1LGi9uCWCqn5VHR6TUlbMRqZMMqcGWd7mmaS3Q1uedpsV39YpPoO1NTswLfOG5EuLlW5DauLp7gnTiO3IrYVDJIZERePHKghSQ7kxd5pdCFvfviXJY1MT64JbdTQto28820FCas9jXD4+tIyjr73C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921697; c=relaxed/simple; bh=SRJsVhulmlSq1Uzokh47KkyteTQIV5JP4y/QcmI6sk0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bPYiOvQo823LIZSXtxGVX8qfSx7QtAR1oN+y88MKfXp+dgipnA/H8wi5iFHriMeCQso9vinLfIY+qitzXI84K+W+dhs3vAvyByck8A6TfiE43VY8aVQA5a/UTxHzsCvteIVEqE8WLYy/6DFZxGssNNl418Y7QdSEijGWDMWmq8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Zz8agE8c; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Zz8agE8c" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AVE5v002942; Wed, 6 Nov 2024 19:34:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= N0C6moVkVDGYPQe6drSrN0mAgk6N09S7YyiwB3qU+YA=; b=Zz8agE8c2QJ397TT RVKXgmIo2qHtUPAJv+wLxm+3DwnsQQfph/DQ5anGmAjZvHfDrUvMY8royVhvTyMz MoRhm7lR6Wxm3owZfC+A8qjdWXHDPKBjqEoG68aa/ABys3mynpEgpPZ8RjSGq1Iw TB/9YbJhAqs5ouly2T24DSc8dT5lRBVMN7Jq8miU+cEiyE7Gem4mZZiVmMD3e9Bv Rj5YgOGiHZtMXg8JotzEJNJ1qRdmvHuLEy0C/kOhJ1OhQ3kiVDBQRXM3lLFUDWVV YLyADF8B6KAfYcbp0EZU1qh5Iigu5yS5iWPuBtYkIf5faN4e2Q6xoYTtdzSZb0O5 9FwFaQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYXSI027644 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 16/30] ASoC: doc: Add documentation for SOC USB Date: Wed, 6 Nov 2024 11:33:59 -0800 Message-ID: <20241106193413.1730413-17-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 2GMqb-wbJ-aphP3ZYnFiWLpRADipPyFL X-Proofpoint-GUID: 2GMqb-wbJ-aphP3ZYnFiWLpRADipPyFL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" With the introduction of the soc-usb driver, add documentation highlighting details on how to utilize the new driver and how it interacts with different components in USB SND and ASoC. It provides examples on how to implement the drivers that will need to be introduced in order to enable USB audio offloading. Signed-off-by: Wesley Cheng --- Documentation/sound/soc/index.rst | 1 + Documentation/sound/soc/usb.rst | 491 ++++++++++++++++++++++++++++++ 2 files changed, 492 insertions(+) create mode 100644 Documentation/sound/soc/usb.rst diff --git a/Documentation/sound/soc/index.rst b/Documentation/sound/soc/in= dex.rst index e57df2dab2fd..8bed8f8f48da 100644 --- a/Documentation/sound/soc/index.rst +++ b/Documentation/sound/soc/index.rst @@ -18,3 +18,4 @@ The documentation is spilt into the following sections:- jack dpcm codec-to-codec + usb diff --git a/Documentation/sound/soc/usb.rst b/Documentation/sound/soc/usb.= rst new file mode 100644 index 000000000000..3a8c69050886 --- /dev/null +++ b/Documentation/sound/soc/usb.rst @@ -0,0 +1,491 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +ASoC USB support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D +In order to leverage the existing USB sound device support in ALSA, the +ASoC USB APIs are introduced to allow the subsystems to exchange +configuration information. + +One potential use case would be to support USB audio offloading, which is +an implementation that allows for an alternate power-optimized path in the= audio +subsystem to handle the transfer of audio data over the USB bus. This wou= ld +let the main processor to stay in lower power modes for longer duration. = The +following is an example design of how the ASoC and ALSA pieces can be conn= ected +together to achieve this: + +:: + + USB | ASoC + | _________________________ + | | ASoC Platform card | + | |_________________________| + | | | + | ___V____ ____V____ + | |ASoC BE | |ASoC FE | + | |DAI LNK | |DAI LNK | + | |________| |_________| + | ^ ^ ^ + | | |________| + | ___V____ | + | |SOC-USB | | + ________ ________ | | | + |USB SND |<--->|USBSND |<------------>|________| | + |(card.c)| |offld |<---------- | + |________| |________|___ | | | + ^ ^ | | | ____________V_________ + | | | | | |IPC | + __ V_______________V_____ | | | |______________________| + |USB SND (endpoint.c) | | | | ^ + |_________________________| | | | | + ^ | | | ___________V___________ + | | | |->|audio DSP | + ___________V_____________ | | |_______________________| + |XHCI HCD |<- | + |_________________________| | + + +SOC USB driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Structures +---------- +``struct snd_soc_usb`` + + - ``list``: list head for SND SOC struct list + - ``component``: reference to ASoC component + - ``connection_status_cb``: callback to notify connection events + - ``update_offload_route_info``: callback to fetch selected USB sound ca= rd/PCM + device + - ``priv_data``: driver data + +The snd_soc_usb structure can be referenced using the ASoC platform card +device, or a USB device (udev->dev). This is created by the ASoC BE DAI +link, and the USB sound entity will be able to pass information to the +ASoC BE DAI link using this structure. + +``struct snd_soc_usb_device`` + + - ``card_idx``: sound card index associated with USB sound device + - ``chip_idx``: USB sound chip array index + - ``cpcm_idx``: capture pcm device indexes associated with the USB sound= device + - ``ppcm_idx``: playback pcm device indexes associated with the USB soun= d device + - ``num_playback``: number of playback streams + - ``num_capture``: number of capture streams + - ``list``: list head for the USB sound device list + +The struct snd_soc_usb_device is created by the USB sound offload driver. +This will carry basic parameters/limitations that will be used to +determine the possible offloading paths for this USB audio device. + +Functions +--------- +.. code-block:: rst + + int snd_soc_usb_find_supported_format(int card_idx, + struct snd_pcm_hw_params *params, int direction) +.. + + - ``card_idx``: the index into the USB sound chip array. + - ``params``: Requested PCM parameters from the USB DPCM BE DAI link + - ``direction``: capture or playback + +**snd_soc_usb_find_supported_format()** ensures that the requested audio p= rofile +being requested by the external DSP is supported by the USB device. + +Returns 0 on success, and -EOPNOTSUPP on failure. + +.. code-block:: rst + + int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device = *sdev) +.. + + - ``usbdev``: the usb device that was discovered + - ``sdev``: capabilities of the device + +**snd_soc_usb_connect()** notifies the ASoC USB DCPM BE DAI link of a USB +audio device detection. This can be utilized in the BE DAI +driver to keep track of available USB audio devices. This is intended +to be called by the USB offload driver residing in USB SND. + +Returns 0 on success, negative error code on failure. + +.. code-block:: rst + + int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_devi= ce *sdev) +.. + + - ``usbdev``: the usb device that was removed + - ``sdev``: capabilities to free + +**snd_soc_usb_disconnect()** notifies the ASoC USB DCPM BE DAI link of a U= SB +audio device removal. This is intended to be called by the USB offload +driver that resides in USB SND. + +.. code-block:: rst + + void *snd_soc_usb_find_priv_data(struct device *usbdev) +.. + + - ``usbdev``: the usb device to reference to find private data + +**snd_soc_usb_find_priv_data()** fetches the private data saved to the SOC= USB +device. + +Returns pointer to priv_data on success, NULL on failure. + +.. code-block:: rst + + int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +.. + + - ``component``: ASoC component to add the jack + - ``jack``: jack component to populate + +**snd_soc_usb_setup_offload_jack()** is a helper to add a sound jack contr= ol to +the platform sound card. This will allow for consistent naming to be used= on +designs that support USB audio offloading. Additionally, this will enable= the +jack to notify of changes. + +Returns 0 on success, negative otherwise. + +.. code-block:: rst + + int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component) +.. + + - ``component``: ASoC component to disable the jack + +**snd_soc_usb_disable_offload_jack()** is a helper to disable a sound jack= control +on the platform sound card. + +Returns 0 on success, negative otherwise. + +.. code-block:: rst + + int snd_soc_usb_enable_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +.. + + - ``component``: ASoC component to enable the jack + - ``jack``: jack component to populate + +**snd_soc_usb_enable_offload_jack()** is the opposing function to the disa= ble jack +API. (**snd_soc_usb_disable_offload_jack()**) This will re-enable a speci= fied +jack to start generating events for changes occurring on the USB port. + +Returns 0 on success, negative otherwise. + +.. code-block:: rst + + int snd_soc_usb_update_offload_route(struct device *dev, int card, int pc= m, + int direction, long *route) +.. + + - ``dev``: USB device to look up offload path mapping + - ``card``: USB sound card index + - ``pcm``: USB sound PCM device index + - ``direction``: direction to fetch offload routing information + - ``route``: mapping of sound card and pcm indexes for the offload path.= This is + an array of two integers that will carry the card and pcm device i= ndexes + in that specific order. This can be used as the array for the kco= ntrol + output. + +**snd_soc_usb_update_offload_route()** calls a registered callback to the = USB BE DAI +link to fetch the information about the mapped ASoC devices for executing = USB audio +offload for the device. ``route`` may be a pointer to a kcontrol value out= put array, +which carries values when the kcontrol is read. + +Returns 0 on success, negative otherwise. + +.. code-block:: rst + + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *c= omponent, + void *data); +.. + + - ``component``: DPCM BE DAI link component + - ``data``: private data + +**snd_soc_usb_allocate_port()** allocates a SOC USB device and populates s= tandard +parameters that is used for further operations. + +Returns a pointer to struct soc_usb on success, negative on error. + +.. code-block:: rst + + void snd_soc_usb_free_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to free + +**snd_soc_usb_free_port()** frees a SOC USB device. + +.. code-block:: rst + + void snd_soc_usb_add_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to add + +**snd_soc_usb_add_port()** add an allocated SOC USB device to the SOC USB = framework. +Once added, this device can be referenced by further operations. + +.. code-block:: rst + + void snd_soc_usb_remove_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to remove + +**snd_soc_usb_remove_port()** removes a SOC USB device from the SOC USB fr= amework. +After removing a device, any SOC USB operations would not be able to refer= ence the +device removed. + +How to Register to SOC USB +-------------------------- +The ASoC DPCM USB BE DAI link is the entity responsible for allocating and +registering the SOC USB device on the component bind. Likewise, it will +also be responsible for freeing the allocated resources. An example can +be shown below: + +.. code-block:: rst + + static int q6usb_component_probe(struct snd_soc_component *component) + { + ... + data->usb =3D snd_soc_usb_allocate_port(component, 1, &data->priv); + if (!data->usb) + return -ENOMEM; + + usb->connection_status_cb =3D q6usb_alsa_connection_cb; + + ret =3D snd_soc_usb_add_port(usb); + if (ret < 0) { + dev_err(component->dev, "failed to add usb port\n"); + goto free_usb; + } + ... + } + + static void q6usb_component_remove(struct snd_soc_component *component) + { + ... + snd_soc_usb_remove_port(data->usb); + snd_soc_usb_free_port(data->usb); + } + + static const struct snd_soc_component_driver q6usb_dai_component =3D { + .probe =3D q6usb_component_probe, + .remove =3D q6usb_component_remove, + .name =3D "q6usb-dai-component", + ... + }; +.. + +BE DAI links can pass along vendor specific information as part of the +call to allocate the SOC USB device. This will allow any BE DAI link +parameters or settings to be accessed by the USB offload driver that +resides in USB SND. + +USB Audio Device Connection Flow +-------------------------------- +USB devices can be hotplugged into the USB ports at any point in time. +The BE DAI link should be aware of the current state of the physical USB +port, i.e. if there are any USB devices with audio interface(s) connected. +connection_status_cb() can be used to notify the BE DAI link of any change. + +This is called whenever there is a USB SND interface bind or remove event, +using snd_soc_usb_connect() or snd_soc_usb_disconnect(): + +.. code-block:: rst + + static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) + { + ... + snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + ... + } + + static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip) + { + ... + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + ... + } +.. + +In order to account for conditions where driver or device existence is +not guaranteed, USB SND exposes snd_usb_rediscover_devices() to resend the +connect events for any identified USB audio interfaces. Consider the +the following situation: + + **usb_audio_probe()** + | --> USB audio streams allocated and saved to usb_chip[] + | --> Propagate connect event to USB offload driver in USB SND + | --> **snd_soc_usb_connect()** exits as USB BE DAI link is not ready + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> The USB audio device connect event is missed + +To ensure connection events are not missed, **snd_usb_rediscover_devices()= ** +is executed when the SOC USB device is registered. Now, when the BE DAI +link component probe occurs, the following highlights the sequence: + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> SOC USB device added, and **snd_usb_rediscover_devices()** runs + + **snd_usb_rediscover_devices()** + | --> Traverses through usb_chip[] and for non-NULL entries issue + | **connection_status_cb()** + +In the case where the USB offload driver is unbound, while USB SND is read= y, +the **snd_usb_rediscover_devices()** is called during module init. This a= llows +for the offloading path to also be enabled with the following flow: + + **usb_audio_probe()** + | --> USB audio streams allocated and saved to usb_chip[] + | --> Propagate connect event to USB offload driver in USB SND + | --> USB offload driver **NOT** ready! + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> No USB connect event due to missing USB offload driver + + USB offload driver probe + | --> **qc_usb_audio_offload_init()** + | --> Calls **snd_usb_rediscover_devices()** to notify of devices + +USB Offload Related Kcontrols +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +Details +------- +A set of kcontrols can be utilized by applications to help select the prop= er sound +devices to enable USB audio offloading. SOC USB exposes the get_offload_d= ev() +callback that designs can use to ensure that the proper indices are return= ed to the +application. + +Implementation +-------------- + +**Example:** + + **Sound Cards**: + + :: + + 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [Seri ]: USB-Audio - Plantronics Blackwire 3225 Seri + Plantronics Plantronics Blackwire + 3225 Seri at usb-xhci-hcd.1.auto-1.1, + full sp + 2 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.aut= o-1.2, full speed + + **PCM Devices**: + + :: + + card 0: SM8250MTPWCD938 [SM8250-MTP-WCD9380-WSA8810-VA-D], device 0: Mu= ltiMedia1 (*) [] + Subdevices: 1/1 + Subdevice #0: subdevice #0 + card 0: SM8250MTPWCD938 [SM8250-MTP-WCD9380-WSA8810-VA-D], device 1: Mu= ltiMedia2 (*) [] + Subdevices: 1/1 + Subdevice #0: subdevice #0 + card 1: Seri [Plantronics Blackwire 3225 Seri], device 0: USB Audio [US= B Audio] + Subdevices: 1/1 + Subdevice #0: subdevice #0 + card 2: C320M [Plantronics C320-M], device 0: USB Audio [USB Audio] + Subdevices: 1/1 + Subdevice #0: subdevice #0 + + **USB Sound Card** - card#1: + + :: + + USB Offload Playback Route PCM#0 -1, -1 (range -1->255) + + **USB Sound Card** - card#2: + + :: + + USB Offload Playback Route PCM#0 0, 1 (range -1->255) + +The above example shows a scenario where the system has one ASoC platform = card +(card#0) and two USB sound devices connected (card#1 and card#2). When re= ading +the available kcontrols for each USB audio device, the following kcontrol = lists +the mapped offload path for the specific device: + + ``USB Offload Playback Route#*`` + +The kcontrol is indexed, because a USB audio device could potentially have +several PCM devices. The above kcontrols are defined as: + + - ``USB Offload Playback Route PCM`` **(R)**: Returns the ASoC platform = sound + card and PCM device index. The output **"0, 1"** (card index, PCM dev= ice index) + signifies that there is an available offload path for the USB SND devi= ce + through card#0 - PCM device#1. If **"-1, -1"** is seen, then no offlo= ad path is + available for the USB SND device. This kcontrol exists for each USB a= udio + device that exists in the system, and its expected to derive the curre= nt status + of offload based on the output value for the kcontrol. + +USB Offload Playback Route Kcontrol +----------------------------------- +In order to allow for vendor specific implementations on audio offloading = device +selection, the SOC USB layer exposes the following: + +.. code-block:: rst + + int (*update_offload_route_info)(struct snd_soc_component *component, + int card, int pcm, long *route); +.. + +These are specific for the **USB Offload Playback Route PCM#** kcontrol. + +When users issue get calls to the kcontrol, the registered SOC USB callbac= ks will +execute the registered function calls to the DPCM BE DAI link. + +**Callback Registration:** + +.. code-block:: rst + + static int q6usb_component_probe(struct snd_soc_component *component) + { + ... + usb =3D snd_soc_usb_allocate_port(component, 1, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb =3D q6usb_alsa_connection_cb; + usb->update_offload_route_info =3D q6usb_get_offload_dev; + + ret =3D snd_soc_usb_add_port(usb); +.. + +Existing USB Sound Kcontrol +--------------------------- +With the introduction of USB offload support, the above USB offload kcontr= ol +will be added to the pre existing list of kcontrols identified by the USB = sound +framework. These kcontrols are still the main controls that are used to +modify characteristics pertaining to the USB audio device. + + :: + + Number of controls: 9 + ctl type num name value + 0 INT 2 Capture Channel Map 0, 0 (r= ange 0->36) + 1 INT 2 Playback Channel Map 0, 0 (r= ange 0->36) + 2 BOOL 1 Headset Capture Switch On + 3 INT 1 Headset Capture Volume 10 (ran= ge 0->13) + 4 BOOL 1 Sidetone Playback Switch On + 5 INT 1 Sidetone Playback Volume 4096 (r= ange 0->8192) + 6 BOOL 1 Headset Playback Switch On + 7 INT 2 Headset Playback Volume 20, 20 = (range 0->24) + 8 INT 2 USB Offload Playback Route PCM#0 -1, -1 = (range -1->255) + +Since USB audio device controls are handled over the USB control endpoint,= use the +existing mechanisms present in the USB mixer to set parameters, such as vo= lume. From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF6BA20D4F6; Wed, 6 Nov 2024 19:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921692; cv=none; b=JHSnzudQMdz9qB6X4mCgOX73oT6lREXY4Vay3LaCIgLmbzN5KXMJMQZKXNy1rEETvtEovkOSByhmWIw9G1PcKsty3ShaBurlRgd3F5QNo8lsppBMTpKMG5lO/KiNeMOfyEitcTjYhUQ5nfU978gS06nHd89A9x8HfIJLt1dmqGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921692; c=relaxed/simple; bh=2TQXo2YMYhg/mBJxKuqafaOEZef1g+SCKODQN1pqdkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f4Tq0V3QnNtcMXUWdsoGJU0b/ZVRD7tyaJFKpemt6UjWixLsJJZ+OwSLCru/fdPPD5m7LpbCKQr7IYPTjTDPsAsFD7Nsy6XKYwJGw3aXxZQ7pByJ/Sbdec6DFZQ7RnPoI9EJmMUKsYIENUyaBF1Jq4bsWVsvcRp08XgtBsNc7c4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=f5zgbt4j; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="f5zgbt4j" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A69rnGE003788; Wed, 6 Nov 2024 19:34:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /ZM8SPXr7udKkYr/SDUmnoP1IOgbHf5SfkdSPWJ27XA=; b=f5zgbt4j0YoMg3sj 5WC5pfipMyBGdC1NIbf+FdAEAiFUXv+jXYj+94+PGU3V4jtqwlF01L0NQXwjYJqp 5wrGuoACsKbaBnltOpG8kApVsTFoGjBnXDPA5wiezHZ0ln+mYZjkQcAPpSzyR2B9 jx9exypQJokL94EpNTkpZTZL31e+Bj8ZqRPP0GydJCocbyvfSJ70o0vt5VKCMB91 6u2hrvYG7vScDwdmSJs+FQ7bgqnhivRjfF77rvwitQ2wPeSfKD9q/8M8H/U9gHqg v4+kI8XBg3TD+6jDMW4VsZ6s0xsktOoarK6SDeycVE7//tm5vXIp++blmp7nPO6X Af40OA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qhbucyf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYY4M030277 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng , Krzysztof Kozlowski Subject: [PATCH v30 17/30] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Date: Wed, 6 Nov 2024 11:34:00 -0800 Message-ID: <20241106193413.1730413-18-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 6KdarNeBd1FI9OzIDWzf8KYXHk_S3UKx X-Proofpoint-GUID: 6KdarNeBd1FI9OzIDWzf8KYXHk_S3UKx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=898 clxscore=1015 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Q6DSP supports handling of USB playback audio data if USB audio offloading is enabled. Add a new definition for the USB_RX AFE port, which is referenced when the AFE port is started. Acked-by: Krzysztof Kozlowski Signed-off-by: Wesley Cheng --- include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h b/include/d= t-bindings/sound/qcom,q6dsp-lpass-ports.h index 39f203256c4f..6d1ce7f5da51 100644 --- a/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h +++ b/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h @@ -139,6 +139,7 @@ #define DISPLAY_PORT_RX_5 133 #define DISPLAY_PORT_RX_6 134 #define DISPLAY_PORT_RX_7 135 +#define USB_RX 136 =20 #define LPASS_CLK_ID_PRI_MI2S_IBIT 1 #define LPASS_CLK_ID_PRI_MI2S_EBIT 2 From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FC6920F5D2; Wed, 6 Nov 2024 19:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; cv=none; b=bsmfK/Bb5JZVk/KNaOVTt8/2DKphBjUW946TFu1kTX0VRArNOoAINU/odWYzU0QRBOPL/ozd1VBNXCpxqd0J4++R7+uAJ49zU1f7m6/YfjNno/I5Y3ewWQfIwZ6f1VfOGg6tdULhOrfN2rZsYAICb5uIPKhzRwUcKG2IsftIB1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; c=relaxed/simple; bh=+NaBd4qh6Tx23KLTq1Tx6jXdHAVdB+MtbWzs+WWGYU4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U6Y39Lu41JuSLnRb8VNJIqsmZl9OWRf+6C+7WYrrOQkglkiYbY3Q0TfhS3NsUro/j3kHnMF2g2FOe2Xzr8eAJ/nFt/jB5R5Ekp56qN+X5OXiz+LIhoBTmZDYM3qxNinJmvHNWh/9rbc+C6n8DrRjKaeLfhsv96inbB2lBk4PzD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=mD/dh1VR; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mD/dh1VR" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6Fxi4s024363; Wed, 6 Nov 2024 19:34:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= kfXkbu7AG3+ERegbUk/pmHNUqLGl/5fxnXQNUoDs2Rw=; b=mD/dh1VR20qy4zoL u045tYp5AJjzehs2AeMWlvpWP4+buUxjBVAna2cKRPyDZGgUQm1OS+yXKZXx4r5d pBWAlwRmw0aqwzpTTHTUsfji0xDqKZkh7lM3bfoF5VhgWKZOYDS03DxCQo1l/220 3fFh+DfMfLrk/x4OgnbsOz7hakeHstzVTXgVKcVXDm4uf4JUsTS8EsPu29BsbGaE 8g/Uy3+b0epo4IXK9znraQecJbpo1VIKw2d0flNW1lr/WlTjKmPVYrssRUmDf8iY gwCfjvAz76V2xbbnO9Ifax43FQlL4oc+epSiDwhaVD0MFvl3U2zzAkhFxjyCr0KQ 2fhpxg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r2ugt506-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYYNY027647 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 18/30] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Date: Wed, 6 Nov 2024 11:34:01 -0800 Message-ID: <20241106193413.1730413-19-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: RNlal8OZULqSPKF17COrKKton9zTssoo X-Proofpoint-GUID: RNlal8OZULqSPKF17COrKKton9zTssoo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Add an example on enabling of USB offload for the Q6DSP. The routing can be done by the mixer, which can pass the multimedia stream to the USB backend. Acked-by: Rob Herring Signed-off-by: Wesley Cheng --- .../devicetree/bindings/sound/qcom,sm8250.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml b/Doc= umentation/devicetree/bindings/sound/qcom,sm8250.yaml index 2e2e01493a5f..884244b6b342 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -189,4 +189,19 @@ examples: sound-dai =3D <&vamacro 0>; }; }; + + usb-dai-link { + link-name =3D "USB Playback"; + cpu { + sound-dai =3D <&q6afedai USB_RX>; + }; + + codec { + sound-dai =3D <&usbdai USB_RX>; + }; + + platform { + sound-dai =3D <&q6routing>; + }; + }; }; From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B90142101AE; Wed, 6 Nov 2024 19:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921700; cv=none; b=BIh5JPBNiWFRtprJphtWu0bLBYABg5wS1nHpy9mQ7shr7OIndRzBWl2bLJ3HMOfuynFfIM66bq187HweInLnEe7wRYXpYa/n+HcKQjO5bt7kftMZxFOrj2GN7B1HICdF24e+x8egyIp04Lfsk9qXEYxvsQYKqDchjPm6V0tb4Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921700; c=relaxed/simple; bh=L5etctbO75cwdCsl3AHqW6k00jR/pVwEBUK9Oe96Kmk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GP4WRlj4DCeUnx7q578KcJU0iYPxqDXww9fvKDPCK1JTBHtoRIocsfP1yIRFeAq/yMk/556ySnBsp1FnDaZhnTzILNH0MkiU+1aGqHCAZF0cHMvJzXOanv3Xugsl+wxgv0RVLfQ0p5irHTcLkDaF3fCUiGFL+Ejwo08nHCbIJLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=WEX6tUhl; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="WEX6tUhl" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6D8PWg023163; Wed, 6 Nov 2024 19:34:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 2xPv35zcaoDECAedUJE8NHILlNszLAqR5yUl4Gzdy/I=; b=WEX6tUhlA5OOVZY6 59xaD/wR/FOqYu4UifUuj6jSaWXlinSNoQgU8vMfYW/kL8NbOJS3AuCLhSwO2PH6 XdfsoT841O0liY79hcP9B721YjQc0b5DMydKgVSFzAWlf2YueY5z2cH/LKTdND06 8reBO2NNe9pIJTPpdml+dBW02xUi6nYObWCncQ0r0t8GuPtHtqRudbz8I5B7AuKF ivOgofM9YzuFly1RAcfl5bfup9dkhqRqtBuwGcMAio6gJqCWdfAnRJ05EEaXekWz oxSU1ZkM0ghuAjvNuSwnhLtxD+bqs0sxynsT4U6xOZFgBjVpsacLqhSXuN4fx9d+ fnvBgg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r07hjg97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYYM4008664 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 19/30] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Date: Wed, 6 Nov 2024 11:34:02 -0800 Message-ID: <20241106193413.1730413-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vOGp6jlKxqV6ZD9ZiirI4q8FX9MzOcUG X-Proofpoint-ORIG-GUID: vOGp6jlKxqV6ZD9ZiirI4q8FX9MzOcUG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" The QC ADSP is able to support USB playback endpoints, so that the main application processor can be placed into lower CPU power modes. This adds the required AFE port configurations and port start command to start an audio session. Specifically, the QC ADSP can support all potential endpoints that are exposed by the audio data interface. This includes isochronous data endpoints, in either synchronous mode or asynchronous mode. In the latter case both implicit or explicit feedback endpoints are supported. The size of audio samples sent per USB frame (microframe) will be adjusted based on information received on the feedback endpoint. Some pre-requisites are needed before issuing the AFE port start command, such as setting the USB AFE dev_token. This carries information about the available USB SND cards and PCM devices that have been discovered on the USB bus. The dev_token field is used by the audio DSP to notify the USB offload driver of which card and PCM index to enable playback on. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6afe-dai.c | 60 +++++++ sound/soc/qcom/qdsp6/q6afe.c | 192 ++++++++++++++++++++++- sound/soc/qcom/qdsp6/q6afe.h | 36 ++++- sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c | 23 +++ sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h | 1 + sound/soc/qcom/qdsp6/q6routing.c | 32 +++- 6 files changed, 341 insertions(+), 3 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-= dai.c index 7d9628cda875..0f47aadaabe1 100644 --- a/sound/soc/qcom/qdsp6/q6afe-dai.c +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c @@ -92,6 +92,39 @@ static int q6hdmi_hw_params(struct snd_pcm_substream *su= bstream, return 0; } =20 +static int q6afe_usb_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6afe_dai_data *dai_data =3D dev_get_drvdata(dai->dev); + int channels =3D params_channels(params); + int rate =3D params_rate(params); + struct q6afe_usb_cfg *usb =3D &dai_data->port_config[dai->id].usb_audio; + + usb->sample_rate =3D rate; + usb->num_channels =3D channels; + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_U16_LE: + case SNDRV_PCM_FORMAT_S16_LE: + usb->bit_width =3D 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + case SNDRV_PCM_FORMAT_S24_3LE: + usb->bit_width =3D 24; + break; + case SNDRV_PCM_FORMAT_S32_LE: + usb->bit_width =3D 32; + break; + default: + dev_err(dai->dev, "%s: invalid format %d\n", + __func__, params_format(params)); + return -EINVAL; + } + + return 0; +} + static int q6i2s_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -394,6 +427,10 @@ static int q6afe_dai_prepare(struct snd_pcm_substream = *substream, q6afe_cdc_dma_port_prepare(dai_data->port[dai->id], &dai_data->port_config[dai->id].dma_cfg); break; + case USB_RX: + q6afe_usb_port_prepare(dai_data->port[dai->id], + &dai_data->port_config[dai->id].usb_audio); + break; default: return -EINVAL; } @@ -622,6 +659,9 @@ static const struct snd_soc_dapm_route q6afe_dapm_route= s[] =3D { {"TX_CODEC_DMA_TX_5", NULL, "TX_CODEC_DMA_TX_5 Capture"}, {"RX_CODEC_DMA_RX_6 Playback", NULL, "RX_CODEC_DMA_RX_6"}, {"RX_CODEC_DMA_RX_7 Playback", NULL, "RX_CODEC_DMA_RX_7"}, + + /* USB playback AFE port receives data for playback, hence use the RX por= t */ + {"USB Playback", NULL, "USB_RX"}, }; =20 static int msm_dai_q6_dai_probe(struct snd_soc_dai *dai) @@ -649,6 +689,23 @@ static int msm_dai_q6_dai_remove(struct snd_soc_dai *d= ai) return 0; } =20 +static const struct snd_soc_dai_ops q6afe_usb_ops =3D { + .probe =3D msm_dai_q6_dai_probe, + .prepare =3D q6afe_dai_prepare, + .hw_params =3D q6afe_usb_hw_params, + /* + * Shutdown callback required to stop the USB AFE port, which is enabled + * by the prepare() stage. This stops the audio traffic on the USB AFE + * port on the Q6DSP. + */ + .shutdown =3D q6afe_dai_shutdown, + /* + * Startup callback not needed, as AFE port start command passes the PCM + * parameters within the AFE command, which is provided by the PCM core + * during the prepare() stage. + */ +}; + static const struct snd_soc_dai_ops q6hdmi_ops =3D { .probe =3D msm_dai_q6_dai_probe, .remove =3D msm_dai_q6_dai_remove, @@ -947,6 +1004,8 @@ static const struct snd_soc_dapm_widget q6afe_dai_widg= ets[] =3D { 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_IN("RX_CODEC_DMA_RX_7", "NULL", 0, SND_SOC_NOPM, 0, 0), + + SND_SOC_DAPM_AIF_IN("USB_RX", NULL, 0, SND_SOC_NOPM, 0, 0), }; =20 static const struct snd_soc_component_driver q6afe_dai_component =3D { @@ -1061,6 +1120,7 @@ static int q6afe_dai_dev_probe(struct platform_device= *pdev) cfg.q6i2s_ops =3D &q6i2s_ops; cfg.q6tdm_ops =3D &q6tdm_ops; cfg.q6dma_ops =3D &q6dma_ops; + cfg.q6usb_ops =3D &q6afe_usb_ops; dais =3D q6dsp_audio_ports_set_config(dev, &cfg, &num_dais); =20 return devm_snd_soc_register_component(dev, &q6afe_dai_component, dais, n= um_dais); diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index ef7557be5d66..3ee6ff8a6bc3 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -35,6 +35,8 @@ #define AFE_MODULE_TDM 0x0001028A =20 #define AFE_PARAM_ID_CDC_SLIMBUS_SLAVE_CFG 0x00010235 +#define AFE_PARAM_ID_USB_AUDIO_DEV_PARAMS 0x000102A5 +#define AFE_PARAM_ID_USB_AUDIO_DEV_LPCM_FMT 0x000102AA =20 #define AFE_PARAM_ID_LPAIF_CLK_CONFIG 0x00010238 #define AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG 0x00010239 @@ -44,6 +46,7 @@ #define AFE_PARAM_ID_TDM_CONFIG 0x0001029D #define AFE_PARAM_ID_PORT_SLOT_MAPPING_CONFIG 0x00010297 #define AFE_PARAM_ID_CODEC_DMA_CONFIG 0x000102B8 +#define AFE_PARAM_ID_USB_AUDIO_CONFIG 0x000102A4 #define AFE_CMD_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f4 #define AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f5 #define AFE_CMD_REMOTE_LPASS_CORE_HW_DEVOTE_REQUEST 0x000100f6 @@ -72,12 +75,16 @@ #define AFE_PORT_CONFIG_I2S_WS_SRC_INTERNAL 0x1 #define AFE_LINEAR_PCM_DATA 0x0 =20 +#define AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG 0x1 =20 /* Port IDs */ #define AFE_API_VERSION_HDMI_CONFIG 0x1 #define AFE_PORT_ID_MULTICHAN_HDMI_RX 0x100E #define AFE_PORT_ID_HDMI_OVER_DP_RX 0x6020 =20 +/* USB AFE port */ +#define AFE_PORT_ID_USB_RX 0x7000 + #define AFE_API_VERSION_SLIMBUS_CONFIG 0x1 /* Clock set API version */ #define AFE_API_VERSION_CLOCK_SET 1 @@ -513,12 +520,96 @@ struct afe_param_id_cdc_dma_cfg { u16 active_channels_mask; } __packed; =20 +struct afe_param_id_usb_cfg { +/* Minor version used for tracking USB audio device configuration. + * Supported values: AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + */ + u32 cfg_minor_version; +/* Sampling rate of the port. + * Supported values: + * - AFE_PORT_SAMPLE_RATE_8K + * - AFE_PORT_SAMPLE_RATE_11025 + * - AFE_PORT_SAMPLE_RATE_12K + * - AFE_PORT_SAMPLE_RATE_16K + * - AFE_PORT_SAMPLE_RATE_22050 + * - AFE_PORT_SAMPLE_RATE_24K + * - AFE_PORT_SAMPLE_RATE_32K + * - AFE_PORT_SAMPLE_RATE_44P1K + * - AFE_PORT_SAMPLE_RATE_48K + * - AFE_PORT_SAMPLE_RATE_96K + * - AFE_PORT_SAMPLE_RATE_192K + */ + u32 sample_rate; +/* Bit width of the sample. + * Supported values: 16, 24 + */ + u16 bit_width; +/* Number of channels. + * Supported values: 1 and 2 + */ + u16 num_channels; +/* Data format supported by the USB. The supported value is + * 0 (#AFE_USB_AUDIO_DATA_FORMAT_LINEAR_PCM). + */ + u16 data_format; +/* this field must be 0 */ + u16 reserved; +/* device token of actual end USB audio device */ + u32 dev_token; +/* endianness of this interface */ + u32 endian; +/* service interval */ + u32 service_interval; +} __packed; + +/** + * struct afe_param_id_usb_audio_dev_params + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @dev_token: device token of actual end USB audio device + **/ +struct afe_param_id_usb_audio_dev_params { + u32 cfg_minor_version; + u32 dev_token; +} __packed; + +/** + * struct afe_param_id_usb_audio_dev_lpcm_fmt + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @endian: endianness of this interface + **/ +struct afe_param_id_usb_audio_dev_lpcm_fmt { + u32 cfg_minor_version; + u32 endian; +} __packed; + +#define AFE_PARAM_ID_USB_AUDIO_SVC_INTERVAL 0x000102B7 + +/** + * struct afe_param_id_usb_audio_svc_interval + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @svc_interval: service interval + **/ +struct afe_param_id_usb_audio_svc_interval { + u32 cfg_minor_version; + u32 svc_interval; +} __packed; + union afe_port_config { struct afe_param_id_hdmi_multi_chan_audio_cfg hdmi_multi_ch; struct afe_param_id_slimbus_cfg slim_cfg; struct afe_param_id_i2s_cfg i2s_cfg; struct afe_param_id_tdm_cfg tdm_cfg; struct afe_param_id_cdc_dma_cfg dma_cfg; + struct afe_param_id_usb_cfg usb_cfg; } __packed; =20 =20 @@ -833,6 +924,7 @@ static struct afe_port_map port_maps[AFE_PORT_MAX] =3D { RX_CODEC_DMA_RX_6, 1, 1}, [RX_CODEC_DMA_RX_7] =3D { AFE_PORT_ID_RX_CODEC_DMA_RX_7, RX_CODEC_DMA_RX_7, 1, 1}, + [USB_RX] =3D { AFE_PORT_ID_USB_RX, USB_RX, 1, 1}, }; =20 static void q6afe_port_free(struct kref *ref) @@ -1290,6 +1382,101 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, } EXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare); =20 +/** + * afe_port_send_usb_dev_param() - Send USB dev token + * + * @port: Instance of afe port + * @cardidx: USB SND card index to reference + * @pcmidx: USB SND PCM device index to reference + * + * The USB dev token carries information about which USB SND card instance= and + * PCM device to execute the offload on. This information is carried thro= ugh + * to the stream enable QMI request, which is handled by the offload class + * driver. The information is parsed to determine which USB device to que= ry + * the required resources for. + */ +int afe_port_send_usb_dev_param(struct q6afe_port *port, int cardidx, int = pcmidx) +{ + struct afe_param_id_usb_audio_dev_params usb_dev; + int ret; + + memset(&usb_dev, 0, sizeof(usb_dev)); + + usb_dev.cfg_minor_version =3D AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + usb_dev.dev_token =3D (cardidx << 16) | (pcmidx << 8); + ret =3D q6afe_port_set_param_v2(port, &usb_dev, + AFE_PARAM_ID_USB_AUDIO_DEV_PARAMS, + AFE_MODULE_AUDIO_DEV_INTERFACE, + sizeof(usb_dev)); + if (ret) + dev_err(port->afe->dev, "%s: AFE device param cmd failed %d\n", + __func__, ret); + + return ret; +} +EXPORT_SYMBOL_GPL(afe_port_send_usb_dev_param); + +static int afe_port_send_usb_params(struct q6afe_port *port, struct q6afe_= usb_cfg *cfg) +{ + union afe_port_config *pcfg =3D &port->port_cfg; + struct afe_param_id_usb_audio_dev_lpcm_fmt lpcm_fmt; + struct afe_param_id_usb_audio_svc_interval svc_int; + int ret; + + if (!pcfg) { + dev_err(port->afe->dev, "%s: Error, no configuration data\n", __func__); + ret =3D -EINVAL; + goto exit; + } + + memset(&lpcm_fmt, 0, sizeof(lpcm_fmt)); + memset(&svc_int, 0, sizeof(svc_int)); + + lpcm_fmt.cfg_minor_version =3D AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + lpcm_fmt.endian =3D pcfg->usb_cfg.endian; + ret =3D q6afe_port_set_param_v2(port, &lpcm_fmt, + AFE_PARAM_ID_USB_AUDIO_DEV_LPCM_FMT, + AFE_MODULE_AUDIO_DEV_INTERFACE, sizeof(lpcm_fmt)); + if (ret) { + dev_err(port->afe->dev, "%s: AFE device param cmd LPCM_FMT failed %d\n", + __func__, ret); + goto exit; + } + + svc_int.cfg_minor_version =3D AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + svc_int.svc_interval =3D pcfg->usb_cfg.service_interval; + ret =3D q6afe_port_set_param_v2(port, &svc_int, + AFE_PARAM_ID_USB_AUDIO_SVC_INTERVAL, + AFE_MODULE_AUDIO_DEV_INTERFACE, sizeof(svc_int)); + if (ret) + dev_err(port->afe->dev, "%s: AFE device param cmd svc_interval failed %d= \n", + __func__, ret); + +exit: + return ret; +} + +/** + * q6afe_usb_port_prepare() - Prepare usb afe port. + * + * @port: Instance of afe port + * @cfg: USB configuration for the afe port + * + */ +void q6afe_usb_port_prepare(struct q6afe_port *port, + struct q6afe_usb_cfg *cfg) +{ + union afe_port_config *pcfg =3D &port->port_cfg; + + pcfg->usb_cfg.cfg_minor_version =3D AFE_API_MINOR_VERSION_USB_AUDIO_CONFI= G; + pcfg->usb_cfg.sample_rate =3D cfg->sample_rate; + pcfg->usb_cfg.num_channels =3D cfg->num_channels; + pcfg->usb_cfg.bit_width =3D cfg->bit_width; + + afe_port_send_usb_params(port, cfg); +} +EXPORT_SYMBOL_GPL(q6afe_usb_port_prepare); + /** * q6afe_hdmi_port_prepare() - Prepare hdmi afe port. * @@ -1612,7 +1799,10 @@ struct q6afe_port *q6afe_port_get_from_id(struct dev= ice *dev, int id) break; case AFE_PORT_ID_WSA_CODEC_DMA_RX_0 ... AFE_PORT_ID_RX_CODEC_DMA_RX_7: cfg_type =3D AFE_PARAM_ID_CODEC_DMA_CONFIG; - break; + break; + case AFE_PORT_ID_USB_RX: + cfg_type =3D AFE_PARAM_ID_USB_AUDIO_CONFIG; + break; default: dev_err(dev, "Invalid port id 0x%x\n", port_id); return ERR_PTR(-EINVAL); diff --git a/sound/soc/qcom/qdsp6/q6afe.h b/sound/soc/qcom/qdsp6/q6afe.h index 65d0676075e1..a29abe4ce436 100644 --- a/sound/soc/qcom/qdsp6/q6afe.h +++ b/sound/soc/qcom/qdsp6/q6afe.h @@ -3,7 +3,7 @@ #ifndef __Q6AFE_H__ #define __Q6AFE_H__ =20 -#define AFE_PORT_MAX 129 +#define AFE_PORT_MAX 137 =20 #define MSM_AFE_PORT_TYPE_RX 0 #define MSM_AFE_PORT_TYPE_TX 1 @@ -203,6 +203,36 @@ struct q6afe_cdc_dma_cfg { u16 active_channels_mask; }; =20 +/** + * struct q6afe_usb_cfg + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @sample_rate: Sampling rate of the port + * Supported values: + * AFE_PORT_SAMPLE_RATE_8K + * AFE_PORT_SAMPLE_RATE_11025 + * AFE_PORT_SAMPLE_RATE_12K + * AFE_PORT_SAMPLE_RATE_16K + * AFE_PORT_SAMPLE_RATE_22050 + * AFE_PORT_SAMPLE_RATE_24K + * AFE_PORT_SAMPLE_RATE_32K + * AFE_PORT_SAMPLE_RATE_44P1K + * AFE_PORT_SAMPLE_RATE_48K + * AFE_PORT_SAMPLE_RATE_96K + * AFE_PORT_SAMPLE_RATE_192K + * @bit_width: Bit width of the sample. + * Supported values: 16, 24 + * @num_channels: Number of channels + * Supported values: 1, 2 + **/ +struct q6afe_usb_cfg { + u32 cfg_minor_version; + u32 sample_rate; + u16 bit_width; + u16 num_channels; +}; =20 struct q6afe_port_config { struct q6afe_hdmi_cfg hdmi; @@ -210,6 +240,7 @@ struct q6afe_port_config { struct q6afe_i2s_cfg i2s_cfg; struct q6afe_tdm_cfg tdm; struct q6afe_cdc_dma_cfg dma_cfg; + struct q6afe_usb_cfg usb_audio; }; =20 struct q6afe_port; @@ -219,6 +250,8 @@ int q6afe_port_start(struct q6afe_port *port); int q6afe_port_stop(struct q6afe_port *port); void q6afe_port_put(struct q6afe_port *port); int q6afe_get_port_id(int index); +void q6afe_usb_port_prepare(struct q6afe_port *port, + struct q6afe_usb_cfg *cfg); void q6afe_hdmi_port_prepare(struct q6afe_port *port, struct q6afe_hdmi_cfg *cfg); void q6afe_slim_port_prepare(struct q6afe_port *port, @@ -228,6 +261,7 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, st= ruct q6afe_tdm_cfg *cfg); void q6afe_cdc_dma_port_prepare(struct q6afe_port *port, struct q6afe_cdc_dma_cfg *cfg); =20 +int afe_port_send_usb_dev_param(struct q6afe_port *port, int cardidx, int = pcmidx); int q6afe_port_set_sysclk(struct q6afe_port *port, int clk_id, int clk_src, int clk_root, unsigned int freq, int dir); diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c b/sound/soc/qcom/qdsp= 6/q6dsp-lpass-ports.c index 4919001de08b..4a96b11f7fd1 100644 --- a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c +++ b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c @@ -97,6 +97,26 @@ } =20 static struct snd_soc_dai_driver q6dsp_audio_fe_dais[] =3D { + { + .playback =3D { + .stream_name =3D "USB Playback", + .rates =3D SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats =3D SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, + .channels_min =3D 1, + .channels_max =3D 2, + .rate_min =3D 8000, + .rate_max =3D 192000, + }, + .id =3D USB_RX, + .name =3D "USB_RX", + }, { .playback =3D { .stream_name =3D "HDMI Playback", @@ -624,6 +644,9 @@ struct snd_soc_dai_driver *q6dsp_audio_ports_set_config= (struct device *dev, case WSA_CODEC_DMA_RX_0 ... RX_CODEC_DMA_RX_7: q6dsp_audio_fe_dais[i].ops =3D cfg->q6dma_ops; break; + case USB_RX: + q6dsp_audio_fe_dais[i].ops =3D cfg->q6usb_ops; + break; default: break; } diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h b/sound/soc/qcom/qdsp= 6/q6dsp-lpass-ports.h index 7f052c8a1257..d8dde6dd0aca 100644 --- a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h +++ b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h @@ -11,6 +11,7 @@ struct q6dsp_audio_port_dai_driver_config { const struct snd_soc_dai_ops *q6i2s_ops; const struct snd_soc_dai_ops *q6tdm_ops; const struct snd_soc_dai_ops *q6dma_ops; + const struct snd_soc_dai_ops *q6usb_ops; }; =20 struct snd_soc_dai_driver *q6dsp_audio_ports_set_config(struct device *dev, diff --git a/sound/soc/qcom/qdsp6/q6routing.c b/sound/soc/qcom/qdsp6/q6rout= ing.c index 90228699ba7d..b7439420b425 100644 --- a/sound/soc/qcom/qdsp6/q6routing.c +++ b/sound/soc/qcom/qdsp6/q6routing.c @@ -435,6 +435,26 @@ static struct session_data *get_session_from_id(struct= msm_routing_data *data, =20 return NULL; } + +static bool is_usb_routing_enabled(struct msm_routing_data *data) +{ + int i; + + /* + * Loop through current sessions to see if there are active routes + * to the USB_RX backend DAI. The USB offload routing is designed + * similarly to the non offload path. If there are multiple PCM + * devices associated with the ASoC platform card, only one active + * path can be routed to the USB offloaded endpoint. + */ + for (i =3D 0; i < MAX_SESSIONS; i++) { + if (data->sessions[i].port_id =3D=3D USB_RX) + return true; + } + + return false; +} + /** * q6routing_stream_close() - Deregister a stream * @@ -499,7 +519,8 @@ static int msm_routing_put_audio_mixer(struct snd_kcont= rol *kcontrol, struct session_data *session =3D &data->sessions[session_id]; =20 if (ucontrol->value.integer.value[0]) { - if (session->port_id =3D=3D be_id) + if (session->port_id =3D=3D be_id || + (be_id =3D=3D USB_RX && is_usb_routing_enabled(data))) return 0; =20 session->port_id =3D be_id; @@ -515,6 +536,9 @@ static int msm_routing_put_audio_mixer(struct snd_kcont= rol *kcontrol, return 1; } =20 +static const struct snd_kcontrol_new usb_mixer_controls[] =3D { + Q6ROUTING_RX_MIXERS(USB_RX) }; + static const struct snd_kcontrol_new hdmi_mixer_controls[] =3D { Q6ROUTING_RX_MIXERS(HDMI_RX) }; =20 @@ -950,6 +974,10 @@ static const struct snd_soc_dapm_widget msm_qdsp6_widg= ets[] =3D { SND_SOC_DAPM_MIXER("MultiMedia8 Mixer", SND_SOC_NOPM, 0, 0, mmul8_mixer_controls, ARRAY_SIZE(mmul8_mixer_controls)), =20 + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, + usb_mixer_controls, + ARRAY_SIZE(usb_mixer_controls)), + }; =20 static const struct snd_soc_dapm_route intercon[] =3D { @@ -1043,6 +1071,8 @@ static const struct snd_soc_dapm_route intercon[] =3D= { {"MM_UL6", NULL, "MultiMedia6 Mixer"}, {"MM_UL7", NULL, "MultiMedia7 Mixer"}, {"MM_UL8", NULL, "MultiMedia8 Mixer"}, + + Q6ROUTING_RX_DAPM_ROUTE("USB Mixer", "USB_RX"), }; =20 static int routing_hw_params(struct snd_soc_component *component, From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255E920FAB7; Wed, 6 Nov 2024 19:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921698; cv=none; b=LIJx5aN4w4dxfTJSROJLCP1CyXdRi7M8Ve1hYP9J7phpyS/lU21+JG2+naRxIGLQ4em8ItF5S/EV+65JU1vAkg1E7RUHgZLKMktesCQ31Vwi2ode7QvEso+Y53+7BTIl1bnl5lsQA/3gG0QLIuMGtMEgXsC1CFjAS9l+T7f/uCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921698; c=relaxed/simple; bh=lH6pajAyODmY/7seq1vw42FSufEXp3D1uilBoZTCkh8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cLyNCtLO/C1vfpxUuNa/w8VjAVoNMn/l+kR/quj7a0mZgzOhpIInlYorPyUL4wYwaWL8Mv/YF/kFhw+xJJ69FfdVG3A7bvTraRJV/yc0yn2euFr6T8sokrylKpIre7CXJt73zBZigAPVYzui7QFrqrqebcwOZkrr5veHxPIadug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=lNCMurcN; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lNCMurcN" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6E00W1001976; Wed, 6 Nov 2024 19:34:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ki29lRSXvVePRr3/SBVRt9DzNF8VTubZk2D+F/mX5Zk=; b=lNCMurcNSNfrw+TA D8KRodKzV7CNo9S82/Z/4BbDtagQ1ysjyYRSSMYl5PcpWkLWcjSEXz5kj3f40kaD blhKAU1LiB7j+SUv0zWsqPQeYdcil/zX2uIQWhPpCQyQOrRbip8otssFUgJw4/ZA dmkAvsdvG9akSyVqkTxNKkqdGQtnj590fl7axqO6O4AIYwQKlt5faCmoc58H56i7 SHuUMNikO8G2MCZZif/0XfDqN8uE0ptUMezaiSUh/Jd9jkcfZdahP4pvQab4tkP3 ZYEunlI3Q/FetVqR+apBjyYSyFkJl0wQMejB8gcjsWO35Ev7fncdnIIcFm6v5O7B ST5V0w== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r072jf9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYZnd027650 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 20/30] ASoC: qcom: qdsp6: q6afe: Increase APR timeout Date: Wed, 6 Nov 2024 11:34:03 -0800 Message-ID: <20241106193413.1730413-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: kSkMa8FMytHu0olcKCXgjt3clZ2i8P8y X-Proofpoint-GUID: kSkMa8FMytHu0olcKCXgjt3clZ2i8P8y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 mlxlogscore=971 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" For USB offloading situations, the AFE port start command will result in a QMI handshake between the Q6DSP and the main processor. Depending on if the USB bus is suspended, this routine would require more time to complete, as resuming the USB bus has some overhead associated with it. Increase the timeout to 3s to allow for sufficient time for the USB QMI stream enable handshake to complete. Reviewed-by: Pierre-Louis Bossart Reviewed-by: Srinivas Kandagatla Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6afe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index 3ee6ff8a6bc3..b5b2af2ce50c 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -366,7 +366,7 @@ #define AFE_API_VERSION_SLOT_MAPPING_CONFIG 1 #define AFE_API_VERSION_CODEC_DMA_CONFIG 1 =20 -#define TIMEOUT_MS 1000 +#define TIMEOUT_MS 3000 #define AFE_CMD_RESP_AVAIL 0 #define AFE_CMD_RESP_NONE 1 #define AFE_CLK_TOKEN 1024 From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51F5921018F; Wed, 6 Nov 2024 19:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; cv=none; b=ZyS3bxyQpdxIJnAmNB+VqsmSJ/87HZYKtWcPrPH9tJwwQFD2ar4KOxccpSrAotRpGyGYrk9IMG8oWJ0QJekUvL6Hk6d4bcpxlA6O6jqKe5qrWtn4QoRpSUl/dzwkUZtDdU31jJkyfYEZH/2qInKjKcRk4ShRdK/Bv/s0dr6YDig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; c=relaxed/simple; bh=TyZpAqNQq1ttOG6UfwMIX9VH/VClmDIoFLNFsNFe7AE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u19AmMV9K34AEsnqsH/BcFH7sN8ES6X6zF5z+7VqLHcVBy6QFHz8RCGf2N3KPPSCNULti8+IfUK1sJVcAnHz1wm5EAP7MR6LCG3ThvuKu0gKeJ+4fFGhfosNOolwZCsZ0xm+VrRzT+zeHzjYx4jzHlax7fuhQNVFRqsZQDtYROw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=NUZq7HR/; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NUZq7HR/" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6D7RYR001544; Wed, 6 Nov 2024 19:34:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Jgs2rFGJgbAL0aGklun+Od7AKyFR8h9rOvkhmuxHVj8=; b=NUZq7HR/G7GkpSzb X2+brSAMmXM/kMnWYf85dPY4xdqX4EzHRmyomOI8caAdXNZ93TkZuvsi4BigcH+z Mc5r9l73EnA3K5akXWkkKovgbu/NY+KbUpCrL1Crmpbf/VGSZo2VLM5VfnXhIM3i sSdMu5/Ha9bqmeyJkxkO1zoiEiJleX8UBCSO744mpF18Rhtzno/Z3ftb6m0TQzq9 fBk1TrdL+sVR2yF8xWqFYArMmUujOtvhgSHOsYYrK7h05kdt0w8XN28BhoLz9Qup L//WPpqRiNBAOzuO0D8k557XfdF2eiF592qIK/Q015YW5+BWoiLnic1dc+ikVORG O56RoA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r07hjg99-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYZ67008671 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 21/30] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Wed, 6 Nov 2024 11:34:04 -0800 Message-ID: <20241106193413.1730413-22-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 3WRNs6NiXvWX1G8ILvQuTl4gSAfTQ-m3 X-Proofpoint-ORIG-GUID: 3WRNs6NiXvWX1G8ILvQuTl4gSAfTQ-m3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Create a USB BE component that will register a new USB port to the ASoC USB framework. This will handle determination on if the requested audio profile is supported by the USB device currently selected. Check for if the PCM format is supported during the hw_params callback. If the profile is not supported then the userspace ALSA entity will receive an error, and can take further action. Signed-off-by: Wesley Cheng --- include/sound/q6usboffload.h | 20 +++ sound/soc/qcom/Kconfig | 10 ++ sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6usb.c | 246 ++++++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 include/sound/q6usboffload.h create mode 100644 sound/soc/qcom/qdsp6/q6usb.c diff --git a/include/sound/q6usboffload.h b/include/sound/q6usboffload.h new file mode 100644 index 000000000000..35fd7388fd52 --- /dev/null +++ b/include/sound/q6usboffload.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * sound/q6usboffload.h -- QDSP6 USB offload + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +/** + * struct q6usb_offload + * @dev - dev handle to usb be + * @domain - allocated iommu domain + * @sid - streamID for iommu + * @intr_num - usb interrupter number + **/ +struct q6usb_offload { + struct device *dev; + struct iommu_domain *domain; + long long sid; + u16 intr_num; +}; diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index ca7a30ebd26a..77c21fc4fc1b 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -118,6 +118,16 @@ config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS =20 +config SND_SOC_QDSP6_USB + tristate "SoC ALSA USB offloading backing for QDSP6" + depends on SND_SOC_USB + help + Adds support for USB offloading for QDSP6 ASoC + based platform sound cards. This will enable the + Q6USB DPCM backend DAI link, which will interact + with the SoC USB framework to initialize a session + with active USB SND devices. + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" depends on QCOM_APR diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 26b7c55c9c11..67267304e7e9 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) +=3D q6apm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) +=3D q6apm-lpass-dais.o obj-$(CONFIG_SND_SOC_QDSP6_PRM) +=3D q6prm.o obj-$(CONFIG_SND_SOC_QDSP6_PRM_LPASS_CLOCKS) +=3D q6prm-clocks.o +obj-$(CONFIG_SND_SOC_QDSP6_USB) +=3D q6usb.o diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c new file mode 100644 index 000000000000..2b3e24520070 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "q6afe.h" +#include "q6dsp-lpass-ports.h" + +#define Q6_USB_SID_MASK 0xF + +struct q6usb_port_data { + struct q6afe_usb_cfg usb_cfg; + struct snd_soc_usb *usb; + struct q6usb_offload priv; + + /* Protects against operations between SOC USB and ASoC */ + struct mutex mutex; + struct list_head devices; +}; + +static const struct snd_soc_dapm_widget q6usb_dai_widgets[] =3D { + SND_SOC_DAPM_HP("USB_RX_BE", NULL), +}; + +static const struct snd_soc_dapm_route q6usb_dapm_routes[] =3D { + {"USB Playback", NULL, "USB_RX_BE"}, +}; + +static int q6usb_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(dai->dev); + struct snd_soc_pcm_runtime *rtd =3D substream->private_data; + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + int direction =3D substream->stream; + struct q6afe_port *q6usb_afe; + struct snd_soc_usb_device *sdev; + int ret =3D -EINVAL; + + mutex_lock(&data->mutex); + + /* No active chip index */ + if (list_empty(&data->devices)) + goto out; + + sdev =3D list_last_entry(&data->devices, struct snd_soc_usb_device, list); + + ret =3D snd_soc_usb_find_supported_format(sdev->chip_idx, params, directi= on); + if (ret < 0) + goto out; + + q6usb_afe =3D q6afe_port_get_from_id(cpu_dai->dev, USB_RX); + if (IS_ERR(q6usb_afe)) + goto out; + + /* Notify audio DSP about the devices being offloaded */ + ret =3D afe_port_send_usb_dev_param(q6usb_afe, sdev->card_idx, + sdev->ppcm_idx[sdev->num_playback - 1]); + +out: + mutex_unlock(&data->mutex); + + return ret; +} + +static const struct snd_soc_dai_ops q6usb_ops =3D { + .hw_params =3D q6usb_hw_params, +}; + +static struct snd_soc_dai_driver q6usb_be_dais[] =3D { + { + .playback =3D { + .stream_name =3D "USB BE RX", + .rates =3D SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats =3D SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, + .channels_min =3D 1, + .channels_max =3D 2, + .rate_max =3D 192000, + .rate_min =3D 8000, + }, + .id =3D USB_RX, + .name =3D "USB_RX_BE", + .ops =3D &q6usb_ops, + }, +}; + +static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *c= omponent, + const struct of_phandle_args *args, + const char **dai_name) +{ + int id =3D args->args[0]; + int ret =3D -EINVAL; + int i; + + for (i =3D 0; i < ARRAY_SIZE(q6usb_be_dais); i++) { + if (q6usb_be_dais[i].id =3D=3D id) { + *dai_name =3D q6usb_be_dais[i].name; + ret =3D 0; + break; + } + } + + return ret; +} + +static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected) +{ + struct q6usb_port_data *data; + + if (!usb->component) + return -ENODEV; + + data =3D dev_get_drvdata(usb->component->dev); + + mutex_lock(&data->mutex); + if (connected) { + /* Selects the latest USB headset plugged in for offloading */ + list_add_tail(&sdev->list, &data->devices); + } else { + list_del(&sdev->list); + } + mutex_unlock(&data->mutex); + + return 0; +} + +static int q6usb_component_probe(struct snd_soc_component *component) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + struct snd_soc_usb *usb; + + usb =3D snd_soc_usb_allocate_port(component, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb =3D q6usb_alsa_connection_cb; + + snd_soc_usb_add_port(usb); + data->usb =3D usb; + + return 0; +} + +static void q6usb_component_remove(struct snd_soc_component *component) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + + snd_soc_usb_remove_port(data->usb); + snd_soc_usb_free_port(data->usb); +} + +static const struct snd_soc_component_driver q6usb_dai_component =3D { + .probe =3D q6usb_component_probe, + .remove =3D q6usb_component_remove, + .name =3D "q6usb-dai-component", + .dapm_widgets =3D q6usb_dai_widgets, + .num_dapm_widgets =3D ARRAY_SIZE(q6usb_dai_widgets), + .dapm_routes =3D q6usb_dapm_routes, + .num_dapm_routes =3D ARRAY_SIZE(q6usb_dapm_routes), + .of_xlate_dai_name =3D q6usb_audio_ports_of_xlate_dai_name, +}; + +static int q6usb_dai_dev_probe(struct platform_device *pdev) +{ + struct device_node *node =3D pdev->dev.of_node; + struct q6usb_port_data *data; + struct device *dev =3D &pdev->dev; + struct of_phandle_args args; + int ret; + + data =3D devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret =3D of_property_read_u16(node, "qcom,usb-audio-intr-idx", + &data->priv.intr_num); + if (ret) { + dev_err(&pdev->dev, "failed to read intr idx.\n"); + return ret; + } + + ret =3D of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); + if (ret < 0) + data->priv.sid =3D -1; + else + data->priv.sid =3D args.args[0] & Q6_USB_SID_MASK; + + data->priv.domain =3D iommu_get_domain_for_dev(&pdev->dev); + + data->priv.dev =3D dev; + INIT_LIST_HEAD(&data->devices); + dev_set_drvdata(dev, data); + + return devm_snd_soc_register_component(dev, &q6usb_dai_component, + q6usb_be_dais, ARRAY_SIZE(q6usb_be_dais)); +} + +static const struct of_device_id q6usb_dai_device_id[] =3D { + { .compatible =3D "qcom,q6usb" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6usb_dai_device_id); + +static struct platform_driver q6usb_dai_platform_driver =3D { + .driver =3D { + .name =3D "q6usb-dai", + .of_match_table =3D of_match_ptr(q6usb_dai_device_id), + }, + .probe =3D q6usb_dai_dev_probe, + /* + * Remove not required as resources are cleaned up as part of + * component removal. Others are device managed resources. + */ +}; +module_platform_driver(q6usb_dai_platform_driver); + +MODULE_DESCRIPTION("Q6 USB backend dai driver"); +MODULE_LICENSE("GPL"); From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA1620F5AB; Wed, 6 Nov 2024 19:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; cv=none; b=mMwcETN/4UkNkXoSBvtqcFsrYW7dUpLT4itZaO1aQbhK5xf/Hk//NP9ooNEdy/v1xQKjFK4W9BCrXPHLKMz6sTCcaHsgN0mBdncwv6zaCuZn2Vk+qRpfDh4rwzYGN2omkSLI3/cW2a09W+3h7tA971XRDg4Z5oHM+nm1V8fvznk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; c=relaxed/simple; bh=FjLFYmyLM91EuK/4S4Mx/FACWz49ZL9h3izMArjdFmk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SC29hxklS3K7KFEaVhQBJkjQSTeREIuDU2uYUERD/afl3gr1eM83dT5Sjt8n9oFfOhH6hDJqUbc1lWlojoCcgzZ//sAravswDrZn14ReVkXejXY/766qiAXSQ7o1RxPfcFXY+WhBXuYtzh1Eq8D6sNj59Xf131a0aDvNy3OhbuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=CXz+mHi1; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="CXz+mHi1" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AvJKt004555; Wed, 6 Nov 2024 19:34:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= KbwVoMaWP1gYXPm3sE2SfiEML+YhA+Qa0sgHtH4EsFg=; b=CXz+mHi12b09/Qlv ar+0TPCZMd8S5h6jE+QVWGhKuHREkYPgui9hPoSgbvUV1g3eRtft6Bg78p6DMLby Wdh/IRpkb+JKBXDXWZ4fkxggLgrVOuPCFjib4/7C7tkEtTUzZf1DZWBJBTPxPtC4 DYll6NrA73CaQvbP7523vTJwBKG6UKZ4Fxi1IqdVlRYMQ0Pe8j9ZfoKdrAvZdZO4 /4MX0cVnFWo6YqsVs4v8yYzZhEkBk6byMjNq1DhHNEltVN4kJtGKhIwTHCCJlLuY C5E71KqX51ualQQxfGYs2C3LsZ2l5wJFxafk+apGksX80xe+v7tchxJU7dDF0SMu AlBv8Q== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvg3txcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYZbq004022 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 22/30] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Date: Wed, 6 Nov 2024 11:34:05 -0800 Message-ID: <20241106193413.1730413-23-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: wsKQCu73qmrDztwbeKtokGybSd05eTAA X-Proofpoint-GUID: wsKQCu73qmrDztwbeKtokGybSd05eTAA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 adultscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" The headphone jack framework has a well defined infrastructure for notifying userspace entities through input devices. Expose a jack device that carries information about if an offload capable device is connected. Applications can further identify specific offloading information through other SND kcontrols. Signed-off-by: Wesley Cheng --- sound/soc/qcom/Kconfig | 5 +++ sound/soc/qcom/Makefile | 2 ++ sound/soc/qcom/qdsp6/q6usb.c | 41 ++++++++++++++++++++++ sound/soc/qcom/sm8250.c | 24 ++++++++++++- sound/soc/qcom/usb_offload_utils.c | 56 ++++++++++++++++++++++++++++++ sound/soc/qcom/usb_offload_utils.h | 30 ++++++++++++++++ 6 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 sound/soc/qcom/usb_offload_utils.c create mode 100644 sound/soc/qcom/usb_offload_utils.h diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 77c21fc4fc1b..6bedac2effc9 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -118,9 +118,14 @@ config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS =20 +config SND_SOC_QCOM_OFFLOAD_UTILS + tristate + config SND_SOC_QDSP6_USB tristate "SoC ALSA USB offloading backing for QDSP6" depends on SND_SOC_USB + select SND_SOC_QCOM_OFFLOAD_UTILS + help Adds support for USB offloading for QDSP6 ASoC based platform sound cards. This will enable the diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile index 16db7b53ddac..985ce2ae286b 100644 --- a/sound/soc/qcom/Makefile +++ b/sound/soc/qcom/Makefile @@ -30,6 +30,7 @@ snd-soc-sc8280xp-y :=3D sc8280xp.o snd-soc-qcom-common-y :=3D common.o snd-soc-qcom-sdw-y :=3D sdw.o snd-soc-x1e80100-y :=3D x1e80100.o +snd-soc-qcom-offload-utils-objs :=3D usb_offload_utils.o =20 obj-$(CONFIG_SND_SOC_STORM) +=3D snd-soc-storm.o obj-$(CONFIG_SND_SOC_APQ8016_SBC) +=3D snd-soc-apq8016-sbc.o @@ -42,6 +43,7 @@ obj-$(CONFIG_SND_SOC_SM8250) +=3D snd-soc-sm8250.o obj-$(CONFIG_SND_SOC_QCOM_COMMON) +=3D snd-soc-qcom-common.o obj-$(CONFIG_SND_SOC_QCOM_SDW) +=3D snd-soc-qcom-sdw.o obj-$(CONFIG_SND_SOC_X1E80100) +=3D snd-soc-x1e80100.o +obj-$(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) +=3D snd-soc-qcom-offload-utils.o =20 #DSP lib obj-$(CONFIG_SND_SOC_QDSP6) +=3D qdsp6/ diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 2b3e24520070..aacbe3bced99 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -14,6 +14,7 @@ #include =20 #include +#include #include #include #include @@ -30,6 +31,7 @@ struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; + struct snd_soc_jack *hs_jack; struct q6usb_offload priv; =20 /* Protects against operations between SOC USB and ASoC */ @@ -142,16 +144,54 @@ static int q6usb_alsa_connection_cb(struct snd_soc_us= b *usb, =20 mutex_lock(&data->mutex); if (connected) { + if (data->hs_jack) + snd_jack_report(data->hs_jack->jack, SND_JACK_USB); + /* Selects the latest USB headset plugged in for offloading */ list_add_tail(&sdev->list, &data->devices); } else { list_del(&sdev->list); + + if (data->hs_jack) + snd_jack_report(data->hs_jack->jack, 0); } mutex_unlock(&data->mutex); =20 return 0; } =20 +static void q6usb_component_disable_jack(struct q6usb_port_data *data) +{ + /* Offload jack has already been disabled */ + if (!data->hs_jack) + return; + + snd_jack_report(data->hs_jack->jack, 0); + data->hs_jack =3D NULL; +} + +static void q6usb_component_enable_jack(struct q6usb_port_data *data, + struct snd_soc_jack *jack) +{ + snd_jack_report(jack->jack, !list_empty(&data->devices) ? SND_JACK_USB : = 0); + data->hs_jack =3D jack; +} + +static int q6usb_component_set_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *priv) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + + mutex_lock(&data->mutex); + if (jack) + q6usb_component_enable_jack(data, jack); + else + q6usb_component_disable_jack(data); + mutex_unlock(&data->mutex); + + return 0; +} + static int q6usb_component_probe(struct snd_soc_component *component) { struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); @@ -179,6 +219,7 @@ static void q6usb_component_remove(struct snd_soc_compo= nent *component) =20 static const struct snd_soc_component_driver q6usb_dai_component =3D { .probe =3D q6usb_component_probe, + .set_jack =3D q6usb_component_set_jack, .remove =3D q6usb_component_remove, .name =3D "q6usb-dai-component", .dapm_widgets =3D q6usb_dai_widgets, diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index 19adadedc88a..4ab1f8c7556a 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -12,6 +12,7 @@ #include #include "qdsp6/q6afe.h" #include "common.h" +#include "usb_offload_utils.h" #include "sdw.h" =20 #define DRIVER_NAME "sm8250" @@ -22,14 +23,34 @@ struct sm8250_snd_data { struct snd_soc_card *card; struct sdw_stream_runtime *sruntime[AFE_PORT_MAX]; struct snd_soc_jack jack; + struct snd_soc_jack usb_offload_jack; + bool usb_offload_jack_setup; bool jack_setup; }; =20 static int sm8250_snd_init(struct snd_soc_pcm_runtime *rtd) { struct sm8250_snd_data *data =3D snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + int ret; + + if (cpu_dai->id =3D=3D USB_RX) + ret =3D qcom_snd_usb_offload_jack_setup(rtd, &data->usb_offload_jack, + &data->usb_offload_jack_setup); + else + ret =3D qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); + return ret; +} + +static void sm8250_snd_exit(struct snd_soc_pcm_runtime *rtd) +{ + struct sm8250_snd_data *data =3D snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + + if (cpu_dai->id =3D=3D USB_RX) + qcom_snd_usb_offload_jack_remove(rtd, + &data->usb_offload_jack_setup); =20 - return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); } =20 static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, @@ -137,6 +158,7 @@ static void sm8250_add_be_ops(struct snd_soc_card *card) for_each_card_prelinks(card, i, link) { if (link->no_pcm =3D=3D 1) { link->init =3D sm8250_snd_init; + link->exit =3D sm8250_snd_exit; link->be_hw_params_fixup =3D sm8250_be_hw_params_fixup; link->ops =3D &sm8250_be_ops; } diff --git a/sound/soc/qcom/usb_offload_utils.c b/sound/soc/qcom/usb_offloa= d_utils.c new file mode 100644 index 000000000000..0ebc73245cd4 --- /dev/null +++ b/sound/soc/qcom/usb_offload_utils.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ +#include +#include +#include +#include + +#include "usb_offload_utils.h" + +int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup) +{ + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai =3D snd_soc_rtd_to_codec(rtd, 0); + int ret =3D 0; + + if (cpu_dai->id !=3D USB_RX) + return -EINVAL; + + if (!*jack_setup) { + ret =3D snd_soc_usb_setup_offload_jack(codec_dai->component, jack); + if (ret) + return ret; + } + + *jack_setup =3D true; + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_setup); + +int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, + bool *jack_setup) +{ + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai =3D snd_soc_rtd_to_codec(rtd, 0); + int ret =3D 0; + + if (cpu_dai->id !=3D USB_RX) + return -EINVAL; + + if (*jack_setup) { + ret =3D snd_soc_usb_disable_offload_jack(codec_dai->component); + if (ret) + return ret; + } + + *jack_setup =3D false; + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_remove); +MODULE_DESCRIPTION("ASoC Q6 USB offload controls"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/qcom/usb_offload_utils.h b/sound/soc/qcom/usb_offloa= d_utils.h new file mode 100644 index 000000000000..38205fa32ed4 --- /dev/null +++ b/sound/soc/qcom/usb_offload_utils.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ +#ifndef __QCOM_SND_USB_OFFLOAD_UTILS_H__ +#define __QCOM_SND_USB_OFFLOAD_UTILS_H__ + +#include + +#if IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) +int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup); + +int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, + bool *jack_setup); +#else +static inline int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runti= me *rtd, + struct snd_soc_jack *jack, + bool *jack_setup) +{ + return -ENODEV; +} + +static inline int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runt= ime *rtd, + bool *jack_setup) +{ + return -ENODEV; +} +#endif /* IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) */ +#endif /* __QCOM_SND_USB_OFFLOAD_UTILS_H__ */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3163321263C; Wed, 6 Nov 2024 19:34:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921701; cv=none; b=N15sgx8Bgu2OCcUXOkbKYg/ubGmFWnonMC/fkISNWqQzLmb0eaK/kFj6oyoJ6KrZbo5UHk3XotesjUfPAwvzL0IR4NniXCW7W05dVe4C0VR8HWiJcyD9d/P0fmLUgR1kqavliYavlEm/d5f0jqp7aY1nQhaXFQaXaoE2bICvpWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921701; c=relaxed/simple; bh=ZXPbpHEzwKIgrv8Ky4uyBr9mDKAN3LmnyDxkuOBUr+s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uoFORbfimp88HsBsEehVvc382r7I6+E/1Hp2iZijlXnMaSL/cIOsQytFxxxCLRWFdDvkEibtMrRIh/3D2R/kbCLtFBVt26D9oipaxBalM1M9jofRufz4iFwBcGYXuGndB+qyy6ujTbCeEDYjPhnBcxMp/KjB2Ol8/r78uF9YtYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=dIrovlze; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dIrovlze" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6FHUmo013143; Wed, 6 Nov 2024 19:34:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= sppKnQ9mP7I1PHGy+WP4+a8FkaLJq9uw25XgiNX7C7I=; b=dIrovlze8VK4Raes SzbE2sPaQU4vjEefKl2fevy14iWgA7oC9onsz8VKM/sKprUvSNY9Cqv1HFO09+Ma iBaTdbaMNuQ6HURtydH1RR8S9H6EcGzAaAs0zXUUX+8Vj9zyyplnVxuD3jm/VJ6b tl+q6MkXaKoCEMnlh17IG5waicIj5peb2/8hgVwoiNl9fULqbATEUtqrO61/b4+Y J44DIBORk7Ixb5gguZzsHxdP8jmELhewaO27j0tl2uNNGzztyOEZB7ZVAfvniDLm tGxcOTUGzgGkGWH0EoT7MBA+XVM0fmV0xHfUW6oV6iDJEdq1ELrilrI3xIQmabYH 3KHL+g== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qp2rv2c1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYaeG004026 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 23/30] ASoC: qcom: qdsp6: Fetch USB offload mapped card and PCM device Date: Wed, 6 Nov 2024 11:34:06 -0800 Message-ID: <20241106193413.1730413-24-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WioAUkfiIJq_6P3tDqjrDuj7YMrE1Z6i X-Proofpoint-ORIG-GUID: WioAUkfiIJq_6P3tDqjrDuj7YMrE1Z6i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 bulkscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" The USB SND path may need to know how the USB offload path is routed, so that applications can open the proper sound card and PCM device. The implementation for the QC ASoC design has a "USB Mixer" kcontrol for each possible FE (Q6ASM) DAI, which can be utilized to know which front end link is enabled. When an application/userspace queries for the mapped offload devices, the logic will lookup the USB mixer status though the following path: MultiMedia* <-> MM_DL* <-> USB Mixer* The "USB Mixer" is a DAPM widget, and the q6routing entity will set the DAPM connect status accordingly if the USB mixer is enabled. If enabled, the Q6USB backend link can fetch the PCM device number from the FE DAI link (Multimedia*). With respects to the card number, that is straightforward, as the ASoC components have direct references to the ASoC platform sound card. An example output can be shown below: Number of controls: 9 name value Capture Channel Map 0, 0 (range 0->36) Playback Channel Map 0, 0 (range 0->36) Headset Capture Switch On Headset Capture Volume 1 (range 0->4) Sidetone Playback Switch On Sidetone Playback Volume 4096 (range 0->8192) Headset Playback Switch On Headset Playback Volume 20, 20 (range 0->24) USB Offload Playback Route PCM#0 0, 1 (range -1->255) The "USB Offload Playback Route PCM#*" kcontrol will signify the corresponding card and pcm device it is offload to. (card#0 pcm - device#1) If the USB SND device supports multiple audio interfaces, then it will contain several PCM streams, hence in those situations, it is expected that there will be multiple playback route kcontrols created. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6usb.c | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index aacbe3bced99..b55e4c457128 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -132,6 +132,109 @@ static int q6usb_audio_ports_of_xlate_dai_name(struct= snd_soc_component *compone return ret; } =20 +static int q6usb_get_pcm_id_from_widget(struct snd_soc_dapm_widget *w) +{ + struct snd_soc_pcm_runtime *rtd; + struct snd_soc_dai *dai; + + for_each_card_rtds(w->dapm->card, rtd) { + dai =3D snd_soc_rtd_to_cpu(rtd, 0); + /* + * Only look for playback widget. RTD number carries the assigned + * PCM index. + */ + if (dai->stream[0].widget =3D=3D w) + return rtd->num; + } + + return -1; +} + +static int q6usb_usb_mixer_enabled(struct snd_soc_dapm_widget *w) +{ + struct snd_soc_dapm_path *p; + + /* Checks to ensure USB path is enabled/connected */ + snd_soc_dapm_widget_for_each_sink_path(w, p) + if (!strcmp(p->sink->name, "USB Mixer") && p->connect) + return 1; + + return 0; +} + +static int q6usb_get_pcm_id(struct snd_soc_component *component) +{ + struct snd_soc_dapm_widget *w; + struct snd_soc_dapm_path *p; + int pidx; + + /* + * Traverse widgets to find corresponding FE widget. The DAI links are + * built like the following: + * MultiMedia* <-> MM_DL* <-> USB Mixer* + */ + for_each_card_widgets(component->card, w) { + if (!strncmp(w->name, "MultiMedia", 10)) { + /* + * Look up all paths associated with the FE widget to see if + * the USB BE is enabled. The sink widget is responsible to + * link with the USB mixers. + */ + snd_soc_dapm_widget_for_each_sink_path(w, p) { + if (q6usb_usb_mixer_enabled(p->sink)) { + pidx =3D q6usb_get_pcm_id_from_widget(w); + return pidx; + } + } + } + } + + return -1; +} + +static int q6usb_update_offload_route(struct snd_soc_component *component,= int card, + int pcm, int direction, long *route) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + struct snd_soc_usb_device *sdev; + int ret =3D 0; + int cidx =3D -1; + int pidx =3D -1; + + mutex_lock(&data->mutex); + + if (list_empty(&data->devices) || + direction =3D=3D SNDRV_PCM_STREAM_CAPTURE) { + ret =3D -ENODEV; + goto out; + } + + sdev =3D list_last_entry(&data->devices, struct snd_soc_usb_device, list); + + /* + * Will always look for last PCM device discovered/probed as the + * active offload index. + */ + if (card =3D=3D sdev->card_idx && + pcm =3D=3D sdev->ppcm_idx[sdev->num_playback - 1]) { + cidx =3D component->card->snd_card->number; + pidx =3D q6usb_get_pcm_id(component); + } + + if (cidx < 0 || pidx < 0) { + cidx =3D -1; + pidx =3D -1; + } + +out: + route[0] =3D cidx; + route[1] =3D pidx; + + mutex_unlock(&data->mutex); + + return ret; +} + static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected) { @@ -202,6 +305,7 @@ static int q6usb_component_probe(struct snd_soc_compone= nt *component) return -ENOMEM; =20 usb->connection_status_cb =3D q6usb_alsa_connection_cb; + usb->update_offload_route_info =3D q6usb_update_offload_route; =20 snd_soc_usb_add_port(usb); data->usb =3D usb; From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B3B820D510; Wed, 6 Nov 2024 19:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921694; cv=none; b=QbX19lY+97HuTnpm8NOBc7EiMBQ7beSF+uG788uz8mNrCCWRegmsqb4xpcokT4DBaLc0U0uh4zvoPbWoVm1D/+9ZSLShu8Ym7gdpy6LAxj0aAMYB4+1GYMoXaexD7fmIEBau4rO35HwOKLfHnG13QB1rAZOr6NQnAJMt1iA3jyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921694; c=relaxed/simple; bh=znXOxIyccn+56SBeFssLZ0htwylqaWKKIkGUg/ch57I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pwdkXA4xgL8rSismMt0ZdBQLXfd40HerrZFRo/gaDiZ/Mwlme82oAOzqflQ41t7cYUmCCEjbIWUSmhAXQTZ0a0c3EgBGiFq/snAIXZW1udOIR19sNwOYtgpsEZrGJ8HTr3HJII/ArU87c9fjRrCOxQL6rSL28Ps1P8kv1IYQ39s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=bzZe1UtE; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="bzZe1UtE" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AcG1l002666; Wed, 6 Nov 2024 19:34:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= CrwFeOx4HKu3nEccoUMDVjOWs+xMeXJhiBRV+pMaDIg=; b=bzZe1UtEU+mZEGKW CzCV4vP3wEBkb1b2Q4fkfpuQsPOVqwoHavMzEBJWneBQxLMhK5/PR4manUMW8HZ4 /e235vB5cD/qpHD2DMQwiTq0n671Awa8QwNkP8VPOEd2WqgTeizX/h/20ug0L7K+ Zo1KxG1efolgqgefcry2D2xYQshyJH9Zv6i1/WKGsmih25tYVMjnoVu+5PN+qeiZ x/q5c6hJLswXw+JA+KZLL+lawn0RdsrFUCLugJl0K196rhVrsD/CN7LKUIFLjPif 5LYVHCGa6T3p1W8mjV41Q6M+/kO2rRe9MqJgUzq9Yonmo63n86rhUwy2Xli8JiLj LGwzsg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y99-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYa1n012026 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 24/30] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Wed, 6 Nov 2024 11:34:07 -0800 Message-ID: <20241106193413.1730413-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: cA50Pj9AthZpooqL3eKyYNs0zlFrQmqI X-Proofpoint-GUID: cA50Pj9AthZpooqL3eKyYNs0zlFrQmqI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Allow for different platforms to be notified on USB SND connect/disconnect sequences. This allows for platform USB SND modules to properly initialize and populate internal structures with references to the USB SND chip device. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 10 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 6c5b0e02e57b..4ac7f2b8309a 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,42 @@ MODULE_PARM_DESC(skip_validation, "Skip unit descripto= r validation (default: no) static DEFINE_MUTEX(register_mutex); static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; static struct usb_driver usb_audio_driver; +static struct snd_usb_platform_ops *platform_ops; + +/* + * Register platform specific operations that will be notified on events + * which occur in USB SND. The platform driver can utilize this path to + * enable features, such as USB audio offloading, which allows for audio d= ata + * to be queued by an audio DSP. + * + * Only one set of platform operations can be registered to USB SND. The + * platform register operation is protected by the register_mutex. + */ +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) +{ + guard(mutex)(®ister_mutex); + if (platform_ops) + return -EEXIST; + + platform_ops =3D ops; + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_register_platform_ops); + +/* + * Unregisters the current set of platform operations. This allows for + * a new set to be registered if required. + * + * The platform unregister operation is protected by the register_mutex. + */ +int snd_usb_unregister_platform_ops(void) +{ + guard(mutex)(®ister_mutex); + platform_ops =3D NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); =20 /* * Checks to see if requested audio profile, i.e sample rate, # of @@ -954,7 +990,11 @@ static int usb_audio_probe(struct usb_interface *intf, chip->num_interfaces++; usb_set_intfdata(intf, chip); atomic_dec(&chip->active); + + if (platform_ops && platform_ops->connect_cb) + platform_ops->connect_cb(chip); mutex_unlock(®ister_mutex); + return 0; =20 __error: @@ -991,6 +1031,9 @@ static void usb_audio_disconnect(struct usb_interface = *intf) card =3D chip->card; =20 mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->disconnect_cb) + platform_ops->disconnect_cb(chip); + if (atomic_inc_return(&chip->shutdown) =3D=3D 1) { struct snd_usb_stream *as; struct snd_usb_endpoint *ep; @@ -1138,6 +1181,9 @@ static int usb_audio_suspend(struct usb_interface *in= tf, pm_message_t message) chip->system_suspend =3D chip->num_suspended_intf; } =20 + if (platform_ops && platform_ops->suspend_cb) + platform_ops->suspend_cb(intf, message); + return 0; } =20 @@ -1178,6 +1224,9 @@ static int usb_audio_resume(struct usb_interface *int= f) =20 snd_usb_midi_v2_resume_all(chip); =20 + if (platform_ops && platform_ops->resume_cb) + platform_ops->resume_cb(intf); + out: if (chip->num_suspended_intf =3D=3D chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); diff --git a/sound/usb/card.h b/sound/usb/card.h index cdafc9e9cecd..d8b8522e1613 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -209,7 +209,17 @@ struct snd_usb_stream { struct list_head list; }; =20 +struct snd_usb_platform_ops { + void (*connect_cb)(struct snd_usb_audio *chip); + void (*disconnect_cb)(struct snd_usb_audio *chip); + void (*suspend_cb)(struct usb_interface *intf, pm_message_t message); + void (*resume_cb)(struct usb_interface *intf); +}; + struct snd_usb_stream * snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *= params, int direction); + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); #endif /* __USBAUDIO_CARD_H */ From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78EA521019C; Wed, 6 Nov 2024 19:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; cv=none; b=XhQBqRI4GqSVqSM9phZlrGnzRjv8wp/unjuGJgh1hQy/akoAi4LeD1zRgPrSfLcxwRISzBsuqrMbCm0pdNwp9hj9tSzwzj79xLRtrWf6jUs1WadFQE+NCu3Q1I2PQLqLSJpha2hToLk0La1blWxhHc9gDEdBezRhfD0fX/gol6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; c=relaxed/simple; bh=9cdnbJPdjIkgUwVVDViOSctU4pwRwxYTjPMbwEvbRI8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NyIPXpE1Ks5hwUJ0F0c1vf5dC+Z1+nWwoeJJf/Dp1OjKwlUQ+n5hox/upi/X+60QCpj8x5hwP+OMbFTEvzFgHyIvrs8XzGbS+UWjeqE4/YlDBP0q08sNNl5ebigOtf1PcFdT42D/qB0trUf9HGLdKloHKy34RKee45J2T08LM70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=TXIRzj85; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TXIRzj85" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A69ORXx017647; Wed, 6 Nov 2024 19:34:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /iXWyJ+VSbDCGIDrA8mF4MYZ6p5L8xVjpkuwHayJnho=; b=TXIRzj85QpPyuJ7E SeRUNN3MLeq1wujHcLOyWOP1gzD74Xf6D5Ev4Lq+XNMexCJY/+4fPJjtbQEGkz6k B48QxK+4O2v0ii4b4WTpXrMi91GI6GXMjocfg66t7gFge7sbYRdnjmL6r43OOwF4 WjCXC4KNTpw3IvHCsXt+IPER/81qQLzskM/fJPAKlpfV4VX4pA/ReTgY00Pyw3NF GXgcPbfX+H+sSzRCVFjip5FMS/885b/4mmVMh8vZPi03QoGJhHZtQEYpM2AZk96c 0B0kSbyTPrbjL1FPayDq7xII16DnqXXRTH44iJXikLL0e3XnU+7G7j3gZmtetsrN CCXNqA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42q5n8pp7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYaeE012029 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 25/30] ALSA: usb-audio: qcom: Add USB QMI definitions Date: Wed, 6 Nov 2024 11:34:08 -0800 Message-ID: <20241106193413.1730413-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vJ9SVgRT2tVjfXSwP3KBJboQxQkfmty4 X-Proofpoint-ORIG-GUID: vJ9SVgRT2tVjfXSwP3KBJboQxQkfmty4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 Content-Type: text/plain; charset="utf-8" The Qualcomm USB audio offload driver utilizes the QMI protocol to communicate with the audio DSP. Add the necessary QMI header and field definitions, so the QMI interface driver is able to route the QMI packet received to the USB audio offload driver. Signed-off-by: Wesley Cheng --- sound/usb/qcom/usb_audio_qmi_v01.c | 863 +++++++++++++++++++++++++++++ sound/usb/qcom/usb_audio_qmi_v01.h | 164 ++++++ 2 files changed, 1027 insertions(+) create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.c create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.h diff --git a/sound/usb/qcom/usb_audio_qmi_v01.c b/sound/usb/qcom/usb_audio_= qmi_v01.c new file mode 100644 index 000000000000..5e8efbec3922 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.c @@ -0,0 +1,863 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#include + +#include "usb_audio_qmi_v01.h" + +static const struct qmi_elem_info mem_info_v01_ei[] =3D { + { + .data_type =3D QMI_UNSIGNED_8_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u64), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct mem_info_v01, va), + }, + { + .data_type =3D QMI_UNSIGNED_8_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u64), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct mem_info_v01, pa), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct mem_info_v01, size), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info apps_mem_info_v01_ei[] =3D { + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct apps_mem_info_v01, evt_ring), + .ei_array =3D mem_info_v01_ei, + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct apps_mem_info_v01, tr_data), + .ei_array =3D mem_info_v01_ei, + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct apps_mem_info_v01, tr_sync), + .ei_array =3D mem_info_v01_ei, + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct apps_mem_info_v01, xfer_buff), + .ei_array =3D mem_info_v01_ei, + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct apps_mem_info_v01, dcba), + .ei_array =3D mem_info_v01_ei, + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_endpoint_descriptor_v01_ei[] =3D { + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bLength), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bDescriptorType), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bEndpointAddress), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bmAttributes), + }, + { + .data_type =3D QMI_UNSIGNED_2_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u16), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + wMaxPacketSize), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bInterval), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bRefresh), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_endpoint_descriptor_v01, + bSynchAddress), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_interface_descriptor_v01_ei[] =3D { + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bLength), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bDescriptorType), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bInterfaceNumber), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bAlternateSetting), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bNumEndpoints), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bInterfaceClass), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bInterfaceSubClass), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + bInterfaceProtocol), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0, + .offset =3D offsetof(struct usb_interface_descriptor_v01, + iInterface), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[] =3D { + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x01, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + enable), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x02, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + usb_token), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[] =3D { + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct qmi_response_type_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x02, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + resp), + .ei_array =3D qmi_response_type_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + status_valid), + }, + { + .data_type =3D QMI_SIGNED_4_BYTE_ENUM, + .elem_len =3D 1, + .elem_size =3D sizeof(enum usb_qmi_audio_stream_status_enum_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + status), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + internal_status_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + internal_status), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + slot_id_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + slot_id), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_token_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_token), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_interface_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc), + .ei_array =3D usb_interface_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x15, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_endpoint_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x15, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc), + .ei_array =3D usb_endpoint_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x16, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_endpoint_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x16, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc), + .ei_array =3D usb_endpoint_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x17, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type =3D QMI_UNSIGNED_2_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u16), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x17, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x18, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x18, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x19, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x19, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1A, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct apps_mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1A, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info), + .ei_array =3D apps_mem_info_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1B, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1B, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1C, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + speed_info_valid), + }, + { + .data_type =3D QMI_SIGNED_4_BYTE_ENUM, + .elem_len =3D 1, + .elem_size =3D sizeof(enum usb_qmi_audio_device_speed_enum_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1C, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + speed_info), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1D, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + controller_num_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x1D, + .offset =3D offsetof(struct qmi_uaudio_stream_resp_msg_v01, + controller_num), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[] =3D { + { + .data_type =3D QMI_SIGNED_4_BYTE_ENUM, + .elem_len =3D 1, + .elem_size =3D sizeof( + enum usb_qmi_audio_device_indication_enum_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x01, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + dev_event), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x02, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + slot_id), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token_valid), + }, + { + .data_type =3D QMI_UNSIGNED_4_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u32), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x10, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_interface_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x11, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc), + .ei_array =3D usb_interface_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_endpoint_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x12, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc), + .ei_array =3D usb_endpoint_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct usb_endpoint_descriptor_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x13, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc), + .ei_array =3D usb_endpoint_descriptor_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type =3D QMI_UNSIGNED_2_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u16), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x14, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x15, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x15, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x16, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x16, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x17, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type =3D QMI_STRUCT, + .elem_len =3D 1, + .elem_size =3D sizeof(struct apps_mem_info_v01), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x17, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info), + .ei_array =3D apps_mem_info_v01_ei, + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x18, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x18, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num), + }, + { + .data_type =3D QMI_OPT_FLAG, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x19, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num_valid), + }, + { + .data_type =3D QMI_UNSIGNED_1_BYTE, + .elem_len =3D 1, + .elem_size =3D sizeof(u8), + .array_type =3D NO_ARRAY, + .tlv_type =3D 0x19, + .offset =3D offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num), + }, + { + .data_type =3D QMI_EOTI, + .array_type =3D NO_ARRAY, + .tlv_type =3D QMI_COMMON_TLV_TYPE, + }, +}; diff --git a/sound/usb/qcom/usb_audio_qmi_v01.h b/sound/usb/qcom/usb_audio_= qmi_v01.h new file mode 100644 index 000000000000..b549b025fe67 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.h @@ -0,0 +1,164 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#ifndef USB_QMI_V01_H +#define USB_QMI_V01_H + +#define UAUDIO_STREAM_SERVICE_ID_V01 0x41D +#define UAUDIO_STREAM_SERVICE_VERS_V01 0x01 + +#define QMI_UAUDIO_STREAM_RESP_V01 0x0001 +#define QMI_UAUDIO_STREAM_REQ_V01 0x0001 +#define QMI_UAUDIO_STREAM_IND_V01 0x0001 + +struct mem_info_v01 { + u64 va; + u64 pa; + u32 size; +}; + +struct apps_mem_info_v01 { + struct mem_info_v01 evt_ring; + struct mem_info_v01 tr_data; + struct mem_info_v01 tr_sync; + struct mem_info_v01 xfer_buff; + struct mem_info_v01 dcba; +}; + +struct usb_endpoint_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bEndpointAddress; + u8 bmAttributes; + u16 wMaxPacketSize; + u8 bInterval; + u8 bRefresh; + u8 bSynchAddress; +}; + +struct usb_interface_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bInterfaceNumber; + u8 bAlternateSetting; + u8 bNumEndpoints; + u8 bInterfaceClass; + u8 bInterfaceSubClass; + u8 bInterfaceProtocol; + u8 iInterface; +}; + +enum usb_qmi_audio_stream_status_enum_v01 { + USB_QMI_STREAM_STATUS_ENUM_MIN_VAL_V01 =3D INT_MIN, + USB_QMI_STREAM_REQ_SUCCESS_V01 =3D 0, + USB_QMI_STREAM_REQ_FAILURE_V01 =3D 1, + USB_QMI_STREAM_REQ_FAILURE_NOT_FOUND_V01 =3D 2, + USB_QMI_STREAM_REQ_FAILURE_INVALID_PARAM_V01 =3D 3, + USB_QMI_STREAM_REQ_FAILURE_MEMALLOC_V01 =3D 4, + USB_QMI_STREAM_STATUS_ENUM_MAX_VAL_V01 =3D INT_MAX, +}; + +enum usb_qmi_audio_device_indication_enum_v01 { + USB_QMI_DEVICE_INDICATION_ENUM_MIN_VAL_V01 =3D INT_MIN, + USB_QMI_DEV_CONNECT_V01 =3D 0, + USB_QMI_DEV_DISCONNECT_V01 =3D 1, + USB_QMI_DEV_SUSPEND_V01 =3D 2, + USB_QMI_DEV_RESUME_V01 =3D 3, + USB_QMI_DEVICE_INDICATION_ENUM_MAX_VAL_V01 =3D INT_MAX, +}; + +enum usb_qmi_audio_device_speed_enum_v01 { + USB_QMI_DEVICE_SPEED_ENUM_MIN_VAL_V01 =3D INT_MIN, + USB_QMI_DEVICE_SPEED_INVALID_V01 =3D 0, + USB_QMI_DEVICE_SPEED_LOW_V01 =3D 1, + USB_QMI_DEVICE_SPEED_FULL_V01 =3D 2, + USB_QMI_DEVICE_SPEED_HIGH_V01 =3D 3, + USB_QMI_DEVICE_SPEED_SUPER_V01 =3D 4, + USB_QMI_DEVICE_SPEED_SUPER_PLUS_V01 =3D 5, + USB_QMI_DEVICE_SPEED_ENUM_MAX_VAL_V01 =3D INT_MAX, +}; + +struct qmi_uaudio_stream_req_msg_v01 { + u8 enable; + u32 usb_token; + u8 audio_format_valid; + u32 audio_format; + u8 number_of_ch_valid; + u32 number_of_ch; + u8 bit_rate_valid; + u32 bit_rate; + u8 xfer_buff_size_valid; + u32 xfer_buff_size; + u8 service_interval_valid; + u32 service_interval; +}; + +#define QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN 46 +extern const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[]; + +struct qmi_uaudio_stream_resp_msg_v01 { + struct qmi_response_type_v01 resp; + u8 status_valid; + enum usb_qmi_audio_stream_status_enum_v01 status; + u8 internal_status_valid; + u32 internal_status; + u8 slot_id_valid; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 speed_info_valid; + enum usb_qmi_audio_device_speed_enum_v01 speed_info; + u8 controller_num_valid; + u8 controller_num; +}; + +#define QMI_UAUDIO_STREAM_RESP_MSG_V01_MAX_MSG_LEN 202 +extern const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[]; + +struct qmi_uaudio_stream_ind_msg_v01 { + enum usb_qmi_audio_device_indication_enum_v01 dev_event; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 controller_num_valid; + u8 controller_num; +}; + +#define QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN 181 +extern const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[]; + +#endif From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 759E7209F3B; Wed, 6 Nov 2024 19:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921705; cv=none; b=nZMaqbCzKWwcaJ977z3yKD7tJJTXKs46SftqPxjShGg6jsC+R7WlSitd2aIsGWxojduhmyKN+6sLZthzUggKg1ssam8nBiQPdKpdRfjMN5SiRcsbilT14bkvkvV59rNX0tQcg20+1JMnRV6bJw1ehB0VPqBhCzHdGJYrzhEvbN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921705; c=relaxed/simple; bh=Nhgx5ltCIvSUOnjoqEQ8fwUTrcZtiOHEP6H9jkfE/jU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bU7PyFaIu/DHtAJaDO1BsRAqofTGOE+gEj/i1qvbLt1TA6uXZCRbeQwqlONiCYjubbrg5YV7M8Es1hqi1u1/CL49DlaINRvRRanyL0M6M55SlzB52ni/8Ht2IG5OyqCDGUmOhsrgH6FbxnpuzyfLa/uOpWEr976dRUv3RWcBSAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=lLKNIvUn; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lLKNIvUn" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6AVE5w002942; Wed, 6 Nov 2024 19:34:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= zzQhwZbImab9sFYHAJlrNB0PzzEHFKmeVN96+QtYlNs=; b=lLKNIvUnro1axjep Nahofu11n15DvAAo5X+1uUUEJYwjUAGCnQ6yRAcRjhm6zrTB8jnh68XbJJ/F0teu 8cdrK3L26CN3GGEdg6FoZNmpFULnknDlTKTmJp8tSmMNNMDmJGSPo/EPpHzRCTuI looVRQMB8KYrsBlBWrtu8HEYGrqcGnIiZ9OiFWi1pNZJ7VFncm/0KwiwmJC4a4MK nRfQp9Qs4vDtVMDqXD14FDH7N+K5FrwNtl/XqFqYy5dCvuDR7g9os1pkjlfaG9xr W3G5ZDH6JCZSr/YWl8tZqCESv36AiJj4wHtqWpWDGhWpgBiPLuyqmaZ++0xQSyAG 3JNqyA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYbTO008676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 26/30] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Date: Wed, 6 Nov 2024 11:34:09 -0800 Message-ID: <20241106193413.1730413-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: CfF8weD85PJV4Te7yTYRkPfnqJO_3vFz X-Proofpoint-GUID: CfF8weD85PJV4Te7yTYRkPfnqJO_3vFz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Several Qualcomm SoCs have a dedicated audio DSP, which has the ability to support USB sound devices. This vendor driver will implement the required handshaking with the DSP, in order to pass along required resources that will be utilized by the DSP's USB SW. The communication channel used for this handshaking will be using the QMI protocol. Required resources include: - Allocated secondary event ring address - EP transfer ring address - Interrupter number The above information will allow for the audio DSP to execute USB transfers over the USB bus. It will also be able to support devices that have an implicit feedback and sync endpoint as well. Offloading these data transfers will allow the main/applications processor to enter lower CPU power modes, and sustain a longer duration in those modes. Audio offloading is initiated with the following sequence: 1. Userspace configures to route audio playback to USB backend and starts playback on the platform soundcard. 2. The Q6DSP AFE will communicate to the audio DSP to start the USB AFE port. 3. This results in a QMI packet with a STREAM enable command. 4. The QC audio offload driver will fetch the required resources, and pass this information as part of the QMI response to the STREAM enable command. 5. Once the QMI response is received the audio DSP will start queuing data on the USB bus. As part of step#2, the audio DSP is aware of the USB SND card and pcm device index that is being selected, and is communicated as part of the QMI request received by QC audio offload. These indices will be used to handle the stream enable QMI request. Signed-off-by: Wesley Cheng --- sound/usb/Kconfig | 15 + sound/usb/Makefile | 2 +- sound/usb/qcom/Makefile | 2 + sound/usb/qcom/qc_audio_offload.c | 1957 +++++++++++++++++++++++++++++ 4 files changed, 1975 insertions(+), 1 deletion(-) create mode 100644 sound/usb/qcom/Makefile create mode 100644 sound/usb/qcom/qc_audio_offload.c diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 4a9569a3a39a..d0f65311894f 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,6 +176,21 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. =20 +config SND_USB_AUDIO_QMI + tristate "Qualcomm Audio Offload driver" + depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SEC_INTR && SND_= SOC_USB + select SND_PCM + help + Say Y here to enable the Qualcomm USB audio offloading feature. + + This module sets up the required QMI stream enable/disable + responses to requests generated by the audio DSP. It passes the + USB transfer resource references, so that the audio DSP can issue + USB transfers to the host controller. + + To compile this driver as a module, choose M here: the module + will be called snd-usb-audio-qmi. + source "sound/usb/line6/Kconfig" =20 endif # SND_USB diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 0532499dbc6d..54a06a2f73ca 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -34,5 +34,5 @@ obj-$(CONFIG_SND_USB_UA101) +=3D snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_USX2Y) +=3D snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_US122L) +=3D snd-usbmidi-lib.o =20 -obj-$(CONFIG_SND) +=3D misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ +obj-$(CONFIG_SND) +=3D misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ qcom/ obj-$(CONFIG_SND_USB_LINE6) +=3D line6/ diff --git a/sound/usb/qcom/Makefile b/sound/usb/qcom/Makefile new file mode 100644 index 000000000000..a81c9b28d484 --- /dev/null +++ b/sound/usb/qcom/Makefile @@ -0,0 +1,2 @@ +snd-usb-audio-qmi-objs :=3D usb_audio_qmi_v01.o qc_audio_offload.o +obj-$(CONFIG_SND_USB_AUDIO_QMI) +=3D snd-usb-audio-qmi.o \ No newline at end of file diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c new file mode 100644 index 000000000000..4ef7c949a6ee --- /dev/null +++ b/sound/usb/qcom/qc_audio_offload.c @@ -0,0 +1,1957 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../usbaudio.h" +#include "../card.h" +#include "../endpoint.h" +#include "../format.h" +#include "../helper.h" +#include "../pcm.h" +#include "../power.h" + +#include "usb_audio_qmi_v01.h" + +/* Stream disable request timeout during USB device disconnect */ +#define DEV_RELEASE_WAIT_TIMEOUT 10000 /* in ms */ + +/* Data interval calculation parameters */ +#define BUS_INTERVAL_FULL_SPEED 1000 /* in us */ +#define BUS_INTERVAL_HIGHSPEED_AND_ABOVE 125 /* in us */ +#define MAX_BINTERVAL_ISOC_EP 16 + +#define QMI_STREAM_REQ_CARD_NUM_MASK 0xffff0000 +#define QMI_STREAM_REQ_DEV_NUM_MASK 0xff00 +#define QMI_STREAM_REQ_DIRECTION 0xff + +/* iommu resource parameters and management */ +#define PREPEND_SID_TO_IOVA(iova, sid) ((u64)(((u64)(iova)) | \ + (((u64)sid) << 32))) +#define IOVA_MASK(iova) (((u64)(iova)) & 0xFFFFFFFF) +#define IOVA_BASE 0x1000 +#define IOVA_XFER_RING_BASE (IOVA_BASE + PAGE_SIZE * (SNDRV_CARDS + 1)) +#define IOVA_XFER_BUF_BASE (IOVA_XFER_RING_BASE + PAGE_SIZE * SNDRV_CARDS = * 32) +#define IOVA_XFER_RING_MAX (IOVA_XFER_BUF_BASE - PAGE_SIZE) +#define IOVA_XFER_BUF_MAX (0xfffff000 - PAGE_SIZE) + +#define MAX_XFER_BUFF_LEN (24 * PAGE_SIZE) + +struct iova_info { + struct list_head list; + unsigned long start_iova; + size_t size; + bool in_use; +}; + +struct intf_info { + unsigned long data_xfer_ring_va; + size_t data_xfer_ring_size; + unsigned long sync_xfer_ring_va; + size_t sync_xfer_ring_size; + unsigned long xfer_buf_va; + size_t xfer_buf_size; + phys_addr_t xfer_buf_pa; + unsigned int data_ep_pipe; + unsigned int sync_ep_pipe; + u8 *xfer_buf; + u8 intf_num; + u8 pcm_card_num; + u8 pcm_dev_num; + u8 direction; + bool in_use; +}; + +struct uaudio_qmi_dev { + struct device *dev; + struct q6usb_offload *data; + + /* list to keep track of available iova */ + struct list_head xfer_ring_list; + size_t xfer_ring_iova_size; + unsigned long curr_xfer_ring_iova; + struct list_head xfer_buf_list; + size_t xfer_buf_iova_size; + unsigned long curr_xfer_buf_iova; + + /* bit fields representing pcm card enabled */ + unsigned long card_slot; + /* indicate event ring mapped or not */ + bool er_mapped; + /* reference count to number of possible consumers */ + atomic_t qdev_in_use; +}; + +struct uaudio_dev { + struct usb_device *udev; + /* audio control interface */ + struct usb_host_interface *ctrl_intf; + unsigned int usb_core_id; + atomic_t in_use; + struct kref kref; + wait_queue_head_t disconnect_wq; + + /* interface specific */ + int num_intf; + struct intf_info *info; + struct snd_usb_audio *chip; + + /* xhci secondary interrupter */ + struct xhci_sec_intr *si; + + /* SoC USB device */ + struct snd_soc_usb_device *sdev; +}; + +static struct uaudio_dev uadev[SNDRV_CARDS]; +static struct uaudio_qmi_dev *uaudio_qdev; +static struct uaudio_qmi_svc *uaudio_svc; +static DEFINE_MUTEX(qdev_mutex); + +struct uaudio_qmi_svc { + struct qmi_handle *uaudio_svc_hdl; + struct sockaddr_qrtr client_sq; + bool client_connected; +}; + +enum mem_type { + MEM_EVENT_RING, + MEM_XFER_RING, + MEM_XFER_BUF, +}; + +/* Supported audio formats */ +enum usb_qmi_audio_format { + USB_QMI_PCM_FORMAT_S8 =3D 0, + USB_QMI_PCM_FORMAT_U8, + USB_QMI_PCM_FORMAT_S16_LE, + USB_QMI_PCM_FORMAT_S16_BE, + USB_QMI_PCM_FORMAT_U16_LE, + USB_QMI_PCM_FORMAT_U16_BE, + USB_QMI_PCM_FORMAT_S24_LE, + USB_QMI_PCM_FORMAT_S24_BE, + USB_QMI_PCM_FORMAT_U24_LE, + USB_QMI_PCM_FORMAT_U24_BE, + USB_QMI_PCM_FORMAT_S24_3LE, + USB_QMI_PCM_FORMAT_S24_3BE, + USB_QMI_PCM_FORMAT_U24_3LE, + USB_QMI_PCM_FORMAT_U24_3BE, + USB_QMI_PCM_FORMAT_S32_LE, + USB_QMI_PCM_FORMAT_S32_BE, + USB_QMI_PCM_FORMAT_U32_LE, + USB_QMI_PCM_FORMAT_U32_BE, +}; + +static int usb_qmi_get_pcm_num(struct snd_usb_audio *chip, int direction) +{ + struct snd_usb_substream *subs =3D NULL; + struct snd_usb_stream *as; + int count =3D 0; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs =3D &as->substream[direction]; + if (subs->ep_num) + count++; + } + + return count; +} + +static enum usb_qmi_audio_device_speed_enum_v01 +get_speed_info(enum usb_device_speed udev_speed) +{ + switch (udev_speed) { + case USB_SPEED_LOW: + return USB_QMI_DEVICE_SPEED_LOW_V01; + case USB_SPEED_FULL: + return USB_QMI_DEVICE_SPEED_FULL_V01; + case USB_SPEED_HIGH: + return USB_QMI_DEVICE_SPEED_HIGH_V01; + case USB_SPEED_SUPER: + return USB_QMI_DEVICE_SPEED_SUPER_V01; + case USB_SPEED_SUPER_PLUS: + return USB_QMI_DEVICE_SPEED_SUPER_PLUS_V01; + default: + return USB_QMI_DEVICE_SPEED_INVALID_V01; + } +} + +static struct snd_usb_substream *find_substream(unsigned int card_num, + unsigned int pcm_idx, + unsigned int direction) +{ + struct snd_usb_substream *subs =3D NULL; + struct snd_usb_audio *chip; + struct snd_usb_stream *as; + + chip =3D uadev[card_num].chip; + if (!chip || atomic_read(&chip->shutdown)) + goto done; + + if (pcm_idx >=3D chip->pcm_devs) + goto done; + + if (direction > SNDRV_PCM_STREAM_CAPTURE) + goto done; + + list_for_each_entry(as, &chip->pcm_list, list) { + if (as->pcm_index =3D=3D pcm_idx) { + subs =3D &as->substream[direction]; + goto done; + } + } + +done: + return subs; +} + +static int info_idx_from_ifnum(int card_num, int intf_num, bool enable) +{ + int i; + + /* + * default index 0 is used when info is allocated upon + * first enable audio stream req for a pcm device + */ + if (enable && !uadev[card_num].info) + return 0; + + for (i =3D 0; i < uadev[card_num].num_intf; i++) { + if (enable && !uadev[card_num].info[i].in_use) + return i; + else if (!enable && + uadev[card_num].info[i].intf_num =3D=3D intf_num) + return i; + } + + return -EINVAL; +} + +static int get_data_interval_from_si(struct snd_usb_substream *subs, + u32 service_interval) +{ + unsigned int bus_intval_mult; + unsigned int bus_intval; + unsigned int binterval; + + if (subs->dev->speed >=3D USB_SPEED_HIGH) + bus_intval =3D BUS_INTERVAL_HIGHSPEED_AND_ABOVE; + else + bus_intval =3D BUS_INTERVAL_FULL_SPEED; + + if (service_interval % bus_intval) + return -EINVAL; + + bus_intval_mult =3D service_interval / bus_intval; + binterval =3D ffs(bus_intval_mult); + if (!binterval || binterval > MAX_BINTERVAL_ISOC_EP) + return -EINVAL; + + /* check if another bit is set then bail out */ + bus_intval_mult =3D bus_intval_mult >> binterval; + if (bus_intval_mult) + return -EINVAL; + + return (binterval - 1); +} + +/* maps audio format received over QMI to asound.h based pcm format */ +static snd_pcm_format_t map_pcm_format(enum usb_qmi_audio_format fmt_recei= ved) +{ + switch (fmt_received) { + case USB_QMI_PCM_FORMAT_S8: + return SNDRV_PCM_FORMAT_S8; + case USB_QMI_PCM_FORMAT_U8: + return SNDRV_PCM_FORMAT_U8; + case USB_QMI_PCM_FORMAT_S16_LE: + return SNDRV_PCM_FORMAT_S16_LE; + case USB_QMI_PCM_FORMAT_S16_BE: + return SNDRV_PCM_FORMAT_S16_BE; + case USB_QMI_PCM_FORMAT_U16_LE: + return SNDRV_PCM_FORMAT_U16_LE; + case USB_QMI_PCM_FORMAT_U16_BE: + return SNDRV_PCM_FORMAT_U16_BE; + case USB_QMI_PCM_FORMAT_S24_LE: + return SNDRV_PCM_FORMAT_S24_LE; + case USB_QMI_PCM_FORMAT_S24_BE: + return SNDRV_PCM_FORMAT_S24_BE; + case USB_QMI_PCM_FORMAT_U24_LE: + return SNDRV_PCM_FORMAT_U24_LE; + case USB_QMI_PCM_FORMAT_U24_BE: + return SNDRV_PCM_FORMAT_U24_BE; + case USB_QMI_PCM_FORMAT_S24_3LE: + return SNDRV_PCM_FORMAT_S24_3LE; + case USB_QMI_PCM_FORMAT_S24_3BE: + return SNDRV_PCM_FORMAT_S24_3BE; + case USB_QMI_PCM_FORMAT_U24_3LE: + return SNDRV_PCM_FORMAT_U24_3LE; + case USB_QMI_PCM_FORMAT_U24_3BE: + return SNDRV_PCM_FORMAT_U24_3BE; + case USB_QMI_PCM_FORMAT_S32_LE: + return SNDRV_PCM_FORMAT_S32_LE; + case USB_QMI_PCM_FORMAT_S32_BE: + return SNDRV_PCM_FORMAT_S32_BE; + case USB_QMI_PCM_FORMAT_U32_LE: + return SNDRV_PCM_FORMAT_U32_LE; + case USB_QMI_PCM_FORMAT_U32_BE: + return SNDRV_PCM_FORMAT_U32_BE; + default: + /* + * We expect the caller to do input validation so we should + * never hit this. But we do have to return a proper + * snd_pcm_format_t value due to the __bitwise attribute; so + * just return the equivalent of 0 in case of bad input. + */ + return SNDRV_PCM_FORMAT_S8; + } +} + +/* Offloading IOMMU management */ +static unsigned long uaudio_get_iova(unsigned long *curr_iova, + size_t *curr_iova_size, + struct list_head *head, size_t size) +{ + struct iova_info *info, *new_info =3D NULL; + struct list_head *curr_head; + size_t tmp_size =3D size; + unsigned long va =3D 0; + bool found =3D false; + + if (size % PAGE_SIZE) + goto done; + + if (size > *curr_iova_size) + goto done; + + if (*curr_iova_size =3D=3D 0) + goto done; + + list_for_each_entry(info, head, list) { + /* exact size iova_info */ + if (!info->in_use && info->size =3D=3D size) { + info->in_use =3D true; + va =3D info->start_iova; + *curr_iova_size -=3D size; + found =3D true; + goto done; + } else if (!info->in_use && tmp_size >=3D info->size) { + if (!new_info) + new_info =3D info; + tmp_size -=3D info->size; + if (tmp_size) + continue; + + va =3D new_info->start_iova; + for (curr_head =3D &new_info->list; curr_head !=3D + &info->list; curr_head =3D curr_head->next) { + new_info =3D list_entry(curr_head, struct + iova_info, list); + new_info->in_use =3D true; + } + info->in_use =3D true; + *curr_iova_size -=3D size; + found =3D true; + goto done; + } else { + /* iova region in use */ + new_info =3D NULL; + tmp_size =3D size; + } + } + + info =3D kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) { + va =3D 0; + goto done; + } + + va =3D *curr_iova; + info->start_iova =3D *curr_iova; + info->size =3D size; + info->in_use =3D true; + *curr_iova +=3D size; + *curr_iova_size -=3D size; + found =3D true; + list_add_tail(&info->list, head); + +done: + return va; +} + +static void uaudio_put_iova(unsigned long va, size_t size, struct list_head + *head, size_t *curr_iova_size) +{ + struct iova_info *info; + size_t tmp_size =3D size; + bool found =3D false; + + list_for_each_entry(info, head, list) { + if (info->start_iova =3D=3D va) { + if (!info->in_use) + return; + + found =3D true; + info->in_use =3D false; + if (info->size =3D=3D size) + goto done; + } + + if (found && tmp_size >=3D info->size) { + info->in_use =3D false; + tmp_size -=3D info->size; + if (!tmp_size) + goto done; + } + } + + if (!found) + return; + +done: + *curr_iova_size +=3D size; +} + +/** + * uaudio_iommu_unmap() - unmaps iommu memory for adsp + * @mtype: ring type + * @va: virtual address to unmap + * @iova_size: region size + * @mapped_iova_size: mapped region size + * + * Unmaps the memory region that was previously assigned to the adsp. + * + */ +static void uaudio_iommu_unmap(enum mem_type mtype, unsigned long va, + size_t iova_size, size_t mapped_iova_size) +{ + size_t umap_size; + bool unmap =3D true; + + if (!va || !iova_size) + return; + + switch (mtype) { + case MEM_EVENT_RING: + if (uaudio_qdev->er_mapped) + uaudio_qdev->er_mapped =3D false; + else + unmap =3D false; + break; + + case MEM_XFER_RING: + uaudio_put_iova(va, iova_size, &uaudio_qdev->xfer_ring_list, + &uaudio_qdev->xfer_ring_iova_size); + break; + case MEM_XFER_BUF: + uaudio_put_iova(va, iova_size, &uaudio_qdev->xfer_buf_list, + &uaudio_qdev->xfer_buf_iova_size); + break; + default: + unmap =3D false; + } + + if (!unmap || !mapped_iova_size) + return; + + umap_size =3D iommu_unmap(uaudio_qdev->data->domain, va, mapped_iova_size= ); + if (umap_size !=3D mapped_iova_size) + dev_err(uaudio_qdev->data->dev, + "unmapped size %zu for iova 0x%08lx of mapped size %zu\n", + umap_size, va, mapped_iova_size); +} + +/** + * uaudio_iommu_map() - maps iommu memory for adsp + * @mtype: ring type + * @dma_coherent: dma coherent + * @pa: physical address for ring/buffer + * @size: size of memory region + * @sgt: sg table for memory region + * + * Maps the XHCI related resources to a memory region that is assigned to = be + * used by the adsp. This will be mapped to the domain, which is created = by + * the ASoC USB backend driver. + * + */ +static unsigned long uaudio_iommu_map(enum mem_type mtype, bool dma_cohere= nt, + phys_addr_t pa, size_t size, + struct sg_table *sgt) +{ + struct scatterlist *sg; + unsigned long va =3D 0; + size_t total_len =3D 0; + unsigned long va_sg; + phys_addr_t pa_sg; + bool map =3D true; + size_t sg_len; + int prot; + int ret; + int i; + + prot =3D IOMMU_READ | IOMMU_WRITE; + + if (dma_coherent) + prot |=3D IOMMU_CACHE; + + switch (mtype) { + case MEM_EVENT_RING: + va =3D IOVA_BASE; + /* er already mapped */ + if (uaudio_qdev->er_mapped) + map =3D false; + break; + case MEM_XFER_RING: + va =3D uaudio_get_iova(&uaudio_qdev->curr_xfer_ring_iova, + &uaudio_qdev->xfer_ring_iova_size, + &uaudio_qdev->xfer_ring_list, size); + break; + case MEM_XFER_BUF: + va =3D uaudio_get_iova(&uaudio_qdev->curr_xfer_buf_iova, + &uaudio_qdev->xfer_buf_iova_size, + &uaudio_qdev->xfer_buf_list, size); + break; + default: + dev_err(uaudio_qdev->data->dev, "unknown mem type %d\n", mtype); + } + + if (!va || !map) + goto done; + + if (!sgt) + goto skip_sgt_map; + + va_sg =3D va; + for_each_sg(sgt->sgl, sg, sgt->nents, i) { + sg_len =3D PAGE_ALIGN(sg->offset + sg->length); + pa_sg =3D page_to_phys(sg_page(sg)); + ret =3D iommu_map(uaudio_qdev->data->domain, va_sg, pa_sg, sg_len, + prot, GFP_KERNEL); + if (ret) { + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va =3D 0; + goto done; + } + + va_sg +=3D sg_len; + total_len +=3D sg_len; + } + + if (size !=3D total_len) { + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va =3D 0; + } + return va; + +skip_sgt_map: + iommu_map(uaudio_qdev->data->domain, va, pa, size, prot, GFP_KERNEL); + +done: + return va; +} + +/* looks up alias, if any, for controller DT node and returns the index */ +static int usb_get_controller_id(struct usb_device *udev) +{ + if (udev->bus->sysdev && udev->bus->sysdev->of_node) + return of_alias_get_id(udev->bus->sysdev->of_node, "usb"); + + return -ENODEV; +} + +/** + * uaudio_dev_intf_cleanup() - cleanup transfer resources + * @udev: usb device + * @info: usb offloading interface + * + * Cleans up the transfer ring related resources which are assigned per + * endpoint from XHCI. This is invoked when the USB endpoints are no + * longer in use by the adsp. + * + */ +static void uaudio_dev_intf_cleanup(struct usb_device *udev, struct intf_i= nfo *info) +{ + uaudio_iommu_unmap(MEM_XFER_RING, info->data_xfer_ring_va, + info->data_xfer_ring_size, info->data_xfer_ring_size); + info->data_xfer_ring_va =3D 0; + info->data_xfer_ring_size =3D 0; + + uaudio_iommu_unmap(MEM_XFER_RING, info->sync_xfer_ring_va, + info->sync_xfer_ring_size, info->sync_xfer_ring_size); + info->sync_xfer_ring_va =3D 0; + info->sync_xfer_ring_size =3D 0; + + uaudio_iommu_unmap(MEM_XFER_BUF, info->xfer_buf_va, info->xfer_buf_size, + info->xfer_buf_size); + info->xfer_buf_va =3D 0; + + usb_free_coherent(udev, info->xfer_buf_size, info->xfer_buf, + info->xfer_buf_pa); + info->xfer_buf_size =3D 0; + info->xfer_buf =3D NULL; + info->xfer_buf_pa =3D 0; + + info->in_use =3D false; +} + +/** + * uaudio_event_ring_cleanup_free() - cleanup secondary event ring + * @dev: usb offload device + * + * Cleans up the secondary event ring that was requested. This will + * occur when the adsp is no longer transferring data on the USB bus + * across all endpoints. + * + */ +static void uaudio_event_ring_cleanup_free(struct uaudio_dev *dev) +{ + clear_bit(dev->chip->card->number, &uaudio_qdev->card_slot); + /* all audio devices are disconnected */ + if (!uaudio_qdev->card_slot) { + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, + PAGE_SIZE); + xhci_sec_intr_remove_interrupter(uadev[dev->chip->card->number].si); + } +} + +static void uaudio_dev_cleanup(struct uaudio_dev *dev) +{ + int if_idx; + + if (!dev->udev) + return; + + /* free xfer buffer and unmap xfer ring and buf per interface */ + for (if_idx =3D 0; if_idx < dev->num_intf; if_idx++) { + if (!dev->info[if_idx].in_use) + continue; + uaudio_dev_intf_cleanup(dev->udev, &dev->info[if_idx]); + dev_dbg(uaudio_qdev->data->dev, + "release resources: intf# %d card# %d\n", + dev->info[if_idx].intf_num, dev->chip->card->number); + } + + dev->num_intf =3D 0; + + /* free interface info */ + kfree(dev->info); + dev->info =3D NULL; + uaudio_event_ring_cleanup_free(dev); + dev->udev =3D NULL; +} + +/** + * disable_audio_stream() - disable usb snd endpoints + * @subs: usb substream + * + * Closes the USB SND endpoints associated with the current audio stream + * used. This will decrement the USB SND endpoint opened reference count. + * + */ +static void disable_audio_stream(struct snd_usb_substream *subs) +{ + struct snd_usb_audio *chip =3D subs->stream->chip; + + snd_usb_hw_free(subs); + snd_usb_autosuspend(chip); +} + +/* QMI service disconnect handlers */ +static void qmi_stop_session(void) +{ + struct snd_usb_substream *subs; + struct usb_host_endpoint *ep; + struct snd_usb_audio *chip; + struct intf_info *info; + int pcm_card_num; + int if_idx; + int idx; + + mutex_lock(&qdev_mutex); + /* find all active intf for set alt 0 and cleanup usb audio dev */ + for (idx =3D 0; idx < SNDRV_CARDS; idx++) { + if (!atomic_read(&uadev[idx].in_use)) + continue; + + chip =3D uadev[idx].chip; + for (if_idx =3D 0; if_idx < uadev[idx].num_intf; if_idx++) { + if (!uadev[idx].info || !uadev[idx].info[if_idx].in_use) + continue; + info =3D &uadev[idx].info[if_idx]; + pcm_card_num =3D info->pcm_card_num; + subs =3D find_substream(pcm_card_num, info->pcm_dev_num, + info->direction); + if (!subs || !chip || atomic_read(&chip->shutdown)) { + dev_err(&subs->dev->dev, + "no sub for c#%u dev#%u dir%u\n", + info->pcm_card_num, + info->pcm_dev_num, + info->direction); + continue; + } + /* Release XHCI endpoints */ + if (info->data_ep_pipe) + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->data_ep_pipe); + xhci_sec_intr_remove_endpoint(uadev[pcm_card_num].si, ep); + + if (info->sync_ep_pipe) + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + xhci_sec_intr_remove_endpoint(uadev[pcm_card_num].si, ep); + + disable_audio_stream(subs); + } + atomic_set(&uadev[idx].in_use, 0); + mutex_lock(&chip->mutex); + uaudio_dev_cleanup(&uadev[idx]); + mutex_unlock(&chip->mutex); + } + mutex_unlock(&qdev_mutex); +} + +/** + * qmi_bye_cb() - qmi bye message callback + * @handle: QMI handle + * @node: id of the dying node + * + * This callback is invoked when the QMI bye control message is received + * from the QMI client. Handle the message accordingly by ensuring that + * the USB offload path is disabled and cleaned up. At this point, ADSP + * is not utilizing the USB bus. + * + */ +static void qmi_bye_cb(struct qmi_handle *handle, unsigned int node) +{ + struct uaudio_qmi_svc *svc =3D uaudio_svc; + + if (svc->uaudio_svc_hdl !=3D handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node =3D=3D node) { + qmi_stop_session(); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node =3D 0; + svc->client_sq.sq_port =3D 0; + svc->client_sq.sq_family =3D 0; + svc->client_connected =3D false; + } +} + +/** + * qmi_svc_disconnect_cb() - qmi client disconnected + * @handle: QMI handle + * @node: id of the dying node + * @port: port of the dying client + * + * Invoked when the remote QMI client is disconnected. Handle this event + * the same way as when the QMI bye message is received. This will ensure + * the USB offloading path is disabled and cleaned up. + * + */ +static void qmi_svc_disconnect_cb(struct qmi_handle *handle, + unsigned int node, unsigned int port) +{ + struct uaudio_qmi_svc *svc; + + if (!uaudio_svc) + return; + + svc =3D uaudio_svc; + if (svc->uaudio_svc_hdl !=3D handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node =3D=3D node && + svc->client_sq.sq_port =3D=3D port) { + qmi_stop_session(); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node =3D 0; + svc->client_sq.sq_port =3D 0; + svc->client_sq.sq_family =3D 0; + svc->client_connected =3D false; + } +} + +/* QMI client callback handlers from QMI interface */ +static struct qmi_ops uaudio_svc_ops_options =3D { + .bye =3D qmi_bye_cb, + .del_client =3D qmi_svc_disconnect_cb, +}; + +/* kref release callback when all streams are disabled */ +static void uaudio_dev_release(struct kref *kref) +{ + struct uaudio_dev *dev =3D container_of(kref, struct uaudio_dev, kref); + + uaudio_event_ring_cleanup_free(dev); + atomic_set(&dev->in_use, 0); + wake_up(&dev->disconnect_wq); +} + +/** + * enable_audio_stream() - enable usb snd endpoints + * @subs: usb substream + * @pcm_format: pcm format requested + * @channels: number of channels + * @cur_rate: sample rate + * @datainterval: interval + * + * Opens all USB SND endpoints used for the data interface. This will inc= rement + * the USB SND endpoint's opened count. Requests to keep the interface re= sumed + * until the audio stream is stopped. Will issue the USB set interface co= ntrol + * message to enable the data interface. + * + */ +static int enable_audio_stream(struct snd_usb_substream *subs, + snd_pcm_format_t pcm_format, + unsigned int channels, unsigned int cur_rate, + int datainterval) +{ + struct snd_pcm_hw_params params; + struct snd_usb_audio *chip; + struct snd_interval *i; + struct snd_mask *m; + int ret; + + chip =3D subs->stream->chip; + + _snd_pcm_hw_params_any(¶ms); + + m =3D hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT); + snd_mask_leave(m, pcm_format); + + i =3D hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS); + snd_interval_setinteger(i); + i->min =3D channels; + i->max =3D channels; + + i =3D hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE); + snd_interval_setinteger(i); + i->min =3D cur_rate; + i->max =3D cur_rate; + + pm_runtime_barrier(&chip->intf[0]->dev); + snd_usb_autoresume(chip); + + ret =3D snd_usb_hw_params(subs, ¶ms); + if (ret < 0) + goto put_suspend; + + if (!atomic_read(&chip->shutdown)) { + ret =3D snd_usb_lock_shutdown(chip); + if (ret < 0) + goto detach_ep; + + if (subs->sync_endpoint) { + ret =3D snd_usb_endpoint_prepare(chip, subs->sync_endpoint); + if (ret < 0) + goto unlock; + } + + ret =3D snd_usb_endpoint_prepare(chip, subs->data_endpoint); + if (ret < 0) + goto unlock; + + snd_usb_unlock_shutdown(chip); + + dev_dbg(uaudio_qdev->data->dev, + "selected %s iface:%d altsetting:%d datainterval:%dus\n", + subs->direction ? "capture" : "playback", + subs->cur_audiofmt->iface, subs->cur_audiofmt->altsetting, + (1 << subs->cur_audiofmt->datainterval) * + (subs->dev->speed >=3D USB_SPEED_HIGH ? + BUS_INTERVAL_HIGHSPEED_AND_ABOVE : + BUS_INTERVAL_FULL_SPEED)); + } + + return 0; + +unlock: + snd_usb_unlock_shutdown(chip); + +detach_ep: + snd_usb_hw_free(subs); + +put_suspend: + snd_usb_autosuspend(chip); + + return ret; +} + +/* returns usb hcd sysdev */ +static struct device *usb_get_usb_backend(struct usb_device *udev) +{ + if (udev->bus->sysdev && udev->bus->sysdev->of_node) + return udev->bus->sysdev; + + return NULL; +} + +/** + * uaudio_transfer_buffer_setup() - fetch and populate xfer buffer params + * @subs: usb substream + * @xfer_buf: xfer buf to be allocated + * @xfer_buf_len: size of allocation + * @mem_info: QMI response info + * + * Allocates and maps the transfer buffers that will be utilized by the + * audio DSP. Will populate the information in the QMI response that is + * sent back to the stream enable request. + * + */ +static int uaudio_transfer_buffer_setup(struct snd_usb_substream *subs, + u8 *xfer_buf, u32 xfer_buf_len, + struct mem_info_v01 *mem_info) +{ + struct sg_table xfer_buf_sgt; + phys_addr_t xfer_buf_pa; + u32 len =3D xfer_buf_len; + bool dma_coherent; + unsigned long va; + u32 remainder; + u32 mult; + int ret; + + dma_coherent =3D dev_is_dma_coherent(subs->dev->bus->sysdev); + + /* xfer buffer, multiple of 4K only */ + if (!len) + len =3D PAGE_SIZE; + + mult =3D len / PAGE_SIZE; + remainder =3D len % PAGE_SIZE; + len =3D mult * PAGE_SIZE; + len +=3D remainder ? PAGE_SIZE : 0; + + if (len > MAX_XFER_BUFF_LEN) { + dev_err(uaudio_qdev->data->dev, + "req buf len %d > max buf len %lu, setting %lu\n", + len, MAX_XFER_BUFF_LEN, MAX_XFER_BUFF_LEN); + len =3D MAX_XFER_BUFF_LEN; + } + + xfer_buf =3D usb_alloc_coherent(subs->dev, len, GFP_KERNEL, &xfer_buf_pa); + if (!xfer_buf) + return -ENOMEM; + + dma_get_sgtable(subs->dev->bus->sysdev, &xfer_buf_sgt, xfer_buf, + xfer_buf_pa, len); + va =3D uaudio_iommu_map(MEM_XFER_BUF, dma_coherent, xfer_buf_pa, len, + &xfer_buf_sgt); + if (!va) { + ret =3D -ENOMEM; + goto unmap_sync; + } + + mem_info->pa =3D xfer_buf_pa; + mem_info->size =3D len; + mem_info->va =3D PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + sg_free_table(&xfer_buf_sgt); + + return 0; + +unmap_sync: + usb_free_coherent(subs->dev, len, xfer_buf, xfer_buf_pa); + + return ret; +} + +/** + * uaudio_endpoint_setup() - fetch and populate endpoint params + * @subs: usb substream + * @endpoint: usb endpoint to add + * @card_num: uadev index + * @mem_info: QMI response info + * @ep_desc: QMI ep desc response field + * + * Initialize the USB endpoint being used for a particular USB + * stream. Will request XHCI sec intr to reserve the EP for + * offloading as well as populating the QMI response with the + * transfer ring parameters. + * + */ +static phys_addr_t +uaudio_endpoint_setup(struct snd_usb_substream *subs, + struct snd_usb_endpoint *endpoint, int card_num, + struct mem_info_v01 *mem_info, + struct usb_endpoint_descriptor_v01 *ep_desc) +{ + struct usb_host_endpoint *ep; + phys_addr_t tr_pa =3D 0; + struct sg_table *sgt; + bool dma_coherent; + unsigned long va; + struct page *pg; + int ret; + + dma_coherent =3D dev_is_dma_coherent(subs->dev->bus->sysdev); + + ep =3D usb_pipe_endpoint(subs->dev, endpoint->pipe); + if (!ep) { + dev_err(uaudio_qdev->data->dev, "data ep # %d context is null\n", + subs->data_endpoint->ep_num); + goto exit; + } + + memcpy(ep_desc, &ep->desc, sizeof(ep->desc)); + + ret =3D xhci_sec_intr_add_endpoint(uadev[card_num].si, ep); + if (ret < 0) { + dev_err(&subs->dev->dev, + "failed to add data ep to sec intr\n"); + ret =3D -ENODEV; + goto exit; + } + + sgt =3D xhci_sec_intr_get_endpoint_buffer(uadev[card_num].si, ep); + if (!sgt) { + dev_err(&subs->dev->dev, + "failed to get data ep ring address\n"); + ret =3D -ENODEV; + goto remove_ep; + } + + pg =3D sg_page(sgt->sgl); + tr_pa =3D page_to_phys(pg); + mem_info->pa =3D sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + /* data transfer ring */ + va =3D uaudio_iommu_map(MEM_XFER_RING, dma_coherent, tr_pa, + PAGE_SIZE, NULL); + if (!va) { + ret =3D -ENOMEM; + goto clear_pa; + } + + mem_info->va =3D PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size =3D PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa =3D 0; +remove_ep: + xhci_sec_intr_remove_endpoint(uadev[card_num].si, ep); +exit: + return ret; +} + +/** + * uaudio_event_ring_setup() - fetch and populate event ring params + * @subs: usb substream + * @card_num: uadev index + * @mem_info: QMI response info + * + * Register secondary interrupter to XHCI and fetch the event buffer info + * and populate the information into the QMI response. + * + */ +static int uaudio_event_ring_setup(struct snd_usb_substream *subs, + int card_num, struct mem_info_v01 *mem_info) +{ + struct sg_table *sgt; + phys_addr_t er_pa; + bool dma_coherent; + unsigned long va; + struct page *pg; + int ret; + + dma_coherent =3D dev_is_dma_coherent(subs->dev->bus->sysdev); + er_pa =3D 0; + + /* event ring */ + ret =3D xhci_sec_intr_create_interrupter(uadev[card_num].si, 1, false, + 0, uaudio_qdev->data->intr_num); + if (ret < 0) { + dev_err(&subs->dev->dev, "failed to fetch interrupter\n"); + goto exit; + } + + sgt =3D xhci_sec_intr_get_event_buffer(uadev[card_num].si); + if (!sgt) { + dev_err(&subs->dev->dev, + "failed to get event ring address\n"); + ret =3D -ENODEV; + goto remove_interrupter; + } + + pg =3D sg_page(sgt->sgl); + er_pa =3D page_to_phys(pg); + mem_info->pa =3D sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + va =3D uaudio_iommu_map(MEM_EVENT_RING, dma_coherent, er_pa, + PAGE_SIZE, NULL); + if (!va) { + ret =3D -ENOMEM; + goto clear_pa; + } + + mem_info->va =3D PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size =3D PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa =3D 0; +remove_interrupter: + xhci_sec_intr_remove_interrupter(uadev[card_num].si); +exit: + return ret; +} + +/** + * uaudio_populate_uac_desc() - parse UAC parameters and populate QMI resp + * @subs: usb substream + * @resp: QMI response buffer + * + * Parses information specified within UAC descriptors which explain the + * sample parameters that the device expects. This information is populat= ed + * to the QMI response sent back to the audio DSP. + * + */ +static int uaudio_populate_uac_desc(struct snd_usb_substream *subs, + struct qmi_uaudio_stream_resp_msg_v01 *resp) +{ + struct usb_interface_descriptor *altsd; + struct usb_host_interface *alts; + struct usb_interface *iface; + int protocol; + + iface =3D usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface); + if (!iface) { + dev_err(&subs->dev->dev, "interface # %d does not exist\n", + subs->cur_audiofmt->iface); + return -ENODEV; + } + + alts =3D &iface->altsetting[subs->cur_audiofmt->altset_idx]; + altsd =3D get_iface_desc(alts); + protocol =3D altsd->bInterfaceProtocol; + + if (protocol =3D=3D UAC_VERSION_1) { + struct uac1_as_header_descriptor *as; + + as =3D snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, + UAC_AS_GENERAL); + if (!as) { + dev_err(&subs->dev->dev, + "%u:%d : no UAC_AS_GENERAL desc\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + return -ENODEV; + } + + resp->data_path_delay =3D as->bDelay; + resp->data_path_delay_valid =3D 1; + + resp->usb_audio_subslot_size =3D subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid =3D 1; + + resp->usb_audio_spec_revision =3D le16_to_cpu(0x0100); + resp->usb_audio_spec_revision_valid =3D 1; + } else if (protocol =3D=3D UAC_VERSION_2) { + resp->usb_audio_subslot_size =3D subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid =3D 1; + + resp->usb_audio_spec_revision =3D le16_to_cpu(0x0200); + resp->usb_audio_spec_revision_valid =3D 1; + } else if (protocol =3D=3D UAC_VERSION_3) { + if (iface->intf_assoc->bFunctionSubClass =3D=3D + UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) { + dev_err(&subs->dev->dev, + "full adc is not supported\n"); + return -EINVAL; + } + + switch (le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize)) { + case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_16: + case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_16: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_16: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_16: { + resp->usb_audio_subslot_size =3D 0x2; + break; + } + + case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_24: + case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_24: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_24: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_24: { + resp->usb_audio_subslot_size =3D 0x3; + break; + } + + default: + dev_err(&subs->dev->dev, + "%d: %u: Invalid wMaxPacketSize\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + return -EINVAL; + } + resp->usb_audio_subslot_size_valid =3D 1; + } else { + dev_err(&subs->dev->dev, "unknown protocol version %x\n", + protocol); + return -ENODEV; + } + + memcpy(&resp->std_as_opr_intf_desc, &alts->desc, sizeof(alts->desc)); + + return 0; +} + +/** + * prepare_qmi_response() - prepare stream enable response + * @subs: usb substream + * @req_msg: QMI request message + * @resp: QMI response buffer + * @info_idx: usb interface array index + * + * Prepares the QMI response for a USB QMI stream enable request. Will pa= rse + * out the parameters within the stream enable request, in order to match + * requested audio profile to the ones exposed by the USB device connected. + * + * In addition, will fetch the XHCI transfer resources needed for the hand= off to + * happen. This includes, transfer ring and buffer addresses and secondar= y event + * ring address. These parameters will be communicated as part of the USB= QMI + * stream enable response. + * + */ +static int prepare_qmi_response(struct snd_usb_substream *subs, + struct qmi_uaudio_stream_req_msg_v01 *req_msg, + struct qmi_uaudio_stream_resp_msg_v01 *resp, + int info_idx) +{ + struct q6usb_offload *data; + u32 xfer_buf_len; + int pcm_dev_num; + int card_num; + u8 *xfer_buf; + int ret; + + pcm_dev_num =3D (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + xfer_buf_len =3D req_msg->xfer_buff_size; + card_num =3D (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 16; + + if (!uadev[card_num].ctrl_intf) { + dev_err(&subs->dev->dev, "audio ctrl intf info not cached\n"); + ret =3D -ENODEV; + goto err; + } + + ret =3D uaudio_populate_uac_desc(subs, resp); + if (ret < 0) + goto err; + + resp->slot_id =3D subs->dev->slot_id; + resp->slot_id_valid =3D 1; + + data =3D snd_soc_usb_find_priv_data(usb_get_usb_backend(subs->dev)); + if (!data) + goto err; + + uaudio_qdev->data =3D data; + + resp->std_as_opr_intf_desc_valid =3D 1; + ret =3D uaudio_endpoint_setup(subs, subs->data_endpoint, card_num, + &resp->xhci_mem_info.tr_data, + &resp->std_as_data_ep_desc); + if (ret < 0) + goto err; + + resp->std_as_data_ep_desc_valid =3D 1; + + if (subs->sync_endpoint) { + ret =3D uaudio_endpoint_setup(subs, subs->sync_endpoint, card_num, + &resp->xhci_mem_info.tr_sync, + &resp->std_as_sync_ep_desc); + if (ret < 0) + goto drop_data_ep; + + resp->std_as_sync_ep_desc_valid =3D 1; + } + + resp->interrupter_num_valid =3D 1; + resp->controller_num_valid =3D 0; + ret =3D usb_get_controller_id(subs->dev); + if (ret >=3D 0) { + resp->controller_num =3D ret; + resp->controller_num_valid =3D 1; + } + + /* event ring */ + ret =3D uaudio_event_ring_setup(subs, card_num, + &resp->xhci_mem_info.evt_ring); + if (ret < 0) + goto drop_sync_ep; + + uaudio_qdev->er_mapped =3D true; + resp->interrupter_num =3D xhci_sec_intr_interrupter_id(uadev[card_num].si= ); + + resp->speed_info =3D get_speed_info(subs->dev->speed); + if (resp->speed_info =3D=3D USB_QMI_DEVICE_SPEED_INVALID_V01) { + ret =3D -ENODEV; + goto free_sec_ring; + } + + resp->speed_info_valid =3D 1; + + ret =3D uaudio_transfer_buffer_setup(subs, xfer_buf, req_msg->xfer_buff_s= ize, + &resp->xhci_mem_info.xfer_buff); + if (ret < 0) { + ret =3D -ENOMEM; + goto free_sec_ring; + } + + resp->xhci_mem_info_valid =3D 1; + + if (!atomic_read(&uadev[card_num].in_use)) { + kref_init(&uadev[card_num].kref); + init_waitqueue_head(&uadev[card_num].disconnect_wq); + uadev[card_num].num_intf =3D + subs->dev->config->desc.bNumInterfaces; + uadev[card_num].info =3D kcalloc(uadev[card_num].num_intf, + sizeof(struct intf_info), + GFP_KERNEL); + if (!uadev[card_num].info) { + ret =3D -ENOMEM; + goto unmap_er; + } + uadev[card_num].udev =3D subs->dev; + atomic_set(&uadev[card_num].in_use, 1); + } else { + kref_get(&uadev[card_num].kref); + } + + uadev[card_num].usb_core_id =3D resp->controller_num; + + /* cache intf specific info to use it for unmap and free xfer buf */ + uadev[card_num].info[info_idx].data_xfer_ring_va =3D + IOVA_MASK(resp->xhci_mem_info.tr_data.va); + uadev[card_num].info[info_idx].data_xfer_ring_size =3D PAGE_SIZE; + uadev[card_num].info[info_idx].sync_xfer_ring_va =3D + IOVA_MASK(resp->xhci_mem_info.tr_sync.va); + uadev[card_num].info[info_idx].sync_xfer_ring_size =3D PAGE_SIZE; + uadev[card_num].info[info_idx].xfer_buf_va =3D + IOVA_MASK(resp->xhci_mem_info.xfer_buff.va); + uadev[card_num].info[info_idx].xfer_buf_pa =3D + resp->xhci_mem_info.xfer_buff.pa; + uadev[card_num].info[info_idx].xfer_buf_size =3D + resp->xhci_mem_info.xfer_buff.size; + uadev[card_num].info[info_idx].data_ep_pipe =3D subs->data_endpoint ? + subs->data_endpoint->pipe : 0; + uadev[card_num].info[info_idx].sync_ep_pipe =3D subs->sync_endpoint ? + subs->sync_endpoint->pipe : 0; + uadev[card_num].info[info_idx].xfer_buf =3D xfer_buf; + uadev[card_num].info[info_idx].pcm_card_num =3D card_num; + uadev[card_num].info[info_idx].pcm_dev_num =3D pcm_dev_num; + uadev[card_num].info[info_idx].direction =3D subs->direction; + uadev[card_num].info[info_idx].intf_num =3D subs->cur_audiofmt->iface; + uadev[card_num].info[info_idx].in_use =3D true; + + set_bit(card_num, &uaudio_qdev->card_slot); + + return 0; + +unmap_er: + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); +free_sec_ring: + xhci_sec_intr_remove_interrupter(uadev[card_num].si); +drop_sync_ep: + if (subs->sync_endpoint) { + uaudio_iommu_unmap(MEM_XFER_RING, + IOVA_MASK(resp->xhci_mem_info.tr_sync.va), + PAGE_SIZE, PAGE_SIZE); + xhci_sec_intr_remove_endpoint(uadev[card_num].si, + usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe)); + } +drop_data_ep: + uaudio_iommu_unmap(MEM_XFER_RING, IOVA_MASK(resp->xhci_mem_info.tr_data.v= a), + PAGE_SIZE, PAGE_SIZE); + xhci_sec_intr_remove_endpoint(uadev[card_num].si, + usb_pipe_endpoint(subs->dev, subs->data_endpoint->pipe)); + +err: + return ret; +} + +/** + * handle_uaudio_stream_req() - handle stream enable/disable request + * @handle: QMI client handle + * @sq: qrtr socket + * @txn: QMI transaction context + * @decoded_msg: decoded QMI message + * + * Main handler for the QMI stream enable/disable requests. This executes= the + * corresponding enable/disable stream apis, respectively. + * + */ +static void handle_uaudio_stream_req(struct qmi_handle *handle, + struct sockaddr_qrtr *sq, + struct qmi_txn *txn, + const void *decoded_msg) +{ + struct qmi_uaudio_stream_req_msg_v01 *req_msg; + struct qmi_uaudio_stream_resp_msg_v01 resp =3D {{0}, 0}; + struct uaudio_qmi_svc *svc =3D uaudio_svc; + struct snd_usb_audio *chip =3D NULL; + struct snd_usb_substream *subs; + struct usb_host_endpoint *ep; + int datainterval =3D -EINVAL; + int info_idx =3D -EINVAL; + struct intf_info *info; + u8 pcm_card_num; + u8 pcm_dev_num; + u8 direction; + int ret =3D 0; + + if (!svc->client_connected) { + svc->client_sq =3D *sq; + svc->client_connected =3D true; + } + + mutex_lock(&qdev_mutex); + req_msg =3D (struct qmi_uaudio_stream_req_msg_v01 *)decoded_msg; + if (!req_msg->audio_format_valid || !req_msg->bit_rate_valid || + !req_msg->number_of_ch_valid || !req_msg->xfer_buff_size_valid) { + ret =3D -EINVAL; + goto response; + } + + if (!uaudio_qdev) { + ret =3D -EINVAL; + goto response; + } + + direction =3D (req_msg->usb_token & QMI_STREAM_REQ_DIRECTION); + pcm_dev_num =3D (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + pcm_card_num =3D (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 1= 6; + if (pcm_card_num >=3D SNDRV_CARDS) { + ret =3D -EINVAL; + goto response; + } + + if (req_msg->audio_format > USB_QMI_PCM_FORMAT_U32_BE) { + ret =3D -EINVAL; + goto response; + } + + subs =3D find_substream(pcm_card_num, pcm_dev_num, direction); + chip =3D uadev[pcm_card_num].chip; + if (!subs || !chip || atomic_read(&chip->shutdown)) { + ret =3D -ENODEV; + goto response; + } + + info_idx =3D info_idx_from_ifnum(pcm_card_num, subs->cur_audiofmt ? + subs->cur_audiofmt->iface : -1, req_msg->enable); + if (atomic_read(&chip->shutdown) || !subs->stream || !subs->stream->pcm || + !subs->stream->chip) { + ret =3D -ENODEV; + goto response; + } + + if (req_msg->enable) { + if (info_idx < 0 || chip->system_suspend) { + ret =3D -EBUSY; + goto response; + } + } + + if (req_msg->service_interval_valid) { + ret =3D get_data_interval_from_si(subs, + req_msg->service_interval); + if (ret =3D=3D -EINVAL) + goto response; + + datainterval =3D ret; + } + + uadev[pcm_card_num].ctrl_intf =3D chip->ctrl_intf; + + if (req_msg->enable) { + ret =3D enable_audio_stream(subs, + map_pcm_format(req_msg->audio_format), + req_msg->number_of_ch, req_msg->bit_rate, + datainterval); + + if (!ret) + ret =3D prepare_qmi_response(subs, req_msg, &resp, + info_idx); + } else { + info =3D &uadev[pcm_card_num].info[info_idx]; + if (info->data_ep_pipe) { + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->data_ep_pipe); + if (ep) { + xhci_sec_intr_stop_endpoint(uadev[pcm_card_num].si, + ep); + xhci_sec_intr_remove_endpoint(uadev[pcm_card_num].si, + ep); + } + + info->data_ep_pipe =3D 0; + } + + if (info->sync_ep_pipe) { + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + if (ep) { + xhci_sec_intr_stop_endpoint(uadev[pcm_card_num].si, + ep); + xhci_sec_intr_remove_endpoint(uadev[pcm_card_num].si, + ep); + } + + info->sync_ep_pipe =3D 0; + } + + disable_audio_stream(subs); + } + +response: + if (!req_msg->enable && ret !=3D -EINVAL && ret !=3D -ENODEV) { + mutex_lock(&chip->mutex); + if (info_idx >=3D 0) { + info =3D &uadev[pcm_card_num].info[info_idx]; + uaudio_dev_intf_cleanup(uadev[pcm_card_num].udev, + info); + } + if (atomic_read(&uadev[pcm_card_num].in_use)) + kref_put(&uadev[pcm_card_num].kref, + uaudio_dev_release); + mutex_unlock(&chip->mutex); + } + mutex_unlock(&qdev_mutex); + + resp.usb_token =3D req_msg->usb_token; + resp.usb_token_valid =3D 1; + resp.internal_status =3D ret; + resp.internal_status_valid =3D 1; + resp.status =3D ret ? USB_QMI_STREAM_REQ_FAILURE_V01 : ret; + resp.status_valid =3D 1; + ret =3D qmi_send_response(svc->uaudio_svc_hdl, sq, txn, + QMI_UAUDIO_STREAM_RESP_V01, + QMI_UAUDIO_STREAM_RESP_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_resp_msg_v01_ei, &resp); +} + +static struct qmi_msg_handler uaudio_stream_req_handlers =3D { + .type =3D QMI_REQUEST, + .msg_id =3D QMI_UAUDIO_STREAM_REQ_V01, + .ei =3D qmi_uaudio_stream_req_msg_v01_ei, + .decoded_size =3D QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN, + .fn =3D handle_uaudio_stream_req, +}; + +/** + * qc_usb_audio_offload_init_qmi_dev() - initializes qmi dev + * + * Initializes the USB qdev, which is used to carry information pertaining= to + * the offloading resources. This device is freed only when there are no = longer + * any offloading candidates. (i.e, when all audio devices are disconnecte= d) + * + */ +static int qc_usb_audio_offload_init_qmi_dev(void) +{ + uaudio_qdev =3D kzalloc(sizeof(*uaudio_qdev), GFP_KERNEL); + if (!uaudio_qdev) + return -ENOMEM; + + /* initialize xfer ring and xfer buf iova list */ + INIT_LIST_HEAD(&uaudio_qdev->xfer_ring_list); + uaudio_qdev->curr_xfer_ring_iova =3D IOVA_XFER_RING_BASE; + uaudio_qdev->xfer_ring_iova_size =3D + IOVA_XFER_RING_MAX - IOVA_XFER_RING_BASE; + + INIT_LIST_HEAD(&uaudio_qdev->xfer_buf_list); + uaudio_qdev->curr_xfer_buf_iova =3D IOVA_XFER_BUF_BASE; + uaudio_qdev->xfer_buf_iova_size =3D + IOVA_XFER_BUF_MAX - IOVA_XFER_BUF_BASE; + + return 0; +} + +/* Populates ppcm_idx array with supported PCM indexes */ +static int qc_usb_audio_offload_fill_avail_pcms(struct snd_usb_audio *chip, + struct snd_soc_usb_device *sdev) +{ + struct snd_usb_stream *as; + struct snd_usb_substream *subs; + int idx =3D 0; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs =3D &as->substream[SNDRV_PCM_STREAM_PLAYBACK]; + if (subs->ep_num) { + sdev->ppcm_idx[idx] =3D as->pcm->device; + idx++; + } + /* + * Break if the current index exceeds the number of possible + * playback streams counted from the UAC descriptors. + */ + if (idx >=3D sdev->num_playback) + break; + } + + return -1; +} + +/** + * qc_usb_audio_offload_probe() - platform op connect handler + * @chip: USB SND device + * + * Platform connect handler when a USB SND device is detected. Will + * notify SOC USB about the connection to enable the USB ASoC backend + * and populate internal USB chip array. + * + */ +static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) +{ + struct usb_interface *intf =3D chip->intf[chip->num_interfaces - 1]; + struct usb_interface_descriptor *altsd; + struct usb_device *udev =3D chip->dev; + struct usb_host_interface *alts; + struct snd_soc_usb_device *sdev; + struct xhci_sec_intr *si; + + /* + * If there is no priv_data, or no playback paths, the connected + * device doesn't support offloading. Avoid populating entries for + * this device. + */ + if (!snd_soc_usb_find_priv_data(usb_get_usb_backend(udev)) || + !usb_qmi_get_pcm_num(chip, 0)) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + if (!uadev[chip->card->number].chip) { + sdev =3D kzalloc(sizeof(*sdev), GFP_KERNEL); + if (!sdev) + goto exit; + + si =3D xhci_sec_intr_register(udev); + if (!si) + goto free_sdev; + } else { + si =3D uadev[chip->card->number].si; + sdev =3D uadev[chip->card->number].sdev; + } + + if (!uaudio_qdev) + qc_usb_audio_offload_init_qmi_dev(); + + atomic_inc(&uaudio_qdev->qdev_in_use); + + uadev[chip->card->number].si =3D si; + uadev[chip->card->number].chip =3D chip; + uadev[chip->card->number].sdev =3D sdev; + + alts =3D &intf->altsetting[0]; + altsd =3D get_iface_desc(alts); + + /* Wait until all PCM devices are populated before notifying soc-usb */ + if (altsd->bInterfaceNumber =3D=3D chip->last_iface) { + sdev->num_playback =3D usb_qmi_get_pcm_num(chip, 0); + + /* + * Allocate playback pcm index array based on number of possible + * playback paths within the UAC descriptors. + */ + sdev->ppcm_idx =3D kcalloc(sdev->num_playback, sizeof(unsigned int), + GFP_KERNEL); + if (!sdev->ppcm_idx) + goto unreg_xhci; + + qc_usb_audio_offload_fill_avail_pcms(chip, sdev); + sdev->card_idx =3D chip->card->number; + sdev->chip_idx =3D chip->index; + + snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + } + + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + + return; + +unreg_xhci: + xhci_sec_intr_unregister(si); + uadev[chip->card->number].si =3D NULL; +free_sdev: + kfree(sdev); + uadev[chip->card->number].sdev =3D NULL; + uadev[chip->card->number].chip =3D NULL; +exit: + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); +} + +/** + * qc_usb_audio_cleanup_qmi_dev() - release qmi device + * + * Frees the USB qdev. Only occurs when there are no longer any potential + * devices that can utilize USB audio offloading. + * + */ +static void qc_usb_audio_cleanup_qmi_dev(void) +{ + kfree(uaudio_qdev); + uaudio_qdev =3D NULL; +} + +/** + * qc_usb_audio_offload_disconnect() - platform op disconnect handler + * @chip: USB SND device + * + * Platform disconnect handler. Will ensure that any pending stream is + * halted by issuing a QMI disconnect indication packet to the adsp. + * + */ +static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip) +{ + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind =3D {0}; + struct uaudio_qmi_svc *svc =3D uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num =3D chip->card->number; + if (card_num >=3D SNDRV_CARDS) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + dev =3D &uadev[card_num]; + + /* Device has already been cleaned up, or never populated */ + if (!dev->chip) { + mutex_unlock(&qdev_mutex); + mutex_unlock(&chip->mutex); + return; + } + + /* cleaned up already */ + if (!dev->udev) + goto done; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + dev_dbg(uaudio_qdev->data->dev, + "sending qmi indication disconnect\n"); + disconnect_ind.dev_event =3D USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id =3D dev->udev->slot_id; + disconnect_ind.controller_num =3D dev->usb_core_id; + disconnect_ind.controller_num_valid =3D 1; + ret =3D qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, + QMI_UAUDIO_STREAM_IND_V01, + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_ind_msg_v01_ei, + &disconnect_ind); + if (ret < 0) + dev_err(uaudio_qdev->data->dev, + "qmi send failed with err: %d\n", ret); + + ret =3D wait_event_interruptible_timeout(dev->disconnect_wq, + !atomic_read(&dev->in_use), + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); + if (!ret) { + dev_err(uaudio_qdev->data->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->data->dev, + "failed with ret %d\n", ret); + atomic_set(&dev->in_use, 0); + } + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + } + + uaudio_dev_cleanup(dev); +done: + /* + * If num_interfaces =3D=3D 1, the last USB SND interface is being remove= d. + * This is to accommodate for devices w/ multiple UAC functions. + */ + if (chip->num_interfaces =3D=3D 1) { + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + xhci_sec_intr_unregister(dev->si); + dev->chip =3D NULL; + kfree(dev->sdev->ppcm_idx); + kfree(dev->sdev); + dev->sdev =3D NULL; + } + mutex_unlock(&chip->mutex); + + atomic_dec(&uaudio_qdev->qdev_in_use); + if (!atomic_read(&uaudio_qdev->qdev_in_use)) + qc_usb_audio_cleanup_qmi_dev(); + + mutex_unlock(&qdev_mutex); +} + +/** + * qc_usb_audio_offload_suspend() - USB offload PM suspend handler + * @intf: USB interface + * @message: suspend type + * + * PM suspend handler to ensure that the USB offloading driver is able to = stop + * any pending traffic, so that the bus can be suspended. + * + */ +static void qc_usb_audio_offload_suspend(struct usb_interface *intf, + pm_message_t message) +{ + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind =3D {0}; + struct snd_usb_audio *chip =3D usb_get_intfdata(intf); + struct uaudio_qmi_svc *svc =3D uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num =3D chip->card->number; + if (card_num >=3D SNDRV_CARDS) + return; + + mutex_lock(&chip->mutex); + dev =3D &uadev[card_num]; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + dev_dbg(uaudio_qdev->data->dev, "sending qmi indication suspend\n"); + disconnect_ind.dev_event =3D USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id =3D dev->udev->slot_id; + disconnect_ind.controller_num =3D dev->usb_core_id; + disconnect_ind.controller_num_valid =3D 1; + ret =3D qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, + QMI_UAUDIO_STREAM_IND_V01, + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_ind_msg_v01_ei, + &disconnect_ind); + if (ret < 0) + dev_err(uaudio_qdev->data->dev, + "qmi send failed with err: %d\n", ret); + + ret =3D wait_event_interruptible_timeout(dev->disconnect_wq, + !atomic_read(&dev->in_use), + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); + if (!ret) { + dev_err(uaudio_qdev->data->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->data->dev, + "failed with ret %d\n", ret); + atomic_set(&dev->in_use, 0); + } + mutex_lock(&chip->mutex); + } + mutex_unlock(&chip->mutex); +} + +static struct snd_usb_platform_ops offload_ops =3D { + .connect_cb =3D qc_usb_audio_offload_probe, + .disconnect_cb =3D qc_usb_audio_offload_disconnect, + .suspend_cb =3D qc_usb_audio_offload_suspend, +}; + +static int __init qc_usb_audio_offload_init(void) +{ + struct uaudio_qmi_svc *svc; + int ret; + + svc =3D kzalloc(sizeof(*svc), GFP_KERNEL); + if (!svc) + return -ENOMEM; + + svc->uaudio_svc_hdl =3D kzalloc(sizeof(*svc->uaudio_svc_hdl), GFP_KERNEL); + if (!svc->uaudio_svc_hdl) { + ret =3D -ENOMEM; + goto free_svc; + } + + ret =3D qmi_handle_init(svc->uaudio_svc_hdl, + QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN, + &uaudio_svc_ops_options, + &uaudio_stream_req_handlers); + ret =3D qmi_add_server(svc->uaudio_svc_hdl, UAUDIO_STREAM_SERVICE_ID_V01, + UAUDIO_STREAM_SERVICE_VERS_V01, 0); + + uaudio_svc =3D svc; + + ret =3D snd_usb_register_platform_ops(&offload_ops); + if (ret < 0) + goto release_qmi; + + return 0; + +release_qmi: + qmi_handle_release(svc->uaudio_svc_hdl); +free_svc: + kfree(svc); + + return ret; +} + +static void __exit qc_usb_audio_offload_exit(void) +{ + struct uaudio_qmi_svc *svc =3D uaudio_svc; + int idx; + + /* + * Remove all connected devices after unregistering ops, to ensure + * that no further connect events will occur. The disconnect routine + * will issue the QMI disconnect indication, which results in the + * external DSP to stop issuing transfers. + */ + snd_usb_unregister_platform_ops(); + for (idx =3D 0; idx < SNDRV_CARDS; idx++) + qc_usb_audio_offload_disconnect(uadev[idx].chip); + + qmi_handle_release(svc->uaudio_svc_hdl); + kfree(svc); + uaudio_svc =3D NULL; +} + +module_init(qc_usb_audio_offload_init); +module_exit(qc_usb_audio_offload_exit); + +MODULE_DESCRIPTION("QC USB Audio Offloading"); +MODULE_LICENSE("GPL"); From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B41320D511; Wed, 6 Nov 2024 19:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921693; cv=none; b=Adi6m4WR6RRDR38kB/IVUnG9sOoDGgZ9SPmrM40puK2cH+YLw70HP4OfXuUbjEmb4sGUNWZU+tZcznKkDSGpJ1V1u5ne5VXI/Qv55evWxVEW0q6UKQqEE/JwX2qW0XoJ11QyvwcfL5f30A2ryiooZCZQ1BL64wZBbB2n2Y59pRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921693; c=relaxed/simple; bh=dlA+a/A3s2H8Ik64s93JljXJruBfc1fYp3Gmv6QOOPQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QdGSbWN1YPoGUOPAz4aKpyfsqw9KbipuUcMJfcejOZtvvGy3p3eJHKApCrca+i8IstBo29PFrrByc1lXXyT917HaadK0bRm0Anh3O+jlcFaaYnXPBQIpm6i2xWr8axNPmwpOffsQ162RxXOkVjWqsCneW78SWTGZt8Jr98KSRGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=gIK8ELoJ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gIK8ELoJ" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6EQYMv002118; Wed, 6 Nov 2024 19:34:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= bWI9BC72pkjgdWXKFDEZd1bqI6IAUkLy1t0yA+scJnM=; b=gIK8ELoJ8ArI8cRo fAmtMjVmSyFxAbWWt20454tESkGjftYR0nqOtxnV8Omv4AIpUxb2q0ihnTjGKMlN 6dqDzRFpTOedNmPfheL0jkggE2cIMF8XUbtHzZRXLYfi1KidCnjzVqN0XoKTZPc4 Kps8KO1NOESg9RRlw9vYHdCI2DuSIFk+gY4mTM3cbs6fwfvL8D6OoUkerXpEegXb WPbN+rRXHPHL9eHLlLWPTFwOxhij9gsauEB54qQkaNl4GgFTywFGP49FGWjTGfre rVHUvRcIJmmmexMpaeOnsxEAElCB9K+Lbck1XQEgvTPYLi2r/CHbKAIIDWdEK1Nh kkLqHw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r072jf9t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYb2x004033 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 27/30] ALSA: usb-audio: qcom: Don't allow USB offload path if PCM device is in use Date: Wed, 6 Nov 2024 11:34:10 -0800 Message-ID: <20241106193413.1730413-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Gi_aM_1ogx2bc32PllNEFKQyeAboQ5z2 X-Proofpoint-GUID: Gi_aM_1ogx2bc32PllNEFKQyeAboQ5z2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 mlxlogscore=970 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" Add proper checks and updates to the USB substream once receiving a USB QMI stream enable request. If the substream is already in use from the non offload path, reject the stream enable request. In addition, update the USB substream opened parameter when enabling the offload path, so the non offload path can be blocked. Signed-off-by: Wesley Cheng --- sound/usb/qcom/qc_audio_offload.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c index 4ef7c949a6ee..9e1c94d28461 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1479,12 +1479,17 @@ static void handle_uaudio_stream_req(struct qmi_han= dle *handle, goto response; } =20 + mutex_lock(&chip->mutex); if (req_msg->enable) { - if (info_idx < 0 || chip->system_suspend) { + if (info_idx < 0 || chip->system_suspend || subs->opened) { ret =3D -EBUSY; + mutex_unlock(&chip->mutex); + goto response; } + subs->opened =3D 1; } + mutex_unlock(&chip->mutex); =20 if (req_msg->service_interval_valid) { ret =3D get_data_interval_from_si(subs, @@ -1506,6 +1511,11 @@ static void handle_uaudio_stream_req(struct qmi_hand= le *handle, if (!ret) ret =3D prepare_qmi_response(subs, req_msg, &resp, info_idx); + if (ret < 0) { + mutex_lock(&chip->mutex); + subs->opened =3D 0; + mutex_unlock(&chip->mutex); + } } else { info =3D &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { @@ -1535,6 +1545,9 @@ static void handle_uaudio_stream_req(struct qmi_handl= e *handle, } =20 disable_audio_stream(subs); + mutex_lock(&chip->mutex); + subs->opened =3D 0; + mutex_unlock(&chip->mutex); } =20 response: From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAB232101AF; Wed, 6 Nov 2024 19:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; cv=none; b=IgGA3zPQLsQsgUESTOdA/QNf0AP0GK2M2T+Jbom+NkWBKfbf3hEndfC24831LPyn7yQjglZcuLGpBr9xFCUL4M94pC/2/ZvP8+xgpHE3T5FghTN+r5JyzpGA0M4IcRWJxq4qFZ1KFVC/coIJY2X+L09SlU1rEIzRak7a6eQjQ2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921699; c=relaxed/simple; bh=4FoFl7pjg7jjV2I5S18Rri3HaR6ZR8SGXzC82fcNEEY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nt08UeIhAY7Z/o4rYDS4ayQ3CVuOWiNqhVi3ls1ldeItzel5UKi3HKvT85ppEcZaGotpLv8l2mksA/0hx+ZsMpBsHbE63lO2/f5qOwSvs/K3Z1EfSzaNAiHM5O0PviS8rSrJoBmg7w7cob0sTzTM3ofpXByGLTX6fzYa4lRPv3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=ManYWuYT; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ManYWuYT" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6B3l5D004579; Wed, 6 Nov 2024 19:34:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= MPH0W2nYcvfswkHOvYtxw3ywTWOF2jw7NdDYFClMCps=; b=ManYWuYTe5H/tQwH okQ9Q6H7tdqXGgnwKYdZTPjFs/g3HY0jPSl5LFPNjpb0m9SkhY8XxlJO3Ih0BYUf Yjh6SZZ0WEzae4rLpcEeSigGGbNPMtEbM676KefxlDic3Mzk6LiplEU4HaKCV/iz Uaq5P2xu6dVRUtrk39EIazqUT8l7Awe9GxnGyf+QGoApgk+lo5FIujPZcS2dkbvK GOMpMOLjKCgJ/Co59HQxiXoOHxW2ELT+ljkgWpeFT0lgjfZFgkTJrbU8RJdhPOy7 utJ5jucxyIpL+394BSm4DR1mRT83vxPUk+x5I21XPMMWFyjRWCEVc2ZESrkt00Wa VfvM8w== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qvhd2y9c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYbev030327 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 28/30] ALSA: usb-audio: Add USB offload route kcontrol Date: Wed, 6 Nov 2024 11:34:11 -0800 Message-ID: <20241106193413.1730413-29-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 1yV6T4SmwVfRwFZApZnyC_M5KLQA_f-K X-Proofpoint-GUID: 1yV6T4SmwVfRwFZApZnyC_M5KLQA_f-K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" In order to allow userspace/applications know about USB offloading status, expose a sound kcontrol that fetches information about which sound card and PCM index the USB device is mapped to for supporting offloading. In the USB audio offloading framework, the ASoC BE DAI link is the entity responsible for registering to the SOC USB layer. It is expected for the USB SND offloading driver to add the kcontrol to the sound card associated with the USB audio device. An example output would look like: tinymix -D 1 get 'USB Offload Playback Route PCM#0' -1, -1 (range -1->255) This example signifies that there is no mapped ASoC path available for the USB SND device. tinymix -D 1 get 'USB Offload Playback Route PCM#0' 0, 0 (range -1->255) This example signifies that the offload path is available over ASoC sound card index#0 and PCM device#0. The USB offload kcontrol will be added in addition to the existing kcontrols identified by the USB SND mixer. The kcontrols used to modify the USB audio device specific parameters are still valid and expected to be used. These parameters are not mirrored to the ASoC subsystem. Signed-off-by: Wesley Cheng --- sound/usb/Kconfig | 10 +++ sound/usb/Makefile | 2 + sound/usb/mixer_usb_offload.c | 102 ++++++++++++++++++++++++++++++ sound/usb/mixer_usb_offload.h | 17 +++++ sound/usb/qcom/Makefile | 2 +- sound/usb/qcom/qc_audio_offload.c | 2 + 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 sound/usb/mixer_usb_offload.c create mode 100644 sound/usb/mixer_usb_offload.h diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index d0f65311894f..4994e6261be5 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,10 +176,20 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. =20 +config SND_USB_OFFLOAD_MIXER + tristate "USB Audio Offload mixer control" + help + Say Y to enable the USB audio offloading mixer controls. This + exposes an USB offload capable kcontrol to signal to applications + about which platform sound card can support USB audio offload. + The returning values specify the mapped ASoC card and PCM device + the USB audio device is associated to. + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SEC_INTR && SND_= SOC_USB select SND_PCM + select SND_USB_OFFLOAD_MIXER help Say Y here to enable the Qualcomm USB audio offloading feature. =20 diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 54a06a2f73ca..2f19f854944c 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -36,3 +36,5 @@ obj-$(CONFIG_SND_USB_US122L) +=3D snd-usbmidi-lib.o =20 obj-$(CONFIG_SND) +=3D misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ qcom/ obj-$(CONFIG_SND_USB_LINE6) +=3D line6/ + +obj-$(CONFIG_SND_USB_OFFLOAD_MIXER) +=3D mixer_usb_offload.o diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c new file mode 100644 index 000000000000..e0689a3b9b86 --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#include + +#include +#include +#include + +#include "usbaudio.h" +#include "card.h" +#include "helper.h" +#include "mixer.h" + +#include "mixer_usb_offload.h" + +#define PCM_IDX(n) ((n) & 0xffff) +#define CARD_IDX(n) ((n) >> 16) + +static int +snd_usb_offload_route_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct device *sysdev =3D snd_kcontrol_chip(kcontrol); + int ret; + + ret =3D snd_soc_usb_update_offload_route(sysdev, + CARD_IDX(kcontrol->private_value), + PCM_IDX(kcontrol->private_value), + SNDRV_PCM_STREAM_PLAYBACK, + ucontrol->value.integer.value); + if (ret < 0) { + ucontrol->value.integer.value[0] =3D -1; + ucontrol->value.integer.value[1] =3D -1; + } + + return 0; +} + +static int snd_usb_offload_route_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =3D SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count =3D 2; + uinfo->value.integer.min =3D -1; + /* Arbitrary max value, as there is no 'limit' on number of PCM devices */ + uinfo->value.integer.max =3D 0xff; + + return 0; +} + +static struct snd_kcontrol_new snd_usb_offload_mapped_ctl =3D { + .iface =3D SNDRV_CTL_ELEM_IFACE_CARD, + .access =3D SNDRV_CTL_ELEM_ACCESS_READ, + .info =3D snd_usb_offload_route_info, + .get =3D snd_usb_offload_route_get, +}; + +/** + * snd_usb_offload_create_ctl() - Add USB offload bounded mixer + * @chip - USB SND chip device + * + * Creates a sound control for a USB audio device, so that applications can + * query for if there is an available USB audio offload path, and which + * card is managing it. + */ +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip) +{ + struct usb_device *udev =3D chip->dev; + struct snd_kcontrol_new *chip_kctl; + struct snd_usb_substream *subs; + struct snd_usb_stream *as; + char ctl_name[34]; + int ret; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs =3D &as->substream[SNDRV_PCM_STREAM_PLAYBACK]; + if (!subs->ep_num || as->pcm_index > 0xff) + continue; + + chip_kctl =3D &snd_usb_offload_mapped_ctl; + chip_kctl->count =3D 1; + /* + * Store the associated USB SND card number and PCM index for + * the kctl. + */ + chip_kctl->private_value =3D as->pcm_index | + chip->card->number << 16; + sprintf(ctl_name, "USB Offload Playback Route PCM#%d", + as->pcm_index); + chip_kctl->name =3D ctl_name; + ret =3D snd_ctl_add(chip->card, snd_ctl_new1(chip_kctl, + udev->bus->sysdev)); + if (ret < 0) + break; + } + + return ret; +} +EXPORT_SYMBOL_GPL(snd_usb_offload_create_ctl); diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h new file mode 100644 index 000000000000..3f6e2a8b19c8 --- /dev/null +++ b/sound/usb/mixer_usb_offload.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#ifndef __USB_OFFLOAD_MIXER_H +#define __USB_OFFLOAD_MIXER_H + +#if IS_ENABLED(CONFIG_SND_USB_OFFLOAD_MIXER) +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip); +#else +static inline int snd_usb_offload_create_ctl(struct snd_usb_audio *chip) +{ + return 0; +} +#endif +#endif /* __USB_OFFLOAD_MIXER_H */ diff --git a/sound/usb/qcom/Makefile b/sound/usb/qcom/Makefile index a81c9b28d484..4005e8391ab9 100644 --- a/sound/usb/qcom/Makefile +++ b/sound/usb/qcom/Makefile @@ -1,2 +1,2 @@ snd-usb-audio-qmi-objs :=3D usb_audio_qmi_v01.o qc_audio_offload.o -obj-$(CONFIG_SND_USB_AUDIO_QMI) +=3D snd-usb-audio-qmi.o \ No newline at end of file +obj-$(CONFIG_SND_USB_AUDIO_QMI) +=3D snd-usb-audio-qmi.o diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c index 9e1c94d28461..f78cd8c504b9 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -36,6 +36,7 @@ #include "../helper.h" #include "../pcm.h" #include "../power.h" +#include "../mixer_usb_offload.h" =20 #include "usb_audio_qmi_v01.h" =20 @@ -1709,6 +1710,7 @@ static void qc_usb_audio_offload_probe(struct snd_usb= _audio *chip) sdev->card_idx =3D chip->card->number; sdev->chip_idx =3D chip->index; =20 + snd_usb_offload_create_ctl(chip); snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); } From nobody Thu Nov 14 04:04:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0B4F20F5AA; Wed, 6 Nov 2024 19:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; cv=none; b=Z9DKdAzKi2AHYdSAiUAQQ46+UNAVrd+erENMnUgiDoiF5DpV7U6mYP2do5ByYZTSd+tKSKyCWKXOHTmCatgWsLjTH4ZV34DCqM4f92kCWuD5FFdwgBqcB1Nud9J2YLp9oOjGYWAFFDGahqNuPc6Px8H02Iu+ODixMKzc36xwbf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; c=relaxed/simple; bh=+LHUSkkeb/1iSaeZg7YknRD2wJpcT86aoNyUqfpTnlk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=unLH+C/mvpu0NE/uLeO4McJzgNnBCfAsv9HyOPAl5mSAHZVx7FRTeGa3yLbqtw9BZTQGL1Hq16CMEOwno9DxCNupfIhMcpGVdX69dS2G3yLM3kY98y6TXC+hsjndFjEyFrk+qcKUL8pk2gN1Qr1KqqqSZ1EzwBoReRzgMrBXuVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Rh9Tg9o0; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Rh9Tg9o0" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6D8PWh023163; Wed, 6 Nov 2024 19:34:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= N7GLtFQSWKEhUD0WleL46UpD6884e9lfBPPVwEHE//I=; b=Rh9Tg9o0ckYINe8S 03rPsFQEP/rV/RunnY6CHOFHAVNxRreJoEg/iAup/PUa7dPk+yO6ErcECa361nRa jhcDfpOIrGc8KeuNdmNHLSNCVOGOum7/AtDK65gMEYz6FDjJhLMHrexeZxLPPkAg G/uy+LvLvmzRoY6Wu1l9FYEmHrwxv5w7K/iLP6p8H/vRUrNO9/0ujBZXXriih6T+ aneF7NeV8BpL1+KLfD6G3Tt9BFMiiSBkprswwd4Y/JXMv40h4wpgz26P+lM/xYee /phLjxbXX1Voty5IpdBaQRYjX821LolrS8+watCgruWxgRGgzkovaFkbc45jF+FR yjHJWA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42r07hjg9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYbRX030330 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 29/30] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Wed, 6 Nov 2024 11:34:12 -0800 Message-ID: <20241106193413.1730413-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: HGM0YS0YAm1CWL2zR8mC4o93ZXMecRTG X-Proofpoint-ORIG-GUID: HGM0YS0YAm1CWL2zR8mC4o93ZXMecRTG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" In case of notifying SND platform drivers of connection events, some of these use cases, such as offloading, require an ASoC USB backend device to be initialized before the events can be handled. If the USB backend device has not yet been probed, this leads to missing initial USB audio device connection events. Expose an API that traverses the usb_chip array for connected devices, and to call the respective connection callback registered to the SND platform driver. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 21 +++++++++++++++++++++ sound/usb/card.h | 2 ++ sound/usb/qcom/qc_audio_offload.c | 2 ++ 3 files changed, 25 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 4ac7f2b8309a..9fb8726a6c93 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -155,6 +155,27 @@ int snd_usb_unregister_platform_ops(void) } EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); =20 +/* + * in case the platform driver was not ready at the time of USB SND + * device connect, expose an API to discover all connected USB devices + * so it can populate any dependent resources/structures. + */ +void snd_usb_rediscover_devices(void) +{ + int i; + + guard(mutex)(®ister_mutex); + + if (!platform_ops || !platform_ops->connect_cb) + return; + + for (i =3D 0; i < SNDRV_CARDS; i++) { + if (usb_chip[i]) + platform_ops->connect_cb(usb_chip[i]); + } +} +EXPORT_SYMBOL_GPL(snd_usb_rediscover_devices); + /* * Checks to see if requested audio profile, i.e sample rate, # of * channels, etc... is supported by the substream associated to the diff --git a/sound/usb/card.h b/sound/usb/card.h index d8b8522e1613..94404c24d240 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -222,4 +222,6 @@ snd_usb_find_suppported_substream(int card_idx, struct = snd_pcm_hw_params *params =20 int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); + +void snd_usb_rediscover_devices(void); #endif /* __USBAUDIO_CARD_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c index f78cd8c504b9..4cf63faedf45 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1935,6 +1935,8 @@ static int __init qc_usb_audio_offload_init(void) if (ret < 0) goto release_qmi; =20 + snd_usb_rediscover_devices(); + return 0; =20 release_qmi: From nobody Thu Nov 14 04:04:26 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E1A220F5A0; Wed, 6 Nov 2024 19:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; cv=none; b=TRKVCR5SlkuVuEwBR6ski+vf5oE19WwbXqVxz4hvoXk5p8Nw0AWMj+eXZBtCSibk2qV0/2o4A7azHdLEYRWWZM/DqVS+lKnBqaIuhF+9D9gyaq5Hpikt6FC8NppfxlGriDE0HpsqmjPZROM/VTfu4PZ7nZ7AnEa9tLk4y5wxi3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921696; c=relaxed/simple; bh=qU0dUNxFUuN/ND2hfWc0/b53f/OYr4+0HIcF9EoyLxI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l2XzjlcQ8xN3IEdKI7XrwU2bg+ZxV9RhAuIzembmsd2yu9CXtBePvL5wx2ZLe6XAtDY/Fq9aI/KCPc1FGKB1/wZAI+iu5Tc0P7iYyxyfrX6ft1L+rV3RtI/xWN8jeW9tbYLh96gS4+I66jgj2vGDXwBkT5ok1TNNwrgq4WrCPIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=pv4jW5RR; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="pv4jW5RR" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6FSE90010532; Wed, 6 Nov 2024 19:34:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= M4IGsOidRHFIubeJL9OdlEYfFZx1GNBQBMy1HdndUaw=; b=pv4jW5RRyIvL6ava hCQfd0sCzbyQKhkd2E0ibF7DkVfko9yM0KcY/5/1CyvJ6Qy25mhXCT5loLnVu5aK qatFJYqXqMG560c0kBEC3/LdhEjM44ml7h7ukvnhrBrwhqcHc7DmiEO2i324PvhS TaQklQo3g1/v0PmpCcDKBruFkezvsulGI4VWwwwo/XTlj3scZKt52Zu5n5D54tNv vUWNZltUBqbVOFSawGtQ7ZdSthoHt9+RkLVG7OgAf9oleWno75TQKmp5ekrW8s9f R+AzGhPa0ugbXwJjy2kQWT0xCj6j8KeGYqZ6C8NtxUIgHOez2U8oxG7CZ9gAi1ZH tAGNHA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42qn73c51y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYcuR008680 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 6 Nov 2024 11:34:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 30/30] ASoC: usb: Rediscover USB SND devices on USB port add Date: Wed, 6 Nov 2024 11:34:13 -0800 Message-ID: <20241106193413.1730413-31-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: g1i3eKsspLBYWBAVOgEWpK8QO6Teuz8z X-Proofpoint-GUID: g1i3eKsspLBYWBAVOgEWpK8QO6Teuz8z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060149 Content-Type: text/plain; charset="utf-8" In case the USB backend device has not been initialized/probed, USB SND device connections can still occur. When the USB backend is eventually made available, previous USB SND device connections are not communicated to the USB backend. Call snd_usb_rediscover_devices() to generate the connect callbacks for all USB SND devices connected. This will allow for the USB backend to be updated with the current set of devices available. The chip array entries are all populated and removed while under the register_mutex, so going over potential race conditions: Thread#1: q6usb_component_probe() --> snd_soc_usb_add_port() --> snd_usb_rediscover_devices() --> mutex_lock(register_mutex) Thread#2 --> usb_audio_disconnect() --> mutex_lock(register_mutex) So either thread#1 or thread#2 will complete first. If Thread#1 completes before thread#2: SOC USB will notify DPCM backend of the device connection. Shortly after, once thread#2 runs, we will get a disconnect event for the connected device. Thread#2 completes before thread#1: Then during snd_usb_rediscover_devices() it won't notify of any connection for that particular chip index. Signed-off-by: Wesley Cheng --- sound/soc/soc-usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index e56826f1df71..ee566ca7c675 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -279,6 +279,8 @@ void snd_soc_usb_add_port(struct snd_soc_usb *usb) mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); + + snd_usb_rediscover_devices(); } EXPORT_SYMBOL_GPL(snd_soc_usb_add_port);