1.. SPDX-License-Identifier: GPL-2.0 2 3================ 4SCSI FC Tansport 5================ 6 7Date: 11/18/2008 8 9Kernel Revisions for features:: 10 11 rports : <<TBS>> 12 vports : 2.6.22 13 bsg support : 2.6.30 (?TBD?) 14 15 16Introduction 17============ 18This file documents the features and components of the SCSI FC Transport. 19It also provides documents the API between the transport and FC LLDDs. 20 21The FC transport can be found at:: 22 23 drivers/scsi/scsi_transport_fc.c 24 include/scsi/scsi_transport_fc.h 25 include/scsi/scsi_netlink_fc.h 26 include/scsi/scsi_bsg_fc.h 27 28This file is found at Documentation/scsi/scsi_fc_transport.rst 29 30 31FC Remote Ports (rports) 32======================== 33<< To Be Supplied >> 34 35 36FC Virtual Ports (vports) 37========================= 38 39Overview 40-------- 41 42 New FC standards have defined mechanisms which allows for a single physical 43 port to appear on as multiple communication ports. Using the N_Port Id 44 Virtualization (NPIV) mechanism, a point-to-point connection to a Fabric 45 can be assigned more than 1 N_Port_ID. Each N_Port_ID appears as a 46 separate port to other endpoints on the fabric, even though it shares one 47 physical link to the switch for communication. Each N_Port_ID can have a 48 unique view of the fabric based on fabric zoning and array lun-masking 49 (just like a normal non-NPIV adapter). Using the Virtual Fabric (VF) 50 mechanism, adding a fabric header to each frame allows the port to 51 interact with the Fabric Port to join multiple fabrics. The port will 52 obtain an N_Port_ID on each fabric it joins. Each fabric will have its 53 own unique view of endpoints and configuration parameters. NPIV may be 54 used together with VF so that the port can obtain multiple N_Port_IDs 55 on each virtual fabric. 56 57 The FC transport is now recognizing a new object - a vport. A vport is 58 an entity that has a world-wide unique World Wide Port Name (wwpn) and 59 World Wide Node Name (wwnn). The transport also allows for the FC4's to 60 be specified for the vport, with FCP_Initiator being the primary role 61 expected. Once instantiated by one of the above methods, it will have a 62 distinct N_Port_ID and view of fabric endpoints and storage entities. 63 The fc_host associated with the physical adapter will export the ability 64 to create vports. The transport will create the vport object within the 65 Linux device tree, and instruct the fc_host's driver to instantiate the 66 virtual port. Typically, the driver will create a new scsi_host instance 67 on the vport, resulting in a unique <H,C,T,L> namespace for the vport. 68 Thus, whether a FC port is based on a physical port or on a virtual port, 69 each will appear as a unique scsi_host with its own target and lun space. 70 71 .. Note:: 72 At this time, the transport is written to create only NPIV-based 73 vports. However, consideration was given to VF-based vports and it 74 should be a minor change to add support if needed. The remaining 75 discussion will concentrate on NPIV. 76 77 .. Note:: 78 World Wide Name assignment (and uniqueness guarantees) are left 79 up to an administrative entity controlling the vport. For example, 80 if vports are to be associated with virtual machines, a XEN mgmt 81 utility would be responsible for creating wwpn/wwnn's for the vport, 82 using its own naming authority and OUI. (Note: it already does this 83 for virtual MAC addresses). 84 85 86Device Trees and Vport Objects: 87------------------------------- 88 89 Today, the device tree typically contains the scsi_host object, 90 with rports and scsi target objects underneath it. Currently the FC 91 transport creates the vport object and places it under the scsi_host 92 object corresponding to the physical adapter. The LLDD will allocate 93 a new scsi_host for the vport and link its object under the vport. 94 The remainder of the tree under the vports scsi_host is the same 95 as the non-NPIV case. The transport is written currently to easily 96 allow the parent of the vport to be something other than the scsi_host. 97 This could be used in the future to link the object onto a vm-specific 98 device tree. If the vport's parent is not the physical port's scsi_host, 99 a symbolic link to the vport object will be placed in the physical 100 port's scsi_host. 101 102 Here's what to expect in the device tree : 103 104 The typical Physical Port's Scsi_Host:: 105 106 /sys/devices/.../host17/ 107 108 and it has the typical descendant tree:: 109 110 /sys/devices/.../host17/rport-17:0-0/target17:0:0/17:0:0:0: 111 112 and then the vport is created on the Physical Port:: 113 114 /sys/devices/.../host17/vport-17:0-0 115 116 and the vport's Scsi_Host is then created:: 117 118 /sys/devices/.../host17/vport-17:0-0/host18 119 120 and then the rest of the tree progresses, such as:: 121 122 /sys/devices/.../host17/vport-17:0-0/host18/rport-18:0-0/target18:0:0/18:0:0:0: 123 124 Here's what to expect in the sysfs tree:: 125 126 scsi_hosts: 127 /sys/class/scsi_host/host17 physical port's scsi_host 128 /sys/class/scsi_host/host18 vport's scsi_host 129 fc_hosts: 130 /sys/class/fc_host/host17 physical port's fc_host 131 /sys/class/fc_host/host18 vport's fc_host 132 fc_vports: 133 /sys/class/fc_vports/vport-17:0-0 the vport's fc_vport 134 fc_rports: 135 /sys/class/fc_remote_ports/rport-17:0-0 rport on the physical port 136 /sys/class/fc_remote_ports/rport-18:0-0 rport on the vport 137 138 139Vport Attributes 140---------------- 141 142 The new fc_vport class object has the following attributes 143 144 node_name: Read_Only 145 The WWNN of the vport 146 147 port_name: Read_Only 148 The WWPN of the vport 149 150 roles: Read_Only 151 Indicates the FC4 roles enabled on the vport. 152 153 symbolic_name: Read_Write 154 A string, appended to the driver's symbolic port name string, which 155 is registered with the switch to identify the vport. For example, 156 a hypervisor could set this string to "Xen Domain 2 VM 5 Vport 2", 157 and this set of identifiers can be seen on switch management screens 158 to identify the port. 159 160 vport_delete: Write_Only 161 When written with a "1", will tear down the vport. 162 163 vport_disable: Write_Only 164 When written with a "1", will transition the vport to a disabled. 165 state. The vport will still be instantiated with the Linux kernel, 166 but it will not be active on the FC link. 167 When written with a "0", will enable the vport. 168 169 vport_last_state: Read_Only 170 Indicates the previous state of the vport. See the section below on 171 "Vport States". 172 173 vport_state: Read_Only 174 Indicates the state of the vport. See the section below on 175 "Vport States". 176 177 vport_type: Read_Only 178 Reflects the FC mechanism used to create the virtual port. 179 Only NPIV is supported currently. 180 181 182 For the fc_host class object, the following attributes are added for vports: 183 184 max_npiv_vports: Read_Only 185 Indicates the maximum number of NPIV-based vports that the 186 driver/adapter can support on the fc_host. 187 188 npiv_vports_inuse: Read_Only 189 Indicates how many NPIV-based vports have been instantiated on the 190 fc_host. 191 192 vport_create: Write_Only 193 A "simple" create interface to instantiate a vport on an fc_host. 194 A "<WWPN>:<WWNN>" string is written to the attribute. The transport 195 then instantiates the vport object and calls the LLDD to create the 196 vport with the role of FCP_Initiator. Each WWN is specified as 16 197 hex characters and may *not* contain any prefixes (e.g. 0x, x, etc). 198 199 vport_delete: Write_Only 200 A "simple" delete interface to teardown a vport. A "<WWPN>:<WWNN>" 201 string is written to the attribute. The transport will locate the 202 vport on the fc_host with the same WWNs and tear it down. Each WWN 203 is specified as 16 hex characters and may *not* contain any prefixes 204 (e.g. 0x, x, etc). 205 206 207Vport States 208------------ 209 210 Vport instantiation consists of two parts: 211 212 - Creation with the kernel and LLDD. This means all transport and 213 driver data structures are built up, and device objects created. 214 This is equivalent to a driver "attach" on an adapter, which is 215 independent of the adapter's link state. 216 - Instantiation of the vport on the FC link via ELS traffic, etc. 217 This is equivalent to a "link up" and successful link initialization. 218 219 Further information can be found in the interfaces section below for 220 Vport Creation. 221 222 Once a vport has been instantiated with the kernel/LLDD, a vport state 223 can be reported via the sysfs attribute. The following states exist: 224 225 FC_VPORT_UNKNOWN - Unknown 226 An temporary state, typically set only while the vport is being 227 instantiated with the kernel and LLDD. 228 229 FC_VPORT_ACTIVE - Active 230 The vport has been successfully been created on the FC link. 231 It is fully functional. 232 233 FC_VPORT_DISABLED - Disabled 234 The vport instantiated, but "disabled". The vport is not instantiated 235 on the FC link. This is equivalent to a physical port with the 236 link "down". 237 238 FC_VPORT_LINKDOWN - Linkdown 239 The vport is not operational as the physical link is not operational. 240 241 FC_VPORT_INITIALIZING - Initializing 242 The vport is in the process of instantiating on the FC link. 243 The LLDD will set this state just prior to starting the ELS traffic 244 to create the vport. This state will persist until the vport is 245 successfully created (state becomes FC_VPORT_ACTIVE) or it fails 246 (state is one of the values below). As this state is transitory, 247 it will not be preserved in the "vport_last_state". 248 249 FC_VPORT_NO_FABRIC_SUPP - No Fabric Support 250 The vport is not operational. One of the following conditions were 251 encountered: 252 253 - The FC topology is not Point-to-Point 254 - The FC port is not connected to an F_Port 255 - The F_Port has indicated that NPIV is not supported. 256 257 FC_VPORT_NO_FABRIC_RSCS - No Fabric Resources 258 The vport is not operational. The Fabric failed FDISC with a status 259 indicating that it does not have sufficient resources to complete 260 the operation. 261 262 FC_VPORT_FABRIC_LOGOUT - Fabric Logout 263 The vport is not operational. The Fabric has LOGO'd the N_Port_ID 264 associated with the vport. 265 266 FC_VPORT_FABRIC_REJ_WWN - Fabric Rejected WWN 267 The vport is not operational. The Fabric failed FDISC with a status 268 indicating that the WWN's are not valid. 269 270 FC_VPORT_FAILED - VPort Failed 271 The vport is not operational. This is a catchall for all other 272 error conditions. 273 274 275 The following state table indicates the different state transitions: 276 277 +------------------+--------------------------------+---------------------+ 278 | State | Event | New State | 279 +==================+================================+=====================+ 280 | n/a | Initialization | Unknown | 281 +------------------+--------------------------------+---------------------+ 282 | Unknown: | Link Down | Linkdown | 283 | +--------------------------------+---------------------+ 284 | | Link Up & Loop | No Fabric Support | 285 | +--------------------------------+---------------------+ 286 | | Link Up & no Fabric | No Fabric Support | 287 | +--------------------------------+---------------------+ 288 | | Link Up & FLOGI response | No Fabric Support | 289 | | indicates no NPIV support | | 290 | +--------------------------------+---------------------+ 291 | | Link Up & FDISC being sent | Initializing | 292 | +--------------------------------+---------------------+ 293 | | Disable request | Disable | 294 +------------------+--------------------------------+---------------------+ 295 | Linkdown: | Link Up | Unknown | 296 +------------------+--------------------------------+---------------------+ 297 | Initializing: | FDISC ACC | Active | 298 | +--------------------------------+---------------------+ 299 | | FDISC LS_RJT w/ no resources | No Fabric Resources | 300 | +--------------------------------+---------------------+ 301 | | FDISC LS_RJT w/ invalid | Fabric Rejected WWN | 302 | | pname or invalid nport_id | | 303 | +--------------------------------+---------------------+ 304 | | FDISC LS_RJT failed for | Vport Failed | 305 | | other reasons | | 306 | +--------------------------------+---------------------+ 307 | | Link Down | Linkdown | 308 | +--------------------------------+---------------------+ 309 | | Disable request | Disable | 310 +------------------+--------------------------------+---------------------+ 311 | Disable: | Enable request | Unknown | 312 +------------------+--------------------------------+---------------------+ 313 | Active: | LOGO received from fabric | Fabric Logout | 314 | +--------------------------------+---------------------+ 315 | | Link Down | Linkdown | 316 | +--------------------------------+---------------------+ 317 | | Disable request | Disable | 318 +------------------+--------------------------------+---------------------+ 319 | Fabric Logout: | Link still up | Unknown | 320 +------------------+--------------------------------+---------------------+ 321 322The following 4 error states all have the same transitions:: 323 324 No Fabric Support: 325 No Fabric Resources: 326 Fabric Rejected WWN: 327 Vport Failed: 328 Disable request Disable 329 Link goes down Linkdown 330 331 332Transport <-> LLDD Interfaces 333----------------------------- 334 335Vport support by LLDD: 336 337 The LLDD indicates support for vports by supplying a vport_create() 338 function in the transport template. The presence of this function will 339 cause the creation of the new attributes on the fc_host. As part of 340 the physical port completing its initialization relative to the 341 transport, it should set the max_npiv_vports attribute to indicate the 342 maximum number of vports the driver and/or adapter supports. 343 344 345Vport Creation: 346 347 The LLDD vport_create() syntax is:: 348 349 int vport_create(struct fc_vport *vport, bool disable) 350 351 where: 352 353 ======= =========================================================== 354 vport Is the newly allocated vport object 355 disable If "true", the vport is to be created in a disabled stated. 356 If "false", the vport is to be enabled upon creation. 357 ======= =========================================================== 358 359 When a request is made to create a new vport (via sgio/netlink, or the 360 vport_create fc_host attribute), the transport will validate that the LLDD 361 can support another vport (e.g. max_npiv_vports > npiv_vports_inuse). 362 If not, the create request will be failed. If space remains, the transport 363 will increment the vport count, create the vport object, and then call the 364 LLDD's vport_create() function with the newly allocated vport object. 365 366 As mentioned above, vport creation is divided into two parts: 367 368 - Creation with the kernel and LLDD. This means all transport and 369 driver data structures are built up, and device objects created. 370 This is equivalent to a driver "attach" on an adapter, which is 371 independent of the adapter's link state. 372 - Instantiation of the vport on the FC link via ELS traffic, etc. 373 This is equivalent to a "link up" and successful link initialization. 374 375 The LLDD's vport_create() function will not synchronously wait for both 376 parts to be fully completed before returning. It must validate that the 377 infrastructure exists to support NPIV, and complete the first part of 378 vport creation (data structure build up) before returning. We do not 379 hinge vport_create() on the link-side operation mainly because: 380 381 - The link may be down. It is not a failure if it is. It simply 382 means the vport is in an inoperable state until the link comes up. 383 This is consistent with the link bouncing post vport creation. 384 - The vport may be created in a disabled state. 385 - This is consistent with a model where: the vport equates to a 386 FC adapter. The vport_create is synonymous with driver attachment 387 to the adapter, which is independent of link state. 388 389 .. Note:: 390 391 special error codes have been defined to delineate infrastructure 392 failure cases for quicker resolution. 393 394 The expected behavior for the LLDD's vport_create() function is: 395 396 - Validate Infrastructure: 397 398 - If the driver or adapter cannot support another vport, whether 399 due to improper firmware, (a lie about) max_npiv, or a lack of 400 some other resource - return VPCERR_UNSUPPORTED. 401 - If the driver validates the WWN's against those already active on 402 the adapter and detects an overlap - return VPCERR_BAD_WWN. 403 - If the driver detects the topology is loop, non-fabric, or the 404 FLOGI did not support NPIV - return VPCERR_NO_FABRIC_SUPP. 405 406 - Allocate data structures. If errors are encountered, such as out 407 of memory conditions, return the respective negative Exxx error code. 408 - If the role is FCP Initiator, the LLDD is to : 409 410 - Call scsi_host_alloc() to allocate a scsi_host for the vport. 411 - Call scsi_add_host(new_shost, &vport->dev) to start the scsi_host 412 and bind it as a child of the vport device. 413 - Initializes the fc_host attribute values. 414 415 - Kick of further vport state transitions based on the disable flag and 416 link state - and return success (zero). 417 418 LLDD Implementers Notes: 419 420 - It is suggested that there be a different fc_function_templates for 421 the physical port and the virtual port. The physical port's template 422 would have the vport_create, vport_delete, and vport_disable functions, 423 while the vports would not. 424 - It is suggested that there be different scsi_host_templates 425 for the physical port and virtual port. Likely, there are driver 426 attributes, embedded into the scsi_host_template, that are applicable 427 for the physical port only (link speed, topology setting, etc). This 428 ensures that the attributes are applicable to the respective scsi_host. 429 430 431Vport Disable/Enable: 432 433 The LLDD vport_disable() syntax is:: 434 435 int vport_disable(struct fc_vport *vport, bool disable) 436 437 where: 438 439 ======= ======================================= 440 vport Is vport to be enabled or disabled 441 disable If "true", the vport is to be disabled. 442 If "false", the vport is to be enabled. 443 ======= ======================================= 444 445 When a request is made to change the disabled state on a vport, the 446 transport will validate the request against the existing vport state. 447 If the request is to disable and the vport is already disabled, the 448 request will fail. Similarly, if the request is to enable, and the 449 vport is not in a disabled state, the request will fail. If the request 450 is valid for the vport state, the transport will call the LLDD to 451 change the vport's state. 452 453 Within the LLDD, if a vport is disabled, it remains instantiated with 454 the kernel and LLDD, but it is not active or visible on the FC link in 455 any way. (see Vport Creation and the 2 part instantiation discussion). 456 The vport will remain in this state until it is deleted or re-enabled. 457 When enabling a vport, the LLDD reinstantiates the vport on the FC 458 link - essentially restarting the LLDD statemachine (see Vport States 459 above). 460 461 462Vport Deletion: 463 464 The LLDD vport_delete() syntax is:: 465 466 int vport_delete(struct fc_vport *vport) 467 468 where: 469 470 vport: Is vport to delete 471 472 When a request is made to delete a vport (via sgio/netlink, or via the 473 fc_host or fc_vport vport_delete attributes), the transport will call 474 the LLDD to terminate the vport on the FC link, and teardown all other 475 datastructures and references. If the LLDD completes successfully, 476 the transport will teardown the vport objects and complete the vport 477 removal. If the LLDD delete request fails, the vport object will remain, 478 but will be in an indeterminate state. 479 480 Within the LLDD, the normal code paths for a scsi_host teardown should 481 be followed. E.g. If the vport has a FCP Initiator role, the LLDD 482 will call fc_remove_host() for the vports scsi_host, followed by 483 scsi_remove_host() and scsi_host_put() for the vports scsi_host. 484 485 486Other: 487 fc_host port_type attribute: 488 There is a new fc_host port_type value - FC_PORTTYPE_NPIV. This value 489 must be set on all vport-based fc_hosts. Normally, on a physical port, 490 the port_type attribute would be set to NPORT, NLPORT, etc based on the 491 topology type and existence of the fabric. As this is not applicable to 492 a vport, it makes more sense to report the FC mechanism used to create 493 the vport. 494 495 Driver unload: 496 FC drivers are required to call fc_remove_host() prior to calling 497 scsi_remove_host(). This allows the fc_host to tear down all remote 498 ports prior the scsi_host being torn down. The fc_remove_host() call 499 was updated to remove all vports for the fc_host as well. 500 501 502Transport supplied functions 503---------------------------- 504 505The following functions are supplied by the FC-transport for use by LLDs. 506 507 ================== ========================= 508 fc_vport_create create a vport 509 fc_vport_terminate detach and remove a vport 510 ================== ========================= 511 512Details:: 513 514 /** 515 * fc_vport_create - Admin App or LLDD requests creation of a vport 516 * @shost: scsi host the virtual port is connected to. 517 * @ids: The world wide names, FC4 port roles, etc for 518 * the virtual port. 519 * 520 * Notes: 521 * This routine assumes no locks are held on entry. 522 */ 523 struct fc_vport * 524 fc_vport_create(struct Scsi_Host *shost, struct fc_vport_identifiers *ids) 525 526 /** 527 * fc_vport_terminate - Admin App or LLDD requests termination of a vport 528 * @vport: fc_vport to be terminated 529 * 530 * Calls the LLDD vport_delete() function, then deallocates and removes 531 * the vport from the shost and object tree. 532 * 533 * Notes: 534 * This routine assumes no locks are held on entry. 535 */ 536 int 537 fc_vport_terminate(struct fc_vport *vport) 538 539 540FC BSG support (CT & ELS passthru, and more) 541============================================ 542 543<< To Be Supplied >> 544 545 546 547 548 549Credits 550======= 551The following people have contributed to this document: 552 553 554 555 556 557 558James Smart 559james.smart@emulex.com 560 561