All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akhil R <akhilrajeev@nvidia.com>
To: Dmitry Osipenko <digetx@gmail.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Krishna Yarlagadda <kyarlagadda@nvidia.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	Rajesh Gumasta <rgumasta@nvidia.com>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"thierry.reding@gmail.com" <thierry.reding@gmail.com>,
	"vkoul@kernel.org" <vkoul@kernel.org>,
	Pavan Kunapuli <pkunapuli@nvidia.com>
Subject: RE: [PATCH v17 2/4] dmaengine: tegra: Add tegra gpcdma driver
Date: Mon, 31 Jan 2022 15:38:07 +0000	[thread overview]
Message-ID: <DM5PR12MB18505C4CB4A34F96E74BF28FC0259@DM5PR12MB1850.namprd12.prod.outlook.com> (raw)
In-Reply-To: <8abf2da8-9a11-8f16-b495-d8ef2d00ab51@gmail.com>

> 31.01.2022 12:09, Akhil R пишет:
> >> В Mon, 31 Jan 2022 04:25:14 +0000
> >> Akhil R <akhilrajeev@nvidia.com> пишет:
> >>
> >>>> 30.01.2022 19:34, Akhil R пишет:
> >>>>>> 29.01.2022 19:40, Akhil R пишет:
> >>>>>>> +static int tegra_dma_device_pause(struct dma_chan *dc) {
> >>>>>>> +     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
> >>>>>>> +     unsigned long wcount, flags;
> >>>>>>> +     int ret = 0;
> >>>>>>> +
> >>>>>>> +     if (!tdc->tdma->chip_data->hw_support_pause)
> >>>>>>> +             return 0;
> >>>>>>
> >>>>>> It's wrong to return zero if pause unsupported, please see what
> >>>>>> dmaengine_pause() returns.
> >>>>>>
> >>>>>>> +
> >>>>>>> +     spin_lock_irqsave(&tdc->vc.lock, flags);
> >>>>>>> +     if (!tdc->dma_desc)
> >>>>>>> +             goto out;
> >>>>>>> +
> >>>>>>> +     ret = tegra_dma_pause(tdc);
> >>>>>>> +     if (ret) {
> >>>>>>> +             dev_err(tdc2dev(tdc), "DMA pause timed out\n");
> >>>>>>> +             goto out;
> >>>>>>> +     }
> >>>>>>> +
> >>>>>>> +     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
> >>>>>>> +     tdc->dma_desc->bytes_xfer +=
> >>>>>>> +                     tdc->dma_desc->bytes_req - (wcount * 4);
> >>>>>>
> >>>>>> Why transfer is accumulated?
> >>>>>>
> >>>>>> Why do you need to update xfer size at all on pause?
> >>>>>
> >>>>> I will verify the calculation. This looks correct only for single
> >>>>> sg transaction.
> >>>>>
> >>>>> Updating xfer_size is added to support drivers which pause the
> >>>>> transaction and read the status before terminating.
> >>>>> Eg.
> >>>>
> >>>> Why you couldn't update the status in tegra_dma_terminate_all()?
> >>> Is it useful to update the status in terminate_all()? I assume the
> >>> descriptor Is freed in vchan_dma_desc_free_list() or am I getting it
> >>> wrong?
> >>
> >> Yes, it's not useful. Then you only need to fix the tx_status() and
> >> don't touch dma_desc on pause.
> > If the bytes_xfer is updated in tx_status(), I suppose
> > DMA_RESIDUE_GRANULARITY_BURST can be kept as is, correct?
> 
> You don't need to update bytes_xfer in tx_status(). Please see Tegra20
> DMA driver for the example, which supports GRANULARITY_BURST properly.

Does the below method look good? bytes_xfer is updated on every ISR and in
tx_status(), the wcount is read to calculate the intermittent value. If the transfer
get complete in between, use wcount as 0 to add sg_req.len to bytes_xfer

static int tegra_dma_get_residual(struct tegra_dma_channel *tdc)
{
	unsigned long wcount = 0, status;
	unsigned int bytes_xfer, residual;
	struct tegra_dma_desc *dma_desc = tdc->dma_desc;
	struct tegra_dma_sg_req *sg_req = dma_desc->sg_req;

	/*
	 * Do not read from CHAN_XFER_COUNT if EOC bit is set
	 * as the transfer would have already completed and
	 * the register could have updated for next transfer
	 * in case of cyclic transfers.
	 */
	status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
	if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
		wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);

	bytes_xfer = dma_desc->bytes_xfer +
		     sg_req[dma_desc->sg_idx - 1].len - (wcount * 4);

	residual = dma_desc->bytes_req - (bytes_xfer % dma_desc->bytes_req);

	return residual;
}

static enum dma_status tegra_dma_tx_status( )
{
	....

	spin_lock_irqsave(&tdc->vc.lock, flags);
	...
	} else if (tdc->dma_desc && tdc->dma_desc->vd.tx.cookie == cookie) {
		residual =  tegra_dma_get_residual(tdc);
		dma_set_residue(txstate, residual);
	} else {
		dev_err(tdc2dev(tdc), "cookie %d is not found\n", cookie);
	}
	spin_unlock_irqrestore(&tdc->vc.lock, flags);

	return ret;
}

  reply	other threads:[~2022-01-31 15:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29 16:40 [PATCH v17 0/4] Add NVIDIA Tegra GPC-DMA driver Akhil R
2022-01-29 16:40 ` [PATCH v17 1/4] dt-bindings: dmaengine: Add doc for tegra gpcdma Akhil R
2022-01-29 16:40 ` [PATCH v17 2/4] dmaengine: tegra: Add tegra gpcdma driver Akhil R
2022-01-29 18:42   ` kernel test robot
2022-01-29 19:23   ` kernel test robot
2022-01-29 19:23     ` kernel test robot
2022-01-30 10:05   ` Dmitry Osipenko
2022-01-30 10:08     ` Dmitry Osipenko
2022-01-30 10:13       ` Dmitry Osipenko
2022-01-30 10:17         ` Dmitry Osipenko
2022-01-30 10:26     ` Dmitry Osipenko
2022-01-30 10:33       ` Dmitry Osipenko
2022-01-30 16:43         ` Akhil R
2022-01-30 23:23           ` Dmitry Osipenko
2022-01-30 16:34     ` Akhil R
2022-01-30 23:11       ` Dmitry Osipenko
2022-01-31  4:25         ` Akhil R
2022-01-31  6:42           ` Dmitry Osipenko
2022-01-31  9:09             ` Akhil R
2022-01-31  9:16               ` Dmitry Osipenko
2022-01-31 15:38                 ` Akhil R [this message]
2022-01-31 16:08                   ` Dmitry Osipenko
2022-02-01 12:05                     ` Akhil R
2022-02-01 13:06                       ` Dmitry Osipenko
2022-01-30 10:38   ` Dmitry Osipenko
2022-01-30 10:39   ` Dmitry Osipenko
2022-01-29 16:40 ` [PATCH v17 3/4] arm64: defconfig: tegra: Enable GPCDMA Akhil R
2022-01-29 16:40 ` [PATCH v17 4/4] arm64: tegra: Add GPCDMA node for tegra186 and tegra194 Akhil R

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=DM5PR12MB18505C4CB4A34F96E74BF28FC0259@DM5PR12MB1850.namprd12.prod.outlook.com \
    --to=akhilrajeev@nvidia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=kyarlagadda@nvidia.com \
    --cc=ldewangan@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pkunapuli@nvidia.com \
    --cc=rgumasta@nvidia.com \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=vkoul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.