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