scsi_fc_transport.rst 25 KB

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