1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * iSCSI transport class definitions
5 * Copyright (C) IBM Corporation, 2004
6 * Copyright (C) Mike Christie, 2004 - 2005
7 * Copyright (C) Dmitry Yusupov, 2004 - 2005
8 * Copyright (C) Alex Aizman, 2004 - 2005
10 #include <linux/module.h>
11 #include <linux/mutex.h>
12 #include <linux/slab.h>
13 #include <linux/bsg-lib.h>
14 #include <linux/idr.h>
16 #include <scsi/scsi.h>
17 #include <scsi/scsi_host.h>
18 #include <scsi/scsi_device.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_iscsi.h>
21 #include <scsi/iscsi_if.h>
22 #include <scsi/scsi_cmnd.h>
23 #include <scsi/scsi_bsg_iscsi.h>
25 #define ISCSI_TRANSPORT_VERSION "2.0-870"
27 #define ISCSI_SEND_MAX_ALLOWED 10
29 #define CREATE_TRACE_POINTS
30 #include <trace/events/iscsi.h>
33 * Export tracepoint symbols to be used by other modules.
35 EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_conn);
36 EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_eh);
37 EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_session);
38 EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_tcp);
39 EXPORT_TRACEPOINT_SYMBOL_GPL(iscsi_dbg_sw_tcp);
41 static int dbg_session;
42 module_param_named(debug_session, dbg_session, int,
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 "
50 module_param_named(debug_conn, dbg_conn, int,
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 "
57 #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \
60 iscsi_cls_session_printk(KERN_INFO, _session, \
63 iscsi_dbg_trace(trace_iscsi_dbg_trans_session, \
65 "%s " dbg_fmt, __func__, ##arg); \
68 #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \
71 iscsi_cls_conn_printk(KERN_INFO, _conn, \
74 iscsi_dbg_trace(trace_iscsi_dbg_trans_conn, \
76 "%s " dbg_fmt, __func__, ##arg); \
79 struct iscsi_internal {
80 struct scsi_transport_template t;
81 struct iscsi_transport *iscsi_transport;
82 struct list_head list;
85 struct transport_container conn_cont;
86 struct transport_container session_cont;
89 static DEFINE_IDR(iscsi_ep_idr);
90 static DEFINE_MUTEX(iscsi_ep_idr_mutex);
92 static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
93 static struct workqueue_struct *iscsi_eh_timer_workq;
95 static struct workqueue_struct *iscsi_conn_cleanup_workq;
97 static DEFINE_IDA(iscsi_sess_ida);
99 * list of registered transports and lock that must
100 * be held while accessing list. The iscsi_transport_lock must
101 * be acquired after the rx_queue_mutex.
103 static LIST_HEAD(iscsi_transports);
104 static DEFINE_SPINLOCK(iscsi_transport_lock);
106 #define to_iscsi_internal(tmpl) \
107 container_of(tmpl, struct iscsi_internal, t)
109 #define dev_to_iscsi_internal(_dev) \
110 container_of(_dev, struct iscsi_internal, dev)
112 static void iscsi_transport_release(struct device *dev)
114 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
119 * iscsi_transport_class represents the iscsi_transports that are
122 static struct class iscsi_transport_class = {
123 .name = "iscsi_transport",
124 .dev_release = iscsi_transport_release,
128 show_transport_handle(struct device *dev, struct device_attribute *attr,
131 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
133 if (!capable(CAP_SYS_ADMIN))
135 return sysfs_emit(buf, "%llu\n",
136 (unsigned long long)iscsi_handle(priv->iscsi_transport));
138 static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
140 #define show_transport_attr(name, format) \
142 show_transport_##name(struct device *dev, \
143 struct device_attribute *attr,char *buf) \
145 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
146 return sysfs_emit(buf, format"\n", priv->iscsi_transport->name);\
148 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
150 show_transport_attr(caps, "0x%x");
152 static struct attribute *iscsi_transport_attrs[] = {
153 &dev_attr_handle.attr,
158 static struct attribute_group iscsi_transport_group = {
159 .attrs = iscsi_transport_attrs,
163 * iSCSI endpoint attrs
165 #define iscsi_dev_to_endpoint(_dev) \
166 container_of(_dev, struct iscsi_endpoint, dev)
168 #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
169 struct device_attribute dev_attr_##_prefix##_##_name = \
170 __ATTR(_name,_mode,_show,_store)
172 static void iscsi_endpoint_release(struct device *dev)
174 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
176 mutex_lock(&iscsi_ep_idr_mutex);
177 idr_remove(&iscsi_ep_idr, ep->id);
178 mutex_unlock(&iscsi_ep_idr_mutex);
183 static struct class iscsi_endpoint_class = {
184 .name = "iscsi_endpoint",
185 .dev_release = iscsi_endpoint_release,
189 show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
191 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
192 return sysfs_emit(buf, "%d\n", ep->id);
194 static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
196 static struct attribute *iscsi_endpoint_attrs[] = {
197 &dev_attr_ep_handle.attr,
201 static struct attribute_group iscsi_endpoint_group = {
202 .attrs = iscsi_endpoint_attrs,
205 struct iscsi_endpoint *
206 iscsi_create_endpoint(int dd_size)
208 struct iscsi_endpoint *ep;
211 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
215 mutex_lock(&iscsi_ep_idr_mutex);
218 * First endpoint id should be 1 to comply with user space
219 * applications (iscsid).
221 id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
223 mutex_unlock(&iscsi_ep_idr_mutex);
224 printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
228 mutex_unlock(&iscsi_ep_idr_mutex);
231 ep->dev.class = &iscsi_endpoint_class;
232 dev_set_name(&ep->dev, "ep-%d", id);
233 err = device_register(&ep->dev);
237 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
242 ep->dd_data = &ep[1];
246 device_unregister(&ep->dev);
250 mutex_lock(&iscsi_ep_idr_mutex);
251 idr_remove(&iscsi_ep_idr, id);
252 mutex_unlock(&iscsi_ep_idr_mutex);
253 put_device(&ep->dev);
259 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
261 void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
263 sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
264 device_unregister(&ep->dev);
266 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
268 void iscsi_put_endpoint(struct iscsi_endpoint *ep)
270 put_device(&ep->dev);
272 EXPORT_SYMBOL_GPL(iscsi_put_endpoint);
275 * iscsi_lookup_endpoint - get ep from handle
276 * @handle: endpoint handle
278 * Caller must do a iscsi_put_endpoint.
280 struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
282 struct iscsi_endpoint *ep;
284 mutex_lock(&iscsi_ep_idr_mutex);
285 ep = idr_find(&iscsi_ep_idr, handle);
289 get_device(&ep->dev);
291 mutex_unlock(&iscsi_ep_idr_mutex);
294 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
297 * Interface to display network param to sysfs
300 static void iscsi_iface_release(struct device *dev)
302 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
303 struct device *parent = iface->dev.parent;
310 static struct class iscsi_iface_class = {
311 .name = "iscsi_iface",
312 .dev_release = iscsi_iface_release,
315 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
316 struct device_attribute dev_attr_##_prefix##_##_name = \
317 __ATTR(_name, _mode, _show, _store)
319 /* iface attrs show */
320 #define iscsi_iface_attr_show(type, name, param_type, param) \
322 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
325 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
326 struct iscsi_transport *t = iface->transport; \
327 return t->get_iface_param(iface, param_type, param, buf); \
330 #define iscsi_iface_net_attr(type, name, param) \
331 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
332 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
334 #define iscsi_iface_attr(type, name, param) \
335 iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \
336 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
338 /* generic read only ipv4 attribute */
339 iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
340 iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
341 iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
342 iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
343 iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en,
344 ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN);
345 iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en,
346 ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN);
347 iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN);
348 iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS);
349 iscsi_iface_net_attr(ipv4_iface, grat_arp_en,
350 ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN);
351 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en,
352 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN);
353 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id,
354 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID);
355 iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en,
356 ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN);
357 iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en,
358 ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN);
359 iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id,
360 ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID);
361 iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en,
362 ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN);
363 iscsi_iface_net_attr(ipv4_iface, fragment_disable,
364 ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE);
365 iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en,
366 ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN);
367 iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL);
369 /* generic read only ipv6 attribute */
370 iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
371 iscsi_iface_net_attr(ipv6_iface, link_local_addr,
372 ISCSI_NET_PARAM_IPV6_LINKLOCAL);
373 iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
374 iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
375 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
376 iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
377 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
378 iscsi_iface_net_attr(ipv6_iface, link_local_state,
379 ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE);
380 iscsi_iface_net_attr(ipv6_iface, router_state,
381 ISCSI_NET_PARAM_IPV6_ROUTER_STATE);
382 iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en,
383 ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN);
384 iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN);
385 iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL);
386 iscsi_iface_net_attr(ipv6_iface, traffic_class,
387 ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS);
388 iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT);
389 iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo,
390 ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO);
391 iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time,
392 ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME);
393 iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo,
394 ISCSI_NET_PARAM_IPV6_ND_STALE_TMO);
395 iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt,
396 ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT);
397 iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu,
398 ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU);
400 /* common read only iface attribute */
401 iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
402 iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
403 iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
404 iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
405 iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
406 iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
407 iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE);
408 iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN);
409 iscsi_iface_net_attr(iface, tcp_nagle_disable,
410 ISCSI_NET_PARAM_TCP_NAGLE_DISABLE);
411 iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE);
412 iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF);
413 iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE);
414 iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN);
415 iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID);
416 iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN);
418 /* common iscsi specific settings attributes */
419 iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO);
420 iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN);
421 iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN);
422 iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN);
423 iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN);
424 iscsi_iface_attr(iface, data_seq_in_order,
425 ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN);
426 iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN);
427 iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL);
428 iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH);
429 iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST);
430 iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T);
431 iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST);
432 iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN);
433 iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN);
434 iscsi_iface_attr(iface, discovery_auth_optional,
435 ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL);
436 iscsi_iface_attr(iface, discovery_logout,
437 ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN);
438 iscsi_iface_attr(iface, strict_login_comp_en,
439 ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN);
440 iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME);
442 static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
443 struct attribute *attr, int i)
445 struct device *dev = container_of(kobj, struct device, kobj);
446 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
447 struct iscsi_transport *t = iface->transport;
450 if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr)
451 param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO;
452 else if (attr == &dev_attr_iface_header_digest.attr)
453 param = ISCSI_IFACE_PARAM_HDRDGST_EN;
454 else if (attr == &dev_attr_iface_data_digest.attr)
455 param = ISCSI_IFACE_PARAM_DATADGST_EN;
456 else if (attr == &dev_attr_iface_immediate_data.attr)
457 param = ISCSI_IFACE_PARAM_IMM_DATA_EN;
458 else if (attr == &dev_attr_iface_initial_r2t.attr)
459 param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN;
460 else if (attr == &dev_attr_iface_data_seq_in_order.attr)
461 param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN;
462 else if (attr == &dev_attr_iface_data_pdu_in_order.attr)
463 param = ISCSI_IFACE_PARAM_PDU_INORDER_EN;
464 else if (attr == &dev_attr_iface_erl.attr)
465 param = ISCSI_IFACE_PARAM_ERL;
466 else if (attr == &dev_attr_iface_max_recv_dlength.attr)
467 param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH;
468 else if (attr == &dev_attr_iface_first_burst_len.attr)
469 param = ISCSI_IFACE_PARAM_FIRST_BURST;
470 else if (attr == &dev_attr_iface_max_outstanding_r2t.attr)
471 param = ISCSI_IFACE_PARAM_MAX_R2T;
472 else if (attr == &dev_attr_iface_max_burst_len.attr)
473 param = ISCSI_IFACE_PARAM_MAX_BURST;
474 else if (attr == &dev_attr_iface_chap_auth.attr)
475 param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN;
476 else if (attr == &dev_attr_iface_bidi_chap.attr)
477 param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN;
478 else if (attr == &dev_attr_iface_discovery_auth_optional.attr)
479 param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL;
480 else if (attr == &dev_attr_iface_discovery_logout.attr)
481 param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN;
482 else if (attr == &dev_attr_iface_strict_login_comp_en.attr)
483 param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN;
484 else if (attr == &dev_attr_iface_initiator_name.attr)
485 param = ISCSI_IFACE_PARAM_INITIATOR_NAME;
488 return t->attr_is_visible(ISCSI_IFACE_PARAM, param);
490 if (attr == &dev_attr_iface_enabled.attr)
491 param = ISCSI_NET_PARAM_IFACE_ENABLE;
492 else if (attr == &dev_attr_iface_vlan_id.attr)
493 param = ISCSI_NET_PARAM_VLAN_ID;
494 else if (attr == &dev_attr_iface_vlan_priority.attr)
495 param = ISCSI_NET_PARAM_VLAN_PRIORITY;
496 else if (attr == &dev_attr_iface_vlan_enabled.attr)
497 param = ISCSI_NET_PARAM_VLAN_ENABLED;
498 else if (attr == &dev_attr_iface_mtu.attr)
499 param = ISCSI_NET_PARAM_MTU;
500 else if (attr == &dev_attr_iface_port.attr)
501 param = ISCSI_NET_PARAM_PORT;
502 else if (attr == &dev_attr_iface_ipaddress_state.attr)
503 param = ISCSI_NET_PARAM_IPADDR_STATE;
504 else if (attr == &dev_attr_iface_delayed_ack_en.attr)
505 param = ISCSI_NET_PARAM_DELAYED_ACK_EN;
506 else if (attr == &dev_attr_iface_tcp_nagle_disable.attr)
507 param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE;
508 else if (attr == &dev_attr_iface_tcp_wsf_disable.attr)
509 param = ISCSI_NET_PARAM_TCP_WSF_DISABLE;
510 else if (attr == &dev_attr_iface_tcp_wsf.attr)
511 param = ISCSI_NET_PARAM_TCP_WSF;
512 else if (attr == &dev_attr_iface_tcp_timer_scale.attr)
513 param = ISCSI_NET_PARAM_TCP_TIMER_SCALE;
514 else if (attr == &dev_attr_iface_tcp_timestamp_en.attr)
515 param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN;
516 else if (attr == &dev_attr_iface_cache_id.attr)
517 param = ISCSI_NET_PARAM_CACHE_ID;
518 else if (attr == &dev_attr_iface_redirect_en.attr)
519 param = ISCSI_NET_PARAM_REDIRECT_EN;
520 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
521 if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
522 param = ISCSI_NET_PARAM_IPV4_ADDR;
523 else if (attr == &dev_attr_ipv4_iface_gateway.attr)
524 param = ISCSI_NET_PARAM_IPV4_GW;
525 else if (attr == &dev_attr_ipv4_iface_subnet.attr)
526 param = ISCSI_NET_PARAM_IPV4_SUBNET;
527 else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
528 param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
530 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr)
531 param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN;
533 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr)
534 param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN;
535 else if (attr == &dev_attr_ipv4_iface_tos_en.attr)
536 param = ISCSI_NET_PARAM_IPV4_TOS_EN;
537 else if (attr == &dev_attr_ipv4_iface_tos.attr)
538 param = ISCSI_NET_PARAM_IPV4_TOS;
539 else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr)
540 param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN;
542 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr)
543 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN;
544 else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr)
545 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID;
547 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr)
548 param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN;
550 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr)
551 param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN;
552 else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr)
553 param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID;
555 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr)
556 param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN;
558 &dev_attr_ipv4_iface_fragment_disable.attr)
559 param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE;
561 &dev_attr_ipv4_iface_incoming_forwarding_en.attr)
562 param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN;
563 else if (attr == &dev_attr_ipv4_iface_ttl.attr)
564 param = ISCSI_NET_PARAM_IPV4_TTL;
567 } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
568 if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
569 param = ISCSI_NET_PARAM_IPV6_ADDR;
570 else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
571 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
572 else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
573 param = ISCSI_NET_PARAM_IPV6_ROUTER;
574 else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
575 param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
576 else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
577 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
578 else if (attr == &dev_attr_ipv6_iface_link_local_state.attr)
579 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE;
580 else if (attr == &dev_attr_ipv6_iface_router_state.attr)
581 param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE;
583 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr)
584 param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN;
585 else if (attr == &dev_attr_ipv6_iface_mld_en.attr)
586 param = ISCSI_NET_PARAM_IPV6_MLD_EN;
587 else if (attr == &dev_attr_ipv6_iface_flow_label.attr)
588 param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL;
589 else if (attr == &dev_attr_ipv6_iface_traffic_class.attr)
590 param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS;
591 else if (attr == &dev_attr_ipv6_iface_hop_limit.attr)
592 param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT;
593 else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr)
594 param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO;
595 else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr)
596 param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME;
597 else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr)
598 param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO;
599 else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr)
600 param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT;
601 else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr)
602 param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU;
606 WARN_ONCE(1, "Invalid iface attr");
610 return t->attr_is_visible(ISCSI_NET_PARAM, param);
613 static struct attribute *iscsi_iface_attrs[] = {
614 &dev_attr_iface_enabled.attr,
615 &dev_attr_iface_vlan_id.attr,
616 &dev_attr_iface_vlan_priority.attr,
617 &dev_attr_iface_vlan_enabled.attr,
618 &dev_attr_ipv4_iface_ipaddress.attr,
619 &dev_attr_ipv4_iface_gateway.attr,
620 &dev_attr_ipv4_iface_subnet.attr,
621 &dev_attr_ipv4_iface_bootproto.attr,
622 &dev_attr_ipv6_iface_ipaddress.attr,
623 &dev_attr_ipv6_iface_link_local_addr.attr,
624 &dev_attr_ipv6_iface_router_addr.attr,
625 &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
626 &dev_attr_ipv6_iface_link_local_autocfg.attr,
627 &dev_attr_iface_mtu.attr,
628 &dev_attr_iface_port.attr,
629 &dev_attr_iface_ipaddress_state.attr,
630 &dev_attr_iface_delayed_ack_en.attr,
631 &dev_attr_iface_tcp_nagle_disable.attr,
632 &dev_attr_iface_tcp_wsf_disable.attr,
633 &dev_attr_iface_tcp_wsf.attr,
634 &dev_attr_iface_tcp_timer_scale.attr,
635 &dev_attr_iface_tcp_timestamp_en.attr,
636 &dev_attr_iface_cache_id.attr,
637 &dev_attr_iface_redirect_en.attr,
638 &dev_attr_iface_def_taskmgmt_tmo.attr,
639 &dev_attr_iface_header_digest.attr,
640 &dev_attr_iface_data_digest.attr,
641 &dev_attr_iface_immediate_data.attr,
642 &dev_attr_iface_initial_r2t.attr,
643 &dev_attr_iface_data_seq_in_order.attr,
644 &dev_attr_iface_data_pdu_in_order.attr,
645 &dev_attr_iface_erl.attr,
646 &dev_attr_iface_max_recv_dlength.attr,
647 &dev_attr_iface_first_burst_len.attr,
648 &dev_attr_iface_max_outstanding_r2t.attr,
649 &dev_attr_iface_max_burst_len.attr,
650 &dev_attr_iface_chap_auth.attr,
651 &dev_attr_iface_bidi_chap.attr,
652 &dev_attr_iface_discovery_auth_optional.attr,
653 &dev_attr_iface_discovery_logout.attr,
654 &dev_attr_iface_strict_login_comp_en.attr,
655 &dev_attr_iface_initiator_name.attr,
656 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr,
657 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr,
658 &dev_attr_ipv4_iface_tos_en.attr,
659 &dev_attr_ipv4_iface_tos.attr,
660 &dev_attr_ipv4_iface_grat_arp_en.attr,
661 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr,
662 &dev_attr_ipv4_iface_dhcp_alt_client_id.attr,
663 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr,
664 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr,
665 &dev_attr_ipv4_iface_dhcp_vendor_id.attr,
666 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr,
667 &dev_attr_ipv4_iface_fragment_disable.attr,
668 &dev_attr_ipv4_iface_incoming_forwarding_en.attr,
669 &dev_attr_ipv4_iface_ttl.attr,
670 &dev_attr_ipv6_iface_link_local_state.attr,
671 &dev_attr_ipv6_iface_router_state.attr,
672 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr,
673 &dev_attr_ipv6_iface_mld_en.attr,
674 &dev_attr_ipv6_iface_flow_label.attr,
675 &dev_attr_ipv6_iface_traffic_class.attr,
676 &dev_attr_ipv6_iface_hop_limit.attr,
677 &dev_attr_ipv6_iface_nd_reachable_tmo.attr,
678 &dev_attr_ipv6_iface_nd_rexmit_time.attr,
679 &dev_attr_ipv6_iface_nd_stale_tmo.attr,
680 &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr,
681 &dev_attr_ipv6_iface_router_adv_link_mtu.attr,
685 static struct attribute_group iscsi_iface_group = {
686 .attrs = iscsi_iface_attrs,
687 .is_visible = iscsi_iface_attr_is_visible,
690 /* convert iscsi_ipaddress_state values to ascii string name */
691 static const struct {
692 enum iscsi_ipaddress_state value;
694 } iscsi_ipaddress_state_names[] = {
695 {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" },
696 {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" },
697 {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" },
698 {ISCSI_IPDDRESS_STATE_VALID, "Valid" },
699 {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" },
700 {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" },
701 {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" },
704 char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state)
709 for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) {
710 if (iscsi_ipaddress_state_names[i].value == port_state) {
711 state = iscsi_ipaddress_state_names[i].name;
717 EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name);
719 /* convert iscsi_router_state values to ascii string name */
720 static const struct {
721 enum iscsi_router_state value;
723 } iscsi_router_state_names[] = {
724 {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" },
725 {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" },
726 {ISCSI_ROUTER_STATE_MANUAL, "Manual" },
727 {ISCSI_ROUTER_STATE_STALE, "Stale" },
730 char *iscsi_get_router_state_name(enum iscsi_router_state router_state)
735 for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) {
736 if (iscsi_router_state_names[i].value == router_state) {
737 state = iscsi_router_state_names[i].name;
743 EXPORT_SYMBOL_GPL(iscsi_get_router_state_name);
746 iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
747 uint32_t iface_type, uint32_t iface_num, int dd_size)
749 struct iscsi_iface *iface;
752 iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
756 iface->transport = transport;
757 iface->iface_type = iface_type;
758 iface->iface_num = iface_num;
759 iface->dev.release = iscsi_iface_release;
760 iface->dev.class = &iscsi_iface_class;
761 /* parent reference released in iscsi_iface_release */
762 iface->dev.parent = get_device(&shost->shost_gendev);
763 if (iface_type == ISCSI_IFACE_TYPE_IPV4)
764 dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
767 dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
770 err = device_register(&iface->dev);
774 err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
779 iface->dd_data = &iface[1];
783 device_unregister(&iface->dev);
787 put_device(&iface->dev);
790 EXPORT_SYMBOL_GPL(iscsi_create_iface);
792 void iscsi_destroy_iface(struct iscsi_iface *iface)
794 sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
795 device_unregister(&iface->dev);
797 EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
800 * Interface to display flash node params to sysfs
803 #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
804 struct device_attribute dev_attr_##_prefix##_##_name = \
805 __ATTR(_name, _mode, _show, _store)
807 /* flash node session attrs show */
808 #define iscsi_flashnode_sess_attr_show(type, name, param) \
810 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
813 struct iscsi_bus_flash_session *fnode_sess = \
814 iscsi_dev_to_flash_session(dev);\
815 struct iscsi_transport *t = fnode_sess->transport; \
816 return t->get_flashnode_param(fnode_sess, param, buf); \
820 #define iscsi_flashnode_sess_attr(type, name, param) \
821 iscsi_flashnode_sess_attr_show(type, name, param) \
822 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
823 show_##type##_##name, NULL);
825 /* Flash node session attributes */
827 iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable,
828 ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE);
829 iscsi_flashnode_sess_attr(fnode, discovery_session,
830 ISCSI_FLASHNODE_DISCOVERY_SESS);
831 iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE);
832 iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN);
833 iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN);
834 iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN);
835 iscsi_flashnode_sess_attr(fnode, data_seq_in_order,
836 ISCSI_FLASHNODE_DATASEQ_INORDER);
837 iscsi_flashnode_sess_attr(fnode, data_pdu_in_order,
838 ISCSI_FLASHNODE_PDU_INORDER);
839 iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN);
840 iscsi_flashnode_sess_attr(fnode, discovery_logout,
841 ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN);
842 iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN);
843 iscsi_flashnode_sess_attr(fnode, discovery_auth_optional,
844 ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL);
845 iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL);
846 iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST);
847 iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT);
848 iscsi_flashnode_sess_attr(fnode, def_time2retain,
849 ISCSI_FLASHNODE_DEF_TIME2RETAIN);
850 iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T);
851 iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID);
852 iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID);
853 iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST);
854 iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo,
855 ISCSI_FLASHNODE_DEF_TASKMGMT_TMO);
856 iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS);
857 iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME);
858 iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT);
859 iscsi_flashnode_sess_attr(fnode, discovery_parent_idx,
860 ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX);
861 iscsi_flashnode_sess_attr(fnode, discovery_parent_type,
862 ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE);
863 iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX);
864 iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX);
865 iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME);
866 iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN);
867 iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD);
868 iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN);
869 iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT);
871 static struct attribute *iscsi_flashnode_sess_attrs[] = {
872 &dev_attr_fnode_auto_snd_tgt_disable.attr,
873 &dev_attr_fnode_discovery_session.attr,
874 &dev_attr_fnode_portal_type.attr,
875 &dev_attr_fnode_entry_enable.attr,
876 &dev_attr_fnode_immediate_data.attr,
877 &dev_attr_fnode_initial_r2t.attr,
878 &dev_attr_fnode_data_seq_in_order.attr,
879 &dev_attr_fnode_data_pdu_in_order.attr,
880 &dev_attr_fnode_chap_auth.attr,
881 &dev_attr_fnode_discovery_logout.attr,
882 &dev_attr_fnode_bidi_chap.attr,
883 &dev_attr_fnode_discovery_auth_optional.attr,
884 &dev_attr_fnode_erl.attr,
885 &dev_attr_fnode_first_burst_len.attr,
886 &dev_attr_fnode_def_time2wait.attr,
887 &dev_attr_fnode_def_time2retain.attr,
888 &dev_attr_fnode_max_outstanding_r2t.attr,
889 &dev_attr_fnode_isid.attr,
890 &dev_attr_fnode_tsid.attr,
891 &dev_attr_fnode_max_burst_len.attr,
892 &dev_attr_fnode_def_taskmgmt_tmo.attr,
893 &dev_attr_fnode_targetalias.attr,
894 &dev_attr_fnode_targetname.attr,
895 &dev_attr_fnode_tpgt.attr,
896 &dev_attr_fnode_discovery_parent_idx.attr,
897 &dev_attr_fnode_discovery_parent_type.attr,
898 &dev_attr_fnode_chap_in_idx.attr,
899 &dev_attr_fnode_chap_out_idx.attr,
900 &dev_attr_fnode_username.attr,
901 &dev_attr_fnode_username_in.attr,
902 &dev_attr_fnode_password.attr,
903 &dev_attr_fnode_password_in.attr,
904 &dev_attr_fnode_is_boot_target.attr,
908 static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj,
909 struct attribute *attr,
912 struct device *dev = container_of(kobj, struct device, kobj);
913 struct iscsi_bus_flash_session *fnode_sess =
914 iscsi_dev_to_flash_session(dev);
915 struct iscsi_transport *t = fnode_sess->transport;
918 if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) {
919 param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE;
920 } else if (attr == &dev_attr_fnode_discovery_session.attr) {
921 param = ISCSI_FLASHNODE_DISCOVERY_SESS;
922 } else if (attr == &dev_attr_fnode_portal_type.attr) {
923 param = ISCSI_FLASHNODE_PORTAL_TYPE;
924 } else if (attr == &dev_attr_fnode_entry_enable.attr) {
925 param = ISCSI_FLASHNODE_ENTRY_EN;
926 } else if (attr == &dev_attr_fnode_immediate_data.attr) {
927 param = ISCSI_FLASHNODE_IMM_DATA_EN;
928 } else if (attr == &dev_attr_fnode_initial_r2t.attr) {
929 param = ISCSI_FLASHNODE_INITIAL_R2T_EN;
930 } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) {
931 param = ISCSI_FLASHNODE_DATASEQ_INORDER;
932 } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) {
933 param = ISCSI_FLASHNODE_PDU_INORDER;
934 } else if (attr == &dev_attr_fnode_chap_auth.attr) {
935 param = ISCSI_FLASHNODE_CHAP_AUTH_EN;
936 } else if (attr == &dev_attr_fnode_discovery_logout.attr) {
937 param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN;
938 } else if (attr == &dev_attr_fnode_bidi_chap.attr) {
939 param = ISCSI_FLASHNODE_BIDI_CHAP_EN;
940 } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) {
941 param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL;
942 } else if (attr == &dev_attr_fnode_erl.attr) {
943 param = ISCSI_FLASHNODE_ERL;
944 } else if (attr == &dev_attr_fnode_first_burst_len.attr) {
945 param = ISCSI_FLASHNODE_FIRST_BURST;
946 } else if (attr == &dev_attr_fnode_def_time2wait.attr) {
947 param = ISCSI_FLASHNODE_DEF_TIME2WAIT;
948 } else if (attr == &dev_attr_fnode_def_time2retain.attr) {
949 param = ISCSI_FLASHNODE_DEF_TIME2RETAIN;
950 } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) {
951 param = ISCSI_FLASHNODE_MAX_R2T;
952 } else if (attr == &dev_attr_fnode_isid.attr) {
953 param = ISCSI_FLASHNODE_ISID;
954 } else if (attr == &dev_attr_fnode_tsid.attr) {
955 param = ISCSI_FLASHNODE_TSID;
956 } else if (attr == &dev_attr_fnode_max_burst_len.attr) {
957 param = ISCSI_FLASHNODE_MAX_BURST;
958 } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) {
959 param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO;
960 } else if (attr == &dev_attr_fnode_targetalias.attr) {
961 param = ISCSI_FLASHNODE_ALIAS;
962 } else if (attr == &dev_attr_fnode_targetname.attr) {
963 param = ISCSI_FLASHNODE_NAME;
964 } else if (attr == &dev_attr_fnode_tpgt.attr) {
965 param = ISCSI_FLASHNODE_TPGT;
966 } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) {
967 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX;
968 } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) {
969 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE;
970 } else if (attr == &dev_attr_fnode_chap_in_idx.attr) {
971 param = ISCSI_FLASHNODE_CHAP_IN_IDX;
972 } else if (attr == &dev_attr_fnode_chap_out_idx.attr) {
973 param = ISCSI_FLASHNODE_CHAP_OUT_IDX;
974 } else if (attr == &dev_attr_fnode_username.attr) {
975 param = ISCSI_FLASHNODE_USERNAME;
976 } else if (attr == &dev_attr_fnode_username_in.attr) {
977 param = ISCSI_FLASHNODE_USERNAME_IN;
978 } else if (attr == &dev_attr_fnode_password.attr) {
979 param = ISCSI_FLASHNODE_PASSWORD;
980 } else if (attr == &dev_attr_fnode_password_in.attr) {
981 param = ISCSI_FLASHNODE_PASSWORD_IN;
982 } else if (attr == &dev_attr_fnode_is_boot_target.attr) {
983 param = ISCSI_FLASHNODE_IS_BOOT_TGT;
985 WARN_ONCE(1, "Invalid flashnode session attr");
989 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
992 static struct attribute_group iscsi_flashnode_sess_attr_group = {
993 .attrs = iscsi_flashnode_sess_attrs,
994 .is_visible = iscsi_flashnode_sess_attr_is_visible,
997 static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = {
998 &iscsi_flashnode_sess_attr_group,
1002 static void iscsi_flashnode_sess_release(struct device *dev)
1004 struct iscsi_bus_flash_session *fnode_sess =
1005 iscsi_dev_to_flash_session(dev);
1007 kfree(fnode_sess->targetname);
1008 kfree(fnode_sess->targetalias);
1009 kfree(fnode_sess->portal_type);
1013 static const struct device_type iscsi_flashnode_sess_dev_type = {
1014 .name = "iscsi_flashnode_sess_dev_type",
1015 .groups = iscsi_flashnode_sess_attr_groups,
1016 .release = iscsi_flashnode_sess_release,
1019 /* flash node connection attrs show */
1020 #define iscsi_flashnode_conn_attr_show(type, name, param) \
1022 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
1025 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
1026 struct iscsi_bus_flash_session *fnode_sess = \
1027 iscsi_flash_conn_to_flash_session(fnode_conn);\
1028 struct iscsi_transport *t = fnode_conn->transport; \
1029 return t->get_flashnode_param(fnode_sess, param, buf); \
1033 #define iscsi_flashnode_conn_attr(type, name, param) \
1034 iscsi_flashnode_conn_attr_show(type, name, param) \
1035 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
1036 show_##type##_##name, NULL);
1038 /* Flash node connection attributes */
1040 iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6,
1041 ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6);
1042 iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN);
1043 iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN);
1044 iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN);
1045 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat,
1046 ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT);
1047 iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable,
1048 ISCSI_FLASHNODE_TCP_NAGLE_DISABLE);
1049 iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable,
1050 ISCSI_FLASHNODE_TCP_WSF_DISABLE);
1051 iscsi_flashnode_conn_attr(fnode, tcp_timer_scale,
1052 ISCSI_FLASHNODE_TCP_TIMER_SCALE);
1053 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable,
1054 ISCSI_FLASHNODE_TCP_TIMESTAMP_EN);
1055 iscsi_flashnode_conn_attr(fnode, fragment_disable,
1056 ISCSI_FLASHNODE_IP_FRAG_DISABLE);
1057 iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO);
1058 iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT);
1059 iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR);
1060 iscsi_flashnode_conn_attr(fnode, max_recv_dlength,
1061 ISCSI_FLASHNODE_MAX_RECV_DLENGTH);
1062 iscsi_flashnode_conn_attr(fnode, max_xmit_dlength,
1063 ISCSI_FLASHNODE_MAX_XMIT_DLENGTH);
1064 iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT);
1065 iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS);
1066 iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC);
1067 iscsi_flashnode_conn_attr(fnode, ipv6_flow_label,
1068 ISCSI_FLASHNODE_IPV6_FLOW_LABEL);
1069 iscsi_flashnode_conn_attr(fnode, redirect_ipaddr,
1070 ISCSI_FLASHNODE_REDIRECT_IPADDR);
1071 iscsi_flashnode_conn_attr(fnode, max_segment_size,
1072 ISCSI_FLASHNODE_MAX_SEGMENT_SIZE);
1073 iscsi_flashnode_conn_attr(fnode, link_local_ipv6,
1074 ISCSI_FLASHNODE_LINK_LOCAL_IPV6);
1075 iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF);
1076 iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF);
1077 iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN);
1078 iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN);
1080 static struct attribute *iscsi_flashnode_conn_attrs[] = {
1081 &dev_attr_fnode_is_fw_assigned_ipv6.attr,
1082 &dev_attr_fnode_header_digest.attr,
1083 &dev_attr_fnode_data_digest.attr,
1084 &dev_attr_fnode_snack_req.attr,
1085 &dev_attr_fnode_tcp_timestamp_stat.attr,
1086 &dev_attr_fnode_tcp_nagle_disable.attr,
1087 &dev_attr_fnode_tcp_wsf_disable.attr,
1088 &dev_attr_fnode_tcp_timer_scale.attr,
1089 &dev_attr_fnode_tcp_timestamp_enable.attr,
1090 &dev_attr_fnode_fragment_disable.attr,
1091 &dev_attr_fnode_max_recv_dlength.attr,
1092 &dev_attr_fnode_max_xmit_dlength.attr,
1093 &dev_attr_fnode_keepalive_tmo.attr,
1094 &dev_attr_fnode_port.attr,
1095 &dev_attr_fnode_ipaddress.attr,
1096 &dev_attr_fnode_redirect_ipaddr.attr,
1097 &dev_attr_fnode_max_segment_size.attr,
1098 &dev_attr_fnode_local_port.attr,
1099 &dev_attr_fnode_ipv4_tos.attr,
1100 &dev_attr_fnode_ipv6_traffic_class.attr,
1101 &dev_attr_fnode_ipv6_flow_label.attr,
1102 &dev_attr_fnode_link_local_ipv6.attr,
1103 &dev_attr_fnode_tcp_xmit_wsf.attr,
1104 &dev_attr_fnode_tcp_recv_wsf.attr,
1105 &dev_attr_fnode_statsn.attr,
1106 &dev_attr_fnode_exp_statsn.attr,
1110 static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj,
1111 struct attribute *attr,
1114 struct device *dev = container_of(kobj, struct device, kobj);
1115 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1116 struct iscsi_transport *t = fnode_conn->transport;
1119 if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) {
1120 param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6;
1121 } else if (attr == &dev_attr_fnode_header_digest.attr) {
1122 param = ISCSI_FLASHNODE_HDR_DGST_EN;
1123 } else if (attr == &dev_attr_fnode_data_digest.attr) {
1124 param = ISCSI_FLASHNODE_DATA_DGST_EN;
1125 } else if (attr == &dev_attr_fnode_snack_req.attr) {
1126 param = ISCSI_FLASHNODE_SNACK_REQ_EN;
1127 } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) {
1128 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT;
1129 } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) {
1130 param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE;
1131 } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) {
1132 param = ISCSI_FLASHNODE_TCP_WSF_DISABLE;
1133 } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) {
1134 param = ISCSI_FLASHNODE_TCP_TIMER_SCALE;
1135 } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) {
1136 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN;
1137 } else if (attr == &dev_attr_fnode_fragment_disable.attr) {
1138 param = ISCSI_FLASHNODE_IP_FRAG_DISABLE;
1139 } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) {
1140 param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH;
1141 } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) {
1142 param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH;
1143 } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) {
1144 param = ISCSI_FLASHNODE_KEEPALIVE_TMO;
1145 } else if (attr == &dev_attr_fnode_port.attr) {
1146 param = ISCSI_FLASHNODE_PORT;
1147 } else if (attr == &dev_attr_fnode_ipaddress.attr) {
1148 param = ISCSI_FLASHNODE_IPADDR;
1149 } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) {
1150 param = ISCSI_FLASHNODE_REDIRECT_IPADDR;
1151 } else if (attr == &dev_attr_fnode_max_segment_size.attr) {
1152 param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE;
1153 } else if (attr == &dev_attr_fnode_local_port.attr) {
1154 param = ISCSI_FLASHNODE_LOCAL_PORT;
1155 } else if (attr == &dev_attr_fnode_ipv4_tos.attr) {
1156 param = ISCSI_FLASHNODE_IPV4_TOS;
1157 } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) {
1158 param = ISCSI_FLASHNODE_IPV6_TC;
1159 } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) {
1160 param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL;
1161 } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) {
1162 param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6;
1163 } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) {
1164 param = ISCSI_FLASHNODE_TCP_XMIT_WSF;
1165 } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) {
1166 param = ISCSI_FLASHNODE_TCP_RECV_WSF;
1167 } else if (attr == &dev_attr_fnode_statsn.attr) {
1168 param = ISCSI_FLASHNODE_STATSN;
1169 } else if (attr == &dev_attr_fnode_exp_statsn.attr) {
1170 param = ISCSI_FLASHNODE_EXP_STATSN;
1172 WARN_ONCE(1, "Invalid flashnode connection attr");
1176 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
1179 static struct attribute_group iscsi_flashnode_conn_attr_group = {
1180 .attrs = iscsi_flashnode_conn_attrs,
1181 .is_visible = iscsi_flashnode_conn_attr_is_visible,
1184 static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = {
1185 &iscsi_flashnode_conn_attr_group,
1189 static void iscsi_flashnode_conn_release(struct device *dev)
1191 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1193 kfree(fnode_conn->ipaddress);
1194 kfree(fnode_conn->redirect_ipaddr);
1195 kfree(fnode_conn->link_local_ipv6_addr);
1199 static const struct device_type iscsi_flashnode_conn_dev_type = {
1200 .name = "iscsi_flashnode_conn_dev_type",
1201 .groups = iscsi_flashnode_conn_attr_groups,
1202 .release = iscsi_flashnode_conn_release,
1205 static struct bus_type iscsi_flashnode_bus;
1207 int iscsi_flashnode_bus_match(struct device *dev,
1208 struct device_driver *drv)
1210 if (dev->bus == &iscsi_flashnode_bus)
1214 EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match);
1216 static struct bus_type iscsi_flashnode_bus = {
1217 .name = "iscsi_flashnode",
1218 .match = &iscsi_flashnode_bus_match,
1222 * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
1223 * @shost: pointer to host data
1224 * @index: index of flashnode to add in sysfs
1225 * @transport: pointer to transport data
1226 * @dd_size: total size to allocate
1228 * Adds a sysfs entry for the flashnode session attributes
1231 * pointer to allocated flashnode sess on success
1234 struct iscsi_bus_flash_session *
1235 iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
1236 struct iscsi_transport *transport,
1239 struct iscsi_bus_flash_session *fnode_sess;
1242 fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL);
1246 fnode_sess->transport = transport;
1247 fnode_sess->target_id = index;
1248 fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type;
1249 fnode_sess->dev.bus = &iscsi_flashnode_bus;
1250 fnode_sess->dev.parent = &shost->shost_gendev;
1251 dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u",
1252 shost->host_no, index);
1254 err = device_register(&fnode_sess->dev);
1259 fnode_sess->dd_data = &fnode_sess[1];
1264 put_device(&fnode_sess->dev);
1267 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
1270 * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
1271 * @shost: pointer to host data
1272 * @fnode_sess: pointer to the parent flashnode session entry
1273 * @transport: pointer to transport data
1274 * @dd_size: total size to allocate
1276 * Adds a sysfs entry for the flashnode connection attributes
1279 * pointer to allocated flashnode conn on success
1282 struct iscsi_bus_flash_conn *
1283 iscsi_create_flashnode_conn(struct Scsi_Host *shost,
1284 struct iscsi_bus_flash_session *fnode_sess,
1285 struct iscsi_transport *transport,
1288 struct iscsi_bus_flash_conn *fnode_conn;
1291 fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL);
1295 fnode_conn->transport = transport;
1296 fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type;
1297 fnode_conn->dev.bus = &iscsi_flashnode_bus;
1298 fnode_conn->dev.parent = &fnode_sess->dev;
1299 dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0",
1300 shost->host_no, fnode_sess->target_id);
1302 err = device_register(&fnode_conn->dev);
1307 fnode_conn->dd_data = &fnode_conn[1];
1312 put_device(&fnode_conn->dev);
1315 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
1318 * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
1319 * @dev: device to verify
1320 * @data: pointer to data containing value to use for verification
1322 * Verifies if the passed device is flashnode conn device
1328 static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
1330 return dev->bus == &iscsi_flashnode_bus;
1333 static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
1335 device_unregister(&fnode_conn->dev);
1339 static int flashnode_match_index(struct device *dev, void *data)
1341 struct iscsi_bus_flash_session *fnode_sess = NULL;
1344 if (!iscsi_flashnode_bus_match(dev, NULL))
1345 goto exit_match_index;
1347 fnode_sess = iscsi_dev_to_flash_session(dev);
1348 ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
1355 * iscsi_get_flashnode_by_index -finds flashnode session entry by index
1356 * @shost: pointer to host data
1357 * @idx: index to match
1359 * Finds the flashnode session object for the passed index
1362 * pointer to found flashnode session object on success
1365 static struct iscsi_bus_flash_session *
1366 iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
1368 struct iscsi_bus_flash_session *fnode_sess = NULL;
1371 dev = device_find_child(&shost->shost_gendev, &idx,
1372 flashnode_match_index);
1374 fnode_sess = iscsi_dev_to_flash_session(dev);
1380 * iscsi_find_flashnode_sess - finds flashnode session entry
1381 * @shost: pointer to host data
1382 * @data: pointer to data containing value to use for comparison
1383 * @fn: function pointer that does actual comparison
1385 * Finds the flashnode session object comparing the data passed using logic
1386 * defined in passed function pointer
1389 * pointer to found flashnode session device object on success
1393 iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
1394 int (*fn)(struct device *dev, void *data))
1396 return device_find_child(&shost->shost_gendev, data, fn);
1398 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
1401 * iscsi_find_flashnode_conn - finds flashnode connection entry
1402 * @fnode_sess: pointer to parent flashnode session entry
1404 * Finds the flashnode connection object comparing the data passed using logic
1405 * defined in passed function pointer
1408 * pointer to found flashnode connection device object on success
1412 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
1414 return device_find_child(&fnode_sess->dev, NULL,
1415 iscsi_is_flashnode_conn_dev);
1417 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);
1419 static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data)
1421 if (!iscsi_is_flashnode_conn_dev(dev, NULL))
1424 return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev));
1428 * iscsi_destroy_flashnode_sess - destroy flashnode session entry
1429 * @fnode_sess: pointer to flashnode session entry to be destroyed
1431 * Deletes the flashnode session entry and all children flashnode connection
1432 * entries from sysfs
1434 void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess)
1438 err = device_for_each_child(&fnode_sess->dev, NULL,
1439 iscsi_iter_destroy_flashnode_conn_fn);
1441 pr_err("Could not delete all connections for %s. Error %d.\n",
1442 fnode_sess->dev.kobj.name, err);
1444 device_unregister(&fnode_sess->dev);
1446 EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);
1448 static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data)
1450 if (!iscsi_flashnode_bus_match(dev, NULL))
1453 iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev));
1458 * iscsi_destroy_all_flashnode - destroy all flashnode session entries
1459 * @shost: pointer to host data
1461 * Destroys all the flashnode session entries and all corresponding children
1462 * flashnode connection entries from sysfs
1464 void iscsi_destroy_all_flashnode(struct Scsi_Host *shost)
1466 device_for_each_child(&shost->shost_gendev, NULL,
1467 iscsi_iter_destroy_flashnode_fn);
1469 EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode);
1475 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
1476 * @job: bsg job to be processed
1478 static int iscsi_bsg_host_dispatch(struct bsg_job *job)
1480 struct Scsi_Host *shost = iscsi_job_to_shost(job);
1481 struct iscsi_bsg_request *req = job->request;
1482 struct iscsi_bsg_reply *reply = job->reply;
1483 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1484 int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
1487 /* check if we have the msgcode value at least */
1488 if (job->request_len < sizeof(uint32_t)) {
1493 /* Validate the host command */
1494 switch (req->msgcode) {
1495 case ISCSI_BSG_HST_VENDOR:
1496 cmdlen += sizeof(struct iscsi_bsg_host_vendor);
1497 if ((shost->hostt->vendor_id == 0L) ||
1498 (req->rqst_data.h_vendor.vendor_id !=
1499 shost->hostt->vendor_id)) {
1509 /* check if we really have all the request data needed */
1510 if (job->request_len < cmdlen) {
1515 ret = i->iscsi_transport->bsg_request(job);
1520 /* return the errno failure code as the only status */
1521 BUG_ON(job->reply_len < sizeof(uint32_t));
1522 reply->reply_payload_rcv_len = 0;
1523 reply->result = ret;
1524 job->reply_len = sizeof(uint32_t);
1525 bsg_job_done(job, ret, 0);
1530 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
1531 * @shost: shost for iscsi_host
1532 * @ihost: iscsi_cls_host adding the structures to
1535 iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
1537 struct device *dev = &shost->shost_gendev;
1538 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1539 struct request_queue *q;
1542 if (!i->iscsi_transport->bsg_request)
1545 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1546 q = bsg_setup_queue(dev, bsg_name, iscsi_bsg_host_dispatch, NULL, 0);
1548 shost_printk(KERN_ERR, shost, "bsg interface failed to "
1549 "initialize - no request queue\n");
1552 __scsi_init_queue(shost, q);
1558 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
1559 struct device *cdev)
1561 struct Scsi_Host *shost = dev_to_shost(dev);
1562 struct iscsi_cls_host *ihost = shost->shost_data;
1564 memset(ihost, 0, sizeof(*ihost));
1565 atomic_set(&ihost->nr_scans, 0);
1566 mutex_init(&ihost->mutex);
1568 iscsi_bsg_host_add(shost, ihost);
1569 /* ignore any bsg add error - we just can't do sgio */
1574 static int iscsi_remove_host(struct transport_container *tc,
1575 struct device *dev, struct device *cdev)
1577 struct Scsi_Host *shost = dev_to_shost(dev);
1578 struct iscsi_cls_host *ihost = shost->shost_data;
1580 bsg_remove_queue(ihost->bsg_q);
1584 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
1590 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
1596 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
1602 static struct sock *nls;
1603 static DEFINE_MUTEX(rx_queue_mutex);
1605 static LIST_HEAD(sesslist);
1606 static DEFINE_SPINLOCK(sesslock);
1607 static LIST_HEAD(connlist);
1608 static LIST_HEAD(connlist_err);
1609 static DEFINE_SPINLOCK(connlock);
1611 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
1613 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
1618 * Returns the matching session to a given sid
1620 static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
1622 unsigned long flags;
1623 struct iscsi_cls_session *sess;
1625 spin_lock_irqsave(&sesslock, flags);
1626 list_for_each_entry(sess, &sesslist, sess_list) {
1627 if (sess->sid == sid) {
1628 spin_unlock_irqrestore(&sesslock, flags);
1632 spin_unlock_irqrestore(&sesslock, flags);
1637 * Returns the matching connection to a given sid / cid tuple
1639 static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
1641 unsigned long flags;
1642 struct iscsi_cls_conn *conn;
1644 spin_lock_irqsave(&connlock, flags);
1645 list_for_each_entry(conn, &connlist, conn_list) {
1646 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
1647 spin_unlock_irqrestore(&connlock, flags);
1651 spin_unlock_irqrestore(&connlock, flags);
1656 * The following functions can be used by LLDs that allocate
1657 * their own scsi_hosts or by software iscsi LLDs
1662 } iscsi_session_state_names[] = {
1663 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
1664 { ISCSI_SESSION_FAILED, "FAILED" },
1665 { ISCSI_SESSION_FREE, "FREE" },
1668 static const char *iscsi_session_state_name(int state)
1673 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
1674 if (iscsi_session_state_names[i].value == state) {
1675 name = iscsi_session_state_names[i].name;
1682 int iscsi_session_chkready(struct iscsi_cls_session *session)
1686 switch (session->state) {
1687 case ISCSI_SESSION_LOGGED_IN:
1690 case ISCSI_SESSION_FAILED:
1691 err = DID_IMM_RETRY << 16;
1693 case ISCSI_SESSION_FREE:
1694 err = DID_TRANSPORT_FAILFAST << 16;
1697 err = DID_NO_CONNECT << 16;
1702 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
1704 int iscsi_is_session_online(struct iscsi_cls_session *session)
1706 unsigned long flags;
1709 spin_lock_irqsave(&session->lock, flags);
1710 if (session->state == ISCSI_SESSION_LOGGED_IN)
1712 spin_unlock_irqrestore(&session->lock, flags);
1715 EXPORT_SYMBOL_GPL(iscsi_is_session_online);
1717 static void iscsi_session_release(struct device *dev)
1719 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
1720 struct Scsi_Host *shost;
1722 shost = iscsi_session_to_shost(session);
1723 scsi_host_put(shost);
1724 ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
1728 int iscsi_is_session_dev(const struct device *dev)
1730 return dev->release == iscsi_session_release;
1732 EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
1734 static int iscsi_iter_session_fn(struct device *dev, void *data)
1736 void (* fn) (struct iscsi_cls_session *) = data;
1738 if (!iscsi_is_session_dev(dev))
1740 fn(iscsi_dev_to_session(dev));
1744 void iscsi_host_for_each_session(struct Scsi_Host *shost,
1745 void (*fn)(struct iscsi_cls_session *))
1747 device_for_each_child(&shost->shost_gendev, fn,
1748 iscsi_iter_session_fn);
1750 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
1753 * iscsi_scan_finished - helper to report when running scans are done
1755 * @time: scan run time
1757 * This function can be used by drives like qla4xxx to report to the scsi
1758 * layer when the scans it kicked off at module load time are done.
1760 int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
1762 struct iscsi_cls_host *ihost = shost->shost_data;
1764 * qla4xxx will have kicked off some session unblocks before calling
1765 * scsi_scan_host, so just wait for them to complete.
1767 return !atomic_read(&ihost->nr_scans);
1769 EXPORT_SYMBOL_GPL(iscsi_scan_finished);
1771 struct iscsi_scan_data {
1772 unsigned int channel;
1775 enum scsi_scan_mode rescan;
1778 static int iscsi_user_scan_session(struct device *dev, void *data)
1780 struct iscsi_scan_data *scan_data = data;
1781 struct iscsi_cls_session *session;
1782 struct Scsi_Host *shost;
1783 struct iscsi_cls_host *ihost;
1784 unsigned long flags;
1787 if (!iscsi_is_session_dev(dev))
1790 session = iscsi_dev_to_session(dev);
1792 ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
1794 shost = iscsi_session_to_shost(session);
1795 ihost = shost->shost_data;
1797 mutex_lock(&ihost->mutex);
1798 spin_lock_irqsave(&session->lock, flags);
1799 if (session->state != ISCSI_SESSION_LOGGED_IN) {
1800 spin_unlock_irqrestore(&session->lock, flags);
1801 goto user_scan_exit;
1803 id = session->target_id;
1804 spin_unlock_irqrestore(&session->lock, flags);
1806 if (id != ISCSI_MAX_TARGET) {
1807 if ((scan_data->channel == SCAN_WILD_CARD ||
1808 scan_data->channel == 0) &&
1809 (scan_data->id == SCAN_WILD_CARD ||
1810 scan_data->id == id))
1811 scsi_scan_target(&session->dev, 0, id,
1812 scan_data->lun, scan_data->rescan);
1816 mutex_unlock(&ihost->mutex);
1817 ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
1821 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
1824 struct iscsi_scan_data scan_data;
1826 scan_data.channel = channel;
1828 scan_data.lun = lun;
1829 scan_data.rescan = SCSI_SCAN_MANUAL;
1831 return device_for_each_child(&shost->shost_gendev, &scan_data,
1832 iscsi_user_scan_session);
1835 static void iscsi_scan_session(struct work_struct *work)
1837 struct iscsi_cls_session *session =
1838 container_of(work, struct iscsi_cls_session, scan_work);
1839 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1840 struct iscsi_cls_host *ihost = shost->shost_data;
1841 struct iscsi_scan_data scan_data;
1843 scan_data.channel = 0;
1844 scan_data.id = SCAN_WILD_CARD;
1845 scan_data.lun = SCAN_WILD_CARD;
1846 scan_data.rescan = SCSI_SCAN_RESCAN;
1848 iscsi_user_scan_session(&session->dev, &scan_data);
1849 atomic_dec(&ihost->nr_scans);
1853 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1854 * @cmd: scsi cmd passed to scsi eh handler
1856 * If the session is down this function will wait for the recovery
1857 * timer to fire or for the session to be logged back in. If the
1858 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1859 * should pass this error value to the scsi eh.
1861 int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
1863 struct iscsi_cls_session *session =
1864 starget_to_session(scsi_target(cmd->device));
1865 unsigned long flags;
1868 spin_lock_irqsave(&session->lock, flags);
1869 while (session->state != ISCSI_SESSION_LOGGED_IN) {
1870 if (session->state == ISCSI_SESSION_FREE) {
1874 spin_unlock_irqrestore(&session->lock, flags);
1876 spin_lock_irqsave(&session->lock, flags);
1878 spin_unlock_irqrestore(&session->lock, flags);
1881 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
1883 static void session_recovery_timedout(struct work_struct *work)
1885 struct iscsi_cls_session *session =
1886 container_of(work, struct iscsi_cls_session,
1887 recovery_work.work);
1888 unsigned long flags;
1890 iscsi_cls_session_printk(KERN_INFO, session,
1891 "session recovery timed out after %d secs\n",
1892 session->recovery_tmo);
1894 spin_lock_irqsave(&session->lock, flags);
1895 switch (session->state) {
1896 case ISCSI_SESSION_FAILED:
1897 session->state = ISCSI_SESSION_FREE;
1899 case ISCSI_SESSION_LOGGED_IN:
1900 case ISCSI_SESSION_FREE:
1901 /* we raced with the unblock's flush */
1902 spin_unlock_irqrestore(&session->lock, flags);
1905 spin_unlock_irqrestore(&session->lock, flags);
1907 ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
1908 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
1909 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
1911 if (session->transport->session_recovery_timedout)
1912 session->transport->session_recovery_timedout(session);
1915 static void __iscsi_unblock_session(struct work_struct *work)
1917 struct iscsi_cls_session *session =
1918 container_of(work, struct iscsi_cls_session,
1920 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1921 struct iscsi_cls_host *ihost = shost->shost_data;
1922 unsigned long flags;
1924 ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
1926 * The recovery and unblock work get run from the same workqueue,
1927 * so try to cancel it if it was going to run after this unblock.
1929 cancel_delayed_work(&session->recovery_work);
1930 spin_lock_irqsave(&session->lock, flags);
1931 session->state = ISCSI_SESSION_LOGGED_IN;
1932 spin_unlock_irqrestore(&session->lock, flags);
1934 scsi_target_unblock(&session->dev, SDEV_RUNNING);
1936 * Only do kernel scanning if the driver is properly hooked into
1937 * the async scanning code (drivers like iscsi_tcp do login and
1938 * scanning from userspace).
1940 if (shost->hostt->scan_finished) {
1941 if (scsi_queue_work(shost, &session->scan_work))
1942 atomic_inc(&ihost->nr_scans);
1944 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
1948 * iscsi_unblock_session - set a session as logged in and start IO.
1949 * @session: iscsi session
1951 * Mark a session as ready to accept IO.
1953 void iscsi_unblock_session(struct iscsi_cls_session *session)
1955 flush_work(&session->block_work);
1957 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
1959 * Blocking the session can be done from any context so we only
1960 * queue the block work. Make sure the unblock work has completed
1961 * because it flushes/cancels the other works and updates the state.
1963 flush_work(&session->unblock_work);
1965 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
1967 static void __iscsi_block_session(struct work_struct *work)
1969 struct iscsi_cls_session *session =
1970 container_of(work, struct iscsi_cls_session,
1972 unsigned long flags;
1974 ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
1975 spin_lock_irqsave(&session->lock, flags);
1976 session->state = ISCSI_SESSION_FAILED;
1977 spin_unlock_irqrestore(&session->lock, flags);
1978 scsi_target_block(&session->dev);
1979 ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
1980 if (session->recovery_tmo >= 0)
1981 queue_delayed_work(iscsi_eh_timer_workq,
1982 &session->recovery_work,
1983 session->recovery_tmo * HZ);
1986 void iscsi_block_session(struct iscsi_cls_session *session)
1988 queue_work(iscsi_eh_timer_workq, &session->block_work);
1990 EXPORT_SYMBOL_GPL(iscsi_block_session);
1992 static void __iscsi_unbind_session(struct work_struct *work)
1994 struct iscsi_cls_session *session =
1995 container_of(work, struct iscsi_cls_session,
1997 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1998 struct iscsi_cls_host *ihost = shost->shost_data;
1999 unsigned long flags;
2000 unsigned int target_id;
2002 ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
2004 /* Prevent new scans and make sure scanning is not in progress */
2005 mutex_lock(&ihost->mutex);
2006 spin_lock_irqsave(&session->lock, flags);
2007 if (session->target_id == ISCSI_MAX_TARGET) {
2008 spin_unlock_irqrestore(&session->lock, flags);
2009 mutex_unlock(&ihost->mutex);
2010 goto unbind_session_exit;
2013 target_id = session->target_id;
2014 session->target_id = ISCSI_MAX_TARGET;
2015 spin_unlock_irqrestore(&session->lock, flags);
2016 mutex_unlock(&ihost->mutex);
2018 scsi_remove_target(&session->dev);
2020 if (session->ida_used)
2021 ida_simple_remove(&iscsi_sess_ida, target_id);
2023 unbind_session_exit:
2024 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
2025 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
2028 static void __iscsi_destroy_session(struct work_struct *work)
2030 struct iscsi_cls_session *session =
2031 container_of(work, struct iscsi_cls_session, destroy_work);
2033 session->transport->destroy_session(session);
2036 struct iscsi_cls_session *
2037 iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2040 struct iscsi_cls_session *session;
2042 session = kzalloc(sizeof(*session) + dd_size,
2047 session->transport = transport;
2048 session->creator = -1;
2049 session->recovery_tmo = 120;
2050 session->recovery_tmo_sysfs_override = false;
2051 session->state = ISCSI_SESSION_FREE;
2052 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
2053 INIT_LIST_HEAD(&session->sess_list);
2054 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
2055 INIT_WORK(&session->block_work, __iscsi_block_session);
2056 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
2057 INIT_WORK(&session->scan_work, iscsi_scan_session);
2058 INIT_WORK(&session->destroy_work, __iscsi_destroy_session);
2059 spin_lock_init(&session->lock);
2061 /* this is released in the dev's release function */
2062 scsi_host_get(shost);
2063 session->dev.parent = &shost->shost_gendev;
2064 session->dev.release = iscsi_session_release;
2065 device_initialize(&session->dev);
2067 session->dd_data = &session[1];
2069 ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
2072 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
2074 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
2076 unsigned long flags;
2080 session->sid = atomic_add_return(1, &iscsi_session_nr);
2082 if (target_id == ISCSI_MAX_TARGET) {
2083 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
2086 iscsi_cls_session_printk(KERN_ERR, session,
2087 "Failure in Target ID Allocation\n");
2090 session->target_id = (unsigned int)id;
2091 session->ida_used = true;
2093 session->target_id = target_id;
2095 dev_set_name(&session->dev, "session%u", session->sid);
2096 err = device_add(&session->dev);
2098 iscsi_cls_session_printk(KERN_ERR, session,
2099 "could not register session's dev\n");
2102 err = transport_register_device(&session->dev);
2104 iscsi_cls_session_printk(KERN_ERR, session,
2105 "could not register transport's dev\n");
2109 spin_lock_irqsave(&sesslock, flags);
2110 list_add(&session->sess_list, &sesslist);
2111 spin_unlock_irqrestore(&sesslock, flags);
2113 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
2114 ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
2118 device_del(&session->dev);
2120 if (session->ida_used)
2121 ida_simple_remove(&iscsi_sess_ida, session->target_id);
2125 EXPORT_SYMBOL_GPL(iscsi_add_session);
2128 * iscsi_create_session - create iscsi class session
2130 * @transport: iscsi transport
2131 * @dd_size: private driver data size
2132 * @target_id: which target
2134 * This can be called from a LLD or iscsi_transport.
2136 struct iscsi_cls_session *
2137 iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2138 int dd_size, unsigned int target_id)
2140 struct iscsi_cls_session *session;
2142 session = iscsi_alloc_session(shost, transport, dd_size);
2146 if (iscsi_add_session(session, target_id)) {
2147 iscsi_free_session(session);
2152 EXPORT_SYMBOL_GPL(iscsi_create_session);
2154 static void iscsi_conn_release(struct device *dev)
2156 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
2157 struct device *parent = conn->dev.parent;
2159 ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
2164 static int iscsi_is_conn_dev(const struct device *dev)
2166 return dev->release == iscsi_conn_release;
2169 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
2171 if (!iscsi_is_conn_dev(dev))
2173 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
2176 void iscsi_remove_session(struct iscsi_cls_session *session)
2178 unsigned long flags;
2181 ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
2183 spin_lock_irqsave(&sesslock, flags);
2184 if (!list_empty(&session->sess_list))
2185 list_del(&session->sess_list);
2186 spin_unlock_irqrestore(&sesslock, flags);
2188 flush_work(&session->block_work);
2189 flush_work(&session->unblock_work);
2190 cancel_delayed_work_sync(&session->recovery_work);
2192 * If we are blocked let commands flow again. The lld or iscsi
2193 * layer should set up the queuecommand to fail commands.
2194 * We assume that LLD will not be calling block/unblock while
2195 * removing the session.
2197 spin_lock_irqsave(&session->lock, flags);
2198 session->state = ISCSI_SESSION_FREE;
2199 spin_unlock_irqrestore(&session->lock, flags);
2201 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2202 /* flush running scans then delete devices */
2203 flush_work(&session->scan_work);
2204 /* flush running unbind operations */
2205 flush_work(&session->unbind_work);
2206 __iscsi_unbind_session(&session->unbind_work);
2208 /* hw iscsi may not have removed all connections from session */
2209 err = device_for_each_child(&session->dev, NULL,
2210 iscsi_iter_destroy_conn_fn);
2212 iscsi_cls_session_printk(KERN_ERR, session,
2213 "Could not delete all connections "
2214 "for session. Error %d.\n", err);
2216 transport_unregister_device(&session->dev);
2218 ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
2219 device_del(&session->dev);
2221 EXPORT_SYMBOL_GPL(iscsi_remove_session);
2223 static void iscsi_stop_conn(struct iscsi_cls_conn *conn, int flag)
2225 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn.\n");
2228 case STOP_CONN_RECOVER:
2229 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2231 case STOP_CONN_TERM:
2232 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2235 iscsi_cls_conn_printk(KERN_ERR, conn, "invalid stop flag %d\n",
2240 conn->transport->stop_conn(conn, flag);
2241 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn done.\n");
2244 static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
2246 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2247 struct iscsi_endpoint *ep;
2249 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep.\n");
2250 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2252 if (!conn->ep || !session->transport->ep_disconnect)
2258 session->transport->unbind_conn(conn, is_active);
2259 session->transport->ep_disconnect(ep);
2260 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep done.\n");
2263 static void iscsi_if_disconnect_bound_ep(struct iscsi_cls_conn *conn,
2264 struct iscsi_endpoint *ep,
2267 /* Check if this was a conn error and the kernel took ownership */
2268 spin_lock_irq(&conn->lock);
2269 if (!test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2270 spin_unlock_irq(&conn->lock);
2271 iscsi_ep_disconnect(conn, is_active);
2273 spin_unlock_irq(&conn->lock);
2274 ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2275 mutex_unlock(&conn->ep_mutex);
2277 flush_work(&conn->cleanup_work);
2279 * Userspace is now done with the EP so we can release the ref
2280 * iscsi_cleanup_conn_work_fn took.
2282 iscsi_put_endpoint(ep);
2283 mutex_lock(&conn->ep_mutex);
2287 static int iscsi_if_stop_conn(struct iscsi_cls_conn *conn, int flag)
2289 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop.\n");
2291 * If this is a termination we have to call stop_conn with that flag
2292 * so the correct states get set. If we haven't run the work yet try to
2293 * avoid the extra run.
2295 if (flag == STOP_CONN_TERM) {
2296 cancel_work_sync(&conn->cleanup_work);
2297 iscsi_stop_conn(conn, flag);
2300 * For offload, when iscsid is restarted it won't know about
2301 * existing endpoints so it can't do a ep_disconnect. We clean
2302 * it up here for userspace.
2304 mutex_lock(&conn->ep_mutex);
2306 iscsi_if_disconnect_bound_ep(conn, conn->ep, true);
2307 mutex_unlock(&conn->ep_mutex);
2310 * Figure out if it was the kernel or userspace initiating this.
2312 spin_lock_irq(&conn->lock);
2313 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2314 spin_unlock_irq(&conn->lock);
2315 iscsi_stop_conn(conn, flag);
2317 spin_unlock_irq(&conn->lock);
2318 ISCSI_DBG_TRANS_CONN(conn,
2319 "flush kernel conn cleanup.\n");
2320 flush_work(&conn->cleanup_work);
2323 * Only clear for recovery to avoid extra cleanup runs during
2326 spin_lock_irq(&conn->lock);
2327 clear_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags);
2328 spin_unlock_irq(&conn->lock);
2330 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop done.\n");
2334 static void iscsi_cleanup_conn_work_fn(struct work_struct *work)
2336 struct iscsi_cls_conn *conn = container_of(work, struct iscsi_cls_conn,
2338 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2340 mutex_lock(&conn->ep_mutex);
2342 * Get a ref to the ep, so we don't release its ID until after
2343 * userspace is done referencing it in iscsi_if_disconnect_bound_ep.
2346 get_device(&conn->ep->dev);
2347 iscsi_ep_disconnect(conn, false);
2349 if (system_state != SYSTEM_RUNNING) {
2351 * If the user has set up for the session to never timeout
2352 * then hang like they wanted. For all other cases fail right
2353 * away since userspace is not going to relogin.
2355 if (session->recovery_tmo > 0)
2356 session->recovery_tmo = 0;
2359 iscsi_stop_conn(conn, STOP_CONN_RECOVER);
2360 mutex_unlock(&conn->ep_mutex);
2361 ISCSI_DBG_TRANS_CONN(conn, "cleanup done.\n");
2364 static int iscsi_iter_force_destroy_conn_fn(struct device *dev, void *data)
2366 struct iscsi_transport *transport;
2367 struct iscsi_cls_conn *conn;
2369 if (!iscsi_is_conn_dev(dev))
2372 conn = iscsi_dev_to_conn(dev);
2373 transport = conn->transport;
2375 if (READ_ONCE(conn->state) != ISCSI_CONN_DOWN)
2376 iscsi_if_stop_conn(conn, STOP_CONN_TERM);
2378 transport->destroy_conn(conn);
2383 * iscsi_force_destroy_session - destroy a session from the kernel
2384 * @session: session to destroy
2386 * Force the destruction of a session from the kernel. This should only be
2387 * used when userspace is no longer running during system shutdown.
2389 void iscsi_force_destroy_session(struct iscsi_cls_session *session)
2391 struct iscsi_transport *transport = session->transport;
2392 unsigned long flags;
2394 WARN_ON_ONCE(system_state == SYSTEM_RUNNING);
2396 spin_lock_irqsave(&sesslock, flags);
2397 if (list_empty(&session->sess_list)) {
2398 spin_unlock_irqrestore(&sesslock, flags);
2400 * Conn/ep is already freed. Session is being torn down via
2401 * async path. For shutdown we don't care about it so return.
2405 spin_unlock_irqrestore(&sesslock, flags);
2407 device_for_each_child(&session->dev, NULL,
2408 iscsi_iter_force_destroy_conn_fn);
2409 transport->destroy_session(session);
2411 EXPORT_SYMBOL_GPL(iscsi_force_destroy_session);
2413 void iscsi_free_session(struct iscsi_cls_session *session)
2415 ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
2416 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
2417 put_device(&session->dev);
2419 EXPORT_SYMBOL_GPL(iscsi_free_session);
2422 * iscsi_create_conn - create iscsi class connection
2423 * @session: iscsi cls session
2424 * @dd_size: private driver data size
2425 * @cid: connection id
2427 * This can be called from a LLD or iscsi_transport. The connection
2428 * is child of the session so cid must be unique for all connections
2431 * Since we do not support MCS, cid will normally be zero. In some cases
2432 * for software iscsi we could be trying to preallocate a connection struct
2433 * in which case there could be two connection structs and cid would be
2436 struct iscsi_cls_conn *
2437 iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
2439 struct iscsi_transport *transport = session->transport;
2440 struct iscsi_cls_conn *conn;
2441 unsigned long flags;
2444 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
2448 conn->dd_data = &conn[1];
2450 mutex_init(&conn->ep_mutex);
2451 spin_lock_init(&conn->lock);
2452 INIT_LIST_HEAD(&conn->conn_list);
2453 INIT_WORK(&conn->cleanup_work, iscsi_cleanup_conn_work_fn);
2454 conn->transport = transport;
2456 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2458 /* this is released in the dev's release function */
2459 if (!get_device(&session->dev))
2462 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
2463 conn->dev.parent = &session->dev;
2464 conn->dev.release = iscsi_conn_release;
2465 err = device_register(&conn->dev);
2467 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2468 "register connection's dev\n");
2469 goto release_parent_ref;
2471 err = transport_register_device(&conn->dev);
2473 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2474 "register transport's dev\n");
2475 goto release_conn_ref;
2478 spin_lock_irqsave(&connlock, flags);
2479 list_add(&conn->conn_list, &connlist);
2480 spin_unlock_irqrestore(&connlock, flags);
2482 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
2486 device_unregister(&conn->dev);
2487 put_device(&session->dev);
2490 put_device(&session->dev);
2496 EXPORT_SYMBOL_GPL(iscsi_create_conn);
2499 * iscsi_destroy_conn - destroy iscsi class connection
2500 * @conn: iscsi cls session
2502 * This can be called from a LLD or iscsi_transport.
2504 int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
2506 unsigned long flags;
2508 spin_lock_irqsave(&connlock, flags);
2509 list_del(&conn->conn_list);
2510 spin_unlock_irqrestore(&connlock, flags);
2512 transport_unregister_device(&conn->dev);
2513 ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n");
2514 device_unregister(&conn->dev);
2517 EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
2519 void iscsi_put_conn(struct iscsi_cls_conn *conn)
2521 put_device(&conn->dev);
2523 EXPORT_SYMBOL_GPL(iscsi_put_conn);
2525 void iscsi_get_conn(struct iscsi_cls_conn *conn)
2527 get_device(&conn->dev);
2529 EXPORT_SYMBOL_GPL(iscsi_get_conn);
2532 * iscsi interface functions
2534 static struct iscsi_internal *
2535 iscsi_if_transport_lookup(struct iscsi_transport *tt)
2537 struct iscsi_internal *priv;
2538 unsigned long flags;
2540 spin_lock_irqsave(&iscsi_transport_lock, flags);
2541 list_for_each_entry(priv, &iscsi_transports, list) {
2542 if (tt == priv->iscsi_transport) {
2543 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2547 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2552 iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
2554 return nlmsg_multicast(nls, skb, 0, group, gfp);
2558 iscsi_unicast_skb(struct sk_buff *skb, u32 portid)
2560 return nlmsg_unicast(nls, skb, portid);
2563 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
2564 char *data, uint32_t data_size)
2566 struct nlmsghdr *nlh;
2567 struct sk_buff *skb;
2568 struct iscsi_uevent *ev;
2570 struct iscsi_internal *priv;
2571 int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
2574 priv = iscsi_if_transport_lookup(conn->transport);
2578 skb = alloc_skb(len, GFP_ATOMIC);
2580 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
2581 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
2582 "control PDU: OOM\n");
2586 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2587 ev = nlmsg_data(nlh);
2588 memset(ev, 0, sizeof(*ev));
2589 ev->transport_handle = iscsi_handle(conn->transport);
2590 ev->type = ISCSI_KEVENT_RECV_PDU;
2591 ev->r.recv_req.cid = conn->cid;
2592 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
2593 pdu = (char*)ev + sizeof(*ev);
2594 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
2595 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
2597 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2599 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
2601 int iscsi_offload_mesg(struct Scsi_Host *shost,
2602 struct iscsi_transport *transport, uint32_t type,
2603 char *data, uint16_t data_size)
2605 struct nlmsghdr *nlh;
2606 struct sk_buff *skb;
2607 struct iscsi_uevent *ev;
2608 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2610 skb = alloc_skb(len, GFP_ATOMIC);
2612 printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
2616 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2617 ev = nlmsg_data(nlh);
2618 memset(ev, 0, sizeof(*ev));
2620 ev->transport_handle = iscsi_handle(transport);
2622 case ISCSI_KEVENT_PATH_REQ:
2623 ev->r.req_path.host_no = shost->host_no;
2625 case ISCSI_KEVENT_IF_DOWN:
2626 ev->r.notify_if_down.host_no = shost->host_no;
2630 memcpy((char *)ev + sizeof(*ev), data, data_size);
2632 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
2634 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
2636 void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
2638 struct nlmsghdr *nlh;
2639 struct sk_buff *skb;
2640 struct iscsi_uevent *ev;
2641 struct iscsi_internal *priv;
2642 int len = nlmsg_total_size(sizeof(*ev));
2643 unsigned long flags;
2646 spin_lock_irqsave(&conn->lock, flags);
2648 * Userspace will only do a stop call if we are at least bound. And, we
2649 * only need to do the in kernel cleanup if in the UP state so cmds can
2650 * be released to upper layers. If in other states just wait for
2651 * userspace to avoid races that can leave the cleanup_work queued.
2653 state = READ_ONCE(conn->state);
2655 case ISCSI_CONN_BOUND:
2657 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP,
2659 queue_work(iscsi_conn_cleanup_workq,
2660 &conn->cleanup_work);
2664 ISCSI_DBG_TRANS_CONN(conn, "Got conn error in state %d\n",
2668 spin_unlock_irqrestore(&conn->lock, flags);
2670 priv = iscsi_if_transport_lookup(conn->transport);
2674 skb = alloc_skb(len, GFP_ATOMIC);
2676 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2677 "conn error (%d)\n", error);
2681 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2682 ev = nlmsg_data(nlh);
2683 ev->transport_handle = iscsi_handle(conn->transport);
2684 ev->type = ISCSI_KEVENT_CONN_ERROR;
2685 ev->r.connerror.error = error;
2686 ev->r.connerror.cid = conn->cid;
2687 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
2689 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2691 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
2694 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
2696 void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
2697 enum iscsi_conn_state state)
2699 struct nlmsghdr *nlh;
2700 struct sk_buff *skb;
2701 struct iscsi_uevent *ev;
2702 struct iscsi_internal *priv;
2703 int len = nlmsg_total_size(sizeof(*ev));
2705 priv = iscsi_if_transport_lookup(conn->transport);
2709 skb = alloc_skb(len, GFP_ATOMIC);
2711 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2712 "conn login (%d)\n", state);
2716 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2717 ev = nlmsg_data(nlh);
2718 ev->transport_handle = iscsi_handle(conn->transport);
2719 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
2720 ev->r.conn_login.state = state;
2721 ev->r.conn_login.cid = conn->cid;
2722 ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
2723 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2725 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
2728 EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
2730 void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
2731 enum iscsi_host_event_code code, uint32_t data_size,
2734 struct nlmsghdr *nlh;
2735 struct sk_buff *skb;
2736 struct iscsi_uevent *ev;
2737 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2739 skb = alloc_skb(len, GFP_NOIO);
2741 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
2746 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2747 ev = nlmsg_data(nlh);
2748 ev->transport_handle = iscsi_handle(transport);
2749 ev->type = ISCSI_KEVENT_HOST_EVENT;
2750 ev->r.host_event.host_no = host_no;
2751 ev->r.host_event.code = code;
2752 ev->r.host_event.data_size = data_size;
2755 memcpy((char *)ev + sizeof(*ev), data, data_size);
2757 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2759 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
2761 void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
2762 uint32_t status, uint32_t pid, uint32_t data_size,
2765 struct nlmsghdr *nlh;
2766 struct sk_buff *skb;
2767 struct iscsi_uevent *ev;
2768 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2770 skb = alloc_skb(len, GFP_NOIO);
2772 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
2776 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2777 ev = nlmsg_data(nlh);
2778 ev->transport_handle = iscsi_handle(transport);
2779 ev->type = ISCSI_KEVENT_PING_COMP;
2780 ev->r.ping_comp.host_no = host_no;
2781 ev->r.ping_comp.status = status;
2782 ev->r.ping_comp.pid = pid;
2783 ev->r.ping_comp.data_size = data_size;
2784 memcpy((char *)ev + sizeof(*ev), data, data_size);
2786 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2788 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
2791 iscsi_if_send_reply(u32 portid, int type, void *payload, int size)
2793 struct sk_buff *skb;
2794 struct nlmsghdr *nlh;
2795 int len = nlmsg_total_size(size);
2797 skb = alloc_skb(len, GFP_ATOMIC);
2799 printk(KERN_ERR "Could not allocate skb to send reply.\n");
2803 nlh = __nlmsg_put(skb, 0, 0, type, (len - sizeof(*nlh)), 0);
2804 memcpy(nlmsg_data(nlh), payload, size);
2805 return iscsi_unicast_skb(skb, portid);
2809 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
2811 struct iscsi_uevent *ev = nlmsg_data(nlh);
2812 struct iscsi_stats *stats;
2813 struct sk_buff *skbstat;
2814 struct iscsi_cls_conn *conn;
2815 struct nlmsghdr *nlhstat;
2816 struct iscsi_uevent *evstat;
2817 struct iscsi_internal *priv;
2818 int len = nlmsg_total_size(sizeof(*ev) +
2819 sizeof(struct iscsi_stats) +
2820 sizeof(struct iscsi_stats_custom) *
2821 ISCSI_STATS_CUSTOM_MAX);
2824 priv = iscsi_if_transport_lookup(transport);
2828 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
2835 skbstat = alloc_skb(len, GFP_ATOMIC);
2837 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
2838 "deliver stats: OOM\n");
2842 nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
2843 (len - sizeof(*nlhstat)), 0);
2844 evstat = nlmsg_data(nlhstat);
2845 memset(evstat, 0, sizeof(*evstat));
2846 evstat->transport_handle = iscsi_handle(conn->transport);
2847 evstat->type = nlh->nlmsg_type;
2848 evstat->u.get_stats.cid =
2849 ev->u.get_stats.cid;
2850 evstat->u.get_stats.sid =
2851 ev->u.get_stats.sid;
2852 stats = (struct iscsi_stats *)
2853 ((char*)evstat + sizeof(*evstat));
2854 memset(stats, 0, sizeof(*stats));
2856 transport->get_stats(conn, stats);
2857 actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
2858 sizeof(struct iscsi_stats) +
2859 sizeof(struct iscsi_stats_custom) *
2860 stats->custom_length);
2861 actual_size -= sizeof(*nlhstat);
2862 actual_size = nlmsg_msg_size(actual_size);
2863 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
2864 nlhstat->nlmsg_len = actual_size;
2866 err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
2868 } while (err < 0 && err != -ECONNREFUSED);
2874 * iscsi_session_event - send session destr. completion event
2875 * @session: iscsi class session
2876 * @event: type of event
2878 int iscsi_session_event(struct iscsi_cls_session *session,
2879 enum iscsi_uevent_e event)
2881 struct iscsi_internal *priv;
2882 struct Scsi_Host *shost;
2883 struct iscsi_uevent *ev;
2884 struct sk_buff *skb;
2885 struct nlmsghdr *nlh;
2886 int rc, len = nlmsg_total_size(sizeof(*ev));
2888 priv = iscsi_if_transport_lookup(session->transport);
2891 shost = iscsi_session_to_shost(session);
2893 skb = alloc_skb(len, GFP_KERNEL);
2895 iscsi_cls_session_printk(KERN_ERR, session,
2896 "Cannot notify userspace of session "
2897 "event %u\n", event);
2901 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2902 ev = nlmsg_data(nlh);
2903 ev->transport_handle = iscsi_handle(session->transport);
2907 case ISCSI_KEVENT_DESTROY_SESSION:
2908 ev->r.d_session.host_no = shost->host_no;
2909 ev->r.d_session.sid = session->sid;
2911 case ISCSI_KEVENT_CREATE_SESSION:
2912 ev->r.c_session_ret.host_no = shost->host_no;
2913 ev->r.c_session_ret.sid = session->sid;
2915 case ISCSI_KEVENT_UNBIND_SESSION:
2916 ev->r.unbind_session.host_no = shost->host_no;
2917 ev->r.unbind_session.sid = session->sid;
2920 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
2927 * this will occur if the daemon is not up, so we just warn
2928 * the user and when the daemon is restarted it will handle it
2930 rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
2932 iscsi_cls_session_printk(KERN_ERR, session,
2933 "Cannot notify userspace of session "
2934 "event %u. Check iscsi daemon\n",
2937 ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
2941 EXPORT_SYMBOL_GPL(iscsi_session_event);
2944 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
2945 struct iscsi_uevent *ev, pid_t pid,
2946 uint32_t initial_cmdsn, uint16_t cmds_max,
2947 uint16_t queue_depth)
2949 struct iscsi_transport *transport = priv->iscsi_transport;
2950 struct iscsi_cls_session *session;
2951 struct Scsi_Host *shost;
2953 session = transport->create_session(ep, cmds_max, queue_depth,
2958 session->creator = pid;
2959 shost = iscsi_session_to_shost(session);
2960 ev->r.c_session_ret.host_no = shost->host_no;
2961 ev->r.c_session_ret.sid = session->sid;
2962 ISCSI_DBG_TRANS_SESSION(session,
2963 "Completed creating transport session\n");
2968 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2970 struct iscsi_cls_conn *conn;
2971 struct iscsi_cls_session *session;
2973 session = iscsi_session_lookup(ev->u.c_conn.sid);
2975 printk(KERN_ERR "iscsi: invalid session %d.\n",
2980 conn = transport->create_conn(session, ev->u.c_conn.cid);
2982 iscsi_cls_session_printk(KERN_ERR, session,
2983 "couldn't create a new connection.");
2987 ev->r.c_conn_ret.sid = session->sid;
2988 ev->r.c_conn_ret.cid = conn->cid;
2990 ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
2995 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2997 struct iscsi_cls_conn *conn;
2999 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
3003 ISCSI_DBG_TRANS_CONN(conn, "Flushing cleanup during destruction\n");
3004 flush_work(&conn->cleanup_work);
3005 ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
3007 if (transport->destroy_conn)
3008 transport->destroy_conn(conn);
3013 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3015 char *data = (char*)ev + sizeof(*ev);
3016 struct iscsi_cls_conn *conn;
3017 struct iscsi_cls_session *session;
3018 int err = 0, value = 0, state;
3020 if (ev->u.set_param.len > PAGE_SIZE)
3023 session = iscsi_session_lookup(ev->u.set_param.sid);
3024 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
3025 if (!conn || !session)
3028 switch (ev->u.set_param.param) {
3029 case ISCSI_PARAM_SESS_RECOVERY_TMO:
3030 sscanf(data, "%d", &value);
3031 if (!session->recovery_tmo_sysfs_override)
3032 session->recovery_tmo = value;
3035 state = READ_ONCE(conn->state);
3036 if (state == ISCSI_CONN_BOUND || state == ISCSI_CONN_UP) {
3037 err = transport->set_param(conn, ev->u.set_param.param,
3038 data, ev->u.set_param.len);
3047 static int iscsi_if_ep_connect(struct iscsi_transport *transport,
3048 struct iscsi_uevent *ev, int msg_type)
3050 struct iscsi_endpoint *ep;
3051 struct sockaddr *dst_addr;
3052 struct Scsi_Host *shost = NULL;
3053 int non_blocking, err = 0;
3055 if (!transport->ep_connect)
3058 if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
3059 shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
3061 printk(KERN_ERR "ep connect failed. Could not find "
3063 ev->u.ep_connect_through_host.host_no);
3066 non_blocking = ev->u.ep_connect_through_host.non_blocking;
3068 non_blocking = ev->u.ep_connect.non_blocking;
3070 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3071 ep = transport->ep_connect(shost, dst_addr, non_blocking);
3077 ev->r.ep_connect_ret.handle = ep->id;
3080 scsi_host_put(shost);
3084 static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
3087 struct iscsi_cls_conn *conn;
3088 struct iscsi_endpoint *ep;
3090 if (!transport->ep_disconnect)
3093 ep = iscsi_lookup_endpoint(ep_handle);
3100 * conn was not even bound yet, so we can't get iscsi conn
3103 transport->ep_disconnect(ep);
3107 mutex_lock(&conn->ep_mutex);
3108 iscsi_if_disconnect_bound_ep(conn, ep, false);
3109 mutex_unlock(&conn->ep_mutex);
3111 iscsi_put_endpoint(ep);
3116 iscsi_if_transport_ep(struct iscsi_transport *transport,
3117 struct iscsi_uevent *ev, int msg_type)
3119 struct iscsi_endpoint *ep;
3123 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3124 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3125 rc = iscsi_if_ep_connect(transport, ev, msg_type);
3127 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3128 if (!transport->ep_poll)
3131 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
3135 ev->r.retcode = transport->ep_poll(ep,
3136 ev->u.ep_poll.timeout_ms);
3137 iscsi_put_endpoint(ep);
3139 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3140 rc = iscsi_if_ep_disconnect(transport,
3141 ev->u.ep_disconnect.ep_handle);
3148 iscsi_tgt_dscvr(struct iscsi_transport *transport,
3149 struct iscsi_uevent *ev)
3151 struct Scsi_Host *shost;
3152 struct sockaddr *dst_addr;
3155 if (!transport->tgt_dscvr)
3158 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
3160 printk(KERN_ERR "target discovery could not find host no %u\n",
3161 ev->u.tgt_dscvr.host_no);
3166 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3167 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
3168 ev->u.tgt_dscvr.enable, dst_addr);
3169 scsi_host_put(shost);
3174 iscsi_set_host_param(struct iscsi_transport *transport,
3175 struct iscsi_uevent *ev)
3177 char *data = (char*)ev + sizeof(*ev);
3178 struct Scsi_Host *shost;
3181 if (!transport->set_host_param)
3184 if (ev->u.set_host_param.len > PAGE_SIZE)
3187 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
3189 printk(KERN_ERR "set_host_param could not find host no %u\n",
3190 ev->u.set_host_param.host_no);
3194 err = transport->set_host_param(shost, ev->u.set_host_param.param,
3195 data, ev->u.set_host_param.len);
3196 scsi_host_put(shost);
3201 iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3203 struct Scsi_Host *shost;
3204 struct iscsi_path *params;
3207 if (!transport->set_path)
3210 shost = scsi_host_lookup(ev->u.set_path.host_no);
3212 printk(KERN_ERR "set path could not find host no %u\n",
3213 ev->u.set_path.host_no);
3217 params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
3218 err = transport->set_path(shost, params);
3220 scsi_host_put(shost);
3224 static int iscsi_session_has_conns(int sid)
3226 struct iscsi_cls_conn *conn;
3227 unsigned long flags;
3230 spin_lock_irqsave(&connlock, flags);
3231 list_for_each_entry(conn, &connlist, conn_list) {
3232 if (iscsi_conn_get_sid(conn) == sid) {
3237 spin_unlock_irqrestore(&connlock, flags);
3243 iscsi_set_iface_params(struct iscsi_transport *transport,
3244 struct iscsi_uevent *ev, uint32_t len)
3246 char *data = (char *)ev + sizeof(*ev);
3247 struct Scsi_Host *shost;
3250 if (!transport->set_iface_param)
3253 shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
3255 printk(KERN_ERR "set_iface_params could not find host no %u\n",
3256 ev->u.set_iface_params.host_no);
3260 err = transport->set_iface_param(shost, data, len);
3261 scsi_host_put(shost);
3266 iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3268 struct Scsi_Host *shost;
3269 struct sockaddr *dst_addr;
3272 if (!transport->send_ping)
3275 shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
3277 printk(KERN_ERR "iscsi_ping could not find host no %u\n",
3278 ev->u.iscsi_ping.host_no);
3282 dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
3283 err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
3284 ev->u.iscsi_ping.iface_type,
3285 ev->u.iscsi_ping.payload_size,
3286 ev->u.iscsi_ping.pid,
3288 scsi_host_put(shost);
3293 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3295 struct iscsi_uevent *ev = nlmsg_data(nlh);
3296 struct Scsi_Host *shost = NULL;
3297 struct iscsi_chap_rec *chap_rec;
3298 struct iscsi_internal *priv;
3299 struct sk_buff *skbchap;
3300 struct nlmsghdr *nlhchap;
3301 struct iscsi_uevent *evchap;
3302 uint32_t chap_buf_size;
3306 if (!transport->get_chap)
3309 priv = iscsi_if_transport_lookup(transport);
3313 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
3314 len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3316 shost = scsi_host_lookup(ev->u.get_chap.host_no);
3318 printk(KERN_ERR "%s: failed. Could not find host no %u\n",
3319 __func__, ev->u.get_chap.host_no);
3326 skbchap = alloc_skb(len, GFP_KERNEL);
3328 printk(KERN_ERR "can not deliver chap: OOM\n");
3333 nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
3334 (len - sizeof(*nlhchap)), 0);
3335 evchap = nlmsg_data(nlhchap);
3336 memset(evchap, 0, sizeof(*evchap));
3337 evchap->transport_handle = iscsi_handle(transport);
3338 evchap->type = nlh->nlmsg_type;
3339 evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
3340 evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
3341 evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
3342 buf = (char *)evchap + sizeof(*evchap);
3343 memset(buf, 0, chap_buf_size);
3345 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
3346 &evchap->u.get_chap.num_entries, buf);
3348 actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3349 skb_trim(skbchap, NLMSG_ALIGN(actual_size));
3350 nlhchap->nlmsg_len = actual_size;
3352 err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
3354 } while (err < 0 && err != -ECONNREFUSED);
3357 scsi_host_put(shost);
3361 static int iscsi_set_chap(struct iscsi_transport *transport,
3362 struct iscsi_uevent *ev, uint32_t len)
3364 char *data = (char *)ev + sizeof(*ev);
3365 struct Scsi_Host *shost;
3368 if (!transport->set_chap)
3371 shost = scsi_host_lookup(ev->u.set_path.host_no);
3373 pr_err("%s could not find host no %u\n",
3374 __func__, ev->u.set_path.host_no);
3378 err = transport->set_chap(shost, data, len);
3379 scsi_host_put(shost);
3383 static int iscsi_delete_chap(struct iscsi_transport *transport,
3384 struct iscsi_uevent *ev)
3386 struct Scsi_Host *shost;
3389 if (!transport->delete_chap)
3392 shost = scsi_host_lookup(ev->u.delete_chap.host_no);
3394 printk(KERN_ERR "%s could not find host no %u\n",
3395 __func__, ev->u.delete_chap.host_no);
3399 err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
3400 scsi_host_put(shost);
3404 static const struct {
3405 enum iscsi_discovery_parent_type value;
3407 } iscsi_discovery_parent_names[] = {
3408 {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
3409 {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
3410 {ISCSI_DISC_PARENT_ISNS, "isns" },
3413 char *iscsi_get_discovery_parent_name(int parent_type)
3416 char *state = "Unknown!";
3418 for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
3419 if (iscsi_discovery_parent_names[i].value & parent_type) {
3420 state = iscsi_discovery_parent_names[i].name;
3426 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
3428 static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
3429 struct iscsi_uevent *ev, uint32_t len)
3431 char *data = (char *)ev + sizeof(*ev);
3432 struct Scsi_Host *shost;
3433 struct iscsi_bus_flash_session *fnode_sess;
3434 struct iscsi_bus_flash_conn *fnode_conn;
3439 if (!transport->set_flashnode_param) {
3441 goto exit_set_fnode;
3444 shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
3446 pr_err("%s could not find host no %u\n",
3447 __func__, ev->u.set_flashnode.host_no);
3449 goto exit_set_fnode;
3452 idx = ev->u.set_flashnode.flashnode_idx;
3453 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3455 pr_err("%s could not find flashnode %u for host no %u\n",
3456 __func__, idx, ev->u.set_flashnode.host_no);
3461 dev = iscsi_find_flashnode_conn(fnode_sess);
3467 fnode_conn = iscsi_dev_to_flash_conn(dev);
3468 err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
3472 put_device(&fnode_sess->dev);
3475 scsi_host_put(shost);
3481 static int iscsi_new_flashnode(struct iscsi_transport *transport,
3482 struct iscsi_uevent *ev, uint32_t len)
3484 char *data = (char *)ev + sizeof(*ev);
3485 struct Scsi_Host *shost;
3489 if (!transport->new_flashnode) {
3491 goto exit_new_fnode;
3494 shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
3496 pr_err("%s could not find host no %u\n",
3497 __func__, ev->u.new_flashnode.host_no);
3502 index = transport->new_flashnode(shost, data, len);
3505 ev->r.new_flashnode_ret.flashnode_idx = index;
3510 scsi_host_put(shost);
3516 static int iscsi_del_flashnode(struct iscsi_transport *transport,
3517 struct iscsi_uevent *ev)
3519 struct Scsi_Host *shost;
3520 struct iscsi_bus_flash_session *fnode_sess;
3524 if (!transport->del_flashnode) {
3526 goto exit_del_fnode;
3529 shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
3531 pr_err("%s could not find host no %u\n",
3532 __func__, ev->u.del_flashnode.host_no);
3537 idx = ev->u.del_flashnode.flashnode_idx;
3538 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3540 pr_err("%s could not find flashnode %u for host no %u\n",
3541 __func__, idx, ev->u.del_flashnode.host_no);
3546 err = transport->del_flashnode(fnode_sess);
3547 put_device(&fnode_sess->dev);
3550 scsi_host_put(shost);
3556 static int iscsi_login_flashnode(struct iscsi_transport *transport,
3557 struct iscsi_uevent *ev)
3559 struct Scsi_Host *shost;
3560 struct iscsi_bus_flash_session *fnode_sess;
3561 struct iscsi_bus_flash_conn *fnode_conn;
3566 if (!transport->login_flashnode) {
3568 goto exit_login_fnode;
3571 shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
3573 pr_err("%s could not find host no %u\n",
3574 __func__, ev->u.login_flashnode.host_no);
3579 idx = ev->u.login_flashnode.flashnode_idx;
3580 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3582 pr_err("%s could not find flashnode %u for host no %u\n",
3583 __func__, idx, ev->u.login_flashnode.host_no);
3588 dev = iscsi_find_flashnode_conn(fnode_sess);
3594 fnode_conn = iscsi_dev_to_flash_conn(dev);
3595 err = transport->login_flashnode(fnode_sess, fnode_conn);
3599 put_device(&fnode_sess->dev);
3602 scsi_host_put(shost);
3608 static int iscsi_logout_flashnode(struct iscsi_transport *transport,
3609 struct iscsi_uevent *ev)
3611 struct Scsi_Host *shost;
3612 struct iscsi_bus_flash_session *fnode_sess;
3613 struct iscsi_bus_flash_conn *fnode_conn;
3618 if (!transport->logout_flashnode) {
3620 goto exit_logout_fnode;
3623 shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
3625 pr_err("%s could not find host no %u\n",
3626 __func__, ev->u.logout_flashnode.host_no);
3631 idx = ev->u.logout_flashnode.flashnode_idx;
3632 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3634 pr_err("%s could not find flashnode %u for host no %u\n",
3635 __func__, idx, ev->u.logout_flashnode.host_no);
3640 dev = iscsi_find_flashnode_conn(fnode_sess);
3646 fnode_conn = iscsi_dev_to_flash_conn(dev);
3648 err = transport->logout_flashnode(fnode_sess, fnode_conn);
3652 put_device(&fnode_sess->dev);
3655 scsi_host_put(shost);
3661 static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
3662 struct iscsi_uevent *ev)
3664 struct Scsi_Host *shost;
3665 struct iscsi_cls_session *session;
3668 if (!transport->logout_flashnode_sid) {
3670 goto exit_logout_sid;
3673 shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
3675 pr_err("%s could not find host no %u\n",
3676 __func__, ev->u.logout_flashnode.host_no);
3681 session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
3683 pr_err("%s could not find session id %u\n",
3684 __func__, ev->u.logout_flashnode_sid.sid);
3689 err = transport->logout_flashnode_sid(session);
3692 scsi_host_put(shost);
3699 iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3701 struct iscsi_uevent *ev = nlmsg_data(nlh);
3702 struct Scsi_Host *shost = NULL;
3703 struct iscsi_internal *priv;
3704 struct sk_buff *skbhost_stats;
3705 struct nlmsghdr *nlhhost_stats;
3706 struct iscsi_uevent *evhost_stats;
3707 int host_stats_size = 0;
3711 if (!transport->get_host_stats)
3714 priv = iscsi_if_transport_lookup(transport);
3718 host_stats_size = sizeof(struct iscsi_offload_host_stats);
3719 len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3721 shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
3723 pr_err("%s: failed. Could not find host no %u\n",
3724 __func__, ev->u.get_host_stats.host_no);
3731 skbhost_stats = alloc_skb(len, GFP_KERNEL);
3732 if (!skbhost_stats) {
3733 pr_err("cannot deliver host stats: OOM\n");
3735 goto exit_host_stats;
3738 nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
3739 (len - sizeof(*nlhhost_stats)), 0);
3740 evhost_stats = nlmsg_data(nlhhost_stats);
3741 memset(evhost_stats, 0, sizeof(*evhost_stats));
3742 evhost_stats->transport_handle = iscsi_handle(transport);
3743 evhost_stats->type = nlh->nlmsg_type;
3744 evhost_stats->u.get_host_stats.host_no =
3745 ev->u.get_host_stats.host_no;
3746 buf = (char *)evhost_stats + sizeof(*evhost_stats);
3747 memset(buf, 0, host_stats_size);
3749 err = transport->get_host_stats(shost, buf, host_stats_size);
3751 kfree_skb(skbhost_stats);
3752 goto exit_host_stats;
3755 actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3756 skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
3757 nlhhost_stats->nlmsg_len = actual_size;
3759 err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
3761 } while (err < 0 && err != -ECONNREFUSED);
3764 scsi_host_put(shost);
3768 static int iscsi_if_transport_conn(struct iscsi_transport *transport,
3769 struct nlmsghdr *nlh)
3771 struct iscsi_uevent *ev = nlmsg_data(nlh);
3772 struct iscsi_cls_session *session;
3773 struct iscsi_cls_conn *conn = NULL;
3774 struct iscsi_endpoint *ep;
3778 switch (nlh->nlmsg_type) {
3779 case ISCSI_UEVENT_CREATE_CONN:
3780 return iscsi_if_create_conn(transport, ev);
3781 case ISCSI_UEVENT_DESTROY_CONN:
3782 return iscsi_if_destroy_conn(transport, ev);
3783 case ISCSI_UEVENT_STOP_CONN:
3784 conn = iscsi_conn_lookup(ev->u.stop_conn.sid,
3785 ev->u.stop_conn.cid);
3789 return iscsi_if_stop_conn(conn, ev->u.stop_conn.flag);
3793 * The following cmds need to be run under the ep_mutex so in kernel
3794 * conn cleanup (ep_disconnect + unbind and conn) is not done while
3795 * these are running. They also must not run if we have just run a conn
3796 * cleanup because they would set the state in a way that might allow
3797 * IO or send IO themselves.
3799 switch (nlh->nlmsg_type) {
3800 case ISCSI_UEVENT_START_CONN:
3801 conn = iscsi_conn_lookup(ev->u.start_conn.sid,
3802 ev->u.start_conn.cid);
3804 case ISCSI_UEVENT_BIND_CONN:
3805 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
3807 case ISCSI_UEVENT_SEND_PDU:
3808 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
3815 mutex_lock(&conn->ep_mutex);
3816 spin_lock_irq(&conn->lock);
3817 if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
3818 spin_unlock_irq(&conn->lock);
3819 mutex_unlock(&conn->ep_mutex);
3820 ev->r.retcode = -ENOTCONN;
3823 spin_unlock_irq(&conn->lock);
3825 switch (nlh->nlmsg_type) {
3826 case ISCSI_UEVENT_BIND_CONN:
3827 session = iscsi_session_lookup(ev->u.b_conn.sid);
3833 ev->r.retcode = transport->bind_conn(session, conn,
3834 ev->u.b_conn.transport_eph,
3835 ev->u.b_conn.is_leading);
3837 WRITE_ONCE(conn->state, ISCSI_CONN_BOUND);
3839 if (ev->r.retcode || !transport->ep_connect)
3842 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
3846 iscsi_put_endpoint(ep);
3849 iscsi_cls_conn_printk(KERN_ERR, conn,
3850 "Could not set ep conn binding\n");
3853 case ISCSI_UEVENT_START_CONN:
3854 ev->r.retcode = transport->start_conn(conn);
3856 WRITE_ONCE(conn->state, ISCSI_CONN_UP);
3859 case ISCSI_UEVENT_SEND_PDU:
3860 pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
3862 if ((ev->u.send_pdu.hdr_size > pdu_len) ||
3863 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
3868 ev->r.retcode = transport->send_pdu(conn,
3869 (struct iscsi_hdr *)((char *)ev + sizeof(*ev)),
3870 (char *)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
3871 ev->u.send_pdu.data_size);
3877 mutex_unlock(&conn->ep_mutex);
3882 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
3886 struct iscsi_uevent *ev = nlmsg_data(nlh);
3887 struct iscsi_transport *transport = NULL;
3888 struct iscsi_internal *priv;
3889 struct iscsi_cls_session *session;
3890 struct iscsi_endpoint *ep = NULL;
3892 if (!netlink_capable(skb, CAP_SYS_ADMIN))
3895 if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
3896 *group = ISCSI_NL_GRP_UIP;
3898 *group = ISCSI_NL_GRP_ISCSID;
3900 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
3903 transport = priv->iscsi_transport;
3905 if (!try_module_get(transport->owner))
3908 portid = NETLINK_CB(skb).portid;
3910 switch (nlh->nlmsg_type) {
3911 case ISCSI_UEVENT_CREATE_SESSION:
3912 err = iscsi_if_create_session(priv, ep, ev,
3914 ev->u.c_session.initial_cmdsn,
3915 ev->u.c_session.cmds_max,
3916 ev->u.c_session.queue_depth);
3918 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
3919 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
3925 err = iscsi_if_create_session(priv, ep, ev,
3927 ev->u.c_bound_session.initial_cmdsn,
3928 ev->u.c_bound_session.cmds_max,
3929 ev->u.c_bound_session.queue_depth);
3930 iscsi_put_endpoint(ep);
3932 case ISCSI_UEVENT_DESTROY_SESSION:
3933 session = iscsi_session_lookup(ev->u.d_session.sid);
3936 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3939 transport->destroy_session(session);
3941 case ISCSI_UEVENT_DESTROY_SESSION_ASYNC:
3942 session = iscsi_session_lookup(ev->u.d_session.sid);
3945 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3948 unsigned long flags;
3950 /* Prevent this session from being found again */
3951 spin_lock_irqsave(&sesslock, flags);
3952 list_del_init(&session->sess_list);
3953 spin_unlock_irqrestore(&sesslock, flags);
3955 queue_work(system_unbound_wq, &session->destroy_work);
3958 case ISCSI_UEVENT_UNBIND_SESSION:
3959 session = iscsi_session_lookup(ev->u.d_session.sid);
3961 scsi_queue_work(iscsi_session_to_shost(session),
3962 &session->unbind_work);
3966 case ISCSI_UEVENT_SET_PARAM:
3967 err = iscsi_set_param(transport, ev);
3969 case ISCSI_UEVENT_CREATE_CONN:
3970 case ISCSI_UEVENT_DESTROY_CONN:
3971 case ISCSI_UEVENT_STOP_CONN:
3972 case ISCSI_UEVENT_START_CONN:
3973 case ISCSI_UEVENT_BIND_CONN:
3974 case ISCSI_UEVENT_SEND_PDU:
3975 err = iscsi_if_transport_conn(transport, nlh);
3977 case ISCSI_UEVENT_GET_STATS:
3978 err = iscsi_if_get_stats(transport, nlh);
3980 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3981 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3982 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3983 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3984 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
3986 case ISCSI_UEVENT_TGT_DSCVR:
3987 err = iscsi_tgt_dscvr(transport, ev);
3989 case ISCSI_UEVENT_SET_HOST_PARAM:
3990 err = iscsi_set_host_param(transport, ev);
3992 case ISCSI_UEVENT_PATH_UPDATE:
3993 err = iscsi_set_path(transport, ev);
3995 case ISCSI_UEVENT_SET_IFACE_PARAMS:
3996 err = iscsi_set_iface_params(transport, ev,
3997 nlmsg_attrlen(nlh, sizeof(*ev)));
3999 case ISCSI_UEVENT_PING:
4000 err = iscsi_send_ping(transport, ev);
4002 case ISCSI_UEVENT_GET_CHAP:
4003 err = iscsi_get_chap(transport, nlh);
4005 case ISCSI_UEVENT_DELETE_CHAP:
4006 err = iscsi_delete_chap(transport, ev);
4008 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
4009 err = iscsi_set_flashnode_param(transport, ev,
4013 case ISCSI_UEVENT_NEW_FLASHNODE:
4014 err = iscsi_new_flashnode(transport, ev,
4015 nlmsg_attrlen(nlh, sizeof(*ev)));
4017 case ISCSI_UEVENT_DEL_FLASHNODE:
4018 err = iscsi_del_flashnode(transport, ev);
4020 case ISCSI_UEVENT_LOGIN_FLASHNODE:
4021 err = iscsi_login_flashnode(transport, ev);
4023 case ISCSI_UEVENT_LOGOUT_FLASHNODE:
4024 err = iscsi_logout_flashnode(transport, ev);
4026 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
4027 err = iscsi_logout_flashnode_sid(transport, ev);
4029 case ISCSI_UEVENT_SET_CHAP:
4030 err = iscsi_set_chap(transport, ev,
4031 nlmsg_attrlen(nlh, sizeof(*ev)));
4033 case ISCSI_UEVENT_GET_HOST_STATS:
4034 err = iscsi_get_host_stats(transport, nlh);
4041 module_put(transport->owner);
4046 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
4047 * Malformed skbs with wrong lengths or invalid creds are not processed.
4050 iscsi_if_rx(struct sk_buff *skb)
4052 u32 portid = NETLINK_CB(skb).portid;
4054 mutex_lock(&rx_queue_mutex);
4055 while (skb->len >= NLMSG_HDRLEN) {
4058 struct nlmsghdr *nlh;
4059 struct iscsi_uevent *ev;
4061 int retries = ISCSI_SEND_MAX_ALLOWED;
4063 nlh = nlmsg_hdr(skb);
4064 if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
4065 skb->len < nlh->nlmsg_len) {
4069 ev = nlmsg_data(nlh);
4070 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
4071 if (rlen > skb->len)
4074 err = iscsi_if_recv_msg(skb, nlh, &group);
4076 ev->type = ISCSI_KEVENT_IF_ERROR;
4081 * special case for GET_STATS:
4082 * on success - sending reply and stats from
4083 * inside of if_recv_msg(),
4084 * on error - fall through.
4086 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
4088 if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
4090 err = iscsi_if_send_reply(portid, nlh->nlmsg_type,
4092 if (err == -EAGAIN && --retries < 0) {
4093 printk(KERN_WARNING "Send reply failed, error %d\n", err);
4096 } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
4097 skb_pull(skb, rlen);
4099 mutex_unlock(&rx_queue_mutex);
4102 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
4103 struct device_attribute dev_attr_##_prefix##_##_name = \
4104 __ATTR(_name,_mode,_show,_store)
4107 * iSCSI connection attrs
4109 #define iscsi_conn_attr_show(param) \
4111 show_conn_param_##param(struct device *dev, \
4112 struct device_attribute *attr, char *buf) \
4114 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4115 struct iscsi_transport *t = conn->transport; \
4116 return t->get_conn_param(conn, param, buf); \
4119 #define iscsi_conn_attr(field, param) \
4120 iscsi_conn_attr_show(param) \
4121 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
4124 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
4125 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
4126 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
4127 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
4128 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
4129 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
4130 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
4131 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
4132 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
4133 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
4134 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
4135 iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
4136 iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
4137 iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
4138 iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
4139 iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
4140 iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
4141 iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
4142 iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
4143 iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
4144 iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
4145 iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
4146 iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
4147 iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
4148 iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
4149 iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
4150 iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
4151 iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
4153 static const char *const connection_state_names[] = {
4154 [ISCSI_CONN_UP] = "up",
4155 [ISCSI_CONN_DOWN] = "down",
4156 [ISCSI_CONN_FAILED] = "failed",
4157 [ISCSI_CONN_BOUND] = "bound"
4160 static ssize_t show_conn_state(struct device *dev,
4161 struct device_attribute *attr, char *buf)
4163 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent);
4164 const char *state = "unknown";
4165 int conn_state = READ_ONCE(conn->state);
4167 if (conn_state >= 0 &&
4168 conn_state < ARRAY_SIZE(connection_state_names))
4169 state = connection_state_names[conn_state];
4171 return sysfs_emit(buf, "%s\n", state);
4173 static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
4176 #define iscsi_conn_ep_attr_show(param) \
4177 static ssize_t show_conn_ep_param_##param(struct device *dev, \
4178 struct device_attribute *attr,\
4181 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4182 struct iscsi_transport *t = conn->transport; \
4183 struct iscsi_endpoint *ep; \
4187 * Need to make sure ep_disconnect does not free the LLD's \
4188 * interconnect resources while we are trying to read them. \
4190 mutex_lock(&conn->ep_mutex); \
4192 if (!ep && t->ep_connect) { \
4193 mutex_unlock(&conn->ep_mutex); \
4198 rc = t->get_ep_param(ep, param, buf); \
4200 rc = t->get_conn_param(conn, param, buf); \
4201 mutex_unlock(&conn->ep_mutex); \
4205 #define iscsi_conn_ep_attr(field, param) \
4206 iscsi_conn_ep_attr_show(param) \
4207 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
4208 show_conn_ep_param_##param, NULL);
4210 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
4211 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
4213 static struct attribute *iscsi_conn_attrs[] = {
4214 &dev_attr_conn_max_recv_dlength.attr,
4215 &dev_attr_conn_max_xmit_dlength.attr,
4216 &dev_attr_conn_header_digest.attr,
4217 &dev_attr_conn_data_digest.attr,
4218 &dev_attr_conn_ifmarker.attr,
4219 &dev_attr_conn_ofmarker.attr,
4220 &dev_attr_conn_address.attr,
4221 &dev_attr_conn_port.attr,
4222 &dev_attr_conn_exp_statsn.attr,
4223 &dev_attr_conn_persistent_address.attr,
4224 &dev_attr_conn_persistent_port.attr,
4225 &dev_attr_conn_ping_tmo.attr,
4226 &dev_attr_conn_recv_tmo.attr,
4227 &dev_attr_conn_local_port.attr,
4228 &dev_attr_conn_statsn.attr,
4229 &dev_attr_conn_keepalive_tmo.attr,
4230 &dev_attr_conn_max_segment_size.attr,
4231 &dev_attr_conn_tcp_timestamp_stat.attr,
4232 &dev_attr_conn_tcp_wsf_disable.attr,
4233 &dev_attr_conn_tcp_nagle_disable.attr,
4234 &dev_attr_conn_tcp_timer_scale.attr,
4235 &dev_attr_conn_tcp_timestamp_enable.attr,
4236 &dev_attr_conn_fragment_disable.attr,
4237 &dev_attr_conn_ipv4_tos.attr,
4238 &dev_attr_conn_ipv6_traffic_class.attr,
4239 &dev_attr_conn_ipv6_flow_label.attr,
4240 &dev_attr_conn_is_fw_assigned_ipv6.attr,
4241 &dev_attr_conn_tcp_xmit_wsf.attr,
4242 &dev_attr_conn_tcp_recv_wsf.attr,
4243 &dev_attr_conn_local_ipaddr.attr,
4244 &dev_attr_conn_state.attr,
4248 static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
4249 struct attribute *attr, int i)
4251 struct device *cdev = container_of(kobj, struct device, kobj);
4252 struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
4253 struct iscsi_transport *t = conn->transport;
4256 if (attr == &dev_attr_conn_max_recv_dlength.attr)
4257 param = ISCSI_PARAM_MAX_RECV_DLENGTH;
4258 else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
4259 param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
4260 else if (attr == &dev_attr_conn_header_digest.attr)
4261 param = ISCSI_PARAM_HDRDGST_EN;
4262 else if (attr == &dev_attr_conn_data_digest.attr)
4263 param = ISCSI_PARAM_DATADGST_EN;
4264 else if (attr == &dev_attr_conn_ifmarker.attr)
4265 param = ISCSI_PARAM_IFMARKER_EN;
4266 else if (attr == &dev_attr_conn_ofmarker.attr)
4267 param = ISCSI_PARAM_OFMARKER_EN;
4268 else if (attr == &dev_attr_conn_address.attr)
4269 param = ISCSI_PARAM_CONN_ADDRESS;
4270 else if (attr == &dev_attr_conn_port.attr)
4271 param = ISCSI_PARAM_CONN_PORT;
4272 else if (attr == &dev_attr_conn_exp_statsn.attr)
4273 param = ISCSI_PARAM_EXP_STATSN;
4274 else if (attr == &dev_attr_conn_persistent_address.attr)
4275 param = ISCSI_PARAM_PERSISTENT_ADDRESS;
4276 else if (attr == &dev_attr_conn_persistent_port.attr)
4277 param = ISCSI_PARAM_PERSISTENT_PORT;
4278 else if (attr == &dev_attr_conn_ping_tmo.attr)
4279 param = ISCSI_PARAM_PING_TMO;
4280 else if (attr == &dev_attr_conn_recv_tmo.attr)
4281 param = ISCSI_PARAM_RECV_TMO;
4282 else if (attr == &dev_attr_conn_local_port.attr)
4283 param = ISCSI_PARAM_LOCAL_PORT;
4284 else if (attr == &dev_attr_conn_statsn.attr)
4285 param = ISCSI_PARAM_STATSN;
4286 else if (attr == &dev_attr_conn_keepalive_tmo.attr)
4287 param = ISCSI_PARAM_KEEPALIVE_TMO;
4288 else if (attr == &dev_attr_conn_max_segment_size.attr)
4289 param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
4290 else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
4291 param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
4292 else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
4293 param = ISCSI_PARAM_TCP_WSF_DISABLE;
4294 else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
4295 param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
4296 else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
4297 param = ISCSI_PARAM_TCP_TIMER_SCALE;
4298 else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
4299 param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
4300 else if (attr == &dev_attr_conn_fragment_disable.attr)
4301 param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
4302 else if (attr == &dev_attr_conn_ipv4_tos.attr)
4303 param = ISCSI_PARAM_IPV4_TOS;
4304 else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
4305 param = ISCSI_PARAM_IPV6_TC;
4306 else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
4307 param = ISCSI_PARAM_IPV6_FLOW_LABEL;
4308 else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
4309 param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
4310 else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
4311 param = ISCSI_PARAM_TCP_XMIT_WSF;
4312 else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
4313 param = ISCSI_PARAM_TCP_RECV_WSF;
4314 else if (attr == &dev_attr_conn_local_ipaddr.attr)
4315 param = ISCSI_PARAM_LOCAL_IPADDR;
4316 else if (attr == &dev_attr_conn_state.attr)
4319 WARN_ONCE(1, "Invalid conn attr");
4323 return t->attr_is_visible(ISCSI_PARAM, param);
4326 static struct attribute_group iscsi_conn_group = {
4327 .attrs = iscsi_conn_attrs,
4328 .is_visible = iscsi_conn_attr_is_visible,
4332 * iSCSI session attrs
4334 #define iscsi_session_attr_show(param, perm) \
4336 show_session_param_##param(struct device *dev, \
4337 struct device_attribute *attr, char *buf) \
4339 struct iscsi_cls_session *session = \
4340 iscsi_dev_to_session(dev->parent); \
4341 struct iscsi_transport *t = session->transport; \
4343 if (perm && !capable(CAP_SYS_ADMIN)) \
4345 return t->get_session_param(session, param, buf); \
4348 #define iscsi_session_attr(field, param, perm) \
4349 iscsi_session_attr_show(param, perm) \
4350 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
4352 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
4353 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
4354 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
4355 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
4356 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
4357 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
4358 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
4359 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
4360 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
4361 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
4362 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
4363 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
4364 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
4365 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
4366 iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
4367 iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
4368 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
4369 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
4370 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
4371 iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
4372 iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
4373 iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
4374 iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
4375 iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
4376 iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
4377 iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
4378 iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
4379 iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
4380 iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
4381 iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
4382 iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
4383 iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
4384 iscsi_session_attr(discovery_auth_optional,
4385 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
4386 iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
4387 iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
4388 iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
4389 iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
4390 iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
4391 iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
4392 iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
4395 show_priv_session_state(struct device *dev, struct device_attribute *attr,
4398 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4399 return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
4401 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
4404 show_priv_session_creator(struct device *dev, struct device_attribute *attr,
4407 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4408 return sysfs_emit(buf, "%d\n", session->creator);
4410 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
4413 show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
4416 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4417 return sysfs_emit(buf, "%d\n", session->target_id);
4419 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
4420 show_priv_session_target_id, NULL);
4422 #define iscsi_priv_session_attr_show(field, format) \
4424 show_priv_session_##field(struct device *dev, \
4425 struct device_attribute *attr, char *buf) \
4427 struct iscsi_cls_session *session = \
4428 iscsi_dev_to_session(dev->parent); \
4429 if (session->field == -1) \
4430 return sysfs_emit(buf, "off\n"); \
4431 return sysfs_emit(buf, format"\n", session->field); \
4434 #define iscsi_priv_session_attr_store(field) \
4436 store_priv_session_##field(struct device *dev, \
4437 struct device_attribute *attr, \
4438 const char *buf, size_t count) \
4442 struct iscsi_cls_session *session = \
4443 iscsi_dev_to_session(dev->parent); \
4444 if ((session->state == ISCSI_SESSION_FREE) || \
4445 (session->state == ISCSI_SESSION_FAILED)) \
4447 if (strncmp(buf, "off", 3) == 0) { \
4448 session->field = -1; \
4449 session->field##_sysfs_override = true; \
4451 val = simple_strtoul(buf, &cp, 0); \
4452 if (*cp != '\0' && *cp != '\n') \
4454 session->field = val; \
4455 session->field##_sysfs_override = true; \
4460 #define iscsi_priv_session_rw_attr(field, format) \
4461 iscsi_priv_session_attr_show(field, format) \
4462 iscsi_priv_session_attr_store(field) \
4463 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
4464 show_priv_session_##field, \
4465 store_priv_session_##field)
4467 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
4469 static struct attribute *iscsi_session_attrs[] = {
4470 &dev_attr_sess_initial_r2t.attr,
4471 &dev_attr_sess_max_outstanding_r2t.attr,
4472 &dev_attr_sess_immediate_data.attr,
4473 &dev_attr_sess_first_burst_len.attr,
4474 &dev_attr_sess_max_burst_len.attr,
4475 &dev_attr_sess_data_pdu_in_order.attr,
4476 &dev_attr_sess_data_seq_in_order.attr,
4477 &dev_attr_sess_erl.attr,
4478 &dev_attr_sess_targetname.attr,
4479 &dev_attr_sess_tpgt.attr,
4480 &dev_attr_sess_password.attr,
4481 &dev_attr_sess_password_in.attr,
4482 &dev_attr_sess_username.attr,
4483 &dev_attr_sess_username_in.attr,
4484 &dev_attr_sess_fast_abort.attr,
4485 &dev_attr_sess_abort_tmo.attr,
4486 &dev_attr_sess_lu_reset_tmo.attr,
4487 &dev_attr_sess_tgt_reset_tmo.attr,
4488 &dev_attr_sess_ifacename.attr,
4489 &dev_attr_sess_initiatorname.attr,
4490 &dev_attr_sess_targetalias.attr,
4491 &dev_attr_sess_boot_root.attr,
4492 &dev_attr_sess_boot_nic.attr,
4493 &dev_attr_sess_boot_target.attr,
4494 &dev_attr_priv_sess_recovery_tmo.attr,
4495 &dev_attr_priv_sess_state.attr,
4496 &dev_attr_priv_sess_creator.attr,
4497 &dev_attr_sess_chap_out_idx.attr,
4498 &dev_attr_sess_chap_in_idx.attr,
4499 &dev_attr_priv_sess_target_id.attr,
4500 &dev_attr_sess_auto_snd_tgt_disable.attr,
4501 &dev_attr_sess_discovery_session.attr,
4502 &dev_attr_sess_portal_type.attr,
4503 &dev_attr_sess_chap_auth.attr,
4504 &dev_attr_sess_discovery_logout.attr,
4505 &dev_attr_sess_bidi_chap.attr,
4506 &dev_attr_sess_discovery_auth_optional.attr,
4507 &dev_attr_sess_def_time2wait.attr,
4508 &dev_attr_sess_def_time2retain.attr,
4509 &dev_attr_sess_isid.attr,
4510 &dev_attr_sess_tsid.attr,
4511 &dev_attr_sess_def_taskmgmt_tmo.attr,
4512 &dev_attr_sess_discovery_parent_idx.attr,
4513 &dev_attr_sess_discovery_parent_type.attr,
4517 static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
4518 struct attribute *attr, int i)
4520 struct device *cdev = container_of(kobj, struct device, kobj);
4521 struct iscsi_cls_session *session = transport_class_to_session(cdev);
4522 struct iscsi_transport *t = session->transport;
4525 if (attr == &dev_attr_sess_initial_r2t.attr)
4526 param = ISCSI_PARAM_INITIAL_R2T_EN;
4527 else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
4528 param = ISCSI_PARAM_MAX_R2T;
4529 else if (attr == &dev_attr_sess_immediate_data.attr)
4530 param = ISCSI_PARAM_IMM_DATA_EN;
4531 else if (attr == &dev_attr_sess_first_burst_len.attr)
4532 param = ISCSI_PARAM_FIRST_BURST;
4533 else if (attr == &dev_attr_sess_max_burst_len.attr)
4534 param = ISCSI_PARAM_MAX_BURST;
4535 else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
4536 param = ISCSI_PARAM_PDU_INORDER_EN;
4537 else if (attr == &dev_attr_sess_data_seq_in_order.attr)
4538 param = ISCSI_PARAM_DATASEQ_INORDER_EN;
4539 else if (attr == &dev_attr_sess_erl.attr)
4540 param = ISCSI_PARAM_ERL;
4541 else if (attr == &dev_attr_sess_targetname.attr)
4542 param = ISCSI_PARAM_TARGET_NAME;
4543 else if (attr == &dev_attr_sess_tpgt.attr)
4544 param = ISCSI_PARAM_TPGT;
4545 else if (attr == &dev_attr_sess_chap_in_idx.attr)
4546 param = ISCSI_PARAM_CHAP_IN_IDX;
4547 else if (attr == &dev_attr_sess_chap_out_idx.attr)
4548 param = ISCSI_PARAM_CHAP_OUT_IDX;
4549 else if (attr == &dev_attr_sess_password.attr)
4550 param = ISCSI_PARAM_USERNAME;
4551 else if (attr == &dev_attr_sess_password_in.attr)
4552 param = ISCSI_PARAM_USERNAME_IN;
4553 else if (attr == &dev_attr_sess_username.attr)
4554 param = ISCSI_PARAM_PASSWORD;
4555 else if (attr == &dev_attr_sess_username_in.attr)
4556 param = ISCSI_PARAM_PASSWORD_IN;
4557 else if (attr == &dev_attr_sess_fast_abort.attr)
4558 param = ISCSI_PARAM_FAST_ABORT;
4559 else if (attr == &dev_attr_sess_abort_tmo.attr)
4560 param = ISCSI_PARAM_ABORT_TMO;
4561 else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
4562 param = ISCSI_PARAM_LU_RESET_TMO;
4563 else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
4564 param = ISCSI_PARAM_TGT_RESET_TMO;
4565 else if (attr == &dev_attr_sess_ifacename.attr)
4566 param = ISCSI_PARAM_IFACE_NAME;
4567 else if (attr == &dev_attr_sess_initiatorname.attr)
4568 param = ISCSI_PARAM_INITIATOR_NAME;
4569 else if (attr == &dev_attr_sess_targetalias.attr)
4570 param = ISCSI_PARAM_TARGET_ALIAS;
4571 else if (attr == &dev_attr_sess_boot_root.attr)
4572 param = ISCSI_PARAM_BOOT_ROOT;
4573 else if (attr == &dev_attr_sess_boot_nic.attr)
4574 param = ISCSI_PARAM_BOOT_NIC;
4575 else if (attr == &dev_attr_sess_boot_target.attr)
4576 param = ISCSI_PARAM_BOOT_TARGET;
4577 else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
4578 param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
4579 else if (attr == &dev_attr_sess_discovery_session.attr)
4580 param = ISCSI_PARAM_DISCOVERY_SESS;
4581 else if (attr == &dev_attr_sess_portal_type.attr)
4582 param = ISCSI_PARAM_PORTAL_TYPE;
4583 else if (attr == &dev_attr_sess_chap_auth.attr)
4584 param = ISCSI_PARAM_CHAP_AUTH_EN;
4585 else if (attr == &dev_attr_sess_discovery_logout.attr)
4586 param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
4587 else if (attr == &dev_attr_sess_bidi_chap.attr)
4588 param = ISCSI_PARAM_BIDI_CHAP_EN;
4589 else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
4590 param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
4591 else if (attr == &dev_attr_sess_def_time2wait.attr)
4592 param = ISCSI_PARAM_DEF_TIME2WAIT;
4593 else if (attr == &dev_attr_sess_def_time2retain.attr)
4594 param = ISCSI_PARAM_DEF_TIME2RETAIN;
4595 else if (attr == &dev_attr_sess_isid.attr)
4596 param = ISCSI_PARAM_ISID;
4597 else if (attr == &dev_attr_sess_tsid.attr)
4598 param = ISCSI_PARAM_TSID;
4599 else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
4600 param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
4601 else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
4602 param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
4603 else if (attr == &dev_attr_sess_discovery_parent_type.attr)
4604 param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
4605 else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
4606 return S_IRUGO | S_IWUSR;
4607 else if (attr == &dev_attr_priv_sess_state.attr)
4609 else if (attr == &dev_attr_priv_sess_creator.attr)
4611 else if (attr == &dev_attr_priv_sess_target_id.attr)
4614 WARN_ONCE(1, "Invalid session attr");
4618 return t->attr_is_visible(ISCSI_PARAM, param);
4621 static struct attribute_group iscsi_session_group = {
4622 .attrs = iscsi_session_attrs,
4623 .is_visible = iscsi_session_attr_is_visible,
4629 #define iscsi_host_attr_show(param) \
4631 show_host_param_##param(struct device *dev, \
4632 struct device_attribute *attr, char *buf) \
4634 struct Scsi_Host *shost = transport_class_to_shost(dev); \
4635 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
4636 return priv->iscsi_transport->get_host_param(shost, param, buf); \
4639 #define iscsi_host_attr(field, param) \
4640 iscsi_host_attr_show(param) \
4641 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
4644 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
4645 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
4646 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
4647 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
4648 iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
4649 iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
4651 static struct attribute *iscsi_host_attrs[] = {
4652 &dev_attr_host_netdev.attr,
4653 &dev_attr_host_hwaddress.attr,
4654 &dev_attr_host_ipaddress.attr,
4655 &dev_attr_host_initiatorname.attr,
4656 &dev_attr_host_port_state.attr,
4657 &dev_attr_host_port_speed.attr,
4661 static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
4662 struct attribute *attr, int i)
4664 struct device *cdev = container_of(kobj, struct device, kobj);
4665 struct Scsi_Host *shost = transport_class_to_shost(cdev);
4666 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
4669 if (attr == &dev_attr_host_netdev.attr)
4670 param = ISCSI_HOST_PARAM_NETDEV_NAME;
4671 else if (attr == &dev_attr_host_hwaddress.attr)
4672 param = ISCSI_HOST_PARAM_HWADDRESS;
4673 else if (attr == &dev_attr_host_ipaddress.attr)
4674 param = ISCSI_HOST_PARAM_IPADDRESS;
4675 else if (attr == &dev_attr_host_initiatorname.attr)
4676 param = ISCSI_HOST_PARAM_INITIATOR_NAME;
4677 else if (attr == &dev_attr_host_port_state.attr)
4678 param = ISCSI_HOST_PARAM_PORT_STATE;
4679 else if (attr == &dev_attr_host_port_speed.attr)
4680 param = ISCSI_HOST_PARAM_PORT_SPEED;
4682 WARN_ONCE(1, "Invalid host attr");
4686 return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
4689 static struct attribute_group iscsi_host_group = {
4690 .attrs = iscsi_host_attrs,
4691 .is_visible = iscsi_host_attr_is_visible,
4694 /* convert iscsi_port_speed values to ascii string name */
4695 static const struct {
4696 enum iscsi_port_speed value;
4698 } iscsi_port_speed_names[] = {
4699 {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
4700 {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
4701 {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
4702 {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
4703 {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
4704 {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" },
4705 {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" },
4708 char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
4711 char *speed = "Unknown!";
4712 struct iscsi_cls_host *ihost = shost->shost_data;
4713 uint32_t port_speed = ihost->port_speed;
4715 for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
4716 if (iscsi_port_speed_names[i].value & port_speed) {
4717 speed = iscsi_port_speed_names[i].name;
4723 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
4725 /* convert iscsi_port_state values to ascii string name */
4726 static const struct {
4727 enum iscsi_port_state value;
4729 } iscsi_port_state_names[] = {
4730 {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
4731 {ISCSI_PORT_STATE_UP, "LINK UP" },
4734 char *iscsi_get_port_state_name(struct Scsi_Host *shost)
4737 char *state = "Unknown!";
4738 struct iscsi_cls_host *ihost = shost->shost_data;
4739 uint32_t port_state = ihost->port_state;
4741 for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
4742 if (iscsi_port_state_names[i].value & port_state) {
4743 state = iscsi_port_state_names[i].name;
4749 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
4751 static int iscsi_session_match(struct attribute_container *cont,
4754 struct iscsi_cls_session *session;
4755 struct Scsi_Host *shost;
4756 struct iscsi_internal *priv;
4758 if (!iscsi_is_session_dev(dev))
4761 session = iscsi_dev_to_session(dev);
4762 shost = iscsi_session_to_shost(session);
4763 if (!shost->transportt)
4766 priv = to_iscsi_internal(shost->transportt);
4767 if (priv->session_cont.ac.class != &iscsi_session_class.class)
4770 return &priv->session_cont.ac == cont;
4773 static int iscsi_conn_match(struct attribute_container *cont,
4776 struct iscsi_cls_session *session;
4777 struct iscsi_cls_conn *conn;
4778 struct Scsi_Host *shost;
4779 struct iscsi_internal *priv;
4781 if (!iscsi_is_conn_dev(dev))
4784 conn = iscsi_dev_to_conn(dev);
4785 session = iscsi_dev_to_session(conn->dev.parent);
4786 shost = iscsi_session_to_shost(session);
4788 if (!shost->transportt)
4791 priv = to_iscsi_internal(shost->transportt);
4792 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
4795 return &priv->conn_cont.ac == cont;
4798 static int iscsi_host_match(struct attribute_container *cont,
4801 struct Scsi_Host *shost;
4802 struct iscsi_internal *priv;
4804 if (!scsi_is_host_device(dev))
4807 shost = dev_to_shost(dev);
4808 if (!shost->transportt ||
4809 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
4812 priv = to_iscsi_internal(shost->transportt);
4813 return &priv->t.host_attrs.ac == cont;
4816 struct scsi_transport_template *
4817 iscsi_register_transport(struct iscsi_transport *tt)
4819 struct iscsi_internal *priv;
4820 unsigned long flags;
4824 WARN_ON(tt->ep_disconnect && !tt->unbind_conn);
4826 priv = iscsi_if_transport_lookup(tt);
4830 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
4833 INIT_LIST_HEAD(&priv->list);
4834 priv->iscsi_transport = tt;
4835 priv->t.user_scan = iscsi_user_scan;
4836 priv->t.create_work_queue = 1;
4838 priv->dev.class = &iscsi_transport_class;
4839 dev_set_name(&priv->dev, "%s", tt->name);
4840 err = device_register(&priv->dev);
4844 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
4846 goto unregister_dev;
4848 /* host parameters */
4849 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
4850 priv->t.host_attrs.ac.match = iscsi_host_match;
4851 priv->t.host_attrs.ac.grp = &iscsi_host_group;
4852 priv->t.host_size = sizeof(struct iscsi_cls_host);
4853 transport_container_register(&priv->t.host_attrs);
4855 /* connection parameters */
4856 priv->conn_cont.ac.class = &iscsi_connection_class.class;
4857 priv->conn_cont.ac.match = iscsi_conn_match;
4858 priv->conn_cont.ac.grp = &iscsi_conn_group;
4859 transport_container_register(&priv->conn_cont);
4861 /* session parameters */
4862 priv->session_cont.ac.class = &iscsi_session_class.class;
4863 priv->session_cont.ac.match = iscsi_session_match;
4864 priv->session_cont.ac.grp = &iscsi_session_group;
4865 transport_container_register(&priv->session_cont);
4867 spin_lock_irqsave(&iscsi_transport_lock, flags);
4868 list_add(&priv->list, &iscsi_transports);
4869 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4871 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
4875 device_unregister(&priv->dev);
4878 put_device(&priv->dev);
4881 EXPORT_SYMBOL_GPL(iscsi_register_transport);
4883 int iscsi_unregister_transport(struct iscsi_transport *tt)
4885 struct iscsi_internal *priv;
4886 unsigned long flags;
4890 mutex_lock(&rx_queue_mutex);
4892 priv = iscsi_if_transport_lookup(tt);
4895 spin_lock_irqsave(&iscsi_transport_lock, flags);
4896 list_del(&priv->list);
4897 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4899 transport_container_unregister(&priv->conn_cont);
4900 transport_container_unregister(&priv->session_cont);
4901 transport_container_unregister(&priv->t.host_attrs);
4903 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
4904 device_unregister(&priv->dev);
4905 mutex_unlock(&rx_queue_mutex);
4909 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
4911 void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *),
4912 struct device *dev, const char *fmt, ...)
4914 struct va_format vaf;
4917 va_start(args, fmt);
4923 EXPORT_SYMBOL_GPL(iscsi_dbg_trace);
4925 static __init int iscsi_transport_init(void)
4928 struct netlink_kernel_cfg cfg = {
4930 .input = iscsi_if_rx,
4932 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
4933 ISCSI_TRANSPORT_VERSION);
4935 atomic_set(&iscsi_session_nr, 0);
4937 err = class_register(&iscsi_transport_class);
4941 err = class_register(&iscsi_endpoint_class);
4943 goto unregister_transport_class;
4945 err = class_register(&iscsi_iface_class);
4947 goto unregister_endpoint_class;
4949 err = transport_class_register(&iscsi_host_class);
4951 goto unregister_iface_class;
4953 err = transport_class_register(&iscsi_connection_class);
4955 goto unregister_host_class;
4957 err = transport_class_register(&iscsi_session_class);
4959 goto unregister_conn_class;
4961 err = bus_register(&iscsi_flashnode_bus);
4963 goto unregister_session_class;
4965 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
4968 goto unregister_flashnode_bus;
4971 iscsi_eh_timer_workq = alloc_workqueue("%s",
4972 WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND,
4974 if (!iscsi_eh_timer_workq) {
4979 iscsi_conn_cleanup_workq = alloc_workqueue("%s",
4980 WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND, 0,
4981 "iscsi_conn_cleanup");
4982 if (!iscsi_conn_cleanup_workq) {
4990 destroy_workqueue(iscsi_eh_timer_workq);
4992 netlink_kernel_release(nls);
4993 unregister_flashnode_bus:
4994 bus_unregister(&iscsi_flashnode_bus);
4995 unregister_session_class:
4996 transport_class_unregister(&iscsi_session_class);
4997 unregister_conn_class:
4998 transport_class_unregister(&iscsi_connection_class);
4999 unregister_host_class:
5000 transport_class_unregister(&iscsi_host_class);
5001 unregister_iface_class:
5002 class_unregister(&iscsi_iface_class);
5003 unregister_endpoint_class:
5004 class_unregister(&iscsi_endpoint_class);
5005 unregister_transport_class:
5006 class_unregister(&iscsi_transport_class);
5010 static void __exit iscsi_transport_exit(void)
5012 destroy_workqueue(iscsi_conn_cleanup_workq);
5013 destroy_workqueue(iscsi_eh_timer_workq);
5014 netlink_kernel_release(nls);
5015 bus_unregister(&iscsi_flashnode_bus);
5016 transport_class_unregister(&iscsi_connection_class);
5017 transport_class_unregister(&iscsi_session_class);
5018 transport_class_unregister(&iscsi_host_class);
5019 class_unregister(&iscsi_endpoint_class);
5020 class_unregister(&iscsi_iface_class);
5021 class_unregister(&iscsi_transport_class);
5024 module_init(iscsi_transport_init);
5025 module_exit(iscsi_transport_exit);
5027 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
5028 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
5029 "Alex Aizman <itn780@yahoo.com>");
5030 MODULE_DESCRIPTION("iSCSI Transport Interface");
5031 MODULE_LICENSE("GPL");
5032 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
5033 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);