Add mdio IPC client library#1134
Conversation
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
|
please add more description about this PR |
Description added |
syncd/MdioIpcClient.cpp
Outdated
|
|
||
| #include "MdioIpcClient.h" | ||
|
|
||
| #define SAI_IPC_SOCK_DIR_SYNCD "/var/run/sswsyncd" |
There was a problem hiding this comment.
Same macros have been defined in MdioIpcServer.cpp, better to put them in a shared head file.
syncd/MdioIpcClient.cpp
Outdated
| fd = open(path, O_DIRECTORY); | ||
| if (fd < 0) | ||
| { | ||
| printf("%s: Program is not run on host\n", __func__); |
There was a problem hiding this comment.
Use SWSS_LOG_XXX instead of printf
syncd/MdioIpcClient.cpp
Outdated
|
|
||
| #define CONN_TIMEOUT 25 /* shorter than 30 sec on server side */ | ||
|
|
||
| static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
There was a problem hiding this comment.
better to use c++ std::mutex
There was a problem hiding this comment.
Will change code to use std::mutex
syncd/MdioIpcClient.cpp
Outdated
|
|
||
| if (number_of_registers > 1) | ||
| { | ||
| printf("Multiple register reads are not supported, num_of_registers: %d\n", number_of_registers); |
There was a problem hiding this comment.
Why not support read/write of multiple registers?
There was a problem hiding this comment.
This is an error check for multiple reasons. The caller of the mdio ipc client is the PAI. The mdio read function prototype defined for PAI has already determined the mdio read single register. The mdio ipc server also determines the mdio read/write single register. The IPC message format also determines the mdio access single register.
| { | ||
| *data = (uint32_t)strtoul(strchrnul(resp, ' ') + 1, NULL, 0); | ||
| rc = SAI_STATUS_SUCCESS; | ||
| } |
There was a problem hiding this comment.
If syncd_mdio_ipc_command(cmd, resp) < 0, for debugging, should at least add log for error code. Better to translate the error code to SAI status code on rc.
There was a problem hiding this comment.
Will add error log as the else condition statement.
|
you should add unittests for this code |
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
|
please add unittests to satisfy code coverage |
|
I am working on the unit test. |
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
…d unittest Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
|
/azpw run Azure.sonic-sairedis |
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
syncd/Makefile.am
Outdated
| libSyncd_a_CXXFLAGS += -DMDIO_ACCESS_USE_NPU | ||
| endif | ||
|
|
||
| if SONIC_ASIC_PLATFORM_VS |
There was a problem hiding this comment.
you are changind default behaviour by this, since by default vs switch is not considered as npu switch
There was a problem hiding this comment.
Because some code in MdioIpcServer.cpp is compiled with the condition MDIO_ACCESS_USE_NPU and seems not run in unit test, I tried to add the condition to the vs platform but it did not work. I will revert the change since it does not help the unit test.
…ORM_UNDEFINED, remove SONIC_ASIC_PLATFORM_VS Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
… add -DMDIO_ACCESS_USE_NPU to CXXFLAGS in azure_pipeline Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
syncd/MdioIpcCommon.h
Outdated
| #define MDIO_SERVER_TIMEOUT 30 /* sec, connection timeout */ | ||
| #define MDIO_CLIENT_TIMEOUT 25 /* shorter than 30 sec on server side */ | ||
|
|
||
| #define CONN_MAX 18 /* max. number of connections */ |
There was a problem hiding this comment.
Will change CONN_MAX to MDIO_CONN_MAX.
…tIpcTestMode() Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
| /* globalContext == 0 for syncd, globalContext > 0 for gbsyncd */ | ||
| MdioIpcServer::m_syncdContext = (globalContext == 0); | ||
| #ifdef MDIO_ACCESS_USE_NPU | ||
| MdioIpcServer::m_accessUseNPU = true; |
There was a problem hiding this comment.
Why not directly m_accessUseNPU = true ? It is not defined as a static class member.
Since member m_accessUseNPU is added, macro MDIO_ACCESS_USE_NPU looks redundant and needs to be removed. Its value can be assigned by adding a parameter like accessUseNPU in the constructor.
There was a problem hiding this comment.
MDIO_ACCESS_USE_NPU is only defined in syncd/Malefile.am for "make configure PLATFORM=broadcom". It is only tested on broadcom ASIC. When other platforms have tested the feature, the syncd/Makefile.am can be modified to add the feature. Actually, if m_accessUseNPU = true for vs platform, we see vssyncd test logs error messages.
There was a problem hiding this comment.
The value of m_accessUseNPU has indicated feature enablement, which could be TRUE if
- platform support, currently only broadcom
- mock MdioIpcServer instance in unittest
There was a problem hiding this comment.
Yes, The value of m_accessUseNPU is TRUE if platform support, currently only broadcom. For mock MdioIpcServer instance in unittest, the value of m_accessUseNPU is changed to be true at run time by the function MdioIpcServer::setIpcTestMode().
syncd/MdioIpcClient.cpp
Outdated
| } | ||
|
|
||
| /* Function to read data using clause 22 from MDIO interface */ | ||
| extern "C" sai_status_t mdio_read_cl22(uint64_t platform_context, uint32_t mdio_addr, uint32_t reg_addr, |
There was a problem hiding this comment.
all those extern C functions should be declared in extern C in header file, and not explicitly here
There was a problem hiding this comment.
which they are, so this extern should be redundant here
There was a problem hiding this comment.
I can try to remove the extern C in .c file. I'm not convinced it's good practice to remove the extern "C" from the implementation file. I think it's better to be explicit in the implementation file.
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
|
|
|
/azpw run Azure.sonic-sairedis |
|
/AzurePipelines run Azure.sonic-sairedis |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
This PR is replaced by #1230 |
|
/easycla |
Signed-off-by: Jiahua Wang jiahua.wang@broadcom.com
This PR is to replace sonic-net/sonic-buildimage#11284
Why I did it
The syncd has a MDIO IPC server to help the access of external PHYs on the NPU MDIO bus. A MDIO IPC client library is required to communicate to the MDIO IPC server. The gbsyncd will pass the function pointers for the function in the client library to the PAI.
How I did it
MDIO IPC client functions are added to connect to the MDIO IPC server socket, to send request and to wait for response IPC messages. The client functions are made into a .so library. The .so library is packaged in the syncd debian package.
How to verify it
The client functions are also available in as a .a library. The unit test code can use the code to test both IPC server and client.