From nobody Fri Nov 29 02:40:12 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 F405D189BA8; Wed, 25 Sep 2024 01:01:37 +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=1727226100; cv=none; b=Iup3Q2sipRrD7imiUIm7UpPUgrdiIkMqGTVjIp9DlVFEND6xz1kjnzmLhncW0+p+LRn8pzdl85mpTXqBHZvBzUGCMyIM8L9f18NauM0uKbhSBOMC40koXVqWKr2yUgKWrsQ7ybJSjRnXqDVBOj1rods7W9KumfL24Kgp9W7ybwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226100; c=relaxed/simple; bh=3nFyRTVOUVhLHMFASESfShsxhY8idPyIGAYXXG9qqd0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HU/1u+GeFRzd+QMcu1LxwAZUc9ywztcJtMubjpy+iqxaJBJz/Kjcfiug+H6Ky1GZbU2o2XWDGKRwNvR2EhwTmygi6diCN6vlajzBQndpDo9dSBDYl9whoHdCYbe6DQJxOHAAVgl9mv7BcE9kIxuuwpcaex1Rv79QDrphN9LDvDQ= 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=L05KghCp; 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="L05KghCp" 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 48OHQCK5026499; Wed, 25 Sep 2024 01:00:13 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= SVZiV+f4SnId4RLZpdWICppkMgvqXrXjIq8fTSzECKc=; b=L05KghCpw+SucqSl goZXCXKKZ2PrwNmCZX8jmu/0d7fnyorDgSfLJ1ZX6dRH5c2H8SJP1nAMNjISxXS0 n726FBaGtgPL5ZcIT7f6HyTPbjq46dSvfFO1gBI/3fhRcqN1ZXn622AVmqCsgtwa 6jd73AEUf96lDL1XCrvY14/FssTkkTfi2cxoImWERqDcIMzJ8qz0ax+v2fz7gWbT V9nCr+7YvMTSk1dYOyWq0OCGbp8gd6ocZ5HyOmaf/9OrgbqQbtycB4dUD4zS4mm7 lF+UOrd9uCVPQoWAhJ18F9TPNjPYDofvbXafo1KkuIcClrz5Yy2RMBhg/Kxsvg70 cKVsoA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 +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 48P10B0U005984 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:11 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; Tue, 24 Sep 2024 18:00:11 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v28 01/32] xhci: add helper to stop endpoint and wait for completion Date: Tue, 24 Sep 2024 17:59:29 -0700 Message-ID: <20240925010000.2231406-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: IY5S9hcSr9jgpHRkSSzoKy6uwHXKU3tp X-Proofpoint-ORIG-GUID: IY5S9hcSr9jgpHRkSSzoKy6uwHXKU3tp 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 Content-Type: text/plain; charset="utf-8" From: Mathias Nyman Expose xhci_stop_endpoint_sync() which is a synchronous variant of xhci_queue_stop_endpoint(). This is useful for client drivers that are using the secondary interrupters, and need to stop the current endpoint session. This does not go through the normal xhci_handle_cmd_stop_ep() command completion handler, because it utilizes the completion path to achieve synchronous behavior. Users of this API are primarily intended to be clients that maintain their own transfer rings, such as in the case of USB audio offload. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 45 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ed1bb7ed44b0..8d7566e33faf 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -2784,6 +2784,51 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *x= hci, return -ENOMEM; } =20 +/* + * Synchronous XHCI stop endpoint helper. Issues the stop endpoint comman= d and + * waits for the command completion before returning. This does not call + * xhci_handle_cmd_stop_ep(), which has additional handling for 'context e= rror' + * cases, along with transfer ring cleanup. + * + * xhci_stop_endpoint_sync() is intended to be utilized by clients that ma= nage + * their own transfer ring, such as offload situations. + */ +int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep= , int suspend, + gfp_t gfp_flags) +{ + struct xhci_command *command; + unsigned long flags; + int ret; + + command =3D xhci_alloc_command(xhci, true, gfp_flags); + if (!command) + return -ENOMEM; + + spin_lock_irqsave(&xhci->lock, flags); + ret =3D xhci_queue_stop_endpoint(xhci, command, ep->vdev->slot_id, + ep->ep_index, suspend); + if (ret < 0) { + spin_unlock_irqrestore(&xhci->lock, flags); + goto out; + } + + xhci_ring_cmd_db(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); + + wait_for_completion(command->completion); + + /* No handling for COMP_CONTEXT_STATE_ERROR done at command completion*/ + if (command->status =3D=3D COMP_COMMAND_ABORTED || + command->status =3D=3D COMP_COMMAND_RING_STOPPED) { + xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); + ret =3D -ETIME; + } +out: + xhci_free_command(xhci, command); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync); =20 /* Issue a configure endpoint command or evaluate context command * and wait for it to finish. diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 324644165d93..51a992d8ffcf 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1917,6 +1917,8 @@ void xhci_ring_doorbell_for_active_rings(struct xhci_= hcd *xhci, void xhci_cleanup_command_queue(struct xhci_hcd *xhci); 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); =20 /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From nobody Fri Nov 29 02:40:12 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 EA4E415853C; Wed, 25 Sep 2024 01:01:25 +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=1727226087; cv=none; b=TSbItvpGfFn2nBZl6flJYnbRl1IJBZgFER2N+G5xcAQSE4/dUBuvwl1akhr6GrRonE/HE7hJkwv4wl7NCGxHqMhiQAyNjlCAdyFIAeF3vav9BuMXQSqWrlQkkvACcsOFZ+Gq3GMcyQQX/gyD6df3LsotmgYXD9fymMOFl00yzp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226087; c=relaxed/simple; bh=2azGS4Mn0hl3bJLIVZjYNoRlE2MsVGBfb5n8aG0ud74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kaPZ93/l0syCcgQtLFWSxOESBMq2i5k+roL+rOifq+umfo80q2K3JjXDgG5u1oeK8zc8zBK7zfs+95wgJooKD1SU8P5Gcv6a9X+38Nj3ywNo8LeUZj4wKDAWJNEd7kI0D/5ct34Ocqd5NJu22HAAzfNAnRUyufa5t8c0pEAzUZw= 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=gTiffzUI; 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="gTiffzUI" 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 48OI9Chp012001; Wed, 25 Sep 2024 01:00:13 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= 8pUtfboEtVwzj3gvJFEJdvS9Fn04qc2yCNOn552kLBs=; b=gTiffzUI7mKdy1iw hSN9XUfSNo0d/kh+GdTQRaH8p8AjbQUpzbmwt2X40glbPZEN5CR3jPDSxbAy98EM iZTcaNxc25fr32PMLPx/JSm+JancQm+wtcE2nJsaP9yfV2fcViVnfmdWNzvaqvq3 47Nv1elHxWhtVguaDQpJXJfkWvibXrJuuKiESArQsU5GGDmUgXibA7eKYxVjAUdV W+4bdepMj0g7qT9NZ9hVI5Vf9bcCfa+D1i50YmGYcmHxs7jVV9YYg9cSgD+xNN8Y TV0XLisXEI9NsKVf7+QI0lBCs0kk2c/CfjDsp0/DbaB1t08qr/Stb4+LDWyT3Uyo EXDlzg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 +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 48P10Boe032375 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:11 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; Tue, 24 Sep 2024 18:00:11 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 02/32] usb: host: xhci: Repurpose event handler for skipping interrupter events Date: Tue, 24 Sep 2024 17:59:30 -0700 Message-ID: <20240925010000.2231406-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: RePv5ae2Ag3IuXF8lMI0krSWN92ksuLP X-Proofpoint-ORIG-GUID: RePv5ae2Ag3IuXF8lMI0krSWN92ksuLP 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=918 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 9e90d2952760..74bdc94d863b 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2951,14 +2951,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 /* @@ -3047,8 +3055,9 @@ static void xhci_clear_interrupt_pending(struct xhci_= hcd *xhci, } =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 51a992d8ffcf..a6fbfc11fb1d 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 Fri Nov 29 02:40:12 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 3A8CA1798C; Wed, 25 Sep 2024 01:00:54 +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=1727226056; cv=none; b=obAzitJGfQkAtynvIL6ikvGbQHMv9p/jgKLWFTiPrxU7rVlsb2StpaHOK80laHpB3CHRWkYgHqiXK8gZPQbRT+x+JV1m/QhlWxSwgXbksAxbwMd97QXxTsLA5o3VddE2TUdly9cm431fcrNrkEPR3h/5vzTA893R0+D4EUG1ftY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226056; c=relaxed/simple; bh=skg6UIxU/pMv3E9zD9o2TZGC4pkMoAHN4igM72YfWMA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AfXOc4f/OCPNe1W5Rwf4QnscWA6tALLVlfCABuswlFDPjjYGy9FjYXvcRufZ5HVLkaPbSjp2w767DJNqRwFDNY8cIi+gjnNzDy6WtV2YylgfMzy8XLWX8NI+P/U34k5l8vgjyFjJusBGmWRLvHemyt+Wy24IkLelvUBQEDN93+E= 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=H7LDGuq+; 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="H7LDGuq+" 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 48OJ55hp031702; Wed, 25 Sep 2024 01:00:14 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= 0ZOt60nzqTKhSEbIxsqylHw856gJTMJM0gWwrXx4SQw=; b=H7LDGuq+vOgl94Mp P/FqXiwLZc5Fu/fX8dew7HZU/hQtONKLnBMA2fcU+/6DeIKpvOdhW2X0vICCR/Qp 1YbEq2bT1tmXjXA2Qyg1V3NymBtT6ySEICi4h5EXflQQiH9QxhKfhejtlGWiOiZ3 aV1WjBP7wSBu6v2qo1ZKcRK6+p9hUKglKyMm3709KPesTJ1qIfUdQ/p29Tam04e0 Sg0emsi87HX4/MujKpSdQ6EhkUYgUh2xhs2NkNiZudoPlSmKWCRnIq1ljOfJf9vD ocsr8rZTfMy6QXa1l3d+dtki48GH03n7P4lELOulG0LXmiIrJ1+15RuGlkCHBiwa li9NMQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sph6thqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 +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 48P10Cax010535 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:12 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; Tue, 24 Sep 2024 18:00:12 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v28 03/32] xhci: sideband: add initial api to register a sideband entity Date: Tue, 24 Sep 2024 17:59:31 -0700 Message-ID: <20240925010000.2231406-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 3-83T1W637Wc6y3F5qjZbvBThjRjFrD1 X-Proofpoint-ORIG-GUID: 3-83T1W637Wc6y3F5qjZbvBThjRjFrD1 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 impostorscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 Content-Type: text/plain; charset="utf-8" From: Mathias Nyman Introduce XHCI sideband, 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 sideband 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. 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 | 9 + drivers/usb/host/Makefile | 2 + drivers/usb/host/xhci-sideband.c | 424 ++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 4 + include/linux/usb/xhci-sideband.h | 70 +++++ 5 files changed, 509 insertions(+) create mode 100644 drivers/usb/host/xhci-sideband.c create mode 100644 include/linux/usb/xhci-sideband.h diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 4448d0ab06f0..96659efa4be5 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -104,6 +104,15 @@ 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_SIDEBAND + tristate "xHCI support for sideband" + help + Say 'Y' to enable the support for the xHCI sideband capability. + 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. + 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..435a1e93b40b 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_SIDEBAND) +=3D xhci-sideband.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-sideband.c b/drivers/usb/host/xhci-sideb= and.c new file mode 100644 index 000000000000..69bc234818d2 --- /dev/null +++ b/drivers/usb/host/xhci-sideband.c @@ -0,0 +1,424 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * xHCI host controller sideband support + * + * Copyright (c) 2023, Intel Corporation. + * + * Author: Mathias Nyman + */ + +#include +#include + +#include "xhci.h" + +/* sideband internal helpers */ +static struct sg_table * +xhci_ring_to_sgtable(struct xhci_sideband *sb, 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(sb->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_sideband_remove_endpoint(struct xhci_sideband *sb, 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(sb->xhci, ep, 0, GFP_KERNEL); + + ep->sideband =3D NULL; + sb->eps[ep->ep_index] =3D NULL; +} + +/* sideband api functions */ + +/** + * xhci_sideband_add_endpoint - add endpoint to sideband access list + * @sb: sideband instance for this usb device + * @host_ep: usb host endpoint + * + * Adds an endpoint to the list of sideband accessed endpoints for this usb + * device. + * After an endpoint is added the sideband client can get the endpoint tra= nsfer + * ring buffer by calling xhci_sideband_endpoint_buffer() + * + * Return: 0 on success, negative error otherwise. + */ +int +xhci_sideband_add_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + mutex_lock(&sb->mutex); + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D &sb->vdev->eps[ep_index]; + + if (ep->ep_state & EP_HAS_STREAMS) { + mutex_unlock(&sb->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 (sb->eps[ep_index] || ep->sideband) { + mutex_unlock(&sb->mutex); + return -EBUSY; + } + + ep->sideband =3D sb; + sb->eps[ep_index] =3D ep; + mutex_unlock(&sb->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_add_endpoint); + +/** + * xhci_sideband_remove_endpoint - remove endpoint from sideband access li= st + * @sb: sideband instance for this usb device + * @host_ep: usb host endpoint + * + * Removes an endpoint from the list of sideband accessed endpoints for th= is usb + * device. + * sideband client should no longer touch the endpoint transfer buffer aft= er + * calling this. + * + * Return: 0 on success, negative error otherwise. + */ +int +xhci_sideband_remove_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep) +{ + struct xhci_virt_ep *ep; + unsigned int ep_index; + + mutex_lock(&sb->mutex); + ep_index =3D xhci_get_endpoint_index(&host_ep->desc); + ep =3D sb->eps[ep_index]; + + if (!ep || !ep->sideband || ep->sideband !=3D sb) { + mutex_unlock(&sb->mutex); + return -ENODEV; + } + + __xhci_sideband_remove_endpoint(sb, ep); + xhci_initialize_ring_info(ep->ring, 1); + mutex_unlock(&sb->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_remove_endpoint); + +int +xhci_sideband_stop_endpoint(struct xhci_sideband *sb, + 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 sb->eps[ep_index]; + + if (!ep || !ep->sideband || ep->sideband !=3D sb) + return -EINVAL; + + return xhci_stop_endpoint_sync(sb->xhci, ep, 0, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(xhci_sideband_stop_endpoint); + +/** + * xhci_sideband_get_endpoint_buffer - gets the endpoint transfer buffer a= ddress + * @sb: sideband 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 + * sideband 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_sideband_get_endpoint_buffer(struct xhci_sideband *sb, + 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 sb->eps[ep_index]; + + if (!ep || !ep->sideband || ep->sideband !=3D sb) + return NULL; + + return xhci_ring_to_sgtable(sb, ep->ring); +} +EXPORT_SYMBOL_GPL(xhci_sideband_get_endpoint_buffer); + +/** + * xhci_sideband_get_event_buffer - return the event buffer for this device + * @sb: sideband 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_sideband_get_event_buffer(struct xhci_sideband *sb) +{ + if (!sb || !sb->ir) + return NULL; + + return xhci_ring_to_sgtable(sb, sb->ir->event_ring); +} +EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); + +/** + * xhci_sideband_create_interrupter - creates a new interrupter for this s= ideband + * @sb: sideband 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_sideband_interrupter_id() + * + * Returns 0 on success, negative error otherwise + */ +int +xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, + bool ip_autoclear) +{ + int ret =3D 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + mutex_lock(&sb->mutex); + if (sb->ir) { + ret =3D -EBUSY; + goto out; + } + + sb->ir =3D xhci_create_secondary_interrupter(xhci_to_hcd(sb->xhci), + num_seg); + if (!sb->ir) { + ret =3D -ENOMEM; + goto out; + } + + sb->ir->ip_autoclear =3D ip_autoclear; + /* skip events for secondary interrupters by default */ + sb->ir->skip_events =3D true; + +out: + mutex_unlock(&sb->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_create_interrupter); + +/** + * xhci_sideband_remove_interrupter - remove the interrupter from a sideba= nd + * @sb: sideband instance for this usb device + * + * Removes a registered interrupt for a sideband. This would allow for ot= her + * sideband users to utilize this interrupter. + */ +void +xhci_sideband_remove_interrupter(struct xhci_sideband *sb) +{ + if (!sb || !sb->ir) + return; + + mutex_lock(&sb->mutex); + xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); + + sb->ir =3D NULL; + mutex_unlock(&sb->mutex); +} +EXPORT_SYMBOL_GPL(xhci_sideband_remove_interrupter); + +/** + * xhci_sideband_interrupter_id - return the interrupter target id + * @sb: sideband 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 sideband client + * needs to write this ID to the 'Interrupter Target' field of the transfe= r 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 othgerwise + */ +int +xhci_sideband_interrupter_id(struct xhci_sideband *sb) +{ + if (!sb || !sb->ir) + return -ENODEV; + + return sb->ir->intr_num; +} +EXPORT_SYMBOL_GPL(xhci_sideband_interrupter_id); + +/** + * xhci_sideband_register - register a sideband for a usb device + * @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_sideband instance if successful. NULL oth= erwise. + */ +struct xhci_sideband * +xhci_sideband_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_sideband *sb; + + /* make sure the usb device is connected to a xhci controller */ + if (!udev->slot_id) + return NULL; + + sb =3D kzalloc_node(sizeof(*sb), GFP_KERNEL, dev_to_node(hcd->self.sysdev= )); + if (!sb) + return NULL; + + mutex_init(&sb->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->sideband) { + xhci_warn(xhci, "XHCI sideband for slot %d already in use\n", + udev->slot_id); + spin_unlock_irq(&xhci->lock); + kfree(sb); + return NULL; + } + + sb->xhci =3D xhci; + sb->vdev =3D vdev; + vdev->sideband =3D sb; + + spin_unlock_irq(&xhci->lock); + + return sb; +} +EXPORT_SYMBOL_GPL(xhci_sideband_register); + +/** + * xhci_sideband_unregister - unregister sideband access to a usb device + * @sb: sideband instance to be unregistered + * + * Unregisters sideband access to a usb device and frees the sideband + * 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_sideband_unregister(struct xhci_sideband *sb) +{ + struct xhci_hcd *xhci; + int i; + + if (!sb) + return; + + xhci =3D sb->xhci; + + mutex_lock(&sb->mutex); + for (i =3D 0; i < EP_CTX_PER_DEV; i++) + if (sb->eps[i]) + __xhci_sideband_remove_endpoint(sb, sb->eps[i]); + mutex_unlock(&sb->mutex); + + xhci_sideband_remove_interrupter(sb); + + spin_lock_irq(&xhci->lock); + sb->xhci =3D NULL; + sb->vdev->sideband =3D NULL; + spin_unlock_irq(&xhci->lock); + + kfree(sb); +} +EXPORT_SYMBOL_GPL(xhci_sideband_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 a6fbfc11fb1d..503784345787 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -693,6 +693,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_sideband *sideband; }; =20 enum xhci_overhead_type { @@ -755,6 +757,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_sideband *sideband; }; =20 /* diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h new file mode 100644 index 000000000000..6c11e240fbca --- /dev/null +++ b/include/linux/usb/xhci-sideband.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_SIDEBAND_H +#define __LINUX_XHCI_SIDEBAND_H + +#include +#include + +#define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ + +struct xhci_sideband; + +/** + * struct xhci_sideband - 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_sideband { + struct xhci_hcd *xhci; + struct xhci_virt_device *vdev; + struct xhci_virt_ep *eps[EP_CTX_PER_DEV]; + struct xhci_interrupter *ir; + + /* Synchronizing xHCI sideband operations with client drivers operations = */ + struct mutex mutex; +}; + +struct xhci_sideband * +xhci_sideband_register(struct usb_device *udev); +void +xhci_sideband_unregister(struct xhci_sideband *sb); +int +xhci_sideband_add_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep); +int +xhci_sideband_remove_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep); +int +xhci_sideband_stop_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep); +struct sg_table * +xhci_sideband_get_endpoint_buffer(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep); +struct sg_table * +xhci_sideband_get_event_buffer(struct xhci_sideband *sb); + +int +xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, + bool ip_autoclear); + +void +xhci_sideband_remove_interrupter(struct xhci_sideband *sb); + +int +xhci_sideband_interrupter_id(struct xhci_sideband *sb); + +#endif /* __LINUX_XHCI_SIDEBAND_H */ From nobody Fri Nov 29 02:40:12 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 B065A1891D2; Wed, 25 Sep 2024 01:01:36 +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=1727226098; cv=none; b=G5YkS55jRg/gi3TD/PfBAHnymXxuagWjalO6dnC1rfZAgo1Nt/a2svy/e0cpR8WnKoy6qEkfAHqejGOspLo3ZRwdRNDbCeZoSh2sfzbmcG7FeB6iT06tE2gCjOKa59ePVaepVfV7bJUthXx6/npPEDwtHRiJoH+G0YccRjW3gHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226098; c=relaxed/simple; bh=S7gNn/zMH9Mq7yohNCakzHW+ZK7IqUedqKKHCL3FDOU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=URaIrIFnQcCk6DKpbtvxK8s+Di/rFJ59lKkQLWygJYr0FqLCPdeXeb/pA6FrEDRLRdJ/oNUwckKcw+KOoh6cWpR/ZL7kGJrTlGvnO7K8F6jjKo4jEcp1VEqrR25nk3zV2OONK0dCSoNeaMPG14DLRyCvxRFXWT16Jv0Old/fWn8= 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=gOY1VxMN; 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="gOY1VxMN" 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 48OHnxLj030180; Wed, 25 Sep 2024 01:00:14 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= c5gwoddCxMnmmFAKaTw4cQrxCONcapW95+AyW+pR6yQ=; b=gOY1VxMN5b76TVVW MLxJTbwzxWf7oXPgpfolJloTPTycHmPbJeyh2ma4A/uB4oTJyDbDOsUi09ZlOsDT 3OYCZcj+UxQGxzdhx6B3Cm3I9JntI8jlU1FrvdGy9SoaPtuY7P525JZeQYS7g9Qa WwVXRuteMtaCf+5KYEgMfWfpkNNNI7c+qwUxU2Xg+WlDFyYFQCd6j7b8nhbdQM6Q Ce3B8Xj//85fZeIksaJ+82xOJ7WB5apR4ZrDwyu8K1b1QLxtONz+cAsFKslc4sjh OT1GQ38MAU26d74BtyVRbH55Gl8+Cf6LP3P7zMGUML9nYHdhXoedYhLLWIpKXcDu 8UPxKg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj77-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 +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 48P10CRs032382 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:12 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; Tue, 24 Sep 2024 18:00:12 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 04/32] usb: xhci: xhci-sideband: Set IMOD for xHCI sideband clients Date: Tue, 24 Sep 2024 17:59:32 -0700 Message-ID: <20240925010000.2231406-5-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: MSXKG88uuFqnuUmaDxAA4ItNFXJ8SOSA X-Proofpoint-ORIG-GUID: MSXKG88uuFqnuUmaDxAA4ItNFXJ8SOSA 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 clxscore=1015 bulkscore=0 mlxlogscore=680 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 Content-Type: text/plain; charset="utf-8" When creating a secondary interrupter over xHCI, add an argument for xHCI sideband clients to specify an interrupt moderation value for the interrupter context assigned. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-sideband.c | 4 ++-- include/linux/usb/xhci-sideband.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index 69bc234818d2..248d9713570e 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); */ int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear) + bool ip_autoclear, u32 imod_interval) { int ret =3D 0; =20 @@ -273,7 +273,7 @@ xhci_sideband_create_interrupter(struct xhci_sideband *= sb, int num_seg, } =20 sb->ir =3D xhci_create_secondary_interrupter(xhci_to_hcd(sb->xhci), - num_seg); + num_seg, imod_interval); if (!sb->ir) { ret =3D -ENOMEM; goto out; diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h index 6c11e240fbca..bc5b56a77e37 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -59,7 +59,7 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *sb); =20 int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear); + bool ip_autoclear, u32 imod_interval); =20 void xhci_sideband_remove_interrupter(struct xhci_sideband *sb); From nobody Fri Nov 29 02:40:12 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 D481515855C; Wed, 25 Sep 2024 01:01:26 +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=1727226088; cv=none; b=HUxShmOOuRj4IcLYNhUKczdxyAxN5jyNf5j+Guvwi9jLgBDKYg1dLkqthYxrBMug6eK6WqEu0GT46vMsFwkUYs4RmkKvGfqvgsyYv+zcMJmZLXlukP+zRJaAXqjumwtvEb32MHo3EekJ9ELD2eCBI6AWDCzNTzXg+nBV/6KirwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226088; c=relaxed/simple; bh=Kp5ddds6Gc1T8ofGoRt/Ck6ZScfTXnzSZienvxMHqq8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ePgrX58dUohmsy33JXVXyLDYbCxyfgMJHWefKzEz788XS6S+hu7T2ht90mFtIJewlJWzyMndn/CYwCv+mX7IwOGmG+vATfLeX7qYkyFyNeBrVVBkpB38XK1KkQuJmseHdGX2IsLkYfr0HlFHYFL2D2ZqPhKwlRVTaPey7gc5F3I= 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=XjgbTkWh; 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="XjgbTkWh" 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 48OHXsAe015817; Wed, 25 Sep 2024 01:00:14 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= CIiOO9bHFnAQkxDw9TUjFKgKhWCq4HlRtM5F6BZuU9Q=; b=XjgbTkWhYiqN+1Yz a1nzWSDHY89werGuJB9V6ldSiniUVpLvjTWdFlLKnq8SOwW2z8VAHgT8BuC10y0Z 0V8cOsJfTcjH8rP32We/J6Ja6BwXUrtS3NSirQqRbfcACODY2Jq80DuYTCmvh30V /tX8XB7gRd1AV6Pgp1KTKWTUsCY0+cONQ3NoFt8gJGprobpaJ3iHJzDvFnP+/Wkt 25z5CzFxx6wIjqjjtcdrJZvmwFmL68epTcpOW9JUv9y1VlSUBkNEEmvILeZ1L9Q0 a54D2nrJeiNIRPUGJukNkmsCr/0Q3K2rDPUsqLd+6hjjGtxxiR6KYbdCQQdiT17Y HcoLrQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sn5bth6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 +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 48P10ClM010545 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:12 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; Tue, 24 Sep 2024 18:00:12 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 05/32] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Tue, 24 Sep 2024 17:59:33 -0700 Message-ID: <20240925010000.2231406-6-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: e55Z-2cFkwCIdXONVhV-QSfaXprYtAJv X-Proofpoint-GUID: e55Z-2cFkwCIdXONVhV-QSfaXprYtAJv 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 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 mlxlogscore=977 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 a25576f27e66..5e022ce3a8fe 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1816,7 +1816,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 @@ -1859,6 +1859,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 74bdc94d863b..b7009aee4130 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3012,9 +3012,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; @@ -3112,6 +3112,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 8d7566e33faf..ed8853accab3 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 503784345787..e37d27190e3c 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); @@ -1924,6 +1928,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 Fri Nov 29 02:40:12 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 5D07115B97E; Wed, 25 Sep 2024 01:01:33 +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=1727226095; cv=none; b=M/8Krxgu9vrSPe+MrzSob2A5ZAwyTjGwXIxQSXE2eMAnBDs39OC8jr2DWXVS0+UeAW6K3V978hf03p5obnMCw2g/Jf5gsh41VKM/i284gCMUnadxZJc1IN2a8jE5OT+Y5NZvwhJHWJXMXznn8foQ7p9rIhBzgz94vIA0XySWqCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226095; c=relaxed/simple; bh=k5pZXz7zhxPw2OQXkssRZiGR5LwzKnHF+F0otCkTWrY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ky5EEL/2X+PjPS+1t7ygx+zWZIfGZc8moMYeDmpv0P0w7vt3jt+EYjOwxYl1gsfOOPUo/X0si/0twU9ooiS7cb0bDqE48yG4Z4Z1+UaJkIEC4rsMoFrN2TzNbtuYYo+CzuScHvXBbs6DApPnBCAZuQ6pE10jPSzftTkZ8RQ2BKk= 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=obLh8InV; 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="obLh8InV" 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 48OIsAp1024446; Wed, 25 Sep 2024 01:00:14 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= /U7Wd7+Vcr+CGbwCDV49RDGBeJTU3cSkWA6J+KzK5+Y=; b=obLh8InV86Mc2ISF TBHIKjoTIhuPsbhd5/O1IHN+eRHABUDSxYR3C3MO1z6L8kHh+Z1cvSd0IdLj5SnY JHyovTMD65inF6vy2VGllHeJKOdmImwOeFxXnRAXetMV91zZSBhUdvjUinlQs9iv 568RORrbyXYaaf6OUyKMvQiaOFePn6LFVA/U/tTOmiBYlMAGD03cvoR0vmOusQDw 8C8E6TDv7RYBNWlrXA4d+uZs3DgKNTe7dDCeb1fmvpUQHm5uZ9Vwl80BtD9msiCd LaFFyVykFVlNV8v6U0kMMWFL5VOYSWdu71kIRpTj1voNM1LHKZ7LCkMRdsWWxFCO iTUD2g== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sph6thqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 +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 48P10D25006008 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 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; Tue, 24 Sep 2024 18:00:12 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 06/32] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Date: Tue, 24 Sep 2024 17:59:34 -0700 Message-ID: <20240925010000.2231406-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: CvH-uCFb7pl48g1AKpeyN9soTGgmQDpb X-Proofpoint-ORIG-GUID: CvH-uCFb7pl48g1AKpeyN9soTGgmQDpb 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 impostorscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=831 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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-sideband.c | 5 +++-- drivers/usb/host/xhci.h | 2 +- include/linux/usb/xhci-sideband.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 5e022ce3a8fe..80cd77fe3dec 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2340,14 +2340,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); @@ -2355,15 +2356,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) { @@ -2379,7 +2383,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-sideband.c b/drivers/usb/host/xhci-sideb= and.c index 248d9713570e..d04cf0af57ae 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); */ int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear, u32 imod_interval) + bool ip_autoclear, u32 imod_interval, int intr_num) { int ret =3D 0; =20 @@ -273,7 +273,8 @@ xhci_sideband_create_interrupter(struct xhci_sideband *= sb, int num_seg, } =20 sb->ir =3D xhci_create_secondary_interrupter(xhci_to_hcd(sb->xhci), - num_seg, imod_interval); + num_seg, imod_interval, + intr_num); if (!sb->ir) { ret =3D -ENOMEM; goto out; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index e37d27190e3c..b4b411d63694 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-sideband.h b/include/linux/usb/xhci-sid= eband.h index bc5b56a77e37..f0223c5535e0 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -59,7 +59,7 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *sb); =20 int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear, u32 imod_interval); + bool ip_autoclear, u32 imod_interval, int intr_num); =20 void xhci_sideband_remove_interrupter(struct xhci_sideband *sb); From nobody Fri Nov 29 02:40:12 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 6A1A915530C; Wed, 25 Sep 2024 01:01:18 +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=1727226079; cv=none; b=bwXeHDqAtOZI+isZbXblcC4vYMQ6JBXytoLZrtF1hgebsAimMXpFRqoq1VBu4MrUK4TQpF65hklxcWpgqgjWQ8XZck1lQtV8YtGoPDh418nSUt+eH3Hd1aoeDclHpeysvxUEYNODJEpXsYPr9iEWc4ZKwABa8G/Dh6ud2DKUtOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226079; c=relaxed/simple; bh=ltXX8jP7pn8uVpu5KSPpn79cIYm5HfBGTiCUp+UHg9k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BqT3ARFr3gDg7ueXBylRSrP8F80PXOFr1Ao1Z8oiySkp0gjAa55SNxgtzNypQuVU48QHgON3xC+DoLedaFAKYixNoc90Q/Se6GdtFcWuPC2F1WGL5R9E8cH9GMqtkqCAtJWYjTgPz4S0T7W/zTMMSXRmFNx33Fyo8w/y6OcdroM= 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=SdMsFCeq; 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="SdMsFCeq" 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 48OHXsAg015817; Wed, 25 Sep 2024 01:00:15 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= AN6ZcvMWlqNjOXpEc6FdiWAhkqYqJERCJ3muWeL5xeM=; b=SdMsFCeqCZYgOJ6N wYWRJXR7SSig3oGKeFvuu0qb4DzrCQ6Z6g/03ddtGDarRosOHk/66Z5u4YC1GoWv oSXGRKXhyGkfLfT3JPc+Z1mA/8ddxhVJH31fp5dWbhdGjRlpqU7mT8mB2mSbyzn1 VUC+eGATMKNl1goeITJcQw0nyfdT71XOyjvz2BKrnlzyyHUP3rbYESfInvZVp2uN Z6zS09PPwhwpRxjBsxtAJxGIY2n+L6iWkM827iZGz5mzgXOjsjS54qMI6C8kkkic odY8on+7Jshf59EdaLVdnHa5rhiF0gm4yk0ptSKMt93M0vMTAoDGPP1lct0rMhlI BNfdPw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sn5bth74-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 +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 48P10Dwj032399 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 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; Tue, 24 Sep 2024 18:00:13 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 07/32] usb: host: xhci-plat: Set XHCI max interrupters if property is present Date: Tue, 24 Sep 2024 17:59:35 -0700 Message-ID: <20240925010000.2231406-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: MSFUBR-ARRURaFb-gH5Y2TATKB9eAJ3O X-Proofpoint-GUID: MSFUBR-ARRURaFb-gH5Y2TATKB9eAJ3O 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 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 3d071b875308..1c12cadc02a1 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -258,6 +258,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 Fri Nov 29 02:40:12 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 77635148FF2; Wed, 25 Sep 2024 01:01:01 +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=1727226063; cv=none; b=uFoxVlSv8ZM7Gw7orotR2Jd/Ozbunc9L0PtlLROP3FvpWMDIzdrlNERNxinVxvsE/wyycaFQn5NfQROPnwBL+eHPHS8J6osCTAa3sQ/KAkHB2HJHOqSF27BdgJxUr4oKloOToMn8RmZl3as5GLD4MJ7FflZOHZwxWqmH9xqTd0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226063; c=relaxed/simple; bh=SEZVsSJ3a46E0oX5ZwE8La/80l4wQDAX2p6gKqh3ypQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V5UUs4SCpX6RIaCAiv3FN1Wo08a9biOoQCuVGhlEaWO3By+KlqbEXf1hrNicmySZbax/iqZ4ZUW+iu4r0ic/Ng28GL2mkzzUxhDuN8Amd2mALUWLVrFQ5mO6qOV9xhn3u60eOEagJ8+lcXR+U+elw19AkjMNL7IgGpljXwZx8yM= 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=XMFVA/AK; 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="XMFVA/AK" 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 48OI7CD9006211; Wed, 25 Sep 2024 01:00:15 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= 6bztHUYvMMxB9IN8zQZC689zDaxiSCm1Mj9EPEMEDNs=; b=XMFVA/AKrF9WjS1/ 6phj66seV5eqB3Jh+YdSodbKPdOKK3JpLti5olNB5nq9uDye8Z3KzYVUrYA1zv7O 5whwQ+jFX1hNfBcc0pwG93sy0YIUTWBADjF6+igf94+WxqZ2K0Fen6hLev6kYXbD WEbpz8VBp8WKK4zpcLkumIPfigtdcB9bhk8eSn/qPQuIWg7MgxXg0HvkWfXqJV1l 2WbgFjgnOSN1SFmHve7YVgJZHFSE4fg7KumfJoQPpM38THWBlJ/ylmJn8xsWDGug /sj/fJkMEov+Uuiksu+W1WE21HXQWfJSTLlI/oogXySSAjZfe1oOum4wan9Fgi0C 4+faHg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sph6thqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 +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 48P10DIB006013 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:13 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; Tue, 24 Sep 2024 18:00:13 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 08/32] usb: dwc3: Specify maximum number of XHCI interrupters Date: Tue, 24 Sep 2024 17:59:36 -0700 Message-ID: <20240925010000.2231406-9-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: iZSfK5BWFZF669mV2MTVXRdDq5l8dUqk X-Proofpoint-ORIG-GUID: iZSfK5BWFZF669mV2MTVXRdDq5l8dUqk 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 impostorscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=853 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 7ee61a89520b..f98d5d04f493 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1573,6 +1573,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 @@ -1595,6 +1596,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); @@ -1648,6 +1652,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) @@ -1736,6 +1746,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 3781c736c1a1..95e6989d116e 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1077,6 +1077,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 @@ -1318,6 +1319,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 a171b27a7845..d883cd7b1615 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -180,6 +180,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 Fri Nov 29 02:40:12 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 C477E18A6C2; Wed, 25 Sep 2024 01:01:38 +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=1727226101; cv=none; b=RXIxFZ7y6T7zICW0mAPCdZxGXHYc3bte61qwwxu425H/XNcp3UlmYcqfP7k95HJ4JqLkoEtfJjcqoOZRPEaUINsMqIb91bCvsynCl0/JuFKEOaqBbm7v5tSpRdp1w1VWmHQEeMX29HPtMkT28sN33M1Q8jCYd3QoaFfVhvbsUgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226101; c=relaxed/simple; bh=H2VvMAmjHHXuPhfwtxy05hMZvGM02stpNq1uNd09GGg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ehLj8vRSDsS2LOqAmuHUVT26PgFlmxdcY5/eu0srigJImIsOA/WbD3Ppg/xW0v+g99Qi4j5iEWC/E6HItgU5aP8JmI+bkt7qXWdgj5QOvP6x5qqXBh/av7s8XE+tUCyrTkqDgigk4hQSHBECeyEAUQa6tzBHxZD0EF8rXApHrn8= 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=eRicVfZE; 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="eRicVfZE" 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 48OGxCiR032075; Wed, 25 Sep 2024 01:00:16 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= Duu2pk9fYk9yJEWt+Uf2phJwawOP/BI2KR50wacEDKE=; b=eRicVfZE4ScOzJLl ovCVnKFGa1e+I7knX50EyRkmfgPYLIbHdmDQLj7uUeFljRGADrBsOQCAVpL0mqv2 CGRQL9+u8KKBLrRI+NRdHd6oqU1pf5hJp0vBGOVgQ2NZ4sCgYybDuReAiyuigQIK a+78IgSLoj9m1p0QE/ouD4e+OEYZPnq13uFTz0PNoZbrefw8muQnmfnqb1juZgjx Kee32EU77VdGMh+CTZh7PBgc0AA9Pd1gnxcb2IGpTrBZDzfj1cypaIOg0HOH+Nwk 35SCG5XIzuks/GOGPoeRzOwwb89oY3ESkdDwcuhSYsUyEfKaImwteG3StD3DnyvA vUbWxA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snfh2ku5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 +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 48P10D8x010558 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 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; Tue, 24 Sep 2024 18:00:13 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 09/32] ALSA: Add USB audio device jack type Date: Tue, 24 Sep 2024 17:59:37 -0700 Message-ID: <20240925010000.2231406-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: FDslvmMeyF2osHSZYferWEWNxzAgFuAQ X-Proofpoint-GUID: FDslvmMeyF2osHSZYferWEWNxzAgFuAQ 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 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 03edf2ccdf6c..607a0c0fc20a 100644 --- a/include/uapi/linux/input-event-codes.h +++ b/include/uapi/linux/input-event-codes.h @@ -922,7 +922,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 Fri Nov 29 02:40:12 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 70442189F2D; Wed, 25 Sep 2024 01:01:38 +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=1727226100; cv=none; b=s/4swkrmYGxEtauwxT7v4hE7sdN4VkmxgmsKg8MmXKJbQeJGUa+9T6p+9tuosjkfv6oNMLlBsdIsZizi+gU3EVXiIf6d75qO6YnC2nCZMdkfbMxOPFCIuDzyTTSeRje4gfdjU9E/bBHDnF9dW64KMIZ77V7imDWQryr5HsFh7QQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226100; c=relaxed/simple; bh=h9Y1cdj3S7SChaa7F6arX081nDigjqC1HDiLCdhPpJc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QdblUJEGjkx2QIKRsI8Wmr9jTtStHBRQNjX3qtCkHbGe5oF+ngZwrpDhY6FsBOYXiK0w7t5OZ9fQUXoZI3c6e8MVTmWreOh5qODaPbF6wuEfk9ld/Mj6KmGeM52Ipupwc3/J8pveMP6xtDqKOjPw8nOnd813IVWH43CtAo3Hsjo= 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=BOQJLhxg; 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="BOQJLhxg" 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 48OIUUMY024753; Wed, 25 Sep 2024 01:00:16 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= tcQSUGQDNQN5yLhmKTUokyJRkF6R5HGF/HngXA/tYEM=; b=BOQJLhxgXvH2ivvH 6ESHojZoWtMCn3oWnoFIYUYiYI+Xc7kvC2kxFtTeDrgjE7PhNDOZjO16+dLsAaYm yHcIF7PqZSeK5FCbaYN/arepKHnSe+Rp0dwQMnhdIT4kzMrPpcVGtUlfGCNUkqi5 onfq0sdzx2922ZkzFr7Fv82A+uDJbtBYMPRqVxt4UatXIuwHZFNAGQkdk1J+s9u5 /CQK6yUdwcIL1JCXWmP3EcYh3X+6sOmjNUi6mQwvRg1/IjKHGXFPYZOxm8E2s890 Ofl0nhh0qf2aL4pHiv8afF84QTB8WX6KGN+/0McSPWqD/7shuG8MJI5Cvpqd3QUV x+Snrg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41skgnauev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 +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 48P10EAo006030 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 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; Tue, 24 Sep 2024 18:00:14 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 10/32] ALSA: usb-audio: Export USB SND APIs for modules Date: Tue, 24 Sep 2024 17:59:38 -0700 Message-ID: <20240925010000.2231406-11-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: pJru0MU7oqcMnQdDet7jGt_z4j3Xtg0N X-Proofpoint-GUID: pJru0MU7oqcMnQdDet7jGt_z4j3Xtg0N 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 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 bdb04fa37a71..c6d9d8d548b4 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -1022,6 +1022,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) @@ -1030,6 +1031,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) { @@ -1052,6 +1054,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) { @@ -1065,6 +1068,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 8f65349a06d3..9876abb80853 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -1513,6 +1513,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 bf80e55d013a..4322ae3738e6 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 Fri Nov 29 02:40:12 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 472FE13AA38; Wed, 25 Sep 2024 01:00: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=1727226056; cv=none; b=oRe1aI94shRGp2Q8w8YUV1oFybkMVOGQmvsmTNdUf5DTGBtVbClaQ+3RiHNMmSbzaNGuGjgO0KEafwE8qjwNL5bKTigjdstNoV+yX5Kve2WUEHEhK4bi+AIVKbYSVac9uBHyl329Fi94Ott2HREF5jPoB5wFwv3aToR80rgDK6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226056; c=relaxed/simple; bh=29VWA0DxT8hK6fkCwQrxvdJBmifY1Kc1/JCR3kgrfD8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B3llOX+ecSi2JoOW0e4e36eTBS6CNuroMorbGHdp2kQHibiBZ27V7kfgKsz+2CF/Xn820ut1iidO1Bg81s5NR5nWBjwOwJYtWPBeBzfHzYpFQqPbJ5fomMgvlP2XS9TkJX9PAMeVEoBqiHCdC5ABS4zvQPPurbYk9QL6B1xZuMc= 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=Ykb8MUlM; 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="Ykb8MUlM" 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 48OIkFbR032044; Wed, 25 Sep 2024 01:00:16 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= s/OTeliDf1Ah9/XP4Pomi7vIYaEPF2MJpZ2JrUJEjg8=; b=Ykb8MUlMoJgYtCKg y78goUlRE7E/PoPFVIaONXzaCJD66JJBy1Z8c/aH0nG3pYivrhDsStcwtHbsJVmH WQTJgloNw7ybp157II9MMw92ZEH0LYk06uUMhRy5/jr0aEg3kjOWegoTS29VUWol Y82bD94eSFOVXtzgVJk2mTDw0K4SHJT+IH/aUSqBD/6n3xjtqWXLsngpi18GuZ83 NRnh8s2Cb/m+QqYKCS+LZf3yUOYp7UDdikoc9l2mKxRBX6B3cqx/KnLktUZ7M4A1 ab47tPoMG0FsGpSoiZ0QgwBJoomWrO56BjTXmP51OaoYe3tJ3uyoKzUDNhIiOphQ jcYrhg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 +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 48P10E1h018666 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 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; Tue, 24 Sep 2024 18:00:14 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 11/32] ALSA: usb-audio: Check for support for requested audio format Date: Tue, 24 Sep 2024 17:59:39 -0700 Message-ID: <20240925010000.2231406-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: _dI47_NJLD4LSXMEyzRgsKR6LCjuzCS2 X-Proofpoint-ORIG-GUID: _dI47_NJLD4LSXMEyzRgsKR6LCjuzCS2 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 c6d9d8d548b4..1f9dfcd8f336 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 Fri Nov 29 02:40:12 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 BD7CD142623; Wed, 25 Sep 2024 01:00:58 +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=1727226060; cv=none; b=GJbOEgOQZzLpZbQ4AweQn0KchtZqL+V8oVjtBuTRLKtsfwejRJH5k7F/3ttwzBlomwnjw1IjXBU8nCKSBxznO50kjz6GO0oyg72guJnSnPo3POgm2Z3o9YNasKGBGxLsUxQiYtq3DGqNNH7ZDT9ErfwWkK1GDukpGvIc8DLKJZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226060; c=relaxed/simple; bh=Nm8aqgQ0GcbTIdZz+5RH7tVRiIi1hmi+glCYy8qYN8M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h5KwqVtTpemAzHW24FNd13iDwVoNbUZHjoOnDmG+XihDJKb8MkCYfGtuLFEyJNGWEa2mLhVdX9UzOPnDDZwx/9UVLMQs96ZImoOMr85ecnKvRVqEoTT2uEghCNYw8u3MNevh4lBwQpHzuA0+N2F2HRSkhPpNt6P7fzygKpMPmeE= 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=hb0KTux2; 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="hb0KTux2" 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 48OI9Chr012001; Wed, 25 Sep 2024 01:00:16 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= iYFID7OryVHMFMsUucuLQ+QUngojA4llWqFBVJpFtVY=; b=hb0KTux2G3I5GZkK TjipEZY6kDjX+dbO6iT8mcmFPr1LhYMVp+uuz2ylpQ0wKDen0vN+BFRqLuz316g6 Ku2FvnWvmU3g5IUjcbg9Bj626l8a4Bo2TceUql0EbBkf34ydc6Z4McQdsZCo0qls OFPvU6Z+hR0Ki4KDzkREReweOSGGLluBKs0oyOtXRpp1MTqsoZtW7opZZF2DzsHE OxrjmNG4N7xCBHeHGo0LO+md6KAWz5cOb8H6J1hBSE5Bcigq95G7A5Bq77Os6SaX ME7GH4klu5QbpkN3mCXPU48Rm41OYfTfLEgAz7bQN+6LyCmWPkU15BN8RBVIQz8/ nvFd3g== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 +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 48P10EVs018669 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 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; Tue, 24 Sep 2024 18:00:14 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 12/32] ALSA: usb-audio: Save UAC sample size information Date: Tue, 24 Sep 2024 17:59:40 -0700 Message-ID: <20240925010000.2231406-13-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 644k5Fr5gamZmNmZE7Va7lGQqFvao7KW X-Proofpoint-ORIG-GUID: 644k5Fr5gamZmNmZE7Va7lGQqFvao7KW 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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. Signed-off-by: Wesley Cheng Reviewed-by: Pierre-Louis Bossart --- 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 3b45d0ee7693..5fde543536a8 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 (1 << UAC_FORMAT_TYPE_I_UNDEFINED))= ) { From nobody Fri Nov 29 02:40:12 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 7292413D899; Wed, 25 Sep 2024 01:00:57 +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=1727226059; cv=none; b=WsUzSmxXh3vBn6uCIE6fKCx8b1I/BHBn88EjFyBN06kjTES/wwqZ9Y4WmO/84ju0qeg48KYLpHPVm0+RbGuNrE4UnAqnXrvB/jMX5HJbcejpEmJ1FlSHnEaqqa46TQnyzDbzNBortotHsx555UsPRwQGBeZsEwuKyEPTLDzVVq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226059; 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=mpTw/cwG795as0nzPkGkRSdT4r4Lcv77YDE75hB3VzMu4YQJNDCjA+r3WLPOlVmY25LhXopnziAtCHTxKLOjFAnfiTi1PW/drTv1il8JQ3jUbrskXIRgnXx9R0QIVmKYDikJeeU/bhqpuZhGI94zDnesTHLETn2MeHC9Ux3l9ko= 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=n1gx21/u; 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="n1gx21/u" 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 48OIkNk4016957; Wed, 25 Sep 2024 01:00:16 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=n1gx21/uL2f5Dw7z RFzYkVCEPauSxeCc4k6WhMT4QO9jt6jKL0FE+vYv9tEzUKC9xFNZEa7dvlLOwQqq F7LwY4R+VACq0+psBbgbCKnFWzHvznZ0SpfoNR8b90tOGgW1URvQhEoI6PYX6cfW QqIfTRs7sxnK6JR+sihheOZuJthee646EKio9LCkFvnwwiy3NdoA9GKShwkFdx1X Z2XlzeOJhfKnJCQtXvddlo2xBprpPAW7pW9TT4NcPboRDaNTcJTgPbwwd7XEmL3B Lf4S7H1fiNwMtQbHkGqxauspEW1jRlKzoT73V/MA7fdal9A8vOPWAGNGFTexvJas SzjbmQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sn5bth7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 +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 48P10EFX010574 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:14 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; Tue, 24 Sep 2024 18:00:14 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 13/32] ALSA: usb-audio: Prevent starting of audio stream if in use Date: Tue, 24 Sep 2024 17:59:41 -0700 Message-ID: <20240925010000.2231406-14-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: JpKw8roQVHBYAhZh67mxBez9-fUk-NXk X-Proofpoint-GUID: JpKw8roQVHBYAhZh67mxBez9-fUk-NXk 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 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 Fri Nov 29 02:40:12 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 8D0E318CC12; Wed, 25 Sep 2024 01:01: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=1727226111; cv=none; b=cwF+yACRD7gutvZP212+ldS5ZnMouLNDc6Fufr5T19CE9k/Uu0V3+HcUCdl779CJE/dpktOs7qVPDUsjMXLgkosoHIgrg8kzi9/dvwN11ZsHLOh+JhwsV0EmZp9tEaYVEThAmz/z+cmioBa6ZDadfJZrKguZX9nkb8JoopDBb7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226111; c=relaxed/simple; bh=kuXvZj2O2+6sLb6+HCTWSvVJ9L05ubY9bD4DgQROLzQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oebQtYCDqQHl4YXcxY8++O6R1xKBOCGWo+EStIEZJu4jnaoGHnFjFQYFMytHC2ajFFnODTtEIR1I3XTH4sSjsLwosQ4IQJSJipaP4AMIeyZf7ajI5AImP7QO7NCwHDqGepT3tWl6U7nAdUiV9iw/NakdBEK5lK7Vd7z57mfOfh4= 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=iGFcqDsn; 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="iGFcqDsn" 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 48OHVpRA007866; Wed, 25 Sep 2024 01:00:16 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= T5qz9jWyU4v1+Ht9Jgi80H4Z4CwhOfh2aqovq123O+U=; b=iGFcqDsngfhK/R2A sNYSMho/R08eIRJ3Hr/zYJ+yR4thcZFCGGpT4vsrJ9/FIoDVDoLOBjchP4RgbxWN MTe7SF3XSyPiCaG5aHlrt1mOeakSlVJfLeoy5SA9hOEjL5TwIKhQNYGhh1HUKqQI VGVk8V1SN0diPhzKoY8I/mImDXgTkn23oW4TnBqZBwyJavQWAxbJ2kFuxujD0x9k OtCn5sPJ1CWnCHynUNuh4vyryE6tMxDCGYuM5DY0hFHT0X8q9vqce2ynPTupipoR twvlwZAfERSrHBfZ4dq8H1yzsRbd231oPJTLkCkbtWnXFZYCExb9A/qLRePmTY7k Hxj7AA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sn5bth7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 +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 48P10Fci006058 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 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; Tue, 24 Sep 2024 18:00:15 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 14/32] ASoC: Add SOC USB APIs for adding an USB backend Date: Tue, 24 Sep 2024 17:59:42 -0700 Message-ID: <20240925010000.2231406-15-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: c161W1y7tA3q2UVGOsd_hBAChV_MLUyD X-Proofpoint-GUID: c161W1y7tA3q2UVGOsd_hBAChV_MLUyD 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 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 a52afb423b46..c993705c8ac2 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 fd61847dd1eb..adf9d9203778 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 Fri Nov 29 02:40:12 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 726ED13D2BE; Wed, 25 Sep 2024 01:01:36 +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=1727226098; cv=none; b=MhWFzK1wFK7R7Oz2rEpyEtjHXBWY0A1u7K+oj5b6CctWbFvgRys08Eo4Hb4JQOGMq6TOp0YnLkdTIjFgJZOMiZXwYrZZ8es0pIFEhv+vId+X1V755fcY/eopIL8JdxizpFh7L9b8YlR8ElpNHlB2Sp9yREJuvb+WrlZ+m5RfodQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226098; c=relaxed/simple; bh=FiFxYrrPO0f4AZFgLNMhwElfx+Sn2apeIdL47dNx34U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lff0XWZl/6qycioccH7xQlptUyhkHrkn4Yq+FuloCf8FzjaiWmjUiWr0vUzIWBeYS/EHZhRC3iNGiUGJMc2QrOTe7s/4/SRQVZ7rSgC38COmlFzR6vQetwFQb3FgkudsERTA4KhHcR5PB6rKJBJvABAZS1Cn+FPw/Rlcw+4LVFA= 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=oZuIcSlh; 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="oZuIcSlh" 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 48OIu8jg017406; Wed, 25 Sep 2024 01:00:17 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=oZuIcSlh1/WhBoPP uAg1UspW9aNTo3XAGHTmDsTMYIMUY54y/WV/N2rShB5QpeLGGpGeIyonNUrU+s21 3tjJb7OstT9cumANOrZGvme/BTmKd8E+A6WF8f0zHCvqv06aGGRrnvP81BQdz8hh tH/1+49tdUA/4ZQqLRtDfjxPxp+hsF57cw7DTlLnre8PDYZ4nhP7yiLtXQe3TZmZ Zmh/L6v+4ZFQxfn+Mn9JrND9JhjRNm2yns2fMEVwmbh/aF7tBoy3wB8/8c5DKrGn nIADIGyx7re2WY4GeX/ZxeKWZJLD6xP+JkZ3ZSC7ApZ9MvmBmOVIxzSJzaGyzLXG uaqrGQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 +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 48P10FNo018708 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 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; Tue, 24 Sep 2024 18:00:15 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 15/32] ASoC: usb: Add PCM format check API for USB backend Date: Tue, 24 Sep 2024 17:59:43 -0700 Message-ID: <20240925010000.2231406-16-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 01-jXZOSumiOCafC9NK7H35QF2rxJWH_ X-Proofpoint-ORIG-GUID: 01-jXZOSumiOCafC9NK7H35QF2rxJWH_ 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 Fri Nov 29 02:40:12 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 620B214E2CD; Wed, 25 Sep 2024 01:01:12 +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=1727226075; cv=none; b=UJLDI59nxqbvpZERIPgB8xmxec2dcx9ZYibd7XP3At3+BuBmj12TA80ltvNcVG+6Upsnc4QpRmdhUZnzKVtVphGTv4TutKBgGeJwG7HBsWQFcePS+j0JdXziI5BP0Q8COprrg1vq9fuLb8o5B4sQmExQdyrrGaG10te2XIxeCic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226075; c=relaxed/simple; bh=KkJPrjb89GjsC+B6aGTE1VpTFDd0xKugVUcgdTkSPcI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GrLoYRl95FDWqBfkcbXnM24oweoQnMS4J41uPSWZDvbBY3HRHDcBRGWa4UxiHAFJ0cGYpi3olXu1SPniGp8F/NqJ0YAGU+qeFu1OTk2+PiNuEfRwru1Pchju7QhcwBzpjQPsCkrUdmQTx5PmVKLVuG7xlRxh5IYNjIyHIH4la5Q= 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=UCpEFxzu; 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="UCpEFxzu" 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 48OIGNtG008564; Wed, 25 Sep 2024 01:00:19 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= O14pxIL46DF1R9aYGy4vKxRGQeKH96fchuMWczG6Ngw=; b=UCpEFxzumzYr9c2g ys+BbsdFB93DUtfHGfqx3o/VxzO+ygv/2tfOWYXcQEncH1kEHG5ZTa81m7JCBFiK P3D1gj6JVIvER1breXi0xj0sx+6IpTVTnfY/XOdUgS0SFvejTuVJ2DY5xsQXuUei OkuHJcker/36hMPyxJxIjtGZo+L3fTmihFIllWTxgT+x5FjDPX5hk3ilrPIHkYdS 02zAhCo2wXAGir69o8PNLtL1DcENwEXnpsUvTyUQy2EjVrWaYbArYe7tojUIf/7B J0YIyCYqszvR9OuIxKw2IdSoFdcJqwo30erPMIIgnNi4GOBS5PuboORFrFkh4Ii7 ltHa8g== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 +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 48P10FYo010610 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:15 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; Tue, 24 Sep 2024 18:00:15 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 16/32] ASoC: usb: Create SOC USB SND jack kcontrol Date: Tue, 24 Sep 2024 17:59:44 -0700 Message-ID: <20240925010000.2231406-17-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: FTCdENQoLg9DZ9o2GHSqgjoRSUAcMPVI X-Proofpoint-ORIG-GUID: FTCdENQoLg9DZ9o2GHSqgjoRSUAcMPVI 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 clxscore=1015 bulkscore=0 mlxlogscore=954 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 | 15 ++++++++++ sound/soc/soc-usb.c | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index db9ff0b4191d..b32af08030ae 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -56,6 +56,10 @@ 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); + 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 +90,17 @@ 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 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..70d8f854c017 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,65 @@ 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_find_priv_data() - Retrieve private data stored * @usbdev: device reference From nobody Fri Nov 29 02:40:12 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 9592914831D; Wed, 25 Sep 2024 01:01:00 +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=1727226062; cv=none; b=puscylq2PfSLgc7chDdDz9jsb/unhyy1/Hy5Wj8Qydh7wg6hS10w83No16uiDgCIooPeFv0BnrB0H+yNexBh+isjqd46EWXfR2m/M1eqQjwyrrWjifSvZIGSC/Rb9dNDWiK05s2q6fG34KFyjHuvfd2vZF/yFquViduDnhCyDic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226062; c=relaxed/simple; bh=t7n8rhO3AEi7st/FJuPVX9s4BxgP3J6zupir+2XpTCw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hIr9IPrbt9Ufrj7TEaJr84hJhMKvwqB5mHGuL5i+AjYE4I/yd19mS89k5XWrT0TfgO8KPrjE/698w+w0HMFwtu02b781bAwQessCbqvwa47NKuwLGfudR2idr7lEHqu9HQPX66zeTTYp6ZyVcOKpfSfVVmiBRDvYOaGk4VkHHTo= 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=JQMwdqds; 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="JQMwdqds" 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 48OHxiW5021675; Wed, 25 Sep 2024 01:00:17 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= swybFnIRHPLzluHHFQvvDyLicOhSUsPc7nkVL7emCFI=; b=JQMwdqdsWn2qa3xB DlByFIF/YoXSDzHTzLCqjOW76Gwbl+PJMgl5V1+oeDJH1uFLAE2c1njYnvh5V/oG 7XM8eqo0Ex6zj7jgULly/4o0ZDH1mdKDYrcBa8UzivmYql0RQpVXvpAIm0VVQwfC 46+Hy9vG1FVNbISnkCt/oOxZWQNXpAhu98YqsTIICZtX3edI1r3GyEx+J4JDaYtf 0/5V46usx6odKOoiJduoMDkgxJYRFJSUnLr1QseHUL6+6RCNs16gZ3kZ2AysumcQ M9xINsmHTW5lshZmrEwnq5JlX2visuWFIWLx6NS0aSt/FKuetW+XiqqCPpnk/gbq mgCIQA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 +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 48P10GL0018717 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 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; Tue, 24 Sep 2024 18:00:15 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 17/32] ASoC: usb: Fetch ASoC card and pcm device information Date: Tue, 24 Sep 2024 17:59:45 -0700 Message-ID: <20240925010000.2231406-18-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: LL17U9lwXDXeRxCQibF7T9wAosqz_x4x X-Proofpoint-ORIG-GUID: LL17U9lwXDXeRxCQibF7T9wAosqz_x4x 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 b32af08030ae..4c6af57291d8 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 @@ -59,6 +67,8 @@ void *snd_soc_usb_find_priv_data(struct device *usbdev); 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_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); @@ -101,6 +111,12 @@ static inline int snd_soc_usb_disable_offload_jack(str= uct snd_soc_component *com 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 70d8f854c017..f88ccf90df32 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -118,6 +118,40 @@ int snd_soc_usb_disable_offload_jack(struct snd_soc_co= mponent *component) } EXPORT_SYMBOL_GPL(snd_soc_usb_disable_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; + + 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 Fri Nov 29 02:40:12 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 4AA91158D87; Wed, 25 Sep 2024 01:01:28 +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=1727226090; cv=none; b=J+q9Cqzw/ekW1U4e8lOWekpUrbpyvM+pYIHaP9+jw1nsDRozEZKTqnPVeGohJgPmT1x7cDKsRdbwY3WwZ0QRjgNuh1XXCr1+rfICPgZLDY7WYhMxvFYTwe8DEs+z08cTFDD6JzIctBfYJzQ1hMe+82xniFXp0oCRH/gCsh1mzkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226090; c=relaxed/simple; bh=qhSG1yc0cArmgfOxInQybGwni3Bn7OGU6vr+0g+ZhYI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uF9xdqxgtNBYyQ/vSy0PXG2167YbH4wYgpS7oEXek+XmY8UcS8AfbXbPFqNwzTAH10rM3/LTUFPIokAAWl/2uH4f9528dIYigrRmNAEpfytIzf2H5KHnwb0P2QrBeSvdsKYymyJBGf0DpsBtojA5C/LvFFmqVUqZqp816cgIFg8= 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=Wl+OHisc; 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="Wl+OHisc" 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 48OImtcD011805; Wed, 25 Sep 2024 01:00:18 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= vaEa0aoL5t+ekz32511tP+VOfYAQXHEglFh39CPp88c=; b=Wl+OHiscX8Jeas7Z yhE7FA68RaLdmRDsP74MkpA02I012x8UO3XSdoW91c0UBg2ceqSPxdFe7x9R8JQK o667ezXm/WuakWumr2Lj5jUt5DTXVVmhnr1LPxLOL/IhlQgamFlX+gYuBQkjXl0W 4AIuITxKIOB2tOQrIMarBf06L1ep84Jhy3AEGjhdqUl89FGAMKCHN8jyyn5HrKUg fLUuTcF8b39cpMycqNenNsjA4SshpFnLPiN1lrvknaJrAt1I4yjJGIiUKLCcqf6Z 7Yc8lkZSk/kVCxop2LNetuzpsHP/jBLSG0idp+fuxZXoi4xkONcYV/xBkKqODoDJ H0oE/A== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41skgnaufa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 +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 48P10G3U032462 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 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; Tue, 24 Sep 2024 18:00:16 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 18/32] ASoC: doc: Add documentation for SOC USB Date: Tue, 24 Sep 2024 17:59:46 -0700 Message-ID: <20240925010000.2231406-19-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: siRUgAMVdeKtd7gVeHMppmJ_Gvk60tbw X-Proofpoint-GUID: siRUgAMVdeKtd7gVeHMppmJ_Gvk60tbw 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 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 | 456 ++++++++++++++++++++++++++++++ 2 files changed, 457 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..b799abd9f133 --- /dev/null +++ b/Documentation/sound/soc/usb.rst @@ -0,0 +1,456 @@ +=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. + +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_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 + + **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. + +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 +can be added to the pre existing list of kcontrols identified by the USB s= ound +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 Fri Nov 29 02:40:12 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 87BDA18C33D; Wed, 25 Sep 2024 01:01:45 +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=1727226107; cv=none; b=Xly5M4ATjoAq8pVPDmify1YRzcRcN4OMawRqMK3DVamfcdgdq2B8vVhhLZloGsUx2oMAzTfrT9e3ruD8TRnPlMX8GCK2CgT5nq5SSsutRs/7bSZ9bBdID9jx1hI4FrRCPRIEo8dlW0dda5zYDwVVmnZtr5ilDc/WS8KFT1p2Uos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226107; c=relaxed/simple; bh=2TQXo2YMYhg/mBJxKuqafaOEZef1g+SCKODQN1pqdkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DgzRwJ0vRAO68/+pOvbyR55DdeeTth+bHTA7lQe0HF5feZ83LDqIJPijdNJZZeySSKmKcmpRVJmgVLmYP3sDFWOlsw6IAArQczu8rTFQ1l5KrsiI8HSjD3OqDzsrlVpGLiMPKnmfezp9zQhyr8UGtVgfwxeg7/Wl8BTYgB/o3Rk= 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=fkLwtl6g; 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="fkLwtl6g" 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 48OIJGAi001625; Wed, 25 Sep 2024 01:00:18 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=fkLwtl6gY5/YQxvf nrWlsv45JZc1oLneg5CUkv/sV56JAFshur2PUz1m3CB+0G5Q0YiqU/inRSziM5oL yPVnUvjXuHnaaymPdk7ERv0MiG7HBeuQza2O+ZI97dN1lTDRZAOVTmEg+xe18aIU ddG+zVwob3Q/4bfIb/ovwDOy2OpFEmYCBjSuxwl0M3qMb1UR0iA9lA+ubUOv/mMt Ij2lw9+0KGjCRvaueVqNrNaBBd6cUz2arOxo0VWHF96TxBH69NHcynEjWAJk1Q9i VbaJcspv0QqtKMxQEiYYa6eQRlqSHAuuecqa1IuS8EpeJYzx1soe9M+Exif1HR0j bxdubg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 +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 48P10GjG006085 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:16 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; Tue, 24 Sep 2024 18:00:16 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng , Krzysztof Kozlowski Subject: [PATCH v28 19/32] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Date: Tue, 24 Sep 2024 17:59:47 -0700 Message-ID: <20240925010000.2231406-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: NaSzemWAq_pAxCITxHtsrN0BkFMCB6MA X-Proofpoint-ORIG-GUID: NaSzemWAq_pAxCITxHtsrN0BkFMCB6MA 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=966 spamscore=0 lowpriorityscore=0 clxscore=1011 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 Fri Nov 29 02:40:12 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 2223D13D52C; Wed, 25 Sep 2024 01:00:57 +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=1727226058; cv=none; b=nM14OmxZzSBfUW6bs5yu1sHthlyjw0tPoqaV3Ip9dLpYT1rdIJN3q6NBIBhTEgyJD9E3Pz1Wj1rSA523Lk8Nnh0tWjJM4cSfLV9GGpWHvjJBhjkU72O6z58pCjcwCenURQh/q/eRMFupTxsy41EQ7dUN3FJjOEBS6BceaDUYvt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226058; c=relaxed/simple; bh=izD+DbozS8oGydYFz+5Vb7dIzvHhxa3xSOkF47CTxH8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=liIB6rgNFfmIeK9xOFOVuCLIZQlYnMO2sxhCUf4Kug49gQNqxQmjl/dwAfVTf7Z+n97C8l/ByWHdzOerWE+74/a40RiBlBaxXvkIUr5TkrsGaSXKUSmJbocbEDSTryjnjUKtjbkRaiE1FDc2inXtuvu7NROpgaTp4htiVg/QuYc= 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=US0ZtrlO; 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="US0ZtrlO" 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 48OI1RDc010270; Wed, 25 Sep 2024 01:00:18 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= DYLWwo/G+1Jgv2CP4pXZ8GM4oRunCFe5DUVQ7F3XSlY=; b=US0ZtrlORMVDTqwd OesL5I5H9W0bnoPiiCUZrnPVJ2Jsql2bBu49tV2lczaVKIWDNfTU/UM1+iI6rnJd d+wjNJJiKJDb8uUnN9xJBD7K56UhwDfyKEi/Jq6Q46jgK9j20RCXB3WRX+ibbhYd 1t9JsqJym8Ks1G8b1tF6AoRGDtN6z+EKngA+RsZ8rlBE0jLq/bboW6m3yzn0QRfR Fl+/xpvYz6txLLX7WBk6ut4aDClXi2npg+zAtzj4WnpqluGZkP/sXpZ51duY/1+K iprE7D6C9SrbhDyd6+SEhvtw32EXbOOnJ/K/u2x9jjr51S23x31nkO8HxTW+Gwuu pdlDAw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj87-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 +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 48P10HHY006088 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 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; Tue, 24 Sep 2024 18:00:16 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 20/32] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Date: Tue, 24 Sep 2024 17:59:48 -0700 Message-ID: <20240925010000.2231406-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: A-tJ9SyNvB5aT27m_zBl5-_b9T79bCBC X-Proofpoint-ORIG-GUID: A-tJ9SyNvB5aT27m_zBl5-_b9T79bCBC 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 b2e15ebbd1bc..f2d708f899bf 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -229,6 +229,21 @@ 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>; + }; + }; }; =20 - | From nobody Fri Nov 29 02:40:12 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 761EC18CBF9; Wed, 25 Sep 2024 01:01:48 +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=1727226110; cv=none; b=gmsoN2QaS3kLFBISS40iVp9GA++pPr6RpgGKcWmuLH9n4eU1ckKH4eU9YKj/V9VoJVBUuh/852StT574UOWQcnaBgCVLe98KtN8k4rFhEQhPOFGbNT99jd4BWzkcJT5A7PeR3+IPcrfm/MByiXaZQOt4EtEVnJiJAu/pMfbgp9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226110; c=relaxed/simple; bh=2gbNPR4HT3KCNH1iLPbrMhv7sa3KS/QWcCgtrWs29n8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IsYjHXcat6LMTIu7XWC84BodgiLnIJLFsFpOYsqXReoqRHC50449B1FtuqLvz9CZf4DSf6UgcmMZ0vrdLXpRZIFy3d5s9JXvDQD/vSKpALkjUx63Vf88XpBUEffWBfNNxVuT/MOASZ5TubJUblMQjxnRBLDGAUB6aTrOO12hFCU= 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=BloQW9op; 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="BloQW9op" 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 48OHorm2019201; Wed, 25 Sep 2024 01:00:19 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= 3kRWtzKHzpDZGUM6HIQWwxuhzWWJZQpy6vSz2bZhVR0=; b=BloQW9opE/2dSy24 UxrMkKkTlOR3b5kD5qXDvwlkDqEC0RHZ3fBdYjrL1L82ME/rzZyFU1ADMMiD+EPN CbePuseAA9Nx9Kuixvs/TaSI4k10cpqJYwuplMcfeLQiU6YplMe0NtErh5b+sPvO ggQ0xxBCth/hGmmCQeZD8MK8jq4Z5vuMV4adFuhSRteIKMbrgupJR0Xw23LHrgHi sxrpUCtiit/0CppZkJxns0+41E36IXVgw4gDt0Xh7DQ4WqXecEUCQE/71ey/KwjV /BoHYm/NIsGDRvVA2OnPlJZ9qOlZ9CgIL3pZi5XvGMqKVKfCF3K/6FtuEj+VDm87 pihDew== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sn5bth7x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 +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 48P10HMk022056 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 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; Tue, 24 Sep 2024 18:00:17 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 21/32] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Date: Tue, 24 Sep 2024 17:59:49 -0700 Message-ID: <20240925010000.2231406-22-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 8SnATzncVYNWz59ayCa0wWiEu-XksqNS X-Proofpoint-GUID: 8SnATzncVYNWz59ayCa0wWiEu-XksqNS 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 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 a9c4f896a7df..b368e781a0a1 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) @@ -392,6 +425,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; } @@ -618,6 +655,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) @@ -645,6 +685,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, @@ -943,6 +1000,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 { @@ -1057,6 +1116,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 81fde0681f95..d55588f249ad 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 Fri Nov 29 02:40:12 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 0E6A733FD; Wed, 25 Sep 2024 01:00: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=1727226054; cv=none; b=mm56ncC4+jg14FEafw9Qsi3HGxo8cG3zoU3uScDKFfbI6BfXU3sPXzbAxUXK8CQQoPKcuS3TZXoaNkC5PVxOiTZDGx3Q8nldi/x4y3fjys/QnW0aorUn9Au+VjGake0TD++IIPhGh4mi4GYLPzYfuUvCxRBhAbr8BNLRaeZtCwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226054; c=relaxed/simple; bh=lH6pajAyODmY/7seq1vw42FSufEXp3D1uilBoZTCkh8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mkXeM387mBo04smnwkVy4X8JQSswxK8vgMtPRv6DCL4/XW5Mc7kfhH4h3ZiSujZh4jWc3MX/r0gAmK6A3tXIngeaClaFcsk+1fogqN6yuJp4K7LAVSd4y52EASdOWyyhtF4UOWYUi86lnlM07ptpAVsyrNRadvomyJRtV4wV9/I= 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=f8aqlQYg; 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="f8aqlQYg" 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 48OHGdCd013420; Wed, 25 Sep 2024 01:00:19 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=f8aqlQYg6mWMtb5o 4F89PsYyab0tqFRm8QUd8S/yHkaaZqu5IICJoJ7ekLStu5ym1tSxTUJPoDVzuAgg PTpXjEgazS3TT/A8BYG04+gmlNgAOqi+oyzBy/wbbVKaGjYJFGglt9QqPhzriyjQ ym6M3MbtBNbEb5Lzf9GUKzyiyMaVkPyhYkAJwMCSGDySh45ntsZjOm6tgTRaQ+f5 Yr+bobZAW5GF1+SY7shw91gnp6RBy6kzw2lHPJO3z5PLUT9Zpl1CvElj40MhzeAp paG61FnEvG8YkhV8tZRjUAKzzwAvxdXh6xV6OrYuY1iDq/0ZInmbiMta+FXdcwY3 qzdV6w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41skgnauff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 +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 48P10HMd006095 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 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; Tue, 24 Sep 2024 18:00:17 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 22/32] ASoC: qcom: qdsp6: q6afe: Increase APR timeout Date: Tue, 24 Sep 2024 17:59:50 -0700 Message-ID: <20240925010000.2231406-23-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: r70W8xh-zXtpy_L9zylUADL9h4E0w2jc X-Proofpoint-GUID: r70W8xh-zXtpy_L9zylUADL9h4E0w2jc 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 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 Fri Nov 29 02:40:12 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 1094B18C03F; Wed, 25 Sep 2024 01:01:43 +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=1727226105; cv=none; b=okf1Vl9KwPeHnL4eBNMVZMWLohotonycks+NnK/jSEmjypkx5MIRFUkc2nT96jc0b8u7F/xjS1EqhE1k/eUe+iFCOtBJ26y6t4xS8UHlj9jKBoz6weyImkflgXZYHKD4U0gFGxgLCe9wkQ2n45wqT43qXufwPQXLzoIN8iR+eJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226105; c=relaxed/simple; bh=4fgBKxtPRpDiHtCjcjtA+uBufM2OdVE/YSR6AUVarCM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LRiY7vGe+6p1J8O0f0OGW/pRkrIWNXZjBZoiowHjuGABmWb0W9tc4bMChSI8YBPXxl061bL3HN0sH646/gcVy50DKCwhp3l3AFQebDQw7Gvu3aUZLPgi6S6ZfOfUB0Go9v3OU5QAZTLz8od+0fwdiXgZpVohnrGCjQ0i1HFLYvc= 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=iwVaoGvs; 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="iwVaoGvs" 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 48OKBH0u001757; Wed, 25 Sep 2024 01:00:19 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= t3S/a23F2/gUNPP5kv7berwz+e6A9EkuP6r3IZeyhew=; b=iwVaoGvs07cDaZdU mJQu122XFMhLj6V+ixYFNVNeYtwD0Q6Ln2w9sHTfIz/a+SL41eFhfNoYJ4ErQs2u mabOjkufVU0bSx8IecG/fQqyVO8BAybNsDgIcK4ZQDlisBvyRI/Pjs8HSvTPMIWs dq47H75swJbmCLUWba0zmXGbKKP5pLb8lryeBMgKpi5YW8HQE6irWkbaLGVt0GTW evx+nVZRWXPQvOq0GHHBZICiZJzXUT7j50sCehyhvOxNlU3BAxRN8DwaLDkVGVcC hWkxDK9fHARTK2uVPGWg82vflp9rI4g5lgLrW14QwT36qNHyyXmCWPRnqwnCxpTH XpOzsA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 +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 48P10HNu022063 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:17 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; Tue, 24 Sep 2024 18:00:17 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 23/32] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Tue, 24 Sep 2024 17:59:51 -0700 Message-ID: <20240925010000.2231406-24-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: KGsk77NUIP1RCUifd8rqxmieV4zZ2ay7 X-Proofpoint-ORIG-GUID: KGsk77NUIP1RCUifd8rqxmieV4zZ2ay7 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 762491d6f2f2..a1beafe2b1dd 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 Fri Nov 29 02:40:12 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 F28531553AF; Wed, 25 Sep 2024 01:01:19 +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=1727226081; cv=none; b=Eq0dLb82egT0LnT9pzEF8SYzKZ9t/ic2U9UmFZM2RirlWvRl4dC1+h/qDc6mYHxkOeHsvxW/aZhZMxmwfdemOGGqFSGfTvG8Nx9/0B8b3mU/FWfB8vdoCdAnGDB2D38BvauxEHCLzLE/C7vXP4a4UX6I0c7OoHsvOLi4b1YwQXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226081; c=relaxed/simple; bh=pDZj61XHmxpcym5qGpT50frQ3N7NEovWTQ3bYPTfvmM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fjCMXHNwwooJLs9x/Cmjj6iEMs2tMsBTQl/w3xwW4xao8dMtHvHricgUo9caiItPTULfXS3yrlU9wY1Lm15uPg2+j2qPeEORlZHW3LkfOxNssP1dzLCO7qFaBo3s4sn8/K/Tu9WVq4ky4zKM+85GXgOI/2CWR27P1aQTgzV220o= 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=IueEZYaY; 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="IueEZYaY" 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 48OIUUMZ024753; Wed, 25 Sep 2024 01:00:19 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= fuZPsaddyW6yHvT0MTao1LxzsVbOB3eL0duRS6UC/Ds=; b=IueEZYaYSGwnYTzn DxT7U5M6Kvsyreedk9Y4SvqKTcsPgWjYQivX9lPGDD8oHl4EifuWwDmErACvWPXF 2CNF+4xKojTzKvE6+x8u86JJr1TD/rRuBYw9v5bXfoT2yuDrfshrjG5673+7vgOE P3ouNMQUo+A8l8/ylMknwLQJle0lv/jcKI13J/32nA3MNyfiMbPojq97LqATOWCq BMr6/eNHX59rqYZNgmVI0khBB/B9NPX69faFX/8DDBp0IVBBiGhT189PT8bEzRMm 60Wzz/lEf6Of4LtolSD6mX7WLX+TT02tmFBJ24DViYU9LyjPQ1qZaI9nFxwAJzI7 MO9e8A== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41skgnaufj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 +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 48P10IsM022069 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 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; Tue, 24 Sep 2024 18:00:18 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 24/32] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Date: Tue, 24 Sep 2024 17:59:52 -0700 Message-ID: <20240925010000.2231406-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 58mpAOrLGoe6dYbXxRJx3ItgNlFbuCwi X-Proofpoint-GUID: 58mpAOrLGoe6dYbXxRJx3ItgNlFbuCwi 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 bulkscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 a1beafe2b1dd..e5284a93cf9a 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 a15dafb99b33..a32db222d937 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, @@ -129,6 +150,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 Fri Nov 29 02:40:12 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 C826718C03A; Wed, 25 Sep 2024 01:01:43 +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=1727226105; cv=none; b=IgWQsg9CNooiC6rAw1nYUuJk8bcjrDBwLNrjZWdP6Qw4yV510c/7sUUG7wznUkYNif0WSsbH61IS8VFIOJUYc4Cbmw2U5O+BNnendRhqbId0rS3SLXhuUBXwTMxbKIrp+6SozPL4KvUQrTMRRPwkhJAJBO2EJarCDmHxYCTod9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226105; c=relaxed/simple; bh=ZXPbpHEzwKIgrv8Ky4uyBr9mDKAN3LmnyDxkuOBUr+s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bvUdA3jpY41LbXjC1UbD5MSs9/6MAoGnF6OmO9krQwmYEOUdhyQ3vvurpYNLjJtqJRhwUZ9OXn8uwR/r6zIDorsJjzSpeoSUQtlpUYTiIOZij3VrqPWcpKcOgjClsPZHQC+1cUqy5FMSfWPHEeXtucgKJAqlLMoVGAydQTR/MAU= 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=Vr/BWohy; 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="Vr/BWohy" 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 48OGxCiW032075; Wed, 25 Sep 2024 01:00:20 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=Vr/BWohyBaMgz3Fd Vk+iL0lx3AMtEU58UeAqxx3a9jo2yvBuCywAvydPhv/mOI6cPQMTzAbttcUpaazG kLEiku9bV0awNTXcPwi8WLbuqdGAINNh2iZZc2nbEJma/TkH7MsO0bTFkTT5NgL6 3RV5rXBo81YZ4wnL3Z7yCwFYFw26rCII/t1+q67km9BFjwKkgrgoyAzxpG1AKgS9 mPxupTKh2vwnU6lsjidY/HZQl95gF2ax2SnaDBB527MbyhJ1QJscHmKWuku5xyn+ UskK2M0CoUh3i5bgKkyc7xYixDPOIrx1P/VrJnALy/nIAXJ2y/zdMV87g4oay0TR N2wlNw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snfh2kuw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 +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 48P10IjE006102 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 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; Tue, 24 Sep 2024 18:00:18 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 25/32] ASoC: qcom: qdsp6: Fetch USB offload mapped card and PCM device Date: Tue, 24 Sep 2024 17:59:53 -0700 Message-ID: <20240925010000.2231406-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: UNkx_vwT_hyGtRIpWR0nkaKtf6hJ64J0 X-Proofpoint-GUID: UNkx_vwT_hyGtRIpWR0nkaKtf6hJ64J0 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 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 Fri Nov 29 02:40:12 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 4CC5E1369BB; Wed, 25 Sep 2024 01:01:09 +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=1727226071; cv=none; b=YPDCecpnH0odu5uZkz/HPEZVENk7eG+kzi4W+DNAxx4125KEOCVttNvf0ET6Du+rtJCGjftKTEMQ+V1SvFYWMSXuL3j4fhCBoTCk8SnCyaVqcDjgFHyCsYtlSVGAAB/xocqbqxsuTBGueLtveVjHXf1W9cVnHdTr+k/gKyG41Mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226071; c=relaxed/simple; bh=6AqDjoRyqy6LqZrw6Wfm9KSKYephW441qNNZBK1XyFY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lPaiulpBTdZz3X2nxcKLs9tUm6U2SdyXBpwYdDoyPt/GnzjZ6322xBtR+fh9UIYtJ86j9EkTWftptvqfqsJ5ZOwYXuwPNWuVYJSiN+bHtHEUIQTIXYBCByJ/1pME+F8qxJrkUuyBPfe7Tw1gbEajRDjgPWYhjyeUkomYqTKxiaM= 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=RlyZlR4x; 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="RlyZlR4x" 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 48OINfxe032473; Wed, 25 Sep 2024 01:00:20 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= uab/+NaMfWEzUKyixsCiUSLJhDlynbFL9O2pQiQ0Y+Q=; b=RlyZlR4xqhgXqd5L 9w4ltQe96wQAyrQm8uoiRll7iECxxlgy+uQw7TerRU8jBDuGrBs2fEVr5WCh+ykz Wu0ocpOhvhe3JTsVlGixhD0PFtobHOgcfG5eRchMnLTlTvJeENkRsHENkHn6u74s 4eFvK+4QTqHL7MX6URp60ok99qlmz6/KW6yj84kGutaXp5cqiXtlK7GcanAW9IgB X3Kz/nI340NiS6loDROtNE1OZURrLioXc8G6ZzjoePVJcfUg50O4UU9GEWaVDoIX T3zj9Pc+3I4ndg49b8rHGBJg8mhzM9htWxxtFFQRA+zmU/BKJHI5uTEuHBr72pew pi05EA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41sp7ujj8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 +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 48P10Iwo018950 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:18 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; Tue, 24 Sep 2024 18:00:18 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 26/32] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Tue, 24 Sep 2024 17:59:54 -0700 Message-ID: <20240925010000.2231406-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: zA2Fm7WUfoEnn8up6qOP7el2weXVceST X-Proofpoint-ORIG-GUID: zA2Fm7WUfoEnn8up6qOP7el2weXVceST 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 clxscore=1015 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 1f9dfcd8f336..326292f37841 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 @@ -946,7 +982,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: @@ -983,6 +1023,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; @@ -1130,6 +1173,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 @@ -1170,6 +1216,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 Fri Nov 29 02:40:12 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 BB295158DC4; Wed, 25 Sep 2024 01:01:28 +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=1727226091; cv=none; b=XviezDh4nR9NZlOavpVa4gt3Kk+ZUN9iOMjPtxMY/AW4fY8KOFuxkGBrt/27tOOtx8jVmzloO5Woscx9/FMqleHCjASmy9gIwalWU2g7+lTJY1jLJiBZZ9BlJDqfzEvB0CLdO3xUsh7i5wbDl9LMjNKLxZ56vxrMXDh7XHqjJp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226091; c=relaxed/simple; bh=9cdnbJPdjIkgUwVVDViOSctU4pwRwxYTjPMbwEvbRI8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=reug8ncDNjPbNFnndTUq4JEAUQI+K945oZCUW1IAD9Pel9PGcD10+PlMPiHMM0TugBFBmfiuN255YOZGUim8nXqz1maH0ptD4jMzRXHEN1z+4JPt+WSD2lwlTNgDVBvN+DLqN66lBORWUuChW5I1cU9uXqvxnbqGCS4IIg4m7Rs= 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=pYz3azGJ; 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="pYz3azGJ" 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 48OHs12v023783; Wed, 25 Sep 2024 01:00:20 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=pYz3azGJclGbHtDU vcI1gttT85jYGrnwLGTusPTHSsEVXu7Rtqd9d4QA/K3aakV6mtIPLcQfSMXV6qVq v3yj4pMG8Ph3aX4Uw/rSprcnFVigshYrY3XXuu4iagxU9Z9GpR4KsDPZ4UoV1C1k gS35XRy2fRJOVAX62MqVLfWjlo7z1oPUn8wYuDOosvzLag1zDYnqSe4UXy3GZe1b 6kwxUVO0v66qtLVx9jy/9wXv/K62I6BAqxsaBmENG6Mby70zLp41Me5Wz6ZX7TUf Y4ywtMLZ8imhiXLz4THTxy6fdJvgRrdODsgr8oidUYdAA/iVj2UODnyZVkOoD/Sj zWk9nQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:20 +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 48P10JFu032501 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 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; Tue, 24 Sep 2024 18:00:18 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 27/32] ALSA: usb-audio: qcom: Add USB QMI definitions Date: Tue, 24 Sep 2024 17:59:55 -0700 Message-ID: <20240925010000.2231406-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: Y94DL0b7oNOAwBJFvWdpL07KwYtIl9pn X-Proofpoint-ORIG-GUID: Y94DL0b7oNOAwBJFvWdpL07KwYtIl9pn 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 Fri Nov 29 02:40:12 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 57E2A13BAC3; Wed, 25 Sep 2024 01:01:18 +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=1727226082; cv=none; b=AnBIH320s5FQFd/OyZ9f3FzztGNSFa1b9htmth0xuxk+OHri3txGDAKPVUF98lsADTqdBsDYYFZytMSzBvVVC1/ZtQZrOjIrsXluVl0afI6pwGJMpPzd+N9qEEgUmJIHg+IOoKs50nLO9luzESoVng71CzLpgDQ4rSnfl513GUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226082; c=relaxed/simple; bh=aaxyCRw1AD1ff8sVrI+4ncHKxsls0eNZZADXQWxNF+0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=froADp/MF/lAJjYUPxSvIc80f/ZQMeK0KYWvjD8zwsSxNPP5BLjv9q1wJn/5efbprOc5RleiTb/nUxm+eme3W2KiTQ+8YWccrMYwfzV0Ku2XgiUMtkcSoTw5TrMhkyN2rPyO85f6QnkmGUvjh7+lD4ePnFbKmvR4DN17L7r4pk0= 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=BBY/82Nb; 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="BBY/82Nb" 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 48OHcjh6014609; Wed, 25 Sep 2024 01:00:21 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= IjexLbgTwBWjCfUumEPiufhDs3BE8h+iEIt5iTZ5I/c=; b=BBY/82NbtGbTeX2L rjTtUMTT9MXlwK/Tn6S5TLrBO0wqWiSjnaqinyN7zg8YE5OdPiqYEstX6okMNkG0 iAMu3FoJclVIewzSmbODfOYnmJPu7PMlnopQ5139qYdLWeH/QEJv//9bkm538We8 xKC5kxSjCmGtNh6n1pCs9xlci6ONfZxAJQLcz4wKAqk7IjM2VHg7fFvRFhOvfIF5 Ag+ZEUod3YZ2I9MFEWTKnUHcp65tne9tJRWdqJ/VQG5hT9BsYaJN2fQWtTg+Z/T4 BnufhfJkgL2gnpz6zAcD9r0jrhKuESjscfCOVx9ogDtjMVDtMRogjSNwBx5xi+cJ /FZZqg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snfh2kv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:20 +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 48P10J2s006118 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 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; Tue, 24 Sep 2024 18:00:19 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 28/32] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Date: Tue, 24 Sep 2024 17:59:56 -0700 Message-ID: <20240925010000.2231406-29-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: Z_t5PKKLmQFuwEmfqv5R30djJoUd1WGc X-Proofpoint-GUID: Z_t5PKKLmQFuwEmfqv5R30djJoUd1WGc 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 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 | 1951 +++++++++++++++++++++++++++++ 4 files changed, 1969 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..5cc3eaf53e6b 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_SIDEBAND && 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..4de4b8b3d2a2 --- /dev/null +++ b/sound/usb/qcom/qc_audio_offload.c @@ -0,0 +1,1951 @@ +// 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 sideband */ + struct xhci_sideband *sb; + + /* 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_sideband_remove_interrupter(uadev[dev->chip->card->number].sb); + } +} + +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_sideband_remove_endpoint(uadev[pcm_card_num].sb, ep); + + if (info->sync_ep_pipe) + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, 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 sideband 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_sideband_add_endpoint(uadev[card_num].sb, ep); + if (ret < 0) { + dev_err(&subs->dev->dev, + "failed to add data ep to sideband\n"); + ret =3D -ENODEV; + goto exit; + } + + sgt =3D xhci_sideband_get_endpoint_buffer(uadev[card_num].sb, 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_sideband_remove_endpoint(uadev[card_num].sb, 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_sideband_create_interrupter(uadev[card_num].sb, 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_sideband_get_event_buffer(uadev[card_num].sb); + 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_sideband_remove_interrupter(uadev[card_num].sb); +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_sideband_interrupter_id(uadev[card_num].sb= ); + + 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_sideband_remove_interrupter(uadev[card_num].sb); +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_sideband_remove_endpoint(uadev[card_num].sb, + 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_sideband_remove_endpoint(uadev[card_num].sb, + 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_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, 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_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, 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_sideband *sb; + + /* + * 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; + + sb =3D xhci_sideband_register(udev); + if (!sb) + goto free_sdev; + } else { + sb =3D uadev[chip->card->number].sb; + 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].sb =3D sb; + 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_sideband_unregister(sb); + uadev[chip->card->number].sb =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_sideband_unregister(dev->sb); + 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 Fri Nov 29 02:40:12 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 D83D115B966; Wed, 25 Sep 2024 01:01:30 +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=1727226094; cv=none; b=YEmaTJyyadNQjuFe3sUCyiFBZDy2v9lW+JowOAbx5ZNuvNiVyd4t3gb7IGQjU4MxkHefZtOiPv1h/wEGKqpMverSK+8dMClEkxX++RhHiCM6i1QGiNwtU46/paK8qqbiX6h8oRdNFCDd+kTsL2XVZq1xAbGAg+6vDeaUGItTENQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226094; c=relaxed/simple; bh=ILm9IsIeFzOmvfKayjiNI915PqE3+N7GH7Fx1QFLIM4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WfQPB09+DtbxRdjJP2/Cef8eHXWbzaCJRrlAV3TI8/A5nLK9Kur2mCqmr2y4nlEa0GWfHoIPVT3sFt6wkF/f66vg79bzAiX2AU7Fj4cFg4nGpEUlgYNHf0p+42qmMhhzT0l2BU8vxfwkDvhUSC83L+jF8aO0nkB3hMbtfDHc2UE= 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=mglUzFcM; 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="mglUzFcM" 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 48OHs12w023783; Wed, 25 Sep 2024 01:00:21 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= ps3pj1rWGaCrzwhX4NetRAi9YyPcgs/OhsJfcZt+G6I=; b=mglUzFcMHoI/bTIK DPR2+X0alxrwQW1r3lRbzCmxiCRkvJ2dFfkM0Av1vOlDebkFTIv6AfNDg03JY5O6 R296Ac/Zd/SsXPla5c5hZ3E7cTpvCGKw6oZ9BPP1LCDQXtgSlarQ0bGHJg/zv5sk ihRCBN8pHpICpWqkkhwsRTMnquK0th32eLBtgPuZY7XLWJiC0gWWaZ65rYmscWxy F8PadGh0P+6I31VwNo7XFlk5RI+5KHVR3tHNNmkMmTqFLyfSCtuNlKLJaG394u3o wfIs32aOj8WWCEjvQMCC/jwCCog1fKBG1rYqz9aD87qk8e0yFo333b4rZ7+oY1N6 un/4xw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:21 +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 48P10Jsj022091 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 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; Tue, 24 Sep 2024 18:00:19 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 29/32] ALSA: usb-audio: qcom: Don't allow USB offload path if PCM device is in use Date: Tue, 24 Sep 2024 17:59:57 -0700 Message-ID: <20240925010000.2231406-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: YyycNXyvLfhZJ8Ir4dTBt15aUrwaF1lO X-Proofpoint-ORIG-GUID: YyycNXyvLfhZJ8Ir4dTBt15aUrwaF1lO 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 4de4b8b3d2a2..a7ad15404fd1 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) { @@ -1529,6 +1539,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 Fri Nov 29 02:40:12 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 460C814EC5D; Wed, 25 Sep 2024 01:01:14 +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=1727226076; cv=none; b=DNiN9AB79FC9QHUGaX3Dp/79sHQLMjSScY6fKGZM2qf1WMd5IQJdqLjySEGDNUucdLP8pv1kF32dLm07CvfjL89T9vuyYOixMm6dMgUYb3qmPYbwlXU/yotnH8FFB0EF2PpUnZSmpo4nm8xReyB3T6a3zr2HzgqmPKA+w4JMYKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226076; c=relaxed/simple; bh=Y5/uxZlOWMk5KNNRmzXgFDLOWfc/MymPO5Jt8+HOqrU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kKkhD2y8PJsAnATcA+UkSFOzkixTdkjvvSgtYzIW0o/7Cv2cFmS0yBF2Wsrx3cG4OX4y5MQzOoqB1EI4uJocSuSGJuKK7nYwfZ0Fk32zUC66OyFtJnvl4nLMnY+QqxYyGNRQYMfYvON3LLO9C0p1xBbisn/jOn9HusTCf7a83KQ= 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=hr2Cm51s; 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="hr2Cm51s" 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 48OHI6YY002767; Wed, 25 Sep 2024 01:00:21 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= Zf07zDWjnx7aQXd5TW1MIzOkUgL2dLXZMLqynSgsPCA=; b=hr2Cm51sw+gNUh8/ 2dZ9Pnhpq17eUnHSn6roQTO/CSojV3wEabSEHW7Xq5Ei6FlrTBjbVsEm8nBDvczV tiw1HPZl7UMyLJCf+te4csA3CVDWN9r3A5JnYQW4Xi6JraGrEakd9CLMh7918sB1 Iy8PG1wYeovwImbzqUCvELNRrnNsZ+35NpgOCuPUnFHoFmIFAvtTlu5LW9VcFUMs uX6hpvGMLiN3pJwH1pCD+MelK+T670I+fmmjhoMtUcAgEy8fBaqK4tJPQmvjpwB9 O6DON1LzVa0IE3dzqKsv/iu84TdldAxk/fvSHJjRI7Jme3o57wNZDtA4wx3DVszL xVSXlA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snfh2kv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:21 +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 48P10Jkh010659 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:19 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; Tue, 24 Sep 2024 18:00:19 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 30/32] ALSA: usb-audio: Add USB offload route kcontrol Date: Tue, 24 Sep 2024 17:59:58 -0700 Message-ID: <20240925010000.2231406-31-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: POIKTast1mBRlG57RdK_Dn9YZd-SVM78 X-Proofpoint-GUID: POIKTast1mBRlG57RdK_Dn9YZd-SVM78 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 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250006 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 5cc3eaf53e6b..e3fbf9541d0b 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_SIDEBAND && 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..16e2fd634684 --- /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[37]; + int ret; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs =3D &as->substream[SNDRV_PCM_STREAM_PLAYBACK]; + if (!subs->ep_num) + 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 a7ad15404fd1..5b9262a116be 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 @@ -1703,6 +1704,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 Fri Nov 29 02:40:12 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 7AC39189918; Wed, 25 Sep 2024 01:01:37 +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=1727226099; cv=none; b=OmuasEb+m4eMG6REyczMlBeioMvlfjg42p1VBf1tNaB14kFZdJq9hyxO800Kol3yMcLi/S6ZSVUFCf7nMTdhlVoOROX8ICl+Am9j//e5V4sMBCUc+zhRMKEmgWI5mwnK2HFkY3/nEsVdVZhS0KrLbERlzvm/+ODBFuNepOWevSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226099; c=relaxed/simple; bh=Z2vXdqza1mKzaYCDwoc0E+XwQviWreyyPzXX84kItQs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V036/30LoUxoNRHmnATYYgb7vmwfiEcbnxhXGaZZlE3VXjetXG6otdvP2wuTZC97FnWImSwL6k3fRGSI2zA7zIpFPhyVauBZcf5Y1Z1whJ9nDN+X23A+ThQQIn39c6crDdOuUONZukDwmMHtZxRDDJ378qK6eO41SFVMCuLvfQk= 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=n4mHvkIW; 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="n4mHvkIW" 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 48OHcoN3020870; Wed, 25 Sep 2024 01:00:22 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= hhypoh1YkPhSPXaYJ78fwY0e2/AKkzkM+fGnN1dHQGY=; b=n4mHvkIWOtjliBrA QVxfjf59TJAEF7pcL/CsPc1yM0Q1QK950Pon/VsTeLEApkj4po9mN0gBvWH5RRlI k0hoTZFIC8x4d+4Z/H92EUPT5eUtKMjGb7Q1e2/8b4FpL8VX9xWYAigAiElDHmUt eCX9dYyXC/Km376ALJbNBCnVyVG+j0PoJhndXudIVmY1iZ/G/EEytTdyLqLIfkb0 /NGJ7Jv8Nin0iGAr/66DwRwd4iWEgKxzaDjV+YcirV3EybdMZ2cRqWg9aiy8tYQn pHKAWiEfGxVI7fmQkTdx/8yMjLB/0IJkUe0cWnZJsdS830lTkyoUNjMwEBUZlfcQ r9Jv3Q== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:21 +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 48P10KQa006126 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:20 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; Tue, 24 Sep 2024 18:00:19 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 31/32] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Tue, 24 Sep 2024 17:59:59 -0700 Message-ID: <20240925010000.2231406-32-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: FmMJpIeDU2j-bQ3sCw-mU1bYw5N2jWXa X-Proofpoint-ORIG-GUID: FmMJpIeDU2j-bQ3sCw-mU1bYw5N2jWXa 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 326292f37841..1f21d11416f9 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 5b9262a116be..2dc651cd3d05 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1929,6 +1929,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 Fri Nov 29 02:40:12 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 5DF56157469; Wed, 25 Sep 2024 01:01:23 +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=1727226084; cv=none; b=TkWadC7bC1vD5t2E825/3R924n6BKRsmjYCoKcR+e6bi/jJqFDxALEJmmS+IdWfZKnxTl7Ex31ogTSVWCfwDDYHihj67LJRFBy0NGKHIHLbynVd1BlnMdSS7BMlZd9OPRLu1Nw8k5lku7LmxTKEwojhcPCpr3zOCOk2nWXUpBVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727226084; c=relaxed/simple; bh=prnyaP8xdPvgf7lPSdgoOnTFSQEEfdLilloaJUXm1RE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kl5rjkOEDANeZGK0kS0a/pcoC4zsnFan+QyH7OjC7kHworObx8AEfPfHJzHwQPsPNY2RyUwsXJjh9+2NQpDHfhIpi5kOG6MPxdPK9zBhgzTe7J1EGpjU4Wx19Z3ohhxMzHh3nSr6ZyPO32gCyyExhUWheBYNIhK5DXdw3VX1w7A= 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=pjldD4f9; 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="pjldD4f9" 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 48OIJGAj001625; Wed, 25 Sep 2024 01:00:22 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= IHuzCQGYpXyTPH0RihFbQD623zcQRcB8CUdC3cqWdMA=; b=pjldD4f9IXUoQo+6 v0DhTrFEJMo29LhW+GBGrrCDkdYe00bE7NcqwI+9FiM4djrz0OYEDpDczfE8hVOS 3C4ivw4yDwn+gJEkjIdkLy9uf0kfmgkki+u+Q8lGxIs346X47HAtcOYfwHf6tlii nKkIuAjL9QutcCbd6MiS8pNOBegMxhWwd3107CTRhcnMeL7GXmsi1EwgCvzGSqFL pJODt2TPVDdE4uDtOhKtyhRE+WF1b/32DaW0U275vhBMnKZVfTvwlRmnMyJ4sPut MKHLvDF1hPGGlDdjZ7xTIhQeGkAoIoZft1FFbAoD6XVdMhTnvz8CtXkNMpsfYD/+ XpGafg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snqyjg40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:21 +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 48P10Kac022123 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Sep 2024 01:00:20 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; Tue, 24 Sep 2024 18:00:20 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 32/32] ASoC: usb: Rediscover USB SND devices on USB port add Date: Tue, 24 Sep 2024 18:00:00 -0700 Message-ID: <20240925010000.2231406-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925010000.2231406-1-quic_wcheng@quicinc.com> References: <20240925010000.2231406-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: vKi0Sn_XlvQ3aFwyj_s_nRXk2lodc4I0 X-Proofpoint-ORIG-GUID: vKi0Sn_XlvQ3aFwyj_s_nRXk2lodc4I0 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 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409250005 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 f88ccf90df32..3457bb51a0a1 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -252,6 +252,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);