From patchwork Tue Feb 13 00:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268776dyb; Mon, 12 Feb 2024 17:28:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUogRlZt+fsZKA6npJU6ykNMIh/fDzAiSHr7OWY+L+czF+xFB1mcDJgmUZIOhsKEYtVODCOh20BZMnYgyc1wXTqZVZ1VA== X-Google-Smtp-Source: AGHT+IFoK8i/hRQfNQpECgu+9EH4xbG2auAcKlXCYyxWnKN24py/Ol6eGy15Wmox8qZQzAOUf+jK X-Received: by 2002:a05:620a:21c4:b0:783:63bc:3eb9 with SMTP id h4-20020a05620a21c400b0078363bc3eb9mr9605617qka.20.1707787712863; Mon, 12 Feb 2024 17:28:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787712; cv=pass; d=google.com; s=arc-20160816; b=HgZE/p8WWPbrCofe2xq/Cce3NH9oXH+K3dSJRshDROODfRJaWsUKi1dSrhcd+HK5hg 6VzEnUnmfZMY1laJ6OjKqmLBUzi69uZf6fNvg07rIRV/OBx7b7ZjXE+fR7XOUDu0RQy4 uB3FYFghLRWJERfKO9yrZxWnKqImjOTmTX2VQsfQDNdE9xM5o4I6TL/EZlFx7HpBaZOE SMt7je24fUpw/fNxaxFCd6Akv5Isfb/huw/Y1qeRl2E32ZU++1qaQ9ENPcdrJlVtcF6X uB/5aZGpjoP7d1ppVPvO45he+wLjx6Xi21Ita5ezGBaGf5Y8njMqZ88Y2o5ut8HoekPf XMRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CAxjiLONN0FsfVJGEMs1T7t8zj114/9U4ixQ4PoMPaY=; fh=umT4iWQ4Ub9xmWhd1TFyPCMDcTKJen/9mhgu00IY92g=; b=D7Y5YTfIttm/jLK2fUZE5R2CkQ13WePCIZM6JFVQktIPtJImYFWGMns5uofKNwXy/v hfd+G1+Jb8ADGnVpG+kqcAnWoPwJ8naNgmRozN+FRYeCVJvtlA63jvOm4MvTiwfI04M8 hMbym/SpLjpOZ+xKH3SsvICackzfmXKakfdiPo/N9SnK5qN+vUNj2xoy55wPIj+3ODzw XV1fnnWk1t/dkuEGZeI48rIvcgSqrRUOvPz11HlmwZ2W6c92ValbDiLAo0c+cKEv6HCv g5rZUvXLgg8/pKb5NbOI5CC2vRF0/ZMVn1CKahXy1Cb4eBorGM4dQHWxGm2wu9o5jWU0 C4TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=T7NZ8y+e; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62787-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62787-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUkYHpOhp43OOyo3ZaPzzNOq47xZFE8yrUq9A9lo6B3IVBbOzxmGZJcfLLMuhhy+iBVZb9w/AkR5sKcomM1zRLyTAz99w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g24-20020a05620a219800b00785d52d1bd0si3687122qka.785.2024.02.12.17.28.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62787-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=T7NZ8y+e; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62787-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62787-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 97CFD1C248B8 for ; Tue, 13 Feb 2024 01:28:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BAAD5F850; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="T7NZ8y+e" 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 9927F224EE; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=eGi2CdphXcjaAPdP68WaI8RtP2w2lgXopfzRLA3F7Qhg0al7d0qHVFa2ej3AUiFgFmRtp6YdPg9YPbe/T+6F3aWfANPxb4fvVuMGDqahdopUmBPlcPWA1VhEsnRFVgRXIaoHLTscPuFeFgm+3gPsVEs7f9JpaW4z2mFqRzwFDmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=+Lw1+4MAX2LtZpd2jn62R4vA+ALFex1PxyuYDKU/fN0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cr4vqFclcvu3PVp/KRz3JOJbx3FHpwUw9fytOfYdbbo3ci/rp095fsRM4E87I3aufSQc836T0Zd0qJuwdoLZZ9VY5daa+ikhOHSQ0zJyQLUx5NR6F0x5t22l4hubPSjfcuVfzzhN82/AT6uENBR+ShBOVgLG7t0dhudcZ9ZOBA4= 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=T7NZ8y+e; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0NBRo009799; Tue, 13 Feb 2024 00:54:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=CAxjiLONN0FsfVJGEMs1 T7t8zj114/9U4ixQ4PoMPaY=; b=T7NZ8y+e5oI8U/bskqs1KNlL7pdIOVCYCVLn QNpBbh308/HgouJjD5Hgiq9PkYx68NKX/81KXjneaazT84mJSYmzuS90g/PZkfKC eIRCgGXtWIi1d75UzZ59xfxJQGX4hp95TrhEmVZQvIAZ7ouv+sVpLMoIerUDLD4T FjRm7YSDz8ROm2QO+Upy3R6ofKL+FGVWmRBXfxKThgxp4W5zaY1HqLtVZUBbmgo2 j70k76jGBZCnw5Tagr1MTUwT75JcWgkOCEgMOeWX12OmsodGTj6ptDfCVKDRIBEY b0tkT2YHd2upkO/15SawIv18akJh0Ejqne66//UvdSdW4ZIwOg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4ty6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sX6M029942 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:32 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 01/50] xhci: Add interrupt pending autoclear flag to each interrupter Date: Mon, 12 Feb 2024 16:53:33 -0800 Message-ID: <20240213005422.3121-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: xYYz8C5f7TWID6_kRTK0hGUGGVnPikRk X-Proofpoint-ORIG-GUID: xYYz8C5f7TWID6_kRTK0hGUGGVnPikRk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=747 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745208906550586 X-GMAIL-MSGID: 1790745208906550586 From: Mathias Nyman Each interrupter has an interrupt pending (IP) bit that should be cleared in the interrupt handler. This is done automatically for systems using MSI/MSI-X interrupts. Secondary interrupters used by audio offload may not actually trigger MSI/MSI-X messages, so driver may need to clear the IP bit manually for these, even if the primary interrupter IP is cleared automatically. Add an ip_autoclear flag to each interrupter that driver can configure when requesting an interrupt for that xHC interrupter, and move the interrupt pending clearing code to its own helper function. Use this ip_autoclear flag instead of the current hcd->msi_enabled to check if IP flag is cleared by software. [Moved ip_autoclear into xhci and set based on msi_enabled -wcheng] Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 21 +++++++++++++++------ drivers/usb/host/xhci.c | 3 +++ drivers/usb/host/xhci.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 33806ae966f9..f8e78068c36f 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3013,6 +3013,19 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); } +/* Clear the interrupt pending bit for a specific interrupter. */ +static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, + struct xhci_interrupter *ir) +{ + if (!ir->ip_autoclear) { + u32 irq_pending; + + irq_pending = readl(&ir->ir_set->irq_pending); + irq_pending |= IMAN_IP; + writel(irq_pending, &ir->ir_set->irq_pending); + } +} + /* * xHCI spec says we can get an interrupt, and if the HC has an error condition, * we might get bad data out of the event ring. Section 4.10.2.7 has a list of @@ -3062,12 +3075,8 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) /* This is the handler of the primary interrupter */ ir = xhci->interrupters[0]; - if (!hcd->msi_enabled) { - u32 irq_pending; - irq_pending = readl(&ir->ir_set->irq_pending); - irq_pending |= IMAN_IP; - writel(irq_pending, &ir->ir_set->irq_pending); - } + + xhci_clear_interrupt_pending(xhci, ir); if (xhci->xhc_state & XHCI_STATE_DYING || xhci->xhc_state & XHCI_STATE_HALTED) { diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index c057c42c36f4..0886829d53e5 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -538,6 +538,9 @@ int xhci_run(struct usb_hcd *hcd) */ hcd->uses_new_polling = 1; + if (hcd->msi_enabled) + ir->ip_autoclear = true; + if (!usb_hcd_is_primary_hcd(hcd)) return xhci_run_finished(xhci); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index c6349e7e1e95..daee202cd369 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1431,6 +1431,7 @@ struct xhci_interrupter { struct xhci_erst erst; struct xhci_intr_reg __iomem *ir_set; unsigned int intr_num; + bool ip_autoclear; /* For interrupter registers save and restore over suspend/resume */ u32 s3_irq_pending; u32 s3_irq_control; From patchwork Tue Feb 13 00:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp277053dyb; Mon, 12 Feb 2024 17:54:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHf5gT1VNk1pzix/lRq2QMroLAWlCfsaRl+V73BDvErrRwe3T4o6Blw1Z1YlLgeX12Z0PTN X-Received: by 2002:a05:6a20:9e4e:b0:19e:367a:2ca9 with SMTP id mt14-20020a056a209e4e00b0019e367a2ca9mr11409739pzb.8.1707789279552; Mon, 12 Feb 2024 17:54:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789279; cv=pass; d=google.com; s=arc-20160816; b=hfD2NrBs8EpWypmI5eyn0YVkz7E/c8CSfTYJo+mVX26PWcrryP91/jeB60j0/9b1S5 c/y3jo25jgV6TUaJx3qaC8STDMEFaamL2j4Xx9WjXVS3Lw1Kfkays96X4T3YnQJ8K/nF luKHtXzW0+4FrPk8ffRHDDMzjr696JaMtpqhDZlxrEwU4+duq+7TW2vMYjUNyby9TGZO V/AcQm9TpSxmAxghuyO4XYvGrJ+oIKrpqcf8mbjt1RZFg34mFm7j1j0dNeAYWR48/Wq/ TMHzhnl7bgmXR9LQOJnZmbMwjeivjQK+ro11XfdWUoiXiTNz5o+HgtHzXy835Z4oo9yt kY1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cPeqWAOHiC/DRr2Pu2t5FImj3arw3vFei7pmew6OZTU=; fh=L5e2ULvIZaD524FhcpT0/RDh9V8JluyXzl2FSwsFj0Y=; b=Osc+P8Tk1iscgKqZw8RtFrICCTo3IrQOQkmEjK0xtVcYt8T6240CE+Rjbia8Yt5tCc W/HiCrGv+yzwjNaRqm9ey3ScabgOOrCpq+1JNmyIkd2EJVEevJSUjFQ+49j5TYzkaDUW PrDl0BIuDNjpA0yA7zijCJBxOIUEypH7I53ohfITFgDd/HfKnGSNlJgQxsFiuRpy7UI6 jr6CDemve/IGv1UjHeo7wmFSOkBk3ao+SvZZx7sqHM9s5UOzEXg2c5P2aAS6AAmQ96rK 7hwHtBzbMjNk5DXSraQP1Bo0pUNqLzI9EtmR/5XfYNKq8Ur4w4LRUTzbEUxvr00AVWly WoNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NppvrRQD; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62796-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62796-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW6xt0mnLZw6JHNFEJkWa5fgTeHZgdAJb60pQY/WIqzQBUlXc/mdSD89NUTH9wCDyvldbs54xOF2c0I+ab9OEzaakpqmw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jd4-20020a170903260400b001da31b60e3csi1105195plb.571.2024.02.12.17.54.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:54:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62796-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NppvrRQD; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62796-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62796-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0742FB285E1 for ; Tue, 13 Feb 2024 01:32:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CC1860DC2; Tue, 13 Feb 2024 00:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NppvrRQD" 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 A92E0224F9; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; cv=none; b=ovc6Gf1mv5drePp39QEvd8cjxDw2vUqGVWDd8sTygwGQiohDQZfzZy0EQbmYTvnSzpcTCO3VfCffARfgkKMJpcV+00CXVqQOvGO0zF0x6kYLAXZz7aqT6Qh+S+nM7QiRwCDpMTMSCh9WJhB1+BddTnEiUhrKXphnRwE+kPuVLXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=u1nuq17zD0xhgBZbYsuMjFfbINv/RaVLoPTPOjJ2BuQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YcDD4TbHIQ/rsSbkFy7rtYHnizd5LThe+2Ch4N1AHqxgfuzYqdL5tuQInVH9tYz4l2DRDCll9H6K45qiCsWpePqamWnfAKKTbhTJuOOU+y4SRFHTMlFPJBrcMDso1DwlkNWaDUgg/fsp9XvWRLzB3yg1yg2Hh30snD1Eepa2m0o= 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=NppvrRQD; 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 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0Yi9x014733; Tue, 13 Feb 2024 00:54:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=cPeqWAOHiC/DRr2Pu2t5 FImj3arw3vFei7pmew6OZTU=; b=NppvrRQD2phZJS7TY2FZRvpHWhFOc94LaI2N dWiD0h5zOebSlWBh80zbXHMgHnOcz5ao7xLaucTnWL5qL2vweyS2B0G/5gNWX7G7 toW+taGqNXXacgb81uGPN7zGG+LgYzcdA+hba+Ap7wEH1UyNYWsJPEyoQ9Bxmmap uFdnHTgzFqOomtmMiBCV/27D1ELQ+nz1NoUI268TV8GAmRKzrDTTgudBjE7FF5CL DLWIN6jSZQnU1i3hL+7ShVXOlvMzbdU315VidiohfM3U6rLibSuVpQhXJdkq3tYd DBHbsca7U3bhCCwB9fTcRVpPs950xLT9/aIbm2oUOS3aAyfjXg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ww5r1a4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sXDp031061 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 02/50] xhci: Add helper to set an interrupters interrupt moderation interval Date: Mon, 12 Feb 2024 16:53:34 -0800 Message-ID: <20240213005422.3121-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 18AqyCUdRgCwt8ip7-4XEaq9JR8JgQFp X-Proofpoint-ORIG-GUID: 18AqyCUdRgCwt8ip7-4XEaq9JR8JgQFp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746851779767655 X-GMAIL-MSGID: 1790746851779767655 From: Mathias Nyman Add a helper to set the interrupt moderation interval for an interrupter. Each interrupter can have its own moderation value. Hardware has a 16bit register for the moderation value, each step is 250ns. Helper function imod_interval argument is in nanoseconds. Values from 0 to 16383750 (250 x 0xffff) are accepted. 0 means no interrupt throttling. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 0886829d53e5..b405b8236134 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -346,6 +346,23 @@ static int xhci_disable_interrupter(struct xhci_interrupter *ir) return 0; } +/* interrupt moderation interval imod_interval in nanoseconds */ +static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, + u32 imod_interval) +{ + u32 imod; + + if (!ir || !ir->ir_set || imod_interval > U16_MAX * 250) + return -EINVAL; + + imod = readl(&ir->ir_set->irq_control); + imod &= ~ER_IRQ_INTERVAL_MASK; + imod |= (imod_interval / 250) & ER_IRQ_INTERVAL_MASK; + writel(imod, &ir->ir_set->irq_control); + + return 0; +} + static void compliance_mode_recovery(struct timer_list *t) { struct xhci_hcd *xhci; @@ -528,7 +545,6 @@ static int xhci_run_finished(struct xhci_hcd *xhci) */ int xhci_run(struct usb_hcd *hcd) { - u32 temp; u64 temp_64; int ret; struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -551,12 +567,7 @@ int xhci_run(struct usb_hcd *hcd) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "ERST deq = 64'h%0lx", (long unsigned int) temp_64); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Set the interrupt modulation register"); - temp = readl(&ir->ir_set->irq_control); - temp &= ~ER_IRQ_INTERVAL_MASK; - temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; - writel(temp, &ir->ir_set->irq_control); + xhci_set_interrupter_moderation(ir, xhci->imod_interval); if (xhci->quirks & XHCI_NEC_HOST) { struct xhci_command *command; From patchwork Tue Feb 13 00:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268754dyb; Mon, 12 Feb 2024 17:28:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFk7Gr20E6xDtO/xhKYvgjnROc/sax/xIi58Z7ztmm+O1/9Yk+f6b72mFn+s4oGVTBpSsGB X-Received: by 2002:ac8:5f95:0:b0:42c:2a20:97e1 with SMTP id j21-20020ac85f95000000b0042c2a2097e1mr11259021qta.13.1707787706288; Mon, 12 Feb 2024 17:28:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787706; cv=pass; d=google.com; s=arc-20160816; b=ns55rc6xaoUWzIVJRyHXA4DGdjR0A5F0Bx17x4K3dlJZ/Vf+c86q1Vy5z3ScvAyFjt D61kaNP38GfZkhD/76eYjN386/zsgelgBgmveARzsp40+LM8B3MhMoOiEAFz2Dw4nFSO PfxZbt2OOAdeXN2oZBEdO1aLuBUIAaG7Erl/QKZ6nO1jb85qYPRD+XF3iQshY7h1yfaj 3Z5hT4e3RxFXgFj9gNBToVRa3BbjtakG++I62GPXPzTlVrZp/VRxjL457dMs6jOYAGuG 3awSZ8U+HffIiAFTIWfe7afFMuUJ0FN9alGjtbbtdbHX0wCOu2Kh9AxMMEk+ks1EiDrv FQqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0+4zaN2NaOvE5eSNuM7RvaMAH7ifIk0BKTL8NmYDuJc=; fh=9+IM1fTdUL67FXuSFJAWeMT0/3hJ54Lsy5vyTr7H23Y=; b=va8ckIap1yMbc0OJ11VM8aP1O3nHVSX84K8jSozcJ5KcJZ4xu85uYx8OT4OaM1c4/y C+/oC/7eRjnEgrS+K/iiL5PrLznx/LBR6BVq2DyudJ2wRL9pfXWMdp0OCQ8fw/pafE+Y GDTMLwthvNjzZg/QZpCX3osduC5R8I65O3fmIA3CHErUubk50GonQ+bEwVOv7O5uL/k0 yYKzcBPp72Hmj3kIIGYMnzhxzNj0u1XWez9d8+vpPq62pcIQyUwwv8RoEw16OsCj1H7R 8rKzuvdxk1h5p/U6FPpIBPUCeavUMAuN2lmrSJBiuz0uhzOpb+7+FUVMYahy0el0LY0C iPWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XygPBqvB; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62784-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62784-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU+LAE/PX9fOGq6/Oih74Y4qvPguamJGwL/xSuWxa3avWSOa/2pV0Y6cm24CIbGShEXCqJ7tt2NxE4s70yvToUv9Q531Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e18-20020ac85992000000b0042c68aca49csi1839733qte.570.2024.02.12.17.28.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:28:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62784-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XygPBqvB; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62784-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62784-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0C9471C248C2 for ; Tue, 13 Feb 2024 01:28:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D43C5F575; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="XygPBqvB" 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 EC6BE22301; Tue, 13 Feb 2024 00:54: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=1707785698; cv=none; b=Gl8Il4raxz1W0nqAMerYbf0D8t5CK0mHDh56f4TkVYcEXw8p54GS0UZzCFQDX9WU823g+CkquOW77arF+3dvRc9c6O8TEKt+9RgzLVf0z4ZD+GyTv/yr61/5Qd4C5zyEz0vJYHKAEsxdN+nhIv6jRWCqVz4yR1RGbyIzhzDulG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785698; c=relaxed/simple; bh=mMfpAsIQkrbAWVmvCtRxOhWRPl8nuSyQX1IpdSaNgfg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S40CvAibb++6sjiPQuRZyw+oE4uR95aZIu1YOFzwD73IjotftwnDDOTpPQhTDl+Q74P7REF8bQfPCQ//gnVSB+qdu058Tx1BIkxKdKIbChcobEleJRF5muxvpNAjjeasxZ6ZsJHJiBgRukfGzB+TfIl54WVfmbprTC13TPkQ1Lo= 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=XygPBqvB; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0qOTG012544; Tue, 13 Feb 2024 00:54:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=0+4zaN2NaOvE5eSNuM7R vaMAH7ifIk0BKTL8NmYDuJc=; b=XygPBqvB61Sy75jhoawIbZ1cieWNgHmQUtKX 9NU0C0A3vM4CSR49dAh4IC4oNR1/tI0cmb7htbUnQ6W8fb7GQR13cfpoSZB+JhM4 3/iSZenxhv+MyAV/4skt4LGTo4ZROKGg5PnezpnwIU9uF/fvpRmoAVUE+IyuZhF8 nNagSFghvU1XOHSH+BORbCRbwVaKp57AiBKnzVu51yQueIX06XhsbPb7RyLk2oCg CSoop2f+xaOgos4zWpi2ibmKf7o28j7N9mQAbVOC0mtrS2CkekypiYzbLDxOVSC1 Z4/H5hEOuqdlQogtibzNnW6IDUTSiTFZYG4bUZ1gEdgDZs9Njw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sXYw029955 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:33 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 03/50] xhci: make isoc_bei_interval variable interrupter specific. Date: Mon, 12 Feb 2024 16:53:35 -0800 Message-ID: <20240213005422.3121-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: UAkEcM17QQNU8EHc-qS7S-DnD_kVorXP X-Proofpoint-ORIG-GUID: UAkEcM17QQNU8EHc-qS7S-DnD_kVorXP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=638 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745201654204448 X-GMAIL-MSGID: 1790745201654204448 From: Mathias Nyman isoc_bei_interval is used to balance how often completed isochronous events cause interrupts. If interval is too large then the event ring may fill up before the completed isoc TRBs are handled. isoc_bei_interval is tuned based on how full the event ring is. isoc_bei_interval variable needs to be per interrupter as with several interrupters each one has its own event ring. move isoc_bei_interval variable to the interrupter structure. if a secondary interrupter does not care about this feature then keep isoc_bei_interval 0. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 2 +- drivers/usb/host/xhci-ring.c | 15 +++++++++------ drivers/usb/host/xhci.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index a7716202a8dd..450adaca68ee 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2533,7 +2533,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) if (xhci_add_interrupter(xhci, ir, 0)) goto fail; - xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; + ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; /* * XXX: Might need to set the Interrupter Moderation Register to diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index f8e78068c36f..1b619a290446 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3103,8 +3103,8 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) event_ring_deq = ir->event_ring->dequeue; /* ring is half-full, force isoc trbs to interrupt more often */ - if (xhci->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) - xhci->isoc_bei_interval = xhci->isoc_bei_interval / 2; + if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) + ir->isoc_bei_interval = ir->isoc_bei_interval / 2; event_loop = 0; } @@ -3972,7 +3972,8 @@ static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, } /* Check if we should generate event interrupt for a TD in an isoc URB */ -static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) +static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i, + struct xhci_interrupter *ir) { if (xhci->hci_version < 0x100) return false; @@ -3983,8 +3984,8 @@ static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) * If AVOID_BEI is set the host handles full event rings poorly, * generate an event at least every 8th TD to clear the event ring */ - if (i && xhci->quirks & XHCI_AVOID_BEI) - return !!(i % xhci->isoc_bei_interval); + if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI) + return !!(i % ir->isoc_bei_interval); return true; } @@ -3993,6 +3994,7 @@ static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, int slot_id, unsigned int ep_index) { + struct xhci_interrupter *ir; struct xhci_ring *ep_ring; struct urb_priv *urb_priv; struct xhci_td *td; @@ -4010,6 +4012,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, xep = &xhci->devs[slot_id]->eps[ep_index]; ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; + ir = xhci->interrupters[0]; num_tds = urb->number_of_packets; if (num_tds < 1) { @@ -4097,7 +4100,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, td->last_trb = ep_ring->enqueue; td->last_trb_seg = ep_ring->enq_seg; field |= TRB_IOC; - if (trb_block_event_intr(xhci, num_tds, i)) + if (trb_block_event_intr(xhci, num_tds, i, ir)) field |= TRB_BEI; } /* Calculate TRB length */ diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index daee202cd369..44e447fdad62 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1432,6 +1432,7 @@ struct xhci_interrupter { struct xhci_intr_reg __iomem *ir_set; unsigned int intr_num; bool ip_autoclear; + u32 isoc_bei_interval; /* For interrupter registers save and restore over suspend/resume */ u32 s3_irq_pending; u32 s3_irq_control; @@ -1504,7 +1505,6 @@ struct xhci_hcd { u8 isoc_threshold; /* imod_interval in ns (I * 250ns) */ u32 imod_interval; - u32 isoc_bei_interval; int event_ring_max; /* 4KB min, 128MB max */ int page_size; From patchwork Tue Feb 13 00:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200176 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp276799dyb; Mon, 12 Feb 2024 17:53:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+ouovIrqEpxpL6vM2+6OrXJFX5NA5clB0k/ur8uqpjGuJjxx40HLak367NJ3LR+hyD0XPJxf5W/EZhS9ZqcjCW3AtFA== X-Google-Smtp-Source: AGHT+IF0cof7mkCNGKDkjE0plwGhuYefpSxs/aS/rl0c78tbFR0ejtdxL1iKIyc//NM71weeisSn X-Received: by 2002:a05:6871:b09:b0:214:df30:3b77 with SMTP id fq9-20020a0568710b0900b00214df303b77mr10776459oab.1.1707789237912; Mon, 12 Feb 2024 17:53:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789237; cv=pass; d=google.com; s=arc-20160816; b=RHjOsZnHq3HIwskMld5a2kuEwMLkIT6pM9uj3RXi4lOkWH+TGsmRK9IjSA2VNSJ9QD +6LVUgFssMhfCZeSf6+g1m4EiP5zGMUMcyMDtWLpI1dYAfHGKPZLv1uRBo68fFNrWi5Z coebccxeZi0dJLXwXxBctP+cE4/B+jprBdVqmCCcxujx+3KHibRgWRW7+P31cXKWxygT ETF3xy5VoReQF/h7dtWrVZEbWunHXtGvdsewI/rA1LYNuaoLfPxzgFXovQhO/jwsHAsq rMGmA5Ij29/CyYY1iE09NN7OMjh8xXJ/Ro2CxKTX/cmjBuY0fTkwM/nn2kQsSfUdf/Bh hi7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N1alWV4PWu2ZQmDggZ7zsuZUodSQzl50W127f+/3e+0=; fh=hoW8nXopRxwLY59KMBCw5G3n2I3egw/W2h1+xcHPcaQ=; b=0NUQqlqd3ntXqTMViWv/2uZ712cg+O3qBxktzZb1O5MzzqQEbs0yLiwQK6opjFL+PK ulNzfNBVibRlPYWAt4FVo/m2MqhTEhM8tQCby1D/KnaMAomdjF8OUDMhDsUatt/hu9G4 vWiBIM2AhE/v927vIjHCdn9V+puQaYrar/7OQOFKObrN97V/QdtSaLvQ7x6QQUocmXlj BhBB9RUa/pEk6DVvqqegFaaMWmYc1d6F0kZU1s18Fn2HiGNcd9flBtHVObayhq9E/hqB 5B5s/bS1IdB/JXDt/FnYhqsVMUSzTQA9MWnKSom/eSJzd+gJwI0GaP7OiPq75Z7b6wLG xdgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=HPNqv1Gg; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62792-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCX0RKnRy8VUEBO3OgWQsGm226GfoEu8oLL8XXxmhRr0K+J7Wy9hW1Izsp8K+3mJ0koOcn3FU2p4SzhROd/oft46+tSPTw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z185-20020a6333c2000000b005dbdce9d103si1061126pgz.563.2024.02.12.17.53.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:53:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=HPNqv1Gg; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62792-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C2529B27218 for ; Tue, 13 Feb 2024 01:32:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3705060B81; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HPNqv1Gg" 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 A928E224F2; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; cv=none; b=P3+p3lYAGXv5bSXZDszvwo6ToL/5dz74LX68dAUczs0GAZ10EVvV6SeWbjcJ7lHAlrjuytq3Ji2rt+boE11xBc0+sX6pqWBSQsnWu55NkJTCu/fsu8eWDAWkNCdkwAYT0CYaaVoS9wJjeoBkw5FH1aczX2YHzY9i7lXPrFk9EzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=kBRKQewBFwebBlSfn7sxo02gwubgl581TIfyTJo/ozk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TibbPba0WPR6FtqOoLgUALIwsGH2HXalmBmuNAmhs72jLvU12zO45TanagYoglHArYwFSfDKOL/nb+wgPhf0Mc8qoRw3+8mFjJOztrrl+oX8k87ZjhmIGJCmzdOeIT06VElRSNOFxGUpCZ7LqlLNVGZMAIihoI6ufwZT3KhglXA= 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=HPNqv1Gg; 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 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CMwliE025287; Tue, 13 Feb 2024 00:54:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=N1alWV4PWu2ZQmDggZ7z suZUodSQzl50W127f+/3e+0=; b=HPNqv1Gg716mlkkJTtcJ+Lv18FAV9rSkdvfJ 3u7ehFw07Ho9053cHFrhrTOMJiaBsM6S96Ho8cAiWCNrZi27AqtbxZcih0ctRztw aMXRWnT/68nh6ALmOXPxZpgegkOQoenSh24u9nW3GeegY5lrNzCTmQ41kJijTrPD MeeGr03SJYbGX0qH6yyK6MgrmrHuRQCZZv6XbJos0h0TUFtT5P6VGXBgDe9zp4Mq t1bquPKRhuXs91gqzMVrUr9x5iJAdyR5bNSDgIyg5dYBmc6O5+OEPnW586u3hDFe lIQ+ADh9ZHHxvnUQuxXScW9B/ltngQzlpdfnNuxfa16OVVHdRA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7nk91505-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sY31031064 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:33 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 04/50] xhci: remove unnecessary event_ring_deq parameter from xhci_handle_event() Date: Mon, 12 Feb 2024 16:53:36 -0800 Message-ID: <20240213005422.3121-5-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: OlCt0Szcx28euu3VdDh37AGo-G15EOcX X-Proofpoint-ORIG-GUID: OlCt0Szcx28euu3VdDh37AGo-G15EOcX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=994 impostorscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746808272585170 X-GMAIL-MSGID: 1790746808272585170 From: Mathias Nyman The event_ring_deq parameter is used to check if the event ring dequeue position is updated while calling by xhci_handle_event(), meaning there was an actual event on the ring to handle. In this case the driver needs to inform hardware about the updated dequeue position. Basically event_ring_deq just stores the old event ring dequeue position before calling the event handler. Keeping track of software event dequeue updates this way is no longer useful as driver anyways reads the current hardware dequeue position within the handle event, and checks if it needs to be updated. The driver might anyway need to modify the EHB (event handler busy) bit in the same register as the dequeue pointer even if the actual dequeue position did not change. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 1b619a290446..a9d2e876d62b 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2982,30 +2982,26 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) */ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, - union xhci_trb *event_ring_deq, bool clear_ehb) { u64 temp_64; dma_addr_t deq; temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - /* If necessary, update the HW's version of the event ring deq ptr. */ - if (event_ring_deq != ir->event_ring->dequeue) { - deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, - ir->event_ring->dequeue); - if (deq == 0) - xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); - /* - * Per 4.9.4, Software writes to the ERDP register shall - * always advance the Event Ring Dequeue Pointer value. - */ - if ((temp_64 & ERST_PTR_MASK) == (deq & ERST_PTR_MASK)) - return; + deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, + ir->event_ring->dequeue); + if (deq == 0) + xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); + /* + * Per 4.9.4, Software writes to the ERDP register shall always advance + * the Event Ring Dequeue Pointer value. + */ + if ((temp_64 & ERST_PTR_MASK) == (deq & ERST_PTR_MASK) && !clear_ehb) + return; - /* Update HC event ring dequeue pointer */ - temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; - temp_64 |= deq & ERST_PTR_MASK; - } + /* Update HC event ring dequeue pointer */ + temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; + temp_64 |= deq & ERST_PTR_MASK; /* Clear the event handler busy flag (RW1C) */ if (clear_ehb) @@ -3034,7 +3030,6 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, irqreturn_t xhci_irq(struct usb_hcd *hcd) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); - union xhci_trb *event_ring_deq; struct xhci_interrupter *ir; irqreturn_t ret = IRQ_NONE; u64 temp_64; @@ -3092,15 +3087,13 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) goto out; } - event_ring_deq = ir->event_ring->dequeue; /* FIXME this should be a delayed service routine * that clears the EHB. */ while (xhci_handle_event(xhci, ir) > 0) { if (event_loop++ < TRBS_PER_SEGMENT / 2) continue; - xhci_update_erst_dequeue(xhci, ir, event_ring_deq, false); - event_ring_deq = ir->event_ring->dequeue; + xhci_update_erst_dequeue(xhci, ir, false); /* ring is half-full, force isoc trbs to interrupt more often */ if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) @@ -3109,7 +3102,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) event_loop = 0; } - xhci_update_erst_dequeue(xhci, ir, event_ring_deq, true); + xhci_update_erst_dequeue(xhci, ir, true); ret = IRQ_HANDLED; out: From patchwork Tue Feb 13 00:53:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272974dyb; Mon, 12 Feb 2024 17:41:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsmprVG2Hw+IIN5x/iFsvHgLQUaRSCvAoAkcXC5wC/vagbZS8lVSZKpmgoe4bbGOfDLP+dHV9NHVTi7ABOaSPxcYSwxQ== X-Google-Smtp-Source: AGHT+IF4knAF1/pbHWT8GqooCLq/7kRNWz8AmeT3Oajr6UK+KpQ3WBf+37uolfWlNhrGO/Jls2Pl X-Received: by 2002:a05:6e02:923:b0:363:c63a:7978 with SMTP id o3-20020a056e02092300b00363c63a7978mr8358164ilt.25.1707788496312; Mon, 12 Feb 2024 17:41:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788496; cv=pass; d=google.com; s=arc-20160816; b=v66SWc3oetuEhhIMnLQg9RJuDsG+z7V9jwsKvRWiay3lUVydJ5Yn7+zBVubrUNzdwF bmv/mleqxZqsHbAMHLRLH1RnUR0GHyIljE2tp7XCVP57WiEOZnZsDnTBj81mhQiAmLvj Z729CBRnRl/WskrWiF7Z4ZPW+Rd+U7WnxapZsgB201zhs6VzjwiWOuJkJ9EWGk2WQrqk NVYI0NfT6FXbOWvs1OEq2n9rkXHEN96XqzEEa91sQGEM2J+YQmfjh6RxX4+zV4YM6Hz0 i2qsTF5X+e98BxA6I1DhuFw/1bHC8A0czC1MmhOBZNdLmky+TncuZyDF6zRNiKK2SUGJ wnbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e3ZP4UGfMJHN9tb9hE1aTUT7cHSD1ZLTE7FnRsZFK6Q=; fh=K4qwWPLsOVza/KmjqbetFbeUVMjWR3AaS+KxluTdTqk=; b=aQeDoEuex9xmVfott+oqp1rME9bMyS/FT4HhUWM6rEIt38vvyGxTRzmdBVI/zsdho8 4PX5a8yhELU+BV2SqRMdR5HfAT1biZoZBQ56yR6m0pahyPmOjMf+5ptF4nYy928wVpBG kaQRh8Sk8YIHhoz3Yoa8JB0vPqDQIp8Fzz18tyXdDBmJi7th/48JSiGWSsQGcMAE1yjO F4NyqwEgQVRLq+29ETYsH5bg8gSaii/3v5d0nwzmY0jfcfoRN0zPfLqX2SZq8uo0Ca9m hXDXquOy7GlgK70zWXqzgkkzDxq6Kt4NE+MRvliD2Wq1TocLbzGjJ2khE33/xeUCeus3 Y2Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aBrqkdTZ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62777-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUbJ7F6ntxzE3wKtuXhvb67qEGZ9y1973a1C95PudpY/wX81OF2EP2PKfTnX1n0GA+SUBjP1uOQ2n5F0yYfGXpp1biWIg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p23-20020a637417000000b005dc6fa39b70si1131553pgc.54.2024.02.12.17.41.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:41:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aBrqkdTZ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62777-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A84FB244B4 for ; Tue, 13 Feb 2024 01:22:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3877B54BF4; Tue, 13 Feb 2024 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="aBrqkdTZ" 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 730D0631; Tue, 13 Feb 2024 00:54: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=1707785696; cv=none; b=sAq5TgbNkTvcO+5tJEKp5ANVF2b6IUjZFDmqKcBUPC1V3/vFztW/KUGvr37TTs4ulGWHD/kBA/E5b13NRkG9/yhuGGn0w2dYG3GL5Ez58zPC75MvXExU+jxk2wWS7Ij92F8ewAN4euBJbFJEBEtme9+GJ8v+XsiYKmdp7iepP98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785696; c=relaxed/simple; bh=9xhUO2oBg3VGby3vuFrh+xyofs8aRXlLZClt/1/wQLY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EYil5c7OmrqnjpemOF3ykc5LHlLU/UVntlzCtD68sIRSqwH7his7cAAWKFNL9s4mixVXD4IKOjl8Cm5AcZlKd9ccq1wfB3vNRLBzk4S1HKwr9jG9aoAx7HcGGtgLAwhMXFIYaR5RqR6URzOsBFwa4B1DW0g/q5Dutc49OFk0TkI= 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=aBrqkdTZ; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D09Ysj016771; Tue, 13 Feb 2024 00:54:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=e3ZP4UGfMJHN9tb9hE1a TUT7cHSD1ZLTE7FnRsZFK6Q=; b=aBrqkdTZ61OWT36+l02qdAEAkAsimqWgdDmw nHMayodPCCY6qLVgFbN9ZnKe2gHxCF0Os1moVwEx9AcZsZ2TQ+rE9fQPUOoaIlYO kpRZBCi1+lptgzCkzLtNMziCh8yHdxmYdFIGmTxckTxD0Lmq0dkjU4dhw6d48Xko ZZKPlrltq3InzhICLF7kulH4KRQTbUrrCC+BzwX0wOtfWIyX6oULu8suJfAni/Ad ciaUmFx/DuGl2zHLhWFnPkTVvLO8FNsHOFwyrbVpNaaRYWk4sJNgQ9R7G8zORO6v Hud64NxIeuc3aQJns8pc64Yb5ic9MzME4xqVGHgJaJjR0ZB6vg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4ty8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sYjR026763 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 05/50] xhci: update event ring dequeue pointer position to controller correctly Date: Mon, 12 Feb 2024 16:53:37 -0800 Message-ID: <20240213005422.3121-6-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: U3voO1VJLncFRE04Fk3igBRQ06DGSlg8 X-Proofpoint-ORIG-GUID: U3voO1VJLncFRE04Fk3igBRQ06DGSlg8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746029890801366 X-GMAIL-MSGID: 1790746029890801366 From: Mathias Nyman The event ring dequeue pointer field (ERDP) in xHC hardware is used to inform controller how far the driver has processed events on the event ring. In the case all events are handled and event ring is empty then the address of the TRB after the last processed one should be written. This TRB is both the enqueue and dequeue pointer. But in case we are writing the ERDP in the middle of processing several events then ERDP field should be written with the "up to and including" address of the last handled event TRB. Currenly each ERDP write by driver is done as if all events are handled and ring is empty. Fix this by adjusting the order when software dequeue "inc_deq()" is called and hardware dequeue "xhci_update_erst_dequeue()" is updated. Details in xhci 1.2 specification section 4.9.4: "System software shall write the Event Ring Dequeue Pointer (ERDP) register to inform the xHC that it has completed the processing of Event TRBs up to and including the Event TRB referenced by the ERDP. The detection of a Cycle bit mismatch in an Event TRB processed by software indicates the location of the xHC Event Ring Enqueue Pointer and that the Event Ring is empty. Software shall write the ERDP with the address of this TRB to indicate that it has processed all Events in the ring" This change depends on fixes made to relocate inc_deq() calls captured in the below commits: commit 3321f84bfae0 ("xhci: simplify event ring dequeue tracking for transfer events") commit d1830364e963 ("xhci: Simplify event ring dequeue pointer update for port change events") Fixes: dc0ffbea5729 ("usb: host: xhci: update event ring dequeue pointer on purpose") Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a9d2e876d62b..0289d77839cf 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2966,9 +2966,6 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) return 0; } - /* Update SW event ring dequeue pointer */ - inc_deq(xhci, ir->event_ring); - /* Are there more items on the event ring? Caller will call us again to * check. */ @@ -3091,15 +3088,21 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) * that clears the EHB. */ while (xhci_handle_event(xhci, ir) > 0) { - if (event_loop++ < TRBS_PER_SEGMENT / 2) - continue; - xhci_update_erst_dequeue(xhci, ir, false); + /* + * If half a segment of events have been handled in one go then + * update ERDP, and force isoc trbs to interrupt more often + */ + if (event_loop++ > TRBS_PER_SEGMENT / 2) { + xhci_update_erst_dequeue(xhci, ir, false); + + if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) + ir->isoc_bei_interval = ir->isoc_bei_interval / 2; - /* ring is half-full, force isoc trbs to interrupt more often */ - if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) - ir->isoc_bei_interval = ir->isoc_bei_interval / 2; + event_loop = 0; + } - event_loop = 0; + /* Update SW event ring dequeue pointer */ + inc_deq(xhci, ir->event_ring); } xhci_update_erst_dequeue(xhci, ir, true); From patchwork Tue Feb 13 00:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268835dyb; Mon, 12 Feb 2024 17:28:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQpPZUE7nQ+4Ys/aZpDy/uHiRDU8FUODI6tWWEI8mjwQu+Y893gPwz1K97oAwDsZOBXrv2LRiCBX3C1HHhDYCNtJKOfA== X-Google-Smtp-Source: AGHT+IFguhXgihXH+hebGUqSj2ViDRgKcp1TSi3NGz1y/M/OA0ASHXkWKNOoRSZ9/djBYS+sYSkq X-Received: by 2002:a17:906:1c8a:b0:a3c:31bd:e9c0 with SMTP id g10-20020a1709061c8a00b00a3c31bde9c0mr5658831ejh.9.1707787723525; Mon, 12 Feb 2024 17:28:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787723; cv=pass; d=google.com; s=arc-20160816; b=vBuVZJC43fuIf4E5t3YLSuRDfsXg6zpkV061zCb5Ew1/PHRkjswOB50P6AF56eLCNU xxgLA3OIUZZcdlatrksbmLBKm1lp0vkrWmpMGCBxvxXcQWAzJQ/n1TukOt6u3bgpQH6l +IbzPOE7/zNWVpJvShRT+WjvVCgdO2TTrHVaJaCrIJYC0ek3lNPuxArtEkC0l6Q+GGMP bSa4xRyxygB3v8cF2gkHUOkRu67FBZYEN/oKGGJa8tJaBQTRIXVcl5ZAWOFOqUTpNWKL ugW6Y4913lYXZLyZ/a0fDiKmBw8hICqweCXDKQ2hr7Gt/dVOtOgMIcevzO+KiDqCTecp EC6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=r/s48r7Nd+rNVTCx+HL87L+3Njw26bFVh6+6XCcEXOU=; fh=k6tu/PhtrwluKJRiJJlHcfTqs7Gexs3P0uYvZ+Rf8Fw=; b=W7SButTSWInrtePWEg18tofwSKLiLBB8vkv2S6oirHOIy/r/byQDTC3lirm3sK8anw m8lsZRonVFzg5qTDjw4ef4NHWUHP6Yj0UmkEBqGCQVbcJnTa/9X3BvvESScVQlK2BC9G UCwCByg91tgdJI5cxBGabAUcV5ArAFF+mYUFHybYMzjT8FTc+dHbaUsZdg4VaUXOGMtB duMLQfDCCQs8Sb3VqnkjcKnZ33595LPQXlsWdH6M5FT4z6EMndUHsoLPCpUXwO9G31QM +XsGVVxnr0WriWCTT6V0wUgPVu+VoMaX2H/OnaJzRUc+Ig1iUQnnlSWqd8ysr23EAuFq dLcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=a3NiQawg; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62791-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCX1q1urha8K7fg5IYaW7Tc3eCU9LooDmXKkA299/BfFn3OMGlLaa0Kvt/To62u+CL1hl0d1824gLgt6qTCVPtrMyXqfWg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c17-20020a170906695100b00a3ce36ce1d5si549307ejs.149.2024.02.12.17.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:28:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=a3NiQawg; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62791-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ECC021F28F19 for ; Tue, 13 Feb 2024 01:28:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90A305F862; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="a3NiQawg" 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 A9BA8224FB; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=ZD/7ThF/7FfHK7hDT37KQB1tcsM0EEUPKsZsZRNbCH8ZIZjm9/FdKHjs9MZDKhgzG0TL783UUi1aLg/FIavlR0yfhv4qrI5vVrIBlC91MhD4aLkIwZg5jCKrNL1AJf+yom3dnuHfzDG90WHV2Uf9BoX53QFz+UYQXEm/VdACQoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=V8MdAsKTPp0AteG57V12qaeFcyZsxonTIhHZ2e6F4Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MFsC7R4AGSSAxfbmk2en6/jdQ3T9En11ZtShvJKH/lJXoQ4JceGD7akn3MT+zt5sMwz5cmt2hWnm/2u5bTwn1kfAJ3kBSxtYJ5nSdcveTqVbc/mLctC966GVRIkfct4KQlqQIAG6vJlI5KoD+BruvTF314/BJq4pDX9CiTD/Sik= 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=a3NiQawg; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0bZj9005335; Tue, 13 Feb 2024 00:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=r/s48r7Nd+rNVTCx+HL8 7L+3Njw26bFVh6+6XCcEXOU=; b=a3NiQawgLCWE1XTKxeDeI6RWlDd12MzOPzpb awDzHtKo/O4kL1aDJu3eoca9G7U7+H0UKLywqgHYg5ycpT+jUvtvDvR+V+qtXbRx VD/ThNo2cRLcuW9HHESGx324nY9RlgzVNrdudqKMaD5G9lS20fASbwg4vOjCmU1T x/nchYFGZoNfCWU/NDWRxuCP7VnO6e5BYF7cIf1JcUYDtIRPMulsm0emWtzw7a58 LHxlzIYKszPE5tQHiflI1jM11MmNyQPEJmNRgEVbkXAgmOnXtr+IM/8M48L3Rb9X oh7NhAXAWvEidOrPaArMtyS8yLy9m3QyJyTCKXfb8WQ/Mjq3Dw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4ty9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sYWW026767 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:34 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 06/50] xhci: move event processing for one interrupter to a separate function Date: Mon, 12 Feb 2024 16:53:38 -0800 Message-ID: <20240213005422.3121-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: qBvbpYauSl0v5LFXg7yx5sJbrhM-xZAt X-Proofpoint-ORIG-GUID: qBvbpYauSl0v5LFXg7yx5sJbrhM-xZAt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745220224618953 X-GMAIL-MSGID: 1790745220224618953 From: Mathias Nyman Split the main XHCI interrupt handler into a different API, so that other potential interrupters can utilize similar event ring handling. A scenario would be if a secondary interrupter required to skip pending events in the event ring, which would warrant a similar set of operations. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 87 +++++++++++++++++------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 0289d77839cf..338b6fddedc3 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3019,6 +3019,46 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, } } +static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) +{ + int event_loop = 0; + u64 temp; + + xhci_clear_interrupt_pending(xhci, ir); + + if (xhci->xhc_state & XHCI_STATE_DYING || + xhci->xhc_state & XHCI_STATE_HALTED) { + xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n"); + + /* Clear the event handler busy flag (RW1C) */ + temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); + return -ENODEV; + } + + while (xhci_handle_event(xhci, ir) > 0) { + /* + * If half a segment of events have been handled in one go then + * update ERDP, and force isoc trbs to interrupt more often + */ + if (event_loop++ > TRBS_PER_SEGMENT / 2) { + xhci_update_erst_dequeue(xhci, ir, false); + + if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) + ir->isoc_bei_interval = ir->isoc_bei_interval / 2; + + event_loop = 0; + } + + /* Update SW event ring dequeue pointer */ + inc_deq(xhci, ir->event_ring); + } + + xhci_update_erst_dequeue(xhci, ir, true); + + return 0; +} + /* * xHCI spec says we can get an interrupt, and if the HC has an error condition, * we might get bad data out of the event ring. Section 4.10.2.7 has a list of @@ -3027,11 +3067,8 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, irqreturn_t xhci_irq(struct usb_hcd *hcd) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct xhci_interrupter *ir; irqreturn_t ret = IRQ_NONE; - u64 temp_64; u32 status; - int event_loop = 0; spin_lock(&xhci->lock); /* Check if the xHC generated the interrupt, or the irq is shared */ @@ -3064,50 +3101,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) */ status |= STS_EINT; writel(status, &xhci->op_regs->status); - - /* This is the handler of the primary interrupter */ - ir = xhci->interrupters[0]; - - xhci_clear_interrupt_pending(xhci, ir); - - if (xhci->xhc_state & XHCI_STATE_DYING || - xhci->xhc_state & XHCI_STATE_HALTED) { - xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " - "Shouldn't IRQs be disabled?\n"); - /* Clear the event handler busy flag (RW1C); - * the event ring should be empty. - */ - temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - xhci_write_64(xhci, temp_64 | ERST_EHB, - &ir->ir_set->erst_dequeue); - ret = IRQ_HANDLED; - goto out; - } - - /* FIXME this should be a delayed service routine - * that clears the EHB. - */ - while (xhci_handle_event(xhci, ir) > 0) { - /* - * If half a segment of events have been handled in one go then - * update ERDP, and force isoc trbs to interrupt more often - */ - if (event_loop++ > TRBS_PER_SEGMENT / 2) { - xhci_update_erst_dequeue(xhci, ir, false); - - if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) - ir->isoc_bei_interval = ir->isoc_bei_interval / 2; - - event_loop = 0; - } - - /* Update SW event ring dequeue pointer */ - inc_deq(xhci, ir->event_ring); - } - - xhci_update_erst_dequeue(xhci, ir, true); ret = IRQ_HANDLED; + /* This is the handler of the primary interrupter */ + xhci_handle_events(xhci, xhci->interrupters[0]); out: spin_unlock(&xhci->lock); From patchwork Tue Feb 13 00:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp273034dyb; Mon, 12 Feb 2024 17:41:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNd5H0cXlpScuRWve22s3UK9pOG8MDB1LuEYDhfGF4XoeNQnpDpiI2jC+UtFqrNvsTOqWe X-Received: by 2002:a17:902:e54e:b0:1da:23e3:1de8 with SMTP id n14-20020a170902e54e00b001da23e31de8mr8915076plf.27.1707788508016; Mon, 12 Feb 2024 17:41:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788508; cv=pass; d=google.com; s=arc-20160816; b=MaAnFuqRRJjGQ23awKaaS5wCCq5C/1FXL5Tej4f/Tqr+xmVufRZjTyW1XP7qooVex5 eu+5qqFM5rkr2SmWwBz5R8u9EGbS7M0SMP7s9AcvjH1Xze62H9M1DSrc3ocIq7Wm2b5i 5t+umKzGJGjhekHEMrym1wWTCL7c/TNbXGMXVkGuP1FpgngAtkr1oFW635AbqxjCGYLm Q5ZY1pAVLBlDsE9MYhqo1BkwnkKbYZ3A2PwfYHl3vMNEGom0YKCgxOJZaXebtGNb6KBh TE7+Db/bRKXJbhxZ+PbCAYwdRlX4ls6I3WmcxnyHghKlcPQuHKQRVBCaxQDBVVJwmFGE hC8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v2ItLrNtk2j1QY1c2ABM7WgcR1ha0sOr3zVlmeNNouY=; fh=4Vd07ok0YlKYF5ykvuNV3T++lp/fe+wQTNgy43L4KuE=; b=RwcLqdKTUnkLuyZsdN/KbAVL1wkqIOQVXBGcZXTXymOIMUb4Rn/csPMxJ3kpiZdc99 IZgspp9bNh+Csv0mLbeQDgVeXkz7yeFV/23bBW3ezBL/t0d3npg+WWg0fu79K/y32iCB wFRg8bhVTSTiEAmU7K4Du7cb6P0DMH4dVxXmiaILUk2kIavh5zK631y8sF7GCm3ZIvx8 l3ByqHHuJIBcYLZUUPorVSZQWuYJbjDtJiknHz/2Ev5e+DYal1qK2amnKVrRWvl3QOTR +j/vGg/I5Eb/xh/0+0Z71p+P0yxxDkdh8z547DAkhEo8OJgym9/owF8KhefojLXFofV/ YTmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=fWtEtV8o; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62778-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVoIantIVMmsC2wZ9hf4nS8cgXysFYk4XHsVwY2W+iTHWs42NIUajWsVUpTOCAxJ1i6tx41o5IB8fGWZEdTgScL2cw4xw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 5-20020a170902c14500b001d78c9a13b7si1066950plj.528.2024.02.12.17.41.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:41:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=fWtEtV8o; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62778-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1F2B4B24ACD for ; Tue, 13 Feb 2024 01:22:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE6A854FB8; Tue, 13 Feb 2024 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="fWtEtV8o" 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 CD7C41EF13; Tue, 13 Feb 2024 00:54: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=1707785696; cv=none; b=lMDhkmjKRSdurq5nn7P8CbTEiz1425T90cAWZgxikKZrVrQ1ZJdDx2LBz/fs2Ld17zjwt4wv/OViBdbDRIqXpD/GEi7WoMXlhGzIj7iLMYksKPbidcZlbnuvpWoPpTjGz0XdmreK5K+OILQfZXGFzVbRY8FFuY12lonMY8oRuAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785696; c=relaxed/simple; bh=httnPJJML5QlmnUl6L9g9SMmpTEhPWJw3rWiUQwkot4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OSz+afFxEz18jx04RDhrcjwDHxhPQ9d/2y9cdzIsM7D5C298OQV2RF7+XPsg8DcCCROn6pw0Songx5x+PZvq1rWvl3hOsmWLL5hrsyJAxvfvuPMbkijjhPDpkxSOJRzmob1rRsNQD5fSAEiJSUPmLtytbTPuuA9O1TLK41PJ6LQ= 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=fWtEtV8o; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CNlaHD015770; Tue, 13 Feb 2024 00:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=v2ItLrNtk2j1QY1c2ABM 7WgcR1ha0sOr3zVlmeNNouY=; b=fWtEtV8oSPZ8wnr1AHYQjQ7qff+uXxHp0Fs3 FJk17PGQDk0GiPJjduppdqCCv+V8ZKMM4rQUbIx9unJ/1SA5nD+p60R9gP3dP/dX KsBhO/OslHj11i0Zyr5IykwFUZq44Rz53Vi2iNZKg3kudhWZv58SWxF209tYswSd gMhzdrNHvvN5AQJW7vm6B9aAV7QKPa6yRfIJxUjVio2sz42+OYoQ3Yy3uWvSYgOb J7jm5x0Y0H53MUSjXkSkQLplly6/WJmmTKwYTM2oQTsjA9J0Rezpc/GwgDcXbSHo 8JQLgHjsqn5RmliX4j2ed+SQOJ80EufX0Na8/AnM7/P6Yvwutg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuwx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sY2X026772 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 07/50] xhci: add helper that checks for unhandled events on a event ring Date: Mon, 12 Feb 2024 16:53:39 -0800 Message-ID: <20240213005422.3121-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: KGBhyYkqqUhxvsgctafNYaxkd-P5tWpn X-Proofpoint-ORIG-GUID: KGBhyYkqqUhxvsgctafNYaxkd-P5tWpn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746042649540169 X-GMAIL-MSGID: 1790746042649540169 From: Mathias Nyman Add unhandled_event_trb() that returns true in case xHC hardware has written new event trbs to the event ring that driver has not yet handled. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 338b6fddedc3..48388bc16b24 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -113,6 +113,12 @@ static bool last_td_in_urb(struct xhci_td *td) return urb_priv->num_tds_done == urb_priv->num_tds; } +static bool unhandled_event_trb(struct xhci_ring *ring) +{ + return ((le32_to_cpu(ring->dequeue->event_cmd.flags) & TRB_CYCLE) == + ring->cycle_state); +} + static void inc_td_cnt(struct urb *urb) { struct urb_priv *urb_priv = urb->hcpriv; @@ -2923,9 +2929,8 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) } event = ir->event_ring->dequeue; - /* Does the HC or OS own the TRB? */ - if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) != - ir->event_ring->cycle_state) + + if (!unhandled_event_trb(ir->event_ring)) return 0; trace_xhci_handle_event(ir->event_ring, &event->generic); From patchwork Tue Feb 13 00:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270142dyb; Mon, 12 Feb 2024 17:32:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/mG/bcM+Nl2tR+hvy/003HukpCGlimd1wCk1Flf3MGnbiMc5Q7yLgwgcOK6jPrx48dLl9EAhUtm0w9gm/5QLtJF0BhA== X-Google-Smtp-Source: AGHT+IECOB4x0SoaxUahhuK/+N0TelomXPnFIwnRtBROO6on2uHr8DdodYZXkyPsatQRU34R2LiT X-Received: by 2002:ac8:7c8b:0:b0:42c:72af:d9ce with SMTP id y11-20020ac87c8b000000b0042c72afd9cemr5229257qtv.64.1707787959133; Mon, 12 Feb 2024 17:32:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787959; cv=pass; d=google.com; s=arc-20160816; b=0D0Qawrxxt001BR1FDcF7d9zDkkEl/zZBiQFcO6NqkoOdsGJPdseLilO3Sm/J3rVF3 bFx2DYoJViY92SWV5VjvpR3n0YvM6TyIX1drJjwa31jaLS2k6pHvNaS++nT0XjxidRj8 hO2QWqLzdLQBPTomYFw2ywROAhKIfsAMrJ5YrVrCWUmfqbEgvVV3lMjyNzteCT1T8ena 17xtXXzuM3PmdtHpw9O4VCmdE7pesKLu97n5DIIN8wy8+ap4PwPOalfCe1P82CT9oPVi EBPzv0seJU2Ax20tDB2hcYdMttc7nIEFvkBMU7OVZQMt8XBytOd1x1NEoCiWCjZdeKQ7 6BLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KLjeKKCPmPfKQrXevx6PEsBCLzPg435el7fcR46yWyc=; fh=ED3m9srEc/nrNxUQJK+hdad/O8pOBXb6dK3nJNYrYLw=; b=DZ6b7IxOAaNN2liRGJld/UjHSk0c9xPQxcVTg8CH/Ig4CbY7DzfnoEQjeh/1TxEdMd kv+nesOQdaq6eEKhdW/iHNdnNjgvyvpa2XvZpfm75QyaQFuv3aLatnuXk6wTSsq5Jb89 W9chlBHjRxazosW7YsSgoNv4c4HNmN65/oXzTe4WAcaRO8qjxcr7Ts0+62NGqIl/PNx9 8U7a3/qCnL+xUd06Ht01BkvrStK0mZqoPXNUg2H+y3OxSlwh3mWayfznY+hrXhlJlOfF agIINM31nYCOwVAvoJRWRmVyGYLasFbR0/AlZmw9cL4h5Y1x01BWG/LQALq3YCaJxnFK Z9kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DoBqXamO; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62797-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVAMW5lgfDEFZS9OSECYxQbv9o4t0jRfFXziDXbN1zjk9zQ4VgFYAzaavJCxc5NLd7Sd4yiIFfUPJTvUkvqbB0NJaShxQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z17-20020ac87f91000000b0042c8093f2d8si1829137qtj.583.2024.02.12.17.32.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DoBqXamO; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62797-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E858C1C23121 for ; Tue, 13 Feb 2024 01:32:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07FBF60BBF; Tue, 13 Feb 2024 00:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="DoBqXamO" 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 F02C6374C5; Tue, 13 Feb 2024 00:54: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=1707785700; cv=none; b=u0G04cc8sBG4BkKRerdtXqd+6FpSMpCHPBf3sNVGajjPY8e9wn3JPJMCBsdgs/m8Qxdpmbc1SeEUxwV+qWu3+tNtKLB/gUuqhOn/QyACb7ibvgbz6NEJd8uudvoG7bvIaLfU1IIJN1kxOHpiwn6Rz5bfD2T0t5P3BLULyHnFPpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=Jk0LMWaa/SpQYHxNARX1Jnkq4LIW4HOuymWLQdv26ls=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PzeJNzKeuIp1SF1qtMmY/SUULGF98aXEjR4TWWLPh+f2ahyjlqeYS2zDIMk01VLSpU7+R4GbCQeIOA4bgSpl4h7BCgyoiHMW5QdayM1HlT2u0CaKcT5D6hSs4U2+ndvRAJA0mgwz2kcbsQJPQ6nnq27HAkPTB7PsISuy3EhagiU= 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=DoBqXamO; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0sa51001435; Tue, 13 Feb 2024 00:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=KLjeKKCPmPfKQrXevx6P EsBCLzPg435el7fcR46yWyc=; b=DoBqXamOhXervrR6deZ/k9rCaIFCIg92Xl6p gCVoBxWVXzoTQ7YuJQcVA98jQ/edMRm8CPCIt0VMG8nc5rtEP2ak/rBupifsUgJZ 1a5ck0QYeaADbl44D5N8QaRqrhWhyiCA6yQmpX2vVCp5Vq+Fx3KyJmSDEGYt59b2 3gj6Tx7N1UMtlTXgaLMcatSc6ttE7KBl5AiI+rqE5hGAwf1eroSB6HQydVx/mjbR g3Gyrd58CKfRodlC/6M1zMyTl1057igQZFB1k3WqSLGyUhRQq6aOWbUEaqoBRR+b Hsl6eOXzlG/txfOedMmNVNT+DviRGr9S9yiNbqhTQTKW9KHibg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sZmb031075 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:34 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 08/50] xhci: Don't check if the event ring is valid before every event TRB Date: Mon, 12 Feb 2024 16:53:40 -0800 Message-ID: <20240213005422.3121-9-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: yprBD-P_vUWcNNinZbNpqAwESbsCnXXu X-Proofpoint-GUID: yprBD-P_vUWcNNinZbNpqAwESbsCnXXu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=476 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745467124389463 X-GMAIL-MSGID: 1790745467124389463 From: Mathias Nyman Check if the event ring exists and is valid once when the event handler is called, not before every individual event TRB. At this point the interrupter is valid, so no need to check that. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 48388bc16b24..293239d8fab0 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2922,12 +2922,6 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) union xhci_trb *event; u32 trb_type; - /* Event ring hasn't been allocated yet. */ - if (!ir || !ir->event_ring || !ir->event_ring->dequeue) { - xhci_err(xhci, "ERROR interrupter not ready\n"); - return -ENOMEM; - } - event = ir->event_ring->dequeue; if (!unhandled_event_trb(ir->event_ring)) @@ -3031,6 +3025,12 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir xhci_clear_interrupt_pending(xhci, ir); + /* Event ring hasn't been allocated yet. */ + if (!ir->event_ring || !ir->event_ring->dequeue) { + xhci_err(xhci, "ERROR interrupter event ring not ready\n"); + return -ENOMEM; + } + if (xhci->xhc_state & XHCI_STATE_DYING || xhci->xhc_state & XHCI_STATE_HALTED) { xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n"); From patchwork Tue Feb 13 00:53:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp269995dyb; Mon, 12 Feb 2024 17:32:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUs/eij+8JMuHR8q76EZ24Kyu03hiPF2K45j/wbTmcdOSAvGp/8hnAaZ3oiUga4gzDhry37nJyV3Ic0iQGmnnIRS93qJA== X-Google-Smtp-Source: AGHT+IFdR1onlrlb2mX8TanvkVL8awXWsP1Ia5e5e76URRvc36B6zacndn2Tt8WkKFdyetFIzS+T X-Received: by 2002:a05:620a:31aa:b0:785:bb46:860b with SMTP id bi42-20020a05620a31aa00b00785bb46860bmr11440031qkb.50.1707787934136; Mon, 12 Feb 2024 17:32:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787934; cv=pass; d=google.com; s=arc-20160816; b=teQEy7oyoGtSPOZ/HRbOSJ5DyerzNUf3+LicqZ7gxneQSp67VEGuR3BmvrH5K5aV6a Hm5I29JU7zqPuYGQnyAiEbb4VbHgox1C3SXH6H7JtjcXF2ZfNPO7erAvyv0NYHcVyqKe LPT1+BEy9qImlFrNcbbDBgyh1eSs7QoZA8E3W+7XYuGhx2xwfnW1aCHMMn9NnXpnqKQb Sb/qr2OlHxwIJVJutsMuj/+3A68jlPHzgFIPfxn1JSX5/fL/VT7pACO1iwWpjM/PwIgx snSMc4mN3D2HCo/n11IqXcrzEdPSi5m6UxCoZ65RVokTnmZxxbk1kEyCtbbzGIUii62C 3N6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YEmwQFMFTsyU12bZ+DA3QUirFGkywDIHtACo1YVzlzE=; fh=5m3l4uTszJfcondahkSEvq+6TfxNj6jyScWPF9ONJoM=; b=ZP9eDoGyEkhOik4Zm+xMOoPZO/4iWv9WMlFnF6iVpnhIWm/KJ4r5Qkqfg+QFcmSecs 8QH0VFW2ql6PJU2YU826keBfInmUSNjv0cO1u0TQWy7JOynUjIzbpaBuli0TeO26hTfF 2iJXqvU8AmtX2uoLZr7q+HLsAfd9IoE2LOyFYoxEUdSeQ3nMjt3m87rSSMgaFUoivghX pRvmgJhkEfITFZ6p43Kbv24yskYt0GN8QQt89jB+9Fp5LjjLuXtC3nCAkf5FS6Mot+CX AZ/CBtwZ22gqJDFxSInI/4zUnmT7BpgB06EpKajTLTR444xibsFWGtjkG/nskiE9Z/mO kARg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cMo+B+Rw; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62793-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62793-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUTcoyy04ULdQzMSqZ2OUELP64IsYlvdKF2ZSNoLrm2DI9NjaW/HAiu2idwQo5KSWUd+VMkxNSy24797mJywydt9ayyCQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g23-20020a05620a13d700b0078575911c72si7370549qkl.671.2024.02.12.17.32.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62793-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cMo+B+Rw; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62793-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62793-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D73701C24A39 for ; Tue, 13 Feb 2024 01:32:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6739760B91; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="cMo+B+Rw" 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 A9337224FA; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; cv=none; b=RT/PP931rI30/26R8i9UculpWLNEMH4UQ7BJ/Iefg/5hMkE9K2sDvYETdqXl13fNGH/nPAnLQg/PckZFoPvH7Qf+MXlwpJw5ts59DdXA8085yvcxdF7rFegWERj3rY8Wibo6BUkfELlvfwu+ovapS/7qiMtpwL280GZTklVsIuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=noUq46uIIl4c54Ml8nUqG/zmcTMdZmp/uQzsEWtdfvc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ERA34B2pebcSXwp0gX240ouH4yc00P1YheaY4imWaM1mSZ/WS/9+blTZOAwain2R3Hpr2gMFDXw+t7+VREIpdUpDS7K6wkkKlX3sqrBLHpviZ+MdIBmAeVhMyo4PshulV4RpQgEoZoft6zDqpD/xzdYSLd9FzFivxLxTZvUcQps= 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=cMo+B+Rw; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D09Ysk016771; Tue, 13 Feb 2024 00:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=YEmwQFMFTsyU12bZ+DA3 QUirFGkywDIHtACo1YVzlzE=; b=cMo+B+RwHegcGoz4tQnlHJha5RGEQ9a1up1+ OoiXUrNejPJq1LmVXFOpaMer1pHmegIs2zTnT+xsOTrA2jfwM7AUahjOl7b+d3AG XtEz63s3BaqWsyl7mJ4LgCe+G4HkdFW4zU1/kLhyhyc9NOrjzF6BDRlmyDXTEQ36 eQmQMCSc1NyAfnMydeqQkbXcW40s5QKRQ1XXjm8EHh9+Gs6eqHyer7zUlOurpVL2 96CeWodMYtcslOYaP7jR6NRhW1WKlBCciH2yQWl73p2QUC2QND4JhawmgQXcvf+q Om/77+QpxnrvcIjcf+1xeLv1rFnguQD5D9fS427+YvFDcgQ36g== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sZr3016233 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 09/50] xhci: Decouple handling an event from checking for unhandled events Date: Mon, 12 Feb 2024 16:53:41 -0800 Message-ID: <20240213005422.3121-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: HRL5JZU_lawJd8PCleqpbovf1MB37d1r X-Proofpoint-ORIG-GUID: HRL5JZU_lawJd8PCleqpbovf1MB37d1r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=746 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745440499528096 X-GMAIL-MSGID: 1790745440499528096 From: Mathias Nyman Some sequences, will require traversing through the entire event ring without handling the event TRB. This is ideal for when secondary interrupters that are utilized by external entities need to clean up the interrupter's event rings during halting of the XHCI HCD. Signed-off-by: Mathias Nyman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-ring.c | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 293239d8fab0..6ef95f67970a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2912,25 +2912,18 @@ static int handle_tx_event(struct xhci_hcd *xhci, } /* - * This function handles all OS-owned events on the event ring. It may drop + * 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 changes). - * Returns >0 for "possibly more events to process" (caller should call again), - * otherwise 0 if done. In future, <0 returns should indicate error code. */ -static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) +static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter *ir, + union xhci_trb *event) { - union xhci_trb *event; u32 trb_type; - event = ir->event_ring->dequeue; - - if (!unhandled_event_trb(ir->event_ring)) - return 0; - trace_xhci_handle_event(ir->event_ring, &event->generic); /* - * Barrier between reading the TRB_CYCLE (valid) flag above and any + * Barrier between reading the TRB_CYCLE (valid) flag before, and any * speculative reads of the event's flags/data below. */ rmb(); @@ -2960,15 +2953,11 @@ static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) * to make sure a watchdog timer didn't mark the host as non-responsive. */ if (xhci->xhc_state & XHCI_STATE_DYING) { - xhci_dbg(xhci, "xHCI host dying, returning from " - "event handler.\n"); - return 0; + xhci_dbg(xhci, "xHCI host dying, returning from event handler.\n"); + return -ENODEV; } - /* Are there more items on the event ring? Caller will call us again to - * check. - */ - return 1; + return 0; } /* @@ -3018,9 +3007,14 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, } } +/* + * Handle all OS-owned events on an interrupter event ring. It may drop + * and reaquire xhci->lock between event processing. + */ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) { int event_loop = 0; + int err; u64 temp; xhci_clear_interrupt_pending(xhci, ir); @@ -3041,7 +3035,10 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir return -ENODEV; } - while (xhci_handle_event(xhci, ir) > 0) { + /* Process all OS owned event TRBs on this event ring */ + while (unhandled_event_trb(ir->event_ring)) { + err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); + /* * If half a segment of events have been handled in one go then * update ERDP, and force isoc trbs to interrupt more often @@ -3057,6 +3054,9 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir /* Update SW event ring dequeue pointer */ inc_deq(xhci, ir->event_ring); + + if (err) + break; } xhci_update_erst_dequeue(xhci, ir, true); From patchwork Tue Feb 13 00:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp277000dyb; Mon, 12 Feb 2024 17:54:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrR2aI4tD45bXwnNgz9xBrDnwSA+KAfh/fBp/aIhOTFbOSNNko9xKbxk2gtm0ykHHnBIHxq5FWUjO63r1tJtXsRJy6TQ== X-Google-Smtp-Source: AGHT+IFnDqN0wRCHDmHjZYRovh3tnTjoF3q7/zhNwDDSmO0uaMgnKPIcRUejAX0KxenaAfNtdtSF X-Received: by 2002:a05:6a00:2da0:b0:6e0:f2a6:abd8 with SMTP id fb32-20020a056a002da000b006e0f2a6abd8mr2295328pfb.34.1707789270946; Mon, 12 Feb 2024 17:54:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789270; cv=pass; d=google.com; s=arc-20160816; b=JH7fRYm7AseQx6IF3v9V7ZXyeyoKMsCXFDY6HDdV4XM80RNSVpgaNTFTqIVi5YHWH3 VLYyJh0HgO87dBhP+mSkbrH4+cpldQkfsc2jIfahJKWek2COmK4a1oIGxPUUqdPJLVJW U+lfOWUXSqMWXRFUQmp7EjsaPaY8bRWsShAjfH918q7oct+rAlOw9jMrh7Q4S6IItCO1 FDGeJdUMT3IzwoGCL9icCF0Xom9+KyW4NrViHOASxlnyQXwmVUK6T4uLp5Uq4G8Cc96Q XJXNAuPN3iDyIYcVMgNV37lQmkxKOuOigVdXVVWDixCDRAVuT21FLYNkcabsHYZnU9mW qinw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/sAK0l6KhmBr0wHjMWMWN+A9UguzYRdYNwmoexTrTrQ=; fh=RGJYrsr8ydg3bt6+3RGdcZhd7OWaQMOtSYzkrcFvTAA=; b=Jh/TDixz7UJp7FghSV9sjuSnq/s4n1I4lfGiIZUOagYDlnIReKM6+Ng8Op99jRaFap m0AYC7eRPUNqyfxJD5semI7iYMjivJGsCwzNDY0HQJeKmsAB6g+mD3jjS3bA9c0jVaIU +eMNAGL45FhCE0cuQBQVJMAYmDG6OvBD9WtpeUg6+tzJy1a8uC16OQzEQ/E2oHt1jEBO NnfYaZ6DCGZ24VnlHzBC/QabAfgIdKKG0gNnQ2eLjsaBFOisLZVWkJ2fLMgK3+flq4q1 27P3mP5eUFHkNV8opOk85MNTvCGyCQxJTFn/b5BjIcEfCrH+6q0BY3oeAAJ5YP2DwIWz musQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="HE/41sCi"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWu2/XJapqLNGv3Ks8qULMz4i7l5UsdSZj1lks3eM5jTzWYJxbUpN5+LreihdHZR+3nQVRou5scsbj3Jj352cOLpiXVnQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u17-20020a63b551000000b005cd90b47495si1117186pgo.264.2024.02.12.17.54.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:54:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="HE/41sCi"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62794-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0FFF2B28625 for ; Tue, 13 Feb 2024 01:32:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D79AD60BB6; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HE/41sCi" 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 C6FC336B17; Tue, 13 Feb 2024 00:54: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=1707785700; cv=none; b=M6lzthuNon8L+pLQVqB2ggo+RrPFaOTCAyoKpANtlANQJjPkbBRFDn2y0YJvDtgIiFVYGnAZ3D2ljGZI7jmVaya2QGbfiJ2TOWEOecawJOe+5ZtVCKOkz0u5jr89PqWaE2vJfWPrxoQZVMsELX/kyeMm4gO6cxDS9RSSTz8P0c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=RtzWV/1LJX88jylynkZkjLYqkeu4eisuZBnouYa2i2E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HGOCktKcG3lgF1lR3f25xV+gVWenGExodInC/cMsEj3Ah1kmhnuvBf+reRtwzFCe+Mg93SeUbEEuZODFKa00v4hOMf17LrLQB3bbOgppLgAgrvppTvJWzoEr45zGSFvgkv0IKFc5ICcpWPN0tkC8+Sv51vj3tQ6RqW1FiCMmkKo= 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=HE/41sCi; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CM42k2008671; Tue, 13 Feb 2024 00:54:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=/sAK0l6KhmBr0wHjMWMW N+A9UguzYRdYNwmoexTrTrQ=; b=HE/41sCir1aTc8S1HhSxoDlKIcEZZ6fSU/eH w1cRWhZKMaG+FK+y4sbvSoTBvik3v25I7IuFaMF4DAT8KDLhZFbfqA9DI4BGvoP8 kES0xNBDJA0yb/DXcl/x0/xikssKrFmD65ISJSyzM8I4Sg+svc3BPklZKgv/aTF1 FKEIZ3CHFrsaAWjXw9tsvaZJ+U9/mUNH+tnTtsZIOA0mSP+Q4tvSSV9R5vNB0ozm 9SGKnfDztX9kqhBiLBnY8JxuyWn8ci5kTau/kB5olBSkZnKfhyTJdNyinWa4czJX nL1rlcKwuPO4SO8ycd/bdkX1ys2RA6AXOXut8DNourw1HBtVRQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sZLX026779 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:35 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 10/50] xhci: add helper to stop endpoint and wait for completion Date: Mon, 12 Feb 2024 16:53:42 -0800 Message-ID: <20240213005422.3121-11-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: I6Z5lkvj98F16MKUXWt3jpR0IW8q8YFB X-Proofpoint-ORIG-GUID: I6Z5lkvj98F16MKUXWt3jpR0IW8q8YFB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746842581776149 X-GMAIL-MSGID: 1790746842581776149 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/clean up the current session. The stop endpoint command handler will also take care of cleaning up the ring. Modifications to repurpose the new API into existing stop endpoint sequences was implemented by Wesley Cheng. Signed-off-by: Mathias Nyman Co-developed-by: Wesley Cheng Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 62 ++++++++++++++++++++++++++++++----------- drivers/usb/host/xhci.h | 2 ++ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index b405b8236134..872ce8c1a5ba 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -2796,6 +2796,48 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, return -ENOMEM; } +/* + * Synchronous XHCI stop endpoint helper. Issues the stop endpoint command and + * waits for the command completion before returning. + */ +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 = xhci_alloc_command(xhci, true, gfp_flags); + if (!command) + return -ENOMEM; + + spin_lock_irqsave(&xhci->lock, flags); + ret = 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); + + ret = wait_for_completion_timeout(command->completion, msecs_to_jiffies(3000)); + if (!ret) + xhci_warn(xhci, "%s: Unable to stop endpoint.\n", + __func__); + + if (command->status == COMP_COMMAND_ABORTED || + command->status == COMP_COMMAND_RING_STOPPED) { + xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); + ret = -ETIME; + } +out: + xhci_free_command(xhci, command); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync); /* Issue a configure endpoint command or evaluate context command * and wait for it to finish. @@ -3119,7 +3161,7 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, struct xhci_virt_device *vdev; struct xhci_virt_ep *ep; struct xhci_input_control_ctx *ctrl_ctx; - struct xhci_command *stop_cmd, *cfg_cmd; + struct xhci_command *cfg_cmd; unsigned int ep_index; unsigned long flags; u32 ep_flag; @@ -3177,10 +3219,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, if (ep_flag == SLOT_FLAG || ep_flag == EP0_FLAG) return; - stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); - if (!stop_cmd) - return; - cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); if (!cfg_cmd) goto cleanup; @@ -3203,23 +3241,16 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, goto cleanup; } - err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, - ep_index, 0); + spin_unlock_irqrestore(&xhci->lock, flags); + + err = xhci_stop_endpoint_sync(xhci, ep, 0, GFP_NOWAIT); if (err < 0) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_free_command(xhci, cfg_cmd); xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", __func__, err); goto cleanup; } - xhci_ring_cmd_db(xhci); - spin_unlock_irqrestore(&xhci->lock, flags); - - wait_for_completion(stop_cmd->completion); - spin_lock_irqsave(&xhci->lock, flags); - /* config ep command clears toggle if add and drop ep flags are set */ ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); if (!ctrl_ctx) { @@ -3251,7 +3282,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, xhci_free_command(xhci, cfg_cmd); cleanup: - xhci_free_command(xhci, stop_cmd); spin_lock_irqsave(&xhci->lock, flags); if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 44e447fdad62..eaea676c85d2 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1919,6 +1919,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); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From patchwork Tue Feb 13 00:53:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268737dyb; Mon, 12 Feb 2024 17:28:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQW2F8a3KF5qYY4Gw/6EpLSHKzw+AB4FjP911Xt1RAnBzjNk4K+EPL+fkvzBHYEueptJjbUZU6i3oIB8d0DgCih9VioQ== X-Google-Smtp-Source: AGHT+IEJohE6lXx0p4u2hDfgb7dWMxIezzaw6Dih8TWdYAEPDXRPxMVuqLQBJjF+QAXMDRaEON1g X-Received: by 2002:a17:906:48c:b0:a35:2f7a:385b with SMTP id f12-20020a170906048c00b00a352f7a385bmr5597787eja.23.1707787699561; Mon, 12 Feb 2024 17:28:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787699; cv=pass; d=google.com; s=arc-20160816; b=JTpQZqvWHrW8kFlenNU+8QN5/WB0nypvxca1jXScm9GfbMmrUtvpqXEWhNyUznJzEy cnMszJ3SjZnlJJt6WT4xwheF1KjpfLm+9UpDPLpJiHbbpOF5gOJ7Wv/FWhFVh/STmYB2 VLKlxO1pHKxhdc4ZjHW2JCrLQpSrVof5loslJNSiNkoW1sJDhP5myNtoLvtCXpxm6S+V bq9bFMDLigf7IWfRXQHRvDd+r9Xc0y3yJadq9wzoqs4My9Xp1cBCXi7qlo56+Pp1nomS X8dJOh1Od9Wq88K43kAIXpJoY/S3/qRh0yE+fs7TEDI2NjmdZOu5Yzx3wGOnAgSfvSbM w90Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SG5fCDVTmpRgSZycQx3KEfThnpA6x5R39MnhiUzJey0=; fh=7xYP27z+sBtL6L/HG58unXW1Ono0fo6NUKZNwQ2zFtM=; b=itcvAZJFCgv9EtT9admKrmHcLQjqkuxybPNinYR21wbHmBPLVTCOHF4aG6+Ut3EdDo 166KT/gyFJzfmHv3NJp/71iM7rejVwxRpcGMt8n0HSop0DoMT+rD3PJKft19rezIeMsS S/D6HKCbXyHgALtgwSmWTOO2THTrK1x/robep2DUpyDkBxCHrcoYdKw+rphVSzNnSpR7 y8eW03mZ13UPavmIsTy4DeGcuLaoXYj+JwnpdsWIFj2JHYk/5iROXpm397VgJurQUdv4 A39fD7H62v4CFcf7SAUt6EvbvHTWbfYBp2e127IeRMNaZQAtKM8ClXyyr5b8+dRZBW3+ FJqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bsoKlUmZ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWtIJPPtsI48M9BgHeMGGXNHE16FHbjEXXsFr3p722QdmVfb6ZC3Q2C67v7hKU9YmjZqV+iv3ropU0m+lh3IXIT6Uverw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cb25-20020a170906a45900b00a38a0206c0esi739018ejb.633.2024.02.12.17.28.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:28:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bsoKlUmZ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2E2C01F28EF8 for ; Tue, 13 Feb 2024 01:28:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B69E5F54F; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="bsoKlUmZ" 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 B8B66225A4; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=SerdQRlG+t6hTfYhe3vkC8fHpOOTpZGa9+KUpu7ziZbweVdyeGW5wrs12qCfsZIWGQHRUAIds+F+WUYSzmLYMO91rnTFe2/mKyw/0CfpEZndhaUWnhZQmo9x9dCKa2C3qSfesspJ5+cQVz7neSiIPeKrlKs5HdsH4Yf3DVXyTTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=iy+moeOwHnE7dgEZhZINQgamHIdgTcysBEEcZ7EgGr0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D5F+YBNFLQx0kET3ZXbkp7KRuNOg4/HGrYrAN+Iqx3+sWiX8UE4A6E+7NbO6iYFn0AbhZdv+47d777GRDsOhwfTqrb42bI5l2LL2zjiBGSX1wR4TOSG3cYi/tOPAiuEE8O+X8qEXARz0U7j9ltX3oJg453hDGaFWB8qOOVYxHmo= 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=bsoKlUmZ; 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 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0PAna011684; Tue, 13 Feb 2024 00:54:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=SG5fCDVTmpRgSZycQx3K EfThnpA6x5R39MnhiUzJey0=; b=bsoKlUmZjt/S891Nyb1XM83g9r9lJzrogdJf I+ooPVuFjXanyrnYD4Ria/FkpN1diqgENzzlPYN8QnOZynce4gk24xBXDiggPYyT svnr2w1hjrFSIfTsm9nv1eH8DC0Ybm7MLrNKL3rH1VOyoWFKrmp3muIRL25Pflrr t2ODJG8HdgzZPJHDEtj1TNeL+/AY2Ep5/AWaGspRZx7aglgGbGp/HWtSUnf7rIwQ 2Q1wuVTUv3U7huLHhbvwMkH7aBqeVF4YFsF18J++Xxrlayf14XfAn+7RxI6+Ahmh R+RSZ8d+ehrCH57/LRIA5JuY4ae2pZUdxKeS88E48RWfaV7r/Q== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7nk91507-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0san6031126 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 11/50] usb: host: xhci: Export enable and disable interrupter APIs Date: Mon, 12 Feb 2024 16:53:43 -0800 Message-ID: <20240213005422.3121-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LCfdGDaDZiYhVHe7aTaewVdf5bQI7gFQ X-Proofpoint-ORIG-GUID: LCfdGDaDZiYhVHe7aTaewVdf5bQI7gFQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=531 impostorscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745194527535593 X-GMAIL-MSGID: 1790745194527535593 Secondary interrupters can be OS owned, so expose the enable and disable interrupter APIs, so that the interrupts can be configured as requested depending on the client. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 6 ++++-- drivers/usb/host/xhci.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 872ce8c1a5ba..834d8d160da4 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -320,7 +320,7 @@ static void xhci_zero_64b_regs(struct xhci_hcd *xhci) xhci_info(xhci, "Fault detected\n"); } -static int xhci_enable_interrupter(struct xhci_interrupter *ir) +int xhci_enable_interrupter(struct xhci_interrupter *ir) { u32 iman; @@ -332,8 +332,9 @@ static int xhci_enable_interrupter(struct xhci_interrupter *ir) return 0; } +EXPORT_SYMBOL_GPL(xhci_enable_interrupter); -static int xhci_disable_interrupter(struct xhci_interrupter *ir) +int xhci_disable_interrupter(struct xhci_interrupter *ir) { u32 iman; @@ -345,6 +346,7 @@ static int xhci_disable_interrupter(struct xhci_interrupter *ir) return 0; } +EXPORT_SYMBOL_GPL(xhci_disable_interrupter); /* interrupt moderation interval imod_interval in nanoseconds */ static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index eaea676c85d2..7c2481838f79 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1871,6 +1871,8 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_device *hdev, struct usb_tt *tt, gfp_t mem_flags); +int xhci_enable_interrupter(struct xhci_interrupter *ir); +int xhci_disable_interrupter(struct xhci_interrupter *ir); /* xHCI ring, segment, TRB, and TD functions */ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); From patchwork Tue Feb 13 00:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271653dyb; Mon, 12 Feb 2024 17:37:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU37ekB4QwSGCJu6aFUZIXbubkBD6uci7tpifOcZl689/ecRFLiTy8zc1OnKc2HPwCzi2zbY4Dosngf6TP+sWMpTmXgNQ== X-Google-Smtp-Source: AGHT+IFGTJe/efusfd0p2/curpoESxvSgvRbbLqTfmOLqLEIHkzhWdaOxyj/Dw/hSvQXqYgmQptv X-Received: by 2002:a05:6a00:84c:b0:6e0:3894:998f with SMTP id q12-20020a056a00084c00b006e03894998fmr2035453pfk.17.1707788249572; Mon, 12 Feb 2024 17:37:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788249; cv=pass; d=google.com; s=arc-20160816; b=nH/mBsCICkW7YiEqHEv9rdhq00TrC2bc03Ud8nl9BJo40eGcqb/0rbkV5BAwrnBiQ/ IxkggH8Uf1TTCAf5hzAhWJGQzx7VRlZLIqHwSd5w1krs26sKOqwqIdrTNveJYykcJ/6l 0ANuGQa8rEbeFg7DGxw2g5HDr8q3Lpn6+ROs2fYbZ1dil5XGdOIRpBa3cmEs5mOHa2Db MCjmwJfjSmTzB6IKoV539w+pAr/fiBXb7SCHWhNMRYU8phk+yBJyusshih0ZAz8sz9dR GPeWKbokg5DAe64U7nwMSuvHZLZ7gJNCbp+I6ypoXh7k6TvzS/fbtReBGZGOf1pAL5qh 6s1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xzOBrfDY1od+4Hb15JRtAcSYTxJyZa8TNxYwb0Lo8t0=; fh=Toarj2zsimOyZrz2I3rIcsG53nyXGc4veCFBRF02gcA=; b=NPf96le3l+lSte8CNtZqgQ9Fg7cq+RCweHOkct84ET+pvnfaA/0t55ztOlLy2a98VI jjgX6EdxQd/BwIIp7zAY6krjhDtuSTgsfS0Jq3sTwlaCpsvPmHxgal8bf2xaALN6uNUy aL8L+D5mWvkXxdSsNpbf52qm5yoXmZpCZoQf77WicardnyMLNG2JN5ZTeWv4a/mLQew/ CLqBR/aGdTsViBa3WuwhNYowouOdNTAtSe7jfEHa8L6eSCtYmu/+Ie3YZMojiShR6Hzc asLLkFY2j7q6QUTkm8VB2oA/2xSzl+FCqd3lr1BvSdADJeZDH4dn5BoXMRq+YT9Et5zs bnsw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TPUSE0WI; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62789-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62789-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUtUpb4BybkCezV3Vnzfhth+b5K3zHWjfxc9MmXgUZJi8JC/CwMrNRGN4D7PRvYbAMVafVAQJ2k3UaTIxXrdRttwG2z2w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g9-20020a63dd49000000b005dc82dd7342si465656pgj.740.2024.02.12.17.37.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:37:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62789-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TPUSE0WI; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62789-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62789-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0D96028BAEB for ; Tue, 13 Feb 2024 01:28:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B9335F85D; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TPUSE0WI" 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 55667224C7; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=lZj8fdekTimn0P2xkSk/BmqhQYXti8zeaCe8anPg7mzlmmF5nvbJlXpqiYD2uZX2LP9l4tq5ApkPlbhRaEAicpsB/ViFoGIvaC/frz5VaJAfaNAZuWhEBbQ3feTkUBgVAuw6K1ILsW7qGp+2TO5o6XP37lc+r53VKaq5kENH754= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=4wdCwc+iVxrd0/Vexs840M3pCv76BsAs/d8m7vV44Kw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hr0Nkcq7JoJ4MlG3mOEU8F8tkUbvLFnI+shqITfezMmiAGa8EOad3w3IgMFgmpNvyt77s3n/1NualqizmKELBM5qcmI03OiEOOo0X0g4o6cQTfka/imVKUHI/qaXbq2+G8qzF8MJ7NDcp3OD5IMS6/WFDa6xvAyoxD/dc9qML1c= 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=TPUSE0WI; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CNmAVJ032703; Tue, 13 Feb 2024 00:54:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=xzOBrfDY1od+4Hb15JRt AcSYTxJyZa8TNxYwb0Lo8t0=; b=TPUSE0WI4YCX+/9t7JvM4xrbaNVSJnBlRSfR Eqv+DY+9d+B3HgzHS/18964GGnmYPMzyMX14Ywx/nEgOpsZcSZevHKoWyPIpUAke 09sfpCx/5Md/iYi3dOD314jY8It7kQId9ShkizvhC4FQMsO/wMN7w8QXrSVsTHH+ Nt4dW7eTKw6/FX7mSa9Gw1sv3PpG+k3mxbYlBOqmtq/QKgjiDw8zgoAC6wWFzurw gljEdF+meavH1TsWTJIsVISuySzIQr4Hj6zwF2izncxlfbu489ZL/I5YI8cxgSef AOYvmsw/QT02mBghueGDzc6HyI1R19R7hEcyG1cdpekeqaexGA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0saW2026782 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:35 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 12/50] usb: host: xhci: Repurpose event handler for skipping interrupter events Date: Mon, 12 Feb 2024 16:53:44 -0800 Message-ID: <20240213005422.3121-13-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: V02w5S8oxe2qZYGWjB73fFRf533jXXxf X-Proofpoint-GUID: V02w5S8oxe2qZYGWjB73fFRf533jXXxf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=809 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745771423977915 X-GMAIL-MSGID: 1790745771423977915 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 6ef95f67970a..958d6fd6d156 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2912,14 +2912,22 @@ static int handle_tx_event(struct xhci_hcd *xhci, } /* - * 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 changes). + * 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_interrupter *ir, union xhci_trb *event) { u32 trb_type; + /* + * 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); /* @@ -3008,8 +3016,9 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci, } /* - * 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 pending events + * for non OS owned interrupter event ring. It may drop and reaquire xhci->lock + * between event processing. */ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7c2481838f79..ad9d93c645ad 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1432,6 +1432,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 patchwork Tue Feb 13 00:53:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270033dyb; Mon, 12 Feb 2024 17:32:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfIsRjJQ0FdBIJkob2y065pp6HKs5Me4Dk+6skXslW4TyhPlXTts/Y/cVV8p9e8yNJqq+WQqyABC9Ngz7mOby5LUzHCw== X-Google-Smtp-Source: AGHT+IE+JiSZOF3d3Ha64H8AfgnCImFDTbSLNDf5xY8V+y+RkSLGZu+uqah5uTp0H+2b2exGH814 X-Received: by 2002:a05:620a:562f:b0:785:bff7:d001 with SMTP id vv15-20020a05620a562f00b00785bff7d001mr8150501qkn.27.1707787940223; Mon, 12 Feb 2024 17:32:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787940; cv=pass; d=google.com; s=arc-20160816; b=ritsbWZdY28yYm0uQpdox2ZYc0JjIsl1/4cUwDm8zEjlBAnUu9NUnwTKjdy65/MHf5 VJulz5pencRcnWO+4KR9uRC6CSGHynN4JYG9bVIzwz8stXwMQph/r6gN61UmkKk+FCoH 5ePUKBNLBMK0tbuDMh/a7FpYvHt0MdTFpSMleScHQYbhB3vlP2/SO+ryNDX+y9bGGSHR LsVi6WtFRddfGj9uWLzIBH8/NKRLb91VmxJtGP8fDtnhCduetTVTTv9n/pcYRV0Oa8DX bQ2UFEZGBx52qHN27tY4YlA7UdPxGQD23Wpt6/57ww96STZnkM1vPNZVODgCE9iCKnWF BljQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LylXK/jrWURWDhUw7tH5hZ4ow+Xl5FX/mchvOMoIBg8=; fh=r4DRVa1E/a7uVrE02QsSwHLVWqtaVl9GyXVC+qvF/H8=; b=ACaubBOusbWIuEB/1b+sv6o/d29WUWzcZpTzFGYhET0M1HBp/WmEV1tOAjKuokzjo3 Ofbdm5i0O6Q3syexEOksYi/VeqRADfxzq3F5ZSmhcJhWMi3y+au8HDo940+H3929MdzM 86NW4r6d/jvngaICdXnitqWVjec7dbG6ln5mH6EsraBrB179pbvoFSjwIqQHsoiZZERx SUIJWr1ibJ79KrbqrnEIjYIEc9MXPRqz/n6MAWSAaQV7Ypseh2sHzqcDdKVoawEc5Sf5 mnGf83zV6o+K5YkR64zL++1CYOdhjw8M63ymd8BLV4vqR7tErZL411QXxpb0p468+9i0 MHaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CWHvJxFW; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62795-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62795-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUfmlhAu9XiO6tcWEcHvPu2/PSKA+MwAd0tdRjEueZZ3g2nRYtlYLJ8HVEGtHGe7wl1Z5E3ko/gvVUPC4XccOMPAtfrtA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r14-20020a05620a03ce00b007853c7fd7a6si7381882qkm.602.2024.02.12.17.32.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62795-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CWHvJxFW; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62795-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62795-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E80921C2451F for ; Tue, 13 Feb 2024 01:32:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8256160B99; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="CWHvJxFW" 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 C701536B1A; Tue, 13 Feb 2024 00:54: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=1707785700; cv=none; b=kdycZ/UUQf+y6hC9b+/96JdMrhIe7XfFlg8ciWWktki1purmepyxKzl3b8i4l2E7PKNP0sGcFkaV3ApTKg9lmHMG3OBMWV2KMGRwYOeEsaZjxsLZt/Rhx4+Nuc3thegFT92IFY++AhsQpGVy+mKN2HGmh4/REN6O9Ud+eod8Y5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785700; c=relaxed/simple; bh=CtxumE9xy8E75NV5EAWv+2S2i06ql2rIZ/FBzOnULFc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EHoXf+mvpQezWPTnP+Mk/bW/U9rXSZJS1Dv/Olor064WU2o/dJddVj4bQhFITpfmE7ZQ+UUEXVQYo3KxdaF5AHXHT5r8BXnomlGJ7+MwrnRxBanZXprEwYFmzyrU05a/8DGZtojWM0eS7uBP1lxgPl+EpHIhWHmcQ8QXYOzeMig= 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=CWHvJxFW; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0daLI010592; Tue, 13 Feb 2024 00:54:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=LylXK/jrWURWDhUw7tH5 hZ4ow+Xl5FX/mchvOMoIBg8=; b=CWHvJxFW3CG7Nq5F+/gjuZcjGEIUfigycJL6 gkpwBQCQS3C2GF/T4XrCwbCESRxKGmvkK3VeD188YiLkFsxECEy06e84AT+LBlEe ACaCpdRxOQDNXKMUYuPmVynXBvQrDFy2IvgenLm1veQFFHXLA5fIMFI2V+L9o8EJ j+Sohik82jvfleeRVUG3VwTsJ0wuhzXNjBGNNMEPYwqjOcDVr0gyA6wYScuqRcdk nTE4n1Vf3nqoyqoZypAHtzOjj9+BnTXs/nIVZjZVYwrW+JOjzqzIMjCxraTEpa68 OrKy6sgLkig1k/jNxwFeKp5jr+GZn4tfZqP4nHhCovxod4tOig== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tyc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0saRO029979 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 13/50] xhci: export XHCI IMOD setting helper for interrupters Date: Mon, 12 Feb 2024 16:53:45 -0800 Message-ID: <20240213005422.3121-14-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: sBt5247R1FsB-HUETT6fcEINd9m01l8C X-Proofpoint-ORIG-GUID: sBt5247R1FsB-HUETT6fcEINd9m01l8C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=642 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745446822030526 X-GMAIL-MSGID: 1790745446822030526 Utilize the xhci_set_interrupter_moderation() API to set the IMOD value for interrupters, so that secondary interrupts can also configure this parameter when clients request for it. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci.c | 3 ++- drivers/usb/host/xhci.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 834d8d160da4..d2ce1e1421e6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -349,7 +349,7 @@ int xhci_disable_interrupter(struct xhci_interrupter *ir) EXPORT_SYMBOL_GPL(xhci_disable_interrupter); /* interrupt moderation interval imod_interval in nanoseconds */ -static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, +int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, u32 imod_interval) { u32 imod; @@ -364,6 +364,7 @@ static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, return 0; } +EXPORT_SYMBOL_GPL(xhci_set_interrupter_moderation); static void compliance_mode_recovery(struct timer_list *t) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index ad9d93c645ad..d88d2f67e3ed 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1874,6 +1874,8 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci, struct usb_tt *tt, gfp_t mem_flags); int xhci_enable_interrupter(struct xhci_interrupter *ir); int xhci_disable_interrupter(struct xhci_interrupter *ir); +int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, + u32 imod_interval); /* xHCI ring, segment, TRB, and TD functions */ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); From patchwork Tue Feb 13 00:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271639dyb; Mon, 12 Feb 2024 17:37:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8xVUejztyxfdq16RinR/gLqPEcb+4wRc/g8tmC1pZVTVDHBO2+H9z2h5I7zBOID2nN+Aq X-Received: by 2002:aa7:d504:0:b0:561:f109:119f with SMTP id y4-20020aa7d504000000b00561f109119fmr358704edq.20.1707788247040; Mon, 12 Feb 2024 17:37:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788247; cv=pass; d=google.com; s=arc-20160816; b=xcbkyr+D34bKjRVAihWTRSag9ShAzIMrsFmgj1LegXVx3k1p9gJJZqaepSENyq0Zrw cGP+OE+infsH40dBoEkk2fyAy3XRmIgt5BslA4HMC+LiTcrb345xIw0oe2v2gwFqywzl ftOi5ztnlf5Aq+b96AoRJkdroCRrl/ZbDhNUAr6MrNSTl0ODjZKM3/UgxgmzoFyMtZZP iJR2hLE/SDGOybIRt6CO3FUU70g7U2QX4lZ8Y0dweh1unL+FGktUBx0iAg9JUVKxX6Qg vnwON8cGKCRprZY0dkJ+JXREkMFTk4VT0bW4gUkKEYm6aObotcPkt+TSi9CZXYHYeMv0 s8TQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=50UuqEOq3NLSs/uMCQKrFMc8INX/zShWCNWXqieQSUE=; fh=GmF9mL58JCGB8e0JRiHyLw/5hiWywihcbQMgjwtq9S0=; b=TEbwVv6CzVTykkCxuTtS+rHUnmGzC2X+a2LJ3Qt0lTomGpluAOJaxH+EuzIXOAyvOP XV7CYsuGYFHZ2bT9su/LkdtESq/hbSJ1XKWk/cYWDVYtyIb0yVQszBVDYuG+YQmHv7LS Rlibp2xEBgm5BNFgQP2CKttOH2RA/YivurfCY/b+c0Da5hcacjqJQ1WFUqvCwNHXxuBV lZ2ZqE91KTJunC9TKljnAjEfrJbNoCy4sM/ChK5+bSQ4QWxxazsOLAD4nsPDHqSKdm5x PvKkxdYOxE7/xZkxDDMJG8m61VA6KB0GNqtM8odfLf489xaS4lQLRKrRAJS49i5JhJ8z IrRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AQB15tyj; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWWr1cyCcwMLLH/BzvAbdBPuuyum+rjj3J4yg/td96eJd/UHexOmVLDmW+EJQNmDWq6crsfuQIO79X6QfdjOpDlsJON9w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z9-20020a05640240c900b0056148c79709si3353918edb.85.2024.02.12.17.37.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:37:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AQB15tyj; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7ABC41F216EB for ; Tue, 13 Feb 2024 01:37:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3095064A98; Tue, 13 Feb 2024 00:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AQB15tyj" 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 9B5485A78D; Tue, 13 Feb 2024 00:55:08 +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=1707785711; cv=none; b=Vq08P358bwqdpTjk+a2uW9CjHyJZbYfqidcAur17nu3MtvHRv/f4JpqMW6+Fg4D4ttfBpyqmoAyXh18LwZY+oyrI8w8AIsiRlmIvuzTFePXwJm9FvwcNRRt6bDt0668gTsIAzkwzoTBrPX9k+OePK16bWDErzFUSTr6FKpAv//A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785711; c=relaxed/simple; bh=RIz5asIzQ/wZ+uW2BObO8Z7X28TbO66VJNASNcekf2w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QnJM+5eUjejORJ5uiF2ag3ENklBvVG1xta77NY5Pfdb/fR+TIbKnoV11j+CvsPO7gClZzAWbsNM6Szljh56LSDx9G3WL5r2B9yHsqsec+C8jSGEKBZWwpAOEQNvfvE6X7blBYdrTv+y8tGdH3Bd9UFmU8zBzfjQ0LbOYh80Dp2o= 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=AQB15tyj; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0qlpB012880; Tue, 13 Feb 2024 00:54:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=50UuqEOq3NLSs/uMCQKr FMc8INX/zShWCNWXqieQSUE=; b=AQB15tyjMMDgCkH/g2dzGM2LW5p8ogJykDoO sk8vuNiC68+9ckOdyIkHs0+VsUjgeXrVzCLHa+PmpDUfB0bmIa4dj/SKv5Jrfn01 P+hbdphBvU9YgHTtvLTkCmGsmUBkOB8M67NsWa4cqY/AIZK8CAFfCVXBu+KBz8rm 67Yxa51a/flzpeUOFJelPy7aZZVPvagCxbdJxtcDqvdHkoCqomD4oJj7vUYmLBsV 8Uvq10bem9OqhlHsYBUxc2p+Fvp27+U2s9XhSv7n13BI16E/kNut8igiAghoZej8 lR8NHZZrf8REVsEiGg+qkc27tlMFuylVcvXeI8CIZLbCfPYfow== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0saYk031056 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:36 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v15 14/50] xhci: sideband: add initial api to register a sideband entity Date: Mon, 12 Feb 2024 16:53:46 -0800 Message-ID: <20240213005422.3121-15-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: TeWytGQVaFyXuPunLTrYFBRnGmF5sNRP X-Proofpoint-ORIG-GUID: TeWytGQVaFyXuPunLTrYFBRnGmF5sNRP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745768787682252 X-GMAIL-MSGID: 1790745768787682252 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 compliation 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 | 411 ++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 4 + include/linux/usb/xhci-sideband.h | 68 +++++ 5 files changed, 494 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..6135603c5dc4 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. +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 += xhci-rcar.o xhci-rcar-hcd-$(CONFIG_USB_XHCI_RZV2M) += xhci-rzv2m.o +obj-$(CONFIG_USB_XHCI_SIDEBAND) += xhci-sideband.o + obj-$(CONFIG_USB_PCI) += pci-quirks.o obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c new file mode 100644 index 000000000000..0944bf31d772 --- /dev/null +++ b/drivers/usb/host/xhci-sideband.c @@ -0,0 +1,411 @@ +// 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 = xhci_to_hcd(sb->xhci)->self.sysdev; + sz = ring->num_segs * TRB_SEGMENT_SIZE; + n_pages = PAGE_ALIGN(sz) >> PAGE_SHIFT; + pages = kvmalloc_array(n_pages, sizeof(struct page *), GFP_KERNEL); + if (!pages) + return NULL; + + sgt = kzalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!sgt) { + kvfree(pages); + return NULL; + } + + seg = ring->first_seg; + /* + * 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 = 0; i < ring->num_segs; i++) { + dma_get_sgtable(dev, sgt, seg->trbs, seg->dma, + TRB_SEGMENT_SIZE); + pages[i] = sg_page(sgt->sgl); + sg_free_table(sgt); + seg = seg->next; + } + + if (sg_alloc_table_from_pages(sgt, pages, n_pages, 0, sz, GFP_KERNEL)) { + kvfree(pages); + kfree(sgt); + + return NULL; + } + /* + * 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) = ring->first_seg->dma; + + return sgt; +} + +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 = NULL; + sb->eps[ep->ep_index] = 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 transfer + * 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 = xhci_get_endpoint_index(&host_ep->desc); + ep = &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 = sb; + sb->eps[ep_index] = ep; + mutex_unlock(&sb->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_add_endpoint); + +/** + * xhci_sideband_remove_endpoint - remove endpoint from sideband access list + * @sb: sideband instance for this usb device + * @host_ep: usb host endpoint + * + * Removes an endpoint from the list of sideband accessed endpoints for this usb + * device. + * sideband client should no longer touch the endpoint transfer buffer after + * 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 = xhci_get_endpoint_index(&host_ep->desc); + ep = sb->eps[ep_index]; + + if (!ep || !ep->sideband) { + 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 = xhci_get_endpoint_index(&host_ep->desc); + ep = sb->eps[ep_index]; + + if (!ep || ep->sideband != 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 address + * @sb: sideband instance for this usb device + * @host_ep: usb host endpoint + * + * Returns the address of the endpoint buffer where xHC controller reads queued + * transfer TRBs from. This is the starting address of the ringbuffer where 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 = xhci_get_endpoint_index(&host_ep->desc); + ep = sb->eps[ep_index]; + + if (!ep) + 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 sideband + * @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 interrupters + * event ring by setting the 'Interrupter Target' field correctly when queueing + * the transfer TRBs. + * Once this interrupter is created the interrupter target ID can be obtained + * 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 = 0; + + if (!sb) + return -ENODEV; + + mutex_lock(&sb->mutex); + if (sb->ir) { + ret = -EBUSY; + goto out; + } + + sb->ir = xhci_create_secondary_interrupter(xhci_to_hcd(sb->xhci), + num_seg); + if (!sb->ir) { + ret = -ENOMEM; + goto out; + } + + sb->ir->ip_autoclear = ip_autoclear; + +out: + mutex_unlock(&sb->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_create_interrupter); + +/** + * xhci_sideband_remove_interrupter - remove the interrupter from a sideband + * @sb: sideband instance for this usb device + * + * Removes a registered interrupt for a sideband. This would allow for other + * 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 = 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 transfer TRBs + * it queues on the endpoints transfer ring to ensure transfer completion event + * are written by xHC to the correct interrupter event ring. + * + * Returns interrupter id on success, negative error 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 otherwise. + */ +struct xhci_sideband * +xhci_sideband_register(struct usb_device *udev) +{ + struct usb_hcd *hcd = bus_to_hcd(udev->bus); + struct xhci_hcd *xhci = 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 = 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 = 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 = xhci; + sb->vdev = vdev; + vdev->sideband = 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 = sb->xhci; + int i; + + mutex_lock(&sb->mutex); + for (i = 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 = NULL; + sb->vdev->sideband = NULL; + spin_unlock_irq(&xhci->lock); + + kfree(sb); +} +EXPORT_SYMBOL_GPL(xhci_sideband_unregister); +MODULE_LICENSE("GPL"); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index d88d2f67e3ed..0a4d9449bdff 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; }; enum xhci_overhead_type { @@ -756,6 +758,8 @@ struct xhci_virt_device { u16 current_mel; /* Used for the debugfs interfaces. */ void *debugfs_private; + /* set if this device is registered for sideband access */ + struct xhci_sideband *sideband; }; /* diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sideband.h new file mode 100644 index 000000000000..1035dae43cee --- /dev/null +++ b/include/linux/usb/xhci-sideband.h @@ -0,0 +1,68 @@ +/* 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 /* FIMXME 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 + * + * FIXME usb device accessed via sideband Keeping track of sideband accessed 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; + 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 patchwork Tue Feb 13 00:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp277486dyb; Mon, 12 Feb 2024 17:55:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbHaa88ySO5Rlos4qs8hR/FUBkNkAkKD1tGkMdQ07YFdcjqwc5SLTyb2QOScsyaSyctj4nHcJ+wVIV7mOlACqreQzBVw== X-Google-Smtp-Source: AGHT+IH4EtIuEIPjbGQROw5UATt/518DDDvAitQcCGbzVWhmtpFCLSgxPDEx6I//EzxDW9BHlHhk X-Received: by 2002:a05:6a00:1d1f:b0:6dd:b12f:c394 with SMTP id a31-20020a056a001d1f00b006ddb12fc394mr8755180pfx.32.1707789349476; Mon, 12 Feb 2024 17:55:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789349; cv=pass; d=google.com; s=arc-20160816; b=OLFiGbds07lKA+TnZR1Pjt1xkykMo68tLHh3wSbdGE0Cd9riqL8Hvwkt3TJVQzdqKx Wr+6fEohUlawIHu1CtnMO4W/DbZ+/zjq6rDt8LIVDQRq3kaQQaiiBOpfFe1kgJE8RXUJ zd5zQe9nv2SQTdOLgnGkZxG6sTos1VLus0uprFlh9qmdvhEmWjjD7+QFA0jIR19OjOJb 3zZ2NUkMs9hhXChTAsefR76ZXNL5zK3QibU6AjmnWBliV9PmQApSlVlv2ZoFxurkLFGY HMlC0e+OnMBCL0GIAvVy5sfXe5BagJ9rPCIAfci1WIbl96xr/PLYyMAXuJWeZ2vtuhzC L1xg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=R0hg4dDBYEp27ZuNyVb3W+iuKNUNsrbwtnpJmQVwa24=; fh=WmBE89YPNg/hsXXLLT9e6Pye5BlrM1ZwtlgEWhCypx4=; b=TAhXgnlU6iooraJO92jh2id6ZLXScCGDCViR1V/7JVWaPD8R/6/a7mQZBpPiveVZTR aeSq2heURwk9/4nQS3mDIMlhd63dFFgtVdOk6yBuPlvUgT7X2v4uihU4R5VYjLnMHoZt 0SCceZZ0Q3L4s1YrqlrzCy/Fhl3S3sOxLAuRVhOW3IBz64tDDm728Y8qfS2qSEBTWAJi mymq22gkGb/L4rWwOE+/spOyj4KPt6lMPmdJXbyuua34XVccLbTGaI7f81miKyQ6OvmZ XNPyfaMZup4dKM6Zv7oZL+52IIhVfZnXwMKIQBUdmmu77UV5I9h8dIfu3vMJyi7o/3eJ LWbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gyWEjAxU; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62808-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62808-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXJ8Ngceab2z5DANJodN6qu4XhydxJE2x2iIyISMcg04Cyjz+lA4V9BRrOZgv+w5sgftmRx8reDL0S9260iONHPDXGIHw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s18-20020a632c12000000b005dc816b234esi591660pgs.629.2024.02.12.17.55.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:55:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62808-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gyWEjAxU; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62808-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62808-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E3073B29030 for ; Tue, 13 Feb 2024 01:33:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6F52612E1; Tue, 13 Feb 2024 00:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gyWEjAxU" 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 C2BE454BE2; Tue, 13 Feb 2024 00:55:02 +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=1707785705; cv=none; b=l048mTQvFSKXQ4jKis2XDItmMP7BAw7paysfK3c6Ag7nn4LE6+vepvR0HnP6qrI+K2GdkHmbMskEmBLtkDMA6coE8Vs4RZK8Skd2/7Vl50+QZzTd4f5UiogMZYd9rAaPR//zVUxO5p5EcYIbM+rd7pFPdBJJAeb7kw5iGKZ2y7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785705; c=relaxed/simple; bh=SI/xXqTaKb918srbROgcUJ5EMq0uUfJ689ErJLs6vMk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gy0iWP0n5L7CrQ1MVPOGFRRbyShgZic1lmptrCV+P2HGOZJULD46hF9p67VGbPdch1JERrdKkyfakqilw4shgDIaSbsbnwNYTTw/gLpwZsNNN1cjnp5pHdTluEi3cLK8C7YYKE6EvDx8/f5kGPRHZ/EDqXOo4sCMNbQoOYwB5Os= 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=gyWEjAxU; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D002B0017050; Tue, 13 Feb 2024 00:54:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=R0hg4dDBYEp27ZuNyVb3 W+iuKNUNsrbwtnpJmQVwa24=; b=gyWEjAxUxfjE28ELnc2nphgXw5fLCaxIoyWO L5yEAfmpOqbTg542e685EdgHm1tT1SMtS8rpnlDwJ9Q0YxPm67mBEnvMEcGPYwjD txtlEC1MM60SFajaGafLBSMGFa7C0pKLQ4cBR4yrWbC4ja+aicNp5qO/3yjTusGj lhbRtka4vxDZlP5V2X/QVJZ04w9ikuIwi7UrHK5jdTxCIK2GiBTtuDcJoX2JZuWj icof0GbhCo4xlNKwi+PP5Pi28USaMwYG0NL0CY6ElU5KcqozfgwjGy4ymi32PlVC olhy5ga+O8QFJVAdgwlkHVDlQPReGcPCFlAK+Eu1dW/0sEKAug== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7wfy82j0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sbYL029987 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 15/50] usb: host: xhci-sideband: Expose a sideband interrupter enable API Date: Mon, 12 Feb 2024 16:53:47 -0800 Message-ID: <20240213005422.3121-16-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: a8HfLKfBN23BQzYO1k_H5hYGXR5GjD5f X-Proofpoint-ORIG-GUID: a8HfLKfBN23BQzYO1k_H5hYGXR5GjD5f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=863 priorityscore=1501 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746925047505270 X-GMAIL-MSGID: 1790746925047505270 Some use cases maybe require that the secondary interrupter's events to be handled by the OS. In this case, configure the IMOD and the skip_events property to enable the interrupter's events. By default, assume that the secondary interrupter doesn't want to enable OS event handling. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-sideband.c | 28 ++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c index 0944bf31d772..504a6f1586b5 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -237,6 +237,30 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); +/** + * xhci_sideband_enable_interrupt - enable interrupt for secondary interrupter + * @sb: sideband instance for this usb device + * @imod_interval: number of event ring segments to allocate + * + * Enables OS owned event handling for a particular interrupter if client + * requests for it. In addition, set the IMOD interval for this particular + * interrupter. + * + * Returns 0 on success, negative error otherwise + */ +int xhci_sideband_enable_interrupt(struct xhci_sideband *sb, u32 imod_interval) +{ + if (!sb || !sb->ir) + return -ENODEV; + + xhci_set_interrupter_moderation(sb->ir, imod_interval); + sb->ir->skip_events = false; + xhci_enable_interrupter(sb->ir); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_enable_interrupt); + /** * xhci_sideband_create_interrupter - creates a new interrupter for this sideband * @sb: sideband instance for this usb device @@ -275,6 +299,8 @@ xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, } sb->ir->ip_autoclear = ip_autoclear; + /* skip events for secondary interrupters by default */ + sb->ir->skip_events = true; out: mutex_unlock(&sb->mutex); @@ -297,6 +323,8 @@ xhci_sideband_remove_interrupter(struct xhci_sideband *sb) return; mutex_lock(&sb->mutex); + if (!sb->ir->skip_events) + xhci_disable_interrupter(sb->ir); xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); sb->ir = NULL; diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sideband.h index 1035dae43cee..a749ae307ba7 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -54,6 +54,8 @@ xhci_sideband_get_endpoint_buffer(struct xhci_sideband *sb, struct sg_table * xhci_sideband_get_event_buffer(struct xhci_sideband *sb); +int xhci_sideband_enable_interrupt(struct xhci_sideband *sb, u32 imod_interval); + int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, bool ip_autoclear); From patchwork Tue Feb 13 00:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270512dyb; Mon, 12 Feb 2024 17:33:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVulJzkr+/e/8tBozGGRwtI+QbpSNZ3YM8RY6BvsVpgldaTG4RPto95Gvf6rW0dcw5BOBzP1rtcBHNfxraA/c/0OyXGeg== X-Google-Smtp-Source: AGHT+IH3pAVGKBwVIDow3zF0daFLzHrg3Q8UBO99ApZFWP2W5O/a6XZBdIczOH1nf8AeeaZTBzNj X-Received: by 2002:a05:6e02:106c:b0:363:b1e7:ed18 with SMTP id q12-20020a056e02106c00b00363b1e7ed18mr9299979ilj.16.1707788022962; Mon, 12 Feb 2024 17:33:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788022; cv=pass; d=google.com; s=arc-20160816; b=LKU4cZTKroqFZhllo9cfev5WW0xN8wXuzotpTMCn5AjqBE0ICfAmba9Ey6s8XWItgy LoGguvd6jruYRdLmLjG4JI4teBJaSWVjMw+RoSLRqBfoPV2t/FzshGR1kMiIPI8aFx+F Gj2BDDvbDauJaJQKfweCdg2rd42q1CDAebH6f6GwsBN3kVrDdIRCqkVpgyAmT8//JFo2 m2cPyTtnIp9F32Ld5nOOc5hdPAVzUZXba/FnMYKQlXibbyKY/YmCcqU+a4M2rOTY75mZ 4NmeviHWpUYqdDjr44Pl9X5+kX4weCfIGqCzQeuROs5bp1M4TmQQL3q2YTergJeyqVVq fExg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A01XTM6TgZIHSNlPTXk1gGSavEdxcNtrzNIQOSevhfM=; fh=sZlk3vWBxEEbqXpNMJdeCL3KXP3z/ZzJPTyHsYcL4GM=; b=eLaTeTMK1MhG9R+snGL2ZNKuT06nFtJbh0yjUlcPDUqV1RQFJIDM1zvTsk27CFQ48L x1T/L/pAYu11rGhtxNyz1EBFcbK8aE63nuIaOIthQwkgBGRrFnlHhjob/4S4DeAQRr0F 3jLcpbcvybpl7igULbfa6jlCA+ut/5VLdGdSmGvCGsj9MRMRgbrcIyKpEQO1tOa7RocF m4qkZguid/mVhRmNH5Fj66QAvxtVygEscmgSOpy7r7qbrT4mOskx7WbbpF/a0hkZwMs/ MWqDJl5hA7xZluGNAP+pkFSX7isuGDwBVD+pTw8EexjYl0Fp43esIp+ggLb8/Hj/zyCg i6FQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DSWnC7Cl; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62804-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62804-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVuo8bx8X/Y8GhNOKLF+5njJV0hKEoOwPVni2ByOTcN0/VAxMTwV5ImQnw8zP8w7pPykNHvD5Hsxl7djq9y2ehfv9jRiw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m187-20020a6326c4000000b005cdfb08b91asi1066583pgm.796.2024.02.12.17.33.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62804-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DSWnC7Cl; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62804-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62804-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B21F928C716 for ; Tue, 13 Feb 2024 01:33:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C561B612E0; Tue, 13 Feb 2024 00:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="DSWnC7Cl" 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 709C85465B; Tue, 13 Feb 2024 00:55: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=1707785704; cv=none; b=WLw4aFb+IQrO+v8dUdylOHd0v+ijtMTz4qss9fT2Apd1RfvdQkgOPU8tQw1KoKt770NVl4bojdAS/87OH05RJLE0zqHMCrxFIpj5LCcEjo3dZ7hUgTQYaRvNc2R23g/Z2ihaJze6ailKvFkYGnXmQId1jhXqSX/MOW6ah7qP0I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785704; c=relaxed/simple; bh=tNQSlvKoWgbkhbz1r67WQZ6Cx+rn2Vw4a4260C31m90=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cplVVgqTecde2mfwQX4+XCv9Oliq6C/N0ukdWnt1dLQ2Nq/i9syeWX+OBBfmiSYZD44b/xr0lSuJw/BN15iTr/9pAP4gx4PSArz5EvbjptgFpvJqH+W2x1rML1qBcLcxR9C0vxl40n32eyJ+yqQDirkJhWRTCS4MHQC+Kbjb6Ao= 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=DSWnC7Cl; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0Ef1m032709; Tue, 13 Feb 2024 00:54:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=A01XTM6TgZIHSNlPTXk1 gGSavEdxcNtrzNIQOSevhfM=; b=DSWnC7ClTRJcdsIBYRZ/+3MztACHpRxWTzmb yQfTe2HC8wM2rwGyPh8BL4Tx99yqiuhoVpFjG01MWykys8ZFP6HPYYk9n56PquRo ZsDnnl4QxvYRauI6zNpOEI5W+PRKVxSIA4gelGMsERZBLZ0tP1HWqsVkcU1axvMd 4r/EQvM++J6Rytd8JzJ659sFWid/IEXVzhQmA6HehcYTmn0cu2GLsgLgMnPjn0JE 2MNTMnX1ch5wiFZgmFZYwRp6pg55Lhhh3bQ/4Wwvqpz1CDy+P5V+dviWu/zCwbsV eCKMqNMnb6PXCA5yYtXZKNR+7fqXuJIimz+qKEpMUqSdy6I4dA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sbkQ016253 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:36 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 16/50] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Mon, 12 Feb 2024 16:53:48 -0800 Message-ID: <20240213005422.3121-17-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: P3ILbEoKKWn_XlCK3P216JqvFpbviphc X-Proofpoint-ORIG-GUID: P3ILbEoKKWn_XlCK3P216JqvFpbviphc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=804 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745534225673264 X-GMAIL-MSGID: 1790745534225673264 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 | 33 ++++++++++++++++++++++++++++++++- drivers/usb/host/xhci.h | 5 +++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 450adaca68ee..e4c13f056c1a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1827,7 +1827,7 @@ xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) tmp &= ERST_SIZE_MASK; writel(tmp, &ir->ir_set->erst_size); - xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); + xhci_update_erst_dequeue(xhci, ir, true); } } @@ -1870,6 +1870,11 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup return; } + /* + * 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 = ir->intr_num; xhci_remove_interrupter(xhci, ir); diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 958d6fd6d156..bdd88dcd0ad3 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2973,7 +2973,7 @@ static int xhci_handle_event_trb(struct xhci_hcd *xhci, 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, +void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, bool clear_ehb) { @@ -3073,6 +3073,37 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir return 0; } +/* + * 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 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + deq = (dma_addr_t)(erdp_reg & ERST_PTR_MASK); + if (!deq) { + xhci_err(xhci, "event ring handling not required\n"); + return; + } + + current_trb = ir->event_ring->dequeue; + /* read cycle state of the last acked trb to find out CCS */ + ring->cycle_state = le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYCLE; + + xhci_handle_events(xhci, ir); +} + /* * xHCI spec says we can get an interrupt, and if the HC has an error condition, * we might get bad data out of the event ring. Section 4.10.2.7 has a list of diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 0a4d9449bdff..96f9d1b38ff5 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1839,6 +1839,8 @@ struct xhci_interrupter * xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg); 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); /* xHCI host controller glue */ typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); @@ -1930,6 +1932,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); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From patchwork Tue Feb 13 00:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp267170dyb; Mon, 12 Feb 2024 17:22:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUa1wBFTvhx4l+5/rzUXdII6Pas0nFVS6vHcf1D7T5c2793Z25gngBsIw15bvU4oupineTsLVEKKKYBbHeuvjgR+o2u3w== X-Google-Smtp-Source: AGHT+IFuRFxYkHRvqNIVTLU53fRjR4J718j5p0QUadpAEzJzBFjrbIrJgalu8+tLLeqEa3GLKaW0 X-Received: by 2002:a5b:e8f:0:b0:dcc:2f94:591a with SMTP id z15-20020a5b0e8f000000b00dcc2f94591amr1158880ybr.12.1707787377841; Mon, 12 Feb 2024 17:22:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787377; cv=pass; d=google.com; s=arc-20160816; b=M2BKzH+MZVxZEWHXRmht3O9p06QLZ8wGgb+BxeA7eIyX4XVQivgG0Hy4LYkIq21nvo 53MhvzSbjmJaoMTU05BLP8cBVVpYeL34G7KPB0kYxMwQ4QTmUCEB2/daVcR9MKTakEKD n6bTWzigESXX1b5WGFqrkQ7f6s0XoccKPoeVooAXaF7GhcRw6k1pYwxxPowg15KXl/s1 +M50c2T/CzI967iuP9AcWcGFF6fVvqW0TbRnaVKnLwgwYJxF+YsivqlrRLpmd8y0Csdu Dd8yp3BrUcL0rneCmnPNuSXUXyt4JLAJMrEj0Q7X1NjuBYsM2amnybqYCMpbyoAyBFTS YcZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j5g8dyzHs41c6UacW6fNXqfVWRX2FAOh81uCqGT3fVg=; fh=IGZIPyeuQG6NvLJpodykwqy4k3hn7CVxRQ9GlaN782o=; b=d/J2InqNpfW7IP+HUgAB32X30f97h5a9PEVSZGPWNGfgOGn9XocWsoju0bWsEt1KZE ZdmbUGHT8ulqsgYUCL2pctMSxIRed+WFSDA3uP1/m3CGu1BKgGOKn1HEH4MK3A9hfJxa Yapfn5td0NltH61LmF4+FDWpx4O8x3ujHOzo6KUmGsTGKkjqI3/INgQTqWuyQhwe+yuv otqd+N6YUT4TqXNV1VVdk5PwVw2RgjcTbCWUs70DZRdJT0ti2yJfa6zsTf2kXH733MM0 uOF5ehZ+l+Nwa+HbuLOTva5qepiVn3gkBNAj/i6TgrbR8L3pBRyZ8C1G3ITdC2Aih2Tm kC6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=D+p3pMi2; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV4CQiyfW6uwSZPmJwm6pxIOZ8VF5qV0pjvKVPUxkmQXC7ajVAOVgTvppgGYmRv+a6ffJnfRfyHC6CTUfJFIRrmfmv2PQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d23-20020a05620a167700b007840449a485si6960762qko.234.2024.02.12.17.22.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:22:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=D+p3pMi2; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 919701C24403 for ; Tue, 13 Feb 2024 01:22:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD93854FB7; Tue, 13 Feb 2024 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="D+p3pMi2" 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 7310017CD; Tue, 13 Feb 2024 00:54: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=1707785696; cv=none; b=t19eEVFDGDo8yCY2763meTqF48el4GZHAy8CdutX8ISr7pQiudnsnIQv4RqUJ8QIprErTDc7bsO7U7keAB+bywhdsRsKSjo4E1YW5fHBFVW6fuRD9IjdpodtldvywLsPc/i0No1OMT2eWsuccCOHBOEK+FAqxvf6apY1T7A/aWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785696; c=relaxed/simple; bh=Ug45xHk+xy84mO+G0Mu7yWycvffGSHKXzcE/I/5ssZ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WrbbZWrK68qcDyTE2FGRTR7jagBjZc+7CBbVPv52lyGcWyJPe7rDZ7+kGUCZdrOmxOiLcNt5Z239PwLuRpkhqMpO/qVuXy3mDVp/9aJqTVK+lMZpXZpHXP0sphPc4+YhdHfprgucYdzPPwnYm8Vulefy7ESfzu9hT6++FYqn5cA= 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=D+p3pMi2; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0qOTH012544; Tue, 13 Feb 2024 00:54:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=j5g8dyzHs41c6UacW6fN XqfVWRX2FAOh81uCqGT3fVg=; b=D+p3pMi2vwN/3W40w9REPjUjvCRreugM9Jfo 4u3A2PXcZoF7Xsgoio/7YYQfqNfWjir1zCPZsdUqPV3R92Bbf+W75Au16UWo398A ND1gQDvliD76ZNAm1WnYAafC87gFtuwSC1hHDyF0SYqNPF7j1ThFUdvQg09bsSLN lfj3MyR6dTlHiobJ1K7ScZMWkKkKZuR+UVE3m2RnRh3aKzWKvgVhCIQySOdfhOJn dy4TAqk89wKpal0pncsGcLsh69WxbcLqVkY/AYsy4oU+ZblLNcOIsxAPVEV1rV7J SgsjmUHkrRkuyv35B1i2Vk1b9NGr2vLTgUPQTTI9gM+3DsuZwQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sbUL029991 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:37 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 17/50] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Date: Mon, 12 Feb 2024 16:53:49 -0800 Message-ID: <20240213005422.3121-18-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: CxkkanV08lSVIP4tsfs-GcGgpY2w2I1j X-Proofpoint-ORIG-GUID: CxkkanV08lSVIP4tsfs-GcGgpY2w2I1j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=504 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790744857508229065 X-GMAIL-MSGID: 1790744857508229065 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 | 30 ++++++++++++++++-------------- drivers/usb/host/xhci-sideband.c | 4 ++-- drivers/usb/host/xhci.h | 2 +- include/linux/usb/xhci-sideband.h | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index e4c13f056c1a..ae28dac7a747 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2360,7 +2360,7 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, } struct xhci_interrupter * -xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg) +xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg, int intr_num) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct xhci_interrupter *ir; @@ -2375,28 +2375,30 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg) return NULL; spin_lock_irq(&xhci->lock); - - /* Find available secondary interrupter, interrupter 0 is reserved for primary */ + /* Find available secondary interrupter, interrupter 0 is reserverd for primary */ for (i = 1; i < xhci->max_interrupters; i++) { - if (xhci->interrupters[i] == NULL) { - err = xhci_add_interrupter(xhci, ir, i); - break; + if ((intr_num > 0 && i == intr_num) || intr_num <= 0) { + if (xhci->interrupters[i] == NULL) { + err = xhci_add_interrupter(xhci, ir, i); + if (err) { + spin_unlock_irq(&xhci->lock); + goto free_ir; + } + break; + } } } - spin_unlock_irq(&xhci->lock); - if (err) { - xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n", - xhci->max_interrupters); - xhci_free_interrupter(xhci, ir); - return NULL; - } - xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", i, xhci->max_interrupters); return ir; + +free_ir: + xhci_free_interrupter(xhci, ir); + + return NULL; } EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter); diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c index 504a6f1586b5..3acbf23095e9 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -278,7 +278,7 @@ EXPORT_SYMBOL_GPL(xhci_sideband_enable_interrupt); */ int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear) + int intr_num, bool ip_autoclear) { int ret = 0; @@ -292,7 +292,7 @@ xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, } sb->ir = xhci_create_secondary_interrupter(xhci_to_hcd(sb->xhci), - num_seg); + num_seg, intr_num); if (!sb->ir) { ret = -ENOMEM; goto out; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 96f9d1b38ff5..60abbc4103fd 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1836,7 +1836,7 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, 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, int num_seg); +xhci_create_secondary_interrupter(struct usb_hcd *hcd, int num_seg, 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-sideband.h index a749ae307ba7..1026502739c5 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -58,7 +58,7 @@ int xhci_sideband_enable_interrupt(struct xhci_sideband *sb, u32 imod_interval); int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, - bool ip_autoclear); + int intr_num, bool ip_autoclear); void xhci_sideband_remove_interrupter(struct xhci_sideband *sb); From patchwork Tue Feb 13 00:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270530dyb; Mon, 12 Feb 2024 17:33:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqRDk7ACvZUq9BI/bL1w/P4RLPlMu4FMGuYLNxhBfIyPGQj4RNIO5F0C3+P85aIzu4vTx8CJiiUI+kW5sWMvnkrnxv0Q== X-Google-Smtp-Source: AGHT+IH6hTowhiCiz1lVtJYtPMtPVSxGMtql+hjrUMXPW/g5n3tfgQVhfElq8orucPc8lVoRXawV X-Received: by 2002:a0c:f0d0:0:b0:68c:9b53:8eb6 with SMTP id d16-20020a0cf0d0000000b0068c9b538eb6mr8393694qvl.43.1707788025355; Mon, 12 Feb 2024 17:33:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788025; cv=pass; d=google.com; s=arc-20160816; b=GIb/dDhp4bE3V0hcvYVkT/mdT5EHNTG29QPR08WGJDUNW4h5ipBaH7dwWU3KnkIlCV 0jf9aEfzHK98LZvRupKfk+JYGC86ziZbNeoOoCJ8H71NjPZpVs6AGtEzp4Wd3xH69r3m sy9R0/M3QOvrIxP11yR+mjgn04mBll7rMXI2he4rTCxfnXjQvELOer6AmDzf5BmMu2/e 7E0DEPLxQ+LUWr7mBCITFDwYcwxBNsYEzjDBcZeMHlEPsAKC5MA6dFNjASti1DG6Aplb 8jnvccUhIHPlE7O52gf7UcpACx6mBJv/Y8Z7IRXaNEwNWVX3+Ee3AW785HJUNmzA+Bex PxHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yay+qiUGzGhzjEyiyEzCIp87K97wb/IQSa/x2bl9rRQ=; fh=Lxh+WTfUh0rCylfQ9qLCOiisvS1NAQg48se9wAtnm4U=; b=as2KND57PANIGZDfLAfBGbJDrPRDAPw6rLj3qfV/46doE8a+zvUyMlshrXc+LvjIad dlFRLsvlB0vBt3WfFd/J1FHieYFuwr6FqEzNkaN+gdw9qWh4loIBrdTyeMJl/jxkUTxY 1KtZ2UliajHJItlqNsgykG+x/wTGV0l1zxm0Hgwu3rsddxShgG86QDIvIrVdgFZA/sYC 35mYufIiNzu0vtv+tvMB4t3BsIOnTSMDKdritngeAbKpKhlOwmsHYy8tETgQCVCoB7Ns ilrv89pZIpIpGgdOgHyrXO6DitbAFQsIUJ7zLr4Yrb3gWXbfBAOakz6QpwbXWNYzkHUN 6Bjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QiWgJVCG; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62798-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVSR3rqy7T5tql6X2/71LBt59I4ljuRHvR8j9JjPH3t3wJ7u27jqfJVPUjRjQwdMA1jPr/5RLkoVte0sLRKS2jNmyrRPQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fv5-20020a056214240500b0068c68e9a5a9si1839954qvb.544.2024.02.12.17.33.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QiWgJVCG; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62798-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 07E521C24B41 for ; Tue, 13 Feb 2024 01:33:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1C8C612E5; Tue, 13 Feb 2024 00:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QiWgJVCG" 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 C84AC37152; Tue, 13 Feb 2024 00:54: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=1707785701; cv=none; b=PKJlXFtcblAswmv+e9Zq6/q6moEH+mwcUz8/arSYjiCtVhCfboqYPT8wH4wtl/csCUjoecM6F0S6epaYZ5v9T8Xhc8FRgx5rnjna9xf7cA5Wlt42C0yvN/V54hxT9u4o9wNtO4EV3VKxGM6YRraM5WQnGLR8Wus6+SrPKJJ2ihg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785701; c=relaxed/simple; bh=x/hoppQoX5GVcdJYlk7KdQu1C05wKNt3MxNopB6D9zQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FapcPf/V7gBLuhzfi6Ix5u+mKM1SZMnh1L2jPcoJ7pnTGzKc2aJjuTsniwL9uQghO/Rp9XtGTK/AtfHqSxm2luEpw7Xs9VD6Lac4CZULaDDc/jzIBOS/Fl0Bp5wWmLMPx67FrDFOmOkBqaOOo+U560fBPkAxgZX5rAbOYKFU8DM= 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=QiWgJVCG; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CK9TaQ005304; Tue, 13 Feb 2024 00:54:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=yay+qiUGzGhzjEyiyEzC Ip87K97wb/IQSa/x2bl9rRQ=; b=QiWgJVCGSYJ6ph/g24efVpUUi329VxUStR+S 4pgh7V6NYpN/xrqAVx3YOQZce/0gjiZsf52jCsSBtyS+u0E7pas6W8zLdiet5qi6 6xGD6bXweX4YchNOsmGQcZgOzPOwp6sALlthHuMZ8UJBUt3uvfW+QXHQvs3+iT+w tUnHh59/i0XOatrivoGJkv7ctkDcMBU4y9jT+WtgMuyUWKS8oUE+GQ+pBdLZKXrU aYW24IVg61cO07GurxBS+444xJaSUSG+cYjIZViXIps0B30NDDGJ5/MMjjl7Rq0U 1Uz2y+7JKnMhUcn4pGbPW30KXWl4wLuZjbKiF54nRV5tpnezYA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0scOs031064 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 18/50] ASoC: Add SOC USB APIs for adding an USB backend Date: Mon, 12 Feb 2024 16:53:50 -0800 Message-ID: <20240213005422.3121-19-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: n_5GAKgY0e9yK2xJ-vG8Lk-Zo5xskKfV X-Proofpoint-ORIG-GUID: n_5GAKgY0e9yK2xJ-vG8Lk-Zo5xskKfV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745535941022703 X-GMAIL-MSGID: 1790745535941022703 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. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 95 ++++++++++++++++ sound/soc/Kconfig | 9 ++ sound/soc/Makefile | 4 + sound/soc/soc-usb.c | 236 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 344 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..c0cf5d1e9024 --- /dev/null +++ b/include/sound/soc-usb.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __LINUX_SND_SOC_USB_H +#define __LINUX_SND_SOC_USB_H + +/** + * struct snd_soc_usb_device + * @card_idx - sound card index associated with USB device + * @chip_idx - USB sound chip array index + * @num_playback - number of playback streams + * @num_capture - number of capture streams + **/ +struct snd_soc_usb_device { + int card_idx; + int chip_idx; + int num_playback; + int num_capture; +}; + +/** + * struct snd_soc_usb + * @list - list head for SND SOC struct list + * @dev - USB backend device reference + * @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 device *dev; + 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) +const char *snd_soc_usb_get_components_tag(bool playback); + +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_device *sdev); +void *snd_soc_usb_find_priv_data(struct device *dev); + +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_supported_streams, void *data); +void snd_soc_usb_free_port(struct snd_soc_usb *usb); +int snd_soc_usb_add_port(struct snd_soc_usb *usb); +int snd_soc_usb_remove_port(struct snd_soc_usb *usb); +#else +static inline const char *snd_soc_usb_get_components_tag(bool playback) +{ + return ""; +} + +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 *dev) +{ + return NULL; +} + +static inline struct snd_soc_usb *snd_soc_usb_allocate_port( + struct snd_soc_component *component, + int num_supported_streams, void *data) +{ + return NULL; +} + +static inline void snd_soc_usb_free_port(struct snd_soc_usb *usb) +{ } + +static inline int snd_soc_usb_add_port(struct snd_soc_usb *usb) +{ + return -EINVAL; +} + +static inline int 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 439fa631c342..d98ef50308c1 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig @@ -76,6 +76,15 @@ config SND_SOC_UTILS_KUNIT_TEST config SND_SOC_ACPI tristate +config SND_SOC_USB + bool "SoC based USB audio offloading" + 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 8376fdb217ed..044ef7db69ca 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile @@ -31,6 +31,10 @@ endif obj-$(CONFIG_SND_SOC_ACPI) += snd-soc-acpi.o +ifneq ($(CONFIG_SND_SOC_USB),) +snd-soc-core-objs += soc-usb.o +endif + obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ obj-$(CONFIG_SND_SOC) += generic/ diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c new file mode 100644 index 000000000000..ca92418501a3 --- /dev/null +++ b/sound/soc/soc-usb.c @@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#include +#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 = 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_find_usb_ctx(struct device_node *node) +{ + struct snd_soc_usb *ctx; + + mutex_lock(&ctx_mutex); + list_for_each_entry(ctx, &usb_ctx_list, list) { + if (ctx->component->dev->of_node == node) { + mutex_unlock(&ctx_mutex); + return ctx; + } + } + mutex_unlock(&ctx_mutex); + + return NULL; +} + +/** + * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag + * @playback: direction of audio stream + * + * Returns the USB offload component tag used in the ASoC components + * string. + * + */ +const char *snd_soc_usb_get_components_tag(bool playback) +{ + if (playback) + return "usbplybkoffld: 1"; + else + return "usbcapoffld: 1"; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_get_components_tag); + +/** + * snd_soc_usb_find_priv_data() - Retrieve private data stored + * @dev: device reference + * + * Fetch the private data stored in the USB SND SOC structure. + * + */ +void *snd_soc_usb_find_priv_data(struct device *dev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + node = snd_soc_find_phandle(dev); + if (!IS_ERR(node)) { + ctx = snd_soc_find_usb_ctx(node); + of_node_put(node); + } else { + /* Check if backend device */ + ctx = snd_soc_find_usb_ctx(dev->of_node); + } + + return ctx ? ctx->priv_data : NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data); + +/** + * snd_soc_usb_allocate_port() - allocate a SOC USB device + * @component: USB DPCM backend DAI component + * @num_streams: number of supported offload streams + * @data: private data + * + * Allocate and initialize a SOC USB device. This will populate parameters that + * are used in subsequent sequences. + * + */ +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_streams, void *data) +{ + struct snd_soc_usb *usb; + + usb = kzalloc(sizeof(*usb), GFP_KERNEL); + if (!usb) + return ERR_PTR(-ENOMEM); + + usb->component = component; + usb->priv_data = data; + usb->num_supported_streams = num_streams; + + return usb; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_allocate_port); + +/** + * snd_soc_usb_free_port() - free a SOC USB device + * @usb: allocated SOC USB device + + * Free and remove the SOC USB device from the available list of devices. + * + */ +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 + * @dev: USB backend device + * @priv: private data + * @connection_cb: connection status callback + * + * Register a USB backend device to the SND USB SOC framework. Memory is + * allocated as part of the USB backend device. + * + */ +int 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); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_add_port); + +/** + * snd_soc_usb_remove_port() - Remove a USB backend port + * @dev: USB backend device + * + * Remove a USB backend device from USB SND SOC. Memory is freed when USB + * backend is removed. + * + */ +int 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 == usb) { + list_del(&ctx->list); + break; + } + } + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port); + +/** + * snd_soc_usb_connect() - Notification of USB device connection + * @usbdev: USB bus device + * @card_idx: USB SND card instance + * + * Notify of a new USB SND device connection. The card_idx can be used to + * handle how the DPCM backend selects, which device to enable USB offloading + * on. + * + */ +int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + if (!usbdev) + return -ENODEV; + + node = snd_soc_find_phandle(usbdev); + if (IS_ERR(node)) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(node); + of_node_put(node); + if (!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 + * + * Notify of a new USB SND device disconnection to the USB backend. + * + */ +int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + if (!usbdev) + return -ENODEV; + + node = snd_soc_find_phandle(usbdev); + if (IS_ERR(node)) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(node); + of_node_put(node); + if (!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); From patchwork Tue Feb 13 00:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270337dyb; Mon, 12 Feb 2024 17:33:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWiEUBWiJygRcbhdiU41h1A6gMWhgbwg+72Z9eVHoYAIAJ/RJPiNbcOnapJr5jmX1xgt+q55AmWhhQlfYPC4XhMsQ+pdg== X-Google-Smtp-Source: AGHT+IHINj7KbEO5GB1HNvzP5JP4tnJTYNbmoOD/zfQi7FZeXXN8HZJJpJBvSZGTxkvisy5D4Kla X-Received: by 2002:a05:6402:797:b0:561:e4aa:ef2c with SMTP id d23-20020a056402079700b00561e4aaef2cmr1013995edy.32.1707787993470; Mon, 12 Feb 2024 17:33:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787993; cv=pass; d=google.com; s=arc-20160816; b=wVh1y3DmGnH5LDXLfiaVcjnhDstPhwDefPCcYr6S1UIHFQkTqeT5+l8PkhIOAuc/5Y 5VXH4/vdyHdO6o1p55ZFB6E4MH5nsbuoGSuTZmguFgRb4DgXEzV2IJ2AlOcOdGPuV+k7 7L1vw/xDNIfkpgAqm1Soyutvtm1T4Gf4RFyKa4w62lK3UKftJ6n7KJ/0/5Ae/X2MQ3p5 C1C9Dk7Y7x/KUW7hlrWN59ion7SgkviwbFdkKU3dq5Kq7CLtxRTt98GF5IGQbc5gGKSn COOuaUtV6pOxqJPOQCA08l9Vr1E0QdBabwqf+r2j6MjiXNEVwK6NfsFpr4sLL32e2TzC kUTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/ZM8SPXr7udKkYr/SDUmnoP1IOgbHf5SfkdSPWJ27XA=; fh=YzrqtNFjff2WixGIusHFDXoHC9AE08VxKiJ42w0BoWw=; b=hn4rUdFr2Icqc7pEsni+rpLnsKQhOV6bxpU6daB3Ca+7vc1eLcR115YonFA0Oivl8C GKGGOZtcQQhWXJCrOB5yxvCUuPQ6PKQeqdp5InKL0FXGyI6HhN+D04aUd3GV8SqFN6Jy i7WvKQzdubNL755Xei2tp28baQjHkeadSZm0up5qVtoBZJPweOEiJpYzF+XH7fKdNGjM Af5JgTTE+1AEbl14zdW3MOrGAcuAF54+FzJsbppu+rsAa5cXLNSDBbXjNlGwOrtfxtfd 9tr4q38TPgMIFZmKCODqZYoEEM8Fe5/f2vgpVc5QDKL+6EubDhVzaJKfnkiboJNFMF0Q r+3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lKhmqnfn; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62800-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62800-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXqhZ9mQmLOHaipg4XufY66fuqi5zJ4CS/od54adGG/a6BbX4PsHKn80ZHJUL14r3oF3MeE5iJ/vKHqEy4LhkiJhRmj1A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g31-20020a056402321f00b00561965316bbsi2174954eda.258.2024.02.12.17.33.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62800-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lKhmqnfn; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62800-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62800-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 32CB91F25F12 for ; Tue, 13 Feb 2024 01:32:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F4BB60BA1; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lKhmqnfn" 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 EAD4D535BD; Tue, 13 Feb 2024 00:55: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=1707785703; cv=none; b=tbbQ4YMsrrzrg7/W8Su2hUH3eix8HC1yctOnDkQwxeVyE1pcx+xupB7XWlwOdoahDJ9TTzEX4Ojm/PEOcfh0VaeWJY1VniOpax3UgoWPjHTXUXXEO1Y1PAtPf1P7B0xiQmIIfpnzubuikN5+yefBDfb2eIZpgpYUrJIRB+ZJGAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785703; c=relaxed/simple; bh=2TQXo2YMYhg/mBJxKuqafaOEZef1g+SCKODQN1pqdkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gVPJGDp3MmnTEo+buBt4fyyrc3eFmTj2vdNizWerwPFA2m5gsJACtB4rk6lcsiyDTcIeqewtIfH71R4k2jRwIW93CFwJeQdC2nLXTUXjlHyrmQmniP0ITI7x60G36107XpidbZQqEpohzBpu42vchpClQ5/yvN/s95VHW1ZzWgU= 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=lKhmqnfn; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0J9eV028624; Tue, 13 Feb 2024 00:54:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=/ZM8SPXr7udKkYr/SDUm noP1IOgbHf5SfkdSPWJ27XA=; b=lKhmqnfnI6dSnOOstfdT0E2qkuq2AlW7+x65 Zh2t+iqZfx+FufMckmvBFi58Vq9sWi2Tkf7C3YVz2spz7ttLbQSWSn2ubacJkKaC 0A7M2/Ahkk5R6ipz5/jDfiHddHE9Bj2E3A2G5PygI2fFkJL/g8jslrGz637+FOxa cGCZJq8f2hXB5HUQmfg9LF6bZUgGoAvLIQacILRZk4KKaw02FLdPKBTD8cJD3PZD ntk6duzy3NYnZ2ppWNuGIFt9vwdqQnbtf7nTq8Z4zEr2iQPkaQpnKEyZi5EWmmHg Wi9B5tz57VDlK+guDpjf/A16d/COVSGagMAn7ynTaZm8Rblsug== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0scqc031070 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 19/50] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Date: Mon, 12 Feb 2024 16:53:51 -0800 Message-ID: <20240213005422.3121-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: tL2esaJL8UFS5M2z8Ynags29-8bFQdrs X-Proofpoint-GUID: tL2esaJL8UFS5M2z8Ynags29-8bFQdrs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=872 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745502702541004 X-GMAIL-MSGID: 1790745502702541004 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/dt-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 #define LPASS_CLK_ID_PRI_MI2S_IBIT 1 #define LPASS_CLK_ID_PRI_MI2S_EBIT 2 From patchwork Tue Feb 13 00:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278550dyb; Mon, 12 Feb 2024 17:59:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVK09fmXSi5alD4WWqxyzjy19nwfjvl0+WM3XbKBVTnmWsRlSdF5hEY5QyI5RmTE0xlqjttGeGgDwEFyZdWNe/rTl0CCg== X-Google-Smtp-Source: AGHT+IG0TVoIgPpNakCrGNCOaXCobovC3d12znJ6O3kbO8PNljAHpPVIO1WzdvJo4LyU4xUNBD8C X-Received: by 2002:a05:6a20:c991:b0:19c:33c4:f813 with SMTP id gy17-20020a056a20c99100b0019c33c4f813mr10273940pzb.22.1707789573654; Mon, 12 Feb 2024 17:59:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789573; cv=pass; d=google.com; s=arc-20160816; b=ybSXGAkmxXLcVzhS5UyF/0owj/4M7I3EZS4hNqTNWrg9xV1Db7RU2mD+hfyuHWLu/e lE33EvyQqcKvlnHKNQLOKKc7osFVx7seaSpXmOUeTStB90m0QTa649CB2RmmxUFi6hhd KLL+4MvybHe8Es7BHUHzRSjTM9eMvBx1pCmiz+pozQQzK0A6dpGDRHDD3fngk/hS0GAu f8ZCDemeIeVLSMPALZ9qVMx5rJWHL5XnmkS1V4k2gP23GS+fatrtb+V3gZ9F2cgY+FVP 6iUTsOrp1NtcRxlxgEuiSZJKGIk5uBs3S7K5UlUdOvtNOQ3isOx6wRJ4Tnj7Mqvj6OoE Vy5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qQjNtAemt4pA7A8UNah9Opd7M7sEIf6lFHISXF6+fqg=; fh=3Pm6QPva1Lb8FW/DZvxF8bnRjED34hD1vc4+JUjuxJU=; b=CjMfx8X9YzTOyKJO0RTGUcR1MXEpt7e+z/lrjQYqV98QwsWfzMaZZGD/8w0hriYlVH +ZYbe2xrg+GMdDJCZPoh1eyscnEPnEVXoq86XvvAne/lBOJkFStt3O02hAy3dNAG45Ie WMXpo/fQtLfBYRTxG13NAtPz7AfHtSqVjkHVaggcOeOePN78DW3DLUezAlpurRoeHjts 75u4L0J6Kc5+0pVjTXLsSNrAMtShRt6nQSg9VzTPqRKOVyvJ1tpUoBn9rj2XKaBBufLO sySt542oZ6mLmO0iBIu2rW1Ckp7osGU3I/fO5esou+jxuAC49uYrNfG1zuQ6Q3M4IYON QqAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ZZOTuIAs; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62813-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62813-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXvFo9Ezix0ABDAHX5XxIbVKDYzYbR4NuY2yh1ENLW1y47ZI9D2mNel9zLYmPHIcep7iNF6vqXm2RbCIYTMtuEiI34Iuw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id jv5-20020a170903058500b001d751b91dc8si1122583plb.460.2024.02.12.17.59.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:59:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62813-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ZZOTuIAs; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62813-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62813-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 84A05B254B6 for ; Tue, 13 Feb 2024 01:37:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B81F663517; Tue, 13 Feb 2024 00:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ZZOTuIAs" 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 B21DD54BD6; Tue, 13 Feb 2024 00:55:02 +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=1707785707; cv=none; b=ljb9s8kM+1tJG1g6FAIlwUaNxXDpL1tiXxHQFmwvbrPOW6BEDqh4U8enTjxB4TQj1tzhJb7TFXYWpnBvK+9DDmjHkXxUJxpH4g+OUhF/O2+AFyzOwsVrtZt8ksR3ezyRIMRbTR3UHyLW/WVnTC/Yef9UirrAJ9Uc5crlktrQmlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785707; c=relaxed/simple; bh=9GImG1uvrSv3ftSZjvPK/IWX3xCwU2NzohBrdUtKIUE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oqJImBvXcDr+NgSt61+/CNI/YxXrnDDpIumy2cFTmejwzf6YZn3N+yeeyERFgvfa3X7CpvnJdtHBKsQOG8lcdgUcYomYDOGcTXtKeVYuWEEVAqQBUJ/Dqa7jrsXVb/KdwPX3qvKP/wmsXY6OFwE1smqKfr3r6Xhv2iyB78pqPCI= 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=ZZOTuIAs; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0nPw8023324; Tue, 13 Feb 2024 00:54:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=qQjNtAemt4pA7A8UNah9 Opd7M7sEIf6lFHISXF6+fqg=; b=ZZOTuIAsPtxwEA2G9zLk85ueJFdwIpmF4Sv6 EITD7wmRlK2qRXLlsdi9knqZg2qOL7WZDyFRSjUiSQE9QMnDGce6Bz2rSdRaMtUJ ugJeFr3leKYsbHIzRvzeqDXt6NXFRjwfO+E6XIdw6UW7uslNIikEft0oVRtkpuo+ lV46cGf4sj7eZoMF+IoyrSdpwy5LUXdJ++UX1Gym0l9yTBJMBBBPkgbdWlVJtMh6 BFv7qUOsMQt1grakcyY0GNgmn6NE0GXmVfpajV4cCi89NFMTL8/h6F9XePrcgXUv uoEh45SiDfjhs0TT82iwQnGP2cjwFF9CJOwfOmJXnAyI0QFrQQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7wfy82j1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sc1E031074 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:38 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 20/50] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Date: Mon, 12 Feb 2024 16:53:52 -0800 Message-ID: <20240213005422.3121-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YkoobvIUvOi2JpexNARDJIjPSIgwbVjr X-Proofpoint-ORIG-GUID: YkoobvIUvOi2JpexNARDJIjPSIgwbVjr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747160098286784 X-GMAIL-MSGID: 1790747160098286784 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, feedback endpoints (both implicit and explicit) as well as the isochronous (data) endpoints. 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 | 191 ++++++++++++++++++++++- 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 | 9 ++ 6 files changed, 318 insertions(+), 2 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c index a9c4f896a7df..80b22d1a24d0 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 *substream, return 0; } +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 = dev_get_drvdata(dai->dev); + int channels = params_channels(params); + int rate = params_rate(params); + struct q6afe_usb_cfg *usb = &dai_data->port_config[dai->id].usb_audio; + + usb->sample_rate = rate; + usb->num_channels = channels; + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_U16_LE: + case SNDRV_PCM_FORMAT_S16_LE: + usb->bit_width = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + case SNDRV_PCM_FORMAT_S24_3LE: + usb->bit_width = 24; + break; + case SNDRV_PCM_FORMAT_S32_LE: + usb->bit_width = 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_routes[] = { {"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 port */ + {"USB Playback", NULL, "USB_RX"}, }; 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 *dai) return 0; } +static const struct snd_soc_dai_ops q6afe_usb_ops = { + .probe = msm_dai_q6_dai_probe, + .prepare = q6afe_dai_prepare, + .hw_params = 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 = 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 = { .probe = msm_dai_q6_dai_probe, .remove = msm_dai_q6_dai_remove, @@ -943,6 +1000,8 @@ static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = { 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), }; static const struct snd_soc_component_driver q6afe_dai_component = { @@ -1057,6 +1116,7 @@ static int q6afe_dai_dev_probe(struct platform_device *pdev) cfg.q6i2s_ops = &q6i2s_ops; cfg.q6tdm_ops = &q6tdm_ops; cfg.q6dma_ops = &q6dma_ops; + cfg.q6usb_ops = &q6afe_usb_ops; dais = q6dsp_audio_ports_set_config(dev, &cfg, &num_dais); return devm_snd_soc_register_component(dev, &q6afe_dai_component, dais, num_dais); diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index ef7557be5d66..948007955934 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -35,6 +35,8 @@ #define AFE_MODULE_TDM 0x0001028A #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 #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 +#define AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG 0x1 /* 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 +/* 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; +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; @@ -833,6 +924,7 @@ static struct afe_port_map port_maps[AFE_PORT_MAX] = { RX_CODEC_DMA_RX_6, 1, 1}, [RX_CODEC_DMA_RX_7] = { AFE_PORT_ID_RX_CODEC_DMA_RX_7, RX_CODEC_DMA_RX_7, 1, 1}, + [USB_RX] = { AFE_PORT_ID_USB_RX, USB_RX, 1, 1}, }; static void q6afe_port_free(struct kref *ref) @@ -1290,6 +1382,100 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, } EXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare); +/** + * 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 through + * to the stream enable QMI request, which is handled by the offload class + * driver. The information is parsed to determine which USB device to query + * 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 = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + usb_dev.dev_token = (cardidx << 16) | (pcmidx << 8); + ret = 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 = &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 = -EINVAL; + goto exit; + } + + memset(&lpcm_fmt, 0, sizeof(lpcm_fmt)); + memset(&svc_int, 0, sizeof(svc_int)); + + lpcm_fmt.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + lpcm_fmt.endian = pcfg->usb_cfg.endian; + ret = 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 = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + svc_int.svc_interval = pcfg->usb_cfg.service_interval; + ret = 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 = &port->port_cfg; + + pcfg->usb_cfg.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + pcfg->usb_cfg.sample_rate = cfg->sample_rate; + pcfg->usb_cfg.num_channels = cfg->num_channels; + pcfg->usb_cfg.bit_width = 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 +1798,10 @@ struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id) break; case AFE_PORT_ID_WSA_CODEC_DMA_RX_0 ... AFE_PORT_ID_RX_CODEC_DMA_RX_7: cfg_type = AFE_PARAM_ID_CODEC_DMA_CONFIG; - break; + break; + case AFE_PORT_ID_USB_RX: + cfg_type = 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..04c70f904b86 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__ -#define AFE_PORT_MAX 129 +#define AFE_PORT_MAX 137 #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; }; +/** + * 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; +}; 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; }; 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, struct q6afe_tdm_cfg *cfg); void q6afe_cdc_dma_port_prepare(struct q6afe_port *port, struct q6afe_cdc_dma_cfg *cfg); +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/qdsp6/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 @@ } static struct snd_soc_dai_driver q6dsp_audio_fe_dais[] = { + { + .playback = { + .stream_name = "USB Playback", + .rates = 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 = 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 = 1, + .channels_max = 2, + .rate_min = 8000, + .rate_max = 192000, + }, + .id = USB_RX, + .name = "USB_RX", + }, { .playback = { .stream_name = "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 = cfg->q6dma_ops; break; + case USB_RX: + q6dsp_audio_fe_dais[i].ops = cfg->q6usb_ops; + break; default: break; } diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h b/sound/soc/qcom/qdsp6/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; }; 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/q6routing.c index 81fde0681f95..45811f0f0d44 100644 --- a/sound/soc/qcom/qdsp6/q6routing.c +++ b/sound/soc/qcom/qdsp6/q6routing.c @@ -515,6 +515,9 @@ static int msm_routing_put_audio_mixer(struct snd_kcontrol *kcontrol, return 1; } +static const struct snd_kcontrol_new usb_mixer_controls[] = { + Q6ROUTING_RX_MIXERS(USB_RX) }; + static const struct snd_kcontrol_new hdmi_mixer_controls[] = { Q6ROUTING_RX_MIXERS(HDMI_RX) }; @@ -950,6 +953,10 @@ static const struct snd_soc_dapm_widget msm_qdsp6_widgets[] = { SND_SOC_DAPM_MIXER("MultiMedia8 Mixer", SND_SOC_NOPM, 0, 0, mmul8_mixer_controls, ARRAY_SIZE(mmul8_mixer_controls)), + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, + usb_mixer_controls, + ARRAY_SIZE(usb_mixer_controls)), + }; static const struct snd_soc_dapm_route intercon[] = { @@ -1043,6 +1050,8 @@ static const struct snd_soc_dapm_route intercon[] = { {"MM_UL6", NULL, "MultiMedia6 Mixer"}, {"MM_UL7", NULL, "MultiMedia7 Mixer"}, {"MM_UL8", NULL, "MultiMedia8 Mixer"}, + + Q6ROUTING_RX_DAPM_ROUTE("USB Mixer", "USB_RX"), }; static int routing_hw_params(struct snd_soc_component *component, From patchwork Tue Feb 13 00:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270074dyb; Mon, 12 Feb 2024 17:32:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/vsLZ6JQU1Kz6CDSeARy61IQ6FUwZLg20UygVdhMR6Nki9TD+DIzXePdx4ITIZbKjlzt4 X-Received: by 2002:a05:6a20:b71c:b0:19c:a202:3f96 with SMTP id fg28-20020a056a20b71c00b0019ca2023f96mr4343946pzb.51.1707787947312; Mon, 12 Feb 2024 17:32:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787947; cv=pass; d=google.com; s=arc-20160816; b=mW5qRreVNsXUg9GVXLhvtZb3C+3I/vsk/VhMejGCGjz5gaK1+ezDSGD4QJH+acMeEu 81+OM+ladDf4XgO8L2KMRpoL9aVxFoSR2PYqSGmYCsF4uKI4vPHqX0d1m/Bh1b2N+CqU 0qmjdLseyTuV0H0uA8+d1kEA9cLol+qt/EJ0Su+8lGzzrcqDagiz1/3ehokMkP+SbWC+ V1ZTZlgD35UV+R4k0PZE++sXCvuH0B69GfLMeDi6Gf82KtYlA2RWhycKS3owWBTLF+se 7fy1zobKRjXgMPKB6jmcHWMfs5mnR5NcIPZT4GxMSKBH9PSTr43SODbJaQ+TyAxwnwnd DqNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Okp2NIuxOum+UIJx68gt8HGPT3ztWG2atEl9RFxfZvI=; fh=zn96EYL+gxEIHc5zWzKb5O89h6+jXVgpPqxKg6LNCaw=; b=RGAl+oR4GJU6ff5tZpXrfZx3mrqLdlOpaYO0pK64aADEOf2mD3BlkYcQDbf6ImpH6Q 8vUeljfoNLIibm3Bsh15L+za4tGtt++WLQjXTA6/M0apKV8YGUzGJt2caV6/XSwTQoXA N+BdNgTy3bJEV/++R4PobhLOnQdhT2mV8H4iL3OyFwRE/+/QBZ0EMyuWyj7cd/+I64Qc K41mE4IY3tkhozxb12exF1VhqyujSE+ycyp4ISUmrpcSFdLu9OCSE+3RoS8xb7Ef0Bxa 8xKasQH+SAa4Offcr40pN/jGF5m7cAw7ThXAulHg9XNvEEVQo7U5gQKQuQp4ZXWzXEIj NVYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DU41Pko+; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62799-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62799-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUwSnsJwk4CB6cNLoFipnLNK2ivFD6UUh05604mkZW6/SOURBwnwYa/H6th78MGs5foVrisgwnEAX31FWZoMPOWY3UDZw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id il4-20020a17090b164400b002972e2132eesi1166932pjb.64.2024.02.12.17.32.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62799-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DU41Pko+; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62799-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62799-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1D03928C659 for ; Tue, 13 Feb 2024 01:32:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C39FA60BAE; Tue, 13 Feb 2024 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="DU41Pko+" 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 C6D5E535A0; Tue, 13 Feb 2024 00:55: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=1707785702; cv=none; b=KJh4kRvtPeiTE1bzMnbSm4BdTl3qTnWWshE/FPimIPYmMxONwNkb7nEjdSFaeZJLsWJpTheImNrlAEdfVHJMK1MLRuOU2FDM+ozP2f40YthDnBZobjBh1h3mygyzbm/sb+INLag229x/DyF3zGLa26Xeu275/cYnvvHpFl0Ew1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785702; c=relaxed/simple; bh=5l1ZDxiiOCJBz70DKB8YoEv4oAwewH8W9SdYrKkgC5E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DFICAHYOR2ULpDVeuGRZwn8CAjrxdtJHrPzOPpgapFU3xf69sKpwUScMIu0FMFTOhTSNwO/wl9V75WdRDWjVqiDMpxGUCI+LKc1ZKmdnNjL/YDWr5aY1xJxF84czYi8bFQ+QojRvEEHCSSbBIpLp8XJ14B2/T4jBR87fc3J2Q2E= 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=DU41Pko+; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CMa2nV024513; Tue, 13 Feb 2024 00:54:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=Okp2NIuxOum+UIJx68gt 8HGPT3ztWG2atEl9RFxfZvI=; b=DU41Pko+SLuEDhtjrkDUrqiR+5tuiJA+0OWv 5LTl7U205dYq3PvCOFaIWL+8Eqey8MZFVYC/clbijJVTa8w6X0IPY28ox5C98A9F U1YA3nTHSjXr63N8R7axzPFUsEWsGvLC7grUC2v03g84puZoXxJEFnlZQFC0PGw9 PaCQH+XtgbwCB26wXKHGcoNl+WFeARb71VwmaisD2ko3azF6ddGg1y4nD54kkrQC U3D6L47w56pRxE6qF/UJGVcqflClnNzxBlx5A+kX6Eny1w5yzly6KXr6+BHXzvq9 EXvrVV4H5STBbuK/LOgBQg+Tn+IVdgzjhvGL5QOYF6rzasP+3Q== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0scio026797 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 16:54:38 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 21/50] ASoC: qdsp6: q6afe: Increase APR timeout Date: Mon, 12 Feb 2024 16:53:53 -0800 Message-ID: <20240213005422.3121-22-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: KOvqSQPbv1_BBCGUkck8OLqaDmrbJXMe X-Proofpoint-GUID: KOvqSQPbv1_BBCGUkck8OLqaDmrbJXMe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=844 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745454338656165 X-GMAIL-MSGID: 1790745454338656165 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: 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 948007955934..452d7e8b9b30 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 -#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 patchwork Tue Feb 13 00:53:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp274928dyb; Mon, 12 Feb 2024 17:47:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV02b/UTiwhZj0tWkzO1HJ1jm0dtXVidCrpws7rfjz03wc0Kygrf3kXvEnjJMEJGHvEK17VuIhBvpRtw2JU10ijyIKiww== X-Google-Smtp-Source: AGHT+IFeX4ojOkY6Qqp1crTu8W5jnB+bPam5GmAJfX/i64Ps7HZLDF8BLL+C+hqW6YOQWHcL46OA X-Received: by 2002:a05:6808:2382:b0:3bf:f4bb:7630 with SMTP id bp2-20020a056808238200b003bff4bb7630mr11206906oib.45.1707788860931; Mon, 12 Feb 2024 17:47:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788860; cv=pass; d=google.com; s=arc-20160816; b=bTZwL8BbR1Rlz31P+ThHrQmq/mtilF0kRLPvVaU9hDAGBXM34keYC/7bx1QpdfB7XC TGXM+7jgjtRNj24F7d291F0XwOzSvhrlyRUJVEHU25z0nnXbwqFFTUWbWeILyNmJlQf0 0ZlbEoSZX2MXhTOPr9j3SQTpXJhtRoG2gAudHD79Xo/cEE0RhR1fWxN/SSQWAn+pJjgU m4iH9nRoQlDdCRnvqcRPDwByWzHS4rGtqT0Yj0Nb9TY0aKdvnW1NIdyfinDjx5EJfNBi XxvIyrve+fojhbJMbxabfjLU2a5/abOyDyYwCCXpN3Brdbc2u0bFEF1kwYtx4QIx+AZw zqyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HV9Pb6l7ZvIx0wp5NxUZhQQ9a+JOucxlg/XCtN+7Lmo=; fh=SpaBjqlL/CsO54sg0XwIVEsz/YFGzFXnqD2cc8Qd11Y=; b=ecuMB5P3uibByYynKzhVlTjLHiL2j6NTHSM6cOoNwwoFeCuAHlg4DBb4h273urBfPe 7WHBRTUYtrkDK8eh+UZcLuumtQcmA08C9Bb5DJoI9/PwFLd2qDBFdjAvOoBiGdbFdNf3 6q/Ts8RcFIjnumoDgANk0t2+e9g6UrsonVMZ+lfgFwtfKNkl99+5mmH/AyLjJHvTfYbD eysPWgwQqTEwyteokrvUh8KLU1mabKoFUEvycQQk73san8q/0YuQDWwb9VvuhIskyEWn YCWjnA0pF5G5eaPJ0kKWVEn7mAlRPrYDtEgkfdL3jGBeH9W5qpzBwm71WruT74Hq5C0N 3fAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DnK94a3J; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62788-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62788-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV3hBsQtg5grQFyIIEqfPb3uK8jNjd2nxwGUrbZwW3H6L1kbc6HcU2p22KrMAApjDPICinSjbZ3UDlSFb5D5SXdx+SYew== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s21-20020a639255000000b005dc1e39fbeasi1096522pgn.80.2024.02.12.17.47.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62788-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DnK94a3J; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62788-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62788-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6F9FFB22825 for ; Tue, 13 Feb 2024 01:29:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA6EE5FB96; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="DnK94a3J" 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 528AC224C6; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; cv=none; b=Uqf/csJNDRExYHfHFVm2T4RmIFQbjEWLl59+ms7IUgsENyM9x3496EtT9bJtTSn411qm7Epcnedsnotn4hH9HibjwZpcNANVD5MXA6t6cARY2fCRqpUlIv8oAo+Bu5wb3P08EqDpAZTPQkVyAJ7TSDlsjkNSbuRvXZc+pdlibik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785699; c=relaxed/simple; bh=RTqL/6yg3gqL8ZK4i40n0gkIb7t9uu+dvMG3qkam1Gw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PNtL1vpi1AIv25fDHnH6wiZ/trXmAa+aBPeg95C8jCukKwI/iZ63uh9DVXeWudL5SkpXS3PuRyS9MtGcPFbw59A25cM4w4KKeFWnawzAfnZ/yan1DgJjaAKz3PtKyW/+SEPSLhyFwOmcSXWKlSVbnGRqwWNUACiOquCe0DTxJZQ= 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=DnK94a3J; 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 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CLQatF001111; Tue, 13 Feb 2024 00:54:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=HV9Pb6l7ZvIx0wp5NxUZ hQQ9a+JOucxlg/XCtN+7Lmo=; b=DnK94a3J7aMjsXnB7RGNGq4GlCL/Ih2gPk7o qlKyJybtV/6a3C+SyLz/8aSgqAVW8oExeZXaJmxc/4stbeFwP43ABLrYVuXPsEt8 WqYWWPEsOg8KGbhJ7m2m7PjTlEfaktwxIFLNpi47M/Ajitidox9xRZ8BluwKH7U9 PkxX3NBQii/PGgZJFdG82bdfAJf7A5gxYAzJBHR/6WaR+BhGAy8bc5XMMkean2wk 4lj7noINa2eqz/9T1LuYqYVpJisdpFQa+xTFJp1Xqfb0c+LL4FQ4OlH+ugMwUO12 T0ZB9fBek6iFAElOLtx4pU+oVFIk/DiiRyzRoUUKfjZFnONx3w== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7nk9150b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sdB9026806 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 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.1118.40; Mon, 12 Feb 2024 16:54:38 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 22/50] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Mon, 12 Feb 2024 16:53:54 -0800 Message-ID: <20240213005422.3121-23-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: D0JEzGpOLuvE326tW3EQ1XjWkm1uV5uc X-Proofpoint-ORIG-GUID: D0JEzGpOLuvE326tW3EQ1XjWkm1uV5uc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746412358266897 X-GMAIL-MSGID: 1790746412358266897 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. Signed-off-by: Wesley Cheng --- include/sound/q6usboffload.h | 20 ++++ sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6usb.c | 218 ++++++++++++++++++++++++++++++++++ sound/soc/soc-usb.c | 1 - 5 files changed, 243 insertions(+), 1 deletion(-) 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..fdc1f5c53a3b --- /dev/null +++ b/include/sound/q6usboffload.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * linux/sound/q6usboffload.h -- QDSP6 USB offload + * + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +/** + * struct q6usb_offload + * @dev - dev handle to usb be + * @sid - streamID for iommu + * @intr_num - usb interrupter number + * @domain - allocated iommu domain + **/ +struct q6usb_offload { + struct device *dev; + long long sid; + u16 intr_num; + struct iommu_domain *domain; +}; diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 762491d6f2f2..b4eed01a2b2b 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -114,6 +114,9 @@ config SND_SOC_QDSP6_APM config SND_SOC_QDSP6_PRM_LPASS_CLOCKS tristate +config SND_SOC_QDSP6_USB + tristate + config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS @@ -134,6 +137,7 @@ config SND_SOC_QDSP6 select SND_SOC_TOPOLOGY select SND_SOC_QDSP6_APM select SND_SOC_QDSP6_PRM + select SND_SOC_QDSP6_USB help To add support for MSM QDSP6 Soc Audio. This will enable sound soc platform specific diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 3963bf234664..c9457ee898d0 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) += q6apm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) += q6apm-lpass-dais.o obj-$(CONFIG_SND_SOC_QDSP6_PRM) += q6prm.o obj-$(CONFIG_SND_SOC_QDSP6_PRM_LPASS_CLOCKS) += q6prm-clocks.o +obj-$(CONFIG_SND_SOC_QDSP6_USB) += q6usb.o diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c new file mode 100644 index 000000000000..00cba1021dc6 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#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; + int active_usb_chip_idx; +}; + +static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { + SND_SOC_DAPM_HP("USB_RX_BE", NULL), +}; + +static const struct snd_soc_dapm_route q6usb_dapm_routes[] = { + {"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) +{ + return 0; +} + +static const struct snd_soc_dai_ops q6usb_ops = { + .hw_params = q6usb_hw_params, +}; + +static struct snd_soc_dai_driver q6usb_be_dais[] = { + { + .playback = { + .stream_name = "USB BE RX", + .rates = 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 = 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 = 1, + .channels_max = 2, + .rate_max = 192000, + .rate_min = 8000, + }, + .id = USB_RX, + .name = "USB_RX_BE", + .ops = &q6usb_ops, + }, +}; + +static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, + const struct of_phandle_args *args, + const char **dai_name) +{ + int id = args->args[0]; + int ret = -EINVAL; + int i; + + for (i = 0; i < ARRAY_SIZE(q6usb_be_dais); i++) { + if (q6usb_be_dais[i].id == id) { + *dai_name = q6usb_be_dais[i].name; + ret = 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 = dev_get_drvdata(usb->component->dev); + + if (connected) { + /* We only track the latest USB headset plugged in */ + data->active_usb_chip_idx = sdev->card_idx; + } + + return 0; +} + +static int q6usb_component_probe(struct snd_soc_component *component) +{ + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + struct snd_soc_usb *usb; + int ret; + + usb = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + + ret = snd_soc_usb_add_port(usb); + if (ret < 0) { + dev_err(component->dev, "failed to add usb port\n"); + goto free_usb; + } + + data->usb = usb; + + return 0; + +free_usb: + snd_soc_usb_free_port(usb); + + return ret; +} + +static void q6usb_component_remove(struct snd_soc_component *component) +{ + struct q6usb_port_data *data = 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 = { + .probe = q6usb_component_probe, + .remove = q6usb_component_remove, + .name = "q6usb-dai-component", + .dapm_widgets = q6usb_dai_widgets, + .num_dapm_widgets = ARRAY_SIZE(q6usb_dai_widgets), + .dapm_routes = q6usb_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(q6usb_dapm_routes), + .of_xlate_dai_name = q6usb_audio_ports_of_xlate_dai_name, +}; + +static int q6usb_dai_dev_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct q6usb_port_data *data; + struct device *dev = &pdev->dev; + struct of_phandle_args args; + int ret; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = 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 = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); + if (ret < 0) + data->priv.sid = -1; + else + data->priv.sid = args.args[0] & Q6_USB_SID_MASK; + + data->priv.domain = iommu_get_domain_for_dev(&pdev->dev); + + data->priv.dev = dev; + 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[] = { + { .compatible = "qcom,q6usb" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6usb_dai_device_id); + +static struct platform_driver q6usb_dai_platform_driver = { + .driver = { + .name = "q6usb-dai", + .of_match_table = of_match_ptr(q6usb_dai_device_id), + }, + .probe = 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"); diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index ca92418501a3..a1e0363bd760 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -101,7 +101,6 @@ struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *componen usb->component = component; usb->priv_data = data; - usb->num_supported_streams = num_streams; return usb; } From patchwork Tue Feb 13 00:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270056dyb; Mon, 12 Feb 2024 17:32:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUM28tQzKh/kr4OAGIafIP/j6flM07msoBNAo0kiVJbXrxQMtMkvMYYATrTXOFTeKLw7fe+dZaXfYC2PEyz1+AEj7w3Pw== X-Google-Smtp-Source: AGHT+IFCwE+NNwp7vTy8IYaqaNXR2tw1/qPoPUoTnVomHDobnMqKGrRhH0c07V9rdHQCb6D7wlpp X-Received: by 2002:a05:6402:5d90:b0:561:9f62:8dbb with SMTP id if16-20020a0564025d9000b005619f628dbbmr3566270edb.15.1707787944213; Mon, 12 Feb 2024 17:32:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787944; cv=pass; d=google.com; s=arc-20160816; b=ZNKdcMhlYgpYe+IuOLWvHAwuJcstem2iem6J+BV7NxA8bSv3OJmYeB88AUrzUMo6RZ GHdjgQvAm+Ofoswiy7DiAIYSgQ9T8/NVaWRFdZe7AHgNc0A4p8Uyxefe2NhDtsbkwcxW EfG17qHo2C3ilIaJaGva/apKMKISPVjUFYMjW0994PYKDOxStw0jYjw0BIcj7xfg+TzW IIIJliZsEzJzCWzFfFOXBgJf5tXYJh+aA5F55hdbuRDh6EGy5TBQKumPozW2Il1/oxda k5Z2isPiMWK+MnqYcpq082E1mGlSQnf5slJAw69flxlT8KuxMQTrIMIMKt5hNWtpnpS8 z8jg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S9VTWxSz7x4qq1AeYZyZG+OFcZ7lvmr3A4Wyz4IN404=; fh=UyRD/j46tedEdaWLpp6Gtr030t5MNfsWrhIqxLBckJ0=; b=FR2qX8TQm6ig8VKNDx9qWbtkj9o+K8zTBp2ir2yTwZWkmASGoVNChr6v4S54l1An+r +b+w2v6pBEhgNvnPYnw9BKKNosFW+t1lbO3TR+X49WYujJGwKyDGbWoZUnVl4iu7GNeu qydeH869BeX8EJKWaS2eeOyY0JmsQD8cPuF0rmyhC2CkOg+gRnkQX8HRzM6LF64AMWXQ eLDZlZeW0xM8dugvnFUkOTUxqPg/5Stdcl2q1TtSO2NYeKfW+w/LyY4GJFhldm1K9gZd A3jntMdHv1CJpsuwtXFW+PfVqnfLWIzpCLZgVQqoIo0g3smMf/CMGGoSe5M7N58uywUq IQBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=BaYytUtE; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62780-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUrWKmWxKyHMiq8/DzGj896rWh2aczFXsiCSG9Xlr+NPCpSqII3JbMkJWI+us8TmfKdE/qE2DFYpK66Bv7OWPT1TE0UqQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q15-20020aa7d44f000000b00561282f081dsi3275740edr.451.2024.02.12.17.32.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=BaYytUtE; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62780-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1290D1F25E97 for ; Tue, 13 Feb 2024 01:23:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A42B55E54; Tue, 13 Feb 2024 00:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="BaYytUtE" 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 758CD8BE3; Tue, 13 Feb 2024 00:54: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=1707785697; cv=none; b=VSRgmheiHbNU3wO5qPC8CJTeyEcwKAvDMOmHshBV8h0SMsi4w9zhAsQA/7CU00Tfuz/Q7cWoDp4AV7yyyFmJkiV4Xi8jxwz7UfohjrWjteNLAFgRCcMXPQP7Sus6ulEf3bA9L7H/BK7EK5SVfGsbxKxJ6fzS9NSQ1IGy6GY7kz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785697; c=relaxed/simple; bh=NFb5KrutHq3DEtEEDYwpfG5twPMjHvzujusJINVO7hw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T01ORB24AmJXU4Z7uCly820R2oQTFEzCkCgPTAJ0hdRW6pi1vnrIuNluAoQ6QkYmIK2cj3EFdFXKV6XSn/zc9iHMnU/89jV/VSdkBvPe115XWc7LZqeyhWVo0Ce49w5NQbMrtZbNYwHDRNPm4rzpvyn5/8atpW36nAur25BnU+g= 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=BaYytUtE; 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 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CNCJGB021788; Tue, 13 Feb 2024 00:54:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=S9VTWxSz7x4qq1AeYZyZ G+OFcZ7lvmr3A4Wyz4IN404=; b=BaYytUtEaNuxdiuWGxeu+wUxHj1mDcnE3VP1 648BglRXWGR7EW0CSOwkxNX78/1F9M/TFVwzsStOarcwv+QDyFDRc9nXFvY5cb9t +SJ96WH096lVab4mQMQIycG6WyRyJ85Y+aKua7PvY6q351Bc+DjHEtxLSD1RiltE iWA1U6E8L5kb6IUoqQe9jqK4XokKckD9Gu++CmfJxUxhuZI8zu05FEOqFE7RTKeY yYzDYGONTg12PzjdAXaJP4ZRRpeSmhscqeWjlm1ZpZfY4wnsDR2wk5vswoFKGszQ rsqw0Ux5L2fcJtedMkXwx6XJUcrdtiOt8wlI1c9ZnUmnVnDO8w== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7nk9150c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sdQi031169 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 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.1118.40; Mon, 12 Feb 2024 16:54:38 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 23/50] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Mon, 12 Feb 2024 16:53:55 -0800 Message-ID: <20240213005422.3121-24-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LcWebloXadRb8Iwt8_ad1PDt3waJqpyg X-Proofpoint-ORIG-GUID: LcWebloXadRb8Iwt8_ad1PDt3waJqpyg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=934 impostorscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745451548444287 X-GMAIL-MSGID: 1790745451548444287 Allow for different platforms to be notified on USB SND connect/disconnect seqeunces. 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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 9 ++++++++ 2 files changed, 62 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1b2edc0fd2e9..ca4f3bc1b42d 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,42 @@ MODULE_PARM_DESC(skip_validation, "Skip unit descriptor 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 data + * 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 = 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 = NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); /* * disconnect streams @@ -910,7 +946,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; __error: @@ -947,6 +987,9 @@ static void usb_audio_disconnect(struct usb_interface *intf) card = chip->card; mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->disconnect_cb) + platform_ops->disconnect_cb(chip); + if (atomic_inc_return(&chip->shutdown) == 1) { struct snd_usb_stream *as; struct snd_usb_endpoint *ep; @@ -1090,6 +1133,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) chip->system_suspend = chip->num_suspended_intf; } + mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->suspend_cb) + platform_ops->suspend_cb(intf, message); + mutex_unlock(®ister_mutex); + return 0; } @@ -1130,6 +1178,11 @@ static int usb_audio_resume(struct usb_interface *intf) snd_usb_midi_v2_resume_all(chip); + mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->resume_cb) + platform_ops->resume_cb(intf); + mutex_unlock(®ister_mutex); + out: if (chip->num_suspended_intf == 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 6ec95b2edf86..2884912adc96 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,13 @@ struct snd_usb_stream { struct list_head list; }; +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); +}; + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); #endif /* __USBAUDIO_CARD_H */ From patchwork Tue Feb 13 00:53:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268894dyb; Mon, 12 Feb 2024 17:28:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGl1/iq06yvpf2CHki5XXFirm5Hn3tDPqpSc7H467WHxpllP3HyAfFFoCFTka6ovNU3Y+gd X-Received: by 2002:a17:906:4c53:b0:a3c:9b8f:e48d with SMTP id d19-20020a1709064c5300b00a3c9b8fe48dmr2912578ejw.27.1707787735274; Mon, 12 Feb 2024 17:28:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787735; cv=pass; d=google.com; s=arc-20160816; b=EohJbtI/NHgFGSt2oVvTwkyqF+LoupoYjtgKiAVR9CbkdCxNN7WcJj/IiLy5zgAZPN mlXR2HfqrimcaMvp6m6NOEaTOSJyDyhDBFk6ZvSgvVzXtsyEdnzQ9oBIt1R431io95fa T22jS0mlosgwEdqgtXV115gbI+O7hv2jVYNts/ipcz1tF/3lFUEBZCAChvP1VQf0O+cS ySX2pJB1YDPX/E7gcYzwM5wYRjciOQgRH1biP0NZpxH3G+n0OlmWs0lnOciERtIjJOZB 3K20Cpwfi/T5l+kZxee6pH1nHiqOa0VqO91DrFCqhFIL+ak2FC/oiIbGMqRoPey4j3AX CBOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o7vHP4LLBYG3S+3r5ZuUO0gEZ9lpoN/n15JMZp7r2rw=; fh=+BMJRxtWtdw+WGe9aa7fQ8K1WFfiB3pa952ItHwhtmo=; b=kMFKVg/c7iZaI5FGhEKtmGCaTV0zfZvNhVC5ISiHoaMU0rF7+HppKRBTNSpGooVLqK 82cCy5s8lDFynQmmiBT09208Jf0QjskiDcZDtqh7c1/mFEyeYwub71NbxW2lUwjvfg0c O2Y76Lyhk/os4qMZe90TsQoPC5P/pqG2VSkng+kAFq5Rwtyd05sPK0CxoBjUXOIr/p/x aDaa076a0Rt1KgzrBmuMWXDvgclNz+yZqbOwPUIst/hwLaqaaEZoBmGUoJoSywYtq/wD +NUKvsZGJdhZ5n947oLzKJTn5jqr7HVlXXP9KGAzjUiGOkjTP6g35ldxDzutdgHt4Ean BzlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CgLPkMKN; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62785-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62785-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWeN1DLDqAgXqaws5346kl8XvlLX+6RzOM67Obil6XlpGaUU1/qk9V2lFRMZXhroAbuU8PB6x3vRO44FmlH66pQCaOlcg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c17-20020a170906695100b00a3ce36ce1d5si549307ejs.149.2024.02.12.17.28.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:28:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62785-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CgLPkMKN; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62785-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62785-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AF19A1F28F4E for ; Tue, 13 Feb 2024 01:28:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6B5A5F87E; Tue, 13 Feb 2024 00:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="CgLPkMKN" 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 F086A2232D; Tue, 13 Feb 2024 00:54: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=1707785698; cv=none; b=Hp9Q3Kxb7ck9EKf2J0JDTIIXHN3GKMAAxoF0br1yUn8OhRGOcXdOauCMS/YWY3YtM7mbb3sQnwVBd7xenytJS+UZccrvWBC+uPn0YzUzy+0S7FJ9QzSKWm2PIrz2xGs6uxpxGN20tfuA2hHHTI7hDhqwZ+AEP5rWXBXziM+4NmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785698; c=relaxed/simple; bh=yy60iKclSo3I7kupLIIW7Eb4iC2/mPynjDbi7rSIXPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CwLQq67OOiVV9urJ4il1m9Haq+PXAauU7B9NFcDZII0AhiAWVjuJb08Wk0qABD5xNNmlARXQHCkW3lJ4N9G9zduZOhPLInCdgUcF+qpveUklOQAT+TkBwV75EdEU9/lviToybmQSe+oK6iPvvE1c9VGDGG0JpTF3PPzFHi3yw0I= 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=CgLPkMKN; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D09BjY016475; Tue, 13 Feb 2024 00:54:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=o7vHP4LLBYG3S+3r5ZuU O0gEZ9lpoN/n15JMZp7r2rw=; b=CgLPkMKNB9BvHDDEGRnwu83X/dMXpkslXZpc b46gt07kNMSfJG6gm/f3ZKDVS1gBsEexm044p+w1geH2WNpawKEgSa1FrRW4FS+v mpJz7wKAkWt/1oAZbiCj7FO0FyxzMNhUkdVyJMYlcalfXMm1jwMw7pKxAVfkDB+B rOeklhGu2Kip5j4nCmLCQJPTPYLSDw4mf3Fco4P1VKIrFRhiRoUxLsL7AomN5Srl E3x4uCKawhcy9XhT1J2mWB4djG7rel1CwmAWOwTrdBKndxu7ndn1RXbkQDH0ddc5 tuaUFhU6V2qaw8hkk+KLsyAP8lWydIl1K+UJUVTJ9XRBlRNjKA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sdvd031173 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:39 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.1118.40; Mon, 12 Feb 2024 16:54:39 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 24/50] ALSA: usb-audio: Export USB SND APIs for modules Date: Mon, 12 Feb 2024 16:53:56 -0800 Message-ID: <20240213005422.3121-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YePuaHpmVaAuHoaF3WBmh8a3HbjV52ik X-Proofpoint-ORIG-GUID: YePuaHpmVaAuHoaF3WBmh8a3HbjV52ik X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745232318910345 X-GMAIL-MSGID: 1790745232318910345 Some vendor modules will utilize useful parsing and endpoint management APIs to start audio playback/capture. 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 ca4f3bc1b42d..7dc8007ba839 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -1061,6 +1061,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); /* autosuspend and unlock the shutdown */ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) @@ -1069,6 +1070,7 @@ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) if (atomic_dec_and_test(&chip->usage_count)) wake_up(&chip->shutdown_wait); } +EXPORT_SYMBOL_GPL(snd_usb_unlock_shutdown); int snd_usb_autoresume(struct snd_usb_audio *chip) { @@ -1091,6 +1093,7 @@ int snd_usb_autoresume(struct snd_usb_audio *chip) } return 0; } +EXPORT_SYMBOL_GPL(snd_usb_autoresume); void snd_usb_autosuspend(struct snd_usb_audio *chip) { @@ -1104,6 +1107,7 @@ void snd_usb_autosuspend(struct snd_usb_audio *chip) for (i = 0; i < chip->num_interfaces; i++) usb_autopm_put_interface(chip->intf[i]); } +EXPORT_SYMBOL_GPL(snd_usb_autosuspend); static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) { 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 *chip, mutex_unlock(&chip->mutex); return err; } +EXPORT_SYMBOL_GPL(snd_usb_endpoint_prepare); /* 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, void *after, u8 dsubtype } return NULL; } +EXPORT_SYMBOL_GPL(snd_usb_find_csint_desc); /* * Wrapper for usb_control_msg(). diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 08bf535ed163..3adb09ce1702 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_format_t format, return found; } +const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, + 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); } +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, } } -/* - * 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 = substream->runtime->private_data; struct snd_usb_audio *chip = 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 = 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, return ret; } +EXPORT_SYMBOL_GPL(snd_usb_hw_params); /* - * 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 = 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 = subs->stream->chip; snd_media_stop_pipeline(subs); @@ -603,6 +623,19 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream) 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 = substream->runtime->private_data; + + return snd_usb_hw_free(subs); +} /* 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 snd_pcm_substream *substream static const struct snd_pcm_ops snd_usb_playback_ops = { .open = snd_usb_pcm_open, .close = snd_usb_pcm_close, - .hw_params = snd_usb_hw_params, - .hw_free = snd_usb_hw_free, + .hw_params = snd_usb_pcm_hw_params, + .hw_free = snd_usb_pcm_hw_free, .prepare = snd_usb_pcm_prepare, .trigger = snd_usb_substream_playback_trigger, .sync_stop = snd_usb_pcm_sync_stop, @@ -1758,8 +1791,8 @@ static const struct snd_pcm_ops snd_usb_playback_ops = { static const struct snd_pcm_ops snd_usb_capture_ops = { .open = snd_usb_pcm_open, .close = snd_usb_pcm_close, - .hw_params = snd_usb_hw_params, - .hw_free = snd_usb_hw_free, + .hw_params = snd_usb_pcm_hw_params, + .hw_free = snd_usb_pcm_hw_free, .prepare = snd_usb_pcm_prepare, .trigger = snd_usb_substream_capture_trigger, .sync_stop = snd_usb_pcm_sync_stop, diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h index 388fe2ba346d..be2dd9478982 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); +const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, + 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 patchwork Tue Feb 13 00:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271615dyb; Mon, 12 Feb 2024 17:37:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHh+MxRKPG4L6VDrjlxDIiQpUMef8k1WZDCAQqtgCGSWacjdTMhN32iz9NQ/IXGs8nHFkdj+CgJCL8bP88BHgEVuNXxw== X-Google-Smtp-Source: AGHT+IGHBn+7KdwS1wmYBQWNjVo5jaa1jXZR8LZp5g11TSvkztZ0R9MxCMyzL6zYtgIC/h5QzT+0 X-Received: by 2002:a9d:6d81:0:b0:6e2:eb2d:6031 with SMTP id x1-20020a9d6d81000000b006e2eb2d6031mr3638412otp.28.1707788244843; Mon, 12 Feb 2024 17:37:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788244; cv=pass; d=google.com; s=arc-20160816; b=Zs+UPCOfrouiWIcsYRyky13mWL8wmf4m0+2/i1anfP4LFWLIzsA3SoqPd4nh1W5iPl 6PHRyS5FPdWlRrDqYesaojzh6Eln3DrDqj+M5MHSTCojg+G2hqMwXIl/xLo5t9t8CphQ THa29a4682x1krL6g13V27DsKMdzsRelSzlc0GJWwVkCLdf8/m7o1m0TgEKdJKK5JXKl QeC6t6iSRO585m6R5+RAyNvim0CZnazk/z/v7z8ozMiBKHAEa1KQoelDauVS8AM09dCm F6z2fgFz6iFFU80qE4PAqM9Tex0JmKu4AoZNaldiW6BmPETdLeg4hRDasXxZ+GEpSUop omeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QAId/huwU+vLycR1v5ldlqmYb6477nfIMJClVSaqa9U=; fh=3/ynYzB0JTakAeyL3B+enh5m6BwHqq0JpUgjrT2x+z4=; b=OOFBiPVp0mNRXwa2jht9Wb48tThsGA4MJm52E5mItsxUz0/ZLKl59h0FgvsJ37Ocgs WoMjOcDHy3o3n8Gc5eorgRiZH8p3H/w8saqDkV6OayjmPOfvw0iLk9MAJI20D4HR1Te7 uJUxTZ28s//krrNn60rk1Y3Za2VUIBoAfyD640ZngHYpxk/yMkjfMN524Tva6QdHuusO SyhdZBkR/aglsrhKAGqIUufr1X9Vw7rIm3lQAPVbTtFs6P2C4vxCxr1hbMGpmypsV5zH bCxNpHGSBKdq22kpuqElAX6BxT7N6N+MfB7DxQlxDTbfw9v2oLzqTZQzKm/KQqxz+jQH Y5LQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="pRrD/Z4f"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62781-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62781-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXZhAn3JxyJm+0fJIayOTAu+Dif5oweMuFHUpvQkiJY65JxW6v3+mxDjhu77Z8aSUyhlgy3ObbXqLID24+rbR2gULYQRQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n68-20020a632747000000b005d6a99217dasi1051258pgn.403.2024.02.12.17.37.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:37:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62781-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="pRrD/Z4f"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62781-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62781-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 09A2728AC91 for ; Tue, 13 Feb 2024 01:27:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 090BD5DF23; Tue, 13 Feb 2024 00:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="pRrD/Z4f" 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 C98C71DFD5; Tue, 13 Feb 2024 00:54: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=1707785697; cv=none; b=bPWrNMgrRe1iHjshMKly2SlzaSMXidV9q42WMTKgntYUc5szmvCUAimF+OcuKoHzweHUjxQ/GqCn2TaPiNbcIV3T4w90+9NKM76hL3kkaDDnFA1y9+OwPrG4aNTtE+fh4kqNIXypAFNi+eJFCputOXTADzw6IhGiQgs26XrE2Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785697; c=relaxed/simple; bh=e35zs7ZNspt8pL25lL7WgCnt43ssCmNv3V8Typ76tw4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mevwMJX1hc0HX3TZje2KR+t58wSuHKtJAHN8vGeOqqxdFuaBHczQSzHf4H0wW6xytR3Gx4kbQ5w8EJl7U+dAkc8y7KjqCgCZjIsruy5NHjXseCtHSFCWfKE4mUFdmaOJclhleDbzPcY5JPgUAWQONsGCjIw1w9Xb9/7tl7kmKeU= 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=pRrD/Z4f; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0LtHO014228; Tue, 13 Feb 2024 00:54:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=QAId/huwU+vLycR1v5ld lqmYb6477nfIMJClVSaqa9U=; b=pRrD/Z4fg7n51QmTvfXxMLzwXrPw6WQyRlFh MSyMUVSETuSaZxn41t4C20sGNTbIVTHwh0/5HpKvwsEmfMTCdIxhphIAjrmsyl5n kB7A01U7sUQpAXrpTNPaTT/L5pPpFgAW4myQmUNwD92TZI+BpdpLGeWOtelC79p+ eAR7/JNpJBzG9d8jAazc1NDwYzTS7a7NNpB2pGLVjF0wZWyuH66177TgfQiYIKE5 /f0xqNNX0E1LBFmeXqvXIsnmKjjZmwz8JpbV4oPStCS1n/9QruzE4mWAkrQ1kv5h S5Ln/lOE2Y0x+CrmOA03+2ZmNEcfkaY9SDczlMRPf7EExkL47A== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sd9G030030 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 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.1118.40; Mon, 12 Feb 2024 16:54:39 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 25/50] ALSA: usb-audio: Save UAC sample size information Date: Mon, 12 Feb 2024 16:53:57 -0800 Message-ID: <20240213005422.3121-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: mvbFW4OTHkV1wPj_w3ATjeLzaSmVY9_L X-Proofpoint-ORIG-GUID: mvbFW4OTHkV1wPj_w3ATjeLzaSmVY9_L X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745766700495672 X-GMAIL-MSGID: 1790745766700495672 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 exisiting parameters. Signed-off-by: Wesley Cheng --- sound/usb/card.h | 1 + sound/usb/format.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sound/usb/card.h b/sound/usb/card.h index 2884912adc96..02e4ea898db5 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 ab5fed9f55b6..1721e4f360fb 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, } fp->fmt_bits = sample_width; + fp->fmt_sz = sample_bytes; if ((pcm_formats == 0) && (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) { From patchwork Tue Feb 13 00:53:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200122 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp267242dyb; Mon, 12 Feb 2024 17:23:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYUCZPy21/lQrng5OVsEuXx0P7/tfliqn0VZu61IGM6Hzdsik71NQnhJeTAnB01T0fvxYnjvDsOH9XK8agMUfce3YXyw== X-Google-Smtp-Source: AGHT+IFKeOnAO/DewZcPGONVcuXf1YXyJIxNYOxHohDV7AapkKaKJgDmUX7d28wNZgfTxCfYS9bq X-Received: by 2002:a05:622a:170f:b0:42c:6bfd:daf3 with SMTP id h15-20020a05622a170f00b0042c6bfddaf3mr9672737qtk.26.1707787395503; Mon, 12 Feb 2024 17:23:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787395; cv=pass; d=google.com; s=arc-20160816; b=za3DXYdXyMHBI0UYFCwf5zyr4x1uaENCoZqlyYEgyI4PmlHrTF/uXC8PihNhBc/d6a h/Oaz3pNPa+71gVxeL1C0/WOftpfAYRIomrqMDC5Eqgfl3cTJH0wfHqWxHgOUqsOCTNG UKvHy0zqyEwlTOKcWvyCPZQHzdzDh5noXZQ/FQrVb0PgdK1RUId3vDtmylWxPXbUN8aH pChk2YRB89EEYc/+kDQ+TJD4By5Syqfb66sQQEFLOoWLJaapbfmf/M+UDLbkLIPO0wD2 sTofWwnBsAo/uzIGAhjeLzJBhuNN1n3kDIZbb9wowYNB6mGG+3FgP3PZcLqFBtEHnZ5r Ofwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b6o1DZWRuc04fm5lKH0e0QE9KkK0X5y0QOEParzZU0g=; fh=WlU3PYVqiu4mvMQosPI+V836IceNWdNOQGz6PtGWPUc=; b=QX+TMonZ7RIPwtzU5udBwAziOQvcFC4R2kgEaIEdOwTTjuKVRWTsYnV+le9ejvsQsj ANODmdx6HlXlWM7+s9Az75CySmjP9okfVc0/NFCH/nD6M5DPQQ6sxXfNXH1396McYBMP X95ss6U5c6WN6auw4ZkqQioA0uz2DjumUxDq8hLQU8ENXZjTRJy0Lcq4NUBMrQA7DJJw X+hWAbJSOUeHmsfVgFgXjQZy8SgWn+STK/ACCM9mgl8BwXQ/xjCgk8lvr1UF4z11U1QG s0+5ltjNITlebVAjDwXzEPUrCGFAhRtpN6aj82POZ/EQE7E5Sak+45kEucta3k+l5YyU E5uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Ij6nkd+J; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62779-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62779-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUrnR0d4GWNSkAKzHHwH5672Hl+547q44XODzAJnIn2y3OiEb5SiwnT4djL0k3nPfl2xEYiHIiwfGQew0rTAnfa34sjKw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i15-20020ac8764f000000b0042c3472845fsi1673048qtr.329.2024.02.12.17.23.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62779-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Ij6nkd+J; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62779-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62779-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3FA681C2448E for ; Tue, 13 Feb 2024 01:23:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5647755799; Tue, 13 Feb 2024 00:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Ij6nkd+J" 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 BB6161CF9C; Tue, 13 Feb 2024 00:54: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=1707785696; cv=none; b=Jg2uJEtRqifXNW1HpquVJRAZLR79NAefq5ig2Ci4Ki+wXfpwmr8WJwv5s2H/MZWlaSDrEBnc3GzNvH6xf0sWU4T1lQbJuJTfA3ccooM+kqXbIukosCt3SXugbQvMsy+og9jNXLehH+0ZkJj+Y6oCLmyUsVZeBt1hCLGjEfDbcKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785696; c=relaxed/simple; bh=/yIRGDVuWTwN01jjLu9D99BsT38c9Fll4aPsKtVd2WA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HCv7kdjwqo1/f9tP9J+wHF9aqSBkNE7uY6PTV0dwzRSJ6Nf8sv+4wSgp7hYPPOVFFJIKMng9mOPOmrKrGkQsmZ0etpv8bKODDAxVXl0G3lBf9xXAYE3Z8Cg+/2cK46aiA0fRWZ8FkL6E6kDDwuk0xzB0efYziltqVPDfARGt8tg= 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=Ij6nkd+J; 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 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0T4pn004845; Tue, 13 Feb 2024 00:54:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=b6o1DZWRuc04fm5lKH0e 0QE9KkK0X5y0QOEParzZU0g=; b=Ij6nkd+JU/YbmpmMEevH/yqEDiQZRwRjvDrr UMpb6GDmTIBtlx3iYqnhWv+aR6Kn4MNlHnkUBUru2xuI4rj6RKAHDODwaR0nu8Rl mdq6bNdi/3yxlr7gObxy8+OdlSXuiRu/49udMtWW3E7jWCBB6C6udG3Vobjwt4uX daK/2O6MQJyQ4olKf0EkDsEe5zSywEcLeLm/5desg/y8FG56Q6rMjAWPNLGI2cuo f0/DVKc+e7R2xPjCOLgrLF9B/4q5VW0cAxxe45hMObNi82LepK7tXLM5/ZtK4hDq h6fkOsOQCj0rYM88QLGT+kmqEDfWGOKZphC2qzm9OeXTPuUoUw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ww5r1ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:41 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0seRD031312 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 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.1118.40; Mon, 12 Feb 2024 16:54:39 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 26/50] usb: dwc3: Specify maximum number of XHCI interrupters Date: Mon, 12 Feb 2024 16:53:58 -0800 Message-ID: <20240213005422.3121-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: cSb6GnVAs9v29iuJDncwqtAwV4GN7f6_ X-Proofpoint-ORIG-GUID: cSb6GnVAs9v29iuJDncwqtAwV4GN7f6_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxscore=0 phishscore=0 mlxlogscore=817 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790744876015736099 X-GMAIL-MSGID: 1790744876015736099 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 | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 3b68e8e45b8b..7ac02339458e 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1485,6 +1485,7 @@ static void dwc3_get_properties(struct dwc3 *dwc) u8 tx_thr_num_pkt_prd = 0; u8 tx_max_burst_prd = 0; u8 tx_fifo_resize_max_num; + u16 num_hc_interrupters; const char *usb_psy_name; int ret; @@ -1507,6 +1508,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) */ tx_fifo_resize_max_num = 6; + /* default to a single XHCI interrupter */ + num_hc_interrupters = 1; + dwc->maximum_speed = usb_get_maximum_speed(dev); dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); dwc->dr_mode = usb_get_dr_mode(dev); @@ -1558,6 +1562,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 = 8; + dwc->do_fifo_resize = device_property_read_bool(dev, "tx-fifo-resize"); if (dwc->do_fifo_resize) @@ -1649,6 +1659,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->imod_interval = 0; dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; + + dwc->num_hc_interrupters = num_hc_interrupters; } /* check whether the core supports IMOD */ diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index df544ec730d2..a851ea0ea2c6 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1068,6 +1068,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 resize * @clear_stall_protocol: endpoint number that requires a delayed status phase + * @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 @@ -1305,6 +1306,7 @@ struct dwc3 { u8 tx_max_burst_prd; u8 tx_fifo_resize_max_num; u8 clear_stall_protocol; + u16 num_hc_interrupters; const char *hsphy_interface; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 4957b9765dc5..3abf3b7d7c88 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -105,7 +105,7 @@ static int dwc3_host_get_irq(struct dwc3 *dwc) int dwc3_host_init(struct dwc3 *dwc) { - struct property_entry props[4]; + struct property_entry props[5]; struct platform_device *xhci; int ret, irq; int prop_idx = 0; @@ -158,6 +158,9 @@ int dwc3_host_init(struct dwc3 *dwc) if (DWC3_VER_IS_WITHIN(DWC3, ANY, 300A)) props[prop_idx++] = PROPERTY_ENTRY_BOOL("quirk-broken-port-ped"); + props[prop_idx++] = PROPERTY_ENTRY_U16("num-hc-interrupters", + dwc->num_hc_interrupters); + if (prop_idx) { ret = device_create_managed_software_node(&xhci->dev, props, NULL); if (ret) { From patchwork Tue Feb 13 00:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270399dyb; Mon, 12 Feb 2024 17:33:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUX4csXg1GbmeM/4BzkJfHd68P5l7gzVNrWPIzzGctZ8FRa0j7UTh1tXTZkNLGcjs0h2H83mh2WQU1vIgOGvsxtK88rmQ== X-Google-Smtp-Source: AGHT+IGddSH+j+cR+Dhtc9VILA3l6UlQba1Sm2qQb+V3l13LoHlPVimOLldZGJvYmeza6A7am8Ki X-Received: by 2002:a05:6a20:3b96:b0:19e:2688:f483 with SMTP id b22-20020a056a203b9600b0019e2688f483mr5182615pzh.43.1707788002946; Mon, 12 Feb 2024 17:33:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788002; cv=pass; d=google.com; s=arc-20160816; b=T9+dtAVzZqMVMv0nN85rKQGfqQUa8KQvGCr1Vm4IP4UY5gwQ6yr2Ezy+QN5xikAkqJ fF9sulyEzT+FgjK/u133Q5fl3YrXCHJ9J6hTEYcP0OH5SWLphQu//YEt7uKmcf7O8bsb aAbVt1K7I6xKQC+xMSW3uK+4IXjRCszT03AjUstpXf9UuJvwfOtABLHeGTy0rEyYEeG0 RFygzM/IRuqned2cZJvZH28fYyK1t9c8Tac3fEhpbBQZlaZ57RjSPF+FnjtqHyrcVpVn VC3xNrajPXdhvbG6cr9o5rmMQXkD1pYnV0CwTnuQLuRqiipQLAMsQ+VUx6KOhaZHBcxH M4Kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8G+8heZ1+RWqkfMIHEmoONeKrV6MuHsqsw1D8O8H9Qk=; fh=4f0dxbIqooUtkyA67EPDHZgFK9HEGDDvK8RpWJ9ENT8=; b=uvHGGqaAK8aIYQV01pvexc8WHFJgldghgQtB5k0K1Rl2tRxgx0j+C6Hd4GL1XS8rGm ZDUB132/hZ1cC5+xRgGIghUfSVTT6VqLpmApRQTNGm1bIp6FEXqiZHdizNlsYBQpwyRR A5OtqjUTY5rFO+atG0zubVlyBkmTo//ReR1KCeC/z2VEvv36AML1D0UyPmNLi02oUeD0 3AdD+Q6lzux1ySl15kx27D6/WmQf0gkD3UvfMCcBtbDkUVN1xvAvu3GBoZCD8vSKBhwm rufNF788OCZwnKhyDykW1u+vRpqLrF9bNLm2zKenRE/qKShbuJ+G2FStCi9lob23q4sG yKog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CWRm94Xy; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62805-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWYYSLrcyWtKlkw2lCTpHd29WLsY6yobZPnxrZHje/4EhBZxHmJBjoi8dubWcDQWdcoL61DO41O+jawcrY6j11DFz6Qkg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o4-20020a170902d4c400b001da15580d28si1126006plg.552.2024.02.12.17.33.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CWRm94Xy; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62805-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B158028C643 for ; Tue, 13 Feb 2024 01:33:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3956B60EE9; Tue, 13 Feb 2024 00:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="CWRm94Xy" 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 EF07254667; Tue, 13 Feb 2024 00:55: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=1707785704; cv=none; b=dPzgLBbySttxRGLrhEVaG8jzSntL593lYOgg6/Ltvml/7M77Qp/Shse4wmJXhwBFUruD/OOMNx+lqB++8jn0HgeGWkBjIVSAvDe+AlueHp39RsHd0OtireF33li8ODHf2Bha+r4Yq0g85e73ZUcxzC+cq0u1uCfP+agDH3voIQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785704; c=relaxed/simple; bh=ymj30Zx1dbYTRAyB5Kax/JPfqIskBJp3/VM40Po124I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RqMKhyNKWPBIIULbUugaYBAY4ST2gTJXzz8lBXJOPtoNnmSzO/5YVtwqhh/rwH2ZqgRFPZs8FTV3kgvzo5Nvz0Srxpgor4HyMbS1kgfwfAQoa6INso9+DIzHBdRfyzG+glz/TK1XXJT7FMSkCm8GVMkMf6Q4ZSl+2BYAGhmu7fQ= 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=CWRm94Xy; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0fmL0006003; Tue, 13 Feb 2024 00:54:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=8G+8heZ1+RWqkfMIHEmo ONeKrV6MuHsqsw1D8O8H9Qk=; b=CWRm94XyRg9ojLX7oHEpoZaD2GL8c/LvofoJ WPT3KthXMF3xE4CfpQQVFY3nrGcueD85VsujkVjPohiOS4q0Ppnk/CZOFzZp9SVK 8FS7+S0XaWIkuN/+zGu+6w1eLLSB7+gc0E2GD83lXed5o4RzCG2QpShdQf+2hNb1 vMIqBCYDS+9nDyGxPkDHsIv0txGp/mdhS7PQDEws/j92QI6nc3TdfLB46/EPItVr 2RH48a0YJ5OJI2U4Fd7GEWSE80F+9vJ7H3UxBQegvaZv1mxqqpYNNH4jQBUYyk93 BPCNQbHEzWNv3E62v3G/hrRWkWtNtj6XnMgwn0xgEH/sIqZ7Yw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7wfy82j3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:41 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sePA031096 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:40 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.1118.40; Mon, 12 Feb 2024 16:54:40 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 27/50] usb: host: xhci-plat: Set XHCI max interrupters if property is present Date: Mon, 12 Feb 2024 16:53:59 -0800 Message-ID: <20240213005422.3121-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: pAq0IOHCmCLWDRFZdrl1Y54feaf8GMF4 X-Proofpoint-ORIG-GUID: pAq0IOHCmCLWDRFZdrl1Y54feaf8GMF4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745513247959125 X-GMAIL-MSGID: 1790745513247959125 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 f04fde19f551..54719f473130 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -255,6 +255,8 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s device_property_read_u32(tmpdev, "imod-interval-ns", &xhci->imod_interval); + device_property_read_u16(tmpdev, "num-hc-interrupters", + &xhci->max_interrupters); } /* From patchwork Tue Feb 13 00:54:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271718dyb; Mon, 12 Feb 2024 17:37:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPciqeI0aFzLMimhsFuMWMR0IlDKBLYyBXkQ2Gj9IYIY9UuCCpcX6RqGYXE9CI+/MQ5XFJenrtaOBolMAOqCV3uvtdZA== X-Google-Smtp-Source: AGHT+IGsngwnoIPyDOFya1M/RohHRZCXrVEJptb3H+9+08tIyUBfC/f0pFbmdAYIY2YYZ7F2SOqn X-Received: by 2002:a19:740c:0:b0:511:878b:807 with SMTP id v12-20020a19740c000000b00511878b0807mr4012363lfe.3.1707788261917; Mon, 12 Feb 2024 17:37:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788261; cv=pass; d=google.com; s=arc-20160816; b=n4By4cfE1ImMAzSSPacMTMZ1Sr3Ji1K/f+4PrRmMWdoufWD9s9BbeU51n0T1pl8RQH H5NfHsApGxTGBlFx4TZn8cRjtY5RviWvYuzW/KEdr7br/l36UoIGY2ic1GCXM2e4BwsN XPQqsYPP966PPUmETiDswuJ+vm4xbIZ4qoMZfLHoyJV4bEifA4E29LWRCAR8wkWMAE/x Lxu3d3d0bQzBmyqc5UuddWU5eT+aP9Db+ErUFxpXEn0v8/zF7Y4DI3NHgWT3LHEq4MgZ N0d3d3r6Hemp3x36+zOkPJdl9y9DX4A55Dm15Yf5BCKYJrDMr1voqmnPxfFBjWxijWoq 073w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ftIPv3vDkOgpufjMyP6nlsgHBVR2qo5YKDjyF5u7Yks=; fh=rEQTEwu/vnoI066OL+RPeJ4t2XU9lszNk7l2Nxgg51g=; b=YHvx0txaOx0eWgngJNiOi+ZAYyEOp52m4dsGJYfGIksq1Wl4+NJbjiT3DjUqbU8Rvi /aZR6owkcEtEvDO0fbExd57yKKO0NiYfh/+4DS6Gi0ggSrQQ6yrzKReTNm+SWkM+WeaC 2ktYiP643iHElAZfU9RWkMFUddkAO4SI0TkqjyiYCiv/nsYgM4jBaCCkQ1J0Px0F3fzx mQx7IEAnczaCgqCfCV6mmnon64LUXO1vcciK72HoqTjbJi2hbvB54s+Ehcxj7yDtwUtu 7IJppTsRmJTfxjMjGY/yPkHJ0log0QanJtUGhl1MWpPsRmX4hX9YOOYOLXuxOvHMkE0u 45og==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Q52A2DaT; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWBr1AyXt5kOcl46tt+PcF8hTlzy4qKUw83DpD+0s6uBK4fkKylxamw/z/UcuUyxyhtP54S5bH3jdC7f8KI+MPEUcz1NA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v18-20020a1709060b5200b00a3cb690a6bdsi742515ejg.747.2024.02.12.17.37.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Q52A2DaT; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B18181F22D83 for ; Tue, 13 Feb 2024 01:37:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2F8A64CD3; Tue, 13 Feb 2024 00:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Q52A2DaT" 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 6552154F8D; Tue, 13 Feb 2024 00:55:03 +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=1707785709; cv=none; b=RhEXMUNXd2yPKIyrd2jbivewlvZj94XFw6iae1J4xvG1yWcqttj99vnEhetOfZTOB2rnWNTI8d8L2OvE0piRzOBZ8bl37FeEJXW0qqWqzfiuKVwfg+Ee5sUmr9nw079zFkyiF2w6hoEdPJ9LJiLGXRzCMG5/h1CtUE8dawD2XVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785709; c=relaxed/simple; bh=Izt4/N7ZEkpAzZrFRiiSnUIjZeHSUSKt0Zk1ibpDxVA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PF42oWGmKxuCgniDR2Bk1TlmmANsthJ1OXa2AuGSfo6t8ovLrf1JUCJx5C7fVVnKxgPPp4voejdurwx7bBXE4g3CVkNFT2gmVRTgXapZ4jzElCFnK5j/7FnWwu4hx972kPYaCrj9zJUfo2T35yOW1spBlMsU9bstiAmETmgQK2A= 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=Q52A2DaT; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0LtHP014228; Tue, 13 Feb 2024 00:54:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=ftIPv3vDkOgpufjMyP6n lsgHBVR2qo5YKDjyF5u7Yks=; b=Q52A2DaTCoSUzsPLpt76ik6nx8/BYrgSioCj UknloFt62j39fuHfmHYEHQWj/ImYkMwFEWD4arp/efU+dCh6TLBfvNHUuGpO9s7U P5vDV3vQU66owCmKJoNBR5uD6M/luOvH5PqjB2P4DOwJ75oG4D8lCo6vJsiy5Hwy jGq7zmev8LU5UtAmDotX5XaJZEC//BRRW1PE0ycTXSDKO4SIijL0/UcaGaQx8urd UcDqlB7kXbRrxEFlGlher7ooO1CRVfr5TttTmV6vjQ2QNjw2X2vaof7qSMlZHTCl 419GdgjYIGYyxW/JTklGd8/xfbynhzQnF51RRm9hozw0yruvyA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhux9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sfxV031561 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:41 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.1118.40; Mon, 12 Feb 2024 16:54:40 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 29/50] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Date: Mon, 12 Feb 2024 16:54:01 -0800 Message-ID: <20240213005422.3121-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: mXuhZU8Hhgys98ajrjXu3IsGUqPD4dCT X-Proofpoint-ORIG-GUID: mXuhZU8Hhgys98ajrjXu3IsGUqPD4dCT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745784224281077 X-GMAIL-MSGID: 1790745784224281077 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. 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 | 1882 +++++++++++++++++++++++++++++ 4 files changed, 1900 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..4c842fbe6365 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. +config SND_USB_AUDIO_QMI + tristate "Qualcomm Audio Offload driver" + depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND + 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" endif # SND_USB diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 8c657c2753c8..246788268ddd 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -34,5 +34,5 @@ obj-$(CONFIG_SND_USB_UA101) += snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o -obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ +obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ qcom/ obj-$(CONFIG_SND_USB_LINE6) += 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 := usb_audio_qmi_v01.o qc_audio_offload.o +obj-$(CONFIG_SND_USB_AUDIO_QMI) += 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_offload.c new file mode 100644 index 000000000000..af67d219fbec --- /dev/null +++ b/sound/usb/qcom/qc_audio_offload.c @@ -0,0 +1,1882 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#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; + /* idx to last udev card number plugged in */ + unsigned int last_card_num; +}; + +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 work_struct qmi_disconnect_work; + struct workqueue_struct *uaudio_wq; + 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 = 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 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 = NULL; + struct snd_usb_audio *chip; + struct snd_usb_stream *as; + + chip = uadev[card_num].chip; + if (!chip || atomic_read(&chip->shutdown)) + goto done; + + if (pcm_idx >= 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 == pcm_idx) { + subs = &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 = 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 == 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 >= USB_SPEED_HIGH) + bus_intval = BUS_INTERVAL_HIGHSPEED_AND_ABOVE; + else + bus_intval = BUS_INTERVAL_FULL_SPEED; + + if (service_interval % bus_intval) + return -EINVAL; + + bus_intval_mult = service_interval / bus_intval; + binterval = 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 = 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_received) +{ + 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 = NULL; + struct list_head *curr_head; + size_t tmp_size = size; + unsigned long va = 0; + bool found = false; + + if (size % PAGE_SIZE) + goto done; + + if (size > *curr_iova_size) + goto done; + + if (*curr_iova_size == 0) + goto done; + + list_for_each_entry(info, head, list) { + /* exact size iova_info */ + if (!info->in_use && info->size == size) { + info->in_use = true; + va = info->start_iova; + *curr_iova_size -= size; + found = true; + goto done; + } else if (!info->in_use && tmp_size >= info->size) { + if (!new_info) + new_info = info; + tmp_size -= info->size; + if (tmp_size) + continue; + + va = new_info->start_iova; + for (curr_head = &new_info->list; curr_head != + &info->list; curr_head = curr_head->next) { + new_info = list_entry(curr_head, struct + iova_info, list); + new_info->in_use = true; + } + info->in_use = true; + *curr_iova_size -= size; + found = true; + goto done; + } else { + /* iova region in use */ + new_info = NULL; + tmp_size = size; + } + } + + info = kzalloc(sizeof(struct iova_info), GFP_KERNEL); + if (!info) { + va = 0; + goto done; + } + + va = info->start_iova = *curr_iova; + info->size = size; + info->in_use = true; + *curr_iova += size; + *curr_iova_size -= size; + found = 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 = size; + bool found = false; + + list_for_each_entry(info, head, list) { + if (info->start_iova == va) { + if (!info->in_use) + return; + + found = true; + info->in_use = false; + if (info->size == size) + goto done; + } + + if (found && tmp_size >= info->size) { + info->in_use = false; + tmp_size -= info->size; + if (!tmp_size) + goto done; + } + } + + if (!found) + return; + +done: + *curr_iova_size += 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 = true; + + if (!va || !iova_size) + return; + + switch (mtype) { + case MEM_EVENT_RING: + if (uaudio_qdev->er_mapped) + uaudio_qdev->er_mapped = false; + else + unmap = 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 = false; + } + + if (!unmap || !mapped_iova_size) + return; + + umap_size = iommu_unmap(uaudio_qdev->data->domain, va, mapped_iova_size); + if (umap_size != 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_coherent, + phys_addr_t pa, size_t size, struct sg_table *sgt) +{ + struct scatterlist *sg; + unsigned long va = 0; + size_t total_len = 0; + unsigned long va_sg; + phys_addr_t pa_sg; + bool map = true; + size_t sg_len; + int prot; + int ret; + int i; + + prot = IOMMU_READ | IOMMU_WRITE; + + if (dma_coherent) + prot |= IOMMU_CACHE; + + switch (mtype) { + case MEM_EVENT_RING: + va = IOVA_BASE; + /* er already mapped */ + if (uaudio_qdev->er_mapped) + map = false; + break; + case MEM_XFER_RING: + va = 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 = 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 = va; + for_each_sg(sgt->sgl, sg, sgt->nents, i) { + sg_len = PAGE_ALIGN(sg->offset + sg->length); + pa_sg = page_to_phys(sg_page(sg)); + ret = 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 = 0; + goto done; + } + + va_sg += sg_len; + total_len += sg_len; + } + + if (size != total_len) { + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va = 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_info *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 = 0; + info->data_xfer_ring_size = 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 = 0; + info->sync_xfer_ring_size = 0; + + uaudio_iommu_unmap(MEM_XFER_BUF, info->xfer_buf_va, + info->xfer_buf_size, info->xfer_buf_size); + info->xfer_buf_va = 0; + + usb_free_coherent(udev, info->xfer_buf_size, + info->xfer_buf, info->xfer_buf_pa); + info->xfer_buf_size = 0; + info->xfer_buf = NULL; + info->xfer_buf_pa = 0; + + info->in_use = 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 = 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 = 0; + + /* free interface info */ + kfree(dev->info); + dev->info = NULL; + uaudio_event_ring_cleanup_free(dev); + dev->udev = 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 = subs->stream->chip; + + snd_usb_hw_free(subs); + snd_usb_autosuspend(chip); +} + +/* QMI service disconnect handlers */ +static void qmi_disconnect_work(struct work_struct *w) +{ + struct snd_usb_substream *subs; + struct snd_usb_audio *chip; + struct intf_info *info; + int if_idx; + int idx; + + mutex_lock(&qdev_mutex); + /* find all active intf for set alt 0 and cleanup usb audio dev */ + for (idx = 0; idx < SNDRV_CARDS; idx++) { + if (!atomic_read(&uadev[idx].in_use)) + continue; + + chip = uadev[idx].chip; + for (if_idx = 0; if_idx < uadev[idx].num_intf; if_idx++) { + if (!uadev[idx].info || !uadev[idx].info[if_idx].in_use) + continue; + info = &uadev[idx].info[if_idx]; + subs = find_substream(info->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; + } + 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 = uaudio_svc; + + if (svc->uaudio_svc_hdl != handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node == node) { + queue_work(svc->uaudio_wq, &svc->qmi_disconnect_work); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node = 0; + svc->client_sq.sq_port = 0; + svc->client_sq.sq_family = 0; + svc->client_connected = 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 == NULL) + return; + + svc = uaudio_svc; + if (svc->uaudio_svc_hdl != handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node == node && + svc->client_sq.sq_port == port) { + queue_work(svc->uaudio_wq, &svc->qmi_disconnect_work); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node = 0; + svc->client_sq.sq_port = 0; + svc->client_sq.sq_family = 0; + svc->client_connected = false; + } +} + +/* QMI client callback handlers from QMI interface */ +static struct qmi_ops uaudio_svc_ops_options = { + .bye = qmi_bye_cb, + .del_client = qmi_svc_disconnect_cb, +}; + +/* kref release callback when all streams are disabled */ +static void uaudio_dev_release(struct kref *kref) +{ + struct uaudio_dev *dev = 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 increment + * the USB SND endpoint's opened count. Requests to keep the interface resumed + * until the audio stream is stopped. Will issue the USB set interface control + * 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 = subs->stream->chip; + + _snd_pcm_hw_params_any(¶ms); + + m = hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT); + snd_mask_leave(m, pcm_format); + + i = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS); + snd_interval_setinteger(i); + i->min = i->max = channels; + + i = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE); + snd_interval_setinteger(i); + i->min = i->max = cur_rate; + + pm_runtime_barrier(&chip->intf[0]->dev); + snd_usb_autoresume(chip); + + ret = snd_usb_hw_params(subs, ¶ms); + if (ret < 0) + goto put_suspend; + + if (!atomic_read(&chip->shutdown)) { + ret = snd_usb_lock_shutdown(chip); + if (ret < 0) + goto detach_ep; + + if (subs->sync_endpoint) { + ret = snd_usb_endpoint_prepare(chip, subs->sync_endpoint); + if (ret < 0) + goto unlock; + } + + ret = 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 >= 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 = xfer_buf_len; + bool dma_coherent; + unsigned long va; + u32 remainder; + u32 mult; + int ret; + + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + + /* xfer buffer, multiple of 4K only */ + if (!len) + len = PAGE_SIZE; + + mult = len / PAGE_SIZE; + remainder = len % PAGE_SIZE; + len = mult * PAGE_SIZE; + len += 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 = MAX_XFER_BUFF_LEN; + } + + xfer_buf = 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 = uaudio_iommu_map(MEM_XFER_BUF, dma_coherent, xfer_buf_pa, len, + &xfer_buf_sgt); + if (!va) { + ret = -ENOMEM; + goto unmap_sync; + } + + mem_info->pa = xfer_buf_pa; + mem_info->size = len; + mem_info->va = 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 = 0; + struct sg_table *sgt; + bool dma_coherent; + unsigned long va; + struct page *pg; + int ret; + + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + + ep = 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 = 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 = -ENODEV; + goto exit; + } + + sgt = 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 = -ENODEV; + goto remove_ep; + } + + pg = sg_page(sgt->sgl); + tr_pa = page_to_phys(pg); + mem_info->pa = sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + /* data transfer ring */ + va = uaudio_iommu_map(MEM_XFER_RING, dma_coherent, tr_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto clear_pa; + } + + mem_info->va = PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size = PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa = 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 = dev_is_dma_coherent(subs->dev->bus->sysdev); + er_pa = 0; + + /* event ring */ + ret = xhci_sideband_create_interrupter(uadev[card_num].sb, 1, + uaudio_qdev->data->intr_num, false); + if (ret < 0) { + dev_err(&subs->dev->dev, "failed to fetch interrupter\n"); + goto exit; + } + + sgt = xhci_sideband_get_event_buffer(uadev[card_num].sb); + if (!sgt) { + dev_err(&subs->dev->dev, + "failed to get event ring address\n"); + ret = -ENODEV; + goto remove_interrupter; + } + + pg = sg_page(sgt->sgl); + er_pa = page_to_phys(pg); + mem_info->pa = sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + va = uaudio_iommu_map(MEM_EVENT_RING, dma_coherent, er_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto clear_pa; + } + + mem_info->va = PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size = PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa = 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 populated + * 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 = 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 = &iface->altsetting[subs->cur_audiofmt->altset_idx]; + altsd = get_iface_desc(alts); + protocol = altsd->bInterfaceProtocol; + + if (protocol == UAC_VERSION_1) { + struct uac1_as_header_descriptor *as; + + as = 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 = as->bDelay; + resp->data_path_delay_valid = 1; + + resp->usb_audio_subslot_size = subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(0x0100); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_2) { + resp->usb_audio_subslot_size = subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(0x0200); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_3) { + if (iface->intf_assoc->bFunctionSubClass == + 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 = 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 = 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 = 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 parse + * 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 handoff to + * happen. This includes, transfer ring and buffer addresses and secondary 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 = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + xfer_buf_len = req_msg->xfer_buff_size; + card_num = uaudio_qdev->last_card_num; + + if (!uadev[card_num].ctrl_intf) { + dev_err(&subs->dev->dev, "audio ctrl intf info not cached\n"); + ret = -ENODEV; + goto err; + } + + ret = uaudio_populate_uac_desc(subs, resp); + if (ret < 0) + goto err; + + resp->slot_id = subs->dev->slot_id; + resp->slot_id_valid = 1; + + data = snd_soc_usb_find_priv_data(usb_get_usb_backend(subs->dev)); + if (!data) + goto err; + + uaudio_qdev->data = data; + + resp->std_as_opr_intf_desc_valid = 1; + ret = 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 = 1; + + if (subs->sync_endpoint) { + ret = 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 = 1; + } + + resp->interrupter_num_valid = 1; + resp->controller_num_valid = 0; + ret = usb_get_controller_id(subs->dev); + if (ret >= 0) { + resp->controller_num = ret; + resp->controller_num_valid = 1; + } + + /* event ring */ + ret = uaudio_event_ring_setup(subs, card_num, + &resp->xhci_mem_info.evt_ring); + if (ret < 0) + goto drop_sync_ep; + + uaudio_qdev->er_mapped = true; + resp->interrupter_num = xhci_sideband_interrupter_id(uadev[card_num].sb); + + resp->speed_info = get_speed_info(subs->dev->speed); + if (resp->speed_info == USB_QMI_DEVICE_SPEED_INVALID_V01) { + ret = -ENODEV; + goto free_sec_ring; + } + + resp->speed_info_valid = 1; + + ret = uaudio_transfer_buffer_setup(subs, xfer_buf, req_msg->xfer_buff_size, + &resp->xhci_mem_info.xfer_buff); + if (ret < 0) { + ret = -ENOMEM; + goto free_sec_ring; + } + + resp->xhci_mem_info_valid = 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 = + subs->dev->config->desc.bNumInterfaces; + uadev[card_num].info = kcalloc(uadev[card_num].num_intf, + sizeof(struct intf_info), GFP_KERNEL); + if (!uadev[card_num].info) { + ret = -ENOMEM; + goto unmap_er; + } + uadev[card_num].udev = subs->dev; + atomic_set(&uadev[card_num].in_use, 1); + } else { + kref_get(&uadev[card_num].kref); + } + + uadev[card_num].usb_core_id = 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 = + IOVA_MASK(resp->xhci_mem_info.tr_data.va); + uadev[card_num].info[info_idx].data_xfer_ring_size = PAGE_SIZE; + uadev[card_num].info[info_idx].sync_xfer_ring_va = + IOVA_MASK(resp->xhci_mem_info.tr_sync.va); + uadev[card_num].info[info_idx].sync_xfer_ring_size = PAGE_SIZE; + uadev[card_num].info[info_idx].xfer_buf_va = + IOVA_MASK(resp->xhci_mem_info.xfer_buff.va); + uadev[card_num].info[info_idx].xfer_buf_pa = + resp->xhci_mem_info.xfer_buff.pa; + uadev[card_num].info[info_idx].xfer_buf_size = + resp->xhci_mem_info.xfer_buff.size; + uadev[card_num].info[info_idx].data_ep_pipe = subs->data_endpoint ? + subs->data_endpoint->pipe : 0; + uadev[card_num].info[info_idx].sync_ep_pipe = subs->sync_endpoint ? + subs->sync_endpoint->pipe : 0; + uadev[card_num].info[info_idx].xfer_buf = xfer_buf; + uadev[card_num].info[info_idx].pcm_card_num = card_num; + uadev[card_num].info[info_idx].pcm_dev_num = pcm_dev_num; + uadev[card_num].info[info_idx].direction = subs->direction; + uadev[card_num].info[info_idx].intf_num = subs->cur_audiofmt->iface; + uadev[card_num].info[info_idx].in_use = 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.va), + 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 = {{0}, 0}; + struct uaudio_qmi_svc *svc = uaudio_svc; + struct snd_usb_audio *chip = NULL; + struct snd_usb_substream *subs; + struct usb_host_endpoint *ep; + int datainterval = -EINVAL; + int info_idx = -EINVAL; + struct intf_info *info; + u8 pcm_card_num; + u8 pcm_dev_num; + u8 direction; + int ret = 0; + + if (!svc->client_connected) { + svc->client_sq = *sq; + svc->client_connected = true; + } + + mutex_lock(&qdev_mutex); + req_msg = (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 = -EINVAL; + goto response; + } + + if (!uaudio_qdev) { + ret = -EINVAL; + goto response; + } + + direction = (req_msg->usb_token & QMI_STREAM_REQ_DIRECTION); + pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + pcm_card_num = req_msg->enable ? uaudio_qdev->last_card_num : + ffs(uaudio_qdev->card_slot) - 1; + if (pcm_card_num >= SNDRV_CARDS) { + ret = -EINVAL; + goto response; + } + + if (req_msg->audio_format > USB_QMI_PCM_FORMAT_U32_BE) { + ret = -EINVAL; + goto response; + } + + subs = find_substream(pcm_card_num, pcm_dev_num, direction); + chip = uadev[pcm_card_num].chip; + if (!subs || !chip || atomic_read(&chip->shutdown)) { + ret = -ENODEV; + goto response; + } + + info_idx = 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 = -ENODEV; + goto response; + } + + if (req_msg->enable) { + if (info_idx < 0 || chip->system_suspend) { + ret = -EBUSY; + goto response; + } + } + + if (req_msg->service_interval_valid) { + ret = get_data_interval_from_si(subs, + req_msg->service_interval); + if (ret == -EINVAL) + goto response; + + datainterval = ret; + } + + uadev[pcm_card_num].ctrl_intf = chip->ctrl_intf; + + if (req_msg->enable) { + ret = enable_audio_stream(subs, + map_pcm_format(req_msg->audio_format), + req_msg->number_of_ch, req_msg->bit_rate, + datainterval); + + if (!ret) + ret = prepare_qmi_response(subs, req_msg, &resp, + info_idx); + } else { + info = &uadev[pcm_card_num].info[info_idx]; + if (info->data_ep_pipe) { + ep = 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 = 0; + } + + if (info->sync_ep_pipe) { + ep = 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 = 0; + } + + disable_audio_stream(subs); + } + +response: + if (!req_msg->enable && ret != -EINVAL && ret != -ENODEV) { + mutex_lock(&chip->mutex); + if (info_idx >= 0) { + info = &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 = req_msg->usb_token; + resp.usb_token_valid = 1; + resp.internal_status = ret; + resp.internal_status_valid = 1; + resp.status = ret ? USB_QMI_STREAM_REQ_FAILURE_V01 : ret; + resp.status_valid = 1; + ret = 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 = { + .type = QMI_REQUEST, + .msg_id = QMI_UAUDIO_STREAM_REQ_V01, + .ei = qmi_uaudio_stream_req_msg_v01_ei, + .decoded_size = QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN, + .fn = 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 disconnected) + * + */ +static int qc_usb_audio_offload_init_qmi_dev(struct usb_device *udev) +{ + uaudio_qdev = kzalloc(sizeof(struct uaudio_qmi_dev), + 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 = IOVA_XFER_RING_BASE; + uaudio_qdev->xfer_ring_iova_size = + IOVA_XFER_RING_MAX - IOVA_XFER_RING_BASE; + + INIT_LIST_HEAD(&uaudio_qdev->xfer_buf_list); + uaudio_qdev->curr_xfer_buf_iova = IOVA_XFER_BUF_BASE; + uaudio_qdev->xfer_buf_iova_size = + IOVA_XFER_BUF_MAX - IOVA_XFER_BUF_BASE; + + return 0; +} + +/** + * 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_device *udev = chip->dev; + struct snd_soc_usb_device *sdev; + struct xhci_sideband *sb; + + /* + * If there is no priv_data, the connected device is on a USB bus + * that doesn't support offloading. Avoid populating entries for + * this device. + */ + if (!snd_soc_usb_find_priv_data(usb_get_usb_backend(udev))) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + if (!uadev[chip->card->number].chip) { + sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); + if (!sdev) + goto exit; + + sb = xhci_sideband_register(udev); + if (!sb) + goto free_sdev; + } else { + sb = uadev[chip->card->number].sb; + sdev = uadev[chip->card->number].sdev; + } + + if (!uaudio_qdev) + qc_usb_audio_offload_init_qmi_dev(udev); + + atomic_inc(&uaudio_qdev->qdev_in_use); + + uadev[chip->card->number].sb = sb; + uadev[chip->card->number].chip = chip; + + sdev->card_idx = chip->card->number; + sdev->chip_idx = chip->index; + uadev[chip->card->number].sdev = sdev; + + uaudio_qdev->last_card_num = chip->card->number; + snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + + return; + +free_sdev: + kfree(sdev); +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 = 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 = {0}; + struct uaudio_qmi_svc *svc = uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num = chip->card->number; + if (card_num >= SNDRV_CARDS) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + dev = &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 = USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id = dev->udev->slot_id; + disconnect_ind.controller_num = dev->usb_core_id; + disconnect_ind.controller_num_valid = 1; + ret = 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 = 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 == 1, the last USB SND interface is being removed. + * This is to accommodate for devices w/ multiple UAC functions. + */ + if (chip->num_interfaces == 1) { + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + xhci_sideband_unregister(dev->sb); + dev->chip = NULL; + kfree(dev->sdev); + dev->sdev = 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 = {0}; + struct snd_usb_audio *chip = usb_get_intfdata(intf); + struct uaudio_qmi_svc *svc = uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num = chip->card->number; + if (card_num >= SNDRV_CARDS) + return; + + + mutex_lock(&chip->mutex); + dev = &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 = USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id = dev->udev->slot_id; + disconnect_ind.controller_num = dev->usb_core_id; + disconnect_ind.controller_num_valid = 1; + ret = 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 = 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 = { + .connect_cb = qc_usb_audio_offload_probe, + .disconnect_cb = qc_usb_audio_offload_disconnect, + .suspend_cb = qc_usb_audio_offload_suspend, +}; + +static int __init qc_usb_audio_offload_init(void) +{ + struct uaudio_qmi_svc *svc; + int ret; + + svc = kzalloc(sizeof(struct uaudio_qmi_svc), GFP_KERNEL); + if (!svc) + return -ENOMEM; + + svc->uaudio_wq = create_singlethread_workqueue("uaudio_svc"); + if (!svc->uaudio_wq) { + ret = -ENOMEM; + goto free_svc; + } + + svc->uaudio_svc_hdl = kzalloc(sizeof(struct qmi_handle), GFP_KERNEL); + if (!svc->uaudio_svc_hdl) { + ret = -ENOMEM; + goto free_wq; + } + + ret = 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 = qmi_add_server(svc->uaudio_svc_hdl, UAUDIO_STREAM_SERVICE_ID_V01, + UAUDIO_STREAM_SERVICE_VERS_V01, 0); + + INIT_WORK(&svc->qmi_disconnect_work, qmi_disconnect_work); + uaudio_svc = svc; + + ret = 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_wq: + destroy_workqueue(svc->uaudio_wq); +free_svc: + kfree(svc); + + return ret; +} + +static void __exit qc_usb_audio_offload_exit(void) +{ + struct uaudio_qmi_svc *svc = 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 = 0; idx < SNDRV_CARDS; idx++) + qc_usb_audio_offload_disconnect(uadev[idx].chip); + + qmi_handle_release(svc->uaudio_svc_hdl); + flush_workqueue(svc->uaudio_wq); + destroy_workqueue(svc->uaudio_wq); + kfree(svc); + uaudio_svc = 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 patchwork Tue Feb 13 00:54:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270589dyb; Mon, 12 Feb 2024 17:33:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW6Bd5leJRppjc/fqLD2+dPlGhjgJ3GpkWIEWIPIVSeG1E4VxyVViXcCAaMMzgOAynIu9VGVVUfDhWKKV7XfXjPb+Gl1Q== X-Google-Smtp-Source: AGHT+IGuIAUN3Rao9bhACrJNun8eUgQAPbU2hKMBqTssN9L0nx+9+Yxx37BDeU2azE0rKaGCu2Ch X-Received: by 2002:aa7:858c:0:b0:6e0:2da2:de3e with SMTP id w12-20020aa7858c000000b006e02da2de3emr6174830pfn.30.1707788038271; Mon, 12 Feb 2024 17:33:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788038; cv=pass; d=google.com; s=arc-20160816; b=GQjEtIQCzjA7YLNbqWTy7X56Q8nJcLtwyAO89BqgU1d4zT3LsekGQwlqKfRcIzkcDH XIVdyD2pKxL7zhFrr5C3UMbCOvUDEvZeH1E+l+Qz+Zjx5VuQLf9XFpyLnfNReZDU4ZUM RsKTssPb2A3QygM9rM7BrrawH3o2JsjYzx3zPkITPw+RXIC6KVi/X6+Ng5wV+fzZweFr Z+luhY3j1GKQ9DcTuSx2F3OErWS42OawqwA//T0mqmjSoQx88C4cxgP4SRcZ17V8r5Oc kLHu5AxD02gUlRt5y1V7XFFBWf2HfDqKTUhOKLYFPPWGEzzTnEl2/AuMDYhN5Qxi2bCF Rhtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QdqLLEJ7eyarB43+aNmJAB1JDcAmYqox+i5Gv5zD0Uo=; fh=ximzVAOwLdgCv0eKDGjMZ1FqSLLhC7GOk7h939r8T5U=; b=xytwhxAw5Np+BH+D6YSz/jHdSTgqmzvuJz+vmW12F1etahScoAJCqzatk2T4b0gYpG tmsPxX4sqGZaNAbR0gw0v6TMxMl5oFoniGayonlsQ+psq4+Ur+p8lgcLmpPQ26G9aDYS zrqNHZZ425lG38lbE326yWH+fxq2KN+gx3jwj8XQ1PuOCHQez8uUsYk/toUhxMsgiSg6 y6+TCLJ+IlQ1y+ZaQ+X+LR6v+WQ5Yya46XjbH2IL+ZQOVhMYbWqgIgx/9APSYtcCmm3P vVrcbYL9CBWVPk4jf8EostIdXcz0LOzCAnI32SPqWjtp9yohPKGqV4qT40CoOnP3T8oB fiXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=L3ZeXt5f; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62810-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUX+8tc//+g5kMK6/+yVCdNJXl2zEEOUf+QzOiTlQPl0AFRpVmi0dcMtP8NylgGFH6a+tfWLMFLuaO57rhQh/RS19vcTA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o13-20020a62cd0d000000b006e0258617basi5793067pfg.29.2024.02.12.17.33.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62810-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=L3ZeXt5f; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62810-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0C84F28C756 for ; Tue, 13 Feb 2024 01:33:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EB30612FC; Tue, 13 Feb 2024 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="L3ZeXt5f" 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 6557A54F8F; Tue, 13 Feb 2024 00:55:03 +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=1707785705; cv=none; b=qBi97dZbAJY8dHYfxRv43q3H+V/dlyaXcopKDS3H4WD7+6PBCNsxsW55ls6jYmYSLPWusV4WIP0COqVDNbWULLMu+IM1I1C+o3Cxg8bQuDIOrfHE3mAsbqHWZUHvJC+Y9XP2L+IX8GChXft1N2g07mCu53QgjyvI2I/Y2M+63uY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785705; c=relaxed/simple; bh=cppxKdliF/4FwBxjDhHdaLdiG9yMsBqfPbx8LPe/RSY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jTJOC2Xj/6DYk+mWk81g6/sHnDzvNT8hQxVz2/gxcignfSF9HU3SBBgH+5ggMVTQreIhlJyWWbj2RfUMMecqEn+KPWXUqcuD8I5RwYOo2SpzWe/xuiHZf+akXbqrjqrfRnFRBj+CvRtmcHLvsOjLiwh9f2jYcU3Jx+QN/b2bQyM= 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=L3ZeXt5f; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CMjQeP010339; Tue, 13 Feb 2024 00:54:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=QdqLLEJ7eyarB43+aNmJ AB1JDcAmYqox+i5Gv5zD0Uo=; b=L3ZeXt5f7cb5sNxGV4XS31zgdW4mjQpg0mYz ja1lxx3sW63QvPcSqLHOqnTwJv3zMjUJu/d9fB0AJu215R7/HlnbAe7wddogJ4FM WGaT/k5rhLg5THlMuz3sV98Hv59eGkgpA4M9svBG5UJl12zYauWcSDfrA7p/Kk15 tmty7fEcQj+3yJRKvJvXKH6vjhH2Ar943dyKWdcowLisPavwHtFVvCSs/RFckrZK 797AfJm6kva+XE1qOQ4pdguFudwib64MwXQYShtqFvv/HIh3fWlkUGFqNeeQ+X21 cmmuAux3rKyTGAZBrgRklcmKCAmo8ZxT0KUMi9Xo4Q/T0lpcGw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sfxW031561 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:41 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.1118.40; Mon, 12 Feb 2024 16:54:41 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 30/50] ALSA: usb-audio: Check for support for requested audio format Date: Mon, 12 Feb 2024 16:54:02 -0800 Message-ID: <20240213005422.3121-31-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: TdrfinbkKcyynGdSlwrCaESPWKN_AtbE X-Proofpoint-GUID: TdrfinbkKcyynGdSlwrCaESPWKN_AtbE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745549998104080 X-GMAIL-MSGID: 1790745549998104080 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. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 31 +++++++++++++++++++++++++++++++ sound/usb/card.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 7dc8007ba839..1ad99a462038 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -155,6 +155,37 @@ int snd_usb_unregister_platform_ops(void) } EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); +/* + * 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 = usb_chip[card_idx]; + + if (chip && enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &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 02e4ea898db5..4d4a6b09d7e8 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -217,4 +217,7 @@ struct snd_usb_platform_ops { int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); + +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 patchwork Tue Feb 13 00:54:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp268592dyb; Mon, 12 Feb 2024 17:27:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5T+H+jvh+c5aNGN/YzpqBsg74IcdEPemTAhB8QFPNFWkD5Gn0b9a849343PyMfF6e+5UD X-Received: by 2002:a05:620a:22b:b0:787:188e:f15d with SMTP id u11-20020a05620a022b00b00787188ef15dmr2019168qkm.28.1707787669405; Mon, 12 Feb 2024 17:27:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787669; cv=pass; d=google.com; s=arc-20160816; b=pgJ225xIME2mFic9H/9pmC2ofDTSWw89JzmoqFjG/d3JEZx3DATW7c7g29KUqU7DNz rwpdUpep4/GdW5BNABRbCyIPWSZljcWFmAW970D2RYVmCJEo62CDwxDq4v6+OLiH9r2u 1sV+Skn4ZZBvitE3LiXBQZbkARVuTkJ+/H1V5TRCWqFJg30C8JmRj3/Mepjx+TMJ5iLX EzhPY2FKI5GV+Of+CW7R5unFg3AxzTa1w+Wb6t9R3ECEdENLsfRgsn2TvYT66vUVr8iG NxyX92Ai12NDff5B4HwhGWxdw7h9pBTLYe4Z2gnNuJQwhq2gEULaoMhMDtV08VgM/3U/ pofg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hhIHa3SWBsZkrlvmJNicRycOcIZIFBMhAQCmyl30frw=; fh=4FqLgk3WSfjbzSQ2ti+HKgWVHJO93sWebPuiQMlU1+4=; b=rEUmL1R6d86wRbEWZnuboY9ZH8xK4XQScYHd0kog4NP45irEGVWYuuAID8bYEl2cyl pMPsk5XkzB3O3EGi9N1e193m/dKCvF9CLs8e500Cdblq9QtMet7zOxe+3whgvIU5jhBZ RnpjgfbJ2AfAwMUJ6v8kvWys+mnqJf5/l3wWYxsdJMoZDxEjrRpPe1Zt13CySLYbJPNC 6MxnKyxDM1uQ14C7snRQI6fhY3SDcohlxgCzt+G4zwlzQ2EjK6pagG8UvXBNz3x0Gi/l Vwi8dm70WECP2JcqA/sKPxEZsiIFZYErB61rqJIB6YTeerNq37K/z2am8+kwt2IpGpiv E2AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TUerxrEw; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62783-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWS0VpfBa2YzzCQWVXOQNgeE/3X1idGEEHnjhLu1woZ7y68pn0PL44Eyq4YAVUzMRXhaVT7begqGqwqTeNsnsfvehCRsQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m10-20020a05620a214a00b00783f2040be5si7295546qkm.535.2024.02.12.17.27.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:27:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TUerxrEw; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62783-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 334001C2475D for ; Tue, 13 Feb 2024 01:27:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71CEB5EE80; Tue, 13 Feb 2024 00:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TUerxrEw" 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 EE90C2232A; Tue, 13 Feb 2024 00:54: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=1707785698; cv=none; b=ulRtpKi2qlFIGpvjGOfrD0GZa9ymrnVIVgy1/GbJrRGkjL4D8XypodyEgXmQ5uAuUfLAMJKJQMXmOj/OMD1NYjxcZE7YLRrDmkGOUUO2fHLg7vvb/KlsPI/xAY4K/Bbg7DxJ8DaJONhXsX0bTmKuWl+CcXSAvtL1227Dr8QYo6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785698; c=relaxed/simple; bh=avZQi57FuGJuxh3XlCVKmJg47Qvdp7d8VoFrgvxtZi4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NI0Zq7JD+Ich1+4rqcFIYsknQAF02F5C/Tte334gGhRExOD2p/+YIeSxERJp9jG3sHSgKmt1PDz4/sVh213C/aAUwwYVu3UcU52gZ0VP8LVLYahiupqMzWV0dd5txvTq5ZLPt3kLca41RUus0AorVXGHqqGtzIfSL+eq5quFRcQ= 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=TUerxrEw; 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 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0SKZp003900; Tue, 13 Feb 2024 00:54:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=hhIHa3SWBsZkrlvmJNic RycOcIZIFBMhAQCmyl30frw=; b=TUerxrEw2ctMBi7w/rrOo5vGfI1ewvT3z9S0 Ny+JTTSCnjxb6gxUfAC0Dv55TMd+VJHVHfhE034Ez/GUY975RlP4ayoY8Go2Rifr bb0CzzP0RCHwYjBiVeeMerWuhxrXv5rLO4a5tu7S7plMdkMfKUX4y1HMpvcZSoyj rr+GapSzFwO5JSb4hjFmamSsq6JDq00Z1KLRNlcf/l2hA5/+jSOaNrhRlT6x3GMA bQ9Cvzu/Nr3FC71Din5V2iLONmeMB1S9DY612wKqpcS5YTZkxofNOcrYrPnGgrNd SmLeHvmES58aRO4ndV2Hi3HpmQANcrPAmPpt4YleRO4w05clJw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ww5r1ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sf8T016277 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:41 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.1118.40; Mon, 12 Feb 2024 16:54:41 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 31/50] ASoC: usb: Add PCM format check API for USB backend Date: Mon, 12 Feb 2024 16:54:03 -0800 Message-ID: <20240213005422.3121-32-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WtlFOqttDo-UPYpPMtJZ0ee6DW8Bzevo X-Proofpoint-ORIG-GUID: WtlFOqttDo-UPYpPMtJZ0ee6DW8Bzevo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745163229328884 X-GMAIL-MSGID: 1790745163229328884 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. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 9 +++++++++ sound/soc/soc-usb.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index c0cf5d1e9024..2790b51d979e 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -39,6 +39,8 @@ struct snd_soc_usb { #if IS_ENABLED(CONFIG_SND_SOC_USB) const char *snd_soc_usb_get_components_tag(bool playback); +int snd_soc_usb_find_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_device *sdev); @@ -55,6 +57,13 @@ static inline const char *snd_soc_usb_get_components_tag(bool playback) return ""; } +static inline int snd_soc_usb_find_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 a1e0363bd760..e3556c397b39 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -80,6 +80,31 @@ void *snd_soc_usb_find_priv_data(struct device *dev) } EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data); +/** + * snd_soc_usb_find_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_format(int card_idx, struct snd_pcm_hw_params *params, + int direction) +{ + struct snd_usb_stream *as; + + as = snd_usb_find_suppported_substream(card_idx, params, direction); + if (!as) + return -EOPNOTSUPP; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_find_format); + /** * snd_soc_usb_allocate_port() - allocate a SOC USB device * @component: USB DPCM backend DAI component From patchwork Tue Feb 13 00:54:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp274219dyb; Mon, 12 Feb 2024 17:45:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+6ybnU8sVLBrLFnaugyLVJ5DcxJuWyd/KySMfcMFvfzzfXERfR97qUMD9ELeJ9Qe5WV1m7ny1LmU6rMCy5YrtjByL/A== X-Google-Smtp-Source: AGHT+IGxpDxtjucXB7pO2f6n7peyx9Opp63/fzfTwytrkUWfZizFd9abTOTtpEw1qlyS9E6MVVd/ X-Received: by 2002:a17:902:cecb:b0:1d9:90d6:bed3 with SMTP id d11-20020a170902cecb00b001d990d6bed3mr11147532plg.43.1707788730342; Mon, 12 Feb 2024 17:45:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788730; cv=pass; d=google.com; s=arc-20160816; b=Yx56uBklmcrc6UgTB0j7YPMZKrQ1t1nauhw7CjEeHHw1SIUz93KTMODYPiVZ4mlmps f4/3HtgeZl1TUN4gf5/gp1ljUtJGJaczfaabe0uA/3qjx/56Md6bn/FvwkXnFaXP8NJC enx2KW9UVfj3seq2vbPDiRHknWVDnfATk7XKZ06KA0pNIM7EE5sAfFwMLTbMP5ssWy7T 6NlNU/eCvn1nnhCIZ0ta1CBO4CONTFzaYnyATJEj4R6MGewA13wmjskyaFN/KLRgLbVw kNQ7YEhuhk6qW+ao51WKkz3Jt1OB+LIHf2I4kblqyY/o+GaCvj5t/siyqKp4exeV3uCE Mx4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Fjij2G5ZCz2q1GRx9e4EEjDB9mY5WYBmc7zvGN19t2k=; fh=SdZStqWbGmVnV3k9uNKS/UlTgP4+LwHA2SPIc7gcqV0=; b=0/auyBA5AKN+KPP3GqsYCKxMAwOqJ2XF3PiRthPWwHzVj1PLRLRRKwEmDcdxC5XQQP tvpa9M7w4bilT127VSaqBkL/apQUE+E0ErntHBBSU9BuSsqLzwI7s3zUDAp8agSil6yv VrfW7DyxF0bgFknzsbPxEW5dYHlbiIxFQeBi1iJFZswW5DMczX9jca2ukaRDv9BxaRxL R054L2aR42lZL40AufnXZJyHlv2c0CN29F2w9cVbhyfHu+HeE5Kg1BAj0QP9r21xvbzN vNgTyxbqaoPawdcuzXeMmcbnsyPJGFk7Rvn8/NglYyi3v2+SapTkbrlXwexcJyrvFvz7 M6OA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GVgWiiPj; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWIsHYWc6TRkQ3La+jlhjzRkl9KuxjMdUuiKwm0lHg6c0jSZuVgtjpAlM3qhDS3ZVp/xERhBBbRZFoGhU/oI2k197ZSvg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l6-20020a170902ec0600b001d885fa768asi1125325pld.195.2024.02.12.17.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:45:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GVgWiiPj; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62782-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8DB10B233DA for ; Tue, 13 Feb 2024 01:27:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A80755D8F5; Tue, 13 Feb 2024 00:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="GVgWiiPj" 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 9F18B20B33; Tue, 13 Feb 2024 00:54: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=1707785697; cv=none; b=oaj4odeAyqG8p9UAOh+TA925X5L2pS5GTwLj7vrpKulZAtb2OlBFUcv/5rZupE/B9KfgrnxDAQcp7oOF4xhIhv/rQUrK2VUg5llbaY4z8iJxJNt+MUZN+K2qFBjCoqeAnx+d+Wv7nhwjev6n8eHqpEdi9w+ztjT66e4qT1SLwO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785697; c=relaxed/simple; bh=wMg/yooJampZGgA3jnDjM7vmFu2HMC0hTX4YlMJF8tY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V44CuSBfNC42LqxOvyWqsIu3Wtn9vh6CN8EdbgWWjRPQpQNsQ6oLKWYBgjKo+lP9pVHuiH41T3Qmh8+Zx3Dsgt+0qR8rHHqv9DkYWD8vc9803VHxsBwUSnrCpGaJY4kIXyMDcMd+JcpZs4NYgYckNLnVuyfEqm5DjGeQYPutUsU= 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=GVgWiiPj; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CLxhxI025599; Tue, 13 Feb 2024 00:54:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=Fjij2G5ZCz2q1GRx9e4E EjDB9mY5WYBmc7zvGN19t2k=; b=GVgWiiPj2+OxibsXx2Dpp/Ro5y2biFoRQykp R6HCeA5nRycfpob45V+O8C2/IhIsyLUPyqNm1+zEFVWYbTMMX5fHvgrjRFe0a79s ctuHdodNie4z88zzNwP7uYnJ3JT2QdBrJhVvqSwuPKDUQn0cdytUR4+jztmIGUVP tEaQgzFlIJO1OIhRzqn1y4fSKr2Arxk7deUB7tw6kCrHU8kp8hDM++5QOjj9D/0A j0iW5S39w+GlgZOlJ0DT0YwmlRPwOuHdZIffymSfAgDQ+dQ0LQzTbyNAgsEd3+Lq RPpm4jBG4yXvAkw3nInzeVcHRajgfVnSc5YV9w37HxUUV2PvMA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sfx4031570 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 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.1118.40; Mon, 12 Feb 2024 16:54:41 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 32/50] ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device Date: Mon, 12 Feb 2024 16:54:04 -0800 Message-ID: <20240213005422.3121-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: uuhfpC6bPjZdk9Zy2OCFC5NBOs5YI7y2 X-Proofpoint-ORIG-GUID: uuhfpC6bPjZdk9Zy2OCFC5NBOs5YI7y2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746275546032395 X-GMAIL-MSGID: 1790746275546032395 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 --- sound/soc/qcom/qdsp6/q6usb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 00cba1021dc6..833a57deb321 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -46,7 +46,11 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - return 0; + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + int direction = substream->stream; + + return snd_soc_usb_find_format(data->active_usb_chip_idx, params, + direction); } static const struct snd_soc_dai_ops q6usb_ops = { From patchwork Tue Feb 13 00:54:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270577dyb; Mon, 12 Feb 2024 17:33:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6cU8QEeIOAGFYRJDmke8CNtHrdmYGA9fOTQtO6udesXALMsI+9aVdS98PEJHg4O14AqVk X-Received: by 2002:a05:6830:18e8:b0:6e2:daea:1b35 with SMTP id d8-20020a05683018e800b006e2daea1b35mr7136350otf.35.1707788036246; Mon, 12 Feb 2024 17:33:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788036; cv=pass; d=google.com; s=arc-20160816; b=nUQ9FuK1lGjQ17PsPn0DRY9qDgWhESm3mnwJrgEpyLYo2dGa9jyPdn0NjfXk2gJ9Ma dFn7w+ou9Jgr3xokMV42IsvTn9bqh3c6oZ0iZ6jyg8aFebnOXtpKjsHLH9O1RgvXz7Kv zC9Z6Q0gopN30+LBnsY14X3cP7I8cQ7f561AaNiw12LRHLGaQimEZqvUkwIUx/J8dPsm mKllV+Zuln6JBus+OHhPN092WrZEdslXNj08fvhij2L2DiNzHVuCZEycqVKIH5x+iMRn wP3HNZv3cenmNijNxHJAoI/NQzucDrOCpeY87X6LzFDJ18/A3WvOJmtF+wuF2aQIdq4x Bj9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NAUoHGZ4M65j67wMqPq95kfl0u86VFJ/0phYKQEzjDY=; fh=e5dQNOJKGgHiJ5NFrY5FAVAWB6WaUKu7F9sTGijidQQ=; b=PzRwnT6i7B5B2ngU3VmKHYqD4o8tt9T8kaid9EVEs4EjOLOraUE96/nDrcRSYFQKdP N6fgWRl/huAPCOvaht2NfwV+q3PAZWrt9qUCsycqg+d+ybq7nk78m98t5A+SciEOmLnB mUMrPGE6YgPyQTBp9AzRaxFJSzWA3QeqvQp6hM06jFD2GZMz1LZSVLp8T2lJA35QGrKA IChAI/rigeHSQ9H9xb0QyIG0PgE7+i1TqxUu+vWkcfdss1ZxOzdhABpbVS0Epxap+n1c zfdhhsfafBQW6CBt+XFEMyo303ppqq+n4FDxVqtJXd+p5PQkkkBSgliHTWDnOLrmgFHE QhLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VAyNbKvD; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62811-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVMFLj1oEQNLU7bzpSq2ul0qbh9CyNr3gfP+UUgGEU4YFp5EgNm7fOnYbL0FNJtwzxTqgdWhS/hAbfRi/Id1GsOKj9rTQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l18-20020a637012000000b005d45c4f4749si1085951pgc.181.2024.02.12.17.33.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VAyNbKvD; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62811-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EB53128C76F for ; Tue, 13 Feb 2024 01:33:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D5B2612FA; Tue, 13 Feb 2024 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VAyNbKvD" 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 DEBDD54BE9; Tue, 13 Feb 2024 00:55:02 +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=1707785706; cv=none; b=GBBz+EmoS6zbMRat9iiQwMXt9r5r/YyUv2Z9bePwXztXvocclOFwMt/pI/xkKjgXRNd9EUWixu3+qrpXZoxwFO514DkURTP27CVF5+xXJgDlO5ihmeDaYqi+C8672Y35RjWn4gq0XgmrQdcCDia6MyrgZh0hIb78SvztJkmAV+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785706; c=relaxed/simple; bh=Fqp+nqEMA818GJLwPboxe/su73wTeKWl5fU2OQYtsJ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dfPsb4BdTD3aWnjbq6saGqVO5eAODBv5Ut6MFLH24lah0ukfIf7nFcntxQFD4zlQ+rUPTVbzlDOFbBaRE6MHIwceezb14h6kjjwW7fIAcVjd+illqW//YflBtL37FigIz0g17+8ymN4Ufp5O+h+uy26yNpwUFgX0TMm0xgjc6hc= 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=VAyNbKvD; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0093L017547; Tue, 13 Feb 2024 00:54:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=NAUoHGZ4M65j67wMqPq9 5kfl0u86VFJ/0phYKQEzjDY=; b=VAyNbKvDX8sAi14C6UNFYTDfm1wGZtC0kcDO uCSH4a9xvxJ6jcaopLIm0RGA+q+ca5duEUx+vkL9+yfKEJ1kVE1q2kOCYE6etUQj Qzr/gjGxaA5axr3F1/ZlfMc/f/jwErBWITXhwknQYFvABpf9+EWlDvrJ8OHSMRsn nD2oX4qV7bX0kjK0DhYp0H53LoLSuQpW29pFHCjaoWdGEOJA1IXlEnPvYH6uqfsH nipgcP68N3m00x+D4sQVH6Oka5Nc+moBkQ0n79lsUfwd5T3ZjgdjVDvis/YssxNe 9sPdetSCFACKjcakmZ4ju64F7qePImVUUTJrQFrU078/8mtCcQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7wfy82j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sge5016285 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 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.1118.40; Mon, 12 Feb 2024 16:54:41 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 33/50] ALSA: usb-audio: Prevent starting of audio stream if in use Date: Mon, 12 Feb 2024 16:54:05 -0800 Message-ID: <20240213005422.3121-34-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vuqBfeKDwe4JWQKQVnjzzN8pVOnpiAsY X-Proofpoint-ORIG-GUID: vuqBfeKDwe4JWQKQVnjzzN8pVOnpiAsY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745547938228143 X-GMAIL-MSGID: 1790745547938228143 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. 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 4d4a6b09d7e8..2c8c51c8b1ea 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) */ + unsigned int opened:1; /* pcm device opened */ unsigned int running: 1; /* running status */ unsigned int period_elapsed_pending; /* delay period handling */ diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 3adb09ce1702..3e6d33de6ce6 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 = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usb_substream *subs = &as->substream[direction]; + struct snd_usb_audio *chip = subs->stream->chip; int ret; + mutex_lock(&chip->mutex); + if (subs->opened) { + mutex_unlock(&chip->mutex); + return -EBUSY; + } + subs->opened = 1; + mutex_unlock(&chip->mutex); + runtime->hw = snd_usb_hardware; /* need an explicit sync to catch applptr update in low-latency mode */ if (direction == SNDRV_PCM_STREAM_PLAYBACK && @@ -1259,13 +1268,23 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream) ret = setup_hw_info(runtime, subs); if (ret < 0) - return ret; + goto err_open; ret = snd_usb_autoresume(subs->stream->chip); if (ret < 0) - return ret; + goto err_open; ret = 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 = 0; + mutex_unlock(&chip->mutex); + return ret; } @@ -1274,6 +1293,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream) int direction = substream->stream; struct snd_usb_stream *as = snd_pcm_substream_chip(substream); struct snd_usb_substream *subs = &as->substream[direction]; + struct snd_usb_audio *chip = subs->stream->chip; int ret; snd_media_stop_pipeline(subs); @@ -1287,6 +1307,9 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream) subs->pcm_substream = NULL; snd_usb_autosuspend(subs->stream->chip); + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); return 0; } From patchwork Tue Feb 13 00:54:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271340dyb; Mon, 12 Feb 2024 17:36:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVi5xE/G7dPDW0ey8PxfQCchzSkrsv4FVkzT9SkvmJmt6B9AisLhQ4u47PGTY+Ml/JO2cp537TsdKbQHozFPscdfrf3BA== X-Google-Smtp-Source: AGHT+IELk4NKmqqSeIEqw1Gxojvdm+9aP6FA37tngGHnG6NVRQVtZDRJDQlVZNINNuFZ8HjVGzrF X-Received: by 2002:a05:651c:617:b0:2d0:a90b:e4e3 with SMTP id k23-20020a05651c061700b002d0a90be4e3mr4381905lje.27.1707788184369; Mon, 12 Feb 2024 17:36:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788184; cv=pass; d=google.com; s=arc-20160816; b=c+7VqtRSl0JTSwK6Kv8cJbFdlmFyhKvL6ljMj/iybGQUkhnqRbeapuaGByQh22Esy5 eAeWvtCQZ0ipZvY2YoPmdjOxuMauWZAGi0Wxnqf/y15iU13WGmUV4Kooq5VBcfPhbbnj ta5/wf8Lx2KSnv9hnW4NTRLBLUkZvBi/noWXAl2OCi46YoBbukE9zmAMnGXeE+l9JSuO TvrCkbqa7h0+tqkNFDZkELmQXjEXeVdwzXZ3f14E5KkGj6GYbyDwuOk+3AlJ2TQBqMBV 0VbWJTPJjc+PGx5h2yn/WBWw2TDZbOP5KoXK9iOl69tgTZxgoC38thlLYwUqYAhHgEyo iTQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wGyjbtwBQ0jltPebsxqOvKMXQoPB3aFFrhoSoalXCkM=; fh=fOSr/U9yIdaf5DyuAwbcWomNGQ2Z4nIimXJUR8A0ndI=; b=fjG1ukVKI2amhGvdLdT8eqMJGU3fkk+xRwFvpl4dB2nRtvdUz68rwCcUq/bGvIY1Dl us7+1PYLKBNldDznhgjDdWQ/NlwwzLeExKLKJIwNmJatcoORiNpQZRz3+vMr7dAG8aTR 4y6hqWUYboDUtW4vmKlw089MVPTy6c6kHKfItSxQ5vB8ob2Puk3CjSHpIDIKsVENd0dT +otnmoCSiUaMJMUmgcwTnjRF7MD/00XtOMrq40kJTagiMybB0i4ZQSIiHX/1wXR/TxT+ VsQMkGcRcpCbos4Alp4G7GnKpMgtJnWwSrtHvpanerY298LJqr7tFbB9vfL1WxgWodBa /gwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=kQFH+Wp6; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62786-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62786-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU1BRnqFwRH4iGtmQmC+3yBt7PbINCPABQ+WeUSBBCbKXFhhYLrk9Z42Op8u0TIpJRfNr1V7i4oG9Nz2wOFVBvDvPtY4g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qu13-20020a170907110d00b00a3c04bf62f7si751820ejb.479.2024.02.12.17.36.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:36:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62786-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=kQFH+Wp6; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62786-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62786-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BB6641F28C3C for ; Tue, 13 Feb 2024 01:27:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AA605EE71; Tue, 13 Feb 2024 00:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="kQFH+Wp6" 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 526AE224C2; Tue, 13 Feb 2024 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785698; cv=none; b=nUCHOno07c3EsrBMGynTddYKI93qALG0mb9om2EeonRV/1a5Ap5Ob7Nf5FfZ4oA9zsb3vMUrsqPSSGUkUevdvpNJRel4euOgUPlcKjcgnGrrOlhs+mVrqOddAzlM+qp98v9GXMhucz6LxYHZsw/73GLZUVb7KOr5OsNhx6yImZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785698; c=relaxed/simple; bh=px268WXk+l3B9SlGv+cxMo3ljNfa2rsGXtf1IZjb19I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ogyfgMZh1c0f5JiFLgSX8Rrk3mb0XJmtxu8jBa/ECgLZRhOLUmWmkai1ASz8FiHhsbMy1YUJBo4w3PG/SlI2XRQR0yo6x9cU3dHUoBK7awo8rQU/dxjM6F/YHgHBX2fh87vZorxlTuRbRa8j+U72mMYPB9XrFe4jf9ln1cisW8Q= 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=kQFH+Wp6; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0r8NU005428; Tue, 13 Feb 2024 00:54:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=wGyjbtwBQ0jltPebsxqO vKMXQoPB3aFFrhoSoalXCkM=; b=kQFH+Wp6btDxu13Ls4XlW+feVzR8ls1mvWjG GFgIgk6Or0hmYUWn0m4mRIo4X40iYoeOOsUZA5jZqtxRwk2jBDGOxMiVb2pCnW7n 9hTNw3VD83C+yWtTL9zRX1go8Iww1q1bmQYU4gN08mnMkzI2oNAuFKTpI+SndE2V aISikBE8tPK5/zHviGfd03qXestegCJIeg1/tF3d+l1AFQgIdCOdkr38qOQqfWXZ mv+NMzPMw9TGx/yUCZ6yva0ceQw1XOOtzwgcWDO2PiCPBiDobaato4MKW2O4zGd2 wlsaEf0+kPo0jxRdooIB/7UOXkjX8O1a0SFV0fBZy92DMRBoYg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sgWj016291 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 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.1118.40; Mon, 12 Feb 2024 16:54:42 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 34/50] ALSA: usb-audio: Do not allow USB offload path if PCM device is in use Date: Mon, 12 Feb 2024 16:54:06 -0800 Message-ID: <20240213005422.3121-35-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: tHFlHBEFnTWLCrkIbGP9XDBLxMqXO3rh X-Proofpoint-ORIG-GUID: tHFlHBEFnTWLCrkIbGP9XDBLxMqXO3rh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=963 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745703113254308 X-GMAIL-MSGID: 1790745703113254308 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_offload.c index af67d219fbec..31c0cf5916a0 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1448,12 +1448,17 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, goto response; } + 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 = -EBUSY; + mutex_unlock(&chip->mutex); + goto response; } + subs->opened = 1; } + mutex_unlock(&chip->mutex); if (req_msg->service_interval_valid) { ret = get_data_interval_from_si(subs, @@ -1475,6 +1480,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, if (!ret) ret = prepare_qmi_response(subs, req_msg, &resp, info_idx); + if (ret < 0) { + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); + } } else { info = &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { @@ -1498,6 +1508,9 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, } disable_audio_stream(subs); + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); } response: From patchwork Tue Feb 13 00:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272394dyb; Mon, 12 Feb 2024 17:39:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVTp77oWarw5nPLGXLjJO3T/vGXAp4NAm2qwBpH2lhi2Z2aR6Rw1bxzPa/gUuSL8dfOR5IhdHrFIMLufg1VT9K24xD9DA== X-Google-Smtp-Source: AGHT+IGBv4aljWQErd4i/9jbGPFwO+o+2t5auOYDiN4cwcw7Yxj2tRwSHPj7VwnF/yD0mRbgbV33 X-Received: by 2002:a05:6a00:189c:b0:6e0:31c4:3f09 with SMTP id x28-20020a056a00189c00b006e031c43f09mr9540902pfh.3.1707788391264; Mon, 12 Feb 2024 17:39:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788391; cv=pass; d=google.com; s=arc-20160816; b=DrxSvNbNEXLt92ze5HVRYMO6QQNuCEP0gFQBrF940Lk3JoAMoqm2HLeVweU8MXBGfC GSKBMMH2AwbAq8K6oLZog5fXPt2V2moAFJ9GRNio76tDPnAYp/wB63A1tY2v9OUNbdU5 jL/W58wYd9gP7xJBI8DInzp2o80+gt8wG9xyz+VlghdVWCsQtQ/xJ2lFmNwOq3/McTKJ /d5+UWKKvB7TJYuHWD3FxjCMNxI6be82xO2rW83SQhF91fdrffpOdgfw5u7aQ1zkFXPu HCNDR0xsE8ZZpxJlpZZgt8voK8kSk2VkGHslSE/azyenp0m0zgQbksrKG3jRC4RANRzX ZHSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VRemWOXPXiXIlDmi9y+GTnchb7p3I7IDu6uqBmXbsdI=; fh=aXcsiD2TssaqMy+wKuED/CbjIXXn+jj6fiBDb7oBJaQ=; b=Sv4vAAFmPAOPxGDgHam/mlcGKGGSO3r39qmhCzZ4WSJEyG25h8/5TTLrS84Izb0QO6 MYUfjK9SIfRcuoLUBdwep5gbzoksKR0g7E4I7MKzC8pvNzwiXEN5kOVJ1bHTbVg388G6 oVM9hhAURKNMe8w7bWpwcwyCxDw/XcyKvPGM5okD0A5Es2DXvhrG23PK+XyHHEmbmIrZ FB52HDnWv175A1iMZfPwWr4elSbWI3xtsWKRpaSpPnE+xwMGYEQCYuoyNNYMNUzRpdK5 5wH/rC7crzb19MMzS9A8OTki0rzIYLg2GoN8zUy0Ctk4vvdWKS/kj/1PA4LKFLEUUa2K sD0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eyRU9uuz; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62812-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62812-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUlrbQpndP6h2OG2/O3BlHrMjy8a4Or72RjTw9/XZsswoF51Ci1r2lF0FdXimOPUXDbP3G2AdWtfcUlnAIEPjfeeLWYxQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id dr21-20020a056a020fd500b005d8bb95ce75si1094872pgb.197.2024.02.12.17.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:39:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62812-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eyRU9uuz; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62812-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62812-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 326E22877A4 for ; Tue, 13 Feb 2024 01:35:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EAA662A00; Tue, 13 Feb 2024 00:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="eyRU9uuz" 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 1CF5455769; Tue, 13 Feb 2024 00:55:04 +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=1707785706; cv=none; b=pa7SG80uk/wsnSpC8uzN4JnlOSdJ6YJ4Ze76S9+xWlurg0i3IzuOb3mRBM5b+vMakwwyYxlKBW3b53BhvywdDiN8Gkzz92uZJYko6fN1FClpXVCpr2WijPj099sl8cXpXRkxg4TuxpeUzKjqm+VN8SpGHLVUrNV3LfYc+3c2FvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785706; c=relaxed/simple; bh=Q9v7m21SznsQRBxoPQiAbg8VdmmvPkGv0cpZczE0uEo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RyKDqSyh2piVpmc/GbSYpf/e40GtVbQ2TaHy5SgClHj6ijIh1EStS7xXtleq0FWxpz+J8LJaUWBEWYgN62AjxGVkiCg024NySf9IBhxWQUyKstKbGz3QqN5v4eN1/9O1sEBElcshgSF9uU7DJNNoqJf08SCvz6AFQAW4F7Oz07g= 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=eyRU9uuz; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D00l8M018326; Tue, 13 Feb 2024 00:54:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=VRemWOXPXiXIlDmi9y+G Tnchb7p3I7IDu6uqBmXbsdI=; b=eyRU9uuzNOwW+q2Qp6545HKAOXSyHsM3cAty mgKN5K+jv1BFaxgu15TwE3yI5kaGxu0wKv6nSeub38pu1fsL7W5u3U3Nq8igbkid YU1m2grdseRnTxhM0byGu+8RkshBzt2uh/Vz9eP9r645ZIm0PpMFVhs7gr3+ZyBv DHEUG2ssSG1PLZl9T6up86otVnScG7qkepcR+K9pA+8UqEE6GHjBnpI8JAQzz9ha PUm1OpaKj+mjZ7l8aPlVIT107u8CXAdidXVVNBDDLt4Ds8ZGyAFuGum5CMQ/SATy t+3NKBmTsk+alq+09wo9ICSh3DvWVBkFqPBRDwxWHPeLTxh0Nw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7wfy82j5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sgw4031134 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:42 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.1118.40; Mon, 12 Feb 2024 16:54:42 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 35/50] ASoC: dt-bindings: Add Q6USB backend Date: Mon, 12 Feb 2024 16:54:07 -0800 Message-ID: <20240213005422.3121-36-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: HgIdYvISWcCrJEvHwu9B1osMThBhrxiR X-Proofpoint-ORIG-GUID: HgIdYvISWcCrJEvHwu9B1osMThBhrxiR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=991 priorityscore=1501 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745920187622633 X-GMAIL-MSGID: 1790745920187622633 Add a dt-binding to describe the definition of enabling the Q6 USB backend device for audio offloading. The node carries information, which is passed along to the QC USB SND class driver counterpart. These parameters will be utilized during QMI stream enable requests. Reviewed-by: Rob Herring Signed-off-by: Wesley Cheng --- .../devicetree/bindings/sound/qcom,q6usb.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/qcom,q6usb.yaml diff --git a/Documentation/devicetree/bindings/sound/qcom,q6usb.yaml b/Documentation/devicetree/bindings/sound/qcom,q6usb.yaml new file mode 100644 index 000000000000..37161d2aa96e --- /dev/null +++ b/Documentation/devicetree/bindings/sound/qcom,q6usb.yaml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/qcom,q6usb.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm ASoC DPCM USB backend DAI + +maintainers: + - Wesley Cheng + +description: + The USB port is a supported AFE path on the Q6 DSP. This ASoC DPCM + backend DAI will communicate the required settings to initialize the + XHCI host controller properly for enabling the offloaded audio stream. + Parameters defined under this node will carry settings, which will be + passed along during the QMI stream enable request and configuration of + the XHCI host controller. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + enum: + - qcom,q6usb + + iommus: + maxItems: 1 + + "#sound-dai-cells": + const: 1 + + qcom,usb-audio-intr-idx: + description: + Desired XHCI interrupter number to use. Depending on the audio DSP + on the platform, it will operate on a specific XHCI interrupter. + $ref: /schemas/types.yaml#/definitions/uint16 + maximum: 8 + +required: + - compatible + - "#sound-dai-cells" + - qcom,usb-audio-intr-idx + +additionalProperties: false + +examples: + - | + dais { + compatible = "qcom,q6usb"; + #sound-dai-cells = <1>; + iommus = <&apps_smmu 0x180f 0x0>; + qcom,usb-audio-intr-idx = /bits/ 16 <2>; + }; From patchwork Tue Feb 13 00:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp277268dyb; Mon, 12 Feb 2024 17:55:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVlcwPhwOspu/QTmssnOm9aqmUF3Brh0osYdukPxFHYvmxW7/Q9f2irZcJkRJRhwPErsZ2gcF/29+oVKl/ttWYy312eKg== X-Google-Smtp-Source: AGHT+IFRLfuwSDvCllCxnfmOFW5KO/DW2S/st/fUacHJk+Vo9vpusbQlzjoxis9Vkq84Z+SeiHKX X-Received: by 2002:a05:6870:9725:b0:219:efcf:4566 with SMTP id n37-20020a056870972500b00219efcf4566mr8298545oaq.13.1707789315999; Mon, 12 Feb 2024 17:55:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789315; cv=pass; d=google.com; s=arc-20160816; b=DTHepAETU64PcBIUP5G2aCAPjs3T0zne9Lenyg8uSnIwsGOryxYqphxIWupwVwIMap /qqkm6gbAJn1pEgKsHFHX8kU9ROnve5ADu0STK7a7sJDYnuvuDBB13MKNIDhOiHUjGfu DMjltlAKx+/Qgy2/Yu/aM0u5kAYeZmVxWsK0wm6htaS8auP6hnLDQFqEmAwPA3IABbFF M2FFMzG6LfcWrC1hfvjN+1xSqL58gFCb7cDJvXmAFqx+djs9F1TrUARitwH14FR1QI7u io0Bc5EdylT96aN5Sxs7hCCAVXhHlfXrTgEG5NZzhGpnE7ezm1iQGXvLFAF6v8F5Frtm JnPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wCcbSWsFpVxj3QLd4HmmfLqNJIIYRPfgAwCjJgT6kZE=; fh=zcI7XPjAskP29hdj2SV8w0nhGXn4ny4aI1uI/RNEMCU=; b=BYeKsuw8kqJcMraHDFrFKWF2gk9pUHBfvmHlBpG+S4yeI86MO88BxYApt6K+TAkNmh L2qqdc08rgigqCY6nKFNtoUjZUG9T5Qlpc6so+W4R+tJFkE1JnZZzFUZTSpTGb1Vq36Z QZoqBu60KGHZ7IZ82b0uDyh6QkXPKPxY9Jo3KDfgZ5r75O7CSFJOQEn/QEpnuV4eRSb/ hIREmi5/p+ZE3BfI+R76yS89lMY6PSni7waJOEpWYCri0r2npFSG3BRYIuj0Q2S2y+6r p+1x8RWTdy4THxv2Ivm5HSWc6bxfXC83M102V9b/dzIDofojvCXgiuxcJQx7IPmqMS0h 0FxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OEZSM7Yn; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62806-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62806-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVwX/GLG6XZvYfvqeFV9rRncz/GoVdxu5+nj2nYhRNQ1hQWLCf2DtPlEhO2GfPKgNd52ZA0nVntkmbQbiSw+QQcRGFZ4Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l1-20020a632501000000b005dbf27229edsi1116729pgl.290.2024.02.12.17.55.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:55:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62806-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OEZSM7Yn; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62806-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62806-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4DA72B28280 for ; Tue, 13 Feb 2024 01:33:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8B8960ECD; Tue, 13 Feb 2024 00:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OEZSM7Yn" 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 5DDE254773; Tue, 13 Feb 2024 00:55: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=1707785704; cv=none; b=gyWur1Ka8JvpjtD61pT3EYIThRxBhm1yhZR9g9+XMllz0kZkxY0I6qDGDEEQtgp4U3gtVi+7y+6knR7hGG+0cjSnAADW/6mQnOip5x9bwE/J/LonG3ZVGrFvJea2ajis6JAoq3rJ1KG3lrTjOVWsWigB6VwGkS4uY4Pgzvag77w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785704; c=relaxed/simple; bh=+XyT6AmPyeGSCzDybpKwWtfIMLvamtKqfXcViqYy9iU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jd6ihgT5lFGOM3bzENG/mOV2gmdTKw7+9ShouSWHhSvg2rywc59DXIgEk6wIcocZ2yTSoyZ0w5QqKuCxwD66DLBorwAwIQ22/mJq47hG0nCrCS0B596RU+88KcpkvHpVex7OMgwExxpYEIKuT7brSpgsc9ChaoBm8yUfOoLPVdU= 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=OEZSM7Yn; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0gRDI017296; Tue, 13 Feb 2024 00:54:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=wCcbSWsFpVxj3QLd4Hmm fLqNJIIYRPfgAwCjJgT6kZE=; b=OEZSM7YnzC2jvLz8Ge+HgODh/bMlBLV+LHlY 6QocGMv0K45/kemn7N28hUHab9dayZjRrcZ90EaxvH2w/15VJIMlsSVoYZrJxQb2 uruQqjUqj0cGG0UEj79gMURYaezcFQisZG5wt4KXJyG+Hrzfo4kRMe0IFRMonluT 5PmH7sLr55C8tCeizTbWpjThImdFHx51fJLwHlQXMja45SU3paKtRNpfL9lG6f/e OXqT43w8G60PyQciR/6C14iSTQjQWo+9kfM0PFVAvBU415pJWGweu2GKUgnhWcoT pq3nL0BDNV4tGtgscAeqVJg+KQq220shn0PWeRLlhnratcI/zg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tyn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0shrt031576 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 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.1118.40; Mon, 12 Feb 2024 16:54:42 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 36/50] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Date: Mon, 12 Feb 2024 16:54:08 -0800 Message-ID: <20240213005422.3121-37-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: P2gtIK4WsY40nniG2zkmTRg6b0mieu-S X-Proofpoint-ORIG-GUID: P2gtIK4WsY40nniG2zkmTRg6b0mieu-S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790746889776938833 X-GMAIL-MSGID: 1790746889776938833 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/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml index 6f419747273e..e78b8b660fce 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -227,6 +227,21 @@ examples: sound-dai = <&vamacro 0>; }; }; + + usb-dai-link { + link-name = "USB Playback"; + cpu { + sound-dai = <&q6afedai USB_RX>; + }; + + codec { + sound-dai = <&usbdai USB_RX>; + }; + + platform { + sound-dai = <&q6routing>; + }; + }; }; - | From patchwork Tue Feb 13 00:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278213dyb; Mon, 12 Feb 2024 17:58:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMBpSLl56FmyPHHLsD8YYRgkDoXEnuW3sBKQSV38xQEBWwEkuoriEpaqEuZI82QqoCCGV/hmdZ7Sm/pLAp6Ub6Putxcw== X-Google-Smtp-Source: AGHT+IGkySZQpt+VTSdZhgvb4TRusT2hLUocJQ4v+Ai5ERkT7qB6e99twFYoGWAe+G+xwhZ48H3C X-Received: by 2002:a17:903:32d1:b0:1d9:6cb4:3330 with SMTP id i17-20020a17090332d100b001d96cb43330mr11163894plr.12.1707789504814; Mon, 12 Feb 2024 17:58:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789504; cv=pass; d=google.com; s=arc-20160816; b=m76Di3Wv9oDTMzb8GvSZlE1rEGyXiIVDfDFjCRe1kzrM5zbN3jFs9ruPi33X8w1Hf+ mQLohu2l491gcvh0qj6vWzaU5/22PYnWdKGQzU22D50O7cDNz7bAbaOhJneBCinkcOnv ESTOMBYZr5Vj12uEVsLmPHq7s8SOD6FTaZ1IniXcQi+AHv9gUWdfnGHr5kyfx9QNr8bL tmENvt12aEslwThT46ES/l4t8xdIKLHGSISN3W8H9lAXQyCjUNSZPew95wbapsQJ06UJ eoURbXvkALeolvMDSDhl7xbuOpl61ECj3Qfn7BfJeulxFOnHvc+FvNwcd0sia3Sfdual SOVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DYlDaoMzMP8hhWYbnbuVllKnwKPUMw5nutuR92LPe2U=; fh=YWjpg2PSm3rYmyVgp8IrmEhOOR9EU37w8Blb9IU0x0g=; b=lLznT+MTAjeOkGHfe5daz4JWNICVAbfueayyJCeBBpchsUmgi9FDsLJ7k4k4UB7nZz O7Bgc/sB5yemL62md6CW/p0KCscioodJZodw0SJo7HNfxy7WWYVd0p5LPdY0Ua+EYHw9 7J2U7HBqRxzWBC1L9a1sfXd20jE9B/P47GUmu0cEJ7Cmot1AhJ3n4fFfyFW04wvWrfQO cBdZMFqhS29RSm//iNjyDhIXE7+oYm2FOhwHlBfRJr/7et4LzbJkVhNnhE3dztqp5ATk ItxV3CMGthC3n5N4bs7aVQC8zfUhANY0RbsbjrsLZhMSvf2TUgVwa68Teyvx3hmtV8v7 cSfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ghJ+1ivm; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62819-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62819-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXoWXRH2miCEwtK6okJUBiVy54lDxPozrCH9SrBYaZmFAJGp4X64iN1W27MykEPLJeIqgFff3Ka/1qV7YKYMXt9+2vjUA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id jc5-20020a17090325c500b001d9055b6a4bsi1125662plb.418.2024.02.12.17.58.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:58:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62819-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ghJ+1ivm; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62819-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62819-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6F91DB2304B for ; Tue, 13 Feb 2024 01:36:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01F156310B; Tue, 13 Feb 2024 00:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ghJ+1ivm" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC6455914A; Tue, 13 Feb 2024 00:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; cv=none; b=dIbFcsr54D/DacyM734l32P5OsFehKBu+Z/hzm+yq3WFruHi/d72JQGb/RBzwfc5kDLxaRh00H7hTCKv4nAN98Eo8KjYj8hYtYl0fTbKCM7yav46YaO182eFLJ9v5dYXkvYdw6/pkqPO9W8qc3TXHiG9GP0vLK8lLhEq54/a7xI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; c=relaxed/simple; bh=3t+oyyObCLNtDcTqp0pGT8TPY42C27S0xw+SlfeDuZ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AOD+EMmd/nKflQ8MmfA/874RogceWcQlPSE7DF7eRXDgr6fZd5C0OUvUu310ROJAmOnPpE0XCAUnmXxOQ9VkH0faa4J6eKqBBCri9zOH/uAHyExg4pWu/eM6dfBRmvz08/TpJGliCXgvqtzWpSE6a4xrU0TBi40Z0wcrg1HUSvs= 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=ghJ+1ivm; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0GkKG012215; Tue, 13 Feb 2024 00:54:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=DYlDaoMzMP8hhWYbnbuV llKnwKPUMw5nutuR92LPe2U=; b=ghJ+1ivmyKilxYdOrWhdXlgFU7cV0lOqVxJb nEexJ/xK1jDCZH7/hqG7Sr1OE5WWI3U4QkJwi9iaWKgZkPZNP0R1LS94MGA9n1yr iWhAjonJZtH4U15XaEL9lv9DcP+I0QgK9nISbUYd9PzHmHKIm18nqM7MFQUpW2dh tH5NEB5dgywHezGymGEGmYSYQjed2riOgXo6u4UOpf6YYTzk4N+JmnsfKLuIrlRn 4EpvKexovlL1uZxzI0SdqY03X8P6mjakGJrfwjTN8+JFXZ4ybPyhrZKJ3YzZLiQp ZBANDOy+Tyv51qZjhzFGACzKAqHzSPdij052ORAfMJ20Bw67jw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7q2y0vvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sh5t031143 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 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.1118.40; Mon, 12 Feb 2024 16:54:42 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 37/50] ALSA: usb-audio: qcom: Populate PCM and USB chip information Date: Mon, 12 Feb 2024 16:54:09 -0800 Message-ID: <20240213005422.3121-38-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: bRV22WulYu8SOK51ErEE8ljXwscoxNiH X-Proofpoint-ORIG-GUID: bRV22WulYu8SOK51ErEE8ljXwscoxNiH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1015 adultscore=0 mlxscore=0 impostorscore=0 mlxlogscore=678 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747087992318524 X-GMAIL-MSGID: 1790747087992318524 Currently, only the index to the USB SND card array is passed to the USB backend. Pass through more information, specifically the USB SND card number and the number of PCM devices available. This allows for the DPCM backend to determine what USB resources are available during situations, such as USB audio offloading. Signed-off-by: Wesley Cheng --- sound/usb/qcom/qc_audio_offload.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 31c0cf5916a0..17cee0cf2ff5 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -172,6 +172,21 @@ enum usb_qmi_audio_format { 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 = NULL; + struct snd_usb_stream *as; + int count = 0; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &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) { @@ -1626,6 +1641,8 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) sdev->card_idx = chip->card->number; sdev->chip_idx = chip->index; + sdev->num_playback = usb_qmi_get_pcm_num(chip, 0); + sdev->num_capture = usb_qmi_get_pcm_num(chip, 1); uadev[chip->card->number].sdev = sdev; uaudio_qdev->last_card_num = chip->card->number; From patchwork Tue Feb 13 00:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270191dyb; Mon, 12 Feb 2024 17:32:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV34aobSuHK0pd8rBvARBENdEm4beV5n9nTukIEq5kA+1HnLqyy79p2ts3Yy7zdxi6yJeJcFYd4tND9Pjl4qvtiGhvPVQ== X-Google-Smtp-Source: AGHT+IHha5G+tijPXQ7DVPdCT+TeGRycWe3vcJMePM/KEbTHSguMzGcZVFibSidJv58/6hKPsGdT X-Received: by 2002:a05:6358:1212:b0:176:9f24:d06b with SMTP id h18-20020a056358121200b001769f24d06bmr10232619rwi.1.1707787971937; Mon, 12 Feb 2024 17:32:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787971; cv=pass; d=google.com; s=arc-20160816; b=ZPLTTQS5sVOTo7cmsns0NlQvcpubPXIvNDlkaknufyS+nYYkcNCHDkDfTxNOnnY3P8 oyNgtF31odZWp6+iEo0zScQu7J4HgEU01AHyN15buhoQIHX3q8N4lL4ruq8kVeKh4f6i HDw1AnyF0OTRxMvnVlrOK0vagNBI1lK9PumAsEMc4UyY0EqGxiuMYpAwawbIrxpBJcI6 +ZOscLfNsPE6jowaHXH3D94YMwWDuYj8exyxFBd5+ZaCgIljuxvjDjjvpHoQKKTMSf0B GQspZ91ZjQhPTA3KQdMpmEwMDzJV6dtY28EZmNCcqkd0jQEURPx6/GUZWlMAJp1/paOD dz0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rknx4yFlGtTVBQ/y80iNV/1i6qwGSOJ39GzerqlUVGA=; fh=RfEB3IN09x+MW0FGJJKdRClqc+7KvIG58ZjUtf82x/0=; b=eLjLXD1DqMRjN1ne02bQvySNltVaLs5W8ot3gXvMNx78afZ6GDKYK+GTLFAAyXPCBQ yN3qIq4hcqGj0SCaMWepJ2F4K3k6cKXvGfkod0sR7yyeqR4GklYouindoJGqriu+8NSk CUyrlNYG5nJcnX8L23vPpUGFnwXyVTIzDdWzxbnP9+8QShDxMwfe2CBOiIPCW8B6XScV xE5AW9PkQt23pMGB9l3s4/OLyI8jieAWhiI4uMETY4OYoDl8h6vsubhcxaHxxGtJxoAR 7ZhKgRfXcGt0w8RR3wUuoBOeoZPo+sU51adZwS9234rcVMr74+399ooqlFe64krRLFFP KMMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Bz1dLKH6; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62801-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUIRmJNSUoN9RLhFJH3JvcGIlfxeGw3vW19/SISe+Bu2gp8EEqJlE0gIrTMlod5B8kR89E0NHJoRf1JB/UHmb+SSsJ7ag== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o13-20020a62cd0d000000b006e0258617basi5793067pfg.29.2024.02.12.17.32.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:32:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Bz1dLKH6; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62801-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AB85928C680 for ; Tue, 13 Feb 2024 01:32:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 425DB60DD1; Tue, 13 Feb 2024 00:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Bz1dLKH6" 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 51AC7381DF; Tue, 13 Feb 2024 00:55: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=1707785703; cv=none; b=niMu5Bz05MB36m93sjFfjvOWd6ZknJRv/dKOoEPGZrQYRN7MLWeV8yxOqS8/qNwENcJ0Dl6ZrZtKWsEEiockKEvIAFz8Il551NLz8RNKvTSDrZmK//0DrQRd0897andEtXLimOAqlRZT+T33k4CCO7esS8dfZJLKBJ2wWFdxBfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785703; c=relaxed/simple; bh=/CBCu7xtzLoC6vN95Vv2nxS4gvDbU4mm+K3QyU75FAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C/H60O+jaHGw9Yi9WNrmxoaMzHrEnyFXQ0nVled+85KFio3kWbrq/7ADWTsuHmRya4k8odaXy7mzEBCkqfN2igocki5qkhSs5EC1uQH60jTvy56cS6LtQMUUpLHB6PqxXPckPQ6MCd1tYl+dst2qWXUb4ajwU9MEGeo7B2VNl5A= 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=Bz1dLKH6; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CMULkP014138; Tue, 13 Feb 2024 00:54:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=Rknx4yFlGtTVBQ/y80iN V/1i6qwGSOJ39GzerqlUVGA=; b=Bz1dLKH6BPpIVv16JP7teGrtUFFG30o9T9cj cns5AnVjp4haZCEVHFaiDhzzHREL1AIUMegSljuvsk17dc4RlBYwyj5eUUkoeUoU yGNiDUTygkGPYTRx1RFw4BY1dAG+uAF4GBoGh3ewy9PMUS0HZzw7NSI/kv0h6dGt L4kVTI/mJA2oFYOvfU0zEhcHAfdA/9xCHAuN1N8LmgGuxSV4zo22YpTEwexeo/N3 PDQgeu6dEyiv1POqBNIrXjbDkU06ztU3S6sanuGMaIgB/MsGHNCby0652vyPMmWY 3kUkwIYy0C8otLcwHrH2S8SJMqK3Q0B48fyqLUABmy+tmq6jtA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0shMi030059 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 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.1118.40; Mon, 12 Feb 2024 16:54:43 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 38/50] ASoC: qcom: qdsp6: Add support to track available USB PCM devices Date: Mon, 12 Feb 2024 16:54:10 -0800 Message-ID: <20240213005422.3121-39-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: QyEi1xdc81R80fnhXLHwtalCXmHLLtDx X-Proofpoint-GUID: QyEi1xdc81R80fnhXLHwtalCXmHLLtDx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=948 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745480281297889 X-GMAIL-MSGID: 1790745480281297889 The USB backend should know about which sound resources are being shared between the ASoC and USB SND paths. This can be utilized to properly select and maintain the offloading devices. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6usb.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 833a57deb321..e539b411c35e 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -27,11 +27,18 @@ #define Q6_USB_SID_MASK 0xF +struct q6usb_status { + struct snd_soc_usb_device *sdev; + unsigned int pcm_index; +}; + struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; int active_usb_chip_idx; + unsigned long available_card_slot; + struct q6usb_status status[SNDRV_CARDS]; }; static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, if (connected) { /* We only track the latest USB headset plugged in */ data->active_usb_chip_idx = sdev->card_idx; + + set_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].sdev = sdev; + } else { + clear_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].sdev = NULL; } return 0; From patchwork Tue Feb 13 00:54:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270544dyb; Mon, 12 Feb 2024 17:33:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHcqhOxbkm43RCP6vX477lu6xkbLl+r+yPaKVSQMFGxpFMCY2BNS+VvFfmeRy14lff+UDi9NTNJU1YXDXUcHoPOEu2Lw== X-Google-Smtp-Source: AGHT+IFvJfE9080cXFgKspR8dMlmtrJ0CTn7PpRdaux07M64LnCMCOlEz9KGGKWfy331U8vSEtNF X-Received: by 2002:a17:90b:8c:b0:297:2134:71d7 with SMTP id bb12-20020a17090b008c00b00297213471d7mr4186420pjb.1.1707788029749; Mon, 12 Feb 2024 17:33:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788029; cv=pass; d=google.com; s=arc-20160816; b=m7vachfXG+hO/iP/MFntD+lOJx63Vq4nNVGXEgwoUN7/IrsmrSj3kejo6gppxItT/P ijY0QRFTc5DSSrPevOx4RnBRRvgiaijQFBNENJvm557laQC31uT+WvQGdVSAieXOCLYq d16Kr/s1mNTyvlonc0JV1auJMTQ16BdOT5HhfU02/CoTh3JfhVcnixk8arhn0WB6+/KK nqL/d0BK/NcTNjBh26kbF7xrKlW4DHrB2planZTBATtFR6Q9TsYNFSp9H93iRkb/qT/y GeQG7Al1QNTCT2A1yZK5pe7akAXrY9arl/UEjgfCNrKAlUnNF7bDdxOjBtyoZNKFwys6 QVJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b5WcYA4M++5hMV1+dtL2ECGuhzTzBXFt95TLOE5PGsc=; fh=8cxcvQqlGko3GQ2gvHKfEjCxwUeTvt8hApJTvO0pNLA=; b=I3v4nq8iQkX8eg5YD8aukZuzQIn60nH9/ijpj5+f+/IU9Vj/Mpxb82mq0xtyWtpAKG sKbeCbOMjXX7cTTfAXwMOzrYaBmzFwIdaPvD54Yd92fMZrsja2M39DO1udTzH6Ytnu8D 0jdt0XD+7NFK9TCZORXGvQKhVkJHdXVyvWmLWAkKlKWmP8BqeQ8B4LEuFgUh8UdHoloC ksw29J30vzBokAzdpxKk4cQ8lCyCCC8yIe+p7w4PAquAHa26i9FIrIC44r4SUKoldqp0 p6VH2oy7C4f50UAW2DWwjRBNiHyHejfcZ037kT+xVb/F6GaDEu7cmxoiBPOIx6/1NK14 ySEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VnG7ZAlv; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62809-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV25cm4JP1e9CJ9CbF3QoRwSn7b95j0neoaEzh4I4IjJGxXsqHLv1Ie0VicA2zA2bSo5bXuJ6U6c/D7GkMSXmEq4rK+3Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id il4-20020a17090b164400b002972e2132eesi1166932pjb.64.2024.02.12.17.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VnG7ZAlv; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62809-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8115F28C75C for ; Tue, 13 Feb 2024 01:33:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E343612F1; Tue, 13 Feb 2024 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VnG7ZAlv" 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 B0BB454BD4; Tue, 13 Feb 2024 00:55:02 +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=1707785705; cv=none; b=jFZN92BcuchuAWbSq8RyHozBqZnnya7RFp6YQIE17btgRol2YY5iad8ZCRgs5soGnftawtH6Jgs5NHvu3qw2wQ3Qe1EqLIdcjE6dWdWfkrxFYFq6JsqHJnHLTTkc2KjQreRkdE7cV8SXWSXNjoLxivkpQ1EvhTgYvZVtFAgOao8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785705; c=relaxed/simple; bh=rkRwkloXLH0NBDDjwKKTUt3p6SyUAZaYvxUn2f86zKQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mZ84PV8f7SA41HNI6nzZFs0Zxdu8PsyIL4V3Mpfpa1PB5bTxkvY89vgqaD5vnEr1+M7JprJYvz0MEU5p1uya320JzZqmepft6YQpg5QqMqpFaAoHLZzu/MeIcNOVucpkGmYmKl+djK53D6BGFY/nbpX8gXY9QF/ZA7z8iQzSZWI= 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=VnG7ZAlv; 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 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0VGfh023525; Tue, 13 Feb 2024 00:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=b5WcYA4M++5hMV1+dtL2 ECGuhzTzBXFt95TLOE5PGsc=; b=VnG7ZAlvZsGVW0FmO7tQ7+PhFRMe9dAmKrJQ qbWV+huWUHCzdeMroCjvodDt7H20OU3cP/5nP+1UxJOVTgpnnfMbjuuKoA/zjp5a qm8d/4Sv9X6BRZihnulhHAjSR5ieUu4/MAIdsUIQs+1m6b4ES4BUemIX5RH5r+7F WZMeAqGQ7pDHlr72ZXD/MT0ZJe3LzEXt1EkG7Bi31x7FBej5TwjXWM8ZjCuv7cN0 pY8gnGx5SS8k52GbKprQu6y4r4tsbwGY5sh/OadxNYYkofzwzDmw2hiRhHwIXJdR OFrHu6DoQSwsujv7+pDSF0DFxPNPJ5O67hDJmpVJm9UQVJxXjw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7nk9150k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0shGx026840 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:43 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.1118.40; Mon, 12 Feb 2024 16:54:43 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 39/50] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Mon, 12 Feb 2024 16:54:11 -0800 Message-ID: <20240213005422.3121-40-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: oRCiRXLe4PkUsoS5oC8awhJlcA5FVkrF X-Proofpoint-ORIG-GUID: oRCiRXLe4PkUsoS5oC8awhJlcA5FVkrF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745541230147998 X-GMAIL-MSGID: 1790745541230147998 Add SND kcontrol to SOC USB, which will allow for userpsace to determine which USB card number and PCM device to offload. This allows for userspace to potentially tag an alternate path for a specific USB SND card and PCM device. Previously, control was absent, and the offload path would be enabled on the last USB SND device which was connected. This logic will continue to be applicable if no mixer input is received for specific device selection. An example to configure the offload device using tinymix: tinymix -D 0 set 'USB Offload Playback Route Select' 1 0 The above command will configure the offload path to utilize card#1 and PCM stream#0. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 7 ++++- sound/soc/soc-usb.c | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 2790b51d979e..7b0531f975c2 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -26,14 +26,19 @@ struct snd_soc_usb_device { * @dev - USB backend device reference * @component - reference to ASoC component * @connection_status_cb - callback to notify connection events + * @put_offload_dev - callback to select USB sound card/PCM device + * @get_offload_dev - callback to fetch selected USB sound card/PCM device * @priv_data - driver data **/ struct snd_soc_usb { struct list_head list; - struct device *dev; struct snd_soc_component *component; int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); + int (*put_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); void *priv_data; }; diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index e3556c397b39..a55d1c509297 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -15,6 +15,9 @@ static struct device_node *snd_soc_find_phandle(struct device *dev) { struct device_node *node; + if (!dev) + return ERR_PTR(-ENODEV); + node = of_parse_phandle(dev->of_node, "usb-soc-be", 0); if (!node) return ERR_PTR(-ENODEV); @@ -38,6 +41,64 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device_node *node) return NULL; } +/* SOC USB sound kcontrols */ +static int soc_usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_offload_dev_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new soc_usb_dev_ctrl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "USB Offload Playback Route Select", + .info = soc_usb_offload_dev_info, + .get = soc_usb_get_offload_dev, + .put = soc_usb_put_offload_dev, +}; + +static int snd_soc_usb_control_init(struct snd_soc_component *component) +{ + return snd_ctl_add(component->card->snd_card, + snd_ctl_new1(&soc_usb_dev_ctrl, component)); +} + /** * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag * @playback: direction of audio stream @@ -157,6 +218,12 @@ EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); */ int snd_soc_usb_add_port(struct snd_soc_usb *usb) { + int ret; + + ret = snd_soc_usb_control_init(usb->component); + if (ret < 0) + return ret; + mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); From patchwork Tue Feb 13 00:54:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270496dyb; Mon, 12 Feb 2024 17:33:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXA0IbPw+NjtYOmxdxNS+AiOx0YQSSOjAKczrN/EcYoP3AECMU5qrS6Ib03EnBeA9OPgsY5e5gMhz7bYIRiWOg+uojeZQ== X-Google-Smtp-Source: AGHT+IFMFxxdDYbiKAJW+5bxZqzr7CZyetUQvC1ls1TUOYvPLcavs9sREkeJr75jCogmVXuzVVNg X-Received: by 2002:a1f:e604:0:b0:4c0:fda:7d8c with SMTP id d4-20020a1fe604000000b004c00fda7d8cmr5180628vkh.2.1707788019359; Mon, 12 Feb 2024 17:33:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788019; cv=pass; d=google.com; s=arc-20160816; b=wct013kpzOScPNfrupkNPeOCup/Ro1/gLKQqckvUNBRFv+e4Iv+vIfcPaQJMCsfE7I b/ggoEouhODEn8Tl/4flOskLUAvr8Wki89GXMZKtrhbjV2bWgEmvn1bwRROHJhRL67l+ 3E8osomEsf+EpNg7vG3PpQL+Q5TffVJIBLEbBLUfmfVcWg44f4Ro1cj1AScHlizcHSoG izsGNEMdQU2URA525XLTzOQlZLor1dJnACWYsfnKdq+S9wkETNaAcxQK1VOn0nGOh6kj Xu9uC12QJkEySX+FH4LS0aN+D5SCLc8Rt1Owe5S1763mSDqb9cB93srXMDVZBiejhTxW X5rA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1wOpcy9jDvAAEHI/K11vsFGqT15VfQz1a4+qL0/PTVM=; fh=arDxJ+9tXyp6o5vrgSokuJAMrQsN9zHIX/+lyrJkEWU=; b=gf7T4DudSaDgGvIDYlGmmhdGAkfLZ/I181q+06yBdwaICG3oJkb9rmK/+9ixmzRdYE 2Ig2/nETPcYqw+BZDB5spP5impup5sF1Ew3K2Sa0tfm3yuvovBJxkTS7pOvvYrzVrRVy SZHCx4hurcoR4IdJikNs//QZWCvtYvAfuwFhLvAUCxuUgAIiqIvIfeCppIdwZlMGwo7D Ht+TSLNz8ARj/21jfiI57BCxMusl/+z+fhLOTQfd0sWJ4lETEKM9LbdibCEgvsivKG3W PYnD/B4oERgu7Ivwb671tTs/2TlknVp4pX0DKZh8t/7ftvo8G9AFm7DNSjUFovE+z69p I72w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TrZTsXpQ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62802-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWDS5q//kk/wm8Ao3gmW0rBBHkGzvcP6lk5TksGjvjvjCxA51l5TC60Ai8QPribp5IOC/ULQID1uAC2/S3OH0qGDqdbfg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dv7-20020ad44ee7000000b0068cd144e023si1846271qvb.329.2024.02.12.17.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:33:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TrZTsXpQ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62802-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 06F0D1C24B41 for ; Tue, 13 Feb 2024 01:33:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A933A612D7; Tue, 13 Feb 2024 00:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TrZTsXpQ" 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 7098A54656; Tue, 13 Feb 2024 00:55: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=1707785704; cv=none; b=t2rupQcP/9Ph9kiV/dozBZ844qEKmnS43m7ebF8+NH09pTlGLBQHgKyLK+eS2UW/6o+QylXNqU4WWB5YYEOi/dgBrDoXU4KWP2NAxTKU/SxlUtReEfzXHzeWLe/zKBKd34b33MFIvzEKoXW+zeOiac/yGnzgMgYOztXBiyqgPpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785704; c=relaxed/simple; bh=WD2aYO20Jj6ylAcciZCsjRR8imXLNE0xsGdkB6cKWI4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LlsP77pytpLKMvETRqIsI0+empaSYh/mpKgJQ/XWT4FamKZCJDI3HUZ3DndNZ8PpYcTZ5v6Qau4zSlasrAfPXV291qrB2Ra6tqb+3t/2x76HBxiYZZ3Jt9fKiRAlHWZiEWOPSQDlJIEt2Yif86PYES7FzGVpBL7PZSY0cua9hy4= 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=TrZTsXpQ; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0ltBU003549; Tue, 13 Feb 2024 00:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=1wOpcy9jDvAAEHI/K11v sFGqT15VfQz1a4+qL0/PTVM=; b=TrZTsXpQ0QIpfnLn5n+FuLyhTAP9VcQOPo5x CSgvyj+n1sl9/j7NEBzlf8DjjAmPBxgQZL5M5Xr0hBg/jC09317ng3iSJcRVdlXm 3qj60A18GAYbzJhWj/2NkC1MViQjv9c3W9vY5r8GZYcITpKWmbRYSmZETNwVd7/i UOfR4n3HYnwWC/WBS73KO9aJCT7nLUpzQw7uY1W5Dv9KJMSAVXNLLYzhNyzIxQcF Zr+WzrZRR8+itrlnhkCb1odT75Z+nJrGr2n6HK6RfE+R0FJ6YYL09cpGRuM0PuY8 PbKhfZe3hOGPpmp8acvHpg9p/1hLvEofBmX2XZFLacNnagspuA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sii5030066 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 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.1118.40; Mon, 12 Feb 2024 16:54:43 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 40/50] ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks Date: Mon, 12 Feb 2024 16:54:12 -0800 Message-ID: <20240213005422.3121-41-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: zaemku8G-V8hcOZk3Os4rjY06LrOPd3U X-Proofpoint-ORIG-GUID: zaemku8G-V8hcOZk3Os4rjY06LrOPd3U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745530322203842 X-GMAIL-MSGID: 1790745530322203842 In order for device selection to be supported, the Q6USB backend DAI link will need to be notified about the device to start the offloading session on. Device selection is made possible by setting the Q6AFE device token. The audio DSP utilizes this parameter, and will pass this field back to the USB offload driver within the QMI stream requests. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6usb.c | 108 +++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index e539b411c35e..61d30303a7bb 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -36,9 +36,12 @@ struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; - int active_usb_chip_idx; + struct mutex mutex; unsigned long available_card_slot; struct q6usb_status status[SNDRV_CARDS]; + bool idx_valid; + int sel_card_idx; + int sel_pcm_idx; }; static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { @@ -54,10 +57,34 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct q6afe_port *q6usb_afe; int direction = substream->stream; + int chip_idx; + int ret; + + mutex_lock(&data->mutex); + chip_idx = data->status[data->sel_card_idx].sdev->chip_idx; + + ret = snd_soc_usb_find_format(chip_idx, params, direction); + if (ret < 0) + goto out; + + q6usb_afe = q6afe_port_get_from_id(cpu_dai->dev, USB_RX); + if (IS_ERR(q6usb_afe)) + goto out; - return snd_soc_usb_find_format(data->active_usb_chip_idx, params, - direction); + ret = afe_port_send_usb_dev_param(q6usb_afe, data->sel_card_idx, + data->sel_pcm_idx); + if (ret < 0) + goto out; + + data->status[data->sel_card_idx].pcm_index = data->sel_pcm_idx; +out: + mutex_unlock(&data->mutex); + + return ret; } static const struct snd_soc_dai_ops q6usb_ops = { @@ -88,6 +115,63 @@ static struct snd_soc_dai_driver q6usb_be_dais[] = { }, }; +static int q6usb_get_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + int pcm_idx; + int card_idx; + + mutex_lock(&data->mutex); + + if (!data->available_card_slot) { + card_idx = -1; + pcm_idx = -1; + } else { + card_idx = data->sel_card_idx; + pcm_idx = data->sel_pcm_idx; + } + + ucontrol->value.integer.value[0] = card_idx; + ucontrol->value.integer.value[1] = pcm_idx; + mutex_unlock(&data->mutex); + + return 0; +} + +static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + int changed = 0; + int pcmidx; + int cardidx; + + cardidx = ucontrol->value.integer.value[0]; + pcmidx = ucontrol->value.integer.value[1]; + + mutex_lock(&data->mutex); + if ((cardidx >= 0 && test_bit(cardidx, &data->available_card_slot))) { + data->sel_card_idx = cardidx; + changed = 1; + } + + if ((pcmidx >= 0 && pcmidx < data->status[cardidx].sdev->num_playback)) { + data->sel_pcm_idx = pcmidx; + changed = 1; + } + + if (changed) + data->idx_valid = true; + +out: + mutex_unlock(&data->mutex); + + return changed; +} + static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, const struct of_phandle_args *args, const char **dai_name) @@ -117,16 +201,28 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, data = dev_get_drvdata(usb->component->dev); + mutex_lock(&data->mutex); if (connected) { /* We only track the latest USB headset plugged in */ - data->active_usb_chip_idx = sdev->card_idx; + if (!data->idx_valid) { + data->sel_card_idx = sdev->card_idx; + data->sel_pcm_idx = 0; + } set_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].sdev = sdev; } else { clear_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].sdev = NULL; + + if (data->sel_card_idx == sdev->card_idx) { + data->idx_valid = false; + data->sel_card_idx = data->available_card_slot ? + ffs(data->available_card_slot) - 1 : 0; + data->sel_pcm_idx = 0; + } } + mutex_unlock(&data->mutex); return 0; } @@ -142,6 +238,8 @@ static int q6usb_component_probe(struct snd_soc_component *component) return -ENOMEM; usb->connection_status_cb = q6usb_alsa_connection_cb; + usb->put_offload_dev = q6usb_put_offload_dev; + usb->get_offload_dev = q6usb_get_offload_dev; ret = snd_soc_usb_add_port(usb); if (ret < 0) { @@ -205,6 +303,8 @@ static int q6usb_dai_dev_probe(struct platform_device *pdev) data->priv.domain = iommu_get_domain_for_dev(&pdev->dev); + mutex_init(&data->mutex); + data->priv.dev = dev; dev_set_drvdata(dev, data); From patchwork Tue Feb 13 00:54:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278343dyb; Mon, 12 Feb 2024 17:58:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXIMpOMfTZyn4qdh6dMqpuit9tmZFnMxXzwlGjPafNSgQKlFZfIBBZ++J5SvsGSFGzfF/KmkT2LYUOOpGYD1nHKL1o2kA== X-Google-Smtp-Source: AGHT+IFMSw4DsH+1cMK4lP2PFzNJ1tEcqszOxORgzh3huOPFfbrFwthED89k8P7EhL0tc+3woyZh X-Received: by 2002:a17:903:41c2:b0:1d9:8789:4b96 with SMTP id u2-20020a17090341c200b001d987894b96mr12408832ple.14.1707789532404; Mon, 12 Feb 2024 17:58:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789532; cv=pass; d=google.com; s=arc-20160816; b=mYzKETpZgRdeMq86pcYwAWd465+MMhb1g+VP/VCSsjGfAVDrWe57pJKdCMcmqp3QBf xXVRf5B5T7lPDq8bT3iUu3KAh1oJWPi+KB3EY4KmKtyOKKRnOeCI7Lcuw4JjCCMbocJr qP8Rv6mPdWDyYHzmIWs5+51PjgywsMobdXZCq5zB6JUnuDDNKMI42WVqyL4W11vcjd0Q Y/qNVEt2fMG9r/pAcLmq9td6GvbUwnmqko772x79hI+bbCk5U6d5phE6o43WDCx3JRix UDPT13KaYRK1eBzmaZ7Hw36LZW2rsJ9SDemd1BuuvnNR2HBHihqrU8Y21WuOIi03XLce DMtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OzAPwOhD063cYXhXZ6rD+ByLWp9zE5bjwd61D6t1YZ4=; fh=orR4nnKJ2NvO0gPi5k6cGNmkZ6JhbgE68lG+I2HWgI4=; b=HEEj+a7C0nD7jfWLLqdzcS+7dtoZ3ohZLT0SIsgotp+MGe/LuKNv6tpsGrua04rz95 /FhTlUxlPjETqJlFqyXKcYBobqcUHZSgU9AwLJ9MCL+zixGFPsXuT1/7Ka6nZS94GfEs G2SoGYEF1qGVYwafxNfDCZazMrwoSgHFNLOOVWt7bbXDtS3xdluixJQGPP1y4XnnzwT8 bi2LpJrf9dND0ChPneuw6o3cxM4nt0szB1Pzs2siPtvV9qd8nComQd42qyFAZ2vo2Mij VOsDJYQQi4m4AIgR1OF42UaqsIugdSqHj8dvgBfOWW0q0+JzkqnwwEVyd9BIPRcb9T0e KIQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IEk8bqKC; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62815-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVOeLg6RF01NfmX9OT51zs9l/wSlqH3Fq+p2tbkhCVUm3AjYgGwKY/X34V40fTINJZOdw9X9kFb8+jxAy9hghI6gmFC9A== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j17-20020a170902c3d100b001d905943e71si1085411plj.423.2024.02.12.17.58.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:58:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62815-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IEk8bqKC; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62815-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 99EFCB241AE for ; Tue, 13 Feb 2024 01:36:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E056D633F0; Tue, 13 Feb 2024 00:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IEk8bqKC" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A52557897; Tue, 13 Feb 2024 00:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785708; cv=none; b=F9cwd0YRA1ROEtVLEbHE3ANYjkhzFvHM9e/Vk9lqUX1/ryvBKWsE0FJ355ykGSMsqIvRrSRdf9WyDimUIDGBwMUoL7aM+VUYHa1Sy8FnhS4zoDzRtraUgqi5thQ3HELKpRklIqyACAowLwufmVjH+B0tNJXekgxoyxz5UzAm5gQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785708; c=relaxed/simple; bh=fB9L2CwDa6c9tniwnRTAxl2vqhAxsIPrZMUFh4ruZBs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A0jHBAgAi20qB+ITbBu7X4C7K+uQonyoDBjY6QHxJ9bqhL+tjQgjiJzFdQ85DCeXzhUc0U6jscwmkEVTi3vOFhhhM0xvxDH+RH5an5dQfQ7TxEVrxbcvnAHRf4i5S5H+1RndzRU/o8AFE3FuJx5vF8td7eJQpxKQ7t8ZzoE8VbU= 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=IEk8bqKC; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D08PwV015741; Tue, 13 Feb 2024 00:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=OzAPwOhD063cYXhXZ6rD +ByLWp9zE5bjwd61D6t1YZ4=; b=IEk8bqKCZHX4WbI2t2OeDGPEx1Fj6mDjf25p 7piPY8xTfnmq4/Q4ZTBl0LAQReN3JoIdez/XPM7bWL7WXZYXkKkKRPIK3ZC17GBT dVC9J+EiFXxk25VrcgIDat9Nh+TCZRJ9yKAdfZUoxO5O8kNGMtBAse6wsvwetE7L 3ZpUTs3IsIvNLbIBWFp+Rym3QSIE5w7e64lw+ERZSaAuh/mUHd26+qtwITXLx2x/ E357d9/F0XGuSoEAdAmcINMsRzaB/aXC6WFQaebHciCh2urVYKvPH3HhOY5fcV00 tKdecW6nlxDMWx/8r6+0RyXzY+VcJzufUJg/FgVguq0JzLdVGw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gse1tuh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sipK031157 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 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.1118.40; Mon, 12 Feb 2024 16:54:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 41/50] ASoC: Add SND kcontrol for fetching USB offload status Date: Mon, 12 Feb 2024 16:54:13 -0800 Message-ID: <20240213005422.3121-42-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Bu0Ctvp1a7SqRliZwA1QS_Zkdqe19jLJ X-Proofpoint-ORIG-GUID: Bu0Ctvp1a7SqRliZwA1QS_Zkdqe19jLJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747116527736443 X-GMAIL-MSGID: 1790747116527736443 Add a kcontrol to the platform sound card to fetch the current offload status. This can allow for userspace to ensure/check which USB SND resources are actually busy versus having to attempt opening the USB SND devices, which will result in an error if offloading is active. An example of fetching the USB offloading status would look like: tinymix -D 0 get 'USB Offload Playback Route Status' -1, -1 (range -1->32) --> [Offload is idle] tinymix -D 0 get 'USB Offload Playback Route Status' 1, 0 (range -1->32) --> [Offload active on card#1 pcm#0] Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 46 ++++++++++++ sound/soc/soc-usb.c | 150 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 194 insertions(+), 2 deletions(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 7b0531f975c2..41e59892c360 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -6,6 +6,24 @@ #ifndef __LINUX_SND_SOC_USB_H #define __LINUX_SND_SOC_USB_H +enum snd_soc_usb_dai_state { + SND_SOC_USB_IDLE, + SND_SOC_USB_PREPARED, + SND_SOC_USB_RUNNING, +}; + +/** + * struct snd_soc_usb_session + * @active_card_idx - active offloaded sound card + * @active_pcm_idx - active offloaded PCM device + * @state - USB BE DAI link PCM state + */ +struct snd_soc_usb_session { + int active_card_idx; + int active_pcm_idx; + enum snd_soc_usb_dai_state state; +}; + /** * struct snd_soc_usb_device * @card_idx - sound card index associated with USB device @@ -25,6 +43,8 @@ struct snd_soc_usb_device { * @list - list head for SND SOC struct list * @dev - USB backend device reference * @component - reference to ASoC component + * @active_list - active sessions + * @num_supported_streams - number of supported concurrent sessions * @connection_status_cb - callback to notify connection events * @put_offload_dev - callback to select USB sound card/PCM device * @get_offload_dev - callback to fetch selected USB sound card/PCM device @@ -33,6 +53,8 @@ struct snd_soc_usb_device { struct snd_soc_usb { struct list_head list; struct snd_soc_component *component; + struct snd_soc_usb_session *active_list; + unsigned int num_supported_streams; int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); int (*put_offload_dev)(struct snd_kcontrol *kcontrol, @@ -51,6 +73,11 @@ 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_device *sdev); void *snd_soc_usb_find_priv_data(struct device *dev); +int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); +int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); +int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state); + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, int num_supported_streams, void *data); void snd_soc_usb_free_port(struct snd_soc_usb *usb); @@ -86,6 +113,25 @@ static inline void *snd_soc_usb_find_priv_data(struct device *dev) return NULL; } +static inline int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, + int pcm_idx) +{ + return -EINVAL; +} + +static inline int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, + int session_id) +{ + return -EINVAL; +} + +static inline int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, + int session_id, + enum snd_soc_usb_dai_state state) +{ + return -EINVAL; +} + static inline struct snd_soc_usb *snd_soc_usb_allocate_port( struct snd_soc_component *component, int num_supported_streams, void *data) diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index a55d1c509297..d3183c0d3844 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -42,11 +42,62 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device_node *node) } /* SOC USB sound kcontrols */ +static int snd_soc_usb_get_offload_status(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_find_usb_ctx(component->dev->of_node); + int control_idx = 0; + int pcm_idx; + int card_idx; + int i; + + for (i = 0; i < ctx->num_supported_streams; i++) { + card_idx = -1; + pcm_idx = -1; + + if (ctx->active_list[i].state == SND_SOC_USB_RUNNING) { + card_idx = ctx->active_list[i].active_card_idx; + pcm_idx = ctx->active_list[i].active_pcm_idx; + } + + ucontrol->value.integer.value[control_idx] = card_idx; + control_idx++; + ucontrol->value.integer.value[control_idx] = pcm_idx; + control_idx++; + } + + return 0; +} + +static int snd_soc_usb_offload_status_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_find_usb_ctx(component->dev->of_node); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2*ctx->num_supported_streams; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new soc_usb_status_ctrl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Route Status", + .info = snd_soc_usb_offload_status_info, + .get = snd_soc_usb_get_offload_status, + .put = NULL, +}; + static int soc_usb_put_offload_dev(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + struct snd_soc_usb *ctx = snd_soc_find_usb_ctx(component->dev->of_node); int ret = 0; mutex_lock(&ctx_mutex); @@ -61,7 +112,7 @@ static int soc_usb_get_offload_dev(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + struct snd_soc_usb *ctx = snd_soc_find_usb_ctx(component->dev->of_node); int ret = 0; mutex_lock(&ctx_mutex); @@ -95,10 +146,96 @@ static const struct snd_kcontrol_new soc_usb_dev_ctrl = { static int snd_soc_usb_control_init(struct snd_soc_component *component) { + int ret; + + ret = snd_ctl_add(component->card->snd_card, + snd_ctl_new1(&soc_usb_status_ctrl, component)); + if (ret < 0) + return ret; + return snd_ctl_add(component->card->snd_card, snd_ctl_new1(&soc_usb_dev_ctrl, component)); } +/** + * snd_soc_usb_set_session_state() - Set the session state for a session + * @usb: SOC USB device + * @session_id: index to active_list + * @state: USB PCM device index + * + * Set the session state for an entry in active_list. This should be only + * called after snd_soc_usb_prepare_session. + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state) +{ + if (session_id < 0 || session_id >= usb->num_supported_streams) + return -EINVAL; + + mutex_lock(&ctx_mutex); + if (usb->active_list[session_id].state == state) { + mutex_unlock(&ctx_mutex); + return 0; + } + + usb->active_list[session_id].state = state; + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_set_session_state); + +/** + * snd_soc_usb_prepare_session() - Find and prepare a session + * @usb: SOC USB device + * @card_idx: USB card index + * @pcm_idx: USB PCM device index + * + * Find an open active session slot on the SOC USB device. If all slots + * are busy, return an error. If not, claim the slot and place it into + * the SND_SOC_USB_PREPARED state. This should be called first before + * calling snd_soc_usb_set_session_state or snd_soc_usb_shutdown_session. + * + * Returns the session id (index) to active_list, negative on error. + * + */ +int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx) +{ + int i; + + mutex_lock(&ctx_mutex); + for (i = 0; i < usb->num_supported_streams; i++) { + if (usb->active_list[i].state == SND_SOC_USB_IDLE) { + usb->active_list[i].active_card_idx = card_idx; + usb->active_list[i].active_pcm_idx = pcm_idx; + usb->active_list[i].state = SND_SOC_USB_PREPARED; + mutex_unlock(&ctx_mutex); + return i; + } + } + mutex_unlock(&ctx_mutex); + + return -EBUSY; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_prepare_session); + +/** + * snd_soc_usb_shutdown_session() - Set USB SOC to idle state + * @usb: SOC USB device + * @session_id: index to active_list + * + * Place the session specified by session_id into the idle/shutdown state. + * + */ +int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id) +{ + return snd_soc_usb_set_session_state(usb, session_id, SND_SOC_USB_IDLE); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_shutdown_session); + /** * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag * @playback: direction of audio stream @@ -185,8 +322,16 @@ struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *componen if (!usb) return ERR_PTR(-ENOMEM); + usb->active_list = kcalloc(num_streams, sizeof(struct snd_soc_usb_session), + GFP_KERNEL); + if (!usb->active_list) { + kfree(usb); + return ERR_PTR(-ENOMEM); + } + usb->component = component; usb->priv_data = data; + usb->num_supported_streams = num_streams; return usb; } @@ -202,6 +347,7 @@ EXPORT_SYMBOL_GPL(snd_soc_usb_allocate_port); void snd_soc_usb_free_port(struct snd_soc_usb *usb) { snd_soc_usb_remove_port(usb); + kfree(usb->active_list); kfree(usb); } EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); From patchwork Tue Feb 13 00:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272685dyb; Mon, 12 Feb 2024 17:40:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUEy9KYuvdZGDSRSksji+/ByrYxpgNVAS2gcXw/WgOTL2f1o2Alg9vUJxQ+a4A+0T3uVdF9GLXRIQ0DpSKOTU4AF4CoxA== X-Google-Smtp-Source: AGHT+IFs90tR+ll26WHsCJIuJNU/EKg5myQ94qX2IrGig0ycCw5NPo9ybe2ARZzAPHdxQ+fzXeoR X-Received: by 2002:a05:6870:15d6:b0:219:51de:344 with SMTP id k22-20020a05687015d600b0021951de0344mr9327990oad.3.1707788442277; Mon, 12 Feb 2024 17:40:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788442; cv=pass; d=google.com; s=arc-20160816; b=zd5QZyOEv9FRWyNvCP3DpPPsYLSSjM8eUuSu3oyskBkCtnXGi8mCoIlflHH2rS///m KjPKccmD24W85LJcBBMhxGQT8aW7p0OVMrbvsydG4QdPMTuQrOH1gdr8I6DywXYETNpl Zvb2Co5/9fybkVdZxW+CyCfpVfk9WvmzfZy4J8Fb5SaY7FRGv4cvrUG2ZynE6yU2VRO5 yEk6WLfw6imhmCHa5wrYjOm6MenEAop0s4mfPwxzw3va7OXmDB/zIUJn3VxoabbyDi72 5K/DFOX5CRjnAz9cyo/T00v52zwhlYuTtwKwN1YTx+ApKY/XdAHFmE9NstRLyiE5E3Rr +GkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TP9fyOwkywtfaOI9LqRokjI/c6lBCTPIOkl0CcpX2Ew=; fh=oiZj2Mh6UZlttWm5z+Bx81n87ZP+d57u7+N7hZwEZ3U=; b=kFFwo0v7Uv8TCR/lQX7GqAua2wwxwZ9Ykkit9mA5+kmNjxY54tCG85yOOY7ncCVR8B w9Nzyc21pRKCaw4oRExvv592qGtKJmF5c3yPFRyTzm/ec9RbrZkrsoJFDkKZI5Vz8Ehd ErRzIsZW13HOHfpVLT5/fAm6rSPF+jd8333/RBGBYl0I24YwcmY+PT62TvAXv3+LWzOu uMlcnnHhRibxsI3zqcViTeMSDyuDQFB2Ubg+kZjauqdhkzAz4XxhIgnmjLALiz+Jjre9 h2m22swkVVnpinzlHn0thgog+4KOGgrbFtigF/sQCGLNZ4fXWVIOdYN1CYdrWy58/rPA ikAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eEbzHleP; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXvxBR60Qj2fyH/W6fPjnQCutlQtqfH3KuJjcNq6+GCVmF/L381EN6Mtc817z8S03gQ4qkQJ94b3dAy1o2vXfwqUZU3cw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d124-20020a633682000000b005dc4b41e2d0si1098381pga.591.2024.02.12.17.40.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:40:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eEbzHleP; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 01D4E288538 for ; Tue, 13 Feb 2024 01:36:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA351634E4; Tue, 13 Feb 2024 00:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="eEbzHleP" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBD0759140; Tue, 13 Feb 2024 00:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785714; cv=none; b=S4nfHOtXzaAahwJCnK+STvO5koEwAp3UsX32e5LCVTNSL3RQfDd8aG45nMpkCnLadvDqz8pswp0dwK1BANR/0XEaAh+UFtINcAu9QFvrAfOlFF9L1zpUxzpc2GACRZudSxw2CKhAz4ARRgUtbgS5+4ODt83IURqUoPSUkjtHWsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785714; c=relaxed/simple; bh=RtmQaj8NkOIBrQYRKvHrCqtxnDMndM5jafzZvCboeCs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kYJBTuZSRWRrP4VqPCoXr9sJdMS8qEYgJ41s4B2c+xBH281K1KOh+A55pLd4+C5zXbsS4f33W4Y9gfxPiUnjY7GtlzohTeY1HDnncX8RcMXo9WWA4ylm5+EAMP4kCkqML3fZMnGvQK1fpMFPTJSU22L9moFWK8nWI9FUB9Wkvmg= 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=eEbzHleP; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0kqEa002770; Tue, 13 Feb 2024 00:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=TP9fyOwkywtfaOI9LqRo kjI/c6lBCTPIOkl0CcpX2Ew=; b=eEbzHleP4IvVKYMAeJNazIeF6Hf8a88A0Bv1 +oREfTyjuQnRr3G8NuUuuwHqZi8KGeR+odJq+deUEV1uiYqC3BAa5w7Gfuw1EYjJ r1YUQiDyz53Fx0RSLe2ocvCaIFKdmywKUZWcb7rbAYtxrg3rnjtjqcuKH+96ATKn 94GsxDYV+QNDCfvrRpBiMPBAvLEv9jSvIv+lPFZJQtrtzVM3ET9O1Gw+f7DZaGcn Ps6RDrLdMCWSbytC2o47yhEAwuZ8RUgfQEsXhaKKGQYJ48xSU3NvRdgpTL0CDmsh 6XAAB1spUG8/KtTRzPwU6GLxICMgTBBmU/+gNecWpjUtZhQIxA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gse1tuj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0siOH030072 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 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.1118.40; Mon, 12 Feb 2024 16:54:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 42/50] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Mon, 12 Feb 2024 16:54:14 -0800 Message-ID: <20240213005422.3121-43-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: p9iPdqQ6jTGAzA9IzhGTzHGUP9wlC9mb X-Proofpoint-ORIG-GUID: p9iPdqQ6jTGAzA9IzhGTzHGUP9wlC9mb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745973505304584 X-GMAIL-MSGID: 1790745973505304584 Register PCM callbacks so that the Q6USB DPCM backend dai link can track and update the status of the PCM device. Utilize the SOC USB state APIs to ensure that the SND kcontrol for the offload status is updated properly. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6usb.c | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 61d30303a7bb..84543b34f2b7 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -30,6 +30,9 @@ struct q6usb_status { struct snd_soc_usb_device *sdev; unsigned int pcm_index; + bool prepared; + bool running; + int session_id; }; struct q6usb_port_data { @@ -81,14 +84,48 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, goto out; data->status[data->sel_card_idx].pcm_index = data->sel_pcm_idx; + data->status[data->sel_card_idx].prepared = true; + data->status[data->sel_card_idx].session_id = + snd_soc_usb_prepare_session(data->usb, data->sel_card_idx, + data->sel_pcm_idx); out: mutex_unlock(&data->mutex); return ret; } +static int q6usb_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = true; + snd_soc_usb_set_session_state(data->usb, + data->status[data->sel_card_idx].session_id, + SND_SOC_USB_RUNNING); + mutex_unlock(&data->mutex); + + return 0; +} + +static void q6usb_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = false; + data->status[data->sel_card_idx].prepared = false; + snd_soc_usb_shutdown_session(data->usb, + data->status[data->sel_card_idx].session_id); + mutex_unlock(&data->mutex); +} + static const struct snd_soc_dai_ops q6usb_ops = { .hw_params = q6usb_hw_params, + .prepare = q6usb_prepare, + .shutdown = q6usb_shutdown, }; static struct snd_soc_dai_driver q6usb_be_dais[] = { @@ -149,10 +186,15 @@ static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, int pcmidx; int cardidx; + mutex_lock(&data->mutex); + + /* Don't allow changes to the offloading devices if session is busy */ + if (data->sel_card_idx >= 0 && data->status[data->sel_card_idx].prepared) + goto out; + cardidx = ucontrol->value.integer.value[0]; pcmidx = ucontrol->value.integer.value[1]; - mutex_lock(&data->mutex); if ((cardidx >= 0 && test_bit(cardidx, &data->available_card_slot))) { data->sel_card_idx = cardidx; changed = 1; @@ -203,8 +245,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, mutex_lock(&data->mutex); if (connected) { - /* We only track the latest USB headset plugged in */ - if (!data->idx_valid) { + /* + * Update the latest USB headset plugged in, if session is + * idle. + */ + if (!data->idx_valid && + !data->status[data->sel_card_idx].prepared) { data->sel_card_idx = sdev->card_idx; data->sel_pcm_idx = 0; } From patchwork Tue Feb 13 00:54:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278410dyb; Mon, 12 Feb 2024 17:59:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCULizyD2/O9cEz06MPaptbWj0d8lGyNUZiqyPM3J5fU7DYE0QH8M1y6ub8vTmM4EaLiMEJ5BAM0mySuuAHVEVs2/GVyDQ== X-Google-Smtp-Source: AGHT+IHbTRSa3IHNTgF34RTUFIxPgnp1nVemRF9S0Cn5EAMxLobtMEHeRU7dMQdFbcLc8K/0tyy2 X-Received: by 2002:a05:6a21:920d:b0:19e:3a94:6309 with SMTP id tl13-20020a056a21920d00b0019e3a946309mr12965242pzb.5.1707789549443; Mon, 12 Feb 2024 17:59:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789549; cv=pass; d=google.com; s=arc-20160816; b=Y9GHzoWVa+aC+c9sHjSICi4tf9GcMVhirgZpZVfXIxQIysYR2FrfesFOHwIls0GKCt tkg0xDB2jGvgzfKYXycVO9LuDZE+FaOszdwAo64nIl63Hex0ZksvJEmsEWymZaudnQnD CRnzHJntzoWRHREWMV3jtL6yB8hacEFw/tRNn/C9EFImBkziKLu5cM96b4zvNDf0fbWZ a6NTlQshPH0sHxwJew9zjfUMMp+Tg1zHdkNBBJqNn9HxG3JSghIREr8XFYyteJb8yQaE 6OzNPYf9vIaLt/0uvRlRXe3cbJLlmFaJfEfen03Q50dTMJw2VM2nl//JAi6/wpIJ6XPH ZfgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5MPghwqMnmfMlYR/X2xQeWKKOu6Pyk4OEgkIZw/sPpA=; fh=Zk+ohc59Qnx/Xn2XyNSX+an/TboGs6xDWC8KYdUvjdI=; b=Gfhf7231tCvZkQUXds0AKI9xkDOoOUl8a5lN0Lofy7LgTERCNSLZM0CSv95uqLevOJ qqoB1yMeRTBErp701yewKsSkS24FJJMDvquPvN2R2QGgjHDEu2xyxRYZ/WqNdDIjilUa +2P4u0GZLsAa7SKEXk+rbn2qV9BNO1oSk4pHwi5QkM5J+xQ5B+HfsXd4zZQ9yUrGStST 638JVw57BrZVIeEkTIzP85+PpsdFWGoOKzlu3YXj53xJWKUfjwMSSXYRaiQhGYqpet+P tn5qh6CvniPCxGXvUU/7rjVatMaURFPgPJ/paovhdtpZxock40/tQvwuAP729yn3of3r co/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mqms3qzN; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXq209CEP3UrdFN/wYNFOyyWP5V+x8KBdl7tIv7lZYPhXRIoJ70nc0S0BZjtxKpM5Kk7rAk0jqKJMMbCH+cBMz7oy3TDQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b8-20020a633408000000b005dc0fe6b511si1165594pga.147.2024.02.12.17.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:59:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mqms3qzN; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5A491B253B8 for ; Tue, 13 Feb 2024 01:36:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A669F6341C; Tue, 13 Feb 2024 00:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mqms3qzN" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1CB25820C; Tue, 13 Feb 2024 00:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785712; cv=none; b=X8iV+QVuKNHW0oh6Ro3jV2rvp2rFhq5983rHwalthFOv5LKW9+T5jugQK4Yp9aTrb5QhCJFM1VpvhP0/KwULztIovF/U9ELPSOmEA/iCXBsU1GMekTL5u6sUE6X8T4jY/CFrkGp25/4CCc/bYLre5bmQ/iWzyz3lo+Ft4yDndl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785712; c=relaxed/simple; bh=YEBC0eKEC3+ceGGPNrb1zBdbPqDsis3CQ0o2eThqCSE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qzFA9jXbgZ3Xvf2o6Rbnv0bkEuhp6A9TcRRfiRlqTkGzaafJ49mDR6gmiTc949/BMc1fJNgET1HcQqUil/iXLGq5Xn8MvPA9d9NCEba8j4di/H+cWqORFhTKkB3iGkG1ROU4FXAb6Fbjl3jzpBnprnVQo+mP8mP3+KWbSmWoWBQ= 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=mqms3qzN; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CNgpcZ032474; Tue, 13 Feb 2024 00:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=5MPghwqMnmfMlYR/X2xQ eWKKOu6Pyk4OEgkIZw/sPpA=; b=mqms3qzNPISCtBo6NMB/89bUDDa4fyJvGbb2 SsjjHwFxou8PXHTvdCJbzyIKnnbkZD0HtYc7cLODNEZy9yOTm/UhgCDa8vy3Yu3E HipgMefK6o701cKBCFn6UzlUpXIH63s/JELTaV4LWSdULftWQGTCqK/PC24xVq9U VvtUISeDP8NA9Wwwzhk2bcQxY7qgyumdNmBaR3K4qw68+uKsqCrKX+rSG1SJzAcK gK68WM4pEsLu1y3Qr2kbyu5ZdvUE2ZEYIpAlPPNQelC1HtqXmIw40Aod+4t5skQb zsAkAqYpcme+Vxtv3zL46YtDnWWGDgOhf9zc7b1rAZtZhY456Q== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ju79jxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0simT030076 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 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.1118.40; Mon, 12 Feb 2024 16:54:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 43/50] ASoC: usb: Create SOC USB SND jack kcontrol Date: Mon, 12 Feb 2024 16:54:15 -0800 Message-ID: <20240213005422.3121-44-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: n_aLO-D4USnVh2ptlN7k1ubcq2AuJtKy X-Proofpoint-GUID: n_aLO-D4USnVh2ptlN7k1ubcq2AuJtKy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=682 lowpriorityscore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 malwarescore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747134217691346 X-GMAIL-MSGID: 1790747134217691346 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. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 10 ++++++++++ sound/soc/soc-usb.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 41e59892c360..b75a48986b6e 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -6,6 +6,8 @@ #ifndef __LINUX_SND_SOC_USB_H #define __LINUX_SND_SOC_USB_H +#include + enum snd_soc_usb_dai_state { SND_SOC_USB_IDLE, SND_SOC_USB_PREPARED, @@ -77,6 +79,8 @@ int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_i int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, enum snd_soc_usb_dai_state state); +int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack); struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, int num_supported_streams, void *data); @@ -132,6 +136,12 @@ static inline int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, return -EINVAL; } +static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +{ + return -ENODEV; +} + static inline struct snd_soc_usb *snd_soc_usb_allocate_port( struct snd_soc_component *component, int num_supported_streams, void *data) diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index d3183c0d3844..f2e83c2d68fd 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -4,8 +4,10 @@ */ #include #include -#include + +#include #include + #include "../usb/card.h" static DEFINE_MUTEX(ctx_mutex); @@ -42,6 +44,40 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device_node *node) } /* 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 = snd_soc_card_jack_new(component->card, "USB Offload Playback Jack", + SND_JACK_HEADPHONE, jack); + if (ret < 0) { + dev_err(component->card->dev, "Unable to add USB offload jack\n"); + return ret; + } + + ret = snd_soc_component_set_jack(component, jack, NULL); + if (ret) { + dev_warn(component->card->dev, "Failed to set jack: %d\n", ret); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_setup_offload_jack); + static int snd_soc_usb_get_offload_status(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { From patchwork Tue Feb 13 00:54:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272633dyb; Mon, 12 Feb 2024 17:40:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVEbn5/lzBx2fh2FllsBLhf99gPxwn9jxqMBZUyHWysigqy3LRm7TttTkQjSzwMonEDXDp+3KAsx/KKX/Avciqib2XWmw== X-Google-Smtp-Source: AGHT+IHE/Uu3sd/x2Y+5voBE6eAnHWEsoM1/PddQlG7wQbtefHQBKPowgxD7A7zRi+G05PpCJXoX X-Received: by 2002:a17:90a:a896:b0:297:164a:ea52 with SMTP id h22-20020a17090aa89600b00297164aea52mr6000617pjq.11.1707788435078; Mon, 12 Feb 2024 17:40:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788435; cv=pass; d=google.com; s=arc-20160816; b=jknlPLwckEOxQAE8FbKpOuHx8INzAAfpwDmoAM9SOao0KaMIl4drcjhyR7jIs1AVY8 ew/woj/bPBfhohxKIZg6fkferlCukqI4WZ1JfR0zug3qSXj+dY/qqbNNprYPx6wqTlVS WoBEYiLbX14w6c69NRZsH9cCAA9J0WJ/Cm5LO5y0gyfX/ySmx4w7ohWqILp91FDO1GEL dyyaheEHdqGM4pTZ8BarH2pjazi0gfCqcVQtbN56wvTY2u86yrQhMpTaraQOXuIKVjWh SZSXVpm39kCTTB8BFlkA/69w4TmJ4eKUkOK039Fg4PqdbOqnhy20tu/KWu3UwSoIprmN xJng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3cOijoiixp7wjp7+zUCdFarig6ypy0C1SI0w7WKRj0Y=; fh=AkOk5QFZYUGRsqN6bfZol0chzdsiS+nctHesATSONGc=; b=OSRnO/6yLJD1hHYVhRN39c1J3R3sU5O3Kvd7xQQRAvEDaCMBtCDb3n5n2Ri3gvf3Yc I4RJMoilZXyGCPryDugN+qtQ3rsPJOTuw+EI/vFU7Tr4ProFzVTz8N8Iy43jkFoyfA3W nRBokfo8MwQNy2zmitKokvtclQUW9eej4s5Tbz7fi6hjnme548v2KGjy5NKIB4SubWk7 TJJbR92aXOeJyrinjNVXO2hKS/nIIADcBOMZM1rVe7Pyyrk8W1N8LhyK18Ee1IvCXEDm I9O3oDuhGS+JTM/i9vJKGRfho7PoaF1OPLjcRbi137IT1zJFBI+IO/Bc519JHbPy/vSM 4nXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eLv4tN54; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62821-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62821-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXUHdxbmNA15PcYP+zunMhQtuQhBJCelCA73uu3UHVggpY7R9C2HZZpuXElzvg3EuI1PRbqYO7URlTNC8J3FB82NLFJrQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e4-20020a17090a9a8400b00295b3ecc46bsi1154048pjp.168.2024.02.12.17.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:40:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62821-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eLv4tN54; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62821-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62821-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DAF42287FC9 for ; Tue, 13 Feb 2024 01:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52D4D63408; Tue, 13 Feb 2024 00:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="eLv4tN54" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541B35A4E3; Tue, 13 Feb 2024 00:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; cv=none; b=KFtlpzp2JKJUaNPk2qq98nT/TSO6e8Nj79SmMAimG9nnmt5N09z/OkV8aCH5/5aDfdlsbPEtwkNCtXPGwnatHsr6cgX/9UOPU4hWcxZ/boj9V2w9eZevFWP4GEY+WpV5H4aeZqYgRNnp/E4c5zYIkPSRGdGxAp3mnntA0vNLzy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; c=relaxed/simple; bh=wsGUkyBZclzL2+9+SE74fiQ0D0EfvGGVI1EZE+VZW5A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AP0mWrdd1LyA15bUCF+I4sWlGhwwfW+vGa8MRZmM9+2p9LPok7TMPhfdk7qb8pISyWTl9yiKY2DskdfUzP41UOr8X3eMx6GggTk63NNBfiodprfXeRDYzGECJ3PCP5AdL/N14SiJcXHyAEz9aJ+C82g8RoVPEXTOktAADu58vBY= 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=eLv4tN54; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0G6Jn031577; Tue, 13 Feb 2024 00:54:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=3cOijoiixp7wjp7+zUCd Farig6ypy0C1SI0w7WKRj0Y=; b=eLv4tN54crEkF0eRBpP7xpzACQ6YiNf01ejB FOTy2X17FpEj+5c5qk2qkJgjhukHgEbb3Mbwi+eVYpZepH9SVxDnk33lP7XHdlIp 6aC3CgqC1yhPBbVrrHzeMgHRxyRokeprrDVwI1r2yraHkqe60xID/H9AgqFdZGw5 5oJTIMwwtMcwB+Wv2NcT1kDUJV/ljnCbnc9Bj1dotY/zzrEvKbeOk+IVJV7X8AIO NDw/15Anith3aIKddligYEwIBAuCfSjO2E/gFiZvQntdi359WVLH6jN3enxSu4UI eRmT92PZPJ2Qw22yf8SBlsDT+yI7RQ8W0lhHHFub6Aflh2gqCg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7hew9rvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sjJF031164 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 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.1118.40; Mon, 12 Feb 2024 16:54:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 44/50] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Date: Mon, 12 Feb 2024 16:54:16 -0800 Message-ID: <20240213005422.3121-45-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 1_DN4oLW9AQvWzW40ohXmEeOdBS2W8rR X-Proofpoint-ORIG-GUID: 1_DN4oLW9AQvWzW40ohXmEeOdBS2W8rR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 malwarescore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745966058038328 X-GMAIL-MSGID: 1790745966058038328 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/common.c | 19 +++++++++++++++++++ sound/soc/qcom/common.h | 3 ++- sound/soc/qcom/qdsp6/q6usb.c | 20 ++++++++++++++++++++ sound/soc/qcom/sm8250.c | 11 ++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index 756706d5b493..c81a52f64ef8 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common.h" @@ -239,4 +240,22 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, return 0; } EXPORT_SYMBOL_GPL(qcom_snd_wcd_jack_setup); + +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 = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); + + if (cpu_dai->id != USB_RX) + return 0; + + if (!*jack_setup) + snd_soc_usb_setup_offload_jack(codec_dai->component, jack); + + *jack_setup = true; + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_setup); MODULE_LICENSE("GPL"); diff --git a/sound/soc/qcom/common.h b/sound/soc/qcom/common.h index d7f80ee5ae26..fca3046c8674 100644 --- a/sound/soc/qcom/common.h +++ b/sound/soc/qcom/common.h @@ -9,5 +9,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card); int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, struct snd_soc_jack *jack, bool *jack_setup); - +int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup); #endif diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 84543b34f2b7..f7b0a9f4310e 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,7 @@ struct q6usb_status { 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; struct mutex mutex; unsigned long available_card_slot; @@ -245,6 +247,9 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, mutex_lock(&data->mutex); if (connected) { + if (!data->available_card_slot) + snd_jack_report(data->hs_jack->jack, 1); + /* * Update the latest USB headset plugged in, if session is * idle. @@ -267,12 +272,26 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, ffs(data->available_card_slot) - 1 : 0; data->sel_pcm_idx = 0; } + + if (!data->available_card_slot) + snd_jack_report(data->hs_jack->jack, 0); } mutex_unlock(&data->mutex); return 0; } +static int q6usb_component_set_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *data) +{ + struct q6usb_port_data *priv = dev_get_drvdata(component->dev); + + priv->hs_jack = jack; + snd_jack_report(jack->jack, priv->available_card_slot ? 1 : 0); + + return 0; +} + static int q6usb_component_probe(struct snd_soc_component *component) { struct q6usb_port_data *data = dev_get_drvdata(component->dev); @@ -313,6 +332,7 @@ static void q6usb_component_remove(struct snd_soc_component *component) static const struct snd_soc_component_driver q6usb_dai_component = { .probe = q6usb_component_probe, + .set_jack = q6usb_component_set_jack, .remove = q6usb_component_remove, .name = "q6usb-dai-component", .dapm_widgets = q6usb_dai_widgets, diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index d70df72c0160..52136897cc92 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -22,14 +22,23 @@ 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; }; static int sm8250_snd_init(struct snd_soc_pcm_runtime *rtd) { struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + int ret; - return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); + if (cpu_dai->id == USB_RX) + ret = qcom_snd_usb_offload_jack_setup(rtd, &data->usb_offload_jack, + &data->usb_offload_jack_setup); + else + ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); + return ret; } static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, From patchwork Tue Feb 13 00:54:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271231dyb; Mon, 12 Feb 2024 17:36:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDOtx4jUvlV8GSAKDuTvWIgXz50UybNCF6KFleFwyq5kDM4hROcde+a1Pg+JdAfGZNXZJP X-Received: by 2002:a17:906:3751:b0:a3b:7216:3091 with SMTP id e17-20020a170906375100b00a3b72163091mr5319748ejc.20.1707788166146; Mon, 12 Feb 2024 17:36:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788166; cv=pass; d=google.com; s=arc-20160816; b=gfHI2lpfnxOGbASQQemSCCM0F3fvDdFCm7xHv9Pj/D0wJ0JUgF+t+xX+Kd/RV4eMUf SpqjAybrNoR2AWJGWgI7heLZZ918d4yzutB3nLv0PbjpPhQ4gsk3mtZy6PQTNIseuwaz isGPV748IolZmA238YomaNUlx4NArK3lhnjLlbojV3EYYKhCz8F+Dw+oys/Nr1CEH5yZ WihmpgAdxhBXi2CVe+C//SRpLAsKU5Y0fHvYVeKk8miZ1dN9ucJ3Pz9tzohFEoDiuZmD CduZ+deSBm3ShDiiikoBogP4qeRDFRInyQ/wHPpX9mJh23q8fHNB3ksTiCPaIhPjogPR 8QiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ij8oJoph0GmIoY5H7m5O8wFj3hNfBOF1jliLmTV42mo=; fh=nouJM4GNSXFHlU58+RMGu5iz96/fGoteg8ZyLybUGsw=; b=kH2miBZBSaZ5QQTtywi6XzqGpZlvpTaiZUhdUoP2jYllT+dnI+S2oQ8BgrX2VjTjlv 6bTTu4idicxuE4CvxstRmMyDijy3wh/ObuBGrHpT4HsV4em9Zxbl4zVd7Ssn2tTjIxF4 f9MaNW2zgyKAv3y9oeCHAO/GKdGWotbsN/DGh130FgruTM5eACHO38ssMJHJsu/H55j7 NOFt1VoPWS/4lx41paBPnVNHLvpV0oeu7N+/Y5I88zFCvZdDA7lw0luw2K+ezgi80vN+ wJSv/qOwOnWHl4YkBPCxtkykLgfAyy3QGuyJTDoGQ3CZEUqoTLcpSVhVAdgztyGC6nGd Yc4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Etm7pnBJ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62816-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU0c1+mn3ZoSKSpV9jFoBODBFYrxuh/otGQJiGS4+a8+SXkH7m+MWEKbOFQ8Wht8njguAV44mXYO9/EVJKELqCvu46Bgw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v18-20020a1709060b5200b00a3cb690a6bdsi742515ejg.747.2024.02.12.17.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62816-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Etm7pnBJ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62816-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9165A1F244A4 for ; Tue, 13 Feb 2024 01:36:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C221963100; Tue, 13 Feb 2024 00:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Etm7pnBJ" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD3415812E; Tue, 13 Feb 2024 00:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785709; cv=none; b=HarfSMz8Y98j3oOXqSsDvhResMfcntrdifP7vWWSVwJ4EVlUpu6kltLb6VKxp/I4GxYQn9Tl+8nBRm6EHcRC110ewTI6C5mqhb5paTWVMkVr4pEOp1B1AfOf5C8xYrZEiRs0gchNggxC65l5n+CmuhQ0GaT3CeBdQO/YDcYlO2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785709; c=relaxed/simple; bh=uV80yVRaHN0ZIjjzpujCRpYPFK4+I3XCkXyOipjyXck=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AkSXJlcFUyq3ZL5DNxIUWC/hdmb04tN9lXbCsMIfcJ6kp8Zn798ieRYvTvVkFdK3StxPbx57UYykYgSX+AE9TIbG74WMX2JOCNeShK6XvSiazDU8/YzOXrz/GfS0+rYk3OCsLRDsCXNis2NCToMEd0on6lAUqMOXfsI8SBTcr9o= 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=Etm7pnBJ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D01HsV008566; Tue, 13 Feb 2024 00:54:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=ij8oJoph0GmIoY5H7m5O 8wFj3hNfBOF1jliLmTV42mo=; b=Etm7pnBJUxGqvHquCE4uslY6RzRrLN9Md8s7 jyZsE7xKMrmAvtBGt3rOrne5k7lMDy6dtcbvuQw9tGD37I90E8YPxkuQX9r4uEO8 EUHrbYqfP7BXYeONEmoR5Jom/1iNp2wJ1It679ApvIYgCpGQ6ioIm0O+yNn70OQL 2M2fHlWINOxEilk6KdZlS1uQjGK8jipEst/kGgahimTJ/HLResTRpBWG+Nn8Xzgc 5CCJFpcAR1gm/ueBRTYb9t8Fq8dRfQ27uQryYlg9xPrL/kvypiJbSU0EIHvameFm 8mz24BRopc6sE5GAOXoT/x6M495yX/bDyU0McueGxXqWVZfSBA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7q2y0vw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sj1D031168 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 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.1118.40; Mon, 12 Feb 2024 16:54:45 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 45/50] ASoC: usb: Fetch ASoC sound card information Date: Mon, 12 Feb 2024 16:54:17 -0800 Message-ID: <20240213005422.3121-46-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: eo9G6cgPzrv80LvHTH8TiioBPqrI4_An X-Proofpoint-ORIG-GUID: eo9G6cgPzrv80LvHTH8TiioBPqrI4_An X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1015 adultscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745683567358127 X-GMAIL-MSGID: 1790745683567358127 For USB sound to expose mixer controls to fetch information about the ASoC sound card, add an API that returns the platform sound card number that is registered with SOC USB. Knowing this allows for applications to further query about the offload status. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 6 ++++++ sound/soc/soc-usb.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index b75a48986b6e..e864a44e7cfa 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -74,6 +74,7 @@ int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params, 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_device *sdev); void *snd_soc_usb_find_priv_data(struct device *dev); +int snd_soc_usb_device_offload_available(struct device *dev); int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); @@ -117,6 +118,11 @@ static inline void *snd_soc_usb_find_priv_data(struct device *dev) return NULL; } +static inline int snd_soc_usb_device_offload_available(struct device *dev) +{ + return -ENODEV; +} + static inline int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx) { diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index f2e83c2d68fd..9de5b9ed0cea 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -339,6 +339,32 @@ int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params, } EXPORT_SYMBOL_GPL(snd_soc_usb_find_format); +/** + * snd_soc_usb_device_offload_available() - Fetch BE DAI link sound card + * @dev: the device to find in SOC USB + * + * Finds the component linked to a specific SOC USB instance, and returns + * the sound card number for the platform card supporting offloading. + * + */ +int snd_soc_usb_device_offload_available(struct device *dev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + node = snd_soc_find_phandle(dev); + if (IS_ERR(node)) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(node); + of_node_put(node); + if (!ctx) + return -ENODEV; + + return ctx->component->card->snd_card->number; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_device_offload_available); + /** * snd_soc_usb_allocate_port() - allocate a SOC USB device * @component: USB DPCM backend DAI component From patchwork Tue Feb 13 00:54:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp270610dyb; Mon, 12 Feb 2024 17:34:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdFBshfSpfqZkGZbxjOU6HuZGJMcSJSOtXwTlmwIkEsZS1xIyMkSv4ZRADE1IdFnfgwGS79znPxudm3wh20LS39s3DpA== X-Google-Smtp-Source: AGHT+IHt/K+IGQCD1II6KuRMeTOwDezERpNzt0bYEj5RUQLWvp2gccqOOwlH/eb5IjlBaWYu9eo3 X-Received: by 2002:a05:620a:27c7:b0:787:1ce9:3917 with SMTP id i7-20020a05620a27c700b007871ce93917mr397085qkp.23.1707788041477; Mon, 12 Feb 2024 17:34:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788041; cv=pass; d=google.com; s=arc-20160816; b=hYWu+cLWHcFPh6EB7c54OevTmJOv/vfJuplsqNe1BV1QLCqtsGtxO/M7eCv5UlD99b R7ngC3/Oev9gIiAVy8r6PhgA9VDjnTmK75+n13SUmjOjBTRH48WOcE5Np6PuoAjxSkqs uqDdJu/EX6mYsTKF0UoexWZvOOoSxxihkpng7aRn3t1jtgLAJ8d1zu56DxeKeTPfQwd3 FBIkzvArmkoBGzcRq3wIWFXYTNZPi5IlI7K/l62YmIBAHbAao8cv6OfIL1hcmB7rwtnF la0UtgPp1LIEbrxBVuzVgfcYXqJJberMB18Xj6Xcst9K2oTX1sx8b4YKSoT8i7TvbLoO ABsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7WS9MIELx5MCGGgcxJyh8PPp7TNkENyHcOTdBOIszpQ=; fh=gZV1s1c6oHru2S2/lNoAbrZxQnjJQ1cbuBkLC5CCDvQ=; b=gtioXM9QqA9xI0nhcppcl8r8Pp4JfzoV+ahRkLse4gAB2LuFnHcHAVu/UPuQL+qiEt p3XffcMuGlEocBbXppoLEtbzODPo5TXvd0Ll2k6vDcfv68gf7vBEwENg+pqEbNBbD3/o 2CNGpefaF38plMyMTyvoAvH1eZ0B4itP+Fpy31pPNgY6onmy38cFc87WuiwGEjfUp5MV 5drD5clnDR2c+OWnrEVyykiz9IHI+64+sqnqcSS0wJvAmN2fjZxnGNTldcYDs5026nzC ArKH4Pv1hk6l7rme2WydIvxGHxqU/vLE/LZWVLJedE2BnlC9Tv9MTuj/kMscdp8KKJeu paWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AE18XcxK; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62807-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62807-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW0seaqkqOfkKWxCXOWg64+pzP/PemL9MEPGdmhZUjHj72oD8FS5p4yagZMP5Xv6uGpqd8P2SOijsdj3UpOmIsALcjJDw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vq18-20020a05620a559200b00783f0a95059si624285qkn.363.2024.02.12.17.34.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:34:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62807-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AE18XcxK; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62807-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62807-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 35E6D1C24B61 for ; Tue, 13 Feb 2024 01:34:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E467612FB; Tue, 13 Feb 2024 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AE18XcxK" 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 61B5D53E0D; Tue, 13 Feb 2024 00:55: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=1707785705; cv=none; b=eIa1Sf3tl8DgrjudYduc31rtsGfDwTqd5cthnvMShreQ1idwlk1kVyTVyoaasdCecwO6MI/Idu/ma3fUYUkawyrNitEfTS23uWQ0k3C/3g+HyjT9Jzl80SUwKzw20B8bwT72fRmlnIMwW97fTb3v4W68BGQAj1V0weCA2EU348o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785705; c=relaxed/simple; bh=FLjS5BNUE9PjIEGGgD0YuqZLJ8Xb2pXDmvHKuLO/lkw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SGOz+ziMoaB9WmHd4DgCPF5wi2fc51/8d0tbCuWsqGqcb+QXSTzUBGhfZv9TSg9EH8Alpe/Rb8+ZVHoz1exRy+Zx2OVi4E4sz9SUEmQpXE+YPgQNuf33/s31ZxGS9cYPNpTNzV2aVRsrWwwcAYWgjFSXuhXvs84UrpMOX+EMvcA= 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=AE18XcxK; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CMbQLH032725; Tue, 13 Feb 2024 00:54:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=7WS9MIELx5MCGGgcxJyh 8PPp7TNkENyHcOTdBOIszpQ=; b=AE18XcxKM7FlHBe8HeR2FQYT9r8GnSm1HzT3 edZ3+OUyK4B111hpy9hz3Vrf1odHTkr4b9NIGQ458bcpTN5RBk7waL7AvwdNd3wh CQNpYqPMMedVXiWHTcY92GJPZYyqIDrMus4LnPJUKlOnF7szsPSTPXIZUqh0sZh4 AeCe5jpiAe+nloAtrU+9hVDXwCewHfjz1hfxBTL0z1Ww6jPAMVi4OW76JzhewqKE RI6jxgR8hBH6h62siw3HTMlvfTe2l1q9fbJa5lkb9a/MkSKFClb0Ki/x0X53seBU eGlRUrChzNwr3IHWa4sbxRGamIJjF5hrOc56yYKpmh1Mwjm5Gw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w62kt4tyr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sjaS026861 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 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.1118.40; Mon, 12 Feb 2024 16:54:45 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 46/50] ALSA: usb-audio: Add USB offloading capable kcontrol Date: Mon, 12 Feb 2024 16:54:18 -0800 Message-ID: <20240213005422.3121-47-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 7wRsNAEB9BzsR_Jm7SrJehgKparUZGNJ X-Proofpoint-ORIG-GUID: 7wRsNAEB9BzsR_Jm7SrJehgKparUZGNJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745553306348682 X-GMAIL-MSGID: 1790745553306348682 In order to allow userspace/applications know about USB offloading status, expose a sound kcontrol that fetches information about which sound card index is associated with the ASoC platform card supporting offloading. In the USB audio offloading framework, the ASoC BE DAI link is the entity responsible for registering to the SOC USB layer. SOC USB will expose more details about the current offloading status, which includes the USB sound card and USB PCM device indexes currently being used. It is expected for the USB 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 Capable Card' 0 (range -1->32) Ths example signifies that card#0 has an USB offload capable path available. Signed-off-by: Wesley Cheng testing new mixer --- sound/usb/Kconfig | 4 ++ sound/usb/Makefile | 1 + sound/usb/mixer_usb_offload.c | 65 +++++++++++++++++++++++++++++++ sound/usb/mixer_usb_offload.h | 11 ++++++ sound/usb/qcom/qc_audio_offload.c | 3 ++ 5 files changed, 84 insertions(+) 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 4c842fbe6365..3e7be258d0e3 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,10 +176,14 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. +config SND_USB_OFFLOAD_MIXER + bool + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND select SND_PCM + select SND_USB_OFFLOAD_MIXER help Say Y here to enable the Qualcomm USB audio offloading feature. diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 246788268ddd..8c54660a11b0 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ stream.o \ validate.o +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c new file mode 100644 index 000000000000..8adb9e227c1b --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include + +#include +#include +#include + +#include "card.h" +#include "mixer.h" +#include "mixer_usb_offload.h" +#include "usbaudio.h" + +static int +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct device *sysdev = snd_kcontrol_chip(kcontrol); + int ret; + + ret = snd_soc_usb_device_offload_available(sysdev); + ucontrol->value.integer.value[0] = ret < 0 ? -1 : ret; + + return ret < 0 ? ret : 0; +} + +static int snd_usb_offload_available_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new snd_usb_offload_available_ctl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Capable Card", + .info = snd_usb_offload_available_info, + .get = snd_usb_offload_available_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 = chip->dev; + + return snd_ctl_add(chip->card, + snd_ctl_new1(&snd_usb_offload_available_ctl, + udev->bus->sysdev)); +} +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..12a2cd1d72e9 --- /dev/null +++ b/sound/usb/mixer_usb_offload.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __USB_OFFLOAD_MIXER_H +#define __USB_OFFLOAD_MIXER_H + +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip); +#endif /* __USB_OFFLOAD_MIXER_H */ + diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 17cee0cf2ff5..265e6d970925 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -34,6 +34,7 @@ #include "../endpoint.h" #include "../format.h" #include "../helper.h" +#include "../mixer_usb_offload.h" #include "../pcm.h" #include "../power.h" @@ -1648,6 +1649,8 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) uaudio_qdev->last_card_num = chip->card->number; snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + snd_usb_offload_create_ctl(chip); + mutex_unlock(&chip->mutex); mutex_unlock(&qdev_mutex); From patchwork Tue Feb 13 00:54:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp271193dyb; Mon, 12 Feb 2024 17:35:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2voov8LGrP0ismVTXl1G/irAFylZJZmPjDq9lYHQ/mLz338nk+CQK+5RkFx652DKLdSudGE+6Diu2OVkpUXjASCfHsQ== X-Google-Smtp-Source: AGHT+IEJGe3U+8HaIEf70YYI9c4SUWb4VOgUv1KNYYDvXP6AOBRMMdw3hfsunP6YBOm42/649XCp X-Received: by 2002:a1f:e403:0:b0:4c0:3552:bd07 with SMTP id b3-20020a1fe403000000b004c03552bd07mr4608996vkh.9.1707788159369; Mon, 12 Feb 2024 17:35:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788159; cv=pass; d=google.com; s=arc-20160816; b=u7hg2mJ43nsdU3PkZC0xGBfwl04pGQqyrf+pDnAsW8iq/8ydKZmHeGKVcXKk+0y3ja N98CZvDzqKoCxCkxt8wFG3rIXLmZ5ARpRfp4j5rvFf6HUDEQlg11yn1si3ltIMyW0cPh RCOXS1DfTRS+kmWZYScfEiyNg5vN701qTZ8Uz82lC1lKrLJ11v55jgyCr3zSxNv0Umzo bY/OeS0/4j6FK3A/jIUKj9rSVICRFpyRaQGz4YR7kq4fw4804XFlqEv8zgN8HqVRme+f bw1hPJuvozxYkDxmpq3jdoUdr7hlSLptpQbGCf2vB/N2iEG+uGPRTmodfJpTvRTBQ60N Fkcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kGmHRhhHPg1MJhqR276zXmPPfA/WmrOcGcOwZw0DDOU=; fh=jXCOjJggeqiz5/sv2SPsUg2UmXf911dKXe1cDxLeyZQ=; b=sH6S0sbUOv+w6Y1x9HP+x3kL4TnGFIl5vsVgrwv46PC8UaYqVHJGN0vthq+ou2e+tF sYoEtGBi7R7cWcXnUYl+z/MEuL2LN6WU5YdozBaqBT73+2PYZ6ZjTBQgc7IybZByXgxr 5eq96a4u7lA/mBLhruhmpToybXkeK8Dgw0aVZicbW3mDoKvl2NZ+LrhLbxVUU2ZtZ3eA 27Xjbhe2tlr6PWZN7qErnTWhvAcxB7SrqOyxeQzzbfucBrSUDnfynj939niKiZoZLO+B CrGpk54FCahMpeY/3j7iAPZTGgdogH2DwxT5YhsvYv/VnCacqqXyYFtOQjBhysOZK6rO 6CXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VUWbPLO7; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62814-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62814-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVkVRcpV00W2uodEe4FSXtuhmRpWHXp4fy+9aKbEIHZqze2zPd3tTtw8lth1cgrSA4DvU/Old4OQDsFoZPxk5hTtZURrg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ed12-20020ad44eac000000b0068c51fc0a0asi1789153qvb.292.2024.02.12.17.35.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:35:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62814-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VUWbPLO7; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62814-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62814-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F0921C24899 for ; Tue, 13 Feb 2024 01:35:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 822A462A15; Tue, 13 Feb 2024 00:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VUWbPLO7" 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 AFAFB55C28; Tue, 13 Feb 2024 00:55:04 +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=1707785707; cv=none; b=raTUnvaYI7qf+HXL+c7Mp6iK2w6dLNZnuukg7Evg3hfei65d76lJ9qj3CrM+nwjENPDldcQku5ScuD1xXf10AmquA8maaU2T82g3NufB5Inxp6ddrIf0pc9c4WBZ4jbIEJD48OcXQGxEX3Oi6lto/hXv0U71jywqocnRvxgTnoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785707; c=relaxed/simple; bh=UFdIRekJUYcowLf9w22phEy8og3ESsOA/bUoW2JxauU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RXrFRKDx1+vr1LOovm4/g4KR/Ks3/nGs5IvzhcDdhzLZ2OQWkMhg/uOspJim+07wCMGqpjS6UO/GdmZz4DCvGw84hd5XDIvpXgbftBOkwO+Rn2Ogp3byjUuuMNl2+Sys4aWjHi1P5CDWd9n2S6IAHE7UIytRxfC2KgYReyk/bck= 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=VUWbPLO7; 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 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0ZDdp009069; Tue, 13 Feb 2024 00:54:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=kGmHRhhHPg1MJhqR276z XmPPfA/WmrOcGcOwZw0DDOU=; b=VUWbPLO74sq3yDqFTM872VfTMXwzqlHBvtp2 xs920r9/95Y+Z6qWMN3ts2+NU8ut+8rsqEJVJevGRXNadiSIQ44uBKMu9leXYKt0 tm/Jf6PDo0PnrDZFOYLey/eSJlwpdCqKW+xsdjX71NXM+eYtTMDWLcnNrcxGK2tt s2qC4frVNmoSCwXfz1pir3wATwYZWBY+ogPpfqVabkgUHOz0XdL+IFKhnqQsmAf9 iQMi8kj9mTkuMgJURuwFfx7x6glfcws0CVcC7ekJlLm2XDZzFbUHo0s8YrBaZgvO F3auyF9nIyf0usRlt4XMO1W4+3BvTCd1HiM1m9ITS8gG/kguGQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gvjhuxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:47 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0skKQ031600 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 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.1118.40; Mon, 12 Feb 2024 16:54:45 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 47/50] ALSA: usb-audio: qcom: Use card and PCM index from QMI request Date: Mon, 12 Feb 2024 16:54:19 -0800 Message-ID: <20240213005422.3121-48-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: RBZHVWgJ97wVvndign-D3alylkCyo6FK X-Proofpoint-ORIG-GUID: RBZHVWgJ97wVvndign-D3alylkCyo6FK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130004 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745676882785143 X-GMAIL-MSGID: 1790745676882785143 Utilize the card and PCM index coming from the USB QMI stream request. This field follows what is set by the ASoC USB backend, and could potentially carry information about a specific device selected through the ASoC USB backend. The backend also has information about the last USB sound device plugged in, so it can choose to select the last device plugged in, accordingly. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 21 +++++++++++++++++++++ sound/usb/card.h | 1 + sound/usb/qcom/qc_audio_offload.c | 10 ++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1ad99a462038..8364c5b8fbbf 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -186,6 +186,27 @@ struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, } EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); +/* + * 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 = 0; i < SNDRV_CARDS; i++) { + if (usb_chip[i]) + platform_ops->connect_cb(usb_chip[i]); + } +} +EXPORT_SYMBOL_GPL(snd_usb_rediscover_devices); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index 2c8c51c8b1ea..68c8c5f12c1a 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -221,4 +221,5 @@ int snd_usb_unregister_platform_ops(void); struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, int direction); +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_offload.c index 265e6d970925..e58924abe5ca 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -107,8 +107,6 @@ struct uaudio_qmi_dev { bool er_mapped; /* reference count to number of possible consumers */ atomic_t qdev_in_use; - /* idx to last udev card number plugged in */ - unsigned int last_card_num; }; struct uaudio_dev { @@ -1244,7 +1242,7 @@ static int prepare_qmi_response(struct snd_usb_substream *subs, pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; xfer_buf_len = req_msg->xfer_buff_size; - card_num = uaudio_qdev->last_card_num; + card_num = (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"); @@ -1437,8 +1435,7 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, direction = (req_msg->usb_token & QMI_STREAM_REQ_DIRECTION); pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; - pcm_card_num = req_msg->enable ? uaudio_qdev->last_card_num : - ffs(uaudio_qdev->card_slot) - 1; + pcm_card_num = (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 16; if (pcm_card_num >= SNDRV_CARDS) { ret = -EINVAL; goto response; @@ -1646,7 +1643,6 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) sdev->num_capture = usb_qmi_get_pcm_num(chip, 1); uadev[chip->card->number].sdev = sdev; - uaudio_qdev->last_card_num = chip->card->number; snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); snd_usb_offload_create_ctl(chip); @@ -1874,6 +1870,8 @@ static int __init qc_usb_audio_offload_init(void) if (ret < 0) goto release_qmi; + snd_usb_rediscover_devices(); + return 0; release_qmi: From patchwork Tue Feb 13 00:54:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278226dyb; Mon, 12 Feb 2024 17:58:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFq/VoeeGmCvt+bPYpVV27XJzbxLkHxUBrKJgtjF4zYI+0UxcOpC99y++FWUXEwuNSz3OXt5j0Ro96Ojc5PhJCUV81+w== X-Google-Smtp-Source: AGHT+IGYeBpd7IWsg/t57dl1GIPtvkiyMg7NQEO9XLVHRoZvQnrwZHNQIMgjKoUyQuuARWzR6O2O X-Received: by 2002:a05:6a21:3943:b0:19f:c0d3:47db with SMTP id ac3-20020a056a21394300b0019fc0d347dbmr1944604pzc.5.1707789508315; Mon, 12 Feb 2024 17:58:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789508; cv=pass; d=google.com; s=arc-20160816; b=QtGVAg+dUnsgxiaTPBdJurxPdgAtqH6sBben/lBYn/7YVH0jRByKgt1ZriWi6qKZeL /juNEG4iv/d71S2PvdnsEdr9avz8eEbdFReXS+GHqU66vokizilBjPo2F6WdcqOKVLrC CISB9VrTv0M0zxetQloV+6wliP6uvoaOLXLRodD3aeyYsnz/V2p+I0iA2+5GdAF7Zenm /Y1FM3jTMWCxPpTNdz43e4Y0+cdWZSgjXFt/sGUvENVHeAph5UfDa8DttLA2VJVAKERH Ah5K9UIIivg/igiO5kmSTWUIyxFl1tPyojs7+C/WAXc+oqv5SWOAxtOx1yDwmwFMhV6y dh2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D0DqocdeBiZmMp9owFwjI2QOH5t43SdG1GCqpHEtKK0=; fh=nSXtz05pGizCVdl9wZ5IGNwR5nSkOqzgUjqZdUOvw+8=; b=rM5ru7yO9vczg/QIGtvn8V2YvUhUsuA7tqcc36NDSZB1EX6ANB5nuzYMEsX+tVOFF5 txyueRafo1rpfczIlQmo1G34RCZx81KTg5l3DOSnXh8mQeSU2ybqyArJMBAUYRytUCV4 h+wbCuJWYkpSWAUdkjcmMahjs81Vu3HYjTZ2OXKXkv0Z3uqcqueTdsZOk8WKiVSwXL/f Jz7bFt6OtWcZglZs3yrL1fVNFc2EDAga2EnQRycpMq6CIe4Jj2MNBBuHZtD1FdMxHvO9 pPki6yE/8b/oTt65/cQaic3kZ2OjFQTuL1Y039Kh/R6LlJ6iVXqv2+rt2cYejkOtkVRH Ejng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=jxhjsdVQ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62820-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUNkUrw/agEtR/EWt7d5UlW9Glv0TRjuM0TNAHEQl5d383tOe6yKwTStXqnvmQk8UrEnl5KcDAkFMgSsmfTQJcd9sCqww== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s69-20020a632c48000000b005dc83423faasi405511pgs.833.2024.02.12.17.58.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:58:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=jxhjsdVQ; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62820-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0CFCBB22D9C for ; Tue, 13 Feb 2024 01:36:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20D2663116; Tue, 13 Feb 2024 00:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="jxhjsdVQ" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBE6659146; Tue, 13 Feb 2024 00:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; cv=none; b=gxM6mRccGES/Z6O/kfTVPeU7E81+1jR+2sD/K7MQsKMW5q9VZuAM2uUdeVKiaoV5IPqIBp6gGXa47swuL0pvtHHvoFKIMgqhgPobR443OGUxwj/HipLPdE/XFpvAawiD9mYzYZCceQteaEeAw/9CLRHeW/y+zCRYxB20US74N/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785710; c=relaxed/simple; bh=/+jd5JtmoaoHN1pQ/vwGQl4AkYq7xNMktaBcFDR5q+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gqWuaB/T1b3MTSTL1sDCS6JhdXDW3Qc4cIZmvLF6LZR66QZEa6fZaD5f56e7MVkEGjJPhHCY6zb6fB9WaMee/u9VQNmI5m3R0bYrAfb0zSzOrheww2BupLpvz4o3GSm97hiVP4UuPHJZM3BN1DbOApIa3+AdyCNHFzd5tSjXevQ= 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=jxhjsdVQ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D01pft000380; Tue, 13 Feb 2024 00:54:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=D0DqocdeBiZmMp9owFwj I2QOH5t43SdG1GCqpHEtKK0=; b=jxhjsdVQLU+VOTkWE5QXeZQh4xeIuw66stnT zEnH6GL4lGNYY0QGbEpjkbv+GY/t3WiUmeIn6vzxtQ8CUB7PWNaPURh2GzonNDnO CurNJ4+n8mDHGZIA2vXgsRg4W+eygvLElCRKj7WEYnukioMswygcF11HBuyQRy34 7KWpkFYiKS8M76Xqmg1G+cFYjfRJqHMmKcZv3IES7DuLWmumLPhSmaQ0/VasH2q6 c2vLJyqw6ifwESFfM8Jb4x4cEG7ysm5xg4vTODgJLSTQDhJYpCzS/PYn9SBqrqeT 7nL4wvpFfAUJfet+NRP46Zj8ihTE8rRkGqOegSupNKA8fYMIiw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7hew9rvu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0skn9031603 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 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.1118.40; Mon, 12 Feb 2024 16:54:45 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 48/50] ASoC: usb: Rediscover USB SND devices on USB port add Date: Mon, 12 Feb 2024 16:54:20 -0800 Message-ID: <20240213005422.3121-49-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: TzIovpDfc2ez2ZcdCLOJkzTGYEwrQn5C X-Proofpoint-ORIG-GUID: TzIovpDfc2ez2ZcdCLOJkzTGYEwrQn5C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 malwarescore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747091734824432 X-GMAIL-MSGID: 1790747091734824432 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 9de5b9ed0cea..44d6057ffb17 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -436,6 +436,8 @@ int snd_soc_usb_add_port(struct snd_soc_usb *usb) list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); + snd_usb_rediscover_devices(); + return 0; } EXPORT_SYMBOL_GPL(snd_soc_usb_add_port); From patchwork Tue Feb 13 00:54:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272608dyb; Mon, 12 Feb 2024 17:40:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZUWmKbYLa7h3auyTNaS5prha3YM/4iVlhDSUCt/vS/iWFRuYbXwystbbDlj1mckhh5L6f2eJylyR95a1B2yXAupiI1g== X-Google-Smtp-Source: AGHT+IFFjzpunlhrycnbBvwvviHEpWtVP3ISZxF88HNj0tCVcIx2Sk9U7eXRwXltP8bBOK8ypS2s X-Received: by 2002:a17:902:e9cd:b0:1db:28c4:b757 with SMTP id 13-20020a170902e9cd00b001db28c4b757mr2072676plk.0.1707788431541; Mon, 12 Feb 2024 17:40:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788431; cv=pass; d=google.com; s=arc-20160816; b=JSfBpKmIyb3S8oXoAmtGuuw4A6mARHPoNL9bEJFvcglAfYahwIMeZwHtwQ0jcDBpz4 Jh2DINDIsnxoNhlGm39B/D6fKnlyaZYMdDenjR39a5BrPujAnCV9y6vni9cXkPbBzNP6 tbd3VRqbwp5louktRn5U9i19LyEHJ3k6rrcClkk/PIxdza0m/q5mFbFb8RLoB0gmQ6xO 8IHPoauZjXVtC+MyFebwwFvGhneL7HpSmlOSoB+axOPeFbRf2j+xeLc0FRjPtPQuuFuj Rg3XyGJlVAM+bOoZ9IMcbDhPu3UvfaH/ddDnhnlJJGcFYpvWcK7/n2jvTyGUMW3NhQQG uQhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5vmvA/j8Eq+r73ofFDYJ664BV9DDh9rA330ASd5d/Rg=; fh=+SXZwO3PU8vIcfMDhSLxwzXYFGQn+TqcqtFHNOFTI+E=; b=NppAQshrUZL7midz1TSFgH2OiwSaWJ8zMz/UsL2RHS9MfALzH73gji92nxA3N/qdXJ J9W56zDBQM1H12K7L/uH8QeI78kQ3P3oNulhr4fXsIdI45H0t0TMe5NzDYGyRkVUdYgW mZApKxyYwGY+fr//mKzSfnxc3W/ll4J4NkuL2zgwBSPfl9uUhVkRjKPvcSTzZJF+tfBz myUGRfN5KMsScgkABxIOqvTxLhonJNRUgTZSIlUhRSSedzS83a0hXVckTBoC3aXxSDfJ FaSrqRxhuB81is3dt0JblKYqQ2hWBnlFJ43e+dI6vOAuas8F9g+7mMjjiXyH0byRh+to 3jtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Eatj4Zz1; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWpTX4iymeVefnPgCRRn9ifXdm0tkeWn75YBthFVXWEGAOccHUyrCpOQn+6FrTOpg3Up+UvnsWIy+wJ+Qr3MqmCQyy8/Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001d70b8d77b9si1110398plx.307.2024.02.12.17.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Eatj4Zz1; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B4C99288274 for ; Tue, 13 Feb 2024 01:36:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AFEA633FB; Tue, 13 Feb 2024 00:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Eatj4Zz1" 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 B42F75812B; Tue, 13 Feb 2024 00:55:06 +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=1707785711; cv=none; b=JYEaHsk34wjnHaU4BOaJ2WOcn1mtI1BFZAQgO5Hpyzy9XT/Zje0RsdgBQW9IAiJHMFko3Wc6MM6t3e39lExKYpRzUpKCcbsUroTLmNOPaYllubstM6FUOdTa+lSE4g3n3NTVJoFJtakNG+FFTwJTWJ8tVjTuYtpnLpcEqbrlNhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785711; c=relaxed/simple; bh=UemOCUX9OC/jB7lWASuqhcBieye2GhhUA69QsoWo44I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n1IWbR68tQvdz6ZL/OombzI2GxVnpRT6hrb3bzxObIZ1+JRR2aTbLYUwmSz4mcf2WL/tVkd90dU7hlbMxCNwyfV/pKsGPYieo4BQIxrtzCHPsvHl1Y1Xw8fSmXSHrIN1w0dNmdy5Zvt1YyhvRZ7tamFWb5qlszF/fsOfsdUopnA= 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=Eatj4Zz1; 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 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CM4vHR027931; Tue, 13 Feb 2024 00:54:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=5vmvA/j8Eq+r73ofFDYJ 664BV9DDh9rA330ASd5d/Rg=; b=Eatj4Zz1Q7LGKyxDIK0BGj6l2aT38s+NN16X WzTDNRVi5t70YfnmKD8PF+6xdlSAzjCzLSEKxtbOoLwlxMHdOo4y+vMzRRAN+9La 5oKF8ZdAlUX2r45uscTDKyTW3jXKxsN8EdVbj7qTW/P2Lzib1hedaeF4BbPIdMlt ipbmd3TfZht5la/oqcpjErmI1wYFAMVSKmforsJzl4dIPYqD5QruA+qsliwP+mnx 6dcZmamBsQ7nbioxN7uLVkCbYtU1Uy0jhe9VA8PdxtDc608d25sRz9x+hZThcSW5 3vXd4Jof+MCJtxA6yW4xcbJKFd+OY6P6LjF+guI9PZR8F0cwag== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7s390kbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:47 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0sk40031192 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 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.1118.40; Mon, 12 Feb 2024 16:54:46 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 49/50] ASoC: qcom: Populate SoC components string Date: Mon, 12 Feb 2024 16:54:21 -0800 Message-ID: <20240213005422.3121-50-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: BFLnIyaRpDc6P0gP1YcYMyGBNoBQkQ1W X-Proofpoint-GUID: BFLnIyaRpDc6P0gP1YcYMyGBNoBQkQ1W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745962243065476 X-GMAIL-MSGID: 1790745962243065476 For userspace to know about certain capabilities of the current platform card, add tags to the components string that it can use to enable support for that audio path. In case of USB offloading, the "usboffldplybk: 1" tag is added to the string. Signed-off-by: Wesley Cheng --- sound/soc/qcom/common.c | 22 ++++++++++++++++++++++ sound/soc/qcom/common.h | 1 + sound/soc/qcom/sm8250.c | 3 +++ 3 files changed, 26 insertions(+) diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index c81a52f64ef8..bd83ac3f2638 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -258,4 +258,26 @@ int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, return 0; } EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_setup); + +int qcom_snd_add_components_string(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_card *card = rtd->card; + const char *prev = card->components; + + switch (cpu_dai->id) { + case USB_RX: + card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s %s", + card->components, + snd_soc_usb_get_components_tag(true)); + default: + break; + } + + if (prev && prev != card->components) + devm_kfree(card->dev, prev); + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_add_components_string); MODULE_LICENSE("GPL"); diff --git a/sound/soc/qcom/common.h b/sound/soc/qcom/common.h index fca3046c8674..8546723e0aa8 100644 --- a/sound/soc/qcom/common.h +++ b/sound/soc/qcom/common.h @@ -11,4 +11,5 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, struct snd_soc_jack *jack, bool *jack_setup); int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, struct snd_soc_jack *jack, bool *jack_setup); +int qcom_snd_add_components_string(struct snd_soc_pcm_runtime *rtd); #endif diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index 52136897cc92..2a5384dd5988 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -38,6 +38,9 @@ static int sm8250_snd_init(struct snd_soc_pcm_runtime *rtd) &data->usb_offload_jack_setup); else ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); + + qcom_snd_add_components_string(rtd); + return ret; } From patchwork Tue Feb 13 00:54:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp278770dyb; Mon, 12 Feb 2024 18:00:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeSSxau7lD6lxtBQ5D47v+ziU1WiaNnRqSBQeYAol74/329sDJ2W4rXybI67/sX7ystVihNIjlV5g3M4vdp4MpfzkaCg== X-Google-Smtp-Source: AGHT+IFmubshvzJfoIMgWLS1WiZIqmTHPjfhykDvLdqCiHFo19GMt3uwgIth1M7UqFMnW/1mU9+G X-Received: by 2002:a17:903:246:b0:1d8:e4b8:95d6 with SMTP id j6-20020a170903024600b001d8e4b895d6mr8173287plh.27.1707789609140; Mon, 12 Feb 2024 18:00:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707789609; cv=pass; d=google.com; s=arc-20160816; b=sLtvfOrM3PaBsMKiG7FLxk6TipqIubM2lvUyo/59x+OriPE2SG3ln/I5JTt6PYi0lm pbHaHRo9bWM6Lvt/Yv127Eb0O7JnrhmntEwiOzJpuPeDbdOt4bJqKSnWMQsI54wNNFs7 UvEncDSasyN8ZCvIriTLGy30JY8iUwAGf7V3zXXtkiUCyYXUFkeISlcFM0XJh7/2NxuH qMT4ZaBzjWQonGZSxTctyvEbqWuuPleh2uko6t+5WJQ27b29qfDRO+Bw7ONDpFXhJQf7 nNSkXSqC+Z+0iyMTjLGW6mrWnfRUXxd+exMdNKWgjYWpU1pdcntspz8OGIderXjwM6Fx CSfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jIhNcJAao4L3t+lM7xozMs6yOtfapDmOsn0CNMaxawM=; fh=4WKoi2meZotKQo1SmX/uituwnmlGM10EshRkvoavzgE=; b=QIQuT08dwTpUAXZxiXGBt/QzV9fbiUgZewAdCxkTCDXOOx4CPufziA+Ww1H8rEi/62 daFdIfX1sBe2kjMYxzTfFgZAWMLjv6QBTX8RzsF/K+WmjO65eGIa8xU8AOqhdKdFjqM3 50nLy1GAYOLmpRuwHYV9dCe42iUAEPs7RBGbrFWv3GaLCFOdYFSnd0+p7HoJqoN5Jgrj MZVE6rXtGJ26MpBOKvCkwCPdUMAU1hlDlp1derKKQfW5hxpUBwGaJk5Zv2nhU/exHJ9f hobQFpLbUjWSCv/wofMDB9cPWnAe8d3EL5BDQLQjRBhrswxpQyqPsXxDysHN+stfaLmA vxRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=D7vPyh+f; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62825-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU7V1yMaSdJHHhmkSWA2wVwVCVycc15fJxBZS+6QLS+AyNVRtTr+hXzRraY65OJPzwMTPA3y7uO9y6qar4/HFf/6mGsng== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h22-20020a170902f7d600b001d72a09b874si1119732plw.3.2024.02.12.18.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:00:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=D7vPyh+f; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62825-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 99B96B221FD for ; Tue, 13 Feb 2024 01:37:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F00A64CC4; Tue, 13 Feb 2024 00:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="D7vPyh+f" 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 1D2325B1F5; Tue, 13 Feb 2024 00:55:08 +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=1707785712; cv=none; b=rkaFcQ1gVf8AUZOO/8/Ox+5sbHSYPmSzqj54WHf6hBoAvlu5WvUWDWekFBvaKCtWnf1YYHIVIqFtsuAOk+6DoSOPL6g7cfWokWK4HAifRjHLQZU26SRAY0XZnpcuxZyxZ/wW+p/jR/7OvehRN+r1lLtMbQNFUSuQd1dS7WGIx0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785712; c=relaxed/simple; bh=tpV2LIvDWyMeK3jFmTnMWqmNOSZ53kTz7F2yP15ipF4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RUV/11qep2iWeGzCq/wmUaMGuZKzTC6mY4okgZeZR79qhkohNDvUeB30M7gLz2deGnJwUVeFgBIZI1FGAUz3DEmV1yebJo0EYyevjGlYSi2RKsEzrnu8l1g+Y/nCFR/tetsGNf6bhpNJbN3AHrSeuUZj/HUIC939GvrC0X+C1wo= 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=D7vPyh+f; 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 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0RdKD002655; Tue, 13 Feb 2024 00:54:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=jIhNcJAao4L3t+lM7xoz Ms6yOtfapDmOsn0CNMaxawM=; b=D7vPyh+f4ftobEYbZy5w4K1h4EhaMLSnLIMy yggP8/Eingb5fooTcchCSA999TmslKJhWME4a2rW3DF0VpDsg9+SwBQuvo6TdLSO GYWVpxEszLKuX2Vv5KZzMYCILi2YLfBE0t5WANFCYqIGzFAyYeaQB9VK9OYh5ay8 eQdYKoLc5NSrcA0BJRgel8fN2tRjOo0f0vbBF0r02J+TEh+gsnT9IeD/Vp9lec+S BiS1LgcjiGnIknhuisL1DaikL/pFFM09wNGUJqOX13ce1EUI1QSC+NM+NoDkEXz9 fHKxNLVInoLB8peyL5Ruvmaz7jvm6uB6aWMNUBykAhcOSU5Fmg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ww5r1ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:47 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D0skp7031610 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:46 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.1118.40; Mon, 12 Feb 2024 16:54:46 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 50/50] ASoC: doc: Add documentation for SOC USB Date: Mon, 12 Feb 2024 16:54:22 -0800 Message-ID: <20240213005422.3121-51-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: JdW0WHYvG4qTRipkhCNdwC5RWgj5gVEG X-Proofpoint-ORIG-GUID: JdW0WHYvG4qTRipkhCNdwC5RWgj5gVEG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790747197022186518 X-GMAIL-MSGID: 1790747197022186518 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 | 611 ++++++++++++++++++++++++++++++ 2 files changed, 612 insertions(+) create mode 100644 Documentation/sound/soc/usb.rst diff --git a/Documentation/sound/soc/index.rst b/Documentation/sound/soc/index.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..3f7c3ef6a0c0 --- /dev/null +++ b/Documentation/sound/soc/usb.rst @@ -0,0 +1,611 @@ +================ +ASoC USB support +================ + +Overview +======== +In order to leverage the existing USB sound device support in ALSA, the +introduction of the ASoC USB APIs, allow for the entities to communicate +with one another. + +One potential use case would be to support USB audio offloading, which is +an implementation that allows for an external DSP on the SoC to handle the +transfer of audio data over the USB bus. This would let the main +processor to stay in lower power modes for longer durations. The following +is an example design of how the ASoC and ALSA pieces can be connected +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 +============== +Structures +---------- +``struct snd_soc_usb`` + + - ``list``: list head for SND SOC struct list + - ``dev``: USB backend device reference + - ``component``: reference to ASoC component + - ``active_list``: active sessions + - ``num_supported_streams``: number of supported concurrent sessions + - ``connection_status_cb``: callback to notify connection events + - ``put_offload_dev``: callback to select USB sound card/PCM device + - ``get_offload_dev``: callback to fetch selected USB sound card/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 device + - ``chip_idx``: USB sound chip array index + - ``num_playback``: number of playback streams + - ``num_capture``: number of capture streams + +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. + +``struct snd_soc_usb_session`` + + - ``active_card_idx``: active offloaded sound card + - ``active_pcm_idx``: active offloaded PCM device + - ``state``: USB BE DAI link PCM state + +The struct snd_soc_usb_session tracks the current offloading state for a +particular card and PCM combination. This structure is carried/saved as +part of the active_list within struct snd_soc_usb. + +The number of entities in the active list corresponds to the number of +snd_soc_usb_session structures that are allocated. This is controlled +by the num_supported_streams that is reported as part of the SOC USB +structure creation. + +Functions +--------- +.. code-block:: rst + + const char *snd_soc_usb_get_components_tag(bool playback); +.. + + - ``playback``: direction of audio stream + +**snd_soc_usb_get_components_tag()** returns the tag used for describing if USB +offloading is supported for appending to the ASoC platform card's components +string. + +Returns a tag based on the direction of the audio stream. + +.. code-block:: rst + + int snd_soc_usb_find_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_format()** ensures that the requested audio profile 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_device *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 USB +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_device_offload_available(struct device *dev) +.. + + - ``dev``: the device to find in SOC USB + +**snd_soc_usb_device_offload_available()** fetch the sound card number associated +to the USB BE DAI link. + +Returns a valid sound card index on success, negative on failure. + +.. code-block:: rst + + int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); +.. + + - ``usb``: SOC USB device + - ``card_idx``: USB sound card index + - ``pcm_idx``: USB PCM device index + +**snd_soc_usb_prepare_session()** populates active_list with a 'struct +snd_soc_usb_session.' This will move the session into the SND_SOC_USB_PREPARED +state. State updates will always start here. + +Returns index to active_list on success, -EBUSY on failure. + +.. code-block:: rst + + int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); +.. + + - ``usb``: SOC USB device + - ``session_id``: session id returned by **snd_soc_usb_prepare_session()** + +**snd_soc_usb_shutdown_session()** frees up a slot in active_list, which signals +that there is no longer an active offloading device. This allows for another +session to be started. + +Returns 0 on success, -EINVAL if session index is invalid. + +.. code-block:: rst + + int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state); +.. + + - ``usb``: SOC USB device + - ``session_id``: session id returned by **snd_soc_usb_prepare_session()** + - ``state``: state to move into + +**snd_soc_usb_set_session_state()** moves an offloading session to the desired +state. + +.. 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``: ASoC sound jack to add + +**snd_soc_usb_setup_offload_jack()** is a helper to add a sound jack control 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 + + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_supported_streams, void *data); +.. + + - ``component``: DPCM BE DAI link component + - ``num_supported_streams``: number of active streams supported by external DSP + - ``data``: private data + +**snd_soc_usb_allocate_port()** allocates a SOC USB device and populates standard +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 + + int 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 + + int 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 framework. +After removing a device, any SOC USB operations would not be able to reference 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 = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (!data->usb) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + + ret = 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 = { + .probe = q6usb_component_probe, + .remove = q6usb_component_remove, + .name = "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 root hub 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. +The following callback can be used to notify the BE DAI link of any change: + + **connection_status_cb()** + +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 situtation: + + **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 unbounded, while USB SND is +ready, the **snd_usb_rediscover_devices()** is called during module init. +This allows 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 + +Advertising USB Audio Offload Capability +---------------------------------------- +As the USB audio offloading can potentially reside within the platform ASoC based +sound card, depending on if there is a USB DPCM backend DAI link existing in the +platform card definition, then users can utilize the sound card's components string, +in order to signal that USB offloading is supported by this sound card. + +The sound core exposes: + + **snd_ctl_card_info()** + +This allows for userspace applications, i.e. amixer, to fetch the components string +that was created as part of the ASoC platform sound card creation routine. The +possible tags that can be seen are: + + - **usbplybkoffld: 1** + - **usbcapoffld: 1** + +**usbplybkoffld** translates to usb offload playback supported, and **usbcapoffld** +translates to USB offload capture supported. Applications can then query the sound +card for further offload status parameters. + +SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers: + + - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload. + + - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities. + +Implementation +-------------- + +**Example:** + + **Sound Cards**: + + :: + + 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed + + + **Platform Sound Card** - card#0: + + :: + + USB Offload Playback Route Status -1, -1 (range -1->32) + USB Offload Playback Route Select 1, 0 (range -1->32) + + + **USB Sound Card** - card#1: + + :: + + USB Offload Playback Capable Card 0 (range -1->32) + + +The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as: + + - ``USB Offload Playback Route Status`` **(R)**: USB sound card and PCM device + index pair that defines which USB SND resources are currently offloaded. If + -1, -1 is seen, it signifies that offload is not active. + - ``USB Offload Playback Route Select`` **(R/W)**: USB sound card and PCM device + index pair which selects the USB device to initiate offloading on. If no value + is written to the kcontrol, then the last USB device discovered will be chosen. + +The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as: + + - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card. + +USB Offload Playback Route Select 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 (*put_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); +.. + +These are specific for the **USB Offload Playback Route Select** kcontrol. + +When users issue get/put calls to the kcontrol, the registered SOC USB callbacks +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 = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + usb->put_offload_dev = q6usb_put_offload_dev; + usb->get_offload_dev = q6usb_get_offload_dev; + + ret = snd_soc_usb_add_port(usb); +.. + +**PUT Callback:** + +Can be used to track current device selection, and to issue any external DSP +commands that might be required for enabling audio offloading. + +.. code-block:: rst + + static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) + { + ... + if ((cardidx >= 0 && test_bit(cardidx, &data->available_card_slot))) { + data->sel_card_idx = cardidx; + changed = 1; + } + + if ((pcmidx >= 0 && pcmidx < data->status[cardidx].sdev->num_playback)) { + data->sel_pcm_idx = pcmidx; + changed = 1; + } +.. + +The above is an example of keeping track of what the userspace entity is +selecting as the playback device. This can be later used to pass the information +along to the external DSP. + + +USB Offload Playback Route Status +------------------- +SOC USB exposes APIs for keeping track of the offloading state, and expects this +to be maintained by the BE DAI link that created/added the SOC USB device. + +**SOC USB State Flow Example** + +:: + + PCM Core | BE USB DAI Link | SOC USB + | | + snd_pcm_hw_params --------> dai_link->ops->hw_params --> snd_soc_usb_prepare_session + | | |--> state = SND_SOC_USB_PREPARED + ... | | |--> slot[0] now active + | | + | | + snd_pcm_do_prepare--------> dai_link->ops->prepare ---> snd_soc_usb_set_session_state + | | |--> state = SND_SOC_USB_RUNNING + ... | | + | | + snd_pcm_release_substream-> dai_link->ops->shutdown---> snd_soc_usb_shutdown_session + | | |--> state = SND_SOC_USB_IDLE + | | |--> slot[0] now idle + + +When executing the kcontrol get callback, it will loop across the active_list array +and report to the application for active USB sound card and USB PCM device indexes. + +USB Offload Playback Capable Card +------------------------------- +USB sound also creates a kcontrol for applications to help determine which platform +sound card USB offloading is linked to. This will allow applications to further +query the platform sound card for specific information about the current USB offload +status. + +This is added as a separate mixer driver: + - mixer_usb_offload.c + - kcontrol: snd_usb_offload_available_ctl + +**snd_usb_offload_available_get()** fetches the associated sound card by utilizing +the **snd_soc_usb_device_offload_available()** API. + +Mixer Examples +-------------- + + :: + + tinymix -D 0 set 'USB Offload Playback Route Select' 2 0 + + + :: + + tinymix -D 0 get 'USB Offload Playback Route Select' + --> 2, 0 (range 0->32) + + :: + + tinymix -D 0 get 'USB Offload Playback Route Status' + --> 2, 0 (range -1->32) [OFFLD active] + --> -1, -1 (range -1->32) [OFFLD idle] + + :: + + tinymix -D 0 get 'USB Offload Playback Capable Card' + --> 0 (range 0->32)