Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * iSCSI Initiator over TCP/IP Data-Path |
| 3 | * |
| 4 | * Copyright (C) 2004 Dmitry Yusupov |
| 5 | * Copyright (C) 2004 Alex Aizman |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 6 | * Copyright (C) 2005 - 2006 Mike Christie |
| 7 | * Copyright (C) 2006 Red Hat, Inc. All rights reserved. |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 8 | * maintained by open-iscsi@googlegroups.com |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | * |
| 20 | * See the file COPYING included with this distribution for more details. |
| 21 | * |
| 22 | * Credits: |
| 23 | * Christoph Hellwig |
| 24 | * FUJITA Tomonori |
| 25 | * Arne Redlich |
| 26 | * Zhenyu Wang |
| 27 | */ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/list.h> |
| 31 | #include <linux/inet.h> |
Mike Christie | 4e7aba7 | 2007-05-30 12:57:23 -0500 | [diff] [blame] | 32 | #include <linux/file.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 33 | #include <linux/blkdev.h> |
| 34 | #include <linux/crypto.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/kfifo.h> |
| 37 | #include <linux/scatterlist.h> |
| 38 | #include <net/tcp.h> |
| 39 | #include <scsi/scsi_cmnd.h> |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 40 | #include <scsi/scsi_device.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 41 | #include <scsi/scsi_host.h> |
| 42 | #include <scsi/scsi.h> |
| 43 | #include <scsi/scsi_transport_iscsi.h> |
| 44 | |
| 45 | #include "iscsi_tcp.h" |
| 46 | |
| 47 | MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 48 | "Alex Aizman <itn780@yahoo.com>"); |
| 49 | MODULE_DESCRIPTION("iSCSI/TCP data-path"); |
| 50 | MODULE_LICENSE("GPL"); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 51 | /* #define DEBUG_TCP */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 52 | #define DEBUG_ASSERT |
| 53 | |
| 54 | #ifdef DEBUG_TCP |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 55 | #define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 56 | #else |
| 57 | #define debug_tcp(fmt...) |
| 58 | #endif |
| 59 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 60 | #ifndef DEBUG_ASSERT |
| 61 | #ifdef BUG_ON |
| 62 | #undef BUG_ON |
| 63 | #endif |
| 64 | #define BUG_ON(expr) |
| 65 | #endif |
| 66 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 67 | static unsigned int iscsi_max_lun = 512; |
| 68 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); |
| 69 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 70 | static inline void |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 71 | iscsi_buf_init_iov(struct iscsi_buf *ibuf, char *vbuf, int size) |
| 72 | { |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 73 | ibuf->sg.page = virt_to_page(vbuf); |
| 74 | ibuf->sg.offset = offset_in_page(vbuf); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 75 | ibuf->sg.length = size; |
| 76 | ibuf->sent = 0; |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 77 | ibuf->use_sendmsg = 1; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static inline void |
| 81 | iscsi_buf_init_sg(struct iscsi_buf *ibuf, struct scatterlist *sg) |
| 82 | { |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 83 | ibuf->sg.page = sg->page; |
| 84 | ibuf->sg.offset = sg->offset; |
| 85 | ibuf->sg.length = sg->length; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Fastpath: sg element fits into single page |
| 88 | */ |
Mike Christie | a1e80c2 | 2006-01-13 18:05:56 -0600 | [diff] [blame] | 89 | if (sg->length + sg->offset <= PAGE_SIZE && !PageSlab(sg->page)) |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 90 | ibuf->use_sendmsg = 0; |
| 91 | else |
| 92 | ibuf->use_sendmsg = 1; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 93 | ibuf->sent = 0; |
| 94 | } |
| 95 | |
| 96 | static inline int |
| 97 | iscsi_buf_left(struct iscsi_buf *ibuf) |
| 98 | { |
| 99 | int rc; |
| 100 | |
| 101 | rc = ibuf->sg.length - ibuf->sent; |
| 102 | BUG_ON(rc < 0); |
| 103 | return rc; |
| 104 | } |
| 105 | |
| 106 | static inline void |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 107 | iscsi_hdr_digest(struct iscsi_conn *conn, struct iscsi_buf *buf, |
| 108 | u8* crc) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 109 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 110 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 111 | |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 112 | crypto_hash_digest(&tcp_conn->tx_hash, &buf->sg, buf->sg.length, crc); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 113 | buf->sg.length += sizeof(u32); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 116 | static inline int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 117 | iscsi_hdr_extract(struct iscsi_tcp_conn *tcp_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 118 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 119 | struct sk_buff *skb = tcp_conn->in.skb; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 120 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 121 | tcp_conn->in.zero_copy_hdr = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 122 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 123 | if (tcp_conn->in.copy >= tcp_conn->hdr_size && |
| 124 | tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 125 | /* |
| 126 | * Zero-copy PDU Header: using connection context |
| 127 | * to store header pointer. |
| 128 | */ |
| 129 | if (skb_shinfo(skb)->frag_list == NULL && |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 130 | !skb_shinfo(skb)->nr_frags) { |
| 131 | tcp_conn->in.hdr = (struct iscsi_hdr *) |
| 132 | ((char*)skb->data + tcp_conn->in.offset); |
| 133 | tcp_conn->in.zero_copy_hdr = 1; |
| 134 | } else { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 135 | /* ignoring return code since we checked |
| 136 | * in.copy before */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 137 | skb_copy_bits(skb, tcp_conn->in.offset, |
| 138 | &tcp_conn->hdr, tcp_conn->hdr_size); |
| 139 | tcp_conn->in.hdr = &tcp_conn->hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 140 | } |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 141 | tcp_conn->in.offset += tcp_conn->hdr_size; |
| 142 | tcp_conn->in.copy -= tcp_conn->hdr_size; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 143 | } else { |
| 144 | int hdr_remains; |
| 145 | int copylen; |
| 146 | |
| 147 | /* |
| 148 | * PDU header scattered across SKB's, |
| 149 | * copying it... This'll happen quite rarely. |
| 150 | */ |
| 151 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 152 | if (tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER) |
| 153 | tcp_conn->in.hdr_offset = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 154 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 155 | hdr_remains = tcp_conn->hdr_size - tcp_conn->in.hdr_offset; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 156 | BUG_ON(hdr_remains <= 0); |
| 157 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 158 | copylen = min(tcp_conn->in.copy, hdr_remains); |
| 159 | skb_copy_bits(skb, tcp_conn->in.offset, |
| 160 | (char*)&tcp_conn->hdr + tcp_conn->in.hdr_offset, |
| 161 | copylen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 162 | |
| 163 | debug_tcp("PDU gather offset %d bytes %d in.offset %d " |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 164 | "in.copy %d\n", tcp_conn->in.hdr_offset, copylen, |
| 165 | tcp_conn->in.offset, tcp_conn->in.copy); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 166 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 167 | tcp_conn->in.offset += copylen; |
| 168 | tcp_conn->in.copy -= copylen; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 169 | if (copylen < hdr_remains) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 170 | tcp_conn->in_progress = IN_PROGRESS_HEADER_GATHER; |
| 171 | tcp_conn->in.hdr_offset += copylen; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 172 | return -EAGAIN; |
| 173 | } |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 174 | tcp_conn->in.hdr = &tcp_conn->hdr; |
| 175 | tcp_conn->discontiguous_hdr_cnt++; |
| 176 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 182 | /* |
| 183 | * must be called with session lock |
| 184 | */ |
| 185 | static void |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 186 | iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 187 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 188 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 189 | struct iscsi_r2t_info *r2t; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 190 | struct scsi_cmnd *sc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 191 | |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 192 | /* flush ctask's r2t queues */ |
| 193 | while (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*))) { |
| 194 | __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t, |
| 195 | sizeof(void*)); |
| 196 | debug_scsi("iscsi_tcp_cleanup_ctask pending r2t dropped\n"); |
| 197 | } |
| 198 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 199 | sc = ctask->sc; |
| 200 | if (unlikely(!sc)) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 201 | return; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 202 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 203 | tcp_ctask->xmstate = XMSTATE_IDLE; |
| 204 | tcp_ctask->r2t = NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /** |
| 208 | * iscsi_data_rsp - SCSI Data-In Response processing |
| 209 | * @conn: iscsi connection |
| 210 | * @ctask: scsi command task |
| 211 | **/ |
| 212 | static int |
| 213 | iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
| 214 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 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; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 218 | struct iscsi_session *session = conn->session; |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 219 | struct scsi_cmnd *sc = ctask->sc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 220 | int datasn = be32_to_cpu(rhdr->datasn); |
| 221 | |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 222 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 223 | /* |
| 224 | * setup Data-In byte counter (gets decremented..) |
| 225 | */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 226 | ctask->data_count = tcp_conn->in.datalen; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 227 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 228 | if (tcp_conn->in.datalen == 0) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 229 | return 0; |
| 230 | |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 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); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 234 | return ISCSI_ERR_DATASN; |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 235 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 236 | |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 237 | tcp_ctask->exp_datasn++; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 238 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 239 | tcp_ctask->data_offset = be32_to_cpu(rhdr->offset); |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 240 | if (tcp_ctask->data_offset + tcp_conn->in.datalen > scsi_bufflen(sc)) { |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 241 | debug_tcp("%s: data_offset(%d) + data_len(%d) > total_length_in(%d)\n", |
| 242 | __FUNCTION__, tcp_ctask->data_offset, |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 243 | tcp_conn->in.datalen, scsi_bufflen(sc)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 244 | return ISCSI_ERR_DATA_OFFSET; |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 245 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 246 | |
| 247 | if (rhdr->flags & ISCSI_FLAG_DATA_STATUS) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 248 | conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; |
zhenyu.z.wang@intel.com | bf310b8 | 2006-01-13 18:05:38 -0600 | [diff] [blame] | 249 | if (rhdr->flags & ISCSI_FLAG_DATA_UNDERFLOW) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 250 | int res_count = be32_to_cpu(rhdr->residual_count); |
| 251 | |
| 252 | if (res_count > 0 && |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 253 | res_count <= scsi_bufflen(sc)) { |
| 254 | scsi_set_resid(sc, res_count); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 255 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
| 256 | } else |
| 257 | sc->result = (DID_BAD_TARGET << 16) | |
| 258 | rhdr->cmd_status; |
zhenyu.z.wang@intel.com | bf310b8 | 2006-01-13 18:05:38 -0600 | [diff] [blame] | 259 | } else if (rhdr->flags & ISCSI_FLAG_DATA_OVERFLOW) { |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 260 | scsi_set_resid(sc, be32_to_cpu(rhdr->residual_count)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 261 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
| 262 | } else |
| 263 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
| 264 | } |
| 265 | |
| 266 | conn->datain_pdus_cnt++; |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * iscsi_solicit_data_init - initialize first Data-Out |
| 272 | * @conn: iscsi connection |
| 273 | * @ctask: scsi command task |
| 274 | * @r2t: R2T info |
| 275 | * |
| 276 | * Notes: |
| 277 | * Initialize first Data-Out within this R2T sequence and finds |
| 278 | * proper data_offset within this SCSI command. |
| 279 | * |
| 280 | * This function is called with connection lock taken. |
| 281 | **/ |
| 282 | static void |
| 283 | iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, |
| 284 | struct iscsi_r2t_info *r2t) |
| 285 | { |
| 286 | struct iscsi_data *hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 287 | struct scsi_cmnd *sc = ctask->sc; |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 288 | int i, sg_count = 0; |
| 289 | struct scatterlist *sg; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 290 | |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 291 | hdr = &r2t->dtask.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 292 | memset(hdr, 0, sizeof(struct iscsi_data)); |
| 293 | hdr->ttt = r2t->ttt; |
| 294 | hdr->datasn = cpu_to_be32(r2t->solicit_datasn); |
| 295 | r2t->solicit_datasn++; |
| 296 | hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 297 | memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun)); |
| 298 | hdr->itt = ctask->hdr->itt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 299 | hdr->exp_statsn = r2t->exp_statsn; |
| 300 | hdr->offset = cpu_to_be32(r2t->data_offset); |
| 301 | if (r2t->data_length > conn->max_xmit_dlength) { |
| 302 | hton24(hdr->dlength, conn->max_xmit_dlength); |
| 303 | r2t->data_count = conn->max_xmit_dlength; |
| 304 | hdr->flags = 0; |
| 305 | } else { |
| 306 | hton24(hdr->dlength, r2t->data_length); |
| 307 | r2t->data_count = r2t->data_length; |
| 308 | hdr->flags = ISCSI_FLAG_CMD_FINAL; |
| 309 | } |
| 310 | conn->dataout_pdus_cnt++; |
| 311 | |
| 312 | r2t->sent = 0; |
| 313 | |
Mike Christie | 6e458cc | 2006-05-18 20:31:31 -0500 | [diff] [blame] | 314 | iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr, |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 315 | sizeof(struct iscsi_hdr)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 316 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 317 | sg = scsi_sglist(sc); |
| 318 | r2t->sg = NULL; |
| 319 | for (i = 0; i < scsi_sg_count(sc); i++, sg += 1) { |
| 320 | /* FIXME: prefetch ? */ |
| 321 | if (sg_count + sg->length > r2t->data_offset) { |
| 322 | int page_offset; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 323 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 324 | /* sg page found! */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 325 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 326 | /* offset within this page */ |
| 327 | page_offset = r2t->data_offset - sg_count; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 328 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 329 | /* fill in this buffer */ |
| 330 | iscsi_buf_init_sg(&r2t->sendbuf, sg); |
| 331 | r2t->sendbuf.sg.offset += page_offset; |
| 332 | r2t->sendbuf.sg.length -= page_offset; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 333 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 334 | /* xmit logic will continue with next one */ |
| 335 | r2t->sg = sg + 1; |
| 336 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 337 | } |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 338 | sg_count += sg->length; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 339 | } |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 340 | BUG_ON(r2t->sg == NULL); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** |
| 344 | * iscsi_r2t_rsp - iSCSI R2T Response processing |
| 345 | * @conn: iscsi connection |
| 346 | * @ctask: scsi command task |
| 347 | **/ |
| 348 | static int |
| 349 | iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
| 350 | { |
| 351 | struct iscsi_r2t_info *r2t; |
| 352 | struct iscsi_session *session = conn->session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 353 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 354 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 355 | struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 356 | int r2tsn = be32_to_cpu(rhdr->r2tsn); |
| 357 | int rc; |
| 358 | |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 359 | if (tcp_conn->in.datalen) { |
| 360 | printk(KERN_ERR "iscsi_tcp: invalid R2t with datalen %d\n", |
| 361 | tcp_conn->in.datalen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 362 | return ISCSI_ERR_DATALEN; |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 363 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 364 | |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 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); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 368 | return ISCSI_ERR_R2TSN; |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 369 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 370 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 371 | /* fill-in new R2T associated with the task */ |
| 372 | spin_lock(&session->lock); |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 373 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); |
| 374 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 375 | if (!ctask->sc || ctask->mtask || |
| 376 | session->state != ISCSI_STATE_LOGGED_IN) { |
| 377 | printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in " |
| 378 | "recovery...\n", ctask->itt); |
| 379 | spin_unlock(&session->lock); |
| 380 | return 0; |
| 381 | } |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 382 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 383 | rc = __kfifo_get(tcp_ctask->r2tpool.queue, (void*)&r2t, sizeof(void*)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 384 | BUG_ON(!rc); |
| 385 | |
| 386 | r2t->exp_statsn = rhdr->statsn; |
| 387 | r2t->data_length = be32_to_cpu(rhdr->data_length); |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 388 | if (r2t->data_length == 0) { |
| 389 | printk(KERN_ERR "iscsi_tcp: invalid R2T with zero data len\n"); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 390 | spin_unlock(&session->lock); |
| 391 | return ISCSI_ERR_DATALEN; |
| 392 | } |
| 393 | |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 394 | if (r2t->data_length > session->max_burst) |
| 395 | debug_scsi("invalid R2T with data len %u and max burst %u." |
| 396 | "Attempting to execute request.\n", |
| 397 | r2t->data_length, session->max_burst); |
| 398 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 399 | r2t->data_offset = be32_to_cpu(rhdr->data_offset); |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 400 | if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 401 | spin_unlock(&session->lock); |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 402 | printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at " |
| 403 | "offset %u and total length %d\n", r2t->data_length, |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 404 | r2t->data_offset, scsi_bufflen(ctask->sc)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 405 | return ISCSI_ERR_DATALEN; |
| 406 | } |
| 407 | |
| 408 | r2t->ttt = rhdr->ttt; /* no flip */ |
| 409 | r2t->solicit_datasn = 0; |
| 410 | |
| 411 | iscsi_solicit_data_init(conn, ctask, r2t); |
| 412 | |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 413 | tcp_ctask->exp_datasn = r2tsn + 1; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 414 | __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 415 | tcp_ctask->xmstate |= XMSTATE_SOL_HDR_INIT; |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 416 | list_move_tail(&ctask->running, &conn->xmitqueue); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 417 | |
Mike Christie | 55e3299 | 2006-01-13 18:05:53 -0600 | [diff] [blame] | 418 | scsi_queue_work(session->host, &conn->xmitwork); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 419 | conn->r2t_pdus_cnt++; |
| 420 | spin_unlock(&session->lock); |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 426 | iscsi_tcp_hdr_recv(struct iscsi_conn *conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 427 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 428 | int rc = 0, opcode, ahslen; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 429 | struct iscsi_hdr *hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 430 | struct iscsi_session *session = conn->session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 431 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 432 | uint32_t cdgst, rdgst = 0, itt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 433 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 434 | hdr = tcp_conn->in.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 435 | |
| 436 | /* verify PDU length */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 437 | tcp_conn->in.datalen = ntoh24(hdr->dlength); |
| 438 | if (tcp_conn->in.datalen > conn->max_recv_dlength) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 439 | printk(KERN_ERR "iscsi_tcp: datalen %d > %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 440 | tcp_conn->in.datalen, conn->max_recv_dlength); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 441 | return ISCSI_ERR_DATALEN; |
| 442 | } |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 443 | tcp_conn->data_copied = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 444 | |
| 445 | /* read AHS */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 446 | ahslen = hdr->hlength << 2; |
| 447 | tcp_conn->in.offset += ahslen; |
| 448 | tcp_conn->in.copy -= ahslen; |
| 449 | if (tcp_conn->in.copy < 0) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 450 | printk(KERN_ERR "iscsi_tcp: can't handle AHS with length " |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 451 | "%d bytes\n", ahslen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 452 | return ISCSI_ERR_AHSLEN; |
| 453 | } |
| 454 | |
| 455 | /* calculate read padding */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 456 | tcp_conn->in.padding = tcp_conn->in.datalen & (ISCSI_PAD_LEN-1); |
| 457 | if (tcp_conn->in.padding) { |
| 458 | tcp_conn->in.padding = ISCSI_PAD_LEN - tcp_conn->in.padding; |
| 459 | debug_scsi("read padding %d bytes\n", tcp_conn->in.padding); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | if (conn->hdrdgst_en) { |
| 463 | struct scatterlist sg; |
| 464 | |
| 465 | sg_init_one(&sg, (u8 *)hdr, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 466 | sizeof(struct iscsi_hdr) + ahslen); |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 467 | crypto_hash_digest(&tcp_conn->rx_hash, &sg, sg.length, |
| 468 | (u8 *)&cdgst); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 469 | rdgst = *(uint32_t*)((char*)hdr + sizeof(struct iscsi_hdr) + |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 470 | ahslen); |
Mike Christie | 8a47cd3 | 2005-11-30 02:27:19 -0600 | [diff] [blame] | 471 | if (cdgst != rdgst) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 472 | printk(KERN_ERR "iscsi_tcp: hdrdgst error " |
| 473 | "recv 0x%x calc 0x%x\n", rdgst, cdgst); |
Mike Christie | 8a47cd3 | 2005-11-30 02:27:19 -0600 | [diff] [blame] | 474 | return ISCSI_ERR_HDR_DGST; |
| 475 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 478 | opcode = hdr->opcode & ISCSI_OPCODE_MASK; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 479 | /* verify itt (itt encoding: age+cid+itt) */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 480 | rc = iscsi_verify_itt(conn, hdr, &itt); |
| 481 | if (rc == ISCSI_ERR_NO_SCSI_CMD) { |
| 482 | tcp_conn->in.datalen = 0; /* force drop */ |
| 483 | return 0; |
| 484 | } else if (rc) |
| 485 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 486 | |
| 487 | debug_tcp("opcode 0x%x offset %d copy %d ahslen %d datalen %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 488 | opcode, tcp_conn->in.offset, tcp_conn->in.copy, |
| 489 | ahslen, tcp_conn->in.datalen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 490 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 491 | switch(opcode) { |
| 492 | case ISCSI_OP_SCSI_DATA_IN: |
| 493 | tcp_conn->in.ctask = session->cmds[itt]; |
| 494 | rc = iscsi_data_rsp(conn, tcp_conn->in.ctask); |
Mike Christie | 275fd7d | 2006-07-24 15:47:17 -0500 | [diff] [blame] | 495 | if (rc) |
| 496 | return rc; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 497 | /* fall through */ |
| 498 | case ISCSI_OP_SCSI_CMD_RSP: |
| 499 | tcp_conn->in.ctask = session->cmds[itt]; |
| 500 | if (tcp_conn->in.datalen) |
| 501 | goto copy_hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 502 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 503 | spin_lock(&session->lock); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 504 | rc = __iscsi_complete_pdu(conn, hdr, NULL, 0); |
| 505 | spin_unlock(&session->lock); |
| 506 | break; |
| 507 | case ISCSI_OP_R2T: |
| 508 | tcp_conn->in.ctask = session->cmds[itt]; |
| 509 | if (ahslen) |
| 510 | rc = ISCSI_ERR_AHSLEN; |
| 511 | else if (tcp_conn->in.ctask->sc->sc_data_direction == |
| 512 | DMA_TO_DEVICE) |
| 513 | rc = iscsi_r2t_rsp(conn, tcp_conn->in.ctask); |
| 514 | else |
| 515 | rc = ISCSI_ERR_PROTO; |
| 516 | break; |
| 517 | case ISCSI_OP_LOGIN_RSP: |
| 518 | case ISCSI_OP_TEXT_RSP: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 519 | case ISCSI_OP_REJECT: |
| 520 | case ISCSI_OP_ASYNC_EVENT: |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 521 | /* |
| 522 | * It is possible that we could get a PDU with a buffer larger |
| 523 | * than 8K, but there are no targets that currently do this. |
| 524 | * For now we fail until we find a vendor that needs it |
| 525 | */ |
Mike Christie | bf32ed3 | 2007-02-28 17:32:17 -0600 | [diff] [blame] | 526 | if (ISCSI_DEF_MAX_RECV_SEG_LEN < |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 527 | tcp_conn->in.datalen) { |
| 528 | printk(KERN_ERR "iscsi_tcp: received buffer of len %u " |
| 529 | "but conn buffer is only %u (opcode %0x)\n", |
| 530 | tcp_conn->in.datalen, |
Mike Christie | bf32ed3 | 2007-02-28 17:32:17 -0600 | [diff] [blame] | 531 | ISCSI_DEF_MAX_RECV_SEG_LEN, opcode); |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 532 | rc = ISCSI_ERR_PROTO; |
| 533 | break; |
| 534 | } |
| 535 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 536 | if (tcp_conn->in.datalen) |
| 537 | goto copy_hdr; |
| 538 | /* fall through */ |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 539 | case ISCSI_OP_LOGOUT_RSP: |
| 540 | case ISCSI_OP_NOOP_IN: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 541 | case ISCSI_OP_SCSI_TMFUNC_RSP: |
| 542 | rc = iscsi_complete_pdu(conn, hdr, NULL, 0); |
| 543 | break; |
| 544 | default: |
| 545 | rc = ISCSI_ERR_BAD_OPCODE; |
| 546 | break; |
| 547 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 548 | |
| 549 | return rc; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 550 | |
| 551 | copy_hdr: |
| 552 | /* |
| 553 | * if we did zero copy for the header but we will need multiple |
| 554 | * skbs to complete the command then we have to copy the header |
| 555 | * for later use |
| 556 | */ |
Mike Christie | 275fd7d | 2006-07-24 15:47:17 -0500 | [diff] [blame] | 557 | if (tcp_conn->in.zero_copy_hdr && tcp_conn->in.copy <= |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 558 | (tcp_conn->in.datalen + tcp_conn->in.padding + |
| 559 | (conn->datadgst_en ? 4 : 0))) { |
| 560 | debug_tcp("Copying header for later use. in.copy %d in.datalen" |
| 561 | " %d\n", tcp_conn->in.copy, tcp_conn->in.datalen); |
| 562 | memcpy(&tcp_conn->hdr, tcp_conn->in.hdr, |
| 563 | sizeof(struct iscsi_hdr)); |
| 564 | tcp_conn->in.hdr = &tcp_conn->hdr; |
| 565 | tcp_conn->in.zero_copy_hdr = 0; |
| 566 | } |
| 567 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
| 571 | * iscsi_ctask_copy - copy skb bits to the destanation cmd task |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 572 | * @conn: iscsi tcp connection |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 573 | * @ctask: scsi command task |
| 574 | * @buf: buffer to copy to |
| 575 | * @buf_size: size of buffer |
| 576 | * @offset: offset within the buffer |
| 577 | * |
| 578 | * Notes: |
| 579 | * The function calls skb_copy_bits() and updates per-connection and |
| 580 | * per-cmd byte counters. |
| 581 | * |
| 582 | * Read counters (in bytes): |
| 583 | * |
| 584 | * conn->in.offset offset within in progress SKB |
| 585 | * conn->in.copy left to copy from in progress SKB |
| 586 | * including padding |
| 587 | * conn->in.copied copied already from in progress SKB |
| 588 | * conn->data_copied copied already from in progress buffer |
| 589 | * ctask->sent total bytes sent up to the MidLayer |
| 590 | * ctask->data_count left to copy from in progress Data-In |
| 591 | * buf_left left to copy from in progress buffer |
| 592 | **/ |
| 593 | static inline int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 594 | iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 595 | void *buf, int buf_size, int offset) |
| 596 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 597 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 598 | int buf_left = buf_size - (tcp_conn->data_copied + offset); |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 599 | unsigned size = min(tcp_conn->in.copy, buf_left); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 600 | int rc; |
| 601 | |
| 602 | size = min(size, ctask->data_count); |
| 603 | |
| 604 | debug_tcp("ctask_copy %d bytes at offset %d copied %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 605 | size, tcp_conn->in.offset, tcp_conn->in.copied); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 606 | |
| 607 | BUG_ON(size <= 0); |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 608 | BUG_ON(tcp_ctask->sent + size > scsi_bufflen(ctask->sc)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 609 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 610 | rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset, |
| 611 | (char*)buf + (offset + tcp_conn->data_copied), size); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 612 | /* must fit into skb->len */ |
| 613 | BUG_ON(rc); |
| 614 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 615 | tcp_conn->in.offset += size; |
| 616 | tcp_conn->in.copy -= size; |
| 617 | tcp_conn->in.copied += size; |
| 618 | tcp_conn->data_copied += size; |
| 619 | tcp_ctask->sent += size; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 620 | ctask->data_count -= size; |
| 621 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 622 | BUG_ON(tcp_conn->in.copy < 0); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 623 | BUG_ON(ctask->data_count < 0); |
| 624 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 625 | if (buf_size != (tcp_conn->data_copied + offset)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 626 | if (!ctask->data_count) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 627 | BUG_ON(buf_size - tcp_conn->data_copied < 0); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 628 | /* done with this PDU */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 629 | return buf_size - tcp_conn->data_copied; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 630 | } |
| 631 | return -EAGAIN; |
| 632 | } |
| 633 | |
| 634 | /* done with this buffer or with both - PDU and buffer */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 635 | tcp_conn->data_copied = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * iscsi_tcp_copy - copy skb bits to the destanation buffer |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 641 | * @conn: iscsi tcp connection |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 642 | * |
| 643 | * Notes: |
| 644 | * The function calls skb_copy_bits() and updates per-connection |
| 645 | * byte counters. |
| 646 | **/ |
| 647 | static inline int |
Mike Christie | ca51868 | 2006-08-31 18:09:32 -0400 | [diff] [blame] | 648 | iscsi_tcp_copy(struct iscsi_conn *conn, int buf_size) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 649 | { |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 650 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 651 | int buf_left = buf_size - tcp_conn->data_copied; |
| 652 | int size = min(tcp_conn->in.copy, buf_left); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 653 | int rc; |
| 654 | |
| 655 | debug_tcp("tcp_copy %d bytes at offset %d copied %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 656 | size, tcp_conn->in.offset, tcp_conn->data_copied); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 657 | BUG_ON(size <= 0); |
| 658 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 659 | rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset, |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 660 | (char*)conn->data + tcp_conn->data_copied, size); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 661 | BUG_ON(rc); |
| 662 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 663 | tcp_conn->in.offset += size; |
| 664 | tcp_conn->in.copy -= size; |
| 665 | tcp_conn->in.copied += size; |
| 666 | tcp_conn->data_copied += size; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 667 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 668 | if (buf_size != tcp_conn->data_copied) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 669 | return -EAGAIN; |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static inline void |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 675 | partial_sg_digest_update(struct hash_desc *desc, struct scatterlist *sg, |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 676 | int offset, int length) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 677 | { |
| 678 | struct scatterlist temp; |
| 679 | |
| 680 | memcpy(&temp, sg, sizeof(struct scatterlist)); |
| 681 | temp.offset = offset; |
| 682 | temp.length = length; |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 683 | crypto_hash_update(desc, &temp, length); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 686 | static void |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 687 | iscsi_recv_digest_update(struct iscsi_tcp_conn *tcp_conn, char* buf, int len) |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 688 | { |
| 689 | struct scatterlist tmp; |
| 690 | |
| 691 | sg_init_one(&tmp, buf, len); |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 692 | crypto_hash_update(&tcp_conn->rx_hash, &tmp, len); |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 693 | } |
| 694 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 695 | static int iscsi_scsi_data_in(struct iscsi_conn *conn) |
| 696 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 697 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 698 | struct iscsi_cmd_task *ctask = tcp_conn->in.ctask; |
| 699 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 700 | struct scsi_cmnd *sc = ctask->sc; |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 701 | struct scatterlist *sg; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 702 | int i, offset, rc = 0; |
| 703 | |
| 704 | BUG_ON((void*)ctask != sc->SCp.ptr); |
| 705 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 706 | offset = tcp_ctask->data_offset; |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 707 | sg = scsi_sglist(sc); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 708 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 709 | if (tcp_ctask->data_offset) |
| 710 | for (i = 0; i < tcp_ctask->sg_count; i++) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 711 | offset -= sg[i].length; |
| 712 | /* we've passed through partial sg*/ |
| 713 | if (offset < 0) |
| 714 | offset = 0; |
| 715 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 716 | for (i = tcp_ctask->sg_count; i < scsi_sg_count(sc); i++) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 717 | char *dest; |
| 718 | |
| 719 | dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 720 | rc = iscsi_ctask_copy(tcp_conn, ctask, dest + sg[i].offset, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 721 | sg[i].length, offset); |
| 722 | kunmap_atomic(dest, KM_SOFTIRQ0); |
| 723 | if (rc == -EAGAIN) |
| 724 | /* continue with the next SKB/PDU */ |
| 725 | return rc; |
| 726 | if (!rc) { |
| 727 | if (conn->datadgst_en) { |
| 728 | if (!offset) |
Herbert Xu | dc64ddf | 2006-08-24 18:45:50 +1000 | [diff] [blame] | 729 | crypto_hash_update( |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 730 | &tcp_conn->rx_hash, |
Arne Redlich | c959e1c | 2006-12-17 12:10:24 -0600 | [diff] [blame] | 731 | &sg[i], sg[i].length); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 732 | else |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 733 | partial_sg_digest_update( |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 734 | &tcp_conn->rx_hash, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 735 | &sg[i], |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 736 | sg[i].offset + offset, |
| 737 | sg[i].length - offset); |
| 738 | } |
| 739 | offset = 0; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 740 | tcp_ctask->sg_count++; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | if (!ctask->data_count) { |
| 744 | if (rc && conn->datadgst_en) |
| 745 | /* |
| 746 | * data-in is complete, but buffer not... |
| 747 | */ |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 748 | partial_sg_digest_update(&tcp_conn->rx_hash, |
| 749 | &sg[i], |
| 750 | sg[i].offset, |
| 751 | sg[i].length-rc); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 752 | rc = 0; |
| 753 | break; |
| 754 | } |
| 755 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 756 | if (!tcp_conn->in.copy) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 757 | return -EAGAIN; |
| 758 | } |
| 759 | BUG_ON(ctask->data_count); |
| 760 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 761 | /* check for non-exceptional status */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 762 | if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) { |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 763 | debug_scsi("done [sc %lx res %d itt 0x%x flags 0x%x]\n", |
| 764 | (long)sc, sc->result, ctask->itt, |
| 765 | tcp_conn->in.hdr->flags); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 766 | spin_lock(&conn->session->lock); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 767 | __iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0); |
| 768 | spin_unlock(&conn->session->lock); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | return rc; |
| 772 | } |
| 773 | |
| 774 | static int |
| 775 | iscsi_data_recv(struct iscsi_conn *conn) |
| 776 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 777 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 778 | int rc = 0, opcode; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 779 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 780 | opcode = tcp_conn->in.hdr->opcode & ISCSI_OPCODE_MASK; |
| 781 | switch (opcode) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 782 | case ISCSI_OP_SCSI_DATA_IN: |
| 783 | rc = iscsi_scsi_data_in(conn); |
| 784 | break; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 785 | case ISCSI_OP_SCSI_CMD_RSP: |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 786 | case ISCSI_OP_TEXT_RSP: |
| 787 | case ISCSI_OP_LOGIN_RSP: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 788 | case ISCSI_OP_ASYNC_EVENT: |
| 789 | case ISCSI_OP_REJECT: |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 790 | /* |
| 791 | * Collect data segment to the connection's data |
| 792 | * placeholder |
| 793 | */ |
Mike Christie | ca51868 | 2006-08-31 18:09:32 -0400 | [diff] [blame] | 794 | if (iscsi_tcp_copy(conn, tcp_conn->in.datalen)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 795 | rc = -EAGAIN; |
| 796 | goto exit; |
| 797 | } |
| 798 | |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 799 | rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, conn->data, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 800 | tcp_conn->in.datalen); |
| 801 | if (!rc && conn->datadgst_en && opcode != ISCSI_OP_LOGIN_RSP) |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 802 | iscsi_recv_digest_update(tcp_conn, conn->data, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 803 | tcp_conn->in.datalen); |
| 804 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 805 | default: |
| 806 | BUG_ON(1); |
| 807 | } |
| 808 | exit: |
| 809 | return rc; |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * iscsi_tcp_data_recv - TCP receive in sendfile fashion |
| 814 | * @rd_desc: read descriptor |
| 815 | * @skb: socket buffer |
| 816 | * @offset: offset in skb |
| 817 | * @len: skb->len - offset |
| 818 | **/ |
| 819 | static int |
| 820 | iscsi_tcp_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, |
| 821 | unsigned int offset, size_t len) |
| 822 | { |
| 823 | int rc; |
| 824 | struct iscsi_conn *conn = rd_desc->arg.data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 825 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 826 | int processed; |
| 827 | char pad[ISCSI_PAD_LEN]; |
| 828 | struct scatterlist sg; |
| 829 | |
| 830 | /* |
| 831 | * Save current SKB and its offset in the corresponding |
| 832 | * connection context. |
| 833 | */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 834 | tcp_conn->in.copy = skb->len - offset; |
| 835 | tcp_conn->in.offset = offset; |
| 836 | tcp_conn->in.skb = skb; |
| 837 | tcp_conn->in.len = tcp_conn->in.copy; |
| 838 | BUG_ON(tcp_conn->in.copy <= 0); |
| 839 | debug_tcp("in %d bytes\n", tcp_conn->in.copy); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 840 | |
| 841 | more: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 842 | tcp_conn->in.copied = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 843 | rc = 0; |
| 844 | |
| 845 | if (unlikely(conn->suspend_rx)) { |
| 846 | debug_tcp("conn %d Rx suspended!\n", conn->id); |
| 847 | return 0; |
| 848 | } |
| 849 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 850 | if (tcp_conn->in_progress == IN_PROGRESS_WAIT_HEADER || |
| 851 | tcp_conn->in_progress == IN_PROGRESS_HEADER_GATHER) { |
| 852 | rc = iscsi_hdr_extract(tcp_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 853 | if (rc) { |
| 854 | if (rc == -EAGAIN) |
| 855 | goto nomore; |
| 856 | else { |
Mike Christie | d82967c | 2006-07-24 15:47:11 -0500 | [diff] [blame] | 857 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 858 | return 0; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * Verify and process incoming PDU header. |
| 864 | */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 865 | rc = iscsi_tcp_hdr_recv(conn); |
| 866 | if (!rc && tcp_conn->in.datalen) { |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 867 | if (conn->datadgst_en) |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 868 | crypto_hash_init(&tcp_conn->rx_hash); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 869 | tcp_conn->in_progress = IN_PROGRESS_DATA_RECV; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 870 | } else if (rc) { |
Mike Christie | 40527af | 2006-07-24 15:47:45 -0500 | [diff] [blame] | 871 | iscsi_conn_failure(conn, rc); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 872 | return 0; |
| 873 | } |
| 874 | } |
| 875 | |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 876 | if (tcp_conn->in_progress == IN_PROGRESS_DDIGEST_RECV && |
| 877 | tcp_conn->in.copy) { |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 878 | uint32_t recv_digest; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 879 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 880 | debug_tcp("extra data_recv offset %d copy %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 881 | tcp_conn->in.offset, tcp_conn->in.copy); |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 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 | |
Mike Christie | ca51868 | 2006-08-31 18:09:32 -0400 | [diff] [blame] | 897 | rc = iscsi_tcp_copy(conn, sizeof(uint32_t)); |
| 898 | if (rc) { |
| 899 | if (rc == -EAGAIN) |
| 900 | goto again; |
| 901 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | memcpy(&recv_digest, conn->data, sizeof(uint32_t)); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 906 | if (recv_digest != tcp_conn->in.datadgst) { |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 907 | debug_tcp("iscsi_tcp: data digest error!" |
| 908 | "0x%x != 0x%x\n", recv_digest, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 909 | tcp_conn->in.datadgst); |
Mike Christie | f6cfba1 | 2005-11-29 23:12:57 -0600 | [diff] [blame] | 910 | iscsi_conn_failure(conn, ISCSI_ERR_DATA_DGST); |
| 911 | return 0; |
| 912 | } else { |
| 913 | debug_tcp("iscsi_tcp: data digest match!" |
| 914 | "0x%x == 0x%x\n", recv_digest, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 915 | tcp_conn->in.datadgst); |
| 916 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 920 | if (tcp_conn->in_progress == IN_PROGRESS_DATA_RECV && |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 921 | tcp_conn->in.copy) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 922 | debug_tcp("data_recv offset %d copy %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 923 | tcp_conn->in.offset, tcp_conn->in.copy); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 924 | |
| 925 | rc = iscsi_data_recv(conn); |
| 926 | if (rc) { |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 927 | if (rc == -EAGAIN) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 928 | goto again; |
Mike Christie | d82967c | 2006-07-24 15:47:11 -0500 | [diff] [blame] | 929 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 930 | return 0; |
| 931 | } |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 932 | |
| 933 | if (tcp_conn->in.padding) |
| 934 | tcp_conn->in_progress = IN_PROGRESS_PAD_RECV; |
| 935 | else if (conn->datadgst_en) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 936 | tcp_conn->in_progress = IN_PROGRESS_DDIGEST_RECV; |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 937 | else |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 938 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 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; |
| 957 | tcp_conn->data_copied = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | debug_tcp("f, processed %d from out of %d padding %d\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 961 | tcp_conn->in.offset - offset, (int)len, tcp_conn->in.padding); |
| 962 | BUG_ON(tcp_conn->in.offset - offset > len); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 963 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 964 | if (tcp_conn->in.offset - offset != len) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 965 | debug_tcp("continue to process %d bytes\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 966 | (int)len - (tcp_conn->in.offset - offset)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 967 | goto more; |
| 968 | } |
| 969 | |
| 970 | nomore: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 971 | processed = tcp_conn->in.offset - offset; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 972 | BUG_ON(processed == 0); |
| 973 | return processed; |
| 974 | |
| 975 | again: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 976 | processed = tcp_conn->in.offset - offset; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 977 | debug_tcp("c, processed %d from out of %d rd_desc_cnt %d\n", |
| 978 | processed, (int)len, (int)rd_desc->count); |
| 979 | BUG_ON(processed == 0); |
| 980 | BUG_ON(processed > len); |
| 981 | |
| 982 | conn->rxdata_octets += processed; |
| 983 | return processed; |
| 984 | } |
| 985 | |
| 986 | static void |
| 987 | iscsi_tcp_data_ready(struct sock *sk, int flag) |
| 988 | { |
| 989 | struct iscsi_conn *conn = sk->sk_user_data; |
| 990 | read_descriptor_t rd_desc; |
| 991 | |
| 992 | read_lock(&sk->sk_callback_lock); |
| 993 | |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 994 | /* |
| 995 | * Use rd_desc to pass 'conn' to iscsi_tcp_data_recv. |
| 996 | * We set count to 1 because we want the network layer to |
| 997 | * hand us all the skbs that are available. iscsi_tcp_data_recv |
| 998 | * handled pdus that cross buffers or pdus that still need data. |
| 999 | */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1000 | rd_desc.arg.data = conn; |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 1001 | rd_desc.count = 1; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1002 | tcp_read_sock(sk, &rd_desc, iscsi_tcp_data_recv); |
| 1003 | |
| 1004 | read_unlock(&sk->sk_callback_lock); |
| 1005 | } |
| 1006 | |
| 1007 | static void |
| 1008 | iscsi_tcp_state_change(struct sock *sk) |
| 1009 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1010 | struct iscsi_tcp_conn *tcp_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1011 | struct iscsi_conn *conn; |
| 1012 | struct iscsi_session *session; |
| 1013 | void (*old_state_change)(struct sock *); |
| 1014 | |
| 1015 | read_lock(&sk->sk_callback_lock); |
| 1016 | |
| 1017 | conn = (struct iscsi_conn*)sk->sk_user_data; |
| 1018 | session = conn->session; |
| 1019 | |
Mike Christie | e627399 | 2005-11-29 23:12:49 -0600 | [diff] [blame] | 1020 | if ((sk->sk_state == TCP_CLOSE_WAIT || |
| 1021 | sk->sk_state == TCP_CLOSE) && |
| 1022 | !atomic_read(&sk->sk_rmem_alloc)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1023 | debug_tcp("iscsi_tcp_state_change: TCP_CLOSE|TCP_CLOSE_WAIT\n"); |
| 1024 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 1025 | } |
| 1026 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1027 | tcp_conn = conn->dd_data; |
| 1028 | old_state_change = tcp_conn->old_state_change; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1029 | |
| 1030 | read_unlock(&sk->sk_callback_lock); |
| 1031 | |
| 1032 | old_state_change(sk); |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * iscsi_write_space - Called when more output buffer space is available |
| 1037 | * @sk: socket space is available for |
| 1038 | **/ |
| 1039 | static void |
| 1040 | iscsi_write_space(struct sock *sk) |
| 1041 | { |
| 1042 | struct iscsi_conn *conn = (struct iscsi_conn*)sk->sk_user_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1043 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1044 | |
| 1045 | tcp_conn->old_write_space(sk); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1046 | debug_tcp("iscsi_write_space: cid %d\n", conn->id); |
Mike Christie | 55e3299 | 2006-01-13 18:05:53 -0600 | [diff] [blame] | 1047 | scsi_queue_work(conn->session->host, &conn->xmitwork); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | static void |
| 1051 | iscsi_conn_set_callbacks(struct iscsi_conn *conn) |
| 1052 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1053 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1054 | struct sock *sk = tcp_conn->sock->sk; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1055 | |
| 1056 | /* assign new callbacks */ |
| 1057 | write_lock_bh(&sk->sk_callback_lock); |
| 1058 | sk->sk_user_data = conn; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1059 | tcp_conn->old_data_ready = sk->sk_data_ready; |
| 1060 | tcp_conn->old_state_change = sk->sk_state_change; |
| 1061 | tcp_conn->old_write_space = sk->sk_write_space; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1062 | sk->sk_data_ready = iscsi_tcp_data_ready; |
| 1063 | sk->sk_state_change = iscsi_tcp_state_change; |
| 1064 | sk->sk_write_space = iscsi_write_space; |
| 1065 | write_unlock_bh(&sk->sk_callback_lock); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1069 | iscsi_conn_restore_callbacks(struct iscsi_tcp_conn *tcp_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1070 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1071 | struct sock *sk = tcp_conn->sock->sk; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1072 | |
| 1073 | /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */ |
| 1074 | write_lock_bh(&sk->sk_callback_lock); |
| 1075 | sk->sk_user_data = NULL; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1076 | sk->sk_data_ready = tcp_conn->old_data_ready; |
| 1077 | sk->sk_state_change = tcp_conn->old_state_change; |
| 1078 | sk->sk_write_space = tcp_conn->old_write_space; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1079 | sk->sk_no_check = 0; |
| 1080 | write_unlock_bh(&sk->sk_callback_lock); |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * iscsi_send - generic send routine |
| 1085 | * @sk: kernel's socket |
| 1086 | * @buf: buffer to write from |
| 1087 | * @size: actual size to write |
| 1088 | * @flags: socket's flags |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1089 | */ |
| 1090 | static inline int |
FUJITA Tomonori | 5685169 | 2006-01-13 18:05:44 -0600 | [diff] [blame] | 1091 | iscsi_send(struct iscsi_conn *conn, struct iscsi_buf *buf, int size, int flags) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1092 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1093 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1094 | struct socket *sk = tcp_conn->sock; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1095 | int offset = buf->sg.offset + buf->sent, res; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1096 | |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 1097 | /* |
| 1098 | * if we got use_sg=0 or are sending something we kmallocd |
| 1099 | * then we did not have to do kmap (kmap returns page_address) |
| 1100 | * |
| 1101 | * if we got use_sg > 0, but had to drop down, we do not |
| 1102 | * set clustering so this should only happen for that |
| 1103 | * slab case. |
| 1104 | */ |
| 1105 | if (buf->use_sendmsg) |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1106 | res = sock_no_sendpage(sk, buf->sg.page, offset, size, flags); |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 1107 | else |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1108 | res = tcp_conn->sendpage(sk, buf->sg.page, offset, size, flags); |
| 1109 | |
| 1110 | if (res >= 0) { |
| 1111 | conn->txdata_octets += res; |
| 1112 | buf->sent += res; |
| 1113 | return res; |
| 1114 | } |
| 1115 | |
| 1116 | tcp_conn->sendpage_failures_cnt++; |
| 1117 | if (res == -EAGAIN) |
| 1118 | res = -ENOBUFS; |
| 1119 | else |
| 1120 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 1121 | return res; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * iscsi_sendhdr - send PDU Header via tcp_sendpage() |
| 1126 | * @conn: iscsi connection |
| 1127 | * @buf: buffer to write from |
| 1128 | * @datalen: lenght of data to be sent after the header |
| 1129 | * |
| 1130 | * Notes: |
| 1131 | * (Tx, Fast Path) |
| 1132 | **/ |
| 1133 | static inline int |
| 1134 | iscsi_sendhdr(struct iscsi_conn *conn, struct iscsi_buf *buf, int datalen) |
| 1135 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1136 | int flags = 0; /* MSG_DONTWAIT; */ |
| 1137 | int res, size; |
| 1138 | |
| 1139 | size = buf->sg.length - buf->sent; |
| 1140 | BUG_ON(buf->sent + size > buf->sg.length); |
| 1141 | if (buf->sent + size != buf->sg.length || datalen) |
| 1142 | flags |= MSG_MORE; |
| 1143 | |
FUJITA Tomonori | 5685169 | 2006-01-13 18:05:44 -0600 | [diff] [blame] | 1144 | res = iscsi_send(conn, buf, size, flags); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1145 | debug_tcp("sendhdr %d bytes, sent %d res %d\n", size, buf->sent, res); |
| 1146 | if (res >= 0) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1147 | if (size != res) |
| 1148 | return -EAGAIN; |
| 1149 | return 0; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1150 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1151 | |
| 1152 | return res; |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * iscsi_sendpage - send one page of iSCSI Data-Out. |
| 1157 | * @conn: iscsi connection |
| 1158 | * @buf: buffer to write from |
| 1159 | * @count: remaining data |
| 1160 | * @sent: number of bytes sent |
| 1161 | * |
| 1162 | * Notes: |
| 1163 | * (Tx, Fast Path) |
| 1164 | **/ |
| 1165 | static inline int |
| 1166 | iscsi_sendpage(struct iscsi_conn *conn, struct iscsi_buf *buf, |
| 1167 | int *count, int *sent) |
| 1168 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1169 | int flags = 0; /* MSG_DONTWAIT; */ |
| 1170 | int res, size; |
| 1171 | |
| 1172 | size = buf->sg.length - buf->sent; |
| 1173 | BUG_ON(buf->sent + size > buf->sg.length); |
| 1174 | if (size > *count) |
| 1175 | size = *count; |
Mike Christie | b13941f | 2005-09-12 21:01:28 -0500 | [diff] [blame] | 1176 | if (buf->sent + size != buf->sg.length || *count != size) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1177 | flags |= MSG_MORE; |
| 1178 | |
FUJITA Tomonori | 5685169 | 2006-01-13 18:05:44 -0600 | [diff] [blame] | 1179 | res = iscsi_send(conn, buf, size, flags); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1180 | debug_tcp("sendpage: %d bytes, sent %d left %d sent %d res %d\n", |
| 1181 | size, buf->sent, *count, *sent, res); |
| 1182 | if (res >= 0) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1183 | *count -= res; |
| 1184 | *sent += res; |
| 1185 | if (size != res) |
| 1186 | return -EAGAIN; |
| 1187 | return 0; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1188 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1189 | |
| 1190 | return res; |
| 1191 | } |
| 1192 | |
| 1193 | static inline void |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1194 | iscsi_data_digest_init(struct iscsi_tcp_conn *tcp_conn, |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1195 | struct iscsi_tcp_cmd_task *tcp_ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1196 | { |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1197 | crypto_hash_init(&tcp_conn->tx_hash); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1198 | tcp_ctask->digest_count = 4; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1201 | /** |
| 1202 | * iscsi_solicit_data_cont - initialize next Data-Out |
| 1203 | * @conn: iscsi connection |
| 1204 | * @ctask: scsi command task |
| 1205 | * @r2t: R2T info |
| 1206 | * @left: bytes left to transfer |
| 1207 | * |
| 1208 | * Notes: |
| 1209 | * Initialize next Data-Out within this R2T sequence and continue |
| 1210 | * to process next Scatter-Gather element(if any) of this SCSI command. |
| 1211 | * |
| 1212 | * Called under connection lock. |
| 1213 | **/ |
| 1214 | static void |
| 1215 | iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, |
| 1216 | struct iscsi_r2t_info *r2t, int left) |
| 1217 | { |
| 1218 | struct iscsi_data *hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1219 | int new_offset; |
| 1220 | |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 1221 | hdr = &r2t->dtask.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1222 | memset(hdr, 0, sizeof(struct iscsi_data)); |
| 1223 | hdr->ttt = r2t->ttt; |
| 1224 | hdr->datasn = cpu_to_be32(r2t->solicit_datasn); |
| 1225 | r2t->solicit_datasn++; |
| 1226 | hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1227 | memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun)); |
| 1228 | hdr->itt = ctask->hdr->itt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1229 | hdr->exp_statsn = r2t->exp_statsn; |
| 1230 | new_offset = r2t->data_offset + r2t->sent; |
| 1231 | hdr->offset = cpu_to_be32(new_offset); |
| 1232 | if (left > conn->max_xmit_dlength) { |
| 1233 | hton24(hdr->dlength, conn->max_xmit_dlength); |
| 1234 | r2t->data_count = conn->max_xmit_dlength; |
| 1235 | } else { |
| 1236 | hton24(hdr->dlength, left); |
| 1237 | r2t->data_count = left; |
| 1238 | hdr->flags = ISCSI_FLAG_CMD_FINAL; |
| 1239 | } |
| 1240 | conn->dataout_pdus_cnt++; |
| 1241 | |
Mike Christie | 6e458cc | 2006-05-18 20:31:31 -0500 | [diff] [blame] | 1242 | iscsi_buf_init_iov(&r2t->headbuf, (char*)hdr, |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 1243 | sizeof(struct iscsi_hdr)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1244 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1245 | if (iscsi_buf_left(&r2t->sendbuf)) |
| 1246 | return; |
| 1247 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 1248 | iscsi_buf_init_sg(&r2t->sendbuf, r2t->sg); |
| 1249 | r2t->sg += 1; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1252 | static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask, |
| 1253 | unsigned long len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1254 | { |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1255 | tcp_ctask->pad_count = len & (ISCSI_PAD_LEN - 1); |
| 1256 | if (!tcp_ctask->pad_count) |
| 1257 | return; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1258 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1259 | tcp_ctask->pad_count = ISCSI_PAD_LEN - tcp_ctask->pad_count; |
| 1260 | debug_scsi("write padding %d bytes\n", tcp_ctask->pad_count); |
| 1261 | tcp_ctask->xmstate |= XMSTATE_W_PAD; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | /** |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1265 | * iscsi_tcp_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1266 | * @conn: iscsi connection |
| 1267 | * @ctask: scsi command task |
| 1268 | * @sc: scsi command |
| 1269 | **/ |
| 1270 | static void |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1271 | iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1272 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1273 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1274 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1275 | BUG_ON(__kfifo_len(tcp_ctask->r2tqueue)); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1276 | tcp_ctask->xmstate = XMSTATE_CMD_HDR_INIT; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | /** |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1280 | * iscsi_tcp_mtask_xmit - xmit management(immediate) task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1281 | * @conn: iscsi connection |
| 1282 | * @mtask: task management task |
| 1283 | * |
| 1284 | * Notes: |
| 1285 | * The function can return -EAGAIN in which case caller must |
| 1286 | * call it again later, or recover. '0' return code means successful |
| 1287 | * xmit. |
| 1288 | * |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1289 | * Management xmit state machine consists of these states: |
| 1290 | * XMSTATE_IMM_HDR_INIT - calculate digest of PDU Header |
| 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 |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1294 | **/ |
| 1295 | static int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1296 | iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1297 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1298 | struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1299 | int rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1300 | |
| 1301 | debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1302 | conn->id, tcp_mtask->xmstate, mtask->itt); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1303 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1304 | if (tcp_mtask->xmstate & XMSTATE_IMM_HDR_INIT) { |
| 1305 | iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr, |
| 1306 | sizeof(struct iscsi_hdr)); |
| 1307 | |
| 1308 | if (mtask->data_count) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1309 | tcp_mtask->xmstate |= XMSTATE_IMM_DATA; |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1310 | iscsi_buf_init_iov(&tcp_mtask->sendbuf, |
| 1311 | (char*)mtask->data, |
| 1312 | mtask->data_count); |
| 1313 | } |
| 1314 | |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 1315 | if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE && |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1316 | conn->stop_stage != STOP_CONN_RECOVER && |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 1317 | conn->hdrdgst_en) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1318 | iscsi_hdr_digest(conn, &tcp_mtask->headbuf, |
| 1319 | (u8*)tcp_mtask->hdrext); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 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) { |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1327 | rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf, |
| 1328 | mtask->data_count); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1329 | if (rc) |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1330 | return rc; |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1331 | tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1334 | if (tcp_mtask->xmstate & XMSTATE_IMM_DATA) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1335 | BUG_ON(!mtask->data_count); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1336 | tcp_mtask->xmstate &= ~XMSTATE_IMM_DATA; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1337 | /* FIXME: implement. |
| 1338 | * Virtual buffer could be spreaded across multiple pages... |
| 1339 | */ |
| 1340 | do { |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1341 | int rc; |
| 1342 | |
| 1343 | rc = iscsi_sendpage(conn, &tcp_mtask->sendbuf, |
| 1344 | &mtask->data_count, &tcp_mtask->sent); |
| 1345 | if (rc) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1346 | tcp_mtask->xmstate |= XMSTATE_IMM_DATA; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1347 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1348 | } |
| 1349 | } while (mtask->data_count); |
| 1350 | } |
| 1351 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1352 | BUG_ON(tcp_mtask->xmstate != XMSTATE_IDLE); |
Al Viro | b437735 | 2007-02-09 16:39:40 +0000 | [diff] [blame] | 1353 | if (mtask->hdr->itt == RESERVED_ITT) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1354 | struct iscsi_session *session = conn->session; |
| 1355 | |
| 1356 | spin_lock_bh(&session->lock); |
| 1357 | list_del(&conn->mtask->running); |
| 1358 | __kfifo_put(session->mgmtpool.queue, (void*)&conn->mtask, |
| 1359 | sizeof(void*)); |
| 1360 | spin_unlock_bh(&session->lock); |
| 1361 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1362 | return 0; |
| 1363 | } |
| 1364 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1365 | static int |
| 1366 | iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1367 | { |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1368 | struct scsi_cmnd *sc = ctask->sc; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1369 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1370 | int rc = 0; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1371 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1372 | if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_INIT) { |
| 1373 | tcp_ctask->sent = 0; |
| 1374 | tcp_ctask->sg_count = 0; |
| 1375 | tcp_ctask->exp_datasn = 0; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1376 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1377 | if (sc->sc_data_direction == DMA_TO_DEVICE) { |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 1378 | struct scatterlist *sg = scsi_sglist(sc); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1379 | |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 1380 | iscsi_buf_init_sg(&tcp_ctask->sendbuf, sg); |
| 1381 | tcp_ctask->sg = sg + 1; |
| 1382 | tcp_ctask->bad_sg = sg + scsi_sg_count(sc); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1383 | |
| 1384 | debug_scsi("cmd [itt 0x%x total %d imm_data %d " |
| 1385 | "unsol count %d, unsol offset %d]\n", |
FUJITA Tomonori | 1c13899 | 2007-06-14 22:13:17 +0900 | [diff] [blame] | 1386 | ctask->itt, scsi_bufflen(sc), |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1387 | ctask->imm_count, ctask->unsol_count, |
| 1388 | ctask->unsol_offset); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1389 | } |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 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; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1401 | if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_XMIT) { |
| 1402 | rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, 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); |
| 1413 | |
| 1414 | if (ctask->conn->datadgst_en) { |
| 1415 | iscsi_data_digest_init(ctask->conn->dd_data, |
| 1416 | tcp_ctask); |
| 1417 | tcp_ctask->immdigest = 0; |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | if (ctask->unsol_count) |
| 1422 | tcp_ctask->xmstate |= |
| 1423 | XMSTATE_UNS_HDR | XMSTATE_UNS_INIT; |
| 1424 | } |
| 1425 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1428 | static int |
| 1429 | iscsi_send_padding(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
| 1430 | { |
| 1431 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 1432 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1433 | int sent = 0, rc; |
| 1434 | |
| 1435 | if (tcp_ctask->xmstate & XMSTATE_W_PAD) { |
| 1436 | iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad, |
| 1437 | tcp_ctask->pad_count); |
| 1438 | if (conn->datadgst_en) |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1439 | crypto_hash_update(&tcp_conn->tx_hash, |
| 1440 | &tcp_ctask->sendbuf.sg, |
| 1441 | tcp_ctask->sendbuf.sg.length); |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1442 | } else if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_PAD)) |
| 1443 | return 0; |
| 1444 | |
| 1445 | tcp_ctask->xmstate &= ~XMSTATE_W_PAD; |
| 1446 | tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_PAD; |
| 1447 | debug_scsi("sending %d pad bytes for itt 0x%x\n", |
| 1448 | tcp_ctask->pad_count, ctask->itt); |
| 1449 | rc = iscsi_sendpage(conn, &tcp_ctask->sendbuf, &tcp_ctask->pad_count, |
| 1450 | &sent); |
| 1451 | if (rc) { |
| 1452 | debug_scsi("padding send failed %d\n", rc); |
| 1453 | tcp_ctask->xmstate |= XMSTATE_W_RESEND_PAD; |
| 1454 | } |
| 1455 | return rc; |
| 1456 | } |
| 1457 | |
| 1458 | static int |
| 1459 | iscsi_send_digest(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask, |
| 1460 | struct iscsi_buf *buf, uint32_t *digest) |
| 1461 | { |
| 1462 | struct iscsi_tcp_cmd_task *tcp_ctask; |
| 1463 | struct iscsi_tcp_conn *tcp_conn; |
| 1464 | int rc, sent = 0; |
| 1465 | |
| 1466 | if (!conn->datadgst_en) |
| 1467 | return 0; |
| 1468 | |
| 1469 | tcp_ctask = ctask->dd_data; |
| 1470 | tcp_conn = conn->dd_data; |
| 1471 | |
| 1472 | if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_DATA_DIGEST)) { |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1473 | crypto_hash_final(&tcp_conn->tx_hash, (u8*)digest); |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1474 | iscsi_buf_init_iov(buf, (char*)digest, 4); |
| 1475 | } |
| 1476 | tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_DATA_DIGEST; |
| 1477 | |
| 1478 | rc = iscsi_sendpage(conn, buf, &tcp_ctask->digest_count, &sent); |
| 1479 | if (!rc) |
| 1480 | debug_scsi("sent digest 0x%x for itt 0x%x\n", *digest, |
| 1481 | ctask->itt); |
| 1482 | else { |
| 1483 | debug_scsi("sending digest 0x%x failed for itt 0x%x!\n", |
| 1484 | *digest, ctask->itt); |
| 1485 | tcp_ctask->xmstate |= XMSTATE_W_RESEND_DATA_DIGEST; |
| 1486 | } |
| 1487 | return rc; |
| 1488 | } |
| 1489 | |
| 1490 | static int |
| 1491 | iscsi_send_data(struct iscsi_cmd_task *ctask, struct iscsi_buf *sendbuf, |
| 1492 | struct scatterlist **sg, int *sent, int *count, |
| 1493 | struct iscsi_buf *digestbuf, uint32_t *digest) |
| 1494 | { |
| 1495 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 1496 | struct iscsi_conn *conn = ctask->conn; |
| 1497 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1498 | int rc, buf_sent, offset; |
| 1499 | |
| 1500 | while (*count) { |
| 1501 | buf_sent = 0; |
| 1502 | offset = sendbuf->sent; |
| 1503 | |
| 1504 | rc = iscsi_sendpage(conn, sendbuf, count, &buf_sent); |
| 1505 | *sent = *sent + buf_sent; |
| 1506 | if (buf_sent && conn->datadgst_en) |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1507 | partial_sg_digest_update(&tcp_conn->tx_hash, |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1508 | &sendbuf->sg, sendbuf->sg.offset + offset, |
| 1509 | buf_sent); |
| 1510 | if (!iscsi_buf_left(sendbuf) && *sg != tcp_ctask->bad_sg) { |
| 1511 | iscsi_buf_init_sg(sendbuf, *sg); |
| 1512 | *sg = *sg + 1; |
| 1513 | } |
| 1514 | |
| 1515 | if (rc) |
| 1516 | return rc; |
| 1517 | } |
| 1518 | |
| 1519 | rc = iscsi_send_padding(conn, ctask); |
| 1520 | if (rc) |
| 1521 | return rc; |
| 1522 | |
| 1523 | return iscsi_send_digest(conn, ctask, digestbuf, digest); |
| 1524 | } |
| 1525 | |
| 1526 | static int |
| 1527 | iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1528 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1529 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1530 | struct iscsi_data_task *dtask; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1531 | int rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1532 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1533 | tcp_ctask->xmstate |= XMSTATE_UNS_DATA; |
| 1534 | if (tcp_ctask->xmstate & XMSTATE_UNS_INIT) { |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1535 | dtask = &tcp_ctask->unsol_dtask; |
| 1536 | |
Mike Christie | ffd0436 | 2006-08-31 18:09:24 -0400 | [diff] [blame] | 1537 | iscsi_prep_unsolicit_data_pdu(ctask, &dtask->hdr); |
| 1538 | iscsi_buf_init_iov(&tcp_ctask->headbuf, (char*)&dtask->hdr, |
| 1539 | sizeof(struct iscsi_hdr)); |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 1540 | if (conn->hdrdgst_en) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1541 | iscsi_hdr_digest(conn, &tcp_ctask->headbuf, |
Mike Christie | af97348 | 2005-09-12 21:01:32 -0500 | [diff] [blame] | 1542 | (u8*)dtask->hdrext); |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1543 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1544 | tcp_ctask->xmstate &= ~XMSTATE_UNS_INIT; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1545 | iscsi_set_padding(tcp_ctask, ctask->data_count); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1546 | } |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1547 | |
| 1548 | rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->data_count); |
| 1549 | if (rc) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1550 | tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA; |
| 1551 | tcp_ctask->xmstate |= XMSTATE_UNS_HDR; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1552 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1555 | if (conn->datadgst_en) { |
| 1556 | dtask = &tcp_ctask->unsol_dtask; |
| 1557 | iscsi_data_digest_init(ctask->conn->dd_data, tcp_ctask); |
| 1558 | dtask->digest = 0; |
| 1559 | } |
| 1560 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1561 | debug_scsi("uns dout [itt 0x%x dlen %d sent %d]\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1562 | ctask->itt, ctask->unsol_count, tcp_ctask->sent); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1563 | return 0; |
| 1564 | } |
| 1565 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1566 | static int |
| 1567 | iscsi_send_unsol_pdu(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1568 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1569 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1570 | int rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1571 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1572 | if (tcp_ctask->xmstate & XMSTATE_UNS_HDR) { |
| 1573 | BUG_ON(!ctask->unsol_count); |
| 1574 | tcp_ctask->xmstate &= ~XMSTATE_UNS_HDR; |
| 1575 | send_hdr: |
| 1576 | rc = iscsi_send_unsol_hdr(conn, ctask); |
| 1577 | if (rc) |
| 1578 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1581 | if (tcp_ctask->xmstate & XMSTATE_UNS_DATA) { |
| 1582 | struct iscsi_data_task *dtask = &tcp_ctask->unsol_dtask; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1583 | int start = tcp_ctask->sent; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1584 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1585 | rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg, |
| 1586 | &tcp_ctask->sent, &ctask->data_count, |
| 1587 | &dtask->digestbuf, &dtask->digest); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1588 | ctask->unsol_count -= tcp_ctask->sent - start; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1589 | if (rc) |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1590 | return rc; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1591 | tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA; |
| 1592 | /* |
| 1593 | * Done with the Data-Out. Next, check if we need |
| 1594 | * to send another unsolicited Data-Out. |
| 1595 | */ |
| 1596 | if (ctask->unsol_count) { |
| 1597 | debug_scsi("sending more uns\n"); |
| 1598 | tcp_ctask->xmstate |= XMSTATE_UNS_INIT; |
| 1599 | goto send_hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1600 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1601 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1602 | return 0; |
| 1603 | } |
| 1604 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1605 | static int iscsi_send_sol_pdu(struct iscsi_conn *conn, |
| 1606 | struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1607 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1608 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1609 | struct iscsi_session *session = conn->session; |
| 1610 | struct iscsi_r2t_info *r2t; |
| 1611 | struct iscsi_data_task *dtask; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1612 | int left, rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1613 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1614 | if (tcp_ctask->xmstate & XMSTATE_SOL_HDR_INIT) { |
Mike Christie | db37c50 | 2006-11-08 15:58:33 -0600 | [diff] [blame] | 1615 | if (!tcp_ctask->r2t) { |
| 1616 | spin_lock_bh(&session->lock); |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1617 | __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t, |
| 1618 | sizeof(void*)); |
Mike Christie | db37c50 | 2006-11-08 15:58:33 -0600 | [diff] [blame] | 1619 | spin_unlock_bh(&session->lock); |
| 1620 | } |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1621 | send_hdr: |
| 1622 | r2t = tcp_ctask->r2t; |
| 1623 | dtask = &r2t->dtask; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1624 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1625 | if (conn->hdrdgst_en) |
| 1626 | iscsi_hdr_digest(conn, &r2t->headbuf, |
| 1627 | (u8*)dtask->hdrext); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 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 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1636 | rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count); |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1637 | if (rc) |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1638 | return rc; |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1639 | tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; |
| 1640 | tcp_ctask->xmstate |= XMSTATE_SOL_DATA; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1641 | |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1642 | if (conn->datadgst_en) { |
| 1643 | iscsi_data_digest_init(conn->dd_data, tcp_ctask); |
| 1644 | dtask->digest = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1645 | } |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1646 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1647 | iscsi_set_padding(tcp_ctask, r2t->data_count); |
| 1648 | debug_scsi("sol dout [dsn %d itt 0x%x dlen %d sent %d]\n", |
| 1649 | r2t->solicit_datasn - 1, ctask->itt, r2t->data_count, |
| 1650 | r2t->sent); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1653 | if (tcp_ctask->xmstate & XMSTATE_SOL_DATA) { |
| 1654 | r2t = tcp_ctask->r2t; |
| 1655 | dtask = &r2t->dtask; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1656 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1657 | rc = iscsi_send_data(ctask, &r2t->sendbuf, &r2t->sg, |
| 1658 | &r2t->sent, &r2t->data_count, |
| 1659 | &dtask->digestbuf, &dtask->digest); |
| 1660 | if (rc) |
| 1661 | return rc; |
| 1662 | tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1663 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1664 | /* |
| 1665 | * Done with this Data-Out. Next, check if we have |
| 1666 | * to send another Data-Out for this R2T. |
| 1667 | */ |
| 1668 | BUG_ON(r2t->data_length - r2t->sent < 0); |
| 1669 | left = r2t->data_length - r2t->sent; |
| 1670 | if (left) { |
| 1671 | iscsi_solicit_data_cont(conn, ctask, r2t, left); |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1672 | goto send_hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1673 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1674 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1675 | /* |
| 1676 | * Done with this R2T. Check if there are more |
| 1677 | * outstanding R2Ts ready to be processed. |
| 1678 | */ |
| 1679 | spin_lock_bh(&session->lock); |
| 1680 | tcp_ctask->r2t = NULL; |
| 1681 | __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t, |
| 1682 | sizeof(void*)); |
| 1683 | if (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, |
| 1684 | sizeof(void*))) { |
| 1685 | tcp_ctask->r2t = r2t; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1686 | spin_unlock_bh(&session->lock); |
| 1687 | goto send_hdr; |
| 1688 | } |
| 1689 | spin_unlock_bh(&session->lock); |
| 1690 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1691 | return 0; |
| 1692 | } |
| 1693 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 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 | **/ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1734 | static int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1735 | iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1736 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1737 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1738 | int rc = 0; |
| 1739 | |
| 1740 | debug_scsi("ctask deq [cid %d xmstate %x itt 0x%x]\n", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1741 | conn->id, tcp_ctask->xmstate, ctask->itt); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1742 | |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1743 | rc = iscsi_send_cmd_hdr(conn, ctask); |
| 1744 | if (rc) |
| 1745 | return rc; |
| 1746 | if (ctask->sc->sc_data_direction != DMA_TO_DEVICE) |
| 1747 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1748 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1749 | if (tcp_ctask->xmstate & XMSTATE_IMM_DATA) { |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1750 | rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg, |
| 1751 | &tcp_ctask->sent, &ctask->imm_count, |
| 1752 | &tcp_ctask->immbuf, &tcp_ctask->immdigest); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1753 | if (rc) |
| 1754 | return rc; |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1755 | tcp_ctask->xmstate &= ~XMSTATE_IMM_DATA; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1758 | rc = iscsi_send_unsol_pdu(conn, ctask); |
| 1759 | if (rc) |
| 1760 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1761 | |
Mike Christie | 62f3830 | 2006-08-31 18:09:27 -0400 | [diff] [blame] | 1762 | rc = iscsi_send_sol_pdu(conn, ctask); |
| 1763 | if (rc) |
| 1764 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1765 | |
| 1766 | return rc; |
| 1767 | } |
| 1768 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1769 | static struct iscsi_cls_conn * |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1770 | iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1771 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1772 | struct iscsi_conn *conn; |
| 1773 | struct iscsi_cls_conn *cls_conn; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1774 | struct iscsi_tcp_conn *tcp_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1775 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1776 | cls_conn = iscsi_conn_setup(cls_session, conn_idx); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1777 | if (!cls_conn) |
| 1778 | return NULL; |
| 1779 | conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1780 | /* |
| 1781 | * due to strange issues with iser these are not set |
| 1782 | * in iscsi_conn_setup |
| 1783 | */ |
Mike Christie | bf32ed3 | 2007-02-28 17:32:17 -0600 | [diff] [blame] | 1784 | conn->max_recv_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1785 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1786 | tcp_conn = kzalloc(sizeof(*tcp_conn), GFP_KERNEL); |
| 1787 | if (!tcp_conn) |
| 1788 | goto tcp_conn_alloc_fail; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1789 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1790 | conn->dd_data = tcp_conn; |
| 1791 | tcp_conn->iscsi_conn = conn; |
| 1792 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
| 1793 | /* initial operational parameters */ |
| 1794 | tcp_conn->hdr_size = sizeof(struct iscsi_hdr); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1795 | |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1796 | tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 1797 | CRYPTO_ALG_ASYNC); |
| 1798 | tcp_conn->tx_hash.flags = 0; |
Mike Christie | 0f23841 | 2007-02-28 17:32:21 -0600 | [diff] [blame] | 1799 | if (IS_ERR(tcp_conn->tx_hash.tfm)) { |
| 1800 | printk(KERN_ERR "Could not create connection due to crc32c " |
| 1801 | "loading error %ld. Make sure the crc32c module is " |
| 1802 | "built as a module or into the kernel\n", |
| 1803 | PTR_ERR(tcp_conn->tx_hash.tfm)); |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1804 | goto free_tcp_conn; |
Mike Christie | 0f23841 | 2007-02-28 17:32:21 -0600 | [diff] [blame] | 1805 | } |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1806 | |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1807 | tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 1808 | CRYPTO_ALG_ASYNC); |
| 1809 | tcp_conn->rx_hash.flags = 0; |
Mike Christie | 0f23841 | 2007-02-28 17:32:21 -0600 | [diff] [blame] | 1810 | if (IS_ERR(tcp_conn->rx_hash.tfm)) { |
| 1811 | printk(KERN_ERR "Could not create connection due to crc32c " |
| 1812 | "loading error %ld. Make sure the crc32c module is " |
| 1813 | "built as a module or into the kernel\n", |
| 1814 | PTR_ERR(tcp_conn->rx_hash.tfm)); |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1815 | goto free_tx_tfm; |
Mike Christie | 0f23841 | 2007-02-28 17:32:21 -0600 | [diff] [blame] | 1816 | } |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1817 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1818 | return cls_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1819 | |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1820 | free_tx_tfm: |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1821 | crypto_free_hash(tcp_conn->tx_hash.tfm); |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1822 | free_tcp_conn: |
| 1823 | kfree(tcp_conn); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1824 | tcp_conn_alloc_fail: |
| 1825 | iscsi_conn_teardown(cls_conn); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1826 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | static void |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1830 | iscsi_tcp_release_conn(struct iscsi_conn *conn) |
| 1831 | { |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1832 | struct iscsi_session *session = conn->session; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1833 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1834 | struct socket *sock = tcp_conn->sock; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1835 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1836 | if (!sock) |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1837 | return; |
| 1838 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1839 | sock_hold(sock->sk); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1840 | iscsi_conn_restore_callbacks(tcp_conn); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1841 | sock_put(sock->sk); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1842 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1843 | spin_lock_bh(&session->lock); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1844 | tcp_conn->sock = NULL; |
| 1845 | conn->recv_lock = NULL; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1846 | spin_unlock_bh(&session->lock); |
| 1847 | sockfd_put(sock); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | static void |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1851 | iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1852 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1853 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1854 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1855 | |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1856 | iscsi_tcp_release_conn(conn); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1857 | iscsi_conn_teardown(cls_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1858 | |
Pete Wyckoff | 534284a | 2006-11-08 15:58:31 -0600 | [diff] [blame] | 1859 | if (tcp_conn->tx_hash.tfm) |
| 1860 | crypto_free_hash(tcp_conn->tx_hash.tfm); |
| 1861 | if (tcp_conn->rx_hash.tfm) |
| 1862 | crypto_free_hash(tcp_conn->rx_hash.tfm); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1863 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1864 | kfree(tcp_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1867 | static void |
| 1868 | iscsi_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) |
| 1869 | { |
| 1870 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | d5390f5 | 2006-08-31 18:09:30 -0400 | [diff] [blame] | 1871 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1872 | |
| 1873 | iscsi_conn_stop(cls_conn, flag); |
| 1874 | iscsi_tcp_release_conn(conn); |
Mike Christie | d5390f5 | 2006-08-31 18:09:30 -0400 | [diff] [blame] | 1875 | tcp_conn->hdr_size = sizeof(struct iscsi_hdr); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1876 | } |
| 1877 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 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 | |
Al Viro | a920487 | 2007-07-20 16:03:40 +0100 | [diff] [blame] | 1888 | addr = kmalloc(sizeof(*addr), GFP_KERNEL); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 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 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1918 | static int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1919 | iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1920 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1921 | int is_leading) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1922 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1923 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 1924 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1925 | struct sock *sk; |
| 1926 | struct socket *sock; |
| 1927 | int err; |
| 1928 | |
| 1929 | /* lookup for existing socket */ |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1930 | sock = sockfd_lookup((int)transport_eph, &err); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1931 | if (!sock) { |
| 1932 | printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err); |
| 1933 | return -EEXIST; |
| 1934 | } |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 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; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1949 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1950 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
| 1951 | if (err) |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1952 | goto free_socket; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1953 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1954 | /* bind iSCSI connection and socket */ |
| 1955 | tcp_conn->sock = sock; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1956 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1957 | /* setup Socket parameters */ |
| 1958 | sk = sock->sk; |
| 1959 | sk->sk_reuse = 1; |
| 1960 | sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */ |
| 1961 | sk->sk_allocation = GFP_ATOMIC; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1962 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1963 | /* FIXME: disable Nagle's algorithm */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1964 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1965 | /* |
| 1966 | * Intercept TCP callbacks for sendfile like receive |
| 1967 | * processing. |
| 1968 | */ |
| 1969 | conn->recv_lock = &sk->sk_callback_lock; |
| 1970 | iscsi_conn_set_callbacks(conn); |
| 1971 | tcp_conn->sendpage = tcp_conn->sock->ops->sendpage; |
| 1972 | /* |
| 1973 | * set receive state machine into initial state |
| 1974 | */ |
| 1975 | tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1976 | return 0; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1977 | |
| 1978 | free_socket: |
| 1979 | sockfd_put(sock); |
| 1980 | return err; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1983 | /* called with host lock */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1984 | static void |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 1985 | iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1986 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1987 | struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1988 | tcp_mtask->xmstate = XMSTATE_IMM_HDR_INIT; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | static int |
| 1992 | iscsi_r2tpool_alloc(struct iscsi_session *session) |
| 1993 | { |
| 1994 | int i; |
| 1995 | int cmd_i; |
| 1996 | |
| 1997 | /* |
| 1998 | * initialize per-task: R2T pool and xmit queue |
| 1999 | */ |
| 2000 | for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { |
| 2001 | struct iscsi_cmd_task *ctask = session->cmds[cmd_i]; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2002 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2003 | |
| 2004 | /* |
| 2005 | * pre-allocated x4 as much r2ts to handle race when |
| 2006 | * target acks DataOut faster than we data_xmit() queues |
| 2007 | * could replenish r2tqueue. |
| 2008 | */ |
| 2009 | |
| 2010 | /* R2T pool */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2011 | if (iscsi_pool_init(&tcp_ctask->r2tpool, session->max_r2t * 4, |
| 2012 | (void***)&tcp_ctask->r2ts, |
| 2013 | sizeof(struct iscsi_r2t_info))) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2014 | goto r2t_alloc_fail; |
| 2015 | } |
| 2016 | |
| 2017 | /* R2T xmit queue */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2018 | tcp_ctask->r2tqueue = kfifo_alloc( |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2019 | session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2020 | if (tcp_ctask->r2tqueue == ERR_PTR(-ENOMEM)) { |
| 2021 | iscsi_pool_free(&tcp_ctask->r2tpool, |
| 2022 | (void**)tcp_ctask->r2ts); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2023 | goto r2t_alloc_fail; |
| 2024 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | return 0; |
| 2028 | |
| 2029 | r2t_alloc_fail: |
| 2030 | for (i = 0; i < cmd_i; i++) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2031 | struct iscsi_cmd_task *ctask = session->cmds[i]; |
| 2032 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 2033 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2034 | kfifo_free(tcp_ctask->r2tqueue); |
| 2035 | iscsi_pool_free(&tcp_ctask->r2tpool, |
| 2036 | (void**)tcp_ctask->r2ts); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2037 | } |
| 2038 | return -ENOMEM; |
| 2039 | } |
| 2040 | |
| 2041 | static void |
| 2042 | iscsi_r2tpool_free(struct iscsi_session *session) |
| 2043 | { |
| 2044 | int i; |
| 2045 | |
| 2046 | for (i = 0; i < session->cmds_max; i++) { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2047 | struct iscsi_cmd_task *ctask = session->cmds[i]; |
| 2048 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 2049 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2050 | kfifo_free(tcp_ctask->r2tqueue); |
| 2051 | iscsi_pool_free(&tcp_ctask->r2tpool, |
| 2052 | (void**)tcp_ctask->r2ts); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2056 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2057 | iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param, |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2058 | char *buf, int buflen) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2059 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2060 | struct iscsi_conn *conn = cls_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2061 | struct iscsi_session *session = conn->session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2062 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2063 | int value; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2064 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2065 | switch(param) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2066 | case ISCSI_PARAM_HDRDGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2067 | iscsi_set_param(cls_conn, param, buf, buflen); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2068 | tcp_conn->hdr_size = sizeof(struct iscsi_hdr); |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 2069 | if (conn->hdrdgst_en) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2070 | tcp_conn->hdr_size += sizeof(__u32); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2071 | break; |
| 2072 | case ISCSI_PARAM_DATADGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2073 | iscsi_set_param(cls_conn, param, buf, buflen); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2074 | tcp_conn->sendpage = conn->datadgst_en ? |
| 2075 | sock_no_sendpage : tcp_conn->sock->ops->sendpage; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2076 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2077 | case ISCSI_PARAM_MAX_R2T: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2078 | sscanf(buf, "%d", &value); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2079 | if (session->max_r2t == roundup_pow_of_two(value)) |
| 2080 | break; |
| 2081 | iscsi_r2tpool_free(session); |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2082 | iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2083 | if (session->max_r2t & (session->max_r2t - 1)) |
| 2084 | session->max_r2t = roundup_pow_of_two(session->max_r2t); |
| 2085 | if (iscsi_r2tpool_alloc(session)) |
| 2086 | return -ENOMEM; |
| 2087 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2088 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2089 | return iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | |
| 2095 | static int |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2096 | iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, |
| 2097 | enum iscsi_param param, char *buf) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2098 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2099 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2100 | int len; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2101 | |
| 2102 | switch(param) { |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2103 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 2104 | spin_lock_bh(&conn->session->lock); |
| 2105 | len = sprintf(buf, "%hu\n", conn->portal_port); |
| 2106 | spin_unlock_bh(&conn->session->lock); |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 2107 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2108 | case ISCSI_PARAM_CONN_ADDRESS: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 2109 | spin_lock_bh(&conn->session->lock); |
| 2110 | len = sprintf(buf, "%s\n", conn->portal_address); |
| 2111 | spin_unlock_bh(&conn->session->lock); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2112 | break; |
| 2113 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2114 | return iscsi_conn_get_param(cls_conn, param, buf); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | return len; |
| 2118 | } |
| 2119 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 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 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2143 | static void |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2144 | iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2145 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2146 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2147 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2148 | |
| 2149 | stats->txdata_octets = conn->txdata_octets; |
| 2150 | stats->rxdata_octets = conn->rxdata_octets; |
| 2151 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; |
| 2152 | stats->dataout_pdus = conn->dataout_pdus_cnt; |
| 2153 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; |
| 2154 | stats->datain_pdus = conn->datain_pdus_cnt; |
| 2155 | stats->r2t_pdus = conn->r2t_pdus_cnt; |
| 2156 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; |
| 2157 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; |
| 2158 | stats->custom_length = 3; |
| 2159 | strcpy(stats->custom[0].desc, "tx_sendpage_failures"); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2160 | stats->custom[0].value = tcp_conn->sendpage_failures_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2161 | strcpy(stats->custom[1].desc, "rx_discontiguous_hdr"); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2162 | stats->custom[1].value = tcp_conn->discontiguous_hdr_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2163 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); |
| 2164 | stats->custom[2].value = conn->eh_abort_cnt; |
| 2165 | } |
| 2166 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2167 | static struct iscsi_cls_session * |
| 2168 | iscsi_tcp_session_create(struct iscsi_transport *iscsit, |
| 2169 | struct scsi_transport_template *scsit, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 2170 | uint16_t cmds_max, uint16_t qdepth, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2171 | uint32_t initial_cmdsn, uint32_t *hostno) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2172 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2173 | struct iscsi_cls_session *cls_session; |
| 2174 | struct iscsi_session *session; |
| 2175 | uint32_t hn; |
| 2176 | int cmd_i; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2177 | |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 2178 | cls_session = iscsi_session_setup(iscsit, scsit, cmds_max, qdepth, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2179 | sizeof(struct iscsi_tcp_cmd_task), |
| 2180 | sizeof(struct iscsi_tcp_mgmt_task), |
| 2181 | initial_cmdsn, &hn); |
| 2182 | if (!cls_session) |
| 2183 | return NULL; |
| 2184 | *hostno = hn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2185 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2186 | session = class_to_transport_session(cls_session); |
| 2187 | for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { |
| 2188 | struct iscsi_cmd_task *ctask = session->cmds[cmd_i]; |
| 2189 | struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; |
| 2190 | |
| 2191 | ctask->hdr = &tcp_ctask->hdr; |
| 2192 | } |
| 2193 | |
| 2194 | for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) { |
| 2195 | struct iscsi_mgmt_task *mtask = session->mgmt_cmds[cmd_i]; |
| 2196 | struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; |
| 2197 | |
| 2198 | mtask->hdr = &tcp_mtask->hdr; |
| 2199 | } |
| 2200 | |
| 2201 | if (iscsi_r2tpool_alloc(class_to_transport_session(cls_session))) |
| 2202 | goto r2tpool_alloc_fail; |
| 2203 | |
| 2204 | return cls_session; |
| 2205 | |
| 2206 | r2tpool_alloc_fail: |
| 2207 | iscsi_session_teardown(cls_session); |
| 2208 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2211 | static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session) |
| 2212 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2213 | iscsi_r2tpool_free(class_to_transport_session(cls_session)); |
| 2214 | iscsi_session_teardown(cls_session); |
| 2215 | } |
| 2216 | |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 2217 | static int iscsi_tcp_slave_configure(struct scsi_device *sdev) |
| 2218 | { |
Mike Christie | b6d44fe | 2007-07-26 12:46:47 -0500 | [diff] [blame] | 2219 | blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_ANY); |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 2220 | blk_queue_dma_alignment(sdev->request_queue, 0); |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2224 | static struct scsi_host_template iscsi_sht = { |
Mike Christie | 7974392 | 2007-07-26 12:46:46 -0500 | [diff] [blame] | 2225 | .module = THIS_MODULE, |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 2226 | .name = "iSCSI Initiator over TCP/IP", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2227 | .queuecommand = iscsi_queuecommand, |
| 2228 | .change_queue_depth = iscsi_change_queue_depth, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 2229 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2230 | .sg_tablesize = ISCSI_SG_TABLESIZE, |
Mike Christie | 8231f0e | 2007-02-28 17:32:20 -0600 | [diff] [blame] | 2231 | .max_sectors = 0xFFFF, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2232 | .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, |
| 2233 | .eh_abort_handler = iscsi_eh_abort, |
| 2234 | .eh_host_reset_handler = iscsi_eh_host_reset, |
| 2235 | .use_clustering = DISABLE_CLUSTERING, |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 2236 | .slave_configure = iscsi_tcp_slave_configure, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2237 | .proc_name = "iscsi_tcp", |
| 2238 | .this_id = -1, |
| 2239 | }; |
| 2240 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2241 | static struct iscsi_transport iscsi_tcp_transport = { |
| 2242 | .owner = THIS_MODULE, |
| 2243 | .name = "tcp", |
| 2244 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
| 2245 | | CAP_DATADGST, |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2246 | .param_mask = ISCSI_MAX_RECV_DLENGTH | |
| 2247 | ISCSI_MAX_XMIT_DLENGTH | |
| 2248 | ISCSI_HDRDGST_EN | |
| 2249 | ISCSI_DATADGST_EN | |
| 2250 | ISCSI_INITIAL_R2T_EN | |
| 2251 | ISCSI_MAX_R2T | |
| 2252 | ISCSI_IMM_DATA_EN | |
| 2253 | ISCSI_FIRST_BURST | |
| 2254 | ISCSI_MAX_BURST | |
| 2255 | ISCSI_PDU_INORDER_EN | |
| 2256 | ISCSI_DATASEQ_INORDER_EN | |
| 2257 | ISCSI_ERL | |
| 2258 | ISCSI_CONN_PORT | |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 2259 | ISCSI_CONN_ADDRESS | |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2260 | ISCSI_EXP_STATSN | |
| 2261 | ISCSI_PERSISTENT_PORT | |
| 2262 | ISCSI_PERSISTENT_ADDRESS | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2263 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
| 2264 | ISCSI_USERNAME | ISCSI_PASSWORD | |
| 2265 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN, |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 2266 | .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 2267 | ISCSI_HOST_INITIATOR_NAME | |
| 2268 | ISCSI_HOST_NETDEV_NAME, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2269 | .host_template = &iscsi_sht, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2270 | .conndata_size = sizeof(struct iscsi_conn), |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2271 | .max_conn = 1, |
| 2272 | .max_cmd_len = ISCSI_TCP_MAX_CMD_LEN, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2273 | /* session management */ |
| 2274 | .create_session = iscsi_tcp_session_create, |
| 2275 | .destroy_session = iscsi_tcp_session_destroy, |
| 2276 | /* connection management */ |
| 2277 | .create_conn = iscsi_tcp_conn_create, |
| 2278 | .bind_conn = iscsi_tcp_conn_bind, |
| 2279 | .destroy_conn = iscsi_tcp_conn_destroy, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2280 | .set_param = iscsi_conn_set_param, |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 2281 | .get_conn_param = iscsi_tcp_conn_get_param, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2282 | .get_session_param = iscsi_session_get_param, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2283 | .start_conn = iscsi_conn_start, |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 2284 | .stop_conn = iscsi_tcp_conn_stop, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 2285 | /* iscsi host params */ |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 2286 | .get_host_param = iscsi_tcp_host_get_param, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 2287 | .set_host_param = iscsi_host_set_param, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2288 | /* IO */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2289 | .send_pdu = iscsi_conn_send_pdu, |
| 2290 | .get_stats = iscsi_conn_get_stats, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 2291 | .init_cmd_task = iscsi_tcp_cmd_init, |
| 2292 | .init_mgmt_task = iscsi_tcp_mgmt_init, |
| 2293 | .xmit_cmd_task = iscsi_tcp_ctask_xmit, |
| 2294 | .xmit_mgmt_task = iscsi_tcp_mtask_xmit, |
| 2295 | .cleanup_cmd_task = iscsi_tcp_cleanup_ctask, |
| 2296 | /* recovery */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2297 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2298 | }; |
| 2299 | |
| 2300 | static int __init |
| 2301 | iscsi_tcp_init(void) |
| 2302 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2303 | if (iscsi_max_lun < 1) { |
Or Gerlitz | be2df72 | 2006-05-02 19:46:43 -0500 | [diff] [blame] | 2304 | printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n", |
| 2305 | iscsi_max_lun); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2306 | return -EINVAL; |
| 2307 | } |
| 2308 | iscsi_tcp_transport.max_lun = iscsi_max_lun; |
| 2309 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2310 | if (!iscsi_register_transport(&iscsi_tcp_transport)) |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 2311 | return -ENODEV; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2312 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2313 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | static void __exit |
| 2317 | iscsi_tcp_exit(void) |
| 2318 | { |
| 2319 | iscsi_unregister_transport(&iscsi_tcp_transport); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | module_init(iscsi_tcp_init); |
| 2323 | module_exit(iscsi_tcp_exit); |