From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Stephan Gerhold <stephan@gerhold.net>
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Loic Poulain <loic.poulain@linaro.org>,
Sergey Ryazanov <ryazanov.s.a@gmail.com>,
Johannes Berg <johannes@sipsolutions.net>,
Andy Gross <agross@kernel.org>, Vinod Koul <vkoul@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Aleksander Morgado <aleksander@aleksander.es>,
netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org,
dmaengine@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
Subject: Re: [PATCH net-next v2 2/4] dmaengine: qcom: bam_dma: Add "powered remotely" mode
Date: Mon, 11 Oct 2021 10:39:20 -0700 [thread overview]
Message-ID: <YWR2yN3x3zroz1GX@ripper> (raw)
In-Reply-To: <20211011141733.3999-3-stephan@gerhold.net>
On Mon 11 Oct 07:17 PDT 2021, Stephan Gerhold wrote:
> In some configurations, the BAM DMA controller is set up by a remote
> processor and the local processor can simply start making use of it
> without setting up the BAM. This is already supported using the
> "qcom,controlled-remotely" property.
>
> However, for some reason another possible configuration is that the
> remote processor is responsible for powering up the BAM, but we are
> still responsible for initializing it (e.g. resetting it etc).
>
> This configuration is quite challenging to handle properly because
> the power control is handled through separate channels
> (e.g. device-specific SMSM interrupts / smem-states). Great care
> must be taken to ensure the BAM registers are not accessed while
> the BAM is powered off since this results in a bus stall.
>
> Attempt to support this configuration with minimal device-specific
> code in the bam_dma driver by tracking the number of requested
> channels. Consumers of DMA channels are responsible to only request
> DMA channels when the BAM was powered on by the remote processor,
> and to release them before the BAM is powered off.
>
> When the first channel is requested the BAM is initialized (reset)
> and it is also put into reset when the last channel was released.
>
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> ---
> Changes since RFC:
> - Drop qcom-specific terminology "power collapse", instead rename
> "qcom,remote-power-collapse" -> "qcom,powered-remotely"
>
> NOTE: This is *not* a compile-time requirement for the BAM-DMUX driver
> so this could also go through the dmaengine tree.
>
> See original RFC for a discussion of alternative approaches to handle
> this configuration:
> https://lore.kernel.org/netdev/20210719145317.79692-3-stephan@gerhold.net/
> ---
> drivers/dma/qcom/bam_dma.c | 88 ++++++++++++++++++++++++--------------
> 1 file changed, 56 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index c8a77b428b52..1b33a3ebbfec 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -388,6 +388,8 @@ struct bam_device {
> /* execution environment ID, from DT */
> u32 ee;
> bool controlled_remotely;
> + bool powered_remotely;
> + u32 active_channels;
>
> const struct reg_offset_data *layout;
>
> @@ -415,6 +417,44 @@ static inline void __iomem *bam_addr(struct bam_device *bdev, u32 pipe,
> r.ee_mult * bdev->ee;
> }
>
> +/**
> + * bam_reset - reset and initialize BAM registers
Please include a set of () after the function name.
> + * @bdev: bam device
> + */
> +static void bam_reset(struct bam_device *bdev)
> +{
> + u32 val;
> +
> + /* s/w reset bam */
> + /* after reset all pipes are disabled and idle */
> + val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
> + val |= BAM_SW_RST;
> + writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> + val &= ~BAM_SW_RST;
> + writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
Seems odd to me that we assert and deassert the reset in back-to-back
writes, without any delay etc. That said, this is unrelated to your
patch as you just moved this hunk from below.
> +
> + /* make sure previous stores are visible before enabling BAM */
> + wmb();
> +
> + /* enable bam */
> + val |= BAM_EN;
> + writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> +
> + /* set descriptor threshhold, start with 4 bytes */
> + writel_relaxed(DEFAULT_CNT_THRSHLD,
> + bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
> +
> + /* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
> + writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
> +
> + /* enable irqs for errors */
> + writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN,
> + bam_addr(bdev, 0, BAM_IRQ_EN));
> +
> + /* unmask global bam interrupt */
> + writel_relaxed(BAM_IRQ_MSK, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
> +}
> +
> /**
> * bam_reset_channel - Reset individual BAM DMA channel
> * @bchan: bam channel
> @@ -512,6 +552,9 @@ static int bam_alloc_chan(struct dma_chan *chan)
> return -ENOMEM;
> }
>
> + if (bdev->active_channels++ == 0 && bdev->powered_remotely)
> + bam_reset(bdev);
> +
> return 0;
> }
>
> @@ -565,6 +608,13 @@ static void bam_free_chan(struct dma_chan *chan)
> /* disable irq */
> writel_relaxed(0, bam_addr(bdev, bchan->id, BAM_P_IRQ_EN));
>
> + if (--bdev->active_channels == 0 && bdev->powered_remotely) {
> + /* s/w reset bam */
> + val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
> + val |= BAM_SW_RST;
> + writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> + }
> +
> err:
> pm_runtime_mark_last_busy(bdev->dev);
> pm_runtime_put_autosuspend(bdev->dev);
> @@ -1164,38 +1214,10 @@ static int bam_init(struct bam_device *bdev)
> bdev->num_channels = val & BAM_NUM_PIPES_MASK;
> }
>
> - if (bdev->controlled_remotely)
> + if (bdev->controlled_remotely || bdev->powered_remotely)
> return 0;
I think the resulting code would be cleaner if you flipped it around as:
/* Reset BAM now if fully controlled locally */
if (!bdev->controlled_remotely && !bdev->powered_remotely)
bam_reset(bdev);
return 0;
Regards,
Bjorn
>
> - /* s/w reset bam */
> - /* after reset all pipes are disabled and idle */
> - val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
> - val |= BAM_SW_RST;
> - writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> - val &= ~BAM_SW_RST;
> - writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> -
> - /* make sure previous stores are visible before enabling BAM */
> - wmb();
> -
> - /* enable bam */
> - val |= BAM_EN;
> - writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
> -
> - /* set descriptor threshhold, start with 4 bytes */
> - writel_relaxed(DEFAULT_CNT_THRSHLD,
> - bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
> -
> - /* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
> - writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
> -
> - /* enable irqs for errors */
> - writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN,
> - bam_addr(bdev, 0, BAM_IRQ_EN));
> -
> - /* unmask global bam interrupt */
> - writel_relaxed(BAM_IRQ_MSK, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
> -
> + bam_reset(bdev);
> return 0;
> }
next prev parent reply other threads:[~2021-10-11 17:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-11 14:17 [PATCH net-next v2 0/4] net: wwan: Add Qualcomm BAM-DMUX WWAN network driver Stephan Gerhold
2021-10-11 14:17 ` [PATCH net-next v2 1/4] dt-bindings: dmaengine: bam_dma: Add "powered remotely" mode Stephan Gerhold
2021-10-18 6:17 ` Vinod Koul
2021-10-18 10:29 ` Stephan Gerhold
2021-10-18 11:34 ` Bhupesh Sharma
2021-10-18 12:56 ` Stephan Gerhold
2021-10-18 16:41 ` Bhupesh Sharma
2021-10-11 14:17 ` [PATCH net-next v2 2/4] dmaengine: qcom: " Stephan Gerhold
2021-10-11 17:39 ` Bjorn Andersson [this message]
2021-10-11 18:06 ` Stephan Gerhold
2021-10-11 14:17 ` [PATCH net-next v2 3/4] dt-bindings: net: Add schema for Qualcomm BAM-DMUX Stephan Gerhold
2021-10-18 20:22 ` Rob Herring
2021-10-19 7:03 ` Stephan Gerhold
2021-10-19 13:19 ` Rob Herring
2021-10-19 13:31 ` Stephan Gerhold
2021-10-11 14:17 ` [PATCH net-next v2 4/4] net: wwan: Add Qualcomm BAM-DMUX WWAN network driver Stephan Gerhold
2021-10-11 14:51 ` Stephan Gerhold
2021-10-12 7:55 ` Loic Poulain
2021-10-12 8:43 ` Stephan Gerhold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YWR2yN3x3zroz1GX@ripper \
--to=bjorn.andersson@linaro.org \
--cc=agross@kernel.org \
--cc=aleksander@aleksander.es \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=jeffrey.l.hugo@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=phone-devel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=ryazanov.s.a@gmail.com \
--cc=stephan@gerhold.net \
--cc=vkoul@kernel.org \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).