From patchwork Thu Sep 21 21:48:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5360836vqi; Thu, 21 Sep 2023 23:31:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHYn3iIOCQVIf9/3aXagKMoeXkGImzDX+8wWPulABrIALZvhX3Uvpqt2nEaKRpuEAkHALU X-Received: by 2002:a17:90a:fc8a:b0:273:a392:7077 with SMTP id ci10-20020a17090afc8a00b00273a3927077mr7454641pjb.10.1695364319005; Thu, 21 Sep 2023 23:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695364318; cv=none; d=google.com; s=arc-20160816; b=0Z9HMWUNdo3IDR1Fe7t6HIhR/b6Pf6UYytSWKfkLYBunRqQCDCyKTjizRWeyLYN0ST XgI4LjionckU5bDr4RsXXn6vV2DCd1KNu/vmZ6CPSE+tvPm6i5OEBCxlStxyoW7l1CGo 9ghN5lf2psAR98lgNGyQZt+IZx7l7/JIx9da2MV5AwcD6fD9KuMdsqhBJUorx6zPR5kf vJGyXypaow5bEgZA2Q6Jtt/SVYCRqS8RtAq9NMCTzZP/R/sAfR/e8af1PPMbA8trhxTq 5AsXslR3T4EmKC3TKQVd6PbMpHzHAV74Z1JXUmMImQJbqYK7ryF+LLY6CASO0w5AD85I a3/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=85oxUKrPGtBcHt9sgFc/4IeBuQfrC3PUhd0eSeeckLU=; fh=3ULhJ7QBW5rTuBflHMANg6R5zFEk2hDxjz9PULLNWtk=; b=wVPGMMmVXPslnzfwMvPDuDGCU6TRtWKGRoShPnuSaXILZz78b0KzUgojPrhKwGUkpM Ft6sLUPVtVd+FWvTpStJQt0mjybLbZWR9saGTye3GemvYlg5SdBtYT0q1G63j9AYlKmh s34RAu7UWVf1xHB34HiNZ/Ldp+aH1CEAZFGvFEYH+LaLSWJkjjV/ChzlMCO+xsYHBxbu zZyQhzmB9vSEh/6ymd68nfohnGUhFYjfEsZEjNIl00VGlZRkhTIrB1F7uGdCZ1EkMPbb Pn+24QoW7cuLxEzkF2hAl4siR1jVh+p4UeFVoRjrpMiitHxnLx6Zj5BeuTxT+1TBZL+9 WRmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QIxnrYg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id w14-20020a17090a460e00b002680abc3699si5235391pjg.115.2023.09.21.23.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 23:31:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QIxnrYg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EFEFA8539E07; Thu, 21 Sep 2023 14:55:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbjIUVyj (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232837AbjIUVxZ (ORCPT ); Thu, 21 Sep 2023 17:53:25 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC7603AA9; Thu, 21 Sep 2023 14:49:54 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLlR29030616; Thu, 21 Sep 2023 21:49:11 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=85oxUKrPGtBcHt9sgFc/4IeBuQfrC3PUhd0eSeeckLU=; b=QIxnrYg+wyUTt/P4aj9AMr7wAkq0kOsR0urGl/oRj9ZhlWTj0jAuRbxqj2ajUCnsbbyl 0eACTiq4DvpiNKYGSrXpchn+vjtxzIJqKdvBTsIfRpWLEHszdIkUk413KTCYmwJPH76Q W9kzyF0mxUc5uh4sOwjH4+z0s/OfsFf+GRXZ47nZ/BlYLrcaR2B5xJL6jGPVR3MQCy9U sSO44eAp5DSAqrGfbC2AcVVhjeoAHH3vEUIIzsKLbeBFX95tRVMPPweCyZrOl3yyZIH2 oXbmrnuPWqaRVPjzlzTMyfQUsP2topudKdsSZbW2P4q73n8s5gOTJ7G+LQ4Rs6eOI0tS zw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u0s0bsa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:11 +0000 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 38LLmrKR031028 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:53 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.36; Thu, 21 Sep 2023 14:48:53 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v7 01/33] xhci: add support to allocate several interrupters Date: Thu, 21 Sep 2023 14:48:11 -0700 Message-ID: <20230921214843.18450-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: GmLE-allMto65GBHXOzO2_hs8yceBi1E X-Proofpoint-ORIG-GUID: GmLE-allMto65GBHXOzO2_hs8yceBi1E X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 mlxlogscore=630 spamscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:55:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777718336274193530 X-GMAIL-MSGID: 1777718336274193530 From: Mathias Nyman Modify the XHCI drivers to accommodate for handling multiple event rings in case there are multiple interrupters. Add the required APIs so clients are able to allocate/request for an interrupter ring, and pass this information back to the client driver. This allows for users to handle the resource accordingly, such as passing the event ring base address to an audio DSP. There is no actual support for multiple MSI/MSI-X vectors. Factoring out XHCI interrupter APIs and structures done by Wesley Cheng, in order to allow for USB class drivers to utilze them. Signed-off-by: Mathias Nyman Co-developed-by: Wesley Cheng Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-debugfs.c | 2 +- drivers/usb/host/xhci-mem.c | 93 ++++++++++++++++++++++++++++++--- drivers/usb/host/xhci-ring.c | 2 +- drivers/usb/host/xhci.c | 49 ++++++++++------- drivers/usb/host/xhci.h | 77 +-------------------------- include/linux/usb/xhci-intr.h | 86 ++++++++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 102 deletions(-) create mode 100644 include/linux/usb/xhci-intr.h diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 99baa60ef50f..15a8402ee8a1 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -693,7 +693,7 @@ void xhci_debugfs_init(struct xhci_hcd *xhci) "command-ring", xhci->debugfs_root); - xhci_debugfs_create_ring_dir(xhci, &xhci->interrupter->event_ring, + xhci_debugfs_create_ring_dir(xhci, &xhci->interrupters[0]->event_ring, "event-ring", xhci->debugfs_root); diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 8714ab5bf04d..2f9228d7d22d 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1837,6 +1837,26 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) kfree(ir); } +void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir) +{ + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + unsigned int intr_num; + + /* interrupter 0 is primary interrupter, don't touch it */ + if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { + xhci_dbg(xhci, "Invalid secondary interrupter, can't remove\n"); + return; + } + + /* fixme, should we check xhci->interrupter[intr_num] == ir */ + spin_lock(&xhci->lock); + intr_num = ir->intr_num; + xhci_free_interrupter(xhci, ir); + xhci->interrupters[intr_num] = NULL; + spin_unlock(&xhci->lock); +} +EXPORT_SYMBOL_GPL(xhci_remove_secondary_interrupter); + void xhci_mem_cleanup(struct xhci_hcd *xhci) { struct device *dev = xhci_to_hcd(xhci)->self.sysdev; @@ -1844,9 +1864,13 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) cancel_delayed_work_sync(&xhci->cmd_timer); - xhci_free_interrupter(xhci, xhci->interrupter); - xhci->interrupter = NULL; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed primary event ring"); + for (i = 0; i < xhci->max_interrupters; i++) { + if (xhci->interrupters[i]) { + xhci_free_interrupter(xhci, xhci->interrupters[i]); + xhci->interrupters[i] = NULL; + } + } + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed interrupters"); if (xhci->cmd_ring) xhci_ring_free(xhci, xhci->cmd_ring); @@ -1916,6 +1940,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) for (i = 0; i < xhci->num_port_caps; i++) kfree(xhci->port_caps[i].psi); kfree(xhci->port_caps); + kfree(xhci->interrupters); xhci->num_port_caps = 0; xhci->usb2_rhub.ports = NULL; @@ -1924,6 +1949,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) xhci->rh_bw = NULL; xhci->ext_caps = NULL; xhci->port_caps = NULL; + xhci->interrupters = NULL; xhci->page_size = 0; xhci->page_shift = 0; @@ -2276,6 +2302,13 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, return -EINVAL; } + if (xhci->interrupters[intr_num]) { + xhci_warn(xhci, "Interrupter %d\n already set up", intr_num); + return -EINVAL; + } + + xhci->interrupters[intr_num] = ir; + ir->intr_num = intr_num; ir->ir_set = &xhci->run_regs->ir_set[intr_num]; /* set ERST count with the number of entries in the segment table */ @@ -2295,10 +2328,53 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, return 0; } +struct xhci_interrupter * +xhci_create_secondary_interrupter(struct usb_hcd *hcd) +{ + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + struct xhci_interrupter *ir; + unsigned int i; + int err = -ENOSPC; + + if (!xhci->interrupters) + return NULL; + + ir = xhci_alloc_interrupter(xhci, GFP_KERNEL); + if (!ir) + return NULL; + + spin_lock_irq(&xhci->lock); + + /* 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; + } + } + + 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); + ir = NULL; + goto out; + } + + xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", + i, xhci->max_interrupters); + +out: + return ir; +} +EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter); + int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) { - dma_addr_t dma; + struct xhci_interrupter *ir; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; + dma_addr_t dma; unsigned int val, val2; u64 val_64; u32 page_size, temp; @@ -2422,11 +2498,14 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) /* Allocate and set up primary interrupter 0 with an event ring. */ xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocating primary event ring"); - xhci->interrupter = xhci_alloc_interrupter(xhci, flags); - if (!xhci->interrupter) + xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), + flags, dev_to_node(dev)); + + ir = xhci_alloc_interrupter(xhci, flags); + if (!ir) goto fail; - if (xhci_add_interrupter(xhci, xhci->interrupter, 0)) + if (xhci_add_interrupter(xhci, ir, 0)) goto fail; xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 1dde53f6eb31..93233cf5ff21 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3074,7 +3074,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) writel(status, &xhci->op_regs->status); /* This is the handler of the primary interrupter */ - ir = xhci->interrupter; + ir = xhci->interrupters[0]; if (!hcd->msi_enabled) { u32 irq_pending; irq_pending = readl(&ir->ir_set->irq_pending); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index e1b1b64a0723..3fd2b58ee1d3 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -456,7 +456,7 @@ static int xhci_init(struct usb_hcd *hcd) static int xhci_run_finished(struct xhci_hcd *xhci) { - struct xhci_interrupter *ir = xhci->interrupter; + struct xhci_interrupter *ir = xhci->interrupters[0]; unsigned long flags; u32 temp; @@ -508,7 +508,7 @@ int xhci_run(struct usb_hcd *hcd) u64 temp_64; int ret; struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct xhci_interrupter *ir = xhci->interrupter; + struct xhci_interrupter *ir = xhci->interrupters[0]; /* Start the xHCI host controller running only after the USB 2.0 roothub * is setup. */ @@ -572,7 +572,7 @@ void xhci_stop(struct usb_hcd *hcd) { u32 temp; struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct xhci_interrupter *ir = xhci->interrupter; + struct xhci_interrupter *ir = xhci->interrupters[0]; mutex_lock(&xhci->mutex); @@ -668,36 +668,49 @@ EXPORT_SYMBOL_GPL(xhci_shutdown); #ifdef CONFIG_PM static void xhci_save_registers(struct xhci_hcd *xhci) { - struct xhci_interrupter *ir = xhci->interrupter; + struct xhci_interrupter *ir; + unsigned int i; xhci->s3.command = readl(&xhci->op_regs->command); xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); - if (!ir) - return; + /* save both primary and all secondary interrupters */ + for (i = 0; i < xhci->max_interrupters; i++) { + ir = xhci->interrupters[i]; + if (!ir) + continue; - ir->s3_erst_size = readl(&ir->ir_set->erst_size); - ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); - ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); - ir->s3_irq_control = readl(&ir->ir_set->irq_control); + ir->s3_erst_size = readl(&ir->ir_set->erst_size); + ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); + ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); + ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); + ir->s3_irq_control = readl(&ir->ir_set->irq_control); + } } static void xhci_restore_registers(struct xhci_hcd *xhci) { - struct xhci_interrupter *ir = xhci->interrupter; + struct xhci_interrupter *ir; + unsigned int i; writel(xhci->s3.command, &xhci->op_regs->command); writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); - writel(ir->s3_erst_size, &ir->ir_set->erst_size); - xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); - xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); - writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); - writel(ir->s3_irq_control, &ir->ir_set->irq_control); + + for (i = 0; i < xhci->max_interrupters; i++) { + ir = xhci->interrupters[i]; + if (!ir) + continue; + + writel(ir->s3_erst_size, &ir->ir_set->erst_size); + xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); + xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); + writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); + writel(ir->s3_irq_control, &ir->ir_set->irq_control); + } } static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) @@ -1059,7 +1072,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) xhci_dbg(xhci, "// Disabling event ring interrupts\n"); temp = readl(&xhci->op_regs->status); writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); - xhci_disable_interrupter(xhci->interrupter); + xhci_disable_interrupter(xhci->interrupters[0]); xhci_dbg(xhci, "cleaning up memory\n"); xhci_mem_cleanup(xhci); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7e282b4522c0..d706a27ec0a3 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -17,6 +17,7 @@ #include #include #include +#include /* Code sharing between pci-quirks and xhci hcd */ #include "xhci-ext-caps.h" @@ -1541,18 +1542,6 @@ static inline const char *xhci_trb_type_string(u8 type) #define AVOID_BEI_INTERVAL_MIN 8 #define AVOID_BEI_INTERVAL_MAX 32 -struct xhci_segment { - union xhci_trb *trbs; - /* private to HCD */ - struct xhci_segment *next; - dma_addr_t dma; - /* Max packet sized bounce buffer for td-fragmant alignment */ - dma_addr_t bounce_dma; - void *bounce_buf; - unsigned int bounce_offs; - unsigned int bounce_len; -}; - enum xhci_cancelled_td_status { TD_DIRTY = 0, TD_HALTED, @@ -1585,16 +1574,6 @@ struct xhci_cd { union xhci_trb *cmd_trb; }; -enum xhci_ring_type { - TYPE_CTRL = 0, - TYPE_ISOC, - TYPE_BULK, - TYPE_INTR, - TYPE_STREAM, - TYPE_COMMAND, - TYPE_EVENT, -}; - static inline const char *xhci_ring_type_string(enum xhci_ring_type type) { switch (type) { @@ -1615,46 +1594,6 @@ static inline const char *xhci_ring_type_string(enum xhci_ring_type type) } return "UNKNOWN"; -} - -struct xhci_ring { - struct xhci_segment *first_seg; - struct xhci_segment *last_seg; - union xhci_trb *enqueue; - struct xhci_segment *enq_seg; - union xhci_trb *dequeue; - struct xhci_segment *deq_seg; - struct list_head td_list; - /* - * Write the cycle state into the TRB cycle field to give ownership of - * the TRB to the host controller (if we are the producer), or to check - * if we own the TRB (if we are the consumer). See section 4.9.1. - */ - u32 cycle_state; - unsigned int stream_id; - unsigned int num_segs; - unsigned int num_trbs_free; /* used only by xhci DbC */ - unsigned int bounce_buf_len; - enum xhci_ring_type type; - bool last_td_was_short; - struct radix_tree_root *trb_address_map; -}; - -struct xhci_erst_entry { - /* 64-bit event ring segment address */ - __le64 seg_addr; - __le32 seg_size; - /* Set to zero */ - __le32 rsvd; -}; - -struct xhci_erst { - struct xhci_erst_entry *entries; - unsigned int num_entries; - /* xhci->event_ring keeps track of segment dma addresses */ - dma_addr_t erst_dma_addr; - /* Num entries the ERST can contain */ - unsigned int erst_size; }; struct xhci_scratchpad { @@ -1707,18 +1646,6 @@ struct xhci_bus_state { unsigned long resuming_ports; }; -struct xhci_interrupter { - struct xhci_ring *event_ring; - struct xhci_erst erst; - struct xhci_intr_reg __iomem *ir_set; - unsigned int intr_num; - /* For interrupter registers save and restore over suspend/resume */ - u32 s3_irq_pending; - u32 s3_irq_control; - u32 s3_erst_size; - u64 s3_erst_base; - u64 s3_erst_dequeue; -}; /* * It can take up to 20 ms to transition from RExit to U0 on the * Intel Lynx Point LP xHCI host. @@ -1799,7 +1726,7 @@ struct xhci_hcd { struct reset_control *reset; /* data structures */ struct xhci_device_context_array *dcbaa; - struct xhci_interrupter *interrupter; + struct xhci_interrupter **interrupters; struct xhci_ring *cmd_ring; unsigned int cmd_ring_state; #define CMD_RING_STATE_RUNNING (1 << 0) diff --git a/include/linux/usb/xhci-intr.h b/include/linux/usb/xhci-intr.h new file mode 100644 index 000000000000..e0091ee2c73a --- /dev/null +++ b/include/linux/usb/xhci-intr.h @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_XHCI_INTR_H +#define __LINUX_XHCI_INTR_H + +#include + +struct xhci_erst_entry { + /* 64-bit event ring segment address */ + __le64 seg_addr; + __le32 seg_size; + /* Set to zero */ + __le32 rsvd; +}; + +enum xhci_ring_type { + TYPE_CTRL = 0, + TYPE_ISOC, + TYPE_BULK, + TYPE_INTR, + TYPE_STREAM, + TYPE_COMMAND, + TYPE_EVENT, +}; + +struct xhci_erst { + struct xhci_erst_entry *entries; + unsigned int num_entries; + /* xhci->event_ring keeps track of segment dma addresses */ + dma_addr_t erst_dma_addr; + /* Num entries the ERST can contain */ + unsigned int erst_size; +}; + +struct xhci_segment { + union xhci_trb *trbs; + /* private to HCD */ + struct xhci_segment *next; + dma_addr_t dma; + /* Max packet sized bounce buffer for td-fragmant alignment */ + dma_addr_t bounce_dma; + void *bounce_buf; + unsigned int bounce_offs; + unsigned int bounce_len; +}; + +struct xhci_ring { + struct xhci_segment *first_seg; + struct xhci_segment *last_seg; + union xhci_trb *enqueue; + struct xhci_segment *enq_seg; + union xhci_trb *dequeue; + struct xhci_segment *deq_seg; + struct list_head td_list; + /* + * Write the cycle state into the TRB cycle field to give ownership of + * the TRB to the host controller (if we are the producer), or to check + * if we own the TRB (if we are the consumer). See section 4.9.1. + */ + u32 cycle_state; + unsigned int stream_id; + unsigned int num_segs; + unsigned int num_trbs_free; + unsigned int num_trbs_free_temp; + unsigned int bounce_buf_len; + enum xhci_ring_type type; + bool last_td_was_short; + struct radix_tree_root *trb_address_map; +}; + +struct xhci_interrupter { + struct xhci_ring *event_ring; + struct xhci_erst erst; + struct xhci_intr_reg __iomem *ir_set; + unsigned int intr_num; + /* For interrupter registers save and restore over suspend/resume */ + u32 s3_irq_pending; + u32 s3_irq_control; + u32 s3_erst_size; + u64 s3_erst_base; + u64 s3_erst_dequeue; +}; + +struct xhci_interrupter * +xhci_create_secondary_interrupter(struct usb_hcd *hcd); +void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir); +#endif From patchwork Thu Sep 21 21:48:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5241453vqi; Thu, 21 Sep 2023 17:57:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG81vYak0OBsGPszfXfbitW8hEGg4zLuGO0VMSZumEiIHLDetQ5WGf8wYJMf5YJXGglfgjj X-Received: by 2002:a17:902:f687:b0:1bb:994c:bc43 with SMTP id l7-20020a170902f68700b001bb994cbc43mr8424794plg.18.1695344228641; Thu, 21 Sep 2023 17:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695344228; cv=none; d=google.com; s=arc-20160816; b=vz/K75bDwv55TRmqN/SVYkfk+fWsBflBDCS6ThQrqRMZT1csdxS5wA/X6laz1DUFPa rr/1b2pdVnptSQ2caZrvxX4Ipdy52EoxxxNEJ3d9oByHqBLN8N00KCUwiCMoQfQ2d/Cl nkJhvI6XAH1pLfvP53p0TtT3XPPt6YjJiYn5pAzhRfNq0nK5oc1BydU56c94yDGbISc9 axjbJAhQNZQOEfVLQTdUC1A3Qt4ekcxW/Oc6Khlt34gErr6UykgGjZakkInM7n631dv9 /KwYU++R7CBBERjmHjDaTR4w7s6Gn2Bi7HLeN/vWZANLKaK2niz7SqPrXTRmVqxqiR0J QKag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZseVt8TpXNsPnD9gXvZiESwKDgOnEM+cyJSdOPfVtyQ=; fh=3ULhJ7QBW5rTuBflHMANg6R5zFEk2hDxjz9PULLNWtk=; b=XDsaL+aaRNeUkGWAGbLxFnfnkdoHQUTtmZ3+ZbGNEs7Xi/VojP8IFnSd9kdQuDETKr 8qApM88uBqUutKaxsf30+OT5vRR87w64nJmf0Zg/tWxUeuANLJOObkrX8WW5p1ZtmXTw uDZjlf78Lm82ZyV9qVIHZOh5XpQhef5ZTHOClkUhrnMVBi060Rf8BVHnAY8dolouDVvZ 3EdxeBZ2YQa+UcAmf9UnJclsmydouyXPjuLKfmjtWJqqk7tVi50qBPHLPRcqmB2cgvEB Ka4CYWYkfZdp2khuwsnG8zDq1rzMOqQ8txceuBN3nPEP2NPAjoislc42gNdhK4NiErUf Ms+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lBolqkkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u8-20020a17090282c800b001bf5f853a86si2452657plz.647.2023.09.21.17.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:57:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=lBolqkkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8B909808E64B; Thu, 21 Sep 2023 15:02:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbjIUWCi (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230439AbjIUWCW (ORCPT ); Thu, 21 Sep 2023 18:02:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A48271E; Thu, 21 Sep 2023 14:49:35 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLGdLs020622; Thu, 21 Sep 2023 21:48:55 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=ZseVt8TpXNsPnD9gXvZiESwKDgOnEM+cyJSdOPfVtyQ=; b=lBolqkkkqztymt1dXfYc7FKe1h92tjLFV4yU0xSQan9awKeycOYYD5dEepjhSmq/FpPL Wwfo46yBtn9gImVbw5F1sVTZ4ErzRW/KDZd3wUqQisKnzZJSMzmmci8qCO1wlc8C0Rf+ jdbJi8umOzz+cRAwB34AUPEefZed5VgFqdprijWxm+rHlBJzlsh5zRBTlIowFdFJ3MZa G8hH7yyLyjXvyb5S2c2dx118dzPC/39l7C41v+B8zW+fMK1kI7PFddkK8H9Ex44zd+zn Mf9Prm2mwIH1jLTiXFvHy9xwl41PfeK2FZVN1w8FJ1NVsgn+1jQjGzLt6Gg5jgaIVOTy ZA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u0hgbuu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:54 +0000 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 38LLmrKo031031 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:53 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.36; Thu, 21 Sep 2023 14:48:53 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v7 02/33] xhci: add helper to stop endpoint and wait for completion Date: Thu, 21 Sep 2023 14:48:12 -0700 Message-ID: <20230921214843.18450-3-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: LgI0xRcvfOVAlYKOfwKnz2s5pci5exze X-Proofpoint-GUID: LgI0xRcvfOVAlYKOfwKnz2s5pci5exze X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777697270104275112 X-GMAIL-MSGID: 1777697270104275112 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-hub.c | 29 +++--------------- drivers/usb/host/xhci.c | 60 +++++++++++++++++++++++++++---------- drivers/usb/host/xhci.h | 2 ++ 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 0054d02239e2..2f7309bdc922 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -489,7 +489,6 @@ EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port); static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) { struct xhci_virt_device *virt_dev; - struct xhci_command *cmd; unsigned long flags; int ret; int i; @@ -501,10 +500,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) trace_xhci_stop_device(virt_dev); - cmd = xhci_alloc_command(xhci, true, GFP_NOIO); - if (!cmd) - return -ENOMEM; - spin_lock_irqsave(&xhci->lock, flags); for (i = LAST_EP_INDEX; i > 0; i--) { if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { @@ -521,7 +516,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) if (!command) { spin_unlock_irqrestore(&xhci->lock, flags); ret = -ENOMEM; - goto cmd_cleanup; + goto out; } ret = xhci_queue_stop_endpoint(xhci, command, slot_id, @@ -529,30 +524,14 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) if (ret) { spin_unlock_irqrestore(&xhci->lock, flags); xhci_free_command(xhci, command); - goto cmd_cleanup; + goto out; } } } - ret = xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend); - if (ret) { - spin_unlock_irqrestore(&xhci->lock, flags); - goto cmd_cleanup; - } - - xhci_ring_cmd_db(xhci); spin_unlock_irqrestore(&xhci->lock, flags); + ret = xhci_stop_endpoint_sync(xhci, &virt_dev->eps[0], suspend); - /* Wait for last stop endpoint command to finish */ - wait_for_completion(cmd->completion); - - if (cmd->status == COMP_COMMAND_ABORTED || - cmd->status == COMP_COMMAND_RING_STOPPED) { - xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); - ret = -ETIME; - } - -cmd_cleanup: - xhci_free_command(xhci, cmd); +out: return ret; } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 3fd2b58ee1d3..163d533d6200 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -2758,6 +2758,46 @@ 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) +{ + struct xhci_command *command; + unsigned long flags; + int ret; + + command = xhci_alloc_command(xhci, true, GFP_KERNEL); + 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; +} /* Issue a configure endpoint command or evaluate context command * and wait for it to finish. @@ -3078,7 +3118,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; @@ -3118,10 +3158,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; @@ -3144,23 +3180,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); 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) { @@ -3192,7 +3221,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 d706a27ec0a3..898b6434dc27 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2125,6 +2125,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); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From patchwork Thu Sep 21 21:48:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5414696vqi; Fri, 22 Sep 2023 01:49:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEm6gPM3TwZzfpiLOSwF8Af7NPWf9iyPc0EPFZH337YpdBj5wk9YW9gqJ/A6D48ZZSdfkHo X-Received: by 2002:a05:6870:e389:b0:1d5:bda7:1337 with SMTP id x9-20020a056870e38900b001d5bda71337mr8618585oad.52.1695372541944; Fri, 22 Sep 2023 01:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695372541; cv=none; d=google.com; s=arc-20160816; b=Kkuz566bEf2270xDi1/tIk1AQpQ+tmnyz9QDl7pby8aHeUkrQ//pW0XV6dZeEkbbJt SW8tpbSTMGwZm0H3idjjwT6t74VVNz7qpMnuQIzJLl9u2ZOVvk5irNTRnpHAUGNNNIzA 9GHufiqNF/NuIrWCRj2+0AWXIyIk8ogonvmZ9IgmU7U48UBGTfY2fGkiv9E9ufMZtMLK v5DLqqI0Efhe5bI7YkKoaprsxvArY8lDsxAIJF0aoQZ8fgFReyrQbZjBhwfYpurKCcBh /49QwVgJ7m4fJS+DZ+30tNQfjI9kq3al7za45HZMucIeIIbJY1XnpYsYzthFxCdoApIl 8BAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b7UX4xEqbpTE5ZLVwG0WlXP9YxrfFv516hblPuLU3KQ=; fh=3ULhJ7QBW5rTuBflHMANg6R5zFEk2hDxjz9PULLNWtk=; b=eMRRFTSiOriviv28grRfktnfYShPnE4/gbYEDZPsJF4DnX782zQdYCZr06yDY9dJp5 pU9DsYlQP4WnukUlAp+msWD/uqZZeFOJfwE0Uhgw1Fo+O45gwJhFGc0QlDlJuSZb/6sf MFmYOyowj7QVLQrIrmrzMmuoaRFFI/Wloh322z9N8KPrl55CZ+q8n/pTV6EZd6mYNTXm 7vZVqHGmeJ+t/Y3x5Tko+ys1UikOfquJ63hsRny6u09/IY+p4kgcrgAyAo/0v4KUkY/q V5n54HRbkaY+UeRUxgD7N+CWUWfUl0WA+jg8ce0/sOnoUYu9WduVzYg5lM9IO6X6/kuk mxEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=axZU5I3t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m65-20020a633f44000000b00578d016422esi3333662pga.821.2023.09.22.01.49.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=axZU5I3t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3590E82F27FB; Thu, 21 Sep 2023 14:55:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233084AbjIUVy3 (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbjIUVxZ (ORCPT ); Thu, 21 Sep 2023 17:53:25 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA5B3AAE; Thu, 21 Sep 2023 14:49:43 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLlR97010420; Thu, 21 Sep 2023 21:49: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=b7UX4xEqbpTE5ZLVwG0WlXP9YxrfFv516hblPuLU3KQ=; b=axZU5I3trJE4Kon+Gn7D8XLr6u/tUFG/MU4Az0ldmO8B9tt4cr+HiAxGx7rLOKArpR78 xuGQyAKdh2agqKZNcaSD64k5aFpJGgOVcKPdN+hKHdtMic0hjXPar4xZ/vQ0Wsi/GZCL YObGLPmytAVLgLY4kj7tCs05uEm1B3h4loEIdRADt8WqR3kHXURENI+mWNKLvI6X5xoK LWHhKy8kzIMadF15ARKcPYm90AnoxACQJftK2krpIL262ll23wLzIiP8MFTidLA5xQhg Lh0lWLezFlTHJMxs13fHu7wpgJVPy72ejIG2Y7JeZgH1/7JNrifrHouTi1qfhGlQ1v/V EA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uknr96q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:54 +0000 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 38LLmsnb012377 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:54 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.36; Thu, 21 Sep 2023 14:48:53 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v7 03/33] xhci: sideband: add initial api to register a sideband entity Date: Thu, 21 Sep 2023 14:48:13 -0700 Message-ID: <20230921214843.18450-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: YWI75WEk4JPNjD4eb5j1DVHqv2Z9Ulie X-Proofpoint-ORIG-GUID: YWI75WEk4JPNjD4eb5j1DVHqv2Z9Ulie X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=995 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:55:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777726958457621653 X-GMAIL-MSGID: 1777726958457621653 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. Multiple ring segment page linking and proper endpoint clean up 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 | 4 + drivers/usb/host/xhci-sideband.c | 198 ++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 23 +--- include/linux/usb/xhci-sideband.h | 57 +++++++++ 5 files changed, 273 insertions(+), 18 deletions(-) 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..83be56c27d64 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 + bool "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..4df946c05ba0 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -32,6 +32,10 @@ endif xhci-rcar-hcd-y += xhci-rcar.o xhci-rcar-hcd-$(CONFIG_USB_XHCI_RZV2M) += xhci-rzv2m.o +ifneq ($(CONFIG_USB_XHCI_SIDEBAND),) + xhci-hcd-y += xhci-sideband.o +endif + 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..937ae627947a --- /dev/null +++ b/drivers/usb/host/xhci-sideband.c @@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * xHCI host controller sideband support + * + * Copyright (c) 2023, Intel Corporation. + * + * Author: Mathias Nyman + */ +#include +#include + +#include "xhci.h" + +static int +xhci_ring_to_sgtable(struct xhci_sideband *sb, struct xhci_ring *ring, struct device *dev) +{ + struct sg_table *sgt; + struct xhci_segment *seg; + struct page **pages; + unsigned int n_pages; + size_t sz; + int i; + + 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 0; + + sgt = kzalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!sgt) { + kvfree(pages); + return 0; + } + + 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 0; + } + + sb->sgt = sgt; + + return 0; +} + +static int __xhci_sideband_remove_endpoint(struct xhci_sideband *sb, + int idx) +{ + struct xhci_virt_ep *ep = sb->eps[idx]; + + /* + * 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); + + sg_free_table(sb->sgt); + ep->sideband = NULL; + sb->eps[idx] = NULL; + + return 0; +} + +/* sidband api functions */ +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; + + /* check this device isn't already controller via sideband */ + vdev = xhci->devs[udev->slot_id]; + + if (!vdev || vdev->sideband) { + xhci_warn(xhci, "XHCI sideband slot already in use %d\n", + udev->slot_id); + return NULL; + } + + sb = kzalloc_node(sizeof(*sb), GFP_KERNEL, dev_to_node(hcd->self.sysdev)); + if (!sb) + return NULL; + + sb->xhci = xhci; + sb->vdev = vdev; + vdev->sideband = sb; + + return sb; +} +EXPORT_SYMBOL_GPL(xhci_sideband_register); + +void +xhci_sideband_unregister(struct xhci_sideband *sb) +{ + int i; + + for (i = 0; i < EP_CTX_PER_DEV; i++) + if (sb->eps[i]) + __xhci_sideband_remove_endpoint(sb, i); + + sb->vdev->sideband = NULL; + kfree(sb); +} +EXPORT_SYMBOL_GPL(xhci_sideband_unregister); + +int +xhci_sideband_add_endpoint(struct xhci_sideband *sb, + struct usb_host_endpoint *host_ep) +{ + struct xhci_hcd *xhci = sb->xhci; + struct device *dev = xhci_to_hcd(xhci)->self.sysdev; + struct xhci_virt_ep *ep; + unsigned int ep_index; + + ep_index = xhci_get_endpoint_index(&host_ep->desc); + ep = &sb->vdev->eps[ep_index]; + + /* + * 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) + return -EBUSY; + + ep->sideband = sb; + sb->eps[ep_index] = ep; + sb->ring = ep->ring; + xhci_ring_to_sgtable(sb, ep->ring, dev); + + return 0; + +} +EXPORT_SYMBOL_GPL(xhci_sideband_add_endpoint); + +int +xhci_sideband_remove_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->vdev != ep->sideband->vdev) + return -ENODEV; + + __xhci_sideband_remove_endpoint(sb, ep_index); + + 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 || sb->vdev != ep->sideband->vdev) + return -EINVAL; + + return xhci_stop_endpoint_sync(sb->xhci, ep, 0); +} +EXPORT_SYMBOL_GPL(xhci_sideband_stop_endpoint); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 898b6434dc27..15ade8ec6b6c 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -18,6 +18,7 @@ #include #include #include +#include /* Code sharing between pci-quirks and xhci hcd */ #include "xhci-ext-caps.h" @@ -975,6 +976,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 { @@ -1004,8 +1007,6 @@ struct xhci_interval_bw_table { unsigned int ss_bw_out; }; -#define EP_CTX_PER_DEV 31 - struct xhci_virt_device { int slot_id; struct usb_device *udev; @@ -1038,6 +1039,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; }; /* @@ -1518,22 +1521,6 @@ static inline const char *xhci_trb_type_string(u8 type) #define NEC_FW_MINOR(p) (((p) >> 0) & 0xff) #define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff) -/* - * TRBS_PER_SEGMENT must be a multiple of 4, - * since the command ring is 64-byte aligned. - * It must also be greater than 16. - */ -#define TRBS_PER_SEGMENT 256 -/* Allow two commands + a link TRB, along with any reserved command TRBs */ -#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) -#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) -#define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE)) -/* TRB buffer pointers can't cross 64KB boundaries */ -#define TRB_MAX_BUFF_SHIFT 16 -#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT) -/* How much data is left before the 64KB boundary? */ -#define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \ - (addr & (TRB_MAX_BUFF_SIZE - 1))) #define MAX_SOFT_RETRY 3 /* * Limits of consecutive isoc trbs that can Block Event Interrupt (BEI) if diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sideband.h new file mode 100644 index 000000000000..d6b2cc91666f --- /dev/null +++ b/include/linux/usb/xhci-sideband.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * xHCI host controller sideband support + * + * Copyright (c) 2023, Intel Corporation. + * + * Author: Mathias Nyman + */ + +#ifndef __LINUX_XHCI_SIDEBAND_H // fixme check ok +#define __LINUX_XHCI_SIDEBAND_H + +#include +/* + * TRBS_PER_SEGMENT must be a multiple of 4, + * since the command ring is 64-byte aligned. + * It must also be greater than 16. + */ +#define TRBS_PER_SEGMENT 256 +/* Allow two commands + a link TRB, along with any reserved command TRBs */ +#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) +#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) +#define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE)) +/* TRB buffer pointers can't cross 64KB boundaries */ +#define TRB_MAX_BUFF_SHIFT 16 +#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT) +/* How much data is left before the 64KB boundary? */ +#define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \ + (addr & (TRB_MAX_BUFF_SIZE - 1))) + +#define EP_CTX_PER_DEV 31 + +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 sg_table *sgt; + struct xhci_ring *ring; + dma_addr_t dma; +}; + +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); +#endif /* __LINUX_XHCI_SIDEBAND_H */ + From patchwork Thu Sep 21 21:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5323768vqi; Thu, 21 Sep 2023 21:50:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdt2S0WBQqdOgBtUgS0MaJZUIkn7g8mKa3w77emN0ehiE8FXt6ReiNvEfObmE1xIb+DyVT X-Received: by 2002:a17:903:41c7:b0:1be:f45c:bc38 with SMTP id u7-20020a17090341c700b001bef45cbc38mr7955118ple.2.1695358255472; Thu, 21 Sep 2023 21:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358255; cv=none; d=google.com; s=arc-20160816; b=LdCOZ/DBHjZyfLJU8OggIs0MsV88jqz905/dAr2aO86QXgQ/pyEX/HVhNaez3UT0/6 mF3KIdIDssbxmYipM+NTM/MT7X+FvDuwnCRN868nmwswdBIGqmYAJ8r1VssugpQ67yN4 Ug1QUKUj/ca9b5P5GjI/mPDLuBL/HyFsM35CSwcZNyIFMWfD7FYEhF4VjMvvjs3ryoCL +8TgJwzbadv4PZm/8XQK3h0Z7psCLDQzOl1hN0sCIn8H9bV5Dspmrad+vVsM5gbaGuLE QOolrEa4AXBffbGENn0ifyGzT0seOW0z7Agd8e+fDmzRwI9/5Vly/nroWSe+tMgk9yux T/dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3lo4gimlUv1KryCkLcmojwfyH5zzqAMvP6LLie+DG/0=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=NS7SfrqNoE82J7ngwMlQtnNr1kcrVEbVzlsLHCA7JG8DyQMPvGp+Mpn0Abr7Cze9SP zR8d+baR85McaeQfdlmfz9LtNLbayBgPbGk1XcMLl7dSLvbhGo6Q5+mPnUUtA2jHHCpU RRouKNdbNVtgenJagTQMC+y7/GQWSBfqzYTJAcdkYsZczqzSl38X4jktNPuVnohWbn5U y/SSuanDUOayTrZE8nrPPbn8M/lLPs9AWnTMpj2InB06oJWxSwDg+OBsf3V/2Flp8aaG gb44VUAXVaUwyWR0roi/1Tx2Ag9ht1VFM7RPBHMAGZR1W1xfziP9lSAbRMxVO8tYd3Ka EoDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="J7p3bk/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id r19-20020a170902c7d300b001b6c462acbdsi2692996pla.15.2023.09.21.21.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:50:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="J7p3bk/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 202E2852D258; Thu, 21 Sep 2023 14:53:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbjIUVxk (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6013B26AB; Thu, 21 Sep 2023 14:49:32 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKLsKG002318; Thu, 21 Sep 2023 21:48:55 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=3lo4gimlUv1KryCkLcmojwfyH5zzqAMvP6LLie+DG/0=; b=J7p3bk/KxIZ54puJMlQdGfCZVZqc7DT/aveym+mw91zGKT3CDh3udp+qavwMDEFfuSxr 50bwO+toxkH64CjeXar3OhEA6c6EbRhpXuAS9a/peN8HmIyxkNR+YjzSdkvx+jSQqVaK ZQ8W8HAlDrf7eYsP9OKtV/jaYowxXyvjRfKyPrssePK6CNQeWfekmHB6TjvVDKnsVEtc uev+Kue21Dnv1r5FV5/9GLAdkf5O06L/Gzx5oOsgr3bcncvu/N0wlKHxf0wqPC7P/djD tDwPtrGbgLymJzo7rUlvkDR0OfVat7ZA6MxddA0XXgyzPdPDeSQ6ECG+cZGalxWaC6jz Cw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u6agbew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:55 +0000 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 38LLmsFp032584 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:54 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.36; Thu, 21 Sep 2023 14:48:53 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 04/33] usb: host: xhci-mem: Cleanup pending secondary event ring events Date: Thu, 21 Sep 2023 14:48:14 -0700 Message-ID: <20230921214843.18450-5-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: WHS_fEVFYyN7pKNxjTdUwcqfvUpgDLUg X-Proofpoint-ORIG-GUID: WHS_fEVFYyN7pKNxjTdUwcqfvUpgDLUg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 mlxlogscore=809 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 malwarescore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777711977745294694 X-GMAIL-MSGID: 1777711977745294694 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 updating the dequeue pointer to the last pending event trb. Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 9 ++++--- drivers/usb/host/xhci-ring.c | 46 ++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.c | 2 +- drivers/usb/host/xhci.h | 3 +++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 2f9228d7d22d..94cbc25e77ca 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1801,7 +1801,6 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) { struct device *dev = xhci_to_hcd(xhci)->self.sysdev; size_t erst_size; - u64 tmp64; u32 tmp; if (!ir) @@ -1823,10 +1822,6 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) tmp = readl(&ir->ir_set->erst_size); tmp &= ERST_SIZE_MASK; writel(tmp, &ir->ir_set->erst_size); - - tmp64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - tmp64 &= (u64) ERST_PTR_MASK; - xhci_write_64(xhci, tmp64, &ir->ir_set->erst_dequeue); } /* free interrrupter event ring */ @@ -1851,6 +1846,10 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup /* fixme, should we check xhci->interrupter[intr_num] == ir */ spin_lock(&xhci->lock); intr_num = ir->intr_num; + + /* cleanup secondary interrupter to ensure there are no pending events */ + xhci_skip_sec_intr_events(xhci, ir->event_ring, ir); + xhci_free_interrupter(xhci, ir); xhci->interrupters[intr_num] = NULL; spin_unlock(&xhci->lock); diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 93233cf5ff21..fdef1b82b1ff 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3026,6 +3026,52 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); } +/* + * 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 *erdp_trb, *current_trb; + struct xhci_segment *seg; + u64 erdp_reg; + u32 iman_reg; + dma_addr_t deq; + unsigned long segment_offset; + + /* disable irq, ack pending interrupt and ack all pending events */ + xhci_disable_interrupter(ir); + iman_reg = readl_relaxed(&ir->ir_set->irq_pending); + if (iman_reg & IMAN_IP) + writel_relaxed(iman_reg, &ir->ir_set->irq_pending); + + /* 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_dbg(xhci, "event ring handling not required\n"); + return; + } + + seg = ring->first_seg; + segment_offset = deq - seg->dma; + + erdp_trb = current_trb = ir->event_ring->dequeue; + while (1) { + inc_deq(xhci, ir->event_ring); + erdp_trb = ir->event_ring->dequeue; + /* cycle state transition */ + if ((le32_to_cpu(erdp_trb->event_cmd.flags) & TRB_CYCLE) != + ring->cycle_state) + break; + } + + xhci_update_erst_dequeue(xhci, ir, current_trb); +} + /* * 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.c b/drivers/usb/host/xhci.c index 163d533d6200..2bb7895c1cd6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -309,7 +309,7 @@ static int xhci_enable_interrupter(struct xhci_interrupter *ir) return 0; } -static int xhci_disable_interrupter(struct xhci_interrupter *ir) +int xhci_disable_interrupter(struct xhci_interrupter *ir) { u32 iman; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 15ade8ec6b6c..e2133f125974 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2029,6 +2029,9 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, int type, gfp_t flags); void xhci_free_container_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, + struct xhci_ring *ring, struct xhci_interrupter *ir); +int xhci_disable_interrupter(struct xhci_interrupter *ir); /* xHCI host controller glue */ typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); From patchwork Thu Sep 21 21:48:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5304618vqi; Thu, 21 Sep 2023 20:57:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMaqsCoOfLOUyptOi20qwPzqom6XH4FVaZ1XOn0CXajjazYyXoVH3RHS0HfqlPMRHbCdCL X-Received: by 2002:a17:902:bb8f:b0:1c4:202d:8747 with SMTP id m15-20020a170902bb8f00b001c4202d8747mr5732873pls.50.1695355036604; Thu, 21 Sep 2023 20:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695355036; cv=none; d=google.com; s=arc-20160816; b=ewYwr70HiOQc2A6F6emPS2mYxA51Io4Imx64kM8dr2JxjsKSK7hPrpMA0R57QjJB1J jpVAZbDSE+G8l/AUaFDZUGRygClzLAI9wPZCZ+s44S1cz2O3AnhgqMZVedvuiG5cw1dt TtwVLYQIfVgpJCvduezNSAOiL6MoU/3AG7kTVUenKCVfxTcgVYx3u6Kcqvb3eIqng2bN cJD+OkwHakRCwfcJDe01RE1prPB7iYOQ6umSWdr2aL4grmw47qjISIXs3GICviVXxHW5 Km1y2y2LxNgT8FjdPzfDT/odDAZgBDbGAOcdMjc2SeYq47xP3rTGWfdsilSSAwKime0X iCtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=r31eiFMh/CBoLoST6JeTG7QMm3NUYna5E/5qOM98ZVk=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=gjWnVdCh4iHCzDce2615sFlJ+HvblNvurpzmR+ihGVm9G1BifqvgH9h15ssn/hMo0B ix64r9sHaFK1uaqwOa5+KJ7IqEMyoUVhOVvUB1qBUh/jvzCO7Hh1brfird/0ETX9ZLiY iTUtaAxZIX5Z9wUBOViawVkndq2+JRHg3YIp4ZMYBjhsslAzUh9ZubEwSTb/U935FEkw GhMa+a9JYHyJTDeL0FG/BqfvMYp0Nh8kW0j5KAgv34Mp9LoyyHAfPMHpTys0H9CIkdXX DJLWoQ0tndPq5oZEOKbaueopIhoANHIzdDXatgh2F4UZSlFkTLtAgRBOUS90FkaNdLml LwUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Y5guhq4G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u13-20020a170902e5cd00b001b8ac52a19esi3341963plf.436.2023.09.21.20.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Y5guhq4G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id ADA4685391A8; Thu, 21 Sep 2023 14:54:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233079AbjIUVy0 (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232815AbjIUVxZ (ORCPT ); Thu, 21 Sep 2023 17:53:25 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACFB32D72; Thu, 21 Sep 2023 14:49:49 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLnPVq020951; Thu, 21 Sep 2023 21:49: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=r31eiFMh/CBoLoST6JeTG7QMm3NUYna5E/5qOM98ZVk=; b=Y5guhq4G6OJnBoQzBr3WF0dMDMtDF/1SSMaKQ9dXOgmab/ioDw9wEGzU2eHoMON+MQHY d+fUg2GTmKJEDkSFH4JbLPOCaxF2vFcMgZoQIzoQyOOHS5JOH9sA9EjEN3RdcwCEWD7t bRYN8JBHE17lte1osmZapN1XpLiPNdoevxp7twYu+sdvbN60U/9boS3lhOYvXKsUaGpb T1PTa5geEXuibnF1z+xIZ4p6BXG7z3KKrVJUe2bFWNZL9Qaz1+OnUMtouz3BytK9htK7 UaEJ/0VkEnVhHhtfjWbPLmsSRdU4cKdJJ7PL/ZJ4+hiNe1I4zudy9ZhW9Zks5xLWAuBY og== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8um1r96p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:25 +0000 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 38LLms02032081 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:54 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.36; Thu, 21 Sep 2023 14:48:54 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 05/33] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Date: Thu, 21 Sep 2023 14:48:15 -0700 Message-ID: <20230921214843.18450-6-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: eUN8CFd5kyyqjmFzFTWDPwE4rZi5uOpD X-Proofpoint-GUID: eUN8CFd5kyyqjmFzFTWDPwE4rZi5uOpD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxlogscore=469 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777708602624169313 X-GMAIL-MSGID: 1777708602624169313 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 | 12 ++++++------ include/linux/usb/xhci-intr.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 94cbc25e77ca..9d07aea34fc6 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2328,7 +2328,7 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, } struct xhci_interrupter * -xhci_create_secondary_interrupter(struct usb_hcd *hcd) +xhci_create_secondary_interrupter(struct usb_hcd *hcd, int intr_num) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct xhci_interrupter *ir; @@ -2343,15 +2343,15 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd) return NULL; spin_lock_irq(&xhci->lock); - /* 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); + break; + } } } - spin_unlock_irq(&xhci->lock); if (err) { xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n", diff --git a/include/linux/usb/xhci-intr.h b/include/linux/usb/xhci-intr.h index e0091ee2c73a..738b0f0481a6 100644 --- a/include/linux/usb/xhci-intr.h +++ b/include/linux/usb/xhci-intr.h @@ -81,6 +81,6 @@ struct xhci_interrupter { }; struct xhci_interrupter * -xhci_create_secondary_interrupter(struct usb_hcd *hcd); +xhci_create_secondary_interrupter(struct usb_hcd *hcd, int intr_num); void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrupter *ir); #endif From patchwork Thu Sep 21 21:48:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143453 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5598893vqi; Fri, 22 Sep 2023 07:03:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrlo9/k9bUzB+Vn3y+Hhhd+SlYGTr9zG7VVwJJAgGW6HxBRCH454aFnnoz1Nje8S5W5YPG X-Received: by 2002:a17:90a:31cc:b0:263:f62b:3601 with SMTP id j12-20020a17090a31cc00b00263f62b3601mr8028782pjf.10.1695391395994; Fri, 22 Sep 2023 07:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695391395; cv=none; d=google.com; s=arc-20160816; b=NlqtuYLUC+oVjUPpYR8cfw3Vgy5IpyMecGAYi9i6jJ8o+nTRZSDPXMWpUl12ZTM42e YeaAl3hDLj+83Y46T9VIDzeftYMuQu/UTm8nqhVw48MSmRGO9LWWSZIEtTwNipv1ckfG DQH/1H9A2CxlxPAeJTPfvRhIimZQDgY2ENdIy4OzMPrRSnqzx3RvKkDxx9riWvJ0FolR kl+pF601LBF5YnrtTCqKvFkyqcmUEARiOM3EFt2QuEYOg11w8Dgy3b2MNPxmAxp28/QA v1mPSzKFwAc4O9t/YyVmba83Zby5auqLic+m4QQao/IQUwrlvLJs6vH7GkJKBrjsWNgZ xLdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VcAYa/+/r3z+L0siR6izCF50ALvk48KnA2NkBZchfcs=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=szZR1B0mXw7tWqpDWPSXb4dAj5/whYg6IWbtcDYNTdKuactmPe8gbRizEqM0EmfMyE uocpIgPoJW6Mc6Cg+MCZBosdMwJ6RjtM87amzO+VowX+l1gSBCFzBcX3PKGkG30xQA+i rEUGf6/j2yjMhVDViWArn6nqi+FXP9U3wc92xM+HhNKJRSMrPEZe25jniyYkeRFF8xsO 29HNZDGJLbPQnHyWup7gSoBXE7k+Bam2psLTGJRxTeWzjacKkoy8KD2ji0YnPeJRIf5Q Vl73dzbH7owaSkIvVYoRAhaSUykZgeAqyBQ3mBln716rHM9Ouef41olQnrir3E1mX5MC J2AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="RgfXN/Jb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id lt12-20020a17090b354c00b00276c28cdd4fsi3960062pjb.31.2023.09.22.07.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:03:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="RgfXN/Jb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CE2C0826EBA1; Thu, 21 Sep 2023 15:21:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233001AbjIUWVS (ORCPT + 29 others); Thu, 21 Sep 2023 18:21:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232879AbjIUWUq (ORCPT ); Thu, 21 Sep 2023 18:20:46 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B05930D8; Thu, 21 Sep 2023 14:49:37 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKOQHF031493; Thu, 21 Sep 2023 21:48:56 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=VcAYa/+/r3z+L0siR6izCF50ALvk48KnA2NkBZchfcs=; b=RgfXN/JbBMpi+O22N0hLlnofOlycQuzNDjyuDO9ryf75ViQ2VySK5Y4aATJvcPZ9+ESh fIJTfHBA46t8H+46A+S/t4iTqK7x9nOdiDwHKUScK0D5AIMcSbQmncKWr116gGOkr+V1 2447tep5JfCU6FET8IWt5uMvCjhBi00Evw3j8O5H5LESTRKeaXBOTssrZfS2ZmYnBTQp ohfigF7pH1M6zwK9yjZZpcQ+aCXFO5A3cHIp1mF5Qd0Px1VUq//g+D6mHSvMOhX3H/cU pM4F3nCz5zgddWYyo70F/XekZEbFyKIx/97m84OZQWODU87cKNUo1KMvPo0ouvBm3DhU 1g== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u9h8arc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 +0000 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 38LLmtLK009002 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:55 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.36; Thu, 21 Sep 2023 14:48:54 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 06/33] ASoC: Add SOC USB APIs for adding an USB backend Date: Thu, 21 Sep 2023 14:48:16 -0700 Message-ID: <20230921214843.18450-7-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: Zma1UENDjOlCyrj0kJL62yzSs2x8JSuz X-Proofpoint-ORIG-GUID: Zma1UENDjOlCyrj0kJL62yzSs2x8JSuz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:21:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777746728487661111 X-GMAIL-MSGID: 1777746728487661111 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 | 48 +++++++++++ sound/soc/Makefile | 2 +- sound/soc/soc-usb.c | 185 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 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..1fa671924018 --- /dev/null +++ b/include/sound/soc-usb.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2023 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; +}; + +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_get_priv_data(struct device *usbdev); + +struct snd_soc_usb *snd_soc_usb_add_port(struct device *dev, void *priv, + int (*connection_cb)(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected)); +int snd_soc_usb_remove_port(struct device *dev); +#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..b5ab2c1a6dd4 --- /dev/null +++ b/sound/soc/soc-usb.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2023 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 *dev) +{ + struct device_node *node; + struct snd_soc_usb *ctx; + + node = snd_soc_find_phandle(dev); + if (IS_ERR(node)) + return NULL; + + mutex_lock(&ctx_mutex); + list_for_each_entry(ctx, &usb_ctx_list, list) { + if (ctx->dev->of_node == node) { + of_node_put(node); + mutex_unlock(&ctx_mutex); + return ctx; + } + } + of_node_put(node); + mutex_unlock(&ctx_mutex); + + return NULL; +} + +/** + * snd_soc_usb_get_priv_data() - Retrieve private data stored + * @dev: device reference + * + * Fetch the private data stored in the USB SND SOC structure. + * + */ +void *snd_soc_usb_get_priv_data(struct device *dev) +{ + struct snd_soc_usb *ctx; + + ctx = snd_soc_find_usb_ctx(dev); + if (!ctx) { + /* Check if backend device */ + mutex_lock(&ctx_mutex); + list_for_each_entry(ctx, &usb_ctx_list, list) { + if (dev->of_node == ctx->dev->of_node) { + mutex_unlock(&ctx_mutex); + goto out; + } + } + mutex_unlock(&ctx_mutex); + ctx = NULL; + } +out: + return ctx ? ctx->priv_data : NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_get_priv_data); + +/** + * 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. + * + */ +struct snd_soc_usb *snd_soc_usb_add_port(struct device *dev, void *priv, + int (*connection_cb)(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected)) +{ + struct snd_soc_usb *usb; + + usb = devm_kzalloc(dev, sizeof(*usb), GFP_KERNEL); + if (!usb) + return ERR_PTR(-ENOMEM); + + usb->connection_status_cb = connection_cb; + usb->dev = dev; + usb->priv_data = priv; + + mutex_lock(&ctx_mutex); + list_add_tail(&usb->list, &usb_ctx_list); + mutex_unlock(&ctx_mutex); + + return usb; +} +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 device *dev) +{ + struct snd_soc_usb *ctx, *tmp; + + mutex_lock(&ctx_mutex); + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) { + if (ctx->dev == dev) { + 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; + + if (!usbdev) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(usbdev); + if (!ctx) + return -ENODEV; + + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, true); + + 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; + + if (!usbdev) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(usbdev); + if (!ctx) + return -ENODEV; + + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, false); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_disconnect); From patchwork Thu Sep 21 21:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5264948vqi; Thu, 21 Sep 2023 18:59:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYaBW4XyoysALhRtBENq4Am9Jp42HmgPRpH6GNxQ6LIB8QpxoyF+ei4uqSeW0cQwvLq7xH X-Received: by 2002:a05:6a20:96ce:b0:15c:b7ba:1624 with SMTP id hq14-20020a056a2096ce00b0015cb7ba1624mr5800132pzc.39.1695347945215; Thu, 21 Sep 2023 18:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695347945; cv=none; d=google.com; s=arc-20160816; b=hb4qOTgn6JNimZ7K4M+/9PqML54OyZwm4/X6JAdLz74vIMuSQTOV8zpMBVNDbPhGCe sjkLYdmNNrhIVQ/CK3dJdzrhSUCpoOSk41+TsCrB+3eshN1zJuWnT78+l3p9/M9Zd91o oN5ZqXjHPYz0TBxKQ7Wcr3O3gzEC8pa5atwSiIH/Hz6RalSTSY9UHFyPraaHs5noNju1 +Me3TgeOJhRKeSMOtpePukLzbUY+4Oh/oMhWcHzpan8OcsLINyh4xlQAaWRwL/UzVusc Yc84y19bPHbkV9yx+OZ/qURomprsvk08/F95C6sGx9y9lIMXgVnlP3/0V6wKIhsTXiML SQ7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/ZM8SPXr7udKkYr/SDUmnoP1IOgbHf5SfkdSPWJ27XA=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=D3OUwnWDC/QN9IHLoRCuQ4z28UqYCRRgOQRg+Mv7ehMDihoPPxTMLsrYoUMReJhwJt lqmhK8SV18PoTcd3VUJSw2NjeDLbU4DC13AadW2NYJatXPk/OyDHWu34QZ7OqWQeXS2K 6NP35hh4Qo3nhuLaAMV/te/ELB0dqDP6yFsDC5LnvxuKDIn9stYfcCKqlG2ne/reohom qW7lLbfgANE/KdG4fRaegOAXv7r2xlhtfYhmP4IvbhQqIMjlfuaBiHcAHpffix4e4GQ+ vDv0pfmLlpBMplUAShKT2DntRMM/SBPauLe6p/OJ7U6iI3eZgc246EajZzy4q4MLyvxx zwvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=WDEbT4oU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bt25-20020a056a00439900b006901504b6a3si2747379pfb.153.2023.09.21.18.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=WDEbT4oU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F05F3852D264; Thu, 21 Sep 2023 14:53:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232987AbjIUVxo (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232659AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8108F26AE; Thu, 21 Sep 2023 14:49:32 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLfTKF001553; Thu, 21 Sep 2023 21:48:56 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/SDUmnoP1IOgbHf5SfkdSPWJ27XA=; b=WDEbT4oUArPEM6/OqhidkEQLqqL19usMe2FKOcZKo8Hjk0KO5ZyNLM7+dcd2VXItNJJH VSOM3SN9t+G195ghVRQCxtUlEvF4xmW7jFXux5mOzOQakyJakTGf92OitmRA07Kb1tzW 6W6mYo1RRZ+4uiUfs7GKgRkH+KDnnSoDukm+mJIAUrO3Kx9V6+mmyJ1WrEUgkIMGB8l6 7PST5bUsYZbN9tknRNGNn/yNLzZCpv72nEn60Uh0MviLlTDiHWoB1/+sqfiNQJne8jKj xPCtgbuNHvgjGK5ILZpyXNUabrku7mmZMHZzso2LE4bCZlH8//4b67qCSNIXHS2ZQnfx TA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txpgc0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 +0000 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 38LLmt1X032604 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:55 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.36; Thu, 21 Sep 2023 14:48:54 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 07/33] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Date: Thu, 21 Sep 2023 14:48:17 -0700 Message-ID: <20230921214843.18450-8-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: AY5ppBiHrTW9vrBCM0py7KCbEjmoVCVT X-Proofpoint-GUID: AY5ppBiHrTW9vrBCM0py7KCbEjmoVCVT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=818 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777701166852027392 X-GMAIL-MSGID: 1777701166852027392 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 Sep 21 21:48:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5270021vqi; Thu, 21 Sep 2023 19:11:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxyAiX6Nd9xF6TpP5i50365sxGKXgN4+x+M57yJMxYFXGODFwgLPTq5vQ8+lZw3dyeej/B X-Received: by 2002:a05:6870:6122:b0:1d5:8f05:39c1 with SMTP id s34-20020a056870612200b001d58f0539c1mr7600988oae.15.1695348670369; Thu, 21 Sep 2023 19:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695348670; cv=none; d=google.com; s=arc-20160816; b=d0acGOu4clLRWgzCseZhsds8l4evk1UE4lkjn4k6yYK/0g22Z79hSLNOpkGEpw4eGn toL7tN9/fwlpn8e74vVed2KMFdERPC688GU/0y2gtNGRI+vk4yBxbMfjaEkmXIY4+6g2 14s9SWaK2aOs7bi5DmiBcQDzO1mQ5Cv/JHGNU9AV74ZtulwObBlpYE1Y4sjCf6qAMoWx tWDV5ObioHUJNl4u5hygY7drHm5hsImqJZaD4E0YnfUYptTfz+pfa7ZNF+tJSqrlM/n7 GX8pyauZ309+LSjkv2Q/RRKwIpyVKYLMfc+WZ5Jkwn5pmshhLR08ZMRW0uhFOelki89M rQvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=emjVpavNYFllGYHBvf0hIAg/rkU2/Nq+QSY608vLq1I=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=nF7wOvL64TiYo8Cr5vJFTgrzJZPFBumqk1YHjojnLEHn580YcokTmV+ito4SfNmHdO /0Nyr1IxafNchubC6JngRg1yTTQ8TEXe1/hLqYc6farWb7Za5bWC5Fkg67RCbdE71Ngh ueS7C9mmU7x1AMYkso7DihaCs7bHch3H+bDoSeaxRi7lgIecGZrdXgRmm7dvnfwPBWAe es6s/IH2gEK9rERseC3GxgQgLWhsRzwqzbJw3bMj74q+9XLZLEMGORH2hKWmkFZDvHOO xE8gIX+VBfyXnEx6VRIwo8QnyVi/pD8pZCDrX7mJCacgbqKyamFpHGVePSog4jYYOrIL /ivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=X6xdZdLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id j72-20020a638b4b000000b0057751b4abe2si2772599pge.111.2023.09.21.19.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 19:11:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=X6xdZdLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 95A99803388C; Thu, 21 Sep 2023 15:17:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232906AbjIUWPg (ORCPT + 29 others); Thu, 21 Sep 2023 18:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232214AbjIUWPU (ORCPT ); Thu, 21 Sep 2023 18:15:20 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15AB53588; Thu, 21 Sep 2023 14:49:38 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLNLbB031497; Thu, 21 Sep 2023 21:48:56 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=emjVpavNYFllGYHBvf0hIAg/rkU2/Nq+QSY608vLq1I=; b=X6xdZdLPVpG1lHrOM9wHLxWMsGOd+rPDccEpkDZL114IpuQNbNehlpgwIOLXVSjHutUm 0lplZmhwoQzSJBNYv6iHNSrbRFGpLa/Amtfq2MNAZ/8vDBDzQ7EkpKTdT5WmksEgG+kg UnSuzpizpPVHmc+G282gN3NMhpBO9z3rbA/gzFHLmcykEc1YZNkAlWnN+1J+xf9Xafy8 dc1y5h4wNV9gKH2NwhiY5UicJYqOVzGmdocnGGQkjM10Hfbqx0WwiBHp+Gb5Lp1JZ3zT R4VAVH6Qr6S3cuQwwKqRqXghUihAmkjGVDPKclgZsv5jztDTNyRdAPj3lxjOKS3cvUwX gw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u0hgbuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 +0000 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 38LLmtOH012384 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:55 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.36; Thu, 21 Sep 2023 14:48:55 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 08/33] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Date: Thu, 21 Sep 2023 14:48:18 -0700 Message-ID: <20230921214843.18450-9-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: 67XESBsvmS8GeXlnMdWIl5UUmPN726ex X-Proofpoint-GUID: 67XESBsvmS8GeXlnMdWIl5UUmPN726ex X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:17:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777701927178631860 X-GMAIL-MSGID: 1777701927178631860 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. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6afe-dai.c | 56 +++++++ sound/soc/qcom/qdsp6/q6afe.c | 183 ++++++++++++++++++++++- sound/soc/qcom/qdsp6/q6afe.h | 35 ++++- 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, 305 insertions(+), 2 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c index 3faa7e0eb0dd..e46c064253d7 100644 --- a/sound/soc/qcom/qdsp6/q6afe-dai.c +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c @@ -91,6 +91,40 @@ static int q6hdmi_hw_params(struct snd_pcm_substream *substream, return 0; } +static int q6usb_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: + case SNDRV_PCM_FORMAT_SPECIAL: + 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) @@ -391,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; } @@ -617,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) @@ -644,6 +685,18 @@ static int msm_dai_q6_dai_remove(struct snd_soc_dai *dai) return 0; } +static const struct snd_soc_dai_ops q6usb_ops = { + .probe = msm_dai_q6_dai_probe, + .prepare = q6afe_dai_prepare, + .hw_params = q6usb_hw_params, + .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, @@ -942,6 +995,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 = { @@ -1056,6 +1111,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 = &q6usb_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 919e326b9462..f49c69472b5c 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -34,6 +34,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 @@ -43,6 +45,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 @@ -71,12 +74,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 @@ -512,12 +519,109 @@ 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; + +/** + * struct afe_param_id_usb_audio_dev_latency_mode + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_LATENCY_MODE + * @mode: latency mode for the USB audio device + **/ +struct afe_param_id_usb_audio_dev_latency_mode { + u32 minor_version; + u32 mode; +} __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; @@ -832,6 +936,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) @@ -1289,6 +1394,79 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, } EXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare); +static int afe_port_send_usb_dev_param(struct q6afe_port *port, struct q6afe_usb_cfg *cfg) +{ + union afe_port_config *pcfg = &port->port_cfg; + struct afe_param_id_usb_audio_dev_params usb_dev; + struct afe_param_id_usb_audio_dev_lpcm_fmt lpcm_fmt; + struct afe_param_id_usb_audio_svc_interval svc_int; + int ret = 0; + + if (!pcfg) { + dev_err(port->afe->dev, "%s: Error, no configuration data\n", __func__); + ret = -EINVAL; + goto exit; + } + + memset(&usb_dev, 0, sizeof(usb_dev)); + memset(&lpcm_fmt, 0, sizeof(lpcm_fmt)); + memset(&svc_int, 0, sizeof(svc_int)); + + usb_dev.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + 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); + goto exit; + } + + 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_dev_param(port, cfg); +} +EXPORT_SYMBOL_GPL(q6afe_usb_port_prepare); + /** * q6afe_hdmi_port_prepare() - Prepare hdmi afe port. * @@ -1611,7 +1789,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 30fd77e2f458..ef47b4ae9e27 100644 --- a/sound/soc/qcom/qdsp6/q6afe.h +++ b/sound/soc/qcom/qdsp6/q6afe.h @@ -5,7 +5,7 @@ #include -#define AFE_PORT_MAX 129 +#define AFE_PORT_MAX 137 #define MSM_AFE_PORT_TYPE_RX 0 #define MSM_AFE_PORT_TYPE_TX 1 @@ -205,6 +205,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; @@ -212,6 +242,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; @@ -221,6 +252,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, 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 bba07899f8fc..a57f45950ae3 100644 --- a/sound/soc/qcom/qdsp6/q6routing.c +++ b/sound/soc/qcom/qdsp6/q6routing.c @@ -514,6 +514,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) }; @@ -949,6 +952,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[] = { @@ -1042,6 +1049,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 Sep 21 21:48:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5313661vqi; Thu, 21 Sep 2023 21:19:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDX6gT+34aXT/oxgSxcmIjnPWZrZzfxLEXkhDxRJRl2/JOq7jrmrcPWf6Eg61DQHTu4xAU X-Received: by 2002:a05:6359:3201:b0:143:9235:9f1f with SMTP id rj1-20020a056359320100b0014392359f1fmr1071474rwb.12.1695356383098; Thu, 21 Sep 2023 21:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695356383; cv=none; d=google.com; s=arc-20160816; b=l2mdxuXrrU4UMC3asSab9DCECdS6DjAe/jSUNCKxq+iwkLZGRKP3a/Ciu45njHUdR/ YIzb000N9Kl/Fpqyhxr9FCR44Q5qT+C6olHk644S3J1cxZNmLcpjjUUMjm9QgNcdlpm2 Isvsyp09uBRUa5qaGlgA1YwK71C82qxjElpLIRJ2c6KoXh7xs1+Q5q31J9c3vxZzDkej hDAnYFLw/p7jQRZLrYf3M+UcN1LSJgwM92MamIUeiUKx5dBSXnAL1rQdJAZVP/WZATBM ZvOu0UPntG1npVNXoECqQx6Zv2CIdn4V3AjEkm2yelkn2uMFwHKU90BTlELlO3Ragi1T rhxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ShOT7wUlq4YSDk3eE/eZp0TDwUGdTXEVDQn3CX7tZhs=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=L0p25If6FSMAqQihFvO4/yk95/dGPdjrp45vGd9iPpC4eg362E2H6bQTXYFni5l6KX 1kEaSQ5YpyhT5bqzq3+x4Jao+Wc6PhFESIT7eam20iMgJ+jQgIPB3tfsRYkJZXzob9nW VlN+zrjoqGHUuAhhg4PomPiNbmKeKYKMtOP+kUSH7kN9xQ5zrhm0hnyjJ0EiqIvczGyw aLtaKfJIkwOEK+4De0VVLPez0VHwpNz2riOgWK4SIE3pUwm41ZgUXazIPGMd8pqZRL0L VIc28EjsPYv39qyySbtM6sSkYZ6/GTcDBFzOmgVU3djtkK8SHsitycvRBfh12dw+fQmp 80sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Ld4sWIew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n9-20020a63f809000000b00577475ee5f6si2975674pgh.618.2023.09.21.21.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Ld4sWIew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2EA398373095; Thu, 21 Sep 2023 14:54:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233072AbjIUVyT (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232359AbjIUVxY (ORCPT ); Thu, 21 Sep 2023 17:53:24 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B51272D; Thu, 21 Sep 2023 14:49:43 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLfEGd020813; Thu, 21 Sep 2023 21:49: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=ShOT7wUlq4YSDk3eE/eZp0TDwUGdTXEVDQn3CX7tZhs=; b=Ld4sWIewrGBjh/Rn/M8BJlcbu5DdLv/IrjUHBVauAQaD7Hu6beztpCidDVXPtMUu5bco 2Y1FEnmQMsaPRXukcjTdrhwuv5BDq7M7/aDbhqH9zt2kGmUcwsXRpzxu/H8KKnySsv50 7dR3B3KHZn7UnBKBSMAHSpQ/GWYOG6OuLeDiiuiBl1rtSrCu/+dd8eqt2Oy/eoN6sFWb C9KIKEKPMefReDHL8+mrl0PtRlvHkM2qzjfZI4RcRt6vr/OqZdN5XoEMZhceDbSN5Jrd SMpDT1crdyh3NwdIpP259bHyRosffXda9IQAM2pkgJ85khlcB4MLh6tXhQ04LxgQAlmI jw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txg8caw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmtpY012387 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:55 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.36; Thu, 21 Sep 2023 14:48:55 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 09/33] ASoC: qdsp6: q6afe: Increase APR timeout Date: Thu, 21 Sep 2023 14:48:19 -0700 Message-ID: <20230921214843.18450-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: TUfuxNKfU12AF1O_P4F_TcAa33izag06 X-Proofpoint-GUID: TUfuxNKfU12AF1O_P4F_TcAa33izag06 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=765 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777710014743899227 X-GMAIL-MSGID: 1777710014743899227 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 f49c69472b5c..72c4e6fe20c4 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -365,7 +365,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 Sep 21 21:48:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 142979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5188554vqi; Thu, 21 Sep 2023 15:51:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHvbw/t+cdn/a1sgvJNASMJnMOxYVDGj+U/G1jdF+MWlM/sR2RCWFp6FDmhWAo6dkskOEX X-Received: by 2002:a05:6a21:7794:b0:14c:d105:2a59 with SMTP id bd20-20020a056a21779400b0014cd1052a59mr5835506pzc.55.1695336680277; Thu, 21 Sep 2023 15:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336680; cv=none; d=google.com; s=arc-20160816; b=razz2pPyzYJP20125d94+3NgI3eJuqMC28QbZl2r39Nutl9sxlIEBsfYQ74UysQjBU A0TD5bd13LzEIytHIk6ArAzecrJILX3qwVC323cyflCta4+sXCwuItQ1EW50UFqsvyYp DdnJ3DgTMbeUBG39kKIoVA9ho7YepVpNcpHiUC47UflFJxaOxjfuzvvfY3St/4WSba/9 6DF3pWkJ7J8o5TUXrppMuvML7dwV1KqEMaOhJE8YBuEkUSNKVn6bFHutE6Q/KEALqDkU rntW5pbYc5YYJuwiAXwYyTHGWO/AFCfZiMy67DPcTQPqLfZaVe0DDmdWOboZ4+IgEpO+ IDRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7Rrx9SgrPONgBc7V4Uk4lPBuOWgmu/HWvdgxqolcgKE=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=NaAqEOjA5/vGOYFBjDpXZZJkWkfjQAuiLTxG0N3Vw67QutEHGKgZLXOYyYf2pdBe4f TeVmZEKlz0Kmlc4R2FFeXxn/HjfU7rp6TJMJTH5yCosHM02scL1+GuOnOLgZUobXxq5G sHk0Kp50M0P1BirRbk2WYEBv17ru1w85vaJ3rAlqScuCtaJFwOv4C4BeTQZ/giu7HqbV nnOdUP2oZyhDci1NFGrx457qNTUisC4nqjny0YjKZQATTN2Oenv+y7N4a3u0xtdQJuVn VV6fQHI580F3NTNtTc4zMYaHONVx9kK3fW/5WW5vgqe40Hwo31zYYknDiadfxTPmJZed HKmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mEukNize; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id me1-20020a17090b17c100b00274e22e2f66si2848838pjb.92.2023.09.21.15.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:51:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=mEukNize; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A0A27808E67A; Thu, 21 Sep 2023 15:04:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbjIUWDl (ORCPT + 29 others); Thu, 21 Sep 2023 18:03:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbjIUWDW (ORCPT ); Thu, 21 Sep 2023 18:03:22 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5D4A213A; Thu, 21 Sep 2023 14:49:41 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLke2U010027; Thu, 21 Sep 2023 21:49: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=7Rrx9SgrPONgBc7V4Uk4lPBuOWgmu/HWvdgxqolcgKE=; b=mEukNizeJq8HSuCNATuoLeuBLMXxC32329I+kXsPq3ASch26xeR4ycVQ0D+jic1jM/WW m5XVXU1G+IF+HyfmgY3e0a5gWNh1aDMXqFnIHbBZDCAh4UqI4Re06hHMyCweVeg93KoF f/Yj7LekHbKhXASWX0PjecOm6+TeZevTrXOU7HphwULb3SjTFG9nY8cV+dzsd0EgRHkL TVn38EZ5uFaqY6jhLZ6l1KpQxpw9OO0MToR1+wLHHL2W9Jtw0BHYLaPMdVCPSndqdj5U hBOYfLHKZ/6wbqDMUmOts6czf8z11cnjdN49wOv/btZ7lnw0y1/knbM9xYqvUcYWyhqa Wg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uknr96t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmufQ009009 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 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.36; Thu, 21 Sep 2023 14:48:55 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 10/33] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Thu, 21 Sep 2023 14:48:20 -0700 Message-ID: <20230921214843.18450-11-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: 7nPDlOZUZGZcRZL67kLr38-0YOtPQgRC X-Proofpoint-ORIG-GUID: 7nPDlOZUZGZcRZL67kLr38-0YOtPQgRC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:04:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689354969389592 X-GMAIL-MSGID: 1777689354969389592 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 | 200 ++++++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 include/sound/q6usboffload.h create mode 100644 sound/soc/qcom/qdsp6/q6usb.c diff --git a/include/sound/q6usboffload.h b/include/sound/q6usboffload.h new file mode 100644 index 000000000000..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 e7b00d1d9e99..bb285af6bb04 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..dd664ad41668 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "q6dsp-lpass-ports.h" +#include "q6afe.h" + +#define SID_MASK 0xF + +struct q6usb_port_data { + struct q6afe_usb_cfg usb_cfg; + struct snd_soc_usb *usb; + struct q6usb_offload priv; + int active_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_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); + + data->usb = snd_soc_usb_add_port(component->dev, &data->priv, q6usb_alsa_connection_cb); + if (IS_ERR(data->usb)) { + dev_err(component->dev, "failed to add usb port\n"); + return -ENODEV; + } + + data->usb->component = component; + + return 0; +} + +static void q6usb_component_remove(struct snd_soc_component *component) +{ + snd_soc_usb_remove_port(component->dev); +} + +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] & 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"); From patchwork Thu Sep 21 21:48:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:910f:0:b0:403:3b70:6f57 with SMTP id r15csp63485vqg; Fri, 22 Sep 2023 20:40:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJ9IB+ZkfQHu4oBIktCqHgNbuN3JNQrFyBjRYiQtjusMYtZT8w6K6L/SDmPF4hD7qMiJQD X-Received: by 2002:a17:902:ecd1:b0:1c0:c3cc:d12a with SMTP id a17-20020a170902ecd100b001c0c3ccd12amr1467846plh.20.1695440451074; Fri, 22 Sep 2023 20:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695440451; cv=none; d=google.com; s=arc-20160816; b=CGD2JZUK8fZRoRjB7vC5+TSrXvB29JGZst62vgtmUOiAsUoh6+xdiSce3Dsx5oQ/fD n7ToO4oec6He+pULqy+O1i1ArGH3xmHc7XVGzo2slu2vrnwtkoyAbVg38LzX2RKGGqwY 9JynB4Pm52d67Kk027tvvpMQ8WsxJfp1ko3u5QMeyv1iNfwtQFW8XBeB+uw8PwBPj5lk 1Gh8c3UOBiYrDPU4WL+QLDr5PooxQT4Jp2pNjrwUoKSSTFxksi/SfKusBSuTPw1UM3OY vgsniwXN7TyZAXk9z6YTTRF9hwSGDf2zf3Yk6lF3iFXq1L8Y9qRLzTHnSppa/p2QYiQE stIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=soLP1wxYe/Q2Qo2eRZtDOZ0+xrFrE1vGLjGfET0ejzk=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=cWFLFh7l4LlLHik6QdLKj5VG5wW6n2Wt1I+nm3fJVH6tmcMJwGTI3Wd492ACpd/pjP AMMAaGfjvvA+XIUjwBneozljQjpk2RKo3itp+prNh9qyX06Ne9uw+ROZdnuaNHuYyfjV ABCBxAeVudChxB0CjsCFpjU9c22UioAL1B8K2njKCOLf/RjUyf+kYLzrhJLFTgE5BnVo MtI4Pl4G0Hh9XuECcTSiblEVtXu2YyReBE9R4gv8yh78Zw2qUtDEgWUylgxHrqmB0gcj LaeS696rqvsBCwX7c08Gihexam5I8TeY/vwHWE6n6GCI1p9+P44FnkWW8PfDV2z7da7g ur0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MBd13M4K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d11-20020a170903230b00b001c1f373ea07si5778786plh.351.2023.09.22.20.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 20:40:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MBd13M4K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7A55C83AA3B0; Thu, 21 Sep 2023 15:02:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232324AbjIUWCV (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbjIUWB7 (ORCPT ); Thu, 21 Sep 2023 18:01:59 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5F21F09; Thu, 21 Sep 2023 14:49:30 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLjmg4011026; Thu, 21 Sep 2023 21:48:57 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=soLP1wxYe/Q2Qo2eRZtDOZ0+xrFrE1vGLjGfET0ejzk=; b=MBd13M4KQTYWDN5PJp0b+fGkS2J4kbOqADB6XQ15hchbs34tjwDXUZv7dodJH7GRxNDI wxYpbbVOa/dOhsfPjUW87xqCTJrYS3jCX6XypuQXotRyPF7puiu8MW7kX1xA0pgavrxx fxPHWpnr6ssTBiwHFuSWTPq1G1CPU6HltZ8FRk0mHoh6PAWI0EzZvYPTq6MZB/Ub7xCo 36YpE6aubhpLjY/EVq5LAUzxEf8CgqGpn78XdCPzvgcw1c8QlcnVgKwQpT3DDVpwjvST PkJqpUmIFLhBeKLPCM/3JOjHqlmUwC3B+EG0iZsEQA7tdqqQHOzGnHPBuuGLeUkwvFPF kA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txpgc0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:57 +0000 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 38LLmu18032095 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 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.36; Thu, 21 Sep 2023 14:48:56 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 11/33] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Thu, 21 Sep 2023 14:48:21 -0700 Message-ID: <20230921214843.18450-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: gZRJBIku5Y-IEr4jpMLSiNuEJBFHlipV X-Proofpoint-GUID: gZRJBIku5Y-IEr4jpMLSiNuEJBFHlipV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=898 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777798166221387105 X-GMAIL-MSGID: 1777798166221387105 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 9 ++++++++ 2 files changed, 69 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1b2edc0fd2e9..1ef6d144aa51 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,49 @@ 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) +{ + int ret; + + mutex_lock(®ister_mutex); + if (platform_ops) { + ret = -EEXIST; + goto out; + } + + platform_ops = ops; +out: + mutex_unlock(®ister_mutex); + 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) +{ + mutex_lock(®ister_mutex); + platform_ops = NULL; + mutex_unlock(®ister_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); /* * disconnect streams @@ -910,7 +953,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 +994,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 +1140,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 +1185,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 Sep 21 21:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5229262vqi; Thu, 21 Sep 2023 17:25:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9qyR+OpnUM9P5NgfPHquzrzoKmb9ZJK2+spn68lePT6Rhvzd2B8oYlb5USsGJU8VmguLk X-Received: by 2002:a17:90b:38d2:b0:268:352c:9d13 with SMTP id nn18-20020a17090b38d200b00268352c9d13mr6947166pjb.0.1695342308143; Thu, 21 Sep 2023 17:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695342308; cv=none; d=google.com; s=arc-20160816; b=CLNwp0vihtl7dNawO/H8bUbmawa/2r+v/p0WuXkBsgaancaSVRmkEj/xUulmgolNGj MA7IRmZS2M8Qplr04675PEvfzlL+JHPLTjDVp6YAyXIETriImfhaqSwWZBRDeddIUDl1 RhqZ+pw7yz9uFJJLYEKhNVLmU/Dj//AvZeE+VClTBBfTeJViwvRfJbmROZ4NULCiXF1q 079FI93I/eXxE+T5oc9J0aRFivHs3WgGUV1Vpv8QsdOtf89laA/V/+LAYcXT61zbKuo1 1glaQRQ1lfHOAKuXgIMYOgvJO4qQ11lINPzU+pGenDX6A5CAH29X+ZsE84NaVVuccix0 XLQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yFEcFuGRN84lI6Aon2p6t/mqpx7vwIPFvRi0lRjtoKU=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=kFhtKH919405f0x3gJY0/rzr3DymwuDEhAk0LmPG1vBUHrawO0KrDmNaoGEDPPfFk1 KYBn7NURaynXpQ3Ea5LvCPGXc6n10KJnke5msiGGLVJWhemLsqcGazACUJ0BLQxEthkX ezXVla2xfaS5lpEH6yreXJTQ6cvlFAn+jxHJCMMg1dSdAcw4IrpwR1cTGUVd6S1BNztt eIiTR6Qn+/iWTC7CLu21rwhjCROajWfvVLX42pbOD1yKrIG1iRc1ZLl8PWMtcSj3P3NC 96NsplEUUuKDldLvKcov+/HSzNsrVYk3PVXjygYnJ5y8sR5IJy0y4oI5oC8ebpjaqT6r 1nsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MkBOapWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u9-20020a17090a410900b00276ac140106si4832415pjf.165.2023.09.21.17.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:25:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MkBOapWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6986C8537F4A; Thu, 21 Sep 2023 14:53:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232459AbjIUVxx (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65BD93AB4; Thu, 21 Sep 2023 14:49:39 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLmw2u015545; Thu, 21 Sep 2023 21:48:58 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=yFEcFuGRN84lI6Aon2p6t/mqpx7vwIPFvRi0lRjtoKU=; b=MkBOapWAULpk48gUkiq7D+VzdAELMtoqdFq++LfV3Aux8BFec/WgJ9LHkiJWb0jCskiA XHp7lu2kFc/TGdnit39aoC3N5orC8Ztfz6n7ySwmC9v9yZoc5I5n5hx7RJpQCpX0k9aM Do/0Y/QnLIQJK9drp5Z+IB5G54pU5YQhbC+iZ9xI5NsYafdYe/TEqbQEORG3TVSeBf8L 5vKUPovQxtXfvAx0X5Hd60JGrz/xRnTtdsMSZXQ2WYq0LLzDqGLbOarsT2yBULIZRRkX 2bXL3SbjP/pcrBCv0tUXzsxjNIBZmD/wTB4YoxH9T9oLleBaKXyMVoogfAczgYga90tU ww== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txpgc0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:57 +0000 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 38LLmuXx012583 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:56 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.36; Thu, 21 Sep 2023 14:48:56 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 12/33] ALSA: usb-audio: Export USB SND APIs for modules Date: Thu, 21 Sep 2023 14:48:22 -0700 Message-ID: <20230921214843.18450-13-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: t3NuzWA7s2A4BELXXJroi-FiH1SExUGF X-Proofpoint-GUID: t3NuzWA7s2A4BELXXJroi-FiH1SExUGF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777695255994071320 X-GMAIL-MSGID: 1777695255994071320 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 1ef6d144aa51..c0b312e264bf 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -1068,6 +1068,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) @@ -1076,6 +1077,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) { @@ -1098,6 +1100,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) { @@ -1111,6 +1114,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 Sep 21 21:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5335761vqi; Thu, 21 Sep 2023 22:25:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAkW88xz6AlNqovaRJ7HjOIpt0THzTOy+RylRmhp0McsBaBjrn6Fz4R0YD2/LE4Q3Zjim+ X-Received: by 2002:a05:6a00:248f:b0:68e:42c9:74e0 with SMTP id c15-20020a056a00248f00b0068e42c974e0mr8385784pfv.3.1695360356448; Thu, 21 Sep 2023 22:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695360356; cv=none; d=google.com; s=arc-20160816; b=i06WXxTqxSRectqskX6BkZLx9tL+wQHahnNRWVT0b7tlioCUXOyboW0wSlLtm4jS0g Rp4MIq640h4DMX80hVmUQXaQ+08a3hhOh6DdVYoFRZpDmxuLPWE7I6DyFdlEbkKAQ+yr UY6x+kzSvALhWo0MbWa9Uy5ZCvROIAs5BOJVgdZH51RVnUkDNovNhfE/+knGTMmgko02 99QkphxGv2DKMBUAaTj82sFp9Pnx67F2GcOUKYr5rqta1NhtFO4OVSP3qyuvqzLJZbCq E1mHWKySAViZ+PAUbe9ZaLIjWHyisHfva+3CothI5PP6/eciZzT3qma0fufn44z19u9/ YPOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vqgnZdckmuHqwFaC8TZurCxmlWYXa/Ehk007pmQMbZ8=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=HKCQ4GWrpeoMXOAVJqwqMKG1HxJwS6xYomXUZ06wNGIcexD2ozPG4zXEHtvPvLydme e+aWw/QdBEtbFPd8S1+yl5b+DMhc1Dde3N/H8U6y7k8+0sGCgaitJ7YpF9ngnuQpW8kA SjTUAWHnLFuyfnEccX7tF2IB3h9+0QEXqZFTfStVOrbSco5AeR0tenj0u9MPTBAD2kOh f6TCgMDP54e64gVaNv32rtmL8Imd6aAwZGB4rKatSHWdZ9E7iPkL8LK0ahRVQIMDbVTB 3iay2zaHsHNVBvrInqAeRvOJ3MEZYuwMGXtdj7PPjfFCZKGm9qLV6DbqiWtAjMG14YGO P1OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RLqeTvYK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q26-20020a631f5a000000b0057c9e0c7bb7si887687pgm.77.2023.09.21.22.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:25:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RLqeTvYK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 52E48808E652; Thu, 21 Sep 2023 15:03:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231986AbjIUWDZ (ORCPT + 29 others); Thu, 21 Sep 2023 18:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbjIUWDE (ORCPT ); Thu, 21 Sep 2023 18:03:04 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B35BD137; Thu, 21 Sep 2023 14:49:40 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKjbbP031840; Thu, 21 Sep 2023 21:49: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=vqgnZdckmuHqwFaC8TZurCxmlWYXa/Ehk007pmQMbZ8=; b=RLqeTvYK8NDf70WL110kS3Kmpn4vXDYKGCWuHGU/zYoowJ3GJLD9ozxOr87Bg16eN9Wq Zd+JAuDmK5emcvQreXD3dHiXdCqVpWdu/2a+mqfIIv9PQY6ezM3fUlZWQB3wAqynNxVU 8nmwtweVUnC3XSZCFu/o2PR54BYI+mitnInf3YiEimMe4+JWKAjeQBfrCbCAheX3OfbN KDSNmBVbTC59NYPqrasWebIhO5j3vAcxCeKjDbv2kzLD93Ovbpq8h0gmSCkjFDD5u/3U 6zjVgq6YVIzt359S+B4BiIt9jMifxXZsYKqrkjVjHvP2kUFnpaplHqDfSERLzx1zEuMs nw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uknr96u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmv5M032099 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:57 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.36; Thu, 21 Sep 2023 14:48:56 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 13/33] dt-bindings: usb: dwc3: Limit num-hc-interrupters definition Date: Thu, 21 Sep 2023 14:48:23 -0700 Message-ID: <20230921214843.18450-14-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: ycws4Fa1Gky-xCbGcyQosTgpE310_DID X-Proofpoint-ORIG-GUID: ycws4Fa1Gky-xCbGcyQosTgpE310_DID X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=603 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:03:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777714181161282387 X-GMAIL-MSGID: 1777714181161282387 Ensure that the number of XHCI secondary interrupters defined for a DWC3 based implementation is limited to 8. XHCI in general can potentially support up to 1024 interrupters. Signed-off-by: Wesley Cheng Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml index a696f23730d3..1be78be1805b 100644 --- a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml @@ -376,6 +376,10 @@ properties: items: enum: [1, 4, 8, 16, 32, 64, 128, 256] + num-hc-interrupters: + maximum: 8 + default: 1 + port: $ref: /schemas/graph.yaml#/properties/port description: From patchwork Thu Sep 21 21:48:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5273848vqi; Thu, 21 Sep 2023 19:22:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEssTddzzp2q1uUwtHbd5poHgxyW91lJNTZtzq9nXblwzg6WtP5tPGVsq2sxpdtB205Nr74 X-Received: by 2002:a05:6a20:dda2:b0:14c:512c:c138 with SMTP id kw34-20020a056a20dda200b0014c512cc138mr5651165pzb.60.1695349365806; Thu, 21 Sep 2023 19:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695349365; cv=none; d=google.com; s=arc-20160816; b=Q4GJ0CfvwBueVLbILQMtiVK8rHXv5OZCmQDs5GVGh6nWtkjYjeDYK6+tIn+chN3TZi iuOANHKqzlTvFHLuiHNPSj9GJJn7sDvaD0auu8QV4I4E818jwWqEGwOkbJgYnR/DGxTx 3aBLOIzWoqQQMc333foOhNQCpEVSorzF4J9jCNiWG0AaacOv1BB27hSkimZ965KNTtYP 3kldKUAK7NP2Yn18HfWT8EDPytYvdi/M5aLNCrx0+X0hXFLfg4LSxaHqMvYE7X+9TQIe JAMKevdcBdoHKllY4TMe1o6xV5PxK4X/tYJ8jeaIIAHKKVdZhopw4kRSr7kAws+y9qw9 WuOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=eMuCxRzjFJNCzXTHvKDH/OMHNktU6HnB8lTCQMc4++s=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=beHIpf+feioqIgnKPeZ3ug9+fF+s42Frnn09UaHWm2B1/VkMbcBXoKI0bIwwDDSKn4 Ydfx40TetyOtWAaGe07wM0+MpKV6QJMYr+5vEAX3U2LdLLFE9eyJMnH1n5pcAKrFFaQH B2l0KTiJ03gzuOa1xWinroe3W1nM1bpSZcyG6fpxdf8O22yNbCC/IQGabSIWJBApjvEj M27gpFglxooINNHglJEY/OqVhKNWpjiUatdvrgLlXLuZQ5Ink8P9zsA83rUMzraiQJw7 zdRVIKQD7DB+nUYRestJ+XOPPjt0U68cNDZ7QXnmbgoCd2TZ69cbN8Nx/K8kmrBf7L+H krtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XOpSG5LQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y6-20020a63e246000000b00569161a1885si2654691pgj.288.2023.09.21.19.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 19:22:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XOpSG5LQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4075680297A4; Thu, 21 Sep 2023 14:55:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233056AbjIUVyK (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbjIUVxX (ORCPT ); Thu, 21 Sep 2023 17:53:23 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCD764483; Thu, 21 Sep 2023 14:49:42 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLNSwD017648; Thu, 21 Sep 2023 21:49: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=eMuCxRzjFJNCzXTHvKDH/OMHNktU6HnB8lTCQMc4++s=; b=XOpSG5LQ+MRCluIjn3D2eElcX2j0zSDjH0tI7QtqpWxdSIaDwYH+wOeF7+DRkWutKtRV HlpCZLxwpAmxZBwNXX/Jcgh++MONSRggkEX1TC9O7fP9fzX7q+wy6G1P8v5sp+/eHdiU ll9TObpu77CA8W0yVOn1odN+jERkWv8CGzl3ZXJrtZhf1hEN2aPMqqhXIYGUpNRvEV14 UNJ3w8JPoV5XgIazBWLVUBb5AGgwy3y8J4jziZvN+Vb8rqlKPBhz9BVsNitRiZ9LQJD4 FuhBFUUFHdV2xQEa7Hrtn+6zd9uDLlIsEW3bzBC5qkUBcfA1JmS3ABgFEKbEH19CQRJa 3Q== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txg8cax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmvTT009012 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:57 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.36; Thu, 21 Sep 2023 14:48:57 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 14/33] dt-bindings: usb: xhci: Add num-hc-interrupters definition Date: Thu, 21 Sep 2023 14:48:24 -0700 Message-ID: <20230921214843.18450-15-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: I3sUxCcARr2qP7pPqXGP1D9O-m3ml8CD X-Proofpoint-GUID: I3sUxCcARr2qP7pPqXGP1D9O-m3ml8CD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=638 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:55:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777702656994188581 X-GMAIL-MSGID: 1777702656994188581 Add the definition for how many interrupts the XHCI host controller should allocate. XHCI can potentially support up to 1024 interrupters, which implementations may want to limit. Reviewed-by: Rob Herring Signed-off-by: Wesley Cheng --- Documentation/devicetree/bindings/usb/usb-xhci.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.yaml b/Documentation/devicetree/bindings/usb/usb-xhci.yaml index 180a261c3e8f..4238ae896ef6 100644 --- a/Documentation/devicetree/bindings/usb/usb-xhci.yaml +++ b/Documentation/devicetree/bindings/usb/usb-xhci.yaml @@ -29,6 +29,12 @@ properties: description: Interrupt moderation interval default: 5000 + num-hc-interrupters: + description: Maximum number of interrupters to allocate + $ref: /schemas/types.yaml#/definitions/uint16 + minimum: 1 + maximum: 1024 + additionalProperties: true examples: From patchwork Thu Sep 21 21:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5370828vqi; Fri, 22 Sep 2023 00:00:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHum0fLqFvIfoCSXQP91cKMbijdY5oSymeiG1Kiv2uimKTRQcShj5AJc2Ek/VOM2lqL437v X-Received: by 2002:a05:6102:51b:b0:452:58a1:112 with SMTP id l27-20020a056102051b00b0045258a10112mr7251823vsa.3.1695366025575; Fri, 22 Sep 2023 00:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366025; cv=none; d=google.com; s=arc-20160816; b=Y3+gw5lR6eVZv438W043lVRTjPnr2CkDD9Qs+CM6g5+kF5hDBd7l7UBLA7v7hVDemx x5lHz7fzXRy8EtW7ig9Q4+RnBjx8u2QvDYveQXbz3JZMymHg42pSLTkmvu/yumRc+nr8 2IeGPrKl0Dd1VjdiC1eEgQNydUQkyDYwl/yGBvg3t4diZoSXkGEB9R/exdNnMlq/OkF5 xQJxr+pQR2Wa39JlZYNKLU9+6oTQpkFPtSJ7/eZSu7pKwMOprDVmeRqehJhhBolGtE4V TYPtbHuqv4cXUygurCOeIlmyvB2Sxwy7KCqWQ5ex/FFbL/i2yEc+IIOBK/BpW32Kohm1 QSCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NS6wPrfCi20AN06ZF+zNXfCmSrqpuR/CsstYpwApEC4=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=YiuH17D8x0/W+Z60OLJ6k8IsQ+Rbdc+tSEfDZO5vmaggmP81d4s3jX94J8cEgEkaaT RquHJuqhmM2zIruIBZQ0toAwVsVjptkv3yicQoA+CjHEY5Ysg9WUO0mcTgaM6gQwjjqM KwCHTUz0cWcMUnYCLmGmeYE6IAGUR9oQ1xD6WxkZZTn7y+s9D8MxnlROWI6tmRaNWsM1 8NxpogUVZ1YtG09S/C7RWOmnh+d7CoITOyYM7UrkLMsbRs8Gbmc7oKfHIf4vxokuhCd9 jeLQw7HYa/s2jPW/IcK7rtTqzPx1BozWeUAjltHnqY/UZB7ZO4fDuy0MD7GfW/S68kwD G+NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=carptqq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 184-20020a6302c1000000b00565322ef4f1si3245541pgc.348.2023.09.22.00.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:00:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=carptqq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0A3B883037E6; Thu, 21 Sep 2023 15:15:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbjIUWPc (ORCPT + 29 others); Thu, 21 Sep 2023 18:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232312AbjIUWPU (ORCPT ); Thu, 21 Sep 2023 18:15:20 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 060BB3A9A; Thu, 21 Sep 2023 14:49:38 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLc4NI009568; Thu, 21 Sep 2023 21:48:59 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=NS6wPrfCi20AN06ZF+zNXfCmSrqpuR/CsstYpwApEC4=; b=carptqq+0eAOGQmO/xFjJSz5Kv6qhMIkgg+nPID+pUCcqgSVhg3cOheFaNeCv9Io9kVh ZxRauYD+8awkpVRdTOa3SL/NpD5FHO51PQ8buV2hfPHI2w3N3Y6bP1QM1hPcpvnf9aBp gD8or46E1eOXsf+UNGgxzcIAeDbuik17mG1h1JH0R4wJ9W1SXYpQcjv9F59Dsr7eXIXy MIXZ3OGyOpQv2iTmEexIwF2Yx0V+9PEdTNYeBPIPACNzJc3k5XFnIRrWKcjP8RSwHFgv PCgOn5e3JR+G27hmDJjQRJ/S58YsDM4qOLCPls0oKLu4+240K5ZfTaxGaAD0WtgexRGO JA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uf2g9ph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:58 +0000 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 38LLmvem032102 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:57 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.36; Thu, 21 Sep 2023 14:48:57 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 15/33] usb: dwc3: Specify maximum number of XHCI interrupters Date: Thu, 21 Sep 2023 14:48:25 -0700 Message-ID: <20230921214843.18450-16-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: N0tw2pPZ1ARpxdW2kNv-qehwZixOhydm X-Proofpoint-ORIG-GUID: N0tw2pPZ1ARpxdW2kNv-qehwZixOhydm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_18,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=667 mlxscore=0 impostorscore=0 clxscore=1015 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:15:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777720125584083915 X-GMAIL-MSGID: 1777720125584083915 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. 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 9c6bf054f15d..fb9fec8b7058 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1385,6 +1385,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; @@ -1407,6 +1408,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); @@ -1450,6 +1454,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) @@ -1532,6 +1542,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 a69ac67d89fe..5268b2628e39 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1051,6 +1051,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 @@ -1279,6 +1280,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 61f57fe5bb78..79ce359c342a 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -61,7 +61,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; @@ -107,6 +107,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 Sep 21 21:48:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5286692vqi; Thu, 21 Sep 2023 20:02:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1j9pmy1nhGXjgHOFvhGHWF3exomqHiZeQsJH0HuvPCrM2nSMRq4vxcLr44sWWG1tyz4sY X-Received: by 2002:a05:6a20:1608:b0:15a:7d2:7594 with SMTP id l8-20020a056a20160800b0015a07d27594mr8127382pzj.11.1695351770039; Thu, 21 Sep 2023 20:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695351770; cv=none; d=google.com; s=arc-20160816; b=U7T9b3w02iuyw8cHXa0O26jJZqi9lcAdVeTOrlcXx524YchaFgqEUcEWnmXbwfPN2Y IOqkrUeuc3Z99xIuWoLifZpxAF8LydvccJzbth5O9OGBhgt+EDpTSqif4uENahX+A1As Q/3n62sCEzG4svSPQ72echevr2lHahlHTjQuMcJsrQR86EuJTU5JEQM3hENlpBkoPoHc bTJCo3jYphYHDAvMxv7w7FFMX13sUP4Z3mWUQTqcBT7sdE0jQy5wvsbDL65T8QqfQeYO 1LdQ7B9PbR9zn8GFNLb/0HA8sZR0jJ6J4fhryFjpGuCPat9IIy34IoXf/z/u4QQrdGyP C8hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=v88cF5DfrmQ11xFFw1qondVS974WsoPZKgPh8eL+d3w=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=KS8Wb34gtIQ1ghMEY383742R1ScOFthbaikO5xHO8+moolqua24SUNi53UOvqtYksV kCWNZTAfKF7oBhK6T/O1iWv68t1rdBPE8FgDF+CrcUhCqeXrnKq3XTrmPnVdpTsny7kK hJUY9XWmbTvKTSCOspScLeaKsWh+0W3qz5+RqxyXdwyiEOqnkCZQOHI4XbSk2zblaPq4 a/XcOGp6dj0M0r+Jq4fuSgc0rqnD1wJenbcSv39UXUmfhy3bVYIaH51b21snz5FeCwF/ kqvKig+A0gBGWEfKuyiC0sOZVpRCqBZ0118qjZCK+vZPZ7HCeKjU4jOivuAE1zWXU6yT AoRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ZHihegQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q7-20020a170902a3c700b001c3e40dfff0si2729391plb.359.2023.09.21.20.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ZHihegQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 89B078022C0C; Thu, 21 Sep 2023 14:56:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233086AbjIUVyc (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232813AbjIUVxZ (ORCPT ); Thu, 21 Sep 2023 17:53:25 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E7BB211E; Thu, 21 Sep 2023 14:49:49 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLmbvk019252; Thu, 21 Sep 2023 21:49: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=v88cF5DfrmQ11xFFw1qondVS974WsoPZKgPh8eL+d3w=; b=ZHihegQhkgThKW+Tl+jgwnRUlESO98D/ideP4zf6NANPNNX0m9a1E+o/u2Oy22JcdF/5 ItlOVrUsUYmnrPP5aZra9Hyn/bMgRjzgh4qwZ+3w/Vk12Mg26ivdypz1dYSHZ4y9zoaP 59UPa1PGkH7OTrDhTfPl71khjjuMIgxILDUtZNJR+0+wO4+x026MarxyfJ/DY1FTcqgs Ig3woUKbgUZoS7l47ynjQe9Hu4FtOxRes26s4z1uwSoO85vjJ5az5neeojkvyqRiFtal qUatswLb2u9fKbCGLxXXhp0Dlpx6zK1GUZUe00FQVRp17Hr6TCd/arqNOWUSM8fwp53L JA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8um1r96s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:25 +0000 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 38LLmwNd032682 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:58 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.36; Thu, 21 Sep 2023 14:48:57 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 16/33] usb: host: xhci-plat: Set XHCI max interrupters if property is present Date: Thu, 21 Sep 2023 14:48:26 -0700 Message-ID: <20230921214843.18450-17-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: G6y03AlcWSdxw9lfBzOQdyN38mIHZsSP X-Proofpoint-GUID: G6y03AlcWSdxw9lfBzOQdyN38mIHZsSP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:56:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777705177597779785 X-GMAIL-MSGID: 1777705177597779785 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 28218c8f1837..d01318f89278 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -251,6 +251,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); } hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0); From patchwork Thu Sep 21 21:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5313374vqi; Thu, 21 Sep 2023 21:18:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEM4lhqrnfqBtl9X4fMkpZzVSyB9D90E0pCcVNhKGAdu5R66A7UAm1zd+Lih1y5iljSfv1W X-Received: by 2002:a17:90b:f12:b0:26f:b733:6887 with SMTP id br18-20020a17090b0f1200b0026fb7336887mr6860692pjb.27.1695356329760; Thu, 21 Sep 2023 21:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695356329; cv=none; d=google.com; s=arc-20160816; b=v4frsbXsxvycMfiZ9Q/Qa8SBhCZpbXu6QqNEfBMA84HxYMTOdhLzfNXfNBwF2lSC+h GveC5j/gm/rYYg7V1YaFDfr/f36oGoyp8YvMLddAA1PFYYYn3/tgGErnkCrK73VRDOLS 4YfK7ibqXhWY8g+J2tJMwnKKTzw3qCxgqp1jEXNBxW/iU8bXPWX4PIUDziH0Iaf95S/f mUq6/3npEX/WVtl2tViLUVYBC9PdCM7ImF1k8/gdYTFC25uE3WeZnGqT3hhTK7sfX7DK xUd4CTmJN0xIRLRT11LBumgV6iUJdMZFzWAEH1O9nVVVScewgDpQyicgZ5YTXue3jaex DKqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SG9o3eOQsGYWtNJxelFkBEOj4dc84BORgsU3tNFO0jo=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=ONlQxfcjvczdM6ovtFD1kFnw3H6QYu33pwDVv9TB9ks/XNnfWT3X/7TYfg2gmLONdT cMtQHbSp509MgDSz+vLkydNRyQqqoMaNb5RPEfBxWum84lMPIb6p+n4B6f8pBucSKLze fYkoc5tXuPm86M7q+0Cz+NN+I8y8IIo72njcanjOUJqWXJDLsdLXkaUVJ0A9tdTfPvxL UoStzA5D6dAZ+YODhAxMolTCqqIxjLbVcGOkelj846Gn3pTrzwqIGfwxCEV3fH1x1lbL S+5zCw4KK5gurfwVdzic7OFEqDrjUTy0jPGenVnxW3feHvAzgf1LP63/h2LOj4f+ztDw 3PSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AvsiZwZv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n21-20020a170903405500b001bdc664cd65si2682523pla.165.2023.09.21.21.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:18:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AvsiZwZv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B02B28539199; Thu, 21 Sep 2023 14:54:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233052AbjIUVyX (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232792AbjIUVxY (ORCPT ); Thu, 21 Sep 2023 17:53:24 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4392610D9; Thu, 21 Sep 2023 14:49:42 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKGLW7015079; Thu, 21 Sep 2023 21:49: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=SG9o3eOQsGYWtNJxelFkBEOj4dc84BORgsU3tNFO0jo=; b=AvsiZwZvIzy8mDGgu+2b7lXAp1BrJDj3OFeKpNqs4IPn3RLuYfo9HVIjEqMbr8hcxzs3 gZYtKMNlpCnKyPLNDes15pUZFmZsOklst+HuTMlFnGE1wXzOVxn6246kiaWlquWSnCLk rVVFO6LIcDDxAwCgl5xislUl8sgcayIraK1r+N9TODBNjkqXryB1tuv7dIEVDG6eJcYC EqjCB9qkKKzGImejHTUPQdsItPL9pxEniMv7AW5+s9gediczHpj2kJ9Ng+cUqRfh3FHu nvO790w7NpcquBFvKtN71DkLBCJoejT7QiUcfBYtGdVvC4g4cw+XfihiylO6zovnyW9P ow== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u5n0bq4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:18 +0000 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 38LLmwFV032695 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:58 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.36; Thu, 21 Sep 2023 14:48:57 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 17/33] ALSA: usb-audio: qcom: Add USB QMI definitions Date: Thu, 21 Sep 2023 14:48:27 -0700 Message-ID: <20230921214843.18450-18-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: D3ObaRTlykKNmcDfqZM51GKq5THCCqML X-Proofpoint-GUID: D3ObaRTlykKNmcDfqZM51GKq5THCCqML X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777709958630350755 X-GMAIL-MSGID: 1777709958630350755 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..bdfd67d980eb --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.c @@ -0,0 +1,892 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include + +#include "usb_audio_qmi_v01.h" + +static 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 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 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 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, + }, +}; + +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, + }, +}; + +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, + }, +}; + +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..68e3842affc5 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.h @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2023 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 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 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 struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[]; + +#endif From patchwork Thu Sep 21 21:48:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5414024vqi; Fri, 22 Sep 2023 01:47:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2of8yVV03XJwZYvFUIoDBTFNtGYSojU4faU1ukYyWo8ECBO/HnJ4RBjVYlNrDCDLk+/QS X-Received: by 2002:a05:6e02:c6d:b0:349:8bd3:b5c4 with SMTP id f13-20020a056e020c6d00b003498bd3b5c4mr7925928ilj.5.1695372422625; Fri, 22 Sep 2023 01:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695372422; cv=none; d=google.com; s=arc-20160816; b=bqSAoSO5NYb7XNTZMIp2G1mGA6fWWNTn7cZJrqrPaWqUbccpS71mUc03xYQx5oBUzw 4iY02OPiOmXN5Iy0oidHd1l77a+C/2uSoKm9NOWYS9kJNPTlRTjxVW4JGCpXuLE1kNeG SUxr4qDqge/htMW00aeNV1icZrKk4qqRaOEx0SzHw8vj//1K9DXMUlUVSmVldhH16nHv 5wXh6JDYr4m7WxMzmN06Jq6OcNJIT0sv+MXbfnw0expBNMOZdZsTuOCzfkiYJiuK3HYe 5GLFZUAP0Q+BzSOK/yIMWqeSmxZTk22OhxrsU9iuQ9rwEFzcOK+srN/u5Pu6Vt/3RcBw m5Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dhGbM7ayinA1lAcDcXyfci4aDAFS3fIWjBoZnbMN/ec=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=zLAeHpPHSzYmD7aAXxqaU2DBXLhnm1aYZbYy3QKLPEFCGI/mdwiO6gk1+Uj5pn4Zsy XUzeKuKy48ggkmCImQDlfg4Ri78eKdREjpP2mS7221ZHb7pleZurQVNfx1gg9k6tRfMI UDyCEMclWTbWQ7BE3B/LPwqAKqPIWInlBy26lhfRw4HikiOHIqbozE7W00c5zCd9lhBQ 0XTr4NR/rWcN+VpGG1pdPfYXkZird/sgwNKQe5KjKaBAiipY7MVVIAPJ92g9075Vda4o q7o43TRzcqlhJuhWLDC1mq+vr4nnwadRLe8JY8YIGDqh8mudSNun4yQ39G63t9k70cUH ZoQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pl+c5ltV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00577461b010fsi3323944pgb.685.2023.09.22.01.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:47:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pl+c5ltV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7A5FB808E659; Thu, 21 Sep 2023 15:03:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232844AbjIUWDL (ORCPT + 29 others); Thu, 21 Sep 2023 18:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232199AbjIUWC7 (ORCPT ); Thu, 21 Sep 2023 18:02:59 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A24112693; Thu, 21 Sep 2023 14:49:49 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLAiPW024548; Thu, 21 Sep 2023 21:49: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=dhGbM7ayinA1lAcDcXyfci4aDAFS3fIWjBoZnbMN/ec=; b=pl+c5ltVqf9j9ddoaPg8+ZpPf44o1J+gBiI5KwYyBnxpJcnYG4VaapK5TS2tua+RcXYN FS1HjyoNIKmqCti9Km/VqCUN7VnZ3PomGbsUZuMsWuVcJ3k4Hy76/1X8mCYqqGbQp8iZ QcPhpfWi4/3sOQ0YIcdBEVveKjIHw6k4CnpKdS+8wrr2zkV/DykTc7vSjQlK3WNYNOXA h3xmQjniWfTwVCN95LBK323sENBaDCFWj3YiSHziBK2OTHLo0YznVusTfW8ccvgu95F1 FrUJDK0I7yDZFBXon54QksG/qN3/LiZRlk4jEUDIE9Ohf2b2R98XuRwt59X3x7MUwoA1 ig== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txg8cay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmww8031080 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:58 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.36; Thu, 21 Sep 2023 14:48:58 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 18/33] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Date: Thu, 21 Sep 2023 14:48:28 -0700 Message-ID: <20230921214843.18450-19-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: iSpxppz9RPMnJ09AwZtyrGGTrZoAkSZ3 X-Proofpoint-GUID: iSpxppz9RPMnJ09AwZtyrGGTrZoAkSZ3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:03:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777726833315805680 X-GMAIL-MSGID: 1777726833315805680 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 | 1830 +++++++++++++++++++++++++++++ 4 files changed, 1848 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 db5ff76d0e61..fa624a4052ae 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..f0977bd8084f --- /dev/null +++ b/sound/usb/qcom/qc_audio_offload.c @@ -0,0 +1,1830 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2023 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 +#include "../usbaudio.h" +#include "../card.h" +#include "../endpoint.h" +#include "../helper.h" +#include "../pcm.h" +#include "../format.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_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; + u32 sid; + u32 intr_num; + struct xhci_interrupter *ir; + struct xhci_ring *sec_ring; + struct iommu_domain *domain; + + /* 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_stream *as; + struct snd_usb_substream *subs = NULL; + struct snd_usb_audio *chip; + + 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, bus_intval_mult, 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; + unsigned long va = 0; + size_t tmp_size = size; + bool found = false; + + if (size % PAGE_SIZE) { + dev_dbg(uaudio_qdev->dev, "size %zu is not page size multiple\n", + size); + goto done; + } + + if (size > *curr_iova_size) { + dev_dbg(uaudio_qdev->dev, "size %zu > curr size %zu\n", + size, *curr_iova_size); + goto done; + } + if (*curr_iova_size == 0) { + dev_dbg(uaudio_qdev->dev, "iova mapping is full\n"); + 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; + dev_dbg(uaudio_qdev->dev, "exact size: %zu found\n", size); + goto done; + } else if (!info->in_use && tmp_size >= info->size) { + if (!new_info) + new_info = info; + dev_dbg(uaudio_qdev->dev, "partial size: %zu found\n", + info->size); + 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: + if (!found) + dev_err(uaudio_qdev->dev, "unable to find %zu size iova\n", + size); + else + dev_dbg(uaudio_qdev->dev, + "va:0x%08lx curr_iova:0x%08lx curr_iova_size:%zu\n", + va, *curr_iova, *curr_iova_size); + + 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) { + dev_err(uaudio_qdev->dev, "va %lu is not in use\n", + va); + 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) { + dev_err(uaudio_qdev->dev, "unable to find the va %lu\n", va); + return; + } +done: + *curr_iova_size += size; + dev_dbg(uaudio_qdev->dev, "curr_iova_size %zu\n", *curr_iova_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: + dev_err(uaudio_qdev->dev, "unknown mem type %d\n", mtype); + unmap = false; + } + + if (!unmap || !mapped_iova_size) + return; + + dev_dbg(uaudio_qdev->dev, "type %d: unmap iova 0x%08lx size %zu\n", + mtype, va, mapped_iova_size); + + umap_size = iommu_unmap(uaudio_qdev->domain, va, mapped_iova_size); + if (umap_size != mapped_iova_size) + dev_err(uaudio_qdev->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) +{ + unsigned long va_sg, va = 0; + bool map = true; + int i, ret; + size_t sg_len, total_len = 0; + struct scatterlist *sg; + phys_addr_t pa_sg; + int 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->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->domain, va_sg, pa_sg, sg_len, + prot, GFP_KERNEL); + if (ret) { + dev_err(uaudio_qdev->dev, "mapping failed ret%d\n", ret); + dev_err(uaudio_qdev->dev, + "type:%d, pa:%pa iova:0x%08lx sg_len:%zu\n", + mtype, &pa_sg, va_sg, sg_len); + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va = 0; + goto done; + } + dev_dbg(uaudio_qdev->dev, + "type:%d map pa:%pa to iova:0x%08lx len:%zu offset:%u\n", + mtype, &pa_sg, va_sg, sg_len, sg->offset); + va_sg += sg_len; + total_len += sg_len; + } + + if (size != total_len) { + dev_err(uaudio_qdev->dev, "iova size %zu != mapped iova size %zu\n", + size, total_len); + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va = 0; + } + return va; + +skip_sgt_map: + dev_dbg(uaudio_qdev->dev, "type:%d map pa:%pa to iova:0x%08lx size:%zu\n", + mtype, &pa, va, size); + + ret = iommu_map(uaudio_qdev->domain, va, pa, size, prot, GFP_KERNEL); + if (ret) + dev_err(uaudio_qdev->dev, + "failed to map pa:%pa iova:0x%lx type:%d ret:%d\n", + &pa, va, mtype, ret); +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) +{ + struct usb_hcd *hcd = bus_to_hcd(dev->udev->bus); + + 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_remove_secondary_interrupter(hcd, uaudio_qdev->ir); + uaudio_qdev->ir = NULL; + } +} + +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->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 intf_info *info; + int idx, if_idx; + struct snd_usb_substream *subs; + struct snd_usb_audio *chip; + + 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); + 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); + 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_usb_audio *chip = subs->stream->chip; + struct snd_pcm_hw_params params; + struct snd_mask *m; + struct snd_interval *i; + int ret; + + _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->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; +} + +/** + * 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 usb_interface *iface; + struct usb_host_interface *alts; + struct usb_interface_descriptor *altsd; + struct usb_interface_assoc_descriptor *assoc; + struct usb_host_endpoint *ep; + struct uac_format_type_i_continuous_descriptor *fmt; + struct uac_format_type_i_discrete_descriptor *fmt_v1; + struct uac_format_type_i_ext_descriptor *fmt_v2; + struct uac1_as_header_descriptor *as; + struct xhci_interrupter *ir; + struct q6usb_offload *data; + struct usb_hcd *hcd; + int ret; + int protocol, card_num, pcm_dev_num; + void *hdr_ptr; + u8 *xfer_buf; + unsigned int data_ep_pipe = 0, sync_ep_pipe = 0; + u32 len, mult, remainder, xfer_buf_len; + unsigned long va, tr_data_va = 0, tr_sync_va = 0; + phys_addr_t xhci_pa, xfer_buf_pa, tr_data_pa = 0, tr_sync_pa = 0; + struct sg_table sgt; + struct page *pg; + bool dma_coherent; + + iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface); + if (!iface) { + dev_err(uaudio_qdev->dev, "interface # %d does not exist\n", + subs->cur_audiofmt->iface); + ret = -ENODEV; + goto err; + } + + assoc = iface->intf_assoc; + 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; + + alts = &iface->altsetting[subs->cur_audiofmt->altset_idx]; + altsd = get_iface_desc(alts); + protocol = altsd->bInterfaceProtocol; + + /* get format type */ + if (protocol != UAC_VERSION_3) { + fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, + UAC_FORMAT_TYPE); + if (!fmt) { + dev_err(uaudio_qdev->dev, + "%u:%d : no UAC_FORMAT_TYPE desc\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + ret = -ENODEV; + goto err; + } + } + + if (!uadev[card_num].ctrl_intf) { + dev_err(uaudio_qdev->dev, "audio ctrl intf info not cached\n"); + ret = -ENODEV; + goto err; + } + + if (protocol != UAC_VERSION_3) { + hdr_ptr = snd_usb_find_csint_desc(uadev[card_num].ctrl_intf->extra, + uadev[card_num].ctrl_intf->extralen, NULL, + UAC_HEADER); + if (!hdr_ptr) { + dev_err(uaudio_qdev->dev, "no UAC_HEADER desc\n"); + ret = -ENODEV; + goto err; + } + } + + if (protocol == UAC_VERSION_1) { + struct uac1_ac_header_descriptor *uac1_hdr = hdr_ptr; + + as = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, + UAC_AS_GENERAL); + if (!as) { + dev_err(uaudio_qdev->dev, + "%u:%d : no UAC_AS_GENERAL desc\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + ret = -ENODEV; + goto err; + } + resp->data_path_delay = as->bDelay; + resp->data_path_delay_valid = 1; + fmt_v1 = (struct uac_format_type_i_discrete_descriptor *)fmt; + resp->usb_audio_subslot_size = fmt_v1->bSubframeSize; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(uac1_hdr->bcdADC); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_2) { + struct uac2_ac_header_descriptor *uac2_hdr = hdr_ptr; + + fmt_v2 = (struct uac_format_type_i_ext_descriptor *)fmt; + resp->usb_audio_subslot_size = fmt_v2->bSubslotSize; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(uac2_hdr->bcdADC); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_3) { + if (assoc->bFunctionSubClass == + UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) { + dev_err(uaudio_qdev->dev, "full adc is not supported\n"); + ret = -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(uaudio_qdev->dev, + "%d: %u: Invalid wMaxPacketSize\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + ret = -EINVAL; + goto err; + } + resp->usb_audio_subslot_size_valid = 1; + } else { + dev_err(uaudio_qdev->dev, "unknown protocol version %x\n", + protocol); + ret = -ENODEV; + goto err; + } + + resp->slot_id = subs->dev->slot_id; + resp->slot_id_valid = 1; + + memcpy(&resp->std_as_opr_intf_desc, &alts->desc, sizeof(alts->desc)); + resp->std_as_opr_intf_desc_valid = 1; + + ep = usb_pipe_endpoint(subs->dev, subs->data_endpoint->pipe); + if (!ep) { + dev_err(uaudio_qdev->dev, "data ep # %d context is null\n", + subs->data_endpoint->ep_num); + ret = -ENODEV; + goto err; + } + data_ep_pipe = subs->data_endpoint->pipe; + memcpy(&resp->std_as_data_ep_desc, &ep->desc, sizeof(ep->desc)); + resp->std_as_data_ep_desc_valid = 1; + + ret = xhci_sideband_add_endpoint(uadev[card_num].sb, ep); + if (ret < 0) { + dev_err(uaudio_qdev->dev, "failed to get data ep ring address\n"); + ret = -ENODEV; + goto err; + } + + pg = sg_page(uadev[card_num].sb->sgt->sgl); + tr_data_pa = page_to_phys(pg); + resp->xhci_mem_info.tr_data.pa = uadev[card_num].sb->ring->first_seg->dma; + + if (subs->sync_endpoint) { + ep = usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe); + if (!ep) { + dev_err(uaudio_qdev->dev, "implicit fb on data ep\n"); + goto skip_sync_ep; + } + sync_ep_pipe = subs->sync_endpoint->pipe; + memcpy(&resp->std_as_sync_ep_desc, &ep->desc, sizeof(ep->desc)); + resp->std_as_sync_ep_desc_valid = 1; + + ret = xhci_sideband_add_endpoint(uadev[card_num].sb, ep); + if (ret < 0) { + dev_err(uaudio_qdev->dev, + "failed to get sync ep ring address\n"); + ret = -ENODEV; + goto drop_data_ep; + } + + pg = sg_page(uadev[card_num].sb->sgt->sgl); + tr_sync_pa = page_to_phys(pg); + resp->xhci_mem_info.tr_sync.pa = uadev[card_num].sb->ring->first_seg->dma; + } + +skip_sync_ep: + data = snd_soc_usb_get_priv_data(usb_get_usb_backend(subs->dev)); + if (!data) + goto drop_sync_ep; + + uaudio_qdev->domain = data->domain; + uaudio_qdev->sid = data->sid; + uaudio_qdev->intr_num = data->intr_num; + uaudio_qdev->dev = data->dev; + + 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; + } + /* map xhci data structures PA memory to iova */ + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + + /* event ring */ + hcd = bus_to_hcd(subs->dev->bus); + ir = xhci_create_secondary_interrupter(hcd, uaudio_qdev->intr_num); + if (!ir) { + dev_err(uaudio_qdev->dev, "failed to fetch interrupter\n"); + ret = -ENODEV; + goto drop_sync_ep; + } + + dma_get_sgtable(subs->dev->bus->sysdev, &sgt, ir->event_ring->first_seg->trbs, + ir->event_ring->first_seg->dma, TRB_SEGMENT_SIZE); + xhci_pa = page_to_phys(sg_page(sgt.sgl)); + if (!xhci_pa) { + dev_err(uaudio_qdev->dev, + "failed to get sec event ring address\n"); + ret = -ENODEV; + goto free_sec_ring; + } + sg_free_table(&sgt); + + uaudio_qdev->ir = ir; + resp->interrupter_num = ir->intr_num; + + va = uaudio_iommu_map(MEM_EVENT_RING, dma_coherent, xhci_pa, PAGE_SIZE, + NULL); + if (!va) { + ret = -ENOMEM; + goto free_sec_ring; + } + + resp->xhci_mem_info.evt_ring.va = PREPEND_SID_TO_IOVA(va, + uaudio_qdev->sid); + resp->xhci_mem_info.evt_ring.pa = ir->event_ring->first_seg->dma; + resp->xhci_mem_info.evt_ring.size = PAGE_SIZE; + uaudio_qdev->er_mapped = true; + + resp->speed_info = get_speed_info(subs->dev->speed); + if (resp->speed_info == USB_QMI_DEVICE_SPEED_INVALID_V01) { + ret = -ENODEV; + goto unmap_er; + } + + resp->speed_info_valid = 1; + + /* data transfer ring */ + va = uaudio_iommu_map(MEM_XFER_RING, dma_coherent, tr_data_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto unmap_er; + } + + tr_data_va = va; + resp->xhci_mem_info.tr_data.va = PREPEND_SID_TO_IOVA(va, + uaudio_qdev->sid); + resp->xhci_mem_info.tr_data.size = PAGE_SIZE; + + /* sync transfer ring */ + if (!resp->xhci_mem_info.tr_sync.pa) + goto skip_sync; + + xhci_pa = resp->xhci_mem_info.tr_sync.pa; + va = uaudio_iommu_map(MEM_XFER_RING, dma_coherent, tr_sync_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto unmap_data; + } + + tr_sync_va = va; + resp->xhci_mem_info.tr_sync.va = PREPEND_SID_TO_IOVA(va, + uaudio_qdev->sid); + resp->xhci_mem_info.tr_sync.size = PAGE_SIZE; + +skip_sync: + /* xfer buffer, multiple of 4K only */ + if (!xfer_buf_len) + xfer_buf_len = PAGE_SIZE; + + mult = xfer_buf_len / PAGE_SIZE; + remainder = xfer_buf_len % PAGE_SIZE; + len = mult * PAGE_SIZE; + len += remainder ? PAGE_SIZE : 0; + + if (len > MAX_XFER_BUFF_LEN) { + dev_err(uaudio_qdev->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) { + ret = -ENOMEM; + goto unmap_sync; + } + + dma_get_sgtable(subs->dev->bus->sysdev, &sgt, xfer_buf, xfer_buf_pa, + len); + va = uaudio_iommu_map(MEM_XFER_BUF, dma_coherent, xfer_buf_pa, len, + &sgt); + if (!va) { + ret = -ENOMEM; + goto unmap_sync; + } + + resp->xhci_mem_info.xfer_buff.pa = xfer_buf_pa; + resp->xhci_mem_info.xfer_buff.size = len; + + resp->xhci_mem_info.xfer_buff.va = PREPEND_SID_TO_IOVA(va, + uaudio_qdev->sid); + + resp->xhci_mem_info_valid = 1; + + sg_free_table(&sgt); + + 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_sync; + } + 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 = 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 = tr_sync_va; + uadev[card_num].info[info_idx].sync_xfer_ring_size = PAGE_SIZE; + uadev[card_num].info[info_idx].xfer_buf_va = va; + uadev[card_num].info[info_idx].xfer_buf_pa = xfer_buf_pa; + uadev[card_num].info[info_idx].xfer_buf_size = len; + uadev[card_num].info[info_idx].data_ep_pipe = data_ep_pipe; + uadev[card_num].info[info_idx].sync_ep_pipe = sync_ep_pipe; + 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_sync: + usb_free_coherent(subs->dev, len, xfer_buf, xfer_buf_pa); + uaudio_iommu_unmap(MEM_XFER_RING, tr_sync_va, PAGE_SIZE, PAGE_SIZE); +unmap_data: + uaudio_iommu_unmap(MEM_XFER_RING, tr_data_va, PAGE_SIZE, PAGE_SIZE); +unmap_er: + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); +free_sec_ring: + xhci_remove_secondary_interrupter(hcd, uaudio_qdev->ir); +drop_sync_ep: + if (subs->sync_endpoint) + xhci_sideband_remove_endpoint(uadev[card_num].sb, + usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe)); +drop_data_ep: + 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 snd_usb_substream *subs; + struct snd_usb_audio *chip = NULL; + struct uaudio_qmi_svc *svc = uaudio_svc; + struct intf_info *info; + struct usb_host_endpoint *ep; + u8 pcm_card_num, pcm_dev_num, direction; + int info_idx = -EINVAL, datainterval = -EINVAL, 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 xhci_sideband *sb; + struct snd_soc_usb_device *sdev; + + /* + * 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_get_priv_data(usb_get_usb_backend(udev))) + return; + + 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; + } + + mutex_lock(&qdev_mutex); + if (!uaudio_qdev) + qc_usb_audio_offload_init_qmi_dev(udev); + + atomic_inc(&uaudio_qdev->qdev_in_use); + mutex_unlock(&qdev_mutex); + + 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); + + return; + +free_sdev: + kfree(sdev); +exit: + mutex_unlock(&chip->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; + } + + /* clean up */ + if (!dev->udev) + goto done; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + dev_dbg(uaudio_qdev->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->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->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->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: + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + + /* + * 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) { + 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)) { + snd_soc_usb_disconnect(usb_get_usb_backend(udev)); + 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 snd_usb_audio *chip = usb_get_intfdata(intf); + 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(&chip->mutex); + dev = &uadev[card_num]; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + dev_dbg(uaudio_qdev->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->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->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->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 Sep 21 21:48:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5498415vqi; Fri, 22 Sep 2023 04:38:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoCQSTWlmLGXNRftjTa6lYu9Gtn7qkKTnvT6/tENYeYh72Wb14dc8XXRUH6sUXsVTMdo+D X-Received: by 2002:a05:6358:2787:b0:143:49f5:145d with SMTP id l7-20020a056358278700b0014349f5145dmr7335538rwb.20.1695382700557; Fri, 22 Sep 2023 04:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695382700; cv=none; d=google.com; s=arc-20160816; b=zMExbc93HNA+kzap4imtvvCLNbHRJnu9onMFKsXIzsoAKMjMwJ/2TzGQvZVWPaIIH+ Si3XV0okscCD14EfV9et14UVDfjpirBbSLqsUjESy/QQmX+ufZxRY91TUHj1KblkE6GN xajaJ+tNjhEhEUYLtL/3UvYBTW3goHbcV3OKuw0eNVyv3CnRreCosjAaJFUnJOzzKbY0 dzeNm21TXbforUtXznVzRVlUJpLRIhcRzGUFzhxsRcmXzwdjn0918yFClM5D1DOzO9VI J+OZTtfK09Mv+kuAgjINL4Evflqm955+cI86HAzAjx6P85+1P8kpQmkjObAryVfkQS3J GTEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dH3EZ3Jzl3/12IrSu0jI4GH3HGQtq5+vzpa4GA8M+f0=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=tA6jrdHqPDtiScYwvENmW96HVNgMsTU0pkJFl860xsLad2TVYUtP3/G0+FnQRhFS5C prNH+DLxUACFu8qdBDK6bnUlyJzd+lgATnxxhtDp98vmyKEVqMLlqUpkTzyZZcYF04GR a7LrHjE/H7IvfkepYpxQHARuq/4y0xu34bEQ1oZyc0MuB7QFYcrSpiZCTt7ukkBaKu9b GWip5TWwjpD3CxaDiDz72AGneW8rwICjBPwFBaMECMJi5A2546NYGVFkZJqIqLz5vtGf hR5NTeemMMHiQ5ehctV9nkmdwxvB4Q+xtOGeDO63QApcmAvLy2YTDfhPUHwepvRolwPe t2WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qh8jXbPl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b26-20020a63931a000000b00578e662d9b3si3542475pge.486.2023.09.22.04.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qh8jXbPl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3FDBE852D27B; Thu, 21 Sep 2023 14:53:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233025AbjIUVxs (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232670AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB4B3A8C; Thu, 21 Sep 2023 14:49:38 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKs3lq027021; Thu, 21 Sep 2023 21:49:00 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=dH3EZ3Jzl3/12IrSu0jI4GH3HGQtq5+vzpa4GA8M+f0=; b=Qh8jXbPlOYiKd08ahmmzOR6cuBSdT3UJGWF3A0fkBhBXRTU4/JPpyTJpa1fwYhAGKudV mw4eozX9wR56/Sy8TvCsACSCNmS39hJlSQjW5ssYd9LcT2U7QgLKtdD27Iqgh1IrrfQu 3Kg9ZqWw7QWmVgO4V6TwJEOR3mOuJAza3ydIL5TQCUemCbmlFDdzeY8mJU6UqZGrofe4 hwyhHCR+9Zdgk5hLcVSLPyO5ynlaDMGncBZag3jrdBB6PjqLWaKTP1g06Rga3BJFko1V FJq3MCD6knqphrpH+pA1xbMODjINxvvnG9Cf7FJea3af9x8YDaB9D6mYD2BRx8Ay0c+Q xA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uf2g9pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:00 +0000 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 38LLmxXk031083 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:59 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.36; Thu, 21 Sep 2023 14:48:58 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 19/33] ALSA: usb-audio: Check for support for requested audio format Date: Thu, 21 Sep 2023 14:48:29 -0700 Message-ID: <20230921214843.18450-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: 2kToF6aRGq---6me_PG0So9suarmzHKO X-Proofpoint-ORIG-GUID: 2kToF6aRGq---6me_PG0So9suarmzHKO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_18,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 clxscore=1015 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777737610586931423 X-GMAIL-MSGID: 1777737610586931423 Allow for checks on a specific USB audio device to see if a requested PCM format is supported. This is needed for support for when playback is initiated by the ASoC USB backend path. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 40 ++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 11 +++++++++++ 2 files changed, 51 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index c0b312e264bf..88f431917c15 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -162,6 +162,46 @@ 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 = NULL; + struct snd_usb_stream *as; + const struct audioformat *fmt; + + /* + * Register mutex is held when populating and clearing usb_chip + * array. + */ + mutex_lock(®ister_mutex); + chip = usb_chip[card_idx]; + if (!chip) { + mutex_unlock(®ister_mutex); + return NULL; + } + + if (enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &as->substream[direction]; + fmt = snd_usb_find_substream_format(subs, params); + if (fmt) { + mutex_unlock(®ister_mutex); + return as; + } + } + } + mutex_unlock(®ister_mutex); + + 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 2884912adc96..e26292363cf0 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -216,4 +216,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 Sep 21 21:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5391411vqi; Fri, 22 Sep 2023 00:52:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1OEjYFSPcUw96XNmLaqBMiYbMBFunEAHbz/QtuAlYkU2mUoJMF2zKHGiBWf5fdLzJ8hSS X-Received: by 2002:a05:620a:2443:b0:773:b795:c9e9 with SMTP id h3-20020a05620a244300b00773b795c9e9mr9341628qkn.17.1695369144037; Fri, 22 Sep 2023 00:52:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695369143; cv=none; d=google.com; s=arc-20160816; b=V49KiAami+VoxpI3Kihasv8mA9ynady3U7P0QDzE/KaEb30uiL31hsdUgLVE8mTvnh 8KsnHbyfUb00iHChNzkUvmks/sjuqHubjwndkU2Yzs0JWXSDVbWIEWsETjQQrS0B6pZJ iw0zht/ZbwRW6IpR27S4ytUkYUCtK/bHSDFxSGsOlSsFC3vyNrkmD26NJzWw+1fYvqGV q7fvuL88cjbPPHB2iS+9Pfhy8x4q7gI4jKpouNv9waEhlQk5hpBdbO4SMSDzYyVG8vNj XRDnW4deYOvAcJTI5Lx389FksHIBpAZ/XTfH827Cq9ubOBcCiI1SdXqrYM0Z1RHeJttO U8GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6ANZFxpwb1E6/2h3bsHO/Ac0s+q1tJrilzF69+2JslE=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=RAn+Row8ZNiGWgBhNK4kTXF3KLbfKQxbMLwolNrWAymr5fYbH3Or72x4Sd8R8qredT 3G+Kx9wgM2YhCVVyz2hxFOPhzU3mm77zuHZWKYl7ROGmO7r9VRJ/w2RWepo686BbFzSB DYyFGS3DIK2kj9172dUbFKAdi8mFLoa3RqTuAh3I+xD16R5ZsbUpC1XRs7Vm3h334SbU U8yYNT9/SH9+DA/2Ypm0H9j4hT73LCWx1A8/1eCY56qYd4cmqmbmhsuSqReaz+SKQ2ku lMUa4y7UlyzBvjwHFgM44FfrhhPZQMMgfdCNDWZlBvffqrcuDctL4fHhFNEipt86ecrk os2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EIzUEDGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j9-20020a056a00234900b00690d7d99e2fsi3482112pfj.212.2023.09.22.00.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:52:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EIzUEDGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DB2BC823CE8B; Thu, 21 Sep 2023 15:03:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjIUWDW (ORCPT + 29 others); Thu, 21 Sep 2023 18:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbjIUWDE (ORCPT ); Thu, 21 Sep 2023 18:03:04 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B70461FCF; Thu, 21 Sep 2023 14:49:48 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLOinV000623; Thu, 21 Sep 2023 21:49: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=6ANZFxpwb1E6/2h3bsHO/Ac0s+q1tJrilzF69+2JslE=; b=EIzUEDGENg1Oc+G8iiWkzbtXpIf8ktcy6AcQfv86hyES9DCrrCTJXc0eHiPh7HWbYjVQ el90VI53ooJp5N+ErGjBb1VxtWMacL8FPBz8ed5eoHkd+xVZ9kBa41ItDyVuC2iJEYKU NG7CPC1UB89+87fqUMCpR//DMQn6Dze9mlqrRAGMkdcihLal92PY2/Ba1cTSis8puyxG 76Ke8XHxnajjPcftdm5DTcxEjQ1PFq5bMj5sbpB/TYViqjTO7JDIDsxlQoQKm0YLEQYH j68FQD8LJYUUxVQn1has/AOM3JPMz80jH+pyEC4qkLH+REth3JC0Chf3N0RvEJsnI6rf /w== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8um1r96u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:25 +0000 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 38LLmxL6009020 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:59 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.36; Thu, 21 Sep 2023 14:48:58 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 20/33] ASoC: usb: Add PCM format check API for USB backend Date: Thu, 21 Sep 2023 14:48:30 -0700 Message-ID: <20230921214843.18450-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: xOdLAOsJpTEHwNh7z1cwwbf7UNDvypQo X-Proofpoint-GUID: xOdLAOsJpTEHwNh7z1cwwbf7UNDvypQo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:03:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777723395339924763 X-GMAIL-MSGID: 1777723395339924763 Introduce a check for 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 | 3 +++ sound/soc/soc-usb.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 1fa671924018..4785ea165e2a 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -37,6 +37,9 @@ struct snd_soc_usb { void *priv_data; }; +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); void *snd_soc_usb_get_priv_data(struct device *usbdev); diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index b5ab2c1a6dd4..619f9bfd6999 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -74,6 +74,19 @@ void *snd_soc_usb_get_priv_data(struct device *dev) } EXPORT_SYMBOL_GPL(snd_soc_usb_get_priv_data); +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_add_port() - Add a USB backend port * @dev: USB backend device From patchwork Thu Sep 21 21:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5325708vqi; Thu, 21 Sep 2023 21:57:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1hjRDtgBfoqWM4XOrCR+gX+A2Tbk98Aef/nGyNWW/HB+w0dYGrq0TW9rCRXeshhb9x74S X-Received: by 2002:a54:4806:0:b0:3a4:3b56:72b2 with SMTP id j6-20020a544806000000b003a43b5672b2mr7461796oij.8.1695358672568; Thu, 21 Sep 2023 21:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358672; cv=none; d=google.com; s=arc-20160816; b=hl78SrGat9iGX32DTwzJRtPig7tZFmA9GAPb5jy/oyds96mQCqCL7cXYt5DsJQct3Y X7DH3dOZ4dXE+p6UsTzIHmQTx0sW3jFhFClvSONHpbCFv0gLevIkizBNt7PxZbOxgJ3n lkYipyuyCx+k+NEEN0u1Srb6F4oRA6Jp/ylqxtnPoe21PbDHOBPzVtKZNEX5OcgOOHoT U3ssOT8rXaHpoTIpC8CUDKoRnTMhhITmMFKs8IPM7G85K3kNnjU3EoMvZk7oL6JzhqWJ hvNQc2mHA0efS0iBIesCmMWpbu9wu0AMztZmYsy96ZHo33nocx82htT2QNCOj0N5AZCo QXrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ob93bqxahOMEufwrgeaLvvgzI4mtSXSHT7C0WZfYQpA=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=v6kNyzsqHoWDVxjQEFTYHXtghW7YJEpiNe8p3SvuMp4KFmwg/QVU8IhQZME+9wkbhb g7R9EL1jS9T8+q73nIfVpWcTP4FJ61OdR2RzLibGjt6B9a+NCTdabALI0tP3BGnMfKlX iWLNPLBflkw3uYG8uSifGGHmFIBPnIJ7q18s+rwCbrENs+cwr1/ol3tmQS8JyVG1kSIi MbMj8cJvYYfcYbly331h92WRxyEbzDT+cQsjh21ctgtyl9qLQEDix2Mt++kCWWTsUy5h yAdLucW8U9ZM9sIO/u5yobTnMIZLROUxiN8nxribPS/8FT93slHDZSbgz+SsSZeLw6zu PP4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Xa6ou7MK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y129-20020a62ce87000000b0068fea8a6169si2804196pfg.404.2023.09.21.21.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Xa6ou7MK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5F1E380530D5; Thu, 21 Sep 2023 14:55:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233090AbjIUVyf (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232833AbjIUVxZ (ORCPT ); Thu, 21 Sep 2023 17:53:25 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 077EF3C14; Thu, 21 Sep 2023 14:49:55 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKotbk002000; Thu, 21 Sep 2023 21:49:11 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=ob93bqxahOMEufwrgeaLvvgzI4mtSXSHT7C0WZfYQpA=; b=Xa6ou7MKTGHcdYtdm5dsnM1IVPg1XLveL9BMOwSF2CWYU1Fn8ILjaIOBzzeQrj1g97oW WBp3hYD9i4IjJcYNXdzF5Wdk+r/TMlGuWmbxVr/2crinKDl4yvq6LJZRBABh60FuV8/D AOS6CyWf4o7vhO0FAzgJDYvubbIhJavoJ6zRQ41ctJsBwRBaNjpa8JMX5uS9nCNu1M6r Wi4aVGjxeP4riRuGVtgfy9g6kJQxS6uv+187PyAqZdLAvkIzhU/uRibFK/qB+W16UZXe RivI/qxgz+49yretWPP5p+ubHF2/BuRSC6paJU+JHzVIOT2x3qeFbxhCCcfKu3DQ8c/N cQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u0s0bsf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:11 +0000 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 38LLmx3T009024 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:59 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.36; Thu, 21 Sep 2023 14:48:59 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 21/33] ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device Date: Thu, 21 Sep 2023 14:48:31 -0700 Message-ID: <20230921214843.18450-22-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: o10g6KvmgfuCCOMtyICd9ILCX4OK17H3 X-Proofpoint-ORIG-GUID: o10g6KvmgfuCCOMtyICd9ILCX4OK17H3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 mlxlogscore=988 spamscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:55:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777712415693338125 X-GMAIL-MSGID: 1777712415693338125 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index dd664ad41668..329a7d4a3c01 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -44,7 +44,10 @@ 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_idx, params, direction); } static const struct snd_soc_dai_ops q6usb_ops = { From patchwork Thu Sep 21 21:48:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143254 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5405316vqi; Fri, 22 Sep 2023 01:24:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsukqRWOPr9Qks8h1CrR/HaC8vZQZLRU5++iDJDIuwTQwlbTGOA4gsr8lO7EA23k0tCPyF X-Received: by 2002:a05:6a21:4988:b0:15d:7767:6553 with SMTP id ax8-20020a056a21498800b0015d77676553mr2849775pzc.35.1695371099316; Fri, 22 Sep 2023 01:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695371099; cv=none; d=google.com; s=arc-20160816; b=WRRiBnRd9Nr8lYrkS8gDmaLAdVjEns8EFjNyRHz33ECcA7Ncqr/68a/k/9POM8nH3E QNpQKNd92Dn8t9ZJbx6KbVyrd/KRaLVyKpfLO4KYWH3kGV6MS/v3ADLCcNye1mumiY3/ 3c+uQAR3Cqy1LAGopLgnzbjb215lquEMHRmlOVzh3JMha7DcIl45IWwIdG/jJ8QAnkpT oCquDTIArWUHhNWl8p6sPIwEyOweostdhzGU5pZYRagMXlO8DQJd7U0REnufsOsnZN1B UkAY+lI5rw7vmkkJuwzrra+z0bmcTsSkvzFZVtIjtjIpDDgSWRJxSPF2v7R5ffvVuZIT dfzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nZHs65wuBxC3BjUfJ5Q1+mjrtbgySNUK60JxPD6B7FI=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=oylq8Lfgurr4dUmUwdM1sgbPlRhvMvqbsBpbwO5nXAYhOGnfiEHxAm5VsxosjnPoa0 ggJCaKUGS3ti4h6hCiujqoYhw1dxo+HGyt0XgPDNqpKCBqybdo50SPPpGvxCQThpn/bv BuWwkyga5rTElqPPFjZ8lZNdvAWWOmA4CdaHSMLC8xjRCVv5DhKi/s6EOjNzwbvIXhm0 H/LyRRPVRdpmygMjXsfkYcXfCg9Kg5HDyEb3DwnyZadqeQdNQu/aOaIza52bjH3RoSrk ZyuqUaX+xfZcyqiVUu2atncz/IEbqcgywk5eke0llH5F5kBJ5A+PEUob8M03mAN2b0Ck eKPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VNF0ysBc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v1-20020a654601000000b0056a290addadsi3365275pgq.787.2023.09.22.01.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VNF0ysBc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6353282F27D3; Thu, 21 Sep 2023 14:54:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbjIUVyH (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232744AbjIUVxX (ORCPT ); Thu, 21 Sep 2023 17:53:23 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246DB3C0E; Thu, 21 Sep 2023 14:49:40 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKTAAW023350; Thu, 21 Sep 2023 21:49: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=nZHs65wuBxC3BjUfJ5Q1+mjrtbgySNUK60JxPD6B7FI=; b=VNF0ysBc4NDwW1iPLXL1Z/eZ0uYtBBt6A1u0bi0hkrxQPzNIJRdSJBdvFLIDPJy7JcPu lX9Zs3bWoCbvsDbL/pQoiwC6KDzc2uLzkAfzhGTZP8+L9vBbI8h7fWcydt3TPkx3f87E YxYaSV8kzdNH2APuudVTcyLQ/hFAEz3/PHc3VbUl6J/OayOSCFC5fQExakGvthvzHI63 kQYCngKwUQBGVEjCAOWt6lrfuQv3LqFltdvWqI+ciRKPPCVccHoumNAi+VUgQokt5sDZ dCfxkDhF1bLkbMBmzPzLNp5nzJt4wd0dQAv3hb9FzHxfNOh0eBc7NQ0Y2OGpx6LmsxSs Tg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uknr96y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLmxvL031086 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:59 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.36; Thu, 21 Sep 2023 14:48:59 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 22/33] ALSA: usb-audio: Prevent starting of audio stream if in use Date: Thu, 21 Sep 2023 14:48:32 -0700 Message-ID: <20230921214843.18450-23-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: kfcaEtSHfao10NiDg4yKa2CwXlBDiaPs X-Proofpoint-ORIG-GUID: kfcaEtSHfao10NiDg4yKa2CwXlBDiaPs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777725445823658397 X-GMAIL-MSGID: 1777725445823658397 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 | 19 +++++++++++++++++-- sound/usb/qcom/qc_audio_offload.c | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sound/usb/card.h b/sound/usb/card.h index e26292363cf0..01f7e10f30f4 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -164,6 +164,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..c2cb52cd5d23 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1241,8 +1241,15 @@ 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; + } + 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 +1266,17 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream) ret = setup_hw_info(runtime, subs); if (ret < 0) - return ret; + goto out; ret = snd_usb_autoresume(subs->stream->chip); if (ret < 0) - return ret; + goto out; ret = snd_media_stream_init(subs, as->pcm, direction); if (ret < 0) snd_usb_autosuspend(subs->stream->chip); + subs->opened = 1; +out: + mutex_unlock(&chip->mutex); + return ret; } @@ -1274,6 +1285,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 +1299,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; } diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index f0977bd8084f..2ce39aa26906 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1400,12 +1400,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, @@ -1427,6 +1432,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) { @@ -1450,6 +1460,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 Sep 21 21:48:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5488481vqi; Fri, 22 Sep 2023 04:21:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+jquHw2pTKdgpfB28E9bG7cqyF+KECVmsJMKo32dQpQOpepMu+dgjMaarRxzki+eejCT8 X-Received: by 2002:a05:6a00:2341:b0:68f:c057:b567 with SMTP id j1-20020a056a00234100b0068fc057b567mr9040102pfj.26.1695381681745; Fri, 22 Sep 2023 04:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695381681; cv=none; d=google.com; s=arc-20160816; b=ZEEWEo/kSs+WYMgHf7ypSwymPAQquOUGgeiH3+gbHcJ5ixUfS4HJtbOfFxWqxTQqp0 Ip01eH46eHaCScZ1I2GCzSctxtwIvwTSrD7WHQiz4aM3j/68/2Awqkdr33hKOMuZa3/8 +1PAWsK5YSOMcvYVR99dLbOyEC3SIiWjWKed8cAvuYA06rPWi/lSW+8pmiTNwB5Kp601 MoHfhZgcKvrqTNtCWa+snUYbaZJruZKUTmfZVb8DDJY+RMGTgqo36gNnOXbtlhNXPljk 6zHVtRAnTrbuGjKFKgexKOstE1ovQeet8CKfGh6RX/8XkYczvM8ijy2SeNlhLc939n1+ G0cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xGf12vHzCwySUzdPW68rY9hJH6nosoRq8BNbdykqy2Q=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=xyyoP7wjtsaWy7up4ynV1ijZyNSzYJVpM4CQFFaP1UG4WUx9t8jvgwBeHFTyJV89gW ZF1VKCCtHXjYGIjP0ZARGwk/bwIviJH3S58cf9pz5Afd3PJdaKICeCKOCSdSvJmidn1e zMtDIZybK4Xjb3EAmxi97qY432NZ73uEQAEufOysiIGcVkn83lz7FUyRXI+M+xp5Q6eu uqdSPUHemeMoIDZ+i8p2DVF21W+P/i67Kh6D+E7nV1j7PQRY9KQouUfyBQ5CyVyDuDAd ssZAetWoUhghSLYd3YVe6cPLpqFm4mlRpA4Pm1C0r+VI1fjLw2TeHYbqqErO6Uopi2d6 MBIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EHoq9wwa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b0056c0e3c77f7si3512939pgj.805.2023.09.22.04.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:21:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EHoq9wwa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 38A918380FD4; Thu, 21 Sep 2023 15:02:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjIUWCI (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232570AbjIUWBw (ORCPT ); Thu, 21 Sep 2023 18:01:52 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C09119B9; Thu, 21 Sep 2023 14:49:54 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLgq3i012957; Thu, 21 Sep 2023 21:49:01 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=xGf12vHzCwySUzdPW68rY9hJH6nosoRq8BNbdykqy2Q=; b=EHoq9wwaCOKms8eXilPG7dsoBmKJbKqts2Ct8NiPyYm1bUNmauPoizsKz+MGIaJ+zxpL ++nBC5s/oNyx4Uka6P4anu0C39G99xho0VNLNXqHZRixo74qjsPGaqyHf7nGIUvLOZfd vVlRPeQC+v0XuKKQKHR8/xLViz2h/fTBG682pCzdhsJp3ZoC9d+KFxMb4VCBjPc7+vNr fna+6J18MRr7zFEMG1qu8g5MbsN9EYerHnSKQVLYyxwNFvwv4gbrKaUqt7sYRSjmybpt npANCOpe7kYsmRfi0rPAje8mJ7bgj5aKllncVTQTZ3Dkh4yXI/FfcYUyCtMkZyPkTC0G GQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u9h8arg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:01 +0000 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 38LLn0ge009031 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:00 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.36; Thu, 21 Sep 2023 14:48:59 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 23/33] ASoC: dt-bindings: Add Q6USB backend Date: Thu, 21 Sep 2023 14:48:33 -0700 Message-ID: <20230921214843.18450-24-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: v-epW4quXQOR2XXUCeD8PItFpE2O1HgS X-Proofpoint-ORIG-GUID: v-epW4quXQOR2XXUCeD8PItFpE2O1HgS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=845 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777736542249066525 X-GMAIL-MSGID: 1777736542249066525 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. Signed-off-by: Wesley Cheng Reviewed-by: Rob Herring --- .../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 Sep 21 21:48:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5416072vqi; Fri, 22 Sep 2023 01:52:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+wlmEZ8V6wBsnky8zC8h9zoENxXxfmcTHEMOARrQBvSct06TMDteTVPbwiLyNUy4qsjtV X-Received: by 2002:a17:90a:17e7:b0:274:bdcc:85b1 with SMTP id q94-20020a17090a17e700b00274bdcc85b1mr3060047pja.12.1695372771944; Fri, 22 Sep 2023 01:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695372771; cv=none; d=google.com; s=arc-20160816; b=vrwsdtnC2P9HBSuc6K6PT8xWRx5kZv8RIhdKyIA0+qoxvXlawIrrF4W2do7SRKxh8z KfGBrEsRYV27O6iVEOu8pwtswVLj0WkFmlonAzJ/5YB0oevpmO8X5Wsz1NkyyuwMGiuJ 46HgLoA8Ri823YoVZSk1+rUKRq9eWg/70KydH2GNab4ZH8G0zApZyqnirUlDUWd38mup CH3ic/LxjDCyH1saJ2ArLbe8+NRpmivH0GNr+Jh/4sc3OSxHMV+0/OADplAgFowmPycL XBJ2uUzk4pzuL//7pf5ZPEBLDbzLJMr+P5ybsCqEj8WqQ1vUfg9S6cvN/90RbuhVDp3g G06g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3gBHabwBqqq6kLDsqXiZ5sw8OskG5Bpac3TWaz1Ue9M=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=IIkD53f+X7nGh4Mq3TcYNUY6ulAGvljSDvr4ApHxDfjwbB515zXxr0gIsb0X3zFbSN vaWEYbOjJ5g8J/yAfqCrCSWxv4f2U6Z36bo/h4BQAE4Nj10toMZ/CwCpmxK4zzvmJUmK bxXh9dJNutoELHvmCWrIee9zev5b/COA4lNjhAlq+rImWh/mATPKnruTq6SUp8CBkXdS Xzop2pUEQVJPvqi8EKbR3dBuM6VlXifNwTpxpcyzIlmm84HgyLvDruKOVnz2Ki9e/uYK ENCFRxr7XrHWbbDQ1xkIdMRXKhCe0uEr8Czs8Fig3D2WbHw+gsnsLNTgvHdJOn97Z0jL ZmFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dTui4bex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id 142-20020a630294000000b00578b6e32b5dsi3281080pgc.405.2023.09.22.01.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dTui4bex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 012E8833AB00; Thu, 21 Sep 2023 15:02:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232784AbjIUWCE (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbjIUWBw (ORCPT ); Thu, 21 Sep 2023 18:01:52 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14410448A; Thu, 21 Sep 2023 14:49:43 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLg9le021716; Thu, 21 Sep 2023 21:49: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=3gBHabwBqqq6kLDsqXiZ5sw8OskG5Bpac3TWaz1Ue9M=; b=dTui4bexcJHjGMtzDVmZSPE5pMdSClHPCgG8y24bzJ5UdbkjxyKazUHN7rII6ePSLL6y YvnPKmVoSNzlfDYq498uS/MLgS8sbjh/RW4V39onkQ+puz2iqYZfF0oapUNTmZX07ogF uGmVgTrnW/r87H2d+6UOEV8Vj7T38CPWFwSM3GRi3LVbgkcX0t66oN9ktJmeGW0o0oxX 3nxQvctbwy6wxvfXdFFmfB7cGBonIiF1xkMbmIymmXbQj4N+p4GU3TLvwyAuwTlFi5WF JDjuicppY6cV4pn7KesJmgO08y8ymKMwoOmPSlDBkFBmturRoF65vjwG4DHTOCfi7siK og== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txg8cb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLn0x8032127 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:00 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.36; Thu, 21 Sep 2023 14:49:00 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 24/33] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Date: Thu, 21 Sep 2023 14:48:34 -0700 Message-ID: <20230921214843.18450-25-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: Knu3PWt2oNxtpV4fN_W391bISPH_mQkN X-Proofpoint-GUID: Knu3PWt2oNxtpV4fN_W391bISPH_mQkN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777727200035123092 X-GMAIL-MSGID: 1777727200035123092 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 262de7a60a73..13145e010ddf 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -220,6 +220,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 Sep 21 21:48:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5282729vqi; Thu, 21 Sep 2023 19:50:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6FyqMM+VUypdzSeMUeA5Rrp9oAKJCZc4D1g8+QVn0OXHcgAD93crX7cwDNsSfw2K6Lh6a X-Received: by 2002:a17:903:41c6:b0:1bd:e258:a256 with SMTP id u6-20020a17090341c600b001bde258a256mr2391797ple.32.1695351038772; Thu, 21 Sep 2023 19:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695351038; cv=none; d=google.com; s=arc-20160816; b=mY9n9ADa13ORlHokok2xmNMN+4P6fYPVjttVbC/nh9wAWz3hx3jeXdBICo1uKv3nb9 2MTTOksAxWv+Mtu0FfBBx29uSyrE6ZCNzAMbdBve3srdN607PEWm28XHRArOu3hq4N1+ JvoIF0UmeK6ZvALK6GJ7TdOUBCscAnPmkhYjKnisOzOcYRbgAAHvgG3n2M1WRGZGTO2v Qx8ABOjRjLqKqjoO3veQD8YOpq85VlVXUPphE0lTzDKrOXVzyjQn/0WzP26/LBcEx2X5 GvB+Ag8bY0iDQ7lYD3Nj3TGn4MmOWceRBYFW9IuWp7RZMZDHOS453Nw+iIPCliJ2iJvI wtwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DJXYybKJrBl7GHgka4BmKmo4v4Wju0w3cfuDKhuRqeQ=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=MaHi+jXAK8y+sTf5qkR6h06cznkoWOuJAe4vQS5d7z/QKyLO+gUfnQN9NfA3qxzVDU I9DzGQhl7Ww/GhX6USbFtANnQO7Y6SP/TwQEFAITb+x48OC0adIB8JCSbF4dlDSutx4t EFzuSnhAf9gLnwSfD8R+VszmtdtQNpsZ+Niq0RpGdO29g340hSrjGP3uBHZOVn3qwzBM DdqFyicDWR7pUOq7cKWgYKjc38m1clRzjKgmKZJeTJpBf7dP8WRL3zs50enUJPXITXZ/ u5VAuyFjMoKBmAA/sbW1IJNehQ/gsv2HzrgF2F91eFNxpfPneA59Glr2DpsvzKBVVtJH 7wXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YZnnt7pN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h8-20020a170902f54800b001bb00cc105csi2939385plf.632.2023.09.21.19.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 19:50:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YZnnt7pN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5DFA3833AB0B; Thu, 21 Sep 2023 15:02:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbjIUWCm (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbjIUWCW (ORCPT ); Thu, 21 Sep 2023 18:02:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E4643A91; Thu, 21 Sep 2023 14:49:38 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLhvD8017305; Thu, 21 Sep 2023 21:49:02 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=DJXYybKJrBl7GHgka4BmKmo4v4Wju0w3cfuDKhuRqeQ=; b=YZnnt7pNtTlwStL7kk/VyD31vQLB8IN80BuOza1Vg1wVUvUUmPCf8pO0dduen8S7q9jp 8E2tFSt/mAB9TYoS72qQwKnahyYMgJ+GYuJUp3oHzJrRXI5FXjSlR+rGlncvZGs2QOMQ VW1yEHPcV4pcq5kwC7sk60xdgTeBpUuuArGJXAkM+W+4isF5xrSFIc6asheYz5ZwuIEY y53o+nDkW0FW+as6iNZU8+0iAIDrLCxXrRmGqMF5ZH0t+DyMyvxTxXeBupy1dTc7cHwM PeSL6m67a73+zbPgqKZ6SxiPMw2Gslbc7rMyZkXZE63Jq+84DlVm9zggwagVJK201A1I uA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u9h8arh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:01 +0000 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 38LLn0vw032741 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:00 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.36; Thu, 21 Sep 2023 14:49:00 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 25/33] ASoC: qcom: qdsp6: q6afe: Split USB AFE dev_token param into separate API Date: Thu, 21 Sep 2023 14:48:35 -0700 Message-ID: <20230921214843.18450-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: Mk5ZpI_eU3ibIOse1N89LST6yJD5dq3l X-Proofpoint-ORIG-GUID: Mk5ZpI_eU3ibIOse1N89LST6yJD5dq3l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777704410619712703 X-GMAIL-MSGID: 1777704410619712703 The Q6USB backend can carry information about the available USB SND cards and PCM devices 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. Separate this into a dedicated API, so the USB backend can set the dev_token accordingly. The audio DSP does not utilize this information until the AFE port start command is sent, which is done during the PCM prepare phase. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6afe.c | 49 +++++++++++++++++++++++++----------- sound/soc/qcom/qdsp6/q6afe.h | 1 + 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index 72c4e6fe20c4..f09a756246f8 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -1394,10 +1394,42 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, } EXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare); -static int afe_port_send_usb_dev_param(struct q6afe_port *port, struct q6afe_usb_cfg *cfg) +/** + * 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) { - union afe_port_config *pcfg = &port->port_cfg; 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 = 0; @@ -1408,20 +1440,9 @@ static int afe_port_send_usb_dev_param(struct q6afe_port *port, struct q6afe_usb goto exit; } - memset(&usb_dev, 0, sizeof(usb_dev)); memset(&lpcm_fmt, 0, sizeof(lpcm_fmt)); memset(&svc_int, 0, sizeof(svc_int)); - usb_dev.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; - 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); - goto exit; - } - 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, @@ -1463,7 +1484,7 @@ void q6afe_usb_port_prepare(struct q6afe_port *port, pcfg->usb_cfg.num_channels = cfg->num_channels; pcfg->usb_cfg.bit_width = cfg->bit_width; - afe_port_send_usb_dev_param(port, cfg); + afe_port_send_usb_params(port, cfg); } EXPORT_SYMBOL_GPL(q6afe_usb_port_prepare); diff --git a/sound/soc/qcom/qdsp6/q6afe.h b/sound/soc/qcom/qdsp6/q6afe.h index ef47b4ae9e27..2ce5ba9dba69 100644 --- a/sound/soc/qcom/qdsp6/q6afe.h +++ b/sound/soc/qcom/qdsp6/q6afe.h @@ -263,6 +263,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); From patchwork Thu Sep 21 21:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5296291vqi; Thu, 21 Sep 2023 20:30:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9Y5Yh2j41zQBiQs6BIQI8W9Om6tUbNDR+FKQxLvCPXwn15SO0VaW8zekEZ4UyWPIMBHCy X-Received: by 2002:a25:abaf:0:b0:d78:11a3:6800 with SMTP id v44-20020a25abaf000000b00d7811a36800mr7474427ybi.61.1695353457709; Thu, 21 Sep 2023 20:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695353457; cv=none; d=google.com; s=arc-20160816; b=wMK4DlzI170A5pBmRV2GaPGDU0w0FOWdbekcRxT3t7jw7HMwAWcu8H75wU/pDLXPqE KIdULlMvIxGTIDphkHC4XWBgOQ4xv5ejUngLLPHyyTNpe+G9pEiZzFC89xQujnTT4pBb KzixFRbsKfYC0vXx84S529sNB2sRDzstpEZKMDwLGQjN0NRUJJ4A0Zeni9ipJ1djLzkK QB29B7458c9KP6jfjeYeG5Ilogd+VtGNUVMPPYYU6oYnXvbuEMubYADGdDC/n+qYBFmi GGV6HSN5vEgNjx52Y0lBDdDnS8V/KtgoKtdtvdpM3TOg5FWXuOEO4NKs+cI3ChEzB6FD K5/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NmQu8MFx2lZ7/sy3a7JXrsNnPwmoH+GDE19rppIQVy8=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=sARAq/ZRA5JxZG5X1V70llun1xb6tCib9nONMsqbEgSjCyrKub3EzQmB6uyi+Zpdf1 uS5lm71bt9FXoci+6NcLln+YVOZbiPb2aiPxsOWzSBg5QqfXNdruWd6dCfiAPuYcBrTv CqUBsR0peNkkrxT0a0djDBzAnlin4cq91kuXIUCtuWWto6QKXmZ+UgLVPELd8+OpydcX iqfNU7N5IiiQq7vRqDuoxBJSWDkDiyUWiXQhL2rNv61n2aZ1U9riW0GQxa1hjBt849Kh nBIS0s4ypoCcfxqjXrj+i/OBvgeFbHMUgTOuN7E1amVRq+2IJmkF6h+LseEHbc/wPjGA HA6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dLwLErET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id 63-20020a630142000000b00578a98c0687si2934878pgb.99.2023.09.21.20.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:30:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dLwLErET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B67428370870; Thu, 21 Sep 2023 14:54:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233022AbjIUVx4 (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA682D63; Thu, 21 Sep 2023 14:49:39 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLjc1k010925; Thu, 21 Sep 2023 21:49:02 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=NmQu8MFx2lZ7/sy3a7JXrsNnPwmoH+GDE19rppIQVy8=; b=dLwLErETigAiw6VM9ji1hY8Mk+oxEbWTxpRVueloA8mRaGarGWhoq6oy9IrPRymWsi5q aerUjw3Yoyj3U4ZDVfkSfZl19XwJM/jdZLjI5ZS++AKckL8jD3xBoVWfJBKGhljqFFz7 glI/1tQj+CM6O8vaGX+SxmNmEo1awrvyAeWYHaIfn3BwBbl2xAmD0i0nLQh48HEggLSG 3x22EsNcV1UJuIXPXfo2oyTfwx9yV/g2wgDK/fWui9xNLafbqvzOZqUoVoLJjqS4+DwV PEnSrIcopCo4LU8+ShossEmIbqFdvDrU4FuDz3YszyGPWFkehOEtEJh3tHDHk3UT3T2b GA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txpgc0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 +0000 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 38LLn1Nb031102 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:01 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.36; Thu, 21 Sep 2023 14:49:00 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 26/33] ALSA: usb-audio: qcom: Populate PCM and USB chip information Date: Thu, 21 Sep 2023 14:48:36 -0700 Message-ID: <20230921214843.18450-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: xkjOQ3Atu-mQnKB-HPI3o_fltUXGJtlf X-Proofpoint-GUID: xkjOQ3Atu-mQnKB-HPI3o_fltUXGJtlf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=644 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777706947151004681 X-GMAIL-MSGID: 1777706947151004681 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 | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 2ce39aa26906..2dffe7e99e01 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -175,6 +175,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) { @@ -1579,6 +1594,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; @@ -1693,10 +1710,8 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip) mutex_unlock(&chip->mutex); atomic_dec(&uaudio_qdev->qdev_in_use); - if (!atomic_read(&uaudio_qdev->qdev_in_use)) { - snd_soc_usb_disconnect(usb_get_usb_backend(udev)); + if (!atomic_read(&uaudio_qdev->qdev_in_use)) qc_usb_audio_cleanup_qmi_dev(); - } mutex_unlock(&qdev_mutex); } From patchwork Thu Sep 21 21:48:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5325474vqi; Thu, 21 Sep 2023 21:57:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmPUWUSI2bw0v8iplD24+N6895Ezgz+/ELTq/gZeEj4luIKWDdeuREnmdld6PKdRQ9u9lf X-Received: by 2002:a17:90b:4b4b:b0:274:7dc2:45fa with SMTP id mi11-20020a17090b4b4b00b002747dc245famr7412321pjb.1.1695358624100; Thu, 21 Sep 2023 21:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358624; cv=none; d=google.com; s=arc-20160816; b=ZvUz5J2JkNJvtRNP/Nx0jeGWcr4MenaOfaOQuCfzxoiMARGmVaVVXuovzaeJ0ZVVOa 2TnRl21TQ9oiyU1RYTXz0vCd+CQtHX1ObWN8mw0e+NkNl5aRLDojELPb+d6xpuk120qn vflmzZF/0A8k6OnCjqaFPRy4qzIKfidgiT1ba6rAu5AueYnjMF4fiw8pDhcqefN3ec/g Kdgf9SF9OErG1bh3Z3H+Q5f2D+sdP/LJ49GTPIwT7/YPQ9CnvaRSj9LH3uY6HTuOiVSg qd7gOMnUydfUY6A61s6LAuq0LVFY/MrC+G1XFgLzxZ9HZc4o5YM2iJ6FSr+hXfxgrVmi XS6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Kd7JVRVp+I+Xk7DXDTAeHHZpvD4f/oHbrP3CUMWtwu0=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=Sae/zqXcnWAZJsUZOXy7Q7Q5riDCXKwcdKGluaCS4zKK5ZpRrKdYf/7TXryvlgH9cY QVY+nR+mFQ99YZy7q75QA3As9zVEJDvCsFXZ7C/FEfkMsjjl+6LH2BaWmQlhPmS4CIaP Q6d6ReUEA+Z8nbyhHTSh8N83e25BYat7iwTdGtlfD9ZqgLgXpWnX3FsqdTrxBJp/+cv6 K5fhiunKcfMawI1MEQwhPA5AUA7WWeBUq1dYzk8e2BMNYyniY2USF3PosKfznvvlpnnw sPJtikxwJ5gNyHxNDOFIdWnLNGJZa+S3E1TRbrYo14EbfzGLoLx421IG9Ceagtrcdq1A noig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=KODfubmM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d11-20020a170903230b00b001c1f373ea07si3413008plh.351.2023.09.21.21.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:57:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=KODfubmM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4A3A2832F64D; Thu, 21 Sep 2023 14:54:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233045AbjIUVx7 (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231414AbjIUVxX (ORCPT ); Thu, 21 Sep 2023 17:53:23 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A2A3C31; Thu, 21 Sep 2023 14:49:40 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLRrOA013210; Thu, 21 Sep 2023 21:49: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=Kd7JVRVp+I+Xk7DXDTAeHHZpvD4f/oHbrP3CUMWtwu0=; b=KODfubmMH6hyC4SSKc0eMU/CDJJJ5A747LJboSjZGWzDvLTgEdFWe8i245FnJL0bwc9J 8HINlHcuRKNGMeu+P7ytppdU+gMjW70L8ImCHYnOTVc9cAEOSdDMTzuJsFjWjmZcjfBx OrWUauCyWEPVAARPFbBhznTKXiEk+T2cxrMhPT9gfCZnWs/XeYtnZMsFyg5jW7z77VU3 cv/xeN+beuHhSs/yRBhmisBBffeFWypdvjtjrAkv++29VaY4dPE7g1tsAIiKdKu6VpEF DtO8kfkQhuiheh5ljyrcBbuJgzQZHjdRcL6QQ2eYjjsX05/tVPXOUj35ZUsu26g5faPp gA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u5n0bq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:18 +0000 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 38LLn1x4009041 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:01 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.36; Thu, 21 Sep 2023 14:49:00 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 27/33] ASoC: qcom: qdsp6: Add support to track available USB PCM devices Date: Thu, 21 Sep 2023 14:48:37 -0700 Message-ID: <20230921214843.18450-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: 75RndmVpVo5bpEZIQfmVlQOetp4V0_oU X-Proofpoint-GUID: 75RndmVpVo5bpEZIQfmVlQOetp4V0_oU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=913 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777712364661885173 X-GMAIL-MSGID: 1777712364661885173 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 329a7d4a3c01..d697cbe7f184 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -25,10 +25,18 @@ #define SID_MASK 0xF +struct q6usb_status { + unsigned int num_pcm; + unsigned int chip_index; + unsigned int pcm_index; +}; + struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; + unsigned long available_card_slot; + struct q6usb_status status[SNDRV_CARDS]; int active_idx; }; @@ -110,6 +118,14 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, if (connected) { /* We only track the latest USB headset plugged in */ data->active_idx = sdev->card_idx; + + set_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].num_pcm = sdev->num_playback; + data->status[sdev->card_idx].chip_index = sdev->chip_idx; + } else { + clear_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].num_pcm = 0; + data->status[sdev->card_idx].chip_index = 0; } return 0; From patchwork Thu Sep 21 21:48:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5299325vqi; Thu, 21 Sep 2023 20:40:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEplA5qPXnWBbf3uJEIhHIq864DIuQ26rWPFPa+cyuty6nJ+p9x3Lwm+i6cpUdjmyulXPM8 X-Received: by 2002:a1f:e641:0:b0:48f:8533:3cda with SMTP id d62-20020a1fe641000000b0048f85333cdamr6990859vkh.11.1695354008321; Thu, 21 Sep 2023 20:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695354008; cv=none; d=google.com; s=arc-20160816; b=oHVxpkffiTUc4PmCTIOcogLrrSZvtmqIdFwaExkxsSrSAVNnPsnqWvSc+lq7QhpKW3 /ZmEU5KhP4z61Zk/IbufIASbs59uXmIJtvpweLVqLkZfqErASqFj2w3MHfeqNEh4Tg9Q N0Atu1KNzFCNvLEaBZo0TecneOhOnKlpCJld23YkLfKMonnpmaLz8ZMAKwMf1VyNEQkT Pj1jaPIO/ik+WlNd1srdcN77+CoGwhgsG3HVMzHvjH+GyZyDiAJx1iX3WHnGyIBUlgm0 R5YMLXmMaQLSbFRHcZiJDBGtWG+xyygBKsE+g/nU6zOT50CzEDKeF0V96dSpHjMOc1el xOyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iVxHFTIcdxp/Jy4SowB2gEZbBITOj/637q7GRBYSO4k=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=iVNaDLuacV0K9PInl/yN9xVrud6r52Rof9W2MOM07vSZ+6PGNTecXtOSx/ETnrXlWo 5K8RLjvMo0S5BRd3IXMYahy7wF5RD+qsGQMfO6YIEQBhS4+3fLxPpN0WVQQEWSHJLEkg EqCL84zun9pxz7vCuggzYSW4pIruWTKTE2SRtldCOMSx6z+CK7VylBivRox6fyKNub9v Qd3Yt7o8+qupXmAZD5YYkYGhOCkhbNTyCNyiOWikK9Ej2EjfdfHhMypaiQHosmI/XKTV /t2ABAG7Ydy7ZgV9ExY55EoUsph2R6y4YenHYZFxbIf0vCy6+bSU6gYLJg8FMxRJwHlo OyjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XSKKlJFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s200-20020a632cd1000000b0056fad9586d2si2731934pgs.429.2023.09.21.20.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XSKKlJFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 624C6852D24C; Thu, 21 Sep 2023 14:53:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232952AbjIUVxf (ORCPT + 29 others); Thu, 21 Sep 2023 17:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9907E270F; Thu, 21 Sep 2023 14:49:33 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLVhZQ030717; Thu, 21 Sep 2023 21:49:03 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=iVxHFTIcdxp/Jy4SowB2gEZbBITOj/637q7GRBYSO4k=; b=XSKKlJFmIFfywESzsRJVkqv2gH5HMGgJ1ITJhOnFe+CpJfIKvTl4xSO+5+3pYlH0eMuJ wDcnE4Oc8vtMyn2giwTCEmbrY96to2lWgvQQiNI+LgQFAw5OrAYVdmMkmUIscBVrFSwx EUth4vMQMlpkMqhbQnbEw4+ZPBFrp14OgwOd+njPENvx/HBoUS2bc0mXMzFW4aoDq5bC rv8wk7Pfgfam2XEzbmwVX84nryt7CwD7KKV53o6FaQyd81M0zkWmn5tv+Vjt19MC+CjE uvKzhEr2TicGOYpt6PT+if73ztoz6RcTb+fQktYci0Uo9HvEXac3OhqocyWUfngMOgaA 9Q== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u6agbf4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 +0000 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 38LLn1hh031126 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:01 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.36; Thu, 21 Sep 2023 14:49:01 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 28/33] ASoC: qcom: qdsp6: Add SND kcontrol to select offload device Date: Thu, 21 Sep 2023 14:48:38 -0700 Message-ID: <20230921214843.18450-29-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: upJUm3DZH_tdsZghbTORWkppuRw1yta2 X-Proofpoint-ORIG-GUID: upJUm3DZH_tdsZghbTORWkppuRw1yta2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 malwarescore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777707524879486834 X-GMAIL-MSGID: 1777707524879486834 Expose a kcontrol on the platform sound card, which will allow for userspace 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 'Q6USB offload SND device select' 1 0 The above will set the Q6AFE device token to choose offload on card#1 and pcm#0. 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 | 125 ++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index d697cbe7f184..a95276b7d91d 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 @@ -35,9 +36,12 @@ struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; + struct mutex mutex; unsigned long available_card_slot; struct q6usb_status status[SNDRV_CARDS]; - int active_idx; + bool idx_valid; + int sel_card_idx; + int sel_pcm_idx; }; static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { @@ -53,9 +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 = asoc_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].chip_index; + + 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_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 = { @@ -86,6 +115,89 @@ 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->idx_valid) { + 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].num_pcm)) { + data->sel_pcm_idx = pcmidx; + data->idx_valid = true; + changed = 1; + } + mutex_unlock(&data->mutex); + + return changed; +} + +static int q6usb_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 q6usb_offload_dev_ctrl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "Q6USB offload SND device select", + .info = q6usb_offload_dev_info, + .get = q6usb_get_offload_dev, + .put = q6usb_put_offload_dev, +}; + +/* Build a mixer control for a UAC connector control (jack-detect) */ +static void q6usb_connector_control_init(struct snd_soc_component *component) +{ + int ret; + + ret = snd_ctl_add(component->card->snd_card, + snd_ctl_new1(&q6usb_offload_dev_ctrl, component)); + if (ret < 0) + return; +} + static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, const struct of_phandle_args *args, const char **dai_name) @@ -115,9 +227,11 @@ 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_idx = sdev->card_idx; + if (!data->idx_valid || data->sel_card_idx < 0) + data->sel_card_idx = sdev->card_idx; set_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].num_pcm = sdev->num_playback; @@ -127,6 +241,7 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, data->status[sdev->card_idx].num_pcm = 0; data->status[sdev->card_idx].chip_index = 0; } + mutex_unlock(&data->mutex); return 0; } @@ -135,6 +250,8 @@ static int q6usb_component_probe(struct snd_soc_component *component) { struct q6usb_port_data *data = dev_get_drvdata(component->dev); + q6usb_connector_control_init(component); + data->usb = snd_soc_usb_add_port(component->dev, &data->priv, q6usb_alsa_connection_cb); if (IS_ERR(data->usb)) { dev_err(component->dev, "failed to add usb port\n"); @@ -189,6 +306,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 Sep 21 21:48:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 142978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5188548vqi; Thu, 21 Sep 2023 15:51:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5cW2XzyGd7Vpm0g3IsqhSB6fGV3Vk7o1NknwuxPdFcUzewTpTPwF/Zkmln18rF+o8H9jw X-Received: by 2002:a05:6a20:160d:b0:15a:3eaa:b7f8 with SMTP id l13-20020a056a20160d00b0015a3eaab7f8mr8033323pzj.50.1695336679622; Thu, 21 Sep 2023 15:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336679; cv=none; d=google.com; s=arc-20160816; b=N3T2vIbMV4smUkwkClFWwHpzIfrsxWHDGx8eJjdXyZ7nsh0bBRiGPS3ftMhLcfQsQM GAI7QQIJ3Xipp60+nWDIt5FLhTfiqkUEbVniUfw4yCF54H739o6MgT4uQQznvCUcrZIi PRbnDKQ4638vpPtjZ72CnoGYUqyPZ7pVZ0KDhkUerFF9k7Uv2yejCOHsRxev1Nyiyqct fHpHSnCS/mGTStc1yiwoCtrjS8ZGoFV6WirFaA7lC14P2e5eB/VkN454p8UUBXR8iPbs Q3BPkJmTM19LIKcJK23zNXQiiA228h2lxkBVA0ywsyxMmBhVbyChvN9T9ydyUQo0j0x6 8f3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LBxkFDyqOnh2+G6P+KTcb0gzdJn618PndBANwN/CVtk=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=MgG8QXSPDMc+2BOS+lh7o4AMg2lLqPFyIdyccg8jdp0QEJQkvnKDHc58qW5MvPMqvl bA+a5fhzwA9nkZfoxNw3yBjUnZvHDBxB/sHWeewWyifGeZvBfjMAb/XikW9DjiRRBvtP tY+jc/GqC7V3X7R1/tTGtv5u3kNtDfEvUgG0mc8GKCsZFhdyDIYFWnd+nOJGUUR42Hnk 4qm22golVlU5pzH2c8qs1JEZyW5s4ErumCpwoagk3r/dbJ2izCaRxJ4VVhhoxzwRLqHW iMz7WM6EW+rsNEeaWQFE6f3gCVFMVIurdbnxhcKNvA25ModEBX9PTpgr3XwMMojWgszr pPHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=I+jNnHit; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y36-20020a056a001ca400b0068fce6a86acsi2414890pfw.121.2023.09.21.15.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=I+jNnHit; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A1926808E646; Thu, 21 Sep 2023 15:02:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232589AbjIUWCo (ORCPT + 29 others); Thu, 21 Sep 2023 18:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbjIUWCW (ORCPT ); Thu, 21 Sep 2023 18:02:22 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54113421C; Thu, 21 Sep 2023 14:49:42 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLiGB2019880; Thu, 21 Sep 2023 21:49: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=LBxkFDyqOnh2+G6P+KTcb0gzdJn618PndBANwN/CVtk=; b=I+jNnHit2LxmqN8VEUft9gqZVi7hbmZFzNcpZ0DQv4WktqNlVS9e4MPzIBCtbfCIMIfI M5VsiST9xXf+YQwNdupPP2usJayAqpbBqq2anWLEGFP5ZYWCDGxu00AUgIwolfHPt/SH B/lpReZiXW7JpthiCYYz+KTcHzn0L0cIld+h0iSY7W2SoOGBuXuNXclT6lGjE7IofwL2 sq46/a8DK8+tk3FrVuKMXQhTv14VaMJnkdLBWT64AIU43mXqQsTHIlejkaoGE6SS+ZZt i+lfZLdC5/O+0hibdabsVn+eMxQHmoViwtRR7rp6jk9VsCOqK7rxIcVwQ532pck0Iv7F Dw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u5n0bq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:18 +0000 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 38LLn2R6009064 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 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.36; Thu, 21 Sep 2023 14:49:01 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 29/33] ASoC: qcom: qdsp6: Add SND kcontrol for fetching offload status Date: Thu, 21 Sep 2023 14:48:39 -0700 Message-ID: <20230921214843.18450-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: vJ-NoKu2mpKjLq4o2KPodOmXsZNFOqTT X-Proofpoint-GUID: vJ-NoKu2mpKjLq4o2KPodOmXsZNFOqTT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:02:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689354436871884 X-GMAIL-MSGID: 1777689354436871884 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 --- sound/soc/qcom/qdsp6/q6usb.c | 104 ++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index a95276b7d91d..d2f60ce66cf3 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -30,6 +30,8 @@ struct q6usb_status { unsigned int num_pcm; unsigned int chip_index; unsigned int pcm_index; + bool prepared; + bool running; }; struct q6usb_port_data { @@ -52,6 +54,17 @@ static const struct snd_soc_dapm_route q6usb_dapm_routes[] = { {"USB Playback", NULL, "USB_RX_BE"}, }; +static int q6usb_find_running(struct q6usb_port_data *data) +{ + int i; + + for (i = 0; i < SNDRV_CARDS; i++) { + if (data->status[i].running) + return i; + } + return -ENODEV; +} + static int q6usb_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -81,14 +94,40 @@ 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; 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; + 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; + 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[] = { @@ -148,10 +187,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; @@ -162,6 +206,8 @@ static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, data->idx_valid = true; changed = 1; } + +out: mutex_unlock(&data->mutex); return changed; @@ -187,11 +233,59 @@ static const struct snd_kcontrol_new q6usb_offload_dev_ctrl = { .put = q6usb_put_offload_dev, }; +static int q6usb_mixer_get_offload_status(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 running; + int card_idx; + int pcm_idx; + + running = q6usb_find_running(data); + if (running < 0) { + card_idx = -1; + pcm_idx = -1; + } else { + card_idx = running; + pcm_idx = data->status[running].pcm_index; + } + + ucontrol->value.integer.value[0] = card_idx; + ucontrol->value.integer.value[1] = pcm_idx; + return 0; +} + +static int q6usb_offload_ctl_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 = 0; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new q6usb_offload_control = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "Q6USB offload status", + .info = q6usb_offload_ctl_info, + .get = q6usb_mixer_get_offload_status, + .put = NULL, +}; + /* Build a mixer control for a UAC connector control (jack-detect) */ static void q6usb_connector_control_init(struct snd_soc_component *component) { int ret; + ret = snd_ctl_add(component->card->snd_card, + snd_ctl_new1(&q6usb_offload_control, component)); + if (ret < 0) + return; + ret = snd_ctl_add(component->card->snd_card, snd_ctl_new1(&q6usb_offload_dev_ctrl, component)); if (ret < 0) @@ -229,8 +323,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 || data->sel_card_idx < 0) + /* + * Update the latest USB headset plugged in, if session is + * idle. + */ + if ((!data->idx_valid || data->sel_card_idx < 0) && + !data->status[data->sel_card_idx].prepared) data->sel_card_idx = sdev->card_idx; set_bit(sdev->card_idx, &data->available_card_slot); From patchwork Thu Sep 21 21:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5561448vqi; Fri, 22 Sep 2023 06:11:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVAYavqYzdP9L4juy2Ryjyninos+hZtuttTZq85/ZlYCOjqx82vS5sZa4ZLPBVSdQNKOht X-Received: by 2002:a17:90b:17c3:b0:263:f4cc:a988 with SMTP id me3-20020a17090b17c300b00263f4cca988mr8154025pjb.5.1695388302242; Fri, 22 Sep 2023 06:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695388302; cv=none; d=google.com; s=arc-20160816; b=NbNvRmkEka7Xh6PklVOTdtBw9a0WXSIx/kL/D+KiHWPTq1wfAu8199d/VKdL7l/3Of YsrbbB7Ur7RS1ICoU7XfAm5+JYc8hGLd7IZswDBmlApcbq45GjYnoZp3wja1CmHQvFoM buaZ7j/TKg0hJKV8ZgZL6YWhvpLl/oy0V9nLwSL0tsO2Zh4sncJ1ubCuOtG6lBIDkyIo 7KxyCNOstVLQV3uOWi4uOG7HWI6nBfa9OH/BaI6AFVGhD70TGUSDhjdbP4qgZcyezju3 9mzptDL4SNkJjLoynMItHkPOU6NpbgKUbSMuj7HUqHuEb+z9CXaNCNvwIxmeaiOB2j2W Cy/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=680s6K8kYHmaW6UIbNRQKTuIHSDR5nqIKTvG3Ugh8so=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=nVyWuKe7pFXY9YjriS6OScmIXSSU1m7k2qrCW5Gg1eHZbfdLtkLcqCYiQnW+K1laWu qyZANsRqIXDOgk0fOFnKGNQjKGNNlmu/uAYk9Za0OkmK1FLGsAG27gckNg2EOl5KUkyE WZuV4WYSztAULr/xo5QSNOJFRqeKOM4kjxYw3VqKyzWm7LBacfVv+byhzK7dmEOTAZ8C X2k3An8+jaKFF8L1ZtjGsDeFsOCQ3xYKlGVAK1iyPWDXNOHxaq5XsLrQCIhi6g4mqdQ8 XjQ7N3d1CkO2hblyNZtYtxAR+1laztowz2+HWZLsHhmszrIx7Osm7mjw6LlxrtJyhKRS SMQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EtCpCykj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id pi2-20020a17090b1e4200b0026818f6a0c0si4450358pjb.86.2023.09.22.06.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:11:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EtCpCykj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 83650832F64C; Thu, 21 Sep 2023 14:54:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbjIUVyD (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbjIUVxX (ORCPT ); Thu, 21 Sep 2023 17:53:23 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248D83C2A; Thu, 21 Sep 2023 14:49:40 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LL73K6030494; Thu, 21 Sep 2023 21:49: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=680s6K8kYHmaW6UIbNRQKTuIHSDR5nqIKTvG3Ugh8so=; b=EtCpCykjlsdAs9I3zHo8WpZIQwK44yI6R9ZS4nXc8DJbvD+pmumsnmEq2W5vTccdwoWp nbKtUYkQ+vocM/RhE9KUeYTZVU7F7kHKjkT6IA8lymM3nVh1nvG+BvRzMrZSWgMM80gV MuYhJDJr1TG/mrbsMaaN6P9g4MWQuD4cGViTN3rX6GVOsjFjp0YkJXOObR3Sa4MiX49W M83vVOkRjagRA2QEMhPmQczaMfOQi2Mr6IP5B8ZDbcaxRJpfk++jIyP6nHpgHbz4/kNF //cODA6n8mw0AMX6Gb6+6DBAn0TeDncOrzSTa4F/SeqUoV6b1xu+BufdKVkXcTAL11e+ gQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u5n0bq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:18 +0000 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 38LLn2ZO032184 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 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.36; Thu, 21 Sep 2023 14:49:01 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 30/33] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Date: Thu, 21 Sep 2023 14:48:40 -0700 Message-ID: <20230921214843.18450-31-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: ai0bEh-pGLtYGP1cLya_lgAgYwPJi8FQ X-Proofpoint-GUID: ai0bEh-pGLtYGP1cLya_lgAgYwPJi8FQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777743484222828188 X-GMAIL-MSGID: 1777743484222828188 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/qdsp6/q6usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index d2f60ce66cf3..9fa6c4016222 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "q6dsp-lpass-ports.h" #include "q6afe.h" @@ -37,6 +38,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; @@ -279,6 +281,7 @@ static const struct snd_kcontrol_new q6usb_offload_control = { /* Build a mixer control for a UAC connector control (jack-detect) */ static void q6usb_connector_control_init(struct snd_soc_component *component) { + struct q6usb_port_data *data = dev_get_drvdata(component->dev); int ret; ret = snd_ctl_add(component->card->snd_card, @@ -290,6 +293,11 @@ static void q6usb_connector_control_init(struct snd_soc_component *component) snd_ctl_new1(&q6usb_offload_dev_ctrl, component)); if (ret < 0) return; + + ret = snd_soc_card_jack_new(component->card, "USB offload", + SND_JACK_HEADSET, &data->hs_jack); + if (ret) + return; } static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, @@ -323,6 +331,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. @@ -338,6 +349,9 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, clear_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].num_pcm = 0; data->status[sdev->card_idx].chip_index = 0; + + if (!data->available_card_slot) + snd_jack_report(data->hs_jack.jack, 0); } mutex_unlock(&data->mutex); From patchwork Thu Sep 21 21:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5448822vqi; Fri, 22 Sep 2023 03:06:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkwXh7PejASMHKZXsSw//fmFXIlBsRkBuHgTVJ6JheXeysOIBT8/vvgncjLe+NJnq32HCN X-Received: by 2002:a05:6a00:cd4:b0:68f:f741:57a1 with SMTP id b20-20020a056a000cd400b0068ff74157a1mr9237541pfv.7.1695377186297; Fri, 22 Sep 2023 03:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695377186; cv=none; d=google.com; s=arc-20160816; b=xZZghYN7MpEvvUYahu79/p/Ep9szemKwdpocsHVIggxODr/xYtTEmheb/clNzNtW5s /dMbF3G8Iej5WEzo6YU3zyziysP1pIWndDtcYGCXRiSwyQzrdL0YOjjMu6ej9YCHShuE 7n4eVY/qrY4D0MJNDUEaSd+4pM55EFDKNWbm0YtBIDg3Jp71vGUvUJZ5FAF34g9l6q+O pN1kUAzH72r8/Pzw3XnlDyBBH5vdD2D8efWbVcFxSurumW8oP/JLyr9MBWPbEMxEUgDd daaaJ4/kNVOKmYFnaQzZwLeLbx7Zi9cYGKTeAN2dyYQ7E1uPQrO7GsuFZ1xqoE126J1c cKow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=e0W9a3ggrYIVw0XCJb6rDIkBiGQl97APIxzQ9iCtvxI=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=srpzgfCHaks+gKYE6xILyMWoA4LfJvTo7Ww6Amz7sZTDAqNR3lM0Pyk4/+Z+Ei+QpJ uieO5YVx6qxBd42qVaDnZiqoenyW1BRzrhPOeBq6m3WfKS+HVtJ9iiwO3bIcoNTIWRs/ EvU6f/IxPfT9+0L5HPhI8BnlW7BvVg9Y7OQvxMGfq4b6zMAP10ddApWcTTA3ETkBuew2 QAcGlV4OcduLQJ1LeJB6h3n5uQVer87PfShZNfmF+m2FcxOpLSa1p/p3dTyb4TZ5BId1 DkA3rWOnf54Qfsh7hYpZ03ZDajXyF5VZrWvgidQNQpa0wJheclvCf0Bo0b+TbGkUkTXK tp0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XsOfqRh7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id g4-20020a056a001a0400b00690fb3c5cecsi3762284pfv.16.2023.09.22.03.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 03:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XsOfqRh7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 389AF8325E97; Thu, 21 Sep 2023 14:54:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233057AbjIUVyM (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjIUVxY (ORCPT ); Thu, 21 Sep 2023 17:53:24 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313DA448F; Thu, 21 Sep 2023 14:49:43 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLXlub007813; Thu, 21 Sep 2023 21:49: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=e0W9a3ggrYIVw0XCJb6rDIkBiGQl97APIxzQ9iCtvxI=; b=XsOfqRh7hp/NDl08znqXS5nAowH8L4meC3n3b/zuMqljGYP7BkLlSB8xCe94SnbNMmVc OIn20ClDQM0pOLsBDtzXFsKUstPVN3chYTWmlbLs0cch+oiIl7in5ovByRDRfiodnTMa hO841Sy7AbHuPNXTcR3h63kgqRlMeg+CaTdQmtC9y5qRY2F8FXRs5o+PqBYi07v2ClDN HL0DoEqCxj6eB9gCdnLVoWMivIC6ab4Y9qqzS5TGpyUfA019gc1EIEpnpbL0RR3+tpb7 1BCTeYytXdb6WOzCfM8ObFN6xmLZXnaKCWUt50IIQbYmYIkRFDZyYoLUTOh+W1SF6YYS 3g== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8txg8cb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:21 +0000 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 38LLn2Dp000321 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 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.36; Thu, 21 Sep 2023 14:49:02 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 31/33] ALSA: usb-audio: qcom: Use card and PCM index from QMI request Date: Thu, 21 Sep 2023 14:48:41 -0700 Message-ID: <20230921214843.18450-32-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: CFPlal0ZwMRLzkXaGQQtPeD65UxO0UVs X-Proofpoint-GUID: CFPlal0ZwMRLzkXaGQQtPeD65UxO0UVs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777731828073483354 X-GMAIL-MSGID: 1777731828073483354 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 2dffe7e99e01..e482e62d5f37 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -109,8 +109,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 { @@ -987,7 +985,7 @@ static int prepare_qmi_response(struct snd_usb_substream *subs, assoc = iface->intf_assoc; 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; alts = &iface->altsetting[subs->cur_audiofmt->altset_idx]; altsd = get_iface_desc(alts); @@ -1388,8 +1386,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; @@ -1598,7 +1595,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 Sep 21 21:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 142991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5192291vqi; Thu, 21 Sep 2023 16:00:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYorfL23wgk4W2RBDx9R/AHv4aTyzAQNAek4zUZVqZQyBAM+QP6hhr/wwYzPcpO7HqHU4F X-Received: by 2002:a05:6359:3201:b0:143:9235:9f1f with SMTP id rj1-20020a056359320100b0014392359f1fmr746115rwb.12.1695337259657; Thu, 21 Sep 2023 16:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695337259; cv=none; d=google.com; s=arc-20160816; b=WxX/dS018Y6NeiZLBg1Nwd5XTs3EXGFcebmDxJsxux1ynwmLmSLnJU2sOsZ+rYtiT3 QSGd96rDDMg5M/foCUX135GzSGpzZ39q0HSNfIWdI3s9dILH6aqxZn7t9En6NfZu/l1k /pDOFHn5LllOfsrIa9UnKtS+VVszYXj8AbCLqhHVuua/yzpD8R3VxN4X2qVXzrSnyzXr bKkZjnYU/DYo/m27jAwRMZP6K0cLOAgTXOnla2kKXdK+erA8J7SC9DuD4+656gP8Xatq m/y/wpToGIgsA0hxqFuKswsW+ADao/jpBMNXGc8z5liZAv5bKi/zwyg6gUKdyZswJ5/b acjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CL3FVM1qBZnRnbh0US8YjFD3CDy8ri2rtoQ7u0QpjGc=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=dTYaRBY0ak1Ko8J0rr2igWlFcpVQD0QsgZ8ySeyJNaLH0/v1zQcTMdpZWe+gdJV4R/ 4UpOUH/3eZUmLPNmPtup8Ma4uamSX3OzOeGJ7/9Q1TGQ0v/0a5mg2VmVqeZXUAhUS8YV ZZD9PWIc+vdiQeC97TR+RRCdcKNDcWWjY/nnAJT4iDTf7lRsezOvoptiBwT0eN/0pVDp 2Cy+MOA036r4pfBDXOSy0656ijAh/zAORh7kPAVfR1gVw33IFRt01QKKupZ9Pzp7TnCz fx//vOYVOzod3G1UfEW3npXpCpsbPJxGu1cCTeqFsfFeEDCf1Y4otFprANI3gIYgBbX3 YopA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aASXP1CR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id f10-20020a65550a000000b00573fe48c908si2350220pgr.128.2023.09.21.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 16:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aASXP1CR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 347848387EC5; Thu, 21 Sep 2023 15:21:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233327AbjIUWVp (ORCPT + 29 others); Thu, 21 Sep 2023 18:21:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233207AbjIUWVA (ORCPT ); Thu, 21 Sep 2023 18:21:00 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF240269E; Thu, 21 Sep 2023 14:49:31 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LLkGvV024475; Thu, 21 Sep 2023 21:49:04 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=CL3FVM1qBZnRnbh0US8YjFD3CDy8ri2rtoQ7u0QpjGc=; b=aASXP1CRFPXmTtiLeI+Rn/0NcGH/688lUbhc1GWeWnomme3cxVY0ZSZ7hCvui8c4Zx4h ECd+8v/AoaqqCx+bV21BA/R5ChzMACFFRVyJDcn2yJRmdvnM2sK8MeE+jPZ3vWxbZgsF aLXkYcqrsx/hR0spGGAb/E3h6j4ATNmQOrp8Qw9jq3AwTcvEqzXrB+l0hVmAXd49B1LC OfsN7vmOlANLTXQdCSJblb7Q/ELghKtMFBJzBxSLWmejvLtFwDQCY3wHUpa4v/RyF0b2 Ga8BMB08c7zT3BKESw4Ay1jxGx9w8Tomnz3ubGmCjCmMJSi+b2neHJ91SxP8tchx86hj uA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uf2g9pp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:03 +0000 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 38LLn2Xw031173 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:02 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.36; Thu, 21 Sep 2023 14:49:02 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 32/33] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Thu, 21 Sep 2023 14:48:42 -0700 Message-ID: <20230921214843.18450-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: RoeeOnwb49JI3NqfV2kxyqmPbxKTjn-9 X-Proofpoint-ORIG-GUID: RoeeOnwb49JI3NqfV2kxyqmPbxKTjn-9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_18,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 clxscore=1015 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:21:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689962576667559 X-GMAIL-MSGID: 1777689962576667559 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 | 19 +++++++++++++++++++ sound/usb/card.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 88f431917c15..7d3f470754ca 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -202,6 +202,25 @@ 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; + + mutex_lock(®ister_mutex); + for (i = 0; i < SNDRV_CARDS; i++) { + if (usb_chip[i]) + if (platform_ops && platform_ops->connect_cb) + platform_ops->connect_cb(usb_chip[i]); + } + mutex_unlock(®ister_mutex); +} +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 01f7e10f30f4..c0aeda17ed69 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -221,11 +221,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 */ From patchwork Thu Sep 21 21:48:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 143776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:910f:0:b0:403:3b70:6f57 with SMTP id r15csp28801vqg; Fri, 22 Sep 2023 18:45:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOOAtej9YKxHQbJkHrkmIYmzYIXa2An5OzPZCRwK9D9yVATWTUxGOxnw+SjzyWIcW8DivU X-Received: by 2002:a05:6808:3da:b0:3a7:88ce:7ac8 with SMTP id o26-20020a05680803da00b003a788ce7ac8mr1333753oie.47.1695433541610; Fri, 22 Sep 2023 18:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695433541; cv=none; d=google.com; s=arc-20160816; b=TB/n6vIjnPiS9MVsV5TaxSuV2OY9H6Y+9uHlmk9zydlst6kjW+WE/yXIKJ5sHYZ6EU t/lINnn7F28rIwihuWc3bkGDcxeHVAVZNTo52sO80LmNdj9GQE7AxJmIEaXfL72MSfds ttPtEb9fHZHIcV6GBb0+xoe1QjFBB5SYq/GOFc4jpcQDqBIk4FVq3ImddqI3k/iDFF3y amJnG66WjL1MBmrSkC2DUTsWCwZvy5FHpBkxgsm8w+2DmYlTdFUhwbwhv9KVSUQOBHzd YSFyk5jeCJdaLxAS6xYxNnqmdK6siwcV0PBlBUREjchoAmbUpxgVUMZwGtn3cy3XR2m0 mr7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jt0oIgTyqjbTXFE8R+uBXHTwbnogDehsEUidVF5fLmc=; fh=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=lky/yg5pZapwU8yDx29s8omnmvtyNB2bSbK7rJ1TBckl3rPw00ytScKQi3cXcxMX6G ETLE4D5h0okqYETye7cPZSeDB8CKHn9/J6bR64wqUp4IR21rVmz95cUoLUJMPnN4U4jN 6eUIyeQFYkz/VgcLadz5zpt4+TzJjHAOnwnf0bffgCywAGZCFVIilnDj2zW2aKn3ClIk B9rweTW9kRg//RcRz94yEqvk31fwTDVKSck+1knIdIUhUX9itGWeAaobLjrrx+4UCXYr 3G604poSFc2WWuT7CvQsQQms1cR+GM6dgDCmkTTnv9h23xqa8y533p89ToplZoyzeNkd mMAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MepJ+upG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id f23-20020a63f117000000b0056679c8e70csi5166190pgi.272.2023.09.22.18.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 18:45:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MepJ+upG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 715938370879; Thu, 21 Sep 2023 14:54:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233062AbjIUVyO (ORCPT + 29 others); Thu, 21 Sep 2023 17:54:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230439AbjIUVxX (ORCPT ); Thu, 21 Sep 2023 17:53:23 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9901410C6; Thu, 21 Sep 2023 14:49:41 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LJp8sC021537; Thu, 21 Sep 2023 21:49: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=jt0oIgTyqjbTXFE8R+uBXHTwbnogDehsEUidVF5fLmc=; b=MepJ+upGMC1sdTcJTSVbHR4RoDqNx6wVoRzmygug+04KquPz9HEL7lRSToIR0rsC9fX9 C5mY3pk8tiXTyL3cPecy9FBFpfIyZbVNdqhaEsS5EAa5gEDA74vaf836/dJWmBuGAn5I dGYJgPZTUcOFQeZTK4mpVPSgK/RA7NUj3WIxeGg6HdmFF2/CgJNiUsPT+SvvVzw+/wJE x1Y2U7iOjT9gXMVYRUsg8KztGRfaGldOab8l6JOFWLCX83DsgQ7X88s5mtzFhLsEsSqG ycmoHrGJlPxdHNCtlx01i+/mgnXYny9LvK+E1IYmkptE9OpvPMW7RYA1H/mJWlQ0wMN3 FA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u5n0bqa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:18 +0000 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 38LLn36L012662 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:03 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.36; Thu, 21 Sep 2023 14:49:02 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 33/33] ASoC: usb: Rediscover USB SND devices on USB port add Date: Thu, 21 Sep 2023 14:48:43 -0700 Message-ID: <20230921214843.18450-34-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: Ge7Hcxdn640ava6jWa6SIXk8D6arxYXD X-Proofpoint-GUID: Ge7Hcxdn640ava6jWa6SIXk8D6arxYXD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_19,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210189 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:54:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777790921223979023 X-GMAIL-MSGID: 1777790921223979023 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 619f9bfd6999..7df7f93cf5a2 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -115,6 +115,8 @@ struct snd_soc_usb *snd_soc_usb_add_port(struct device *dev, void *priv, list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); + snd_usb_rediscover_devices(); + return usb; } EXPORT_SYMBOL_GPL(snd_soc_usb_add_port);