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