tools: ynl: generate code for the ethtool family
Subsystems (4)
Jakub Kicinski
maintainercover tools: ynl: generate code for the ethtool family
And finally ethtool support. Thanks to Stan's work the ethtool family spec is quite complete, so there is a lot of operations to support.
I chickened out of stats-get support, they require at the very least type-value support on a u64 scalar. Type-value is an arrangement where a u16 attribute is encoded directly in attribute type. Code gen can support this if the inside is a nest, we just throw in an extra field into that nest to carry the attr type. But a little more coding is needed to for a scalar, because first we need to turn the scalar into a struct with one member, then we can add the attr type.
Other than that ethtool required event support (notification which does not share contents with any GET), but the previous series already added that to the codegen.
I haven't tested all the ops here, and a few I tried seem to work.
Jakub Kicinski (12):
tools: ynl-gen: support excluding tricky ops
tools: ynl-gen: record extra args for regen
netlink: specs: support setting prefix-name per attribute
netlink: specs: ethtool: add C render hints
tools: ynl-gen: don't generate enum types if unnamed
tools: ynl-gen: resolve enum vs struct name conflicts
netlink: specs: ethtool: add empty enum stringset
netlink: specs: ethtool: untangle UDP tunnels and cable test a bit
netlink: specs: ethtool: untangle stats-get
netlink: specs: ethtool: mark pads as pads
tools: ynl: generate code for the ethtool family
tools: ynl: add sample for ethtool
Documentation/netlink/genetlink-c.yaml | 4 + Documentation/netlink/genetlink-legacy.yaml | 4 + Documentation/netlink/specs/ethtool.yaml | 120 +- tools/net/ynl/generated/Makefile | 9 +- tools/net/ynl/generated/ethtool-user.c | 6353 +++++++++++++++++++ tools/net/ynl/generated/ethtool-user.h | 5531 ++++++++++++++++ tools/net/ynl/lib/nlspec.py | 12 +- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/ethtool.c | 65 + tools/net/ynl/ynl-gen-c.py | 59 +- tools/net/ynl/ynl-regen.sh | 4 +- 11 files changed, 12116 insertions(+), 46 deletions(-) create mode 100644 tools/net/ynl/generated/ethtool-user.c create mode 100644 tools/net/ynl/generated/ethtool-user.h create mode 100644 tools/net/ynl/samples/ethtool.c
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 1/12 tools: ynl-gen: support excluding tricky ops
The ethtool family has a small handful of quite tricky ops and a lot of simple very useful ops. Teach ynl-gen to skip ops so that we can bypass the tricky ones.
--- tools/net/ynl/lib/nlspec.py | 12 ++++++++++-- tools/net/ynl/ynl-gen-c.py | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-)
tools/net/ynl/lib/nlspec.py +10 -2
@@ -334,7 +334,7 @@ jsonschema = None consts dict of all constants/enums fixed_header string, optional name of family default fixed header struct """ - def __init__(self, spec_path, schema_path=None): + def __init__(self, spec_path, schema_path=None, exclude_ops=None): with open(spec_path, "r") as stream: prefix = '# SPDX-License-Identifier: ' first = stream.readline().strip()
@@ -349,6 +349,8 @@ jsonschema = None super().__init__(self, spec) + self._exclude_ops = exclude_ops if exclude_ops else [] + self.proto = self.yaml.get('protocol', 'genetlink') self.msg_id_model = self.yaml['operations'].get('enum-model', 'unified')
@@ -449,7 +451,13 @@ jsonschema = None req_val = None if rsp_val == rsp_val_next: rsp_val = None - op = self.new_operation(elem, req_val, rsp_val) + + skip = False + for exclude in self._exclude_ops: + skip |= bool(exclude.match(elem['name'])) + if not skip: + op = self.new_operation(elem, req_val, rsp_val) + req_val = req_val_next rsp_val = rsp_val_next
tools/net/ynl/ynl-gen-c.py +7 -3
@@ -4,6 +4,7 @@ import argparse import collections import os +import re import yaml from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, SpecEnumEntry
@@ -739,7 +740,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S class Family(SpecFamily): - def __init__(self, file_name): + def __init__(self, file_name, exclude_ops): # Added by resolve: self.c_name = None delattr(self, "c_name")
@@ -754,7 +755,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S self.hooks = None delattr(self, "hooks") - super().__init__(file_name) + super().__init__(file_name, exclude_ops=exclude_ops) self.fam_key = c_upper(self.yaml.get('c-family-name', self.yaml["name"] + '_FAMILY_NAME')) self.ver_key = c_upper(self.yaml.get('c-version-name', self.yaml["name"] + '_FAMILY_VERSION'))
@@ -2241,6 +2242,7 @@ _C_KW = { parser.add_argument('--header', dest='header', action='store_true', default=None) parser.add_argument('--source', dest='header', action='store_false') parser.add_argument('--user-header', nargs='+', default=[]) + parser.add_argument('--exclude-op', action='append', default=[]) parser.add_argument('-o', dest='out_file', type=str) args = parser.parse_args()
@@ -2249,8 +2251,10 @@ _C_KW = { if args.header is None: parser.error("--header or --source is required") + exclude_ops = [re.compile(expr) for expr in args.exclude_op] + try: - parsed = Family(args.spec) + parsed = Family(args.spec, exclude_ops) if parsed.license != '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)': print('Spec license:', parsed.license) print('License must be: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 2/12 tools: ynl-gen: record extra args for regen
In reply to Jakub Kicinskiynl-regen needs to know the arguments used to generate a file. Record excluded ops and, while at it, user headers.
--- tools/net/ynl/ynl-gen-c.py | 5 +++++ tools/net/ynl/ynl-regen.sh | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +5 -0
@@ -2281,6 +2281,11 @@ _C_KW = { cw.p("/* Do not edit directly, auto-generated from: */") cw.p(f"/*\t{spec_kernel} */") cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */") + if args.exclude_op or args.user_header: + line = '' + line += ' --user-header '.join([''] + args.user_header) + line += ' --exclude-op '.join([''] + args.exclude_op) + cw.p(f'/* YNL-ARG{line} */') cw.nl() if args.mode == 'uapi':
tools/net/ynl/ynl-regen.sh +3 -1
@@ -19,6 +19,7 @@ for f in $files; do # params: 0 1 2 3 # $YAML YNL-GEN kernel $mode params=( $(git grep -B1 -h '/\* YNL-GEN' $f | sed 's@/\*\(.*\)\*/@\1@') ) + args=$(sed -n 's@/\* YNL-ARG \(.*\) \*/@\1@p' $f) if [ $f -nt ${params[0]} -a -z "$force" ]; then echo -e "\tSKIP $f"
@@ -26,5 +27,6 @@ for f in $files; do fi echo -e "\tGEN ${params[2]}\t$f" - $TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} -o $f + $TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} \ + $args -o $f done
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 3/12 netlink: specs: support setting prefix-name per attribute
In reply to Jakub KicinskiEthtool's PSE PoDL has a attr nest with different prefixes:
/* Power Sourcing Equipment */
enum {
ETHTOOL_A_PSE_UNSPEC,
ETHTOOL_A_PSE_HEADER, /* nest - _A_HEADER_* */
ETHTOOL_A_PODL_PSE_ADMIN_STATE, /* u32 */
ETHTOOL_A_PODL_PSE_ADMIN_CONTROL, /* u32 */
ETHTOOL_A_PODL_PSE_PW_D_STATUS, /* u32 */Header has a prefix of ETHTOOL_A_PSE_ and other attrs prefix of ETHTOOL_A_PODL_PSE_ we can't cover them uniformly.
If PODL was after PSE life would be easy.
Now we either need to add prefixes to attr names which is yucky or support setting prefix name per attr.
--- Documentation/netlink/genetlink-c.yaml | 4 ++++ Documentation/netlink/genetlink-legacy.yaml | 4 ++++ tools/net/ynl/ynl-gen-c.py | 7 +++++-- 3 files changed, 13 insertions(+), 2 deletions(-)
Documentation/netlink/genetlink-c.yaml +4 -0
@@ -195,6 +195,10 @@ additionalProperties: False description: Max length for a string or a binary attribute. $ref: '#/$defs/len-or-define' sub-type: *attr-type + # Start genetlink-c + name-prefix: + type: string + # End genetlink-c # Make sure name-prefix does not appear in subsets (subsets inherit naming) dependencies:
Documentation/netlink/genetlink-legacy.yaml +4 -0
@@ -226,6 +226,10 @@ additionalProperties: False description: Max length for a string or a binary attribute. $ref: '#/$defs/len-or-define' sub-type: *attr-type + # Start genetlink-c + name-prefix: + type: string + # End genetlink-c # Start genetlink-legacy struct: description: Name of the struct type used for the attribute.
tools/net/ynl/ynl-gen-c.py +5 -2
@@ -58,8 +58,11 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S delattr(self, "enum_name") def resolve(self): - self.enum_name = f"{self.attr_set.name_prefix}{self.name}" - self.enum_name = c_upper(self.enum_name) + if 'name-prefix' in self.attr: + enum_name = f"{self.attr['name-prefix']}{self.name}" + else: + enum_name = f"{self.attr_set.name_prefix}{self.name}" + self.enum_name = c_upper(enum_name) def is_multi_val(self): return None
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 4/12 netlink: specs: ethtool: add C render hints
In reply to Jakub KicinskiMost of the C enum names are guessed correctly, but there is a handful of corner cases we need to name explicitly.
--- Documentation/netlink/specs/ethtool.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/netlink/specs/ethtool.yaml +5 -0
@@ -9,6 +9,7 @@ doc: Partial family for Ethtool Netlink. definitions: - name: udp-tunnel-type + enum-name: type: enum entries: [ vxlan, geneve, vxlan-gpe ]
@@ -836,12 +837,15 @@ doc: Partial family for Ethtool Netlink. - name: admin-state type: u32 + name-prefix: ethtool-a-podl-pse- - name: admin-control type: u32 + name-prefix: ethtool-a-podl-pse- - name: pw-d-status type: u32 + name-prefix: ethtool-a-podl-pse- - name: rss attributes:
@@ -895,6 +899,7 @@ doc: Partial family for Ethtool Netlink. operations: enum-model: directional + name-prefix: ethtool-msg- list: - name: strset-get
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 5/12 tools: ynl-gen: don't generate enum types if unnamed
In reply to Jakub KicinskiIf attr set or enum has empty enum name we need to use u32 or int as function arguments and struct members.
--- tools/net/ynl/ynl-gen-c.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/net/ynl/ynl-gen-c.py +10 -2
@@ -268,7 +268,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S else: self.is_bitfield = False - if 'enum' in self.attr and not self.is_bitfield: + maybe_enum = not self.is_bitfield and 'enum' in self.attr + if maybe_enum and self.family.consts[self.attr['enum']].enum_name: self.type_name = f"enum {self.family.name}_{c_lower(self.attr['enum'])}" else: self.type_name = '__' + self.type
@@ -652,7 +653,14 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S class EnumSet(SpecEnumSet): def __init__(self, family, yaml): self.render_name = c_lower(family.name + '-' + yaml['name']) - self.enum_name = 'enum ' + self.render_name + + if 'enum-name' in yaml: + if yaml['enum-name']: + self.enum_name = 'enum ' + c_lower(yaml['enum-name']) + else: + self.enum_name = None + else: + self.enum_name = 'enum ' + self.render_name self.value_pfx = yaml.get('name-prefix', f"{family.name}-{yaml['name']}-")
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 6/12 tools: ynl-gen: resolve enum vs struct name conflicts
In reply to Jakub KicinskiEthtool has an attribute set called stringset, from which we'll generate struct ethtool_stringset. Unfortunately, the old ethtool header declares enum ethtool_stringset (the same name), to which compilers object.
This seems unavoidable. Check struct names against known constants and append an underscore if conflict is detected.
--- tools/net/ynl/ynl-gen-c.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
tools/net/ynl/ynl-gen-c.py +20 -5
@@ -49,6 +49,11 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S else: self.nested_render_name = f"{family.name}_{c_lower(self.nested_attrs)}" + if self.nested_attrs in self.family.consts: + self.nested_struct_type = 'struct ' + self.nested_render_name + '_' + else: + self.nested_struct_type = 'struct ' + self.nested_render_name + self.c_name = c_lower(self.name) if self.c_name in _C_KW: self.c_name += '_'
@@ -425,7 +430,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S class TypeNest(Type): def _complex_member_type(self, ri): - return f"struct {self.nested_render_name}" + return self.nested_struct_type def free(self, ri, var, ref): ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name});')
@@ -470,7 +475,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S def _complex_member_type(self, ri): if 'type' not in self.attr or self.attr['type'] == 'nest': - return f"struct {self.nested_render_name}" + return self.nested_struct_type elif self.attr['type'] in scalars: scalar_pfx = '__' if ri.ku_space == 'user' else '' return scalar_pfx + self.attr['type']
@@ -530,7 +535,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S def _complex_member_type(self, ri): if 'sub-type' not in self.attr or self.attr['sub-type'] == 'nest': - return f"struct {self.nested_render_name}" + return self.nested_struct_type elif self.attr['sub-type'] in scalars: scalar_pfx = '__' if ri.ku_space == 'user' else '' return scalar_pfx + self.attr['sub-type']
@@ -550,7 +555,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S class TypeNestTypeValue(Type): def _complex_member_type(self, ri): - return f"struct {self.nested_render_name}" + return self.nested_struct_type def _attr_typol(self): return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
@@ -593,6 +598,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S else: self.render_name = f"{family.name}_{c_lower(space_name)}" self.struct_name = 'struct ' + self.render_name + if self.nested and space_name in family.consts: + self.struct_name += '_' self.ptr_name = self.struct_name + ' *' self.request = False
@@ -994,10 +1001,13 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S if not self.attr_set: self.attr_set = op['attribute-set'] + self.type_name_conflict = False if op: self.type_name = c_lower(op.name) else: self.type_name = c_lower(attr_set) + if attr_set in family.consts: + self.type_name_conflict = True self.cw = cw
@@ -1634,12 +1644,17 @@ _C_KW = { def print_free_prototype(ri, direction, suffix=';'): name = op_prefix(ri, direction) + struct_name = name + if ri.type_name_conflict: + struct_name += '_' arg = free_arg_name(direction) - ri.cw.write_func_prot('void', f"{name}_free", [f"struct {name} *{arg}"], suffix=suffix) + ri.cw.write_func_prot('void', f"{name}_free", [f"struct {struct_name} *{arg}"], suffix=suffix) def _print_type(ri, direction, struct): suffix = f'_{ri.type_name}{direction_to_suffix[direction]}' + if not direction and ri.type_name_conflict: + suffix += '_' if ri.op_mode == 'dump': suffix += '_dump'
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 7/12 netlink: specs: ethtool: add empty enum stringset
In reply to Jakub KicinskiC does not allow defining structures and enums with the same name. Since enum ethtool_stringset exists in the uAPI we need to include at least a stub of it in the spec. This will trigger name collision avoidance in the code gen.
--- Documentation/netlink/specs/ethtool.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/netlink/specs/ethtool.yaml +4 -0
@@ -12,6 +12,10 @@ doc: Partial family for Ethtool Netlink. enum-name: type: enum entries: [ vxlan, geneve, vxlan-gpe ] + - + name: stringset + type: enum + entries: [] attribute-sets: -
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 8/12 netlink: specs: ethtool: untangle UDP tunnels and cable test a bit
In reply to Jakub KicinskiUDP tunnel and cable test messages have a lot of nests, which do not match the names of the enum entries in C uAPI. Some of the structure / nesting also looks wrong.
Untangle this a little bit based on the names, comments and educated guesses, I haven't actually tested the results.
--- Documentation/netlink/specs/ethtool.yaml | 82 ++++++++++++++++++------ 1 file changed, 62 insertions(+), 20 deletions(-)
Documentation/netlink/specs/ethtool.yaml +62 -20
@@ -582,7 +582,7 @@ doc: Partial family for Ethtool Netlink. name: phc-index type: u32 - - name: cable-test-ntf-nest-result + name: cable-result attributes: - name: pair
@@ -591,7 +591,7 @@ doc: Partial family for Ethtool Netlink. name: code type: u8 - - name: cable-test-ntf-nest-fault-length + name: cable-fault-length attributes: - name: pair
@@ -600,18 +600,25 @@ doc: Partial family for Ethtool Netlink. name: cm type: u32 - - name: cable-test-ntf-nest + name: cable-nest attributes: - name: result type: nest - nested-attributes: cable-test-ntf-nest-result + nested-attributes: cable-result - name: fault-length type: nest - nested-attributes: cable-test-ntf-nest-fault-length + nested-attributes: cable-fault-length - name: cable-test + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: cable-test-ntf attributes: - name: header
@@ -623,7 +630,7 @@ doc: Partial family for Ethtool Netlink. - name: nest type: nest - nested-attributes: cable-test-ntf-nest + nested-attributes: cable-nest - name: cable-test-tdr-cfg attributes:
@@ -637,8 +644,22 @@ doc: Partial family for Ethtool Netlink. name: step type: u32 - - name: pari + name: pair type: u8 + - + name: cable-test-tdr-ntf + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: status + type: u8 + - + name: nest + type: nest + nested-attributes: cable-nest - name: cable-test-tdr attributes:
@@ -651,7 +672,7 @@ doc: Partial family for Ethtool Netlink. type: nest nested-attributes: cable-test-tdr-cfg - - name: tunnel-info-udp-entry + name: tunnel-udp-entry attributes: - name: port
@@ -662,7 +683,7 @@ doc: Partial family for Ethtool Netlink. type: u32 enum: udp-tunnel-type - - name: tunnel-info-udp-table + name: tunnel-udp-table attributes: - name: size
@@ -672,9 +693,17 @@ doc: Partial family for Ethtool Netlink. type: nest nested-attributes: bitset - - name: udp-ports + name: entry type: nest - nested-attributes: tunnel-info-udp-entry + multi-attr: true + nested-attributes: tunnel-udp-entry + - + name: tunnel-udp + attributes: + - + name: table + type: nest + nested-attributes: tunnel-udp-table - name: tunnel-info attributes:
@@ -685,7 +714,7 @@ doc: Partial family for Ethtool Netlink. - name: udp-ports type: nest - nested-attributes: tunnel-info-udp-table + nested-attributes: tunnel-udp - name: fec-stat attributes:
@@ -1357,10 +1386,16 @@ doc: Partial family for Ethtool Netlink. request: attributes: - header - reply: - attributes: - - header - - cable-test-ntf-nest + - + name: cable-test-ntf + doc: Cable test notification. + + attribute-set: cable-test-ntf + + event: + attributes: + - header + - status - name: cable-test-tdr-act doc: Cable test TDR.
@@ -1371,10 +1406,17 @@ doc: Partial family for Ethtool Netlink. request: attributes: - header - reply: - attributes: - - header - - cable-test-tdr-cfg + - + name: cable-test-tdr-ntf + doc: Cable test TDR notification. + + attribute-set: cable-test-tdr-ntf + + event: + attributes: + - header + - status + - nest - name: tunnel-info-get doc: Get tsinfo params.
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 9/12 netlink: specs: ethtool: untangle stats-get
In reply to Jakub KicinskiCode gen for stats is a bit of a challenge, but from looking at the attrs I think that the format isn't quite right.
--- Documentation/netlink/specs/ethtool.yaml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
Documentation/netlink/specs/ethtool.yaml +17 -4
@@ -793,16 +793,29 @@ doc: Partial family for Ethtool Netlink. type: u32 - name: stat - type: nest - nested-attributes: u64 + type: u64 + type-value: [ id ] - name: hist-rx type: nest - nested-attributes: u64 + nested-attributes: stats-grp-hist - name: hist-tx type: nest - nested-attributes: u64 + nested-attributes: stats-grp-hist + - + name: hist-bkt-low + type: u32 + - + name: hist-bkt-hi + type: u32 + - + name: hist-val + type: u64 + - + name: stats-grp-hist + subset-of: stats-grp + attributes: - name: hist-bkt-low type: u32
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 10/12 netlink: specs: ethtool: mark pads as pads
In reply to Jakub KicinskiPad is a separate type. Even though in practice they can only be a u32 the value should be discarded.
--- Documentation/netlink/specs/ethtool.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/netlink/specs/ethtool.yaml +4 -4
@@ -502,7 +502,7 @@ doc: Partial family for Ethtool Netlink. attributes: - name: pad - type: u32 + type: pad - name: tx-frames type: u64
@@ -720,7 +720,7 @@ doc: Partial family for Ethtool Netlink. attributes: - name: pad - type: u8 + type: pad - name: corrected type: binary
@@ -784,7 +784,7 @@ doc: Partial family for Ethtool Netlink. attributes: - name: pad - type: u32 + type: pad - name: id type: u32
@@ -830,7 +830,7 @@ doc: Partial family for Ethtool Netlink. attributes: - name: pad - type: u32 + type: pad - name: header type: nest
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerPATCH 11/12 tools: ynl: generate code for the ethtool family
In reply to Jakub KicinskiGenerate the protocol code for ethtool. Skip the stats for now, they are the only outlier in terms of complexity. Stats are a sort-of semi-polymorphic (attr space of a nest depends on value of another attr) or a type-value-scalar, depending on how one wants to look at it...
A challenge for another time.
--- tools/net/ynl/generated/Makefile | 9 +- tools/net/ynl/generated/ethtool-user.c | 6353 ++++++++++++++++++++++++ tools/net/ynl/generated/ethtool-user.h | 5531 +++++++++++++++++++++ 3 files changed, 11890 insertions(+), 3 deletions(-) create mode 100644 tools/net/ynl/generated/ethtool-user.c create mode 100644 tools/net/ynl/generated/ethtool-user.h
tools/net/ynl/generated/Makefile +6 -3
@@ -7,9 +7,12 @@ ifeq ("$(DEBUG)","1") CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan endif +YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \ + --exclude-op stats-get + TOOL:=../ynl-gen-c.py -GENS:=devlink handshake fou netdev +GENS:=ethtool devlink handshake fou netdev SRCS=$(patsubst %,%-user.c,${GENS}) HDRS=$(patsubst %,%-user.h,${GENS}) OBJS=$(patsubst %,%-user.o,${GENS})
@@ -22,11 +25,11 @@ protos.a: $(OBJS) %-user.h: ../../../../Documentation/netlink/specs/%.yaml $(TOOL) @echo -e "\tGEN $@" - @$(TOOL) --mode user --header --spec $< > $@ + @$(TOOL) --mode user --header --spec $< $(YNL_GEN_ARG_$*) > $@ %-user.c: ../../../../Documentation/netlink/specs/%.yaml $(TOOL) @echo -e "\tGEN $@" - @$(TOOL) --mode user --source --spec $< > $@ + @$(TOOL) --mode user --source --spec $< $(YNL_GEN_ARG_$*) > $@ %-user.o: %-user.c %-user.h @echo -e "\tCC $@"
tools/net/ynl/generated/ethtool-user.c new file +6353 -0
2,974 lines not on this page · raw message
tools/net/ynl/generated/ethtool-user.h new file +5531 -0
5,531 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.40.1
Part of the diff is not shown here. View the raw message.
Jakub Kicinski
maintainerPATCH 12/12 tools: ynl: add sample for ethtool
In reply to Jakub KicinskiConfiguring / reading ring sizes and counts is a fairly common operation for ethtool netlink. Present a sample doing that with YNL:
$ ./ethtool
Channels:
enp1s0: combined 1
eni1np1: combined 1
eni2np1: combined 1
Rings:
enp1s0: rx 256 tx 256
eni1np1: rx 0 tx 0
eni2np1: rx 0 tx 0--- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/ethtool.c | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tools/net/ynl/samples/ethtool.c
tools/net/ynl/samples/.gitignore +1 -0
@@ -1,2 +1,3 @@ +ethtool devlink netdev
tools/net/ynl/samples/ethtool.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.40.1
Quoted 32 lines · Jakub Kicinski
And finally ethtool support. Thanks to Stan's work the ethtool family spec is quite complete, so there is a lot of operations to support.
I chickened out of stats-get support, they require at the very least type-value support on a u64 scalar. Type-value is an arrangement where a u16 attribute is encoded directly in attribute type. Code gen can support this if the inside is a nest, we just throw in an extra field into that nest to carry the attr type. But a little more coding is needed to for a scalar, because first we need to turn the scalar into a struct with one member, then we can add the attr type.
Other than that ethtool required event support (notification which does not share contents with any GET), but the previous series already added that to the codegen.
I haven't tested all the ops here, and a few I tried seem to work.
Jakub Kicinski (12):
tools: ynl-gen: support excluding tricky ops
tools: ynl-gen: record extra args for regen
netlink: specs: support setting prefix-name per attribute
netlink: specs: ethtool: add C render hints
tools: ynl-gen: don't generate enum types if unnamed
tools: ynl-gen: resolve enum vs struct name conflicts
netlink: specs: ethtool: add empty enum stringset
netlink: specs: ethtool: untangle UDP tunnels and cable test a bit
netlink: specs: ethtool: untangle stats-get
netlink: specs: ethtool: mark pads as pads
tools: ynl: generate code for the ethtool family
tools: ynl: add sample for ethtool
Quoted 15 lines
Documentation/netlink/genetlink-c.yaml | 4 + Documentation/netlink/genetlink-legacy.yaml | 4 + Documentation/netlink/specs/ethtool.yaml | 120 +- tools/net/ynl/generated/Makefile | 9 +- tools/net/ynl/generated/ethtool-user.c | 6353 +++++++++++++++++++ tools/net/ynl/generated/ethtool-user.h | 5531 ++++++++++++++++ tools/net/ynl/lib/nlspec.py | 12 +- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/ethtool.c | 65 + tools/net/ynl/ynl-gen-c.py | 59 +- tools/net/ynl/ynl-regen.sh | 4 +- 11 files changed, 12116 insertions(+), 46 deletions(-) create mode 100644 tools/net/ynl/generated/ethtool-user.c create mode 100644 tools/net/ynl/generated/ethtool-user.h create mode 100644 tools/net/ynl/samples/ethtool.c
Exciting! Clicked through the series, everything makes sense:
Cable tests are yucky.
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 11 lines · On Fri, 9 Jun 2023 14:43:34 -0700 you wrote:
And finally ethtool support. Thanks to Stan's work the ethtool family spec is quite complete, so there is a lot of operations to support.
I chickened out of stats-get support, they require at the very least type-value support on a u64 scalar. Type-value is an arrangement where a u16 attribute is encoded directly in attribute type. Code gen can support this if the inside is a nest, we just throw in an extra field into that nest to carry the attr type. But a little more coding is needed to for a scalar, because first we need to turn the scalar into a struct with one member, then we can add the attr type.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,01/12] tools: ynl-gen: support excluding tricky ops
https://git.kernel.org/netdev/net-next/c/008bcd6835a2 - [net-next,02/12] tools: ynl-gen: record extra args for regen https://git.kernel.org/netdev/net-next/c/33eedb0071c8 - [net-next,03/12] netlink: specs: support setting prefix-name per attribute https://git.kernel.org/netdev/net-next/c/ed2042cc77f1 - [net-next,04/12] netlink: specs: ethtool: add C render hints https://git.kernel.org/netdev/net-next/c/d4813b11d679 - [net-next,05/12] tools: ynl-gen: don't generate enum types if unnamed https://git.kernel.org/netdev/net-next/c/dddc9f53da3e - [net-next,06/12] tools: ynl-gen: resolve enum vs struct name conflicts https://git.kernel.org/netdev/net-next/c/2c9d47a095f7 - [net-next,07/12] netlink: specs: ethtool: add empty enum stringset https://git.kernel.org/netdev/net-next/c/180ad455273a - [net-next,08/12] netlink: specs: ethtool: untangle UDP tunnels and cable test a bit https://git.kernel.org/netdev/net-next/c/37c852222712 - [net-next,09/12] netlink: specs: ethtool: untangle stats-get https://git.kernel.org/netdev/net-next/c/709d0c3b3d4c - [net-next,10/12] netlink: specs: ethtool: mark pads as pads https://git.kernel.org/netdev/net-next/c/68335713d2ea - [net-next,11/12] tools: ynl: generate code for the ethtool family https://git.kernel.org/netdev/net-next/c/2d7be507d65e - [net-next,12/12] tools: ynl: add sample for ethtool https://git.kernel.org/netdev/net-next/c/f561ff232a6b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html