Commit 040cd232 authored by Boaz Harrosh's avatar Boaz Harrosh Committed by James Bottomley

[SCSI] nsp_cs: convert to data accessors and !use_sg cleanup

  - use scsi data accessors
  - cleanup !use_sg code paths
  - TODO: use next_sg() for Jens's sglist branch. Look for 2
    places with "SCp.buffer++"
Signed-off-by: default avatarBoaz Harrosh <bharrosh@panasas.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 73d2cb16
...@@ -135,6 +135,11 @@ static nsp_hw_data nsp_data_base; /* attach <-> detect glue */ ...@@ -135,6 +135,11 @@ static nsp_hw_data nsp_data_base; /* attach <-> detect glue */
#define NSP_DEBUG_BUF_LEN 150 #define NSP_DEBUG_BUF_LEN 150
static inline void nsp_inc_resid(struct scsi_cmnd *SCpnt, int residInc)
{
scsi_set_resid(SCpnt, scsi_get_resid(SCpnt) + residInc);
}
static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ...) static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ...)
{ {
va_list args; va_list args;
...@@ -192,8 +197,10 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt, ...@@ -192,8 +197,10 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
#endif #endif
nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata; nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "SCpnt=0x%p target=%d lun=%d buff=0x%p bufflen=%d use_sg=%d", nsp_dbg(NSP_DEBUG_QUEUECOMMAND,
SCpnt, target, SCpnt->device->lun, SCpnt->request_buffer, SCpnt->request_bufflen, SCpnt->use_sg); "SCpnt=0x%p target=%d lun=%d sglist=0x%p bufflen=%d sg_count=%d",
SCpnt, target, SCpnt->device->lun, scsi_sglist(SCpnt),
scsi_bufflen(SCpnt), scsi_sg_count(SCpnt));
//nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "before CurrentSC=0x%p", data->CurrentSC); //nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "before CurrentSC=0x%p", data->CurrentSC);
SCpnt->scsi_done = done; SCpnt->scsi_done = done;
...@@ -225,7 +232,7 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt, ...@@ -225,7 +232,7 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
SCpnt->SCp.have_data_in = IO_UNKNOWN; SCpnt->SCp.have_data_in = IO_UNKNOWN;
SCpnt->SCp.sent_command = 0; SCpnt->SCp.sent_command = 0;
SCpnt->SCp.phase = PH_UNDETERMINED; SCpnt->SCp.phase = PH_UNDETERMINED;
SCpnt->resid = SCpnt->request_bufflen; scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
/* setup scratch area /* setup scratch area
SCp.ptr : buffer pointer SCp.ptr : buffer pointer
...@@ -233,14 +240,14 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt, ...@@ -233,14 +240,14 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
SCp.buffer : next buffer SCp.buffer : next buffer
SCp.buffers_residual : left buffers in list SCp.buffers_residual : left buffers in list
SCp.phase : current state of the command */ SCp.phase : current state of the command */
if (SCpnt->use_sg) { if (scsi_bufflen(SCpnt)) {
SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer; SCpnt->SCp.buffer = scsi_sglist(SCpnt);
SCpnt->SCp.ptr = BUFFER_ADDR; SCpnt->SCp.ptr = BUFFER_ADDR;
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
} else { } else {
SCpnt->SCp.ptr = (char *) SCpnt->request_buffer; SCpnt->SCp.ptr = NULL;
SCpnt->SCp.this_residual = SCpnt->request_bufflen; SCpnt->SCp.this_residual = 0;
SCpnt->SCp.buffer = NULL; SCpnt->SCp.buffer = NULL;
SCpnt->SCp.buffers_residual = 0; SCpnt->SCp.buffers_residual = 0;
} }
...@@ -721,7 +728,9 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt) ...@@ -721,7 +728,9 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
ocount = data->FifoCount; ocount = data->FifoCount;
nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d", nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d",
SCpnt, SCpnt->resid, ocount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual, SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual); SCpnt, scsi_get_resid(SCpnt), ocount, SCpnt->SCp.ptr,
SCpnt->SCp.this_residual, SCpnt->SCp.buffer,
SCpnt->SCp.buffers_residual);
time_out = 1000; time_out = 1000;
...@@ -771,7 +780,7 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt) ...@@ -771,7 +780,7 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
return; return;
} }
SCpnt->resid -= res; nsp_inc_resid(SCpnt, -res);
SCpnt->SCp.ptr += res; SCpnt->SCp.ptr += res;
SCpnt->SCp.this_residual -= res; SCpnt->SCp.this_residual -= res;
ocount += res; ocount += res;
...@@ -795,10 +804,12 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt) ...@@ -795,10 +804,12 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
if (time_out == 0) { if (time_out == 0) {
nsp_msg(KERN_DEBUG, "pio read timeout resid=%d this_residual=%d buffers_residual=%d", nsp_msg(KERN_DEBUG, "pio read timeout resid=%d this_residual=%d buffers_residual=%d",
SCpnt->resid, SCpnt->SCp.this_residual, SCpnt->SCp.buffers_residual); scsi_get_resid(SCpnt), SCpnt->SCp.this_residual,
SCpnt->SCp.buffers_residual);
} }
nsp_dbg(NSP_DEBUG_DATA_IO, "read ocount=0x%x", ocount); nsp_dbg(NSP_DEBUG_DATA_IO, "read ocount=0x%x", ocount);
nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId, SCpnt->resid); nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId,
scsi_get_resid(SCpnt));
} }
/* /*
...@@ -816,7 +827,9 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt) ...@@ -816,7 +827,9 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt)
ocount = data->FifoCount; ocount = data->FifoCount;
nsp_dbg(NSP_DEBUG_DATA_IO, "in fifocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d resid=0x%x", nsp_dbg(NSP_DEBUG_DATA_IO, "in fifocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d resid=0x%x",
data->FifoCount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual, SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual, SCpnt->resid); data->FifoCount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual,
SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual,
scsi_get_resid(SCpnt));
time_out = 1000; time_out = 1000;
...@@ -830,7 +843,7 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt) ...@@ -830,7 +843,7 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt)
nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x, res=%d\n", stat, res); nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x, res=%d\n", stat, res);
/* Put back pointer */ /* Put back pointer */
SCpnt->resid += res; nsp_inc_resid(SCpnt, res);
SCpnt->SCp.ptr -= res; SCpnt->SCp.ptr -= res;
SCpnt->SCp.this_residual += res; SCpnt->SCp.this_residual += res;
ocount -= res; ocount -= res;
...@@ -866,7 +879,7 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt) ...@@ -866,7 +879,7 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt)
break; break;
} }
SCpnt->resid -= res; nsp_inc_resid(SCpnt, -res);
SCpnt->SCp.ptr += res; SCpnt->SCp.ptr += res;
SCpnt->SCp.this_residual -= res; SCpnt->SCp.this_residual -= res;
ocount += res; ocount += res;
...@@ -886,10 +899,12 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt) ...@@ -886,10 +899,12 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt)
data->FifoCount = ocount; data->FifoCount = ocount;
if (time_out == 0) { if (time_out == 0) {
nsp_msg(KERN_DEBUG, "pio write timeout resid=0x%x", SCpnt->resid); nsp_msg(KERN_DEBUG, "pio write timeout resid=0x%x",
scsi_get_resid(SCpnt));
} }
nsp_dbg(NSP_DEBUG_DATA_IO, "write ocount=0x%x", ocount); nsp_dbg(NSP_DEBUG_DATA_IO, "write ocount=0x%x", ocount);
nsp_dbg(NSP_DEBUG_DATA_IO, "w cmd=%d resid=0x%x\n", data->CmdId, SCpnt->resid); nsp_dbg(NSP_DEBUG_DATA_IO, "w cmd=%d resid=0x%x\n", data->CmdId,
scsi_get_resid(SCpnt));
} }
#undef RFIFO_CRIT #undef RFIFO_CRIT
#undef WFIFO_CRIT #undef WFIFO_CRIT
...@@ -911,9 +926,8 @@ static int nsp_nexus(struct scsi_cmnd *SCpnt) ...@@ -911,9 +926,8 @@ static int nsp_nexus(struct scsi_cmnd *SCpnt)
nsp_index_write(base, SYNCREG, sync->SyncRegister); nsp_index_write(base, SYNCREG, sync->SyncRegister);
nsp_index_write(base, ACKWIDTH, sync->AckWidth); nsp_index_write(base, ACKWIDTH, sync->AckWidth);
if (SCpnt->use_sg == 0 || if (scsi_get_resid(SCpnt) % 4 != 0 ||
SCpnt->resid % 4 != 0 || scsi_get_resid(SCpnt) <= PAGE_SIZE ) {
SCpnt->resid <= PAGE_SIZE ) {
data->TransferMode = MODE_IO8; data->TransferMode = MODE_IO8;
} else if (nsp_burst_mode == BURST_MEM32) { } else if (nsp_burst_mode == BURST_MEM32) {
data->TransferMode = MODE_MEM32; data->TransferMode = MODE_MEM32;
......
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