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