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);
257 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
259 void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
261 sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
262 device_unregister(&ep->dev);
264 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
266 void iscsi_put_endpoint(struct iscsi_endpoint *ep)
268 put_device(&ep->dev);
270 EXPORT_SYMBOL_GPL(iscsi_put_endpoint);
273 * iscsi_lookup_endpoint - get ep from handle
274 * @handle: endpoint handle
276 * Caller must do a iscsi_put_endpoint.
278 struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
280 struct iscsi_endpoint *ep;
282 mutex_lock(&iscsi_ep_idr_mutex);
283 ep = idr_find(&iscsi_ep_idr, handle);
287 get_device(&ep->dev);
289 mutex_unlock(&iscsi_ep_idr_mutex);
292 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
295 * Interface to display network param to sysfs
298 static void iscsi_iface_release(struct device *dev)
300 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
301 struct device *parent = iface->dev.parent;
308 static struct class iscsi_iface_class = {
309 .name = "iscsi_iface",
310 .dev_release = iscsi_iface_release,
313 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
314 struct device_attribute dev_attr_##_prefix##_##_name = \
315 __ATTR(_name, _mode, _show, _store)
317 /* iface attrs show */
318 #define iscsi_iface_attr_show(type, name, param_type, param) \
320 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
323 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
324 struct iscsi_transport *t = iface->transport; \
325 return t->get_iface_param(iface, param_type, param, buf); \
328 #define iscsi_iface_net_attr(type, name, param) \
329 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
330 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
332 #define iscsi_iface_attr(type, name, param) \
333 iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \
334 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
336 /* generic read only ipv4 attribute */
337 iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
338 iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
339 iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
340 iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
341 iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en,
342 ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN);
343 iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en,
344 ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN);
345 iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN);
346 iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS);
347 iscsi_iface_net_attr(ipv4_iface, grat_arp_en,
348 ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN);
349 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en,
350 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN);
351 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id,
352 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID);
353 iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en,
354 ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN);
355 iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en,
356 ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN);
357 iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id,
358 ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID);
359 iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en,
360 ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN);
361 iscsi_iface_net_attr(ipv4_iface, fragment_disable,
362 ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE);
363 iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en,
364 ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN);
365 iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL);
367 /* generic read only ipv6 attribute */
368 iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
369 iscsi_iface_net_attr(ipv6_iface, link_local_addr,
370 ISCSI_NET_PARAM_IPV6_LINKLOCAL);
371 iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
372 iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
373 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
374 iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
375 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
376 iscsi_iface_net_attr(ipv6_iface, link_local_state,
377 ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE);
378 iscsi_iface_net_attr(ipv6_iface, router_state,
379 ISCSI_NET_PARAM_IPV6_ROUTER_STATE);
380 iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en,
381 ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN);
382 iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN);
383 iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL);
384 iscsi_iface_net_attr(ipv6_iface, traffic_class,
385 ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS);
386 iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT);
387 iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo,
388 ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO);
389 iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time,
390 ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME);
391 iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo,
392 ISCSI_NET_PARAM_IPV6_ND_STALE_TMO);
393 iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt,
394 ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT);
395 iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu,
396 ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU);
398 /* common read only iface attribute */
399 iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
400 iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
401 iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
402 iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
403 iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
404 iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
405 iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE);
406 iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN);
407 iscsi_iface_net_attr(iface, tcp_nagle_disable,
408 ISCSI_NET_PARAM_TCP_NAGLE_DISABLE);
409 iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE);
410 iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF);
411 iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE);
412 iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN);
413 iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID);
414 iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN);
416 /* common iscsi specific settings attributes */
417 iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO);
418 iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN);
419 iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN);
420 iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN);
421 iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN);
422 iscsi_iface_attr(iface, data_seq_in_order,
423 ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN);
424 iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN);
425 iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL);
426 iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH);
427 iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST);
428 iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T);
429 iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST);
430 iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN);
431 iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN);
432 iscsi_iface_attr(iface, discovery_auth_optional,
433 ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL);
434 iscsi_iface_attr(iface, discovery_logout,
435 ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN);
436 iscsi_iface_attr(iface, strict_login_comp_en,
437 ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN);
438 iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME);
440 static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
441 struct attribute *attr, int i)
443 struct device *dev = container_of(kobj, struct device, kobj);
444 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
445 struct iscsi_transport *t = iface->transport;
448 if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr)
449 param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO;
450 else if (attr == &dev_attr_iface_header_digest.attr)
451 param = ISCSI_IFACE_PARAM_HDRDGST_EN;
452 else if (attr == &dev_attr_iface_data_digest.attr)
453 param = ISCSI_IFACE_PARAM_DATADGST_EN;
454 else if (attr == &dev_attr_iface_immediate_data.attr)
455 param = ISCSI_IFACE_PARAM_IMM_DATA_EN;
456 else if (attr == &dev_attr_iface_initial_r2t.attr)
457 param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN;
458 else if (attr == &dev_attr_iface_data_seq_in_order.attr)
459 param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN;
460 else if (attr == &dev_attr_iface_data_pdu_in_order.attr)
461 param = ISCSI_IFACE_PARAM_PDU_INORDER_EN;
462 else if (attr == &dev_attr_iface_erl.attr)
463 param = ISCSI_IFACE_PARAM_ERL;
464 else if (attr == &dev_attr_iface_max_recv_dlength.attr)
465 param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH;
466 else if (attr == &dev_attr_iface_first_burst_len.attr)
467 param = ISCSI_IFACE_PARAM_FIRST_BURST;
468 else if (attr == &dev_attr_iface_max_outstanding_r2t.attr)
469 param = ISCSI_IFACE_PARAM_MAX_R2T;
470 else if (attr == &dev_attr_iface_max_burst_len.attr)
471 param = ISCSI_IFACE_PARAM_MAX_BURST;
472 else if (attr == &dev_attr_iface_chap_auth.attr)
473 param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN;
474 else if (attr == &dev_attr_iface_bidi_chap.attr)
475 param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN;
476 else if (attr == &dev_attr_iface_discovery_auth_optional.attr)
477 param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL;
478 else if (attr == &dev_attr_iface_discovery_logout.attr)
479 param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN;
480 else if (attr == &dev_attr_iface_strict_login_comp_en.attr)
481 param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN;
482 else if (attr == &dev_attr_iface_initiator_name.attr)
483 param = ISCSI_IFACE_PARAM_INITIATOR_NAME;
486 return t->attr_is_visible(ISCSI_IFACE_PARAM, param);
488 if (attr == &dev_attr_iface_enabled.attr)
489 param = ISCSI_NET_PARAM_IFACE_ENABLE;
490 else if (attr == &dev_attr_iface_vlan_id.attr)
491 param = ISCSI_NET_PARAM_VLAN_ID;
492 else if (attr == &dev_attr_iface_vlan_priority.attr)
493 param = ISCSI_NET_PARAM_VLAN_PRIORITY;
494 else if (attr == &dev_attr_iface_vlan_enabled.attr)
495 param = ISCSI_NET_PARAM_VLAN_ENABLED;
496 else if (attr == &dev_attr_iface_mtu.attr)
497 param = ISCSI_NET_PARAM_MTU;
498 else if (attr == &dev_attr_iface_port.attr)
499 param = ISCSI_NET_PARAM_PORT;
500 else if (attr == &dev_attr_iface_ipaddress_state.attr)
501 param = ISCSI_NET_PARAM_IPADDR_STATE;
502 else if (attr == &dev_attr_iface_delayed_ack_en.attr)
503 param = ISCSI_NET_PARAM_DELAYED_ACK_EN;
504 else if (attr == &dev_attr_iface_tcp_nagle_disable.attr)
505 param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE;
506 else if (attr == &dev_attr_iface_tcp_wsf_disable.attr)
507 param = ISCSI_NET_PARAM_TCP_WSF_DISABLE;
508 else if (attr == &dev_attr_iface_tcp_wsf.attr)
509 param = ISCSI_NET_PARAM_TCP_WSF;
510 else if (attr == &dev_attr_iface_tcp_timer_scale.attr)
511 param = ISCSI_NET_PARAM_TCP_TIMER_SCALE;
512 else if (attr == &dev_attr_iface_tcp_timestamp_en.attr)
513 param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN;
514 else if (attr == &dev_attr_iface_cache_id.attr)
515 param = ISCSI_NET_PARAM_CACHE_ID;
516 else if (attr == &dev_attr_iface_redirect_en.attr)
517 param = ISCSI_NET_PARAM_REDIRECT_EN;
518 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
519 if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
520 param = ISCSI_NET_PARAM_IPV4_ADDR;
521 else if (attr == &dev_attr_ipv4_iface_gateway.attr)
522 param = ISCSI_NET_PARAM_IPV4_GW;
523 else if (attr == &dev_attr_ipv4_iface_subnet.attr)
524 param = ISCSI_NET_PARAM_IPV4_SUBNET;
525 else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
526 param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
528 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr)
529 param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN;
531 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr)
532 param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN;
533 else if (attr == &dev_attr_ipv4_iface_tos_en.attr)
534 param = ISCSI_NET_PARAM_IPV4_TOS_EN;
535 else if (attr == &dev_attr_ipv4_iface_tos.attr)
536 param = ISCSI_NET_PARAM_IPV4_TOS;
537 else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr)
538 param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN;
540 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr)
541 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN;
542 else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr)
543 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID;
545 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr)
546 param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN;
548 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr)
549 param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN;
550 else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr)
551 param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID;
553 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr)
554 param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN;
556 &dev_attr_ipv4_iface_fragment_disable.attr)
557 param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE;
559 &dev_attr_ipv4_iface_incoming_forwarding_en.attr)
560 param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN;
561 else if (attr == &dev_attr_ipv4_iface_ttl.attr)
562 param = ISCSI_NET_PARAM_IPV4_TTL;
565 } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
566 if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
567 param = ISCSI_NET_PARAM_IPV6_ADDR;
568 else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
569 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
570 else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
571 param = ISCSI_NET_PARAM_IPV6_ROUTER;
572 else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
573 param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
574 else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
575 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
576 else if (attr == &dev_attr_ipv6_iface_link_local_state.attr)
577 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE;
578 else if (attr == &dev_attr_ipv6_iface_router_state.attr)
579 param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE;
581 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr)
582 param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN;
583 else if (attr == &dev_attr_ipv6_iface_mld_en.attr)
584 param = ISCSI_NET_PARAM_IPV6_MLD_EN;
585 else if (attr == &dev_attr_ipv6_iface_flow_label.attr)
586 param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL;
587 else if (attr == &dev_attr_ipv6_iface_traffic_class.attr)
588 param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS;
589 else if (attr == &dev_attr_ipv6_iface_hop_limit.attr)
590 param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT;
591 else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr)
592 param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO;
593 else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr)
594 param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME;
595 else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr)
596 param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO;
597 else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr)
598 param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT;
599 else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr)
600 param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU;
604 WARN_ONCE(1, "Invalid iface attr");
608 return t->attr_is_visible(ISCSI_NET_PARAM, param);
611 static struct attribute *iscsi_iface_attrs[] = {
612 &dev_attr_iface_enabled.attr,
613 &dev_attr_iface_vlan_id.attr,
614 &dev_attr_iface_vlan_priority.attr,
615 &dev_attr_iface_vlan_enabled.attr,
616 &dev_attr_ipv4_iface_ipaddress.attr,
617 &dev_attr_ipv4_iface_gateway.attr,
618 &dev_attr_ipv4_iface_subnet.attr,
619 &dev_attr_ipv4_iface_bootproto.attr,
620 &dev_attr_ipv6_iface_ipaddress.attr,
621 &dev_attr_ipv6_iface_link_local_addr.attr,
622 &dev_attr_ipv6_iface_router_addr.attr,
623 &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
624 &dev_attr_ipv6_iface_link_local_autocfg.attr,
625 &dev_attr_iface_mtu.attr,
626 &dev_attr_iface_port.attr,
627 &dev_attr_iface_ipaddress_state.attr,
628 &dev_attr_iface_delayed_ack_en.attr,
629 &dev_attr_iface_tcp_nagle_disable.attr,
630 &dev_attr_iface_tcp_wsf_disable.attr,
631 &dev_attr_iface_tcp_wsf.attr,
632 &dev_attr_iface_tcp_timer_scale.attr,
633 &dev_attr_iface_tcp_timestamp_en.attr,
634 &dev_attr_iface_cache_id.attr,
635 &dev_attr_iface_redirect_en.attr,
636 &dev_attr_iface_def_taskmgmt_tmo.attr,
637 &dev_attr_iface_header_digest.attr,
638 &dev_attr_iface_data_digest.attr,
639 &dev_attr_iface_immediate_data.attr,
640 &dev_attr_iface_initial_r2t.attr,
641 &dev_attr_iface_data_seq_in_order.attr,
642 &dev_attr_iface_data_pdu_in_order.attr,
643 &dev_attr_iface_erl.attr,
644 &dev_attr_iface_max_recv_dlength.attr,
645 &dev_attr_iface_first_burst_len.attr,
646 &dev_attr_iface_max_outstanding_r2t.attr,
647 &dev_attr_iface_max_burst_len.attr,
648 &dev_attr_iface_chap_auth.attr,
649 &dev_attr_iface_bidi_chap.attr,
650 &dev_attr_iface_discovery_auth_optional.attr,
651 &dev_attr_iface_discovery_logout.attr,
652 &dev_attr_iface_strict_login_comp_en.attr,
653 &dev_attr_iface_initiator_name.attr,
654 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr,
655 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr,
656 &dev_attr_ipv4_iface_tos_en.attr,
657 &dev_attr_ipv4_iface_tos.attr,
658 &dev_attr_ipv4_iface_grat_arp_en.attr,
659 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr,
660 &dev_attr_ipv4_iface_dhcp_alt_client_id.attr,
661 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr,
662 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr,
663 &dev_attr_ipv4_iface_dhcp_vendor_id.attr,
664 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr,
665 &dev_attr_ipv4_iface_fragment_disable.attr,
666 &dev_attr_ipv4_iface_incoming_forwarding_en.attr,
667 &dev_attr_ipv4_iface_ttl.attr,
668 &dev_attr_ipv6_iface_link_local_state.attr,
669 &dev_attr_ipv6_iface_router_state.attr,
670 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr,
671 &dev_attr_ipv6_iface_mld_en.attr,
672 &dev_attr_ipv6_iface_flow_label.attr,
673 &dev_attr_ipv6_iface_traffic_class.attr,
674 &dev_attr_ipv6_iface_hop_limit.attr,
675 &dev_attr_ipv6_iface_nd_reachable_tmo.attr,
676 &dev_attr_ipv6_iface_nd_rexmit_time.attr,
677 &dev_attr_ipv6_iface_nd_stale_tmo.attr,
678 &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr,
679 &dev_attr_ipv6_iface_router_adv_link_mtu.attr,
683 static struct attribute_group iscsi_iface_group = {
684 .attrs = iscsi_iface_attrs,
685 .is_visible = iscsi_iface_attr_is_visible,
688 /* convert iscsi_ipaddress_state values to ascii string name */
689 static const struct {
690 enum iscsi_ipaddress_state value;
692 } iscsi_ipaddress_state_names[] = {
693 {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" },
694 {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" },
695 {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" },
696 {ISCSI_IPDDRESS_STATE_VALID, "Valid" },
697 {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" },
698 {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" },
699 {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" },
702 char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state)
707 for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) {
708 if (iscsi_ipaddress_state_names[i].value == port_state) {
709 state = iscsi_ipaddress_state_names[i].name;
715 EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name);
717 /* convert iscsi_router_state values to ascii string name */
718 static const struct {
719 enum iscsi_router_state value;
721 } iscsi_router_state_names[] = {
722 {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" },
723 {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" },
724 {ISCSI_ROUTER_STATE_MANUAL, "Manual" },
725 {ISCSI_ROUTER_STATE_STALE, "Stale" },
728 char *iscsi_get_router_state_name(enum iscsi_router_state router_state)
733 for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) {
734 if (iscsi_router_state_names[i].value == router_state) {
735 state = iscsi_router_state_names[i].name;
741 EXPORT_SYMBOL_GPL(iscsi_get_router_state_name);
744 iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
745 uint32_t iface_type, uint32_t iface_num, int dd_size)
747 struct iscsi_iface *iface;
750 iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
754 iface->transport = transport;
755 iface->iface_type = iface_type;
756 iface->iface_num = iface_num;
757 iface->dev.release = iscsi_iface_release;
758 iface->dev.class = &iscsi_iface_class;
759 /* parent reference released in iscsi_iface_release */
760 iface->dev.parent = get_device(&shost->shost_gendev);
761 if (iface_type == ISCSI_IFACE_TYPE_IPV4)
762 dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
765 dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
768 err = device_register(&iface->dev);
772 err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
777 iface->dd_data = &iface[1];
781 device_unregister(&iface->dev);
785 put_device(iface->dev.parent);
789 EXPORT_SYMBOL_GPL(iscsi_create_iface);
791 void iscsi_destroy_iface(struct iscsi_iface *iface)
793 sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
794 device_unregister(&iface->dev);
796 EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
799 * Interface to display flash node params to sysfs
802 #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
803 struct device_attribute dev_attr_##_prefix##_##_name = \
804 __ATTR(_name, _mode, _show, _store)
806 /* flash node session attrs show */
807 #define iscsi_flashnode_sess_attr_show(type, name, param) \
809 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
812 struct iscsi_bus_flash_session *fnode_sess = \
813 iscsi_dev_to_flash_session(dev);\
814 struct iscsi_transport *t = fnode_sess->transport; \
815 return t->get_flashnode_param(fnode_sess, param, buf); \
819 #define iscsi_flashnode_sess_attr(type, name, param) \
820 iscsi_flashnode_sess_attr_show(type, name, param) \
821 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
822 show_##type##_##name, NULL);
824 /* Flash node session attributes */
826 iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable,
827 ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE);
828 iscsi_flashnode_sess_attr(fnode, discovery_session,
829 ISCSI_FLASHNODE_DISCOVERY_SESS);
830 iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE);
831 iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN);
832 iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN);
833 iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN);
834 iscsi_flashnode_sess_attr(fnode, data_seq_in_order,
835 ISCSI_FLASHNODE_DATASEQ_INORDER);
836 iscsi_flashnode_sess_attr(fnode, data_pdu_in_order,
837 ISCSI_FLASHNODE_PDU_INORDER);
838 iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN);
839 iscsi_flashnode_sess_attr(fnode, discovery_logout,
840 ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN);
841 iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN);
842 iscsi_flashnode_sess_attr(fnode, discovery_auth_optional,
843 ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL);
844 iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL);
845 iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST);
846 iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT);
847 iscsi_flashnode_sess_attr(fnode, def_time2retain,
848 ISCSI_FLASHNODE_DEF_TIME2RETAIN);
849 iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T);
850 iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID);
851 iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID);
852 iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST);
853 iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo,
854 ISCSI_FLASHNODE_DEF_TASKMGMT_TMO);
855 iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS);
856 iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME);
857 iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT);
858 iscsi_flashnode_sess_attr(fnode, discovery_parent_idx,
859 ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX);
860 iscsi_flashnode_sess_attr(fnode, discovery_parent_type,
861 ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE);
862 iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX);
863 iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX);
864 iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME);
865 iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN);
866 iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD);
867 iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN);
868 iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT);
870 static struct attribute *iscsi_flashnode_sess_attrs[] = {
871 &dev_attr_fnode_auto_snd_tgt_disable.attr,
872 &dev_attr_fnode_discovery_session.attr,
873 &dev_attr_fnode_portal_type.attr,
874 &dev_attr_fnode_entry_enable.attr,
875 &dev_attr_fnode_immediate_data.attr,
876 &dev_attr_fnode_initial_r2t.attr,
877 &dev_attr_fnode_data_seq_in_order.attr,
878 &dev_attr_fnode_data_pdu_in_order.attr,
879 &dev_attr_fnode_chap_auth.attr,
880 &dev_attr_fnode_discovery_logout.attr,
881 &dev_attr_fnode_bidi_chap.attr,
882 &dev_attr_fnode_discovery_auth_optional.attr,
883 &dev_attr_fnode_erl.attr,
884 &dev_attr_fnode_first_burst_len.attr,
885 &dev_attr_fnode_def_time2wait.attr,
886 &dev_attr_fnode_def_time2retain.attr,
887 &dev_attr_fnode_max_outstanding_r2t.attr,
888 &dev_attr_fnode_isid.attr,
889 &dev_attr_fnode_tsid.attr,
890 &dev_attr_fnode_max_burst_len.attr,
891 &dev_attr_fnode_def_taskmgmt_tmo.attr,
892 &dev_attr_fnode_targetalias.attr,
893 &dev_attr_fnode_targetname.attr,
894 &dev_attr_fnode_tpgt.attr,
895 &dev_attr_fnode_discovery_parent_idx.attr,
896 &dev_attr_fnode_discovery_parent_type.attr,
897 &dev_attr_fnode_chap_in_idx.attr,
898 &dev_attr_fnode_chap_out_idx.attr,
899 &dev_attr_fnode_username.attr,
900 &dev_attr_fnode_username_in.attr,
901 &dev_attr_fnode_password.attr,
902 &dev_attr_fnode_password_in.attr,
903 &dev_attr_fnode_is_boot_target.attr,
907 static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj,
908 struct attribute *attr,
911 struct device *dev = container_of(kobj, struct device, kobj);
912 struct iscsi_bus_flash_session *fnode_sess =
913 iscsi_dev_to_flash_session(dev);
914 struct iscsi_transport *t = fnode_sess->transport;
917 if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) {
918 param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE;
919 } else if (attr == &dev_attr_fnode_discovery_session.attr) {
920 param = ISCSI_FLASHNODE_DISCOVERY_SESS;
921 } else if (attr == &dev_attr_fnode_portal_type.attr) {
922 param = ISCSI_FLASHNODE_PORTAL_TYPE;
923 } else if (attr == &dev_attr_fnode_entry_enable.attr) {
924 param = ISCSI_FLASHNODE_ENTRY_EN;
925 } else if (attr == &dev_attr_fnode_immediate_data.attr) {
926 param = ISCSI_FLASHNODE_IMM_DATA_EN;
927 } else if (attr == &dev_attr_fnode_initial_r2t.attr) {
928 param = ISCSI_FLASHNODE_INITIAL_R2T_EN;
929 } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) {
930 param = ISCSI_FLASHNODE_DATASEQ_INORDER;
931 } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) {
932 param = ISCSI_FLASHNODE_PDU_INORDER;
933 } else if (attr == &dev_attr_fnode_chap_auth.attr) {
934 param = ISCSI_FLASHNODE_CHAP_AUTH_EN;
935 } else if (attr == &dev_attr_fnode_discovery_logout.attr) {
936 param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN;
937 } else if (attr == &dev_attr_fnode_bidi_chap.attr) {
938 param = ISCSI_FLASHNODE_BIDI_CHAP_EN;
939 } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) {
940 param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL;
941 } else if (attr == &dev_attr_fnode_erl.attr) {
942 param = ISCSI_FLASHNODE_ERL;
943 } else if (attr == &dev_attr_fnode_first_burst_len.attr) {
944 param = ISCSI_FLASHNODE_FIRST_BURST;
945 } else if (attr == &dev_attr_fnode_def_time2wait.attr) {
946 param = ISCSI_FLASHNODE_DEF_TIME2WAIT;
947 } else if (attr == &dev_attr_fnode_def_time2retain.attr) {
948 param = ISCSI_FLASHNODE_DEF_TIME2RETAIN;
949 } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) {
950 param = ISCSI_FLASHNODE_MAX_R2T;
951 } else if (attr == &dev_attr_fnode_isid.attr) {
952 param = ISCSI_FLASHNODE_ISID;
953 } else if (attr == &dev_attr_fnode_tsid.attr) {
954 param = ISCSI_FLASHNODE_TSID;
955 } else if (attr == &dev_attr_fnode_max_burst_len.attr) {
956 param = ISCSI_FLASHNODE_MAX_BURST;
957 } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) {
958 param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO;
959 } else if (attr == &dev_attr_fnode_targetalias.attr) {
960 param = ISCSI_FLASHNODE_ALIAS;
961 } else if (attr == &dev_attr_fnode_targetname.attr) {
962 param = ISCSI_FLASHNODE_NAME;
963 } else if (attr == &dev_attr_fnode_tpgt.attr) {
964 param = ISCSI_FLASHNODE_TPGT;
965 } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) {
966 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX;
967 } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) {
968 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE;
969 } else if (attr == &dev_attr_fnode_chap_in_idx.attr) {
970 param = ISCSI_FLASHNODE_CHAP_IN_IDX;
971 } else if (attr == &dev_attr_fnode_chap_out_idx.attr) {
972 param = ISCSI_FLASHNODE_CHAP_OUT_IDX;
973 } else if (attr == &dev_attr_fnode_username.attr) {
974 param = ISCSI_FLASHNODE_USERNAME;
975 } else if (attr == &dev_attr_fnode_username_in.attr) {
976 param = ISCSI_FLASHNODE_USERNAME_IN;
977 } else if (attr == &dev_attr_fnode_password.attr) {
978 param = ISCSI_FLASHNODE_PASSWORD;
979 } else if (attr == &dev_attr_fnode_password_in.attr) {
980 param = ISCSI_FLASHNODE_PASSWORD_IN;
981 } else if (attr == &dev_attr_fnode_is_boot_target.attr) {
982 param = ISCSI_FLASHNODE_IS_BOOT_TGT;
984 WARN_ONCE(1, "Invalid flashnode session attr");
988 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
991 static struct attribute_group iscsi_flashnode_sess_attr_group = {
992 .attrs = iscsi_flashnode_sess_attrs,
993 .is_visible = iscsi_flashnode_sess_attr_is_visible,
996 static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = {
997 &iscsi_flashnode_sess_attr_group,
1001 static void iscsi_flashnode_sess_release(struct device *dev)
1003 struct iscsi_bus_flash_session *fnode_sess =
1004 iscsi_dev_to_flash_session(dev);
1006 kfree(fnode_sess->targetname);
1007 kfree(fnode_sess->targetalias);
1008 kfree(fnode_sess->portal_type);
1012 static const struct device_type iscsi_flashnode_sess_dev_type = {
1013 .name = "iscsi_flashnode_sess_dev_type",
1014 .groups = iscsi_flashnode_sess_attr_groups,
1015 .release = iscsi_flashnode_sess_release,
1018 /* flash node connection attrs show */
1019 #define iscsi_flashnode_conn_attr_show(type, name, param) \
1021 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
1024 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
1025 struct iscsi_bus_flash_session *fnode_sess = \
1026 iscsi_flash_conn_to_flash_session(fnode_conn);\
1027 struct iscsi_transport *t = fnode_conn->transport; \
1028 return t->get_flashnode_param(fnode_sess, param, buf); \
1032 #define iscsi_flashnode_conn_attr(type, name, param) \
1033 iscsi_flashnode_conn_attr_show(type, name, param) \
1034 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
1035 show_##type##_##name, NULL);
1037 /* Flash node connection attributes */
1039 iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6,
1040 ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6);
1041 iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN);
1042 iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN);
1043 iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN);
1044 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat,
1045 ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT);
1046 iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable,
1047 ISCSI_FLASHNODE_TCP_NAGLE_DISABLE);
1048 iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable,
1049 ISCSI_FLASHNODE_TCP_WSF_DISABLE);
1050 iscsi_flashnode_conn_attr(fnode, tcp_timer_scale,
1051 ISCSI_FLASHNODE_TCP_TIMER_SCALE);
1052 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable,
1053 ISCSI_FLASHNODE_TCP_TIMESTAMP_EN);
1054 iscsi_flashnode_conn_attr(fnode, fragment_disable,
1055 ISCSI_FLASHNODE_IP_FRAG_DISABLE);
1056 iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO);
1057 iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT);
1058 iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR);
1059 iscsi_flashnode_conn_attr(fnode, max_recv_dlength,
1060 ISCSI_FLASHNODE_MAX_RECV_DLENGTH);
1061 iscsi_flashnode_conn_attr(fnode, max_xmit_dlength,
1062 ISCSI_FLASHNODE_MAX_XMIT_DLENGTH);
1063 iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT);
1064 iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS);
1065 iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC);
1066 iscsi_flashnode_conn_attr(fnode, ipv6_flow_label,
1067 ISCSI_FLASHNODE_IPV6_FLOW_LABEL);
1068 iscsi_flashnode_conn_attr(fnode, redirect_ipaddr,
1069 ISCSI_FLASHNODE_REDIRECT_IPADDR);
1070 iscsi_flashnode_conn_attr(fnode, max_segment_size,
1071 ISCSI_FLASHNODE_MAX_SEGMENT_SIZE);
1072 iscsi_flashnode_conn_attr(fnode, link_local_ipv6,
1073 ISCSI_FLASHNODE_LINK_LOCAL_IPV6);
1074 iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF);
1075 iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF);
1076 iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN);
1077 iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN);
1079 static struct attribute *iscsi_flashnode_conn_attrs[] = {
1080 &dev_attr_fnode_is_fw_assigned_ipv6.attr,
1081 &dev_attr_fnode_header_digest.attr,
1082 &dev_attr_fnode_data_digest.attr,
1083 &dev_attr_fnode_snack_req.attr,
1084 &dev_attr_fnode_tcp_timestamp_stat.attr,
1085 &dev_attr_fnode_tcp_nagle_disable.attr,
1086 &dev_attr_fnode_tcp_wsf_disable.attr,
1087 &dev_attr_fnode_tcp_timer_scale.attr,
1088 &dev_attr_fnode_tcp_timestamp_enable.attr,
1089 &dev_attr_fnode_fragment_disable.attr,
1090 &dev_attr_fnode_max_recv_dlength.attr,
1091 &dev_attr_fnode_max_xmit_dlength.attr,
1092 &dev_attr_fnode_keepalive_tmo.attr,
1093 &dev_attr_fnode_port.attr,
1094 &dev_attr_fnode_ipaddress.attr,
1095 &dev_attr_fnode_redirect_ipaddr.attr,
1096 &dev_attr_fnode_max_segment_size.attr,
1097 &dev_attr_fnode_local_port.attr,
1098 &dev_attr_fnode_ipv4_tos.attr,
1099 &dev_attr_fnode_ipv6_traffic_class.attr,
1100 &dev_attr_fnode_ipv6_flow_label.attr,
1101 &dev_attr_fnode_link_local_ipv6.attr,
1102 &dev_attr_fnode_tcp_xmit_wsf.attr,
1103 &dev_attr_fnode_tcp_recv_wsf.attr,
1104 &dev_attr_fnode_statsn.attr,
1105 &dev_attr_fnode_exp_statsn.attr,
1109 static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj,
1110 struct attribute *attr,
1113 struct device *dev = container_of(kobj, struct device, kobj);
1114 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1115 struct iscsi_transport *t = fnode_conn->transport;
1118 if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) {
1119 param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6;
1120 } else if (attr == &dev_attr_fnode_header_digest.attr) {
1121 param = ISCSI_FLASHNODE_HDR_DGST_EN;
1122 } else if (attr == &dev_attr_fnode_data_digest.attr) {
1123 param = ISCSI_FLASHNODE_DATA_DGST_EN;
1124 } else if (attr == &dev_attr_fnode_snack_req.attr) {
1125 param = ISCSI_FLASHNODE_SNACK_REQ_EN;
1126 } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) {
1127 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT;
1128 } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) {
1129 param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE;
1130 } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) {
1131 param = ISCSI_FLASHNODE_TCP_WSF_DISABLE;
1132 } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) {
1133 param = ISCSI_FLASHNODE_TCP_TIMER_SCALE;
1134 } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) {
1135 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN;
1136 } else if (attr == &dev_attr_fnode_fragment_disable.attr) {
1137 param = ISCSI_FLASHNODE_IP_FRAG_DISABLE;
1138 } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) {
1139 param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH;
1140 } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) {
1141 param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH;
1142 } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) {
1143 param = ISCSI_FLASHNODE_KEEPALIVE_TMO;
1144 } else if (attr == &dev_attr_fnode_port.attr) {
1145 param = ISCSI_FLASHNODE_PORT;
1146 } else if (attr == &dev_attr_fnode_ipaddress.attr) {
1147 param = ISCSI_FLASHNODE_IPADDR;
1148 } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) {
1149 param = ISCSI_FLASHNODE_REDIRECT_IPADDR;
1150 } else if (attr == &dev_attr_fnode_max_segment_size.attr) {
1151 param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE;
1152 } else if (attr == &dev_attr_fnode_local_port.attr) {
1153 param = ISCSI_FLASHNODE_LOCAL_PORT;
1154 } else if (attr == &dev_attr_fnode_ipv4_tos.attr) {
1155 param = ISCSI_FLASHNODE_IPV4_TOS;
1156 } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) {
1157 param = ISCSI_FLASHNODE_IPV6_TC;
1158 } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) {
1159 param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL;
1160 } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) {
1161 param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6;
1162 } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) {
1163 param = ISCSI_FLASHNODE_TCP_XMIT_WSF;
1164 } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) {
1165 param = ISCSI_FLASHNODE_TCP_RECV_WSF;
1166 } else if (attr == &dev_attr_fnode_statsn.attr) {
1167 param = ISCSI_FLASHNODE_STATSN;
1168 } else if (attr == &dev_attr_fnode_exp_statsn.attr) {
1169 param = ISCSI_FLASHNODE_EXP_STATSN;
1171 WARN_ONCE(1, "Invalid flashnode connection attr");
1175 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
1178 static struct attribute_group iscsi_flashnode_conn_attr_group = {
1179 .attrs = iscsi_flashnode_conn_attrs,
1180 .is_visible = iscsi_flashnode_conn_attr_is_visible,
1183 static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = {
1184 &iscsi_flashnode_conn_attr_group,
1188 static void iscsi_flashnode_conn_release(struct device *dev)
1190 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1192 kfree(fnode_conn->ipaddress);
1193 kfree(fnode_conn->redirect_ipaddr);
1194 kfree(fnode_conn->link_local_ipv6_addr);
1198 static const struct device_type iscsi_flashnode_conn_dev_type = {
1199 .name = "iscsi_flashnode_conn_dev_type",
1200 .groups = iscsi_flashnode_conn_attr_groups,
1201 .release = iscsi_flashnode_conn_release,
1204 static struct bus_type iscsi_flashnode_bus;
1206 int iscsi_flashnode_bus_match(struct device *dev,
1207 struct device_driver *drv)
1209 if (dev->bus == &iscsi_flashnode_bus)
1213 EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match);
1215 static struct bus_type iscsi_flashnode_bus = {
1216 .name = "iscsi_flashnode",
1217 .match = &iscsi_flashnode_bus_match,
1221 * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
1222 * @shost: pointer to host data
1223 * @index: index of flashnode to add in sysfs
1224 * @transport: pointer to transport data
1225 * @dd_size: total size to allocate
1227 * Adds a sysfs entry for the flashnode session attributes
1230 * pointer to allocated flashnode sess on success
1233 struct iscsi_bus_flash_session *
1234 iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
1235 struct iscsi_transport *transport,
1238 struct iscsi_bus_flash_session *fnode_sess;
1241 fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL);
1245 fnode_sess->transport = transport;
1246 fnode_sess->target_id = index;
1247 fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type;
1248 fnode_sess->dev.bus = &iscsi_flashnode_bus;
1249 fnode_sess->dev.parent = &shost->shost_gendev;
1250 dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u",
1251 shost->host_no, index);
1253 err = device_register(&fnode_sess->dev);
1255 goto free_fnode_sess;
1258 fnode_sess->dd_data = &fnode_sess[1];
1266 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
1269 * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
1270 * @shost: pointer to host data
1271 * @fnode_sess: pointer to the parent flashnode session entry
1272 * @transport: pointer to transport data
1273 * @dd_size: total size to allocate
1275 * Adds a sysfs entry for the flashnode connection attributes
1278 * pointer to allocated flashnode conn on success
1281 struct iscsi_bus_flash_conn *
1282 iscsi_create_flashnode_conn(struct Scsi_Host *shost,
1283 struct iscsi_bus_flash_session *fnode_sess,
1284 struct iscsi_transport *transport,
1287 struct iscsi_bus_flash_conn *fnode_conn;
1290 fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL);
1294 fnode_conn->transport = transport;
1295 fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type;
1296 fnode_conn->dev.bus = &iscsi_flashnode_bus;
1297 fnode_conn->dev.parent = &fnode_sess->dev;
1298 dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0",
1299 shost->host_no, fnode_sess->target_id);
1301 err = device_register(&fnode_conn->dev);
1303 goto free_fnode_conn;
1306 fnode_conn->dd_data = &fnode_conn[1];
1314 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
1317 * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
1318 * @dev: device to verify
1319 * @data: pointer to data containing value to use for verification
1321 * Verifies if the passed device is flashnode conn device
1327 static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
1329 return dev->bus == &iscsi_flashnode_bus;
1332 static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
1334 device_unregister(&fnode_conn->dev);
1338 static int flashnode_match_index(struct device *dev, void *data)
1340 struct iscsi_bus_flash_session *fnode_sess = NULL;
1343 if (!iscsi_flashnode_bus_match(dev, NULL))
1344 goto exit_match_index;
1346 fnode_sess = iscsi_dev_to_flash_session(dev);
1347 ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
1354 * iscsi_get_flashnode_by_index -finds flashnode session entry by index
1355 * @shost: pointer to host data
1356 * @idx: index to match
1358 * Finds the flashnode session object for the passed index
1361 * pointer to found flashnode session object on success
1364 static struct iscsi_bus_flash_session *
1365 iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
1367 struct iscsi_bus_flash_session *fnode_sess = NULL;
1370 dev = device_find_child(&shost->shost_gendev, &idx,
1371 flashnode_match_index);
1373 fnode_sess = iscsi_dev_to_flash_session(dev);
1379 * iscsi_find_flashnode_sess - finds flashnode session entry
1380 * @shost: pointer to host data
1381 * @data: pointer to data containing value to use for comparison
1382 * @fn: function pointer that does actual comparison
1384 * Finds the flashnode session object comparing the data passed using logic
1385 * defined in passed function pointer
1388 * pointer to found flashnode session device object on success
1392 iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
1393 int (*fn)(struct device *dev, void *data))
1395 return device_find_child(&shost->shost_gendev, data, fn);
1397 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
1400 * iscsi_find_flashnode_conn - finds flashnode connection entry
1401 * @fnode_sess: pointer to parent flashnode session entry
1403 * Finds the flashnode connection object comparing the data passed using logic
1404 * defined in passed function pointer
1407 * pointer to found flashnode connection device object on success
1411 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
1413 return device_find_child(&fnode_sess->dev, NULL,
1414 iscsi_is_flashnode_conn_dev);
1416 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);
1418 static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data)
1420 if (!iscsi_is_flashnode_conn_dev(dev, NULL))
1423 return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev));
1427 * iscsi_destroy_flashnode_sess - destroy flashnode session entry
1428 * @fnode_sess: pointer to flashnode session entry to be destroyed
1430 * Deletes the flashnode session entry and all children flashnode connection
1431 * entries from sysfs
1433 void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess)
1437 err = device_for_each_child(&fnode_sess->dev, NULL,
1438 iscsi_iter_destroy_flashnode_conn_fn);
1440 pr_err("Could not delete all connections for %s. Error %d.\n",
1441 fnode_sess->dev.kobj.name, err);
1443 device_unregister(&fnode_sess->dev);
1445 EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);
1447 static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data)
1449 if (!iscsi_flashnode_bus_match(dev, NULL))
1452 iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev));
1457 * iscsi_destroy_all_flashnode - destroy all flashnode session entries
1458 * @shost: pointer to host data
1460 * Destroys all the flashnode session entries and all corresponding children
1461 * flashnode connection entries from sysfs
1463 void iscsi_destroy_all_flashnode(struct Scsi_Host *shost)
1465 device_for_each_child(&shost->shost_gendev, NULL,
1466 iscsi_iter_destroy_flashnode_fn);
1468 EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode);
1474 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
1475 * @job: bsg job to be processed
1477 static int iscsi_bsg_host_dispatch(struct bsg_job *job)
1479 struct Scsi_Host *shost = iscsi_job_to_shost(job);
1480 struct iscsi_bsg_request *req = job->request;
1481 struct iscsi_bsg_reply *reply = job->reply;
1482 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1483 int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
1486 /* check if we have the msgcode value at least */
1487 if (job->request_len < sizeof(uint32_t)) {
1492 /* Validate the host command */
1493 switch (req->msgcode) {
1494 case ISCSI_BSG_HST_VENDOR:
1495 cmdlen += sizeof(struct iscsi_bsg_host_vendor);
1496 if ((shost->hostt->vendor_id == 0L) ||
1497 (req->rqst_data.h_vendor.vendor_id !=
1498 shost->hostt->vendor_id)) {
1508 /* check if we really have all the request data needed */
1509 if (job->request_len < cmdlen) {
1514 ret = i->iscsi_transport->bsg_request(job);
1519 /* return the errno failure code as the only status */
1520 BUG_ON(job->reply_len < sizeof(uint32_t));
1521 reply->reply_payload_rcv_len = 0;
1522 reply->result = ret;
1523 job->reply_len = sizeof(uint32_t);
1524 bsg_job_done(job, ret, 0);
1529 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
1530 * @shost: shost for iscsi_host
1531 * @ihost: iscsi_cls_host adding the structures to
1534 iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
1536 struct device *dev = &shost->shost_gendev;
1537 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1538 struct request_queue *q;
1541 if (!i->iscsi_transport->bsg_request)
1544 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1545 q = bsg_setup_queue(dev, bsg_name, iscsi_bsg_host_dispatch, NULL, 0);
1547 shost_printk(KERN_ERR, shost, "bsg interface failed to "
1548 "initialize - no request queue\n");
1551 __scsi_init_queue(shost, q);
1557 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
1558 struct device *cdev)
1560 struct Scsi_Host *shost = dev_to_shost(dev);
1561 struct iscsi_cls_host *ihost = shost->shost_data;
1563 memset(ihost, 0, sizeof(*ihost));
1564 atomic_set(&ihost->nr_scans, 0);
1565 mutex_init(&ihost->mutex);
1567 iscsi_bsg_host_add(shost, ihost);
1568 /* ignore any bsg add error - we just can't do sgio */
1573 static int iscsi_remove_host(struct transport_container *tc,
1574 struct device *dev, struct device *cdev)
1576 struct Scsi_Host *shost = dev_to_shost(dev);
1577 struct iscsi_cls_host *ihost = shost->shost_data;
1579 bsg_remove_queue(ihost->bsg_q);
1583 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
1589 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
1595 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
1601 static struct sock *nls;
1602 static DEFINE_MUTEX(rx_queue_mutex);
1604 static LIST_HEAD(sesslist);
1605 static DEFINE_SPINLOCK(sesslock);
1606 static LIST_HEAD(connlist);
1607 static LIST_HEAD(connlist_err);
1608 static DEFINE_SPINLOCK(connlock);
1610 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
1612 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
1617 * Returns the matching session to a given sid
1619 static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
1621 unsigned long flags;
1622 struct iscsi_cls_session *sess;
1624 spin_lock_irqsave(&sesslock, flags);
1625 list_for_each_entry(sess, &sesslist, sess_list) {
1626 if (sess->sid == sid) {
1627 spin_unlock_irqrestore(&sesslock, flags);
1631 spin_unlock_irqrestore(&sesslock, flags);
1636 * Returns the matching connection to a given sid / cid tuple
1638 static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
1640 unsigned long flags;
1641 struct iscsi_cls_conn *conn;
1643 spin_lock_irqsave(&connlock, flags);
1644 list_for_each_entry(conn, &connlist, conn_list) {
1645 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
1646 spin_unlock_irqrestore(&connlock, flags);
1650 spin_unlock_irqrestore(&connlock, flags);
1655 * The following functions can be used by LLDs that allocate
1656 * their own scsi_hosts or by software iscsi LLDs
1661 } iscsi_session_state_names[] = {
1662 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
1663 { ISCSI_SESSION_FAILED, "FAILED" },
1664 { ISCSI_SESSION_FREE, "FREE" },
1667 static const char *iscsi_session_state_name(int state)
1672 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
1673 if (iscsi_session_state_names[i].value == state) {
1674 name = iscsi_session_state_names[i].name;
1681 int iscsi_session_chkready(struct iscsi_cls_session *session)
1685 switch (session->state) {
1686 case ISCSI_SESSION_LOGGED_IN:
1689 case ISCSI_SESSION_FAILED:
1690 err = DID_IMM_RETRY << 16;
1692 case ISCSI_SESSION_FREE:
1693 err = DID_TRANSPORT_FAILFAST << 16;
1696 err = DID_NO_CONNECT << 16;
1701 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
1703 int iscsi_is_session_online(struct iscsi_cls_session *session)
1705 unsigned long flags;
1708 spin_lock_irqsave(&session->lock, flags);
1709 if (session->state == ISCSI_SESSION_LOGGED_IN)
1711 spin_unlock_irqrestore(&session->lock, flags);
1714 EXPORT_SYMBOL_GPL(iscsi_is_session_online);
1716 static void iscsi_session_release(struct device *dev)
1718 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
1719 struct Scsi_Host *shost;
1721 shost = iscsi_session_to_shost(session);
1722 scsi_host_put(shost);
1723 ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
1727 int iscsi_is_session_dev(const struct device *dev)
1729 return dev->release == iscsi_session_release;
1731 EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
1733 static int iscsi_iter_session_fn(struct device *dev, void *data)
1735 void (* fn) (struct iscsi_cls_session *) = data;
1737 if (!iscsi_is_session_dev(dev))
1739 fn(iscsi_dev_to_session(dev));
1743 void iscsi_host_for_each_session(struct Scsi_Host *shost,
1744 void (*fn)(struct iscsi_cls_session *))
1746 device_for_each_child(&shost->shost_gendev, fn,
1747 iscsi_iter_session_fn);
1749 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
1752 * iscsi_scan_finished - helper to report when running scans are done
1754 * @time: scan run time
1756 * This function can be used by drives like qla4xxx to report to the scsi
1757 * layer when the scans it kicked off at module load time are done.
1759 int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
1761 struct iscsi_cls_host *ihost = shost->shost_data;
1763 * qla4xxx will have kicked off some session unblocks before calling
1764 * scsi_scan_host, so just wait for them to complete.
1766 return !atomic_read(&ihost->nr_scans);
1768 EXPORT_SYMBOL_GPL(iscsi_scan_finished);
1770 struct iscsi_scan_data {
1771 unsigned int channel;
1774 enum scsi_scan_mode rescan;
1777 static int iscsi_user_scan_session(struct device *dev, void *data)
1779 struct iscsi_scan_data *scan_data = data;
1780 struct iscsi_cls_session *session;
1781 struct Scsi_Host *shost;
1782 struct iscsi_cls_host *ihost;
1783 unsigned long flags;
1786 if (!iscsi_is_session_dev(dev))
1789 session = iscsi_dev_to_session(dev);
1791 ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
1793 shost = iscsi_session_to_shost(session);
1794 ihost = shost->shost_data;
1796 mutex_lock(&ihost->mutex);
1797 spin_lock_irqsave(&session->lock, flags);
1798 if (session->state != ISCSI_SESSION_LOGGED_IN) {
1799 spin_unlock_irqrestore(&session->lock, flags);
1800 goto user_scan_exit;
1802 id = session->target_id;
1803 spin_unlock_irqrestore(&session->lock, flags);
1805 if (id != ISCSI_MAX_TARGET) {
1806 if ((scan_data->channel == SCAN_WILD_CARD ||
1807 scan_data->channel == 0) &&
1808 (scan_data->id == SCAN_WILD_CARD ||
1809 scan_data->id == id))
1810 scsi_scan_target(&session->dev, 0, id,
1811 scan_data->lun, scan_data->rescan);
1815 mutex_unlock(&ihost->mutex);
1816 ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
1820 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
1823 struct iscsi_scan_data scan_data;
1825 scan_data.channel = channel;
1827 scan_data.lun = lun;
1828 scan_data.rescan = SCSI_SCAN_MANUAL;
1830 return device_for_each_child(&shost->shost_gendev, &scan_data,
1831 iscsi_user_scan_session);
1834 static void iscsi_scan_session(struct work_struct *work)
1836 struct iscsi_cls_session *session =
1837 container_of(work, struct iscsi_cls_session, scan_work);
1838 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1839 struct iscsi_cls_host *ihost = shost->shost_data;
1840 struct iscsi_scan_data scan_data;
1842 scan_data.channel = 0;
1843 scan_data.id = SCAN_WILD_CARD;
1844 scan_data.lun = SCAN_WILD_CARD;
1845 scan_data.rescan = SCSI_SCAN_RESCAN;
1847 iscsi_user_scan_session(&session->dev, &scan_data);
1848 atomic_dec(&ihost->nr_scans);
1852 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1853 * @cmd: scsi cmd passed to scsi eh handler
1855 * If the session is down this function will wait for the recovery
1856 * timer to fire or for the session to be logged back in. If the
1857 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1858 * should pass this error value to the scsi eh.
1860 int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
1862 struct iscsi_cls_session *session =
1863 starget_to_session(scsi_target(cmd->device));
1864 unsigned long flags;
1867 spin_lock_irqsave(&session->lock, flags);
1868 while (session->state != ISCSI_SESSION_LOGGED_IN) {
1869 if (session->state == ISCSI_SESSION_FREE) {
1873 spin_unlock_irqrestore(&session->lock, flags);
1875 spin_lock_irqsave(&session->lock, flags);
1877 spin_unlock_irqrestore(&session->lock, flags);
1880 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
1882 static void session_recovery_timedout(struct work_struct *work)
1884 struct iscsi_cls_session *session =
1885 container_of(work, struct iscsi_cls_session,
1886 recovery_work.work);
1887 unsigned long flags;
1889 iscsi_cls_session_printk(KERN_INFO, session,
1890 "session recovery timed out after %d secs\n",
1891 session->recovery_tmo);
1893 spin_lock_irqsave(&session->lock, flags);
1894 switch (session->state) {
1895 case ISCSI_SESSION_FAILED:
1896 session->state = ISCSI_SESSION_FREE;
1898 case ISCSI_SESSION_LOGGED_IN:
1899 case ISCSI_SESSION_FREE:
1900 /* we raced with the unblock's flush */
1901 spin_unlock_irqrestore(&session->lock, flags);
1904 spin_unlock_irqrestore(&session->lock, flags);
1906 ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
1907 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
1908 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
1910 if (session->transport->session_recovery_timedout)
1911 session->transport->session_recovery_timedout(session);
1914 static void __iscsi_unblock_session(struct work_struct *work)
1916 struct iscsi_cls_session *session =
1917 container_of(work, struct iscsi_cls_session,
1919 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1920 struct iscsi_cls_host *ihost = shost->shost_data;
1921 unsigned long flags;
1923 ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
1925 * The recovery and unblock work get run from the same workqueue,
1926 * so try to cancel it if it was going to run after this unblock.
1928 cancel_delayed_work(&session->recovery_work);
1929 spin_lock_irqsave(&session->lock, flags);
1930 session->state = ISCSI_SESSION_LOGGED_IN;
1931 spin_unlock_irqrestore(&session->lock, flags);
1933 scsi_target_unblock(&session->dev, SDEV_RUNNING);
1935 * Only do kernel scanning if the driver is properly hooked into
1936 * the async scanning code (drivers like iscsi_tcp do login and
1937 * scanning from userspace).
1939 if (shost->hostt->scan_finished) {
1940 if (scsi_queue_work(shost, &session->scan_work))
1941 atomic_inc(&ihost->nr_scans);
1943 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
1947 * iscsi_unblock_session - set a session as logged in and start IO.
1948 * @session: iscsi session
1950 * Mark a session as ready to accept IO.
1952 void iscsi_unblock_session(struct iscsi_cls_session *session)
1954 flush_work(&session->block_work);
1956 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
1958 * Blocking the session can be done from any context so we only
1959 * queue the block work. Make sure the unblock work has completed
1960 * because it flushes/cancels the other works and updates the state.
1962 flush_work(&session->unblock_work);
1964 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
1966 static void __iscsi_block_session(struct work_struct *work)
1968 struct iscsi_cls_session *session =
1969 container_of(work, struct iscsi_cls_session,
1971 unsigned long flags;
1973 ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
1974 spin_lock_irqsave(&session->lock, flags);
1975 session->state = ISCSI_SESSION_FAILED;
1976 spin_unlock_irqrestore(&session->lock, flags);
1977 scsi_target_block(&session->dev);
1978 ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
1979 if (session->recovery_tmo >= 0)
1980 queue_delayed_work(iscsi_eh_timer_workq,
1981 &session->recovery_work,
1982 session->recovery_tmo * HZ);
1985 void iscsi_block_session(struct iscsi_cls_session *session)
1987 queue_work(iscsi_eh_timer_workq, &session->block_work);
1989 EXPORT_SYMBOL_GPL(iscsi_block_session);
1991 static void __iscsi_unbind_session(struct work_struct *work)
1993 struct iscsi_cls_session *session =
1994 container_of(work, struct iscsi_cls_session,
1996 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1997 struct iscsi_cls_host *ihost = shost->shost_data;
1998 unsigned long flags;
1999 unsigned int target_id;
2001 ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
2003 /* Prevent new scans and make sure scanning is not in progress */
2004 mutex_lock(&ihost->mutex);
2005 spin_lock_irqsave(&session->lock, flags);
2006 if (session->target_id == ISCSI_MAX_TARGET) {
2007 spin_unlock_irqrestore(&session->lock, flags);
2008 mutex_unlock(&ihost->mutex);
2009 goto unbind_session_exit;
2012 target_id = session->target_id;
2013 session->target_id = ISCSI_MAX_TARGET;
2014 spin_unlock_irqrestore(&session->lock, flags);
2015 mutex_unlock(&ihost->mutex);
2017 scsi_remove_target(&session->dev);
2019 if (session->ida_used)
2020 ida_simple_remove(&iscsi_sess_ida, target_id);
2022 unbind_session_exit:
2023 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
2024 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
2027 static void __iscsi_destroy_session(struct work_struct *work)
2029 struct iscsi_cls_session *session =
2030 container_of(work, struct iscsi_cls_session, destroy_work);
2032 session->transport->destroy_session(session);
2035 struct iscsi_cls_session *
2036 iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2039 struct iscsi_cls_session *session;
2041 session = kzalloc(sizeof(*session) + dd_size,
2046 session->transport = transport;
2047 session->creator = -1;
2048 session->recovery_tmo = 120;
2049 session->recovery_tmo_sysfs_override = false;
2050 session->state = ISCSI_SESSION_FREE;
2051 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
2052 INIT_LIST_HEAD(&session->sess_list);
2053 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
2054 INIT_WORK(&session->block_work, __iscsi_block_session);
2055 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
2056 INIT_WORK(&session->scan_work, iscsi_scan_session);
2057 INIT_WORK(&session->destroy_work, __iscsi_destroy_session);
2058 spin_lock_init(&session->lock);
2060 /* this is released in the dev's release function */
2061 scsi_host_get(shost);
2062 session->dev.parent = &shost->shost_gendev;
2063 session->dev.release = iscsi_session_release;
2064 device_initialize(&session->dev);
2066 session->dd_data = &session[1];
2068 ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
2071 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
2073 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
2075 unsigned long flags;
2079 session->sid = atomic_add_return(1, &iscsi_session_nr);
2081 if (target_id == ISCSI_MAX_TARGET) {
2082 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
2085 iscsi_cls_session_printk(KERN_ERR, session,
2086 "Failure in Target ID Allocation\n");
2089 session->target_id = (unsigned int)id;
2090 session->ida_used = true;
2092 session->target_id = target_id;
2094 dev_set_name(&session->dev, "session%u", session->sid);
2095 err = device_add(&session->dev);
2097 iscsi_cls_session_printk(KERN_ERR, session,
2098 "could not register session's dev\n");
2101 err = transport_register_device(&session->dev);
2103 iscsi_cls_session_printk(KERN_ERR, session,
2104 "could not register transport's dev\n");
2108 spin_lock_irqsave(&sesslock, flags);
2109 list_add(&session->sess_list, &sesslist);
2110 spin_unlock_irqrestore(&sesslock, flags);
2112 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
2113 ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
2117 device_del(&session->dev);
2119 if (session->ida_used)
2120 ida_simple_remove(&iscsi_sess_ida, session->target_id);
2124 EXPORT_SYMBOL_GPL(iscsi_add_session);
2127 * iscsi_create_session - create iscsi class session
2129 * @transport: iscsi transport
2130 * @dd_size: private driver data size
2131 * @target_id: which target
2133 * This can be called from a LLD or iscsi_transport.
2135 struct iscsi_cls_session *
2136 iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2137 int dd_size, unsigned int target_id)
2139 struct iscsi_cls_session *session;
2141 session = iscsi_alloc_session(shost, transport, dd_size);
2145 if (iscsi_add_session(session, target_id)) {
2146 iscsi_free_session(session);
2151 EXPORT_SYMBOL_GPL(iscsi_create_session);
2153 static void iscsi_conn_release(struct device *dev)
2155 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
2156 struct device *parent = conn->dev.parent;
2158 ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
2163 static int iscsi_is_conn_dev(const struct device *dev)
2165 return dev->release == iscsi_conn_release;
2168 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
2170 if (!iscsi_is_conn_dev(dev))
2172 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
2175 void iscsi_remove_session(struct iscsi_cls_session *session)
2177 unsigned long flags;
2180 ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
2182 spin_lock_irqsave(&sesslock, flags);
2183 if (!list_empty(&session->sess_list))
2184 list_del(&session->sess_list);
2185 spin_unlock_irqrestore(&sesslock, flags);
2187 flush_work(&session->block_work);
2188 flush_work(&session->unblock_work);
2189 cancel_delayed_work_sync(&session->recovery_work);
2191 * If we are blocked let commands flow again. The lld or iscsi
2192 * layer should set up the queuecommand to fail commands.
2193 * We assume that LLD will not be calling block/unblock while
2194 * removing the session.
2196 spin_lock_irqsave(&session->lock, flags);
2197 session->state = ISCSI_SESSION_FREE;
2198 spin_unlock_irqrestore(&session->lock, flags);
2200 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2201 /* flush running scans then delete devices */
2202 flush_work(&session->scan_work);
2203 /* flush running unbind operations */
2204 flush_work(&session->unbind_work);
2205 __iscsi_unbind_session(&session->unbind_work);
2207 /* hw iscsi may not have removed all connections from session */
2208 err = device_for_each_child(&session->dev, NULL,
2209 iscsi_iter_destroy_conn_fn);
2211 iscsi_cls_session_printk(KERN_ERR, session,
2212 "Could not delete all connections "
2213 "for session. Error %d.\n", err);
2215 transport_unregister_device(&session->dev);
2217 ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
2218 device_del(&session->dev);
2220 EXPORT_SYMBOL_GPL(iscsi_remove_session);
2222 static void iscsi_stop_conn(struct iscsi_cls_conn *conn, int flag)
2224 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn.\n");
2227 case STOP_CONN_RECOVER:
2228 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2230 case STOP_CONN_TERM:
2231 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2234 iscsi_cls_conn_printk(KERN_ERR, conn, "invalid stop flag %d\n",
2239 conn->transport->stop_conn(conn, flag);
2240 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn done.\n");
2243 static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
2245 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2246 struct iscsi_endpoint *ep;
2248 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep.\n");
2249 WRITE_ONCE(conn->state, ISCSI_CONN_FAILED);
2251 if (!conn->ep || !session->transport->ep_disconnect)
2257 session->transport->unbind_conn(conn, is_active);
2258 session->transport->ep_disconnect(ep);
2259 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep done.\n");
2262 static void iscsi_if_disconnect_bound_ep(struct iscsi_cls_conn *conn,
2263 struct iscsi_endpoint *ep,
2266 /* Check if this was a conn error and the kernel took ownership */
2267 spin_lock_irq(&conn->lock);
2268 if (!test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2269 spin_unlock_irq(&conn->lock);
2270 iscsi_ep_disconnect(conn, is_active);
2272 spin_unlock_irq(&conn->lock);
2273 ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2274 mutex_unlock(&conn->ep_mutex);
2276 flush_work(&conn->cleanup_work);
2278 * Userspace is now done with the EP so we can release the ref
2279 * iscsi_cleanup_conn_work_fn took.
2281 iscsi_put_endpoint(ep);
2282 mutex_lock(&conn->ep_mutex);
2286 static int iscsi_if_stop_conn(struct iscsi_transport *transport,
2287 struct iscsi_uevent *ev)
2289 int flag = ev->u.stop_conn.flag;
2290 struct iscsi_cls_conn *conn;
2292 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
2296 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop.\n");
2298 * If this is a termination we have to call stop_conn with that flag
2299 * so the correct states get set. If we haven't run the work yet try to
2300 * avoid the extra run.
2302 if (flag == STOP_CONN_TERM) {
2303 cancel_work_sync(&conn->cleanup_work);
2304 iscsi_stop_conn(conn, flag);
2307 * For offload, when iscsid is restarted it won't know about
2308 * existing endpoints so it can't do a ep_disconnect. We clean
2309 * it up here for userspace.
2311 mutex_lock(&conn->ep_mutex);
2313 iscsi_if_disconnect_bound_ep(conn, conn->ep, true);
2314 mutex_unlock(&conn->ep_mutex);
2317 * Figure out if it was the kernel or userspace initiating this.
2319 spin_lock_irq(&conn->lock);
2320 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2321 spin_unlock_irq(&conn->lock);
2322 iscsi_stop_conn(conn, flag);
2324 spin_unlock_irq(&conn->lock);
2325 ISCSI_DBG_TRANS_CONN(conn,
2326 "flush kernel conn cleanup.\n");
2327 flush_work(&conn->cleanup_work);
2330 * Only clear for recovery to avoid extra cleanup runs during
2333 spin_lock_irq(&conn->lock);
2334 clear_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags);
2335 spin_unlock_irq(&conn->lock);
2337 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop done.\n");
2341 static void iscsi_cleanup_conn_work_fn(struct work_struct *work)
2343 struct iscsi_cls_conn *conn = container_of(work, struct iscsi_cls_conn,
2345 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2347 mutex_lock(&conn->ep_mutex);
2349 * Get a ref to the ep, so we don't release its ID until after
2350 * userspace is done referencing it in iscsi_if_disconnect_bound_ep.
2353 get_device(&conn->ep->dev);
2354 iscsi_ep_disconnect(conn, false);
2356 if (system_state != SYSTEM_RUNNING) {
2358 * If the user has set up for the session to never timeout
2359 * then hang like they wanted. For all other cases fail right
2360 * away since userspace is not going to relogin.
2362 if (session->recovery_tmo > 0)
2363 session->recovery_tmo = 0;
2366 iscsi_stop_conn(conn, STOP_CONN_RECOVER);
2367 mutex_unlock(&conn->ep_mutex);
2368 ISCSI_DBG_TRANS_CONN(conn, "cleanup done.\n");
2371 void iscsi_free_session(struct iscsi_cls_session *session)
2373 ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
2374 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
2375 put_device(&session->dev);
2377 EXPORT_SYMBOL_GPL(iscsi_free_session);
2380 * iscsi_create_conn - create iscsi class connection
2381 * @session: iscsi cls session
2382 * @dd_size: private driver data size
2383 * @cid: connection id
2385 * This can be called from a LLD or iscsi_transport. The connection
2386 * is child of the session so cid must be unique for all connections
2389 * Since we do not support MCS, cid will normally be zero. In some cases
2390 * for software iscsi we could be trying to preallocate a connection struct
2391 * in which case there could be two connection structs and cid would be
2394 struct iscsi_cls_conn *
2395 iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
2397 struct iscsi_transport *transport = session->transport;
2398 struct iscsi_cls_conn *conn;
2399 unsigned long flags;
2402 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
2406 conn->dd_data = &conn[1];
2408 mutex_init(&conn->ep_mutex);
2409 spin_lock_init(&conn->lock);
2410 INIT_LIST_HEAD(&conn->conn_list);
2411 INIT_WORK(&conn->cleanup_work, iscsi_cleanup_conn_work_fn);
2412 conn->transport = transport;
2414 WRITE_ONCE(conn->state, ISCSI_CONN_DOWN);
2416 /* this is released in the dev's release function */
2417 if (!get_device(&session->dev))
2420 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
2421 conn->dev.parent = &session->dev;
2422 conn->dev.release = iscsi_conn_release;
2423 err = device_register(&conn->dev);
2425 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2426 "register connection's dev\n");
2427 goto release_parent_ref;
2429 err = transport_register_device(&conn->dev);
2431 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2432 "register transport's dev\n");
2433 goto release_conn_ref;
2436 spin_lock_irqsave(&connlock, flags);
2437 list_add(&conn->conn_list, &connlist);
2438 spin_unlock_irqrestore(&connlock, flags);
2440 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
2444 device_unregister(&conn->dev);
2445 put_device(&session->dev);
2448 put_device(&session->dev);
2454 EXPORT_SYMBOL_GPL(iscsi_create_conn);
2457 * iscsi_destroy_conn - destroy iscsi class connection
2458 * @conn: iscsi cls session
2460 * This can be called from a LLD or iscsi_transport.
2462 int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
2464 unsigned long flags;
2466 spin_lock_irqsave(&connlock, flags);
2467 list_del(&conn->conn_list);
2468 spin_unlock_irqrestore(&connlock, flags);
2470 transport_unregister_device(&conn->dev);
2471 ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n");
2472 device_unregister(&conn->dev);
2475 EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
2477 void iscsi_put_conn(struct iscsi_cls_conn *conn)
2479 put_device(&conn->dev);
2481 EXPORT_SYMBOL_GPL(iscsi_put_conn);
2483 void iscsi_get_conn(struct iscsi_cls_conn *conn)
2485 get_device(&conn->dev);
2487 EXPORT_SYMBOL_GPL(iscsi_get_conn);
2490 * iscsi interface functions
2492 static struct iscsi_internal *
2493 iscsi_if_transport_lookup(struct iscsi_transport *tt)
2495 struct iscsi_internal *priv;
2496 unsigned long flags;
2498 spin_lock_irqsave(&iscsi_transport_lock, flags);
2499 list_for_each_entry(priv, &iscsi_transports, list) {
2500 if (tt == priv->iscsi_transport) {
2501 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2505 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2510 iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
2512 return nlmsg_multicast(nls, skb, 0, group, gfp);
2516 iscsi_unicast_skb(struct sk_buff *skb, u32 portid)
2518 return nlmsg_unicast(nls, skb, portid);
2521 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
2522 char *data, uint32_t data_size)
2524 struct nlmsghdr *nlh;
2525 struct sk_buff *skb;
2526 struct iscsi_uevent *ev;
2528 struct iscsi_internal *priv;
2529 int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
2532 priv = iscsi_if_transport_lookup(conn->transport);
2536 skb = alloc_skb(len, GFP_ATOMIC);
2538 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
2539 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
2540 "control PDU: OOM\n");
2544 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2545 ev = nlmsg_data(nlh);
2546 memset(ev, 0, sizeof(*ev));
2547 ev->transport_handle = iscsi_handle(conn->transport);
2548 ev->type = ISCSI_KEVENT_RECV_PDU;
2549 ev->r.recv_req.cid = conn->cid;
2550 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
2551 pdu = (char*)ev + sizeof(*ev);
2552 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
2553 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
2555 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2557 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
2559 int iscsi_offload_mesg(struct Scsi_Host *shost,
2560 struct iscsi_transport *transport, uint32_t type,
2561 char *data, uint16_t data_size)
2563 struct nlmsghdr *nlh;
2564 struct sk_buff *skb;
2565 struct iscsi_uevent *ev;
2566 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2568 skb = alloc_skb(len, GFP_ATOMIC);
2570 printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
2574 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2575 ev = nlmsg_data(nlh);
2576 memset(ev, 0, sizeof(*ev));
2578 ev->transport_handle = iscsi_handle(transport);
2580 case ISCSI_KEVENT_PATH_REQ:
2581 ev->r.req_path.host_no = shost->host_no;
2583 case ISCSI_KEVENT_IF_DOWN:
2584 ev->r.notify_if_down.host_no = shost->host_no;
2588 memcpy((char *)ev + sizeof(*ev), data, data_size);
2590 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
2592 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
2594 void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
2596 struct nlmsghdr *nlh;
2597 struct sk_buff *skb;
2598 struct iscsi_uevent *ev;
2599 struct iscsi_internal *priv;
2600 int len = nlmsg_total_size(sizeof(*ev));
2601 unsigned long flags;
2604 spin_lock_irqsave(&conn->lock, flags);
2606 * Userspace will only do a stop call if we are at least bound. And, we
2607 * only need to do the in kernel cleanup if in the UP state so cmds can
2608 * be released to upper layers. If in other states just wait for
2609 * userspace to avoid races that can leave the cleanup_work queued.
2611 state = READ_ONCE(conn->state);
2613 case ISCSI_CONN_BOUND:
2615 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP,
2617 queue_work(iscsi_conn_cleanup_workq,
2618 &conn->cleanup_work);
2622 ISCSI_DBG_TRANS_CONN(conn, "Got conn error in state %d\n",
2626 spin_unlock_irqrestore(&conn->lock, flags);
2628 priv = iscsi_if_transport_lookup(conn->transport);
2632 skb = alloc_skb(len, GFP_ATOMIC);
2634 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2635 "conn error (%d)\n", error);
2639 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2640 ev = nlmsg_data(nlh);
2641 ev->transport_handle = iscsi_handle(conn->transport);
2642 ev->type = ISCSI_KEVENT_CONN_ERROR;
2643 ev->r.connerror.error = error;
2644 ev->r.connerror.cid = conn->cid;
2645 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
2647 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2649 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
2652 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
2654 void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
2655 enum iscsi_conn_state state)
2657 struct nlmsghdr *nlh;
2658 struct sk_buff *skb;
2659 struct iscsi_uevent *ev;
2660 struct iscsi_internal *priv;
2661 int len = nlmsg_total_size(sizeof(*ev));
2663 priv = iscsi_if_transport_lookup(conn->transport);
2667 skb = alloc_skb(len, GFP_ATOMIC);
2669 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2670 "conn login (%d)\n", state);
2674 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2675 ev = nlmsg_data(nlh);
2676 ev->transport_handle = iscsi_handle(conn->transport);
2677 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
2678 ev->r.conn_login.state = state;
2679 ev->r.conn_login.cid = conn->cid;
2680 ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
2681 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2683 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
2686 EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
2688 void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
2689 enum iscsi_host_event_code code, uint32_t data_size,
2692 struct nlmsghdr *nlh;
2693 struct sk_buff *skb;
2694 struct iscsi_uevent *ev;
2695 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2697 skb = alloc_skb(len, GFP_NOIO);
2699 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
2704 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2705 ev = nlmsg_data(nlh);
2706 ev->transport_handle = iscsi_handle(transport);
2707 ev->type = ISCSI_KEVENT_HOST_EVENT;
2708 ev->r.host_event.host_no = host_no;
2709 ev->r.host_event.code = code;
2710 ev->r.host_event.data_size = data_size;
2713 memcpy((char *)ev + sizeof(*ev), data, data_size);
2715 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2717 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
2719 void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
2720 uint32_t status, uint32_t pid, uint32_t data_size,
2723 struct nlmsghdr *nlh;
2724 struct sk_buff *skb;
2725 struct iscsi_uevent *ev;
2726 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2728 skb = alloc_skb(len, GFP_NOIO);
2730 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
2734 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2735 ev = nlmsg_data(nlh);
2736 ev->transport_handle = iscsi_handle(transport);
2737 ev->type = ISCSI_KEVENT_PING_COMP;
2738 ev->r.ping_comp.host_no = host_no;
2739 ev->r.ping_comp.status = status;
2740 ev->r.ping_comp.pid = pid;
2741 ev->r.ping_comp.data_size = data_size;
2742 memcpy((char *)ev + sizeof(*ev), data, data_size);
2744 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2746 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
2749 iscsi_if_send_reply(u32 portid, int type, void *payload, int size)
2751 struct sk_buff *skb;
2752 struct nlmsghdr *nlh;
2753 int len = nlmsg_total_size(size);
2755 skb = alloc_skb(len, GFP_ATOMIC);
2757 printk(KERN_ERR "Could not allocate skb to send reply.\n");
2761 nlh = __nlmsg_put(skb, 0, 0, type, (len - sizeof(*nlh)), 0);
2762 memcpy(nlmsg_data(nlh), payload, size);
2763 return iscsi_unicast_skb(skb, portid);
2767 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
2769 struct iscsi_uevent *ev = nlmsg_data(nlh);
2770 struct iscsi_stats *stats;
2771 struct sk_buff *skbstat;
2772 struct iscsi_cls_conn *conn;
2773 struct nlmsghdr *nlhstat;
2774 struct iscsi_uevent *evstat;
2775 struct iscsi_internal *priv;
2776 int len = nlmsg_total_size(sizeof(*ev) +
2777 sizeof(struct iscsi_stats) +
2778 sizeof(struct iscsi_stats_custom) *
2779 ISCSI_STATS_CUSTOM_MAX);
2782 priv = iscsi_if_transport_lookup(transport);
2786 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
2793 skbstat = alloc_skb(len, GFP_ATOMIC);
2795 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
2796 "deliver stats: OOM\n");
2800 nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
2801 (len - sizeof(*nlhstat)), 0);
2802 evstat = nlmsg_data(nlhstat);
2803 memset(evstat, 0, sizeof(*evstat));
2804 evstat->transport_handle = iscsi_handle(conn->transport);
2805 evstat->type = nlh->nlmsg_type;
2806 evstat->u.get_stats.cid =
2807 ev->u.get_stats.cid;
2808 evstat->u.get_stats.sid =
2809 ev->u.get_stats.sid;
2810 stats = (struct iscsi_stats *)
2811 ((char*)evstat + sizeof(*evstat));
2812 memset(stats, 0, sizeof(*stats));
2814 transport->get_stats(conn, stats);
2815 actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
2816 sizeof(struct iscsi_stats) +
2817 sizeof(struct iscsi_stats_custom) *
2818 stats->custom_length);
2819 actual_size -= sizeof(*nlhstat);
2820 actual_size = nlmsg_msg_size(actual_size);
2821 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
2822 nlhstat->nlmsg_len = actual_size;
2824 err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
2826 } while (err < 0 && err != -ECONNREFUSED);
2832 * iscsi_session_event - send session destr. completion event
2833 * @session: iscsi class session
2834 * @event: type of event
2836 int iscsi_session_event(struct iscsi_cls_session *session,
2837 enum iscsi_uevent_e event)
2839 struct iscsi_internal *priv;
2840 struct Scsi_Host *shost;
2841 struct iscsi_uevent *ev;
2842 struct sk_buff *skb;
2843 struct nlmsghdr *nlh;
2844 int rc, len = nlmsg_total_size(sizeof(*ev));
2846 priv = iscsi_if_transport_lookup(session->transport);
2849 shost = iscsi_session_to_shost(session);
2851 skb = alloc_skb(len, GFP_KERNEL);
2853 iscsi_cls_session_printk(KERN_ERR, session,
2854 "Cannot notify userspace of session "
2855 "event %u\n", event);
2859 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2860 ev = nlmsg_data(nlh);
2861 ev->transport_handle = iscsi_handle(session->transport);
2865 case ISCSI_KEVENT_DESTROY_SESSION:
2866 ev->r.d_session.host_no = shost->host_no;
2867 ev->r.d_session.sid = session->sid;
2869 case ISCSI_KEVENT_CREATE_SESSION:
2870 ev->r.c_session_ret.host_no = shost->host_no;
2871 ev->r.c_session_ret.sid = session->sid;
2873 case ISCSI_KEVENT_UNBIND_SESSION:
2874 ev->r.unbind_session.host_no = shost->host_no;
2875 ev->r.unbind_session.sid = session->sid;
2878 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
2885 * this will occur if the daemon is not up, so we just warn
2886 * the user and when the daemon is restarted it will handle it
2888 rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
2890 iscsi_cls_session_printk(KERN_ERR, session,
2891 "Cannot notify userspace of session "
2892 "event %u. Check iscsi daemon\n",
2895 ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
2899 EXPORT_SYMBOL_GPL(iscsi_session_event);
2902 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
2903 struct iscsi_uevent *ev, pid_t pid,
2904 uint32_t initial_cmdsn, uint16_t cmds_max,
2905 uint16_t queue_depth)
2907 struct iscsi_transport *transport = priv->iscsi_transport;
2908 struct iscsi_cls_session *session;
2909 struct Scsi_Host *shost;
2911 session = transport->create_session(ep, cmds_max, queue_depth,
2916 session->creator = pid;
2917 shost = iscsi_session_to_shost(session);
2918 ev->r.c_session_ret.host_no = shost->host_no;
2919 ev->r.c_session_ret.sid = session->sid;
2920 ISCSI_DBG_TRANS_SESSION(session,
2921 "Completed creating transport session\n");
2926 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2928 struct iscsi_cls_conn *conn;
2929 struct iscsi_cls_session *session;
2931 session = iscsi_session_lookup(ev->u.c_conn.sid);
2933 printk(KERN_ERR "iscsi: invalid session %d.\n",
2938 conn = transport->create_conn(session, ev->u.c_conn.cid);
2940 iscsi_cls_session_printk(KERN_ERR, session,
2941 "couldn't create a new connection.");
2945 ev->r.c_conn_ret.sid = session->sid;
2946 ev->r.c_conn_ret.cid = conn->cid;
2948 ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
2953 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2955 struct iscsi_cls_conn *conn;
2957 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
2961 ISCSI_DBG_TRANS_CONN(conn, "Flushing cleanup during destruction\n");
2962 flush_work(&conn->cleanup_work);
2963 ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
2965 if (transport->destroy_conn)
2966 transport->destroy_conn(conn);
2971 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2973 char *data = (char*)ev + sizeof(*ev);
2974 struct iscsi_cls_conn *conn;
2975 struct iscsi_cls_session *session;
2976 int err = 0, value = 0, state;
2978 if (ev->u.set_param.len > PAGE_SIZE)
2981 session = iscsi_session_lookup(ev->u.set_param.sid);
2982 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
2983 if (!conn || !session)
2986 switch (ev->u.set_param.param) {
2987 case ISCSI_PARAM_SESS_RECOVERY_TMO:
2988 sscanf(data, "%d", &value);
2989 if (!session->recovery_tmo_sysfs_override)
2990 session->recovery_tmo = value;
2993 state = READ_ONCE(conn->state);
2994 if (state == ISCSI_CONN_BOUND || state == ISCSI_CONN_UP) {
2995 err = transport->set_param(conn, ev->u.set_param.param,
2996 data, ev->u.set_param.len);
3005 static int iscsi_if_ep_connect(struct iscsi_transport *transport,
3006 struct iscsi_uevent *ev, int msg_type)
3008 struct iscsi_endpoint *ep;
3009 struct sockaddr *dst_addr;
3010 struct Scsi_Host *shost = NULL;
3011 int non_blocking, err = 0;
3013 if (!transport->ep_connect)
3016 if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
3017 shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
3019 printk(KERN_ERR "ep connect failed. Could not find "
3021 ev->u.ep_connect_through_host.host_no);
3024 non_blocking = ev->u.ep_connect_through_host.non_blocking;
3026 non_blocking = ev->u.ep_connect.non_blocking;
3028 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3029 ep = transport->ep_connect(shost, dst_addr, non_blocking);
3035 ev->r.ep_connect_ret.handle = ep->id;
3038 scsi_host_put(shost);
3042 static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
3045 struct iscsi_cls_conn *conn;
3046 struct iscsi_endpoint *ep;
3048 if (!transport->ep_disconnect)
3051 ep = iscsi_lookup_endpoint(ep_handle);
3058 * conn was not even bound yet, so we can't get iscsi conn
3061 transport->ep_disconnect(ep);
3065 mutex_lock(&conn->ep_mutex);
3066 iscsi_if_disconnect_bound_ep(conn, ep, false);
3067 mutex_unlock(&conn->ep_mutex);
3069 iscsi_put_endpoint(ep);
3074 iscsi_if_transport_ep(struct iscsi_transport *transport,
3075 struct iscsi_uevent *ev, int msg_type)
3077 struct iscsi_endpoint *ep;
3081 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3082 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3083 rc = iscsi_if_ep_connect(transport, ev, msg_type);
3085 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3086 if (!transport->ep_poll)
3089 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
3093 ev->r.retcode = transport->ep_poll(ep,
3094 ev->u.ep_poll.timeout_ms);
3095 iscsi_put_endpoint(ep);
3097 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3098 rc = iscsi_if_ep_disconnect(transport,
3099 ev->u.ep_disconnect.ep_handle);
3106 iscsi_tgt_dscvr(struct iscsi_transport *transport,
3107 struct iscsi_uevent *ev)
3109 struct Scsi_Host *shost;
3110 struct sockaddr *dst_addr;
3113 if (!transport->tgt_dscvr)
3116 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
3118 printk(KERN_ERR "target discovery could not find host no %u\n",
3119 ev->u.tgt_dscvr.host_no);
3124 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3125 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
3126 ev->u.tgt_dscvr.enable, dst_addr);
3127 scsi_host_put(shost);
3132 iscsi_set_host_param(struct iscsi_transport *transport,
3133 struct iscsi_uevent *ev)
3135 char *data = (char*)ev + sizeof(*ev);
3136 struct Scsi_Host *shost;
3139 if (!transport->set_host_param)
3142 if (ev->u.set_host_param.len > PAGE_SIZE)
3145 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
3147 printk(KERN_ERR "set_host_param could not find host no %u\n",
3148 ev->u.set_host_param.host_no);
3152 err = transport->set_host_param(shost, ev->u.set_host_param.param,
3153 data, ev->u.set_host_param.len);
3154 scsi_host_put(shost);
3159 iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3161 struct Scsi_Host *shost;
3162 struct iscsi_path *params;
3165 if (!transport->set_path)
3168 shost = scsi_host_lookup(ev->u.set_path.host_no);
3170 printk(KERN_ERR "set path could not find host no %u\n",
3171 ev->u.set_path.host_no);
3175 params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
3176 err = transport->set_path(shost, params);
3178 scsi_host_put(shost);
3182 static int iscsi_session_has_conns(int sid)
3184 struct iscsi_cls_conn *conn;
3185 unsigned long flags;
3188 spin_lock_irqsave(&connlock, flags);
3189 list_for_each_entry(conn, &connlist, conn_list) {
3190 if (iscsi_conn_get_sid(conn) == sid) {
3195 spin_unlock_irqrestore(&connlock, flags);
3201 iscsi_set_iface_params(struct iscsi_transport *transport,
3202 struct iscsi_uevent *ev, uint32_t len)
3204 char *data = (char *)ev + sizeof(*ev);
3205 struct Scsi_Host *shost;
3208 if (!transport->set_iface_param)
3211 shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
3213 printk(KERN_ERR "set_iface_params could not find host no %u\n",
3214 ev->u.set_iface_params.host_no);
3218 err = transport->set_iface_param(shost, data, len);
3219 scsi_host_put(shost);
3224 iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3226 struct Scsi_Host *shost;
3227 struct sockaddr *dst_addr;
3230 if (!transport->send_ping)
3233 shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
3235 printk(KERN_ERR "iscsi_ping could not find host no %u\n",
3236 ev->u.iscsi_ping.host_no);
3240 dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
3241 err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
3242 ev->u.iscsi_ping.iface_type,
3243 ev->u.iscsi_ping.payload_size,
3244 ev->u.iscsi_ping.pid,
3246 scsi_host_put(shost);
3251 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3253 struct iscsi_uevent *ev = nlmsg_data(nlh);
3254 struct Scsi_Host *shost = NULL;
3255 struct iscsi_chap_rec *chap_rec;
3256 struct iscsi_internal *priv;
3257 struct sk_buff *skbchap;
3258 struct nlmsghdr *nlhchap;
3259 struct iscsi_uevent *evchap;
3260 uint32_t chap_buf_size;
3264 if (!transport->get_chap)
3267 priv = iscsi_if_transport_lookup(transport);
3271 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
3272 len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3274 shost = scsi_host_lookup(ev->u.get_chap.host_no);
3276 printk(KERN_ERR "%s: failed. Could not find host no %u\n",
3277 __func__, ev->u.get_chap.host_no);
3284 skbchap = alloc_skb(len, GFP_KERNEL);
3286 printk(KERN_ERR "can not deliver chap: OOM\n");
3291 nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
3292 (len - sizeof(*nlhchap)), 0);
3293 evchap = nlmsg_data(nlhchap);
3294 memset(evchap, 0, sizeof(*evchap));
3295 evchap->transport_handle = iscsi_handle(transport);
3296 evchap->type = nlh->nlmsg_type;
3297 evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
3298 evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
3299 evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
3300 buf = (char *)evchap + sizeof(*evchap);
3301 memset(buf, 0, chap_buf_size);
3303 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
3304 &evchap->u.get_chap.num_entries, buf);
3306 actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3307 skb_trim(skbchap, NLMSG_ALIGN(actual_size));
3308 nlhchap->nlmsg_len = actual_size;
3310 err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
3312 } while (err < 0 && err != -ECONNREFUSED);
3315 scsi_host_put(shost);
3319 static int iscsi_set_chap(struct iscsi_transport *transport,
3320 struct iscsi_uevent *ev, uint32_t len)
3322 char *data = (char *)ev + sizeof(*ev);
3323 struct Scsi_Host *shost;
3326 if (!transport->set_chap)
3329 shost = scsi_host_lookup(ev->u.set_path.host_no);
3331 pr_err("%s could not find host no %u\n",
3332 __func__, ev->u.set_path.host_no);
3336 err = transport->set_chap(shost, data, len);
3337 scsi_host_put(shost);
3341 static int iscsi_delete_chap(struct iscsi_transport *transport,
3342 struct iscsi_uevent *ev)
3344 struct Scsi_Host *shost;
3347 if (!transport->delete_chap)
3350 shost = scsi_host_lookup(ev->u.delete_chap.host_no);
3352 printk(KERN_ERR "%s could not find host no %u\n",
3353 __func__, ev->u.delete_chap.host_no);
3357 err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
3358 scsi_host_put(shost);
3362 static const struct {
3363 enum iscsi_discovery_parent_type value;
3365 } iscsi_discovery_parent_names[] = {
3366 {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
3367 {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
3368 {ISCSI_DISC_PARENT_ISNS, "isns" },
3371 char *iscsi_get_discovery_parent_name(int parent_type)
3374 char *state = "Unknown!";
3376 for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
3377 if (iscsi_discovery_parent_names[i].value & parent_type) {
3378 state = iscsi_discovery_parent_names[i].name;
3384 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
3386 static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
3387 struct iscsi_uevent *ev, uint32_t len)
3389 char *data = (char *)ev + sizeof(*ev);
3390 struct Scsi_Host *shost;
3391 struct iscsi_bus_flash_session *fnode_sess;
3392 struct iscsi_bus_flash_conn *fnode_conn;
3397 if (!transport->set_flashnode_param) {
3399 goto exit_set_fnode;
3402 shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
3404 pr_err("%s could not find host no %u\n",
3405 __func__, ev->u.set_flashnode.host_no);
3407 goto exit_set_fnode;
3410 idx = ev->u.set_flashnode.flashnode_idx;
3411 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3413 pr_err("%s could not find flashnode %u for host no %u\n",
3414 __func__, idx, ev->u.set_flashnode.host_no);
3419 dev = iscsi_find_flashnode_conn(fnode_sess);
3425 fnode_conn = iscsi_dev_to_flash_conn(dev);
3426 err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
3430 put_device(&fnode_sess->dev);
3433 scsi_host_put(shost);
3439 static int iscsi_new_flashnode(struct iscsi_transport *transport,
3440 struct iscsi_uevent *ev, uint32_t len)
3442 char *data = (char *)ev + sizeof(*ev);
3443 struct Scsi_Host *shost;
3447 if (!transport->new_flashnode) {
3449 goto exit_new_fnode;
3452 shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
3454 pr_err("%s could not find host no %u\n",
3455 __func__, ev->u.new_flashnode.host_no);
3460 index = transport->new_flashnode(shost, data, len);
3463 ev->r.new_flashnode_ret.flashnode_idx = index;
3468 scsi_host_put(shost);
3474 static int iscsi_del_flashnode(struct iscsi_transport *transport,
3475 struct iscsi_uevent *ev)
3477 struct Scsi_Host *shost;
3478 struct iscsi_bus_flash_session *fnode_sess;
3482 if (!transport->del_flashnode) {
3484 goto exit_del_fnode;
3487 shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
3489 pr_err("%s could not find host no %u\n",
3490 __func__, ev->u.del_flashnode.host_no);
3495 idx = ev->u.del_flashnode.flashnode_idx;
3496 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3498 pr_err("%s could not find flashnode %u for host no %u\n",
3499 __func__, idx, ev->u.del_flashnode.host_no);
3504 err = transport->del_flashnode(fnode_sess);
3505 put_device(&fnode_sess->dev);
3508 scsi_host_put(shost);
3514 static int iscsi_login_flashnode(struct iscsi_transport *transport,
3515 struct iscsi_uevent *ev)
3517 struct Scsi_Host *shost;
3518 struct iscsi_bus_flash_session *fnode_sess;
3519 struct iscsi_bus_flash_conn *fnode_conn;
3524 if (!transport->login_flashnode) {
3526 goto exit_login_fnode;
3529 shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
3531 pr_err("%s could not find host no %u\n",
3532 __func__, ev->u.login_flashnode.host_no);
3537 idx = ev->u.login_flashnode.flashnode_idx;
3538 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3540 pr_err("%s could not find flashnode %u for host no %u\n",
3541 __func__, idx, ev->u.login_flashnode.host_no);
3546 dev = iscsi_find_flashnode_conn(fnode_sess);
3552 fnode_conn = iscsi_dev_to_flash_conn(dev);
3553 err = transport->login_flashnode(fnode_sess, fnode_conn);
3557 put_device(&fnode_sess->dev);
3560 scsi_host_put(shost);
3566 static int iscsi_logout_flashnode(struct iscsi_transport *transport,
3567 struct iscsi_uevent *ev)
3569 struct Scsi_Host *shost;
3570 struct iscsi_bus_flash_session *fnode_sess;
3571 struct iscsi_bus_flash_conn *fnode_conn;
3576 if (!transport->logout_flashnode) {
3578 goto exit_logout_fnode;
3581 shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
3583 pr_err("%s could not find host no %u\n",
3584 __func__, ev->u.logout_flashnode.host_no);
3589 idx = ev->u.logout_flashnode.flashnode_idx;
3590 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3592 pr_err("%s could not find flashnode %u for host no %u\n",
3593 __func__, idx, ev->u.logout_flashnode.host_no);
3598 dev = iscsi_find_flashnode_conn(fnode_sess);
3604 fnode_conn = iscsi_dev_to_flash_conn(dev);
3606 err = transport->logout_flashnode(fnode_sess, fnode_conn);
3610 put_device(&fnode_sess->dev);
3613 scsi_host_put(shost);
3619 static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
3620 struct iscsi_uevent *ev)
3622 struct Scsi_Host *shost;
3623 struct iscsi_cls_session *session;
3626 if (!transport->logout_flashnode_sid) {
3628 goto exit_logout_sid;
3631 shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
3633 pr_err("%s could not find host no %u\n",
3634 __func__, ev->u.logout_flashnode.host_no);
3639 session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
3641 pr_err("%s could not find session id %u\n",
3642 __func__, ev->u.logout_flashnode_sid.sid);
3647 err = transport->logout_flashnode_sid(session);
3650 scsi_host_put(shost);
3657 iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3659 struct iscsi_uevent *ev = nlmsg_data(nlh);
3660 struct Scsi_Host *shost = NULL;
3661 struct iscsi_internal *priv;
3662 struct sk_buff *skbhost_stats;
3663 struct nlmsghdr *nlhhost_stats;
3664 struct iscsi_uevent *evhost_stats;
3665 int host_stats_size = 0;
3669 if (!transport->get_host_stats)
3672 priv = iscsi_if_transport_lookup(transport);
3676 host_stats_size = sizeof(struct iscsi_offload_host_stats);
3677 len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3679 shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
3681 pr_err("%s: failed. Could not find host no %u\n",
3682 __func__, ev->u.get_host_stats.host_no);
3689 skbhost_stats = alloc_skb(len, GFP_KERNEL);
3690 if (!skbhost_stats) {
3691 pr_err("cannot deliver host stats: OOM\n");
3693 goto exit_host_stats;
3696 nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
3697 (len - sizeof(*nlhhost_stats)), 0);
3698 evhost_stats = nlmsg_data(nlhhost_stats);
3699 memset(evhost_stats, 0, sizeof(*evhost_stats));
3700 evhost_stats->transport_handle = iscsi_handle(transport);
3701 evhost_stats->type = nlh->nlmsg_type;
3702 evhost_stats->u.get_host_stats.host_no =
3703 ev->u.get_host_stats.host_no;
3704 buf = (char *)evhost_stats + sizeof(*evhost_stats);
3705 memset(buf, 0, host_stats_size);
3707 err = transport->get_host_stats(shost, buf, host_stats_size);
3709 kfree_skb(skbhost_stats);
3710 goto exit_host_stats;
3713 actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3714 skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
3715 nlhhost_stats->nlmsg_len = actual_size;
3717 err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
3719 } while (err < 0 && err != -ECONNREFUSED);
3722 scsi_host_put(shost);
3726 static int iscsi_if_transport_conn(struct iscsi_transport *transport,
3727 struct nlmsghdr *nlh)
3729 struct iscsi_uevent *ev = nlmsg_data(nlh);
3730 struct iscsi_cls_session *session;
3731 struct iscsi_cls_conn *conn = NULL;
3732 struct iscsi_endpoint *ep;
3736 switch (nlh->nlmsg_type) {
3737 case ISCSI_UEVENT_CREATE_CONN:
3738 return iscsi_if_create_conn(transport, ev);
3739 case ISCSI_UEVENT_DESTROY_CONN:
3740 return iscsi_if_destroy_conn(transport, ev);
3741 case ISCSI_UEVENT_STOP_CONN:
3742 return iscsi_if_stop_conn(transport, ev);
3746 * The following cmds need to be run under the ep_mutex so in kernel
3747 * conn cleanup (ep_disconnect + unbind and conn) is not done while
3748 * these are running. They also must not run if we have just run a conn
3749 * cleanup because they would set the state in a way that might allow
3750 * IO or send IO themselves.
3752 switch (nlh->nlmsg_type) {
3753 case ISCSI_UEVENT_START_CONN:
3754 conn = iscsi_conn_lookup(ev->u.start_conn.sid,
3755 ev->u.start_conn.cid);
3757 case ISCSI_UEVENT_BIND_CONN:
3758 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
3760 case ISCSI_UEVENT_SEND_PDU:
3761 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
3768 mutex_lock(&conn->ep_mutex);
3769 spin_lock_irq(&conn->lock);
3770 if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
3771 spin_unlock_irq(&conn->lock);
3772 mutex_unlock(&conn->ep_mutex);
3773 ev->r.retcode = -ENOTCONN;
3776 spin_unlock_irq(&conn->lock);
3778 switch (nlh->nlmsg_type) {
3779 case ISCSI_UEVENT_BIND_CONN:
3780 session = iscsi_session_lookup(ev->u.b_conn.sid);
3786 ev->r.retcode = transport->bind_conn(session, conn,
3787 ev->u.b_conn.transport_eph,
3788 ev->u.b_conn.is_leading);
3790 WRITE_ONCE(conn->state, ISCSI_CONN_BOUND);
3792 if (ev->r.retcode || !transport->ep_connect)
3795 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
3799 iscsi_put_endpoint(ep);
3802 iscsi_cls_conn_printk(KERN_ERR, conn,
3803 "Could not set ep conn binding\n");
3806 case ISCSI_UEVENT_START_CONN:
3807 ev->r.retcode = transport->start_conn(conn);
3809 WRITE_ONCE(conn->state, ISCSI_CONN_UP);
3812 case ISCSI_UEVENT_SEND_PDU:
3813 pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
3815 if ((ev->u.send_pdu.hdr_size > pdu_len) ||
3816 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
3821 ev->r.retcode = transport->send_pdu(conn,
3822 (struct iscsi_hdr *)((char *)ev + sizeof(*ev)),
3823 (char *)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
3824 ev->u.send_pdu.data_size);
3830 mutex_unlock(&conn->ep_mutex);
3835 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
3839 struct iscsi_uevent *ev = nlmsg_data(nlh);
3840 struct iscsi_transport *transport = NULL;
3841 struct iscsi_internal *priv;
3842 struct iscsi_cls_session *session;
3843 struct iscsi_endpoint *ep = NULL;
3845 if (!netlink_capable(skb, CAP_SYS_ADMIN))
3848 if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
3849 *group = ISCSI_NL_GRP_UIP;
3851 *group = ISCSI_NL_GRP_ISCSID;
3853 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
3856 transport = priv->iscsi_transport;
3858 if (!try_module_get(transport->owner))
3861 portid = NETLINK_CB(skb).portid;
3863 switch (nlh->nlmsg_type) {
3864 case ISCSI_UEVENT_CREATE_SESSION:
3865 err = iscsi_if_create_session(priv, ep, ev,
3867 ev->u.c_session.initial_cmdsn,
3868 ev->u.c_session.cmds_max,
3869 ev->u.c_session.queue_depth);
3871 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
3872 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
3878 err = iscsi_if_create_session(priv, ep, ev,
3880 ev->u.c_bound_session.initial_cmdsn,
3881 ev->u.c_bound_session.cmds_max,
3882 ev->u.c_bound_session.queue_depth);
3883 iscsi_put_endpoint(ep);
3885 case ISCSI_UEVENT_DESTROY_SESSION:
3886 session = iscsi_session_lookup(ev->u.d_session.sid);
3889 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3892 transport->destroy_session(session);
3894 case ISCSI_UEVENT_DESTROY_SESSION_ASYNC:
3895 session = iscsi_session_lookup(ev->u.d_session.sid);
3898 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3901 unsigned long flags;
3903 /* Prevent this session from being found again */
3904 spin_lock_irqsave(&sesslock, flags);
3905 list_del_init(&session->sess_list);
3906 spin_unlock_irqrestore(&sesslock, flags);
3908 queue_work(system_unbound_wq, &session->destroy_work);
3911 case ISCSI_UEVENT_UNBIND_SESSION:
3912 session = iscsi_session_lookup(ev->u.d_session.sid);
3914 scsi_queue_work(iscsi_session_to_shost(session),
3915 &session->unbind_work);
3919 case ISCSI_UEVENT_SET_PARAM:
3920 err = iscsi_set_param(transport, ev);
3922 case ISCSI_UEVENT_CREATE_CONN:
3923 case ISCSI_UEVENT_DESTROY_CONN:
3924 case ISCSI_UEVENT_STOP_CONN:
3925 case ISCSI_UEVENT_START_CONN:
3926 case ISCSI_UEVENT_BIND_CONN:
3927 case ISCSI_UEVENT_SEND_PDU:
3928 err = iscsi_if_transport_conn(transport, nlh);
3930 case ISCSI_UEVENT_GET_STATS:
3931 err = iscsi_if_get_stats(transport, nlh);
3933 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3934 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3935 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3936 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3937 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
3939 case ISCSI_UEVENT_TGT_DSCVR:
3940 err = iscsi_tgt_dscvr(transport, ev);
3942 case ISCSI_UEVENT_SET_HOST_PARAM:
3943 err = iscsi_set_host_param(transport, ev);
3945 case ISCSI_UEVENT_PATH_UPDATE:
3946 err = iscsi_set_path(transport, ev);
3948 case ISCSI_UEVENT_SET_IFACE_PARAMS:
3949 err = iscsi_set_iface_params(transport, ev,
3950 nlmsg_attrlen(nlh, sizeof(*ev)));
3952 case ISCSI_UEVENT_PING:
3953 err = iscsi_send_ping(transport, ev);
3955 case ISCSI_UEVENT_GET_CHAP:
3956 err = iscsi_get_chap(transport, nlh);
3958 case ISCSI_UEVENT_DELETE_CHAP:
3959 err = iscsi_delete_chap(transport, ev);
3961 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
3962 err = iscsi_set_flashnode_param(transport, ev,
3966 case ISCSI_UEVENT_NEW_FLASHNODE:
3967 err = iscsi_new_flashnode(transport, ev,
3968 nlmsg_attrlen(nlh, sizeof(*ev)));
3970 case ISCSI_UEVENT_DEL_FLASHNODE:
3971 err = iscsi_del_flashnode(transport, ev);
3973 case ISCSI_UEVENT_LOGIN_FLASHNODE:
3974 err = iscsi_login_flashnode(transport, ev);
3976 case ISCSI_UEVENT_LOGOUT_FLASHNODE:
3977 err = iscsi_logout_flashnode(transport, ev);
3979 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
3980 err = iscsi_logout_flashnode_sid(transport, ev);
3982 case ISCSI_UEVENT_SET_CHAP:
3983 err = iscsi_set_chap(transport, ev,
3984 nlmsg_attrlen(nlh, sizeof(*ev)));
3986 case ISCSI_UEVENT_GET_HOST_STATS:
3987 err = iscsi_get_host_stats(transport, nlh);
3994 module_put(transport->owner);
3999 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
4000 * Malformed skbs with wrong lengths or invalid creds are not processed.
4003 iscsi_if_rx(struct sk_buff *skb)
4005 u32 portid = NETLINK_CB(skb).portid;
4007 mutex_lock(&rx_queue_mutex);
4008 while (skb->len >= NLMSG_HDRLEN) {
4011 struct nlmsghdr *nlh;
4012 struct iscsi_uevent *ev;
4014 int retries = ISCSI_SEND_MAX_ALLOWED;
4016 nlh = nlmsg_hdr(skb);
4017 if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
4018 skb->len < nlh->nlmsg_len) {
4022 ev = nlmsg_data(nlh);
4023 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
4024 if (rlen > skb->len)
4027 err = iscsi_if_recv_msg(skb, nlh, &group);
4029 ev->type = ISCSI_KEVENT_IF_ERROR;
4034 * special case for GET_STATS:
4035 * on success - sending reply and stats from
4036 * inside of if_recv_msg(),
4037 * on error - fall through.
4039 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
4041 if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
4043 err = iscsi_if_send_reply(portid, nlh->nlmsg_type,
4045 if (err == -EAGAIN && --retries < 0) {
4046 printk(KERN_WARNING "Send reply failed, error %d\n", err);
4049 } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
4050 skb_pull(skb, rlen);
4052 mutex_unlock(&rx_queue_mutex);
4055 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
4056 struct device_attribute dev_attr_##_prefix##_##_name = \
4057 __ATTR(_name,_mode,_show,_store)
4060 * iSCSI connection attrs
4062 #define iscsi_conn_attr_show(param) \
4064 show_conn_param_##param(struct device *dev, \
4065 struct device_attribute *attr, char *buf) \
4067 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4068 struct iscsi_transport *t = conn->transport; \
4069 return t->get_conn_param(conn, param, buf); \
4072 #define iscsi_conn_attr(field, param) \
4073 iscsi_conn_attr_show(param) \
4074 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
4077 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
4078 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
4079 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
4080 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
4081 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
4082 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
4083 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
4084 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
4085 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
4086 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
4087 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
4088 iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
4089 iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
4090 iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
4091 iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
4092 iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
4093 iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
4094 iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
4095 iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
4096 iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
4097 iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
4098 iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
4099 iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
4100 iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
4101 iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
4102 iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
4103 iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
4104 iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
4106 static const char *const connection_state_names[] = {
4107 [ISCSI_CONN_UP] = "up",
4108 [ISCSI_CONN_DOWN] = "down",
4109 [ISCSI_CONN_FAILED] = "failed",
4110 [ISCSI_CONN_BOUND] = "bound"
4113 static ssize_t show_conn_state(struct device *dev,
4114 struct device_attribute *attr, char *buf)
4116 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent);
4117 const char *state = "unknown";
4118 int conn_state = READ_ONCE(conn->state);
4120 if (conn_state >= 0 &&
4121 conn_state < ARRAY_SIZE(connection_state_names))
4122 state = connection_state_names[conn_state];
4124 return sysfs_emit(buf, "%s\n", state);
4126 static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
4129 #define iscsi_conn_ep_attr_show(param) \
4130 static ssize_t show_conn_ep_param_##param(struct device *dev, \
4131 struct device_attribute *attr,\
4134 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4135 struct iscsi_transport *t = conn->transport; \
4136 struct iscsi_endpoint *ep; \
4140 * Need to make sure ep_disconnect does not free the LLD's \
4141 * interconnect resources while we are trying to read them. \
4143 mutex_lock(&conn->ep_mutex); \
4145 if (!ep && t->ep_connect) { \
4146 mutex_unlock(&conn->ep_mutex); \
4151 rc = t->get_ep_param(ep, param, buf); \
4153 rc = t->get_conn_param(conn, param, buf); \
4154 mutex_unlock(&conn->ep_mutex); \
4158 #define iscsi_conn_ep_attr(field, param) \
4159 iscsi_conn_ep_attr_show(param) \
4160 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
4161 show_conn_ep_param_##param, NULL);
4163 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
4164 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
4166 static struct attribute *iscsi_conn_attrs[] = {
4167 &dev_attr_conn_max_recv_dlength.attr,
4168 &dev_attr_conn_max_xmit_dlength.attr,
4169 &dev_attr_conn_header_digest.attr,
4170 &dev_attr_conn_data_digest.attr,
4171 &dev_attr_conn_ifmarker.attr,
4172 &dev_attr_conn_ofmarker.attr,
4173 &dev_attr_conn_address.attr,
4174 &dev_attr_conn_port.attr,
4175 &dev_attr_conn_exp_statsn.attr,
4176 &dev_attr_conn_persistent_address.attr,
4177 &dev_attr_conn_persistent_port.attr,
4178 &dev_attr_conn_ping_tmo.attr,
4179 &dev_attr_conn_recv_tmo.attr,
4180 &dev_attr_conn_local_port.attr,
4181 &dev_attr_conn_statsn.attr,
4182 &dev_attr_conn_keepalive_tmo.attr,
4183 &dev_attr_conn_max_segment_size.attr,
4184 &dev_attr_conn_tcp_timestamp_stat.attr,
4185 &dev_attr_conn_tcp_wsf_disable.attr,
4186 &dev_attr_conn_tcp_nagle_disable.attr,
4187 &dev_attr_conn_tcp_timer_scale.attr,
4188 &dev_attr_conn_tcp_timestamp_enable.attr,
4189 &dev_attr_conn_fragment_disable.attr,
4190 &dev_attr_conn_ipv4_tos.attr,
4191 &dev_attr_conn_ipv6_traffic_class.attr,
4192 &dev_attr_conn_ipv6_flow_label.attr,
4193 &dev_attr_conn_is_fw_assigned_ipv6.attr,
4194 &dev_attr_conn_tcp_xmit_wsf.attr,
4195 &dev_attr_conn_tcp_recv_wsf.attr,
4196 &dev_attr_conn_local_ipaddr.attr,
4197 &dev_attr_conn_state.attr,
4201 static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
4202 struct attribute *attr, int i)
4204 struct device *cdev = container_of(kobj, struct device, kobj);
4205 struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
4206 struct iscsi_transport *t = conn->transport;
4209 if (attr == &dev_attr_conn_max_recv_dlength.attr)
4210 param = ISCSI_PARAM_MAX_RECV_DLENGTH;
4211 else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
4212 param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
4213 else if (attr == &dev_attr_conn_header_digest.attr)
4214 param = ISCSI_PARAM_HDRDGST_EN;
4215 else if (attr == &dev_attr_conn_data_digest.attr)
4216 param = ISCSI_PARAM_DATADGST_EN;
4217 else if (attr == &dev_attr_conn_ifmarker.attr)
4218 param = ISCSI_PARAM_IFMARKER_EN;
4219 else if (attr == &dev_attr_conn_ofmarker.attr)
4220 param = ISCSI_PARAM_OFMARKER_EN;
4221 else if (attr == &dev_attr_conn_address.attr)
4222 param = ISCSI_PARAM_CONN_ADDRESS;
4223 else if (attr == &dev_attr_conn_port.attr)
4224 param = ISCSI_PARAM_CONN_PORT;
4225 else if (attr == &dev_attr_conn_exp_statsn.attr)
4226 param = ISCSI_PARAM_EXP_STATSN;
4227 else if (attr == &dev_attr_conn_persistent_address.attr)
4228 param = ISCSI_PARAM_PERSISTENT_ADDRESS;
4229 else if (attr == &dev_attr_conn_persistent_port.attr)
4230 param = ISCSI_PARAM_PERSISTENT_PORT;
4231 else if (attr == &dev_attr_conn_ping_tmo.attr)
4232 param = ISCSI_PARAM_PING_TMO;
4233 else if (attr == &dev_attr_conn_recv_tmo.attr)
4234 param = ISCSI_PARAM_RECV_TMO;
4235 else if (attr == &dev_attr_conn_local_port.attr)
4236 param = ISCSI_PARAM_LOCAL_PORT;
4237 else if (attr == &dev_attr_conn_statsn.attr)
4238 param = ISCSI_PARAM_STATSN;
4239 else if (attr == &dev_attr_conn_keepalive_tmo.attr)
4240 param = ISCSI_PARAM_KEEPALIVE_TMO;
4241 else if (attr == &dev_attr_conn_max_segment_size.attr)
4242 param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
4243 else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
4244 param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
4245 else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
4246 param = ISCSI_PARAM_TCP_WSF_DISABLE;
4247 else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
4248 param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
4249 else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
4250 param = ISCSI_PARAM_TCP_TIMER_SCALE;
4251 else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
4252 param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
4253 else if (attr == &dev_attr_conn_fragment_disable.attr)
4254 param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
4255 else if (attr == &dev_attr_conn_ipv4_tos.attr)
4256 param = ISCSI_PARAM_IPV4_TOS;
4257 else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
4258 param = ISCSI_PARAM_IPV6_TC;
4259 else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
4260 param = ISCSI_PARAM_IPV6_FLOW_LABEL;
4261 else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
4262 param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
4263 else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
4264 param = ISCSI_PARAM_TCP_XMIT_WSF;
4265 else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
4266 param = ISCSI_PARAM_TCP_RECV_WSF;
4267 else if (attr == &dev_attr_conn_local_ipaddr.attr)
4268 param = ISCSI_PARAM_LOCAL_IPADDR;
4269 else if (attr == &dev_attr_conn_state.attr)
4272 WARN_ONCE(1, "Invalid conn attr");
4276 return t->attr_is_visible(ISCSI_PARAM, param);
4279 static struct attribute_group iscsi_conn_group = {
4280 .attrs = iscsi_conn_attrs,
4281 .is_visible = iscsi_conn_attr_is_visible,
4285 * iSCSI session attrs
4287 #define iscsi_session_attr_show(param, perm) \
4289 show_session_param_##param(struct device *dev, \
4290 struct device_attribute *attr, char *buf) \
4292 struct iscsi_cls_session *session = \
4293 iscsi_dev_to_session(dev->parent); \
4294 struct iscsi_transport *t = session->transport; \
4296 if (perm && !capable(CAP_SYS_ADMIN)) \
4298 return t->get_session_param(session, param, buf); \
4301 #define iscsi_session_attr(field, param, perm) \
4302 iscsi_session_attr_show(param, perm) \
4303 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
4305 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
4306 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
4307 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
4308 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
4309 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
4310 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
4311 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
4312 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
4313 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
4314 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
4315 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
4316 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
4317 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
4318 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
4319 iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
4320 iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
4321 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
4322 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
4323 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
4324 iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
4325 iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
4326 iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
4327 iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
4328 iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
4329 iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
4330 iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
4331 iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
4332 iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
4333 iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
4334 iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
4335 iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
4336 iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
4337 iscsi_session_attr(discovery_auth_optional,
4338 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
4339 iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
4340 iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
4341 iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
4342 iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
4343 iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
4344 iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
4345 iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
4348 show_priv_session_state(struct device *dev, struct device_attribute *attr,
4351 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4352 return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
4354 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
4357 show_priv_session_creator(struct device *dev, struct device_attribute *attr,
4360 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4361 return sysfs_emit(buf, "%d\n", session->creator);
4363 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
4366 show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
4369 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4370 return sysfs_emit(buf, "%d\n", session->target_id);
4372 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
4373 show_priv_session_target_id, NULL);
4375 #define iscsi_priv_session_attr_show(field, format) \
4377 show_priv_session_##field(struct device *dev, \
4378 struct device_attribute *attr, char *buf) \
4380 struct iscsi_cls_session *session = \
4381 iscsi_dev_to_session(dev->parent); \
4382 if (session->field == -1) \
4383 return sysfs_emit(buf, "off\n"); \
4384 return sysfs_emit(buf, format"\n", session->field); \
4387 #define iscsi_priv_session_attr_store(field) \
4389 store_priv_session_##field(struct device *dev, \
4390 struct device_attribute *attr, \
4391 const char *buf, size_t count) \
4395 struct iscsi_cls_session *session = \
4396 iscsi_dev_to_session(dev->parent); \
4397 if ((session->state == ISCSI_SESSION_FREE) || \
4398 (session->state == ISCSI_SESSION_FAILED)) \
4400 if (strncmp(buf, "off", 3) == 0) { \
4401 session->field = -1; \
4402 session->field##_sysfs_override = true; \
4404 val = simple_strtoul(buf, &cp, 0); \
4405 if (*cp != '\0' && *cp != '\n') \
4407 session->field = val; \
4408 session->field##_sysfs_override = true; \
4413 #define iscsi_priv_session_rw_attr(field, format) \
4414 iscsi_priv_session_attr_show(field, format) \
4415 iscsi_priv_session_attr_store(field) \
4416 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
4417 show_priv_session_##field, \
4418 store_priv_session_##field)
4420 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
4422 static struct attribute *iscsi_session_attrs[] = {
4423 &dev_attr_sess_initial_r2t.attr,
4424 &dev_attr_sess_max_outstanding_r2t.attr,
4425 &dev_attr_sess_immediate_data.attr,
4426 &dev_attr_sess_first_burst_len.attr,
4427 &dev_attr_sess_max_burst_len.attr,
4428 &dev_attr_sess_data_pdu_in_order.attr,
4429 &dev_attr_sess_data_seq_in_order.attr,
4430 &dev_attr_sess_erl.attr,
4431 &dev_attr_sess_targetname.attr,
4432 &dev_attr_sess_tpgt.attr,
4433 &dev_attr_sess_password.attr,
4434 &dev_attr_sess_password_in.attr,
4435 &dev_attr_sess_username.attr,
4436 &dev_attr_sess_username_in.attr,
4437 &dev_attr_sess_fast_abort.attr,
4438 &dev_attr_sess_abort_tmo.attr,
4439 &dev_attr_sess_lu_reset_tmo.attr,
4440 &dev_attr_sess_tgt_reset_tmo.attr,
4441 &dev_attr_sess_ifacename.attr,
4442 &dev_attr_sess_initiatorname.attr,
4443 &dev_attr_sess_targetalias.attr,
4444 &dev_attr_sess_boot_root.attr,
4445 &dev_attr_sess_boot_nic.attr,
4446 &dev_attr_sess_boot_target.attr,
4447 &dev_attr_priv_sess_recovery_tmo.attr,
4448 &dev_attr_priv_sess_state.attr,
4449 &dev_attr_priv_sess_creator.attr,
4450 &dev_attr_sess_chap_out_idx.attr,
4451 &dev_attr_sess_chap_in_idx.attr,
4452 &dev_attr_priv_sess_target_id.attr,
4453 &dev_attr_sess_auto_snd_tgt_disable.attr,
4454 &dev_attr_sess_discovery_session.attr,
4455 &dev_attr_sess_portal_type.attr,
4456 &dev_attr_sess_chap_auth.attr,
4457 &dev_attr_sess_discovery_logout.attr,
4458 &dev_attr_sess_bidi_chap.attr,
4459 &dev_attr_sess_discovery_auth_optional.attr,
4460 &dev_attr_sess_def_time2wait.attr,
4461 &dev_attr_sess_def_time2retain.attr,
4462 &dev_attr_sess_isid.attr,
4463 &dev_attr_sess_tsid.attr,
4464 &dev_attr_sess_def_taskmgmt_tmo.attr,
4465 &dev_attr_sess_discovery_parent_idx.attr,
4466 &dev_attr_sess_discovery_parent_type.attr,
4470 static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
4471 struct attribute *attr, int i)
4473 struct device *cdev = container_of(kobj, struct device, kobj);
4474 struct iscsi_cls_session *session = transport_class_to_session(cdev);
4475 struct iscsi_transport *t = session->transport;
4478 if (attr == &dev_attr_sess_initial_r2t.attr)
4479 param = ISCSI_PARAM_INITIAL_R2T_EN;
4480 else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
4481 param = ISCSI_PARAM_MAX_R2T;
4482 else if (attr == &dev_attr_sess_immediate_data.attr)
4483 param = ISCSI_PARAM_IMM_DATA_EN;
4484 else if (attr == &dev_attr_sess_first_burst_len.attr)
4485 param = ISCSI_PARAM_FIRST_BURST;
4486 else if (attr == &dev_attr_sess_max_burst_len.attr)
4487 param = ISCSI_PARAM_MAX_BURST;
4488 else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
4489 param = ISCSI_PARAM_PDU_INORDER_EN;
4490 else if (attr == &dev_attr_sess_data_seq_in_order.attr)
4491 param = ISCSI_PARAM_DATASEQ_INORDER_EN;
4492 else if (attr == &dev_attr_sess_erl.attr)
4493 param = ISCSI_PARAM_ERL;
4494 else if (attr == &dev_attr_sess_targetname.attr)
4495 param = ISCSI_PARAM_TARGET_NAME;
4496 else if (attr == &dev_attr_sess_tpgt.attr)
4497 param = ISCSI_PARAM_TPGT;
4498 else if (attr == &dev_attr_sess_chap_in_idx.attr)
4499 param = ISCSI_PARAM_CHAP_IN_IDX;
4500 else if (attr == &dev_attr_sess_chap_out_idx.attr)
4501 param = ISCSI_PARAM_CHAP_OUT_IDX;
4502 else if (attr == &dev_attr_sess_password.attr)
4503 param = ISCSI_PARAM_USERNAME;
4504 else if (attr == &dev_attr_sess_password_in.attr)
4505 param = ISCSI_PARAM_USERNAME_IN;
4506 else if (attr == &dev_attr_sess_username.attr)
4507 param = ISCSI_PARAM_PASSWORD;
4508 else if (attr == &dev_attr_sess_username_in.attr)
4509 param = ISCSI_PARAM_PASSWORD_IN;
4510 else if (attr == &dev_attr_sess_fast_abort.attr)
4511 param = ISCSI_PARAM_FAST_ABORT;
4512 else if (attr == &dev_attr_sess_abort_tmo.attr)
4513 param = ISCSI_PARAM_ABORT_TMO;
4514 else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
4515 param = ISCSI_PARAM_LU_RESET_TMO;
4516 else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
4517 param = ISCSI_PARAM_TGT_RESET_TMO;
4518 else if (attr == &dev_attr_sess_ifacename.attr)
4519 param = ISCSI_PARAM_IFACE_NAME;
4520 else if (attr == &dev_attr_sess_initiatorname.attr)
4521 param = ISCSI_PARAM_INITIATOR_NAME;
4522 else if (attr == &dev_attr_sess_targetalias.attr)
4523 param = ISCSI_PARAM_TARGET_ALIAS;
4524 else if (attr == &dev_attr_sess_boot_root.attr)
4525 param = ISCSI_PARAM_BOOT_ROOT;
4526 else if (attr == &dev_attr_sess_boot_nic.attr)
4527 param = ISCSI_PARAM_BOOT_NIC;
4528 else if (attr == &dev_attr_sess_boot_target.attr)
4529 param = ISCSI_PARAM_BOOT_TARGET;
4530 else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
4531 param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
4532 else if (attr == &dev_attr_sess_discovery_session.attr)
4533 param = ISCSI_PARAM_DISCOVERY_SESS;
4534 else if (attr == &dev_attr_sess_portal_type.attr)
4535 param = ISCSI_PARAM_PORTAL_TYPE;
4536 else if (attr == &dev_attr_sess_chap_auth.attr)
4537 param = ISCSI_PARAM_CHAP_AUTH_EN;
4538 else if (attr == &dev_attr_sess_discovery_logout.attr)
4539 param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
4540 else if (attr == &dev_attr_sess_bidi_chap.attr)
4541 param = ISCSI_PARAM_BIDI_CHAP_EN;
4542 else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
4543 param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
4544 else if (attr == &dev_attr_sess_def_time2wait.attr)
4545 param = ISCSI_PARAM_DEF_TIME2WAIT;
4546 else if (attr == &dev_attr_sess_def_time2retain.attr)
4547 param = ISCSI_PARAM_DEF_TIME2RETAIN;
4548 else if (attr == &dev_attr_sess_isid.attr)
4549 param = ISCSI_PARAM_ISID;
4550 else if (attr == &dev_attr_sess_tsid.attr)
4551 param = ISCSI_PARAM_TSID;
4552 else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
4553 param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
4554 else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
4555 param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
4556 else if (attr == &dev_attr_sess_discovery_parent_type.attr)
4557 param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
4558 else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
4559 return S_IRUGO | S_IWUSR;
4560 else if (attr == &dev_attr_priv_sess_state.attr)
4562 else if (attr == &dev_attr_priv_sess_creator.attr)
4564 else if (attr == &dev_attr_priv_sess_target_id.attr)
4567 WARN_ONCE(1, "Invalid session attr");
4571 return t->attr_is_visible(ISCSI_PARAM, param);
4574 static struct attribute_group iscsi_session_group = {
4575 .attrs = iscsi_session_attrs,
4576 .is_visible = iscsi_session_attr_is_visible,
4582 #define iscsi_host_attr_show(param) \
4584 show_host_param_##param(struct device *dev, \
4585 struct device_attribute *attr, char *buf) \
4587 struct Scsi_Host *shost = transport_class_to_shost(dev); \
4588 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
4589 return priv->iscsi_transport->get_host_param(shost, param, buf); \
4592 #define iscsi_host_attr(field, param) \
4593 iscsi_host_attr_show(param) \
4594 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
4597 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
4598 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
4599 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
4600 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
4601 iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
4602 iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
4604 static struct attribute *iscsi_host_attrs[] = {
4605 &dev_attr_host_netdev.attr,
4606 &dev_attr_host_hwaddress.attr,
4607 &dev_attr_host_ipaddress.attr,
4608 &dev_attr_host_initiatorname.attr,
4609 &dev_attr_host_port_state.attr,
4610 &dev_attr_host_port_speed.attr,
4614 static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
4615 struct attribute *attr, int i)
4617 struct device *cdev = container_of(kobj, struct device, kobj);
4618 struct Scsi_Host *shost = transport_class_to_shost(cdev);
4619 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
4622 if (attr == &dev_attr_host_netdev.attr)
4623 param = ISCSI_HOST_PARAM_NETDEV_NAME;
4624 else if (attr == &dev_attr_host_hwaddress.attr)
4625 param = ISCSI_HOST_PARAM_HWADDRESS;
4626 else if (attr == &dev_attr_host_ipaddress.attr)
4627 param = ISCSI_HOST_PARAM_IPADDRESS;
4628 else if (attr == &dev_attr_host_initiatorname.attr)
4629 param = ISCSI_HOST_PARAM_INITIATOR_NAME;
4630 else if (attr == &dev_attr_host_port_state.attr)
4631 param = ISCSI_HOST_PARAM_PORT_STATE;
4632 else if (attr == &dev_attr_host_port_speed.attr)
4633 param = ISCSI_HOST_PARAM_PORT_SPEED;
4635 WARN_ONCE(1, "Invalid host attr");
4639 return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
4642 static struct attribute_group iscsi_host_group = {
4643 .attrs = iscsi_host_attrs,
4644 .is_visible = iscsi_host_attr_is_visible,
4647 /* convert iscsi_port_speed values to ascii string name */
4648 static const struct {
4649 enum iscsi_port_speed value;
4651 } iscsi_port_speed_names[] = {
4652 {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
4653 {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
4654 {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
4655 {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
4656 {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
4657 {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" },
4658 {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" },
4661 char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
4664 char *speed = "Unknown!";
4665 struct iscsi_cls_host *ihost = shost->shost_data;
4666 uint32_t port_speed = ihost->port_speed;
4668 for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
4669 if (iscsi_port_speed_names[i].value & port_speed) {
4670 speed = iscsi_port_speed_names[i].name;
4676 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
4678 /* convert iscsi_port_state values to ascii string name */
4679 static const struct {
4680 enum iscsi_port_state value;
4682 } iscsi_port_state_names[] = {
4683 {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
4684 {ISCSI_PORT_STATE_UP, "LINK UP" },
4687 char *iscsi_get_port_state_name(struct Scsi_Host *shost)
4690 char *state = "Unknown!";
4691 struct iscsi_cls_host *ihost = shost->shost_data;
4692 uint32_t port_state = ihost->port_state;
4694 for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
4695 if (iscsi_port_state_names[i].value & port_state) {
4696 state = iscsi_port_state_names[i].name;
4702 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
4704 static int iscsi_session_match(struct attribute_container *cont,
4707 struct iscsi_cls_session *session;
4708 struct Scsi_Host *shost;
4709 struct iscsi_internal *priv;
4711 if (!iscsi_is_session_dev(dev))
4714 session = iscsi_dev_to_session(dev);
4715 shost = iscsi_session_to_shost(session);
4716 if (!shost->transportt)
4719 priv = to_iscsi_internal(shost->transportt);
4720 if (priv->session_cont.ac.class != &iscsi_session_class.class)
4723 return &priv->session_cont.ac == cont;
4726 static int iscsi_conn_match(struct attribute_container *cont,
4729 struct iscsi_cls_session *session;
4730 struct iscsi_cls_conn *conn;
4731 struct Scsi_Host *shost;
4732 struct iscsi_internal *priv;
4734 if (!iscsi_is_conn_dev(dev))
4737 conn = iscsi_dev_to_conn(dev);
4738 session = iscsi_dev_to_session(conn->dev.parent);
4739 shost = iscsi_session_to_shost(session);
4741 if (!shost->transportt)
4744 priv = to_iscsi_internal(shost->transportt);
4745 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
4748 return &priv->conn_cont.ac == cont;
4751 static int iscsi_host_match(struct attribute_container *cont,
4754 struct Scsi_Host *shost;
4755 struct iscsi_internal *priv;
4757 if (!scsi_is_host_device(dev))
4760 shost = dev_to_shost(dev);
4761 if (!shost->transportt ||
4762 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
4765 priv = to_iscsi_internal(shost->transportt);
4766 return &priv->t.host_attrs.ac == cont;
4769 struct scsi_transport_template *
4770 iscsi_register_transport(struct iscsi_transport *tt)
4772 struct iscsi_internal *priv;
4773 unsigned long flags;
4777 WARN_ON(tt->ep_disconnect && !tt->unbind_conn);
4779 priv = iscsi_if_transport_lookup(tt);
4783 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
4786 INIT_LIST_HEAD(&priv->list);
4787 priv->iscsi_transport = tt;
4788 priv->t.user_scan = iscsi_user_scan;
4789 priv->t.create_work_queue = 1;
4791 priv->dev.class = &iscsi_transport_class;
4792 dev_set_name(&priv->dev, "%s", tt->name);
4793 err = device_register(&priv->dev);
4797 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
4799 goto unregister_dev;
4801 /* host parameters */
4802 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
4803 priv->t.host_attrs.ac.match = iscsi_host_match;
4804 priv->t.host_attrs.ac.grp = &iscsi_host_group;
4805 priv->t.host_size = sizeof(struct iscsi_cls_host);
4806 transport_container_register(&priv->t.host_attrs);
4808 /* connection parameters */
4809 priv->conn_cont.ac.class = &iscsi_connection_class.class;
4810 priv->conn_cont.ac.match = iscsi_conn_match;
4811 priv->conn_cont.ac.grp = &iscsi_conn_group;
4812 transport_container_register(&priv->conn_cont);
4814 /* session parameters */
4815 priv->session_cont.ac.class = &iscsi_session_class.class;
4816 priv->session_cont.ac.match = iscsi_session_match;
4817 priv->session_cont.ac.grp = &iscsi_session_group;
4818 transport_container_register(&priv->session_cont);
4820 spin_lock_irqsave(&iscsi_transport_lock, flags);
4821 list_add(&priv->list, &iscsi_transports);
4822 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4824 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
4828 device_unregister(&priv->dev);
4834 EXPORT_SYMBOL_GPL(iscsi_register_transport);
4836 int iscsi_unregister_transport(struct iscsi_transport *tt)
4838 struct iscsi_internal *priv;
4839 unsigned long flags;
4843 mutex_lock(&rx_queue_mutex);
4845 priv = iscsi_if_transport_lookup(tt);
4848 spin_lock_irqsave(&iscsi_transport_lock, flags);
4849 list_del(&priv->list);
4850 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4852 transport_container_unregister(&priv->conn_cont);
4853 transport_container_unregister(&priv->session_cont);
4854 transport_container_unregister(&priv->t.host_attrs);
4856 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
4857 device_unregister(&priv->dev);
4858 mutex_unlock(&rx_queue_mutex);
4862 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
4864 void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *),
4865 struct device *dev, const char *fmt, ...)
4867 struct va_format vaf;
4870 va_start(args, fmt);
4876 EXPORT_SYMBOL_GPL(iscsi_dbg_trace);
4878 static __init int iscsi_transport_init(void)
4881 struct netlink_kernel_cfg cfg = {
4883 .input = iscsi_if_rx,
4885 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
4886 ISCSI_TRANSPORT_VERSION);
4888 atomic_set(&iscsi_session_nr, 0);
4890 err = class_register(&iscsi_transport_class);
4894 err = class_register(&iscsi_endpoint_class);
4896 goto unregister_transport_class;
4898 err = class_register(&iscsi_iface_class);
4900 goto unregister_endpoint_class;
4902 err = transport_class_register(&iscsi_host_class);
4904 goto unregister_iface_class;
4906 err = transport_class_register(&iscsi_connection_class);
4908 goto unregister_host_class;
4910 err = transport_class_register(&iscsi_session_class);
4912 goto unregister_conn_class;
4914 err = bus_register(&iscsi_flashnode_bus);
4916 goto unregister_session_class;
4918 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
4921 goto unregister_flashnode_bus;
4924 iscsi_eh_timer_workq = alloc_workqueue("%s",
4925 WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND,
4927 if (!iscsi_eh_timer_workq) {
4932 iscsi_conn_cleanup_workq = alloc_workqueue("%s",
4933 WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND, 0,
4934 "iscsi_conn_cleanup");
4935 if (!iscsi_conn_cleanup_workq) {
4943 destroy_workqueue(iscsi_eh_timer_workq);
4945 netlink_kernel_release(nls);
4946 unregister_flashnode_bus:
4947 bus_unregister(&iscsi_flashnode_bus);
4948 unregister_session_class:
4949 transport_class_unregister(&iscsi_session_class);
4950 unregister_conn_class:
4951 transport_class_unregister(&iscsi_connection_class);
4952 unregister_host_class:
4953 transport_class_unregister(&iscsi_host_class);
4954 unregister_iface_class:
4955 class_unregister(&iscsi_iface_class);
4956 unregister_endpoint_class:
4957 class_unregister(&iscsi_endpoint_class);
4958 unregister_transport_class:
4959 class_unregister(&iscsi_transport_class);
4963 static void __exit iscsi_transport_exit(void)
4965 destroy_workqueue(iscsi_conn_cleanup_workq);
4966 destroy_workqueue(iscsi_eh_timer_workq);
4967 netlink_kernel_release(nls);
4968 bus_unregister(&iscsi_flashnode_bus);
4969 transport_class_unregister(&iscsi_connection_class);
4970 transport_class_unregister(&iscsi_session_class);
4971 transport_class_unregister(&iscsi_host_class);
4972 class_unregister(&iscsi_endpoint_class);
4973 class_unregister(&iscsi_iface_class);
4974 class_unregister(&iscsi_transport_class);
4977 module_init(iscsi_transport_init);
4978 module_exit(iscsi_transport_exit);
4980 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
4981 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
4982 "Alex Aizman <itn780@yahoo.com>");
4983 MODULE_DESCRIPTION("iSCSI Transport Interface");
4984 MODULE_LICENSE("GPL");
4985 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
4986 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);