summaryrefslogtreecommitdiffstats
path: root/src/shared/ethtool-link-mode.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/shared/ethtool-link-mode.py
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shared/ethtool-link-mode.py')
-rw-r--r--src/shared/ethtool-link-mode.py61
1 files changed, 61 insertions, 0 deletions
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(' <tbody>')
+
+ 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'''\
+ <row><entry><option>{name}</option></entry>
+ <entry>{speed}</entry><entry>{duplex}</entry></row>
+ ''')
+ else:
+ enum = f'[{enum}]'
+ print(f' {enum:50} = "{name}",')
+
+if xml:
+ print(' </tbody>')
+
+assert len(entries) >= 99