← Documents Documentation/scsi/scsi_fc_transport.rst GitHub 원문 ↗

Linux 6.18.37 · SCSI

SCSI Fibre Channel 전송 계층

SCSI FC transport의 rport, NPIV vport, sysfs 상태 전이와 LLDD 인터페이스를 설명합니다.

Source pathDocumentation/scsi/scsi_fc_transport.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

scsi_fc_transport.rst:1-593

SCSI FC transport의 rport, NPIV vport, sysfs 상태 전이와 LLDD 인터페이스를 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

문서 범위와 구현 파일

1-30

이 문서는 SCSI Fibre Channel(FC) 전송 계층의 기능과 구성 요소, 전송 계층과 FC LLDD 사이의 API를 설명한다. 문서 날짜는 2008년 11월 18일이며 vport는 커널 2.6.22, BSG 지원은 2.6.30으로 기록되어 있고 rport 버전은 아직 정하지 않은 상태다.

관련 구현과 헤더는 `drivers/scsi/scsi_transport_fc.c`, `include/scsi/scsi_transport_fc.h`, `include/scsi/scsi_netlink_fc.h`, `include/scsi/scsi_bsg_fc.h`에 있다. 문서 자체의 경로는 `Documentation/scsi/scsi_fc_transport.rst`이다.

.. SPDX-License-Identifier: GPL-2.0

=================
SCSI FC Transport
=================

Date:  11/18/2008

Kernel Revisions for features::

  rports : <<TBS>>
  vports : 2.6.22
  bsg support : 2.6.30 (?TBD?)


Introduction
============
This file documents the features and components of the SCSI FC Transport.
It also provides documents the API between the transport and FC LLDDs.

The FC transport can be found at::

  drivers/scsi/scsi_transport_fc.c
  include/scsi/scsi_transport_fc.h
  include/scsi/scsi_netlink_fc.h
  include/scsi/scsi_bsg_fc.h

This file is found at Documentation/scsi/scsi_fc_transport.rst

FC 원격 포트(rport)

31-68

FC 하위 시스템의 원격 포트, 즉 rport는 로컬 포트가 통신할 수 있는 원격 Fibre Channel 노드다. 보통 FC 전송으로 SCSI 명령에 응답하는 스토리지 배열이나 테이프 장치 같은 target이다.

Linux에서는 FC transport class가 rport를 관리하며 `/sys/class/fc_remote_ports/` 아래에 표시한다. 각 디렉터리는 port ID, node name, port state, link speed 같은 속성을 제공한다. Fabric login 또는 scan에서 새 장치를 발견하면 만들고, 장치를 제거하거나 링크를 잃을 때까지 유지한다.

드라이버는 발견한 포트의 `fc_rport_identifiers`를 채우고 `fc_remote_port_add()`를 호출해 SCSI 하위 시스템에 등록한다. 제거할 때는 `fc_remote_port_delete()`를 사용한다. rport는 FC host adapter 아래의 sysfs 자식으로도 보인다.

rport 주요 속성
속성의미
node_nameWWNN
port_nameWWPN
port_id원격 포트의 FC 주소
rolesinitiator, target 또는 둘 다
port_state현재 동작 상태

원격 FC 노드를 식별하고 상태를 나타낸다.

FC Remote Ports (rports)
========================

  In the Fibre Channel (FC) subsystem, a remote port (rport) refers to a
  remote Fibre Channel node that the local port can communicate with.
  These are typically storage targets (e.g., arrays, tapes) that respond
  to SCSI commands over FC transport.

  In Linux, rports are managed by the FC transport class and are
  represented in sysfs under:

    /sys/class/fc_remote_ports/

  Each rport directory contains attributes describing the remote port,
  such as port ID, node name, port state, and link speed.

  rports are typically created by the FC transport when a new device is
  discovered during a fabric login or scan, and they persist until the
  device is removed or the link is lost.

  Common attributes:
  - node_name: World Wide Node Name (WWNN).
  - port_name: World Wide Port Name (WWPN).
  - port_id: FC address of the remote port.
  - roles: Indicates if the port is an initiator, target, or both.
  - port_state: Shows the current operational state.

  After discovering a remote port, the driver typically populates a
  fc_rport_identifiers structure and invokes fc_remote_port_add() to
  create and register the remote port with the SCSI subsystem via the
  Fibre Channel (FC) transport class.

  rports are also visible via sysfs as children of the FC host adapter.

  For developers: use fc_remote_port_add() and fc_remote_port_delete() when
  implementing a driver that interacts with the FC transport class.

FC 가상 포트와 NPIV

69-118

새 FC 표준은 하나의 물리 포트가 여러 통신 포트로 보이게 한다. NPIV에서는 Fabric과의 point-to-point 연결에 둘 이상의 `N_Port_ID`를 할당할 수 있다. 각 ID는 같은 물리 링크를 공유하지만 다른 endpoint에는 별도 포트로 보이며, zoning과 LUN masking에 따라 고유한 Fabric 시야를 가질 수 있다.

Virtual Fabric(VF)은 frame에 Fabric header를 추가해 하나의 포트가 여러 Fabric에 참여하게 한다. 포트는 참여한 Fabric마다 `N_Port_ID`를 얻고, 각 Fabric에는 독립된 endpoint와 설정 시야가 있다. NPIV와 VF를 결합하면 가상 Fabric마다 여러 ID를 얻을 수 있다.

FC transport의 새 객체인 vport는 고유한 WWPN과 WWNN을 갖는다. FC4 역할도 지정할 수 있으며 주 역할은 `FCP_Initiator`다. 물리 adapter의 `fc_host`가 vport 생성 기능을 내보내면 전송 계층이 Linux device tree에 vport 객체를 만들고 LLDD에 실제 가상 포트 생성을 지시한다.

드라이버는 보통 vport마다 새 `scsi_host`를 만들어 독립적인 `<H,C,T,L>` 이름 공간을 제공한다. 현재 구현은 NPIV 기반 vport만 생성하지만 VF 지원도 고려한 구조다. WWPN/WWNN의 할당과 고유성은 관리 주체의 책임이며, 예를 들어 가상 머신 관리 도구가 자체 OUI와 명명 권한으로 생성할 수 있다.

FC Virtual Ports (vports)
=========================

Overview
--------

  New FC standards have defined mechanisms which allows for a single physical
  port to appear on as multiple communication ports. Using the N_Port Id
  Virtualization (NPIV) mechanism, a point-to-point connection to a Fabric
  can be assigned more than 1 N_Port_ID.  Each N_Port_ID appears as a
  separate port to other endpoints on the fabric, even though it shares one
  physical link to the switch for communication. Each N_Port_ID can have a
  unique view of the fabric based on fabric zoning and array lun-masking
  (just like a normal non-NPIV adapter).  Using the Virtual Fabric (VF)
  mechanism, adding a fabric header to each frame allows the port to
  interact with the Fabric Port to join multiple fabrics. The port will
  obtain an N_Port_ID on each fabric it joins. Each fabric will have its
  own unique view of endpoints and configuration parameters.  NPIV may be
  used together with VF so that the port can obtain multiple N_Port_IDs
  on each virtual fabric.

  The FC transport is now recognizing a new object - a vport.  A vport is
  an entity that has a world-wide unique World Wide Port Name (wwpn) and
  World Wide Node Name (wwnn). The transport also allows for the FC4's to
  be specified for the vport, with FCP_Initiator being the primary role
  expected. Once instantiated by one of the above methods, it will have a
  distinct N_Port_ID and view of fabric endpoints and storage entities.
  The fc_host associated with the physical adapter will export the ability
  to create vports. The transport will create the vport object within the
  Linux device tree, and instruct the fc_host's driver to instantiate the
  virtual port. Typically, the driver will create a new scsi_host instance
  on the vport, resulting in a unique <H,C,T,L> namespace for the vport.
  Thus, whether a FC port is based on a physical port or on a virtual port,
  each will appear as a unique scsi_host with its own target and lun space.

  .. Note::
    At this time, the transport is written to create only NPIV-based
    vports. However, consideration was given to VF-based vports and it
    should be a minor change to add support if needed.  The remaining
    discussion will concentrate on NPIV.

  .. Note::
    World Wide Name assignment (and uniqueness guarantees) are left
    up to an administrative entity controlling the vport. For example,
    if vports are to be associated with virtual machines, a XEN mgmt
    utility would be responsible for creating wwpn/wwnn's for the vport,
    using its own naming authority and OUI. (Note: it already does this
    for virtual MAC addresses).

장치 트리와 sysfs 배치

119-171

일반 장치 트리에서는 `scsi_host` 아래에 rport와 SCSI target이 있다. FC transport는 물리 adapter의 `scsi_host` 아래에 vport 객체를 만들고, LLDD는 vport 아래에 새 `scsi_host`를 연결한다. 그 아래의 rport, target, LUN 트리는 비-NPIV 구성과 같다.

구현은 vport 부모를 물리 `scsi_host`가 아닌 객체로 바꿀 가능성도 고려한다. 향후 VM 전용 트리에 연결할 수 있으며, 이 경우 물리 포트의 `scsi_host`에는 vport 객체를 가리키는 symbolic link가 놓인다.

원문의 예에서는 물리 `host17` 아래 `vport-17:0-0`을 만들고 그 아래 `host18`을 생성한다. 이후 `host18`의 rport와 target, LUN이 이어진다. class view에서는 `/sys/class/scsi_host`, `/sys/class/fc_host`, `/sys/class/fc_vports`, `/sys/class/fc_remote_ports`에 각각 대응 객체가 나타난다.

vport 장치 트리
physical host17vport-17:0-0virtual host18rport-18:0-0target18:0:018:0:0:0 LUN

물리 포트에서 가상 SCSI 호스트와 원격 장치로 이어지는 계층이다.

Device Trees and Vport Objects:
-------------------------------

  Today, the device tree typically contains the scsi_host object,
  with rports and scsi target objects underneath it. Currently the FC
  transport creates the vport object and places it under the scsi_host
  object corresponding to the physical adapter.  The LLDD will allocate
  a new scsi_host for the vport and link its object under the vport.
  The remainder of the tree under the vports scsi_host is the same
  as the non-NPIV case. The transport is written currently to easily
  allow the parent of the vport to be something other than the scsi_host.
  This could be used in the future to link the object onto a vm-specific
  device tree. If the vport's parent is not the physical port's scsi_host,
  a symbolic link to the vport object will be placed in the physical
  port's scsi_host.

  Here's what to expect in the device tree :

   The typical Physical Port's Scsi_Host::

     /sys/devices/.../host17/

   and it has the typical descendant tree::

     /sys/devices/.../host17/rport-17:0-0/target17:0:0/17:0:0:0:

   and then the vport is created on the Physical Port::

     /sys/devices/.../host17/vport-17:0-0

   and the vport's Scsi_Host is then created::

     /sys/devices/.../host17/vport-17:0-0/host18

   and then the rest of the tree progresses, such as::

     /sys/devices/.../host17/vport-17:0-0/host18/rport-18:0-0/target18:0:0/18:0:0:0:

  Here's what to expect in the sysfs tree::

   scsi_hosts:
     /sys/class/scsi_host/host17                physical port's scsi_host
     /sys/class/scsi_host/host18                vport's scsi_host
   fc_hosts:
     /sys/class/fc_host/host17                  physical port's fc_host
     /sys/class/fc_host/host18                  vport's fc_host
   fc_vports:
     /sys/class/fc_vports/vport-17:0-0          the vport's fc_vport
   fc_rports:
     /sys/class/fc_remote_ports/rport-17:0-0    rport on the physical port
     /sys/class/fc_remote_ports/rport-18:0-0    rport on the vport

vport와 fc_host 속성

172-239

`fc_vport` class 객체의 `node_name`, `port_name`, `roles`, `vport_last_state`, `vport_state`, `vport_type`은 읽기 전용이다. `symbolic_name`은 읽고 쓸 수 있으며, 드라이버의 symbolic port name 뒤에 붙여 switch 관리 화면에서 vport를 식별하게 한다.

`vport_delete`에 `1`을 쓰면 vport를 제거한다. `vport_disable`에 `1`을 쓰면 Linux 커널 객체는 유지하면서 FC 링크에서 비활성화하고, `0`을 쓰면 다시 활성화한다. `vport_type`은 생성에 사용한 FC 메커니즘이며 현재는 NPIV만 지원한다.

`fc_host`에는 읽기 전용 `max_npiv_vports`, `npiv_vports_inuse`가 추가된다. 쓰기 전용 `vport_create`와 `vport_delete`는 `"<WWPN>:<WWNN>"` 형식을 받는다. 각 WWN은 정확히 16개의 16진 문자이고 `0x`, `x` 같은 접두사는 허용되지 않는다. create는 `FCP_Initiator` 역할로 만들고, delete는 같은 WWN의 vport를 찾아 해체한다.

vport sysfs 속성
속성접근의미
node_name / port_nameRead_OnlyWWNN / WWPN
rolesRead_Only활성 FC4 역할
symbolic_nameRead_Writeswitch 표시용 이름
vport_deleteWrite_Only1로 제거
vport_disableWrite_Only1 비활성, 0 활성
vport_last_state / vport_stateRead_Only이전/현재 상태
vport_typeRead_Only현재 NPIV

접근 모드와 핵심 기능을 보존했다.

Vport Attributes
----------------

  The new fc_vport class object has the following attributes

     node_name:                                                 Read_Only
       The WWNN of the vport

     port_name:                                                 Read_Only
       The WWPN of the vport

     roles:                                                     Read_Only
       Indicates the FC4 roles enabled on the vport.

     symbolic_name:                                             Read_Write
       A string, appended to the driver's symbolic port name string, which
       is registered with the switch to identify the vport. For example,
       a hypervisor could set this string to "Xen Domain 2 VM 5 Vport 2",
       and this set of identifiers can be seen on switch management screens
       to identify the port.

     vport_delete:                                              Write_Only
       When written with a "1", will tear down the vport.

     vport_disable:                                             Write_Only
       When written with a "1", will transition the vport to a disabled.
       state.  The vport will still be instantiated with the Linux kernel,
       but it will not be active on the FC link.
       When written with a "0", will enable the vport.

     vport_last_state:                                          Read_Only
       Indicates the previous state of the vport.  See the section below on
       "Vport States".

     vport_state:                                               Read_Only
       Indicates the state of the vport.  See the section below on
       "Vport States".

     vport_type:                                                Read_Only
       Reflects the FC mechanism used to create the virtual port.
       Only NPIV is supported currently.


  For the fc_host class object, the following attributes are added for vports:

     max_npiv_vports:                                           Read_Only
       Indicates the maximum number of NPIV-based vports that the
       driver/adapter can support on the fc_host.

     npiv_vports_inuse:                                         Read_Only
       Indicates how many NPIV-based vports have been instantiated on the
       fc_host.

     vport_create:                                              Write_Only
       A "simple" create interface to instantiate a vport on an fc_host.
       A "<WWPN>:<WWNN>" string is written to the attribute. The transport
       then instantiates the vport object and calls the LLDD to create the
       vport with the role of FCP_Initiator.  Each WWN is specified as 16
       hex characters and may *not* contain any prefixes (e.g. 0x, x, etc).

     vport_delete:                                              Write_Only
        A "simple" delete interface to teardown a vport. A "<WWPN>:<WWNN>"
        string is written to the attribute. The transport will locate the
        vport on the fc_host with the same WWNs and tear it down.  Each WWN
        is specified as 16 hex characters and may *not* contain any prefixes
        (e.g. 0x, x, etc).

vport 생성 단계와 상태 정의

240-307

vport 생성은 두 부분으로 나뉜다. 먼저 커널과 LLDD에서 전송 및 드라이버 자료 구조와 장치 객체를 만든다. 이는 링크 상태와 독립적인 adapter attach에 해당한다. 다음으로 ELS 트래픽 등을 통해 FC 링크에 vport를 실제 생성한다. 이는 link up과 성공적인 링크 초기화에 해당한다.

커널과 LLDD에 vport 객체가 만들어지면 sysfs에서 상태를 보고할 수 있다. `FC_VPORT_INITIALIZING`은 ELS 트래픽을 시작하기 직전부터 성공 또는 실패까지 지속되는 전이 상태이므로 `vport_last_state`에는 보존하지 않는다.

`FC_VPORT_NO_FABRIC_SUPP`는 point-to-point가 아니거나 F_Port에 연결되지 않았거나 F_Port가 NPIV를 지원하지 않을 때 사용한다. `FC_VPORT_NO_FABRIC_RSCS`는 Fabric 자원 부족으로 FDISC가 실패한 경우, `FC_VPORT_FABRIC_LOGOUT`은 Fabric이 N_Port_ID를 LOGO한 경우, `FC_VPORT_FABRIC_REJ_WWN`은 WWN이 유효하지 않다고 거부한 경우다. 나머지 오류는 `FC_VPORT_FAILED`로 묶는다.

vport 상태
상수표시의미
FC_VPORT_UNKNOWNUnknown커널과 LLDD에 객체를 만드는 동안의 임시 상태
FC_VPORT_ACTIVEActiveFC 링크에서 생성되어 완전히 동작함
FC_VPORT_DISABLEDDisabled객체는 있으나 FC 링크에는 나타나지 않음
FC_VPORT_LINKDOWNLinkdown물리 링크가 동작하지 않아 vport도 비동작
FC_VPORT_INITIALIZINGInitializingFDISC 등 ELS 절차 진행 중
FC_VPORT_NO_FABRIC_SUPPNo Fabric Support토폴로지, F_Port 또는 NPIV 지원 조건 불충족
FC_VPORT_NO_FABRIC_RSCSNo Fabric ResourcesFabric에 FDISC 처리 자원이 부족함
FC_VPORT_FABRIC_LOGOUTFabric LogoutFabric이 vport의 N_Port_ID에 LOGO 수행
FC_VPORT_FABRIC_REJ_WWNFabric Rejected WWNFabric이 WWN을 유효하지 않다고 거부
FC_VPORT_FAILEDVPort Failed그 밖의 오류를 포괄하는 실패 상태

상태 상수, 표시 이름과 의미다.

Vport States
------------

  Vport instantiation consists of two parts:

    - Creation with the kernel and LLDD. This means all transport and
      driver data structures are built up, and device objects created.
      This is equivalent to a driver "attach" on an adapter, which is
      independent of the adapter's link state.
    - Instantiation of the vport on the FC link via ELS traffic, etc.
      This is equivalent to a "link up" and successful link initialization.

  Further information can be found in the interfaces section below for
  Vport Creation.

  Once a vport has been instantiated with the kernel/LLDD, a vport state
  can be reported via the sysfs attribute. The following states exist:

    FC_VPORT_UNKNOWN            - Unknown
      An temporary state, typically set only while the vport is being
      instantiated with the kernel and LLDD.

    FC_VPORT_ACTIVE             - Active
      The vport has been successfully been created on the FC link.
      It is fully functional.

    FC_VPORT_DISABLED           - Disabled
      The vport instantiated, but "disabled". The vport is not instantiated
      on the FC link. This is equivalent to a physical port with the
      link "down".

    FC_VPORT_LINKDOWN           - Linkdown
      The vport is not operational as the physical link is not operational.

    FC_VPORT_INITIALIZING       - Initializing
      The vport is in the process of instantiating on the FC link.
      The LLDD will set this state just prior to starting the ELS traffic
      to create the vport. This state will persist until the vport is
      successfully created (state becomes FC_VPORT_ACTIVE) or it fails
      (state is one of the values below).  As this state is transitory,
      it will not be preserved in the "vport_last_state".

    FC_VPORT_NO_FABRIC_SUPP     - No Fabric Support
      The vport is not operational. One of the following conditions were
      encountered:

       - The FC topology is not Point-to-Point
       - The FC port is not connected to an F_Port
       - The F_Port has indicated that NPIV is not supported.

    FC_VPORT_NO_FABRIC_RSCS     - No Fabric Resources
      The vport is not operational. The Fabric failed FDISC with a status
      indicating that it does not have sufficient resources to complete
      the operation.

    FC_VPORT_FABRIC_LOGOUT      - Fabric Logout
      The vport is not operational. The Fabric has LOGO'd the N_Port_ID
      associated with the vport.

    FC_VPORT_FABRIC_REJ_WWN     - Fabric Rejected WWN
      The vport is not operational. The Fabric failed FDISC with a status
      indicating that the WWN's are not valid.

    FC_VPORT_FAILED             - VPort Failed
      The vport is not operational. This is a catchall for all other
      error conditions.

vport 상태 전이

308-364

초기화하면 `Unknown`이 된다. Unknown에서 링크가 내려가면 `Linkdown`, loop 또는 Fabric 없음 또는 FLOGI가 NPIV 미지원을 알리면 `No Fabric Support`, FDISC를 보내기 시작하면 `Initializing`, disable 요청이면 `Disable`로 전이한다.

Linkdown에서 링크가 올라오면 Unknown으로 돌아간다. Initializing에서 FDISC ACC는 Active, 자원 부족 LS_RJT는 No Fabric Resources, 잘못된 pname 또는 nport_id는 Fabric Rejected WWN, 그 밖의 FDISC 거부는 Vport Failed로 간다. 링크 하강과 disable 요청도 각각 Linkdown과 Disable로 간다.

Disable에서 enable 요청을 받으면 Unknown으로 돌아간다. Active에서 Fabric LOGO는 Fabric Logout, 링크 하강은 Linkdown, disable은 Disable로 간다. Fabric Logout에서 링크가 살아 있으면 Unknown으로 돌아간다. No Fabric Support, No Fabric Resources, Fabric Rejected WWN, Vport Failed는 모두 disable 요청에서 Disable, 링크 하강에서 Linkdown으로 전이한다.

핵심 상태 전이
현재 상태사건새 상태
n/aInitializationUnknown
UnknownLink DownLinkdown
UnknownLoop/no Fabric/no NPIVNo Fabric Support
UnknownFDISC being sentInitializing
InitializingFDISC ACCActive
InitializingLS_RJT no resourcesNo Fabric Resources
InitializingLS_RJT invalid WWNFabric Rejected WWN
ActiveFabric LOGOFabric Logout
DisableEnableUnknown
오류 상태Disable / Link downDisable / Linkdown

원문의 ASCII 상태 표를 사건 중심으로 구조화했다.

  The following state table indicates the different state transitions:

   +------------------+--------------------------------+---------------------+
   | State            | Event                          | New State           |
   +==================+================================+=====================+
   | n/a              | Initialization                 | Unknown             |
   +------------------+--------------------------------+---------------------+
   | Unknown:         | Link Down                      | Linkdown            |
   |                  +--------------------------------+---------------------+
   |                  | Link Up & Loop                 | No Fabric Support   |
   |                  +--------------------------------+---------------------+
   |                  | Link Up & no Fabric            | No Fabric Support   |
   |                  +--------------------------------+---------------------+
   |                  | Link Up & FLOGI response       | No Fabric Support   |
   |                  | indicates no NPIV support      |                     |
   |                  +--------------------------------+---------------------+
   |                  | Link Up & FDISC being sent     | Initializing        |
   |                  +--------------------------------+---------------------+
   |                  | Disable request                | Disable             |
   +------------------+--------------------------------+---------------------+
   | Linkdown:        | Link Up                        | Unknown             |
   +------------------+--------------------------------+---------------------+
   | Initializing:    | FDISC ACC                      | Active              |
   |                  +--------------------------------+---------------------+
   |                  | FDISC LS_RJT w/ no resources   | No Fabric Resources |
   |                  +--------------------------------+---------------------+
   |                  | FDISC LS_RJT w/ invalid        | Fabric Rejected WWN |
   |                      | pname or invalid nport_id      |                     |
   |                  +--------------------------------+---------------------+
   |                  | FDISC LS_RJT failed for        | Vport Failed        |
   |                  | other reasons                  |                     |
   |                  +--------------------------------+---------------------+
   |                  | Link Down                      | Linkdown            |
   |                  +--------------------------------+---------------------+
   |                  | Disable request                | Disable             |
   +------------------+--------------------------------+---------------------+
   | Disable:         | Enable request                 | Unknown             |
   +------------------+--------------------------------+---------------------+
   | Active:          | LOGO received from fabric      | Fabric Logout       |
   |                  +--------------------------------+---------------------+
   |                  | Link Down                      | Linkdown            |
   |                  +--------------------------------+---------------------+
   |                  | Disable request                | Disable             |
   +------------------+--------------------------------+---------------------+
   | Fabric Logout:   | Link still up                  | Unknown             |
   +------------------+--------------------------------+---------------------+

The following 4 error states all have the same transitions::

    No Fabric Support:
    No Fabric Resources:
    Fabric Rejected WWN:
    Vport Failed:
                        Disable request                 Disable
                        Link goes down                  Linkdown

LLDD의 vport 지원 선언

365-377

LLDD는 transport template에 `vport_create()`를 제공해 vport 지원을 알린다. 이 함수가 있으면 FC transport가 `fc_host`에 새 속성을 만든다. 물리 포트 초기화를 마칠 때 드라이버는 `max_npiv_vports`를 설정해 드라이버 또는 adapter가 지원하는 최대 vport 수를 알려야 한다.

Transport <-> LLDD Interfaces
-----------------------------

Vport support by LLDD:

  The LLDD indicates support for vports by supplying a vport_create()
  function in the transport template.  The presence of this function will
  cause the creation of the new attributes on the fc_host.  As part of
  the physical port completing its initialization relative to the
  transport, it should set the max_npiv_vports attribute to indicate the
  maximum number of vports the driver and/or adapter supports.

vport 생성 인터페이스와 오류

378-450

LLDD 생성 함수의 원형은 `int vport_create(struct fc_vport *vport, bool disable)`이다. `vport`는 새로 할당한 객체이고, `disable`이 true이면 비활성 상태로 만들며 false이면 생성과 함께 활성화한다.

sgio/netlink 또는 `fc_host`의 `vport_create` 속성으로 요청하면 전송 계층은 `max_npiv_vports > npiv_vports_inuse` 같은 조건으로 여유를 확인한다. 가능하면 사용 수를 증가시키고 객체를 만든 뒤 LLDD 함수에 넘긴다.

LLDD 함수는 링크 쪽 생성까지 동기적으로 기다리지 않는다. NPIV 기반 구조가 있는지 검증하고 자료 구조를 만드는 첫 단계를 마친 뒤 반환해야 한다. 링크가 내려가 있어도 그 자체는 실패가 아니고, 비활성 상태로 생성할 수도 있으며, adapter attach가 링크 상태와 독립적이라는 모델과 일치하기 때문이다.

기반 구조가 다른 vport를 지원하지 못하면 `VPCERR_UNSUPPORTED`, 기존 WWN과 겹치면 `VPCERR_BAD_WWN`, loop나 non-fabric 또는 NPIV 미지원 FLOGI면 `VPCERR_NO_FABRIC_SUPP`를 반환한다. 메모리 부족 등 자료 구조 할당 오류에는 해당 음수 `Exxx` 코드를 반환한다.

역할이 FCP Initiator이면 `scsi_host_alloc()`으로 host를 만들고 `scsi_add_host(new_shost, &vport->dev)`로 vport 자식에 연결한 뒤 `fc_host` 속성을 초기화한다. 마지막으로 disable flag와 링크 상태에 따라 후속 상태 전이를 시작하고 0을 반환한다.

vport_create 특별 오류
오류조건
VPCERR_UNSUPPORTEDfirmware, max_npiv 또는 자원 때문에 추가 vport 불가
VPCERR_BAD_WWN활성 WWN과 중복
VPCERR_NO_FABRIC_SUPPloop/non-fabric/NPIV 미지원
-Exxx메모리 등 일반 할당 오류

기반 구조 실패를 빠르게 구분하는 반환값이다.

Vport Creation:

  The LLDD vport_create() syntax is::

      int vport_create(struct fc_vport *vport, bool disable)

  where:

      =======   ===========================================================
      vport     Is the newly allocated vport object
      disable   If "true", the vport is to be created in a disabled stated.
                If "false", the vport is to be enabled upon creation.
      =======   ===========================================================

  When a request is made to create a new vport (via sgio/netlink, or the
  vport_create fc_host attribute), the transport will validate that the LLDD
  can support another vport (e.g. max_npiv_vports > npiv_vports_inuse).
  If not, the create request will be failed.  If space remains, the transport
  will increment the vport count, create the vport object, and then call the
  LLDD's vport_create() function with the newly allocated vport object.

  As mentioned above, vport creation is divided into two parts:

    - Creation with the kernel and LLDD. This means all transport and
      driver data structures are built up, and device objects created.
      This is equivalent to a driver "attach" on an adapter, which is
      independent of the adapter's link state.
    - Instantiation of the vport on the FC link via ELS traffic, etc.
      This is equivalent to a "link up" and successful link initialization.

  The LLDD's vport_create() function will not synchronously wait for both
  parts to be fully completed before returning. It must validate that the
  infrastructure exists to support NPIV, and complete the first part of
  vport creation (data structure build up) before returning.  We do not
  hinge vport_create() on the link-side operation mainly because:

    - The link may be down. It is not a failure if it is. It simply
      means the vport is in an inoperable state until the link comes up.
      This is consistent with the link bouncing post vport creation.
    - The vport may be created in a disabled state.
    - This is consistent with a model where:  the vport equates to a
      FC adapter. The vport_create is synonymous with driver attachment
      to the adapter, which is independent of link state.

  .. Note::

      special error codes have been defined to delineate infrastructure
      failure cases for quicker resolution.

  The expected behavior for the LLDD's vport_create() function is:

    - Validate Infrastructure:

        - If the driver or adapter cannot support another vport, whether
            due to improper firmware, (a lie about) max_npiv, or a lack of
            some other resource - return VPCERR_UNSUPPORTED.
        - If the driver validates the WWN's against those already active on
            the adapter and detects an overlap - return VPCERR_BAD_WWN.
        - If the driver detects the topology is loop, non-fabric, or the
            FLOGI did not support NPIV - return VPCERR_NO_FABRIC_SUPP.

    - Allocate data structures. If errors are encountered, such as out
        of memory conditions, return the respective negative Exxx error code.
    - If the role is FCP Initiator, the LLDD is to :

        - Call scsi_host_alloc() to allocate a scsi_host for the vport.
        - Call scsi_add_host(new_shost, &vport->dev) to start the scsi_host
          and bind it as a child of the vport device.
        - Initializes the fc_host attribute values.

    - Kick of further vport state transitions based on the disable flag and
        link state - and return success (zero).

LLDD 구현 권고

451-463

물리 포트와 가상 포트에는 서로 다른 `fc_function_templates`를 쓰는 것이 권장된다. 물리 포트 템플릿은 `vport_create`, `vport_delete`, `vport_disable`을 제공하지만 vport 템플릿에는 제공하지 않는다.

`scsi_host_templates`도 물리 포트와 가상 포트용을 구분하는 편이 좋다. 링크 속도나 토폴로지 설정처럼 물리 포트에만 적용되는 드라이버 속성이 올바른 `scsi_host`에만 나타나게 할 수 있다.

  LLDD Implementers Notes:

  - It is suggested that there be a different fc_function_templates for
    the physical port and the virtual port.  The physical port's template
    would have the vport_create, vport_delete, and vport_disable functions,
    while the vports would not.
  - It is suggested that there be different scsi_host_templates
    for the physical port and virtual port. Likely, there are driver
    attributes, embedded into the scsi_host_template, that are applicable
    for the physical port only (link speed, topology setting, etc). This
    ensures that the attributes are applicable to the respective scsi_host.

vport 비활성화와 재활성화

464-494

인터페이스 원형은 `int vport_disable(struct fc_vport *vport, bool disable)`이다. true는 비활성화, false는 활성화를 뜻한다. 전송 계층은 현재 상태와 요청을 비교해 이미 비활성인 vport에 다시 disable을 요청하거나 비활성 상태가 아닌 vport에 enable을 요청하면 실패시킨다.

유효한 요청은 LLDD에 전달한다. 비활성화된 vport는 커널과 LLDD 객체를 유지하지만 FC 링크에는 전혀 활성 또는 가시 상태가 아니다. 삭제하거나 다시 활성화할 때까지 유지되며, 활성화하면 LLDD가 FC 링크에 vport를 다시 만들고 상태 기계를 재시작한다.

Vport Disable/Enable:

  The LLDD vport_disable() syntax is::

      int vport_disable(struct fc_vport *vport, bool disable)

  where:

      =======   =======================================
      vport     Is vport to be enabled or disabled
      disable   If "true", the vport is to be disabled.
                If "false", the vport is to be enabled.
      =======   =======================================

  When a request is made to change the disabled state on a vport, the
  transport will validate the request against the existing vport state.
  If the request is to disable and the vport is already disabled, the
  request will fail. Similarly, if the request is to enable, and the
  vport is not in a disabled state, the request will fail.  If the request
  is valid for the vport state, the transport will call the LLDD to
  change the vport's state.

  Within the LLDD, if a vport is disabled, it remains instantiated with
  the kernel and LLDD, but it is not active or visible on the FC link in
  any way. (see Vport Creation and the 2 part instantiation discussion).
  The vport will remain in this state until it is deleted or re-enabled.
  When enabling a vport, the LLDD reinstantiates the vport on the FC
  link - essentially restarting the LLDD statemachine (see Vport States
  above).

vport 삭제, port_type과 드라이버 제거

495-534

삭제 함수는 `int vport_delete(struct fc_vport *vport)`이다. sgio/netlink 또는 sysfs 속성으로 삭제를 요청하면 전송 계층이 LLDD에 FC 링크의 vport 종료와 자료 구조 및 참조 해체를 맡긴다. 성공하면 전송 계층이 객체 제거를 끝내고, 실패하면 객체는 남지만 상태는 확정할 수 없다.

FCP Initiator 역할이면 일반 `scsi_host` 해체 경로를 따라 `fc_remove_host()`, `scsi_remove_host()`, `scsi_host_put()` 순으로 호출한다.

vport 기반 `fc_host`의 `port_type`은 `FC_PORTTYPE_NPIV`여야 한다. 물리 포트의 NPORT, NLPORT 같은 토폴로지 값 대신 포트를 만든 FC 메커니즘을 보고하는 것이 적절하다. FC 드라이버는 `scsi_remove_host()` 전에 `fc_remove_host()`를 호출해 원격 포트와 해당 host의 모든 vport를 먼저 제거해야 한다.

Vport Deletion:

  The LLDD vport_delete() syntax is::

      int vport_delete(struct fc_vport *vport)

  where:

      vport:    Is vport to delete

  When a request is made to delete a vport (via sgio/netlink, or via the
  fc_host or fc_vport vport_delete attributes), the transport will call
  the LLDD to terminate the vport on the FC link, and teardown all other
  datastructures and references.  If the LLDD completes successfully,
  the transport will teardown the vport objects and complete the vport
  removal.  If the LLDD delete request fails, the vport object will remain,
  but will be in an indeterminate state.

  Within the LLDD, the normal code paths for a scsi_host teardown should
  be followed. E.g. If the vport has a FCP Initiator role, the LLDD
  will call fc_remove_host() for the vports scsi_host, followed by
  scsi_remove_host() and scsi_host_put() for the vports scsi_host.


Other:
  fc_host port_type attribute:
    There is a new fc_host port_type value - FC_PORTTYPE_NPIV. This value
    must be set on all vport-based fc_hosts.  Normally, on a physical port,
    the port_type attribute would be set to NPORT, NLPORT, etc based on the
    topology type and existence of the fabric. As this is not applicable to
    a vport, it makes more sense to report the FC mechanism used to create
    the vport.

  Driver unload:
    FC drivers are required to call fc_remove_host() prior to calling
    scsi_remove_host().  This allows the fc_host to tear down all remote
    ports prior the scsi_host being torn down.  The fc_remove_host() call
    was updated to remove all vports for the fc_host as well.

전송 계층 제공 함수

535-572

FC transport는 LLD가 사용할 `fc_vport_create`와 `fc_vport_terminate`를 제공한다. `fc_vport_create(struct Scsi_Host *shost, struct fc_vport_identifiers *ids)`는 관리 응용 프로그램이나 LLDD 요청으로 vport를 만들며, 진입 시 잠금이 잡혀 있지 않다고 가정한다. `ids`에는 WWN과 FC4 역할 등이 들어간다.

`fc_vport_terminate(struct fc_vport *vport)`는 LLDD의 `vport_delete()`를 호출한 뒤 해당 vport를 `shost`와 객체 트리에서 제거하고 메모리를 해제한다. 이 함수도 진입 시 잠금이 잡혀 있지 않다고 가정한다.

FC transport 제공 함수
함수기능
fc_vport_createvport 생성
fc_vport_terminatevport 분리 및 제거

LLD에서 사용하는 두 공개 작업이다.

Transport supplied functions
----------------------------

The following functions are supplied by the FC-transport for use by LLDs.

   ==================   =========================
   fc_vport_create      create a vport
   fc_vport_terminate   detach and remove a vport
   ==================   =========================

Details::

    /**
    * fc_vport_create - Admin App or LLDD requests creation of a vport
    * @shost:     scsi host the virtual port is connected to.
    * @ids:       The world wide names, FC4 port roles, etc for
    *              the virtual port.
    *
    * Notes:
    *     This routine assumes no locks are held on entry.
    */
    struct fc_vport *
    fc_vport_create(struct Scsi_Host *shost, struct fc_vport_identifiers *ids)

    /**
    * fc_vport_terminate - Admin App or LLDD requests termination of a vport
    * @vport:      fc_vport to be terminated
    *
    * Calls the LLDD vport_delete() function, then deallocates and removes
    * the vport from the shost and object tree.
    *
    * Notes:
    *      This routine assumes no locks are held on entry.
    */
    int
    fc_vport_terminate(struct fc_vport *vport)

FC BSG 지원과 기여자

573-593

CT와 ELS passthrough 등을 포함한 FC BSG 지원 절은 원문에서 아직 `<< To Be Supplied >>`로 남아 있어 세부 내용이 제공되지 않는다.

문서 기여자로 James Smart와 `james.smart@broadcom.com`이 기록되어 있다.

FC BSG support (CT & ELS passthru, and more)
============================================

<< To Be Supplied >>





Credits
=======
The following people have contributed to this document:






James Smart
james.smart@broadcom.com