2 * iSCSI Initiator over TCP/IP Data-Path
4 * Copyright (C) 2004 Dmitry Yusupov
5 * Copyright (C) 2004 Alex Aizman
6 * Copyright (C) 2005 - 2006 Mike Christie
7 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
8 * maintained by open-iscsi@googlegroups.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * See the file COPYING included with this distribution for more details.
29 #include <linux/types.h>
30 #include <linux/list.h>
31 #include <linux/inet.h>
32 #include <linux/blkdev.h>
33 #include <linux/crypto.h>
34 #include <linux/delay.h>
35 #include <linux/kfifo.h>
36 #include <linux/scatterlist.h>
37 #include <linux/mutex.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi.h>
42 #include <scsi/scsi_transport_iscsi.h>
44 #include "iscsi_tcp.h"
46 MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, "
47 "Alex Aizman <itn780@yahoo.com>");
48 MODULE_DESCRIPTION("iSCSI/TCP data-path");
49 MODULE_LICENSE("GPL");
50 /* #define DEBUG_TCP */
54 #define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt)
56 #define debug_tcp(fmt...)
66 static unsigned int iscsi_max_lun = 512;
67 module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
70 iscsi_buf_init_iov(struct iscsi_buf *ibuf, char *vbuf, int size)
72 ibuf->sg.page = virt_to_page(vbuf);
73 ibuf->sg.offset = offset_in_page(vbuf);
74 ibuf->sg.length = size;
76 ibuf->use_sendmsg = 1;
80 iscsi_buf_init_sg(struct iscsi_buf *ibuf, struct scatterlist *sg)
82 ibuf->sg.page = sg->page;
83 ibuf->sg.offset = sg->offset;
84 ibuf->sg.length = sg->length;
86 * Fastpath: sg element fits into single page
88 if (sg->length + sg->offset <= PAGE_SIZE && !PageSlab(sg->page))
89 ibuf->use_sendmsg = 0;
91 ibuf->use_sendmsg = 1;
96 iscsi_buf_left(struct iscsi_buf *ibuf)
100 rc = ibuf->sg.length - ibuf->sent;
106 iscsi_hdr_digest(struct iscsi_conn *conn, struct iscsi_buf *buf,
109 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
111 crypto_digest_digest(tcp_conn->tx_tfm, &buf->sg, 1, crc);
112 buf->sg.length = tcp_conn->hdr_size;
116 iscsi_hdr_extract(struct iscsi_tcp_conn *tcp_conn)
118 struct sk_buff *skb = tcp_conn->in.skb;
120 tcp_conn->in.zero_copy_hdr = 0;
122 if (tcp_conn->in.copy >= tcp_conn->hdr_size &&
123 tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER) {
125 * Zero-copy PDU Header: using connection context
126 * to store header pointer.
128 if (skb_shinfo(skb)->frag_list == NULL &&
129 !skb_shinfo(skb)->nr_frags) {
130 tcp_conn->in.hdr = (struct iscsi_hdr *)
131 ((char*)skb->data + tcp_conn->in.offset);
132 tcp_conn->in.zero_copy_hdr = 1;
134 /* ignoring return code since we checked
136 skb_copy_bits(skb, tcp_conn->in.offset,
137 &tcp_conn->hdr, tcp_conn->hdr_size);
138 tcp_conn->in.hdr = &tcp_conn->hdr;
140 tcp_conn->in.offset += tcp_conn->hdr_size;
141 tcp_conn->in.copy -= tcp_conn->hdr_size;
147 * PDU header scattered across SKB's,
148 * copying it... This'll happen quite rarely.
151 if (tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER)
152 tcp_conn->in.hdr_offset = 0;
154 hdr_remains = tcp_conn->hdr_size - tcp_conn->in.hdr_offset;
155 BUG_ON(hdr_remains <= 0);
157 copylen = min(tcp_conn->in.copy, hdr_remains);
158 skb_copy_bits(skb, tcp_conn->in.offset,
159 (char*)&tcp_conn->hdr + tcp_conn->in.hdr_offset,
162 debug_tcp("PDU gather offset %d bytes %d in.offset %d "
163 "in.copy %d\n", tcp_conn->in.hdr_offset, copylen,
164 tcp_conn->in.offset, tcp_conn->in.copy);
166 tcp_conn->in.offset += copylen;
167 tcp_conn->in.copy -= copylen;
168 if (copylen < hdr_remains) {
169 tcp_conn->in_progress = IN_PROGRESS_HEADER_GATHER;
170 tcp_conn->in.hdr_offset += copylen;
173 tcp_conn->in.hdr = &tcp_conn->hdr;
174 tcp_conn->discontiguous_hdr_cnt++;
175 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
182 * must be called with session lock
185 iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
187 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
188 struct iscsi_r2t_info *r2t;
189 struct scsi_cmnd *sc;
191 /* flush ctask's r2t queues */
192 while (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*))) {
193 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
195 debug_scsi("iscsi_tcp_cleanup_ctask pending r2t dropped\n");
202 tcp_ctask->xmstate = XMSTATE_IDLE;
203 tcp_ctask->r2t = NULL;
207 * iscsi_data_rsp - SCSI Data-In Response processing
208 * @conn: iscsi connection
209 * @ctask: scsi command task
212 iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
215 struct iscsi_tcp_conn *tcp_conn = conn->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;
218 struct iscsi_session *session = conn->session;
219 int datasn = be32_to_cpu(rhdr->datasn);
221 rc = iscsi_check_assign_cmdsn(session, (struct iscsi_nopin*)rhdr);
225 * setup Data-In byte counter (gets decremented..)
227 ctask->data_count = tcp_conn->in.datalen;
229 if (tcp_conn->in.datalen == 0)
232 if (ctask->datasn != datasn)
233 return ISCSI_ERR_DATASN;
237 tcp_ctask->data_offset = be32_to_cpu(rhdr->offset);
238 if (tcp_ctask->data_offset + tcp_conn->in.datalen > ctask->total_length)
239 return ISCSI_ERR_DATA_OFFSET;
241 if (rhdr->flags & ISCSI_FLAG_DATA_STATUS) {
242 struct scsi_cmnd *sc = ctask->sc;
244 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
245 if (rhdr->flags & ISCSI_FLAG_DATA_UNDERFLOW) {
246 int res_count = be32_to_cpu(rhdr->residual_count);
249 res_count <= sc->request_bufflen) {
250 sc->resid = res_count;
251 sc->result = (DID_OK << 16) | rhdr->cmd_status;
253 sc->result = (DID_BAD_TARGET << 16) |
255 } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) {
256 sc->resid = be32_to_cpu(rhdr->residual_count);
257 sc->result = (DID_OK << 16) | rhdr->cmd_status;
259 sc->result = (DID_OK << 16) | rhdr->cmd_status;
262 conn->datain_pdus_cnt++;
267 * iscsi_solicit_data_init - initialize first Data-Out
268 * @conn: iscsi connection
269 * @ctask: scsi command task
273 * Initialize first Data-Out within this R2T sequence and finds
274 * proper data_offset within this SCSI command.
276 * This function is called with connection lock taken.
279 iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
280 struct iscsi_r2t_info *r2t)
282 struct iscsi_data *hdr;
283 struct scsi_cmnd *sc = ctask->sc;
285 hdr = &r2t->dtask.hdr;
286 memset(hdr, 0, sizeof(struct iscsi_data));
288 hdr->datasn = cpu_to_be32(r2t->solicit_datasn);
289 r2t->solicit_datasn++;
290 hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
291 memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
292 hdr->itt = ctask->hdr->itt;
293 hdr->exp_statsn = r2t->exp_statsn;
294 hdr->offset = cpu_to_be32(r2t->data_offset);
295 if (r2t->data_length > conn->max_xmit_dlength) {
296 hton24(hdr->dlength, conn->max_xmit_dlength);
297 r2t->data_count = conn->max_xmit_dlength;
300 hton24(hdr->dlength, r2t->data_length);
301 r2t->data_count = r2t->data_length;
302 hdr->flags = ISCSI_FLAG_CMD_FINAL;
304 conn->dataout_pdus_cnt++;
308 iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr,
309 sizeof(struct iscsi_hdr));
313 struct scatterlist *sg = sc->request_buffer;
316 for (i = 0; i < sc->use_sg; i++, sg += 1) {
317 /* FIXME: prefetch ? */
318 if (sg_count + sg->length > r2t->data_offset) {
323 /* offset within this page */
324 page_offset = r2t->data_offset - sg_count;
326 /* fill in this buffer */
327 iscsi_buf_init_sg(&r2t->sendbuf, sg);
328 r2t->sendbuf.sg.offset += page_offset;
329 r2t->sendbuf.sg.length -= page_offset;
331 /* xmit logic will continue with next one */
335 sg_count += sg->length;
337 BUG_ON(r2t->sg == NULL);
339 iscsi_buf_init_iov(&r2t->sendbuf,
340 (char*)sc->request_buffer + r2t->data_offset,
347 * iscsi_r2t_rsp - iSCSI R2T Response processing
348 * @conn: iscsi connection
349 * @ctask: scsi command task
352 iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
354 struct iscsi_r2t_info *r2t;
355 struct iscsi_session *session = conn->session;
356 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
357 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
358 struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;
359 int r2tsn = be32_to_cpu(rhdr->r2tsn);
362 if (tcp_conn->in.datalen) {
363 printk(KERN_ERR "iscsi_tcp: invalid R2t with datalen %d\n",
364 tcp_conn->in.datalen);
365 return ISCSI_ERR_DATALEN;
368 if (tcp_ctask->exp_r2tsn && tcp_ctask->exp_r2tsn != r2tsn)
369 return ISCSI_ERR_R2TSN;
371 rc = iscsi_check_assign_cmdsn(session, (struct iscsi_nopin*)rhdr);
375 /* FIXME: use R2TSN to detect missing R2T */
377 /* fill-in new R2T associated with the task */
378 spin_lock(&session->lock);
379 if (!ctask->sc || ctask->mtask ||
380 session->state != ISCSI_STATE_LOGGED_IN) {
381 printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in "
382 "recovery...\n", ctask->itt);
383 spin_unlock(&session->lock);
387 rc = __kfifo_get(tcp_ctask->r2tpool.queue, (void*)&r2t, sizeof(void*));
390 r2t->exp_statsn = rhdr->statsn;
391 r2t->data_length = be32_to_cpu(rhdr->data_length);
392 if (r2t->data_length == 0) {
393 printk(KERN_ERR "iscsi_tcp: invalid R2T with zero data len\n");
394 spin_unlock(&session->lock);
395 return ISCSI_ERR_DATALEN;
398 if (r2t->data_length > session->max_burst)
399 debug_scsi("invalid R2T with data len %u and max burst %u."
400 "Attempting to execute request.\n",
401 r2t->data_length, session->max_burst);
403 r2t->data_offset = be32_to_cpu(rhdr->data_offset);
404 if (r2t->data_offset + r2t->data_length > ctask->total_length) {
405 spin_unlock(&session->lock);
406 printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at "
407 "offset %u and total length %d\n", r2t->data_length,
408 r2t->data_offset, ctask->total_length);
409 return ISCSI_ERR_DATALEN;
412 r2t->ttt = rhdr->ttt; /* no flip */
413 r2t->solicit_datasn = 0;
415 iscsi_solicit_data_init(conn, ctask, r2t);
417 tcp_ctask->exp_r2tsn = r2tsn + 1;
418 tcp_ctask->xmstate |= XMSTATE_SOL_HDR;
419 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*));
420 list_move_tail(&ctask->running, &conn->xmitqueue);
422 scsi_queue_work(session->host, &conn->xmitwork);
423 conn->r2t_pdus_cnt++;
424 spin_unlock(&session->lock);
430 iscsi_tcp_hdr_recv(struct iscsi_conn *conn)
432 int rc = 0, opcode, ahslen;
433 struct iscsi_hdr *hdr;
434 struct iscsi_session *session = conn->session;
435 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
436 uint32_t cdgst, rdgst = 0, itt;
438 hdr = tcp_conn->in.hdr;
440 /* verify PDU length */
441 tcp_conn->in.datalen = ntoh24(hdr->dlength);
442 if (tcp_conn->in.datalen > conn->max_recv_dlength) {
443 printk(KERN_ERR "iscsi_tcp: datalen %d > %d\n",
444 tcp_conn->in.datalen, conn->max_recv_dlength);
445 return ISCSI_ERR_DATALEN;
447 tcp_conn->data_copied = 0;
450 ahslen = hdr->hlength << 2;
451 tcp_conn->in.offset += ahslen;
452 tcp_conn->in.copy -= ahslen;
453 if (tcp_conn->in.copy < 0) {
454 printk(KERN_ERR "iscsi_tcp: can't handle AHS with length "
455 "%d bytes\n", ahslen);
456 return ISCSI_ERR_AHSLEN;
459 /* calculate read padding */
460 tcp_conn->in.padding = tcp_conn->in.datalen & (ISCSI_PAD_LEN-1);
461 if (tcp_conn->in.padding) {
462 tcp_conn->in.padding = ISCSI_PAD_LEN - tcp_conn->in.padding;
463 debug_scsi("read padding %d bytes\n", tcp_conn->in.padding);
466 if (conn->hdrdgst_en) {
467 struct scatterlist sg;
469 sg_init_one(&sg, (u8 *)hdr,
470 sizeof(struct iscsi_hdr) + ahslen);
471 crypto_digest_digest(tcp_conn->rx_tfm, &sg, 1, (u8 *)&cdgst);
472 rdgst = *(uint32_t*)((char*)hdr + sizeof(struct iscsi_hdr) +
474 if (cdgst != rdgst) {
475 printk(KERN_ERR "iscsi_tcp: hdrdgst error "
476 "recv 0x%x calc 0x%x\n", rdgst, cdgst);
477 return ISCSI_ERR_HDR_DGST;
481 opcode = hdr->opcode & ISCSI_OPCODE_MASK;
482 /* verify itt (itt encoding: age+cid+itt) */
483 rc = iscsi_verify_itt(conn, hdr, &itt);
484 if (rc == ISCSI_ERR_NO_SCSI_CMD) {
485 tcp_conn->in.datalen = 0; /* force drop */
490 debug_tcp("opcode 0x%x offset %d copy %d ahslen %d datalen %d\n",
491 opcode, tcp_conn->in.offset, tcp_conn->in.copy,
492 ahslen, tcp_conn->in.datalen);
495 case ISCSI_OP_SCSI_DATA_IN:
496 tcp_conn->in.ctask = session->cmds[itt];
497 rc = iscsi_data_rsp(conn, tcp_conn->in.ctask);
501 case ISCSI_OP_SCSI_CMD_RSP:
502 tcp_conn->in.ctask = session->cmds[itt];
503 if (tcp_conn->in.datalen)
506 spin_lock(&session->lock);
507 rc = __iscsi_complete_pdu(conn, hdr, NULL, 0);
508 spin_unlock(&session->lock);
511 tcp_conn->in.ctask = session->cmds[itt];
513 rc = ISCSI_ERR_AHSLEN;
514 else if (tcp_conn->in.ctask->sc->sc_data_direction ==
516 rc = iscsi_r2t_rsp(conn, tcp_conn->in.ctask);
518 rc = ISCSI_ERR_PROTO;
520 case ISCSI_OP_LOGIN_RSP:
521 case ISCSI_OP_TEXT_RSP:
522 case ISCSI_OP_REJECT:
523 case ISCSI_OP_ASYNC_EVENT:
525 * It is possible that we could get a PDU with a buffer larger
526 * than 8K, but there are no targets that currently do this.
527 * For now we fail until we find a vendor that needs it
529 if (DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH <
530 tcp_conn->in.datalen) {
531 printk(KERN_ERR "iscsi_tcp: received buffer of len %u "
532 "but conn buffer is only %u (opcode %0x)\n",
533 tcp_conn->in.datalen,
534 DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH, opcode);
535 rc = ISCSI_ERR_PROTO;
539 if (tcp_conn->in.datalen)
542 case ISCSI_OP_LOGOUT_RSP:
543 case ISCSI_OP_NOOP_IN:
544 case ISCSI_OP_SCSI_TMFUNC_RSP:
545 rc = iscsi_complete_pdu(conn, hdr, NULL, 0);
548 rc = ISCSI_ERR_BAD_OPCODE;
556 * if we did zero copy for the header but we will need multiple
557 * skbs to complete the command then we have to copy the header
560 if (tcp_conn->in.zero_copy_hdr && tcp_conn->in.copy <=
561 (tcp_conn->in.datalen + tcp_conn->in.padding +
562 (conn->datadgst_en ? 4 : 0))) {
563 debug_tcp("Copying header for later use. in.copy %d in.datalen"
564 " %d\n", tcp_conn->in.copy, tcp_conn->in.datalen);
565 memcpy(&tcp_conn->hdr, tcp_conn->in.hdr,
566 sizeof(struct iscsi_hdr));
567 tcp_conn->in.hdr = &tcp_conn->hdr;
568 tcp_conn->in.zero_copy_hdr = 0;
574 * iscsi_ctask_copy - copy skb bits to the destanation cmd task
575 * @conn: iscsi tcp connection
576 * @ctask: scsi command task
577 * @buf: buffer to copy to
578 * @buf_size: size of buffer
579 * @offset: offset within the buffer
582 * The function calls skb_copy_bits() and updates per-connection and
583 * per-cmd byte counters.
585 * Read counters (in bytes):
587 * conn->in.offset offset within in progress SKB
588 * conn->in.copy left to copy from in progress SKB
590 * conn->in.copied copied already from in progress SKB
591 * conn->data_copied copied already from in progress buffer
592 * ctask->sent total bytes sent up to the MidLayer
593 * ctask->data_count left to copy from in progress Data-In
594 * buf_left left to copy from in progress buffer
597 iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask,
598 void *buf, int buf_size, int offset)
600 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
601 int buf_left = buf_size - (tcp_conn->data_copied + offset);
602 int size = min(tcp_conn->in.copy, buf_left);
605 size = min(size, ctask->data_count);
607 debug_tcp("ctask_copy %d bytes at offset %d copied %d\n",
608 size, tcp_conn->in.offset, tcp_conn->in.copied);
611 BUG_ON(tcp_ctask->sent + size > ctask->total_length);
613 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset,
614 (char*)buf + (offset + tcp_conn->data_copied), size);
615 /* must fit into skb->len */
618 tcp_conn->in.offset += size;
619 tcp_conn->in.copy -= size;
620 tcp_conn->in.copied += size;
621 tcp_conn->data_copied += size;
622 tcp_ctask->sent += size;
623 ctask->data_count -= size;
625 BUG_ON(tcp_conn->in.copy < 0);
626 BUG_ON(ctask->data_count < 0);
628 if (buf_size != (tcp_conn->data_copied + offset)) {
629 if (!ctask->data_count) {
630 BUG_ON(buf_size - tcp_conn->data_copied < 0);
631 /* done with this PDU */
632 return buf_size - tcp_conn->data_copied;
637 /* done with this buffer or with both - PDU and buffer */
638 tcp_conn->data_copied = 0;
643 * iscsi_tcp_copy - copy skb bits to the destanation buffer
644 * @conn: iscsi tcp connection
647 * The function calls skb_copy_bits() and updates per-connection
651 iscsi_tcp_copy(struct iscsi_conn *conn, int buf_size)
653 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
654 int buf_left = buf_size - tcp_conn->data_copied;
655 int size = min(tcp_conn->in.copy, buf_left);
658 debug_tcp("tcp_copy %d bytes at offset %d copied %d\n",
659 size, tcp_conn->in.offset, tcp_conn->data_copied);
662 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset,
663 (char*)conn->data + tcp_conn->data_copied, size);
666 tcp_conn->in.offset += size;
667 tcp_conn->in.copy -= size;
668 tcp_conn->in.copied += size;
669 tcp_conn->data_copied += size;
671 if (buf_size != tcp_conn->data_copied)
678 partial_sg_digest_update(struct crypto_tfm *tfm, struct scatterlist *sg,
679 int offset, int length)
681 struct scatterlist temp;
683 memcpy(&temp, sg, sizeof(struct scatterlist));
684 temp.offset = offset;
685 temp.length = length;
686 crypto_digest_update(tfm, &temp, 1);
690 iscsi_recv_digest_update(struct iscsi_tcp_conn *tcp_conn, char* buf, int len)
692 struct scatterlist tmp;
694 sg_init_one(&tmp, buf, len);
695 crypto_digest_update(tcp_conn->rx_tfm, &tmp, 1);
698 static int iscsi_scsi_data_in(struct iscsi_conn *conn)
700 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
701 struct iscsi_cmd_task *ctask = tcp_conn->in.ctask;
702 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
703 struct scsi_cmnd *sc = ctask->sc;
704 struct scatterlist *sg;
705 int i, offset, rc = 0;
707 BUG_ON((void*)ctask != sc->SCp.ptr);
710 * copying Data-In into the Scsi_Cmnd
713 i = ctask->data_count;
714 rc = iscsi_ctask_copy(tcp_conn, ctask, sc->request_buffer,
716 tcp_ctask->data_offset);
719 if (conn->datadgst_en)
720 iscsi_recv_digest_update(tcp_conn, sc->request_buffer,
726 offset = tcp_ctask->data_offset;
727 sg = sc->request_buffer;
729 if (tcp_ctask->data_offset)
730 for (i = 0; i < tcp_ctask->sg_count; i++)
731 offset -= sg[i].length;
732 /* we've passed through partial sg*/
736 for (i = tcp_ctask->sg_count; i < sc->use_sg; i++) {
739 dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0);
740 rc = iscsi_ctask_copy(tcp_conn, ctask, dest + sg[i].offset,
741 sg[i].length, offset);
742 kunmap_atomic(dest, KM_SOFTIRQ0);
744 /* continue with the next SKB/PDU */
747 if (conn->datadgst_en) {
749 crypto_digest_update(
753 partial_sg_digest_update(
756 sg[i].offset + offset,
757 sg[i].length - offset);
760 tcp_ctask->sg_count++;
763 if (!ctask->data_count) {
764 if (rc && conn->datadgst_en)
766 * data-in is complete, but buffer not...
768 partial_sg_digest_update(tcp_conn->rx_tfm,
770 sg[i].offset, sg[i].length-rc);
775 if (!tcp_conn->in.copy)
778 BUG_ON(ctask->data_count);
781 /* check for non-exceptional status */
782 if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) {
783 debug_scsi("done [sc %lx res %d itt 0x%x flags 0x%x]\n",
784 (long)sc, sc->result, ctask->itt,
785 tcp_conn->in.hdr->flags);
786 spin_lock(&conn->session->lock);
787 __iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0);
788 spin_unlock(&conn->session->lock);
795 iscsi_data_recv(struct iscsi_conn *conn)
797 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
800 opcode = tcp_conn->in.hdr->opcode & ISCSI_OPCODE_MASK;
802 case ISCSI_OP_SCSI_DATA_IN:
803 rc = iscsi_scsi_data_in(conn);
805 case ISCSI_OP_SCSI_CMD_RSP:
806 case ISCSI_OP_TEXT_RSP:
807 case ISCSI_OP_LOGIN_RSP:
808 case ISCSI_OP_ASYNC_EVENT:
809 case ISCSI_OP_REJECT:
811 * Collect data segment to the connection's data
814 if (iscsi_tcp_copy(conn, tcp_conn->in.datalen)) {
819 rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, conn->data,
820 tcp_conn->in.datalen);
821 if (!rc && conn->datadgst_en && opcode != ISCSI_OP_LOGIN_RSP)
822 iscsi_recv_digest_update(tcp_conn, conn->data,
823 tcp_conn->in.datalen);
833 * iscsi_tcp_data_recv - TCP receive in sendfile fashion
834 * @rd_desc: read descriptor
835 * @skb: socket buffer
836 * @offset: offset in skb
837 * @len: skb->len - offset
840 iscsi_tcp_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
841 unsigned int offset, size_t len)
844 struct iscsi_conn *conn = rd_desc->arg.data;
845 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
847 char pad[ISCSI_PAD_LEN];
848 struct scatterlist sg;
851 * Save current SKB and its offset in the corresponding
852 * connection context.
854 tcp_conn->in.copy = skb->len - offset;
855 tcp_conn->in.offset = offset;
856 tcp_conn->in.skb = skb;
857 tcp_conn->in.len = tcp_conn->in.copy;
858 BUG_ON(tcp_conn->in.copy <= 0);
859 debug_tcp("in %d bytes\n", tcp_conn->in.copy);
862 tcp_conn->in.copied = 0;
865 if (unlikely(conn->suspend_rx)) {
866 debug_tcp("conn %d Rx suspended!\n", conn->id);
870 if (tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER ||
871 tcp_conn->in_progress == IN_PROGRESS_HEADER_GATHER) {
872 rc = iscsi_hdr_extract(tcp_conn);
877 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
883 * Verify and process incoming PDU header.
885 rc = iscsi_tcp_hdr_recv(conn);
886 if (!rc && tcp_conn->in.datalen) {
887 if (conn->datadgst_en)
888 crypto_digest_init(tcp_conn->rx_tfm);
889 tcp_conn->in_progress = IN_PROGRESS_DATA_RECV;
891 iscsi_conn_failure(conn, rc);
896 if (tcp_conn->in_progress == IN_PROGRESS_DDIGEST_RECV) {
897 uint32_t recv_digest;
899 debug_tcp("extra data_recv offset %d copy %d\n",
900 tcp_conn->in.offset, tcp_conn->in.copy);
901 rc = iscsi_tcp_copy(conn, sizeof(uint32_t));
905 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
909 memcpy(&recv_digest, conn->data, sizeof(uint32_t));
910 if (recv_digest != tcp_conn->in.datadgst) {
911 debug_tcp("iscsi_tcp: data digest error!"
912 "0x%x != 0x%x\n", recv_digest,
913 tcp_conn->in.datadgst);
914 iscsi_conn_failure(conn, ISCSI_ERR_DATA_DGST);
917 debug_tcp("iscsi_tcp: data digest match!"
918 "0x%x == 0x%x\n", recv_digest,
919 tcp_conn->in.datadgst);
920 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
924 if (tcp_conn->in_progress == IN_PROGRESS_DATA_RECV &&
927 debug_tcp("data_recv offset %d copy %d\n",
928 tcp_conn->in.offset, tcp_conn->in.copy);
930 rc = iscsi_data_recv(conn);
934 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
937 tcp_conn->in.copy -= tcp_conn->in.padding;
938 tcp_conn->in.offset += tcp_conn->in.padding;
939 if (conn->datadgst_en) {
940 if (tcp_conn->in.padding) {
941 debug_tcp("padding -> %d\n",
942 tcp_conn->in.padding);
943 memset(pad, 0, tcp_conn->in.padding);
944 sg_init_one(&sg, pad, tcp_conn->in.padding);
945 crypto_digest_update(tcp_conn->rx_tfm,
948 crypto_digest_final(tcp_conn->rx_tfm,
949 (u8 *) &tcp_conn->in.datadgst);
950 debug_tcp("rx digest 0x%x\n", tcp_conn->in.datadgst);
951 tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV;
952 tcp_conn->data_copied = 0;
954 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
957 debug_tcp("f, processed %d from out of %d padding %d\n",
958 tcp_conn->in.offset - offset, (int)len, tcp_conn->in.padding);
959 BUG_ON(tcp_conn->in.offset - offset > len);
961 if (tcp_conn->in.offset - offset != len) {
962 debug_tcp("continue to process %d bytes\n",
963 (int)len - (tcp_conn->in.offset - offset));
968 processed = tcp_conn->in.offset - offset;
969 BUG_ON(processed == 0);
973 processed = tcp_conn->in.offset - offset;
974 debug_tcp("c, processed %d from out of %d rd_desc_cnt %d\n",
975 processed, (int)len, (int)rd_desc->count);
976 BUG_ON(processed == 0);
977 BUG_ON(processed > len);
979 conn->rxdata_octets += processed;
984 iscsi_tcp_data_ready(struct sock *sk, int flag)
986 struct iscsi_conn *conn = sk->sk_user_data;
987 read_descriptor_t rd_desc;
989 read_lock(&sk->sk_callback_lock);
992 * Use rd_desc to pass 'conn' to iscsi_tcp_data_recv.
993 * We set count to 1 because we want the network layer to
994 * hand us all the skbs that are available. iscsi_tcp_data_recv
995 * handled pdus that cross buffers or pdus that still need data.
997 rd_desc.arg.data = conn;
999 tcp_read_sock(sk, &rd_desc, iscsi_tcp_data_recv);
1001 read_unlock(&sk->sk_callback_lock);
1005 iscsi_tcp_state_change(struct sock *sk)
1007 struct iscsi_tcp_conn *tcp_conn;
1008 struct iscsi_conn *conn;
1009 struct iscsi_session *session;
1010 void (*old_state_change)(struct sock *);
1012 read_lock(&sk->sk_callback_lock);
1014 conn = (struct iscsi_conn*)sk->sk_user_data;
1015 session = conn->session;
1017 if ((sk->sk_state == TCP_CLOSE_WAIT ||
1018 sk->sk_state == TCP_CLOSE) &&
1019 !atomic_read(&sk->sk_rmem_alloc)) {
1020 debug_tcp("iscsi_tcp_state_change: TCP_CLOSE|TCP_CLOSE_WAIT\n");
1021 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1024 tcp_conn = conn->dd_data;
1025 old_state_change = tcp_conn->old_state_change;
1027 read_unlock(&sk->sk_callback_lock);
1029 old_state_change(sk);
1033 * iscsi_write_space - Called when more output buffer space is available
1034 * @sk: socket space is available for
1037 iscsi_write_space(struct sock *sk)
1039 struct iscsi_conn *conn = (struct iscsi_conn*)sk->sk_user_data;
1040 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1042 tcp_conn->old_write_space(sk);
1043 debug_tcp("iscsi_write_space: cid %d\n", conn->id);
1044 scsi_queue_work(conn->session->host, &conn->xmitwork);
1048 iscsi_conn_set_callbacks(struct iscsi_conn *conn)
1050 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1051 struct sock *sk = tcp_conn->sock->sk;
1053 /* assign new callbacks */
1054 write_lock_bh(&sk->sk_callback_lock);
1055 sk->sk_user_data = conn;
1056 tcp_conn->old_data_ready = sk->sk_data_ready;
1057 tcp_conn->old_state_change = sk->sk_state_change;
1058 tcp_conn->old_write_space = sk->sk_write_space;
1059 sk->sk_data_ready = iscsi_tcp_data_ready;
1060 sk->sk_state_change = iscsi_tcp_state_change;
1061 sk->sk_write_space = iscsi_write_space;
1062 write_unlock_bh(&sk->sk_callback_lock);
1066 iscsi_conn_restore_callbacks(struct iscsi_tcp_conn *tcp_conn)
1068 struct sock *sk = tcp_conn->sock->sk;
1070 /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */
1071 write_lock_bh(&sk->sk_callback_lock);
1072 sk->sk_user_data = NULL;
1073 sk->sk_data_ready = tcp_conn->old_data_ready;
1074 sk->sk_state_change = tcp_conn->old_state_change;
1075 sk->sk_write_space = tcp_conn->old_write_space;
1076 sk->sk_no_check = 0;
1077 write_unlock_bh(&sk->sk_callback_lock);
1081 * iscsi_send - generic send routine
1082 * @sk: kernel's socket
1083 * @buf: buffer to write from
1084 * @size: actual size to write
1085 * @flags: socket's flags
1088 iscsi_send(struct iscsi_conn *conn, struct iscsi_buf *buf, int size, int flags)
1090 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1091 struct socket *sk = tcp_conn->sock;
1092 int offset = buf->sg.offset + buf->sent, res;
1095 * if we got use_sg=0 or are sending something we kmallocd
1096 * then we did not have to do kmap (kmap returns page_address)
1098 * if we got use_sg > 0, but had to drop down, we do not
1099 * set clustering so this should only happen for that
1102 if (buf->use_sendmsg)
1103 res = sock_no_sendpage(sk, buf->sg.page, offset, size, flags);
1105 res = tcp_conn->sendpage(sk, buf->sg.page, offset, size, flags);
1108 conn->txdata_octets += res;
1113 tcp_conn->sendpage_failures_cnt++;
1117 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1122 * iscsi_sendhdr - send PDU Header via tcp_sendpage()
1123 * @conn: iscsi connection
1124 * @buf: buffer to write from
1125 * @datalen: lenght of data to be sent after the header
1131 iscsi_sendhdr(struct iscsi_conn *conn, struct iscsi_buf *buf, int datalen)
1133 int flags = 0; /* MSG_DONTWAIT; */
1136 size = buf->sg.length - buf->sent;
1137 BUG_ON(buf->sent + size > buf->sg.length);
1138 if (buf->sent + size != buf->sg.length || datalen)
1141 res = iscsi_send(conn, buf, size, flags);
1142 debug_tcp("sendhdr %d bytes, sent %d res %d\n", size, buf->sent, res);
1153 * iscsi_sendpage - send one page of iSCSI Data-Out.
1154 * @conn: iscsi connection
1155 * @buf: buffer to write from
1156 * @count: remaining data
1157 * @sent: number of bytes sent
1163 iscsi_sendpage(struct iscsi_conn *conn, struct iscsi_buf *buf,
1164 int *count, int *sent)
1166 int flags = 0; /* MSG_DONTWAIT; */
1169 size = buf->sg.length - buf->sent;
1170 BUG_ON(buf->sent + size > buf->sg.length);
1173 if (buf->sent + size != buf->sg.length || *count != size)
1176 res = iscsi_send(conn, buf, size, flags);
1177 debug_tcp("sendpage: %d bytes, sent %d left %d sent %d res %d\n",
1178 size, buf->sent, *count, *sent, res);
1191 iscsi_data_digest_init(struct iscsi_tcp_conn *tcp_conn,
1192 struct iscsi_tcp_cmd_task *tcp_ctask)
1194 crypto_digest_init(tcp_conn->tx_tfm);
1195 tcp_ctask->digest_count = 4;
1199 * iscsi_solicit_data_cont - initialize next Data-Out
1200 * @conn: iscsi connection
1201 * @ctask: scsi command task
1203 * @left: bytes left to transfer
1206 * Initialize next Data-Out within this R2T sequence and continue
1207 * to process next Scatter-Gather element(if any) of this SCSI command.
1209 * Called under connection lock.
1212 iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1213 struct iscsi_r2t_info *r2t, int left)
1215 struct iscsi_data *hdr;
1216 struct scsi_cmnd *sc = ctask->sc;
1219 hdr = &r2t->dtask.hdr;
1220 memset(hdr, 0, sizeof(struct iscsi_data));
1221 hdr->ttt = r2t->ttt;
1222 hdr->datasn = cpu_to_be32(r2t->solicit_datasn);
1223 r2t->solicit_datasn++;
1224 hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
1225 memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
1226 hdr->itt = ctask->hdr->itt;
1227 hdr->exp_statsn = r2t->exp_statsn;
1228 new_offset = r2t->data_offset + r2t->sent;
1229 hdr->offset = cpu_to_be32(new_offset);
1230 if (left > conn->max_xmit_dlength) {
1231 hton24(hdr->dlength, conn->max_xmit_dlength);
1232 r2t->data_count = conn->max_xmit_dlength;
1234 hton24(hdr->dlength, left);
1235 r2t->data_count = left;
1236 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1238 conn->dataout_pdus_cnt++;
1240 iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr,
1241 sizeof(struct iscsi_hdr));
1243 if (iscsi_buf_left(&r2t->sendbuf))
1247 iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg);
1250 iscsi_buf_init_iov(&r2t->sendbuf,
1251 (char*)sc->request_buffer + new_offset,
1257 static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask,
1260 tcp_ctask->pad_count = len & (ISCSI_PAD_LEN - 1);
1261 if (!tcp_ctask->pad_count)
1264 tcp_ctask->pad_count = ISCSI_PAD_LEN - tcp_ctask->pad_count;
1265 debug_scsi("write padding %d bytes\n", tcp_ctask->pad_count);
1266 tcp_ctask->xmstate |= XMSTATE_W_PAD;
1270 * iscsi_tcp_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
1271 * @conn: iscsi connection
1272 * @ctask: scsi command task
1276 iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask)
1278 struct scsi_cmnd *sc = ctask->sc;
1279 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1281 BUG_ON(__kfifo_len(tcp_ctask->r2tqueue));
1283 tcp_ctask->sent = 0;
1284 tcp_ctask->sg_count = 0;
1286 if (sc->sc_data_direction == DMA_TO_DEVICE) {
1287 tcp_ctask->xmstate = XMSTATE_W_HDR;
1288 tcp_ctask->exp_r2tsn = 0;
1289 BUG_ON(ctask->total_length == 0);
1292 struct scatterlist *sg = sc->request_buffer;
1294 iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg);
1295 tcp_ctask->sg = sg + 1;
1296 tcp_ctask->bad_sg = sg + sc->use_sg;
1298 iscsi_buf_init_iov(&tcp_ctask->sendbuf,
1300 sc->request_bufflen);
1301 tcp_ctask->sg = NULL;
1302 tcp_ctask->bad_sg = NULL;
1304 debug_scsi("cmd [itt 0x%x total %d imm_data %d "
1305 "unsol count %d, unsol offset %d]\n",
1306 ctask->itt, ctask->total_length, ctask->imm_count,
1307 ctask->unsol_count, ctask->unsol_offset);
1309 tcp_ctask->xmstate = XMSTATE_R_HDR;
1311 iscsi_buf_init_iov(&tcp_ctask->headbuf, (char*)ctask->hdr,
1312 sizeof(struct iscsi_hdr));
1316 * iscsi_tcp_mtask_xmit - xmit management(immediate) task
1317 * @conn: iscsi connection
1318 * @mtask: task management task
1321 * The function can return -EAGAIN in which case caller must
1322 * call it again later, or recover. '0' return code means successful
1325 * Management xmit state machine consists of two states:
1326 * IN_PROGRESS_IMM_HEAD - PDU Header xmit in progress
1327 * IN_PROGRESS_IMM_DATA - PDU Data xmit in progress
1330 iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1332 struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data;
1335 debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n",
1336 conn->id, tcp_mtask->xmstate, mtask->itt);
1338 if (tcp_mtask->xmstate & XMSTATE_IMM_HDR) {
1339 tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR;
1340 if (mtask->data_count)
1341 tcp_mtask->xmstate |= XMSTATE_IMM_DATA;
1342 if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE &&
1343 conn->stop_stage != STOP_CONN_RECOVER &&
1345 iscsi_hdr_digest(conn, &tcp_mtask->headbuf,
1346 (u8*)tcp_mtask->hdrext);
1347 rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf,
1350 tcp_mtask->xmstate |= XMSTATE_IMM_HDR;
1351 if (mtask->data_count)
1352 tcp_mtask->xmstate &= ~XMSTATE_IMM_DATA;
1357 if (tcp_mtask->xmstate & XMSTATE_IMM_DATA) {
1358 BUG_ON(!mtask->data_count);
1359 tcp_mtask->xmstate &= ~XMSTATE_IMM_DATA;
1360 /* FIXME: implement.
1361 * Virtual buffer could be spreaded across multiple pages...
1366 rc = iscsi_sendpage(conn, &tcp_mtask->sendbuf,
1367 &mtask->data_count, &tcp_mtask->sent);
1369 tcp_mtask->xmstate |= XMSTATE_IMM_DATA;
1372 } while (mtask->data_count);
1375 BUG_ON(tcp_mtask->xmstate != XMSTATE_IDLE);
1376 if (mtask->hdr->itt == cpu_to_be32(ISCSI_RESERVED_TAG)) {
1377 struct iscsi_session *session = conn->session;
1379 spin_lock_bh(&session->lock);
1380 list_del(&conn->mtask->running);
1381 __kfifo_put(session->mgmtpool.queue, (void*)&conn->mtask,
1383 spin_unlock_bh(&session->lock);
1389 iscsi_send_read_hdr(struct iscsi_conn *conn,
1390 struct iscsi_tcp_cmd_task *tcp_ctask)
1394 tcp_ctask->xmstate &= ~XMSTATE_R_HDR;
1395 if (conn->hdrdgst_en)
1396 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1397 (u8*)tcp_ctask->hdrext);
1398 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, 0);
1400 BUG_ON(tcp_ctask->xmstate != XMSTATE_IDLE);
1401 return 0; /* wait for Data-In */
1403 tcp_ctask->xmstate |= XMSTATE_R_HDR;
1408 iscsi_send_write_hdr(struct iscsi_conn *conn,
1409 struct iscsi_cmd_task *ctask)
1411 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1414 tcp_ctask->xmstate &= ~XMSTATE_W_HDR;
1415 if (conn->hdrdgst_en)
1416 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1417 (u8*)tcp_ctask->hdrext);
1418 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->imm_count);
1420 tcp_ctask->xmstate |= XMSTATE_W_HDR;
1424 if (ctask->imm_count) {
1425 tcp_ctask->xmstate |= XMSTATE_IMM_DATA;
1426 iscsi_set_padding(tcp_ctask, ctask->imm_count);
1428 if (ctask->conn->datadgst_en) {
1429 iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask);
1430 tcp_ctask->immdigest = 0;
1434 if (ctask->unsol_count)
1435 tcp_ctask->xmstate |= XMSTATE_UNS_HDR | XMSTATE_UNS_INIT;
1440 iscsi_send_padding(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1442 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1443 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1446 if (tcp_ctask->xmstate & XMSTATE_W_PAD) {
1447 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad,
1448 tcp_ctask->pad_count);
1449 if (conn->datadgst_en)
1450 crypto_digest_update(tcp_conn->tx_tfm,
1451 &tcp_ctask->sendbuf.sg, 1);
1452 } else if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_PAD))
1455 tcp_ctask->xmstate &= ~XMSTATE_W_PAD;
1456 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_PAD;
1457 debug_scsi("sending %d pad bytes for itt 0x%x\n",
1458 tcp_ctask->pad_count, ctask->itt);
1459 rc = iscsi_sendpage(conn, &tcp_ctask->sendbuf, &tcp_ctask->pad_count,
1462 debug_scsi("padding send failed %d\n", rc);
1463 tcp_ctask->xmstate |= XMSTATE_W_RESEND_PAD;
1469 iscsi_send_digest(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1470 struct iscsi_buf *buf, uint32_t *digest)
1472 struct iscsi_tcp_cmd_task *tcp_ctask;
1473 struct iscsi_tcp_conn *tcp_conn;
1476 if (!conn->datadgst_en)
1479 tcp_ctask = ctask->dd_data;
1480 tcp_conn = conn->dd_data;
1482 if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_DATA_DIGEST)) {
1483 crypto_digest_final(tcp_conn->tx_tfm, (u8*)digest);
1484 iscsi_buf_init_iov(buf, (char*)digest, 4);
1486 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_DATA_DIGEST;
1488 rc = iscsi_sendpage(conn, buf, &tcp_ctask->digest_count, &sent);
1490 debug_scsi("sent digest 0x%x for itt 0x%x\n", *digest,
1493 debug_scsi("sending digest 0x%x failed for itt 0x%x!\n",
1494 *digest, ctask->itt);
1495 tcp_ctask->xmstate |= XMSTATE_W_RESEND_DATA_DIGEST;
1501 iscsi_send_data(struct iscsi_cmd_task *ctask, struct iscsi_buf *sendbuf,
1502 struct scatterlist **sg, int *sent, int *count,
1503 struct iscsi_buf *digestbuf, uint32_t *digest)
1505 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1506 struct iscsi_conn *conn = ctask->conn;
1507 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1508 int rc, buf_sent, offset;
1512 offset = sendbuf->sent;
1514 rc = iscsi_sendpage(conn, sendbuf, count, &buf_sent);
1515 *sent = *sent + buf_sent;
1516 if (buf_sent && conn->datadgst_en)
1517 partial_sg_digest_update(tcp_conn->tx_tfm,
1518 &sendbuf->sg, sendbuf->sg.offset + offset,
1520 if (!iscsi_buf_left(sendbuf) && *sg != tcp_ctask->bad_sg) {
1521 iscsi_buf_init_sg(sendbuf, *sg);
1529 rc = iscsi_send_padding(conn, ctask);
1533 return iscsi_send_digest(conn, ctask, digestbuf, digest);
1537 iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1539 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1540 struct iscsi_data_task *dtask;
1543 tcp_ctask->xmstate |= XMSTATE_UNS_DATA;
1544 if (tcp_ctask->xmstate & XMSTATE_UNS_INIT) {
1545 dtask = &tcp_ctask->unsol_dtask;
1547 iscsi_prep_unsolicit_data_pdu(ctask, &dtask->hdr);
1548 iscsi_buf_init_iov(&tcp_ctask->headbuf, (char*)&dtask->hdr,
1549 sizeof(struct iscsi_hdr));
1550 if (conn->hdrdgst_en)
1551 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1552 (u8*)dtask->hdrext);
1554 tcp_ctask->xmstate &= ~XMSTATE_UNS_INIT;
1555 iscsi_set_padding(tcp_ctask, ctask->data_count);
1558 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->data_count);
1560 tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA;
1561 tcp_ctask->xmstate |= XMSTATE_UNS_HDR;
1565 if (conn->datadgst_en) {
1566 dtask = &tcp_ctask->unsol_dtask;
1567 iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask);
1571 debug_scsi("uns dout [itt 0x%x dlen %d sent %d]\n",
1572 ctask->itt, ctask->unsol_count, tcp_ctask->sent);
1577 iscsi_send_unsol_pdu(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1579 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1582 if (tcp_ctask->xmstate & XMSTATE_UNS_HDR) {
1583 BUG_ON(!ctask->unsol_count);
1584 tcp_ctask->xmstate &= ~XMSTATE_UNS_HDR;
1586 rc = iscsi_send_unsol_hdr(conn, ctask);
1591 if (tcp_ctask->xmstate & XMSTATE_UNS_DATA) {
1592 struct iscsi_data_task *dtask = &tcp_ctask->unsol_dtask;
1593 int start = tcp_ctask->sent;
1595 rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg,
1596 &tcp_ctask->sent, &ctask->data_count,
1597 &dtask->digestbuf, &dtask->digest);
1598 ctask->unsol_count -= tcp_ctask->sent - start;
1601 tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA;
1603 * Done with the Data-Out. Next, check if we need
1604 * to send another unsolicited Data-Out.
1606 if (ctask->unsol_count) {
1607 debug_scsi("sending more uns\n");
1608 tcp_ctask->xmstate |= XMSTATE_UNS_INIT;
1615 static int iscsi_send_sol_pdu(struct iscsi_conn *conn,
1616 struct iscsi_cmd_task *ctask)
1618 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1619 struct iscsi_session *session = conn->session;
1620 struct iscsi_r2t_info *r2t;
1621 struct iscsi_data_task *dtask;
1624 if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) {
1625 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR;
1626 tcp_ctask->xmstate |= XMSTATE_SOL_DATA;
1627 if (!tcp_ctask->r2t)
1628 __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t,
1631 r2t = tcp_ctask->r2t;
1632 dtask = &r2t->dtask;
1634 if (conn->hdrdgst_en)
1635 iscsi_hdr_digest(conn, &r2t->headbuf,
1636 (u8*)dtask->hdrext);
1637 rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count);
1639 tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA;
1640 tcp_ctask->xmstate |= XMSTATE_SOL_HDR;
1644 if (conn->datadgst_en) {
1645 iscsi_data_digest_init(conn->dd_data, tcp_ctask);
1649 iscsi_set_padding(tcp_ctask, r2t->data_count);
1650 debug_scsi("sol dout [dsn %d itt 0x%x dlen %d sent %d]\n",
1651 r2t->solicit_datasn - 1, ctask->itt, r2t->data_count,
1655 if (tcp_ctask->xmstate & XMSTATE_SOL_DATA) {
1656 r2t = tcp_ctask->r2t;
1657 dtask = &r2t->dtask;
1659 rc = iscsi_send_data(ctask, &r2t->sendbuf, &r2t->sg,
1660 &r2t->sent, &r2t->data_count,
1661 &dtask->digestbuf, &dtask->digest);
1664 tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA;
1667 * Done with this Data-Out. Next, check if we have
1668 * to send another Data-Out for this R2T.
1670 BUG_ON(r2t->data_length - r2t->sent < 0);
1671 left = r2t->data_length - r2t->sent;
1673 iscsi_solicit_data_cont(conn, ctask, r2t, left);
1674 tcp_ctask->xmstate |= XMSTATE_SOL_DATA;
1675 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR;
1680 * Done with this R2T. Check if there are more
1681 * outstanding R2Ts ready to be processed.
1683 spin_lock_bh(&session->lock);
1684 tcp_ctask->r2t = NULL;
1685 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
1687 if (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t,
1689 tcp_ctask->r2t = r2t;
1690 tcp_ctask->xmstate |= XMSTATE_SOL_DATA;
1691 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR;
1692 spin_unlock_bh(&session->lock);
1695 spin_unlock_bh(&session->lock);
1701 iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1703 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1706 debug_scsi("ctask deq [cid %d xmstate %x itt 0x%x]\n",
1707 conn->id, tcp_ctask->xmstate, ctask->itt);
1710 * serialize with TMF AbortTask
1715 if (tcp_ctask->xmstate & XMSTATE_R_HDR)
1716 return iscsi_send_read_hdr(conn, tcp_ctask);
1718 if (tcp_ctask->xmstate & XMSTATE_W_HDR) {
1719 rc = iscsi_send_write_hdr(conn, ctask);
1724 if (tcp_ctask->xmstate & XMSTATE_IMM_DATA) {
1725 rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg,
1726 &tcp_ctask->sent, &ctask->imm_count,
1727 &tcp_ctask->immbuf, &tcp_ctask->immdigest);
1730 tcp_ctask->xmstate &= ~XMSTATE_IMM_DATA;
1733 rc = iscsi_send_unsol_pdu(conn, ctask);
1737 rc = iscsi_send_sol_pdu(conn, ctask);
1744 static struct iscsi_cls_conn *
1745 iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1747 struct iscsi_conn *conn;
1748 struct iscsi_cls_conn *cls_conn;
1749 struct iscsi_tcp_conn *tcp_conn;
1751 cls_conn = iscsi_conn_setup(cls_session, conn_idx);
1754 conn = cls_conn->dd_data;
1756 * due to strange issues with iser these are not set
1757 * in iscsi_conn_setup
1759 conn->max_recv_dlength = DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH;
1761 tcp_conn = kzalloc(sizeof(*tcp_conn), GFP_KERNEL);
1763 goto tcp_conn_alloc_fail;
1765 conn->dd_data = tcp_conn;
1766 tcp_conn->iscsi_conn = conn;
1767 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
1768 /* initial operational parameters */
1769 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1771 tcp_conn->tx_tfm = crypto_alloc_tfm("crc32c", 0);
1772 if (!tcp_conn->tx_tfm)
1775 tcp_conn->rx_tfm = crypto_alloc_tfm("crc32c", 0);
1776 if (!tcp_conn->rx_tfm)
1782 crypto_free_tfm(tcp_conn->tx_tfm);
1785 tcp_conn_alloc_fail:
1786 iscsi_conn_teardown(cls_conn);
1791 iscsi_tcp_release_conn(struct iscsi_conn *conn)
1793 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1795 if (!tcp_conn->sock)
1798 sock_hold(tcp_conn->sock->sk);
1799 iscsi_conn_restore_callbacks(tcp_conn);
1800 sock_put(tcp_conn->sock->sk);
1802 sock_release(tcp_conn->sock);
1803 tcp_conn->sock = NULL;
1804 conn->recv_lock = NULL;
1808 iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1810 struct iscsi_conn *conn = cls_conn->dd_data;
1811 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1814 if (conn->hdrdgst_en || conn->datadgst_en)
1817 iscsi_tcp_release_conn(conn);
1818 iscsi_conn_teardown(cls_conn);
1820 /* now free tcp_conn */
1822 if (tcp_conn->tx_tfm)
1823 crypto_free_tfm(tcp_conn->tx_tfm);
1824 if (tcp_conn->rx_tfm)
1825 crypto_free_tfm(tcp_conn->rx_tfm);
1832 iscsi_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
1834 struct iscsi_conn *conn = cls_conn->dd_data;
1835 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1837 iscsi_conn_stop(cls_conn, flag);
1838 iscsi_tcp_release_conn(conn);
1839 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1843 iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1844 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
1847 struct iscsi_conn *conn = cls_conn->dd_data;
1848 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1850 struct socket *sock;
1853 /* lookup for existing socket */
1854 sock = sockfd_lookup((int)transport_eph, &err);
1856 printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err);
1860 err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
1864 /* bind iSCSI connection and socket */
1865 tcp_conn->sock = sock;
1867 /* setup Socket parameters */
1870 sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */
1871 sk->sk_allocation = GFP_ATOMIC;
1873 /* FIXME: disable Nagle's algorithm */
1876 * Intercept TCP callbacks for sendfile like receive
1879 conn->recv_lock = &sk->sk_callback_lock;
1880 iscsi_conn_set_callbacks(conn);
1881 tcp_conn->sendpage = tcp_conn->sock->ops->sendpage;
1883 * set receive state machine into initial state
1885 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
1890 /* called with host lock */
1892 iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask,
1893 char *data, uint32_t data_size)
1895 struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data;
1897 iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr,
1898 sizeof(struct iscsi_hdr));
1899 tcp_mtask->xmstate = XMSTATE_IMM_HDR;
1900 tcp_mtask->sent = 0;
1902 if (mtask->data_count)
1903 iscsi_buf_init_iov(&tcp_mtask->sendbuf, (char*)mtask->data,
1908 iscsi_r2tpool_alloc(struct iscsi_session *session)
1914 * initialize per-task: R2T pool and xmit queue
1916 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
1917 struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
1918 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1921 * pre-allocated x4 as much r2ts to handle race when
1922 * target acks DataOut faster than we data_xmit() queues
1923 * could replenish r2tqueue.
1927 if (iscsi_pool_init(&tcp_ctask->r2tpool, session->max_r2t * 4,
1928 (void***)&tcp_ctask->r2ts,
1929 sizeof(struct iscsi_r2t_info))) {
1930 goto r2t_alloc_fail;
1933 /* R2T xmit queue */
1934 tcp_ctask->r2tqueue = kfifo_alloc(
1935 session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL);
1936 if (tcp_ctask->r2tqueue == ERR_PTR(-ENOMEM)) {
1937 iscsi_pool_free(&tcp_ctask->r2tpool,
1938 (void**)tcp_ctask->r2ts);
1939 goto r2t_alloc_fail;
1946 for (i = 0; i < cmd_i; i++) {
1947 struct iscsi_cmd_task *ctask = session->cmds[i];
1948 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1950 kfifo_free(tcp_ctask->r2tqueue);
1951 iscsi_pool_free(&tcp_ctask->r2tpool,
1952 (void**)tcp_ctask->r2ts);
1958 iscsi_r2tpool_free(struct iscsi_session *session)
1962 for (i = 0; i < session->cmds_max; i++) {
1963 struct iscsi_cmd_task *ctask = session->cmds[i];
1964 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1966 kfifo_free(tcp_ctask->r2tqueue);
1967 iscsi_pool_free(&tcp_ctask->r2tpool,
1968 (void**)tcp_ctask->r2ts);
1973 iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
1974 char *buf, int buflen)
1976 struct iscsi_conn *conn = cls_conn->dd_data;
1977 struct iscsi_session *session = conn->session;
1978 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1982 case ISCSI_PARAM_HDRDGST_EN:
1983 iscsi_set_param(cls_conn, param, buf, buflen);
1984 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1985 if (conn->hdrdgst_en)
1986 tcp_conn->hdr_size += sizeof(__u32);
1988 case ISCSI_PARAM_DATADGST_EN:
1989 iscsi_set_param(cls_conn, param, buf, buflen);
1990 tcp_conn->sendpage = conn->datadgst_en ?
1991 sock_no_sendpage : tcp_conn->sock->ops->sendpage;
1993 case ISCSI_PARAM_MAX_R2T:
1994 sscanf(buf, "%d", &value);
1995 if (session->max_r2t == roundup_pow_of_two(value))
1997 iscsi_r2tpool_free(session);
1998 iscsi_set_param(cls_conn, param, buf, buflen);
1999 if (session->max_r2t & (session->max_r2t - 1))
2000 session->max_r2t = roundup_pow_of_two(session->max_r2t);
2001 if (iscsi_r2tpool_alloc(session))
2005 return iscsi_set_param(cls_conn, param, buf, buflen);
2012 iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
2013 enum iscsi_param param, char *buf)
2015 struct iscsi_conn *conn = cls_conn->dd_data;
2016 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2017 struct inet_sock *inet;
2018 struct ipv6_pinfo *np;
2023 case ISCSI_PARAM_CONN_PORT:
2024 mutex_lock(&conn->xmitmutex);
2025 if (!tcp_conn->sock) {
2026 mutex_unlock(&conn->xmitmutex);
2030 inet = inet_sk(tcp_conn->sock->sk);
2031 len = sprintf(buf, "%hu\n", be16_to_cpu(inet->dport));
2032 mutex_unlock(&conn->xmitmutex);
2034 case ISCSI_PARAM_CONN_ADDRESS:
2035 mutex_lock(&conn->xmitmutex);
2036 if (!tcp_conn->sock) {
2037 mutex_unlock(&conn->xmitmutex);
2041 sk = tcp_conn->sock->sk;
2042 if (sk->sk_family == PF_INET) {
2044 len = sprintf(buf, "%u.%u.%u.%u\n",
2045 NIPQUAD(inet->daddr));
2049 "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
2052 mutex_unlock(&conn->xmitmutex);
2055 return iscsi_conn_get_param(cls_conn, param, buf);
2062 iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
2064 struct iscsi_conn *conn = cls_conn->dd_data;
2065 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2067 stats->txdata_octets = conn->txdata_octets;
2068 stats->rxdata_octets = conn->rxdata_octets;
2069 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
2070 stats->dataout_pdus = conn->dataout_pdus_cnt;
2071 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
2072 stats->datain_pdus = conn->datain_pdus_cnt;
2073 stats->r2t_pdus = conn->r2t_pdus_cnt;
2074 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
2075 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
2076 stats->custom_length = 3;
2077 strcpy(stats->custom[0].desc, "tx_sendpage_failures");
2078 stats->custom[0].value = tcp_conn->sendpage_failures_cnt;
2079 strcpy(stats->custom[1].desc, "rx_discontiguous_hdr");
2080 stats->custom[1].value = tcp_conn->discontiguous_hdr_cnt;
2081 strcpy(stats->custom[2].desc, "eh_abort_cnt");
2082 stats->custom[2].value = conn->eh_abort_cnt;
2085 static struct iscsi_cls_session *
2086 iscsi_tcp_session_create(struct iscsi_transport *iscsit,
2087 struct scsi_transport_template *scsit,
2088 uint32_t initial_cmdsn, uint32_t *hostno)
2090 struct iscsi_cls_session *cls_session;
2091 struct iscsi_session *session;
2095 cls_session = iscsi_session_setup(iscsit, scsit,
2096 sizeof(struct iscsi_tcp_cmd_task),
2097 sizeof(struct iscsi_tcp_mgmt_task),
2098 initial_cmdsn, &hn);
2103 session = class_to_transport_session(cls_session);
2104 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
2105 struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
2106 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
2108 ctask->hdr = &tcp_ctask->hdr;
2111 for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) {
2112 struct iscsi_mgmt_task *mtask = session->mgmt_cmds[cmd_i];
2113 struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data;
2115 mtask->hdr = &tcp_mtask->hdr;
2118 if (iscsi_r2tpool_alloc(class_to_transport_session(cls_session)))
2119 goto r2tpool_alloc_fail;
2124 iscsi_session_teardown(cls_session);
2128 static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session)
2130 iscsi_r2tpool_free(class_to_transport_session(cls_session));
2131 iscsi_session_teardown(cls_session);
2134 static struct scsi_host_template iscsi_sht = {
2135 .name = "iSCSI Initiator over TCP/IP",
2136 .queuecommand = iscsi_queuecommand,
2137 .change_queue_depth = iscsi_change_queue_depth,
2138 .can_queue = ISCSI_XMIT_CMDS_MAX - 1,
2139 .sg_tablesize = ISCSI_SG_TABLESIZE,
2140 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
2141 .eh_abort_handler = iscsi_eh_abort,
2142 .eh_host_reset_handler = iscsi_eh_host_reset,
2143 .use_clustering = DISABLE_CLUSTERING,
2144 .proc_name = "iscsi_tcp",
2148 static struct iscsi_transport iscsi_tcp_transport = {
2149 .owner = THIS_MODULE,
2151 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
2153 .param_mask = ISCSI_MAX_RECV_DLENGTH |
2154 ISCSI_MAX_XMIT_DLENGTH |
2157 ISCSI_INITIAL_R2T_EN |
2162 ISCSI_PDU_INORDER_EN |
2163 ISCSI_DATASEQ_INORDER_EN |
2166 ISCSI_CONN_ADDRESS |
2168 ISCSI_PERSISTENT_PORT |
2169 ISCSI_PERSISTENT_ADDRESS |
2172 .host_template = &iscsi_sht,
2173 .conndata_size = sizeof(struct iscsi_conn),
2175 .max_cmd_len = ISCSI_TCP_MAX_CMD_LEN,
2176 /* session management */
2177 .create_session = iscsi_tcp_session_create,
2178 .destroy_session = iscsi_tcp_session_destroy,
2179 /* connection management */
2180 .create_conn = iscsi_tcp_conn_create,
2181 .bind_conn = iscsi_tcp_conn_bind,
2182 .destroy_conn = iscsi_tcp_conn_destroy,
2183 .set_param = iscsi_conn_set_param,
2184 .get_conn_param = iscsi_tcp_conn_get_param,
2185 .get_session_param = iscsi_session_get_param,
2186 .start_conn = iscsi_conn_start,
2187 .stop_conn = iscsi_tcp_conn_stop,
2189 .send_pdu = iscsi_conn_send_pdu,
2190 .get_stats = iscsi_conn_get_stats,
2191 .init_cmd_task = iscsi_tcp_cmd_init,
2192 .init_mgmt_task = iscsi_tcp_mgmt_init,
2193 .xmit_cmd_task = iscsi_tcp_ctask_xmit,
2194 .xmit_mgmt_task = iscsi_tcp_mtask_xmit,
2195 .cleanup_cmd_task = iscsi_tcp_cleanup_ctask,
2197 .session_recovery_timedout = iscsi_session_recovery_timedout,
2201 iscsi_tcp_init(void)
2203 if (iscsi_max_lun < 1) {
2204 printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n",
2208 iscsi_tcp_transport.max_lun = iscsi_max_lun;
2210 if (!iscsi_register_transport(&iscsi_tcp_transport))
2217 iscsi_tcp_exit(void)
2219 iscsi_unregister_transport(&iscsi_tcp_transport);
2222 module_init(iscsi_tcp_init);
2223 module_exit(iscsi_tcp_exit);