All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bean Huo <huobean@gmail.com>
To: daejun7.park@samsung.com, Greg KH <gregkh@linuxfoundation.org>,
	"avri.altman@wdc.com" <avri.altman@wdc.com>,
	"jejb@linux.ibm.com" <jejb@linux.ibm.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"asutoshd@codeaurora.org" <asutoshd@codeaurora.org>,
	"stanley.chu@mediatek.com" <stanley.chu@mediatek.com>,
	"cang@codeaurora.org" <cang@codeaurora.org>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	ALIM AKHTAR <alim.akhtar@samsung.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	JinHwan Park <jh.i.park@samsung.com>,
	Javier Gonzalez <javier.gonz@samsung.com>,
	SEUNGUK SHIN <seunguk.shin@samsung.com>,
	Sung-Jun Park <sungjun07.park@samsung.com>,
	Jinyoung CHOI <j-young.choi@samsung.com>,
	BoRam Shin <boram.shin@samsung.com>
Subject: Re: [PATCH v26 4/4] scsi: ufs: Add HPB 2.0 support
Date: Thu, 04 Mar 2021 10:59:55 +0100	[thread overview]
Message-ID: <0242e4ab10acff9a7d71c2f956ba4624bf95add2.camel@gmail.com> (raw)
In-Reply-To: <20210303062926epcms2p6aa6737e5ed3916eed9ab80011aad3d83@epcms2p6>

On Wed, 2021-03-03 at 15:29 +0900, Daejun Park wrote:
> +
> +static inline int ufshpb_get_read_id(struct ufshpb_lu *hpb)
> +{
> +       if (++hpb->cur_read_id >= MAX_HPB_READ_ID)
> +               hpb->cur_read_id = 0;
> +       return hpb->cur_read_id;
> +}
> +
> +static int ufshpb_execute_pre_req(struct ufshpb_lu *hpb, struct
> scsi_cmnd *cmd,
> +                                 struct ufshpb_req *pre_req, int
> read_id)
> +{
> +       struct scsi_device *sdev = cmd->device;
> +       struct request_queue *q = sdev->request_queue;
> +       struct request *req;
> +       struct scsi_request *rq;
> +       struct bio *bio = pre_req->bio;
> +
> +       pre_req->hpb = hpb;
> +       pre_req->wb.lpn = sectors_to_logical(cmd->device,
> +                                            blk_rq_pos(cmd-
> >request));
> +       pre_req->wb.len = sectors_to_logical(cmd->device,
> +                                            blk_rq_sectors(cmd-
> >request));
> +       if (ufshpb_pre_req_add_bio_page(hpb, q, pre_req))
> +               return -ENOMEM;
> +
> +       req = pre_req->req;
> +
> +       /* 1. request setup */
> +       blk_rq_append_bio(req, &bio);
> +       req->rq_disk = NULL;
> +       req->end_io_data = (void *)pre_req;
> +       req->end_io = ufshpb_pre_req_compl_fn;
> +
> +       /* 2. scsi_request setup */
> +       rq = scsi_req(req);
> +       rq->retries = 1;
> +
> +       ufshpb_set_write_buf_cmd(rq->cmd, pre_req->wb.lpn, pre_req-
> >wb.len,
> +                                read_id);
> +       rq->cmd_len = scsi_command_size(rq->cmd);
> +
> +       if (blk_insert_cloned_request(q, req) != BLK_STS_OK)
> +               return -EAGAIN;
> +
> +       hpb->stats.pre_req_cnt++;
> +
> +       return 0;
> +}
> +
> +static int ufshpb_issue_pre_req(struct ufshpb_lu *hpb, struct
> scsi_cmnd *cmd,
> +                               int *read_id)
> +{
> +       struct ufshpb_req *pre_req;
> +       struct request *req = NULL;
> +       struct bio *bio = NULL;
> +       unsigned long flags;
> +       int _read_id;
> +       int ret = 0;
> +
> +       req = blk_get_request(cmd->device->request_queue,
> +                             REQ_OP_SCSI_OUT | REQ_SYNC,
> BLK_MQ_REQ_NOWAIT);
> +       if (IS_ERR(req))
> +               return -EAGAIN;
> +
> +       bio = bio_alloc(GFP_ATOMIC, 1);
> +       if (!bio) {
> +               blk_put_request(req);
> +               return -EAGAIN;
> +       }
> +
> +       spin_lock_irqsave(&hpb->rgn_state_lock, flags);
> +       pre_req = ufshpb_get_pre_req(hpb);
> +       if (!pre_req) {
> +               ret = -EAGAIN;
> +               goto unlock_out;
> +       }
> +       _read_id = ufshpb_get_read_id(hpb);
> +       spin_unlock_irqrestore(&hpb->rgn_state_lock, flags);
> +
> +       pre_req->req = req;
> +       pre_req->bio = bio;
> +
> +       ret = ufshpb_execute_pre_req(hpb, cmd, pre_req, _read_id);
> +       if (ret)
> +               goto free_pre_req;
> +
> +       *read_id = _read_id;
> +
> +       return ret;
> +free_pre_req:
> +       spin_lock_irqsave(&hpb->rgn_state_lock, flags);
> +       ufshpb_put_pre_req(hpb, pre_req);
> +unlock_out:
> +       spin_unlock_irqrestore(&hpb->rgn_state_lock, flags);
> +       bio_put(bio);
> +       blk_put_request(req);
> +       return ret;
> +}
> +
>  /*
>   * This function will set up HPB read command using host-side L2P
> map data.
> - * In HPB v1.0, maximum size of HPB read command is 4KB.
>   */
> -void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
> +int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
>  {
>         struct ufshpb_lu *hpb;
>         struct ufshpb_region *rgn;
> @@ -291,26 +560,27 @@ void ufshpb_prep(struct ufs_hba *hba, struct
> ufshcd_lrb *lrbp)
>         u64 ppn;
>         unsigned long flags;
>         int transfer_len, rgn_idx, srgn_idx, srgn_offset;
> +       int read_id = 0;
>         int err = 0;
>  
>         hpb = ufshpb_get_hpb_data(cmd->device);
>         if (!hpb)
> -               return;
> +               return -ENODEV;
>  
>         if (ufshpb_get_state(hpb) != HPB_PRESENT) {
>                 dev_notice(&hpb->sdev_ufs_lu->sdev_dev,
>                            "%s: ufshpb state is not PRESENT",
> __func__);
> -               return;
> +               return -ENODEV;
>         }
>  
>         if (!ufshpb_is_write_or_discard_cmd(cmd) &&
>             !ufshpb_is_read_cmd(cmd))
> -               return;
> +               return 0;
>  
>         transfer_len = sectors_to_logical(cmd->device,
>                                           blk_rq_sectors(cmd-
> >request));
>         if (unlikely(!transfer_len))
> -               return;
> +               return 0;
>  
>         lpn = sectors_to_logical(cmd->device, blk_rq_pos(cmd-
> >request));
>         ufshpb_get_pos_from_lpn(hpb, lpn, &rgn_idx, &srgn_idx,
> &srgn_offset);
> @@ -323,18 +593,19 @@ void ufshpb_prep(struct ufs_hba *hba, struct
> ufshcd_lrb *lrbp)
>                 ufshpb_set_ppn_dirty(hpb, rgn_idx, srgn_idx,
> srgn_offset,
>                                  transfer_len);
>                 spin_unlock_irqrestore(&hpb->rgn_state_lock, flags);
> -               return;
> +               return 0;
>         }
>  
> -       if (!ufshpb_is_support_chunk(transfer_len))
> -               return;
> +       if (!ufshpb_is_support_chunk(hpb, transfer_len) &&
> +           (ufshpb_is_legacy(hba) && (transfer_len !=
> HPB_LEGACY_CHUNK_HIGH)))
> +               return 0;
>  
>         spin_lock_irqsave(&hpb->rgn_state_lock, flags);
>         if (ufshpb_test_ppn_dirty(hpb, rgn_idx, srgn_idx,
> srgn_offset,
>                                    transfer_len)) {
>                 hpb->stats.miss_cnt++;
>                 spin_unlock_irqrestore(&hpb->rgn_state_lock, flags);
> -               return;
> +               return 0;
>         }
>  
>         err = ufshpb_fill_ppn_from_page(hpb, srgn->mctx, srgn_offset,
> 1, &ppn);
> @@ -347,28 +618,46 @@ void ufshpb_prep(struct ufs_hba *hba, struct
> ufshcd_lrb *lrbp)
>                  * active state.
>                  */
>                 dev_err(hba->dev, "get ppn failed. err %d\n", err);
> -               return;
> +               return err;
> +       }
> +
> +       if (!ufshpb_is_legacy(hba) &&
> +           ufshpb_is_required_wb(hpb, transfer_len)) {
> +               err = ufshpb_issue_pre_req(hpb, cmd, &read_id);
> +               if (err) {
> +                       unsigned long timeout;
> +
> +                       timeout = cmd->jiffies_at_alloc +
> msecs_to_jiffies(
> +                                 hpb->params.requeue_timeout_ms);
> +
> +                       if (time_before(jiffies, timeout))
> +                               return -EAGAIN;
> +
> +                       hpb->stats.miss_cnt++;
> +                       return 0;
> +               }
>         }
>  
> -       ufshpb_set_hpb_read_to_upiu(hpb, lrbp, lpn, ppn,
> transfer_len);
> +       ufshpb_set_hpb_read_to_upiu(hpb, lrbp, lpn, ppn,
> transfer_len, read_id);
>  
>         hpb->stats.hit_cnt++;
> +       return 0;
>  }



BUG!!!


Please read HPB 2.0 Spec carefully, and check how to correctly use HPB
READ ID. you are assigning 0 for HPB write buffer. how can you expect
the HPB READ be paired???



HPB READ ID
• If this value is 0, then HPB READ ID mode is not used, in which case
the physical addresses, except for the first LBA, needed to read the
data should be calculated or searched for by the device. If this value
is not 0, then HPB READ ID mode is used, in which case the device
returns the data corresponding to the HPB entries that are bound to
the HPB READ ID value.

Bean


  parent reply	other threads:[~2021-03-04 10:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p2>
2021-03-03  6:26 ` [PATCH v26 0/4] scsi: ufs: Add Host Performance Booster Support Daejun Park
     [not found]   ` <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p1>
2021-03-03  6:28     ` [PATCH v26 1/4] scsi: ufs: Introduce HPB feature Daejun Park
2021-03-09  3:15       ` [PATCH] [v26,1/4] " Wang Qing
2021-03-09  6:21       ` [Resend]Re: " Wang Qing
     [not found]   ` <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p6>
2021-03-03  6:28     ` [PATCH v26 2/4] scsi: ufs: L2P map management for HPB read Daejun Park
2021-03-11  8:56       ` Can Guo
2021-03-12  1:19       ` Can Guo
     [not found]       ` <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p8>
2021-03-12  1:23         ` Daejun Park
     [not found]       ` <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p3>
2021-03-12  1:48         ` Daejun Park
2021-03-12  2:03           ` Can Guo
2021-03-12  7:17         ` Daejun Park
2021-03-15  1:54           ` Can Guo
2021-03-03  6:29     ` [PATCH v26 4/4] scsi: ufs: Add HPB 2.0 support Daejun Park
2021-03-03 14:50       ` Bean Huo
2021-03-04  8:37         ` Can Guo
2021-03-04  6:25       ` Can Guo
2021-03-04  8:21       ` Can Guo
2021-03-04  9:59       ` Bean Huo [this message]
2021-03-09  1:38       ` Can Guo
2021-03-10  9:14         ` Can Guo
     [not found]   ` <CGME20210303062633epcms2p252227acd30ad15c1ca821d7e3f547b9e@epcms2p5>
2021-03-03  6:28     ` [PATCH v26 3/4] scsi: ufs: Prepare HPB read for cached sub-region Daejun Park
2021-03-12  1:23       ` Can Guo
2021-03-05  0:35     ` Re: [PATCH v26 4/4] scsi: ufs: Add HPB 2.0 support Daejun Park
2021-03-15  2:19     ` Re: [PATCH v26 2/4] scsi: ufs: L2P map management for HPB read Daejun Park
2021-03-05  0:24 ` Re: [PATCH v26 4/4] scsi: ufs: Add HPB 2.0 support Daejun Park
2021-03-05  0:33 ` Daejun Park

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=0242e4ab10acff9a7d71c2f956ba4624bf95add2.camel@gmail.com \
    --to=huobean@gmail.com \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avri.altman@wdc.com \
    --cc=boram.shin@samsung.com \
    --cc=bvanassche@acm.org \
    --cc=cang@codeaurora.org \
    --cc=daejun7.park@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=j-young.choi@samsung.com \
    --cc=javier.gonz@samsung.com \
    --cc=jejb@linux.ibm.com \
    --cc=jh.i.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=seunguk.shin@samsung.com \
    --cc=stanley.chu@mediatek.com \
    --cc=sungjun07.park@samsung.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 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.