Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * iSCSI transport class definitions |
| 4 | * |
| 5 | * Copyright (C) IBM Corporation, 2004 |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 6 | * Copyright (C) Mike Christie, 2004 - 2005 |
| 7 | * Copyright (C) Dmitry Yusupov, 2004 - 2005 |
| 8 | * Copyright (C) Alex Aizman, 2004 - 2005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | #include <linux/module.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 11 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 13 | #include <linux/bsg-lib.h> |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 14 | #include <linux/idr.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 15 | #include <net/tcp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <scsi/scsi.h> |
| 17 | #include <scsi/scsi_host.h> |
| 18 | #include <scsi/scsi_device.h> |
| 19 | #include <scsi/scsi_transport.h> |
| 20 | #include <scsi/scsi_transport_iscsi.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 21 | #include <scsi/iscsi_if.h> |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 22 | #include <scsi/scsi_cmnd.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 23 | #include <scsi/scsi_bsg_iscsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Mike Christie | 4c2133c | 2008-06-16 10:11:34 -0500 | [diff] [blame] | 25 | #define ISCSI_TRANSPORT_VERSION "2.0-870" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Bo Wu | bba340c | 2019-11-20 13:26:17 +0000 | [diff] [blame] | 27 | #define ISCSI_SEND_MAX_ALLOWED 10 |
| 28 | |
Fred Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 29 | #define CREATE_TRACE_POINTS |
| 30 | #include <trace/events/iscsi.h> |
| 31 | |
| 32 | /* |
| 33 | * Export tracepoint symbols to be used by other modules. |
| 34 | */ |
| 35 | EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_conn); |
| 36 | EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_eh); |
| 37 | EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_session); |
| 38 | EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_tcp); |
| 39 | EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_sw_tcp); |
| 40 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 41 | static int dbg_session; |
| 42 | module_param_named(debug_session, dbg_session, int, |
| 43 | S_IRUGO | S_IWUSR); |
| 44 | MODULE_PARM_DESC(debug_session, |
| 45 | "Turn on debugging for sessions in scsi_transport_iscsi " |
| 46 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 47 | "is off."); |
| 48 | |
| 49 | static int dbg_conn; |
| 50 | module_param_named(debug_conn, dbg_conn, int, |
| 51 | S_IRUGO | S_IWUSR); |
| 52 | MODULE_PARM_DESC(debug_conn, |
| 53 | "Turn on debugging for connections in scsi_transport_iscsi " |
| 54 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 55 | "is off."); |
| 56 | |
| 57 | #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \ |
| 58 | do { \ |
| 59 | if (dbg_session) \ |
| 60 | iscsi_cls_session_printk(KERN_INFO, _session, \ |
| 61 | "%s: " dbg_fmt, \ |
| 62 | __func__, ##arg); \ |
Fred Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 63 | iscsi_dbg_trace(trace_iscsi_dbg_trans_session, \ |
| 64 | &(_session)->dev, \ |
| 65 | "%s " dbg_fmt, __func__, ##arg); \ |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 66 | } while (0); |
| 67 | |
| 68 | #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \ |
| 69 | do { \ |
| 70 | if (dbg_conn) \ |
| 71 | iscsi_cls_conn_printk(KERN_INFO, _conn, \ |
| 72 | "%s: " dbg_fmt, \ |
Fred Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 73 | __func__, ##arg); \ |
| 74 | iscsi_dbg_trace(trace_iscsi_dbg_trans_conn, \ |
| 75 | &(_conn)->dev, \ |
| 76 | "%s " dbg_fmt, __func__, ##arg); \ |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 77 | } while (0); |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | struct iscsi_internal { |
| 80 | struct scsi_transport_template t; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 81 | struct iscsi_transport *iscsi_transport; |
| 82 | struct list_head list; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 83 | struct device dev; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 84 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 85 | struct transport_container conn_cont; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 86 | struct transport_container session_cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 89 | /* Worker to perform connection failure on unresponsive connections |
| 90 | * completely in kernel space. |
| 91 | */ |
| 92 | static void stop_conn_work_fn(struct work_struct *work); |
| 93 | static DECLARE_WORK(stop_conn_work, stop_conn_work_fn); |
| 94 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 95 | static atomic_t iscsi_session_nr; /* sysfs session id for next new session */ |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 96 | static struct workqueue_struct *iscsi_eh_timer_workq; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 97 | |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 98 | static struct workqueue_struct *iscsi_destroy_workq; |
| 99 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 100 | static DEFINE_IDA(iscsi_sess_ida); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 101 | /* |
| 102 | * list of registered transports and lock that must |
| 103 | * be held while accessing list. The iscsi_transport_lock must |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 104 | * be acquired after the rx_queue_mutex. |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 105 | */ |
| 106 | static LIST_HEAD(iscsi_transports); |
| 107 | static DEFINE_SPINLOCK(iscsi_transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 109 | #define to_iscsi_internal(tmpl) \ |
| 110 | container_of(tmpl, struct iscsi_internal, t) |
| 111 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 112 | #define dev_to_iscsi_internal(_dev) \ |
| 113 | container_of(_dev, struct iscsi_internal, dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 114 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 115 | static void iscsi_transport_release(struct device *dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 116 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 117 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 118 | kfree(priv); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * iscsi_transport_class represents the iscsi_transports that are |
| 123 | * registered. |
| 124 | */ |
| 125 | static struct class iscsi_transport_class = { |
| 126 | .name = "iscsi_transport", |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 127 | .dev_release = iscsi_transport_release, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 131 | show_transport_handle(struct device *dev, struct device_attribute *attr, |
| 132 | char *buf) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 133 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 134 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Lee Duncan | c71edc5 | 2021-02-23 13:06:24 -0800 | [diff] [blame] | 135 | |
| 136 | if (!capable(CAP_SYS_ADMIN)) |
| 137 | return -EACCES; |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 138 | return sysfs_emit(buf, "%llu\n", |
| 139 | (unsigned long long)iscsi_handle(priv->iscsi_transport)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 140 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 141 | static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 142 | |
| 143 | #define show_transport_attr(name, format) \ |
| 144 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 145 | show_transport_##name(struct device *dev, \ |
| 146 | struct device_attribute *attr,char *buf) \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 147 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 148 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \ |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 149 | return sysfs_emit(buf, format"\n", priv->iscsi_transport->name);\ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 150 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 151 | static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 152 | |
| 153 | show_transport_attr(caps, "0x%x"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 154 | |
| 155 | static struct attribute *iscsi_transport_attrs[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 156 | &dev_attr_handle.attr, |
| 157 | &dev_attr_caps.attr, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 158 | NULL, |
| 159 | }; |
| 160 | |
| 161 | static struct attribute_group iscsi_transport_group = { |
| 162 | .attrs = iscsi_transport_attrs, |
| 163 | }; |
| 164 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 165 | /* |
| 166 | * iSCSI endpoint attrs |
| 167 | */ |
| 168 | #define iscsi_dev_to_endpoint(_dev) \ |
| 169 | container_of(_dev, struct iscsi_endpoint, dev) |
| 170 | |
| 171 | #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 172 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 173 | __ATTR(_name,_mode,_show,_store) |
| 174 | |
| 175 | static void iscsi_endpoint_release(struct device *dev) |
| 176 | { |
| 177 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
| 178 | kfree(ep); |
| 179 | } |
| 180 | |
| 181 | static struct class iscsi_endpoint_class = { |
| 182 | .name = "iscsi_endpoint", |
| 183 | .dev_release = iscsi_endpoint_release, |
| 184 | }; |
| 185 | |
| 186 | static ssize_t |
| 187 | show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf) |
| 188 | { |
| 189 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 190 | return sysfs_emit(buf, "%llu\n", (unsigned long long) ep->id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 191 | } |
| 192 | static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL); |
| 193 | |
| 194 | static struct attribute *iscsi_endpoint_attrs[] = { |
| 195 | &dev_attr_ep_handle.attr, |
| 196 | NULL, |
| 197 | }; |
| 198 | |
| 199 | static struct attribute_group iscsi_endpoint_group = { |
| 200 | .attrs = iscsi_endpoint_attrs, |
| 201 | }; |
| 202 | |
| 203 | #define ISCSI_MAX_EPID -1 |
| 204 | |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 205 | static int iscsi_match_epid(struct device *dev, const void *data) |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 206 | { |
| 207 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 208 | const uint64_t *epid = data; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 209 | |
| 210 | return *epid == ep->id; |
| 211 | } |
| 212 | |
| 213 | struct iscsi_endpoint * |
| 214 | iscsi_create_endpoint(int dd_size) |
| 215 | { |
| 216 | struct device *dev; |
| 217 | struct iscsi_endpoint *ep; |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 218 | uint64_t id; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 219 | int err; |
| 220 | |
| 221 | for (id = 1; id < ISCSI_MAX_EPID; id++) { |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 222 | dev = class_find_device(&iscsi_endpoint_class, NULL, &id, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 223 | iscsi_match_epid); |
| 224 | if (!dev) |
| 225 | break; |
Sagi Grimberg | 4ce3087 | 2015-05-20 12:38:58 +0300 | [diff] [blame] | 226 | else |
| 227 | put_device(dev); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 228 | } |
| 229 | if (id == ISCSI_MAX_EPID) { |
| 230 | printk(KERN_ERR "Too many connections. Max supported %u\n", |
| 231 | ISCSI_MAX_EPID - 1); |
| 232 | return NULL; |
| 233 | } |
| 234 | |
| 235 | ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL); |
| 236 | if (!ep) |
| 237 | return NULL; |
| 238 | |
| 239 | ep->id = id; |
| 240 | ep->dev.class = &iscsi_endpoint_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 241 | dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 242 | err = device_register(&ep->dev); |
| 243 | if (err) |
| 244 | goto free_ep; |
| 245 | |
| 246 | err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 247 | if (err) |
| 248 | goto unregister_dev; |
| 249 | |
| 250 | if (dd_size) |
| 251 | ep->dd_data = &ep[1]; |
| 252 | return ep; |
| 253 | |
| 254 | unregister_dev: |
| 255 | device_unregister(&ep->dev); |
| 256 | return NULL; |
| 257 | |
| 258 | free_ep: |
| 259 | kfree(ep); |
| 260 | return NULL; |
| 261 | } |
| 262 | EXPORT_SYMBOL_GPL(iscsi_create_endpoint); |
| 263 | |
| 264 | void iscsi_destroy_endpoint(struct iscsi_endpoint *ep) |
| 265 | { |
| 266 | sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 267 | device_unregister(&ep->dev); |
| 268 | } |
| 269 | EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint); |
| 270 | |
| 271 | struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) |
| 272 | { |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 273 | struct iscsi_endpoint *ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 274 | struct device *dev; |
| 275 | |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 276 | dev = class_find_device(&iscsi_endpoint_class, NULL, &handle, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 277 | iscsi_match_epid); |
| 278 | if (!dev) |
| 279 | return NULL; |
| 280 | |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 281 | ep = iscsi_dev_to_endpoint(dev); |
| 282 | /* |
| 283 | * we can drop this now because the interface will prevent |
| 284 | * removals and lookups from racing. |
| 285 | */ |
| 286 | put_device(dev); |
| 287 | return ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 288 | } |
| 289 | EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint); |
| 290 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 291 | /* |
| 292 | * Interface to display network param to sysfs |
| 293 | */ |
| 294 | |
| 295 | static void iscsi_iface_release(struct device *dev) |
| 296 | { |
| 297 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 298 | struct device *parent = iface->dev.parent; |
| 299 | |
| 300 | kfree(iface); |
| 301 | put_device(parent); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | static struct class iscsi_iface_class = { |
| 306 | .name = "iscsi_iface", |
| 307 | .dev_release = iscsi_iface_release, |
| 308 | }; |
| 309 | |
| 310 | #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \ |
| 311 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 312 | __ATTR(_name, _mode, _show, _store) |
| 313 | |
| 314 | /* iface attrs show */ |
| 315 | #define iscsi_iface_attr_show(type, name, param_type, param) \ |
| 316 | static ssize_t \ |
| 317 | show_##type##_##name(struct device *dev, struct device_attribute *attr, \ |
| 318 | char *buf) \ |
| 319 | { \ |
| 320 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \ |
| 321 | struct iscsi_transport *t = iface->transport; \ |
| 322 | return t->get_iface_param(iface, param_type, param, buf); \ |
| 323 | } \ |
| 324 | |
| 325 | #define iscsi_iface_net_attr(type, name, param) \ |
| 326 | iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \ |
| 327 | static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL); |
| 328 | |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 329 | #define iscsi_iface_attr(type, name, param) \ |
| 330 | iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \ |
| 331 | static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL); |
| 332 | |
| 333 | /* generic read only ipv4 attribute */ |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 334 | iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR); |
| 335 | iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW); |
| 336 | iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET); |
| 337 | iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO); |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 338 | iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en, |
| 339 | ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN); |
| 340 | iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en, |
| 341 | ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN); |
| 342 | iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN); |
| 343 | iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS); |
| 344 | iscsi_iface_net_attr(ipv4_iface, grat_arp_en, |
| 345 | ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN); |
| 346 | iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en, |
| 347 | ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN); |
| 348 | iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id, |
| 349 | ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID); |
| 350 | iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en, |
| 351 | ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN); |
| 352 | iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en, |
| 353 | ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN); |
| 354 | iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id, |
| 355 | ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID); |
| 356 | iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en, |
| 357 | ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN); |
| 358 | iscsi_iface_net_attr(ipv4_iface, fragment_disable, |
| 359 | ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE); |
| 360 | iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en, |
| 361 | ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN); |
| 362 | iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 363 | |
| 364 | /* generic read only ipv6 attribute */ |
| 365 | iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR); |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 366 | iscsi_iface_net_attr(ipv6_iface, link_local_addr, |
| 367 | ISCSI_NET_PARAM_IPV6_LINKLOCAL); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 368 | iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER); |
| 369 | iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg, |
| 370 | ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG); |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 371 | iscsi_iface_net_attr(ipv6_iface, link_local_autocfg, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 372 | ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG); |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 373 | iscsi_iface_net_attr(ipv6_iface, link_local_state, |
| 374 | ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE); |
| 375 | iscsi_iface_net_attr(ipv6_iface, router_state, |
| 376 | ISCSI_NET_PARAM_IPV6_ROUTER_STATE); |
| 377 | iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en, |
| 378 | ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN); |
| 379 | iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN); |
| 380 | iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL); |
| 381 | iscsi_iface_net_attr(ipv6_iface, traffic_class, |
| 382 | ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS); |
| 383 | iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT); |
| 384 | iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo, |
| 385 | ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO); |
| 386 | iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time, |
| 387 | ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME); |
| 388 | iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo, |
| 389 | ISCSI_NET_PARAM_IPV6_ND_STALE_TMO); |
| 390 | iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt, |
| 391 | ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT); |
| 392 | iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu, |
| 393 | ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 394 | |
| 395 | /* common read only iface attribute */ |
| 396 | iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE); |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 397 | iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID); |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 398 | iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY); |
| 399 | iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED); |
Vikas Chaudhary | 8c7d40f | 2011-08-01 03:26:12 -0700 | [diff] [blame] | 400 | iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU); |
Vikas Chaudhary | fcb5124 | 2011-08-01 03:26:18 -0700 | [diff] [blame] | 401 | iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT); |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 402 | iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE); |
| 403 | iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN); |
| 404 | iscsi_iface_net_attr(iface, tcp_nagle_disable, |
| 405 | ISCSI_NET_PARAM_TCP_NAGLE_DISABLE); |
| 406 | iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE); |
| 407 | iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF); |
| 408 | iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE); |
| 409 | iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN); |
| 410 | iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID); |
| 411 | iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN); |
| 412 | |
| 413 | /* common iscsi specific settings attributes */ |
| 414 | iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO); |
| 415 | iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN); |
| 416 | iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN); |
| 417 | iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN); |
| 418 | iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN); |
| 419 | iscsi_iface_attr(iface, data_seq_in_order, |
| 420 | ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN); |
| 421 | iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN); |
| 422 | iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL); |
| 423 | iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH); |
| 424 | iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST); |
| 425 | iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T); |
| 426 | iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST); |
| 427 | iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN); |
| 428 | iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN); |
| 429 | iscsi_iface_attr(iface, discovery_auth_optional, |
| 430 | ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL); |
| 431 | iscsi_iface_attr(iface, discovery_logout, |
| 432 | ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN); |
| 433 | iscsi_iface_attr(iface, strict_login_comp_en, |
| 434 | ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN); |
| 435 | iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 436 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 437 | static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 438 | struct attribute *attr, int i) |
| 439 | { |
| 440 | struct device *dev = container_of(kobj, struct device, kobj); |
| 441 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 442 | struct iscsi_transport *t = iface->transport; |
Mike Christie | b82a1a2 | 2021-06-30 19:25:59 -0500 | [diff] [blame] | 443 | int param = -1; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 444 | |
Baokun Li | 2d030542 | 2021-09-01 16:53:36 +0800 | [diff] [blame] | 445 | if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr) |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 446 | param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO; |
| 447 | else if (attr == &dev_attr_iface_header_digest.attr) |
| 448 | param = ISCSI_IFACE_PARAM_HDRDGST_EN; |
| 449 | else if (attr == &dev_attr_iface_data_digest.attr) |
| 450 | param = ISCSI_IFACE_PARAM_DATADGST_EN; |
| 451 | else if (attr == &dev_attr_iface_immediate_data.attr) |
| 452 | param = ISCSI_IFACE_PARAM_IMM_DATA_EN; |
| 453 | else if (attr == &dev_attr_iface_initial_r2t.attr) |
| 454 | param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN; |
| 455 | else if (attr == &dev_attr_iface_data_seq_in_order.attr) |
| 456 | param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN; |
| 457 | else if (attr == &dev_attr_iface_data_pdu_in_order.attr) |
| 458 | param = ISCSI_IFACE_PARAM_PDU_INORDER_EN; |
| 459 | else if (attr == &dev_attr_iface_erl.attr) |
| 460 | param = ISCSI_IFACE_PARAM_ERL; |
| 461 | else if (attr == &dev_attr_iface_max_recv_dlength.attr) |
| 462 | param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH; |
| 463 | else if (attr == &dev_attr_iface_first_burst_len.attr) |
| 464 | param = ISCSI_IFACE_PARAM_FIRST_BURST; |
| 465 | else if (attr == &dev_attr_iface_max_outstanding_r2t.attr) |
| 466 | param = ISCSI_IFACE_PARAM_MAX_R2T; |
| 467 | else if (attr == &dev_attr_iface_max_burst_len.attr) |
| 468 | param = ISCSI_IFACE_PARAM_MAX_BURST; |
| 469 | else if (attr == &dev_attr_iface_chap_auth.attr) |
| 470 | param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN; |
| 471 | else if (attr == &dev_attr_iface_bidi_chap.attr) |
| 472 | param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN; |
| 473 | else if (attr == &dev_attr_iface_discovery_auth_optional.attr) |
| 474 | param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL; |
| 475 | else if (attr == &dev_attr_iface_discovery_logout.attr) |
| 476 | param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN; |
| 477 | else if (attr == &dev_attr_iface_strict_login_comp_en.attr) |
| 478 | param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN; |
| 479 | else if (attr == &dev_attr_iface_initiator_name.attr) |
| 480 | param = ISCSI_IFACE_PARAM_INITIATOR_NAME; |
Mike Christie | b82a1a2 | 2021-06-30 19:25:59 -0500 | [diff] [blame] | 481 | |
| 482 | if (param != -1) |
| 483 | return t->attr_is_visible(ISCSI_IFACE_PARAM, param); |
| 484 | |
Baokun Li | 2d030542 | 2021-09-01 16:53:36 +0800 | [diff] [blame] | 485 | if (attr == &dev_attr_iface_enabled.attr) |
| 486 | param = ISCSI_NET_PARAM_IFACE_ENABLE; |
| 487 | else if (attr == &dev_attr_iface_vlan_id.attr) |
Mike Christie | b82a1a2 | 2021-06-30 19:25:59 -0500 | [diff] [blame] | 488 | param = ISCSI_NET_PARAM_VLAN_ID; |
| 489 | else if (attr == &dev_attr_iface_vlan_priority.attr) |
| 490 | param = ISCSI_NET_PARAM_VLAN_PRIORITY; |
| 491 | else if (attr == &dev_attr_iface_vlan_enabled.attr) |
| 492 | param = ISCSI_NET_PARAM_VLAN_ENABLED; |
| 493 | else if (attr == &dev_attr_iface_mtu.attr) |
| 494 | param = ISCSI_NET_PARAM_MTU; |
| 495 | else if (attr == &dev_attr_iface_port.attr) |
| 496 | param = ISCSI_NET_PARAM_PORT; |
| 497 | else if (attr == &dev_attr_iface_ipaddress_state.attr) |
| 498 | param = ISCSI_NET_PARAM_IPADDR_STATE; |
| 499 | else if (attr == &dev_attr_iface_delayed_ack_en.attr) |
| 500 | param = ISCSI_NET_PARAM_DELAYED_ACK_EN; |
| 501 | else if (attr == &dev_attr_iface_tcp_nagle_disable.attr) |
| 502 | param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE; |
| 503 | else if (attr == &dev_attr_iface_tcp_wsf_disable.attr) |
| 504 | param = ISCSI_NET_PARAM_TCP_WSF_DISABLE; |
| 505 | else if (attr == &dev_attr_iface_tcp_wsf.attr) |
| 506 | param = ISCSI_NET_PARAM_TCP_WSF; |
| 507 | else if (attr == &dev_attr_iface_tcp_timer_scale.attr) |
| 508 | param = ISCSI_NET_PARAM_TCP_TIMER_SCALE; |
| 509 | else if (attr == &dev_attr_iface_tcp_timestamp_en.attr) |
| 510 | param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN; |
| 511 | else if (attr == &dev_attr_iface_cache_id.attr) |
| 512 | param = ISCSI_NET_PARAM_CACHE_ID; |
| 513 | else if (attr == &dev_attr_iface_redirect_en.attr) |
| 514 | param = ISCSI_NET_PARAM_REDIRECT_EN; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 515 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 516 | if (attr == &dev_attr_ipv4_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 517 | param = ISCSI_NET_PARAM_IPV4_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 518 | else if (attr == &dev_attr_ipv4_iface_gateway.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 519 | param = ISCSI_NET_PARAM_IPV4_GW; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 520 | else if (attr == &dev_attr_ipv4_iface_subnet.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 521 | param = ISCSI_NET_PARAM_IPV4_SUBNET; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 522 | else if (attr == &dev_attr_ipv4_iface_bootproto.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 523 | param = ISCSI_NET_PARAM_IPV4_BOOTPROTO; |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 524 | else if (attr == |
| 525 | &dev_attr_ipv4_iface_dhcp_dns_address_en.attr) |
| 526 | param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN; |
| 527 | else if (attr == |
| 528 | &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr) |
| 529 | param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN; |
| 530 | else if (attr == &dev_attr_ipv4_iface_tos_en.attr) |
| 531 | param = ISCSI_NET_PARAM_IPV4_TOS_EN; |
| 532 | else if (attr == &dev_attr_ipv4_iface_tos.attr) |
| 533 | param = ISCSI_NET_PARAM_IPV4_TOS; |
| 534 | else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr) |
| 535 | param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN; |
| 536 | else if (attr == |
| 537 | &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr) |
| 538 | param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN; |
| 539 | else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr) |
| 540 | param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID; |
| 541 | else if (attr == |
| 542 | &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr) |
| 543 | param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN; |
| 544 | else if (attr == |
| 545 | &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr) |
| 546 | param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN; |
| 547 | else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr) |
| 548 | param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID; |
| 549 | else if (attr == |
| 550 | &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr) |
| 551 | param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN; |
| 552 | else if (attr == |
| 553 | &dev_attr_ipv4_iface_fragment_disable.attr) |
| 554 | param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE; |
| 555 | else if (attr == |
| 556 | &dev_attr_ipv4_iface_incoming_forwarding_en.attr) |
| 557 | param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN; |
| 558 | else if (attr == &dev_attr_ipv4_iface_ttl.attr) |
| 559 | param = ISCSI_NET_PARAM_IPV4_TTL; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 560 | else |
| 561 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 562 | } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) { |
| 563 | if (attr == &dev_attr_ipv6_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 564 | param = ISCSI_NET_PARAM_IPV6_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 565 | else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 566 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 567 | else if (attr == &dev_attr_ipv6_iface_router_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 568 | param = ISCSI_NET_PARAM_IPV6_ROUTER; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 569 | else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 570 | param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG; |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 571 | else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 572 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG; |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 573 | else if (attr == &dev_attr_ipv6_iface_link_local_state.attr) |
| 574 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE; |
| 575 | else if (attr == &dev_attr_ipv6_iface_router_state.attr) |
| 576 | param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE; |
| 577 | else if (attr == |
| 578 | &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr) |
| 579 | param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN; |
| 580 | else if (attr == &dev_attr_ipv6_iface_mld_en.attr) |
| 581 | param = ISCSI_NET_PARAM_IPV6_MLD_EN; |
| 582 | else if (attr == &dev_attr_ipv6_iface_flow_label.attr) |
| 583 | param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL; |
| 584 | else if (attr == &dev_attr_ipv6_iface_traffic_class.attr) |
| 585 | param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS; |
| 586 | else if (attr == &dev_attr_ipv6_iface_hop_limit.attr) |
| 587 | param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT; |
| 588 | else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr) |
| 589 | param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO; |
| 590 | else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr) |
| 591 | param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME; |
| 592 | else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr) |
| 593 | param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO; |
| 594 | else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr) |
| 595 | param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT; |
| 596 | else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr) |
| 597 | param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 598 | else |
| 599 | return 0; |
| 600 | } else { |
| 601 | WARN_ONCE(1, "Invalid iface attr"); |
| 602 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 603 | } |
| 604 | |
Mike Christie | b82a1a2 | 2021-06-30 19:25:59 -0500 | [diff] [blame] | 605 | return t->attr_is_visible(ISCSI_NET_PARAM, param); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static struct attribute *iscsi_iface_attrs[] = { |
| 609 | &dev_attr_iface_enabled.attr, |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 610 | &dev_attr_iface_vlan_id.attr, |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 611 | &dev_attr_iface_vlan_priority.attr, |
| 612 | &dev_attr_iface_vlan_enabled.attr, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 613 | &dev_attr_ipv4_iface_ipaddress.attr, |
| 614 | &dev_attr_ipv4_iface_gateway.attr, |
| 615 | &dev_attr_ipv4_iface_subnet.attr, |
| 616 | &dev_attr_ipv4_iface_bootproto.attr, |
| 617 | &dev_attr_ipv6_iface_ipaddress.attr, |
| 618 | &dev_attr_ipv6_iface_link_local_addr.attr, |
| 619 | &dev_attr_ipv6_iface_router_addr.attr, |
| 620 | &dev_attr_ipv6_iface_ipaddr_autocfg.attr, |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 621 | &dev_attr_ipv6_iface_link_local_autocfg.attr, |
Vikas Chaudhary | 8c7d40f | 2011-08-01 03:26:12 -0700 | [diff] [blame] | 622 | &dev_attr_iface_mtu.attr, |
Vikas Chaudhary | fcb5124 | 2011-08-01 03:26:18 -0700 | [diff] [blame] | 623 | &dev_attr_iface_port.attr, |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 624 | &dev_attr_iface_ipaddress_state.attr, |
| 625 | &dev_attr_iface_delayed_ack_en.attr, |
| 626 | &dev_attr_iface_tcp_nagle_disable.attr, |
| 627 | &dev_attr_iface_tcp_wsf_disable.attr, |
| 628 | &dev_attr_iface_tcp_wsf.attr, |
| 629 | &dev_attr_iface_tcp_timer_scale.attr, |
| 630 | &dev_attr_iface_tcp_timestamp_en.attr, |
| 631 | &dev_attr_iface_cache_id.attr, |
| 632 | &dev_attr_iface_redirect_en.attr, |
| 633 | &dev_attr_iface_def_taskmgmt_tmo.attr, |
| 634 | &dev_attr_iface_header_digest.attr, |
| 635 | &dev_attr_iface_data_digest.attr, |
| 636 | &dev_attr_iface_immediate_data.attr, |
| 637 | &dev_attr_iface_initial_r2t.attr, |
| 638 | &dev_attr_iface_data_seq_in_order.attr, |
| 639 | &dev_attr_iface_data_pdu_in_order.attr, |
| 640 | &dev_attr_iface_erl.attr, |
| 641 | &dev_attr_iface_max_recv_dlength.attr, |
| 642 | &dev_attr_iface_first_burst_len.attr, |
| 643 | &dev_attr_iface_max_outstanding_r2t.attr, |
| 644 | &dev_attr_iface_max_burst_len.attr, |
| 645 | &dev_attr_iface_chap_auth.attr, |
| 646 | &dev_attr_iface_bidi_chap.attr, |
| 647 | &dev_attr_iface_discovery_auth_optional.attr, |
| 648 | &dev_attr_iface_discovery_logout.attr, |
| 649 | &dev_attr_iface_strict_login_comp_en.attr, |
| 650 | &dev_attr_iface_initiator_name.attr, |
| 651 | &dev_attr_ipv4_iface_dhcp_dns_address_en.attr, |
| 652 | &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr, |
| 653 | &dev_attr_ipv4_iface_tos_en.attr, |
| 654 | &dev_attr_ipv4_iface_tos.attr, |
| 655 | &dev_attr_ipv4_iface_grat_arp_en.attr, |
| 656 | &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr, |
| 657 | &dev_attr_ipv4_iface_dhcp_alt_client_id.attr, |
| 658 | &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr, |
| 659 | &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr, |
| 660 | &dev_attr_ipv4_iface_dhcp_vendor_id.attr, |
| 661 | &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr, |
| 662 | &dev_attr_ipv4_iface_fragment_disable.attr, |
| 663 | &dev_attr_ipv4_iface_incoming_forwarding_en.attr, |
| 664 | &dev_attr_ipv4_iface_ttl.attr, |
| 665 | &dev_attr_ipv6_iface_link_local_state.attr, |
| 666 | &dev_attr_ipv6_iface_router_state.attr, |
| 667 | &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr, |
| 668 | &dev_attr_ipv6_iface_mld_en.attr, |
| 669 | &dev_attr_ipv6_iface_flow_label.attr, |
| 670 | &dev_attr_ipv6_iface_traffic_class.attr, |
| 671 | &dev_attr_ipv6_iface_hop_limit.attr, |
| 672 | &dev_attr_ipv6_iface_nd_reachable_tmo.attr, |
| 673 | &dev_attr_ipv6_iface_nd_rexmit_time.attr, |
| 674 | &dev_attr_ipv6_iface_nd_stale_tmo.attr, |
| 675 | &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr, |
| 676 | &dev_attr_ipv6_iface_router_adv_link_mtu.attr, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 677 | NULL, |
| 678 | }; |
| 679 | |
| 680 | static struct attribute_group iscsi_iface_group = { |
| 681 | .attrs = iscsi_iface_attrs, |
| 682 | .is_visible = iscsi_iface_attr_is_visible, |
| 683 | }; |
| 684 | |
Harish Zunjarrao | 3e0f65b | 2013-10-18 09:01:41 -0400 | [diff] [blame] | 685 | /* convert iscsi_ipaddress_state values to ascii string name */ |
| 686 | static const struct { |
| 687 | enum iscsi_ipaddress_state value; |
| 688 | char *name; |
| 689 | } iscsi_ipaddress_state_names[] = { |
| 690 | {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" }, |
| 691 | {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" }, |
| 692 | {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" }, |
| 693 | {ISCSI_IPDDRESS_STATE_VALID, "Valid" }, |
| 694 | {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" }, |
| 695 | {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" }, |
| 696 | {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" }, |
| 697 | }; |
| 698 | |
| 699 | char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state) |
| 700 | { |
| 701 | int i; |
| 702 | char *state = NULL; |
| 703 | |
| 704 | for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) { |
| 705 | if (iscsi_ipaddress_state_names[i].value == port_state) { |
| 706 | state = iscsi_ipaddress_state_names[i].name; |
| 707 | break; |
| 708 | } |
| 709 | } |
| 710 | return state; |
| 711 | } |
| 712 | EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name); |
| 713 | |
| 714 | /* convert iscsi_router_state values to ascii string name */ |
| 715 | static const struct { |
| 716 | enum iscsi_router_state value; |
| 717 | char *name; |
| 718 | } iscsi_router_state_names[] = { |
| 719 | {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" }, |
| 720 | {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" }, |
| 721 | {ISCSI_ROUTER_STATE_MANUAL, "Manual" }, |
| 722 | {ISCSI_ROUTER_STATE_STALE, "Stale" }, |
| 723 | }; |
| 724 | |
| 725 | char *iscsi_get_router_state_name(enum iscsi_router_state router_state) |
| 726 | { |
| 727 | int i; |
| 728 | char *state = NULL; |
| 729 | |
| 730 | for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) { |
| 731 | if (iscsi_router_state_names[i].value == router_state) { |
| 732 | state = iscsi_router_state_names[i].name; |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | return state; |
| 737 | } |
| 738 | EXPORT_SYMBOL_GPL(iscsi_get_router_state_name); |
| 739 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 740 | struct iscsi_iface * |
| 741 | iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 742 | uint32_t iface_type, uint32_t iface_num, int dd_size) |
| 743 | { |
| 744 | struct iscsi_iface *iface; |
| 745 | int err; |
| 746 | |
| 747 | iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL); |
| 748 | if (!iface) |
| 749 | return NULL; |
| 750 | |
| 751 | iface->transport = transport; |
| 752 | iface->iface_type = iface_type; |
| 753 | iface->iface_num = iface_num; |
| 754 | iface->dev.release = iscsi_iface_release; |
| 755 | iface->dev.class = &iscsi_iface_class; |
| 756 | /* parent reference released in iscsi_iface_release */ |
| 757 | iface->dev.parent = get_device(&shost->shost_gendev); |
| 758 | if (iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 759 | dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no, |
| 760 | iface_num); |
| 761 | else |
| 762 | dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no, |
| 763 | iface_num); |
| 764 | |
| 765 | err = device_register(&iface->dev); |
| 766 | if (err) |
| 767 | goto free_iface; |
| 768 | |
| 769 | err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group); |
| 770 | if (err) |
| 771 | goto unreg_iface; |
| 772 | |
| 773 | if (dd_size) |
| 774 | iface->dd_data = &iface[1]; |
| 775 | return iface; |
| 776 | |
| 777 | unreg_iface: |
| 778 | device_unregister(&iface->dev); |
| 779 | return NULL; |
| 780 | |
| 781 | free_iface: |
| 782 | put_device(iface->dev.parent); |
| 783 | kfree(iface); |
| 784 | return NULL; |
| 785 | } |
| 786 | EXPORT_SYMBOL_GPL(iscsi_create_iface); |
| 787 | |
| 788 | void iscsi_destroy_iface(struct iscsi_iface *iface) |
| 789 | { |
| 790 | sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group); |
| 791 | device_unregister(&iface->dev); |
| 792 | } |
| 793 | EXPORT_SYMBOL_GPL(iscsi_destroy_iface); |
| 794 | |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 795 | /* |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 796 | * Interface to display flash node params to sysfs |
| 797 | */ |
| 798 | |
| 799 | #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \ |
| 800 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 801 | __ATTR(_name, _mode, _show, _store) |
| 802 | |
| 803 | /* flash node session attrs show */ |
| 804 | #define iscsi_flashnode_sess_attr_show(type, name, param) \ |
| 805 | static ssize_t \ |
| 806 | show_##type##_##name(struct device *dev, struct device_attribute *attr, \ |
| 807 | char *buf) \ |
| 808 | { \ |
| 809 | struct iscsi_bus_flash_session *fnode_sess = \ |
| 810 | iscsi_dev_to_flash_session(dev);\ |
| 811 | struct iscsi_transport *t = fnode_sess->transport; \ |
| 812 | return t->get_flashnode_param(fnode_sess, param, buf); \ |
| 813 | } \ |
| 814 | |
| 815 | |
| 816 | #define iscsi_flashnode_sess_attr(type, name, param) \ |
| 817 | iscsi_flashnode_sess_attr_show(type, name, param) \ |
| 818 | static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \ |
| 819 | show_##type##_##name, NULL); |
| 820 | |
| 821 | /* Flash node session attributes */ |
| 822 | |
| 823 | iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable, |
| 824 | ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE); |
| 825 | iscsi_flashnode_sess_attr(fnode, discovery_session, |
| 826 | ISCSI_FLASHNODE_DISCOVERY_SESS); |
| 827 | iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE); |
| 828 | iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN); |
| 829 | iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN); |
| 830 | iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN); |
| 831 | iscsi_flashnode_sess_attr(fnode, data_seq_in_order, |
| 832 | ISCSI_FLASHNODE_DATASEQ_INORDER); |
| 833 | iscsi_flashnode_sess_attr(fnode, data_pdu_in_order, |
| 834 | ISCSI_FLASHNODE_PDU_INORDER); |
| 835 | iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN); |
| 836 | iscsi_flashnode_sess_attr(fnode, discovery_logout, |
| 837 | ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN); |
| 838 | iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN); |
| 839 | iscsi_flashnode_sess_attr(fnode, discovery_auth_optional, |
| 840 | ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL); |
| 841 | iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL); |
| 842 | iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST); |
| 843 | iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT); |
| 844 | iscsi_flashnode_sess_attr(fnode, def_time2retain, |
| 845 | ISCSI_FLASHNODE_DEF_TIME2RETAIN); |
| 846 | iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T); |
| 847 | iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID); |
| 848 | iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID); |
| 849 | iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST); |
| 850 | iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo, |
| 851 | ISCSI_FLASHNODE_DEF_TASKMGMT_TMO); |
| 852 | iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS); |
| 853 | iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME); |
| 854 | iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT); |
| 855 | iscsi_flashnode_sess_attr(fnode, discovery_parent_idx, |
| 856 | ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX); |
| 857 | iscsi_flashnode_sess_attr(fnode, discovery_parent_type, |
| 858 | ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE); |
| 859 | iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX); |
| 860 | iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX); |
| 861 | iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME); |
| 862 | iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN); |
| 863 | iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD); |
| 864 | iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN); |
| 865 | iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT); |
| 866 | |
| 867 | static struct attribute *iscsi_flashnode_sess_attrs[] = { |
| 868 | &dev_attr_fnode_auto_snd_tgt_disable.attr, |
| 869 | &dev_attr_fnode_discovery_session.attr, |
| 870 | &dev_attr_fnode_portal_type.attr, |
| 871 | &dev_attr_fnode_entry_enable.attr, |
| 872 | &dev_attr_fnode_immediate_data.attr, |
| 873 | &dev_attr_fnode_initial_r2t.attr, |
| 874 | &dev_attr_fnode_data_seq_in_order.attr, |
| 875 | &dev_attr_fnode_data_pdu_in_order.attr, |
| 876 | &dev_attr_fnode_chap_auth.attr, |
| 877 | &dev_attr_fnode_discovery_logout.attr, |
| 878 | &dev_attr_fnode_bidi_chap.attr, |
| 879 | &dev_attr_fnode_discovery_auth_optional.attr, |
| 880 | &dev_attr_fnode_erl.attr, |
| 881 | &dev_attr_fnode_first_burst_len.attr, |
| 882 | &dev_attr_fnode_def_time2wait.attr, |
| 883 | &dev_attr_fnode_def_time2retain.attr, |
| 884 | &dev_attr_fnode_max_outstanding_r2t.attr, |
| 885 | &dev_attr_fnode_isid.attr, |
| 886 | &dev_attr_fnode_tsid.attr, |
| 887 | &dev_attr_fnode_max_burst_len.attr, |
| 888 | &dev_attr_fnode_def_taskmgmt_tmo.attr, |
| 889 | &dev_attr_fnode_targetalias.attr, |
| 890 | &dev_attr_fnode_targetname.attr, |
| 891 | &dev_attr_fnode_tpgt.attr, |
| 892 | &dev_attr_fnode_discovery_parent_idx.attr, |
| 893 | &dev_attr_fnode_discovery_parent_type.attr, |
| 894 | &dev_attr_fnode_chap_in_idx.attr, |
| 895 | &dev_attr_fnode_chap_out_idx.attr, |
| 896 | &dev_attr_fnode_username.attr, |
| 897 | &dev_attr_fnode_username_in.attr, |
| 898 | &dev_attr_fnode_password.attr, |
| 899 | &dev_attr_fnode_password_in.attr, |
| 900 | &dev_attr_fnode_is_boot_target.attr, |
| 901 | NULL, |
| 902 | }; |
| 903 | |
| 904 | static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj, |
| 905 | struct attribute *attr, |
| 906 | int i) |
| 907 | { |
| 908 | struct device *dev = container_of(kobj, struct device, kobj); |
| 909 | struct iscsi_bus_flash_session *fnode_sess = |
| 910 | iscsi_dev_to_flash_session(dev); |
| 911 | struct iscsi_transport *t = fnode_sess->transport; |
| 912 | int param; |
| 913 | |
| 914 | if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) { |
| 915 | param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE; |
| 916 | } else if (attr == &dev_attr_fnode_discovery_session.attr) { |
| 917 | param = ISCSI_FLASHNODE_DISCOVERY_SESS; |
| 918 | } else if (attr == &dev_attr_fnode_portal_type.attr) { |
| 919 | param = ISCSI_FLASHNODE_PORTAL_TYPE; |
| 920 | } else if (attr == &dev_attr_fnode_entry_enable.attr) { |
| 921 | param = ISCSI_FLASHNODE_ENTRY_EN; |
| 922 | } else if (attr == &dev_attr_fnode_immediate_data.attr) { |
| 923 | param = ISCSI_FLASHNODE_IMM_DATA_EN; |
| 924 | } else if (attr == &dev_attr_fnode_initial_r2t.attr) { |
| 925 | param = ISCSI_FLASHNODE_INITIAL_R2T_EN; |
| 926 | } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) { |
| 927 | param = ISCSI_FLASHNODE_DATASEQ_INORDER; |
| 928 | } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) { |
| 929 | param = ISCSI_FLASHNODE_PDU_INORDER; |
| 930 | } else if (attr == &dev_attr_fnode_chap_auth.attr) { |
| 931 | param = ISCSI_FLASHNODE_CHAP_AUTH_EN; |
| 932 | } else if (attr == &dev_attr_fnode_discovery_logout.attr) { |
| 933 | param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN; |
| 934 | } else if (attr == &dev_attr_fnode_bidi_chap.attr) { |
| 935 | param = ISCSI_FLASHNODE_BIDI_CHAP_EN; |
| 936 | } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) { |
| 937 | param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL; |
| 938 | } else if (attr == &dev_attr_fnode_erl.attr) { |
| 939 | param = ISCSI_FLASHNODE_ERL; |
| 940 | } else if (attr == &dev_attr_fnode_first_burst_len.attr) { |
| 941 | param = ISCSI_FLASHNODE_FIRST_BURST; |
| 942 | } else if (attr == &dev_attr_fnode_def_time2wait.attr) { |
| 943 | param = ISCSI_FLASHNODE_DEF_TIME2WAIT; |
| 944 | } else if (attr == &dev_attr_fnode_def_time2retain.attr) { |
| 945 | param = ISCSI_FLASHNODE_DEF_TIME2RETAIN; |
| 946 | } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) { |
| 947 | param = ISCSI_FLASHNODE_MAX_R2T; |
| 948 | } else if (attr == &dev_attr_fnode_isid.attr) { |
| 949 | param = ISCSI_FLASHNODE_ISID; |
| 950 | } else if (attr == &dev_attr_fnode_tsid.attr) { |
| 951 | param = ISCSI_FLASHNODE_TSID; |
| 952 | } else if (attr == &dev_attr_fnode_max_burst_len.attr) { |
| 953 | param = ISCSI_FLASHNODE_MAX_BURST; |
| 954 | } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) { |
| 955 | param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO; |
| 956 | } else if (attr == &dev_attr_fnode_targetalias.attr) { |
| 957 | param = ISCSI_FLASHNODE_ALIAS; |
| 958 | } else if (attr == &dev_attr_fnode_targetname.attr) { |
| 959 | param = ISCSI_FLASHNODE_NAME; |
| 960 | } else if (attr == &dev_attr_fnode_tpgt.attr) { |
| 961 | param = ISCSI_FLASHNODE_TPGT; |
| 962 | } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) { |
| 963 | param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX; |
| 964 | } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) { |
| 965 | param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE; |
| 966 | } else if (attr == &dev_attr_fnode_chap_in_idx.attr) { |
| 967 | param = ISCSI_FLASHNODE_CHAP_IN_IDX; |
| 968 | } else if (attr == &dev_attr_fnode_chap_out_idx.attr) { |
| 969 | param = ISCSI_FLASHNODE_CHAP_OUT_IDX; |
| 970 | } else if (attr == &dev_attr_fnode_username.attr) { |
| 971 | param = ISCSI_FLASHNODE_USERNAME; |
| 972 | } else if (attr == &dev_attr_fnode_username_in.attr) { |
| 973 | param = ISCSI_FLASHNODE_USERNAME_IN; |
| 974 | } else if (attr == &dev_attr_fnode_password.attr) { |
| 975 | param = ISCSI_FLASHNODE_PASSWORD; |
| 976 | } else if (attr == &dev_attr_fnode_password_in.attr) { |
| 977 | param = ISCSI_FLASHNODE_PASSWORD_IN; |
| 978 | } else if (attr == &dev_attr_fnode_is_boot_target.attr) { |
| 979 | param = ISCSI_FLASHNODE_IS_BOOT_TGT; |
| 980 | } else { |
| 981 | WARN_ONCE(1, "Invalid flashnode session attr"); |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param); |
| 986 | } |
| 987 | |
| 988 | static struct attribute_group iscsi_flashnode_sess_attr_group = { |
| 989 | .attrs = iscsi_flashnode_sess_attrs, |
| 990 | .is_visible = iscsi_flashnode_sess_attr_is_visible, |
| 991 | }; |
| 992 | |
| 993 | static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = { |
| 994 | &iscsi_flashnode_sess_attr_group, |
| 995 | NULL, |
| 996 | }; |
| 997 | |
| 998 | static void iscsi_flashnode_sess_release(struct device *dev) |
| 999 | { |
| 1000 | struct iscsi_bus_flash_session *fnode_sess = |
| 1001 | iscsi_dev_to_flash_session(dev); |
| 1002 | |
| 1003 | kfree(fnode_sess->targetname); |
| 1004 | kfree(fnode_sess->targetalias); |
| 1005 | kfree(fnode_sess->portal_type); |
| 1006 | kfree(fnode_sess); |
| 1007 | } |
| 1008 | |
Bhumika Goyal | 7988faf | 2017-08-19 13:52:24 +0530 | [diff] [blame] | 1009 | static const struct device_type iscsi_flashnode_sess_dev_type = { |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1010 | .name = "iscsi_flashnode_sess_dev_type", |
| 1011 | .groups = iscsi_flashnode_sess_attr_groups, |
| 1012 | .release = iscsi_flashnode_sess_release, |
| 1013 | }; |
| 1014 | |
| 1015 | /* flash node connection attrs show */ |
| 1016 | #define iscsi_flashnode_conn_attr_show(type, name, param) \ |
| 1017 | static ssize_t \ |
| 1018 | show_##type##_##name(struct device *dev, struct device_attribute *attr, \ |
| 1019 | char *buf) \ |
| 1020 | { \ |
| 1021 | struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\ |
| 1022 | struct iscsi_bus_flash_session *fnode_sess = \ |
| 1023 | iscsi_flash_conn_to_flash_session(fnode_conn);\ |
| 1024 | struct iscsi_transport *t = fnode_conn->transport; \ |
| 1025 | return t->get_flashnode_param(fnode_sess, param, buf); \ |
| 1026 | } \ |
| 1027 | |
| 1028 | |
| 1029 | #define iscsi_flashnode_conn_attr(type, name, param) \ |
| 1030 | iscsi_flashnode_conn_attr_show(type, name, param) \ |
| 1031 | static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \ |
| 1032 | show_##type##_##name, NULL); |
| 1033 | |
| 1034 | /* Flash node connection attributes */ |
| 1035 | |
| 1036 | iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6, |
| 1037 | ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6); |
| 1038 | iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN); |
| 1039 | iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN); |
| 1040 | iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN); |
| 1041 | iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat, |
| 1042 | ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT); |
| 1043 | iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable, |
| 1044 | ISCSI_FLASHNODE_TCP_NAGLE_DISABLE); |
| 1045 | iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable, |
| 1046 | ISCSI_FLASHNODE_TCP_WSF_DISABLE); |
| 1047 | iscsi_flashnode_conn_attr(fnode, tcp_timer_scale, |
| 1048 | ISCSI_FLASHNODE_TCP_TIMER_SCALE); |
| 1049 | iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable, |
| 1050 | ISCSI_FLASHNODE_TCP_TIMESTAMP_EN); |
| 1051 | iscsi_flashnode_conn_attr(fnode, fragment_disable, |
| 1052 | ISCSI_FLASHNODE_IP_FRAG_DISABLE); |
| 1053 | iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO); |
| 1054 | iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT); |
| 1055 | iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR); |
| 1056 | iscsi_flashnode_conn_attr(fnode, max_recv_dlength, |
| 1057 | ISCSI_FLASHNODE_MAX_RECV_DLENGTH); |
| 1058 | iscsi_flashnode_conn_attr(fnode, max_xmit_dlength, |
| 1059 | ISCSI_FLASHNODE_MAX_XMIT_DLENGTH); |
| 1060 | iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT); |
| 1061 | iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS); |
| 1062 | iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC); |
| 1063 | iscsi_flashnode_conn_attr(fnode, ipv6_flow_label, |
| 1064 | ISCSI_FLASHNODE_IPV6_FLOW_LABEL); |
| 1065 | iscsi_flashnode_conn_attr(fnode, redirect_ipaddr, |
| 1066 | ISCSI_FLASHNODE_REDIRECT_IPADDR); |
| 1067 | iscsi_flashnode_conn_attr(fnode, max_segment_size, |
| 1068 | ISCSI_FLASHNODE_MAX_SEGMENT_SIZE); |
| 1069 | iscsi_flashnode_conn_attr(fnode, link_local_ipv6, |
| 1070 | ISCSI_FLASHNODE_LINK_LOCAL_IPV6); |
| 1071 | iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF); |
| 1072 | iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF); |
| 1073 | iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN); |
| 1074 | iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN); |
| 1075 | |
| 1076 | static struct attribute *iscsi_flashnode_conn_attrs[] = { |
| 1077 | &dev_attr_fnode_is_fw_assigned_ipv6.attr, |
| 1078 | &dev_attr_fnode_header_digest.attr, |
| 1079 | &dev_attr_fnode_data_digest.attr, |
| 1080 | &dev_attr_fnode_snack_req.attr, |
| 1081 | &dev_attr_fnode_tcp_timestamp_stat.attr, |
| 1082 | &dev_attr_fnode_tcp_nagle_disable.attr, |
| 1083 | &dev_attr_fnode_tcp_wsf_disable.attr, |
| 1084 | &dev_attr_fnode_tcp_timer_scale.attr, |
| 1085 | &dev_attr_fnode_tcp_timestamp_enable.attr, |
| 1086 | &dev_attr_fnode_fragment_disable.attr, |
| 1087 | &dev_attr_fnode_max_recv_dlength.attr, |
| 1088 | &dev_attr_fnode_max_xmit_dlength.attr, |
| 1089 | &dev_attr_fnode_keepalive_tmo.attr, |
| 1090 | &dev_attr_fnode_port.attr, |
| 1091 | &dev_attr_fnode_ipaddress.attr, |
| 1092 | &dev_attr_fnode_redirect_ipaddr.attr, |
| 1093 | &dev_attr_fnode_max_segment_size.attr, |
| 1094 | &dev_attr_fnode_local_port.attr, |
| 1095 | &dev_attr_fnode_ipv4_tos.attr, |
| 1096 | &dev_attr_fnode_ipv6_traffic_class.attr, |
| 1097 | &dev_attr_fnode_ipv6_flow_label.attr, |
| 1098 | &dev_attr_fnode_link_local_ipv6.attr, |
| 1099 | &dev_attr_fnode_tcp_xmit_wsf.attr, |
| 1100 | &dev_attr_fnode_tcp_recv_wsf.attr, |
| 1101 | &dev_attr_fnode_statsn.attr, |
| 1102 | &dev_attr_fnode_exp_statsn.attr, |
| 1103 | NULL, |
| 1104 | }; |
| 1105 | |
| 1106 | static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj, |
| 1107 | struct attribute *attr, |
| 1108 | int i) |
| 1109 | { |
| 1110 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1111 | struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 1112 | struct iscsi_transport *t = fnode_conn->transport; |
| 1113 | int param; |
| 1114 | |
| 1115 | if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) { |
| 1116 | param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6; |
| 1117 | } else if (attr == &dev_attr_fnode_header_digest.attr) { |
| 1118 | param = ISCSI_FLASHNODE_HDR_DGST_EN; |
| 1119 | } else if (attr == &dev_attr_fnode_data_digest.attr) { |
| 1120 | param = ISCSI_FLASHNODE_DATA_DGST_EN; |
| 1121 | } else if (attr == &dev_attr_fnode_snack_req.attr) { |
| 1122 | param = ISCSI_FLASHNODE_SNACK_REQ_EN; |
| 1123 | } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) { |
| 1124 | param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT; |
| 1125 | } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) { |
| 1126 | param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE; |
| 1127 | } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) { |
| 1128 | param = ISCSI_FLASHNODE_TCP_WSF_DISABLE; |
| 1129 | } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) { |
| 1130 | param = ISCSI_FLASHNODE_TCP_TIMER_SCALE; |
| 1131 | } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) { |
| 1132 | param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN; |
| 1133 | } else if (attr == &dev_attr_fnode_fragment_disable.attr) { |
| 1134 | param = ISCSI_FLASHNODE_IP_FRAG_DISABLE; |
| 1135 | } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) { |
| 1136 | param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH; |
| 1137 | } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) { |
| 1138 | param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH; |
| 1139 | } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) { |
| 1140 | param = ISCSI_FLASHNODE_KEEPALIVE_TMO; |
| 1141 | } else if (attr == &dev_attr_fnode_port.attr) { |
| 1142 | param = ISCSI_FLASHNODE_PORT; |
| 1143 | } else if (attr == &dev_attr_fnode_ipaddress.attr) { |
| 1144 | param = ISCSI_FLASHNODE_IPADDR; |
| 1145 | } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) { |
| 1146 | param = ISCSI_FLASHNODE_REDIRECT_IPADDR; |
| 1147 | } else if (attr == &dev_attr_fnode_max_segment_size.attr) { |
| 1148 | param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE; |
| 1149 | } else if (attr == &dev_attr_fnode_local_port.attr) { |
| 1150 | param = ISCSI_FLASHNODE_LOCAL_PORT; |
| 1151 | } else if (attr == &dev_attr_fnode_ipv4_tos.attr) { |
| 1152 | param = ISCSI_FLASHNODE_IPV4_TOS; |
| 1153 | } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) { |
| 1154 | param = ISCSI_FLASHNODE_IPV6_TC; |
| 1155 | } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) { |
| 1156 | param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL; |
| 1157 | } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) { |
| 1158 | param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6; |
| 1159 | } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) { |
| 1160 | param = ISCSI_FLASHNODE_TCP_XMIT_WSF; |
| 1161 | } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) { |
| 1162 | param = ISCSI_FLASHNODE_TCP_RECV_WSF; |
| 1163 | } else if (attr == &dev_attr_fnode_statsn.attr) { |
| 1164 | param = ISCSI_FLASHNODE_STATSN; |
| 1165 | } else if (attr == &dev_attr_fnode_exp_statsn.attr) { |
| 1166 | param = ISCSI_FLASHNODE_EXP_STATSN; |
| 1167 | } else { |
| 1168 | WARN_ONCE(1, "Invalid flashnode connection attr"); |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param); |
| 1173 | } |
| 1174 | |
| 1175 | static struct attribute_group iscsi_flashnode_conn_attr_group = { |
| 1176 | .attrs = iscsi_flashnode_conn_attrs, |
| 1177 | .is_visible = iscsi_flashnode_conn_attr_is_visible, |
| 1178 | }; |
| 1179 | |
| 1180 | static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = { |
| 1181 | &iscsi_flashnode_conn_attr_group, |
| 1182 | NULL, |
| 1183 | }; |
| 1184 | |
| 1185 | static void iscsi_flashnode_conn_release(struct device *dev) |
| 1186 | { |
| 1187 | struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 1188 | |
| 1189 | kfree(fnode_conn->ipaddress); |
| 1190 | kfree(fnode_conn->redirect_ipaddr); |
| 1191 | kfree(fnode_conn->link_local_ipv6_addr); |
| 1192 | kfree(fnode_conn); |
| 1193 | } |
| 1194 | |
Bhumika Goyal | 7988faf | 2017-08-19 13:52:24 +0530 | [diff] [blame] | 1195 | static const struct device_type iscsi_flashnode_conn_dev_type = { |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1196 | .name = "iscsi_flashnode_conn_dev_type", |
| 1197 | .groups = iscsi_flashnode_conn_attr_groups, |
| 1198 | .release = iscsi_flashnode_conn_release, |
| 1199 | }; |
| 1200 | |
Bart Van Assche | 4c1340a | 2016-03-30 11:28:11 -0700 | [diff] [blame] | 1201 | static struct bus_type iscsi_flashnode_bus; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1202 | |
| 1203 | int iscsi_flashnode_bus_match(struct device *dev, |
| 1204 | struct device_driver *drv) |
| 1205 | { |
| 1206 | if (dev->bus == &iscsi_flashnode_bus) |
| 1207 | return 1; |
| 1208 | return 0; |
| 1209 | } |
| 1210 | EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match); |
| 1211 | |
Bart Van Assche | 4c1340a | 2016-03-30 11:28:11 -0700 | [diff] [blame] | 1212 | static struct bus_type iscsi_flashnode_bus = { |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1213 | .name = "iscsi_flashnode", |
| 1214 | .match = &iscsi_flashnode_bus_match, |
| 1215 | }; |
| 1216 | |
| 1217 | /** |
| 1218 | * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs |
| 1219 | * @shost: pointer to host data |
| 1220 | * @index: index of flashnode to add in sysfs |
| 1221 | * @transport: pointer to transport data |
| 1222 | * @dd_size: total size to allocate |
| 1223 | * |
| 1224 | * Adds a sysfs entry for the flashnode session attributes |
| 1225 | * |
| 1226 | * Returns: |
Masanari Iida | e227867 | 2014-02-18 22:54:36 +0900 | [diff] [blame] | 1227 | * pointer to allocated flashnode sess on success |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1228 | * %NULL on failure |
| 1229 | */ |
| 1230 | struct iscsi_bus_flash_session * |
| 1231 | iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index, |
| 1232 | struct iscsi_transport *transport, |
| 1233 | int dd_size) |
| 1234 | { |
| 1235 | struct iscsi_bus_flash_session *fnode_sess; |
| 1236 | int err; |
| 1237 | |
| 1238 | fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL); |
| 1239 | if (!fnode_sess) |
| 1240 | return NULL; |
| 1241 | |
| 1242 | fnode_sess->transport = transport; |
| 1243 | fnode_sess->target_id = index; |
| 1244 | fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type; |
| 1245 | fnode_sess->dev.bus = &iscsi_flashnode_bus; |
| 1246 | fnode_sess->dev.parent = &shost->shost_gendev; |
| 1247 | dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u", |
| 1248 | shost->host_no, index); |
| 1249 | |
| 1250 | err = device_register(&fnode_sess->dev); |
| 1251 | if (err) |
| 1252 | goto free_fnode_sess; |
| 1253 | |
| 1254 | if (dd_size) |
| 1255 | fnode_sess->dd_data = &fnode_sess[1]; |
| 1256 | |
| 1257 | return fnode_sess; |
| 1258 | |
| 1259 | free_fnode_sess: |
| 1260 | kfree(fnode_sess); |
| 1261 | return NULL; |
| 1262 | } |
| 1263 | EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess); |
| 1264 | |
| 1265 | /** |
| 1266 | * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs |
| 1267 | * @shost: pointer to host data |
| 1268 | * @fnode_sess: pointer to the parent flashnode session entry |
| 1269 | * @transport: pointer to transport data |
| 1270 | * @dd_size: total size to allocate |
| 1271 | * |
| 1272 | * Adds a sysfs entry for the flashnode connection attributes |
| 1273 | * |
| 1274 | * Returns: |
| 1275 | * pointer to allocated flashnode conn on success |
| 1276 | * %NULL on failure |
| 1277 | */ |
| 1278 | struct iscsi_bus_flash_conn * |
| 1279 | iscsi_create_flashnode_conn(struct Scsi_Host *shost, |
| 1280 | struct iscsi_bus_flash_session *fnode_sess, |
| 1281 | struct iscsi_transport *transport, |
| 1282 | int dd_size) |
| 1283 | { |
| 1284 | struct iscsi_bus_flash_conn *fnode_conn; |
| 1285 | int err; |
| 1286 | |
| 1287 | fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL); |
| 1288 | if (!fnode_conn) |
| 1289 | return NULL; |
| 1290 | |
| 1291 | fnode_conn->transport = transport; |
| 1292 | fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type; |
| 1293 | fnode_conn->dev.bus = &iscsi_flashnode_bus; |
| 1294 | fnode_conn->dev.parent = &fnode_sess->dev; |
| 1295 | dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0", |
| 1296 | shost->host_no, fnode_sess->target_id); |
| 1297 | |
| 1298 | err = device_register(&fnode_conn->dev); |
| 1299 | if (err) |
| 1300 | goto free_fnode_conn; |
| 1301 | |
| 1302 | if (dd_size) |
| 1303 | fnode_conn->dd_data = &fnode_conn[1]; |
| 1304 | |
| 1305 | return fnode_conn; |
| 1306 | |
| 1307 | free_fnode_conn: |
| 1308 | kfree(fnode_conn); |
| 1309 | return NULL; |
| 1310 | } |
| 1311 | EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn); |
| 1312 | |
| 1313 | /** |
| 1314 | * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn |
| 1315 | * @dev: device to verify |
| 1316 | * @data: pointer to data containing value to use for verification |
| 1317 | * |
| 1318 | * Verifies if the passed device is flashnode conn device |
| 1319 | * |
| 1320 | * Returns: |
| 1321 | * 1 on success |
| 1322 | * 0 on failure |
| 1323 | */ |
Bart Van Assche | 7a15fdf | 2016-03-30 11:27:47 -0700 | [diff] [blame] | 1324 | static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data) |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1325 | { |
| 1326 | return dev->bus == &iscsi_flashnode_bus; |
| 1327 | } |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1328 | |
| 1329 | static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn) |
| 1330 | { |
| 1331 | device_unregister(&fnode_conn->dev); |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | static int flashnode_match_index(struct device *dev, void *data) |
| 1336 | { |
| 1337 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 1338 | int ret = 0; |
| 1339 | |
| 1340 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 1341 | goto exit_match_index; |
| 1342 | |
| 1343 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 1344 | ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0; |
| 1345 | |
| 1346 | exit_match_index: |
| 1347 | return ret; |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * iscsi_get_flashnode_by_index -finds flashnode session entry by index |
| 1352 | * @shost: pointer to host data |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1353 | * @idx: index to match |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1354 | * |
| 1355 | * Finds the flashnode session object for the passed index |
| 1356 | * |
| 1357 | * Returns: |
| 1358 | * pointer to found flashnode session object on success |
| 1359 | * %NULL on failure |
| 1360 | */ |
| 1361 | static struct iscsi_bus_flash_session * |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1362 | iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx) |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1363 | { |
| 1364 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 1365 | struct device *dev; |
| 1366 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1367 | dev = device_find_child(&shost->shost_gendev, &idx, |
| 1368 | flashnode_match_index); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1369 | if (dev) |
| 1370 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 1371 | |
| 1372 | return fnode_sess; |
| 1373 | } |
| 1374 | |
| 1375 | /** |
| 1376 | * iscsi_find_flashnode_sess - finds flashnode session entry |
| 1377 | * @shost: pointer to host data |
| 1378 | * @data: pointer to data containing value to use for comparison |
| 1379 | * @fn: function pointer that does actual comparison |
| 1380 | * |
| 1381 | * Finds the flashnode session object comparing the data passed using logic |
| 1382 | * defined in passed function pointer |
| 1383 | * |
| 1384 | * Returns: |
| 1385 | * pointer to found flashnode session device object on success |
| 1386 | * %NULL on failure |
| 1387 | */ |
| 1388 | struct device * |
| 1389 | iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data, |
| 1390 | int (*fn)(struct device *dev, void *data)) |
| 1391 | { |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1392 | return device_find_child(&shost->shost_gendev, data, fn); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1393 | } |
| 1394 | EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess); |
| 1395 | |
| 1396 | /** |
| 1397 | * iscsi_find_flashnode_conn - finds flashnode connection entry |
| 1398 | * @fnode_sess: pointer to parent flashnode session entry |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1399 | * |
| 1400 | * Finds the flashnode connection object comparing the data passed using logic |
| 1401 | * defined in passed function pointer |
| 1402 | * |
| 1403 | * Returns: |
| 1404 | * pointer to found flashnode connection device object on success |
| 1405 | * %NULL on failure |
| 1406 | */ |
| 1407 | struct device * |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1408 | iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess) |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1409 | { |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 1410 | return device_find_child(&fnode_sess->dev, NULL, |
| 1411 | iscsi_is_flashnode_conn_dev); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1412 | } |
| 1413 | EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn); |
| 1414 | |
| 1415 | static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data) |
| 1416 | { |
| 1417 | if (!iscsi_is_flashnode_conn_dev(dev, NULL)) |
| 1418 | return 0; |
| 1419 | |
| 1420 | return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev)); |
| 1421 | } |
| 1422 | |
| 1423 | /** |
Masanari Iida | e227867 | 2014-02-18 22:54:36 +0900 | [diff] [blame] | 1424 | * iscsi_destroy_flashnode_sess - destroy flashnode session entry |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1425 | * @fnode_sess: pointer to flashnode session entry to be destroyed |
| 1426 | * |
| 1427 | * Deletes the flashnode session entry and all children flashnode connection |
| 1428 | * entries from sysfs |
| 1429 | */ |
| 1430 | void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess) |
| 1431 | { |
| 1432 | int err; |
| 1433 | |
| 1434 | err = device_for_each_child(&fnode_sess->dev, NULL, |
| 1435 | iscsi_iter_destroy_flashnode_conn_fn); |
| 1436 | if (err) |
| 1437 | pr_err("Could not delete all connections for %s. Error %d.\n", |
| 1438 | fnode_sess->dev.kobj.name, err); |
| 1439 | |
| 1440 | device_unregister(&fnode_sess->dev); |
| 1441 | } |
| 1442 | EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess); |
| 1443 | |
| 1444 | static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data) |
| 1445 | { |
| 1446 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 1447 | return 0; |
| 1448 | |
| 1449 | iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev)); |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | /** |
Masanari Iida | e227867 | 2014-02-18 22:54:36 +0900 | [diff] [blame] | 1454 | * iscsi_destroy_all_flashnode - destroy all flashnode session entries |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 1455 | * @shost: pointer to host data |
| 1456 | * |
| 1457 | * Destroys all the flashnode session entries and all corresponding children |
| 1458 | * flashnode connection entries from sysfs |
| 1459 | */ |
| 1460 | void iscsi_destroy_all_flashnode(struct Scsi_Host *shost) |
| 1461 | { |
| 1462 | device_for_each_child(&shost->shost_gendev, NULL, |
| 1463 | iscsi_iter_destroy_flashnode_fn); |
| 1464 | } |
| 1465 | EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode); |
| 1466 | |
| 1467 | /* |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1468 | * BSG support |
| 1469 | */ |
| 1470 | /** |
| 1471 | * iscsi_bsg_host_dispatch - Dispatch command to LLD. |
| 1472 | * @job: bsg job to be processed |
| 1473 | */ |
| 1474 | static int iscsi_bsg_host_dispatch(struct bsg_job *job) |
| 1475 | { |
| 1476 | struct Scsi_Host *shost = iscsi_job_to_shost(job); |
| 1477 | struct iscsi_bsg_request *req = job->request; |
| 1478 | struct iscsi_bsg_reply *reply = job->reply; |
| 1479 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 1480 | int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ |
| 1481 | int ret; |
| 1482 | |
| 1483 | /* check if we have the msgcode value at least */ |
| 1484 | if (job->request_len < sizeof(uint32_t)) { |
| 1485 | ret = -ENOMSG; |
| 1486 | goto fail_host_msg; |
| 1487 | } |
| 1488 | |
| 1489 | /* Validate the host command */ |
| 1490 | switch (req->msgcode) { |
| 1491 | case ISCSI_BSG_HST_VENDOR: |
| 1492 | cmdlen += sizeof(struct iscsi_bsg_host_vendor); |
| 1493 | if ((shost->hostt->vendor_id == 0L) || |
| 1494 | (req->rqst_data.h_vendor.vendor_id != |
| 1495 | shost->hostt->vendor_id)) { |
| 1496 | ret = -ESRCH; |
| 1497 | goto fail_host_msg; |
| 1498 | } |
| 1499 | break; |
| 1500 | default: |
| 1501 | ret = -EBADR; |
| 1502 | goto fail_host_msg; |
| 1503 | } |
| 1504 | |
| 1505 | /* check if we really have all the request data needed */ |
| 1506 | if (job->request_len < cmdlen) { |
| 1507 | ret = -ENOMSG; |
| 1508 | goto fail_host_msg; |
| 1509 | } |
| 1510 | |
| 1511 | ret = i->iscsi_transport->bsg_request(job); |
| 1512 | if (!ret) |
| 1513 | return 0; |
| 1514 | |
| 1515 | fail_host_msg: |
| 1516 | /* return the errno failure code as the only status */ |
| 1517 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 1518 | reply->reply_payload_rcv_len = 0; |
| 1519 | reply->result = ret; |
| 1520 | job->reply_len = sizeof(uint32_t); |
| 1521 | bsg_job_done(job, ret, 0); |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | /** |
| 1526 | * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests |
| 1527 | * @shost: shost for iscsi_host |
Marcos Paulo de Souza | eae627e | 2011-11-02 11:17:17 -0200 | [diff] [blame] | 1528 | * @ihost: iscsi_cls_host adding the structures to |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1529 | */ |
| 1530 | static int |
| 1531 | iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) |
| 1532 | { |
| 1533 | struct device *dev = &shost->shost_gendev; |
| 1534 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 1535 | struct request_queue *q; |
| 1536 | char bsg_name[20]; |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1537 | |
| 1538 | if (!i->iscsi_transport->bsg_request) |
| 1539 | return -ENOTSUPP; |
| 1540 | |
| 1541 | snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no); |
Jens Axboe | aae3b06 | 2018-10-26 11:26:25 -0600 | [diff] [blame] | 1542 | q = bsg_setup_queue(dev, bsg_name, iscsi_bsg_host_dispatch, NULL, 0); |
Christoph Hellwig | 8ae94eb | 2017-01-03 15:25:02 +0300 | [diff] [blame] | 1543 | if (IS_ERR(q)) { |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1544 | shost_printk(KERN_ERR, shost, "bsg interface failed to " |
| 1545 | "initialize - no request queue\n"); |
Christoph Hellwig | 8ae94eb | 2017-01-03 15:25:02 +0300 | [diff] [blame] | 1546 | return PTR_ERR(q); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1547 | } |
Christoph Hellwig | 8ae94eb | 2017-01-03 15:25:02 +0300 | [diff] [blame] | 1548 | __scsi_init_queue(shost, q); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1549 | |
| 1550 | ihost->bsg_q = q; |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1554 | static int iscsi_setup_host(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1555 | struct device *cdev) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1556 | { |
| 1557 | struct Scsi_Host *shost = dev_to_shost(dev); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1558 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1559 | |
| 1560 | memset(ihost, 0, sizeof(*ihost)); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1561 | atomic_set(&ihost->nr_scans, 0); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1562 | mutex_init(&ihost->mutex); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1563 | |
| 1564 | iscsi_bsg_host_add(shost, ihost); |
| 1565 | /* ignore any bsg add error - we just can't do sgio */ |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | static int iscsi_remove_host(struct transport_container *tc, |
| 1571 | struct device *dev, struct device *cdev) |
| 1572 | { |
| 1573 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 1574 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 1575 | |
Jens Axboe | 5e28b8d | 2018-10-26 11:27:02 -0600 | [diff] [blame] | 1576 | bsg_remove_queue(ihost->bsg_q); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | static DECLARE_TRANSPORT_CLASS(iscsi_host_class, |
| 1581 | "iscsi_host", |
| 1582 | iscsi_setup_host, |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 1583 | iscsi_remove_host, |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1584 | NULL); |
| 1585 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1586 | static DECLARE_TRANSPORT_CLASS(iscsi_session_class, |
| 1587 | "iscsi_session", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | NULL, |
| 1589 | NULL, |
| 1590 | NULL); |
| 1591 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1592 | static DECLARE_TRANSPORT_CLASS(iscsi_connection_class, |
| 1593 | "iscsi_connection", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | NULL, |
| 1595 | NULL, |
| 1596 | NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1597 | |
| 1598 | static struct sock *nls; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 1599 | static DEFINE_MUTEX(rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1600 | |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 1601 | /* |
| 1602 | * conn_mutex protects the {start,bind,stop,destroy}_conn from racing |
| 1603 | * against the kernel stop_connection recovery mechanism |
| 1604 | */ |
| 1605 | static DEFINE_MUTEX(conn_mutex); |
| 1606 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1607 | static LIST_HEAD(sesslist); |
| 1608 | static DEFINE_SPINLOCK(sesslock); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1609 | static LIST_HEAD(connlist); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 1610 | static LIST_HEAD(connlist_err); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1611 | static DEFINE_SPINLOCK(connlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1613 | static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn) |
| 1614 | { |
| 1615 | struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent); |
| 1616 | return sess->sid; |
| 1617 | } |
| 1618 | |
| 1619 | /* |
| 1620 | * Returns the matching session to a given sid |
| 1621 | */ |
| 1622 | static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1623 | { |
| 1624 | unsigned long flags; |
| 1625 | struct iscsi_cls_session *sess; |
| 1626 | |
| 1627 | spin_lock_irqsave(&sesslock, flags); |
| 1628 | list_for_each_entry(sess, &sesslist, sess_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1629 | if (sess->sid == sid) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1630 | spin_unlock_irqrestore(&sesslock, flags); |
| 1631 | return sess; |
| 1632 | } |
| 1633 | } |
| 1634 | spin_unlock_irqrestore(&sesslock, flags); |
| 1635 | return NULL; |
| 1636 | } |
| 1637 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1638 | /* |
| 1639 | * Returns the matching connection to a given sid / cid tuple |
| 1640 | */ |
| 1641 | static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1642 | { |
| 1643 | unsigned long flags; |
| 1644 | struct iscsi_cls_conn *conn; |
| 1645 | |
| 1646 | spin_lock_irqsave(&connlock, flags); |
| 1647 | list_for_each_entry(conn, &connlist, conn_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1648 | if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1649 | spin_unlock_irqrestore(&connlock, flags); |
| 1650 | return conn; |
| 1651 | } |
| 1652 | } |
| 1653 | spin_unlock_irqrestore(&connlock, flags); |
| 1654 | return NULL; |
| 1655 | } |
| 1656 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1657 | /* |
| 1658 | * The following functions can be used by LLDs that allocate |
| 1659 | * their own scsi_hosts or by software iscsi LLDs |
| 1660 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1661 | static struct { |
| 1662 | int value; |
| 1663 | char *name; |
| 1664 | } iscsi_session_state_names[] = { |
| 1665 | { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" }, |
| 1666 | { ISCSI_SESSION_FAILED, "FAILED" }, |
| 1667 | { ISCSI_SESSION_FREE, "FREE" }, |
| 1668 | }; |
| 1669 | |
Adrian Bunk | 3b0f208 | 2008-02-13 23:30:17 +0200 | [diff] [blame] | 1670 | static const char *iscsi_session_state_name(int state) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1671 | { |
| 1672 | int i; |
| 1673 | char *name = NULL; |
| 1674 | |
| 1675 | for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) { |
| 1676 | if (iscsi_session_state_names[i].value == state) { |
| 1677 | name = iscsi_session_state_names[i].name; |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | return name; |
| 1682 | } |
| 1683 | |
| 1684 | int iscsi_session_chkready(struct iscsi_cls_session *session) |
| 1685 | { |
| 1686 | unsigned long flags; |
| 1687 | int err; |
| 1688 | |
| 1689 | spin_lock_irqsave(&session->lock, flags); |
| 1690 | switch (session->state) { |
| 1691 | case ISCSI_SESSION_LOGGED_IN: |
| 1692 | err = 0; |
| 1693 | break; |
| 1694 | case ISCSI_SESSION_FAILED: |
Andrew Vasquez | 9a1a69a1 | 2009-04-29 13:12:39 -0500 | [diff] [blame] | 1695 | err = DID_IMM_RETRY << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1696 | break; |
| 1697 | case ISCSI_SESSION_FREE: |
Mike Christie | 56d7fcf | 2008-08-19 18:45:26 -0500 | [diff] [blame] | 1698 | err = DID_TRANSPORT_FAILFAST << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1699 | break; |
| 1700 | default: |
| 1701 | err = DID_NO_CONNECT << 16; |
| 1702 | break; |
| 1703 | } |
| 1704 | spin_unlock_irqrestore(&session->lock, flags); |
| 1705 | return err; |
| 1706 | } |
| 1707 | EXPORT_SYMBOL_GPL(iscsi_session_chkready); |
| 1708 | |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 1709 | int iscsi_is_session_online(struct iscsi_cls_session *session) |
| 1710 | { |
| 1711 | unsigned long flags; |
| 1712 | int ret = 0; |
| 1713 | |
| 1714 | spin_lock_irqsave(&session->lock, flags); |
| 1715 | if (session->state == ISCSI_SESSION_LOGGED_IN) |
| 1716 | ret = 1; |
| 1717 | spin_unlock_irqrestore(&session->lock, flags); |
| 1718 | return ret; |
| 1719 | } |
| 1720 | EXPORT_SYMBOL_GPL(iscsi_is_session_online); |
| 1721 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1722 | static void iscsi_session_release(struct device *dev) |
| 1723 | { |
| 1724 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1725 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1727 | shost = iscsi_session_to_shost(session); |
| 1728 | scsi_host_put(shost); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1729 | ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1730 | kfree(session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1731 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 1733 | int iscsi_is_session_dev(const struct device *dev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1734 | { |
| 1735 | return dev->release == iscsi_session_release; |
| 1736 | } |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 1737 | EXPORT_SYMBOL_GPL(iscsi_is_session_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 1739 | static int iscsi_iter_session_fn(struct device *dev, void *data) |
| 1740 | { |
| 1741 | void (* fn) (struct iscsi_cls_session *) = data; |
| 1742 | |
| 1743 | if (!iscsi_is_session_dev(dev)) |
| 1744 | return 0; |
| 1745 | fn(iscsi_dev_to_session(dev)); |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | void iscsi_host_for_each_session(struct Scsi_Host *shost, |
| 1750 | void (*fn)(struct iscsi_cls_session *)) |
| 1751 | { |
| 1752 | device_for_each_child(&shost->shost_gendev, fn, |
| 1753 | iscsi_iter_session_fn); |
| 1754 | } |
| 1755 | EXPORT_SYMBOL_GPL(iscsi_host_for_each_session); |
| 1756 | |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1757 | /** |
| 1758 | * iscsi_scan_finished - helper to report when running scans are done |
| 1759 | * @shost: scsi host |
| 1760 | * @time: scan run time |
| 1761 | * |
| 1762 | * This function can be used by drives like qla4xxx to report to the scsi |
| 1763 | * layer when the scans it kicked off at module load time are done. |
| 1764 | */ |
| 1765 | int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 1766 | { |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1767 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1768 | /* |
| 1769 | * qla4xxx will have kicked off some session unblocks before calling |
| 1770 | * scsi_scan_host, so just wait for them to complete. |
| 1771 | */ |
| 1772 | return !atomic_read(&ihost->nr_scans); |
| 1773 | } |
| 1774 | EXPORT_SYMBOL_GPL(iscsi_scan_finished); |
| 1775 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1776 | struct iscsi_scan_data { |
| 1777 | unsigned int channel; |
| 1778 | unsigned int id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1779 | u64 lun; |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1780 | enum scsi_scan_mode rescan; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1781 | }; |
| 1782 | |
| 1783 | static int iscsi_user_scan_session(struct device *dev, void *data) |
| 1784 | { |
| 1785 | struct iscsi_scan_data *scan_data = data; |
| 1786 | struct iscsi_cls_session *session; |
| 1787 | struct Scsi_Host *shost; |
| 1788 | struct iscsi_cls_host *ihost; |
| 1789 | unsigned long flags; |
| 1790 | unsigned int id; |
| 1791 | |
| 1792 | if (!iscsi_is_session_dev(dev)) |
| 1793 | return 0; |
| 1794 | |
| 1795 | session = iscsi_dev_to_session(dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1796 | |
| 1797 | ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n"); |
| 1798 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1799 | shost = iscsi_session_to_shost(session); |
| 1800 | ihost = shost->shost_data; |
| 1801 | |
| 1802 | mutex_lock(&ihost->mutex); |
| 1803 | spin_lock_irqsave(&session->lock, flags); |
| 1804 | if (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 1805 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1806 | goto user_scan_exit; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1807 | } |
| 1808 | id = session->target_id; |
| 1809 | spin_unlock_irqrestore(&session->lock, flags); |
| 1810 | |
| 1811 | if (id != ISCSI_MAX_TARGET) { |
| 1812 | if ((scan_data->channel == SCAN_WILD_CARD || |
| 1813 | scan_data->channel == 0) && |
| 1814 | (scan_data->id == SCAN_WILD_CARD || |
| 1815 | scan_data->id == id)) |
| 1816 | scsi_scan_target(&session->dev, 0, id, |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1817 | scan_data->lun, scan_data->rescan); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1818 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1819 | |
| 1820 | user_scan_exit: |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1821 | mutex_unlock(&ihost->mutex); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1822 | ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n"); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1823 | return 0; |
| 1824 | } |
| 1825 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1826 | static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1827 | uint id, u64 lun) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1828 | { |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1829 | struct iscsi_scan_data scan_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1830 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1831 | scan_data.channel = channel; |
| 1832 | scan_data.id = id; |
| 1833 | scan_data.lun = lun; |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1834 | scan_data.rescan = SCSI_SCAN_MANUAL; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1835 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1836 | return device_for_each_child(&shost->shost_gendev, &scan_data, |
| 1837 | iscsi_user_scan_session); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1838 | } |
| 1839 | |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1840 | static void iscsi_scan_session(struct work_struct *work) |
| 1841 | { |
| 1842 | struct iscsi_cls_session *session = |
| 1843 | container_of(work, struct iscsi_cls_session, scan_work); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1844 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1845 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1846 | struct iscsi_scan_data scan_data; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1847 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1848 | scan_data.channel = 0; |
| 1849 | scan_data.id = SCAN_WILD_CARD; |
| 1850 | scan_data.lun = SCAN_WILD_CARD; |
Hannes Reinecke | 1d64508 | 2016-03-17 08:39:45 +0100 | [diff] [blame] | 1851 | scan_data.rescan = SCSI_SCAN_RESCAN; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1852 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1853 | iscsi_user_scan_session(&session->dev, &scan_data); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1854 | atomic_dec(&ihost->nr_scans); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1855 | } |
| 1856 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 1857 | /** |
| 1858 | * iscsi_block_scsi_eh - block scsi eh until session state has transistioned |
Randy Dunlap | e6d4ef4 | 2010-08-14 13:05:41 -0700 | [diff] [blame] | 1859 | * @cmd: scsi cmd passed to scsi eh handler |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 1860 | * |
| 1861 | * If the session is down this function will wait for the recovery |
| 1862 | * timer to fire or for the session to be logged back in. If the |
| 1863 | * recovery timer fires then FAST_IO_FAIL is returned. The caller |
| 1864 | * should pass this error value to the scsi eh. |
| 1865 | */ |
| 1866 | int iscsi_block_scsi_eh(struct scsi_cmnd *cmd) |
| 1867 | { |
| 1868 | struct iscsi_cls_session *session = |
| 1869 | starget_to_session(scsi_target(cmd->device)); |
| 1870 | unsigned long flags; |
| 1871 | int ret = 0; |
| 1872 | |
| 1873 | spin_lock_irqsave(&session->lock, flags); |
| 1874 | while (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 1875 | if (session->state == ISCSI_SESSION_FREE) { |
| 1876 | ret = FAST_IO_FAIL; |
| 1877 | break; |
| 1878 | } |
| 1879 | spin_unlock_irqrestore(&session->lock, flags); |
| 1880 | msleep(1000); |
| 1881 | spin_lock_irqsave(&session->lock, flags); |
| 1882 | } |
| 1883 | spin_unlock_irqrestore(&session->lock, flags); |
| 1884 | return ret; |
| 1885 | } |
| 1886 | EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh); |
| 1887 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1888 | static void session_recovery_timedout(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1889 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1890 | struct iscsi_cls_session *session = |
| 1891 | container_of(work, struct iscsi_cls_session, |
| 1892 | recovery_work.work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1893 | unsigned long flags; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1894 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1895 | iscsi_cls_session_printk(KERN_INFO, session, |
| 1896 | "session recovery timed out after %d secs\n", |
| 1897 | session->recovery_tmo); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1898 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1899 | spin_lock_irqsave(&session->lock, flags); |
| 1900 | switch (session->state) { |
| 1901 | case ISCSI_SESSION_FAILED: |
| 1902 | session->state = ISCSI_SESSION_FREE; |
| 1903 | break; |
| 1904 | case ISCSI_SESSION_LOGGED_IN: |
| 1905 | case ISCSI_SESSION_FREE: |
| 1906 | /* we raced with the unblock's flush */ |
| 1907 | spin_unlock_irqrestore(&session->lock, flags); |
| 1908 | return; |
| 1909 | } |
| 1910 | spin_unlock_irqrestore(&session->lock, flags); |
| 1911 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1912 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n"); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 1913 | scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1914 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n"); |
Mike Christie | f0c9f49 | 2021-11-05 17:10:47 -0500 | [diff] [blame] | 1915 | |
| 1916 | if (session->transport->session_recovery_timedout) |
| 1917 | session->transport->session_recovery_timedout(session); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1918 | } |
| 1919 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1920 | static void __iscsi_unblock_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1921 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1922 | struct iscsi_cls_session *session = |
| 1923 | container_of(work, struct iscsi_cls_session, |
| 1924 | unblock_work); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1925 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1926 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1927 | unsigned long flags; |
| 1928 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1929 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n"); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1930 | /* |
| 1931 | * The recovery and unblock work get run from the same workqueue, |
| 1932 | * so try to cancel it if it was going to run after this unblock. |
| 1933 | */ |
| 1934 | cancel_delayed_work(&session->recovery_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1935 | spin_lock_irqsave(&session->lock, flags); |
| 1936 | session->state = ISCSI_SESSION_LOGGED_IN; |
| 1937 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1938 | /* start IO */ |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 1939 | scsi_target_unblock(&session->dev, SDEV_RUNNING); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1940 | /* |
| 1941 | * Only do kernel scanning if the driver is properly hooked into |
| 1942 | * the async scanning code (drivers like iscsi_tcp do login and |
| 1943 | * scanning from userspace). |
| 1944 | */ |
| 1945 | if (shost->hostt->scan_finished) { |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 1946 | if (scsi_queue_work(shost, &session->scan_work)) |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 1947 | atomic_inc(&ihost->nr_scans); |
| 1948 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1949 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1950 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1951 | |
| 1952 | /** |
| 1953 | * iscsi_unblock_session - set a session as logged in and start IO. |
| 1954 | * @session: iscsi session |
| 1955 | * |
| 1956 | * Mark a session as ready to accept IO. |
| 1957 | */ |
| 1958 | void iscsi_unblock_session(struct iscsi_cls_session *session) |
| 1959 | { |
Mike Christie | 68f2f83 | 2021-05-25 13:18:09 -0500 | [diff] [blame] | 1960 | flush_work(&session->block_work); |
| 1961 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1962 | queue_work(iscsi_eh_timer_workq, &session->unblock_work); |
| 1963 | /* |
Mike Christie | 1d726aa | 2020-07-01 14:47:47 -0500 | [diff] [blame] | 1964 | * Blocking the session can be done from any context so we only |
| 1965 | * queue the block work. Make sure the unblock work has completed |
| 1966 | * because it flushes/cancels the other works and updates the state. |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1967 | */ |
Mike Christie | 1d726aa | 2020-07-01 14:47:47 -0500 | [diff] [blame] | 1968 | flush_work(&session->unblock_work); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1969 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1970 | EXPORT_SYMBOL_GPL(iscsi_unblock_session); |
| 1971 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1972 | static void __iscsi_block_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1973 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1974 | struct iscsi_cls_session *session = |
| 1975 | container_of(work, struct iscsi_cls_session, |
| 1976 | block_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1977 | unsigned long flags; |
| 1978 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1979 | ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1980 | spin_lock_irqsave(&session->lock, flags); |
| 1981 | session->state = ISCSI_SESSION_FAILED; |
| 1982 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1983 | scsi_target_block(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1984 | ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n"); |
Mike Christie | fdd46dc | 2009-11-11 16:34:34 -0600 | [diff] [blame] | 1985 | if (session->recovery_tmo >= 0) |
| 1986 | queue_delayed_work(iscsi_eh_timer_workq, |
| 1987 | &session->recovery_work, |
| 1988 | session->recovery_tmo * HZ); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1989 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1990 | |
| 1991 | void iscsi_block_session(struct iscsi_cls_session *session) |
| 1992 | { |
| 1993 | queue_work(iscsi_eh_timer_workq, &session->block_work); |
| 1994 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1995 | EXPORT_SYMBOL_GPL(iscsi_block_session); |
| 1996 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1997 | static void __iscsi_unbind_session(struct work_struct *work) |
| 1998 | { |
| 1999 | struct iscsi_cls_session *session = |
| 2000 | container_of(work, struct iscsi_cls_session, |
| 2001 | unbind_work); |
| 2002 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 2003 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2004 | unsigned long flags; |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2005 | unsigned int target_id; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2006 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2007 | ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n"); |
| 2008 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2009 | /* Prevent new scans and make sure scanning is not in progress */ |
| 2010 | mutex_lock(&ihost->mutex); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2011 | spin_lock_irqsave(&session->lock, flags); |
| 2012 | if (session->target_id == ISCSI_MAX_TARGET) { |
| 2013 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2014 | mutex_unlock(&ihost->mutex); |
Wu Bo | 13e60d3 | 2020-03-24 15:58:50 +0800 | [diff] [blame] | 2015 | goto unbind_session_exit; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2016 | } |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2017 | |
| 2018 | target_id = session->target_id; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2019 | session->target_id = ISCSI_MAX_TARGET; |
| 2020 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2021 | mutex_unlock(&ihost->mutex); |
| 2022 | |
Mike Christie | e463f96 | 2020-07-01 14:47:46 -0500 | [diff] [blame] | 2023 | scsi_remove_target(&session->dev); |
| 2024 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2025 | if (session->ida_used) |
| 2026 | ida_simple_remove(&iscsi_sess_ida, target_id); |
| 2027 | |
Wu Bo | 13e60d3 | 2020-03-24 15:58:50 +0800 | [diff] [blame] | 2028 | unbind_session_exit: |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2029 | iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2030 | ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2031 | } |
| 2032 | |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 2033 | static void __iscsi_destroy_session(struct work_struct *work) |
| 2034 | { |
| 2035 | struct iscsi_cls_session *session = |
| 2036 | container_of(work, struct iscsi_cls_session, destroy_work); |
| 2037 | |
| 2038 | session->transport->destroy_session(session); |
| 2039 | } |
| 2040 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2041 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2042 | iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 2043 | int dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2044 | { |
| 2045 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2047 | session = kzalloc(sizeof(*session) + dd_size, |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2048 | GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2049 | if (!session) |
Mike Christie | f53a88d | 2006-06-28 12:00:27 -0500 | [diff] [blame] | 2050 | return NULL; |
| 2051 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2052 | session->transport = transport; |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2053 | session->creator = -1; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2054 | session->recovery_tmo = 120; |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 2055 | session->recovery_tmo_sysfs_override = false; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2056 | session->state = ISCSI_SESSION_FREE; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2057 | INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2058 | INIT_LIST_HEAD(&session->sess_list); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 2059 | INIT_WORK(&session->unblock_work, __iscsi_unblock_session); |
| 2060 | INIT_WORK(&session->block_work, __iscsi_block_session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2061 | INIT_WORK(&session->unbind_work, __iscsi_unbind_session); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 2062 | INIT_WORK(&session->scan_work, iscsi_scan_session); |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 2063 | INIT_WORK(&session->destroy_work, __iscsi_destroy_session); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2064 | spin_lock_init(&session->lock); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2065 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 2066 | /* this is released in the dev's release function */ |
| 2067 | scsi_host_get(shost); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2068 | session->dev.parent = &shost->shost_gendev; |
| 2069 | session->dev.release = iscsi_session_release; |
| 2070 | device_initialize(&session->dev); |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2071 | if (dd_size) |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2072 | session->dd_data = &session[1]; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2073 | |
| 2074 | ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2075 | return session; |
| 2076 | } |
| 2077 | EXPORT_SYMBOL_GPL(iscsi_alloc_session); |
| 2078 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 2079 | int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2080 | { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2081 | unsigned long flags; |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2082 | int id = 0; |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2083 | int err; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2084 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 2085 | session->sid = atomic_add_return(1, &iscsi_session_nr); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2086 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2087 | if (target_id == ISCSI_MAX_TARGET) { |
| 2088 | id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2089 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2090 | if (id < 0) { |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2091 | iscsi_cls_session_printk(KERN_ERR, session, |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2092 | "Failure in Target ID Allocation\n"); |
| 2093 | return id; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 2094 | } |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2095 | session->target_id = (unsigned int)id; |
| 2096 | session->ida_used = true; |
| 2097 | } else |
| 2098 | session->target_id = target_id; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2099 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2100 | dev_set_name(&session->dev, "session%u", session->sid); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2101 | err = device_add(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2102 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2103 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2104 | "could not register session's dev\n"); |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2105 | goto release_ida; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2106 | } |
Gabriel Krisman Bertazi | f3c893e | 2020-01-06 13:58:17 -0500 | [diff] [blame] | 2107 | err = transport_register_device(&session->dev); |
| 2108 | if (err) { |
| 2109 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2110 | "could not register transport's dev\n"); |
| 2111 | goto release_dev; |
| 2112 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2113 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2114 | spin_lock_irqsave(&sesslock, flags); |
| 2115 | list_add(&session->sess_list, &sesslist); |
| 2116 | spin_unlock_irqrestore(&sesslock, flags); |
| 2117 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2118 | iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2119 | ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2120 | return 0; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2121 | |
Gabriel Krisman Bertazi | f3c893e | 2020-01-06 13:58:17 -0500 | [diff] [blame] | 2122 | release_dev: |
| 2123 | device_del(&session->dev); |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 2124 | release_ida: |
| 2125 | if (session->ida_used) |
| 2126 | ida_simple_remove(&iscsi_sess_ida, session->target_id); |
| 2127 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2128 | return err; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2129 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2130 | EXPORT_SYMBOL_GPL(iscsi_add_session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2131 | |
| 2132 | /** |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2133 | * iscsi_create_session - create iscsi class session |
| 2134 | * @shost: scsi host |
| 2135 | * @transport: iscsi transport |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2136 | * @dd_size: private driver data size |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2137 | * @target_id: which target |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2138 | * |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2139 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2140 | */ |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2141 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2142 | iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 2143 | int dd_size, unsigned int target_id) |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2144 | { |
| 2145 | struct iscsi_cls_session *session; |
| 2146 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2147 | session = iscsi_alloc_session(shost, transport, dd_size); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2148 | if (!session) |
| 2149 | return NULL; |
| 2150 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 2151 | if (iscsi_add_session(session, target_id)) { |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2152 | iscsi_free_session(session); |
| 2153 | return NULL; |
| 2154 | } |
| 2155 | return session; |
| 2156 | } |
| 2157 | EXPORT_SYMBOL_GPL(iscsi_create_session); |
| 2158 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2159 | static void iscsi_conn_release(struct device *dev) |
| 2160 | { |
| 2161 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev); |
| 2162 | struct device *parent = conn->dev.parent; |
| 2163 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2164 | ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2165 | kfree(conn); |
| 2166 | put_device(parent); |
| 2167 | } |
| 2168 | |
| 2169 | static int iscsi_is_conn_dev(const struct device *dev) |
| 2170 | { |
| 2171 | return dev->release == iscsi_conn_release; |
| 2172 | } |
| 2173 | |
| 2174 | static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data) |
| 2175 | { |
| 2176 | if (!iscsi_is_conn_dev(dev)) |
| 2177 | return 0; |
| 2178 | return iscsi_destroy_conn(iscsi_dev_to_conn(dev)); |
| 2179 | } |
| 2180 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2181 | void iscsi_remove_session(struct iscsi_cls_session *session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2182 | { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2183 | unsigned long flags; |
| 2184 | int err; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2185 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2186 | ISCSI_DBG_TRANS_SESSION(session, "Removing session\n"); |
| 2187 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2188 | spin_lock_irqsave(&sesslock, flags); |
Mike Christie | 93bf02e | 2020-07-01 14:47:48 -0500 | [diff] [blame] | 2189 | if (!list_empty(&session->sess_list)) |
| 2190 | list_del(&session->sess_list); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2191 | spin_unlock_irqrestore(&sesslock, flags); |
| 2192 | |
Mike Christie | 1d726aa | 2020-07-01 14:47:47 -0500 | [diff] [blame] | 2193 | flush_work(&session->block_work); |
| 2194 | flush_work(&session->unblock_work); |
| 2195 | cancel_delayed_work_sync(&session->recovery_work); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2196 | /* |
| 2197 | * If we are blocked let commands flow again. The lld or iscsi |
| 2198 | * layer should set up the queuecommand to fail commands. |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 2199 | * We assume that LLD will not be calling block/unblock while |
| 2200 | * removing the session. |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2201 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2202 | spin_lock_irqsave(&session->lock, flags); |
| 2203 | session->state = ISCSI_SESSION_FREE; |
| 2204 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 2205 | |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2206 | scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 2207 | /* flush running scans then delete devices */ |
Jitendra Bhivare | 90e9631 | 2017-03-24 14:11:43 +0530 | [diff] [blame] | 2208 | flush_work(&session->scan_work); |
Maurizio Lombardi | 165aa2b | 2019-01-28 15:24:42 +0100 | [diff] [blame] | 2209 | /* flush running unbind operations */ |
| 2210 | flush_work(&session->unbind_work); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 2211 | __iscsi_unbind_session(&session->unbind_work); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2212 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2213 | /* hw iscsi may not have removed all connections from session */ |
| 2214 | err = device_for_each_child(&session->dev, NULL, |
| 2215 | iscsi_iter_destroy_conn_fn); |
| 2216 | if (err) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2217 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2218 | "Could not delete all connections " |
| 2219 | "for session. Error %d.\n", err); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2220 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2221 | transport_unregister_device(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2222 | |
| 2223 | ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2224 | device_del(&session->dev); |
| 2225 | } |
| 2226 | EXPORT_SYMBOL_GPL(iscsi_remove_session); |
| 2227 | |
| 2228 | void iscsi_free_session(struct iscsi_cls_session *session) |
| 2229 | { |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2230 | ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2231 | iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2232 | put_device(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2233 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 2234 | EXPORT_SYMBOL_GPL(iscsi_free_session); |
| 2235 | |
| 2236 | /** |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2237 | * iscsi_create_conn - create iscsi class connection |
| 2238 | * @session: iscsi cls session |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2239 | * @dd_size: private driver data size |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2240 | * @cid: connection id |
| 2241 | * |
| 2242 | * This can be called from a LLD or iscsi_transport. The connection |
| 2243 | * is child of the session so cid must be unique for all connections |
| 2244 | * on the session. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2245 | * |
| 2246 | * Since we do not support MCS, cid will normally be zero. In some cases |
| 2247 | * for software iscsi we could be trying to preallocate a connection struct |
| 2248 | * in which case there could be two connection structs and cid would be |
| 2249 | * non-zero. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2250 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2251 | struct iscsi_cls_conn * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2252 | iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2253 | { |
| 2254 | struct iscsi_transport *transport = session->transport; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2255 | struct iscsi_cls_conn *conn; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2256 | unsigned long flags; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2257 | int err; |
| 2258 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2259 | conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2260 | if (!conn) |
| 2261 | return NULL; |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 2262 | if (dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2263 | conn->dd_data = &conn[1]; |
| 2264 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 2265 | mutex_init(&conn->ep_mutex); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2266 | INIT_LIST_HEAD(&conn->conn_list); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2267 | INIT_LIST_HEAD(&conn->conn_list_err); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2268 | conn->transport = transport; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2269 | conn->cid = cid; |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 2270 | conn->state = ISCSI_CONN_DOWN; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2271 | |
| 2272 | /* this is released in the dev's release function */ |
| 2273 | if (!get_device(&session->dev)) |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2274 | goto free_conn; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2275 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2276 | dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2277 | conn->dev.parent = &session->dev; |
| 2278 | conn->dev.release = iscsi_conn_release; |
| 2279 | err = device_register(&conn->dev); |
| 2280 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2281 | iscsi_cls_session_printk(KERN_ERR, session, "could not " |
| 2282 | "register connection's dev\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2283 | goto release_parent_ref; |
| 2284 | } |
Gabriel Krisman Bertazi | f3c893e | 2020-01-06 13:58:17 -0500 | [diff] [blame] | 2285 | err = transport_register_device(&conn->dev); |
| 2286 | if (err) { |
| 2287 | iscsi_cls_session_printk(KERN_ERR, session, "could not " |
| 2288 | "register transport's dev\n"); |
| 2289 | goto release_conn_ref; |
| 2290 | } |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2291 | |
| 2292 | spin_lock_irqsave(&connlock, flags); |
| 2293 | list_add(&conn->conn_list, &connlist); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2294 | spin_unlock_irqrestore(&connlock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2295 | |
| 2296 | ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2297 | return conn; |
| 2298 | |
Gabriel Krisman Bertazi | f3c893e | 2020-01-06 13:58:17 -0500 | [diff] [blame] | 2299 | release_conn_ref: |
Qinglang Miao | dcda662 | 2020-11-20 15:48:52 +0800 | [diff] [blame] | 2300 | device_unregister(&conn->dev); |
| 2301 | put_device(&session->dev); |
| 2302 | return NULL; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2303 | release_parent_ref: |
| 2304 | put_device(&session->dev); |
| 2305 | free_conn: |
| 2306 | kfree(conn); |
| 2307 | return NULL; |
| 2308 | } |
| 2309 | |
| 2310 | EXPORT_SYMBOL_GPL(iscsi_create_conn); |
| 2311 | |
| 2312 | /** |
| 2313 | * iscsi_destroy_conn - destroy iscsi class connection |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2314 | * @conn: iscsi cls session |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2315 | * |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2316 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2317 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2318 | int iscsi_destroy_conn(struct iscsi_cls_conn *conn) |
| 2319 | { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2320 | unsigned long flags; |
| 2321 | |
| 2322 | spin_lock_irqsave(&connlock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2323 | list_del(&conn->conn_list); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2324 | list_del(&conn->conn_list_err); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2325 | spin_unlock_irqrestore(&connlock, flags); |
| 2326 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2327 | transport_unregister_device(&conn->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2328 | ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2329 | device_unregister(&conn->dev); |
| 2330 | return 0; |
| 2331 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2332 | EXPORT_SYMBOL_GPL(iscsi_destroy_conn); |
| 2333 | |
Mike Christie | 21962a5 | 2021-05-25 13:18:03 -0500 | [diff] [blame] | 2334 | void iscsi_put_conn(struct iscsi_cls_conn *conn) |
| 2335 | { |
| 2336 | put_device(&conn->dev); |
| 2337 | } |
| 2338 | EXPORT_SYMBOL_GPL(iscsi_put_conn); |
| 2339 | |
| 2340 | void iscsi_get_conn(struct iscsi_cls_conn *conn) |
| 2341 | { |
| 2342 | get_device(&conn->dev); |
| 2343 | } |
| 2344 | EXPORT_SYMBOL_GPL(iscsi_get_conn); |
| 2345 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2346 | /* |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2347 | * iscsi interface functions |
| 2348 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2349 | static struct iscsi_internal * |
| 2350 | iscsi_if_transport_lookup(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2352 | struct iscsi_internal *priv; |
| 2353 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2355 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 2356 | list_for_each_entry(priv, &iscsi_transports, list) { |
| 2357 | if (tt == priv->iscsi_transport) { |
| 2358 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 2359 | return priv; |
| 2360 | } |
| 2361 | } |
| 2362 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 2363 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2366 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2367 | iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp) |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2368 | { |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2369 | return nlmsg_multicast(nls, skb, 0, group, gfp); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2370 | } |
| 2371 | |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 2372 | static int |
| 2373 | iscsi_unicast_skb(struct sk_buff *skb, u32 portid) |
| 2374 | { |
| 2375 | return nlmsg_unicast(nls, skb, portid); |
| 2376 | } |
| 2377 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2378 | int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2379 | char *data, uint32_t data_size) |
| 2380 | { |
| 2381 | struct nlmsghdr *nlh; |
| 2382 | struct sk_buff *skb; |
| 2383 | struct iscsi_uevent *ev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2384 | char *pdu; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2385 | struct iscsi_internal *priv; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2386 | int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) + |
| 2387 | data_size); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2388 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2389 | priv = iscsi_if_transport_lookup(conn->transport); |
| 2390 | if (!priv) |
| 2391 | return -EINVAL; |
| 2392 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2393 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2394 | if (!skb) { |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 2395 | iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED); |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2396 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver " |
| 2397 | "control PDU: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2398 | return -ENOMEM; |
| 2399 | } |
| 2400 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2401 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2402 | ev = nlmsg_data(nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2403 | memset(ev, 0, sizeof(*ev)); |
| 2404 | ev->transport_handle = iscsi_handle(conn->transport); |
| 2405 | ev->type = ISCSI_KEVENT_RECV_PDU; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2406 | ev->r.recv_req.cid = conn->cid; |
| 2407 | ev->r.recv_req.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2408 | pdu = (char*)ev + sizeof(*ev); |
| 2409 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); |
| 2410 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); |
| 2411 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2412 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2413 | } |
| 2414 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); |
| 2415 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2416 | int iscsi_offload_mesg(struct Scsi_Host *shost, |
| 2417 | struct iscsi_transport *transport, uint32_t type, |
| 2418 | char *data, uint16_t data_size) |
| 2419 | { |
| 2420 | struct nlmsghdr *nlh; |
| 2421 | struct sk_buff *skb; |
| 2422 | struct iscsi_uevent *ev; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2423 | int len = nlmsg_total_size(sizeof(*ev) + data_size); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2424 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 2425 | skb = alloc_skb(len, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2426 | if (!skb) { |
| 2427 | printk(KERN_ERR "can not deliver iscsi offload message:OOM\n"); |
| 2428 | return -ENOMEM; |
| 2429 | } |
| 2430 | |
| 2431 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2432 | ev = nlmsg_data(nlh); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2433 | memset(ev, 0, sizeof(*ev)); |
| 2434 | ev->type = type; |
| 2435 | ev->transport_handle = iscsi_handle(transport); |
| 2436 | switch (type) { |
| 2437 | case ISCSI_KEVENT_PATH_REQ: |
| 2438 | ev->r.req_path.host_no = shost->host_no; |
| 2439 | break; |
| 2440 | case ISCSI_KEVENT_IF_DOWN: |
| 2441 | ev->r.notify_if_down.host_no = shost->host_no; |
| 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 2446 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 2447 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2448 | } |
| 2449 | EXPORT_SYMBOL_GPL(iscsi_offload_mesg); |
| 2450 | |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2451 | /* |
| 2452 | * This can be called without the rx_queue_mutex, if invoked by the kernel |
| 2453 | * stop work. But, in that case, it is guaranteed not to race with |
| 2454 | * iscsi_destroy by conn_mutex. |
| 2455 | */ |
| 2456 | static void iscsi_if_stop_conn(struct iscsi_cls_conn *conn, int flag) |
| 2457 | { |
| 2458 | /* |
| 2459 | * It is important that this path doesn't rely on |
| 2460 | * rx_queue_mutex, otherwise, a thread doing allocation on a |
| 2461 | * start_session/start_connection could sleep waiting on a |
| 2462 | * writeback to a failed iscsi device, that cannot be recovered |
| 2463 | * because the lock is held. If we don't hold it here, the |
| 2464 | * kernel stop_conn_work_fn has a chance to stop the broken |
| 2465 | * session and resolve the allocation. |
| 2466 | * |
| 2467 | * Still, the user invoked .stop_conn() needs to be serialized |
| 2468 | * with stop_conn_work_fn by a private mutex. Not pretty, but |
| 2469 | * it works. |
| 2470 | */ |
| 2471 | mutex_lock(&conn_mutex); |
Mike Christie | 4ad382b | 2021-07-13 17:18:37 +0800 | [diff] [blame] | 2472 | switch (flag) { |
| 2473 | case STOP_CONN_RECOVER: |
| 2474 | conn->state = ISCSI_CONN_FAILED; |
| 2475 | break; |
| 2476 | case STOP_CONN_TERM: |
| 2477 | conn->state = ISCSI_CONN_DOWN; |
| 2478 | break; |
| 2479 | default: |
| 2480 | iscsi_cls_conn_printk(KERN_ERR, conn, |
| 2481 | "invalid stop flag %d\n", flag); |
| 2482 | goto unlock; |
| 2483 | } |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2484 | |
Mike Christie | 4ad382b | 2021-07-13 17:18:37 +0800 | [diff] [blame] | 2485 | conn->transport->stop_conn(conn, flag); |
| 2486 | unlock: |
| 2487 | mutex_unlock(&conn_mutex); |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2488 | } |
| 2489 | |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2490 | static void stop_conn_work_fn(struct work_struct *work) |
| 2491 | { |
| 2492 | struct iscsi_cls_conn *conn, *tmp; |
| 2493 | unsigned long flags; |
| 2494 | LIST_HEAD(recovery_list); |
| 2495 | |
| 2496 | spin_lock_irqsave(&connlock, flags); |
| 2497 | if (list_empty(&connlist_err)) { |
| 2498 | spin_unlock_irqrestore(&connlock, flags); |
| 2499 | return; |
| 2500 | } |
| 2501 | list_splice_init(&connlist_err, &recovery_list); |
| 2502 | spin_unlock_irqrestore(&connlock, flags); |
| 2503 | |
| 2504 | list_for_each_entry_safe(conn, tmp, &recovery_list, conn_list_err) { |
| 2505 | uint32_t sid = iscsi_conn_get_sid(conn); |
| 2506 | struct iscsi_cls_session *session; |
| 2507 | |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2508 | session = iscsi_session_lookup(sid); |
| 2509 | if (session) { |
| 2510 | if (system_state != SYSTEM_RUNNING) { |
| 2511 | session->recovery_tmo = 0; |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2512 | iscsi_if_stop_conn(conn, STOP_CONN_TERM); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2513 | } else { |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2514 | iscsi_if_stop_conn(conn, STOP_CONN_RECOVER); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | list_del_init(&conn->conn_list_err); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 2522 | void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2523 | { |
| 2524 | struct nlmsghdr *nlh; |
| 2525 | struct sk_buff *skb; |
| 2526 | struct iscsi_uevent *ev; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2527 | struct iscsi_internal *priv; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2528 | int len = nlmsg_total_size(sizeof(*ev)); |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2529 | unsigned long flags; |
| 2530 | |
| 2531 | spin_lock_irqsave(&connlock, flags); |
| 2532 | list_add(&conn->conn_list_err, &connlist_err); |
| 2533 | spin_unlock_irqrestore(&connlock, flags); |
| 2534 | queue_work(system_unbound_wq, &stop_conn_work); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2535 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2536 | priv = iscsi_if_transport_lookup(conn->transport); |
| 2537 | if (!priv) |
| 2538 | return; |
| 2539 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2540 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2541 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2542 | iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored " |
| 2543 | "conn error (%d)\n", error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2544 | return; |
| 2545 | } |
| 2546 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2547 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2548 | ev = nlmsg_data(nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2549 | ev->transport_handle = iscsi_handle(conn->transport); |
| 2550 | ev->type = ISCSI_KEVENT_CONN_ERROR; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2551 | ev->r.connerror.error = error; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2552 | ev->r.connerror.cid = conn->cid; |
| 2553 | ev->r.connerror.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2554 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2555 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2556 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2557 | iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n", |
| 2558 | error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2559 | } |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 2560 | EXPORT_SYMBOL_GPL(iscsi_conn_error_event); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2561 | |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 2562 | void iscsi_conn_login_event(struct iscsi_cls_conn *conn, |
| 2563 | enum iscsi_conn_state state) |
| 2564 | { |
| 2565 | struct nlmsghdr *nlh; |
| 2566 | struct sk_buff *skb; |
| 2567 | struct iscsi_uevent *ev; |
| 2568 | struct iscsi_internal *priv; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2569 | int len = nlmsg_total_size(sizeof(*ev)); |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 2570 | |
| 2571 | priv = iscsi_if_transport_lookup(conn->transport); |
| 2572 | if (!priv) |
| 2573 | return; |
| 2574 | |
| 2575 | skb = alloc_skb(len, GFP_ATOMIC); |
| 2576 | if (!skb) { |
| 2577 | iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored " |
| 2578 | "conn login (%d)\n", state); |
| 2579 | return; |
| 2580 | } |
| 2581 | |
| 2582 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2583 | ev = nlmsg_data(nlh); |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 2584 | ev->transport_handle = iscsi_handle(conn->transport); |
| 2585 | ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE; |
| 2586 | ev->r.conn_login.state = state; |
| 2587 | ev->r.conn_login.cid = conn->cid; |
| 2588 | ev->r.conn_login.sid = iscsi_conn_get_sid(conn); |
| 2589 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
| 2590 | |
| 2591 | iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n", |
| 2592 | state); |
| 2593 | } |
| 2594 | EXPORT_SYMBOL_GPL(iscsi_conn_login_event); |
| 2595 | |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 2596 | void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, |
| 2597 | enum iscsi_host_event_code code, uint32_t data_size, |
| 2598 | uint8_t *data) |
| 2599 | { |
| 2600 | struct nlmsghdr *nlh; |
| 2601 | struct sk_buff *skb; |
| 2602 | struct iscsi_uevent *ev; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2603 | int len = nlmsg_total_size(sizeof(*ev) + data_size); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 2604 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 2605 | skb = alloc_skb(len, GFP_NOIO); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 2606 | if (!skb) { |
| 2607 | printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n", |
| 2608 | host_no, code); |
| 2609 | return; |
| 2610 | } |
| 2611 | |
| 2612 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2613 | ev = nlmsg_data(nlh); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 2614 | ev->transport_handle = iscsi_handle(transport); |
| 2615 | ev->type = ISCSI_KEVENT_HOST_EVENT; |
| 2616 | ev->r.host_event.host_no = host_no; |
| 2617 | ev->r.host_event.code = code; |
| 2618 | ev->r.host_event.data_size = data_size; |
| 2619 | |
| 2620 | if (data_size) |
| 2621 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 2622 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 2623 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 2624 | } |
| 2625 | EXPORT_SYMBOL_GPL(iscsi_post_host_event); |
| 2626 | |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2627 | void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, |
| 2628 | uint32_t status, uint32_t pid, uint32_t data_size, |
| 2629 | uint8_t *data) |
| 2630 | { |
| 2631 | struct nlmsghdr *nlh; |
| 2632 | struct sk_buff *skb; |
| 2633 | struct iscsi_uevent *ev; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2634 | int len = nlmsg_total_size(sizeof(*ev) + data_size); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2635 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 2636 | skb = alloc_skb(len, GFP_NOIO); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2637 | if (!skb) { |
| 2638 | printk(KERN_ERR "gracefully ignored ping comp: OOM\n"); |
| 2639 | return; |
| 2640 | } |
| 2641 | |
| 2642 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2643 | ev = nlmsg_data(nlh); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2644 | ev->transport_handle = iscsi_handle(transport); |
| 2645 | ev->type = ISCSI_KEVENT_PING_COMP; |
| 2646 | ev->r.ping_comp.host_no = host_no; |
| 2647 | ev->r.ping_comp.status = status; |
| 2648 | ev->r.ping_comp.pid = pid; |
| 2649 | ev->r.ping_comp.data_size = data_size; |
| 2650 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 2651 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 2652 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2653 | } |
| 2654 | EXPORT_SYMBOL_GPL(iscsi_ping_comp_event); |
| 2655 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2656 | static int |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 2657 | iscsi_if_send_reply(u32 portid, int type, void *payload, int size) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2658 | { |
| 2659 | struct sk_buff *skb; |
| 2660 | struct nlmsghdr *nlh; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2661 | int len = nlmsg_total_size(size); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2662 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2663 | skb = alloc_skb(len, GFP_ATOMIC); |
Mike Christie | 239a7dc | 2007-05-30 12:57:07 -0500 | [diff] [blame] | 2664 | if (!skb) { |
| 2665 | printk(KERN_ERR "Could not allocate skb to send reply.\n"); |
| 2666 | return -ENOMEM; |
| 2667 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2668 | |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 2669 | nlh = __nlmsg_put(skb, 0, 0, type, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2670 | memcpy(nlmsg_data(nlh), payload, size); |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 2671 | return iscsi_unicast_skb(skb, portid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | static int |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 2675 | iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2676 | { |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2677 | struct iscsi_uevent *ev = nlmsg_data(nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2678 | struct iscsi_stats *stats; |
| 2679 | struct sk_buff *skbstat; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2680 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2681 | struct nlmsghdr *nlhstat; |
| 2682 | struct iscsi_uevent *evstat; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2683 | struct iscsi_internal *priv; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2684 | int len = nlmsg_total_size(sizeof(*ev) + |
| 2685 | sizeof(struct iscsi_stats) + |
| 2686 | sizeof(struct iscsi_stats_custom) * |
| 2687 | ISCSI_STATS_CUSTOM_MAX); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2688 | int err = 0; |
| 2689 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 2690 | priv = iscsi_if_transport_lookup(transport); |
| 2691 | if (!priv) |
| 2692 | return -EINVAL; |
| 2693 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2694 | conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2695 | if (!conn) |
| 2696 | return -EEXIST; |
| 2697 | |
| 2698 | do { |
| 2699 | int actual_size; |
| 2700 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2701 | skbstat = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2702 | if (!skbstat) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2703 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not " |
| 2704 | "deliver stats: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2705 | return -ENOMEM; |
| 2706 | } |
| 2707 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2708 | nlhstat = __nlmsg_put(skbstat, 0, 0, 0, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2709 | (len - sizeof(*nlhstat)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2710 | evstat = nlmsg_data(nlhstat); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2711 | memset(evstat, 0, sizeof(*evstat)); |
| 2712 | evstat->transport_handle = iscsi_handle(conn->transport); |
| 2713 | evstat->type = nlh->nlmsg_type; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2714 | evstat->u.get_stats.cid = |
| 2715 | ev->u.get_stats.cid; |
| 2716 | evstat->u.get_stats.sid = |
| 2717 | ev->u.get_stats.sid; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2718 | stats = (struct iscsi_stats *) |
| 2719 | ((char*)evstat + sizeof(*evstat)); |
| 2720 | memset(stats, 0, sizeof(*stats)); |
| 2721 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2722 | transport->get_stats(conn, stats); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2723 | actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) + |
| 2724 | sizeof(struct iscsi_stats) + |
| 2725 | sizeof(struct iscsi_stats_custom) * |
| 2726 | stats->custom_length); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2727 | actual_size -= sizeof(*nlhstat); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2728 | actual_size = nlmsg_msg_size(actual_size); |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 2729 | skb_trim(skbstat, NLMSG_ALIGN(actual_size)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2730 | nlhstat->nlmsg_len = actual_size; |
| 2731 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2732 | err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID, |
| 2733 | GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2734 | } while (err < 0 && err != -ECONNREFUSED); |
| 2735 | |
| 2736 | return err; |
| 2737 | } |
| 2738 | |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2739 | /** |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2740 | * iscsi_session_event - send session destr. completion event |
| 2741 | * @session: iscsi class session |
| 2742 | * @event: type of event |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2743 | */ |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2744 | int iscsi_session_event(struct iscsi_cls_session *session, |
| 2745 | enum iscsi_uevent_e event) |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2746 | { |
| 2747 | struct iscsi_internal *priv; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2748 | struct Scsi_Host *shost; |
| 2749 | struct iscsi_uevent *ev; |
| 2750 | struct sk_buff *skb; |
| 2751 | struct nlmsghdr *nlh; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2752 | int rc, len = nlmsg_total_size(sizeof(*ev)); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2753 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2754 | priv = iscsi_if_transport_lookup(session->transport); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2755 | if (!priv) |
| 2756 | return -EINVAL; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2757 | shost = iscsi_session_to_shost(session); |
| 2758 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2759 | skb = alloc_skb(len, GFP_KERNEL); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2760 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2761 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2762 | "Cannot notify userspace of session " |
| 2763 | "event %u\n", event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2764 | return -ENOMEM; |
| 2765 | } |
| 2766 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2767 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 2768 | ev = nlmsg_data(nlh); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2769 | ev->transport_handle = iscsi_handle(session->transport); |
| 2770 | |
| 2771 | ev->type = event; |
| 2772 | switch (event) { |
| 2773 | case ISCSI_KEVENT_DESTROY_SESSION: |
| 2774 | ev->r.d_session.host_no = shost->host_no; |
| 2775 | ev->r.d_session.sid = session->sid; |
| 2776 | break; |
| 2777 | case ISCSI_KEVENT_CREATE_SESSION: |
| 2778 | ev->r.c_session_ret.host_no = shost->host_no; |
| 2779 | ev->r.c_session_ret.sid = session->sid; |
| 2780 | break; |
| 2781 | case ISCSI_KEVENT_UNBIND_SESSION: |
| 2782 | ev->r.unbind_session.host_no = shost->host_no; |
| 2783 | ev->r.unbind_session.sid = session->sid; |
| 2784 | break; |
| 2785 | default: |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2786 | iscsi_cls_session_printk(KERN_ERR, session, "Invalid event " |
| 2787 | "%u.\n", event); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2788 | kfree_skb(skb); |
| 2789 | return -EINVAL; |
| 2790 | } |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2791 | |
| 2792 | /* |
| 2793 | * this will occur if the daemon is not up, so we just warn |
| 2794 | * the user and when the daemon is restarted it will handle it |
| 2795 | */ |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2796 | rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL); |
Pablo Neira Ayuso | ff491a7 | 2009-02-05 23:56:36 -0800 | [diff] [blame] | 2797 | if (rc == -ESRCH) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2798 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2799 | "Cannot notify userspace of session " |
| 2800 | "event %u. Check iscsi daemon\n", |
| 2801 | event); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2802 | |
| 2803 | ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n", |
| 2804 | event, rc); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2805 | return rc; |
| 2806 | } |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2807 | EXPORT_SYMBOL_GPL(iscsi_session_event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 2808 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2809 | static int |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2810 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep, |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2811 | struct iscsi_uevent *ev, pid_t pid, |
| 2812 | uint32_t initial_cmdsn, uint16_t cmds_max, |
| 2813 | uint16_t queue_depth) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2814 | { |
| 2815 | struct iscsi_transport *transport = priv->iscsi_transport; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2816 | struct iscsi_cls_session *session; |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 2817 | struct Scsi_Host *shost; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2818 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2819 | session = transport->create_session(ep, cmds_max, queue_depth, |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 2820 | initial_cmdsn); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2821 | if (!session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2822 | return -ENOMEM; |
| 2823 | |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2824 | session->creator = pid; |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 2825 | shost = iscsi_session_to_shost(session); |
| 2826 | ev->r.c_session_ret.host_no = shost->host_no; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2827 | ev->r.c_session_ret.sid = session->sid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2828 | ISCSI_DBG_TRANS_SESSION(session, |
| 2829 | "Completed creating transport session\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2830 | return 0; |
| 2831 | } |
| 2832 | |
| 2833 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2834 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2835 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2836 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2837 | struct iscsi_cls_session *session; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2838 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2839 | session = iscsi_session_lookup(ev->u.c_conn.sid); |
| 2840 | if (!session) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2841 | printk(KERN_ERR "iscsi: invalid session %d.\n", |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2842 | ev->u.c_conn.sid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2843 | return -EINVAL; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2844 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2845 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2846 | conn = transport->create_conn(session, ev->u.c_conn.cid); |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2847 | if (!conn) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 2848 | iscsi_cls_session_printk(KERN_ERR, session, |
| 2849 | "couldn't create a new connection."); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2850 | return -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2851 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2852 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2853 | ev->r.c_conn_ret.sid = session->sid; |
| 2854 | ev->r.c_conn_ret.cid = conn->cid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2855 | |
| 2856 | ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2857 | return 0; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | static int |
| 2861 | iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 2862 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2863 | struct iscsi_cls_conn *conn; |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2864 | unsigned long flags; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2865 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2866 | conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2867 | if (!conn) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2868 | return -EINVAL; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2869 | |
Bharath Ravi | 0ab7104 | 2020-01-25 01:19:25 -0500 | [diff] [blame] | 2870 | spin_lock_irqsave(&connlock, flags); |
| 2871 | if (!list_empty(&conn->conn_list_err)) { |
| 2872 | spin_unlock_irqrestore(&connlock, flags); |
| 2873 | return -EAGAIN; |
| 2874 | } |
| 2875 | spin_unlock_irqrestore(&connlock, flags); |
| 2876 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2877 | ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n"); |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2878 | |
| 2879 | mutex_lock(&conn_mutex); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2880 | if (transport->destroy_conn) |
| 2881 | transport->destroy_conn(conn); |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 2882 | mutex_unlock(&conn_mutex); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 2883 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2884 | return 0; |
| 2885 | } |
| 2886 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2887 | static int |
| 2888 | iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 2889 | { |
| 2890 | char *data = (char*)ev + sizeof(*ev); |
| 2891 | struct iscsi_cls_conn *conn; |
| 2892 | struct iscsi_cls_session *session; |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2893 | int err = 0, value = 0; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2894 | |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 2895 | if (ev->u.set_param.len > PAGE_SIZE) |
| 2896 | return -EINVAL; |
| 2897 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2898 | session = iscsi_session_lookup(ev->u.set_param.sid); |
| 2899 | conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); |
| 2900 | if (!conn || !session) |
| 2901 | return -EINVAL; |
| 2902 | |
| 2903 | switch (ev->u.set_param.param) { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2904 | case ISCSI_PARAM_SESS_RECOVERY_TMO: |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2905 | sscanf(data, "%d", &value); |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 2906 | if (!session->recovery_tmo_sysfs_override) |
| 2907 | session->recovery_tmo = value; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2908 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2909 | default: |
Gulam Mohamed | 221b7e1 | 2021-07-13 17:18:36 +0800 | [diff] [blame] | 2910 | if ((conn->state == ISCSI_CONN_BOUND) || |
| 2911 | (conn->state == ISCSI_CONN_UP)) { |
| 2912 | err = transport->set_param(conn, ev->u.set_param.param, |
| 2913 | data, ev->u.set_param.len); |
| 2914 | } else { |
| 2915 | return -ENOTCONN; |
| 2916 | } |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | return err; |
| 2920 | } |
| 2921 | |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 2922 | static int iscsi_if_ep_connect(struct iscsi_transport *transport, |
| 2923 | struct iscsi_uevent *ev, int msg_type) |
| 2924 | { |
| 2925 | struct iscsi_endpoint *ep; |
| 2926 | struct sockaddr *dst_addr; |
| 2927 | struct Scsi_Host *shost = NULL; |
| 2928 | int non_blocking, err = 0; |
| 2929 | |
| 2930 | if (!transport->ep_connect) |
| 2931 | return -EINVAL; |
| 2932 | |
| 2933 | if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) { |
| 2934 | shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no); |
| 2935 | if (!shost) { |
| 2936 | printk(KERN_ERR "ep connect failed. Could not find " |
| 2937 | "host no %u\n", |
| 2938 | ev->u.ep_connect_through_host.host_no); |
| 2939 | return -ENODEV; |
| 2940 | } |
| 2941 | non_blocking = ev->u.ep_connect_through_host.non_blocking; |
| 2942 | } else |
| 2943 | non_blocking = ev->u.ep_connect.non_blocking; |
| 2944 | |
| 2945 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
| 2946 | ep = transport->ep_connect(shost, dst_addr, non_blocking); |
| 2947 | if (IS_ERR(ep)) { |
| 2948 | err = PTR_ERR(ep); |
| 2949 | goto release_host; |
| 2950 | } |
| 2951 | |
| 2952 | ev->r.ep_connect_ret.handle = ep->id; |
| 2953 | release_host: |
| 2954 | if (shost) |
| 2955 | scsi_host_put(shost); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 2959 | static int iscsi_if_ep_disconnect(struct iscsi_transport *transport, |
| 2960 | u64 ep_handle) |
| 2961 | { |
| 2962 | struct iscsi_cls_conn *conn; |
| 2963 | struct iscsi_endpoint *ep; |
| 2964 | |
| 2965 | if (!transport->ep_disconnect) |
| 2966 | return -EINVAL; |
| 2967 | |
| 2968 | ep = iscsi_lookup_endpoint(ep_handle); |
| 2969 | if (!ep) |
| 2970 | return -EINVAL; |
| 2971 | conn = ep->conn; |
| 2972 | if (conn) { |
| 2973 | mutex_lock(&conn->ep_mutex); |
| 2974 | conn->ep = NULL; |
| 2975 | mutex_unlock(&conn->ep_mutex); |
Mike Christie | 4ad382b | 2021-07-13 17:18:37 +0800 | [diff] [blame] | 2976 | conn->state = ISCSI_CONN_FAILED; |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | transport->ep_disconnect(ep); |
| 2980 | return 0; |
| 2981 | } |
| 2982 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2983 | static int |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2984 | iscsi_if_transport_ep(struct iscsi_transport *transport, |
| 2985 | struct iscsi_uevent *ev, int msg_type) |
| 2986 | { |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2987 | struct iscsi_endpoint *ep; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2988 | int rc = 0; |
| 2989 | |
| 2990 | switch (msg_type) { |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 2991 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2992 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 2993 | rc = iscsi_if_ep_connect(transport, ev, msg_type); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2994 | break; |
| 2995 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 2996 | if (!transport->ep_poll) |
| 2997 | return -EINVAL; |
| 2998 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2999 | ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle); |
| 3000 | if (!ep) |
| 3001 | return -EINVAL; |
| 3002 | |
| 3003 | ev->r.retcode = transport->ep_poll(ep, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 3004 | ev->u.ep_poll.timeout_ms); |
| 3005 | break; |
| 3006 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 3007 | rc = iscsi_if_ep_disconnect(transport, |
| 3008 | ev->u.ep_disconnect.ep_handle); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 3009 | break; |
| 3010 | } |
| 3011 | return rc; |
| 3012 | } |
| 3013 | |
| 3014 | static int |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3015 | iscsi_tgt_dscvr(struct iscsi_transport *transport, |
| 3016 | struct iscsi_uevent *ev) |
| 3017 | { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 3018 | struct Scsi_Host *shost; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3019 | struct sockaddr *dst_addr; |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 3020 | int err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3021 | |
| 3022 | if (!transport->tgt_dscvr) |
| 3023 | return -EINVAL; |
| 3024 | |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 3025 | shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 3026 | if (!shost) { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 3027 | printk(KERN_ERR "target discovery could not find host no %u\n", |
| 3028 | ev->u.tgt_dscvr.host_no); |
| 3029 | return -ENODEV; |
| 3030 | } |
| 3031 | |
| 3032 | |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3033 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 3034 | err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type, |
| 3035 | ev->u.tgt_dscvr.enable, dst_addr); |
| 3036 | scsi_host_put(shost); |
| 3037 | return err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | static int |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 3041 | iscsi_set_host_param(struct iscsi_transport *transport, |
| 3042 | struct iscsi_uevent *ev) |
| 3043 | { |
| 3044 | char *data = (char*)ev + sizeof(*ev); |
| 3045 | struct Scsi_Host *shost; |
| 3046 | int err; |
| 3047 | |
| 3048 | if (!transport->set_host_param) |
| 3049 | return -ENOSYS; |
| 3050 | |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 3051 | if (ev->u.set_host_param.len > PAGE_SIZE) |
| 3052 | return -EINVAL; |
| 3053 | |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 3054 | shost = scsi_host_lookup(ev->u.set_host_param.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 3055 | if (!shost) { |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 3056 | printk(KERN_ERR "set_host_param could not find host no %u\n", |
| 3057 | ev->u.set_host_param.host_no); |
| 3058 | return -ENODEV; |
| 3059 | } |
| 3060 | |
| 3061 | err = transport->set_host_param(shost, ev->u.set_host_param.param, |
| 3062 | data, ev->u.set_host_param.len); |
| 3063 | scsi_host_put(shost); |
| 3064 | return err; |
| 3065 | } |
| 3066 | |
| 3067 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3068 | iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 3069 | { |
| 3070 | struct Scsi_Host *shost; |
| 3071 | struct iscsi_path *params; |
| 3072 | int err; |
| 3073 | |
| 3074 | if (!transport->set_path) |
| 3075 | return -ENOSYS; |
| 3076 | |
| 3077 | shost = scsi_host_lookup(ev->u.set_path.host_no); |
| 3078 | if (!shost) { |
| 3079 | printk(KERN_ERR "set path could not find host no %u\n", |
| 3080 | ev->u.set_path.host_no); |
| 3081 | return -ENODEV; |
| 3082 | } |
| 3083 | |
| 3084 | params = (struct iscsi_path *)((char *)ev + sizeof(*ev)); |
| 3085 | err = transport->set_path(shost, params); |
| 3086 | |
| 3087 | scsi_host_put(shost); |
| 3088 | return err; |
| 3089 | } |
| 3090 | |
Nick Black | 54155ed | 2019-12-26 15:31:48 -0500 | [diff] [blame] | 3091 | static int iscsi_session_has_conns(int sid) |
| 3092 | { |
| 3093 | struct iscsi_cls_conn *conn; |
| 3094 | unsigned long flags; |
| 3095 | int found = 0; |
| 3096 | |
| 3097 | spin_lock_irqsave(&connlock, flags); |
| 3098 | list_for_each_entry(conn, &connlist, conn_list) { |
| 3099 | if (iscsi_conn_get_sid(conn) == sid) { |
| 3100 | found = 1; |
| 3101 | break; |
| 3102 | } |
| 3103 | } |
| 3104 | spin_unlock_irqrestore(&connlock, flags); |
| 3105 | |
| 3106 | return found; |
| 3107 | } |
| 3108 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3109 | static int |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 3110 | iscsi_set_iface_params(struct iscsi_transport *transport, |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 3111 | struct iscsi_uevent *ev, uint32_t len) |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 3112 | { |
| 3113 | char *data = (char *)ev + sizeof(*ev); |
| 3114 | struct Scsi_Host *shost; |
| 3115 | int err; |
| 3116 | |
| 3117 | if (!transport->set_iface_param) |
| 3118 | return -ENOSYS; |
| 3119 | |
| 3120 | shost = scsi_host_lookup(ev->u.set_iface_params.host_no); |
| 3121 | if (!shost) { |
| 3122 | printk(KERN_ERR "set_iface_params could not find host no %u\n", |
| 3123 | ev->u.set_iface_params.host_no); |
| 3124 | return -ENODEV; |
| 3125 | } |
| 3126 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 3127 | err = transport->set_iface_param(shost, data, len); |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 3128 | scsi_host_put(shost); |
| 3129 | return err; |
| 3130 | } |
| 3131 | |
| 3132 | static int |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 3133 | iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 3134 | { |
| 3135 | struct Scsi_Host *shost; |
| 3136 | struct sockaddr *dst_addr; |
| 3137 | int err; |
| 3138 | |
| 3139 | if (!transport->send_ping) |
| 3140 | return -ENOSYS; |
| 3141 | |
| 3142 | shost = scsi_host_lookup(ev->u.iscsi_ping.host_no); |
| 3143 | if (!shost) { |
| 3144 | printk(KERN_ERR "iscsi_ping could not find host no %u\n", |
| 3145 | ev->u.iscsi_ping.host_no); |
| 3146 | return -ENODEV; |
| 3147 | } |
| 3148 | |
| 3149 | dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev)); |
| 3150 | err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num, |
| 3151 | ev->u.iscsi_ping.iface_type, |
| 3152 | ev->u.iscsi_ping.payload_size, |
| 3153 | ev->u.iscsi_ping.pid, |
| 3154 | dst_addr); |
| 3155 | scsi_host_put(shost); |
| 3156 | return err; |
| 3157 | } |
| 3158 | |
| 3159 | static int |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3160 | iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
| 3161 | { |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3162 | struct iscsi_uevent *ev = nlmsg_data(nlh); |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3163 | struct Scsi_Host *shost = NULL; |
| 3164 | struct iscsi_chap_rec *chap_rec; |
| 3165 | struct iscsi_internal *priv; |
| 3166 | struct sk_buff *skbchap; |
| 3167 | struct nlmsghdr *nlhchap; |
| 3168 | struct iscsi_uevent *evchap; |
| 3169 | uint32_t chap_buf_size; |
| 3170 | int len, err = 0; |
| 3171 | char *buf; |
| 3172 | |
| 3173 | if (!transport->get_chap) |
| 3174 | return -EINVAL; |
| 3175 | |
| 3176 | priv = iscsi_if_transport_lookup(transport); |
| 3177 | if (!priv) |
| 3178 | return -EINVAL; |
| 3179 | |
| 3180 | chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec)); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3181 | len = nlmsg_total_size(sizeof(*ev) + chap_buf_size); |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3182 | |
| 3183 | shost = scsi_host_lookup(ev->u.get_chap.host_no); |
| 3184 | if (!shost) { |
Masanari Iida | 804ff60 | 2015-05-07 23:21:27 +0900 | [diff] [blame] | 3185 | printk(KERN_ERR "%s: failed. Could not find host no %u\n", |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3186 | __func__, ev->u.get_chap.host_no); |
| 3187 | return -ENODEV; |
| 3188 | } |
| 3189 | |
| 3190 | do { |
| 3191 | int actual_size; |
| 3192 | |
| 3193 | skbchap = alloc_skb(len, GFP_KERNEL); |
| 3194 | if (!skbchap) { |
| 3195 | printk(KERN_ERR "can not deliver chap: OOM\n"); |
| 3196 | err = -ENOMEM; |
| 3197 | goto exit_get_chap; |
| 3198 | } |
| 3199 | |
| 3200 | nlhchap = __nlmsg_put(skbchap, 0, 0, 0, |
| 3201 | (len - sizeof(*nlhchap)), 0); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3202 | evchap = nlmsg_data(nlhchap); |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3203 | memset(evchap, 0, sizeof(*evchap)); |
| 3204 | evchap->transport_handle = iscsi_handle(transport); |
| 3205 | evchap->type = nlh->nlmsg_type; |
| 3206 | evchap->u.get_chap.host_no = ev->u.get_chap.host_no; |
| 3207 | evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx; |
| 3208 | evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries; |
Nick Black' via open-iscsi | a799cb7 | 2014-07-01 11:24:37 -0500 | [diff] [blame] | 3209 | buf = (char *)evchap + sizeof(*evchap); |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3210 | memset(buf, 0, chap_buf_size); |
| 3211 | |
| 3212 | err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx, |
| 3213 | &evchap->u.get_chap.num_entries, buf); |
| 3214 | |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3215 | actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size); |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3216 | skb_trim(skbchap, NLMSG_ALIGN(actual_size)); |
| 3217 | nlhchap->nlmsg_len = actual_size; |
| 3218 | |
| 3219 | err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID, |
| 3220 | GFP_KERNEL); |
| 3221 | } while (err < 0 && err != -ECONNREFUSED); |
| 3222 | |
| 3223 | exit_get_chap: |
| 3224 | scsi_host_put(shost); |
| 3225 | return err; |
| 3226 | } |
| 3227 | |
Adheer Chandravanshi | 3af142f | 2013-09-17 07:54:48 -0400 | [diff] [blame] | 3228 | static int iscsi_set_chap(struct iscsi_transport *transport, |
| 3229 | struct iscsi_uevent *ev, uint32_t len) |
| 3230 | { |
| 3231 | char *data = (char *)ev + sizeof(*ev); |
| 3232 | struct Scsi_Host *shost; |
| 3233 | int err = 0; |
| 3234 | |
| 3235 | if (!transport->set_chap) |
| 3236 | return -ENOSYS; |
| 3237 | |
| 3238 | shost = scsi_host_lookup(ev->u.set_path.host_no); |
| 3239 | if (!shost) { |
| 3240 | pr_err("%s could not find host no %u\n", |
| 3241 | __func__, ev->u.set_path.host_no); |
| 3242 | return -ENODEV; |
| 3243 | } |
| 3244 | |
| 3245 | err = transport->set_chap(shost, data, len); |
| 3246 | scsi_host_put(shost); |
| 3247 | return err; |
| 3248 | } |
| 3249 | |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3250 | static int iscsi_delete_chap(struct iscsi_transport *transport, |
| 3251 | struct iscsi_uevent *ev) |
| 3252 | { |
| 3253 | struct Scsi_Host *shost; |
| 3254 | int err = 0; |
| 3255 | |
| 3256 | if (!transport->delete_chap) |
| 3257 | return -ENOSYS; |
| 3258 | |
| 3259 | shost = scsi_host_lookup(ev->u.delete_chap.host_no); |
| 3260 | if (!shost) { |
| 3261 | printk(KERN_ERR "%s could not find host no %u\n", |
| 3262 | __func__, ev->u.delete_chap.host_no); |
| 3263 | return -ENODEV; |
| 3264 | } |
| 3265 | |
| 3266 | err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx); |
| 3267 | scsi_host_put(shost); |
| 3268 | return err; |
| 3269 | } |
| 3270 | |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3271 | static const struct { |
| 3272 | enum iscsi_discovery_parent_type value; |
| 3273 | char *name; |
| 3274 | } iscsi_discovery_parent_names[] = { |
| 3275 | {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" }, |
| 3276 | {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" }, |
| 3277 | {ISCSI_DISC_PARENT_ISNS, "isns" }, |
| 3278 | }; |
| 3279 | |
| 3280 | char *iscsi_get_discovery_parent_name(int parent_type) |
| 3281 | { |
| 3282 | int i; |
| 3283 | char *state = "Unknown!"; |
| 3284 | |
| 3285 | for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) { |
| 3286 | if (iscsi_discovery_parent_names[i].value & parent_type) { |
| 3287 | state = iscsi_discovery_parent_names[i].name; |
| 3288 | break; |
| 3289 | } |
| 3290 | } |
| 3291 | return state; |
| 3292 | } |
| 3293 | EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name); |
| 3294 | |
| 3295 | static int iscsi_set_flashnode_param(struct iscsi_transport *transport, |
| 3296 | struct iscsi_uevent *ev, uint32_t len) |
| 3297 | { |
| 3298 | char *data = (char *)ev + sizeof(*ev); |
| 3299 | struct Scsi_Host *shost; |
| 3300 | struct iscsi_bus_flash_session *fnode_sess; |
| 3301 | struct iscsi_bus_flash_conn *fnode_conn; |
| 3302 | struct device *dev; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3303 | uint32_t idx; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3304 | int err = 0; |
| 3305 | |
| 3306 | if (!transport->set_flashnode_param) { |
| 3307 | err = -ENOSYS; |
| 3308 | goto exit_set_fnode; |
| 3309 | } |
| 3310 | |
| 3311 | shost = scsi_host_lookup(ev->u.set_flashnode.host_no); |
| 3312 | if (!shost) { |
| 3313 | pr_err("%s could not find host no %u\n", |
| 3314 | __func__, ev->u.set_flashnode.host_no); |
| 3315 | err = -ENODEV; |
Jing Xiangfeng | 68e12e5f | 2020-06-15 16:12:26 +0800 | [diff] [blame] | 3316 | goto exit_set_fnode; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3319 | idx = ev->u.set_flashnode.flashnode_idx; |
| 3320 | fnode_sess = iscsi_get_flashnode_by_index(shost, idx); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3321 | if (!fnode_sess) { |
| 3322 | pr_err("%s could not find flashnode %u for host no %u\n", |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3323 | __func__, idx, ev->u.set_flashnode.host_no); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3324 | err = -ENODEV; |
| 3325 | goto put_host; |
| 3326 | } |
| 3327 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3328 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3329 | if (!dev) { |
| 3330 | err = -ENODEV; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3331 | goto put_sess; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 3335 | err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3336 | put_device(dev); |
| 3337 | |
| 3338 | put_sess: |
| 3339 | put_device(&fnode_sess->dev); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3340 | |
| 3341 | put_host: |
| 3342 | scsi_host_put(shost); |
| 3343 | |
| 3344 | exit_set_fnode: |
| 3345 | return err; |
| 3346 | } |
| 3347 | |
| 3348 | static int iscsi_new_flashnode(struct iscsi_transport *transport, |
| 3349 | struct iscsi_uevent *ev, uint32_t len) |
| 3350 | { |
| 3351 | char *data = (char *)ev + sizeof(*ev); |
| 3352 | struct Scsi_Host *shost; |
| 3353 | int index; |
| 3354 | int err = 0; |
| 3355 | |
| 3356 | if (!transport->new_flashnode) { |
| 3357 | err = -ENOSYS; |
| 3358 | goto exit_new_fnode; |
| 3359 | } |
| 3360 | |
| 3361 | shost = scsi_host_lookup(ev->u.new_flashnode.host_no); |
| 3362 | if (!shost) { |
| 3363 | pr_err("%s could not find host no %u\n", |
| 3364 | __func__, ev->u.new_flashnode.host_no); |
| 3365 | err = -ENODEV; |
| 3366 | goto put_host; |
| 3367 | } |
| 3368 | |
| 3369 | index = transport->new_flashnode(shost, data, len); |
| 3370 | |
| 3371 | if (index >= 0) |
| 3372 | ev->r.new_flashnode_ret.flashnode_idx = index; |
| 3373 | else |
| 3374 | err = -EIO; |
| 3375 | |
| 3376 | put_host: |
| 3377 | scsi_host_put(shost); |
| 3378 | |
| 3379 | exit_new_fnode: |
| 3380 | return err; |
| 3381 | } |
| 3382 | |
| 3383 | static int iscsi_del_flashnode(struct iscsi_transport *transport, |
| 3384 | struct iscsi_uevent *ev) |
| 3385 | { |
| 3386 | struct Scsi_Host *shost; |
| 3387 | struct iscsi_bus_flash_session *fnode_sess; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3388 | uint32_t idx; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3389 | int err = 0; |
| 3390 | |
| 3391 | if (!transport->del_flashnode) { |
| 3392 | err = -ENOSYS; |
| 3393 | goto exit_del_fnode; |
| 3394 | } |
| 3395 | |
| 3396 | shost = scsi_host_lookup(ev->u.del_flashnode.host_no); |
| 3397 | if (!shost) { |
| 3398 | pr_err("%s could not find host no %u\n", |
| 3399 | __func__, ev->u.del_flashnode.host_no); |
| 3400 | err = -ENODEV; |
| 3401 | goto put_host; |
| 3402 | } |
| 3403 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3404 | idx = ev->u.del_flashnode.flashnode_idx; |
| 3405 | fnode_sess = iscsi_get_flashnode_by_index(shost, idx); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3406 | if (!fnode_sess) { |
| 3407 | pr_err("%s could not find flashnode %u for host no %u\n", |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3408 | __func__, idx, ev->u.del_flashnode.host_no); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3409 | err = -ENODEV; |
| 3410 | goto put_host; |
| 3411 | } |
| 3412 | |
| 3413 | err = transport->del_flashnode(fnode_sess); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3414 | put_device(&fnode_sess->dev); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3415 | |
| 3416 | put_host: |
| 3417 | scsi_host_put(shost); |
| 3418 | |
| 3419 | exit_del_fnode: |
| 3420 | return err; |
| 3421 | } |
| 3422 | |
| 3423 | static int iscsi_login_flashnode(struct iscsi_transport *transport, |
| 3424 | struct iscsi_uevent *ev) |
| 3425 | { |
| 3426 | struct Scsi_Host *shost; |
| 3427 | struct iscsi_bus_flash_session *fnode_sess; |
| 3428 | struct iscsi_bus_flash_conn *fnode_conn; |
| 3429 | struct device *dev; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3430 | uint32_t idx; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3431 | int err = 0; |
| 3432 | |
| 3433 | if (!transport->login_flashnode) { |
| 3434 | err = -ENOSYS; |
| 3435 | goto exit_login_fnode; |
| 3436 | } |
| 3437 | |
| 3438 | shost = scsi_host_lookup(ev->u.login_flashnode.host_no); |
| 3439 | if (!shost) { |
| 3440 | pr_err("%s could not find host no %u\n", |
| 3441 | __func__, ev->u.login_flashnode.host_no); |
| 3442 | err = -ENODEV; |
| 3443 | goto put_host; |
| 3444 | } |
| 3445 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3446 | idx = ev->u.login_flashnode.flashnode_idx; |
| 3447 | fnode_sess = iscsi_get_flashnode_by_index(shost, idx); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3448 | if (!fnode_sess) { |
| 3449 | pr_err("%s could not find flashnode %u for host no %u\n", |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3450 | __func__, idx, ev->u.login_flashnode.host_no); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3451 | err = -ENODEV; |
| 3452 | goto put_host; |
| 3453 | } |
| 3454 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3455 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3456 | if (!dev) { |
| 3457 | err = -ENODEV; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3458 | goto put_sess; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 3462 | err = transport->login_flashnode(fnode_sess, fnode_conn); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3463 | put_device(dev); |
| 3464 | |
| 3465 | put_sess: |
| 3466 | put_device(&fnode_sess->dev); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3467 | |
| 3468 | put_host: |
| 3469 | scsi_host_put(shost); |
| 3470 | |
| 3471 | exit_login_fnode: |
| 3472 | return err; |
| 3473 | } |
| 3474 | |
| 3475 | static int iscsi_logout_flashnode(struct iscsi_transport *transport, |
| 3476 | struct iscsi_uevent *ev) |
| 3477 | { |
| 3478 | struct Scsi_Host *shost; |
| 3479 | struct iscsi_bus_flash_session *fnode_sess; |
| 3480 | struct iscsi_bus_flash_conn *fnode_conn; |
| 3481 | struct device *dev; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3482 | uint32_t idx; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3483 | int err = 0; |
| 3484 | |
| 3485 | if (!transport->logout_flashnode) { |
| 3486 | err = -ENOSYS; |
| 3487 | goto exit_logout_fnode; |
| 3488 | } |
| 3489 | |
| 3490 | shost = scsi_host_lookup(ev->u.logout_flashnode.host_no); |
| 3491 | if (!shost) { |
| 3492 | pr_err("%s could not find host no %u\n", |
| 3493 | __func__, ev->u.logout_flashnode.host_no); |
| 3494 | err = -ENODEV; |
| 3495 | goto put_host; |
| 3496 | } |
| 3497 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3498 | idx = ev->u.logout_flashnode.flashnode_idx; |
| 3499 | fnode_sess = iscsi_get_flashnode_by_index(shost, idx); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3500 | if (!fnode_sess) { |
| 3501 | pr_err("%s could not find flashnode %u for host no %u\n", |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3502 | __func__, idx, ev->u.logout_flashnode.host_no); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3503 | err = -ENODEV; |
| 3504 | goto put_host; |
| 3505 | } |
| 3506 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3507 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3508 | if (!dev) { |
| 3509 | err = -ENODEV; |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3510 | goto put_sess; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 3514 | |
| 3515 | err = transport->logout_flashnode(fnode_sess, fnode_conn); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 3516 | put_device(dev); |
| 3517 | |
| 3518 | put_sess: |
| 3519 | put_device(&fnode_sess->dev); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3520 | |
| 3521 | put_host: |
| 3522 | scsi_host_put(shost); |
| 3523 | |
| 3524 | exit_logout_fnode: |
| 3525 | return err; |
| 3526 | } |
| 3527 | |
| 3528 | static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport, |
| 3529 | struct iscsi_uevent *ev) |
| 3530 | { |
| 3531 | struct Scsi_Host *shost; |
| 3532 | struct iscsi_cls_session *session; |
| 3533 | int err = 0; |
| 3534 | |
| 3535 | if (!transport->logout_flashnode_sid) { |
| 3536 | err = -ENOSYS; |
| 3537 | goto exit_logout_sid; |
| 3538 | } |
| 3539 | |
| 3540 | shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no); |
| 3541 | if (!shost) { |
| 3542 | pr_err("%s could not find host no %u\n", |
| 3543 | __func__, ev->u.logout_flashnode.host_no); |
| 3544 | err = -ENODEV; |
| 3545 | goto put_host; |
| 3546 | } |
| 3547 | |
| 3548 | session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid); |
| 3549 | if (!session) { |
| 3550 | pr_err("%s could not find session id %u\n", |
| 3551 | __func__, ev->u.logout_flashnode_sid.sid); |
| 3552 | err = -EINVAL; |
| 3553 | goto put_host; |
| 3554 | } |
| 3555 | |
| 3556 | err = transport->logout_flashnode_sid(session); |
| 3557 | |
| 3558 | put_host: |
| 3559 | scsi_host_put(shost); |
| 3560 | |
| 3561 | exit_logout_sid: |
| 3562 | return err; |
| 3563 | } |
| 3564 | |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3565 | static int |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3566 | iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
| 3567 | { |
| 3568 | struct iscsi_uevent *ev = nlmsg_data(nlh); |
| 3569 | struct Scsi_Host *shost = NULL; |
| 3570 | struct iscsi_internal *priv; |
| 3571 | struct sk_buff *skbhost_stats; |
| 3572 | struct nlmsghdr *nlhhost_stats; |
| 3573 | struct iscsi_uevent *evhost_stats; |
| 3574 | int host_stats_size = 0; |
| 3575 | int len, err = 0; |
| 3576 | char *buf; |
| 3577 | |
| 3578 | if (!transport->get_host_stats) |
Mike Christie | 719e587 | 2014-07-12 15:51:50 -0500 | [diff] [blame] | 3579 | return -ENOSYS; |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3580 | |
| 3581 | priv = iscsi_if_transport_lookup(transport); |
| 3582 | if (!priv) |
| 3583 | return -EINVAL; |
| 3584 | |
| 3585 | host_stats_size = sizeof(struct iscsi_offload_host_stats); |
| 3586 | len = nlmsg_total_size(sizeof(*ev) + host_stats_size); |
| 3587 | |
| 3588 | shost = scsi_host_lookup(ev->u.get_host_stats.host_no); |
| 3589 | if (!shost) { |
Arvind Yadav | 013ee63 | 2017-10-29 11:39:46 +0530 | [diff] [blame] | 3590 | pr_err("%s: failed. Could not find host no %u\n", |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3591 | __func__, ev->u.get_host_stats.host_no); |
| 3592 | return -ENODEV; |
| 3593 | } |
| 3594 | |
| 3595 | do { |
| 3596 | int actual_size; |
| 3597 | |
| 3598 | skbhost_stats = alloc_skb(len, GFP_KERNEL); |
| 3599 | if (!skbhost_stats) { |
| 3600 | pr_err("cannot deliver host stats: OOM\n"); |
| 3601 | err = -ENOMEM; |
| 3602 | goto exit_host_stats; |
| 3603 | } |
| 3604 | |
| 3605 | nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0, |
| 3606 | (len - sizeof(*nlhhost_stats)), 0); |
| 3607 | evhost_stats = nlmsg_data(nlhhost_stats); |
| 3608 | memset(evhost_stats, 0, sizeof(*evhost_stats)); |
| 3609 | evhost_stats->transport_handle = iscsi_handle(transport); |
| 3610 | evhost_stats->type = nlh->nlmsg_type; |
| 3611 | evhost_stats->u.get_host_stats.host_no = |
| 3612 | ev->u.get_host_stats.host_no; |
Nick Black' via open-iscsi | a799cb7 | 2014-07-01 11:24:37 -0500 | [diff] [blame] | 3613 | buf = (char *)evhost_stats + sizeof(*evhost_stats); |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3614 | memset(buf, 0, host_stats_size); |
| 3615 | |
| 3616 | err = transport->get_host_stats(shost, buf, host_stats_size); |
Mike Christie | 2f7608f | 2014-07-12 15:51:48 -0500 | [diff] [blame] | 3617 | if (err) { |
Mike Christie | bfb5087 | 2014-08-03 18:37:52 -0500 | [diff] [blame] | 3618 | kfree_skb(skbhost_stats); |
Mike Christie | 2f7608f | 2014-07-12 15:51:48 -0500 | [diff] [blame] | 3619 | goto exit_host_stats; |
| 3620 | } |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3621 | |
| 3622 | actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size); |
| 3623 | skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size)); |
| 3624 | nlhhost_stats->nlmsg_len = actual_size; |
| 3625 | |
| 3626 | err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID, |
| 3627 | GFP_KERNEL); |
| 3628 | } while (err < 0 && err != -ECONNREFUSED); |
| 3629 | |
| 3630 | exit_host_stats: |
| 3631 | scsi_host_put(shost); |
| 3632 | return err; |
| 3633 | } |
| 3634 | |
| 3635 | |
| 3636 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3637 | iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3638 | { |
| 3639 | int err = 0; |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3640 | u32 portid; |
Chris Leech | f40bbcb | 2021-02-23 21:39:01 -0800 | [diff] [blame] | 3641 | u32 pdu_len; |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3642 | struct iscsi_uevent *ev = nlmsg_data(nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3643 | struct iscsi_transport *transport = NULL; |
| 3644 | struct iscsi_internal *priv; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3645 | struct iscsi_cls_session *session; |
| 3646 | struct iscsi_cls_conn *conn; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 3647 | struct iscsi_endpoint *ep = NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3648 | |
Lee Duncan | c71edc5 | 2021-02-23 13:06:24 -0800 | [diff] [blame] | 3649 | if (!netlink_capable(skb, CAP_SYS_ADMIN)) |
| 3650 | return -EPERM; |
| 3651 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3652 | if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE) |
| 3653 | *group = ISCSI_NL_GRP_UIP; |
| 3654 | else |
| 3655 | *group = ISCSI_NL_GRP_ISCSID; |
| 3656 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3657 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); |
| 3658 | if (!priv) |
| 3659 | return -EINVAL; |
| 3660 | transport = priv->iscsi_transport; |
| 3661 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3662 | if (!try_module_get(transport->owner)) |
| 3663 | return -EINVAL; |
| 3664 | |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3665 | portid = NETLINK_CB(skb).portid; |
| 3666 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3667 | switch (nlh->nlmsg_type) { |
| 3668 | case ISCSI_UEVENT_CREATE_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 3669 | err = iscsi_if_create_session(priv, ep, ev, |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3670 | portid, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 3671 | ev->u.c_session.initial_cmdsn, |
| 3672 | ev->u.c_session.cmds_max, |
| 3673 | ev->u.c_session.queue_depth); |
| 3674 | break; |
| 3675 | case ISCSI_UEVENT_CREATE_BOUND_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 3676 | ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle); |
Mike Christie | c95fddc | 2008-06-16 10:11:32 -0500 | [diff] [blame] | 3677 | if (!ep) { |
| 3678 | err = -EINVAL; |
| 3679 | break; |
| 3680 | } |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 3681 | |
| 3682 | err = iscsi_if_create_session(priv, ep, ev, |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3683 | portid, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 3684 | ev->u.c_bound_session.initial_cmdsn, |
| 3685 | ev->u.c_bound_session.cmds_max, |
| 3686 | ev->u.c_bound_session.queue_depth); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3687 | break; |
| 3688 | case ISCSI_UEVENT_DESTROY_SESSION: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3689 | session = iscsi_session_lookup(ev->u.d_session.sid); |
Nick Black | 54155ed | 2019-12-26 15:31:48 -0500 | [diff] [blame] | 3690 | if (!session) |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 3691 | err = -EINVAL; |
Nick Black | 54155ed | 2019-12-26 15:31:48 -0500 | [diff] [blame] | 3692 | else if (iscsi_session_has_conns(ev->u.d_session.sid)) |
| 3693 | err = -EBUSY; |
| 3694 | else |
| 3695 | transport->destroy_session(session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 3696 | break; |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 3697 | case ISCSI_UEVENT_DESTROY_SESSION_ASYNC: |
| 3698 | session = iscsi_session_lookup(ev->u.d_session.sid); |
| 3699 | if (!session) |
| 3700 | err = -EINVAL; |
| 3701 | else if (iscsi_session_has_conns(ev->u.d_session.sid)) |
| 3702 | err = -EBUSY; |
| 3703 | else { |
| 3704 | unsigned long flags; |
| 3705 | |
| 3706 | /* Prevent this session from being found again */ |
| 3707 | spin_lock_irqsave(&sesslock, flags); |
Mike Christie | 93bf02e | 2020-07-01 14:47:48 -0500 | [diff] [blame] | 3708 | list_del_init(&session->sess_list); |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 3709 | spin_unlock_irqrestore(&sesslock, flags); |
| 3710 | |
| 3711 | queue_work(iscsi_destroy_workq, &session->destroy_work); |
| 3712 | } |
| 3713 | break; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 3714 | case ISCSI_UEVENT_UNBIND_SESSION: |
| 3715 | session = iscsi_session_lookup(ev->u.d_session.sid); |
| 3716 | if (session) |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 3717 | scsi_queue_work(iscsi_session_to_shost(session), |
| 3718 | &session->unbind_work); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 3719 | else |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3720 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3721 | break; |
| 3722 | case ISCSI_UEVENT_CREATE_CONN: |
| 3723 | err = iscsi_if_create_conn(transport, ev); |
| 3724 | break; |
| 3725 | case ISCSI_UEVENT_DESTROY_CONN: |
| 3726 | err = iscsi_if_destroy_conn(transport, ev); |
| 3727 | break; |
| 3728 | case ISCSI_UEVENT_BIND_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3729 | session = iscsi_session_lookup(ev->u.b_conn.sid); |
| 3730 | conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3731 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 3732 | if (conn && conn->ep) |
| 3733 | iscsi_if_ep_disconnect(transport, conn->ep->id); |
| 3734 | |
| 3735 | if (!session || !conn) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3736 | err = -EINVAL; |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 3737 | break; |
| 3738 | } |
| 3739 | |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3740 | mutex_lock(&conn_mutex); |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 3741 | ev->r.retcode = transport->bind_conn(session, conn, |
| 3742 | ev->u.b_conn.transport_eph, |
| 3743 | ev->u.b_conn.is_leading); |
Gulam Mohamed | 221b7e1 | 2021-07-13 17:18:36 +0800 | [diff] [blame] | 3744 | if (!ev->r.retcode) |
| 3745 | conn->state = ISCSI_CONN_BOUND; |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3746 | mutex_unlock(&conn_mutex); |
| 3747 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 3748 | if (ev->r.retcode || !transport->ep_connect) |
| 3749 | break; |
| 3750 | |
| 3751 | ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph); |
| 3752 | if (ep) { |
| 3753 | ep->conn = conn; |
| 3754 | |
| 3755 | mutex_lock(&conn->ep_mutex); |
| 3756 | conn->ep = ep; |
| 3757 | mutex_unlock(&conn->ep_mutex); |
| 3758 | } else |
| 3759 | iscsi_cls_conn_printk(KERN_ERR, conn, |
| 3760 | "Could not set ep conn " |
| 3761 | "binding\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3762 | break; |
| 3763 | case ISCSI_UEVENT_SET_PARAM: |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3764 | err = iscsi_set_param(transport, ev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3765 | break; |
| 3766 | case ISCSI_UEVENT_START_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3767 | conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid); |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 3768 | if (conn) { |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3769 | mutex_lock(&conn_mutex); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3770 | ev->r.retcode = transport->start_conn(conn); |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 3771 | if (!ev->r.retcode) |
| 3772 | conn->state = ISCSI_CONN_UP; |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3773 | mutex_unlock(&conn_mutex); |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 3774 | } |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3775 | else |
| 3776 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3777 | break; |
| 3778 | case ISCSI_UEVENT_STOP_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3779 | conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3780 | if (conn) |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3781 | iscsi_if_stop_conn(conn, ev->u.stop_conn.flag); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3782 | else |
| 3783 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3784 | break; |
| 3785 | case ISCSI_UEVENT_SEND_PDU: |
Chris Leech | f40bbcb | 2021-02-23 21:39:01 -0800 | [diff] [blame] | 3786 | pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev); |
| 3787 | |
| 3788 | if ((ev->u.send_pdu.hdr_size > pdu_len) || |
| 3789 | (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) { |
| 3790 | err = -EINVAL; |
| 3791 | break; |
| 3792 | } |
| 3793 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3794 | conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid); |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3795 | if (conn) { |
| 3796 | mutex_lock(&conn_mutex); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3797 | ev->r.retcode = transport->send_pdu(conn, |
| 3798 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), |
| 3799 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, |
| 3800 | ev->u.send_pdu.data_size); |
Gabriel Krisman Bertazi | 7e7cd796 | 2020-05-19 22:29:59 -0400 | [diff] [blame] | 3801 | mutex_unlock(&conn_mutex); |
| 3802 | } |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3803 | else |
| 3804 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3805 | break; |
| 3806 | case ISCSI_UEVENT_GET_STATS: |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 3807 | err = iscsi_if_get_stats(transport, nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3808 | break; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 3809 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
| 3810 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 3811 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 3812 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 3813 | err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); |
| 3814 | break; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 3815 | case ISCSI_UEVENT_TGT_DSCVR: |
| 3816 | err = iscsi_tgt_dscvr(transport, ev); |
| 3817 | break; |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 3818 | case ISCSI_UEVENT_SET_HOST_PARAM: |
| 3819 | err = iscsi_set_host_param(transport, ev); |
| 3820 | break; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3821 | case ISCSI_UEVENT_PATH_UPDATE: |
| 3822 | err = iscsi_set_path(transport, ev); |
| 3823 | break; |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 3824 | case ISCSI_UEVENT_SET_IFACE_PARAMS: |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 3825 | err = iscsi_set_iface_params(transport, ev, |
| 3826 | nlmsg_attrlen(nlh, sizeof(*ev))); |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 3827 | break; |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 3828 | case ISCSI_UEVENT_PING: |
| 3829 | err = iscsi_send_ping(transport, ev); |
| 3830 | break; |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3831 | case ISCSI_UEVENT_GET_CHAP: |
| 3832 | err = iscsi_get_chap(transport, nlh); |
| 3833 | break; |
| 3834 | case ISCSI_UEVENT_DELETE_CHAP: |
| 3835 | err = iscsi_delete_chap(transport, ev); |
| 3836 | break; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 3837 | case ISCSI_UEVENT_SET_FLASHNODE_PARAMS: |
| 3838 | err = iscsi_set_flashnode_param(transport, ev, |
| 3839 | nlmsg_attrlen(nlh, |
| 3840 | sizeof(*ev))); |
| 3841 | break; |
| 3842 | case ISCSI_UEVENT_NEW_FLASHNODE: |
| 3843 | err = iscsi_new_flashnode(transport, ev, |
| 3844 | nlmsg_attrlen(nlh, sizeof(*ev))); |
| 3845 | break; |
| 3846 | case ISCSI_UEVENT_DEL_FLASHNODE: |
| 3847 | err = iscsi_del_flashnode(transport, ev); |
| 3848 | break; |
| 3849 | case ISCSI_UEVENT_LOGIN_FLASHNODE: |
| 3850 | err = iscsi_login_flashnode(transport, ev); |
| 3851 | break; |
| 3852 | case ISCSI_UEVENT_LOGOUT_FLASHNODE: |
| 3853 | err = iscsi_logout_flashnode(transport, ev); |
| 3854 | break; |
| 3855 | case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID: |
| 3856 | err = iscsi_logout_flashnode_sid(transport, ev); |
| 3857 | break; |
Adheer Chandravanshi | 3af142f | 2013-09-17 07:54:48 -0400 | [diff] [blame] | 3858 | case ISCSI_UEVENT_SET_CHAP: |
| 3859 | err = iscsi_set_chap(transport, ev, |
| 3860 | nlmsg_attrlen(nlh, sizeof(*ev))); |
| 3861 | break; |
Lalit Chandivade | 6fa7c55 | 2013-11-22 05:28:18 -0500 | [diff] [blame] | 3862 | case ISCSI_UEVENT_GET_HOST_STATS: |
| 3863 | err = iscsi_get_host_stats(transport, nlh); |
| 3864 | break; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3865 | default: |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 3866 | err = -ENOSYS; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3867 | break; |
| 3868 | } |
| 3869 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 3870 | module_put(transport->owner); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3871 | return err; |
| 3872 | } |
| 3873 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3874 | /* |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3875 | * Get message from skb. Each message is processed by iscsi_if_recv_msg. |
| 3876 | * Malformed skbs with wrong lengths or invalid creds are not processed. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 3877 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3878 | static void |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3879 | iscsi_if_rx(struct sk_buff *skb) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3880 | { |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3881 | u32 portid = NETLINK_CB(skb).portid; |
| 3882 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 3883 | mutex_lock(&rx_queue_mutex); |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3884 | while (skb->len >= NLMSG_HDRLEN) { |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3885 | int err; |
| 3886 | uint32_t rlen; |
| 3887 | struct nlmsghdr *nlh; |
| 3888 | struct iscsi_uevent *ev; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3889 | uint32_t group; |
Bo Wu | bba340c | 2019-11-20 13:26:17 +0000 | [diff] [blame] | 3890 | int retries = ISCSI_SEND_MAX_ALLOWED; |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3891 | |
| 3892 | nlh = nlmsg_hdr(skb); |
Xin Long | c88f0e6 | 2017-08-27 20:25:26 +0800 | [diff] [blame] | 3893 | if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) || |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3894 | skb->len < nlh->nlmsg_len) { |
| 3895 | break; |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 3896 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 3897 | |
Hong zhi guo | e07ebea | 2013-03-27 06:53:15 +0000 | [diff] [blame] | 3898 | ev = nlmsg_data(nlh); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3899 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); |
| 3900 | if (rlen > skb->len) |
| 3901 | rlen = skb->len; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3902 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 3903 | err = iscsi_if_recv_msg(skb, nlh, &group); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3904 | if (err) { |
| 3905 | ev->type = ISCSI_KEVENT_IF_ERROR; |
| 3906 | ev->iferror = err; |
| 3907 | } |
| 3908 | do { |
| 3909 | /* |
| 3910 | * special case for GET_STATS: |
| 3911 | * on success - sending reply and stats from |
| 3912 | * inside of if_recv_msg(), |
| 3913 | * on error - fall through. |
| 3914 | */ |
| 3915 | if (ev->type == ISCSI_UEVENT_GET_STATS && !err) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3916 | break; |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 3917 | if (ev->type == ISCSI_UEVENT_GET_CHAP && !err) |
| 3918 | break; |
Chris Leech | af17092 | 2018-04-09 15:15:28 -0700 | [diff] [blame] | 3919 | err = iscsi_if_send_reply(portid, nlh->nlmsg_type, |
| 3920 | ev, sizeof(*ev)); |
Bo Wu | bba340c | 2019-11-20 13:26:17 +0000 | [diff] [blame] | 3921 | if (err == -EAGAIN && --retries < 0) { |
| 3922 | printk(KERN_WARNING "Send reply failed, error %d\n", err); |
| 3923 | break; |
| 3924 | } |
Sasha Levin | 46a7c17 | 2012-01-25 22:16:16 -0500 | [diff] [blame] | 3925 | } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 3926 | skb_pull(skb, rlen); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3927 | } |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 3928 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3931 | #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3932 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3933 | __ATTR(_name,_mode,_show,_store) |
| 3934 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3935 | /* |
| 3936 | * iSCSI connection attrs |
| 3937 | */ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 3938 | #define iscsi_conn_attr_show(param) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3940 | show_conn_param_##param(struct device *dev, \ |
| 3941 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3942 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3943 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3944 | struct iscsi_transport *t = conn->transport; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 3945 | return t->get_conn_param(conn, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3946 | } |
| 3947 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 3948 | #define iscsi_conn_attr(field, param) \ |
| 3949 | iscsi_conn_attr_show(param) \ |
| 3950 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 3951 | NULL); |
| 3952 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 3953 | iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH); |
| 3954 | iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH); |
| 3955 | iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN); |
| 3956 | iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN); |
| 3957 | iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN); |
| 3958 | iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN); |
| 3959 | iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT); |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 3960 | iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN); |
| 3961 | iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); |
Mike Christie | f6d5180 | 2007-12-13 12:43:30 -0600 | [diff] [blame] | 3962 | iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO); |
| 3963 | iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO); |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 3964 | iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT); |
| 3965 | iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN); |
| 3966 | iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO); |
| 3967 | iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE); |
| 3968 | iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT); |
| 3969 | iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE); |
| 3970 | iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE); |
| 3971 | iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE); |
| 3972 | iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN); |
| 3973 | iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE); |
| 3974 | iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS); |
| 3975 | iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC); |
| 3976 | iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL); |
| 3977 | iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6); |
| 3978 | iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF); |
| 3979 | iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF); |
Adheer Chandravanshi | 5af62f2 | 2013-11-22 05:28:20 -0500 | [diff] [blame] | 3980 | iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR); |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 3981 | |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 3982 | static const char *const connection_state_names[] = { |
| 3983 | [ISCSI_CONN_UP] = "up", |
| 3984 | [ISCSI_CONN_DOWN] = "down", |
Gulam Mohamed | 221b7e1 | 2021-07-13 17:18:36 +0800 | [diff] [blame] | 3985 | [ISCSI_CONN_FAILED] = "failed", |
| 3986 | [ISCSI_CONN_BOUND] = "bound" |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 3987 | }; |
| 3988 | |
| 3989 | static ssize_t show_conn_state(struct device *dev, |
| 3990 | struct device_attribute *attr, char *buf) |
| 3991 | { |
| 3992 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); |
| 3993 | const char *state = "unknown"; |
| 3994 | |
| 3995 | if (conn->state >= 0 && |
| 3996 | conn->state < ARRAY_SIZE(connection_state_names)) |
| 3997 | state = connection_state_names[conn->state]; |
| 3998 | |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 3999 | return sysfs_emit(buf, "%s\n", state); |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 4000 | } |
| 4001 | static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state, |
| 4002 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
Mike Christie | 289324b | 2011-02-16 15:04:37 -0600 | [diff] [blame] | 4004 | #define iscsi_conn_ep_attr_show(param) \ |
| 4005 | static ssize_t show_conn_ep_param_##param(struct device *dev, \ |
| 4006 | struct device_attribute *attr,\ |
| 4007 | char *buf) \ |
| 4008 | { \ |
| 4009 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
| 4010 | struct iscsi_transport *t = conn->transport; \ |
| 4011 | struct iscsi_endpoint *ep; \ |
| 4012 | ssize_t rc; \ |
| 4013 | \ |
| 4014 | /* \ |
| 4015 | * Need to make sure ep_disconnect does not free the LLD's \ |
| 4016 | * interconnect resources while we are trying to read them. \ |
| 4017 | */ \ |
| 4018 | mutex_lock(&conn->ep_mutex); \ |
| 4019 | ep = conn->ep; \ |
| 4020 | if (!ep && t->ep_connect) { \ |
| 4021 | mutex_unlock(&conn->ep_mutex); \ |
| 4022 | return -ENOTCONN; \ |
| 4023 | } \ |
| 4024 | \ |
| 4025 | if (ep) \ |
| 4026 | rc = t->get_ep_param(ep, param, buf); \ |
| 4027 | else \ |
| 4028 | rc = t->get_conn_param(conn, param, buf); \ |
| 4029 | mutex_unlock(&conn->ep_mutex); \ |
| 4030 | return rc; \ |
| 4031 | } |
| 4032 | |
| 4033 | #define iscsi_conn_ep_attr(field, param) \ |
| 4034 | iscsi_conn_ep_attr_show(param) \ |
| 4035 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \ |
| 4036 | show_conn_ep_param_##param, NULL); |
| 4037 | |
| 4038 | iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS); |
| 4039 | iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT); |
| 4040 | |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 4041 | static struct attribute *iscsi_conn_attrs[] = { |
| 4042 | &dev_attr_conn_max_recv_dlength.attr, |
| 4043 | &dev_attr_conn_max_xmit_dlength.attr, |
| 4044 | &dev_attr_conn_header_digest.attr, |
| 4045 | &dev_attr_conn_data_digest.attr, |
| 4046 | &dev_attr_conn_ifmarker.attr, |
| 4047 | &dev_attr_conn_ofmarker.attr, |
| 4048 | &dev_attr_conn_address.attr, |
| 4049 | &dev_attr_conn_port.attr, |
| 4050 | &dev_attr_conn_exp_statsn.attr, |
| 4051 | &dev_attr_conn_persistent_address.attr, |
| 4052 | &dev_attr_conn_persistent_port.attr, |
| 4053 | &dev_attr_conn_ping_tmo.attr, |
| 4054 | &dev_attr_conn_recv_tmo.attr, |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 4055 | &dev_attr_conn_local_port.attr, |
| 4056 | &dev_attr_conn_statsn.attr, |
| 4057 | &dev_attr_conn_keepalive_tmo.attr, |
| 4058 | &dev_attr_conn_max_segment_size.attr, |
| 4059 | &dev_attr_conn_tcp_timestamp_stat.attr, |
| 4060 | &dev_attr_conn_tcp_wsf_disable.attr, |
| 4061 | &dev_attr_conn_tcp_nagle_disable.attr, |
| 4062 | &dev_attr_conn_tcp_timer_scale.attr, |
| 4063 | &dev_attr_conn_tcp_timestamp_enable.attr, |
| 4064 | &dev_attr_conn_fragment_disable.attr, |
| 4065 | &dev_attr_conn_ipv4_tos.attr, |
| 4066 | &dev_attr_conn_ipv6_traffic_class.attr, |
| 4067 | &dev_attr_conn_ipv6_flow_label.attr, |
| 4068 | &dev_attr_conn_is_fw_assigned_ipv6.attr, |
| 4069 | &dev_attr_conn_tcp_xmit_wsf.attr, |
| 4070 | &dev_attr_conn_tcp_recv_wsf.attr, |
Adheer Chandravanshi | 5af62f2 | 2013-11-22 05:28:20 -0500 | [diff] [blame] | 4071 | &dev_attr_conn_local_ipaddr.attr, |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 4072 | &dev_attr_conn_state.attr, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 4073 | NULL, |
| 4074 | }; |
| 4075 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4076 | static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 4077 | struct attribute *attr, int i) |
| 4078 | { |
| 4079 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 4080 | struct iscsi_cls_conn *conn = transport_class_to_conn(cdev); |
| 4081 | struct iscsi_transport *t = conn->transport; |
| 4082 | int param; |
| 4083 | |
| 4084 | if (attr == &dev_attr_conn_max_recv_dlength.attr) |
| 4085 | param = ISCSI_PARAM_MAX_RECV_DLENGTH; |
| 4086 | else if (attr == &dev_attr_conn_max_xmit_dlength.attr) |
| 4087 | param = ISCSI_PARAM_MAX_XMIT_DLENGTH; |
| 4088 | else if (attr == &dev_attr_conn_header_digest.attr) |
| 4089 | param = ISCSI_PARAM_HDRDGST_EN; |
| 4090 | else if (attr == &dev_attr_conn_data_digest.attr) |
| 4091 | param = ISCSI_PARAM_DATADGST_EN; |
| 4092 | else if (attr == &dev_attr_conn_ifmarker.attr) |
| 4093 | param = ISCSI_PARAM_IFMARKER_EN; |
| 4094 | else if (attr == &dev_attr_conn_ofmarker.attr) |
| 4095 | param = ISCSI_PARAM_OFMARKER_EN; |
| 4096 | else if (attr == &dev_attr_conn_address.attr) |
| 4097 | param = ISCSI_PARAM_CONN_ADDRESS; |
| 4098 | else if (attr == &dev_attr_conn_port.attr) |
| 4099 | param = ISCSI_PARAM_CONN_PORT; |
| 4100 | else if (attr == &dev_attr_conn_exp_statsn.attr) |
| 4101 | param = ISCSI_PARAM_EXP_STATSN; |
| 4102 | else if (attr == &dev_attr_conn_persistent_address.attr) |
| 4103 | param = ISCSI_PARAM_PERSISTENT_ADDRESS; |
| 4104 | else if (attr == &dev_attr_conn_persistent_port.attr) |
| 4105 | param = ISCSI_PARAM_PERSISTENT_PORT; |
| 4106 | else if (attr == &dev_attr_conn_ping_tmo.attr) |
| 4107 | param = ISCSI_PARAM_PING_TMO; |
| 4108 | else if (attr == &dev_attr_conn_recv_tmo.attr) |
| 4109 | param = ISCSI_PARAM_RECV_TMO; |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 4110 | else if (attr == &dev_attr_conn_local_port.attr) |
| 4111 | param = ISCSI_PARAM_LOCAL_PORT; |
| 4112 | else if (attr == &dev_attr_conn_statsn.attr) |
| 4113 | param = ISCSI_PARAM_STATSN; |
| 4114 | else if (attr == &dev_attr_conn_keepalive_tmo.attr) |
| 4115 | param = ISCSI_PARAM_KEEPALIVE_TMO; |
| 4116 | else if (attr == &dev_attr_conn_max_segment_size.attr) |
| 4117 | param = ISCSI_PARAM_MAX_SEGMENT_SIZE; |
| 4118 | else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr) |
| 4119 | param = ISCSI_PARAM_TCP_TIMESTAMP_STAT; |
| 4120 | else if (attr == &dev_attr_conn_tcp_wsf_disable.attr) |
| 4121 | param = ISCSI_PARAM_TCP_WSF_DISABLE; |
| 4122 | else if (attr == &dev_attr_conn_tcp_nagle_disable.attr) |
| 4123 | param = ISCSI_PARAM_TCP_NAGLE_DISABLE; |
| 4124 | else if (attr == &dev_attr_conn_tcp_timer_scale.attr) |
| 4125 | param = ISCSI_PARAM_TCP_TIMER_SCALE; |
| 4126 | else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr) |
| 4127 | param = ISCSI_PARAM_TCP_TIMESTAMP_EN; |
| 4128 | else if (attr == &dev_attr_conn_fragment_disable.attr) |
| 4129 | param = ISCSI_PARAM_IP_FRAGMENT_DISABLE; |
| 4130 | else if (attr == &dev_attr_conn_ipv4_tos.attr) |
| 4131 | param = ISCSI_PARAM_IPV4_TOS; |
| 4132 | else if (attr == &dev_attr_conn_ipv6_traffic_class.attr) |
| 4133 | param = ISCSI_PARAM_IPV6_TC; |
| 4134 | else if (attr == &dev_attr_conn_ipv6_flow_label.attr) |
| 4135 | param = ISCSI_PARAM_IPV6_FLOW_LABEL; |
| 4136 | else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr) |
| 4137 | param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6; |
| 4138 | else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr) |
| 4139 | param = ISCSI_PARAM_TCP_XMIT_WSF; |
| 4140 | else if (attr == &dev_attr_conn_tcp_recv_wsf.attr) |
| 4141 | param = ISCSI_PARAM_TCP_RECV_WSF; |
Adheer Chandravanshi | 5af62f2 | 2013-11-22 05:28:20 -0500 | [diff] [blame] | 4142 | else if (attr == &dev_attr_conn_local_ipaddr.attr) |
| 4143 | param = ISCSI_PARAM_LOCAL_IPADDR; |
Gabriel Krisman Bertazi | 82b8cf4 | 2020-03-17 19:34:22 -0400 | [diff] [blame] | 4144 | else if (attr == &dev_attr_conn_state.attr) |
| 4145 | return S_IRUGO; |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 4146 | else { |
| 4147 | WARN_ONCE(1, "Invalid conn attr"); |
| 4148 | return 0; |
| 4149 | } |
| 4150 | |
| 4151 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 4152 | } |
| 4153 | |
| 4154 | static struct attribute_group iscsi_conn_group = { |
| 4155 | .attrs = iscsi_conn_attrs, |
| 4156 | .is_visible = iscsi_conn_attr_is_visible, |
| 4157 | }; |
| 4158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | /* |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4160 | * iSCSI session attrs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | */ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 4162 | #define iscsi_session_attr_show(param, perm) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4164 | show_session_param_##param(struct device *dev, \ |
| 4165 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4166 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4167 | struct iscsi_cls_session *session = \ |
| 4168 | iscsi_dev_to_session(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4169 | struct iscsi_transport *t = session->transport; \ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 4170 | \ |
| 4171 | if (perm && !capable(CAP_SYS_ADMIN)) \ |
| 4172 | return -EACCES; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 4173 | return t->get_session_param(session, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 4176 | #define iscsi_session_attr(field, param, perm) \ |
| 4177 | iscsi_session_attr_show(param, perm) \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 4178 | static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4179 | NULL); |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 4180 | iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0); |
| 4181 | iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0); |
| 4182 | iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0); |
| 4183 | iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0); |
| 4184 | iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0); |
| 4185 | iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0); |
| 4186 | iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0); |
| 4187 | iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0); |
| 4188 | iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0); |
| 4189 | iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0); |
| 4190 | iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1); |
| 4191 | iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1); |
| 4192 | iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1); |
| 4193 | iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1); |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 4194 | iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1); |
| 4195 | iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1); |
Mike Christie | 4cd49ea | 2007-12-13 12:43:38 -0600 | [diff] [blame] | 4196 | iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0); |
| 4197 | iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0); |
| 4198 | iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0); |
Mike Christie | 3fe5ae8 | 2009-11-11 16:34:33 -0600 | [diff] [blame] | 4199 | iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0); |
Mike Christie | 88dfd34 | 2008-05-21 15:54:16 -0500 | [diff] [blame] | 4200 | iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0); |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 4201 | iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0); |
| 4202 | iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0); |
Eddie Wai | 3b9373e | 2013-06-20 10:21:26 -0700 | [diff] [blame] | 4203 | iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0); |
| 4204 | iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0); |
| 4205 | iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0); |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 4206 | iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0); |
| 4207 | iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0); |
| 4208 | iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0); |
| 4209 | iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0); |
| 4210 | iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0); |
| 4211 | iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0); |
| 4212 | iscsi_session_attr(discovery_auth_optional, |
| 4213 | ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0); |
| 4214 | iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0); |
| 4215 | iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0); |
| 4216 | iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0); |
| 4217 | iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); |
| 4218 | iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); |
| 4219 | iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); |
| 4220 | iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4221 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 4222 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4223 | show_priv_session_state(struct device *dev, struct device_attribute *attr, |
| 4224 | char *buf) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 4225 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4226 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 4227 | return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state)); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 4228 | } |
| 4229 | static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state, |
| 4230 | NULL); |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 4231 | static ssize_t |
| 4232 | show_priv_session_creator(struct device *dev, struct device_attribute *attr, |
| 4233 | char *buf) |
| 4234 | { |
| 4235 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 4236 | return sysfs_emit(buf, "%d\n", session->creator); |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 4237 | } |
| 4238 | static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator, |
| 4239 | NULL); |
Manish Rangankar | 930a9f0 | 2012-11-23 06:58:41 -0500 | [diff] [blame] | 4240 | static ssize_t |
| 4241 | show_priv_session_target_id(struct device *dev, struct device_attribute *attr, |
| 4242 | char *buf) |
| 4243 | { |
| 4244 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 4245 | return sysfs_emit(buf, "%d\n", session->target_id); |
Manish Rangankar | 930a9f0 | 2012-11-23 06:58:41 -0500 | [diff] [blame] | 4246 | } |
| 4247 | static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO, |
| 4248 | show_priv_session_target_id, NULL); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 4249 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4250 | #define iscsi_priv_session_attr_show(field, format) \ |
| 4251 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4252 | show_priv_session_##field(struct device *dev, \ |
| 4253 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4254 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4255 | struct iscsi_cls_session *session = \ |
| 4256 | iscsi_dev_to_session(dev->parent); \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4257 | if (session->field == -1) \ |
Chris Leech | 76d92bf | 2021-02-23 18:00:17 -0800 | [diff] [blame] | 4258 | return sysfs_emit(buf, "off\n"); \ |
| 4259 | return sysfs_emit(buf, format"\n", session->field); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4260 | } |
| 4261 | |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4262 | #define iscsi_priv_session_attr_store(field) \ |
| 4263 | static ssize_t \ |
| 4264 | store_priv_session_##field(struct device *dev, \ |
| 4265 | struct device_attribute *attr, \ |
| 4266 | const char *buf, size_t count) \ |
| 4267 | { \ |
| 4268 | int val; \ |
| 4269 | char *cp; \ |
| 4270 | struct iscsi_cls_session *session = \ |
| 4271 | iscsi_dev_to_session(dev->parent); \ |
| 4272 | if ((session->state == ISCSI_SESSION_FREE) || \ |
| 4273 | (session->state == ISCSI_SESSION_FAILED)) \ |
| 4274 | return -EBUSY; \ |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 4275 | if (strncmp(buf, "off", 3) == 0) { \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4276 | session->field = -1; \ |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 4277 | session->field##_sysfs_override = true; \ |
| 4278 | } else { \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4279 | val = simple_strtoul(buf, &cp, 0); \ |
| 4280 | if (*cp != '\0' && *cp != '\n') \ |
| 4281 | return -EINVAL; \ |
| 4282 | session->field = val; \ |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 4283 | session->field##_sysfs_override = true; \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4284 | } \ |
| 4285 | return count; \ |
| 4286 | } |
| 4287 | |
| 4288 | #define iscsi_priv_session_rw_attr(field, format) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4289 | iscsi_priv_session_attr_show(field, format) \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4290 | iscsi_priv_session_attr_store(field) \ |
Vasiliy Kulikov | 523f3c8 | 2011-02-04 15:24:14 +0300 | [diff] [blame] | 4291 | static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4292 | show_priv_session_##field, \ |
| 4293 | store_priv_session_##field) |
Chris Leech | 9c8108a | 2015-06-16 16:07:13 -0700 | [diff] [blame] | 4294 | |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 4295 | iscsi_priv_session_rw_attr(recovery_tmo, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 4296 | |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4297 | static struct attribute *iscsi_session_attrs[] = { |
| 4298 | &dev_attr_sess_initial_r2t.attr, |
| 4299 | &dev_attr_sess_max_outstanding_r2t.attr, |
| 4300 | &dev_attr_sess_immediate_data.attr, |
| 4301 | &dev_attr_sess_first_burst_len.attr, |
| 4302 | &dev_attr_sess_max_burst_len.attr, |
| 4303 | &dev_attr_sess_data_pdu_in_order.attr, |
| 4304 | &dev_attr_sess_data_seq_in_order.attr, |
| 4305 | &dev_attr_sess_erl.attr, |
| 4306 | &dev_attr_sess_targetname.attr, |
| 4307 | &dev_attr_sess_tpgt.attr, |
| 4308 | &dev_attr_sess_password.attr, |
| 4309 | &dev_attr_sess_password_in.attr, |
| 4310 | &dev_attr_sess_username.attr, |
| 4311 | &dev_attr_sess_username_in.attr, |
| 4312 | &dev_attr_sess_fast_abort.attr, |
| 4313 | &dev_attr_sess_abort_tmo.attr, |
| 4314 | &dev_attr_sess_lu_reset_tmo.attr, |
| 4315 | &dev_attr_sess_tgt_reset_tmo.attr, |
| 4316 | &dev_attr_sess_ifacename.attr, |
| 4317 | &dev_attr_sess_initiatorname.attr, |
| 4318 | &dev_attr_sess_targetalias.attr, |
Eddie Wai | 3b9373e | 2013-06-20 10:21:26 -0700 | [diff] [blame] | 4319 | &dev_attr_sess_boot_root.attr, |
| 4320 | &dev_attr_sess_boot_nic.attr, |
| 4321 | &dev_attr_sess_boot_target.attr, |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4322 | &dev_attr_priv_sess_recovery_tmo.attr, |
| 4323 | &dev_attr_priv_sess_state.attr, |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 4324 | &dev_attr_priv_sess_creator.attr, |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 4325 | &dev_attr_sess_chap_out_idx.attr, |
| 4326 | &dev_attr_sess_chap_in_idx.attr, |
Manish Rangankar | 930a9f0 | 2012-11-23 06:58:41 -0500 | [diff] [blame] | 4327 | &dev_attr_priv_sess_target_id.attr, |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 4328 | &dev_attr_sess_auto_snd_tgt_disable.attr, |
| 4329 | &dev_attr_sess_discovery_session.attr, |
| 4330 | &dev_attr_sess_portal_type.attr, |
| 4331 | &dev_attr_sess_chap_auth.attr, |
| 4332 | &dev_attr_sess_discovery_logout.attr, |
| 4333 | &dev_attr_sess_bidi_chap.attr, |
| 4334 | &dev_attr_sess_discovery_auth_optional.attr, |
| 4335 | &dev_attr_sess_def_time2wait.attr, |
| 4336 | &dev_attr_sess_def_time2retain.attr, |
| 4337 | &dev_attr_sess_isid.attr, |
| 4338 | &dev_attr_sess_tsid.attr, |
| 4339 | &dev_attr_sess_def_taskmgmt_tmo.attr, |
| 4340 | &dev_attr_sess_discovery_parent_idx.attr, |
| 4341 | &dev_attr_sess_discovery_parent_type.attr, |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4342 | NULL, |
| 4343 | }; |
| 4344 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4345 | static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4346 | struct attribute *attr, int i) |
| 4347 | { |
| 4348 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 4349 | struct iscsi_cls_session *session = transport_class_to_session(cdev); |
| 4350 | struct iscsi_transport *t = session->transport; |
| 4351 | int param; |
| 4352 | |
| 4353 | if (attr == &dev_attr_sess_initial_r2t.attr) |
| 4354 | param = ISCSI_PARAM_INITIAL_R2T_EN; |
| 4355 | else if (attr == &dev_attr_sess_max_outstanding_r2t.attr) |
| 4356 | param = ISCSI_PARAM_MAX_R2T; |
| 4357 | else if (attr == &dev_attr_sess_immediate_data.attr) |
| 4358 | param = ISCSI_PARAM_IMM_DATA_EN; |
| 4359 | else if (attr == &dev_attr_sess_first_burst_len.attr) |
| 4360 | param = ISCSI_PARAM_FIRST_BURST; |
| 4361 | else if (attr == &dev_attr_sess_max_burst_len.attr) |
| 4362 | param = ISCSI_PARAM_MAX_BURST; |
| 4363 | else if (attr == &dev_attr_sess_data_pdu_in_order.attr) |
| 4364 | param = ISCSI_PARAM_PDU_INORDER_EN; |
| 4365 | else if (attr == &dev_attr_sess_data_seq_in_order.attr) |
| 4366 | param = ISCSI_PARAM_DATASEQ_INORDER_EN; |
| 4367 | else if (attr == &dev_attr_sess_erl.attr) |
| 4368 | param = ISCSI_PARAM_ERL; |
| 4369 | else if (attr == &dev_attr_sess_targetname.attr) |
| 4370 | param = ISCSI_PARAM_TARGET_NAME; |
| 4371 | else if (attr == &dev_attr_sess_tpgt.attr) |
| 4372 | param = ISCSI_PARAM_TPGT; |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 4373 | else if (attr == &dev_attr_sess_chap_in_idx.attr) |
| 4374 | param = ISCSI_PARAM_CHAP_IN_IDX; |
| 4375 | else if (attr == &dev_attr_sess_chap_out_idx.attr) |
| 4376 | param = ISCSI_PARAM_CHAP_OUT_IDX; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4377 | else if (attr == &dev_attr_sess_password.attr) |
| 4378 | param = ISCSI_PARAM_USERNAME; |
| 4379 | else if (attr == &dev_attr_sess_password_in.attr) |
| 4380 | param = ISCSI_PARAM_USERNAME_IN; |
| 4381 | else if (attr == &dev_attr_sess_username.attr) |
| 4382 | param = ISCSI_PARAM_PASSWORD; |
| 4383 | else if (attr == &dev_attr_sess_username_in.attr) |
| 4384 | param = ISCSI_PARAM_PASSWORD_IN; |
| 4385 | else if (attr == &dev_attr_sess_fast_abort.attr) |
| 4386 | param = ISCSI_PARAM_FAST_ABORT; |
| 4387 | else if (attr == &dev_attr_sess_abort_tmo.attr) |
| 4388 | param = ISCSI_PARAM_ABORT_TMO; |
| 4389 | else if (attr == &dev_attr_sess_lu_reset_tmo.attr) |
| 4390 | param = ISCSI_PARAM_LU_RESET_TMO; |
| 4391 | else if (attr == &dev_attr_sess_tgt_reset_tmo.attr) |
| 4392 | param = ISCSI_PARAM_TGT_RESET_TMO; |
| 4393 | else if (attr == &dev_attr_sess_ifacename.attr) |
| 4394 | param = ISCSI_PARAM_IFACE_NAME; |
| 4395 | else if (attr == &dev_attr_sess_initiatorname.attr) |
| 4396 | param = ISCSI_PARAM_INITIATOR_NAME; |
| 4397 | else if (attr == &dev_attr_sess_targetalias.attr) |
| 4398 | param = ISCSI_PARAM_TARGET_ALIAS; |
Eddie Wai | 3b9373e | 2013-06-20 10:21:26 -0700 | [diff] [blame] | 4399 | else if (attr == &dev_attr_sess_boot_root.attr) |
| 4400 | param = ISCSI_PARAM_BOOT_ROOT; |
| 4401 | else if (attr == &dev_attr_sess_boot_nic.attr) |
| 4402 | param = ISCSI_PARAM_BOOT_NIC; |
| 4403 | else if (attr == &dev_attr_sess_boot_target.attr) |
| 4404 | param = ISCSI_PARAM_BOOT_TARGET; |
Adheer Chandravanshi | ae542ed | 2013-07-01 05:54:11 -0400 | [diff] [blame] | 4405 | else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr) |
| 4406 | param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE; |
| 4407 | else if (attr == &dev_attr_sess_discovery_session.attr) |
| 4408 | param = ISCSI_PARAM_DISCOVERY_SESS; |
| 4409 | else if (attr == &dev_attr_sess_portal_type.attr) |
| 4410 | param = ISCSI_PARAM_PORTAL_TYPE; |
| 4411 | else if (attr == &dev_attr_sess_chap_auth.attr) |
| 4412 | param = ISCSI_PARAM_CHAP_AUTH_EN; |
| 4413 | else if (attr == &dev_attr_sess_discovery_logout.attr) |
| 4414 | param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN; |
| 4415 | else if (attr == &dev_attr_sess_bidi_chap.attr) |
| 4416 | param = ISCSI_PARAM_BIDI_CHAP_EN; |
| 4417 | else if (attr == &dev_attr_sess_discovery_auth_optional.attr) |
| 4418 | param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL; |
| 4419 | else if (attr == &dev_attr_sess_def_time2wait.attr) |
| 4420 | param = ISCSI_PARAM_DEF_TIME2WAIT; |
| 4421 | else if (attr == &dev_attr_sess_def_time2retain.attr) |
| 4422 | param = ISCSI_PARAM_DEF_TIME2RETAIN; |
| 4423 | else if (attr == &dev_attr_sess_isid.attr) |
| 4424 | param = ISCSI_PARAM_ISID; |
| 4425 | else if (attr == &dev_attr_sess_tsid.attr) |
| 4426 | param = ISCSI_PARAM_TSID; |
| 4427 | else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr) |
| 4428 | param = ISCSI_PARAM_DEF_TASKMGMT_TMO; |
| 4429 | else if (attr == &dev_attr_sess_discovery_parent_idx.attr) |
| 4430 | param = ISCSI_PARAM_DISCOVERY_PARENT_IDX; |
| 4431 | else if (attr == &dev_attr_sess_discovery_parent_type.attr) |
| 4432 | param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4433 | else if (attr == &dev_attr_priv_sess_recovery_tmo.attr) |
| 4434 | return S_IRUGO | S_IWUSR; |
| 4435 | else if (attr == &dev_attr_priv_sess_state.attr) |
| 4436 | return S_IRUGO; |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 4437 | else if (attr == &dev_attr_priv_sess_creator.attr) |
| 4438 | return S_IRUGO; |
Manish Rangankar | 930a9f0 | 2012-11-23 06:58:41 -0500 | [diff] [blame] | 4439 | else if (attr == &dev_attr_priv_sess_target_id.attr) |
| 4440 | return S_IRUGO; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4441 | else { |
| 4442 | WARN_ONCE(1, "Invalid session attr"); |
| 4443 | return 0; |
| 4444 | } |
| 4445 | |
| 4446 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 4447 | } |
| 4448 | |
| 4449 | static struct attribute_group iscsi_session_group = { |
| 4450 | .attrs = iscsi_session_attrs, |
| 4451 | .is_visible = iscsi_session_attr_is_visible, |
| 4452 | }; |
| 4453 | |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4454 | /* |
| 4455 | * iSCSI host attrs |
| 4456 | */ |
| 4457 | #define iscsi_host_attr_show(param) \ |
| 4458 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4459 | show_host_param_##param(struct device *dev, \ |
| 4460 | struct device_attribute *attr, char *buf) \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4461 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4462 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4463 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \ |
| 4464 | return priv->iscsi_transport->get_host_param(shost, param, buf); \ |
| 4465 | } |
| 4466 | |
| 4467 | #define iscsi_host_attr(field, param) \ |
| 4468 | iscsi_host_attr_show(param) \ |
| 4469 | static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \ |
| 4470 | NULL); |
| 4471 | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 4472 | iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4473 | iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS); |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 4474 | iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 4475 | iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME); |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 4476 | iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE); |
| 4477 | iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4478 | |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4479 | static struct attribute *iscsi_host_attrs[] = { |
| 4480 | &dev_attr_host_netdev.attr, |
| 4481 | &dev_attr_host_hwaddress.attr, |
| 4482 | &dev_attr_host_ipaddress.attr, |
| 4483 | &dev_attr_host_initiatorname.attr, |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 4484 | &dev_attr_host_port_state.attr, |
| 4485 | &dev_attr_host_port_speed.attr, |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4486 | NULL, |
| 4487 | }; |
| 4488 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4489 | static umode_t iscsi_host_attr_is_visible(struct kobject *kobj, |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4490 | struct attribute *attr, int i) |
| 4491 | { |
| 4492 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 4493 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 4494 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); |
| 4495 | int param; |
| 4496 | |
| 4497 | if (attr == &dev_attr_host_netdev.attr) |
| 4498 | param = ISCSI_HOST_PARAM_NETDEV_NAME; |
| 4499 | else if (attr == &dev_attr_host_hwaddress.attr) |
| 4500 | param = ISCSI_HOST_PARAM_HWADDRESS; |
| 4501 | else if (attr == &dev_attr_host_ipaddress.attr) |
| 4502 | param = ISCSI_HOST_PARAM_IPADDRESS; |
| 4503 | else if (attr == &dev_attr_host_initiatorname.attr) |
| 4504 | param = ISCSI_HOST_PARAM_INITIATOR_NAME; |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 4505 | else if (attr == &dev_attr_host_port_state.attr) |
| 4506 | param = ISCSI_HOST_PARAM_PORT_STATE; |
| 4507 | else if (attr == &dev_attr_host_port_speed.attr) |
| 4508 | param = ISCSI_HOST_PARAM_PORT_SPEED; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4509 | else { |
| 4510 | WARN_ONCE(1, "Invalid host attr"); |
| 4511 | return 0; |
| 4512 | } |
| 4513 | |
| 4514 | return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param); |
| 4515 | } |
| 4516 | |
| 4517 | static struct attribute_group iscsi_host_group = { |
| 4518 | .attrs = iscsi_host_attrs, |
| 4519 | .is_visible = iscsi_host_attr_is_visible, |
| 4520 | }; |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 4521 | |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 4522 | /* convert iscsi_port_speed values to ascii string name */ |
| 4523 | static const struct { |
| 4524 | enum iscsi_port_speed value; |
| 4525 | char *name; |
| 4526 | } iscsi_port_speed_names[] = { |
| 4527 | {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" }, |
| 4528 | {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" }, |
| 4529 | {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" }, |
| 4530 | {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" }, |
| 4531 | {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" }, |
Jitendra Bhivare | f9e4fa4 | 2016-01-20 14:10:57 +0530 | [diff] [blame] | 4532 | {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" }, |
| 4533 | {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" }, |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 4534 | }; |
| 4535 | |
| 4536 | char *iscsi_get_port_speed_name(struct Scsi_Host *shost) |
| 4537 | { |
| 4538 | int i; |
| 4539 | char *speed = "Unknown!"; |
| 4540 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 4541 | uint32_t port_speed = ihost->port_speed; |
| 4542 | |
| 4543 | for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) { |
| 4544 | if (iscsi_port_speed_names[i].value & port_speed) { |
| 4545 | speed = iscsi_port_speed_names[i].name; |
| 4546 | break; |
| 4547 | } |
| 4548 | } |
| 4549 | return speed; |
| 4550 | } |
| 4551 | EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name); |
| 4552 | |
| 4553 | /* convert iscsi_port_state values to ascii string name */ |
| 4554 | static const struct { |
| 4555 | enum iscsi_port_state value; |
| 4556 | char *name; |
| 4557 | } iscsi_port_state_names[] = { |
| 4558 | {ISCSI_PORT_STATE_DOWN, "LINK DOWN" }, |
| 4559 | {ISCSI_PORT_STATE_UP, "LINK UP" }, |
| 4560 | }; |
| 4561 | |
| 4562 | char *iscsi_get_port_state_name(struct Scsi_Host *shost) |
| 4563 | { |
| 4564 | int i; |
| 4565 | char *state = "Unknown!"; |
| 4566 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 4567 | uint32_t port_state = ihost->port_state; |
| 4568 | |
| 4569 | for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) { |
| 4570 | if (iscsi_port_state_names[i].value & port_state) { |
| 4571 | state = iscsi_port_state_names[i].name; |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | return state; |
| 4576 | } |
| 4577 | EXPORT_SYMBOL_GPL(iscsi_get_port_state_name); |
| 4578 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4579 | static int iscsi_session_match(struct attribute_container *cont, |
| 4580 | struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4582 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | struct Scsi_Host *shost; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4584 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4586 | if (!iscsi_is_session_dev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | return 0; |
| 4588 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4589 | session = iscsi_dev_to_session(dev); |
| 4590 | shost = iscsi_session_to_shost(session); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4591 | if (!shost->transportt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | return 0; |
| 4593 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4594 | priv = to_iscsi_internal(shost->transportt); |
| 4595 | if (priv->session_cont.ac.class != &iscsi_session_class.class) |
| 4596 | return 0; |
| 4597 | |
| 4598 | return &priv->session_cont.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4601 | static int iscsi_conn_match(struct attribute_container *cont, |
| 4602 | struct device *dev) |
| 4603 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4604 | struct iscsi_cls_session *session; |
| 4605 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4606 | struct Scsi_Host *shost; |
| 4607 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4609 | if (!iscsi_is_conn_dev(dev)) |
| 4610 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4612 | conn = iscsi_dev_to_conn(dev); |
| 4613 | session = iscsi_dev_to_session(conn->dev.parent); |
| 4614 | shost = iscsi_session_to_shost(session); |
| 4615 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4616 | if (!shost->transportt) |
| 4617 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4619 | priv = to_iscsi_internal(shost->transportt); |
| 4620 | if (priv->conn_cont.ac.class != &iscsi_connection_class.class) |
| 4621 | return 0; |
| 4622 | |
| 4623 | return &priv->conn_cont.ac == cont; |
| 4624 | } |
| 4625 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4626 | static int iscsi_host_match(struct attribute_container *cont, |
| 4627 | struct device *dev) |
| 4628 | { |
| 4629 | struct Scsi_Host *shost; |
| 4630 | struct iscsi_internal *priv; |
| 4631 | |
| 4632 | if (!scsi_is_host_device(dev)) |
| 4633 | return 0; |
| 4634 | |
| 4635 | shost = dev_to_shost(dev); |
| 4636 | if (!shost->transportt || |
| 4637 | shost->transportt->host_attrs.ac.class != &iscsi_host_class.class) |
| 4638 | return 0; |
| 4639 | |
| 4640 | priv = to_iscsi_internal(shost->transportt); |
| 4641 | return &priv->t.host_attrs.ac == cont; |
| 4642 | } |
| 4643 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4644 | struct scsi_transport_template * |
| 4645 | iscsi_register_transport(struct iscsi_transport *tt) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4646 | { |
| 4647 | struct iscsi_internal *priv; |
| 4648 | unsigned long flags; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4649 | int err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4650 | |
| 4651 | BUG_ON(!tt); |
| 4652 | |
| 4653 | priv = iscsi_if_transport_lookup(tt); |
| 4654 | if (priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4655 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4656 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 4657 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4658 | if (!priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4659 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4660 | INIT_LIST_HEAD(&priv->list); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4661 | priv->iscsi_transport = tt; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4662 | priv->t.user_scan = iscsi_user_scan; |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 4663 | priv->t.create_work_queue = 1; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4664 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4665 | priv->dev.class = &iscsi_transport_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 4666 | dev_set_name(&priv->dev, "%s", tt->name); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4667 | err = device_register(&priv->dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4668 | if (err) |
| 4669 | goto free_priv; |
| 4670 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4671 | err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4672 | if (err) |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4673 | goto unregister_dev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4674 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4675 | /* host parameters */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4676 | priv->t.host_attrs.ac.class = &iscsi_host_class.class; |
| 4677 | priv->t.host_attrs.ac.match = iscsi_host_match; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 4678 | priv->t.host_attrs.ac.grp = &iscsi_host_group; |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 4679 | priv->t.host_size = sizeof(struct iscsi_cls_host); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4680 | transport_container_register(&priv->t.host_attrs); |
| 4681 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4682 | /* connection parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4683 | priv->conn_cont.ac.class = &iscsi_connection_class.class; |
| 4684 | priv->conn_cont.ac.match = iscsi_conn_match; |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 4685 | priv->conn_cont.ac.grp = &iscsi_conn_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4686 | transport_container_register(&priv->conn_cont); |
| 4687 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4688 | /* session parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4689 | priv->session_cont.ac.class = &iscsi_session_class.class; |
| 4690 | priv->session_cont.ac.match = iscsi_session_match; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 4691 | priv->session_cont.ac.grp = &iscsi_session_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4692 | transport_container_register(&priv->session_cont); |
| 4693 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4694 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 4695 | list_add(&priv->list, &iscsi_transports); |
| 4696 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4698 | printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4699 | return &priv->t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4701 | unregister_dev: |
| 4702 | device_unregister(&priv->dev); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 4703 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4704 | free_priv: |
| 4705 | kfree(priv); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 4706 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4708 | EXPORT_SYMBOL_GPL(iscsi_register_transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4710 | int iscsi_unregister_transport(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4712 | struct iscsi_internal *priv; |
| 4713 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4715 | BUG_ON(!tt); |
| 4716 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 4717 | mutex_lock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4718 | |
| 4719 | priv = iscsi_if_transport_lookup(tt); |
| 4720 | BUG_ON (!priv); |
| 4721 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4722 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 4723 | list_del(&priv->list); |
| 4724 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 4725 | |
| 4726 | transport_container_unregister(&priv->conn_cont); |
| 4727 | transport_container_unregister(&priv->session_cont); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4728 | transport_container_unregister(&priv->t.host_attrs); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4729 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4730 | sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group); |
| 4731 | device_unregister(&priv->dev); |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 4732 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4733 | |
| 4734 | return 0; |
| 4735 | } |
| 4736 | EXPORT_SYMBOL_GPL(iscsi_unregister_transport); |
| 4737 | |
Fred Herard | c2332b0 | 2018-11-21 12:04:43 -0500 | [diff] [blame] | 4738 | void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *), |
| 4739 | struct device *dev, const char *fmt, ...) |
| 4740 | { |
| 4741 | struct va_format vaf; |
| 4742 | va_list args; |
| 4743 | |
| 4744 | va_start(args, fmt); |
| 4745 | vaf.fmt = fmt; |
| 4746 | vaf.va = &args; |
| 4747 | trace(dev, &vaf); |
| 4748 | va_end(args); |
| 4749 | } |
| 4750 | EXPORT_SYMBOL_GPL(iscsi_dbg_trace); |
| 4751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | static __init int iscsi_transport_init(void) |
| 4753 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4754 | int err; |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 4755 | struct netlink_kernel_cfg cfg = { |
| 4756 | .groups = 1, |
| 4757 | .input = iscsi_if_rx, |
| 4758 | }; |
Meelis Roos | 0949260 | 2006-12-17 12:10:26 -0600 | [diff] [blame] | 4759 | printk(KERN_INFO "Loading iSCSI transport class v%s.\n", |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 4760 | ISCSI_TRANSPORT_VERSION); |
| 4761 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 4762 | atomic_set(&iscsi_session_nr, 0); |
| 4763 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4764 | err = class_register(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | if (err) |
| 4766 | return err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4767 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 4768 | err = class_register(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4769 | if (err) |
| 4770 | goto unregister_transport_class; |
| 4771 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 4772 | err = class_register(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 4773 | if (err) |
| 4774 | goto unregister_endpoint_class; |
| 4775 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 4776 | err = transport_class_register(&iscsi_host_class); |
| 4777 | if (err) |
| 4778 | goto unregister_iface_class; |
| 4779 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4780 | err = transport_class_register(&iscsi_connection_class); |
| 4781 | if (err) |
| 4782 | goto unregister_host_class; |
| 4783 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4784 | err = transport_class_register(&iscsi_session_class); |
| 4785 | if (err) |
| 4786 | goto unregister_conn_class; |
| 4787 | |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 4788 | err = bus_register(&iscsi_flashnode_bus); |
| 4789 | if (err) |
| 4790 | goto unregister_session_class; |
| 4791 | |
Pablo Neira Ayuso | 9f00d97 | 2012-09-08 02:53:54 +0000 | [diff] [blame] | 4792 | nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4793 | if (!nls) { |
| 4794 | err = -ENOBUFS; |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 4795 | goto unregister_flashnode_bus; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Bob Liu | 3ce4196 | 2020-05-05 09:19:08 +0800 | [diff] [blame] | 4798 | iscsi_eh_timer_workq = alloc_workqueue("%s", |
| 4799 | WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND, |
Bob Liu | 1a98262 | 2020-07-01 11:07:44 +0800 | [diff] [blame] | 4800 | 1, "iscsi_eh"); |
Wei Yongjun | bcab2cc | 2013-04-19 09:23:28 +0800 | [diff] [blame] | 4801 | if (!iscsi_eh_timer_workq) { |
| 4802 | err = -ENOMEM; |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 4803 | goto release_nls; |
Wei Yongjun | bcab2cc | 2013-04-19 09:23:28 +0800 | [diff] [blame] | 4804 | } |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 4805 | |
Bob Liu | 919a295 | 2020-07-03 13:16:03 +0800 | [diff] [blame] | 4806 | iscsi_destroy_workq = alloc_workqueue("%s", |
| 4807 | WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND, |
| 4808 | 1, "iscsi_destroy"); |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 4809 | if (!iscsi_destroy_workq) { |
| 4810 | err = -ENOMEM; |
| 4811 | goto destroy_wq; |
| 4812 | } |
| 4813 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 4814 | return 0; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4815 | |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 4816 | destroy_wq: |
| 4817 | destroy_workqueue(iscsi_eh_timer_workq); |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 4818 | release_nls: |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 4819 | netlink_kernel_release(nls); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 4820 | unregister_flashnode_bus: |
| 4821 | bus_unregister(&iscsi_flashnode_bus); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4822 | unregister_session_class: |
| 4823 | transport_class_unregister(&iscsi_session_class); |
| 4824 | unregister_conn_class: |
| 4825 | transport_class_unregister(&iscsi_connection_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4826 | unregister_host_class: |
| 4827 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 4828 | unregister_iface_class: |
| 4829 | class_unregister(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 4830 | unregister_endpoint_class: |
| 4831 | class_unregister(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4832 | unregister_transport_class: |
| 4833 | class_unregister(&iscsi_transport_class); |
| 4834 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | static void __exit iscsi_transport_exit(void) |
| 4838 | { |
Frank Mayhar | cc6b32e | 2020-02-27 14:59:45 -0500 | [diff] [blame] | 4839 | destroy_workqueue(iscsi_destroy_workq); |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 4840 | destroy_workqueue(iscsi_eh_timer_workq); |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 4841 | netlink_kernel_release(nls); |
Adheer Chandravanshi | c6a4bb2 | 2013-03-22 07:41:29 -0400 | [diff] [blame] | 4842 | bus_unregister(&iscsi_flashnode_bus); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4843 | transport_class_unregister(&iscsi_connection_class); |
| 4844 | transport_class_unregister(&iscsi_session_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 4845 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 4846 | class_unregister(&iscsi_endpoint_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 4847 | class_unregister(&iscsi_iface_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4848 | class_unregister(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | module_init(iscsi_transport_init); |
| 4852 | module_exit(iscsi_transport_exit); |
| 4853 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 4854 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, " |
| 4855 | "Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 4856 | "Alex Aizman <itn780@yahoo.com>"); |
| 4857 | MODULE_DESCRIPTION("iSCSI Transport Interface"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | MODULE_LICENSE("GPL"); |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 4859 | MODULE_VERSION(ISCSI_TRANSPORT_VERSION); |
Stephen Hemminger | 058548a | 2010-12-09 09:37:56 -0800 | [diff] [blame] | 4860 | MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI); |