2 * iSCSI transport class definitions
4 * Copyright (C) IBM Corporation, 2004
5 * Copyright (C) Mike Christie, 2004 - 2005
6 * Copyright (C) Dmitry Yusupov, 2004 - 2005
7 * Copyright (C) Alex Aizman, 2004 - 2005
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <linux/module.h>
24 #include <linux/mutex.h>
25 #include <linux/slab.h>
26 #include <linux/bsg-lib.h>
27 #include <linux/idr.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_transport.h>
33 #include <scsi/scsi_transport_iscsi.h>
34 #include <scsi/iscsi_if.h>
35 #include <scsi/scsi_cmnd.h>
36 #include <scsi/scsi_bsg_iscsi.h>
38 #define ISCSI_TRANSPORT_VERSION "2.0-870"
40 static int dbg_session
;
41 module_param_named(debug_session
, dbg_session
, int,
43 MODULE_PARM_DESC(debug_session
,
44 "Turn on debugging for sessions in scsi_transport_iscsi "
45 "module. Set to 1 to turn on, and zero to turn off. Default "
49 module_param_named(debug_conn
, dbg_conn
, int,
51 MODULE_PARM_DESC(debug_conn
,
52 "Turn on debugging for connections in scsi_transport_iscsi "
53 "module. Set to 1 to turn on, and zero to turn off. Default "
56 #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \
59 iscsi_cls_session_printk(KERN_INFO, _session, \
64 #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \
67 iscsi_cls_conn_printk(KERN_INFO, _conn, \
72 struct iscsi_internal
{
73 struct scsi_transport_template t
;
74 struct iscsi_transport
*iscsi_transport
;
75 struct list_head list
;
78 struct transport_container conn_cont
;
79 struct transport_container session_cont
;
82 static atomic_t iscsi_session_nr
; /* sysfs session id for next new session */
83 static struct workqueue_struct
*iscsi_eh_timer_workq
;
85 static DEFINE_IDA(iscsi_sess_ida
);
87 * list of registered transports and lock that must
88 * be held while accessing list. The iscsi_transport_lock must
89 * be acquired after the rx_queue_mutex.
91 static LIST_HEAD(iscsi_transports
);
92 static DEFINE_SPINLOCK(iscsi_transport_lock
);
94 #define to_iscsi_internal(tmpl) \
95 container_of(tmpl, struct iscsi_internal, t)
97 #define dev_to_iscsi_internal(_dev) \
98 container_of(_dev, struct iscsi_internal, dev)
100 static void iscsi_transport_release(struct device
*dev
)
102 struct iscsi_internal
*priv
= dev_to_iscsi_internal(dev
);
107 * iscsi_transport_class represents the iscsi_transports that are
110 static struct class iscsi_transport_class
= {
111 .name
= "iscsi_transport",
112 .dev_release
= iscsi_transport_release
,
116 show_transport_handle(struct device
*dev
, struct device_attribute
*attr
,
119 struct iscsi_internal
*priv
= dev_to_iscsi_internal(dev
);
120 return sprintf(buf
, "%llu\n", (unsigned long long)iscsi_handle(priv
->iscsi_transport
));
122 static DEVICE_ATTR(handle
, S_IRUGO
, show_transport_handle
, NULL
);
124 #define show_transport_attr(name, format) \
126 show_transport_##name(struct device *dev, \
127 struct device_attribute *attr,char *buf) \
129 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
130 return sprintf(buf, format"\n", priv->iscsi_transport->name); \
132 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
134 show_transport_attr(caps
, "0x%x");
136 static struct attribute
*iscsi_transport_attrs
[] = {
137 &dev_attr_handle
.attr
,
142 static struct attribute_group iscsi_transport_group
= {
143 .attrs
= iscsi_transport_attrs
,
147 * iSCSI endpoint attrs
149 #define iscsi_dev_to_endpoint(_dev) \
150 container_of(_dev, struct iscsi_endpoint, dev)
152 #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
153 struct device_attribute dev_attr_##_prefix##_##_name = \
154 __ATTR(_name,_mode,_show,_store)
156 static void iscsi_endpoint_release(struct device
*dev
)
158 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
162 static struct class iscsi_endpoint_class
= {
163 .name
= "iscsi_endpoint",
164 .dev_release
= iscsi_endpoint_release
,
168 show_ep_handle(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
170 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
171 return sprintf(buf
, "%llu\n", (unsigned long long) ep
->id
);
173 static ISCSI_ATTR(ep
, handle
, S_IRUGO
, show_ep_handle
, NULL
);
175 static struct attribute
*iscsi_endpoint_attrs
[] = {
176 &dev_attr_ep_handle
.attr
,
180 static struct attribute_group iscsi_endpoint_group
= {
181 .attrs
= iscsi_endpoint_attrs
,
184 #define ISCSI_MAX_EPID -1
186 static int iscsi_match_epid(struct device
*dev
, const void *data
)
188 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
189 const uint64_t *epid
= data
;
191 return *epid
== ep
->id
;
194 struct iscsi_endpoint
*
195 iscsi_create_endpoint(int dd_size
)
198 struct iscsi_endpoint
*ep
;
202 for (id
= 1; id
< ISCSI_MAX_EPID
; id
++) {
203 dev
= class_find_device(&iscsi_endpoint_class
, NULL
, &id
,
208 if (id
== ISCSI_MAX_EPID
) {
209 printk(KERN_ERR
"Too many connections. Max supported %u\n",
214 ep
= kzalloc(sizeof(*ep
) + dd_size
, GFP_KERNEL
);
219 ep
->dev
.class = &iscsi_endpoint_class
;
220 dev_set_name(&ep
->dev
, "ep-%llu", (unsigned long long) id
);
221 err
= device_register(&ep
->dev
);
225 err
= sysfs_create_group(&ep
->dev
.kobj
, &iscsi_endpoint_group
);
230 ep
->dd_data
= &ep
[1];
234 device_unregister(&ep
->dev
);
241 EXPORT_SYMBOL_GPL(iscsi_create_endpoint
);
243 void iscsi_destroy_endpoint(struct iscsi_endpoint
*ep
)
245 sysfs_remove_group(&ep
->dev
.kobj
, &iscsi_endpoint_group
);
246 device_unregister(&ep
->dev
);
248 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint
);
250 struct iscsi_endpoint
*iscsi_lookup_endpoint(u64 handle
)
252 struct iscsi_endpoint
*ep
;
255 dev
= class_find_device(&iscsi_endpoint_class
, NULL
, &handle
,
260 ep
= iscsi_dev_to_endpoint(dev
);
262 * we can drop this now because the interface will prevent
263 * removals and lookups from racing.
268 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint
);
271 * Interface to display network param to sysfs
274 static void iscsi_iface_release(struct device
*dev
)
276 struct iscsi_iface
*iface
= iscsi_dev_to_iface(dev
);
277 struct device
*parent
= iface
->dev
.parent
;
284 static struct class iscsi_iface_class
= {
285 .name
= "iscsi_iface",
286 .dev_release
= iscsi_iface_release
,
289 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
290 struct device_attribute dev_attr_##_prefix##_##_name = \
291 __ATTR(_name, _mode, _show, _store)
293 /* iface attrs show */
294 #define iscsi_iface_attr_show(type, name, param_type, param) \
296 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
299 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
300 struct iscsi_transport *t = iface->transport; \
301 return t->get_iface_param(iface, param_type, param, buf); \
304 #define iscsi_iface_net_attr(type, name, param) \
305 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
306 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
308 /* generic read only ipvi4 attribute */
309 iscsi_iface_net_attr(ipv4_iface
, ipaddress
, ISCSI_NET_PARAM_IPV4_ADDR
);
310 iscsi_iface_net_attr(ipv4_iface
, gateway
, ISCSI_NET_PARAM_IPV4_GW
);
311 iscsi_iface_net_attr(ipv4_iface
, subnet
, ISCSI_NET_PARAM_IPV4_SUBNET
);
312 iscsi_iface_net_attr(ipv4_iface
, bootproto
, ISCSI_NET_PARAM_IPV4_BOOTPROTO
);
314 /* generic read only ipv6 attribute */
315 iscsi_iface_net_attr(ipv6_iface
, ipaddress
, ISCSI_NET_PARAM_IPV6_ADDR
);
316 iscsi_iface_net_attr(ipv6_iface
, link_local_addr
, ISCSI_NET_PARAM_IPV6_LINKLOCAL
);
317 iscsi_iface_net_attr(ipv6_iface
, router_addr
, ISCSI_NET_PARAM_IPV6_ROUTER
);
318 iscsi_iface_net_attr(ipv6_iface
, ipaddr_autocfg
,
319 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
);
320 iscsi_iface_net_attr(ipv6_iface
, link_local_autocfg
,
321 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
);
323 /* common read only iface attribute */
324 iscsi_iface_net_attr(iface
, enabled
, ISCSI_NET_PARAM_IFACE_ENABLE
);
325 iscsi_iface_net_attr(iface
, vlan_id
, ISCSI_NET_PARAM_VLAN_ID
);
326 iscsi_iface_net_attr(iface
, vlan_priority
, ISCSI_NET_PARAM_VLAN_PRIORITY
);
327 iscsi_iface_net_attr(iface
, vlan_enabled
, ISCSI_NET_PARAM_VLAN_ENABLED
);
328 iscsi_iface_net_attr(iface
, mtu
, ISCSI_NET_PARAM_MTU
);
329 iscsi_iface_net_attr(iface
, port
, ISCSI_NET_PARAM_PORT
);
331 static umode_t
iscsi_iface_attr_is_visible(struct kobject
*kobj
,
332 struct attribute
*attr
, int i
)
334 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
335 struct iscsi_iface
*iface
= iscsi_dev_to_iface(dev
);
336 struct iscsi_transport
*t
= iface
->transport
;
339 if (attr
== &dev_attr_iface_enabled
.attr
)
340 param
= ISCSI_NET_PARAM_IFACE_ENABLE
;
341 else if (attr
== &dev_attr_iface_vlan_id
.attr
)
342 param
= ISCSI_NET_PARAM_VLAN_ID
;
343 else if (attr
== &dev_attr_iface_vlan_priority
.attr
)
344 param
= ISCSI_NET_PARAM_VLAN_PRIORITY
;
345 else if (attr
== &dev_attr_iface_vlan_enabled
.attr
)
346 param
= ISCSI_NET_PARAM_VLAN_ENABLED
;
347 else if (attr
== &dev_attr_iface_mtu
.attr
)
348 param
= ISCSI_NET_PARAM_MTU
;
349 else if (attr
== &dev_attr_iface_port
.attr
)
350 param
= ISCSI_NET_PARAM_PORT
;
351 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
) {
352 if (attr
== &dev_attr_ipv4_iface_ipaddress
.attr
)
353 param
= ISCSI_NET_PARAM_IPV4_ADDR
;
354 else if (attr
== &dev_attr_ipv4_iface_gateway
.attr
)
355 param
= ISCSI_NET_PARAM_IPV4_GW
;
356 else if (attr
== &dev_attr_ipv4_iface_subnet
.attr
)
357 param
= ISCSI_NET_PARAM_IPV4_SUBNET
;
358 else if (attr
== &dev_attr_ipv4_iface_bootproto
.attr
)
359 param
= ISCSI_NET_PARAM_IPV4_BOOTPROTO
;
362 } else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
) {
363 if (attr
== &dev_attr_ipv6_iface_ipaddress
.attr
)
364 param
= ISCSI_NET_PARAM_IPV6_ADDR
;
365 else if (attr
== &dev_attr_ipv6_iface_link_local_addr
.attr
)
366 param
= ISCSI_NET_PARAM_IPV6_LINKLOCAL
;
367 else if (attr
== &dev_attr_ipv6_iface_router_addr
.attr
)
368 param
= ISCSI_NET_PARAM_IPV6_ROUTER
;
369 else if (attr
== &dev_attr_ipv6_iface_ipaddr_autocfg
.attr
)
370 param
= ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
;
371 else if (attr
== &dev_attr_ipv6_iface_link_local_autocfg
.attr
)
372 param
= ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
;
376 WARN_ONCE(1, "Invalid iface attr");
380 return t
->attr_is_visible(ISCSI_NET_PARAM
, param
);
383 static struct attribute
*iscsi_iface_attrs
[] = {
384 &dev_attr_iface_enabled
.attr
,
385 &dev_attr_iface_vlan_id
.attr
,
386 &dev_attr_iface_vlan_priority
.attr
,
387 &dev_attr_iface_vlan_enabled
.attr
,
388 &dev_attr_ipv4_iface_ipaddress
.attr
,
389 &dev_attr_ipv4_iface_gateway
.attr
,
390 &dev_attr_ipv4_iface_subnet
.attr
,
391 &dev_attr_ipv4_iface_bootproto
.attr
,
392 &dev_attr_ipv6_iface_ipaddress
.attr
,
393 &dev_attr_ipv6_iface_link_local_addr
.attr
,
394 &dev_attr_ipv6_iface_router_addr
.attr
,
395 &dev_attr_ipv6_iface_ipaddr_autocfg
.attr
,
396 &dev_attr_ipv6_iface_link_local_autocfg
.attr
,
397 &dev_attr_iface_mtu
.attr
,
398 &dev_attr_iface_port
.attr
,
402 static struct attribute_group iscsi_iface_group
= {
403 .attrs
= iscsi_iface_attrs
,
404 .is_visible
= iscsi_iface_attr_is_visible
,
408 iscsi_create_iface(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
409 uint32_t iface_type
, uint32_t iface_num
, int dd_size
)
411 struct iscsi_iface
*iface
;
414 iface
= kzalloc(sizeof(*iface
) + dd_size
, GFP_KERNEL
);
418 iface
->transport
= transport
;
419 iface
->iface_type
= iface_type
;
420 iface
->iface_num
= iface_num
;
421 iface
->dev
.release
= iscsi_iface_release
;
422 iface
->dev
.class = &iscsi_iface_class
;
423 /* parent reference released in iscsi_iface_release */
424 iface
->dev
.parent
= get_device(&shost
->shost_gendev
);
425 if (iface_type
== ISCSI_IFACE_TYPE_IPV4
)
426 dev_set_name(&iface
->dev
, "ipv4-iface-%u-%u", shost
->host_no
,
429 dev_set_name(&iface
->dev
, "ipv6-iface-%u-%u", shost
->host_no
,
432 err
= device_register(&iface
->dev
);
436 err
= sysfs_create_group(&iface
->dev
.kobj
, &iscsi_iface_group
);
441 iface
->dd_data
= &iface
[1];
445 device_unregister(&iface
->dev
);
449 put_device(iface
->dev
.parent
);
453 EXPORT_SYMBOL_GPL(iscsi_create_iface
);
455 void iscsi_destroy_iface(struct iscsi_iface
*iface
)
457 sysfs_remove_group(&iface
->dev
.kobj
, &iscsi_iface_group
);
458 device_unregister(&iface
->dev
);
460 EXPORT_SYMBOL_GPL(iscsi_destroy_iface
);
463 * Interface to display flash node params to sysfs
466 #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
467 struct device_attribute dev_attr_##_prefix##_##_name = \
468 __ATTR(_name, _mode, _show, _store)
470 /* flash node session attrs show */
471 #define iscsi_flashnode_sess_attr_show(type, name, param) \
473 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
476 struct iscsi_bus_flash_session *fnode_sess = \
477 iscsi_dev_to_flash_session(dev);\
478 struct iscsi_transport *t = fnode_sess->transport; \
479 return t->get_flashnode_param(fnode_sess, param, buf); \
483 #define iscsi_flashnode_sess_attr(type, name, param) \
484 iscsi_flashnode_sess_attr_show(type, name, param) \
485 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
486 show_##type##_##name, NULL);
488 /* Flash node session attributes */
490 iscsi_flashnode_sess_attr(fnode
, auto_snd_tgt_disable
,
491 ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE
);
492 iscsi_flashnode_sess_attr(fnode
, discovery_session
,
493 ISCSI_FLASHNODE_DISCOVERY_SESS
);
494 iscsi_flashnode_sess_attr(fnode
, portal_type
, ISCSI_FLASHNODE_PORTAL_TYPE
);
495 iscsi_flashnode_sess_attr(fnode
, entry_enable
, ISCSI_FLASHNODE_ENTRY_EN
);
496 iscsi_flashnode_sess_attr(fnode
, immediate_data
, ISCSI_FLASHNODE_IMM_DATA_EN
);
497 iscsi_flashnode_sess_attr(fnode
, initial_r2t
, ISCSI_FLASHNODE_INITIAL_R2T_EN
);
498 iscsi_flashnode_sess_attr(fnode
, data_seq_in_order
,
499 ISCSI_FLASHNODE_DATASEQ_INORDER
);
500 iscsi_flashnode_sess_attr(fnode
, data_pdu_in_order
,
501 ISCSI_FLASHNODE_PDU_INORDER
);
502 iscsi_flashnode_sess_attr(fnode
, chap_auth
, ISCSI_FLASHNODE_CHAP_AUTH_EN
);
503 iscsi_flashnode_sess_attr(fnode
, discovery_logout
,
504 ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN
);
505 iscsi_flashnode_sess_attr(fnode
, bidi_chap
, ISCSI_FLASHNODE_BIDI_CHAP_EN
);
506 iscsi_flashnode_sess_attr(fnode
, discovery_auth_optional
,
507 ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL
);
508 iscsi_flashnode_sess_attr(fnode
, erl
, ISCSI_FLASHNODE_ERL
);
509 iscsi_flashnode_sess_attr(fnode
, first_burst_len
, ISCSI_FLASHNODE_FIRST_BURST
);
510 iscsi_flashnode_sess_attr(fnode
, def_time2wait
, ISCSI_FLASHNODE_DEF_TIME2WAIT
);
511 iscsi_flashnode_sess_attr(fnode
, def_time2retain
,
512 ISCSI_FLASHNODE_DEF_TIME2RETAIN
);
513 iscsi_flashnode_sess_attr(fnode
, max_outstanding_r2t
, ISCSI_FLASHNODE_MAX_R2T
);
514 iscsi_flashnode_sess_attr(fnode
, isid
, ISCSI_FLASHNODE_ISID
);
515 iscsi_flashnode_sess_attr(fnode
, tsid
, ISCSI_FLASHNODE_TSID
);
516 iscsi_flashnode_sess_attr(fnode
, max_burst_len
, ISCSI_FLASHNODE_MAX_BURST
);
517 iscsi_flashnode_sess_attr(fnode
, def_taskmgmt_tmo
,
518 ISCSI_FLASHNODE_DEF_TASKMGMT_TMO
);
519 iscsi_flashnode_sess_attr(fnode
, targetalias
, ISCSI_FLASHNODE_ALIAS
);
520 iscsi_flashnode_sess_attr(fnode
, targetname
, ISCSI_FLASHNODE_NAME
);
521 iscsi_flashnode_sess_attr(fnode
, tpgt
, ISCSI_FLASHNODE_TPGT
);
522 iscsi_flashnode_sess_attr(fnode
, discovery_parent_idx
,
523 ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX
);
524 iscsi_flashnode_sess_attr(fnode
, discovery_parent_type
,
525 ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE
);
526 iscsi_flashnode_sess_attr(fnode
, chap_in_idx
, ISCSI_FLASHNODE_CHAP_IN_IDX
);
527 iscsi_flashnode_sess_attr(fnode
, chap_out_idx
, ISCSI_FLASHNODE_CHAP_OUT_IDX
);
528 iscsi_flashnode_sess_attr(fnode
, username
, ISCSI_FLASHNODE_USERNAME
);
529 iscsi_flashnode_sess_attr(fnode
, username_in
, ISCSI_FLASHNODE_USERNAME_IN
);
530 iscsi_flashnode_sess_attr(fnode
, password
, ISCSI_FLASHNODE_PASSWORD
);
531 iscsi_flashnode_sess_attr(fnode
, password_in
, ISCSI_FLASHNODE_PASSWORD_IN
);
532 iscsi_flashnode_sess_attr(fnode
, is_boot_target
, ISCSI_FLASHNODE_IS_BOOT_TGT
);
534 static struct attribute
*iscsi_flashnode_sess_attrs
[] = {
535 &dev_attr_fnode_auto_snd_tgt_disable
.attr
,
536 &dev_attr_fnode_discovery_session
.attr
,
537 &dev_attr_fnode_portal_type
.attr
,
538 &dev_attr_fnode_entry_enable
.attr
,
539 &dev_attr_fnode_immediate_data
.attr
,
540 &dev_attr_fnode_initial_r2t
.attr
,
541 &dev_attr_fnode_data_seq_in_order
.attr
,
542 &dev_attr_fnode_data_pdu_in_order
.attr
,
543 &dev_attr_fnode_chap_auth
.attr
,
544 &dev_attr_fnode_discovery_logout
.attr
,
545 &dev_attr_fnode_bidi_chap
.attr
,
546 &dev_attr_fnode_discovery_auth_optional
.attr
,
547 &dev_attr_fnode_erl
.attr
,
548 &dev_attr_fnode_first_burst_len
.attr
,
549 &dev_attr_fnode_def_time2wait
.attr
,
550 &dev_attr_fnode_def_time2retain
.attr
,
551 &dev_attr_fnode_max_outstanding_r2t
.attr
,
552 &dev_attr_fnode_isid
.attr
,
553 &dev_attr_fnode_tsid
.attr
,
554 &dev_attr_fnode_max_burst_len
.attr
,
555 &dev_attr_fnode_def_taskmgmt_tmo
.attr
,
556 &dev_attr_fnode_targetalias
.attr
,
557 &dev_attr_fnode_targetname
.attr
,
558 &dev_attr_fnode_tpgt
.attr
,
559 &dev_attr_fnode_discovery_parent_idx
.attr
,
560 &dev_attr_fnode_discovery_parent_type
.attr
,
561 &dev_attr_fnode_chap_in_idx
.attr
,
562 &dev_attr_fnode_chap_out_idx
.attr
,
563 &dev_attr_fnode_username
.attr
,
564 &dev_attr_fnode_username_in
.attr
,
565 &dev_attr_fnode_password
.attr
,
566 &dev_attr_fnode_password_in
.attr
,
567 &dev_attr_fnode_is_boot_target
.attr
,
571 static umode_t
iscsi_flashnode_sess_attr_is_visible(struct kobject
*kobj
,
572 struct attribute
*attr
,
575 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
576 struct iscsi_bus_flash_session
*fnode_sess
=
577 iscsi_dev_to_flash_session(dev
);
578 struct iscsi_transport
*t
= fnode_sess
->transport
;
581 if (attr
== &dev_attr_fnode_auto_snd_tgt_disable
.attr
) {
582 param
= ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE
;
583 } else if (attr
== &dev_attr_fnode_discovery_session
.attr
) {
584 param
= ISCSI_FLASHNODE_DISCOVERY_SESS
;
585 } else if (attr
== &dev_attr_fnode_portal_type
.attr
) {
586 param
= ISCSI_FLASHNODE_PORTAL_TYPE
;
587 } else if (attr
== &dev_attr_fnode_entry_enable
.attr
) {
588 param
= ISCSI_FLASHNODE_ENTRY_EN
;
589 } else if (attr
== &dev_attr_fnode_immediate_data
.attr
) {
590 param
= ISCSI_FLASHNODE_IMM_DATA_EN
;
591 } else if (attr
== &dev_attr_fnode_initial_r2t
.attr
) {
592 param
= ISCSI_FLASHNODE_INITIAL_R2T_EN
;
593 } else if (attr
== &dev_attr_fnode_data_seq_in_order
.attr
) {
594 param
= ISCSI_FLASHNODE_DATASEQ_INORDER
;
595 } else if (attr
== &dev_attr_fnode_data_pdu_in_order
.attr
) {
596 param
= ISCSI_FLASHNODE_PDU_INORDER
;
597 } else if (attr
== &dev_attr_fnode_chap_auth
.attr
) {
598 param
= ISCSI_FLASHNODE_CHAP_AUTH_EN
;
599 } else if (attr
== &dev_attr_fnode_discovery_logout
.attr
) {
600 param
= ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN
;
601 } else if (attr
== &dev_attr_fnode_bidi_chap
.attr
) {
602 param
= ISCSI_FLASHNODE_BIDI_CHAP_EN
;
603 } else if (attr
== &dev_attr_fnode_discovery_auth_optional
.attr
) {
604 param
= ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL
;
605 } else if (attr
== &dev_attr_fnode_erl
.attr
) {
606 param
= ISCSI_FLASHNODE_ERL
;
607 } else if (attr
== &dev_attr_fnode_first_burst_len
.attr
) {
608 param
= ISCSI_FLASHNODE_FIRST_BURST
;
609 } else if (attr
== &dev_attr_fnode_def_time2wait
.attr
) {
610 param
= ISCSI_FLASHNODE_DEF_TIME2WAIT
;
611 } else if (attr
== &dev_attr_fnode_def_time2retain
.attr
) {
612 param
= ISCSI_FLASHNODE_DEF_TIME2RETAIN
;
613 } else if (attr
== &dev_attr_fnode_max_outstanding_r2t
.attr
) {
614 param
= ISCSI_FLASHNODE_MAX_R2T
;
615 } else if (attr
== &dev_attr_fnode_isid
.attr
) {
616 param
= ISCSI_FLASHNODE_ISID
;
617 } else if (attr
== &dev_attr_fnode_tsid
.attr
) {
618 param
= ISCSI_FLASHNODE_TSID
;
619 } else if (attr
== &dev_attr_fnode_max_burst_len
.attr
) {
620 param
= ISCSI_FLASHNODE_MAX_BURST
;
621 } else if (attr
== &dev_attr_fnode_def_taskmgmt_tmo
.attr
) {
622 param
= ISCSI_FLASHNODE_DEF_TASKMGMT_TMO
;
623 } else if (attr
== &dev_attr_fnode_targetalias
.attr
) {
624 param
= ISCSI_FLASHNODE_ALIAS
;
625 } else if (attr
== &dev_attr_fnode_targetname
.attr
) {
626 param
= ISCSI_FLASHNODE_NAME
;
627 } else if (attr
== &dev_attr_fnode_tpgt
.attr
) {
628 param
= ISCSI_FLASHNODE_TPGT
;
629 } else if (attr
== &dev_attr_fnode_discovery_parent_idx
.attr
) {
630 param
= ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX
;
631 } else if (attr
== &dev_attr_fnode_discovery_parent_type
.attr
) {
632 param
= ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE
;
633 } else if (attr
== &dev_attr_fnode_chap_in_idx
.attr
) {
634 param
= ISCSI_FLASHNODE_CHAP_IN_IDX
;
635 } else if (attr
== &dev_attr_fnode_chap_out_idx
.attr
) {
636 param
= ISCSI_FLASHNODE_CHAP_OUT_IDX
;
637 } else if (attr
== &dev_attr_fnode_username
.attr
) {
638 param
= ISCSI_FLASHNODE_USERNAME
;
639 } else if (attr
== &dev_attr_fnode_username_in
.attr
) {
640 param
= ISCSI_FLASHNODE_USERNAME_IN
;
641 } else if (attr
== &dev_attr_fnode_password
.attr
) {
642 param
= ISCSI_FLASHNODE_PASSWORD
;
643 } else if (attr
== &dev_attr_fnode_password_in
.attr
) {
644 param
= ISCSI_FLASHNODE_PASSWORD_IN
;
645 } else if (attr
== &dev_attr_fnode_is_boot_target
.attr
) {
646 param
= ISCSI_FLASHNODE_IS_BOOT_TGT
;
648 WARN_ONCE(1, "Invalid flashnode session attr");
652 return t
->attr_is_visible(ISCSI_FLASHNODE_PARAM
, param
);
655 static struct attribute_group iscsi_flashnode_sess_attr_group
= {
656 .attrs
= iscsi_flashnode_sess_attrs
,
657 .is_visible
= iscsi_flashnode_sess_attr_is_visible
,
660 static const struct attribute_group
*iscsi_flashnode_sess_attr_groups
[] = {
661 &iscsi_flashnode_sess_attr_group
,
665 static void iscsi_flashnode_sess_release(struct device
*dev
)
667 struct iscsi_bus_flash_session
*fnode_sess
=
668 iscsi_dev_to_flash_session(dev
);
670 kfree(fnode_sess
->targetname
);
671 kfree(fnode_sess
->targetalias
);
672 kfree(fnode_sess
->portal_type
);
676 struct device_type iscsi_flashnode_sess_dev_type
= {
677 .name
= "iscsi_flashnode_sess_dev_type",
678 .groups
= iscsi_flashnode_sess_attr_groups
,
679 .release
= iscsi_flashnode_sess_release
,
682 /* flash node connection attrs show */
683 #define iscsi_flashnode_conn_attr_show(type, name, param) \
685 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
688 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
689 struct iscsi_bus_flash_session *fnode_sess = \
690 iscsi_flash_conn_to_flash_session(fnode_conn);\
691 struct iscsi_transport *t = fnode_conn->transport; \
692 return t->get_flashnode_param(fnode_sess, param, buf); \
696 #define iscsi_flashnode_conn_attr(type, name, param) \
697 iscsi_flashnode_conn_attr_show(type, name, param) \
698 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
699 show_##type##_##name, NULL);
701 /* Flash node connection attributes */
703 iscsi_flashnode_conn_attr(fnode
, is_fw_assigned_ipv6
,
704 ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6
);
705 iscsi_flashnode_conn_attr(fnode
, header_digest
, ISCSI_FLASHNODE_HDR_DGST_EN
);
706 iscsi_flashnode_conn_attr(fnode
, data_digest
, ISCSI_FLASHNODE_DATA_DGST_EN
);
707 iscsi_flashnode_conn_attr(fnode
, snack_req
, ISCSI_FLASHNODE_SNACK_REQ_EN
);
708 iscsi_flashnode_conn_attr(fnode
, tcp_timestamp_stat
,
709 ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT
);
710 iscsi_flashnode_conn_attr(fnode
, tcp_nagle_disable
,
711 ISCSI_FLASHNODE_TCP_NAGLE_DISABLE
);
712 iscsi_flashnode_conn_attr(fnode
, tcp_wsf_disable
,
713 ISCSI_FLASHNODE_TCP_WSF_DISABLE
);
714 iscsi_flashnode_conn_attr(fnode
, tcp_timer_scale
,
715 ISCSI_FLASHNODE_TCP_TIMER_SCALE
);
716 iscsi_flashnode_conn_attr(fnode
, tcp_timestamp_enable
,
717 ISCSI_FLASHNODE_TCP_TIMESTAMP_EN
);
718 iscsi_flashnode_conn_attr(fnode
, fragment_disable
,
719 ISCSI_FLASHNODE_IP_FRAG_DISABLE
);
720 iscsi_flashnode_conn_attr(fnode
, keepalive_tmo
, ISCSI_FLASHNODE_KEEPALIVE_TMO
);
721 iscsi_flashnode_conn_attr(fnode
, port
, ISCSI_FLASHNODE_PORT
);
722 iscsi_flashnode_conn_attr(fnode
, ipaddress
, ISCSI_FLASHNODE_IPADDR
);
723 iscsi_flashnode_conn_attr(fnode
, max_recv_dlength
,
724 ISCSI_FLASHNODE_MAX_RECV_DLENGTH
);
725 iscsi_flashnode_conn_attr(fnode
, max_xmit_dlength
,
726 ISCSI_FLASHNODE_MAX_XMIT_DLENGTH
);
727 iscsi_flashnode_conn_attr(fnode
, local_port
, ISCSI_FLASHNODE_LOCAL_PORT
);
728 iscsi_flashnode_conn_attr(fnode
, ipv4_tos
, ISCSI_FLASHNODE_IPV4_TOS
);
729 iscsi_flashnode_conn_attr(fnode
, ipv6_traffic_class
, ISCSI_FLASHNODE_IPV6_TC
);
730 iscsi_flashnode_conn_attr(fnode
, ipv6_flow_label
,
731 ISCSI_FLASHNODE_IPV6_FLOW_LABEL
);
732 iscsi_flashnode_conn_attr(fnode
, redirect_ipaddr
,
733 ISCSI_FLASHNODE_REDIRECT_IPADDR
);
734 iscsi_flashnode_conn_attr(fnode
, max_segment_size
,
735 ISCSI_FLASHNODE_MAX_SEGMENT_SIZE
);
736 iscsi_flashnode_conn_attr(fnode
, link_local_ipv6
,
737 ISCSI_FLASHNODE_LINK_LOCAL_IPV6
);
738 iscsi_flashnode_conn_attr(fnode
, tcp_xmit_wsf
, ISCSI_FLASHNODE_TCP_XMIT_WSF
);
739 iscsi_flashnode_conn_attr(fnode
, tcp_recv_wsf
, ISCSI_FLASHNODE_TCP_RECV_WSF
);
740 iscsi_flashnode_conn_attr(fnode
, statsn
, ISCSI_FLASHNODE_STATSN
);
741 iscsi_flashnode_conn_attr(fnode
, exp_statsn
, ISCSI_FLASHNODE_EXP_STATSN
);
743 static struct attribute
*iscsi_flashnode_conn_attrs
[] = {
744 &dev_attr_fnode_is_fw_assigned_ipv6
.attr
,
745 &dev_attr_fnode_header_digest
.attr
,
746 &dev_attr_fnode_data_digest
.attr
,
747 &dev_attr_fnode_snack_req
.attr
,
748 &dev_attr_fnode_tcp_timestamp_stat
.attr
,
749 &dev_attr_fnode_tcp_nagle_disable
.attr
,
750 &dev_attr_fnode_tcp_wsf_disable
.attr
,
751 &dev_attr_fnode_tcp_timer_scale
.attr
,
752 &dev_attr_fnode_tcp_timestamp_enable
.attr
,
753 &dev_attr_fnode_fragment_disable
.attr
,
754 &dev_attr_fnode_max_recv_dlength
.attr
,
755 &dev_attr_fnode_max_xmit_dlength
.attr
,
756 &dev_attr_fnode_keepalive_tmo
.attr
,
757 &dev_attr_fnode_port
.attr
,
758 &dev_attr_fnode_ipaddress
.attr
,
759 &dev_attr_fnode_redirect_ipaddr
.attr
,
760 &dev_attr_fnode_max_segment_size
.attr
,
761 &dev_attr_fnode_local_port
.attr
,
762 &dev_attr_fnode_ipv4_tos
.attr
,
763 &dev_attr_fnode_ipv6_traffic_class
.attr
,
764 &dev_attr_fnode_ipv6_flow_label
.attr
,
765 &dev_attr_fnode_link_local_ipv6
.attr
,
766 &dev_attr_fnode_tcp_xmit_wsf
.attr
,
767 &dev_attr_fnode_tcp_recv_wsf
.attr
,
768 &dev_attr_fnode_statsn
.attr
,
769 &dev_attr_fnode_exp_statsn
.attr
,
773 static umode_t
iscsi_flashnode_conn_attr_is_visible(struct kobject
*kobj
,
774 struct attribute
*attr
,
777 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
778 struct iscsi_bus_flash_conn
*fnode_conn
= iscsi_dev_to_flash_conn(dev
);
779 struct iscsi_transport
*t
= fnode_conn
->transport
;
782 if (attr
== &dev_attr_fnode_is_fw_assigned_ipv6
.attr
) {
783 param
= ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6
;
784 } else if (attr
== &dev_attr_fnode_header_digest
.attr
) {
785 param
= ISCSI_FLASHNODE_HDR_DGST_EN
;
786 } else if (attr
== &dev_attr_fnode_data_digest
.attr
) {
787 param
= ISCSI_FLASHNODE_DATA_DGST_EN
;
788 } else if (attr
== &dev_attr_fnode_snack_req
.attr
) {
789 param
= ISCSI_FLASHNODE_SNACK_REQ_EN
;
790 } else if (attr
== &dev_attr_fnode_tcp_timestamp_stat
.attr
) {
791 param
= ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT
;
792 } else if (attr
== &dev_attr_fnode_tcp_nagle_disable
.attr
) {
793 param
= ISCSI_FLASHNODE_TCP_NAGLE_DISABLE
;
794 } else if (attr
== &dev_attr_fnode_tcp_wsf_disable
.attr
) {
795 param
= ISCSI_FLASHNODE_TCP_WSF_DISABLE
;
796 } else if (attr
== &dev_attr_fnode_tcp_timer_scale
.attr
) {
797 param
= ISCSI_FLASHNODE_TCP_TIMER_SCALE
;
798 } else if (attr
== &dev_attr_fnode_tcp_timestamp_enable
.attr
) {
799 param
= ISCSI_FLASHNODE_TCP_TIMESTAMP_EN
;
800 } else if (attr
== &dev_attr_fnode_fragment_disable
.attr
) {
801 param
= ISCSI_FLASHNODE_IP_FRAG_DISABLE
;
802 } else if (attr
== &dev_attr_fnode_max_recv_dlength
.attr
) {
803 param
= ISCSI_FLASHNODE_MAX_RECV_DLENGTH
;
804 } else if (attr
== &dev_attr_fnode_max_xmit_dlength
.attr
) {
805 param
= ISCSI_FLASHNODE_MAX_XMIT_DLENGTH
;
806 } else if (attr
== &dev_attr_fnode_keepalive_tmo
.attr
) {
807 param
= ISCSI_FLASHNODE_KEEPALIVE_TMO
;
808 } else if (attr
== &dev_attr_fnode_port
.attr
) {
809 param
= ISCSI_FLASHNODE_PORT
;
810 } else if (attr
== &dev_attr_fnode_ipaddress
.attr
) {
811 param
= ISCSI_FLASHNODE_IPADDR
;
812 } else if (attr
== &dev_attr_fnode_redirect_ipaddr
.attr
) {
813 param
= ISCSI_FLASHNODE_REDIRECT_IPADDR
;
814 } else if (attr
== &dev_attr_fnode_max_segment_size
.attr
) {
815 param
= ISCSI_FLASHNODE_MAX_SEGMENT_SIZE
;
816 } else if (attr
== &dev_attr_fnode_local_port
.attr
) {
817 param
= ISCSI_FLASHNODE_LOCAL_PORT
;
818 } else if (attr
== &dev_attr_fnode_ipv4_tos
.attr
) {
819 param
= ISCSI_FLASHNODE_IPV4_TOS
;
820 } else if (attr
== &dev_attr_fnode_ipv6_traffic_class
.attr
) {
821 param
= ISCSI_FLASHNODE_IPV6_TC
;
822 } else if (attr
== &dev_attr_fnode_ipv6_flow_label
.attr
) {
823 param
= ISCSI_FLASHNODE_IPV6_FLOW_LABEL
;
824 } else if (attr
== &dev_attr_fnode_link_local_ipv6
.attr
) {
825 param
= ISCSI_FLASHNODE_LINK_LOCAL_IPV6
;
826 } else if (attr
== &dev_attr_fnode_tcp_xmit_wsf
.attr
) {
827 param
= ISCSI_FLASHNODE_TCP_XMIT_WSF
;
828 } else if (attr
== &dev_attr_fnode_tcp_recv_wsf
.attr
) {
829 param
= ISCSI_FLASHNODE_TCP_RECV_WSF
;
830 } else if (attr
== &dev_attr_fnode_statsn
.attr
) {
831 param
= ISCSI_FLASHNODE_STATSN
;
832 } else if (attr
== &dev_attr_fnode_exp_statsn
.attr
) {
833 param
= ISCSI_FLASHNODE_EXP_STATSN
;
835 WARN_ONCE(1, "Invalid flashnode connection attr");
839 return t
->attr_is_visible(ISCSI_FLASHNODE_PARAM
, param
);
842 static struct attribute_group iscsi_flashnode_conn_attr_group
= {
843 .attrs
= iscsi_flashnode_conn_attrs
,
844 .is_visible
= iscsi_flashnode_conn_attr_is_visible
,
847 static const struct attribute_group
*iscsi_flashnode_conn_attr_groups
[] = {
848 &iscsi_flashnode_conn_attr_group
,
852 static void iscsi_flashnode_conn_release(struct device
*dev
)
854 struct iscsi_bus_flash_conn
*fnode_conn
= iscsi_dev_to_flash_conn(dev
);
856 kfree(fnode_conn
->ipaddress
);
857 kfree(fnode_conn
->redirect_ipaddr
);
858 kfree(fnode_conn
->link_local_ipv6_addr
);
862 struct device_type iscsi_flashnode_conn_dev_type
= {
863 .name
= "iscsi_flashnode_conn_dev_type",
864 .groups
= iscsi_flashnode_conn_attr_groups
,
865 .release
= iscsi_flashnode_conn_release
,
868 struct bus_type iscsi_flashnode_bus
;
870 int iscsi_flashnode_bus_match(struct device
*dev
,
871 struct device_driver
*drv
)
873 if (dev
->bus
== &iscsi_flashnode_bus
)
877 EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match
);
879 struct bus_type iscsi_flashnode_bus
= {
880 .name
= "iscsi_flashnode",
881 .match
= &iscsi_flashnode_bus_match
,
885 * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
886 * @shost: pointer to host data
887 * @index: index of flashnode to add in sysfs
888 * @transport: pointer to transport data
889 * @dd_size: total size to allocate
891 * Adds a sysfs entry for the flashnode session attributes
894 * pointer to allocated flashnode sess on sucess
897 struct iscsi_bus_flash_session
*
898 iscsi_create_flashnode_sess(struct Scsi_Host
*shost
, int index
,
899 struct iscsi_transport
*transport
,
902 struct iscsi_bus_flash_session
*fnode_sess
;
905 fnode_sess
= kzalloc(sizeof(*fnode_sess
) + dd_size
, GFP_KERNEL
);
909 fnode_sess
->transport
= transport
;
910 fnode_sess
->target_id
= index
;
911 fnode_sess
->dev
.type
= &iscsi_flashnode_sess_dev_type
;
912 fnode_sess
->dev
.bus
= &iscsi_flashnode_bus
;
913 fnode_sess
->dev
.parent
= &shost
->shost_gendev
;
914 dev_set_name(&fnode_sess
->dev
, "flashnode_sess-%u:%u",
915 shost
->host_no
, index
);
917 err
= device_register(&fnode_sess
->dev
);
919 goto free_fnode_sess
;
922 fnode_sess
->dd_data
= &fnode_sess
[1];
930 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess
);
933 * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
934 * @shost: pointer to host data
935 * @fnode_sess: pointer to the parent flashnode session entry
936 * @transport: pointer to transport data
937 * @dd_size: total size to allocate
939 * Adds a sysfs entry for the flashnode connection attributes
942 * pointer to allocated flashnode conn on success
945 struct iscsi_bus_flash_conn
*
946 iscsi_create_flashnode_conn(struct Scsi_Host
*shost
,
947 struct iscsi_bus_flash_session
*fnode_sess
,
948 struct iscsi_transport
*transport
,
951 struct iscsi_bus_flash_conn
*fnode_conn
;
954 fnode_conn
= kzalloc(sizeof(*fnode_conn
) + dd_size
, GFP_KERNEL
);
958 fnode_conn
->transport
= transport
;
959 fnode_conn
->dev
.type
= &iscsi_flashnode_conn_dev_type
;
960 fnode_conn
->dev
.bus
= &iscsi_flashnode_bus
;
961 fnode_conn
->dev
.parent
= &fnode_sess
->dev
;
962 dev_set_name(&fnode_conn
->dev
, "flashnode_conn-%u:%u:0",
963 shost
->host_no
, fnode_sess
->target_id
);
965 err
= device_register(&fnode_conn
->dev
);
967 goto free_fnode_conn
;
970 fnode_conn
->dd_data
= &fnode_conn
[1];
978 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn
);
981 * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
982 * @dev: device to verify
983 * @data: pointer to data containing value to use for verification
985 * Verifies if the passed device is flashnode conn device
991 int iscsi_is_flashnode_conn_dev(struct device
*dev
, void *data
)
993 return dev
->bus
== &iscsi_flashnode_bus
;
995 EXPORT_SYMBOL_GPL(iscsi_is_flashnode_conn_dev
);
997 static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn
*fnode_conn
)
999 device_unregister(&fnode_conn
->dev
);
1003 static int flashnode_match_index(struct device
*dev
, void *data
)
1005 struct iscsi_bus_flash_session
*fnode_sess
= NULL
;
1008 if (!iscsi_flashnode_bus_match(dev
, NULL
))
1009 goto exit_match_index
;
1011 fnode_sess
= iscsi_dev_to_flash_session(dev
);
1012 ret
= (fnode_sess
->target_id
== *((int *)data
)) ? 1 : 0;
1019 * iscsi_get_flashnode_by_index -finds flashnode session entry by index
1020 * @shost: pointer to host data
1021 * @idx: index to match
1023 * Finds the flashnode session object for the passed index
1026 * pointer to found flashnode session object on success
1029 static struct iscsi_bus_flash_session
*
1030 iscsi_get_flashnode_by_index(struct Scsi_Host
*shost
, uint32_t idx
)
1032 struct iscsi_bus_flash_session
*fnode_sess
= NULL
;
1035 dev
= device_find_child(&shost
->shost_gendev
, &idx
,
1036 flashnode_match_index
);
1038 fnode_sess
= iscsi_dev_to_flash_session(dev
);
1044 * iscsi_find_flashnode_sess - finds flashnode session entry
1045 * @shost: pointer to host data
1046 * @data: pointer to data containing value to use for comparison
1047 * @fn: function pointer that does actual comparison
1049 * Finds the flashnode session object comparing the data passed using logic
1050 * defined in passed function pointer
1053 * pointer to found flashnode session device object on success
1057 iscsi_find_flashnode_sess(struct Scsi_Host
*shost
, void *data
,
1058 int (*fn
)(struct device
*dev
, void *data
))
1060 return device_find_child(&shost
->shost_gendev
, data
, fn
);
1062 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess
);
1065 * iscsi_find_flashnode_conn - finds flashnode connection entry
1066 * @fnode_sess: pointer to parent flashnode session entry
1068 * Finds the flashnode connection object comparing the data passed using logic
1069 * defined in passed function pointer
1072 * pointer to found flashnode connection device object on success
1076 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session
*fnode_sess
)
1078 return device_find_child(&fnode_sess
->dev
, NULL
,
1079 iscsi_is_flashnode_conn_dev
);
1081 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn
);
1083 static int iscsi_iter_destroy_flashnode_conn_fn(struct device
*dev
, void *data
)
1085 if (!iscsi_is_flashnode_conn_dev(dev
, NULL
))
1088 return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev
));
1092 * iscsi_destroy_flashnode_sess - destory flashnode session entry
1093 * @fnode_sess: pointer to flashnode session entry to be destroyed
1095 * Deletes the flashnode session entry and all children flashnode connection
1096 * entries from sysfs
1098 void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session
*fnode_sess
)
1102 err
= device_for_each_child(&fnode_sess
->dev
, NULL
,
1103 iscsi_iter_destroy_flashnode_conn_fn
);
1105 pr_err("Could not delete all connections for %s. Error %d.\n",
1106 fnode_sess
->dev
.kobj
.name
, err
);
1108 device_unregister(&fnode_sess
->dev
);
1110 EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess
);
1112 static int iscsi_iter_destroy_flashnode_fn(struct device
*dev
, void *data
)
1114 if (!iscsi_flashnode_bus_match(dev
, NULL
))
1117 iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev
));
1122 * iscsi_destroy_all_flashnode - destory all flashnode session entries
1123 * @shost: pointer to host data
1125 * Destroys all the flashnode session entries and all corresponding children
1126 * flashnode connection entries from sysfs
1128 void iscsi_destroy_all_flashnode(struct Scsi_Host
*shost
)
1130 device_for_each_child(&shost
->shost_gendev
, NULL
,
1131 iscsi_iter_destroy_flashnode_fn
);
1133 EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode
);
1139 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
1140 * @job: bsg job to be processed
1142 static int iscsi_bsg_host_dispatch(struct bsg_job
*job
)
1144 struct Scsi_Host
*shost
= iscsi_job_to_shost(job
);
1145 struct iscsi_bsg_request
*req
= job
->request
;
1146 struct iscsi_bsg_reply
*reply
= job
->reply
;
1147 struct iscsi_internal
*i
= to_iscsi_internal(shost
->transportt
);
1148 int cmdlen
= sizeof(uint32_t); /* start with length of msgcode */
1151 /* check if we have the msgcode value at least */
1152 if (job
->request_len
< sizeof(uint32_t)) {
1157 /* Validate the host command */
1158 switch (req
->msgcode
) {
1159 case ISCSI_BSG_HST_VENDOR
:
1160 cmdlen
+= sizeof(struct iscsi_bsg_host_vendor
);
1161 if ((shost
->hostt
->vendor_id
== 0L) ||
1162 (req
->rqst_data
.h_vendor
.vendor_id
!=
1163 shost
->hostt
->vendor_id
)) {
1173 /* check if we really have all the request data needed */
1174 if (job
->request_len
< cmdlen
) {
1179 ret
= i
->iscsi_transport
->bsg_request(job
);
1184 /* return the errno failure code as the only status */
1185 BUG_ON(job
->reply_len
< sizeof(uint32_t));
1186 reply
->reply_payload_rcv_len
= 0;
1187 reply
->result
= ret
;
1188 job
->reply_len
= sizeof(uint32_t);
1189 bsg_job_done(job
, ret
, 0);
1194 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
1195 * @shost: shost for iscsi_host
1196 * @ihost: iscsi_cls_host adding the structures to
1199 iscsi_bsg_host_add(struct Scsi_Host
*shost
, struct iscsi_cls_host
*ihost
)
1201 struct device
*dev
= &shost
->shost_gendev
;
1202 struct iscsi_internal
*i
= to_iscsi_internal(shost
->transportt
);
1203 struct request_queue
*q
;
1207 if (!i
->iscsi_transport
->bsg_request
)
1210 snprintf(bsg_name
, sizeof(bsg_name
), "iscsi_host%d", shost
->host_no
);
1212 q
= __scsi_alloc_queue(shost
, bsg_request_fn
);
1216 ret
= bsg_setup_queue(dev
, q
, bsg_name
, iscsi_bsg_host_dispatch
, 0);
1218 shost_printk(KERN_ERR
, shost
, "bsg interface failed to "
1219 "initialize - no request queue\n");
1220 blk_cleanup_queue(q
);
1228 static int iscsi_setup_host(struct transport_container
*tc
, struct device
*dev
,
1229 struct device
*cdev
)
1231 struct Scsi_Host
*shost
= dev_to_shost(dev
);
1232 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1234 memset(ihost
, 0, sizeof(*ihost
));
1235 atomic_set(&ihost
->nr_scans
, 0);
1236 mutex_init(&ihost
->mutex
);
1238 iscsi_bsg_host_add(shost
, ihost
);
1239 /* ignore any bsg add error - we just can't do sgio */
1244 static int iscsi_remove_host(struct transport_container
*tc
,
1245 struct device
*dev
, struct device
*cdev
)
1247 struct Scsi_Host
*shost
= dev_to_shost(dev
);
1248 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1251 bsg_unregister_queue(ihost
->bsg_q
);
1252 blk_cleanup_queue(ihost
->bsg_q
);
1257 static DECLARE_TRANSPORT_CLASS(iscsi_host_class
,
1263 static DECLARE_TRANSPORT_CLASS(iscsi_session_class
,
1269 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class
,
1275 static struct sock
*nls
;
1276 static DEFINE_MUTEX(rx_queue_mutex
);
1278 static LIST_HEAD(sesslist
);
1279 static DEFINE_SPINLOCK(sesslock
);
1280 static LIST_HEAD(connlist
);
1281 static DEFINE_SPINLOCK(connlock
);
1283 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn
*conn
)
1285 struct iscsi_cls_session
*sess
= iscsi_dev_to_session(conn
->dev
.parent
);
1290 * Returns the matching session to a given sid
1292 static struct iscsi_cls_session
*iscsi_session_lookup(uint32_t sid
)
1294 unsigned long flags
;
1295 struct iscsi_cls_session
*sess
;
1297 spin_lock_irqsave(&sesslock
, flags
);
1298 list_for_each_entry(sess
, &sesslist
, sess_list
) {
1299 if (sess
->sid
== sid
) {
1300 spin_unlock_irqrestore(&sesslock
, flags
);
1304 spin_unlock_irqrestore(&sesslock
, flags
);
1309 * Returns the matching connection to a given sid / cid tuple
1311 static struct iscsi_cls_conn
*iscsi_conn_lookup(uint32_t sid
, uint32_t cid
)
1313 unsigned long flags
;
1314 struct iscsi_cls_conn
*conn
;
1316 spin_lock_irqsave(&connlock
, flags
);
1317 list_for_each_entry(conn
, &connlist
, conn_list
) {
1318 if ((conn
->cid
== cid
) && (iscsi_conn_get_sid(conn
) == sid
)) {
1319 spin_unlock_irqrestore(&connlock
, flags
);
1323 spin_unlock_irqrestore(&connlock
, flags
);
1328 * The following functions can be used by LLDs that allocate
1329 * their own scsi_hosts or by software iscsi LLDs
1334 } iscsi_session_state_names
[] = {
1335 { ISCSI_SESSION_LOGGED_IN
, "LOGGED_IN" },
1336 { ISCSI_SESSION_FAILED
, "FAILED" },
1337 { ISCSI_SESSION_FREE
, "FREE" },
1340 static const char *iscsi_session_state_name(int state
)
1345 for (i
= 0; i
< ARRAY_SIZE(iscsi_session_state_names
); i
++) {
1346 if (iscsi_session_state_names
[i
].value
== state
) {
1347 name
= iscsi_session_state_names
[i
].name
;
1354 int iscsi_session_chkready(struct iscsi_cls_session
*session
)
1356 unsigned long flags
;
1359 spin_lock_irqsave(&session
->lock
, flags
);
1360 switch (session
->state
) {
1361 case ISCSI_SESSION_LOGGED_IN
:
1364 case ISCSI_SESSION_FAILED
:
1365 err
= DID_IMM_RETRY
<< 16;
1367 case ISCSI_SESSION_FREE
:
1368 err
= DID_TRANSPORT_FAILFAST
<< 16;
1371 err
= DID_NO_CONNECT
<< 16;
1374 spin_unlock_irqrestore(&session
->lock
, flags
);
1377 EXPORT_SYMBOL_GPL(iscsi_session_chkready
);
1379 int iscsi_is_session_online(struct iscsi_cls_session
*session
)
1381 unsigned long flags
;
1384 spin_lock_irqsave(&session
->lock
, flags
);
1385 if (session
->state
== ISCSI_SESSION_LOGGED_IN
)
1387 spin_unlock_irqrestore(&session
->lock
, flags
);
1390 EXPORT_SYMBOL_GPL(iscsi_is_session_online
);
1392 static void iscsi_session_release(struct device
*dev
)
1394 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
);
1395 struct Scsi_Host
*shost
;
1397 shost
= iscsi_session_to_shost(session
);
1398 scsi_host_put(shost
);
1399 ISCSI_DBG_TRANS_SESSION(session
, "Completing session release\n");
1403 int iscsi_is_session_dev(const struct device
*dev
)
1405 return dev
->release
== iscsi_session_release
;
1407 EXPORT_SYMBOL_GPL(iscsi_is_session_dev
);
1409 static int iscsi_iter_session_fn(struct device
*dev
, void *data
)
1411 void (* fn
) (struct iscsi_cls_session
*) = data
;
1413 if (!iscsi_is_session_dev(dev
))
1415 fn(iscsi_dev_to_session(dev
));
1419 void iscsi_host_for_each_session(struct Scsi_Host
*shost
,
1420 void (*fn
)(struct iscsi_cls_session
*))
1422 device_for_each_child(&shost
->shost_gendev
, fn
,
1423 iscsi_iter_session_fn
);
1425 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session
);
1428 * iscsi_scan_finished - helper to report when running scans are done
1430 * @time: scan run time
1432 * This function can be used by drives like qla4xxx to report to the scsi
1433 * layer when the scans it kicked off at module load time are done.
1435 int iscsi_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1437 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1439 * qla4xxx will have kicked off some session unblocks before calling
1440 * scsi_scan_host, so just wait for them to complete.
1442 return !atomic_read(&ihost
->nr_scans
);
1444 EXPORT_SYMBOL_GPL(iscsi_scan_finished
);
1446 struct iscsi_scan_data
{
1447 unsigned int channel
;
1452 static int iscsi_user_scan_session(struct device
*dev
, void *data
)
1454 struct iscsi_scan_data
*scan_data
= data
;
1455 struct iscsi_cls_session
*session
;
1456 struct Scsi_Host
*shost
;
1457 struct iscsi_cls_host
*ihost
;
1458 unsigned long flags
;
1461 if (!iscsi_is_session_dev(dev
))
1464 session
= iscsi_dev_to_session(dev
);
1466 ISCSI_DBG_TRANS_SESSION(session
, "Scanning session\n");
1468 shost
= iscsi_session_to_shost(session
);
1469 ihost
= shost
->shost_data
;
1471 mutex_lock(&ihost
->mutex
);
1472 spin_lock_irqsave(&session
->lock
, flags
);
1473 if (session
->state
!= ISCSI_SESSION_LOGGED_IN
) {
1474 spin_unlock_irqrestore(&session
->lock
, flags
);
1475 goto user_scan_exit
;
1477 id
= session
->target_id
;
1478 spin_unlock_irqrestore(&session
->lock
, flags
);
1480 if (id
!= ISCSI_MAX_TARGET
) {
1481 if ((scan_data
->channel
== SCAN_WILD_CARD
||
1482 scan_data
->channel
== 0) &&
1483 (scan_data
->id
== SCAN_WILD_CARD
||
1484 scan_data
->id
== id
))
1485 scsi_scan_target(&session
->dev
, 0, id
,
1490 mutex_unlock(&ihost
->mutex
);
1491 ISCSI_DBG_TRANS_SESSION(session
, "Completed session scan\n");
1495 static int iscsi_user_scan(struct Scsi_Host
*shost
, uint channel
,
1498 struct iscsi_scan_data scan_data
;
1500 scan_data
.channel
= channel
;
1502 scan_data
.lun
= lun
;
1504 return device_for_each_child(&shost
->shost_gendev
, &scan_data
,
1505 iscsi_user_scan_session
);
1508 static void iscsi_scan_session(struct work_struct
*work
)
1510 struct iscsi_cls_session
*session
=
1511 container_of(work
, struct iscsi_cls_session
, scan_work
);
1512 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1513 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1514 struct iscsi_scan_data scan_data
;
1516 scan_data
.channel
= 0;
1517 scan_data
.id
= SCAN_WILD_CARD
;
1518 scan_data
.lun
= SCAN_WILD_CARD
;
1520 iscsi_user_scan_session(&session
->dev
, &scan_data
);
1521 atomic_dec(&ihost
->nr_scans
);
1525 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1526 * @cmd: scsi cmd passed to scsi eh handler
1528 * If the session is down this function will wait for the recovery
1529 * timer to fire or for the session to be logged back in. If the
1530 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1531 * should pass this error value to the scsi eh.
1533 int iscsi_block_scsi_eh(struct scsi_cmnd
*cmd
)
1535 struct iscsi_cls_session
*session
=
1536 starget_to_session(scsi_target(cmd
->device
));
1537 unsigned long flags
;
1540 spin_lock_irqsave(&session
->lock
, flags
);
1541 while (session
->state
!= ISCSI_SESSION_LOGGED_IN
) {
1542 if (session
->state
== ISCSI_SESSION_FREE
) {
1546 spin_unlock_irqrestore(&session
->lock
, flags
);
1548 spin_lock_irqsave(&session
->lock
, flags
);
1550 spin_unlock_irqrestore(&session
->lock
, flags
);
1553 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh
);
1555 static void session_recovery_timedout(struct work_struct
*work
)
1557 struct iscsi_cls_session
*session
=
1558 container_of(work
, struct iscsi_cls_session
,
1559 recovery_work
.work
);
1560 unsigned long flags
;
1562 iscsi_cls_session_printk(KERN_INFO
, session
,
1563 "session recovery timed out after %d secs\n",
1564 session
->recovery_tmo
);
1566 spin_lock_irqsave(&session
->lock
, flags
);
1567 switch (session
->state
) {
1568 case ISCSI_SESSION_FAILED
:
1569 session
->state
= ISCSI_SESSION_FREE
;
1571 case ISCSI_SESSION_LOGGED_IN
:
1572 case ISCSI_SESSION_FREE
:
1573 /* we raced with the unblock's flush */
1574 spin_unlock_irqrestore(&session
->lock
, flags
);
1577 spin_unlock_irqrestore(&session
->lock
, flags
);
1579 if (session
->transport
->session_recovery_timedout
)
1580 session
->transport
->session_recovery_timedout(session
);
1582 ISCSI_DBG_TRANS_SESSION(session
, "Unblocking SCSI target\n");
1583 scsi_target_unblock(&session
->dev
, SDEV_TRANSPORT_OFFLINE
);
1584 ISCSI_DBG_TRANS_SESSION(session
, "Completed unblocking SCSI target\n");
1587 static void __iscsi_unblock_session(struct work_struct
*work
)
1589 struct iscsi_cls_session
*session
=
1590 container_of(work
, struct iscsi_cls_session
,
1592 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1593 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1594 unsigned long flags
;
1596 ISCSI_DBG_TRANS_SESSION(session
, "Unblocking session\n");
1598 * The recovery and unblock work get run from the same workqueue,
1599 * so try to cancel it if it was going to run after this unblock.
1601 cancel_delayed_work(&session
->recovery_work
);
1602 spin_lock_irqsave(&session
->lock
, flags
);
1603 session
->state
= ISCSI_SESSION_LOGGED_IN
;
1604 spin_unlock_irqrestore(&session
->lock
, flags
);
1606 scsi_target_unblock(&session
->dev
, SDEV_RUNNING
);
1608 * Only do kernel scanning if the driver is properly hooked into
1609 * the async scanning code (drivers like iscsi_tcp do login and
1610 * scanning from userspace).
1612 if (shost
->hostt
->scan_finished
) {
1613 if (scsi_queue_work(shost
, &session
->scan_work
))
1614 atomic_inc(&ihost
->nr_scans
);
1616 ISCSI_DBG_TRANS_SESSION(session
, "Completed unblocking session\n");
1620 * iscsi_unblock_session - set a session as logged in and start IO.
1621 * @session: iscsi session
1623 * Mark a session as ready to accept IO.
1625 void iscsi_unblock_session(struct iscsi_cls_session
*session
)
1627 queue_work(iscsi_eh_timer_workq
, &session
->unblock_work
);
1629 * make sure all the events have completed before tell the driver
1632 flush_workqueue(iscsi_eh_timer_workq
);
1634 EXPORT_SYMBOL_GPL(iscsi_unblock_session
);
1636 static void __iscsi_block_session(struct work_struct
*work
)
1638 struct iscsi_cls_session
*session
=
1639 container_of(work
, struct iscsi_cls_session
,
1641 unsigned long flags
;
1643 ISCSI_DBG_TRANS_SESSION(session
, "Blocking session\n");
1644 spin_lock_irqsave(&session
->lock
, flags
);
1645 session
->state
= ISCSI_SESSION_FAILED
;
1646 spin_unlock_irqrestore(&session
->lock
, flags
);
1647 scsi_target_block(&session
->dev
);
1648 ISCSI_DBG_TRANS_SESSION(session
, "Completed SCSI target blocking\n");
1649 if (session
->recovery_tmo
>= 0)
1650 queue_delayed_work(iscsi_eh_timer_workq
,
1651 &session
->recovery_work
,
1652 session
->recovery_tmo
* HZ
);
1655 void iscsi_block_session(struct iscsi_cls_session
*session
)
1657 queue_work(iscsi_eh_timer_workq
, &session
->block_work
);
1659 EXPORT_SYMBOL_GPL(iscsi_block_session
);
1661 static void __iscsi_unbind_session(struct work_struct
*work
)
1663 struct iscsi_cls_session
*session
=
1664 container_of(work
, struct iscsi_cls_session
,
1666 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1667 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1668 unsigned long flags
;
1669 unsigned int target_id
;
1671 ISCSI_DBG_TRANS_SESSION(session
, "Unbinding session\n");
1673 /* Prevent new scans and make sure scanning is not in progress */
1674 mutex_lock(&ihost
->mutex
);
1675 spin_lock_irqsave(&session
->lock
, flags
);
1676 if (session
->target_id
== ISCSI_MAX_TARGET
) {
1677 spin_unlock_irqrestore(&session
->lock
, flags
);
1678 mutex_unlock(&ihost
->mutex
);
1682 target_id
= session
->target_id
;
1683 session
->target_id
= ISCSI_MAX_TARGET
;
1684 spin_unlock_irqrestore(&session
->lock
, flags
);
1685 mutex_unlock(&ihost
->mutex
);
1687 if (session
->ida_used
)
1688 ida_simple_remove(&iscsi_sess_ida
, target_id
);
1690 scsi_remove_target(&session
->dev
);
1691 iscsi_session_event(session
, ISCSI_KEVENT_UNBIND_SESSION
);
1692 ISCSI_DBG_TRANS_SESSION(session
, "Completed target removal\n");
1695 struct iscsi_cls_session
*
1696 iscsi_alloc_session(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
1699 struct iscsi_cls_session
*session
;
1701 session
= kzalloc(sizeof(*session
) + dd_size
,
1706 session
->transport
= transport
;
1707 session
->creator
= -1;
1708 session
->recovery_tmo
= 120;
1709 session
->state
= ISCSI_SESSION_FREE
;
1710 INIT_DELAYED_WORK(&session
->recovery_work
, session_recovery_timedout
);
1711 INIT_LIST_HEAD(&session
->sess_list
);
1712 INIT_WORK(&session
->unblock_work
, __iscsi_unblock_session
);
1713 INIT_WORK(&session
->block_work
, __iscsi_block_session
);
1714 INIT_WORK(&session
->unbind_work
, __iscsi_unbind_session
);
1715 INIT_WORK(&session
->scan_work
, iscsi_scan_session
);
1716 spin_lock_init(&session
->lock
);
1718 /* this is released in the dev's release function */
1719 scsi_host_get(shost
);
1720 session
->dev
.parent
= &shost
->shost_gendev
;
1721 session
->dev
.release
= iscsi_session_release
;
1722 device_initialize(&session
->dev
);
1724 session
->dd_data
= &session
[1];
1726 ISCSI_DBG_TRANS_SESSION(session
, "Completed session allocation\n");
1729 EXPORT_SYMBOL_GPL(iscsi_alloc_session
);
1731 int iscsi_add_session(struct iscsi_cls_session
*session
, unsigned int target_id
)
1733 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1734 struct iscsi_cls_host
*ihost
;
1735 unsigned long flags
;
1739 ihost
= shost
->shost_data
;
1740 session
->sid
= atomic_add_return(1, &iscsi_session_nr
);
1742 if (target_id
== ISCSI_MAX_TARGET
) {
1743 id
= ida_simple_get(&iscsi_sess_ida
, 0, 0, GFP_KERNEL
);
1746 iscsi_cls_session_printk(KERN_ERR
, session
,
1747 "Failure in Target ID Allocation\n");
1750 session
->target_id
= (unsigned int)id
;
1751 session
->ida_used
= true;
1753 session
->target_id
= target_id
;
1755 dev_set_name(&session
->dev
, "session%u", session
->sid
);
1756 err
= device_add(&session
->dev
);
1758 iscsi_cls_session_printk(KERN_ERR
, session
,
1759 "could not register session's dev\n");
1762 transport_register_device(&session
->dev
);
1764 spin_lock_irqsave(&sesslock
, flags
);
1765 list_add(&session
->sess_list
, &sesslist
);
1766 spin_unlock_irqrestore(&sesslock
, flags
);
1768 iscsi_session_event(session
, ISCSI_KEVENT_CREATE_SESSION
);
1769 ISCSI_DBG_TRANS_SESSION(session
, "Completed session adding\n");
1773 if (session
->ida_used
)
1774 ida_simple_remove(&iscsi_sess_ida
, session
->target_id
);
1778 EXPORT_SYMBOL_GPL(iscsi_add_session
);
1781 * iscsi_create_session - create iscsi class session
1783 * @transport: iscsi transport
1784 * @dd_size: private driver data size
1785 * @target_id: which target
1787 * This can be called from a LLD or iscsi_transport.
1789 struct iscsi_cls_session
*
1790 iscsi_create_session(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
1791 int dd_size
, unsigned int target_id
)
1793 struct iscsi_cls_session
*session
;
1795 session
= iscsi_alloc_session(shost
, transport
, dd_size
);
1799 if (iscsi_add_session(session
, target_id
)) {
1800 iscsi_free_session(session
);
1805 EXPORT_SYMBOL_GPL(iscsi_create_session
);
1807 static void iscsi_conn_release(struct device
*dev
)
1809 struct iscsi_cls_conn
*conn
= iscsi_dev_to_conn(dev
);
1810 struct device
*parent
= conn
->dev
.parent
;
1812 ISCSI_DBG_TRANS_CONN(conn
, "Releasing conn\n");
1817 static int iscsi_is_conn_dev(const struct device
*dev
)
1819 return dev
->release
== iscsi_conn_release
;
1822 static int iscsi_iter_destroy_conn_fn(struct device
*dev
, void *data
)
1824 if (!iscsi_is_conn_dev(dev
))
1826 return iscsi_destroy_conn(iscsi_dev_to_conn(dev
));
1829 void iscsi_remove_session(struct iscsi_cls_session
*session
)
1831 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1832 unsigned long flags
;
1835 ISCSI_DBG_TRANS_SESSION(session
, "Removing session\n");
1837 spin_lock_irqsave(&sesslock
, flags
);
1838 list_del(&session
->sess_list
);
1839 spin_unlock_irqrestore(&sesslock
, flags
);
1841 /* make sure there are no blocks/unblocks queued */
1842 flush_workqueue(iscsi_eh_timer_workq
);
1843 /* make sure the timedout callout is not running */
1844 if (!cancel_delayed_work(&session
->recovery_work
))
1845 flush_workqueue(iscsi_eh_timer_workq
);
1847 * If we are blocked let commands flow again. The lld or iscsi
1848 * layer should set up the queuecommand to fail commands.
1849 * We assume that LLD will not be calling block/unblock while
1850 * removing the session.
1852 spin_lock_irqsave(&session
->lock
, flags
);
1853 session
->state
= ISCSI_SESSION_FREE
;
1854 spin_unlock_irqrestore(&session
->lock
, flags
);
1856 scsi_target_unblock(&session
->dev
, SDEV_TRANSPORT_OFFLINE
);
1857 /* flush running scans then delete devices */
1858 scsi_flush_work(shost
);
1859 __iscsi_unbind_session(&session
->unbind_work
);
1861 /* hw iscsi may not have removed all connections from session */
1862 err
= device_for_each_child(&session
->dev
, NULL
,
1863 iscsi_iter_destroy_conn_fn
);
1865 iscsi_cls_session_printk(KERN_ERR
, session
,
1866 "Could not delete all connections "
1867 "for session. Error %d.\n", err
);
1869 transport_unregister_device(&session
->dev
);
1871 ISCSI_DBG_TRANS_SESSION(session
, "Completing session removal\n");
1872 device_del(&session
->dev
);
1874 EXPORT_SYMBOL_GPL(iscsi_remove_session
);
1876 void iscsi_free_session(struct iscsi_cls_session
*session
)
1878 ISCSI_DBG_TRANS_SESSION(session
, "Freeing session\n");
1879 iscsi_session_event(session
, ISCSI_KEVENT_DESTROY_SESSION
);
1880 put_device(&session
->dev
);
1882 EXPORT_SYMBOL_GPL(iscsi_free_session
);
1885 * iscsi_destroy_session - destroy iscsi session
1886 * @session: iscsi_session
1888 * Can be called by a LLD or iscsi_transport. There must not be
1889 * any running connections.
1891 int iscsi_destroy_session(struct iscsi_cls_session
*session
)
1893 iscsi_remove_session(session
);
1894 ISCSI_DBG_TRANS_SESSION(session
, "Completing session destruction\n");
1895 iscsi_free_session(session
);
1898 EXPORT_SYMBOL_GPL(iscsi_destroy_session
);
1901 * iscsi_create_conn - create iscsi class connection
1902 * @session: iscsi cls session
1903 * @dd_size: private driver data size
1904 * @cid: connection id
1906 * This can be called from a LLD or iscsi_transport. The connection
1907 * is child of the session so cid must be unique for all connections
1910 * Since we do not support MCS, cid will normally be zero. In some cases
1911 * for software iscsi we could be trying to preallocate a connection struct
1912 * in which case there could be two connection structs and cid would be
1915 struct iscsi_cls_conn
*
1916 iscsi_create_conn(struct iscsi_cls_session
*session
, int dd_size
, uint32_t cid
)
1918 struct iscsi_transport
*transport
= session
->transport
;
1919 struct iscsi_cls_conn
*conn
;
1920 unsigned long flags
;
1923 conn
= kzalloc(sizeof(*conn
) + dd_size
, GFP_KERNEL
);
1927 conn
->dd_data
= &conn
[1];
1929 mutex_init(&conn
->ep_mutex
);
1930 INIT_LIST_HEAD(&conn
->conn_list
);
1931 conn
->transport
= transport
;
1934 /* this is released in the dev's release function */
1935 if (!get_device(&session
->dev
))
1938 dev_set_name(&conn
->dev
, "connection%d:%u", session
->sid
, cid
);
1939 conn
->dev
.parent
= &session
->dev
;
1940 conn
->dev
.release
= iscsi_conn_release
;
1941 err
= device_register(&conn
->dev
);
1943 iscsi_cls_session_printk(KERN_ERR
, session
, "could not "
1944 "register connection's dev\n");
1945 goto release_parent_ref
;
1947 transport_register_device(&conn
->dev
);
1949 spin_lock_irqsave(&connlock
, flags
);
1950 list_add(&conn
->conn_list
, &connlist
);
1951 spin_unlock_irqrestore(&connlock
, flags
);
1953 ISCSI_DBG_TRANS_CONN(conn
, "Completed conn creation\n");
1957 put_device(&session
->dev
);
1963 EXPORT_SYMBOL_GPL(iscsi_create_conn
);
1966 * iscsi_destroy_conn - destroy iscsi class connection
1967 * @conn: iscsi cls session
1969 * This can be called from a LLD or iscsi_transport.
1971 int iscsi_destroy_conn(struct iscsi_cls_conn
*conn
)
1973 unsigned long flags
;
1975 spin_lock_irqsave(&connlock
, flags
);
1976 list_del(&conn
->conn_list
);
1977 spin_unlock_irqrestore(&connlock
, flags
);
1979 transport_unregister_device(&conn
->dev
);
1980 ISCSI_DBG_TRANS_CONN(conn
, "Completing conn destruction\n");
1981 device_unregister(&conn
->dev
);
1984 EXPORT_SYMBOL_GPL(iscsi_destroy_conn
);
1987 * iscsi interface functions
1989 static struct iscsi_internal
*
1990 iscsi_if_transport_lookup(struct iscsi_transport
*tt
)
1992 struct iscsi_internal
*priv
;
1993 unsigned long flags
;
1995 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
1996 list_for_each_entry(priv
, &iscsi_transports
, list
) {
1997 if (tt
== priv
->iscsi_transport
) {
1998 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
2002 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
2007 iscsi_multicast_skb(struct sk_buff
*skb
, uint32_t group
, gfp_t gfp
)
2009 return nlmsg_multicast(nls
, skb
, 0, group
, gfp
);
2012 int iscsi_recv_pdu(struct iscsi_cls_conn
*conn
, struct iscsi_hdr
*hdr
,
2013 char *data
, uint32_t data_size
)
2015 struct nlmsghdr
*nlh
;
2016 struct sk_buff
*skb
;
2017 struct iscsi_uevent
*ev
;
2019 struct iscsi_internal
*priv
;
2020 int len
= nlmsg_total_size(sizeof(*ev
) + sizeof(struct iscsi_hdr
) +
2023 priv
= iscsi_if_transport_lookup(conn
->transport
);
2027 skb
= alloc_skb(len
, GFP_ATOMIC
);
2029 iscsi_conn_error_event(conn
, ISCSI_ERR_CONN_FAILED
);
2030 iscsi_cls_conn_printk(KERN_ERR
, conn
, "can not deliver "
2031 "control PDU: OOM\n");
2035 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2036 ev
= nlmsg_data(nlh
);
2037 memset(ev
, 0, sizeof(*ev
));
2038 ev
->transport_handle
= iscsi_handle(conn
->transport
);
2039 ev
->type
= ISCSI_KEVENT_RECV_PDU
;
2040 ev
->r
.recv_req
.cid
= conn
->cid
;
2041 ev
->r
.recv_req
.sid
= iscsi_conn_get_sid(conn
);
2042 pdu
= (char*)ev
+ sizeof(*ev
);
2043 memcpy(pdu
, hdr
, sizeof(struct iscsi_hdr
));
2044 memcpy(pdu
+ sizeof(struct iscsi_hdr
), data
, data_size
);
2046 return iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
2048 EXPORT_SYMBOL_GPL(iscsi_recv_pdu
);
2050 int iscsi_offload_mesg(struct Scsi_Host
*shost
,
2051 struct iscsi_transport
*transport
, uint32_t type
,
2052 char *data
, uint16_t data_size
)
2054 struct nlmsghdr
*nlh
;
2055 struct sk_buff
*skb
;
2056 struct iscsi_uevent
*ev
;
2057 int len
= nlmsg_total_size(sizeof(*ev
) + data_size
);
2059 skb
= alloc_skb(len
, GFP_ATOMIC
);
2061 printk(KERN_ERR
"can not deliver iscsi offload message:OOM\n");
2065 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2066 ev
= nlmsg_data(nlh
);
2067 memset(ev
, 0, sizeof(*ev
));
2069 ev
->transport_handle
= iscsi_handle(transport
);
2071 case ISCSI_KEVENT_PATH_REQ
:
2072 ev
->r
.req_path
.host_no
= shost
->host_no
;
2074 case ISCSI_KEVENT_IF_DOWN
:
2075 ev
->r
.notify_if_down
.host_no
= shost
->host_no
;
2079 memcpy((char *)ev
+ sizeof(*ev
), data
, data_size
);
2081 return iscsi_multicast_skb(skb
, ISCSI_NL_GRP_UIP
, GFP_ATOMIC
);
2083 EXPORT_SYMBOL_GPL(iscsi_offload_mesg
);
2085 void iscsi_conn_error_event(struct iscsi_cls_conn
*conn
, enum iscsi_err error
)
2087 struct nlmsghdr
*nlh
;
2088 struct sk_buff
*skb
;
2089 struct iscsi_uevent
*ev
;
2090 struct iscsi_internal
*priv
;
2091 int len
= nlmsg_total_size(sizeof(*ev
));
2093 priv
= iscsi_if_transport_lookup(conn
->transport
);
2097 skb
= alloc_skb(len
, GFP_ATOMIC
);
2099 iscsi_cls_conn_printk(KERN_ERR
, conn
, "gracefully ignored "
2100 "conn error (%d)\n", error
);
2104 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2105 ev
= nlmsg_data(nlh
);
2106 ev
->transport_handle
= iscsi_handle(conn
->transport
);
2107 ev
->type
= ISCSI_KEVENT_CONN_ERROR
;
2108 ev
->r
.connerror
.error
= error
;
2109 ev
->r
.connerror
.cid
= conn
->cid
;
2110 ev
->r
.connerror
.sid
= iscsi_conn_get_sid(conn
);
2112 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
2114 iscsi_cls_conn_printk(KERN_INFO
, conn
, "detected conn error (%d)\n",
2117 EXPORT_SYMBOL_GPL(iscsi_conn_error_event
);
2119 void iscsi_conn_login_event(struct iscsi_cls_conn
*conn
,
2120 enum iscsi_conn_state state
)
2122 struct nlmsghdr
*nlh
;
2123 struct sk_buff
*skb
;
2124 struct iscsi_uevent
*ev
;
2125 struct iscsi_internal
*priv
;
2126 int len
= nlmsg_total_size(sizeof(*ev
));
2128 priv
= iscsi_if_transport_lookup(conn
->transport
);
2132 skb
= alloc_skb(len
, GFP_ATOMIC
);
2134 iscsi_cls_conn_printk(KERN_ERR
, conn
, "gracefully ignored "
2135 "conn login (%d)\n", state
);
2139 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2140 ev
= nlmsg_data(nlh
);
2141 ev
->transport_handle
= iscsi_handle(conn
->transport
);
2142 ev
->type
= ISCSI_KEVENT_CONN_LOGIN_STATE
;
2143 ev
->r
.conn_login
.state
= state
;
2144 ev
->r
.conn_login
.cid
= conn
->cid
;
2145 ev
->r
.conn_login
.sid
= iscsi_conn_get_sid(conn
);
2146 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
2148 iscsi_cls_conn_printk(KERN_INFO
, conn
, "detected conn login (%d)\n",
2151 EXPORT_SYMBOL_GPL(iscsi_conn_login_event
);
2153 void iscsi_post_host_event(uint32_t host_no
, struct iscsi_transport
*transport
,
2154 enum iscsi_host_event_code code
, uint32_t data_size
,
2157 struct nlmsghdr
*nlh
;
2158 struct sk_buff
*skb
;
2159 struct iscsi_uevent
*ev
;
2160 int len
= nlmsg_total_size(sizeof(*ev
) + data_size
);
2162 skb
= alloc_skb(len
, GFP_NOIO
);
2164 printk(KERN_ERR
"gracefully ignored host event (%d):%d OOM\n",
2169 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2170 ev
= nlmsg_data(nlh
);
2171 ev
->transport_handle
= iscsi_handle(transport
);
2172 ev
->type
= ISCSI_KEVENT_HOST_EVENT
;
2173 ev
->r
.host_event
.host_no
= host_no
;
2174 ev
->r
.host_event
.code
= code
;
2175 ev
->r
.host_event
.data_size
= data_size
;
2178 memcpy((char *)ev
+ sizeof(*ev
), data
, data_size
);
2180 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_NOIO
);
2182 EXPORT_SYMBOL_GPL(iscsi_post_host_event
);
2184 void iscsi_ping_comp_event(uint32_t host_no
, struct iscsi_transport
*transport
,
2185 uint32_t status
, uint32_t pid
, uint32_t data_size
,
2188 struct nlmsghdr
*nlh
;
2189 struct sk_buff
*skb
;
2190 struct iscsi_uevent
*ev
;
2191 int len
= nlmsg_total_size(sizeof(*ev
) + data_size
);
2193 skb
= alloc_skb(len
, GFP_NOIO
);
2195 printk(KERN_ERR
"gracefully ignored ping comp: OOM\n");
2199 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2200 ev
= nlmsg_data(nlh
);
2201 ev
->transport_handle
= iscsi_handle(transport
);
2202 ev
->type
= ISCSI_KEVENT_PING_COMP
;
2203 ev
->r
.ping_comp
.host_no
= host_no
;
2204 ev
->r
.ping_comp
.status
= status
;
2205 ev
->r
.ping_comp
.pid
= pid
;
2206 ev
->r
.ping_comp
.data_size
= data_size
;
2207 memcpy((char *)ev
+ sizeof(*ev
), data
, data_size
);
2209 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_NOIO
);
2211 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event
);
2214 iscsi_if_send_reply(uint32_t group
, int seq
, int type
, int done
, int multi
,
2215 void *payload
, int size
)
2217 struct sk_buff
*skb
;
2218 struct nlmsghdr
*nlh
;
2219 int len
= nlmsg_total_size(size
);
2220 int flags
= multi
? NLM_F_MULTI
: 0;
2221 int t
= done
? NLMSG_DONE
: type
;
2223 skb
= alloc_skb(len
, GFP_ATOMIC
);
2225 printk(KERN_ERR
"Could not allocate skb to send reply.\n");
2229 nlh
= __nlmsg_put(skb
, 0, 0, t
, (len
- sizeof(*nlh
)), 0);
2230 nlh
->nlmsg_flags
= flags
;
2231 memcpy(nlmsg_data(nlh
), payload
, size
);
2232 return iscsi_multicast_skb(skb
, group
, GFP_ATOMIC
);
2236 iscsi_if_get_stats(struct iscsi_transport
*transport
, struct nlmsghdr
*nlh
)
2238 struct iscsi_uevent
*ev
= nlmsg_data(nlh
);
2239 struct iscsi_stats
*stats
;
2240 struct sk_buff
*skbstat
;
2241 struct iscsi_cls_conn
*conn
;
2242 struct nlmsghdr
*nlhstat
;
2243 struct iscsi_uevent
*evstat
;
2244 struct iscsi_internal
*priv
;
2245 int len
= nlmsg_total_size(sizeof(*ev
) +
2246 sizeof(struct iscsi_stats
) +
2247 sizeof(struct iscsi_stats_custom
) *
2248 ISCSI_STATS_CUSTOM_MAX
);
2251 priv
= iscsi_if_transport_lookup(transport
);
2255 conn
= iscsi_conn_lookup(ev
->u
.get_stats
.sid
, ev
->u
.get_stats
.cid
);
2262 skbstat
= alloc_skb(len
, GFP_ATOMIC
);
2264 iscsi_cls_conn_printk(KERN_ERR
, conn
, "can not "
2265 "deliver stats: OOM\n");
2269 nlhstat
= __nlmsg_put(skbstat
, 0, 0, 0,
2270 (len
- sizeof(*nlhstat
)), 0);
2271 evstat
= nlmsg_data(nlhstat
);
2272 memset(evstat
, 0, sizeof(*evstat
));
2273 evstat
->transport_handle
= iscsi_handle(conn
->transport
);
2274 evstat
->type
= nlh
->nlmsg_type
;
2275 evstat
->u
.get_stats
.cid
=
2276 ev
->u
.get_stats
.cid
;
2277 evstat
->u
.get_stats
.sid
=
2278 ev
->u
.get_stats
.sid
;
2279 stats
= (struct iscsi_stats
*)
2280 ((char*)evstat
+ sizeof(*evstat
));
2281 memset(stats
, 0, sizeof(*stats
));
2283 transport
->get_stats(conn
, stats
);
2284 actual_size
= nlmsg_total_size(sizeof(struct iscsi_uevent
) +
2285 sizeof(struct iscsi_stats
) +
2286 sizeof(struct iscsi_stats_custom
) *
2287 stats
->custom_length
);
2288 actual_size
-= sizeof(*nlhstat
);
2289 actual_size
= nlmsg_msg_size(actual_size
);
2290 skb_trim(skbstat
, NLMSG_ALIGN(actual_size
));
2291 nlhstat
->nlmsg_len
= actual_size
;
2293 err
= iscsi_multicast_skb(skbstat
, ISCSI_NL_GRP_ISCSID
,
2295 } while (err
< 0 && err
!= -ECONNREFUSED
);
2301 * iscsi_session_event - send session destr. completion event
2302 * @session: iscsi class session
2303 * @event: type of event
2305 int iscsi_session_event(struct iscsi_cls_session
*session
,
2306 enum iscsi_uevent_e event
)
2308 struct iscsi_internal
*priv
;
2309 struct Scsi_Host
*shost
;
2310 struct iscsi_uevent
*ev
;
2311 struct sk_buff
*skb
;
2312 struct nlmsghdr
*nlh
;
2313 int rc
, len
= nlmsg_total_size(sizeof(*ev
));
2315 priv
= iscsi_if_transport_lookup(session
->transport
);
2318 shost
= iscsi_session_to_shost(session
);
2320 skb
= alloc_skb(len
, GFP_KERNEL
);
2322 iscsi_cls_session_printk(KERN_ERR
, session
,
2323 "Cannot notify userspace of session "
2324 "event %u\n", event
);
2328 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
2329 ev
= nlmsg_data(nlh
);
2330 ev
->transport_handle
= iscsi_handle(session
->transport
);
2334 case ISCSI_KEVENT_DESTROY_SESSION
:
2335 ev
->r
.d_session
.host_no
= shost
->host_no
;
2336 ev
->r
.d_session
.sid
= session
->sid
;
2338 case ISCSI_KEVENT_CREATE_SESSION
:
2339 ev
->r
.c_session_ret
.host_no
= shost
->host_no
;
2340 ev
->r
.c_session_ret
.sid
= session
->sid
;
2342 case ISCSI_KEVENT_UNBIND_SESSION
:
2343 ev
->r
.unbind_session
.host_no
= shost
->host_no
;
2344 ev
->r
.unbind_session
.sid
= session
->sid
;
2347 iscsi_cls_session_printk(KERN_ERR
, session
, "Invalid event "
2354 * this will occur if the daemon is not up, so we just warn
2355 * the user and when the daemon is restarted it will handle it
2357 rc
= iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_KERNEL
);
2359 iscsi_cls_session_printk(KERN_ERR
, session
,
2360 "Cannot notify userspace of session "
2361 "event %u. Check iscsi daemon\n",
2364 ISCSI_DBG_TRANS_SESSION(session
, "Completed handling event %d rc %d\n",
2368 EXPORT_SYMBOL_GPL(iscsi_session_event
);
2371 iscsi_if_create_session(struct iscsi_internal
*priv
, struct iscsi_endpoint
*ep
,
2372 struct iscsi_uevent
*ev
, pid_t pid
,
2373 uint32_t initial_cmdsn
, uint16_t cmds_max
,
2374 uint16_t queue_depth
)
2376 struct iscsi_transport
*transport
= priv
->iscsi_transport
;
2377 struct iscsi_cls_session
*session
;
2378 struct Scsi_Host
*shost
;
2380 session
= transport
->create_session(ep
, cmds_max
, queue_depth
,
2385 session
->creator
= pid
;
2386 shost
= iscsi_session_to_shost(session
);
2387 ev
->r
.c_session_ret
.host_no
= shost
->host_no
;
2388 ev
->r
.c_session_ret
.sid
= session
->sid
;
2389 ISCSI_DBG_TRANS_SESSION(session
,
2390 "Completed creating transport session\n");
2395 iscsi_if_create_conn(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
2397 struct iscsi_cls_conn
*conn
;
2398 struct iscsi_cls_session
*session
;
2400 session
= iscsi_session_lookup(ev
->u
.c_conn
.sid
);
2402 printk(KERN_ERR
"iscsi: invalid session %d.\n",
2407 conn
= transport
->create_conn(session
, ev
->u
.c_conn
.cid
);
2409 iscsi_cls_session_printk(KERN_ERR
, session
,
2410 "couldn't create a new connection.");
2414 ev
->r
.c_conn_ret
.sid
= session
->sid
;
2415 ev
->r
.c_conn_ret
.cid
= conn
->cid
;
2417 ISCSI_DBG_TRANS_CONN(conn
, "Completed creating transport conn\n");
2422 iscsi_if_destroy_conn(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
2424 struct iscsi_cls_conn
*conn
;
2426 conn
= iscsi_conn_lookup(ev
->u
.d_conn
.sid
, ev
->u
.d_conn
.cid
);
2430 ISCSI_DBG_TRANS_CONN(conn
, "Destroying transport conn\n");
2431 if (transport
->destroy_conn
)
2432 transport
->destroy_conn(conn
);
2438 iscsi_set_param(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
2440 char *data
= (char*)ev
+ sizeof(*ev
);
2441 struct iscsi_cls_conn
*conn
;
2442 struct iscsi_cls_session
*session
;
2443 int err
= 0, value
= 0;
2445 session
= iscsi_session_lookup(ev
->u
.set_param
.sid
);
2446 conn
= iscsi_conn_lookup(ev
->u
.set_param
.sid
, ev
->u
.set_param
.cid
);
2447 if (!conn
|| !session
)
2450 switch (ev
->u
.set_param
.param
) {
2451 case ISCSI_PARAM_SESS_RECOVERY_TMO
:
2452 sscanf(data
, "%d", &value
);
2453 session
->recovery_tmo
= value
;
2456 err
= transport
->set_param(conn
, ev
->u
.set_param
.param
,
2457 data
, ev
->u
.set_param
.len
);
2463 static int iscsi_if_ep_connect(struct iscsi_transport
*transport
,
2464 struct iscsi_uevent
*ev
, int msg_type
)
2466 struct iscsi_endpoint
*ep
;
2467 struct sockaddr
*dst_addr
;
2468 struct Scsi_Host
*shost
= NULL
;
2469 int non_blocking
, err
= 0;
2471 if (!transport
->ep_connect
)
2474 if (msg_type
== ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
) {
2475 shost
= scsi_host_lookup(ev
->u
.ep_connect_through_host
.host_no
);
2477 printk(KERN_ERR
"ep connect failed. Could not find "
2479 ev
->u
.ep_connect_through_host
.host_no
);
2482 non_blocking
= ev
->u
.ep_connect_through_host
.non_blocking
;
2484 non_blocking
= ev
->u
.ep_connect
.non_blocking
;
2486 dst_addr
= (struct sockaddr
*)((char*)ev
+ sizeof(*ev
));
2487 ep
= transport
->ep_connect(shost
, dst_addr
, non_blocking
);
2493 ev
->r
.ep_connect_ret
.handle
= ep
->id
;
2496 scsi_host_put(shost
);
2500 static int iscsi_if_ep_disconnect(struct iscsi_transport
*transport
,
2503 struct iscsi_cls_conn
*conn
;
2504 struct iscsi_endpoint
*ep
;
2506 if (!transport
->ep_disconnect
)
2509 ep
= iscsi_lookup_endpoint(ep_handle
);
2514 mutex_lock(&conn
->ep_mutex
);
2516 mutex_unlock(&conn
->ep_mutex
);
2519 transport
->ep_disconnect(ep
);
2524 iscsi_if_transport_ep(struct iscsi_transport
*transport
,
2525 struct iscsi_uevent
*ev
, int msg_type
)
2527 struct iscsi_endpoint
*ep
;
2531 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
:
2532 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT
:
2533 rc
= iscsi_if_ep_connect(transport
, ev
, msg_type
);
2535 case ISCSI_UEVENT_TRANSPORT_EP_POLL
:
2536 if (!transport
->ep_poll
)
2539 ep
= iscsi_lookup_endpoint(ev
->u
.ep_poll
.ep_handle
);
2543 ev
->r
.retcode
= transport
->ep_poll(ep
,
2544 ev
->u
.ep_poll
.timeout_ms
);
2546 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT
:
2547 rc
= iscsi_if_ep_disconnect(transport
,
2548 ev
->u
.ep_disconnect
.ep_handle
);
2555 iscsi_tgt_dscvr(struct iscsi_transport
*transport
,
2556 struct iscsi_uevent
*ev
)
2558 struct Scsi_Host
*shost
;
2559 struct sockaddr
*dst_addr
;
2562 if (!transport
->tgt_dscvr
)
2565 shost
= scsi_host_lookup(ev
->u
.tgt_dscvr
.host_no
);
2567 printk(KERN_ERR
"target discovery could not find host no %u\n",
2568 ev
->u
.tgt_dscvr
.host_no
);
2573 dst_addr
= (struct sockaddr
*)((char*)ev
+ sizeof(*ev
));
2574 err
= transport
->tgt_dscvr(shost
, ev
->u
.tgt_dscvr
.type
,
2575 ev
->u
.tgt_dscvr
.enable
, dst_addr
);
2576 scsi_host_put(shost
);
2581 iscsi_set_host_param(struct iscsi_transport
*transport
,
2582 struct iscsi_uevent
*ev
)
2584 char *data
= (char*)ev
+ sizeof(*ev
);
2585 struct Scsi_Host
*shost
;
2588 if (!transport
->set_host_param
)
2591 shost
= scsi_host_lookup(ev
->u
.set_host_param
.host_no
);
2593 printk(KERN_ERR
"set_host_param could not find host no %u\n",
2594 ev
->u
.set_host_param
.host_no
);
2598 err
= transport
->set_host_param(shost
, ev
->u
.set_host_param
.param
,
2599 data
, ev
->u
.set_host_param
.len
);
2600 scsi_host_put(shost
);
2605 iscsi_set_path(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
2607 struct Scsi_Host
*shost
;
2608 struct iscsi_path
*params
;
2611 if (!transport
->set_path
)
2614 shost
= scsi_host_lookup(ev
->u
.set_path
.host_no
);
2616 printk(KERN_ERR
"set path could not find host no %u\n",
2617 ev
->u
.set_path
.host_no
);
2621 params
= (struct iscsi_path
*)((char *)ev
+ sizeof(*ev
));
2622 err
= transport
->set_path(shost
, params
);
2624 scsi_host_put(shost
);
2629 iscsi_set_iface_params(struct iscsi_transport
*transport
,
2630 struct iscsi_uevent
*ev
, uint32_t len
)
2632 char *data
= (char *)ev
+ sizeof(*ev
);
2633 struct Scsi_Host
*shost
;
2636 if (!transport
->set_iface_param
)
2639 shost
= scsi_host_lookup(ev
->u
.set_iface_params
.host_no
);
2641 printk(KERN_ERR
"set_iface_params could not find host no %u\n",
2642 ev
->u
.set_iface_params
.host_no
);
2646 err
= transport
->set_iface_param(shost
, data
, len
);
2647 scsi_host_put(shost
);
2652 iscsi_send_ping(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
2654 struct Scsi_Host
*shost
;
2655 struct sockaddr
*dst_addr
;
2658 if (!transport
->send_ping
)
2661 shost
= scsi_host_lookup(ev
->u
.iscsi_ping
.host_no
);
2663 printk(KERN_ERR
"iscsi_ping could not find host no %u\n",
2664 ev
->u
.iscsi_ping
.host_no
);
2668 dst_addr
= (struct sockaddr
*)((char *)ev
+ sizeof(*ev
));
2669 err
= transport
->send_ping(shost
, ev
->u
.iscsi_ping
.iface_num
,
2670 ev
->u
.iscsi_ping
.iface_type
,
2671 ev
->u
.iscsi_ping
.payload_size
,
2672 ev
->u
.iscsi_ping
.pid
,
2674 scsi_host_put(shost
);
2679 iscsi_get_chap(struct iscsi_transport
*transport
, struct nlmsghdr
*nlh
)
2681 struct iscsi_uevent
*ev
= nlmsg_data(nlh
);
2682 struct Scsi_Host
*shost
= NULL
;
2683 struct iscsi_chap_rec
*chap_rec
;
2684 struct iscsi_internal
*priv
;
2685 struct sk_buff
*skbchap
;
2686 struct nlmsghdr
*nlhchap
;
2687 struct iscsi_uevent
*evchap
;
2688 uint32_t chap_buf_size
;
2692 if (!transport
->get_chap
)
2695 priv
= iscsi_if_transport_lookup(transport
);
2699 chap_buf_size
= (ev
->u
.get_chap
.num_entries
* sizeof(*chap_rec
));
2700 len
= nlmsg_total_size(sizeof(*ev
) + chap_buf_size
);
2702 shost
= scsi_host_lookup(ev
->u
.get_chap
.host_no
);
2704 printk(KERN_ERR
"%s: failed. Cound not find host no %u\n",
2705 __func__
, ev
->u
.get_chap
.host_no
);
2712 skbchap
= alloc_skb(len
, GFP_KERNEL
);
2714 printk(KERN_ERR
"can not deliver chap: OOM\n");
2719 nlhchap
= __nlmsg_put(skbchap
, 0, 0, 0,
2720 (len
- sizeof(*nlhchap
)), 0);
2721 evchap
= nlmsg_data(nlhchap
);
2722 memset(evchap
, 0, sizeof(*evchap
));
2723 evchap
->transport_handle
= iscsi_handle(transport
);
2724 evchap
->type
= nlh
->nlmsg_type
;
2725 evchap
->u
.get_chap
.host_no
= ev
->u
.get_chap
.host_no
;
2726 evchap
->u
.get_chap
.chap_tbl_idx
= ev
->u
.get_chap
.chap_tbl_idx
;
2727 evchap
->u
.get_chap
.num_entries
= ev
->u
.get_chap
.num_entries
;
2728 buf
= (char *) ((char *)evchap
+ sizeof(*evchap
));
2729 memset(buf
, 0, chap_buf_size
);
2731 err
= transport
->get_chap(shost
, ev
->u
.get_chap
.chap_tbl_idx
,
2732 &evchap
->u
.get_chap
.num_entries
, buf
);
2734 actual_size
= nlmsg_total_size(sizeof(*ev
) + chap_buf_size
);
2735 skb_trim(skbchap
, NLMSG_ALIGN(actual_size
));
2736 nlhchap
->nlmsg_len
= actual_size
;
2738 err
= iscsi_multicast_skb(skbchap
, ISCSI_NL_GRP_ISCSID
,
2740 } while (err
< 0 && err
!= -ECONNREFUSED
);
2743 scsi_host_put(shost
);
2747 static int iscsi_delete_chap(struct iscsi_transport
*transport
,
2748 struct iscsi_uevent
*ev
)
2750 struct Scsi_Host
*shost
;
2753 if (!transport
->delete_chap
)
2756 shost
= scsi_host_lookup(ev
->u
.delete_chap
.host_no
);
2758 printk(KERN_ERR
"%s could not find host no %u\n",
2759 __func__
, ev
->u
.delete_chap
.host_no
);
2763 err
= transport
->delete_chap(shost
, ev
->u
.delete_chap
.chap_tbl_idx
);
2764 scsi_host_put(shost
);
2768 static const struct {
2769 enum iscsi_discovery_parent_type value
;
2771 } iscsi_discovery_parent_names
[] = {
2772 {ISCSI_DISC_PARENT_UNKNOWN
, "Unknown" },
2773 {ISCSI_DISC_PARENT_SENDTGT
, "Sendtarget" },
2774 {ISCSI_DISC_PARENT_ISNS
, "isns" },
2777 char *iscsi_get_discovery_parent_name(int parent_type
)
2780 char *state
= "Unknown!";
2782 for (i
= 0; i
< ARRAY_SIZE(iscsi_discovery_parent_names
); i
++) {
2783 if (iscsi_discovery_parent_names
[i
].value
& parent_type
) {
2784 state
= iscsi_discovery_parent_names
[i
].name
;
2790 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name
);
2792 static int iscsi_set_flashnode_param(struct iscsi_transport
*transport
,
2793 struct iscsi_uevent
*ev
, uint32_t len
)
2795 char *data
= (char *)ev
+ sizeof(*ev
);
2796 struct Scsi_Host
*shost
;
2797 struct iscsi_bus_flash_session
*fnode_sess
;
2798 struct iscsi_bus_flash_conn
*fnode_conn
;
2803 if (!transport
->set_flashnode_param
) {
2805 goto exit_set_fnode
;
2808 shost
= scsi_host_lookup(ev
->u
.set_flashnode
.host_no
);
2810 pr_err("%s could not find host no %u\n",
2811 __func__
, ev
->u
.set_flashnode
.host_no
);
2816 idx
= ev
->u
.set_flashnode
.flashnode_idx
;
2817 fnode_sess
= iscsi_get_flashnode_by_index(shost
, idx
);
2819 pr_err("%s could not find flashnode %u for host no %u\n",
2820 __func__
, idx
, ev
->u
.set_flashnode
.host_no
);
2825 dev
= iscsi_find_flashnode_conn(fnode_sess
);
2831 fnode_conn
= iscsi_dev_to_flash_conn(dev
);
2832 err
= transport
->set_flashnode_param(fnode_sess
, fnode_conn
, data
, len
);
2836 put_device(&fnode_sess
->dev
);
2839 scsi_host_put(shost
);
2845 static int iscsi_new_flashnode(struct iscsi_transport
*transport
,
2846 struct iscsi_uevent
*ev
, uint32_t len
)
2848 char *data
= (char *)ev
+ sizeof(*ev
);
2849 struct Scsi_Host
*shost
;
2853 if (!transport
->new_flashnode
) {
2855 goto exit_new_fnode
;
2858 shost
= scsi_host_lookup(ev
->u
.new_flashnode
.host_no
);
2860 pr_err("%s could not find host no %u\n",
2861 __func__
, ev
->u
.new_flashnode
.host_no
);
2866 index
= transport
->new_flashnode(shost
, data
, len
);
2869 ev
->r
.new_flashnode_ret
.flashnode_idx
= index
;
2874 scsi_host_put(shost
);
2880 static int iscsi_del_flashnode(struct iscsi_transport
*transport
,
2881 struct iscsi_uevent
*ev
)
2883 struct Scsi_Host
*shost
;
2884 struct iscsi_bus_flash_session
*fnode_sess
;
2888 if (!transport
->del_flashnode
) {
2890 goto exit_del_fnode
;
2893 shost
= scsi_host_lookup(ev
->u
.del_flashnode
.host_no
);
2895 pr_err("%s could not find host no %u\n",
2896 __func__
, ev
->u
.del_flashnode
.host_no
);
2901 idx
= ev
->u
.del_flashnode
.flashnode_idx
;
2902 fnode_sess
= iscsi_get_flashnode_by_index(shost
, idx
);
2904 pr_err("%s could not find flashnode %u for host no %u\n",
2905 __func__
, idx
, ev
->u
.del_flashnode
.host_no
);
2910 err
= transport
->del_flashnode(fnode_sess
);
2911 put_device(&fnode_sess
->dev
);
2914 scsi_host_put(shost
);
2920 static int iscsi_login_flashnode(struct iscsi_transport
*transport
,
2921 struct iscsi_uevent
*ev
)
2923 struct Scsi_Host
*shost
;
2924 struct iscsi_bus_flash_session
*fnode_sess
;
2925 struct iscsi_bus_flash_conn
*fnode_conn
;
2930 if (!transport
->login_flashnode
) {
2932 goto exit_login_fnode
;
2935 shost
= scsi_host_lookup(ev
->u
.login_flashnode
.host_no
);
2937 pr_err("%s could not find host no %u\n",
2938 __func__
, ev
->u
.login_flashnode
.host_no
);
2943 idx
= ev
->u
.login_flashnode
.flashnode_idx
;
2944 fnode_sess
= iscsi_get_flashnode_by_index(shost
, idx
);
2946 pr_err("%s could not find flashnode %u for host no %u\n",
2947 __func__
, idx
, ev
->u
.login_flashnode
.host_no
);
2952 dev
= iscsi_find_flashnode_conn(fnode_sess
);
2958 fnode_conn
= iscsi_dev_to_flash_conn(dev
);
2959 err
= transport
->login_flashnode(fnode_sess
, fnode_conn
);
2963 put_device(&fnode_sess
->dev
);
2966 scsi_host_put(shost
);
2972 static int iscsi_logout_flashnode(struct iscsi_transport
*transport
,
2973 struct iscsi_uevent
*ev
)
2975 struct Scsi_Host
*shost
;
2976 struct iscsi_bus_flash_session
*fnode_sess
;
2977 struct iscsi_bus_flash_conn
*fnode_conn
;
2982 if (!transport
->logout_flashnode
) {
2984 goto exit_logout_fnode
;
2987 shost
= scsi_host_lookup(ev
->u
.logout_flashnode
.host_no
);
2989 pr_err("%s could not find host no %u\n",
2990 __func__
, ev
->u
.logout_flashnode
.host_no
);
2995 idx
= ev
->u
.logout_flashnode
.flashnode_idx
;
2996 fnode_sess
= iscsi_get_flashnode_by_index(shost
, idx
);
2998 pr_err("%s could not find flashnode %u for host no %u\n",
2999 __func__
, idx
, ev
->u
.logout_flashnode
.host_no
);
3004 dev
= iscsi_find_flashnode_conn(fnode_sess
);
3010 fnode_conn
= iscsi_dev_to_flash_conn(dev
);
3012 err
= transport
->logout_flashnode(fnode_sess
, fnode_conn
);
3016 put_device(&fnode_sess
->dev
);
3019 scsi_host_put(shost
);
3025 static int iscsi_logout_flashnode_sid(struct iscsi_transport
*transport
,
3026 struct iscsi_uevent
*ev
)
3028 struct Scsi_Host
*shost
;
3029 struct iscsi_cls_session
*session
;
3032 if (!transport
->logout_flashnode_sid
) {
3034 goto exit_logout_sid
;
3037 shost
= scsi_host_lookup(ev
->u
.logout_flashnode_sid
.host_no
);
3039 pr_err("%s could not find host no %u\n",
3040 __func__
, ev
->u
.logout_flashnode
.host_no
);
3045 session
= iscsi_session_lookup(ev
->u
.logout_flashnode_sid
.sid
);
3047 pr_err("%s could not find session id %u\n",
3048 __func__
, ev
->u
.logout_flashnode_sid
.sid
);
3053 err
= transport
->logout_flashnode_sid(session
);
3056 scsi_host_put(shost
);
3063 iscsi_if_recv_msg(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, uint32_t *group
)
3066 struct iscsi_uevent
*ev
= nlmsg_data(nlh
);
3067 struct iscsi_transport
*transport
= NULL
;
3068 struct iscsi_internal
*priv
;
3069 struct iscsi_cls_session
*session
;
3070 struct iscsi_cls_conn
*conn
;
3071 struct iscsi_endpoint
*ep
= NULL
;
3073 if (nlh
->nlmsg_type
== ISCSI_UEVENT_PATH_UPDATE
)
3074 *group
= ISCSI_NL_GRP_UIP
;
3076 *group
= ISCSI_NL_GRP_ISCSID
;
3078 priv
= iscsi_if_transport_lookup(iscsi_ptr(ev
->transport_handle
));
3081 transport
= priv
->iscsi_transport
;
3083 if (!try_module_get(transport
->owner
))
3086 switch (nlh
->nlmsg_type
) {
3087 case ISCSI_UEVENT_CREATE_SESSION
:
3088 err
= iscsi_if_create_session(priv
, ep
, ev
,
3089 NETLINK_CB(skb
).portid
,
3090 ev
->u
.c_session
.initial_cmdsn
,
3091 ev
->u
.c_session
.cmds_max
,
3092 ev
->u
.c_session
.queue_depth
);
3094 case ISCSI_UEVENT_CREATE_BOUND_SESSION
:
3095 ep
= iscsi_lookup_endpoint(ev
->u
.c_bound_session
.ep_handle
);
3101 err
= iscsi_if_create_session(priv
, ep
, ev
,
3102 NETLINK_CB(skb
).portid
,
3103 ev
->u
.c_bound_session
.initial_cmdsn
,
3104 ev
->u
.c_bound_session
.cmds_max
,
3105 ev
->u
.c_bound_session
.queue_depth
);
3107 case ISCSI_UEVENT_DESTROY_SESSION
:
3108 session
= iscsi_session_lookup(ev
->u
.d_session
.sid
);
3110 transport
->destroy_session(session
);
3114 case ISCSI_UEVENT_UNBIND_SESSION
:
3115 session
= iscsi_session_lookup(ev
->u
.d_session
.sid
);
3117 scsi_queue_work(iscsi_session_to_shost(session
),
3118 &session
->unbind_work
);
3122 case ISCSI_UEVENT_CREATE_CONN
:
3123 err
= iscsi_if_create_conn(transport
, ev
);
3125 case ISCSI_UEVENT_DESTROY_CONN
:
3126 err
= iscsi_if_destroy_conn(transport
, ev
);
3128 case ISCSI_UEVENT_BIND_CONN
:
3129 session
= iscsi_session_lookup(ev
->u
.b_conn
.sid
);
3130 conn
= iscsi_conn_lookup(ev
->u
.b_conn
.sid
, ev
->u
.b_conn
.cid
);
3132 if (conn
&& conn
->ep
)
3133 iscsi_if_ep_disconnect(transport
, conn
->ep
->id
);
3135 if (!session
|| !conn
) {
3140 ev
->r
.retcode
= transport
->bind_conn(session
, conn
,
3141 ev
->u
.b_conn
.transport_eph
,
3142 ev
->u
.b_conn
.is_leading
);
3143 if (ev
->r
.retcode
|| !transport
->ep_connect
)
3146 ep
= iscsi_lookup_endpoint(ev
->u
.b_conn
.transport_eph
);
3150 mutex_lock(&conn
->ep_mutex
);
3152 mutex_unlock(&conn
->ep_mutex
);
3154 iscsi_cls_conn_printk(KERN_ERR
, conn
,
3155 "Could not set ep conn "
3158 case ISCSI_UEVENT_SET_PARAM
:
3159 err
= iscsi_set_param(transport
, ev
);
3161 case ISCSI_UEVENT_START_CONN
:
3162 conn
= iscsi_conn_lookup(ev
->u
.start_conn
.sid
, ev
->u
.start_conn
.cid
);
3164 ev
->r
.retcode
= transport
->start_conn(conn
);
3168 case ISCSI_UEVENT_STOP_CONN
:
3169 conn
= iscsi_conn_lookup(ev
->u
.stop_conn
.sid
, ev
->u
.stop_conn
.cid
);
3171 transport
->stop_conn(conn
, ev
->u
.stop_conn
.flag
);
3175 case ISCSI_UEVENT_SEND_PDU
:
3176 conn
= iscsi_conn_lookup(ev
->u
.send_pdu
.sid
, ev
->u
.send_pdu
.cid
);
3178 ev
->r
.retcode
= transport
->send_pdu(conn
,
3179 (struct iscsi_hdr
*)((char*)ev
+ sizeof(*ev
)),
3180 (char*)ev
+ sizeof(*ev
) + ev
->u
.send_pdu
.hdr_size
,
3181 ev
->u
.send_pdu
.data_size
);
3185 case ISCSI_UEVENT_GET_STATS
:
3186 err
= iscsi_if_get_stats(transport
, nlh
);
3188 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT
:
3189 case ISCSI_UEVENT_TRANSPORT_EP_POLL
:
3190 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT
:
3191 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
:
3192 err
= iscsi_if_transport_ep(transport
, ev
, nlh
->nlmsg_type
);
3194 case ISCSI_UEVENT_TGT_DSCVR
:
3195 err
= iscsi_tgt_dscvr(transport
, ev
);
3197 case ISCSI_UEVENT_SET_HOST_PARAM
:
3198 err
= iscsi_set_host_param(transport
, ev
);
3200 case ISCSI_UEVENT_PATH_UPDATE
:
3201 err
= iscsi_set_path(transport
, ev
);
3203 case ISCSI_UEVENT_SET_IFACE_PARAMS
:
3204 err
= iscsi_set_iface_params(transport
, ev
,
3205 nlmsg_attrlen(nlh
, sizeof(*ev
)));
3207 case ISCSI_UEVENT_PING
:
3208 err
= iscsi_send_ping(transport
, ev
);
3210 case ISCSI_UEVENT_GET_CHAP
:
3211 err
= iscsi_get_chap(transport
, nlh
);
3213 case ISCSI_UEVENT_DELETE_CHAP
:
3214 err
= iscsi_delete_chap(transport
, ev
);
3216 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS
:
3217 err
= iscsi_set_flashnode_param(transport
, ev
,
3221 case ISCSI_UEVENT_NEW_FLASHNODE
:
3222 err
= iscsi_new_flashnode(transport
, ev
,
3223 nlmsg_attrlen(nlh
, sizeof(*ev
)));
3225 case ISCSI_UEVENT_DEL_FLASHNODE
:
3226 err
= iscsi_del_flashnode(transport
, ev
);
3228 case ISCSI_UEVENT_LOGIN_FLASHNODE
:
3229 err
= iscsi_login_flashnode(transport
, ev
);
3231 case ISCSI_UEVENT_LOGOUT_FLASHNODE
:
3232 err
= iscsi_logout_flashnode(transport
, ev
);
3234 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID
:
3235 err
= iscsi_logout_flashnode_sid(transport
, ev
);
3242 module_put(transport
->owner
);
3247 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
3248 * Malformed skbs with wrong lengths or invalid creds are not processed.
3251 iscsi_if_rx(struct sk_buff
*skb
)
3253 mutex_lock(&rx_queue_mutex
);
3254 while (skb
->len
>= NLMSG_HDRLEN
) {
3257 struct nlmsghdr
*nlh
;
3258 struct iscsi_uevent
*ev
;
3261 nlh
= nlmsg_hdr(skb
);
3262 if (nlh
->nlmsg_len
< sizeof(*nlh
) ||
3263 skb
->len
< nlh
->nlmsg_len
) {
3267 ev
= nlmsg_data(nlh
);
3268 rlen
= NLMSG_ALIGN(nlh
->nlmsg_len
);
3269 if (rlen
> skb
->len
)
3272 err
= iscsi_if_recv_msg(skb
, nlh
, &group
);
3274 ev
->type
= ISCSI_KEVENT_IF_ERROR
;
3279 * special case for GET_STATS:
3280 * on success - sending reply and stats from
3281 * inside of if_recv_msg(),
3282 * on error - fall through.
3284 if (ev
->type
== ISCSI_UEVENT_GET_STATS
&& !err
)
3286 if (ev
->type
== ISCSI_UEVENT_GET_CHAP
&& !err
)
3288 err
= iscsi_if_send_reply(group
, nlh
->nlmsg_seq
,
3289 nlh
->nlmsg_type
, 0, 0, ev
, sizeof(*ev
));
3290 } while (err
< 0 && err
!= -ECONNREFUSED
&& err
!= -ESRCH
);
3291 skb_pull(skb
, rlen
);
3293 mutex_unlock(&rx_queue_mutex
);
3296 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
3297 struct device_attribute dev_attr_##_prefix##_##_name = \
3298 __ATTR(_name,_mode,_show,_store)
3301 * iSCSI connection attrs
3303 #define iscsi_conn_attr_show(param) \
3305 show_conn_param_##param(struct device *dev, \
3306 struct device_attribute *attr, char *buf) \
3308 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
3309 struct iscsi_transport *t = conn->transport; \
3310 return t->get_conn_param(conn, param, buf); \
3313 #define iscsi_conn_attr(field, param) \
3314 iscsi_conn_attr_show(param) \
3315 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
3318 iscsi_conn_attr(max_recv_dlength
, ISCSI_PARAM_MAX_RECV_DLENGTH
);
3319 iscsi_conn_attr(max_xmit_dlength
, ISCSI_PARAM_MAX_XMIT_DLENGTH
);
3320 iscsi_conn_attr(header_digest
, ISCSI_PARAM_HDRDGST_EN
);
3321 iscsi_conn_attr(data_digest
, ISCSI_PARAM_DATADGST_EN
);
3322 iscsi_conn_attr(ifmarker
, ISCSI_PARAM_IFMARKER_EN
);
3323 iscsi_conn_attr(ofmarker
, ISCSI_PARAM_OFMARKER_EN
);
3324 iscsi_conn_attr(persistent_port
, ISCSI_PARAM_PERSISTENT_PORT
);
3325 iscsi_conn_attr(exp_statsn
, ISCSI_PARAM_EXP_STATSN
);
3326 iscsi_conn_attr(persistent_address
, ISCSI_PARAM_PERSISTENT_ADDRESS
);
3327 iscsi_conn_attr(ping_tmo
, ISCSI_PARAM_PING_TMO
);
3328 iscsi_conn_attr(recv_tmo
, ISCSI_PARAM_RECV_TMO
);
3329 iscsi_conn_attr(local_port
, ISCSI_PARAM_LOCAL_PORT
);
3330 iscsi_conn_attr(statsn
, ISCSI_PARAM_STATSN
);
3331 iscsi_conn_attr(keepalive_tmo
, ISCSI_PARAM_KEEPALIVE_TMO
);
3332 iscsi_conn_attr(max_segment_size
, ISCSI_PARAM_MAX_SEGMENT_SIZE
);
3333 iscsi_conn_attr(tcp_timestamp_stat
, ISCSI_PARAM_TCP_TIMESTAMP_STAT
);
3334 iscsi_conn_attr(tcp_wsf_disable
, ISCSI_PARAM_TCP_WSF_DISABLE
);
3335 iscsi_conn_attr(tcp_nagle_disable
, ISCSI_PARAM_TCP_NAGLE_DISABLE
);
3336 iscsi_conn_attr(tcp_timer_scale
, ISCSI_PARAM_TCP_TIMER_SCALE
);
3337 iscsi_conn_attr(tcp_timestamp_enable
, ISCSI_PARAM_TCP_TIMESTAMP_EN
);
3338 iscsi_conn_attr(fragment_disable
, ISCSI_PARAM_IP_FRAGMENT_DISABLE
);
3339 iscsi_conn_attr(ipv4_tos
, ISCSI_PARAM_IPV4_TOS
);
3340 iscsi_conn_attr(ipv6_traffic_class
, ISCSI_PARAM_IPV6_TC
);
3341 iscsi_conn_attr(ipv6_flow_label
, ISCSI_PARAM_IPV6_FLOW_LABEL
);
3342 iscsi_conn_attr(is_fw_assigned_ipv6
, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6
);
3343 iscsi_conn_attr(tcp_xmit_wsf
, ISCSI_PARAM_TCP_XMIT_WSF
);
3344 iscsi_conn_attr(tcp_recv_wsf
, ISCSI_PARAM_TCP_RECV_WSF
);
3347 #define iscsi_conn_ep_attr_show(param) \
3348 static ssize_t show_conn_ep_param_##param(struct device *dev, \
3349 struct device_attribute *attr,\
3352 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
3353 struct iscsi_transport *t = conn->transport; \
3354 struct iscsi_endpoint *ep; \
3358 * Need to make sure ep_disconnect does not free the LLD's \
3359 * interconnect resources while we are trying to read them. \
3361 mutex_lock(&conn->ep_mutex); \
3363 if (!ep && t->ep_connect) { \
3364 mutex_unlock(&conn->ep_mutex); \
3369 rc = t->get_ep_param(ep, param, buf); \
3371 rc = t->get_conn_param(conn, param, buf); \
3372 mutex_unlock(&conn->ep_mutex); \
3376 #define iscsi_conn_ep_attr(field, param) \
3377 iscsi_conn_ep_attr_show(param) \
3378 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
3379 show_conn_ep_param_##param, NULL);
3381 iscsi_conn_ep_attr(address
, ISCSI_PARAM_CONN_ADDRESS
);
3382 iscsi_conn_ep_attr(port
, ISCSI_PARAM_CONN_PORT
);
3384 static struct attribute
*iscsi_conn_attrs
[] = {
3385 &dev_attr_conn_max_recv_dlength
.attr
,
3386 &dev_attr_conn_max_xmit_dlength
.attr
,
3387 &dev_attr_conn_header_digest
.attr
,
3388 &dev_attr_conn_data_digest
.attr
,
3389 &dev_attr_conn_ifmarker
.attr
,
3390 &dev_attr_conn_ofmarker
.attr
,
3391 &dev_attr_conn_address
.attr
,
3392 &dev_attr_conn_port
.attr
,
3393 &dev_attr_conn_exp_statsn
.attr
,
3394 &dev_attr_conn_persistent_address
.attr
,
3395 &dev_attr_conn_persistent_port
.attr
,
3396 &dev_attr_conn_ping_tmo
.attr
,
3397 &dev_attr_conn_recv_tmo
.attr
,
3398 &dev_attr_conn_local_port
.attr
,
3399 &dev_attr_conn_statsn
.attr
,
3400 &dev_attr_conn_keepalive_tmo
.attr
,
3401 &dev_attr_conn_max_segment_size
.attr
,
3402 &dev_attr_conn_tcp_timestamp_stat
.attr
,
3403 &dev_attr_conn_tcp_wsf_disable
.attr
,
3404 &dev_attr_conn_tcp_nagle_disable
.attr
,
3405 &dev_attr_conn_tcp_timer_scale
.attr
,
3406 &dev_attr_conn_tcp_timestamp_enable
.attr
,
3407 &dev_attr_conn_fragment_disable
.attr
,
3408 &dev_attr_conn_ipv4_tos
.attr
,
3409 &dev_attr_conn_ipv6_traffic_class
.attr
,
3410 &dev_attr_conn_ipv6_flow_label
.attr
,
3411 &dev_attr_conn_is_fw_assigned_ipv6
.attr
,
3412 &dev_attr_conn_tcp_xmit_wsf
.attr
,
3413 &dev_attr_conn_tcp_recv_wsf
.attr
,
3417 static umode_t
iscsi_conn_attr_is_visible(struct kobject
*kobj
,
3418 struct attribute
*attr
, int i
)
3420 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3421 struct iscsi_cls_conn
*conn
= transport_class_to_conn(cdev
);
3422 struct iscsi_transport
*t
= conn
->transport
;
3425 if (attr
== &dev_attr_conn_max_recv_dlength
.attr
)
3426 param
= ISCSI_PARAM_MAX_RECV_DLENGTH
;
3427 else if (attr
== &dev_attr_conn_max_xmit_dlength
.attr
)
3428 param
= ISCSI_PARAM_MAX_XMIT_DLENGTH
;
3429 else if (attr
== &dev_attr_conn_header_digest
.attr
)
3430 param
= ISCSI_PARAM_HDRDGST_EN
;
3431 else if (attr
== &dev_attr_conn_data_digest
.attr
)
3432 param
= ISCSI_PARAM_DATADGST_EN
;
3433 else if (attr
== &dev_attr_conn_ifmarker
.attr
)
3434 param
= ISCSI_PARAM_IFMARKER_EN
;
3435 else if (attr
== &dev_attr_conn_ofmarker
.attr
)
3436 param
= ISCSI_PARAM_OFMARKER_EN
;
3437 else if (attr
== &dev_attr_conn_address
.attr
)
3438 param
= ISCSI_PARAM_CONN_ADDRESS
;
3439 else if (attr
== &dev_attr_conn_port
.attr
)
3440 param
= ISCSI_PARAM_CONN_PORT
;
3441 else if (attr
== &dev_attr_conn_exp_statsn
.attr
)
3442 param
= ISCSI_PARAM_EXP_STATSN
;
3443 else if (attr
== &dev_attr_conn_persistent_address
.attr
)
3444 param
= ISCSI_PARAM_PERSISTENT_ADDRESS
;
3445 else if (attr
== &dev_attr_conn_persistent_port
.attr
)
3446 param
= ISCSI_PARAM_PERSISTENT_PORT
;
3447 else if (attr
== &dev_attr_conn_ping_tmo
.attr
)
3448 param
= ISCSI_PARAM_PING_TMO
;
3449 else if (attr
== &dev_attr_conn_recv_tmo
.attr
)
3450 param
= ISCSI_PARAM_RECV_TMO
;
3451 else if (attr
== &dev_attr_conn_local_port
.attr
)
3452 param
= ISCSI_PARAM_LOCAL_PORT
;
3453 else if (attr
== &dev_attr_conn_statsn
.attr
)
3454 param
= ISCSI_PARAM_STATSN
;
3455 else if (attr
== &dev_attr_conn_keepalive_tmo
.attr
)
3456 param
= ISCSI_PARAM_KEEPALIVE_TMO
;
3457 else if (attr
== &dev_attr_conn_max_segment_size
.attr
)
3458 param
= ISCSI_PARAM_MAX_SEGMENT_SIZE
;
3459 else if (attr
== &dev_attr_conn_tcp_timestamp_stat
.attr
)
3460 param
= ISCSI_PARAM_TCP_TIMESTAMP_STAT
;
3461 else if (attr
== &dev_attr_conn_tcp_wsf_disable
.attr
)
3462 param
= ISCSI_PARAM_TCP_WSF_DISABLE
;
3463 else if (attr
== &dev_attr_conn_tcp_nagle_disable
.attr
)
3464 param
= ISCSI_PARAM_TCP_NAGLE_DISABLE
;
3465 else if (attr
== &dev_attr_conn_tcp_timer_scale
.attr
)
3466 param
= ISCSI_PARAM_TCP_TIMER_SCALE
;
3467 else if (attr
== &dev_attr_conn_tcp_timestamp_enable
.attr
)
3468 param
= ISCSI_PARAM_TCP_TIMESTAMP_EN
;
3469 else if (attr
== &dev_attr_conn_fragment_disable
.attr
)
3470 param
= ISCSI_PARAM_IP_FRAGMENT_DISABLE
;
3471 else if (attr
== &dev_attr_conn_ipv4_tos
.attr
)
3472 param
= ISCSI_PARAM_IPV4_TOS
;
3473 else if (attr
== &dev_attr_conn_ipv6_traffic_class
.attr
)
3474 param
= ISCSI_PARAM_IPV6_TC
;
3475 else if (attr
== &dev_attr_conn_ipv6_flow_label
.attr
)
3476 param
= ISCSI_PARAM_IPV6_FLOW_LABEL
;
3477 else if (attr
== &dev_attr_conn_is_fw_assigned_ipv6
.attr
)
3478 param
= ISCSI_PARAM_IS_FW_ASSIGNED_IPV6
;
3479 else if (attr
== &dev_attr_conn_tcp_xmit_wsf
.attr
)
3480 param
= ISCSI_PARAM_TCP_XMIT_WSF
;
3481 else if (attr
== &dev_attr_conn_tcp_recv_wsf
.attr
)
3482 param
= ISCSI_PARAM_TCP_RECV_WSF
;
3484 WARN_ONCE(1, "Invalid conn attr");
3488 return t
->attr_is_visible(ISCSI_PARAM
, param
);
3491 static struct attribute_group iscsi_conn_group
= {
3492 .attrs
= iscsi_conn_attrs
,
3493 .is_visible
= iscsi_conn_attr_is_visible
,
3497 * iSCSI session attrs
3499 #define iscsi_session_attr_show(param, perm) \
3501 show_session_param_##param(struct device *dev, \
3502 struct device_attribute *attr, char *buf) \
3504 struct iscsi_cls_session *session = \
3505 iscsi_dev_to_session(dev->parent); \
3506 struct iscsi_transport *t = session->transport; \
3508 if (perm && !capable(CAP_SYS_ADMIN)) \
3510 return t->get_session_param(session, param, buf); \
3513 #define iscsi_session_attr(field, param, perm) \
3514 iscsi_session_attr_show(param, perm) \
3515 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
3517 iscsi_session_attr(targetname
, ISCSI_PARAM_TARGET_NAME
, 0);
3518 iscsi_session_attr(initial_r2t
, ISCSI_PARAM_INITIAL_R2T_EN
, 0);
3519 iscsi_session_attr(max_outstanding_r2t
, ISCSI_PARAM_MAX_R2T
, 0);
3520 iscsi_session_attr(immediate_data
, ISCSI_PARAM_IMM_DATA_EN
, 0);
3521 iscsi_session_attr(first_burst_len
, ISCSI_PARAM_FIRST_BURST
, 0);
3522 iscsi_session_attr(max_burst_len
, ISCSI_PARAM_MAX_BURST
, 0);
3523 iscsi_session_attr(data_pdu_in_order
, ISCSI_PARAM_PDU_INORDER_EN
, 0);
3524 iscsi_session_attr(data_seq_in_order
, ISCSI_PARAM_DATASEQ_INORDER_EN
, 0);
3525 iscsi_session_attr(erl
, ISCSI_PARAM_ERL
, 0);
3526 iscsi_session_attr(tpgt
, ISCSI_PARAM_TPGT
, 0);
3527 iscsi_session_attr(username
, ISCSI_PARAM_USERNAME
, 1);
3528 iscsi_session_attr(username_in
, ISCSI_PARAM_USERNAME_IN
, 1);
3529 iscsi_session_attr(password
, ISCSI_PARAM_PASSWORD
, 1);
3530 iscsi_session_attr(password_in
, ISCSI_PARAM_PASSWORD_IN
, 1);
3531 iscsi_session_attr(chap_out_idx
, ISCSI_PARAM_CHAP_OUT_IDX
, 1);
3532 iscsi_session_attr(chap_in_idx
, ISCSI_PARAM_CHAP_IN_IDX
, 1);
3533 iscsi_session_attr(fast_abort
, ISCSI_PARAM_FAST_ABORT
, 0);
3534 iscsi_session_attr(abort_tmo
, ISCSI_PARAM_ABORT_TMO
, 0);
3535 iscsi_session_attr(lu_reset_tmo
, ISCSI_PARAM_LU_RESET_TMO
, 0);
3536 iscsi_session_attr(tgt_reset_tmo
, ISCSI_PARAM_TGT_RESET_TMO
, 0);
3537 iscsi_session_attr(ifacename
, ISCSI_PARAM_IFACE_NAME
, 0);
3538 iscsi_session_attr(initiatorname
, ISCSI_PARAM_INITIATOR_NAME
, 0);
3539 iscsi_session_attr(targetalias
, ISCSI_PARAM_TARGET_ALIAS
, 0);
3540 iscsi_session_attr(boot_root
, ISCSI_PARAM_BOOT_ROOT
, 0);
3541 iscsi_session_attr(boot_nic
, ISCSI_PARAM_BOOT_NIC
, 0);
3542 iscsi_session_attr(boot_target
, ISCSI_PARAM_BOOT_TARGET
, 0);
3543 iscsi_session_attr(auto_snd_tgt_disable
, ISCSI_PARAM_AUTO_SND_TGT_DISABLE
, 0);
3544 iscsi_session_attr(discovery_session
, ISCSI_PARAM_DISCOVERY_SESS
, 0);
3545 iscsi_session_attr(portal_type
, ISCSI_PARAM_PORTAL_TYPE
, 0);
3546 iscsi_session_attr(chap_auth
, ISCSI_PARAM_CHAP_AUTH_EN
, 0);
3547 iscsi_session_attr(discovery_logout
, ISCSI_PARAM_DISCOVERY_LOGOUT_EN
, 0);
3548 iscsi_session_attr(bidi_chap
, ISCSI_PARAM_BIDI_CHAP_EN
, 0);
3549 iscsi_session_attr(discovery_auth_optional
,
3550 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL
, 0);
3551 iscsi_session_attr(def_time2wait
, ISCSI_PARAM_DEF_TIME2WAIT
, 0);
3552 iscsi_session_attr(def_time2retain
, ISCSI_PARAM_DEF_TIME2RETAIN
, 0);
3553 iscsi_session_attr(isid
, ISCSI_PARAM_ISID
, 0);
3554 iscsi_session_attr(tsid
, ISCSI_PARAM_TSID
, 0);
3555 iscsi_session_attr(def_taskmgmt_tmo
, ISCSI_PARAM_DEF_TASKMGMT_TMO
, 0);
3556 iscsi_session_attr(discovery_parent_idx
, ISCSI_PARAM_DISCOVERY_PARENT_IDX
, 0);
3557 iscsi_session_attr(discovery_parent_type
, ISCSI_PARAM_DISCOVERY_PARENT_TYPE
, 0);
3560 show_priv_session_state(struct device
*dev
, struct device_attribute
*attr
,
3563 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
->parent
);
3564 return sprintf(buf
, "%s\n", iscsi_session_state_name(session
->state
));
3566 static ISCSI_CLASS_ATTR(priv_sess
, state
, S_IRUGO
, show_priv_session_state
,
3569 show_priv_session_creator(struct device
*dev
, struct device_attribute
*attr
,
3572 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
->parent
);
3573 return sprintf(buf
, "%d\n", session
->creator
);
3575 static ISCSI_CLASS_ATTR(priv_sess
, creator
, S_IRUGO
, show_priv_session_creator
,
3578 show_priv_session_target_id(struct device
*dev
, struct device_attribute
*attr
,
3581 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
->parent
);
3582 return sprintf(buf
, "%d\n", session
->target_id
);
3584 static ISCSI_CLASS_ATTR(priv_sess
, target_id
, S_IRUGO
,
3585 show_priv_session_target_id
, NULL
);
3587 #define iscsi_priv_session_attr_show(field, format) \
3589 show_priv_session_##field(struct device *dev, \
3590 struct device_attribute *attr, char *buf) \
3592 struct iscsi_cls_session *session = \
3593 iscsi_dev_to_session(dev->parent); \
3594 if (session->field == -1) \
3595 return sprintf(buf, "off\n"); \
3596 return sprintf(buf, format"\n", session->field); \
3599 #define iscsi_priv_session_attr_store(field) \
3601 store_priv_session_##field(struct device *dev, \
3602 struct device_attribute *attr, \
3603 const char *buf, size_t count) \
3607 struct iscsi_cls_session *session = \
3608 iscsi_dev_to_session(dev->parent); \
3609 if ((session->state == ISCSI_SESSION_FREE) || \
3610 (session->state == ISCSI_SESSION_FAILED)) \
3612 if (strncmp(buf, "off", 3) == 0) \
3613 session->field = -1; \
3615 val = simple_strtoul(buf, &cp, 0); \
3616 if (*cp != '\0' && *cp != '\n') \
3618 session->field = val; \
3623 #define iscsi_priv_session_rw_attr(field, format) \
3624 iscsi_priv_session_attr_show(field, format) \
3625 iscsi_priv_session_attr_store(field) \
3626 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
3627 show_priv_session_##field, \
3628 store_priv_session_##field)
3629 iscsi_priv_session_rw_attr(recovery_tmo
, "%d");
3631 static struct attribute
*iscsi_session_attrs
[] = {
3632 &dev_attr_sess_initial_r2t
.attr
,
3633 &dev_attr_sess_max_outstanding_r2t
.attr
,
3634 &dev_attr_sess_immediate_data
.attr
,
3635 &dev_attr_sess_first_burst_len
.attr
,
3636 &dev_attr_sess_max_burst_len
.attr
,
3637 &dev_attr_sess_data_pdu_in_order
.attr
,
3638 &dev_attr_sess_data_seq_in_order
.attr
,
3639 &dev_attr_sess_erl
.attr
,
3640 &dev_attr_sess_targetname
.attr
,
3641 &dev_attr_sess_tpgt
.attr
,
3642 &dev_attr_sess_password
.attr
,
3643 &dev_attr_sess_password_in
.attr
,
3644 &dev_attr_sess_username
.attr
,
3645 &dev_attr_sess_username_in
.attr
,
3646 &dev_attr_sess_fast_abort
.attr
,
3647 &dev_attr_sess_abort_tmo
.attr
,
3648 &dev_attr_sess_lu_reset_tmo
.attr
,
3649 &dev_attr_sess_tgt_reset_tmo
.attr
,
3650 &dev_attr_sess_ifacename
.attr
,
3651 &dev_attr_sess_initiatorname
.attr
,
3652 &dev_attr_sess_targetalias
.attr
,
3653 &dev_attr_sess_boot_root
.attr
,
3654 &dev_attr_sess_boot_nic
.attr
,
3655 &dev_attr_sess_boot_target
.attr
,
3656 &dev_attr_priv_sess_recovery_tmo
.attr
,
3657 &dev_attr_priv_sess_state
.attr
,
3658 &dev_attr_priv_sess_creator
.attr
,
3659 &dev_attr_sess_chap_out_idx
.attr
,
3660 &dev_attr_sess_chap_in_idx
.attr
,
3661 &dev_attr_priv_sess_target_id
.attr
,
3662 &dev_attr_sess_auto_snd_tgt_disable
.attr
,
3663 &dev_attr_sess_discovery_session
.attr
,
3664 &dev_attr_sess_portal_type
.attr
,
3665 &dev_attr_sess_chap_auth
.attr
,
3666 &dev_attr_sess_discovery_logout
.attr
,
3667 &dev_attr_sess_bidi_chap
.attr
,
3668 &dev_attr_sess_discovery_auth_optional
.attr
,
3669 &dev_attr_sess_def_time2wait
.attr
,
3670 &dev_attr_sess_def_time2retain
.attr
,
3671 &dev_attr_sess_isid
.attr
,
3672 &dev_attr_sess_tsid
.attr
,
3673 &dev_attr_sess_def_taskmgmt_tmo
.attr
,
3674 &dev_attr_sess_discovery_parent_idx
.attr
,
3675 &dev_attr_sess_discovery_parent_type
.attr
,
3679 static umode_t
iscsi_session_attr_is_visible(struct kobject
*kobj
,
3680 struct attribute
*attr
, int i
)
3682 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3683 struct iscsi_cls_session
*session
= transport_class_to_session(cdev
);
3684 struct iscsi_transport
*t
= session
->transport
;
3687 if (attr
== &dev_attr_sess_initial_r2t
.attr
)
3688 param
= ISCSI_PARAM_INITIAL_R2T_EN
;
3689 else if (attr
== &dev_attr_sess_max_outstanding_r2t
.attr
)
3690 param
= ISCSI_PARAM_MAX_R2T
;
3691 else if (attr
== &dev_attr_sess_immediate_data
.attr
)
3692 param
= ISCSI_PARAM_IMM_DATA_EN
;
3693 else if (attr
== &dev_attr_sess_first_burst_len
.attr
)
3694 param
= ISCSI_PARAM_FIRST_BURST
;
3695 else if (attr
== &dev_attr_sess_max_burst_len
.attr
)
3696 param
= ISCSI_PARAM_MAX_BURST
;
3697 else if (attr
== &dev_attr_sess_data_pdu_in_order
.attr
)
3698 param
= ISCSI_PARAM_PDU_INORDER_EN
;
3699 else if (attr
== &dev_attr_sess_data_seq_in_order
.attr
)
3700 param
= ISCSI_PARAM_DATASEQ_INORDER_EN
;
3701 else if (attr
== &dev_attr_sess_erl
.attr
)
3702 param
= ISCSI_PARAM_ERL
;
3703 else if (attr
== &dev_attr_sess_targetname
.attr
)
3704 param
= ISCSI_PARAM_TARGET_NAME
;
3705 else if (attr
== &dev_attr_sess_tpgt
.attr
)
3706 param
= ISCSI_PARAM_TPGT
;
3707 else if (attr
== &dev_attr_sess_chap_in_idx
.attr
)
3708 param
= ISCSI_PARAM_CHAP_IN_IDX
;
3709 else if (attr
== &dev_attr_sess_chap_out_idx
.attr
)
3710 param
= ISCSI_PARAM_CHAP_OUT_IDX
;
3711 else if (attr
== &dev_attr_sess_password
.attr
)
3712 param
= ISCSI_PARAM_USERNAME
;
3713 else if (attr
== &dev_attr_sess_password_in
.attr
)
3714 param
= ISCSI_PARAM_USERNAME_IN
;
3715 else if (attr
== &dev_attr_sess_username
.attr
)
3716 param
= ISCSI_PARAM_PASSWORD
;
3717 else if (attr
== &dev_attr_sess_username_in
.attr
)
3718 param
= ISCSI_PARAM_PASSWORD_IN
;
3719 else if (attr
== &dev_attr_sess_fast_abort
.attr
)
3720 param
= ISCSI_PARAM_FAST_ABORT
;
3721 else if (attr
== &dev_attr_sess_abort_tmo
.attr
)
3722 param
= ISCSI_PARAM_ABORT_TMO
;
3723 else if (attr
== &dev_attr_sess_lu_reset_tmo
.attr
)
3724 param
= ISCSI_PARAM_LU_RESET_TMO
;
3725 else if (attr
== &dev_attr_sess_tgt_reset_tmo
.attr
)
3726 param
= ISCSI_PARAM_TGT_RESET_TMO
;
3727 else if (attr
== &dev_attr_sess_ifacename
.attr
)
3728 param
= ISCSI_PARAM_IFACE_NAME
;
3729 else if (attr
== &dev_attr_sess_initiatorname
.attr
)
3730 param
= ISCSI_PARAM_INITIATOR_NAME
;
3731 else if (attr
== &dev_attr_sess_targetalias
.attr
)
3732 param
= ISCSI_PARAM_TARGET_ALIAS
;
3733 else if (attr
== &dev_attr_sess_boot_root
.attr
)
3734 param
= ISCSI_PARAM_BOOT_ROOT
;
3735 else if (attr
== &dev_attr_sess_boot_nic
.attr
)
3736 param
= ISCSI_PARAM_BOOT_NIC
;
3737 else if (attr
== &dev_attr_sess_boot_target
.attr
)
3738 param
= ISCSI_PARAM_BOOT_TARGET
;
3739 else if (attr
== &dev_attr_sess_auto_snd_tgt_disable
.attr
)
3740 param
= ISCSI_PARAM_AUTO_SND_TGT_DISABLE
;
3741 else if (attr
== &dev_attr_sess_discovery_session
.attr
)
3742 param
= ISCSI_PARAM_DISCOVERY_SESS
;
3743 else if (attr
== &dev_attr_sess_portal_type
.attr
)
3744 param
= ISCSI_PARAM_PORTAL_TYPE
;
3745 else if (attr
== &dev_attr_sess_chap_auth
.attr
)
3746 param
= ISCSI_PARAM_CHAP_AUTH_EN
;
3747 else if (attr
== &dev_attr_sess_discovery_logout
.attr
)
3748 param
= ISCSI_PARAM_DISCOVERY_LOGOUT_EN
;
3749 else if (attr
== &dev_attr_sess_bidi_chap
.attr
)
3750 param
= ISCSI_PARAM_BIDI_CHAP_EN
;
3751 else if (attr
== &dev_attr_sess_discovery_auth_optional
.attr
)
3752 param
= ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL
;
3753 else if (attr
== &dev_attr_sess_def_time2wait
.attr
)
3754 param
= ISCSI_PARAM_DEF_TIME2WAIT
;
3755 else if (attr
== &dev_attr_sess_def_time2retain
.attr
)
3756 param
= ISCSI_PARAM_DEF_TIME2RETAIN
;
3757 else if (attr
== &dev_attr_sess_isid
.attr
)
3758 param
= ISCSI_PARAM_ISID
;
3759 else if (attr
== &dev_attr_sess_tsid
.attr
)
3760 param
= ISCSI_PARAM_TSID
;
3761 else if (attr
== &dev_attr_sess_def_taskmgmt_tmo
.attr
)
3762 param
= ISCSI_PARAM_DEF_TASKMGMT_TMO
;
3763 else if (attr
== &dev_attr_sess_discovery_parent_idx
.attr
)
3764 param
= ISCSI_PARAM_DISCOVERY_PARENT_IDX
;
3765 else if (attr
== &dev_attr_sess_discovery_parent_type
.attr
)
3766 param
= ISCSI_PARAM_DISCOVERY_PARENT_TYPE
;
3767 else if (attr
== &dev_attr_priv_sess_recovery_tmo
.attr
)
3768 return S_IRUGO
| S_IWUSR
;
3769 else if (attr
== &dev_attr_priv_sess_state
.attr
)
3771 else if (attr
== &dev_attr_priv_sess_creator
.attr
)
3773 else if (attr
== &dev_attr_priv_sess_target_id
.attr
)
3776 WARN_ONCE(1, "Invalid session attr");
3780 return t
->attr_is_visible(ISCSI_PARAM
, param
);
3783 static struct attribute_group iscsi_session_group
= {
3784 .attrs
= iscsi_session_attrs
,
3785 .is_visible
= iscsi_session_attr_is_visible
,
3791 #define iscsi_host_attr_show(param) \
3793 show_host_param_##param(struct device *dev, \
3794 struct device_attribute *attr, char *buf) \
3796 struct Scsi_Host *shost = transport_class_to_shost(dev); \
3797 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
3798 return priv->iscsi_transport->get_host_param(shost, param, buf); \
3801 #define iscsi_host_attr(field, param) \
3802 iscsi_host_attr_show(param) \
3803 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
3806 iscsi_host_attr(netdev
, ISCSI_HOST_PARAM_NETDEV_NAME
);
3807 iscsi_host_attr(hwaddress
, ISCSI_HOST_PARAM_HWADDRESS
);
3808 iscsi_host_attr(ipaddress
, ISCSI_HOST_PARAM_IPADDRESS
);
3809 iscsi_host_attr(initiatorname
, ISCSI_HOST_PARAM_INITIATOR_NAME
);
3810 iscsi_host_attr(port_state
, ISCSI_HOST_PARAM_PORT_STATE
);
3811 iscsi_host_attr(port_speed
, ISCSI_HOST_PARAM_PORT_SPEED
);
3813 static struct attribute
*iscsi_host_attrs
[] = {
3814 &dev_attr_host_netdev
.attr
,
3815 &dev_attr_host_hwaddress
.attr
,
3816 &dev_attr_host_ipaddress
.attr
,
3817 &dev_attr_host_initiatorname
.attr
,
3818 &dev_attr_host_port_state
.attr
,
3819 &dev_attr_host_port_speed
.attr
,
3823 static umode_t
iscsi_host_attr_is_visible(struct kobject
*kobj
,
3824 struct attribute
*attr
, int i
)
3826 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3827 struct Scsi_Host
*shost
= transport_class_to_shost(cdev
);
3828 struct iscsi_internal
*priv
= to_iscsi_internal(shost
->transportt
);
3831 if (attr
== &dev_attr_host_netdev
.attr
)
3832 param
= ISCSI_HOST_PARAM_NETDEV_NAME
;
3833 else if (attr
== &dev_attr_host_hwaddress
.attr
)
3834 param
= ISCSI_HOST_PARAM_HWADDRESS
;
3835 else if (attr
== &dev_attr_host_ipaddress
.attr
)
3836 param
= ISCSI_HOST_PARAM_IPADDRESS
;
3837 else if (attr
== &dev_attr_host_initiatorname
.attr
)
3838 param
= ISCSI_HOST_PARAM_INITIATOR_NAME
;
3839 else if (attr
== &dev_attr_host_port_state
.attr
)
3840 param
= ISCSI_HOST_PARAM_PORT_STATE
;
3841 else if (attr
== &dev_attr_host_port_speed
.attr
)
3842 param
= ISCSI_HOST_PARAM_PORT_SPEED
;
3844 WARN_ONCE(1, "Invalid host attr");
3848 return priv
->iscsi_transport
->attr_is_visible(ISCSI_HOST_PARAM
, param
);
3851 static struct attribute_group iscsi_host_group
= {
3852 .attrs
= iscsi_host_attrs
,
3853 .is_visible
= iscsi_host_attr_is_visible
,
3856 /* convert iscsi_port_speed values to ascii string name */
3857 static const struct {
3858 enum iscsi_port_speed value
;
3860 } iscsi_port_speed_names
[] = {
3861 {ISCSI_PORT_SPEED_UNKNOWN
, "Unknown" },
3862 {ISCSI_PORT_SPEED_10MBPS
, "10 Mbps" },
3863 {ISCSI_PORT_SPEED_100MBPS
, "100 Mbps" },
3864 {ISCSI_PORT_SPEED_1GBPS
, "1 Gbps" },
3865 {ISCSI_PORT_SPEED_10GBPS
, "10 Gbps" },
3868 char *iscsi_get_port_speed_name(struct Scsi_Host
*shost
)
3871 char *speed
= "Unknown!";
3872 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
3873 uint32_t port_speed
= ihost
->port_speed
;
3875 for (i
= 0; i
< ARRAY_SIZE(iscsi_port_speed_names
); i
++) {
3876 if (iscsi_port_speed_names
[i
].value
& port_speed
) {
3877 speed
= iscsi_port_speed_names
[i
].name
;
3883 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name
);
3885 /* convert iscsi_port_state values to ascii string name */
3886 static const struct {
3887 enum iscsi_port_state value
;
3889 } iscsi_port_state_names
[] = {
3890 {ISCSI_PORT_STATE_DOWN
, "LINK DOWN" },
3891 {ISCSI_PORT_STATE_UP
, "LINK UP" },
3894 char *iscsi_get_port_state_name(struct Scsi_Host
*shost
)
3897 char *state
= "Unknown!";
3898 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
3899 uint32_t port_state
= ihost
->port_state
;
3901 for (i
= 0; i
< ARRAY_SIZE(iscsi_port_state_names
); i
++) {
3902 if (iscsi_port_state_names
[i
].value
& port_state
) {
3903 state
= iscsi_port_state_names
[i
].name
;
3909 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name
);
3911 static int iscsi_session_match(struct attribute_container
*cont
,
3914 struct iscsi_cls_session
*session
;
3915 struct Scsi_Host
*shost
;
3916 struct iscsi_internal
*priv
;
3918 if (!iscsi_is_session_dev(dev
))
3921 session
= iscsi_dev_to_session(dev
);
3922 shost
= iscsi_session_to_shost(session
);
3923 if (!shost
->transportt
)
3926 priv
= to_iscsi_internal(shost
->transportt
);
3927 if (priv
->session_cont
.ac
.class != &iscsi_session_class
.class)
3930 return &priv
->session_cont
.ac
== cont
;
3933 static int iscsi_conn_match(struct attribute_container
*cont
,
3936 struct iscsi_cls_session
*session
;
3937 struct iscsi_cls_conn
*conn
;
3938 struct Scsi_Host
*shost
;
3939 struct iscsi_internal
*priv
;
3941 if (!iscsi_is_conn_dev(dev
))
3944 conn
= iscsi_dev_to_conn(dev
);
3945 session
= iscsi_dev_to_session(conn
->dev
.parent
);
3946 shost
= iscsi_session_to_shost(session
);
3948 if (!shost
->transportt
)
3951 priv
= to_iscsi_internal(shost
->transportt
);
3952 if (priv
->conn_cont
.ac
.class != &iscsi_connection_class
.class)
3955 return &priv
->conn_cont
.ac
== cont
;
3958 static int iscsi_host_match(struct attribute_container
*cont
,
3961 struct Scsi_Host
*shost
;
3962 struct iscsi_internal
*priv
;
3964 if (!scsi_is_host_device(dev
))
3967 shost
= dev_to_shost(dev
);
3968 if (!shost
->transportt
||
3969 shost
->transportt
->host_attrs
.ac
.class != &iscsi_host_class
.class)
3972 priv
= to_iscsi_internal(shost
->transportt
);
3973 return &priv
->t
.host_attrs
.ac
== cont
;
3976 struct scsi_transport_template
*
3977 iscsi_register_transport(struct iscsi_transport
*tt
)
3979 struct iscsi_internal
*priv
;
3980 unsigned long flags
;
3985 priv
= iscsi_if_transport_lookup(tt
);
3989 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
3992 INIT_LIST_HEAD(&priv
->list
);
3993 priv
->iscsi_transport
= tt
;
3994 priv
->t
.user_scan
= iscsi_user_scan
;
3995 priv
->t
.create_work_queue
= 1;
3997 priv
->dev
.class = &iscsi_transport_class
;
3998 dev_set_name(&priv
->dev
, "%s", tt
->name
);
3999 err
= device_register(&priv
->dev
);
4003 err
= sysfs_create_group(&priv
->dev
.kobj
, &iscsi_transport_group
);
4005 goto unregister_dev
;
4007 /* host parameters */
4008 priv
->t
.host_attrs
.ac
.class = &iscsi_host_class
.class;
4009 priv
->t
.host_attrs
.ac
.match
= iscsi_host_match
;
4010 priv
->t
.host_attrs
.ac
.grp
= &iscsi_host_group
;
4011 priv
->t
.host_size
= sizeof(struct iscsi_cls_host
);
4012 transport_container_register(&priv
->t
.host_attrs
);
4014 /* connection parameters */
4015 priv
->conn_cont
.ac
.class = &iscsi_connection_class
.class;
4016 priv
->conn_cont
.ac
.match
= iscsi_conn_match
;
4017 priv
->conn_cont
.ac
.grp
= &iscsi_conn_group
;
4018 transport_container_register(&priv
->conn_cont
);
4020 /* session parameters */
4021 priv
->session_cont
.ac
.class = &iscsi_session_class
.class;
4022 priv
->session_cont
.ac
.match
= iscsi_session_match
;
4023 priv
->session_cont
.ac
.grp
= &iscsi_session_group
;
4024 transport_container_register(&priv
->session_cont
);
4026 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
4027 list_add(&priv
->list
, &iscsi_transports
);
4028 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
4030 printk(KERN_NOTICE
"iscsi: registered transport (%s)\n", tt
->name
);
4034 device_unregister(&priv
->dev
);
4040 EXPORT_SYMBOL_GPL(iscsi_register_transport
);
4042 int iscsi_unregister_transport(struct iscsi_transport
*tt
)
4044 struct iscsi_internal
*priv
;
4045 unsigned long flags
;
4049 mutex_lock(&rx_queue_mutex
);
4051 priv
= iscsi_if_transport_lookup(tt
);
4054 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
4055 list_del(&priv
->list
);
4056 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
4058 transport_container_unregister(&priv
->conn_cont
);
4059 transport_container_unregister(&priv
->session_cont
);
4060 transport_container_unregister(&priv
->t
.host_attrs
);
4062 sysfs_remove_group(&priv
->dev
.kobj
, &iscsi_transport_group
);
4063 device_unregister(&priv
->dev
);
4064 mutex_unlock(&rx_queue_mutex
);
4068 EXPORT_SYMBOL_GPL(iscsi_unregister_transport
);
4070 static __init
int iscsi_transport_init(void)
4073 struct netlink_kernel_cfg cfg
= {
4075 .input
= iscsi_if_rx
,
4077 printk(KERN_INFO
"Loading iSCSI transport class v%s.\n",
4078 ISCSI_TRANSPORT_VERSION
);
4080 atomic_set(&iscsi_session_nr
, 0);
4082 err
= class_register(&iscsi_transport_class
);
4086 err
= class_register(&iscsi_endpoint_class
);
4088 goto unregister_transport_class
;
4090 err
= class_register(&iscsi_iface_class
);
4092 goto unregister_endpoint_class
;
4094 err
= transport_class_register(&iscsi_host_class
);
4096 goto unregister_iface_class
;
4098 err
= transport_class_register(&iscsi_connection_class
);
4100 goto unregister_host_class
;
4102 err
= transport_class_register(&iscsi_session_class
);
4104 goto unregister_conn_class
;
4106 err
= bus_register(&iscsi_flashnode_bus
);
4108 goto unregister_session_class
;
4110 nls
= netlink_kernel_create(&init_net
, NETLINK_ISCSI
, &cfg
);
4113 goto unregister_flashnode_bus
;
4116 iscsi_eh_timer_workq
= create_singlethread_workqueue("iscsi_eh");
4117 if (!iscsi_eh_timer_workq
) {
4125 netlink_kernel_release(nls
);
4126 unregister_flashnode_bus
:
4127 bus_unregister(&iscsi_flashnode_bus
);
4128 unregister_session_class
:
4129 transport_class_unregister(&iscsi_session_class
);
4130 unregister_conn_class
:
4131 transport_class_unregister(&iscsi_connection_class
);
4132 unregister_host_class
:
4133 transport_class_unregister(&iscsi_host_class
);
4134 unregister_iface_class
:
4135 class_unregister(&iscsi_iface_class
);
4136 unregister_endpoint_class
:
4137 class_unregister(&iscsi_endpoint_class
);
4138 unregister_transport_class
:
4139 class_unregister(&iscsi_transport_class
);
4143 static void __exit
iscsi_transport_exit(void)
4145 destroy_workqueue(iscsi_eh_timer_workq
);
4146 netlink_kernel_release(nls
);
4147 bus_unregister(&iscsi_flashnode_bus
);
4148 transport_class_unregister(&iscsi_connection_class
);
4149 transport_class_unregister(&iscsi_session_class
);
4150 transport_class_unregister(&iscsi_host_class
);
4151 class_unregister(&iscsi_endpoint_class
);
4152 class_unregister(&iscsi_iface_class
);
4153 class_unregister(&iscsi_transport_class
);
4156 module_init(iscsi_transport_init
);
4157 module_exit(iscsi_transport_exit
);
4159 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
4160 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
4161 "Alex Aizman <itn780@yahoo.com>");
4162 MODULE_DESCRIPTION("iSCSI Transport Interface");
4163 MODULE_LICENSE("GPL");
4164 MODULE_VERSION(ISCSI_TRANSPORT_VERSION
);
4165 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK
, NETLINK_ISCSI
);