From patchwork Thu Feb 16 16:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 58169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp405378wrn; Thu, 16 Feb 2023 08:45:00 -0800 (PST) X-Google-Smtp-Source: AK7set8HEMe0aVjHxnBZJbB8fk9GINmJenIAhK4iopz/LXEaJgG5WNMXkLSnHpMNTAjea9+vuEcV X-Received: by 2002:a17:906:9485:b0:870:827f:f78e with SMTP id t5-20020a170906948500b00870827ff78emr6295526ejx.48.1676565900534; Thu, 16 Feb 2023 08:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676565900; cv=none; d=google.com; s=arc-20160816; b=DIFoaY9vZKzJP5YtZ9OTQIVu4+b20JBovEhBAHo4SBT7m8wb+YQpPLFCYXo0qyB9in bIOzL4xqsKsbxZyDqjQ2coOi3JP41ZYT1DjI9hLiQ7e/nA3U6Z0e+kvC1dkwvOWgV8Ao 9GwJdTr117fDzn53Gen04g/XkcoYmLs5rDCQaGw3yAl6k1amBtG181IiPoC5Shiqe/uz oDE//xGKcAjLl0n5R9BckEh5Rq61sQZ3Y5STz9W9vOZ8JvdxQEyoToLUZafvNTTtQnQA ZtEMPloly7ECol8lxW91/hpg/q/YzFMN/9khXAzK2nstimeKvykmhMB8QpxvQhapmEx2 w2LA== 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=xkLbnqJt/sijM+Co64dSaanSfQWhIPybj6CY+XxPrR8=; b=QSMtQYyd8JVjEMmZd5cHO0xaj9qDqFvgE4lkwgKUCx1tXuJ7MEBztBNaMEe9A77iNQ FXyOChBS5Ha27b+7esWF/yvAyoNgzxEwS4WrfUl/57lVarBQ4oOBXY16iTv9bx69V5u/ zNZScU7eondwrgocjWCc6ijTkdS/uoyNOLNr+57ZINZk6KwKuREN75gPNWGCnEL6L2uf KG0VV3wwaMkewSYjD5ub2G7fXxSelg7zH2FR6E6bagPlsxOUZ0OYDSfdJRnDsDaejqcp xJi+NFyhwlniS0T3yZusiJzUpaRAUBa5ySwaufuT2TEtwdczjHbeS8Xu9xJaeA4PoVwg SODA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bTZKxEEY; 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 ew20-20020a170907951400b008b145f10ea6si2359301ejc.388.2023.02.16.08.44.36; Thu, 16 Feb 2023 08:45:00 -0800 (PST) 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=bTZKxEEY; 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 S229436AbjBPQi1 (ORCPT + 99 others); Thu, 16 Feb 2023 11:38:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjBPQi0 (ORCPT ); Thu, 16 Feb 2023 11:38:26 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F29FC4CC98; Thu, 16 Feb 2023 08:38:23 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31G9v6W8006206; Thu, 16 Feb 2023 16:38:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=xkLbnqJt/sijM+Co64dSaanSfQWhIPybj6CY+XxPrR8=; b=bTZKxEEYXlAriNHGjQI+btGTq8axeObcfAi0eLBZkcOmP0y5eqQSz7PVdO7XU1dM/Uu3 Bn3kIHnGdnhfrYvEEp5j37Ybwcaprd/DHe5EcfrTmgdgNw2ONELRsj+WHQ+RXPicB3ny wtHIBdr/3OXSWEkVbsZGDHt2wnxLIGWtzDYJcnLk4BJ3vDS2G83zSanes4FiqHYbOyf2 1RNpQwtsw+cdZ9qtt3qjZ59ok5L4ebg6ip+0+YOFgkzYTo5N6LqhHjPOsLlTHXJnuEAE sS2snKNS+JYN3b4Yk8DBR0B9KEonFURoVXIe4htDOLOYYoEBzyeHCdECz7jGjwK10ut9 6Q== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nsja910cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 16:38:20 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 31GGcJiQ011639 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 16:38:19 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, 16 Feb 2023 08:38:18 -0800 From: Elliot Berman To: , Jassi Brar CC: , , , Subject: [PATCH 1/3] mailbox: Allow direct registration to a channel Date: Thu, 16 Feb 2023 08:38:03 -0800 Message-ID: <20230216163804.456714-1-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213232537.2040976-1-quic_eberman@quicinc.com> References: <20230213232537.2040976-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 8bNlDWfzueRAZh6CaVV4wflYTGdv_NWy X-Proofpoint-ORIG-GUID: 8bNlDWfzueRAZh6CaVV4wflYTGdv_NWy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-16_12,2023-02-16_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302160144 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 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757761554149274737?= X-GMAIL-MSGID: =?utf-8?q?1758006765906579999?= 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. 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 Mon Feb 13 23:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 56596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2643617wrn; Mon, 13 Feb 2023 15:44:10 -0800 (PST) X-Google-Smtp-Source: AK7set/8MeVwV+rG7YC9sFYO3deoFhTq54OsS28g7tNXfrL0uLWYmqrBqlXC9mWNWhAKvzHwg5EM X-Received: by 2002:a50:d79e:0:b0:4ac:bba0:435b with SMTP id w30-20020a50d79e000000b004acbba0435bmr403248edi.35.1676331850341; Mon, 13 Feb 2023 15:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676331850; cv=none; d=google.com; s=arc-20160816; b=FbvdI09UHDwOQafxYoK4xboDnl70yinFa3vVvr0glftyxVOjcY0He2B5BbDuldxtY9 Pwoc6jD2rGxsbYSdgVIJWYfKUDYLbkpzXk0N/5+e7WVa4b2e7ehJTeOZBlBUJe3nNtKp NqT6FRZbsK4dskxmySHakEzBQpacn/LwCGrEdlymMKe0u+pUjhA799428Wh3Dr4mLr5F UaXECnhXnxtQPbnKeThpS8W01afpjk7Q3FX9HZ9Bcu0G+aLXIRg4VlPObqZCboiViAWS OYmk6d8M2ZFgjPEjnqCST+ZRMQI/w5yzzvlXUtT4Ptt9eXqHNqNaKRWwmJSiZXR1Loya Ai4g== 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=5h/EZHc8rrmczzuC0ieTpz03Ifs78USEUnGyDzlpK8I=; b=JJHcL5DOIHRZSZUh4/G/97dZh9WAsRIC6Tam5MJreBDu4jBImVLWBniBI46gzQsfcA Z4eWIU5ReGzD+4OeVLjP75EzjjqjtEjzb8byePCCrd1yqhhECWRxC3CNyeTZeFhbqdBr VJTJ81jeDfdhWP8hnPb9VOYyWRolSxuI7VmX4R0LptRulIedcwL+GLd/FZFFDUwdwQys hPJ22y3jiOwt6Z6CjZHt0Iv2qBbjbIXXGb9VzUSZHi8u4p3QhybRQ7TriMmMVHuamSXQ EHLeH/SRK9mjl+ISygOC4G+4etzWgGbcTbBOkzKCkPRotBODCcXZ4iVwrOOub7TmuWqq y7vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dB+hfJnh; 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 ba17-20020a0564021ad100b004a08c6ced0dsi15228389edb.536.2023.02.13.15.43.47; Mon, 13 Feb 2023 15:44:10 -0800 (PST) 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=dB+hfJnh; 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 S230484AbjBMX01 (ORCPT + 99 others); Mon, 13 Feb 2023 18:26:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjBMX0Z (ORCPT ); Mon, 13 Feb 2023 18:26:25 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE17F900B; Mon, 13 Feb 2023 15:26:24 -0800 (PST) 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 31DMP72D009111; Mon, 13 Feb 2023 23:26: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-transfer-encoding : content-type; s=qcppdkim1; bh=5h/EZHc8rrmczzuC0ieTpz03Ifs78USEUnGyDzlpK8I=; b=dB+hfJnhKHbfL+9xrzVcomRcjt4Vxp1GVkQXjZ7LnmBumj6Sr3pzIYr668l53gQ+CBjq rJsVVH1R/MUeGvymJIFQwhK7ToWxKCOgXsoaUSxzhsfQ07Jmn5mGgNFZacxJNJ0tNKG/ PLdLQlp/9BtD8YtMV0aWqtcJVad3zdMcwdHX7zSRh9S0anY3mayR7r9dUhZUlMRacSfs 1nqzdpeZHSkurCz4BRCoJph+fLHFIQ6EycdPvOU4eRLXDGCfh8vn+sL6ZWIjUQ2OxtWj WSgx+B1KOO0JGN5SddCXUVbL0p3qC4tJDJmwRSRc6v6GXUjtvKNlWtjM4/PACNT2ejOc Sw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3np0qpwedw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 23:26:20 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 31DNQJkm015177 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 23:26:19 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.36; Mon, 13 Feb 2023 15:26:19 -0800 From: Elliot Berman To: Jassi Brar CC: Elliot Berman , Sudeep Holla , , , Subject: [PATCH 2/3] mailbox: omap: Use mbox_bind_client Date: Mon, 13 Feb 2023 15:25:36 -0800 Message-ID: <20230213232537.2040976-3-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213232537.2040976-1-quic_eberman@quicinc.com> References: <20230213232537.2040976-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: SyqOvCMWteYq2Bhw8Xj0Mc3a_rkPR69R X-Proofpoint-ORIG-GUID: SyqOvCMWteYq2Bhw8Xj0Mc3a_rkPR69R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-13_12,2023-02-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=710 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302130205 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 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757761346475357244?= X-GMAIL-MSGID: =?utf-8?q?1757761346475357244?= 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 Mon Feb 13 23:25:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 56595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2639812wrn; Mon, 13 Feb 2023 15:35:46 -0800 (PST) X-Google-Smtp-Source: AK7set8j02wlfhkklsa+PXk/r/V5pgFuPdXKn9xjNRu1PiQrjAmymtzAGNx1VxJwT6miihSuJB+u X-Received: by 2002:a17:902:c946:b0:19a:b5cd:6e73 with SMTP id i6-20020a170902c94600b0019ab5cd6e73mr769136pla.3.1676331346442; Mon, 13 Feb 2023 15:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676331346; cv=none; d=google.com; s=arc-20160816; b=qI8gQxH/fTDzDHpuRwwHq1HCwkxmcRIaGJ6nr7E24aYSX4jzDWZbNTv3J8s+NLjfcI qE7l7fnkIetFhqGZixlX6IAUpFli567y/wmcM9mmaaidzAKNTTBrO6zZ72dv//LpTUsm CJp1CizxiLdcH/8ZzSCP7yPlGxCstfWeUi6ulZIfrzK9Bh8sVhzLq/yQfDZTc6dRhNAV YPBTSEEneZep3j/FElJ0K850TnE9rNo4oAkvwsi8wrguLAA+NHljlEZPeaGwJVijoVcW R69KkFsPOr7GYrmEK+a5AAAq5pF1CbM9LckddUujdL2Xzjuht/fVhXjFgfi8BmSMvmsQ 3sbQ== 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=7yEmPDxwX+j68RdLPeUfDl+nbsuqsW6P3jODpDSi6T0=; b=0PEe4zD4zl2IXuqtRyyi0h8xvSlnmH4M6n7sviWUyJlu01iShcNG3gAtELE5pLt08H W+aXGPwbkrmQktPW+9JyQP7Ju119BcDgzejevMAm+pJ29SXV9ZCW+jlvlOkQP7XbVHft KCdqItoRzPLF0Y+9rbotEkba3dopEmsBg5Vm5G7IZ3kvmDrG6Z9d815RZ7nmMcFlY6UC tp2lKix7Xgc+ADoFFrgceJNGhlHnEwZy3TbUFhWKPcJESrUSsBxRIzN8uzCX0iEOJf1y L6ndKfVrdvPQdI5O4dmCH+kDHoErZV9SmAevSPU82HJ/SOvRznX9Spj/x7jxYkdtLU3J LZgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aLv42hbh; 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 b17-20020a170903229100b0019a93fa292fsi6808453plh.67.2023.02.13.15.35.32; Mon, 13 Feb 2023 15:35:46 -0800 (PST) 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=aLv42hbh; 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 S230488AbjBMX0a (ORCPT + 99 others); Mon, 13 Feb 2023 18:26:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjBMX00 (ORCPT ); Mon, 13 Feb 2023 18:26:26 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91A5212D; Mon, 13 Feb 2023 15:26:25 -0800 (PST) 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 31DMv5LH022198; Mon, 13 Feb 2023 23:26: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-transfer-encoding : content-type; s=qcppdkim1; bh=7yEmPDxwX+j68RdLPeUfDl+nbsuqsW6P3jODpDSi6T0=; b=aLv42hbhCrtbuGTKHpe8Id+PtqkKqBs/twfRAzwIrjjD51KMi3aMV2QnAq2OyPpRCFiP l+h6A1ijsw3yklTzvxvVPPqwd9gfzGgxRKhtvRraDtYzS2LzV+dvO4DY5sL+4fhOaj2e 10jud8P54DA73tB8p+1/E40TTzMj4/IhVHDa0TpLNHE93u0Hq+YVo4/qh+uG8Q5IGKnG QwfBEFLmYTEcZDNS3Zy7m3sdXIfQiJG1w4q+0zuiQueFPaoXdNvYzq4uTT/q7qopIg+c zoApddZD01KjFpx5ndpfAkHcUGklTR5o9SMGYdx34msxD8Yj956mkPt1VxSW6lLOq+CP Og== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3np389w8rb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 23:26:21 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 31DNQK0B030322 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 23:26:20 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.36; Mon, 13 Feb 2023 15:26:20 -0800 From: Elliot Berman To: Jassi Brar , Sudeep Holla CC: Elliot Berman , , , Subject: [PATCH 3/3] mailbox: pcc: Use mbox_bind_client Date: Mon, 13 Feb 2023 15:25:37 -0800 Message-ID: <20230213232537.2040976-4-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213232537.2040976-1-quic_eberman@quicinc.com> References: <20230213232537.2040976-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: FryChU_jp-N1t5XihmY6y49n05w6IhkI X-Proofpoint-GUID: FryChU_jp-N1t5XihmY6y49n05w6IhkI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-13_12,2023-02-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=854 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302130205 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 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757760817782586167?= X-GMAIL-MSGID: =?utf-8?q?1757760817782586167?= 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. 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, }; /**