From patchwork Thu Feb 8 23:13: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: 198648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514917dyd; Thu, 8 Feb 2024 15:27:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWo6aXKZa7ru/dMVoh8i75XE1hUerL70/7s7kPGZXT7n6h0CYqktrR58dUHI9e8RtbOoYTt+rGzf+5M0UImO8KDuruuVg== X-Google-Smtp-Source: AGHT+IEXj5bV/w6G+K+nDHnBpK23SEs6UAbSXquukB5KC6danWUqeJ+KvP0sEat57YPl6pqILtYo X-Received: by 2002:a05:6a20:6a0e:b0:19e:99be:c53a with SMTP id p14-20020a056a206a0e00b0019e99bec53amr1636517pzk.4.1707434841196; Thu, 08 Feb 2024 15:27:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434841; cv=pass; d=google.com; s=arc-20160816; b=f8wB/Ev7qcigvlNdoZpP7MLqCONZTiEm0mhGLklsm6q88XBB1zjGmIQGHZ7kJqtWfL amE6n407IErYl3eXX6ouWapTmQ8GBTnvobgj6JGpikoVPwSpdCpg2braMJkxtiz9DY6C lQM+m0f/0gqfWqiHGSBeqJ0ZUNy55/gMhfonpk5h4LdGRD5eonHbrQzxzGL+hRRv+8kv UOOaJ7ghJgEb/mq/UE572SAR4M9QaLpqZpMOl7RiGz/tOegmFy8yTW0nL+FPhtlzMsq2 PWUJ7bcs7R89/kydW+r2Jyemz3Z2Vj3QcSi1cpZVZHgdpuWrjPjl/ElCBXIJL2BmzfWh FTXQ== 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=2sOcjxKmnstL/5ftZf5841vds3YmEI4sRJLRwbFI4Jw=; fh=G1xDANw3HTYVHjI5bi8cjTt7VfOY+zG0o4JxKiFL3go=; b=pAESRZ1hNpGANdOSPLSrii4omUnBeK6paYrU5I0S2QvUOFaXiy/ym1N64mL/vuSoku rmCHCGG5+P3wWPXbi7jQEv04fXwFlwKPWVIFOXOh2nhjRwa8i1KLX/OE5Zr1UWx6Ojnv m3XDz+Jx8K5C3jy586ZfRaztQFMAsgajqmuyZ/Xxq/RGh1ZSIrlz0OkusFisAccnkvRf jnbUJ0JtMtP6b2G4Yimgn1eJgXMt7kGNsGoqf2tXG53q++UpePbW2A3NarsTQt5oI74K Kamy9MPTNnhwBCGifnu3eFatiZkEdfpS5I2KFUaW8UlPEqRCHVXleOKJE9LMsVsqyUcz kpVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nVQssM6t; 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-58819-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58819-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXihdoTgkoarYARPCKSB8CQ+75nvTBiULM2lXjHa46Dxd7o31gZyxMiBLZykg5UwPP9JcU9+NjxNVrV0xVrrGUMt7Nd2A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b25-20020a656699000000b005ce19c68684si608808pgw.495.2024.02.08.15.27.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:27:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58819-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=nVQssM6t; 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-58819-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58819-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 A7B4D28F4A7 for ; Thu, 8 Feb 2024 23:25:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A9CC5FB9E; Thu, 8 Feb 2024 23:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="nVQssM6t" 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 D1BAD50A69; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; cv=none; b=k6o0/4y/uCFNBri65Z74+SllONLrClYptR88RqhxkOlMpcFqeaNeNwxCf9YZQVjeyPFSvvwH7NAzc7v4qXekdwSyTe6MCm1TQgP8qE6SZED3J5wVO76aJhem3qOpBA/XcchQibwep9AtxarEK1UOSPEzpQdQ7Ho2sDZhUC3exJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; c=relaxed/simple; bh=/ctydeO9BP9IDNCKzOW84UaD1pWVBJmsNl/Vixk3Z5M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GkZY9ipzkBQjDdj7Uk898r/G9UvOY4bhQDSMXLCt0S2R3OrJKeAhQlVSAqYmnZNqxqCV8dW2ATBH6NqHhwXuWEFZQDJof4NU5FlWioP02M0rPiV7+fqyF3TZSgt1P3zyHEBmoWRJd24rmHHhbtYpoG+wj5cA4h1z2Xzahs5/0Pg= 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=nVQssM6t; 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 418KhRQ8019816; Thu, 8 Feb 2024 23:14:17 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=2sOcjxKmnstL/5ftZf58 41vds3YmEI4sRJLRwbFI4Jw=; b=nVQssM6tWjWN+AaUAvEFXjHBVSCl3GR1MBZh mZFhvLraLcunmZDyhyQSOKFzRqUd/Mw3Y5IvW5xNhYUS0CpIBDF2tixyabrxLKvA e5i3Er14Y8SwtwFliKeNPHTCCF+mgIsluMGAeCDQ3Oj4J7km9R1eCIZVTsGocVh2 o4TSc7EJUvSZsRWRMpToJBnc1zBvyCf7aNJV1GnM7uw54YQTiQxp/trSTsoi+A3I rP040Qj3+mrKgJfiPDqCnFzjPAZjpewOwzYoHMv+LNfy2jE9fPswvNXeQdbS3Aoe csJQq7b6ZIahHEpZ3Diw/VNZmh+oPErw4ooZShyXh8w1GYpPgg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujtt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:17 +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 418NEGP5009144 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:16 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:15 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 01/53] xhci: fix possible null pointer dereference at secondary interrupter removal Date: Thu, 8 Feb 2024 15:13:14 -0800 Message-ID: <20240208231406.27397-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: UP_Bh-r2YyQE-WRxE1odBi-VgumwIQ2N X-Proofpoint-GUID: UP_Bh-r2YyQE-WRxE1odBi-VgumwIQ2N 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375196075049428 X-GMAIL-MSGID: 1790375196075049428 From: Mathias Nyman Don't try to remove a secondary interrupter that is known to be invalid. Also check if the interrupter is valid inside the spinlock that protects the array of interrupters. Found by smatch static checker Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-usb/ffaa0a1b-5984-4a1f-bfd3-9184630a97b9@moroto.mountain/ Fixes: c99b38c41234 ("xhci: add support to allocate several interrupters") Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20240125152737.2983959-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 4460fa7e9fab..d00d4d937236 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1861,14 +1861,14 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup struct xhci_hcd *xhci = hcd_to_xhci(hcd); unsigned int intr_num; + spin_lock_irq(&xhci->lock); + /* interrupter 0 is primary interrupter, don't touch it */ - if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) + if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { xhci_dbg(xhci, "Invalid secondary interrupter, can't remove\n"); - - /* fixme, should we check xhci->interrupter[intr_num] == ir */ - /* fixme locking */ - - spin_lock_irq(&xhci->lock); + spin_unlock_irq(&xhci->lock); + return; + } intr_num = ir->intr_num; From patchwork Thu Feb 8 23:13: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: 198693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp522036dyd; Thu, 8 Feb 2024 15:44:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEU1D+pUnvIYV/znInpxKKLLpBbQjjcxLRHl65viAs7b3IJpHOSwUlKd2a0MO5SQrFsmSWA X-Received: by 2002:a05:6a21:3416:b0:19e:3cbf:60a8 with SMTP id yn22-20020a056a21341600b0019e3cbf60a8mr117828pzb.39.1707435894474; Thu, 08 Feb 2024 15:44:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435894; cv=pass; d=google.com; s=arc-20160816; b=yg8QYgD9dYLhdS4/6B8YSz6WHkUU2CEoxLEs8Kg09AzRP7BjAzkVPkdMOXgm2YhiMc ushURWSpF4ip39fzEBK+CzYhV+DVH0sIShqpFjZNJWWu9qDXm2PcrrhcldXYzzWMaRp0 U5xzguzD2MZADWDp/ilsmuGGiyvAAw5zB2gM8mPsuVpp+zAAzQn/9a+2LF/sSzLVZk3M NtDBsjcfczHjO4TJ0cneAG7qZCIQTEheSFlFjcGhNSHUVCeRRpoMIss8TVz/g6mShLTq tQ1u/OnkxlKnh929gsE7w+sBODJOmOcxAfWRelO0EXQ8fFu2jfAjP86RdOHbUDDrzb8b mgtA== 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=jumcsyHAMPRdK6BBRrtXrViYw1o9e9jHI3H7NDZD9Tc=; fh=uG1xFDlRK7OqUnVFs/vzXImfDm7QCvTqat9QbDmnegE=; b=jRfiso78s5L5YovOwfzim1GbJVvoad+cDwcLPgsphlXI3X3hVSf9rGA01uVYkeNTXx Yb2iRHw6T0wPysWb6IzK6gKXEdCOxPbkC16wfgBI+dtEivBfF2s27umHNh3FsgmtpI4K /4usEm+TnA0U4G7geGlusC+BKKKlc0CedXOxOQq/h+VwMdq+wqocPv48K+6BtTOa2HE5 LUE7F4hrmd1AoypbsJ6fc5Pkacg57et9e7Z11bCT/ImpYj7EQpXzkW5oEe9EAaKuU0ew pylhr3+hDCYfPKz64Y7LG8YTk5XPdIHJ6OrZAHyhtsiWRHXtn5kNRPVzAbLqqP9uetXJ v5eg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=F8n6wV8j; 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-58812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58812-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUPY6OcGBA/Rcsq2Hw8V3UPhr1z2wY3PR8sl88DjQJvp4wXSTYrDBWIM3j3LvhxRpqy2OyqRu6M4KMks7zqHSeFcN+N2g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s23-20020a056a00179700b006dde1bdb08csi527839pfg.164.2024.02.08.15.44.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:44:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58812-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=F8n6wV8j; 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-58812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58812-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 793B3B2B7D9 for ; Thu, 8 Feb 2024 23:22:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABE3559B4E; Thu, 8 Feb 2024 23:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="F8n6wV8j" 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 7F6EF50A6A; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=Sm/lJsd1YtQcW4aWdzsy2ni2qlA/p02pjsbJ71sQttBy/UScYA1Iz/n2A/G0MidDvdBokPiepPRm6ee6FAx06URm/ccV22zw7KvjZrnEmTUu8wLbhe1jQMy1EzfIwh7ddu0IXBuyqLxA2ZltwKbfEg4k6yQxRwBQ8Ek4O5vKSDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; c=relaxed/simple; bh=AUzYa+W3vXThhkfZrkvq18z95m/MUhJSaK13Esrt9IU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DjD2vG+QzThH7SlwRH0jvHACrr4XNDzLd6mQYfkZOczW0xNNbDBdnnjeP7DCd6FQu8A1JVPpjayXRX952ZxpmzMt3+3xBM1T5oQp+0ZNgt1CGXnZKfH0krKSfHVHHRUv831a17Zq1qWeBDMyvUiRZoZvnSgW75PvQmNIFh+c+wY= 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=F8n6wV8j; 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 418Mqt56008173; Thu, 8 Feb 2024 23:14:18 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=jumcsyHAMPRdK6BBRrtX rViYw1o9e9jHI3H7NDZD9Tc=; b=F8n6wV8jo+3D4QCffSq7/J+CRknaj8BZan6H 2vdUiWpqscI0/NfaYSGm+ykyvuspkiZ0VT3wwpqeCRrEihJJGdo5du54zYJ9pDmd 0VkDAklAesRtj3IxJDOSfUQXyPz6MiqIZjlFqW7H7OFxACOkf2igx0A8EAUhJD2B YwfsfK3s9vwIchro7lznOQKxAF4nGVJCSy1CCChHzq+D/1z/Ot4KmTGI4BDHGKCf rtpjLiWM6drs9M0wv1W3+dyO2sUQlveN6i3ADBHCQl5Qg2B/ESk0jK2clEImVWwd ObuWTOGN5xZho6cSIsFdHfUzWx5L9m/MgosNPZEGL9It62hnYQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2aan-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:17 +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 418NEGtP022030 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:16 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:16 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 02/53] xhci: fix off by one check when adding a secondary interrupter. Date: Thu, 8 Feb 2024 15:13:15 -0800 Message-ID: <20240208231406.27397-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: VLcCHzYUv4yxZ_dA3mNz8QIsNh7SR_HZ X-Proofpoint-GUID: VLcCHzYUv4yxZ_dA3mNz8QIsNh7SR_HZ 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376300363894245 X-GMAIL-MSGID: 1790376300363894245 From: Mathias Nyman The sanity check of interrupter index when adding a new interrupter is off by one. intr_num needs to be smaller than xhci->max_interrupter to fit the array of interrupters. Luckily this doesn't cause any real word harm as xhci_add_interrupter() is always called with a intr_num value smaller than xhci->max_interrupters in any current kernel. Should not be needed for stable as 6.7 kernel and older only supports one interrupter, with intr_num always being zero. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-usb/e9771296-586d-456a-ac24-a82de79bb2e6@moroto.mountain/ Fixes: 4bf398e15aa4 ("xhci: split allocate interrupter into separate alloacte and add parts") Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20240125152737.2983959-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d00d4d937236..a7716202a8dd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2322,7 +2322,7 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, u64 erst_base; u32 erst_size; - if (intr_num > xhci->max_interrupters) { + if (intr_num >= xhci->max_interrupters) { xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n", intr_num, xhci->max_interrupters); return -EINVAL; From patchwork Thu Feb 8 23:13: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: 198645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514623dyd; Thu, 8 Feb 2024 15:26:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXDi59WGB1lIRiIgoY3Uv98B1L5P/H66wVdw8fy++Wo24Qv67wmTiEVvrcM4Ist+nzY1I1sNEQtXAv56cXFYRFBBgCexw== X-Google-Smtp-Source: AGHT+IFbsY9+xY/FyH4uZdlObIrja6pYyh+eBBClC/jofzrTKro4Lst9xm613Fa3NohED7JsQTnG X-Received: by 2002:a05:6214:dcf:b0:68c:87c6:d69b with SMTP id 15-20020a0562140dcf00b0068c87c6d69bmr899270qvt.59.1707434791825; Thu, 08 Feb 2024 15:26:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434791; cv=pass; d=google.com; s=arc-20160816; b=WLTJ6C7SACpTXc00INwwMiuMsQkc0jOjm7N9lvV5Dk9KT3LbF3POZlR21CPioS3tRk KLwINDgX3Rn61HoGisDF7bRF23uSz3uhWk/sQJJ/v2VrQ3rjDacC5Y+EBjLu2jun5BBr NkUfM93UTvDQG7r8muE8rYAHnDTmlOh1hTc644kwvmULPBsQXAD7cxzT0zOwYrHhOo5p 5pk+iNliPd0eP72EmMXyTKIXK2GJVVI+nNSGDTeOYZ8TYzuio2N7C6atGO+PDUvXAQgb awANOE/QFPgEiyvPw1kA2aJ54L92kQMhBDQaZD+HAb8BTxdAefSYleVgij/S6+zf+Lnn XV2Q== 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=HczAAAXhEsk4XHXuGppn2bLe0mn+4kCtM4YB0kVM3s4=; b=tNGNsTZ5h4uw1URZ9jjMWvPNsR+Q0GiTs30csBouweF12rxRWiOo00q+J2mhFNVDMU xZhGvJRUV3GIjrMPYOLN2zMynw5oeW2gB7a3MifZtXp0xCP1m0Ngdlcr72G903/4adq0 kG1i+axxvR2KwyXISm8YUNjhOSGW3TwvzmiQIE0wvegO0jkTmB/6ffHLh/V2MXImhNws NqrylLs+mT7r1G7WCmeEmuvzBcjA15oRkzsQSmTCl+9IhIZJ5yEUl8DHqW3cGcd2abBi 0J876/tngcVVwRbt3fkGaZYVfKtbe1LVwahyTm8PEQ6/uBL3WPsP20BMHakKZOXhgkK4 Rl4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mqP9cIx0; 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-58818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58818-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVTE7RLvPD1pkWIiuHuOCNl48nlk0ZTDyykRWtdXqjwf/DFVWLkB1abPuqSMh1YAX9dGeaaP14Y5eJEOJsnnZNkZt0K3g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kj23-20020a056214529700b0068c6fa95b48si659011qvb.466.2024.02.08.15.26.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:26:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58818-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=mqP9cIx0; 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-58818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58818-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 0BC121C25703 for ; Thu, 8 Feb 2024 23:25:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08DD95FB97; Thu, 8 Feb 2024 23:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mqP9cIx0" 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 7A3F650A83; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; cv=none; b=TdRTpLVS4f3fMOlhEAsWNkXL4POTdG+wWBkwrLi1/1P2SIn7xsQWWZIKrYHPsvCo+crGXGCyM0KGK16osNDmRmfx5qgpU1S3XVSuPGauMNMTOEn3INz+9n6pgBKlE1yUOKZF4HHnt1QBl0G9RLId+VYQjMw/IPcIsLgopKCw25Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; 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=atVKWWjdCr+Dsqmdzy7G4+3jAdV/QZwzpSfIrxbjEGjDebKfN2grV+XR/o4tEXo+OQdch/FC9G8HTo2hebM23oqpkxhgUzEBhXLaWn7w07fSa4CdYZdJkyB/2QpGAYJY/i/wUcEqwLFqWXkxiKI1g040sCl5uQYnRlOpeLHKmWw= 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=mqP9cIx0; 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 418MmN3S002112; Thu, 8 Feb 2024 23:14:18 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=mqP9cIx0InFl7OdHAQAPRVMprKdpURH8hyxv UkPKn/HWmUHuuA4F+zYlg1O5JcoK+ZFTzUjtOSf8gaL3aXDNUH2JT0tky+Rf4nqr IABYPGzZ8jiD1Kn5mskLYL+gwVfF+Gdyny3J35ZTx1AQsVYwv9DUaWY7dG1Ifen0 mCMe8b1bG1h1y5CxnrIT8KoRQU03gemSmR3OFof3tyNWnq6RoqZmsvk51ngGXCmu ffuWPcmDxPpwrCoesUIRfPJ7m12Hnnz/o2MMra5UcXurAI4/kYD+FedAedqwAQSZ i8bfMIfweDzyvqrG9c7Ed+IU4VGhjcJZsgXGALQuWiI5rPPjew== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujtu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:17 +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 418NEGLm013078 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:16 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:16 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 03/53] xhci: Add interrupt pending autoclear flag to each interrupter Date: Thu, 8 Feb 2024 15:13:16 -0800 Message-ID: <20240208231406.27397-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: jV9Z2PR1PTwfQH0bOBidFR4StK83vaMM X-Proofpoint-GUID: jV9Z2PR1PTwfQH0bOBidFR4StK83vaMM 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=742 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375144320684490 X-GMAIL-MSGID: 1790375144320684490 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 Thu Feb 8 23:13: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: 198644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514602dyd; Thu, 8 Feb 2024 15:26:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZf2LqBix7V6epj42YXXswIUUoU5P/WxOpWP7IMPegj/lbC51Fwfd6z6TgpIAKKkmGWJPr X-Received: by 2002:a9d:6184:0:b0:6e1:12a3:f291 with SMTP id g4-20020a9d6184000000b006e112a3f291mr1136838otk.12.1707434788748; Thu, 08 Feb 2024 15:26:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434788; cv=pass; d=google.com; s=arc-20160816; b=b58RsCbqM2CkP8sqNDHCifFNAViTB3GTJnPG9xf/poGiMcRppxWRkTJyOxu+OW/N7G TcBkE+J5Qk7of/ir6X1YYgA696wGDSyEft3dfp02p1/fwcy2777SEQIVHQodRUyCftms cj18isRuYc59CbQE1k5WbgqIh1PC6/OyiueqNFOUHLEuSI+zNrbLXJz32UhS530SymJz cnUvDTI+sn7rCxJK8Fc9XnGsaxBwTg7jB+Qejy9+K2c5spnLmlsYA5JKec4vtyGxu2Xw 8eYftpN1CZhiSQDETk897Dne1iCHIGcV9A9VdHVklWQLY5LQejC4wdNYHwGDobBkCdpu rVXg== 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=ps0LrW9fe07ZpRv1v4cuUEHtkE9i0BwcPG+iqQWLnZw=; b=WhQUeCI20oIVQkIo5pjxIbu8DC+RllL9tmezsE1HgZJcLK6ZK/GYUuzDHkHUiDB71d shQEDS/X1x2p2WGCfY+l225uxSlIBJMF9KYzA0Cu5LRHA8dyJ/Lzti+RYhH72q23tkUt /Ia990ehaqViHFMdgA7PKFY2jrtcjeePe+ITJgdxYhJP2EuFLGa0TWK0G3rgFWo1thOi GWzNx+GWHvum1YxqTAj5ZjnUsG0QUopqL87ZGBTwiG6MlGsSduqrhudY9kkj+btBNHlY y6U8ZCw7u2h4h5QBk5LEErT2kURoPvZwZy/Dwx2P+1dx1mQ8JS/Zh8AN/mHgflXDq69e ZX5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=H6hBMbl2; 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-58817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXNH9nEgsMcy+br6yChL9pkLH4tkSrqlJuOTbzg6eG+YvieUgRCgsvZ1DAJZ3cGBrj1ZOhpksyzzlyp352jG/QM2UyfEg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bp34-20020a05622a1ba200b0042c33533b0esi615040qtb.275.2024.02.08.15.26.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:26:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58817-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=H6hBMbl2; 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-58817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58817-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 9CBB71C2579D for ; Thu, 8 Feb 2024 23:25:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC80C5FB82; Thu, 8 Feb 2024 23:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="H6hBMbl2" 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 778B550A6C; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=V1T3FcqgM8Tcw/3LQdq4e6MUOgDge4nkKing39qKK0pP+ocj7A6yrbzuy9ignomiXvSKy/lM8oBAH+EBaTVW/VvIzfYZkpahOegxP5WjjVscCUmMgx4Bix0hYNgB6j1pv2eSwY7mLyST52IWroNyTWLdB4z8LHqNOjbetBEizNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; c=relaxed/simple; bh=u1nuq17zD0xhgBZbYsuMjFfbINv/RaVLoPTPOjJ2BuQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TAIbI5I+FV5YhZxoIH0vWZ61rc7xe3+kXnLzSQtvzq76JSOSDyNEyktF7LEBMWnH/ItrSzMDHARu/DjBHI4DNDnlKTIx/ITt6Rkrxs7wqgwCn0PRuYnu7/GBusufoPtlIod21tEXvkEsBl35VQqdplI8gNu8epnYQ9ACQO7MKdc= 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=H6hBMbl2; 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 418JN6rq023417; Thu, 8 Feb 2024 23:14:18 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=H6hBMbl2oxWEkUHQyLHQGQMx9NmOqzFr8lBt oAbzPiXYHPbac97ineu70MScwC/g8bty3YgdLQ/I1Nb8A1zorepH0+kzcXWlmCr+ eKYd34YJN6ZxGoj8BTv5vUnuzWhOMg5uQN7P+gnexBsbIO3F4V85VUZSTlHA3m2D EEhN4pQKOY9AE6XbHM8qcXmEMMlUE30uNEiGGs6y7VR3KboD9yOiGBDwxAeXYTTP nHcQ4fmf8maYYP3auq44vlfZPzKWT2oLTcDAZADjH9NcKuI1Ksx/o+Qg1QRC06mC JSIKiWaVaDRLTv+StDBp4+EXYJTBwVTM8o9J+uwQmATsHMy2cQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k4m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:18 +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 418NEH59005524 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:17 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:16 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 04/53] xhci: Add helper to set an interrupters interrupt moderation interval Date: Thu, 8 Feb 2024 15:13:17 -0800 Message-ID: <20240208231406.27397-5-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: jC9Px0ZUE7YJLKOwu8TgizVV1hughGfU X-Proofpoint-ORIG-GUID: jC9Px0ZUE7YJLKOwu8TgizVV1hughGfU 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375141148176726 X-GMAIL-MSGID: 1790375141148176726 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 Thu Feb 8 23:13: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: 198698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp525503dyd; Thu, 8 Feb 2024 15:53:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzVrU7302tyVZ84rU4wTpE/OKkCLU/BhpP+QJZI80FtheuGeUlAltWWc0HjDQRps40VHGYtrfLmi1VXSx76aZVwEaoQg== X-Google-Smtp-Source: AGHT+IHncGH5iXKWWyTnjNTDCj0IyG6fnZ/s5glgg4MRcoJEdynHnf920Kkx3i9MeixFv/H9FqDB X-Received: by 2002:a05:6a20:94c5:b0:19a:fe7a:89cb with SMTP id ht5-20020a056a2094c500b0019afe7a89cbmr161001pzb.20.1707436418736; Thu, 08 Feb 2024 15:53:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436418; cv=pass; d=google.com; s=arc-20160816; b=G1xjH2M0u177zlBbk/40Q/FsdhEghkuK0UfzqOiPyc4lCdIULkhIo4nYKuGbdhwXV/ v+hj09oT/0XcSoLT4EdN+x189BE+TgSGPfaegg5kkiY3BMXEGRo6Nr61Qol7wp1HE/+H Mrk9cIj8QY28C0DCWEzo8gu1clWe3Ub/SfAmBBoFD+eFp5ls1oZ9Il4iG45QUvI5B/HO aj5O+5dDgt13fMH9Bg/mO0y663StKCPCaJAq6n4zODfhXmgdfEte+jOb4qtk17ZOEU09 8ita0Le2PSgm6G0h8B0AgDzFxomjAdWOkfYF5VL1TNkoSxP0RAEHAwZjMRZDsVOKXdBA +R0g== 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=vIEOYfe34j1NdG2zBcqRpmp4reHZRIKzD8461h7taww=; b=g6QuiYMCQlpfVa9Q5vtHxuLApv3ofrHuj1TqG4NuPtBa1uLncXTOq7YNPeickQPqDB Bffr+PjRTjixPR4socBko+fMCtKdZ91F6mWo+GmRuN4Rv2Ozz7DifqGmRGyULQ8zTpfT ocxWT8BWDXhcyqkZwvwn/WcpVt6ks2lnzu0oQ2FhjywpXPKFlCi7hP/cRpEZ4cpUlsct ORf9xyhW7DNgq0mgj5AiGtWb8CQsyYiNkfMc2stpeBvH4+gWeg+QTGRREUlYpDL83T8h uzQS2Y84HlL4TloGg8mqjp4MckhFfceow3JT7BHSB6PJt9YWZM0UtgYe9eaJFxTdOzDu KcCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=FNiiHMtl; 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-58822-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVkEvzI0F8Fc+/YKVc7N9/Tv98UmXh5dQH5NC4+s6ziahkLonmgRkp67qhCPfp3nnuRWcamwhxQcpRLB/4O+2ATzsaJ0A== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b4-20020a056a000cc400b006dde06c69c2si560327pfv.189.2024.02.08.15.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:53:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58822-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=FNiiHMtl; 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-58822-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58822-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 9ACADB2971F for ; Thu, 8 Feb 2024 23:26:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 280F15FF0A; Thu, 8 Feb 2024 23:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FNiiHMtl" 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 77CAB50A7E; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; cv=none; b=LyIeiWRr/xs2Cu+Vp63rOGqcy6HwzkFj+H2GqGnOUuk1FnapZg1+FbIpiVoM0bFlxGLA0eR8QQXmfppBxlXlNi4bv5MTb29BRMCbNhDI/xk3cElWK9o+IJsIyAynhOeENUvCLF86z+3CeaJjsJ1QwRIX9/JbJp60WWHmISJ7/tU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=mMfpAsIQkrbAWVmvCtRxOhWRPl8nuSyQX1IpdSaNgfg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BsD8SbT1IFFUMvxRatgLzKoMHHfgeNskAC53oIrUAXqNbJ4fygHyDi9pICJvIz13gSNK+NiaqjGskhkYRQzqezWM9AVSjqHOD9oV6MreOSNBpGby1XTZKSAyX76jKwKxo19NIAgjIcSQzxJ0016QemIhGDCbhCUWo3aoMzQBnwE= 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=FNiiHMtl; 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 418Mf3TJ022643; Thu, 8 Feb 2024 23:14:18 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=FNiiHMtl8/evjAD3+BQlaYvPka9L/47++SKQ gRLvC+aitnCt0UTraei/9jtqQV9XIcinDBTdc/xejK2ZuvkRzx1ezQyDFAzSVw0f ravDH04suj4OPoKC71k/CK6ujYElGUlWnnDC3vsoky95DoMmdCVK6Z/zaHo9lB3O jost0pVYNWYAPM7TmlQyaZWpEqeLOop6Y5pgynNQyxeU+tBf+U1MwwzuuV38RRt8 55At5mJF8BWt1UYzLxdcpUURTsgaOeMnQLiXtSQ+jRUApJmyJJtot85Gk8byxb/6 w5VLFHriCZRhv2UU/26QwSvvkCGgsCPwqzwtYZJGQ3DJYua3/g== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:18 +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 418NEHsg013081 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:17 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:17 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 05/53] xhci: make isoc_bei_interval variable interrupter specific. Date: Thu, 8 Feb 2024 15:13:18 -0800 Message-ID: <20240208231406.27397-6-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: KznavazFv7W2o9T-fozCvAQrhTcK2yBI X-Proofpoint-GUID: KznavazFv7W2o9T-fozCvAQrhTcK2yBI 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=638 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376850152014612 X-GMAIL-MSGID: 1790376850152014612 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 Thu Feb 8 23:13: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: 198656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515968dyd; Thu, 8 Feb 2024 15:30:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxvjuhpIiXL+FNFimPESchHq0O2239g4rI3Ltyq5Ndts5Vl3Jg1n/PEzx9YR7GV7JEmicpxYGSHpiS2G+gzMm7EXw29w== X-Google-Smtp-Source: AGHT+IFRzTjGDuHUg736f9Z7L77EO9WnVw41lBI6Dxdqejcx3VzJeLJr9YNE3HtpxbkMjYW5pb1Z X-Received: by 2002:a05:6402:28cb:b0:560:5c7b:ba5 with SMTP id ef11-20020a05640228cb00b005605c7b0ba5mr150713edb.19.1707435006004; Thu, 08 Feb 2024 15:30:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435005; cv=pass; d=google.com; s=arc-20160816; b=KaDrZF0yxC10oEaVUjgQMv91lXxe0aThO+vNiG03rh2mv6QINKOAefg8IYWKq1bfqE qg9jY8MSnJRcjEx8/HkbhmGOFd7AOR1DClEEwQT7NLanS9mDInSAw9600kw0WqV/7Yuy aY+ErMmFpRp9TyvyU4Zu+Qt1dSivJvckiGqJ3j/iKX3b9EQSw+uXns2lQWgCJlr6r0vf ijZ7dBM22DL9j2H3c4UdRTKmQbBceLwio6FmhRmZ0s8fI3dgm7pkP2xa4ZJrlw0XD4Xp s/9HCmmajZmTH7sI3yduCv85tvG0VieaXhTZXrAaKs0J9wtp+FlibnrAtO/h6m1m5guc Fyag== 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=TM9p2GGFRl8zcSOqMJpYsb08/gDsOLC0iZtHVRFM14c=; b=KME2Lx7GE795/CaE8ZrKa4otGnavbQdhaVRIXKhOg+oduLFsPhOwL6/MDB/IBizoHu CHVrP6Sp11BKry3G0COw7vTxhRxDjvjyjJqpVjRU0lPUFPylUi4uJ/eRVaiaZji2WE22 ouxkeEf4lGEGWLcAl3/DBrJ2dU+UgJufSMtuGBydFb9+gTbZDx8gqFfJGsCmq2ihIMeF 0zIh7FsnnwWF5Q85qw4wiMjeuhVR5xKR17YR6lYu6E1RjDZHBK9OhGfgVAF6/neRC6bo dekooML8DI0UINaE2S0rQbLwJJfd41IclkYPSKLrTnr6nhd1SZeT6wBq1454/xEdTaXG 8BQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UJNCcHgl; 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-58827-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58827-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW7+xF8NTuIccHtDNYhKJEcwwiNTBYjMBa167zmR+4x67SWYpcS3a2du/47pAYt9GaB6/qAjyB6mASv1VtOeXm9ZSqT4Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bo8-20020a0564020b2800b0056035dce894si210777edb.145.2024.02.08.15.30.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58827-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=UJNCcHgl; 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-58827-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58827-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 667C71F20846 for ; Thu, 8 Feb 2024 23:30:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5763160EE4; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="UJNCcHgl" 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 3C1A65025F; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434083; cv=none; b=eAg/vcaFB7IrqboNuROJqxHjbZ6IO7Kvi7G3/J9Cl68tNVjUSbvOBMYNdoZDyVkDEvlBEFXWWPIfxB1TaM5mQY7sYgWN+nz5Uc2XU2+ciRnZBJWAIRYQMhZplaccr4wASMftrFwyqPyqrUQPqQGo4F4MyYHCs1ecS1GplHXmILM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434083; c=relaxed/simple; bh=kBRKQewBFwebBlSfn7sxo02gwubgl581TIfyTJo/ozk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RbssGXU8ngQlD2MZFDH+GoVuMivrtwWWKgpY2TVFkMaF2naDaoY/ZgYKxJGKpSE9gQEH5duZdPrpSIqSt5F4MRDTih9uh7RZQiUdTcg3d3YguDwz93xtNrDxQOKXDtGtMNnHFjGXbVOeiImXCYt81IVgpTYXF75iVGTxrybrnt0= 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=UJNCcHgl; 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 418NEJIJ030158; Thu, 8 Feb 2024 23:14:19 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=UJNCcHglAQSC7sPmuN8UH7Yp70IYmtGoyRco egrrZgif8heTA2+N7+SOwMI05AMG7aW+eYR7YNLIdZTVPBq3ZtNNl4paL/rqahx5 FU7IykElolrja82xmD4oSKhbHwm0Gqwv/oiC0+vt8b1sYnlT15CKqXDMICNXhVHd 4VXbfXOyMSd0AO1DyCmeP0PBDfThTyIIwtVtqJoUd/d8QlG2O63kpVsfMKIfUy1E Ka1y4LjgKawbbx5fOdwt2H/P/pwhKDt5d9XgZKAreFmT/jV86Rlr8wlS/s0ySn7O BAv3Q2YyC0fcd8pZQP2m99L8PSP884nnPHLB+wGox3F64a4hfw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbaj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:18 +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 418NEHHX013086 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:17 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:17 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 06/53] xhci: remove unnecessary event_ring_deq parameter from xhci_handle_event() Date: Thu, 8 Feb 2024 15:13:19 -0800 Message-ID: <20240208231406.27397-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 7GjNYeHCyostH8ZVGYTA7NnMP9VQNmHq X-Proofpoint-GUID: 7GjNYeHCyostH8ZVGYTA7NnMP9VQNmHq 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=994 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375368925056283 X-GMAIL-MSGID: 1790375368925056283 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 Thu Feb 8 23:13: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: 198657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515992dyd; Thu, 8 Feb 2024 15:30:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVU0bU6hXGVoiMdWEhrW1LlZauUR1o3it56S8EOjY6Cg0K6JTpohZZC4CwvtsCm7BlSmePI0cas1JfchPsLc+v9L0TCxA== X-Google-Smtp-Source: AGHT+IGlqJKArR5N/LYkM1cLsT3ERELwvG8WB7FPTypgqNFJ200hXg2U8Nsft+W7R8j3tQ83kw37 X-Received: by 2002:a17:906:7d6:b0:a36:927e:cc0 with SMTP id m22-20020a17090607d600b00a36927e0cc0mr538187ejc.9.1707435008590; Thu, 08 Feb 2024 15:30:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435008; cv=pass; d=google.com; s=arc-20160816; b=mmyVii6wigA4CkZXbw7D4nU+64YjAYddpdQRXt1UzYAIOKz5TyGzQ923eBXdeYZM4N QJJ1JLtfeWDlwKUTJ53L/Fm0Ykb/sxOTQalmUeLqkdmI6MuYq0kRg0nSaFfsU8IVLOcP W1E0EeKC85Fe9vIDXdrJhoRRwvAPV4NxFqeqhkp6HU1p1Z7pbiycKKPIaUfdksLEDzQe Djv93KmKeQ90scti6m+bPgN5QI2noTpvsqWUF2QT+x7srHM8wGr//opww4VOyPnzkng3 FVIoagD+jngdGCS+YRtkKp6QLPxCc4dd8CFYWkhlA18dFKlC3of61G+n1RJhx7An1Sku QJBg== 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=OUYf3ofsp0HflnoB3meRxUazhVQ+60m0cmW1yZG44xo=; b=ZKv/5oYBqap1PdJFqx7XqWjgMkXdPURk40ioB4ipEQ2xOjMAVzYaKBRlBzrQEluDwE mua9vZ9JPuMgUa78xLUalB1c3yBzMFDhzr7Hw5zrcWUmJD9aXBSSio+J4CkbNuA/HA04 6fcn4uuK+Mw7Dj+EyZLm/xikAo0tHonpclIppwz7RkGZUa6gacH4UgSOC625/HTvzSGs +5GqP38w76HlBLVEVSW+HRChi8juSou3XtJokJ1S2UdFWLoLRUwCWeYX/46rbWHKdFGR 00JafFrnDCbo9G4cJmIj05NwXU4HF8o0SKvMpZ446x5Q03VYkhZ7HSM/Tn3rton6n8m5 TFTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="AEBApGw/"; 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-58831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58831-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWHBdv3nHpP+xqaKM9+rhxQSXVuDBZTPQpIxNUOZeeXPTgmUKb9Kp4vgxujYS1VYDi+vn3xgqBOlc3cHcjpLfsQM8FNjA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t21-20020a17090616d500b00a3bd3ce7a89si162072ejd.10.2024.02.08.15.30.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58831-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="AEBApGw/"; 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-58831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58831-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 076DB1F210BD for ; Thu, 8 Feb 2024 23:30:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59E87612D4; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AEBApGw/" 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 16A0B51005; Thu, 8 Feb 2024 23:14:39 +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=1707434086; cv=none; b=O7KQn7IptwxbWD5/QYXHbZE60pOEZv4BRDyH/K5UAqtM7w2+S4s26JIcEMkQZYSUGI1idxYZho5bXRhvxAiuyIBes9ZA1RFWKLJSxmOdkRFIdrT9Vxwx0hKZb8sLBcxQRpPDvLV/q492hSTwSeYMD4A0q/7IZ2yaoGbo+o9HznQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434086; 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=tOBF34oOWskuAdSDwjXp4/Z80THS491UP0J4iLrIYMhRGU6gseKdnVOgjBipbh53Pf2k8tsP8OMf8AtzDkkKnY23Jr5UqC5skgCCGObhI49YEMu/WnaFnA+cooy56u4/XU96K4hga6FXNq1PJ/TrCw6XMphm/2s7CLx0RTUXNI4= 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=AEBApGw/; 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 418Mk55W029816; Thu, 8 Feb 2024 23:14:19 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=AEBApGw/IkkSrovJhMhdHqhx/5YmH5UwFutq NcqlEU8nn2qvyDNBKEofFhdBlQFno0LUc3SMcAns3QWmDMZeBZcyJtQtR01OQre4 jRMfL+NSIERXEvWPPMQCyJOs10zjLDY9wWWpz+7FAp/8ckbrobkXH4J5UIu8vEEa Anw+NvwdVqgnlSmaL4RJhBfkOL/UHb/tDpyTF8SRTL3W6gUiZVTQmoKng3nCZ05F EjmrpvRgq4Wl56nR33BNYAUw0rkAoVev/zTkwAbCgyFQrhDrPQLzf5izTKubjoFb pIagp1OFB3Dx77tW59XUfIJLfP206MhS1rP5mVVzRT2LuOXVuw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1p9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:19 +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 418NEIGl012196 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:18 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:17 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 07/53] xhci: update event ring dequeue pointer position to controller correctly Date: Thu, 8 Feb 2024 15:13:20 -0800 Message-ID: <20240208231406.27397-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: sP22P7Fda8SrKVI3FRS9q_RMAUOS53sY X-Proofpoint-GUID: sP22P7Fda8SrKVI3FRS9q_RMAUOS53sY 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375371572335204 X-GMAIL-MSGID: 1790375371572335204 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 Thu Feb 8 23:13: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: 198640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp513251dyd; Thu, 8 Feb 2024 15:22:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/h1A7Yi3r2xwTVvANtkfXXSIrbmUE0VmtKshJeqGE8iPiI2ZqmWU7NxH3CX9mS7OkXbdH X-Received: by 2002:a17:906:4a93:b0:a3b:aefa:fc28 with SMTP id x19-20020a1709064a9300b00a3baefafc28mr497880eju.72.1707434578619; Thu, 08 Feb 2024 15:22:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434578; cv=pass; d=google.com; s=arc-20160816; b=FLypMobYkwep7N4rO8RGn/lT7yiOeQXwRfQm+cZD4RjRaaVlDiHgv4XW84dzs+Z2gN O2fsM3GpDqGsQR7Nb1LtDpupEIjmQ5xtDTkIQIjj5WY6rt/VZTTnG06HtTm1NHKK2AT3 FVcxSCqpjA9JnMn9Y25CwNS0h0aIPTpfLGzBviC1Mn7Zywz0TBUn/gF25eIH7sNGM5zK mfvmLUoGu4TysvS45Tg/P1HO8yrlZc4HXZ7CHfaNsp3sB/CU3jkm8fFJ4SPrbo0oYV2R O6rn1i4kn3Ek8+kND5c0uzaaO7IINJr68SmQtXBlA+XFlfjgThEV+2Vsx63cjwAspZ+q kpnA== 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=kDcopA1t3qridOkkGKIstCc+R09HvZxcRLV3k9dEmLU=; b=MSP59ey1k2bHpRfM9TnBIOzUpvXLwAReA4Fo7FliiKX1ZzZg9Dz1qby+groTrdmJ3+ qjrL/Il7QL2OdjMOnYYPa7b6vrDlB+Y8q62y2Zd7Qd/GX1+MgAdPykKmlOUv0ps0PYiO HLDily7vcd2w1qOk6Y2gwDzZhbh/L6r3iFUoYV3Kspu401cjInwV+hR/6xl/eY8XmuPD BPNdsuamhrZFRyQi4SzOdRbsUfG/chacHR5dQbdcCJ4edyLV3C64vGyzyWZN3RXQ5g95 RZdwXakY1hrN8ufaZXAi2/GJagtI88hhP/XKjr5uMzYycljq3GiupNdlHt6/30bSwMJD rYJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GuVcHdS3; 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-58811-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58811-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXilsC7Cdh0K7dgDFefIrXJHJY7M6BHI+I4winvq7cY6LKmzuq0GDE0dOk7bhaT8srA/vdzjznqV22fEbCp6w0+XhK1ug== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c19-20020a17090603d300b00a385bc701f8si157251eja.960.2024.02.08.15.22.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58811-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=GuVcHdS3; 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-58811-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58811-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 8EBDF1F267AB for ; Thu, 8 Feb 2024 23:21:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F8F259161; Thu, 8 Feb 2024 23:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="GuVcHdS3" 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 611A450A7B; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; cv=none; b=PuMW5EcESqFez6hFe5KmtwNG3qzedeqmnuDVC48pKhZQUh93fyPfvEUTlvOfhR1HRmomUn5AK9kZblN929CULctdxrCJePFlFkLUgK2biqY8GsVoyQFVa7/kSG0I5fn3yunSQtQA3eEMqRMJnbQmv0ZAZHzsjbqbqOrinV16NWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; c=relaxed/simple; bh=V8MdAsKTPp0AteG57V12qaeFcyZsxonTIhHZ2e6F4Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mibBs+0xJ1I15FT3rGbPxKVqO9t2cPJF5F5ruDA/56nXviuKbmF3Rt8NnH0VfuinQ73WfjjG8ZWe3O/88muFdHbfWLkR2caxIEcX9wXt2i/wfBV2zwP7f2mj9RxiAvJuk1n4f+ejWLX6Sn6YeQEj4Vtd2PEBeBvAbddOULszYe4= 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=GuVcHdS3; 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 418JMcO8009667; Thu, 8 Feb 2024 23:14:19 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=GuVcHdS3o0J9/shn+Sed88QrlPvV7YbG5T9R UGzXhLiAvO7JfNvOFqfzt6AS+jWCfNdhrU/5m/woFqBeUDedcqVVrtvBldUDN4Rd uBUF1p3cJiPFV3f/KFckHe2Ie2flRlc/uKqiM6uSMF2HzlYrIfPcz+cCduyYJEJE 8Yo4YsbuhHF3LqH26KwLi7jFT7TR5h3XK+mKnrMRRCWQsU/Us6SZcy3ToPOIHe3z 2EsW9nPLWSWbtZSBc36FU3rlHGuxW4unID+RsDrXvtAwFNgnGmnRmai3WPaVtzDz B3s3QRmwg81g3+xBLBZoIp0+MuBe69C7M/gieHDIax68edVtfQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs01-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:19 +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 418NEIGm012196 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:18 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:17 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 08/53] xhci: move event processing for one interrupter to a separate function Date: Thu, 8 Feb 2024 15:13:21 -0800 Message-ID: <20240208231406.27397-9-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: RHkQaFtGU7USGusNuyRqtum-p57dwdnM X-Proofpoint-GUID: RHkQaFtGU7USGusNuyRqtum-p57dwdnM 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790374920749121542 X-GMAIL-MSGID: 1790374920749121542 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 Thu Feb 8 23:13: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: 198655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515883dyd; Thu, 8 Feb 2024 15:29:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVrw3eKIO7VhbQPV3NNmDhhkYz/4kAql6fNS/RFDax/QEUk6XGb8gVx4+ifbbp5aZxX/aHdlmkK9zzLkOEPfrE7hKgMXA== X-Google-Smtp-Source: AGHT+IE7wp1MK7zZbJw1ZqLbD45S6vsrnLgIh/vnkG82NmO4e2zi9Dzqd+nufO+nmJYx3SvqWgwO X-Received: by 2002:a05:6830:1458:b0:6dd:e1a4:17fb with SMTP id w24-20020a056830145800b006dde1a417fbmr1073345otp.38.1707434996254; Thu, 08 Feb 2024 15:29:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434996; cv=pass; d=google.com; s=arc-20160816; b=yEg2InXQFxDvx23lxa+t8uXykF9/HU0cwDCyx/39V+5j1+xtd4iWZ4r9VKep+j07e9 Fz1MYuWa5XzqJWM3a3wGVmfkLshKH8+zDuGTba3Gr6P1LakvIgWwm4QRd4NEgOfZgkWe DcVQS/Lio+NiKLpMQgZqaEMbnye2QWXvcSQWT1f0OqwvM7zjlzLtBp/ydnqjuVqnyoz7 n8S8pv40/yDn+0DQkxEBoV2JAJhd5rLz9MXmc1e4gL3Ih2yajkWtEVDCLc4jzKehQwuk iN5jgC1vax5jgy6Tr2lK99mzIkjUXptK8zuvBDDfpHbZ/4rn065ILdEuXxL4m8EVjsZC 0tmQ== 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=Fi0pWKvTIysr+rZVwpRfl9u+xx38ztf+vUsMWQHJyBY=; b=PCYFsUiAvocHYr5WzqG+Kk8mpWV/i7vJAfH7XUxiKVExTco9mPdjWqoIpbMtkBVupy I6ljUWsr1+TdPu13iv3GTpAfoqlZZbWuyAHPMJQjdMFSHlfLOZAhmJcvk4dsb1rzz9lg xSXg5nIAey2MFon7n4rfyelVzAWxNLyN/GWDX+LQeMyUnD4GfxJE27v7lKrCK9cw835z lvTwYpMOVGpoS3OE5IzPEsnHR9feK06ZqJJHT3bQnrW177slHTcxhJFaZS5mIHQRs42E /DE+uhMDsQkSCzk2dmVJ3P3t35zdMMc/hFo/B/ddlBmTB9JWab4k+13pbi3Z4Lp3uPMA xmcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=e24GPRU1; 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-58838-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58838-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWCGvTDxWWU09UP4yT8HCsRI6wGibdy/XRbFq7vwSIcByFfINyUxmPAVTeb2JUMEzPfXNUFvU6ODTgHCgqpmHzCYIRlOQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 19-20020ac85713000000b0042c4a985c46si603032qtw.35.2024.02.08.15.29.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:29:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58838-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=e24GPRU1; 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-58838-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58838-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 08AAF1C21C23 for ; Thu, 8 Feb 2024 23:29:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27480612C4; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="e24GPRU1" 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 95F00535A1; Thu, 8 Feb 2024 23:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; cv=none; b=a+mfmy7H8C+yiz748NbgdLxAi9zXQP6bfS+PS5pqmpOfZ7+U8dmh2cyOL8RIfavt6/rxSPCU2iluy2dnfsV05hzBEybSwAlM5FwPfD7tmxaDPJQ6lq5vrTwfSJnja9k8RnZrTY6BLwo4AF0yA2Jl41jA61+jAuYICYRSH1Tdg5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; c=relaxed/simple; bh=httnPJJML5QlmnUl6L9g9SMmpTEhPWJw3rWiUQwkot4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aax8PThlSzFUvNWz9sBajgdpm9gKrPtZKUZHMdnnUx+Fpkr7WI20yJvsLrzIp9A+iIJXFlt0SIHSKP6+y//90ITayJqRLUaebvK5SSeZOoO012qwj5/2IakUe9GR6PSHvobkAuV0jmoafhV7B+2szmDbxaMsBQ8XjkD+Xbic2G8= 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=e24GPRU1; 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 418MlA5J031470; Thu, 8 Feb 2024 23:14:19 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=e24GPRU1V4U6QFgGWVVKhW8vy3TgUPj0vLdR pelgFWziJfpruK8ipMubFs8eHrEgwFQTDUsM4gExPm/+mWBIKFdbxMBpmz0hThsa jH6X4v+0GkZAI4DpgI2fw25n3LyD6iVAnlca7O1owa2AjulBOkGUWC5ZQyRj+mNL k49iHOQ+t8Fb/V25LqxeJEuq2M0GEYz2Iy6sSvKRVhOgJFI+QwGJbWZx42JStH6r +C/OEZRmGox6MkmikYLERxqSiC0mwDj6Q0uDq5j9bIGJ5GnPm7inSPJNQEJNO8Aj VIgxe69+60s8Tpo7tJl6FaFUDQE5TuBIsBqOkZJE8/WHOk2bpA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2aaq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:19 +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 418NEI3o012202 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:18 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:18 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 09/53] xhci: add helper that checks for unhandled events on a event ring Date: Thu, 8 Feb 2024 15:13:22 -0800 Message-ID: <20240208231406.27397-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 2LjOZDT6qoQD_SNop_3nA5mBVBIiiktS X-Proofpoint-GUID: 2LjOZDT6qoQD_SNop_3nA5mBVBIiiktS 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375359046583069 X-GMAIL-MSGID: 1790375359046583069 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 Thu Feb 8 23:13:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515837dyd; Thu, 8 Feb 2024 15:29:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgCjn/Jxg6SeC8DtG3p5OoGom25he3eLQdM6zQj3zktIu4gWLVETZKTlsjm5F/m52q/B9X X-Received: by 2002:ac8:5a01:0:b0:42c:4f4b:8e32 with SMTP id n1-20020ac85a01000000b0042c4f4b8e32mr15945qta.8.1707434989961; Thu, 08 Feb 2024 15:29:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434989; cv=pass; d=google.com; s=arc-20160816; b=jXG+8OeAEzMM91hhI/4h1Okvc8BofbgdGi5cjjVj9LpSFHwAFkaCe/nBFp4U2Slyaz 97nyH4ekrf5KOR9/QE4H5lKEU+62im3pU+igFd31ow5ohRiNX506uc4JjC55Ejrei0Wg cC9mLFRVqGojk1h2sZOPRr1Zc4mbgQV+LHD3l4XatE5EHTWbQ1EXc6w6SZY/CzgnfZWJ jaR33EBASsxWKXuz7tLa167xa4J3swc2FnPJ/1g071XbvpqXtBCAtbtcANjtzEvVgXDI ckH0KodFazS9XOHbi6iD2ikGPnvWXjk/jF39P+d9aHzRPLe6q3PWDCdjIfhcQsqf2UnZ NmkQ== 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=BTz2tU9VekTteZtf8JrmYz+TeyDp6N1lBPC3WrnCceA=; b=MsRJoiFexU9O81/Zl7LRMxktCV4IOclLIw1IF0XOGLij0Eh1/Hto63wKlTpFUW47xH ifxanPW5qT/s2phutL6jGp2bNO7Xo4//E5BHd8BHu31FyT8X67b1QR4Pnn2CcQYY1RBZ 0890iZqV4oP6Au7PD28O0MfxHS/uyRYoUL7QbpARHCsV+7/dxB1FLGRcYSsFoN5AgIh8 w3BYPt4AJqgSSgVnpKpzNxFxnKFvCcEnHDvRfygeO0wCdccV9OUDP/oyO5f9B9ee6JU1 +iI+OAPPGkTWoQprpcWKFbLIxBiHchNper9DmxnYebfHuyInazD/1lMPDL3A4F2eAE1G owgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eRIdNiTm; 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-58833-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58833-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWMXcwYxeOjKtXMcj4XG1Q/GBaccVU8fQtbTzdCEht44xqruBKWhaoMg9iug2yGD/tWVmYqz+8Tfm1uVMSXxdb9LashKQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c14-20020a05622a024e00b0042c4add21d5si566461qtx.652.2024.02.08.15.29.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:29:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58833-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=eRIdNiTm; 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-58833-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58833-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 B99AD1C21397 for ; Thu, 8 Feb 2024 23:29:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0502460EF8; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="eRIdNiTm" 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 3EF345026B; Thu, 8 Feb 2024 23:14:42 +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=1707434086; cv=none; b=Sc5HlLA9deFZ1nclbBQl3AvV6VdXXmCV3yTyFGgaFLAMowohZNnRN2ZbD/PXER4CC7ri5P7CoQMFq//e9uycDhuaZZg8CcwwnOVxSyzdi/CGyFq5SPPKImKPT5YiikJKiWtKMd4Y2D6WdPLP2vvHenSIiKrjpHEC2rUcPJ2SWIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434086; c=relaxed/simple; bh=Jk0LMWaa/SpQYHxNARX1Jnkq4LIW4HOuymWLQdv26ls=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fp913WSRaSY/blxhXeFN35CE7p0SgcXfUFLdKMENTvUcUehq1Vp9TzYwsJEfI78/cWQbqPSR3WGH6C0iMrcIWDEfgAEH9+Igu5ZOEpkbZM6KnUAkHgeCaUnfvq643PV6HMsU3CkdAjogRqc/ahQ0YCBW/Po13xkNXlvouk0XGec= 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=eRIdNiTm; 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 418KFtpA005718; Thu, 8 Feb 2024 23:14:20 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=eRIdNiTmMl6+jbowa4xC8fs7fbsBMAPyjJ2Q 9/+UdM1KNgJ537SBDdDQpxgtuYWWXYFM2wu2Bdm86mg3SuWUv1MmuGER2Xr8GdPM o6sA0O9DhxAaXeP0b88hc7IW9bL+badHvp8z2FCw2jYwvHLUOopBHzoUfPjJKDXd RtKVs7Nn951/fwcNfqtKsSAn0y53Zgp7n2E2fqLFu0e5F+nDZWtwnQW/+pdUiT/t AiFJ5ft2nBhqSLb+AkrSEROcnk7IYDwzr56zXXZlIUiVKKILjnTNWNWe5fTYJFur a6mINJpToY53LJOWzz9emGub5sPsmWFbt9dhggP98Hrg+InJow== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbaj2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:19 +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 418NEIdp005532 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:18 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:18 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 10/53] xhci: Don't check if the event ring is valid before every event TRB Date: Thu, 8 Feb 2024 15:13:23 -0800 Message-ID: <20240208231406.27397-11-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 93zJEfuOBtSwavi2uQlPONvU6kF3CJUY X-Proofpoint-GUID: 93zJEfuOBtSwavi2uQlPONvU6kF3CJUY 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=477 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375352141686055 X-GMAIL-MSGID: 1790375352141686055 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 Thu Feb 8 23:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp526455dyd; Thu, 8 Feb 2024 15:56:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjNEJKbU8Byzgyb33El7ldy9/N/Sb5P6b5UF06MjtpECoebp59VOskLG02+OCA8xdNM72C X-Received: by 2002:a17:903:1108:b0:1d9:bf01:165d with SMTP id n8-20020a170903110800b001d9bf01165dmr1030306plh.10.1707436577052; Thu, 08 Feb 2024 15:56:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436577; cv=pass; d=google.com; s=arc-20160816; b=cXl0RYqRkvPq85vKzwwdw6E5vJ2LLtTQK3mc6wkOMj5Fcq/+e7FbvZscB072Hvyv4X nJUIOIdBFqOnaUC+NhVmbOeDxax7BXo80nBRiKpolKToH26XHvDx5wYSFmAbP5rHQEE1 BkFV9qlHKDU2zMVtyen5UhKQbSSy+AVhvOTLGtJqFqs8pmCiYfpVcYAtuk0buXtoGsFm BpuwfWYr3mD2xBNAhe/dSliqqtdyUMks7ZL4DREMx12VeDwYXVPA5mcf4+IdIDZsH9c3 MxgC+XgHlhBEGHDbVhhrgvI2p2hVY4pWMzaaF1AX5pKVb2pVAUcaqWG0o9zmQHhxJSmq YChg== 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=mvIJ5VjcmhoVUKk+ZplKxHOtZvmCqQFxYqP6TO4vhR0=; b=ZyjCajO/5AEOLPTD7PbWJYFLdxsaJ/LXkJhmXod45X/HeeAhIgcbyEDWAuKx28vOKU Dpp/DaeAnqDGjX2Y62yHPrOEWVX+oI3gfVvFd3G0f0qHuSjcIOqddJldpUJnu3pm/p6a PREH/b0sxLcdyQAjdoqQiI3Dzd8qF9wkxvLwIPt4BxbQL0wVLgIcYrEdFlc9h/D/tIok J23E3JnBSrHqlF9o8Mv+patAg1y+u1GkEqvG5eMa99aT7dRQCbNNcbCFov+/8iDd+E3I NGM9GBVzuIYplH2ABkyczCa/PgPBp8vqVxAMgbFKz/QU7Zw3RPBPAPDJH7f0XE/KVrE4 3uhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RJkMzGjw; 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-58829-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58829-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW3Q07S00/scBQ3GfhJzb/LNLqmJdNWfxT0RviQUSY7Vze/xC4eVtszAzWUvEcYPxVSR4Plnc0Ix6uD2cROpB/rLZLseA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id me5-20020a170902fc4500b001d9e8a8808esi585182plb.579.2024.02.08.15.56.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:56:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58829-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=RJkMzGjw; 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-58829-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58829-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 3F4F0B256D1 for ; Thu, 8 Feb 2024 23:30:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57760612D0; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="RJkMzGjw" 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 BAD6351C3F; Thu, 8 Feb 2024 23:14:40 +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=1707434084; cv=none; b=Ny9cNfdEg9oc9OzTvuqTDx9eEs1dZ2as7/Ou8VXVx7QZPpsbTr3RTDinQHo2YskONhMJEAXjoTfEuP15owYUu8adiClqQ4pkAa7+79UlEIew8KQV1RdUVrF0XRPh7q6NwSoO45FU87cJT7blmqVr/ji6d9eA9mZ9hnfCm/F3b04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434084; c=relaxed/simple; bh=noUq46uIIl4c54Ml8nUqG/zmcTMdZmp/uQzsEWtdfvc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JVilKygTAVuAwfjT26sFXRNC6mlJD4YITgA4YJfzI+9hlmcbUDlWyX35exj6aHPCqpOvxYBqkyf52s4cGD1zDUx+lWCREbZkQJ2jniV+Gh9fCpyZJZBdrMGHZq4b25ZpHf8BCJfo/AgqPK31EQdeKS6I2AjovUqTUcrICcxHQ7I= 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=RJkMzGjw; 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 (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418MJO4H021321; Thu, 8 Feb 2024 23:14:20 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=RJkMzGjwFkBj/rqez8OKgz2SxZRALnqMcvow soxiggxZKe+RQjt13YexYCUTCwGysFMzI22VDi3wRpVnq+2G8GAMaHMHGX/13EOU EqGVXGIfKULg0huUaKuN0A+8K5VrE4EZdiLr8sRdRmCGc1BIr0t6FTCl3TpLHyV0 8yTfDRsrQla+YWW7L96zggFSnuOS0EvlnsuZx3ONvohBcFXY8NUbsWqmD0eDG/jG N2XLiL7c38chzJvNWf3CJTFZdd4TZc5jGMa3ZuVGus4z2R0TshXv2IhlG0Azijbp 1Mg/RxUo+hGeJYX+DD+2hvWlaWuT/GU9h+OILxggnHKnuFjmbA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4h0ukb1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:19 +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 418NEJ9B012210 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:19 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:18 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 11/53] xhci: Decouple handling an event from checking for unhandled events Date: Thu, 8 Feb 2024 15:13:24 -0800 Message-ID: <20240208231406.27397-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Z9RkZonsmHQ_n7Xk2MMhib9GFMFc9VDx X-Proofpoint-GUID: Z9RkZonsmHQ_n7Xk2MMhib9GFMFc9VDx 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=744 priorityscore=1501 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377015989272766 X-GMAIL-MSGID: 1790377015989272766 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 Thu Feb 8 23:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp528726dyd; Thu, 8 Feb 2024 16:01:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcm2tu3D+53ACIoTybZ27tjAkfiFsE1KNAOQxgWEwsXW1J0XbmVM6ekuBqhb7ccXER9IRIvZVuPdC0mJzWO0VNQPXF2w== X-Google-Smtp-Source: AGHT+IF2BHVDDI4OijHZwBngjKHK/thXvIzmJPZpMufcpE6xCLFCP7zelLmTEB5RiZe8xdlDCjKt X-Received: by 2002:a17:902:f545:b0:1d9:abf6:e50a with SMTP id h5-20020a170902f54500b001d9abf6e50amr763570plf.8.1707436904618; Thu, 08 Feb 2024 16:01:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436904; cv=pass; d=google.com; s=arc-20160816; b=gNipbvH5JDitV+0OnBhEZbzNFmimAWqD76YkYJsXC754pnxcFH/5R/kAsgV8DjLbNY zw6Ptu91b/wL0BLgSNwj9E7nHIKFp9nkN5n+W3Fl9bc90uyh9HGK180t4LPQgIO27mSG eDwOSt2ACqSRcvgLXRCncD5VDqBY94KkHeCxYjibXnFY+BGxzDgPxYQIzUJa7Bqisesm j6fpHVGpXeSQi1YaIcIfNOggvIefLnqECun4zTazPrvtg8frvt4Bgb4foX0ZD8CUxuge pKyylsnQWvbdmkeYBVAIzfNQrLv2hpRG6r9tSIQBiiLPeMsBKd/8o4z32Y/Ifwj3xrQY jSQQ== 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=qB7Mleig4jeIpno6EkpUgL9tP+v+Eax6LKyDfee//V4=; b=ypZfifQ12rk9FLjd/sf7tdhq00Z8zBRDutQTf302YZuby4JFKhvuBY9HvLGGkaMFpI a2Eof/5HI/iXx74gTjybuSYqg3A1wmWIjYgXVp/Qy/OwXLoX/vAIH7Wpz7dJmWZG3iNu Zogb92n2yfUGC3AMenWjQSq3ByD7b8PPC9f0Mk+u1t2Zljd7DyVkzGoRA8MaVpMOLgS0 t3lylEINBswemwT/jldNiBZAc1egPz1WjR+s5cmkE6K44XZrd6gJT7DkAvFLFvr7eNBS aDyM/RWfzDllapCCWF5CPaiiorZHG4PkW+LoSR5Y0b+ks0RjG19G40VUwucBnqpuJYGt inVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CLnOpkU4; 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-58858-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58858-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXeJqyPpe166seoFSUx9vIowNgYpnXukRRDuLXZ9yrJZKsnoaf439eZFgpEooF9wF5W+B2htwiPQ3UGKsdYKqrHNsKbfQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u4-20020a17090341c400b001d9c080867dsi604763ple.134.2024.02.08.16.01.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:01:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58858-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=CLnOpkU4; 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-58858-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58858-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 79241B2F083 for ; Thu, 8 Feb 2024 23:35:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3667664CD; Thu, 8 Feb 2024 23:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="CLnOpkU4" 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 B43A257870; Thu, 8 Feb 2024 23:14:51 +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=1707434095; cv=none; b=kbFY9EjPJzntsC1xgJSi0DpJfppMIw52/TPMfDuQgE/TtaxZv2u7l7Re0RTBKQ1++Xzrknf3q/ZFJNNuievO2/O8oX3Ft+ARukEPm/KzxEgVpAV2a3HCtez8RcaBS+4uD6wCsSmP3JkffcFz6YC1wTYTrKDm615mWjG/uQnqSBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; c=relaxed/simple; bh=RtzWV/1LJX88jylynkZkjLYqkeu4eisuZBnouYa2i2E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XpRzYY8TK0h/XrsAvENkZlqhemoxGim+XQ4/SFxzJqA/nurz/dsdUnnSWySyWh5OsTYy6cXmqmKdJIwaoKEzZRASCPUSdGfEdEsytnkRz5vGLh3qW6YvVJkI+ihKex2PbnZZFUrt2CNMg3VvusTryRzhEwGlNwsCjloOey26HJM= 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=CLnOpkU4; 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 418Me8ct021274; Thu, 8 Feb 2024 23:14:20 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=CLnOpkU46QfpL/bsTHrmN8OsPpFRNUYqFo8j PsUinvy5Y6BPsBpL+D5tH9WyZFarqGRGPkENpaEEXRly+OvHmGSiD9gdbGG84Cb0 ZL3kxFIDHaJ7qAgjFsI7UMkEzg/8oxVEzhO6OYl5+MASKkCvtsokKxq91Yq1erUS ixXnEpu58ERaPx5IeYpYBAz3KZBjruwKT1ceGYm+R2dajgweRt96NkeXLXBv54p1 I9QOeNt526PbsT6gOVlIWxyBbWgz3NnYVg2Vzek8cJIflPi5qx1MrKzPPE+iGHUB q7idiZu2crdK9ZmA2fSqgUWOmteqXzwPNERspuv0ZWnsJ28gXQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:20 +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 418NEJrb005536 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:19 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:18 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 12/53] xhci: add helper to stop endpoint and wait for completion Date: Thu, 8 Feb 2024 15:13:25 -0800 Message-ID: <20240208231406.27397-13-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: nhcOCgu189DswD_LlE4ua0vUOLjue7Y5 X-Proofpoint-GUID: nhcOCgu189DswD_LlE4ua0vUOLjue7Y5 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377359992820620 X-GMAIL-MSGID: 1790377359992820620 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 Thu Feb 8 23:13:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517940dyd; Thu, 8 Feb 2024 15:34:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaH5GJgXJ1WRq856nWawaBFmXJj1slK6qqfTSJSS1GxcN0VsUtl7zDUKG5WfE0HrlquBbo X-Received: by 2002:aa7:d9cf:0:b0:55e:f37f:7fc5 with SMTP id v15-20020aa7d9cf000000b0055ef37f7fc5mr53651eds.14.1707435282504; Thu, 08 Feb 2024 15:34:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435282; cv=pass; d=google.com; s=arc-20160816; b=tTqnF/fAEs2mtqMDakkjiGLO+/d6fNOcdq9UZXdITXiL4uIanbNoolrEBchgwRlFFj bkFsQHziBWaiQVjCNqYI85aa7VhfsEgnIEsZnrjrSBb6FG8OuvdRY2Hbv2u8tp3zGmHs VWYL57eWADorio96fIK7cX7pOC8tY7bw1eADR2t/jKlhgrhn/ERC37UAJn+ugo79DfuA t2NV7viem8e2CUETx8BzgCz8hMGNbIeciA1vYXGi4FtmZVd/3ZiVnIcLOlnB8B8vxyZs 0opULMO+bMwJa9jbKx1cmkqNM2IGSBuOlxAV1TYzT9cLj1WjCrQOZI96+J7Wj0g27Qsh WxcQ== 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=TreTDeJed7nsMjN3GCnBrOT5qBakVhTWH9qJ0fDG27g=; b=s/gOrW2y6B0ZoLd15ybTZaKcICDrpBtZimC8PGKgSPM8Jhg3xUJZPA7rbcQUhRmwmq VJp3P6EVpHrBxboNghQ/hfVAfX+rk7vSAgYpz4pEvuNndMFhIJbFePDDktp6TOU8ztiy YWGH/VkDCewx2Znmzq/VfpJu0huf3g4oHbs/tZFerPR59WK4j1q3lhGCBMXplm9QmrFc mzlXcvAdhoxwHmvn9RyRSO2NDJU3Ln0xgvncYt6pjVjUKUG8EgAU33emUwx67vk8qVy7 4bseL9Dxq0FFzDaRIDrIGJ2W7BAicbmU3dylA9gXKliunhddrjODLhHzMP0gaaLtJLMB PDtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QQGMyYKZ; 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-58852-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58852-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVH+8caz/gWoVwt9Tg75KWieN6Cy5Ez5A+1f9GYeSjP68u4aaJMDSgAX55FMvHCTAgvFJ9HaWKbxZzYiBM1YVzP7Em+Bw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a3-20020aa7d743000000b0056117e168basi202049eds.621.2024.02.08.15.34.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58852-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=QQGMyYKZ; 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-58852-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58852-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 BA1DD1F245A3 for ; Thu, 8 Feb 2024 23:34:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D597160891; Thu, 8 Feb 2024 23:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QQGMyYKZ" 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 D89BD55E47; Thu, 8 Feb 2024 23:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434093; cv=none; b=acsLn/lRMv8p0qTrcXJv3ymoqJMVa0yhBrqIGa/oJgcI2x6R9/uzvQjsY2SkQVyYIsP8Dy1M2R0LQhEhj8DtWzNTdmyTJOp2nQ9i6bVoCbutKGBhFs2+J4fxU01jXo942aDRpgBYToKQwAZ3oZKb6WpLFCX1nuuZfgV6VWupgvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434093; c=relaxed/simple; bh=iy+moeOwHnE7dgEZhZINQgamHIdgTcysBEEcZ7EgGr0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ww03eJiHKP4AqjsIq2lWozHt250D2HMLD3DhfAzyI7CpCpTLULPPhe7F6y1qpL9VwEsIsD4stbhkfIbb4LioW8wy+n/BrWSFLH8jfgfYlCPXuK+fVGKM73LkxoCOQH9jUWN4FOJdKlZK3rsbRHUa45ZQDa1nzrJHs0VBv9gSJQU= 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=QQGMyYKZ; 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 418MHjX4008175; Thu, 8 Feb 2024 23:14:20 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=QQGMyYKZQSj7Zxcr4HjbXUGi6coFHJMF0KJR 5cGUEOu7zKpNv5pwwi+k8Pgqpx2eM/ySwRV9qNEyh4KwvBcS+1Lw0NWLhCcS99mR gfeXI6SKOch8ZQ8uAPNgjyaYk8GHyqtFrUX/AgqY/OzwJYCAODvqJzfn9CVxEfgt LnDg6urIFf9XhMlPnwVy9nSMdF6FOqfbZIBkm7thhq28RkJEhPYu9P67w305o8OF 35EXEpGrmw+kwOyHIHEqAHi4/+glsHmyE/5E6PxTACq4ShJqr5aWe/2MEugk0EWp JC2RzVXbu9eFTsqIEoQ+gACc7qtsUefJLcsyP64v00A3bn+hMQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:20 +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 418NEJwq012220 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:19 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:19 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 13/53] usb: host: xhci: Export enable and disable interrupter APIs Date: Thu, 8 Feb 2024 15:13:26 -0800 Message-ID: <20240208231406.27397-14-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: iD9s3Gr8mxmebLAxQYVMbpxS1U9mPmX8 X-Proofpoint-GUID: iD9s3Gr8mxmebLAxQYVMbpxS1U9mPmX8 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=527 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375658979263185 X-GMAIL-MSGID: 1790375658979263185 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 Thu Feb 8 23:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp526082dyd; Thu, 8 Feb 2024 15:55:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUuZg7VRgCWcSGhGpjeqUWM3FErFymD3300jX47z4IcpifVnFaERvQ5hW0r0UE9cqibqJkf/8KUwQRPaOVDbnPQEchkKw== X-Google-Smtp-Source: AGHT+IFSxSMcXT4rGxWqfxUe3v8DFOFWKpvUqvXc7tB4U7mScCNCRC04jMZPSwqEHEDKsJZpOMlD X-Received: by 2002:a17:90b:1d82:b0:296:5c1a:f681 with SMTP id pf2-20020a17090b1d8200b002965c1af681mr440242pjb.5.1707436506901; Thu, 08 Feb 2024 15:55:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436506; cv=pass; d=google.com; s=arc-20160816; b=kCJlCrIAh61GhzSauFJZkzP3sWLptKr/Qv0L6REXF/qNKUowwy930e/gL6wQlvQNk2 stKzejOR13SZtI/8+XlqFGs8yIh/1W1ZTxwtDhI0SMjblHkioj9Se6IGWdVhZPTCgksV xK+o9Bojjj3H8aaqhTMkCmXykYG0A54Ay1KUvRolBhoTk7IgLrqyqruMC5cnfpy5u50P /I64h0/9hrWk9npoUD3/tRVWQB+l25Lt9poMa41yHKxP0EqSToHzamakseI44WI8YJSS kms8zyGlRKEjhI5kiAM8RuY4BYqKvOTGvlbjUUvVofZ5ye5D6NzWrlK7vx+K8GNLCTxZ w8Og== 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=HgBqiG/70YChkBG8xhlsoVblfECXWSo3di5On+x9HHw=; b=YSueTwhTu2c988ealdsVZIX7dXbD7dJDwDKtJm4V8b8LtRk/pVLWgn2iNIiojCPreT /RVcBVx98xRkOUCVxlWa/E054dHlgew2WVdMKZEEeKfXhbRmuOYhslyxth3PEQhXisR8 NgNKKZzwv4QTrt9nuqanRelyCNUPYSxWuc7g8gdaTVh8S6GlfrTGBJJyF7mhEwzfIoYu Yx82xcGElY+ORgopaUe/ev2HJh12EPdRqWVQdoaKUyoKL/wKyD3IDPLFLkXpFOP/BJp5 weu7QniJGZaATYJHBx59n12TzHgSL9ZFJPL19noZ164StZghjkNBTh6ME8DLNVzCkGeb ICRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EVKI0Bra; 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-58825-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58825-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWuTZTwpAStA42gyGR4JemD+zv9x61C2/K6gTXF/z35e97RbD1GbeCONBejcSoDRsxdvf58ae/zrv6C07MY8yw7O91s6w== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lk16-20020a17090b33d000b002931f778063si590161pjb.67.2024.02.08.15.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:55:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58825-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=EVKI0Bra; 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-58825-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58825-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 B1393B2D188 for ; Thu, 8 Feb 2024 23:29:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14A7660DFB; Thu, 8 Feb 2024 23:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="EVKI0Bra" 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 7C53850A8F; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; cv=none; b=eM2eUFrkoW+rwp74cRF8UGS5SNukzGs5NEf1XJBLWuH8/GpkS5556Ug2eaJMraroHWmZkAkYCcWIt1b46B9GoSkxNfCl25a99Z4XC2a1XPs7rjTZ8isQ3saCfDHhENn+WwgUzAXUXygva5DLkSTksaof0JmE0CTEEvyAXF9fQb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; 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=WiobqOVGMp4kUOKEOq1L4lrfYvSyYb8Tz+EOU4RewHySV3KTSziLN1Wrh+LzV+ZNTdaahkQE3YlN5Jy0+MsqmdVrpO25tXNnNmpG8ylPYn80HIaJiab0yNcPj6yeq2l/M9+ae94y89Vf9n4pygzpL5EPH1EdDAldKqRUCXMA8Tg= 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=EVKI0Bra; 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 418K2eGA004633; Thu, 8 Feb 2024 23:14:21 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=EVKI0BrasVNYMX1TKA1W/yRoE93YVVFbSQ3/ nVFcMPi427e/3Vw5F+d+g7SW1HOCAiDTpVZs+6Lcu9RJeT1m4RhTFpl1/+1yfcnF 4NH256cviux1kihofe3dQwnJr2S9tUdjszzosTR13Lu4sCWkXiBZ/AapkMbOX7Am i55bm1a+VAJZbreWYYcrqWXLM8jlp/2d2MqXbammCERCG+vmIv29WnSiHCsS2hb5 YsLgb2LKJQnjj1NreKTk86cGXIVMbIs93302qafVFETsKa84C9f3ywUvPCve2vK2 M4U141nQKFYdpsUQmPgL57dv8i5XhRp9aBEn6uB1PnOk+zVDYw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:20 +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 418NEJsL009175 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:19 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:19 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 14/53] usb: host: xhci: Repurpose event handler for skipping interrupter events Date: Thu, 8 Feb 2024 15:13:27 -0800 Message-ID: <20240208231406.27397-15-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: AC6ddKv74oJRJjEdwF54M0Zcdw4LlBzb X-Proofpoint-GUID: AC6ddKv74oJRJjEdwF54M0Zcdw4LlBzb 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=762 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376942757999700 X-GMAIL-MSGID: 1790376942757999700 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 Thu Feb 8 23:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518097dyd; Thu, 8 Feb 2024 15:35:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWc6gEHomBFBJCMiigvO3PDGZW4J3GwGYNMnX+MGLY4xWmntp9MdhoIZMt4KeXV6Y/4jDlytaU6P1A+AGWUQScSZ932og== X-Google-Smtp-Source: AGHT+IHeA1fV6a1Up2CJVHyc4gLc/rmLwjMS856vHnNizh7T992ClxoAqti4sfDd1pA+yn6KkqjG X-Received: by 2002:a2e:9c82:0:b0:2d0:7b53:9330 with SMTP id x2-20020a2e9c82000000b002d07b539330mr48614lji.14.1707435308043; Thu, 08 Feb 2024 15:35:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435308; cv=pass; d=google.com; s=arc-20160816; b=cSrEQX9tuJagOL9zNYlv08OS2y7cTjYBMPb7Io9Ecxuy8LzmDxp432qirDdP5c6dlO rk7aXO5PJugFRm5Ffst4+ebWkeTJKTZOfk8tzsySG05NpU58gPAoVEZT6sKRSYv7nxtP ZeH6xtp336/K6k2nHUtELgH05z6eFQFNLDngmDBY7YRnW5G8K0TUgNWyVxPXhKiS1oMy d5DIHyCzSoZ4HnriIjDx+2Xue3JWgl+msHEDHOBk+/o02eR6ZqFE6zCFDzv9LtIJwlO4 35zHSqjUOCDGvxqTMNIfbmWwlLSvS61PAKNfv9XuwzgnQtHF1cy1COy7DzulAEpWdHht OmTQ== 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=w8F/tWePn/EzRhFyfZm7Qljv1VxMYxdrW55pZYxx5mI=; b=ykaM64UtABEMkQOMBEAyEI9uekzUCgCO3C+oWp3RiG8XkVKo/AX9zmBvwoIQQVHwle ij5FWBzG+CG5TJaKYO+BXyswa24ponTcHPN4TSUkbg+BRoDLBRDwuzSock4t+d7ko4Aa jIHkltM6QkVAGh7BujJsPhA/4C+VE33EKahCPnjh364lJC3kPzHquHY/uH6ZS/9S9ZGZ 4/zDP1aj1fgyXBkVIyMJoqZJgJ1BAQMDLcRCZCLLD4HAC1xvFIuX0s28NY0hZNap7M8p Z6LWX36sCs3ksvv958AJAzQvsyew3zf0b295k8YtapCmMsrrIuLPr8pMf8AiRVerBfU+ 0EZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Dgv7Fqxh; 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-58855-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWsenwBiYe61JyqsEVvhjknbfRbOfH/o1d53aUoRH1EipNsp/I+gwBERpHpQGLnTq3PUwJ1QEC+wzEYV+7n/DX9DTkG5Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a3-20020aa7d743000000b0056117e168basi202049eds.621.2024.02.08.15.35.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58855-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=Dgv7Fqxh; 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-58855-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58855-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 86CD51F24766 for ; Thu, 8 Feb 2024 23:35:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96EA365BBE; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Dgv7Fqxh" 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 190F056B87; Thu, 8 Feb 2024 23:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; cv=none; b=mhVEkABB6jTAlESxQHW2hFc/txQYpgPOtNHfY0SRbYc7MKvlIRSBErI0dC1ArAGBE1NXGn+I6iiNsXBtEnJu81TwX7/OOq/e9CBNPcm4cVO2NlUysLg1KqTtmX478ySw0QdWzNahO7pQ11/94GcDafy4yWp7pub4xGZRFs4BWsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; c=relaxed/simple; bh=CtxumE9xy8E75NV5EAWv+2S2i06ql2rIZ/FBzOnULFc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=llOzd351yn+fVQSK6dxnn9F3+v+ZyU8wlliCW2IP8tASMz03YRtabyLPBkUT8wR0HrixeKbdwV5i44QDs53mrTjVl2xAFuH2MWEyKsrNHXuvkqKDTKcOMQD+h+rGIYq14TIUbYvPG48EXVgan7wJWzgVK0jbaxEFpIJQToJP5DE= 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=Dgv7Fqxh; 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 418NEJIK030158; Thu, 8 Feb 2024 23:14:21 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=Dgv7FqxhtH9f1RNYfrnZzcKUr8++SWiRRLP8 ms0TXMHN3an6XGgO3sa99LUPTBo2+iFLjTUIvINUnUq8VcKAYNoc/+4ytiHnUZ2I 1iI6FC4xZiLqHbNoi8B2d9Z1+LWn78RR4OBFQ9I7Wj8g4gobGhsQCqWhjfxrgnTB l4o13/ZEyCwlm02EhSJg9WvB8cD0bSHn/8PHSv6HctbEB4K7GFGmcfyYTflBmSus +Stmi9Z+DEov8NTy4bSFP2xZiK4gN+/4dnd7dnCBsPxVU8fdOAZIpKtKjMrIDtm8 autlNtiCK9jkYjz4PAWHWB9OwJnS1dhk8woTibP7gPoxardPGA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbaj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:21 +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 418NEKaT013111 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:20 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:19 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 15/53] xhci: export XHCI IMOD setting helper for interrupters Date: Thu, 8 Feb 2024 15:13:28 -0800 Message-ID: <20240208231406.27397-16-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: oraUR1R5Z0LoZynEoAQRSb_UxzRhPzRj X-Proofpoint-GUID: oraUR1R5Z0LoZynEoAQRSb_UxzRhPzRj 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=642 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375685504246633 X-GMAIL-MSGID: 1790375685504246633 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 Thu Feb 8 23:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518298dyd; Thu, 8 Feb 2024 15:35:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW53tmP3W7Xl5X1vEm9+8LczvLTn0Q6oGaMztdkl8xdRKF5cIleD7n5lUfTQc55dCgNpr1Y3RAXXBuilrKg/e5QjM+vlA== X-Google-Smtp-Source: AGHT+IEZmTZry9S0AM5xIG4NHMv8jSsXpWijJJJpMg/OSYmib28cohob0v5oXBZKHT5SJ4wU7EAT X-Received: by 2002:ac8:584c:0:b0:42c:38c0:1e7a with SMTP id h12-20020ac8584c000000b0042c38c01e7amr14661qth.1.1707435338655; Thu, 08 Feb 2024 15:35:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435338; cv=pass; d=google.com; s=arc-20160816; b=vr7phF8gEuW0EOkRfsi+yUxT2fkVSgVcoO8ae9NAXUZuKGwHyk5khqJ3PF9fjezsFg F36S/BGK9pThLKOUqGF4N13ata6mfgajNvWt7pcUUZgRm8+8691ePGSPnsU9qsvP/5Ft WSdAa43o9go1+hU+lsoes/UINY/DfXCBUBo3EG7OAj4Noaivk3j7XElAILz/1aTjsQWk a0SFFiO39znmXotEVT6o1xic2Wp53Qky0neKuQSl7WSb0YSfHOTzkrPrJDjVFmWCk9e4 efDee5KyK7EymB7S0zt6IVf5V6AirXnjSJ3cX6PtKF6zXCHUJfUzdWjvL45kX1y4PzX/ F99g== 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=S8bMIHajr6Z6hWnR9mOCSab82eUv790SMIy5Whx30Jg=; b=nXbXJ+RjDenSSXgQ8EpsNHOLey/veUX3tI4iAusB8xmzgNWBbpscETFfi0ptFMq7sB BhVgq3oDz71aXmzu1O8FcCy58W8E7gaduQgPFwBJ1nJP0piwH85pM656MqRkWjkocMeQ K7ySqz2R/fDxJKXNqVa363UJXMkhrLCOr0oUE4ZBNul2qr3C2WOKInkh9BkohUk5VOZd lkMaC6pKatuAoWJ3xs4ShzKEhLJsxemeG2/SqpXjBAjBXWmFGRUruElB7ONwkD6v2O6m FB7rTmJeSJ1LY8OhL3XHFqV5Tt/YWVq1q96Suh9ENBruBE8e2rzA6ryqcPLl7sTmCK8r Eipg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lMZC0If0; 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-58844-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58844-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUWfMZp39P/bonLb9/9HM2Ftv8KbVySrVI6HQPAKrWNW8fzxUFWksD4glwIlrNrlFEmuMJhFdXUSMRuCYweJM2YAFw/Dg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c12-20020ac85a8c000000b0042c4ccf6635si615372qtc.340.2024.02.08.15.35.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58844-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=lMZC0If0; 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-58844-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58844-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 0A4441C2153E for ; Thu, 8 Feb 2024 23:35:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C7D2664B8; Thu, 8 Feb 2024 23:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lMZC0If0" 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 705E6524B2; Thu, 8 Feb 2024 23:14:41 +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=1707434090; cv=none; b=NPAISxaq1UEiPX7aagU/XqwqukOud3RJMTDtaO42MsDJ4aNCvUlG91QTWSWGQXudW2XOKRdzAq6tItgJHRywtm4NUjqWD0Y/SBwp5HLpounwjqgsDivUN2Oc3/dxlMSqnGEqTbXoVN9NDCmcxiRj66Gz7U/G581QBDE2+jAua8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; c=relaxed/simple; bh=RIz5asIzQ/wZ+uW2BObO8Z7X28TbO66VJNASNcekf2w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rug2slTZ+xP+pBYulE4eDCzBI5T2QDwrdYLCSnarXCMeabWH9N6E5rvrwlsJMmNHWTLtvZ6oXWcQophAZr/x7ZOYl6za5Z0hBcEFHo8Y60179XytDEb08jWk2F2gcUijzY+m0pvknHOhubnC90Drac4OcZe/Z0S7HoR0TsuV+hM= 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=lMZC0If0; 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 418LkDVr022876; Thu, 8 Feb 2024 23:14:21 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=lMZC0If0ik6iC7fTNm+ia+7gGGSWGMzrMui4 WmxSOGtrS/gGVCEAldQ3T9qpDRt5E0KdaO3J15aBQNTHF05ExbfFWDwPJ2xQHJUq aSqeY6CE/pLd3gRqubGzzPIVQc4vB/pxDJcpjD9S+pkyjBcbagPQEiwt1YmqEDU1 OgBrZTWn5vlrarSIG16WqZkj5PTBf4oMNNLlw6lSC9xpQWlHJlG5j/rb3zLWpvxN xZg/t177k5lfob6SyPYWbPn7g/1GCK1NvxhO1LCMzqKBTVjyGn4kDYkgiaGSWhrY ZL2EkKm6ujKXQ3raWua3acOx27fJ1gKX2qIxvIbQQdSDQEI42w== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:21 +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 418NEKeK009184 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:20 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:20 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 16/53] xhci: sideband: add initial api to register a sideband entity Date: Thu, 8 Feb 2024 15:13:29 -0800 Message-ID: <20240208231406.27397-17-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: mjPPorrAA0bN6u8wu2555S-ADpEiPXPE X-Proofpoint-ORIG-GUID: mjPPorrAA0bN6u8wu2555S-ADpEiPXPE 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375717716807243 X-GMAIL-MSGID: 1790375717716807243 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 Thu Feb 8 23:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516311dyd; Thu, 8 Feb 2024 15:30:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6A+onMQeXWXGtmr6RPlkpvClKZt02H+3wy7lvdkr3T2BiKs9fS7LkIK3oRZ471ikmLFCi X-Received: by 2002:a05:6358:8aa:b0:179:2771:69b with SMTP id m42-20020a05635808aa00b001792771069bmr734110rwj.29.1707435049032; Thu, 08 Feb 2024 15:30:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435048; cv=pass; d=google.com; s=arc-20160816; b=Md6FWb0PrCnwYyUbV5yWBbG9yuJgaOOJybZ86Xlj5ejPV4nOreew7e6HWlL9uDBESv Izj7OG+zEBGHAM0oceubjYvoA3/CayqJ3oK9ozYhHDNby0SqIGvdQKRzCmqMWX9RGSBh g1iMa8Cj+qW4xCFX5t3/PxHh0nR/bQCtQD9EtuEMDNG3/R8rLehp0N1ifVAFwVdExlQe Mvx2BM7gt96Aj/C8S0wANoWN/LVKtFP5BP7XtDqdYtUiEe95qN+grkFGLQPTBBzt+OG1 q+XodAP2r/GG58ukyml31sJyLekTg7vCnjOY+v5CUVTgtZcfGFGT11fRtiFZcUTmeQ1D eqpQ== 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=vckLp/hvliRIHVxn1sAltPVFYjYuuZ9711DpkwZ6lbI=; b=oK+oj2r8F6y4gvOy9Jax+sWSI2jV1dpJVsorxRYNb/ygujFBV9iIyyPyER/7tB9OWs GIeZNlMjTNs8rrQLvJCpYA7BUPOdMx3pSEY490jrUCT/8ovFYtbxba0X5AGh9zSKBi3e Xe/al6PWVPUUDQhg577fhFKL5Q0CMkAx6OJvxRoxJH65ecbjUH1ODwQypDaaXOXtUISb 0qhEx1EwIeYdVRmcFzH10YffkaLuE68yRcqlWFXqKXAdo0td2PVw7RAqahyYwGgH5urP aM0gryBO+pFC7rTBj6W4BiYVBpWTVZSgVjkUMvd1cas07fDrn7nEdJjlHjBHg3WEWJyR P1AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=FTjnsN7f; 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-58825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58825-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW8hxszJU3sgMhkbGkl6nkyKI+XVFPTwGtkFB3KLkJSHhZP1KeAnb+EeD/LCH7lS3RUKc669datO3q5he718W0qVOVbdw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h189-20020a6383c6000000b005dc352a563csi599397pge.348.2024.02.08.15.30.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58825-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=FTjnsN7f; 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-58825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58825-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 B1E9928222E for ; Thu, 8 Feb 2024 23:29:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06D5560DF0; Thu, 8 Feb 2024 23:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FTjnsN7f" 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 CFD0C50A64; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; cv=none; b=o/GRnR69Ni/gsgOmqiBKBfQVhn8g+lGaEHa0HDracfLKdkVmm5xN99DvcRFUx/MHGsMAZHWFyvm2k0VMgZWNRpp/sswHRKcmpi1EUc2BnuwuOGRPOc6e/wNHRbbQDSvDbcdz/Ie8LgdPrZ0eK6vWILhBzLXc0uAeCP6MTgt2mps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=SI/xXqTaKb918srbROgcUJ5EMq0uUfJ689ErJLs6vMk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AHke/d2EWjvjzXu5cmuWFSnEIeM17N+K6u7iRVYkP8+ZC0l26X3aDqEOQb6sXySCZiFoLXrVpR7w/GLZfjPhrAbJXBbJpEW59kfhfwSo2SHk7H3Dlnu6yPZ8jIhaZQBdxFx2aoHoo7WpHldTuu8FQEjfEaQ7uFyIZgJr6yYW/K0= 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=FTjnsN7f; 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 418NEMq7019885; Thu, 8 Feb 2024 23:14:22 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=FTjnsN7fdVxAc2UvYiKmD7fm7FQr8NGOD5oG hylWH/q5ztdYWV8QEYQDwtQT4b2FDgKSFbl7k3VjeoMq0/zmueXyAGq4n5u+PLPh tzLFBZftaxflalTmf6LOk+ormn9pJSykakdjhC/mwJVG8xDlBQh3GQoLtKSPS/c7 vLXmo9Xj+G27ySI4NjYgG63iNECeqvF9Ng3kkO0wd4O7y9QyBcbHt3NEJsMazCI7 j9eZwsf4qvLXNmtpT54g6bVPXSAMUJM4ZaaT9PXWVWXsRC3hmTkK0RbTVQUggwKw dqfE83RXKDmy78hEKncHWD3az8clMAWuRd29aK8kwEaX2MmROQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:21 +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 418NEKeM009184 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:20 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:20 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 17/53] usb: host: xhci-sideband: Expose a sideband interrupter enable API Date: Thu, 8 Feb 2024 15:13:30 -0800 Message-ID: <20240208231406.27397-18-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: UMRFRDIAwbd-beul10c12h01cINUObdh X-Proofpoint-GUID: UMRFRDIAwbd-beul10c12h01cINUObdh 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=864 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375414195742928 X-GMAIL-MSGID: 1790375414195742928 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 Thu Feb 8 23:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514725dyd; Thu, 8 Feb 2024 15:26:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IELIpVr6NOmDjpdsYpkk7TANsER4MBDOWQHildebkTfaHmegnkeoQzMWD+6JgoucGmlqSfP X-Received: by 2002:a67:f655:0:b0:46d:295d:1d9c with SMTP id u21-20020a67f655000000b0046d295d1d9cmr825340vso.21.1707434809446; Thu, 08 Feb 2024 15:26:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434809; cv=pass; d=google.com; s=arc-20160816; b=Cy39PXhX0iHt87pmwF0mAn3CjfOtKyN7HLc9aNezcAkBKw8Tq4XjMSThe/ivhsLUJo XCV84EJ/0s7Fyj+/05g6oCcb3hi3u7lvNr3pnKI3M6qfrNfd8NCykA5WI6HnlA9fQ6Dv qm/YnnJ5cshvX+lxrOOdGb+t3rFpZVWNVbPDO7VbOpqYjuzijMDuu7Eq2/p59tDI8EAg R11pngvGNo8IFY+pNbYmXVQFVkvSnrEJi5+F7+MOkmTWnuTPkhJyC1cyUSu5xf/vhVx2 cMV/KU3Jll7HHnN6KPJiqtJPeQdlE6CCybtpAdcB62uAj2JM40zG4sNtufUc1qoWur13 I63Q== 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=iLRo+djuHPM7I01bVksIwSEtLYzajlf6g/RQCVRQKlc=; b=IIrxLP+STFTSfNoIqsVc+9i/zyqJ7AbARWC8YglQ73hVlt99Rkt+DFgjGCMV7mJ/YK tCVY6U1Zbkx/QHT3neaRzQEI2rUw97fukmJpjzLAuD6IJuk0deH/mJrrDQaeD8T9/OKO dZyn2D8nvBO+/myR7vT4u4LnWHNv9o0EhaJ7gxWq85qWPzkbWRzfh4qM4v19CxhbItkO Ie/JoLFar/ogwjVK/Q746HDLtrGtvvIoQqdhbbuEsdQKDHBnfL4AE6YlgzOpAPAYYbds SL1A1PImRYLXhyD7mtGRqMj8IDG0ITo80aJtoOfJ70/L7KEOvLNO92xeZ+WtKAt7DsnN F+4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pntxAkyI; 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-58821-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58821-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWOi6mdZdP9W8mOF7+Lq1Ed5pMc6SiKkHXUxzbXnnpHMsf8ACI1K87oMHZcWQ2AYXRx0biskVktohXtGzWWWwJhPefovg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i6-20020ad45c66000000b00686a0c905e1si650467qvh.463.2024.02.08.15.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58821-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=pntxAkyI; 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-58821-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58821-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 1BDF91C21856 for ; Thu, 8 Feb 2024 23:26:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09AF45FEFC; Thu, 8 Feb 2024 23:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="pntxAkyI" 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 C55C250A62; Thu, 8 Feb 2024 23:14:35 +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=1707434081; cv=none; b=jrZuZxTOe0PTDT4zFJCbz1CVhTRAIR8ZcCN8Hw6+VS887I+w4/2pjUtSMrGguDjQLJDdyWY+uOTTAcRFvG0WQHYhyQBJ21fcKu0dn8CnWHC41cBJhFc887pNELpKu4+hht+Vh9lrMllNHh7D/Xe89ZjEGis6aFl31vxpTzvS3Vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; c=relaxed/simple; bh=tNQSlvKoWgbkhbz1r67WQZ6Cx+rn2Vw4a4260C31m90=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kmlZAUQerXKgiHG7Voe6coVmEEBQkDDPtuUQls4iNsW+1/3n/UGjoDa5mZZOyMKn8JmigzaH6RkRQ6KS1lpdqOxrzdVeJXL3fRHNUKhbuBviJkAeKR5THbagdHpu9X85t5cpcAAlo2gZjhCOvoN64PIi7tg+RN6mp8urs0IlNos= 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=pntxAkyI; 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 418Mgx1X025050; Thu, 8 Feb 2024 23:14:22 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=pntxAkyIfTJdXr7jHNhQVRhxFb2V6RU7S2yn DNbvpgFoqJg8mAYASNHGesN6+L7SYNloC2HBiAWb9Ub+2CvVo76byyISXu+Ou+Au Ca0cfaeq2JxMAS5Dk2ZoiVanDPQUXoKPfupDE0aUTc3BOOWt+Vn1c7FEXVp9eEGi 1pVqf7OGN8p4b5OdkE8rPR68c1NP8X5aaTFE9k3WIS1M6FF0itPqfqeQuQmmYhfQ dzdQSWbkcS5e33bOa5V8Dnf9j8z5GcBzvCqEMCTdqJ0uyCQylPPxlaM+RY6siAUo SQSvV378tokWYXyNwFY/ax/iI8xEkkg5NYyNQ8Rg+tWlggyoTQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:22 +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 418NELfN013120 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:21 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; Thu, 8 Feb 2024 15:14:20 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 18/53] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Thu, 8 Feb 2024 15:13:31 -0800 Message-ID: <20240208231406.27397-19-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: RgYNcKUTZzSWGLuMDtNVg_La_hoM_qt- X-Proofpoint-GUID: RgYNcKUTZzSWGLuMDtNVg_La_hoM_qt- 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=805 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375163091909558 X-GMAIL-MSGID: 1790375163091909558 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 Thu Feb 8 23:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp524908dyd; Thu, 8 Feb 2024 15:52:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtSKiYjN59PDSOdRKS87XApKN1HISFZYRMIo7+eBrK7YITbgLqBseYlxKchVyC9dqrDeNG X-Received: by 2002:a17:90a:de90:b0:296:a43f:66f4 with SMTP id n16-20020a17090ade9000b00296a43f66f4mr811717pjv.39.1707436326809; Thu, 08 Feb 2024 15:52:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436326; cv=pass; d=google.com; s=arc-20160816; b=0kLeCtuTqYbfPe9N7XXIracuwjaK3UMKwrJOq8cwkl6keEgM6wyyRTbWPi26zmqFDz I/8HvVjHlTbXfc7QjyD+sDSaP75iLy6LzsC73ABpQDr2tS+JPv/ZWM+eNFMmwQuR3KJx XLciQunulEc9OxZd8/OOq1gYdDlIua2tf3DUVxQe2joWiYoQ7xyD1sJbI75vluZEMMIL KyhO6NpZzy7zhndmygplzliwpUbmVfUGESFgF1GTJgFnrcskaUFng2R6pECE/HKwAFBL k7MVjXrOOAWvrosSwAjVAGA2lmzmGsjVFfnwj4FQ4g6z0kh0LpehXRt67josuuLWagZW w2bg== 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=ntwO8Gr027G0GaVH8o/GNycewRd7rKMf349Z3AVlLKY=; b=sSSoPXDQh/znQzya4c+j4SkyQ+2QW3/vKj8UvUpk/VVrTMtMHzsp0+GVkKIrGK8jCa /w4V84qZ7hUkLN/lgRyh38balRePD00EsdbrXJQWf8s1VBXg6H3Lgt8L0zp2PaEx7P4m 6lVk4OyS4K7K84jdg0ExUT1T2pngkVOuqN/1l50Z3/nGw7K6nJg+XyEDSQ6G+bxicy0b bAL/yCzKnf2TybQ0J4312QXawFKhqT7ceeDHrMScc6qgW7kxe8vvE29ObYjUglN6lw0Q XIiPC6jFmvBuvJ3pIrhndWOgFhWIdlTm0iD3d0FYAMCi57HmKHkliOFBohvTaFDT2HWS FiHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=b1IIRgRI; 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-58816-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW75DNDNHEsGufwdFYBe4nJDLvg+TFxfqiqpJK1VHE1lVIYTNGRGheKU/Jovr/Bz1Hm2cRW6FlQABDdciqnwUZM2Qnk7Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id sw12-20020a17090b2c8c00b002948d6a7fc6si585427pjb.41.2024.02.08.15.52.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:52:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58816-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=b1IIRgRI; 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-58816-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58816-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 9EA61B2D72F for ; Thu, 8 Feb 2024 23:25:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A9285FB99; Thu, 8 Feb 2024 23:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="b1IIRgRI" 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 1035A50A8C; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=D7u5JoFGlnHHiUAK7lLXG5eP8nBabwQf5HNZl9nDBegcZomSqXx+TP4FS2t62RQxBqU3QoYD78gHRURO6MuZUv/q6InmPFXXXaxbJHBZ6hS9cQuF49fLF5eVN9EU8JGjr3z3fkV8QP1XNVAGrJRqYXpMC5aQetVoyhXz9+eEdnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; 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=Kl/8LQzApYMKmCctTVsUcJoCLva4FMCFVONttOtOj0moixrllmkAII4bCJC1c5nSiWlgtS4Hxq80aCctOqmf99C2aaBc6peZC11UbVhxvp4vkf0eiHXZ4IpC+1z+U9LkgvtaFOSVSKUgk4dQQqpS/uUknNXXOWTYwQOesljnfjo= 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=b1IIRgRI; 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 418NBZW0010685; Thu, 8 Feb 2024 23:14:22 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=b1IIRgRI9Y3rDo9o1v+mJBDCSk/G8qmyyUtK tDmfvywEQJkiypsg9bIyeq5EIMikvgRK+QpSLFhPaAO2T2R9RmeNjCNswYndQj0u 4qYCytNNlUJnu2BHCM/A2iwSaQcxuzFC4AmboH2miMml6h7paXWAeRwPrq1N+Hfi pqrJG5rgJqXrXUIrTmwcPAylsv7z78FNjtJi6MmYEQ8lIRpyMOEa709naLgKH25/ l+rGHFtLAA26pyuMQnHdn4HL0xiKqEm3hdK0V4DUbRzpk6bMKYFRE2ATvUxx0Th/ Hf3UkA8xZCBmmiMorh5hCEE4qw0TD67zUESK0grKphITm16Ciw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:22 +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 418NEL58013127 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:21 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; Thu, 8 Feb 2024 15:14:20 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 19/53] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Date: Thu, 8 Feb 2024 15:13:32 -0800 Message-ID: <20240208231406.27397-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: FvOl3IrFiGh03MGDjQEdJROYhqaxJB-9 X-Proofpoint-ORIG-GUID: FvOl3IrFiGh03MGDjQEdJROYhqaxJB-9 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=504 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376753855301903 X-GMAIL-MSGID: 1790376753855301903 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 Thu Feb 8 23:13: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: 198639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp512942dyd; Thu, 8 Feb 2024 15:22:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVKGRgPMvz3AhqkqPvy/rvuVBktF5qZ5X2ZpT0x84pH6NWVx29I93s0wAYoTvrBZJx4rcwpEH80/RM8iwt8rB2TiZQjkA== X-Google-Smtp-Source: AGHT+IHLpcsvlunikaOJst0PX53fT7EEpbThmQs5Ev4CkRtWBYbe6huJYgE0KaN9HtvNaBWskQ+2 X-Received: by 2002:a05:6870:910e:b0:219:84b8:40d1 with SMTP id o14-20020a056870910e00b0021984b840d1mr1118219oae.20.1707434538277; Thu, 08 Feb 2024 15:22:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434538; cv=pass; d=google.com; s=arc-20160816; b=Q4d2K7DxRI9G7ySr//y0ATZy0GZBj/C/lLkLOYohJb6zRvVQ8RqznRLJurm3mm1wOw 1OzDAyibyIKIa9FOYlOTo5i2S8tvbOvxGw0y7YAAEqM0Um9vTLgBKVJNNp+SLPHKhCKL b8tqja4S/UAD9SAE8Rw5whQ7W/mCV8QdJSmTAkB8M9wQqyBRnKx5e8cPCFfQakGfh3S8 OFSGM/lhbPkE0AnXmeJpF+TkTY2x6BDZqEf1CLJdPnllRmpPSii3WskUVBdPIf6LEcq6 fmfkQoTq+rYFYTmouxHKnBSuLjLh+aHMm+aqCrNeS0gptuu4patJm70Jy47fJBcUNjPX 4kMQ== 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=2bqx3llrxyBywbR7+4V4cUJgHXzQJuIxnmeUW2ujU8E=; fh=QeJIyoO0RcfU7yVpIHOEOjqJxv6dftEMUUEhebDvJTs=; b=Z/OT5b+5GVjeX2A8bmprEq80tyLMNsw915GUWjVa37h9uHPJqUPx3IXUpzL0+JyTPc pyen+NiQ3amQqWB9yZgrOwGkREYkrPb+/JUgFCzCoUhSRDXHd7KGuQolk/UbwFvVUYwc dvNiIXfQTKvaRSJRlCyxuvoyIW4XqwLBNDdBuUqWG/+2Oa2EBHhwnYGmTMvEiM7aj2wN xka2TE9Z2/QKoBa3tKRTX2OnZ2//osb6vREZmgR4LHcmC3m1uW6wcqJ6a8QqgabKeCu6 A0fRawqh3xFGrqm42irQNGEdHVJWy9HDJupJkDJ7mP0mlxJG5vATH05b1YW4PyEfpPzq XGzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=goAqfotj; 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-58810-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCX/ggVMOF2Q+EYH+gGk1iFOeEveZzagnXeZYJsr6Qknuoc8WZct5CS+vAuvGO+mUa70TkVtZ5fVbkw4r+Ru/q00lI0aHw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d22-20020ac85456000000b0042c4c95eec2si487422qtq.785.2024.02.08.15.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:22:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58810-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=goAqfotj; 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-58810-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58810-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 EFFD41C23321 for ; Thu, 8 Feb 2024 23:22:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1F955A110; Thu, 8 Feb 2024 23:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="goAqfotj" 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 164E450A6F; Thu, 8 Feb 2024 23:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; cv=none; b=BLiqaWse2GCm1fD4Dqo2a54gHxW68HOl2ogYuJQw8avSg6ByuO+l/FKIKMnBzsVaICDi766ZkYnHZrB1wlb1ABSVurRxblHemLnB3pIDCtalcMfIGlibajDvZ2HXbKKKu52lNDpm0C3A4VC1FfnMmTJvKltJnGJuxXCdrsuEZNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; c=relaxed/simple; bh=LOoCjFAg4MDdcZUNgYaDr6A9F2zPDaiqwzEE1cf+61o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nhcWXs0UNZrCdmxunKMf05uQbY2E4VtKWMsGuhG28t8UZ0cOSnc3Qjk/joToMmOWat/dNJTGcImk1d2ruGdcNkMEy5lI411kGfUluKJUZaGxDQgW1vnZlriUTo/26wu7CkrM83AyJO7jq5Ws4/KJrj8mNa8nwqmtoSlqB6dpmLQ= 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=goAqfotj; 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 418MTecD000732; Thu, 8 Feb 2024 23:14:22 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=2bqx3llrxyBywbR7+4V4 cUJgHXzQJuIxnmeUW2ujU8E=; b=goAqfotjXYFpc+3WkTM1z5YE4BVUVpVvhHE+ K1xnTAe2A0abgHRBQqOxGpoX87SoQLHxxeoJ0yQaPaemFoC1ApTCqEfKVIXPA/B5 PUCzNNZIaTtQJeDkJQI9HgUeyhW54Sj/jDbdHa4LqCVJpuIwu0Y1yqWMnMz0+5y/ uBlkfBBH7dWjimp9u9UeMQ2JJ6F7ANPcae25vHyNWtxqb5YET9gpm3h4u9M3vNMw 0Gd/2rwfc7P9+kgJbIOMMs16dwzp8A9I2YHJu7HxmPSp2P5JA/JS5xVJyJilBDaE dKBb49CTRZwnVZFbFJb8sClVykRGDXf/gFGZGWUVPcVnsG4HnA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwuju1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:22 +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 418NELo4012237 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:21 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; Thu, 8 Feb 2024 15:14:21 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 20/53] ASoC: Add SOC USB APIs for adding an USB backend Date: Thu, 8 Feb 2024 15:13:33 -0800 Message-ID: <20240208231406.27397-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: j4zOY4KpU8DyCFhla9yVnktLL_CyVzX5 X-Proofpoint-GUID: j4zOY4KpU8DyCFhla9yVnktLL_CyVzX5 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790374878424426340 X-GMAIL-MSGID: 1790374878424426340 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 | 51 +++++++++ sound/soc/Makefile | 2 +- sound/soc/soc-usb.c | 236 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+), 1 deletion(-) 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..c0c6b5abacdf --- /dev/null +++ b/include/sound/soc-usb.h @@ -0,0 +1,51 @@ +/* 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; +}; + +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); +#endif diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 8376fdb217ed..d597cda11abc 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o soc-dai.o soc-component.o +snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-usb.o soc-utils.o soc-dai.o soc-component.o snd-soc-core-objs += soc-pcm.o soc-devres.o soc-ops.o soc-link.o soc-card.o snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o 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 Thu Feb 8 23:13: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: 198653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515747dyd; Thu, 8 Feb 2024 15:29:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV2cSPRexpiHTKcyQH8cZ2vCPY68oqIBokQH1GuMLL5L7qafuksrq70octL2stJ/5wg4S8EQAKaoY+uqXXHNZDr32g5rQ== X-Google-Smtp-Source: AGHT+IFRrgigSree7rMho6ZSqpjAfxjsIvuOCUviO3wwDBHnY6IXT98Mz81nMeO2h5xjsl1+N3mS X-Received: by 2002:a05:620a:a0b:b0:785:8d8a:6722 with SMTP id i11-20020a05620a0a0b00b007858d8a6722mr1237216qka.39.1707434978604; Thu, 08 Feb 2024 15:29:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434978; cv=pass; d=google.com; s=arc-20160816; b=t53L7FJnWLDY72JDfaZUXfsee31/tw9hc3ZrxxuPChkBXLtfyiWS1U2z/g++3hl6qG asZ+5dG+YkBndVYZZ5s5qRD66Ek5ONbxq1GgReFoPUB+D9C+VX/Ur00PaDVARXqT6stf 6AHQZQKq+s5BI330V3RJTnhe/J5aRHCj9/tzATibyNzKr1qKbQrQu2RRk5d/KB0Ovpra E2dmzP2DFUM0GaGlSArcMtJRw3K34PaTZ1FQFcpf5P0bmG21n9NYKtFjZLF1evB8BkQw IPuK92SW+qpsruCTO+tAMMVfmNrAnM1O8GYOam7RmMc36dZHTkLtzfEyOZttWZqQTBqq HYVQ== 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=nxs5x4G7gwW7PF02KvFuAfH0YDk4nvlomAFqZuxEq0c=; b=tRzJkza7Aw27MYGZ+9HuBIoXtzf1SCCqxE8B1GWiXQ5SgG1fhQfGcdI6fKE2q7YCR6 HlZMMCQFef2Q/ePoUGuWdOSeo0ceJnfyAesdMycj3EWKKb6TA+D2vsA2ctmFLdw6TNwO Lrvnw2jHLLCSEbKDYRnL0f2oUwBEtLZgjWKi/0zMON0UItvYNsvFXasCrGX4A6wZUfBY W86pl7XUn/igkhU1QAtqYc5o84UVbD4zORNhYoP8FXotJakVDGtV3SbMmAYAX4j4KsXa sxXlrj9ajGMMg93gTVALUl4V6Fjc1TagL81HnWxLWx7oMGz4ZD3rOnx92EBy6YLNaS1M MFgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lHPMn9TN; 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-58828-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58828-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVpDspUQxe116DrPiVSGF7xYw2gmS4XZDfZJNJju5jbb1xw/HjwfSgaasz+8iPBSw2rMFKOOv4kIHcW7KDluriNtWTp6w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g17-20020ae9e111000000b0078574988770si698125qkm.232.2024.02.08.15.29.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:29:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58828-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=lHPMn9TN; 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-58828-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58828-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 643FC1C2240F for ; Thu, 8 Feb 2024 23:29:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0A9A60DD7; Thu, 8 Feb 2024 23:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lHPMn9TN" 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 BB50E51C40; Thu, 8 Feb 2024 23:14:40 +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=1707434083; cv=none; b=asr4UCcbIaNck+8OMhXBSuGThtWjeu0OyQ4TS+0Al1UGCH6fSu68V/PlbzgzkUkgoQNCmYvx6H6jK8dRYjRjamMcl0fbv8cszX/cPBHB6wDVvr6c6s7UoHE3PKmuWSwf0V8oZeshgVZL6kjIT5SXXIQz16eyBQR4GhJE8TNwvyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434083; c=relaxed/simple; bh=2TQXo2YMYhg/mBJxKuqafaOEZef1g+SCKODQN1pqdkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mzaj3qy4JAJ2fR44jmzGm0umMz9/5NSkPDM3TvYyCu9L47TOq2aNx7sfFoUwxRctDpECvdyOGVNdewi055xc3/k908hI/tnIQWchvWEZB0XdgOHibogYooz6n48kUdqE//EvpAoCBSYxbaPOvNgCB/nhLDkfwNPWJZ8V4Fzut2g= 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=lHPMn9TN; 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 (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418NDXoM003755; Thu, 8 Feb 2024 23:14:22 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=lHPMn9TNYX6CsHDeFyjBgHBBihIQcPNBCoub mui54R7Xb11P1FMWbiMtVVcZ2SiNbGrDDPdgeKT2aj388ZIfQQCKKlxq+QtZHIiB 7CTGtKLMH3UxWfF441bvDz/dAYUe28PLFYuAtcU6JHkE3kli30NMjO/x51NbQz1W qzPHSj6MWIDSWrKxyqcXc7jq38Ik3cdDfotW9yoHj3auaxGhr+Be8oj0/PeYpR7t /Yc+Lfs9FK0HNMvS5zBKXhybLhhFapltlzBGPgkAJDGTbp8p/mCMb/3f2OSFe6Bu xKr4Tz5w2HAHyMytX64vLoCa/pPXD70UsyBYTxGswnifqFQ2mg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4h0ukb1q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:22 +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 418NELx9012242 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:21 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; Thu, 8 Feb 2024 15:14:21 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 21/53] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Date: Thu, 8 Feb 2024 15:13:34 -0800 Message-ID: <20240208231406.27397-22-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 80sBv8ctx3-TrHMgw8JQt60GOUvomXao X-Proofpoint-GUID: 80sBv8ctx3-TrHMgw8JQt60GOUvomXao 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=872 priorityscore=1501 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375340269527466 X-GMAIL-MSGID: 1790375340269527466 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 Thu Feb 8 23:13: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: 198652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515319dyd; Thu, 8 Feb 2024 15:28:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIg2MUZQGtDvKg0H6qjTgXE88ey9wu/rRsFZzmu1CSZlkcmETr9kPhvNsjoILi+FIdMrb7 X-Received: by 2002:a05:6358:98a7:b0:175:f406:a0b7 with SMTP id q39-20020a05635898a700b00175f406a0b7mr638912rwa.16.1707434909697; Thu, 08 Feb 2024 15:28:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434909; cv=pass; d=google.com; s=arc-20160816; b=RCKsh9UszUxNsEqXhh30sYcbrVOgclQAieTvqyTPrZFL6wDFiaEe8NOj6rbRXkyfhN Df5dek7ZpL8FWfoBEFiECdcxX6P2RLZCoQXd9ZRDL2Tpsk+TSyR1CAqQkzA1DPOj3J0K 1Zcmt9ORLGYMlFKulSRUPcHqBXYMU3rwsT5rL+5mpi5GqDxPcQ3NGqOiDpNZTGG8iBxf R4pWXNvg35NnegovZyBcCnizCWQUDvGa52Pw3vgEH+CU7fxXrxjOwT8EbsbapOA9v8+m nqPfUs6Wwt3gkmlbI+7Mswv+1F2dpLhH0A9IPi3JaqXy7UXhxGuKykEzgON/C9FHAehU F6qw== 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=vt3b6i1gmzZDDMGKuF9nJmhhR/20A/+Y3+y53v0lO1Q=; b=UaztNei2pGxXJl0wluPRuS4ESaTJ+Tl3385Bnzb0PV5zdKIpmNMTDvJMkLUix9LDbD hnaG2Xb/R87eWUcUDWjf3V08IVZTYk52EZzVRPe8c+4ZhJj4Kkl5YCvZzv+yEiXjHmCH oD44g7L//yofsLKbjACpU2VojyKW8uaazhftW0cAXFBWXkrPlCkrdNhMBQulSk0WFsua ZJeDK2Vu6hcCvCdbCfCT+4A5EqP7JNdtNo+yVfBU/cq7dBkvGc0WT9umu71Fciu3WceN S5xHU19J2ShkevPK5sbnLUhbYp69bVvZnLX6UtZsatYR/ojNNJxAad4qBrlA2Ucl4LoA JvrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="QB/Wl8bG"; 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-58815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUwNmSRgjU5e81thLEeSB1wCN3Ii0W5T2IWUeq/mMJ3jaJ6MRuHm3IxEyNPXpReOG7KJCu6cdmBBCIpOSMZdb2iN60B8Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b25-20020a656699000000b005ce19c68684si608808pgw.495.2024.02.08.15.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:28:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58815-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="QB/Wl8bG"; 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-58815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58815-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 8CFF528E5F0 for ; Thu, 8 Feb 2024 23:27:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58BE8605A3; Thu, 8 Feb 2024 23:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QB/Wl8bG" 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 6FB1950A80; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=MZbR9gB/wu9m2+THd/VCWJ6CEHU8h7Sy0XKOgbwLclxt6g9ywUtzKOz9aXbWQO8ROqcf0K+QMyZ0DgkB0qsMjNiiMe8VfRGHPXz1PUHr3C4FF7kt0eGte8rSDF7E6fJ7iMX/rYOfCwpzXopasOCL+gfS2tDSfqZSYqMy368O/Gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; c=relaxed/simple; bh=9GImG1uvrSv3ftSZjvPK/IWX3xCwU2NzohBrdUtKIUE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BxELrWSnZ8y5VVdBM52q3krsZgnNDegM4K46w5IMvWI0dcy+Kxz+MIClnGTJ/qC/rfKnLT9pXd4a9HlvG0IneLdvjU7P35QsFZM3Bc1UqT+fAbc5j3mOdNpDoVH2345P1UWu5bCafwZrwzE2I9N0x+k2R8SGT114iIOsNCic4YY= 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=QB/Wl8bG; 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 418N0Dlg022325; Thu, 8 Feb 2024 23:14:23 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=QB/Wl8bGn3SUWbPrcqcqBNN/EbDlBUJbBUdJ zdXjc1EK/Xpk4tGp7ELFBJtZtDTsGWH3eoKS0qg4KDqngXQoyAcpgkxBHGisTh2b kJ/m4/nNna1eDezOwVWjY54VMqWMNiJu9DyGVGO/lj04NGquG+lMc7ghTR5c2qID jDaly7VRvUBxXnbm4q8VnBq6FEZwyoxsOSQIX9p74JD12BXkyeN0uxouWtmPWoFl XyLmb65VSgETdoOt5gn/T5h/RPS8dRSsbI4QLHfNidV4lVVOS5IB9jKGKn1wBoea eK84Xrtq4nyQbsqhX7yOipiSpqt5gyTIzZrO61T4QbujZ9trmQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2aau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:23 +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 418NEMoM022062 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:22 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; Thu, 8 Feb 2024 15:14:21 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 22/53] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Date: Thu, 8 Feb 2024 15:13:35 -0800 Message-ID: <20240208231406.27397-23-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: b2jW0Jw2UE220Oaf6zJWZ6-0wbZKy_p4 X-Proofpoint-GUID: b2jW0Jw2UE220Oaf6zJWZ6-0wbZKy_p4 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375267739229748 X-GMAIL-MSGID: 1790375267739229748 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 Thu Feb 8 23:13: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: 198641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp513967dyd; Thu, 8 Feb 2024 15:24:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzEVRCZcZZYXPKvba/uT6KyDtBIl38y8r4iOyuvjAZif22mz9MUYdz87XF7yJiuOPqx3xV X-Received: by 2002:ac8:7151:0:b0:42c:4260:13b8 with SMTP id h17-20020ac87151000000b0042c426013b8mr1883450qtp.21.1707434694900; Thu, 08 Feb 2024 15:24:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434694; cv=pass; d=google.com; s=arc-20160816; b=Sv3GcTCaTbzEvPW91yXOHaC4t1fRqNwI9pnhODRF/CvOhq7SZx3s+N0uRNuBAgXnVy yXJGkF10kxQKpAiPxuKDhcvgbG7AsQHYwKugJXCn5OjUTFWoSGoBCuKpmNz7m2po3P2a F5ZaVxP+Svx9CJlap2EubiukmMEaKtbPM59FxaEqwN/KVCHC2YIOJc0iWBHtzHZvdzKs zL+EhYMeBRebJ49Sx7iBU5pJTE+6qr7WixJt/hWTCdoBw3ST3Ffb8En2CIwPkiEeSiQV GxyIVYDtsVqJzSjpVGwmDQWCtuSm+mEe+5gw6lDomLwmQiJCviIo0LBjkBy2M6uSktay A5Pw== 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=OxJ3x6Dn/VRQWCEl+s+vAMKmt7TQ8UQeymj4GS9E+TY=; b=Il31i8nVpGPC63Janb18DTUdo0381BAJoWSroDwtC5Q2HLoLsQX0XDZEkfpWSn+XX/ J8iyJL1FDj8AlqZyMcItdSWM1HqvawBGgo/1PJpVAJ9S+yV/0g0n/uKfE4AIw5wy+GZ+ i/ZaXDc2Bv5AXcHXBU1i65hLsihe4OY+7XAiZtd5BgtI7HA+ApdZfaqHzLIMRWNQsq50 FYfY7idyCoADKkzlyOgnMDaTO6cpaLVKzzUL4hbKj8N+ksPQMXIgxWRlLFZVoLOdM9hA qf9Gj1JHc90P2C0T1zXMLcl2z5WVPj3X55BqXxNJBO9JC3wmd6Vo8GczuYXgRsytQfuq HaVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=A9FL+apI; 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-58814-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58814-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXJ1USM06N3exvh/s7nQo5k75XGYRiO8HIfW5cwrWeUJF2JH8Tin1BNO2qyvHosOWiYnY/KRa/IqVK49u4p3qy2kY8QIg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q6-20020a05622a030600b0042aa55b47d4si627148qtw.109.2024.02.08.15.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:24:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58814-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=A9FL+apI; 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-58814-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58814-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 AA91C1C235C2 for ; Thu, 8 Feb 2024 23:24:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BB2D5EE83; Thu, 8 Feb 2024 23:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="A9FL+apI" 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 B0A6450A81; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=MWGU3Ln+3TzMsB7WarghQlsDwskHsV+28C68XB+r9lxNXfuvCuM8d51gbiat+YU68+fyrTvCjoQ8vqKmLNTXyYAFKoVjGg9qNvJfBJfuGrE6ZE7c7t6l56cU2vR8eiqEioO0zs03NjF8PPDRei0gmelEIaTmOHbVUW6naLeiLnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; c=relaxed/simple; bh=5l1ZDxiiOCJBz70DKB8YoEv4oAwewH8W9SdYrKkgC5E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GkUfio2I40SePm1ajgR4M/l2eAM/FB+uCbo+lXar814mr+H4OwL7PuqLlmlJ80eVjL4xtRt+qyoMXl+CJ6WRvDgHzFkgeeczvk7pakcawPyG2Kl1Rh/ZZkFBDzdebazqLoocJMfOsz/yNpfSghJ4rsv2+GrixKS7gU8swMa3QMk= 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=A9FL+apI; 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 418Mj1xw027084; Thu, 8 Feb 2024 23:14:23 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=A9FL+apIJXIwKN1eiBw/0Rjyc2CUT/GwqFuu vssozkQ1ZXBnn7zGlwod8q6D9tMjmSAvwkSd8cwKBH++T8GneoRXFwBFS4f2vNtg FfkzilTurCCxgc5+VJcrnejINVhDImQM+2FqcrhxWzXCwkkDPyvpwEYH4kXCcpyx PCZKISa3fGHxR30T41fQaOHoILmVMWrDoMdgNdmvxHSGKg3HfcOg4nwxAUdAkoac xU7GTNh3XPILjT3ylZOdWkbF8kT9z1xxEfefxD2NvP8dgRSbRF+9yUjnTpn08bfL M22n/tgwmATdYQ2TJjLDMrJZr250lIvKA/WmqJVIX2Z/RAz2ag== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2aav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:23 +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 418NEMLq022066 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:22 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; Thu, 8 Feb 2024 15:14:22 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 23/53] ASoC: qdsp6: q6afe: Increase APR timeout Date: Thu, 8 Feb 2024 15:13:36 -0800 Message-ID: <20240208231406.27397-24-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Kx9sPqqVXk-WvcgyewwCVYxkRnVIUCAG X-Proofpoint-GUID: Kx9sPqqVXk-WvcgyewwCVYxkRnVIUCAG 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=832 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375042742210219 X-GMAIL-MSGID: 1790375042742210219 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 Thu Feb 8 23:13: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: 198664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516738dyd; Thu, 8 Feb 2024 15:31:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNvT9fFJuoMyr0UyDCsJfVrYMzuYJIK/T5TtGuBTwqEcSwacM9mAzt11dSQPu9P5PSS1Oh X-Received: by 2002:aa7:9dc1:0:b0:6e0:535f:b72e with SMTP id g1-20020aa79dc1000000b006e0535fb72emr752711pfq.34.1707435111590; Thu, 08 Feb 2024 15:31:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435111; cv=pass; d=google.com; s=arc-20160816; b=lQByBErvwtEmkype5tHTa0w2Yv1xYcpgbeHW43l3ZPkgsqLjudv1pfO4M+q0OjhrEB 0rB0hlpZRF4vJbMoS9TxhkGk2g5P71NtUpaezoPSCsydSFA4rG3Byd31DT+GZMLhZeL3 iq/FZkDf6hVFl4QIbuRVL3jwTG+9/G2iD2mpeVmBtNtLlvv7mnzgVL7b9iIvvmr+rEYu NVHRWXDjt9TX0vKhGnvUSRZ4InUuUto338031FSzGB9R/Jj7grpG9B6/pUNuBO62P1Bk DyCAEXM2mASgbg4ub/RoauNSKTTg/65EWeTLIbqXuDDtPRQfggBIzs8cXnyuhPXtg5+J fAoQ== 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=vwCRa4F0I2aTGPI/oQqSb5mm36EEU6b/02rSheUVi2s=; b=lu234JXJPp7ytoJf3/CnVcSbBuLEU2Co/KznS3PGFVYfb90KxOQzr3GSHPa6y/82Zw aED4fm3WokbBi/JpUpkibcoGR+k/FI2UjKuEdboR15w9cQhiazwLAM74TOzGbzef07ZS MAGC3lmunHP3Jz6/wgFe3nPLpq4Q9cpM5liEmHtSVwcUW4xc+S75VAWn4koIkKPWUs2b wJIkNyG65fpS1BuJQKON53yOH81yHP4vBFQgJs4NtqYdeodNDXgat01UMa1rbMCnn1YX hGEoz996gAc1YgBc2fwqh+qRpaStCd/YoCK9I2lxAwP3c6eyucLd47aLWSOxexfyJpbv 0P4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=H4ADjBhB; 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-58834-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58834-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWEO2xVl/qntUgdfv1CcdDUQcrMX2bZKYlL5CZAN8eP9ZITckSzcZPppH7sdZqD6HniWwa7OaqJtbH2jPAY9xpe89Otdw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lo20-20020a056a003d1400b006e07230e6ebsi517677pfb.286.2024.02.08.15.31.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:31:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58834-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=H4ADjBhB; 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-58834-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58834-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 3DA65281AE5 for ; Thu, 8 Feb 2024 23:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 603586169A; Thu, 8 Feb 2024 23:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="H4ADjBhB" 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 94BB253800; Thu, 8 Feb 2024 23:14:43 +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=1707434087; cv=none; b=g0wsrg82W3PaGaYcVSweMWNfQwI22oe/hO6ulRojfNlbGNLwLSFPyT6xay1DNrCddscEFdDAJk0D3nYwYgxwVcHLYT3NTf1xBF+4YdEkM4dyUZWXeLpCjWiw81DqV9zT+w+gqSFaZFp8MLHkDUZvXOkWgC2tSj4l2dESBVuksA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434087; c=relaxed/simple; bh=RTqL/6yg3gqL8ZK4i40n0gkIb7t9uu+dvMG3qkam1Gw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MCgeMJX4U9KDQi89N6rRxLmJUjOHUYZS8k5AQWVRdmdbecbiEohQjgM/rHSzpqsYgZ0NJQ5/Go6ePKBK9ApG2lM5wM4wGnBHm6Oo/XhShRhdBgzR4YKk6YawspWl2fVGyxOxjpEsWdOyh516fIzOPi2TlXxVdV/p1gEPt+hvEws= 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=H4ADjBhB; 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 418Mn5gl029828; Thu, 8 Feb 2024 23:14:23 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=H4ADjBhBIznlI1JCP8jI7Axsw64VnIRdooVi MTnyYpvcSCTxTZ9lgDxGqUX46HcF5iaRg1TXJLN618oP6ce8tUow7zj6zOeQsANO oi/vS2u0I/RzwTx2t8fB1gDsvuKSNh+C53vUikY/GRA/W4UdyXpjkXmAUuGYNHqT jN8doXYj7BoDU943i88LxjqM/JPB+XXd4espflhqbWoGhFgZX+S6VtP8dla1kZK7 yAK0vapABAI1J4LaldcKrQlZc19Au3zjv/JRg4jjGfzORE/IXgZbAPubB7PaUbov 7OI0nQANiHlQCK/DeKF9AW8tQonejBaUuhngFd3IXdqcgnYXgg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:23 +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 418NEM9b009219 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:22 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; Thu, 8 Feb 2024 15:14:22 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 24/53] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Thu, 8 Feb 2024 15:13:37 -0800 Message-ID: <20240208231406.27397-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: RURA2Xibtex_GgC-F-AjK-Xl4Aax_GUG X-Proofpoint-ORIG-GUID: RURA2Xibtex_GgC-F-AjK-Xl4Aax_GUG 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375479742909196 X-GMAIL-MSGID: 1790375479742909196 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 Thu Feb 8 23:13: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: 198638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp512655dyd; Thu, 8 Feb 2024 15:21:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzfHlPb8BpbtChHxdY908T3Jg2w0xhyeZb47XNMxv+TLHkdPv9Fdn7QCBO3bDiX32acUOHwcDHD2pAHjJPttbqvk2wYg== X-Google-Smtp-Source: AGHT+IH11pA0jkXcAMEUki4oMn3m4CTaw4WGFBr156eeY8/scr1rGeF/e4x8N8nHvghci0hkGaNN X-Received: by 2002:a05:6a00:92a8:b0:6e0:5e78:7509 with SMTP id jw40-20020a056a0092a800b006e05e787509mr1027822pfb.31.1707434496121; Thu, 08 Feb 2024 15:21:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434496; cv=pass; d=google.com; s=arc-20160816; b=Yw9hyyfHhj8kgcZ97Wjl5WhGRdovT9X9O3Nw3kt7ntyyh/ylwHfn3cG2Qfl83jKZqL fTPAkFFgBgjjAq69Bo1VTr0gwCLAHPZ5F5TYoGGbwixQFMHSMQVVc47YjeDJuTnS/cka VoFbOuRTB8BjSAAbbO9aX+IGZCEowARVbzRY0QPcFScMCXdqIGuVbUzH3Gw0lX7suvOT GEha4CYkbbnFYN0LAn2owonY8Afire817643Y/+N8206gZl2BmpD4lcmwapsb/d32qrs KBy5SEEoC0e0xrmCApaRv9fj9ZPLw/PcfxeEPmjzzY1fvl5801Sq4U2Tl6M4k0p5WHaP RBjw== 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=u+/pmkQpt/5Y+DifftmjUD5pAdbd2XJguD6yel/yQwQ=; b=RDk9q+e5voZFDDe6LeeewIum+e5acfQRzQuXy88kdt0/1RFUOz7hdNH6fJPwE2HtAo Hdi5HtyWo1TIzsLjTbU4C+M4tp3CG2PLQ4IavoBvoJ1xVadZSmrWiarqwHKQNgAaBkh5 1ygYB2plaf+PmVuFtQw0ZlNxjkwhoRvtEW0wexm/GwpNzOqTeiMu7EUq07FcTO6M03V9 q4tfxER45By5hMu0a9HAYcNW3FESpyffHAkeTJLuBhhmXzXn5qWSAzIqYFxEDm2O+S8A WQgt7CRPu76jYrwbMxjJElJqw3b8/ssxpMKmkW+xr7Q9XwXmf58crH3G+sDYlkE4E12x j5iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nmyhFz94; 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-58808-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58808-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWs9EQNyOvYKE+GlYShEoCp/J+lGZ5IffucmdWwKniez46fXAwAyQ9GtBUPjnxZRIDgqM8t0g6u5iYj9LsVNYDKoX/vxg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 75-20020a63014e000000b005d509aa1476si572310pgb.549.2024.02.08.15.21.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:21:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58808-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=nmyhFz94; 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-58808-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58808-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 8595928EC69 for ; Thu, 8 Feb 2024 23:20:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D3E657885; Thu, 8 Feb 2024 23:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="nmyhFz94" 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 17D1250A70; Thu, 8 Feb 2024 23:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; cv=none; b=eMzWc20vP72bogeh7vkTQspRHtDFW3aFjFUe/Z2mw7+kx91PUp7ARo7VGt45OqF7tDuEIYidLO6qqFW3bl24dGP1pvZ77dyyGlhvVaV37xro5wxSSQ+zw1E+EIObIi1Gp9QT16z6utXVVeOvhNa5Rd3CivrgUsqomiX3i9Wv6+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; c=relaxed/simple; bh=NFb5KrutHq3DEtEEDYwpfG5twPMjHvzujusJINVO7hw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VZj/40COk3HGsY7SPh5NK4yNjYd2CDZbNn9oQuhuxbQVN1ti48Ppnuo5TXvlIW+yaktYwQJv+u30j75YjfNp48DTu+EIpdQHm8lPyIrRTHfuGZ7QiU7Z5byanggdIryblK7ygY/jN7zNLrL5U6Wl7j/BMkRPECGNuhNRuYDg3hA= 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=nmyhFz94; 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 418MWXUY003836; Thu, 8 Feb 2024 23:14:24 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=nmyhFz94i58NcMtBUXFTjFvgn+JoddbHFpsq 1HZftJnOtPoWWU7bO5CnwCN8LXMX9FxFr3dzeHIp8KxM3AwnF4AarfXKFDs4aIj0 aF2A/2fMkgy/btH6W45Lk0pewA1cxI2qghchH8N90oekuxcjmDNP08NIXD4gMUJs jhkCCT2o3MXkkxCDUWJK4GnCNwT9HmBBSTv/CD5c2sljVtnrFExxfY5SkWx1143D OVP3VakBVlgWgT/r4dpWng1lw5Zl8KcbQgYBFZNKdepNSS3CIYlFKeXvZSkKGxyO v5r06cBM0/CqJpwX1lyNLjC0JZdMPkhnsjUug6kHG3W3LaBapg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:23 +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 418NEMsw005590 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:23 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; Thu, 8 Feb 2024 15:14:22 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 25/53] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Thu, 8 Feb 2024 15:13:38 -0800 Message-ID: <20240208231406.27397-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: MV9UD4QMEr-0_X4WY57egN_5DuUEBoQP X-Proofpoint-GUID: MV9UD4QMEr-0_X4WY57egN_5DuUEBoQP 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=934 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790374834249768760 X-GMAIL-MSGID: 1790374834249768760 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 Thu Feb 8 23:13: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: 198677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518120dyd; Thu, 8 Feb 2024 15:35:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVeGyWTYwsEptLJ6OLnJnB6+If+dhBHldpyWNVxkCoYbo6hfw1qB9Wm3l07iKapT+y15Ts0Ki5TwEkcba+L9zWz6Tm/vQ== X-Google-Smtp-Source: AGHT+IHqBfS+r/hHc8do3Atj+Gg2q9QSYXqBF7n9voUh+70tmwOqAHwTCLw0L257tjxTrJ7IhfxR X-Received: by 2002:a05:6870:a10a:b0:219:a97a:c9ad with SMTP id m10-20020a056870a10a00b00219a97ac9admr1244768oae.36.1707435311259; Thu, 08 Feb 2024 15:35:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435311; cv=pass; d=google.com; s=arc-20160816; b=YL48lDx0wt6KR0dWnBRuoUFVRUVpxeaMIzPGHb2poqDr5Ny6vtwxx2Ud/HzjOd8238 8rPCHMZ5trU849suWQaduTe8E+t3WsvlDkNnemxdSwb72yzkMnYXePhIw6E/1d2DHjkY FyUJK9odBvDXG47HwLNqIDUgmnLbkWlJHeBpA1R2ahMnKHZ9kUsjVTncYLdwO7YP0g90 4PoNPoukSUSyBYQEvml3YlMemU1ulCsNifyEhMCW+MgZ0VyTLtZDDeGKVocVKj3iNxWx 6mMU0DEsru6jvaeaJ0KHsU9HhQABCHXC8hOM7kl3zGAaTUVgq157yjB9FQJsO3NAnx1l qt/g== 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=4tB1SVovx4gC6mkDAFhBhlhbMcG8S3kJDBQxJmoDHsU=; b=r4EG0yDTWpEYYiW5qKt1PlUE2xbO8whpPv8zowlsmHmT4iIXOp8SZOlxDcEleCimiw wLYU45lDqUKWW2FFmp1dtC12xHR7UcwpfvBoRxoMbhKyKR4eSKNjHW2nwEf+1OiEVdIL UD4WqfRy4O9VeLfyQgN+JrV+HQPkzHHAu3TLU74k0PwueE3nB6HqekEqO9bSaCwYkkj8 sPXkWtPYQ4MppPtRSDi0pdBujbU6cm9xJSx097pjEvfoDvWkZOpvwPvvlqNrw6wqodC1 o/Wrtm9sKjPr52h3RKGM5CZBbJSIz5kBDD27OUfzC6e1WyvcR/xA2XGwNKAXEXQ7QEj0 9w7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=L3n78pcm; 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-58850-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58850-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXoB8Er6cin+Ys/CH/moSQ5zz+UFmsDvcz0nzIQ6trj7p9bsrEUjwc2umVRnOPJkGisiPcpbyMqZ68jK2UnGrOi4kg4Fg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ch9-20020a056a0208c900b005dc4f8a376asi666941pgb.884.2024.02.08.15.35.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58850-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=L3n78pcm; 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-58850-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58850-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 02AF1281100 for ; Thu, 8 Feb 2024 23:35:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE60165BC4; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="L3n78pcm" 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 E1DBE537E5; Thu, 8 Feb 2024 23:14:42 +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=1707434093; cv=none; b=ddlKvzXNusnz0WE9bqfRXwiHf+7g7j0ieVentkOG0dt1EgEveTKHB+skg/fpwCN+tSacJ4sX/jQAS5d5dK+kTrBOICuUd522d672MIn/gL9vQSdzpOeK0MhJOSbZqNZmmbXsENB1Z0poFxPO6t4SlSvTh98+dHkXeZaSA5MOTio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434093; c=relaxed/simple; bh=yy60iKclSo3I7kupLIIW7Eb4iC2/mPynjDbi7rSIXPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GthPIRtNP0otJOzH1KJpQ1OrWEzeOIwdvpVufS21dhiR63y8aW3D/JzJgyBbBCHf0jCNFoZFyEzA6HYuAUrIjswWUVY4Yd46CEx1mdGsfmx2R0wjYMxplaDpC3n68i8NzvHyHN2LFyb28shulQg4hPzMnwYVrLoTcevnAKxWNbs= 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=L3n78pcm; 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 418MWNU3030202; Thu, 8 Feb 2024 23:14:24 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=L3n78pcmE8qwrYpvEEGi6AdCzwlrz0/oApnt P4C+agKIkJFC8TkHvhg3A2XgVOOU6F7ozdc5HdkSMIE8MrGtCLJ2WZ/mVLc78vn6 Mk93i3hdknOE5Yye570GYfs1zZ7h3gfjW+pFyJKrmgcLyfnf4WKcmVBymSDgPRZG rdWb5ES/xApcBEnMAx88aMyiBiEFNrEpxOKiKZL8AVF+4cP/sX0niilGWolLtEWs coHqnPqQjixKIP8FiAl3iZpylTkaKNu8aEh9c0hSDQmO0pur9L7/aes5yO6as4T7 d59y13/KoOPRre30rJxyQey5rxDqUh7e8Y6/XUXUBDdkYVyiCQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:24 +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 418NEN1b013158 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:23 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; Thu, 8 Feb 2024 15:14:22 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 26/53] ALSA: usb-audio: Export USB SND APIs for modules Date: Thu, 8 Feb 2024 15:13:39 -0800 Message-ID: <20240208231406.27397-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: mqwc83T7FKcEuXvUvAHEja6LlEPewGh4 X-Proofpoint-ORIG-GUID: mqwc83T7FKcEuXvUvAHEja6LlEPewGh4 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375688931589218 X-GMAIL-MSGID: 1790375688931589218 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 Thu Feb 8 23:13: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: 198697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp525045dyd; Thu, 8 Feb 2024 15:52:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpCiCAk81yLC04VA4t3pSQKAl93K8Inr4dP07nl9N1sM5wqn3aFNEL2g9mJK6S5ra7q9Pm X-Received: by 2002:a17:90a:3f88:b0:296:833a:b47f with SMTP id m8-20020a17090a3f8800b00296833ab47fmr966981pjc.21.1707436345122; Thu, 08 Feb 2024 15:52:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436345; cv=pass; d=google.com; s=arc-20160816; b=HwCIpEOGkhPKjWwhZJWtBQhrhszmi/MSGdLXQRFlrHJdj+RGQE+GJKVe2yOrNnqT5u fendUkx+g4fqkP2TUizAvD1EA/TBTT4YziC0sIVcZdHuhR8bpHrpYBLwHzN61gtNcHF1 xyvjGX67bHVEUudnOIFlzYTU6iS7CmJ4GXmONMUjrjrKSUQlGfPoKfhOUXRljU0lNtHi eCq8T8bMm30Mt6HaZAsYSU5qclmqQn3QW0iRw+rIp/61NU5fygtIxGONYeTRQ14+nc42 IWQav0kcP6hvPf76M73pWzQiSVyRW7+nly3McIfUtkS4keDy7JKCReQidkof9LFjWb9m c99g== 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=OmWrLqmxCc1gmz0F5H4ayXFYXg4kpYMbtf+6t7yApQ4=; b=fEdJHGijha84hFsap56SiWVplVjXJDqbBPmBKYZlfmJ6yeiN0HyvnSjvCid/9rUKrL aSf29Lc0JGn6NlcGSCpUECXXlJsNkPxJiSYyM7bO1BvqN+zY0H5KI5ot1mJM68D9zAVj czrDSHMbVgsRyEgOuAdysfV/YGVKTm8JpbrFn7UoGF2CPBaq2xYaIJhPWzXs/XHYaK5G w0a18JoEoVXgVlznEByevdb9yfh2Qofm9tX/C8yvpbilweAzy8extZ5BxKjevwPDu/9k 0229+kR9WAtkZs+wXxiOkbfcwxDvHKH9KDiLVxZxK/m/BWxyQaAtPgyb3xHlSC2UzDh6 EA1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IqSGZ33a; 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-58813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58813-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU2qq2z1BOyzDNmFuIKRM6Oppk7wMX2tY4NeN/yvrP4Yf6lnWKtxhu/SaVrggljiMUecjhz/8pofQ8IedmVjA45VF6RvQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lk16-20020a17090b33d000b002931f778063si590161pjb.67.2024.02.08.15.52.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:52:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58813-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=IqSGZ33a; 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-58813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58813-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 6FD23B2D020 for ; Thu, 8 Feb 2024 23:25:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 561665F552; Thu, 8 Feb 2024 23:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IqSGZ33a" 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 01C6050A88; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; cv=none; b=KJ1uz78cvDdfkbnU6Rb6ye9t992JjVXMU27pQ1nhX/1ELm5Dx+w+AYb/7w44DW5KRoEdeu6tJHRVLge8USVMhgUw2CRhxV9daQjjFoIzPDkaT8EaaiNE/2SMCNC5PECksAiOG3bxnWhLmi1tyDkoldD8CaGiu8a8hhnN3qN7TsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434080; c=relaxed/simple; bh=e35zs7ZNspt8pL25lL7WgCnt43ssCmNv3V8Typ76tw4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ag/zLssiBc9NDXHN/tcgYBol9fvn/HQhqOVku2L6ngdrceYtTjjSjf91tXJ+vSdNlCODPhjTA8s4EsYoadBmWQupUg6QfU1agH2pJHbGkk8KveZEIN+ou6pGEr+sNo1GnjKyUqM7uQzd6EqyToDgO+n87pb4RREA6XnFQni5G4s= 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=IqSGZ33a; 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 418JMJJ3024949; Thu, 8 Feb 2024 23:14:24 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=IqSGZ33a0/mWGgAaiW0g3yzj74WbhCWnEyT7 bNpBs+K36ieh2WuyqySsKLGkh+vKwWa0JCqTPG4UAFZmTS0WgAtiny/cDqkix0YA 74q7Okd1nKBaZ0vBSVkKiOMbX6VFhFhZ91kGwCkF9o6xQQw6H4JpJOXtlb3KNU1g 52dHa0b7ttI8kQUjdYEQ1O9FMoLPdDXm/I8DUXx0rTcBCQtk36y1AdbgMeY3vIHG tAPGJ9V0/S4DmzwU1laRdrQq4AaGZXRGmRLNu5iiltk3n5htTQz5L8aC6maWCoA8 QLa3HoOlblKwnbAFN89bBZOzsOPWxOi7xAPQZEjIbtuAezAfMQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbaj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:24 +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 418NENdI012256 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:23 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; Thu, 8 Feb 2024 15:14:23 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 27/53] ALSA: usb-audio: Save UAC sample size information Date: Thu, 8 Feb 2024 15:13:40 -0800 Message-ID: <20240208231406.27397-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: lBsbiqdlLJVPpWaN2BYOe6MyqWBwxgPP X-Proofpoint-GUID: lBsbiqdlLJVPpWaN2BYOe6MyqWBwxgPP 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376773173855672 X-GMAIL-MSGID: 1790376773173855672 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 Thu Feb 8 23:13: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: 198643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514334dyd; Thu, 8 Feb 2024 15:25:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0MDVcnWYF7zVFYJslOhi6MVvf+eh9DoEH5z3KQwufNXCEJJexHSA83P4kSgmk2bKCOGqR X-Received: by 2002:a17:907:7676:b0:a38:1f86:9451 with SMTP id kk22-20020a170907767600b00a381f869451mr504262ejc.30.1707434749426; Thu, 08 Feb 2024 15:25:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434749; cv=pass; d=google.com; s=arc-20160816; b=q2bU/3Xzay6Qt8qJjjIWM8IIqKPUs8wxqUZPdA+x+5yIhYxK2t0etiLjtA/iJS4J4B /ea3w0gsSFiQERae2Co5eUukuYKieZqN/sCXBdYGYioSXAWXFzMg9Y5PFTHaa4m4UdFM GLtAIvrSSoD0qv20DESRrQ0XU/ampaISHezeG0ItPQ9780Jc/uu5/KnFC1H0pAiyASbn QTwHsm/qKqv9TE7KpLYIEo+Xsk5+WwY1Rnuj6FWYcKx8kFqnSutjsJXKgSNlNSOd0n5q oqHleUb4NmaEq/qIacrv9UVKZWHaEUMvjWh1RoFP/iOZ2I6VV7/bLGHdwxYw7FXjp/8u RZwQ== 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=x+cSdIEQuRhzG7DnLLjR6hsKAicKMw4+otbcsSdu12A=; b=fBJUt9Iv3+eam0M3w00MMabTxybwLvKpulHAjNCNXkYLZRCu2lTtQQa9R+/pBuSC8C ZG19qbYcGJY4VlW4JXnO/iECUue3ypHnlWERbfNVeSGTN7DPQ02xJlbMIjEDvlfbhEGU 6gM2EpzFBPRgRxoR1Q7OnLahYz+k/iqcsjQ1Zw7ltmZvQlXQ8bUYJdgxyYZGMthcO6WH YQ/kq3KEKS4zZViU0mKHJ/dBvHQAiaGpOBNoFzSxv2niqY5NhKT6ApOXtTauVw19e702 JosfWpwDSIOgZgPzDbrxgLDEQUmT4PrqL3Op/K8bkFiTyu8Ngpo7i2Mj/f8jG/YW1HSB 6tmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=PFP+Tkzu; 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-58820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58820-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXy5HYtKpxbLgNomWRyZ1MsSp4Rshdwaycn8CRuW+iCB0xzFFhhzZK6/eROBrkr3LsatTilPZpON5IF1T6Gc73Y/podTw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lc22-20020a170906dff600b00a3852590962si152855ejc.655.2024.02.08.15.25.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:25:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58820-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=PFP+Tkzu; 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-58820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58820-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 D61791F219DE for ; Thu, 8 Feb 2024 23:25:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32D535FBB1; Thu, 8 Feb 2024 23:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="PFP+Tkzu" 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 D563650A87; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; cv=none; b=U8IgOOySWgAisVknGiKv9ZTet+FymUbTUMDRyWlYlzgjv2pV6qpGF66gL/iPUDas8eVFvp5nFh2SXOFMUaraZy32AjfbtTEVgP0UP4gZjxLWQYRAfI3auNYCNf5xWUUdYN2XTWPTbxT5o9TIrIJhL3GxdvK1myQHTQ85bjXlcUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; c=relaxed/simple; bh=/yIRGDVuWTwN01jjLu9D99BsT38c9Fll4aPsKtVd2WA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ipe7Wkm7t5ckAMhTpaTuRz01abHNpzxZcJfpmUI7k/KMrOWdtN+CljTQwXEreML5OE6A094EgosUiRMQ/oSMAafe7ys3bVrRLxsY8wIxVaX4deAVxhQgDJMVYJoAb+KKlqQRT/jF3JNUrUHsoGMVX7RNqYkwoWfB16PWYQHtKsw= 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=PFP+Tkzu; 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 418MX69C006565; Thu, 8 Feb 2024 23:14:25 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=PFP+Tkzu6Ic+PNGn7f8cqqxIlG4j82O8Qi7S bIg6UHS4yRMT7gzL3M4+hZ96WR6moTrpDxS294oO4hFPNsP8CIgZIb812f6pScI3 VA9zGk4VR7dwe4daWFkcztS/dE7Qb/oNnamdiJS/vLUVupFhHpjb+gHS7Z4XxIK5 k/toL5TzQUux5qXzdMevWXk9W6DBqedvfliIz+GNMyojo2en/tbgmm65NligvK6Y GHc0O1kB7UPGEnZtZIG+nsdVYeCWsgxwKRW/rscJdaHtwWkMDHEBs8bwegzZbNRO xmzQELdF9DS2Al0Vc6ZS/gqDGug+PG3m2KoKknnlTI3HEitz7w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwuju3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:24 +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 418NENcu013164 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:23 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; Thu, 8 Feb 2024 15:14:23 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 28/53] usb: dwc3: Specify maximum number of XHCI interrupters Date: Thu, 8 Feb 2024 15:13:41 -0800 Message-ID: <20240208231406.27397-29-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: fZjWp2rJ0_xxJDs5NbhYeGQX5yMlGWmQ X-Proofpoint-GUID: fZjWp2rJ0_xxJDs5NbhYeGQX5yMlGWmQ 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=811 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375099406815206 X-GMAIL-MSGID: 1790375099406815206 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 Thu Feb 8 23:13: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: 198692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp521785dyd; Thu, 8 Feb 2024 15:44:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpqH9nL/1ZHCXm8//1PQcmGRiLaT8c/oIrgfaDrpuhuQ+IvNCjxK8wA8lX/yyWOXQrKCH8 X-Received: by 2002:a17:90a:fa02:b0:295:cfb4:9d4c with SMTP id cm2-20020a17090afa0200b00295cfb49d4cmr729897pjb.33.1707435850341; Thu, 08 Feb 2024 15:44:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435850; cv=pass; d=google.com; s=arc-20160816; b=hbBEDqTD+NchU/GI2FgS3bPVceZAFQmMIi4fX7lZLQeJ5koO2BIgLppWNeZS7wv5wn P1PgO9715FFRFIs0AD9C6mDRzPAx+Y5xWtdDjVcJevz9L47viYL7SGClhwjMb0sZCuF7 9r/aJgpwPK/BdZnMkkDb9efhNYRe7LsO6eD1nj7Tsb6xJ3N6wvhAMIGZlUsuQjev+L36 Y7PeLbaWIR37Rtf1LaCqJFV/A8rVVLplfUkBrQup15VqHM7KrqirRCOp/VUIk+TrJ8us VBfkx5YJgxNH9cfoEEEuyeF2rTEEiF9l0xmReHt9HsemZTUd5ZJiZmyFvIhfY/UCo/xy 6kCg== 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=SfFk3tDxXfHKi5D8VA5HxsObXDyJPeusvwYcvTMEvK8=; b=CiewVm8cclf88VfmvRV4oO6vqdeVWBBITUiX9CfOie1axH7dUZOkc7VlDqINffShLX GjdjHeVZIzO1SeRMyjvBQvMpxJdOci1o7ceM+VssBTxR1MLjKeskZHoiLYoJ+lzJ0vnk eBh4M5QuBKNv6MpQxEjVhHrV5AZYFLDr3UDp29kusW1AaVqGrSFrVku7rMz+wAeCJH2K CrugNw9EicKQ6dqBp8CXPimwi1BEmr/8fXov9zRofuiFZFBepUsLUe8CDkaD2dMk8Gar iAor0tFDYXShyZQWHHKLfKzPVBi3Bq49f9xflDRTmNsDEio0+gW/47+3LSfrDz3tFESi rBAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QZIR5xtD; 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-58809-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58809-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUG82vdzblU66sXP8be05NvCeblVuS7Ew3NxxtprgOCFbAIMfa+eJVf3xkawKJT5prlQKIUoO6A5cuatzY/nN2rayvLUw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ls4-20020a17090b350400b00296eec3b8c3si606637pjb.28.2024.02.08.15.44.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58809-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=QZIR5xtD; 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-58809-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58809-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 53F76B2B207 for ; Thu, 8 Feb 2024 23:21:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D9E659148; Thu, 8 Feb 2024 23:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QZIR5xtD" 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 7DDF150A65; Thu, 8 Feb 2024 23:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; cv=none; b=nDen1RNqzEmFUrNLsok23tTj44KiO6FfvYD+MQB09dyZXoeQ9WSZozyOnIF1eYP+siyl/ao04Smxm6fQjBZdyZAtiQvLRiRBYN5w65LQl7GngE/+arK0p6HVr47UqvUOPuHEKWUrn8TKQhqMiu4exhE1bBnpenPUkTDWzsjnuYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; c=relaxed/simple; bh=ymj30Zx1dbYTRAyB5Kax/JPfqIskBJp3/VM40Po124I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=acAR13fzu9P02AAIcCBOWoMxLlJ9u25otaZ+LTx7rn/jt26ECi3x77feFy6TMRPpcjgFPHeuRiMx6tPAupDrs6mMGrc3FJWa8Q76aGi8REJ+CGcmUQ7erMyoy5+t31l/eH2erlZZPglS3dt1QzkvtS+nWUYVRLDpQJfTp/mGeXI= 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=QZIR5xtD; 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 418Mw9fE021788; Thu, 8 Feb 2024 23:14:25 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=QZIR5xtD0syiSVFu69qh1CVR/iTO3yBbyFqh QwqZvCY0rj7GSlqnK/qU6Ame6ABJMPB58gt4ptIr7/tKxtz4cIqcylZg/T6+I4wj EkNzY33oa0YnJqV5xHUWJ6LQ4cDhj5C+in0mn8p2M82iVaeVaTbVoMiwMb/7m7SM FGAIBkc1HN9JSZHPE0/nnShADa8elq8hW6OOZ5AXxY/KV0F2CI6uIlhH45QZebSm eO/ODPr7EApAvBZ4W7KYwl8zq5Rpq38MaZHnhrBZoAwctPVmZ8C9ray8cb+cP4pU hgObmnRzvh3QUGmBE9R5t7Wsnopg+0QSX7tORyjOUu1dOokHAQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs0b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:25 +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 418NEOLg012262 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:24 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; Thu, 8 Feb 2024 15:14:23 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 29/53] usb: host: xhci-plat: Set XHCI max interrupters if property is present Date: Thu, 8 Feb 2024 15:13:42 -0800 Message-ID: <20240208231406.27397-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: jh-uhT39Iz6jVBcHqtuzsAMOKlp-QDlK X-Proofpoint-GUID: jh-uhT39Iz6jVBcHqtuzsAMOKlp-QDlK 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376254523864899 X-GMAIL-MSGID: 1790376254523864899 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 Thu Feb 8 23:13: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: 198683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518510dyd; Thu, 8 Feb 2024 15:36:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUeHen3/P1eooebLvY5as0k/n78Ll8x8lHrWIEMWS2J0plthQeV07ekS+v7A4UB+tKOtHa3VuFZhg6xjcpZZ0aU8CP1nA== X-Google-Smtp-Source: AGHT+IFcCa9g37TKjAmukjCR4heqsS+uhzSq4wQ9jS3sklaJH5FkHHOPgD4oN3MShSuOzND+ES2o X-Received: by 2002:a1f:dd44:0:b0:4bd:7da1:a2ea with SMTP id u65-20020a1fdd44000000b004bd7da1a2eamr82205vkg.14.1707435370480; Thu, 08 Feb 2024 15:36:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435370; cv=pass; d=google.com; s=arc-20160816; b=GcGczsmbqdc1WEreSDotn/jFTJnSZp/AzKNL5Y1OxY8lCrp7YOp+p0UKwhBCawPkIL em/B1/qhJ7I2NU91oVQp76nP1O2kXDpWOCmqnMNQwp/a1K4zXMNO+r7ipj9kHSX72oI5 SoQdciMm6vOkPt8fqFtWrBIPBgZfAj90UQyThIK3nyayu807i16Bsrp6EhhsVum3Y0GE +mhEWKCeicJLVQPnzyEZwvYHBw1Ce4MONB/NJ5HPkhHCwxMEWhnwAgY0B2gye1X4/ncf h/FJ4qjyYs8gC13xOJU43zzyr671N+NwRsTjkgov2QaoZHYvjEMATcm3vo4h/ksK4z6E WymA== 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=yjKVm2kTkPUY0O8Z+B/dUnJ2wDpXr0PIc72TCL70gyY=; fh=lZSPKwEH8WiChJ5YLx5RXlHTgspQlde6qVV5rp3yXK8=; b=voL+EG1LmcWN31ustOmu6b830668Pfter6lJsIFG3VyKOYaOpcnfM4DlFAS814QQ1K I9y20iwKpdWtgxNJtWBRnsu82llh1p0XvYc7Umz/a9gX72vCIS1Iw2KeQpaxugvlA154 4kQYBqzDbW17Lp3T5SPgNdgFbqMUTf9qoYiUlq3VkkQCzih8y5taioe9H+MeyOhO+AqB 21ybPalANmvZAUOCMY6yejPr8J8d+P6y/BvaYIn5y/ahQmxqrP+BzZZvjgEAyucArBzL WwHG7wQxU0D/VlFUaJkhJzrn0irv/wAXfqwyJGxR+bySC+h5tBTAv8CdyZQmMYnV8g7I uy/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=G8ouxzha; 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-58848-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58848-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV0s+UZwS9a17h9HXNpAwKhRwFIbCD8snuy1ViCabrok1eTMC8VYe0761P0d1/mjxj5G01D9b0tEG7UqtaLe3eh+okdsA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jz14-20020a0562140e6e00b0068cab7f4d3bsi644787qvb.181.2024.02.08.15.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:36:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58848-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=G8ouxzha; 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-58848-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58848-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 347081C2153E for ; Thu, 8 Feb 2024 23:36:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41F7F692F9; Thu, 8 Feb 2024 23:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="G8ouxzha" 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 2E24F535D9; Thu, 8 Feb 2024 23:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=NMK/97YYKA0NcjpDjT6+Ut5H3iJoby/Yfrg7ddZRrgVhMEFK1p5/8WHwmwdj1vxiSTzEJmVHsR/Jy/xdvBhbKmwMHn+Ro1dT6hfJN8naz3qWXNxQeBLnzmdNswEykuhNBasfBegZKfdAb52var3Dhr5SDYVnVLvO3rHaTBQU+jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=rAH9lQXdt+xoba424n6HNzz7OQlMhiOMAWV3bB3Ppt8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pYxjnj1msxtM9rfrSWXtKkxs5od7VX3I/yhBdOBbDw0oucIf+UiYQGxFk0nP37LUjEbPjDWkloi52xIPusFuXgm9HxvzfZ+fiUlrGmmGauCo3U7i1U513ckBSwNSrqOVZh/vcry/TQfUv3vk9Z05QXPZIVnOxpeFTFPrbrDbM+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=G8ouxzha; 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 418LxqxJ015804; Thu, 8 Feb 2024 23:14:25 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=yjKVm2kTkPUY0O8Z+B/d UnJ2wDpXr0PIc72TCL70gyY=; b=G8ouxzha6WW0DQH6y+xN/TPDM0DtEcxESnmT aD7E6tiknsPiXWTamRbw1czuJlE7l87fWwb1I5a7EhF2m3uTL5yXwat9yPSdfc4G UiBbQqQk2JhZAhRR4HM3iMRuYy5sAVak3QlNB33NBAjqmD+c52/ewc5seUYRa2YF k/Ml0JMYgdUJZie4HjCgogM4mzc6LC9dBM1l+vKS83EnzGg8SkxBOOxXoKgAQJz8 DZCQXtKe+HjbaqH3dpVNmdnERbQB3+EkZkNvjVA+4aQ2pwUFiDgfs5yztLPnwDq2 XzHMud6GL8wMA1apUWV/7+C8wQ310y2p7wNPvPmm3n/V9kCHvQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4stxj8rs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:25 +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 418NEOnH012265 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:24 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; Thu, 8 Feb 2024 15:14:23 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 30/53] ALSA: usb-audio: qcom: Add USB QMI definitions Date: Thu, 8 Feb 2024 15:13:43 -0800 Message-ID: <20240208231406.27397-31-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: dr_DUSOhsa3T5QgDi4nGRxp3rCSTCA1p X-Proofpoint-ORIG-GUID: dr_DUSOhsa3T5QgDi4nGRxp3rCSTCA1p 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 impostorscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375751044435369 X-GMAIL-MSGID: 1790375751044435369 The Qualcomm USB audio offload driver utilizes the QMI protocol to communicate with the audio DSP. Add the necessary QMI header and field definitions, so the QMI interface driver is able to route the QMI packet received to the USB audio offload driver. Signed-off-by: Wesley Cheng --- sound/usb/qcom/usb_audio_qmi_v01.c | 892 +++++++++++++++++++++++++++++ sound/usb/qcom/usb_audio_qmi_v01.h | 162 ++++++ 2 files changed, 1054 insertions(+) create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.c create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.h diff --git a/sound/usb/qcom/usb_audio_qmi_v01.c b/sound/usb/qcom/usb_audio_qmi_v01.c new file mode 100644 index 000000000000..5f61a8b1cef2 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.c @@ -0,0 +1,892 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include + +#include "usb_audio_qmi_v01.h" + +static const struct qmi_elem_info mem_info_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_8_BYTE, + .elem_len = 1, + .elem_size = sizeof(u64), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, va), + }, + { + .data_type = QMI_UNSIGNED_8_BYTE, + .elem_len = 1, + .elem_size = sizeof(u64), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, pa), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, size), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info apps_mem_info_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, evt_ring), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, tr_data), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, tr_sync), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, xfer_buff), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, dcba), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_endpoint_descriptor_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bLength), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bDescriptorType), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bEndpointAddress), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bmAttributes), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + wMaxPacketSize), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bInterval), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bRefresh), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bSynchAddress), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_interface_descriptor_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bLength), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bDescriptorType), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceNumber), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bAlternateSetting), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bNumEndpoints), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceClass), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceSubClass), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceProtocol), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + iInterface), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x01, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + enable), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct qmi_response_type_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + status_valid), + }, + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof(enum usb_qmi_audio_stream_status_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + status), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + internal_status_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + internal_status), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + slot_id_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + slot_id), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_token_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_interface_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc), + .ei_array = usb_interface_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1A, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct apps_mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x1A, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info), + .ei_array = apps_mem_info_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1B, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1B, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1C, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + speed_info_valid), + }, + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof(enum usb_qmi_audio_device_speed_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x1C, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + speed_info), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1D, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + controller_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1D, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + controller_num), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[] = { + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof( + enum usb_qmi_audio_device_indication_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x01, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + dev_event), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + slot_id), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_interface_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc), + .ei_array = usb_interface_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct apps_mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info), + .ei_array = apps_mem_info_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; diff --git a/sound/usb/qcom/usb_audio_qmi_v01.h b/sound/usb/qcom/usb_audio_qmi_v01.h new file mode 100644 index 000000000000..6876c4d225a8 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.h @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef USB_QMI_V01_H +#define USB_QMI_V01_H + +#define UAUDIO_STREAM_SERVICE_ID_V01 0x41D +#define UAUDIO_STREAM_SERVICE_VERS_V01 0x01 + +#define QMI_UAUDIO_STREAM_RESP_V01 0x0001 +#define QMI_UAUDIO_STREAM_REQ_V01 0x0001 +#define QMI_UAUDIO_STREAM_IND_V01 0x0001 + + +struct mem_info_v01 { + u64 va; + u64 pa; + u32 size; +}; + +struct apps_mem_info_v01 { + struct mem_info_v01 evt_ring; + struct mem_info_v01 tr_data; + struct mem_info_v01 tr_sync; + struct mem_info_v01 xfer_buff; + struct mem_info_v01 dcba; +}; + +struct usb_endpoint_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bEndpointAddress; + u8 bmAttributes; + u16 wMaxPacketSize; + u8 bInterval; + u8 bRefresh; + u8 bSynchAddress; +}; + +struct usb_interface_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bInterfaceNumber; + u8 bAlternateSetting; + u8 bNumEndpoints; + u8 bInterfaceClass; + u8 bInterfaceSubClass; + u8 bInterfaceProtocol; + u8 iInterface; +}; + +enum usb_qmi_audio_stream_status_enum_v01 { + USB_QMI_STREAM_STATUS_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_STREAM_REQ_SUCCESS_V01 = 0, + USB_QMI_STREAM_REQ_FAILURE_V01 = 1, + USB_QMI_STREAM_REQ_FAILURE_NOT_FOUND_V01 = 2, + USB_QMI_STREAM_REQ_FAILURE_INVALID_PARAM_V01 = 3, + USB_QMI_STREAM_REQ_FAILURE_MEMALLOC_V01 = 4, + USB_QMI_STREAM_STATUS_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +enum usb_qmi_audio_device_indication_enum_v01 { + USB_QMI_DEVICE_INDICATION_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_DEV_CONNECT_V01 = 0, + USB_QMI_DEV_DISCONNECT_V01 = 1, + USB_QMI_DEV_SUSPEND_V01 = 2, + USB_QMI_DEV_RESUME_V01 = 3, + USB_QMI_DEVICE_INDICATION_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +enum usb_qmi_audio_device_speed_enum_v01 { + USB_QMI_DEVICE_SPEED_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_DEVICE_SPEED_INVALID_V01 = 0, + USB_QMI_DEVICE_SPEED_LOW_V01 = 1, + USB_QMI_DEVICE_SPEED_FULL_V01 = 2, + USB_QMI_DEVICE_SPEED_HIGH_V01 = 3, + USB_QMI_DEVICE_SPEED_SUPER_V01 = 4, + USB_QMI_DEVICE_SPEED_SUPER_PLUS_V01 = 5, + USB_QMI_DEVICE_SPEED_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +struct qmi_uaudio_stream_req_msg_v01 { + u8 enable; + u32 usb_token; + u8 audio_format_valid; + u32 audio_format; + u8 number_of_ch_valid; + u32 number_of_ch; + u8 bit_rate_valid; + u32 bit_rate; + u8 xfer_buff_size_valid; + u32 xfer_buff_size; + u8 service_interval_valid; + u32 service_interval; +}; +#define QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN 46 +extern const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[]; + +struct qmi_uaudio_stream_resp_msg_v01 { + struct qmi_response_type_v01 resp; + u8 status_valid; + enum usb_qmi_audio_stream_status_enum_v01 status; + u8 internal_status_valid; + u32 internal_status; + u8 slot_id_valid; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 speed_info_valid; + enum usb_qmi_audio_device_speed_enum_v01 speed_info; + u8 controller_num_valid; + u8 controller_num; +}; +#define QMI_UAUDIO_STREAM_RESP_MSG_V01_MAX_MSG_LEN 202 +extern const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[]; + +struct qmi_uaudio_stream_ind_msg_v01 { + enum usb_qmi_audio_device_indication_enum_v01 dev_event; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 controller_num_valid; + u8 controller_num; +}; +#define QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN 181 +extern const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[]; + +#endif From patchwork Thu Feb 8 23:13: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: 198685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518814dyd; Thu, 8 Feb 2024 15:36:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtTPgpcXMi1x+BWBNp8kj3COKoHihoi6XP2e1u9+V/gURJE7ZkTUzAQI4fIYo5o/aKHzj1FnXfnsYHYOX528/7q67dVg== X-Google-Smtp-Source: AGHT+IGlTmLAOUdEEQtfiJ0qQrkSm9rLd34TEogzMwgTdaY8C7lL7Igan3ZveScWFnEF9wUrA7nQ X-Received: by 2002:a17:906:fc20:b0:a38:537:9598 with SMTP id ov32-20020a170906fc2000b00a3805379598mr535836ejb.17.1707435416888; Thu, 08 Feb 2024 15:36:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435416; cv=pass; d=google.com; s=arc-20160816; b=duoN9fM6PEdFJd4tlP/i8RseKqSNTbUTy7mYDnwIuaj+JpHTGVjR3L/bwaZC6RkERj hxlOU1+hWlY5hmr1HgSrVgoIS4BhVPZFq5ceSDMMFIXuOcgrvoGm5aIAycuV3KxYb7qf NdgaUZE/oiKZPBbbU3hNb/Ee8Hbui6P0Vk3x8ZmIVlns/zN9G7XIDCpb/mSc0XzgMZ7u 0X1dzI8XyHQyTYUXVF5OZ4FcnqKLaY476t0KMJmvxl7s2lkRgt4YeKNPLGFqFpBnN/A2 N10jnrZrk6gBtVmzBkyOU6oyrb7K4CO4sTd9myBjk3s8+MitHiT1D19jqLBu5n04+GXK ULMA== 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=dv2E0NEgURlcMLVB99ntHVcycjZ/FTz9IiEONU/rQG8=; b=gBhEoP7L1Yg+v0Y89Sc3/iju4j8SOzDENpMMKE4fQNHp0KYh9nadPh+OWcIAJ3eRFv HsxnLO6yR0Yl0GHRsdqdtn7tQSrwKDmB306JKbwp/3I++2tLh7szkhM18dwe4ztHRedO XHuVcTF2K7foRKP3NF2H90mxDBpAmsW8ZAxPuMTR6eZJ+7XPovrITPYeK36FHmH9ZbtP U2TS7hw2c16FtsWVvrUhXJ0S0XyBXzVsE5qkZJRUl7XDzTi3+qdhqveXHYk7rSuPauiw 715XUwrwe+FVPIk3mgwvxQwYVOhcevJvAqdq33EgdO0oN8qaiOWwG8/iaDaBeYWzmHPm 4zig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IDSK1zKI; 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-58859-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58859-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXVTR4ZvSgXW+p5CbaLnlsGJ2SY06uuQAwHXj3arjAyQOggbjwo89nmKo9WfZTMu+50YVBlfGalZKeVsA4xqHGFnpk75g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n26-20020a170906119a00b00a3849113468si166377eja.108.2024.02.08.15.36.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:36:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58859-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=IDSK1zKI; 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-58859-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58859-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 4C9BB1F24C3F for ; Thu, 8 Feb 2024 23:36:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05A6650A7B; Thu, 8 Feb 2024 23:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IDSK1zKI" 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 C639E57873; Thu, 8 Feb 2024 23:14:51 +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=1707434097; cv=none; b=BR6GqyJMKIskZjtiUhuQlJC03jqbhG+7AhH2qL0LbFMZx5qwz5QEqYhE84gVKncenQGx013KESJqmPPkO7Ckva/V0+AWOLJucPA4TecT48FCbTuX1oBK8TBoswXF89I6Xug7P0mbcwW3gxbNzBid0LEJgc+cK///uraYovEoTLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434097; c=relaxed/simple; bh=Izt4/N7ZEkpAzZrFRiiSnUIjZeHSUSKt0Zk1ibpDxVA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RJHn4WbU2yvt1GGLiMB1h99CyIHBPBgGcorUvtCoaVT0tiGd5XQ6+JBevhFe+10TpWryYtEVFCrDzNsl2i963fGKbWkwkymGAIEG6F2dLDetbTvYmRGK/VghmIaFGW13DkZrhCMYt7D+oZZoUs3981TtgQlYtxxxvIeqg7FkgbQ= 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=IDSK1zKI; 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 418Mrwxs024968; Thu, 8 Feb 2024 23:14:26 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=IDSK1zKIeGUbzDZ2JvzVdP015gpCM/4xCiJ+ 9im7yWRZqrFVxVQHZYty9tQbqOQ3hGqFndbCdW1RFdSiHxag1qIeo88TB8y1WgDF wx/+zHw5AxmXjRFUuZpwajDgFDgxu2Duu5HhbVVDG6a/VvN2rtpl6Jsb6ks5Ea39 5Xh9B5bRsLgiT+KVa4PsUWBYxc07Fr/OoRPUNjaFKqxtTazopNGt+kENuHi0lr2Z /QUTcaQhMPa6lqL/VP7G8wAUaI0I17jS/W4U+tZLNeRW9c+EEbRH0qhtqaor1ssj FUxMYNBPeWLIssIzxSGIdY9GyBGCn2VMfk6cccXMfQlAqe9pnQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbaja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:25 +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 418NEO0G013170 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:24 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; Thu, 8 Feb 2024 15:14:24 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 31/53] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Date: Thu, 8 Feb 2024 15:13:44 -0800 Message-ID: <20240208231406.27397-32-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 9BjfsBv1Wa1awZJIUBwoPb-pWUQmzYeh X-Proofpoint-GUID: 9BjfsBv1Wa1awZJIUBwoPb-pWUQmzYeh 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375799423099064 X-GMAIL-MSGID: 1790375799423099064 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 Thu Feb 8 23:13: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: 198659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516222dyd; Thu, 8 Feb 2024 15:30:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWk6G7np1B+jJs+pS2tAsBUq0D5DwMLLPv4QvQ7/GPKsohx19+HAqp/u2hLZeS7XYiXukVQPIAbNiwwS7K1Mm5iPjEBRg== X-Google-Smtp-Source: AGHT+IEMZshIPZzOqFja/prkPF8rzAEuZ2IPbl/D19reXsheP4WWgNwyzprydbdyGKlneRZEZVMq X-Received: by 2002:a05:6a00:2d1c:b0:6e0:8718:eac2 with SMTP id fa28-20020a056a002d1c00b006e08718eac2mr104529pfb.23.1707435038104; Thu, 08 Feb 2024 15:30:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435038; cv=pass; d=google.com; s=arc-20160816; b=Jg7ZUaC/3cdUgpx8nSE+0y5OpZlPFfxTVhq2K8+ZoZo0jpCJvDJKWwd5giz6gbe4Ke 0GccoNPLNGQOBGjydNZ907hzeUMZPYBUbShAwhL0jSz6G7TsJGLSBU9pC0s+3YlUuG0G vEtsL29WT9V8qfnIHdl7X+cz7FgfA0T8/tY6utFoGIAuXuI1BCfrJ1UZ8/IWlwnXA3B7 lk7laNYuqjN31jA+12eDD2H6+e89gJuf55FIBg9wtsOMZFLJtRmUIMWga5ZkIZgpKt7Y Zixa9bjqDElJG4/NXWHYcoKxhziv5yAiDGF1+3vnJgIwWbZX4z5nVHCmGx+wNCLL0lvt Gvqw== 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=o+wRszxk0RVAQ49EubcS3o6BAod/YEpz+w8A12Os+Eg=; fh=DCOgySnvkUhutDZ6l+uRTbsPYEa/DfkPJ0GjZwidHdI=; b=eO84N52Z2CCkyEcdZmqzCqUFdGnB6ZZCI724eKX2cadfk3WZVQJQym80mMNs6DLpLC ITGqQlKMiFKxOh0Wk5x0J1eadUhCIVuzFgSE5hMXcWdd7d0GliFLeHVdsPC+RydbWinF 6sTcEO9Ls0XacNKp9b70iQqxRjXgeRT/GWYG/djs6xVz4a/3kAej3OQVXvME5W2dGnWD YX7cTEMC68uyzwsdkLGegs4HxQsHt5D8tZSqPD7/MpnHTVQnnS6NLmOyIPUTDoicKe0e JzEJEjjnQ58CQN5DmkWLVU+V3/4fA7vCISSQ8CER0WoKCZ1Xz22+ZAoWWRhJX6DdF/jx bMkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RbsmGQXF; 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-58824-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUZAEYoQHoC+tQ4Izu2GmBLBQu5bvOshaJVuImgqOUpIw76Arg1Zv/moyyLKy72OgQoVg4eLoM4IxMaINKQZA686NolsQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q8-20020aa79828000000b006ddce4f37c0si481283pfl.285.2024.02.08.15.30.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58824-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=RbsmGQXF; 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-58824-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58824-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 004AB281CE9 for ; Thu, 8 Feb 2024 23:28:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB86660DD3; Thu, 8 Feb 2024 23:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="RbsmGQXF" 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 58BA450267; Thu, 8 Feb 2024 23:14:39 +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=1707434082; cv=none; b=lgVw8S1+4r1ydNq8qHtVgC9Xy7YHOfIS3vRUjOxp9X1K9RoYR40j8m/fDcRGqH+mbtV50c9nnlVsC+zMDDmmYcOzDXB5VogYWY3kTI+mJhm7Jp+cVLfutcNx7i+FJmcet6zYpZS58N2DgJIpEdJBdKL62LwLR/vIF0TQrlQ6s5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=NETfvnw1ab2cyP+I0JYT3vCjGI4smKavYXYp7OlXQfg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lfkv0VdWa0EYUerzs6Zf+OsOalABZ2hGO5zopv5Z4sGnaNbJAHKcD68HDsOOsoyp1L8QEL/VNeog2v4saSDBKnCrXaDa9lE1akDIGhhBovteODoJTiaTUdCfHn5PNvjWULSloXk1veRVsTkBJ6GKRCJtXpgubSzHaV3bTn12z7E= 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=RbsmGQXF; 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 418MhkpW026726; Thu, 8 Feb 2024 23:14:26 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=o+wRszxk0RVAQ49EubcS 3o6BAod/YEpz+w8A12Os+Eg=; b=RbsmGQXFVzmjoNLNl5ewYhHHaLuLmMw9BHfE ooxs8MEytIb2nGVBsjAdwPpI3fShZJ/6MIeCsCBjxechY3l5K99Eafgp/r6yLBs0 9n2+eZUnZANST2cqYj4LzgGYYzeNehNAh7w9sL98OyGyFBcZgv6v+nsCHMJuIZQ8 6Pv8dCS2yKpmFqazAGUPAjTOrXw6SAWf0l0NNEZVMVzXjKTgkC77SwZbc4ByvIeP ekOak0UuXK6vjI6A3kSz7if+H8zJyb0w3q/VQvJjTw/FrLAgGw5a3hqEBHt00t8y aeni2EcKyUxLcAgAM3XgBq5GriIQBxPwOI4fPEbWpQc6n6myQw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs0c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:25 +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 418NEO0H013170 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:24 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; Thu, 8 Feb 2024 15:14:24 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 32/53] ALSA: usb-audio: Check for support for requested audio format Date: Thu, 8 Feb 2024 15:13:45 -0800 Message-ID: <20240208231406.27397-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Ks6BwNx3ChFFUf7KjWAN8kNc42jvynxW X-Proofpoint-GUID: Ks6BwNx3ChFFUf7KjWAN8kNc42jvynxW 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375402314776206 X-GMAIL-MSGID: 1790375402314776206 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 | 11 +++++++++++ 2 files changed, 42 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..ed4a664e24e5 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -217,4 +217,15 @@ struct snd_usb_platform_ops { int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); + +#if IS_ENABLED(CONFIG_SND_USB_AUDIO) +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction); +#else +static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction) +{ + return NULL; +} +#endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */ From patchwork Thu Feb 8 23:13: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: 198682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518454dyd; Thu, 8 Feb 2024 15:36:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8ONg9OA5QkuUH83o+a0wF6VO3fNI3/VbZALGayktPVa2TkwTcPXlvGpp5Uc5oEAGCslEA X-Received: by 2002:a17:90a:dc0b:b0:296:452a:9662 with SMTP id i11-20020a17090adc0b00b00296452a9662mr296075pjv.2.1707435363073; Thu, 08 Feb 2024 15:36:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435363; cv=pass; d=google.com; s=arc-20160816; b=YSrrIpAnWM+DcakeuXVDU1lIZE/mnPOjdlgggLsCargIJYXDZtEFIQWml7IMIHMw4D Ov5pQmT1fH16/M4IKiATw40ZpRK/VfvSARwuo5eJXQ8s3/s1izSCwG8czMM1hkNdhv8u KtPv6qHVwA1uCsYhh82ueSl5/3qDpIU5UT99Y+bO49pg92JzLGfgMUOoh4mJUuFi++wY Pjc0yZgRyHL4kipFIpzi6VeWtHaMysoixr75YCw1ViKxneFPVvonmloQo5LvcoJBLG/B BUwBvda+OOzZQ+kWziJZVmOpgPMMe0xMO6MzIQNncbLQK0lFfP1fNEh4JzeAtqrn6TrC vSdg== 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=ykcyhuwEhB5FE+rNrTlrUbhFOhgtshSgIcmuOKFpL3A=; fh=p4lLYBaNk/6gvJJs0tDclVwwBckFgKnxbBSqC3am3pI=; b=tU3res9R+e8EG8y3LmqFQadzwX12ith+/2A5XDrVxNQV9qEIAmBT0Xg1vQNdCxcVZe gRCyobjP14BsPxYMDUXPZ2PAuw9c403p7v7RmbdPHdzPD+PKJF0NbN8ZxFaEOX/issdZ WZDVTYjdKgUe/mVnLUzlnYN+e8zbuqzYIEAU/b1z9HoO3TbCbWX1tsHKN7qsgwrt4Bf8 3Qtas+Yz5QRzJbGP0HZl/r1ty6pfukdWjm58HIivhftnAPlgVQdmRYXm5MWdTx4m5o1l 3pg9iLgc3o75zXaeD+/c5WSyoOql+VJl/bdLZ7kN1368qXhw2nW6M7dQdy99UU8Ns0um Ym4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IOwvJH3u; 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-58861-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58861-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW1YaEnV43ErYSqnBcUCqRbN55GttQOhNij33RHU3RKJ3rP6zcx8qQU/jtJ+fzRgOrTsTTneXA9vW909yT4Sk1Bsx/Dow== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w21-20020a17090a8a1500b0029707f6025asi405997pjn.15.2024.02.08.15.36.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:36:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58861-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=IOwvJH3u; 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-58861-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58861-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 D73FF2819CF for ; Thu, 8 Feb 2024 23:36:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A89EE67C7B; Thu, 8 Feb 2024 23:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IOwvJH3u" 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 878105CDCC; Thu, 8 Feb 2024 23:14: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=1707434098; cv=none; b=F3s393CxFT9AHYK2RqLeccHehDFZ2omdKQ4y45dX33svEjxFkeJHtofhcdUbcjTSNLD5mURJFnotoMLp5CFy7magLTYFRbRu45nrpkHBQz53GluOKRe6Vn9iwwaw2YfELVWiQGf96A7KQl679TX7imTiK51WyfAR3dKtlc4uT+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434098; c=relaxed/simple; bh=Qq33CwXLVxI1jn/NLnJhzo53fs/1RVWlAKACEKQ/XQ8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qnBdutqMf0Y2WB5Tm0N8my4L/DagSxMZ9NU7ZjsedfIadK1OqKFeZx4owyFXQF1Pfwx4JkGRJOb0Eq+8V34UK1gz/RjvdjbilNDGFBaATnIVL6P1b6EteqNeHu0BmR1fxP9Y8cEt/wgfcp2+JW32q0bjW/c6SIUHtUPnu5Ekh7w= 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=IOwvJH3u; 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 418NEJIL030158; Thu, 8 Feb 2024 23:14:26 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=ykcyhuwEhB5FE+rNrTlr UbhFOhgtshSgIcmuOKFpL3A=; b=IOwvJH3un0g+fMwj6Ae/0ngGA+FDlctjGY/7 GaQCpCNAysOE81xJI4Gk+D/X6h8k6tsnfR4Hkt+5sCvREngUwtEGHkP0b9UD3JvP uGnQYK3OBbmLqVc1YYmh6iwDXXg0wZVIWUIkgE6cT95r9X/IZjN/rhSfpQ+9V5fl 559MZqaN//IpNc0mUMapxGdjoSO5STsthv8RHjqIAdzi7XYp65vRBgboc5Q2AQFM +P1yMeWENDRPXn6b+Zwbv5m5V8lyFDIS0c0xTDcb/iAneEOJc0qWTiXJ/+RfZh7x fP3Au+CRDpPpQUifJsGrga616oJikOkjaWR6EseYcj1FKieMTQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbajb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:26 +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 418NEPFf005609 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:25 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; Thu, 8 Feb 2024 15:14:24 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 33/53] ASoC: usb: Add PCM format check API for USB backend Date: Thu, 8 Feb 2024 15:13:46 -0800 Message-ID: <20240208231406.27397-34-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: CTVCLWGaqzy-bGHnA3UkE_crcdQJWCZP X-Proofpoint-GUID: CTVCLWGaqzy-bGHnA3UkE_crcdQJWCZP 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375743518137008 X-GMAIL-MSGID: 1790375743518137008 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 | 2 ++ sound/soc/soc-usb.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index c0c6b5abacdf..d9fc83180c56 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -38,6 +38,8 @@ struct 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); 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 Thu Feb 8 23:13: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: 198658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516000dyd; Thu, 8 Feb 2024 15:30:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUeqMaUG/rfkbkRCAvmm0V7Wkwjk9V2RuNBdcfbJB5pnffkVxG/5ySaeolQyYNIrjmbPeND37dJlX5DGT20ecHk89nzCg== X-Google-Smtp-Source: AGHT+IGM1L6oWiWAS6VupuTn6ZU1K25nGPzWPfPHLfm7fYDnY2Mt+99djYFazMMZfxCTpVqOBYec X-Received: by 2002:aa7:c383:0:b0:560:1c3:e23d with SMTP id k3-20020aa7c383000000b0056001c3e23dmr52354edq.16.1707435009545; Thu, 08 Feb 2024 15:30:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435009; cv=pass; d=google.com; s=arc-20160816; b=xBM7KCurQk6KGS2MKr/4M5npiqo3If24OeHig+vIA20FjvBWor5GFR6qBtyzTeUzqo Ad9o7zwMSSKS6tZ0aGpfdsNz0dPXA3i38NrhPHvPXtTognuaKifd1c41nrkVM5Q9DUuH WxUkMYb9P/tDlfLlK7Snj6rGMT4DDxx+xuIdchtM3mht2Jn3Ihgxg2gqCPL2NL9lE6lB eo/lYCiCcJ9M9BOg9Gw54SujvFkr9xur/unTnwbGwTD/N7Mn/IxQKMaid8O1tR+GE6U2 hhlzLfluk2US64EuDbhYfzgUzkZGI11kHRwXrrvM3nv6Sco4ECVil2IcORXqR9cEZS8g BYUA== 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=BBSXqgbxUWIN+IK89zrSPgbzcdtv5SiPyCGjtZlr0Lo=; b=eybHWAywEgbntYDpVwG+kZzDCQbnoylEYBvlqn6EtSkS9ffkWvTMaVIrY0K/CxQzaB gLkc+7AIwEFPUpC7xlVlDfKIs5Bhp0rT+B/Tmu6kxWUiywcMxRzUESKdi6CiIafXTxDo KF2BhGNbEBsDHQi1XCH9kXsl2DEv2n8M4BrHyVfogRpuVxhkknuX8bLQoY0uJ1jIbjxn Dj+zzMyHiNFsG8ryNb+d5NRMrT53gsyxIMwYr0m/EiKo5SgrzoIoRLVebsxTXfxy2NIW R6AXKHR4Fu9SP6tTqDXPJzBJYTtumnQ2QHlKfImWAlfvsPmEH+wpYxGjFUgSpl+vZ4bk YIUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lg+cAQ79; 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-58832-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58832-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCX242sWchfq/3i/SZlhpZzlKgptPOlyjpE5kjlYx7N0JWV3ogKE/Rrwu92GoFGA87C2uhooB7lDDr50qPAwqp6+bNuFew== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z20-20020aa7d414000000b0056107d10782si204973edq.281.2024.02.08.15.30.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58832-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=lg+cAQ79; 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-58832-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58832-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 2D40F1F21322 for ; Thu, 8 Feb 2024 23:30:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88C2E50A8F; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lg+cAQ79" 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 95D5C53802; Thu, 8 Feb 2024 23:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434087; cv=none; b=sKgleShbyh2oyZcnx3s7Nmsqn7pA2yEDhblAVNYB9YbAC7qdYjodBQH9FPSSJVdk5ipCbj+Q2dOOuOwEeXKRMGc8VSYbzj+qiM8Vr2BBrzm74wj1lJ0JAVcH5xD3WwDm3uxbq2t98YlwYEYwXNr/6n/lXhIChM3Z+bnoWRmS6pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434087; c=relaxed/simple; bh=wMg/yooJampZGgA3jnDjM7vmFu2HMC0hTX4YlMJF8tY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jKU79eJsx+1ejjCVPDMAIf2AnhCJRHlPNwoa3JVnaVmVqyV5AoZJPfOMWMkI/RUTjGcgdSAoYFaUhLgtHT/gs7N3MDs4d0a/cZT6e6w/vnzKmc84WJEWbDEJ2rnVxIBKHr28s7CDd9sCPAydZHP8zeE0NExhWezw8/odKNyOqxw= 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=lg+cAQ79; 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 418LENm0009617; Thu, 8 Feb 2024 23:14:26 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=lg+cAQ79AN5fbt8ViGSyPDh84XZrm26I+XjU +GTJB3qv7xXGlo51GOqaj86TFXhm0ptzHZVSUyBEJzmHq8VHTKxAi1S3d1qqbhPt haSqIcE68f5JWmNzByI5Q/4/WJCKhw3rdy7GwJQl7wL5mTdlCfyaLgPTvpTHUHdP P1D1vxG91GCDo9+ju/QACtb1NRCjc2uw/W7tRCUXShgqtiGlkb1SwzyzOHxXVZoB cmSrk4CZanGi8wKVhEHBPaXmZ4+VMaSeNpjc6jZXOfmiHHqPyP2rILVuxOeuwW3x usRtlMc2+8gn0Ubxm41eRDPuxQF3bZtxOcBq7rCbfhp2Qt6W/Q== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2ab0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:26 +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 418NEP6n005615 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:25 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; Thu, 8 Feb 2024 15:14:25 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 34/53] ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device Date: Thu, 8 Feb 2024 15:13:47 -0800 Message-ID: <20240208231406.27397-35-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: kGtSH2PEcQPUfUvdHaOXynNKo2YYGeSX X-Proofpoint-GUID: kGtSH2PEcQPUfUvdHaOXynNKo2YYGeSX 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375372184934986 X-GMAIL-MSGID: 1790375372184934986 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 Thu Feb 8 23:13: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: 198674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517997dyd; Thu, 8 Feb 2024 15:34:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUssMZ9nCO8rgq/dMxlqMWXbVGhNFOy+j0gZEaeu6btvhKmZ0mFo5vazSyb2ZsVrdP8UOktCseI5bLryH6TRZzkXC/iNg== X-Google-Smtp-Source: AGHT+IFbHdb89uA7S7NpQRiAPM7X+4/CmyzLVhFSlv9MMqEFY+ftwrORTltkW1FwjQYwv3CNhx3r X-Received: by 2002:a05:6a20:3aa2:b0:19e:99c0:c1eb with SMTP id d34-20020a056a203aa200b0019e99c0c1ebmr71629pzh.51.1707435291889; Thu, 08 Feb 2024 15:34:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435291; cv=pass; d=google.com; s=arc-20160816; b=b/rMf8N088gDHqw0br47j1z0RsZMPwmwxmlhGRv4g2NsoY24IlVUE1OUdi2U7HODTX kw8ce3RqK+pyp8ZGpGMrYyaADenC27IkrWd8i7fHSvDvzh999/GOY1bstzMVNhJPtpix W9ilXXNNNgj1s3tV/FaJQt4HCeKhEm1p6YeETLZQXwdm/yLSGjqa+TiTz6GZfGmUGj4j GoH6d7BuAwF/j4SgY2fxsEc2fb7oX+aUBBChd75rwHhzJUMZjYEggRlH92XroXYoWlEY 8NyB/s9JtpfTW3Y3R+d7Rvg1vs8n2OqixaJUz7dpnuJqwRCB+syQvWZB0aS/3aQ5r+8t kbxg== 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=4JPA4eHmUMHFWIjYZV4HYPfzi6+ok1DDMOkZIqZ6MOQ=; fh=7KGMV7fCysJ5oPCE9OJ9EYDbdH//90lmDec5QsZDv64=; b=CPE/9KYRLJXTRFZgAppXttcf6Tt5uNuUlAqBX04pQbvUznaJGxqRpx8oHSNRgxPAqM SQ4UcBIvsN5vKswcNkc2G4akIGEWTtDih18G5RA3mu1nMxtVhtwHx4cuFeLHONOCl+OZ ORitGC5QZSt4bD4D6IwiPqFPAKaluIGTZ4kgXSMsjrrHfKJ4Wy+qNRl/Gz6VL2OVaSoN n0rjSzmg0rygcALQIcUaibJtE8EL56aAmaXUtzdfMmny7GW7fCBbXtJTNJcwGOvk153n eRWjTLMsR8WMEUU0XmvSXPBWR2ygqclFnWPsVF/qqbFYwziSYr8KI0E4MO4+jfvXRh+i 8QyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Okk+jkH1; 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-58853-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58853-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVSSpxAw1K+9F4PDozqRk2trlkefPXU/f0Fduqf0OISEPunNEK7L3e052OzbTaOiSyfQRR6B/7qqK7oCOtM/hxuKoyVsA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l129-20020a632587000000b005c6c950c3bdsi603082pgl.642.2024.02.08.15.34.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58853-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=Okk+jkH1; 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-58853-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58853-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 84B02280C52 for ; Thu, 8 Feb 2024 23:34:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13D426167F; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Okk+jkH1" 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 B25355786E; Thu, 8 Feb 2024 23:14:51 +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=1707434094; cv=none; b=uPLbCY9Gv8xNstIFLtoKhUNymZpgiQIv1DeYIu8rR9OVjlZqvsbxVSpmPdgkEDR5Tz1C9FncYIZJnzRczPOtPKDYzAPQJwJXc3/7MiAcHcyfXTOZM7cvJiaTD9fpHCSFI2Umk/2xjQT2bMrFVLHpKKDDwPe4KqR5AI/ivg7fejY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434094; c=relaxed/simple; bh=JtJrswJjSBSTvEffu+QUKkRoYrxTr/tQnHphN5S+Y2U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zrc9QNsl8Jzt/DBnjq7sybVdgDU/8Q1tnMKgYAjkaBKRg8W3stNf0K9oyM4KBcySOU5V7zeRKevgLbbLlhauHTKBT8jBwwLhJ4QZXD8umPoiyx5IHduczs2KV+e9Ur1TiPYTi5gf+ghTfCXwETH72Np4sMpY0lgRwiELw/9EuBo= 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=Okk+jkH1; 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 418MdPi3016538; Thu, 8 Feb 2024 23:14:26 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=4JPA4eHmUMHFWIjYZV4H YPfzi6+ok1DDMOkZIqZ6MOQ=; b=Okk+jkH1HM+a9NhlFpGg8gfOXP7AOtSSB9C4 k7TF/5rYOHxD1Sl7LHR2OZL7TyzKEhBCtO1Xw84UIOptOdhcRjaTp5u3+ajSCc9a xryH3GbbBZwM7rfZgXwRKHcyRWz6lpEvatw1Cn9WSnsQZIGraY8N/sGNuPFKcNHY LitwQK1Yov9GCZrs3vKwaNDuB0mbhBVtVM/BIwL8ZqYsB4UNa9WcIN3ljo6HhQ0C A31Vg4MNUgZRxgNlKOw4weGvHIog6LmWIbFqyMziO9zfE3GHBEPgrbNuuYSzeUOt nTQ0hd3eqN0DnWZiv82nx81PcJQ58ihEou0vKMecv6Ah05t5uQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:26 +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 418NEPlX022108 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:25 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; Thu, 8 Feb 2024 15:14:25 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 35/53] ALSA: usb-audio: Prevent starting of audio stream if in use Date: Thu, 8 Feb 2024 15:13:48 -0800 Message-ID: <20240208231406.27397-36-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: TtsJA_TsSQZf7sKMj9gFZPUZajkby-SI X-Proofpoint-GUID: TtsJA_TsSQZf7sKMj9gFZPUZajkby-SI 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375668527719085 X-GMAIL-MSGID: 1790375668527719085 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 ed4a664e24e5..6d59995440c3 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 Thu Feb 8 23:13: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: 198681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518426dyd; Thu, 8 Feb 2024 15:36:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcu8wREkO7PiRYuKs8AFKwHakd1Pc5VRDqC+u/OkqdlRsP4pOAomoDqsU4eEgBdYAiUePO X-Received: by 2002:a05:6359:4c0b:b0:176:9f24:d06b with SMTP id kj11-20020a0563594c0b00b001769f24d06bmr642999rwc.1.1707435360196; Thu, 08 Feb 2024 15:36:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435360; cv=pass; d=google.com; s=arc-20160816; b=m1lvypO4w6hVHp+wireX37rLpxGF1Ws8ADwuPs4WldAKIUk25lhm2tyLieU6rtjs9c 4iCftfo8t2EngBXs8CcsMmw6gUF+qiy/8o/bxbndnVTGzOCQ9LHcvCB7GS6eLC8fXJ2z ijJwri81nvXzBTB04uNv6694G73MHso6Avra7Ot6ZvlNJlDpBjlhQ4f+DZs2cnNHCyjY 2erNWvSWROJ7CdXGCMJe4/M0kyOSq4zViBKOCn3lw3zuBCBL9nHohjaA6I8K9r9uTB+p 4fOzlLUKew91mGp/2Jqz02Oucek2K5xC9Ln3KnNf8eiNbYurb1ui+HFBnpsrDayPXmsP oFZw== 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=fIsuvBq4ArB9gE46figMQK9f9BUvAuqzvQljDv+3s3k=; b=eScEM1EcUtkG43GlMTw1DzKGwJ78hLTY86vCHO7SF7HG3+DPJt2eYIPUCjzYDIU01Y agYLAsPbHpOaYsi12Gkln1f8yjG9E/mjwxxGQTiGNXvHwleAAJLrmf87YVFFUk8qpiPr Gj14at8icx9sp0vN6lshStCyWwdBwrIHhAWpPYFhe5PbBqfjomgMypm0Ssg0mT/Jvgoh Fo2MetbJpqiuN5J2kuYEDee5AQ20RqFR3cjT8SRMLXpuPDf/7K+BIRf1Qpiy5HuolStG qLiJnugA4ghQclUdW1NlJ9S1khqbJDd3dTqI0jLdYmv9Ok1nC9QwIULWXkuE4unNERjS 4+pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=oYUUhyMe; 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-58860-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58860-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWx/XpNqmpACrNVdUZ7i9T3YchcDTtpyucQD3mUrlROvbtkZnss2ToyrjCpeelZ+Xzl2hHFpKpxvVzBHMLIjq2ZSWF5yw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r144-20020a632b96000000b005c658bf30aasi610401pgr.412.2024.02.08.15.36.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:36:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58860-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=oYUUhyMe; 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-58860-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58860-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 ED8372819E2 for ; Thu, 8 Feb 2024 23:35:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61BD567C5D; Thu, 8 Feb 2024 23:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="oYUUhyMe" 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 D02615C606; Thu, 8 Feb 2024 23:14: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=1707434097; cv=none; b=aLVKyWeLVrQgxgBXmIiKHgWrNY1QyotrWzk1LNDgEu4+Yr+FRSQ/b5J0qNlv8COfgLOxUt+cBWAYdTe5+jeoNLwh4H/tXLpho6wETSO+FsZtRLE3/XSpJtmjtS8lU3v1hR90TV3M/bfpdCWjDAus43WaAD6wURqzjjV7e9hLdkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434097; c=relaxed/simple; bh=px268WXk+l3B9SlGv+cxMo3ljNfa2rsGXtf1IZjb19I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PnApPAkjbWm8qTdLaQvm28CABHdutuXeqmamTTog+/G2B/u7DUgJbgJHjDyNk1sFKyEKg71khbMeIHIfwh+ABTEhONR+px24C4XinWxkG6Wo6Mr8VhAts84cDMa3M0jUseiC4MZvZ++F3qQ/orRYTbV3ZpEx7SYzl3fvo9VzPJw= 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=oYUUhyMe; 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 418NBDw9025996; Thu, 8 Feb 2024 23:14:27 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=oYUUhyMeds91Vvnghbc7NvRvHQ/uiK/0XwVM Zm3OR3hyWyGhsdf20g9zLVTWeruwIOrQnP7kgHhyOHAazcbuIxCwRUTGM8kC55IH Oo25YWKimLW1bwz2V7MXzRX6CXYjOguZUpoy7tPVRiw/+eJpAs93gOnBFQ1kNg5t +MH4InxDEBvAys57jHiqiQSXAEMGHnBSeFVv7RtTzkY/eihbQZ5Pti5+IlQ2NmAW bSIQBSb94GJSWPah8svr/kUBHnC5dwLtLVUGxw/HuCql2309vcmO/r9hNA4AX7En PMaAqrQvGhiXdDWpwQm6AR7pG5NTDz/Vm4jIoLrmyIYl3vT4mQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4hhkbajc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:26 +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 418NEPpo022118 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:25 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; Thu, 8 Feb 2024 15:14:25 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 36/53] ALSA: usb-audio: Do not allow USB offload path if PCM device is in use Date: Thu, 8 Feb 2024 15:13:49 -0800 Message-ID: <20240208231406.27397-37-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 8tNcLsd4pCiNAPtUa4YmZn_yLZMQo9-V X-Proofpoint-GUID: 8tNcLsd4pCiNAPtUa4YmZn_yLZMQo9-V 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=963 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375740001680735 X-GMAIL-MSGID: 1790375740001680735 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 Thu Feb 8 23:13: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: 198661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516439dyd; Thu, 8 Feb 2024 15:31:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXODtstY1WxTlWCawBRkpazO/vORGD9PuGRUpIKm5V9Pye0nL+5zHo2eFSKBp2HDf9Hy1B/DoEWBfrjvuj7fg1IrOJoHQ== X-Google-Smtp-Source: AGHT+IFAg1/uKHD1OMEYlIDDfxkbcFrtbl/S9CYi6yhqrCfbhirwFWj1H5BLF0mfhqy351q6el/P X-Received: by 2002:a05:6830:208:b0:6e1:4848:a41c with SMTP id em8-20020a056830020800b006e14848a41cmr1192649otb.7.1707435070178; Thu, 08 Feb 2024 15:31:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435070; cv=pass; d=google.com; s=arc-20160816; b=iaTZeifmz6mbulrdC+maFCKOf3DSHT4WwtHmsQzQ7w3EoqA5wScgrMRY8KjwuW6lmK SBNuRF4Zq6R1UKZp3+xr8pyo7VAykOhDfaojk6uY7COQyECnvsX8/KDiHB1BOtw6Z9J4 T+xLDYwrVuYksVudHlr65JsmWc1nJNtGwkT7zPq8KXxVw7R/tQ/FrsWFbbAKj4J6dEUq R01t5Jl2TWOTVwPdyLqIaCforJpn/T0LdlOdq2Upks++pLhaZogn3HbXGQBD6r5iC/W+ UGLHH15lOz4F4DSFjRfMNNRMLVeJDPRrQFNqhFQG54yPjDtwIAALFr7AS3U/Wtwvn4yv y5zA== 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=7z6anhazlpwnwyHiIFimKzXr5+m6l6t1CFmcQYTL2gQ=; b=Z3J+ElTWOPPF60zTfuAtWVG5UL9hJBROhZVs5eA/3KYDTGNCNRX1+f3b56pPgZ7NHL sPN2KmbWmIcgqAUicV0/MtnhdEHMhSOAv4m75Pumngr3idz0vUe7+FZmhqGvftTS3/SX HpuoDY1NC0CiK0M5DbiTZJLdQtwZiWtWXckC5VGx/Pk4BMWL5iUU+YiDDsD24eOGCMur 60dNyE7KQn+/KLiOmM6M5ma2wsaLNmJc8qlnrbdw3CL0tQYZ7qSZtVajnyx9RdVDzJMo H/kIVJpl6GiJ3IfFM3vEgWZNfErGNLLZdICHNUhqBjmFZlSVcX0tQqiA8Mmvp3l2QOyi /gPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="JZC/FOlY"; 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-58835-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58835-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWcbMrCDVdl4tQxu9M9veHrjxGg6kOM0UpBO/AywjU3vGVbZ4D2u1BhWHP4R6Kam3xTXOKwH6bgC5dXfqxsJ3X0NeDHfQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u22-20020ac858d6000000b0042c28be0ebdsi604692qta.249.2024.02.08.15.31.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:31:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58835-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="JZC/FOlY"; 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-58835-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58835-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 C1AF11C243AA for ; Thu, 8 Feb 2024 23:30:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C396B612FC; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="JZC/FOlY" 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 CFD7D50A68; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434087; cv=none; b=NHCLANHeF/6PLQqX69HSrW266kr0ejrvnlu1T6ARDkkpD97w1JKn4EOXDCv4ARmaSP7cHuljk6C49VX4lNcCOm3Dkp4OLd3HzoNPrE5NQEKUP3vDkriVZQ+VAujUA4AF6cK5mjQWW5th19RNud2C6h2lypuGljvlWf2CH9Te0nA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434087; c=relaxed/simple; bh=Q9v7m21SznsQRBxoPQiAbg8VdmmvPkGv0cpZczE0uEo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JDIK0beaD56ArF/RStcYlq4U4bfr0FI1GKZKFuEIhZ1HE96han+nSBgVRopbsLz5138XkgNwLVYYiSHKdJg8Z0Q5C966rIEB9uebm8cFeAGZ9JWr+LLZmKFzlOxgez76FdJkKUaIuZvbanaYfzvyOEH/KpycUSkWoKitFJS/nV4= 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=JZC/FOlY; 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 418MEeE9032659; Thu, 8 Feb 2024 23:14:27 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=JZC/FOlY9mHlXLczzW+49/MYLlwVO7wRBYdH rBsmWq7/k+Zg7LElz50ecsFvxgw/i/wndX6q8IGwJKk54lqFYSpZ8C8wj8VmNa2l XDwBGCGZrkcPdW4+Lb37RhSANxrWfkmOSa+1hLIsuECJAPqfg3J0zBOlOuz7E4aP PgU1Fal25odPFNm0uv9SEJ6Wn5vbo5FcwxpxqWIZMToDbmPkIO+EJC8QCZUQMYne Rh7DWsCYBDZK5keyAdEi13a/x9K4Q5WK8hUH6XzTpq07S/3dtNuoYBZbcPjsTxV/ x+d9AmCbES/IM+VHP5iNsNazkTiRYhhgUk56kQfO66NI7zguRA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2ab1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:27 +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 418NEQ5x022125 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:26 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; Thu, 8 Feb 2024 15:14:25 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 37/53] ASoC: dt-bindings: Add Q6USB backend Date: Thu, 8 Feb 2024 15:13:50 -0800 Message-ID: <20240208231406.27397-38-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ERBXskQchwE0Erp-d7F2pd-0nD19QeNz X-Proofpoint-GUID: ERBXskQchwE0Erp-d7F2pd-0nD19QeNz 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=991 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375436010240135 X-GMAIL-MSGID: 1790375436010240135 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 Thu Feb 8 23:13: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: 198662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516475dyd; Thu, 8 Feb 2024 15:31:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHh5OBvnM2WbqwJ40EPYquScTl9JjjKQaLbvLDOpGx5+0XiPqNSb7+lhYg2f2u3v/T+gSIA X-Received: by 2002:a17:903:1d1:b0:1d9:40c9:43f1 with SMTP id e17-20020a17090301d100b001d940c943f1mr772965plh.49.1707435075960; Thu, 08 Feb 2024 15:31:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435075; cv=pass; d=google.com; s=arc-20160816; b=NuZa3/XTdZpnBZq2d6a+bzUup6wVSw4t1sPhJXBzmLQHU2qZfQbCAOwRbc/FuO+jVR UTfUR8KpHC+SlZr7g2MfmF8SWMr9xesfwExO2TK3NOPHPLLYBzWl7T8dpXDBMzBqd0SP W7YGBM7loYIx4kDRFzI/3AhCVHjeB16xYEpHW9XZF0gJLG3sfd5lsSgE9veDgQn0nLUN lksdvMH6gbv3GNhVUh+kGB9JlzYXkCvbFY1YOLHRXSdCIBq+vnqfRKoRzjLbZunPgIk5 s1oChA/cLm7C00WgTHWp1jxKML3rWd9JGPr2upw1aZlm07dk1Bab9XQkMv/793TFRDFw 4QuA== 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=a/1jgBSP2QTA0927Dnpsv6yb6V6ENqtCvH0B/OqyWe0=; b=ypuTqWX0Mx8+TLXxjDsXIGG1Ai80xHg1jjrmkTlMW1M7iw7dnnTUfKLO4lYBinTu1N 09GaAVLFDKEhVyl62BwRE5ubOpOvkQcXPDnG6RuQem76+9Wg6Y0ECKNt8x7VhHhoIOoG 4O9KRmGf/t/3hPwxm+qWxae+4hjFdF8b2xg5P+H/ynpgidDiJLujMGNRnhIRWRG+gq+b 5Eky6/mhZRQTeAoDAntO8fo+8AontLziGQTNlfOM9Nl40PrfbHfkjOd09t9cr1+rikcs qSPKWvYphuTXcIAMUVVizFCiBqJUFSqCwNnjjv59tlPJWFIRSNxe0PEM3N9cuC4xhSy/ 8FfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VPo5Pgya; 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-58826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58826-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWubWPX2mmBVYTsM2x5qZZlPpO5x9epPZFDkfdeNrxzpSBi91qw1dAEMSauYM7Vv1AdgbGLFwx4Rjs28wt3seVmgKWoVQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f13-20020a17090aec8d00b0029705a95d81si604728pjy.36.2024.02.08.15.31.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:31:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58826-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=VPo5Pgya; 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-58826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58826-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 BBE30288AD8 for ; Thu, 8 Feb 2024 23:29:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0538060EF9; Thu, 8 Feb 2024 23:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VPo5Pgya" 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 3BEC650257; Thu, 8 Feb 2024 23:14:39 +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=1707434082; cv=none; b=J7G5s5Rdp+B3hAmvieybHB3y1engq74sRlezJNZwZ+YzI9biZvvkoyDp9dZHmfEtprxKLrNRnS0kNVWE7H6oZwn9QowUTSgMQyV4X7zbNsg1JUhbtdY89QBpgJ0B955KmvdcCdMwlEMY2YeWt6AISdUeKJN3xRkFIq5D0C9n7Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=+XyT6AmPyeGSCzDybpKwWtfIMLvamtKqfXcViqYy9iU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZYqRF5Grk+VweTzydhsv4sAbyb4pz1EkF4+EsuBSpQAyHGmm/TztvsivEo8B67Ebsdg6diF6ZpbPoq7XI7DM6IKUIN4ExF6XPNQzMax+5hFse51dZSETQ94Du188dgbdMFoM3WJuRs9zKqoNe7l5KsgTPVhJs8Rkpq3KtsaTIrA= 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=VPo5Pgya; 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 418MpGpw006283; Thu, 8 Feb 2024 23:14:27 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=VPo5PgyaScf9Z5zFeHM+7dwUzX/KT5Ku8Zi+ l8lORPrON9bdzKjJL3CeSmWq+tte4yaL0/7i/vP3XQTNaXYTAh+ZHU+YY6pOtQVb boFbfm9ocRFUYG03WWfHU4Ag5cWrYoeS9q+I74lof20C4Ltd7iv4tvcZgRgJFym1 SiwdmCuJ4gTSDc69TdgL/t3UCgZHPJkEhS6i4eZ1tIkxraLXvv0KO4jbmtKsp4hz uZfZk4vchfa618Y0j8OZsy6xcAoOal0ApgtsxPdMmb23GP1jySPEDZi7QWAZXW0O yIXJTajU6fdkoM/ioHz9fRO2OO/g6WcCkdPcN0XPjPWE8zxQlw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:27 +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 418NEQoY009240 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:26 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; Thu, 8 Feb 2024 15:14:26 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 38/53] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Date: Thu, 8 Feb 2024 15:13:51 -0800 Message-ID: <20240208231406.27397-39-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ZRqryVz3eMuaYuloTZMd96lywdUYc0_A X-Proofpoint-GUID: ZRqryVz3eMuaYuloTZMd96lywdUYc0_A 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375442336040008 X-GMAIL-MSGID: 1790375442336040008 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 Thu Feb 8 23:13: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: 198663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516576dyd; Thu, 8 Feb 2024 15:31:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJdfYY6VINeAz4rQvxWPlmdV76Y5eHQME9PM4D0O6iCD+dL37nvkHyW56nKLtSLvPTHP0X X-Received: by 2002:a05:622a:c5:b0:42a:b257:2019 with SMTP id p5-20020a05622a00c500b0042ab2572019mr779151qtw.39.1707435089437; Thu, 08 Feb 2024 15:31:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435089; cv=pass; d=google.com; s=arc-20160816; b=nDjvN/mEZBAehsNee6tvBIIJsHoqLGuK63m7DVxQOtMS65rtrk65N6z/5A7cyyGooV vJjpNoWIFUI2hZv6cnnmr+SaMk+WlmlJyXYyrh+xS4V/wF1SH3fXMYJp9M6ceLWjg7Or MZm0O/i0Cf+iQKxs30kGQ69c8y8lBbKPMR5wXtfZxC+2fT1eQkZYJkzPfh4cBSMNITeh mBmpdU4vaedId2g6KRAKA7ZhWARfkj0+Zg6eNjr+s8V0HGOIv4xGvvPN+JYaACBGb6bv 88YNsaqfQgcwFbcYat2BHm7HkVIHAsbRBSh0ceh/YeWWByHSRmkm7Ee1rztKuNlLES4b emkw== 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=pdX+rtNgBfyktI8aW8QNKzGaq2YWu/AZWsfWib7GJjQ=; b=WjSf0UITU7pFsbm+Rh86wgyqbNYKsGQNld3I7saDeNFBbTYP22/KtoYZNFYHusIbQo 9pzQj7Zwx5zB4KyvQOeuV6Toi2vTXwiE+rURMMYswcNgvHBsd+CkSaYBcqkVrJae8pQC D1x3z2uaLhfe9RPe6FUGW3Qn2sC39g+edk9XFs/GJJqMIeO4xYn9jyzYMWRYotbFfUG8 ZON7hTaY/B/+zshM6hDNOgHfLqUt8TtKCATvYy2gkzo4NrSPJQU9JV2HBQL4xkZMB7JB hx/IL1rFIaSp3tVwHUtGvwsyGUt6v/UtQYDc2ZevrrMcHeURXjiIaigC7hfqynou9bb8 Zejw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=K2hj+YZu; 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-58839-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58839-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV5gl3qOqngvwk4uKq+yVQIE6I4sSDAIFN43htzJaGM5wTmlatQpqvVnnpi2ZVncN2Q/unVg2AF7jy55Q0ihEMYxzbe/Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k10-20020a05622a03ca00b0042c4c25cff7si581200qtx.657.2024.02.08.15.31.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:31:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58839-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=K2hj+YZu; 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-58839-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58839-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 147B61C262B3 for ; Thu, 8 Feb 2024 23:31:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2E646280A; Thu, 8 Feb 2024 23:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="K2hj+YZu" 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 720445026F; Thu, 8 Feb 2024 23:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; cv=none; b=BzLPd3X2pquQxQh2JKyI4y0+KJt3Ez4Pvfu+96FNBFFCde3ZjAUxwoRHAeyqD287lU24pwfIEiVkQRWVbG8VNghADf2PI0EbVqUh+whIVRSfXTG0tqyLho4pAQP5w1aqWiLP0/j/wlJlnU3QpTVahx+zdClhtRR4yvNkVE95qlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; c=relaxed/simple; bh=3t+oyyObCLNtDcTqp0pGT8TPY42C27S0xw+SlfeDuZ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s3Lx2WKpU0smDaxwwkdT+b8Npx4wKkYH/S8vVEc9ZE+9JDCHBPoKNJdE9xQ9BZlwo9eu1WFOqOQMKy+ceifBaeGwqYquMjTIo2NuetNFE2dDAT1LJR9DpzEy03nCh4o6mwo2wnREq/xqTy6lFIOIOt4/n0tWUK9lNWU62YXlWF8= 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=K2hj+YZu; 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 418NEIaf017497; Thu, 8 Feb 2024 23:14:27 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=K2hj+YZu+y4JlOqaF68U0RvHAMROkv4naoV0 GtSSs8VXS38a8RiWCPNi69+sbnM/heSuhxDVp+ftlWMhwMjYOywgigyI6m2hezOT eF/N1TA5L01gGlvm1OFkNJWaVeWivpODNs1qJ0EB4F/+y/Sj1PttjtzE9i1a3uQ4 i3SqQ1ygSD69d5cvGAblj19ZSslQYeKpRV9eaDfl7s/d8by2CwnURsN3+ueXs1wU LLt39ke/NuZ9DnRPci5YMcQoSU5hhvWc7wSmXdW3A7HAxzkhw8heJXtTad1+osHg Z0cOGCnuLkjs8MAMhg0zuxG5RZlnwOZmtyX3XX99WPCRacf89A== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:27 +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 418NEQQw009243 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:26 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; Thu, 8 Feb 2024 15:14:26 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 39/53] ALSA: usb-audio: qcom: Populate PCM and USB chip information Date: Thu, 8 Feb 2024 15:13:52 -0800 Message-ID: <20240208231406.27397-40-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: AgMmo6ObVps9fInl0heZldMqQcOSiLcZ X-Proofpoint-ORIG-GUID: AgMmo6ObVps9fInl0heZldMqQcOSiLcZ 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=678 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375456499858950 X-GMAIL-MSGID: 1790375456499858950 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 Thu Feb 8 23:13: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: 198702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp526615dyd; Thu, 8 Feb 2024 15:56:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUlXKi6WHKMDCCoClWBu5eXZ+d+WD8EX1/8xd0a/09H+SvzjdWC1o4G+bFk5pHJkGRpkEx0btG9f/amuA7DnKXQjbdNlw== X-Google-Smtp-Source: AGHT+IEwH5+LTAvkGxRgxubHsu0/6hK5zJRns6bivdswQlCWapjg8cqjzTd9gFQrw1lafa0nvUCk X-Received: by 2002:a9d:6d05:0:b0:6dd:e264:f8fa with SMTP id o5-20020a9d6d05000000b006dde264f8famr1135816otp.28.1707436605396; Thu, 08 Feb 2024 15:56:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436605; cv=pass; d=google.com; s=arc-20160816; b=jxEtnODPaYzmkI7rblsO/wCUhTKlxm5cx1bgfx6+pluczQhlJM+gX3JXWUhnunmVi0 ZUj3qhxYhYuFunaLpSdXeFPLwllY9srurBTGp9G5/wCPd8wUpdC5mShixqm9484Z5Pw5 KWmVeDo+q7s3gNPfEAspaGT0jVSYeLyTTIvueRbMG3Uro6xG0v8b52uWhh69bIPXnLBX T959anwb9pz6+Nt7DmTwZVMOrw1/1cce2Syu2tbNbk5B5QLkuGOUo+8y8ykP+Pq+7bou faYQwnVOC+m5KPVHTHMN+2kqmTrDdoozssumQ0SLb60TfFa/BAjTMIcC5n38lEv8yQNw zaog== 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=l6MuCJVdYZdieZw/b2ooJ8TNWZJJdmWi4OSieNQBdSY=; b=dJ7HIs0q6lN03lkuqxjTdQla0CNJOWv9mAlhjSxO8sd2HftM06Z5rVdUzxYsSo3+js eAk2SlJlLukKW4gDegUvk9BZECb9jymvPADNeSERc5IGugl0Bi19/ulV7MK3/NFJ7F8/ WssOdb7NY4wfH+qn+4khC1a3pSqbOb8YHb3O8JVwls1UByR73omK16+ZFYh+Wpi2btRD FMurfWJLnzszrWuHvBAiaWAa0Alq92Hhv0qFL9A3Yvn262PtkhRhW6p0qgYQ7OScQ1Nb bhEkkho7L2yAyZnaanglbUmg3w4qoQvclG2SRDje4mjswKNxEIbUPnkW8tKJJ3L3Kz6w gQGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OK1BrHd9; 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-58823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV/Lji0LffQAE+l7KQEhQEG94YpDTf9DUedlWYJl6o+VVdZusEIX0Rija5i8U5qGjmcdMfdrOxIDXIvADj7eSyxqalvJA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bx32-20020a056a02052000b005ce3c33c303si683915pgb.301.2024.02.08.15.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:56:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58823-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=OK1BrHd9; 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-58823-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58823-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 56352B2EA09 for ; Thu, 8 Feb 2024 23:28:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B517160DD4; Thu, 8 Feb 2024 23:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OK1BrHd9" 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 5619750261; Thu, 8 Feb 2024 23:14:39 +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=1707434082; cv=none; b=d0gjq0h8D1IWWaScSapGYgHRYAIqKTSAdAzmKbrYPjdyiOSSmbkS4oZ/F4cBrJCd5v8m7BgTX1RvRIMzhNZCf6/x+yctHMiKf+3JKgsD4y1esDTQudKBcPG2e29WKAbVof/JBtlpD/l2xkx3fp3k46aI96JMfqg5Yh3/Ux535UI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=/CBCu7xtzLoC6vN95Vv2nxS4gvDbU4mm+K3QyU75FAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GYczLZ+x7Ac8GENKP2y4OL60TtRqKe+KIYzGcKd3rUj74aBLNSIutbyZn3BPe2HS688HV9c1AeXdxgTZjrTSbfT5rCAAdQtd9D3QyVrzS7FXgmW0t6qfdGOxGT2UQlEL4721nuBJjCKsWsCAny67xj6TDKBT9qarQuwEFKo2cWg= 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=OK1BrHd9; 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 418LjXpA014636; Thu, 8 Feb 2024 23:14:28 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=OK1BrHd98bfwPkoB79hobZEgVs0p9mRtRsQV z4HLm2TRhkOhReFbV+Shth8h7mD9bgpwuEUj76hHIN6FS+zHrcT5K0SH9UgpkGaT oxsdMS6m7BDryrVxFoZ537plt3snDyrXaHqbSV+wb7J/CkYtq6PyBW0zOjx1f38x qNktygGXUnSaG8WLVvEJzVE96Bdq/OghW5vD5n4rQndfXQ2b9RV+OU6CjGV/P1xV aLyVAdIPJdkD5T+Gx/UB5CYNtsqtOKb2Zuw7n+xAtkq2Lp19mMBEvNouoKuBHmSK VFTnXoWtJm9iSiD331cANCt+qodNjDofZsfcCTQdn9gqN2Udxw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwuju7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:28 +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 418NERT1012282 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:27 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; Thu, 8 Feb 2024 15:14:26 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 40/53] ASoC: qcom: qdsp6: Add support to track available USB PCM devices Date: Thu, 8 Feb 2024 15:13:53 -0800 Message-ID: <20240208231406.27397-41-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: w4lg_aZAydkbR-tEtmWgoeKrn3jhZpVc X-Proofpoint-GUID: w4lg_aZAydkbR-tEtmWgoeKrn3jhZpVc 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=948 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377045595250847 X-GMAIL-MSGID: 1790377045595250847 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 Thu Feb 8 23:13: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: 198673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517956dyd; Thu, 8 Feb 2024 15:34:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqOT6XgRuZfuZQDauNidvJuWYxATvsuWy1JsjtFilyq30HjAIksOlD72WiZqO4QO3OwJYw X-Received: by 2002:a17:906:11da:b0:a38:5658:54aa with SMTP id o26-20020a17090611da00b00a38565854aamr924756eja.12.1707435285914; Thu, 08 Feb 2024 15:34:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435285; cv=pass; d=google.com; s=arc-20160816; b=L5z/77g5UPswXr+BCrypVFjj4rA17ClnqqzVn1qCFKJjr3+G/ILnXRNVazW6YHTc29 C/S7L7qdDQUrrR/Hx6BMFzTk6x/veS9PA5w2JaDQHQpux/mhHpLzyzkYMVbNc8kmHAa7 dhWYRPKERsne8lr8vwWGIEY/fimqqvsmL8MLRQivtFI4hPcyoqdUKdNfCA+aRmVGqF+u moP6tUXYqB2r6B6/VJs/aYgGBTDAkZQCoH76miBI7Sl+8iEnDryRynS2PWZ1P8h4a20t qtONjNpLnlFOdQ0udppLAV648Wv7EV8xbmBD5I7Tb3/D6IkYMHhgrVcBFUjn0GlPFxun DWVg== 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=/sTR0p9zlpS7eU37j5GfC+kimrOVjLRydHUUztF1zZ0=; fh=6vGHtAY++xld/oA5O3T/vfhVZpCGOZqds7/bXt+/g14=; b=D280naFkiikh/CIVfAhZgxVfuxekD4XUo/NH9qeFANHB7udLysClxI4FmBuG6+etkn WzoFDofa/qWTsW4MsekZv2Okj2LfTRizyDR+TiAuvKkH32kGctOfx/TuHwiqnhcGYGyM s956i22Ex1Ewml95hhLGiWDmU+4rkCbjPkqEFtFdHM45Dh0W18mpI+727Z9WNXO0sMIW +K94o5k+P2GpqWFzPQZNKRJ9zfnz47dyoLnC12R70tHuZy1pH0ZGB/NoaQP+zGkeOpJt jolvj+yW0Qi6R3nkhPSekCJUFXWrVfbZdQFyE+t+PYS/kkoXD+kk2OKqkCVCYr3nU1G+ l7jA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QlZcP5CD; 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-58847-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58847-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUsX/qolC7CYqbUPySyEWMwCO697ezuczyNayqkqxlggnkDx2azGgopuKLi8Q0ogprOYnejj16l8JQqUtLXDRT6EpugTQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j18-20020a170906279200b00a38273c1415si166066ejc.275.2024.02.08.15.34.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58847-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=QlZcP5CD; 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-58847-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58847-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 565021F2450A for ; Thu, 8 Feb 2024 23:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF99960EFD; Thu, 8 Feb 2024 23:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QlZcP5CD" 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 18F2F50A91; Thu, 8 Feb 2024 23:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=mie22rX444gJ20m0wSRHQPgAKfIvU/INzYk/DLIM5O8bUbYIj7yfwND6NJ0SLzcj0qRe1RfBASCCgDJoSpmR+VmwRbs0s8yfFYmF1FuIzJdQkaY9EbgpniD4gDGKztuQaKzyz+sOILiM5S4iLwojPqUCqyBOiJipHVTbV6DUTHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=dxm4+VEN51l4gmeKDtMJd2TXPbMeemernY3Jm3jbXQE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dzqvHO74guoPk+SSfENnY+qiIxy0ah4kJF+dXZbu74zZqiX5ocTnZGq7ZjR88mus6nGs/xvmTQmiBbSxJxd7ZPRMXzWLs9Eef/6vdi4wln496zJSNdTZ7u1KWxMmHkagHO7rFpighgqXOKpjKQsZ53KPU7z1MairKUhCv44suuo= 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=QlZcP5CD; 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 418MHZDd026120; Thu, 8 Feb 2024 23:14:28 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=/sTR0p9zlpS7eU37j5Gf C+kimrOVjLRydHUUztF1zZ0=; b=QlZcP5CDZmHFWxFfULldSBsqtmO9eaorSk+B SJBaEm+ulcE++gHF4GDI6SUruoDSkCspAAeptH0jvgzIDAOGtfRqHkgqo55Duwpx DC+laR7Tr9cn8my3bHa6pUN9pFeZM8MYibNbbh+rTwsa75tuz35uq+2RU+i0YvzQ 1ezvRztKejfQQc37RWST/ZqkaCzXx62UA6fIpmkMQCqPaSwMdyP/VWbPZjLpCHBF /p4J1Gh2Juto+8Eg/ewNReoEMOJeVF+TJJa1HRAQv6sxyVK1JUmOF1YlXACV5Tb1 jsriPz3XWUq4qoIyOBtDFuPpIkdznNxgNKP8XhpfUxk8Js8Hpg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:27 +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 418NERiC013186 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:27 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; Thu, 8 Feb 2024 15:14:26 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 41/53] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Thu, 8 Feb 2024 15:13:54 -0800 Message-ID: <20240208231406.27397-42-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: PUKlfc6x5ILTNzz8LOwrSeJyB5PM3q5c X-Proofpoint-ORIG-GUID: PUKlfc6x5ILTNzz8LOwrSeJyB5PM3q5c 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375661987864681 X-GMAIL-MSGID: 1790375661987864681 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 'SNDUSB OFFLD device 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 d9fc83180c56..20d7b32bba07 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..c568c67e3e4a 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 = "SNDUSB OFFLD device 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 Thu Feb 8 23:13: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: 198666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516833dyd; Thu, 8 Feb 2024 15:32:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHzmbuSTuxohaJrU0NoYRA6bX8e0AnLJQ2o+uPkaBnDNuqIaMTgOPM8HP6qBdoRTiJKRQjDIwbpJqPNT1pR5zNyJ8pfQ== X-Google-Smtp-Source: AGHT+IG6KOD94U6r1LQ2/WxitPcejMk6uH3P1iinwAN3TgCjQ42HB5q5HcyLoa2eWKOsWB8/BR16 X-Received: by 2002:a17:902:d547:b0:1d4:dddc:d38e with SMTP id z7-20020a170902d54700b001d4dddcd38emr844506plf.61.1707435124807; Thu, 08 Feb 2024 15:32:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435124; cv=pass; d=google.com; s=arc-20160816; b=uFoqhLaj9DqvFclg/0lr44IuK3b1yx7j30RHfKL+Hp86imrQCwQYUKnYEhM+0BubaG 832kdsAlVNYtoXt42Af/3sTaOj3athl3ikJYuH1q6sQu+7qu2+YIr+0k+2IEC5Z6XNGy Z9G3MAJAheDLBjrOTDcQCi94StM7FfLhqPujON8V3G+zy0bO32HPX0qc6gPsE0JWp8UO Fh1nGVFaX3iqM3liTkDpNJdLLTHtQZG9dayzDonKa+g4+WFAAZsU4HoAF4iLEabzcZNi Q17MooCuLSwHqKYsDO9+0MkI+3hKUUpkWSeUh24lv5DEMMR0CPsyqkT74HuTy0ypy+yo +WCg== 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=bqpoeBuh+jxgeHkWKgZnYeBlWG3JJNayY5TWufBvs6g=; b=ethQs+Glq3THPNLDVDj4XNRdbqT/Wxwg+GKmkbZ+me6OqZyI6zrqY+3fA8WcTmvsFS MncVPoTV13NEQuq1KY7SbWcUc6ap4S3J4HsJLnS/a+I0IaIbf5hpPb7wcQZKvRParWsW oMVwvHav7HWDWMHqrOQfO89zqJ5vNNFEst8A0YPcP4iO78rSzcyrWqC9MQbL4Mb6TAwt tI0Dyatq6KinmUFpz5v0avGlk2yCWOuZyghhtS4MXdBRYOSLOklFPXFri/GogYI+u2bj +tSHM55s8b5ek4N6c9884FXQyihxG9GU9kXwAUZvAylBk0vATGjrvyrEFwO17DDGow8G QcNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YJJYtLfv; 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-58840-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58840-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWQmGKhSiRD3ytaTN4IKH8ViHgZqsWKfjGkBBh1I6g/PmXsG84DpZDqW6p0RgZDBHvMsDGDytsCmaWRvW1IkMSoVWGJ2Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f13-20020a17090aec8d00b0029705a95d81si604728pjy.36.2024.02.08.15.32.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:32:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58840-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=YJJYtLfv; 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-58840-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58840-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 E771C28393F for ; Thu, 8 Feb 2024 23:31:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2721362811; Thu, 8 Feb 2024 23:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="YJJYtLfv" 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 95EAA5026E; Thu, 8 Feb 2024 23:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; cv=none; b=FX0ag5bCiZ+Mkn3iq8R04/Lr4NwpydrrhOdUg9SPQizCIzqC9Q7jsJana3SShCGRrYOVMmtSG83ASe4MBwnx5ht4BI+7bjCiv08sAeSAIDtlVzNf5O9DpcNYQBimM7uF4vKYLcxsYJgIk/M32QAkh7JaJDkbSjXzX0EKLqVTKkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; c=relaxed/simple; bh=WD2aYO20Jj6ylAcciZCsjRR8imXLNE0xsGdkB6cKWI4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IFWugNUtrIS0XfztG7Iri9myeXdFlMcdOdcLSW3EUwyCfVhK8pl9aN5uWkpq8aYBMgqgWvujD0mD8iPDOhdU6kK1l4054B9/6jg1lgZof3v5jl2KFnS9n4wBdBZlux1ky76mOJoDHjQeUDOQOtrpFUkFhH7gHDol68Wp9ygEKPU= 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=YJJYtLfv; 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 418MslHe009997; Thu, 8 Feb 2024 23:14:28 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=YJJYtLfv6rYecfY1vsi7jy/WfiWHH08mvHeR iIuF9dPF80y2AvhQ7ue+WZ/8ORBpgvGWHoCJeeGnXyS7SnRW5XCY517qRU5Nu9SC 1eVDpCKH9+aYHty5mK35K/XkoXmpkYBAUz/04NipuDhrBNT/t6dCE6ujGIq89D47 aZzvybMYp6CWSpAekVz2rOAX7TkoF5SbEkVS6H065rjBO6cnTA1ckbWB8qSLvtba NJLolKdaKsE5CoLmqbGICGHS9bY8YuZQ2Cr+55S+9G4r3qFXAG3ZBu4bYxBWVY6V NAcovEUggrVXFEGxuksIvgZ1AMr9OW6ZfglyCjZiCUMfDIi+QQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:28 +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 418NERsv005633 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:27 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; Thu, 8 Feb 2024 15:14:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 42/53] ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks Date: Thu, 8 Feb 2024 15:13:55 -0800 Message-ID: <20240208231406.27397-43-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: dZtBKbQ_ZcKW5hLsH2PT2b45Okq8DfBj X-Proofpoint-ORIG-GUID: dZtBKbQ_ZcKW5hLsH2PT2b45Okq8DfBj 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375493615180929 X-GMAIL-MSGID: 1790375493615180929 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 Thu Feb 8 23:13: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: 198665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516806dyd; Thu, 8 Feb 2024 15:32:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXvqsNwgNfaRii5IYU2xzaIUYo2LXRxY9gPJmtE2xzq/PtiQUfFMXhEjiyq7+3FF8uGdzPFM6nzrPyf2guDLi4UeWnyRA== X-Google-Smtp-Source: AGHT+IEQe1vafgfJiJErL3zPnnLKw9oqpR3wuBeRhJ2y24BUOJSSYqdaJAcLfjaJPayMiFKSsugb X-Received: by 2002:a05:6e02:50c:b0:363:bb5a:3329 with SMTP id d12-20020a056e02050c00b00363bb5a3329mr109536ils.1.1707435122282; Thu, 08 Feb 2024 15:32:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435122; cv=pass; d=google.com; s=arc-20160816; b=OoODKaBRClmy+qQuVDd80tCB7GScICHC2Wl6NrNFIKXmUTmdCxjNgfjUgmu/jfMABy Kl4z4fypTNWtOmE2CjsgOrKLODxF7wtYIyyrtF72+Sx3YYEzprxZJF+5qPDv2RNeIS1P KgGVrPdpFdydmCrNxVrxzDSAgJ/ow/QPx8HZ2pOAPMVNdMQ1es4l2fHueMetzog8SlEy 6r8fLJANpPuDHvsCuJD1emTV8w4pqkUNapnV1rHQcMP8Qli9vWFN0B9WgB0yRhViQB55 VG9qPykZhsbVFeGA5x5qyIOhR4OZLkuwDl9BHHBZaJ2VUL3chcYdij5Hv7BTIFBhveEd ouTQ== 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=60ObKyG9TuHBxrZeqJMrxbRUfxtLp+1tF0A4Dzl6/6A=; fh=lMpWYdJhwbanlilmP0aFu4ZPcOXl2q0MHFo/wzNZX0s=; b=zZ7H0mis1FDMjq7hcNKQSYUpwzvgjHfzGd8o+GZjahpOcvRj058HxNgJaGvRcVuHMt 7bjSg7Y1cquiCXMqnijvP8mlK1LacoMhBFOOoyNdJxRF6EID57IxzKXna++bEh/EYOCR pQXNd+B6nyWpEgN88jWi7W/rCOTzem+J3zr+l9BxlzyDva5vVFKbUbGpA0j5Mkbw6/Zo ZPQ9U3uQOx9nfr45o+4XGu8vQ43j6CTmFf53Vbtp8Pakfd+Oh6LY4L0FhUiGrcUZLYvo ifwep2ChmpchAXE9h0qWVEF+oiDx6IkdSr9s/9UtEbS3MTvn1SAzIWr66CEBUjQdLL9F oo0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=WoWB6ApH; 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-58836-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58836-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXYSmzqxY9ElYJqcz6GJTdjYt76URkyGSjzt3orDQdadOgwWjqDAgZ/zZ/1gL+/hwWarp14R6y2zZmsmjojB5VopHWBzw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l7-20020a633e07000000b005d8b7053268si625724pga.5.2024.02.08.15.32.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:32:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58836-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=WoWB6ApH; 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-58836-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58836-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 B928F282EA3 for ; Thu, 8 Feb 2024 23:31:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF100627FD; Thu, 8 Feb 2024 23:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="WoWB6ApH" 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 4EF6A54756; Thu, 8 Feb 2024 23:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434089; cv=none; b=lgMAu5QFes80CfyNTUEop8ZfqILwMrlmgNJjSTYBmRu/xMLKHPb3oV10RBPWdVB4wfYX4ItB1vEG4PDfJJMA5fJ9yy5bJM1RFVVqhM3luDUWkfEX7YjYWjjolvG7ImP8uIjDKqFlcZp87s0mjKgGEIVquSe3/BN3mdd+QqAQtN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434089; c=relaxed/simple; bh=XHbx/v/TuXqw8WQvMgvyY6h+6CwDlT1EQepdFQ4hDLM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nvvPd1/kgKC5t9rYZXPek7OoygLeqlbFM/mtIPu9R5Oz48rG9OFTJlDI7c2/mXti92RvWghYw1l0PuGNNvDoJ7eTSiTXPLVqS0hniuXW++n04a9jFYkM8HW1GTTDuDtEUR5WVmkCJeqz1ScohER+vi3eaTnY2+lEHU9pjNQpjoo= 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=WoWB6ApH; 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 418MuafA014286; Thu, 8 Feb 2024 23:14:28 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=60ObKyG9TuHBxrZeqJMr xbRUfxtLp+1tF0A4Dzl6/6A=; b=WoWB6ApHQF/PedLCC2HZcwweOkn2x39XU5i+ vl9E4HCoUPTfFxjuB07f3H3OqD0XcEh7ZVDoDJdozWib6xPejk7kTUVA0ZAlRBrN yOgteZP4wWyhKML5pWbSEhK0NyWLpo43Q376TeSZR6re/asPdCKvpxj1cLB2l2pb IX37xeNYLb3t3zlxzvi3TsBG1pvY2i5xojl4l7In6m80OdmUxUC6OdCBh4ssRZqs PSrcCBCGsZaMbLPC4BSF9QKLYkGXEjnGvwClrgRGgaHQgTkIb/NWj9RQPEQVqWxa Xt8TFH+njXyEGSWD5QWjkQ9mGNJM5EXHepUy/tS1nrNhmhHROA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4wbvhn29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:28 +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 418NERaJ012289 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:27 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; Thu, 8 Feb 2024 15:14:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 43/53] ASoC: Add SND kcontrol for fetching USB offload status Date: Thu, 8 Feb 2024 15:13:56 -0800 Message-ID: <20240208231406.27397-44-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Eg5OL8_s-fpTnL8DEFlAcA5nAj5huvEi X-Proofpoint-ORIG-GUID: Eg5OL8_s-fpTnL8DEFlAcA5nAj5huvEi 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375491018587256 X-GMAIL-MSGID: 1790375491018587256 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. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 27 ++++++++ sound/soc/soc-usb.c | 150 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 175 insertions(+), 2 deletions(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 20d7b32bba07..c05d9b2f5c90 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, @@ -50,6 +72,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); diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index c568c67e3e4a..9c082129cb9f 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 = "SNDUSB OFFLD playback 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 Thu Feb 8 23:13: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: 198670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517666dyd; Thu, 8 Feb 2024 15:34:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6QsG4meIVj+w8+f4ksbxMPhkHwKPOrwaV+Cb8pDqJwTMTXfDl1zWJJQcrnQa1YBtUFugK X-Received: by 2002:a1f:df82:0:b0:4c0:1ab8:ac8 with SMTP id w124-20020a1fdf82000000b004c01ab80ac8mr97792vkg.3.1707435241014; Thu, 08 Feb 2024 15:34:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435240; cv=pass; d=google.com; s=arc-20160816; b=t/SVs1UiUqutZe5M7o9pSAAey+NvnwiLj/4Os5M8SFluua2DDVH81ii9fcguM6K8+0 3BFtGJBXSoLTonzjAs/OkbXga2PpIhFnp127Qv4Xcze2tySka8PqF3rAJj8x0dZOOhq4 AcT2V8JpcTgnPh7hzV7pEPIR6mUxyRVvJUIabUIs9GlqvDno2gUDx8ZqQu6GFf7fRqW3 PDavkcl1jzOv0RwWL2usgaZI+HPYPUEW7nfRzZ/nqGvU9PQ3/3gq5Z4JNgFFfVRyLVRJ lgxW+/nyJRP4AFCQPh1n3GVOt12znnKCYxBXwwyUepO++dAX1uNWHAR9+/QwLrGeCmZh HrkQ== 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=QJ/hZmsw1vzyBP/94ev68V/7RHa4ICZrgHskl2HlgLs=; b=ASnhFsd2eqvWmnbT0PFlFrvXBxm5tfIw2bjJ5zIGsYtxpX7MqPdmVSGc5cvaw1RrUQ QSvk40kft7+4ylkTf20t8ZNXvc/3QIyXC0akvGvZOToU6HpuLkdgbRnjO+RKhxek7H36 ivZ/OGXa1aXlN5oWmgJxAOj+IVHItriPsVRI7jaj3oZUPGv86jKWBevegs+WF6nW0T4l JKXYeVoxna2Pxctrpq33/YXprNGHyZjlBNxBJ/JfCB3xNpeZZ9EOft0Xv/CokhCch+AK HUUe74a1uj2RDG9kEXnSO4JAhVpvItDQDYOeW2J/fOZDAJVW/VxeCxcMxFTZ9EPpA723 OqrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=c2cWnabg; 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-58845-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58845-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWOCo+kdijdk2McKX+91MFV7Y0Hk6YmeNb4vsUVQM+F7XEIVqhYwFFT30VVd+QPi0YTqRHTpVuhAq67EpNou6LxFFczpw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kj7-20020a056214528700b0068c65ca8e3esi673880qvb.143.2024.02.08.15.34.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58845-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=c2cWnabg; 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-58845-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58845-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 B5A5D1C215C6 for ; Thu, 8 Feb 2024 23:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 987EE657C7; Thu, 8 Feb 2024 23:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="c2cWnabg" 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 13DC952F94; Thu, 8 Feb 2024 23:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=sIAmH2MmlW4EpNj7ZmHXaJUCUdJxy5p9bgeFwT6H+DzJd4nkVdAEWFcvKUIDblNnPvhYJdOGoE2eo9d2y1K8kr7ujsCM3bWA3GrqPOmRlvrcNvXUUnk7mxS6JHHEaO69DyH0uMY7cazBX5rTE9VoHeLN383opuOGqb4MD0wD1Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=RtmQaj8NkOIBrQYRKvHrCqtxnDMndM5jafzZvCboeCs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CU7mLUhyetQgquytpdGaNTmOHL80reibq7k7a+Ur28qDgzhclpljHGEElB8f6r/p5p4ivbHW4Yon09C3lw5LvwEdi9q5MbNsnsZSJdVzKZWkDCh+miLh2IRbX2WvxEat74qovKAeYr4u/oIHhunIcdJZVBzelDqoLXRk28e9kRE= 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=c2cWnabg; 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 418MFqIM022116; Thu, 8 Feb 2024 23:14:29 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=c2cWnabgoyrRqmiIMVLN/dRloJgomExyfbdP Z8lZkaEIGVQXFU5/6CCCmS3l7esNYTGIv7sjrvi+NQo5bFNQpX4FBn00bUmV57OQ hb05hUsfnyLZHXpJdSMSovoZ/fzylR+kqkwck6ipd2NjQL+WYbtBmuBCVAEgV7Ky c8IdQNMysVThnDpTxnasc+oEwlSLM6ZUjNKhoIpf7RMvPhzUtZFBCZ6f6OJNlhhs eWXcdXuYbcxdA23TQqD3Q0h1dIaZTBavtQ31Lypnv6IN1N1IYKExxc0dw5I5ObLF OGbFW0DG3A4hMkSbTH4u0tVqo7nCGZr1FgTLbu6PEaf+v57+Cw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:28 +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 418NESnF013190 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:28 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; Thu, 8 Feb 2024 15:14:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 44/53] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Thu, 8 Feb 2024 15:13:57 -0800 Message-ID: <20240208231406.27397-45-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Zi5kGkVCl-qkeoGQEZG27HTsVVobxTji X-Proofpoint-ORIG-GUID: Zi5kGkVCl-qkeoGQEZG27HTsVVobxTji 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375615411964999 X-GMAIL-MSGID: 1790375615411964999 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 Thu Feb 8 23:13: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: 198669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517549dyd; Thu, 8 Feb 2024 15:33:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwY3UjhFyliIKtf3+ps3lXn/ZbXo2BSyB3/N7FudaGOSO4/Jcfy/3xq6CI59yo7z30HQjr X-Received: by 2002:a05:6358:6f9e:b0:178:b9a0:fe9f with SMTP id s30-20020a0563586f9e00b00178b9a0fe9fmr728760rwn.19.1707435224179; Thu, 08 Feb 2024 15:33:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435224; cv=pass; d=google.com; s=arc-20160816; b=krqbYxC6ltPoEMS9AvWtVw8hU4V2BU0l8ASMLQnbwrD57I8W8WXWdh2PcRnBsapvFs vGGGt6zinhXAonpt4IsvE3AXF2j+3/kgRT9NbmAd/An0+fF9bI39lEKlKNQg6jVBM7ee 4R3bXC5tWAgiNx3sS3wm/AXRZiiBpjRwxqsCM6KWkZXttwXTpkaKM1fqWtF9K1BaGGl/ FHFcJ0g9kFX0C9uaAKAWw17oabO8Ftepc53WiI41SZhTvZSV5b3XyWLbSYMTwJSTMk79 qITdC/ZELioYayQJ+Tgd9wOxWOagHuS0TR4MytzzKh2PN82Hi0Ah451Sr/aeJ/AjH8lD Ethg== 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=EzS2gn4U4WnO6HUj0UC69z/Zo5B+U25eLv0bGKq0HUI=; fh=bcdD9+ev54RVSrR9qIPP+WzEFPNb1Z93cC9FkpbF5iE=; b=Zq7BiL6YTZVWMdwETGSFuAD6TH6FlfE9jZk8/wGRGmlO+tjYbum96fyVKetlocRoit vPNN7ylYOStue1wV3DlD8HFl/L+Cn1mXo4zZckgzkXDtGhySg1C95Iimb/WKF4j/M3AH rqWP1FP8mxfBTsFkvXJVhgS9DH/iKGeMSvxEiERLaaJE8oePujGjHyEHL1yySv6aQ/+z 8HX2aYRjs0JtEZpgQLP8kpeQh01au7eyCt5IJR9x4lgApxUNdRVNINHQSx6FADfn9FJ3 Nke381hucYkTUTP8bGXLPwDIf3OvfgG3Ar80skwvAQaKQ62X1t7L30cZrOyrV2hpW0K2 fj2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Vq7e9dh9; 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-58842-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58842-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUYS+FVlAKIaMd437ntYgWemFquffCSPncRVr2lwSi/RrDMdZ0sLX60TMkukCoMCuuEi7/X5YPxTbLL+U6fNqH6jfLf0w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l29-20020a63ba5d000000b005dbd5035ddasi587336pgu.275.2024.02.08.15.33.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:33:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58842-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=Vq7e9dh9; 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-58842-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58842-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 E42D72811C4 for ; Thu, 8 Feb 2024 23:33:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CD19651B7; Thu, 8 Feb 2024 23:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Vq7e9dh9" 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 AC3CB54FB0; Thu, 8 Feb 2024 23:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; cv=none; b=B4J6EOsuz8IsNQXZhXGi8kdgQfnMLqzDkmK+icctKUjmrEAUJ2btwjH0QSIciV1/0XHFk7py+MQk1sa1winjF6bX4wyaGnYV/rG5uBvHkXji7Jhgpk9rECds4sUkCJVCc6F50Xa+KOlr9M6ASLMTUb2vvyTB0SZabUoo8jtisrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; c=relaxed/simple; bh=kCI2wpxHS2B0a8rnreQMrTdOsnwA7+jL3ssXaF27uaU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FtzOi1Sl2uqAjGQP2QSu3f40uDj6gun2mSf09zue87GRTLm+ilMWeYtj698ITBDtAUZhM8OhaTBMlFfTMaCgVUD0bjjPYfUQnVhlYKDvUXwnpiPeqkaWmDc7NtoPO8mklXA6jlQusGkzsMcrcxMwH2ZWrnNYF/i5PKmU39ozPhQ= 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=Vq7e9dh9; 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 418N0rmX025969; Thu, 8 Feb 2024 23:14:29 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=EzS2gn4U4WnO6HUj0UC6 9z/Zo5B+U25eLv0bGKq0HUI=; b=Vq7e9dh9cfW50sAun5tL/amCcCfQA7CdG8cW A2BXfcmuiaNRSuDfRPCFbYxqmZ3agMRJRzj7u7BJQnDoe50HdGBB5EhChj/oOwjh btUc/nrKUub5kIZyrbwITLJi23/9X3o1smJlB4QLoZ4ps4sViW9tMQxGRGGJxx7O 9mUb/Yy3AjQwdiFB2dmlYZSNkcsNL7OrAfp0mK9sCKItgjRLYnNlhjrsRdYKmztX TgWGc9TihAQAIC97mJTzOyUI/rGCbX7mKn4Y0e0IVJvC5/NysM8DkYQWaZ3tjvcN 9yS0F2hNwTsjPGtHtv4byRgiqr0PT8puwEK2CKNLIvuugG1HWg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:29 +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 418NEScr005639 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:28 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; Thu, 8 Feb 2024 15:14:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 45/53] ASoC: usb: Create SOC USB SND jack kcontrol Date: Thu, 8 Feb 2024 15:13:58 -0800 Message-ID: <20240208231406.27397-46-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: fnioLAMqjAzfQg0-pZ6w1c1JU1bR7suu X-Proofpoint-GUID: fnioLAMqjAzfQg0-pZ6w1c1JU1bR7suu 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=725 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375597959469588 X-GMAIL-MSGID: 1790375597959469588 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 | 4 ++++ sound/soc/soc-usb.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index c05d9b2f5c90..e07e83d86a11 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, @@ -76,6 +78,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); diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index 9c082129cb9f..f22fd1b6d294 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -4,8 +4,11 @@ */ #include #include + +#include #include #include + #include "../usb/card.h" static DEFINE_MUTEX(ctx_mutex); @@ -42,6 +45,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, "SNDUSB OFFLD 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 Thu Feb 8 23:13: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: 198667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517279dyd; Thu, 8 Feb 2024 15:33:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjv6Hnkrl5JR1FRhTGMMMd9o+J84zsdIK4iTvAsOHbctusvlIxpEPw00MzJ2SlYKmyQMoS X-Received: by 2002:a17:906:6ce:b0:a38:1938:3d41 with SMTP id v14-20020a17090606ce00b00a3819383d41mr521700ejb.10.1707435188549; Thu, 08 Feb 2024 15:33:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435188; cv=pass; d=google.com; s=arc-20160816; b=XT0KWiGOoTiu/QW2mKDD62Yfg0bysn/dCdualAiBSKnzZLhtr+lcS8/EwKB1AJAqMV R4ahpcar85XiA2Hr6CXfKlY1BX+8svETOP4l0qfJPduCh+mAe2IcMeyD9Di1heKswIXG mze4EWBjqd8lfmHl65REMUin7X160voAZ3P64gxscwyI/1YBPoXRvXfhVD1KpE2MBn8O IMN0n1gKKwme367QYuujr3E+N9LDztwq1/06A9q0g1BLyptriS7C+HORk3CVbMNCWA+J IF5sKAM0dk3vGwULEvhv7etPGroUxtQtXFz0fN4oIWNk5bEGflADSK4mT408eGuHs0nA lLvA== 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=Znh46aiTFxjHHa+/r3tY9J/c7ggutFIZ1wXq7ru/Dj8=; b=0ODFGMheGonD7Ih1lSkYRvENU1k5WLFwpk4PQJJXjjGyYLA8/GMDS1Ceh8BTy+1Oq+ btQQy2HLiopz8QL3YnroU259y79yGo4Qs2fzfKWGmji9IIDVQi6WGc4/EoX4PAlTgWIk 5/cOtMwT32ogHgDLUfEXkMNpxH9VYBjHswK1WVm30VDeeH1ynI9GZjhp9S/TZlzqH9C7 CdSzq4dEPPi0H3i4CoeJf5uuhymOTFxoD8sjr64KXzHjNtr+rRlD96rM/++uy+Y71yHx h/KAKPuENB0z8icjXF2Uzb8d5ulNBMAPkkx9zbJAfhqOFfbucVVcFhbBXfZeb9i++8LL Bxog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QoUWbWgL; 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-58841-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58841-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCU+Tke+GvR19ry2QoU7ETzz9XOs/h8UmxdG0eru36vYu/hcTrPKa/wtd9sOKlyO3dwY38dIknSQtGLt0vg9I5ayd9r0oA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a8-20020a1709066d4800b00a383f1af140si171563ejt.63.2024.02.08.15.33.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:33:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58841-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=QoUWbWgL; 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-58841-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58841-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 CF5601F21466 for ; Thu, 8 Feb 2024 23:33:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D66564A93; Thu, 8 Feb 2024 23:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QoUWbWgL" 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 2E1EC50271; Thu, 8 Feb 2024 23:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; cv=none; b=X6dvxfcE5wnl8yND5xHSujExcKxGR4kuNYKE6lsSnU82jw9QcXQN0ANpFL3iIrxXt/mRCpHKVyPqk2J9SmhXQCrmVyz3Jljgc1EQmoe9k0u2Rchof6iAYMHVHqHYnRWBagb1J2ugeF1MbQDgogDrztNLMNpVZeC2QnMxSxbSLE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434090; 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=f+tVHSCsTyEzCb7o+xhFsEFdkF3Pj2gObsSvhWI8n6R2xbbMTdlEsfdWakfBViDmlb2XpuQuyRwau3OKqnbAs/2QrFkl2PBa6IwfQHCRP+jkZnB+2ImRND7G+9vZndTZHpQwSaZSg1gkD+ohT8D1cLGjDDGa4217UGcPUDmCwXU= 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=QoUWbWgL; 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 418MqJIs003419; Thu, 8 Feb 2024 23:14:30 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=QoUWbWgLkDj1FiuPpFEukyotGozkRQSTTnPq luJB3QFCsbawGkoSCswRm24BeRYEe+woM6kAX9AtcPVQ5kBcr7Hh2otvMVkurj5r VYTlPtsms12z6uLW3L2skYX+BYgcclPCxIilZtKxCdUW5BzRCDr5g+eF4XiHJNVR wte2gowOs852+iCprMwK8nBG+eeSH7aOQH3HV9/GG+T+vhCrTqPSEXBlov5g73Tn 0ohDUbfVQs2wj2+jVLyOf3QCUcIjLXBTetMzBwlXqQOKRbdyxoQ5gi2ygjj2GPZi rf+HmcsqYxVGjaRvcxa8f0YeJ6fOgVAQ+tW1x0q2Gpme/l6ShQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k55-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:29 +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 418NESDZ005642 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:28 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; Thu, 8 Feb 2024 15:14:28 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 46/53] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Date: Thu, 8 Feb 2024 15:13:59 -0800 Message-ID: <20240208231406.27397-47-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: W7lvUrqdZ15zQ1_lrTVWYR2LGo9XPvMl X-Proofpoint-ORIG-GUID: W7lvUrqdZ15zQ1_lrTVWYR2LGo9XPvMl 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375560082478077 X-GMAIL-MSGID: 1790375560082478077 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 Thu Feb 8 23:14:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517516dyd; Thu, 8 Feb 2024 15:33:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUK9uH9f8nHVArWerC+vyhOE3ky9sHYhBDSy8jjvnDpmRiEMVU5Mj/F7dsq5176y9/07AO/hWOkqu1XnZ1n5XYgs2fTnQ== X-Google-Smtp-Source: AGHT+IH7XpdZf5IGn02u+/tH2P5oTi9SJcS08nT5c6MeZYgj3Tly4FiM6yAaUx+PXFlmpLqz7FYC X-Received: by 2002:a05:6214:29cc:b0:68c:3f60:f09a with SMTP id gh12-20020a05621429cc00b0068c3f60f09amr892148qvb.47.1707435219638; Thu, 08 Feb 2024 15:33:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435219; cv=pass; d=google.com; s=arc-20160816; b=W0pPR+62bAC7CHba5THoqinLYrOfrCMQxhMloZBT8oXqjZOsu2LTilzom8AjZcBhsO 2Rm5VUIJG47lVETHUfEBsI+SjRNIxAHmZ61lWdhEuwofXWo6BGn3gf4VPwr0oDqyp6V1 D8uG2e84QPwFP44QOGhT6y/zZ7UQ51P1zQ9rP/aZkKdWvNRbWPOs6OxDmYKeg6/ynOQ5 F5phNfzChXW3pK3r7+YEUonkYR5cuwnFpQRIcNElTSvEbFZuMrTZhcRnzS5d93nhvppY rwmDi0BGwotD8g3GIP0FEC74GGBpTsgrBD6RBCftmdXUoLnpIxQ5FtQ3IgX0ORUGx3sI 4dbg== 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=4B1k97XPpHND08MwaSfKILwcn62znRNXke+S79WKkGE=; fh=o2dA1o3ANpBWfgZZVNbjXp6bRi94P2QQ7516FhgnTvA=; b=CdfoLohBwk50G1nkhCx9TsIn9gJf7+NlRo3HljmkMSG59nOBZwo6b8Ujub5CIhhGA6 sHjFc54GveWDg8fA0/7W0qFJVhkbTnuAB6RsnS5ABJzKQfiTsGrw7HobtIRyZIAq0/D2 lieBB2r7mRCzOJP01eev7tgVawO68Jz7chHpDbZAWxVFlek/94j2qIK7JTL/GHMe07nV 3F/Bxi+7xAZkON2iu3ygpHePp0VMxHa2+7UQWc42zQs/OyPqgy0RJD00kv0uH+X1zUm6 v46M2K+8sKFNjXIFRJKxqll7PrVgqtvPpbO5w+AoCmdidRttV4EqDChTimWFq3IuHSBT iBJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OlRn4jWR; 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-58843-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58843-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUQ6uWeqsVOsAueNW4pyHb+kT7WLf4mjyjxpMUaU/8EP4/PrFTSOA1DGDIcP8cour3pdyaioY0moXlXas1EIa2Go0QQGQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jm6-20020ad45ec6000000b0068c3a96d43dsi677123qvb.218.2024.02.08.15.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:33:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58843-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=OlRn4jWR; 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-58843-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58843-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 5C8171C22091 for ; Thu, 8 Feb 2024 23:33:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0599D651AC; Thu, 8 Feb 2024 23:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OlRn4jWR" 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 EBC8855789; Thu, 8 Feb 2024 23:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=NhvlCQzN+RE6d0Ri+eF05ZG68hVu5YosFvmYpyDlpnawhjHQ8QIgMKAyjYIvtzfa60ohYbyY7y1PF4icu+hMyZ0fd3EybLGwEGASAH6bceTtvvP6L/aKs4YwK0BsoNa93DVHkBQQcYle8Olk/9YvRYy4PR7kRHQzRxDy0306wr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=B2Uh+utLRUwvSvG6gKYDBbEMdPWEQKJy4Vy8UpaYpEg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jBMm+ouvqPfJh2J07E+AVOWSB6uVNWqEF/VKJ0CiCoNt8UUWJTO4IOeiLoDR1KBUXTqiwv1yg0GMUTy2rSlmdjNRrU1MWI+e1oM5Fe3AACy81B2uvHlRqZmG9jM0d9E+L2eV26cRSLV8WKgl+NKSBw6f1o7drwPRD5YbbV8fKEw= 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=OlRn4jWR; 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 418N5MTS001374; Thu, 8 Feb 2024 23:14:30 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=4B1k97XPpHND08MwaSfK ILwcn62znRNXke+S79WKkGE=; b=OlRn4jWRXEaofllDuqqK6MvKzh1WSh/ZZPif OHSKr3WtI5WI5Qdi88o9rCVLWOMYN2ONI4UynXevHUnEuACtCvRkLyBBuMjV80iX GOAIIFlALEb4ETMdfOMvd3TLkqRxpaINOvOqQeQDNpB5+uieVjTju1sQfkb7HN/u RhokmWYKCbj7hjX6nakoZV7giOQ+H4KWyrZSSgZbiCbVBiR3kTuNYiQ4tHgoKkXn +vfnRJHvwNEoJ8n1KNQo7sLSnSPm3COw6UfT0ta06RqXnqi9En1dz+NGjN1B06pC HwFXYeZKTdClWD8WL6C8gXMezKeGTQrMXcy0dmvrCX3ZN+sz9A== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:29 +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 418NEStl009259 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:28 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; Thu, 8 Feb 2024 15:14:28 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 47/53] ASoC: usb: Fetch ASoC sound card information Date: Thu, 8 Feb 2024 15:14:00 -0800 Message-ID: <20240208231406.27397-48-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Ai1V8jvH3MvZ9vwJj9XYdhdtTauEDGz4 X-Proofpoint-GUID: Ai1V8jvH3MvZ9vwJj9XYdhdtTauEDGz4 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375593039579216 X-GMAIL-MSGID: 1790375593039579216 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 | 1 + sound/soc/soc-usb.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index e07e83d86a11..443c53419295 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -73,6 +73,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); diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index f22fd1b6d294..dfd6f53898c5 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -340,6 +340,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 Thu Feb 8 23:14: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: 198678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518232dyd; Thu, 8 Feb 2024 15:35:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuL56xIJF+k8czWCMeroo/RpaUqzP64TzAOZB+mXCKBApixEDDxUfVxSFakeOdZQwXMXE1 X-Received: by 2002:a05:620a:3902:b0:783:ae0c:5e8f with SMTP id qr2-20020a05620a390200b00783ae0c5e8fmr1342856qkn.71.1707435327559; Thu, 08 Feb 2024 15:35:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435327; cv=pass; d=google.com; s=arc-20160816; b=xV9Owx1bPWJ0pMrfU58lhqh04+mAG127b5h0BhkrMO50VpZT+04BGOo++O8f/Vbvlz w/WDdaRC4b8ukMMLjGxv+/2chli5zDjB1HtR9Yj4fHpJbd3HSzB61tVp61qBlObiZgZU wjZq4bn06mUoHfSgTVbJWE8pAEeNfWcKGQTlEVfDz2HFc7nain3Lch/CuyJVumQfN5l9 4Y7LZ3RnanPK4SGtCpEBPAkhd7CuHCVskKaIcPi5eBPjlMsIf+GrLtqo14hXe1VMtkFG 6UMEFguCnM+acSSbkVHHbuM3O9EOvpZrv15JOxLbEhBzc92uutKzwALHhPww24omsPiu FdHA== 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=6MDZdz79HYTo4EmUJtI2TotOggbgYgDt+zthz34wuRw=; fh=fcnAqnOxFKuvI2gVuKkjl8dj2KiZr8A+0qEPrmeXReE=; b=fGgda+a1a7NdeuRmGFqdWXm6jRad8/Vib4jzIN/QOebeBC2unOynbJw8JS8eulupu+ eB8HaupPSuvj4+JSjzRjpUNuKRYAhVcEe4gHDL6XacVScWdi0C9cZ8M9PARoe0Pu0Zxd le0R2VMPRp9vcgTeU9IF9e4NZCWvDYPz3uHXlp19AYXsKqOYj/V1pjA2vqeZJBjCjqWi S6zUngStBaiWSoOA8vxRHhi2VA6BVtvmXMAyqhjnkw8c0iH9AqXDfgu6iEZgqrC+Vy9i asJvpsHSQyZzXEwjJlARSPhCvygoXS3N2oUzBVcZEnOyfxYHW2Qo1+hmuU4bznVianSW 5fCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JACMIod4; 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-58854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVn9gxycCh+5mlPxd3FCHknJQDIaqddXSSBYj35bq8shgMuJVlKUrU2Ya2wcWw5SSno8mSG3cP1Ez2hJD9tlGSK9HJ5Sg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s19-20020ae9f713000000b007840798bb28si669614qkg.240.2024.02.08.15.35.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58854-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=JACMIod4; 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-58854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58854-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 C713A1C20AFA for ; Thu, 8 Feb 2024 23:35:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92ECD65BBC; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="JACMIod4" 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 79E7B55C02; Thu, 8 Feb 2024 23:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434094; cv=none; b=MI3yjQ/4WoLgmnLOcD/aGKxisohbvQ7LphlfSUU/wp+DJOkgwjJxQrXS1cPVibzlaDUI7Wf70U3PvKvvl6z2CA39l8XJrI7nJXC/4Hr/HsGE7vl97GwiykajNWCMIcY1Ak++YQzX0iDhmdp3A2yYC1cQLFReWmTZZ5lcRHZhnl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434094; c=relaxed/simple; bh=1bLwLr0EX/0lvwIzLyQnWS6s7hCSGP8YBc8NPNbcw8w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BfRiFcfbJria6X34GCQ0gH2cCJMEsFkM5egbpUPQ5sD/3IMUWHPiq0l33bRazm9QWvtJh6laZBNRtKihABo/yH0WlKupcoq6Y/4mePV24NAfrUhfFQx8jd9fJyILn2hRq35Li2TBzv28tCQAGalUP2iHy4JhsGHJmcA5Cq0cBmw= 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=JACMIod4; 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 418N3G8k027491; Thu, 8 Feb 2024 23:14:30 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=6MDZdz79HYTo4EmUJtI2 TotOggbgYgDt+zthz34wuRw=; b=JACMIod45ACt+XoJzYnI8bXHgWPxrf/ThDRz ZfZUnIbQJsMhewume4mpPeGOit2aWSUm/DlFpu38qJ2frf75qXjAIcXFsWTQVpKQ vfAIbIU/gYd0Rkx8/8QYirW2A4jHrEi5Bs8uoU8WIsx16ntJ9ZyHx14ceYd53AT3 FyySG7/LBZeGLUpMEKZfv0Q3qEZkIrKwbdNUupbqh9VXJzYmn3WXuonBAzIhwKy7 nlvMNHCwK7bss17QdYL/pvJKfAvlcgL/dphvjWwVoswKs/9XhnG7sb3u+otgGFnt NeOyXVU368TCTUOcT81yB/fqZ6qxrOeLhijUFeobuHC/xsZDwg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2ab3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:30 +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 418NETpo005648 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:28 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 48/53] ALSA: usb-audio: mixer: Add USB offloading mixer control Date: Thu, 8 Feb 2024 15:14:01 -0800 Message-ID: <20240208231406.27397-49-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: a5yJ6nA3VQT2S0mNjM3lD1FT4BtXQGer X-Proofpoint-GUID: a5yJ6nA3VQT2S0mNjM3lD1FT4BtXQGer 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375706095552867 X-GMAIL-MSGID: 1790375706095552867 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. Signed-off-by: Wesley Cheng --- sound/usb/Kconfig | 4 ++ sound/usb/Makefile | 1 + sound/usb/mixer.c | 5 +++ sound/usb/mixer_usb_offload.c | 72 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_usb_offload.h | 17 +++++++++ 5 files changed, 99 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.c b/sound/usb/mixer.c index 409fc1164694..09229e623469 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -48,6 +48,7 @@ #include "mixer.h" #include "helper.h" #include "mixer_quirks.h" +#include "mixer_usb_offload.h" #include "power.h" #define MAX_ID_ELEMS 256 @@ -3609,6 +3610,10 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif) if (err < 0) goto _error; + err = snd_usb_offload_init_mixer(mixer); + if (err < 0) + goto _error; + err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops); if (err < 0) goto _error; diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c new file mode 100644 index 000000000000..61b17359b987 --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,72 @@ +// 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_create_mixer(struct usb_mixer_interface *mixer, + const struct snd_kcontrol_new *new_kctl) +{ + struct snd_usb_audio *chip = mixer->chip; + struct usb_device *udev = chip->dev; + + return snd_ctl_add(chip->card, + snd_ctl_new1(new_kctl, udev->bus->sysdev)); +} + +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_init_mixer() - Add USB offload bounded mixer + * @mixer - USB mixer + * + * 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_init_mixer(struct usb_mixer_interface *mixer) +{ + return snd_usb_offload_create_mixer(mixer, &snd_usb_offload_available_ctl); +} +EXPORT_SYMBOL_GPL(snd_usb_offload_init_mixer); diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h new file mode 100644 index 000000000000..fb88e872d8fa --- /dev/null +++ b/sound/usb/mixer_usb_offload.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __USB_OFFLOAD_MIXER_H +#define __USB_OFFLOAD_MIXER_H + +#if IS_ENABLED(CONFIG_SND_USB_OFFLOAD_MIXER) +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer); +#else +static int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) +{ + return 0; +} +#endif +#endif /* __USB_OFFLOAD_MIXER_H */ From patchwork Thu Feb 8 23:14: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: 198703 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp528566dyd; Thu, 8 Feb 2024 16:01:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEJYnr52q/SQ/SZGYFRXjvaqUQh0mjt27f3D5u3uI2joVrv5aAmbuhKkpvO5pe6NDL+Y9p X-Received: by 2002:a05:6871:285:b0:219:6ad2:3b8d with SMTP id i5-20020a056871028500b002196ad23b8dmr1156527oae.26.1707436888323; Thu, 08 Feb 2024 16:01:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707436888; cv=pass; d=google.com; s=arc-20160816; b=uOsWmCNCtwiWV7PMcz052e/fQH0xWMkd7LyGF/mxY7HjDQSu/77htCLoWKxbVY3/dJ tF8HK9irn06v5ms+ksYyaeYfDCD5MA1+4iEE6M2pIoJ+fgaZOxMIWa9BoJDSWpH7AyWG NjJL9BlDLk6m0Ys9Gaxef7esfDuomkC5Ccf4usD/ke+7haNnKTSoX5XTAs6qyRCRfY+E VTnn+7XkQFRNpSD4oGG6ZIaeGh5rkw9qJWaDtakXbw6sDU9YLR9sDVQMrebGi2spEbl9 MNWMICCopeWqcpDPBRRwVGXAfh4fsB712NWxiwyfZKVKnsOiB9T4hm1wCTTHOoiVk1qm wFhQ== 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=2epZr9ZtYhWfEyi+rsjAogaNtlPRCGTpOp6RI1gYLko=; fh=HUE686taQXDj/Rx1XnX3CuItxxL+l9ajkhpUV3PGhv8=; b=bf7DNwWfNO91eUvJ0gqbLfOszowSm1dNVki7J+OSTi4IE3ElSlEF9I3ueYRyMbFRqW i7KUljAzBRGfE6pgPWbv4TZQpI0mMFy4VUpGh2hj7f2gUzeBn0HxwbNj88qdyrXTxuqQ RaDdc1ikJYb16GCte8NQ8B02BjcKtlPSjQ3adUwx/LaDsfbvVtEgs2Mg2f0SFI1qbpmF UwDWeSqrXTPjbdk8RqRX4dmNGYraBOx6gIZnqD+AvxSJ4KONHDGsxqBauJBIyiqLFQDt 9FJBVzH7wbF8g3lpDmNXZ4ZWi1NqUkGa1xRafjlj18oojvuI9ZOmwWcQqJSSaaTJEs9/ l+vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IGhzOK9N; 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-58849-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58849-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCW6Asll6cVosYHaJTJ90GCl6781cMDp884Udmq6r7YHKa0nuuOQGmn/HuZMBxg0/THtZ1xGMTS0cf+R/7iMI5vg41VprQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id dq22-20020a056a020f9600b005cec90b9a98si587639pgb.835.2024.02.08.16.01.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:01:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58849-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=IGhzOK9N; 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-58849-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58849-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 7264FB2F0F1 for ; Thu, 8 Feb 2024 23:34:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A15E5465D; Thu, 8 Feb 2024 23:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IGhzOK9N" 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 E688050273; Thu, 8 Feb 2024 23:14:47 +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=1707434091; cv=none; b=i6XF7GQHpDVqkgmqyrqeqdCyW8ZZIMRf+ltuNdinJKoYDO/0yc/vzUZuGrMuN16VZlDCwO0zAK+bzPMjQtfqDeDZpg/Xq78RHWW5wNtha1hMhBZE6yQNcKhYIhN7Wd5mIIwh9MzLLI6e5uNbs+Dch3Kb+XoC44v1SnRxjDYycS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=INx7prBwTCttt9ewnnpDW+hd8zJyPL3YkoMtJKT37Rs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O//KcuXugQ/N1leZE5scct1zLi94SKofo/jYvzU1wjaRTCbzboX8MsBTPvbieQ/G5ELGin4EVRvE+vDhc0zReklZux0nW+vOPVbrunZWuEkehkLaWj6v02pZ9LTTETMPXS2vo7ciTCNQDpKIzo4SazgZR8d2gIeORhkq0+Q1QSI= 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=IGhzOK9N; 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 418M0NXu020183; Thu, 8 Feb 2024 23:14:30 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=2epZr9ZtYhWfEyi+rsjA ogaNtlPRCGTpOp6RI1gYLko=; b=IGhzOK9NqB8TTMVPGd01CPFpiA0dY/IdQsOh qgFAFKLmLPUPL49P6OQFExLkSWsQ/csSmvOqT5Y0uXyEvVBPWby5w28kV7tkZJt0 5oLoEPoZ7Erze01/wuvoWDxNvyXvHrLUOxRqA6Yv+xgVTMMQu0Pwe3BDZnS2kmJW nL+mEkp/mWA6uIxInH88ti4WV5l2eXseMahenZoDddKh0GJ0n+IlgaC1w3K64Zj+ nhQ7rNVxxN26u3zNqt/62JQQ7rRFnIL2hKvZEwgZAAefQKElH3NhKsT26ZkuPXh9 Bl6haYfYztybMA8I4vES84MADU5xwhdI/Y/bLdLV5FCMVAOeiQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:30 +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 418NETuE013201 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 49/53] ALSA: usb-audio: qcom: Use card and PCM index from QMI request Date: Thu, 8 Feb 2024 15:14:02 -0800 Message-ID: <20240208231406.27397-50-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: g-aYwvnaOrlPFiFAt-IKpmdxz17feKyS X-Proofpoint-ORIG-GUID: g-aYwvnaOrlPFiFAt-IKpmdxz17feKyS 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377342870479854 X-GMAIL-MSGID: 1790377342870479854 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/qcom/qc_audio_offload.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 17cee0cf2ff5..08af82ec22ad 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -106,8 +106,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 { @@ -1243,7 +1241,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"); @@ -1436,8 +1434,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; @@ -1645,7 +1642,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); mutex_unlock(&chip->mutex); From patchwork Thu Feb 8 23:14: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: 198675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518022dyd; Thu, 8 Feb 2024 15:34:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDVfdxOUApwLDM+IZRGss4RMipHEzP6VayA5/SHNVXXa5frrVnQwg2y1ZijALSZK5kt6TW X-Received: by 2002:a17:906:6893:b0:a3b:c221:8598 with SMTP id n19-20020a170906689300b00a3bc2218598mr584717ejr.9.1707435296179; Thu, 08 Feb 2024 15:34:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435296; cv=pass; d=google.com; s=arc-20160816; b=f6ySSSkdmz7bgfot93Uh3Lp/rJBdNB7H6C1wfii66lQFpKIbIoK1VnxJOZzyTPs4B9 AK/GYzPvlz5M0d25Z8dByDC9kjr6TSHNVyEiWFSyXAO499sO/+jVarwhvk5CrtLKSoFV HkjOHKN/dq+WsQOhDU0VNpkyAC/zRU60nfvKHODzgh9jUdI38b413Z127xa+6G1npG3S 1n2OLmqoV8ey1eRlPzPSXaFJX7jVN1zWDIs3fL4o9PPbmz5B2lmGaqWFHwVZDB3UwtX+ 1VJVdtymORXfumZJimzburpSyJnsFTqxENCAIyTvofWj/xi5dgc+5uAo8G/NaKqKPGCH pUHA== 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=8XDjQaxOLfi4DxLUbYexlGFO1qpWIPu7oQ+LyPPQC2w=; fh=OrYiwVOEENj1Ue7mId+rs+F6E8yXE1kZnKYfU9fksqg=; b=Ydsd0OUmEkRc1nWxO1cUCYgM3ghzi3F8o9JIPGWIH4OcCrpumib+292ngqtGSKmuf7 g9HE6buwE/SXYPaPhy3Uj85BmM8CxmKjIruFvPu7U4PKvLinlXYGtl1mPSXCk4Z4uLU4 ZbCoJkiuD2pur1QBvYujqSIDi5UUpIKPaHoD55/hH4GAEnFRVwS7ojdGyHIjAdmN5VmR wYwd9Py03hZU249vgbP+SYaEjVUW+ZbudGj0kh4a7EkKDuiKL1k05pGekr5ZTl7iyVcS 4qJ3RFuXVmG2SnDLC099gqYBwYMqvVB8jlRtO88tncK1j6Q+sf5I/fs2XH1Gr3/XL18w OLcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lssA6LJR; 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-58851-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58851-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUCPg0FMpAGmua5BzXSTvz5VsHdsPPqoFFXzZQQdtPO9Bfn/dKcaFWvpd3rVl0dYB9JtnzY09rEQqrIN62QBWjmTt/KIw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dl16-20020a170907945000b00a37d142ce88si170319ejc.533.2024.02.08.15.34.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58851-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=lssA6LJR; 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-58851-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58851-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 C25161F21C0F for ; Thu, 8 Feb 2024 23:34:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C61E6519E; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lssA6LJR" 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 B31BC54FB7; Thu, 8 Feb 2024 23:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434092; cv=none; b=AVuztqYc+1UsKpzyB5/ZFEgkWQ0rafoShCGXwXwxGWISolN+07x6yIGXtW4OxcOJ6R5pvxdQfjgZF5qIMkjBa+P60gg1peDVJXEgfs7zFjbQp7et1R3JluBjV4HbnoYi9NR6g7CQu8+eTYSN52iGQrhrJ3zLzaMDDTYhh0rT17Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434092; c=relaxed/simple; bh=MDJ4NALM+hrJQ3Ivndp0OdNiEtiGfWJ7lqjiNchqs6E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TnmUWoBx3Rgg0dBJj+P14yqQqU/qJW9iZ4ZleXeCDJcwig3p0dQG2uilL3AM91nlYxKA3LfWDyHkA/0orqd3+XyA32FikvaP2Qll0iScVLbhD/lpFF8RueKTSGjuUGxMFLvNqehon6vK0wms4jt0qzfpSylIKPkPHx6qi2ZPVpM= 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=lssA6LJR; 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 418L0A9q021166; Thu, 8 Feb 2024 23:14:31 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=8XDjQaxOLfi4DxLUbYex lGFO1qpWIPu7oQ+LyPPQC2w=; b=lssA6LJRThwnDZwe97/4Habwd0QYbNwbuBC4 Nei1k39944wEVv8sEY0rxn28CQkGPUKlagLBV6JJB4Sy74zJeBS3OwNUvewsKM+H Hbi6omjZ+JEqvVUzGe6bNki+rbgYk6O+FDj1tBhAgfrQaLJcu/BHJKYCHT1YIOTt bOr/vNc9XBDzkYrJGvOV7LPkV+rmsw+tWNKmhy01j7BaVSS596ymu6GxHwnwD0Sk bgnwRaTf1nyHBvwKmaW0PXet/AqD9SEMD/f6fftqTh0VGSckO7H7Tkkakhmw6614 NpCkSIWrxMeDtOWOV3yFwDr7yWLyojclM4fTstp7Wbq0FEVJqA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:30 +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 418NETBD013204 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 50/53] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Thu, 8 Feb 2024 15:14:03 -0800 Message-ID: <20240208231406.27397-51-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: d_AFCsLh86x0uTJ2DpV0W-TJBBs8LRJk X-Proofpoint-GUID: d_AFCsLh86x0uTJ2DpV0W-TJBBs8LRJk 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375672821106135 X-GMAIL-MSGID: 1790375672821106135 In case of notifying SND platform drivers of connection events, some of these use cases, such as offloading, require an ASoC USB backend device to be initialized before the events can be handled. If the USB backend device has not yet been probed, this leads to missing initial USB audio device connection events. Expose an API that traverses the usb_chip array for connected devices, and to call the respective connection callback registered to the SND platform driver. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 21 +++++++++++++++++++++ sound/usb/card.h | 2 ++ sound/usb/qcom/qc_audio_offload.c | 2 ++ 3 files changed, 25 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 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 6d59995440c3..3a0d68f453a1 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -222,11 +222,13 @@ int snd_usb_unregister_platform_ops(void); #if IS_ENABLED(CONFIG_SND_USB_AUDIO) 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); #else static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, int direction) { return NULL; } +static void snd_usb_rediscover_devices(void) { } #endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 08af82ec22ad..9b0f98600e58 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1867,6 +1867,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 Thu Feb 8 23:14: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: 198671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517878dyd; Thu, 8 Feb 2024 15:34:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRstTu5pbWkKhrY4pshU97O3V0eWrRsQp3iTFAxxQ1olwEPW9ZdlU17pJK/VpjNWYyUJycUmjAuyj0xAIDZ414xFtc8w== X-Google-Smtp-Source: AGHT+IF6iifF1ZWMPkSWPV42LvQ7BEXtK4MQ59/eIEQhsuJrRYQHwG4ZAprBR9C5NkOwWvROR89+ X-Received: by 2002:a05:6a20:9c8b:b0:19c:b1f0:9848 with SMTP id mj11-20020a056a209c8b00b0019cb1f09848mr178175pzb.7.1707435275285; Thu, 08 Feb 2024 15:34:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435275; cv=pass; d=google.com; s=arc-20160816; b=PwV4UMVpFdMX0BwIq/4Qy1hx0QRClfJkFdlkCTTqtChE3BGY2x4qXWCPu5uwSITiiR vR53cBALpzTemlDcM8amBVL8sq4AhXL/o+EAdqtjJCmXxNLPxZvRNnOYIV6cJ2AR5M4Z iqBU9ISdjNvFW1khSBILElwyN+i2E4AKePmZz+OTus6TaMkbT+PfB28yDM89GstriXyC jiNpwPwAUYXY9LrhDC62EyyAel2T7PdItiC2vG+TePsIDd6XOUQ1tSVhKT9YmuHOOnTi fnbeH+VlEoWu1lxK1OYw56+oWAZ2Gh92c6KcZR+pVj8FEDrb0QdEzHol3EluEQ3cpnuL MQOw== 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=1gKa8uPfE60yWjTTUplQLsTc6cS2VTs4IFAWikb6MkA=; fh=A2cejPMO12NxPXXAaxqALMtJAD/RfzJwxipbd++qiRg=; b=BUCLEIir1Kxwa0Y1aCiqTNAWvw7Hz17VK3ZLPkp6v7fORBXiZak5rQKpD97E3Gl+l3 xQEJyld7MOXw16qUjGIvJ5eSfQbseTroxG70vSBO1VD6wfQ4L8YXUGRtVlNqaYPeevge DIouuOp9A7hgJRKktL3qexX1WUHJGxpJjnFFVnT3V0ZOB+/7qwhzLRV3uU5nVq39B52x Zfjvlb5a6hdeZLIpRjAG546OKkEpPfWNtrI4kl67n3OciQjiG5XhAEobUa2T9jw4sosc cbMfUpsyqXX+HzfKTXhgyl5KMholrR54gAOQqZrMSXFfkatE6lcAvUowiUohscW+1HXs FbrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mwfLJ32a; 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-58846-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58846-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWotAhzNCMtu4HM1sqVe5lTWgvC+pQKayzW64FuqMb6NOcadZmUrLiXKdh+oCLBp6ajw5s5zEebGmrTyDJPThOz7dH2UQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ch9-20020a056a0208c900b005dc4f8a376asi666941pgb.884.2024.02.08.15.34.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58846-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=mwfLJ32a; 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-58846-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58846-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 86BEE284F91 for ; Thu, 8 Feb 2024 23:34:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3643A5026F; Thu, 8 Feb 2024 23:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mwfLJ32a" 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 9318554FAE; Thu, 8 Feb 2024 23:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=UjQ/4cigmoxALhEgphFDLbTcE4SsWeKp1HW7/jA+jleuWC3VCE4jl2JUSED/eFhrZu0vU8e+pUSCeTIalRkCeaThKyjDHdRJOT6kvo8CU24s2SgmMMdBbcIhMk5H2Ekh1UKOys1NOaJqKXDEEZTLfIRHgBtfDdxBwOYDWKKN2VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=GgnICuH7GHv7SDlK6A+NlCN2HhLTGdZZc+5NwsH4lPE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jEfqeenfXpr+BDKKy1XKcawmAO0EqHn0iGOTKPkR9sKGYTTZTFP3geXtgkulutrMBJYROudA0p9T9yev9Y+cbPL/mg4T38Qu8l3eICd3U4lN6SldUMNTmra3wlRhKd31AChAJnjUUIEsBg6y1sk0eVN42JpZkjAxNIZo3mh/YJU= 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=mwfLJ32a; 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 418Mm7mG001429; Thu, 8 Feb 2024 23:14:31 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=1gKa8uPfE60yWjTTUplQ LsTc6cS2VTs4IFAWikb6MkA=; b=mwfLJ32a4WxDD8ch1RYJpsy4UMZ4f+PZ9CA6 z8NvoUbW75E1ZuaJDoECFUrq5jjXTfm0HLbjGR0sVyczbOjdjlJdPMpK9mwjRFNG hOfbjn0wg17yYu//58hJTj9btCimJClWaA7yZlWdiiyMwBxrXM0sgniN/yKfN2wu k8yUcQMgdYMYwKMs2MrJLF+WoKmhuhNQrnW0KWDdur+6qhpeEwsGKWml3T+h6PZj rbKANA8cD/itgRdfdLzxdxAdZDE6ig6gCSauCq3cNTsDKxIVpiELsyO5ryS2Gyrz fKyuYO0bMtr/FSl2wceiAy5VtVhFsWu5b8aY3/jYzqzO+J2RtA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujuc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:31 +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 418NEUwB005652 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 51/53] ASoC: usb: Rediscover USB SND devices on USB port add Date: Thu, 8 Feb 2024 15:14:04 -0800 Message-ID: <20240208231406.27397-52-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: L9tl1Hi6qOSqUvYvy-6cEpxSLUX6F09w X-Proofpoint-GUID: L9tl1Hi6qOSqUvYvy-6cEpxSLUX6F09w 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375651283685473 X-GMAIL-MSGID: 1790375651283685473 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 dfd6f53898c5..4d6d6ab0601f 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -437,6 +437,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 Thu Feb 8 23:14: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: 198679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518233dyd; Thu, 8 Feb 2024 15:35:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXauqfm/HVVfYaCSJbr4DgUOtMrSGyLTc0tUO6t72uIyuMCuCwkuv5bGFfb0uhhdsApWeFO15rqjyb2Yr84Kg133jyRUw== X-Google-Smtp-Source: AGHT+IFsQCEuZ7cxkTjVpQRmhUaNlMat/qOK4CVNpyCfU2J2HAhe0LP3HIXrm7joUPhKlV33dDMV X-Received: by 2002:ac2:52b4:0:b0:511:621a:5d5f with SMTP id r20-20020ac252b4000000b00511621a5d5fmr431662lfm.39.1707435327891; Thu, 08 Feb 2024 15:35:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435327; cv=pass; d=google.com; s=arc-20160816; b=dnuCSWqJyOaI5puzmC/6Ggb/thG3EXNC9LBwlVbFcnnLrGRVn9dAGxSVZOtsgJ0+d/ Jp8yAtWbJs7OPOWTZavPxthSGJqRSUE2kBkrbaLR/Ijr5b7NTe7dwMX07DdmRSbZ3d9x z5VVfOnVVH73gAN1oxQ5fp99vncOu2ANVztBf+nwqJhq3YJzZ7EKd8GDCuBL3UzlOddu plrUCr4eOkL2lItqvjF9rnoEyiRFt31n9VvWjUaPdu00aJfnI6kLr1QuQXQmqDkMzvDB POqi04WtX68lHJLuVXuIZxX2kx8Wf4zJLHUCITkc2EdX7uG0VVmTtVtUv0Xq/KWMQjcf +CPg== 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=upVjUEHr+u/G1R6ZE8FxkqLqh2LqYLV17YihttNjauQ=; b=PaIIw9TtaCiVHhMTFXIxnvUSYKqlzsc6avjF2856W4hFyxZvZ6rzYholphZaHk8eud oVaK/MK94elhzhB/ZU4Jkmlp16xLU63CjFsHlEncAB0ufhVvEMuKwAV9EIyoHLTTeVoF 0s+MXL1jJwe236f2vBHfHiOTSK4GdVYDfQImScZUbHsFcFKJrxH9kC7FdKM+Ve9740OY dQEIec8+cGftMoCl6IRl/3wlTnyUsTMJxvj05etLtJpVBXfUIjkADdVzsUtDid/DPot1 nmPQy6zCBtpqLe5TbJWkKlJvbcjv99Ga2pkRjnzvE/ksdrXUmEbNoI3Q6a8Amqm7XWmz lP1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dGmQcKMt; 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-58857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58857-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVAyTyNnWEP9jwttNaDNN2otFfFeTXAAXGfCLmz0mnOzvEBhsOB2VU+hJmbFS8sC7MblnwK42zsXGeNAX7b69ex8qWiQQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bq10-20020a170906d0ca00b00a37d03805afsi169441ejb.956.2024.02.08.15.35.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58857-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=dGmQcKMt; 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-58857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58857-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 7CDDB1F2446A for ; Thu, 8 Feb 2024 23:35:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EFDE664AA; Thu, 8 Feb 2024 23:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dGmQcKMt" 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 42EA251000; Thu, 8 Feb 2024 23:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; cv=none; b=iDhqWPkn/y83nAbLkGC/NJ1+YSGs8FrW0jG4Zl4qndTdG0h3O9dawiYB2VP7gvMK7mZeQzawsTTei0DkxONtF+yXU8xAMuLn1qRA4oG/4xm4HaHa0FK1wwgyzTFU5SLR8DKdNm64+R65xvkSRLgk0Nq6OhXCjeb6GRrby+/N5qU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; c=relaxed/simple; bh=UemOCUX9OC/jB7lWASuqhcBieye2GhhUA69QsoWo44I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ucdeHMJ8Wgau97+PBbB1zRtM8s41efOyfIwRkSL/ADqjmVxtNOg+73a7R/kD9ZoXXtb4yRFwKzC2i/4BhC7a0yjT3lrr12OJjh7Ku6uNbn3ICoDHpyEMb/H5a6rH6iXs3em9dgpkOjIvZiD/FQTQPBMlmWXnLYySgUk4E59ob60= 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=dGmQcKMt; 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 418MS3sl028342; Thu, 8 Feb 2024 23:14:31 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=dGmQcKMtJcdhs3o+6Hpx9Jvrrfbe+SomrysV o00oxhPC+A0MAe3kWfz20+FZbKBDzc1rpogD9wRMLKGkCrFW9aA403MwCPhlLr9r EV69Fy5i/aEO2Wvlb4AeI+g+vo37Zs1ORzwcset17KDuM9ktBAWYjXJ7u6K7v3th 9GplbiPKuaqZxhLALtlghazFgPKqQVqD+EVG2KL6AePfVb8jLhLzk317IX9QbUR8 FLT0NVWLZnEiFEAmnBfxESV5ihOnfZXKf/DCbkBCfksgWrnwrB87pi30pwZIgscS wGhF3Ytse3seUz0ky7KwTbJqOnGjS3Lunj8B/1d+WC6Tvmbx0Q== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:31 +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 418NEUgo005657 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 52/53] ASoC: qcom: Populate SoC components string Date: Thu, 8 Feb 2024 15:14:05 -0800 Message-ID: <20240208231406.27397-53-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: I7SvFsBNvBuvwcKKudjew83ifYcaV9Hb X-Proofpoint-GUID: I7SvFsBNvBuvwcKKudjew83ifYcaV9Hb 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375706079925488 X-GMAIL-MSGID: 1790375706079925488 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 Thu Feb 8 23:14: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: 198684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518770dyd; Thu, 8 Feb 2024 15:36:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxSLaOZOnsoyHafmcEs6kz08QofIzHeT+d2L3g7ClyL+7Ypv8s3mKUFpsaUMehEaH2aNb4Om+uD0IEJNyRsO3a7dwXqw== X-Google-Smtp-Source: AGHT+IE3IrOCRXH0TaZn0Y9pskH4Pk7T57ul1bsILjEaQ+QY2K1u21vy+sJiA7PZyX796+N7rGlS X-Received: by 2002:a17:906:35d4:b0:a3b:b22a:f268 with SMTP id p20-20020a17090635d400b00a3bb22af268mr569196ejb.5.1707435410428; Thu, 08 Feb 2024 15:36:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435410; cv=pass; d=google.com; s=arc-20160816; b=gKrYZB/f5zgqnVGxiGJrm562mghMGbyYBEXfdCRvBqaB2t8BqBTdG6A8H727CHr2eH 2LBEfThBIl8zCYs0m4UhsmCU9ktaoBcCp0Oz2ipyCk/gKBaUuqEylPbhBLhJsqPOlnoM TV6i/nZjhmLkY4JzM+xSy8IViAaWeSrdF+Put2sCLXE8/aOLaL9PSTaxA88B/CRm2YHh wV2IsZSefZSfig6uAgadRAM8BzVaLSXEX/djNIa5Zmlfn4sFsR4OWYsgN6Cm0Q62jJtS oWYT9xrupYBVWLrz0uiV9X+XP0yMjmtlvSEM8dSj7YWkNclbTbSByuN8K0+H2oQ0g6y+ aGiw== 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=myJLVPZj3rPIdm3qrd/zKGuPpL/C/3rCqL6v4TBk7T0=; fh=ZuDcoL0acPJJrMF+bsIdqncVHmn6hF54APKP0l4HqJo=; b=o8cQRCUncVVfbDZRe3Oi3YLqQy+UmHsv2x/lKC3zdgagkhaY45Ulbu3C4xmQdL+bZq AgSi/f5QbZkl33HBnz26ezXtJfWQ/Q4DvtvN2363N/n1iFa9wSZ7SFi8oABplNomwmjF ucAJugNVB+eVxmTwarf8YS1618poIJieipNhueeqndPgThBesQrsaECkG5ZbmXe+4ixL dPIY2WliyCXyfztEItt0knTbuiAHjZA4beoc1QbY9qtccfheTR1OCmBG7GWMpVW/Jygq xjxxxEgPhMvUemxLJ2ItLkhW/4YUWu5TjdjNhPAERgrUSOvGGYSZvif5/7shs7gzOx4I OOcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gBTPvQUO; 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-58856-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58856-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVUQ0i/nVnL4+ExgeNOBeaVm236nq/ld1jmrIVqQbPOiWUGODyjmVIHQ5HXPK373t/uD4rL3XAIYLSB49DZGtcFGUO7Iw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d26-20020a170906041a00b00a3a40a7831esi169905eja.149.2024.02.08.15.36.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:36:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58856-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=gBTPvQUO; 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-58856-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58856-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 CFBA81F2163D for ; Thu, 8 Feb 2024 23:36:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2D4069D0D; Thu, 8 Feb 2024 23:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gBTPvQUO" 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 90BFC55E71; Thu, 8 Feb 2024 23:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; cv=none; b=odbhAohLlz5NgILYy66BAgxusLOwG2UrdRLzUlxb+7skeKiOf2HCfVAVkbO2XsOBw3xY9+QZZOvap6Jxum+F737vY29qie3S7pUsAr6yJUSzKjaSCd2Ze50U1Ru3zZwq0BrzNzIyK1qhcClVOhUpL2QonJLWuHrTThed5C+M7IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434095; c=relaxed/simple; bh=P+RvMKwVssmkGEJXCRKZH2Lx8YbxHNwljTEVTAm/On4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BaErJ9nzxaR2iKg/lHX/ZVFs6N/s4DzS+5Dp2v1LKF4vUm4/UOgtw25RU+b9X+eyvpA90ZXqrR8/5XCnL5AlgphIjTVpyEbMigRcOKsLYI5rObvpb3oHiHPNB+ob/z54Uq+ZoPItzvVSoPvwAnLM6VOXixiyyPP+nz4z2oBMTa4= 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=gBTPvQUO; 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 418MJtfj004216; Thu, 8 Feb 2024 23:14:32 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=myJLVPZj3rPIdm3qrd/z KGuPpL/C/3rCqL6v4TBk7T0=; b=gBTPvQUOma7VW0R97cU4XnY45ui+YM8muvTk 3EDuJAtKhwoEPCf/3htpN2NfMYBGZ3hBRfRDcuX86Eqam0AB5x3SP7VNr/HHFSYq y/Dx2JIqNwfipTzSH1S267v1UlrT67k0atwZrBz7xZfbWr06NBHAO8PIAr6DeJBR pXHryqPrU95oZLe5slIRJ2Lef6JXTtQX6LlfwkrxDR4BVBihhWVvyceIXwFs/jIk /gMgBQmvzQK3zxHsdfCikpTVEbReDZ06V+p1+kPGXlHTs9TCW2MJ1EWt2xIhxOld Qw5p1diNkibx3J4eJIMykPY1v5NUrCA7P1nQOPbv+9IqnqEXjA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4rk82k57-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:31 +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 418NEUqc022146 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:30 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:30 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 53/53] ASoC: doc: Add documentation for SOC USB Date: Thu, 8 Feb 2024 15:14:06 -0800 Message-ID: <20240208231406.27397-54-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LmNZgtOTNJ4lSJLxsVKPBQHrRadWbLMp X-Proofpoint-ORIG-GUID: LmNZgtOTNJ4lSJLxsVKPBQHrRadWbLMp 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375792752995902 X-GMAIL-MSGID: 1790375792752995902 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..5e57a9a3855a --- /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: + + :: + + SNDUSB OFFLD status -1, -1 (range -1->32) + SNDUSB OFFLD device 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: + + - ``SNDUSB OFFLD 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. + - ``SNDUSB OFFLD device 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: + + - ``SNDUSB OFFLD playback available`` **(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. + +SNDUSB OFFLD device 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 **SNDUSB OFFLD device 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. + + +SNDUSB OFFLD 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 'SNDUSB OFFLD device select' 2 0 + + + :: + + tinymix -D 0 get 'SNDUSB OFFLD device select' + --> 2, 0 (range 0->32) + + :: + + tinymix -D 0 get 'SNDUSB OFFLD 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)