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 static char *iscsi_session_target_state_name[] = {
1683 [ISCSI_SESSION_TARGET_UNBOUND] = "UNBOUND",
1684 [ISCSI_SESSION_TARGET_ALLOCATED] = "ALLOCATED",
1685 [ISCSI_SESSION_TARGET_SCANNED] = "SCANNED",
1686 [ISCSI_SESSION_TARGET_UNBINDING] = "UNBINDING",
1689 int iscsi_session_chkready(struct iscsi_cls_session *session)
1693 switch (session->state) {
1694 case ISCSI_SESSION_LOGGED_IN:
1697 case ISCSI_SESSION_FAILED:
1698 err = DID_IMM_RETRY << 16;
1700 case ISCSI_SESSION_FREE:
1701 err = DID_TRANSPORT_FAILFAST << 16;
1704 err = DID_NO_CONNECT << 16;
1709 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
1711 int iscsi_is_session_online(struct iscsi_cls_session *session)
1713 unsigned long flags;
1716 spin_lock_irqsave(&session->lock, flags);
1717 if (session->state == ISCSI_SESSION_LOGGED_IN)
1719 spin_unlock_irqrestore(&session->lock, flags);
1722 EXPORT_SYMBOL_GPL(iscsi_is_session_online);
1724 static void iscsi_session_release(struct device *dev)
1726 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
1727 struct Scsi_Host *shost;
1729 shost = iscsi_session_to_shost(session);
1730 scsi_host_put(shost);
1731 ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
1735 int iscsi_is_session_dev(const struct device *dev)
1737 return dev->release == iscsi_session_release;
1739 EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
1741 static int iscsi_iter_session_fn(struct device *dev, void *data)
1743 void (* fn) (struct iscsi_cls_session *) = data;
1745 if (!iscsi_is_session_dev(dev))
1747 fn(iscsi_dev_to_session(dev));
1751 void iscsi_host_for_each_session(struct Scsi_Host *shost,
1752 void (*fn)(struct iscsi_cls_session *))
1754 device_for_each_child(&shost->shost_gendev, fn,
1755 iscsi_iter_session_fn);
1757 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
1760 * iscsi_scan_finished - helper to report when running scans are done
1762 * @time: scan run time
1764 * This function can be used by drives like qla4xxx to report to the scsi
1765 * layer when the scans it kicked off at module load time are done.
1767 int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
1769 struct iscsi_cls_host *ihost = shost->shost_data;
1771 * qla4xxx will have kicked off some session unblocks before calling
1772 * scsi_scan_host, so just wait for them to complete.
1774 return !atomic_read(&ihost->nr_scans);
1776 EXPORT_SYMBOL_GPL(iscsi_scan_finished);
1778 struct iscsi_scan_data {
1779 unsigned int channel;
1782 enum scsi_scan_mode rescan;
1785 static int iscsi_user_scan_session(struct device *dev, void *data)
1787 struct iscsi_scan_data *scan_data = data;
1788 struct iscsi_cls_session *session;
1789 struct Scsi_Host *shost;
1790 struct iscsi_cls_host *ihost;
1791 unsigned long flags;
1794 if (!iscsi_is_session_dev(dev))
1797 session = iscsi_dev_to_session(dev);
1799 ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
1801 shost = iscsi_session_to_shost(session);
1802 ihost = shost->shost_data;
1804 mutex_lock(&ihost->mutex);
1805 spin_lock_irqsave(&session->lock, flags);
1806 if (session->state != ISCSI_SESSION_LOGGED_IN) {
1807 spin_unlock_irqrestore(&session->lock, flags);
1808 goto user_scan_exit;
1810 id = session->target_id;
1811 spin_unlock_irqrestore(&session->lock, flags);
1813 if (id != ISCSI_MAX_TARGET) {
1814 if ((scan_data->channel == SCAN_WILD_CARD ||
1815 scan_data->channel == 0) &&
1816 (scan_data->id == SCAN_WILD_CARD ||
1817 scan_data->id == id)) {
1818 scsi_scan_target(&session->dev, 0, id,
1819 scan_data->lun, scan_data->rescan);
1820 spin_lock_irqsave(&session->lock, flags);
1821 session->target_state = ISCSI_SESSION_TARGET_SCANNED;
1822 spin_unlock_irqrestore(&session->lock, flags);
1827 mutex_unlock(&ihost->mutex);
1828 ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
1832 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
1835 struct iscsi_scan_data scan_data;
1837 scan_data.channel = channel;
1839 scan_data.lun = lun;
1840 scan_data.rescan = SCSI_SCAN_MANUAL;
1842 return device_for_each_child(&shost->shost_gendev, &scan_data,
1843 iscsi_user_scan_session);
1846 static void iscsi_scan_session(struct work_struct *work)
1848 struct iscsi_cls_session *session =
1849 container_of(work, struct iscsi_cls_session, scan_work);
1850 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1851 struct iscsi_cls_host *ihost = shost->shost_data;
1852 struct iscsi_scan_data scan_data;
1854 scan_data.channel = 0;
1855 scan_data.id = SCAN_WILD_CARD;
1856 scan_data.lun = SCAN_WILD_CARD;
1857 scan_data.rescan = SCSI_SCAN_RESCAN;
1859 iscsi_user_scan_session(&session->dev, &scan_data);
1860 atomic_dec(&ihost->nr_scans);
1864 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1865 * @cmd: scsi cmd passed to scsi eh handler
1867 * If the session is down this function will wait for the recovery
1868 * timer to fire or for the session to be logged back in. If the
1869 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1870 * should pass this error value to the scsi eh.
1872 int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
1874 struct iscsi_cls_session *session =
1875 starget_to_session(scsi_target(cmd->device));
1876 unsigned long flags;
1879 spin_lock_irqsave(&session->lock, flags);
1880 while (session->state != ISCSI_SESSION_LOGGED_IN) {
1881 if (session->state == ISCSI_SESSION_FREE) {
1885 spin_unlock_irqrestore(&session->lock, flags);
1887 spin_lock_irqsave(&session->lock, flags);
1889 spin_unlock_irqrestore(&session->lock, flags);
1892 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
1894 static void session_recovery_timedout(struct work_struct *work)
1896 struct iscsi_cls_session *session =
1897 container_of(work, struct iscsi_cls_session,
1898 recovery_work.work);
1899 unsigned long flags;
1901 iscsi_cls_session_printk(KERN_INFO, session,
1902 "session recovery timed out after %d secs\n",
1903 session->recovery_tmo);
1905 spin_lock_irqsave(&session->lock, flags);
1906 switch (session->state) {
1907 case ISCSI_SESSION_FAILED:
1908 session->state = ISCSI_SESSION_FREE;
1910 case ISCSI_SESSION_LOGGED_IN:
1911 case ISCSI_SESSION_FREE:
1912 /* we raced with the unblock's flush */
1913 spin_unlock_irqrestore(&session->lock, flags);
1916 spin_unlock_irqrestore(&session->lock, flags);
1918 ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
1919 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
1920 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
1922 if (session->transport->session_recovery_timedout)
1923 session->transport->session_recovery_timedout(session);
1926 static void __iscsi_unblock_session(struct work_struct *work)
1928 struct iscsi_cls_session *session =
1929 container_of(work, struct iscsi_cls_session,
1931 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1932 struct iscsi_cls_host *ihost = shost->shost_data;
1933 unsigned long flags;
1935 ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
1937 * The recovery and unblock work get run from the same workqueue,
1938 * so try to cancel it if it was going to run after this unblock.
1940 cancel_delayed_work(&session->recovery_work);
1941 spin_lock_irqsave(&session->lock, flags);
1942 session->state = ISCSI_SESSION_LOGGED_IN;
1943 spin_unlock_irqrestore(&session->lock, flags);
1945 scsi_target_unblock(&session->dev, SDEV_RUNNING);
1947 * Only do kernel scanning if the driver is properly hooked into
1948 * the async scanning code (drivers like iscsi_tcp do login and
1949 * scanning from userspace).
1951 if (shost->hostt->scan_finished) {
1952 if (scsi_queue_work(shost, &session->scan_work))
1953 atomic_inc(&ihost->nr_scans);
1955 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
1959 * iscsi_unblock_session - set a session as logged in and start IO.
1960 * @session: iscsi session
1962 * Mark a session as ready to accept IO.
1964 void iscsi_unblock_session(struct iscsi_cls_session *session)
1966 flush_work(&session->block_work);
1968 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
1970 * Blocking the session can be done from any context so we only
1971 * queue the block work. Make sure the unblock work has completed
1972 * because it flushes/cancels the other works and updates the state.
1974 flush_work(&session->unblock_work);
1976 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
1978 static void __iscsi_block_session(struct work_struct *work)
1980 struct iscsi_cls_session *session =
1981 container_of(work, struct iscsi_cls_session,
1983 unsigned long flags;
1985 ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
1986 spin_lock_irqsave(&session->lock, flags);
1987 session->state = ISCSI_SESSION_FAILED;
1988 spin_unlock_irqrestore(&session->lock, flags);
1989 scsi_target_block(&session->dev);
1990 ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
1991 if (session->recovery_tmo >= 0)
1992 queue_delayed_work(iscsi_eh_timer_workq,
1993 &session->recovery_work,
1994 session->recovery_tmo * HZ);
1997 void iscsi_block_session(struct iscsi_cls_session *session)
1999 queue_work(iscsi_eh_timer_workq, &session->block_work);
2001 EXPORT_SYMBOL_GPL(iscsi_block_session);
2003 static void __iscsi_unbind_session(struct work_struct *work)
2005 struct iscsi_cls_session *session =
2006 container_of(work, struct iscsi_cls_session,
2008 struct Scsi_Host *shost = iscsi_session_to_shost(session);
2009 struct iscsi_cls_host *ihost = shost->shost_data;
2010 unsigned long flags;
2011 unsigned int target_id;
2012 bool remove_target = true;
2014 ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
2016 /* Prevent new scans and make sure scanning is not in progress */
2017 mutex_lock(&ihost->mutex);
2018 spin_lock_irqsave(&session->lock, flags);
2019 if (session->target_state == ISCSI_SESSION_TARGET_ALLOCATED) {
2020 remove_target = false;
2021 } else if (session->target_state != ISCSI_SESSION_TARGET_SCANNED) {
2022 spin_unlock_irqrestore(&session->lock, flags);
2023 mutex_unlock(&ihost->mutex);
2024 ISCSI_DBG_TRANS_SESSION(session,
2025 "Skipping target unbinding: Session is unbound/unbinding.\n");
2029 session->target_state = ISCSI_SESSION_TARGET_UNBINDING;
2030 target_id = session->target_id;
2031 session->target_id = ISCSI_MAX_TARGET;
2032 spin_unlock_irqrestore(&session->lock, flags);
2033 mutex_unlock(&ihost->mutex);
2036 scsi_remove_target(&session->dev);
2038 if (session->ida_used)
2039 ida_simple_remove(&iscsi_sess_ida, target_id);
2041 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
2042 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
2044 spin_lock_irqsave(&session->lock, flags);
2045 session->target_state = ISCSI_SESSION_TARGET_UNBOUND;
2046 spin_unlock_irqrestore(&session->lock, flags);
2049 static void __iscsi_destroy_session(struct work_struct *work)
2051 struct iscsi_cls_session *session =
2052 container_of(work, struct iscsi_cls_session, destroy_work);
2054 session->transport->destroy_session(session);
2057 struct iscsi_cls_session *
2058 iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2061 struct iscsi_cls_session *session;
2063 session = kzalloc(sizeof(*session) + dd_size,
2068 session->transport = transport;
2069 session->creator = -1;
2070 session->recovery_tmo = 120;
2071 session->recovery_tmo_sysfs_override = false;
2072 session->state = ISCSI_SESSION_FREE;
2073 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
2074 INIT_LIST_HEAD(&session->sess_list);
2075 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
2076 INIT_WORK(&session->block_work, __iscsi_block_session);
2077 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
2078 INIT_WORK(&session->scan_work, iscsi_scan_session);
2079 INIT_WORK(&session->destroy_work, __iscsi_destroy_session);
2080 spin_lock_init(&session->lock);
2082 /* this is released in the dev's release function */
2083 scsi_host_get(shost);
2084 session->dev.parent = &shost->shost_gendev;
2085 session->dev.release = iscsi_session_release;
2086 device_initialize(&session->dev);
2088 session->dd_data = &session[1];
2090 ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
2093 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
2095 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
2097 unsigned long flags;
2101 session->sid = atomic_add_return(1, &iscsi_session_nr);
2103 if (target_id == ISCSI_MAX_TARGET) {
2104 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
2107 iscsi_cls_session_printk(KERN_ERR, session,
2108 "Failure in Target ID Allocation\n");
2111 session->target_id = (unsigned int)id;
2112 session->ida_used = true;
2114 session->target_id = target_id;
2115 spin_lock_irqsave(&session->lock, flags);
2116 session->target_state = ISCSI_SESSION_TARGET_ALLOCATED;
2117 spin_unlock_irqrestore(&session->lock, flags);
2119 dev_set_name(&session->dev, "session%u", session->sid);
2120 err = device_add(&session->dev);
2122 iscsi_cls_session_printk(KERN_ERR, session,
2123 "could not register session's dev\n");
2126 err = transport_register_device(&session->dev);
2128 iscsi_cls_session_printk(KERN_ERR, session,
2129 "could not register transport's dev\n");
2133 spin_lock_irqsave(&sesslock, flags);
2134 list_add(&session->sess_list, &sesslist);
2135 spin_unlock_irqrestore(&sesslock, flags);
2137 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
2138 ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
2142 device_del(&session->dev);
2144 if (session->ida_used)
2145 ida_simple_remove(&iscsi_sess_ida, session->target_id);
2149 EXPORT_SYMBOL_GPL(iscsi_add_session);
2152 * iscsi_create_session - create iscsi class session
2154 * @transport: iscsi transport
2155 * @dd_size: private driver data size
2156 * @target_id: which target
2158 * This can be called from a LLD or iscsi_transport.
2160 struct iscsi_cls_session *
2161 iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2162 int dd_size, unsigned int target_id)
2164 struct iscsi_cls_session *session;
2166 session = iscsi_alloc_session(shost, transport, dd_size);
2170 if (iscsi_add_session(session, target_id)) {
2171 iscsi_free_session(session);
2176 EXPORT_SYMBOL_GPL(iscsi_create_session);
2178 static void iscsi_conn_release(struct device *dev)
2180 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
2181 struct device *parent = conn->dev.parent;
2183 ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
2188 static int iscsi_is_conn_dev(const struct device *dev)
2190 return dev->release == iscsi_conn_release;
2193 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
2195 if (!iscsi_is_conn_dev(dev))
2197 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
2200 void iscsi_remove_session(struct iscsi_cls_session *session)
2202 unsigned long flags;
2205 ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
2207 spin_lock_irqsave(&sesslock, flags);
2208 if (!list_empty(&session->sess_list))
2209 list_del(&session->sess_list);
2210 spin_unlock_irqrestore(&sesslock, flags);
2212 flush_work(&session->block_work);
2213 flush_work(&session->unblock_work);
2214 cancel_delayed_work_sync(&session->recovery_work);
2216 * If we are blocked let commands flow again. The lld or iscsi
2217 * layer should set up the queuecommand to fail commands.
2218 * We assume that LLD will not be calling block/unblock while
2219 * removing the session.
2221 spin_lock_irqsave(&session->lock, flags);
2222 session->state = ISCSI_SESSION_FREE;
2223 spin_unlock_irqrestore(&session->lock, flags);
2225 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2226 /* flush running scans then delete devices */
2227 flush_work(&session->scan_work);
2228 /* flush running unbind operations */
2229 flush_work(&session->unbind_work);
2230 __iscsi_unbind_session(&session->unbind_work);
2232 /* hw iscsi may not have removed all connections from session */
2233 err = device_for_each_child(&session->dev, NULL,
2234 iscsi_iter_destroy_conn_fn);
2236 iscsi_cls_session_printk(KERN_ERR, session,
2237 "Could not delete all connections "
2238 "for session. Error %d.\n", err);
2240 transport_unregister_device(&session->dev);
2242 ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
2243 device_del(&session->dev);
2245 EXPORT_SYMBOL_GPL(iscsi_remove_session);
2247 static void iscsi_stop_conn(struct iscsi_cls_conn *conn, int flag)
2249 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn.\n");
2252 case STOP_CONN_RECOVER:
2253 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2255 case STOP_CONN_TERM:
2256 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2259 iscsi_cls_conn_printk(KERN_ERR, conn, "invalid stop flag %d\n",
2264 conn->transport->stop_conn(conn, flag);
2265 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn done.\n");
2268 static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
2270 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2271 struct iscsi_endpoint *ep;
2273 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep.\n");
2274 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2276 if (!conn->ep || !session->transport->ep_disconnect)
2282 session->transport->unbind_conn(conn, is_active);
2283 session->transport->ep_disconnect(ep);
2284 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep done.\n");
2287 static void iscsi_if_disconnect_bound_ep(struct iscsi_cls_conn *conn,
2288 struct iscsi_endpoint *ep,
2291 /* Check if this was a conn error and the kernel took ownership */
2292 spin_lock_irq(&conn->lock);
2293 if (!test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2294 spin_unlock_irq(&conn->lock);
2295 iscsi_ep_disconnect(conn, is_active);
2297 spin_unlock_irq(&conn->lock);
2298 ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2299 mutex_unlock(&conn->ep_mutex);
2301 flush_work(&conn->cleanup_work);
2303 * Userspace is now done with the EP so we can release the ref
2304 * iscsi_cleanup_conn_work_fn took.
2306 iscsi_put_endpoint(ep);
2307 mutex_lock(&conn->ep_mutex);
2311 static int iscsi_if_stop_conn(struct iscsi_cls_conn *conn, int flag)
2313 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop.\n");
2315 * If this is a termination we have to call stop_conn with that flag
2316 * so the correct states get set. If we haven't run the work yet try to
2317 * avoid the extra run.
2319 if (flag == STOP_CONN_TERM) {
2320 cancel_work_sync(&conn->cleanup_work);
2321 iscsi_stop_conn(conn, flag);
2324 * For offload, when iscsid is restarted it won't know about
2325 * existing endpoints so it can't do a ep_disconnect. We clean
2326 * it up here for userspace.
2328 mutex_lock(&conn->ep_mutex);
2330 iscsi_if_disconnect_bound_ep(conn, conn->ep, true);
2331 mutex_unlock(&conn->ep_mutex);
2334 * Figure out if it was the kernel or userspace initiating this.
2336 spin_lock_irq(&conn->lock);
2337 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2338 spin_unlock_irq(&conn->lock);
2339 iscsi_stop_conn(conn, flag);
2341 spin_unlock_irq(&conn->lock);
2342 ISCSI_DBG_TRANS_CONN(conn,
2343 "flush kernel conn cleanup.\n");
2344 flush_work(&conn->cleanup_work);
2347 * Only clear for recovery to avoid extra cleanup runs during
2350 spin_lock_irq(&conn->lock);
2351 clear_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags);
2352 spin_unlock_irq(&conn->lock);
2354 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop done.\n");
2358 static void iscsi_cleanup_conn_work_fn(struct work_struct *work)
2360 struct iscsi_cls_conn *conn = container_of(work, struct iscsi_cls_conn,
2362 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2364 mutex_lock(&conn->ep_mutex);
2366 * Get a ref to the ep, so we don't release its ID until after
2367 * userspace is done referencing it in iscsi_if_disconnect_bound_ep.
2370 get_device(&conn->ep->dev);
2371 iscsi_ep_disconnect(conn, false);
2373 if (system_state != SYSTEM_RUNNING) {
2375 * If the user has set up for the session to never timeout
2376 * then hang like they wanted. For all other cases fail right
2377 * away since userspace is not going to relogin.
2379 if (session->recovery_tmo > 0)
2380 session->recovery_tmo = 0;
2383 iscsi_stop_conn(conn, STOP_CONN_RECOVER);
2384 mutex_unlock(&conn->ep_mutex);
2385 ISCSI_DBG_TRANS_CONN(conn, "cleanup done.\n");
2388 static int iscsi_iter_force_destroy_conn_fn(struct device *dev, void *data)
2390 struct iscsi_transport *transport;
2391 struct iscsi_cls_conn *conn;
2393 if (!iscsi_is_conn_dev(dev))
2396 conn = iscsi_dev_to_conn(dev);
2397 transport = conn->transport;
2399 if (READ_ONCE(conn->state) != ISCSI_CONN_DOWN)
2400 iscsi_if_stop_conn(conn, STOP_CONN_TERM);
2402 transport->destroy_conn(conn);
2407 * iscsi_force_destroy_session - destroy a session from the kernel
2408 * @session: session to destroy
2410 * Force the destruction of a session from the kernel. This should only be
2411 * used when userspace is no longer running during system shutdown.
2413 void iscsi_force_destroy_session(struct iscsi_cls_session *session)
2415 struct iscsi_transport *transport = session->transport;
2416 unsigned long flags;
2418 WARN_ON_ONCE(system_state == SYSTEM_RUNNING);
2420 spin_lock_irqsave(&sesslock, flags);
2421 if (list_empty(&session->sess_list)) {
2422 spin_unlock_irqrestore(&sesslock, flags);
2424 * Conn/ep is already freed. Session is being torn down via
2425 * async path. For shutdown we don't care about it so return.
2429 spin_unlock_irqrestore(&sesslock, flags);
2431 device_for_each_child(&session->dev, NULL,
2432 iscsi_iter_force_destroy_conn_fn);
2433 transport->destroy_session(session);
2435 EXPORT_SYMBOL_GPL(iscsi_force_destroy_session);
2437 void iscsi_free_session(struct iscsi_cls_session *session)
2439 ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
2440 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
2441 put_device(&session->dev);
2443 EXPORT_SYMBOL_GPL(iscsi_free_session);
2446 * iscsi_create_conn - create iscsi class connection
2447 * @session: iscsi cls session
2448 * @dd_size: private driver data size
2449 * @cid: connection id
2451 * This can be called from a LLD or iscsi_transport. The connection
2452 * is child of the session so cid must be unique for all connections
2455 * Since we do not support MCS, cid will normally be zero. In some cases
2456 * for software iscsi we could be trying to preallocate a connection struct
2457 * in which case there could be two connection structs and cid would be
2460 struct iscsi_cls_conn *
2461 iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
2463 struct iscsi_transport *transport = session->transport;
2464 struct iscsi_cls_conn *conn;
2465 unsigned long flags;
2468 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
2472 conn->dd_data = &conn[1];
2474 mutex_init(&conn->ep_mutex);
2475 spin_lock_init(&conn->lock);
2476 INIT_LIST_HEAD(&conn->conn_list);
2477 INIT_WORK(&conn->cleanup_work, iscsi_cleanup_conn_work_fn);
2478 conn->transport = transport;
2480 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2482 /* this is released in the dev's release function */
2483 if (!get_device(&session->dev))
2486 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
2487 conn->dev.parent = &session->dev;
2488 conn->dev.release = iscsi_conn_release;
2489 err = device_register(&conn->dev);
2491 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2492 "register connection's dev\n");
2493 goto release_parent_ref;
2495 err = transport_register_device(&conn->dev);
2497 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2498 "register transport's dev\n");
2499 goto release_conn_ref;
2502 spin_lock_irqsave(&connlock, flags);
2503 list_add(&conn->conn_list, &connlist);
2504 spin_unlock_irqrestore(&connlock, flags);
2506 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
2510 device_unregister(&conn->dev);
2511 put_device(&session->dev);
2514 put_device(&session->dev);
2520 EXPORT_SYMBOL_GPL(iscsi_create_conn);
2523 * iscsi_destroy_conn - destroy iscsi class connection
2524 * @conn: iscsi cls session
2526 * This can be called from a LLD or iscsi_transport.
2528 int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
2530 unsigned long flags;
2532 spin_lock_irqsave(&connlock, flags);
2533 list_del(&conn->conn_list);
2534 spin_unlock_irqrestore(&connlock, flags);
2536 transport_unregister_device(&conn->dev);
2537 ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n");
2538 device_unregister(&conn->dev);
2541 EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
2543 void iscsi_put_conn(struct iscsi_cls_conn *conn)
2545 put_device(&conn->dev);
2547 EXPORT_SYMBOL_GPL(iscsi_put_conn);
2549 void iscsi_get_conn(struct iscsi_cls_conn *conn)
2551 get_device(&conn->dev);
2553 EXPORT_SYMBOL_GPL(iscsi_get_conn);
2556 * iscsi interface functions
2558 static struct iscsi_internal *
2559 iscsi_if_transport_lookup(struct iscsi_transport *tt)
2561 struct iscsi_internal *priv;
2562 unsigned long flags;
2564 spin_lock_irqsave(&iscsi_transport_lock, flags);
2565 list_for_each_entry(priv, &iscsi_transports, list) {
2566 if (tt == priv->iscsi_transport) {
2567 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2571 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2576 iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
2578 return nlmsg_multicast(nls, skb, 0, group, gfp);
2582 iscsi_unicast_skb(struct sk_buff *skb, u32 portid)
2584 return nlmsg_unicast(nls, skb, portid);
2587 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
2588 char *data, uint32_t data_size)
2590 struct nlmsghdr *nlh;
2591 struct sk_buff *skb;
2592 struct iscsi_uevent *ev;
2594 struct iscsi_internal *priv;
2595 int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
2598 priv = iscsi_if_transport_lookup(conn->transport);
2602 skb = alloc_skb(len, GFP_ATOMIC);
2604 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
2605 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
2606 "control PDU: OOM\n");
2610 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2611 ev = nlmsg_data(nlh);
2612 memset(ev, 0, sizeof(*ev));
2613 ev->transport_handle = iscsi_handle(conn->transport);
2614 ev->type = ISCSI_KEVENT_RECV_PDU;
2615 ev->r.recv_req.cid = conn->cid;
2616 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
2617 pdu = (char*)ev + sizeof(*ev);
2618 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
2619 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
2621 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2623 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
2625 int iscsi_offload_mesg(struct Scsi_Host *shost,
2626 struct iscsi_transport *transport, uint32_t type,
2627 char *data, uint16_t data_size)
2629 struct nlmsghdr *nlh;
2630 struct sk_buff *skb;
2631 struct iscsi_uevent *ev;
2632 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2634 skb = alloc_skb(len, GFP_ATOMIC);
2636 printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
2640 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2641 ev = nlmsg_data(nlh);
2642 memset(ev, 0, sizeof(*ev));
2644 ev->transport_handle = iscsi_handle(transport);
2646 case ISCSI_KEVENT_PATH_REQ:
2647 ev->r.req_path.host_no = shost->host_no;
2649 case ISCSI_KEVENT_IF_DOWN:
2650 ev->r.notify_if_down.host_no = shost->host_no;
2654 memcpy((char *)ev + sizeof(*ev), data, data_size);
2656 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
2658 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
2660 void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
2662 struct nlmsghdr *nlh;
2663 struct sk_buff *skb;
2664 struct iscsi_uevent *ev;
2665 struct iscsi_internal *priv;
2666 int len = nlmsg_total_size(sizeof(*ev));
2667 unsigned long flags;
2670 spin_lock_irqsave(&conn->lock, flags);
2672 * Userspace will only do a stop call if we are at least bound. And, we
2673 * only need to do the in kernel cleanup if in the UP state so cmds can
2674 * be released to upper layers. If in other states just wait for
2675 * userspace to avoid races that can leave the cleanup_work queued.
2677 state = READ_ONCE(conn->state);
2679 case ISCSI_CONN_BOUND:
2681 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP,
2683 queue_work(iscsi_conn_cleanup_workq,
2684 &conn->cleanup_work);
2688 ISCSI_DBG_TRANS_CONN(conn, "Got conn error in state %d\n",
2692 spin_unlock_irqrestore(&conn->lock, flags);
2694 priv = iscsi_if_transport_lookup(conn->transport);
2698 skb = alloc_skb(len, GFP_ATOMIC);
2700 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2701 "conn error (%d)\n", error);
2705 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2706 ev = nlmsg_data(nlh);
2707 ev->transport_handle = iscsi_handle(conn->transport);
2708 ev->type = ISCSI_KEVENT_CONN_ERROR;
2709 ev->r.connerror.error = error;
2710 ev->r.connerror.cid = conn->cid;
2711 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
2713 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2715 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
2718 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
2720 void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
2721 enum iscsi_conn_state state)
2723 struct nlmsghdr *nlh;
2724 struct sk_buff *skb;
2725 struct iscsi_uevent *ev;
2726 struct iscsi_internal *priv;
2727 int len = nlmsg_total_size(sizeof(*ev));
2729 priv = iscsi_if_transport_lookup(conn->transport);
2733 skb = alloc_skb(len, GFP_ATOMIC);
2735 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2736 "conn login (%d)\n", state);
2740 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2741 ev = nlmsg_data(nlh);
2742 ev->transport_handle = iscsi_handle(conn->transport);
2743 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
2744 ev->r.conn_login.state = state;
2745 ev->r.conn_login.cid = conn->cid;
2746 ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
2747 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2749 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
2752 EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
2754 void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
2755 enum iscsi_host_event_code code, uint32_t data_size,
2758 struct nlmsghdr *nlh;
2759 struct sk_buff *skb;
2760 struct iscsi_uevent *ev;
2761 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2763 skb = alloc_skb(len, GFP_NOIO);
2765 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
2770 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2771 ev = nlmsg_data(nlh);
2772 ev->transport_handle = iscsi_handle(transport);
2773 ev->type = ISCSI_KEVENT_HOST_EVENT;
2774 ev->r.host_event.host_no = host_no;
2775 ev->r.host_event.code = code;
2776 ev->r.host_event.data_size = data_size;
2779 memcpy((char *)ev + sizeof(*ev), data, data_size);
2781 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2783 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
2785 void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
2786 uint32_t status, uint32_t pid, uint32_t data_size,
2789 struct nlmsghdr *nlh;
2790 struct sk_buff *skb;
2791 struct iscsi_uevent *ev;
2792 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2794 skb = alloc_skb(len, GFP_NOIO);
2796 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
2800 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2801 ev = nlmsg_data(nlh);
2802 ev->transport_handle = iscsi_handle(transport);
2803 ev->type = ISCSI_KEVENT_PING_COMP;
2804 ev->r.ping_comp.host_no = host_no;
2805 ev->r.ping_comp.status = status;
2806 ev->r.ping_comp.pid = pid;
2807 ev->r.ping_comp.data_size = data_size;
2808 memcpy((char *)ev + sizeof(*ev), data, data_size);
2810 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2812 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
2815 iscsi_if_send_reply(u32 portid, int type, void *payload, int size)
2817 struct sk_buff *skb;
2818 struct nlmsghdr *nlh;
2819 int len = nlmsg_total_size(size);
2821 skb = alloc_skb(len, GFP_ATOMIC);
2823 printk(KERN_ERR "Could not allocate skb to send reply.\n");
2827 nlh = __nlmsg_put(skb, 0, 0, type, (len - sizeof(*nlh)), 0);
2828 memcpy(nlmsg_data(nlh), payload, size);
2829 return iscsi_unicast_skb(skb, portid);
2833 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
2835 struct iscsi_uevent *ev = nlmsg_data(nlh);
2836 struct iscsi_stats *stats;
2837 struct sk_buff *skbstat;
2838 struct iscsi_cls_conn *conn;
2839 struct nlmsghdr *nlhstat;
2840 struct iscsi_uevent *evstat;
2841 struct iscsi_internal *priv;
2842 int len = nlmsg_total_size(sizeof(*ev) +
2843 sizeof(struct iscsi_stats) +
2844 sizeof(struct iscsi_stats_custom) *
2845 ISCSI_STATS_CUSTOM_MAX);
2848 priv = iscsi_if_transport_lookup(transport);
2852 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
2859 skbstat = alloc_skb(len, GFP_ATOMIC);
2861 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
2862 "deliver stats: OOM\n");
2866 nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
2867 (len - sizeof(*nlhstat)), 0);
2868 evstat = nlmsg_data(nlhstat);
2869 memset(evstat, 0, sizeof(*evstat));
2870 evstat->transport_handle = iscsi_handle(conn->transport);
2871 evstat->type = nlh->nlmsg_type;
2872 evstat->u.get_stats.cid =
2873 ev->u.get_stats.cid;
2874 evstat->u.get_stats.sid =
2875 ev->u.get_stats.sid;
2876 stats = (struct iscsi_stats *)
2877 ((char*)evstat + sizeof(*evstat));
2878 memset(stats, 0, sizeof(*stats));
2880 transport->get_stats(conn, stats);
2881 actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
2882 sizeof(struct iscsi_stats) +
2883 sizeof(struct iscsi_stats_custom) *
2884 stats->custom_length);
2885 actual_size -= sizeof(*nlhstat);
2886 actual_size = nlmsg_msg_size(actual_size);
2887 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
2888 nlhstat->nlmsg_len = actual_size;
2890 err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
2892 } while (err < 0 && err != -ECONNREFUSED);
2898 * iscsi_session_event - send session destr. completion event
2899 * @session: iscsi class session
2900 * @event: type of event
2902 int iscsi_session_event(struct iscsi_cls_session *session,
2903 enum iscsi_uevent_e event)
2905 struct iscsi_internal *priv;
2906 struct Scsi_Host *shost;
2907 struct iscsi_uevent *ev;
2908 struct sk_buff *skb;
2909 struct nlmsghdr *nlh;
2910 int rc, len = nlmsg_total_size(sizeof(*ev));
2912 priv = iscsi_if_transport_lookup(session->transport);
2915 shost = iscsi_session_to_shost(session);
2917 skb = alloc_skb(len, GFP_KERNEL);
2919 iscsi_cls_session_printk(KERN_ERR, session,
2920 "Cannot notify userspace of session "
2921 "event %u\n", event);
2925 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2926 ev = nlmsg_data(nlh);
2927 ev->transport_handle = iscsi_handle(session->transport);
2931 case ISCSI_KEVENT_DESTROY_SESSION:
2932 ev->r.d_session.host_no = shost->host_no;
2933 ev->r.d_session.sid = session->sid;
2935 case ISCSI_KEVENT_CREATE_SESSION:
2936 ev->r.c_session_ret.host_no = shost->host_no;
2937 ev->r.c_session_ret.sid = session->sid;
2939 case ISCSI_KEVENT_UNBIND_SESSION:
2940 ev->r.unbind_session.host_no = shost->host_no;
2941 ev->r.unbind_session.sid = session->sid;
2944 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
2951 * this will occur if the daemon is not up, so we just warn
2952 * the user and when the daemon is restarted it will handle it
2954 rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
2956 iscsi_cls_session_printk(KERN_ERR, session,
2957 "Cannot notify userspace of session "
2958 "event %u. Check iscsi daemon\n",
2961 ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
2965 EXPORT_SYMBOL_GPL(iscsi_session_event);
2968 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
2969 struct iscsi_uevent *ev, pid_t pid,
2970 uint32_t initial_cmdsn, uint16_t cmds_max,
2971 uint16_t queue_depth)
2973 struct iscsi_transport *transport = priv->iscsi_transport;
2974 struct iscsi_cls_session *session;
2975 struct Scsi_Host *shost;
2977 session = transport->create_session(ep, cmds_max, queue_depth,
2982 session->creator = pid;
2983 shost = iscsi_session_to_shost(session);
2984 ev->r.c_session_ret.host_no = shost->host_no;
2985 ev->r.c_session_ret.sid = session->sid;
2986 ISCSI_DBG_TRANS_SESSION(session,
2987 "Completed creating transport session\n");
2992 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2994 struct iscsi_cls_conn *conn;
2995 struct iscsi_cls_session *session;
2997 session = iscsi_session_lookup(ev->u.c_conn.sid);
2999 printk(KERN_ERR "iscsi: invalid session %d.\n",
3004 conn = transport->create_conn(session, ev->u.c_conn.cid);
3006 iscsi_cls_session_printk(KERN_ERR, session,
3007 "couldn't create a new connection.");
3011 ev->r.c_conn_ret.sid = session->sid;
3012 ev->r.c_conn_ret.cid = conn->cid;
3014 ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
3019 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3021 struct iscsi_cls_conn *conn;
3023 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
3027 ISCSI_DBG_TRANS_CONN(conn, "Flushing cleanup during destruction\n");
3028 flush_work(&conn->cleanup_work);
3029 ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
3031 if (transport->destroy_conn)
3032 transport->destroy_conn(conn);
3037 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3039 char *data = (char*)ev + sizeof(*ev);
3040 struct iscsi_cls_conn *conn;
3041 struct iscsi_cls_session *session;
3042 int err = 0, value = 0, state;
3044 if (ev->u.set_param.len > PAGE_SIZE)
3047 session = iscsi_session_lookup(ev->u.set_param.sid);
3048 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
3049 if (!conn || !session)
3052 switch (ev->u.set_param.param) {
3053 case ISCSI_PARAM_SESS_RECOVERY_TMO:
3054 sscanf(data, "%d", &value);
3055 if (!session->recovery_tmo_sysfs_override)
3056 session->recovery_tmo = value;
3059 state = READ_ONCE(conn->state);
3060 if (state == ISCSI_CONN_BOUND || state == ISCSI_CONN_UP) {
3061 err = transport->set_param(conn, ev->u.set_param.param,
3062 data, ev->u.set_param.len);
3071 static int iscsi_if_ep_connect(struct iscsi_transport *transport,
3072 struct iscsi_uevent *ev, int msg_type)
3074 struct iscsi_endpoint *ep;
3075 struct sockaddr *dst_addr;
3076 struct Scsi_Host *shost = NULL;
3077 int non_blocking, err = 0;
3079 if (!transport->ep_connect)
3082 if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
3083 shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
3085 printk(KERN_ERR "ep connect failed. Could not find "
3087 ev->u.ep_connect_through_host.host_no);
3090 non_blocking = ev->u.ep_connect_through_host.non_blocking;
3092 non_blocking = ev->u.ep_connect.non_blocking;
3094 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3095 ep = transport->ep_connect(shost, dst_addr, non_blocking);
3101 ev->r.ep_connect_ret.handle = ep->id;
3104 scsi_host_put(shost);
3108 static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
3111 struct iscsi_cls_conn *conn;
3112 struct iscsi_endpoint *ep;
3114 if (!transport->ep_disconnect)
3117 ep = iscsi_lookup_endpoint(ep_handle);
3124 * conn was not even bound yet, so we can't get iscsi conn
3127 transport->ep_disconnect(ep);
3131 mutex_lock(&conn->ep_mutex);
3132 iscsi_if_disconnect_bound_ep(conn, ep, false);
3133 mutex_unlock(&conn->ep_mutex);
3135 iscsi_put_endpoint(ep);
3140 iscsi_if_transport_ep(struct iscsi_transport *transport,
3141 struct iscsi_uevent *ev, int msg_type)
3143 struct iscsi_endpoint *ep;
3147 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3148 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3149 rc = iscsi_if_ep_connect(transport, ev, msg_type);
3151 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3152 if (!transport->ep_poll)
3155 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
3159 ev->r.retcode = transport->ep_poll(ep,
3160 ev->u.ep_poll.timeout_ms);
3161 iscsi_put_endpoint(ep);
3163 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3164 rc = iscsi_if_ep_disconnect(transport,
3165 ev->u.ep_disconnect.ep_handle);
3172 iscsi_tgt_dscvr(struct iscsi_transport *transport,
3173 struct iscsi_uevent *ev)
3175 struct Scsi_Host *shost;
3176 struct sockaddr *dst_addr;
3179 if (!transport->tgt_dscvr)
3182 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
3184 printk(KERN_ERR "target discovery could not find host no %u\n",
3185 ev->u.tgt_dscvr.host_no);
3190 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3191 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
3192 ev->u.tgt_dscvr.enable, dst_addr);
3193 scsi_host_put(shost);
3198 iscsi_set_host_param(struct iscsi_transport *transport,
3199 struct iscsi_uevent *ev)
3201 char *data = (char*)ev + sizeof(*ev);
3202 struct Scsi_Host *shost;
3205 if (!transport->set_host_param)
3208 if (ev->u.set_host_param.len > PAGE_SIZE)
3211 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
3213 printk(KERN_ERR "set_host_param could not find host no %u\n",
3214 ev->u.set_host_param.host_no);
3218 err = transport->set_host_param(shost, ev->u.set_host_param.param,
3219 data, ev->u.set_host_param.len);
3220 scsi_host_put(shost);
3225 iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3227 struct Scsi_Host *shost;
3228 struct iscsi_path *params;
3231 if (!transport->set_path)
3234 shost = scsi_host_lookup(ev->u.set_path.host_no);
3236 printk(KERN_ERR "set path could not find host no %u\n",
3237 ev->u.set_path.host_no);
3241 params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
3242 err = transport->set_path(shost, params);
3244 scsi_host_put(shost);
3248 static int iscsi_session_has_conns(int sid)
3250 struct iscsi_cls_conn *conn;
3251 unsigned long flags;
3254 spin_lock_irqsave(&connlock, flags);
3255 list_for_each_entry(conn, &connlist, conn_list) {
3256 if (iscsi_conn_get_sid(conn) == sid) {
3261 spin_unlock_irqrestore(&connlock, flags);
3267 iscsi_set_iface_params(struct iscsi_transport *transport,
3268 struct iscsi_uevent *ev, uint32_t len)
3270 char *data = (char *)ev + sizeof(*ev);
3271 struct Scsi_Host *shost;
3274 if (!transport->set_iface_param)
3277 shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
3279 printk(KERN_ERR "set_iface_params could not find host no %u\n",
3280 ev->u.set_iface_params.host_no);
3284 err = transport->set_iface_param(shost, data, len);
3285 scsi_host_put(shost);
3290 iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3292 struct Scsi_Host *shost;
3293 struct sockaddr *dst_addr;
3296 if (!transport->send_ping)
3299 shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
3301 printk(KERN_ERR "iscsi_ping could not find host no %u\n",
3302 ev->u.iscsi_ping.host_no);
3306 dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
3307 err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
3308 ev->u.iscsi_ping.iface_type,
3309 ev->u.iscsi_ping.payload_size,
3310 ev->u.iscsi_ping.pid,
3312 scsi_host_put(shost);
3317 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3319 struct iscsi_uevent *ev = nlmsg_data(nlh);
3320 struct Scsi_Host *shost = NULL;
3321 struct iscsi_chap_rec *chap_rec;
3322 struct iscsi_internal *priv;
3323 struct sk_buff *skbchap;
3324 struct nlmsghdr *nlhchap;
3325 struct iscsi_uevent *evchap;
3326 uint32_t chap_buf_size;
3330 if (!transport->get_chap)
3333 priv = iscsi_if_transport_lookup(transport);
3337 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
3338 len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3340 shost = scsi_host_lookup(ev->u.get_chap.host_no);
3342 printk(KERN_ERR "%s: failed. Could not find host no %u\n",
3343 __func__, ev->u.get_chap.host_no);
3350 skbchap = alloc_skb(len, GFP_KERNEL);
3352 printk(KERN_ERR "can not deliver chap: OOM\n");
3357 nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
3358 (len - sizeof(*nlhchap)), 0);
3359 evchap = nlmsg_data(nlhchap);
3360 memset(evchap, 0, sizeof(*evchap));
3361 evchap->transport_handle = iscsi_handle(transport);
3362 evchap->type = nlh->nlmsg_type;
3363 evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
3364 evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
3365 evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
3366 buf = (char *)evchap + sizeof(*evchap);
3367 memset(buf, 0, chap_buf_size);
3369 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
3370 &evchap->u.get_chap.num_entries, buf);
3372 actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3373 skb_trim(skbchap, NLMSG_ALIGN(actual_size));
3374 nlhchap->nlmsg_len = actual_size;
3376 err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
3378 } while (err < 0 && err != -ECONNREFUSED);
3381 scsi_host_put(shost);
3385 static int iscsi_set_chap(struct iscsi_transport *transport,
3386 struct iscsi_uevent *ev, uint32_t len)
3388 char *data = (char *)ev + sizeof(*ev);
3389 struct Scsi_Host *shost;
3392 if (!transport->set_chap)
3395 shost = scsi_host_lookup(ev->u.set_path.host_no);
3397 pr_err("%s could not find host no %u\n",
3398 __func__, ev->u.set_path.host_no);
3402 err = transport->set_chap(shost, data, len);
3403 scsi_host_put(shost);
3407 static int iscsi_delete_chap(struct iscsi_transport *transport,
3408 struct iscsi_uevent *ev)
3410 struct Scsi_Host *shost;
3413 if (!transport->delete_chap)
3416 shost = scsi_host_lookup(ev->u.delete_chap.host_no);
3418 printk(KERN_ERR "%s could not find host no %u\n",
3419 __func__, ev->u.delete_chap.host_no);
3423 err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
3424 scsi_host_put(shost);
3428 static const struct {
3429 enum iscsi_discovery_parent_type value;
3431 } iscsi_discovery_parent_names[] = {
3432 {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
3433 {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
3434 {ISCSI_DISC_PARENT_ISNS, "isns" },
3437 char *iscsi_get_discovery_parent_name(int parent_type)
3440 char *state = "Unknown!";
3442 for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
3443 if (iscsi_discovery_parent_names[i].value & parent_type) {
3444 state = iscsi_discovery_parent_names[i].name;
3450 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
3452 static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
3453 struct iscsi_uevent *ev, uint32_t len)
3455 char *data = (char *)ev + sizeof(*ev);
3456 struct Scsi_Host *shost;
3457 struct iscsi_bus_flash_session *fnode_sess;
3458 struct iscsi_bus_flash_conn *fnode_conn;
3463 if (!transport->set_flashnode_param) {
3465 goto exit_set_fnode;
3468 shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
3470 pr_err("%s could not find host no %u\n",
3471 __func__, ev->u.set_flashnode.host_no);
3473 goto exit_set_fnode;
3476 idx = ev->u.set_flashnode.flashnode_idx;
3477 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3479 pr_err("%s could not find flashnode %u for host no %u\n",
3480 __func__, idx, ev->u.set_flashnode.host_no);
3485 dev = iscsi_find_flashnode_conn(fnode_sess);
3491 fnode_conn = iscsi_dev_to_flash_conn(dev);
3492 err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
3496 put_device(&fnode_sess->dev);
3499 scsi_host_put(shost);
3505 static int iscsi_new_flashnode(struct iscsi_transport *transport,
3506 struct iscsi_uevent *ev, uint32_t len)
3508 char *data = (char *)ev + sizeof(*ev);
3509 struct Scsi_Host *shost;
3513 if (!transport->new_flashnode) {
3515 goto exit_new_fnode;
3518 shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
3520 pr_err("%s could not find host no %u\n",
3521 __func__, ev->u.new_flashnode.host_no);
3526 index = transport->new_flashnode(shost, data, len);
3529 ev->r.new_flashnode_ret.flashnode_idx = index;
3534 scsi_host_put(shost);
3540 static int iscsi_del_flashnode(struct iscsi_transport *transport,
3541 struct iscsi_uevent *ev)
3543 struct Scsi_Host *shost;
3544 struct iscsi_bus_flash_session *fnode_sess;
3548 if (!transport->del_flashnode) {
3550 goto exit_del_fnode;
3553 shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
3555 pr_err("%s could not find host no %u\n",
3556 __func__, ev->u.del_flashnode.host_no);
3561 idx = ev->u.del_flashnode.flashnode_idx;
3562 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3564 pr_err("%s could not find flashnode %u for host no %u\n",
3565 __func__, idx, ev->u.del_flashnode.host_no);
3570 err = transport->del_flashnode(fnode_sess);
3571 put_device(&fnode_sess->dev);
3574 scsi_host_put(shost);
3580 static int iscsi_login_flashnode(struct iscsi_transport *transport,
3581 struct iscsi_uevent *ev)
3583 struct Scsi_Host *shost;
3584 struct iscsi_bus_flash_session *fnode_sess;
3585 struct iscsi_bus_flash_conn *fnode_conn;
3590 if (!transport->login_flashnode) {
3592 goto exit_login_fnode;
3595 shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
3597 pr_err("%s could not find host no %u\n",
3598 __func__, ev->u.login_flashnode.host_no);
3603 idx = ev->u.login_flashnode.flashnode_idx;
3604 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3606 pr_err("%s could not find flashnode %u for host no %u\n",
3607 __func__, idx, ev->u.login_flashnode.host_no);
3612 dev = iscsi_find_flashnode_conn(fnode_sess);
3618 fnode_conn = iscsi_dev_to_flash_conn(dev);
3619 err = transport->login_flashnode(fnode_sess, fnode_conn);
3623 put_device(&fnode_sess->dev);
3626 scsi_host_put(shost);
3632 static int iscsi_logout_flashnode(struct iscsi_transport *transport,
3633 struct iscsi_uevent *ev)
3635 struct Scsi_Host *shost;
3636 struct iscsi_bus_flash_session *fnode_sess;
3637 struct iscsi_bus_flash_conn *fnode_conn;
3642 if (!transport->logout_flashnode) {
3644 goto exit_logout_fnode;
3647 shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
3649 pr_err("%s could not find host no %u\n",
3650 __func__, ev->u.logout_flashnode.host_no);
3655 idx = ev->u.logout_flashnode.flashnode_idx;
3656 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3658 pr_err("%s could not find flashnode %u for host no %u\n",
3659 __func__, idx, ev->u.logout_flashnode.host_no);
3664 dev = iscsi_find_flashnode_conn(fnode_sess);
3670 fnode_conn = iscsi_dev_to_flash_conn(dev);
3672 err = transport->logout_flashnode(fnode_sess, fnode_conn);
3676 put_device(&fnode_sess->dev);
3679 scsi_host_put(shost);
3685 static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
3686 struct iscsi_uevent *ev)
3688 struct Scsi_Host *shost;
3689 struct iscsi_cls_session *session;
3692 if (!transport->logout_flashnode_sid) {
3694 goto exit_logout_sid;
3697 shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
3699 pr_err("%s could not find host no %u\n",
3700 __func__, ev->u.logout_flashnode.host_no);
3705 session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
3707 pr_err("%s could not find session id %u\n",
3708 __func__, ev->u.logout_flashnode_sid.sid);
3713 err = transport->logout_flashnode_sid(session);
3716 scsi_host_put(shost);
3723 iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3725 struct iscsi_uevent *ev = nlmsg_data(nlh);
3726 struct Scsi_Host *shost = NULL;
3727 struct iscsi_internal *priv;
3728 struct sk_buff *skbhost_stats;
3729 struct nlmsghdr *nlhhost_stats;
3730 struct iscsi_uevent *evhost_stats;
3731 int host_stats_size = 0;
3735 if (!transport->get_host_stats)
3738 priv = iscsi_if_transport_lookup(transport);
3742 host_stats_size = sizeof(struct iscsi_offload_host_stats);
3743 len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3745 shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
3747 pr_err("%s: failed. Could not find host no %u\n",
3748 __func__, ev->u.get_host_stats.host_no);
3755 skbhost_stats = alloc_skb(len, GFP_KERNEL);
3756 if (!skbhost_stats) {
3757 pr_err("cannot deliver host stats: OOM\n");
3759 goto exit_host_stats;
3762 nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
3763 (len - sizeof(*nlhhost_stats)), 0);
3764 evhost_stats = nlmsg_data(nlhhost_stats);
3765 memset(evhost_stats, 0, sizeof(*evhost_stats));
3766 evhost_stats->transport_handle = iscsi_handle(transport);
3767 evhost_stats->type = nlh->nlmsg_type;
3768 evhost_stats->u.get_host_stats.host_no =
3769 ev->u.get_host_stats.host_no;
3770 buf = (char *)evhost_stats + sizeof(*evhost_stats);
3771 memset(buf, 0, host_stats_size);
3773 err = transport->get_host_stats(shost, buf, host_stats_size);
3775 kfree_skb(skbhost_stats);
3776 goto exit_host_stats;
3779 actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3780 skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
3781 nlhhost_stats->nlmsg_len = actual_size;
3783 err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
3785 } while (err < 0 && err != -ECONNREFUSED);
3788 scsi_host_put(shost);
3792 static int iscsi_if_transport_conn(struct iscsi_transport *transport,
3793 struct nlmsghdr *nlh)
3795 struct iscsi_uevent *ev = nlmsg_data(nlh);
3796 struct iscsi_cls_session *session;
3797 struct iscsi_cls_conn *conn = NULL;
3798 struct iscsi_endpoint *ep;
3802 switch (nlh->nlmsg_type) {
3803 case ISCSI_UEVENT_CREATE_CONN:
3804 return iscsi_if_create_conn(transport, ev);
3805 case ISCSI_UEVENT_DESTROY_CONN:
3806 return iscsi_if_destroy_conn(transport, ev);
3807 case ISCSI_UEVENT_STOP_CONN:
3808 conn = iscsi_conn_lookup(ev->u.stop_conn.sid,
3809 ev->u.stop_conn.cid);
3813 return iscsi_if_stop_conn(conn, ev->u.stop_conn.flag);
3817 * The following cmds need to be run under the ep_mutex so in kernel
3818 * conn cleanup (ep_disconnect + unbind and conn) is not done while
3819 * these are running. They also must not run if we have just run a conn
3820 * cleanup because they would set the state in a way that might allow
3821 * IO or send IO themselves.
3823 switch (nlh->nlmsg_type) {
3824 case ISCSI_UEVENT_START_CONN:
3825 conn = iscsi_conn_lookup(ev->u.start_conn.sid,
3826 ev->u.start_conn.cid);
3828 case ISCSI_UEVENT_BIND_CONN:
3829 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
3831 case ISCSI_UEVENT_SEND_PDU:
3832 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
3839 mutex_lock(&conn->ep_mutex);
3840 spin_lock_irq(&conn->lock);
3841 if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
3842 spin_unlock_irq(&conn->lock);
3843 mutex_unlock(&conn->ep_mutex);
3844 ev->r.retcode = -ENOTCONN;
3847 spin_unlock_irq(&conn->lock);
3849 switch (nlh->nlmsg_type) {
3850 case ISCSI_UEVENT_BIND_CONN:
3851 session = iscsi_session_lookup(ev->u.b_conn.sid);
3857 ev->r.retcode = transport->bind_conn(session, conn,
3858 ev->u.b_conn.transport_eph,
3859 ev->u.b_conn.is_leading);
3861 WRITE_ONCE(conn->state, ISCSI_CONN_BOUND);
3863 if (ev->r.retcode || !transport->ep_connect)
3866 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
3870 iscsi_put_endpoint(ep);
3873 iscsi_cls_conn_printk(KERN_ERR, conn,
3874 "Could not set ep conn binding\n");
3877 case ISCSI_UEVENT_START_CONN:
3878 ev->r.retcode = transport->start_conn(conn);
3880 WRITE_ONCE(conn->state, ISCSI_CONN_UP);
3883 case ISCSI_UEVENT_SEND_PDU:
3884 pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
3886 if ((ev->u.send_pdu.hdr_size > pdu_len) ||
3887 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
3892 ev->r.retcode = transport->send_pdu(conn,
3893 (struct iscsi_hdr *)((char *)ev + sizeof(*ev)),
3894 (char *)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
3895 ev->u.send_pdu.data_size);
3901 mutex_unlock(&conn->ep_mutex);
3906 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
3910 struct iscsi_uevent *ev = nlmsg_data(nlh);
3911 struct iscsi_transport *transport = NULL;
3912 struct iscsi_internal *priv;
3913 struct iscsi_cls_session *session;
3914 struct iscsi_endpoint *ep = NULL;
3916 if (!netlink_capable(skb, CAP_SYS_ADMIN))
3919 if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
3920 *group = ISCSI_NL_GRP_UIP;
3922 *group = ISCSI_NL_GRP_ISCSID;
3924 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
3927 transport = priv->iscsi_transport;
3929 if (!try_module_get(transport->owner))
3932 portid = NETLINK_CB(skb).portid;
3934 switch (nlh->nlmsg_type) {
3935 case ISCSI_UEVENT_CREATE_SESSION:
3936 err = iscsi_if_create_session(priv, ep, ev,
3938 ev->u.c_session.initial_cmdsn,
3939 ev->u.c_session.cmds_max,
3940 ev->u.c_session.queue_depth);
3942 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
3943 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
3949 err = iscsi_if_create_session(priv, ep, ev,
3951 ev->u.c_bound_session.initial_cmdsn,
3952 ev->u.c_bound_session.cmds_max,
3953 ev->u.c_bound_session.queue_depth);
3954 iscsi_put_endpoint(ep);
3956 case ISCSI_UEVENT_DESTROY_SESSION:
3957 session = iscsi_session_lookup(ev->u.d_session.sid);
3960 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3963 transport->destroy_session(session);
3965 case ISCSI_UEVENT_DESTROY_SESSION_ASYNC:
3966 session = iscsi_session_lookup(ev->u.d_session.sid);
3969 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3972 unsigned long flags;
3974 /* Prevent this session from being found again */
3975 spin_lock_irqsave(&sesslock, flags);
3976 list_del_init(&session->sess_list);
3977 spin_unlock_irqrestore(&sesslock, flags);
3979 queue_work(system_unbound_wq, &session->destroy_work);
3982 case ISCSI_UEVENT_UNBIND_SESSION:
3983 session = iscsi_session_lookup(ev->u.d_session.sid);
3985 scsi_queue_work(iscsi_session_to_shost(session),
3986 &session->unbind_work);
3990 case ISCSI_UEVENT_SET_PARAM:
3991 err = iscsi_set_param(transport, ev);
3993 case ISCSI_UEVENT_CREATE_CONN:
3994 case ISCSI_UEVENT_DESTROY_CONN:
3995 case ISCSI_UEVENT_STOP_CONN:
3996 case ISCSI_UEVENT_START_CONN:
3997 case ISCSI_UEVENT_BIND_CONN:
3998 case ISCSI_UEVENT_SEND_PDU:
3999 err = iscsi_if_transport_conn(transport, nlh);
4001 case ISCSI_UEVENT_GET_STATS:
4002 err = iscsi_if_get_stats(transport, nlh);
4004 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
4005 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
4006 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
4007 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
4008 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
4010 case ISCSI_UEVENT_TGT_DSCVR:
4011 err = iscsi_tgt_dscvr(transport, ev);
4013 case ISCSI_UEVENT_SET_HOST_PARAM:
4014 err = iscsi_set_host_param(transport, ev);
4016 case ISCSI_UEVENT_PATH_UPDATE:
4017 err = iscsi_set_path(transport, ev);
4019 case ISCSI_UEVENT_SET_IFACE_PARAMS:
4020 err = iscsi_set_iface_params(transport, ev,
4021 nlmsg_attrlen(nlh, sizeof(*ev)));
4023 case ISCSI_UEVENT_PING:
4024 err = iscsi_send_ping(transport, ev);
4026 case ISCSI_UEVENT_GET_CHAP:
4027 err = iscsi_get_chap(transport, nlh);
4029 case ISCSI_UEVENT_DELETE_CHAP:
4030 err = iscsi_delete_chap(transport, ev);
4032 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
4033 err = iscsi_set_flashnode_param(transport, ev,
4037 case ISCSI_UEVENT_NEW_FLASHNODE:
4038 err = iscsi_new_flashnode(transport, ev,
4039 nlmsg_attrlen(nlh, sizeof(*ev)));
4041 case ISCSI_UEVENT_DEL_FLASHNODE:
4042 err = iscsi_del_flashnode(transport, ev);
4044 case ISCSI_UEVENT_LOGIN_FLASHNODE:
4045 err = iscsi_login_flashnode(transport, ev);
4047 case ISCSI_UEVENT_LOGOUT_FLASHNODE:
4048 err = iscsi_logout_flashnode(transport, ev);
4050 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
4051 err = iscsi_logout_flashnode_sid(transport, ev);
4053 case ISCSI_UEVENT_SET_CHAP:
4054 err = iscsi_set_chap(transport, ev,
4055 nlmsg_attrlen(nlh, sizeof(*ev)));
4057 case ISCSI_UEVENT_GET_HOST_STATS:
4058 err = iscsi_get_host_stats(transport, nlh);
4065 module_put(transport->owner);
4070 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
4071 * Malformed skbs with wrong lengths or invalid creds are not processed.
4074 iscsi_if_rx(struct sk_buff *skb)
4076 u32 portid = NETLINK_CB(skb).portid;
4078 mutex_lock(&rx_queue_mutex);
4079 while (skb->len >= NLMSG_HDRLEN) {
4082 struct nlmsghdr *nlh;
4083 struct iscsi_uevent *ev;
4085 int retries = ISCSI_SEND_MAX_ALLOWED;
4087 nlh = nlmsg_hdr(skb);
4088 if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
4089 skb->len < nlh->nlmsg_len) {
4093 ev = nlmsg_data(nlh);
4094 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
4095 if (rlen > skb->len)
4098 err = iscsi_if_recv_msg(skb, nlh, &group);
4100 ev->type = ISCSI_KEVENT_IF_ERROR;
4105 * special case for GET_STATS:
4106 * on success - sending reply and stats from
4107 * inside of if_recv_msg(),
4108 * on error - fall through.
4110 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
4112 if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
4114 err = iscsi_if_send_reply(portid, nlh->nlmsg_type,
4116 if (err == -EAGAIN && --retries < 0) {
4117 printk(KERN_WARNING "Send reply failed, error %d\n", err);
4120 } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
4121 skb_pull(skb, rlen);
4123 mutex_unlock(&rx_queue_mutex);
4126 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
4127 struct device_attribute dev_attr_##_prefix##_##_name = \
4128 __ATTR(_name,_mode,_show,_store)
4131 * iSCSI connection attrs
4133 #define iscsi_conn_attr_show(param) \
4135 show_conn_param_##param(struct device *dev, \
4136 struct device_attribute *attr, char *buf) \
4138 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4139 struct iscsi_transport *t = conn->transport; \
4140 return t->get_conn_param(conn, param, buf); \
4143 #define iscsi_conn_attr(field, param) \
4144 iscsi_conn_attr_show(param) \
4145 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
4148 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
4149 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
4150 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
4151 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
4152 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
4153 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
4154 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
4155 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
4156 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
4157 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
4158 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
4159 iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
4160 iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
4161 iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
4162 iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
4163 iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
4164 iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
4165 iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
4166 iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
4167 iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
4168 iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
4169 iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
4170 iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
4171 iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
4172 iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
4173 iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
4174 iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
4175 iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
4177 static const char *const connection_state_names[] = {
4178 [ISCSI_CONN_UP] = "up",
4179 [ISCSI_CONN_DOWN] = "down",
4180 [ISCSI_CONN_FAILED] = "failed",
4181 [ISCSI_CONN_BOUND] = "bound"
4184 static ssize_t show_conn_state(struct device *dev,
4185 struct device_attribute *attr, char *buf)
4187 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent);
4188 const char *state = "unknown";
4189 int conn_state = READ_ONCE(conn->state);
4191 if (conn_state >= 0 &&
4192 conn_state < ARRAY_SIZE(connection_state_names))
4193 state = connection_state_names[conn_state];
4195 return sysfs_emit(buf, "%s\n", state);
4197 static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
4200 #define iscsi_conn_ep_attr_show(param) \
4201 static ssize_t show_conn_ep_param_##param(struct device *dev, \
4202 struct device_attribute *attr,\
4205 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4206 struct iscsi_transport *t = conn->transport; \
4207 struct iscsi_endpoint *ep; \
4211 * Need to make sure ep_disconnect does not free the LLD's \
4212 * interconnect resources while we are trying to read them. \
4214 mutex_lock(&conn->ep_mutex); \
4216 if (!ep && t->ep_connect) { \
4217 mutex_unlock(&conn->ep_mutex); \
4222 rc = t->get_ep_param(ep, param, buf); \
4224 rc = t->get_conn_param(conn, param, buf); \
4225 mutex_unlock(&conn->ep_mutex); \
4229 #define iscsi_conn_ep_attr(field, param) \
4230 iscsi_conn_ep_attr_show(param) \
4231 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
4232 show_conn_ep_param_##param, NULL);
4234 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
4235 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
4237 static struct attribute *iscsi_conn_attrs[] = {
4238 &dev_attr_conn_max_recv_dlength.attr,
4239 &dev_attr_conn_max_xmit_dlength.attr,
4240 &dev_attr_conn_header_digest.attr,
4241 &dev_attr_conn_data_digest.attr,
4242 &dev_attr_conn_ifmarker.attr,
4243 &dev_attr_conn_ofmarker.attr,
4244 &dev_attr_conn_address.attr,
4245 &dev_attr_conn_port.attr,
4246 &dev_attr_conn_exp_statsn.attr,
4247 &dev_attr_conn_persistent_address.attr,
4248 &dev_attr_conn_persistent_port.attr,
4249 &dev_attr_conn_ping_tmo.attr,
4250 &dev_attr_conn_recv_tmo.attr,
4251 &dev_attr_conn_local_port.attr,
4252 &dev_attr_conn_statsn.attr,
4253 &dev_attr_conn_keepalive_tmo.attr,
4254 &dev_attr_conn_max_segment_size.attr,
4255 &dev_attr_conn_tcp_timestamp_stat.attr,
4256 &dev_attr_conn_tcp_wsf_disable.attr,
4257 &dev_attr_conn_tcp_nagle_disable.attr,
4258 &dev_attr_conn_tcp_timer_scale.attr,
4259 &dev_attr_conn_tcp_timestamp_enable.attr,
4260 &dev_attr_conn_fragment_disable.attr,
4261 &dev_attr_conn_ipv4_tos.attr,
4262 &dev_attr_conn_ipv6_traffic_class.attr,
4263 &dev_attr_conn_ipv6_flow_label.attr,
4264 &dev_attr_conn_is_fw_assigned_ipv6.attr,
4265 &dev_attr_conn_tcp_xmit_wsf.attr,
4266 &dev_attr_conn_tcp_recv_wsf.attr,
4267 &dev_attr_conn_local_ipaddr.attr,
4268 &dev_attr_conn_state.attr,
4272 static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
4273 struct attribute *attr, int i)
4275 struct device *cdev = container_of(kobj, struct device, kobj);
4276 struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
4277 struct iscsi_transport *t = conn->transport;
4280 if (attr == &dev_attr_conn_max_recv_dlength.attr)
4281 param = ISCSI_PARAM_MAX_RECV_DLENGTH;
4282 else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
4283 param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
4284 else if (attr == &dev_attr_conn_header_digest.attr)
4285 param = ISCSI_PARAM_HDRDGST_EN;
4286 else if (attr == &dev_attr_conn_data_digest.attr)
4287 param = ISCSI_PARAM_DATADGST_EN;
4288 else if (attr == &dev_attr_conn_ifmarker.attr)
4289 param = ISCSI_PARAM_IFMARKER_EN;
4290 else if (attr == &dev_attr_conn_ofmarker.attr)
4291 param = ISCSI_PARAM_OFMARKER_EN;
4292 else if (attr == &dev_attr_conn_address.attr)
4293 param = ISCSI_PARAM_CONN_ADDRESS;
4294 else if (attr == &dev_attr_conn_port.attr)
4295 param = ISCSI_PARAM_CONN_PORT;
4296 else if (attr == &dev_attr_conn_exp_statsn.attr)
4297 param = ISCSI_PARAM_EXP_STATSN;
4298 else if (attr == &dev_attr_conn_persistent_address.attr)
4299 param = ISCSI_PARAM_PERSISTENT_ADDRESS;
4300 else if (attr == &dev_attr_conn_persistent_port.attr)
4301 param = ISCSI_PARAM_PERSISTENT_PORT;
4302 else if (attr == &dev_attr_conn_ping_tmo.attr)
4303 param = ISCSI_PARAM_PING_TMO;
4304 else if (attr == &dev_attr_conn_recv_tmo.attr)
4305 param = ISCSI_PARAM_RECV_TMO;
4306 else if (attr == &dev_attr_conn_local_port.attr)
4307 param = ISCSI_PARAM_LOCAL_PORT;
4308 else if (attr == &dev_attr_conn_statsn.attr)
4309 param = ISCSI_PARAM_STATSN;
4310 else if (attr == &dev_attr_conn_keepalive_tmo.attr)
4311 param = ISCSI_PARAM_KEEPALIVE_TMO;
4312 else if (attr == &dev_attr_conn_max_segment_size.attr)
4313 param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
4314 else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
4315 param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
4316 else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
4317 param = ISCSI_PARAM_TCP_WSF_DISABLE;
4318 else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
4319 param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
4320 else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
4321 param = ISCSI_PARAM_TCP_TIMER_SCALE;
4322 else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
4323 param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
4324 else if (attr == &dev_attr_conn_fragment_disable.attr)
4325 param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
4326 else if (attr == &dev_attr_conn_ipv4_tos.attr)
4327 param = ISCSI_PARAM_IPV4_TOS;
4328 else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
4329 param = ISCSI_PARAM_IPV6_TC;
4330 else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
4331 param = ISCSI_PARAM_IPV6_FLOW_LABEL;
4332 else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
4333 param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
4334 else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
4335 param = ISCSI_PARAM_TCP_XMIT_WSF;
4336 else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
4337 param = ISCSI_PARAM_TCP_RECV_WSF;
4338 else if (attr == &dev_attr_conn_local_ipaddr.attr)
4339 param = ISCSI_PARAM_LOCAL_IPADDR;
4340 else if (attr == &dev_attr_conn_state.attr)
4343 WARN_ONCE(1, "Invalid conn attr");
4347 return t->attr_is_visible(ISCSI_PARAM, param);
4350 static struct attribute_group iscsi_conn_group = {
4351 .attrs = iscsi_conn_attrs,
4352 .is_visible = iscsi_conn_attr_is_visible,
4356 * iSCSI session attrs
4358 #define iscsi_session_attr_show(param, perm) \
4360 show_session_param_##param(struct device *dev, \
4361 struct device_attribute *attr, char *buf) \
4363 struct iscsi_cls_session *session = \
4364 iscsi_dev_to_session(dev->parent); \
4365 struct iscsi_transport *t = session->transport; \
4367 if (perm && !capable(CAP_SYS_ADMIN)) \
4369 return t->get_session_param(session, param, buf); \
4372 #define iscsi_session_attr(field, param, perm) \
4373 iscsi_session_attr_show(param, perm) \
4374 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
4376 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
4377 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
4378 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
4379 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
4380 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
4381 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
4382 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
4383 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
4384 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
4385 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
4386 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
4387 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
4388 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
4389 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
4390 iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
4391 iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
4392 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
4393 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
4394 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
4395 iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
4396 iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
4397 iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
4398 iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
4399 iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
4400 iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
4401 iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
4402 iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
4403 iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
4404 iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
4405 iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
4406 iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
4407 iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
4408 iscsi_session_attr(discovery_auth_optional,
4409 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
4410 iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
4411 iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
4412 iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
4413 iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
4414 iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
4415 iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
4416 iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
4419 show_priv_session_target_state(struct device *dev, struct device_attribute *attr,
4422 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4424 return sysfs_emit(buf, "%s\n",
4425 iscsi_session_target_state_name[session->target_state]);
4428 static ISCSI_CLASS_ATTR(priv_sess, target_state, S_IRUGO,
4429 show_priv_session_target_state, NULL);
4432 show_priv_session_state(struct device *dev, struct device_attribute *attr,
4435 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4436 return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
4438 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
4441 show_priv_session_creator(struct device *dev, struct device_attribute *attr,
4444 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4445 return sysfs_emit(buf, "%d\n", session->creator);
4447 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
4450 show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
4453 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4454 return sysfs_emit(buf, "%d\n", session->target_id);
4456 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
4457 show_priv_session_target_id, NULL);
4459 #define iscsi_priv_session_attr_show(field, format) \
4461 show_priv_session_##field(struct device *dev, \
4462 struct device_attribute *attr, char *buf) \
4464 struct iscsi_cls_session *session = \
4465 iscsi_dev_to_session(dev->parent); \
4466 if (session->field == -1) \
4467 return sysfs_emit(buf, "off\n"); \
4468 return sysfs_emit(buf, format"\n", session->field); \
4471 #define iscsi_priv_session_attr_store(field) \
4473 store_priv_session_##field(struct device *dev, \
4474 struct device_attribute *attr, \
4475 const char *buf, size_t count) \
4479 struct iscsi_cls_session *session = \
4480 iscsi_dev_to_session(dev->parent); \
4481 if ((session->state == ISCSI_SESSION_FREE) || \
4482 (session->state == ISCSI_SESSION_FAILED)) \
4484 if (strncmp(buf, "off", 3) == 0) { \
4485 session->field = -1; \
4486 session->field##_sysfs_override = true; \
4488 val = simple_strtoul(buf, &cp, 0); \
4489 if (*cp != '\0' && *cp != '\n') \
4491 session->field = val; \
4492 session->field##_sysfs_override = true; \
4497 #define iscsi_priv_session_rw_attr(field, format) \
4498 iscsi_priv_session_attr_show(field, format) \
4499 iscsi_priv_session_attr_store(field) \
4500 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
4501 show_priv_session_##field, \
4502 store_priv_session_##field)
4504 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
4506 static struct attribute *iscsi_session_attrs[] = {
4507 &dev_attr_sess_initial_r2t.attr,
4508 &dev_attr_sess_max_outstanding_r2t.attr,
4509 &dev_attr_sess_immediate_data.attr,
4510 &dev_attr_sess_first_burst_len.attr,
4511 &dev_attr_sess_max_burst_len.attr,
4512 &dev_attr_sess_data_pdu_in_order.attr,
4513 &dev_attr_sess_data_seq_in_order.attr,
4514 &dev_attr_sess_erl.attr,
4515 &dev_attr_sess_targetname.attr,
4516 &dev_attr_sess_tpgt.attr,
4517 &dev_attr_sess_password.attr,
4518 &dev_attr_sess_password_in.attr,
4519 &dev_attr_sess_username.attr,
4520 &dev_attr_sess_username_in.attr,
4521 &dev_attr_sess_fast_abort.attr,
4522 &dev_attr_sess_abort_tmo.attr,
4523 &dev_attr_sess_lu_reset_tmo.attr,
4524 &dev_attr_sess_tgt_reset_tmo.attr,
4525 &dev_attr_sess_ifacename.attr,
4526 &dev_attr_sess_initiatorname.attr,
4527 &dev_attr_sess_targetalias.attr,
4528 &dev_attr_sess_boot_root.attr,
4529 &dev_attr_sess_boot_nic.attr,
4530 &dev_attr_sess_boot_target.attr,
4531 &dev_attr_priv_sess_recovery_tmo.attr,
4532 &dev_attr_priv_sess_state.attr,
4533 &dev_attr_priv_sess_target_state.attr,
4534 &dev_attr_priv_sess_creator.attr,
4535 &dev_attr_sess_chap_out_idx.attr,
4536 &dev_attr_sess_chap_in_idx.attr,
4537 &dev_attr_priv_sess_target_id.attr,
4538 &dev_attr_sess_auto_snd_tgt_disable.attr,
4539 &dev_attr_sess_discovery_session.attr,
4540 &dev_attr_sess_portal_type.attr,
4541 &dev_attr_sess_chap_auth.attr,
4542 &dev_attr_sess_discovery_logout.attr,
4543 &dev_attr_sess_bidi_chap.attr,
4544 &dev_attr_sess_discovery_auth_optional.attr,
4545 &dev_attr_sess_def_time2wait.attr,
4546 &dev_attr_sess_def_time2retain.attr,
4547 &dev_attr_sess_isid.attr,
4548 &dev_attr_sess_tsid.attr,
4549 &dev_attr_sess_def_taskmgmt_tmo.attr,
4550 &dev_attr_sess_discovery_parent_idx.attr,
4551 &dev_attr_sess_discovery_parent_type.attr,
4555 static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
4556 struct attribute *attr, int i)
4558 struct device *cdev = container_of(kobj, struct device, kobj);
4559 struct iscsi_cls_session *session = transport_class_to_session(cdev);
4560 struct iscsi_transport *t = session->transport;
4563 if (attr == &dev_attr_sess_initial_r2t.attr)
4564 param = ISCSI_PARAM_INITIAL_R2T_EN;
4565 else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
4566 param = ISCSI_PARAM_MAX_R2T;
4567 else if (attr == &dev_attr_sess_immediate_data.attr)
4568 param = ISCSI_PARAM_IMM_DATA_EN;
4569 else if (attr == &dev_attr_sess_first_burst_len.attr)
4570 param = ISCSI_PARAM_FIRST_BURST;
4571 else if (attr == &dev_attr_sess_max_burst_len.attr)
4572 param = ISCSI_PARAM_MAX_BURST;
4573 else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
4574 param = ISCSI_PARAM_PDU_INORDER_EN;
4575 else if (attr == &dev_attr_sess_data_seq_in_order.attr)
4576 param = ISCSI_PARAM_DATASEQ_INORDER_EN;
4577 else if (attr == &dev_attr_sess_erl.attr)
4578 param = ISCSI_PARAM_ERL;
4579 else if (attr == &dev_attr_sess_targetname.attr)
4580 param = ISCSI_PARAM_TARGET_NAME;
4581 else if (attr == &dev_attr_sess_tpgt.attr)
4582 param = ISCSI_PARAM_TPGT;
4583 else if (attr == &dev_attr_sess_chap_in_idx.attr)
4584 param = ISCSI_PARAM_CHAP_IN_IDX;
4585 else if (attr == &dev_attr_sess_chap_out_idx.attr)
4586 param = ISCSI_PARAM_CHAP_OUT_IDX;
4587 else if (attr == &dev_attr_sess_password.attr)
4588 param = ISCSI_PARAM_USERNAME;
4589 else if (attr == &dev_attr_sess_password_in.attr)
4590 param = ISCSI_PARAM_USERNAME_IN;
4591 else if (attr == &dev_attr_sess_username.attr)
4592 param = ISCSI_PARAM_PASSWORD;
4593 else if (attr == &dev_attr_sess_username_in.attr)
4594 param = ISCSI_PARAM_PASSWORD_IN;
4595 else if (attr == &dev_attr_sess_fast_abort.attr)
4596 param = ISCSI_PARAM_FAST_ABORT;
4597 else if (attr == &dev_attr_sess_abort_tmo.attr)
4598 param = ISCSI_PARAM_ABORT_TMO;
4599 else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
4600 param = ISCSI_PARAM_LU_RESET_TMO;
4601 else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
4602 param = ISCSI_PARAM_TGT_RESET_TMO;
4603 else if (attr == &dev_attr_sess_ifacename.attr)
4604 param = ISCSI_PARAM_IFACE_NAME;
4605 else if (attr == &dev_attr_sess_initiatorname.attr)
4606 param = ISCSI_PARAM_INITIATOR_NAME;
4607 else if (attr == &dev_attr_sess_targetalias.attr)
4608 param = ISCSI_PARAM_TARGET_ALIAS;
4609 else if (attr == &dev_attr_sess_boot_root.attr)
4610 param = ISCSI_PARAM_BOOT_ROOT;
4611 else if (attr == &dev_attr_sess_boot_nic.attr)
4612 param = ISCSI_PARAM_BOOT_NIC;
4613 else if (attr == &dev_attr_sess_boot_target.attr)
4614 param = ISCSI_PARAM_BOOT_TARGET;
4615 else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
4616 param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
4617 else if (attr == &dev_attr_sess_discovery_session.attr)
4618 param = ISCSI_PARAM_DISCOVERY_SESS;
4619 else if (attr == &dev_attr_sess_portal_type.attr)
4620 param = ISCSI_PARAM_PORTAL_TYPE;
4621 else if (attr == &dev_attr_sess_chap_auth.attr)
4622 param = ISCSI_PARAM_CHAP_AUTH_EN;
4623 else if (attr == &dev_attr_sess_discovery_logout.attr)
4624 param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
4625 else if (attr == &dev_attr_sess_bidi_chap.attr)
4626 param = ISCSI_PARAM_BIDI_CHAP_EN;
4627 else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
4628 param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
4629 else if (attr == &dev_attr_sess_def_time2wait.attr)
4630 param = ISCSI_PARAM_DEF_TIME2WAIT;
4631 else if (attr == &dev_attr_sess_def_time2retain.attr)
4632 param = ISCSI_PARAM_DEF_TIME2RETAIN;
4633 else if (attr == &dev_attr_sess_isid.attr)
4634 param = ISCSI_PARAM_ISID;
4635 else if (attr == &dev_attr_sess_tsid.attr)
4636 param = ISCSI_PARAM_TSID;
4637 else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
4638 param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
4639 else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
4640 param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
4641 else if (attr == &dev_attr_sess_discovery_parent_type.attr)
4642 param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
4643 else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
4644 return S_IRUGO | S_IWUSR;
4645 else if (attr == &dev_attr_priv_sess_state.attr)
4647 else if (attr == &dev_attr_priv_sess_target_state.attr)
4649 else if (attr == &dev_attr_priv_sess_creator.attr)
4651 else if (attr == &dev_attr_priv_sess_target_id.attr)
4654 WARN_ONCE(1, "Invalid session attr");
4658 return t->attr_is_visible(ISCSI_PARAM, param);
4661 static struct attribute_group iscsi_session_group = {
4662 .attrs = iscsi_session_attrs,
4663 .is_visible = iscsi_session_attr_is_visible,
4669 #define iscsi_host_attr_show(param) \
4671 show_host_param_##param(struct device *dev, \
4672 struct device_attribute *attr, char *buf) \
4674 struct Scsi_Host *shost = transport_class_to_shost(dev); \
4675 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
4676 return priv->iscsi_transport->get_host_param(shost, param, buf); \
4679 #define iscsi_host_attr(field, param) \
4680 iscsi_host_attr_show(param) \
4681 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
4684 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
4685 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
4686 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
4687 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
4688 iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
4689 iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
4691 static struct attribute *iscsi_host_attrs[] = {
4692 &dev_attr_host_netdev.attr,
4693 &dev_attr_host_hwaddress.attr,
4694 &dev_attr_host_ipaddress.attr,
4695 &dev_attr_host_initiatorname.attr,
4696 &dev_attr_host_port_state.attr,
4697 &dev_attr_host_port_speed.attr,
4701 static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
4702 struct attribute *attr, int i)
4704 struct device *cdev = container_of(kobj, struct device, kobj);
4705 struct Scsi_Host *shost = transport_class_to_shost(cdev);
4706 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
4709 if (attr == &dev_attr_host_netdev.attr)
4710 param = ISCSI_HOST_PARAM_NETDEV_NAME;
4711 else if (attr == &dev_attr_host_hwaddress.attr)
4712 param = ISCSI_HOST_PARAM_HWADDRESS;
4713 else if (attr == &dev_attr_host_ipaddress.attr)
4714 param = ISCSI_HOST_PARAM_IPADDRESS;
4715 else if (attr == &dev_attr_host_initiatorname.attr)
4716 param = ISCSI_HOST_PARAM_INITIATOR_NAME;
4717 else if (attr == &dev_attr_host_port_state.attr)
4718 param = ISCSI_HOST_PARAM_PORT_STATE;
4719 else if (attr == &dev_attr_host_port_speed.attr)
4720 param = ISCSI_HOST_PARAM_PORT_SPEED;
4722 WARN_ONCE(1, "Invalid host attr");
4726 return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
4729 static struct attribute_group iscsi_host_group = {
4730 .attrs = iscsi_host_attrs,
4731 .is_visible = iscsi_host_attr_is_visible,
4734 /* convert iscsi_port_speed values to ascii string name */
4735 static const struct {
4736 enum iscsi_port_speed value;
4738 } iscsi_port_speed_names[] = {
4739 {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
4740 {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
4741 {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
4742 {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
4743 {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
4744 {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" },
4745 {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" },
4748 char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
4751 char *speed = "Unknown!";
4752 struct iscsi_cls_host *ihost = shost->shost_data;
4753 uint32_t port_speed = ihost->port_speed;
4755 for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
4756 if (iscsi_port_speed_names[i].value & port_speed) {
4757 speed = iscsi_port_speed_names[i].name;
4763 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
4765 /* convert iscsi_port_state values to ascii string name */
4766 static const struct {
4767 enum iscsi_port_state value;
4769 } iscsi_port_state_names[] = {
4770 {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
4771 {ISCSI_PORT_STATE_UP, "LINK UP" },
4774 char *iscsi_get_port_state_name(struct Scsi_Host *shost)
4777 char *state = "Unknown!";
4778 struct iscsi_cls_host *ihost = shost->shost_data;
4779 uint32_t port_state = ihost->port_state;
4781 for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
4782 if (iscsi_port_state_names[i].value & port_state) {
4783 state = iscsi_port_state_names[i].name;
4789 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
4791 static int iscsi_session_match(struct attribute_container *cont,
4794 struct iscsi_cls_session *session;
4795 struct Scsi_Host *shost;
4796 struct iscsi_internal *priv;
4798 if (!iscsi_is_session_dev(dev))
4801 session = iscsi_dev_to_session(dev);
4802 shost = iscsi_session_to_shost(session);
4803 if (!shost->transportt)
4806 priv = to_iscsi_internal(shost->transportt);
4807 if (priv->session_cont.ac.class != &iscsi_session_class.class)
4810 return &priv->session_cont.ac == cont;
4813 static int iscsi_conn_match(struct attribute_container *cont,
4816 struct iscsi_cls_session *session;
4817 struct iscsi_cls_conn *conn;
4818 struct Scsi_Host *shost;
4819 struct iscsi_internal *priv;
4821 if (!iscsi_is_conn_dev(dev))
4824 conn = iscsi_dev_to_conn(dev);
4825 session = iscsi_dev_to_session(conn->dev.parent);
4826 shost = iscsi_session_to_shost(session);
4828 if (!shost->transportt)
4831 priv = to_iscsi_internal(shost->transportt);
4832 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
4835 return &priv->conn_cont.ac == cont;
4838 static int iscsi_host_match(struct attribute_container *cont,
4841 struct Scsi_Host *shost;
4842 struct iscsi_internal *priv;
4844 if (!scsi_is_host_device(dev))
4847 shost = dev_to_shost(dev);
4848 if (!shost->transportt ||
4849 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
4852 priv = to_iscsi_internal(shost->transportt);
4853 return &priv->t.host_attrs.ac == cont;
4856 struct scsi_transport_template *
4857 iscsi_register_transport(struct iscsi_transport *tt)
4859 struct iscsi_internal *priv;
4860 unsigned long flags;
4864 WARN_ON(tt->ep_disconnect && !tt->unbind_conn);
4866 priv = iscsi_if_transport_lookup(tt);
4870 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
4873 INIT_LIST_HEAD(&priv->list);
4874 priv->iscsi_transport = tt;
4875 priv->t.user_scan = iscsi_user_scan;
4876 priv->t.create_work_queue = 1;
4878 priv->dev.class = &iscsi_transport_class;
4879 dev_set_name(&priv->dev, "%s", tt->name);
4880 err = device_register(&priv->dev);
4884 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
4886 goto unregister_dev;
4888 /* host parameters */
4889 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
4890 priv->t.host_attrs.ac.match = iscsi_host_match;
4891 priv->t.host_attrs.ac.grp = &iscsi_host_group;
4892 priv->t.host_size = sizeof(struct iscsi_cls_host);
4893 transport_container_register(&priv->t.host_attrs);
4895 /* connection parameters */
4896 priv->conn_cont.ac.class = &iscsi_connection_class.class;
4897 priv->conn_cont.ac.match = iscsi_conn_match;
4898 priv->conn_cont.ac.grp = &iscsi_conn_group;
4899 transport_container_register(&priv->conn_cont);
4901 /* session parameters */
4902 priv->session_cont.ac.class = &iscsi_session_class.class;
4903 priv->session_cont.ac.match = iscsi_session_match;
4904 priv->session_cont.ac.grp = &iscsi_session_group;
4905 transport_container_register(&priv->session_cont);
4907 spin_lock_irqsave(&iscsi_transport_lock, flags);
4908 list_add(&priv->list, &iscsi_transports);
4909 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4911 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
4915 device_unregister(&priv->dev);
4918 put_device(&priv->dev);
4921 EXPORT_SYMBOL_GPL(iscsi_register_transport);
4923 int iscsi_unregister_transport(struct iscsi_transport *tt)
4925 struct iscsi_internal *priv;
4926 unsigned long flags;
4930 mutex_lock(&rx_queue_mutex);
4932 priv = iscsi_if_transport_lookup(tt);
4935 spin_lock_irqsave(&iscsi_transport_lock, flags);
4936 list_del(&priv->list);
4937 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4939 transport_container_unregister(&priv->conn_cont);
4940 transport_container_unregister(&priv->session_cont);
4941 transport_container_unregister(&priv->t.host_attrs);
4943 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
4944 device_unregister(&priv->dev);
4945 mutex_unlock(&rx_queue_mutex);
4949 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
4951 void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *),
4952 struct device *dev, const char *fmt, ...)
4954 struct va_format vaf;
4957 va_start(args, fmt);
4963 EXPORT_SYMBOL_GPL(iscsi_dbg_trace);
4965 static __init int iscsi_transport_init(void)
4968 struct netlink_kernel_cfg cfg = {
4970 .input = iscsi_if_rx,
4972 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
4973 ISCSI_TRANSPORT_VERSION);
4975 atomic_set(&iscsi_session_nr, 0);
4977 err = class_register(&iscsi_transport_class);
4981 err = class_register(&iscsi_endpoint_class);
4983 goto unregister_transport_class;
4985 err = class_register(&iscsi_iface_class);
4987 goto unregister_endpoint_class;
4989 err = transport_class_register(&iscsi_host_class);
4991 goto unregister_iface_class;
4993 err = transport_class_register(&iscsi_connection_class);
4995 goto unregister_host_class;
4997 err = transport_class_register(&iscsi_session_class);
4999 goto unregister_conn_class;
5001 err = bus_register(&iscsi_flashnode_bus);
5003 goto unregister_session_class;
5005 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
5008 goto unregister_flashnode_bus;
5011 iscsi_eh_timer_workq = alloc_workqueue("%s",
5012 WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND,
5014 if (!iscsi_eh_timer_workq) {
5019 iscsi_conn_cleanup_workq = alloc_workqueue("%s",
5020 WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND, 0,
5021 "iscsi_conn_cleanup");
5022 if (!iscsi_conn_cleanup_workq) {
5030 destroy_workqueue(iscsi_eh_timer_workq);
5032 netlink_kernel_release(nls);
5033 unregister_flashnode_bus:
5034 bus_unregister(&iscsi_flashnode_bus);
5035 unregister_session_class:
5036 transport_class_unregister(&iscsi_session_class);
5037 unregister_conn_class:
5038 transport_class_unregister(&iscsi_connection_class);
5039 unregister_host_class:
5040 transport_class_unregister(&iscsi_host_class);
5041 unregister_iface_class:
5042 class_unregister(&iscsi_iface_class);
5043 unregister_endpoint_class:
5044 class_unregister(&iscsi_endpoint_class);
5045 unregister_transport_class:
5046 class_unregister(&iscsi_transport_class);
5050 static void __exit iscsi_transport_exit(void)
5052 destroy_workqueue(iscsi_conn_cleanup_workq);
5053 destroy_workqueue(iscsi_eh_timer_workq);
5054 netlink_kernel_release(nls);
5055 bus_unregister(&iscsi_flashnode_bus);
5056 transport_class_unregister(&iscsi_connection_class);
5057 transport_class_unregister(&iscsi_session_class);
5058 transport_class_unregister(&iscsi_host_class);
5059 class_unregister(&iscsi_endpoint_class);
5060 class_unregister(&iscsi_iface_class);
5061 class_unregister(&iscsi_transport_class);
5064 module_init(iscsi_transport_init);
5065 module_exit(iscsi_transport_exit);
5067 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
5068 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
5069 "Alex Aizman <itn780@yahoo.com>");
5070 MODULE_DESCRIPTION("iSCSI Transport Interface");
5071 MODULE_LICENSE("GPL");
5072 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
5073 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);