Skip to content

Commit

Permalink
driver/rawnetworkinterfacedriver: ethtool get/change pause settings
Browse files Browse the repository at this point in the history
Add interface pause configuration (`ethtool --pause`) support to the
RawNetworkInterfaceDriver. This allows configuring the pause parameters
autoneg, rx and tx on the bound interface.

Also add a `get_pause_settings()` method to query those settings.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause committed Oct 30, 2024
1 parent 63b38ce commit a93f147
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions helpers/labgrid-raw-interface
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ def main(program, options):
args.append(options.ifname)
args.extend(options.ethtool_set_eee_args)

elif options.subcommand == "pause":
for arg in options.ethtool_pause_args:
if arg.startswith("-") or not allowed_chars.issuperset(arg):
raise ValueError(f"ethtool --pause arg '{arg}' contains invalid characters")

args.append("--pause")
args.append(options.ifname)
args.extend(options.ethtool_pause_args)

try:
os.execvp(args[0], args)
except FileNotFoundError as e:
Expand Down Expand Up @@ -154,6 +163,13 @@ if __name__ == "__main__":
"ethtool_set_eee_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --set-eee args"
)

# ethtool: pause
ethtool_change_parser = ethtool_subparsers.add_parser("pause")
ethtool_change_parser.add_argument("ifname", type=str, help="interface name")
ethtool_change_parser.add_argument(
"ethtool_pause_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --pause args"
)

args = parser.parse_args()
try:
main(args.program, args)
Expand Down
22 changes: 22 additions & 0 deletions labgrid/driver/rawnetworkinterfacedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ def ethtool_configure_eee(self, **settings):
cmd = self._wrap_command(cmd)
subprocess.check_call(cmd)

@Driver.check_active
def get_ethtool_pause_settings(self):
"""
Returns pause parameters via ethtool of the bound network interface resource.
"""
cmd = self.iface.command_prefix + ["ethtool", "--json", "--show-pause", self.iface.ifname]
output = subprocess.check_output(cmd, encoding="utf-8")
return json.loads(output)[0]

@Driver.check_active
@step(args=["settings"])
def ethtool_configure_pause(self, **settings):
"""
Change pause parameters via ethtool of the bound network interface resource.
Supported settings are described in ethtool(8) --pause
"""
cmd = ["ethtool", "pause", self.iface.ifname]
cmd += [item for pair in settings.items() for item in pair]
cmd = self._wrap_command(cmd)
subprocess.check_call(cmd)

def _stop(self, proc, *, timeout=None):
assert proc is not None

Expand Down

0 comments on commit a93f147

Please sign in to comment.