Skip to content

Commit

Permalink
Merge branch '5.3/scsi-sg' into scsi-next
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkpetersen committed Jun 27, 2019
2 parents baf23ed + 3e99b3b commit 893ca25
Show file tree
Hide file tree
Showing 26 changed files with 205 additions and 154 deletions.
7 changes: 4 additions & 3 deletions drivers/nvme/host/fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,8 @@ nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq,

freq->sg_table.sgl = freq->first_sgl;
ret = sg_alloc_table_chained(&freq->sg_table,
blk_rq_nr_phys_segments(rq), freq->sg_table.sgl);
blk_rq_nr_phys_segments(rq), freq->sg_table.sgl,
SG_CHUNK_SIZE);
if (ret)
return -ENOMEM;

Expand All @@ -2122,7 +2123,7 @@ nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq,
freq->sg_cnt = fc_dma_map_sg(ctrl->lport->dev, freq->sg_table.sgl,
op->nents, dir);
if (unlikely(freq->sg_cnt <= 0)) {
sg_free_table_chained(&freq->sg_table, true);
sg_free_table_chained(&freq->sg_table, SG_CHUNK_SIZE);
freq->sg_cnt = 0;
return -EFAULT;
}
Expand All @@ -2148,7 +2149,7 @@ nvme_fc_unmap_data(struct nvme_fc_ctrl *ctrl, struct request *rq,

nvme_cleanup_cmd(rq);

sg_free_table_chained(&freq->sg_table, true);
sg_free_table_chained(&freq->sg_table, SG_CHUNK_SIZE);

freq->sg_cnt = 0;
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/nvme/host/rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ static void nvme_rdma_unmap_data(struct nvme_rdma_queue *queue,
WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE);

nvme_cleanup_cmd(rq);
sg_free_table_chained(&req->sg_table, true);
sg_free_table_chained(&req->sg_table, SG_CHUNK_SIZE);
}

static int nvme_rdma_set_sg_null(struct nvme_command *c)
Expand Down Expand Up @@ -1248,7 +1248,8 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue,

req->sg_table.sgl = req->first_sgl;
ret = sg_alloc_table_chained(&req->sg_table,
blk_rq_nr_phys_segments(rq), req->sg_table.sgl);
blk_rq_nr_phys_segments(rq), req->sg_table.sgl,
SG_CHUNK_SIZE);
if (ret)
return -ENOMEM;

Expand Down Expand Up @@ -1288,7 +1289,7 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue,
req->nents, rq_data_dir(rq) ==
WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
out_free_table:
sg_free_table_chained(&req->sg_table, true);
sg_free_table_chained(&req->sg_table, SG_CHUNK_SIZE);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/nvme/target/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void nvme_loop_complete_rq(struct request *req)
struct nvme_loop_iod *iod = blk_mq_rq_to_pdu(req);

nvme_cleanup_cmd(req);
sg_free_table_chained(&iod->sg_table, true);
sg_free_table_chained(&iod->sg_table, SG_CHUNK_SIZE);
nvme_complete_rq(req);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
iod->sg_table.sgl = iod->first_sgl;
if (sg_alloc_table_chained(&iod->sg_table,
blk_rq_nr_phys_segments(req),
iod->sg_table.sgl))
iod->sg_table.sgl, SG_CHUNK_SIZE))
return BLK_STS_RESOURCE;

iod->req.sg = iod->sg_table.sgl;
Expand Down
4 changes: 2 additions & 2 deletions drivers/s390/scsi/zfcp_fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
{
int i;

for (i = 0; i < count; i++, sg++)
for (i = 0; i < count; i++, sg = sg_next(sg))
if (sg)
free_page((unsigned long) sg_virt(sg));
else
Expand All @@ -641,7 +641,7 @@ static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
int i;

sg_init_table(sg, count);
for (i = 0; i < count; i++, sg++) {
for (i = 0; i < count; i++, sg = sg_next(sg)) {
addr = (void *) get_zeroed_page(GFP_KERNEL);
if (!addr) {
zfcp_fc_sg_free_table(sg, i);
Expand Down
41 changes: 18 additions & 23 deletions drivers/scsi/NCR5380.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)

if (scsi_bufflen(cmd)) {
cmd->SCp.buffer = scsi_sglist(cmd);
cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
cmd->SCp.this_residual = cmd->SCp.buffer->length;
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
cmd->SCp.ptr = NULL;
cmd->SCp.this_residual = 0;
}
Expand All @@ -163,6 +161,17 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
cmd->SCp.Message = 0;
}

static inline void advance_sg_buffer(struct scsi_cmnd *cmd)
{
struct scatterlist *s = cmd->SCp.buffer;

if (!cmd->SCp.this_residual && s && !sg_is_last(s)) {
cmd->SCp.buffer = sg_next(s);
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
cmd->SCp.this_residual = cmd->SCp.buffer->length;
}
}

/**
* NCR5380_poll_politely2 - wait for two chip register values
* @hostdata: host private data
Expand Down Expand Up @@ -1670,12 +1679,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
sun3_dma_setup_done != cmd) {
int count;

if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
++cmd->SCp.buffer;
--cmd->SCp.buffers_residual;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
}
advance_sg_buffer(cmd);

count = sun3scsi_dma_xfer_len(hostdata, cmd);

Expand Down Expand Up @@ -1725,15 +1729,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
* scatter-gather list, move onto the next one.
*/

if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
++cmd->SCp.buffer;
--cmd->SCp.buffers_residual;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
dsprintk(NDEBUG_INFORMATION, instance, "%d bytes and %d buffers left\n",
cmd->SCp.this_residual,
cmd->SCp.buffers_residual);
}
advance_sg_buffer(cmd);
dsprintk(NDEBUG_INFORMATION, instance,
"this residual %d, sg ents %d\n",
cmd->SCp.this_residual,
sg_nents(cmd->SCp.buffer));

/*
* The preferred transfer method is going to be
Expand Down Expand Up @@ -2126,12 +2126,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
if (sun3_dma_setup_done != tmp) {
int count;

if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
++tmp->SCp.buffer;
--tmp->SCp.buffers_residual;
tmp->SCp.this_residual = tmp->SCp.buffer->length;
tmp->SCp.ptr = sg_virt(tmp->SCp.buffer);
}
advance_sg_buffer(tmp);

count = sun3scsi_dma_xfer_len(hostdata, tmp);

Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/advansys.c
Original file line number Diff line number Diff line change
Expand Up @@ -7714,7 +7714,7 @@ adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
return ADV_SUCCESS;
}
slp++;
slp = sg_next(slp);
}
sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
prev_sg_block = sg_block;
Expand Down
46 changes: 23 additions & 23 deletions drivers/scsi/aha152x.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,21 +948,18 @@ static int aha152x_internal_queue(struct scsi_cmnd *SCpnt,
SCp.ptr : buffer pointer
SCp.this_residual : buffer length
SCp.buffer : next buffer
SCp.buffers_residual : left buffers in list
SCp.phase : current state of the command */

if ((phase & resetting) || !scsi_sglist(SCpnt)) {
SCpnt->SCp.ptr = NULL;
SCpnt->SCp.this_residual = 0;
scsi_set_resid(SCpnt, 0);
SCpnt->SCp.buffer = NULL;
SCpnt->SCp.buffers_residual = 0;
} else {
scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
SCpnt->SCp.buffer = scsi_sglist(SCpnt);
SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer);
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
}

DO_LOCK(flags);
Expand Down Expand Up @@ -2030,10 +2027,9 @@ static void datai_run(struct Scsi_Host *shpnt)
}

if (CURRENT_SC->SCp.this_residual == 0 &&
CURRENT_SC->SCp.buffers_residual > 0) {
!sg_is_last(CURRENT_SC->SCp.buffer)) {
/* advance to next buffer */
CURRENT_SC->SCp.buffers_residual--;
CURRENT_SC->SCp.buffer++;
CURRENT_SC->SCp.buffer = sg_next(CURRENT_SC->SCp.buffer);
CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
}
Expand Down Expand Up @@ -2136,10 +2132,10 @@ static void datao_run(struct Scsi_Host *shpnt)
CMD_INC_RESID(CURRENT_SC, -2 * data_count);
}

if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
if (CURRENT_SC->SCp.this_residual == 0 &&
!sg_is_last(CURRENT_SC->SCp.buffer)) {
/* advance to next buffer */
CURRENT_SC->SCp.buffers_residual--;
CURRENT_SC->SCp.buffer++;
CURRENT_SC->SCp.buffer = sg_next(CURRENT_SC->SCp.buffer);
CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
}
Expand All @@ -2158,22 +2154,26 @@ static void datao_run(struct Scsi_Host *shpnt)
static void datao_end(struct Scsi_Host *shpnt)
{
if(TESTLO(DMASTAT, DFIFOEMP)) {
int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) -
GETSTCNT();
u32 datao_cnt = GETSTCNT();
int datao_out = DATA_LEN - scsi_get_resid(CURRENT_SC);
int done;
struct scatterlist *sg = scsi_sglist(CURRENT_SC);

CMD_INC_RESID(CURRENT_SC, data_count);
CMD_INC_RESID(CURRENT_SC, datao_out - datao_cnt);

data_count -= CURRENT_SC->SCp.ptr -
SG_ADDRESS(CURRENT_SC->SCp.buffer);
while(data_count>0) {
CURRENT_SC->SCp.buffer--;
CURRENT_SC->SCp.buffers_residual++;
data_count -= CURRENT_SC->SCp.buffer->length;
done = scsi_bufflen(CURRENT_SC) - scsi_get_resid(CURRENT_SC);
/* Locate the first SG entry not yet sent */
while (done > 0 && !sg_is_last(sg)) {
if (done < sg->length)
break;
done -= sg->length;
sg = sg_next(sg);
}
CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) -
data_count;
CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length +
data_count;

CURRENT_SC->SCp.buffer = sg;
CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) + done;
CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length -
done;
}

SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
Expand Down Expand Up @@ -2501,7 +2501,7 @@ static void get_command(struct seq_file *m, struct scsi_cmnd * ptr)

seq_printf(m, "); resid=%d; residual=%d; buffers=%d; phase |",
scsi_get_resid(ptr), ptr->SCp.this_residual,
ptr->SCp.buffers_residual);
sg_nents(ptr->SCp.buffer) - 1);

if (ptr->SCp.phase & not_issued)
seq_puts(m, "not issued|");
Expand Down
20 changes: 13 additions & 7 deletions drivers/scsi/esp_scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd);
struct scatterlist *sg = scsi_sglist(cmd);
int total = 0, i;
struct scatterlist *s;

if (cmd->sc_data_direction == DMA_NONE)
return;
Expand All @@ -380,16 +381,18 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
* a dma address, so perform an identity mapping.
*/
spriv->num_sg = scsi_sg_count(cmd);
for (i = 0; i < spriv->num_sg; i++) {
sg[i].dma_address = (uintptr_t)sg_virt(&sg[i]);
total += sg_dma_len(&sg[i]);

scsi_for_each_sg(cmd, s, spriv->num_sg, i) {
s->dma_address = (uintptr_t)sg_virt(s);
total += sg_dma_len(s);
}
} else {
spriv->num_sg = scsi_dma_map(cmd);
for (i = 0; i < spriv->num_sg; i++)
total += sg_dma_len(&sg[i]);
scsi_for_each_sg(cmd, s, spriv->num_sg, i)
total += sg_dma_len(s);
}
spriv->cur_residue = sg_dma_len(sg);
spriv->prv_sg = NULL;
spriv->cur_sg = sg;
spriv->tot_residue = total;
}
Expand Down Expand Up @@ -443,7 +446,8 @@ static void esp_advance_dma(struct esp *esp, struct esp_cmd_entry *ent,
p->tot_residue = 0;
}
if (!p->cur_residue && p->tot_residue) {
p->cur_sg++;
p->prv_sg = p->cur_sg;
p->cur_sg = sg_next(p->cur_sg);
p->cur_residue = sg_dma_len(p->cur_sg);
}
}
Expand All @@ -464,6 +468,7 @@ static void esp_save_pointers(struct esp *esp, struct esp_cmd_entry *ent)
return;
}
ent->saved_cur_residue = spriv->cur_residue;
ent->saved_prv_sg = spriv->prv_sg;
ent->saved_cur_sg = spriv->cur_sg;
ent->saved_tot_residue = spriv->tot_residue;
}
Expand All @@ -478,6 +483,7 @@ static void esp_restore_pointers(struct esp *esp, struct esp_cmd_entry *ent)
return;
}
spriv->cur_residue = ent->saved_cur_residue;
spriv->prv_sg = ent->saved_prv_sg;
spriv->cur_sg = ent->saved_cur_sg;
spriv->tot_residue = ent->saved_tot_residue;
}
Expand Down Expand Up @@ -1646,7 +1652,7 @@ static int esp_msgin_process(struct esp *esp)
spriv = ESP_CMD_PRIV(ent->cmd);

if (spriv->cur_residue == sg_dma_len(spriv->cur_sg)) {
spriv->cur_sg--;
spriv->cur_sg = spriv->prv_sg;
spriv->cur_residue = 1;
} else
spriv->cur_residue++;
Expand Down
2 changes: 2 additions & 0 deletions drivers/scsi/esp_scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
struct esp_cmd_priv {
int num_sg;
int cur_residue;
struct scatterlist *prv_sg;
struct scatterlist *cur_sg;
int tot_residue;
};
Expand All @@ -273,6 +274,7 @@ struct esp_cmd_entry {
struct scsi_cmnd *cmd;

unsigned int saved_cur_residue;
struct scatterlist *saved_prv_sg;
struct scatterlist *saved_cur_sg;
unsigned int saved_tot_residue;

Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/imm.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ static int imm_completion(struct scsi_cmnd *cmd)
if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
/* if scatter/gather, advance to the next segment */
if (cmd->SCp.buffers_residual--) {
cmd->SCp.buffer++;
cmd->SCp.buffer = sg_next(cmd->SCp.buffer);
cmd->SCp.this_residual =
cmd->SCp.buffer->length;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
Expand Down
Loading

0 comments on commit 893ca25

Please sign in to comment.