diff options
Diffstat (limited to 'drivers/scsi/scsi_transport_fc.c')
-rw-r--r-- | drivers/scsi/scsi_transport_fc.c | 831 |
1 files changed, 803 insertions, 28 deletions
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index b4d1ece46f78..e8825709797e 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * FiberChannel transport specific attributes exported to sysfs. | 2 | * FiberChannel transport specific attributes exported to sysfs. |
3 | * | 3 | * |
4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. | 4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. |
@@ -19,9 +19,10 @@ | |||
19 | * | 19 | * |
20 | * ======== | 20 | * ======== |
21 | * | 21 | * |
22 | * Copyright (C) 2004-2005 James Smart, Emulex Corporation | 22 | * Copyright (C) 2004-2007 James Smart, Emulex Corporation |
23 | * Rewrite for host, target, device, and remote port attributes, | 23 | * Rewrite for host, target, device, and remote port attributes, |
24 | * statistics, and service functions... | 24 | * statistics, and service functions... |
25 | * Add vports, etc | ||
25 | * | 26 | * |
26 | */ | 27 | */ |
27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
@@ -37,6 +38,34 @@ | |||
37 | #include "scsi_priv.h" | 38 | #include "scsi_priv.h" |
38 | 39 | ||
39 | static int fc_queue_work(struct Scsi_Host *, struct work_struct *); | 40 | static int fc_queue_work(struct Scsi_Host *, struct work_struct *); |
41 | static void fc_vport_sched_delete(struct work_struct *work); | ||
42 | |||
43 | /* | ||
44 | * This is a temporary carrier for creating a vport. It will eventually | ||
45 | * be replaced by a real message definition for sgio or netlink. | ||
46 | * | ||
47 | * fc_vport_identifiers: This set of data contains all elements | ||
48 | * to uniquely identify and instantiate a FC virtual port. | ||
49 | * | ||
50 | * Notes: | ||
51 | * symbolic_name: The driver is to append the symbolic_name string data | ||
52 | * to the symbolic_node_name data that it generates by default. | ||
53 | * the resulting combination should then be registered with the switch. | ||
54 | * It is expected that things like Xen may stuff a VM title into | ||
55 | * this field. | ||
56 | */ | ||
57 | struct fc_vport_identifiers { | ||
58 | u64 node_name; | ||
59 | u64 port_name; | ||
60 | u32 roles; | ||
61 | bool disable; | ||
62 | enum fc_port_type vport_type; /* only FC_PORTTYPE_NPIV allowed */ | ||
63 | char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN]; | ||
64 | }; | ||
65 | |||
66 | static int fc_vport_create(struct Scsi_Host *shost, int channel, | ||
67 | struct device *pdev, struct fc_vport_identifiers *ids, | ||
68 | struct fc_vport **vport); | ||
40 | 69 | ||
41 | /* | 70 | /* |
42 | * Redefine so that we can have same named attributes in the | 71 | * Redefine so that we can have same named attributes in the |
@@ -90,10 +119,14 @@ static struct { | |||
90 | { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" }, | 119 | { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" }, |
91 | { FC_PORTTYPE_LPORT, "LPort (private loop)" }, | 120 | { FC_PORTTYPE_LPORT, "LPort (private loop)" }, |
92 | { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" }, | 121 | { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" }, |
122 | { FC_PORTTYPE_NPIV, "NPIV VPORT" }, | ||
93 | }; | 123 | }; |
94 | fc_enum_name_search(port_type, fc_port_type, fc_port_type_names) | 124 | fc_enum_name_search(port_type, fc_port_type, fc_port_type_names) |
95 | #define FC_PORTTYPE_MAX_NAMELEN 50 | 125 | #define FC_PORTTYPE_MAX_NAMELEN 50 |
96 | 126 | ||
127 | /* Reuse fc_port_type enum function for vport_type */ | ||
128 | #define get_fc_vport_type_name get_fc_port_type_name | ||
129 | |||
97 | 130 | ||
98 | /* Convert fc_host_event_code values to ascii string name */ | 131 | /* Convert fc_host_event_code values to ascii string name */ |
99 | static const struct { | 132 | static const struct { |
@@ -139,6 +172,29 @@ fc_enum_name_search(port_state, fc_port_state, fc_port_state_names) | |||
139 | #define FC_PORTSTATE_MAX_NAMELEN 20 | 172 | #define FC_PORTSTATE_MAX_NAMELEN 20 |
140 | 173 | ||
141 | 174 | ||
175 | /* Convert fc_vport_state values to ascii string name */ | ||
176 | static struct { | ||
177 | enum fc_vport_state value; | ||
178 | char *name; | ||
179 | } fc_vport_state_names[] = { | ||
180 | { FC_VPORT_UNKNOWN, "Unknown" }, | ||
181 | { FC_VPORT_ACTIVE, "Active" }, | ||
182 | { FC_VPORT_DISABLED, "Disabled" }, | ||
183 | { FC_VPORT_LINKDOWN, "Linkdown" }, | ||
184 | { FC_VPORT_INITIALIZING, "Initializing" }, | ||
185 | { FC_VPORT_NO_FABRIC_SUPP, "No Fabric Support" }, | ||
186 | { FC_VPORT_NO_FABRIC_RSCS, "No Fabric Resources" }, | ||
187 | { FC_VPORT_FABRIC_LOGOUT, "Fabric Logout" }, | ||
188 | { FC_VPORT_FABRIC_REJ_WWN, "Fabric Rejected WWN" }, | ||
189 | { FC_VPORT_FAILED, "VPort Failed" }, | ||
190 | }; | ||
191 | fc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names) | ||
192 | #define FC_VPORTSTATE_MAX_NAMELEN 24 | ||
193 | |||
194 | /* Reuse fc_vport_state enum function for vport_last_state */ | ||
195 | #define get_fc_vport_last_state_name get_fc_vport_state_name | ||
196 | |||
197 | |||
142 | /* Convert fc_tgtid_binding_type values to ascii string name */ | 198 | /* Convert fc_tgtid_binding_type values to ascii string name */ |
143 | static const struct { | 199 | static const struct { |
144 | enum fc_tgtid_binding_type value; | 200 | enum fc_tgtid_binding_type value; |
@@ -219,16 +275,16 @@ show_fc_fc4s (char *buf, u8 *fc4_list) | |||
219 | } | 275 | } |
220 | 276 | ||
221 | 277 | ||
222 | /* Convert FC_RPORT_ROLE bit values to ascii string name */ | 278 | /* Convert FC_PORT_ROLE bit values to ascii string name */ |
223 | static const struct { | 279 | static const struct { |
224 | u32 value; | 280 | u32 value; |
225 | char *name; | 281 | char *name; |
226 | } fc_remote_port_role_names[] = { | 282 | } fc_port_role_names[] = { |
227 | { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" }, | 283 | { FC_PORT_ROLE_FCP_TARGET, "FCP Target" }, |
228 | { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" }, | 284 | { FC_PORT_ROLE_FCP_INITIATOR, "FCP Initiator" }, |
229 | { FC_RPORT_ROLE_IP_PORT, "IP Port" }, | 285 | { FC_PORT_ROLE_IP_PORT, "IP Port" }, |
230 | }; | 286 | }; |
231 | fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names) | 287 | fc_bitfield_name_search(port_roles, fc_port_role_names) |
232 | 288 | ||
233 | /* | 289 | /* |
234 | * Define roles that are specific to port_id. Values are relative to ROLE_MASK. | 290 | * Define roles that are specific to port_id. Values are relative to ROLE_MASK. |
@@ -252,7 +308,8 @@ static void fc_scsi_scan_rport(struct work_struct *work); | |||
252 | */ | 308 | */ |
253 | #define FC_STARGET_NUM_ATTRS 3 | 309 | #define FC_STARGET_NUM_ATTRS 3 |
254 | #define FC_RPORT_NUM_ATTRS 10 | 310 | #define FC_RPORT_NUM_ATTRS 10 |
255 | #define FC_HOST_NUM_ATTRS 17 | 311 | #define FC_VPORT_NUM_ATTRS 9 |
312 | #define FC_HOST_NUM_ATTRS 21 | ||
256 | 313 | ||
257 | struct fc_internal { | 314 | struct fc_internal { |
258 | struct scsi_transport_template t; | 315 | struct scsi_transport_template t; |
@@ -278,6 +335,10 @@ struct fc_internal { | |||
278 | struct transport_container rport_attr_cont; | 335 | struct transport_container rport_attr_cont; |
279 | struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS]; | 336 | struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS]; |
280 | struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1]; | 337 | struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1]; |
338 | |||
339 | struct transport_container vport_attr_cont; | ||
340 | struct class_device_attribute private_vport_attrs[FC_VPORT_NUM_ATTRS]; | ||
341 | struct class_device_attribute *vport_attrs[FC_VPORT_NUM_ATTRS + 1]; | ||
281 | }; | 342 | }; |
282 | 343 | ||
283 | #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) | 344 | #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) |
@@ -318,7 +379,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev, | |||
318 | struct Scsi_Host *shost = dev_to_shost(dev); | 379 | struct Scsi_Host *shost = dev_to_shost(dev); |
319 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); | 380 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
320 | 381 | ||
321 | /* | 382 | /* |
322 | * Set default values easily detected by the midlayer as | 383 | * Set default values easily detected by the midlayer as |
323 | * failure cases. The scsi lldd is responsible for initializing | 384 | * failure cases. The scsi lldd is responsible for initializing |
324 | * all transport attributes to valid values per host. | 385 | * all transport attributes to valid values per host. |
@@ -331,6 +392,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev, | |||
331 | sizeof(fc_host->supported_fc4s)); | 392 | sizeof(fc_host->supported_fc4s)); |
332 | fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; | 393 | fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; |
333 | fc_host->maxframe_size = -1; | 394 | fc_host->maxframe_size = -1; |
395 | fc_host->max_npiv_vports = 0; | ||
334 | memset(fc_host->serial_number, 0, | 396 | memset(fc_host->serial_number, 0, |
335 | sizeof(fc_host->serial_number)); | 397 | sizeof(fc_host->serial_number)); |
336 | 398 | ||
@@ -348,8 +410,11 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev, | |||
348 | 410 | ||
349 | INIT_LIST_HEAD(&fc_host->rports); | 411 | INIT_LIST_HEAD(&fc_host->rports); |
350 | INIT_LIST_HEAD(&fc_host->rport_bindings); | 412 | INIT_LIST_HEAD(&fc_host->rport_bindings); |
413 | INIT_LIST_HEAD(&fc_host->vports); | ||
351 | fc_host->next_rport_number = 0; | 414 | fc_host->next_rport_number = 0; |
352 | fc_host->next_target_id = 0; | 415 | fc_host->next_target_id = 0; |
416 | fc_host->next_vport_number = 0; | ||
417 | fc_host->npiv_vports_inuse = 0; | ||
353 | 418 | ||
354 | snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d", | 419 | snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d", |
355 | shost->host_no); | 420 | shost->host_no); |
@@ -388,6 +453,16 @@ static DECLARE_TRANSPORT_CLASS(fc_rport_class, | |||
388 | NULL); | 453 | NULL); |
389 | 454 | ||
390 | /* | 455 | /* |
456 | * Setup and Remove actions for virtual ports are handled | ||
457 | * in the service functions below. | ||
458 | */ | ||
459 | static DECLARE_TRANSPORT_CLASS(fc_vport_class, | ||
460 | "fc_vports", | ||
461 | NULL, | ||
462 | NULL, | ||
463 | NULL); | ||
464 | |||
465 | /* | ||
391 | * Module Parameters | 466 | * Module Parameters |
392 | */ | 467 | */ |
393 | 468 | ||
@@ -585,6 +660,9 @@ static __init int fc_transport_init(void) | |||
585 | error = transport_class_register(&fc_host_class); | 660 | error = transport_class_register(&fc_host_class); |
586 | if (error) | 661 | if (error) |
587 | return error; | 662 | return error; |
663 | error = transport_class_register(&fc_vport_class); | ||
664 | if (error) | ||
665 | return error; | ||
588 | error = transport_class_register(&fc_rport_class); | 666 | error = transport_class_register(&fc_rport_class); |
589 | if (error) | 667 | if (error) |
590 | return error; | 668 | return error; |
@@ -596,6 +674,7 @@ static void __exit fc_transport_exit(void) | |||
596 | transport_class_unregister(&fc_transport_class); | 674 | transport_class_unregister(&fc_transport_class); |
597 | transport_class_unregister(&fc_rport_class); | 675 | transport_class_unregister(&fc_rport_class); |
598 | transport_class_unregister(&fc_host_class); | 676 | transport_class_unregister(&fc_host_class); |
677 | transport_class_unregister(&fc_vport_class); | ||
599 | } | 678 | } |
600 | 679 | ||
601 | /* | 680 | /* |
@@ -800,9 +879,9 @@ show_fc_rport_roles (struct class_device *cdev, char *buf) | |||
800 | return snprintf(buf, 30, "Unknown Fabric Entity\n"); | 879 | return snprintf(buf, 30, "Unknown Fabric Entity\n"); |
801 | } | 880 | } |
802 | } else { | 881 | } else { |
803 | if (rport->roles == FC_RPORT_ROLE_UNKNOWN) | 882 | if (rport->roles == FC_PORT_ROLE_UNKNOWN) |
804 | return snprintf(buf, 20, "unknown\n"); | 883 | return snprintf(buf, 20, "unknown\n"); |
805 | return get_fc_remote_port_roles_names(rport->roles, buf); | 884 | return get_fc_port_roles_names(rport->roles, buf); |
806 | } | 885 | } |
807 | } | 886 | } |
808 | static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO, | 887 | static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO, |
@@ -857,7 +936,7 @@ static FC_CLASS_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR, | |||
857 | 936 | ||
858 | /* | 937 | /* |
859 | * Note: in the target show function we recognize when the remote | 938 | * Note: in the target show function we recognize when the remote |
860 | * port is in the hierarchy and do not allow the driver to get | 939 | * port is in the heirarchy and do not allow the driver to get |
861 | * involved in sysfs functions. The driver only gets involved if | 940 | * involved in sysfs functions. The driver only gets involved if |
862 | * it's the "old" style that doesn't use rports. | 941 | * it's the "old" style that doesn't use rports. |
863 | */ | 942 | */ |
@@ -912,6 +991,257 @@ fc_starget_rd_attr(port_id, "0x%06x\n", 20); | |||
912 | 991 | ||
913 | 992 | ||
914 | /* | 993 | /* |
994 | * FC Virtual Port Attribute Management | ||
995 | */ | ||
996 | |||
997 | #define fc_vport_show_function(field, format_string, sz, cast) \ | ||
998 | static ssize_t \ | ||
999 | show_fc_vport_##field (struct class_device *cdev, char *buf) \ | ||
1000 | { \ | ||
1001 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1002 | struct Scsi_Host *shost = vport_to_shost(vport); \ | ||
1003 | struct fc_internal *i = to_fc_internal(shost->transportt); \ | ||
1004 | if ((i->f->get_vport_##field) && \ | ||
1005 | !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \ | ||
1006 | i->f->get_vport_##field(vport); \ | ||
1007 | return snprintf(buf, sz, format_string, cast vport->field); \ | ||
1008 | } | ||
1009 | |||
1010 | #define fc_vport_store_function(field) \ | ||
1011 | static ssize_t \ | ||
1012 | store_fc_vport_##field(struct class_device *cdev, const char *buf, \ | ||
1013 | size_t count) \ | ||
1014 | { \ | ||
1015 | int val; \ | ||
1016 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1017 | struct Scsi_Host *shost = vport_to_shost(vport); \ | ||
1018 | struct fc_internal *i = to_fc_internal(shost->transportt); \ | ||
1019 | char *cp; \ | ||
1020 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \ | ||
1021 | return -EBUSY; \ | ||
1022 | val = simple_strtoul(buf, &cp, 0); \ | ||
1023 | if (*cp && (*cp != '\n')) \ | ||
1024 | return -EINVAL; \ | ||
1025 | i->f->set_vport_##field(vport, val); \ | ||
1026 | return count; \ | ||
1027 | } | ||
1028 | |||
1029 | #define fc_vport_store_str_function(field, slen) \ | ||
1030 | static ssize_t \ | ||
1031 | store_fc_vport_##field(struct class_device *cdev, const char *buf, \ | ||
1032 | size_t count) \ | ||
1033 | { \ | ||
1034 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1035 | struct Scsi_Host *shost = vport_to_shost(vport); \ | ||
1036 | struct fc_internal *i = to_fc_internal(shost->transportt); \ | ||
1037 | unsigned int cnt=count; \ | ||
1038 | \ | ||
1039 | /* count may include a LF at end of string */ \ | ||
1040 | if (buf[cnt-1] == '\n') \ | ||
1041 | cnt--; \ | ||
1042 | if (cnt > ((slen) - 1)) \ | ||
1043 | return -EINVAL; \ | ||
1044 | memcpy(vport->field, buf, cnt); \ | ||
1045 | i->f->set_vport_##field(vport); \ | ||
1046 | return count; \ | ||
1047 | } | ||
1048 | |||
1049 | #define fc_vport_rd_attr(field, format_string, sz) \ | ||
1050 | fc_vport_show_function(field, format_string, sz, ) \ | ||
1051 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO, \ | ||
1052 | show_fc_vport_##field, NULL) | ||
1053 | |||
1054 | #define fc_vport_rd_attr_cast(field, format_string, sz, cast) \ | ||
1055 | fc_vport_show_function(field, format_string, sz, (cast)) \ | ||
1056 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO, \ | ||
1057 | show_fc_vport_##field, NULL) | ||
1058 | |||
1059 | #define fc_vport_rw_attr(field, format_string, sz) \ | ||
1060 | fc_vport_show_function(field, format_string, sz, ) \ | ||
1061 | fc_vport_store_function(field) \ | ||
1062 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ | ||
1063 | show_fc_vport_##field, \ | ||
1064 | store_fc_vport_##field) | ||
1065 | |||
1066 | #define fc_private_vport_show_function(field, format_string, sz, cast) \ | ||
1067 | static ssize_t \ | ||
1068 | show_fc_vport_##field (struct class_device *cdev, char *buf) \ | ||
1069 | { \ | ||
1070 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1071 | return snprintf(buf, sz, format_string, cast vport->field); \ | ||
1072 | } | ||
1073 | |||
1074 | #define fc_private_vport_store_u32_function(field) \ | ||
1075 | static ssize_t \ | ||
1076 | store_fc_vport_##field(struct class_device *cdev, const char *buf, \ | ||
1077 | size_t count) \ | ||
1078 | { \ | ||
1079 | u32 val; \ | ||
1080 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1081 | char *cp; \ | ||
1082 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \ | ||
1083 | return -EBUSY; \ | ||
1084 | val = simple_strtoul(buf, &cp, 0); \ | ||
1085 | if (*cp && (*cp != '\n')) \ | ||
1086 | return -EINVAL; \ | ||
1087 | vport->field = val; \ | ||
1088 | return count; \ | ||
1089 | } | ||
1090 | |||
1091 | |||
1092 | #define fc_private_vport_rd_attr(field, format_string, sz) \ | ||
1093 | fc_private_vport_show_function(field, format_string, sz, ) \ | ||
1094 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO, \ | ||
1095 | show_fc_vport_##field, NULL) | ||
1096 | |||
1097 | #define fc_private_vport_rd_attr_cast(field, format_string, sz, cast) \ | ||
1098 | fc_private_vport_show_function(field, format_string, sz, (cast)) \ | ||
1099 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO, \ | ||
1100 | show_fc_vport_##field, NULL) | ||
1101 | |||
1102 | #define fc_private_vport_rw_u32_attr(field, format_string, sz) \ | ||
1103 | fc_private_vport_show_function(field, format_string, sz, ) \ | ||
1104 | fc_private_vport_store_u32_function(field) \ | ||
1105 | static FC_CLASS_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ | ||
1106 | show_fc_vport_##field, \ | ||
1107 | store_fc_vport_##field) | ||
1108 | |||
1109 | |||
1110 | #define fc_private_vport_rd_enum_attr(title, maxlen) \ | ||
1111 | static ssize_t \ | ||
1112 | show_fc_vport_##title (struct class_device *cdev, char *buf) \ | ||
1113 | { \ | ||
1114 | struct fc_vport *vport = transport_class_to_vport(cdev); \ | ||
1115 | const char *name; \ | ||
1116 | name = get_fc_##title##_name(vport->title); \ | ||
1117 | if (!name) \ | ||
1118 | return -EINVAL; \ | ||
1119 | return snprintf(buf, maxlen, "%s\n", name); \ | ||
1120 | } \ | ||
1121 | static FC_CLASS_DEVICE_ATTR(vport, title, S_IRUGO, \ | ||
1122 | show_fc_vport_##title, NULL) | ||
1123 | |||
1124 | |||
1125 | #define SETUP_VPORT_ATTRIBUTE_RD(field) \ | ||
1126 | i->private_vport_attrs[count] = class_device_attr_vport_##field; \ | ||
1127 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ | ||
1128 | i->private_vport_attrs[count].store = NULL; \ | ||
1129 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ | ||
1130 | if (i->f->get_##field) \ | ||
1131 | count++ | ||
1132 | /* NOTE: Above MACRO differs: checks function not show bit */ | ||
1133 | |||
1134 | #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field) \ | ||
1135 | i->private_vport_attrs[count] = class_device_attr_vport_##field; \ | ||
1136 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ | ||
1137 | i->private_vport_attrs[count].store = NULL; \ | ||
1138 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ | ||
1139 | count++ | ||
1140 | |||
1141 | #define SETUP_VPORT_ATTRIBUTE_WR(field) \ | ||
1142 | i->private_vport_attrs[count] = class_device_attr_vport_##field; \ | ||
1143 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ | ||
1144 | if (i->f->field) \ | ||
1145 | count++ | ||
1146 | /* NOTE: Above MACRO differs: checks function */ | ||
1147 | |||
1148 | #define SETUP_VPORT_ATTRIBUTE_RW(field) \ | ||
1149 | i->private_vport_attrs[count] = class_device_attr_vport_##field; \ | ||
1150 | if (!i->f->set_vport_##field) { \ | ||
1151 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ | ||
1152 | i->private_vport_attrs[count].store = NULL; \ | ||
1153 | } \ | ||
1154 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ | ||
1155 | count++ | ||
1156 | /* NOTE: Above MACRO differs: does not check show bit */ | ||
1157 | |||
1158 | #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field) \ | ||
1159 | { \ | ||
1160 | i->private_vport_attrs[count] = class_device_attr_vport_##field; \ | ||
1161 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ | ||
1162 | count++; \ | ||
1163 | } | ||
1164 | |||
1165 | |||
1166 | /* The FC Transport Virtual Port Attributes: */ | ||
1167 | |||
1168 | /* Fixed Virtual Port Attributes */ | ||
1169 | |||
1170 | /* Dynamic Virtual Port Attributes */ | ||
1171 | |||
1172 | /* Private Virtual Port Attributes */ | ||
1173 | |||
1174 | fc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN); | ||
1175 | fc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN); | ||
1176 | fc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); | ||
1177 | fc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); | ||
1178 | |||
1179 | static ssize_t | ||
1180 | show_fc_vport_roles (struct class_device *cdev, char *buf) | ||
1181 | { | ||
1182 | struct fc_vport *vport = transport_class_to_vport(cdev); | ||
1183 | |||
1184 | if (vport->roles == FC_PORT_ROLE_UNKNOWN) | ||
1185 | return snprintf(buf, 20, "unknown\n"); | ||
1186 | return get_fc_port_roles_names(vport->roles, buf); | ||
1187 | } | ||
1188 | static FC_CLASS_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL); | ||
1189 | |||
1190 | fc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN); | ||
1191 | |||
1192 | fc_private_vport_show_function(symbolic_name, "%s\n", | ||
1193 | FC_VPORT_SYMBOLIC_NAMELEN + 1, ) | ||
1194 | fc_vport_store_str_function(symbolic_name, FC_VPORT_SYMBOLIC_NAMELEN) | ||
1195 | static FC_CLASS_DEVICE_ATTR(vport, symbolic_name, S_IRUGO | S_IWUSR, | ||
1196 | show_fc_vport_symbolic_name, store_fc_vport_symbolic_name); | ||
1197 | |||
1198 | static ssize_t | ||
1199 | store_fc_vport_delete(struct class_device *cdev, const char *buf, | ||
1200 | size_t count) | ||
1201 | { | ||
1202 | struct fc_vport *vport = transport_class_to_vport(cdev); | ||
1203 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
1204 | |||
1205 | fc_queue_work(shost, &vport->vport_delete_work); | ||
1206 | return count; | ||
1207 | } | ||
1208 | static FC_CLASS_DEVICE_ATTR(vport, vport_delete, S_IWUSR, | ||
1209 | NULL, store_fc_vport_delete); | ||
1210 | |||
1211 | |||
1212 | /* | ||
1213 | * Enable/Disable vport | ||
1214 | * Write "1" to disable, write "0" to enable | ||
1215 | */ | ||
1216 | static ssize_t | ||
1217 | store_fc_vport_disable(struct class_device *cdev, const char *buf, | ||
1218 | size_t count) | ||
1219 | { | ||
1220 | struct fc_vport *vport = transport_class_to_vport(cdev); | ||
1221 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
1222 | struct fc_internal *i = to_fc_internal(shost->transportt); | ||
1223 | int stat; | ||
1224 | |||
1225 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) | ||
1226 | return -EBUSY; | ||
1227 | |||
1228 | if (*buf == '0') { | ||
1229 | if (vport->vport_state != FC_VPORT_DISABLED) | ||
1230 | return -EALREADY; | ||
1231 | } else if (*buf == '1') { | ||
1232 | if (vport->vport_state == FC_VPORT_DISABLED) | ||
1233 | return -EALREADY; | ||
1234 | } else | ||
1235 | return -EINVAL; | ||
1236 | |||
1237 | stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true)); | ||
1238 | return stat ? stat : count; | ||
1239 | } | ||
1240 | static FC_CLASS_DEVICE_ATTR(vport, vport_disable, S_IWUSR, | ||
1241 | NULL, store_fc_vport_disable); | ||
1242 | |||
1243 | |||
1244 | /* | ||
915 | * Host Attribute Management | 1245 | * Host Attribute Management |
916 | */ | 1246 | */ |
917 | 1247 | ||
@@ -1003,6 +1333,13 @@ static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL) | |||
1003 | if (i->f->show_host_##field) \ | 1333 | if (i->f->show_host_##field) \ |
1004 | count++ | 1334 | count++ |
1005 | 1335 | ||
1336 | #define SETUP_HOST_ATTRIBUTE_RD_NS(field) \ | ||
1337 | i->private_host_attrs[count] = class_device_attr_host_##field; \ | ||
1338 | i->private_host_attrs[count].attr.mode = S_IRUGO; \ | ||
1339 | i->private_host_attrs[count].store = NULL; \ | ||
1340 | i->host_attrs[count] = &i->private_host_attrs[count]; \ | ||
1341 | count++ | ||
1342 | |||
1006 | #define SETUP_HOST_ATTRIBUTE_RW(field) \ | 1343 | #define SETUP_HOST_ATTRIBUTE_RW(field) \ |
1007 | i->private_host_attrs[count] = class_device_attr_host_##field; \ | 1344 | i->private_host_attrs[count] = class_device_attr_host_##field; \ |
1008 | if (!i->f->set_host_##field) { \ | 1345 | if (!i->f->set_host_##field) { \ |
@@ -1090,6 +1427,7 @@ fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); | |||
1090 | fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20, | 1427 | fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20, |
1091 | unsigned long long); | 1428 | unsigned long long); |
1092 | fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20); | 1429 | fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20); |
1430 | fc_private_host_rd_attr(max_npiv_vports, "%u\n", 20); | ||
1093 | fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1)); | 1431 | fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1)); |
1094 | 1432 | ||
1095 | 1433 | ||
@@ -1210,6 +1548,9 @@ store_fc_private_host_issue_lip(struct class_device *cdev, | |||
1210 | static FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL, | 1548 | static FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL, |
1211 | store_fc_private_host_issue_lip); | 1549 | store_fc_private_host_issue_lip); |
1212 | 1550 | ||
1551 | fc_private_host_rd_attr(npiv_vports_inuse, "%u\n", 20); | ||
1552 | |||
1553 | |||
1213 | /* | 1554 | /* |
1214 | * Host Statistics Management | 1555 | * Host Statistics Management |
1215 | */ | 1556 | */ |
@@ -1285,7 +1626,6 @@ fc_reset_statistics(struct class_device *cdev, const char *buf, | |||
1285 | static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL, | 1626 | static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL, |
1286 | fc_reset_statistics); | 1627 | fc_reset_statistics); |
1287 | 1628 | ||
1288 | |||
1289 | static struct attribute *fc_statistics_attrs[] = { | 1629 | static struct attribute *fc_statistics_attrs[] = { |
1290 | &class_device_attr_host_seconds_since_last_reset.attr, | 1630 | &class_device_attr_host_seconds_since_last_reset.attr, |
1291 | &class_device_attr_host_tx_frames.attr, | 1631 | &class_device_attr_host_tx_frames.attr, |
@@ -1316,6 +1656,142 @@ static struct attribute_group fc_statistics_group = { | |||
1316 | .attrs = fc_statistics_attrs, | 1656 | .attrs = fc_statistics_attrs, |
1317 | }; | 1657 | }; |
1318 | 1658 | ||
1659 | |||
1660 | /* Host Vport Attributes */ | ||
1661 | |||
1662 | static int | ||
1663 | fc_parse_wwn(const char *ns, u64 *nm) | ||
1664 | { | ||
1665 | unsigned int i, j; | ||
1666 | u8 wwn[8]; | ||
1667 | |||
1668 | memset(wwn, 0, sizeof(wwn)); | ||
1669 | |||
1670 | /* Validate and store the new name */ | ||
1671 | for (i=0, j=0; i < 16; i++) { | ||
1672 | if ((*ns >= 'a') && (*ns <= 'f')) | ||
1673 | j = ((j << 4) | ((*ns++ -'a') + 10)); | ||
1674 | else if ((*ns >= 'A') && (*ns <= 'F')) | ||
1675 | j = ((j << 4) | ((*ns++ -'A') + 10)); | ||
1676 | else if ((*ns >= '0') && (*ns <= '9')) | ||
1677 | j = ((j << 4) | (*ns++ -'0')); | ||
1678 | else | ||
1679 | return -EINVAL; | ||
1680 | if (i % 2) { | ||
1681 | wwn[i/2] = j & 0xff; | ||
1682 | j = 0; | ||
1683 | } | ||
1684 | } | ||
1685 | |||
1686 | *nm = wwn_to_u64(wwn); | ||
1687 | |||
1688 | return 0; | ||
1689 | } | ||
1690 | |||
1691 | |||
1692 | /* | ||
1693 | * "Short-cut" sysfs variable to create a new vport on a FC Host. | ||
1694 | * Input is a string of the form "<WWPN>:<WWNN>". Other attributes | ||
1695 | * will default to a NPIV-based FCP_Initiator; The WWNs are specified | ||
1696 | * as hex characters, and may *not* contain any prefixes (e.g. 0x, x, etc) | ||
1697 | */ | ||
1698 | static ssize_t | ||
1699 | store_fc_host_vport_create(struct class_device *cdev, const char *buf, | ||
1700 | size_t count) | ||
1701 | { | ||
1702 | struct Scsi_Host *shost = transport_class_to_shost(cdev); | ||
1703 | struct fc_vport_identifiers vid; | ||
1704 | struct fc_vport *vport; | ||
1705 | unsigned int cnt=count; | ||
1706 | int stat; | ||
1707 | |||
1708 | memset(&vid, 0, sizeof(vid)); | ||
1709 | |||
1710 | /* count may include a LF at end of string */ | ||
1711 | if (buf[cnt-1] == '\n') | ||
1712 | cnt--; | ||
1713 | |||
1714 | /* validate we have enough characters for WWPN */ | ||
1715 | if ((cnt != (16+1+16)) || (buf[16] != ':')) | ||
1716 | return -EINVAL; | ||
1717 | |||
1718 | stat = fc_parse_wwn(&buf[0], &vid.port_name); | ||
1719 | if (stat) | ||
1720 | return stat; | ||
1721 | |||
1722 | stat = fc_parse_wwn(&buf[17], &vid.node_name); | ||
1723 | if (stat) | ||
1724 | return stat; | ||
1725 | |||
1726 | vid.roles = FC_PORT_ROLE_FCP_INITIATOR; | ||
1727 | vid.vport_type = FC_PORTTYPE_NPIV; | ||
1728 | /* vid.symbolic_name is already zero/NULL's */ | ||
1729 | vid.disable = false; /* always enabled */ | ||
1730 | |||
1731 | /* we only allow support on Channel 0 !!! */ | ||
1732 | stat = fc_vport_create(shost, 0, &shost->shost_gendev, &vid, &vport); | ||
1733 | return stat ? stat : count; | ||
1734 | } | ||
1735 | static FC_CLASS_DEVICE_ATTR(host, vport_create, S_IWUSR, NULL, | ||
1736 | store_fc_host_vport_create); | ||
1737 | |||
1738 | |||
1739 | /* | ||
1740 | * "Short-cut" sysfs variable to delete a vport on a FC Host. | ||
1741 | * Vport is identified by a string containing "<WWPN>:<WWNN>". | ||
1742 | * The WWNs are specified as hex characters, and may *not* contain | ||
1743 | * any prefixes (e.g. 0x, x, etc) | ||
1744 | */ | ||
1745 | static ssize_t | ||
1746 | store_fc_host_vport_delete(struct class_device *cdev, const char *buf, | ||
1747 | size_t count) | ||
1748 | { | ||
1749 | struct Scsi_Host *shost = transport_class_to_shost(cdev); | ||
1750 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); | ||
1751 | struct fc_vport *vport; | ||
1752 | u64 wwpn, wwnn; | ||
1753 | unsigned long flags; | ||
1754 | unsigned int cnt=count; | ||
1755 | int stat, match; | ||
1756 | |||
1757 | /* count may include a LF at end of string */ | ||
1758 | if (buf[cnt-1] == '\n') | ||
1759 | cnt--; | ||
1760 | |||
1761 | /* validate we have enough characters for WWPN */ | ||
1762 | if ((cnt != (16+1+16)) || (buf[16] != ':')) | ||
1763 | return -EINVAL; | ||
1764 | |||
1765 | stat = fc_parse_wwn(&buf[0], &wwpn); | ||
1766 | if (stat) | ||
1767 | return stat; | ||
1768 | |||
1769 | stat = fc_parse_wwn(&buf[17], &wwnn); | ||
1770 | if (stat) | ||
1771 | return stat; | ||
1772 | |||
1773 | spin_lock_irqsave(shost->host_lock, flags); | ||
1774 | match = 0; | ||
1775 | /* we only allow support on Channel 0 !!! */ | ||
1776 | list_for_each_entry(vport, &fc_host->vports, peers) { | ||
1777 | if ((vport->channel == 0) && | ||
1778 | (vport->port_name == wwpn) && (vport->node_name == wwnn)) { | ||
1779 | match = 1; | ||
1780 | break; | ||
1781 | } | ||
1782 | } | ||
1783 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
1784 | |||
1785 | if (!match) | ||
1786 | return -ENODEV; | ||
1787 | |||
1788 | stat = fc_vport_terminate(vport); | ||
1789 | return stat ? stat : count; | ||
1790 | } | ||
1791 | static FC_CLASS_DEVICE_ATTR(host, vport_delete, S_IWUSR, NULL, | ||
1792 | store_fc_host_vport_delete); | ||
1793 | |||
1794 | |||
1319 | static int fc_host_match(struct attribute_container *cont, | 1795 | static int fc_host_match(struct attribute_container *cont, |
1320 | struct device *dev) | 1796 | struct device *dev) |
1321 | { | 1797 | { |
@@ -1387,6 +1863,40 @@ static int fc_rport_match(struct attribute_container *cont, | |||
1387 | } | 1863 | } |
1388 | 1864 | ||
1389 | 1865 | ||
1866 | static void fc_vport_dev_release(struct device *dev) | ||
1867 | { | ||
1868 | struct fc_vport *vport = dev_to_vport(dev); | ||
1869 | put_device(dev->parent); /* release kobj parent */ | ||
1870 | kfree(vport); | ||
1871 | } | ||
1872 | |||
1873 | int scsi_is_fc_vport(const struct device *dev) | ||
1874 | { | ||
1875 | return dev->release == fc_vport_dev_release; | ||
1876 | } | ||
1877 | EXPORT_SYMBOL(scsi_is_fc_vport); | ||
1878 | |||
1879 | static int fc_vport_match(struct attribute_container *cont, | ||
1880 | struct device *dev) | ||
1881 | { | ||
1882 | struct fc_vport *vport; | ||
1883 | struct Scsi_Host *shost; | ||
1884 | struct fc_internal *i; | ||
1885 | |||
1886 | if (!scsi_is_fc_vport(dev)) | ||
1887 | return 0; | ||
1888 | vport = dev_to_vport(dev); | ||
1889 | |||
1890 | shost = vport_to_shost(vport); | ||
1891 | if (!shost->transportt || shost->transportt->host_attrs.ac.class | ||
1892 | != &fc_host_class.class) | ||
1893 | return 0; | ||
1894 | |||
1895 | i = to_fc_internal(shost->transportt); | ||
1896 | return &i->vport_attr_cont.ac == cont; | ||
1897 | } | ||
1898 | |||
1899 | |||
1390 | /** | 1900 | /** |
1391 | * fc_timed_out - FC Transport I/O timeout intercept handler | 1901 | * fc_timed_out - FC Transport I/O timeout intercept handler |
1392 | * | 1902 | * |
@@ -1433,6 +1943,9 @@ static int fc_user_scan(struct Scsi_Host *shost, uint channel, | |||
1433 | if (rport->scsi_target_id == -1) | 1943 | if (rport->scsi_target_id == -1) |
1434 | continue; | 1944 | continue; |
1435 | 1945 | ||
1946 | if (rport->port_state != FC_PORTSTATE_ONLINE) | ||
1947 | continue; | ||
1948 | |||
1436 | if ((channel == SCAN_WILD_CARD || channel == rport->channel) && | 1949 | if ((channel == SCAN_WILD_CARD || channel == rport->channel) && |
1437 | (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) { | 1950 | (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) { |
1438 | scsi_scan_target(&rport->dev, rport->channel, | 1951 | scsi_scan_target(&rport->dev, rport->channel, |
@@ -1472,6 +1985,11 @@ fc_attach_transport(struct fc_function_template *ft) | |||
1472 | i->rport_attr_cont.ac.match = fc_rport_match; | 1985 | i->rport_attr_cont.ac.match = fc_rport_match; |
1473 | transport_container_register(&i->rport_attr_cont); | 1986 | transport_container_register(&i->rport_attr_cont); |
1474 | 1987 | ||
1988 | i->vport_attr_cont.ac.attrs = &i->vport_attrs[0]; | ||
1989 | i->vport_attr_cont.ac.class = &fc_vport_class.class; | ||
1990 | i->vport_attr_cont.ac.match = fc_vport_match; | ||
1991 | transport_container_register(&i->vport_attr_cont); | ||
1992 | |||
1475 | i->f = ft; | 1993 | i->f = ft; |
1476 | 1994 | ||
1477 | /* Transport uses the shost workq for scsi scanning */ | 1995 | /* Transport uses the shost workq for scsi scanning */ |
@@ -1480,7 +1998,7 @@ fc_attach_transport(struct fc_function_template *ft) | |||
1480 | i->t.eh_timed_out = fc_timed_out; | 1998 | i->t.eh_timed_out = fc_timed_out; |
1481 | 1999 | ||
1482 | i->t.user_scan = fc_user_scan; | 2000 | i->t.user_scan = fc_user_scan; |
1483 | 2001 | ||
1484 | /* | 2002 | /* |
1485 | * Setup SCSI Target Attributes. | 2003 | * Setup SCSI Target Attributes. |
1486 | */ | 2004 | */ |
@@ -1505,6 +2023,10 @@ fc_attach_transport(struct fc_function_template *ft) | |||
1505 | SETUP_HOST_ATTRIBUTE_RD(supported_fc4s); | 2023 | SETUP_HOST_ATTRIBUTE_RD(supported_fc4s); |
1506 | SETUP_HOST_ATTRIBUTE_RD(supported_speeds); | 2024 | SETUP_HOST_ATTRIBUTE_RD(supported_speeds); |
1507 | SETUP_HOST_ATTRIBUTE_RD(maxframe_size); | 2025 | SETUP_HOST_ATTRIBUTE_RD(maxframe_size); |
2026 | if (ft->vport_create) { | ||
2027 | SETUP_HOST_ATTRIBUTE_RD_NS(max_npiv_vports); | ||
2028 | SETUP_HOST_ATTRIBUTE_RD_NS(npiv_vports_inuse); | ||
2029 | } | ||
1508 | SETUP_HOST_ATTRIBUTE_RD(serial_number); | 2030 | SETUP_HOST_ATTRIBUTE_RD(serial_number); |
1509 | 2031 | ||
1510 | SETUP_HOST_ATTRIBUTE_RD(port_id); | 2032 | SETUP_HOST_ATTRIBUTE_RD(port_id); |
@@ -1520,6 +2042,10 @@ fc_attach_transport(struct fc_function_template *ft) | |||
1520 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type); | 2042 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type); |
1521 | if (ft->issue_fc_host_lip) | 2043 | if (ft->issue_fc_host_lip) |
1522 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip); | 2044 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip); |
2045 | if (ft->vport_create) | ||
2046 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_create); | ||
2047 | if (ft->vport_delete) | ||
2048 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_delete); | ||
1523 | 2049 | ||
1524 | BUG_ON(count > FC_HOST_NUM_ATTRS); | 2050 | BUG_ON(count > FC_HOST_NUM_ATTRS); |
1525 | 2051 | ||
@@ -1545,6 +2071,24 @@ fc_attach_transport(struct fc_function_template *ft) | |||
1545 | 2071 | ||
1546 | i->rport_attrs[count] = NULL; | 2072 | i->rport_attrs[count] = NULL; |
1547 | 2073 | ||
2074 | /* | ||
2075 | * Setup Virtual Port Attributes. | ||
2076 | */ | ||
2077 | count=0; | ||
2078 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_state); | ||
2079 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_last_state); | ||
2080 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(node_name); | ||
2081 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(port_name); | ||
2082 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(roles); | ||
2083 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_type); | ||
2084 | SETUP_VPORT_ATTRIBUTE_RW(symbolic_name); | ||
2085 | SETUP_VPORT_ATTRIBUTE_WR(vport_delete); | ||
2086 | SETUP_VPORT_ATTRIBUTE_WR(vport_disable); | ||
2087 | |||
2088 | BUG_ON(count > FC_VPORT_NUM_ATTRS); | ||
2089 | |||
2090 | i->vport_attrs[count] = NULL; | ||
2091 | |||
1548 | return &i->t; | 2092 | return &i->t; |
1549 | } | 2093 | } |
1550 | EXPORT_SYMBOL(fc_attach_transport); | 2094 | EXPORT_SYMBOL(fc_attach_transport); |
@@ -1556,6 +2100,7 @@ void fc_release_transport(struct scsi_transport_template *t) | |||
1556 | transport_container_unregister(&i->t.target_attrs); | 2100 | transport_container_unregister(&i->t.target_attrs); |
1557 | transport_container_unregister(&i->t.host_attrs); | 2101 | transport_container_unregister(&i->t.host_attrs); |
1558 | transport_container_unregister(&i->rport_attr_cont); | 2102 | transport_container_unregister(&i->rport_attr_cont); |
2103 | transport_container_unregister(&i->vport_attr_cont); | ||
1559 | 2104 | ||
1560 | kfree(i); | 2105 | kfree(i); |
1561 | } | 2106 | } |
@@ -1667,9 +2212,17 @@ fc_flush_devloss(struct Scsi_Host *shost) | |||
1667 | void | 2212 | void |
1668 | fc_remove_host(struct Scsi_Host *shost) | 2213 | fc_remove_host(struct Scsi_Host *shost) |
1669 | { | 2214 | { |
1670 | struct fc_rport *rport, *next_rport; | 2215 | struct fc_vport *vport = NULL, *next_vport = NULL; |
2216 | struct fc_rport *rport = NULL, *next_rport = NULL; | ||
1671 | struct workqueue_struct *work_q; | 2217 | struct workqueue_struct *work_q; |
1672 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); | 2218 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
2219 | unsigned long flags; | ||
2220 | |||
2221 | spin_lock_irqsave(shost->host_lock, flags); | ||
2222 | |||
2223 | /* Remove any vports */ | ||
2224 | list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) | ||
2225 | fc_queue_work(shost, &vport->vport_delete_work); | ||
1673 | 2226 | ||
1674 | /* Remove any remote ports */ | 2227 | /* Remove any remote ports */ |
1675 | list_for_each_entry_safe(rport, next_rport, | 2228 | list_for_each_entry_safe(rport, next_rport, |
@@ -1686,6 +2239,8 @@ fc_remove_host(struct Scsi_Host *shost) | |||
1686 | fc_queue_work(shost, &rport->rport_delete_work); | 2239 | fc_queue_work(shost, &rport->rport_delete_work); |
1687 | } | 2240 | } |
1688 | 2241 | ||
2242 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
2243 | |||
1689 | /* flush all scan work items */ | 2244 | /* flush all scan work items */ |
1690 | scsi_flush_work(shost); | 2245 | scsi_flush_work(shost); |
1691 | 2246 | ||
@@ -1744,7 +2299,7 @@ fc_rport_final_delete(struct work_struct *work) | |||
1744 | unsigned long flags; | 2299 | unsigned long flags; |
1745 | 2300 | ||
1746 | /* | 2301 | /* |
1747 | * if a scan is pending, flush the SCSI Host work_q so that | 2302 | * if a scan is pending, flush the SCSI Host work_q so that |
1748 | * that we can reclaim the rport scan work element. | 2303 | * that we can reclaim the rport scan work element. |
1749 | */ | 2304 | */ |
1750 | if (rport->flags & FC_RPORT_SCAN_PENDING) | 2305 | if (rport->flags & FC_RPORT_SCAN_PENDING) |
@@ -1844,7 +2399,7 @@ fc_rport_create(struct Scsi_Host *shost, int channel, | |||
1844 | spin_lock_irqsave(shost->host_lock, flags); | 2399 | spin_lock_irqsave(shost->host_lock, flags); |
1845 | 2400 | ||
1846 | rport->number = fc_host->next_rport_number++; | 2401 | rport->number = fc_host->next_rport_number++; |
1847 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) | 2402 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) |
1848 | rport->scsi_target_id = fc_host->next_target_id++; | 2403 | rport->scsi_target_id = fc_host->next_target_id++; |
1849 | else | 2404 | else |
1850 | rport->scsi_target_id = -1; | 2405 | rport->scsi_target_id = -1; |
@@ -1869,7 +2424,7 @@ fc_rport_create(struct Scsi_Host *shost, int channel, | |||
1869 | transport_add_device(dev); | 2424 | transport_add_device(dev); |
1870 | transport_configure_device(dev); | 2425 | transport_configure_device(dev); |
1871 | 2426 | ||
1872 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) { | 2427 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { |
1873 | /* initiate a scan of the target */ | 2428 | /* initiate a scan of the target */ |
1874 | rport->flags |= FC_RPORT_SCAN_PENDING; | 2429 | rport->flags |= FC_RPORT_SCAN_PENDING; |
1875 | scsi_queue_work(shost, &rport->scan_work); | 2430 | scsi_queue_work(shost, &rport->scan_work); |
@@ -2003,7 +2558,7 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel, | |||
2003 | 2558 | ||
2004 | /* was a target, not in roles */ | 2559 | /* was a target, not in roles */ |
2005 | if ((rport->scsi_target_id != -1) && | 2560 | if ((rport->scsi_target_id != -1) && |
2006 | (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET))) | 2561 | (!(ids->roles & FC_PORT_ROLE_FCP_TARGET))) |
2007 | return rport; | 2562 | return rport; |
2008 | 2563 | ||
2009 | /* | 2564 | /* |
@@ -2086,7 +2641,7 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel, | |||
2086 | memset(rport->dd_data, 0, | 2641 | memset(rport->dd_data, 0, |
2087 | fci->f->dd_fcrport_size); | 2642 | fci->f->dd_fcrport_size); |
2088 | 2643 | ||
2089 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) { | 2644 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { |
2090 | /* initiate a scan of the target */ | 2645 | /* initiate a scan of the target */ |
2091 | rport->flags |= FC_RPORT_SCAN_PENDING; | 2646 | rport->flags |= FC_RPORT_SCAN_PENDING; |
2092 | scsi_queue_work(shost, &rport->scan_work); | 2647 | scsi_queue_work(shost, &rport->scan_work); |
@@ -2243,11 +2798,11 @@ fc_remote_port_rolechg(struct fc_rport *rport, u32 roles) | |||
2243 | int create = 0; | 2798 | int create = 0; |
2244 | 2799 | ||
2245 | spin_lock_irqsave(shost->host_lock, flags); | 2800 | spin_lock_irqsave(shost->host_lock, flags); |
2246 | if (roles & FC_RPORT_ROLE_FCP_TARGET) { | 2801 | if (roles & FC_PORT_ROLE_FCP_TARGET) { |
2247 | if (rport->scsi_target_id == -1) { | 2802 | if (rport->scsi_target_id == -1) { |
2248 | rport->scsi_target_id = fc_host->next_target_id++; | 2803 | rport->scsi_target_id = fc_host->next_target_id++; |
2249 | create = 1; | 2804 | create = 1; |
2250 | } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) | 2805 | } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET)) |
2251 | create = 1; | 2806 | create = 1; |
2252 | } | 2807 | } |
2253 | 2808 | ||
@@ -2294,7 +2849,7 @@ EXPORT_SYMBOL(fc_remote_port_rolechg); | |||
2294 | * fc_timeout_deleted_rport - Timeout handler for a deleted remote port, | 2849 | * fc_timeout_deleted_rport - Timeout handler for a deleted remote port, |
2295 | * which we blocked, and has now failed to return | 2850 | * which we blocked, and has now failed to return |
2296 | * in the allotted time. | 2851 | * in the allotted time. |
2297 | * | 2852 | * |
2298 | * @work: rport target that failed to reappear in the allotted time. | 2853 | * @work: rport target that failed to reappear in the allotted time. |
2299 | **/ | 2854 | **/ |
2300 | static void | 2855 | static void |
@@ -2317,7 +2872,7 @@ fc_timeout_deleted_rport(struct work_struct *work) | |||
2317 | */ | 2872 | */ |
2318 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && | 2873 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && |
2319 | (rport->scsi_target_id != -1) && | 2874 | (rport->scsi_target_id != -1) && |
2320 | !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { | 2875 | !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) { |
2321 | dev_printk(KERN_ERR, &rport->dev, | 2876 | dev_printk(KERN_ERR, &rport->dev, |
2322 | "blocked FC remote port time out: no longer" | 2877 | "blocked FC remote port time out: no longer" |
2323 | " a FCP target, removing starget\n"); | 2878 | " a FCP target, removing starget\n"); |
@@ -2367,7 +2922,7 @@ fc_timeout_deleted_rport(struct work_struct *work) | |||
2367 | */ | 2922 | */ |
2368 | rport->maxframe_size = -1; | 2923 | rport->maxframe_size = -1; |
2369 | rport->supported_classes = FC_COS_UNSPECIFIED; | 2924 | rport->supported_classes = FC_COS_UNSPECIFIED; |
2370 | rport->roles = FC_RPORT_ROLE_UNKNOWN; | 2925 | rport->roles = FC_PORT_ROLE_UNKNOWN; |
2371 | rport->port_state = FC_PORTSTATE_NOTPRESENT; | 2926 | rport->port_state = FC_PORTSTATE_NOTPRESENT; |
2372 | 2927 | ||
2373 | /* remove the identifiers that aren't used in the consisting binding */ | 2928 | /* remove the identifiers that aren't used in the consisting binding */ |
@@ -2436,7 +2991,7 @@ fc_scsi_scan_rport(struct work_struct *work) | |||
2436 | unsigned long flags; | 2991 | unsigned long flags; |
2437 | 2992 | ||
2438 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && | 2993 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && |
2439 | (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { | 2994 | (rport->roles & FC_PORT_ROLE_FCP_TARGET)) { |
2440 | scsi_scan_target(&rport->dev, rport->channel, | 2995 | scsi_scan_target(&rport->dev, rport->channel, |
2441 | rport->scsi_target_id, SCAN_WILD_CARD, 1); | 2996 | rport->scsi_target_id, SCAN_WILD_CARD, 1); |
2442 | } | 2997 | } |
@@ -2447,7 +3002,227 @@ fc_scsi_scan_rport(struct work_struct *work) | |||
2447 | } | 3002 | } |
2448 | 3003 | ||
2449 | 3004 | ||
2450 | MODULE_AUTHOR("Martin Hicks"); | 3005 | /** |
3006 | * fc_vport_create - allocates and creates a FC virtual port. | ||
3007 | * @shost: scsi host the virtual port is connected to. | ||
3008 | * @channel: Channel on shost port connected to. | ||
3009 | * @pdev: parent device for vport | ||
3010 | * @ids: The world wide names, FC4 port roles, etc for | ||
3011 | * the virtual port. | ||
3012 | * @ret_vport: The pointer to the created vport. | ||
3013 | * | ||
3014 | * Allocates and creates the vport structure, calls the parent host | ||
3015 | * to instantiate the vport, the completes w/ class and sysfs creation. | ||
3016 | * | ||
3017 | * Notes: | ||
3018 | * This routine assumes no locks are held on entry. | ||
3019 | **/ | ||
3020 | static int | ||
3021 | fc_vport_create(struct Scsi_Host *shost, int channel, struct device *pdev, | ||
3022 | struct fc_vport_identifiers *ids, struct fc_vport **ret_vport) | ||
3023 | { | ||
3024 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); | ||
3025 | struct fc_internal *fci = to_fc_internal(shost->transportt); | ||
3026 | struct fc_vport *vport; | ||
3027 | struct device *dev; | ||
3028 | unsigned long flags; | ||
3029 | size_t size; | ||
3030 | int error; | ||
3031 | |||
3032 | *ret_vport = NULL; | ||
3033 | |||
3034 | if ( ! fci->f->vport_create) | ||
3035 | return -ENOENT; | ||
3036 | |||
3037 | size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size); | ||
3038 | vport = kzalloc(size, GFP_KERNEL); | ||
3039 | if (unlikely(!vport)) { | ||
3040 | printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__); | ||
3041 | return -ENOMEM; | ||
3042 | } | ||
3043 | |||
3044 | vport->vport_state = FC_VPORT_UNKNOWN; | ||
3045 | vport->vport_last_state = FC_VPORT_UNKNOWN; | ||
3046 | vport->node_name = ids->node_name; | ||
3047 | vport->port_name = ids->port_name; | ||
3048 | vport->roles = ids->roles; | ||
3049 | vport->vport_type = ids->vport_type; | ||
3050 | if (fci->f->dd_fcvport_size) | ||
3051 | vport->dd_data = &vport[1]; | ||
3052 | vport->shost = shost; | ||
3053 | vport->channel = channel; | ||
3054 | vport->flags = FC_VPORT_CREATING; | ||
3055 | INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete); | ||
3056 | |||
3057 | spin_lock_irqsave(shost->host_lock, flags); | ||
3058 | |||
3059 | if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) { | ||
3060 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3061 | kfree(vport); | ||
3062 | return -ENOSPC; | ||
3063 | } | ||
3064 | fc_host->npiv_vports_inuse++; | ||
3065 | vport->number = fc_host->next_vport_number++; | ||
3066 | list_add_tail(&vport->peers, &fc_host->vports); | ||
3067 | get_device(&shost->shost_gendev); /* for fc_host->vport list */ | ||
3068 | |||
3069 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3070 | |||
3071 | dev = &vport->dev; | ||
3072 | device_initialize(dev); /* takes self reference */ | ||
3073 | dev->parent = get_device(pdev); /* takes parent reference */ | ||
3074 | dev->release = fc_vport_dev_release; | ||
3075 | sprintf(dev->bus_id, "vport-%d:%d-%d", | ||
3076 | shost->host_no, channel, vport->number); | ||
3077 | transport_setup_device(dev); | ||
3078 | |||
3079 | error = device_add(dev); | ||
3080 | if (error) { | ||
3081 | printk(KERN_ERR "FC Virtual Port device_add failed\n"); | ||
3082 | goto delete_vport; | ||
3083 | } | ||
3084 | transport_add_device(dev); | ||
3085 | transport_configure_device(dev); | ||
3086 | |||
3087 | error = fci->f->vport_create(vport, ids->disable); | ||
3088 | if (error) { | ||
3089 | printk(KERN_ERR "FC Virtual Port LLDD Create failed\n"); | ||
3090 | goto delete_vport_all; | ||
3091 | } | ||
3092 | |||
3093 | /* | ||
3094 | * if the parent isn't the physical adapter's Scsi_Host, ensure | ||
3095 | * the Scsi_Host at least contains ia symlink to the vport. | ||
3096 | */ | ||
3097 | if (pdev != &shost->shost_gendev) { | ||
3098 | error = sysfs_create_link(&shost->shost_gendev.kobj, | ||
3099 | &dev->kobj, dev->bus_id); | ||
3100 | if (error) | ||
3101 | printk(KERN_ERR | ||
3102 | "%s: Cannot create vport symlinks for " | ||
3103 | "%s, err=%d\n", | ||
3104 | __FUNCTION__, dev->bus_id, error); | ||
3105 | } | ||
3106 | spin_lock_irqsave(shost->host_lock, flags); | ||
3107 | vport->flags &= ~FC_VPORT_CREATING; | ||
3108 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3109 | |||
3110 | dev_printk(KERN_NOTICE, pdev, | ||
3111 | "%s created via shost%d channel %d\n", dev->bus_id, | ||
3112 | shost->host_no, channel); | ||
3113 | |||
3114 | *ret_vport = vport; | ||
3115 | |||
3116 | return 0; | ||
3117 | |||
3118 | delete_vport_all: | ||
3119 | transport_remove_device(dev); | ||
3120 | device_del(dev); | ||
3121 | delete_vport: | ||
3122 | transport_destroy_device(dev); | ||
3123 | spin_lock_irqsave(shost->host_lock, flags); | ||
3124 | list_del(&vport->peers); | ||
3125 | put_device(&shost->shost_gendev); /* for fc_host->vport list */ | ||
3126 | fc_host->npiv_vports_inuse--; | ||
3127 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3128 | put_device(dev->parent); | ||
3129 | kfree(vport); | ||
3130 | |||
3131 | return error; | ||
3132 | } | ||
3133 | |||
3134 | |||
3135 | /** | ||
3136 | * fc_vport_terminate - Admin App or LLDD requests termination of a vport | ||
3137 | * @vport: fc_vport to be terminated | ||
3138 | * | ||
3139 | * Calls the LLDD vport_delete() function, then deallocates and removes | ||
3140 | * the vport from the shost and object tree. | ||
3141 | * | ||
3142 | * Notes: | ||
3143 | * This routine assumes no locks are held on entry. | ||
3144 | **/ | ||
3145 | int | ||
3146 | fc_vport_terminate(struct fc_vport *vport) | ||
3147 | { | ||
3148 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
3149 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); | ||
3150 | struct fc_internal *i = to_fc_internal(shost->transportt); | ||
3151 | struct device *dev = &vport->dev; | ||
3152 | unsigned long flags; | ||
3153 | int stat; | ||
3154 | |||
3155 | spin_lock_irqsave(shost->host_lock, flags); | ||
3156 | if (vport->flags & FC_VPORT_CREATING) { | ||
3157 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3158 | return -EBUSY; | ||
3159 | } | ||
3160 | if (vport->flags & (FC_VPORT_DEL)) { | ||
3161 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3162 | return -EALREADY; | ||
3163 | } | ||
3164 | vport->flags |= FC_VPORT_DELETING; | ||
3165 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3166 | |||
3167 | if (i->f->vport_delete) | ||
3168 | stat = i->f->vport_delete(vport); | ||
3169 | else | ||
3170 | stat = -ENOENT; | ||
3171 | |||
3172 | spin_lock_irqsave(shost->host_lock, flags); | ||
3173 | vport->flags &= ~FC_VPORT_DELETING; | ||
3174 | if (!stat) { | ||
3175 | vport->flags |= FC_VPORT_DELETED; | ||
3176 | list_del(&vport->peers); | ||
3177 | fc_host->npiv_vports_inuse--; | ||
3178 | put_device(&shost->shost_gendev); /* for fc_host->vport list */ | ||
3179 | } | ||
3180 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
3181 | |||
3182 | if (stat) | ||
3183 | return stat; | ||
3184 | |||
3185 | if (dev->parent != &shost->shost_gendev) | ||
3186 | sysfs_remove_link(&shost->shost_gendev.kobj, dev->bus_id); | ||
3187 | transport_remove_device(dev); | ||
3188 | device_del(dev); | ||
3189 | transport_destroy_device(dev); | ||
3190 | |||
3191 | /* | ||
3192 | * Removing our self-reference should mean our | ||
3193 | * release function gets called, which will drop the remaining | ||
3194 | * parent reference and free the data structure. | ||
3195 | */ | ||
3196 | put_device(dev); /* for self-reference */ | ||
3197 | |||
3198 | return 0; /* SUCCESS */ | ||
3199 | } | ||
3200 | EXPORT_SYMBOL(fc_vport_terminate); | ||
3201 | |||
3202 | /** | ||
3203 | * fc_vport_sched_delete - workq-based delete request for a vport | ||
3204 | * | ||
3205 | * @work: vport to be deleted. | ||
3206 | **/ | ||
3207 | static void | ||
3208 | fc_vport_sched_delete(struct work_struct *work) | ||
3209 | { | ||
3210 | struct fc_vport *vport = | ||
3211 | container_of(work, struct fc_vport, vport_delete_work); | ||
3212 | int stat; | ||
3213 | |||
3214 | stat = fc_vport_terminate(vport); | ||
3215 | if (stat) | ||
3216 | dev_printk(KERN_ERR, vport->dev.parent, | ||
3217 | "%s: %s could not be deleted created via " | ||
3218 | "shost%d channel %d - error %d\n", __FUNCTION__, | ||
3219 | vport->dev.bus_id, vport->shost->host_no, | ||
3220 | vport->channel, stat); | ||
3221 | } | ||
3222 | |||
3223 | |||
3224 | /* Original Author: Martin Hicks */ | ||
3225 | MODULE_AUTHOR("James Smart"); | ||
2451 | MODULE_DESCRIPTION("FC Transport Attributes"); | 3226 | MODULE_DESCRIPTION("FC Transport Attributes"); |
2452 | MODULE_LICENSE("GPL"); | 3227 | MODULE_LICENSE("GPL"); |
2453 | 3228 | ||