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