Skip to content

Commit

Permalink
Add support of mdio IPC server class using sai switch api and unix so…
Browse files Browse the repository at this point in the history
…cket (sonic-net#1080)

Why I did it
When MDIO devices (external PHYs) are connected on MDIO bus from NPU, the MDIO access is through SAI switch mdio read/write APIs. The syncd calling the SAI APIs needs to act as an IPC server so that the gbsyncd programming the MDIO devices can use the APIs by the IPC mechanism.

How I did it
MdioIpcServer class is added to start a new thread, to create an unix socket, to listen on the socket, to accept connection and to read/reply IPC messages. The corresponding functions for MDIO clause 45 and clause 22 access are also added to VendorSai class.

How to verify it
We can use socat to simulate the IPC client, e.g.
docker exec -it syncd socat - UNIX-CONNECT:/var/run/sswsyncd/mdio-ipc.srv
to read MDIO clause 45 register at an address and an offset
mdio <address> <reg offset>
to write MDIO clause 45 register at an address and an offset with a value
mdio <address> <reg offset> <value>
to read MDIO clause 22 register at an address and an offset
mdio-cl22 <address> <reg offset>
to write MDIO clause 22 register at an address and an offset with a value
mdio-cl22 <address> <reg offset> <value>

Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
  • Loading branch information
jiahua-wang authored Jul 28, 2022
1 parent 513cb2a commit 854d54e
Show file tree
Hide file tree
Showing 11 changed files with 728 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ AX_CODE_COVERAGE
AX_ADD_AM_MACRO_STATIC([])

AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BAREFOOT, test x$CONFIGURED_PLATFORM = xbarefoot)
AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BROADCOM, test x$CONFIGURED_PLATFORM = xbroadcom)

AC_ARG_ENABLE(debug,
[ --enable-debug turn on debugging],
Expand Down
48 changes: 48 additions & 0 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,51 @@ sai_status_t SaiInterface::get(
return SAI_STATUS_FAILURE;
}
}

sai_status_t SaiInterface::switchMdioRead(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_Out_ uint32_t *reg_val)
{
SWSS_LOG_ENTER();

return SAI_STATUS_FAILURE;
}

sai_status_t SaiInterface::switchMdioWrite(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_In_ const uint32_t *reg_val)
{
SWSS_LOG_ENTER();

return SAI_STATUS_FAILURE;
}

sai_status_t SaiInterface::switchMdioCl22Read(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_Out_ uint32_t *reg_val)
{
SWSS_LOG_ENTER();

return SAI_STATUS_FAILURE;
}

sai_status_t SaiInterface::switchMdioCl22Write(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_In_ const uint32_t *reg_val)
{
SWSS_LOG_ENTER();

return SAI_STATUS_FAILURE;
}
28 changes: 28 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,34 @@ namespace sairedis
_In_ uint32_t attrCount,
_In_ const sai_attribute_t *attrList) = 0;

virtual sai_status_t switchMdioRead(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_Out_ uint32_t *reg_val);

virtual sai_status_t switchMdioWrite(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_In_ const uint32_t *reg_val);

virtual sai_status_t switchMdioCl22Read(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_Out_ uint32_t *reg_val);

virtual sai_status_t switchMdioCl22Write(
_In_ sai_object_id_t switch_id,
_In_ uint32_t device_addr,
_In_ uint32_t start_reg_addr,
_In_ uint32_t number_of_registers,
_In_ const uint32_t *reg_val);

public: // SAI API

virtual sai_status_t objectTypeGetAvailability(
Expand Down
5 changes: 5 additions & 0 deletions syncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ libSyncd_a_SOURCES = \
FlexCounterManager.cpp \
GlobalSwitchId.cpp \
HardReiniter.cpp \
MdioIpcServer.cpp \
MetadataLogger.cpp \
NotificationHandler.cpp \
NotificationProcessor.cpp \
Expand Down Expand Up @@ -71,6 +72,10 @@ syncd_CXXFLAGS += -DSAITHRIFT=yes
syncd_LDADD += -lrpcserver -lthrift
endif

if SONIC_ASIC_PLATFORM_BROADCOM
libSyncd_a_CXXFLAGS += -DMDIO_ACCESS_USE_NPU
endif

libSyncdRequestShutdown_a_SOURCES = \
RequestShutdown.cpp \
RequestShutdownCommandLineOptions.cpp \
Expand Down
Loading

0 comments on commit 854d54e

Please sign in to comment.