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 #define ISCSI_SEND_MAX_ALLOWED 10
42 static int dbg_session;
43 module_param_named(debug_session, dbg_session, int,
45 MODULE_PARM_DESC(debug_session,
46 "Turn on debugging for sessions in scsi_transport_iscsi "
47 "module. Set to 1 to turn on, and zero to turn off. Default "
51 module_param_named(debug_conn, dbg_conn, int,
53 MODULE_PARM_DESC(debug_conn,
54 "Turn on debugging for connections in scsi_transport_iscsi "
55 "module. Set to 1 to turn on, and zero to turn off. Default "
58 #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \
61 iscsi_cls_session_printk(KERN_INFO, _session, \
66 #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \
69 iscsi_cls_conn_printk(KERN_INFO, _conn, \
74 struct iscsi_internal {
75 struct scsi_transport_template t;
76 struct iscsi_transport *iscsi_transport;
77 struct list_head list;
80 struct transport_container conn_cont;
81 struct transport_container session_cont;
84 static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
85 static struct workqueue_struct *iscsi_eh_timer_workq;
87 static DEFINE_IDA(iscsi_sess_ida);
89 * list of registered transports and lock that must
90 * be held while accessing list. The iscsi_transport_lock must
91 * be acquired after the rx_queue_mutex.
93 static LIST_HEAD(iscsi_transports);
94 static DEFINE_SPINLOCK(iscsi_transport_lock);
96 #define to_iscsi_internal(tmpl) \
97 container_of(tmpl, struct iscsi_internal, t)
99 #define dev_to_iscsi_internal(_dev) \
100 container_of(_dev, struct iscsi_internal, dev)
102 static void iscsi_transport_release(struct device *dev)
104 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
109 * iscsi_transport_class represents the iscsi_transports that are
112 static struct class iscsi_transport_class = {
113 .name = "iscsi_transport",
114 .dev_release = iscsi_transport_release,
118 show_transport_handle(struct device *dev, struct device_attribute *attr,
121 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
123 if (!capable(CAP_SYS_ADMIN))
125 return sysfs_emit(buf, "%llu\n",
126 (unsigned long long)iscsi_handle(priv->iscsi_transport));
128 static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
130 #define show_transport_attr(name, format) \
132 show_transport_##name(struct device *dev, \
133 struct device_attribute *attr,char *buf) \
135 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
136 return sysfs_emit(buf, format"\n", priv->iscsi_transport->name);\
138 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
140 show_transport_attr(caps, "0x%x");
142 static struct attribute *iscsi_transport_attrs[] = {
143 &dev_attr_handle.attr,
148 static struct attribute_group iscsi_transport_group = {
149 .attrs = iscsi_transport_attrs,
153 * iSCSI endpoint attrs
155 #define iscsi_dev_to_endpoint(_dev) \
156 container_of(_dev, struct iscsi_endpoint, dev)
158 #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
159 struct device_attribute dev_attr_##_prefix##_##_name = \
160 __ATTR(_name,_mode,_show,_store)
162 static void iscsi_endpoint_release(struct device *dev)
164 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
168 static struct class iscsi_endpoint_class = {
169 .name = "iscsi_endpoint",
170 .dev_release = iscsi_endpoint_release,
174 show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
176 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
177 return sysfs_emit(buf, "%llu\n", (unsigned long long) ep->id);
179 static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
181 static struct attribute *iscsi_endpoint_attrs[] = {
182 &dev_attr_ep_handle.attr,
186 static struct attribute_group iscsi_endpoint_group = {
187 .attrs = iscsi_endpoint_attrs,
190 #define ISCSI_MAX_EPID -1
192 static int iscsi_match_epid(struct device *dev, const void *data)
194 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
195 const uint64_t *epid = data;
197 return *epid == ep->id;
200 struct iscsi_endpoint *
201 iscsi_create_endpoint(int dd_size)
204 struct iscsi_endpoint *ep;
208 for (id = 1; id < ISCSI_MAX_EPID; id++) {
209 dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
216 if (id == ISCSI_MAX_EPID) {
217 printk(KERN_ERR "Too many connections. Max supported %u\n",
222 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
227 ep->dev.class = &iscsi_endpoint_class;
228 dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id);
229 err = device_register(&ep->dev);
233 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
238 ep->dd_data = &ep[1];
242 device_unregister(&ep->dev);
249 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
251 void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
253 sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
254 device_unregister(&ep->dev);
256 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
258 struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
260 struct iscsi_endpoint *ep;
263 dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
268 ep = iscsi_dev_to_endpoint(dev);
270 * we can drop this now because the interface will prevent
271 * removals and lookups from racing.
276 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
279 * Interface to display network param to sysfs
282 static void iscsi_iface_release(struct device *dev)
284 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
285 struct device *parent = iface->dev.parent;
292 static struct class iscsi_iface_class = {
293 .name = "iscsi_iface",
294 .dev_release = iscsi_iface_release,
297 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
298 struct device_attribute dev_attr_##_prefix##_##_name = \
299 __ATTR(_name, _mode, _show, _store)
301 /* iface attrs show */
302 #define iscsi_iface_attr_show(type, name, param_type, param) \
304 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
307 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
308 struct iscsi_transport *t = iface->transport; \
309 return t->get_iface_param(iface, param_type, param, buf); \
312 #define iscsi_iface_net_attr(type, name, param) \
313 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
314 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
316 #define iscsi_iface_attr(type, name, param) \
317 iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \
318 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
320 /* generic read only ipv4 attribute */
321 iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
322 iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
323 iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
324 iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
325 iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en,
326 ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN);
327 iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en,
328 ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN);
329 iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN);
330 iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS);
331 iscsi_iface_net_attr(ipv4_iface, grat_arp_en,
332 ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN);
333 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en,
334 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN);
335 iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id,
336 ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID);
337 iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en,
338 ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN);
339 iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en,
340 ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN);
341 iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id,
342 ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID);
343 iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en,
344 ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN);
345 iscsi_iface_net_attr(ipv4_iface, fragment_disable,
346 ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE);
347 iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en,
348 ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN);
349 iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL);
351 /* generic read only ipv6 attribute */
352 iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
353 iscsi_iface_net_attr(ipv6_iface, link_local_addr,
354 ISCSI_NET_PARAM_IPV6_LINKLOCAL);
355 iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
356 iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
357 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
358 iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
359 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
360 iscsi_iface_net_attr(ipv6_iface, link_local_state,
361 ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE);
362 iscsi_iface_net_attr(ipv6_iface, router_state,
363 ISCSI_NET_PARAM_IPV6_ROUTER_STATE);
364 iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en,
365 ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN);
366 iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN);
367 iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL);
368 iscsi_iface_net_attr(ipv6_iface, traffic_class,
369 ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS);
370 iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT);
371 iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo,
372 ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO);
373 iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time,
374 ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME);
375 iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo,
376 ISCSI_NET_PARAM_IPV6_ND_STALE_TMO);
377 iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt,
378 ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT);
379 iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu,
380 ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU);
382 /* common read only iface attribute */
383 iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
384 iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
385 iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
386 iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
387 iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
388 iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
389 iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE);
390 iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN);
391 iscsi_iface_net_attr(iface, tcp_nagle_disable,
392 ISCSI_NET_PARAM_TCP_NAGLE_DISABLE);
393 iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE);
394 iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF);
395 iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE);
396 iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN);
397 iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID);
398 iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN);
400 /* common iscsi specific settings attributes */
401 iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO);
402 iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN);
403 iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN);
404 iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN);
405 iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN);
406 iscsi_iface_attr(iface, data_seq_in_order,
407 ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN);
408 iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN);
409 iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL);
410 iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH);
411 iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST);
412 iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T);
413 iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST);
414 iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN);
415 iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN);
416 iscsi_iface_attr(iface, discovery_auth_optional,
417 ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL);
418 iscsi_iface_attr(iface, discovery_logout,
419 ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN);
420 iscsi_iface_attr(iface, strict_login_comp_en,
421 ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN);
422 iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME);
424 static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
425 struct attribute *attr, int i)
427 struct device *dev = container_of(kobj, struct device, kobj);
428 struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
429 struct iscsi_transport *t = iface->transport;
432 if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr)
433 param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO;
434 else if (attr == &dev_attr_iface_header_digest.attr)
435 param = ISCSI_IFACE_PARAM_HDRDGST_EN;
436 else if (attr == &dev_attr_iface_data_digest.attr)
437 param = ISCSI_IFACE_PARAM_DATADGST_EN;
438 else if (attr == &dev_attr_iface_immediate_data.attr)
439 param = ISCSI_IFACE_PARAM_IMM_DATA_EN;
440 else if (attr == &dev_attr_iface_initial_r2t.attr)
441 param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN;
442 else if (attr == &dev_attr_iface_data_seq_in_order.attr)
443 param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN;
444 else if (attr == &dev_attr_iface_data_pdu_in_order.attr)
445 param = ISCSI_IFACE_PARAM_PDU_INORDER_EN;
446 else if (attr == &dev_attr_iface_erl.attr)
447 param = ISCSI_IFACE_PARAM_ERL;
448 else if (attr == &dev_attr_iface_max_recv_dlength.attr)
449 param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH;
450 else if (attr == &dev_attr_iface_first_burst_len.attr)
451 param = ISCSI_IFACE_PARAM_FIRST_BURST;
452 else if (attr == &dev_attr_iface_max_outstanding_r2t.attr)
453 param = ISCSI_IFACE_PARAM_MAX_R2T;
454 else if (attr == &dev_attr_iface_max_burst_len.attr)
455 param = ISCSI_IFACE_PARAM_MAX_BURST;
456 else if (attr == &dev_attr_iface_chap_auth.attr)
457 param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN;
458 else if (attr == &dev_attr_iface_bidi_chap.attr)
459 param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN;
460 else if (attr == &dev_attr_iface_discovery_auth_optional.attr)
461 param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL;
462 else if (attr == &dev_attr_iface_discovery_logout.attr)
463 param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN;
464 else if (attr == &dev_attr_iface_strict_login_comp_en.attr)
465 param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN;
466 else if (attr == &dev_attr_iface_initiator_name.attr)
467 param = ISCSI_IFACE_PARAM_INITIATOR_NAME;
470 return t->attr_is_visible(ISCSI_IFACE_PARAM, param);
472 if (attr == &dev_attr_iface_enabled.attr)
473 param = ISCSI_NET_PARAM_IFACE_ENABLE;
474 else if (attr == &dev_attr_iface_vlan_id.attr)
475 param = ISCSI_NET_PARAM_VLAN_ID;
476 else if (attr == &dev_attr_iface_vlan_priority.attr)
477 param = ISCSI_NET_PARAM_VLAN_PRIORITY;
478 else if (attr == &dev_attr_iface_vlan_enabled.attr)
479 param = ISCSI_NET_PARAM_VLAN_ENABLED;
480 else if (attr == &dev_attr_iface_mtu.attr)
481 param = ISCSI_NET_PARAM_MTU;
482 else if (attr == &dev_attr_iface_port.attr)
483 param = ISCSI_NET_PARAM_PORT;
484 else if (attr == &dev_attr_iface_ipaddress_state.attr)
485 param = ISCSI_NET_PARAM_IPADDR_STATE;
486 else if (attr == &dev_attr_iface_delayed_ack_en.attr)
487 param = ISCSI_NET_PARAM_DELAYED_ACK_EN;
488 else if (attr == &dev_attr_iface_tcp_nagle_disable.attr)
489 param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE;
490 else if (attr == &dev_attr_iface_tcp_wsf_disable.attr)
491 param = ISCSI_NET_PARAM_TCP_WSF_DISABLE;
492 else if (attr == &dev_attr_iface_tcp_wsf.attr)
493 param = ISCSI_NET_PARAM_TCP_WSF;
494 else if (attr == &dev_attr_iface_tcp_timer_scale.attr)
495 param = ISCSI_NET_PARAM_TCP_TIMER_SCALE;
496 else if (attr == &dev_attr_iface_tcp_timestamp_en.attr)
497 param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN;
498 else if (attr == &dev_attr_iface_cache_id.attr)
499 param = ISCSI_NET_PARAM_CACHE_ID;
500 else if (attr == &dev_attr_iface_redirect_en.attr)
501 param = ISCSI_NET_PARAM_REDIRECT_EN;
502 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
503 if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
504 param = ISCSI_NET_PARAM_IPV4_ADDR;
505 else if (attr == &dev_attr_ipv4_iface_gateway.attr)
506 param = ISCSI_NET_PARAM_IPV4_GW;
507 else if (attr == &dev_attr_ipv4_iface_subnet.attr)
508 param = ISCSI_NET_PARAM_IPV4_SUBNET;
509 else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
510 param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
512 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr)
513 param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN;
515 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr)
516 param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN;
517 else if (attr == &dev_attr_ipv4_iface_tos_en.attr)
518 param = ISCSI_NET_PARAM_IPV4_TOS_EN;
519 else if (attr == &dev_attr_ipv4_iface_tos.attr)
520 param = ISCSI_NET_PARAM_IPV4_TOS;
521 else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr)
522 param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN;
524 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr)
525 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN;
526 else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr)
527 param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID;
529 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr)
530 param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN;
532 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr)
533 param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN;
534 else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr)
535 param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID;
537 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr)
538 param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN;
540 &dev_attr_ipv4_iface_fragment_disable.attr)
541 param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE;
543 &dev_attr_ipv4_iface_incoming_forwarding_en.attr)
544 param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN;
545 else if (attr == &dev_attr_ipv4_iface_ttl.attr)
546 param = ISCSI_NET_PARAM_IPV4_TTL;
549 } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
550 if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
551 param = ISCSI_NET_PARAM_IPV6_ADDR;
552 else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
553 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
554 else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
555 param = ISCSI_NET_PARAM_IPV6_ROUTER;
556 else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
557 param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
558 else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
559 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
560 else if (attr == &dev_attr_ipv6_iface_link_local_state.attr)
561 param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE;
562 else if (attr == &dev_attr_ipv6_iface_router_state.attr)
563 param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE;
565 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr)
566 param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN;
567 else if (attr == &dev_attr_ipv6_iface_mld_en.attr)
568 param = ISCSI_NET_PARAM_IPV6_MLD_EN;
569 else if (attr == &dev_attr_ipv6_iface_flow_label.attr)
570 param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL;
571 else if (attr == &dev_attr_ipv6_iface_traffic_class.attr)
572 param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS;
573 else if (attr == &dev_attr_ipv6_iface_hop_limit.attr)
574 param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT;
575 else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr)
576 param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO;
577 else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr)
578 param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME;
579 else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr)
580 param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO;
581 else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr)
582 param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT;
583 else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr)
584 param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU;
588 WARN_ONCE(1, "Invalid iface attr");
592 return t->attr_is_visible(ISCSI_NET_PARAM, param);
595 static struct attribute *iscsi_iface_attrs[] = {
596 &dev_attr_iface_enabled.attr,
597 &dev_attr_iface_vlan_id.attr,
598 &dev_attr_iface_vlan_priority.attr,
599 &dev_attr_iface_vlan_enabled.attr,
600 &dev_attr_ipv4_iface_ipaddress.attr,
601 &dev_attr_ipv4_iface_gateway.attr,
602 &dev_attr_ipv4_iface_subnet.attr,
603 &dev_attr_ipv4_iface_bootproto.attr,
604 &dev_attr_ipv6_iface_ipaddress.attr,
605 &dev_attr_ipv6_iface_link_local_addr.attr,
606 &dev_attr_ipv6_iface_router_addr.attr,
607 &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
608 &dev_attr_ipv6_iface_link_local_autocfg.attr,
609 &dev_attr_iface_mtu.attr,
610 &dev_attr_iface_port.attr,
611 &dev_attr_iface_ipaddress_state.attr,
612 &dev_attr_iface_delayed_ack_en.attr,
613 &dev_attr_iface_tcp_nagle_disable.attr,
614 &dev_attr_iface_tcp_wsf_disable.attr,
615 &dev_attr_iface_tcp_wsf.attr,
616 &dev_attr_iface_tcp_timer_scale.attr,
617 &dev_attr_iface_tcp_timestamp_en.attr,
618 &dev_attr_iface_cache_id.attr,
619 &dev_attr_iface_redirect_en.attr,
620 &dev_attr_iface_def_taskmgmt_tmo.attr,
621 &dev_attr_iface_header_digest.attr,
622 &dev_attr_iface_data_digest.attr,
623 &dev_attr_iface_immediate_data.attr,
624 &dev_attr_iface_initial_r2t.attr,
625 &dev_attr_iface_data_seq_in_order.attr,
626 &dev_attr_iface_data_pdu_in_order.attr,
627 &dev_attr_iface_erl.attr,
628 &dev_attr_iface_max_recv_dlength.attr,
629 &dev_attr_iface_first_burst_len.attr,
630 &dev_attr_iface_max_outstanding_r2t.attr,
631 &dev_attr_iface_max_burst_len.attr,
632 &dev_attr_iface_chap_auth.attr,
633 &dev_attr_iface_bidi_chap.attr,
634 &dev_attr_iface_discovery_auth_optional.attr,
635 &dev_attr_iface_discovery_logout.attr,
636 &dev_attr_iface_strict_login_comp_en.attr,
637 &dev_attr_iface_initiator_name.attr,
638 &dev_attr_ipv4_iface_dhcp_dns_address_en.attr,
639 &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr,
640 &dev_attr_ipv4_iface_tos_en.attr,
641 &dev_attr_ipv4_iface_tos.attr,
642 &dev_attr_ipv4_iface_grat_arp_en.attr,
643 &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr,
644 &dev_attr_ipv4_iface_dhcp_alt_client_id.attr,
645 &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr,
646 &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr,
647 &dev_attr_ipv4_iface_dhcp_vendor_id.attr,
648 &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr,
649 &dev_attr_ipv4_iface_fragment_disable.attr,
650 &dev_attr_ipv4_iface_incoming_forwarding_en.attr,
651 &dev_attr_ipv4_iface_ttl.attr,
652 &dev_attr_ipv6_iface_link_local_state.attr,
653 &dev_attr_ipv6_iface_router_state.attr,
654 &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr,
655 &dev_attr_ipv6_iface_mld_en.attr,
656 &dev_attr_ipv6_iface_flow_label.attr,
657 &dev_attr_ipv6_iface_traffic_class.attr,
658 &dev_attr_ipv6_iface_hop_limit.attr,
659 &dev_attr_ipv6_iface_nd_reachable_tmo.attr,
660 &dev_attr_ipv6_iface_nd_rexmit_time.attr,
661 &dev_attr_ipv6_iface_nd_stale_tmo.attr,
662 &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr,
663 &dev_attr_ipv6_iface_router_adv_link_mtu.attr,
667 static struct attribute_group iscsi_iface_group = {
668 .attrs = iscsi_iface_attrs,
669 .is_visible = iscsi_iface_attr_is_visible,
672 /* convert iscsi_ipaddress_state values to ascii string name */
673 static const struct {
674 enum iscsi_ipaddress_state value;
676 } iscsi_ipaddress_state_names[] = {
677 {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" },
678 {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" },
679 {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" },
680 {ISCSI_IPDDRESS_STATE_VALID, "Valid" },
681 {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" },
682 {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" },
683 {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" },
686 char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state)
691 for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) {
692 if (iscsi_ipaddress_state_names[i].value == port_state) {
693 state = iscsi_ipaddress_state_names[i].name;
699 EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name);
701 /* convert iscsi_router_state values to ascii string name */
702 static const struct {
703 enum iscsi_router_state value;
705 } iscsi_router_state_names[] = {
706 {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" },
707 {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" },
708 {ISCSI_ROUTER_STATE_MANUAL, "Manual" },
709 {ISCSI_ROUTER_STATE_STALE, "Stale" },
712 char *iscsi_get_router_state_name(enum iscsi_router_state router_state)
717 for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) {
718 if (iscsi_router_state_names[i].value == router_state) {
719 state = iscsi_router_state_names[i].name;
725 EXPORT_SYMBOL_GPL(iscsi_get_router_state_name);
728 iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
729 uint32_t iface_type, uint32_t iface_num, int dd_size)
731 struct iscsi_iface *iface;
734 iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
738 iface->transport = transport;
739 iface->iface_type = iface_type;
740 iface->iface_num = iface_num;
741 iface->dev.release = iscsi_iface_release;
742 iface->dev.class = &iscsi_iface_class;
743 /* parent reference released in iscsi_iface_release */
744 iface->dev.parent = get_device(&shost->shost_gendev);
745 if (iface_type == ISCSI_IFACE_TYPE_IPV4)
746 dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
749 dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
752 err = device_register(&iface->dev);
756 err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
761 iface->dd_data = &iface[1];
765 device_unregister(&iface->dev);
769 put_device(iface->dev.parent);
773 EXPORT_SYMBOL_GPL(iscsi_create_iface);
775 void iscsi_destroy_iface(struct iscsi_iface *iface)
777 sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
778 device_unregister(&iface->dev);
780 EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
783 * Interface to display flash node params to sysfs
786 #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
787 struct device_attribute dev_attr_##_prefix##_##_name = \
788 __ATTR(_name, _mode, _show, _store)
790 /* flash node session attrs show */
791 #define iscsi_flashnode_sess_attr_show(type, name, param) \
793 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
796 struct iscsi_bus_flash_session *fnode_sess = \
797 iscsi_dev_to_flash_session(dev);\
798 struct iscsi_transport *t = fnode_sess->transport; \
799 return t->get_flashnode_param(fnode_sess, param, buf); \
803 #define iscsi_flashnode_sess_attr(type, name, param) \
804 iscsi_flashnode_sess_attr_show(type, name, param) \
805 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
806 show_##type##_##name, NULL);
808 /* Flash node session attributes */
810 iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable,
811 ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE);
812 iscsi_flashnode_sess_attr(fnode, discovery_session,
813 ISCSI_FLASHNODE_DISCOVERY_SESS);
814 iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE);
815 iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN);
816 iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN);
817 iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN);
818 iscsi_flashnode_sess_attr(fnode, data_seq_in_order,
819 ISCSI_FLASHNODE_DATASEQ_INORDER);
820 iscsi_flashnode_sess_attr(fnode, data_pdu_in_order,
821 ISCSI_FLASHNODE_PDU_INORDER);
822 iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN);
823 iscsi_flashnode_sess_attr(fnode, discovery_logout,
824 ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN);
825 iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN);
826 iscsi_flashnode_sess_attr(fnode, discovery_auth_optional,
827 ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL);
828 iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL);
829 iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST);
830 iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT);
831 iscsi_flashnode_sess_attr(fnode, def_time2retain,
832 ISCSI_FLASHNODE_DEF_TIME2RETAIN);
833 iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T);
834 iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID);
835 iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID);
836 iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST);
837 iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo,
838 ISCSI_FLASHNODE_DEF_TASKMGMT_TMO);
839 iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS);
840 iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME);
841 iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT);
842 iscsi_flashnode_sess_attr(fnode, discovery_parent_idx,
843 ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX);
844 iscsi_flashnode_sess_attr(fnode, discovery_parent_type,
845 ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE);
846 iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX);
847 iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX);
848 iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME);
849 iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN);
850 iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD);
851 iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN);
852 iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT);
854 static struct attribute *iscsi_flashnode_sess_attrs[] = {
855 &dev_attr_fnode_auto_snd_tgt_disable.attr,
856 &dev_attr_fnode_discovery_session.attr,
857 &dev_attr_fnode_portal_type.attr,
858 &dev_attr_fnode_entry_enable.attr,
859 &dev_attr_fnode_immediate_data.attr,
860 &dev_attr_fnode_initial_r2t.attr,
861 &dev_attr_fnode_data_seq_in_order.attr,
862 &dev_attr_fnode_data_pdu_in_order.attr,
863 &dev_attr_fnode_chap_auth.attr,
864 &dev_attr_fnode_discovery_logout.attr,
865 &dev_attr_fnode_bidi_chap.attr,
866 &dev_attr_fnode_discovery_auth_optional.attr,
867 &dev_attr_fnode_erl.attr,
868 &dev_attr_fnode_first_burst_len.attr,
869 &dev_attr_fnode_def_time2wait.attr,
870 &dev_attr_fnode_def_time2retain.attr,
871 &dev_attr_fnode_max_outstanding_r2t.attr,
872 &dev_attr_fnode_isid.attr,
873 &dev_attr_fnode_tsid.attr,
874 &dev_attr_fnode_max_burst_len.attr,
875 &dev_attr_fnode_def_taskmgmt_tmo.attr,
876 &dev_attr_fnode_targetalias.attr,
877 &dev_attr_fnode_targetname.attr,
878 &dev_attr_fnode_tpgt.attr,
879 &dev_attr_fnode_discovery_parent_idx.attr,
880 &dev_attr_fnode_discovery_parent_type.attr,
881 &dev_attr_fnode_chap_in_idx.attr,
882 &dev_attr_fnode_chap_out_idx.attr,
883 &dev_attr_fnode_username.attr,
884 &dev_attr_fnode_username_in.attr,
885 &dev_attr_fnode_password.attr,
886 &dev_attr_fnode_password_in.attr,
887 &dev_attr_fnode_is_boot_target.attr,
891 static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj,
892 struct attribute *attr,
895 struct device *dev = container_of(kobj, struct device, kobj);
896 struct iscsi_bus_flash_session *fnode_sess =
897 iscsi_dev_to_flash_session(dev);
898 struct iscsi_transport *t = fnode_sess->transport;
901 if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) {
902 param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE;
903 } else if (attr == &dev_attr_fnode_discovery_session.attr) {
904 param = ISCSI_FLASHNODE_DISCOVERY_SESS;
905 } else if (attr == &dev_attr_fnode_portal_type.attr) {
906 param = ISCSI_FLASHNODE_PORTAL_TYPE;
907 } else if (attr == &dev_attr_fnode_entry_enable.attr) {
908 param = ISCSI_FLASHNODE_ENTRY_EN;
909 } else if (attr == &dev_attr_fnode_immediate_data.attr) {
910 param = ISCSI_FLASHNODE_IMM_DATA_EN;
911 } else if (attr == &dev_attr_fnode_initial_r2t.attr) {
912 param = ISCSI_FLASHNODE_INITIAL_R2T_EN;
913 } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) {
914 param = ISCSI_FLASHNODE_DATASEQ_INORDER;
915 } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) {
916 param = ISCSI_FLASHNODE_PDU_INORDER;
917 } else if (attr == &dev_attr_fnode_chap_auth.attr) {
918 param = ISCSI_FLASHNODE_CHAP_AUTH_EN;
919 } else if (attr == &dev_attr_fnode_discovery_logout.attr) {
920 param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN;
921 } else if (attr == &dev_attr_fnode_bidi_chap.attr) {
922 param = ISCSI_FLASHNODE_BIDI_CHAP_EN;
923 } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) {
924 param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL;
925 } else if (attr == &dev_attr_fnode_erl.attr) {
926 param = ISCSI_FLASHNODE_ERL;
927 } else if (attr == &dev_attr_fnode_first_burst_len.attr) {
928 param = ISCSI_FLASHNODE_FIRST_BURST;
929 } else if (attr == &dev_attr_fnode_def_time2wait.attr) {
930 param = ISCSI_FLASHNODE_DEF_TIME2WAIT;
931 } else if (attr == &dev_attr_fnode_def_time2retain.attr) {
932 param = ISCSI_FLASHNODE_DEF_TIME2RETAIN;
933 } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) {
934 param = ISCSI_FLASHNODE_MAX_R2T;
935 } else if (attr == &dev_attr_fnode_isid.attr) {
936 param = ISCSI_FLASHNODE_ISID;
937 } else if (attr == &dev_attr_fnode_tsid.attr) {
938 param = ISCSI_FLASHNODE_TSID;
939 } else if (attr == &dev_attr_fnode_max_burst_len.attr) {
940 param = ISCSI_FLASHNODE_MAX_BURST;
941 } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) {
942 param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO;
943 } else if (attr == &dev_attr_fnode_targetalias.attr) {
944 param = ISCSI_FLASHNODE_ALIAS;
945 } else if (attr == &dev_attr_fnode_targetname.attr) {
946 param = ISCSI_FLASHNODE_NAME;
947 } else if (attr == &dev_attr_fnode_tpgt.attr) {
948 param = ISCSI_FLASHNODE_TPGT;
949 } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) {
950 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX;
951 } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) {
952 param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE;
953 } else if (attr == &dev_attr_fnode_chap_in_idx.attr) {
954 param = ISCSI_FLASHNODE_CHAP_IN_IDX;
955 } else if (attr == &dev_attr_fnode_chap_out_idx.attr) {
956 param = ISCSI_FLASHNODE_CHAP_OUT_IDX;
957 } else if (attr == &dev_attr_fnode_username.attr) {
958 param = ISCSI_FLASHNODE_USERNAME;
959 } else if (attr == &dev_attr_fnode_username_in.attr) {
960 param = ISCSI_FLASHNODE_USERNAME_IN;
961 } else if (attr == &dev_attr_fnode_password.attr) {
962 param = ISCSI_FLASHNODE_PASSWORD;
963 } else if (attr == &dev_attr_fnode_password_in.attr) {
964 param = ISCSI_FLASHNODE_PASSWORD_IN;
965 } else if (attr == &dev_attr_fnode_is_boot_target.attr) {
966 param = ISCSI_FLASHNODE_IS_BOOT_TGT;
968 WARN_ONCE(1, "Invalid flashnode session attr");
972 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
975 static struct attribute_group iscsi_flashnode_sess_attr_group = {
976 .attrs = iscsi_flashnode_sess_attrs,
977 .is_visible = iscsi_flashnode_sess_attr_is_visible,
980 static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = {
981 &iscsi_flashnode_sess_attr_group,
985 static void iscsi_flashnode_sess_release(struct device *dev)
987 struct iscsi_bus_flash_session *fnode_sess =
988 iscsi_dev_to_flash_session(dev);
990 kfree(fnode_sess->targetname);
991 kfree(fnode_sess->targetalias);
992 kfree(fnode_sess->portal_type);
996 struct device_type iscsi_flashnode_sess_dev_type = {
997 .name = "iscsi_flashnode_sess_dev_type",
998 .groups = iscsi_flashnode_sess_attr_groups,
999 .release = iscsi_flashnode_sess_release,
1002 /* flash node connection attrs show */
1003 #define iscsi_flashnode_conn_attr_show(type, name, param) \
1005 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
1008 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
1009 struct iscsi_bus_flash_session *fnode_sess = \
1010 iscsi_flash_conn_to_flash_session(fnode_conn);\
1011 struct iscsi_transport *t = fnode_conn->transport; \
1012 return t->get_flashnode_param(fnode_sess, param, buf); \
1016 #define iscsi_flashnode_conn_attr(type, name, param) \
1017 iscsi_flashnode_conn_attr_show(type, name, param) \
1018 static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
1019 show_##type##_##name, NULL);
1021 /* Flash node connection attributes */
1023 iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6,
1024 ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6);
1025 iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN);
1026 iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN);
1027 iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN);
1028 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat,
1029 ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT);
1030 iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable,
1031 ISCSI_FLASHNODE_TCP_NAGLE_DISABLE);
1032 iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable,
1033 ISCSI_FLASHNODE_TCP_WSF_DISABLE);
1034 iscsi_flashnode_conn_attr(fnode, tcp_timer_scale,
1035 ISCSI_FLASHNODE_TCP_TIMER_SCALE);
1036 iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable,
1037 ISCSI_FLASHNODE_TCP_TIMESTAMP_EN);
1038 iscsi_flashnode_conn_attr(fnode, fragment_disable,
1039 ISCSI_FLASHNODE_IP_FRAG_DISABLE);
1040 iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO);
1041 iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT);
1042 iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR);
1043 iscsi_flashnode_conn_attr(fnode, max_recv_dlength,
1044 ISCSI_FLASHNODE_MAX_RECV_DLENGTH);
1045 iscsi_flashnode_conn_attr(fnode, max_xmit_dlength,
1046 ISCSI_FLASHNODE_MAX_XMIT_DLENGTH);
1047 iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT);
1048 iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS);
1049 iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC);
1050 iscsi_flashnode_conn_attr(fnode, ipv6_flow_label,
1051 ISCSI_FLASHNODE_IPV6_FLOW_LABEL);
1052 iscsi_flashnode_conn_attr(fnode, redirect_ipaddr,
1053 ISCSI_FLASHNODE_REDIRECT_IPADDR);
1054 iscsi_flashnode_conn_attr(fnode, max_segment_size,
1055 ISCSI_FLASHNODE_MAX_SEGMENT_SIZE);
1056 iscsi_flashnode_conn_attr(fnode, link_local_ipv6,
1057 ISCSI_FLASHNODE_LINK_LOCAL_IPV6);
1058 iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF);
1059 iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF);
1060 iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN);
1061 iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN);
1063 static struct attribute *iscsi_flashnode_conn_attrs[] = {
1064 &dev_attr_fnode_is_fw_assigned_ipv6.attr,
1065 &dev_attr_fnode_header_digest.attr,
1066 &dev_attr_fnode_data_digest.attr,
1067 &dev_attr_fnode_snack_req.attr,
1068 &dev_attr_fnode_tcp_timestamp_stat.attr,
1069 &dev_attr_fnode_tcp_nagle_disable.attr,
1070 &dev_attr_fnode_tcp_wsf_disable.attr,
1071 &dev_attr_fnode_tcp_timer_scale.attr,
1072 &dev_attr_fnode_tcp_timestamp_enable.attr,
1073 &dev_attr_fnode_fragment_disable.attr,
1074 &dev_attr_fnode_max_recv_dlength.attr,
1075 &dev_attr_fnode_max_xmit_dlength.attr,
1076 &dev_attr_fnode_keepalive_tmo.attr,
1077 &dev_attr_fnode_port.attr,
1078 &dev_attr_fnode_ipaddress.attr,
1079 &dev_attr_fnode_redirect_ipaddr.attr,
1080 &dev_attr_fnode_max_segment_size.attr,
1081 &dev_attr_fnode_local_port.attr,
1082 &dev_attr_fnode_ipv4_tos.attr,
1083 &dev_attr_fnode_ipv6_traffic_class.attr,
1084 &dev_attr_fnode_ipv6_flow_label.attr,
1085 &dev_attr_fnode_link_local_ipv6.attr,
1086 &dev_attr_fnode_tcp_xmit_wsf.attr,
1087 &dev_attr_fnode_tcp_recv_wsf.attr,
1088 &dev_attr_fnode_statsn.attr,
1089 &dev_attr_fnode_exp_statsn.attr,
1093 static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj,
1094 struct attribute *attr,
1097 struct device *dev = container_of(kobj, struct device, kobj);
1098 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1099 struct iscsi_transport *t = fnode_conn->transport;
1102 if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) {
1103 param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6;
1104 } else if (attr == &dev_attr_fnode_header_digest.attr) {
1105 param = ISCSI_FLASHNODE_HDR_DGST_EN;
1106 } else if (attr == &dev_attr_fnode_data_digest.attr) {
1107 param = ISCSI_FLASHNODE_DATA_DGST_EN;
1108 } else if (attr == &dev_attr_fnode_snack_req.attr) {
1109 param = ISCSI_FLASHNODE_SNACK_REQ_EN;
1110 } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) {
1111 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT;
1112 } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) {
1113 param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE;
1114 } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) {
1115 param = ISCSI_FLASHNODE_TCP_WSF_DISABLE;
1116 } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) {
1117 param = ISCSI_FLASHNODE_TCP_TIMER_SCALE;
1118 } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) {
1119 param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN;
1120 } else if (attr == &dev_attr_fnode_fragment_disable.attr) {
1121 param = ISCSI_FLASHNODE_IP_FRAG_DISABLE;
1122 } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) {
1123 param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH;
1124 } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) {
1125 param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH;
1126 } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) {
1127 param = ISCSI_FLASHNODE_KEEPALIVE_TMO;
1128 } else if (attr == &dev_attr_fnode_port.attr) {
1129 param = ISCSI_FLASHNODE_PORT;
1130 } else if (attr == &dev_attr_fnode_ipaddress.attr) {
1131 param = ISCSI_FLASHNODE_IPADDR;
1132 } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) {
1133 param = ISCSI_FLASHNODE_REDIRECT_IPADDR;
1134 } else if (attr == &dev_attr_fnode_max_segment_size.attr) {
1135 param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE;
1136 } else if (attr == &dev_attr_fnode_local_port.attr) {
1137 param = ISCSI_FLASHNODE_LOCAL_PORT;
1138 } else if (attr == &dev_attr_fnode_ipv4_tos.attr) {
1139 param = ISCSI_FLASHNODE_IPV4_TOS;
1140 } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) {
1141 param = ISCSI_FLASHNODE_IPV6_TC;
1142 } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) {
1143 param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL;
1144 } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) {
1145 param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6;
1146 } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) {
1147 param = ISCSI_FLASHNODE_TCP_XMIT_WSF;
1148 } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) {
1149 param = ISCSI_FLASHNODE_TCP_RECV_WSF;
1150 } else if (attr == &dev_attr_fnode_statsn.attr) {
1151 param = ISCSI_FLASHNODE_STATSN;
1152 } else if (attr == &dev_attr_fnode_exp_statsn.attr) {
1153 param = ISCSI_FLASHNODE_EXP_STATSN;
1155 WARN_ONCE(1, "Invalid flashnode connection attr");
1159 return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
1162 static struct attribute_group iscsi_flashnode_conn_attr_group = {
1163 .attrs = iscsi_flashnode_conn_attrs,
1164 .is_visible = iscsi_flashnode_conn_attr_is_visible,
1167 static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = {
1168 &iscsi_flashnode_conn_attr_group,
1172 static void iscsi_flashnode_conn_release(struct device *dev)
1174 struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
1176 kfree(fnode_conn->ipaddress);
1177 kfree(fnode_conn->redirect_ipaddr);
1178 kfree(fnode_conn->link_local_ipv6_addr);
1182 struct device_type iscsi_flashnode_conn_dev_type = {
1183 .name = "iscsi_flashnode_conn_dev_type",
1184 .groups = iscsi_flashnode_conn_attr_groups,
1185 .release = iscsi_flashnode_conn_release,
1188 struct bus_type iscsi_flashnode_bus;
1190 int iscsi_flashnode_bus_match(struct device *dev,
1191 struct device_driver *drv)
1193 if (dev->bus == &iscsi_flashnode_bus)
1197 EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match);
1199 struct bus_type iscsi_flashnode_bus = {
1200 .name = "iscsi_flashnode",
1201 .match = &iscsi_flashnode_bus_match,
1205 * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
1206 * @shost: pointer to host data
1207 * @index: index of flashnode to add in sysfs
1208 * @transport: pointer to transport data
1209 * @dd_size: total size to allocate
1211 * Adds a sysfs entry for the flashnode session attributes
1214 * pointer to allocated flashnode sess on success
1217 struct iscsi_bus_flash_session *
1218 iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
1219 struct iscsi_transport *transport,
1222 struct iscsi_bus_flash_session *fnode_sess;
1225 fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL);
1229 fnode_sess->transport = transport;
1230 fnode_sess->target_id = index;
1231 fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type;
1232 fnode_sess->dev.bus = &iscsi_flashnode_bus;
1233 fnode_sess->dev.parent = &shost->shost_gendev;
1234 dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u",
1235 shost->host_no, index);
1237 err = device_register(&fnode_sess->dev);
1239 goto free_fnode_sess;
1242 fnode_sess->dd_data = &fnode_sess[1];
1250 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
1253 * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
1254 * @shost: pointer to host data
1255 * @fnode_sess: pointer to the parent flashnode session entry
1256 * @transport: pointer to transport data
1257 * @dd_size: total size to allocate
1259 * Adds a sysfs entry for the flashnode connection attributes
1262 * pointer to allocated flashnode conn on success
1265 struct iscsi_bus_flash_conn *
1266 iscsi_create_flashnode_conn(struct Scsi_Host *shost,
1267 struct iscsi_bus_flash_session *fnode_sess,
1268 struct iscsi_transport *transport,
1271 struct iscsi_bus_flash_conn *fnode_conn;
1274 fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL);
1278 fnode_conn->transport = transport;
1279 fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type;
1280 fnode_conn->dev.bus = &iscsi_flashnode_bus;
1281 fnode_conn->dev.parent = &fnode_sess->dev;
1282 dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0",
1283 shost->host_no, fnode_sess->target_id);
1285 err = device_register(&fnode_conn->dev);
1287 goto free_fnode_conn;
1290 fnode_conn->dd_data = &fnode_conn[1];
1298 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
1301 * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
1302 * @dev: device to verify
1303 * @data: pointer to data containing value to use for verification
1305 * Verifies if the passed device is flashnode conn device
1311 int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
1313 return dev->bus == &iscsi_flashnode_bus;
1315 EXPORT_SYMBOL_GPL(iscsi_is_flashnode_conn_dev);
1317 static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
1319 device_unregister(&fnode_conn->dev);
1323 static int flashnode_match_index(struct device *dev, void *data)
1325 struct iscsi_bus_flash_session *fnode_sess = NULL;
1328 if (!iscsi_flashnode_bus_match(dev, NULL))
1329 goto exit_match_index;
1331 fnode_sess = iscsi_dev_to_flash_session(dev);
1332 ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
1339 * iscsi_get_flashnode_by_index -finds flashnode session entry by index
1340 * @shost: pointer to host data
1341 * @idx: index to match
1343 * Finds the flashnode session object for the passed index
1346 * pointer to found flashnode session object on success
1349 static struct iscsi_bus_flash_session *
1350 iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
1352 struct iscsi_bus_flash_session *fnode_sess = NULL;
1355 dev = device_find_child(&shost->shost_gendev, &idx,
1356 flashnode_match_index);
1358 fnode_sess = iscsi_dev_to_flash_session(dev);
1364 * iscsi_find_flashnode_sess - finds flashnode session entry
1365 * @shost: pointer to host data
1366 * @data: pointer to data containing value to use for comparison
1367 * @fn: function pointer that does actual comparison
1369 * Finds the flashnode session object comparing the data passed using logic
1370 * defined in passed function pointer
1373 * pointer to found flashnode session device object on success
1377 iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
1378 int (*fn)(struct device *dev, void *data))
1380 return device_find_child(&shost->shost_gendev, data, fn);
1382 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
1385 * iscsi_find_flashnode_conn - finds flashnode connection entry
1386 * @fnode_sess: pointer to parent flashnode session entry
1388 * Finds the flashnode connection object comparing the data passed using logic
1389 * defined in passed function pointer
1392 * pointer to found flashnode connection device object on success
1396 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
1398 return device_find_child(&fnode_sess->dev, NULL,
1399 iscsi_is_flashnode_conn_dev);
1401 EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);
1403 static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data)
1405 if (!iscsi_is_flashnode_conn_dev(dev, NULL))
1408 return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev));
1412 * iscsi_destroy_flashnode_sess - destroy flashnode session entry
1413 * @fnode_sess: pointer to flashnode session entry to be destroyed
1415 * Deletes the flashnode session entry and all children flashnode connection
1416 * entries from sysfs
1418 void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess)
1422 err = device_for_each_child(&fnode_sess->dev, NULL,
1423 iscsi_iter_destroy_flashnode_conn_fn);
1425 pr_err("Could not delete all connections for %s. Error %d.\n",
1426 fnode_sess->dev.kobj.name, err);
1428 device_unregister(&fnode_sess->dev);
1430 EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);
1432 static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data)
1434 if (!iscsi_flashnode_bus_match(dev, NULL))
1437 iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev));
1442 * iscsi_destroy_all_flashnode - destroy all flashnode session entries
1443 * @shost: pointer to host data
1445 * Destroys all the flashnode session entries and all corresponding children
1446 * flashnode connection entries from sysfs
1448 void iscsi_destroy_all_flashnode(struct Scsi_Host *shost)
1450 device_for_each_child(&shost->shost_gendev, NULL,
1451 iscsi_iter_destroy_flashnode_fn);
1453 EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode);
1459 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
1460 * @job: bsg job to be processed
1462 static int iscsi_bsg_host_dispatch(struct bsg_job *job)
1464 struct Scsi_Host *shost = iscsi_job_to_shost(job);
1465 struct iscsi_bsg_request *req = job->request;
1466 struct iscsi_bsg_reply *reply = job->reply;
1467 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1468 int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
1471 /* check if we have the msgcode value at least */
1472 if (job->request_len < sizeof(uint32_t)) {
1477 /* Validate the host command */
1478 switch (req->msgcode) {
1479 case ISCSI_BSG_HST_VENDOR:
1480 cmdlen += sizeof(struct iscsi_bsg_host_vendor);
1481 if ((shost->hostt->vendor_id == 0L) ||
1482 (req->rqst_data.h_vendor.vendor_id !=
1483 shost->hostt->vendor_id)) {
1493 /* check if we really have all the request data needed */
1494 if (job->request_len < cmdlen) {
1499 ret = i->iscsi_transport->bsg_request(job);
1504 /* return the errno failure code as the only status */
1505 BUG_ON(job->reply_len < sizeof(uint32_t));
1506 reply->reply_payload_rcv_len = 0;
1507 reply->result = ret;
1508 job->reply_len = sizeof(uint32_t);
1509 bsg_job_done(job, ret, 0);
1514 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
1515 * @shost: shost for iscsi_host
1516 * @ihost: iscsi_cls_host adding the structures to
1519 iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
1521 struct device *dev = &shost->shost_gendev;
1522 struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1523 struct request_queue *q;
1527 if (!i->iscsi_transport->bsg_request)
1530 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1532 q = __scsi_alloc_queue(shost, bsg_request_fn);
1536 ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0);
1538 shost_printk(KERN_ERR, shost, "bsg interface failed to "
1539 "initialize - no request queue\n");
1540 blk_cleanup_queue(q);
1548 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
1549 struct device *cdev)
1551 struct Scsi_Host *shost = dev_to_shost(dev);
1552 struct iscsi_cls_host *ihost = shost->shost_data;
1554 memset(ihost, 0, sizeof(*ihost));
1555 atomic_set(&ihost->nr_scans, 0);
1556 mutex_init(&ihost->mutex);
1558 iscsi_bsg_host_add(shost, ihost);
1559 /* ignore any bsg add error - we just can't do sgio */
1564 static int iscsi_remove_host(struct transport_container *tc,
1565 struct device *dev, struct device *cdev)
1567 struct Scsi_Host *shost = dev_to_shost(dev);
1568 struct iscsi_cls_host *ihost = shost->shost_data;
1571 bsg_unregister_queue(ihost->bsg_q);
1572 blk_cleanup_queue(ihost->bsg_q);
1577 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
1583 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
1589 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
1595 static struct sock *nls;
1596 static DEFINE_MUTEX(rx_queue_mutex);
1598 static LIST_HEAD(sesslist);
1599 static DEFINE_SPINLOCK(sesslock);
1600 static LIST_HEAD(connlist);
1601 static DEFINE_SPINLOCK(connlock);
1603 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
1605 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
1610 * Returns the matching session to a given sid
1612 static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
1614 unsigned long flags;
1615 struct iscsi_cls_session *sess;
1617 spin_lock_irqsave(&sesslock, flags);
1618 list_for_each_entry(sess, &sesslist, sess_list) {
1619 if (sess->sid == sid) {
1620 spin_unlock_irqrestore(&sesslock, flags);
1624 spin_unlock_irqrestore(&sesslock, flags);
1629 * Returns the matching connection to a given sid / cid tuple
1631 static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
1633 unsigned long flags;
1634 struct iscsi_cls_conn *conn;
1636 spin_lock_irqsave(&connlock, flags);
1637 list_for_each_entry(conn, &connlist, conn_list) {
1638 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
1639 spin_unlock_irqrestore(&connlock, flags);
1643 spin_unlock_irqrestore(&connlock, flags);
1648 * The following functions can be used by LLDs that allocate
1649 * their own scsi_hosts or by software iscsi LLDs
1654 } iscsi_session_state_names[] = {
1655 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
1656 { ISCSI_SESSION_FAILED, "FAILED" },
1657 { ISCSI_SESSION_FREE, "FREE" },
1660 static const char *iscsi_session_state_name(int state)
1665 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
1666 if (iscsi_session_state_names[i].value == state) {
1667 name = iscsi_session_state_names[i].name;
1674 int iscsi_session_chkready(struct iscsi_cls_session *session)
1676 unsigned long flags;
1679 spin_lock_irqsave(&session->lock, flags);
1680 switch (session->state) {
1681 case ISCSI_SESSION_LOGGED_IN:
1684 case ISCSI_SESSION_FAILED:
1685 err = DID_IMM_RETRY << 16;
1687 case ISCSI_SESSION_FREE:
1688 err = DID_TRANSPORT_FAILFAST << 16;
1691 err = DID_NO_CONNECT << 16;
1694 spin_unlock_irqrestore(&session->lock, flags);
1697 EXPORT_SYMBOL_GPL(iscsi_session_chkready);
1699 int iscsi_is_session_online(struct iscsi_cls_session *session)
1701 unsigned long flags;
1704 spin_lock_irqsave(&session->lock, flags);
1705 if (session->state == ISCSI_SESSION_LOGGED_IN)
1707 spin_unlock_irqrestore(&session->lock, flags);
1710 EXPORT_SYMBOL_GPL(iscsi_is_session_online);
1712 static void iscsi_session_release(struct device *dev)
1714 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
1715 struct Scsi_Host *shost;
1717 shost = iscsi_session_to_shost(session);
1718 scsi_host_put(shost);
1719 ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
1723 int iscsi_is_session_dev(const struct device *dev)
1725 return dev->release == iscsi_session_release;
1727 EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
1729 static int iscsi_iter_session_fn(struct device *dev, void *data)
1731 void (* fn) (struct iscsi_cls_session *) = data;
1733 if (!iscsi_is_session_dev(dev))
1735 fn(iscsi_dev_to_session(dev));
1739 void iscsi_host_for_each_session(struct Scsi_Host *shost,
1740 void (*fn)(struct iscsi_cls_session *))
1742 device_for_each_child(&shost->shost_gendev, fn,
1743 iscsi_iter_session_fn);
1745 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
1748 * iscsi_scan_finished - helper to report when running scans are done
1750 * @time: scan run time
1752 * This function can be used by drives like qla4xxx to report to the scsi
1753 * layer when the scans it kicked off at module load time are done.
1755 int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
1757 struct iscsi_cls_host *ihost = shost->shost_data;
1759 * qla4xxx will have kicked off some session unblocks before calling
1760 * scsi_scan_host, so just wait for them to complete.
1762 return !atomic_read(&ihost->nr_scans);
1764 EXPORT_SYMBOL_GPL(iscsi_scan_finished);
1766 struct iscsi_scan_data {
1767 unsigned int channel;
1772 static int iscsi_user_scan_session(struct device *dev, void *data)
1774 struct iscsi_scan_data *scan_data = data;
1775 struct iscsi_cls_session *session;
1776 struct Scsi_Host *shost;
1777 struct iscsi_cls_host *ihost;
1778 unsigned long flags;
1781 if (!iscsi_is_session_dev(dev))
1784 session = iscsi_dev_to_session(dev);
1786 ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
1788 shost = iscsi_session_to_shost(session);
1789 ihost = shost->shost_data;
1791 mutex_lock(&ihost->mutex);
1792 spin_lock_irqsave(&session->lock, flags);
1793 if (session->state != ISCSI_SESSION_LOGGED_IN) {
1794 spin_unlock_irqrestore(&session->lock, flags);
1795 goto user_scan_exit;
1797 id = session->target_id;
1798 spin_unlock_irqrestore(&session->lock, flags);
1800 if (id != ISCSI_MAX_TARGET) {
1801 if ((scan_data->channel == SCAN_WILD_CARD ||
1802 scan_data->channel == 0) &&
1803 (scan_data->id == SCAN_WILD_CARD ||
1804 scan_data->id == id))
1805 scsi_scan_target(&session->dev, 0, id,
1810 mutex_unlock(&ihost->mutex);
1811 ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
1815 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
1818 struct iscsi_scan_data scan_data;
1820 scan_data.channel = channel;
1822 scan_data.lun = lun;
1824 return device_for_each_child(&shost->shost_gendev, &scan_data,
1825 iscsi_user_scan_session);
1828 static void iscsi_scan_session(struct work_struct *work)
1830 struct iscsi_cls_session *session =
1831 container_of(work, struct iscsi_cls_session, scan_work);
1832 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1833 struct iscsi_cls_host *ihost = shost->shost_data;
1834 struct iscsi_scan_data scan_data;
1836 scan_data.channel = 0;
1837 scan_data.id = SCAN_WILD_CARD;
1838 scan_data.lun = SCAN_WILD_CARD;
1840 iscsi_user_scan_session(&session->dev, &scan_data);
1841 atomic_dec(&ihost->nr_scans);
1845 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
1846 * @cmd: scsi cmd passed to scsi eh handler
1848 * If the session is down this function will wait for the recovery
1849 * timer to fire or for the session to be logged back in. If the
1850 * recovery timer fires then FAST_IO_FAIL is returned. The caller
1851 * should pass this error value to the scsi eh.
1853 int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
1855 struct iscsi_cls_session *session =
1856 starget_to_session(scsi_target(cmd->device));
1857 unsigned long flags;
1860 spin_lock_irqsave(&session->lock, flags);
1861 while (session->state != ISCSI_SESSION_LOGGED_IN) {
1862 if (session->state == ISCSI_SESSION_FREE) {
1866 spin_unlock_irqrestore(&session->lock, flags);
1868 spin_lock_irqsave(&session->lock, flags);
1870 spin_unlock_irqrestore(&session->lock, flags);
1873 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
1875 static void session_recovery_timedout(struct work_struct *work)
1877 struct iscsi_cls_session *session =
1878 container_of(work, struct iscsi_cls_session,
1879 recovery_work.work);
1880 unsigned long flags;
1882 iscsi_cls_session_printk(KERN_INFO, session,
1883 "session recovery timed out after %d secs\n",
1884 session->recovery_tmo);
1886 spin_lock_irqsave(&session->lock, flags);
1887 switch (session->state) {
1888 case ISCSI_SESSION_FAILED:
1889 session->state = ISCSI_SESSION_FREE;
1891 case ISCSI_SESSION_LOGGED_IN:
1892 case ISCSI_SESSION_FREE:
1893 /* we raced with the unblock's flush */
1894 spin_unlock_irqrestore(&session->lock, flags);
1897 spin_unlock_irqrestore(&session->lock, flags);
1899 if (session->transport->session_recovery_timedout)
1900 session->transport->session_recovery_timedout(session);
1902 ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
1903 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
1904 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
1907 static void __iscsi_unblock_session(struct work_struct *work)
1909 struct iscsi_cls_session *session =
1910 container_of(work, struct iscsi_cls_session,
1912 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1913 struct iscsi_cls_host *ihost = shost->shost_data;
1914 unsigned long flags;
1916 ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
1918 * The recovery and unblock work get run from the same workqueue,
1919 * so try to cancel it if it was going to run after this unblock.
1921 cancel_delayed_work(&session->recovery_work);
1922 spin_lock_irqsave(&session->lock, flags);
1923 session->state = ISCSI_SESSION_LOGGED_IN;
1924 spin_unlock_irqrestore(&session->lock, flags);
1926 scsi_target_unblock(&session->dev, SDEV_RUNNING);
1928 * Only do kernel scanning if the driver is properly hooked into
1929 * the async scanning code (drivers like iscsi_tcp do login and
1930 * scanning from userspace).
1932 if (shost->hostt->scan_finished) {
1933 if (scsi_queue_work(shost, &session->scan_work))
1934 atomic_inc(&ihost->nr_scans);
1936 ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
1940 * iscsi_unblock_session - set a session as logged in and start IO.
1941 * @session: iscsi session
1943 * Mark a session as ready to accept IO.
1945 void iscsi_unblock_session(struct iscsi_cls_session *session)
1947 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
1949 * make sure all the events have completed before tell the driver
1952 flush_workqueue(iscsi_eh_timer_workq);
1954 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
1956 static void __iscsi_block_session(struct work_struct *work)
1958 struct iscsi_cls_session *session =
1959 container_of(work, struct iscsi_cls_session,
1961 unsigned long flags;
1963 ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
1964 spin_lock_irqsave(&session->lock, flags);
1965 session->state = ISCSI_SESSION_FAILED;
1966 spin_unlock_irqrestore(&session->lock, flags);
1967 scsi_target_block(&session->dev);
1968 ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
1969 if (session->recovery_tmo >= 0)
1970 queue_delayed_work(iscsi_eh_timer_workq,
1971 &session->recovery_work,
1972 session->recovery_tmo * HZ);
1975 void iscsi_block_session(struct iscsi_cls_session *session)
1977 queue_work(iscsi_eh_timer_workq, &session->block_work);
1979 EXPORT_SYMBOL_GPL(iscsi_block_session);
1981 static void __iscsi_unbind_session(struct work_struct *work)
1983 struct iscsi_cls_session *session =
1984 container_of(work, struct iscsi_cls_session,
1986 struct Scsi_Host *shost = iscsi_session_to_shost(session);
1987 struct iscsi_cls_host *ihost = shost->shost_data;
1988 unsigned long flags;
1989 unsigned int target_id;
1991 ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
1993 /* Prevent new scans and make sure scanning is not in progress */
1994 mutex_lock(&ihost->mutex);
1995 spin_lock_irqsave(&session->lock, flags);
1996 if (session->target_id == ISCSI_MAX_TARGET) {
1997 spin_unlock_irqrestore(&session->lock, flags);
1998 mutex_unlock(&ihost->mutex);
1999 goto unbind_session_exit;
2002 target_id = session->target_id;
2003 session->target_id = ISCSI_MAX_TARGET;
2004 spin_unlock_irqrestore(&session->lock, flags);
2005 mutex_unlock(&ihost->mutex);
2007 if (session->ida_used)
2008 ida_simple_remove(&iscsi_sess_ida, target_id);
2010 scsi_remove_target(&session->dev);
2012 unbind_session_exit:
2013 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
2014 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
2017 struct iscsi_cls_session *
2018 iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2021 struct iscsi_cls_session *session;
2023 session = kzalloc(sizeof(*session) + dd_size,
2028 session->transport = transport;
2029 session->creator = -1;
2030 session->recovery_tmo = 120;
2031 session->recovery_tmo_sysfs_override = false;
2032 session->state = ISCSI_SESSION_FREE;
2033 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
2034 INIT_LIST_HEAD(&session->sess_list);
2035 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
2036 INIT_WORK(&session->block_work, __iscsi_block_session);
2037 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
2038 INIT_WORK(&session->scan_work, iscsi_scan_session);
2039 spin_lock_init(&session->lock);
2041 /* this is released in the dev's release function */
2042 scsi_host_get(shost);
2043 session->dev.parent = &shost->shost_gendev;
2044 session->dev.release = iscsi_session_release;
2045 device_initialize(&session->dev);
2047 session->dd_data = &session[1];
2049 ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
2052 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
2054 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
2056 struct Scsi_Host *shost = iscsi_session_to_shost(session);
2057 struct iscsi_cls_host *ihost;
2058 unsigned long flags;
2062 ihost = shost->shost_data;
2063 session->sid = atomic_add_return(1, &iscsi_session_nr);
2065 if (target_id == ISCSI_MAX_TARGET) {
2066 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
2069 iscsi_cls_session_printk(KERN_ERR, session,
2070 "Failure in Target ID Allocation\n");
2073 session->target_id = (unsigned int)id;
2074 session->ida_used = true;
2076 session->target_id = target_id;
2078 dev_set_name(&session->dev, "session%u", session->sid);
2079 err = device_add(&session->dev);
2081 iscsi_cls_session_printk(KERN_ERR, session,
2082 "could not register session's dev\n");
2085 transport_register_device(&session->dev);
2087 spin_lock_irqsave(&sesslock, flags);
2088 list_add(&session->sess_list, &sesslist);
2089 spin_unlock_irqrestore(&sesslock, flags);
2091 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
2092 ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
2096 if (session->ida_used)
2097 ida_simple_remove(&iscsi_sess_ida, session->target_id);
2101 EXPORT_SYMBOL_GPL(iscsi_add_session);
2104 * iscsi_create_session - create iscsi class session
2106 * @transport: iscsi transport
2107 * @dd_size: private driver data size
2108 * @target_id: which target
2110 * This can be called from a LLD or iscsi_transport.
2112 struct iscsi_cls_session *
2113 iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
2114 int dd_size, unsigned int target_id)
2116 struct iscsi_cls_session *session;
2118 session = iscsi_alloc_session(shost, transport, dd_size);
2122 if (iscsi_add_session(session, target_id)) {
2123 iscsi_free_session(session);
2128 EXPORT_SYMBOL_GPL(iscsi_create_session);
2130 static void iscsi_conn_release(struct device *dev)
2132 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
2133 struct device *parent = conn->dev.parent;
2135 ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
2140 static int iscsi_is_conn_dev(const struct device *dev)
2142 return dev->release == iscsi_conn_release;
2145 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
2147 if (!iscsi_is_conn_dev(dev))
2149 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
2152 void iscsi_remove_session(struct iscsi_cls_session *session)
2154 struct Scsi_Host *shost = iscsi_session_to_shost(session);
2155 unsigned long flags;
2158 ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
2160 spin_lock_irqsave(&sesslock, flags);
2161 list_del(&session->sess_list);
2162 spin_unlock_irqrestore(&sesslock, flags);
2164 /* make sure there are no blocks/unblocks queued */
2165 flush_workqueue(iscsi_eh_timer_workq);
2166 /* make sure the timedout callout is not running */
2167 if (!cancel_delayed_work(&session->recovery_work))
2168 flush_workqueue(iscsi_eh_timer_workq);
2170 * If we are blocked let commands flow again. The lld or iscsi
2171 * layer should set up the queuecommand to fail commands.
2172 * We assume that LLD will not be calling block/unblock while
2173 * removing the session.
2175 spin_lock_irqsave(&session->lock, flags);
2176 session->state = ISCSI_SESSION_FREE;
2177 spin_unlock_irqrestore(&session->lock, flags);
2179 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2180 /* flush running scans then delete devices */
2181 scsi_flush_work(shost);
2182 __iscsi_unbind_session(&session->unbind_work);
2184 /* hw iscsi may not have removed all connections from session */
2185 err = device_for_each_child(&session->dev, NULL,
2186 iscsi_iter_destroy_conn_fn);
2188 iscsi_cls_session_printk(KERN_ERR, session,
2189 "Could not delete all connections "
2190 "for session. Error %d.\n", err);
2192 transport_unregister_device(&session->dev);
2194 ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
2195 device_del(&session->dev);
2197 EXPORT_SYMBOL_GPL(iscsi_remove_session);
2199 void iscsi_free_session(struct iscsi_cls_session *session)
2201 ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
2202 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
2203 put_device(&session->dev);
2205 EXPORT_SYMBOL_GPL(iscsi_free_session);
2208 * iscsi_destroy_session - destroy iscsi session
2209 * @session: iscsi_session
2211 * Can be called by a LLD or iscsi_transport. There must not be
2212 * any running connections.
2214 int iscsi_destroy_session(struct iscsi_cls_session *session)
2216 iscsi_remove_session(session);
2217 ISCSI_DBG_TRANS_SESSION(session, "Completing session destruction\n");
2218 iscsi_free_session(session);
2221 EXPORT_SYMBOL_GPL(iscsi_destroy_session);
2224 * iscsi_create_conn - create iscsi class connection
2225 * @session: iscsi cls session
2226 * @dd_size: private driver data size
2227 * @cid: connection id
2229 * This can be called from a LLD or iscsi_transport. The connection
2230 * is child of the session so cid must be unique for all connections
2233 * Since we do not support MCS, cid will normally be zero. In some cases
2234 * for software iscsi we could be trying to preallocate a connection struct
2235 * in which case there could be two connection structs and cid would be
2238 struct iscsi_cls_conn *
2239 iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
2241 struct iscsi_transport *transport = session->transport;
2242 struct iscsi_cls_conn *conn;
2243 unsigned long flags;
2246 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
2250 conn->dd_data = &conn[1];
2252 mutex_init(&conn->ep_mutex);
2253 INIT_LIST_HEAD(&conn->conn_list);
2254 conn->transport = transport;
2257 /* this is released in the dev's release function */
2258 if (!get_device(&session->dev))
2261 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
2262 conn->dev.parent = &session->dev;
2263 conn->dev.release = iscsi_conn_release;
2264 err = device_register(&conn->dev);
2266 iscsi_cls_session_printk(KERN_ERR, session, "could not "
2267 "register connection's dev\n");
2268 goto release_parent_ref;
2270 transport_register_device(&conn->dev);
2272 spin_lock_irqsave(&connlock, flags);
2273 list_add(&conn->conn_list, &connlist);
2274 spin_unlock_irqrestore(&connlock, flags);
2276 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
2280 put_device(&session->dev);
2286 EXPORT_SYMBOL_GPL(iscsi_create_conn);
2289 * iscsi_destroy_conn - destroy iscsi class connection
2290 * @conn: iscsi cls session
2292 * This can be called from a LLD or iscsi_transport.
2294 int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
2296 unsigned long flags;
2298 spin_lock_irqsave(&connlock, flags);
2299 list_del(&conn->conn_list);
2300 spin_unlock_irqrestore(&connlock, flags);
2302 transport_unregister_device(&conn->dev);
2303 ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n");
2304 device_unregister(&conn->dev);
2307 EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
2309 void iscsi_put_conn(struct iscsi_cls_conn *conn)
2311 put_device(&conn->dev);
2313 EXPORT_SYMBOL_GPL(iscsi_put_conn);
2315 void iscsi_get_conn(struct iscsi_cls_conn *conn)
2317 get_device(&conn->dev);
2319 EXPORT_SYMBOL_GPL(iscsi_get_conn);
2322 * iscsi interface functions
2324 static struct iscsi_internal *
2325 iscsi_if_transport_lookup(struct iscsi_transport *tt)
2327 struct iscsi_internal *priv;
2328 unsigned long flags;
2330 spin_lock_irqsave(&iscsi_transport_lock, flags);
2331 list_for_each_entry(priv, &iscsi_transports, list) {
2332 if (tt == priv->iscsi_transport) {
2333 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2337 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
2342 iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
2344 return nlmsg_multicast(nls, skb, 0, group, gfp);
2347 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
2348 char *data, uint32_t data_size)
2350 struct nlmsghdr *nlh;
2351 struct sk_buff *skb;
2352 struct iscsi_uevent *ev;
2354 struct iscsi_internal *priv;
2355 int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
2358 priv = iscsi_if_transport_lookup(conn->transport);
2362 skb = alloc_skb(len, GFP_ATOMIC);
2364 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
2365 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
2366 "control PDU: OOM\n");
2370 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2371 ev = nlmsg_data(nlh);
2372 memset(ev, 0, sizeof(*ev));
2373 ev->transport_handle = iscsi_handle(conn->transport);
2374 ev->type = ISCSI_KEVENT_RECV_PDU;
2375 ev->r.recv_req.cid = conn->cid;
2376 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
2377 pdu = (char*)ev + sizeof(*ev);
2378 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
2379 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
2381 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2383 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
2385 int iscsi_offload_mesg(struct Scsi_Host *shost,
2386 struct iscsi_transport *transport, uint32_t type,
2387 char *data, uint16_t data_size)
2389 struct nlmsghdr *nlh;
2390 struct sk_buff *skb;
2391 struct iscsi_uevent *ev;
2392 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2394 skb = alloc_skb(len, GFP_ATOMIC);
2396 printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
2400 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2401 ev = nlmsg_data(nlh);
2402 memset(ev, 0, sizeof(*ev));
2404 ev->transport_handle = iscsi_handle(transport);
2406 case ISCSI_KEVENT_PATH_REQ:
2407 ev->r.req_path.host_no = shost->host_no;
2409 case ISCSI_KEVENT_IF_DOWN:
2410 ev->r.notify_if_down.host_no = shost->host_no;
2414 memcpy((char *)ev + sizeof(*ev), data, data_size);
2416 return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
2418 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
2420 void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
2422 struct nlmsghdr *nlh;
2423 struct sk_buff *skb;
2424 struct iscsi_uevent *ev;
2425 struct iscsi_internal *priv;
2426 int len = nlmsg_total_size(sizeof(*ev));
2428 priv = iscsi_if_transport_lookup(conn->transport);
2432 skb = alloc_skb(len, GFP_ATOMIC);
2434 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2435 "conn error (%d)\n", error);
2439 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2440 ev = nlmsg_data(nlh);
2441 ev->transport_handle = iscsi_handle(conn->transport);
2442 ev->type = ISCSI_KEVENT_CONN_ERROR;
2443 ev->r.connerror.error = error;
2444 ev->r.connerror.cid = conn->cid;
2445 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
2447 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2449 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
2452 EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
2454 void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
2455 enum iscsi_conn_state state)
2457 struct nlmsghdr *nlh;
2458 struct sk_buff *skb;
2459 struct iscsi_uevent *ev;
2460 struct iscsi_internal *priv;
2461 int len = nlmsg_total_size(sizeof(*ev));
2463 priv = iscsi_if_transport_lookup(conn->transport);
2467 skb = alloc_skb(len, GFP_ATOMIC);
2469 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
2470 "conn login (%d)\n", state);
2474 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2475 ev = nlmsg_data(nlh);
2476 ev->transport_handle = iscsi_handle(conn->transport);
2477 ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
2478 ev->r.conn_login.state = state;
2479 ev->r.conn_login.cid = conn->cid;
2480 ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
2481 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
2483 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
2486 EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
2488 void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
2489 enum iscsi_host_event_code code, uint32_t data_size,
2492 struct nlmsghdr *nlh;
2493 struct sk_buff *skb;
2494 struct iscsi_uevent *ev;
2495 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2497 skb = alloc_skb(len, GFP_NOIO);
2499 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
2504 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2505 ev = nlmsg_data(nlh);
2506 ev->transport_handle = iscsi_handle(transport);
2507 ev->type = ISCSI_KEVENT_HOST_EVENT;
2508 ev->r.host_event.host_no = host_no;
2509 ev->r.host_event.code = code;
2510 ev->r.host_event.data_size = data_size;
2513 memcpy((char *)ev + sizeof(*ev), data, data_size);
2515 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2517 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
2519 void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
2520 uint32_t status, uint32_t pid, uint32_t data_size,
2523 struct nlmsghdr *nlh;
2524 struct sk_buff *skb;
2525 struct iscsi_uevent *ev;
2526 int len = nlmsg_total_size(sizeof(*ev) + data_size);
2528 skb = alloc_skb(len, GFP_NOIO);
2530 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
2534 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2535 ev = nlmsg_data(nlh);
2536 ev->transport_handle = iscsi_handle(transport);
2537 ev->type = ISCSI_KEVENT_PING_COMP;
2538 ev->r.ping_comp.host_no = host_no;
2539 ev->r.ping_comp.status = status;
2540 ev->r.ping_comp.pid = pid;
2541 ev->r.ping_comp.data_size = data_size;
2542 memcpy((char *)ev + sizeof(*ev), data, data_size);
2544 iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
2546 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
2549 iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi,
2550 void *payload, int size)
2552 struct sk_buff *skb;
2553 struct nlmsghdr *nlh;
2554 int len = nlmsg_total_size(size);
2555 int flags = multi ? NLM_F_MULTI : 0;
2556 int t = done ? NLMSG_DONE : type;
2558 skb = alloc_skb(len, GFP_ATOMIC);
2560 printk(KERN_ERR "Could not allocate skb to send reply.\n");
2564 nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0);
2565 nlh->nlmsg_flags = flags;
2566 memcpy(nlmsg_data(nlh), payload, size);
2567 return iscsi_multicast_skb(skb, group, GFP_ATOMIC);
2571 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
2573 struct iscsi_uevent *ev = nlmsg_data(nlh);
2574 struct iscsi_stats *stats;
2575 struct sk_buff *skbstat;
2576 struct iscsi_cls_conn *conn;
2577 struct nlmsghdr *nlhstat;
2578 struct iscsi_uevent *evstat;
2579 struct iscsi_internal *priv;
2580 int len = nlmsg_total_size(sizeof(*ev) +
2581 sizeof(struct iscsi_stats) +
2582 sizeof(struct iscsi_stats_custom) *
2583 ISCSI_STATS_CUSTOM_MAX);
2586 priv = iscsi_if_transport_lookup(transport);
2590 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
2597 skbstat = alloc_skb(len, GFP_ATOMIC);
2599 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
2600 "deliver stats: OOM\n");
2604 nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
2605 (len - sizeof(*nlhstat)), 0);
2606 evstat = nlmsg_data(nlhstat);
2607 memset(evstat, 0, sizeof(*evstat));
2608 evstat->transport_handle = iscsi_handle(conn->transport);
2609 evstat->type = nlh->nlmsg_type;
2610 evstat->u.get_stats.cid =
2611 ev->u.get_stats.cid;
2612 evstat->u.get_stats.sid =
2613 ev->u.get_stats.sid;
2614 stats = (struct iscsi_stats *)
2615 ((char*)evstat + sizeof(*evstat));
2616 memset(stats, 0, sizeof(*stats));
2618 transport->get_stats(conn, stats);
2619 actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
2620 sizeof(struct iscsi_stats) +
2621 sizeof(struct iscsi_stats_custom) *
2622 stats->custom_length);
2623 actual_size -= sizeof(*nlhstat);
2624 actual_size = nlmsg_msg_size(actual_size);
2625 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
2626 nlhstat->nlmsg_len = actual_size;
2628 err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
2630 } while (err < 0 && err != -ECONNREFUSED);
2636 * iscsi_session_event - send session destr. completion event
2637 * @session: iscsi class session
2638 * @event: type of event
2640 int iscsi_session_event(struct iscsi_cls_session *session,
2641 enum iscsi_uevent_e event)
2643 struct iscsi_internal *priv;
2644 struct Scsi_Host *shost;
2645 struct iscsi_uevent *ev;
2646 struct sk_buff *skb;
2647 struct nlmsghdr *nlh;
2648 int rc, len = nlmsg_total_size(sizeof(*ev));
2650 priv = iscsi_if_transport_lookup(session->transport);
2653 shost = iscsi_session_to_shost(session);
2655 skb = alloc_skb(len, GFP_KERNEL);
2657 iscsi_cls_session_printk(KERN_ERR, session,
2658 "Cannot notify userspace of session "
2659 "event %u\n", event);
2663 nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
2664 ev = nlmsg_data(nlh);
2665 ev->transport_handle = iscsi_handle(session->transport);
2669 case ISCSI_KEVENT_DESTROY_SESSION:
2670 ev->r.d_session.host_no = shost->host_no;
2671 ev->r.d_session.sid = session->sid;
2673 case ISCSI_KEVENT_CREATE_SESSION:
2674 ev->r.c_session_ret.host_no = shost->host_no;
2675 ev->r.c_session_ret.sid = session->sid;
2677 case ISCSI_KEVENT_UNBIND_SESSION:
2678 ev->r.unbind_session.host_no = shost->host_no;
2679 ev->r.unbind_session.sid = session->sid;
2682 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
2689 * this will occur if the daemon is not up, so we just warn
2690 * the user and when the daemon is restarted it will handle it
2692 rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
2694 iscsi_cls_session_printk(KERN_ERR, session,
2695 "Cannot notify userspace of session "
2696 "event %u. Check iscsi daemon\n",
2699 ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
2703 EXPORT_SYMBOL_GPL(iscsi_session_event);
2706 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
2707 struct iscsi_uevent *ev, pid_t pid,
2708 uint32_t initial_cmdsn, uint16_t cmds_max,
2709 uint16_t queue_depth)
2711 struct iscsi_transport *transport = priv->iscsi_transport;
2712 struct iscsi_cls_session *session;
2713 struct Scsi_Host *shost;
2715 session = transport->create_session(ep, cmds_max, queue_depth,
2720 session->creator = pid;
2721 shost = iscsi_session_to_shost(session);
2722 ev->r.c_session_ret.host_no = shost->host_no;
2723 ev->r.c_session_ret.sid = session->sid;
2724 ISCSI_DBG_TRANS_SESSION(session,
2725 "Completed creating transport session\n");
2730 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2732 struct iscsi_cls_conn *conn;
2733 struct iscsi_cls_session *session;
2735 session = iscsi_session_lookup(ev->u.c_conn.sid);
2737 printk(KERN_ERR "iscsi: invalid session %d.\n",
2742 conn = transport->create_conn(session, ev->u.c_conn.cid);
2744 iscsi_cls_session_printk(KERN_ERR, session,
2745 "couldn't create a new connection.");
2749 ev->r.c_conn_ret.sid = session->sid;
2750 ev->r.c_conn_ret.cid = conn->cid;
2752 ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
2757 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2759 struct iscsi_cls_conn *conn;
2761 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
2765 ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
2766 if (transport->destroy_conn)
2767 transport->destroy_conn(conn);
2773 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2775 char *data = (char*)ev + sizeof(*ev);
2776 struct iscsi_cls_conn *conn;
2777 struct iscsi_cls_session *session;
2778 int err = 0, value = 0;
2780 if (ev->u.set_param.len > PAGE_SIZE)
2783 session = iscsi_session_lookup(ev->u.set_param.sid);
2784 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
2785 if (!conn || !session)
2788 switch (ev->u.set_param.param) {
2789 case ISCSI_PARAM_SESS_RECOVERY_TMO:
2790 sscanf(data, "%d", &value);
2791 if (!session->recovery_tmo_sysfs_override)
2792 session->recovery_tmo = value;
2795 err = transport->set_param(conn, ev->u.set_param.param,
2796 data, ev->u.set_param.len);
2802 static int iscsi_if_ep_connect(struct iscsi_transport *transport,
2803 struct iscsi_uevent *ev, int msg_type)
2805 struct iscsi_endpoint *ep;
2806 struct sockaddr *dst_addr;
2807 struct Scsi_Host *shost = NULL;
2808 int non_blocking, err = 0;
2810 if (!transport->ep_connect)
2813 if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
2814 shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
2816 printk(KERN_ERR "ep connect failed. Could not find "
2818 ev->u.ep_connect_through_host.host_no);
2821 non_blocking = ev->u.ep_connect_through_host.non_blocking;
2823 non_blocking = ev->u.ep_connect.non_blocking;
2825 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
2826 ep = transport->ep_connect(shost, dst_addr, non_blocking);
2832 ev->r.ep_connect_ret.handle = ep->id;
2835 scsi_host_put(shost);
2839 static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
2842 struct iscsi_cls_conn *conn;
2843 struct iscsi_endpoint *ep;
2845 if (!transport->ep_disconnect)
2848 ep = iscsi_lookup_endpoint(ep_handle);
2853 mutex_lock(&conn->ep_mutex);
2855 mutex_unlock(&conn->ep_mutex);
2858 transport->ep_disconnect(ep);
2863 iscsi_if_transport_ep(struct iscsi_transport *transport,
2864 struct iscsi_uevent *ev, int msg_type)
2866 struct iscsi_endpoint *ep;
2870 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
2871 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
2872 rc = iscsi_if_ep_connect(transport, ev, msg_type);
2874 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
2875 if (!transport->ep_poll)
2878 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
2882 ev->r.retcode = transport->ep_poll(ep,
2883 ev->u.ep_poll.timeout_ms);
2885 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
2886 rc = iscsi_if_ep_disconnect(transport,
2887 ev->u.ep_disconnect.ep_handle);
2894 iscsi_tgt_dscvr(struct iscsi_transport *transport,
2895 struct iscsi_uevent *ev)
2897 struct Scsi_Host *shost;
2898 struct sockaddr *dst_addr;
2901 if (!transport->tgt_dscvr)
2904 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
2906 printk(KERN_ERR "target discovery could not find host no %u\n",
2907 ev->u.tgt_dscvr.host_no);
2912 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
2913 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
2914 ev->u.tgt_dscvr.enable, dst_addr);
2915 scsi_host_put(shost);
2920 iscsi_set_host_param(struct iscsi_transport *transport,
2921 struct iscsi_uevent *ev)
2923 char *data = (char*)ev + sizeof(*ev);
2924 struct Scsi_Host *shost;
2927 if (!transport->set_host_param)
2930 if (ev->u.set_host_param.len > PAGE_SIZE)
2933 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
2935 printk(KERN_ERR "set_host_param could not find host no %u\n",
2936 ev->u.set_host_param.host_no);
2940 err = transport->set_host_param(shost, ev->u.set_host_param.param,
2941 data, ev->u.set_host_param.len);
2942 scsi_host_put(shost);
2947 iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
2949 struct Scsi_Host *shost;
2950 struct iscsi_path *params;
2953 if (!transport->set_path)
2956 shost = scsi_host_lookup(ev->u.set_path.host_no);
2958 printk(KERN_ERR "set path could not find host no %u\n",
2959 ev->u.set_path.host_no);
2963 params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
2964 err = transport->set_path(shost, params);
2966 scsi_host_put(shost);
2970 static int iscsi_session_has_conns(int sid)
2972 struct iscsi_cls_conn *conn;
2973 unsigned long flags;
2976 spin_lock_irqsave(&connlock, flags);
2977 list_for_each_entry(conn, &connlist, conn_list) {
2978 if (iscsi_conn_get_sid(conn) == sid) {
2983 spin_unlock_irqrestore(&connlock, flags);
2989 iscsi_set_iface_params(struct iscsi_transport *transport,
2990 struct iscsi_uevent *ev, uint32_t len)
2992 char *data = (char *)ev + sizeof(*ev);
2993 struct Scsi_Host *shost;
2996 if (!transport->set_iface_param)
2999 shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
3001 printk(KERN_ERR "set_iface_params could not find host no %u\n",
3002 ev->u.set_iface_params.host_no);
3006 err = transport->set_iface_param(shost, data, len);
3007 scsi_host_put(shost);
3012 iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
3014 struct Scsi_Host *shost;
3015 struct sockaddr *dst_addr;
3018 if (!transport->send_ping)
3021 shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
3023 printk(KERN_ERR "iscsi_ping could not find host no %u\n",
3024 ev->u.iscsi_ping.host_no);
3028 dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
3029 err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
3030 ev->u.iscsi_ping.iface_type,
3031 ev->u.iscsi_ping.payload_size,
3032 ev->u.iscsi_ping.pid,
3034 scsi_host_put(shost);
3039 iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3041 struct iscsi_uevent *ev = nlmsg_data(nlh);
3042 struct Scsi_Host *shost = NULL;
3043 struct iscsi_chap_rec *chap_rec;
3044 struct iscsi_internal *priv;
3045 struct sk_buff *skbchap;
3046 struct nlmsghdr *nlhchap;
3047 struct iscsi_uevent *evchap;
3048 uint32_t chap_buf_size;
3052 if (!transport->get_chap)
3055 priv = iscsi_if_transport_lookup(transport);
3059 chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
3060 len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3062 shost = scsi_host_lookup(ev->u.get_chap.host_no);
3064 printk(KERN_ERR "%s: failed. Could not find host no %u\n",
3065 __func__, ev->u.get_chap.host_no);
3072 skbchap = alloc_skb(len, GFP_KERNEL);
3074 printk(KERN_ERR "can not deliver chap: OOM\n");
3079 nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
3080 (len - sizeof(*nlhchap)), 0);
3081 evchap = nlmsg_data(nlhchap);
3082 memset(evchap, 0, sizeof(*evchap));
3083 evchap->transport_handle = iscsi_handle(transport);
3084 evchap->type = nlh->nlmsg_type;
3085 evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
3086 evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
3087 evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
3088 buf = (char *)evchap + sizeof(*evchap);
3089 memset(buf, 0, chap_buf_size);
3091 err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
3092 &evchap->u.get_chap.num_entries, buf);
3094 actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
3095 skb_trim(skbchap, NLMSG_ALIGN(actual_size));
3096 nlhchap->nlmsg_len = actual_size;
3098 err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
3100 } while (err < 0 && err != -ECONNREFUSED);
3103 scsi_host_put(shost);
3107 static int iscsi_set_chap(struct iscsi_transport *transport,
3108 struct iscsi_uevent *ev, uint32_t len)
3110 char *data = (char *)ev + sizeof(*ev);
3111 struct Scsi_Host *shost;
3114 if (!transport->set_chap)
3117 shost = scsi_host_lookup(ev->u.set_path.host_no);
3119 pr_err("%s could not find host no %u\n",
3120 __func__, ev->u.set_path.host_no);
3124 err = transport->set_chap(shost, data, len);
3125 scsi_host_put(shost);
3129 static int iscsi_delete_chap(struct iscsi_transport *transport,
3130 struct iscsi_uevent *ev)
3132 struct Scsi_Host *shost;
3135 if (!transport->delete_chap)
3138 shost = scsi_host_lookup(ev->u.delete_chap.host_no);
3140 printk(KERN_ERR "%s could not find host no %u\n",
3141 __func__, ev->u.delete_chap.host_no);
3145 err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
3146 scsi_host_put(shost);
3150 static const struct {
3151 enum iscsi_discovery_parent_type value;
3153 } iscsi_discovery_parent_names[] = {
3154 {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
3155 {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
3156 {ISCSI_DISC_PARENT_ISNS, "isns" },
3159 char *iscsi_get_discovery_parent_name(int parent_type)
3162 char *state = "Unknown!";
3164 for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
3165 if (iscsi_discovery_parent_names[i].value & parent_type) {
3166 state = iscsi_discovery_parent_names[i].name;
3172 EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
3174 static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
3175 struct iscsi_uevent *ev, uint32_t len)
3177 char *data = (char *)ev + sizeof(*ev);
3178 struct Scsi_Host *shost;
3179 struct iscsi_bus_flash_session *fnode_sess;
3180 struct iscsi_bus_flash_conn *fnode_conn;
3185 if (!transport->set_flashnode_param) {
3187 goto exit_set_fnode;
3190 shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
3192 pr_err("%s could not find host no %u\n",
3193 __func__, ev->u.set_flashnode.host_no);
3195 goto exit_set_fnode;
3198 idx = ev->u.set_flashnode.flashnode_idx;
3199 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3201 pr_err("%s could not find flashnode %u for host no %u\n",
3202 __func__, idx, ev->u.set_flashnode.host_no);
3207 dev = iscsi_find_flashnode_conn(fnode_sess);
3213 fnode_conn = iscsi_dev_to_flash_conn(dev);
3214 err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
3218 put_device(&fnode_sess->dev);
3221 scsi_host_put(shost);
3227 static int iscsi_new_flashnode(struct iscsi_transport *transport,
3228 struct iscsi_uevent *ev, uint32_t len)
3230 char *data = (char *)ev + sizeof(*ev);
3231 struct Scsi_Host *shost;
3235 if (!transport->new_flashnode) {
3237 goto exit_new_fnode;
3240 shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
3242 pr_err("%s could not find host no %u\n",
3243 __func__, ev->u.new_flashnode.host_no);
3248 index = transport->new_flashnode(shost, data, len);
3251 ev->r.new_flashnode_ret.flashnode_idx = index;
3256 scsi_host_put(shost);
3262 static int iscsi_del_flashnode(struct iscsi_transport *transport,
3263 struct iscsi_uevent *ev)
3265 struct Scsi_Host *shost;
3266 struct iscsi_bus_flash_session *fnode_sess;
3270 if (!transport->del_flashnode) {
3272 goto exit_del_fnode;
3275 shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
3277 pr_err("%s could not find host no %u\n",
3278 __func__, ev->u.del_flashnode.host_no);
3283 idx = ev->u.del_flashnode.flashnode_idx;
3284 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3286 pr_err("%s could not find flashnode %u for host no %u\n",
3287 __func__, idx, ev->u.del_flashnode.host_no);
3292 err = transport->del_flashnode(fnode_sess);
3293 put_device(&fnode_sess->dev);
3296 scsi_host_put(shost);
3302 static int iscsi_login_flashnode(struct iscsi_transport *transport,
3303 struct iscsi_uevent *ev)
3305 struct Scsi_Host *shost;
3306 struct iscsi_bus_flash_session *fnode_sess;
3307 struct iscsi_bus_flash_conn *fnode_conn;
3312 if (!transport->login_flashnode) {
3314 goto exit_login_fnode;
3317 shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
3319 pr_err("%s could not find host no %u\n",
3320 __func__, ev->u.login_flashnode.host_no);
3325 idx = ev->u.login_flashnode.flashnode_idx;
3326 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3328 pr_err("%s could not find flashnode %u for host no %u\n",
3329 __func__, idx, ev->u.login_flashnode.host_no);
3334 dev = iscsi_find_flashnode_conn(fnode_sess);
3340 fnode_conn = iscsi_dev_to_flash_conn(dev);
3341 err = transport->login_flashnode(fnode_sess, fnode_conn);
3345 put_device(&fnode_sess->dev);
3348 scsi_host_put(shost);
3354 static int iscsi_logout_flashnode(struct iscsi_transport *transport,
3355 struct iscsi_uevent *ev)
3357 struct Scsi_Host *shost;
3358 struct iscsi_bus_flash_session *fnode_sess;
3359 struct iscsi_bus_flash_conn *fnode_conn;
3364 if (!transport->logout_flashnode) {
3366 goto exit_logout_fnode;
3369 shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
3371 pr_err("%s could not find host no %u\n",
3372 __func__, ev->u.logout_flashnode.host_no);
3377 idx = ev->u.logout_flashnode.flashnode_idx;
3378 fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
3380 pr_err("%s could not find flashnode %u for host no %u\n",
3381 __func__, idx, ev->u.logout_flashnode.host_no);
3386 dev = iscsi_find_flashnode_conn(fnode_sess);
3392 fnode_conn = iscsi_dev_to_flash_conn(dev);
3394 err = transport->logout_flashnode(fnode_sess, fnode_conn);
3398 put_device(&fnode_sess->dev);
3401 scsi_host_put(shost);
3407 static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
3408 struct iscsi_uevent *ev)
3410 struct Scsi_Host *shost;
3411 struct iscsi_cls_session *session;
3414 if (!transport->logout_flashnode_sid) {
3416 goto exit_logout_sid;
3419 shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
3421 pr_err("%s could not find host no %u\n",
3422 __func__, ev->u.logout_flashnode.host_no);
3427 session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
3429 pr_err("%s could not find session id %u\n",
3430 __func__, ev->u.logout_flashnode_sid.sid);
3435 err = transport->logout_flashnode_sid(session);
3438 scsi_host_put(shost);
3445 iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
3447 struct iscsi_uevent *ev = nlmsg_data(nlh);
3448 struct Scsi_Host *shost = NULL;
3449 struct iscsi_internal *priv;
3450 struct sk_buff *skbhost_stats;
3451 struct nlmsghdr *nlhhost_stats;
3452 struct iscsi_uevent *evhost_stats;
3453 int host_stats_size = 0;
3457 if (!transport->get_host_stats)
3460 priv = iscsi_if_transport_lookup(transport);
3464 host_stats_size = sizeof(struct iscsi_offload_host_stats);
3465 len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3467 shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
3469 pr_err("%s: failed. Cound not find host no %u\n",
3470 __func__, ev->u.get_host_stats.host_no);
3477 skbhost_stats = alloc_skb(len, GFP_KERNEL);
3478 if (!skbhost_stats) {
3479 pr_err("cannot deliver host stats: OOM\n");
3481 goto exit_host_stats;
3484 nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
3485 (len - sizeof(*nlhhost_stats)), 0);
3486 evhost_stats = nlmsg_data(nlhhost_stats);
3487 memset(evhost_stats, 0, sizeof(*evhost_stats));
3488 evhost_stats->transport_handle = iscsi_handle(transport);
3489 evhost_stats->type = nlh->nlmsg_type;
3490 evhost_stats->u.get_host_stats.host_no =
3491 ev->u.get_host_stats.host_no;
3492 buf = (char *)evhost_stats + sizeof(*evhost_stats);
3493 memset(buf, 0, host_stats_size);
3495 err = transport->get_host_stats(shost, buf, host_stats_size);
3497 kfree_skb(skbhost_stats);
3498 goto exit_host_stats;
3501 actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
3502 skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
3503 nlhhost_stats->nlmsg_len = actual_size;
3505 err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
3507 } while (err < 0 && err != -ECONNREFUSED);
3510 scsi_host_put(shost);
3516 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
3520 struct iscsi_uevent *ev = nlmsg_data(nlh);
3521 struct iscsi_transport *transport = NULL;
3522 struct iscsi_internal *priv;
3523 struct iscsi_cls_session *session;
3524 struct iscsi_cls_conn *conn;
3525 struct iscsi_endpoint *ep = NULL;
3527 if (!netlink_capable(skb, CAP_SYS_ADMIN))
3530 if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
3531 *group = ISCSI_NL_GRP_UIP;
3533 *group = ISCSI_NL_GRP_ISCSID;
3535 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
3538 transport = priv->iscsi_transport;
3540 if (!try_module_get(transport->owner))
3543 switch (nlh->nlmsg_type) {
3544 case ISCSI_UEVENT_CREATE_SESSION:
3545 err = iscsi_if_create_session(priv, ep, ev,
3546 NETLINK_CB(skb).portid,
3547 ev->u.c_session.initial_cmdsn,
3548 ev->u.c_session.cmds_max,
3549 ev->u.c_session.queue_depth);
3551 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
3552 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
3558 err = iscsi_if_create_session(priv, ep, ev,
3559 NETLINK_CB(skb).portid,
3560 ev->u.c_bound_session.initial_cmdsn,
3561 ev->u.c_bound_session.cmds_max,
3562 ev->u.c_bound_session.queue_depth);
3564 case ISCSI_UEVENT_DESTROY_SESSION:
3565 session = iscsi_session_lookup(ev->u.d_session.sid);
3568 else if (iscsi_session_has_conns(ev->u.d_session.sid))
3571 transport->destroy_session(session);
3573 case ISCSI_UEVENT_UNBIND_SESSION:
3574 session = iscsi_session_lookup(ev->u.d_session.sid);
3576 scsi_queue_work(iscsi_session_to_shost(session),
3577 &session->unbind_work);
3581 case ISCSI_UEVENT_CREATE_CONN:
3582 err = iscsi_if_create_conn(transport, ev);
3584 case ISCSI_UEVENT_DESTROY_CONN:
3585 err = iscsi_if_destroy_conn(transport, ev);
3587 case ISCSI_UEVENT_BIND_CONN:
3588 session = iscsi_session_lookup(ev->u.b_conn.sid);
3589 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
3591 if (conn && conn->ep)
3592 iscsi_if_ep_disconnect(transport, conn->ep->id);
3594 if (!session || !conn) {
3599 ev->r.retcode = transport->bind_conn(session, conn,
3600 ev->u.b_conn.transport_eph,
3601 ev->u.b_conn.is_leading);
3602 if (ev->r.retcode || !transport->ep_connect)
3605 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
3609 mutex_lock(&conn->ep_mutex);
3611 mutex_unlock(&conn->ep_mutex);
3613 iscsi_cls_conn_printk(KERN_ERR, conn,
3614 "Could not set ep conn "
3617 case ISCSI_UEVENT_SET_PARAM:
3618 err = iscsi_set_param(transport, ev);
3620 case ISCSI_UEVENT_START_CONN:
3621 conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid);
3623 ev->r.retcode = transport->start_conn(conn);
3627 case ISCSI_UEVENT_STOP_CONN:
3628 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
3630 transport->stop_conn(conn, ev->u.stop_conn.flag);
3634 case ISCSI_UEVENT_SEND_PDU:
3635 pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
3637 if ((ev->u.send_pdu.hdr_size > pdu_len) ||
3638 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
3643 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
3645 ev->r.retcode = transport->send_pdu(conn,
3646 (struct iscsi_hdr*)((char*)ev + sizeof(*ev)),
3647 (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
3648 ev->u.send_pdu.data_size);
3652 case ISCSI_UEVENT_GET_STATS:
3653 err = iscsi_if_get_stats(transport, nlh);
3655 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
3656 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
3657 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
3658 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
3659 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
3661 case ISCSI_UEVENT_TGT_DSCVR:
3662 err = iscsi_tgt_dscvr(transport, ev);
3664 case ISCSI_UEVENT_SET_HOST_PARAM:
3665 err = iscsi_set_host_param(transport, ev);
3667 case ISCSI_UEVENT_PATH_UPDATE:
3668 err = iscsi_set_path(transport, ev);
3670 case ISCSI_UEVENT_SET_IFACE_PARAMS:
3671 err = iscsi_set_iface_params(transport, ev,
3672 nlmsg_attrlen(nlh, sizeof(*ev)));
3674 case ISCSI_UEVENT_PING:
3675 err = iscsi_send_ping(transport, ev);
3677 case ISCSI_UEVENT_GET_CHAP:
3678 err = iscsi_get_chap(transport, nlh);
3680 case ISCSI_UEVENT_DELETE_CHAP:
3681 err = iscsi_delete_chap(transport, ev);
3683 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
3684 err = iscsi_set_flashnode_param(transport, ev,
3688 case ISCSI_UEVENT_NEW_FLASHNODE:
3689 err = iscsi_new_flashnode(transport, ev,
3690 nlmsg_attrlen(nlh, sizeof(*ev)));
3692 case ISCSI_UEVENT_DEL_FLASHNODE:
3693 err = iscsi_del_flashnode(transport, ev);
3695 case ISCSI_UEVENT_LOGIN_FLASHNODE:
3696 err = iscsi_login_flashnode(transport, ev);
3698 case ISCSI_UEVENT_LOGOUT_FLASHNODE:
3699 err = iscsi_logout_flashnode(transport, ev);
3701 case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
3702 err = iscsi_logout_flashnode_sid(transport, ev);
3704 case ISCSI_UEVENT_SET_CHAP:
3705 err = iscsi_set_chap(transport, ev,
3706 nlmsg_attrlen(nlh, sizeof(*ev)));
3708 case ISCSI_UEVENT_GET_HOST_STATS:
3709 err = iscsi_get_host_stats(transport, nlh);
3716 module_put(transport->owner);
3721 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
3722 * Malformed skbs with wrong lengths or invalid creds are not processed.
3725 iscsi_if_rx(struct sk_buff *skb)
3727 mutex_lock(&rx_queue_mutex);
3728 while (skb->len >= NLMSG_HDRLEN) {
3731 struct nlmsghdr *nlh;
3732 struct iscsi_uevent *ev;
3734 int retries = ISCSI_SEND_MAX_ALLOWED;
3736 nlh = nlmsg_hdr(skb);
3737 if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
3738 skb->len < nlh->nlmsg_len) {
3742 ev = nlmsg_data(nlh);
3743 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
3744 if (rlen > skb->len)
3747 err = iscsi_if_recv_msg(skb, nlh, &group);
3749 ev->type = ISCSI_KEVENT_IF_ERROR;
3754 * special case for GET_STATS:
3755 * on success - sending reply and stats from
3756 * inside of if_recv_msg(),
3757 * on error - fall through.
3759 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
3761 if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
3763 err = iscsi_if_send_reply(group, nlh->nlmsg_seq,
3764 nlh->nlmsg_type, 0, 0, ev, sizeof(*ev));
3765 if (err == -EAGAIN && --retries < 0) {
3766 printk(KERN_WARNING "Send reply failed, error %d\n", err);
3769 } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
3770 skb_pull(skb, rlen);
3772 mutex_unlock(&rx_queue_mutex);
3775 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
3776 struct device_attribute dev_attr_##_prefix##_##_name = \
3777 __ATTR(_name,_mode,_show,_store)
3780 * iSCSI connection attrs
3782 #define iscsi_conn_attr_show(param) \
3784 show_conn_param_##param(struct device *dev, \
3785 struct device_attribute *attr, char *buf) \
3787 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
3788 struct iscsi_transport *t = conn->transport; \
3789 return t->get_conn_param(conn, param, buf); \
3792 #define iscsi_conn_attr(field, param) \
3793 iscsi_conn_attr_show(param) \
3794 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
3797 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
3798 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
3799 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
3800 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
3801 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
3802 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
3803 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
3804 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
3805 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
3806 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
3807 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
3808 iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
3809 iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
3810 iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
3811 iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
3812 iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
3813 iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
3814 iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
3815 iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
3816 iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
3817 iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
3818 iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
3819 iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
3820 iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
3821 iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
3822 iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
3823 iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
3824 iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
3827 #define iscsi_conn_ep_attr_show(param) \
3828 static ssize_t show_conn_ep_param_##param(struct device *dev, \
3829 struct device_attribute *attr,\
3832 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
3833 struct iscsi_transport *t = conn->transport; \
3834 struct iscsi_endpoint *ep; \
3838 * Need to make sure ep_disconnect does not free the LLD's \
3839 * interconnect resources while we are trying to read them. \
3841 mutex_lock(&conn->ep_mutex); \
3843 if (!ep && t->ep_connect) { \
3844 mutex_unlock(&conn->ep_mutex); \
3849 rc = t->get_ep_param(ep, param, buf); \
3851 rc = t->get_conn_param(conn, param, buf); \
3852 mutex_unlock(&conn->ep_mutex); \
3856 #define iscsi_conn_ep_attr(field, param) \
3857 iscsi_conn_ep_attr_show(param) \
3858 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
3859 show_conn_ep_param_##param, NULL);
3861 iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
3862 iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
3864 static struct attribute *iscsi_conn_attrs[] = {
3865 &dev_attr_conn_max_recv_dlength.attr,
3866 &dev_attr_conn_max_xmit_dlength.attr,
3867 &dev_attr_conn_header_digest.attr,
3868 &dev_attr_conn_data_digest.attr,
3869 &dev_attr_conn_ifmarker.attr,
3870 &dev_attr_conn_ofmarker.attr,
3871 &dev_attr_conn_address.attr,
3872 &dev_attr_conn_port.attr,
3873 &dev_attr_conn_exp_statsn.attr,
3874 &dev_attr_conn_persistent_address.attr,
3875 &dev_attr_conn_persistent_port.attr,
3876 &dev_attr_conn_ping_tmo.attr,
3877 &dev_attr_conn_recv_tmo.attr,
3878 &dev_attr_conn_local_port.attr,
3879 &dev_attr_conn_statsn.attr,
3880 &dev_attr_conn_keepalive_tmo.attr,
3881 &dev_attr_conn_max_segment_size.attr,
3882 &dev_attr_conn_tcp_timestamp_stat.attr,
3883 &dev_attr_conn_tcp_wsf_disable.attr,
3884 &dev_attr_conn_tcp_nagle_disable.attr,
3885 &dev_attr_conn_tcp_timer_scale.attr,
3886 &dev_attr_conn_tcp_timestamp_enable.attr,
3887 &dev_attr_conn_fragment_disable.attr,
3888 &dev_attr_conn_ipv4_tos.attr,
3889 &dev_attr_conn_ipv6_traffic_class.attr,
3890 &dev_attr_conn_ipv6_flow_label.attr,
3891 &dev_attr_conn_is_fw_assigned_ipv6.attr,
3892 &dev_attr_conn_tcp_xmit_wsf.attr,
3893 &dev_attr_conn_tcp_recv_wsf.attr,
3894 &dev_attr_conn_local_ipaddr.attr,
3898 static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
3899 struct attribute *attr, int i)
3901 struct device *cdev = container_of(kobj, struct device, kobj);
3902 struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
3903 struct iscsi_transport *t = conn->transport;
3906 if (attr == &dev_attr_conn_max_recv_dlength.attr)
3907 param = ISCSI_PARAM_MAX_RECV_DLENGTH;
3908 else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
3909 param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
3910 else if (attr == &dev_attr_conn_header_digest.attr)
3911 param = ISCSI_PARAM_HDRDGST_EN;
3912 else if (attr == &dev_attr_conn_data_digest.attr)
3913 param = ISCSI_PARAM_DATADGST_EN;
3914 else if (attr == &dev_attr_conn_ifmarker.attr)
3915 param = ISCSI_PARAM_IFMARKER_EN;
3916 else if (attr == &dev_attr_conn_ofmarker.attr)
3917 param = ISCSI_PARAM_OFMARKER_EN;
3918 else if (attr == &dev_attr_conn_address.attr)
3919 param = ISCSI_PARAM_CONN_ADDRESS;
3920 else if (attr == &dev_attr_conn_port.attr)
3921 param = ISCSI_PARAM_CONN_PORT;
3922 else if (attr == &dev_attr_conn_exp_statsn.attr)
3923 param = ISCSI_PARAM_EXP_STATSN;
3924 else if (attr == &dev_attr_conn_persistent_address.attr)
3925 param = ISCSI_PARAM_PERSISTENT_ADDRESS;
3926 else if (attr == &dev_attr_conn_persistent_port.attr)
3927 param = ISCSI_PARAM_PERSISTENT_PORT;
3928 else if (attr == &dev_attr_conn_ping_tmo.attr)
3929 param = ISCSI_PARAM_PING_TMO;
3930 else if (attr == &dev_attr_conn_recv_tmo.attr)
3931 param = ISCSI_PARAM_RECV_TMO;
3932 else if (attr == &dev_attr_conn_local_port.attr)
3933 param = ISCSI_PARAM_LOCAL_PORT;
3934 else if (attr == &dev_attr_conn_statsn.attr)
3935 param = ISCSI_PARAM_STATSN;
3936 else if (attr == &dev_attr_conn_keepalive_tmo.attr)
3937 param = ISCSI_PARAM_KEEPALIVE_TMO;
3938 else if (attr == &dev_attr_conn_max_segment_size.attr)
3939 param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
3940 else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
3941 param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
3942 else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
3943 param = ISCSI_PARAM_TCP_WSF_DISABLE;
3944 else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
3945 param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
3946 else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
3947 param = ISCSI_PARAM_TCP_TIMER_SCALE;
3948 else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
3949 param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
3950 else if (attr == &dev_attr_conn_fragment_disable.attr)
3951 param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
3952 else if (attr == &dev_attr_conn_ipv4_tos.attr)
3953 param = ISCSI_PARAM_IPV4_TOS;
3954 else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
3955 param = ISCSI_PARAM_IPV6_TC;
3956 else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
3957 param = ISCSI_PARAM_IPV6_FLOW_LABEL;
3958 else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
3959 param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
3960 else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
3961 param = ISCSI_PARAM_TCP_XMIT_WSF;
3962 else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
3963 param = ISCSI_PARAM_TCP_RECV_WSF;
3964 else if (attr == &dev_attr_conn_local_ipaddr.attr)
3965 param = ISCSI_PARAM_LOCAL_IPADDR;
3967 WARN_ONCE(1, "Invalid conn attr");
3971 return t->attr_is_visible(ISCSI_PARAM, param);
3974 static struct attribute_group iscsi_conn_group = {
3975 .attrs = iscsi_conn_attrs,
3976 .is_visible = iscsi_conn_attr_is_visible,
3980 * iSCSI session attrs
3982 #define iscsi_session_attr_show(param, perm) \
3984 show_session_param_##param(struct device *dev, \
3985 struct device_attribute *attr, char *buf) \
3987 struct iscsi_cls_session *session = \
3988 iscsi_dev_to_session(dev->parent); \
3989 struct iscsi_transport *t = session->transport; \
3991 if (perm && !capable(CAP_SYS_ADMIN)) \
3993 return t->get_session_param(session, param, buf); \
3996 #define iscsi_session_attr(field, param, perm) \
3997 iscsi_session_attr_show(param, perm) \
3998 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
4000 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
4001 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
4002 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
4003 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
4004 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
4005 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
4006 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
4007 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
4008 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
4009 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
4010 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
4011 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
4012 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
4013 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
4014 iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
4015 iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
4016 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
4017 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
4018 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
4019 iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
4020 iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
4021 iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
4022 iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
4023 iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
4024 iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
4025 iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
4026 iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
4027 iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
4028 iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
4029 iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
4030 iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
4031 iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
4032 iscsi_session_attr(discovery_auth_optional,
4033 ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
4034 iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
4035 iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
4036 iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
4037 iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
4038 iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
4039 iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
4040 iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
4043 show_priv_session_state(struct device *dev, struct device_attribute *attr,
4046 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4047 return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
4049 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
4052 show_priv_session_creator(struct device *dev, struct device_attribute *attr,
4055 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4056 return sysfs_emit(buf, "%d\n", session->creator);
4058 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
4061 show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
4064 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
4065 return sysfs_emit(buf, "%d\n", session->target_id);
4067 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
4068 show_priv_session_target_id, NULL);
4070 #define iscsi_priv_session_attr_show(field, format) \
4072 show_priv_session_##field(struct device *dev, \
4073 struct device_attribute *attr, char *buf) \
4075 struct iscsi_cls_session *session = \
4076 iscsi_dev_to_session(dev->parent); \
4077 if (session->field == -1) \
4078 return sysfs_emit(buf, "off\n"); \
4079 return sysfs_emit(buf, format"\n", session->field); \
4082 #define iscsi_priv_session_attr_store(field) \
4084 store_priv_session_##field(struct device *dev, \
4085 struct device_attribute *attr, \
4086 const char *buf, size_t count) \
4090 struct iscsi_cls_session *session = \
4091 iscsi_dev_to_session(dev->parent); \
4092 if ((session->state == ISCSI_SESSION_FREE) || \
4093 (session->state == ISCSI_SESSION_FAILED)) \
4095 if (strncmp(buf, "off", 3) == 0) { \
4096 session->field = -1; \
4097 session->field##_sysfs_override = true; \
4099 val = simple_strtoul(buf, &cp, 0); \
4100 if (*cp != '\0' && *cp != '\n') \
4102 session->field = val; \
4103 session->field##_sysfs_override = true; \
4108 #define iscsi_priv_session_rw_attr(field, format) \
4109 iscsi_priv_session_attr_show(field, format) \
4110 iscsi_priv_session_attr_store(field) \
4111 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
4112 show_priv_session_##field, \
4113 store_priv_session_##field)
4115 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
4117 static struct attribute *iscsi_session_attrs[] = {
4118 &dev_attr_sess_initial_r2t.attr,
4119 &dev_attr_sess_max_outstanding_r2t.attr,
4120 &dev_attr_sess_immediate_data.attr,
4121 &dev_attr_sess_first_burst_len.attr,
4122 &dev_attr_sess_max_burst_len.attr,
4123 &dev_attr_sess_data_pdu_in_order.attr,
4124 &dev_attr_sess_data_seq_in_order.attr,
4125 &dev_attr_sess_erl.attr,
4126 &dev_attr_sess_targetname.attr,
4127 &dev_attr_sess_tpgt.attr,
4128 &dev_attr_sess_password.attr,
4129 &dev_attr_sess_password_in.attr,
4130 &dev_attr_sess_username.attr,
4131 &dev_attr_sess_username_in.attr,
4132 &dev_attr_sess_fast_abort.attr,
4133 &dev_attr_sess_abort_tmo.attr,
4134 &dev_attr_sess_lu_reset_tmo.attr,
4135 &dev_attr_sess_tgt_reset_tmo.attr,
4136 &dev_attr_sess_ifacename.attr,
4137 &dev_attr_sess_initiatorname.attr,
4138 &dev_attr_sess_targetalias.attr,
4139 &dev_attr_sess_boot_root.attr,
4140 &dev_attr_sess_boot_nic.attr,
4141 &dev_attr_sess_boot_target.attr,
4142 &dev_attr_priv_sess_recovery_tmo.attr,
4143 &dev_attr_priv_sess_state.attr,
4144 &dev_attr_priv_sess_creator.attr,
4145 &dev_attr_sess_chap_out_idx.attr,
4146 &dev_attr_sess_chap_in_idx.attr,
4147 &dev_attr_priv_sess_target_id.attr,
4148 &dev_attr_sess_auto_snd_tgt_disable.attr,
4149 &dev_attr_sess_discovery_session.attr,
4150 &dev_attr_sess_portal_type.attr,
4151 &dev_attr_sess_chap_auth.attr,
4152 &dev_attr_sess_discovery_logout.attr,
4153 &dev_attr_sess_bidi_chap.attr,
4154 &dev_attr_sess_discovery_auth_optional.attr,
4155 &dev_attr_sess_def_time2wait.attr,
4156 &dev_attr_sess_def_time2retain.attr,
4157 &dev_attr_sess_isid.attr,
4158 &dev_attr_sess_tsid.attr,
4159 &dev_attr_sess_def_taskmgmt_tmo.attr,
4160 &dev_attr_sess_discovery_parent_idx.attr,
4161 &dev_attr_sess_discovery_parent_type.attr,
4165 static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
4166 struct attribute *attr, int i)
4168 struct device *cdev = container_of(kobj, struct device, kobj);
4169 struct iscsi_cls_session *session = transport_class_to_session(cdev);
4170 struct iscsi_transport *t = session->transport;
4173 if (attr == &dev_attr_sess_initial_r2t.attr)
4174 param = ISCSI_PARAM_INITIAL_R2T_EN;
4175 else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
4176 param = ISCSI_PARAM_MAX_R2T;
4177 else if (attr == &dev_attr_sess_immediate_data.attr)
4178 param = ISCSI_PARAM_IMM_DATA_EN;
4179 else if (attr == &dev_attr_sess_first_burst_len.attr)
4180 param = ISCSI_PARAM_FIRST_BURST;
4181 else if (attr == &dev_attr_sess_max_burst_len.attr)
4182 param = ISCSI_PARAM_MAX_BURST;
4183 else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
4184 param = ISCSI_PARAM_PDU_INORDER_EN;
4185 else if (attr == &dev_attr_sess_data_seq_in_order.attr)
4186 param = ISCSI_PARAM_DATASEQ_INORDER_EN;
4187 else if (attr == &dev_attr_sess_erl.attr)
4188 param = ISCSI_PARAM_ERL;
4189 else if (attr == &dev_attr_sess_targetname.attr)
4190 param = ISCSI_PARAM_TARGET_NAME;
4191 else if (attr == &dev_attr_sess_tpgt.attr)
4192 param = ISCSI_PARAM_TPGT;
4193 else if (attr == &dev_attr_sess_chap_in_idx.attr)
4194 param = ISCSI_PARAM_CHAP_IN_IDX;
4195 else if (attr == &dev_attr_sess_chap_out_idx.attr)
4196 param = ISCSI_PARAM_CHAP_OUT_IDX;
4197 else if (attr == &dev_attr_sess_password.attr)
4198 param = ISCSI_PARAM_USERNAME;
4199 else if (attr == &dev_attr_sess_password_in.attr)
4200 param = ISCSI_PARAM_USERNAME_IN;
4201 else if (attr == &dev_attr_sess_username.attr)
4202 param = ISCSI_PARAM_PASSWORD;
4203 else if (attr == &dev_attr_sess_username_in.attr)
4204 param = ISCSI_PARAM_PASSWORD_IN;
4205 else if (attr == &dev_attr_sess_fast_abort.attr)
4206 param = ISCSI_PARAM_FAST_ABORT;
4207 else if (attr == &dev_attr_sess_abort_tmo.attr)
4208 param = ISCSI_PARAM_ABORT_TMO;
4209 else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
4210 param = ISCSI_PARAM_LU_RESET_TMO;
4211 else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
4212 param = ISCSI_PARAM_TGT_RESET_TMO;
4213 else if (attr == &dev_attr_sess_ifacename.attr)
4214 param = ISCSI_PARAM_IFACE_NAME;
4215 else if (attr == &dev_attr_sess_initiatorname.attr)
4216 param = ISCSI_PARAM_INITIATOR_NAME;
4217 else if (attr == &dev_attr_sess_targetalias.attr)
4218 param = ISCSI_PARAM_TARGET_ALIAS;
4219 else if (attr == &dev_attr_sess_boot_root.attr)
4220 param = ISCSI_PARAM_BOOT_ROOT;
4221 else if (attr == &dev_attr_sess_boot_nic.attr)
4222 param = ISCSI_PARAM_BOOT_NIC;
4223 else if (attr == &dev_attr_sess_boot_target.attr)
4224 param = ISCSI_PARAM_BOOT_TARGET;
4225 else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
4226 param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
4227 else if (attr == &dev_attr_sess_discovery_session.attr)
4228 param = ISCSI_PARAM_DISCOVERY_SESS;
4229 else if (attr == &dev_attr_sess_portal_type.attr)
4230 param = ISCSI_PARAM_PORTAL_TYPE;
4231 else if (attr == &dev_attr_sess_chap_auth.attr)
4232 param = ISCSI_PARAM_CHAP_AUTH_EN;
4233 else if (attr == &dev_attr_sess_discovery_logout.attr)
4234 param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
4235 else if (attr == &dev_attr_sess_bidi_chap.attr)
4236 param = ISCSI_PARAM_BIDI_CHAP_EN;
4237 else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
4238 param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
4239 else if (attr == &dev_attr_sess_def_time2wait.attr)
4240 param = ISCSI_PARAM_DEF_TIME2WAIT;
4241 else if (attr == &dev_attr_sess_def_time2retain.attr)
4242 param = ISCSI_PARAM_DEF_TIME2RETAIN;
4243 else if (attr == &dev_attr_sess_isid.attr)
4244 param = ISCSI_PARAM_ISID;
4245 else if (attr == &dev_attr_sess_tsid.attr)
4246 param = ISCSI_PARAM_TSID;
4247 else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
4248 param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
4249 else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
4250 param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
4251 else if (attr == &dev_attr_sess_discovery_parent_type.attr)
4252 param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
4253 else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
4254 return S_IRUGO | S_IWUSR;
4255 else if (attr == &dev_attr_priv_sess_state.attr)
4257 else if (attr == &dev_attr_priv_sess_creator.attr)
4259 else if (attr == &dev_attr_priv_sess_target_id.attr)
4262 WARN_ONCE(1, "Invalid session attr");
4266 return t->attr_is_visible(ISCSI_PARAM, param);
4269 static struct attribute_group iscsi_session_group = {
4270 .attrs = iscsi_session_attrs,
4271 .is_visible = iscsi_session_attr_is_visible,
4277 #define iscsi_host_attr_show(param) \
4279 show_host_param_##param(struct device *dev, \
4280 struct device_attribute *attr, char *buf) \
4282 struct Scsi_Host *shost = transport_class_to_shost(dev); \
4283 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
4284 return priv->iscsi_transport->get_host_param(shost, param, buf); \
4287 #define iscsi_host_attr(field, param) \
4288 iscsi_host_attr_show(param) \
4289 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
4292 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
4293 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
4294 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
4295 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
4296 iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
4297 iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
4299 static struct attribute *iscsi_host_attrs[] = {
4300 &dev_attr_host_netdev.attr,
4301 &dev_attr_host_hwaddress.attr,
4302 &dev_attr_host_ipaddress.attr,
4303 &dev_attr_host_initiatorname.attr,
4304 &dev_attr_host_port_state.attr,
4305 &dev_attr_host_port_speed.attr,
4309 static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
4310 struct attribute *attr, int i)
4312 struct device *cdev = container_of(kobj, struct device, kobj);
4313 struct Scsi_Host *shost = transport_class_to_shost(cdev);
4314 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
4317 if (attr == &dev_attr_host_netdev.attr)
4318 param = ISCSI_HOST_PARAM_NETDEV_NAME;
4319 else if (attr == &dev_attr_host_hwaddress.attr)
4320 param = ISCSI_HOST_PARAM_HWADDRESS;
4321 else if (attr == &dev_attr_host_ipaddress.attr)
4322 param = ISCSI_HOST_PARAM_IPADDRESS;
4323 else if (attr == &dev_attr_host_initiatorname.attr)
4324 param = ISCSI_HOST_PARAM_INITIATOR_NAME;
4325 else if (attr == &dev_attr_host_port_state.attr)
4326 param = ISCSI_HOST_PARAM_PORT_STATE;
4327 else if (attr == &dev_attr_host_port_speed.attr)
4328 param = ISCSI_HOST_PARAM_PORT_SPEED;
4330 WARN_ONCE(1, "Invalid host attr");
4334 return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
4337 static struct attribute_group iscsi_host_group = {
4338 .attrs = iscsi_host_attrs,
4339 .is_visible = iscsi_host_attr_is_visible,
4342 /* convert iscsi_port_speed values to ascii string name */
4343 static const struct {
4344 enum iscsi_port_speed value;
4346 } iscsi_port_speed_names[] = {
4347 {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
4348 {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
4349 {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
4350 {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
4351 {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
4354 char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
4357 char *speed = "Unknown!";
4358 struct iscsi_cls_host *ihost = shost->shost_data;
4359 uint32_t port_speed = ihost->port_speed;
4361 for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
4362 if (iscsi_port_speed_names[i].value & port_speed) {
4363 speed = iscsi_port_speed_names[i].name;
4369 EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
4371 /* convert iscsi_port_state values to ascii string name */
4372 static const struct {
4373 enum iscsi_port_state value;
4375 } iscsi_port_state_names[] = {
4376 {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
4377 {ISCSI_PORT_STATE_UP, "LINK UP" },
4380 char *iscsi_get_port_state_name(struct Scsi_Host *shost)
4383 char *state = "Unknown!";
4384 struct iscsi_cls_host *ihost = shost->shost_data;
4385 uint32_t port_state = ihost->port_state;
4387 for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
4388 if (iscsi_port_state_names[i].value & port_state) {
4389 state = iscsi_port_state_names[i].name;
4395 EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
4397 static int iscsi_session_match(struct attribute_container *cont,
4400 struct iscsi_cls_session *session;
4401 struct Scsi_Host *shost;
4402 struct iscsi_internal *priv;
4404 if (!iscsi_is_session_dev(dev))
4407 session = iscsi_dev_to_session(dev);
4408 shost = iscsi_session_to_shost(session);
4409 if (!shost->transportt)
4412 priv = to_iscsi_internal(shost->transportt);
4413 if (priv->session_cont.ac.class != &iscsi_session_class.class)
4416 return &priv->session_cont.ac == cont;
4419 static int iscsi_conn_match(struct attribute_container *cont,
4422 struct iscsi_cls_session *session;
4423 struct iscsi_cls_conn *conn;
4424 struct Scsi_Host *shost;
4425 struct iscsi_internal *priv;
4427 if (!iscsi_is_conn_dev(dev))
4430 conn = iscsi_dev_to_conn(dev);
4431 session = iscsi_dev_to_session(conn->dev.parent);
4432 shost = iscsi_session_to_shost(session);
4434 if (!shost->transportt)
4437 priv = to_iscsi_internal(shost->transportt);
4438 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
4441 return &priv->conn_cont.ac == cont;
4444 static int iscsi_host_match(struct attribute_container *cont,
4447 struct Scsi_Host *shost;
4448 struct iscsi_internal *priv;
4450 if (!scsi_is_host_device(dev))
4453 shost = dev_to_shost(dev);
4454 if (!shost->transportt ||
4455 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
4458 priv = to_iscsi_internal(shost->transportt);
4459 return &priv->t.host_attrs.ac == cont;
4462 struct scsi_transport_template *
4463 iscsi_register_transport(struct iscsi_transport *tt)
4465 struct iscsi_internal *priv;
4466 unsigned long flags;
4471 priv = iscsi_if_transport_lookup(tt);
4475 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
4478 INIT_LIST_HEAD(&priv->list);
4479 priv->iscsi_transport = tt;
4480 priv->t.user_scan = iscsi_user_scan;
4481 priv->t.create_work_queue = 1;
4483 priv->dev.class = &iscsi_transport_class;
4484 dev_set_name(&priv->dev, "%s", tt->name);
4485 err = device_register(&priv->dev);
4489 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
4491 goto unregister_dev;
4493 /* host parameters */
4494 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
4495 priv->t.host_attrs.ac.match = iscsi_host_match;
4496 priv->t.host_attrs.ac.grp = &iscsi_host_group;
4497 priv->t.host_size = sizeof(struct iscsi_cls_host);
4498 transport_container_register(&priv->t.host_attrs);
4500 /* connection parameters */
4501 priv->conn_cont.ac.class = &iscsi_connection_class.class;
4502 priv->conn_cont.ac.match = iscsi_conn_match;
4503 priv->conn_cont.ac.grp = &iscsi_conn_group;
4504 transport_container_register(&priv->conn_cont);
4506 /* session parameters */
4507 priv->session_cont.ac.class = &iscsi_session_class.class;
4508 priv->session_cont.ac.match = iscsi_session_match;
4509 priv->session_cont.ac.grp = &iscsi_session_group;
4510 transport_container_register(&priv->session_cont);
4512 spin_lock_irqsave(&iscsi_transport_lock, flags);
4513 list_add(&priv->list, &iscsi_transports);
4514 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4516 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
4520 device_unregister(&priv->dev);
4526 EXPORT_SYMBOL_GPL(iscsi_register_transport);
4528 int iscsi_unregister_transport(struct iscsi_transport *tt)
4530 struct iscsi_internal *priv;
4531 unsigned long flags;
4535 mutex_lock(&rx_queue_mutex);
4537 priv = iscsi_if_transport_lookup(tt);
4540 spin_lock_irqsave(&iscsi_transport_lock, flags);
4541 list_del(&priv->list);
4542 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
4544 transport_container_unregister(&priv->conn_cont);
4545 transport_container_unregister(&priv->session_cont);
4546 transport_container_unregister(&priv->t.host_attrs);
4548 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
4549 device_unregister(&priv->dev);
4550 mutex_unlock(&rx_queue_mutex);
4554 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
4556 static __init int iscsi_transport_init(void)
4559 struct netlink_kernel_cfg cfg = {
4561 .input = iscsi_if_rx,
4563 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
4564 ISCSI_TRANSPORT_VERSION);
4566 atomic_set(&iscsi_session_nr, 0);
4568 err = class_register(&iscsi_transport_class);
4572 err = class_register(&iscsi_endpoint_class);
4574 goto unregister_transport_class;
4576 err = class_register(&iscsi_iface_class);
4578 goto unregister_endpoint_class;
4580 err = transport_class_register(&iscsi_host_class);
4582 goto unregister_iface_class;
4584 err = transport_class_register(&iscsi_connection_class);
4586 goto unregister_host_class;
4588 err = transport_class_register(&iscsi_session_class);
4590 goto unregister_conn_class;
4592 err = bus_register(&iscsi_flashnode_bus);
4594 goto unregister_session_class;
4596 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
4599 goto unregister_flashnode_bus;
4602 iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh");
4603 if (!iscsi_eh_timer_workq) {
4611 netlink_kernel_release(nls);
4612 unregister_flashnode_bus:
4613 bus_unregister(&iscsi_flashnode_bus);
4614 unregister_session_class:
4615 transport_class_unregister(&iscsi_session_class);
4616 unregister_conn_class:
4617 transport_class_unregister(&iscsi_connection_class);
4618 unregister_host_class:
4619 transport_class_unregister(&iscsi_host_class);
4620 unregister_iface_class:
4621 class_unregister(&iscsi_iface_class);
4622 unregister_endpoint_class:
4623 class_unregister(&iscsi_endpoint_class);
4624 unregister_transport_class:
4625 class_unregister(&iscsi_transport_class);
4629 static void __exit iscsi_transport_exit(void)
4631 destroy_workqueue(iscsi_eh_timer_workq);
4632 netlink_kernel_release(nls);
4633 bus_unregister(&iscsi_flashnode_bus);
4634 transport_class_unregister(&iscsi_connection_class);
4635 transport_class_unregister(&iscsi_session_class);
4636 transport_class_unregister(&iscsi_host_class);
4637 class_unregister(&iscsi_endpoint_class);
4638 class_unregister(&iscsi_iface_class);
4639 class_unregister(&iscsi_transport_class);
4642 module_init(iscsi_transport_init);
4643 module_exit(iscsi_transport_exit);
4645 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
4646 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
4647 "Alex Aizman <itn780@yahoo.com>");
4648 MODULE_DESCRIPTION("iSCSI Transport Interface");
4649 MODULE_LICENSE("GPL");
4650 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
4651 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);