From 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 22:49:52 +0200 Subject: Adding upstream version 255.4. Signed-off-by: Daniel Baumann --- src/shared/ethtool-link-mode.py | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/shared/ethtool-link-mode.py (limited to 'src/shared/ethtool-link-mode.py') diff --git a/src/shared/ethtool-link-mode.py b/src/shared/ethtool-link-mode.py new file mode 100644 index 0000000..aac1576 --- /dev/null +++ b/src/shared/ethtool-link-mode.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-or-later + +import re +import shlex +import subprocess +import sys + +OVERRIDES = { + 'autoneg' : 'autonegotiation', +} + +mode, cpp, header = sys.argv[1:] +xml = mode == '--xml' + +command = [*shlex.split(cpp), '-include', header, '-'] +out = subprocess.check_output(command, stdin=subprocess.DEVNULL, universal_newlines=True) + +lines = iter(out.splitlines()) +for line in lines: + if line.startswith('enum ethtool_link_mode_bit_indices {'): + break + +entries = [] +for line in lines: + if line.startswith('}'): + break + # ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0, + m = re.match(r'^\s*(ETHTOOL_LINK_MODE_((\d*).*)_BIT)\s*=\s*(\d+),', line) + if not m: + continue + enum, name, speed, value = m.groups() + + name = name.lower().replace('_', '-') + name = OVERRIDES.get(name, name) + + duplex = name.split('-')[-1].lower() + if duplex not in {'half', 'full'}: + duplex = '' + + entries += [(enum, name, speed, value, duplex)] + +if xml: + print(' ') + + entries.sort(key=lambda entry: (int(entry[2]) if entry[2] else 1e20, entry[4], entry[1], entry[3])) + +for enum, name, speed, value, duplex in entries: + if xml: + print(f'''\ + + {speed}{duplex} + ''') + else: + enum = f'[{enum}]' + print(f' {enum:50} = "{name}",') + +if xml: + print(' ') + +assert len(entries) >= 99 -- cgit v1.2.3