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