Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of mdio access using sai switch api and unix socket IPC s… #1071

Closed
wants to merge 1 commit into from

Conversation

jiahua-wang
Copy link
Contributor

…erver

Signed-off-by: Jiahua Wang jiahua.wang@broadcom.com

…erver

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

ghost commented Jun 27, 2022

CLA assistant check
All CLA requirements met.

Comment on lines +18 to +21
#ifdef MDIO_ACCESS_USE_NPU
sai_object_id_t mdioSwitchId = SAI_NULL_OBJECT_ID;
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

why you suddenly need this instead of gSwitchId? also i strongly advise to not use global objects, this file is added only for thrift support

Copy link
Collaborator

Choose a reason for hiding this comment

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

current logic in syncd is able to handle multiple switches and it should be treated as such

Copy link
Collaborator

Choose a reason for hiding this comment

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

this mdioSwitchId needs to be passed to this class that you will create in the constructor, then remove global definition

Comment on lines +4475 to +4479
#ifdef MDIO_ACCESS_USE_NPU
extern int startIpcMdioProcessingThread(sai_switch_api_t *sai_switch_api);
extern void stopIpcMdioProcessingThread(void);
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

move this to separate file
also why those 2 functions needs to be explicitly called instead on internals SAI when calling create_switch ?

@@ -4494,6 +4499,13 @@ void Syncd::run()
// notification queue is created before we create switch
m_processor->startNotificationsProcessingThread();

#ifdef MDIO_ACCESS_USE_NPU
if (m_commandLineOptions->m_globalContext == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you need explicit context context zero here?

@@ -4472,6 +4472,11 @@ static void timerWatchdogCallback(
SWSS_LOG_ERROR("main loop execution exceeded %ld ms", span/1000);
}

#ifdef MDIO_ACCESS_USE_NPU
extern int startIpcMdioProcessingThread(sai_switch_api_t *sai_switch_api);
Copy link
Collaborator

Choose a reason for hiding this comment

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

don'y pass sai_switch_api, since this suggest that you may call some create functions and it will get out of sync with redisdb

Copy link
Collaborator

Choose a reason for hiding this comment

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

those functions needs to be object methods

Copy link
Collaborator

Choose a reason for hiding this comment

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

you can pass std::shared_ptr as api

@@ -0,0 +1,440 @@
#include <stdio.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you want to keep this file, make this to a proper class, and then instantiate object and call explicitly functions of that object

}

/* Convert to lowercase string */
static char *strlower(char *s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use c++ functions instead of reinventing this

Comment on lines +364 to +369
#if 0
printf("CMD: ");
for (j = 0; j < argc; ++j)
printf("[%s],", argv[j]);
printf("\n");
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove debug

taskAlive = 0;
pthread_join(taskId, (void **)&err);
SWSS_LOG_NOTICE("IPC task thread is stopped\n");
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unnecessary return

};

static void *syncd_ipc_task_main(void *ctx)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

all functions are missing SWSS_LOG_ENTER()

else
{
ret = sai_switch_api->switch_mdio_read(mdioSwitchId, mdio_addr, reg_addr, 1, &val);
sprintf(resp, "%d 0x%x\n", ret, val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

output to a unknown buffer size out the function scope, use std::string to produce response or log errors here instead of passing it through the stack

static sai_status_t syncd_ipc_cmd_mdio_common(char *resp, int argc, char *argv[], sai_switch_api_t *sai_switch_api)
{
int ret = 0;
uint32_t mdio_addr = 0, reg_addr = 0, val = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

declare 1 variable perl line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am rewriting the code in c++ class. I will try to address most of the comments in new code.

@jiahua-wang
Copy link
Contributor Author

This PR is replaced by #1080

@jiahua-wang jiahua-wang deleted the mdio-access branch July 25, 2022 22:02
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.

2 participants