Skip to content

Add mdio IPC client library#1134

Closed
jiahua-wang wants to merge 37 commits intosonic-net:masterfrom
jiahua-wang:ipc-client
Closed

Add mdio IPC client library#1134
jiahua-wang wants to merge 37 commits intosonic-net:masterfrom
jiahua-wang:ipc-client

Conversation

@jiahua-wang
Copy link
Copy Markdown
Contributor

@jiahua-wang jiahua-wang commented Sep 28, 2022

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.

Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
@kcudnik
Copy link
Copy Markdown
Collaborator

kcudnik commented Sep 29, 2022

please add more description about this PR

@jiahua-wang
Copy link
Copy Markdown
Contributor Author

please add more description about this PR

Description added


#include "MdioIpcClient.h"

#define SAI_IPC_SOCK_DIR_SYNCD "/var/run/sswsyncd"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same macros have been defined in MdioIpcServer.cpp, better to put them in a shared head file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do that

fd = open(path, O_DIRECTORY);
if (fd < 0)
{
printf("%s: Program is not run on host\n", __func__);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SWSS_LOG_XXX instead of printf

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do that


#define CONN_TIMEOUT 25 /* shorter than 30 sec on server side */

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use c++ std::mutex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change code to use std::mutex


if (number_of_registers > 1)
{
printf("Multiple register reads are not supported, num_of_registers: %d\n", number_of_registers);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not support read/write of multiple registers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add error log as the else condition statement.

@kcudnik
Copy link
Copy Markdown
Collaborator

kcudnik commented Oct 10, 2022

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>
@kcudnik
Copy link
Copy Markdown
Collaborator

kcudnik commented Oct 24, 2022

please add unittests to satisfy code coverage

@jiahua-wang
Copy link
Copy Markdown
Contributor Author

I am working on the unit test.

Signed-off-by: Jiahua Wang <jiahua.wang@broadcom.com>
kcudnik
kcudnik previously approved these changes Mar 16, 2023
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>
@jiahua-wang
Copy link
Copy Markdown
Contributor Author

/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>
libSyncd_a_CXXFLAGS += -DMDIO_ACCESS_USE_NPU
endif

if SONIC_ASIC_PLATFORM_VS
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are changind default behaviour by this, since by default vs switch is not considered as npu switch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
#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 */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix this by MDIO_

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of m_accessUseNPU has indicated feature enablement, which could be TRUE if

  1. platform support, currently only broadcom
  2. mock MdioIpcServer instance in unittest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

}

/* 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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all those extern C functions should be declared in extern C in header file, and not explicitly here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which they are, so this extern should be redundant here

Copy link
Copy Markdown
Contributor Author

@jiahua-wang jiahua-wang Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 19, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@jiahua-wang
Copy link
Copy Markdown
Contributor Author

/azpw run Azure.sonic-sairedis

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run Azure.sonic-sairedis

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jiahua-wang
Copy link
Copy Markdown
Contributor Author

This PR is replaced by #1230

@WillsonHG
Copy link
Copy Markdown

/easycla

@jiahua-wang jiahua-wang deleted the ipc-client branch April 24, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants