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