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