Commit 7a4df79d authored by Bean Huo's avatar Bean Huo Committed by Martin K. Petersen

scsi: ufs: core: Split ufshcd_map_sg()

Take out the "map scatter-gather list to prdt" part of the code in
ufshcd_map_sg() and split it into a new function ufshcd_sgl_to_prdt().
Signed-off-by: default avatarBean Huo <beanhuo@micron.com>
Reviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 765ab00d
...@@ -2399,38 +2399,30 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) ...@@ -2399,38 +2399,30 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
} }
/** /**
* ufshcd_map_sg - Map scatter-gather list to prdt * ufshcd_sgl_to_prdt - SG list to PRTD (Physical Region Description Table, 4DW format)
* @hba: per adapter instance * @hba: per-adapter instance
* @lrbp: pointer to local reference block * @lrbp: pointer to local reference block
* * @sg_entries: The number of sg lists actually used
* Returns 0 in case of success, non-zero value in case of failure * @sg_list: Pointer to SG list
*/ */
static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) static void ufshcd_sgl_to_prdt(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, int sg_entries,
struct scatterlist *sg_list)
{ {
struct ufshcd_sg_entry *prd_table; struct ufshcd_sg_entry *prd_table;
struct scatterlist *sg; struct scatterlist *sg;
struct scsi_cmnd *cmd;
int sg_segments;
int i; int i;
cmd = lrbp->cmd; if (sg_entries) {
sg_segments = scsi_dma_map(cmd);
if (sg_segments < 0)
return sg_segments;
if (sg_segments) {
if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN)
lrbp->utr_descriptor_ptr->prd_table_length = lrbp->utr_descriptor_ptr->prd_table_length =
cpu_to_le16((sg_segments * cpu_to_le16((sg_entries * sizeof(struct ufshcd_sg_entry)));
sizeof(struct ufshcd_sg_entry)));
else else
lrbp->utr_descriptor_ptr->prd_table_length = lrbp->utr_descriptor_ptr->prd_table_length = cpu_to_le16(sg_entries);
cpu_to_le16(sg_segments);
prd_table = lrbp->ucd_prdt_ptr; prd_table = lrbp->ucd_prdt_ptr;
scsi_for_each_sg(cmd, sg, sg_segments, i) { for_each_sg(sg_list, sg, sg_entries, i) {
const unsigned int len = sg_dma_len(sg); const unsigned int len = sg_dma_len(sg);
/* /*
...@@ -2449,6 +2441,24 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) ...@@ -2449,6 +2441,24 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
} else { } else {
lrbp->utr_descriptor_ptr->prd_table_length = 0; lrbp->utr_descriptor_ptr->prd_table_length = 0;
} }
}
/**
* ufshcd_map_sg - Map scatter-gather list to prdt
* @hba: per adapter instance
* @lrbp: pointer to local reference block
*
* Returns 0 in case of success, non-zero value in case of failure
*/
static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
{
struct scsi_cmnd *cmd = lrbp->cmd;
int sg_segments = scsi_dma_map(cmd);
if (sg_segments < 0)
return sg_segments;
ufshcd_sgl_to_prdt(hba, lrbp, sg_segments, scsi_sglist(cmd));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment