-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
base: main
Are you sure you want to change the base?
net: shell: iface: Add link speed settings command #90374
Conversation
Hello @peileeli, and thank you very much for your first pull request to the Zephyr project! |
subsys/net/lib/shell/iface.c
Outdated
PR_WARNING("No such interface in index %d\n", idx); | ||
return -ENODEV; | ||
} | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
e7cc324
to
fc6fb1c
Compare
fc6fb1c
to
38f9418
Compare
subsys/net/lib/shell/iface.c
Outdated
@@ -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.", |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this 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.
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 |
That's mainly from the days when there was not separate phy api and they integrated the phy code into the ethernet driver/days. |
@maass-hamburg what if user wants to change speed using shell? |
Yes exactly. You can use it together with the 'get_phy' from the Ethernet api. |
ok, let me try that approach! |
8031b4a
to
adb7b69
Compare
@maass-hamburg @jukkar @rlubos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few nitpicks.
subsys/net/lib/shell/iface.c
Outdated
|
||
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.
This comment was marked as resolved.
Sorry, something went wrong.
subsys/net/lib/shell/iface.c
Outdated
@@ -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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
subsys/net/lib/shell/iface.c
Outdated
|
||
phy_configure_link(phy_dev, speed); | ||
|
||
return 0; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
adb7b69
to
54aab3a
Compare
subsys/net/lib/shell/iface.c
Outdated
#if !defined(CONFIG_NET_L2_ETHERNET_MGMT) | ||
PR_WARNING("Unsupported command, please enable CONFIG_NET_L2_ETHERNET_MGMT\n"); | ||
return -ENOEXEC; | ||
#else |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
subsys/net/lib/shell/iface.c
Outdated
case 10: | ||
speed = LINK_FULL_10BASE; | ||
break; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
orh
in the next argument, sonet 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.
There was a problem hiding this comment.
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>
54aab3a
to
3d375f9
Compare
Changes Added: |
for (int j = 2; j < argc; j++) { | ||
if (isdigit(argv[j][0]) == 0) { | ||
if (strcmp(argv[j], "half") == 0) { | ||
full_duplex = false; | ||
break; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
|
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