Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1681622rwo; Wed, 2 Aug 2023 19:47:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlFX+VYcqZt4Fka7SydS0vElHVaQH+23817vag59qb7xAMYQabeox8yshnTmIVOAPG37JXC0 X-Received: by 2002:a17:906:cc55:b0:975:63f4:4b with SMTP id mm21-20020a170906cc5500b0097563f4004bmr6825445ejb.36.1691030874900; Wed, 02 Aug 2023 19:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691030874; cv=none; d=google.com; s=arc-20160816; b=pkrBme5Li4XWipnNaqcGSVesr++vIteKT5OGUJTbyNdCseNli5UmDO1HMKaxgl+l4w fB/l9ANEtQ6p03cwnWIdyaYDT6c+ctzZLTXdF2BLM7hNx/PEascGR+/eGpicm9ZOfhYl Gx4Uz/M0VGNvK2upxQWSBCuLzxOlJOrcPAaqSSdzXZgiFsYZD8PTF745wnx58poordN3 ohiYluezatoTMFDb8lZEXqK4WDHvsdLNzM9Tc3UmJ9+MnzVhDolhcIQgOsegztRYwhlI VjNZ4w6V39pQ7xJkHiZ1oEth1enKyXm0sH64kAiu2aEvbzgduGZcc84m1xsLUmpCuMZ3 xQIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VmDQBngkUfZT7Xd42gcofemITc/48pOXICJi21nKB7Y=; fh=ZOLRAOmQlABSnw6QT6zZ/BTgzzVdcmO80n3JU352NnE=; b=sRwDKp+NMWmhrjBXdj6b2VkoQ5oVNcJkqZHT8nr2ZiJEXcB/XpZVcA3aaXy1/hxCHg 8fJbe+fh3yICQsKa5UXyhSUBXXR6o1ohXC1OiZ5qOORHKjr98E0f6RB8TDbHedVJZAjb JtEvGoDpVOwSyMMSYt46NWon0M+M7PZrG4BIcT0q9/khK76tKm1tSpDQA+W0REjrvnHj xkamBjGBhM633Y4UtKq6ckjCKl5qlFKIZZ65W4YA/yZgEhbxGWph6dRjVtff9kwzYogK 2XHirbGybf6mZWx9rBnThukFqMdS+NQcm+jvjAsgHgHjFsENhZxm7TQhC8ACs4WdHzdM BcmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OJGaD8RZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ce18-20020a170906b25200b00992d730e99dsi8039795ejb.494.2023.08.02.19.47.30; Wed, 02 Aug 2023 19:47:54 -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=@gmail.com header.s=20221208 header.b=OJGaD8RZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbjHCAdS (ORCPT + 99 others); Wed, 2 Aug 2023 20:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbjHCAdR (ORCPT ); Wed, 2 Aug 2023 20:33:17 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AF1C1982; Wed, 2 Aug 2023 17:33:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-99bf3f59905so48875366b.3; Wed, 02 Aug 2023 17:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691022794; x=1691627594; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VmDQBngkUfZT7Xd42gcofemITc/48pOXICJi21nKB7Y=; b=OJGaD8RZzpICKo/egDvoKyYF3ObJBah3LwvF3MMdEUkKFTsRp79+vLiECUE8EC5ElA h0wX6cqi32v02EAf16jbWp54W9C/pCGVEwmKhcbiAE9iiy9VAjX2LxDket4+qA3arrvx hkgbFDZnO3/GejE+3BhPVZrnVs6+a1q/ynRFZkDm8L2uHRVvMrd15j9+Y2k+Tf6d975i fKaKrr0pvpDEMtSrMDpK8aEzMEb8IAwzVZoKpOrNuYwquwaZ43UfbBw0DJsprAKb0rbF sSSsY2Q9u25xsvFt/Su9yjAaHzYI+TnIXYxJj6TF8GYkfklHjke6rC0NHp0FetzC5O2Z ecTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691022794; x=1691627594; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VmDQBngkUfZT7Xd42gcofemITc/48pOXICJi21nKB7Y=; b=jZ7u9m48ep7jdiGeaioY9vYOFZyovpMGLgTTKqZt8Sq7dOZYloSoyI8T/KIy4BwSai Z9yxpHgJ6JfQ15Hf+vDR2wlkT69DCUb3XT7TPESxeGqr2Sj/TaYdfoKvUWW89HbYrWRL v8e9LoMNfDJvaxVDXkxp2nver+BCyUznMgmZLKYm0Oz9UjDQNP4WQlgCLl0J1463K8qx 7FqQrZvW0zJHuP/A3cY3uvEfeOy1zc+jpy0lamAJBBQK5BEjhZHCd1Y8Y8Vy+5Ns0q3y VAX4jK33vfg1bphDSDDMEfznSD7RYGKH/4Pp31EDlr97ZUlpACx4ceDtkfiW+ne0IIRF IEFQ== X-Gm-Message-State: ABy/qLY+Ok3tBNAyABuuw2ZqyiPJyV0tQksNPWxM2Emdpz5LEw6hWQR8 4vRN1ProITmEgfPZtdeQdam5Q6ByiZMsat0kNFM= X-Received: by 2002:a17:906:18:b0:997:e79c:99dc with SMTP id 24-20020a170906001800b00997e79c99dcmr6226030eja.74.1691022793795; Wed, 02 Aug 2023 17:33:13 -0700 (PDT) MIME-Version: 1.0 References: <20230613172054.3959700-1-quic_eberman@quicinc.com> <20230613172054.3959700-7-quic_eberman@quicinc.com> In-Reply-To: <20230613172054.3959700-7-quic_eberman@quicinc.com> From: Jassi Brar Date: Wed, 2 Aug 2023 19:33:02 -0500 Message-ID: Subject: Re: [PATCH v14 06/25] mailbox: Add Gunyah message queue mailbox To: Elliot Berman Cc: Alex Elder , Srinivas Kandagatla , Prakruthi Deepak Heragu , Jonathan Corbet , Murali Nalajala , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Dmitry Baryshkov , Bjorn Andersson , Konrad Dybcio , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bagas Sanjaya , Will Deacon , Andy Gross , Catalin Marinas , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, Jun 13, 2023 at 12:21=E2=80=AFPM Elliot Berman wrote: ...... > diff --git a/drivers/mailbox/gunyah-msgq.c b/drivers/mailbox/gunyah-msgq.= c > new file mode 100644 > index 0000000000000..7f777339278eb > --- /dev/null > +++ b/drivers/mailbox/gunyah-msgq.c > @@ -0,0 +1,219 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights r= eserved. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + I believe some includes could be removed without issue. > > +#define mbox_chan_to_msgq(chan) (container_of(chan->mbox, struct gh_msgq= , mbox)) > + container_of need not be in brackets. > +static irqreturn_t gh_msgq_rx_irq_handler(int irq, void *data) > +{ > + struct gh_msgq *msgq =3D data; > + struct gh_msgq_rx_data rx_data; > + enum gh_error gh_error; > + bool ready =3D true; > + Please limit the scope of rx_data and gh_error by moving them inside the while() body. > + while (ready) { > + gh_error =3D gh_hypercall_msgq_recv(msgq->rx_ghrsc->capid= , > + &rx_data.data, sizeof(rx_data.data), > + &rx_data.length, &ready); > + if (gh_error !=3D GH_ERROR_OK) { > + if (gh_error !=3D GH_ERROR_MSGQUEUE_EMPTY) > + dev_warn(msgq->mbox.dev, "Failed to recei= ve data: %d\n", gh_error); > + break; > + } > + if (likely(gh_msgq_chan(msgq)->cl)) > + mbox_chan_received_data(gh_msgq_chan(msgq), &rx_d= ata); > + } > + > + return IRQ_HANDLED; > +} > + > +static int gh_msgq_send_data(struct mbox_chan *chan, void *data) > +{ > + struct gh_msgq *msgq =3D mbox_chan_to_msgq(chan); > + struct gh_msgq_tx_data *msgq_data =3D data; > + u64 tx_flags =3D 0; > + enum gh_error gh_error; > + bool ready; > + > + if (!msgq->tx_ghrsc) > + return -EOPNOTSUPP; > + If we hit this error, the fix will still be in the upper layer. So please drop the check and, if needed, add one in the client driver. > + if (msgq_data->push) > + tx_flags |=3D GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH; > + > + gh_error =3D gh_hypercall_msgq_send(msgq->tx_ghrsc->capid, msgq_d= ata->length, msgq_data->data, > + tx_flags, &ready); > + > + /** > + * unlikely because Linux tracks state of msgq and should not try= to > + * send message when msgq is full. > + */ > + if (unlikely(gh_error =3D=3D GH_ERROR_MSGQUEUE_FULL)) > + return -EAGAIN; > + If it is not expected to hit, please remove the check. If there can be a 'race' like situation, still remove this and try to find an appropriate place to avoid the race. > + /** > + * Propagate all other errors to client. If we return error to ma= ilbox > + * framework, then no other messages can be sent and nobody will = know > + * to retry this message. > + */ > + msgq->last_ret =3D gh_error_remap(gh_error); > + > + /** > + * This message was successfully sent, but message queue isn't re= ady to > + * accept more messages because it's now full. Mailbox framework > + * requires that we only report that message was transmitted when > + * we're ready to transmit another message. We'll get that in the= form > + * of tx IRQ once the other side starts to drain the msgq. > + */ > + if (gh_error =3D=3D GH_ERROR_OK) { > + if (!ready) > + return 0; > + } else { > + dev_err(msgq->mbox.dev, "Failed to send data: %d (%d)\n",= gh_error, msgq->last_ret); > + } > + > + /** > + * We can send more messages. > ... until we can not (when the platform specific queue is full)= . > Mailbox framework requires that tx done > + * happens asynchronously to sending the message. > hence the mailbox api needs to track each transfer's stage. > Gunyah message queues > + * tell us right away on the hypercall return whether we can send= more > + * messages. To work around this, defer the txdone to a tasklet. > + */ > If not here, you would still have to put the 'defer' somewhere in the upper layer. So it is not exactly a "workaround". > + tasklet_schedule(&msgq->txdone_tasklet); > + > + return 0; > +} > + > diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h > index 01a6f202d037e..982e27d10d57f 100644 > --- a/include/linux/gunyah.h > +++ b/include/linux/gunyah.h > @@ -8,11 +8,68 @@ > > #include > #include > +#include > #include > +#include > +#include > #include > controller.h and client.h aren't supposed to be in the same header. The Client and the Controller driver could include them respectively before this header. Cheers.