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