From patchwork Mon Jan 9 22:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD1F8C5479D for ; Mon, 9 Jan 2023 22:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237372AbjAIWk1 (ORCPT ); Mon, 9 Jan 2023 17:40:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237870AbjAIWkM (ORCPT ); Mon, 9 Jan 2023 17:40:12 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E4B13DD2; Mon, 9 Jan 2023 14:40:11 -0800 (PST) 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 309KFLl0024402; Mon, 9 Jan 2023 22:40: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=Y9T5mXuEeB6ZHBIcoZEDpgHVBZE6CIMC1qry4NKe/sE=; b=klCLtulNiMbtEZoGh3oTk1DIzuDqahHdcllN+RxnK/kYqnU88JOkPdrOEnZtC64wyOLI +iJ7tQwhdGVc3WlDmTG/s+j8ZdkrQU5LyZNvbaHpPIBCVCqlfEPmnZIQrk9yuiu4b9Zi 7L7EEyCZhiKPlYg8YJ1pHbo2cePFBuZyMP4FrGpIAp/O2EdUHoUbd0s+D8Em4vKsBQj+ aZvzSa06vna0DS42S6TccU3f9uktqf3+gL+8k9te2A+qyojG1Q4KGZqieQei7HWSpG+l iWAPd7r2F3IXL+yTbYoaupybilk9obG5VnOsrOfGJSxOcNXPav2YXYw45eC5tQgA/yqv eQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3n0ssh87rq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:08 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309Me7Ql027265 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:07 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:07 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 1/6] rpmsg: glink: Extract tx kick operation Date: Mon, 9 Jan 2023 14:39:56 -0800 Message-ID: <20230109224001.1706516-2-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: IPNUsT6Ll7ntQkrbwh-_c6G9OLHea3P5 X-Proofpoint-ORIG-GUID: IPNUsT6Ll7ntQkrbwh-_c6G9OLHea3P5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Refactor out the tx kick operations to its own function, in preparation for pushing the details to the individual transports. Signed-off-by: Bjorn Andersson Reviewed-by: Chris Lew --- drivers/rpmsg/qcom_glink_native.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 115c0a1eddb1..5fd8b70271b7 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -303,6 +303,12 @@ static void qcom_glink_tx_write(struct qcom_glink *glink, glink->tx_pipe->write(glink->tx_pipe, hdr, hlen, data, dlen); } +static void qcom_glink_tx_kick(struct qcom_glink *glink) +{ + mbox_send_message(glink->mbox_chan, NULL); + mbox_client_txdone(glink->mbox_chan, 0); +} + static void qcom_glink_send_read_notify(struct qcom_glink *glink) { struct glink_msg msg; @@ -313,8 +319,7 @@ static void qcom_glink_send_read_notify(struct qcom_glink *glink) qcom_glink_tx_write(glink, &msg, sizeof(msg), NULL, 0); - mbox_send_message(glink->mbox_chan, NULL); - mbox_client_txdone(glink->mbox_chan, 0); + qcom_glink_tx_kick(glink); } static int qcom_glink_tx(struct qcom_glink *glink, @@ -355,9 +360,7 @@ static int qcom_glink_tx(struct qcom_glink *glink, } qcom_glink_tx_write(glink, hdr, hlen, data, dlen); - - mbox_send_message(glink->mbox_chan, NULL); - mbox_client_txdone(glink->mbox_chan, 0); + qcom_glink_tx_kick(glink); out: spin_unlock_irqrestore(&glink->tx_lock, flags); @@ -1046,9 +1049,7 @@ static irqreturn_t qcom_glink_native_intr(int irq, void *data) break; case RPM_CMD_READ_NOTIF: qcom_glink_rx_advance(glink, ALIGN(sizeof(msg), 8)); - - mbox_send_message(glink->mbox_chan, NULL); - mbox_client_txdone(glink->mbox_chan, 0); + qcom_glink_tx_kick(glink); break; case RPM_CMD_INTENT: qcom_glink_handle_intent(glink, param1, param2, avail); From patchwork Mon Jan 9 22:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B44F9C678D9 for ; Mon, 9 Jan 2023 22:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237913AbjAIWkc (ORCPT ); Mon, 9 Jan 2023 17:40:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237616AbjAIWkN (ORCPT ); Mon, 9 Jan 2023 17:40:13 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E05A2F58C; Mon, 9 Jan 2023 14:40:12 -0800 (PST) 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 309LepaQ020592; Mon, 9 Jan 2023 22:40:09 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=4e8Mz6h5RL7FchyNrlIzMuzEyjtxoOYy8k36C7ow1bQ=; b=SLO8blYcV7A/7Pyi2k5MqTRRT6FXPnRBds0FEHT4SMSKrO8VU+4lBS26OPWnar8Uz+67 maaA/gKcX98WeAwDVIdauD1evkv9V8kofz18Firsbtw/EgOf1LyWJL1QVtckviVPzTmr FJnlE9FyuBXn3Sgg4qSnDiwGKGz6/BtYyxrd/kjlOa0YBWhvx6vVBLzURh9Cd/5PaUVe 75EeD3rczl8FFwcV0+JjaR1DILoGTwVfCspVXDnwtKIRQBgmEPYUCmNSfHxqL2vejF90 E+EOEVuEWo7itvcvxHg3Q3nASyF9Rvdi+h1PvKsUB9Hmc+Y3FWDyk1f/11iWxWv8KA5y Zg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3my14fv7wq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:08 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309Me7AF026530 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:07 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:07 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 2/6] rpmsg: glink: smem: Wrap driver context Date: Mon, 9 Jan 2023 14:39:57 -0800 Message-ID: <20230109224001.1706516-3-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: S51Z6nBS4a13u6ylmerCopeu_qajcnSu X-Proofpoint-ORIG-GUID: S51Z6nBS4a13u6ylmerCopeu_qajcnSu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 spamscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The Glink SMEM driver allocates a struct device and hangs two devres-allocated pipe objects thereon. To facilitate the move of interrupt and mailbox handling to the driver, introduce a wrapper object capturing the device, glink reference and remote processor id. The type of the remoteproc reference is updated, as these are specifically targetting the SMEM implementation. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/qcom_common.h | 3 +- drivers/rpmsg/qcom_glink_smem.c | 76 ++++++++++++++++++++------------ include/linux/rpmsg/qcom_glink.h | 12 ++--- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/drivers/remoteproc/qcom_common.h b/drivers/remoteproc/qcom_common.h index c35adf730be0..2747c7d9ba44 100644 --- a/drivers/remoteproc/qcom_common.h +++ b/drivers/remoteproc/qcom_common.h @@ -6,6 +6,7 @@ #include "remoteproc_internal.h" #include +struct qcom_glink_smem; struct qcom_sysmon; struct qcom_rproc_glink { @@ -15,7 +16,7 @@ struct qcom_rproc_glink { struct device *dev; struct device_node *node; - struct qcom_glink *edge; + struct qcom_glink_smem *edge; }; struct qcom_rproc_subdev { diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c index 579bc4443f6d..703e63fa5a86 100644 --- a/drivers/rpmsg/qcom_glink_smem.c +++ b/drivers/rpmsg/qcom_glink_smem.c @@ -33,6 +33,14 @@ #define SMEM_GLINK_NATIVE_XPRT_FIFO_0 479 #define SMEM_GLINK_NATIVE_XPRT_FIFO_1 480 +struct qcom_glink_smem { + struct device dev; + + struct qcom_glink *glink; + + u32 remote_pid; +}; + struct glink_smem_pipe { struct qcom_glink_pipe native; @@ -41,7 +49,7 @@ struct glink_smem_pipe { void *fifo; - int remote_pid; + struct qcom_glink_smem *smem; }; #define to_smem_pipe(p) container_of(p, struct glink_smem_pipe, native) @@ -49,13 +57,14 @@ struct glink_smem_pipe { static size_t glink_smem_rx_avail(struct qcom_glink_pipe *np) { struct glink_smem_pipe *pipe = to_smem_pipe(np); + struct qcom_glink_smem *smem = pipe->smem; size_t len; void *fifo; u32 head; u32 tail; if (!pipe->fifo) { - fifo = qcom_smem_get(pipe->remote_pid, + fifo = qcom_smem_get(smem->remote_pid, SMEM_GLINK_NATIVE_XPRT_FIFO_1, &len); if (IS_ERR(fifo)) { pr_err("failed to acquire RX fifo handle: %ld\n", @@ -179,45 +188,49 @@ static void glink_smem_tx_write(struct qcom_glink_pipe *glink_pipe, static void qcom_glink_smem_release(struct device *dev) { - kfree(dev); + struct qcom_glink_smem *smem = container_of(dev, struct qcom_glink_smem, dev); + + kfree(smem); } -struct qcom_glink *qcom_glink_smem_register(struct device *parent, - struct device_node *node) +struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, + struct device_node *node) { struct glink_smem_pipe *rx_pipe; struct glink_smem_pipe *tx_pipe; struct qcom_glink *glink; - struct device *dev; + struct qcom_glink_smem *smem; u32 remote_pid; __le32 *descs; size_t size; int ret; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) + smem = kzalloc(sizeof(*smem), GFP_KERNEL); + if (!smem) return ERR_PTR(-ENOMEM); - dev->parent = parent; - dev->of_node = node; - dev->release = qcom_glink_smem_release; - dev_set_name(dev, "%s:%pOFn", dev_name(parent->parent), node); - ret = device_register(dev); + smem->dev.parent = parent; + smem->dev.of_node = node; + smem->dev.release = qcom_glink_smem_release; + dev_set_name(&smem->dev, "%s:%pOFn", dev_name(parent->parent), node); + ret = device_register(&smem->dev); if (ret) { pr_err("failed to register glink edge\n"); - put_device(dev); + put_device(&smem->dev); return ERR_PTR(ret); } - ret = of_property_read_u32(dev->of_node, "qcom,remote-pid", + ret = of_property_read_u32(smem->dev.of_node, "qcom,remote-pid", &remote_pid); if (ret) { - dev_err(dev, "failed to parse qcom,remote-pid\n"); + dev_err(&smem->dev, "failed to parse qcom,remote-pid\n"); goto err_put_dev; } - rx_pipe = devm_kzalloc(dev, sizeof(*rx_pipe), GFP_KERNEL); - tx_pipe = devm_kzalloc(dev, sizeof(*tx_pipe), GFP_KERNEL); + smem->remote_pid = remote_pid; + + rx_pipe = devm_kzalloc(&smem->dev, sizeof(*rx_pipe), GFP_KERNEL); + tx_pipe = devm_kzalloc(&smem->dev, sizeof(*tx_pipe), GFP_KERNEL); if (!rx_pipe || !tx_pipe) { ret = -ENOMEM; goto err_put_dev; @@ -226,20 +239,20 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent, ret = qcom_smem_alloc(remote_pid, SMEM_GLINK_NATIVE_XPRT_DESCRIPTOR, 32); if (ret && ret != -EEXIST) { - dev_err(dev, "failed to allocate glink descriptors\n"); + dev_err(&smem->dev, "failed to allocate glink descriptors\n"); goto err_put_dev; } descs = qcom_smem_get(remote_pid, SMEM_GLINK_NATIVE_XPRT_DESCRIPTOR, &size); if (IS_ERR(descs)) { - dev_err(dev, "failed to acquire xprt descriptor\n"); + dev_err(&smem->dev, "failed to acquire xprt descriptor\n"); ret = PTR_ERR(descs); goto err_put_dev; } if (size != 32) { - dev_err(dev, "glink descriptor of invalid size\n"); + dev_err(&smem->dev, "glink descriptor of invalid size\n"); ret = -EINVAL; goto err_put_dev; } @@ -252,31 +265,31 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent, ret = qcom_smem_alloc(remote_pid, SMEM_GLINK_NATIVE_XPRT_FIFO_0, SZ_16K); if (ret && ret != -EEXIST) { - dev_err(dev, "failed to allocate TX fifo\n"); + dev_err(&smem->dev, "failed to allocate TX fifo\n"); goto err_put_dev; } tx_pipe->fifo = qcom_smem_get(remote_pid, SMEM_GLINK_NATIVE_XPRT_FIFO_0, &tx_pipe->native.length); if (IS_ERR(tx_pipe->fifo)) { - dev_err(dev, "failed to acquire TX fifo\n"); + dev_err(&smem->dev, "failed to acquire TX fifo\n"); ret = PTR_ERR(tx_pipe->fifo); goto err_put_dev; } + rx_pipe->smem = smem; rx_pipe->native.avail = glink_smem_rx_avail; rx_pipe->native.peak = glink_smem_rx_peak; rx_pipe->native.advance = glink_smem_rx_advance; - rx_pipe->remote_pid = remote_pid; + tx_pipe->smem = smem; tx_pipe->native.avail = glink_smem_tx_avail; tx_pipe->native.write = glink_smem_tx_write; - tx_pipe->remote_pid = remote_pid; *rx_pipe->tail = 0; *tx_pipe->head = 0; - glink = qcom_glink_native_probe(dev, + glink = qcom_glink_native_probe(&smem->dev, GLINK_FEATURE_INTENT_REUSE, &rx_pipe->native, &tx_pipe->native, false); @@ -285,17 +298,22 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent, goto err_put_dev; } - return glink; + smem->glink = glink; + + return smem; + err_put_dev: - device_unregister(dev); + device_unregister(&smem->dev); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(qcom_glink_smem_register); -void qcom_glink_smem_unregister(struct qcom_glink *glink) +void qcom_glink_smem_unregister(struct qcom_glink_smem *smem) { + struct qcom_glink *glink = smem->glink; + qcom_glink_native_remove(glink); qcom_glink_native_unregister(glink); } diff --git a/include/linux/rpmsg/qcom_glink.h b/include/linux/rpmsg/qcom_glink.h index 22fc3a69b683..bfbd48f435fa 100644 --- a/include/linux/rpmsg/qcom_glink.h +++ b/include/linux/rpmsg/qcom_glink.h @@ -5,7 +5,7 @@ #include -struct qcom_glink; +struct qcom_glink_smem; #if IS_ENABLED(CONFIG_RPMSG_QCOM_GLINK) void qcom_glink_ssr_notify(const char *ssr_name); @@ -15,20 +15,20 @@ static inline void qcom_glink_ssr_notify(const char *ssr_name) {} #if IS_ENABLED(CONFIG_RPMSG_QCOM_GLINK_SMEM) -struct qcom_glink *qcom_glink_smem_register(struct device *parent, - struct device_node *node); -void qcom_glink_smem_unregister(struct qcom_glink *glink); +struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, + struct device_node *node); +void qcom_glink_smem_unregister(struct qcom_glink_smem *glink); #else -static inline struct qcom_glink * +static inline struct qcom_glink_smem * qcom_glink_smem_register(struct device *parent, struct device_node *node) { return NULL; } -static inline void qcom_glink_smem_unregister(struct qcom_glink *glink) {} +static inline void qcom_glink_smem_unregister(struct qcom_glink_smem *glink) {} #endif #endif From patchwork Mon Jan 9 22:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8515CC678D5 for ; Mon, 9 Jan 2023 22:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237888AbjAIWka (ORCPT ); Mon, 9 Jan 2023 17:40:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237926AbjAIWkP (ORCPT ); Mon, 9 Jan 2023 17:40:15 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2780613FA2; Mon, 9 Jan 2023 14:40:14 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 309MdkFf006180; Mon, 9 Jan 2023 22:40:09 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=Fo+XDG1NWFHnUwew+NJYKC5jDr9wAAH4NTYJKeieCi0=; b=W7TtcXJrQCe9JzF1PtgbKg3l1289i15yKC8c18ZLRQIYNZ1E3ygVtxCwK8aGbPq/ec7o SiXUbjCZTcaAb/g20ONw0u0JFC3vGnkpAfHGCcT4ovtW3qPK1+vXM9t8P28+wpTNbyMz riAG5YI6wfNYzKB7R+i/QgnjMnFE8BbUGg/z+848y501ZJm+4d5ATvOkm+iJstWv6P2q CQII8LPsmplQf1S7tvN6vdJzkDOtboqQvSvEA5ZNdUTtH5e3OwxAKnRGyCmOxMGTesnu hsIbsb8vZRDXN8FFVrnMIg4ntUs/TN1DRdCcWSdgF03E4G4ghK5il7Fh9e3UykchL1iN JQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3mxx3w4ecx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:09 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309Me8sx026536 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:08 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:07 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 3/6] rpmsg: glink: rpm: Wrap driver context Date: Mon, 9 Jan 2023 14:39:58 -0800 Message-ID: <20230109224001.1706516-4-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: a-8e6U_0kPQ2TBsYH21HLqpya64i3SJd X-Proofpoint-GUID: a-8e6U_0kPQ2TBsYH21HLqpya64i3SJd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org As with the SMEM driver update, wrap the RPM context in a struct to facilitate the upcoming changes of moving IRQ and mailbox registration to the driver. Signed-off-by: Bjorn Andersson Reviewed-by: Chris Lew --- drivers/rpmsg/qcom_glink_rpm.c | 44 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_rpm.c b/drivers/rpmsg/qcom_glink_rpm.c index f64f45d1a735..6443843df6ca 100644 --- a/drivers/rpmsg/qcom_glink_rpm.c +++ b/drivers/rpmsg/qcom_glink_rpm.c @@ -53,6 +53,13 @@ struct glink_rpm_pipe { void __iomem *fifo; }; +struct glink_rpm { + struct qcom_glink *glink; + + struct glink_rpm_pipe rx_pipe; + struct glink_rpm_pipe tx_pipe; +}; + static size_t glink_rpm_rx_avail(struct qcom_glink_pipe *glink_pipe) { struct glink_rpm_pipe *pipe = to_rpm_pipe(glink_pipe); @@ -257,8 +264,7 @@ static int glink_rpm_parse_toc(struct device *dev, static int glink_rpm_probe(struct platform_device *pdev) { struct qcom_glink *glink; - struct glink_rpm_pipe *rx_pipe; - struct glink_rpm_pipe *tx_pipe; + struct glink_rpm *rpm; struct device_node *np; void __iomem *msg_ram; size_t msg_ram_size; @@ -266,9 +272,8 @@ static int glink_rpm_probe(struct platform_device *pdev) struct resource r; int ret; - rx_pipe = devm_kzalloc(&pdev->dev, sizeof(*rx_pipe), GFP_KERNEL); - tx_pipe = devm_kzalloc(&pdev->dev, sizeof(*tx_pipe), GFP_KERNEL); - if (!rx_pipe || !tx_pipe) + rpm = devm_kzalloc(&pdev->dev, sizeof(*rpm), GFP_KERNEL); + if (!rpm) return -ENOMEM; np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", 0); @@ -283,36 +288,39 @@ static int glink_rpm_probe(struct platform_device *pdev) return -ENOMEM; ret = glink_rpm_parse_toc(dev, msg_ram, msg_ram_size, - rx_pipe, tx_pipe); + &rpm->rx_pipe, &rpm->tx_pipe); if (ret) return ret; /* Pipe specific accessors */ - rx_pipe->native.avail = glink_rpm_rx_avail; - rx_pipe->native.peak = glink_rpm_rx_peak; - rx_pipe->native.advance = glink_rpm_rx_advance; - tx_pipe->native.avail = glink_rpm_tx_avail; - tx_pipe->native.write = glink_rpm_tx_write; + rpm->rx_pipe.native.avail = glink_rpm_rx_avail; + rpm->rx_pipe.native.peak = glink_rpm_rx_peak; + rpm->rx_pipe.native.advance = glink_rpm_rx_advance; + rpm->tx_pipe.native.avail = glink_rpm_tx_avail; + rpm->tx_pipe.native.write = glink_rpm_tx_write; - writel(0, tx_pipe->head); - writel(0, rx_pipe->tail); + writel(0, rpm->tx_pipe.head); + writel(0, rpm->rx_pipe.tail); - glink = qcom_glink_native_probe(&pdev->dev, + glink = qcom_glink_native_probe(dev, 0, - &rx_pipe->native, - &tx_pipe->native, + &rpm->rx_pipe.native, + &rpm->tx_pipe.native, true); if (IS_ERR(glink)) return PTR_ERR(glink); - platform_set_drvdata(pdev, glink); + rpm->glink = glink; + + platform_set_drvdata(pdev, rpm); return 0; } static int glink_rpm_remove(struct platform_device *pdev) { - struct qcom_glink *glink = platform_get_drvdata(pdev); + struct glink_rpm *rpm = platform_get_drvdata(pdev); + struct qcom_glink *glink = rpm->glink; qcom_glink_native_remove(glink); From patchwork Mon Jan 9 22:39:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A38E9C678D7 for ; Mon, 9 Jan 2023 22:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237903AbjAIWkc (ORCPT ); Mon, 9 Jan 2023 17:40:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237882AbjAIWkO (ORCPT ); Mon, 9 Jan 2023 17:40:14 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F4F13CD5; Mon, 9 Jan 2023 14:40:13 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 309MBXFM032168; Mon, 9 Jan 2023 22:40:09 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=+SMlSdL97syI43DpjKDXJvwPE6lMtuB/fs9f7CilYLo=; b=H54YKqPBGyX19nw/HRG7axAUqXSVJ3fLchR1yEQ2QCyWWB+EaorgtWhwpAhkdbVE34dr f9rtw2bOKbO/hj3owoiGI8FtD5HNKhL96oVAlavR1fGRoH/clal3xdmRya7/RD4ZIdAW kFt84uthj0sI96YZfzWMV10/Vs+1O3IH6xujHbYs4B5Ix8EhNyHh2Hzl7MzvUrzldYEZ aiMDKJxT6QPfH9iSfXiJfYXJnKXhgBaUM9YUcdnLD0MYNNuMcD8Rs/nRqHf0JvzN1O0j IzMzX4qaqacC/sS1rV3MAy3ikOU/VVSDdrPfZxOeoBRj+YW7PeaCxuR93/aAmjm2uDaG Aw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3mxx3w4ecy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:09 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309Me8eT027294 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:08 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:08 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 4/6] rpmsg: glink: Move irq and mbox handling to transports Date: Mon, 9 Jan 2023 14:39:59 -0800 Message-ID: <20230109224001.1706516-5-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Bpbf_kpH4kQlwFhSSTGy9zbjuPU6-OGf X-Proofpoint-GUID: Bpbf_kpH4kQlwFhSSTGy9zbjuPU6-OGf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Not all GLINK transports uses an interrupt and a mailbox instance. The interrupt for RPM needs to be IRQF_NOSUSPEND, while it seems reasonable for the SMEM interrupt to use irq_set_wake. The glink struct device is constructed in the SMEM and RPM drivers but torn down in the core driver. Move the interrupt and kick handling into the SMEM and RPM driver, to improve this and facilitate further improvements. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/qcom_glink_native.c | 48 ++------------------------ drivers/rpmsg/qcom_glink_native.h | 3 +- drivers/rpmsg/qcom_glink_rpm.c | 50 ++++++++++++++++++++++++++- drivers/rpmsg/qcom_glink_smem.c | 56 +++++++++++++++++++++++++++++-- 4 files changed, 108 insertions(+), 49 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 5fd8b70271b7..db5d946d5901 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -78,11 +77,8 @@ struct glink_core_rx_intent { /** * struct qcom_glink - driver context, relates to one remote subsystem * @dev: reference to the associated struct device - * @mbox_client: mailbox client - * @mbox_chan: mailbox channel * @rx_pipe: pipe object for receive FIFO * @tx_pipe: pipe object for transmit FIFO - * @irq: IRQ for signaling incoming events * @rx_work: worker for handling received control messages * @rx_lock: protects the @rx_queue * @rx_queue: queue of received control messages to be processed in @rx_work @@ -98,14 +94,9 @@ struct glink_core_rx_intent { struct qcom_glink { struct device *dev; - struct mbox_client mbox_client; - struct mbox_chan *mbox_chan; - struct qcom_glink_pipe *rx_pipe; struct qcom_glink_pipe *tx_pipe; - int irq; - struct work_struct rx_work; spinlock_t rx_lock; struct list_head rx_queue; @@ -305,8 +296,7 @@ static void qcom_glink_tx_write(struct qcom_glink *glink, static void qcom_glink_tx_kick(struct qcom_glink *glink) { - mbox_send_message(glink->mbox_chan, NULL); - mbox_client_txdone(glink->mbox_chan, 0); + glink->tx_pipe->kick(glink->tx_pipe); } static void qcom_glink_send_read_notify(struct qcom_glink *glink) @@ -1004,9 +994,8 @@ static int qcom_glink_rx_open_ack(struct qcom_glink *glink, unsigned int lcid) return 0; } -static irqreturn_t qcom_glink_native_intr(int irq, void *data) +void qcom_glink_native_intr(struct qcom_glink *glink) { - struct qcom_glink *glink = data; struct glink_msg msg; unsigned int param1; unsigned int param2; @@ -1075,9 +1064,8 @@ static irqreturn_t qcom_glink_native_intr(int irq, void *data) if (ret) break; } - - return IRQ_HANDLED; } +EXPORT_SYMBOL(qcom_glink_native_intr); /* Locally initiated rpmsg_create_ept */ static struct glink_channel *qcom_glink_create_local(struct qcom_glink *glink, @@ -1723,7 +1711,6 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev, struct qcom_glink_pipe *tx, bool intentless) { - int irq; int ret; struct qcom_glink *glink; @@ -1754,27 +1741,6 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev, if (ret) dev_err(dev, "failed to add groups\n"); - glink->mbox_client.dev = dev; - glink->mbox_client.knows_txdone = true; - glink->mbox_chan = mbox_request_channel(&glink->mbox_client, 0); - if (IS_ERR(glink->mbox_chan)) { - if (PTR_ERR(glink->mbox_chan) != -EPROBE_DEFER) - dev_err(dev, "failed to acquire IPC channel\n"); - return ERR_CAST(glink->mbox_chan); - } - - irq = of_irq_get(dev->of_node, 0); - ret = devm_request_irq(dev, irq, - qcom_glink_native_intr, - IRQF_NO_SUSPEND | IRQF_SHARED, - "glink-native", glink); - if (ret) { - dev_err(dev, "failed to request IRQ\n"); - return ERR_PTR(ret); - } - - glink->irq = irq; - ret = qcom_glink_send_version(glink); if (ret) return ERR_PTR(ret); @@ -1800,7 +1766,6 @@ void qcom_glink_native_remove(struct qcom_glink *glink) int cid; int ret; - disable_irq(glink->irq); qcom_glink_cancel_rx_work(glink); ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device); @@ -1817,15 +1782,8 @@ void qcom_glink_native_remove(struct qcom_glink *glink) idr_destroy(&glink->lcids); idr_destroy(&glink->rcids); - mbox_free_channel(glink->mbox_chan); } EXPORT_SYMBOL_GPL(qcom_glink_native_remove); -void qcom_glink_native_unregister(struct qcom_glink *glink) -{ - device_unregister(glink->dev); -} -EXPORT_SYMBOL_GPL(qcom_glink_native_unregister); - MODULE_DESCRIPTION("Qualcomm GLINK driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/rpmsg/qcom_glink_native.h b/drivers/rpmsg/qcom_glink_native.h index e9a8671616c7..0129fe1b2b6c 100644 --- a/drivers/rpmsg/qcom_glink_native.h +++ b/drivers/rpmsg/qcom_glink_native.h @@ -24,6 +24,7 @@ struct qcom_glink_pipe { void (*write)(struct qcom_glink_pipe *glink_pipe, const void *hdr, size_t hlen, const void *data, size_t dlen); + void (*kick)(struct qcom_glink_pipe *glink_pipe); }; struct device; @@ -35,6 +36,6 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev, struct qcom_glink_pipe *tx, bool intentless); void qcom_glink_native_remove(struct qcom_glink *glink); +void qcom_glink_native_intr(struct qcom_glink *glink); -void qcom_glink_native_unregister(struct qcom_glink *glink); #endif diff --git a/drivers/rpmsg/qcom_glink_rpm.c b/drivers/rpmsg/qcom_glink_rpm.c index 6443843df6ca..9136645d6251 100644 --- a/drivers/rpmsg/qcom_glink_rpm.c +++ b/drivers/rpmsg/qcom_glink_rpm.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,11 @@ struct glink_rpm_pipe { struct glink_rpm { struct qcom_glink *glink; + int irq; + + struct mbox_client mbox_client; + struct mbox_chan *mbox_chan; + struct glink_rpm_pipe rx_pipe; struct glink_rpm_pipe tx_pipe; }; @@ -186,6 +192,24 @@ static void glink_rpm_tx_write(struct qcom_glink_pipe *glink_pipe, writel(head, pipe->head); } +static void glink_rpm_tx_kick(struct qcom_glink_pipe *glink_pipe) +{ + struct glink_rpm_pipe *pipe = to_rpm_pipe(glink_pipe); + struct glink_rpm *rpm = container_of(pipe, struct glink_rpm, tx_pipe); + + mbox_send_message(rpm->mbox_chan, NULL); + mbox_client_txdone(rpm->mbox_chan, 0); +} + +static irqreturn_t qcom_glink_rpm_intr(int irq, void *data) +{ + struct glink_rpm *rpm = data; + + qcom_glink_native_intr(rpm->glink); + + return IRQ_HANDLED; +} + static int glink_rpm_parse_toc(struct device *dev, void __iomem *msg_ram, size_t msg_ram_size, @@ -292,12 +316,28 @@ static int glink_rpm_probe(struct platform_device *pdev) if (ret) return ret; + rpm->irq = of_irq_get(dev->of_node, 0); + ret = devm_request_irq(dev, rpm->irq, qcom_glink_rpm_intr, + IRQF_NO_SUSPEND | IRQF_NO_AUTOEN, + "glink-rpm", rpm); + if (ret) { + dev_err(dev, "failed to request IRQ\n"); + return ret; + } + + rpm->mbox_client.dev = dev; + rpm->mbox_client.knows_txdone = true; + rpm->mbox_chan = mbox_request_channel(&rpm->mbox_client, 0); + if (IS_ERR(rpm->mbox_chan)) + return dev_err_probe(dev, PTR_ERR(rpm->mbox_chan), "failed to acquire IPC channel\n"); + /* Pipe specific accessors */ rpm->rx_pipe.native.avail = glink_rpm_rx_avail; rpm->rx_pipe.native.peak = glink_rpm_rx_peak; rpm->rx_pipe.native.advance = glink_rpm_rx_advance; rpm->tx_pipe.native.avail = glink_rpm_tx_avail; rpm->tx_pipe.native.write = glink_rpm_tx_write; + rpm->tx_pipe.native.kick = glink_rpm_tx_kick; writel(0, rpm->tx_pipe.head); writel(0, rpm->rx_pipe.tail); @@ -307,13 +347,17 @@ static int glink_rpm_probe(struct platform_device *pdev) &rpm->rx_pipe.native, &rpm->tx_pipe.native, true); - if (IS_ERR(glink)) + if (IS_ERR(glink)) { + mbox_free_channel(rpm->mbox_chan); return PTR_ERR(glink); + } rpm->glink = glink; platform_set_drvdata(pdev, rpm); + enable_irq(rpm->irq); + return 0; } @@ -322,8 +366,12 @@ static int glink_rpm_remove(struct platform_device *pdev) struct glink_rpm *rpm = platform_get_drvdata(pdev); struct qcom_glink *glink = rpm->glink; + disable_irq(rpm->irq); + qcom_glink_native_remove(glink); + mbox_free_channel(rpm->mbox_chan); + return 0; } diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c index 703e63fa5a86..eec47ae98d67 100644 --- a/drivers/rpmsg/qcom_glink_smem.c +++ b/drivers/rpmsg/qcom_glink_smem.c @@ -7,8 +7,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -36,8 +38,12 @@ struct qcom_glink_smem { struct device dev; + int irq; struct qcom_glink *glink; + struct mbox_client mbox_client; + struct mbox_chan *mbox_chan; + u32 remote_pid; }; @@ -186,6 +192,24 @@ static void glink_smem_tx_write(struct qcom_glink_pipe *glink_pipe, *pipe->head = cpu_to_le32(head); } +static void glink_smem_tx_kick(struct qcom_glink_pipe *glink_pipe) +{ + struct glink_smem_pipe *pipe = to_smem_pipe(glink_pipe); + struct qcom_glink_smem *smem = pipe->smem; + + mbox_send_message(smem->mbox_chan, NULL); + mbox_client_txdone(smem->mbox_chan, 0); +} + +static irqreturn_t qcom_glink_smem_intr(int irq, void *data) +{ + struct qcom_glink_smem *smem = data; + + qcom_glink_native_intr(smem->glink); + + return IRQ_HANDLED; +} + static void qcom_glink_smem_release(struct device *dev) { struct qcom_glink_smem *smem = container_of(dev, struct qcom_glink_smem, dev); @@ -277,6 +301,24 @@ struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, goto err_put_dev; } + smem->irq = of_irq_get(smem->dev.of_node, 0); + ret = devm_request_irq(&smem->dev, smem->irq, qcom_glink_smem_intr, + IRQF_NO_SUSPEND | IRQF_NO_AUTOEN, + "glink-smem", smem); + if (ret) { + dev_err(&smem->dev, "failed to request IRQ\n"); + goto err_put_dev; + } + + smem->mbox_client.dev = &smem->dev; + smem->mbox_client.knows_txdone = true; + smem->mbox_chan = mbox_request_channel(&smem->mbox_client, 0); + if (IS_ERR(smem->mbox_chan)) { + ret = dev_err_probe(&smem->dev, PTR_ERR(smem->mbox_chan), + "failed to acquire IPC channel\n"); + goto err_put_dev; + } + rx_pipe->smem = smem; rx_pipe->native.avail = glink_smem_rx_avail; rx_pipe->native.peak = glink_smem_rx_peak; @@ -285,6 +327,7 @@ struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, tx_pipe->smem = smem; tx_pipe->native.avail = glink_smem_tx_avail; tx_pipe->native.write = glink_smem_tx_write; + tx_pipe->native.kick = glink_smem_tx_kick; *rx_pipe->tail = 0; *tx_pipe->head = 0; @@ -295,13 +338,17 @@ struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, false); if (IS_ERR(glink)) { ret = PTR_ERR(glink); - goto err_put_dev; + goto err_free_mbox; } smem->glink = glink; + enable_irq(smem->irq); + return smem; +err_free_mbox: + mbox_free_channel(smem->mbox_chan); err_put_dev: device_unregister(&smem->dev); @@ -314,8 +361,13 @@ void qcom_glink_smem_unregister(struct qcom_glink_smem *smem) { struct qcom_glink *glink = smem->glink; + disable_irq(smem->irq); + qcom_glink_native_remove(glink); - qcom_glink_native_unregister(glink); + + device_unregister(&smem->dev); + + mbox_free_channel(smem->mbox_chan); } EXPORT_SYMBOL_GPL(qcom_glink_smem_unregister); From patchwork Mon Jan 9 22:40:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54680C67871 for ; Mon, 9 Jan 2023 22:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237815AbjAIWk3 (ORCPT ); Mon, 9 Jan 2023 17:40:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237876AbjAIWkO (ORCPT ); Mon, 9 Jan 2023 17:40:14 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A3013DD2; Mon, 9 Jan 2023 14:40:13 -0800 (PST) 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 309LaGkU011502; Mon, 9 Jan 2023 22:40:10 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=Glrtv76v1bUv28bnY+eZovy/+aP3haJt+dyyflPqbj4=; b=lCtRi4+f1azhFm3NYPuzOdrU2NgHeyxLxNmrCkMKXR1+bFu67su1ys4jnraIzYRAKoxc TaVKCIIFgXsMchmLDC/pUDtTcJ9OLwNaZxHzEGAaMWzGX3MIjflFPrSJ3ys6q/mKkJUm fyfAEDKCgRWi2GJHuEykeaTbt4A0Vr9SXkmASEhf8OfiRvRAQGx+AfTSLnE/zXRmUC0m tUlXlbimTeHhYMWk+j/IzIbc5vm5ooswfSx3bfVuYXiX2oScT9nSEAobB+DjIajAxY/4 9sO8b7A8NwK04TMxP1hSWvuCo4ea8f/GGvqNJ0bm/zue3sgeBECWYt1YjZsOW/UwQapm tg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3my0u147fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:09 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309Me88L027303 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:08 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:08 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 5/6] rpmsg: glink: Fail qcom_glink_tx() once remove has been initiated Date: Mon, 9 Jan 2023 14:40:00 -0800 Message-ID: <20230109224001.1706516-6-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: BFabGhtaB_nTNpYI2eFPRkM3WKEDJ2Rl X-Proofpoint-ORIG-GUID: BFabGhtaB_nTNpYI2eFPRkM3WKEDJ2Rl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=808 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Upon removing the glink edge communication is at best one-way. This means that the very common scenario of glink requesting intents will not be possible to serve. Typically a successful transmission results in the client waiting for a response, with some timeout and a mechanism for aborting that timeout. Because of this, once the glink edge is defunct once removal is commenced it's better to fail transmissions fast. Signed-off-by: Bjorn Andersson Reviewed-by: Chris Lew --- drivers/rpmsg/qcom_glink_native.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index db5d946d5901..d81d0729493e 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -90,6 +90,7 @@ struct glink_core_rx_intent { * @intentless: flag to indicate that there is no intent * @tx_avail_notify: Waitqueue for pending tx tasks * @sent_read_notify: flag to check cmd sent or not + * @abort_tx: flag indicating that all tx attempts should fail */ struct qcom_glink { struct device *dev; @@ -111,6 +112,8 @@ struct qcom_glink { bool intentless; wait_queue_head_t tx_avail_notify; bool sent_read_notify; + + bool abort_tx; }; enum { @@ -326,12 +329,22 @@ static int qcom_glink_tx(struct qcom_glink *glink, spin_lock_irqsave(&glink->tx_lock, flags); + if (glink->abort_tx) { + ret = -EIO; + goto out; + } + while (qcom_glink_tx_avail(glink) < tlen) { if (!wait) { ret = -EAGAIN; goto out; } + if (glink->abort_tx) { + ret = -EIO; + goto out; + } + if (!glink->sent_read_notify) { glink->sent_read_notify = true; qcom_glink_send_read_notify(glink); @@ -1763,11 +1776,18 @@ static int qcom_glink_remove_device(struct device *dev, void *data) void qcom_glink_native_remove(struct qcom_glink *glink) { struct glink_channel *channel; + unsigned long flags; int cid; int ret; qcom_glink_cancel_rx_work(glink); + /* Fail all attempts at sending messages */ + spin_lock_irqsave(&glink->tx_lock, flags); + glink->abort_tx = true; + wake_up_all(&glink->tx_avail_notify); + spin_unlock_irqrestore(&glink->tx_lock, flags); + ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device); if (ret) dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret); From patchwork Mon Jan 9 22:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13094441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 645A5C63797 for ; Mon, 9 Jan 2023 22:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237890AbjAIWkb (ORCPT ); Mon, 9 Jan 2023 17:40:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237922AbjAIWkO (ORCPT ); Mon, 9 Jan 2023 17:40:14 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F5F13FA6; Mon, 9 Jan 2023 14:40:14 -0800 (PST) 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 309Maet2015718; Mon, 9 Jan 2023 22:40: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-transfer-encoding : content-type; s=qcppdkim1; bh=BY0U/IfBBmjexzqkP5sEll4FvdKK3LgbuOw30SuZ9hE=; b=NZ9Qk5arFonnNXYATWjh6w5EirdQuiGHRPsCDeALkQiG2iOZ8i6s7QvlBtiphZbGbgOQ 9Aex3DpPfXHArYf7ZyV8wdFfCz/2prOi/CzcOHG3sW9uMxdEXmlZoDuQ6WnbFbMCKdeo 8MN8TWJQzFwpW81HrlSJDHVpxYjlI7aKpSCuq2MLlBW9gHP/BxCNEbWiainB6n8J0n/I 3diP69QomN7KxkUFHscheswdTx9eDLotIdL3F/nw/tWAvSSE+ammzDAqmJ7zZ74rMxKS mzmmNX2YZMSKdiEO0QKlFors35GURIEBEH2vxMtyVDT21TGZJt4a+yVRLJuNJn72qseO nQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3my1wu452d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 22:40:11 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 309MeBbH003685 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 22:40:11 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 9 Jan 2023 14:40:08 -0800 From: Bjorn Andersson To: Bjorn Andersson , Mathieu Poirier , Chris Lew CC: , , Subject: [PATCH 6/6] rpmsg: glink: Cancel pending intent requests at removal Date: Mon, 9 Jan 2023 14:40:01 -0800 Message-ID: <20230109224001.1706516-7-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109224001.1706516-1-quic_bjorande@quicinc.com> References: <20230109224001.1706516-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: OMw4aFvjcilatTXB6ds_brK0IJd9sMuF X-Proofpoint-GUID: OMw4aFvjcilatTXB6ds_brK0IJd9sMuF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_14,2023-01-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=749 malwarescore=0 clxscore=1015 mlxscore=0 priorityscore=1501 impostorscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org During removal of the glink edge interrupts are disabled and no more incoming messages are being serviced. In addition to the remote endpoint being defunct that means that any outstanding requests for intents will not be serviced, and qcom_glink_request_intent() will blindly wait for up to 10 seconds. Mark the intent request as not granted and complete the intent request completion to fail the waiting client immediately. Once the current intent request is failed, any potential clients waiting for the intent request mutex will not enter the same wait, as the qcom_glink_tx() call will fail fast. Signed-off-by: Bjorn Andersson Reviewed-by: Chris Lew --- drivers/rpmsg/qcom_glink_native.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index d81d0729493e..bb14e7edeadc 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -423,6 +423,12 @@ static void qcom_glink_handle_intent_req_ack(struct qcom_glink *glink, complete(&channel->intent_req_comp); } +static void qcom_glink_intent_req_abort(struct glink_channel *channel) +{ + channel->intent_req_result = 0; + complete(&channel->intent_req_comp); +} + /** * qcom_glink_send_open_req() - send a RPM_CMD_OPEN request to the remote * @glink: Ptr to the glink edge @@ -1788,6 +1794,12 @@ void qcom_glink_native_remove(struct qcom_glink *glink) wake_up_all(&glink->tx_avail_notify); spin_unlock_irqrestore(&glink->tx_lock, flags); + /* Abort any senders waiting for intent requests */ + spin_lock_irqsave(&glink->idr_lock, flags); + idr_for_each_entry(&glink->lcids, channel, cid) + qcom_glink_intent_req_abort(channel); + spin_unlock_irqrestore(&glink->idr_lock, flags); + ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device); if (ret) dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret);