James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * FiberChannel transport specific attributes exported to sysfs. |
| 3 | * |
| 4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | * ======== |
| 21 | * |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 22 | * Copyright (C) 2004-2007 James Smart, Emulex Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * Rewrite for host, target, device, and remote port attributes, |
| 24 | * statistics, and service functions... |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 25 | * Add vports, etc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * |
| 27 | */ |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 30 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_host.h> |
| 33 | #include <scsi/scsi_transport.h> |
| 34 | #include <scsi/scsi_transport_fc.h> |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_cmnd.h> |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 36 | #include <linux/netlink.h> |
| 37 | #include <net/netlink.h> |
| 38 | #include <scsi/scsi_netlink_fc.h> |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 39 | #include <scsi/scsi_bsg_fc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "scsi_priv.h" |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 41 | #include "scsi_transport_fc_internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 43 | static int fc_queue_work(struct Scsi_Host *, struct work_struct *); |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 44 | static void fc_vport_sched_delete(struct work_struct *work); |
Andrew Vasquez | a30c3f6 | 2008-07-18 08:32:52 -0700 | [diff] [blame] | 45 | static int fc_vport_setup(struct Scsi_Host *shost, int channel, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 46 | struct device *pdev, struct fc_vport_identifiers *ids, |
| 47 | struct fc_vport **vport); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 48 | static int fc_bsg_hostadd(struct Scsi_Host *, struct fc_host_attrs *); |
| 49 | static int fc_bsg_rportadd(struct Scsi_Host *, struct fc_rport *); |
| 50 | static void fc_bsg_remove(struct request_queue *); |
| 51 | static void fc_bsg_goose_queue(struct fc_rport *); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 52 | |
| 53 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * Redefine so that we can have same named attributes in the |
| 55 | * sdev/starget/host objects. |
| 56 | */ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 57 | #define FC_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 58 | struct device_attribute device_attr_##_prefix##_##_name = \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | __ATTR(_name,_mode,_show,_store) |
| 60 | |
| 61 | #define fc_enum_name_search(title, table_type, table) \ |
| 62 | static const char *get_fc_##title##_name(enum table_type table_key) \ |
| 63 | { \ |
| 64 | int i; \ |
| 65 | char *name = NULL; \ |
| 66 | \ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 67 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | if (table[i].value == table_key) { \ |
| 69 | name = table[i].name; \ |
| 70 | break; \ |
| 71 | } \ |
| 72 | } \ |
| 73 | return name; \ |
| 74 | } |
| 75 | |
| 76 | #define fc_enum_name_match(title, table_type, table) \ |
| 77 | static int get_fc_##title##_match(const char *table_key, \ |
| 78 | enum table_type *value) \ |
| 79 | { \ |
| 80 | int i; \ |
| 81 | \ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 82 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | if (strncmp(table_key, table[i].name, \ |
| 84 | table[i].matchlen) == 0) { \ |
| 85 | *value = table[i].value; \ |
| 86 | return 0; /* success */ \ |
| 87 | } \ |
| 88 | } \ |
| 89 | return 1; /* failure */ \ |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* Convert fc_port_type values to ascii string name */ |
| 94 | static struct { |
| 95 | enum fc_port_type value; |
| 96 | char *name; |
| 97 | } fc_port_type_names[] = { |
| 98 | { FC_PORTTYPE_UNKNOWN, "Unknown" }, |
| 99 | { FC_PORTTYPE_OTHER, "Other" }, |
| 100 | { FC_PORTTYPE_NOTPRESENT, "Not Present" }, |
| 101 | { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" }, |
| 102 | { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" }, |
| 103 | { FC_PORTTYPE_LPORT, "LPort (private loop)" }, |
Christof Schmitt | 951948a | 2009-01-15 16:51:48 +0100 | [diff] [blame] | 104 | { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection)" }, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 105 | { FC_PORTTYPE_NPIV, "NPIV VPORT" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | fc_enum_name_search(port_type, fc_port_type, fc_port_type_names) |
| 108 | #define FC_PORTTYPE_MAX_NAMELEN 50 |
| 109 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 110 | /* Reuse fc_port_type enum function for vport_type */ |
| 111 | #define get_fc_vport_type_name get_fc_port_type_name |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 114 | /* Convert fc_host_event_code values to ascii string name */ |
| 115 | static const struct { |
| 116 | enum fc_host_event_code value; |
| 117 | char *name; |
| 118 | } fc_host_event_code_names[] = { |
| 119 | { FCH_EVT_LIP, "lip" }, |
| 120 | { FCH_EVT_LINKUP, "link_up" }, |
| 121 | { FCH_EVT_LINKDOWN, "link_down" }, |
| 122 | { FCH_EVT_LIPRESET, "lip_reset" }, |
| 123 | { FCH_EVT_RSCN, "rscn" }, |
| 124 | { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" }, |
| 125 | { FCH_EVT_PORT_UNKNOWN, "port_unknown" }, |
| 126 | { FCH_EVT_PORT_ONLINE, "port_online" }, |
| 127 | { FCH_EVT_PORT_OFFLINE, "port_offline" }, |
| 128 | { FCH_EVT_PORT_FABRIC, "port_fabric" }, |
| 129 | { FCH_EVT_LINK_UNKNOWN, "link_unknown" }, |
| 130 | { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" }, |
| 131 | }; |
| 132 | fc_enum_name_search(host_event_code, fc_host_event_code, |
| 133 | fc_host_event_code_names) |
| 134 | #define FC_HOST_EVENT_CODE_MAX_NAMELEN 30 |
| 135 | |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* Convert fc_port_state values to ascii string name */ |
| 138 | static struct { |
| 139 | enum fc_port_state value; |
| 140 | char *name; |
| 141 | } fc_port_state_names[] = { |
| 142 | { FC_PORTSTATE_UNKNOWN, "Unknown" }, |
| 143 | { FC_PORTSTATE_NOTPRESENT, "Not Present" }, |
| 144 | { FC_PORTSTATE_ONLINE, "Online" }, |
| 145 | { FC_PORTSTATE_OFFLINE, "Offline" }, |
| 146 | { FC_PORTSTATE_BLOCKED, "Blocked" }, |
| 147 | { FC_PORTSTATE_BYPASSED, "Bypassed" }, |
| 148 | { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" }, |
| 149 | { FC_PORTSTATE_LINKDOWN, "Linkdown" }, |
| 150 | { FC_PORTSTATE_ERROR, "Error" }, |
| 151 | { FC_PORTSTATE_LOOPBACK, "Loopback" }, |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 152 | { FC_PORTSTATE_DELETED, "Deleted" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | fc_enum_name_search(port_state, fc_port_state, fc_port_state_names) |
| 155 | #define FC_PORTSTATE_MAX_NAMELEN 20 |
| 156 | |
| 157 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 158 | /* Convert fc_vport_state values to ascii string name */ |
| 159 | static struct { |
| 160 | enum fc_vport_state value; |
| 161 | char *name; |
| 162 | } fc_vport_state_names[] = { |
| 163 | { FC_VPORT_UNKNOWN, "Unknown" }, |
| 164 | { FC_VPORT_ACTIVE, "Active" }, |
| 165 | { FC_VPORT_DISABLED, "Disabled" }, |
| 166 | { FC_VPORT_LINKDOWN, "Linkdown" }, |
| 167 | { FC_VPORT_INITIALIZING, "Initializing" }, |
| 168 | { FC_VPORT_NO_FABRIC_SUPP, "No Fabric Support" }, |
| 169 | { FC_VPORT_NO_FABRIC_RSCS, "No Fabric Resources" }, |
| 170 | { FC_VPORT_FABRIC_LOGOUT, "Fabric Logout" }, |
| 171 | { FC_VPORT_FABRIC_REJ_WWN, "Fabric Rejected WWN" }, |
| 172 | { FC_VPORT_FAILED, "VPort Failed" }, |
| 173 | }; |
| 174 | fc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names) |
| 175 | #define FC_VPORTSTATE_MAX_NAMELEN 24 |
| 176 | |
| 177 | /* Reuse fc_vport_state enum function for vport_last_state */ |
| 178 | #define get_fc_vport_last_state_name get_fc_vport_state_name |
| 179 | |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* Convert fc_tgtid_binding_type values to ascii string name */ |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 182 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | enum fc_tgtid_binding_type value; |
| 184 | char *name; |
| 185 | int matchlen; |
| 186 | } fc_tgtid_binding_type_names[] = { |
| 187 | { FC_TGTID_BIND_NONE, "none", 4 }, |
| 188 | { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 }, |
| 189 | { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 }, |
| 190 | { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 }, |
| 191 | }; |
| 192 | fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type, |
| 193 | fc_tgtid_binding_type_names) |
| 194 | fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type, |
| 195 | fc_tgtid_binding_type_names) |
| 196 | #define FC_BINDTYPE_MAX_NAMELEN 30 |
| 197 | |
| 198 | |
| 199 | #define fc_bitfield_name_search(title, table) \ |
| 200 | static ssize_t \ |
| 201 | get_fc_##title##_names(u32 table_key, char *buf) \ |
| 202 | { \ |
| 203 | char *prefix = ""; \ |
| 204 | ssize_t len = 0; \ |
| 205 | int i; \ |
| 206 | \ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 207 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (table[i].value & table_key) { \ |
| 209 | len += sprintf(buf + len, "%s%s", \ |
| 210 | prefix, table[i].name); \ |
| 211 | prefix = ", "; \ |
| 212 | } \ |
| 213 | } \ |
| 214 | len += sprintf(buf + len, "\n"); \ |
| 215 | return len; \ |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /* Convert FC_COS bit values to ascii string name */ |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 220 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | u32 value; |
| 222 | char *name; |
| 223 | } fc_cos_names[] = { |
| 224 | { FC_COS_CLASS1, "Class 1" }, |
| 225 | { FC_COS_CLASS2, "Class 2" }, |
| 226 | { FC_COS_CLASS3, "Class 3" }, |
| 227 | { FC_COS_CLASS4, "Class 4" }, |
| 228 | { FC_COS_CLASS6, "Class 6" }, |
| 229 | }; |
| 230 | fc_bitfield_name_search(cos, fc_cos_names) |
| 231 | |
| 232 | |
| 233 | /* Convert FC_PORTSPEED bit values to ascii string name */ |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 234 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | u32 value; |
| 236 | char *name; |
| 237 | } fc_port_speed_names[] = { |
| 238 | { FC_PORTSPEED_1GBIT, "1 Gbit" }, |
| 239 | { FC_PORTSPEED_2GBIT, "2 Gbit" }, |
| 240 | { FC_PORTSPEED_4GBIT, "4 Gbit" }, |
| 241 | { FC_PORTSPEED_10GBIT, "10 Gbit" }, |
James Smart | c3d2350 | 2007-03-12 14:16:35 -0500 | [diff] [blame] | 242 | { FC_PORTSPEED_8GBIT, "8 Gbit" }, |
| 243 | { FC_PORTSPEED_16GBIT, "16 Gbit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" }, |
| 245 | }; |
| 246 | fc_bitfield_name_search(port_speed, fc_port_speed_names) |
| 247 | |
| 248 | |
| 249 | static int |
| 250 | show_fc_fc4s (char *buf, u8 *fc4_list) |
| 251 | { |
| 252 | int i, len=0; |
| 253 | |
| 254 | for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++) |
| 255 | len += sprintf(buf + len , "0x%02x ", *fc4_list); |
| 256 | len += sprintf(buf + len, "\n"); |
| 257 | return len; |
| 258 | } |
| 259 | |
| 260 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 261 | /* Convert FC_PORT_ROLE bit values to ascii string name */ |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 262 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | u32 value; |
| 264 | char *name; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 265 | } fc_port_role_names[] = { |
| 266 | { FC_PORT_ROLE_FCP_TARGET, "FCP Target" }, |
| 267 | { FC_PORT_ROLE_FCP_INITIATOR, "FCP Initiator" }, |
| 268 | { FC_PORT_ROLE_IP_PORT, "IP Port" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | }; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 270 | fc_bitfield_name_search(port_roles, fc_port_role_names) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * Define roles that are specific to port_id. Values are relative to ROLE_MASK. |
| 274 | */ |
| 275 | #define FC_WELLKNOWN_PORTID_MASK 0xfffff0 |
| 276 | #define FC_WELLKNOWN_ROLE_MASK 0x00000f |
| 277 | #define FC_FPORT_PORTID 0x00000e |
| 278 | #define FC_FABCTLR_PORTID 0x00000d |
| 279 | #define FC_DIRSRVR_PORTID 0x00000c |
| 280 | #define FC_TIMESRVR_PORTID 0x00000b |
| 281 | #define FC_MGMTSRVR_PORTID 0x00000a |
| 282 | |
| 283 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 284 | static void fc_timeout_deleted_rport(struct work_struct *work); |
| 285 | static void fc_timeout_fail_rport_io(struct work_struct *work); |
| 286 | static void fc_scsi_scan_rport(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * Attribute counts pre object type... |
| 290 | * Increase these values if you add attributes |
| 291 | */ |
| 292 | #define FC_STARGET_NUM_ATTRS 3 |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 293 | #define FC_RPORT_NUM_ATTRS 10 |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 294 | #define FC_VPORT_NUM_ATTRS 9 |
James Smart | 4643682 | 2009-07-28 12:30:01 -0400 | [diff] [blame] | 295 | #define FC_HOST_NUM_ATTRS 22 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | struct fc_internal { |
| 298 | struct scsi_transport_template t; |
| 299 | struct fc_function_template *f; |
| 300 | |
| 301 | /* |
| 302 | * For attributes : each object has : |
| 303 | * An array of the actual attributes structures |
| 304 | * An array of null-terminated pointers to the attribute |
| 305 | * structures - used for mid-layer interaction. |
| 306 | * |
| 307 | * The attribute containers for the starget and host are are |
| 308 | * part of the midlayer. As the remote port is specific to the |
| 309 | * fc transport, we must provide the attribute container. |
| 310 | */ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 311 | struct device_attribute private_starget_attrs[ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | FC_STARGET_NUM_ATTRS]; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 313 | struct device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 315 | struct device_attribute private_host_attrs[FC_HOST_NUM_ATTRS]; |
| 316 | struct device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | struct transport_container rport_attr_cont; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 319 | struct device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS]; |
| 320 | struct device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1]; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 321 | |
| 322 | struct transport_container vport_attr_cont; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 323 | struct device_attribute private_vport_attrs[FC_VPORT_NUM_ATTRS]; |
| 324 | struct device_attribute *vport_attrs[FC_VPORT_NUM_ATTRS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) |
| 328 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 329 | static int fc_target_setup(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 330 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | struct scsi_target *starget = to_scsi_target(dev); |
| 333 | struct fc_rport *rport = starget_to_rport(starget); |
| 334 | |
| 335 | /* |
| 336 | * if parent is remote port, use values from remote port. |
| 337 | * Otherwise, this host uses the fc_transport, but not the |
| 338 | * remote port interface. As such, initialize to known non-values. |
| 339 | */ |
| 340 | if (rport) { |
| 341 | fc_starget_node_name(starget) = rport->node_name; |
| 342 | fc_starget_port_name(starget) = rport->port_name; |
| 343 | fc_starget_port_id(starget) = rport->port_id; |
| 344 | } else { |
| 345 | fc_starget_node_name(starget) = -1; |
| 346 | fc_starget_port_name(starget) = -1; |
| 347 | fc_starget_port_id(starget) = -1; |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static DECLARE_TRANSPORT_CLASS(fc_transport_class, |
| 354 | "fc_transport", |
| 355 | fc_target_setup, |
| 356 | NULL, |
| 357 | NULL); |
| 358 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 359 | static int fc_host_setup(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 360 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | struct Scsi_Host *shost = dev_to_shost(dev); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 363 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 365 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | * Set default values easily detected by the midlayer as |
| 367 | * failure cases. The scsi lldd is responsible for initializing |
| 368 | * all transport attributes to valid values per host. |
| 369 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 370 | fc_host->node_name = -1; |
| 371 | fc_host->port_name = -1; |
| 372 | fc_host->permanent_port_name = -1; |
| 373 | fc_host->supported_classes = FC_COS_UNSPECIFIED; |
| 374 | memset(fc_host->supported_fc4s, 0, |
| 375 | sizeof(fc_host->supported_fc4s)); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 376 | fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; |
| 377 | fc_host->maxframe_size = -1; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 378 | fc_host->max_npiv_vports = 0; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 379 | memset(fc_host->serial_number, 0, |
| 380 | sizeof(fc_host->serial_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 382 | fc_host->port_id = -1; |
| 383 | fc_host->port_type = FC_PORTTYPE_UNKNOWN; |
| 384 | fc_host->port_state = FC_PORTSTATE_UNKNOWN; |
| 385 | memset(fc_host->active_fc4s, 0, |
| 386 | sizeof(fc_host->active_fc4s)); |
| 387 | fc_host->speed = FC_PORTSPEED_UNKNOWN; |
| 388 | fc_host->fabric_name = -1; |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 389 | memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name)); |
| 390 | memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 392 | fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 394 | INIT_LIST_HEAD(&fc_host->rports); |
| 395 | INIT_LIST_HEAD(&fc_host->rport_bindings); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 396 | INIT_LIST_HEAD(&fc_host->vports); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 397 | fc_host->next_rport_number = 0; |
| 398 | fc_host->next_target_id = 0; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 399 | fc_host->next_vport_number = 0; |
| 400 | fc_host->npiv_vports_inuse = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Kay Sievers | aab0de2 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 402 | snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name), |
| 403 | "fc_wq_%d", shost->host_no); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 404 | fc_host->work_q = create_singlethread_workqueue( |
| 405 | fc_host->work_q_name); |
| 406 | if (!fc_host->work_q) |
| 407 | return -ENOMEM; |
| 408 | |
Kay Sievers | aab0de2 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 409 | snprintf(fc_host->devloss_work_q_name, |
| 410 | sizeof(fc_host->devloss_work_q_name), |
| 411 | "fc_dl_%d", shost->host_no); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 412 | fc_host->devloss_work_q = create_singlethread_workqueue( |
| 413 | fc_host->devloss_work_q_name); |
| 414 | if (!fc_host->devloss_work_q) { |
| 415 | destroy_workqueue(fc_host->work_q); |
| 416 | fc_host->work_q = NULL; |
| 417 | return -ENOMEM; |
| 418 | } |
| 419 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 420 | fc_bsg_hostadd(shost, fc_host); |
| 421 | /* ignore any bsg add error - we just can't do sgio */ |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int fc_host_remove(struct transport_container *tc, struct device *dev, |
| 427 | struct device *cdev) |
| 428 | { |
| 429 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 430 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
| 431 | |
| 432 | fc_bsg_remove(fc_host->rqst_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static DECLARE_TRANSPORT_CLASS(fc_host_class, |
| 437 | "fc_host", |
| 438 | fc_host_setup, |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 439 | fc_host_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | NULL); |
| 441 | |
| 442 | /* |
| 443 | * Setup and Remove actions for remote ports are handled |
| 444 | * in the service functions below. |
| 445 | */ |
| 446 | static DECLARE_TRANSPORT_CLASS(fc_rport_class, |
| 447 | "fc_remote_ports", |
| 448 | NULL, |
| 449 | NULL, |
| 450 | NULL); |
| 451 | |
| 452 | /* |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 453 | * Setup and Remove actions for virtual ports are handled |
| 454 | * in the service functions below. |
| 455 | */ |
| 456 | static DECLARE_TRANSPORT_CLASS(fc_vport_class, |
| 457 | "fc_vports", |
| 458 | NULL, |
| 459 | NULL, |
| 460 | NULL); |
| 461 | |
| 462 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | * Module Parameters |
| 464 | */ |
| 465 | |
| 466 | /* |
| 467 | * dev_loss_tmo: the default number of seconds that the FC transport |
| 468 | * should insulate the loss of a remote port. |
| 469 | * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT. |
| 470 | */ |
James Smart | 1c9e16e | 2006-05-16 16:13:36 -0400 | [diff] [blame] | 471 | static unsigned int fc_dev_loss_tmo = 60; /* seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Masatake YAMATO | 10f4b89 | 2007-09-19 22:59:16 +0900 | [diff] [blame] | 473 | module_param_named(dev_loss_tmo, fc_dev_loss_tmo, uint, S_IRUGO|S_IWUSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | MODULE_PARM_DESC(dev_loss_tmo, |
| 475 | "Maximum number of seconds that the FC transport should" |
| 476 | " insulate the loss of a remote port. Once this value is" |
| 477 | " exceeded, the scsi target is removed. Value should be" |
| 478 | " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT."); |
| 479 | |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 480 | /* |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 481 | * Netlink Infrastructure |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 482 | */ |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 483 | |
| 484 | static atomic_t fc_event_seq; |
| 485 | |
| 486 | /** |
| 487 | * fc_get_event_number - Obtain the next sequential FC event number |
| 488 | * |
| 489 | * Notes: |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 490 | * We could have inlined this, but it would have required fc_event_seq to |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 491 | * be exposed. For now, live with the subroutine call. |
| 492 | * Atomic used to avoid lock/unlock... |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 493 | */ |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 494 | u32 |
| 495 | fc_get_event_number(void) |
| 496 | { |
| 497 | return atomic_add_return(1, &fc_event_seq); |
| 498 | } |
| 499 | EXPORT_SYMBOL(fc_get_event_number); |
| 500 | |
| 501 | |
| 502 | /** |
| 503 | * fc_host_post_event - called to post an even on an fc_host. |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 504 | * @shost: host the event occurred on |
| 505 | * @event_number: fc event number obtained from get_fc_event_number() |
| 506 | * @event_code: fc_host event being posted |
| 507 | * @event_data: 32bits of data for the event being posted |
| 508 | * |
| 509 | * Notes: |
| 510 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 511 | */ |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 512 | void |
| 513 | fc_host_post_event(struct Scsi_Host *shost, u32 event_number, |
| 514 | enum fc_host_event_code event_code, u32 event_data) |
| 515 | { |
| 516 | struct sk_buff *skb; |
| 517 | struct nlmsghdr *nlh; |
| 518 | struct fc_nl_event *event; |
| 519 | const char *name; |
| 520 | u32 len, skblen; |
| 521 | int err; |
| 522 | |
| 523 | if (!scsi_nl_sock) { |
| 524 | err = -ENOENT; |
| 525 | goto send_fail; |
| 526 | } |
| 527 | |
| 528 | len = FC_NL_MSGALIGN(sizeof(*event)); |
| 529 | skblen = NLMSG_SPACE(len); |
| 530 | |
| 531 | skb = alloc_skb(skblen, GFP_KERNEL); |
| 532 | if (!skb) { |
| 533 | err = -ENOBUFS; |
| 534 | goto send_fail; |
| 535 | } |
| 536 | |
| 537 | nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, |
| 538 | skblen - sizeof(*nlh), 0); |
| 539 | if (!nlh) { |
| 540 | err = -ENOBUFS; |
| 541 | goto send_fail_skb; |
| 542 | } |
| 543 | event = NLMSG_DATA(nlh); |
| 544 | |
| 545 | INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, |
| 546 | FC_NL_ASYNC_EVENT, len); |
| 547 | event->seconds = get_seconds(); |
| 548 | event->vendor_id = 0; |
| 549 | event->host_no = shost->host_no; |
| 550 | event->event_datalen = sizeof(u32); /* bytes */ |
| 551 | event->event_num = event_number; |
| 552 | event->event_code = event_code; |
| 553 | event->event_data = event_data; |
| 554 | |
Pablo Neira Ayuso | ff491a7 | 2009-02-05 23:56:36 -0800 | [diff] [blame] | 555 | nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, |
| 556 | GFP_KERNEL); |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 557 | return; |
| 558 | |
| 559 | send_fail_skb: |
| 560 | kfree_skb(skb); |
| 561 | send_fail: |
| 562 | name = get_fc_host_event_code_name(event_code); |
| 563 | printk(KERN_WARNING |
| 564 | "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 565 | __func__, shost->host_no, |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 566 | (name) ? name : "<unknown>", event_data, err); |
| 567 | return; |
| 568 | } |
| 569 | EXPORT_SYMBOL(fc_host_post_event); |
| 570 | |
| 571 | |
| 572 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 573 | * fc_host_post_vendor_event - called to post a vendor unique event on an fc_host |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 574 | * @shost: host the event occurred on |
| 575 | * @event_number: fc event number obtained from get_fc_event_number() |
| 576 | * @data_len: amount, in bytes, of vendor unique data |
| 577 | * @data_buf: pointer to vendor unique data |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 578 | * @vendor_id: Vendor id |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 579 | * |
| 580 | * Notes: |
| 581 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 582 | */ |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 583 | void |
| 584 | fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, |
James Smart | f14e2e2 | 2006-08-22 09:55:23 -0400 | [diff] [blame] | 585 | u32 data_len, char * data_buf, u64 vendor_id) |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 586 | { |
| 587 | struct sk_buff *skb; |
| 588 | struct nlmsghdr *nlh; |
| 589 | struct fc_nl_event *event; |
| 590 | u32 len, skblen; |
| 591 | int err; |
| 592 | |
| 593 | if (!scsi_nl_sock) { |
| 594 | err = -ENOENT; |
| 595 | goto send_vendor_fail; |
| 596 | } |
| 597 | |
| 598 | len = FC_NL_MSGALIGN(sizeof(*event) + data_len); |
| 599 | skblen = NLMSG_SPACE(len); |
| 600 | |
| 601 | skb = alloc_skb(skblen, GFP_KERNEL); |
| 602 | if (!skb) { |
| 603 | err = -ENOBUFS; |
| 604 | goto send_vendor_fail; |
| 605 | } |
| 606 | |
| 607 | nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, |
| 608 | skblen - sizeof(*nlh), 0); |
| 609 | if (!nlh) { |
| 610 | err = -ENOBUFS; |
| 611 | goto send_vendor_fail_skb; |
| 612 | } |
| 613 | event = NLMSG_DATA(nlh); |
| 614 | |
| 615 | INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, |
| 616 | FC_NL_ASYNC_EVENT, len); |
| 617 | event->seconds = get_seconds(); |
| 618 | event->vendor_id = vendor_id; |
| 619 | event->host_no = shost->host_no; |
| 620 | event->event_datalen = data_len; /* bytes */ |
| 621 | event->event_num = event_number; |
| 622 | event->event_code = FCH_EVT_VENDOR_UNIQUE; |
| 623 | memcpy(&event->event_data, data_buf, data_len); |
| 624 | |
Pablo Neira Ayuso | ff491a7 | 2009-02-05 23:56:36 -0800 | [diff] [blame] | 625 | nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, |
| 626 | GFP_KERNEL); |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 627 | return; |
| 628 | |
| 629 | send_vendor_fail_skb: |
| 630 | kfree_skb(skb); |
| 631 | send_vendor_fail: |
| 632 | printk(KERN_WARNING |
| 633 | "%s: Dropped Event : host %d vendor_unique - err %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 634 | __func__, shost->host_no, err); |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 635 | return; |
| 636 | } |
| 637 | EXPORT_SYMBOL(fc_host_post_vendor_event); |
| 638 | |
| 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | static __init int fc_transport_init(void) |
| 642 | { |
James Smart | 84314fd | 2006-08-18 17:30:09 -0400 | [diff] [blame] | 643 | int error; |
| 644 | |
| 645 | atomic_set(&fc_event_seq, 0); |
| 646 | |
| 647 | error = transport_class_register(&fc_host_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (error) |
| 649 | return error; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 650 | error = transport_class_register(&fc_vport_class); |
| 651 | if (error) |
| 652 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | error = transport_class_register(&fc_rport_class); |
| 654 | if (error) |
| 655 | return error; |
| 656 | return transport_class_register(&fc_transport_class); |
| 657 | } |
| 658 | |
| 659 | static void __exit fc_transport_exit(void) |
| 660 | { |
| 661 | transport_class_unregister(&fc_transport_class); |
| 662 | transport_class_unregister(&fc_rport_class); |
| 663 | transport_class_unregister(&fc_host_class); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 664 | transport_class_unregister(&fc_vport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* |
| 668 | * FC Remote Port Attribute Management |
| 669 | */ |
| 670 | |
| 671 | #define fc_rport_show_function(field, format_string, sz, cast) \ |
| 672 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 673 | show_fc_rport_##field (struct device *dev, \ |
| 674 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 676 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | struct Scsi_Host *shost = rport_to_shost(rport); \ |
| 678 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 679 | if ((i->f->get_rport_##field) && \ |
| 680 | !((rport->port_state == FC_PORTSTATE_BLOCKED) || \ |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 681 | (rport->port_state == FC_PORTSTATE_DELETED) || \ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 682 | (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | i->f->get_rport_##field(rport); \ |
| 684 | return snprintf(buf, sz, format_string, cast rport->field); \ |
| 685 | } |
| 686 | |
| 687 | #define fc_rport_store_function(field) \ |
| 688 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 689 | store_fc_rport_##field(struct device *dev, \ |
| 690 | struct device_attribute *attr, \ |
| 691 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { \ |
| 693 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 694 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | struct Scsi_Host *shost = rport_to_shost(rport); \ |
| 696 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 697 | char *cp; \ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 698 | if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \ |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 699 | (rport->port_state == FC_PORTSTATE_DELETED) || \ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 700 | (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \ |
| 701 | return -EBUSY; \ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 702 | val = simple_strtoul(buf, &cp, 0); \ |
| 703 | if (*cp && (*cp != '\n')) \ |
| 704 | return -EINVAL; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | i->f->set_rport_##field(rport, val); \ |
| 706 | return count; \ |
| 707 | } |
| 708 | |
| 709 | #define fc_rport_rd_attr(field, format_string, sz) \ |
| 710 | fc_rport_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 711 | static FC_DEVICE_ATTR(rport, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | show_fc_rport_##field, NULL) |
| 713 | |
| 714 | #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \ |
| 715 | fc_rport_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 716 | static FC_DEVICE_ATTR(rport, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | show_fc_rport_##field, NULL) |
| 718 | |
| 719 | #define fc_rport_rw_attr(field, format_string, sz) \ |
| 720 | fc_rport_show_function(field, format_string, sz, ) \ |
| 721 | fc_rport_store_function(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 722 | static FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | show_fc_rport_##field, \ |
| 724 | store_fc_rport_##field) |
| 725 | |
| 726 | |
| 727 | #define fc_private_rport_show_function(field, format_string, sz, cast) \ |
| 728 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 729 | show_fc_rport_##field (struct device *dev, \ |
| 730 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 732 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | return snprintf(buf, sz, format_string, cast rport->field); \ |
| 734 | } |
| 735 | |
| 736 | #define fc_private_rport_rd_attr(field, format_string, sz) \ |
| 737 | fc_private_rport_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 738 | static FC_DEVICE_ATTR(rport, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | show_fc_rport_##field, NULL) |
| 740 | |
| 741 | #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \ |
| 742 | fc_private_rport_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 743 | static FC_DEVICE_ATTR(rport, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | show_fc_rport_##field, NULL) |
| 745 | |
| 746 | |
| 747 | #define fc_private_rport_rd_enum_attr(title, maxlen) \ |
| 748 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 749 | show_fc_rport_##title (struct device *dev, \ |
| 750 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 752 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | const char *name; \ |
| 754 | name = get_fc_##title##_name(rport->title); \ |
| 755 | if (!name) \ |
| 756 | return -EINVAL; \ |
| 757 | return snprintf(buf, maxlen, "%s\n", name); \ |
| 758 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 759 | static FC_DEVICE_ATTR(rport, title, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | show_fc_rport_##title, NULL) |
| 761 | |
| 762 | |
| 763 | #define SETUP_RPORT_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 764 | i->private_rport_attrs[count] = device_attr_rport_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | i->private_rport_attrs[count].attr.mode = S_IRUGO; \ |
| 766 | i->private_rport_attrs[count].store = NULL; \ |
| 767 | i->rport_attrs[count] = &i->private_rport_attrs[count]; \ |
| 768 | if (i->f->show_rport_##field) \ |
| 769 | count++ |
| 770 | |
| 771 | #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 772 | i->private_rport_attrs[count] = device_attr_rport_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | i->private_rport_attrs[count].attr.mode = S_IRUGO; \ |
| 774 | i->private_rport_attrs[count].store = NULL; \ |
| 775 | i->rport_attrs[count] = &i->private_rport_attrs[count]; \ |
| 776 | count++ |
| 777 | |
| 778 | #define SETUP_RPORT_ATTRIBUTE_RW(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 779 | i->private_rport_attrs[count] = device_attr_rport_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (!i->f->set_rport_##field) { \ |
| 781 | i->private_rport_attrs[count].attr.mode = S_IRUGO; \ |
| 782 | i->private_rport_attrs[count].store = NULL; \ |
| 783 | } \ |
| 784 | i->rport_attrs[count] = &i->private_rport_attrs[count]; \ |
| 785 | if (i->f->show_rport_##field) \ |
| 786 | count++ |
| 787 | |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 788 | #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(field) \ |
| 789 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 790 | i->private_rport_attrs[count] = device_attr_rport_##field; \ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 791 | i->rport_attrs[count] = &i->private_rport_attrs[count]; \ |
| 792 | count++; \ |
| 793 | } |
| 794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* The FC Transport Remote Port Attributes: */ |
| 797 | |
| 798 | /* Fixed Remote Port Attributes */ |
| 799 | |
| 800 | fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20); |
| 801 | |
| 802 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 803 | show_fc_rport_supported_classes (struct device *dev, |
| 804 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 806 | struct fc_rport *rport = transport_class_to_rport(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | if (rport->supported_classes == FC_COS_UNSPECIFIED) |
| 808 | return snprintf(buf, 20, "unspecified\n"); |
| 809 | return get_fc_cos_names(rport->supported_classes, buf); |
| 810 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 811 | static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | show_fc_rport_supported_classes, NULL); |
| 813 | |
| 814 | /* Dynamic Remote Port Attributes */ |
| 815 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 816 | /* |
| 817 | * dev_loss_tmo attribute |
| 818 | */ |
| 819 | fc_rport_show_function(dev_loss_tmo, "%d\n", 20, ) |
| 820 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 821 | store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr, |
| 822 | const char *buf, size_t count) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 823 | { |
| 824 | int val; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 825 | struct fc_rport *rport = transport_class_to_rport(dev); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 826 | struct Scsi_Host *shost = rport_to_shost(rport); |
| 827 | struct fc_internal *i = to_fc_internal(shost->transportt); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 828 | char *cp; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 829 | if ((rport->port_state == FC_PORTSTATE_BLOCKED) || |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 830 | (rport->port_state == FC_PORTSTATE_DELETED) || |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 831 | (rport->port_state == FC_PORTSTATE_NOTPRESENT)) |
| 832 | return -EBUSY; |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 833 | val = simple_strtoul(buf, &cp, 0); |
| 834 | if ((*cp && (*cp != '\n')) || |
| 835 | (val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 836 | return -EINVAL; |
| 837 | i->f->set_rport_dev_loss_tmo(rport, val); |
| 838 | return count; |
| 839 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 840 | static FC_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR, |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 841 | show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
| 843 | |
| 844 | /* Private Remote Port Attributes */ |
| 845 | |
| 846 | fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); |
| 847 | fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); |
| 848 | fc_private_rport_rd_attr(port_id, "0x%06x\n", 20); |
| 849 | |
| 850 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 851 | show_fc_rport_roles (struct device *dev, struct device_attribute *attr, |
| 852 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 854 | struct fc_rport *rport = transport_class_to_rport(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | /* identify any roles that are port_id specific */ |
| 857 | if ((rport->port_id != -1) && |
| 858 | (rport->port_id & FC_WELLKNOWN_PORTID_MASK) == |
| 859 | FC_WELLKNOWN_PORTID_MASK) { |
| 860 | switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) { |
| 861 | case FC_FPORT_PORTID: |
| 862 | return snprintf(buf, 30, "Fabric Port\n"); |
| 863 | case FC_FABCTLR_PORTID: |
| 864 | return snprintf(buf, 30, "Fabric Controller\n"); |
| 865 | case FC_DIRSRVR_PORTID: |
| 866 | return snprintf(buf, 30, "Directory Server\n"); |
| 867 | case FC_TIMESRVR_PORTID: |
| 868 | return snprintf(buf, 30, "Time Server\n"); |
| 869 | case FC_MGMTSRVR_PORTID: |
| 870 | return snprintf(buf, 30, "Management Server\n"); |
| 871 | default: |
| 872 | return snprintf(buf, 30, "Unknown Fabric Entity\n"); |
| 873 | } |
| 874 | } else { |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 875 | if (rport->roles == FC_PORT_ROLE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | return snprintf(buf, 20, "unknown\n"); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 877 | return get_fc_port_roles_names(rport->roles, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 880 | static FC_DEVICE_ATTR(rport, roles, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | show_fc_rport_roles, NULL); |
| 882 | |
| 883 | fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); |
| 884 | fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20); |
| 885 | |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 886 | /* |
| 887 | * fast_io_fail_tmo attribute |
| 888 | */ |
| 889 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 890 | show_fc_rport_fast_io_fail_tmo (struct device *dev, |
| 891 | struct device_attribute *attr, char *buf) |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 892 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 893 | struct fc_rport *rport = transport_class_to_rport(dev); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 894 | |
| 895 | if (rport->fast_io_fail_tmo == -1) |
| 896 | return snprintf(buf, 5, "off\n"); |
| 897 | return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo); |
| 898 | } |
| 899 | |
| 900 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 901 | store_fc_rport_fast_io_fail_tmo(struct device *dev, |
| 902 | struct device_attribute *attr, const char *buf, |
| 903 | size_t count) |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 904 | { |
| 905 | int val; |
| 906 | char *cp; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 907 | struct fc_rport *rport = transport_class_to_rport(dev); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 908 | |
| 909 | if ((rport->port_state == FC_PORTSTATE_BLOCKED) || |
| 910 | (rport->port_state == FC_PORTSTATE_DELETED) || |
| 911 | (rport->port_state == FC_PORTSTATE_NOTPRESENT)) |
| 912 | return -EBUSY; |
| 913 | if (strncmp(buf, "off", 3) == 0) |
| 914 | rport->fast_io_fail_tmo = -1; |
| 915 | else { |
| 916 | val = simple_strtoul(buf, &cp, 0); |
| 917 | if ((*cp && (*cp != '\n')) || |
| 918 | (val < 0) || (val >= rport->dev_loss_tmo)) |
| 919 | return -EINVAL; |
| 920 | rport->fast_io_fail_tmo = val; |
| 921 | } |
| 922 | return count; |
| 923 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 924 | static FC_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR, |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 925 | show_fc_rport_fast_io_fail_tmo, store_fc_rport_fast_io_fail_tmo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | |
| 928 | /* |
| 929 | * FC SCSI Target Attribute Management |
| 930 | */ |
| 931 | |
| 932 | /* |
| 933 | * Note: in the target show function we recognize when the remote |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 934 | * port is in the heirarchy and do not allow the driver to get |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | * involved in sysfs functions. The driver only gets involved if |
| 936 | * it's the "old" style that doesn't use rports. |
| 937 | */ |
| 938 | #define fc_starget_show_function(field, format_string, sz, cast) \ |
| 939 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 940 | show_fc_starget_##field (struct device *dev, \ |
| 941 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 943 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 945 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 946 | struct fc_rport *rport = starget_to_rport(starget); \ |
| 947 | if (rport) \ |
| 948 | fc_starget_##field(starget) = rport->field; \ |
| 949 | else if (i->f->get_starget_##field) \ |
| 950 | i->f->get_starget_##field(starget); \ |
| 951 | return snprintf(buf, sz, format_string, \ |
| 952 | cast fc_starget_##field(starget)); \ |
| 953 | } |
| 954 | |
| 955 | #define fc_starget_rd_attr(field, format_string, sz) \ |
| 956 | fc_starget_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 957 | static FC_DEVICE_ATTR(starget, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | show_fc_starget_##field, NULL) |
| 959 | |
| 960 | #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \ |
| 961 | fc_starget_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 962 | static FC_DEVICE_ATTR(starget, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | show_fc_starget_##field, NULL) |
| 964 | |
| 965 | #define SETUP_STARGET_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 966 | i->private_starget_attrs[count] = device_attr_starget_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | i->private_starget_attrs[count].attr.mode = S_IRUGO; \ |
| 968 | i->private_starget_attrs[count].store = NULL; \ |
| 969 | i->starget_attrs[count] = &i->private_starget_attrs[count]; \ |
| 970 | if (i->f->show_starget_##field) \ |
| 971 | count++ |
| 972 | |
| 973 | #define SETUP_STARGET_ATTRIBUTE_RW(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 974 | i->private_starget_attrs[count] = device_attr_starget_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (!i->f->set_starget_##field) { \ |
| 976 | i->private_starget_attrs[count].attr.mode = S_IRUGO; \ |
| 977 | i->private_starget_attrs[count].store = NULL; \ |
| 978 | } \ |
| 979 | i->starget_attrs[count] = &i->private_starget_attrs[count]; \ |
| 980 | if (i->f->show_starget_##field) \ |
| 981 | count++ |
| 982 | |
| 983 | /* The FC Transport SCSI Target Attributes: */ |
| 984 | fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); |
| 985 | fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); |
| 986 | fc_starget_rd_attr(port_id, "0x%06x\n", 20); |
| 987 | |
| 988 | |
| 989 | /* |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 990 | * FC Virtual Port Attribute Management |
| 991 | */ |
| 992 | |
| 993 | #define fc_vport_show_function(field, format_string, sz, cast) \ |
| 994 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 995 | show_fc_vport_##field (struct device *dev, \ |
| 996 | struct device_attribute *attr, char *buf) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 997 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 998 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 999 | struct Scsi_Host *shost = vport_to_shost(vport); \ |
| 1000 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 1001 | if ((i->f->get_vport_##field) && \ |
| 1002 | !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \ |
| 1003 | i->f->get_vport_##field(vport); \ |
| 1004 | return snprintf(buf, sz, format_string, cast vport->field); \ |
| 1005 | } |
| 1006 | |
| 1007 | #define fc_vport_store_function(field) \ |
| 1008 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1009 | store_fc_vport_##field(struct device *dev, \ |
| 1010 | struct device_attribute *attr, \ |
| 1011 | const char *buf, size_t count) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1012 | { \ |
| 1013 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1014 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 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 \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1029 | store_fc_vport_##field(struct device *dev, \ |
| 1030 | struct device_attribute *attr, \ |
| 1031 | const char *buf, size_t count) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1032 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1033 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1034 | struct Scsi_Host *shost = vport_to_shost(vport); \ |
| 1035 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 1036 | unsigned int cnt=count; \ |
| 1037 | \ |
| 1038 | /* count may include a LF at end of string */ \ |
| 1039 | if (buf[cnt-1] == '\n') \ |
| 1040 | cnt--; \ |
| 1041 | if (cnt > ((slen) - 1)) \ |
| 1042 | return -EINVAL; \ |
| 1043 | memcpy(vport->field, buf, cnt); \ |
| 1044 | i->f->set_vport_##field(vport); \ |
| 1045 | return count; \ |
| 1046 | } |
| 1047 | |
| 1048 | #define fc_vport_rd_attr(field, format_string, sz) \ |
| 1049 | fc_vport_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1050 | static FC_DEVICE_ATTR(vport, field, S_IRUGO, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1051 | show_fc_vport_##field, NULL) |
| 1052 | |
| 1053 | #define fc_vport_rd_attr_cast(field, format_string, sz, cast) \ |
| 1054 | fc_vport_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1055 | static FC_DEVICE_ATTR(vport, field, S_IRUGO, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1056 | show_fc_vport_##field, NULL) |
| 1057 | |
| 1058 | #define fc_vport_rw_attr(field, format_string, sz) \ |
| 1059 | fc_vport_show_function(field, format_string, sz, ) \ |
| 1060 | fc_vport_store_function(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1061 | static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1062 | show_fc_vport_##field, \ |
| 1063 | store_fc_vport_##field) |
| 1064 | |
| 1065 | #define fc_private_vport_show_function(field, format_string, sz, cast) \ |
| 1066 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1067 | show_fc_vport_##field (struct device *dev, \ |
| 1068 | struct device_attribute *attr, char *buf) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1069 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1070 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 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 \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1076 | store_fc_vport_##field(struct device *dev, \ |
| 1077 | struct device_attribute *attr, \ |
| 1078 | const char *buf, size_t count) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1079 | { \ |
| 1080 | u32 val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1081 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1082 | char *cp; \ |
| 1083 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \ |
| 1084 | return -EBUSY; \ |
| 1085 | val = simple_strtoul(buf, &cp, 0); \ |
| 1086 | if (*cp && (*cp != '\n')) \ |
| 1087 | return -EINVAL; \ |
| 1088 | vport->field = val; \ |
| 1089 | return count; \ |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | #define fc_private_vport_rd_attr(field, format_string, sz) \ |
| 1094 | fc_private_vport_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1095 | static FC_DEVICE_ATTR(vport, field, S_IRUGO, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1096 | show_fc_vport_##field, NULL) |
| 1097 | |
| 1098 | #define fc_private_vport_rd_attr_cast(field, format_string, sz, cast) \ |
| 1099 | fc_private_vport_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1100 | static FC_DEVICE_ATTR(vport, field, S_IRUGO, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1101 | show_fc_vport_##field, NULL) |
| 1102 | |
| 1103 | #define fc_private_vport_rw_u32_attr(field, format_string, sz) \ |
| 1104 | fc_private_vport_show_function(field, format_string, sz, ) \ |
| 1105 | fc_private_vport_store_u32_function(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1106 | static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1107 | show_fc_vport_##field, \ |
| 1108 | store_fc_vport_##field) |
| 1109 | |
| 1110 | |
| 1111 | #define fc_private_vport_rd_enum_attr(title, maxlen) \ |
| 1112 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1113 | show_fc_vport_##title (struct device *dev, \ |
| 1114 | struct device_attribute *attr, \ |
| 1115 | char *buf) \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1116 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1117 | struct fc_vport *vport = transport_class_to_vport(dev); \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1118 | const char *name; \ |
| 1119 | name = get_fc_##title##_name(vport->title); \ |
| 1120 | if (!name) \ |
| 1121 | return -EINVAL; \ |
| 1122 | return snprintf(buf, maxlen, "%s\n", name); \ |
| 1123 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1124 | static FC_DEVICE_ATTR(vport, title, S_IRUGO, \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1125 | show_fc_vport_##title, NULL) |
| 1126 | |
| 1127 | |
| 1128 | #define SETUP_VPORT_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1129 | i->private_vport_attrs[count] = device_attr_vport_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1130 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ |
| 1131 | i->private_vport_attrs[count].store = NULL; \ |
| 1132 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ |
| 1133 | if (i->f->get_##field) \ |
| 1134 | count++ |
| 1135 | /* NOTE: Above MACRO differs: checks function not show bit */ |
| 1136 | |
| 1137 | #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1138 | i->private_vport_attrs[count] = device_attr_vport_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1139 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ |
| 1140 | i->private_vport_attrs[count].store = NULL; \ |
| 1141 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ |
| 1142 | count++ |
| 1143 | |
| 1144 | #define SETUP_VPORT_ATTRIBUTE_WR(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1145 | i->private_vport_attrs[count] = device_attr_vport_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1146 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ |
| 1147 | if (i->f->field) \ |
| 1148 | count++ |
| 1149 | /* NOTE: Above MACRO differs: checks function */ |
| 1150 | |
| 1151 | #define SETUP_VPORT_ATTRIBUTE_RW(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1152 | i->private_vport_attrs[count] = device_attr_vport_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1153 | if (!i->f->set_vport_##field) { \ |
| 1154 | i->private_vport_attrs[count].attr.mode = S_IRUGO; \ |
| 1155 | i->private_vport_attrs[count].store = NULL; \ |
| 1156 | } \ |
| 1157 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ |
| 1158 | count++ |
| 1159 | /* NOTE: Above MACRO differs: does not check show bit */ |
| 1160 | |
| 1161 | #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field) \ |
| 1162 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1163 | i->private_vport_attrs[count] = device_attr_vport_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1164 | i->vport_attrs[count] = &i->private_vport_attrs[count]; \ |
| 1165 | count++; \ |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | /* The FC Transport Virtual Port Attributes: */ |
| 1170 | |
| 1171 | /* Fixed Virtual Port Attributes */ |
| 1172 | |
| 1173 | /* Dynamic Virtual Port Attributes */ |
| 1174 | |
| 1175 | /* Private Virtual Port Attributes */ |
| 1176 | |
| 1177 | fc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN); |
| 1178 | fc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN); |
| 1179 | fc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); |
| 1180 | fc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); |
| 1181 | |
| 1182 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1183 | show_fc_vport_roles (struct device *dev, struct device_attribute *attr, |
| 1184 | char *buf) |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1185 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1186 | struct fc_vport *vport = transport_class_to_vport(dev); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1187 | |
| 1188 | if (vport->roles == FC_PORT_ROLE_UNKNOWN) |
| 1189 | return snprintf(buf, 20, "unknown\n"); |
| 1190 | return get_fc_port_roles_names(vport->roles, buf); |
| 1191 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1192 | static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1193 | |
| 1194 | fc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN); |
| 1195 | |
| 1196 | fc_private_vport_show_function(symbolic_name, "%s\n", |
| 1197 | FC_VPORT_SYMBOLIC_NAMELEN + 1, ) |
| 1198 | fc_vport_store_str_function(symbolic_name, FC_VPORT_SYMBOLIC_NAMELEN) |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1199 | static FC_DEVICE_ATTR(vport, symbolic_name, S_IRUGO | S_IWUSR, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1200 | show_fc_vport_symbolic_name, store_fc_vport_symbolic_name); |
| 1201 | |
| 1202 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1203 | store_fc_vport_delete(struct device *dev, struct device_attribute *attr, |
| 1204 | const char *buf, size_t count) |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1205 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1206 | struct fc_vport *vport = transport_class_to_vport(dev); |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 1207 | struct Scsi_Host *shost = vport_to_shost(vport); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1208 | |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 1209 | fc_queue_work(shost, &vport->vport_delete_work); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1210 | return count; |
| 1211 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1212 | static FC_DEVICE_ATTR(vport, vport_delete, S_IWUSR, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1213 | NULL, store_fc_vport_delete); |
| 1214 | |
| 1215 | |
| 1216 | /* |
| 1217 | * Enable/Disable vport |
| 1218 | * Write "1" to disable, write "0" to enable |
| 1219 | */ |
| 1220 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1221 | store_fc_vport_disable(struct device *dev, struct device_attribute *attr, |
| 1222 | const char *buf, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1223 | size_t count) |
| 1224 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1225 | struct fc_vport *vport = transport_class_to_vport(dev); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1226 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 1227 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1228 | int stat; |
| 1229 | |
| 1230 | if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) |
| 1231 | return -EBUSY; |
| 1232 | |
| 1233 | if (*buf == '0') { |
| 1234 | if (vport->vport_state != FC_VPORT_DISABLED) |
| 1235 | return -EALREADY; |
| 1236 | } else if (*buf == '1') { |
| 1237 | if (vport->vport_state == FC_VPORT_DISABLED) |
| 1238 | return -EALREADY; |
| 1239 | } else |
| 1240 | return -EINVAL; |
| 1241 | |
| 1242 | stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true)); |
| 1243 | return stat ? stat : count; |
| 1244 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1245 | static FC_DEVICE_ATTR(vport, vport_disable, S_IWUSR, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1246 | NULL, store_fc_vport_disable); |
| 1247 | |
| 1248 | |
| 1249 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | * Host Attribute Management |
| 1251 | */ |
| 1252 | |
| 1253 | #define fc_host_show_function(field, format_string, sz, cast) \ |
| 1254 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1255 | show_fc_host_##field (struct device *dev, \ |
| 1256 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1258 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 1260 | if (i->f->get_host_##field) \ |
| 1261 | i->f->get_host_##field(shost); \ |
| 1262 | return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ |
| 1263 | } |
| 1264 | |
| 1265 | #define fc_host_store_function(field) \ |
| 1266 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1267 | store_fc_host_##field(struct device *dev, \ |
| 1268 | struct device_attribute *attr, \ |
| 1269 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | { \ |
| 1271 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1272 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 1274 | char *cp; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | \ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 1276 | val = simple_strtoul(buf, &cp, 0); \ |
| 1277 | if (*cp && (*cp != '\n')) \ |
| 1278 | return -EINVAL; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | i->f->set_host_##field(shost, val); \ |
| 1280 | return count; \ |
| 1281 | } |
| 1282 | |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 1283 | #define fc_host_store_str_function(field, slen) \ |
| 1284 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1285 | store_fc_host_##field(struct device *dev, \ |
| 1286 | struct device_attribute *attr, \ |
| 1287 | const char *buf, size_t count) \ |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 1288 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1289 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 1290 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 1291 | unsigned int cnt=count; \ |
| 1292 | \ |
| 1293 | /* count may include a LF at end of string */ \ |
| 1294 | if (buf[cnt-1] == '\n') \ |
| 1295 | cnt--; \ |
| 1296 | if (cnt > ((slen) - 1)) \ |
| 1297 | return -EINVAL; \ |
| 1298 | memcpy(fc_host_##field(shost), buf, cnt); \ |
| 1299 | i->f->set_host_##field(shost); \ |
| 1300 | return count; \ |
| 1301 | } |
| 1302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | #define fc_host_rd_attr(field, format_string, sz) \ |
| 1304 | fc_host_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1305 | static FC_DEVICE_ATTR(host, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | show_fc_host_##field, NULL) |
| 1307 | |
| 1308 | #define fc_host_rd_attr_cast(field, format_string, sz, cast) \ |
| 1309 | fc_host_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1310 | static FC_DEVICE_ATTR(host, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | show_fc_host_##field, NULL) |
| 1312 | |
| 1313 | #define fc_host_rw_attr(field, format_string, sz) \ |
| 1314 | fc_host_show_function(field, format_string, sz, ) \ |
| 1315 | fc_host_store_function(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1316 | static FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | show_fc_host_##field, \ |
| 1318 | store_fc_host_##field) |
| 1319 | |
| 1320 | #define fc_host_rd_enum_attr(title, maxlen) \ |
| 1321 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1322 | show_fc_host_##title (struct device *dev, \ |
| 1323 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1325 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | struct fc_internal *i = to_fc_internal(shost->transportt); \ |
| 1327 | const char *name; \ |
| 1328 | if (i->f->get_host_##title) \ |
| 1329 | i->f->get_host_##title(shost); \ |
| 1330 | name = get_fc_##title##_name(fc_host_##title(shost)); \ |
| 1331 | if (!name) \ |
| 1332 | return -EINVAL; \ |
| 1333 | return snprintf(buf, maxlen, "%s\n", name); \ |
| 1334 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1335 | static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
| 1337 | #define SETUP_HOST_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1338 | i->private_host_attrs[count] = device_attr_host_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | if (i->f->show_host_##field) \ |
| 1343 | count++ |
| 1344 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1345 | #define SETUP_HOST_ATTRIBUTE_RD_NS(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1346 | i->private_host_attrs[count] = device_attr_host_##field; \ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1347 | i->private_host_attrs[count].attr.mode = S_IRUGO; \ |
| 1348 | i->private_host_attrs[count].store = NULL; \ |
| 1349 | i->host_attrs[count] = &i->private_host_attrs[count]; \ |
| 1350 | count++ |
| 1351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | #define SETUP_HOST_ATTRIBUTE_RW(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1353 | i->private_host_attrs[count] = device_attr_host_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | if (!i->f->set_host_##field) { \ |
| 1355 | i->private_host_attrs[count].attr.mode = S_IRUGO; \ |
| 1356 | i->private_host_attrs[count].store = NULL; \ |
| 1357 | } \ |
| 1358 | i->host_attrs[count] = &i->private_host_attrs[count]; \ |
| 1359 | if (i->f->show_host_##field) \ |
| 1360 | count++ |
| 1361 | |
| 1362 | |
| 1363 | #define fc_private_host_show_function(field, format_string, sz, cast) \ |
| 1364 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1365 | show_fc_host_##field (struct device *dev, \ |
| 1366 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1368 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ |
| 1370 | } |
| 1371 | |
| 1372 | #define fc_private_host_rd_attr(field, format_string, sz) \ |
| 1373 | fc_private_host_show_function(field, format_string, sz, ) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1374 | static FC_DEVICE_ATTR(host, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | show_fc_host_##field, NULL) |
| 1376 | |
| 1377 | #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \ |
| 1378 | fc_private_host_show_function(field, format_string, sz, (cast)) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1379 | static FC_DEVICE_ATTR(host, field, S_IRUGO, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | show_fc_host_##field, NULL) |
| 1381 | |
| 1382 | #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1383 | i->private_host_attrs[count] = device_attr_host_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | i->private_host_attrs[count].attr.mode = S_IRUGO; \ |
| 1385 | i->private_host_attrs[count].store = NULL; \ |
| 1386 | i->host_attrs[count] = &i->private_host_attrs[count]; \ |
| 1387 | count++ |
| 1388 | |
| 1389 | #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \ |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1390 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1391 | i->private_host_attrs[count] = device_attr_host_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | i->host_attrs[count] = &i->private_host_attrs[count]; \ |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1393 | count++; \ |
| 1394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | |
| 1397 | /* Fixed Host Attributes */ |
| 1398 | |
| 1399 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1400 | show_fc_host_supported_classes (struct device *dev, |
| 1401 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1403 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
| 1405 | if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED) |
| 1406 | return snprintf(buf, 20, "unspecified\n"); |
| 1407 | |
| 1408 | return get_fc_cos_names(fc_host_supported_classes(shost), buf); |
| 1409 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1410 | static FC_DEVICE_ATTR(host, supported_classes, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | show_fc_host_supported_classes, NULL); |
| 1412 | |
| 1413 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1414 | show_fc_host_supported_fc4s (struct device *dev, |
| 1415 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1417 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost)); |
| 1419 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1420 | static FC_DEVICE_ATTR(host, supported_fc4s, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | show_fc_host_supported_fc4s, NULL); |
| 1422 | |
| 1423 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1424 | show_fc_host_supported_speeds (struct device *dev, |
| 1425 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1427 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
| 1429 | if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN) |
| 1430 | return snprintf(buf, 20, "unknown\n"); |
| 1431 | |
| 1432 | return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf); |
| 1433 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1434 | static FC_DEVICE_ATTR(host, supported_speeds, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | show_fc_host_supported_speeds, NULL); |
| 1436 | |
| 1437 | |
| 1438 | fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); |
| 1439 | fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); |
Andreas Herrmann | 6b7281d | 2006-01-13 02:16:54 +0100 | [diff] [blame] | 1440 | fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20, |
| 1441 | unsigned long long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1443 | fc_private_host_rd_attr(max_npiv_vports, "%u\n", 20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1)); |
| 1445 | |
| 1446 | |
| 1447 | /* Dynamic Host Attributes */ |
| 1448 | |
| 1449 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1450 | show_fc_host_active_fc4s (struct device *dev, |
| 1451 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1453 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1455 | |
| 1456 | if (i->f->get_host_active_fc4s) |
| 1457 | i->f->get_host_active_fc4s(shost); |
| 1458 | |
| 1459 | return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost)); |
| 1460 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1461 | static FC_DEVICE_ATTR(host, active_fc4s, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | show_fc_host_active_fc4s, NULL); |
| 1463 | |
| 1464 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1465 | show_fc_host_speed (struct device *dev, |
| 1466 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1468 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1470 | |
| 1471 | if (i->f->get_host_speed) |
| 1472 | i->f->get_host_speed(shost); |
| 1473 | |
| 1474 | if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN) |
| 1475 | return snprintf(buf, 20, "unknown\n"); |
| 1476 | |
| 1477 | return get_fc_port_speed_names(fc_host_speed(shost), buf); |
| 1478 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1479 | static FC_DEVICE_ATTR(host, speed, S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | show_fc_host_speed, NULL); |
| 1481 | |
| 1482 | |
| 1483 | fc_host_rd_attr(port_id, "0x%06x\n", 20); |
| 1484 | fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN); |
| 1485 | fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); |
| 1486 | fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long); |
James Smart | 016131b | 2006-08-14 08:20:25 -0400 | [diff] [blame] | 1487 | fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 1489 | fc_private_host_show_function(system_hostname, "%s\n", |
| 1490 | FC_SYMBOLIC_NAME_SIZE + 1, ) |
| 1491 | fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE) |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1492 | static FC_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR, |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 1493 | show_fc_host_system_hostname, store_fc_host_system_hostname); |
| 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
| 1496 | /* Private Host Attributes */ |
| 1497 | |
| 1498 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1499 | show_fc_private_host_tgtid_bind_type(struct device *dev, |
| 1500 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1502 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | const char *name; |
| 1504 | |
| 1505 | name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost)); |
| 1506 | if (!name) |
| 1507 | return -EINVAL; |
| 1508 | return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name); |
| 1509 | } |
| 1510 | |
James.Smart@Emulex.Com | d16794f6a | 2005-10-05 13:50:08 -0400 | [diff] [blame] | 1511 | #define get_list_head_entry(pos, head, member) \ |
| 1512 | pos = list_entry((head)->next, typeof(*pos), member) |
| 1513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1515 | store_fc_private_host_tgtid_bind_type(struct device *dev, |
| 1516 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1518 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
James.Smart@Emulex.Com | d16794f6a | 2005-10-05 13:50:08 -0400 | [diff] [blame] | 1519 | struct fc_rport *rport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | enum fc_tgtid_binding_type val; |
| 1521 | unsigned long flags; |
| 1522 | |
| 1523 | if (get_fc_tgtid_bind_type_match(buf, &val)) |
| 1524 | return -EINVAL; |
| 1525 | |
| 1526 | /* if changing bind type, purge all unused consistent bindings */ |
| 1527 | if (val != fc_host_tgtid_bind_type(shost)) { |
| 1528 | spin_lock_irqsave(shost->host_lock, flags); |
James.Smart@Emulex.Com | d16794f6a | 2005-10-05 13:50:08 -0400 | [diff] [blame] | 1529 | while (!list_empty(&fc_host_rport_bindings(shost))) { |
| 1530 | get_list_head_entry(rport, |
| 1531 | &fc_host_rport_bindings(shost), peers); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 1532 | list_del(&rport->peers); |
| 1533 | rport->port_state = FC_PORTSTATE_DELETED; |
| 1534 | fc_queue_work(shost, &rport->rport_delete_work); |
James.Smart@Emulex.Com | d16794f6a | 2005-10-05 13:50:08 -0400 | [diff] [blame] | 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 1537 | } |
| 1538 | |
| 1539 | fc_host_tgtid_bind_type(shost) = val; |
| 1540 | return count; |
| 1541 | } |
| 1542 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1543 | static FC_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | show_fc_private_host_tgtid_bind_type, |
| 1545 | store_fc_private_host_tgtid_bind_type); |
| 1546 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1547 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1548 | store_fc_private_host_issue_lip(struct device *dev, |
| 1549 | struct device_attribute *attr, const char *buf, size_t count) |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1550 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1551 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1552 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1553 | int ret; |
| 1554 | |
| 1555 | /* ignore any data value written to the attribute */ |
| 1556 | if (i->f->issue_fc_host_lip) { |
| 1557 | ret = i->f->issue_fc_host_lip(shost); |
| 1558 | return ret ? ret: count; |
| 1559 | } |
| 1560 | |
| 1561 | return -ENOENT; |
| 1562 | } |
| 1563 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1564 | static FC_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL, |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1565 | store_fc_private_host_issue_lip); |
| 1566 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1567 | fc_private_host_rd_attr(npiv_vports_inuse, "%u\n", 20); |
| 1568 | |
| 1569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | /* |
| 1571 | * Host Statistics Management |
| 1572 | */ |
| 1573 | |
| 1574 | /* Show a given an attribute in the statistics group */ |
| 1575 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1576 | fc_stat_show(const struct device *dev, char *buf, unsigned long offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1578 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1580 | struct fc_host_statistics *stats; |
| 1581 | ssize_t ret = -ENOENT; |
| 1582 | |
| 1583 | if (offset > sizeof(struct fc_host_statistics) || |
| 1584 | offset % sizeof(u64) != 0) |
| 1585 | WARN_ON(1); |
| 1586 | |
| 1587 | if (i->f->get_fc_host_stats) { |
| 1588 | stats = (i->f->get_fc_host_stats)(shost); |
| 1589 | if (stats) |
| 1590 | ret = snprintf(buf, 20, "0x%llx\n", |
| 1591 | (unsigned long long)*(u64 *)(((u8 *) stats) + offset)); |
| 1592 | } |
| 1593 | return ret; |
| 1594 | } |
| 1595 | |
| 1596 | |
| 1597 | /* generate a read-only statistics attribute */ |
| 1598 | #define fc_host_statistic(name) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1599 | static ssize_t show_fcstat_##name(struct device *cd, \ |
| 1600 | struct device_attribute *attr, \ |
| 1601 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | { \ |
| 1603 | return fc_stat_show(cd, buf, \ |
| 1604 | offsetof(struct fc_host_statistics, name)); \ |
| 1605 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1606 | static FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | |
| 1608 | fc_host_statistic(seconds_since_last_reset); |
| 1609 | fc_host_statistic(tx_frames); |
| 1610 | fc_host_statistic(tx_words); |
| 1611 | fc_host_statistic(rx_frames); |
| 1612 | fc_host_statistic(rx_words); |
| 1613 | fc_host_statistic(lip_count); |
| 1614 | fc_host_statistic(nos_count); |
| 1615 | fc_host_statistic(error_frames); |
| 1616 | fc_host_statistic(dumped_frames); |
| 1617 | fc_host_statistic(link_failure_count); |
| 1618 | fc_host_statistic(loss_of_sync_count); |
| 1619 | fc_host_statistic(loss_of_signal_count); |
| 1620 | fc_host_statistic(prim_seq_protocol_err_count); |
| 1621 | fc_host_statistic(invalid_tx_word_count); |
| 1622 | fc_host_statistic(invalid_crc_count); |
| 1623 | fc_host_statistic(fcp_input_requests); |
| 1624 | fc_host_statistic(fcp_output_requests); |
| 1625 | fc_host_statistic(fcp_control_requests); |
| 1626 | fc_host_statistic(fcp_input_megabytes); |
| 1627 | fc_host_statistic(fcp_output_megabytes); |
| 1628 | |
| 1629 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1630 | fc_reset_statistics(struct device *dev, struct device_attribute *attr, |
| 1631 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1633 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 1635 | |
| 1636 | /* ignore any data value written to the attribute */ |
| 1637 | if (i->f->reset_fc_host_stats) { |
| 1638 | i->f->reset_fc_host_stats(shost); |
| 1639 | return count; |
| 1640 | } |
| 1641 | |
| 1642 | return -ENOENT; |
| 1643 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1644 | static FC_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | fc_reset_statistics); |
| 1646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | static struct attribute *fc_statistics_attrs[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1648 | &device_attr_host_seconds_since_last_reset.attr, |
| 1649 | &device_attr_host_tx_frames.attr, |
| 1650 | &device_attr_host_tx_words.attr, |
| 1651 | &device_attr_host_rx_frames.attr, |
| 1652 | &device_attr_host_rx_words.attr, |
| 1653 | &device_attr_host_lip_count.attr, |
| 1654 | &device_attr_host_nos_count.attr, |
| 1655 | &device_attr_host_error_frames.attr, |
| 1656 | &device_attr_host_dumped_frames.attr, |
| 1657 | &device_attr_host_link_failure_count.attr, |
| 1658 | &device_attr_host_loss_of_sync_count.attr, |
| 1659 | &device_attr_host_loss_of_signal_count.attr, |
| 1660 | &device_attr_host_prim_seq_protocol_err_count.attr, |
| 1661 | &device_attr_host_invalid_tx_word_count.attr, |
| 1662 | &device_attr_host_invalid_crc_count.attr, |
| 1663 | &device_attr_host_fcp_input_requests.attr, |
| 1664 | &device_attr_host_fcp_output_requests.attr, |
| 1665 | &device_attr_host_fcp_control_requests.attr, |
| 1666 | &device_attr_host_fcp_input_megabytes.attr, |
| 1667 | &device_attr_host_fcp_output_megabytes.attr, |
| 1668 | &device_attr_host_reset_statistics.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | NULL |
| 1670 | }; |
| 1671 | |
| 1672 | static struct attribute_group fc_statistics_group = { |
| 1673 | .name = "statistics", |
| 1674 | .attrs = fc_statistics_attrs, |
| 1675 | }; |
| 1676 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1677 | |
| 1678 | /* Host Vport Attributes */ |
| 1679 | |
| 1680 | static int |
| 1681 | fc_parse_wwn(const char *ns, u64 *nm) |
| 1682 | { |
| 1683 | unsigned int i, j; |
| 1684 | u8 wwn[8]; |
| 1685 | |
| 1686 | memset(wwn, 0, sizeof(wwn)); |
| 1687 | |
| 1688 | /* Validate and store the new name */ |
| 1689 | for (i=0, j=0; i < 16; i++) { |
| 1690 | if ((*ns >= 'a') && (*ns <= 'f')) |
| 1691 | j = ((j << 4) | ((*ns++ -'a') + 10)); |
| 1692 | else if ((*ns >= 'A') && (*ns <= 'F')) |
| 1693 | j = ((j << 4) | ((*ns++ -'A') + 10)); |
| 1694 | else if ((*ns >= '0') && (*ns <= '9')) |
| 1695 | j = ((j << 4) | (*ns++ -'0')); |
| 1696 | else |
| 1697 | return -EINVAL; |
| 1698 | if (i % 2) { |
| 1699 | wwn[i/2] = j & 0xff; |
| 1700 | j = 0; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | *nm = wwn_to_u64(wwn); |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | /* |
| 1711 | * "Short-cut" sysfs variable to create a new vport on a FC Host. |
| 1712 | * Input is a string of the form "<WWPN>:<WWNN>". Other attributes |
| 1713 | * will default to a NPIV-based FCP_Initiator; The WWNs are specified |
| 1714 | * as hex characters, and may *not* contain any prefixes (e.g. 0x, x, etc) |
| 1715 | */ |
| 1716 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1717 | store_fc_host_vport_create(struct device *dev, struct device_attribute *attr, |
| 1718 | const char *buf, size_t count) |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1719 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1720 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1721 | struct fc_vport_identifiers vid; |
| 1722 | struct fc_vport *vport; |
| 1723 | unsigned int cnt=count; |
| 1724 | int stat; |
| 1725 | |
| 1726 | memset(&vid, 0, sizeof(vid)); |
| 1727 | |
| 1728 | /* count may include a LF at end of string */ |
| 1729 | if (buf[cnt-1] == '\n') |
| 1730 | cnt--; |
| 1731 | |
| 1732 | /* validate we have enough characters for WWPN */ |
| 1733 | if ((cnt != (16+1+16)) || (buf[16] != ':')) |
| 1734 | return -EINVAL; |
| 1735 | |
| 1736 | stat = fc_parse_wwn(&buf[0], &vid.port_name); |
| 1737 | if (stat) |
| 1738 | return stat; |
| 1739 | |
| 1740 | stat = fc_parse_wwn(&buf[17], &vid.node_name); |
| 1741 | if (stat) |
| 1742 | return stat; |
| 1743 | |
| 1744 | vid.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 1745 | vid.vport_type = FC_PORTTYPE_NPIV; |
| 1746 | /* vid.symbolic_name is already zero/NULL's */ |
| 1747 | vid.disable = false; /* always enabled */ |
| 1748 | |
| 1749 | /* we only allow support on Channel 0 !!! */ |
Andrew Vasquez | a30c3f6 | 2008-07-18 08:32:52 -0700 | [diff] [blame] | 1750 | stat = fc_vport_setup(shost, 0, &shost->shost_gendev, &vid, &vport); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1751 | return stat ? stat : count; |
| 1752 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1753 | static FC_DEVICE_ATTR(host, vport_create, S_IWUSR, NULL, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1754 | store_fc_host_vport_create); |
| 1755 | |
| 1756 | |
| 1757 | /* |
| 1758 | * "Short-cut" sysfs variable to delete a vport on a FC Host. |
| 1759 | * Vport is identified by a string containing "<WWPN>:<WWNN>". |
| 1760 | * The WWNs are specified as hex characters, and may *not* contain |
| 1761 | * any prefixes (e.g. 0x, x, etc) |
| 1762 | */ |
| 1763 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1764 | store_fc_host_vport_delete(struct device *dev, struct device_attribute *attr, |
| 1765 | const char *buf, size_t count) |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1766 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1767 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1768 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
| 1769 | struct fc_vport *vport; |
| 1770 | u64 wwpn, wwnn; |
| 1771 | unsigned long flags; |
| 1772 | unsigned int cnt=count; |
| 1773 | int stat, match; |
| 1774 | |
| 1775 | /* count may include a LF at end of string */ |
| 1776 | if (buf[cnt-1] == '\n') |
| 1777 | cnt--; |
| 1778 | |
| 1779 | /* validate we have enough characters for WWPN */ |
| 1780 | if ((cnt != (16+1+16)) || (buf[16] != ':')) |
| 1781 | return -EINVAL; |
| 1782 | |
| 1783 | stat = fc_parse_wwn(&buf[0], &wwpn); |
| 1784 | if (stat) |
| 1785 | return stat; |
| 1786 | |
| 1787 | stat = fc_parse_wwn(&buf[17], &wwnn); |
| 1788 | if (stat) |
| 1789 | return stat; |
| 1790 | |
| 1791 | spin_lock_irqsave(shost->host_lock, flags); |
| 1792 | match = 0; |
| 1793 | /* we only allow support on Channel 0 !!! */ |
| 1794 | list_for_each_entry(vport, &fc_host->vports, peers) { |
| 1795 | if ((vport->channel == 0) && |
| 1796 | (vport->port_name == wwpn) && (vport->node_name == wwnn)) { |
| 1797 | match = 1; |
| 1798 | break; |
| 1799 | } |
| 1800 | } |
| 1801 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 1802 | |
| 1803 | if (!match) |
| 1804 | return -ENODEV; |
| 1805 | |
| 1806 | stat = fc_vport_terminate(vport); |
| 1807 | return stat ? stat : count; |
| 1808 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1809 | static FC_DEVICE_ATTR(host, vport_delete, S_IWUSR, NULL, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1810 | store_fc_host_vport_delete); |
| 1811 | |
| 1812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | static int fc_host_match(struct attribute_container *cont, |
| 1814 | struct device *dev) |
| 1815 | { |
| 1816 | struct Scsi_Host *shost; |
| 1817 | struct fc_internal *i; |
| 1818 | |
| 1819 | if (!scsi_is_host_device(dev)) |
| 1820 | return 0; |
| 1821 | |
| 1822 | shost = dev_to_shost(dev); |
| 1823 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1824 | != &fc_host_class.class) |
| 1825 | return 0; |
| 1826 | |
| 1827 | i = to_fc_internal(shost->transportt); |
| 1828 | |
| 1829 | return &i->t.host_attrs.ac == cont; |
| 1830 | } |
| 1831 | |
| 1832 | static int fc_target_match(struct attribute_container *cont, |
| 1833 | struct device *dev) |
| 1834 | { |
| 1835 | struct Scsi_Host *shost; |
| 1836 | struct fc_internal *i; |
| 1837 | |
| 1838 | if (!scsi_is_target_device(dev)) |
| 1839 | return 0; |
| 1840 | |
| 1841 | shost = dev_to_shost(dev->parent); |
| 1842 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1843 | != &fc_host_class.class) |
| 1844 | return 0; |
| 1845 | |
| 1846 | i = to_fc_internal(shost->transportt); |
| 1847 | |
| 1848 | return &i->t.target_attrs.ac == cont; |
| 1849 | } |
| 1850 | |
| 1851 | static void fc_rport_dev_release(struct device *dev) |
| 1852 | { |
| 1853 | struct fc_rport *rport = dev_to_rport(dev); |
| 1854 | put_device(dev->parent); |
| 1855 | kfree(rport); |
| 1856 | } |
| 1857 | |
| 1858 | int scsi_is_fc_rport(const struct device *dev) |
| 1859 | { |
| 1860 | return dev->release == fc_rport_dev_release; |
| 1861 | } |
| 1862 | EXPORT_SYMBOL(scsi_is_fc_rport); |
| 1863 | |
| 1864 | static int fc_rport_match(struct attribute_container *cont, |
| 1865 | struct device *dev) |
| 1866 | { |
| 1867 | struct Scsi_Host *shost; |
| 1868 | struct fc_internal *i; |
| 1869 | |
| 1870 | if (!scsi_is_fc_rport(dev)) |
| 1871 | return 0; |
| 1872 | |
| 1873 | shost = dev_to_shost(dev->parent); |
| 1874 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1875 | != &fc_host_class.class) |
| 1876 | return 0; |
| 1877 | |
| 1878 | i = to_fc_internal(shost->transportt); |
| 1879 | |
| 1880 | return &i->rport_attr_cont.ac == cont; |
| 1881 | } |
| 1882 | |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1883 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 1884 | static void fc_vport_dev_release(struct device *dev) |
| 1885 | { |
| 1886 | struct fc_vport *vport = dev_to_vport(dev); |
| 1887 | put_device(dev->parent); /* release kobj parent */ |
| 1888 | kfree(vport); |
| 1889 | } |
| 1890 | |
| 1891 | int scsi_is_fc_vport(const struct device *dev) |
| 1892 | { |
| 1893 | return dev->release == fc_vport_dev_release; |
| 1894 | } |
| 1895 | EXPORT_SYMBOL(scsi_is_fc_vport); |
| 1896 | |
| 1897 | static int fc_vport_match(struct attribute_container *cont, |
| 1898 | struct device *dev) |
| 1899 | { |
| 1900 | struct fc_vport *vport; |
| 1901 | struct Scsi_Host *shost; |
| 1902 | struct fc_internal *i; |
| 1903 | |
| 1904 | if (!scsi_is_fc_vport(dev)) |
| 1905 | return 0; |
| 1906 | vport = dev_to_vport(dev); |
| 1907 | |
| 1908 | shost = vport_to_shost(vport); |
| 1909 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1910 | != &fc_host_class.class) |
| 1911 | return 0; |
| 1912 | |
| 1913 | i = to_fc_internal(shost->transportt); |
| 1914 | return &i->vport_attr_cont.ac == cont; |
| 1915 | } |
| 1916 | |
| 1917 | |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 1918 | /** |
| 1919 | * fc_timed_out - FC Transport I/O timeout intercept handler |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 1920 | * @scmd: The SCSI command which timed out |
| 1921 | * |
| 1922 | * This routine protects against error handlers getting invoked while a |
| 1923 | * rport is in a blocked state, typically due to a temporarily loss of |
| 1924 | * connectivity. If the error handlers are allowed to proceed, requests |
| 1925 | * to abort i/o, reset the target, etc will likely fail as there is no way |
| 1926 | * to communicate with the device to perform the requested function. These |
| 1927 | * failures may result in the midlayer taking the device offline, requiring |
| 1928 | * manual intervention to restore operation. |
| 1929 | * |
| 1930 | * This routine, called whenever an i/o times out, validates the state of |
| 1931 | * the underlying rport. If the rport is blocked, it returns |
| 1932 | * EH_RESET_TIMER, which will continue to reschedule the timeout. |
| 1933 | * Eventually, either the device will return, or devloss_tmo will fire, |
| 1934 | * and when the timeout then fires, it will be handled normally. |
| 1935 | * If the rport is not blocked, normal error handling continues. |
| 1936 | * |
| 1937 | * Notes: |
| 1938 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1939 | */ |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1940 | static enum blk_eh_timer_return |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 1941 | fc_timed_out(struct scsi_cmnd *scmd) |
| 1942 | { |
| 1943 | struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); |
| 1944 | |
| 1945 | if (rport->port_state == FC_PORTSTATE_BLOCKED) |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1946 | return BLK_EH_RESET_TIMER; |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 1947 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1948 | return BLK_EH_NOT_HANDLED; |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 1949 | } |
| 1950 | |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1951 | /* |
James Smart | bda2325 | 2008-04-24 12:12:46 -0400 | [diff] [blame] | 1952 | * Called by fc_user_scan to locate an rport on the shost that |
| 1953 | * matches the channel and target id, and invoke scsi_scan_target() |
| 1954 | * on the rport. |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1955 | */ |
James Smart | bda2325 | 2008-04-24 12:12:46 -0400 | [diff] [blame] | 1956 | static void |
| 1957 | fc_user_scan_tgt(struct Scsi_Host *shost, uint channel, uint id, uint lun) |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1958 | { |
| 1959 | struct fc_rport *rport; |
James Smart | bda2325 | 2008-04-24 12:12:46 -0400 | [diff] [blame] | 1960 | unsigned long flags; |
| 1961 | |
| 1962 | spin_lock_irqsave(shost->host_lock, flags); |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1963 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1964 | list_for_each_entry(rport, &fc_host_rports(shost), peers) { |
| 1965 | if (rport->scsi_target_id == -1) |
| 1966 | continue; |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 1967 | |
Hannes Reinecke | 0d2fcd9 | 2007-06-14 15:16:45 +0200 | [diff] [blame] | 1968 | if (rport->port_state != FC_PORTSTATE_ONLINE) |
| 1969 | continue; |
| 1970 | |
James Smart | bda2325 | 2008-04-24 12:12:46 -0400 | [diff] [blame] | 1971 | if ((channel == rport->channel) && |
| 1972 | (id == rport->scsi_target_id)) { |
| 1973 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 1974 | scsi_scan_target(&rport->dev, channel, id, lun, 1); |
| 1975 | return; |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
James Smart | bda2325 | 2008-04-24 12:12:46 -0400 | [diff] [blame] | 1979 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 1980 | } |
| 1981 | |
| 1982 | /* |
| 1983 | * Called via sysfs scan routines. Necessary, as the FC transport |
| 1984 | * wants to place all target objects below the rport object. So this |
| 1985 | * routine must invoke the scsi_scan_target() routine with the rport |
| 1986 | * object as the parent. |
| 1987 | */ |
| 1988 | static int |
| 1989 | fc_user_scan(struct Scsi_Host *shost, uint channel, uint id, uint lun) |
| 1990 | { |
| 1991 | uint chlo, chhi; |
| 1992 | uint tgtlo, tgthi; |
| 1993 | |
| 1994 | if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || |
| 1995 | ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || |
| 1996 | ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) |
| 1997 | return -EINVAL; |
| 1998 | |
| 1999 | if (channel == SCAN_WILD_CARD) { |
| 2000 | chlo = 0; |
| 2001 | chhi = shost->max_channel + 1; |
| 2002 | } else { |
| 2003 | chlo = channel; |
| 2004 | chhi = channel + 1; |
| 2005 | } |
| 2006 | |
| 2007 | if (id == SCAN_WILD_CARD) { |
| 2008 | tgtlo = 0; |
| 2009 | tgthi = shost->max_id; |
| 2010 | } else { |
| 2011 | tgtlo = id; |
| 2012 | tgthi = id + 1; |
| 2013 | } |
| 2014 | |
| 2015 | for ( ; chlo < chhi; chlo++) |
| 2016 | for ( ; tgtlo < tgthi; tgtlo++) |
| 2017 | fc_user_scan_tgt(shost, chlo, tgtlo, lun); |
| 2018 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 2019 | return 0; |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 2020 | } |
| 2021 | |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 2022 | static int fc_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id, |
| 2023 | int result) |
| 2024 | { |
| 2025 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 2026 | return i->f->tsk_mgmt_response(shost, nexus, tm_id, result); |
| 2027 | } |
| 2028 | |
| 2029 | static int fc_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result) |
| 2030 | { |
| 2031 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 2032 | return i->f->it_nexus_response(shost, nexus, result); |
| 2033 | } |
| 2034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | struct scsi_transport_template * |
| 2036 | fc_attach_transport(struct fc_function_template *ft) |
| 2037 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | int count; |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 2039 | struct fc_internal *i = kzalloc(sizeof(struct fc_internal), |
| 2040 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | |
| 2042 | if (unlikely(!i)) |
| 2043 | return NULL; |
| 2044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | i->t.target_attrs.ac.attrs = &i->starget_attrs[0]; |
| 2046 | i->t.target_attrs.ac.class = &fc_transport_class.class; |
| 2047 | i->t.target_attrs.ac.match = fc_target_match; |
| 2048 | i->t.target_size = sizeof(struct fc_starget_attrs); |
| 2049 | transport_container_register(&i->t.target_attrs); |
| 2050 | |
| 2051 | i->t.host_attrs.ac.attrs = &i->host_attrs[0]; |
| 2052 | i->t.host_attrs.ac.class = &fc_host_class.class; |
| 2053 | i->t.host_attrs.ac.match = fc_host_match; |
| 2054 | i->t.host_size = sizeof(struct fc_host_attrs); |
| 2055 | if (ft->get_fc_host_stats) |
| 2056 | i->t.host_attrs.statistics = &fc_statistics_group; |
| 2057 | transport_container_register(&i->t.host_attrs); |
| 2058 | |
| 2059 | i->rport_attr_cont.ac.attrs = &i->rport_attrs[0]; |
| 2060 | i->rport_attr_cont.ac.class = &fc_rport_class.class; |
| 2061 | i->rport_attr_cont.ac.match = fc_rport_match; |
| 2062 | transport_container_register(&i->rport_attr_cont); |
| 2063 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2064 | i->vport_attr_cont.ac.attrs = &i->vport_attrs[0]; |
| 2065 | i->vport_attr_cont.ac.class = &fc_vport_class.class; |
| 2066 | i->vport_attr_cont.ac.match = fc_vport_match; |
| 2067 | transport_container_register(&i->vport_attr_cont); |
| 2068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | i->f = ft; |
| 2070 | |
| 2071 | /* Transport uses the shost workq for scsi scanning */ |
| 2072 | i->t.create_work_queue = 1; |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 2073 | |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 2074 | i->t.eh_timed_out = fc_timed_out; |
| 2075 | |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 2076 | i->t.user_scan = fc_user_scan; |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 2077 | |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 2078 | /* target-mode drivers' functions */ |
| 2079 | i->t.tsk_mgmt_response = fc_tsk_mgmt_response; |
| 2080 | i->t.it_nexus_response = fc_it_nexus_response; |
| 2081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | /* |
| 2083 | * Setup SCSI Target Attributes. |
| 2084 | */ |
| 2085 | count = 0; |
| 2086 | SETUP_STARGET_ATTRIBUTE_RD(node_name); |
| 2087 | SETUP_STARGET_ATTRIBUTE_RD(port_name); |
| 2088 | SETUP_STARGET_ATTRIBUTE_RD(port_id); |
| 2089 | |
| 2090 | BUG_ON(count > FC_STARGET_NUM_ATTRS); |
| 2091 | |
| 2092 | i->starget_attrs[count] = NULL; |
| 2093 | |
| 2094 | |
| 2095 | /* |
| 2096 | * Setup SCSI Host Attributes. |
| 2097 | */ |
| 2098 | count=0; |
| 2099 | SETUP_HOST_ATTRIBUTE_RD(node_name); |
| 2100 | SETUP_HOST_ATTRIBUTE_RD(port_name); |
Andreas Herrmann | 6b7281d | 2006-01-13 02:16:54 +0100 | [diff] [blame] | 2101 | SETUP_HOST_ATTRIBUTE_RD(permanent_port_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | SETUP_HOST_ATTRIBUTE_RD(supported_classes); |
| 2103 | SETUP_HOST_ATTRIBUTE_RD(supported_fc4s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | SETUP_HOST_ATTRIBUTE_RD(supported_speeds); |
| 2105 | SETUP_HOST_ATTRIBUTE_RD(maxframe_size); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2106 | if (ft->vport_create) { |
| 2107 | SETUP_HOST_ATTRIBUTE_RD_NS(max_npiv_vports); |
| 2108 | SETUP_HOST_ATTRIBUTE_RD_NS(npiv_vports_inuse); |
| 2109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | SETUP_HOST_ATTRIBUTE_RD(serial_number); |
| 2111 | |
| 2112 | SETUP_HOST_ATTRIBUTE_RD(port_id); |
| 2113 | SETUP_HOST_ATTRIBUTE_RD(port_type); |
| 2114 | SETUP_HOST_ATTRIBUTE_RD(port_state); |
| 2115 | SETUP_HOST_ATTRIBUTE_RD(active_fc4s); |
| 2116 | SETUP_HOST_ATTRIBUTE_RD(speed); |
| 2117 | SETUP_HOST_ATTRIBUTE_RD(fabric_name); |
James Smart | 016131b | 2006-08-14 08:20:25 -0400 | [diff] [blame] | 2118 | SETUP_HOST_ATTRIBUTE_RD(symbolic_name); |
James Smart | b8d0821 | 2006-08-17 08:00:43 -0400 | [diff] [blame] | 2119 | SETUP_HOST_ATTRIBUTE_RW(system_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | |
| 2121 | /* Transport-managed attributes */ |
| 2122 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type); |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 2123 | if (ft->issue_fc_host_lip) |
| 2124 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2125 | if (ft->vport_create) |
| 2126 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_create); |
| 2127 | if (ft->vport_delete) |
| 2128 | SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_delete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
| 2130 | BUG_ON(count > FC_HOST_NUM_ATTRS); |
| 2131 | |
| 2132 | i->host_attrs[count] = NULL; |
| 2133 | |
| 2134 | /* |
| 2135 | * Setup Remote Port Attributes. |
| 2136 | */ |
| 2137 | count=0; |
| 2138 | SETUP_RPORT_ATTRIBUTE_RD(maxframe_size); |
| 2139 | SETUP_RPORT_ATTRIBUTE_RD(supported_classes); |
| 2140 | SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo); |
| 2141 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name); |
| 2142 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name); |
| 2143 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id); |
| 2144 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles); |
| 2145 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state); |
| 2146 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id); |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2147 | SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | |
| 2149 | BUG_ON(count > FC_RPORT_NUM_ATTRS); |
| 2150 | |
| 2151 | i->rport_attrs[count] = NULL; |
| 2152 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2153 | /* |
| 2154 | * Setup Virtual Port Attributes. |
| 2155 | */ |
| 2156 | count=0; |
| 2157 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_state); |
| 2158 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_last_state); |
| 2159 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(node_name); |
| 2160 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(port_name); |
| 2161 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(roles); |
| 2162 | SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_type); |
| 2163 | SETUP_VPORT_ATTRIBUTE_RW(symbolic_name); |
| 2164 | SETUP_VPORT_ATTRIBUTE_WR(vport_delete); |
| 2165 | SETUP_VPORT_ATTRIBUTE_WR(vport_disable); |
| 2166 | |
| 2167 | BUG_ON(count > FC_VPORT_NUM_ATTRS); |
| 2168 | |
| 2169 | i->vport_attrs[count] = NULL; |
| 2170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | return &i->t; |
| 2172 | } |
| 2173 | EXPORT_SYMBOL(fc_attach_transport); |
| 2174 | |
| 2175 | void fc_release_transport(struct scsi_transport_template *t) |
| 2176 | { |
| 2177 | struct fc_internal *i = to_fc_internal(t); |
| 2178 | |
| 2179 | transport_container_unregister(&i->t.target_attrs); |
| 2180 | transport_container_unregister(&i->t.host_attrs); |
| 2181 | transport_container_unregister(&i->rport_attr_cont); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2182 | transport_container_unregister(&i->vport_attr_cont); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
| 2184 | kfree(i); |
| 2185 | } |
| 2186 | EXPORT_SYMBOL(fc_release_transport); |
| 2187 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2188 | /** |
| 2189 | * fc_queue_work - Queue work to the fc_host workqueue. |
| 2190 | * @shost: Pointer to Scsi_Host bound to fc_host. |
| 2191 | * @work: Work to queue for execution. |
| 2192 | * |
| 2193 | * Return value: |
James Smart | a0785ed | 2006-05-11 13:27:09 -0400 | [diff] [blame] | 2194 | * 1 - work queued for execution |
| 2195 | * 0 - work is already queued |
| 2196 | * -EINVAL - work queue doesn't exist |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2197 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2198 | static int |
| 2199 | fc_queue_work(struct Scsi_Host *shost, struct work_struct *work) |
| 2200 | { |
| 2201 | if (unlikely(!fc_host_work_q(shost))) { |
| 2202 | printk(KERN_ERR |
| 2203 | "ERROR: FC host '%s' attempted to queue work, " |
| 2204 | "when no workqueue created.\n", shost->hostt->name); |
| 2205 | dump_stack(); |
| 2206 | |
| 2207 | return -EINVAL; |
| 2208 | } |
| 2209 | |
| 2210 | return queue_work(fc_host_work_q(shost), work); |
| 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * fc_flush_work - Flush a fc_host's workqueue. |
| 2215 | * @shost: Pointer to Scsi_Host bound to fc_host. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2216 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2217 | static void |
| 2218 | fc_flush_work(struct Scsi_Host *shost) |
| 2219 | { |
| 2220 | if (!fc_host_work_q(shost)) { |
| 2221 | printk(KERN_ERR |
| 2222 | "ERROR: FC host '%s' attempted to flush work, " |
| 2223 | "when no workqueue created.\n", shost->hostt->name); |
| 2224 | dump_stack(); |
| 2225 | return; |
| 2226 | } |
| 2227 | |
| 2228 | flush_workqueue(fc_host_work_q(shost)); |
| 2229 | } |
| 2230 | |
| 2231 | /** |
| 2232 | * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue. |
| 2233 | * @shost: Pointer to Scsi_Host bound to fc_host. |
| 2234 | * @work: Work to queue for execution. |
| 2235 | * @delay: jiffies to delay the work queuing |
| 2236 | * |
| 2237 | * Return value: |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2238 | * 1 on success / 0 already queued / < 0 for error |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2239 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2240 | static int |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2241 | fc_queue_devloss_work(struct Scsi_Host *shost, struct delayed_work *work, |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2242 | unsigned long delay) |
| 2243 | { |
| 2244 | if (unlikely(!fc_host_devloss_work_q(shost))) { |
| 2245 | printk(KERN_ERR |
| 2246 | "ERROR: FC host '%s' attempted to queue work, " |
| 2247 | "when no workqueue created.\n", shost->hostt->name); |
| 2248 | dump_stack(); |
| 2249 | |
| 2250 | return -EINVAL; |
| 2251 | } |
| 2252 | |
| 2253 | return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay); |
| 2254 | } |
| 2255 | |
| 2256 | /** |
| 2257 | * fc_flush_devloss - Flush a fc_host's devloss workqueue. |
| 2258 | * @shost: Pointer to Scsi_Host bound to fc_host. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2259 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2260 | static void |
| 2261 | fc_flush_devloss(struct Scsi_Host *shost) |
| 2262 | { |
| 2263 | if (!fc_host_devloss_work_q(shost)) { |
| 2264 | printk(KERN_ERR |
| 2265 | "ERROR: FC host '%s' attempted to flush work, " |
| 2266 | "when no workqueue created.\n", shost->hostt->name); |
| 2267 | dump_stack(); |
| 2268 | return; |
| 2269 | } |
| 2270 | |
| 2271 | flush_workqueue(fc_host_devloss_work_q(shost)); |
| 2272 | } |
| 2273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | |
| 2275 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2276 | * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host. |
| 2277 | * @shost: Which &Scsi_Host |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | * |
| 2279 | * This routine is expected to be called immediately preceeding the |
| 2280 | * a driver's call to scsi_remove_host(). |
| 2281 | * |
| 2282 | * WARNING: A driver utilizing the fc_transport, which fails to call |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2283 | * this routine prior to scsi_remove_host(), will leave dangling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | * objects in /sys/class/fc_remote_ports. Access to any of these |
| 2285 | * objects can result in a system crash !!! |
| 2286 | * |
| 2287 | * Notes: |
| 2288 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2289 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | void |
| 2291 | fc_remove_host(struct Scsi_Host *shost) |
| 2292 | { |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2293 | struct fc_vport *vport = NULL, *next_vport = NULL; |
| 2294 | struct fc_rport *rport = NULL, *next_rport = NULL; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2295 | struct workqueue_struct *work_q; |
| 2296 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2297 | unsigned long flags; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2298 | |
| 2299 | spin_lock_irqsave(shost->host_lock, flags); |
| 2300 | |
| 2301 | /* Remove any vports */ |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 2302 | list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) |
| 2303 | fc_queue_work(shost, &vport->vport_delete_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | |
| 2305 | /* Remove any remote ports */ |
| 2306 | list_for_each_entry_safe(rport, next_rport, |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2307 | &fc_host->rports, peers) { |
| 2308 | list_del(&rport->peers); |
| 2309 | rport->port_state = FC_PORTSTATE_DELETED; |
| 2310 | fc_queue_work(shost, &rport->rport_delete_work); |
| 2311 | } |
| 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | list_for_each_entry_safe(rport, next_rport, |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2314 | &fc_host->rport_bindings, peers) { |
| 2315 | list_del(&rport->peers); |
| 2316 | rport->port_state = FC_PORTSTATE_DELETED; |
| 2317 | fc_queue_work(shost, &rport->rport_delete_work); |
| 2318 | } |
| 2319 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2320 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2321 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2322 | /* flush all scan work items */ |
| 2323 | scsi_flush_work(shost); |
| 2324 | |
| 2325 | /* flush all stgt delete, and rport delete work items, then kill it */ |
| 2326 | if (fc_host->work_q) { |
| 2327 | work_q = fc_host->work_q; |
| 2328 | fc_host->work_q = NULL; |
| 2329 | destroy_workqueue(work_q); |
| 2330 | } |
| 2331 | |
| 2332 | /* flush all devloss work items, then kill it */ |
| 2333 | if (fc_host->devloss_work_q) { |
| 2334 | work_q = fc_host->devloss_work_q; |
| 2335 | fc_host->devloss_work_q = NULL; |
| 2336 | destroy_workqueue(work_q); |
| 2337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | } |
| 2339 | EXPORT_SYMBOL(fc_remove_host); |
| 2340 | |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2341 | static void fc_terminate_rport_io(struct fc_rport *rport) |
| 2342 | { |
| 2343 | struct Scsi_Host *shost = rport_to_shost(rport); |
| 2344 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 2345 | |
| 2346 | /* Involve the LLDD if possible to terminate all io on the rport. */ |
| 2347 | if (i->f->terminate_rport_io) |
| 2348 | i->f->terminate_rport_io(rport); |
| 2349 | |
| 2350 | /* |
| 2351 | * must unblock to flush queued IO. The caller will have set |
| 2352 | * the port_state or flags, so that fc_remote_port_chkready will |
| 2353 | * fail IO. |
| 2354 | */ |
| 2355 | scsi_target_unblock(&rport->dev); |
| 2356 | } |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2357 | |
| 2358 | /** |
| 2359 | * fc_starget_delete - called to delete the scsi decendents of an rport |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2360 | * @work: remote port to be operated on. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2361 | * |
| 2362 | * Deletes target and all sdevs. |
| 2363 | */ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2364 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2365 | fc_starget_delete(struct work_struct *work) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2366 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2367 | struct fc_rport *rport = |
| 2368 | container_of(work, struct fc_rport, stgt_delete_work); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2369 | |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2370 | fc_terminate_rport_io(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2371 | scsi_remove_target(&rport->dev); |
| 2372 | } |
| 2373 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2374 | |
| 2375 | /** |
| 2376 | * fc_rport_final_delete - finish rport termination and delete it. |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2377 | * @work: remote port to be deleted. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2378 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2379 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2380 | fc_rport_final_delete(struct work_struct *work) |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2381 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2382 | struct fc_rport *rport = |
| 2383 | container_of(work, struct fc_rport, rport_delete_work); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2384 | struct device *dev = &rport->dev; |
| 2385 | struct Scsi_Host *shost = rport_to_shost(rport); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2386 | struct fc_internal *i = to_fc_internal(shost->transportt); |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2387 | unsigned long flags; |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 2388 | int do_callback = 0; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2389 | |
| 2390 | /* |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 2391 | * if a scan is pending, flush the SCSI Host work_q so that |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2392 | * that we can reclaim the rport scan work element. |
| 2393 | */ |
| 2394 | if (rport->flags & FC_RPORT_SCAN_PENDING) |
| 2395 | scsi_flush_work(shost); |
| 2396 | |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2397 | fc_terminate_rport_io(rport); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 2398 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2399 | /* |
| 2400 | * Cancel any outstanding timers. These should really exist |
| 2401 | * only when rmmod'ing the LLDD and we're asking for |
| 2402 | * immediate termination of the rports |
| 2403 | */ |
| 2404 | spin_lock_irqsave(shost->host_lock, flags); |
| 2405 | if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { |
| 2406 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2407 | if (!cancel_delayed_work(&rport->fail_io_work)) |
| 2408 | fc_flush_devloss(shost); |
| 2409 | if (!cancel_delayed_work(&rport->dev_loss_work)) |
| 2410 | fc_flush_devloss(shost); |
| 2411 | spin_lock_irqsave(shost->host_lock, flags); |
| 2412 | rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; |
| 2413 | } |
| 2414 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2415 | |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2416 | /* Delete SCSI target and sdevs */ |
| 2417 | if (rport->scsi_target_id != -1) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2418 | fc_starget_delete(&rport->stgt_delete_work); |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2419 | |
| 2420 | /* |
| 2421 | * Notify the driver that the rport is now dead. The LLDD will |
| 2422 | * also guarantee that any communication to the rport is terminated |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 2423 | * |
| 2424 | * Avoid this call if we already called it when we preserved the |
| 2425 | * rport for the binding. |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2426 | */ |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 2427 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 2428 | if (!(rport->flags & FC_RPORT_DEVLOSS_CALLBK_DONE) && |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 2429 | (i->f->dev_loss_tmo_callbk)) { |
| 2430 | rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; |
| 2431 | do_callback = 1; |
| 2432 | } |
| 2433 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2434 | |
| 2435 | if (do_callback) |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2436 | i->f->dev_loss_tmo_callbk(rport); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2437 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 2438 | fc_bsg_remove(rport->rqst_q); |
| 2439 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2440 | transport_remove_device(dev); |
| 2441 | device_del(dev); |
| 2442 | transport_destroy_device(dev); |
James Smart | 3bdad7b | 2006-06-26 14:19:59 -0400 | [diff] [blame] | 2443 | put_device(&shost->shost_gendev); /* for fc_host->rport list */ |
| 2444 | put_device(dev); /* for self-reference */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | /** |
| 2449 | * fc_rport_create - allocates and creates a remote FC port. |
| 2450 | * @shost: scsi host the remote port is connected to. |
| 2451 | * @channel: Channel on shost port connected to. |
| 2452 | * @ids: The world wide names, fc address, and FC4 port |
| 2453 | * roles for the remote port. |
| 2454 | * |
| 2455 | * Allocates and creates the remoter port structure, including the |
| 2456 | * class and sysfs creation. |
| 2457 | * |
| 2458 | * Notes: |
| 2459 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2460 | */ |
Adrian Bunk | 44818ef | 2007-07-09 11:59:59 -0700 | [diff] [blame] | 2461 | static struct fc_rport * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | fc_rport_create(struct Scsi_Host *shost, int channel, |
| 2463 | struct fc_rport_identifiers *ids) |
| 2464 | { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2465 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | struct fc_internal *fci = to_fc_internal(shost->transportt); |
| 2467 | struct fc_rport *rport; |
| 2468 | struct device *dev; |
| 2469 | unsigned long flags; |
| 2470 | int error; |
| 2471 | size_t size; |
| 2472 | |
| 2473 | size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size); |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 2474 | rport = kzalloc(size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | if (unlikely(!rport)) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2476 | printk(KERN_ERR "%s: allocation failure\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | return NULL; |
| 2478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
| 2480 | rport->maxframe_size = -1; |
| 2481 | rport->supported_classes = FC_COS_UNSPECIFIED; |
| 2482 | rport->dev_loss_tmo = fc_dev_loss_tmo; |
| 2483 | memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name)); |
| 2484 | memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name)); |
| 2485 | rport->port_id = ids->port_id; |
| 2486 | rport->roles = ids->roles; |
| 2487 | rport->port_state = FC_PORTSTATE_ONLINE; |
| 2488 | if (fci->f->dd_fcrport_size) |
| 2489 | rport->dd_data = &rport[1]; |
| 2490 | rport->channel = channel; |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2491 | rport->fast_io_fail_tmo = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2493 | INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport); |
| 2494 | INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io); |
| 2495 | INIT_WORK(&rport->scan_work, fc_scsi_scan_rport); |
| 2496 | INIT_WORK(&rport->stgt_delete_work, fc_starget_delete); |
| 2497 | INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | |
| 2499 | spin_lock_irqsave(shost->host_lock, flags); |
| 2500 | |
| 2501 | rport->number = fc_host->next_rport_number++; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2502 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | rport->scsi_target_id = fc_host->next_target_id++; |
| 2504 | else |
| 2505 | rport->scsi_target_id = -1; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2506 | list_add_tail(&rport->peers, &fc_host->rports); |
James Smart | 3bdad7b | 2006-06-26 14:19:59 -0400 | [diff] [blame] | 2507 | get_device(&shost->shost_gendev); /* for fc_host->rport list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
| 2509 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2510 | |
| 2511 | dev = &rport->dev; |
James Smart | 3bdad7b | 2006-06-26 14:19:59 -0400 | [diff] [blame] | 2512 | device_initialize(dev); /* takes self reference */ |
| 2513 | dev->parent = get_device(&shost->shost_gendev); /* parent reference */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | dev->release = fc_rport_dev_release; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2515 | dev_set_name(dev, "rport-%d:%d-%d", |
| 2516 | shost->host_no, channel, rport->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | transport_setup_device(dev); |
| 2518 | |
| 2519 | error = device_add(dev); |
| 2520 | if (error) { |
| 2521 | printk(KERN_ERR "FC Remote Port device_add failed\n"); |
| 2522 | goto delete_rport; |
| 2523 | } |
| 2524 | transport_add_device(dev); |
| 2525 | transport_configure_device(dev); |
| 2526 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 2527 | fc_bsg_rportadd(shost, rport); |
| 2528 | /* ignore any bsg add error - we just can't do sgio */ |
| 2529 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2530 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | /* initiate a scan of the target */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2532 | rport->flags |= FC_RPORT_SCAN_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | scsi_queue_work(shost, &rport->scan_work); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | |
| 2536 | return rport; |
| 2537 | |
| 2538 | delete_rport: |
| 2539 | transport_destroy_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | spin_lock_irqsave(shost->host_lock, flags); |
| 2541 | list_del(&rport->peers); |
James Smart | 3bdad7b | 2006-06-26 14:19:59 -0400 | [diff] [blame] | 2542 | put_device(&shost->shost_gendev); /* for fc_host->rport list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2544 | put_device(dev->parent); |
| 2545 | kfree(rport); |
| 2546 | return NULL; |
| 2547 | } |
| 2548 | |
| 2549 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2550 | * fc_remote_port_add - notify fc transport of the existence of a remote FC port. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | * @shost: scsi host the remote port is connected to. |
| 2552 | * @channel: Channel on shost port connected to. |
| 2553 | * @ids: The world wide names, fc address, and FC4 port |
| 2554 | * roles for the remote port. |
| 2555 | * |
| 2556 | * The LLDD calls this routine to notify the transport of the existence |
| 2557 | * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn) |
| 2558 | * of the port, it's FC address (port_id), and the FC4 roles that are |
| 2559 | * active for the port. |
| 2560 | * |
| 2561 | * For ports that are FCP targets (aka scsi targets), the FC transport |
| 2562 | * maintains consistent target id bindings on behalf of the LLDD. |
| 2563 | * A consistent target id binding is an assignment of a target id to |
| 2564 | * a remote port identifier, which persists while the scsi host is |
| 2565 | * attached. The remote port can disappear, then later reappear, and |
| 2566 | * it's target id assignment remains the same. This allows for shifts |
| 2567 | * in FC addressing (if binding by wwpn or wwnn) with no apparent |
| 2568 | * changes to the scsi subsystem which is based on scsi host number and |
| 2569 | * target id values. Bindings are only valid during the attachment of |
| 2570 | * the scsi host. If the host detaches, then later re-attaches, target |
| 2571 | * id bindings may change. |
| 2572 | * |
| 2573 | * This routine is responsible for returning a remote port structure. |
| 2574 | * The routine will search the list of remote ports it maintains |
| 2575 | * internally on behalf of consistent target id mappings. If found, the |
| 2576 | * remote port structure will be reused. Otherwise, a new remote port |
| 2577 | * structure will be allocated. |
| 2578 | * |
| 2579 | * Whenever a remote port is allocated, a new fc_remote_port class |
| 2580 | * device is created. |
| 2581 | * |
| 2582 | * Should not be called from interrupt context. |
| 2583 | * |
| 2584 | * Notes: |
| 2585 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2586 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | struct fc_rport * |
| 2588 | fc_remote_port_add(struct Scsi_Host *shost, int channel, |
| 2589 | struct fc_rport_identifiers *ids) |
| 2590 | { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2591 | struct fc_internal *fci = to_fc_internal(shost->transportt); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2592 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | struct fc_rport *rport; |
| 2594 | unsigned long flags; |
| 2595 | int match = 0; |
| 2596 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2597 | /* ensure any stgt delete functions are done */ |
| 2598 | fc_flush_work(shost); |
| 2599 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2600 | /* |
| 2601 | * Search the list of "active" rports, for an rport that has been |
| 2602 | * deleted, but we've held off the real delete while the target |
| 2603 | * is in a "blocked" state. |
| 2604 | */ |
| 2605 | spin_lock_irqsave(shost->host_lock, flags); |
| 2606 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2607 | list_for_each_entry(rport, &fc_host->rports, peers) { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2608 | |
| 2609 | if ((rport->port_state == FC_PORTSTATE_BLOCKED) && |
| 2610 | (rport->channel == channel)) { |
| 2611 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2612 | switch (fc_host->tgtid_bind_type) { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2613 | case FC_TGTID_BIND_BY_WWPN: |
| 2614 | case FC_TGTID_BIND_NONE: |
| 2615 | if (rport->port_name == ids->port_name) |
| 2616 | match = 1; |
| 2617 | break; |
| 2618 | case FC_TGTID_BIND_BY_WWNN: |
| 2619 | if (rport->node_name == ids->node_name) |
| 2620 | match = 1; |
| 2621 | break; |
| 2622 | case FC_TGTID_BIND_BY_ID: |
| 2623 | if (rport->port_id == ids->port_id) |
| 2624 | match = 1; |
| 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | if (match) { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2629 | |
| 2630 | memcpy(&rport->node_name, &ids->node_name, |
| 2631 | sizeof(rport->node_name)); |
| 2632 | memcpy(&rport->port_name, &ids->port_name, |
| 2633 | sizeof(rport->port_name)); |
| 2634 | rport->port_id = ids->port_id; |
| 2635 | |
| 2636 | rport->port_state = FC_PORTSTATE_ONLINE; |
| 2637 | rport->roles = ids->roles; |
| 2638 | |
| 2639 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2640 | |
| 2641 | if (fci->f->dd_fcrport_size) |
| 2642 | memset(rport->dd_data, 0, |
| 2643 | fci->f->dd_fcrport_size); |
| 2644 | |
| 2645 | /* |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2646 | * If we were not a target, cancel the |
| 2647 | * io terminate and rport timers, and |
| 2648 | * we're done. |
| 2649 | * |
| 2650 | * If we were a target, but our new role |
| 2651 | * doesn't indicate a target, leave the |
| 2652 | * timers running expecting the role to |
| 2653 | * change as the target fully logs in. If |
| 2654 | * it doesn't, the target will be torn down. |
| 2655 | * |
| 2656 | * If we were a target, and our role shows |
| 2657 | * we're still a target, cancel the timers |
| 2658 | * and kick off a scan. |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2659 | */ |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2660 | |
| 2661 | /* was a target, not in roles */ |
| 2662 | if ((rport->scsi_target_id != -1) && |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2663 | (!(ids->roles & FC_PORT_ROLE_FCP_TARGET))) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2664 | return rport; |
| 2665 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2666 | /* |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2667 | * Stop the fail io and dev_loss timers. |
| 2668 | * If they flush, the port_state will |
| 2669 | * be checked and will NOOP the function. |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2670 | */ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2671 | if (!cancel_delayed_work(&rport->fail_io_work)) |
| 2672 | fc_flush_devloss(shost); |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2673 | if (!cancel_delayed_work(&rport->dev_loss_work)) |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2674 | fc_flush_devloss(shost); |
| 2675 | |
| 2676 | spin_lock_irqsave(shost->host_lock, flags); |
| 2677 | |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2678 | rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 2679 | FC_RPORT_DEVLOSS_PENDING | |
| 2680 | FC_RPORT_DEVLOSS_CALLBK_DONE); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2681 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2682 | /* if target, initiate a scan */ |
| 2683 | if (rport->scsi_target_id != -1) { |
| 2684 | rport->flags |= FC_RPORT_SCAN_PENDING; |
| 2685 | scsi_queue_work(shost, |
| 2686 | &rport->scan_work); |
| 2687 | spin_unlock_irqrestore(shost->host_lock, |
| 2688 | flags); |
| 2689 | scsi_target_unblock(&rport->dev); |
| 2690 | } else |
| 2691 | spin_unlock_irqrestore(shost->host_lock, |
| 2692 | flags); |
James Smart | a0785ed | 2006-05-11 13:27:09 -0400 | [diff] [blame] | 2693 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 2694 | fc_bsg_goose_queue(rport); |
| 2695 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2696 | return rport; |
| 2697 | } |
| 2698 | } |
| 2699 | } |
| 2700 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2701 | /* |
| 2702 | * Search the bindings array |
| 2703 | * Note: if never a FCP target, you won't be on this list |
| 2704 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2705 | if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
| 2707 | /* search for a matching consistent binding */ |
| 2708 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2709 | list_for_each_entry(rport, &fc_host->rport_bindings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | peers) { |
| 2711 | if (rport->channel != channel) |
| 2712 | continue; |
| 2713 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2714 | switch (fc_host->tgtid_bind_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | case FC_TGTID_BIND_BY_WWPN: |
| 2716 | if (rport->port_name == ids->port_name) |
| 2717 | match = 1; |
| 2718 | break; |
| 2719 | case FC_TGTID_BIND_BY_WWNN: |
| 2720 | if (rport->node_name == ids->node_name) |
| 2721 | match = 1; |
| 2722 | break; |
| 2723 | case FC_TGTID_BIND_BY_ID: |
| 2724 | if (rport->port_id == ids->port_id) |
| 2725 | match = 1; |
| 2726 | break; |
| 2727 | case FC_TGTID_BIND_NONE: /* to keep compiler happy */ |
| 2728 | break; |
| 2729 | } |
| 2730 | |
| 2731 | if (match) { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2732 | list_move_tail(&rport->peers, &fc_host->rports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | break; |
| 2734 | } |
| 2735 | } |
| 2736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | if (match) { |
| 2738 | memcpy(&rport->node_name, &ids->node_name, |
| 2739 | sizeof(rport->node_name)); |
| 2740 | memcpy(&rport->port_name, &ids->port_name, |
| 2741 | sizeof(rport->port_name)); |
| 2742 | rport->port_id = ids->port_id; |
| 2743 | rport->roles = ids->roles; |
| 2744 | rport->port_state = FC_PORTSTATE_ONLINE; |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2745 | rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2747 | if (fci->f->dd_fcrport_size) |
| 2748 | memset(rport->dd_data, 0, |
| 2749 | fci->f->dd_fcrport_size); |
| 2750 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2751 | if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | /* initiate a scan of the target */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2753 | rport->flags |= FC_RPORT_SCAN_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | scsi_queue_work(shost, &rport->scan_work); |
James Smart | a0785ed | 2006-05-11 13:27:09 -0400 | [diff] [blame] | 2755 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2756 | scsi_target_unblock(&rport->dev); |
| 2757 | } else |
| 2758 | spin_unlock_irqrestore(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | |
| 2760 | return rport; |
| 2761 | } |
| 2762 | } |
| 2763 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2764 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | /* No consistent binding found - create new remote port entry */ |
| 2767 | rport = fc_rport_create(shost, channel, ids); |
| 2768 | |
| 2769 | return rport; |
| 2770 | } |
| 2771 | EXPORT_SYMBOL(fc_remote_port_add); |
| 2772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | |
| 2774 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2775 | * fc_remote_port_delete - notifies the fc transport that a remote port is no longer in existence. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | * @rport: The remote port that no longer exists |
| 2777 | * |
| 2778 | * The LLDD calls this routine to notify the transport that a remote |
| 2779 | * port is no longer part of the topology. Note: Although a port |
| 2780 | * may no longer be part of the topology, it may persist in the remote |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2781 | * ports displayed by the fc_host. We do this under 2 conditions: |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2782 | * 1) If the port was a scsi target, we delay its deletion by "blocking" it. |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2783 | * This allows the port to temporarily disappear, then reappear without |
| 2784 | * disrupting the SCSI device tree attached to it. During the "blocked" |
| 2785 | * period the port will still exist. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2786 | * 2) If the port was a scsi target and disappears for longer than we |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2787 | * expect, we'll delete the port and the tear down the SCSI device tree |
| 2788 | * attached to it. However, we want to semi-persist the target id assigned |
| 2789 | * to that port if it eventually does exist. The port structure will |
| 2790 | * remain (although with minimal information) so that the target id |
| 2791 | * bindings remails. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | * |
| 2793 | * If the remote port is not an FCP Target, it will be fully torn down |
| 2794 | * and deallocated, including the fc_remote_port class device. |
| 2795 | * |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2796 | * If the remote port is an FCP Target, the port will be placed in a |
| 2797 | * temporary blocked state. From the LLDD's perspective, the rport no |
| 2798 | * longer exists. From the SCSI midlayer's perspective, the SCSI target |
| 2799 | * exists, but all sdevs on it are blocked from further I/O. The following |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2800 | * is then expected. |
| 2801 | * |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2802 | * If the remote port does not return (signaled by a LLDD call to |
| 2803 | * fc_remote_port_add()) within the dev_loss_tmo timeout, then the |
| 2804 | * scsi target is removed - killing all outstanding i/o and removing the |
| 2805 | * scsi devices attached ot it. The port structure will be marked Not |
| 2806 | * Present and be partially cleared, leaving only enough information to |
| 2807 | * recognize the remote port relative to the scsi target id binding if |
| 2808 | * it later appears. The port will remain as long as there is a valid |
| 2809 | * binding (e.g. until the user changes the binding type or unloads the |
| 2810 | * scsi host with the binding). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | * |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2812 | * If the remote port returns within the dev_loss_tmo value (and matches |
| 2813 | * according to the target id binding type), the port structure will be |
| 2814 | * reused. If it is no longer a SCSI target, the target will be torn |
| 2815 | * down. If it continues to be a SCSI target, then the target will be |
| 2816 | * unblocked (allowing i/o to be resumed), and a scan will be activated |
| 2817 | * to ensure that all luns are detected. |
| 2818 | * |
| 2819 | * Called from normal process context only - cannot be called from interrupt. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | * |
| 2821 | * Notes: |
| 2822 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2823 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | void |
| 2825 | fc_remote_port_delete(struct fc_rport *rport) |
| 2826 | { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2827 | struct Scsi_Host *shost = rport_to_shost(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2828 | int timeout = rport->dev_loss_tmo; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2829 | unsigned long flags; |
| 2830 | |
| 2831 | /* |
| 2832 | * No need to flush the fc_host work_q's, as all adds are synchronous. |
| 2833 | * |
| 2834 | * We do need to reclaim the rport scan work element, so eventually |
| 2835 | * (in fc_rport_final_delete()) we'll flush the scsi host work_q if |
| 2836 | * there's still a scan pending. |
| 2837 | */ |
| 2838 | |
| 2839 | spin_lock_irqsave(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2841 | if (rport->port_state != FC_PORTSTATE_ONLINE) { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2842 | spin_unlock_irqrestore(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | return; |
| 2844 | } |
| 2845 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2846 | /* |
| 2847 | * In the past, we if this was not an FCP-Target, we would |
| 2848 | * unconditionally just jump to deleting the rport. |
| 2849 | * However, rports can be used as node containers by the LLDD, |
| 2850 | * and its not appropriate to just terminate the rport at the |
| 2851 | * first sign of a loss in connectivity. The LLDD may want to |
| 2852 | * send ELS traffic to re-validate the login. If the rport is |
| 2853 | * immediately deleted, it makes it inappropriate for a node |
| 2854 | * container. |
| 2855 | * So... we now unconditionally wait dev_loss_tmo before |
| 2856 | * destroying an rport. |
| 2857 | */ |
| 2858 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2859 | rport->port_state = FC_PORTSTATE_BLOCKED; |
| 2860 | |
| 2861 | rport->flags |= FC_RPORT_DEVLOSS_PENDING; |
| 2862 | |
| 2863 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2864 | |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 2865 | if (rport->roles & FC_PORT_ROLE_FCP_INITIATOR && |
| 2866 | shost->active_mode & MODE_TARGET) |
| 2867 | fc_tgt_it_nexus_destroy(shost, (unsigned long)rport); |
| 2868 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2869 | scsi_target_block(&rport->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2871 | /* see if we need to kill io faster than waiting for device loss */ |
| 2872 | if ((rport->fast_io_fail_tmo != -1) && |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2873 | (rport->fast_io_fail_tmo < timeout)) |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2874 | fc_queue_devloss_work(shost, &rport->fail_io_work, |
| 2875 | rport->fast_io_fail_tmo * HZ); |
| 2876 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2877 | /* cap the length the devices can be blocked until they are deleted */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2878 | fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | } |
| 2880 | EXPORT_SYMBOL(fc_remote_port_delete); |
| 2881 | |
| 2882 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2883 | * fc_remote_port_rolechg - notifies the fc transport that the roles on a remote may have changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | * @rport: The remote port that changed. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2885 | * @roles: New roles for this port. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | * |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2887 | * Description: The LLDD calls this routine to notify the transport that the |
| 2888 | * roles on a remote port may have changed. The largest effect of this is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | * if a port now becomes a FCP Target, it must be allocated a |
| 2890 | * scsi target id. If the port is no longer a FCP target, any |
| 2891 | * scsi target id value assigned to it will persist in case the |
| 2892 | * role changes back to include FCP Target. No changes in the scsi |
| 2893 | * midlayer will be invoked if the role changes (in the expectation |
| 2894 | * that the role will be resumed. If it doesn't normal error processing |
| 2895 | * will take place). |
| 2896 | * |
| 2897 | * Should not be called from interrupt context. |
| 2898 | * |
| 2899 | * Notes: |
| 2900 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2901 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | void |
| 2903 | fc_remote_port_rolechg(struct fc_rport *rport, u32 roles) |
| 2904 | { |
| 2905 | struct Scsi_Host *shost = rport_to_shost(rport); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2906 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | unsigned long flags; |
| 2908 | int create = 0; |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 2909 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2912 | if (roles & FC_PORT_ROLE_FCP_TARGET) { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2913 | if (rport->scsi_target_id == -1) { |
| 2914 | rport->scsi_target_id = fc_host->next_target_id++; |
| 2915 | create = 1; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2916 | } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET)) |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2917 | create = 1; |
FUJITA Tomonori | 7525236 | 2007-09-01 02:02:27 +0900 | [diff] [blame] | 2918 | } else if (shost->active_mode & MODE_TARGET) { |
| 2919 | ret = fc_tgt_it_nexus_create(shost, (unsigned long)rport, |
| 2920 | (char *)&rport->node_name); |
| 2921 | if (ret) |
| 2922 | printk(KERN_ERR "FC Remore Port tgt nexus failed %d\n", |
| 2923 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2926 | rport->roles = roles; |
| 2927 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2928 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2929 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2930 | if (create) { |
| 2931 | /* |
| 2932 | * There may have been a delete timer running on the |
| 2933 | * port. Ensure that it is cancelled as we now know |
| 2934 | * the port is an FCP Target. |
| 2935 | * Note: we know the rport is exists and in an online |
| 2936 | * state as the LLDD would not have had an rport |
| 2937 | * reference to pass us. |
| 2938 | * |
| 2939 | * Take no action on the del_timer failure as the state |
| 2940 | * machine state change will validate the |
| 2941 | * transaction. |
| 2942 | */ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 2943 | if (!cancel_delayed_work(&rport->fail_io_work)) |
| 2944 | fc_flush_devloss(shost); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2945 | if (!cancel_delayed_work(&rport->dev_loss_work)) |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2946 | fc_flush_devloss(shost); |
| 2947 | |
| 2948 | spin_lock_irqsave(shost->host_lock, flags); |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 2949 | rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | |
| 2950 | FC_RPORT_DEVLOSS_PENDING); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2951 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2952 | |
| 2953 | /* ensure any stgt delete functions are done */ |
| 2954 | fc_flush_work(shost); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | /* initiate a scan of the target */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2957 | spin_lock_irqsave(shost->host_lock, flags); |
| 2958 | rport->flags |= FC_RPORT_SCAN_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | scsi_queue_work(shost, &rport->scan_work); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2960 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | a0785ed | 2006-05-11 13:27:09 -0400 | [diff] [blame] | 2961 | scsi_target_unblock(&rport->dev); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | } |
| 2964 | EXPORT_SYMBOL(fc_remote_port_rolechg); |
| 2965 | |
| 2966 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2967 | * fc_timeout_deleted_rport - Timeout handler for a deleted remote port. |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2968 | * @work: rport target that failed to reappear in the allotted time. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2969 | * |
| 2970 | * Description: An attempt to delete a remote port blocks, and if it fails |
| 2971 | * to return in the allotted time this gets called. |
| 2972 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2974 | fc_timeout_deleted_rport(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2976 | struct fc_rport *rport = |
| 2977 | container_of(work, struct fc_rport, dev_loss_work.work); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2978 | struct Scsi_Host *shost = rport_to_shost(rport); |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 2979 | struct fc_internal *i = to_fc_internal(shost->transportt); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2980 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2981 | unsigned long flags; |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 2982 | int do_callback = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2984 | spin_lock_irqsave(shost->host_lock, flags); |
| 2985 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2986 | rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; |
| 2987 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2988 | /* |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2989 | * If the port is ONLINE, then it came back. If it was a SCSI |
| 2990 | * target, validate it still is. If not, tear down the |
| 2991 | * scsi_target on it. |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2992 | */ |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2993 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 2994 | (rport->scsi_target_id != -1) && |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 2995 | !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) { |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2996 | dev_printk(KERN_ERR, &rport->dev, |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2997 | "blocked FC remote port time out: no longer" |
| 2998 | " a FCP target, removing starget\n"); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 2999 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | a0785ed | 2006-05-11 13:27:09 -0400 | [diff] [blame] | 3000 | scsi_target_unblock(&rport->dev); |
| 3001 | fc_queue_work(shost, &rport->stgt_delete_work); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3002 | return; |
| 3003 | } |
| 3004 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 3005 | /* NOOP state - we're flushing workq's */ |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3006 | if (rport->port_state != FC_PORTSTATE_BLOCKED) { |
| 3007 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3008 | dev_printk(KERN_ERR, &rport->dev, |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 3009 | "blocked FC remote port time out: leaving" |
| 3010 | " rport%s alone\n", |
| 3011 | (rport->scsi_target_id != -1) ? " and starget" : ""); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3012 | return; |
| 3013 | } |
| 3014 | |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 3015 | if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) || |
| 3016 | (rport->scsi_target_id == -1)) { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3017 | list_del(&rport->peers); |
| 3018 | rport->port_state = FC_PORTSTATE_DELETED; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3019 | dev_printk(KERN_ERR, &rport->dev, |
James Smart | 92740b2 | 2007-04-27 11:53:17 -0400 | [diff] [blame] | 3020 | "blocked FC remote port time out: removing" |
| 3021 | " rport%s\n", |
| 3022 | (rport->scsi_target_id != -1) ? " and starget" : ""); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3023 | fc_queue_work(shost, &rport->rport_delete_work); |
| 3024 | spin_unlock_irqrestore(shost->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3025 | return; |
| 3026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
| 3028 | dev_printk(KERN_ERR, &rport->dev, |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3029 | "blocked FC remote port time out: removing target and " |
| 3030 | "saving binding\n"); |
| 3031 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3032 | list_move_tail(&rport->peers, &fc_host->rport_bindings); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3033 | |
| 3034 | /* |
| 3035 | * Note: We do not remove or clear the hostdata area. This allows |
| 3036 | * host-specific target data to persist along with the |
| 3037 | * scsi_target_id. It's up to the host to manage it's hostdata area. |
| 3038 | */ |
| 3039 | |
| 3040 | /* |
| 3041 | * Reinitialize port attributes that may change if the port comes back. |
| 3042 | */ |
| 3043 | rport->maxframe_size = -1; |
| 3044 | rport->supported_classes = FC_COS_UNSPECIFIED; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3045 | rport->roles = FC_PORT_ROLE_UNKNOWN; |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3046 | rport->port_state = FC_PORTSTATE_NOTPRESENT; |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 3047 | rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3048 | |
James Smart | f78badb | 2008-12-05 16:29:59 -0600 | [diff] [blame] | 3049 | /* |
| 3050 | * Pre-emptively kill I/O rather than waiting for the work queue |
| 3051 | * item to teardown the starget. (FCOE libFC folks prefer this |
| 3052 | * and to have the rport_port_id still set when it's done). |
| 3053 | */ |
| 3054 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3055 | fc_terminate_rport_io(rport); |
| 3056 | |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 3057 | spin_lock_irqsave(shost->host_lock, flags); |
James Smart | f78badb | 2008-12-05 16:29:59 -0600 | [diff] [blame] | 3058 | |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 3059 | if (rport->port_state == FC_PORTSTATE_NOTPRESENT) { /* still missing */ |
| 3060 | |
| 3061 | /* remove the identifiers that aren't used in the consisting binding */ |
| 3062 | switch (fc_host->tgtid_bind_type) { |
| 3063 | case FC_TGTID_BIND_BY_WWPN: |
| 3064 | rport->node_name = -1; |
| 3065 | rport->port_id = -1; |
| 3066 | break; |
| 3067 | case FC_TGTID_BIND_BY_WWNN: |
| 3068 | rport->port_name = -1; |
| 3069 | rport->port_id = -1; |
| 3070 | break; |
| 3071 | case FC_TGTID_BIND_BY_ID: |
| 3072 | rport->node_name = -1; |
| 3073 | rport->port_name = -1; |
| 3074 | break; |
| 3075 | case FC_TGTID_BIND_NONE: /* to keep compiler happy */ |
| 3076 | break; |
| 3077 | } |
| 3078 | |
| 3079 | /* |
| 3080 | * As this only occurs if the remote port (scsi target) |
| 3081 | * went away and didn't come back - we'll remove |
| 3082 | * all attached scsi devices. |
| 3083 | */ |
| 3084 | rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; |
| 3085 | fc_queue_work(shost, &rport->stgt_delete_work); |
| 3086 | |
| 3087 | do_callback = 1; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3088 | } |
| 3089 | |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 3090 | spin_unlock_irqrestore(shost->host_lock, flags); |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 3091 | |
| 3092 | /* |
| 3093 | * Notify the driver that the rport is now dead. The LLDD will |
| 3094 | * also guarantee that any communication to the rport is terminated |
| 3095 | * |
| 3096 | * Note: we set the CALLBK_DONE flag above to correspond |
| 3097 | */ |
Michael Reed | 8798a69 | 2009-10-09 14:15:59 -0500 | [diff] [blame] | 3098 | if (do_callback && i->f->dev_loss_tmo_callbk) |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 3099 | i->f->dev_loss_tmo_callbk(rport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | } |
| 3101 | |
James Smart | 4be98c0 | 2009-01-05 12:14:18 -0500 | [diff] [blame] | 3102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3104 | * fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a disconnected SCSI target. |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3105 | * @work: rport to terminate io on. |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 3106 | * |
| 3107 | * Notes: Only requests the failure of the io, not that all are flushed |
| 3108 | * prior to returning. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3109 | */ |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 3110 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3111 | fc_timeout_fail_rport_io(struct work_struct *work) |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 3112 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3113 | struct fc_rport *rport = |
| 3114 | container_of(work, struct fc_rport, fail_io_work.work); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 3115 | |
| 3116 | if (rport->port_state != FC_PORTSTATE_BLOCKED) |
| 3117 | return; |
| 3118 | |
Mike Christie | fff9d40 | 2008-08-19 18:45:23 -0500 | [diff] [blame] | 3119 | rport->flags |= FC_RPORT_FAST_FAIL_TIMEDOUT; |
| 3120 | fc_terminate_rport_io(rport); |
James Smart | 0f29b96 | 2006-08-18 17:33:29 -0400 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | * fc_scsi_scan_rport - called to perform a scsi scan on a remote port. |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3125 | * @work: remote port to be scanned. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3128 | fc_scsi_scan_rport(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3130 | struct fc_rport *rport = |
| 3131 | container_of(work, struct fc_rport, scan_work); |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3132 | struct Scsi_Host *shost = rport_to_shost(rport); |
Christof Schmitt | 03f002f | 2007-08-28 09:31:21 +0200 | [diff] [blame] | 3133 | struct fc_internal *i = to_fc_internal(shost->transportt); |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 3134 | unsigned long flags; |
| 3135 | |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3136 | if ((rport->port_state == FC_PORTSTATE_ONLINE) && |
Christof Schmitt | 03f002f | 2007-08-28 09:31:21 +0200 | [diff] [blame] | 3137 | (rport->roles & FC_PORT_ROLE_FCP_TARGET) && |
| 3138 | !(i->f->disable_target_scan)) { |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3139 | scsi_scan_target(&rport->dev, rport->channel, |
| 3140 | rport->scsi_target_id, SCAN_WILD_CARD, 1); |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 3141 | } |
James Smart | aedf349 | 2006-04-10 10:14:05 -0400 | [diff] [blame] | 3142 | |
| 3143 | spin_lock_irqsave(shost->host_lock, flags); |
| 3144 | rport->flags &= ~FC_RPORT_SCAN_PENDING; |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 3145 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3146 | } |
| 3147 | |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 3148 | /** |
| 3149 | * fc_block_scsi_eh - Block SCSI eh thread for blocked fc_rport |
| 3150 | * @cmnd: SCSI command that scsi_eh is trying to recover |
| 3151 | * |
| 3152 | * This routine can be called from a FC LLD scsi_eh callback. It |
| 3153 | * blocks the scsi_eh thread until the fc_rport leaves the |
| 3154 | * FC_PORTSTATE_BLOCKED. This is necessary to avoid the scsi_eh |
| 3155 | * failing recovery actions for blocked rports which would lead to |
| 3156 | * offlined SCSI devices. |
| 3157 | */ |
| 3158 | void fc_block_scsi_eh(struct scsi_cmnd *cmnd) |
| 3159 | { |
| 3160 | struct Scsi_Host *shost = cmnd->device->host; |
| 3161 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
| 3162 | unsigned long flags; |
| 3163 | |
| 3164 | spin_lock_irqsave(shost->host_lock, flags); |
| 3165 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { |
| 3166 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3167 | msleep(1000); |
| 3168 | spin_lock_irqsave(shost->host_lock, flags); |
| 3169 | } |
| 3170 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3171 | } |
| 3172 | EXPORT_SYMBOL(fc_block_scsi_eh); |
James.Smart@Emulex.Com | 42e3314 | 2005-12-15 09:56:22 -0500 | [diff] [blame] | 3173 | |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3174 | /** |
Andrew Vasquez | a30c3f6 | 2008-07-18 08:32:52 -0700 | [diff] [blame] | 3175 | * fc_vport_setup - allocates and creates a FC virtual port. |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3176 | * @shost: scsi host the virtual port is connected to. |
| 3177 | * @channel: Channel on shost port connected to. |
| 3178 | * @pdev: parent device for vport |
| 3179 | * @ids: The world wide names, FC4 port roles, etc for |
| 3180 | * the virtual port. |
| 3181 | * @ret_vport: The pointer to the created vport. |
| 3182 | * |
| 3183 | * Allocates and creates the vport structure, calls the parent host |
| 3184 | * to instantiate the vport, the completes w/ class and sysfs creation. |
| 3185 | * |
| 3186 | * Notes: |
| 3187 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3188 | */ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3189 | static int |
Andrew Vasquez | a30c3f6 | 2008-07-18 08:32:52 -0700 | [diff] [blame] | 3190 | fc_vport_setup(struct Scsi_Host *shost, int channel, struct device *pdev, |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3191 | struct fc_vport_identifiers *ids, struct fc_vport **ret_vport) |
| 3192 | { |
| 3193 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
| 3194 | struct fc_internal *fci = to_fc_internal(shost->transportt); |
| 3195 | struct fc_vport *vport; |
| 3196 | struct device *dev; |
| 3197 | unsigned long flags; |
| 3198 | size_t size; |
| 3199 | int error; |
| 3200 | |
| 3201 | *ret_vport = NULL; |
| 3202 | |
| 3203 | if ( ! fci->f->vport_create) |
| 3204 | return -ENOENT; |
| 3205 | |
| 3206 | size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size); |
| 3207 | vport = kzalloc(size, GFP_KERNEL); |
| 3208 | if (unlikely(!vport)) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3209 | printk(KERN_ERR "%s: allocation failure\n", __func__); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3210 | return -ENOMEM; |
| 3211 | } |
| 3212 | |
| 3213 | vport->vport_state = FC_VPORT_UNKNOWN; |
| 3214 | vport->vport_last_state = FC_VPORT_UNKNOWN; |
| 3215 | vport->node_name = ids->node_name; |
| 3216 | vport->port_name = ids->port_name; |
| 3217 | vport->roles = ids->roles; |
| 3218 | vport->vport_type = ids->vport_type; |
| 3219 | if (fci->f->dd_fcvport_size) |
| 3220 | vport->dd_data = &vport[1]; |
| 3221 | vport->shost = shost; |
| 3222 | vport->channel = channel; |
| 3223 | vport->flags = FC_VPORT_CREATING; |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3224 | INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3225 | |
| 3226 | spin_lock_irqsave(shost->host_lock, flags); |
| 3227 | |
| 3228 | if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) { |
| 3229 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3230 | kfree(vport); |
| 3231 | return -ENOSPC; |
| 3232 | } |
| 3233 | fc_host->npiv_vports_inuse++; |
| 3234 | vport->number = fc_host->next_vport_number++; |
| 3235 | list_add_tail(&vport->peers, &fc_host->vports); |
| 3236 | get_device(&shost->shost_gendev); /* for fc_host->vport list */ |
| 3237 | |
| 3238 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3239 | |
| 3240 | dev = &vport->dev; |
| 3241 | device_initialize(dev); /* takes self reference */ |
| 3242 | dev->parent = get_device(pdev); /* takes parent reference */ |
| 3243 | dev->release = fc_vport_dev_release; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3244 | dev_set_name(dev, "vport-%d:%d-%d", |
| 3245 | shost->host_no, channel, vport->number); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3246 | transport_setup_device(dev); |
| 3247 | |
| 3248 | error = device_add(dev); |
| 3249 | if (error) { |
| 3250 | printk(KERN_ERR "FC Virtual Port device_add failed\n"); |
| 3251 | goto delete_vport; |
| 3252 | } |
| 3253 | transport_add_device(dev); |
| 3254 | transport_configure_device(dev); |
| 3255 | |
| 3256 | error = fci->f->vport_create(vport, ids->disable); |
| 3257 | if (error) { |
| 3258 | printk(KERN_ERR "FC Virtual Port LLDD Create failed\n"); |
| 3259 | goto delete_vport_all; |
| 3260 | } |
| 3261 | |
| 3262 | /* |
| 3263 | * if the parent isn't the physical adapter's Scsi_Host, ensure |
| 3264 | * the Scsi_Host at least contains ia symlink to the vport. |
| 3265 | */ |
| 3266 | if (pdev != &shost->shost_gendev) { |
| 3267 | error = sysfs_create_link(&shost->shost_gendev.kobj, |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3268 | &dev->kobj, dev_name(dev)); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3269 | if (error) |
| 3270 | printk(KERN_ERR |
| 3271 | "%s: Cannot create vport symlinks for " |
| 3272 | "%s, err=%d\n", |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3273 | __func__, dev_name(dev), error); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3274 | } |
| 3275 | spin_lock_irqsave(shost->host_lock, flags); |
| 3276 | vport->flags &= ~FC_VPORT_CREATING; |
| 3277 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3278 | |
| 3279 | dev_printk(KERN_NOTICE, pdev, |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3280 | "%s created via shost%d channel %d\n", dev_name(dev), |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3281 | shost->host_no, channel); |
| 3282 | |
| 3283 | *ret_vport = vport; |
| 3284 | |
| 3285 | return 0; |
| 3286 | |
| 3287 | delete_vport_all: |
| 3288 | transport_remove_device(dev); |
| 3289 | device_del(dev); |
| 3290 | delete_vport: |
| 3291 | transport_destroy_device(dev); |
| 3292 | spin_lock_irqsave(shost->host_lock, flags); |
| 3293 | list_del(&vport->peers); |
| 3294 | put_device(&shost->shost_gendev); /* for fc_host->vport list */ |
| 3295 | fc_host->npiv_vports_inuse--; |
| 3296 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3297 | put_device(dev->parent); |
| 3298 | kfree(vport); |
| 3299 | |
| 3300 | return error; |
| 3301 | } |
| 3302 | |
Andrew Vasquez | a30c3f6 | 2008-07-18 08:32:52 -0700 | [diff] [blame] | 3303 | /** |
| 3304 | * fc_vport_create - Admin App or LLDD requests creation of a vport |
| 3305 | * @shost: scsi host the virtual port is connected to. |
| 3306 | * @channel: channel on shost port connected to. |
| 3307 | * @ids: The world wide names, FC4 port roles, etc for |
| 3308 | * the virtual port. |
| 3309 | * |
| 3310 | * Notes: |
| 3311 | * This routine assumes no locks are held on entry. |
| 3312 | */ |
| 3313 | struct fc_vport * |
| 3314 | fc_vport_create(struct Scsi_Host *shost, int channel, |
| 3315 | struct fc_vport_identifiers *ids) |
| 3316 | { |
| 3317 | int stat; |
| 3318 | struct fc_vport *vport; |
| 3319 | |
| 3320 | stat = fc_vport_setup(shost, channel, &shost->shost_gendev, |
| 3321 | ids, &vport); |
| 3322 | return stat ? NULL : vport; |
| 3323 | } |
| 3324 | EXPORT_SYMBOL(fc_vport_create); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3325 | |
| 3326 | /** |
| 3327 | * fc_vport_terminate - Admin App or LLDD requests termination of a vport |
| 3328 | * @vport: fc_vport to be terminated |
| 3329 | * |
| 3330 | * Calls the LLDD vport_delete() function, then deallocates and removes |
| 3331 | * the vport from the shost and object tree. |
| 3332 | * |
| 3333 | * Notes: |
| 3334 | * This routine assumes no locks are held on entry. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3335 | */ |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3336 | int |
| 3337 | fc_vport_terminate(struct fc_vport *vport) |
| 3338 | { |
| 3339 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 3340 | struct fc_host_attrs *fc_host = shost_to_fc_host(shost); |
| 3341 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3342 | struct device *dev = &vport->dev; |
| 3343 | unsigned long flags; |
| 3344 | int stat; |
| 3345 | |
| 3346 | spin_lock_irqsave(shost->host_lock, flags); |
| 3347 | if (vport->flags & FC_VPORT_CREATING) { |
| 3348 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3349 | return -EBUSY; |
| 3350 | } |
| 3351 | if (vport->flags & (FC_VPORT_DEL)) { |
| 3352 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3353 | return -EALREADY; |
| 3354 | } |
| 3355 | vport->flags |= FC_VPORT_DELETING; |
| 3356 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3357 | |
| 3358 | if (i->f->vport_delete) |
| 3359 | stat = i->f->vport_delete(vport); |
| 3360 | else |
| 3361 | stat = -ENOENT; |
| 3362 | |
| 3363 | spin_lock_irqsave(shost->host_lock, flags); |
| 3364 | vport->flags &= ~FC_VPORT_DELETING; |
| 3365 | if (!stat) { |
| 3366 | vport->flags |= FC_VPORT_DELETED; |
| 3367 | list_del(&vport->peers); |
| 3368 | fc_host->npiv_vports_inuse--; |
| 3369 | put_device(&shost->shost_gendev); /* for fc_host->vport list */ |
| 3370 | } |
| 3371 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 3372 | |
| 3373 | if (stat) |
| 3374 | return stat; |
| 3375 | |
| 3376 | if (dev->parent != &shost->shost_gendev) |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3377 | sysfs_remove_link(&shost->shost_gendev.kobj, dev_name(dev)); |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3378 | transport_remove_device(dev); |
| 3379 | device_del(dev); |
| 3380 | transport_destroy_device(dev); |
| 3381 | |
| 3382 | /* |
| 3383 | * Removing our self-reference should mean our |
| 3384 | * release function gets called, which will drop the remaining |
| 3385 | * parent reference and free the data structure. |
| 3386 | */ |
| 3387 | put_device(dev); /* for self-reference */ |
| 3388 | |
| 3389 | return 0; /* SUCCESS */ |
| 3390 | } |
| 3391 | EXPORT_SYMBOL(fc_vport_terminate); |
| 3392 | |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3393 | /** |
| 3394 | * fc_vport_sched_delete - workq-based delete request for a vport |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3395 | * @work: vport to be deleted. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 3396 | */ |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3397 | static void |
| 3398 | fc_vport_sched_delete(struct work_struct *work) |
| 3399 | { |
| 3400 | struct fc_vport *vport = |
| 3401 | container_of(work, struct fc_vport, vport_delete_work); |
| 3402 | int stat; |
James Smart | a53eb5e | 2007-04-27 12:41:09 -0400 | [diff] [blame] | 3403 | |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3404 | stat = fc_vport_terminate(vport); |
| 3405 | if (stat) |
| 3406 | dev_printk(KERN_ERR, vport->dev.parent, |
| 3407 | "%s: %s could not be deleted created via " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3408 | "shost%d channel %d - error %d\n", __func__, |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 3409 | dev_name(&vport->dev), vport->shost->host_no, |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 3410 | vport->channel, stat); |
| 3411 | } |
| 3412 | |
| 3413 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3414 | /* |
| 3415 | * BSG support |
| 3416 | */ |
| 3417 | |
| 3418 | |
| 3419 | /** |
| 3420 | * fc_destroy_bsgjob - routine to teardown/delete a fc bsg job |
| 3421 | * @job: fc_bsg_job that is to be torn down |
| 3422 | */ |
| 3423 | static void |
| 3424 | fc_destroy_bsgjob(struct fc_bsg_job *job) |
| 3425 | { |
| 3426 | unsigned long flags; |
| 3427 | |
| 3428 | spin_lock_irqsave(&job->job_lock, flags); |
| 3429 | if (job->ref_cnt) { |
| 3430 | spin_unlock_irqrestore(&job->job_lock, flags); |
| 3431 | return; |
| 3432 | } |
| 3433 | spin_unlock_irqrestore(&job->job_lock, flags); |
| 3434 | |
| 3435 | put_device(job->dev); /* release reference for the request */ |
| 3436 | |
| 3437 | kfree(job->request_payload.sg_list); |
| 3438 | kfree(job->reply_payload.sg_list); |
| 3439 | kfree(job); |
| 3440 | } |
| 3441 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3442 | /** |
| 3443 | * fc_bsg_jobdone - completion routine for bsg requests that the LLD has |
| 3444 | * completed |
| 3445 | * @job: fc_bsg_job that is complete |
| 3446 | */ |
| 3447 | static void |
| 3448 | fc_bsg_jobdone(struct fc_bsg_job *job) |
| 3449 | { |
| 3450 | struct request *req = job->req; |
| 3451 | struct request *rsp = req->next_rq; |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3452 | int err; |
| 3453 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3454 | err = job->req->errors = job->reply->result; |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3455 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3456 | if (err < 0) |
| 3457 | /* we're only returning the result field in the reply */ |
| 3458 | job->req->sense_len = sizeof(uint32_t); |
| 3459 | else |
| 3460 | job->req->sense_len = job->reply_len; |
| 3461 | |
| 3462 | /* we assume all request payload was transferred, residual == 0 */ |
| 3463 | req->resid_len = 0; |
| 3464 | |
| 3465 | if (rsp) { |
| 3466 | WARN_ON(job->reply->reply_payload_rcv_len > rsp->resid_len); |
| 3467 | |
| 3468 | /* set reply (bidi) residual */ |
| 3469 | rsp->resid_len -= min(job->reply->reply_payload_rcv_len, |
| 3470 | rsp->resid_len); |
| 3471 | } |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3472 | blk_complete_request(req); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3473 | } |
| 3474 | |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3475 | /** |
| 3476 | * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests |
Randy Dunlap | fe5d20c | 2009-07-04 13:10:41 -0700 | [diff] [blame] | 3477 | * @rq: BSG request that holds the job to be destroyed |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3478 | */ |
| 3479 | static void fc_bsg_softirq_done(struct request *rq) |
| 3480 | { |
| 3481 | struct fc_bsg_job *job = rq->special; |
| 3482 | unsigned long flags; |
| 3483 | |
| 3484 | spin_lock_irqsave(&job->job_lock, flags); |
| 3485 | job->state_flags |= FC_RQST_STATE_DONE; |
| 3486 | job->ref_cnt--; |
| 3487 | spin_unlock_irqrestore(&job->job_lock, flags); |
| 3488 | |
| 3489 | blk_end_request_all(rq, rq->errors); |
| 3490 | fc_destroy_bsgjob(job); |
| 3491 | } |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3492 | |
| 3493 | /** |
| 3494 | * fc_bsg_job_timeout - handler for when a bsg request timesout |
| 3495 | * @req: request that timed out |
| 3496 | */ |
| 3497 | static enum blk_eh_timer_return |
| 3498 | fc_bsg_job_timeout(struct request *req) |
| 3499 | { |
| 3500 | struct fc_bsg_job *job = (void *) req->special; |
| 3501 | struct Scsi_Host *shost = job->shost; |
| 3502 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3503 | unsigned long flags; |
| 3504 | int err = 0, done = 0; |
| 3505 | |
| 3506 | if (job->rport && job->rport->port_state == FC_PORTSTATE_BLOCKED) |
| 3507 | return BLK_EH_RESET_TIMER; |
| 3508 | |
| 3509 | spin_lock_irqsave(&job->job_lock, flags); |
| 3510 | if (job->state_flags & FC_RQST_STATE_DONE) |
| 3511 | done = 1; |
| 3512 | else |
| 3513 | job->ref_cnt++; |
| 3514 | spin_unlock_irqrestore(&job->job_lock, flags); |
| 3515 | |
| 3516 | if (!done && i->f->bsg_timeout) { |
| 3517 | /* call LLDD to abort the i/o as it has timed out */ |
| 3518 | err = i->f->bsg_timeout(job); |
| 3519 | if (err) |
| 3520 | printk(KERN_ERR "ERROR: FC BSG request timeout - LLD " |
| 3521 | "abort failed with status %d\n", err); |
| 3522 | } |
| 3523 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3524 | /* the blk_end_sync_io() doesn't check the error */ |
Giridhar Malavali | 47e7e89 | 2009-06-19 16:26:54 -0700 | [diff] [blame] | 3525 | if (done) |
| 3526 | return BLK_EH_NOT_HANDLED; |
| 3527 | else |
| 3528 | return BLK_EH_HANDLED; |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3529 | } |
| 3530 | |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3531 | static int |
| 3532 | fc_bsg_map_buffer(struct fc_bsg_buffer *buf, struct request *req) |
| 3533 | { |
| 3534 | size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments); |
| 3535 | |
| 3536 | BUG_ON(!req->nr_phys_segments); |
| 3537 | |
| 3538 | buf->sg_list = kzalloc(sz, GFP_KERNEL); |
| 3539 | if (!buf->sg_list) |
| 3540 | return -ENOMEM; |
| 3541 | sg_init_table(buf->sg_list, req->nr_phys_segments); |
| 3542 | buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list); |
| 3543 | buf->payload_len = blk_rq_bytes(req); |
| 3544 | return 0; |
| 3545 | } |
| 3546 | |
| 3547 | |
| 3548 | /** |
| 3549 | * fc_req_to_bsgjob - Allocate/create the fc_bsg_job structure for the |
| 3550 | * bsg request |
| 3551 | * @shost: SCSI Host corresponding to the bsg object |
| 3552 | * @rport: (optional) FC Remote Port corresponding to the bsg object |
| 3553 | * @req: BSG request that needs a job structure |
| 3554 | */ |
| 3555 | static int |
| 3556 | fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport *rport, |
| 3557 | struct request *req) |
| 3558 | { |
| 3559 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3560 | struct request *rsp = req->next_rq; |
| 3561 | struct fc_bsg_job *job; |
| 3562 | int ret; |
| 3563 | |
| 3564 | BUG_ON(req->special); |
| 3565 | |
| 3566 | job = kzalloc(sizeof(struct fc_bsg_job) + i->f->dd_bsg_size, |
| 3567 | GFP_KERNEL); |
| 3568 | if (!job) |
| 3569 | return -ENOMEM; |
| 3570 | |
| 3571 | /* |
| 3572 | * Note: this is a bit silly. |
| 3573 | * The request gets formatted as a SGIO v4 ioctl request, which |
| 3574 | * then gets reformatted as a blk request, which then gets |
| 3575 | * reformatted as a fc bsg request. And on completion, we have |
| 3576 | * to wrap return results such that SGIO v4 thinks it was a scsi |
| 3577 | * status. I hope this was all worth it. |
| 3578 | */ |
| 3579 | |
| 3580 | req->special = job; |
| 3581 | job->shost = shost; |
| 3582 | job->rport = rport; |
| 3583 | job->req = req; |
| 3584 | if (i->f->dd_bsg_size) |
| 3585 | job->dd_data = (void *)&job[1]; |
| 3586 | spin_lock_init(&job->job_lock); |
| 3587 | job->request = (struct fc_bsg_request *)req->cmd; |
| 3588 | job->request_len = req->cmd_len; |
| 3589 | job->reply = req->sense; |
| 3590 | job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer |
| 3591 | * allocated */ |
| 3592 | if (req->bio) { |
| 3593 | ret = fc_bsg_map_buffer(&job->request_payload, req); |
| 3594 | if (ret) |
| 3595 | goto failjob_rls_job; |
| 3596 | } |
| 3597 | if (rsp && rsp->bio) { |
| 3598 | ret = fc_bsg_map_buffer(&job->reply_payload, rsp); |
| 3599 | if (ret) |
| 3600 | goto failjob_rls_rqst_payload; |
| 3601 | } |
| 3602 | job->job_done = fc_bsg_jobdone; |
| 3603 | if (rport) |
| 3604 | job->dev = &rport->dev; |
| 3605 | else |
| 3606 | job->dev = &shost->shost_gendev; |
| 3607 | get_device(job->dev); /* take a reference for the request */ |
| 3608 | |
| 3609 | job->ref_cnt = 1; |
| 3610 | |
| 3611 | return 0; |
| 3612 | |
| 3613 | |
| 3614 | failjob_rls_rqst_payload: |
| 3615 | kfree(job->request_payload.sg_list); |
| 3616 | failjob_rls_job: |
| 3617 | kfree(job); |
| 3618 | return -ENOMEM; |
| 3619 | } |
| 3620 | |
| 3621 | |
| 3622 | enum fc_dispatch_result { |
| 3623 | FC_DISPATCH_BREAK, /* on return, q is locked, break from q loop */ |
| 3624 | FC_DISPATCH_LOCKED, /* on return, q is locked, continue on */ |
| 3625 | FC_DISPATCH_UNLOCKED, /* on return, q is unlocked, continue on */ |
| 3626 | }; |
| 3627 | |
| 3628 | |
| 3629 | /** |
| 3630 | * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD |
Randy Dunlap | 5415907 | 2009-06-18 19:39:57 -0700 | [diff] [blame] | 3631 | * @q: fc host request queue |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3632 | * @shost: scsi host rport attached to |
| 3633 | * @job: bsg job to be processed |
| 3634 | */ |
| 3635 | static enum fc_dispatch_result |
| 3636 | fc_bsg_host_dispatch(struct request_queue *q, struct Scsi_Host *shost, |
| 3637 | struct fc_bsg_job *job) |
| 3638 | { |
| 3639 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3640 | int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ |
| 3641 | int ret; |
| 3642 | |
| 3643 | /* Validate the host command */ |
| 3644 | switch (job->request->msgcode) { |
| 3645 | case FC_BSG_HST_ADD_RPORT: |
| 3646 | cmdlen += sizeof(struct fc_bsg_host_add_rport); |
| 3647 | break; |
| 3648 | |
| 3649 | case FC_BSG_HST_DEL_RPORT: |
| 3650 | cmdlen += sizeof(struct fc_bsg_host_del_rport); |
| 3651 | break; |
| 3652 | |
| 3653 | case FC_BSG_HST_ELS_NOLOGIN: |
| 3654 | cmdlen += sizeof(struct fc_bsg_host_els); |
| 3655 | /* there better be a xmt and rcv payloads */ |
| 3656 | if ((!job->request_payload.payload_len) || |
| 3657 | (!job->reply_payload.payload_len)) { |
| 3658 | ret = -EINVAL; |
| 3659 | goto fail_host_msg; |
| 3660 | } |
| 3661 | break; |
| 3662 | |
| 3663 | case FC_BSG_HST_CT: |
| 3664 | cmdlen += sizeof(struct fc_bsg_host_ct); |
| 3665 | /* there better be xmt and rcv payloads */ |
| 3666 | if ((!job->request_payload.payload_len) || |
| 3667 | (!job->reply_payload.payload_len)) { |
| 3668 | ret = -EINVAL; |
| 3669 | goto fail_host_msg; |
| 3670 | } |
| 3671 | break; |
| 3672 | |
| 3673 | case FC_BSG_HST_VENDOR: |
| 3674 | cmdlen += sizeof(struct fc_bsg_host_vendor); |
| 3675 | if ((shost->hostt->vendor_id == 0L) || |
| 3676 | (job->request->rqst_data.h_vendor.vendor_id != |
| 3677 | shost->hostt->vendor_id)) { |
| 3678 | ret = -ESRCH; |
| 3679 | goto fail_host_msg; |
| 3680 | } |
| 3681 | break; |
| 3682 | |
| 3683 | default: |
| 3684 | ret = -EBADR; |
| 3685 | goto fail_host_msg; |
| 3686 | } |
| 3687 | |
| 3688 | /* check if we really have all the request data needed */ |
| 3689 | if (job->request_len < cmdlen) { |
| 3690 | ret = -ENOMSG; |
| 3691 | goto fail_host_msg; |
| 3692 | } |
| 3693 | |
| 3694 | ret = i->f->bsg_request(job); |
| 3695 | if (!ret) |
| 3696 | return FC_DISPATCH_UNLOCKED; |
| 3697 | |
| 3698 | fail_host_msg: |
| 3699 | /* return the errno failure code as the only status */ |
| 3700 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 3701 | job->reply->result = ret; |
| 3702 | job->reply_len = sizeof(uint32_t); |
| 3703 | fc_bsg_jobdone(job); |
| 3704 | return FC_DISPATCH_UNLOCKED; |
| 3705 | } |
| 3706 | |
| 3707 | |
| 3708 | /* |
| 3709 | * fc_bsg_goose_queue - restart rport queue in case it was stopped |
| 3710 | * @rport: rport to be restarted |
| 3711 | */ |
| 3712 | static void |
| 3713 | fc_bsg_goose_queue(struct fc_rport *rport) |
| 3714 | { |
| 3715 | int flagset; |
Christof Schmitt | 39562e7 | 2009-06-26 16:30:43 +0200 | [diff] [blame] | 3716 | unsigned long flags; |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3717 | |
| 3718 | if (!rport->rqst_q) |
| 3719 | return; |
| 3720 | |
| 3721 | get_device(&rport->dev); |
| 3722 | |
Christof Schmitt | 39562e7 | 2009-06-26 16:30:43 +0200 | [diff] [blame] | 3723 | spin_lock_irqsave(rport->rqst_q->queue_lock, flags); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3724 | flagset = test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags) && |
| 3725 | !test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags); |
| 3726 | if (flagset) |
| 3727 | queue_flag_set(QUEUE_FLAG_REENTER, rport->rqst_q); |
| 3728 | __blk_run_queue(rport->rqst_q); |
| 3729 | if (flagset) |
| 3730 | queue_flag_clear(QUEUE_FLAG_REENTER, rport->rqst_q); |
Christof Schmitt | 39562e7 | 2009-06-26 16:30:43 +0200 | [diff] [blame] | 3731 | spin_unlock_irqrestore(rport->rqst_q->queue_lock, flags); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3732 | |
| 3733 | put_device(&rport->dev); |
| 3734 | } |
| 3735 | |
| 3736 | |
| 3737 | /** |
| 3738 | * fc_bsg_rport_dispatch - process rport bsg requests and dispatch to LLDD |
Randy Dunlap | 5415907 | 2009-06-18 19:39:57 -0700 | [diff] [blame] | 3739 | * @q: rport request queue |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3740 | * @shost: scsi host rport attached to |
| 3741 | * @rport: rport request destined to |
| 3742 | * @job: bsg job to be processed |
| 3743 | */ |
| 3744 | static enum fc_dispatch_result |
| 3745 | fc_bsg_rport_dispatch(struct request_queue *q, struct Scsi_Host *shost, |
| 3746 | struct fc_rport *rport, struct fc_bsg_job *job) |
| 3747 | { |
| 3748 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3749 | int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ |
| 3750 | int ret; |
| 3751 | |
| 3752 | /* Validate the rport command */ |
| 3753 | switch (job->request->msgcode) { |
| 3754 | case FC_BSG_RPT_ELS: |
| 3755 | cmdlen += sizeof(struct fc_bsg_rport_els); |
| 3756 | goto check_bidi; |
| 3757 | |
| 3758 | case FC_BSG_RPT_CT: |
| 3759 | cmdlen += sizeof(struct fc_bsg_rport_ct); |
| 3760 | check_bidi: |
| 3761 | /* there better be xmt and rcv payloads */ |
| 3762 | if ((!job->request_payload.payload_len) || |
| 3763 | (!job->reply_payload.payload_len)) { |
| 3764 | ret = -EINVAL; |
| 3765 | goto fail_rport_msg; |
| 3766 | } |
| 3767 | break; |
| 3768 | default: |
| 3769 | ret = -EBADR; |
| 3770 | goto fail_rport_msg; |
| 3771 | } |
| 3772 | |
| 3773 | /* check if we really have all the request data needed */ |
| 3774 | if (job->request_len < cmdlen) { |
| 3775 | ret = -ENOMSG; |
| 3776 | goto fail_rport_msg; |
| 3777 | } |
| 3778 | |
| 3779 | ret = i->f->bsg_request(job); |
| 3780 | if (!ret) |
| 3781 | return FC_DISPATCH_UNLOCKED; |
| 3782 | |
| 3783 | fail_rport_msg: |
| 3784 | /* return the errno failure code as the only status */ |
| 3785 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 3786 | job->reply->result = ret; |
| 3787 | job->reply_len = sizeof(uint32_t); |
| 3788 | fc_bsg_jobdone(job); |
| 3789 | return FC_DISPATCH_UNLOCKED; |
| 3790 | } |
| 3791 | |
| 3792 | |
| 3793 | /** |
| 3794 | * fc_bsg_request_handler - generic handler for bsg requests |
| 3795 | * @q: request queue to manage |
| 3796 | * @shost: Scsi_Host related to the bsg object |
| 3797 | * @rport: FC remote port related to the bsg object (optional) |
| 3798 | * @dev: device structure for bsg object |
| 3799 | */ |
| 3800 | static void |
| 3801 | fc_bsg_request_handler(struct request_queue *q, struct Scsi_Host *shost, |
| 3802 | struct fc_rport *rport, struct device *dev) |
| 3803 | { |
| 3804 | struct request *req; |
| 3805 | struct fc_bsg_job *job; |
| 3806 | enum fc_dispatch_result ret; |
| 3807 | |
| 3808 | if (!get_device(dev)) |
| 3809 | return; |
| 3810 | |
| 3811 | while (!blk_queue_plugged(q)) { |
| 3812 | if (rport && (rport->port_state == FC_PORTSTATE_BLOCKED)) |
| 3813 | break; |
| 3814 | |
| 3815 | req = blk_fetch_request(q); |
| 3816 | if (!req) |
| 3817 | break; |
| 3818 | |
| 3819 | if (rport && (rport->port_state != FC_PORTSTATE_ONLINE)) { |
| 3820 | req->errors = -ENXIO; |
| 3821 | spin_unlock_irq(q->queue_lock); |
| 3822 | blk_end_request(req, -ENXIO, blk_rq_bytes(req)); |
| 3823 | spin_lock_irq(q->queue_lock); |
| 3824 | continue; |
| 3825 | } |
| 3826 | |
| 3827 | spin_unlock_irq(q->queue_lock); |
| 3828 | |
| 3829 | ret = fc_req_to_bsgjob(shost, rport, req); |
| 3830 | if (ret) { |
| 3831 | req->errors = ret; |
| 3832 | blk_end_request(req, ret, blk_rq_bytes(req)); |
| 3833 | spin_lock_irq(q->queue_lock); |
| 3834 | continue; |
| 3835 | } |
| 3836 | |
| 3837 | job = req->special; |
| 3838 | |
| 3839 | /* check if we have the msgcode value at least */ |
| 3840 | if (job->request_len < sizeof(uint32_t)) { |
| 3841 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 3842 | job->reply->result = -ENOMSG; |
| 3843 | job->reply_len = sizeof(uint32_t); |
| 3844 | fc_bsg_jobdone(job); |
| 3845 | spin_lock_irq(q->queue_lock); |
| 3846 | continue; |
| 3847 | } |
| 3848 | |
| 3849 | /* the dispatch routines will unlock the queue_lock */ |
| 3850 | if (rport) |
| 3851 | ret = fc_bsg_rport_dispatch(q, shost, rport, job); |
| 3852 | else |
| 3853 | ret = fc_bsg_host_dispatch(q, shost, job); |
| 3854 | |
| 3855 | /* did dispatcher hit state that can't process any more */ |
| 3856 | if (ret == FC_DISPATCH_BREAK) |
| 3857 | break; |
| 3858 | |
| 3859 | /* did dispatcher had released the lock */ |
| 3860 | if (ret == FC_DISPATCH_UNLOCKED) |
| 3861 | spin_lock_irq(q->queue_lock); |
| 3862 | } |
| 3863 | |
| 3864 | spin_unlock_irq(q->queue_lock); |
| 3865 | put_device(dev); |
| 3866 | spin_lock_irq(q->queue_lock); |
| 3867 | } |
| 3868 | |
| 3869 | |
| 3870 | /** |
| 3871 | * fc_bsg_host_handler - handler for bsg requests for a fc host |
| 3872 | * @q: fc host request queue |
| 3873 | */ |
| 3874 | static void |
| 3875 | fc_bsg_host_handler(struct request_queue *q) |
| 3876 | { |
| 3877 | struct Scsi_Host *shost = q->queuedata; |
| 3878 | |
| 3879 | fc_bsg_request_handler(q, shost, NULL, &shost->shost_gendev); |
| 3880 | } |
| 3881 | |
| 3882 | |
| 3883 | /** |
| 3884 | * fc_bsg_rport_handler - handler for bsg requests for a fc rport |
| 3885 | * @q: rport request queue |
| 3886 | */ |
| 3887 | static void |
| 3888 | fc_bsg_rport_handler(struct request_queue *q) |
| 3889 | { |
| 3890 | struct fc_rport *rport = q->queuedata; |
| 3891 | struct Scsi_Host *shost = rport_to_shost(rport); |
| 3892 | |
| 3893 | fc_bsg_request_handler(q, shost, rport, &rport->dev); |
| 3894 | } |
| 3895 | |
| 3896 | |
| 3897 | /** |
| 3898 | * fc_bsg_hostadd - Create and add the bsg hooks so we can receive requests |
| 3899 | * @shost: shost for fc_host |
| 3900 | * @fc_host: fc_host adding the structures to |
| 3901 | */ |
| 3902 | static int |
| 3903 | fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host) |
| 3904 | { |
| 3905 | struct device *dev = &shost->shost_gendev; |
| 3906 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3907 | struct request_queue *q; |
| 3908 | int err; |
James Bottomley | 3c559ea | 2009-06-21 12:11:43 -0500 | [diff] [blame] | 3909 | char bsg_name[20]; |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3910 | |
| 3911 | fc_host->rqst_q = NULL; |
| 3912 | |
| 3913 | if (!i->f->bsg_request) |
| 3914 | return -ENOTSUPP; |
| 3915 | |
| 3916 | snprintf(bsg_name, sizeof(bsg_name), |
| 3917 | "fc_host%d", shost->host_no); |
| 3918 | |
| 3919 | q = __scsi_alloc_queue(shost, fc_bsg_host_handler); |
| 3920 | if (!q) { |
| 3921 | printk(KERN_ERR "fc_host%d: bsg interface failed to " |
| 3922 | "initialize - no request queue\n", |
| 3923 | shost->host_no); |
| 3924 | return -ENOMEM; |
| 3925 | } |
| 3926 | |
| 3927 | q->queuedata = shost; |
| 3928 | queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3929 | blk_queue_softirq_done(q, fc_bsg_softirq_done); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3930 | blk_queue_rq_timed_out(q, fc_bsg_job_timeout); |
| 3931 | blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT); |
| 3932 | |
| 3933 | err = bsg_register_queue(q, dev, bsg_name, NULL); |
| 3934 | if (err) { |
| 3935 | printk(KERN_ERR "fc_host%d: bsg interface failed to " |
| 3936 | "initialize - register queue\n", |
| 3937 | shost->host_no); |
| 3938 | blk_cleanup_queue(q); |
| 3939 | return err; |
| 3940 | } |
| 3941 | |
| 3942 | fc_host->rqst_q = q; |
| 3943 | return 0; |
| 3944 | } |
| 3945 | |
| 3946 | |
| 3947 | /** |
| 3948 | * fc_bsg_rportadd - Create and add the bsg hooks so we can receive requests |
| 3949 | * @shost: shost that rport is attached to |
| 3950 | * @rport: rport that the bsg hooks are being attached to |
| 3951 | */ |
| 3952 | static int |
| 3953 | fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport) |
| 3954 | { |
| 3955 | struct device *dev = &rport->dev; |
| 3956 | struct fc_internal *i = to_fc_internal(shost->transportt); |
| 3957 | struct request_queue *q; |
| 3958 | int err; |
| 3959 | |
| 3960 | rport->rqst_q = NULL; |
| 3961 | |
| 3962 | if (!i->f->bsg_request) |
| 3963 | return -ENOTSUPP; |
| 3964 | |
| 3965 | q = __scsi_alloc_queue(shost, fc_bsg_rport_handler); |
| 3966 | if (!q) { |
| 3967 | printk(KERN_ERR "%s: bsg interface failed to " |
| 3968 | "initialize - no request queue\n", |
| 3969 | dev->kobj.name); |
| 3970 | return -ENOMEM; |
| 3971 | } |
| 3972 | |
| 3973 | q->queuedata = rport; |
| 3974 | queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); |
Giridhar Malavali | b5c6f77 | 2009-06-19 16:26:53 -0700 | [diff] [blame] | 3975 | blk_queue_softirq_done(q, fc_bsg_softirq_done); |
James Smart | 9e4f5e2 | 2009-03-26 13:33:19 -0400 | [diff] [blame] | 3976 | blk_queue_rq_timed_out(q, fc_bsg_job_timeout); |
| 3977 | blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT); |
| 3978 | |
| 3979 | err = bsg_register_queue(q, dev, NULL, NULL); |
| 3980 | if (err) { |
| 3981 | printk(KERN_ERR "%s: bsg interface failed to " |
| 3982 | "initialize - register queue\n", |
| 3983 | dev->kobj.name); |
| 3984 | blk_cleanup_queue(q); |
| 3985 | return err; |
| 3986 | } |
| 3987 | |
| 3988 | rport->rqst_q = q; |
| 3989 | return 0; |
| 3990 | } |
| 3991 | |
| 3992 | |
| 3993 | /** |
| 3994 | * fc_bsg_remove - Deletes the bsg hooks on fchosts/rports |
| 3995 | * @q: the request_queue that is to be torn down. |
| 3996 | */ |
| 3997 | static void |
| 3998 | fc_bsg_remove(struct request_queue *q) |
| 3999 | { |
| 4000 | if (q) { |
| 4001 | bsg_unregister_queue(q); |
| 4002 | blk_cleanup_queue(q); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | |
James Smart | 9ef3e4a | 2007-05-24 19:04:44 -0400 | [diff] [blame] | 4007 | /* Original Author: Martin Hicks */ |
| 4008 | MODULE_AUTHOR("James Smart"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | MODULE_DESCRIPTION("FC Transport Attributes"); |
| 4010 | MODULE_LICENSE("GPL"); |
| 4011 | |
| 4012 | module_init(fc_transport_init); |
| 4013 | module_exit(fc_transport_exit); |