Commit ad4fafcd authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

tools: ynl: use 1 as the default for first entry in attrs/ops

Pretty much all families use value: 1 or reserve as unspec
the first entry in attribute set and the first operation.
Make this the default. Update documentation (the doc for
values of operations just refers back to doc for attrs
so updating only attrs).
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7cf93538
...@@ -197,7 +197,12 @@ value ...@@ -197,7 +197,12 @@ value
Numerical attribute ID, used in serialized Netlink messages. Numerical attribute ID, used in serialized Netlink messages.
The ``value`` property can be skipped, in which case the attribute ID The ``value`` property can be skipped, in which case the attribute ID
will be the value of the previous attribute plus one (recursively) will be the value of the previous attribute plus one (recursively)
and ``0`` for the first attribute in the attribute set. and ``1`` for the first attribute in the attribute set.
Attributes (and operations) use ``1`` as the default value for the first
entry (unlike enums in definitions which start from ``0``) because
entry ``0`` is almost always reserved as undefined. Spec can explicitly
set value to ``0`` if needed.
Note that the ``value`` of an attribute is defined only in its main set Note that the ``value`` of an attribute is defined only in its main set
(not in subsets). (not in subsets).
......
...@@ -96,7 +96,7 @@ class SpecAttrSet(SpecElement): ...@@ -96,7 +96,7 @@ class SpecAttrSet(SpecElement):
self.attrs_by_val = collections.OrderedDict() self.attrs_by_val = collections.OrderedDict()
if self.subset_of is None: if self.subset_of is None:
val = 0 val = 1
for elem in self.yaml['attributes']: for elem in self.yaml['attributes']:
if 'value' in elem: if 'value' in elem:
val = elem['value'] val = elem['value']
...@@ -252,7 +252,7 @@ class SpecFamily(SpecElement): ...@@ -252,7 +252,7 @@ class SpecFamily(SpecElement):
self._resolution_list.append(elem) self._resolution_list.append(elem)
def _dictify_ops_unified(self): def _dictify_ops_unified(self):
val = 0 val = 1
for elem in self.yaml['operations']['list']: for elem in self.yaml['operations']['list']:
if 'value' in elem: if 'value' in elem:
val = elem['value'] val = elem['value']
...@@ -263,7 +263,7 @@ class SpecFamily(SpecElement): ...@@ -263,7 +263,7 @@ class SpecFamily(SpecElement):
self.msgs[op.name] = op self.msgs[op.name] = op
def _dictify_ops_directional(self): def _dictify_ops_directional(self):
req_val = rsp_val = 0 req_val = rsp_val = 1
for elem in self.yaml['operations']['list']: for elem in self.yaml['operations']['list']:
if 'notify' in elem: if 'notify' in elem:
if 'value' in elem: if 'value' in elem:
......
...@@ -2044,14 +2044,17 @@ def render_uapi(family, cw): ...@@ -2044,14 +2044,17 @@ def render_uapi(family, cw):
max_value = f"({cnt_name} - 1)" max_value = f"({cnt_name} - 1)"
uapi_enum_start(family, cw, family['operations'], 'enum-name') uapi_enum_start(family, cw, family['operations'], 'enum-name')
val = 0
for op in family.msgs.values(): for op in family.msgs.values():
if separate_ntf and ('notify' in op or 'event' in op): if separate_ntf and ('notify' in op or 'event' in op):
continue continue
suffix = ',' suffix = ','
if 'value' in op: if op.value != val:
suffix = f" = {op['value']}," suffix = f" = {op.value},"
val = op.value
cw.p(op.enum_name + suffix) cw.p(op.enum_name + suffix)
val += 1
cw.nl() cw.nl()
cw.p(cnt_name + ('' if max_by_define else ',')) cw.p(cnt_name + ('' if max_by_define else ','))
if not max_by_define: if not max_by_define:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment