linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jolly Shah <jollys@google.com>
To: John Garry <john.garry@huawei.com>
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com,
	a.darwish@linutronix.de, Jason Yan <yanaijie@huawei.com>,
	luojiaxing@huawei.com, dan.carpenter@oracle.com,
	b.zolnierkie@samsung.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Reset num_scatter if libata mark qc as NODATA
Date: Thu, 18 Mar 2021 16:06:20 -0700	[thread overview]
Message-ID: <CABGCNpDisbWF=fSyKZPfyvR7RgZQeCg-PVxYOUs6PpkagAiMmw@mail.gmail.com> (raw)
In-Reply-To: <329a6159-7da6-f60d-b1a5-14648b90f052@huawei.com>

Hi John,


On Thu, Mar 18, 2021 at 9:19 AM John Garry <john.garry@huawei.com> wrote:
>
> On 18/03/2021 00:24, Jolly Shah wrote:
> > Hi John,
> >
> > Thanks for the review.
> >
> >
> > On Wed, Mar 17, 2021 at 4:44 AM John Garry <john.garry@huawei.com> wrote:
> >>
> >> On 16/03/2021 19:39, Jolly Shah wrote:
> >>> When the cache_type for the scsi device is changed, the scsi layer
> >>> issues a MODE_SELECT command. The caching mode details are communicated
> >>> via a request buffer associated with the scsi command with data
> >>> direction set as DMA_TO_DEVICE (scsi_mode_select). When this command
> >>> reaches the libata layer, as a part of generic initial setup, libata
> >>> layer sets up the scatterlist for the command using the scsi command
> >>> (ata_scsi_qc_new). This command is then translated by the libata layer
> >>> into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer
> >>> treats this as a non data command (ata_mselect_caching), since it only
> >>> needs an ata taskfile to pass the caching on/off information to the
> >>> device. It does not need the scatterlist that has been setup, so it does
> >>> not perform dma_map_sg on the scatterlist (ata_qc_issue).
> >>
> >> So if we don't perform the dma_map_sg() on the sgl at this point, then
> >> it seems to me that we should not perform for_each_sg() on it either,
> >> right? That is still what happens in sas_ata_qc_issue() in this case.
> >>
>
> Hi Jolly Shah,
>
> >
> > Yes that's right. To avoid that, I can add elseif block for
> > ATA_PROT_NODATA before for_each_sg() is performed. Currently there's
> > existing code block for ATA_PROT_NODATA after for_each_sg()  is
> > performed,
> > reused that to reset num_scatter. Please suggest.
> >
>
> How about just combine the 2x if-else statements into 1x if-elif-else
> statement, like:
>
>
> if (ata_is_atapi(qc->tf.protocol)) {
>         memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
>         task->total_xfer_len = qc->nbytes;
>         task->num_scatter = qc->n_elem;
>         task->data_dir = qc->dma_dir;
> } else if (qc->tf.protocol == ATA_PROT_NODATA) {
>         task->data_dir = DMA_NONE;
> } else {
>         for_each_sg(qc->sg, sg, qc->n_elem, si)
>                 xfer += sg_dma_len(sg);
>
>         task->total_xfer_len = xfer;
>         task->num_scatter = si;
>         task->data_dir = qc->dma_dir;
> }
>
Updated in v2.

> >>> Unfortunately,
> >>> when this command reaches the libsas layer(sas_ata_qc_issue), libsas
> >>> layer sees it as a non data command with a scatterlist. It cannot
> >>> extract the correct dma length, since the scatterlist has not been
> >>> mapped with dma_map_sg for a DMA operation. When this partially
> >>> constructed SAS task reaches pm80xx LLDD, it results in below warning.
> >>>
> >>> "pm80xx_chip_sata_req 6058: The sg list address
> >>> start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff
> >>> end_addr_low=0xffffffff has crossed 4G boundary"
> >>>
> >>> This patch assigns appropriate value to  num_sectors for ata non data
> >>> commands.
> >>>
> >>> Signed-off-by: Jolly Shah <jollys@google.com>
> >>> ---
> >>>    drivers/scsi/libsas/sas_ata.c | 6 ++++--
> >>>    1 file changed, 4 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
> >>> index 024e5a550759..94ec08cebbaa 100644
> >>> --- a/drivers/scsi/libsas/sas_ata.c
> >>> +++ b/drivers/scsi/libsas/sas_ata.c
> >>> @@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
> >>>                task->num_scatter = si;
> >>>        }
> >>>
> >>> -     if (qc->tf.protocol == ATA_PROT_NODATA)
> >>> +     if (qc->tf.protocol == ATA_PROT_NODATA) {
> >>>                task->data_dir = DMA_NONE;
> >>> -     else
> >>> +             task->num_scatter = 0;
> >>
> >> task->num_scatter has already been set in this function. Best not set it
> >> twice.
> >>
> >
> > Sure. Please suggest if I should update patch to above suggested
> > approach. That will avoid setting num_scatter twice.
> >
>
> Thanks,
> John
>
> BTW, could we add a fixes tag?

Added in v2.

Thanks,
Jolly

      reply	other threads:[~2021-03-18 23:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 19:39 [PATCH] scsi: libsas: Reset num_scatter if libata mark qc as NODATA Jolly Shah
2021-03-17  1:50 ` Jason Yan
2021-03-17 17:11   ` Jolly Shah
2021-03-17 11:42 ` John Garry
2021-03-18  0:24   ` Jolly Shah
2021-03-18 16:17     ` John Garry
2021-03-18 23:06       ` Jolly Shah [this message]

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='CABGCNpDisbWF=fSyKZPfyvR7RgZQeCg-PVxYOUs6PpkagAiMmw@mail.gmail.com' \
    --to=jollys@google.com \
    --cc=a.darwish@linutronix.de \
    --cc=b.zolnierkie@samsung.com \
    --cc=dan.carpenter@oracle.com \
    --cc=jejb@linux.ibm.com \
    --cc=john.garry@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=luojiaxing@huawei.com \
    --cc=martin.petersen@oracle.com \
    --cc=yanaijie@huawei.com \
    /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).