blob: ed3debce2819afa24bf066db7c44b76b15f50e48 [file] [log] [blame]
Alex Aizman7ba24712005-08-04 19:30:08 -07001/*
2 * iSCSI Initiator over TCP/IP Data-Path
3 *
4 * Copyright (C) 2004 Dmitry Yusupov
5 * Copyright (C) 2004 Alex Aizman
Mike Christie5bb0b552006-04-06 21:26:46 -05006 * Copyright (C) 2005 - 2006 Mike Christie
7 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
Alex Aizman7ba24712005-08-04 19:30:08 -07008 * 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
Herbert Xu5d6ac292016-01-24 21:19:41 +080029#include <crypto/hash.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070030#include <linux/types.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070031#include <linux/inet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Vlastimil Babkaf1083042017-05-08 15:59:53 -070033#include <linux/sched/mm.h>
Mike Christie4e7aba72007-05-30 12:57:23 -050034#include <linux/file.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070035#include <linux/blkdev.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070036#include <linux/delay.h>
37#include <linux/kfifo.h>
38#include <linux/scatterlist.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040039#include <linux/module.h>
Jianchao Wang89d0c802018-03-07 20:29:03 +080040#include <linux/backing-dev.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070041#include <net/tcp.h>
42#include <scsi/scsi_cmnd.h>
Mike Christied1d81c02007-05-30 12:57:21 -050043#include <scsi/scsi_device.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070044#include <scsi/scsi_host.h>
45#include <scsi/scsi.h>
46#include <scsi/scsi_transport_iscsi.h>
Fred Herardc2332b02018-11-21 12:04:43 -050047#include <trace/events/iscsi.h>
Alex Aizman7ba24712005-08-04 19:30:08 -070048
49#include "iscsi_tcp.h"
50
Mike Christie38e1a8f2008-12-02 00:32:12 -060051MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
52 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
Alex Aizman7ba24712005-08-04 19:30:08 -070053 "Alex Aizman <itn780@yahoo.com>");
54MODULE_DESCRIPTION("iSCSI/TCP data-path");
55MODULE_LICENSE("GPL");
Alex Aizman7ba24712005-08-04 19:30:08 -070056
Mike Christie38e1a8f2008-12-02 00:32:12 -060057static struct scsi_transport_template *iscsi_sw_tcp_scsi_transport;
58static struct scsi_host_template iscsi_sw_tcp_sht;
59static struct iscsi_transport iscsi_sw_tcp_transport;
Mike Christie75613522008-05-21 15:53:59 -050060
Rob Eversc0e4eaa2012-08-15 18:39:34 -040061static unsigned int iscsi_max_lun = ~0;
Alex Aizman7ba24712005-08-04 19:30:08 -070062module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
63
Mike Christiec93f87c2009-03-05 14:46:00 -060064static int iscsi_sw_tcp_dbg;
65module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int,
66 S_IRUGO | S_IWUSR);
67MODULE_PARM_DESC(debug_iscsi_tcp, "Turn on debugging for iscsi_tcp module "
68 "Set to 1 to turn on, and zero to turn off. Default is off.");
69
70#define ISCSI_SW_TCP_DBG(_conn, dbg_fmt, arg...) \
71 do { \
72 if (iscsi_sw_tcp_dbg) \
73 iscsi_conn_printk(KERN_INFO, _conn, \
74 "%s " dbg_fmt, \
75 __func__, ##arg); \
Fred Herardc2332b02018-11-21 12:04:43 -050076 iscsi_dbg_trace(trace_iscsi_dbg_sw_tcp, \
77 &(_conn)->cls_conn->dev, \
78 "%s " dbg_fmt, __func__, ##arg);\
Mike Christiec93f87c2009-03-05 14:46:00 -060079 } while (0);
80
81
Olaf Kirchda32dd62007-12-13 12:43:21 -060082/**
Mike Christie38e1a8f2008-12-02 00:32:12 -060083 * iscsi_sw_tcp_recv - TCP receive in sendfile fashion
84 * @rd_desc: read descriptor
85 * @skb: socket buffer
86 * @offset: offset in skb
87 * @len: skb->len - offset
Olaf Kirchda32dd62007-12-13 12:43:21 -060088 */
Mike Christie38e1a8f2008-12-02 00:32:12 -060089static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
90 unsigned int offset, size_t len)
Alex Aizman7ba24712005-08-04 19:30:08 -070091{
Mike Christie38e1a8f2008-12-02 00:32:12 -060092 struct iscsi_conn *conn = rd_desc->arg.data;
93 unsigned int consumed, total_consumed = 0;
94 int status;
95
Mike Christiec93f87c2009-03-05 14:46:00 -060096 ISCSI_SW_TCP_DBG(conn, "in %d bytes\n", skb->len - offset);
Mike Christie38e1a8f2008-12-02 00:32:12 -060097
98 do {
99 status = 0;
100 consumed = iscsi_tcp_recv_skb(conn, skb, offset, 0, &status);
101 offset += consumed;
102 total_consumed += consumed;
103 } while (consumed != 0 && status != ISCSI_TCP_SKB_DONE);
104
Mike Christiec93f87c2009-03-05 14:46:00 -0600105 ISCSI_SW_TCP_DBG(conn, "read %d bytes status %d\n",
106 skb->len - offset, status);
Mike Christie38e1a8f2008-12-02 00:32:12 -0600107 return total_consumed;
Olaf Kirchda32dd62007-12-13 12:43:21 -0600108}
Alex Aizman7ba24712005-08-04 19:30:08 -0700109
Hannes Reinecke523eeac2009-08-20 15:10:57 -0500110/**
111 * iscsi_sw_sk_state_check - check socket state
112 * @sk: socket
113 *
114 * If the socket is in CLOSE or CLOSE_WAIT we should
115 * not close the connection if there is still some
116 * data pending.
Mike Christie03adb5f2011-06-24 15:11:54 -0500117 *
118 * Must be called with sk_callback_lock.
Hannes Reinecke523eeac2009-08-20 15:10:57 -0500119 */
120static inline int iscsi_sw_sk_state_check(struct sock *sk)
121{
Mike Christie03adb5f2011-06-24 15:11:54 -0500122 struct iscsi_conn *conn = sk->sk_user_data;
Hannes Reinecke523eeac2009-08-20 15:10:57 -0500123
Mike Christied1af8a32009-08-20 15:11:02 -0500124 if ((sk->sk_state == TCP_CLOSE_WAIT || sk->sk_state == TCP_CLOSE) &&
Chris Leechc7124952013-09-26 09:09:44 -0700125 (conn->session->state != ISCSI_STATE_LOGGING_OUT) &&
Mike Christied1af8a32009-08-20 15:11:02 -0500126 !atomic_read(&sk->sk_rmem_alloc)) {
127 ISCSI_SW_TCP_DBG(conn, "TCP_CLOSE|TCP_CLOSE_WAIT\n");
128 iscsi_conn_failure(conn, ISCSI_ERR_TCP_CONN_CLOSE);
129 return -ECONNRESET;
130 }
Hannes Reinecke523eeac2009-08-20 15:10:57 -0500131 return 0;
132}
133
David S. Miller676d2362014-04-11 16:15:36 -0400134static void iscsi_sw_tcp_data_ready(struct sock *sk)
Olaf Kirchda32dd62007-12-13 12:43:21 -0600135{
Mike Christie03adb5f2011-06-24 15:11:54 -0500136 struct iscsi_conn *conn;
137 struct iscsi_tcp_conn *tcp_conn;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600138 read_descriptor_t rd_desc;
Alex Aizman7ba24712005-08-04 19:30:08 -0700139
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700140 read_lock_bh(&sk->sk_callback_lock);
Mike Christie03adb5f2011-06-24 15:11:54 -0500141 conn = sk->sk_user_data;
142 if (!conn) {
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700143 read_unlock_bh(&sk->sk_callback_lock);
Mike Christie03adb5f2011-06-24 15:11:54 -0500144 return;
145 }
146 tcp_conn = conn->dd_data;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600147
148 /*
Mike Christie38e1a8f2008-12-02 00:32:12 -0600149 * Use rd_desc to pass 'conn' to iscsi_tcp_recv.
150 * We set count to 1 because we want the network layer to
151 * hand us all the skbs that are available. iscsi_tcp_recv
152 * handled pdus that cross buffers or pdus that still need data.
Olaf Kircha8ac6312007-12-13 12:43:35 -0600153 */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600154 rd_desc.arg.data = conn;
155 rd_desc.count = 1;
156 tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600157
Mike Christied1af8a32009-08-20 15:11:02 -0500158 iscsi_sw_sk_state_check(sk);
Hannes Reinecke523eeac2009-08-20 15:10:57 -0500159
Mike Christie38e1a8f2008-12-02 00:32:12 -0600160 /* If we had to (atomically) map a highmem page,
161 * unmap it now. */
162 iscsi_tcp_segment_unmap(&tcp_conn->in.segment);
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700163 read_unlock_bh(&sk->sk_callback_lock);
Olaf Kirchda32dd62007-12-13 12:43:21 -0600164}
Alex Aizman7ba24712005-08-04 19:30:08 -0700165
Mike Christie38e1a8f2008-12-02 00:32:12 -0600166static void iscsi_sw_tcp_state_change(struct sock *sk)
Olaf Kirchda32dd62007-12-13 12:43:21 -0600167{
Mike Christie38e1a8f2008-12-02 00:32:12 -0600168 struct iscsi_tcp_conn *tcp_conn;
169 struct iscsi_sw_tcp_conn *tcp_sw_conn;
170 struct iscsi_conn *conn;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600171 void (*old_state_change)(struct sock *);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600172
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700173 read_lock_bh(&sk->sk_callback_lock);
Mike Christie03adb5f2011-06-24 15:11:54 -0500174 conn = sk->sk_user_data;
175 if (!conn) {
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700176 read_unlock_bh(&sk->sk_callback_lock);
Mike Christie03adb5f2011-06-24 15:11:54 -0500177 return;
178 }
Mike Christie38e1a8f2008-12-02 00:32:12 -0600179
Mike Christied1af8a32009-08-20 15:11:02 -0500180 iscsi_sw_sk_state_check(sk);
Alex Aizman7ba24712005-08-04 19:30:08 -0700181
Mike Christie38e1a8f2008-12-02 00:32:12 -0600182 tcp_conn = conn->dd_data;
183 tcp_sw_conn = tcp_conn->dd_data;
184 old_state_change = tcp_sw_conn->old_state_change;
185
Eric Dumazet7cb001d2016-05-17 17:44:06 -0700186 read_unlock_bh(&sk->sk_callback_lock);
Mike Christie38e1a8f2008-12-02 00:32:12 -0600187
188 old_state_change(sk);
Olaf Kirchda32dd62007-12-13 12:43:21 -0600189}
Alex Aizman7ba24712005-08-04 19:30:08 -0700190
Olaf Kirchda32dd62007-12-13 12:43:21 -0600191/**
Mike Christie38e1a8f2008-12-02 00:32:12 -0600192 * iscsi_write_space - Called when more output buffer space is available
193 * @sk: socket space is available for
194 **/
195static void iscsi_sw_tcp_write_space(struct sock *sk)
Olaf Kirchda32dd62007-12-13 12:43:21 -0600196{
Mike Christie03adb5f2011-06-24 15:11:54 -0500197 struct iscsi_conn *conn;
198 struct iscsi_tcp_conn *tcp_conn;
199 struct iscsi_sw_tcp_conn *tcp_sw_conn;
200 void (*old_write_space)(struct sock *);
Olaf Kirchda32dd62007-12-13 12:43:21 -0600201
Mike Christie03adb5f2011-06-24 15:11:54 -0500202 read_lock_bh(&sk->sk_callback_lock);
203 conn = sk->sk_user_data;
204 if (!conn) {
205 read_unlock_bh(&sk->sk_callback_lock);
206 return;
207 }
208
209 tcp_conn = conn->dd_data;
210 tcp_sw_conn = tcp_conn->dd_data;
211 old_write_space = tcp_sw_conn->old_write_space;
212 read_unlock_bh(&sk->sk_callback_lock);
213
214 old_write_space(sk);
215
Mike Christiec93f87c2009-03-05 14:46:00 -0600216 ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
Mike Christie32ae7632009-03-05 14:46:03 -0600217 iscsi_conn_queue_work(conn);
Mike Christie38e1a8f2008-12-02 00:32:12 -0600218}
Olaf Kircha8ac6312007-12-13 12:43:35 -0600219
Mike Christie38e1a8f2008-12-02 00:32:12 -0600220static void iscsi_sw_tcp_conn_set_callbacks(struct iscsi_conn *conn)
221{
222 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
223 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
224 struct sock *sk = tcp_sw_conn->sock->sk;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600225
Mike Christie38e1a8f2008-12-02 00:32:12 -0600226 /* assign new callbacks */
227 write_lock_bh(&sk->sk_callback_lock);
228 sk->sk_user_data = conn;
229 tcp_sw_conn->old_data_ready = sk->sk_data_ready;
230 tcp_sw_conn->old_state_change = sk->sk_state_change;
231 tcp_sw_conn->old_write_space = sk->sk_write_space;
232 sk->sk_data_ready = iscsi_sw_tcp_data_ready;
233 sk->sk_state_change = iscsi_sw_tcp_state_change;
234 sk->sk_write_space = iscsi_sw_tcp_write_space;
235 write_unlock_bh(&sk->sk_callback_lock);
236}
Alex Aizman7ba24712005-08-04 19:30:08 -0700237
Mike Christie38e1a8f2008-12-02 00:32:12 -0600238static void
Avi Kaplanc484a50a2010-04-09 22:07:38 -0500239iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn)
Mike Christie38e1a8f2008-12-02 00:32:12 -0600240{
Avi Kaplanc484a50a2010-04-09 22:07:38 -0500241 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
242 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600243 struct sock *sk = tcp_sw_conn->sock->sk;
Olaf Kirchda32dd62007-12-13 12:43:21 -0600244
Mike Christie38e1a8f2008-12-02 00:32:12 -0600245 /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */
246 write_lock_bh(&sk->sk_callback_lock);
247 sk->sk_user_data = NULL;
248 sk->sk_data_ready = tcp_sw_conn->old_data_ready;
249 sk->sk_state_change = tcp_sw_conn->old_state_change;
250 sk->sk_write_space = tcp_sw_conn->old_write_space;
Tom Herbert28448b82014-05-23 08:47:19 -0700251 sk->sk_no_check_tx = 0;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600252 write_unlock_bh(&sk->sk_callback_lock);
Olaf Kirchda32dd62007-12-13 12:43:21 -0600253}
254
255/**
Mike Christie38e1a8f2008-12-02 00:32:12 -0600256 * iscsi_sw_tcp_xmit_segment - transmit segment
Mike Christie6df19a72008-12-02 00:32:16 -0600257 * @tcp_conn: the iSCSI TCP connection
Olaf Kircha8ac6312007-12-13 12:43:35 -0600258 * @segment: the buffer to transmnit
259 *
260 * This function transmits as much of the buffer as
261 * the network layer will accept, and returns the number of
262 * bytes transmitted.
263 *
264 * If CRC hashing is enabled, the function will compute the
265 * hash as it goes. When the entire segment has been transmitted,
266 * it will retrieve the hash value and send it as well.
267 */
Mike Christie6df19a72008-12-02 00:32:16 -0600268static int iscsi_sw_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn,
Mike Christie38e1a8f2008-12-02 00:32:12 -0600269 struct iscsi_segment *segment)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600270{
Mike Christie6df19a72008-12-02 00:32:16 -0600271 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600272 struct socket *sk = tcp_sw_conn->sock;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600273 unsigned int copied = 0;
274 int r = 0;
275
Mike Christie6df19a72008-12-02 00:32:16 -0600276 while (!iscsi_tcp_segment_done(tcp_conn, segment, 0, r)) {
Olaf Kircha8ac6312007-12-13 12:43:35 -0600277 struct scatterlist *sg;
278 unsigned int offset, copy;
279 int flags = 0;
280
281 r = 0;
282 offset = segment->copied;
283 copy = segment->size - offset;
284
285 if (segment->total_copied + segment->size < segment->total_size)
286 flags |= MSG_MORE;
287
288 /* Use sendpage if we can; else fall back to sendmsg */
289 if (!segment->data) {
290 sg = segment->sg;
291 offset += segment->sg_offset + sg->offset;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600292 r = tcp_sw_conn->sendpage(sk, sg_page(sg), offset,
293 copy, flags);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600294 } else {
295 struct msghdr msg = { .msg_flags = flags };
296 struct kvec iov = {
297 .iov_base = segment->data + offset,
298 .iov_len = copy
299 };
300
301 r = kernel_sendmsg(sk, &msg, &iov, 1, copy);
302 }
303
304 if (r < 0) {
305 iscsi_tcp_segment_unmap(segment);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600306 return r;
307 }
308 copied += r;
309 }
310 return copied;
311}
312
313/**
Mike Christie38e1a8f2008-12-02 00:32:12 -0600314 * iscsi_sw_tcp_xmit - TCP transmit
Randy Dunlapccd4a432017-12-22 14:08:27 -0800315 * @conn: iscsi connection
Alex Aizman7ba24712005-08-04 19:30:08 -0700316 **/
Mike Christie38e1a8f2008-12-02 00:32:12 -0600317static int iscsi_sw_tcp_xmit(struct iscsi_conn *conn)
Alex Aizman7ba24712005-08-04 19:30:08 -0700318{
Mike Christie5bb0b552006-04-06 21:26:46 -0500319 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600320 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
321 struct iscsi_segment *segment = &tcp_sw_conn->out.segment;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600322 unsigned int consumed = 0;
323 int rc = 0;
Alex Aizman7ba24712005-08-04 19:30:08 -0700324
Olaf Kircha8ac6312007-12-13 12:43:35 -0600325 while (1) {
Mike Christie6df19a72008-12-02 00:32:16 -0600326 rc = iscsi_sw_tcp_xmit_segment(tcp_conn, segment);
Mike Christie32382492009-06-15 22:11:09 -0500327 /*
328 * We may not have been able to send data because the conn
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300329 * is getting stopped. libiscsi will know so propagate err
Mike Christie32382492009-06-15 22:11:09 -0500330 * for it to do the right thing.
331 */
332 if (rc == -EAGAIN)
333 return rc;
334 else if (rc < 0) {
Mike Christie6f481e32008-09-24 11:46:13 -0500335 rc = ISCSI_ERR_XMIT_FAILED;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600336 goto error;
Mike Christie32382492009-06-15 22:11:09 -0500337 } else if (rc == 0)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600338 break;
339
340 consumed += rc;
341
342 if (segment->total_copied >= segment->total_size) {
343 if (segment->done != NULL) {
344 rc = segment->done(tcp_conn, segment);
Mike Christie6f481e32008-09-24 11:46:13 -0500345 if (rc != 0)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600346 goto error;
347 }
348 }
349 }
350
Mike Christiec93f87c2009-03-05 14:46:00 -0600351 ISCSI_SW_TCP_DBG(conn, "xmit %d bytes\n", consumed);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600352
353 conn->txdata_octets += consumed;
354 return consumed;
355
356error:
357 /* Transmit error. We could initiate error recovery
358 * here. */
Mike Christiec93f87c2009-03-05 14:46:00 -0600359 ISCSI_SW_TCP_DBG(conn, "Error sending PDU, errno=%d\n", rc);
Mike Christie6f481e32008-09-24 11:46:13 -0500360 iscsi_conn_failure(conn, rc);
361 return -EIO;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600362}
363
364/**
365 * iscsi_tcp_xmit_qlen - return the number of bytes queued for xmit
Randy Dunlapccd4a432017-12-22 14:08:27 -0800366 * @conn: iscsi connection
Olaf Kircha8ac6312007-12-13 12:43:35 -0600367 */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600368static inline int iscsi_sw_tcp_xmit_qlen(struct iscsi_conn *conn)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600369{
370 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600371 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
372 struct iscsi_segment *segment = &tcp_sw_conn->out.segment;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600373
374 return segment->total_copied - segment->total_size;
375}
376
Mike Christie38e1a8f2008-12-02 00:32:12 -0600377static int iscsi_sw_tcp_pdu_xmit(struct iscsi_task *task)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600378{
Mike Christiee5a7efe2008-12-02 00:32:07 -0600379 struct iscsi_conn *conn = task->conn;
Vlastimil Babkaf1083042017-05-08 15:59:53 -0700380 unsigned int noreclaim_flag;
Mike Christie9e45dd72013-04-10 11:24:39 -0500381 int rc = 0;
382
Vlastimil Babkaf1083042017-05-08 15:59:53 -0700383 noreclaim_flag = memalloc_noreclaim_save();
Olaf Kircha8ac6312007-12-13 12:43:35 -0600384
Mike Christie38e1a8f2008-12-02 00:32:12 -0600385 while (iscsi_sw_tcp_xmit_qlen(conn)) {
386 rc = iscsi_sw_tcp_xmit(conn);
Mike Christie9e45dd72013-04-10 11:24:39 -0500387 if (rc == 0) {
388 rc = -EAGAIN;
389 break;
390 }
Olaf Kircha8ac6312007-12-13 12:43:35 -0600391 if (rc < 0)
Mike Christie9e45dd72013-04-10 11:24:39 -0500392 break;
393 rc = 0;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600394 }
395
Vlastimil Babkaf1083042017-05-08 15:59:53 -0700396 memalloc_noreclaim_restore(noreclaim_flag);
Mike Christie9e45dd72013-04-10 11:24:39 -0500397 return rc;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600398}
399
400/*
401 * This is called when we're done sending the header.
402 * Simply copy the data_segment to the send segment, and return.
403 */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600404static int iscsi_sw_tcp_send_hdr_done(struct iscsi_tcp_conn *tcp_conn,
405 struct iscsi_segment *segment)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600406{
Mike Christie38e1a8f2008-12-02 00:32:12 -0600407 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
408
409 tcp_sw_conn->out.segment = tcp_sw_conn->out.data_segment;
Mike Christiec93f87c2009-03-05 14:46:00 -0600410 ISCSI_SW_TCP_DBG(tcp_conn->iscsi_conn,
411 "Header done. Next segment size %u total_size %u\n",
412 tcp_sw_conn->out.segment.size,
413 tcp_sw_conn->out.segment.total_size);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600414 return 0;
415}
416
Mike Christie38e1a8f2008-12-02 00:32:12 -0600417static void iscsi_sw_tcp_send_hdr_prep(struct iscsi_conn *conn, void *hdr,
418 size_t hdrlen)
Olaf Kircha8ac6312007-12-13 12:43:35 -0600419{
420 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600421 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600422
Mike Christiec93f87c2009-03-05 14:46:00 -0600423 ISCSI_SW_TCP_DBG(conn, "%s\n", conn->hdrdgst_en ?
424 "digest enabled" : "digest disabled");
Olaf Kircha8ac6312007-12-13 12:43:35 -0600425
426 /* Clear the data segment - needs to be filled in by the
427 * caller using iscsi_tcp_send_data_prep() */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600428 memset(&tcp_sw_conn->out.data_segment, 0,
429 sizeof(struct iscsi_segment));
Olaf Kircha8ac6312007-12-13 12:43:35 -0600430
431 /* If header digest is enabled, compute the CRC and
432 * place the digest into the same buffer. We make
Mike Christie135a8ad2008-05-21 15:54:10 -0500433 * sure that both iscsi_tcp_task and mtask have
Olaf Kircha8ac6312007-12-13 12:43:35 -0600434 * sufficient room.
Mike Christie7cae5152006-01-13 18:05:47 -0600435 */
Olaf Kircha8ac6312007-12-13 12:43:35 -0600436 if (conn->hdrdgst_en) {
Herbert Xu5d6ac292016-01-24 21:19:41 +0800437 iscsi_tcp_dgst_header(tcp_sw_conn->tx_hash, hdr, hdrlen,
Olaf Kircha8ac6312007-12-13 12:43:35 -0600438 hdr + hdrlen);
439 hdrlen += ISCSI_DIGEST_SIZE;
Mike Christie3219e522006-05-30 00:37:28 -0500440 }
441
Olaf Kircha8ac6312007-12-13 12:43:35 -0600442 /* Remember header pointer for later, when we need
443 * to decide whether there's a payload to go along
444 * with the header. */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600445 tcp_sw_conn->out.hdr = hdr;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600446
Mike Christie38e1a8f2008-12-02 00:32:12 -0600447 iscsi_segment_init_linear(&tcp_sw_conn->out.segment, hdr, hdrlen,
448 iscsi_sw_tcp_send_hdr_done, NULL);
Alex Aizman7ba24712005-08-04 19:30:08 -0700449}
450
Olaf Kircha8ac6312007-12-13 12:43:35 -0600451/*
452 * Prepare the send buffer for the payload data.
453 * Padding and checksumming will all be taken care
454 * of by the iscsi_segment routines.
455 */
456static int
Mike Christie38e1a8f2008-12-02 00:32:12 -0600457iscsi_sw_tcp_send_data_prep(struct iscsi_conn *conn, struct scatterlist *sg,
458 unsigned int count, unsigned int offset,
459 unsigned int len)
Alex Aizman7ba24712005-08-04 19:30:08 -0700460{
Olaf Kircha8ac6312007-12-13 12:43:35 -0600461 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600462 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Herbert Xu5d6ac292016-01-24 21:19:41 +0800463 struct ahash_request *tx_hash = NULL;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600464 unsigned int hdr_spec_len;
Alex Aizman7ba24712005-08-04 19:30:08 -0700465
Mike Christiec93f87c2009-03-05 14:46:00 -0600466 ISCSI_SW_TCP_DBG(conn, "offset=%d, datalen=%d %s\n", offset, len,
467 conn->datadgst_en ?
468 "digest enabled" : "digest disabled");
Alex Aizman7ba24712005-08-04 19:30:08 -0700469
Olaf Kircha8ac6312007-12-13 12:43:35 -0600470 /* Make sure the datalen matches what the caller
471 said he would send. */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600472 hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600473 WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len));
Alex Aizman7ba24712005-08-04 19:30:08 -0700474
Olaf Kircha8ac6312007-12-13 12:43:35 -0600475 if (conn->datadgst_en)
Herbert Xu5d6ac292016-01-24 21:19:41 +0800476 tx_hash = tcp_sw_conn->tx_hash;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600477
Mike Christie38e1a8f2008-12-02 00:32:12 -0600478 return iscsi_segment_seek_sg(&tcp_sw_conn->out.data_segment,
479 sg, count, offset, len,
480 NULL, tx_hash);
Alex Aizman7ba24712005-08-04 19:30:08 -0700481}
482
Olaf Kircha8ac6312007-12-13 12:43:35 -0600483static void
Mike Christie38e1a8f2008-12-02 00:32:12 -0600484iscsi_sw_tcp_send_linear_data_prep(struct iscsi_conn *conn, void *data,
Olaf Kircha8ac6312007-12-13 12:43:35 -0600485 size_t len)
Alex Aizman7ba24712005-08-04 19:30:08 -0700486{
Olaf Kircha8ac6312007-12-13 12:43:35 -0600487 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600488 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Herbert Xu5d6ac292016-01-24 21:19:41 +0800489 struct ahash_request *tx_hash = NULL;
Olaf Kircha8ac6312007-12-13 12:43:35 -0600490 unsigned int hdr_spec_len;
Alex Aizman7ba24712005-08-04 19:30:08 -0700491
Mike Christiec93f87c2009-03-05 14:46:00 -0600492 ISCSI_SW_TCP_DBG(conn, "datalen=%zd %s\n", len, conn->datadgst_en ?
493 "digest enabled" : "digest disabled");
Alex Aizman7ba24712005-08-04 19:30:08 -0700494
Olaf Kircha8ac6312007-12-13 12:43:35 -0600495 /* Make sure the datalen matches what the caller
496 said he would send. */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600497 hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600498 WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len));
Alex Aizman7ba24712005-08-04 19:30:08 -0700499
Olaf Kircha8ac6312007-12-13 12:43:35 -0600500 if (conn->datadgst_en)
Herbert Xu5d6ac292016-01-24 21:19:41 +0800501 tx_hash = tcp_sw_conn->tx_hash;
Alex Aizman7ba24712005-08-04 19:30:08 -0700502
Mike Christie38e1a8f2008-12-02 00:32:12 -0600503 iscsi_segment_init_linear(&tcp_sw_conn->out.data_segment,
Olaf Kircha8ac6312007-12-13 12:43:35 -0600504 data, len, NULL, tx_hash);
Alex Aizman7ba24712005-08-04 19:30:08 -0700505}
506
Mike Christie38e1a8f2008-12-02 00:32:12 -0600507static int iscsi_sw_tcp_pdu_init(struct iscsi_task *task,
508 unsigned int offset, unsigned int count)
Mike Christiee5a7efe2008-12-02 00:32:07 -0600509{
510 struct iscsi_conn *conn = task->conn;
511 int err = 0;
512
Mike Christie38e1a8f2008-12-02 00:32:12 -0600513 iscsi_sw_tcp_send_hdr_prep(conn, task->hdr, task->hdr_len);
Mike Christiee5a7efe2008-12-02 00:32:07 -0600514
515 if (!count)
516 return 0;
517
518 if (!task->sc)
Mike Christie38e1a8f2008-12-02 00:32:12 -0600519 iscsi_sw_tcp_send_linear_data_prep(conn, task->data, count);
Mike Christiee5a7efe2008-12-02 00:32:07 -0600520 else {
Christoph Hellwigae3d56d2019-01-29 09:33:07 +0100521 struct scsi_data_buffer *sdb = &task->sc->sdb;
Mike Christiee5a7efe2008-12-02 00:32:07 -0600522
Mike Christie38e1a8f2008-12-02 00:32:12 -0600523 err = iscsi_sw_tcp_send_data_prep(conn, sdb->table.sgl,
524 sdb->table.nents, offset,
525 count);
Mike Christiee5a7efe2008-12-02 00:32:07 -0600526 }
527
528 if (err) {
Mike Christie9a6510e2009-04-21 15:32:31 -0500529 /* got invalid offset/len */
Mike Christiee5a7efe2008-12-02 00:32:07 -0600530 return -EIO;
531 }
532 return 0;
533}
534
Mike Christie2ff79d52008-12-02 00:32:14 -0600535static int iscsi_sw_tcp_pdu_alloc(struct iscsi_task *task, uint8_t opcode)
Mike Christiee5a7efe2008-12-02 00:32:07 -0600536{
537 struct iscsi_tcp_task *tcp_task = task->dd_data;
538
Mike Christie38e1a8f2008-12-02 00:32:12 -0600539 task->hdr = task->dd_data + sizeof(*tcp_task);
540 task->hdr_max = sizeof(struct iscsi_sw_tcp_hdrbuf) - ISCSI_DIGEST_SIZE;
Mike Christiee5a7efe2008-12-02 00:32:07 -0600541 return 0;
542}
543
Mike Christie7b8631b2006-01-13 18:05:50 -0600544static struct iscsi_cls_conn *
Mike Christie38e1a8f2008-12-02 00:32:12 -0600545iscsi_sw_tcp_conn_create(struct iscsi_cls_session *cls_session,
546 uint32_t conn_idx)
Alex Aizman7ba24712005-08-04 19:30:08 -0700547{
Mike Christie7b8631b2006-01-13 18:05:50 -0600548 struct iscsi_conn *conn;
549 struct iscsi_cls_conn *cls_conn;
Mike Christie5bb0b552006-04-06 21:26:46 -0500550 struct iscsi_tcp_conn *tcp_conn;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600551 struct iscsi_sw_tcp_conn *tcp_sw_conn;
Herbert Xu5d6ac292016-01-24 21:19:41 +0800552 struct crypto_ahash *tfm;
Alex Aizman7ba24712005-08-04 19:30:08 -0700553
Mike Christie38e1a8f2008-12-02 00:32:12 -0600554 cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*tcp_sw_conn),
555 conn_idx);
Mike Christie7b8631b2006-01-13 18:05:50 -0600556 if (!cls_conn)
557 return NULL;
558 conn = cls_conn->dd_data;
Mike Christie5d91e202008-05-21 15:54:01 -0500559 tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600560 tcp_sw_conn = tcp_conn->dd_data;
Alex Aizman7ba24712005-08-04 19:30:08 -0700561
Herbert Xu5d6ac292016-01-24 21:19:41 +0800562 tfm = crypto_alloc_ahash("crc32c", 0, CRYPTO_ALG_ASYNC);
563 if (IS_ERR(tfm))
Mike Christie5d91e202008-05-21 15:54:01 -0500564 goto free_conn;
Mike Christiedd8c0d92006-08-31 18:09:28 -0400565
Herbert Xu5d6ac292016-01-24 21:19:41 +0800566 tcp_sw_conn->tx_hash = ahash_request_alloc(tfm, GFP_KERNEL);
567 if (!tcp_sw_conn->tx_hash)
568 goto free_tfm;
569 ahash_request_set_callback(tcp_sw_conn->tx_hash, 0, NULL, NULL);
570
571 tcp_sw_conn->rx_hash = ahash_request_alloc(tfm, GFP_KERNEL);
572 if (!tcp_sw_conn->rx_hash)
573 goto free_tx_hash;
574 ahash_request_set_callback(tcp_sw_conn->rx_hash, 0, NULL, NULL);
575
576 tcp_conn->rx_hash = tcp_sw_conn->rx_hash;
Mike Christiedd8c0d92006-08-31 18:09:28 -0400577
Mike Christie7b8631b2006-01-13 18:05:50 -0600578 return cls_conn;
Alex Aizman7ba24712005-08-04 19:30:08 -0700579
Herbert Xu5d6ac292016-01-24 21:19:41 +0800580free_tx_hash:
581 ahash_request_free(tcp_sw_conn->tx_hash);
582free_tfm:
583 crypto_free_ahash(tfm);
Mike Christie5d91e202008-05-21 15:54:01 -0500584free_conn:
Mike Christie322d7392008-01-31 13:36:52 -0600585 iscsi_conn_printk(KERN_ERR, conn,
586 "Could not create connection due to crc32c "
587 "loading error. Make sure the crc32c "
588 "module is built as a module or into the "
589 "kernel\n");
Mike Christie38e1a8f2008-12-02 00:32:12 -0600590 iscsi_tcp_conn_teardown(cls_conn);
Mike Christie7b8631b2006-01-13 18:05:50 -0600591 return NULL;
Alex Aizman7ba24712005-08-04 19:30:08 -0700592}
593
Mike Christie38e1a8f2008-12-02 00:32:12 -0600594static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn)
Mike Christie1c834692006-07-24 15:47:26 -0500595{
Mike Christie22236962007-05-30 12:57:24 -0500596 struct iscsi_session *session = conn->session;
Mike Christie1c834692006-07-24 15:47:26 -0500597 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600598 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
599 struct socket *sock = tcp_sw_conn->sock;
Mike Christie1c834692006-07-24 15:47:26 -0500600
Mike Christie22236962007-05-30 12:57:24 -0500601 if (!sock)
Mike Christie1c834692006-07-24 15:47:26 -0500602 return;
603
Mike Christie22236962007-05-30 12:57:24 -0500604 sock_hold(sock->sk);
Avi Kaplanc484a50a2010-04-09 22:07:38 -0500605 iscsi_sw_tcp_conn_restore_callbacks(conn);
Mike Christie22236962007-05-30 12:57:24 -0500606 sock_put(sock->sk);
Mike Christie1c834692006-07-24 15:47:26 -0500607
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600608 spin_lock_bh(&session->frwd_lock);
Mike Christie38e1a8f2008-12-02 00:32:12 -0600609 tcp_sw_conn->sock = NULL;
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600610 spin_unlock_bh(&session->frwd_lock);
Mike Christie22236962007-05-30 12:57:24 -0500611 sockfd_put(sock);
Mike Christie1c834692006-07-24 15:47:26 -0500612}
613
Mike Christie38e1a8f2008-12-02 00:32:12 -0600614static void iscsi_sw_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
Alex Aizman7ba24712005-08-04 19:30:08 -0700615{
Mike Christie7b8631b2006-01-13 18:05:50 -0600616 struct iscsi_conn *conn = cls_conn->dd_data;
Mike Christie5bb0b552006-04-06 21:26:46 -0500617 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600618 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Alex Aizman7ba24712005-08-04 19:30:08 -0700619
Mike Christie38e1a8f2008-12-02 00:32:12 -0600620 iscsi_sw_tcp_release_conn(conn);
Alex Aizman7ba24712005-08-04 19:30:08 -0700621
Herbert Xu5d6ac292016-01-24 21:19:41 +0800622 ahash_request_free(tcp_sw_conn->rx_hash);
623 if (tcp_sw_conn->tx_hash) {
624 struct crypto_ahash *tfm;
625
626 tfm = crypto_ahash_reqtfm(tcp_sw_conn->tx_hash);
627 ahash_request_free(tcp_sw_conn->tx_hash);
628 crypto_free_ahash(tfm);
629 }
Alex Aizman7ba24712005-08-04 19:30:08 -0700630
Mike Christie38e1a8f2008-12-02 00:32:12 -0600631 iscsi_tcp_conn_teardown(cls_conn);
Alex Aizman7ba24712005-08-04 19:30:08 -0700632}
633
Mike Christie38e1a8f2008-12-02 00:32:12 -0600634static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
Mike Christie1c834692006-07-24 15:47:26 -0500635{
636 struct iscsi_conn *conn = cls_conn->dd_data;
Mike Christie913e5bf2008-05-21 15:54:18 -0500637 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600638 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Mike Christieb64e77f2010-02-10 16:51:47 -0600639 struct socket *sock = tcp_sw_conn->sock;
Mike Christie913e5bf2008-05-21 15:54:18 -0500640
641 /* userspace may have goofed up and not bound us */
Mike Christieb64e77f2010-02-10 16:51:47 -0600642 if (!sock)
Mike Christie913e5bf2008-05-21 15:54:18 -0500643 return;
Mike Christie1c834692006-07-24 15:47:26 -0500644
Mike Christie8c38a292010-05-21 18:24:16 -0500645 sock->sk->sk_err = EIO;
646 wake_up_interruptible(sk_sleep(sock->sk));
Mike Christieb64e77f2010-02-10 16:51:47 -0600647
Mike Christie03adb5f2011-06-24 15:11:54 -0500648 /* stop xmit side */
649 iscsi_suspend_tx(conn);
650
651 /* stop recv side and release socket */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600652 iscsi_sw_tcp_release_conn(conn);
Mike Christie03adb5f2011-06-24 15:11:54 -0500653
654 iscsi_conn_stop(cls_conn, flag);
Mike Christie1c834692006-07-24 15:47:26 -0500655}
656
Alex Aizman7ba24712005-08-04 19:30:08 -0700657static int
Mike Christie38e1a8f2008-12-02 00:32:12 -0600658iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
659 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
660 int is_leading)
Alex Aizman7ba24712005-08-04 19:30:08 -0700661{
Mike Christiea79af8a2011-02-16 15:04:36 -0600662 struct iscsi_session *session = cls_session->dd_data;
Mike Christie5bb0b552006-04-06 21:26:46 -0500663 struct iscsi_conn *conn = cls_conn->dd_data;
664 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600665 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Alex Aizman7ba24712005-08-04 19:30:08 -0700666 struct sock *sk;
667 struct socket *sock;
668 int err;
669
670 /* lookup for existing socket */
Or Gerlitz264faaa2006-05-02 19:46:36 -0500671 sock = sockfd_lookup((int)transport_eph, &err);
Alex Aizman7ba24712005-08-04 19:30:08 -0700672 if (!sock) {
Mike Christie322d7392008-01-31 13:36:52 -0600673 iscsi_conn_printk(KERN_ERR, conn,
674 "sockfd_lookup failed %d\n", err);
Alex Aizman7ba24712005-08-04 19:30:08 -0700675 return -EEXIST;
676 }
677
Mike Christie5bb0b552006-04-06 21:26:46 -0500678 err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
679 if (err)
Mike Christie22236962007-05-30 12:57:24 -0500680 goto free_socket;
Alex Aizman7ba24712005-08-04 19:30:08 -0700681
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600682 spin_lock_bh(&session->frwd_lock);
Mike Christie67a61112006-05-30 00:37:20 -0500683 /* bind iSCSI connection and socket */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600684 tcp_sw_conn->sock = sock;
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600685 spin_unlock_bh(&session->frwd_lock);
Alex Aizman7ba24712005-08-04 19:30:08 -0700686
Mike Christie67a61112006-05-30 00:37:20 -0500687 /* setup Socket parameters */
688 sk = sock->sk;
Pavel Emelyanov4a17fd52012-04-19 03:39:36 +0000689 sk->sk_reuse = SK_CAN_REUSE;
Mike Christie67a61112006-05-30 00:37:20 -0500690 sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */
691 sk->sk_allocation = GFP_ATOMIC;
Mike Christie9e45dd72013-04-10 11:24:39 -0500692 sk_set_memalloc(sk);
Alex Aizman7ba24712005-08-04 19:30:08 -0700693
Mike Christie38e1a8f2008-12-02 00:32:12 -0600694 iscsi_sw_tcp_conn_set_callbacks(conn);
695 tcp_sw_conn->sendpage = tcp_sw_conn->sock->ops->sendpage;
Mike Christie67a61112006-05-30 00:37:20 -0500696 /*
697 * set receive state machine into initial state
698 */
Olaf Kirchda32dd62007-12-13 12:43:21 -0600699 iscsi_tcp_hdr_recv_prep(tcp_conn);
Alex Aizman7ba24712005-08-04 19:30:08 -0700700 return 0;
Mike Christie22236962007-05-30 12:57:24 -0500701
702free_socket:
703 sockfd_put(sock);
704 return err;
Alex Aizman7ba24712005-08-04 19:30:08 -0700705}
706
Mike Christie38e1a8f2008-12-02 00:32:12 -0600707static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn,
708 enum iscsi_param param, char *buf,
709 int buflen)
Alex Aizman7ba24712005-08-04 19:30:08 -0700710{
Mike Christie7b7232f2006-02-01 21:06:49 -0600711 struct iscsi_conn *conn = cls_conn->dd_data;
Mike Christie5bb0b552006-04-06 21:26:46 -0500712 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600713 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Alex Aizman7ba24712005-08-04 19:30:08 -0700714
Alex Aizman7ba24712005-08-04 19:30:08 -0700715 switch(param) {
Alex Aizman7ba24712005-08-04 19:30:08 -0700716 case ISCSI_PARAM_HDRDGST_EN:
Mike Christie5c75b7f2006-06-28 12:00:26 -0500717 iscsi_set_param(cls_conn, param, buf, buflen);
Alex Aizman7ba24712005-08-04 19:30:08 -0700718 break;
719 case ISCSI_PARAM_DATADGST_EN:
Mike Christie5c75b7f2006-06-28 12:00:26 -0500720 iscsi_set_param(cls_conn, param, buf, buflen);
Mike Christie38e1a8f2008-12-02 00:32:12 -0600721 tcp_sw_conn->sendpage = conn->datadgst_en ?
722 sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage;
Alex Aizman7ba24712005-08-04 19:30:08 -0700723 break;
Alex Aizman7ba24712005-08-04 19:30:08 -0700724 case ISCSI_PARAM_MAX_R2T:
Mike Christie1304be52012-01-26 21:13:10 -0600725 return iscsi_tcp_set_max_r2t(conn, buf);
Alex Aizman7ba24712005-08-04 19:30:08 -0700726 default:
Mike Christie5c75b7f2006-06-28 12:00:26 -0500727 return iscsi_set_param(cls_conn, param, buf, buflen);
Alex Aizman7ba24712005-08-04 19:30:08 -0700728 }
729
730 return 0;
731}
732
Mike Christie38e1a8f2008-12-02 00:32:12 -0600733static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
734 enum iscsi_param param, char *buf)
Mike Christie7b8631b2006-01-13 18:05:50 -0600735{
Mike Christie7b7232f2006-02-01 21:06:49 -0600736 struct iscsi_conn *conn = cls_conn->dd_data;
Mike Christiea79af8a2011-02-16 15:04:36 -0600737 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
738 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
739 struct sockaddr_in6 addr;
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100740 int rc;
Mike Christie7b8631b2006-01-13 18:05:50 -0600741
742 switch(param) {
Mike Christiefd7255f2006-04-06 21:13:36 -0500743 case ISCSI_PARAM_CONN_PORT:
Mike Christiefd7255f2006-04-06 21:13:36 -0500744 case ISCSI_PARAM_CONN_ADDRESS:
Mike Christie4bfb8ebf2014-09-29 13:55:42 -0500745 case ISCSI_PARAM_LOCAL_PORT:
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600746 spin_lock_bh(&conn->session->frwd_lock);
Mike Christiea79af8a2011-02-16 15:04:36 -0600747 if (!tcp_sw_conn || !tcp_sw_conn->sock) {
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600748 spin_unlock_bh(&conn->session->frwd_lock);
Mike Christiea79af8a2011-02-16 15:04:36 -0600749 return -ENOTCONN;
750 }
Mike Christie4bfb8ebf2014-09-29 13:55:42 -0500751 if (param == ISCSI_PARAM_LOCAL_PORT)
752 rc = kernel_getsockname(tcp_sw_conn->sock,
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100753 (struct sockaddr *)&addr);
Mike Christie4bfb8ebf2014-09-29 13:55:42 -0500754 else
755 rc = kernel_getpeername(tcp_sw_conn->sock,
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100756 (struct sockaddr *)&addr);
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600757 spin_unlock_bh(&conn->session->frwd_lock);
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100758 if (rc < 0)
Mike Christiea79af8a2011-02-16 15:04:36 -0600759 return rc;
760
761 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
762 &addr, param, buf);
Mike Christiefd7255f2006-04-06 21:13:36 -0500763 default:
Mike Christie5c75b7f2006-06-28 12:00:26 -0500764 return iscsi_conn_get_param(cls_conn, param, buf);
Mike Christiefd7255f2006-04-06 21:13:36 -0500765 }
766
Mike Christiea79af8a2011-02-16 15:04:36 -0600767 return 0;
768}
769
770static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
771 enum iscsi_host_param param, char *buf)
772{
773 struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost);
774 struct iscsi_session *session = tcp_sw_host->session;
775 struct iscsi_conn *conn;
776 struct iscsi_tcp_conn *tcp_conn;
777 struct iscsi_sw_tcp_conn *tcp_sw_conn;
778 struct sockaddr_in6 addr;
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100779 int rc;
Mike Christiea79af8a2011-02-16 15:04:36 -0600780
781 switch (param) {
782 case ISCSI_HOST_PARAM_IPADDRESS:
Mike Christieeee2b5c2014-02-07 00:41:42 -0600783 if (!session)
784 return -ENOTCONN;
785
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600786 spin_lock_bh(&session->frwd_lock);
Mike Christiea79af8a2011-02-16 15:04:36 -0600787 conn = session->leadconn;
788 if (!conn) {
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600789 spin_unlock_bh(&session->frwd_lock);
Mike Christiea79af8a2011-02-16 15:04:36 -0600790 return -ENOTCONN;
791 }
792 tcp_conn = conn->dd_data;
793
794 tcp_sw_conn = tcp_conn->dd_data;
795 if (!tcp_sw_conn->sock) {
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600796 spin_unlock_bh(&session->frwd_lock);
Mike Christiea79af8a2011-02-16 15:04:36 -0600797 return -ENOTCONN;
798 }
799
800 rc = kernel_getsockname(tcp_sw_conn->sock,
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100801 (struct sockaddr *)&addr);
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600802 spin_unlock_bh(&session->frwd_lock);
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100803 if (rc < 0)
Mike Christiea79af8a2011-02-16 15:04:36 -0600804 return rc;
805
806 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
Nathan Chancellor20054592018-10-03 18:06:15 -0700807 &addr,
808 (enum iscsi_param)param, buf);
Mike Christiea79af8a2011-02-16 15:04:36 -0600809 default:
810 return iscsi_host_get_param(shost, param, buf);
811 }
812
813 return 0;
Mike Christiefd7255f2006-04-06 21:13:36 -0500814}
815
Alex Aizman7ba24712005-08-04 19:30:08 -0700816static void
Mike Christie38e1a8f2008-12-02 00:32:12 -0600817iscsi_sw_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
818 struct iscsi_stats *stats)
Alex Aizman7ba24712005-08-04 19:30:08 -0700819{
Mike Christie7b7232f2006-02-01 21:06:49 -0600820 struct iscsi_conn *conn = cls_conn->dd_data;
Mike Christie5bb0b552006-04-06 21:26:46 -0500821 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600822 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
Alex Aizman7ba24712005-08-04 19:30:08 -0700823
Alex Aizman7ba24712005-08-04 19:30:08 -0700824 stats->custom_length = 3;
825 strcpy(stats->custom[0].desc, "tx_sendpage_failures");
Mike Christie38e1a8f2008-12-02 00:32:12 -0600826 stats->custom[0].value = tcp_sw_conn->sendpage_failures_cnt;
Alex Aizman7ba24712005-08-04 19:30:08 -0700827 strcpy(stats->custom[1].desc, "rx_discontiguous_hdr");
Mike Christie38e1a8f2008-12-02 00:32:12 -0600828 stats->custom[1].value = tcp_sw_conn->discontiguous_hdr_cnt;
Alex Aizman7ba24712005-08-04 19:30:08 -0700829 strcpy(stats->custom[2].desc, "eh_abort_cnt");
830 stats->custom[2].value = conn->eh_abort_cnt;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600831
832 iscsi_tcp_conn_get_stats(cls_conn, stats);
Alex Aizman7ba24712005-08-04 19:30:08 -0700833}
834
Mike Christie5bb0b552006-04-06 21:26:46 -0500835static struct iscsi_cls_session *
Mike Christie38e1a8f2008-12-02 00:32:12 -0600836iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
Mike Christie5e7facb2009-03-05 14:46:06 -0600837 uint16_t qdepth, uint32_t initial_cmdsn)
Alex Aizman7ba24712005-08-04 19:30:08 -0700838{
Mike Christie5bb0b552006-04-06 21:26:46 -0500839 struct iscsi_cls_session *cls_session;
840 struct iscsi_session *session;
Mike Christiea79af8a2011-02-16 15:04:36 -0600841 struct iscsi_sw_tcp_host *tcp_sw_host;
Mike Christie06520ede2008-05-21 15:54:15 -0500842 struct Scsi_Host *shost;
Alex Aizman7ba24712005-08-04 19:30:08 -0700843
Mike Christie06520ede2008-05-21 15:54:15 -0500844 if (ep) {
845 printk(KERN_ERR "iscsi_tcp: invalid ep %p.\n", ep);
Mike Christie5bb0b552006-04-06 21:26:46 -0500846 return NULL;
Mike Christie75613522008-05-21 15:53:59 -0500847 }
Alex Aizman7ba24712005-08-04 19:30:08 -0700848
Mike Christiea79af8a2011-02-16 15:04:36 -0600849 shost = iscsi_host_alloc(&iscsi_sw_tcp_sht,
850 sizeof(struct iscsi_sw_tcp_host), 1);
Mike Christie75613522008-05-21 15:53:59 -0500851 if (!shost)
852 return NULL;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600853 shost->transportt = iscsi_sw_tcp_scsi_transport;
Mike Christie4d108352009-03-05 14:46:04 -0600854 shost->cmd_per_lun = qdepth;
Mike Christie75613522008-05-21 15:53:59 -0500855 shost->max_lun = iscsi_max_lun;
856 shost->max_id = 0;
857 shost->max_channel = 0;
Boaz Harrosh30e9ba92008-05-26 11:31:19 +0300858 shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
Mike Christie75613522008-05-21 15:53:59 -0500859
Mike Christiea4804cd2008-05-21 15:54:00 -0500860 if (iscsi_host_add(shost, NULL))
Mike Christie75613522008-05-21 15:53:59 -0500861 goto free_host;
Mike Christie75613522008-05-21 15:53:59 -0500862
Mike Christie38e1a8f2008-12-02 00:32:12 -0600863 cls_session = iscsi_session_setup(&iscsi_sw_tcp_transport, shost,
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +0530864 cmds_max, 0,
Mike Christie38e1a8f2008-12-02 00:32:12 -0600865 sizeof(struct iscsi_tcp_task) +
866 sizeof(struct iscsi_sw_tcp_hdrbuf),
Mike Christie79706342008-05-21 15:54:12 -0500867 initial_cmdsn, 0);
Mike Christie75613522008-05-21 15:53:59 -0500868 if (!cls_session)
869 goto remove_host;
870 session = cls_session->dd_data;
Mike Christiea79af8a2011-02-16 15:04:36 -0600871 tcp_sw_host = iscsi_host_priv(shost);
872 tcp_sw_host->session = session;
Mike Christie75613522008-05-21 15:53:59 -0500873
Mike Christiefbc514b2008-05-21 15:54:07 -0500874 shost->can_queue = session->scsi_cmds_max;
Mike Christie38e1a8f2008-12-02 00:32:12 -0600875 if (iscsi_tcp_r2tpool_alloc(session))
Mike Christie75613522008-05-21 15:53:59 -0500876 goto remove_session;
Mike Christie5bb0b552006-04-06 21:26:46 -0500877 return cls_session;
878
Mike Christie75613522008-05-21 15:53:59 -0500879remove_session:
Mike Christie5bb0b552006-04-06 21:26:46 -0500880 iscsi_session_teardown(cls_session);
Mike Christie75613522008-05-21 15:53:59 -0500881remove_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500882 iscsi_host_remove(shost);
Mike Christie75613522008-05-21 15:53:59 -0500883free_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500884 iscsi_host_free(shost);
Mike Christie5bb0b552006-04-06 21:26:46 -0500885 return NULL;
Alex Aizman7ba24712005-08-04 19:30:08 -0700886}
887
Mike Christie38e1a8f2008-12-02 00:32:12 -0600888static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
Mike Christie5bb0b552006-04-06 21:26:46 -0500889{
Mike Christie75613522008-05-21 15:53:59 -0500890 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
891
Mike Christie38e1a8f2008-12-02 00:32:12 -0600892 iscsi_tcp_r2tpool_free(cls_session->dd_data);
Mike Christiee5bd7b542008-09-24 11:46:10 -0500893 iscsi_session_teardown(cls_session);
Mike Christie75613522008-05-21 15:53:59 -0500894
Mike Christiea4804cd2008-05-21 15:54:00 -0500895 iscsi_host_remove(shost);
896 iscsi_host_free(shost);
Mike Christie5bb0b552006-04-06 21:26:46 -0500897}
898
Al Viro587a1f12011-07-23 23:11:19 -0400899static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500900{
901 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500902 case ISCSI_HOST_PARAM:
903 switch (param) {
904 case ISCSI_HOST_PARAM_NETDEV_NAME:
905 case ISCSI_HOST_PARAM_HWADDRESS:
906 case ISCSI_HOST_PARAM_IPADDRESS:
907 case ISCSI_HOST_PARAM_INITIATOR_NAME:
908 return S_IRUGO;
909 default:
910 return 0;
911 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500912 case ISCSI_PARAM:
913 switch (param) {
914 case ISCSI_PARAM_MAX_RECV_DLENGTH:
915 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
916 case ISCSI_PARAM_HDRDGST_EN:
917 case ISCSI_PARAM_DATADGST_EN:
918 case ISCSI_PARAM_CONN_ADDRESS:
919 case ISCSI_PARAM_CONN_PORT:
Mike Christie4bfb8ebf2014-09-29 13:55:42 -0500920 case ISCSI_PARAM_LOCAL_PORT:
Mike Christie3128c6c2011-07-25 13:48:42 -0500921 case ISCSI_PARAM_EXP_STATSN:
922 case ISCSI_PARAM_PERSISTENT_ADDRESS:
923 case ISCSI_PARAM_PERSISTENT_PORT:
924 case ISCSI_PARAM_PING_TMO:
925 case ISCSI_PARAM_RECV_TMO:
Mike Christie1d063c12011-07-25 13:48:43 -0500926 case ISCSI_PARAM_INITIAL_R2T_EN:
927 case ISCSI_PARAM_MAX_R2T:
928 case ISCSI_PARAM_IMM_DATA_EN:
929 case ISCSI_PARAM_FIRST_BURST:
930 case ISCSI_PARAM_MAX_BURST:
931 case ISCSI_PARAM_PDU_INORDER_EN:
932 case ISCSI_PARAM_DATASEQ_INORDER_EN:
933 case ISCSI_PARAM_ERL:
934 case ISCSI_PARAM_TARGET_NAME:
935 case ISCSI_PARAM_TPGT:
936 case ISCSI_PARAM_USERNAME:
937 case ISCSI_PARAM_PASSWORD:
938 case ISCSI_PARAM_USERNAME_IN:
939 case ISCSI_PARAM_PASSWORD_IN:
940 case ISCSI_PARAM_FAST_ABORT:
941 case ISCSI_PARAM_ABORT_TMO:
942 case ISCSI_PARAM_LU_RESET_TMO:
943 case ISCSI_PARAM_TGT_RESET_TMO:
944 case ISCSI_PARAM_IFACE_NAME:
945 case ISCSI_PARAM_INITIATOR_NAME:
Mike Christie3128c6c2011-07-25 13:48:42 -0500946 return S_IRUGO;
947 default:
948 return 0;
949 }
950 }
951
952 return 0;
953}
954
Mike Christie38e1a8f2008-12-02 00:32:12 -0600955static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
Mike Christied1d81c02007-05-30 12:57:21 -0500956{
Jianchao Wang89d0c802018-03-07 20:29:03 +0800957 struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(sdev->host);
958 struct iscsi_session *session = tcp_sw_host->session;
959 struct iscsi_conn *conn = session->leadconn;
960
961 if (conn->datadgst_en)
962 sdev->request_queue->backing_dev_info->capabilities
963 |= BDI_CAP_STABLE_WRITES;
Mike Christied1d81c02007-05-30 12:57:21 -0500964 blk_queue_dma_alignment(sdev->request_queue, 0);
965 return 0;
966}
967
Mike Christie38e1a8f2008-12-02 00:32:12 -0600968static struct scsi_host_template iscsi_sw_tcp_sht = {
Mike Christie79743922007-07-26 12:46:46 -0500969 .module = THIS_MODULE,
Mike Christief4246b32006-07-24 15:47:54 -0500970 .name = "iSCSI Initiator over TCP/IP",
Mike Christie5bb0b552006-04-06 21:26:46 -0500971 .queuecommand = iscsi_queuecommand,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100972 .change_queue_depth = scsi_change_queue_depth,
Mike Christie15482712007-05-30 12:57:19 -0500973 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1,
Mike Christie66bbe0c2007-12-13 12:43:39 -0600974 .sg_tablesize = 4096,
Mike Christie8231f0e2007-02-28 17:32:20 -0600975 .max_sectors = 0xFFFF,
Mike Christie5bb0b552006-04-06 21:26:46 -0500976 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100977 .eh_timed_out = iscsi_eh_cmd_timed_out,
Mike Christie5bb0b552006-04-06 21:26:46 -0500978 .eh_abort_handler = iscsi_eh_abort,
Mike Christie843c0a82007-12-13 12:43:20 -0600979 .eh_device_reset_handler= iscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +0530980 .eh_target_reset_handler = iscsi_eh_recover_target,
Christoph Hellwig4af14d12018-12-13 16:17:09 +0100981 .dma_boundary = PAGE_SIZE - 1,
Mike Christie38e1a8f2008-12-02 00:32:12 -0600982 .slave_configure = iscsi_sw_tcp_slave_configure,
Mike Christie6b5d6c42009-04-21 15:32:32 -0500983 .target_alloc = iscsi_target_alloc,
Mike Christie5bb0b552006-04-06 21:26:46 -0500984 .proc_name = "iscsi_tcp",
985 .this_id = -1,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100986 .track_queue_depth = 1,
Mike Christie5bb0b552006-04-06 21:26:46 -0500987};
988
Mike Christie38e1a8f2008-12-02 00:32:12 -0600989static struct iscsi_transport iscsi_sw_tcp_transport = {
Alex Aizman7ba24712005-08-04 19:30:08 -0700990 .owner = THIS_MODULE,
991 .name = "tcp",
992 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
993 | CAP_DATADGST,
Mike Christie5bb0b552006-04-06 21:26:46 -0500994 /* session management */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600995 .create_session = iscsi_sw_tcp_session_create,
996 .destroy_session = iscsi_sw_tcp_session_destroy,
Mike Christie5bb0b552006-04-06 21:26:46 -0500997 /* connection management */
Mike Christie38e1a8f2008-12-02 00:32:12 -0600998 .create_conn = iscsi_sw_tcp_conn_create,
999 .bind_conn = iscsi_sw_tcp_conn_bind,
1000 .destroy_conn = iscsi_sw_tcp_conn_destroy,
Mike Christie3128c6c2011-07-25 13:48:42 -05001001 .attr_is_visible = iscsi_sw_tcp_attr_is_visible,
Mike Christie38e1a8f2008-12-02 00:32:12 -06001002 .set_param = iscsi_sw_tcp_conn_set_param,
1003 .get_conn_param = iscsi_sw_tcp_conn_get_param,
Mike Christie7b8631b2006-01-13 18:05:50 -06001004 .get_session_param = iscsi_session_get_param,
Alex Aizman7ba24712005-08-04 19:30:08 -07001005 .start_conn = iscsi_conn_start,
Mike Christie38e1a8f2008-12-02 00:32:12 -06001006 .stop_conn = iscsi_sw_tcp_conn_stop,
Mike Christie0801c242007-05-30 12:57:12 -05001007 /* iscsi host params */
Mike Christiea79af8a2011-02-16 15:04:36 -06001008 .get_host_param = iscsi_sw_tcp_host_get_param,
Mike Christie0801c242007-05-30 12:57:12 -05001009 .set_host_param = iscsi_host_set_param,
Mike Christie5bb0b552006-04-06 21:26:46 -05001010 /* IO */
Alex Aizman7ba24712005-08-04 19:30:08 -07001011 .send_pdu = iscsi_conn_send_pdu,
Mike Christie38e1a8f2008-12-02 00:32:12 -06001012 .get_stats = iscsi_sw_tcp_conn_get_stats,
Mike Christiee5a7efe2008-12-02 00:32:07 -06001013 /* iscsi task/cmd helpers */
Mike Christiefbc514b2008-05-21 15:54:07 -05001014 .init_task = iscsi_tcp_task_init,
1015 .xmit_task = iscsi_tcp_task_xmit,
1016 .cleanup_task = iscsi_tcp_cleanup_task,
Mike Christiee5a7efe2008-12-02 00:32:07 -06001017 /* low level pdu helpers */
Mike Christie38e1a8f2008-12-02 00:32:12 -06001018 .xmit_pdu = iscsi_sw_tcp_pdu_xmit,
1019 .init_pdu = iscsi_sw_tcp_pdu_init,
1020 .alloc_pdu = iscsi_sw_tcp_pdu_alloc,
Mike Christie5bb0b552006-04-06 21:26:46 -05001021 /* recovery */
Mike Christie30a6c652006-04-06 21:13:39 -05001022 .session_recovery_timedout = iscsi_session_recovery_timedout,
Alex Aizman7ba24712005-08-04 19:30:08 -07001023};
1024
Mike Christie38e1a8f2008-12-02 00:32:12 -06001025static int __init iscsi_sw_tcp_init(void)
Alex Aizman7ba24712005-08-04 19:30:08 -07001026{
Alex Aizman7ba24712005-08-04 19:30:08 -07001027 if (iscsi_max_lun < 1) {
Or Gerlitzbe2df722006-05-02 19:46:43 -05001028 printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n",
1029 iscsi_max_lun);
Alex Aizman7ba24712005-08-04 19:30:08 -07001030 return -EINVAL;
1031 }
Alex Aizman7ba24712005-08-04 19:30:08 -07001032
Mike Christie38e1a8f2008-12-02 00:32:12 -06001033 iscsi_sw_tcp_scsi_transport = iscsi_register_transport(
1034 &iscsi_sw_tcp_transport);
1035 if (!iscsi_sw_tcp_scsi_transport)
Mike Christieffbfe922006-05-18 20:31:36 -05001036 return -ENODEV;
Alex Aizman7ba24712005-08-04 19:30:08 -07001037
Mike Christie7b8631b2006-01-13 18:05:50 -06001038 return 0;
Alex Aizman7ba24712005-08-04 19:30:08 -07001039}
1040
Mike Christie38e1a8f2008-12-02 00:32:12 -06001041static void __exit iscsi_sw_tcp_exit(void)
Alex Aizman7ba24712005-08-04 19:30:08 -07001042{
Mike Christie38e1a8f2008-12-02 00:32:12 -06001043 iscsi_unregister_transport(&iscsi_sw_tcp_transport);
Alex Aizman7ba24712005-08-04 19:30:08 -07001044}
1045
Mike Christie38e1a8f2008-12-02 00:32:12 -06001046module_init(iscsi_sw_tcp_init);
1047module_exit(iscsi_sw_tcp_exit);