From patchwork Thu Mar 23 19:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 74185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp3091865wrt; Thu, 23 Mar 2023 12:22:19 -0700 (PDT) X-Google-Smtp-Source: AKy350YTyj7ihIO2EyU8nYELwu943eLPrv6Ti2sisf4Mt84peO8rmvkor53Npv4Y0oFOxiULkcOW X-Received: by 2002:a17:906:175a:b0:92c:8e4a:1a42 with SMTP id d26-20020a170906175a00b0092c8e4a1a42mr144141eje.32.1679599338940; Thu, 23 Mar 2023 12:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679599338; cv=none; d=google.com; s=arc-20160816; b=jEWy/881c1sxEpYEjZ1uM4y/FBr7OKC4ex3Q2f6jQbDkVFwsBWPLJbnT4jA9KmKHNF IIfS0CjZOzcafTm0i12oBa1wu4jA+qgw5Wmm/DVx0VcZQdEAPccwYHNC22q3USZSGmr4 7nLrDU2HobokqttMkDKR/blIZfoWyk8S/oydFaciiA/7+MeYjojO/RzBwRBvuP4acLJI 8dsSo1c51mzPhqk8VPelfjd3NFZLA0UEbx7NWEYRIDt7u7kf4X2gapA1zWu1o/14YrCA 3o1H4U4kpjw9hsDqHmiij3qh7dkxAeRQzUi5l2hnN400s5WBClQDDRRz5ciZ6P+YtCrK 4dTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z651w3Zr09wKIQBW4iFS4x7U8CUJKlv+nPJ1dwbKYMA=; b=iisgrThhKWtfvJKA2WkkFch5HPpaRFltE/K9OZRtH1Qj5r8r+fmgYu54SugaAusu7k BTmshgpeAs50Z2GcW5xPNCgpE4/f+s0ZIrD8MWvw8EUSlWZgWSXgOvobRwdljZSh3Dgs y7U8DbyyUjklchumpM3xJs92CTkHACchqE7/ZHzA4IAedMyI9nPsclieOn1rFkYoX/t5 gfvNzcnC2OouYvhiA7R+9Xt1LAVw/+aNe4Kv2a2Vo292+W9UJClF0KRbYbu/vGKQ7rYH a7TR5ykIDDd4CpjYsBJe3j3NICj0GxION4RdFhLCzkSRe+LN8ZPT9phFzhu+JduBtJzV MUPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EYgFbn7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a056402161500b004acb32d3a1bsi18430873edv.362.2023.03.23.12.21.52; Thu, 23 Mar 2023 12:22:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=EYgFbn7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjCWTQV (ORCPT + 99 others); Thu, 23 Mar 2023 15:16:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231589AbjCWTQN (ORCPT ); Thu, 23 Mar 2023 15:16:13 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC42E9EEA; Thu, 23 Mar 2023 12:16:12 -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 32NJFHFs002308; Thu, 23 Mar 2023 19:16:07 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-transfer-encoding : content-type; s=qcppdkim1; bh=Z651w3Zr09wKIQBW4iFS4x7U8CUJKlv+nPJ1dwbKYMA=; b=EYgFbn7+9ceF/F6+D7Qsbz3ORFndurxbOSE4uhenGSx+Y/J++5c7iWi2l2Hl6vXNZALC D+Yn6yq31yP339Aa4Q6nxK/Lshw4FsefAzCab189oBcyuKrVz1Hnq3C2Tyjmp3ajvBb0 juA6RKuhgYM3HCPjnufLuiQ6827rH8t/r3CqOr5FnXNxbla+LPWv4MjTwZdJVI3KYqjU j03AOtoHSbLs7DwSSgm1kLVpnx7A8FFcEqJfGIPByRSTxFtFGbW5kQknPHYtLIMqpFIu M2CZ5hIKN60AVevDVQCLl6v8siYrxZxNa/T+ktGiNw9ws+gJLjCJGSIPnUR8IrcPHeaA yA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pgfv6a42h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:07 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32NJG6sV019372 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:06 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 23 Mar 2023 12:16:06 -0700 From: Elliot Berman To: Jassi Brar CC: Elliot Berman , Sudeep Holla , , , Subject: [PATCH v2 1/3] mailbox: Allow direct registration to a channel Date: Thu, 23 Mar 2023 12:15:25 -0700 Message-ID: <20230323191527.1472695-2-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230323191527.1472695-1-quic_eberman@quicinc.com> References: <20230323191527.1472695-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: jMBalDA7of7syKMZqJw2ti_Cdso3AFJJ X-Proofpoint-ORIG-GUID: jMBalDA7of7syKMZqJw2ti_Cdso3AFJJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-23_12,2023-03-23_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxlogscore=980 malwarescore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 phishscore=0 impostorscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230141 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761187556190617032?= X-GMAIL-MSGID: =?utf-8?q?1761187556190617032?= Support virtual mailbox controllers and clients which are not platform devices or come from the devicetree by allowing them to match client to channel via some other mechanism. Tested-by: Sudeep Holla (pcc) Signed-off-by: Elliot Berman --- drivers/mailbox/mailbox.c | 96 ++++++++++++++++++++++++---------- include/linux/mailbox_client.h | 1 + 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 4229b9b5da98..adf36c05fa43 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -317,6 +317,71 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout) } EXPORT_SYMBOL_GPL(mbox_flush); +static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) +{ + struct device *dev = cl->dev; + unsigned long flags; + int ret; + + if (chan->cl || !try_module_get(chan->mbox->dev->driver->owner)) { + dev_dbg(dev, "%s: mailbox not free\n", __func__); + return -EBUSY; + } + + spin_lock_irqsave(&chan->lock, flags); + chan->msg_free = 0; + chan->msg_count = 0; + chan->active_req = NULL; + chan->cl = cl; + init_completion(&chan->tx_complete); + + if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) + chan->txdone_method = TXDONE_BY_ACK; + + spin_unlock_irqrestore(&chan->lock, flags); + + if (chan->mbox->ops->startup) { + ret = chan->mbox->ops->startup(chan); + + if (ret) { + dev_err(dev, "Unable to startup the chan (%d)\n", ret); + mbox_free_channel(chan); + return ret; + } + } + + return 0; +} + +/** + * mbox_bind_client - Request a mailbox channel. + * @chan: The mailbox channel to bind the client to. + * @cl: Identity of the client requesting the channel. + * + * The Client specifies its requirements and capabilities while asking for + * a mailbox channel. It can't be called from atomic context. + * The channel is exclusively allocated and can't be used by another + * client before the owner calls mbox_free_channel. + * After assignment, any packet received on this channel will be + * handed over to the client via the 'rx_callback'. + * The framework holds reference to the client, so the mbox_client + * structure shouldn't be modified until the mbox_free_channel returns. + * + * Return: 0 if the channel was assigned to the client successfully. + * <0 for request failure. + */ +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) +{ + int ret; + + mutex_lock(&con_mutex); + ret = __mbox_bind_client(chan, cl); + mutex_unlock(&con_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(mbox_bind_client); + /** * mbox_request_channel - Request a mailbox channel. * @cl: Identity of the client requesting the channel. @@ -340,7 +405,6 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) struct mbox_controller *mbox; struct of_phandle_args spec; struct mbox_chan *chan; - unsigned long flags; int ret; if (!dev || !dev->of_node) { @@ -372,33 +436,9 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) return chan; } - if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { - dev_dbg(dev, "%s: mailbox not free\n", __func__); - mutex_unlock(&con_mutex); - return ERR_PTR(-EBUSY); - } - - spin_lock_irqsave(&chan->lock, flags); - chan->msg_free = 0; - chan->msg_count = 0; - chan->active_req = NULL; - chan->cl = cl; - init_completion(&chan->tx_complete); - - if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) - chan->txdone_method = TXDONE_BY_ACK; - - spin_unlock_irqrestore(&chan->lock, flags); - - if (chan->mbox->ops->startup) { - ret = chan->mbox->ops->startup(chan); - - if (ret) { - dev_err(dev, "Unable to startup the chan (%d)\n", ret); - mbox_free_channel(chan); - chan = ERR_PTR(ret); - } - } + ret = __mbox_bind_client(chan, cl); + if (ret) + chan = ERR_PTR(ret); mutex_unlock(&con_mutex); return chan; diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index 65229a45590f..734694912ef7 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -37,6 +37,7 @@ struct mbox_client { void (*tx_done)(struct mbox_client *cl, void *mssg, int r); }; +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl); struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, const char *name); struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); From patchwork Thu Mar 23 19:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 74184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp3091825wrt; Thu, 23 Mar 2023 12:22:14 -0700 (PDT) X-Google-Smtp-Source: AK7set8AIqBXFp0FXtDFPzLcyS9DUnTTiFi294wzdyAalIo/Ra5behL4rfRO9Y7EXPKNDl4lwcuH X-Received: by 2002:a05:6a20:2098:b0:d0:61ff:8535 with SMTP id b24-20020a056a20209800b000d061ff8535mr646714pza.4.1679599334316; Thu, 23 Mar 2023 12:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679599334; cv=none; d=google.com; s=arc-20160816; b=PglxfnhnLkxwSESK3099hUPd6WU3JhD/6A68FCgV1Le+uEs0/a1A+D6PzOG47l+Npc QOv12Bu2Yq3146rM4FUjHFSuEPnqD/JvHwCz6PR5OFa9oxIXVKdXGCGSvQi4+2KAO5QS VQ5ZnPTJ8Jv7ljjhYZh8gHyDouSlFiNSbSz8ggzcxjukbEBCgs0VQFtsnFuIoZrtjwgU EIZSoG3VcMCHOAZixBswHy4wPQutsWODAf0GQ3R78189UXy6EO1+Sd8DmWIbH6iXIYFU 1g4oI67MV6P8hJ94gidA2FnHUtmXie74ZRw85Twj9xeUGvnTeBaOCOMTn9h/oPRbob0W A4bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8YqbOZ+zPszKRteZJwJzU3+KjVpZYfDq8pQt6ZMxOqQ=; b=eku7WvBzo7krqc15sYiw/cRoN+LAesisjE13dEEyknlFSFl9uOTtyTN2vKPL9T3wO8 EF5bs/lD3cdwCEGEs2fst9raIF3CYaSjGfq14ERFCCG2Lxae9rIccdvr8sGxiIy56vRy oqKm9WCIIwTCWcsYeeVQR2MEoynQjwS/IUu2anO24fJUE9Zw0+kYX/5m0eJHCzrcVoI7 W1uuH6Owv0A1O0/zjDpB9vc+3cdR7aPdexEZHaq/kusDkryiNK9AfCIKZ2ywpiESB3Og 2mA1Yd5Rm9AuJIrAiMZdDj5aZa7KPWB7R0PWEOhuvWyp8eLWIz0pFIFHftIN0wE15ai9 Pn8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="c/2ZeS9L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a056a0002a600b00590712dd84bsi18537297pfs.81.2023.03.23.12.22.00; Thu, 23 Mar 2023 12:22:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="c/2ZeS9L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbjCWTQQ (ORCPT + 99 others); Thu, 23 Mar 2023 15:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231611AbjCWTQN (ORCPT ); Thu, 23 Mar 2023 15:16:13 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F407E83E6; Thu, 23 Mar 2023 12:16:11 -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 32N42B8s016035; Thu, 23 Mar 2023 19:16:08 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-transfer-encoding : content-type; s=qcppdkim1; bh=8YqbOZ+zPszKRteZJwJzU3+KjVpZYfDq8pQt6ZMxOqQ=; b=c/2ZeS9Lq8bBFdeRAmuvtv7bUMPmDVAy1fB2Cg2h1ad+kKfXAf8pUSjWEyzAmMXV94Z5 /M5G5bv9M2DJyKHYUk2D7eZBjIEhZZ/yNl7LAAjmIh2UZ+RiYZD8zpopLJnU6mgjtMEo rjNrQC0DDfaBabVaFeQ0jUoRhliTlocmIMVaWU22SvZzev+ultxZSbgHYxDq1S1PocTT y/Dj4pcNhBCEiZpkrTnOLwOuXK5EEkg+yn5RvB47uHLJRNKJ4MPEDJdI7AO6JrWshYXk lOmcijwNuDiVXkgtaXF53aLgeCfxPaPnG5ovGjBhFpqINVtu24LYycWVKJZtkciGSRpj xw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pgfaxj6u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:08 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32NJG733002838 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:07 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 23 Mar 2023 12:16:06 -0700 From: Elliot Berman To: Jassi Brar CC: Elliot Berman , Sudeep Holla , , , Subject: [PATCH v2 2/3] mailbox: omap: Use mbox_bind_client Date: Thu, 23 Mar 2023 12:15:26 -0700 Message-ID: <20230323191527.1472695-3-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230323191527.1472695-1-quic_eberman@quicinc.com> References: <20230323191527.1472695-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 1sPoIAR6C65FD0lVjBL4uL4DUAzPP1sy X-Proofpoint-ORIG-GUID: 1sPoIAR6C65FD0lVjBL4uL4DUAzPP1sy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-23_12,2023-03-23_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=684 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230141 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761187551374459215?= X-GMAIL-MSGID: =?utf-8?q?1761187551374459215?= Use generic mbox_bind_client() to bind omap mailbox channel to a client. mbox_bind_client is identical to the replaced lines, except that it: - Does the operation under con_mutex which prevents possible races in removal path - Sets TXDONE_BY_ACK if omap uses TXDONE_BY_POLL. omap uses TXDONE_BY_IRQ, so this check is not applicable. - Calls chan->mbox->ops->startup, if available. omap doesn't have, so this is not applicable. Signed-off-by: Elliot Berman --- drivers/mailbox/omap-mailbox.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/mailbox/omap-mailbox.c b/drivers/mailbox/omap-mailbox.c index 098c82d87137..dfe82a5ff403 100644 --- a/drivers/mailbox/omap-mailbox.c +++ b/drivers/mailbox/omap-mailbox.c @@ -417,8 +417,6 @@ struct mbox_chan *omap_mbox_request_channel(struct mbox_client *cl, struct device *dev = cl->dev; struct omap_mbox *mbox = NULL; struct omap_mbox_device *mdev; - struct mbox_chan *chan; - unsigned long flags; int ret; if (!dev) @@ -441,23 +439,11 @@ struct mbox_chan *omap_mbox_request_channel(struct mbox_client *cl, if (!mbox || !mbox->chan) return ERR_PTR(-ENOENT); - chan = mbox->chan; - spin_lock_irqsave(&chan->lock, flags); - chan->msg_free = 0; - chan->msg_count = 0; - chan->active_req = NULL; - chan->cl = cl; - init_completion(&chan->tx_complete); - spin_unlock_irqrestore(&chan->lock, flags); - - ret = chan->mbox->ops->startup(chan); - if (ret) { - pr_err("Unable to startup the chan (%d)\n", ret); - mbox_free_channel(chan); - chan = ERR_PTR(ret); - } + ret = mbox_bind_client(mbox->chan, cl); + if (ret) + return ERR_PTR(ret); - return chan; + return mbox->chan; } EXPORT_SYMBOL(omap_mbox_request_channel); From patchwork Thu Mar 23 19:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 74183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp3091659wrt; Thu, 23 Mar 2023 12:21:51 -0700 (PDT) Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Zypnxxwj X-Google-Smtp-Source: AK7set9UQtgCadDwGsBH59gNWIJIgMDvWT4S40/gdg9dpHtbkHdWdp/wWwuwSM985Pk3Jhp2SazU X-Received: by 2002:a17:90a:520c:b0:23f:618a:6bec with SMTP id v12-20020a17090a520c00b0023f618a6becmr8070557pjh.49.1679599311197; Thu, 23 Mar 2023 12:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679599311; cv=none; d=google.com; s=arc-20160816; b=gIZlOCFL01VCLjovoTVoNf7i1LdJ1OiVgEvTTjhq0Bknx2CSXGo29FFLyR79XzrhpD Igp0AnFZR8InXMshUAvco8ib5/PPyBLj0+8aseQtWpSB7KyG+EonNjk4RMWfaF0GEFKH csOei8kiCVrr/kW2LFn9KnDSplwINHkT/O6gqgjqINZUbD8Ey7a2lQDIVQ/ym5FqQULv 7YWZ1CYz9H8EmvOkBpnmSBU3ydsp/Z0UcXJBfZP8uyIm7V6/hU97wONqWbiDH7uKTDg3 0y69x3JD90UI8QRKA6TtQPRygysZfj2JfjW/XrVXyP39+LJLgu6blT1cJmWU7pnk/QME H3kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AsLuWZMU0pEXcJlZrbFHzc7hyBlA/hDA5NWZw9Nnua0=; b=vy3iCVq50Jm59HNglO9WZeHHvLDpotzskP2rt50QUJFLGSF7GwCCE/U7TrrDJxxD9Q Jrskv0jbE6XYwqeHAxtHZ60q3cmKfdnrr4FZ9AVxVySUKcDvyKQGO1lIwYGcVYPIh4Ew lfYVRXHjw77O/2Q9UoRe8SMvoKXBH1mH0R9idGtWANsQGeClcggGhPZzhhN1oON0vVlB wLMdVWDcE/4N0TKlvNH+QRXrYRetF/d1NjOVg5dyzJKwr4Y1+9XfFwwpJUkIbb7MTxPY /svb+gjDKSm/bw8Pz7A+SGQThSGZj8jVYZX14ewiwlEpSV95DnRzCJ+QICmz7jRJGHpW XaQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Zypnxxwj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a17090a648f00b00234ac7c8061si2483975pjj.175.2023.03.23.12.21.37; Thu, 23 Mar 2023 12:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Zypnxxwj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231649AbjCWTQS (ORCPT + 99 others); Thu, 23 Mar 2023 15:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjCWTQN (ORCPT ); Thu, 23 Mar 2023 15:16:13 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 972C19000; Thu, 23 Mar 2023 12:16:12 -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 32NJ0Iuk026875; Thu, 23 Mar 2023 19:16:08 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-transfer-encoding : content-type; s=qcppdkim1; bh=AsLuWZMU0pEXcJlZrbFHzc7hyBlA/hDA5NWZw9Nnua0=; b=Zypnxxwjo+Hr7M4zzmbQ69wqnivBcUAY4c/aPoIksT382qE5yXCtYSI1NRd+51f/xzht uVZ8FMXijvx9GPu7ybyx4kKGJXH5Zj/8aBl4yxPzLcuUbRe/SHyRls7+xzLEK493EY19 NKrwyST8eRvxpzr5Bn18TdiptR1lqAMkOVBvaGfkEn/htSAqD2vDy9TSDHdZgd2cwxmo p0TZjON2Neo2BiDyE++g0cDcK/0IyWG5CMpNQVEQHh21GUBHCwWeDFWVZmAZIRGoTNtZ wKE0OC0j1kMwD+hdFQHPVO8q4TMdPWKZxHQ3wZEkfjDSTHlZ8hnYzmbY0aUMYMibv6G+ fw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pgfv6a42m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:08 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32NJG81i019385 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 19:16:08 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 23 Mar 2023 12:16:07 -0700 From: Elliot Berman To: Jassi Brar , Sudeep Holla CC: Elliot Berman , , , Subject: [PATCH v2 3/3] mailbox: pcc: Use mbox_bind_client Date: Thu, 23 Mar 2023 12:15:27 -0700 Message-ID: <20230323191527.1472695-4-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230323191527.1472695-1-quic_eberman@quicinc.com> References: <20230323191527.1472695-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: dhYEWwJk9JL_NKKvzPjdnsCS3gGzx6lw X-Proofpoint-ORIG-GUID: dhYEWwJk9JL_NKKvzPjdnsCS3gGzx6lw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-23_12,2023-03-23_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxlogscore=665 malwarescore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 phishscore=0 impostorscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230141 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761187527171767821?= X-GMAIL-MSGID: =?utf-8?q?1761187527171767821?= Use generic mbox_bind_client() to bind omap mailbox channel to a client. mbox_bind_client is identical to the replaced lines, except that it: - Does the operation under con_mutex which prevents possible races in removal path - Sets TXDONE_BY_ACK if pcc uses TXDONE_BY_POLL and the client knows when tx is done. TXDONE_BY_ACK is already set if there's no interrupt, so this is not applicable. - Calls chan->mbox->ops->startup. This is usecase for requesting irq: move the devm_request_irq into the startup callback and unregister it in the shutdown path. Tested-by: Sudeep Holla Signed-off-by: Elliot Berman --- drivers/mailbox/pcc.c | 82 ++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 105d46c9801b..3a025415c5d5 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -283,7 +283,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) struct pcc_chan_info *pchan; struct mbox_chan *chan; struct device *dev; - unsigned long flags; + int rc; if (subspace_id < 0 || subspace_id >= pcc_chan_count) return ERR_PTR(-ENOENT); @@ -296,30 +296,9 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) } dev = chan->mbox->dev; - spin_lock_irqsave(&chan->lock, flags); - chan->msg_free = 0; - chan->msg_count = 0; - chan->active_req = NULL; - chan->cl = cl; - init_completion(&chan->tx_complete); - - if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) - chan->txdone_method = TXDONE_BY_ACK; - - spin_unlock_irqrestore(&chan->lock, flags); - - if (pchan->plat_irq > 0) { - int rc; - - rc = devm_request_irq(dev, pchan->plat_irq, pcc_mbox_irq, 0, - MBOX_IRQ_NAME, chan); - if (unlikely(rc)) { - dev_err(dev, "failed to register PCC interrupt %d\n", - pchan->plat_irq); - pcc_mbox_free_channel(&pchan->chan); - return ERR_PTR(rc); - } - } + rc = mbox_bind_client(chan, cl); + if (rc) + return ERR_PTR(rc); return &pchan->chan; } @@ -333,23 +312,12 @@ EXPORT_SYMBOL_GPL(pcc_mbox_request_channel); */ void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan) { - struct pcc_chan_info *pchan_info = to_pcc_chan_info(pchan); struct mbox_chan *chan = pchan->mchan; - unsigned long flags; if (!chan || !chan->cl) return; - if (pchan_info->plat_irq > 0) - devm_free_irq(chan->mbox->dev, pchan_info->plat_irq, chan); - - spin_lock_irqsave(&chan->lock, flags); - chan->cl = NULL; - chan->active_req = NULL; - if (chan->txdone_method == TXDONE_BY_ACK) - chan->txdone_method = TXDONE_BY_POLL; - - spin_unlock_irqrestore(&chan->lock, flags); + mbox_free_channel(chan); } EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); @@ -377,8 +345,48 @@ static int pcc_send_data(struct mbox_chan *chan, void *data) return pcc_chan_reg_read_modify_write(&pchan->db); } +/** + * pcc_startup - Called from Mailbox Controller code. Used here + * to request the interrupt. + * @chan: Pointer to Mailbox channel to startup. + * + * Return: Err if something failed else 0 for success. + */ +int pcc_startup(struct mbox_chan *chan) +{ + struct pcc_chan_info *pchan = chan->con_priv; + int rc; + + if (pchan->plat_irq > 0) { + rc = devm_request_irq(chan->mbox->dev, pchan->plat_irq, pcc_mbox_irq, 0, + MBOX_IRQ_NAME, chan); + if (unlikely(rc)) { + dev_err(chan->mbox->dev, "failed to register PCC interrupt %d\n", + pchan->plat_irq); + return rc; + } + } + + return 0; +} + +/** + * pcc_shutdown - Called from Mailbox Controller code. Used here + * to free the interrupt. + * @chan: Pointer to Mailbox channel to shutdown. + */ +void pcc_shutdown(struct mbox_chan *chan) +{ + struct pcc_chan_info *pchan = chan->con_priv; + + if (pchan->plat_irq > 0) + devm_free_irq(chan->mbox->dev, pchan->plat_irq, chan); +} + static const struct mbox_chan_ops pcc_chan_ops = { .send_data = pcc_send_data, + .startup = pcc_startup, + .shutdown = pcc_shutdown, }; /**