Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * iSCSI Initiator over TCP/IP Data-Path |
| 3 | * |
| 4 | * Copyright (C) 2004 Dmitry Yusupov |
| 5 | * Copyright (C) 2004 Alex Aizman |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 6 | * Copyright (C) 2005 - 2006 Mike Christie |
| 7 | * Copyright (C) 2006 Red Hat, Inc. All rights reserved. |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 8 | * maintained by open-iscsi@googlegroups.com |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published |
| 12 | * by the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * See the file COPYING included with this distribution for more details. |
| 21 | * |
| 22 | * Credits: |
| 23 | * Christoph Hellwig |
| 24 | * FUJITA Tomonori |
| 25 | * Arne Redlich |
| 26 | * Zhenyu Wang |
| 27 | */ |
| 28 | |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 29 | #include <crypto/hash.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 31 | #include <linux/inet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Vlastimil Babka | f108304 | 2017-05-08 15:59:53 -0700 | [diff] [blame] | 33 | #include <linux/sched/mm.h> |
Mike Christie | 4e7aba7 | 2007-05-30 12:57:23 -0500 | [diff] [blame] | 34 | #include <linux/file.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 35 | #include <linux/blkdev.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/kfifo.h> |
| 38 | #include <linux/scatterlist.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 39 | #include <linux/module.h> |
Jianchao Wang | 89d0c80 | 2018-03-07 20:29:03 +0800 | [diff] [blame] | 40 | #include <linux/backing-dev.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 41 | #include <net/tcp.h> |
| 42 | #include <scsi/scsi_cmnd.h> |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 43 | #include <scsi/scsi_device.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 44 | #include <scsi/scsi_host.h> |
| 45 | #include <scsi/scsi.h> |
| 46 | #include <scsi/scsi_transport_iscsi.h> |
Fred Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 47 | #include <trace/events/iscsi.h> |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 48 | |
| 49 | #include "iscsi_tcp.h" |
| 50 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 51 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, " |
| 52 | "Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 53 | "Alex Aizman <itn780@yahoo.com>"); |
| 54 | MODULE_DESCRIPTION("iSCSI/TCP data-path"); |
| 55 | MODULE_LICENSE("GPL"); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 56 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 57 | static struct scsi_transport_template *iscsi_sw_tcp_scsi_transport; |
| 58 | static struct scsi_host_template iscsi_sw_tcp_sht; |
| 59 | static struct iscsi_transport iscsi_sw_tcp_transport; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 60 | |
Rob Evers | c0e4eaa | 2012-08-15 18:39:34 -0400 | [diff] [blame] | 61 | static unsigned int iscsi_max_lun = ~0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 62 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); |
| 63 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 64 | static int iscsi_sw_tcp_dbg; |
| 65 | module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int, |
| 66 | S_IRUGO | S_IWUSR); |
| 67 | MODULE_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 Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 76 | iscsi_dbg_trace(trace_iscsi_dbg_sw_tcp, \ |
| 77 | &(_conn)->cls_conn->dev, \ |
| 78 | "%s " dbg_fmt, __func__, ##arg);\ |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 79 | } while (0); |
| 80 | |
| 81 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 82 | /** |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 83 | * 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 Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 88 | */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 89 | static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, |
| 90 | unsigned int offset, size_t len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 91 | { |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 92 | struct iscsi_conn *conn = rd_desc->arg.data; |
| 93 | unsigned int consumed, total_consumed = 0; |
| 94 | int status; |
| 95 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 96 | ISCSI_SW_TCP_DBG(conn, "in %d bytes\n", skb->len - offset); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 97 | |
| 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 Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 105 | ISCSI_SW_TCP_DBG(conn, "read %d bytes status %d\n", |
| 106 | skb->len - offset, status); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 107 | return total_consumed; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 108 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 109 | |
Hannes Reinecke | 523eeac | 2009-08-20 15:10:57 -0500 | [diff] [blame] | 110 | /** |
| 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 Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 117 | * |
| 118 | * Must be called with sk_callback_lock. |
Hannes Reinecke | 523eeac | 2009-08-20 15:10:57 -0500 | [diff] [blame] | 119 | */ |
| 120 | static inline int iscsi_sw_sk_state_check(struct sock *sk) |
| 121 | { |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 122 | struct iscsi_conn *conn = sk->sk_user_data; |
Hannes Reinecke | 523eeac | 2009-08-20 15:10:57 -0500 | [diff] [blame] | 123 | |
Mike Christie | d1af8a3 | 2009-08-20 15:11:02 -0500 | [diff] [blame] | 124 | if ((sk->sk_state == TCP_CLOSE_WAIT || sk->sk_state == TCP_CLOSE) && |
Chris Leech | c712495 | 2013-09-26 09:09:44 -0700 | [diff] [blame] | 125 | (conn->session->state != ISCSI_STATE_LOGGING_OUT) && |
Mike Christie | d1af8a3 | 2009-08-20 15:11:02 -0500 | [diff] [blame] | 126 | !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 Reinecke | 523eeac | 2009-08-20 15:10:57 -0500 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 134 | static void iscsi_sw_tcp_data_ready(struct sock *sk) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 135 | { |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 136 | struct iscsi_conn *conn; |
| 137 | struct iscsi_tcp_conn *tcp_conn; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 138 | read_descriptor_t rd_desc; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 139 | |
Eric Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 140 | read_lock_bh(&sk->sk_callback_lock); |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 141 | conn = sk->sk_user_data; |
| 142 | if (!conn) { |
Eric Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 143 | read_unlock_bh(&sk->sk_callback_lock); |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | tcp_conn = conn->dd_data; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 147 | |
| 148 | /* |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 149 | * 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 Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 153 | */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 154 | rd_desc.arg.data = conn; |
| 155 | rd_desc.count = 1; |
| 156 | tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 157 | |
Mike Christie | d1af8a3 | 2009-08-20 15:11:02 -0500 | [diff] [blame] | 158 | iscsi_sw_sk_state_check(sk); |
Hannes Reinecke | 523eeac | 2009-08-20 15:10:57 -0500 | [diff] [blame] | 159 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 160 | /* If we had to (atomically) map a highmem page, |
| 161 | * unmap it now. */ |
| 162 | iscsi_tcp_segment_unmap(&tcp_conn->in.segment); |
Eric Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 163 | read_unlock_bh(&sk->sk_callback_lock); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 164 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 165 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 166 | static void iscsi_sw_tcp_state_change(struct sock *sk) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 167 | { |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 168 | struct iscsi_tcp_conn *tcp_conn; |
| 169 | struct iscsi_sw_tcp_conn *tcp_sw_conn; |
| 170 | struct iscsi_conn *conn; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 171 | void (*old_state_change)(struct sock *); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 172 | |
Eric Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 173 | read_lock_bh(&sk->sk_callback_lock); |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 174 | conn = sk->sk_user_data; |
| 175 | if (!conn) { |
Eric Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 176 | read_unlock_bh(&sk->sk_callback_lock); |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 177 | return; |
| 178 | } |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 179 | |
Mike Christie | d1af8a3 | 2009-08-20 15:11:02 -0500 | [diff] [blame] | 180 | iscsi_sw_sk_state_check(sk); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 181 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 182 | 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 Dumazet | 7cb001d | 2016-05-17 17:44:06 -0700 | [diff] [blame] | 186 | read_unlock_bh(&sk->sk_callback_lock); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 187 | |
| 188 | old_state_change(sk); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 189 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 190 | |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 191 | /** |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 192 | * iscsi_write_space - Called when more output buffer space is available |
| 193 | * @sk: socket space is available for |
| 194 | **/ |
| 195 | static void iscsi_sw_tcp_write_space(struct sock *sk) |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 196 | { |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 197 | 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 Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 201 | |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 202 | 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 Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 216 | ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n"); |
Mike Christie | 32ae763 | 2009-03-05 14:46:03 -0600 | [diff] [blame] | 217 | iscsi_conn_queue_work(conn); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 218 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 219 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 220 | static 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 Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 225 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 226 | /* 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 Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 237 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 238 | static void |
Avi Kaplan | c484a50a | 2010-04-09 22:07:38 -0500 | [diff] [blame] | 239 | iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn) |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 240 | { |
Avi Kaplan | c484a50a | 2010-04-09 22:07:38 -0500 | [diff] [blame] | 241 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
| 242 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 243 | struct sock *sk = tcp_sw_conn->sock->sk; |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 244 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 245 | /* 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 Herbert | 28448b8 | 2014-05-23 08:47:19 -0700 | [diff] [blame] | 251 | sk->sk_no_check_tx = 0; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 252 | write_unlock_bh(&sk->sk_callback_lock); |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 256 | * iscsi_sw_tcp_xmit_segment - transmit segment |
Mike Christie | 6df19a7 | 2008-12-02 00:32:16 -0600 | [diff] [blame] | 257 | * @tcp_conn: the iSCSI TCP connection |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 258 | * @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 Christie | 6df19a7 | 2008-12-02 00:32:16 -0600 | [diff] [blame] | 268 | static int iscsi_sw_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 269 | struct iscsi_segment *segment) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 270 | { |
Mike Christie | 6df19a7 | 2008-12-02 00:32:16 -0600 | [diff] [blame] | 271 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 272 | struct socket *sk = tcp_sw_conn->sock; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 273 | unsigned int copied = 0; |
| 274 | int r = 0; |
| 275 | |
Mike Christie | 6df19a7 | 2008-12-02 00:32:16 -0600 | [diff] [blame] | 276 | while (!iscsi_tcp_segment_done(tcp_conn, segment, 0, r)) { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 277 | 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 Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 292 | r = tcp_sw_conn->sendpage(sk, sg_page(sg), offset, |
| 293 | copy, flags); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 294 | } 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 Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 306 | return r; |
| 307 | } |
| 308 | copied += r; |
| 309 | } |
| 310 | return copied; |
| 311 | } |
| 312 | |
| 313 | /** |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 314 | * iscsi_sw_tcp_xmit - TCP transmit |
Randy Dunlap | ccd4a43 | 2017-12-22 14:08:27 -0800 | [diff] [blame] | 315 | * @conn: iscsi connection |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 316 | **/ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 317 | static int iscsi_sw_tcp_xmit(struct iscsi_conn *conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 318 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 319 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 320 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
| 321 | struct iscsi_segment *segment = &tcp_sw_conn->out.segment; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 322 | unsigned int consumed = 0; |
| 323 | int rc = 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 324 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 325 | while (1) { |
Mike Christie | 6df19a7 | 2008-12-02 00:32:16 -0600 | [diff] [blame] | 326 | rc = iscsi_sw_tcp_xmit_segment(tcp_conn, segment); |
Mike Christie | 3238249 | 2009-06-15 22:11:09 -0500 | [diff] [blame] | 327 | /* |
| 328 | * We may not have been able to send data because the conn |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 329 | * is getting stopped. libiscsi will know so propagate err |
Mike Christie | 3238249 | 2009-06-15 22:11:09 -0500 | [diff] [blame] | 330 | * for it to do the right thing. |
| 331 | */ |
| 332 | if (rc == -EAGAIN) |
| 333 | return rc; |
| 334 | else if (rc < 0) { |
Mike Christie | 6f481e3 | 2008-09-24 11:46:13 -0500 | [diff] [blame] | 335 | rc = ISCSI_ERR_XMIT_FAILED; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 336 | goto error; |
Mike Christie | 3238249 | 2009-06-15 22:11:09 -0500 | [diff] [blame] | 337 | } else if (rc == 0) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 338 | 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 Christie | 6f481e3 | 2008-09-24 11:46:13 -0500 | [diff] [blame] | 345 | if (rc != 0) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 346 | goto error; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 351 | ISCSI_SW_TCP_DBG(conn, "xmit %d bytes\n", consumed); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 352 | |
| 353 | conn->txdata_octets += consumed; |
| 354 | return consumed; |
| 355 | |
| 356 | error: |
| 357 | /* Transmit error. We could initiate error recovery |
| 358 | * here. */ |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 359 | ISCSI_SW_TCP_DBG(conn, "Error sending PDU, errno=%d\n", rc); |
Mike Christie | 6f481e3 | 2008-09-24 11:46:13 -0500 | [diff] [blame] | 360 | iscsi_conn_failure(conn, rc); |
| 361 | return -EIO; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
| 365 | * iscsi_tcp_xmit_qlen - return the number of bytes queued for xmit |
Randy Dunlap | ccd4a43 | 2017-12-22 14:08:27 -0800 | [diff] [blame] | 366 | * @conn: iscsi connection |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 367 | */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 368 | static inline int iscsi_sw_tcp_xmit_qlen(struct iscsi_conn *conn) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 369 | { |
| 370 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 371 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
| 372 | struct iscsi_segment *segment = &tcp_sw_conn->out.segment; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 373 | |
| 374 | return segment->total_copied - segment->total_size; |
| 375 | } |
| 376 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 377 | static int iscsi_sw_tcp_pdu_xmit(struct iscsi_task *task) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 378 | { |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 379 | struct iscsi_conn *conn = task->conn; |
Vlastimil Babka | f108304 | 2017-05-08 15:59:53 -0700 | [diff] [blame] | 380 | unsigned int noreclaim_flag; |
Mike Christie | 9e45dd7 | 2013-04-10 11:24:39 -0500 | [diff] [blame] | 381 | int rc = 0; |
| 382 | |
Vlastimil Babka | f108304 | 2017-05-08 15:59:53 -0700 | [diff] [blame] | 383 | noreclaim_flag = memalloc_noreclaim_save(); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 384 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 385 | while (iscsi_sw_tcp_xmit_qlen(conn)) { |
| 386 | rc = iscsi_sw_tcp_xmit(conn); |
Mike Christie | 9e45dd7 | 2013-04-10 11:24:39 -0500 | [diff] [blame] | 387 | if (rc == 0) { |
| 388 | rc = -EAGAIN; |
| 389 | break; |
| 390 | } |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 391 | if (rc < 0) |
Mike Christie | 9e45dd7 | 2013-04-10 11:24:39 -0500 | [diff] [blame] | 392 | break; |
| 393 | rc = 0; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 394 | } |
| 395 | |
Vlastimil Babka | f108304 | 2017-05-08 15:59:53 -0700 | [diff] [blame] | 396 | memalloc_noreclaim_restore(noreclaim_flag); |
Mike Christie | 9e45dd7 | 2013-04-10 11:24:39 -0500 | [diff] [blame] | 397 | return rc; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 398 | } |
| 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 Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 404 | static int iscsi_sw_tcp_send_hdr_done(struct iscsi_tcp_conn *tcp_conn, |
| 405 | struct iscsi_segment *segment) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 406 | { |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 407 | 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 Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 410 | 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 Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 414 | return 0; |
| 415 | } |
| 416 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 417 | static void iscsi_sw_tcp_send_hdr_prep(struct iscsi_conn *conn, void *hdr, |
| 418 | size_t hdrlen) |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 419 | { |
| 420 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 421 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 422 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 423 | ISCSI_SW_TCP_DBG(conn, "%s\n", conn->hdrdgst_en ? |
| 424 | "digest enabled" : "digest disabled"); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 425 | |
| 426 | /* Clear the data segment - needs to be filled in by the |
| 427 | * caller using iscsi_tcp_send_data_prep() */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 428 | memset(&tcp_sw_conn->out.data_segment, 0, |
| 429 | sizeof(struct iscsi_segment)); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 430 | |
| 431 | /* If header digest is enabled, compute the CRC and |
| 432 | * place the digest into the same buffer. We make |
Mike Christie | 135a8ad | 2008-05-21 15:54:10 -0500 | [diff] [blame] | 433 | * sure that both iscsi_tcp_task and mtask have |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 434 | * sufficient room. |
Mike Christie | 7cae515 | 2006-01-13 18:05:47 -0600 | [diff] [blame] | 435 | */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 436 | if (conn->hdrdgst_en) { |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 437 | iscsi_tcp_dgst_header(tcp_sw_conn->tx_hash, hdr, hdrlen, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 438 | hdr + hdrlen); |
| 439 | hdrlen += ISCSI_DIGEST_SIZE; |
Mike Christie | 3219e52 | 2006-05-30 00:37:28 -0500 | [diff] [blame] | 440 | } |
| 441 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 442 | /* Remember header pointer for later, when we need |
| 443 | * to decide whether there's a payload to go along |
| 444 | * with the header. */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 445 | tcp_sw_conn->out.hdr = hdr; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 446 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 447 | iscsi_segment_init_linear(&tcp_sw_conn->out.segment, hdr, hdrlen, |
| 448 | iscsi_sw_tcp_send_hdr_done, NULL); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 451 | /* |
| 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 | */ |
| 456 | static int |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 457 | iscsi_sw_tcp_send_data_prep(struct iscsi_conn *conn, struct scatterlist *sg, |
| 458 | unsigned int count, unsigned int offset, |
| 459 | unsigned int len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 460 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 461 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 462 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 463 | struct ahash_request *tx_hash = NULL; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 464 | unsigned int hdr_spec_len; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 465 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 466 | ISCSI_SW_TCP_DBG(conn, "offset=%d, datalen=%d %s\n", offset, len, |
| 467 | conn->datadgst_en ? |
| 468 | "digest enabled" : "digest disabled"); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 469 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 470 | /* Make sure the datalen matches what the caller |
| 471 | said he would send. */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 472 | hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 473 | WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 474 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 475 | if (conn->datadgst_en) |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 476 | tx_hash = tcp_sw_conn->tx_hash; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 477 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 478 | return iscsi_segment_seek_sg(&tcp_sw_conn->out.data_segment, |
| 479 | sg, count, offset, len, |
| 480 | NULL, tx_hash); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 483 | static void |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 484 | iscsi_sw_tcp_send_linear_data_prep(struct iscsi_conn *conn, void *data, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 485 | size_t len) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 486 | { |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 487 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 488 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 489 | struct ahash_request *tx_hash = NULL; |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 490 | unsigned int hdr_spec_len; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 491 | |
Mike Christie | c93f87c | 2009-03-05 14:46:00 -0600 | [diff] [blame] | 492 | ISCSI_SW_TCP_DBG(conn, "datalen=%zd %s\n", len, conn->datadgst_en ? |
| 493 | "digest enabled" : "digest disabled"); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 494 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 495 | /* Make sure the datalen matches what the caller |
| 496 | said he would send. */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 497 | hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 498 | WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len)); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 499 | |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 500 | if (conn->datadgst_en) |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 501 | tx_hash = tcp_sw_conn->tx_hash; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 502 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 503 | iscsi_segment_init_linear(&tcp_sw_conn->out.data_segment, |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 504 | data, len, NULL, tx_hash); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 507 | static int iscsi_sw_tcp_pdu_init(struct iscsi_task *task, |
| 508 | unsigned int offset, unsigned int count) |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 509 | { |
| 510 | struct iscsi_conn *conn = task->conn; |
| 511 | int err = 0; |
| 512 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 513 | iscsi_sw_tcp_send_hdr_prep(conn, task->hdr, task->hdr_len); |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 514 | |
| 515 | if (!count) |
| 516 | return 0; |
| 517 | |
| 518 | if (!task->sc) |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 519 | iscsi_sw_tcp_send_linear_data_prep(conn, task->data, count); |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 520 | else { |
Christoph Hellwig | ae3d56d | 2019-01-29 09:33:07 +0100 | [diff] [blame^] | 521 | struct scsi_data_buffer *sdb = &task->sc->sdb; |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 522 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 523 | err = iscsi_sw_tcp_send_data_prep(conn, sdb->table.sgl, |
| 524 | sdb->table.nents, offset, |
| 525 | count); |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | if (err) { |
Mike Christie | 9a6510e | 2009-04-21 15:32:31 -0500 | [diff] [blame] | 529 | /* got invalid offset/len */ |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 530 | return -EIO; |
| 531 | } |
| 532 | return 0; |
| 533 | } |
| 534 | |
Mike Christie | 2ff79d5 | 2008-12-02 00:32:14 -0600 | [diff] [blame] | 535 | static int iscsi_sw_tcp_pdu_alloc(struct iscsi_task *task, uint8_t opcode) |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 536 | { |
| 537 | struct iscsi_tcp_task *tcp_task = task->dd_data; |
| 538 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 539 | task->hdr = task->dd_data + sizeof(*tcp_task); |
| 540 | task->hdr_max = sizeof(struct iscsi_sw_tcp_hdrbuf) - ISCSI_DIGEST_SIZE; |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 544 | static struct iscsi_cls_conn * |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 545 | iscsi_sw_tcp_conn_create(struct iscsi_cls_session *cls_session, |
| 546 | uint32_t conn_idx) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 547 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 548 | struct iscsi_conn *conn; |
| 549 | struct iscsi_cls_conn *cls_conn; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 550 | struct iscsi_tcp_conn *tcp_conn; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 551 | struct iscsi_sw_tcp_conn *tcp_sw_conn; |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 552 | struct crypto_ahash *tfm; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 553 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 554 | cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*tcp_sw_conn), |
| 555 | conn_idx); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 556 | if (!cls_conn) |
| 557 | return NULL; |
| 558 | conn = cls_conn->dd_data; |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 559 | tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 560 | tcp_sw_conn = tcp_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 561 | |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 562 | tfm = crypto_alloc_ahash("crc32c", 0, CRYPTO_ALG_ASYNC); |
| 563 | if (IS_ERR(tfm)) |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 564 | goto free_conn; |
Mike Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 565 | |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 566 | 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 Christie | dd8c0d9 | 2006-08-31 18:09:28 -0400 | [diff] [blame] | 577 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 578 | return cls_conn; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 579 | |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 580 | free_tx_hash: |
| 581 | ahash_request_free(tcp_sw_conn->tx_hash); |
| 582 | free_tfm: |
| 583 | crypto_free_ahash(tfm); |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 584 | free_conn: |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 585 | 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 Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 590 | iscsi_tcp_conn_teardown(cls_conn); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 591 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 594 | static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn) |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 595 | { |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 596 | struct iscsi_session *session = conn->session; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 597 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 598 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
| 599 | struct socket *sock = tcp_sw_conn->sock; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 600 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 601 | if (!sock) |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 602 | return; |
| 603 | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 604 | sock_hold(sock->sk); |
Avi Kaplan | c484a50a | 2010-04-09 22:07:38 -0500 | [diff] [blame] | 605 | iscsi_sw_tcp_conn_restore_callbacks(conn); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 606 | sock_put(sock->sk); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 607 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 608 | spin_lock_bh(&session->frwd_lock); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 609 | tcp_sw_conn->sock = NULL; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 610 | spin_unlock_bh(&session->frwd_lock); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 611 | sockfd_put(sock); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 612 | } |
| 613 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 614 | static void iscsi_sw_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 615 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 616 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 617 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 618 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 619 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 620 | iscsi_sw_tcp_release_conn(conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 621 | |
Herbert Xu | 5d6ac29 | 2016-01-24 21:19:41 +0800 | [diff] [blame] | 622 | 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 Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 630 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 631 | iscsi_tcp_conn_teardown(cls_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 634 | static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 635 | { |
| 636 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 913e5bf | 2008-05-21 15:54:18 -0500 | [diff] [blame] | 637 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 638 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Mike Christie | b64e77f | 2010-02-10 16:51:47 -0600 | [diff] [blame] | 639 | struct socket *sock = tcp_sw_conn->sock; |
Mike Christie | 913e5bf | 2008-05-21 15:54:18 -0500 | [diff] [blame] | 640 | |
| 641 | /* userspace may have goofed up and not bound us */ |
Mike Christie | b64e77f | 2010-02-10 16:51:47 -0600 | [diff] [blame] | 642 | if (!sock) |
Mike Christie | 913e5bf | 2008-05-21 15:54:18 -0500 | [diff] [blame] | 643 | return; |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 644 | |
Mike Christie | 8c38a29 | 2010-05-21 18:24:16 -0500 | [diff] [blame] | 645 | sock->sk->sk_err = EIO; |
| 646 | wake_up_interruptible(sk_sleep(sock->sk)); |
Mike Christie | b64e77f | 2010-02-10 16:51:47 -0600 | [diff] [blame] | 647 | |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 648 | /* stop xmit side */ |
| 649 | iscsi_suspend_tx(conn); |
| 650 | |
| 651 | /* stop recv side and release socket */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 652 | iscsi_sw_tcp_release_conn(conn); |
Mike Christie | 03adb5f | 2011-06-24 15:11:54 -0500 | [diff] [blame] | 653 | |
| 654 | iscsi_conn_stop(cls_conn, flag); |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 655 | } |
| 656 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 657 | static int |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 658 | iscsi_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 Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 661 | { |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 662 | struct iscsi_session *session = cls_session->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 663 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 664 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 665 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 666 | struct sock *sk; |
| 667 | struct socket *sock; |
| 668 | int err; |
| 669 | |
| 670 | /* lookup for existing socket */ |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 671 | sock = sockfd_lookup((int)transport_eph, &err); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 672 | if (!sock) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 673 | iscsi_conn_printk(KERN_ERR, conn, |
| 674 | "sockfd_lookup failed %d\n", err); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 675 | return -EEXIST; |
| 676 | } |
| 677 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 678 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
| 679 | if (err) |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 680 | goto free_socket; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 681 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 682 | spin_lock_bh(&session->frwd_lock); |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 683 | /* bind iSCSI connection and socket */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 684 | tcp_sw_conn->sock = sock; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 685 | spin_unlock_bh(&session->frwd_lock); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 686 | |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 687 | /* setup Socket parameters */ |
| 688 | sk = sock->sk; |
Pavel Emelyanov | 4a17fd5 | 2012-04-19 03:39:36 +0000 | [diff] [blame] | 689 | sk->sk_reuse = SK_CAN_REUSE; |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 690 | sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */ |
| 691 | sk->sk_allocation = GFP_ATOMIC; |
Mike Christie | 9e45dd7 | 2013-04-10 11:24:39 -0500 | [diff] [blame] | 692 | sk_set_memalloc(sk); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 693 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 694 | iscsi_sw_tcp_conn_set_callbacks(conn); |
| 695 | tcp_sw_conn->sendpage = tcp_sw_conn->sock->ops->sendpage; |
Mike Christie | 67a6111 | 2006-05-30 00:37:20 -0500 | [diff] [blame] | 696 | /* |
| 697 | * set receive state machine into initial state |
| 698 | */ |
Olaf Kirch | da32dd6 | 2007-12-13 12:43:21 -0600 | [diff] [blame] | 699 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 700 | return 0; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 701 | |
| 702 | free_socket: |
| 703 | sockfd_put(sock); |
| 704 | return err; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 707 | static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn, |
| 708 | enum iscsi_param param, char *buf, |
| 709 | int buflen) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 710 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 711 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 712 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 713 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 714 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 715 | switch(param) { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 716 | case ISCSI_PARAM_HDRDGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 717 | iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 718 | break; |
| 719 | case ISCSI_PARAM_DATADGST_EN: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 720 | iscsi_set_param(cls_conn, param, buf, buflen); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 721 | tcp_sw_conn->sendpage = conn->datadgst_en ? |
| 722 | sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 723 | break; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 724 | case ISCSI_PARAM_MAX_R2T: |
Mike Christie | 1304be5 | 2012-01-26 21:13:10 -0600 | [diff] [blame] | 725 | return iscsi_tcp_set_max_r2t(conn, buf); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 726 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 727 | return iscsi_set_param(cls_conn, param, buf, buflen); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 733 | static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, |
| 734 | enum iscsi_param param, char *buf) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 735 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 736 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 737 | 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 Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 740 | int rc; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 741 | |
| 742 | switch(param) { |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 743 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 744 | case ISCSI_PARAM_CONN_ADDRESS: |
Mike Christie | 4bfb8ebf | 2014-09-29 13:55:42 -0500 | [diff] [blame] | 745 | case ISCSI_PARAM_LOCAL_PORT: |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 746 | spin_lock_bh(&conn->session->frwd_lock); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 747 | if (!tcp_sw_conn || !tcp_sw_conn->sock) { |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 748 | spin_unlock_bh(&conn->session->frwd_lock); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 749 | return -ENOTCONN; |
| 750 | } |
Mike Christie | 4bfb8ebf | 2014-09-29 13:55:42 -0500 | [diff] [blame] | 751 | if (param == ISCSI_PARAM_LOCAL_PORT) |
| 752 | rc = kernel_getsockname(tcp_sw_conn->sock, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 753 | (struct sockaddr *)&addr); |
Mike Christie | 4bfb8ebf | 2014-09-29 13:55:42 -0500 | [diff] [blame] | 754 | else |
| 755 | rc = kernel_getpeername(tcp_sw_conn->sock, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 756 | (struct sockaddr *)&addr); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 757 | spin_unlock_bh(&conn->session->frwd_lock); |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 758 | if (rc < 0) |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 759 | return rc; |
| 760 | |
| 761 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 762 | &addr, param, buf); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 763 | default: |
Mike Christie | 5c75b7f | 2006-06-28 12:00:26 -0500 | [diff] [blame] | 764 | return iscsi_conn_get_param(cls_conn, param, buf); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | static 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 Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 779 | int rc; |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 780 | |
| 781 | switch (param) { |
| 782 | case ISCSI_HOST_PARAM_IPADDRESS: |
Mike Christie | eee2b5c | 2014-02-07 00:41:42 -0600 | [diff] [blame] | 783 | if (!session) |
| 784 | return -ENOTCONN; |
| 785 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 786 | spin_lock_bh(&session->frwd_lock); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 787 | conn = session->leadconn; |
| 788 | if (!conn) { |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 789 | spin_unlock_bh(&session->frwd_lock); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 790 | 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 Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 796 | spin_unlock_bh(&session->frwd_lock); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 797 | return -ENOTCONN; |
| 798 | } |
| 799 | |
| 800 | rc = kernel_getsockname(tcp_sw_conn->sock, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 801 | (struct sockaddr *)&addr); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 802 | spin_unlock_bh(&session->frwd_lock); |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 803 | if (rc < 0) |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 804 | return rc; |
| 805 | |
| 806 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
Nathan Chancellor | 2005459 | 2018-10-03 18:06:15 -0700 | [diff] [blame] | 807 | &addr, |
| 808 | (enum iscsi_param)param, buf); |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 809 | default: |
| 810 | return iscsi_host_get_param(shost, param, buf); |
| 811 | } |
| 812 | |
| 813 | return 0; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 814 | } |
| 815 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 816 | static void |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 817 | iscsi_sw_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 818 | struct iscsi_stats *stats) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 819 | { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 820 | struct iscsi_conn *conn = cls_conn->dd_data; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 821 | struct iscsi_tcp_conn *tcp_conn = conn->dd_data; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 822 | struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 823 | |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 824 | stats->custom_length = 3; |
| 825 | strcpy(stats->custom[0].desc, "tx_sendpage_failures"); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 826 | stats->custom[0].value = tcp_sw_conn->sendpage_failures_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 827 | strcpy(stats->custom[1].desc, "rx_discontiguous_hdr"); |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 828 | stats->custom[1].value = tcp_sw_conn->discontiguous_hdr_cnt; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 829 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); |
| 830 | stats->custom[2].value = conn->eh_abort_cnt; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 831 | |
| 832 | iscsi_tcp_conn_get_stats(cls_conn, stats); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 835 | static struct iscsi_cls_session * |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 836 | iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 837 | uint16_t qdepth, uint32_t initial_cmdsn) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 838 | { |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 839 | struct iscsi_cls_session *cls_session; |
| 840 | struct iscsi_session *session; |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 841 | struct iscsi_sw_tcp_host *tcp_sw_host; |
Mike Christie | 06520ede | 2008-05-21 15:54:15 -0500 | [diff] [blame] | 842 | struct Scsi_Host *shost; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 843 | |
Mike Christie | 06520ede | 2008-05-21 15:54:15 -0500 | [diff] [blame] | 844 | if (ep) { |
| 845 | printk(KERN_ERR "iscsi_tcp: invalid ep %p.\n", ep); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 846 | return NULL; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 847 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 848 | |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 849 | shost = iscsi_host_alloc(&iscsi_sw_tcp_sht, |
| 850 | sizeof(struct iscsi_sw_tcp_host), 1); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 851 | if (!shost) |
| 852 | return NULL; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 853 | shost->transportt = iscsi_sw_tcp_scsi_transport; |
Mike Christie | 4d10835 | 2009-03-05 14:46:04 -0600 | [diff] [blame] | 854 | shost->cmd_per_lun = qdepth; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 855 | shost->max_lun = iscsi_max_lun; |
| 856 | shost->max_id = 0; |
| 857 | shost->max_channel = 0; |
Boaz Harrosh | 30e9ba9 | 2008-05-26 11:31:19 +0300 | [diff] [blame] | 858 | shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 859 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 860 | if (iscsi_host_add(shost, NULL)) |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 861 | goto free_host; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 862 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 863 | cls_session = iscsi_session_setup(&iscsi_sw_tcp_transport, shost, |
Jayamohan Kallickal | b8b9e1b8 | 2009-09-22 08:21:22 +0530 | [diff] [blame] | 864 | cmds_max, 0, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 865 | sizeof(struct iscsi_tcp_task) + |
| 866 | sizeof(struct iscsi_sw_tcp_hdrbuf), |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 867 | initial_cmdsn, 0); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 868 | if (!cls_session) |
| 869 | goto remove_host; |
| 870 | session = cls_session->dd_data; |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 871 | tcp_sw_host = iscsi_host_priv(shost); |
| 872 | tcp_sw_host->session = session; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 873 | |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 874 | shost->can_queue = session->scsi_cmds_max; |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 875 | if (iscsi_tcp_r2tpool_alloc(session)) |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 876 | goto remove_session; |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 877 | return cls_session; |
| 878 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 879 | remove_session: |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 880 | iscsi_session_teardown(cls_session); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 881 | remove_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 882 | iscsi_host_remove(shost); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 883 | free_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 884 | iscsi_host_free(shost); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 885 | return NULL; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 888 | static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session) |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 889 | { |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 890 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); |
| 891 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 892 | iscsi_tcp_r2tpool_free(cls_session->dd_data); |
Mike Christie | e5bd7b54 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 893 | iscsi_session_teardown(cls_session); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 894 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 895 | iscsi_host_remove(shost); |
| 896 | iscsi_host_free(shost); |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 897 | } |
| 898 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 899 | static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 900 | { |
| 901 | switch (param_type) { |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 902 | 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 Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 912 | 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 Christie | 4bfb8ebf | 2014-09-29 13:55:42 -0500 | [diff] [blame] | 920 | case ISCSI_PARAM_LOCAL_PORT: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 921 | 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 Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 926 | 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 Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 946 | return S_IRUGO; |
| 947 | default: |
| 948 | return 0; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 955 | static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev) |
Mike Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 956 | { |
Jianchao Wang | 89d0c80 | 2018-03-07 20:29:03 +0800 | [diff] [blame] | 957 | 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 Christie | d1d81c0 | 2007-05-30 12:57:21 -0500 | [diff] [blame] | 964 | blk_queue_dma_alignment(sdev->request_queue, 0); |
| 965 | return 0; |
| 966 | } |
| 967 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 968 | static struct scsi_host_template iscsi_sw_tcp_sht = { |
Mike Christie | 7974392 | 2007-07-26 12:46:46 -0500 | [diff] [blame] | 969 | .module = THIS_MODULE, |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 970 | .name = "iSCSI Initiator over TCP/IP", |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 971 | .queuecommand = iscsi_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 972 | .change_queue_depth = scsi_change_queue_depth, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 973 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
Mike Christie | 66bbe0c | 2007-12-13 12:43:39 -0600 | [diff] [blame] | 974 | .sg_tablesize = 4096, |
Mike Christie | 8231f0e | 2007-02-28 17:32:20 -0600 | [diff] [blame] | 975 | .max_sectors = 0xFFFF, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 976 | .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 977 | .eh_timed_out = iscsi_eh_cmd_timed_out, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 978 | .eh_abort_handler = iscsi_eh_abort, |
Mike Christie | 843c0a8 | 2007-12-13 12:43:20 -0600 | [diff] [blame] | 979 | .eh_device_reset_handler= iscsi_eh_device_reset, |
Jayamohan Kallickal | 309ce15 | 2010-02-20 08:02:10 +0530 | [diff] [blame] | 980 | .eh_target_reset_handler = iscsi_eh_recover_target, |
Christoph Hellwig | 4af14d1 | 2018-12-13 16:17:09 +0100 | [diff] [blame] | 981 | .dma_boundary = PAGE_SIZE - 1, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 982 | .slave_configure = iscsi_sw_tcp_slave_configure, |
Mike Christie | 6b5d6c4 | 2009-04-21 15:32:32 -0500 | [diff] [blame] | 983 | .target_alloc = iscsi_target_alloc, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 984 | .proc_name = "iscsi_tcp", |
| 985 | .this_id = -1, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 986 | .track_queue_depth = 1, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 987 | }; |
| 988 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 989 | static struct iscsi_transport iscsi_sw_tcp_transport = { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 990 | .owner = THIS_MODULE, |
| 991 | .name = "tcp", |
| 992 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
| 993 | | CAP_DATADGST, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 994 | /* session management */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 995 | .create_session = iscsi_sw_tcp_session_create, |
| 996 | .destroy_session = iscsi_sw_tcp_session_destroy, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 997 | /* connection management */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 998 | .create_conn = iscsi_sw_tcp_conn_create, |
| 999 | .bind_conn = iscsi_sw_tcp_conn_bind, |
| 1000 | .destroy_conn = iscsi_sw_tcp_conn_destroy, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 1001 | .attr_is_visible = iscsi_sw_tcp_attr_is_visible, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1002 | .set_param = iscsi_sw_tcp_conn_set_param, |
| 1003 | .get_conn_param = iscsi_sw_tcp_conn_get_param, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1004 | .get_session_param = iscsi_session_get_param, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1005 | .start_conn = iscsi_conn_start, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1006 | .stop_conn = iscsi_sw_tcp_conn_stop, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 1007 | /* iscsi host params */ |
Mike Christie | a79af8a | 2011-02-16 15:04:36 -0600 | [diff] [blame] | 1008 | .get_host_param = iscsi_sw_tcp_host_get_param, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 1009 | .set_host_param = iscsi_host_set_param, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1010 | /* IO */ |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1011 | .send_pdu = iscsi_conn_send_pdu, |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1012 | .get_stats = iscsi_sw_tcp_conn_get_stats, |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 1013 | /* iscsi task/cmd helpers */ |
Mike Christie | fbc514b | 2008-05-21 15:54:07 -0500 | [diff] [blame] | 1014 | .init_task = iscsi_tcp_task_init, |
| 1015 | .xmit_task = iscsi_tcp_task_xmit, |
| 1016 | .cleanup_task = iscsi_tcp_cleanup_task, |
Mike Christie | e5a7efe | 2008-12-02 00:32:07 -0600 | [diff] [blame] | 1017 | /* low level pdu helpers */ |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1018 | .xmit_pdu = iscsi_sw_tcp_pdu_xmit, |
| 1019 | .init_pdu = iscsi_sw_tcp_pdu_init, |
| 1020 | .alloc_pdu = iscsi_sw_tcp_pdu_alloc, |
Mike Christie | 5bb0b55 | 2006-04-06 21:26:46 -0500 | [diff] [blame] | 1021 | /* recovery */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1022 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1023 | }; |
| 1024 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1025 | static int __init iscsi_sw_tcp_init(void) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1026 | { |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1027 | if (iscsi_max_lun < 1) { |
Or Gerlitz | be2df72 | 2006-05-02 19:46:43 -0500 | [diff] [blame] | 1028 | printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n", |
| 1029 | iscsi_max_lun); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1030 | return -EINVAL; |
| 1031 | } |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1032 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1033 | iscsi_sw_tcp_scsi_transport = iscsi_register_transport( |
| 1034 | &iscsi_sw_tcp_transport); |
| 1035 | if (!iscsi_sw_tcp_scsi_transport) |
Mike Christie | ffbfe92 | 2006-05-18 20:31:36 -0500 | [diff] [blame] | 1036 | return -ENODEV; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1037 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1038 | return 0; |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1041 | static void __exit iscsi_sw_tcp_exit(void) |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1042 | { |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1043 | iscsi_unregister_transport(&iscsi_sw_tcp_transport); |
Alex Aizman | 7ba2471 | 2005-08-04 19:30:08 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Mike Christie | 38e1a8f | 2008-12-02 00:32:12 -0600 | [diff] [blame] | 1046 | module_init(iscsi_sw_tcp_init); |
| 1047 | module_exit(iscsi_sw_tcp_exit); |