aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/iscsi_tcp.c
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2007-06-14 09:13:17 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-06-17 17:01:55 -0400
commit1c13899154f6f93e8c9ff3e981a90d5f21df2d6b (patch)
tree0287449d5e4da4fb8824e49f5cd25c4dbfcc3bac /drivers/scsi/iscsi_tcp.c
parentd36b113eea2918ce1badf277af9fc64311609ca2 (diff)
[SCSI] iscsi_tcp: convert to use the data buffer accessors
- remove the unnecessary map_single path. - convert to use the new accessors for the sg lists and the parameters. TODO: use scsi_for_each_sg(). Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Acked-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/iscsi_tcp.c')
-rw-r--r--drivers/scsi/iscsi_tcp.c117
1 files changed, 38 insertions, 79 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index d5a6527b3b3d..aebcd5fcdc55 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -237,10 +237,10 @@ iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
237 tcp_ctask->exp_datasn++; 237 tcp_ctask->exp_datasn++;
238 238
239 tcp_ctask->data_offset = be32_to_cpu(rhdr->offset); 239 tcp_ctask->data_offset = be32_to_cpu(rhdr->offset);
240 if (tcp_ctask->data_offset + tcp_conn->in.datalen > sc->request_bufflen) { 240 if (tcp_ctask->data_offset + tcp_conn->in.datalen > scsi_bufflen(sc)) {
241 debug_tcp("%s: data_offset(%d) + data_len(%d) > total_length_in(%d)\n", 241 debug_tcp("%s: data_offset(%d) + data_len(%d) > total_length_in(%d)\n",
242 __FUNCTION__, tcp_ctask->data_offset, 242 __FUNCTION__, tcp_ctask->data_offset,
243 tcp_conn->in.datalen, sc->request_bufflen); 243 tcp_conn->in.datalen, scsi_bufflen(sc));
244 return ISCSI_ERR_DATA_OFFSET; 244 return ISCSI_ERR_DATA_OFFSET;
245 } 245 }
246 246
@@ -250,14 +250,14 @@ iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
250 int res_count = be32_to_cpu(rhdr->residual_count); 250 int res_count = be32_to_cpu(rhdr->residual_count);
251 251
252 if (res_count > 0 && 252 if (res_count > 0 &&
253 res_count <= sc->request_bufflen) { 253 res_count <= scsi_bufflen(sc)) {
254 sc->resid = res_count; 254 scsi_set_resid(sc, res_count);
255 sc->result = (DID_OK << 16) | rhdr->cmd_status; 255 sc->result = (DID_OK << 16) | rhdr->cmd_status;
256 } else 256 } else
257 sc->result = (DID_BAD_TARGET << 16) | 257 sc->result = (DID_BAD_TARGET << 16) |
258 rhdr->cmd_status; 258 rhdr->cmd_status;
259 } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) { 259 } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) {
260 sc->resid = be32_to_cpu(rhdr->residual_count); 260 scsi_set_resid(sc, be32_to_cpu(rhdr->residual_count));
261 sc->result = (DID_OK << 16) | rhdr->cmd_status; 261 sc->result = (DID_OK << 16) | rhdr->cmd_status;
262 } else 262 } else
263 sc->result = (DID_OK << 16) | rhdr->cmd_status; 263 sc->result = (DID_OK << 16) | rhdr->cmd_status;
@@ -285,6 +285,8 @@ iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
285{ 285{
286 struct iscsi_data *hdr; 286 struct iscsi_data *hdr;
287 struct scsi_cmnd *sc = ctask->sc; 287 struct scsi_cmnd *sc = ctask->sc;
288 int i, sg_count = 0;
289 struct scatterlist *sg;
288 290
289 hdr = &r2t->dtask.hdr; 291 hdr = &r2t->dtask.hdr;
290 memset(hdr, 0, sizeof(struct iscsi_data)); 292 memset(hdr, 0, sizeof(struct iscsi_data));
@@ -312,39 +314,30 @@ iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
312 iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr, 314 iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr,
313 sizeof(struct iscsi_hdr)); 315 sizeof(struct iscsi_hdr));
314 316
315 if (sc->use_sg) { 317 sg = scsi_sglist(sc);
316 int i, sg_count = 0; 318 r2t->sg = NULL;
317 struct scatterlist *sg = sc->request_buffer; 319 for (i = 0; i < scsi_sg_count(sc); i++, sg += 1) {
318 320 /* FIXME: prefetch ? */
319 r2t->sg = NULL; 321 if (sg_count + sg->length > r2t->data_offset) {
320 for (i = 0; i < sc->use_sg; i++, sg += 1) { 322 int page_offset;
321 /* FIXME: prefetch ? */
322 if (sg_count + sg->length > r2t->data_offset) {
323 int page_offset;
324 323
325 /* sg page found! */ 324 /* sg page found! */
326 325
327 /* offset within this page */ 326 /* offset within this page */
328 page_offset = r2t->data_offset - sg_count; 327 page_offset = r2t->data_offset - sg_count;
329 328
330 /* fill in this buffer */ 329 /* fill in this buffer */
331 iscsi_buf_init_sg(&r2t->sendbuf, sg); 330 iscsi_buf_init_sg(&r2t->sendbuf, sg);
332 r2t->sendbuf.sg.offset += page_offset; 331 r2t->sendbuf.sg.offset += page_offset;
333 r2t->sendbuf.sg.length -= page_offset; 332 r2t->sendbuf.sg.length -= page_offset;
334 333
335 /* xmit logic will continue with next one */ 334 /* xmit logic will continue with next one */
336 r2t->sg = sg + 1; 335 r2t->sg = sg + 1;
337 break; 336 break;
338 }
339 sg_count += sg->length;
340 } 337 }
341 BUG_ON(r2t->sg == NULL); 338 sg_count += sg->length;
342 } else {
343 iscsi_buf_init_iov(&r2t->sendbuf,
344 (char*)sc->request_buffer + r2t->data_offset,
345 r2t->data_count);
346 r2t->sg = NULL;
347 } 339 }
340 BUG_ON(r2t->sg == NULL);
348} 341}
349 342
350/** 343/**
@@ -404,11 +397,11 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
404 r2t->data_length, session->max_burst); 397 r2t->data_length, session->max_burst);
405 398
406 r2t->data_offset = be32_to_cpu(rhdr->data_offset); 399 r2t->data_offset = be32_to_cpu(rhdr->data_offset);
407 if (r2t->data_offset + r2t->data_length > ctask->sc->request_bufflen) { 400 if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) {
408 spin_unlock(&session->lock); 401 spin_unlock(&session->lock);
409 printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at " 402 printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at "
410 "offset %u and total length %d\n", r2t->data_length, 403 "offset %u and total length %d\n", r2t->data_length,
411 r2t->data_offset, ctask->sc->request_bufflen); 404 r2t->data_offset, scsi_bufflen(ctask->sc));
412 return ISCSI_ERR_DATALEN; 405 return ISCSI_ERR_DATALEN;
413 } 406 }
414 407
@@ -612,7 +605,7 @@ iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask,
612 size, tcp_conn->in.offset, tcp_conn->in.copied); 605 size, tcp_conn->in.offset, tcp_conn->in.copied);
613 606
614 BUG_ON(size <= 0); 607 BUG_ON(size <= 0);
615 BUG_ON(tcp_ctask->sent + size > ctask->sc->request_bufflen); 608 BUG_ON(tcp_ctask->sent + size > scsi_bufflen(ctask->sc));
616 609
617 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset, 610 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset,
618 (char*)buf + (offset + tcp_conn->data_copied), size); 611 (char*)buf + (offset + tcp_conn->data_copied), size);
@@ -710,25 +703,8 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
710 703
711 BUG_ON((void*)ctask != sc->SCp.ptr); 704 BUG_ON((void*)ctask != sc->SCp.ptr);
712 705
713 /*
714 * copying Data-In into the Scsi_Cmnd
715 */
716 if (!sc->use_sg) {
717 i = ctask->data_count;
718 rc = iscsi_ctask_copy(tcp_conn, ctask, sc->request_buffer,
719 sc->request_bufflen,
720 tcp_ctask->data_offset);
721 if (rc == -EAGAIN)
722 return rc;
723 if (conn->datadgst_en)
724 iscsi_recv_digest_update(tcp_conn, sc->request_buffer,
725 i);
726 rc = 0;
727 goto done;
728 }
729
730 offset = tcp_ctask->data_offset; 706 offset = tcp_ctask->data_offset;
731 sg = sc->request_buffer; 707 sg = scsi_sglist(sc);
732 708
733 if (tcp_ctask->data_offset) 709 if (tcp_ctask->data_offset)
734 for (i = 0; i < tcp_ctask->sg_count; i++) 710 for (i = 0; i < tcp_ctask->sg_count; i++)
@@ -737,7 +713,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
737 if (offset < 0) 713 if (offset < 0)
738 offset = 0; 714 offset = 0;
739 715
740 for (i = tcp_ctask->sg_count; i < sc->use_sg; i++) { 716 for (i = tcp_ctask->sg_count; i < scsi_sg_count(sc); i++) {
741 char *dest; 717 char *dest;
742 718
743 dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0); 719 dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0);
@@ -782,7 +758,6 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
782 } 758 }
783 BUG_ON(ctask->data_count); 759 BUG_ON(ctask->data_count);
784 760
785done:
786 /* check for non-exceptional status */ 761 /* check for non-exceptional status */
787 if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) { 762 if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) {
788 debug_scsi("done [sc %lx res %d itt 0x%x flags 0x%x]\n", 763 debug_scsi("done [sc %lx res %d itt 0x%x flags 0x%x]\n",
@@ -1241,7 +1216,6 @@ iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1241 struct iscsi_r2t_info *r2t, int left) 1216 struct iscsi_r2t_info *r2t, int left)
1242{ 1217{
1243 struct iscsi_data *hdr; 1218 struct iscsi_data *hdr;
1244 struct scsi_cmnd *sc = ctask->sc;
1245 int new_offset; 1219 int new_offset;
1246 1220
1247 hdr = &r2t->dtask.hdr; 1221 hdr = &r2t->dtask.hdr;
@@ -1271,15 +1245,8 @@ iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1271 if (iscsi_buf_left(&r2t->sendbuf)) 1245 if (iscsi_buf_left(&r2t->sendbuf))
1272 return; 1246 return;
1273 1247
1274 if (sc->use_sg) { 1248 iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg);
1275 iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg); 1249 r2t->sg += 1;
1276 r2t->sg += 1;
1277 } else {
1278 iscsi_buf_init_iov(&r2t->sendbuf,
1279 (char*)sc->request_buffer + new_offset,
1280 r2t->data_count);
1281 r2t->sg = NULL;
1282 }
1283} 1250}
1284 1251
1285static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask, 1252static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask,
@@ -1408,23 +1375,15 @@ iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1408 tcp_ctask->exp_datasn = 0; 1375 tcp_ctask->exp_datasn = 0;
1409 1376
1410 if (sc->sc_data_direction == DMA_TO_DEVICE) { 1377 if (sc->sc_data_direction == DMA_TO_DEVICE) {
1411 if (sc->use_sg) { 1378 struct scatterlist *sg = scsi_sglist(sc);
1412 struct scatterlist *sg = sc->request_buffer; 1379
1413 1380 iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg);
1414 iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg); 1381 tcp_ctask->sg = sg + 1;
1415 tcp_ctask->sg = sg + 1; 1382 tcp_ctask->bad_sg = sg + scsi_sg_count(sc);
1416 tcp_ctask->bad_sg = sg + sc->use_sg;
1417 } else {
1418 iscsi_buf_init_iov(&tcp_ctask->sendbuf,
1419 sc->request_buffer,
1420 sc->request_bufflen);
1421 tcp_ctask->sg = NULL;
1422 tcp_ctask->bad_sg = NULL;
1423 }
1424 1383
1425 debug_scsi("cmd [itt 0x%x total %d imm_data %d " 1384 debug_scsi("cmd [itt 0x%x total %d imm_data %d "
1426 "unsol count %d, unsol offset %d]\n", 1385 "unsol count %d, unsol offset %d]\n",
1427 ctask->itt, sc->request_bufflen, 1386 ctask->itt, scsi_bufflen(sc),
1428 ctask->imm_count, ctask->unsol_count, 1387 ctask->imm_count, ctask->unsol_count,
1429 ctask->unsol_offset); 1388 ctask->unsol_offset);
1430 } 1389 }