1 /* 2 * FiberChannel transport specific attributes exported to sysfs. 3 * 4 * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 * ======== 21 * 22 * Copyright (C) 2004-2007 James Smart, Emulex Corporation 23 * Rewrite for host, target, device, and remote port attributes, 24 * statistics, and service functions... 25 * 26 */ 27 #ifndef SCSI_TRANSPORT_FC_H 28 #define SCSI_TRANSPORT_FC_H 29 30 #include <linux/sched.h> 31 #include <linux/bsg-lib.h> 32 #include <asm/unaligned.h> 33 #include <scsi/scsi.h> 34 #include <scsi/scsi_netlink.h> 35 #include <scsi/scsi_host.h> 36 37 struct scsi_transport_template; 38 39 /* 40 * FC Port definitions - Following FC HBAAPI guidelines 41 * 42 * Note: Not all binary values for the different fields match HBAAPI. 43 * Instead, we use densely packed ordinal values or enums. 44 * We get away with this as we never present the actual binary values 45 * externally. For sysfs, we always present the string that describes 46 * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring 47 * to understand the values. The HBAAPI user-space library is free to 48 * convert the strings into the HBAAPI-specified binary values. 49 * 50 * Note: Not all HBAAPI-defined values are contained in the definitions 51 * below. Those not appropriate to an fc_host (e.g. FCP initiator) have 52 * been removed. 53 */ 54 55 /* 56 * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c 57 * (for the ascii descriptions). 58 */ 59 enum fc_port_type { 60 FC_PORTTYPE_UNKNOWN, 61 FC_PORTTYPE_OTHER, 62 FC_PORTTYPE_NOTPRESENT, 63 FC_PORTTYPE_NPORT, /* Attached to FPort */ 64 FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */ 65 FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */ 66 FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */ 67 FC_PORTTYPE_NPIV, /* VPORT based on NPIV */ 68 }; 69 70 71 /* 72 * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c 73 * (for the ascii descriptions). 74 */ 75 enum fc_port_state { 76 FC_PORTSTATE_UNKNOWN, 77 FC_PORTSTATE_NOTPRESENT, 78 FC_PORTSTATE_ONLINE, 79 FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */ 80 FC_PORTSTATE_BLOCKED, 81 FC_PORTSTATE_BYPASSED, 82 FC_PORTSTATE_DIAGNOSTICS, 83 FC_PORTSTATE_LINKDOWN, 84 FC_PORTSTATE_ERROR, 85 FC_PORTSTATE_LOOPBACK, 86 FC_PORTSTATE_DELETED, 87 }; 88 89 90 /* 91 * fc_vport_state: If you alter this, you also need to alter 92 * scsi_transport_fc.c (for the ascii descriptions). 93 */ 94 enum fc_vport_state { 95 FC_VPORT_UNKNOWN, 96 FC_VPORT_ACTIVE, 97 FC_VPORT_DISABLED, 98 FC_VPORT_LINKDOWN, 99 FC_VPORT_INITIALIZING, 100 FC_VPORT_NO_FABRIC_SUPP, 101 FC_VPORT_NO_FABRIC_RSCS, 102 FC_VPORT_FABRIC_LOGOUT, 103 FC_VPORT_FABRIC_REJ_WWN, 104 FC_VPORT_FAILED, 105 }; 106 107 108 109 /* 110 * FC Classes of Service 111 * Note: values are not enumerated, as they can be "or'd" together 112 * for reporting (e.g. report supported_classes). If you alter this list, 113 * you also need to alter scsi_transport_fc.c (for the ascii descriptions). 114 */ 115 #define FC_COS_UNSPECIFIED 0 116 #define FC_COS_CLASS1 2 117 #define FC_COS_CLASS2 4 118 #define FC_COS_CLASS3 8 119 #define FC_COS_CLASS4 0x10 120 #define FC_COS_CLASS6 0x40 121 122 /* 123 * FC Port Speeds 124 * Note: values are not enumerated, as they can be "or'd" together 125 * for reporting (e.g. report supported_speeds). If you alter this list, 126 * you also need to alter scsi_transport_fc.c (for the ascii descriptions). 127 */ 128 #define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver 129 incapable of reporting */ 130 #define FC_PORTSPEED_1GBIT 1 131 #define FC_PORTSPEED_2GBIT 2 132 #define FC_PORTSPEED_10GBIT 4 133 #define FC_PORTSPEED_4GBIT 8 134 #define FC_PORTSPEED_8GBIT 0x10 135 #define FC_PORTSPEED_16GBIT 0x20 136 #define FC_PORTSPEED_32GBIT 0x40 137 #define FC_PORTSPEED_20GBIT 0x80 138 #define FC_PORTSPEED_40GBIT 0x100 139 #define FC_PORTSPEED_50GBIT 0x200 140 #define FC_PORTSPEED_100GBIT 0x400 141 #define FC_PORTSPEED_25GBIT 0x800 142 #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */ 143 144 /* 145 * fc_tgtid_binding_type: If you alter this, you also need to alter 146 * scsi_transport_fc.c (for the ascii descriptions). 147 */ 148 enum fc_tgtid_binding_type { 149 FC_TGTID_BIND_NONE, 150 FC_TGTID_BIND_BY_WWPN, 151 FC_TGTID_BIND_BY_WWNN, 152 FC_TGTID_BIND_BY_ID, 153 }; 154 155 /* 156 * FC Port Roles 157 * Note: values are not enumerated, as they can be "or'd" together 158 * for reporting (e.g. report roles). If you alter this list, 159 * you also need to alter scsi_transport_fc.c (for the ascii descriptions). 160 */ 161 #define FC_PORT_ROLE_UNKNOWN 0x00 162 #define FC_PORT_ROLE_FCP_TARGET 0x01 163 #define FC_PORT_ROLE_FCP_INITIATOR 0x02 164 #define FC_PORT_ROLE_IP_PORT 0x04 165 #define FC_PORT_ROLE_FCP_DUMMY_INITIATOR 0x08 166 167 /* The following are for compatibility */ 168 #define FC_RPORT_ROLE_UNKNOWN FC_PORT_ROLE_UNKNOWN 169 #define FC_RPORT_ROLE_FCP_TARGET FC_PORT_ROLE_FCP_TARGET 170 #define FC_RPORT_ROLE_FCP_INITIATOR FC_PORT_ROLE_FCP_INITIATOR 171 #define FC_RPORT_ROLE_IP_PORT FC_PORT_ROLE_IP_PORT 172 173 174 /* Macro for use in defining Virtual Port attributes */ 175 #define FC_VPORT_ATTR(_name,_mode,_show,_store) \ 176 struct device_attribute dev_attr_vport_##_name = \ 177 __ATTR(_name,_mode,_show,_store) 178 179 /* 180 * fc_vport_identifiers: This set of data contains all elements 181 * to uniquely identify and instantiate a FC virtual port. 182 * 183 * Notes: 184 * symbolic_name: The driver is to append the symbolic_name string data 185 * to the symbolic_node_name data that it generates by default. 186 * the resulting combination should then be registered with the switch. 187 * It is expected that things like Xen may stuff a VM title into 188 * this field. 189 */ 190 #define FC_VPORT_SYMBOLIC_NAMELEN 64 191 struct fc_vport_identifiers { 192 u64 node_name; 193 u64 port_name; 194 u32 roles; 195 bool disable; 196 enum fc_port_type vport_type; /* only FC_PORTTYPE_NPIV allowed */ 197 char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN]; 198 }; 199 200 /* 201 * FC Virtual Port Attributes 202 * 203 * This structure exists for each FC port is a virtual FC port. Virtual 204 * ports share the physical link with the Physical port. Each virtual 205 * ports has a unique presence on the SAN, and may be instantiated via 206 * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a 207 * unique presence, each vport has it's own view of the fabric, 208 * authentication privilege, and priorities. 209 * 210 * A virtual port may support 1 or more FC4 roles. Typically it is a 211 * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC 212 * roles. FC port attributes for the vport will be reported on any 213 * fc_host class object allocated for an FCP Initiator. 214 * 215 * -- 216 * 217 * Fixed attributes are not expected to change. The driver is 218 * expected to set these values after receiving the fc_vport structure 219 * via the vport_create() call from the transport. 220 * The transport fully manages all get functions w/o driver interaction. 221 * 222 * Dynamic attributes are expected to change. The driver participates 223 * in all get/set operations via functions provided by the driver. 224 * 225 * Private attributes are transport-managed values. They are fully 226 * managed by the transport w/o driver interaction. 227 */ 228 229 struct fc_vport { 230 /* Fixed Attributes */ 231 232 /* Dynamic Attributes */ 233 234 /* Private (Transport-managed) Attributes */ 235 enum fc_vport_state vport_state; 236 enum fc_vport_state vport_last_state; 237 u64 node_name; 238 u64 port_name; 239 u32 roles; 240 u32 vport_id; /* Admin Identifier for the vport */ 241 enum fc_port_type vport_type; 242 char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN]; 243 244 /* exported data */ 245 void *dd_data; /* Used for driver-specific storage */ 246 247 /* internal data */ 248 struct Scsi_Host *shost; /* Physical Port Parent */ 249 unsigned int channel; 250 u32 number; 251 u8 flags; 252 struct list_head peers; 253 struct device dev; 254 struct work_struct vport_delete_work; 255 } __attribute__((aligned(sizeof(unsigned long)))); 256 257 /* bit field values for struct fc_vport "flags" field: */ 258 #define FC_VPORT_CREATING 0x01 259 #define FC_VPORT_DELETING 0x02 260 #define FC_VPORT_DELETED 0x04 261 #define FC_VPORT_DEL 0x06 /* Any DELETE state */ 262 263 #define dev_to_vport(d) \ 264 container_of(d, struct fc_vport, dev) 265 #define transport_class_to_vport(dev) \ 266 dev_to_vport(dev->parent) 267 #define vport_to_shost(v) \ 268 (v->shost) 269 #define vport_to_shost_channel(v) \ 270 (v->channel) 271 #define vport_to_parent(v) \ 272 (v->dev.parent) 273 274 275 /* Error return codes for vport_create() callback */ 276 #define VPCERR_UNSUPPORTED -ENOSYS /* no driver/adapter 277 support */ 278 #define VPCERR_BAD_WWN -ENOTUNIQ /* driver validation 279 of WWNs failed */ 280 #define VPCERR_NO_FABRIC_SUPP -EOPNOTSUPP /* Fabric connection 281 is loop or the 282 Fabric Port does 283 not support NPIV */ 284 285 /* 286 * fc_rport_identifiers: This set of data contains all elements 287 * to uniquely identify a remote FC port. The driver uses this data 288 * to report the existence of a remote FC port in the topology. Internally, 289 * the transport uses this data for attributes and to manage consistent 290 * target id bindings. 291 */ 292 struct fc_rport_identifiers { 293 u64 node_name; 294 u64 port_name; 295 u32 port_id; 296 u32 roles; 297 }; 298 299 300 /* Macro for use in defining Remote Port attributes */ 301 #define FC_RPORT_ATTR(_name,_mode,_show,_store) \ 302 struct device_attribute dev_attr_rport_##_name = \ 303 __ATTR(_name,_mode,_show,_store) 304 305 306 /* 307 * FC Remote Port Attributes 308 * 309 * This structure exists for each remote FC port that a LLDD notifies 310 * the subsystem of. A remote FC port may or may not be a SCSI Target, 311 * also be a SCSI initiator, IP endpoint, etc. As such, the remote 312 * port is considered a separate entity, independent of "role" (such 313 * as scsi target). 314 * 315 * -- 316 * 317 * Attributes are based on HBAAPI V2.0 definitions. Only those 318 * attributes that are determinable by the local port (aka Host) 319 * are contained. 320 * 321 * Fixed attributes are not expected to change. The driver is 322 * expected to set these values after successfully calling 323 * fc_remote_port_add(). The transport fully manages all get functions 324 * w/o driver interaction. 325 * 326 * Dynamic attributes are expected to change. The driver participates 327 * in all get/set operations via functions provided by the driver. 328 * 329 * Private attributes are transport-managed values. They are fully 330 * managed by the transport w/o driver interaction. 331 */ 332 333 struct fc_rport { /* aka fc_starget_attrs */ 334 /* Fixed Attributes */ 335 u32 maxframe_size; 336 u32 supported_classes; 337 338 /* Dynamic Attributes */ 339 u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */ 340 341 /* Private (Transport-managed) Attributes */ 342 u64 node_name; 343 u64 port_name; 344 u32 port_id; 345 u32 roles; 346 enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */ 347 u32 scsi_target_id; 348 u32 fast_io_fail_tmo; 349 350 /* exported data */ 351 void *dd_data; /* Used for driver-specific storage */ 352 353 /* internal data */ 354 unsigned int channel; 355 u32 number; 356 u8 flags; 357 struct list_head peers; 358 struct device dev; 359 struct delayed_work dev_loss_work; 360 struct work_struct scan_work; 361 struct delayed_work fail_io_work; 362 struct work_struct stgt_delete_work; 363 struct work_struct rport_delete_work; 364 struct request_queue *rqst_q; /* bsg support */ 365 } __attribute__((aligned(sizeof(unsigned long)))); 366 367 /* bit field values for struct fc_rport "flags" field: */ 368 #define FC_RPORT_DEVLOSS_PENDING 0x01 369 #define FC_RPORT_SCAN_PENDING 0x02 370 #define FC_RPORT_FAST_FAIL_TIMEDOUT 0x04 371 #define FC_RPORT_DEVLOSS_CALLBK_DONE 0x08 372 373 #define dev_to_rport(d) \ 374 container_of(d, struct fc_rport, dev) 375 #define transport_class_to_rport(dev) \ 376 dev_to_rport(dev->parent) 377 #define rport_to_shost(r) \ 378 dev_to_shost(r->dev.parent) 379 380 /* 381 * FC SCSI Target Attributes 382 * 383 * The SCSI Target is considered an extension of a remote port (as 384 * a remote port can be more than a SCSI Target). Within the scsi 385 * subsystem, we leave the Target as a separate entity. Doing so 386 * provides backward compatibility with prior FC transport api's, 387 * and lets remote ports be handled entirely within the FC transport 388 * and independently from the scsi subsystem. The drawback is that 389 * some data will be duplicated. 390 */ 391 392 struct fc_starget_attrs { /* aka fc_target_attrs */ 393 /* Dynamic Attributes */ 394 u64 node_name; 395 u64 port_name; 396 u32 port_id; 397 }; 398 399 #define fc_starget_node_name(x) \ 400 (((struct fc_starget_attrs *)&(x)->starget_data)->node_name) 401 #define fc_starget_port_name(x) \ 402 (((struct fc_starget_attrs *)&(x)->starget_data)->port_name) 403 #define fc_starget_port_id(x) \ 404 (((struct fc_starget_attrs *)&(x)->starget_data)->port_id) 405 406 #define starget_to_rport(s) \ 407 scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL 408 409 410 /* 411 * FC Local Port (Host) Statistics 412 */ 413 414 /* FC Statistics - Following FC HBAAPI v2.0 guidelines */ 415 struct fc_host_statistics { 416 /* port statistics */ 417 u64 seconds_since_last_reset; 418 u64 tx_frames; 419 u64 tx_words; 420 u64 rx_frames; 421 u64 rx_words; 422 u64 lip_count; 423 u64 nos_count; 424 u64 error_frames; 425 u64 dumped_frames; 426 u64 link_failure_count; 427 u64 loss_of_sync_count; 428 u64 loss_of_signal_count; 429 u64 prim_seq_protocol_err_count; 430 u64 invalid_tx_word_count; 431 u64 invalid_crc_count; 432 433 /* fc4 statistics (only FCP supported currently) */ 434 u64 fcp_input_requests; 435 u64 fcp_output_requests; 436 u64 fcp_control_requests; 437 u64 fcp_input_megabytes; 438 u64 fcp_output_megabytes; 439 u64 fcp_packet_alloc_failures; /* fcp packet allocation failures */ 440 u64 fcp_packet_aborts; /* fcp packet aborted */ 441 u64 fcp_frame_alloc_failures; /* fcp frame allocation failures */ 442 443 /* fc exches statistics */ 444 u64 fc_no_free_exch; /* no free exch memory */ 445 u64 fc_no_free_exch_xid; /* no free exch id */ 446 u64 fc_xid_not_found; /* exch not found for a response */ 447 u64 fc_xid_busy; /* exch exist for new a request */ 448 u64 fc_seq_not_found; /* seq is not found for exchange */ 449 u64 fc_non_bls_resp; /* a non BLS response frame with 450 a sequence responder in new exch */ 451 }; 452 453 454 /* 455 * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines 456 */ 457 458 /* 459 * fc_host_event_code: If you alter this, you also need to alter 460 * scsi_transport_fc.c (for the ascii descriptions). 461 */ 462 enum fc_host_event_code { 463 FCH_EVT_LIP = 0x1, 464 FCH_EVT_LINKUP = 0x2, 465 FCH_EVT_LINKDOWN = 0x3, 466 FCH_EVT_LIPRESET = 0x4, 467 FCH_EVT_RSCN = 0x5, 468 FCH_EVT_ADAPTER_CHANGE = 0x103, 469 FCH_EVT_PORT_UNKNOWN = 0x200, 470 FCH_EVT_PORT_OFFLINE = 0x201, 471 FCH_EVT_PORT_ONLINE = 0x202, 472 FCH_EVT_PORT_FABRIC = 0x204, 473 FCH_EVT_LINK_UNKNOWN = 0x500, 474 FCH_EVT_VENDOR_UNIQUE = 0xffff, 475 }; 476 477 478 /* 479 * FC Local Port (Host) Attributes 480 * 481 * Attributes are based on HBAAPI V2.0 definitions. 482 * Note: OSDeviceName is determined by user-space library 483 * 484 * Fixed attributes are not expected to change. The driver is 485 * expected to set these values after successfully calling scsi_add_host(). 486 * The transport fully manages all get functions w/o driver interaction. 487 * 488 * Dynamic attributes are expected to change. The driver participates 489 * in all get/set operations via functions provided by the driver. 490 * 491 * Private attributes are transport-managed values. They are fully 492 * managed by the transport w/o driver interaction. 493 */ 494 495 #define FC_FC4_LIST_SIZE 32 496 #define FC_SYMBOLIC_NAME_SIZE 256 497 #define FC_VERSION_STRING_SIZE 64 498 #define FC_SERIAL_NUMBER_SIZE 80 499 500 struct fc_host_attrs { 501 /* Fixed Attributes */ 502 u64 node_name; 503 u64 port_name; 504 u64 permanent_port_name; 505 u32 supported_classes; 506 u8 supported_fc4s[FC_FC4_LIST_SIZE]; 507 u32 supported_speeds; 508 u32 maxframe_size; 509 u16 max_npiv_vports; 510 char serial_number[FC_SERIAL_NUMBER_SIZE]; 511 char manufacturer[FC_SERIAL_NUMBER_SIZE]; 512 char model[FC_SYMBOLIC_NAME_SIZE]; 513 char model_description[FC_SYMBOLIC_NAME_SIZE]; 514 char hardware_version[FC_VERSION_STRING_SIZE]; 515 char driver_version[FC_VERSION_STRING_SIZE]; 516 char firmware_version[FC_VERSION_STRING_SIZE]; 517 char optionrom_version[FC_VERSION_STRING_SIZE]; 518 519 /* Dynamic Attributes */ 520 u32 port_id; 521 enum fc_port_type port_type; 522 enum fc_port_state port_state; 523 u8 active_fc4s[FC_FC4_LIST_SIZE]; 524 u32 speed; 525 u64 fabric_name; 526 char symbolic_name[FC_SYMBOLIC_NAME_SIZE]; 527 char system_hostname[FC_SYMBOLIC_NAME_SIZE]; 528 u32 dev_loss_tmo; 529 530 /* Private (Transport-managed) Attributes */ 531 enum fc_tgtid_binding_type tgtid_bind_type; 532 533 /* internal data */ 534 struct list_head rports; 535 struct list_head rport_bindings; 536 struct list_head vports; 537 u32 next_rport_number; 538 u32 next_target_id; 539 u32 next_vport_number; 540 u16 npiv_vports_inuse; 541 542 /* work queues for rport state manipulation */ 543 char work_q_name[20]; 544 struct workqueue_struct *work_q; 545 char devloss_work_q_name[20]; 546 struct workqueue_struct *devloss_work_q; 547 548 /* bsg support */ 549 struct request_queue *rqst_q; 550 }; 551 552 #define shost_to_fc_host(x) \ 553 ((struct fc_host_attrs *)(x)->shost_data) 554 555 #define fc_host_node_name(x) \ 556 (((struct fc_host_attrs *)(x)->shost_data)->node_name) 557 #define fc_host_port_name(x) \ 558 (((struct fc_host_attrs *)(x)->shost_data)->port_name) 559 #define fc_host_permanent_port_name(x) \ 560 (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name) 561 #define fc_host_supported_classes(x) \ 562 (((struct fc_host_attrs *)(x)->shost_data)->supported_classes) 563 #define fc_host_supported_fc4s(x) \ 564 (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s) 565 #define fc_host_supported_speeds(x) \ 566 (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds) 567 #define fc_host_maxframe_size(x) \ 568 (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size) 569 #define fc_host_max_npiv_vports(x) \ 570 (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports) 571 #define fc_host_serial_number(x) \ 572 (((struct fc_host_attrs *)(x)->shost_data)->serial_number) 573 #define fc_host_manufacturer(x) \ 574 (((struct fc_host_attrs *)(x)->shost_data)->manufacturer) 575 #define fc_host_model(x) \ 576 (((struct fc_host_attrs *)(x)->shost_data)->model) 577 #define fc_host_model_description(x) \ 578 (((struct fc_host_attrs *)(x)->shost_data)->model_description) 579 #define fc_host_hardware_version(x) \ 580 (((struct fc_host_attrs *)(x)->shost_data)->hardware_version) 581 #define fc_host_driver_version(x) \ 582 (((struct fc_host_attrs *)(x)->shost_data)->driver_version) 583 #define fc_host_firmware_version(x) \ 584 (((struct fc_host_attrs *)(x)->shost_data)->firmware_version) 585 #define fc_host_optionrom_version(x) \ 586 (((struct fc_host_attrs *)(x)->shost_data)->optionrom_version) 587 #define fc_host_port_id(x) \ 588 (((struct fc_host_attrs *)(x)->shost_data)->port_id) 589 #define fc_host_port_type(x) \ 590 (((struct fc_host_attrs *)(x)->shost_data)->port_type) 591 #define fc_host_port_state(x) \ 592 (((struct fc_host_attrs *)(x)->shost_data)->port_state) 593 #define fc_host_active_fc4s(x) \ 594 (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s) 595 #define fc_host_speed(x) \ 596 (((struct fc_host_attrs *)(x)->shost_data)->speed) 597 #define fc_host_fabric_name(x) \ 598 (((struct fc_host_attrs *)(x)->shost_data)->fabric_name) 599 #define fc_host_symbolic_name(x) \ 600 (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name) 601 #define fc_host_system_hostname(x) \ 602 (((struct fc_host_attrs *)(x)->shost_data)->system_hostname) 603 #define fc_host_tgtid_bind_type(x) \ 604 (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type) 605 #define fc_host_rports(x) \ 606 (((struct fc_host_attrs *)(x)->shost_data)->rports) 607 #define fc_host_rport_bindings(x) \ 608 (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings) 609 #define fc_host_vports(x) \ 610 (((struct fc_host_attrs *)(x)->shost_data)->vports) 611 #define fc_host_next_rport_number(x) \ 612 (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number) 613 #define fc_host_next_target_id(x) \ 614 (((struct fc_host_attrs *)(x)->shost_data)->next_target_id) 615 #define fc_host_next_vport_number(x) \ 616 (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number) 617 #define fc_host_npiv_vports_inuse(x) \ 618 (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse) 619 #define fc_host_work_q_name(x) \ 620 (((struct fc_host_attrs *)(x)->shost_data)->work_q_name) 621 #define fc_host_work_q(x) \ 622 (((struct fc_host_attrs *)(x)->shost_data)->work_q) 623 #define fc_host_devloss_work_q_name(x) \ 624 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name) 625 #define fc_host_devloss_work_q(x) \ 626 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q) 627 #define fc_host_dev_loss_tmo(x) \ 628 (((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo) 629 630 /* The functions by which the transport class and the driver communicate */ 631 struct fc_function_template { 632 void (*get_rport_dev_loss_tmo)(struct fc_rport *); 633 void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32); 634 635 void (*get_starget_node_name)(struct scsi_target *); 636 void (*get_starget_port_name)(struct scsi_target *); 637 void (*get_starget_port_id)(struct scsi_target *); 638 639 void (*get_host_port_id)(struct Scsi_Host *); 640 void (*get_host_port_type)(struct Scsi_Host *); 641 void (*get_host_port_state)(struct Scsi_Host *); 642 void (*get_host_active_fc4s)(struct Scsi_Host *); 643 void (*get_host_speed)(struct Scsi_Host *); 644 void (*get_host_fabric_name)(struct Scsi_Host *); 645 void (*get_host_symbolic_name)(struct Scsi_Host *); 646 void (*set_host_system_hostname)(struct Scsi_Host *); 647 648 struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *); 649 void (*reset_fc_host_stats)(struct Scsi_Host *); 650 651 int (*issue_fc_host_lip)(struct Scsi_Host *); 652 653 void (*dev_loss_tmo_callbk)(struct fc_rport *); 654 void (*terminate_rport_io)(struct fc_rport *); 655 656 void (*set_vport_symbolic_name)(struct fc_vport *); 657 int (*vport_create)(struct fc_vport *, bool); 658 int (*vport_disable)(struct fc_vport *, bool); 659 int (*vport_delete)(struct fc_vport *); 660 661 /* bsg support */ 662 int (*bsg_request)(struct bsg_job *); 663 int (*bsg_timeout)(struct bsg_job *); 664 665 /* allocation lengths for host-specific data */ 666 u32 dd_fcrport_size; 667 u32 dd_fcvport_size; 668 u32 dd_bsg_size; 669 670 /* 671 * The driver sets these to tell the transport class it 672 * wants the attributes displayed in sysfs. If the show_ flag 673 * is not set, the attribute will be private to the transport 674 * class 675 */ 676 677 /* remote port fixed attributes */ 678 unsigned long show_rport_maxframe_size:1; 679 unsigned long show_rport_supported_classes:1; 680 unsigned long show_rport_dev_loss_tmo:1; 681 682 /* 683 * target dynamic attributes 684 * These should all be "1" if the driver uses the remote port 685 * add/delete functions (so attributes reflect rport values). 686 */ 687 unsigned long show_starget_node_name:1; 688 unsigned long show_starget_port_name:1; 689 unsigned long show_starget_port_id:1; 690 691 /* host fixed attributes */ 692 unsigned long show_host_node_name:1; 693 unsigned long show_host_port_name:1; 694 unsigned long show_host_permanent_port_name:1; 695 unsigned long show_host_supported_classes:1; 696 unsigned long show_host_supported_fc4s:1; 697 unsigned long show_host_supported_speeds:1; 698 unsigned long show_host_maxframe_size:1; 699 unsigned long show_host_serial_number:1; 700 unsigned long show_host_manufacturer:1; 701 unsigned long show_host_model:1; 702 unsigned long show_host_model_description:1; 703 unsigned long show_host_hardware_version:1; 704 unsigned long show_host_driver_version:1; 705 unsigned long show_host_firmware_version:1; 706 unsigned long show_host_optionrom_version:1; 707 /* host dynamic attributes */ 708 unsigned long show_host_port_id:1; 709 unsigned long show_host_port_type:1; 710 unsigned long show_host_port_state:1; 711 unsigned long show_host_active_fc4s:1; 712 unsigned long show_host_speed:1; 713 unsigned long show_host_fabric_name:1; 714 unsigned long show_host_symbolic_name:1; 715 unsigned long show_host_system_hostname:1; 716 717 unsigned long disable_target_scan:1; 718 }; 719 720 721 /** 722 * fc_remote_port_chkready - called to validate the remote port state 723 * prior to initiating io to the port. 724 * 725 * Returns a scsi result code that can be returned by the LLDD. 726 * 727 * @rport: remote port to be checked 728 **/ 729 static inline int 730 fc_remote_port_chkready(struct fc_rport *rport) 731 { 732 int result; 733 734 switch (rport->port_state) { 735 case FC_PORTSTATE_ONLINE: 736 if (rport->roles & FC_PORT_ROLE_FCP_TARGET) 737 result = 0; 738 else if (rport->flags & FC_RPORT_DEVLOSS_PENDING) 739 result = DID_IMM_RETRY << 16; 740 else 741 result = DID_NO_CONNECT << 16; 742 break; 743 case FC_PORTSTATE_BLOCKED: 744 if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT) 745 result = DID_TRANSPORT_FAILFAST << 16; 746 else 747 result = DID_IMM_RETRY << 16; 748 break; 749 default: 750 result = DID_NO_CONNECT << 16; 751 break; 752 } 753 return result; 754 } 755 756 static inline u64 wwn_to_u64(u8 *wwn) 757 { 758 return get_unaligned_be64(wwn); 759 } 760 761 static inline void u64_to_wwn(u64 inm, u8 *wwn) 762 { 763 put_unaligned_be64(inm, wwn); 764 } 765 766 /** 767 * fc_vport_set_state() - called to set a vport's state. Saves the old state, 768 * excepting the transitory states of initializing and sending the ELS 769 * traffic to instantiate the vport on the link. 770 * 771 * Assumes the driver has surrounded this with the proper locking to ensure 772 * a coherent state change. 773 * 774 * @vport: virtual port whose state is changing 775 * @new_state: new state 776 **/ 777 static inline void 778 fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state) 779 { 780 if ((new_state != FC_VPORT_UNKNOWN) && 781 (new_state != FC_VPORT_INITIALIZING)) 782 vport->vport_last_state = vport->vport_state; 783 vport->vport_state = new_state; 784 } 785 786 struct scsi_transport_template *fc_attach_transport( 787 struct fc_function_template *); 788 void fc_release_transport(struct scsi_transport_template *); 789 void fc_remove_host(struct Scsi_Host *); 790 struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost, 791 int channel, struct fc_rport_identifiers *ids); 792 void fc_remote_port_delete(struct fc_rport *rport); 793 void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles); 794 int scsi_is_fc_rport(const struct device *); 795 u32 fc_get_event_number(void); 796 void fc_host_post_event(struct Scsi_Host *shost, u32 event_number, 797 enum fc_host_event_code event_code, u32 event_data); 798 void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, 799 u32 data_len, char * data_buf, u64 vendor_id); 800 /* Note: when specifying vendor_id to fc_host_post_vendor_event() 801 * be sure to read the Vendor Type and ID formatting requirements 802 * specified in scsi_netlink.h 803 */ 804 struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel, 805 struct fc_vport_identifiers *); 806 int fc_vport_terminate(struct fc_vport *vport); 807 int fc_block_scsi_eh(struct scsi_cmnd *cmnd); 808 enum blk_eh_timer_return fc_eh_timed_out(struct scsi_cmnd *scmd); 809 810 static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job) 811 { 812 if (scsi_is_host_device(job->dev)) 813 return dev_to_shost(job->dev); 814 return rport_to_shost(dev_to_rport(job->dev)); 815 } 816 817 static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job) 818 { 819 if (scsi_is_fc_rport(job->dev)) 820 return dev_to_rport(job->dev); 821 return NULL; 822 } 823 824 #endif /* SCSI_TRANSPORT_FC_H */ 825