From: Vinod Koul <vkoul@kernel.org>
To: Jassi Brar <jassisinghbrar@gmail.com>
Cc: dmaengine@vger.kernel.org,
Devicetree List <devicetree@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
orito.takao@socionext.com,
Masami Hiramatsu <masami.hiramatsu@linaro.org>,
kasai.kazuhiro@socionext.com,
Jassi Brar <jaswinder.singh@linaro.org>
Subject: Re: [PATCH 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms
Date: Fri, 16 Aug 2019 10:13:04 +0530 [thread overview]
Message-ID: <20190816044304.GZ12733@vkoul-mobl.Dlink> (raw)
In-Reply-To: <CABb+yY3pLBA=Y_4kUZ-E_VWOiJsofung2bMA5HqkNeNJkOOZxQ@mail.gmail.com>
On 15-08-19, 21:25, Jassi Brar wrote:
> On Mon, Jun 24, 2019 at 1:47 AM Vinod Koul <vkoul@kernel.org> wrote:
> >
> > On 12-06-19, 19:52, jassisinghbrar@gmail.com wrote:
> >
> > > +#include <linux/bits.h>
> > > +#include <linux/clk.h>
> > > +#include <linux/dma-mapping.h>
> > > +#include <linux/dmaengine.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/iopoll.h>
> > > +#include <linux/list.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of.h>
> > > +#include <linux/of_dma.h>
> >
> > Do we need both, IIRC of_dma.h does include of.h!
> >
> OK
>
> > > +/* mc->vc.lock must be held by caller */
> > > +static void milbeaut_chan_start(struct milbeaut_hdmac_chan *mc,
> > > + struct milbeaut_hdmac_desc *md)
> > > +{
> > > + struct scatterlist *sg;
> > > + u32 cb, ca, src_addr, dest_addr, len;
> > ^^
> > double space
> >
> OK
>
> > > +static irqreturn_t milbeaut_hdmac_interrupt(int irq, void *dev_id)
> > > +{
> > > + struct milbeaut_hdmac_chan *mc = dev_id;
> > > + struct milbeaut_hdmac_desc *md;
> > > + irqreturn_t ret = IRQ_HANDLED;
> > > + u32 val;
> > > +
> > > + spin_lock(&mc->vc.lock);
> > > +
> > > + /* Ack and Disable irqs */
> > > + val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACB);
> > > + val &= ~(FIELD_PREP(MLB_HDMAC_SS, 0x7));
> > ^^^^
> > Magic ..?
> >
> OK, will define a macro for 7
>
> > > +static int milbeaut_hdmac_chan_pause(struct dma_chan *chan)
> > > +{
> > > + struct virt_dma_chan *vc = to_virt_chan(chan);
> > > + struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
> > > + u32 val;
> > > +
> > > + spin_lock(&mc->vc.lock);
> > > + val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
> > > + val |= MLB_HDMAC_PB;
> > > + writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);
> >
> > We really should have an updatel() and friends in kernel, feel free to
> > add in your driver though!
> >
> I'll pass on that for now.
>
> > > +static int milbeaut_hdmac_chan_init(struct platform_device *pdev,
> > > + struct milbeaut_hdmac_device *mdev,
> > > + int chan_id)
> > > +{
> > > + struct device *dev = &pdev->dev;
> > > + struct milbeaut_hdmac_chan *mc = &mdev->channels[chan_id];
> > > + char *irq_name;
> > > + int irq, ret;
> > > +
> > > + irq = platform_get_irq(pdev, chan_id);
> > > + if (irq < 0) {
> > > + dev_err(&pdev->dev, "failed to get IRQ number for ch%d\n",
> > > + chan_id);
> > > + return irq;
> > > + }
> > > +
> > > + irq_name = devm_kasprintf(dev, GFP_KERNEL, "milbeaut-hdmac-%d",
> > > + chan_id);
> > > + if (!irq_name)
> > > + return -ENOMEM;
> > > +
> > > + ret = devm_request_irq(dev, irq, milbeaut_hdmac_interrupt,
> > > + IRQF_SHARED, irq_name, mc);
> >
> > I tend to dislike using devm_request_irq(), we have no control over when
> > the irq is freed and what is a spirious irq is running while we are
> > unrolling, so IMHO it make sense to free up and ensure all tasklets are
> > quiesced when remove returns
> >
> If the code is written clean and tight we need not be so paranoid.
>
> > > + if (ret)
> > > + return ret;
> > > +
> > > + mc->mdev = mdev;
> > > + mc->reg_ch_base = mdev->reg_base + MLB_HDMAC_CH_STRIDE * (chan_id + 1);
> > > + mc->vc.desc_free = milbeaut_hdmac_desc_free;
> > > + vchan_init(&mc->vc, &mdev->ddev);
> >
> > who kills the vc->task?
> >
> vchan_synchronize() called from milbeaut_hdmac_synchronize()
But that can be skipped by called, from driver pov we need to ensure
that it is killed
> > > +static int milbeaut_hdmac_remove(struct platform_device *pdev)
> > > +{
> > > + struct milbeaut_hdmac_device *mdev = platform_get_drvdata(pdev);
> > > + struct dma_chan *chan;
> > > + int ret;
> > > +
> > > + /*
> > > + * Before reaching here, almost all descriptors have been freed by the
> > > + * ->device_free_chan_resources() hook. However, each channel might
> > > + * be still holding one descriptor that was on-flight at that moment.
> > > + * Terminate it to make sure this hardware is no longer running. Then,
> > > + * free the channel resources once again to avoid memory leak.
> > > + */
> > > + list_for_each_entry(chan, &mdev->ddev.channels, device_node) {
> > > + ret = dmaengine_terminate_sync(chan);
> > > + if (ret)
> > > + return ret;
> > > + milbeaut_hdmac_free_chan_resources(chan);
> > > + }
> > > +
> > > + of_dma_controller_free(pdev->dev.of_node);
> > > + dma_async_device_unregister(&mdev->ddev);
> > > + clk_disable_unprepare(mdev->clk);
> >
> > And as suspected we have active tasklets and irq at this time :(
> >
> Not sure how is that....
Since you use devm variants, and driver tasklet is not killed, irq can
be fired (spurious as well) and can run irq and schedule a tasklet. How
do you prevent that?
Thanks
--
~Vinod
next prev parent reply other threads:[~2019-08-16 4:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-13 0:51 [PATCH 0/2] Add support for AHB DMA controller on Milbeaut series jassisinghbrar
2019-06-13 0:52 ` [PATCH 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings jassisinghbrar
2019-07-09 14:34 ` Rob Herring
2019-07-10 4:12 ` Jassi Brar
2019-07-10 13:48 ` Rob Herring
2019-06-13 0:52 ` [PATCH 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms jassisinghbrar
2019-06-24 6:44 ` Vinod Koul
2019-08-16 2:25 ` Jassi Brar
2019-08-16 4:43 ` Vinod Koul [this message]
2019-08-18 5:16 ` [PATCH v2 0/2] Add support for AHB DMA controller on Milbeaut series jassisinghbrar
2019-08-18 5:17 ` [PATCH v2 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings jassisinghbrar
2019-08-27 16:31 ` Rob Herring
2019-09-04 5:50 ` Vinod Koul
2019-09-04 6:18 ` Jassi Brar
2019-09-06 5:12 ` Vinod Koul
2019-08-18 5:18 ` [PATCH v2 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms jassisinghbrar
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=20190816044304.GZ12733@vkoul-mobl.Dlink \
--to=vkoul@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=jassisinghbrar@gmail.com \
--cc=jaswinder.singh@linaro.org \
--cc=kasai.kazuhiro@socionext.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masami.hiramatsu@linaro.org \
--cc=orito.takao@socionext.com \
--cc=robh+dt@kernel.org \
/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).