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