Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * iSCSI Initiator over TCP/IP Data-Path |
| 3 | * |
| 4 | * Copyright (C) 2004 Dmitry Yusupov |
| 5 | * Copyright (C) 2004 Alex Aizman |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 6 | * Copyright (C) 2005 - 2006 Mike Christie |
| 7 | * Copyright (C) 2006 Red Hat, Inc. All rights reserved. |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 8 | * maintained by open-iscsi@googlegroups.com |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published |
| 12 | * by the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * See the file COPYING included with this distribution for more details. |
| 21 | * |
| 22 | * Credits: |
| 23 | * Christoph Hellwig |
| 24 | * FUJITA Tomonori |
| 25 | * Arne Redlich |
| 26 | * Zhenyu Wang |
| 27 | */ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/list.h> |
| 31 | #include <linux/inet.h> |
Mike Christie | 4e7aba7 | 2007-05-30 12:57:23 -0500 | [diff] [blame] | 32 | #include <linux/file.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 33 | #include <linux/blkdev.h> |
| 34 | #include <linux/crypto.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/kfifo.h> |
| 37 | #include <linux/scatterlist.h> |
| 38 | #include <net/tcp.h> |
| 39 | #include <scsi/scsi_cmnd.h> |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 40 | #include <scsi/scsi_device.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 41 | #include <scsi/scsi_host.h> |
| 42 | #include <scsi/scsi.h> |
| 43 | #include <scsi/scsi_transport_iscsi.h> |
| 44 | |
| 45 | #include "iscsi_tcp.h" |
| 46 | |
| 47 | MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 48 | "Alex Aizman <itn780@yahoo.com>"); |
| 49 | MODULE_DESCRIPTION("iSCSI/TCP data-path"); |
| 50 | MODULE_LICENSE("GPL"); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 51 | #undef DEBUG_TCP |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 52 | #define DEBUG_ASSERT |
| 53 | |
| 54 | #ifdef DEBUG_TCP |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 55 | #define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 56 | #else |
| 57 | #define debug_tcp(fmt...) |
| 58 | #endif |
| 59 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 60 | #ifndef DEBUG_ASSERT |
| 61 | #ifdef BUG_ON |
| 62 | #undef BUG_ON |
| 63 | #endif |
| 64 | #define BUG_ON(expr) |
| 65 | #endif |
| 66 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 67 | static struct scsi_transport_template *iscsi_tcp_scsi_transport; |
| 68 | static struct scsi_host_template iscsi_sht; |
| 69 | static struct iscsi_transport iscsi_tcp_transport; |
| 70 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 71 | static unsigned int iscsi_max_lun = 512; |
| 72 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); |
| 73 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 74 | static int iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 75 | struct iscsi_segment *segment); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 76 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 77 | /* |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 78 | * Scatterlist handling: inside the iscsi_segment, we |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 79 | * remember an index into the scatterlist, and set data/size |
| 80 | * to the current scatterlist entry. For highmem pages, we |
| 81 | * kmap as needed. |
| 82 | * |
| 83 | * Note that the page is unmapped when we return from |
| 84 | * TCP's data_ready handler, so we may end up mapping and |
| 85 | * unmapping the same page repeatedly. The whole reason |
| 86 | * for this is that we shouldn't keep the page mapped |
| 87 | * outside the softirq. |
| 88 | */ |
| 89 | |
| 90 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 91 | * iscsi_tcp_segment_init_sg - init indicated scatterlist entry |
| 92 | * @segment: the buffer object |
| 93 | * @sg: scatterlist |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 94 | * @offset: byte offset into that sg entry |
| 95 | * |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 96 | * This function sets up the segment so that subsequent |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 97 | * data is copied to the indicated sg entry, at the given |
| 98 | * offset. |
| 99 | */ |
| 100 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 101 | iscsi_tcp_segment_init_sg(struct iscsi_segment *segment, |
| 102 | struct scatterlist *sg, unsigned int offset) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 103 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 104 | segment->sg = sg; |
| 105 | segment->sg_offset = offset; |
| 106 | segment->size = min(sg->length - offset, |
| 107 | segment->total_size - segment->total_copied); |
| 108 | segment->data = NULL; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 109 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 110 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 111 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 112 | * iscsi_tcp_segment_map - map the current S/G page |
| 113 | * @segment: iscsi_segment |
| 114 | * @recv: 1 if called from recv path |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 115 | * |
| 116 | * We only need to possibly kmap data if scatter lists are being used, |
| 117 | * because the iscsi passthrough and internal IO paths will never use high |
| 118 | * mem pages. |
| 119 | */ |
| 120 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 121 | iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 122 | { |
| 123 | struct scatterlist *sg; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 124 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 125 | if (segment->data != NULL || !segment->sg) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 126 | return; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 127 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 128 | sg = segment->sg; |
| 129 | BUG_ON(segment->sg_mapped); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 130 | BUG_ON(sg->length == 0); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * If the page count is greater than one it is ok to send |
| 134 | * to the network layer's zero copy send path. If not we |
| 135 | * have to go the slow sendmsg path. We always map for the |
| 136 | * recv path. |
| 137 | */ |
| 138 | if (page_count(sg_page(sg)) >= 1 && !recv) |
| 139 | return; |
| 140 | |
| 141 | debug_tcp("iscsi_tcp_segment_map %s %p\n", recv ? "recv" : "xmit", |
| 142 | segment); |
| 143 | segment->sg_mapped = kmap_atomic(sg_page(sg), KM_SOFTIRQ0); |
| 144 | segment->data = segment->sg_mapped + sg->offset + segment->sg_offset; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 145 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 146 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 147 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 148 | iscsi_tcp_segment_unmap(struct iscsi_segment *segment) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 149 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 150 | debug_tcp("iscsi_tcp_segment_unmap %p\n", segment); |
| 151 | |
| 152 | if (segment->sg_mapped) { |
| 153 | debug_tcp("iscsi_tcp_segment_unmap valid\n"); |
| 154 | kunmap_atomic(segment->sg_mapped, KM_SOFTIRQ0); |
| 155 | segment->sg_mapped = NULL; |
| 156 | segment->data = NULL; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 157 | } |
| 158 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 159 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 160 | /* |
| 161 | * Splice the digest buffer into the buffer |
| 162 | */ |
| 163 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 164 | iscsi_tcp_segment_splice_digest(struct iscsi_segment *segment, void *digest) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 165 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 166 | segment->data = digest; |
| 167 | segment->digest_len = ISCSI_DIGEST_SIZE; |
| 168 | segment->total_size += ISCSI_DIGEST_SIZE; |
| 169 | segment->size = ISCSI_DIGEST_SIZE; |
| 170 | segment->copied = 0; |
| 171 | segment->sg = NULL; |
| 172 | segment->hash = NULL; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 173 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 174 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 175 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 176 | * iscsi_tcp_segment_done - check whether the segment is complete |
| 177 | * @segment: iscsi segment to check |
| 178 | * @recv: set to one of this is called from the recv path |
| 179 | * @copied: number of bytes copied |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 180 | * |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 181 | * Check if we're done receiving this segment. If the receive |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 182 | * buffer is full but we expect more data, move on to the |
| 183 | * next entry in the scatterlist. |
| 184 | * |
| 185 | * If the amount of data we received isn't a multiple of 4, |
| 186 | * we will transparently receive the pad bytes, too. |
| 187 | * |
| 188 | * This function must be re-entrant. |
| 189 | */ |
| 190 | static inline int |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 191 | iscsi_tcp_segment_done(struct iscsi_segment *segment, int recv, unsigned copied) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 192 | { |
| 193 | static unsigned char padbuf[ISCSI_PAD_LEN]; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 194 | struct scatterlist sg; |
Boaz Harrosh | 004d653 | 2007-12-13 12:43:23 -0600 | [diff] [blame] | 195 | unsigned int pad; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 196 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 197 | debug_tcp("copied %u %u size %u %s\n", segment->copied, copied, |
| 198 | segment->size, recv ? "recv" : "xmit"); |
| 199 | if (segment->hash && copied) { |
| 200 | /* |
| 201 | * If a segment is kmapd we must unmap it before sending |
| 202 | * to the crypto layer since that will try to kmap it again. |
| 203 | */ |
| 204 | iscsi_tcp_segment_unmap(segment); |
| 205 | |
| 206 | if (!segment->data) { |
| 207 | sg_init_table(&sg, 1); |
| 208 | sg_set_page(&sg, sg_page(segment->sg), copied, |
| 209 | segment->copied + segment->sg_offset + |
| 210 | segment->sg->offset); |
| 211 | } else |
| 212 | sg_init_one(&sg, segment->data + segment->copied, |
| 213 | copied); |
| 214 | crypto_hash_update(segment->hash, &sg, copied); |
| 215 | } |
| 216 | |
| 217 | segment->copied += copied; |
| 218 | if (segment->copied < segment->size) { |
| 219 | iscsi_tcp_segment_map(segment, recv); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 220 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 223 | segment->total_copied += segment->copied; |
| 224 | segment->copied = 0; |
| 225 | segment->size = 0; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 226 | |
| 227 | /* Unmap the current scatterlist page, if there is one. */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 228 | iscsi_tcp_segment_unmap(segment); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 229 | |
| 230 | /* Do we have more scatterlist entries? */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 231 | debug_tcp("total copied %u total size %u\n", segment->total_copied, |
| 232 | segment->total_size); |
| 233 | if (segment->total_copied < segment->total_size) { |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 234 | /* Proceed to the next entry in the scatterlist. */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 235 | iscsi_tcp_segment_init_sg(segment, sg_next(segment->sg), |
| 236 | 0); |
| 237 | iscsi_tcp_segment_map(segment, recv); |
| 238 | BUG_ON(segment->size == 0); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | /* Do we need to handle padding? */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 243 | pad = iscsi_padding(segment->total_copied); |
Boaz Harrosh | 004d653 | 2007-12-13 12:43:23 -0600 | [diff] [blame] | 244 | if (pad != 0) { |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 245 | debug_tcp("consume %d pad bytes\n", pad); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 246 | segment->total_size += pad; |
| 247 | segment->size = pad; |
| 248 | segment->data = padbuf; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | /* |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 253 | * Set us up for transferring the data digest. hdr digest |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 254 | * is completely handled in hdr done function. |
| 255 | */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 256 | if (segment->hash) { |
| 257 | crypto_hash_final(segment->hash, segment->digest); |
| 258 | iscsi_tcp_segment_splice_digest(segment, |
| 259 | recv ? segment->recv_digest : segment->digest); |
| 260 | return 0; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return 1; |
| 264 | } |
| 265 | |
| 266 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 267 | * iscsi_tcp_xmit_segment - transmit segment |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 268 | * @tcp_conn: the iSCSI TCP connection |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 269 | * @segment: the buffer to transmnit |
| 270 | * |
| 271 | * This function transmits as much of the buffer as |
| 272 | * the network layer will accept, and returns the number of |
| 273 | * bytes transmitted. |
| 274 | * |
| 275 | * If CRC hashing is enabled, the function will compute the |
| 276 | * hash as it goes. When the entire segment has been transmitted, |
| 277 | * it will retrieve the hash value and send it as well. |
| 278 | */ |
| 279 | static int |
| 280 | iscsi_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn, |
| 281 | struct iscsi_segment *segment) |
| 282 | { |
| 283 | struct socket *sk = tcp_conn->sock; |
| 284 | unsigned int copied = 0; |
| 285 | int r = 0; |
| 286 | |
| 287 | while (!iscsi_tcp_segment_done(segment, 0, r)) { |
| 288 | struct scatterlist *sg; |
| 289 | unsigned int offset, copy; |
| 290 | int flags = 0; |
| 291 | |
| 292 | r = 0; |
| 293 | offset = segment->copied; |
| 294 | copy = segment->size - offset; |
| 295 | |
| 296 | if (segment->total_copied + segment->size < segment->total_size) |
| 297 | flags |= MSG_MORE; |
| 298 | |
| 299 | /* Use sendpage if we can; else fall back to sendmsg */ |
| 300 | if (!segment->data) { |
| 301 | sg = segment->sg; |
| 302 | offset += segment->sg_offset + sg->offset; |
| 303 | r = tcp_conn->sendpage(sk, sg_page(sg), offset, copy, |
| 304 | flags); |
| 305 | } else { |
| 306 | struct msghdr msg = { .msg_flags = flags }; |
| 307 | struct kvec iov = { |
| 308 | .iov_base = segment->data + offset, |
| 309 | .iov_len = copy |
| 310 | }; |
| 311 | |
| 312 | r = kernel_sendmsg(sk, &msg, &iov, 1, copy); |
| 313 | } |
| 314 | |
| 315 | if (r < 0) { |
| 316 | iscsi_tcp_segment_unmap(segment); |
| 317 | if (copied || r == -EAGAIN) |
| 318 | break; |
| 319 | return r; |
| 320 | } |
| 321 | copied += r; |
| 322 | } |
| 323 | return copied; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * iscsi_tcp_segment_recv - copy data to segment |
| 328 | * @tcp_conn: the iSCSI TCP connection |
| 329 | * @segment: the buffer to copy to |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 330 | * @ptr: data pointer |
| 331 | * @len: amount of data available |
| 332 | * |
| 333 | * This function copies up to @len bytes to the |
| 334 | * given buffer, and returns the number of bytes |
| 335 | * consumed, which can actually be less than @len. |
| 336 | * |
| 337 | * If hash digest is enabled, the function will update the |
| 338 | * hash while copying. |
| 339 | * Combining these two operations doesn't buy us a lot (yet), |
| 340 | * but in the future we could implement combined copy+crc, |
| 341 | * just way we do for network layer checksums. |
| 342 | */ |
| 343 | static int |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 344 | iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn, |
| 345 | struct iscsi_segment *segment, const void *ptr, |
| 346 | unsigned int len) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 347 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 348 | unsigned int copy = 0, copied = 0; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 349 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 350 | while (!iscsi_tcp_segment_done(segment, 1, copy)) { |
| 351 | if (copied == len) { |
| 352 | debug_tcp("iscsi_tcp_segment_recv copied %d bytes\n", |
| 353 | len); |
| 354 | break; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 355 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 356 | |
| 357 | copy = min(len - copied, segment->size - segment->copied); |
| 358 | debug_tcp("iscsi_tcp_segment_recv copying %d\n", copy); |
| 359 | memcpy(segment->data + segment->copied, ptr + copied, copy); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 360 | copied += copy; |
| 361 | } |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 362 | return copied; |
| 363 | } |
| 364 | |
| 365 | static inline void |
| 366 | iscsi_tcp_dgst_header(struct hash_desc *hash, const void *hdr, size_t hdrlen, |
| 367 | unsigned char digest[ISCSI_DIGEST_SIZE]) |
| 368 | { |
| 369 | struct scatterlist sg; |
| 370 | |
| 371 | sg_init_one(&sg, hdr, hdrlen); |
| 372 | crypto_hash_digest(hash, &sg, hdrlen, digest); |
| 373 | } |
| 374 | |
| 375 | static inline int |
| 376 | iscsi_tcp_dgst_verify(struct iscsi_tcp_conn *tcp_conn, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 377 | struct iscsi_segment *segment) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 378 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 379 | if (!segment->digest_len) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 380 | return 1; |
| 381 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 382 | if (memcmp(segment->recv_digest, segment->digest, |
| 383 | segment->digest_len)) { |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 384 | debug_scsi("digest mismatch\n"); |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | return 1; |
| 389 | } |
| 390 | |
| 391 | /* |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 392 | * Helper function to set up segment buffer |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 393 | */ |
| 394 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 395 | __iscsi_segment_init(struct iscsi_segment *segment, size_t size, |
| 396 | iscsi_segment_done_fn_t *done, struct hash_desc *hash) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 397 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 398 | memset(segment, 0, sizeof(*segment)); |
| 399 | segment->total_size = size; |
| 400 | segment->done = done; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 401 | |
| 402 | if (hash) { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 403 | segment->hash = hash; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 404 | crypto_hash_init(hash); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static inline void |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 409 | iscsi_segment_init_linear(struct iscsi_segment *segment, void *data, |
| 410 | size_t size, iscsi_segment_done_fn_t *done, |
| 411 | struct hash_desc *hash) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 412 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 413 | __iscsi_segment_init(segment, size, done, hash); |
| 414 | segment->data = data; |
| 415 | segment->size = size; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static inline int |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 419 | iscsi_segment_seek_sg(struct iscsi_segment *segment, |
| 420 | struct scatterlist *sg_list, unsigned int sg_count, |
| 421 | unsigned int offset, size_t size, |
| 422 | iscsi_segment_done_fn_t *done, struct hash_desc *hash) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 423 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 424 | struct scatterlist *sg; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 425 | unsigned int i; |
| 426 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 427 | debug_scsi("iscsi_segment_seek_sg offset %u size %llu\n", |
| 428 | offset, size); |
| 429 | __iscsi_segment_init(segment, size, done, hash); |
| 430 | for_each_sg(sg_list, sg, sg_count, i) { |
| 431 | debug_scsi("sg %d, len %u offset %u\n", i, sg->length, |
| 432 | sg->offset); |
| 433 | if (offset < sg->length) { |
| 434 | iscsi_tcp_segment_init_sg(segment, sg, offset); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 435 | return 0; |
| 436 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 437 | offset -= sg->length; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | return ISCSI_ERR_DATA_OFFSET; |
| 441 | } |
| 442 | |
| 443 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 444 | * iscsi_tcp_hdr_recv_prep - prep segment for hdr reception |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 445 | * @tcp_conn: iscsi connection to prep for |
| 446 | * |
| 447 | * This function always passes NULL for the hash argument, because when this |
| 448 | * function is called we do not yet know the final size of the header and want |
| 449 | * to delay the digest processing until we know that. |
| 450 | */ |
| 451 | static void |
| 452 | iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn) |
| 453 | { |
| 454 | debug_tcp("iscsi_tcp_hdr_recv_prep(%p%s)\n", tcp_conn, |
| 455 | tcp_conn->iscsi_conn->hdrdgst_en ? ", digest enabled" : ""); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 456 | iscsi_segment_init_linear(&tcp_conn->in.segment, |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 457 | tcp_conn->in.hdr_buf, sizeof(struct iscsi_hdr), |
| 458 | iscsi_tcp_hdr_recv_done, NULL); |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Handle incoming reply to any other type of command |
| 463 | */ |
| 464 | static int |
| 465 | iscsi_tcp_data_recv_done(struct iscsi_tcp_conn *tcp_conn, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 466 | struct iscsi_segment *segment) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 467 | { |
| 468 | struct iscsi_conn *conn = tcp_conn->iscsi_conn; |
| 469 | int rc = 0; |
| 470 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 471 | if (!iscsi_tcp_dgst_verify(tcp_conn, segment)) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 472 | return ISCSI_ERR_DATA_DGST; |
| 473 | |
| 474 | rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, |
| 475 | conn->data, tcp_conn->in.datalen); |
| 476 | if (rc) |
| 477 | return rc; |
| 478 | |
| 479 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 483 | static void |
| 484 | iscsi_tcp_data_recv_prep(struct iscsi_tcp_conn *tcp_conn) |
| 485 | { |
| 486 | struct iscsi_conn *conn = tcp_conn->iscsi_conn; |
| 487 | struct hash_desc *rx_hash = NULL; |
| 488 | |
| 489 | if (conn->datadgst_en) |
| 490 | rx_hash = &tcp_conn->rx_hash; |
| 491 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 492 | iscsi_segment_init_linear(&tcp_conn->in.segment, |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 493 | conn->data, tcp_conn->in.datalen, |
| 494 | iscsi_tcp_data_recv_done, rx_hash); |
| 495 | } |
| 496 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 497 | /* |
| 498 | * must be called with session lock |
| 499 | */ |
| 500 | static void |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 501 | iscsi_tcp_cleanup_task(struct iscsi_conn *conn, struct iscsi_task *task) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 502 | { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 503 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 504 | struct iscsi_r2t_info *r2t; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 505 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 506 | /* nothing to do for mgmt tasks */ |
| 507 | if (!task->sc) |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 508 | return; |
| 509 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 510 | /* flush task's r2t queues */ |
| 511 | while (__kfifo_get(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) { |
| 512 | __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 513 | sizeof(void*)); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 514 | debug_scsi("iscsi_tcp_cleanup_task pending r2t dropped\n"); |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 515 | } |
| 516 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 517 | r2t = tcp_task->r2t; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 518 | if (r2t != NULL) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 519 | __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 520 | sizeof(void*)); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 521 | tcp_task->r2t = NULL; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 522 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /** |
| 526 | * iscsi_data_rsp - SCSI Data-In Response processing |
| 527 | * @conn: iscsi connection |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 528 | * @task: scsi command task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 529 | **/ |
| 530 | static int |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 531 | iscsi_data_rsp(struct iscsi_conn *conn, struct iscsi_task *task) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 532 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 533 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 534 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 535 | 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] | 536 | struct iscsi_session *session = conn->session; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 537 | struct scsi_cmnd *sc = task->sc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 538 | int datasn = be32_to_cpu(rhdr->datasn); |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 539 | unsigned total_in_length = scsi_in(sc)->length; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 540 | |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 541 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 542 | if (tcp_conn->in.datalen == 0) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 543 | return 0; |
| 544 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 545 | if (tcp_task->exp_datasn != datasn) { |
| 546 | debug_tcp("%s: task->exp_datasn(%d) != rhdr->datasn(%d)\n", |
| 547 | __FUNCTION__, tcp_task->exp_datasn, datasn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 548 | return ISCSI_ERR_DATASN; |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 549 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 550 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 551 | tcp_task->exp_datasn++; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 552 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 553 | tcp_task->data_offset = be32_to_cpu(rhdr->offset); |
| 554 | if (tcp_task->data_offset + tcp_conn->in.datalen > total_in_length) { |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 555 | debug_tcp("%s: data_offset(%d) + data_len(%d) > total_length_in(%d)\n", |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 556 | __FUNCTION__, tcp_task->data_offset, |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 557 | tcp_conn->in.datalen, total_in_length); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 558 | return ISCSI_ERR_DATA_OFFSET; |
Mike Christie | 857ae0b | 2007-05-30 12:57:15 -0500 | [diff] [blame] | 559 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 560 | |
| 561 | if (rhdr->flags & ISCSI_FLAG_DATA_STATUS) { |
Boaz Harrosh | 7207fea | 2007-12-13 12:43:22 -0600 | [diff] [blame] | 562 | sc->result = (DID_OK << 16) | rhdr->cmd_status; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 563 | conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; |
Boaz Harrosh | 7207fea | 2007-12-13 12:43:22 -0600 | [diff] [blame] | 564 | if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW | |
| 565 | ISCSI_FLAG_DATA_OVERFLOW)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 566 | int res_count = be32_to_cpu(rhdr->residual_count); |
| 567 | |
| 568 | if (res_count > 0 && |
Boaz Harrosh | 7207fea | 2007-12-13 12:43:22 -0600 | [diff] [blame] | 569 | (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW || |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 570 | res_count <= total_in_length)) |
| 571 | scsi_in(sc)->resid = res_count; |
Boaz Harrosh | 7207fea | 2007-12-13 12:43:22 -0600 | [diff] [blame] | 572 | else |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 573 | sc->result = (DID_BAD_TARGET << 16) | |
| 574 | rhdr->cmd_status; |
Boaz Harrosh | 7207fea | 2007-12-13 12:43:22 -0600 | [diff] [blame] | 575 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | conn->datain_pdus_cnt++; |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * iscsi_solicit_data_init - initialize first Data-Out |
| 584 | * @conn: iscsi connection |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 585 | * @task: scsi command task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 586 | * @r2t: R2T info |
| 587 | * |
| 588 | * Notes: |
| 589 | * Initialize first Data-Out within this R2T sequence and finds |
| 590 | * proper data_offset within this SCSI command. |
| 591 | * |
| 592 | * This function is called with connection lock taken. |
| 593 | **/ |
| 594 | static void |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 595 | iscsi_solicit_data_init(struct iscsi_conn *conn, struct iscsi_task *task, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 596 | struct iscsi_r2t_info *r2t) |
| 597 | { |
| 598 | struct iscsi_data *hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 599 | |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 600 | hdr = &r2t->dtask.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 601 | memset(hdr, 0, sizeof(struct iscsi_data)); |
| 602 | hdr->ttt = r2t->ttt; |
| 603 | hdr->datasn = cpu_to_be32(r2t->solicit_datasn); |
| 604 | r2t->solicit_datasn++; |
| 605 | hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 606 | memcpy(hdr->lun, task->hdr->lun, sizeof(hdr->lun)); |
| 607 | hdr->itt = task->hdr->itt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 608 | hdr->exp_statsn = r2t->exp_statsn; |
| 609 | hdr->offset = cpu_to_be32(r2t->data_offset); |
| 610 | if (r2t->data_length > conn->max_xmit_dlength) { |
| 611 | hton24(hdr->dlength, conn->max_xmit_dlength); |
| 612 | r2t->data_count = conn->max_xmit_dlength; |
| 613 | hdr->flags = 0; |
| 614 | } else { |
| 615 | hton24(hdr->dlength, r2t->data_length); |
| 616 | r2t->data_count = r2t->data_length; |
| 617 | hdr->flags = ISCSI_FLAG_CMD_FINAL; |
| 618 | } |
| 619 | conn->dataout_pdus_cnt++; |
| 620 | |
| 621 | r2t->sent = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /** |
| 625 | * iscsi_r2t_rsp - iSCSI R2T Response processing |
| 626 | * @conn: iscsi connection |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 627 | * @task: scsi command task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 628 | **/ |
| 629 | static int |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 630 | iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 631 | { |
| 632 | struct iscsi_r2t_info *r2t; |
| 633 | struct iscsi_session *session = conn->session; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 634 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 635 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 636 | 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] | 637 | int r2tsn = be32_to_cpu(rhdr->r2tsn); |
| 638 | int rc; |
| 639 | |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 640 | if (tcp_conn->in.datalen) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 641 | iscsi_conn_printk(KERN_ERR, conn, |
| 642 | "invalid R2t with datalen %d\n", |
| 643 | tcp_conn->in.datalen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 644 | return ISCSI_ERR_DATALEN; |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 645 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 646 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 647 | if (tcp_task->exp_datasn != r2tsn){ |
| 648 | debug_tcp("%s: task->exp_datasn(%d) != rhdr->r2tsn(%d)\n", |
| 649 | __FUNCTION__, tcp_task->exp_datasn, r2tsn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 650 | return ISCSI_ERR_R2TSN; |
Mike Christie | d473cc7 | 2007-05-30 12:57:14 -0500 | [diff] [blame] | 651 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 652 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 653 | /* fill-in new R2T associated with the task */ |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 654 | iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); |
| 655 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 656 | if (!task->sc || session->state != ISCSI_STATE_LOGGED_IN) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 657 | iscsi_conn_printk(KERN_INFO, conn, |
| 658 | "dropping R2T itt %d in recovery.\n", |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 659 | task->itt); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 660 | return 0; |
| 661 | } |
Mike Christie | b6c395e | 2006-07-24 15:47:15 -0500 | [diff] [blame] | 662 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 663 | rc = __kfifo_get(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 664 | BUG_ON(!rc); |
| 665 | |
| 666 | r2t->exp_statsn = rhdr->statsn; |
| 667 | r2t->data_length = be32_to_cpu(rhdr->data_length); |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 668 | if (r2t->data_length == 0) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 669 | iscsi_conn_printk(KERN_ERR, conn, |
| 670 | "invalid R2T with zero data len\n"); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 671 | __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, |
Olaf Kirch | 03766a1 | 2007-12-13 12:43:36 -0600 | [diff] [blame] | 672 | sizeof(void*)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 673 | return ISCSI_ERR_DATALEN; |
| 674 | } |
| 675 | |
Mike Christie | 98a9416 | 2006-08-31 18:09:26 -0400 | [diff] [blame] | 676 | if (r2t->data_length > session->max_burst) |
| 677 | debug_scsi("invalid R2T with data len %u and max burst %u." |
| 678 | "Attempting to execute request.\n", |
| 679 | r2t->data_length, session->max_burst); |
| 680 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 681 | r2t->data_offset = be32_to_cpu(rhdr->data_offset); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 682 | if (r2t->data_offset + r2t->data_length > scsi_out(task->sc)->length) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 683 | iscsi_conn_printk(KERN_ERR, conn, |
| 684 | "invalid R2T with data len %u at offset %u " |
| 685 | "and total length %d\n", r2t->data_length, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 686 | r2t->data_offset, scsi_out(task->sc)->length); |
| 687 | __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t, |
Olaf Kirch | 03766a1 | 2007-12-13 12:43:36 -0600 | [diff] [blame] | 688 | sizeof(void*)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 689 | return ISCSI_ERR_DATALEN; |
| 690 | } |
| 691 | |
| 692 | r2t->ttt = rhdr->ttt; /* no flip */ |
| 693 | r2t->solicit_datasn = 0; |
| 694 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 695 | iscsi_solicit_data_init(conn, task, r2t); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 696 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 697 | tcp_task->exp_datasn = r2tsn + 1; |
| 698 | __kfifo_put(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 699 | conn->r2t_pdus_cnt++; |
Mike Christie | 843c0a8 | 2007-12-13 12:43:20 -0600 | [diff] [blame] | 700 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 701 | iscsi_requeue_task(task); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 705 | /* |
| 706 | * Handle incoming reply to DataIn command |
| 707 | */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 708 | static int |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 709 | iscsi_tcp_process_data_in(struct iscsi_tcp_conn *tcp_conn, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 710 | struct iscsi_segment *segment) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 711 | { |
| 712 | struct iscsi_conn *conn = tcp_conn->iscsi_conn; |
| 713 | struct iscsi_hdr *hdr = tcp_conn->in.hdr; |
| 714 | int rc; |
| 715 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 716 | if (!iscsi_tcp_dgst_verify(tcp_conn, segment)) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 717 | return ISCSI_ERR_DATA_DGST; |
| 718 | |
| 719 | /* check for non-exceptional status */ |
| 720 | if (hdr->flags & ISCSI_FLAG_DATA_STATUS) { |
| 721 | rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0); |
| 722 | if (rc) |
| 723 | return rc; |
| 724 | } |
| 725 | |
| 726 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * iscsi_tcp_hdr_dissect - process PDU header |
| 732 | * @conn: iSCSI connection |
| 733 | * @hdr: PDU header |
| 734 | * |
| 735 | * This function analyzes the header of the PDU received, |
| 736 | * and performs several sanity checks. If the PDU is accompanied |
| 737 | * by data, the receive buffer is set up to copy the incoming data |
| 738 | * to the correct location. |
| 739 | */ |
| 740 | static int |
| 741 | iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 742 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 743 | int rc = 0, opcode, ahslen; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 744 | struct iscsi_session *session = conn->session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 745 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 746 | struct iscsi_task *task; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 747 | |
| 748 | /* verify PDU length */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 749 | tcp_conn->in.datalen = ntoh24(hdr->dlength); |
| 750 | if (tcp_conn->in.datalen > conn->max_recv_dlength) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 751 | iscsi_conn_printk(KERN_ERR, conn, |
| 752 | "iscsi_tcp: datalen %d > %d\n", |
| 753 | tcp_conn->in.datalen, conn->max_recv_dlength); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 754 | return ISCSI_ERR_DATALEN; |
| 755 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 756 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 757 | /* Additional header segments. So far, we don't |
| 758 | * process additional headers. |
| 759 | */ |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 760 | ahslen = hdr->hlength << 2; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 761 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 762 | opcode = hdr->opcode & ISCSI_OPCODE_MASK; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 763 | /* verify itt (itt encoding: age+cid+itt) */ |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 764 | rc = iscsi_verify_itt(conn, hdr->itt); |
Mike Christie | 7a53dc5 | 2007-12-13 12:43:37 -0600 | [diff] [blame] | 765 | if (rc) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 766 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 767 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 768 | debug_tcp("opcode 0x%x ahslen %d datalen %d\n", |
| 769 | opcode, ahslen, tcp_conn->in.datalen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 770 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 771 | switch(opcode) { |
| 772 | case ISCSI_OP_SCSI_DATA_IN: |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 773 | task = iscsi_itt_to_ctask(conn, hdr->itt); |
| 774 | if (!task) |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 775 | return ISCSI_ERR_BAD_ITT; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 776 | if (!task->sc) |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 777 | return ISCSI_ERR_NO_SCSI_CMD; |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 778 | |
Mike Christie | 4545a88 | 2007-12-13 12:43:40 -0600 | [diff] [blame] | 779 | spin_lock(&conn->session->lock); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 780 | rc = iscsi_data_rsp(conn, task); |
Mike Christie | 4545a88 | 2007-12-13 12:43:40 -0600 | [diff] [blame] | 781 | spin_unlock(&conn->session->lock); |
Mike Christie | 275fd7d | 2006-07-24 15:47:17 -0500 | [diff] [blame] | 782 | if (rc) |
| 783 | return rc; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 784 | if (tcp_conn->in.datalen) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 785 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 786 | struct hash_desc *rx_hash = NULL; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 787 | struct scsi_data_buffer *sdb = scsi_in(task->sc); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 788 | |
| 789 | /* |
| 790 | * Setup copy of Data-In into the Scsi_Cmnd |
| 791 | * Scatterlist case: |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 792 | * We set up the iscsi_segment to point to the next |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 793 | * scatterlist entry to copy to. As we go along, |
| 794 | * we move on to the next scatterlist entry and |
| 795 | * update the digest per-entry. |
| 796 | */ |
| 797 | if (conn->datadgst_en) |
| 798 | rx_hash = &tcp_conn->rx_hash; |
| 799 | |
| 800 | debug_tcp("iscsi_tcp_begin_data_in(%p, offset=%d, " |
| 801 | "datalen=%d)\n", tcp_conn, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 802 | tcp_task->data_offset, |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 803 | tcp_conn->in.datalen); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 804 | return iscsi_segment_seek_sg(&tcp_conn->in.segment, |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 805 | sdb->table.sgl, |
| 806 | sdb->table.nents, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 807 | tcp_task->data_offset, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 808 | tcp_conn->in.datalen, |
| 809 | iscsi_tcp_process_data_in, |
| 810 | rx_hash); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 811 | } |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 812 | /* fall through */ |
| 813 | case ISCSI_OP_SCSI_CMD_RSP: |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 814 | if (tcp_conn->in.datalen) { |
| 815 | iscsi_tcp_data_recv_prep(tcp_conn); |
| 816 | return 0; |
| 817 | } |
| 818 | rc = iscsi_complete_pdu(conn, hdr, NULL, 0); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 819 | break; |
| 820 | case ISCSI_OP_R2T: |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 821 | task = iscsi_itt_to_ctask(conn, hdr->itt); |
| 822 | if (!task) |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 823 | return ISCSI_ERR_BAD_ITT; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 824 | if (!task->sc) |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 825 | return ISCSI_ERR_NO_SCSI_CMD; |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 826 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 827 | if (ahslen) |
| 828 | rc = ISCSI_ERR_AHSLEN; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 829 | else if (task->sc->sc_data_direction == DMA_TO_DEVICE) { |
Mike Christie | 4545a88 | 2007-12-13 12:43:40 -0600 | [diff] [blame] | 830 | spin_lock(&session->lock); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 831 | rc = iscsi_r2t_rsp(conn, task); |
Mike Christie | 4545a88 | 2007-12-13 12:43:40 -0600 | [diff] [blame] | 832 | spin_unlock(&session->lock); |
| 833 | } else |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 834 | rc = ISCSI_ERR_PROTO; |
| 835 | break; |
| 836 | case ISCSI_OP_LOGIN_RSP: |
| 837 | case ISCSI_OP_TEXT_RSP: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 838 | case ISCSI_OP_REJECT: |
| 839 | case ISCSI_OP_ASYNC_EVENT: |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 840 | /* |
| 841 | * It is possible that we could get a PDU with a buffer larger |
| 842 | * than 8K, but there are no targets that currently do this. |
| 843 | * For now we fail until we find a vendor that needs it |
| 844 | */ |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 845 | if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->in.datalen) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 846 | iscsi_conn_printk(KERN_ERR, conn, |
| 847 | "iscsi_tcp: received buffer of " |
| 848 | "len %u but conn buffer is only %u " |
| 849 | "(opcode %0x)\n", |
| 850 | tcp_conn->in.datalen, |
| 851 | ISCSI_DEF_MAX_RECV_SEG_LEN, opcode); |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 852 | rc = ISCSI_ERR_PROTO; |
| 853 | break; |
| 854 | } |
| 855 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 856 | /* If there's data coming in with the response, |
| 857 | * receive it to the connection's buffer. |
| 858 | */ |
| 859 | if (tcp_conn->in.datalen) { |
| 860 | iscsi_tcp_data_recv_prep(tcp_conn); |
| 861 | return 0; |
| 862 | } |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 863 | /* fall through */ |
Mike Christie | c8dc1e5 | 2006-07-24 15:47:39 -0500 | [diff] [blame] | 864 | case ISCSI_OP_LOGOUT_RSP: |
| 865 | case ISCSI_OP_NOOP_IN: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 866 | case ISCSI_OP_SCSI_TMFUNC_RSP: |
| 867 | rc = iscsi_complete_pdu(conn, hdr, NULL, 0); |
| 868 | break; |
| 869 | default: |
| 870 | rc = ISCSI_ERR_BAD_OPCODE; |
| 871 | break; |
| 872 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 873 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 874 | if (rc == 0) { |
| 875 | /* Anything that comes with data should have |
| 876 | * been handled above. */ |
| 877 | if (tcp_conn->in.datalen) |
| 878 | return ISCSI_ERR_PROTO; |
| 879 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
| 880 | } |
| 881 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 882 | return rc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 885 | /** |
| 886 | * iscsi_tcp_hdr_recv_done - process PDU header |
| 887 | * |
| 888 | * This is the callback invoked when the PDU header has |
| 889 | * been received. If the header is followed by additional |
| 890 | * header segments, we go back for more data. |
| 891 | */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 892 | static int |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 893 | iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 894 | struct iscsi_segment *segment) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 895 | { |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 896 | struct iscsi_conn *conn = tcp_conn->iscsi_conn; |
| 897 | struct iscsi_hdr *hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 898 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 899 | /* Check if there are additional header segments |
| 900 | * *prior* to computing the digest, because we |
| 901 | * may need to go back to the caller for more. |
| 902 | */ |
| 903 | hdr = (struct iscsi_hdr *) tcp_conn->in.hdr_buf; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 904 | if (segment->copied == sizeof(struct iscsi_hdr) && hdr->hlength) { |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 905 | /* Bump the header length - the caller will |
| 906 | * just loop around and get the AHS for us, and |
| 907 | * call again. */ |
| 908 | unsigned int ahslen = hdr->hlength << 2; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 909 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 910 | /* Make sure we don't overflow */ |
| 911 | if (sizeof(*hdr) + ahslen > sizeof(tcp_conn->in.hdr_buf)) |
| 912 | return ISCSI_ERR_AHSLEN; |
| 913 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 914 | segment->total_size += ahslen; |
| 915 | segment->size += ahslen; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 916 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 917 | } |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 918 | |
| 919 | /* We're done processing the header. See if we're doing |
| 920 | * header digests; if so, set up the recv_digest buffer |
| 921 | * and go back for more. */ |
| 922 | if (conn->hdrdgst_en) { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 923 | if (segment->digest_len == 0) { |
| 924 | iscsi_tcp_segment_splice_digest(segment, |
| 925 | segment->recv_digest); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 926 | return 0; |
| 927 | } |
| 928 | iscsi_tcp_dgst_header(&tcp_conn->rx_hash, hdr, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 929 | segment->total_copied - ISCSI_DIGEST_SIZE, |
| 930 | segment->digest); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 931 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 932 | if (!iscsi_tcp_dgst_verify(tcp_conn, segment)) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 933 | return ISCSI_ERR_HDR_DGST; |
| 934 | } |
| 935 | |
| 936 | tcp_conn->in.hdr = hdr; |
| 937 | return iscsi_tcp_hdr_dissect(conn, hdr); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /** |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 941 | * iscsi_tcp_recv - TCP receive in sendfile fashion |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 942 | * @rd_desc: read descriptor |
| 943 | * @skb: socket buffer |
| 944 | * @offset: offset in skb |
| 945 | * @len: skb->len - offset |
| 946 | **/ |
| 947 | static int |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 948 | iscsi_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, |
| 949 | unsigned int offset, size_t len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 950 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 951 | struct iscsi_conn *conn = rd_desc->arg.data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 952 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 953 | struct iscsi_segment *segment = &tcp_conn->in.segment; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 954 | struct skb_seq_state seq; |
| 955 | unsigned int consumed = 0; |
| 956 | int rc = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 957 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 958 | debug_tcp("in %d bytes\n", skb->len - offset); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 959 | |
| 960 | if (unlikely(conn->suspend_rx)) { |
| 961 | debug_tcp("conn %d Rx suspended!\n", conn->id); |
| 962 | return 0; |
| 963 | } |
| 964 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 965 | skb_prepare_seq_read(skb, offset, skb->len, &seq); |
| 966 | while (1) { |
| 967 | unsigned int avail; |
| 968 | const u8 *ptr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 969 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 970 | avail = skb_seq_read(consumed, &ptr, &seq); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 971 | if (avail == 0) { |
| 972 | debug_tcp("no more data avail. Consumed %d\n", |
| 973 | consumed); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 974 | break; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 975 | } |
| 976 | BUG_ON(segment->copied >= segment->size); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 977 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 978 | debug_tcp("skb %p ptr=%p avail=%u\n", skb, ptr, avail); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 979 | rc = iscsi_tcp_segment_recv(tcp_conn, segment, ptr, avail); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 980 | BUG_ON(rc == 0); |
| 981 | consumed += rc; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 982 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 983 | if (segment->total_copied >= segment->total_size) { |
| 984 | debug_tcp("segment done\n"); |
| 985 | rc = segment->done(tcp_conn, segment); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 986 | if (rc != 0) { |
| 987 | skb_abort_seq_read(&seq); |
| 988 | goto error; |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 989 | } |
Mike Christie | dbdb016 | 2007-05-30 12:57:20 -0500 | [diff] [blame] | 990 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 991 | /* The done() functions sets up the |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 992 | * next segment. */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 995 | skb_abort_seq_read(&seq); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 996 | conn->rxdata_octets += consumed; |
| 997 | return consumed; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 998 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 999 | error: |
| 1000 | debug_tcp("Error receiving PDU, errno=%d\n", rc); |
| 1001 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 1002 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static void |
| 1006 | iscsi_tcp_data_ready(struct sock *sk, int flag) |
| 1007 | { |
| 1008 | struct iscsi_conn *conn = sk->sk_user_data; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1009 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1010 | read_descriptor_t rd_desc; |
| 1011 | |
| 1012 | read_lock(&sk->sk_callback_lock); |
| 1013 | |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 1014 | /* |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1015 | * Use rd_desc to pass 'conn' to iscsi_tcp_recv. |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 1016 | * We set count to 1 because we want the network layer to |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1017 | * hand us all the skbs that are available. iscsi_tcp_recv |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 1018 | * handled pdus that cross buffers or pdus that still need data. |
| 1019 | */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1020 | rd_desc.arg.data = conn; |
Mike Christie | 665b44a | 2006-05-02 19:46:49 -0500 | [diff] [blame] | 1021 | rd_desc.count = 1; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1022 | tcp_read_sock(sk, &rd_desc, iscsi_tcp_recv); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1023 | |
| 1024 | read_unlock(&sk->sk_callback_lock); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1025 | |
| 1026 | /* If we had to (atomically) map a highmem page, |
| 1027 | * unmap it now. */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1028 | iscsi_tcp_segment_unmap(&tcp_conn->in.segment); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static void |
| 1032 | iscsi_tcp_state_change(struct sock *sk) |
| 1033 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1034 | struct iscsi_tcp_conn *tcp_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1035 | struct iscsi_conn *conn; |
| 1036 | struct iscsi_session *session; |
| 1037 | void (*old_state_change)(struct sock *); |
| 1038 | |
| 1039 | read_lock(&sk->sk_callback_lock); |
| 1040 | |
| 1041 | conn = (struct iscsi_conn*)sk->sk_user_data; |
| 1042 | session = conn->session; |
| 1043 | |
Mike Christie | e627399 | 2005-11-29 23:12:49 -0600 | [diff] [blame] | 1044 | if ((sk->sk_state == TCP_CLOSE_WAIT || |
| 1045 | sk->sk_state == TCP_CLOSE) && |
| 1046 | !atomic_read(&sk->sk_rmem_alloc)) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1047 | debug_tcp("iscsi_tcp_state_change: TCP_CLOSE|TCP_CLOSE_WAIT\n"); |
| 1048 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 1049 | } |
| 1050 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1051 | tcp_conn = conn->dd_data; |
| 1052 | old_state_change = tcp_conn->old_state_change; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1053 | |
| 1054 | read_unlock(&sk->sk_callback_lock); |
| 1055 | |
| 1056 | old_state_change(sk); |
| 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * iscsi_write_space - Called when more output buffer space is available |
| 1061 | * @sk: socket space is available for |
| 1062 | **/ |
| 1063 | static void |
| 1064 | iscsi_write_space(struct sock *sk) |
| 1065 | { |
| 1066 | struct iscsi_conn *conn = (struct iscsi_conn*)sk->sk_user_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1067 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1068 | |
| 1069 | tcp_conn->old_write_space(sk); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1070 | debug_tcp("iscsi_write_space: cid %d\n", conn->id); |
Mike Christie | 55e3299 | 2006-01-13 18:05:53 -0600 | [diff] [blame] | 1071 | scsi_queue_work(conn->session->host, &conn->xmitwork); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static void |
| 1075 | iscsi_conn_set_callbacks(struct iscsi_conn *conn) |
| 1076 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1077 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1078 | struct sock *sk = tcp_conn->sock->sk; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1079 | |
| 1080 | /* assign new callbacks */ |
| 1081 | write_lock_bh(&sk->sk_callback_lock); |
| 1082 | sk->sk_user_data = conn; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1083 | tcp_conn->old_data_ready = sk->sk_data_ready; |
| 1084 | tcp_conn->old_state_change = sk->sk_state_change; |
| 1085 | tcp_conn->old_write_space = sk->sk_write_space; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1086 | sk->sk_data_ready = iscsi_tcp_data_ready; |
| 1087 | sk->sk_state_change = iscsi_tcp_state_change; |
| 1088 | sk->sk_write_space = iscsi_write_space; |
| 1089 | write_unlock_bh(&sk->sk_callback_lock); |
| 1090 | } |
| 1091 | |
| 1092 | static void |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1093 | iscsi_conn_restore_callbacks(struct iscsi_tcp_conn *tcp_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1094 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1095 | struct sock *sk = tcp_conn->sock->sk; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */ |
| 1098 | write_lock_bh(&sk->sk_callback_lock); |
| 1099 | sk->sk_user_data = NULL; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1100 | sk->sk_data_ready = tcp_conn->old_data_ready; |
| 1101 | sk->sk_state_change = tcp_conn->old_state_change; |
| 1102 | sk->sk_write_space = tcp_conn->old_write_space; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1103 | sk->sk_no_check = 0; |
| 1104 | write_unlock_bh(&sk->sk_callback_lock); |
| 1105 | } |
| 1106 | |
| 1107 | /** |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1108 | * iscsi_xmit - TCP transmit |
| 1109 | **/ |
| 1110 | static int |
| 1111 | iscsi_xmit(struct iscsi_conn *conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1112 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1113 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1114 | struct iscsi_segment *segment = &tcp_conn->out.segment; |
| 1115 | unsigned int consumed = 0; |
| 1116 | int rc = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1117 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1118 | while (1) { |
| 1119 | rc = iscsi_tcp_xmit_segment(tcp_conn, segment); |
| 1120 | if (rc < 0) |
| 1121 | goto error; |
| 1122 | if (rc == 0) |
| 1123 | break; |
| 1124 | |
| 1125 | consumed += rc; |
| 1126 | |
| 1127 | if (segment->total_copied >= segment->total_size) { |
| 1128 | if (segment->done != NULL) { |
| 1129 | rc = segment->done(tcp_conn, segment); |
| 1130 | if (rc < 0) |
| 1131 | goto error; |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | debug_tcp("xmit %d bytes\n", consumed); |
| 1137 | |
| 1138 | conn->txdata_octets += consumed; |
| 1139 | return consumed; |
| 1140 | |
| 1141 | error: |
| 1142 | /* Transmit error. We could initiate error recovery |
| 1143 | * here. */ |
| 1144 | debug_tcp("Error sending PDU, errno=%d\n", rc); |
| 1145 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 1146 | return rc; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * iscsi_tcp_xmit_qlen - return the number of bytes queued for xmit |
| 1151 | */ |
| 1152 | static inline int |
| 1153 | iscsi_tcp_xmit_qlen(struct iscsi_conn *conn) |
| 1154 | { |
| 1155 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1156 | struct iscsi_segment *segment = &tcp_conn->out.segment; |
| 1157 | |
| 1158 | return segment->total_copied - segment->total_size; |
| 1159 | } |
| 1160 | |
| 1161 | static inline int |
| 1162 | iscsi_tcp_flush(struct iscsi_conn *conn) |
| 1163 | { |
| 1164 | int rc; |
| 1165 | |
| 1166 | while (iscsi_tcp_xmit_qlen(conn)) { |
| 1167 | rc = iscsi_xmit(conn); |
| 1168 | if (rc == 0) |
| 1169 | return -EAGAIN; |
| 1170 | if (rc < 0) |
| 1171 | return rc; |
| 1172 | } |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | /* |
| 1178 | * This is called when we're done sending the header. |
| 1179 | * Simply copy the data_segment to the send segment, and return. |
| 1180 | */ |
| 1181 | static int |
| 1182 | iscsi_tcp_send_hdr_done(struct iscsi_tcp_conn *tcp_conn, |
| 1183 | struct iscsi_segment *segment) |
| 1184 | { |
| 1185 | tcp_conn->out.segment = tcp_conn->out.data_segment; |
| 1186 | debug_tcp("Header done. Next segment size %u total_size %u\n", |
| 1187 | tcp_conn->out.segment.size, tcp_conn->out.segment.total_size); |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | static void |
| 1192 | iscsi_tcp_send_hdr_prep(struct iscsi_conn *conn, void *hdr, size_t hdrlen) |
| 1193 | { |
| 1194 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1195 | |
| 1196 | debug_tcp("%s(%p%s)\n", __FUNCTION__, tcp_conn, |
| 1197 | conn->hdrdgst_en? ", digest enabled" : ""); |
| 1198 | |
| 1199 | /* Clear the data segment - needs to be filled in by the |
| 1200 | * caller using iscsi_tcp_send_data_prep() */ |
| 1201 | memset(&tcp_conn->out.data_segment, 0, sizeof(struct iscsi_segment)); |
| 1202 | |
| 1203 | /* If header digest is enabled, compute the CRC and |
| 1204 | * place the digest into the same buffer. We make |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1205 | * sure that both iscsi_tcp_task and mtask have |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1206 | * sufficient room. |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 1207 | */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1208 | if (conn->hdrdgst_en) { |
| 1209 | iscsi_tcp_dgst_header(&tcp_conn->tx_hash, hdr, hdrlen, |
| 1210 | hdr + hdrlen); |
| 1211 | hdrlen += ISCSI_DIGEST_SIZE; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 1212 | } |
| 1213 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1214 | /* Remember header pointer for later, when we need |
| 1215 | * to decide whether there's a payload to go along |
| 1216 | * with the header. */ |
| 1217 | tcp_conn->out.hdr = hdr; |
| 1218 | |
| 1219 | iscsi_segment_init_linear(&tcp_conn->out.segment, hdr, hdrlen, |
| 1220 | iscsi_tcp_send_hdr_done, NULL); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1223 | /* |
| 1224 | * Prepare the send buffer for the payload data. |
| 1225 | * Padding and checksumming will all be taken care |
| 1226 | * of by the iscsi_segment routines. |
| 1227 | */ |
| 1228 | static int |
| 1229 | iscsi_tcp_send_data_prep(struct iscsi_conn *conn, struct scatterlist *sg, |
| 1230 | unsigned int count, unsigned int offset, |
| 1231 | unsigned int len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1232 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1233 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1234 | struct hash_desc *tx_hash = NULL; |
| 1235 | unsigned int hdr_spec_len; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1236 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1237 | debug_tcp("%s(%p, offset=%d, datalen=%d%s)\n", __FUNCTION__, |
| 1238 | tcp_conn, offset, len, |
| 1239 | conn->datadgst_en? ", digest enabled" : ""); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1240 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1241 | /* Make sure the datalen matches what the caller |
| 1242 | said he would send. */ |
| 1243 | hdr_spec_len = ntoh24(tcp_conn->out.hdr->dlength); |
| 1244 | WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1245 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1246 | if (conn->datadgst_en) |
| 1247 | tx_hash = &tcp_conn->tx_hash; |
| 1248 | |
| 1249 | return iscsi_segment_seek_sg(&tcp_conn->out.data_segment, |
| 1250 | sg, count, offset, len, |
| 1251 | NULL, tx_hash); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1254 | static void |
| 1255 | iscsi_tcp_send_linear_data_prepare(struct iscsi_conn *conn, void *data, |
| 1256 | size_t len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1257 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1258 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 1259 | struct hash_desc *tx_hash = NULL; |
| 1260 | unsigned int hdr_spec_len; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1261 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1262 | debug_tcp("%s(%p, datalen=%d%s)\n", __FUNCTION__, tcp_conn, len, |
| 1263 | conn->datadgst_en? ", digest enabled" : ""); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1264 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1265 | /* Make sure the datalen matches what the caller |
| 1266 | said he would send. */ |
| 1267 | hdr_spec_len = ntoh24(tcp_conn->out.hdr->dlength); |
| 1268 | WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1269 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1270 | if (conn->datadgst_en) |
| 1271 | tx_hash = &tcp_conn->tx_hash; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1272 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1273 | iscsi_segment_init_linear(&tcp_conn->out.data_segment, |
| 1274 | data, len, NULL, tx_hash); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1277 | /** |
| 1278 | * iscsi_solicit_data_cont - initialize next Data-Out |
| 1279 | * @conn: iscsi connection |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1280 | * @task: scsi command task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1281 | * @r2t: R2T info |
| 1282 | * @left: bytes left to transfer |
| 1283 | * |
| 1284 | * Notes: |
| 1285 | * Initialize next Data-Out within this R2T sequence and continue |
| 1286 | * to process next Scatter-Gather element(if any) of this SCSI command. |
| 1287 | * |
| 1288 | * Called under connection lock. |
| 1289 | **/ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1290 | static int |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1291 | iscsi_solicit_data_cont(struct iscsi_conn *conn, struct iscsi_task *task, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1292 | struct iscsi_r2t_info *r2t) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1293 | { |
| 1294 | struct iscsi_data *hdr; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1295 | int new_offset, left; |
| 1296 | |
| 1297 | BUG_ON(r2t->data_length - r2t->sent < 0); |
| 1298 | left = r2t->data_length - r2t->sent; |
| 1299 | if (left == 0) |
| 1300 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1301 | |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 1302 | hdr = &r2t->dtask.hdr; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1303 | memset(hdr, 0, sizeof(struct iscsi_data)); |
| 1304 | hdr->ttt = r2t->ttt; |
| 1305 | hdr->datasn = cpu_to_be32(r2t->solicit_datasn); |
| 1306 | r2t->solicit_datasn++; |
| 1307 | hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1308 | memcpy(hdr->lun, task->hdr->lun, sizeof(hdr->lun)); |
| 1309 | hdr->itt = task->hdr->itt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1310 | hdr->exp_statsn = r2t->exp_statsn; |
| 1311 | new_offset = r2t->data_offset + r2t->sent; |
| 1312 | hdr->offset = cpu_to_be32(new_offset); |
| 1313 | if (left > conn->max_xmit_dlength) { |
| 1314 | hton24(hdr->dlength, conn->max_xmit_dlength); |
| 1315 | r2t->data_count = conn->max_xmit_dlength; |
| 1316 | } else { |
| 1317 | hton24(hdr->dlength, left); |
| 1318 | r2t->data_count = left; |
| 1319 | hdr->flags = ISCSI_FLAG_CMD_FINAL; |
| 1320 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1321 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1322 | conn->dataout_pdus_cnt++; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1323 | return 1; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /** |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1327 | * iscsi_tcp_task - Initialize iSCSI SCSI_READ or SCSI_WRITE commands |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1328 | * @conn: iscsi connection |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1329 | * @task: scsi command task |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1330 | * @sc: scsi command |
| 1331 | **/ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1332 | static int |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1333 | iscsi_tcp_task_init(struct iscsi_task *task) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1334 | { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1335 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
| 1336 | struct iscsi_conn *conn = task->conn; |
| 1337 | struct scsi_cmnd *sc = task->sc; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1338 | int err; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1339 | |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1340 | if (!sc) { |
| 1341 | /* |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1342 | * mgmt tasks do not have a scatterlist since they come |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1343 | * in from the iscsi interface. |
| 1344 | */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1345 | debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, |
| 1346 | task->itt); |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1347 | |
| 1348 | /* Prepare PDU, optionally w/ immediate data */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1349 | iscsi_tcp_send_hdr_prep(conn, task->hdr, sizeof(*task->hdr)); |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1350 | |
| 1351 | /* If we have immediate data, attach a payload */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1352 | if (task->data_count) |
| 1353 | iscsi_tcp_send_linear_data_prepare(conn, task->data, |
| 1354 | task->data_count); |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1355 | return 0; |
| 1356 | } |
| 1357 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1358 | BUG_ON(__kfifo_len(tcp_task->r2tqueue)); |
| 1359 | tcp_task->sent = 0; |
| 1360 | tcp_task->exp_datasn = 0; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1361 | |
| 1362 | /* Prepare PDU, optionally w/ immediate data */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1363 | debug_scsi("task deq [cid %d itt 0x%x imm %d unsol %d]\n", |
| 1364 | conn->id, task->itt, task->imm_count, |
| 1365 | task->unsol_count); |
| 1366 | iscsi_tcp_send_hdr_prep(conn, task->hdr, task->hdr_len); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1367 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1368 | if (!task->imm_count) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1369 | return 0; |
| 1370 | |
| 1371 | /* If we have immediate data, attach a payload */ |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 1372 | err = iscsi_tcp_send_data_prep(conn, scsi_out(sc)->table.sgl, |
| 1373 | scsi_out(sc)->table.nents, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1374 | 0, task->imm_count); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1375 | if (err) |
| 1376 | return err; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1377 | tcp_task->sent += task->imm_count; |
| 1378 | task->imm_count = 0; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1379 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1382 | /* |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1383 | * iscsi_tcp_task_xmit - xmit normal PDU task |
| 1384 | * @task: iscsi command task |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1385 | * |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1386 | * We're expected to return 0 when everything was transmitted succesfully, |
| 1387 | * -EAGAIN if there's still data in the queue, or != 0 for any other kind |
| 1388 | * of error. |
| 1389 | */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1390 | static int |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1391 | iscsi_tcp_task_xmit(struct iscsi_task *task) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1392 | { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1393 | struct iscsi_conn *conn = task->conn; |
| 1394 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
| 1395 | struct scsi_cmnd *sc = task->sc; |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1396 | struct scsi_data_buffer *sdb; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1397 | int rc = 0; |
| 1398 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1399 | flush: |
| 1400 | /* Flush any pending data first. */ |
| 1401 | rc = iscsi_tcp_flush(conn); |
| 1402 | if (rc < 0) |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1403 | return rc; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1404 | |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1405 | /* mgmt command */ |
| 1406 | if (!sc) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1407 | if (task->hdr->itt == RESERVED_ITT) |
| 1408 | iscsi_put_task(task); |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1409 | return 0; |
| 1410 | } |
| 1411 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1412 | /* Are we done already? */ |
| 1413 | if (sc->sc_data_direction != DMA_TO_DEVICE) |
Mike Christie | 218432c | 2007-05-30 12:57:17 -0500 | [diff] [blame] | 1414 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1415 | |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1416 | sdb = scsi_out(sc); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1417 | if (task->unsol_count != 0) { |
| 1418 | struct iscsi_data *hdr = &tcp_task->unsol_dtask.hdr; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1419 | |
| 1420 | /* Prepare a header for the unsolicited PDU. |
| 1421 | * The amount of data we want to send will be |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1422 | * in task->data_count. |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1423 | * FIXME: return the data count instead. |
| 1424 | */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1425 | iscsi_prep_unsolicit_data_pdu(task, hdr); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1426 | |
| 1427 | debug_tcp("unsol dout [itt 0x%x doff %d dlen %d]\n", |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1428 | task->itt, tcp_task->sent, task->data_count); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1429 | |
| 1430 | iscsi_tcp_send_hdr_prep(conn, hdr, sizeof(*hdr)); |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 1431 | rc = iscsi_tcp_send_data_prep(conn, sdb->table.sgl, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1432 | sdb->table.nents, tcp_task->sent, |
| 1433 | task->data_count); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1434 | if (rc) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1435 | goto fail; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1436 | tcp_task->sent += task->data_count; |
| 1437 | task->unsol_count -= task->data_count; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1438 | goto flush; |
| 1439 | } else { |
| 1440 | struct iscsi_session *session = conn->session; |
| 1441 | struct iscsi_r2t_info *r2t; |
| 1442 | |
| 1443 | /* All unsolicited PDUs sent. Check for solicited PDUs. |
| 1444 | */ |
| 1445 | spin_lock_bh(&session->lock); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1446 | r2t = tcp_task->r2t; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1447 | if (r2t != NULL) { |
| 1448 | /* Continue with this R2T? */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1449 | if (!iscsi_solicit_data_cont(conn, task, r2t)) { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1450 | debug_scsi(" done with r2t %p\n", r2t); |
| 1451 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1452 | __kfifo_put(tcp_task->r2tpool.queue, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1453 | (void*)&r2t, sizeof(void*)); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1454 | tcp_task->r2t = r2t = NULL; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | if (r2t == NULL) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1459 | __kfifo_get(tcp_task->r2tqueue, (void*)&tcp_task->r2t, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1460 | sizeof(void*)); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1461 | r2t = tcp_task->r2t; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1462 | } |
| 1463 | spin_unlock_bh(&session->lock); |
| 1464 | |
| 1465 | /* Waiting for more R2Ts to arrive. */ |
| 1466 | if (r2t == NULL) { |
| 1467 | debug_tcp("no R2Ts yet\n"); |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | debug_scsi("sol dout %p [dsn %d itt 0x%x doff %d dlen %d]\n", |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1472 | r2t, r2t->solicit_datasn - 1, task->itt, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1473 | r2t->data_offset + r2t->sent, r2t->data_count); |
| 1474 | |
| 1475 | iscsi_tcp_send_hdr_prep(conn, &r2t->dtask.hdr, |
| 1476 | sizeof(struct iscsi_hdr)); |
| 1477 | |
Boaz Harrosh | 94795b6 | 2008-04-18 10:11:53 -0500 | [diff] [blame] | 1478 | rc = iscsi_tcp_send_data_prep(conn, sdb->table.sgl, |
| 1479 | sdb->table.nents, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1480 | r2t->data_offset + r2t->sent, |
| 1481 | r2t->data_count); |
| 1482 | if (rc) |
| 1483 | goto fail; |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1484 | tcp_task->sent += r2t->data_count; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1485 | r2t->sent += r2t->data_count; |
| 1486 | goto flush; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1487 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 1488 | return 0; |
| 1489 | fail: |
| 1490 | iscsi_conn_failure(conn, rc); |
| 1491 | return -EIO; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1494 | static struct iscsi_cls_conn * |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1495 | 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] | 1496 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1497 | struct iscsi_conn *conn; |
| 1498 | struct iscsi_cls_conn *cls_conn; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1499 | struct iscsi_tcp_conn *tcp_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1500 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1501 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*tcp_conn), conn_idx); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1502 | if (!cls_conn) |
| 1503 | return NULL; |
| 1504 | conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1505 | /* |
| 1506 | * due to strange issues with iser these are not set |
| 1507 | * in iscsi_conn_setup |
| 1508 | */ |
Mike Christie | bf32ed3 | 2007-02-28 17:32:17 -0600 | [diff] [blame] | 1509 | conn->max_recv_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1510 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1511 | tcp_conn = conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1512 | tcp_conn->iscsi_conn = conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1513 | |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1514 | tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 1515 | CRYPTO_ALG_ASYNC); |
| 1516 | tcp_conn->tx_hash.flags = 0; |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1517 | if (IS_ERR(tcp_conn->tx_hash.tfm)) |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1518 | goto free_conn; |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1519 | |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1520 | tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 1521 | CRYPTO_ALG_ASYNC); |
| 1522 | tcp_conn->rx_hash.flags = 0; |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1523 | if (IS_ERR(tcp_conn->rx_hash.tfm)) |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1524 | goto free_tx_tfm; |
| 1525 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1526 | return cls_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1527 | |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 1528 | free_tx_tfm: |
James Bottomley | c9802cd | 2006-09-23 15:33:43 -0500 | [diff] [blame] | 1529 | crypto_free_hash(tcp_conn->tx_hash.tfm); |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1530 | free_conn: |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1531 | iscsi_conn_printk(KERN_ERR, conn, |
| 1532 | "Could not create connection due to crc32c " |
| 1533 | "loading error. Make sure the crc32c " |
| 1534 | "module is built as a module or into the " |
| 1535 | "kernel\n"); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1536 | iscsi_conn_teardown(cls_conn); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1537 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | static void |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1541 | iscsi_tcp_release_conn(struct iscsi_conn *conn) |
| 1542 | { |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1543 | struct iscsi_session *session = conn->session; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1544 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1545 | struct socket *sock = tcp_conn->sock; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1546 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1547 | if (!sock) |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1548 | return; |
| 1549 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1550 | sock_hold(sock->sk); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1551 | iscsi_conn_restore_callbacks(tcp_conn); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1552 | sock_put(sock->sk); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1553 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1554 | spin_lock_bh(&session->lock); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1555 | tcp_conn->sock = NULL; |
| 1556 | conn->recv_lock = NULL; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1557 | spin_unlock_bh(&session->lock); |
| 1558 | sockfd_put(sock); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static void |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1562 | iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1563 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1564 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1565 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1566 | |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1567 | iscsi_tcp_release_conn(conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1568 | |
Pete Wyckoff | 534284a | 2006-11-08 15:58:31 -0600 | [diff] [blame] | 1569 | if (tcp_conn->tx_hash.tfm) |
| 1570 | crypto_free_hash(tcp_conn->tx_hash.tfm); |
| 1571 | if (tcp_conn->rx_hash.tfm) |
| 1572 | crypto_free_hash(tcp_conn->rx_hash.tfm); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1573 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1574 | iscsi_conn_teardown(cls_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1577 | static void |
| 1578 | iscsi_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) |
| 1579 | { |
| 1580 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 1581 | |
| 1582 | iscsi_conn_stop(cls_conn, flag); |
| 1583 | iscsi_tcp_release_conn(conn); |
| 1584 | } |
| 1585 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1586 | static int iscsi_tcp_get_addr(struct iscsi_conn *conn, struct socket *sock, |
| 1587 | char *buf, int *port, |
| 1588 | int (*getname)(struct socket *, struct sockaddr *, |
| 1589 | int *addrlen)) |
| 1590 | { |
| 1591 | struct sockaddr_storage *addr; |
| 1592 | struct sockaddr_in6 *sin6; |
| 1593 | struct sockaddr_in *sin; |
| 1594 | int rc = 0, len; |
| 1595 | |
Al Viro | a920487 | 2007-07-20 16:03:40 +0100 | [diff] [blame] | 1596 | addr = kmalloc(sizeof(*addr), GFP_KERNEL); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1597 | if (!addr) |
| 1598 | return -ENOMEM; |
| 1599 | |
| 1600 | if (getname(sock, (struct sockaddr *) addr, &len)) { |
| 1601 | rc = -ENODEV; |
| 1602 | goto free_addr; |
| 1603 | } |
| 1604 | |
| 1605 | switch (addr->ss_family) { |
| 1606 | case AF_INET: |
| 1607 | sin = (struct sockaddr_in *)addr; |
| 1608 | spin_lock_bh(&conn->session->lock); |
| 1609 | sprintf(buf, NIPQUAD_FMT, NIPQUAD(sin->sin_addr.s_addr)); |
| 1610 | *port = be16_to_cpu(sin->sin_port); |
| 1611 | spin_unlock_bh(&conn->session->lock); |
| 1612 | break; |
| 1613 | case AF_INET6: |
| 1614 | sin6 = (struct sockaddr_in6 *)addr; |
| 1615 | spin_lock_bh(&conn->session->lock); |
| 1616 | sprintf(buf, NIP6_FMT, NIP6(sin6->sin6_addr)); |
| 1617 | *port = be16_to_cpu(sin6->sin6_port); |
| 1618 | spin_unlock_bh(&conn->session->lock); |
| 1619 | break; |
| 1620 | } |
| 1621 | free_addr: |
| 1622 | kfree(addr); |
| 1623 | return rc; |
| 1624 | } |
| 1625 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1626 | static int |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1627 | iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1628 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1629 | int is_leading) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1630 | { |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1631 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); |
| 1632 | struct iscsi_host *ihost = shost_priv(shost); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1633 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 1634 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1635 | struct sock *sk; |
| 1636 | struct socket *sock; |
| 1637 | int err; |
| 1638 | |
| 1639 | /* lookup for existing socket */ |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1640 | sock = sockfd_lookup((int)transport_eph, &err); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1641 | if (!sock) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1642 | iscsi_conn_printk(KERN_ERR, conn, |
| 1643 | "sockfd_lookup failed %d\n", err); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1644 | return -EEXIST; |
| 1645 | } |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1646 | /* |
| 1647 | * copy these values now because if we drop the session |
| 1648 | * userspace may still want to query the values since we will |
| 1649 | * be using them for the reconnect |
| 1650 | */ |
| 1651 | err = iscsi_tcp_get_addr(conn, sock, conn->portal_address, |
| 1652 | &conn->portal_port, kernel_getpeername); |
| 1653 | if (err) |
| 1654 | goto free_socket; |
| 1655 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1656 | err = iscsi_tcp_get_addr(conn, sock, ihost->local_address, |
| 1657 | &ihost->local_port, kernel_getsockname); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1658 | if (err) |
| 1659 | goto free_socket; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1660 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1661 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
| 1662 | if (err) |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1663 | goto free_socket; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1664 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1665 | /* bind iSCSI connection and socket */ |
| 1666 | tcp_conn->sock = sock; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1667 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1668 | /* setup Socket parameters */ |
| 1669 | sk = sock->sk; |
| 1670 | sk->sk_reuse = 1; |
| 1671 | sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */ |
| 1672 | sk->sk_allocation = GFP_ATOMIC; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1673 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1674 | /* FIXME: disable Nagle's algorithm */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1675 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 1676 | /* |
| 1677 | * Intercept TCP callbacks for sendfile like receive |
| 1678 | * processing. |
| 1679 | */ |
| 1680 | conn->recv_lock = &sk->sk_callback_lock; |
| 1681 | iscsi_conn_set_callbacks(conn); |
| 1682 | tcp_conn->sendpage = tcp_conn->sock->ops->sendpage; |
| 1683 | /* |
| 1684 | * set receive state machine into initial state |
| 1685 | */ |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 1686 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1687 | return 0; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1688 | |
| 1689 | free_socket: |
| 1690 | sockfd_put(sock); |
| 1691 | return err; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1694 | static int |
| 1695 | iscsi_r2tpool_alloc(struct iscsi_session *session) |
| 1696 | { |
| 1697 | int i; |
| 1698 | int cmd_i; |
| 1699 | |
| 1700 | /* |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1701 | * initialize per-task: R2T pool and xmit queue |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1702 | */ |
| 1703 | for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1704 | struct iscsi_task *task = session->cmds[cmd_i]; |
| 1705 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1706 | |
| 1707 | /* |
| 1708 | * pre-allocated x4 as much r2ts to handle race when |
| 1709 | * target acks DataOut faster than we data_xmit() queues |
| 1710 | * could replenish r2tqueue. |
| 1711 | */ |
| 1712 | |
| 1713 | /* R2T pool */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1714 | if (iscsi_pool_init(&tcp_task->r2tpool, session->max_r2t * 4, NULL, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1715 | sizeof(struct iscsi_r2t_info))) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1716 | goto r2t_alloc_fail; |
| 1717 | } |
| 1718 | |
| 1719 | /* R2T xmit queue */ |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1720 | tcp_task->r2tqueue = kfifo_alloc( |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1721 | session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL); |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1722 | if (tcp_task->r2tqueue == ERR_PTR(-ENOMEM)) { |
| 1723 | iscsi_pool_free(&tcp_task->r2tpool); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1724 | goto r2t_alloc_fail; |
| 1725 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | return 0; |
| 1729 | |
| 1730 | r2t_alloc_fail: |
| 1731 | for (i = 0; i < cmd_i; i++) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1732 | struct iscsi_task *task = session->cmds[i]; |
| 1733 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1734 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1735 | kfifo_free(tcp_task->r2tqueue); |
| 1736 | iscsi_pool_free(&tcp_task->r2tpool); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1737 | } |
| 1738 | return -ENOMEM; |
| 1739 | } |
| 1740 | |
| 1741 | static void |
| 1742 | iscsi_r2tpool_free(struct iscsi_session *session) |
| 1743 | { |
| 1744 | int i; |
| 1745 | |
| 1746 | for (i = 0; i < session->cmds_max; i++) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1747 | struct iscsi_task *task = session->cmds[i]; |
| 1748 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1749 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1750 | kfifo_free(tcp_task->r2tqueue); |
| 1751 | iscsi_pool_free(&tcp_task->r2tpool); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1755 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1756 | 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] | 1757 | char *buf, int buflen) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1758 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1759 | struct iscsi_conn *conn = cls_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1760 | struct iscsi_session *session = conn->session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1761 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1762 | int value; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1763 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1764 | switch(param) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1765 | case ISCSI_PARAM_HDRDGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1766 | iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1767 | break; |
| 1768 | case ISCSI_PARAM_DATADGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1769 | iscsi_set_param(cls_conn, param, buf, buflen); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1770 | tcp_conn->sendpage = conn->datadgst_en ? |
| 1771 | sock_no_sendpage : tcp_conn->sock->ops->sendpage; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1772 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1773 | case ISCSI_PARAM_MAX_R2T: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1774 | sscanf(buf, "%d", &value); |
Mike Christie | df93ffc | 2007-12-13 12:43:42 -0600 | [diff] [blame] | 1775 | if (value <= 0 || !is_power_of_2(value)) |
| 1776 | return -EINVAL; |
| 1777 | if (session->max_r2t == value) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1778 | break; |
| 1779 | iscsi_r2tpool_free(session); |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1780 | iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1781 | if (iscsi_r2tpool_alloc(session)) |
| 1782 | return -ENOMEM; |
| 1783 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1784 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1785 | return iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | static int |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1792 | iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, |
| 1793 | enum iscsi_param param, char *buf) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1794 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1795 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1796 | int len; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1797 | |
| 1798 | switch(param) { |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1799 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1800 | spin_lock_bh(&conn->session->lock); |
| 1801 | len = sprintf(buf, "%hu\n", conn->portal_port); |
| 1802 | spin_unlock_bh(&conn->session->lock); |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 1803 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1804 | case ISCSI_PARAM_CONN_ADDRESS: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1805 | spin_lock_bh(&conn->session->lock); |
| 1806 | len = sprintf(buf, "%s\n", conn->portal_address); |
| 1807 | spin_unlock_bh(&conn->session->lock); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1808 | break; |
| 1809 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1810 | return iscsi_conn_get_param(cls_conn, param, buf); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | return len; |
| 1814 | } |
| 1815 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1816 | static void |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1817 | 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] | 1818 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1819 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1820 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1821 | |
| 1822 | stats->txdata_octets = conn->txdata_octets; |
| 1823 | stats->rxdata_octets = conn->rxdata_octets; |
| 1824 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; |
| 1825 | stats->dataout_pdus = conn->dataout_pdus_cnt; |
| 1826 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; |
| 1827 | stats->datain_pdus = conn->datain_pdus_cnt; |
| 1828 | stats->r2t_pdus = conn->r2t_pdus_cnt; |
| 1829 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; |
| 1830 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; |
| 1831 | stats->custom_length = 3; |
| 1832 | strcpy(stats->custom[0].desc, "tx_sendpage_failures"); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1833 | stats->custom[0].value = tcp_conn->sendpage_failures_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1834 | strcpy(stats->custom[1].desc, "rx_discontiguous_hdr"); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1835 | stats->custom[1].value = tcp_conn->discontiguous_hdr_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1836 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); |
| 1837 | stats->custom[2].value = conn->eh_abort_cnt; |
| 1838 | } |
| 1839 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1840 | static struct iscsi_cls_session * |
Mike Christie | 06520ede | 2008-05-21 15:54:15 -0500 | [diff] [blame] | 1841 | iscsi_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 1842 | uint16_t qdepth, uint32_t initial_cmdsn, |
| 1843 | uint32_t *hostno) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1844 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1845 | struct iscsi_cls_session *cls_session; |
| 1846 | struct iscsi_session *session; |
Mike Christie | 06520ede | 2008-05-21 15:54:15 -0500 | [diff] [blame] | 1847 | struct Scsi_Host *shost; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1848 | int cmd_i; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1849 | |
Mike Christie | 06520ede | 2008-05-21 15:54:15 -0500 | [diff] [blame] | 1850 | if (ep) { |
| 1851 | printk(KERN_ERR "iscsi_tcp: invalid ep %p.\n", ep); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1852 | return NULL; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1853 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1854 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1855 | shost = iscsi_host_alloc(&iscsi_sht, 0, qdepth); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1856 | if (!shost) |
| 1857 | return NULL; |
| 1858 | shost->transportt = iscsi_tcp_scsi_transport; |
| 1859 | shost->max_lun = iscsi_max_lun; |
| 1860 | shost->max_id = 0; |
| 1861 | shost->max_channel = 0; |
| 1862 | shost->max_cmd_len = 16; |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1863 | shost->can_queue = cmds_max; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1864 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1865 | if (iscsi_host_add(shost, NULL)) |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1866 | goto free_host; |
| 1867 | *hostno = shost->host_no; |
| 1868 | |
| 1869 | cls_session = iscsi_session_setup(&iscsi_tcp_transport, shost, cmds_max, |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1870 | sizeof(struct iscsi_tcp_task), |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1871 | initial_cmdsn, 0); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1872 | if (!cls_session) |
| 1873 | goto remove_host; |
| 1874 | session = cls_session->dd_data; |
| 1875 | |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1876 | shost->can_queue = session->scsi_cmds_max; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1877 | for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1878 | struct iscsi_task *task = session->cmds[cmd_i]; |
| 1879 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1880 | |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 1881 | task->hdr = &tcp_task->hdr.cmd_hdr; |
| 1882 | task->hdr_max = sizeof(tcp_task->hdr) - ISCSI_DIGEST_SIZE; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1883 | } |
| 1884 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1885 | if (iscsi_r2tpool_alloc(session)) |
| 1886 | goto remove_session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1887 | return cls_session; |
| 1888 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1889 | remove_session: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1890 | iscsi_session_teardown(cls_session); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1891 | remove_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1892 | iscsi_host_remove(shost); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1893 | free_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1894 | iscsi_host_free(shost); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1895 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1898 | static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session) |
| 1899 | { |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1900 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); |
| 1901 | |
| 1902 | iscsi_r2tpool_free(cls_session->dd_data); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1903 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1904 | iscsi_host_remove(shost); |
| 1905 | iscsi_host_free(shost); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1906 | } |
| 1907 | |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 1908 | static int iscsi_tcp_slave_configure(struct scsi_device *sdev) |
| 1909 | { |
Mike Christie | b6d44fe | 2007-07-26 12:46:47 -0500 | [diff] [blame] | 1910 | blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_ANY); |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 1911 | blk_queue_dma_alignment(sdev->request_queue, 0); |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1915 | static struct scsi_host_template iscsi_sht = { |
Mike Christie | 7974392 | 2007-07-26 12:46:46 -0500 | [diff] [blame] | 1916 | .module = THIS_MODULE, |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 1917 | .name = "iSCSI Initiator over TCP/IP", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1918 | .queuecommand = iscsi_queuecommand, |
| 1919 | .change_queue_depth = iscsi_change_queue_depth, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 1920 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
Mike Christie | 66bbe0c | 2007-12-13 12:43:39 -0600 | [diff] [blame] | 1921 | .sg_tablesize = 4096, |
Mike Christie | 8231f0e | 2007-02-28 17:32:20 -0600 | [diff] [blame] | 1922 | .max_sectors = 0xFFFF, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1923 | .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, |
| 1924 | .eh_abort_handler = iscsi_eh_abort, |
Mike Christie | 843c0a8 | 2007-12-13 12:43:20 -0600 | [diff] [blame] | 1925 | .eh_device_reset_handler= iscsi_eh_device_reset, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1926 | .eh_host_reset_handler = iscsi_eh_host_reset, |
| 1927 | .use_clustering = DISABLE_CLUSTERING, |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 1928 | .slave_configure = iscsi_tcp_slave_configure, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1929 | .proc_name = "iscsi_tcp", |
| 1930 | .this_id = -1, |
| 1931 | }; |
| 1932 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1933 | static struct iscsi_transport iscsi_tcp_transport = { |
| 1934 | .owner = THIS_MODULE, |
| 1935 | .name = "tcp", |
| 1936 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
| 1937 | | CAP_DATADGST, |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1938 | .param_mask = ISCSI_MAX_RECV_DLENGTH | |
| 1939 | ISCSI_MAX_XMIT_DLENGTH | |
| 1940 | ISCSI_HDRDGST_EN | |
| 1941 | ISCSI_DATADGST_EN | |
| 1942 | ISCSI_INITIAL_R2T_EN | |
| 1943 | ISCSI_MAX_R2T | |
| 1944 | ISCSI_IMM_DATA_EN | |
| 1945 | ISCSI_FIRST_BURST | |
| 1946 | ISCSI_MAX_BURST | |
| 1947 | ISCSI_PDU_INORDER_EN | |
| 1948 | ISCSI_DATASEQ_INORDER_EN | |
| 1949 | ISCSI_ERL | |
| 1950 | ISCSI_CONN_PORT | |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 1951 | ISCSI_CONN_ADDRESS | |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1952 | ISCSI_EXP_STATSN | |
| 1953 | ISCSI_PERSISTENT_PORT | |
| 1954 | ISCSI_PERSISTENT_ADDRESS | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 1955 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
| 1956 | ISCSI_USERNAME | ISCSI_PASSWORD | |
Mike Christie | 843c0a8 | 2007-12-13 12:43:20 -0600 | [diff] [blame] | 1957 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | |
Mike Christie | f6d5180 | 2007-12-13 12:43:30 -0600 | [diff] [blame] | 1958 | ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | |
| 1959 | ISCSI_LU_RESET_TMO | |
Mike Christie | 88dfd34 | 2008-05-21 15:54:16 -0500 | [diff] [blame^] | 1960 | ISCSI_PING_TMO | ISCSI_RECV_TMO | |
| 1961 | ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME, |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1962 | .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 1963 | ISCSI_HOST_INITIATOR_NAME | |
| 1964 | ISCSI_HOST_NETDEV_NAME, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1965 | /* session management */ |
| 1966 | .create_session = iscsi_tcp_session_create, |
| 1967 | .destroy_session = iscsi_tcp_session_destroy, |
| 1968 | /* connection management */ |
| 1969 | .create_conn = iscsi_tcp_conn_create, |
| 1970 | .bind_conn = iscsi_tcp_conn_bind, |
| 1971 | .destroy_conn = iscsi_tcp_conn_destroy, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1972 | .set_param = iscsi_conn_set_param, |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 1973 | .get_conn_param = iscsi_tcp_conn_get_param, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1974 | .get_session_param = iscsi_session_get_param, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1975 | .start_conn = iscsi_conn_start, |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 1976 | .stop_conn = iscsi_tcp_conn_stop, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 1977 | /* iscsi host params */ |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1978 | .get_host_param = iscsi_host_get_param, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 1979 | .set_host_param = iscsi_host_set_param, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1980 | /* IO */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1981 | .send_pdu = iscsi_conn_send_pdu, |
| 1982 | .get_stats = iscsi_conn_get_stats, |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1983 | .init_task = iscsi_tcp_task_init, |
| 1984 | .xmit_task = iscsi_tcp_task_xmit, |
| 1985 | .cleanup_task = iscsi_tcp_cleanup_task, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1986 | /* recovery */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1987 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1988 | }; |
| 1989 | |
| 1990 | static int __init |
| 1991 | iscsi_tcp_init(void) |
| 1992 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1993 | if (iscsi_max_lun < 1) { |
Or Gerlitz | be2df72 | 2006-05-02 19:46:43 -0500 | [diff] [blame] | 1994 | printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n", |
| 1995 | iscsi_max_lun); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1996 | return -EINVAL; |
| 1997 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1998 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 1999 | iscsi_tcp_scsi_transport = iscsi_register_transport( |
| 2000 | &iscsi_tcp_transport); |
| 2001 | if (!iscsi_tcp_scsi_transport) |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 2002 | return -ENODEV; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2003 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2004 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | static void __exit |
| 2008 | iscsi_tcp_exit(void) |
| 2009 | { |
| 2010 | iscsi_unregister_transport(&iscsi_tcp_transport); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | module_init(iscsi_tcp_init); |
| 2014 | module_exit(iscsi_tcp_exit); |