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 atomic_t iscsi_session_nr; /* sysfs session id for next new session */
91 static struct workqueue_struct *iscsi_conn_cleanup_workq;
93 static DEFINE_IDA(iscsi_sess_ida);
95 * list of registered transports and lock that must
96 * be held while accessing list. The iscsi_transport_lock must
97 * be acquired after the rx_queue_mutex.
99 static LIST_HEAD(iscsi_transports);
100 static DEFINE_SPINLOCK(iscsi_transport_lock);
102 #define to_iscsi_internal(tmpl) \
103 container_of(tmpl, struct iscsi_internal, t)
105 #define dev_to_iscsi_internal(_dev) \
106 container_of(_dev, struct iscsi_internal, dev)
108 static void iscsi_transport_release(struct device *dev)
110 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
115 * iscsi_transport_class represents the iscsi_transports that are
118 static struct class iscsi_transport_class = {
119 .name = "iscsi_transport",
120 .dev_release = iscsi_transport_release,
124 show_transport_handle(struct device *dev, struct device_attribute *attr,
127 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
129 if (!capable(CAP_SYS_ADMIN))
131 return sysfs_emit(buf, "%llu\n",
132 (unsigned long long)iscsi_handle(priv->iscsi_transport));
134 static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
136 #define show_transport_attr(name, format) \
138 show_transport_##name(struct device *dev, \
139 struct device_attribute *attr,char *buf) \
141 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
142 return sysfs_emit(buf, format"\n", priv->iscsi_transport->name);\
144 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
146 show_transport_attr(caps, "0x%x");
148 static struct attribute *iscsi_transport_attrs[] = {
149 &dev_attr_handle.attr,
154 static struct attribute_group iscsi_transport_group = {
155 .attrs = iscsi_transport_attrs,
159 * iSCSI endpoint attrs
161 #define iscsi_dev_to_endpoint(_dev) \
162 container_of(_dev, struct iscsi_endpoint, dev)
164 #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
165 struct device_attribute dev_attr_##_prefix##_##_name = \
166 __ATTR(_name,_mode,_show,_store)
168 static void iscsi_endpoint_release(struct device *dev)
170 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
174 static struct class iscsi_endpoint_class = {
175 .name = "iscsi_endpoint",
176 .dev_release = iscsi_endpoint_release,
180 show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
182 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
183 return sysfs_emit(buf, "%llu\n", (unsigned long long) ep->id);
185 static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
187 static struct attribute *iscsi_endpoint_attrs[] = {
188 &dev_attr_ep_handle.attr,
192 static struct attribute_group iscsi_endpoint_group = {
193 .attrs = iscsi_endpoint_attrs,
196 #define ISCSI_MAX_EPID -1
198 static int iscsi_match_epid(struct device *dev, const void *data)
200 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
201 const uint64_t *epid = data;
203 return *epid == ep->id;
206 struct iscsi_endpoint *
207 iscsi_create_endpoint(int dd_size)
210 struct iscsi_endpoint *ep;
214 for (id = 1; id < ISCSI_MAX_EPID; id++) {
215 dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
222 if (id == ISCSI_MAX_EPID) {
223 printk(KERN_ERR "Too many connections. Max supported %u\n",
228 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
233 ep->dev.class = &iscsi_endpoint_class;
234 dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id);
235 err = device_register(&ep->dev);
239 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
244 ep->dd_data = &ep[1];
248 device_unregister(&ep->dev);
255 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
257 void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
259 sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
260 device_unregister(&ep->dev);
262 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
264 void iscsi_put_endpoint(struct iscsi_endpoint *ep)
266 put_device(&ep->dev);
268 EXPORT_SYMBOL_GPL(iscsi_put_endpoint);
271 * iscsi_lookup_endpoint - get ep from handle
272 * @handle: endpoint handle
274 * Caller must do a iscsi_put_endpoint.
276 struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
280 dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
285 return iscsi_dev_to_endpoint(dev);
287 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
290 * Interface to display network param to sysfs
293 static void iscsi_iface_release(struct device *dev)
295 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
296 struct device *parent = iface->dev.parent;
303 static struct class iscsi_iface_class = {
304 .name = "iscsi_iface",
305 .dev_release = iscsi_iface_release,
308 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
309 struct device_attribute dev_attr_##_prefix##_##_name = \
310 __ATTR(_name, _mode, _show, _store)
312 /* iface attrs show */
313 #define iscsi_iface_attr_show(type, name, param_type, param) \
315 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
318 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
319 struct iscsi_transport *t = iface->transport; \
320 return t->get_iface_param(iface, param_type, param, buf); \
323 #define iscsi_iface_net_attr(type, name, param) \
324 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
325 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
327 #define iscsi_iface_attr(type, name, param) \
328 iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \
329 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
331 /* generic read only ipv4 attribute */
332 iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
333 iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
334 iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
335 iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
336 iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en,
337 ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN);
338 iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en,
339 ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN);
340 iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN);
341 iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS);
342 iscsi_iface_net_attr(ipv4_iface, grat_arp_en,
343 ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN);
344 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en,
345 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN);
346 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id,
347 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID);
348 iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en,
349 ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN);
350 iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en,
351 ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN);
352 iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id,
353 ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID);
354 iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en,
355 ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN);
356 iscsi_iface_net_attr(ipv4_iface, fragment_disable,
357 ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE);
358 iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en,
359 ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN);
360 iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL);
362 /* generic read only ipv6 attribute */
363 iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
364 iscsi_iface_net_attr(ipv6_iface, link_local_addr,
365 ISCSI_NET_PARAM_IPV6_LINKLOCAL);
366 iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
367 iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
368 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
369 iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
370 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
371 iscsi_iface_net_attr(ipv6_iface, link_local_state,
372 ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE);
373 iscsi_iface_net_attr(ipv6_iface, router_state,
374 ISCSI_NET_PARAM_IPV6_ROUTER_STATE);
375 iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en,
376 ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN);
377 iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN);
378 iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL);
379 iscsi_iface_net_attr(ipv6_iface, traffic_class,
380 ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS);
381 iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT);
382 iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo,
383 ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO);
384 iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time,
385 ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME);
386 iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo,
387 ISCSI_NET_PARAM_IPV6_ND_STALE_TMO);
388 iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt,
389 ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT);
390 iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu,
391 ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU);
393 /* common read only iface attribute */
394 iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
395 iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
396 iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
397 iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
398 iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
399 iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
400 iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE);
401 iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN);
402 iscsi_iface_net_attr(iface, tcp_nagle_disable,
403 ISCSI_NET_PARAM_TCP_NAGLE_DISABLE);
404 iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE);
405 iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF);
406 iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE);
407 iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN);
408 iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID);
409 iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN);
411 /* common iscsi specific settings attributes */
412 iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO);
413 iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN);
414 iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN);
415 iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN);
416 iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN);
417 iscsi_iface_attr(iface, data_seq_in_order,
418 ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN);
419 iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN);
420 iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL);
421 iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH);
422 iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST);
423 iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T);
424 iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST);
425 iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN);
426 iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN);
427 iscsi_iface_attr(iface, discovery_auth_optional,
428 ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL);
429 iscsi_iface_attr(iface, discovery_logout,
430 ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN);
431 iscsi_iface_attr(iface, strict_login_comp_en,
432 ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN);
433 iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME);
435 static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
436 struct attribute *attr, int i)
438 struct device *dev = container_of(kobj, struct device, kobj);
439 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
440 struct iscsi_transport *t = iface->transport;
443 if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr)
444 param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO;
445 else if (attr == &dev_attr_iface_header_digest.attr)
446 param = ISCSI_IFACE_PARAM_HDRDGST_EN;
447 else if (attr == &dev_attr_iface_data_digest.attr)
448 param = ISCSI_IFACE_PARAM_DATADGST_EN;
449 else if (attr == &dev_attr_iface_immediate_data.attr)
450 param = ISCSI_IFACE_PARAM_IMM_DATA_EN;
451 else if (attr == &dev_attr_iface_initial_r2t.attr)
452 param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN;
453 else if (attr == &dev_attr_iface_data_seq_in_order.attr)
454 param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN;
455 else if (attr == &dev_attr_iface_data_pdu_in_order.attr)
456 param = ISCSI_IFACE_PARAM_PDU_INORDER_EN;
457 else if (attr == &dev_attr_iface_erl.attr)
458 param = ISCSI_IFACE_PARAM_ERL;
459 else if (attr == &dev_attr_iface_max_recv_dlength.attr)
460 param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH;
461 else if (attr == &dev_attr_iface_first_burst_len.attr)
462 param = ISCSI_IFACE_PARAM_FIRST_BURST;
463 else if (attr == &dev_attr_iface_max_outstanding_r2t.attr)
464 param = ISCSI_IFACE_PARAM_MAX_R2T;
465 else if (attr == &dev_attr_iface_max_burst_len.attr)
466 param = ISCSI_IFACE_PARAM_MAX_BURST;
467 else if (attr == &dev_attr_iface_chap_auth.attr)
468 param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN;
469 else if (attr == &dev_attr_iface_bidi_chap.attr)
470 param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN;
471 else if (attr == &dev_attr_iface_discovery_auth_optional.attr)
472 param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL;
473 else if (attr == &dev_attr_iface_discovery_logout.attr)
474 param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN;
475 else if (attr == &dev_attr_iface_strict_login_comp_en.attr)
476 param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN;
477 else if (attr == &dev_attr_iface_initiator_name.attr)
478 param = ISCSI_IFACE_PARAM_INITIATOR_NAME;
481 return t->attr_is_visible(ISCSI_IFACE_PARAM, param);
483 if (attr == &dev_attr_iface_enabled.attr)
484 param = ISCSI_NET_PARAM_IFACE_ENABLE;
485 else if (attr == &dev_attr_iface_vlan_id.attr)
486 param = ISCSI_NET_PARAM_VLAN_ID;
487 else if (attr == &dev_attr_iface_vlan_priority.attr)
488 param = ISCSI_NET_PARAM_VLAN_PRIORITY;
489 else if (attr == &dev_attr_iface_vlan_enabled.attr)
490 param = ISCSI_NET_PARAM_VLAN_ENABLED;
491 else if (attr == &dev_attr_iface_mtu.attr)
492 param = ISCSI_NET_PARAM_MTU;
493 else if (attr == &dev_attr_iface_port.attr)
494 param = ISCSI_NET_PARAM_PORT;
495 else if (attr == &dev_attr_iface_ipaddress_state.attr)
496 param = ISCSI_NET_PARAM_IPADDR_STATE;
497 else if (attr == &dev_attr_iface_delayed_ack_en.attr)
498 param = ISCSI_NET_PARAM_DELAYED_ACK_EN;
499 else if (attr == &dev_attr_iface_tcp_nagle_disable.attr)
500 param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE;
501 else if (attr == &dev_attr_iface_tcp_wsf_disable.attr)
502 param = ISCSI_NET_PARAM_TCP_WSF_DISABLE;
503 else if (attr == &dev_attr_iface_tcp_wsf.attr)
504 param = ISCSI_NET_PARAM_TCP_WSF;
505 else if (attr == &dev_attr_iface_tcp_timer_scale.attr)
506 param = ISCSI_NET_PARAM_TCP_TIMER_SCALE;
507 else if (attr == &dev_attr_iface_tcp_timestamp_en.attr)
508 param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN;
509 else if (attr == &dev_attr_iface_cache_id.attr)
510 param = ISCSI_NET_PARAM_CACHE_ID;
511 else if (attr == &dev_attr_iface_redirect_en.attr)
512 param = ISCSI_NET_PARAM_REDIRECT_EN;
513 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
514 if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
515 param = ISCSI_NET_PARAM_IPV4_ADDR;
516 else if (attr == &dev_attr_ipv4_iface_gateway.attr)
517 param = ISCSI_NET_PARAM_IPV4_GW;
518 else if (attr == &dev_attr_ipv4_iface_subnet.attr)
519 param = ISCSI_NET_PARAM_IPV4_SUBNET;
520 else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
521 param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
523 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr)
524 param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN;
526 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr)
527 param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN;
528 else if (attr == &dev_attr_ipv4_iface_tos_en.attr)
529 param = ISCSI_NET_PARAM_IPV4_TOS_EN;
530 else if (attr == &dev_attr_ipv4_iface_tos.attr)
531 param = ISCSI_NET_PARAM_IPV4_TOS;
532 else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr)
533 param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN;
535 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr)
536 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN;
537 else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr)
538 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID;
540 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr)
541 param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN;
543 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr)
544 param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN;
545 else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr)
546 param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID;
548 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr)
549 param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN;
551 &dev_attr_ipv4_iface_fragment_disable.attr)
552 param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE;
554 &dev_attr_ipv4_iface_incoming_forwarding_en.attr)
555 param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN;
556 else if (attr == &dev_attr_ipv4_iface_ttl.attr)
557 param = ISCSI_NET_PARAM_IPV4_TTL;
560 } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
561 if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
562 param = ISCSI_NET_PARAM_IPV6_ADDR;
563 else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
564 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
565 else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
566 param = ISCSI_NET_PARAM_IPV6_ROUTER;
567 else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
568 param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
569 else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
570 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
571 else if (attr == &dev_attr_ipv6_iface_link_local_state.attr)
572 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE;
573 else if (attr == &dev_attr_ipv6_iface_router_state.attr)
574 param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE;
576 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr)
577 param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN;
578 else if (attr == &dev_attr_ipv6_iface_mld_en.attr)
579 param = ISCSI_NET_PARAM_IPV6_MLD_EN;
580 else if (attr == &dev_attr_ipv6_iface_flow_label.attr)
581 param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL;
582 else if (attr == &dev_attr_ipv6_iface_traffic_class.attr)
583 param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS;
584 else if (attr == &dev_attr_ipv6_iface_hop_limit.attr)
585 param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT;
586 else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr)
587 param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO;
588 else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr)
589 param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME;
590 else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr)
591 param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO;
592 else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr)
593 param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT;
594 else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr)
595 param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU;
599 WARN_ONCE(1, "Invalid iface attr");
603 return t->attr_is_visible(ISCSI_NET_PARAM, param);
606 static struct attribute *iscsi_iface_attrs[] = {
607 &dev_attr_iface_enabled.attr,
608 &dev_attr_iface_vlan_id.attr,
609 &dev_attr_iface_vlan_priority.attr,
610 &dev_attr_iface_vlan_enabled.attr,
611 &dev_attr_ipv4_iface_ipaddress.attr,
612 &dev_attr_ipv4_iface_gateway.attr,
613 &dev_attr_ipv4_iface_subnet.attr,
614 &dev_attr_ipv4_iface_bootproto.attr,
615 &dev_attr_ipv6_iface_ipaddress.attr,
616 &dev_attr_ipv6_iface_link_local_addr.attr,
617 &dev_attr_ipv6_iface_router_addr.attr,
618 &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
619 &dev_attr_ipv6_iface_link_local_autocfg.attr,
620 &dev_attr_iface_mtu.attr,
621 &dev_attr_iface_port.attr,
622 &dev_attr_iface_ipaddress_state.attr,
623 &dev_attr_iface_delayed_ack_en.attr,
624 &dev_attr_iface_tcp_nagle_disable.attr,
625 &dev_attr_iface_tcp_wsf_disable.attr,
626 &dev_attr_iface_tcp_wsf.attr,
627 &dev_attr_iface_tcp_timer_scale.attr,
628 &dev_attr_iface_tcp_timestamp_en.attr,
629 &dev_attr_iface_cache_id.attr,
630 &dev_attr_iface_redirect_en.attr,
631 &dev_attr_iface_def_taskmgmt_tmo.attr,
632 &dev_attr_iface_header_digest.attr,
633 &dev_attr_iface_data_digest.attr,
634 &dev_attr_iface_immediate_data.attr,
635 &dev_attr_iface_initial_r2t.attr,
636 &dev_attr_iface_data_seq_in_order.attr,
637 &dev_attr_iface_data_pdu_in_order.attr,
638 &dev_attr_iface_erl.attr,
639 &dev_attr_iface_max_recv_dlength.attr,
640 &dev_attr_iface_first_burst_len.attr,
641 &dev_attr_iface_max_outstanding_r2t.attr,
642 &dev_attr_iface_max_burst_len.attr,
643 &dev_attr_iface_chap_auth.attr,
644 &dev_attr_iface_bidi_chap.attr,
645 &dev_attr_iface_discovery_auth_optional.attr,
646 &dev_attr_iface_discovery_logout.attr,
647 &dev_attr_iface_strict_login_comp_en.attr,
648 &dev_attr_iface_initiator_name.attr,
649 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr,
650 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr,
651 &dev_attr_ipv4_iface_tos_en.attr,
652 &dev_attr_ipv4_iface_tos.attr,
653 &dev_attr_ipv4_iface_grat_arp_en.attr,
654 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr,
655 &dev_attr_ipv4_iface_dhcp_alt_client_id.attr,
656 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr,
657 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr,
658 &dev_attr_ipv4_iface_dhcp_vendor_id.attr,
659 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr,
660 &dev_attr_ipv4_iface_fragment_disable.attr,
661 &dev_attr_ipv4_iface_incoming_forwarding_en.attr,
662 &dev_attr_ipv4_iface_ttl.attr,
663 &dev_attr_ipv6_iface_link_local_state.attr,
664 &dev_attr_ipv6_iface_router_state.attr,
665 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr,
666 &dev_attr_ipv6_iface_mld_en.attr,
667 &dev_attr_ipv6_iface_flow_label.attr,
668 &dev_attr_ipv6_iface_traffic_class.attr,
669 &dev_attr_ipv6_iface_hop_limit.attr,
670 &dev_attr_ipv6_iface_nd_reachable_tmo.attr,
671 &dev_attr_ipv6_iface_nd_rexmit_time.attr,
672 &dev_attr_ipv6_iface_nd_stale_tmo.attr,
673 &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr,
674 &dev_attr_ipv6_iface_router_adv_link_mtu.attr,
678 static struct attribute_group iscsi_iface_group = {
679 .attrs = iscsi_iface_attrs,
680 .is_visible = iscsi_iface_attr_is_visible,
683 /* convert iscsi_ipaddress_state values to ascii string name */
684 static const struct {
685 enum iscsi_ipaddress_state value;
687 } iscsi_ipaddress_state_names[] = {
688 {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" },
689 {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" },
690 {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" },
691 {ISCSI_IPDDRESS_STATE_VALID, "Valid" },
692 {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" },
693 {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" },
694 {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" },
697 char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state)
702 for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) {
703 if (iscsi_ipaddress_state_names[i].value == port_state) {
704 state = iscsi_ipaddress_state_names[i].name;
710 EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name);
712 /* convert iscsi_router_state values to ascii string name */
713 static const struct {
714 enum iscsi_router_state value;
716 } iscsi_router_state_names[] = {
717 {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" },
718 {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" },
719 {ISCSI_ROUTER_STATE_MANUAL, "Manual" },
720 {ISCSI_ROUTER_STATE_STALE, "Stale" },
723 char *iscsi_get_router_state_name(enum iscsi_router_state router_state)
728 for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) {
729 if (iscsi_router_state_names[i].value == router_state) {
730 state = iscsi_router_state_names[i].name;
736 EXPORT_SYMBOL_GPL(iscsi_get_router_state_name);
739 iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
740 uint32_t iface_type, uint32_t iface_num, int dd_size)
742 struct iscsi_iface *iface;
745 iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
749 iface->transport = transport;
750 iface->iface_type = iface_type;
751 iface->iface_num = iface_num;
752 iface->dev.release = iscsi_iface_release;
753 iface->dev.class = &iscsi_iface_class;
754 /* parent reference released in iscsi_iface_release */
755 iface->dev.parent = get_device(&shost->shost_gendev);
756 if (iface_type == ISCSI_IFACE_TYPE_IPV4)
757 dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
760 dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
763 err = device_register(&iface->dev);
767 err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
772 iface->dd_data = &iface[1];
776 device_unregister(&iface->dev);
780 put_device(iface->dev.parent);
784 EXPORT_SYMBOL_GPL(iscsi_create_iface);
786 void iscsi_destroy_iface(struct iscsi_iface *iface)
788 sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
789 device_unregister(&iface->dev);
791 EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
794 * Interface to display flash node params to sysfs
797 #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
798 struct device_attribute dev_attr_##_prefix##_##_name = \
799 __ATTR(_name, _mode, _show, _store)
801 /* flash node session attrs show */
802 #define iscsi_flashnode_sess_attr_show(type, name, param) \
804 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
807 struct iscsi_bus_flash_session *fnode_sess = \
808 iscsi_dev_to_flash_session(dev);\
809 struct iscsi_transport *t = fnode_sess->transport; \
810 return t->get_flashnode_param(fnode_sess, param, buf); \
814 #define iscsi_flashnode_sess_attr(type, name, param) \
815 iscsi_flashnode_sess_attr_show(type, name, param) \
816 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
817 show_##type##_##name, NULL);
819 /* Flash node session attributes */
821 iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable,
822 ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE);
823 iscsi_flashnode_sess_attr(fnode, discovery_session,
824 ISCSI_FLASHNODE_DISCOVERY_SESS);
825 iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE);
826 iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN);
827 iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN);
828 iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN);
829 iscsi_flashnode_sess_attr(fnode, data_seq_in_order,
830 ISCSI_FLASHNODE_DATASEQ_INORDER);
831 iscsi_flashnode_sess_attr(fnode, data_pdu_in_order,
832 ISCSI_FLASHNODE_PDU_INORDER);
833 iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN);
834 iscsi_flashnode_sess_attr(fnode, discovery_logout,
835 ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN);
836 iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN);
837 iscsi_flashnode_sess_attr(fnode, discovery_auth_optional,
838 ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL);
839 iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL);
840 iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST);
841 iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT);
842 iscsi_flashnode_sess_attr(fnode, def_time2retain,
843 ISCSI_FLASHNODE_DEF_TIME2RETAIN);
844 iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T);
845 iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID);
846 iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID);
847 iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST);
848 iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo,
849 ISCSI_FLASHNODE_DEF_TASKMGMT_TMO);
850 iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS);
851 iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME);
852 iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT);
853 iscsi_flashnode_sess_attr(fnode, discovery_parent_idx,
854 ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX);
855 iscsi_flashnode_sess_attr(fnode, discovery_parent_type,
856 ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE);
857 iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX);
858 iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX);
859 iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME);
860 iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN);
861 iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD);
862 iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN);
863 iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT);
865 static struct attribute *iscsi_flashnode_sess_attrs[] = {
866 &dev_attr_fnode_auto_snd_tgt_disable.attr,
867 &dev_attr_fnode_discovery_session.attr,
868 &dev_attr_fnode_portal_type.attr,
869 &dev_attr_fnode_entry_enable.attr,
870 &dev_attr_fnode_immediate_data.attr,
871 &dev_attr_fnode_initial_r2t.attr,
872 &dev_attr_fnode_data_seq_in_order.attr,
873 &dev_attr_fnode_data_pdu_in_order.attr,
874 &dev_attr_fnode_chap_auth.attr,
875 &dev_attr_fnode_discovery_logout.attr,
876 &dev_attr_fnode_bidi_chap.attr,
877 &dev_attr_fnode_discovery_auth_optional.attr,
878 &dev_attr_fnode_erl.attr,
879 &dev_attr_fnode_first_burst_len.attr,
880 &dev_attr_fnode_def_time2wait.attr,
881 &dev_attr_fnode_def_time2retain.attr,
882 &dev_attr_fnode_max_outstanding_r2t.attr,
883 &dev_attr_fnode_isid.attr,
884 &dev_attr_fnode_tsid.attr,
885 &dev_attr_fnode_max_burst_len.attr,
886 &dev_attr_fnode_def_taskmgmt_tmo.attr,
887 &dev_attr_fnode_targetalias.attr,
888 &dev_attr_fnode_targetname.attr,
889 &dev_attr_fnode_tpgt.attr,
890 &dev_attr_fnode_discovery_parent_idx.attr,
891 &dev_attr_fnode_discovery_parent_type.attr,
892 &dev_attr_fnode_chap_in_idx.attr,
893 &dev_attr_fnode_chap_out_idx.attr,
894 &dev_attr_fnode_username.attr,
895 &dev_attr_fnode_username_in.attr,
896 &dev_attr_fnode_password.attr,
897 &dev_attr_fnode_password_in.attr,
898 &dev_attr_fnode_is_boot_target.attr,
902 static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj,
903 struct attribute *attr,
906 struct device *dev = container_of(kobj, struct device, kobj);
907 struct iscsi_bus_flash_session *fnode_sess =
908 iscsi_dev_to_flash_session(dev);
909 struct iscsi_transport *t = fnode_sess->transport;
912 if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) {
913 param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE;
914 } else if (attr == &dev_attr_fnode_discovery_session.attr) {
915 param = ISCSI_FLASHNODE_DISCOVERY_SESS;
916 } else if (attr == &dev_attr_fnode_portal_type.attr) {
917 param = ISCSI_FLASHNODE_PORTAL_TYPE;
918 } else if (attr == &dev_attr_fnode_entry_enable.attr) {
919 param = ISCSI_FLASHNODE_ENTRY_EN;
920 } else if (attr == &dev_attr_fnode_immediate_data.attr) {
921 param = ISCSI_FLASHNODE_IMM_DATA_EN;
922 } else if (attr == &dev_attr_fnode_initial_r2t.attr) {
923 param = ISCSI_FLASHNODE_INITIAL_R2T_EN;
924 } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) {
925 param = ISCSI_FLASHNODE_DATASEQ_INORDER;
926 } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) {
927 param = ISCSI_FLASHNODE_PDU_INORDER;
928 } else if (attr == &dev_attr_fnode_chap_auth.attr) {
929 param = ISCSI_FLASHNODE_CHAP_AUTH_EN;
930 } else if (attr == &dev_attr_fnode_discovery_logout.attr) {
931 param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN;
932 } else if (attr == &dev_attr_fnode_bidi_chap.attr) {
933 param = ISCSI_FLASHNODE_BIDI_CHAP_EN;
934 } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) {
935 param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL;
936 } else if (attr == &dev_attr_fnode_erl.attr) {
937 param = ISCSI_FLASHNODE_ERL;
938 } else if (attr == &dev_attr_fnode_first_burst_len.attr) {
939 param = ISCSI_FLASHNODE_FIRST_BURST;
940 } else if (attr == &dev_attr_fnode_def_time2wait.attr) {
941 param = ISCSI_FLASHNODE_DEF_TIME2WAIT;
942 } else if (attr == &dev_attr_fnode_def_time2retain.attr) {
943 param = ISCSI_FLASHNODE_DEF_TIME2RETAIN;
944 } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) {
945 param = ISCSI_FLASHNODE_MAX_R2T;
946 } else if (attr == &dev_attr_fnode_isid.attr) {
947 param = ISCSI_FLASHNODE_ISID;
948 } else if (attr == &dev_attr_fnode_tsid.attr) {
949 param = ISCSI_FLASHNODE_TSID;
950 } else if (attr == &dev_attr_fnode_max_burst_len.attr) {
951 param = ISCSI_FLASHNODE_MAX_BURST;
952 } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) {
953 param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO;
954 } else if (attr == &dev_attr_fnode_targetalias.attr) {
955 param = ISCSI_FLASHNODE_ALIAS;
956 } else if (attr == &dev_attr_fnode_targetname.attr) {
957 param = ISCSI_FLASHNODE_NAME;
958 } else if (attr == &dev_attr_fnode_tpgt.attr) {
959 param = ISCSI_FLASHNODE_TPGT;
960 } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) {
961 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX;
962 } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) {
963 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE;
964 } else if (attr == &dev_attr_fnode_chap_in_idx.attr) {
965 param = ISCSI_FLASHNODE_CHAP_IN_IDX;
966 } else if (attr == &dev_attr_fnode_chap_out_idx.attr) {
967 param = ISCSI_FLASHNODE_CHAP_OUT_IDX;
968 } else if (attr == &dev_attr_fnode_username.attr) {
969 param = ISCSI_FLASHNODE_USERNAME;
970 } else if (attr == &dev_attr_fnode_username_in.attr) {
971 param = ISCSI_FLASHNODE_USERNAME_IN;
972 } else if (attr == &dev_attr_fnode_password.attr) {
973 param = ISCSI_FLASHNODE_PASSWORD;
974 } else if (attr == &dev_attr_fnode_password_in.attr) {
975 param = ISCSI_FLASHNODE_PASSWORD_IN;
976 } else if (attr == &dev_attr_fnode_is_boot_target.attr) {
977 param = ISCSI_FLASHNODE_IS_BOOT_TGT;
979 WARN_ONCE(1, "Invalid flashnode session attr");
983 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
986 static struct attribute_group iscsi_flashnode_sess_attr_group = {
987 .attrs = iscsi_flashnode_sess_attrs,
988 .is_visible = iscsi_flashnode_sess_attr_is_visible,
991 static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = {
992 &iscsi_flashnode_sess_attr_group,
996 static void iscsi_flashnode_sess_release(struct device *dev)
998 struct iscsi_bus_flash_session *fnode_sess =
999 iscsi_dev_to_flash_session(dev);
1001 kfree(fnode_sess->targetname);
1002 kfree(fnode_sess->targetalias);
1003 kfree(fnode_sess->portal_type);
1007 static const struct device_type iscsi_flashnode_sess_dev_type = {
1008 .name = "iscsi_flashnode_sess_dev_type",
1009 .groups = iscsi_flashnode_sess_attr_groups,
1010 .release = iscsi_flashnode_sess_release,
1013 /* flash node connection attrs show */
1014 #define iscsi_flashnode_conn_attr_show(type, name, param) \
1016 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
1019 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
1020 struct iscsi_bus_flash_session *fnode_sess = \
1021 iscsi_flash_conn_to_flash_session(fnode_conn);\
1022 struct iscsi_transport *t = fnode_conn->transport; \
1023 return t->get_flashnode_param(fnode_sess, param, buf); \
1027 #define iscsi_flashnode_conn_attr(type, name, param) \
1028 iscsi_flashnode_conn_attr_show(type, name, param) \
1029 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
1030 show_##type##_##name, NULL);
1032 /* Flash node connection attributes */
1034 iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6,
1035 ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6);
1036 iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN);
1037 iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN);
1038 iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN);
1039 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat,
1040 ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT);
1041 iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable,
1042 ISCSI_FLASHNODE_TCP_NAGLE_DISABLE);
1043 iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable,
1044 ISCSI_FLASHNODE_TCP_WSF_DISABLE);
1045 iscsi_flashnode_conn_attr(fnode, tcp_timer_scale,
1046 ISCSI_FLASHNODE_TCP_TIMER_SCALE);
1047 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable,
1048 ISCSI_FLASHNODE_TCP_TIMESTAMP_EN);
1049 iscsi_flashnode_conn_attr(fnode, fragment_disable,
1050 ISCSI_FLASHNODE_IP_FRAG_DISABLE);
1051 iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO);
1052 iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT);
1053 iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR);
1054 iscsi_flashnode_conn_attr(fnode, max_recv_dlength,
1055 ISCSI_FLASHNODE_MAX_RECV_DLENGTH);
1056 iscsi_flashnode_conn_attr(fnode, max_xmit_dlength,
1057 ISCSI_FLASHNODE_MAX_XMIT_DLENGTH);
1058 iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT);
1059 iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS);
1060 iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC);
1061 iscsi_flashnode_conn_attr(fnode, ipv6_flow_label,
1062 ISCSI_FLASHNODE_IPV6_FLOW_LABEL);
1063 iscsi_flashnode_conn_attr(fnode, redirect_ipaddr,
1064 ISCSI_FLASHNODE_REDIRECT_IPADDR);
1065 iscsi_flashnode_conn_attr(fnode, max_segment_size,
1066 ISCSI_FLASHNODE_MAX_SEGMENT_SIZE);
1067 iscsi_flashnode_conn_attr(fnode, link_local_ipv6,
1068 ISCSI_FLASHNODE_LINK_LOCAL_IPV6);
1069 iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF);
1070 iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF);
1071 iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN);
1072 iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN);
1074 static struct attribute *iscsi_flashnode_conn_attrs[] = {
1075 &dev_attr_fnode_is_fw_assigned_ipv6.attr,
1076 &dev_attr_fnode_header_digest.attr,
1077 &dev_attr_fnode_data_digest.attr,
1078 &dev_attr_fnode_snack_req.attr,
1079 &dev_attr_fnode_tcp_timestamp_stat.attr,
1080 &dev_attr_fnode_tcp_nagle_disable.attr,
1081 &dev_attr_fnode_tcp_wsf_disable.attr,
1082 &dev_attr_fnode_tcp_timer_scale.attr,
1083 &dev_attr_fnode_tcp_timestamp_enable.attr,
1084 &dev_attr_fnode_fragment_disable.attr,
1085 &dev_attr_fnode_max_recv_dlength.attr,
1086 &dev_attr_fnode_max_xmit_dlength.attr,
1087 &dev_attr_fnode_keepalive_tmo.attr,
1088 &dev_attr_fnode_port.attr,
1089 &dev_attr_fnode_ipaddress.attr,
1090 &dev_attr_fnode_redirect_ipaddr.attr,
1091 &dev_attr_fnode_max_segment_size.attr,
1092 &dev_attr_fnode_local_port.attr,
1093 &dev_attr_fnode_ipv4_tos.attr,
1094 &dev_attr_fnode_ipv6_traffic_class.attr,
1095 &dev_attr_fnode_ipv6_flow_label.attr,
1096 &dev_attr_fnode_link_local_ipv6.attr,
1097 &dev_attr_fnode_tcp_xmit_wsf.attr,
1098 &dev_attr_fnode_tcp_recv_wsf.attr,
1099 &dev_attr_fnode_statsn.attr,
1100 &dev_attr_fnode_exp_statsn.attr,
1104 static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj,
1105 struct attribute *attr,
1108 struct device *dev = container_of(kobj, struct device, kobj);
1109 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1110 struct iscsi_transport *t = fnode_conn->transport;
1113 if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) {
1114 param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6;
1115 } else if (attr == &dev_attr_fnode_header_digest.attr) {
1116 param = ISCSI_FLASHNODE_HDR_DGST_EN;
1117 } else if (attr == &dev_attr_fnode_data_digest.attr) {
1118 param = ISCSI_FLASHNODE_DATA_DGST_EN;
1119 } else if (attr == &dev_attr_fnode_snack_req.attr) {
1120 param = ISCSI_FLASHNODE_SNACK_REQ_EN;
1121 } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) {
1122 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT;
1123 } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) {
1124 param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE;
1125 } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) {
1126 param = ISCSI_FLASHNODE_TCP_WSF_DISABLE;
1127 } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) {
1128 param = ISCSI_FLASHNODE_TCP_TIMER_SCALE;
1129 } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) {
1130 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN;
1131 } else if (attr == &dev_attr_fnode_fragment_disable.attr) {
1132 param = ISCSI_FLASHNODE_IP_FRAG_DISABLE;
1133 } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) {
1134 param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH;
1135 } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) {
1136 param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH;
1137 } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) {
1138 param = ISCSI_FLASHNODE_KEEPALIVE_TMO;
1139 } else if (attr == &dev_attr_fnode_port.attr) {
1140 param = ISCSI_FLASHNODE_PORT;
1141 } else if (attr == &dev_attr_fnode_ipaddress.attr) {
1142 param = ISCSI_FLASHNODE_IPADDR;
1143 } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) {
1144 param = ISCSI_FLASHNODE_REDIRECT_IPADDR;
1145 } else if (attr == &dev_attr_fnode_max_segment_size.attr) {
1146 param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE;
1147 } else if (attr == &dev_attr_fnode_local_port.attr) {
1148 param = ISCSI_FLASHNODE_LOCAL_PORT;
1149 } else if (attr == &dev_attr_fnode_ipv4_tos.attr) {
1150 param = ISCSI_FLASHNODE_IPV4_TOS;
1151 } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) {
1152 param = ISCSI_FLASHNODE_IPV6_TC;
1153 } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) {
1154 param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL;
1155 } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) {
1156 param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6;
1157 } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) {
1158 param = ISCSI_FLASHNODE_TCP_XMIT_WSF;
1159 } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) {
1160 param = ISCSI_FLASHNODE_TCP_RECV_WSF;
1161 } else if (attr == &dev_attr_fnode_statsn.attr) {
1162 param = ISCSI_FLASHNODE_STATSN;
1163 } else if (attr == &dev_attr_fnode_exp_statsn.attr) {
1164 param = ISCSI_FLASHNODE_EXP_STATSN;
1166 WARN_ONCE(1, "Invalid flashnode connection attr");
1170 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
1173 static struct attribute_group iscsi_flashnode_conn_attr_group = {
1174 .attrs = iscsi_flashnode_conn_attrs,
1175 .is_visible = iscsi_flashnode_conn_attr_is_visible,
1178 static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = {
1179 &iscsi_flashnode_conn_attr_group,
1183 static void iscsi_flashnode_conn_release(struct device *dev)
1185 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1187 kfree(fnode_conn->ipaddress);
1188 kfree(fnode_conn->redirect_ipaddr);
1189 kfree(fnode_conn->link_local_ipv6_addr);
1193 static const struct device_type iscsi_flashnode_conn_dev_type = {
1194 .name = "iscsi_flashnode_conn_dev_type",
1195 .groups = iscsi_flashnode_conn_attr_groups,
1196 .release = iscsi_flashnode_conn_release,
1199 static struct bus_type iscsi_flashnode_bus;
1201 int iscsi_flashnode_bus_match(struct device *dev,
1202 struct device_driver *drv)
1204 if (dev->bus == &iscsi_flashnode_bus)
1208 EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match);
1210 static struct bus_type iscsi_flashnode_bus = {
1211 .name = "iscsi_flashnode",
1212 .match = &iscsi_flashnode_bus_match,
1216 * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
1217 * @shost: pointer to host data
1218 * @index: index of flashnode to add in sysfs
1219 * @transport: pointer to transport data
1220 * @dd_size: total size to allocate
1222 * Adds a sysfs entry for the flashnode session attributes
1225 * pointer to allocated flashnode sess on success
1228 struct iscsi_bus_flash_session *
1229 iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
1230 struct iscsi_transport *transport,
1233 struct iscsi_bus_flash_session *fnode_sess;
1236 fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL);
1240 fnode_sess->transport = transport;
1241 fnode_sess->target_id = index;
1242 fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type;
1243 fnode_sess->dev.bus = &iscsi_flashnode_bus;
1244 fnode_sess->dev.parent = &shost->shost_gendev;
1245 dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u",
1246 shost->host_no, index);
1248 err = device_register(&fnode_sess->dev);
1250 goto free_fnode_sess;
1253 fnode_sess->dd_data = &fnode_sess[1];
1261 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
1264 * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
1265 * @shost: pointer to host data
1266 * @fnode_sess: pointer to the parent flashnode session entry
1267 * @transport: pointer to transport data
1268 * @dd_size: total size to allocate
1270 * Adds a sysfs entry for the flashnode connection attributes
1273 * pointer to allocated flashnode conn on success
1276 struct iscsi_bus_flash_conn *
1277 iscsi_create_flashnode_conn(struct Scsi_Host *shost,
1278 struct iscsi_bus_flash_session *fnode_sess,
1279 struct iscsi_transport *transport,
1282 struct iscsi_bus_flash_conn *fnode_conn;
1285 fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL);
1289 fnode_conn->transport = transport;
1290 fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type;
1291 fnode_conn->dev.bus = &iscsi_flashnode_bus;
1292 fnode_conn->dev.parent = &fnode_sess->dev;
1293 dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0",
1294 shost->host_no, fnode_sess->target_id);
1296 err = device_register(&fnode_conn->dev);
1298 goto free_fnode_conn;
1301 fnode_conn->dd_data = &fnode_conn[1];
1309 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
1312 * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
1313 * @dev: device to verify
1314 * @data: pointer to data containing value to use for verification
1316 * Verifies if the passed device is flashnode conn device
1322 static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
1324 return dev->bus == &iscsi_flashnode_bus;
1327 static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
1329 device_unregister(&fnode_conn->dev);
1333 static int flashnode_match_index(struct device *dev, void *data)
1335 struct iscsi_bus_flash_session *fnode_sess = NULL;
1338 if (!iscsi_flashnode_bus_match(dev, NULL))
1339 goto exit_match_index;
1341 fnode_sess = iscsi_dev_to_flash_session(dev);
1342 ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
1349 * iscsi_get_flashnode_by_index -finds flashnode session entry by index
1350 * @shost: pointer to host data
1351 * @idx: index to match
1353 * Finds the flashnode session object for the passed index
1356 * pointer to found flashnode session object on success
1359 static struct iscsi_bus_flash_session *
1360 iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
1362 struct iscsi_bus_flash_session *fnode_sess = NULL;
1365 dev = device_find_child(&shost->shost_gendev, &idx,
1366 flashnode_match_index);
1368 fnode_sess = iscsi_dev_to_flash_session(dev);
1374 * iscsi_find_flashnode_sess - finds flashnode session entry
1375 * @shost: pointer to host data
1376 * @data: pointer to data containing value to use for comparison
1377 * @fn: function pointer that does actual comparison
1379 * Finds the flashnode session object comparing the data passed using logic
1380 * defined in passed function pointer
1383 * pointer to found flashnode session device object on success
1387 iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
1388 int (*fn)(struct device *dev, void *data))
1390 return device_find_child(&shost->shost_gendev, data, fn);
1392 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
1395 * iscsi_find_flashnode_conn - finds flashnode connection entry
1396 * @fnode_sess: pointer to parent flashnode session entry
1398 * Finds the flashnode connection object comparing the data passed using logic
1399 * defined in passed function pointer
1402 * pointer to found flashnode connection device object on success
1406 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
1408 return device_find_child(&fnode_sess->dev, NULL,
1409 iscsi_is_flashnode_conn_dev);
1411 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);
1413 static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data)
1415 if (!iscsi_is_flashnode_conn_dev(dev, NULL))
1418 return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev));
1422 * iscsi_destroy_flashnode_sess - destroy flashnode session entry
1423 * @fnode_sess: pointer to flashnode session entry to be destroyed
1425 * Deletes the flashnode session entry and all children flashnode connection
1426 * entries from sysfs
1428 void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess)
1432 err = device_for_each_child(&fnode_sess->dev, NULL,
1433 iscsi_iter_destroy_flashnode_conn_fn);
1435 pr_err("Could not delete all connections for %s. Error %d.\n",
1436 fnode_sess->dev.kobj.name, err);
1438 device_unregister(&fnode_sess->dev);
1440 EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);
1442 static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data)
1444 if (!iscsi_flashnode_bus_match(dev, NULL))
1447 iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev));
1452 * iscsi_destroy_all_flashnode - destroy all flashnode session entries
1453 * @shost: pointer to host data
1455 * Destroys all the flashnode session entries and all corresponding children
1456 * flashnode connection entries from sysfs
1458 void iscsi_destroy_all_flashnode(struct Scsi_Host *shost)
1460 device_for_each_child(&shost->shost_gendev, NULL,
1461 iscsi_iter_destroy_flashnode_fn);
1463 EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode);
1469 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
1470 * @job: bsg job to be processed
1472 static int iscsi_bsg_host_dispatch(struct bsg_job *job)
1474 struct Scsi_Host *shost = iscsi_job_to_shost(job);
1475 struct iscsi_bsg_request *req = job->request;
1476 struct iscsi_bsg_reply *reply = job->reply;
1477 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1478 int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
1481 /* check if we have the msgcode value at least */
1482 if (job->request_len < sizeof(uint32_t)) {
1487 /* Validate the host command */
1488 switch (req->msgcode) {
1489 case ISCSI_BSG_HST_VENDOR:
1490 cmdlen += sizeof(struct iscsi_bsg_host_vendor);
1491 if ((shost->hostt->vendor_id == 0L) ||
1492 (req->rqst_data.h_vendor.vendor_id !=
1493 shost->hostt->vendor_id)) {
1503 /* check if we really have all the request data needed */
1504 if (job->request_len < cmdlen) {
1509 ret = i->iscsi_transport->bsg_request(job);
1514 /* return the errno failure code as the only status */
1515 BUG_ON(job->reply_len < sizeof(uint32_t));
1516 reply->reply_payload_rcv_len = 0;
1517 reply->result = ret;
1518 job->reply_len = sizeof(uint32_t);
1519 bsg_job_done(job, ret, 0);
1524 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
1525 * @shost: shost for iscsi_host
1526 * @ihost: iscsi_cls_host adding the structures to
1529 iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
1531 struct device *dev = &shost->shost_gendev;
1532 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1533 struct request_queue *q;
1536 if (!i->iscsi_transport->bsg_request)
1539 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1540 q = bsg_setup_queue(dev, bsg_name, iscsi_bsg_host_dispatch, NULL, 0);
1542 shost_printk(KERN_ERR, shost, "bsg interface failed to "
1543 "initialize - no request queue\n");
1546 __scsi_init_queue(shost, q);
1552 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
1553 struct device *cdev)
1555 struct Scsi_Host *shost = dev_to_shost(dev);
1556 struct iscsi_cls_host *ihost = shost->shost_data;
1558 memset(ihost, 0, sizeof(*ihost));
1559 mutex_init(&ihost->mutex);
1561 iscsi_bsg_host_add(shost, ihost);
1562 /* ignore any bsg add error - we just can't do sgio */
1567 static int iscsi_remove_host(struct transport_container *tc,
1568 struct device *dev, struct device *cdev)
1570 struct Scsi_Host *shost = dev_to_shost(dev);
1571 struct iscsi_cls_host *ihost = shost->shost_data;
1573 bsg_remove_queue(ihost->bsg_q);
1577 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
1583 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
1589 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
1595 static struct sock *nls;
1596 static DEFINE_MUTEX(rx_queue_mutex);
1598 static LIST_HEAD(sesslist);
1599 static DEFINE_SPINLOCK(sesslock);
1600 static LIST_HEAD(connlist);
1601 static LIST_HEAD(connlist_err);
1602 static DEFINE_SPINLOCK(connlock);
1604 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
1606 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
1611 * Returns the matching session to a given sid
1613 static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
1615 unsigned long flags;
1616 struct iscsi_cls_session *sess;
1618 spin_lock_irqsave(&sesslock, flags);
1619 list_for_each_entry(sess, &sesslist, sess_list) {
1620 if (sess->sid == sid) {
1621 spin_unlock_irqrestore(&sesslock, flags);
1625 spin_unlock_irqrestore(&sesslock, flags);
1630 * Returns the matching connection to a given sid / cid tuple
1632 static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
1634 unsigned long flags;
1635 struct iscsi_cls_conn *conn;
1637 spin_lock_irqsave(&connlock, flags);
1638 list_for_each_entry(conn, &connlist, conn_list) {
1639 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
1640 spin_unlock_irqrestore(&connlock, flags);
1644 spin_unlock_irqrestore(&connlock, flags);
1649 * The following functions can be used by LLDs that allocate
1650 * their own scsi_hosts or by software iscsi LLDs
1655 } iscsi_session_state_names[] = {
1656 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
1657 { ISCSI_SESSION_FAILED, "FAILED" },
1658 { ISCSI_SESSION_FREE, "FREE" },
1661 static const char *iscsi_session_state_name(int state)
1666 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
1667 if (iscsi_session_state_names[i].value == state) {
1668 name = iscsi_session_state_names[i].name;
1675 int iscsi_session_chkready(struct iscsi_cls_session *session)
1679 switch (session->state) {
1680 case ISCSI_SESSION_LOGGED_IN:
1683 case ISCSI_SESSION_FAILED:
1684 err = DID_IMM_RETRY << 16;
1686 case ISCSI_SESSION_FREE:
1687 err = DID_TRANSPORT_FAILFAST << 16;
1690 err = DID_NO_CONNECT << 16;
1695 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
1697 int iscsi_is_session_online(struct iscsi_cls_session *session)
1699 unsigned long flags;
1702 spin_lock_irqsave(&session->lock, flags);
1703 if (session->state == ISCSI_SESSION_LOGGED_IN)
1705 spin_unlock_irqrestore(&session->lock, flags);
1708 EXPORT_SYMBOL_GPL(iscsi_is_session_online);
1710 static void iscsi_session_release(struct device *dev)
1712 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
1713 struct Scsi_Host *shost;
1715 shost = iscsi_session_to_shost(session);
1716 scsi_host_put(shost);
1717 ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
1721 int iscsi_is_session_dev(const struct device *dev)
1723 return dev->release == iscsi_session_release;
1725 EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
1727 static int iscsi_iter_session_fn(struct device *dev, void *data)
1729 void (* fn) (struct iscsi_cls_session *) = data;
1731 if (!iscsi_is_session_dev(dev))
1733 fn(iscsi_dev_to_session(dev));
1737 void iscsi_host_for_each_session(struct Scsi_Host *shost,
1738 void (*fn)(struct iscsi_cls_session *))
1740 device_for_each_child(&shost->shost_gendev, fn,
1741 iscsi_iter_session_fn);
1743 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
1745 struct iscsi_scan_data {
1746 unsigned int channel;
1749 enum scsi_scan_mode rescan;
1752 static int iscsi_user_scan_session(struct device *dev, void *data)
1754 struct iscsi_scan_data *scan_data = data;
1755 struct iscsi_cls_session *session;
1756 struct Scsi_Host *shost;
1757 struct iscsi_cls_host *ihost;
1758 unsigned long flags;
1761 if (!iscsi_is_session_dev(dev))
1764 session = iscsi_dev_to_session(dev);
1766 ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
1768 shost = iscsi_session_to_shost(session);
1769 ihost = shost->shost_data;
1771 mutex_lock(&ihost->mutex);
1772 spin_lock_irqsave(&session->lock, flags);
1773 if (session->state != ISCSI_SESSION_LOGGED_IN) {
1774 spin_unlock_irqrestore(&session->lock, flags);
1775 goto user_scan_exit;
1777 id = session->target_id;
1778 spin_unlock_irqrestore(&session->lock, flags);
1780 if (id != ISCSI_MAX_TARGET) {
1781 if ((scan_data->channel == SCAN_WILD_CARD ||
1782 scan_data->channel == 0) &&
1783 (scan_data->id == SCAN_WILD_CARD ||
1784 scan_data->id == id))
1785 scsi_scan_target(&session->dev, 0, id,
1786 scan_data->lun, scan_data->rescan);
1790 mutex_unlock(&ihost->mutex);
1791 ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
1795 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
1798 struct iscsi_scan_data scan_data;
1800 scan_data.channel = channel;
1802 scan_data.lun = lun;
1803 scan_data.rescan = SCSI_SCAN_MANUAL;
1805 return device_for_each_child(&shost->shost_gendev, &scan_data,
1806 iscsi_user_scan_session);
1809 static void iscsi_scan_session(struct work_struct *work)
1811 struct iscsi_cls_session *session =
1812 container_of(work, struct iscsi_cls_session, scan_work);
1813 struct iscsi_scan_data scan_data;
1815 scan_data.channel = 0;
1816 scan_data.id = SCAN_WILD_CARD;
1817 scan_data.lun = SCAN_WILD_CARD;
1818 scan_data.rescan = SCSI_SCAN_RESCAN;
1820 iscsi_user_scan_session(&session->dev, &scan_data);
1824 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1825 * @cmd: scsi cmd passed to scsi eh handler
1827 * If the session is down this function will wait for the recovery
1828 * timer to fire or for the session to be logged back in. If the
1829 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1830 * should pass this error value to the scsi eh.
1832 int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
1834 struct iscsi_cls_session *session =
1835 starget_to_session(scsi_target(cmd->device));
1836 unsigned long flags;
1839 spin_lock_irqsave(&session->lock, flags);
1840 while (session->state != ISCSI_SESSION_LOGGED_IN) {
1841 if (session->state == ISCSI_SESSION_FREE) {
1845 spin_unlock_irqrestore(&session->lock, flags);
1847 spin_lock_irqsave(&session->lock, flags);
1849 spin_unlock_irqrestore(&session->lock, flags);
1852 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
1854 static void session_recovery_timedout(struct work_struct *work)
1856 struct iscsi_cls_session *session =
1857 container_of(work, struct iscsi_cls_session,
1858 recovery_work.work);
1859 unsigned long flags;
1861 iscsi_cls_session_printk(KERN_INFO, session,
1862 "session recovery timed out after %d secs\n",
1863 session->recovery_tmo);
1865 spin_lock_irqsave(&session->lock, flags);
1866 switch (session->state) {
1867 case ISCSI_SESSION_FAILED:
1868 session->state = ISCSI_SESSION_FREE;
1870 case ISCSI_SESSION_LOGGED_IN:
1871 case ISCSI_SESSION_FREE:
1872 /* we raced with the unblock's flush */
1873 spin_unlock_irqrestore(&session->lock, flags);
1876 spin_unlock_irqrestore(&session->lock, flags);
1878 ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
1879 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
1880 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
1882 if (session->transport->session_recovery_timedout)
1883 session->transport->session_recovery_timedout(session);
1886 static void __iscsi_unblock_session(struct work_struct *work)
1888 struct iscsi_cls_session *session =
1889 container_of(work, struct iscsi_cls_session,
1891 unsigned long flags;
1893 ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
1895 cancel_delayed_work_sync(&session->recovery_work);
1896 spin_lock_irqsave(&session->lock, flags);
1897 session->state = ISCSI_SESSION_LOGGED_IN;
1898 spin_unlock_irqrestore(&session->lock, flags);
1900 scsi_target_unblock(&session->dev, SDEV_RUNNING);
1901 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
1905 * iscsi_unblock_session - set a session as logged in and start IO.
1906 * @session: iscsi session
1908 * Mark a session as ready to accept IO.
1910 void iscsi_unblock_session(struct iscsi_cls_session *session)
1912 if (!cancel_work_sync(&session->block_work))
1913 cancel_delayed_work_sync(&session->recovery_work);
1915 queue_work(session->workq, &session->unblock_work);
1917 * Blocking the session can be done from any context so we only
1918 * queue the block work. Make sure the unblock work has completed
1919 * because it flushes/cancels the other works and updates the state.
1921 flush_work(&session->unblock_work);
1923 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
1925 static void __iscsi_block_session(struct work_struct *work)
1927 struct iscsi_cls_session *session =
1928 container_of(work, struct iscsi_cls_session,
1930 unsigned long flags;
1932 ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
1933 spin_lock_irqsave(&session->lock, flags);
1934 session->state = ISCSI_SESSION_FAILED;
1935 spin_unlock_irqrestore(&session->lock, flags);
1936 scsi_target_block(&session->dev);
1937 ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
1938 if (session->recovery_tmo >= 0)
1939 queue_delayed_work(session->workq,
1940 &session->recovery_work,
1941 session->recovery_tmo * HZ);
1944 void iscsi_block_session(struct iscsi_cls_session *session)
1946 queue_work(session->workq, &session->block_work);
1948 EXPORT_SYMBOL_GPL(iscsi_block_session);
1950 static void __iscsi_unbind_session(struct work_struct *work)
1952 struct iscsi_cls_session *session =
1953 container_of(work, struct iscsi_cls_session,
1955 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1956 struct iscsi_cls_host *ihost = shost->shost_data;
1957 unsigned long flags;
1958 unsigned int target_id;
1960 ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
1962 /* Prevent new scans and make sure scanning is not in progress */
1963 mutex_lock(&ihost->mutex);
1964 spin_lock_irqsave(&session->lock, flags);
1965 if (session->target_id == ISCSI_MAX_TARGET) {
1966 spin_unlock_irqrestore(&session->lock, flags);
1967 mutex_unlock(&ihost->mutex);
1968 goto unbind_session_exit;
1971 target_id = session->target_id;
1972 session->target_id = ISCSI_MAX_TARGET;
1973 spin_unlock_irqrestore(&session->lock, flags);
1974 mutex_unlock(&ihost->mutex);
1976 scsi_remove_target(&session->dev);
1978 if (session->ida_used)
1979 ida_simple_remove(&iscsi_sess_ida, target_id);
1981 unbind_session_exit:
1982 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
1983 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
1986 static void __iscsi_destroy_session(struct work_struct *work)
1988 struct iscsi_cls_session *session =
1989 container_of(work, struct iscsi_cls_session, destroy_work);
1991 session->transport->destroy_session(session);
1994 struct iscsi_cls_session *
1995 iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
1998 struct iscsi_cls_session *session;
2000 session = kzalloc(sizeof(*session) + dd_size,
2005 session->transport = transport;
2006 session->creator = -1;
2007 session->recovery_tmo = 120;
2008 session->recovery_tmo_sysfs_override = false;
2009 session->state = ISCSI_SESSION_FREE;
2010 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
2011 INIT_LIST_HEAD(&session->sess_list);
2012 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
2013 INIT_WORK(&session->block_work, __iscsi_block_session);
2014 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
2015 INIT_WORK(&session->scan_work, iscsi_scan_session);
2016 INIT_WORK(&session->destroy_work, __iscsi_destroy_session);
2017 spin_lock_init(&session->lock);
2019 /* this is released in the dev's release function */
2020 scsi_host_get(shost);
2021 session->dev.parent = &shost->shost_gendev;
2022 session->dev.release = iscsi_session_release;
2023 device_initialize(&session->dev);
2025 session->dd_data = &session[1];
2027 ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
2030 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
2032 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
2034 struct Scsi_Host *shost = iscsi_session_to_shost(session);
2035 unsigned long flags;
2039 session->sid = atomic_add_return(1, &iscsi_session_nr);
2041 session->workq = alloc_workqueue("iscsi_ctrl_%d:%d",
2042 WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND, 0,
2043 shost->host_no, session->sid);
2044 if (!session->workq)
2047 if (target_id == ISCSI_MAX_TARGET) {
2048 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
2051 iscsi_cls_session_printk(KERN_ERR, session,
2052 "Failure in Target ID Allocation\n");
2056 session->target_id = (unsigned int)id;
2057 session->ida_used = true;
2059 session->target_id = target_id;
2061 dev_set_name(&session->dev, "session%u", session->sid);
2062 err = device_add(&session->dev);
2064 iscsi_cls_session_printk(KERN_ERR, session,
2065 "could not register session's dev\n");
2068 err = transport_register_device(&session->dev);
2070 iscsi_cls_session_printk(KERN_ERR, session,
2071 "could not register transport's dev\n");
2075 spin_lock_irqsave(&sesslock, flags);
2076 list_add(&session->sess_list, &sesslist);
2077 spin_unlock_irqrestore(&sesslock, flags);
2079 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
2080 ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
2084 device_del(&session->dev);
2086 if (session->ida_used)
2087 ida_simple_remove(&iscsi_sess_ida, session->target_id);
2089 destroy_workqueue(session->workq);
2092 EXPORT_SYMBOL_GPL(iscsi_add_session);
2095 * iscsi_create_session - create iscsi class session
2097 * @transport: iscsi transport
2098 * @dd_size: private driver data size
2099 * @target_id: which target
2101 * This can be called from a LLD or iscsi_transport.
2103 struct iscsi_cls_session *
2104 iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2105 int dd_size, unsigned int target_id)
2107 struct iscsi_cls_session *session;
2109 session = iscsi_alloc_session(shost, transport, dd_size);
2113 if (iscsi_add_session(session, target_id)) {
2114 iscsi_free_session(session);
2119 EXPORT_SYMBOL_GPL(iscsi_create_session);
2121 static void iscsi_conn_release(struct device *dev)
2123 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
2124 struct device *parent = conn->dev.parent;
2126 ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
2131 static int iscsi_is_conn_dev(const struct device *dev)
2133 return dev->release == iscsi_conn_release;
2136 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
2138 if (!iscsi_is_conn_dev(dev))
2141 iscsi_remove_conn(iscsi_dev_to_conn(dev));
2142 iscsi_put_conn(iscsi_dev_to_conn(dev));
2147 void iscsi_remove_session(struct iscsi_cls_session *session)
2149 unsigned long flags;
2152 ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
2154 spin_lock_irqsave(&sesslock, flags);
2155 if (!list_empty(&session->sess_list))
2156 list_del(&session->sess_list);
2157 spin_unlock_irqrestore(&sesslock, flags);
2159 if (!cancel_work_sync(&session->block_work))
2160 cancel_delayed_work_sync(&session->recovery_work);
2161 cancel_work_sync(&session->unblock_work);
2163 * If we are blocked let commands flow again. The lld or iscsi
2164 * layer should set up the queuecommand to fail commands.
2165 * We assume that LLD will not be calling block/unblock while
2166 * removing the session.
2168 spin_lock_irqsave(&session->lock, flags);
2169 session->state = ISCSI_SESSION_FREE;
2170 spin_unlock_irqrestore(&session->lock, flags);
2172 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2174 * qla4xxx can perform it's own scans when it runs in kernel only
2175 * mode. Make sure to flush those scans.
2177 flush_work(&session->scan_work);
2178 /* flush running unbind operations */
2179 flush_work(&session->unbind_work);
2180 __iscsi_unbind_session(&session->unbind_work);
2182 /* hw iscsi may not have removed all connections from session */
2183 err = device_for_each_child(&session->dev, NULL,
2184 iscsi_iter_destroy_conn_fn);
2186 iscsi_cls_session_printk(KERN_ERR, session,
2187 "Could not delete all connections "
2188 "for session. Error %d.\n", err);
2190 transport_unregister_device(&session->dev);
2192 destroy_workqueue(session->workq);
2194 ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
2195 device_del(&session->dev);
2197 EXPORT_SYMBOL_GPL(iscsi_remove_session);
2199 static void iscsi_stop_conn(struct iscsi_cls_conn *conn, int flag)
2201 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn.\n");
2204 case STOP_CONN_RECOVER:
2205 conn->state = ISCSI_CONN_FAILED;
2207 case STOP_CONN_TERM:
2208 conn->state = ISCSI_CONN_DOWN;
2211 iscsi_cls_conn_printk(KERN_ERR, conn, "invalid stop flag %d\n",
2216 conn->transport->stop_conn(conn, flag);
2217 ISCSI_DBG_TRANS_CONN(conn, "Stopping conn done.\n");
2220 static int iscsi_if_stop_conn(struct iscsi_transport *transport,
2221 struct iscsi_uevent *ev)
2223 int flag = ev->u.stop_conn.flag;
2224 struct iscsi_cls_conn *conn;
2226 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
2230 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop.\n");
2232 * If this is a termination we have to call stop_conn with that flag
2233 * so the correct states get set. If we haven't run the work yet try to
2234 * avoid the extra run.
2236 if (flag == STOP_CONN_TERM) {
2237 cancel_work_sync(&conn->cleanup_work);
2238 iscsi_stop_conn(conn, flag);
2241 * Figure out if it was the kernel or userspace initiating this.
2243 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2244 iscsi_stop_conn(conn, flag);
2246 ISCSI_DBG_TRANS_CONN(conn,
2247 "flush kernel conn cleanup.\n");
2248 flush_work(&conn->cleanup_work);
2251 * Only clear for recovery to avoid extra cleanup runs during
2254 clear_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags);
2256 ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop done.\n");
2260 static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
2262 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2263 struct iscsi_endpoint *ep;
2265 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep.\n");
2266 conn->state = ISCSI_CONN_FAILED;
2268 if (!conn->ep || !session->transport->ep_disconnect)
2274 session->transport->unbind_conn(conn, is_active);
2275 session->transport->ep_disconnect(ep);
2276 ISCSI_DBG_TRANS_CONN(conn, "disconnect ep done.\n");
2279 static void iscsi_cleanup_conn_work_fn(struct work_struct *work)
2281 struct iscsi_cls_conn *conn = container_of(work, struct iscsi_cls_conn,
2283 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
2285 mutex_lock(&conn->ep_mutex);
2287 * If we are not at least bound there is nothing for us to do. Userspace
2288 * will do a ep_disconnect call if offload is used, but will not be
2289 * doing a stop since there is nothing to clean up, so we have to clear
2290 * the cleanup bit here.
2292 if (conn->state != ISCSI_CONN_BOUND && conn->state != ISCSI_CONN_UP) {
2293 ISCSI_DBG_TRANS_CONN(conn, "Got error while conn is already failed. Ignoring.\n");
2294 clear_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags);
2295 mutex_unlock(&conn->ep_mutex);
2299 iscsi_ep_disconnect(conn, false);
2301 if (system_state != SYSTEM_RUNNING) {
2303 * If the user has set up for the session to never timeout
2304 * then hang like they wanted. For all other cases fail right
2305 * away since userspace is not going to relogin.
2307 if (session->recovery_tmo > 0)
2308 session->recovery_tmo = 0;
2311 iscsi_stop_conn(conn, STOP_CONN_RECOVER);
2312 mutex_unlock(&conn->ep_mutex);
2313 ISCSI_DBG_TRANS_CONN(conn, "cleanup done.\n");
2316 void iscsi_free_session(struct iscsi_cls_session *session)
2318 ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
2319 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
2320 put_device(&session->dev);
2322 EXPORT_SYMBOL_GPL(iscsi_free_session);
2325 * iscsi_alloc_conn - alloc iscsi class connection
2326 * @session: iscsi cls session
2327 * @dd_size: private driver data size
2328 * @cid: connection id
2330 struct iscsi_cls_conn *
2331 iscsi_alloc_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
2333 struct iscsi_transport *transport = session->transport;
2334 struct iscsi_cls_conn *conn;
2336 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
2340 conn->dd_data = &conn[1];
2342 mutex_init(&conn->ep_mutex);
2343 INIT_LIST_HEAD(&conn->conn_list);
2344 INIT_WORK(&conn->cleanup_work, iscsi_cleanup_conn_work_fn);
2345 conn->transport = transport;
2347 conn->state = ISCSI_CONN_DOWN;
2349 /* this is released in the dev's release function */
2350 if (!get_device(&session->dev))
2353 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
2354 device_initialize(&conn->dev);
2355 conn->dev.parent = &session->dev;
2356 conn->dev.release = iscsi_conn_release;
2364 EXPORT_SYMBOL_GPL(iscsi_alloc_conn);
2367 * iscsi_add_conn - add iscsi class connection
2368 * @conn: iscsi cls connection
2370 * This will expose iscsi_cls_conn to sysfs so make sure the related
2371 * resources for sysfs attributes are initialized before calling this.
2373 int iscsi_add_conn(struct iscsi_cls_conn *conn)
2376 unsigned long flags;
2377 struct iscsi_cls_session *session = iscsi_dev_to_session(conn->dev.parent);
2379 err = device_add(&conn->dev);
2381 iscsi_cls_session_printk(KERN_ERR, session,
2382 "could not register connection's dev\n");
2385 err = transport_register_device(&conn->dev);
2387 iscsi_cls_session_printk(KERN_ERR, session,
2388 "could not register transport's dev\n");
2389 device_del(&conn->dev);
2393 spin_lock_irqsave(&connlock, flags);
2394 list_add(&conn->conn_list, &connlist);
2395 spin_unlock_irqrestore(&connlock, flags);
2399 EXPORT_SYMBOL_GPL(iscsi_add_conn);
2402 * iscsi_remove_conn - remove iscsi class connection from sysfs
2403 * @conn: iscsi cls connection
2405 * Remove iscsi_cls_conn from sysfs, and wait for previous
2406 * read/write of iscsi_cls_conn's attributes in sysfs to finish.
2408 void iscsi_remove_conn(struct iscsi_cls_conn *conn)
2410 unsigned long flags;
2412 spin_lock_irqsave(&connlock, flags);
2413 list_del(&conn->conn_list);
2414 spin_unlock_irqrestore(&connlock, flags);
2416 transport_unregister_device(&conn->dev);
2417 device_del(&conn->dev);
2419 EXPORT_SYMBOL_GPL(iscsi_remove_conn);
2421 void iscsi_put_conn(struct iscsi_cls_conn *conn)
2423 put_device(&conn->dev);
2425 EXPORT_SYMBOL_GPL(iscsi_put_conn);
2427 void iscsi_get_conn(struct iscsi_cls_conn *conn)
2429 get_device(&conn->dev);
2431 EXPORT_SYMBOL_GPL(iscsi_get_conn);
2434 * iscsi interface functions
2436 static struct iscsi_internal *
2437 iscsi_if_transport_lookup(struct iscsi_transport *tt)
2439 struct iscsi_internal *priv;
2440 unsigned long flags;
2442 spin_lock_irqsave(&iscsi_transport_lock, flags);
2443 list_for_each_entry(priv, &iscsi_transports, list) {
2444 if (tt == priv->iscsi_transport) {
2445 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2449 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2454 iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
2456 return nlmsg_multicast(nls, skb, 0, group, gfp);
2460 iscsi_unicast_skb(struct sk_buff *skb, u32 portid)
2462 return nlmsg_unicast(nls, skb, portid);
2465 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
2466 char *data, uint32_t data_size)
2468 struct nlmsghdr *nlh;
2469 struct sk_buff *skb;
2470 struct iscsi_uevent *ev;
2472 struct iscsi_internal *priv;
2473 int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
2476 priv = iscsi_if_transport_lookup(conn->transport);
2480 skb = alloc_skb(len, GFP_ATOMIC);
2482 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
2483 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
2484 "control PDU: OOM\n");
2488 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2489 ev = nlmsg_data(nlh);
2490 memset(ev, 0, sizeof(*ev));
2491 ev->transport_handle = iscsi_handle(conn->transport);
2492 ev->type = ISCSI_KEVENT_RECV_PDU;
2493 ev->r.recv_req.cid = conn->cid;
2494 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
2495 pdu = (char*)ev + sizeof(*ev);
2496 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
2497 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
2499 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2501 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
2503 int iscsi_offload_mesg(struct Scsi_Host *shost,
2504 struct iscsi_transport *transport, uint32_t type,
2505 char *data, uint16_t data_size)
2507 struct nlmsghdr *nlh;
2508 struct sk_buff *skb;
2509 struct iscsi_uevent *ev;
2510 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2512 skb = alloc_skb(len, GFP_ATOMIC);
2514 printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
2518 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2519 ev = nlmsg_data(nlh);
2520 memset(ev, 0, sizeof(*ev));
2522 ev->transport_handle = iscsi_handle(transport);
2524 case ISCSI_KEVENT_PATH_REQ:
2525 ev->r.req_path.host_no = shost->host_no;
2527 case ISCSI_KEVENT_IF_DOWN:
2528 ev->r.notify_if_down.host_no = shost->host_no;
2532 memcpy((char *)ev + sizeof(*ev), data, data_size);
2534 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
2536 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
2538 void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
2540 struct nlmsghdr *nlh;
2541 struct sk_buff *skb;
2542 struct iscsi_uevent *ev;
2543 struct iscsi_internal *priv;
2544 int len = nlmsg_total_size(sizeof(*ev));
2546 if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags))
2547 queue_work(iscsi_conn_cleanup_workq, &conn->cleanup_work);
2549 priv = iscsi_if_transport_lookup(conn->transport);
2553 skb = alloc_skb(len, GFP_ATOMIC);
2555 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2556 "conn error (%d)\n", error);
2560 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2561 ev = nlmsg_data(nlh);
2562 ev->transport_handle = iscsi_handle(conn->transport);
2563 ev->type = ISCSI_KEVENT_CONN_ERROR;
2564 ev->r.connerror.error = error;
2565 ev->r.connerror.cid = conn->cid;
2566 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
2568 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2570 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
2573 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
2575 void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
2576 enum iscsi_conn_state state)
2578 struct nlmsghdr *nlh;
2579 struct sk_buff *skb;
2580 struct iscsi_uevent *ev;
2581 struct iscsi_internal *priv;
2582 int len = nlmsg_total_size(sizeof(*ev));
2584 priv = iscsi_if_transport_lookup(conn->transport);
2588 skb = alloc_skb(len, GFP_ATOMIC);
2590 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2591 "conn login (%d)\n", state);
2595 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2596 ev = nlmsg_data(nlh);
2597 ev->transport_handle = iscsi_handle(conn->transport);
2598 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
2599 ev->r.conn_login.state = state;
2600 ev->r.conn_login.cid = conn->cid;
2601 ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
2602 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2604 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
2607 EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
2609 void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
2610 enum iscsi_host_event_code code, uint32_t data_size,
2613 struct nlmsghdr *nlh;
2614 struct sk_buff *skb;
2615 struct iscsi_uevent *ev;
2616 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2618 skb = alloc_skb(len, GFP_NOIO);
2620 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
2625 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2626 ev = nlmsg_data(nlh);
2627 ev->transport_handle = iscsi_handle(transport);
2628 ev->type = ISCSI_KEVENT_HOST_EVENT;
2629 ev->r.host_event.host_no = host_no;
2630 ev->r.host_event.code = code;
2631 ev->r.host_event.data_size = data_size;
2634 memcpy((char *)ev + sizeof(*ev), data, data_size);
2636 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2638 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
2640 void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
2641 uint32_t status, uint32_t pid, uint32_t data_size,
2644 struct nlmsghdr *nlh;
2645 struct sk_buff *skb;
2646 struct iscsi_uevent *ev;
2647 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2649 skb = alloc_skb(len, GFP_NOIO);
2651 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
2655 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2656 ev = nlmsg_data(nlh);
2657 ev->transport_handle = iscsi_handle(transport);
2658 ev->type = ISCSI_KEVENT_PING_COMP;
2659 ev->r.ping_comp.host_no = host_no;
2660 ev->r.ping_comp.status = status;
2661 ev->r.ping_comp.pid = pid;
2662 ev->r.ping_comp.data_size = data_size;
2663 memcpy((char *)ev + sizeof(*ev), data, data_size);
2665 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2667 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
2670 iscsi_if_send_reply(u32 portid, int type, void *payload, int size)
2672 struct sk_buff *skb;
2673 struct nlmsghdr *nlh;
2674 int len = nlmsg_total_size(size);
2676 skb = alloc_skb(len, GFP_ATOMIC);
2678 printk(KERN_ERR "Could not allocate skb to send reply.\n");
2682 nlh = __nlmsg_put(skb, 0, 0, type, (len - sizeof(*nlh)), 0);
2683 memcpy(nlmsg_data(nlh), payload, size);
2684 return iscsi_unicast_skb(skb, portid);
2688 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
2690 struct iscsi_uevent *ev = nlmsg_data(nlh);
2691 struct iscsi_stats *stats;
2692 struct sk_buff *skbstat;
2693 struct iscsi_cls_conn *conn;
2694 struct nlmsghdr *nlhstat;
2695 struct iscsi_uevent *evstat;
2696 struct iscsi_internal *priv;
2697 int len = nlmsg_total_size(sizeof(*ev) +
2698 sizeof(struct iscsi_stats) +
2699 sizeof(struct iscsi_stats_custom) *
2700 ISCSI_STATS_CUSTOM_MAX);
2703 priv = iscsi_if_transport_lookup(transport);
2707 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
2714 skbstat = alloc_skb(len, GFP_ATOMIC);
2716 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
2717 "deliver stats: OOM\n");
2721 nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
2722 (len - sizeof(*nlhstat)), 0);
2723 evstat = nlmsg_data(nlhstat);
2724 memset(evstat, 0, sizeof(*evstat));
2725 evstat->transport_handle = iscsi_handle(conn->transport);
2726 evstat->type = nlh->nlmsg_type;
2727 evstat->u.get_stats.cid =
2728 ev->u.get_stats.cid;
2729 evstat->u.get_stats.sid =
2730 ev->u.get_stats.sid;
2731 stats = (struct iscsi_stats *)
2732 ((char*)evstat + sizeof(*evstat));
2733 memset(stats, 0, sizeof(*stats));
2735 transport->get_stats(conn, stats);
2736 actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
2737 sizeof(struct iscsi_stats) +
2738 sizeof(struct iscsi_stats_custom) *
2739 stats->custom_length);
2740 actual_size -= sizeof(*nlhstat);
2741 actual_size = nlmsg_msg_size(actual_size);
2742 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
2743 nlhstat->nlmsg_len = actual_size;
2745 err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
2747 } while (err < 0 && err != -ECONNREFUSED);
2753 * iscsi_session_event - send session destr. completion event
2754 * @session: iscsi class session
2755 * @event: type of event
2757 int iscsi_session_event(struct iscsi_cls_session *session,
2758 enum iscsi_uevent_e event)
2760 struct iscsi_internal *priv;
2761 struct Scsi_Host *shost;
2762 struct iscsi_uevent *ev;
2763 struct sk_buff *skb;
2764 struct nlmsghdr *nlh;
2765 int rc, len = nlmsg_total_size(sizeof(*ev));
2767 priv = iscsi_if_transport_lookup(session->transport);
2770 shost = iscsi_session_to_shost(session);
2772 skb = alloc_skb(len, GFP_KERNEL);
2774 iscsi_cls_session_printk(KERN_ERR, session,
2775 "Cannot notify userspace of session "
2776 "event %u\n", event);
2780 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2781 ev = nlmsg_data(nlh);
2782 ev->transport_handle = iscsi_handle(session->transport);
2786 case ISCSI_KEVENT_DESTROY_SESSION:
2787 ev->r.d_session.host_no = shost->host_no;
2788 ev->r.d_session.sid = session->sid;
2790 case ISCSI_KEVENT_CREATE_SESSION:
2791 ev->r.c_session_ret.host_no = shost->host_no;
2792 ev->r.c_session_ret.sid = session->sid;
2794 case ISCSI_KEVENT_UNBIND_SESSION:
2795 ev->r.unbind_session.host_no = shost->host_no;
2796 ev->r.unbind_session.sid = session->sid;
2799 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
2806 * this will occur if the daemon is not up, so we just warn
2807 * the user and when the daemon is restarted it will handle it
2809 rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
2811 iscsi_cls_session_printk(KERN_ERR, session,
2812 "Cannot notify userspace of session "
2813 "event %u. Check iscsi daemon\n",
2816 ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
2820 EXPORT_SYMBOL_GPL(iscsi_session_event);
2823 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
2824 struct iscsi_uevent *ev, pid_t pid,
2825 uint32_t initial_cmdsn, uint16_t cmds_max,
2826 uint16_t queue_depth)
2828 struct iscsi_transport *transport = priv->iscsi_transport;
2829 struct iscsi_cls_session *session;
2830 struct Scsi_Host *shost;
2832 session = transport->create_session(ep, cmds_max, queue_depth,
2837 session->creator = pid;
2838 shost = iscsi_session_to_shost(session);
2839 ev->r.c_session_ret.host_no = shost->host_no;
2840 ev->r.c_session_ret.sid = session->sid;
2841 ISCSI_DBG_TRANS_SESSION(session,
2842 "Completed creating transport session\n");
2847 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2849 struct iscsi_cls_conn *conn;
2850 struct iscsi_cls_session *session;
2852 session = iscsi_session_lookup(ev->u.c_conn.sid);
2854 printk(KERN_ERR "iscsi: invalid session %d.\n",
2859 conn = transport->create_conn(session, ev->u.c_conn.cid);
2861 iscsi_cls_session_printk(KERN_ERR, session,
2862 "couldn't create a new connection.");
2866 ev->r.c_conn_ret.sid = session->sid;
2867 ev->r.c_conn_ret.cid = conn->cid;
2869 ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
2874 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2876 struct iscsi_cls_conn *conn;
2878 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
2882 ISCSI_DBG_TRANS_CONN(conn, "Flushing cleanup during destruction\n");
2883 flush_work(&conn->cleanup_work);
2884 ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
2886 if (transport->destroy_conn)
2887 transport->destroy_conn(conn);
2892 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2894 char *data = (char*)ev + sizeof(*ev);
2895 struct iscsi_cls_conn *conn;
2896 struct iscsi_cls_session *session;
2897 int err = 0, value = 0;
2899 if (ev->u.set_param.len > PAGE_SIZE)
2902 session = iscsi_session_lookup(ev->u.set_param.sid);
2903 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
2904 if (!conn || !session)
2907 switch (ev->u.set_param.param) {
2908 case ISCSI_PARAM_SESS_RECOVERY_TMO:
2909 sscanf(data, "%d", &value);
2910 if (!session->recovery_tmo_sysfs_override)
2911 session->recovery_tmo = value;
2914 if ((conn->state == ISCSI_CONN_BOUND) ||
2915 (conn->state == ISCSI_CONN_UP)) {
2916 err = transport->set_param(conn, ev->u.set_param.param,
2917 data, ev->u.set_param.len);
2926 static int iscsi_if_ep_connect(struct iscsi_transport *transport,
2927 struct iscsi_uevent *ev, int msg_type)
2929 struct iscsi_endpoint *ep;
2930 struct sockaddr *dst_addr;
2931 struct Scsi_Host *shost = NULL;
2932 int non_blocking, err = 0;
2934 if (!transport->ep_connect)
2937 if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
2938 shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
2940 printk(KERN_ERR "ep connect failed. Could not find "
2942 ev->u.ep_connect_through_host.host_no);
2945 non_blocking = ev->u.ep_connect_through_host.non_blocking;
2947 non_blocking = ev->u.ep_connect.non_blocking;
2949 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
2950 ep = transport->ep_connect(shost, dst_addr, non_blocking);
2956 ev->r.ep_connect_ret.handle = ep->id;
2959 scsi_host_put(shost);
2963 static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
2966 struct iscsi_cls_conn *conn;
2967 struct iscsi_endpoint *ep;
2969 if (!transport->ep_disconnect)
2972 ep = iscsi_lookup_endpoint(ep_handle);
2979 * conn was not even bound yet, so we can't get iscsi conn
2982 transport->ep_disconnect(ep);
2986 mutex_lock(&conn->ep_mutex);
2987 /* Check if this was a conn error and the kernel took ownership */
2988 if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2989 ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2990 mutex_unlock(&conn->ep_mutex);
2992 flush_work(&conn->cleanup_work);
2996 iscsi_ep_disconnect(conn, false);
2997 mutex_unlock(&conn->ep_mutex);
2999 iscsi_put_endpoint(ep);
3004 iscsi_if_transport_ep(struct iscsi_transport *transport,
3005 struct iscsi_uevent *ev, int msg_type)
3007 struct iscsi_endpoint *ep;
3011 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3012 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3013 rc = iscsi_if_ep_connect(transport, ev, msg_type);
3015 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3016 if (!transport->ep_poll)
3019 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
3023 ev->r.retcode = transport->ep_poll(ep,
3024 ev->u.ep_poll.timeout_ms);
3025 iscsi_put_endpoint(ep);
3027 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3028 rc = iscsi_if_ep_disconnect(transport,
3029 ev->u.ep_disconnect.ep_handle);
3036 iscsi_tgt_dscvr(struct iscsi_transport *transport,
3037 struct iscsi_uevent *ev)
3039 struct Scsi_Host *shost;
3040 struct sockaddr *dst_addr;
3043 if (!transport->tgt_dscvr)
3046 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
3048 printk(KERN_ERR "target discovery could not find host no %u\n",
3049 ev->u.tgt_dscvr.host_no);
3054 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
3055 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
3056 ev->u.tgt_dscvr.enable, dst_addr);
3057 scsi_host_put(shost);
3062 iscsi_set_host_param(struct iscsi_transport *transport,
3063 struct iscsi_uevent *ev)
3065 char *data = (char*)ev + sizeof(*ev);
3066 struct Scsi_Host *shost;
3069 if (!transport->set_host_param)
3072 if (ev->u.set_host_param.len > PAGE_SIZE)
3075 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
3077 printk(KERN_ERR "set_host_param could not find host no %u\n",
3078 ev->u.set_host_param.host_no);
3082 err = transport->set_host_param(shost, ev->u.set_host_param.param,
3083 data, ev->u.set_host_param.len);
3084 scsi_host_put(shost);
3089 iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3091 struct Scsi_Host *shost;
3092 struct iscsi_path *params;
3095 if (!transport->set_path)
3098 shost = scsi_host_lookup(ev->u.set_path.host_no);
3100 printk(KERN_ERR "set path could not find host no %u\n",
3101 ev->u.set_path.host_no);
3105 params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
3106 err = transport->set_path(shost, params);
3108 scsi_host_put(shost);
3112 static int iscsi_session_has_conns(int sid)
3114 struct iscsi_cls_conn *conn;
3115 unsigned long flags;
3118 spin_lock_irqsave(&connlock, flags);
3119 list_for_each_entry(conn, &connlist, conn_list) {
3120 if (iscsi_conn_get_sid(conn) == sid) {
3125 spin_unlock_irqrestore(&connlock, flags);
3131 iscsi_set_iface_params(struct iscsi_transport *transport,
3132 struct iscsi_uevent *ev, uint32_t len)
3134 char *data = (char *)ev + sizeof(*ev);
3135 struct Scsi_Host *shost;
3138 if (!transport->set_iface_param)
3141 shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
3143 printk(KERN_ERR "set_iface_params could not find host no %u\n",
3144 ev->u.set_iface_params.host_no);
3148 err = transport->set_iface_param(shost, data, len);
3149 scsi_host_put(shost);
3154 iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3156 struct Scsi_Host *shost;
3157 struct sockaddr *dst_addr;
3160 if (!transport->send_ping)
3163 shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
3165 printk(KERN_ERR "iscsi_ping could not find host no %u\n",
3166 ev->u.iscsi_ping.host_no);
3170 dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
3171 err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
3172 ev->u.iscsi_ping.iface_type,
3173 ev->u.iscsi_ping.payload_size,
3174 ev->u.iscsi_ping.pid,
3176 scsi_host_put(shost);
3181 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3183 struct iscsi_uevent *ev = nlmsg_data(nlh);
3184 struct Scsi_Host *shost = NULL;
3185 struct iscsi_chap_rec *chap_rec;
3186 struct iscsi_internal *priv;
3187 struct sk_buff *skbchap;
3188 struct nlmsghdr *nlhchap;
3189 struct iscsi_uevent *evchap;
3190 uint32_t chap_buf_size;
3194 if (!transport->get_chap)
3197 priv = iscsi_if_transport_lookup(transport);
3201 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
3202 len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3204 shost = scsi_host_lookup(ev->u.get_chap.host_no);
3206 printk(KERN_ERR "%s: failed. Could not find host no %u\n",
3207 __func__, ev->u.get_chap.host_no);
3214 skbchap = alloc_skb(len, GFP_KERNEL);
3216 printk(KERN_ERR "can not deliver chap: OOM\n");
3221 nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
3222 (len - sizeof(*nlhchap)), 0);
3223 evchap = nlmsg_data(nlhchap);
3224 memset(evchap, 0, sizeof(*evchap));
3225 evchap->transport_handle = iscsi_handle(transport);
3226 evchap->type = nlh->nlmsg_type;
3227 evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
3228 evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
3229 evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
3230 buf = (char *)evchap + sizeof(*evchap);
3231 memset(buf, 0, chap_buf_size);
3233 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
3234 &evchap->u.get_chap.num_entries, buf);
3236 actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3237 skb_trim(skbchap, NLMSG_ALIGN(actual_size));
3238 nlhchap->nlmsg_len = actual_size;
3240 err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
3242 } while (err < 0 && err != -ECONNREFUSED);
3245 scsi_host_put(shost);
3249 static int iscsi_set_chap(struct iscsi_transport *transport,
3250 struct iscsi_uevent *ev, uint32_t len)
3252 char *data = (char *)ev + sizeof(*ev);
3253 struct Scsi_Host *shost;
3256 if (!transport->set_chap)
3259 shost = scsi_host_lookup(ev->u.set_path.host_no);
3261 pr_err("%s could not find host no %u\n",
3262 __func__, ev->u.set_path.host_no);
3266 err = transport->set_chap(shost, data, len);
3267 scsi_host_put(shost);
3271 static int iscsi_delete_chap(struct iscsi_transport *transport,
3272 struct iscsi_uevent *ev)
3274 struct Scsi_Host *shost;
3277 if (!transport->delete_chap)
3280 shost = scsi_host_lookup(ev->u.delete_chap.host_no);
3282 printk(KERN_ERR "%s could not find host no %u\n",
3283 __func__, ev->u.delete_chap.host_no);
3287 err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
3288 scsi_host_put(shost);
3292 static const struct {
3293 enum iscsi_discovery_parent_type value;
3295 } iscsi_discovery_parent_names[] = {
3296 {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
3297 {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
3298 {ISCSI_DISC_PARENT_ISNS, "isns" },
3301 char *iscsi_get_discovery_parent_name(int parent_type)
3304 char *state = "Unknown!";
3306 for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
3307 if (iscsi_discovery_parent_names[i].value & parent_type) {
3308 state = iscsi_discovery_parent_names[i].name;
3314 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
3316 static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
3317 struct iscsi_uevent *ev, uint32_t len)
3319 char *data = (char *)ev + sizeof(*ev);
3320 struct Scsi_Host *shost;
3321 struct iscsi_bus_flash_session *fnode_sess;
3322 struct iscsi_bus_flash_conn *fnode_conn;
3327 if (!transport->set_flashnode_param) {
3329 goto exit_set_fnode;
3332 shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
3334 pr_err("%s could not find host no %u\n",
3335 __func__, ev->u.set_flashnode.host_no);
3337 goto exit_set_fnode;
3340 idx = ev->u.set_flashnode.flashnode_idx;
3341 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3343 pr_err("%s could not find flashnode %u for host no %u\n",
3344 __func__, idx, ev->u.set_flashnode.host_no);
3349 dev = iscsi_find_flashnode_conn(fnode_sess);
3355 fnode_conn = iscsi_dev_to_flash_conn(dev);
3356 err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
3360 put_device(&fnode_sess->dev);
3363 scsi_host_put(shost);
3369 static int iscsi_new_flashnode(struct iscsi_transport *transport,
3370 struct iscsi_uevent *ev, uint32_t len)
3372 char *data = (char *)ev + sizeof(*ev);
3373 struct Scsi_Host *shost;
3377 if (!transport->new_flashnode) {
3379 goto exit_new_fnode;
3382 shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
3384 pr_err("%s could not find host no %u\n",
3385 __func__, ev->u.new_flashnode.host_no);
3390 index = transport->new_flashnode(shost, data, len);
3393 ev->r.new_flashnode_ret.flashnode_idx = index;
3398 scsi_host_put(shost);
3404 static int iscsi_del_flashnode(struct iscsi_transport *transport,
3405 struct iscsi_uevent *ev)
3407 struct Scsi_Host *shost;
3408 struct iscsi_bus_flash_session *fnode_sess;
3412 if (!transport->del_flashnode) {
3414 goto exit_del_fnode;
3417 shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
3419 pr_err("%s could not find host no %u\n",
3420 __func__, ev->u.del_flashnode.host_no);
3425 idx = ev->u.del_flashnode.flashnode_idx;
3426 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3428 pr_err("%s could not find flashnode %u for host no %u\n",
3429 __func__, idx, ev->u.del_flashnode.host_no);
3434 err = transport->del_flashnode(fnode_sess);
3435 put_device(&fnode_sess->dev);
3438 scsi_host_put(shost);
3444 static int iscsi_login_flashnode(struct iscsi_transport *transport,
3445 struct iscsi_uevent *ev)
3447 struct Scsi_Host *shost;
3448 struct iscsi_bus_flash_session *fnode_sess;
3449 struct iscsi_bus_flash_conn *fnode_conn;
3454 if (!transport->login_flashnode) {
3456 goto exit_login_fnode;
3459 shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
3461 pr_err("%s could not find host no %u\n",
3462 __func__, ev->u.login_flashnode.host_no);
3467 idx = ev->u.login_flashnode.flashnode_idx;
3468 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3470 pr_err("%s could not find flashnode %u for host no %u\n",
3471 __func__, idx, ev->u.login_flashnode.host_no);
3476 dev = iscsi_find_flashnode_conn(fnode_sess);
3482 fnode_conn = iscsi_dev_to_flash_conn(dev);
3483 err = transport->login_flashnode(fnode_sess, fnode_conn);
3487 put_device(&fnode_sess->dev);
3490 scsi_host_put(shost);
3496 static int iscsi_logout_flashnode(struct iscsi_transport *transport,
3497 struct iscsi_uevent *ev)
3499 struct Scsi_Host *shost;
3500 struct iscsi_bus_flash_session *fnode_sess;
3501 struct iscsi_bus_flash_conn *fnode_conn;
3506 if (!transport->logout_flashnode) {
3508 goto exit_logout_fnode;
3511 shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
3513 pr_err("%s could not find host no %u\n",
3514 __func__, ev->u.logout_flashnode.host_no);
3519 idx = ev->u.logout_flashnode.flashnode_idx;
3520 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3522 pr_err("%s could not find flashnode %u for host no %u\n",
3523 __func__, idx, ev->u.logout_flashnode.host_no);
3528 dev = iscsi_find_flashnode_conn(fnode_sess);
3534 fnode_conn = iscsi_dev_to_flash_conn(dev);
3536 err = transport->logout_flashnode(fnode_sess, fnode_conn);
3540 put_device(&fnode_sess->dev);
3543 scsi_host_put(shost);
3549 static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
3550 struct iscsi_uevent *ev)
3552 struct Scsi_Host *shost;
3553 struct iscsi_cls_session *session;
3556 if (!transport->logout_flashnode_sid) {
3558 goto exit_logout_sid;
3561 shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
3563 pr_err("%s could not find host no %u\n",
3564 __func__, ev->u.logout_flashnode.host_no);
3569 session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
3571 pr_err("%s could not find session id %u\n",
3572 __func__, ev->u.logout_flashnode_sid.sid);
3577 err = transport->logout_flashnode_sid(session);
3580 scsi_host_put(shost);
3587 iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3589 struct iscsi_uevent *ev = nlmsg_data(nlh);
3590 struct Scsi_Host *shost = NULL;
3591 struct iscsi_internal *priv;
3592 struct sk_buff *skbhost_stats;
3593 struct nlmsghdr *nlhhost_stats;
3594 struct iscsi_uevent *evhost_stats;
3595 int host_stats_size = 0;
3599 if (!transport->get_host_stats)
3602 priv = iscsi_if_transport_lookup(transport);
3606 host_stats_size = sizeof(struct iscsi_offload_host_stats);
3607 len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3609 shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
3611 pr_err("%s: failed. Could not find host no %u\n",
3612 __func__, ev->u.get_host_stats.host_no);
3619 skbhost_stats = alloc_skb(len, GFP_KERNEL);
3620 if (!skbhost_stats) {
3621 pr_err("cannot deliver host stats: OOM\n");
3623 goto exit_host_stats;
3626 nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
3627 (len - sizeof(*nlhhost_stats)), 0);
3628 evhost_stats = nlmsg_data(nlhhost_stats);
3629 memset(evhost_stats, 0, sizeof(*evhost_stats));
3630 evhost_stats->transport_handle = iscsi_handle(transport);
3631 evhost_stats->type = nlh->nlmsg_type;
3632 evhost_stats->u.get_host_stats.host_no =
3633 ev->u.get_host_stats.host_no;
3634 buf = (char *)evhost_stats + sizeof(*evhost_stats);
3635 memset(buf, 0, host_stats_size);
3637 err = transport->get_host_stats(shost, buf, host_stats_size);
3639 kfree_skb(skbhost_stats);
3640 goto exit_host_stats;
3643 actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3644 skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
3645 nlhhost_stats->nlmsg_len = actual_size;
3647 err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
3649 } while (err < 0 && err != -ECONNREFUSED);
3652 scsi_host_put(shost);
3656 static int iscsi_if_transport_conn(struct iscsi_transport *transport,
3657 struct nlmsghdr *nlh)
3659 struct iscsi_uevent *ev = nlmsg_data(nlh);
3660 struct iscsi_cls_session *session;
3661 struct iscsi_cls_conn *conn = NULL;
3662 struct iscsi_endpoint *ep;
3666 switch (nlh->nlmsg_type) {
3667 case ISCSI_UEVENT_CREATE_CONN:
3668 return iscsi_if_create_conn(transport, ev);
3669 case ISCSI_UEVENT_DESTROY_CONN:
3670 return iscsi_if_destroy_conn(transport, ev);
3671 case ISCSI_UEVENT_STOP_CONN:
3672 return iscsi_if_stop_conn(transport, ev);
3676 * The following cmds need to be run under the ep_mutex so in kernel
3677 * conn cleanup (ep_disconnect + unbind and conn) is not done while
3678 * these are running. They also must not run if we have just run a conn
3679 * cleanup because they would set the state in a way that might allow
3680 * IO or send IO themselves.
3682 switch (nlh->nlmsg_type) {
3683 case ISCSI_UEVENT_START_CONN:
3684 conn = iscsi_conn_lookup(ev->u.start_conn.sid,
3685 ev->u.start_conn.cid);
3687 case ISCSI_UEVENT_BIND_CONN:
3688 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
3690 case ISCSI_UEVENT_SEND_PDU:
3691 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
3698 mutex_lock(&conn->ep_mutex);
3699 if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
3700 mutex_unlock(&conn->ep_mutex);
3701 ev->r.retcode = -ENOTCONN;
3705 switch (nlh->nlmsg_type) {
3706 case ISCSI_UEVENT_BIND_CONN:
3709 * For offload boot support where iscsid is restarted
3710 * during the pivot root stage, the ep will be intact
3711 * here when the new iscsid instance starts up and
3714 iscsi_ep_disconnect(conn, true);
3717 session = iscsi_session_lookup(ev->u.b_conn.sid);
3723 ev->r.retcode = transport->bind_conn(session, conn,
3724 ev->u.b_conn.transport_eph,
3725 ev->u.b_conn.is_leading);
3727 conn->state = ISCSI_CONN_BOUND;
3729 if (ev->r.retcode || !transport->ep_connect)
3732 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
3736 iscsi_put_endpoint(ep);
3739 iscsi_cls_conn_printk(KERN_ERR, conn,
3740 "Could not set ep conn binding\n");
3743 case ISCSI_UEVENT_START_CONN:
3744 ev->r.retcode = transport->start_conn(conn);
3746 conn->state = ISCSI_CONN_UP;
3748 case ISCSI_UEVENT_SEND_PDU:
3749 pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
3751 if ((ev->u.send_pdu.hdr_size > pdu_len) ||
3752 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
3757 ev->r.retcode = transport->send_pdu(conn,
3758 (struct iscsi_hdr *)((char *)ev + sizeof(*ev)),
3759 (char *)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
3760 ev->u.send_pdu.data_size);
3766 mutex_unlock(&conn->ep_mutex);
3771 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
3775 struct iscsi_uevent *ev = nlmsg_data(nlh);
3776 struct iscsi_transport *transport = NULL;
3777 struct iscsi_internal *priv;
3778 struct iscsi_cls_session *session;
3779 struct iscsi_endpoint *ep = NULL;
3781 if (!netlink_capable(skb, CAP_SYS_ADMIN))
3784 if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
3785 *group = ISCSI_NL_GRP_UIP;
3787 *group = ISCSI_NL_GRP_ISCSID;
3789 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
3792 transport = priv->iscsi_transport;
3794 if (!try_module_get(transport->owner))
3797 portid = NETLINK_CB(skb).portid;
3799 switch (nlh->nlmsg_type) {
3800 case ISCSI_UEVENT_CREATE_SESSION:
3801 err = iscsi_if_create_session(priv, ep, ev,
3803 ev->u.c_session.initial_cmdsn,
3804 ev->u.c_session.cmds_max,
3805 ev->u.c_session.queue_depth);
3807 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
3808 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
3814 err = iscsi_if_create_session(priv, ep, ev,
3816 ev->u.c_bound_session.initial_cmdsn,
3817 ev->u.c_bound_session.cmds_max,
3818 ev->u.c_bound_session.queue_depth);
3819 iscsi_put_endpoint(ep);
3821 case ISCSI_UEVENT_DESTROY_SESSION:
3822 session = iscsi_session_lookup(ev->u.d_session.sid);
3825 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3828 transport->destroy_session(session);
3830 case ISCSI_UEVENT_DESTROY_SESSION_ASYNC:
3831 session = iscsi_session_lookup(ev->u.d_session.sid);
3834 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3837 unsigned long flags;
3839 /* Prevent this session from being found again */
3840 spin_lock_irqsave(&sesslock, flags);
3841 list_del_init(&session->sess_list);
3842 spin_unlock_irqrestore(&sesslock, flags);
3844 queue_work(system_unbound_wq, &session->destroy_work);
3847 case ISCSI_UEVENT_UNBIND_SESSION:
3848 session = iscsi_session_lookup(ev->u.d_session.sid);
3850 queue_work(session->workq, &session->unbind_work);
3854 case ISCSI_UEVENT_SET_PARAM:
3855 err = iscsi_set_param(transport, ev);
3857 case ISCSI_UEVENT_CREATE_CONN:
3858 case ISCSI_UEVENT_DESTROY_CONN:
3859 case ISCSI_UEVENT_STOP_CONN:
3860 case ISCSI_UEVENT_START_CONN:
3861 case ISCSI_UEVENT_BIND_CONN:
3862 case ISCSI_UEVENT_SEND_PDU:
3863 err = iscsi_if_transport_conn(transport, nlh);
3865 case ISCSI_UEVENT_GET_STATS:
3866 err = iscsi_if_get_stats(transport, nlh);
3868 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3869 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3870 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3871 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3872 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
3874 case ISCSI_UEVENT_TGT_DSCVR:
3875 err = iscsi_tgt_dscvr(transport, ev);
3877 case ISCSI_UEVENT_SET_HOST_PARAM:
3878 err = iscsi_set_host_param(transport, ev);
3880 case ISCSI_UEVENT_PATH_UPDATE:
3881 err = iscsi_set_path(transport, ev);
3883 case ISCSI_UEVENT_SET_IFACE_PARAMS:
3884 err = iscsi_set_iface_params(transport, ev,
3885 nlmsg_attrlen(nlh, sizeof(*ev)));
3887 case ISCSI_UEVENT_PING:
3888 err = iscsi_send_ping(transport, ev);
3890 case ISCSI_UEVENT_GET_CHAP:
3891 err = iscsi_get_chap(transport, nlh);
3893 case ISCSI_UEVENT_DELETE_CHAP:
3894 err = iscsi_delete_chap(transport, ev);
3896 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
3897 err = iscsi_set_flashnode_param(transport, ev,
3901 case ISCSI_UEVENT_NEW_FLASHNODE:
3902 err = iscsi_new_flashnode(transport, ev,
3903 nlmsg_attrlen(nlh, sizeof(*ev)));
3905 case ISCSI_UEVENT_DEL_FLASHNODE:
3906 err = iscsi_del_flashnode(transport, ev);
3908 case ISCSI_UEVENT_LOGIN_FLASHNODE:
3909 err = iscsi_login_flashnode(transport, ev);
3911 case ISCSI_UEVENT_LOGOUT_FLASHNODE:
3912 err = iscsi_logout_flashnode(transport, ev);
3914 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
3915 err = iscsi_logout_flashnode_sid(transport, ev);
3917 case ISCSI_UEVENT_SET_CHAP:
3918 err = iscsi_set_chap(transport, ev,
3919 nlmsg_attrlen(nlh, sizeof(*ev)));
3921 case ISCSI_UEVENT_GET_HOST_STATS:
3922 err = iscsi_get_host_stats(transport, nlh);
3929 module_put(transport->owner);
3934 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
3935 * Malformed skbs with wrong lengths or invalid creds are not processed.
3938 iscsi_if_rx(struct sk_buff *skb)
3940 u32 portid = NETLINK_CB(skb).portid;
3942 mutex_lock(&rx_queue_mutex);
3943 while (skb->len >= NLMSG_HDRLEN) {
3946 struct nlmsghdr *nlh;
3947 struct iscsi_uevent *ev;
3949 int retries = ISCSI_SEND_MAX_ALLOWED;
3951 nlh = nlmsg_hdr(skb);
3952 if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
3953 skb->len < nlh->nlmsg_len) {
3957 ev = nlmsg_data(nlh);
3958 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
3959 if (rlen > skb->len)
3962 err = iscsi_if_recv_msg(skb, nlh, &group);
3964 ev->type = ISCSI_KEVENT_IF_ERROR;
3969 * special case for GET_STATS:
3970 * on success - sending reply and stats from
3971 * inside of if_recv_msg(),
3972 * on error - fall through.
3974 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
3976 if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
3978 err = iscsi_if_send_reply(portid, nlh->nlmsg_type,
3980 if (err == -EAGAIN && --retries < 0) {
3981 printk(KERN_WARNING "Send reply failed, error %d\n", err);
3984 } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
3985 skb_pull(skb, rlen);
3987 mutex_unlock(&rx_queue_mutex);
3990 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
3991 struct device_attribute dev_attr_##_prefix##_##_name = \
3992 __ATTR(_name,_mode,_show,_store)
3995 * iSCSI connection attrs
3997 #define iscsi_conn_attr_show(param) \
3999 show_conn_param_##param(struct device *dev, \
4000 struct device_attribute *attr, char *buf) \
4002 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4003 struct iscsi_transport *t = conn->transport; \
4004 return t->get_conn_param(conn, param, buf); \
4007 #define iscsi_conn_attr(field, param) \
4008 iscsi_conn_attr_show(param) \
4009 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
4012 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
4013 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
4014 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
4015 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
4016 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
4017 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
4018 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
4019 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
4020 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
4021 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
4022 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
4023 iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
4024 iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
4025 iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
4026 iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
4027 iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
4028 iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
4029 iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
4030 iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
4031 iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
4032 iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
4033 iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
4034 iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
4035 iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
4036 iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
4037 iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
4038 iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
4039 iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
4041 static const char *const connection_state_names[] = {
4042 [ISCSI_CONN_UP] = "up",
4043 [ISCSI_CONN_DOWN] = "down",
4044 [ISCSI_CONN_FAILED] = "failed",
4045 [ISCSI_CONN_BOUND] = "bound"
4048 static ssize_t show_conn_state(struct device *dev,
4049 struct device_attribute *attr, char *buf)
4051 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent);
4052 const char *state = "unknown";
4054 if (conn->state >= 0 &&
4055 conn->state < ARRAY_SIZE(connection_state_names))
4056 state = connection_state_names[conn->state];
4058 return sysfs_emit(buf, "%s\n", state);
4060 static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
4063 #define iscsi_conn_ep_attr_show(param) \
4064 static ssize_t show_conn_ep_param_##param(struct device *dev, \
4065 struct device_attribute *attr,\
4068 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
4069 struct iscsi_transport *t = conn->transport; \
4070 struct iscsi_endpoint *ep; \
4074 * Need to make sure ep_disconnect does not free the LLD's \
4075 * interconnect resources while we are trying to read them. \
4077 mutex_lock(&conn->ep_mutex); \
4079 if (!ep && t->ep_connect) { \
4080 mutex_unlock(&conn->ep_mutex); \
4085 rc = t->get_ep_param(ep, param, buf); \
4087 rc = t->get_conn_param(conn, param, buf); \
4088 mutex_unlock(&conn->ep_mutex); \
4092 #define iscsi_conn_ep_attr(field, param) \
4093 iscsi_conn_ep_attr_show(param) \
4094 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
4095 show_conn_ep_param_##param, NULL);
4097 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
4098 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
4100 static struct attribute *iscsi_conn_attrs[] = {
4101 &dev_attr_conn_max_recv_dlength.attr,
4102 &dev_attr_conn_max_xmit_dlength.attr,
4103 &dev_attr_conn_header_digest.attr,
4104 &dev_attr_conn_data_digest.attr,
4105 &dev_attr_conn_ifmarker.attr,
4106 &dev_attr_conn_ofmarker.attr,
4107 &dev_attr_conn_address.attr,
4108 &dev_attr_conn_port.attr,
4109 &dev_attr_conn_exp_statsn.attr,
4110 &dev_attr_conn_persistent_address.attr,
4111 &dev_attr_conn_persistent_port.attr,
4112 &dev_attr_conn_ping_tmo.attr,
4113 &dev_attr_conn_recv_tmo.attr,
4114 &dev_attr_conn_local_port.attr,
4115 &dev_attr_conn_statsn.attr,
4116 &dev_attr_conn_keepalive_tmo.attr,
4117 &dev_attr_conn_max_segment_size.attr,
4118 &dev_attr_conn_tcp_timestamp_stat.attr,
4119 &dev_attr_conn_tcp_wsf_disable.attr,
4120 &dev_attr_conn_tcp_nagle_disable.attr,
4121 &dev_attr_conn_tcp_timer_scale.attr,
4122 &dev_attr_conn_tcp_timestamp_enable.attr,
4123 &dev_attr_conn_fragment_disable.attr,
4124 &dev_attr_conn_ipv4_tos.attr,
4125 &dev_attr_conn_ipv6_traffic_class.attr,
4126 &dev_attr_conn_ipv6_flow_label.attr,
4127 &dev_attr_conn_is_fw_assigned_ipv6.attr,
4128 &dev_attr_conn_tcp_xmit_wsf.attr,
4129 &dev_attr_conn_tcp_recv_wsf.attr,
4130 &dev_attr_conn_local_ipaddr.attr,
4131 &dev_attr_conn_state.attr,
4135 static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
4136 struct attribute *attr, int i)
4138 struct device *cdev = container_of(kobj, struct device, kobj);
4139 struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
4140 struct iscsi_transport *t = conn->transport;
4143 if (attr == &dev_attr_conn_max_recv_dlength.attr)
4144 param = ISCSI_PARAM_MAX_RECV_DLENGTH;
4145 else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
4146 param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
4147 else if (attr == &dev_attr_conn_header_digest.attr)
4148 param = ISCSI_PARAM_HDRDGST_EN;
4149 else if (attr == &dev_attr_conn_data_digest.attr)
4150 param = ISCSI_PARAM_DATADGST_EN;
4151 else if (attr == &dev_attr_conn_ifmarker.attr)
4152 param = ISCSI_PARAM_IFMARKER_EN;
4153 else if (attr == &dev_attr_conn_ofmarker.attr)
4154 param = ISCSI_PARAM_OFMARKER_EN;
4155 else if (attr == &dev_attr_conn_address.attr)
4156 param = ISCSI_PARAM_CONN_ADDRESS;
4157 else if (attr == &dev_attr_conn_port.attr)
4158 param = ISCSI_PARAM_CONN_PORT;
4159 else if (attr == &dev_attr_conn_exp_statsn.attr)
4160 param = ISCSI_PARAM_EXP_STATSN;
4161 else if (attr == &dev_attr_conn_persistent_address.attr)
4162 param = ISCSI_PARAM_PERSISTENT_ADDRESS;
4163 else if (attr == &dev_attr_conn_persistent_port.attr)
4164 param = ISCSI_PARAM_PERSISTENT_PORT;
4165 else if (attr == &dev_attr_conn_ping_tmo.attr)
4166 param = ISCSI_PARAM_PING_TMO;
4167 else if (attr == &dev_attr_conn_recv_tmo.attr)
4168 param = ISCSI_PARAM_RECV_TMO;
4169 else if (attr == &dev_attr_conn_local_port.attr)
4170 param = ISCSI_PARAM_LOCAL_PORT;
4171 else if (attr == &dev_attr_conn_statsn.attr)
4172 param = ISCSI_PARAM_STATSN;
4173 else if (attr == &dev_attr_conn_keepalive_tmo.attr)
4174 param = ISCSI_PARAM_KEEPALIVE_TMO;
4175 else if (attr == &dev_attr_conn_max_segment_size.attr)
4176 param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
4177 else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
4178 param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
4179 else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
4180 param = ISCSI_PARAM_TCP_WSF_DISABLE;
4181 else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
4182 param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
4183 else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
4184 param = ISCSI_PARAM_TCP_TIMER_SCALE;
4185 else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
4186 param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
4187 else if (attr == &dev_attr_conn_fragment_disable.attr)
4188 param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
4189 else if (attr == &dev_attr_conn_ipv4_tos.attr)
4190 param = ISCSI_PARAM_IPV4_TOS;
4191 else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
4192 param = ISCSI_PARAM_IPV6_TC;
4193 else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
4194 param = ISCSI_PARAM_IPV6_FLOW_LABEL;
4195 else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
4196 param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
4197 else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
4198 param = ISCSI_PARAM_TCP_XMIT_WSF;
4199 else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
4200 param = ISCSI_PARAM_TCP_RECV_WSF;
4201 else if (attr == &dev_attr_conn_local_ipaddr.attr)
4202 param = ISCSI_PARAM_LOCAL_IPADDR;
4203 else if (attr == &dev_attr_conn_state.attr)
4206 WARN_ONCE(1, "Invalid conn attr");
4210 return t->attr_is_visible(ISCSI_PARAM, param);
4213 static struct attribute_group iscsi_conn_group = {
4214 .attrs = iscsi_conn_attrs,
4215 .is_visible = iscsi_conn_attr_is_visible,
4219 * iSCSI session attrs
4221 #define iscsi_session_attr_show(param, perm) \
4223 show_session_param_##param(struct device *dev, \
4224 struct device_attribute *attr, char *buf) \
4226 struct iscsi_cls_session *session = \
4227 iscsi_dev_to_session(dev->parent); \
4228 struct iscsi_transport *t = session->transport; \
4230 if (perm && !capable(CAP_SYS_ADMIN)) \
4232 return t->get_session_param(session, param, buf); \
4235 #define iscsi_session_attr(field, param, perm) \
4236 iscsi_session_attr_show(param, perm) \
4237 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
4239 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
4240 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
4241 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
4242 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
4243 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
4244 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
4245 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
4246 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
4247 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
4248 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
4249 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
4250 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
4251 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
4252 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
4253 iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
4254 iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
4255 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
4256 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
4257 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
4258 iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
4259 iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
4260 iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
4261 iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
4262 iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
4263 iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
4264 iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
4265 iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
4266 iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
4267 iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
4268 iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
4269 iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
4270 iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
4271 iscsi_session_attr(discovery_auth_optional,
4272 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
4273 iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
4274 iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
4275 iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
4276 iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
4277 iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
4278 iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
4279 iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
4282 show_priv_session_state(struct device *dev, struct device_attribute *attr,
4285 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4286 return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
4288 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
4291 show_priv_session_creator(struct device *dev, struct device_attribute *attr,
4294 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4295 return sysfs_emit(buf, "%d\n", session->creator);
4297 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
4300 show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
4303 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4304 return sysfs_emit(buf, "%d\n", session->target_id);
4306 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
4307 show_priv_session_target_id, NULL);
4309 #define iscsi_priv_session_attr_show(field, format) \
4311 show_priv_session_##field(struct device *dev, \
4312 struct device_attribute *attr, char *buf) \
4314 struct iscsi_cls_session *session = \
4315 iscsi_dev_to_session(dev->parent); \
4316 if (session->field == -1) \
4317 return sysfs_emit(buf, "off\n"); \
4318 return sysfs_emit(buf, format"\n", session->field); \
4321 #define iscsi_priv_session_attr_store(field) \
4323 store_priv_session_##field(struct device *dev, \
4324 struct device_attribute *attr, \
4325 const char *buf, size_t count) \
4329 struct iscsi_cls_session *session = \
4330 iscsi_dev_to_session(dev->parent); \
4331 if ((session->state == ISCSI_SESSION_FREE) || \
4332 (session->state == ISCSI_SESSION_FAILED)) \
4334 if (strncmp(buf, "off", 3) == 0) { \
4335 session->field = -1; \
4336 session->field##_sysfs_override = true; \
4338 val = simple_strtoul(buf, &cp, 0); \
4339 if (*cp != '\0' && *cp != '\n') \
4341 session->field = val; \
4342 session->field##_sysfs_override = true; \
4347 #define iscsi_priv_session_rw_attr(field, format) \
4348 iscsi_priv_session_attr_show(field, format) \
4349 iscsi_priv_session_attr_store(field) \
4350 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
4351 show_priv_session_##field, \
4352 store_priv_session_##field)
4354 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
4356 static struct attribute *iscsi_session_attrs[] = {
4357 &dev_attr_sess_initial_r2t.attr,
4358 &dev_attr_sess_max_outstanding_r2t.attr,
4359 &dev_attr_sess_immediate_data.attr,
4360 &dev_attr_sess_first_burst_len.attr,
4361 &dev_attr_sess_max_burst_len.attr,
4362 &dev_attr_sess_data_pdu_in_order.attr,
4363 &dev_attr_sess_data_seq_in_order.attr,
4364 &dev_attr_sess_erl.attr,
4365 &dev_attr_sess_targetname.attr,
4366 &dev_attr_sess_tpgt.attr,
4367 &dev_attr_sess_password.attr,
4368 &dev_attr_sess_password_in.attr,
4369 &dev_attr_sess_username.attr,
4370 &dev_attr_sess_username_in.attr,
4371 &dev_attr_sess_fast_abort.attr,
4372 &dev_attr_sess_abort_tmo.attr,
4373 &dev_attr_sess_lu_reset_tmo.attr,
4374 &dev_attr_sess_tgt_reset_tmo.attr,
4375 &dev_attr_sess_ifacename.attr,
4376 &dev_attr_sess_initiatorname.attr,
4377 &dev_attr_sess_targetalias.attr,
4378 &dev_attr_sess_boot_root.attr,
4379 &dev_attr_sess_boot_nic.attr,
4380 &dev_attr_sess_boot_target.attr,
4381 &dev_attr_priv_sess_recovery_tmo.attr,
4382 &dev_attr_priv_sess_state.attr,
4383 &dev_attr_priv_sess_creator.attr,
4384 &dev_attr_sess_chap_out_idx.attr,
4385 &dev_attr_sess_chap_in_idx.attr,
4386 &dev_attr_priv_sess_target_id.attr,
4387 &dev_attr_sess_auto_snd_tgt_disable.attr,
4388 &dev_attr_sess_discovery_session.attr,
4389 &dev_attr_sess_portal_type.attr,
4390 &dev_attr_sess_chap_auth.attr,
4391 &dev_attr_sess_discovery_logout.attr,
4392 &dev_attr_sess_bidi_chap.attr,
4393 &dev_attr_sess_discovery_auth_optional.attr,
4394 &dev_attr_sess_def_time2wait.attr,
4395 &dev_attr_sess_def_time2retain.attr,
4396 &dev_attr_sess_isid.attr,
4397 &dev_attr_sess_tsid.attr,
4398 &dev_attr_sess_def_taskmgmt_tmo.attr,
4399 &dev_attr_sess_discovery_parent_idx.attr,
4400 &dev_attr_sess_discovery_parent_type.attr,
4404 static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
4405 struct attribute *attr, int i)
4407 struct device *cdev = container_of(kobj, struct device, kobj);
4408 struct iscsi_cls_session *session = transport_class_to_session(cdev);
4409 struct iscsi_transport *t = session->transport;
4412 if (attr == &dev_attr_sess_initial_r2t.attr)
4413 param = ISCSI_PARAM_INITIAL_R2T_EN;
4414 else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
4415 param = ISCSI_PARAM_MAX_R2T;
4416 else if (attr == &dev_attr_sess_immediate_data.attr)
4417 param = ISCSI_PARAM_IMM_DATA_EN;
4418 else if (attr == &dev_attr_sess_first_burst_len.attr)
4419 param = ISCSI_PARAM_FIRST_BURST;
4420 else if (attr == &dev_attr_sess_max_burst_len.attr)
4421 param = ISCSI_PARAM_MAX_BURST;
4422 else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
4423 param = ISCSI_PARAM_PDU_INORDER_EN;
4424 else if (attr == &dev_attr_sess_data_seq_in_order.attr)
4425 param = ISCSI_PARAM_DATASEQ_INORDER_EN;
4426 else if (attr == &dev_attr_sess_erl.attr)
4427 param = ISCSI_PARAM_ERL;
4428 else if (attr == &dev_attr_sess_targetname.attr)
4429 param = ISCSI_PARAM_TARGET_NAME;
4430 else if (attr == &dev_attr_sess_tpgt.attr)
4431 param = ISCSI_PARAM_TPGT;
4432 else if (attr == &dev_attr_sess_chap_in_idx.attr)
4433 param = ISCSI_PARAM_CHAP_IN_IDX;
4434 else if (attr == &dev_attr_sess_chap_out_idx.attr)
4435 param = ISCSI_PARAM_CHAP_OUT_IDX;
4436 else if (attr == &dev_attr_sess_password.attr)
4437 param = ISCSI_PARAM_USERNAME;
4438 else if (attr == &dev_attr_sess_password_in.attr)
4439 param = ISCSI_PARAM_USERNAME_IN;
4440 else if (attr == &dev_attr_sess_username.attr)
4441 param = ISCSI_PARAM_PASSWORD;
4442 else if (attr == &dev_attr_sess_username_in.attr)
4443 param = ISCSI_PARAM_PASSWORD_IN;
4444 else if (attr == &dev_attr_sess_fast_abort.attr)
4445 param = ISCSI_PARAM_FAST_ABORT;
4446 else if (attr == &dev_attr_sess_abort_tmo.attr)
4447 param = ISCSI_PARAM_ABORT_TMO;
4448 else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
4449 param = ISCSI_PARAM_LU_RESET_TMO;
4450 else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
4451 param = ISCSI_PARAM_TGT_RESET_TMO;
4452 else if (attr == &dev_attr_sess_ifacename.attr)
4453 param = ISCSI_PARAM_IFACE_NAME;
4454 else if (attr == &dev_attr_sess_initiatorname.attr)
4455 param = ISCSI_PARAM_INITIATOR_NAME;
4456 else if (attr == &dev_attr_sess_targetalias.attr)
4457 param = ISCSI_PARAM_TARGET_ALIAS;
4458 else if (attr == &dev_attr_sess_boot_root.attr)
4459 param = ISCSI_PARAM_BOOT_ROOT;
4460 else if (attr == &dev_attr_sess_boot_nic.attr)
4461 param = ISCSI_PARAM_BOOT_NIC;
4462 else if (attr == &dev_attr_sess_boot_target.attr)
4463 param = ISCSI_PARAM_BOOT_TARGET;
4464 else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
4465 param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
4466 else if (attr == &dev_attr_sess_discovery_session.attr)
4467 param = ISCSI_PARAM_DISCOVERY_SESS;
4468 else if (attr == &dev_attr_sess_portal_type.attr)
4469 param = ISCSI_PARAM_PORTAL_TYPE;
4470 else if (attr == &dev_attr_sess_chap_auth.attr)
4471 param = ISCSI_PARAM_CHAP_AUTH_EN;
4472 else if (attr == &dev_attr_sess_discovery_logout.attr)
4473 param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
4474 else if (attr == &dev_attr_sess_bidi_chap.attr)
4475 param = ISCSI_PARAM_BIDI_CHAP_EN;
4476 else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
4477 param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
4478 else if (attr == &dev_attr_sess_def_time2wait.attr)
4479 param = ISCSI_PARAM_DEF_TIME2WAIT;
4480 else if (attr == &dev_attr_sess_def_time2retain.attr)
4481 param = ISCSI_PARAM_DEF_TIME2RETAIN;
4482 else if (attr == &dev_attr_sess_isid.attr)
4483 param = ISCSI_PARAM_ISID;
4484 else if (attr == &dev_attr_sess_tsid.attr)
4485 param = ISCSI_PARAM_TSID;
4486 else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
4487 param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
4488 else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
4489 param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
4490 else if (attr == &dev_attr_sess_discovery_parent_type.attr)
4491 param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
4492 else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
4493 return S_IRUGO | S_IWUSR;
4494 else if (attr == &dev_attr_priv_sess_state.attr)
4496 else if (attr == &dev_attr_priv_sess_creator.attr)
4498 else if (attr == &dev_attr_priv_sess_target_id.attr)
4501 WARN_ONCE(1, "Invalid session attr");
4505 return t->attr_is_visible(ISCSI_PARAM, param);
4508 static struct attribute_group iscsi_session_group = {
4509 .attrs = iscsi_session_attrs,
4510 .is_visible = iscsi_session_attr_is_visible,
4516 #define iscsi_host_attr_show(param) \
4518 show_host_param_##param(struct device *dev, \
4519 struct device_attribute *attr, char *buf) \
4521 struct Scsi_Host *shost = transport_class_to_shost(dev); \
4522 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
4523 return priv->iscsi_transport->get_host_param(shost, param, buf); \
4526 #define iscsi_host_attr(field, param) \
4527 iscsi_host_attr_show(param) \
4528 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
4531 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
4532 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
4533 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
4534 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
4535 iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
4536 iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
4538 static struct attribute *iscsi_host_attrs[] = {
4539 &dev_attr_host_netdev.attr,
4540 &dev_attr_host_hwaddress.attr,
4541 &dev_attr_host_ipaddress.attr,
4542 &dev_attr_host_initiatorname.attr,
4543 &dev_attr_host_port_state.attr,
4544 &dev_attr_host_port_speed.attr,
4548 static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
4549 struct attribute *attr, int i)
4551 struct device *cdev = container_of(kobj, struct device, kobj);
4552 struct Scsi_Host *shost = transport_class_to_shost(cdev);
4553 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
4556 if (attr == &dev_attr_host_netdev.attr)
4557 param = ISCSI_HOST_PARAM_NETDEV_NAME;
4558 else if (attr == &dev_attr_host_hwaddress.attr)
4559 param = ISCSI_HOST_PARAM_HWADDRESS;
4560 else if (attr == &dev_attr_host_ipaddress.attr)
4561 param = ISCSI_HOST_PARAM_IPADDRESS;
4562 else if (attr == &dev_attr_host_initiatorname.attr)
4563 param = ISCSI_HOST_PARAM_INITIATOR_NAME;
4564 else if (attr == &dev_attr_host_port_state.attr)
4565 param = ISCSI_HOST_PARAM_PORT_STATE;
4566 else if (attr == &dev_attr_host_port_speed.attr)
4567 param = ISCSI_HOST_PARAM_PORT_SPEED;
4569 WARN_ONCE(1, "Invalid host attr");
4573 return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
4576 static struct attribute_group iscsi_host_group = {
4577 .attrs = iscsi_host_attrs,
4578 .is_visible = iscsi_host_attr_is_visible,
4581 /* convert iscsi_port_speed values to ascii string name */
4582 static const struct {
4583 enum iscsi_port_speed value;
4585 } iscsi_port_speed_names[] = {
4586 {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
4587 {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
4588 {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
4589 {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
4590 {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
4591 {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" },
4592 {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" },
4595 char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
4598 char *speed = "Unknown!";
4599 struct iscsi_cls_host *ihost = shost->shost_data;
4600 uint32_t port_speed = ihost->port_speed;
4602 for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
4603 if (iscsi_port_speed_names[i].value & port_speed) {
4604 speed = iscsi_port_speed_names[i].name;
4610 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
4612 /* convert iscsi_port_state values to ascii string name */
4613 static const struct {
4614 enum iscsi_port_state value;
4616 } iscsi_port_state_names[] = {
4617 {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
4618 {ISCSI_PORT_STATE_UP, "LINK UP" },
4621 char *iscsi_get_port_state_name(struct Scsi_Host *shost)
4624 char *state = "Unknown!";
4625 struct iscsi_cls_host *ihost = shost->shost_data;
4626 uint32_t port_state = ihost->port_state;
4628 for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
4629 if (iscsi_port_state_names[i].value & port_state) {
4630 state = iscsi_port_state_names[i].name;
4636 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
4638 static int iscsi_session_match(struct attribute_container *cont,
4641 struct iscsi_cls_session *session;
4642 struct Scsi_Host *shost;
4643 struct iscsi_internal *priv;
4645 if (!iscsi_is_session_dev(dev))
4648 session = iscsi_dev_to_session(dev);
4649 shost = iscsi_session_to_shost(session);
4650 if (!shost->transportt)
4653 priv = to_iscsi_internal(shost->transportt);
4654 if (priv->session_cont.ac.class != &iscsi_session_class.class)
4657 return &priv->session_cont.ac == cont;
4660 static int iscsi_conn_match(struct attribute_container *cont,
4663 struct iscsi_cls_session *session;
4664 struct iscsi_cls_conn *conn;
4665 struct Scsi_Host *shost;
4666 struct iscsi_internal *priv;
4668 if (!iscsi_is_conn_dev(dev))
4671 conn = iscsi_dev_to_conn(dev);
4672 session = iscsi_dev_to_session(conn->dev.parent);
4673 shost = iscsi_session_to_shost(session);
4675 if (!shost->transportt)
4678 priv = to_iscsi_internal(shost->transportt);
4679 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
4682 return &priv->conn_cont.ac == cont;
4685 static int iscsi_host_match(struct attribute_container *cont,
4688 struct Scsi_Host *shost;
4689 struct iscsi_internal *priv;
4691 if (!scsi_is_host_device(dev))
4694 shost = dev_to_shost(dev);
4695 if (!shost->transportt ||
4696 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
4699 priv = to_iscsi_internal(shost->transportt);
4700 return &priv->t.host_attrs.ac == cont;
4703 struct scsi_transport_template *
4704 iscsi_register_transport(struct iscsi_transport *tt)
4706 struct iscsi_internal *priv;
4707 unsigned long flags;
4711 WARN_ON(tt->ep_disconnect && !tt->unbind_conn);
4713 priv = iscsi_if_transport_lookup(tt);
4717 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
4720 INIT_LIST_HEAD(&priv->list);
4721 priv->iscsi_transport = tt;
4722 priv->t.user_scan = iscsi_user_scan;
4724 priv->dev.class = &iscsi_transport_class;
4725 dev_set_name(&priv->dev, "%s", tt->name);
4726 err = device_register(&priv->dev);
4730 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
4732 goto unregister_dev;
4734 /* host parameters */
4735 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
4736 priv->t.host_attrs.ac.match = iscsi_host_match;
4737 priv->t.host_attrs.ac.grp = &iscsi_host_group;
4738 priv->t.host_size = sizeof(struct iscsi_cls_host);
4739 transport_container_register(&priv->t.host_attrs);
4741 /* connection parameters */
4742 priv->conn_cont.ac.class = &iscsi_connection_class.class;
4743 priv->conn_cont.ac.match = iscsi_conn_match;
4744 priv->conn_cont.ac.grp = &iscsi_conn_group;
4745 transport_container_register(&priv->conn_cont);
4747 /* session parameters */
4748 priv->session_cont.ac.class = &iscsi_session_class.class;
4749 priv->session_cont.ac.match = iscsi_session_match;
4750 priv->session_cont.ac.grp = &iscsi_session_group;
4751 transport_container_register(&priv->session_cont);
4753 spin_lock_irqsave(&iscsi_transport_lock, flags);
4754 list_add(&priv->list, &iscsi_transports);
4755 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4757 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
4761 device_unregister(&priv->dev);
4767 EXPORT_SYMBOL_GPL(iscsi_register_transport);
4769 int iscsi_unregister_transport(struct iscsi_transport *tt)
4771 struct iscsi_internal *priv;
4772 unsigned long flags;
4776 mutex_lock(&rx_queue_mutex);
4778 priv = iscsi_if_transport_lookup(tt);
4781 spin_lock_irqsave(&iscsi_transport_lock, flags);
4782 list_del(&priv->list);
4783 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4785 transport_container_unregister(&priv->conn_cont);
4786 transport_container_unregister(&priv->session_cont);
4787 transport_container_unregister(&priv->t.host_attrs);
4789 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
4790 device_unregister(&priv->dev);
4791 mutex_unlock(&rx_queue_mutex);
4795 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
4797 void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *),
4798 struct device *dev, const char *fmt, ...)
4800 struct va_format vaf;
4803 va_start(args, fmt);
4809 EXPORT_SYMBOL_GPL(iscsi_dbg_trace);
4811 static __init int iscsi_transport_init(void)
4814 struct netlink_kernel_cfg cfg = {
4816 .input = iscsi_if_rx,
4818 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
4819 ISCSI_TRANSPORT_VERSION);
4821 atomic_set(&iscsi_session_nr, 0);
4823 err = class_register(&iscsi_transport_class);
4827 err = class_register(&iscsi_endpoint_class);
4829 goto unregister_transport_class;
4831 err = class_register(&iscsi_iface_class);
4833 goto unregister_endpoint_class;
4835 err = transport_class_register(&iscsi_host_class);
4837 goto unregister_iface_class;
4839 err = transport_class_register(&iscsi_connection_class);
4841 goto unregister_host_class;
4843 err = transport_class_register(&iscsi_session_class);
4845 goto unregister_conn_class;
4847 err = bus_register(&iscsi_flashnode_bus);
4849 goto unregister_session_class;
4851 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
4854 goto unregister_flashnode_bus;
4857 iscsi_conn_cleanup_workq = alloc_workqueue("%s",
4858 WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND, 0,
4859 "iscsi_conn_cleanup");
4860 if (!iscsi_conn_cleanup_workq) {
4868 netlink_kernel_release(nls);
4869 unregister_flashnode_bus:
4870 bus_unregister(&iscsi_flashnode_bus);
4871 unregister_session_class:
4872 transport_class_unregister(&iscsi_session_class);
4873 unregister_conn_class:
4874 transport_class_unregister(&iscsi_connection_class);
4875 unregister_host_class:
4876 transport_class_unregister(&iscsi_host_class);
4877 unregister_iface_class:
4878 class_unregister(&iscsi_iface_class);
4879 unregister_endpoint_class:
4880 class_unregister(&iscsi_endpoint_class);
4881 unregister_transport_class:
4882 class_unregister(&iscsi_transport_class);
4886 static void __exit iscsi_transport_exit(void)
4888 destroy_workqueue(iscsi_conn_cleanup_workq);
4889 netlink_kernel_release(nls);
4890 bus_unregister(&iscsi_flashnode_bus);
4891 transport_class_unregister(&iscsi_connection_class);
4892 transport_class_unregister(&iscsi_session_class);
4893 transport_class_unregister(&iscsi_host_class);
4894 class_unregister(&iscsi_endpoint_class);
4895 class_unregister(&iscsi_iface_class);
4896 class_unregister(&iscsi_transport_class);
4899 module_init(iscsi_transport_init);
4900 module_exit(iscsi_transport_exit);
4902 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
4903 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
4904 "Alex Aizman <itn780@yahoo.com>");
4905 MODULE_DESCRIPTION("iSCSI Transport Interface");
4906 MODULE_LICENSE("GPL");
4907 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
4908 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);