From 3d5cc842ea651de68cfac299d6a8bd2849c9a1f8 Mon Sep 17 00:00:00 2001 From: Nicolas Vollmar Date: Thu, 12 Dec 2024 19:34:20 +0100 Subject: T6944: adds option to enable switchdev mode on ethernet interface --- python/vyos/ifconfig/ethernet.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'python') diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py index 50dd0f396..a8b72cc9c 100644 --- a/python/vyos/ifconfig/ethernet.py +++ b/python/vyos/ifconfig/ethernet.py @@ -417,6 +417,25 @@ class EthernetIf(Interface): print(f'could not set "{rx_tx}" ring-buffer for {ifname}') return output + def set_switchdev(self, enable): + ifname = self.config['ifname'] + addr, code = self._popen(f'ethtool -i {ifname} | grep bus-info | awk \'{{print $2}}\'') + if code != 0: + print(f'could not resolve PCIe address of {ifname}') + return + + enabled = False + state, code = self._popen(f'/sbin/devlink dev eswitch show pci/{addr} | awk \'{{print $3}}\'') + if code == 0 and state == 'switchdev': + enabled = True + + if enable and not enabled: + output, code = self._popen(f'/sbin/devlink dev eswitch set pci/{addr} mode switchdev') + if code != 0: + print(f'{ifname} does not support switchdev mode') + elif not enable and enabled: + self._cmd(f'/sbin/devlink dev eswitch set pci/{addr} mode legacy') + def update(self, config): """ General helper function which works on a dictionary retrived by get_config_dict(). It's main intention is to consolidate the scattered @@ -463,6 +482,8 @@ class EthernetIf(Interface): for rx_tx, size in config['ring_buffer'].items(): self.set_ring_buffer(rx_tx, size) + self.set_switchdev('switchdev' in config) + # call base class last super().update(config) -- cgit v1.2.3