scsi_fc_transport.rst 24 KB

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