요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
.. _phy_link_topology:
=================
PHY link topology
=================
Overview
========
The PHY link topology representation in the networking stack aims at representing
the hardware layout for any given Ethernet link.
An Ethernet interface from userspace's point of view is nothing but a
:c:type:`struct net_device <net_device>`, which exposes configuration options
through the legacy ioctls and the ethtool netlink commands. The base assumption
when designing these configuration APIs were that the link looks something like ::
+-----------------------+ +----------+ +--------------+
| Ethernet Controller / | | Ethernet | | Connector / |
| MAC | ------ | PHY | ---- | Port | ---... to LP
+-----------------------+ +----------+ +--------------+
struct net_device struct phy_device
Commands that needs to configure the PHY will go through the net_device.phydev
field to reach the PHY and perform the relevant configuration.
This assumption falls apart in more complex topologies that can arise when,
for example, using SFP transceivers (although that's not the only specific case).
Here, we have 2 basic scenarios. Either the MAC is able to output a serialized
interface, that can directly be fed to an SFP cage, such as SGMII, 1000BaseX,
10GBaseR, etc.
The link topology then looks like this (when an SFP module is inserted) ::
+-----+ SGMII +------------+
| MAC | ------- | SFP Module |
+-----+ +------------+
Knowing that some modules embed a PHY, the actual link is more like ::
+-----+ SGMII +--------------+
| MAC | -------- | PHY (on SFP) |
+-----+ +--------------+
In this case, the SFP PHY is handled by phylib, and registered by phylink through
its SFP upstream ops.
Now some Ethernet controllers aren't able to output a serialized interface, so
we can't directly connect them to an SFP cage. However, some PHYs can be used
as media-converters, to translate the non-serialized MAC MII interface to a
serialized MII interface fed to the SFP ::
+-----+ RGMII +-----------------------+ SGMII +--------------+
| MAC | ------- | PHY (media converter) | ------- | PHY (on SFP) |
+-----+ +-----------------------+ +--------------+
This is where the model of having a single net_device.phydev pointer shows its
limitations, as we now have 2 PHYs on the link.
The phy_link topology framework aims at providing a way to keep track of every
PHY on the link, for use by both kernel drivers and subsystems, but also to
report the topology to userspace, allowing to target individual PHYs in configuration
commands.
API
===
The :c:type:`struct phy_link_topology <phy_link_topology>` is a per-netdevice
resource, that gets initialized at netdevice creation. Once it's initialized,
it is then possible to register PHYs to the topology through :
:c:func:`phy_link_topo_add_phy`
Besides registering the PHY to the topology, this call will also assign a unique
index to the PHY, which can then be reported to userspace to refer to this PHY
(akin to the ifindex). This index is a u32, ranging from 1 to U32_MAX. The value
0 is reserved to indicate the PHY doesn't belong to any topology yet.
The PHY can then be removed from the topology through
:c:func:`phy_link_topo_del_phy`
These function are already hooked into the phylib subsystem, so all PHYs that
are linked to a net_device through :c:func:`phy_attach_direct` will automatically
join the netdev's topology.
PHYs that are on a SFP module will also be automatically registered IF the SFP
upstream is phylink (so, no media-converter).
PHY drivers that can be used as SFP upstream need to call :c:func:`phy_sfp_attach_phy`
and :c:func:`phy_sfp_detach_phy`, which can be used as a
.attach_phy / .detach_phy implementation for the
:c:type:`struct sfp_upstream_ops <sfp_upstream_ops>`.
UAPI
====
There exist a set of netlink commands to query the link topology from userspace,
see ``Documentation/networking/ethtool-netlink.rst``.
The whole point of having a topology representation is to assign the phyindex
field in :c:type:`struct phy_device <phy_device>`. This index is reported to
userspace using the ``ETHTOOL_MSG_PHY_GET`` ethtnl command. Performing a DUMP operation
will result in all PHYs from all net_device being listed. The DUMP command
accepts either a ``ETHTOOL_A_HEADER_DEV_INDEX`` or ``ETHTOOL_A_HEADER_DEV_NAME``
to be passed in the request to filter the DUMP to a single net_device.
The retrieved index can then be passed as a request parameter using the
``ETHTOOL_A_HEADER_PHY_INDEX`` field in the following ethnl commands :
* ``ETHTOOL_MSG_STRSET_GET`` to get the stats string set from a given PHY
* ``ETHTOOL_MSG_CABLE_TEST_ACT`` and ``ETHTOOL_MSG_CABLE_TEST_ACT``, to perform
cable testing on a given PHY on the link (most likely the outermost PHY)
* ``ETHTOOL_MSG_PSE_SET`` and ``ETHTOOL_MSG_PSE_GET`` for PHY-controlled PoE and PSE settings
* ``ETHTOOL_MSG_PLCA_GET_CFG``, ``ETHTOOL_MSG_PLCA_SET_CFG`` and ``ETHTOOL_MSG_PLCA_GET_STATUS``
to set the PLCA (Physical Layer Collision Avoidance) parameters
Note that the PHY index can be passed to other requests, which will silently
ignore it if present and irrelevant.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
기본 Ethernet 링크 모델과 한계
1-26네트워킹 스택의 PHY 링크 토폴로지 표현은 특정 Ethernet 링크를 구성하는 실제 하드웨어 배치를 나타내기 위한 것입니다. 사용자 공간에서 Ethernet 인터페이스는 구성 옵션을 제공하는 `struct net_device`로 보입니다. 이 옵션은 기존 ioctl과 ethtool Netlink 명령을 통해 노출됩니다.
이 구성 API를 설계할 때에는 링크가 Ethernet controller 또는 MAC, Ethernet PHY, connector 또는 port 순서로 이어진다고 가정했습니다. 이때 `struct net_device`는 MAC 쪽을, `struct phy_device`는 단일 PHY를 나타냅니다. PHY를 설정해야 하는 명령은 `net_device.phydev` 필드를 따라 PHY에 도달하여 필요한 작업을 수행합니다.
그러나 SFP transceiver처럼 링크 구조가 복잡해지면 이 가정은 더 이상 성립하지 않습니다. SFP만이 유일한 사례는 아니지만, 하나의 `phydev` 포인터로는 링크에 참여하는 여러 PHY와 그 순서를 구분할 수 없다는 문제가 가장 분명하게 드러납니다.
구성 명령은 net_device.phydev를 통해 한 개의 PHY에 도달합니다.
사용자 공간 인터페이스와 물리 링크 객체의 대응입니다.
.. SPDX-License-Identifier: GPL-2.0
.. _phy_link_topology:
=================
PHY link topology
=================
Overview
========
The PHY link topology representation in the networking stack aims at representing
the hardware layout for any given Ethernet link.
An Ethernet interface from userspace's point of view is nothing but a
:c:type:`struct net_device <net_device>`, which exposes configuration options
through the legacy ioctls and the ethtool netlink commands. The base assumption
when designing these configuration APIs were that the link looks something like ::
+-----------------------+ +----------+ +--------------+
| Ethernet Controller / | | Ethernet | | Connector / |
| MAC | ------ | PHY | ---- | Port | ---... to LP
+-----------------------+ +----------+ +--------------+
struct net_device struct phy_device
Commands that needs to configure the PHY will go through the net_device.phydev
field to reach the PHY and perform the relevant configuration.
직렬 인터페이스와 SFP 내장 PHY
27-51복잡한 링크에는 두 가지 기본 시나리오가 있습니다. 첫 번째는 MAC이 `SGMII`, `1000BaseX`, `10GBaseR` 같은 직렬화된 인터페이스를 출력할 수 있어 SFP cage에 직접 연결되는 경우입니다.
SFP module을 삽입하면 겉보기 링크는 MAC에서 SGMII를 거쳐 SFP module로 이어집니다. 하지만 일부 module에는 PHY가 내장되어 있으므로 실제 물리 계층은 MAC에서 SGMII를 거쳐 SFP 위의 PHY로 연결된 형태입니다.
이 경우 SFP PHY는 phylib가 관리합니다. phylink는 자신의 SFP upstream operation을 통해 해당 PHY를 등록합니다. 따라서 module 내부 PHY도 링크 토폴로지에서 독립적으로 식별할 수 있어야 합니다.
MAC이 직렬 인터페이스를 직접 출력할 수 있는 배치입니다.
This assumption falls apart in more complex topologies that can arise when,
for example, using SFP transceivers (although that's not the only specific case).
Here, we have 2 basic scenarios. Either the MAC is able to output a serialized
interface, that can directly be fed to an SFP cage, such as SGMII, 1000BaseX,
10GBaseR, etc.
The link topology then looks like this (when an SFP module is inserted) ::
+-----+ SGMII +------------+
| MAC | ------- | SFP Module |
+-----+ +------------+
Knowing that some modules embed a PHY, the actual link is more like ::
+-----+ SGMII +--------------+
| MAC | -------- | PHY (on SFP) |
+-----+ +--------------+
In this case, the SFP PHY is handled by phylib, and registered by phylink through
its SFP upstream ops.
Now some Ethernet controllers aren't able to output a serialized interface, so
we can't directly connect them to an SFP cage. However, some PHYs can be used
미디어 컨버터와 다중 PHY 토폴로지
52-75두 번째 시나리오는 Ethernet controller가 직렬화된 인터페이스를 출력하지 못해 SFP cage에 직접 연결할 수 없는 경우입니다. 이때 일부 PHY를 media converter로 사용하여 MAC의 비직렬 MII 인터페이스를 SFP에 공급할 직렬 MII 인터페이스로 변환할 수 있습니다.
대표적인 배치는 MAC에서 `RGMII`로 media-converter PHY에 연결하고, 그 PHY가 `SGMII`로 SFP module 안의 PHY에 연결되는 형태입니다. 이제 링크에는 PHY가 두 개 있으므로 단일 `net_device.phydev` 포인터 모델의 한계가 나타납니다.
`phy_link` 토폴로지 프레임워크는 링크의 모든 PHY를 추적하는 방법을 제공합니다. 커널 driver와 subsystem이 이 정보를 사용할 수 있을 뿐 아니라 사용자 공간에도 토폴로지를 보고할 수 있으므로, 구성 명령에서 개별 PHY를 지정할 수 있습니다.
비직렬 MAC 인터페이스를 SFP용 직렬 인터페이스로 변환합니다.
단일 phydev 모델과 다중 PHY 모델의 차이입니다.
as media-converters, to translate the non-serialized MAC MII interface to a
serialized MII interface fed to the SFP ::
+-----+ RGMII +-----------------------+ SGMII +--------------+
| MAC | ------- | PHY (media converter) | ------- | PHY (on SFP) |
+-----+ +-----------------------+ +--------------+
This is where the model of having a single net_device.phydev pointer shows its
limitations, as we now have 2 PHYs on the link.
The phy_link topology framework aims at providing a way to keep track of every
PHY on the link, for use by both kernel drivers and subsystems, but also to
report the topology to userspace, allowing to target individual PHYs in configuration
commands.
API
===
The :c:type:`struct phy_link_topology <phy_link_topology>` is a per-netdevice
resource, that gets initialized at netdevice creation. Once it's initialized,
it is then possible to register PHYs to the topology through :
:c:func:`phy_link_topo_add_phy`
등록 API와 phyindex 할당
76-99`struct phy_link_topology`는 netdevice마다 존재하는 자원이며 netdevice를 만들 때 초기화됩니다. 초기화 뒤에는 `phy_link_topo_add_phy`를 호출하여 PHY를 토폴로지에 등록할 수 있습니다.
`phy_link_topo_add_phy`는 PHY를 등록하는 동시에 고유한 index를 할당합니다. 이 index는 인터페이스의 ifindex와 비슷하게 사용자 공간에서 특정 PHY를 가리키는 데 사용됩니다. 형식은 `u32`이고 유효 범위는 1부터 `U32_MAX`까지입니다. 값 0은 아직 어떤 토폴로지에도 속하지 않은 PHY를 뜻하도록 예약되어 있습니다.
PHY는 `phy_link_topo_del_phy`를 통해 토폴로지에서 제거할 수 있습니다. 이 함수들은 이미 phylib subsystem에 연결되어 있으므로 `phy_attach_direct`를 통해 `net_device`에 연결한 모든 PHY는 자동으로 해당 netdev의 토폴로지에 참여합니다.
SFP module 위의 PHY도 SFP upstream이 phylink인 경우 자동 등록됩니다. 즉 media converter가 없는 직접 연결 경로가 이에 해당합니다.
SFP upstream으로 사용할 수 있는 PHY driver는 `phy_sfp_attach_phy`와 `phy_sfp_detach_phy`를 호출해야 합니다. 이 함수는 `struct sfp_upstream_ops`의 `.attach_phy`와 `.detach_phy` 구현으로 사용할 수 있습니다.
등록 경로와 index 의미를 정리합니다.
Besides registering the PHY to the topology, this call will also assign a unique
index to the PHY, which can then be reported to userspace to refer to this PHY
(akin to the ifindex). This index is a u32, ranging from 1 to U32_MAX. The value
0 is reserved to indicate the PHY doesn't belong to any topology yet.
The PHY can then be removed from the topology through
:c:func:`phy_link_topo_del_phy`
These function are already hooked into the phylib subsystem, so all PHYs that
are linked to a net_device through :c:func:`phy_attach_direct` will automatically
join the netdev's topology.
PHYs that are on a SFP module will also be automatically registered IF the SFP
upstream is phylink (so, no media-converter).
PHY drivers that can be used as SFP upstream need to call :c:func:`phy_sfp_attach_phy`
and :c:func:`phy_sfp_detach_phy`, which can be used as a
.attach_phy / .detach_phy implementation for the
:c:type:`struct sfp_upstream_ops <sfp_upstream_ops>`.
UAPI
====
ethtool Netlink UAPI
100-121사용자 공간에서 링크 토폴로지를 조회하는 Netlink 명령 집합이 있으며 자세한 내용은 `Documentation/networking/ethtool-netlink.rst`에 있습니다.
토폴로지 표현의 핵심 목적은 `struct phy_device`의 `phyindex` 필드를 할당하는 것입니다. 이 index는 ethtool Netlink의 `ETHTOOL_MSG_PHY_GET` 명령으로 사용자 공간에 보고됩니다. DUMP 작업을 수행하면 모든 `net_device`에 속한 모든 PHY가 나열됩니다.
DUMP 요청에 `ETHTOOL_A_HEADER_DEV_INDEX` 또는 `ETHTOOL_A_HEADER_DEV_NAME`을 전달하면 결과를 하나의 `net_device`로 제한할 수 있습니다. 조회한 index는 이후 요청의 `ETHTOOL_A_HEADER_PHY_INDEX` 필드에 넣어 링크의 특정 PHY를 대상으로 삼습니다.
`ETHTOOL_MSG_STRSET_GET`은 지정한 PHY의 통계 문자열 집합을 가져옵니다. 원문에 나열된 `ETHTOOL_MSG_CABLE_TEST_ACT` 명령은 링크의 PHY, 대개 가장 바깥쪽 PHY에서 cable test를 수행합니다. 원문에는 같은 명령 이름이 두 번 적혀 있으며 그대로 보존했습니다.
`ETHTOOL_MSG_PSE_SET`과 `ETHTOOL_MSG_PSE_GET`은 PHY가 제어하는 PoE 및 PSE 설정에 사용됩니다. `ETHTOOL_MSG_PLCA_GET_CFG`, `ETHTOOL_MSG_PLCA_SET_CFG`, `ETHTOOL_MSG_PLCA_GET_STATUS`는 PLCA(Physical Layer Collision Avoidance) 매개변수를 조회·설정하고 상태를 가져옵니다.
PHY index를 다른 요청에 전달할 수도 있습니다. 다만 그 요청에서 index가 관련이 없으면 오류를 내지 않고 조용히 무시합니다.
ETHTOOL_A_HEADER_PHY_INDEX로 개별 PHY를 선택합니다.
netdevice로 DUMP를 필터링한 뒤 phyindex를 후속 명령에 전달합니다.
There exist a set of netlink commands to query the link topology from userspace,
see ``Documentation/networking/ethtool-netlink.rst``.
The whole point of having a topology representation is to assign the phyindex
field in :c:type:`struct phy_device <phy_device>`. This index is reported to
userspace using the ``ETHTOOL_MSG_PHY_GET`` ethtnl command. Performing a DUMP operation
will result in all PHYs from all net_device being listed. The DUMP command
accepts either a ``ETHTOOL_A_HEADER_DEV_INDEX`` or ``ETHTOOL_A_HEADER_DEV_NAME``
to be passed in the request to filter the DUMP to a single net_device.
The retrieved index can then be passed as a request parameter using the
``ETHTOOL_A_HEADER_PHY_INDEX`` field in the following ethnl commands :
* ``ETHTOOL_MSG_STRSET_GET`` to get the stats string set from a given PHY
* ``ETHTOOL_MSG_CABLE_TEST_ACT`` and ``ETHTOOL_MSG_CABLE_TEST_ACT``, to perform
cable testing on a given PHY on the link (most likely the outermost PHY)
* ``ETHTOOL_MSG_PSE_SET`` and ``ETHTOOL_MSG_PSE_GET`` for PHY-controlled PoE and PSE settings
* ``ETHTOOL_MSG_PLCA_GET_CFG``, ``ETHTOOL_MSG_PLCA_SET_CFG`` and ``ETHTOOL_MSG_PLCA_GET_STATUS``
to set the PLCA (Physical Layer Collision Avoidance) parameters
Note that the PHY index can be passed to other requests, which will silently
ignore it if present and irrelevant.
요약·해설
phy-link-topology.rst:1-121PHY 링크 토폴로지는 `net_device` 하나에 PHY 하나만 연결된다는 오래된 가정을 확장합니다. SFP 내장 PHY와 media-converter PHY가 연속된 링크의 모든 PHY를 등록하고 고유한 `phyindex`를 부여하여, kernel driver와 ethtool Netlink 사용자가 정확한 PHY를 조회하고 설정할 수 있게 합니다.
하드웨어 등록부터 사용자 공간 구성까지의 관계입니다.