Skip to content

net: shell: iface: Add link speed settings command #90374

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peileeli
Copy link

Add this to set link speed through net_shell.
Current zephyr version doesn't have user interface to change speed, hence adding this to accomodate it.

Able to change link speed using command below:
net iface set_link
eg: net iface set_link 1 100

Copy link

Hello @peileeli, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

PR_WARNING("No such interface in index %d\n", idx);
return -ENODEV;
}

Copy link
Member

Choose a reason for hiding this comment

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

We need to make sure that the interface is Ethernet one. So something like this (see similar checks in other parts of this file).

	if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
               PR_WARNING("Interface %idx is not Ethernet type\n", idx);
               return -EINVAL;
       }

@@ -27,6 +27,7 @@ LOG_MODULE_DECLARE(net_shell);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the subsys: prefix from commit subject, it is not needed.

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

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

@Vijayakannan , i have done the amendment accordingly

This comment was marked as resolved.

@peileeli peileeli changed the title subsys: net: shell: Enable set_config in net_shell net: shell: Enable set_config in net_shell May 23, 2025
@peileeli peileeli force-pushed the dev/peileeli/set_link_cmd branch from e7cc324 to fc6fb1c Compare May 26, 2025 03:24
@peileeli peileeli force-pushed the dev/peileeli/set_link_cmd branch from fc6fb1c to 38f9418 Compare May 26, 2025 04:30
@@ -841,6 +889,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_iface,
SHELL_CMD(default, IFACE_DYN_CMD,
"'net iface default [<index>]' displays or sets the default network interface.",
cmd_net_default_iface),
SHELL_CMD(set_link, IFACE_DYN_CMD,
"'net iface set_link <index> <Speed 10/100/1000>' sets link speed for the network interface.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The help string is missing 2500/5000 speed variants.

Copy link
Contributor

@Vijayakannan Vijayakannan left a comment

Choose a reason for hiding this comment

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

please amend the commit and PR tittle to reflect exactly.

@@ -27,6 +27,7 @@ LOG_MODULE_DECLARE(net_shell);
#endif

This comment was marked as resolved.

Copy link
Collaborator

@maass-hamburg maass-hamburg left a comment

Choose a reason for hiding this comment

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

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

@clamattia
Copy link
Collaborator

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

I tend to agree with this. To me it is unclear when which api should be used. For example, there is a lot of redundancy with get_phy and then using the phy interface vs. using the ethernet interface.

@maass-hamburg
Copy link
Collaborator

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

I tend to agree with this. To me it is unclear when which api should be used. For example, there is a lot of redundancy with get_phy and then using the phy interface vs. using the ethernet interface.

That's mainly from the days when there was not separate phy api and they integrated the phy code into the ethernet driver/days.

@peileeli
Copy link
Author

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

@maass-hamburg what if user wants to change speed using shell?
Do you mean that shell directly call to phy_configure_link() instead of ethernet driver?

@maass-hamburg
Copy link
Collaborator

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

@maass-hamburg what if user wants to change speed using shell?
Do you mean that shell directly call to phy_configure_link() instead of ethernet driver?

Yes exactly. You can use it together with the 'get_phy' from the Ethernet api.

@peileeli
Copy link
Author

The preferred way to change the Ethernet speed is, to go over the phy and not directly over the Ethernet driver. When the link is then changed by the phy will inform the Ethernet driver via the callback. The api, that is used here, is not implemented in most Ethernet drivers. I'm actually in favor of removing/deprecating this part of the api.

@maass-hamburg what if user wants to change speed using shell?
Do you mean that shell directly call to phy_configure_link() instead of ethernet driver?

Yes exactly. You can use it together with the 'get_phy' from the Ethernet api.

ok, let me try that approach!

@peileeli peileeli force-pushed the dev/peileeli/set_link_cmd branch 2 times, most recently from 8031b4a to adb7b69 Compare May 30, 2025 11:32
@peileeli
Copy link
Author

@maass-hamburg @jukkar @rlubos
I have made amendment accordingly.
[1] use get_phy()
[2] use phy_configure_link()
[3] modify the printout to support (10/100/1000/2500/5000)
[4] check iface

Copy link
Contributor

@Vijayakannan Vijayakannan left a comment

Choose a reason for hiding this comment

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

few nitpicks.


iface = net_if_get_by_index(idx);
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
PR_WARNING("Interface %idx is not Ethernet type\n", idx);

This comment was marked as resolved.

@@ -841,6 +896,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_iface,
SHELL_CMD(default, IFACE_DYN_CMD,
"'net iface default [<index>]' displays or sets the default network interface.",
cmd_net_default_iface),
SHELL_CMD(set_link, IFACE_DYN_CMD,
"'net iface set_link <index> <Speed 10/100/1000/2500/5000>' sets link speed for the network interface.",

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

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

i think for the message i will remain but split to 100 characters

@@ -27,6 +27,7 @@ LOG_MODULE_DECLARE(net_shell);
#endif

This comment was marked as resolved.


phy_configure_link(phy_dev, speed);

return 0;

This comment was marked as resolved.

@peileeli peileeli changed the title net: shell: Enable set_config in net_shell net: shell: iface: Add link speed settings command Jun 2, 2025
@peileeli peileeli force-pushed the dev/peileeli/set_link_cmd branch from adb7b69 to 54aab3a Compare June 2, 2025 07:00
Comment on lines 823 to 826
#if !defined(CONFIG_NET_L2_ETHERNET_MGMT)
PR_WARNING("Unsupported command, please enable CONFIG_NET_L2_ETHERNET_MGMT\n");
return -ENOEXEC;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

CONFIG_NET_L2_ETHERNET_MGMT is not needed

return -ENOTSUP;
}

return phy_configure_link(phy_dev, speed);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this also supports multiple speeds, maybe we could have something like
net iface set_link 1 100 10, which would allow LINK_FULL_100BASE and LINK_FULL_10BASE

Copy link
Contributor

Choose a reason for hiding this comment

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

this also supports multiple speeds, maybe we could have something like net iface set_link 1 100 10, which would allow LINK_FULL_100BASE and LINK_FULL_10BASE

The multiple speed command argument will overlap with the duplex command recommended below. So, can we interchange the command format as shown below to accommodate Multiple speed and Duplex.?

net iface set_link 1 half 100 10

Copy link
Collaborator

Choose a reason for hiding this comment

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

we could loop through the arguments with argc as the max and check if the next argument exists and check if it is not a number then increase the iterator.

net iface set_link 1 100 100 half 10 ( = LINK_FULL_100BASE | LINK_HALF_100BASE | LINK_FULL_10BASE)
should be possible

Copy link
Author

Choose a reason for hiding this comment

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

ok, let me try this.

Comment on lines 849 to 851
case 10:
speed = LINK_FULL_10BASE;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

there are also half duplex variants, maybe check if there is a half or h in the next argument, so
net iface set_link 1 10 half would use LINK_HALF_10BASE.

half is very rarely used, so I would also be fine without it (Optional requirement). Could still be added later.

Copy link
Contributor

Choose a reason for hiding this comment

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

there are also half duplex variants, maybe check if there is a half or h in the next argument, so net iface set_link 1 10 half would use LINK_HALF_10BASE.

I agree with this overloading idea. Perhaps take note of "ETHERNET_CONFIG_TYPE_DUPLEX" for setting the existing duplex option, which might require to deprecate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"ETHERNET_CONFIG_TYPE_DUPLEX" is irrelevant, when going directly over the phy, the phy will inform the ethernet driver. also see #90652

Add this to set link speed through net_shell.
Current zephyr version doesn't have user interface to change
speed, hence adding this to accomodate it.

Able to change link speed using command below:
net iface set_link <iface idx> <speed> <optional:duplex>
eg: net iface set_link 1 100 half
    net iface set_link 1 10 full
    net iface set_link 1 1000

Able to set multiple link speed like below:
net iface set_link <iface idx> <speed1> <speed2> <optional:duplex>
eg: net iface set_link 1 10 100 half
    net iface set_link 1 1000 full 10

Signed-off-by: Ling Pei Lee <pei.lee.ling@intel.com>
@peileeli peileeli force-pushed the dev/peileeli/set_link_cmd branch from 54aab3a to 3d375f9 Compare June 3, 2025 11:44
@peileeli
Copy link
Author

peileeli commented Jun 3, 2025

Changes Added:
[1] comments amendment
[2] Add multiple link speed support
[3] Add half/full duplex support

Comment on lines +852 to +859
for (int j = 2; j < argc; j++) {
if (isdigit(argv[j][0]) == 0) {
if (strcmp(argv[j], "half") == 0) {
full_duplex = false;
break;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be inside the next loop, so it could be set after each speed, also I would just check if the first letter is h, is more performant and the user don't have to write half every time.

Copy link

sonarqubecloud bot commented Jun 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants