diff options
Diffstat (limited to 'drivers/scsi/iscsi_tcp.c')
-rw-r--r-- | drivers/scsi/iscsi_tcp.c | 606 |
1 files changed, 346 insertions, 260 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index c9a3abf9e7b6..aebcd5fcdc55 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c | |||
@@ -29,14 +29,15 @@ | |||
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | #include <linux/list.h> | 30 | #include <linux/list.h> |
31 | #include <linux/inet.h> | 31 | #include <linux/inet.h> |
32 | #include <linux/file.h> | ||
32 | #include <linux/blkdev.h> | 33 | #include <linux/blkdev.h> |
33 | #include <linux/crypto.h> | 34 | #include <linux/crypto.h> |
34 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
35 | #include <linux/kfifo.h> | 36 | #include <linux/kfifo.h> |
36 | #include <linux/scatterlist.h> | 37 | #include <linux/scatterlist.h> |
37 | #include <linux/mutex.h> | ||
38 | #include <net/tcp.h> | 38 | #include <net/tcp.h> |
39 | #include <scsi/scsi_cmnd.h> | 39 | #include <scsi/scsi_cmnd.h> |
40 | #include <scsi/scsi_device.h> | ||
40 | #include <scsi/scsi_host.h> | 41 | #include <scsi/scsi_host.h> |
41 | #include <scsi/scsi.h> | 42 | #include <scsi/scsi.h> |
42 | #include <scsi/scsi_transport_iscsi.h> | 43 | #include <scsi/scsi_transport_iscsi.h> |
@@ -109,7 +110,7 @@ iscsi_hdr_digest(struct iscsi_conn *conn, struct iscsi_buf *buf, | |||
109 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; | 110 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
110 | 111 | ||
111 | crypto_hash_digest(&tcp_conn->tx_hash, &buf->sg, buf->sg.length, crc); | 112 | crypto_hash_digest(&tcp_conn->tx_hash, &buf->sg, buf->sg.length, crc); |
112 | buf->sg.length = tcp_conn->hdr_size; | 113 | buf->sg.length += sizeof(u32); |
113 | } | 114 | } |
114 | 115 | ||
115 | static inline int | 116 | static inline int |
@@ -211,16 +212,14 @@ iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
211 | static int | 212 | static int |
212 | iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | 213 | iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
213 | { | 214 | { |
214 | int rc; | ||
215 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; | 215 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
216 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; | 216 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
217 | struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)tcp_conn->in.hdr; | 217 | struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)tcp_conn->in.hdr; |
218 | struct iscsi_session *session = conn->session; | 218 | struct iscsi_session *session = conn->session; |
219 | struct scsi_cmnd *sc = ctask->sc; | ||
219 | int datasn = be32_to_cpu(rhdr->datasn); | 220 | int datasn = be32_to_cpu(rhdr->datasn); |
220 | 221 | ||
221 | rc = iscsi_check_assign_cmdsn(session, (struct iscsi_nopin*)rhdr); | 222 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); |
222 | if (rc) | ||
223 | return rc; | ||
224 | /* | 223 | /* |
225 | * setup Data-In byte counter (gets decremented..) | 224 | * setup Data-In byte counter (gets decremented..) |
226 | */ | 225 | */ |
@@ -229,31 +228,36 @@ iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
229 | if (tcp_conn->in.datalen == 0) | 228 | if (tcp_conn->in.datalen == 0) |
230 | return 0; | 229 | return 0; |
231 | 230 | ||
232 | if (ctask->datasn != datasn) | 231 | if (tcp_ctask->exp_datasn != datasn) { |
232 | debug_tcp("%s: ctask->exp_datasn(%d) != rhdr->datasn(%d)\n", | ||
233 | __FUNCTION__, tcp_ctask->exp_datasn, datasn); | ||
233 | return ISCSI_ERR_DATASN; | 234 | return ISCSI_ERR_DATASN; |
235 | } | ||
234 | 236 | ||
235 | ctask->datasn++; | 237 | tcp_ctask->exp_datasn++; |
236 | 238 | ||
237 | tcp_ctask->data_offset = be32_to_cpu(rhdr->offset); | 239 | tcp_ctask->data_offset = be32_to_cpu(rhdr->offset); |
238 | if (tcp_ctask->data_offset + tcp_conn->in.datalen > ctask->total_length) | 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", | ||
242 | __FUNCTION__, tcp_ctask->data_offset, | ||
243 | tcp_conn->in.datalen, scsi_bufflen(sc)); | ||
239 | return ISCSI_ERR_DATA_OFFSET; | 244 | return ISCSI_ERR_DATA_OFFSET; |
245 | } | ||
240 | 246 | ||
241 | if (rhdr->flags & ISCSI_FLAG_DATA_STATUS) { | 247 | if (rhdr->flags & ISCSI_FLAG_DATA_STATUS) { |
242 | struct scsi_cmnd *sc = ctask->sc; | ||
243 | |||
244 | conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; | 248 | conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; |
245 | if (rhdr->flags & ISCSI_FLAG_DATA_UNDERFLOW) { | 249 | if (rhdr->flags & ISCSI_FLAG_DATA_UNDERFLOW) { |
246 | int res_count = be32_to_cpu(rhdr->residual_count); | 250 | int res_count = be32_to_cpu(rhdr->residual_count); |
247 | 251 | ||
248 | if (res_count > 0 && | 252 | if (res_count > 0 && |
249 | res_count <= sc->request_bufflen) { | 253 | res_count <= scsi_bufflen(sc)) { |
250 | sc->resid = res_count; | 254 | scsi_set_resid(sc, res_count); |
251 | sc->result = (DID_OK << 16) | rhdr->cmd_status; | 255 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
252 | } else | 256 | } else |
253 | sc->result = (DID_BAD_TARGET << 16) | | 257 | sc->result = (DID_BAD_TARGET << 16) | |
254 | rhdr->cmd_status; | 258 | rhdr->cmd_status; |
255 | } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) { | 259 | } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) { |
256 | sc->resid = be32_to_cpu(rhdr->residual_count); | 260 | scsi_set_resid(sc, be32_to_cpu(rhdr->residual_count)); |
257 | sc->result = (DID_OK << 16) | rhdr->cmd_status; | 261 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
258 | } else | 262 | } else |
259 | sc->result = (DID_OK << 16) | rhdr->cmd_status; | 263 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
@@ -281,6 +285,8 @@ iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, | |||
281 | { | 285 | { |
282 | struct iscsi_data *hdr; | 286 | struct iscsi_data *hdr; |
283 | struct scsi_cmnd *sc = ctask->sc; | 287 | struct scsi_cmnd *sc = ctask->sc; |
288 | int i, sg_count = 0; | ||
289 | struct scatterlist *sg; | ||
284 | 290 | ||
285 | hdr = &r2t->dtask.hdr; | 291 | hdr = &r2t->dtask.hdr; |
286 | memset(hdr, 0, sizeof(struct iscsi_data)); | 292 | memset(hdr, 0, sizeof(struct iscsi_data)); |
@@ -308,39 +314,30 @@ iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, | |||
308 | iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr, | 314 | iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr, |
309 | sizeof(struct iscsi_hdr)); | 315 | sizeof(struct iscsi_hdr)); |
310 | 316 | ||
311 | if (sc->use_sg) { | 317 | sg = scsi_sglist(sc); |
312 | int i, sg_count = 0; | 318 | r2t->sg = NULL; |
313 | struct scatterlist *sg = sc->request_buffer; | 319 | for (i = 0; i < scsi_sg_count(sc); i++, sg += 1) { |
314 | 320 | /* FIXME: prefetch ? */ | |
315 | r2t->sg = NULL; | 321 | if (sg_count + sg->length > r2t->data_offset) { |
316 | for (i = 0; i < sc->use_sg; i++, sg += 1) { | 322 | int page_offset; |
317 | /* FIXME: prefetch ? */ | ||
318 | if (sg_count + sg->length > r2t->data_offset) { | ||
319 | int page_offset; | ||
320 | 323 | ||
321 | /* sg page found! */ | 324 | /* sg page found! */ |
322 | 325 | ||
323 | /* offset within this page */ | 326 | /* offset within this page */ |
324 | page_offset = r2t->data_offset - sg_count; | 327 | page_offset = r2t->data_offset - sg_count; |
325 | 328 | ||
326 | /* fill in this buffer */ | 329 | /* fill in this buffer */ |
327 | iscsi_buf_init_sg(&r2t->sendbuf, sg); | 330 | iscsi_buf_init_sg(&r2t->sendbuf, sg); |
328 | r2t->sendbuf.sg.offset += page_offset; | 331 | r2t->sendbuf.sg.offset += page_offset; |
329 | r2t->sendbuf.sg.length -= page_offset; | 332 | r2t->sendbuf.sg.length -= page_offset; |
330 | 333 | ||
331 | /* xmit logic will continue with next one */ | 334 | /* xmit logic will continue with next one */ |
332 | r2t->sg = sg + 1; | 335 | r2t->sg = sg + 1; |
333 | break; | 336 | break; |
334 | } | ||
335 | sg_count += sg->length; | ||
336 | } | 337 | } |
337 | BUG_ON(r2t->sg == NULL); | 338 | sg_count += sg->length; |
338 | } else { | ||
339 | iscsi_buf_init_iov(&r2t->sendbuf, | ||
340 | (char*)sc->request_buffer + r2t->data_offset, | ||
341 | r2t->data_count); | ||
342 | r2t->sg = NULL; | ||
343 | } | 339 | } |
340 | BUG_ON(r2t->sg == NULL); | ||
344 | } | 341 | } |
345 | 342 | ||
346 | /** | 343 | /** |
@@ -365,17 +362,16 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
365 | return ISCSI_ERR_DATALEN; | 362 | return ISCSI_ERR_DATALEN; |
366 | } | 363 | } |
367 | 364 | ||
368 | if (tcp_ctask->exp_r2tsn && tcp_ctask->exp_r2tsn != r2tsn) | 365 | if (tcp_ctask->exp_datasn != r2tsn){ |
366 | debug_tcp("%s: ctask->exp_datasn(%d) != rhdr->r2tsn(%d)\n", | ||
367 | __FUNCTION__, tcp_ctask->exp_datasn, r2tsn); | ||
369 | return ISCSI_ERR_R2TSN; | 368 | return ISCSI_ERR_R2TSN; |
370 | 369 | } | |
371 | rc = iscsi_check_assign_cmdsn(session, (struct iscsi_nopin*)rhdr); | ||
372 | if (rc) | ||
373 | return rc; | ||
374 | |||
375 | /* FIXME: use R2TSN to detect missing R2T */ | ||
376 | 370 | ||
377 | /* fill-in new R2T associated with the task */ | 371 | /* fill-in new R2T associated with the task */ |
378 | spin_lock(&session->lock); | 372 | spin_lock(&session->lock); |
373 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); | ||
374 | |||
379 | if (!ctask->sc || ctask->mtask || | 375 | if (!ctask->sc || ctask->mtask || |
380 | session->state != ISCSI_STATE_LOGGED_IN) { | 376 | session->state != ISCSI_STATE_LOGGED_IN) { |
381 | printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in " | 377 | printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in " |
@@ -401,11 +397,11 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
401 | r2t->data_length, session->max_burst); | 397 | r2t->data_length, session->max_burst); |
402 | 398 | ||
403 | r2t->data_offset = be32_to_cpu(rhdr->data_offset); | 399 | r2t->data_offset = be32_to_cpu(rhdr->data_offset); |
404 | if (r2t->data_offset + r2t->data_length > ctask->total_length) { | 400 | if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) { |
405 | spin_unlock(&session->lock); | 401 | spin_unlock(&session->lock); |
406 | 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 " |
407 | "offset %u and total length %d\n", r2t->data_length, | 403 | "offset %u and total length %d\n", r2t->data_length, |
408 | r2t->data_offset, ctask->total_length); | 404 | r2t->data_offset, scsi_bufflen(ctask->sc)); |
409 | return ISCSI_ERR_DATALEN; | 405 | return ISCSI_ERR_DATALEN; |
410 | } | 406 | } |
411 | 407 | ||
@@ -414,9 +410,9 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
414 | 410 | ||
415 | iscsi_solicit_data_init(conn, ctask, r2t); | 411 | iscsi_solicit_data_init(conn, ctask, r2t); |
416 | 412 | ||
417 | tcp_ctask->exp_r2tsn = r2tsn + 1; | 413 | tcp_ctask->exp_datasn = r2tsn + 1; |
418 | __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); | 414 | __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); |
419 | tcp_ctask->xmstate |= XMSTATE_SOL_HDR; | 415 | tcp_ctask->xmstate |= XMSTATE_SOL_HDR_INIT; |
420 | list_move_tail(&ctask->running, &conn->xmitqueue); | 416 | list_move_tail(&ctask->running, &conn->xmitqueue); |
421 | 417 | ||
422 | scsi_queue_work(session->host, &conn->xmitwork); | 418 | scsi_queue_work(session->host, &conn->xmitwork); |
@@ -600,7 +596,7 @@ iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask, | |||
600 | { | 596 | { |
601 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; | 597 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
602 | int buf_left = buf_size - (tcp_conn->data_copied + offset); | 598 | int buf_left = buf_size - (tcp_conn->data_copied + offset); |
603 | int size = min(tcp_conn->in.copy, buf_left); | 599 | unsigned size = min(tcp_conn->in.copy, buf_left); |
604 | int rc; | 600 | int rc; |
605 | 601 | ||
606 | size = min(size, ctask->data_count); | 602 | size = min(size, ctask->data_count); |
@@ -609,7 +605,7 @@ iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask, | |||
609 | size, tcp_conn->in.offset, tcp_conn->in.copied); | 605 | size, tcp_conn->in.offset, tcp_conn->in.copied); |
610 | 606 | ||
611 | BUG_ON(size <= 0); | 607 | BUG_ON(size <= 0); |
612 | BUG_ON(tcp_ctask->sent + size > ctask->total_length); | 608 | BUG_ON(tcp_ctask->sent + size > scsi_bufflen(ctask->sc)); |
613 | 609 | ||
614 | 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, |
615 | (char*)buf + (offset + tcp_conn->data_copied), size); | 611 | (char*)buf + (offset + tcp_conn->data_copied), size); |
@@ -707,25 +703,8 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn) | |||
707 | 703 | ||
708 | BUG_ON((void*)ctask != sc->SCp.ptr); | 704 | BUG_ON((void*)ctask != sc->SCp.ptr); |
709 | 705 | ||
710 | /* | ||
711 | * copying Data-In into the Scsi_Cmnd | ||
712 | */ | ||
713 | if (!sc->use_sg) { | ||
714 | i = ctask->data_count; | ||
715 | rc = iscsi_ctask_copy(tcp_conn, ctask, sc->request_buffer, | ||
716 | sc->request_bufflen, | ||
717 | tcp_ctask->data_offset); | ||
718 | if (rc == -EAGAIN) | ||
719 | return rc; | ||
720 | if (conn->datadgst_en) | ||
721 | iscsi_recv_digest_update(tcp_conn, sc->request_buffer, | ||
722 | i); | ||
723 | rc = 0; | ||
724 | goto done; | ||
725 | } | ||
726 | |||
727 | offset = tcp_ctask->data_offset; | 706 | offset = tcp_ctask->data_offset; |
728 | sg = sc->request_buffer; | 707 | sg = scsi_sglist(sc); |
729 | 708 | ||
730 | if (tcp_ctask->data_offset) | 709 | if (tcp_ctask->data_offset) |
731 | for (i = 0; i < tcp_ctask->sg_count; i++) | 710 | for (i = 0; i < tcp_ctask->sg_count; i++) |
@@ -734,7 +713,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn) | |||
734 | if (offset < 0) | 713 | if (offset < 0) |
735 | offset = 0; | 714 | offset = 0; |
736 | 715 | ||
737 | for (i = tcp_ctask->sg_count; i < sc->use_sg; i++) { | 716 | for (i = tcp_ctask->sg_count; i < scsi_sg_count(sc); i++) { |
738 | char *dest; | 717 | char *dest; |
739 | 718 | ||
740 | dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0); | 719 | dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0); |
@@ -779,7 +758,6 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn) | |||
779 | } | 758 | } |
780 | BUG_ON(ctask->data_count); | 759 | BUG_ON(ctask->data_count); |
781 | 760 | ||
782 | done: | ||
783 | /* check for non-exceptional status */ | 761 | /* check for non-exceptional status */ |
784 | if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) { | 762 | if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) { |
785 | 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", |
@@ -895,11 +873,27 @@ more: | |||
895 | } | 873 | } |
896 | } | 874 | } |
897 | 875 | ||
898 | if (tcp_conn->in_progress == IN_PROGRESS_DDIGEST_RECV) { | 876 | if (tcp_conn->in_progress == IN_PROGRESS_DDIGEST_RECV && |
877 | tcp_conn->in.copy) { | ||
899 | uint32_t recv_digest; | 878 | uint32_t recv_digest; |
900 | 879 | ||
901 | debug_tcp("extra data_recv offset %d copy %d\n", | 880 | debug_tcp("extra data_recv offset %d copy %d\n", |
902 | tcp_conn->in.offset, tcp_conn->in.copy); | 881 | tcp_conn->in.offset, tcp_conn->in.copy); |
882 | |||
883 | if (!tcp_conn->data_copied) { | ||
884 | if (tcp_conn->in.padding) { | ||
885 | debug_tcp("padding -> %d\n", | ||
886 | tcp_conn->in.padding); | ||
887 | memset(pad, 0, tcp_conn->in.padding); | ||
888 | sg_init_one(&sg, pad, tcp_conn->in.padding); | ||
889 | crypto_hash_update(&tcp_conn->rx_hash, | ||
890 | &sg, sg.length); | ||
891 | } | ||
892 | crypto_hash_final(&tcp_conn->rx_hash, | ||
893 | (u8 *) &tcp_conn->in.datadgst); | ||
894 | debug_tcp("rx digest 0x%x\n", tcp_conn->in.datadgst); | ||
895 | } | ||
896 | |||
903 | rc = iscsi_tcp_copy(conn, sizeof(uint32_t)); | 897 | rc = iscsi_tcp_copy(conn, sizeof(uint32_t)); |
904 | if (rc) { | 898 | if (rc) { |
905 | if (rc == -EAGAIN) | 899 | if (rc == -EAGAIN) |
@@ -924,8 +918,7 @@ more: | |||
924 | } | 918 | } |
925 | 919 | ||
926 | if (tcp_conn->in_progress == IN_PROGRESS_DATA_RECV && | 920 | if (tcp_conn->in_progress == IN_PROGRESS_DATA_RECV && |
927 | tcp_conn->in.copy) { | 921 | tcp_conn->in.copy) { |
928 | |||
929 | debug_tcp("data_recv offset %d copy %d\n", | 922 | debug_tcp("data_recv offset %d copy %d\n", |
930 | tcp_conn->in.offset, tcp_conn->in.copy); | 923 | tcp_conn->in.offset, tcp_conn->in.copy); |
931 | 924 | ||
@@ -936,24 +929,32 @@ more: | |||
936 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 929 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
937 | return 0; | 930 | return 0; |
938 | } | 931 | } |
939 | tcp_conn->in.copy -= tcp_conn->in.padding; | 932 | |
940 | tcp_conn->in.offset += tcp_conn->in.padding; | 933 | if (tcp_conn->in.padding) |
941 | if (conn->datadgst_en) { | 934 | tcp_conn->in_progress = IN_PROGRESS_PAD_RECV; |
942 | if (tcp_conn->in.padding) { | 935 | else if (conn->datadgst_en) |
943 | debug_tcp("padding -> %d\n", | ||
944 | tcp_conn->in.padding); | ||
945 | memset(pad, 0, tcp_conn->in.padding); | ||
946 | sg_init_one(&sg, pad, tcp_conn->in.padding); | ||
947 | crypto_hash_update(&tcp_conn->rx_hash, | ||
948 | &sg, sg.length); | ||
949 | } | ||
950 | crypto_hash_final(&tcp_conn->rx_hash, | ||
951 | (u8 *) &tcp_conn->in.datadgst); | ||
952 | debug_tcp("rx digest 0x%x\n", tcp_conn->in.datadgst); | ||
953 | tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV; | 936 | tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV; |
954 | tcp_conn->data_copied = 0; | 937 | else |
955 | } else | 938 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
939 | tcp_conn->data_copied = 0; | ||
940 | } | ||
941 | |||
942 | if (tcp_conn->in_progress == IN_PROGRESS_PAD_RECV && | ||
943 | tcp_conn->in.copy) { | ||
944 | int copylen = min(tcp_conn->in.padding - tcp_conn->data_copied, | ||
945 | tcp_conn->in.copy); | ||
946 | |||
947 | tcp_conn->in.copy -= copylen; | ||
948 | tcp_conn->in.offset += copylen; | ||
949 | tcp_conn->data_copied += copylen; | ||
950 | |||
951 | if (tcp_conn->data_copied != tcp_conn->in.padding) | ||
952 | tcp_conn->in_progress = IN_PROGRESS_PAD_RECV; | ||
953 | else if (conn->datadgst_en) | ||
954 | tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV; | ||
955 | else | ||
956 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; | 956 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
957 | tcp_conn->data_copied = 0; | ||
957 | } | 958 | } |
958 | 959 | ||
959 | debug_tcp("f, processed %d from out of %d padding %d\n", | 960 | debug_tcp("f, processed %d from out of %d padding %d\n", |
@@ -1215,7 +1216,6 @@ iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, | |||
1215 | struct iscsi_r2t_info *r2t, int left) | 1216 | struct iscsi_r2t_info *r2t, int left) |
1216 | { | 1217 | { |
1217 | struct iscsi_data *hdr; | 1218 | struct iscsi_data *hdr; |
1218 | struct scsi_cmnd *sc = ctask->sc; | ||
1219 | int new_offset; | 1219 | int new_offset; |
1220 | 1220 | ||
1221 | hdr = &r2t->dtask.hdr; | 1221 | hdr = &r2t->dtask.hdr; |
@@ -1245,15 +1245,8 @@ iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, | |||
1245 | if (iscsi_buf_left(&r2t->sendbuf)) | 1245 | if (iscsi_buf_left(&r2t->sendbuf)) |
1246 | return; | 1246 | return; |
1247 | 1247 | ||
1248 | if (sc->use_sg) { | 1248 | iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg); |
1249 | iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg); | 1249 | r2t->sg += 1; |
1250 | r2t->sg += 1; | ||
1251 | } else { | ||
1252 | iscsi_buf_init_iov(&r2t->sendbuf, | ||
1253 | (char*)sc->request_buffer + new_offset, | ||
1254 | r2t->data_count); | ||
1255 | r2t->sg = NULL; | ||
1256 | } | ||
1257 | } | 1250 | } |
1258 | 1251 | ||
1259 | static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask, | 1252 | static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask, |
@@ -1277,41 +1270,10 @@ static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask, | |||
1277 | static void | 1270 | static void |
1278 | iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask) | 1271 | iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask) |
1279 | { | 1272 | { |
1280 | struct scsi_cmnd *sc = ctask->sc; | ||
1281 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; | 1273 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
1282 | 1274 | ||
1283 | BUG_ON(__kfifo_len(tcp_ctask->r2tqueue)); | 1275 | BUG_ON(__kfifo_len(tcp_ctask->r2tqueue)); |
1284 | 1276 | tcp_ctask->xmstate = XMSTATE_CMD_HDR_INIT; | |
1285 | tcp_ctask->sent = 0; | ||
1286 | tcp_ctask->sg_count = 0; | ||
1287 | |||
1288 | if (sc->sc_data_direction == DMA_TO_DEVICE) { | ||
1289 | tcp_ctask->xmstate = XMSTATE_W_HDR; | ||
1290 | tcp_ctask->exp_r2tsn = 0; | ||
1291 | BUG_ON(ctask->total_length == 0); | ||
1292 | |||
1293 | if (sc->use_sg) { | ||
1294 | struct scatterlist *sg = sc->request_buffer; | ||
1295 | |||
1296 | iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg); | ||
1297 | tcp_ctask->sg = sg + 1; | ||
1298 | tcp_ctask->bad_sg = sg + sc->use_sg; | ||
1299 | } else { | ||
1300 | iscsi_buf_init_iov(&tcp_ctask->sendbuf, | ||
1301 | sc->request_buffer, | ||
1302 | sc->request_bufflen); | ||
1303 | tcp_ctask->sg = NULL; | ||
1304 | tcp_ctask->bad_sg = NULL; | ||
1305 | } | ||
1306 | debug_scsi("cmd [itt 0x%x total %d imm_data %d " | ||
1307 | "unsol count %d, unsol offset %d]\n", | ||
1308 | ctask->itt, ctask->total_length, ctask->imm_count, | ||
1309 | ctask->unsol_count, ctask->unsol_offset); | ||
1310 | } else | ||
1311 | tcp_ctask->xmstate = XMSTATE_R_HDR; | ||
1312 | |||
1313 | iscsi_buf_init_iov(&tcp_ctask->headbuf, (char*)ctask->hdr, | ||
1314 | sizeof(struct iscsi_hdr)); | ||
1315 | } | 1277 | } |
1316 | 1278 | ||
1317 | /** | 1279 | /** |
@@ -1324,9 +1286,11 @@ iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask) | |||
1324 | * call it again later, or recover. '0' return code means successful | 1286 | * call it again later, or recover. '0' return code means successful |
1325 | * xmit. | 1287 | * xmit. |
1326 | * | 1288 | * |
1327 | * Management xmit state machine consists of two states: | 1289 | * Management xmit state machine consists of these states: |
1328 | * IN_PROGRESS_IMM_HEAD - PDU Header xmit in progress | 1290 | * XMSTATE_IMM_HDR_INIT - calculate digest of PDU Header |
1329 | * IN_PROGRESS_IMM_DATA - PDU Data xmit in progress | 1291 | * XMSTATE_IMM_HDR - PDU Header xmit in progress |
1292 | * XMSTATE_IMM_DATA - PDU Data xmit in progress | ||
1293 | * XMSTATE_IDLE - management PDU is done | ||
1330 | **/ | 1294 | **/ |
1331 | static int | 1295 | static int |
1332 | iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) | 1296 | iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) |
@@ -1337,23 +1301,34 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) | |||
1337 | debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n", | 1301 | debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n", |
1338 | conn->id, tcp_mtask->xmstate, mtask->itt); | 1302 | conn->id, tcp_mtask->xmstate, mtask->itt); |
1339 | 1303 | ||
1340 | if (tcp_mtask->xmstate & XMSTATE_IMM_HDR) { | 1304 | if (tcp_mtask->xmstate & XMSTATE_IMM_HDR_INIT) { |
1341 | tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR; | 1305 | iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr, |
1342 | if (mtask->data_count) | 1306 | sizeof(struct iscsi_hdr)); |
1307 | |||
1308 | if (mtask->data_count) { | ||
1343 | tcp_mtask->xmstate |= XMSTATE_IMM_DATA; | 1309 | tcp_mtask->xmstate |= XMSTATE_IMM_DATA; |
1310 | iscsi_buf_init_iov(&tcp_mtask->sendbuf, | ||
1311 | (char*)mtask->data, | ||
1312 | mtask->data_count); | ||
1313 | } | ||
1314 | |||
1344 | if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE && | 1315 | if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE && |
1345 | conn->stop_stage != STOP_CONN_RECOVER && | 1316 | conn->stop_stage != STOP_CONN_RECOVER && |
1346 | conn->hdrdgst_en) | 1317 | conn->hdrdgst_en) |
1347 | iscsi_hdr_digest(conn, &tcp_mtask->headbuf, | 1318 | iscsi_hdr_digest(conn, &tcp_mtask->headbuf, |
1348 | (u8*)tcp_mtask->hdrext); | 1319 | (u8*)tcp_mtask->hdrext); |
1320 | |||
1321 | tcp_mtask->sent = 0; | ||
1322 | tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR_INIT; | ||
1323 | tcp_mtask->xmstate |= XMSTATE_IMM_HDR; | ||
1324 | } | ||
1325 | |||
1326 | if (tcp_mtask->xmstate & XMSTATE_IMM_HDR) { | ||
1349 | rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf, | 1327 | rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf, |
1350 | mtask->data_count); | 1328 | mtask->data_count); |
1351 | if (rc) { | 1329 | if (rc) |
1352 | tcp_mtask->xmstate |= XMSTATE_IMM_HDR; | ||
1353 | if (mtask->data_count) | ||
1354 | tcp_mtask->xmstate &= ~XMSTATE_IMM_DATA; | ||
1355 | return rc; | 1330 | return rc; |
1356 | } | 1331 | tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR; |
1357 | } | 1332 | } |
1358 | 1333 | ||
1359 | if (tcp_mtask->xmstate & XMSTATE_IMM_DATA) { | 1334 | if (tcp_mtask->xmstate & XMSTATE_IMM_DATA) { |
@@ -1387,55 +1362,67 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) | |||
1387 | return 0; | 1362 | return 0; |
1388 | } | 1363 | } |
1389 | 1364 | ||
1390 | static inline int | 1365 | static int |
1391 | iscsi_send_read_hdr(struct iscsi_conn *conn, | 1366 | iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
1392 | struct iscsi_tcp_cmd_task *tcp_ctask) | ||
1393 | { | 1367 | { |
1394 | int rc; | 1368 | struct scsi_cmnd *sc = ctask->sc; |
1369 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; | ||
1370 | int rc = 0; | ||
1395 | 1371 | ||
1396 | tcp_ctask->xmstate &= ~XMSTATE_R_HDR; | 1372 | if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_INIT) { |
1397 | if (conn->hdrdgst_en) | 1373 | tcp_ctask->sent = 0; |
1398 | iscsi_hdr_digest(conn, &tcp_ctask->headbuf, | 1374 | tcp_ctask->sg_count = 0; |
1399 | (u8*)tcp_ctask->hdrext); | 1375 | tcp_ctask->exp_datasn = 0; |
1400 | rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, 0); | ||
1401 | if (!rc) { | ||
1402 | BUG_ON(tcp_ctask->xmstate != XMSTATE_IDLE); | ||
1403 | return 0; /* wait for Data-In */ | ||
1404 | } | ||
1405 | tcp_ctask->xmstate |= XMSTATE_R_HDR; | ||
1406 | return rc; | ||
1407 | } | ||
1408 | 1376 | ||
1409 | static inline int | 1377 | if (sc->sc_data_direction == DMA_TO_DEVICE) { |
1410 | iscsi_send_write_hdr(struct iscsi_conn *conn, | 1378 | struct scatterlist *sg = scsi_sglist(sc); |
1411 | struct iscsi_cmd_task *ctask) | ||
1412 | { | ||
1413 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; | ||
1414 | int rc; | ||
1415 | 1379 | ||
1416 | tcp_ctask->xmstate &= ~XMSTATE_W_HDR; | 1380 | iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg); |
1417 | if (conn->hdrdgst_en) | 1381 | tcp_ctask->sg = sg + 1; |
1418 | iscsi_hdr_digest(conn, &tcp_ctask->headbuf, | 1382 | tcp_ctask->bad_sg = sg + scsi_sg_count(sc); |
1419 | (u8*)tcp_ctask->hdrext); | 1383 | |
1420 | rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->imm_count); | 1384 | debug_scsi("cmd [itt 0x%x total %d imm_data %d " |
1421 | if (rc) { | 1385 | "unsol count %d, unsol offset %d]\n", |
1422 | tcp_ctask->xmstate |= XMSTATE_W_HDR; | 1386 | ctask->itt, scsi_bufflen(sc), |
1423 | return rc; | 1387 | ctask->imm_count, ctask->unsol_count, |
1388 | ctask->unsol_offset); | ||
1389 | } | ||
1390 | |||
1391 | iscsi_buf_init_iov(&tcp_ctask->headbuf, (char*)ctask->hdr, | ||
1392 | sizeof(struct iscsi_hdr)); | ||
1393 | |||
1394 | if (conn->hdrdgst_en) | ||
1395 | iscsi_hdr_digest(conn, &tcp_ctask->headbuf, | ||
1396 | (u8*)tcp_ctask->hdrext); | ||
1397 | tcp_ctask->xmstate &= ~XMSTATE_CMD_HDR_INIT; | ||
1398 | tcp_ctask->xmstate |= XMSTATE_CMD_HDR_XMIT; | ||
1424 | } | 1399 | } |
1425 | 1400 | ||
1426 | if (ctask->imm_count) { | 1401 | if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_XMIT) { |
1427 | tcp_ctask->xmstate |= XMSTATE_IMM_DATA; | 1402 | rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->imm_count); |
1428 | iscsi_set_padding(tcp_ctask, ctask->imm_count); | 1403 | if (rc) |
1404 | return rc; | ||
1405 | tcp_ctask->xmstate &= ~XMSTATE_CMD_HDR_XMIT; | ||
1406 | |||
1407 | if (sc->sc_data_direction != DMA_TO_DEVICE) | ||
1408 | return 0; | ||
1409 | |||
1410 | if (ctask->imm_count) { | ||
1411 | tcp_ctask->xmstate |= XMSTATE_IMM_DATA; | ||
1412 | iscsi_set_padding(tcp_ctask, ctask->imm_count); | ||
1429 | 1413 | ||
1430 | if (ctask->conn->datadgst_en) { | 1414 | if (ctask->conn->datadgst_en) { |
1431 | iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask); | 1415 | iscsi_data_digest_init(ctask->conn->dd_data, |
1432 | tcp_ctask->immdigest = 0; | 1416 | tcp_ctask); |
1417 | tcp_ctask->immdigest = 0; | ||
1418 | } | ||
1433 | } | 1419 | } |
1434 | } | ||
1435 | 1420 | ||
1436 | if (ctask->unsol_count) | 1421 | if (ctask->unsol_count) |
1437 | tcp_ctask->xmstate |= XMSTATE_UNS_HDR | XMSTATE_UNS_INIT; | 1422 | tcp_ctask->xmstate |= |
1438 | return 0; | 1423 | XMSTATE_UNS_HDR | XMSTATE_UNS_INIT; |
1424 | } | ||
1425 | return rc; | ||
1439 | } | 1426 | } |
1440 | 1427 | ||
1441 | static int | 1428 | static int |
@@ -1624,9 +1611,7 @@ static int iscsi_send_sol_pdu(struct iscsi_conn *conn, | |||
1624 | struct iscsi_data_task *dtask; | 1611 | struct iscsi_data_task *dtask; |
1625 | int left, rc; | 1612 | int left, rc; |
1626 | 1613 | ||
1627 | if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) { | 1614 | if (tcp_ctask->xmstate & XMSTATE_SOL_HDR_INIT) { |
1628 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; | ||
1629 | tcp_ctask->xmstate |= XMSTATE_SOL_DATA; | ||
1630 | if (!tcp_ctask->r2t) { | 1615 | if (!tcp_ctask->r2t) { |
1631 | spin_lock_bh(&session->lock); | 1616 | spin_lock_bh(&session->lock); |
1632 | __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t, | 1617 | __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t, |
@@ -1640,12 +1625,19 @@ send_hdr: | |||
1640 | if (conn->hdrdgst_en) | 1625 | if (conn->hdrdgst_en) |
1641 | iscsi_hdr_digest(conn, &r2t->headbuf, | 1626 | iscsi_hdr_digest(conn, &r2t->headbuf, |
1642 | (u8*)dtask->hdrext); | 1627 | (u8*)dtask->hdrext); |
1628 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR_INIT; | ||
1629 | tcp_ctask->xmstate |= XMSTATE_SOL_HDR; | ||
1630 | } | ||
1631 | |||
1632 | if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) { | ||
1633 | r2t = tcp_ctask->r2t; | ||
1634 | dtask = &r2t->dtask; | ||
1635 | |||
1643 | rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count); | 1636 | rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count); |
1644 | if (rc) { | 1637 | if (rc) |
1645 | tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA; | ||
1646 | tcp_ctask->xmstate |= XMSTATE_SOL_HDR; | ||
1647 | return rc; | 1638 | return rc; |
1648 | } | 1639 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; |
1640 | tcp_ctask->xmstate |= XMSTATE_SOL_DATA; | ||
1649 | 1641 | ||
1650 | if (conn->datadgst_en) { | 1642 | if (conn->datadgst_en) { |
1651 | iscsi_data_digest_init(conn->dd_data, tcp_ctask); | 1643 | iscsi_data_digest_init(conn->dd_data, tcp_ctask); |
@@ -1677,8 +1669,6 @@ send_hdr: | |||
1677 | left = r2t->data_length - r2t->sent; | 1669 | left = r2t->data_length - r2t->sent; |
1678 | if (left) { | 1670 | if (left) { |
1679 | iscsi_solicit_data_cont(conn, ctask, r2t, left); | 1671 | iscsi_solicit_data_cont(conn, ctask, r2t, left); |
1680 | tcp_ctask->xmstate |= XMSTATE_SOL_DATA; | ||
1681 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; | ||
1682 | goto send_hdr; | 1672 | goto send_hdr; |
1683 | } | 1673 | } |
1684 | 1674 | ||
@@ -1693,8 +1683,6 @@ send_hdr: | |||
1693 | if (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, | 1683 | if (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, |
1694 | sizeof(void*))) { | 1684 | sizeof(void*))) { |
1695 | tcp_ctask->r2t = r2t; | 1685 | tcp_ctask->r2t = r2t; |
1696 | tcp_ctask->xmstate |= XMSTATE_SOL_DATA; | ||
1697 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; | ||
1698 | spin_unlock_bh(&session->lock); | 1686 | spin_unlock_bh(&session->lock); |
1699 | goto send_hdr; | 1687 | goto send_hdr; |
1700 | } | 1688 | } |
@@ -1703,6 +1691,46 @@ send_hdr: | |||
1703 | return 0; | 1691 | return 0; |
1704 | } | 1692 | } |
1705 | 1693 | ||
1694 | /** | ||
1695 | * iscsi_tcp_ctask_xmit - xmit normal PDU task | ||
1696 | * @conn: iscsi connection | ||
1697 | * @ctask: iscsi command task | ||
1698 | * | ||
1699 | * Notes: | ||
1700 | * The function can return -EAGAIN in which case caller must | ||
1701 | * call it again later, or recover. '0' return code means successful | ||
1702 | * xmit. | ||
1703 | * The function is devided to logical helpers (above) for the different | ||
1704 | * xmit stages. | ||
1705 | * | ||
1706 | *iscsi_send_cmd_hdr() | ||
1707 | * XMSTATE_CMD_HDR_INIT - prepare Header and Data buffers Calculate | ||
1708 | * Header Digest | ||
1709 | * XMSTATE_CMD_HDR_XMIT - Transmit header in progress | ||
1710 | * | ||
1711 | *iscsi_send_padding | ||
1712 | * XMSTATE_W_PAD - Prepare and send pading | ||
1713 | * XMSTATE_W_RESEND_PAD - retry send pading | ||
1714 | * | ||
1715 | *iscsi_send_digest | ||
1716 | * XMSTATE_W_RESEND_DATA_DIGEST - Finalize and send Data Digest | ||
1717 | * XMSTATE_W_RESEND_DATA_DIGEST - retry sending digest | ||
1718 | * | ||
1719 | *iscsi_send_unsol_hdr | ||
1720 | * XMSTATE_UNS_INIT - prepare un-solicit data header and digest | ||
1721 | * XMSTATE_UNS_HDR - send un-solicit header | ||
1722 | * | ||
1723 | *iscsi_send_unsol_pdu | ||
1724 | * XMSTATE_UNS_DATA - send un-solicit data in progress | ||
1725 | * | ||
1726 | *iscsi_send_sol_pdu | ||
1727 | * XMSTATE_SOL_HDR_INIT - solicit data header and digest initialize | ||
1728 | * XMSTATE_SOL_HDR - send solicit header | ||
1729 | * XMSTATE_SOL_DATA - send solicit data | ||
1730 | * | ||
1731 | *iscsi_tcp_ctask_xmit | ||
1732 | * XMSTATE_IMM_DATA - xmit managment data (??) | ||
1733 | **/ | ||
1706 | static int | 1734 | static int |
1707 | iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | 1735 | iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
1708 | { | 1736 | { |
@@ -1712,20 +1740,11 @@ iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |||
1712 | debug_scsi("ctask deq [cid %d xmstate %x itt 0x%x]\n", | 1740 | debug_scsi("ctask deq [cid %d xmstate %x itt 0x%x]\n", |
1713 | conn->id, tcp_ctask->xmstate, ctask->itt); | 1741 | conn->id, tcp_ctask->xmstate, ctask->itt); |
1714 | 1742 | ||
1715 | /* | 1743 | rc = iscsi_send_cmd_hdr(conn, ctask); |
1716 | * serialize with TMF AbortTask | 1744 | if (rc) |
1717 | */ | ||
1718 | if (ctask->mtask) | ||
1719 | return rc; | 1745 | return rc; |
1720 | 1746 | if (ctask->sc->sc_data_direction != DMA_TO_DEVICE) | |
1721 | if (tcp_ctask->xmstate & XMSTATE_R_HDR) | 1747 | return 0; |
1722 | return iscsi_send_read_hdr(conn, tcp_ctask); | ||
1723 | |||
1724 | if (tcp_ctask->xmstate & XMSTATE_W_HDR) { | ||
1725 | rc = iscsi_send_write_hdr(conn, ctask); | ||
1726 | if (rc) | ||
1727 | return rc; | ||
1728 | } | ||
1729 | 1748 | ||
1730 | if (tcp_ctask->xmstate & XMSTATE_IMM_DATA) { | 1749 | if (tcp_ctask->xmstate & XMSTATE_IMM_DATA) { |
1731 | rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg, | 1750 | rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg, |
@@ -1810,18 +1829,22 @@ tcp_conn_alloc_fail: | |||
1810 | static void | 1829 | static void |
1811 | iscsi_tcp_release_conn(struct iscsi_conn *conn) | 1830 | iscsi_tcp_release_conn(struct iscsi_conn *conn) |
1812 | { | 1831 | { |
1832 | struct iscsi_session *session = conn->session; | ||
1813 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; | 1833 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
1834 | struct socket *sock = tcp_conn->sock; | ||
1814 | 1835 | ||
1815 | if (!tcp_conn->sock) | 1836 | if (!sock) |
1816 | return; | 1837 | return; |
1817 | 1838 | ||
1818 | sock_hold(tcp_conn->sock->sk); | 1839 | sock_hold(sock->sk); |
1819 | iscsi_conn_restore_callbacks(tcp_conn); | 1840 | iscsi_conn_restore_callbacks(tcp_conn); |
1820 | sock_put(tcp_conn->sock->sk); | 1841 | sock_put(sock->sk); |
1821 | 1842 | ||
1822 | sock_release(tcp_conn->sock); | 1843 | spin_lock_bh(&session->lock); |
1823 | tcp_conn->sock = NULL; | 1844 | tcp_conn->sock = NULL; |
1824 | conn->recv_lock = NULL; | 1845 | conn->recv_lock = NULL; |
1846 | spin_unlock_bh(&session->lock); | ||
1847 | sockfd_put(sock); | ||
1825 | } | 1848 | } |
1826 | 1849 | ||
1827 | static void | 1850 | static void |
@@ -1852,6 +1875,46 @@ iscsi_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) | |||
1852 | tcp_conn->hdr_size = sizeof(struct iscsi_hdr); | 1875 | tcp_conn->hdr_size = sizeof(struct iscsi_hdr); |
1853 | } | 1876 | } |
1854 | 1877 | ||
1878 | static int iscsi_tcp_get_addr(struct iscsi_conn *conn, struct socket *sock, | ||
1879 | char *buf, int *port, | ||
1880 | int (*getname)(struct socket *, struct sockaddr *, | ||
1881 | int *addrlen)) | ||
1882 | { | ||
1883 | struct sockaddr_storage *addr; | ||
1884 | struct sockaddr_in6 *sin6; | ||
1885 | struct sockaddr_in *sin; | ||
1886 | int rc = 0, len; | ||
1887 | |||
1888 | addr = kmalloc(GFP_KERNEL, sizeof(*addr)); | ||
1889 | if (!addr) | ||
1890 | return -ENOMEM; | ||
1891 | |||
1892 | if (getname(sock, (struct sockaddr *) addr, &len)) { | ||
1893 | rc = -ENODEV; | ||
1894 | goto free_addr; | ||
1895 | } | ||
1896 | |||
1897 | switch (addr->ss_family) { | ||
1898 | case AF_INET: | ||
1899 | sin = (struct sockaddr_in *)addr; | ||
1900 | spin_lock_bh(&conn->session->lock); | ||
1901 | sprintf(buf, NIPQUAD_FMT, NIPQUAD(sin->sin_addr.s_addr)); | ||
1902 | *port = be16_to_cpu(sin->sin_port); | ||
1903 | spin_unlock_bh(&conn->session->lock); | ||
1904 | break; | ||
1905 | case AF_INET6: | ||
1906 | sin6 = (struct sockaddr_in6 *)addr; | ||
1907 | spin_lock_bh(&conn->session->lock); | ||
1908 | sprintf(buf, NIP6_FMT, NIP6(sin6->sin6_addr)); | ||
1909 | *port = be16_to_cpu(sin6->sin6_port); | ||
1910 | spin_unlock_bh(&conn->session->lock); | ||
1911 | break; | ||
1912 | } | ||
1913 | free_addr: | ||
1914 | kfree(addr); | ||
1915 | return rc; | ||
1916 | } | ||
1917 | |||
1855 | static int | 1918 | static int |
1856 | iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, | 1919 | iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, |
1857 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, | 1920 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, |
@@ -1869,10 +1932,24 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, | |||
1869 | printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err); | 1932 | printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err); |
1870 | return -EEXIST; | 1933 | return -EEXIST; |
1871 | } | 1934 | } |
1935 | /* | ||
1936 | * copy these values now because if we drop the session | ||
1937 | * userspace may still want to query the values since we will | ||
1938 | * be using them for the reconnect | ||
1939 | */ | ||
1940 | err = iscsi_tcp_get_addr(conn, sock, conn->portal_address, | ||
1941 | &conn->portal_port, kernel_getpeername); | ||
1942 | if (err) | ||
1943 | goto free_socket; | ||
1944 | |||
1945 | err = iscsi_tcp_get_addr(conn, sock, conn->local_address, | ||
1946 | &conn->local_port, kernel_getsockname); | ||
1947 | if (err) | ||
1948 | goto free_socket; | ||
1872 | 1949 | ||
1873 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); | 1950 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
1874 | if (err) | 1951 | if (err) |
1875 | return err; | 1952 | goto free_socket; |
1876 | 1953 | ||
1877 | /* bind iSCSI connection and socket */ | 1954 | /* bind iSCSI connection and socket */ |
1878 | tcp_conn->sock = sock; | 1955 | tcp_conn->sock = sock; |
@@ -1896,25 +1973,19 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, | |||
1896 | * set receive state machine into initial state | 1973 | * set receive state machine into initial state |
1897 | */ | 1974 | */ |
1898 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; | 1975 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
1899 | |||
1900 | return 0; | 1976 | return 0; |
1977 | |||
1978 | free_socket: | ||
1979 | sockfd_put(sock); | ||
1980 | return err; | ||
1901 | } | 1981 | } |
1902 | 1982 | ||
1903 | /* called with host lock */ | 1983 | /* called with host lock */ |
1904 | static void | 1984 | static void |
1905 | iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask, | 1985 | iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) |
1906 | char *data, uint32_t data_size) | ||
1907 | { | 1986 | { |
1908 | struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; | 1987 | struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; |
1909 | 1988 | tcp_mtask->xmstate = XMSTATE_IMM_HDR_INIT; | |
1910 | iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr, | ||
1911 | sizeof(struct iscsi_hdr)); | ||
1912 | tcp_mtask->xmstate = XMSTATE_IMM_HDR; | ||
1913 | tcp_mtask->sent = 0; | ||
1914 | |||
1915 | if (mtask->data_count) | ||
1916 | iscsi_buf_init_iov(&tcp_mtask->sendbuf, (char*)mtask->data, | ||
1917 | mtask->data_count); | ||
1918 | } | 1989 | } |
1919 | 1990 | ||
1920 | static int | 1991 | static int |
@@ -2026,41 +2097,18 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, | |||
2026 | enum iscsi_param param, char *buf) | 2097 | enum iscsi_param param, char *buf) |
2027 | { | 2098 | { |
2028 | struct iscsi_conn *conn = cls_conn->dd_data; | 2099 | struct iscsi_conn *conn = cls_conn->dd_data; |
2029 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; | ||
2030 | struct inet_sock *inet; | ||
2031 | struct ipv6_pinfo *np; | ||
2032 | struct sock *sk; | ||
2033 | int len; | 2100 | int len; |
2034 | 2101 | ||
2035 | switch(param) { | 2102 | switch(param) { |
2036 | case ISCSI_PARAM_CONN_PORT: | 2103 | case ISCSI_PARAM_CONN_PORT: |
2037 | mutex_lock(&conn->xmitmutex); | 2104 | spin_lock_bh(&conn->session->lock); |
2038 | if (!tcp_conn->sock) { | 2105 | len = sprintf(buf, "%hu\n", conn->portal_port); |
2039 | mutex_unlock(&conn->xmitmutex); | 2106 | spin_unlock_bh(&conn->session->lock); |
2040 | return -EINVAL; | ||
2041 | } | ||
2042 | |||
2043 | inet = inet_sk(tcp_conn->sock->sk); | ||
2044 | len = sprintf(buf, "%hu\n", be16_to_cpu(inet->dport)); | ||
2045 | mutex_unlock(&conn->xmitmutex); | ||
2046 | break; | 2107 | break; |
2047 | case ISCSI_PARAM_CONN_ADDRESS: | 2108 | case ISCSI_PARAM_CONN_ADDRESS: |
2048 | mutex_lock(&conn->xmitmutex); | 2109 | spin_lock_bh(&conn->session->lock); |
2049 | if (!tcp_conn->sock) { | 2110 | len = sprintf(buf, "%s\n", conn->portal_address); |
2050 | mutex_unlock(&conn->xmitmutex); | 2111 | spin_unlock_bh(&conn->session->lock); |
2051 | return -EINVAL; | ||
2052 | } | ||
2053 | |||
2054 | sk = tcp_conn->sock->sk; | ||
2055 | if (sk->sk_family == PF_INET) { | ||
2056 | inet = inet_sk(sk); | ||
2057 | len = sprintf(buf, NIPQUAD_FMT "\n", | ||
2058 | NIPQUAD(inet->daddr)); | ||
2059 | } else { | ||
2060 | np = inet6_sk(sk); | ||
2061 | len = sprintf(buf, NIP6_FMT "\n", NIP6(np->daddr)); | ||
2062 | } | ||
2063 | mutex_unlock(&conn->xmitmutex); | ||
2064 | break; | 2112 | break; |
2065 | default: | 2113 | default: |
2066 | return iscsi_conn_get_param(cls_conn, param, buf); | 2114 | return iscsi_conn_get_param(cls_conn, param, buf); |
@@ -2069,6 +2117,29 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, | |||
2069 | return len; | 2117 | return len; |
2070 | } | 2118 | } |
2071 | 2119 | ||
2120 | static int | ||
2121 | iscsi_tcp_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param, | ||
2122 | char *buf) | ||
2123 | { | ||
2124 | struct iscsi_session *session = iscsi_hostdata(shost->hostdata); | ||
2125 | int len; | ||
2126 | |||
2127 | switch (param) { | ||
2128 | case ISCSI_HOST_PARAM_IPADDRESS: | ||
2129 | spin_lock_bh(&session->lock); | ||
2130 | if (!session->leadconn) | ||
2131 | len = -ENODEV; | ||
2132 | else | ||
2133 | len = sprintf(buf, "%s\n", | ||
2134 | session->leadconn->local_address); | ||
2135 | spin_unlock_bh(&session->lock); | ||
2136 | break; | ||
2137 | default: | ||
2138 | return iscsi_host_get_param(shost, param, buf); | ||
2139 | } | ||
2140 | return len; | ||
2141 | } | ||
2142 | |||
2072 | static void | 2143 | static void |
2073 | iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) | 2144 | iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) |
2074 | { | 2145 | { |
@@ -2096,6 +2167,7 @@ iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) | |||
2096 | static struct iscsi_cls_session * | 2167 | static struct iscsi_cls_session * |
2097 | iscsi_tcp_session_create(struct iscsi_transport *iscsit, | 2168 | iscsi_tcp_session_create(struct iscsi_transport *iscsit, |
2098 | struct scsi_transport_template *scsit, | 2169 | struct scsi_transport_template *scsit, |
2170 | uint16_t cmds_max, uint16_t qdepth, | ||
2099 | uint32_t initial_cmdsn, uint32_t *hostno) | 2171 | uint32_t initial_cmdsn, uint32_t *hostno) |
2100 | { | 2172 | { |
2101 | struct iscsi_cls_session *cls_session; | 2173 | struct iscsi_cls_session *cls_session; |
@@ -2103,7 +2175,7 @@ iscsi_tcp_session_create(struct iscsi_transport *iscsit, | |||
2103 | uint32_t hn; | 2175 | uint32_t hn; |
2104 | int cmd_i; | 2176 | int cmd_i; |
2105 | 2177 | ||
2106 | cls_session = iscsi_session_setup(iscsit, scsit, | 2178 | cls_session = iscsi_session_setup(iscsit, scsit, cmds_max, qdepth, |
2107 | sizeof(struct iscsi_tcp_cmd_task), | 2179 | sizeof(struct iscsi_tcp_cmd_task), |
2108 | sizeof(struct iscsi_tcp_mgmt_task), | 2180 | sizeof(struct iscsi_tcp_mgmt_task), |
2109 | initial_cmdsn, &hn); | 2181 | initial_cmdsn, &hn); |
@@ -2142,17 +2214,24 @@ static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session) | |||
2142 | iscsi_session_teardown(cls_session); | 2214 | iscsi_session_teardown(cls_session); |
2143 | } | 2215 | } |
2144 | 2216 | ||
2217 | static int iscsi_tcp_slave_configure(struct scsi_device *sdev) | ||
2218 | { | ||
2219 | blk_queue_dma_alignment(sdev->request_queue, 0); | ||
2220 | return 0; | ||
2221 | } | ||
2222 | |||
2145 | static struct scsi_host_template iscsi_sht = { | 2223 | static struct scsi_host_template iscsi_sht = { |
2146 | .name = "iSCSI Initiator over TCP/IP", | 2224 | .name = "iSCSI Initiator over TCP/IP", |
2147 | .queuecommand = iscsi_queuecommand, | 2225 | .queuecommand = iscsi_queuecommand, |
2148 | .change_queue_depth = iscsi_change_queue_depth, | 2226 | .change_queue_depth = iscsi_change_queue_depth, |
2149 | .can_queue = ISCSI_XMIT_CMDS_MAX - 1, | 2227 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
2150 | .sg_tablesize = ISCSI_SG_TABLESIZE, | 2228 | .sg_tablesize = ISCSI_SG_TABLESIZE, |
2151 | .max_sectors = 0xFFFF, | 2229 | .max_sectors = 0xFFFF, |
2152 | .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, | 2230 | .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, |
2153 | .eh_abort_handler = iscsi_eh_abort, | 2231 | .eh_abort_handler = iscsi_eh_abort, |
2154 | .eh_host_reset_handler = iscsi_eh_host_reset, | 2232 | .eh_host_reset_handler = iscsi_eh_host_reset, |
2155 | .use_clustering = DISABLE_CLUSTERING, | 2233 | .use_clustering = DISABLE_CLUSTERING, |
2234 | .slave_configure = iscsi_tcp_slave_configure, | ||
2156 | .proc_name = "iscsi_tcp", | 2235 | .proc_name = "iscsi_tcp", |
2157 | .this_id = -1, | 2236 | .this_id = -1, |
2158 | }; | 2237 | }; |
@@ -2179,8 +2258,12 @@ static struct iscsi_transport iscsi_tcp_transport = { | |||
2179 | ISCSI_EXP_STATSN | | 2258 | ISCSI_EXP_STATSN | |
2180 | ISCSI_PERSISTENT_PORT | | 2259 | ISCSI_PERSISTENT_PORT | |
2181 | ISCSI_PERSISTENT_ADDRESS | | 2260 | ISCSI_PERSISTENT_ADDRESS | |
2182 | ISCSI_TARGET_NAME | | 2261 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
2183 | ISCSI_TPGT, | 2262 | ISCSI_USERNAME | ISCSI_PASSWORD | |
2263 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN, | ||
2264 | .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | | ||
2265 | ISCSI_HOST_INITIATOR_NAME | | ||
2266 | ISCSI_HOST_NETDEV_NAME, | ||
2184 | .host_template = &iscsi_sht, | 2267 | .host_template = &iscsi_sht, |
2185 | .conndata_size = sizeof(struct iscsi_conn), | 2268 | .conndata_size = sizeof(struct iscsi_conn), |
2186 | .max_conn = 1, | 2269 | .max_conn = 1, |
@@ -2197,6 +2280,9 @@ static struct iscsi_transport iscsi_tcp_transport = { | |||
2197 | .get_session_param = iscsi_session_get_param, | 2280 | .get_session_param = iscsi_session_get_param, |
2198 | .start_conn = iscsi_conn_start, | 2281 | .start_conn = iscsi_conn_start, |
2199 | .stop_conn = iscsi_tcp_conn_stop, | 2282 | .stop_conn = iscsi_tcp_conn_stop, |
2283 | /* iscsi host params */ | ||
2284 | .get_host_param = iscsi_tcp_host_get_param, | ||
2285 | .set_host_param = iscsi_host_set_param, | ||
2200 | /* IO */ | 2286 | /* IO */ |
2201 | .send_pdu = iscsi_conn_send_pdu, | 2287 | .send_pdu = iscsi_conn_send_pdu, |
2202 | .get_stats = iscsi_conn_get_stats, | 2288 | .get_stats = iscsi_conn_get_stats, |