Skip to content

Commit a1796a5

Browse files
jiahua-wangyxieca
authored andcommitted
Add support of mdio IPC server class using sai switch api and unix socket (#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 <[email protected]>
1 parent 87d5a3e commit a1796a5

11 files changed

Lines changed: 728 additions & 0 deletions

File tree

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AX_CODE_COVERAGE
1616
AX_ADD_AM_MACRO_STATIC([])
1717

1818
AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BAREFOOT, test x$CONFIGURED_PLATFORM = xbarefoot)
19+
AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BROADCOM, test x$CONFIGURED_PLATFORM = xbroadcom)
1920

2021
AC_ARG_ENABLE(debug,
2122
[ --enable-debug turn on debugging],

meta/SaiInterface.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,51 @@ sai_status_t SaiInterface::get(
197197
return SAI_STATUS_FAILURE;
198198
}
199199
}
200+
201+
sai_status_t SaiInterface::switchMdioRead(
202+
_In_ sai_object_id_t switch_id,
203+
_In_ uint32_t device_addr,
204+
_In_ uint32_t start_reg_addr,
205+
_In_ uint32_t number_of_registers,
206+
_Out_ uint32_t *reg_val)
207+
{
208+
SWSS_LOG_ENTER();
209+
210+
return SAI_STATUS_FAILURE;
211+
}
212+
213+
sai_status_t SaiInterface::switchMdioWrite(
214+
_In_ sai_object_id_t switch_id,
215+
_In_ uint32_t device_addr,
216+
_In_ uint32_t start_reg_addr,
217+
_In_ uint32_t number_of_registers,
218+
_In_ const uint32_t *reg_val)
219+
{
220+
SWSS_LOG_ENTER();
221+
222+
return SAI_STATUS_FAILURE;
223+
}
224+
225+
sai_status_t SaiInterface::switchMdioCl22Read(
226+
_In_ sai_object_id_t switch_id,
227+
_In_ uint32_t device_addr,
228+
_In_ uint32_t start_reg_addr,
229+
_In_ uint32_t number_of_registers,
230+
_Out_ uint32_t *reg_val)
231+
{
232+
SWSS_LOG_ENTER();
233+
234+
return SAI_STATUS_FAILURE;
235+
}
236+
237+
sai_status_t SaiInterface::switchMdioCl22Write(
238+
_In_ sai_object_id_t switch_id,
239+
_In_ uint32_t device_addr,
240+
_In_ uint32_t start_reg_addr,
241+
_In_ uint32_t number_of_registers,
242+
_In_ const uint32_t *reg_val)
243+
{
244+
SWSS_LOG_ENTER();
245+
246+
return SAI_STATUS_FAILURE;
247+
}

meta/SaiInterface.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,34 @@ namespace sairedis
222222
_In_ uint32_t attrCount,
223223
_In_ const sai_attribute_t *attrList) = 0;
224224

225+
virtual sai_status_t switchMdioRead(
226+
_In_ sai_object_id_t switch_id,
227+
_In_ uint32_t device_addr,
228+
_In_ uint32_t start_reg_addr,
229+
_In_ uint32_t number_of_registers,
230+
_Out_ uint32_t *reg_val);
231+
232+
virtual sai_status_t switchMdioWrite(
233+
_In_ sai_object_id_t switch_id,
234+
_In_ uint32_t device_addr,
235+
_In_ uint32_t start_reg_addr,
236+
_In_ uint32_t number_of_registers,
237+
_In_ const uint32_t *reg_val);
238+
239+
virtual sai_status_t switchMdioCl22Read(
240+
_In_ sai_object_id_t switch_id,
241+
_In_ uint32_t device_addr,
242+
_In_ uint32_t start_reg_addr,
243+
_In_ uint32_t number_of_registers,
244+
_Out_ uint32_t *reg_val);
245+
246+
virtual sai_status_t switchMdioCl22Write(
247+
_In_ sai_object_id_t switch_id,
248+
_In_ uint32_t device_addr,
249+
_In_ uint32_t start_reg_addr,
250+
_In_ uint32_t number_of_registers,
251+
_In_ const uint32_t *reg_val);
252+
225253
public: // SAI API
226254

227255
virtual sai_status_t objectTypeGetAvailability(

syncd/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ libSyncd_a_SOURCES = \
2323
FlexCounterManager.cpp \
2424
GlobalSwitchId.cpp \
2525
HardReiniter.cpp \
26+
MdioIpcServer.cpp \
2627
MetadataLogger.cpp \
2728
NotificationHandler.cpp \
2829
NotificationProcessor.cpp \
@@ -71,6 +72,10 @@ syncd_CXXFLAGS += -DSAITHRIFT=yes
7172
syncd_LDADD += -lrpcserver -lthrift
7273
endif
7374

75+
if SONIC_ASIC_PLATFORM_BROADCOM
76+
libSyncd_a_CXXFLAGS += -DMDIO_ACCESS_USE_NPU
77+
endif
78+
7479
libSyncdRequestShutdown_a_SOURCES = \
7580
RequestShutdown.cpp \
7681
RequestShutdownCommandLineOptions.cpp \

0 commit comments

Comments
 (0)