Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * iSCSI transport class definitions |
| 3 | * |
| 4 | * Copyright (C) IBM Corporation, 2004 |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 5 | * Copyright (C) Mike Christie, 2004 - 2005 |
| 6 | * Copyright (C) Dmitry Yusupov, 2004 - 2005 |
| 7 | * Copyright (C) Alex Aizman, 2004 - 2005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | #include <linux/module.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 26 | #include <linux/bsg-lib.h> |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 27 | #include <linux/idr.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 28 | #include <net/tcp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| 30 | #include <scsi/scsi_host.h> |
| 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_transport.h> |
| 33 | #include <scsi/scsi_transport_iscsi.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 34 | #include <scsi/iscsi_if.h> |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 35 | #include <scsi/scsi_cmnd.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 36 | #include <scsi/scsi_bsg_iscsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Mike Christie | 4c2133c | 2008-06-16 10:11:34 -0500 | [diff] [blame] | 38 | #define ISCSI_TRANSPORT_VERSION "2.0-870" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 40 | static int dbg_session; |
| 41 | module_param_named(debug_session, dbg_session, int, |
| 42 | S_IRUGO | S_IWUSR); |
| 43 | MODULE_PARM_DESC(debug_session, |
| 44 | "Turn on debugging for sessions in scsi_transport_iscsi " |
| 45 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 46 | "is off."); |
| 47 | |
| 48 | static int dbg_conn; |
| 49 | module_param_named(debug_conn, dbg_conn, int, |
| 50 | S_IRUGO | S_IWUSR); |
| 51 | MODULE_PARM_DESC(debug_conn, |
| 52 | "Turn on debugging for connections in scsi_transport_iscsi " |
| 53 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 54 | "is off."); |
| 55 | |
| 56 | #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \ |
| 57 | do { \ |
| 58 | if (dbg_session) \ |
| 59 | iscsi_cls_session_printk(KERN_INFO, _session, \ |
| 60 | "%s: " dbg_fmt, \ |
| 61 | __func__, ##arg); \ |
| 62 | } while (0); |
| 63 | |
| 64 | #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \ |
| 65 | do { \ |
| 66 | if (dbg_conn) \ |
| 67 | iscsi_cls_conn_printk(KERN_INFO, _conn, \ |
| 68 | "%s: " dbg_fmt, \ |
| 69 | __func__, ##arg); \ |
| 70 | } while (0); |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct iscsi_internal { |
| 73 | struct scsi_transport_template t; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 74 | struct iscsi_transport *iscsi_transport; |
| 75 | struct list_head list; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 76 | struct device dev; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 77 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 78 | struct transport_container conn_cont; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 79 | struct transport_container session_cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 82 | 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] | 83 | static struct workqueue_struct *iscsi_eh_timer_workq; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 84 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 85 | static DEFINE_IDA(iscsi_sess_ida); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 86 | /* |
| 87 | * list of registered transports and lock that must |
| 88 | * be held while accessing list. The iscsi_transport_lock must |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 89 | * be acquired after the rx_queue_mutex. |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 90 | */ |
| 91 | static LIST_HEAD(iscsi_transports); |
| 92 | static DEFINE_SPINLOCK(iscsi_transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 94 | #define to_iscsi_internal(tmpl) \ |
| 95 | container_of(tmpl, struct iscsi_internal, t) |
| 96 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 97 | #define dev_to_iscsi_internal(_dev) \ |
| 98 | container_of(_dev, struct iscsi_internal, dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 99 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 100 | static void iscsi_transport_release(struct device *dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 101 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 102 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 103 | kfree(priv); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * iscsi_transport_class represents the iscsi_transports that are |
| 108 | * registered. |
| 109 | */ |
| 110 | static struct class iscsi_transport_class = { |
| 111 | .name = "iscsi_transport", |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 112 | .dev_release = iscsi_transport_release, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 116 | show_transport_handle(struct device *dev, struct device_attribute *attr, |
| 117 | char *buf) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 118 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 119 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Mike Christie | 762e2bf | 2005-09-12 21:01:46 -0500 | [diff] [blame] | 120 | return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 121 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 122 | static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 123 | |
| 124 | #define show_transport_attr(name, format) \ |
| 125 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 126 | show_transport_##name(struct device *dev, \ |
| 127 | struct device_attribute *attr,char *buf) \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 128 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 129 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 130 | return sprintf(buf, format"\n", priv->iscsi_transport->name); \ |
| 131 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 132 | static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 133 | |
| 134 | show_transport_attr(caps, "0x%x"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 135 | |
| 136 | static struct attribute *iscsi_transport_attrs[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 137 | &dev_attr_handle.attr, |
| 138 | &dev_attr_caps.attr, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 139 | NULL, |
| 140 | }; |
| 141 | |
| 142 | static struct attribute_group iscsi_transport_group = { |
| 143 | .attrs = iscsi_transport_attrs, |
| 144 | }; |
| 145 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 146 | /* |
| 147 | * iSCSI endpoint attrs |
| 148 | */ |
| 149 | #define iscsi_dev_to_endpoint(_dev) \ |
| 150 | container_of(_dev, struct iscsi_endpoint, dev) |
| 151 | |
| 152 | #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 153 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 154 | __ATTR(_name,_mode,_show,_store) |
| 155 | |
| 156 | static void iscsi_endpoint_release(struct device *dev) |
| 157 | { |
| 158 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
| 159 | kfree(ep); |
| 160 | } |
| 161 | |
| 162 | static struct class iscsi_endpoint_class = { |
| 163 | .name = "iscsi_endpoint", |
| 164 | .dev_release = iscsi_endpoint_release, |
| 165 | }; |
| 166 | |
| 167 | static ssize_t |
| 168 | show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf) |
| 169 | { |
| 170 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 171 | return sprintf(buf, "%llu\n", (unsigned long long) ep->id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 172 | } |
| 173 | static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL); |
| 174 | |
| 175 | static struct attribute *iscsi_endpoint_attrs[] = { |
| 176 | &dev_attr_ep_handle.attr, |
| 177 | NULL, |
| 178 | }; |
| 179 | |
| 180 | static struct attribute_group iscsi_endpoint_group = { |
| 181 | .attrs = iscsi_endpoint_attrs, |
| 182 | }; |
| 183 | |
| 184 | #define ISCSI_MAX_EPID -1 |
| 185 | |
| 186 | static int iscsi_match_epid(struct device *dev, void *data) |
| 187 | { |
| 188 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 189 | uint64_t *epid = (uint64_t *) data; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 190 | |
| 191 | return *epid == ep->id; |
| 192 | } |
| 193 | |
| 194 | struct iscsi_endpoint * |
| 195 | iscsi_create_endpoint(int dd_size) |
| 196 | { |
| 197 | struct device *dev; |
| 198 | struct iscsi_endpoint *ep; |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 199 | uint64_t id; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 200 | int err; |
| 201 | |
| 202 | for (id = 1; id < ISCSI_MAX_EPID; id++) { |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 203 | dev = class_find_device(&iscsi_endpoint_class, NULL, &id, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 204 | iscsi_match_epid); |
| 205 | if (!dev) |
| 206 | break; |
| 207 | } |
| 208 | if (id == ISCSI_MAX_EPID) { |
| 209 | printk(KERN_ERR "Too many connections. Max supported %u\n", |
| 210 | ISCSI_MAX_EPID - 1); |
| 211 | return NULL; |
| 212 | } |
| 213 | |
| 214 | ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL); |
| 215 | if (!ep) |
| 216 | return NULL; |
| 217 | |
| 218 | ep->id = id; |
| 219 | ep->dev.class = &iscsi_endpoint_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 220 | dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 221 | err = device_register(&ep->dev); |
| 222 | if (err) |
| 223 | goto free_ep; |
| 224 | |
| 225 | err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 226 | if (err) |
| 227 | goto unregister_dev; |
| 228 | |
| 229 | if (dd_size) |
| 230 | ep->dd_data = &ep[1]; |
| 231 | return ep; |
| 232 | |
| 233 | unregister_dev: |
| 234 | device_unregister(&ep->dev); |
| 235 | return NULL; |
| 236 | |
| 237 | free_ep: |
| 238 | kfree(ep); |
| 239 | return NULL; |
| 240 | } |
| 241 | EXPORT_SYMBOL_GPL(iscsi_create_endpoint); |
| 242 | |
| 243 | void iscsi_destroy_endpoint(struct iscsi_endpoint *ep) |
| 244 | { |
| 245 | sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 246 | device_unregister(&ep->dev); |
| 247 | } |
| 248 | EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint); |
| 249 | |
| 250 | struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) |
| 251 | { |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 252 | struct iscsi_endpoint *ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 253 | struct device *dev; |
| 254 | |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 255 | dev = class_find_device(&iscsi_endpoint_class, NULL, &handle, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 256 | iscsi_match_epid); |
| 257 | if (!dev) |
| 258 | return NULL; |
| 259 | |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 260 | ep = iscsi_dev_to_endpoint(dev); |
| 261 | /* |
| 262 | * we can drop this now because the interface will prevent |
| 263 | * removals and lookups from racing. |
| 264 | */ |
| 265 | put_device(dev); |
| 266 | return ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 267 | } |
| 268 | EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint); |
| 269 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 270 | /* |
| 271 | * Interface to display network param to sysfs |
| 272 | */ |
| 273 | |
| 274 | static void iscsi_iface_release(struct device *dev) |
| 275 | { |
| 276 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 277 | struct device *parent = iface->dev.parent; |
| 278 | |
| 279 | kfree(iface); |
| 280 | put_device(parent); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | static struct class iscsi_iface_class = { |
| 285 | .name = "iscsi_iface", |
| 286 | .dev_release = iscsi_iface_release, |
| 287 | }; |
| 288 | |
| 289 | #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \ |
| 290 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 291 | __ATTR(_name, _mode, _show, _store) |
| 292 | |
| 293 | /* iface attrs show */ |
| 294 | #define iscsi_iface_attr_show(type, name, param_type, param) \ |
| 295 | static ssize_t \ |
| 296 | show_##type##_##name(struct device *dev, struct device_attribute *attr, \ |
| 297 | char *buf) \ |
| 298 | { \ |
| 299 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \ |
| 300 | struct iscsi_transport *t = iface->transport; \ |
| 301 | return t->get_iface_param(iface, param_type, param, buf); \ |
| 302 | } \ |
| 303 | |
| 304 | #define iscsi_iface_net_attr(type, name, param) \ |
| 305 | iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \ |
| 306 | static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL); |
| 307 | |
| 308 | /* generic read only ipvi4 attribute */ |
| 309 | iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR); |
| 310 | iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW); |
| 311 | iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET); |
| 312 | iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO); |
| 313 | |
| 314 | /* generic read only ipv6 attribute */ |
| 315 | iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR); |
| 316 | iscsi_iface_net_attr(ipv6_iface, link_local_addr, ISCSI_NET_PARAM_IPV6_LINKLOCAL); |
| 317 | iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER); |
| 318 | iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg, |
| 319 | ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG); |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 320 | iscsi_iface_net_attr(ipv6_iface, link_local_autocfg, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 321 | ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG); |
| 322 | |
| 323 | /* common read only iface attribute */ |
| 324 | iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE); |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 325 | iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID); |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 326 | iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY); |
| 327 | iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED); |
Vikas Chaudhary | 8c7d40f | 2011-08-01 03:26:12 -0700 | [diff] [blame] | 328 | iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU); |
Vikas Chaudhary | fcb5124 | 2011-08-01 03:26:18 -0700 | [diff] [blame] | 329 | iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 330 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 331 | static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 332 | struct attribute *attr, int i) |
| 333 | { |
| 334 | struct device *dev = container_of(kobj, struct device, kobj); |
| 335 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 336 | struct iscsi_transport *t = iface->transport; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 337 | int param; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 338 | |
| 339 | if (attr == &dev_attr_iface_enabled.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 340 | param = ISCSI_NET_PARAM_IFACE_ENABLE; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 341 | else if (attr == &dev_attr_iface_vlan_id.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 342 | param = ISCSI_NET_PARAM_VLAN_ID; |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 343 | else if (attr == &dev_attr_iface_vlan_priority.attr) |
| 344 | param = ISCSI_NET_PARAM_VLAN_PRIORITY; |
| 345 | else if (attr == &dev_attr_iface_vlan_enabled.attr) |
| 346 | param = ISCSI_NET_PARAM_VLAN_ENABLED; |
Vikas Chaudhary | 8c7d40f | 2011-08-01 03:26:12 -0700 | [diff] [blame] | 347 | else if (attr == &dev_attr_iface_mtu.attr) |
| 348 | param = ISCSI_NET_PARAM_MTU; |
Vikas Chaudhary | fcb5124 | 2011-08-01 03:26:18 -0700 | [diff] [blame] | 349 | else if (attr == &dev_attr_iface_port.attr) |
| 350 | param = ISCSI_NET_PARAM_PORT; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 351 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 352 | if (attr == &dev_attr_ipv4_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 353 | param = ISCSI_NET_PARAM_IPV4_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 354 | else if (attr == &dev_attr_ipv4_iface_gateway.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 355 | param = ISCSI_NET_PARAM_IPV4_GW; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 356 | else if (attr == &dev_attr_ipv4_iface_subnet.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 357 | param = ISCSI_NET_PARAM_IPV4_SUBNET; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 358 | else if (attr == &dev_attr_ipv4_iface_bootproto.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 359 | param = ISCSI_NET_PARAM_IPV4_BOOTPROTO; |
| 360 | else |
| 361 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 362 | } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) { |
| 363 | if (attr == &dev_attr_ipv6_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 364 | param = ISCSI_NET_PARAM_IPV6_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 365 | else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 366 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 367 | else if (attr == &dev_attr_ipv6_iface_router_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 368 | param = ISCSI_NET_PARAM_IPV6_ROUTER; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 369 | else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 370 | param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG; |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 371 | else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 372 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG; |
| 373 | else |
| 374 | return 0; |
| 375 | } else { |
| 376 | WARN_ONCE(1, "Invalid iface attr"); |
| 377 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 378 | } |
| 379 | |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 380 | return t->attr_is_visible(ISCSI_NET_PARAM, param); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static struct attribute *iscsi_iface_attrs[] = { |
| 384 | &dev_attr_iface_enabled.attr, |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 385 | &dev_attr_iface_vlan_id.attr, |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 386 | &dev_attr_iface_vlan_priority.attr, |
| 387 | &dev_attr_iface_vlan_enabled.attr, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 388 | &dev_attr_ipv4_iface_ipaddress.attr, |
| 389 | &dev_attr_ipv4_iface_gateway.attr, |
| 390 | &dev_attr_ipv4_iface_subnet.attr, |
| 391 | &dev_attr_ipv4_iface_bootproto.attr, |
| 392 | &dev_attr_ipv6_iface_ipaddress.attr, |
| 393 | &dev_attr_ipv6_iface_link_local_addr.attr, |
| 394 | &dev_attr_ipv6_iface_router_addr.attr, |
| 395 | &dev_attr_ipv6_iface_ipaddr_autocfg.attr, |
Mike Christie | 88f4f51 | 2011-10-06 03:56:58 -0500 | [diff] [blame] | 396 | &dev_attr_ipv6_iface_link_local_autocfg.attr, |
Vikas Chaudhary | 8c7d40f | 2011-08-01 03:26:12 -0700 | [diff] [blame] | 397 | &dev_attr_iface_mtu.attr, |
Vikas Chaudhary | fcb5124 | 2011-08-01 03:26:18 -0700 | [diff] [blame] | 398 | &dev_attr_iface_port.attr, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 399 | NULL, |
| 400 | }; |
| 401 | |
| 402 | static struct attribute_group iscsi_iface_group = { |
| 403 | .attrs = iscsi_iface_attrs, |
| 404 | .is_visible = iscsi_iface_attr_is_visible, |
| 405 | }; |
| 406 | |
| 407 | struct iscsi_iface * |
| 408 | iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 409 | uint32_t iface_type, uint32_t iface_num, int dd_size) |
| 410 | { |
| 411 | struct iscsi_iface *iface; |
| 412 | int err; |
| 413 | |
| 414 | iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL); |
| 415 | if (!iface) |
| 416 | return NULL; |
| 417 | |
| 418 | iface->transport = transport; |
| 419 | iface->iface_type = iface_type; |
| 420 | iface->iface_num = iface_num; |
| 421 | iface->dev.release = iscsi_iface_release; |
| 422 | iface->dev.class = &iscsi_iface_class; |
| 423 | /* parent reference released in iscsi_iface_release */ |
| 424 | iface->dev.parent = get_device(&shost->shost_gendev); |
| 425 | if (iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 426 | dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no, |
| 427 | iface_num); |
| 428 | else |
| 429 | dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no, |
| 430 | iface_num); |
| 431 | |
| 432 | err = device_register(&iface->dev); |
| 433 | if (err) |
| 434 | goto free_iface; |
| 435 | |
| 436 | err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group); |
| 437 | if (err) |
| 438 | goto unreg_iface; |
| 439 | |
| 440 | if (dd_size) |
| 441 | iface->dd_data = &iface[1]; |
| 442 | return iface; |
| 443 | |
| 444 | unreg_iface: |
| 445 | device_unregister(&iface->dev); |
| 446 | return NULL; |
| 447 | |
| 448 | free_iface: |
| 449 | put_device(iface->dev.parent); |
| 450 | kfree(iface); |
| 451 | return NULL; |
| 452 | } |
| 453 | EXPORT_SYMBOL_GPL(iscsi_create_iface); |
| 454 | |
| 455 | void iscsi_destroy_iface(struct iscsi_iface *iface) |
| 456 | { |
| 457 | sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group); |
| 458 | device_unregister(&iface->dev); |
| 459 | } |
| 460 | EXPORT_SYMBOL_GPL(iscsi_destroy_iface); |
| 461 | |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 462 | /* |
| 463 | * BSG support |
| 464 | */ |
| 465 | /** |
| 466 | * iscsi_bsg_host_dispatch - Dispatch command to LLD. |
| 467 | * @job: bsg job to be processed |
| 468 | */ |
| 469 | static int iscsi_bsg_host_dispatch(struct bsg_job *job) |
| 470 | { |
| 471 | struct Scsi_Host *shost = iscsi_job_to_shost(job); |
| 472 | struct iscsi_bsg_request *req = job->request; |
| 473 | struct iscsi_bsg_reply *reply = job->reply; |
| 474 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 475 | int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ |
| 476 | int ret; |
| 477 | |
| 478 | /* check if we have the msgcode value at least */ |
| 479 | if (job->request_len < sizeof(uint32_t)) { |
| 480 | ret = -ENOMSG; |
| 481 | goto fail_host_msg; |
| 482 | } |
| 483 | |
| 484 | /* Validate the host command */ |
| 485 | switch (req->msgcode) { |
| 486 | case ISCSI_BSG_HST_VENDOR: |
| 487 | cmdlen += sizeof(struct iscsi_bsg_host_vendor); |
| 488 | if ((shost->hostt->vendor_id == 0L) || |
| 489 | (req->rqst_data.h_vendor.vendor_id != |
| 490 | shost->hostt->vendor_id)) { |
| 491 | ret = -ESRCH; |
| 492 | goto fail_host_msg; |
| 493 | } |
| 494 | break; |
| 495 | default: |
| 496 | ret = -EBADR; |
| 497 | goto fail_host_msg; |
| 498 | } |
| 499 | |
| 500 | /* check if we really have all the request data needed */ |
| 501 | if (job->request_len < cmdlen) { |
| 502 | ret = -ENOMSG; |
| 503 | goto fail_host_msg; |
| 504 | } |
| 505 | |
| 506 | ret = i->iscsi_transport->bsg_request(job); |
| 507 | if (!ret) |
| 508 | return 0; |
| 509 | |
| 510 | fail_host_msg: |
| 511 | /* return the errno failure code as the only status */ |
| 512 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 513 | reply->reply_payload_rcv_len = 0; |
| 514 | reply->result = ret; |
| 515 | job->reply_len = sizeof(uint32_t); |
| 516 | bsg_job_done(job, ret, 0); |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests |
| 522 | * @shost: shost for iscsi_host |
Marcos Paulo de Souza | eae627e | 2011-11-02 11:17:17 -0200 | [diff] [blame] | 523 | * @ihost: iscsi_cls_host adding the structures to |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 524 | */ |
| 525 | static int |
| 526 | iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) |
| 527 | { |
| 528 | struct device *dev = &shost->shost_gendev; |
| 529 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 530 | struct request_queue *q; |
| 531 | char bsg_name[20]; |
| 532 | int ret; |
| 533 | |
| 534 | if (!i->iscsi_transport->bsg_request) |
| 535 | return -ENOTSUPP; |
| 536 | |
| 537 | snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no); |
| 538 | |
| 539 | q = __scsi_alloc_queue(shost, bsg_request_fn); |
| 540 | if (!q) |
| 541 | return -ENOMEM; |
| 542 | |
| 543 | ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0); |
| 544 | if (ret) { |
| 545 | shost_printk(KERN_ERR, shost, "bsg interface failed to " |
| 546 | "initialize - no request queue\n"); |
| 547 | blk_cleanup_queue(q); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | ihost->bsg_q = q; |
| 552 | return 0; |
| 553 | } |
| 554 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 555 | static int iscsi_setup_host(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 556 | struct device *cdev) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 557 | { |
| 558 | struct Scsi_Host *shost = dev_to_shost(dev); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 559 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 560 | |
| 561 | memset(ihost, 0, sizeof(*ihost)); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 562 | atomic_set(&ihost->nr_scans, 0); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 563 | mutex_init(&ihost->mutex); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 564 | |
| 565 | iscsi_bsg_host_add(shost, ihost); |
| 566 | /* ignore any bsg add error - we just can't do sgio */ |
| 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static int iscsi_remove_host(struct transport_container *tc, |
| 572 | struct device *dev, struct device *cdev) |
| 573 | { |
| 574 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 575 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 576 | |
| 577 | if (ihost->bsg_q) { |
Tejun Heo | 86072d8 | 2012-06-04 20:40:54 -0700 | [diff] [blame] | 578 | bsg_unregister_queue(ihost->bsg_q); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 579 | blk_cleanup_queue(ihost->bsg_q); |
| 580 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static DECLARE_TRANSPORT_CLASS(iscsi_host_class, |
| 585 | "iscsi_host", |
| 586 | iscsi_setup_host, |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame] | 587 | iscsi_remove_host, |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 588 | NULL); |
| 589 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 590 | static DECLARE_TRANSPORT_CLASS(iscsi_session_class, |
| 591 | "iscsi_session", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | NULL, |
| 593 | NULL, |
| 594 | NULL); |
| 595 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 596 | static DECLARE_TRANSPORT_CLASS(iscsi_connection_class, |
| 597 | "iscsi_connection", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | NULL, |
| 599 | NULL, |
| 600 | NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 601 | |
| 602 | static struct sock *nls; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 603 | static DEFINE_MUTEX(rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 604 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 605 | static LIST_HEAD(sesslist); |
| 606 | static DEFINE_SPINLOCK(sesslock); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 607 | static LIST_HEAD(connlist); |
| 608 | static DEFINE_SPINLOCK(connlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 610 | static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn) |
| 611 | { |
| 612 | struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent); |
| 613 | return sess->sid; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Returns the matching session to a given sid |
| 618 | */ |
| 619 | static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 620 | { |
| 621 | unsigned long flags; |
| 622 | struct iscsi_cls_session *sess; |
| 623 | |
| 624 | spin_lock_irqsave(&sesslock, flags); |
| 625 | list_for_each_entry(sess, &sesslist, sess_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 626 | if (sess->sid == sid) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 627 | spin_unlock_irqrestore(&sesslock, flags); |
| 628 | return sess; |
| 629 | } |
| 630 | } |
| 631 | spin_unlock_irqrestore(&sesslock, flags); |
| 632 | return NULL; |
| 633 | } |
| 634 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 635 | /* |
| 636 | * Returns the matching connection to a given sid / cid tuple |
| 637 | */ |
| 638 | 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] | 639 | { |
| 640 | unsigned long flags; |
| 641 | struct iscsi_cls_conn *conn; |
| 642 | |
| 643 | spin_lock_irqsave(&connlock, flags); |
| 644 | list_for_each_entry(conn, &connlist, conn_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 645 | if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 646 | spin_unlock_irqrestore(&connlock, flags); |
| 647 | return conn; |
| 648 | } |
| 649 | } |
| 650 | spin_unlock_irqrestore(&connlock, flags); |
| 651 | return NULL; |
| 652 | } |
| 653 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 654 | /* |
| 655 | * The following functions can be used by LLDs that allocate |
| 656 | * their own scsi_hosts or by software iscsi LLDs |
| 657 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 658 | static struct { |
| 659 | int value; |
| 660 | char *name; |
| 661 | } iscsi_session_state_names[] = { |
| 662 | { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" }, |
| 663 | { ISCSI_SESSION_FAILED, "FAILED" }, |
| 664 | { ISCSI_SESSION_FREE, "FREE" }, |
| 665 | }; |
| 666 | |
Adrian Bunk | 3b0f208 | 2008-02-13 23:30:17 +0200 | [diff] [blame] | 667 | static const char *iscsi_session_state_name(int state) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 668 | { |
| 669 | int i; |
| 670 | char *name = NULL; |
| 671 | |
| 672 | for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) { |
| 673 | if (iscsi_session_state_names[i].value == state) { |
| 674 | name = iscsi_session_state_names[i].name; |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | return name; |
| 679 | } |
| 680 | |
| 681 | int iscsi_session_chkready(struct iscsi_cls_session *session) |
| 682 | { |
| 683 | unsigned long flags; |
| 684 | int err; |
| 685 | |
| 686 | spin_lock_irqsave(&session->lock, flags); |
| 687 | switch (session->state) { |
| 688 | case ISCSI_SESSION_LOGGED_IN: |
| 689 | err = 0; |
| 690 | break; |
| 691 | case ISCSI_SESSION_FAILED: |
Andrew Vasquez | 9a1a69a1 | 2009-04-29 13:12:39 -0500 | [diff] [blame] | 692 | err = DID_IMM_RETRY << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 693 | break; |
| 694 | case ISCSI_SESSION_FREE: |
Mike Christie | 56d7fcf | 2008-08-19 18:45:26 -0500 | [diff] [blame] | 695 | err = DID_TRANSPORT_FAILFAST << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 696 | break; |
| 697 | default: |
| 698 | err = DID_NO_CONNECT << 16; |
| 699 | break; |
| 700 | } |
| 701 | spin_unlock_irqrestore(&session->lock, flags); |
| 702 | return err; |
| 703 | } |
| 704 | EXPORT_SYMBOL_GPL(iscsi_session_chkready); |
| 705 | |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 706 | int iscsi_is_session_online(struct iscsi_cls_session *session) |
| 707 | { |
| 708 | unsigned long flags; |
| 709 | int ret = 0; |
| 710 | |
| 711 | spin_lock_irqsave(&session->lock, flags); |
| 712 | if (session->state == ISCSI_SESSION_LOGGED_IN) |
| 713 | ret = 1; |
| 714 | spin_unlock_irqrestore(&session->lock, flags); |
| 715 | return ret; |
| 716 | } |
| 717 | EXPORT_SYMBOL_GPL(iscsi_is_session_online); |
| 718 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 719 | static void iscsi_session_release(struct device *dev) |
| 720 | { |
| 721 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 722 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 724 | shost = iscsi_session_to_shost(session); |
| 725 | scsi_host_put(shost); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 726 | ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 727 | kfree(session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 730 | int iscsi_is_session_dev(const struct device *dev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 731 | { |
| 732 | return dev->release == iscsi_session_release; |
| 733 | } |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 734 | EXPORT_SYMBOL_GPL(iscsi_is_session_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 736 | static int iscsi_iter_session_fn(struct device *dev, void *data) |
| 737 | { |
| 738 | void (* fn) (struct iscsi_cls_session *) = data; |
| 739 | |
| 740 | if (!iscsi_is_session_dev(dev)) |
| 741 | return 0; |
| 742 | fn(iscsi_dev_to_session(dev)); |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | void iscsi_host_for_each_session(struct Scsi_Host *shost, |
| 747 | void (*fn)(struct iscsi_cls_session *)) |
| 748 | { |
| 749 | device_for_each_child(&shost->shost_gendev, fn, |
| 750 | iscsi_iter_session_fn); |
| 751 | } |
| 752 | EXPORT_SYMBOL_GPL(iscsi_host_for_each_session); |
| 753 | |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 754 | /** |
| 755 | * iscsi_scan_finished - helper to report when running scans are done |
| 756 | * @shost: scsi host |
| 757 | * @time: scan run time |
| 758 | * |
| 759 | * This function can be used by drives like qla4xxx to report to the scsi |
| 760 | * layer when the scans it kicked off at module load time are done. |
| 761 | */ |
| 762 | int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 763 | { |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 764 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 765 | /* |
| 766 | * qla4xxx will have kicked off some session unblocks before calling |
| 767 | * scsi_scan_host, so just wait for them to complete. |
| 768 | */ |
| 769 | return !atomic_read(&ihost->nr_scans); |
| 770 | } |
| 771 | EXPORT_SYMBOL_GPL(iscsi_scan_finished); |
| 772 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 773 | struct iscsi_scan_data { |
| 774 | unsigned int channel; |
| 775 | unsigned int id; |
| 776 | unsigned int lun; |
| 777 | }; |
| 778 | |
| 779 | static int iscsi_user_scan_session(struct device *dev, void *data) |
| 780 | { |
| 781 | struct iscsi_scan_data *scan_data = data; |
| 782 | struct iscsi_cls_session *session; |
| 783 | struct Scsi_Host *shost; |
| 784 | struct iscsi_cls_host *ihost; |
| 785 | unsigned long flags; |
| 786 | unsigned int id; |
| 787 | |
| 788 | if (!iscsi_is_session_dev(dev)) |
| 789 | return 0; |
| 790 | |
| 791 | session = iscsi_dev_to_session(dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 792 | |
| 793 | ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n"); |
| 794 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 795 | shost = iscsi_session_to_shost(session); |
| 796 | ihost = shost->shost_data; |
| 797 | |
| 798 | mutex_lock(&ihost->mutex); |
| 799 | spin_lock_irqsave(&session->lock, flags); |
| 800 | if (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 801 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 802 | goto user_scan_exit; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 803 | } |
| 804 | id = session->target_id; |
| 805 | spin_unlock_irqrestore(&session->lock, flags); |
| 806 | |
| 807 | if (id != ISCSI_MAX_TARGET) { |
| 808 | if ((scan_data->channel == SCAN_WILD_CARD || |
| 809 | scan_data->channel == 0) && |
| 810 | (scan_data->id == SCAN_WILD_CARD || |
| 811 | scan_data->id == id)) |
| 812 | scsi_scan_target(&session->dev, 0, id, |
| 813 | scan_data->lun, 1); |
| 814 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 815 | |
| 816 | user_scan_exit: |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 817 | mutex_unlock(&ihost->mutex); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 818 | ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n"); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 822 | static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, |
| 823 | uint id, uint lun) |
| 824 | { |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 825 | struct iscsi_scan_data scan_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 826 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 827 | scan_data.channel = channel; |
| 828 | scan_data.id = id; |
| 829 | scan_data.lun = lun; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 830 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 831 | return device_for_each_child(&shost->shost_gendev, &scan_data, |
| 832 | iscsi_user_scan_session); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 833 | } |
| 834 | |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 835 | static void iscsi_scan_session(struct work_struct *work) |
| 836 | { |
| 837 | struct iscsi_cls_session *session = |
| 838 | container_of(work, struct iscsi_cls_session, scan_work); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 839 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 840 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 841 | struct iscsi_scan_data scan_data; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 842 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 843 | scan_data.channel = 0; |
| 844 | scan_data.id = SCAN_WILD_CARD; |
| 845 | scan_data.lun = SCAN_WILD_CARD; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 846 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 847 | iscsi_user_scan_session(&session->dev, &scan_data); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 848 | atomic_dec(&ihost->nr_scans); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 849 | } |
| 850 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 851 | /** |
| 852 | * iscsi_block_scsi_eh - block scsi eh until session state has transistioned |
Randy Dunlap | e6d4ef4 | 2010-08-14 13:05:41 -0700 | [diff] [blame] | 853 | * @cmd: scsi cmd passed to scsi eh handler |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 854 | * |
| 855 | * If the session is down this function will wait for the recovery |
| 856 | * timer to fire or for the session to be logged back in. If the |
| 857 | * recovery timer fires then FAST_IO_FAIL is returned. The caller |
| 858 | * should pass this error value to the scsi eh. |
| 859 | */ |
| 860 | int iscsi_block_scsi_eh(struct scsi_cmnd *cmd) |
| 861 | { |
| 862 | struct iscsi_cls_session *session = |
| 863 | starget_to_session(scsi_target(cmd->device)); |
| 864 | unsigned long flags; |
| 865 | int ret = 0; |
| 866 | |
| 867 | spin_lock_irqsave(&session->lock, flags); |
| 868 | while (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 869 | if (session->state == ISCSI_SESSION_FREE) { |
| 870 | ret = FAST_IO_FAIL; |
| 871 | break; |
| 872 | } |
| 873 | spin_unlock_irqrestore(&session->lock, flags); |
| 874 | msleep(1000); |
| 875 | spin_lock_irqsave(&session->lock, flags); |
| 876 | } |
| 877 | spin_unlock_irqrestore(&session->lock, flags); |
| 878 | return ret; |
| 879 | } |
| 880 | EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh); |
| 881 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 882 | static void session_recovery_timedout(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 883 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 884 | struct iscsi_cls_session *session = |
| 885 | container_of(work, struct iscsi_cls_session, |
| 886 | recovery_work.work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 887 | unsigned long flags; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 888 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 889 | iscsi_cls_session_printk(KERN_INFO, session, |
| 890 | "session recovery timed out after %d secs\n", |
| 891 | session->recovery_tmo); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 892 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 893 | spin_lock_irqsave(&session->lock, flags); |
| 894 | switch (session->state) { |
| 895 | case ISCSI_SESSION_FAILED: |
| 896 | session->state = ISCSI_SESSION_FREE; |
| 897 | break; |
| 898 | case ISCSI_SESSION_LOGGED_IN: |
| 899 | case ISCSI_SESSION_FREE: |
| 900 | /* we raced with the unblock's flush */ |
| 901 | spin_unlock_irqrestore(&session->lock, flags); |
| 902 | return; |
| 903 | } |
| 904 | spin_unlock_irqrestore(&session->lock, flags); |
| 905 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 906 | if (session->transport->session_recovery_timedout) |
| 907 | session->transport->session_recovery_timedout(session); |
| 908 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 909 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n"); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 910 | scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 911 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n"); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 912 | } |
| 913 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 914 | static void __iscsi_unblock_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 915 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 916 | struct iscsi_cls_session *session = |
| 917 | container_of(work, struct iscsi_cls_session, |
| 918 | unblock_work); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 919 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 920 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 921 | unsigned long flags; |
| 922 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 923 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n"); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 924 | /* |
| 925 | * The recovery and unblock work get run from the same workqueue, |
| 926 | * so try to cancel it if it was going to run after this unblock. |
| 927 | */ |
| 928 | cancel_delayed_work(&session->recovery_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 929 | spin_lock_irqsave(&session->lock, flags); |
| 930 | session->state = ISCSI_SESSION_LOGGED_IN; |
| 931 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 932 | /* start IO */ |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 933 | scsi_target_unblock(&session->dev, SDEV_RUNNING); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 934 | /* |
| 935 | * Only do kernel scanning if the driver is properly hooked into |
| 936 | * the async scanning code (drivers like iscsi_tcp do login and |
| 937 | * scanning from userspace). |
| 938 | */ |
| 939 | if (shost->hostt->scan_finished) { |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 940 | if (scsi_queue_work(shost, &session->scan_work)) |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 941 | atomic_inc(&ihost->nr_scans); |
| 942 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 943 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 944 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 945 | |
| 946 | /** |
| 947 | * iscsi_unblock_session - set a session as logged in and start IO. |
| 948 | * @session: iscsi session |
| 949 | * |
| 950 | * Mark a session as ready to accept IO. |
| 951 | */ |
| 952 | void iscsi_unblock_session(struct iscsi_cls_session *session) |
| 953 | { |
| 954 | queue_work(iscsi_eh_timer_workq, &session->unblock_work); |
| 955 | /* |
| 956 | * make sure all the events have completed before tell the driver |
| 957 | * it is safe |
| 958 | */ |
| 959 | flush_workqueue(iscsi_eh_timer_workq); |
| 960 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 961 | EXPORT_SYMBOL_GPL(iscsi_unblock_session); |
| 962 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 963 | static void __iscsi_block_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 964 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 965 | struct iscsi_cls_session *session = |
| 966 | container_of(work, struct iscsi_cls_session, |
| 967 | block_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 968 | unsigned long flags; |
| 969 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 970 | ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 971 | spin_lock_irqsave(&session->lock, flags); |
| 972 | session->state = ISCSI_SESSION_FAILED; |
| 973 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 974 | scsi_target_block(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 975 | ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n"); |
Mike Christie | fdd46dc | 2009-11-11 16:34:34 -0600 | [diff] [blame] | 976 | if (session->recovery_tmo >= 0) |
| 977 | queue_delayed_work(iscsi_eh_timer_workq, |
| 978 | &session->recovery_work, |
| 979 | session->recovery_tmo * HZ); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 980 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 981 | |
| 982 | void iscsi_block_session(struct iscsi_cls_session *session) |
| 983 | { |
| 984 | queue_work(iscsi_eh_timer_workq, &session->block_work); |
| 985 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 986 | EXPORT_SYMBOL_GPL(iscsi_block_session); |
| 987 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 988 | static void __iscsi_unbind_session(struct work_struct *work) |
| 989 | { |
| 990 | struct iscsi_cls_session *session = |
| 991 | container_of(work, struct iscsi_cls_session, |
| 992 | unbind_work); |
| 993 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 994 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 995 | unsigned long flags; |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 996 | unsigned int target_id; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 997 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 998 | ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n"); |
| 999 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1000 | /* Prevent new scans and make sure scanning is not in progress */ |
| 1001 | mutex_lock(&ihost->mutex); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1002 | spin_lock_irqsave(&session->lock, flags); |
| 1003 | if (session->target_id == ISCSI_MAX_TARGET) { |
| 1004 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1005 | mutex_unlock(&ihost->mutex); |
| 1006 | return; |
| 1007 | } |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1008 | |
| 1009 | target_id = session->target_id; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1010 | session->target_id = ISCSI_MAX_TARGET; |
| 1011 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1012 | mutex_unlock(&ihost->mutex); |
| 1013 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1014 | if (session->ida_used) |
| 1015 | ida_simple_remove(&iscsi_sess_ida, target_id); |
| 1016 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1017 | scsi_remove_target(&session->dev); |
| 1018 | iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1019 | ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1020 | } |
| 1021 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1022 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1023 | iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 1024 | int dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1025 | { |
| 1026 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1028 | session = kzalloc(sizeof(*session) + dd_size, |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1029 | GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1030 | if (!session) |
Mike Christie | f53a88d | 2006-06-28 12:00:27 -0500 | [diff] [blame] | 1031 | return NULL; |
| 1032 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1033 | session->transport = transport; |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 1034 | session->creator = -1; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1035 | session->recovery_tmo = 120; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1036 | session->state = ISCSI_SESSION_FREE; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1037 | INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1038 | INIT_LIST_HEAD(&session->sess_list); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1039 | INIT_WORK(&session->unblock_work, __iscsi_unblock_session); |
| 1040 | INIT_WORK(&session->block_work, __iscsi_block_session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1041 | INIT_WORK(&session->unbind_work, __iscsi_unbind_session); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1042 | INIT_WORK(&session->scan_work, iscsi_scan_session); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1043 | spin_lock_init(&session->lock); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1044 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1045 | /* this is released in the dev's release function */ |
| 1046 | scsi_host_get(shost); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1047 | session->dev.parent = &shost->shost_gendev; |
| 1048 | session->dev.release = iscsi_session_release; |
| 1049 | device_initialize(&session->dev); |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1050 | if (dd_size) |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1051 | session->dd_data = &session[1]; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1052 | |
| 1053 | ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1054 | return session; |
| 1055 | } |
| 1056 | EXPORT_SYMBOL_GPL(iscsi_alloc_session); |
| 1057 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1058 | 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] | 1059 | { |
| 1060 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1061 | struct iscsi_cls_host *ihost; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1062 | unsigned long flags; |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1063 | int id = 0; |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1064 | int err; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1065 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1066 | ihost = shost->shost_data; |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 1067 | session->sid = atomic_add_return(1, &iscsi_session_nr); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1068 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1069 | if (target_id == ISCSI_MAX_TARGET) { |
| 1070 | id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1071 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1072 | if (id < 0) { |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1073 | iscsi_cls_session_printk(KERN_ERR, session, |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1074 | "Failure in Target ID Allocation\n"); |
| 1075 | return id; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1076 | } |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1077 | session->target_id = (unsigned int)id; |
| 1078 | session->ida_used = true; |
| 1079 | } else |
| 1080 | session->target_id = target_id; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1081 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1082 | dev_set_name(&session->dev, "session%u", session->sid); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1083 | err = device_add(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1084 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1085 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1086 | "could not register session's dev\n"); |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1087 | goto release_ida; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1088 | } |
| 1089 | transport_register_device(&session->dev); |
| 1090 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1091 | spin_lock_irqsave(&sesslock, flags); |
| 1092 | list_add(&session->sess_list, &sesslist); |
| 1093 | spin_unlock_irqrestore(&sesslock, flags); |
| 1094 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1095 | iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1096 | ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1097 | return 0; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1098 | |
Mike Christie | 8d4a690 | 2011-10-06 03:56:57 -0500 | [diff] [blame] | 1099 | release_ida: |
| 1100 | if (session->ida_used) |
| 1101 | ida_simple_remove(&iscsi_sess_ida, session->target_id); |
| 1102 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1103 | return err; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1104 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1105 | EXPORT_SYMBOL_GPL(iscsi_add_session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1106 | |
| 1107 | /** |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1108 | * iscsi_create_session - create iscsi class session |
| 1109 | * @shost: scsi host |
| 1110 | * @transport: iscsi transport |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1111 | * @dd_size: private driver data size |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1112 | * @target_id: which target |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1113 | * |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1114 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1115 | */ |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1116 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1117 | iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 1118 | int dd_size, unsigned int target_id) |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1119 | { |
| 1120 | struct iscsi_cls_session *session; |
| 1121 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1122 | session = iscsi_alloc_session(shost, transport, dd_size); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1123 | if (!session) |
| 1124 | return NULL; |
| 1125 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1126 | if (iscsi_add_session(session, target_id)) { |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1127 | iscsi_free_session(session); |
| 1128 | return NULL; |
| 1129 | } |
| 1130 | return session; |
| 1131 | } |
| 1132 | EXPORT_SYMBOL_GPL(iscsi_create_session); |
| 1133 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1134 | static void iscsi_conn_release(struct device *dev) |
| 1135 | { |
| 1136 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev); |
| 1137 | struct device *parent = conn->dev.parent; |
| 1138 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1139 | ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1140 | kfree(conn); |
| 1141 | put_device(parent); |
| 1142 | } |
| 1143 | |
| 1144 | static int iscsi_is_conn_dev(const struct device *dev) |
| 1145 | { |
| 1146 | return dev->release == iscsi_conn_release; |
| 1147 | } |
| 1148 | |
| 1149 | static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data) |
| 1150 | { |
| 1151 | if (!iscsi_is_conn_dev(dev)) |
| 1152 | return 0; |
| 1153 | return iscsi_destroy_conn(iscsi_dev_to_conn(dev)); |
| 1154 | } |
| 1155 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1156 | void iscsi_remove_session(struct iscsi_cls_session *session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1157 | { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1158 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1159 | unsigned long flags; |
| 1160 | int err; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1161 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1162 | ISCSI_DBG_TRANS_SESSION(session, "Removing session\n"); |
| 1163 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1164 | spin_lock_irqsave(&sesslock, flags); |
| 1165 | list_del(&session->sess_list); |
| 1166 | spin_unlock_irqrestore(&sesslock, flags); |
| 1167 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1168 | /* make sure there are no blocks/unblocks queued */ |
| 1169 | flush_workqueue(iscsi_eh_timer_workq); |
| 1170 | /* make sure the timedout callout is not running */ |
| 1171 | if (!cancel_delayed_work(&session->recovery_work)) |
| 1172 | flush_workqueue(iscsi_eh_timer_workq); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1173 | /* |
| 1174 | * If we are blocked let commands flow again. The lld or iscsi |
| 1175 | * layer should set up the queuecommand to fail commands. |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1176 | * We assume that LLD will not be calling block/unblock while |
| 1177 | * removing the session. |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1178 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1179 | spin_lock_irqsave(&session->lock, flags); |
| 1180 | session->state = ISCSI_SESSION_FREE; |
| 1181 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1182 | |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 1183 | scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1184 | /* flush running scans then delete devices */ |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 1185 | scsi_flush_work(shost); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1186 | __iscsi_unbind_session(&session->unbind_work); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1187 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1188 | /* hw iscsi may not have removed all connections from session */ |
| 1189 | err = device_for_each_child(&session->dev, NULL, |
| 1190 | iscsi_iter_destroy_conn_fn); |
| 1191 | if (err) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1192 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1193 | "Could not delete all connections " |
| 1194 | "for session. Error %d.\n", err); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1195 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1196 | transport_unregister_device(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1197 | |
| 1198 | ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1199 | device_del(&session->dev); |
| 1200 | } |
| 1201 | EXPORT_SYMBOL_GPL(iscsi_remove_session); |
| 1202 | |
| 1203 | void iscsi_free_session(struct iscsi_cls_session *session) |
| 1204 | { |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1205 | ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1206 | iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1207 | put_device(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1208 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1209 | EXPORT_SYMBOL_GPL(iscsi_free_session); |
| 1210 | |
| 1211 | /** |
| 1212 | * iscsi_destroy_session - destroy iscsi session |
| 1213 | * @session: iscsi_session |
| 1214 | * |
| 1215 | * Can be called by a LLD or iscsi_transport. There must not be |
| 1216 | * any running connections. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1217 | */ |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1218 | int iscsi_destroy_session(struct iscsi_cls_session *session) |
| 1219 | { |
| 1220 | iscsi_remove_session(session); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1221 | ISCSI_DBG_TRANS_SESSION(session, "Completing session destruction\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1222 | iscsi_free_session(session); |
| 1223 | return 0; |
| 1224 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1225 | EXPORT_SYMBOL_GPL(iscsi_destroy_session); |
| 1226 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1227 | /** |
| 1228 | * iscsi_create_conn - create iscsi class connection |
| 1229 | * @session: iscsi cls session |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1230 | * @dd_size: private driver data size |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1231 | * @cid: connection id |
| 1232 | * |
| 1233 | * This can be called from a LLD or iscsi_transport. The connection |
| 1234 | * is child of the session so cid must be unique for all connections |
| 1235 | * on the session. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1236 | * |
| 1237 | * Since we do not support MCS, cid will normally be zero. In some cases |
| 1238 | * for software iscsi we could be trying to preallocate a connection struct |
| 1239 | * in which case there could be two connection structs and cid would be |
| 1240 | * non-zero. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1241 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1242 | struct iscsi_cls_conn * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1243 | 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] | 1244 | { |
| 1245 | struct iscsi_transport *transport = session->transport; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1246 | struct iscsi_cls_conn *conn; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1247 | unsigned long flags; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1248 | int err; |
| 1249 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1250 | conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1251 | if (!conn) |
| 1252 | return NULL; |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1253 | if (dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1254 | conn->dd_data = &conn[1]; |
| 1255 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1256 | mutex_init(&conn->ep_mutex); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1257 | INIT_LIST_HEAD(&conn->conn_list); |
| 1258 | conn->transport = transport; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1259 | conn->cid = cid; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1260 | |
| 1261 | /* this is released in the dev's release function */ |
| 1262 | if (!get_device(&session->dev)) |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1263 | goto free_conn; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1264 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1265 | dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1266 | conn->dev.parent = &session->dev; |
| 1267 | conn->dev.release = iscsi_conn_release; |
| 1268 | err = device_register(&conn->dev); |
| 1269 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1270 | iscsi_cls_session_printk(KERN_ERR, session, "could not " |
| 1271 | "register connection's dev\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1272 | goto release_parent_ref; |
| 1273 | } |
| 1274 | transport_register_device(&conn->dev); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1275 | |
| 1276 | spin_lock_irqsave(&connlock, flags); |
| 1277 | list_add(&conn->conn_list, &connlist); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1278 | spin_unlock_irqrestore(&connlock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1279 | |
| 1280 | ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1281 | return conn; |
| 1282 | |
| 1283 | release_parent_ref: |
| 1284 | put_device(&session->dev); |
| 1285 | free_conn: |
| 1286 | kfree(conn); |
| 1287 | return NULL; |
| 1288 | } |
| 1289 | |
| 1290 | EXPORT_SYMBOL_GPL(iscsi_create_conn); |
| 1291 | |
| 1292 | /** |
| 1293 | * iscsi_destroy_conn - destroy iscsi class connection |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1294 | * @conn: iscsi cls session |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1295 | * |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1296 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1297 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1298 | int iscsi_destroy_conn(struct iscsi_cls_conn *conn) |
| 1299 | { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1300 | unsigned long flags; |
| 1301 | |
| 1302 | spin_lock_irqsave(&connlock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1303 | list_del(&conn->conn_list); |
| 1304 | spin_unlock_irqrestore(&connlock, flags); |
| 1305 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1306 | transport_unregister_device(&conn->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1307 | ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1308 | device_unregister(&conn->dev); |
| 1309 | return 0; |
| 1310 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1311 | EXPORT_SYMBOL_GPL(iscsi_destroy_conn); |
| 1312 | |
| 1313 | /* |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1314 | * iscsi interface functions |
| 1315 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1316 | static struct iscsi_internal * |
| 1317 | iscsi_if_transport_lookup(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1319 | struct iscsi_internal *priv; |
| 1320 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1322 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 1323 | list_for_each_entry(priv, &iscsi_transports, list) { |
| 1324 | if (tt == priv->iscsi_transport) { |
| 1325 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 1326 | return priv; |
| 1327 | } |
| 1328 | } |
| 1329 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 1330 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1333 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1334 | 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] | 1335 | { |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1336 | return nlmsg_multicast(nls, skb, 0, group, gfp); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1339 | 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] | 1340 | char *data, uint32_t data_size) |
| 1341 | { |
| 1342 | struct nlmsghdr *nlh; |
| 1343 | struct sk_buff *skb; |
| 1344 | struct iscsi_uevent *ev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1345 | char *pdu; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1346 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1347 | int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + |
| 1348 | data_size); |
| 1349 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1350 | priv = iscsi_if_transport_lookup(conn->transport); |
| 1351 | if (!priv) |
| 1352 | return -EINVAL; |
| 1353 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1354 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1355 | if (!skb) { |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1356 | iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED); |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1357 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver " |
| 1358 | "control PDU: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1359 | return -ENOMEM; |
| 1360 | } |
| 1361 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1362 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1363 | ev = NLMSG_DATA(nlh); |
| 1364 | memset(ev, 0, sizeof(*ev)); |
| 1365 | ev->transport_handle = iscsi_handle(conn->transport); |
| 1366 | ev->type = ISCSI_KEVENT_RECV_PDU; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1367 | ev->r.recv_req.cid = conn->cid; |
| 1368 | ev->r.recv_req.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1369 | pdu = (char*)ev + sizeof(*ev); |
| 1370 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); |
| 1371 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); |
| 1372 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1373 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1374 | } |
| 1375 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); |
| 1376 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1377 | int iscsi_offload_mesg(struct Scsi_Host *shost, |
| 1378 | struct iscsi_transport *transport, uint32_t type, |
| 1379 | char *data, uint16_t data_size) |
| 1380 | { |
| 1381 | struct nlmsghdr *nlh; |
| 1382 | struct sk_buff *skb; |
| 1383 | struct iscsi_uevent *ev; |
| 1384 | int len = NLMSG_SPACE(sizeof(*ev) + data_size); |
| 1385 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 1386 | skb = alloc_skb(len, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1387 | if (!skb) { |
| 1388 | printk(KERN_ERR "can not deliver iscsi offload message:OOM\n"); |
| 1389 | return -ENOMEM; |
| 1390 | } |
| 1391 | |
| 1392 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
| 1393 | ev = NLMSG_DATA(nlh); |
| 1394 | memset(ev, 0, sizeof(*ev)); |
| 1395 | ev->type = type; |
| 1396 | ev->transport_handle = iscsi_handle(transport); |
| 1397 | switch (type) { |
| 1398 | case ISCSI_KEVENT_PATH_REQ: |
| 1399 | ev->r.req_path.host_no = shost->host_no; |
| 1400 | break; |
| 1401 | case ISCSI_KEVENT_IF_DOWN: |
| 1402 | ev->r.notify_if_down.host_no = shost->host_no; |
| 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 1407 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 1408 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1409 | } |
| 1410 | EXPORT_SYMBOL_GPL(iscsi_offload_mesg); |
| 1411 | |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1412 | 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] | 1413 | { |
| 1414 | struct nlmsghdr *nlh; |
| 1415 | struct sk_buff *skb; |
| 1416 | struct iscsi_uevent *ev; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1417 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1418 | int len = NLMSG_SPACE(sizeof(*ev)); |
| 1419 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1420 | priv = iscsi_if_transport_lookup(conn->transport); |
| 1421 | if (!priv) |
| 1422 | return; |
| 1423 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1424 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1425 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1426 | iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored " |
| 1427 | "conn error (%d)\n", error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1428 | return; |
| 1429 | } |
| 1430 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1431 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1432 | ev = NLMSG_DATA(nlh); |
| 1433 | ev->transport_handle = iscsi_handle(conn->transport); |
| 1434 | ev->type = ISCSI_KEVENT_CONN_ERROR; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1435 | ev->r.connerror.error = error; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1436 | ev->r.connerror.cid = conn->cid; |
| 1437 | ev->r.connerror.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1438 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1439 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1440 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1441 | iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n", |
| 1442 | error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1443 | } |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1444 | EXPORT_SYMBOL_GPL(iscsi_conn_error_event); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1445 | |
Manish Rangankar | 17fa575 | 2011-07-25 13:48:52 -0500 | [diff] [blame] | 1446 | void iscsi_conn_login_event(struct iscsi_cls_conn *conn, |
| 1447 | enum iscsi_conn_state state) |
| 1448 | { |
| 1449 | struct nlmsghdr *nlh; |
| 1450 | struct sk_buff *skb; |
| 1451 | struct iscsi_uevent *ev; |
| 1452 | struct iscsi_internal *priv; |
| 1453 | int len = NLMSG_SPACE(sizeof(*ev)); |
| 1454 | |
| 1455 | priv = iscsi_if_transport_lookup(conn->transport); |
| 1456 | if (!priv) |
| 1457 | return; |
| 1458 | |
| 1459 | skb = alloc_skb(len, GFP_ATOMIC); |
| 1460 | if (!skb) { |
| 1461 | iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored " |
| 1462 | "conn login (%d)\n", state); |
| 1463 | return; |
| 1464 | } |
| 1465 | |
| 1466 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
| 1467 | ev = NLMSG_DATA(nlh); |
| 1468 | ev->transport_handle = iscsi_handle(conn->transport); |
| 1469 | ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE; |
| 1470 | ev->r.conn_login.state = state; |
| 1471 | ev->r.conn_login.cid = conn->cid; |
| 1472 | ev->r.conn_login.sid = iscsi_conn_get_sid(conn); |
| 1473 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
| 1474 | |
| 1475 | iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n", |
| 1476 | state); |
| 1477 | } |
| 1478 | EXPORT_SYMBOL_GPL(iscsi_conn_login_event); |
| 1479 | |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 1480 | void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, |
| 1481 | enum iscsi_host_event_code code, uint32_t data_size, |
| 1482 | uint8_t *data) |
| 1483 | { |
| 1484 | struct nlmsghdr *nlh; |
| 1485 | struct sk_buff *skb; |
| 1486 | struct iscsi_uevent *ev; |
| 1487 | int len = NLMSG_SPACE(sizeof(*ev) + data_size); |
| 1488 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 1489 | skb = alloc_skb(len, GFP_NOIO); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 1490 | if (!skb) { |
| 1491 | printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n", |
| 1492 | host_no, code); |
| 1493 | return; |
| 1494 | } |
| 1495 | |
| 1496 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
| 1497 | ev = NLMSG_DATA(nlh); |
| 1498 | ev->transport_handle = iscsi_handle(transport); |
| 1499 | ev->type = ISCSI_KEVENT_HOST_EVENT; |
| 1500 | ev->r.host_event.host_no = host_no; |
| 1501 | ev->r.host_event.code = code; |
| 1502 | ev->r.host_event.data_size = data_size; |
| 1503 | |
| 1504 | if (data_size) |
| 1505 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 1506 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 1507 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO); |
Vikas Chaudhary | a11e254 | 2012-02-13 18:30:46 +0530 | [diff] [blame] | 1508 | } |
| 1509 | EXPORT_SYMBOL_GPL(iscsi_post_host_event); |
| 1510 | |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 1511 | void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, |
| 1512 | uint32_t status, uint32_t pid, uint32_t data_size, |
| 1513 | uint8_t *data) |
| 1514 | { |
| 1515 | struct nlmsghdr *nlh; |
| 1516 | struct sk_buff *skb; |
| 1517 | struct iscsi_uevent *ev; |
| 1518 | int len = NLMSG_SPACE(sizeof(*ev) + data_size); |
| 1519 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 1520 | skb = alloc_skb(len, GFP_NOIO); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 1521 | if (!skb) { |
| 1522 | printk(KERN_ERR "gracefully ignored ping comp: OOM\n"); |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
| 1527 | ev = NLMSG_DATA(nlh); |
| 1528 | ev->transport_handle = iscsi_handle(transport); |
| 1529 | ev->type = ISCSI_KEVENT_PING_COMP; |
| 1530 | ev->r.ping_comp.host_no = host_no; |
| 1531 | ev->r.ping_comp.status = status; |
| 1532 | ev->r.ping_comp.pid = pid; |
| 1533 | ev->r.ping_comp.data_size = data_size; |
| 1534 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 1535 | |
Mike Christie | 49d0e64 | 2012-03-06 16:09:01 -0600 | [diff] [blame] | 1536 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO); |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 1537 | } |
| 1538 | EXPORT_SYMBOL_GPL(iscsi_ping_comp_event); |
| 1539 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1540 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1541 | iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi, |
| 1542 | void *payload, int size) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1543 | { |
| 1544 | struct sk_buff *skb; |
| 1545 | struct nlmsghdr *nlh; |
| 1546 | int len = NLMSG_SPACE(size); |
| 1547 | int flags = multi ? NLM_F_MULTI : 0; |
| 1548 | int t = done ? NLMSG_DONE : type; |
| 1549 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1550 | skb = alloc_skb(len, GFP_ATOMIC); |
Mike Christie | 239a7dc | 2007-05-30 12:57:07 -0500 | [diff] [blame] | 1551 | if (!skb) { |
| 1552 | printk(KERN_ERR "Could not allocate skb to send reply.\n"); |
| 1553 | return -ENOMEM; |
| 1554 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1555 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1556 | nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1557 | nlh->nlmsg_flags = flags; |
| 1558 | memcpy(NLMSG_DATA(nlh), payload, size); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1559 | return iscsi_multicast_skb(skb, group, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | static int |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1563 | iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1564 | { |
| 1565 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 1566 | struct iscsi_stats *stats; |
| 1567 | struct sk_buff *skbstat; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1568 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1569 | struct nlmsghdr *nlhstat; |
| 1570 | struct iscsi_uevent *evstat; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1571 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1572 | int len = NLMSG_SPACE(sizeof(*ev) + |
| 1573 | sizeof(struct iscsi_stats) + |
| 1574 | sizeof(struct iscsi_stats_custom) * |
| 1575 | ISCSI_STATS_CUSTOM_MAX); |
| 1576 | int err = 0; |
| 1577 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1578 | priv = iscsi_if_transport_lookup(transport); |
| 1579 | if (!priv) |
| 1580 | return -EINVAL; |
| 1581 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1582 | 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] | 1583 | if (!conn) |
| 1584 | return -EEXIST; |
| 1585 | |
| 1586 | do { |
| 1587 | int actual_size; |
| 1588 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1589 | skbstat = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1590 | if (!skbstat) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1591 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not " |
| 1592 | "deliver stats: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1593 | return -ENOMEM; |
| 1594 | } |
| 1595 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1596 | nlhstat = __nlmsg_put(skbstat, 0, 0, 0, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1597 | (len - sizeof(*nlhstat)), 0); |
| 1598 | evstat = NLMSG_DATA(nlhstat); |
| 1599 | memset(evstat, 0, sizeof(*evstat)); |
| 1600 | evstat->transport_handle = iscsi_handle(conn->transport); |
| 1601 | evstat->type = nlh->nlmsg_type; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1602 | evstat->u.get_stats.cid = |
| 1603 | ev->u.get_stats.cid; |
| 1604 | evstat->u.get_stats.sid = |
| 1605 | ev->u.get_stats.sid; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1606 | stats = (struct iscsi_stats *) |
| 1607 | ((char*)evstat + sizeof(*evstat)); |
| 1608 | memset(stats, 0, sizeof(*stats)); |
| 1609 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1610 | transport->get_stats(conn, stats); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1611 | actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
| 1612 | sizeof(struct iscsi_stats) + |
| 1613 | sizeof(struct iscsi_stats_custom) * |
| 1614 | stats->custom_length); |
| 1615 | actual_size -= sizeof(*nlhstat); |
| 1616 | actual_size = NLMSG_LENGTH(actual_size); |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1617 | skb_trim(skbstat, NLMSG_ALIGN(actual_size)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1618 | nlhstat->nlmsg_len = actual_size; |
| 1619 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1620 | err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID, |
| 1621 | GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1622 | } while (err < 0 && err != -ECONNREFUSED); |
| 1623 | |
| 1624 | return err; |
| 1625 | } |
| 1626 | |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1627 | /** |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1628 | * iscsi_session_event - send session destr. completion event |
| 1629 | * @session: iscsi class session |
| 1630 | * @event: type of event |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1631 | */ |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1632 | int iscsi_session_event(struct iscsi_cls_session *session, |
| 1633 | enum iscsi_uevent_e event) |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1634 | { |
| 1635 | struct iscsi_internal *priv; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1636 | struct Scsi_Host *shost; |
| 1637 | struct iscsi_uevent *ev; |
| 1638 | struct sk_buff *skb; |
| 1639 | struct nlmsghdr *nlh; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1640 | int rc, len = NLMSG_SPACE(sizeof(*ev)); |
| 1641 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1642 | priv = iscsi_if_transport_lookup(session->transport); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1643 | if (!priv) |
| 1644 | return -EINVAL; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1645 | shost = iscsi_session_to_shost(session); |
| 1646 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1647 | skb = alloc_skb(len, GFP_KERNEL); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1648 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1649 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1650 | "Cannot notify userspace of session " |
| 1651 | "event %u\n", event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1652 | return -ENOMEM; |
| 1653 | } |
| 1654 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1655 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1656 | ev = NLMSG_DATA(nlh); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1657 | ev->transport_handle = iscsi_handle(session->transport); |
| 1658 | |
| 1659 | ev->type = event; |
| 1660 | switch (event) { |
| 1661 | case ISCSI_KEVENT_DESTROY_SESSION: |
| 1662 | ev->r.d_session.host_no = shost->host_no; |
| 1663 | ev->r.d_session.sid = session->sid; |
| 1664 | break; |
| 1665 | case ISCSI_KEVENT_CREATE_SESSION: |
| 1666 | ev->r.c_session_ret.host_no = shost->host_no; |
| 1667 | ev->r.c_session_ret.sid = session->sid; |
| 1668 | break; |
| 1669 | case ISCSI_KEVENT_UNBIND_SESSION: |
| 1670 | ev->r.unbind_session.host_no = shost->host_no; |
| 1671 | ev->r.unbind_session.sid = session->sid; |
| 1672 | break; |
| 1673 | default: |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1674 | iscsi_cls_session_printk(KERN_ERR, session, "Invalid event " |
| 1675 | "%u.\n", event); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1676 | kfree_skb(skb); |
| 1677 | return -EINVAL; |
| 1678 | } |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1679 | |
| 1680 | /* |
| 1681 | * this will occur if the daemon is not up, so we just warn |
| 1682 | * the user and when the daemon is restarted it will handle it |
| 1683 | */ |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1684 | rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL); |
Pablo Neira Ayuso | ff491a7 | 2009-02-05 23:56:36 -0800 | [diff] [blame] | 1685 | if (rc == -ESRCH) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1686 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1687 | "Cannot notify userspace of session " |
| 1688 | "event %u. Check iscsi daemon\n", |
| 1689 | event); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1690 | |
| 1691 | ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n", |
| 1692 | event, rc); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1693 | return rc; |
| 1694 | } |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1695 | EXPORT_SYMBOL_GPL(iscsi_session_event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1696 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1697 | static int |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1698 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep, |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 1699 | struct iscsi_uevent *ev, pid_t pid, |
| 1700 | uint32_t initial_cmdsn, uint16_t cmds_max, |
| 1701 | uint16_t queue_depth) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1702 | { |
| 1703 | struct iscsi_transport *transport = priv->iscsi_transport; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1704 | struct iscsi_cls_session *session; |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1705 | struct Scsi_Host *shost; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1706 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1707 | session = transport->create_session(ep, cmds_max, queue_depth, |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1708 | initial_cmdsn); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1709 | if (!session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1710 | return -ENOMEM; |
| 1711 | |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 1712 | session->creator = pid; |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1713 | shost = iscsi_session_to_shost(session); |
| 1714 | ev->r.c_session_ret.host_no = shost->host_no; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1715 | ev->r.c_session_ret.sid = session->sid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1716 | ISCSI_DBG_TRANS_SESSION(session, |
| 1717 | "Completed creating transport session\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1722 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1723 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1724 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1725 | struct iscsi_cls_session *session; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1726 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1727 | session = iscsi_session_lookup(ev->u.c_conn.sid); |
| 1728 | if (!session) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1729 | printk(KERN_ERR "iscsi: invalid session %d.\n", |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1730 | ev->u.c_conn.sid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1731 | return -EINVAL; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1732 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1733 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1734 | conn = transport->create_conn(session, ev->u.c_conn.cid); |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1735 | if (!conn) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1736 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1737 | "couldn't create a new connection."); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1738 | return -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1739 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1740 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1741 | ev->r.c_conn_ret.sid = session->sid; |
| 1742 | ev->r.c_conn_ret.cid = conn->cid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1743 | |
| 1744 | ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1745 | return 0; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | static int |
| 1749 | iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1750 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1751 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1752 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1753 | 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] | 1754 | if (!conn) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1755 | return -EINVAL; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1756 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1757 | ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1758 | if (transport->destroy_conn) |
| 1759 | transport->destroy_conn(conn); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1760 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1761 | return 0; |
| 1762 | } |
| 1763 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1764 | static int |
| 1765 | iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1766 | { |
| 1767 | char *data = (char*)ev + sizeof(*ev); |
| 1768 | struct iscsi_cls_conn *conn; |
| 1769 | struct iscsi_cls_session *session; |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1770 | int err = 0, value = 0; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1771 | |
| 1772 | session = iscsi_session_lookup(ev->u.set_param.sid); |
| 1773 | conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); |
| 1774 | if (!conn || !session) |
| 1775 | return -EINVAL; |
| 1776 | |
| 1777 | switch (ev->u.set_param.param) { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1778 | case ISCSI_PARAM_SESS_RECOVERY_TMO: |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1779 | sscanf(data, "%d", &value); |
Mike Christie | fdd46dc | 2009-11-11 16:34:34 -0600 | [diff] [blame] | 1780 | session->recovery_tmo = value; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1781 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1782 | default: |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1783 | err = transport->set_param(conn, ev->u.set_param.param, |
| 1784 | data, ev->u.set_param.len); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | return err; |
| 1788 | } |
| 1789 | |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1790 | static int iscsi_if_ep_connect(struct iscsi_transport *transport, |
| 1791 | struct iscsi_uevent *ev, int msg_type) |
| 1792 | { |
| 1793 | struct iscsi_endpoint *ep; |
| 1794 | struct sockaddr *dst_addr; |
| 1795 | struct Scsi_Host *shost = NULL; |
| 1796 | int non_blocking, err = 0; |
| 1797 | |
| 1798 | if (!transport->ep_connect) |
| 1799 | return -EINVAL; |
| 1800 | |
| 1801 | if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) { |
| 1802 | shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no); |
| 1803 | if (!shost) { |
| 1804 | printk(KERN_ERR "ep connect failed. Could not find " |
| 1805 | "host no %u\n", |
| 1806 | ev->u.ep_connect_through_host.host_no); |
| 1807 | return -ENODEV; |
| 1808 | } |
| 1809 | non_blocking = ev->u.ep_connect_through_host.non_blocking; |
| 1810 | } else |
| 1811 | non_blocking = ev->u.ep_connect.non_blocking; |
| 1812 | |
| 1813 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
| 1814 | ep = transport->ep_connect(shost, dst_addr, non_blocking); |
| 1815 | if (IS_ERR(ep)) { |
| 1816 | err = PTR_ERR(ep); |
| 1817 | goto release_host; |
| 1818 | } |
| 1819 | |
| 1820 | ev->r.ep_connect_ret.handle = ep->id; |
| 1821 | release_host: |
| 1822 | if (shost) |
| 1823 | scsi_host_put(shost); |
| 1824 | return err; |
| 1825 | } |
| 1826 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1827 | static int iscsi_if_ep_disconnect(struct iscsi_transport *transport, |
| 1828 | u64 ep_handle) |
| 1829 | { |
| 1830 | struct iscsi_cls_conn *conn; |
| 1831 | struct iscsi_endpoint *ep; |
| 1832 | |
| 1833 | if (!transport->ep_disconnect) |
| 1834 | return -EINVAL; |
| 1835 | |
| 1836 | ep = iscsi_lookup_endpoint(ep_handle); |
| 1837 | if (!ep) |
| 1838 | return -EINVAL; |
| 1839 | conn = ep->conn; |
| 1840 | if (conn) { |
| 1841 | mutex_lock(&conn->ep_mutex); |
| 1842 | conn->ep = NULL; |
| 1843 | mutex_unlock(&conn->ep_mutex); |
| 1844 | } |
| 1845 | |
| 1846 | transport->ep_disconnect(ep); |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1850 | static int |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1851 | iscsi_if_transport_ep(struct iscsi_transport *transport, |
| 1852 | struct iscsi_uevent *ev, int msg_type) |
| 1853 | { |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1854 | struct iscsi_endpoint *ep; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1855 | int rc = 0; |
| 1856 | |
| 1857 | switch (msg_type) { |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1858 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1859 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1860 | rc = iscsi_if_ep_connect(transport, ev, msg_type); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1861 | break; |
| 1862 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 1863 | if (!transport->ep_poll) |
| 1864 | return -EINVAL; |
| 1865 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1866 | ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle); |
| 1867 | if (!ep) |
| 1868 | return -EINVAL; |
| 1869 | |
| 1870 | ev->r.retcode = transport->ep_poll(ep, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1871 | ev->u.ep_poll.timeout_ms); |
| 1872 | break; |
| 1873 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1874 | rc = iscsi_if_ep_disconnect(transport, |
| 1875 | ev->u.ep_disconnect.ep_handle); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | return rc; |
| 1879 | } |
| 1880 | |
| 1881 | static int |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1882 | iscsi_tgt_dscvr(struct iscsi_transport *transport, |
| 1883 | struct iscsi_uevent *ev) |
| 1884 | { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1885 | struct Scsi_Host *shost; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1886 | struct sockaddr *dst_addr; |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1887 | int err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1888 | |
| 1889 | if (!transport->tgt_dscvr) |
| 1890 | return -EINVAL; |
| 1891 | |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1892 | shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 1893 | if (!shost) { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1894 | printk(KERN_ERR "target discovery could not find host no %u\n", |
| 1895 | ev->u.tgt_dscvr.host_no); |
| 1896 | return -ENODEV; |
| 1897 | } |
| 1898 | |
| 1899 | |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1900 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1901 | err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type, |
| 1902 | ev->u.tgt_dscvr.enable, dst_addr); |
| 1903 | scsi_host_put(shost); |
| 1904 | return err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | static int |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 1908 | iscsi_set_host_param(struct iscsi_transport *transport, |
| 1909 | struct iscsi_uevent *ev) |
| 1910 | { |
| 1911 | char *data = (char*)ev + sizeof(*ev); |
| 1912 | struct Scsi_Host *shost; |
| 1913 | int err; |
| 1914 | |
| 1915 | if (!transport->set_host_param) |
| 1916 | return -ENOSYS; |
| 1917 | |
| 1918 | shost = scsi_host_lookup(ev->u.set_host_param.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 1919 | if (!shost) { |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 1920 | printk(KERN_ERR "set_host_param could not find host no %u\n", |
| 1921 | ev->u.set_host_param.host_no); |
| 1922 | return -ENODEV; |
| 1923 | } |
| 1924 | |
| 1925 | err = transport->set_host_param(shost, ev->u.set_host_param.param, |
| 1926 | data, ev->u.set_host_param.len); |
| 1927 | scsi_host_put(shost); |
| 1928 | return err; |
| 1929 | } |
| 1930 | |
| 1931 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1932 | iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1933 | { |
| 1934 | struct Scsi_Host *shost; |
| 1935 | struct iscsi_path *params; |
| 1936 | int err; |
| 1937 | |
| 1938 | if (!transport->set_path) |
| 1939 | return -ENOSYS; |
| 1940 | |
| 1941 | shost = scsi_host_lookup(ev->u.set_path.host_no); |
| 1942 | if (!shost) { |
| 1943 | printk(KERN_ERR "set path could not find host no %u\n", |
| 1944 | ev->u.set_path.host_no); |
| 1945 | return -ENODEV; |
| 1946 | } |
| 1947 | |
| 1948 | params = (struct iscsi_path *)((char *)ev + sizeof(*ev)); |
| 1949 | err = transport->set_path(shost, params); |
| 1950 | |
| 1951 | scsi_host_put(shost); |
| 1952 | return err; |
| 1953 | } |
| 1954 | |
| 1955 | static int |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 1956 | iscsi_set_iface_params(struct iscsi_transport *transport, |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 1957 | struct iscsi_uevent *ev, uint32_t len) |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 1958 | { |
| 1959 | char *data = (char *)ev + sizeof(*ev); |
| 1960 | struct Scsi_Host *shost; |
| 1961 | int err; |
| 1962 | |
| 1963 | if (!transport->set_iface_param) |
| 1964 | return -ENOSYS; |
| 1965 | |
| 1966 | shost = scsi_host_lookup(ev->u.set_iface_params.host_no); |
| 1967 | if (!shost) { |
| 1968 | printk(KERN_ERR "set_iface_params could not find host no %u\n", |
| 1969 | ev->u.set_iface_params.host_no); |
| 1970 | return -ENODEV; |
| 1971 | } |
| 1972 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 1973 | err = transport->set_iface_param(shost, data, len); |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 1974 | scsi_host_put(shost); |
| 1975 | return err; |
| 1976 | } |
| 1977 | |
| 1978 | static int |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 1979 | iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1980 | { |
| 1981 | struct Scsi_Host *shost; |
| 1982 | struct sockaddr *dst_addr; |
| 1983 | int err; |
| 1984 | |
| 1985 | if (!transport->send_ping) |
| 1986 | return -ENOSYS; |
| 1987 | |
| 1988 | shost = scsi_host_lookup(ev->u.iscsi_ping.host_no); |
| 1989 | if (!shost) { |
| 1990 | printk(KERN_ERR "iscsi_ping could not find host no %u\n", |
| 1991 | ev->u.iscsi_ping.host_no); |
| 1992 | return -ENODEV; |
| 1993 | } |
| 1994 | |
| 1995 | dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev)); |
| 1996 | err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num, |
| 1997 | ev->u.iscsi_ping.iface_type, |
| 1998 | ev->u.iscsi_ping.payload_size, |
| 1999 | ev->u.iscsi_ping.pid, |
| 2000 | dst_addr); |
| 2001 | scsi_host_put(shost); |
| 2002 | return err; |
| 2003 | } |
| 2004 | |
| 2005 | static int |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 2006 | iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
| 2007 | { |
| 2008 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 2009 | struct Scsi_Host *shost = NULL; |
| 2010 | struct iscsi_chap_rec *chap_rec; |
| 2011 | struct iscsi_internal *priv; |
| 2012 | struct sk_buff *skbchap; |
| 2013 | struct nlmsghdr *nlhchap; |
| 2014 | struct iscsi_uevent *evchap; |
| 2015 | uint32_t chap_buf_size; |
| 2016 | int len, err = 0; |
| 2017 | char *buf; |
| 2018 | |
| 2019 | if (!transport->get_chap) |
| 2020 | return -EINVAL; |
| 2021 | |
| 2022 | priv = iscsi_if_transport_lookup(transport); |
| 2023 | if (!priv) |
| 2024 | return -EINVAL; |
| 2025 | |
| 2026 | chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec)); |
| 2027 | len = NLMSG_SPACE(sizeof(*ev) + chap_buf_size); |
| 2028 | |
| 2029 | shost = scsi_host_lookup(ev->u.get_chap.host_no); |
| 2030 | if (!shost) { |
| 2031 | printk(KERN_ERR "%s: failed. Cound not find host no %u\n", |
| 2032 | __func__, ev->u.get_chap.host_no); |
| 2033 | return -ENODEV; |
| 2034 | } |
| 2035 | |
| 2036 | do { |
| 2037 | int actual_size; |
| 2038 | |
| 2039 | skbchap = alloc_skb(len, GFP_KERNEL); |
| 2040 | if (!skbchap) { |
| 2041 | printk(KERN_ERR "can not deliver chap: OOM\n"); |
| 2042 | err = -ENOMEM; |
| 2043 | goto exit_get_chap; |
| 2044 | } |
| 2045 | |
| 2046 | nlhchap = __nlmsg_put(skbchap, 0, 0, 0, |
| 2047 | (len - sizeof(*nlhchap)), 0); |
| 2048 | evchap = NLMSG_DATA(nlhchap); |
| 2049 | memset(evchap, 0, sizeof(*evchap)); |
| 2050 | evchap->transport_handle = iscsi_handle(transport); |
| 2051 | evchap->type = nlh->nlmsg_type; |
| 2052 | evchap->u.get_chap.host_no = ev->u.get_chap.host_no; |
| 2053 | evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx; |
| 2054 | evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries; |
| 2055 | buf = (char *) ((char *)evchap + sizeof(*evchap)); |
| 2056 | memset(buf, 0, chap_buf_size); |
| 2057 | |
| 2058 | err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx, |
| 2059 | &evchap->u.get_chap.num_entries, buf); |
| 2060 | |
| 2061 | actual_size = NLMSG_SPACE(sizeof(*ev) + chap_buf_size); |
| 2062 | skb_trim(skbchap, NLMSG_ALIGN(actual_size)); |
| 2063 | nlhchap->nlmsg_len = actual_size; |
| 2064 | |
| 2065 | err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID, |
| 2066 | GFP_KERNEL); |
| 2067 | } while (err < 0 && err != -ECONNREFUSED); |
| 2068 | |
| 2069 | exit_get_chap: |
| 2070 | scsi_host_put(shost); |
| 2071 | return err; |
| 2072 | } |
| 2073 | |
| 2074 | static int iscsi_delete_chap(struct iscsi_transport *transport, |
| 2075 | struct iscsi_uevent *ev) |
| 2076 | { |
| 2077 | struct Scsi_Host *shost; |
| 2078 | int err = 0; |
| 2079 | |
| 2080 | if (!transport->delete_chap) |
| 2081 | return -ENOSYS; |
| 2082 | |
| 2083 | shost = scsi_host_lookup(ev->u.delete_chap.host_no); |
| 2084 | if (!shost) { |
| 2085 | printk(KERN_ERR "%s could not find host no %u\n", |
| 2086 | __func__, ev->u.delete_chap.host_no); |
| 2087 | return -ENODEV; |
| 2088 | } |
| 2089 | |
| 2090 | err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx); |
| 2091 | scsi_host_put(shost); |
| 2092 | return err; |
| 2093 | } |
| 2094 | |
| 2095 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2096 | 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] | 2097 | { |
| 2098 | int err = 0; |
| 2099 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 2100 | struct iscsi_transport *transport = NULL; |
| 2101 | struct iscsi_internal *priv; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2102 | struct iscsi_cls_session *session; |
| 2103 | struct iscsi_cls_conn *conn; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2104 | struct iscsi_endpoint *ep = NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2105 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2106 | if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE) |
| 2107 | *group = ISCSI_NL_GRP_UIP; |
| 2108 | else |
| 2109 | *group = ISCSI_NL_GRP_ISCSID; |
| 2110 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2111 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); |
| 2112 | if (!priv) |
| 2113 | return -EINVAL; |
| 2114 | transport = priv->iscsi_transport; |
| 2115 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2116 | if (!try_module_get(transport->owner)) |
| 2117 | return -EINVAL; |
| 2118 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2119 | switch (nlh->nlmsg_type) { |
| 2120 | case ISCSI_UEVENT_CREATE_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2121 | err = iscsi_if_create_session(priv, ep, ev, |
Mike Christie | df1c7ba | 2012-01-26 21:13:09 -0600 | [diff] [blame] | 2122 | NETLINK_CB(skb).pid, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 2123 | ev->u.c_session.initial_cmdsn, |
| 2124 | ev->u.c_session.cmds_max, |
| 2125 | ev->u.c_session.queue_depth); |
| 2126 | break; |
| 2127 | case ISCSI_UEVENT_CREATE_BOUND_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2128 | ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle); |
Mike Christie | c95fddc | 2008-06-16 10:11:32 -0500 | [diff] [blame] | 2129 | if (!ep) { |
| 2130 | err = -EINVAL; |
| 2131 | break; |
| 2132 | } |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2133 | |
| 2134 | err = iscsi_if_create_session(priv, ep, ev, |
Mike Christie | df1c7ba | 2012-01-26 21:13:09 -0600 | [diff] [blame] | 2135 | NETLINK_CB(skb).pid, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 2136 | ev->u.c_bound_session.initial_cmdsn, |
| 2137 | ev->u.c_bound_session.cmds_max, |
| 2138 | ev->u.c_bound_session.queue_depth); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2139 | break; |
| 2140 | case ISCSI_UEVENT_DESTROY_SESSION: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2141 | session = iscsi_session_lookup(ev->u.d_session.sid); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2142 | if (session) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2143 | transport->destroy_session(session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2144 | else |
| 2145 | err = -EINVAL; |
| 2146 | break; |
| 2147 | case ISCSI_UEVENT_UNBIND_SESSION: |
| 2148 | session = iscsi_session_lookup(ev->u.d_session.sid); |
| 2149 | if (session) |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 2150 | scsi_queue_work(iscsi_session_to_shost(session), |
| 2151 | &session->unbind_work); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 2152 | else |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2153 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2154 | break; |
| 2155 | case ISCSI_UEVENT_CREATE_CONN: |
| 2156 | err = iscsi_if_create_conn(transport, ev); |
| 2157 | break; |
| 2158 | case ISCSI_UEVENT_DESTROY_CONN: |
| 2159 | err = iscsi_if_destroy_conn(transport, ev); |
| 2160 | break; |
| 2161 | case ISCSI_UEVENT_BIND_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2162 | session = iscsi_session_lookup(ev->u.b_conn.sid); |
| 2163 | 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] | 2164 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 2165 | if (conn && conn->ep) |
| 2166 | iscsi_if_ep_disconnect(transport, conn->ep->id); |
| 2167 | |
| 2168 | if (!session || !conn) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2169 | err = -EINVAL; |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | ev->r.retcode = transport->bind_conn(session, conn, |
| 2174 | ev->u.b_conn.transport_eph, |
| 2175 | ev->u.b_conn.is_leading); |
| 2176 | if (ev->r.retcode || !transport->ep_connect) |
| 2177 | break; |
| 2178 | |
| 2179 | ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph); |
| 2180 | if (ep) { |
| 2181 | ep->conn = conn; |
| 2182 | |
| 2183 | mutex_lock(&conn->ep_mutex); |
| 2184 | conn->ep = ep; |
| 2185 | mutex_unlock(&conn->ep_mutex); |
| 2186 | } else |
| 2187 | iscsi_cls_conn_printk(KERN_ERR, conn, |
| 2188 | "Could not set ep conn " |
| 2189 | "binding\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2190 | break; |
| 2191 | case ISCSI_UEVENT_SET_PARAM: |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2192 | err = iscsi_set_param(transport, ev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2193 | break; |
| 2194 | case ISCSI_UEVENT_START_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2195 | conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2196 | if (conn) |
| 2197 | ev->r.retcode = transport->start_conn(conn); |
| 2198 | else |
| 2199 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2200 | break; |
| 2201 | case ISCSI_UEVENT_STOP_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2202 | 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] | 2203 | if (conn) |
| 2204 | transport->stop_conn(conn, ev->u.stop_conn.flag); |
| 2205 | else |
| 2206 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2207 | break; |
| 2208 | case ISCSI_UEVENT_SEND_PDU: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2209 | conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2210 | if (conn) |
| 2211 | ev->r.retcode = transport->send_pdu(conn, |
| 2212 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), |
| 2213 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, |
| 2214 | ev->u.send_pdu.data_size); |
| 2215 | else |
| 2216 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2217 | break; |
| 2218 | case ISCSI_UEVENT_GET_STATS: |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 2219 | err = iscsi_if_get_stats(transport, nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2220 | break; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2221 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
| 2222 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 2223 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 2224 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2225 | err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); |
| 2226 | break; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 2227 | case ISCSI_UEVENT_TGT_DSCVR: |
| 2228 | err = iscsi_tgt_dscvr(transport, ev); |
| 2229 | break; |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 2230 | case ISCSI_UEVENT_SET_HOST_PARAM: |
| 2231 | err = iscsi_set_host_param(transport, ev); |
| 2232 | break; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2233 | case ISCSI_UEVENT_PATH_UPDATE: |
| 2234 | err = iscsi_set_path(transport, ev); |
| 2235 | break; |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 2236 | case ISCSI_UEVENT_SET_IFACE_PARAMS: |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2237 | err = iscsi_set_iface_params(transport, ev, |
| 2238 | nlmsg_attrlen(nlh, sizeof(*ev))); |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 2239 | break; |
Vikas Chaudhary | ac20c7b | 2012-02-13 18:30:48 +0530 | [diff] [blame] | 2240 | case ISCSI_UEVENT_PING: |
| 2241 | err = iscsi_send_ping(transport, ev); |
| 2242 | break; |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 2243 | case ISCSI_UEVENT_GET_CHAP: |
| 2244 | err = iscsi_get_chap(transport, nlh); |
| 2245 | break; |
| 2246 | case ISCSI_UEVENT_DELETE_CHAP: |
| 2247 | err = iscsi_delete_chap(transport, ev); |
| 2248 | break; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2249 | default: |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 2250 | err = -ENOSYS; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2251 | break; |
| 2252 | } |
| 2253 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2254 | module_put(transport->owner); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2255 | return err; |
| 2256 | } |
| 2257 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2258 | /* |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2259 | * Get message from skb. Each message is processed by iscsi_if_recv_msg. |
| 2260 | * Malformed skbs with wrong lengths or invalid creds are not processed. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2261 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2262 | static void |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2263 | iscsi_if_rx(struct sk_buff *skb) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2264 | { |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2265 | mutex_lock(&rx_queue_mutex); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2266 | while (skb->len >= NLMSG_SPACE(0)) { |
| 2267 | int err; |
| 2268 | uint32_t rlen; |
| 2269 | struct nlmsghdr *nlh; |
| 2270 | struct iscsi_uevent *ev; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2271 | uint32_t group; |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2272 | |
| 2273 | nlh = nlmsg_hdr(skb); |
| 2274 | if (nlh->nlmsg_len < sizeof(*nlh) || |
| 2275 | skb->len < nlh->nlmsg_len) { |
| 2276 | break; |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 2277 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 2278 | |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2279 | ev = NLMSG_DATA(nlh); |
| 2280 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); |
| 2281 | if (rlen > skb->len) |
| 2282 | rlen = skb->len; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2283 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2284 | err = iscsi_if_recv_msg(skb, nlh, &group); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2285 | if (err) { |
| 2286 | ev->type = ISCSI_KEVENT_IF_ERROR; |
| 2287 | ev->iferror = err; |
| 2288 | } |
| 2289 | do { |
| 2290 | /* |
| 2291 | * special case for GET_STATS: |
| 2292 | * on success - sending reply and stats from |
| 2293 | * inside of if_recv_msg(), |
| 2294 | * on error - fall through. |
| 2295 | */ |
| 2296 | if (ev->type == ISCSI_UEVENT_GET_STATS && !err) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2297 | break; |
Nilesh Javali | 6260a5d | 2012-02-27 03:08:51 -0800 | [diff] [blame] | 2298 | if (ev->type == ISCSI_UEVENT_GET_CHAP && !err) |
| 2299 | break; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2300 | err = iscsi_if_send_reply(group, nlh->nlmsg_seq, |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2301 | nlh->nlmsg_type, 0, 0, ev, sizeof(*ev)); |
Sasha Levin | 46a7c17 | 2012-01-25 22:16:16 -0500 | [diff] [blame] | 2302 | } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2303 | skb_pull(skb, rlen); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2304 | } |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2305 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2308 | #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2309 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2310 | __ATTR(_name,_mode,_show,_store) |
| 2311 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2312 | /* |
| 2313 | * iSCSI connection attrs |
| 2314 | */ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2315 | #define iscsi_conn_attr_show(param) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2317 | show_conn_param_##param(struct device *dev, \ |
| 2318 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2319 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2320 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2321 | struct iscsi_transport *t = conn->transport; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2322 | return t->get_conn_param(conn, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2323 | } |
| 2324 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2325 | #define iscsi_conn_attr(field, param) \ |
| 2326 | iscsi_conn_attr_show(param) \ |
| 2327 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2328 | NULL); |
| 2329 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2330 | iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH); |
| 2331 | iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH); |
| 2332 | iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN); |
| 2333 | iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN); |
| 2334 | iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN); |
| 2335 | iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN); |
| 2336 | iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT); |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2337 | iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN); |
| 2338 | iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); |
Mike Christie | f6d5180 | 2007-12-13 12:43:30 -0600 | [diff] [blame] | 2339 | iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO); |
| 2340 | iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | |
Mike Christie | 289324b | 2011-02-16 15:04:37 -0600 | [diff] [blame] | 2342 | #define iscsi_conn_ep_attr_show(param) \ |
| 2343 | static ssize_t show_conn_ep_param_##param(struct device *dev, \ |
| 2344 | struct device_attribute *attr,\ |
| 2345 | char *buf) \ |
| 2346 | { \ |
| 2347 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
| 2348 | struct iscsi_transport *t = conn->transport; \ |
| 2349 | struct iscsi_endpoint *ep; \ |
| 2350 | ssize_t rc; \ |
| 2351 | \ |
| 2352 | /* \ |
| 2353 | * Need to make sure ep_disconnect does not free the LLD's \ |
| 2354 | * interconnect resources while we are trying to read them. \ |
| 2355 | */ \ |
| 2356 | mutex_lock(&conn->ep_mutex); \ |
| 2357 | ep = conn->ep; \ |
| 2358 | if (!ep && t->ep_connect) { \ |
| 2359 | mutex_unlock(&conn->ep_mutex); \ |
| 2360 | return -ENOTCONN; \ |
| 2361 | } \ |
| 2362 | \ |
| 2363 | if (ep) \ |
| 2364 | rc = t->get_ep_param(ep, param, buf); \ |
| 2365 | else \ |
| 2366 | rc = t->get_conn_param(conn, param, buf); \ |
| 2367 | mutex_unlock(&conn->ep_mutex); \ |
| 2368 | return rc; \ |
| 2369 | } |
| 2370 | |
| 2371 | #define iscsi_conn_ep_attr(field, param) \ |
| 2372 | iscsi_conn_ep_attr_show(param) \ |
| 2373 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \ |
| 2374 | show_conn_ep_param_##param, NULL); |
| 2375 | |
| 2376 | iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS); |
| 2377 | iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT); |
| 2378 | |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 2379 | static struct attribute *iscsi_conn_attrs[] = { |
| 2380 | &dev_attr_conn_max_recv_dlength.attr, |
| 2381 | &dev_attr_conn_max_xmit_dlength.attr, |
| 2382 | &dev_attr_conn_header_digest.attr, |
| 2383 | &dev_attr_conn_data_digest.attr, |
| 2384 | &dev_attr_conn_ifmarker.attr, |
| 2385 | &dev_attr_conn_ofmarker.attr, |
| 2386 | &dev_attr_conn_address.attr, |
| 2387 | &dev_attr_conn_port.attr, |
| 2388 | &dev_attr_conn_exp_statsn.attr, |
| 2389 | &dev_attr_conn_persistent_address.attr, |
| 2390 | &dev_attr_conn_persistent_port.attr, |
| 2391 | &dev_attr_conn_ping_tmo.attr, |
| 2392 | &dev_attr_conn_recv_tmo.attr, |
| 2393 | NULL, |
| 2394 | }; |
| 2395 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 2396 | static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 2397 | struct attribute *attr, int i) |
| 2398 | { |
| 2399 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2400 | struct iscsi_cls_conn *conn = transport_class_to_conn(cdev); |
| 2401 | struct iscsi_transport *t = conn->transport; |
| 2402 | int param; |
| 2403 | |
| 2404 | if (attr == &dev_attr_conn_max_recv_dlength.attr) |
| 2405 | param = ISCSI_PARAM_MAX_RECV_DLENGTH; |
| 2406 | else if (attr == &dev_attr_conn_max_xmit_dlength.attr) |
| 2407 | param = ISCSI_PARAM_MAX_XMIT_DLENGTH; |
| 2408 | else if (attr == &dev_attr_conn_header_digest.attr) |
| 2409 | param = ISCSI_PARAM_HDRDGST_EN; |
| 2410 | else if (attr == &dev_attr_conn_data_digest.attr) |
| 2411 | param = ISCSI_PARAM_DATADGST_EN; |
| 2412 | else if (attr == &dev_attr_conn_ifmarker.attr) |
| 2413 | param = ISCSI_PARAM_IFMARKER_EN; |
| 2414 | else if (attr == &dev_attr_conn_ofmarker.attr) |
| 2415 | param = ISCSI_PARAM_OFMARKER_EN; |
| 2416 | else if (attr == &dev_attr_conn_address.attr) |
| 2417 | param = ISCSI_PARAM_CONN_ADDRESS; |
| 2418 | else if (attr == &dev_attr_conn_port.attr) |
| 2419 | param = ISCSI_PARAM_CONN_PORT; |
| 2420 | else if (attr == &dev_attr_conn_exp_statsn.attr) |
| 2421 | param = ISCSI_PARAM_EXP_STATSN; |
| 2422 | else if (attr == &dev_attr_conn_persistent_address.attr) |
| 2423 | param = ISCSI_PARAM_PERSISTENT_ADDRESS; |
| 2424 | else if (attr == &dev_attr_conn_persistent_port.attr) |
| 2425 | param = ISCSI_PARAM_PERSISTENT_PORT; |
| 2426 | else if (attr == &dev_attr_conn_ping_tmo.attr) |
| 2427 | param = ISCSI_PARAM_PING_TMO; |
| 2428 | else if (attr == &dev_attr_conn_recv_tmo.attr) |
| 2429 | param = ISCSI_PARAM_RECV_TMO; |
| 2430 | else { |
| 2431 | WARN_ONCE(1, "Invalid conn attr"); |
| 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 2436 | } |
| 2437 | |
| 2438 | static struct attribute_group iscsi_conn_group = { |
| 2439 | .attrs = iscsi_conn_attrs, |
| 2440 | .is_visible = iscsi_conn_attr_is_visible, |
| 2441 | }; |
| 2442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | /* |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2444 | * iSCSI session attrs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | */ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2446 | #define iscsi_session_attr_show(param, perm) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2448 | show_session_param_##param(struct device *dev, \ |
| 2449 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2450 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2451 | struct iscsi_cls_session *session = \ |
| 2452 | iscsi_dev_to_session(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2453 | struct iscsi_transport *t = session->transport; \ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2454 | \ |
| 2455 | if (perm && !capable(CAP_SYS_ADMIN)) \ |
| 2456 | return -EACCES; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2457 | return t->get_session_param(session, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2460 | #define iscsi_session_attr(field, param, perm) \ |
| 2461 | iscsi_session_attr_show(param, perm) \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2462 | static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2463 | NULL); |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2464 | iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0); |
| 2465 | iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0); |
| 2466 | iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0); |
| 2467 | iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0); |
| 2468 | iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0); |
| 2469 | iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0); |
| 2470 | iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0); |
| 2471 | iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0); |
| 2472 | iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0); |
| 2473 | iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0); |
| 2474 | iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1); |
| 2475 | iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1); |
| 2476 | iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1); |
| 2477 | iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1); |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 2478 | iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1); |
| 2479 | iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1); |
Mike Christie | 4cd49ea | 2007-12-13 12:43:38 -0600 | [diff] [blame] | 2480 | iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0); |
| 2481 | iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0); |
| 2482 | iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0); |
Mike Christie | 3fe5ae8 | 2009-11-11 16:34:33 -0600 | [diff] [blame] | 2483 | iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0); |
Mike Christie | 88dfd34 | 2008-05-21 15:54:16 -0500 | [diff] [blame] | 2484 | iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0); |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 2485 | iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0); |
| 2486 | iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2487 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2488 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2489 | show_priv_session_state(struct device *dev, struct device_attribute *attr, |
| 2490 | char *buf) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2491 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2492 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2493 | return sprintf(buf, "%s\n", iscsi_session_state_name(session->state)); |
| 2494 | } |
| 2495 | static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state, |
| 2496 | NULL); |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2497 | static ssize_t |
| 2498 | show_priv_session_creator(struct device *dev, struct device_attribute *attr, |
| 2499 | char *buf) |
| 2500 | { |
| 2501 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
| 2502 | return sprintf(buf, "%d\n", session->creator); |
| 2503 | } |
| 2504 | static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator, |
| 2505 | NULL); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2506 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2507 | #define iscsi_priv_session_attr_show(field, format) \ |
| 2508 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2509 | show_priv_session_##field(struct device *dev, \ |
| 2510 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2511 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2512 | struct iscsi_cls_session *session = \ |
| 2513 | iscsi_dev_to_session(dev->parent); \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2514 | if (session->field == -1) \ |
| 2515 | return sprintf(buf, "off\n"); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2516 | return sprintf(buf, format"\n", session->field); \ |
| 2517 | } |
| 2518 | |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2519 | #define iscsi_priv_session_attr_store(field) \ |
| 2520 | static ssize_t \ |
| 2521 | store_priv_session_##field(struct device *dev, \ |
| 2522 | struct device_attribute *attr, \ |
| 2523 | const char *buf, size_t count) \ |
| 2524 | { \ |
| 2525 | int val; \ |
| 2526 | char *cp; \ |
| 2527 | struct iscsi_cls_session *session = \ |
| 2528 | iscsi_dev_to_session(dev->parent); \ |
| 2529 | if ((session->state == ISCSI_SESSION_FREE) || \ |
| 2530 | (session->state == ISCSI_SESSION_FAILED)) \ |
| 2531 | return -EBUSY; \ |
| 2532 | if (strncmp(buf, "off", 3) == 0) \ |
| 2533 | session->field = -1; \ |
| 2534 | else { \ |
| 2535 | val = simple_strtoul(buf, &cp, 0); \ |
| 2536 | if (*cp != '\0' && *cp != '\n') \ |
| 2537 | return -EINVAL; \ |
| 2538 | session->field = val; \ |
| 2539 | } \ |
| 2540 | return count; \ |
| 2541 | } |
| 2542 | |
| 2543 | #define iscsi_priv_session_rw_attr(field, format) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2544 | iscsi_priv_session_attr_show(field, format) \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2545 | iscsi_priv_session_attr_store(field) \ |
Vasiliy Kulikov | 523f3c8 | 2011-02-04 15:24:14 +0300 | [diff] [blame] | 2546 | static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2547 | show_priv_session_##field, \ |
| 2548 | store_priv_session_##field) |
| 2549 | iscsi_priv_session_rw_attr(recovery_tmo, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2550 | |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2551 | static struct attribute *iscsi_session_attrs[] = { |
| 2552 | &dev_attr_sess_initial_r2t.attr, |
| 2553 | &dev_attr_sess_max_outstanding_r2t.attr, |
| 2554 | &dev_attr_sess_immediate_data.attr, |
| 2555 | &dev_attr_sess_first_burst_len.attr, |
| 2556 | &dev_attr_sess_max_burst_len.attr, |
| 2557 | &dev_attr_sess_data_pdu_in_order.attr, |
| 2558 | &dev_attr_sess_data_seq_in_order.attr, |
| 2559 | &dev_attr_sess_erl.attr, |
| 2560 | &dev_attr_sess_targetname.attr, |
| 2561 | &dev_attr_sess_tpgt.attr, |
| 2562 | &dev_attr_sess_password.attr, |
| 2563 | &dev_attr_sess_password_in.attr, |
| 2564 | &dev_attr_sess_username.attr, |
| 2565 | &dev_attr_sess_username_in.attr, |
| 2566 | &dev_attr_sess_fast_abort.attr, |
| 2567 | &dev_attr_sess_abort_tmo.attr, |
| 2568 | &dev_attr_sess_lu_reset_tmo.attr, |
| 2569 | &dev_attr_sess_tgt_reset_tmo.attr, |
| 2570 | &dev_attr_sess_ifacename.attr, |
| 2571 | &dev_attr_sess_initiatorname.attr, |
| 2572 | &dev_attr_sess_targetalias.attr, |
| 2573 | &dev_attr_priv_sess_recovery_tmo.attr, |
| 2574 | &dev_attr_priv_sess_state.attr, |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2575 | &dev_attr_priv_sess_creator.attr, |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 2576 | &dev_attr_sess_chap_out_idx.attr, |
| 2577 | &dev_attr_sess_chap_in_idx.attr, |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2578 | NULL, |
| 2579 | }; |
| 2580 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 2581 | static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2582 | struct attribute *attr, int i) |
| 2583 | { |
| 2584 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2585 | struct iscsi_cls_session *session = transport_class_to_session(cdev); |
| 2586 | struct iscsi_transport *t = session->transport; |
| 2587 | int param; |
| 2588 | |
| 2589 | if (attr == &dev_attr_sess_initial_r2t.attr) |
| 2590 | param = ISCSI_PARAM_INITIAL_R2T_EN; |
| 2591 | else if (attr == &dev_attr_sess_max_outstanding_r2t.attr) |
| 2592 | param = ISCSI_PARAM_MAX_R2T; |
| 2593 | else if (attr == &dev_attr_sess_immediate_data.attr) |
| 2594 | param = ISCSI_PARAM_IMM_DATA_EN; |
| 2595 | else if (attr == &dev_attr_sess_first_burst_len.attr) |
| 2596 | param = ISCSI_PARAM_FIRST_BURST; |
| 2597 | else if (attr == &dev_attr_sess_max_burst_len.attr) |
| 2598 | param = ISCSI_PARAM_MAX_BURST; |
| 2599 | else if (attr == &dev_attr_sess_data_pdu_in_order.attr) |
| 2600 | param = ISCSI_PARAM_PDU_INORDER_EN; |
| 2601 | else if (attr == &dev_attr_sess_data_seq_in_order.attr) |
| 2602 | param = ISCSI_PARAM_DATASEQ_INORDER_EN; |
| 2603 | else if (attr == &dev_attr_sess_erl.attr) |
| 2604 | param = ISCSI_PARAM_ERL; |
| 2605 | else if (attr == &dev_attr_sess_targetname.attr) |
| 2606 | param = ISCSI_PARAM_TARGET_NAME; |
| 2607 | else if (attr == &dev_attr_sess_tpgt.attr) |
| 2608 | param = ISCSI_PARAM_TPGT; |
Mike Christie | 3053495 | 2012-02-27 03:08:53 -0800 | [diff] [blame] | 2609 | else if (attr == &dev_attr_sess_chap_in_idx.attr) |
| 2610 | param = ISCSI_PARAM_CHAP_IN_IDX; |
| 2611 | else if (attr == &dev_attr_sess_chap_out_idx.attr) |
| 2612 | param = ISCSI_PARAM_CHAP_OUT_IDX; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2613 | else if (attr == &dev_attr_sess_password.attr) |
| 2614 | param = ISCSI_PARAM_USERNAME; |
| 2615 | else if (attr == &dev_attr_sess_password_in.attr) |
| 2616 | param = ISCSI_PARAM_USERNAME_IN; |
| 2617 | else if (attr == &dev_attr_sess_username.attr) |
| 2618 | param = ISCSI_PARAM_PASSWORD; |
| 2619 | else if (attr == &dev_attr_sess_username_in.attr) |
| 2620 | param = ISCSI_PARAM_PASSWORD_IN; |
| 2621 | else if (attr == &dev_attr_sess_fast_abort.attr) |
| 2622 | param = ISCSI_PARAM_FAST_ABORT; |
| 2623 | else if (attr == &dev_attr_sess_abort_tmo.attr) |
| 2624 | param = ISCSI_PARAM_ABORT_TMO; |
| 2625 | else if (attr == &dev_attr_sess_lu_reset_tmo.attr) |
| 2626 | param = ISCSI_PARAM_LU_RESET_TMO; |
| 2627 | else if (attr == &dev_attr_sess_tgt_reset_tmo.attr) |
| 2628 | param = ISCSI_PARAM_TGT_RESET_TMO; |
| 2629 | else if (attr == &dev_attr_sess_ifacename.attr) |
| 2630 | param = ISCSI_PARAM_IFACE_NAME; |
| 2631 | else if (attr == &dev_attr_sess_initiatorname.attr) |
| 2632 | param = ISCSI_PARAM_INITIATOR_NAME; |
| 2633 | else if (attr == &dev_attr_sess_targetalias.attr) |
| 2634 | param = ISCSI_PARAM_TARGET_ALIAS; |
| 2635 | else if (attr == &dev_attr_priv_sess_recovery_tmo.attr) |
| 2636 | return S_IRUGO | S_IWUSR; |
| 2637 | else if (attr == &dev_attr_priv_sess_state.attr) |
| 2638 | return S_IRUGO; |
Mike Christie | 0c70d84 | 2011-12-05 16:44:01 -0600 | [diff] [blame] | 2639 | else if (attr == &dev_attr_priv_sess_creator.attr) |
| 2640 | return S_IRUGO; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2641 | else { |
| 2642 | WARN_ONCE(1, "Invalid session attr"); |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
| 2646 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 2647 | } |
| 2648 | |
| 2649 | static struct attribute_group iscsi_session_group = { |
| 2650 | .attrs = iscsi_session_attrs, |
| 2651 | .is_visible = iscsi_session_attr_is_visible, |
| 2652 | }; |
| 2653 | |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2654 | /* |
| 2655 | * iSCSI host attrs |
| 2656 | */ |
| 2657 | #define iscsi_host_attr_show(param) \ |
| 2658 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2659 | show_host_param_##param(struct device *dev, \ |
| 2660 | struct device_attribute *attr, char *buf) \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2661 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2662 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2663 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \ |
| 2664 | return priv->iscsi_transport->get_host_param(shost, param, buf); \ |
| 2665 | } |
| 2666 | |
| 2667 | #define iscsi_host_attr(field, param) \ |
| 2668 | iscsi_host_attr_show(param) \ |
| 2669 | static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \ |
| 2670 | NULL); |
| 2671 | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 2672 | iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2673 | iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS); |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 2674 | iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 2675 | iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME); |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 2676 | iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE); |
| 2677 | iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2678 | |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2679 | static struct attribute *iscsi_host_attrs[] = { |
| 2680 | &dev_attr_host_netdev.attr, |
| 2681 | &dev_attr_host_hwaddress.attr, |
| 2682 | &dev_attr_host_ipaddress.attr, |
| 2683 | &dev_attr_host_initiatorname.attr, |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 2684 | &dev_attr_host_port_state.attr, |
| 2685 | &dev_attr_host_port_speed.attr, |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2686 | NULL, |
| 2687 | }; |
| 2688 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 2689 | static umode_t iscsi_host_attr_is_visible(struct kobject *kobj, |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2690 | struct attribute *attr, int i) |
| 2691 | { |
| 2692 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2693 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 2694 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); |
| 2695 | int param; |
| 2696 | |
| 2697 | if (attr == &dev_attr_host_netdev.attr) |
| 2698 | param = ISCSI_HOST_PARAM_NETDEV_NAME; |
| 2699 | else if (attr == &dev_attr_host_hwaddress.attr) |
| 2700 | param = ISCSI_HOST_PARAM_HWADDRESS; |
| 2701 | else if (attr == &dev_attr_host_ipaddress.attr) |
| 2702 | param = ISCSI_HOST_PARAM_IPADDRESS; |
| 2703 | else if (attr == &dev_attr_host_initiatorname.attr) |
| 2704 | param = ISCSI_HOST_PARAM_INITIATOR_NAME; |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 2705 | else if (attr == &dev_attr_host_port_state.attr) |
| 2706 | param = ISCSI_HOST_PARAM_PORT_STATE; |
| 2707 | else if (attr == &dev_attr_host_port_speed.attr) |
| 2708 | param = ISCSI_HOST_PARAM_PORT_SPEED; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2709 | else { |
| 2710 | WARN_ONCE(1, "Invalid host attr"); |
| 2711 | return 0; |
| 2712 | } |
| 2713 | |
| 2714 | return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param); |
| 2715 | } |
| 2716 | |
| 2717 | static struct attribute_group iscsi_host_group = { |
| 2718 | .attrs = iscsi_host_attrs, |
| 2719 | .is_visible = iscsi_host_attr_is_visible, |
| 2720 | }; |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2721 | |
Vikas Chaudhary | aeddde2 | 2012-01-19 03:06:55 -0800 | [diff] [blame] | 2722 | /* convert iscsi_port_speed values to ascii string name */ |
| 2723 | static const struct { |
| 2724 | enum iscsi_port_speed value; |
| 2725 | char *name; |
| 2726 | } iscsi_port_speed_names[] = { |
| 2727 | {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" }, |
| 2728 | {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" }, |
| 2729 | {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" }, |
| 2730 | {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" }, |
| 2731 | {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" }, |
| 2732 | }; |
| 2733 | |
| 2734 | char *iscsi_get_port_speed_name(struct Scsi_Host *shost) |
| 2735 | { |
| 2736 | int i; |
| 2737 | char *speed = "Unknown!"; |
| 2738 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 2739 | uint32_t port_speed = ihost->port_speed; |
| 2740 | |
| 2741 | for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) { |
| 2742 | if (iscsi_port_speed_names[i].value & port_speed) { |
| 2743 | speed = iscsi_port_speed_names[i].name; |
| 2744 | break; |
| 2745 | } |
| 2746 | } |
| 2747 | return speed; |
| 2748 | } |
| 2749 | EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name); |
| 2750 | |
| 2751 | /* convert iscsi_port_state values to ascii string name */ |
| 2752 | static const struct { |
| 2753 | enum iscsi_port_state value; |
| 2754 | char *name; |
| 2755 | } iscsi_port_state_names[] = { |
| 2756 | {ISCSI_PORT_STATE_DOWN, "LINK DOWN" }, |
| 2757 | {ISCSI_PORT_STATE_UP, "LINK UP" }, |
| 2758 | }; |
| 2759 | |
| 2760 | char *iscsi_get_port_state_name(struct Scsi_Host *shost) |
| 2761 | { |
| 2762 | int i; |
| 2763 | char *state = "Unknown!"; |
| 2764 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 2765 | uint32_t port_state = ihost->port_state; |
| 2766 | |
| 2767 | for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) { |
| 2768 | if (iscsi_port_state_names[i].value & port_state) { |
| 2769 | state = iscsi_port_state_names[i].name; |
| 2770 | break; |
| 2771 | } |
| 2772 | } |
| 2773 | return state; |
| 2774 | } |
| 2775 | EXPORT_SYMBOL_GPL(iscsi_get_port_state_name); |
| 2776 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2777 | static int iscsi_session_match(struct attribute_container *cont, |
| 2778 | struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2780 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | struct Scsi_Host *shost; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2782 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2784 | if (!iscsi_is_session_dev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | return 0; |
| 2786 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2787 | session = iscsi_dev_to_session(dev); |
| 2788 | shost = iscsi_session_to_shost(session); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2789 | if (!shost->transportt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | return 0; |
| 2791 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2792 | priv = to_iscsi_internal(shost->transportt); |
| 2793 | if (priv->session_cont.ac.class != &iscsi_session_class.class) |
| 2794 | return 0; |
| 2795 | |
| 2796 | return &priv->session_cont.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2799 | static int iscsi_conn_match(struct attribute_container *cont, |
| 2800 | struct device *dev) |
| 2801 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2802 | struct iscsi_cls_session *session; |
| 2803 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2804 | struct Scsi_Host *shost; |
| 2805 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2807 | if (!iscsi_is_conn_dev(dev)) |
| 2808 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2810 | conn = iscsi_dev_to_conn(dev); |
| 2811 | session = iscsi_dev_to_session(conn->dev.parent); |
| 2812 | shost = iscsi_session_to_shost(session); |
| 2813 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2814 | if (!shost->transportt) |
| 2815 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2817 | priv = to_iscsi_internal(shost->transportt); |
| 2818 | if (priv->conn_cont.ac.class != &iscsi_connection_class.class) |
| 2819 | return 0; |
| 2820 | |
| 2821 | return &priv->conn_cont.ac == cont; |
| 2822 | } |
| 2823 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2824 | static int iscsi_host_match(struct attribute_container *cont, |
| 2825 | struct device *dev) |
| 2826 | { |
| 2827 | struct Scsi_Host *shost; |
| 2828 | struct iscsi_internal *priv; |
| 2829 | |
| 2830 | if (!scsi_is_host_device(dev)) |
| 2831 | return 0; |
| 2832 | |
| 2833 | shost = dev_to_shost(dev); |
| 2834 | if (!shost->transportt || |
| 2835 | shost->transportt->host_attrs.ac.class != &iscsi_host_class.class) |
| 2836 | return 0; |
| 2837 | |
| 2838 | priv = to_iscsi_internal(shost->transportt); |
| 2839 | return &priv->t.host_attrs.ac == cont; |
| 2840 | } |
| 2841 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2842 | struct scsi_transport_template * |
| 2843 | iscsi_register_transport(struct iscsi_transport *tt) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2844 | { |
| 2845 | struct iscsi_internal *priv; |
| 2846 | unsigned long flags; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2847 | int err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2848 | |
| 2849 | BUG_ON(!tt); |
| 2850 | |
| 2851 | priv = iscsi_if_transport_lookup(tt); |
| 2852 | if (priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2853 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2854 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 2855 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2856 | if (!priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2857 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2858 | INIT_LIST_HEAD(&priv->list); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2859 | priv->iscsi_transport = tt; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2860 | priv->t.user_scan = iscsi_user_scan; |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 2861 | priv->t.create_work_queue = 1; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2862 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2863 | priv->dev.class = &iscsi_transport_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2864 | dev_set_name(&priv->dev, "%s", tt->name); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2865 | err = device_register(&priv->dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2866 | if (err) |
| 2867 | goto free_priv; |
| 2868 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2869 | err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2870 | if (err) |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2871 | goto unregister_dev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2872 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2873 | /* host parameters */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2874 | priv->t.host_attrs.ac.class = &iscsi_host_class.class; |
| 2875 | priv->t.host_attrs.ac.match = iscsi_host_match; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2876 | priv->t.host_attrs.ac.grp = &iscsi_host_group; |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 2877 | priv->t.host_size = sizeof(struct iscsi_cls_host); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2878 | transport_container_register(&priv->t.host_attrs); |
| 2879 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2880 | /* connection parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2881 | priv->conn_cont.ac.class = &iscsi_connection_class.class; |
| 2882 | priv->conn_cont.ac.match = iscsi_conn_match; |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 2883 | priv->conn_cont.ac.grp = &iscsi_conn_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2884 | transport_container_register(&priv->conn_cont); |
| 2885 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2886 | /* session parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2887 | priv->session_cont.ac.class = &iscsi_session_class.class; |
| 2888 | priv->session_cont.ac.match = iscsi_session_match; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2889 | priv->session_cont.ac.grp = &iscsi_session_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2890 | transport_container_register(&priv->session_cont); |
| 2891 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2892 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 2893 | list_add(&priv->list, &iscsi_transports); |
| 2894 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2896 | printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2897 | return &priv->t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2899 | unregister_dev: |
| 2900 | device_unregister(&priv->dev); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2901 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2902 | free_priv: |
| 2903 | kfree(priv); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2904 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2906 | EXPORT_SYMBOL_GPL(iscsi_register_transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2908 | int iscsi_unregister_transport(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2910 | struct iscsi_internal *priv; |
| 2911 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2913 | BUG_ON(!tt); |
| 2914 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2915 | mutex_lock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2916 | |
| 2917 | priv = iscsi_if_transport_lookup(tt); |
| 2918 | BUG_ON (!priv); |
| 2919 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2920 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 2921 | list_del(&priv->list); |
| 2922 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 2923 | |
| 2924 | transport_container_unregister(&priv->conn_cont); |
| 2925 | transport_container_unregister(&priv->session_cont); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2926 | transport_container_unregister(&priv->t.host_attrs); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2927 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2928 | sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group); |
| 2929 | device_unregister(&priv->dev); |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2930 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2931 | |
| 2932 | return 0; |
| 2933 | } |
| 2934 | EXPORT_SYMBOL_GPL(iscsi_unregister_transport); |
| 2935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | static __init int iscsi_transport_init(void) |
| 2937 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2938 | int err; |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 2939 | struct netlink_kernel_cfg cfg = { |
| 2940 | .groups = 1, |
| 2941 | .input = iscsi_if_rx, |
| 2942 | }; |
Meelis Roos | 0949260 | 2006-12-17 12:10:26 -0600 | [diff] [blame] | 2943 | printk(KERN_INFO "Loading iSCSI transport class v%s.\n", |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 2944 | ISCSI_TRANSPORT_VERSION); |
| 2945 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 2946 | atomic_set(&iscsi_session_nr, 0); |
| 2947 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2948 | err = class_register(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | if (err) |
| 2950 | return err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2951 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2952 | err = class_register(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2953 | if (err) |
| 2954 | goto unregister_transport_class; |
| 2955 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2956 | err = class_register(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2957 | if (err) |
| 2958 | goto unregister_endpoint_class; |
| 2959 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2960 | err = transport_class_register(&iscsi_host_class); |
| 2961 | if (err) |
| 2962 | goto unregister_iface_class; |
| 2963 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2964 | err = transport_class_register(&iscsi_connection_class); |
| 2965 | if (err) |
| 2966 | goto unregister_host_class; |
| 2967 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2968 | err = transport_class_register(&iscsi_session_class); |
| 2969 | if (err) |
| 2970 | goto unregister_conn_class; |
| 2971 | |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 2972 | nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, |
| 2973 | THIS_MODULE, &cfg); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2974 | if (!nls) { |
| 2975 | err = -ENOBUFS; |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2976 | goto unregister_session_class; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 2979 | iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh"); |
| 2980 | if (!iscsi_eh_timer_workq) |
| 2981 | goto release_nls; |
| 2982 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2983 | return 0; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2984 | |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 2985 | release_nls: |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 2986 | netlink_kernel_release(nls); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2987 | unregister_session_class: |
| 2988 | transport_class_unregister(&iscsi_session_class); |
| 2989 | unregister_conn_class: |
| 2990 | transport_class_unregister(&iscsi_connection_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2991 | unregister_host_class: |
| 2992 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2993 | unregister_iface_class: |
| 2994 | class_unregister(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2995 | unregister_endpoint_class: |
| 2996 | class_unregister(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2997 | unregister_transport_class: |
| 2998 | class_unregister(&iscsi_transport_class); |
| 2999 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | static void __exit iscsi_transport_exit(void) |
| 3003 | { |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 3004 | destroy_workqueue(iscsi_eh_timer_workq); |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 3005 | netlink_kernel_release(nls); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3006 | transport_class_unregister(&iscsi_connection_class); |
| 3007 | transport_class_unregister(&iscsi_session_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 3008 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 3009 | class_unregister(&iscsi_endpoint_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 3010 | class_unregister(&iscsi_iface_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3011 | class_unregister(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | module_init(iscsi_transport_init); |
| 3015 | module_exit(iscsi_transport_exit); |
| 3016 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 3017 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, " |
| 3018 | "Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 3019 | "Alex Aizman <itn780@yahoo.com>"); |
| 3020 | MODULE_DESCRIPTION("iSCSI Transport Interface"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | MODULE_LICENSE("GPL"); |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 3022 | MODULE_VERSION(ISCSI_TRANSPORT_VERSION); |
Stephen Hemminger | 058548a | 2010-12-09 09:37:56 -0800 | [diff] [blame] | 3023 | MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI); |