Commit a9c47697 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'tools-ynl-gen-improvements-for-dpll'

Jakub Kicinski says:

====================
tools: ynl-gen: improvements for DPLL

A set of improvements needed to generate the kernel code for DPLL.
====================

Link: https://lore.kernel.org/r/20230612155920.1787579-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 6b5f9a87 be093a80
...@@ -300,8 +300,10 @@ class TypeScalar(Type): ...@@ -300,8 +300,10 @@ class TypeScalar(Type):
return f"NLA_POLICY_MIN({policy}, {self.checks['min']})" return f"NLA_POLICY_MIN({policy}, {self.checks['min']})"
elif 'enum' in self.attr: elif 'enum' in self.attr:
enum = self.family.consts[self.attr['enum']] enum = self.family.consts[self.attr['enum']]
cnt = len(enum['entries']) low, high = enum.value_range()
return f"NLA_POLICY_MAX({policy}, {cnt - 1})" if low == 0:
return f"NLA_POLICY_MAX({policy}, {high})"
return f"NLA_POLICY_RANGE({policy}, {low}, {high})"
return super()._attr_policy(policy) return super()._attr_policy(policy)
def _attr_typol(self): def _attr_typol(self):
...@@ -460,6 +462,11 @@ class TypeNest(Type): ...@@ -460,6 +462,11 @@ class TypeNest(Type):
class TypeMultiAttr(Type): class TypeMultiAttr(Type):
def __init__(self, family, attr_set, attr, value, base_type):
super().__init__(family, attr_set, attr, value)
self.base_type = base_type
def is_multi_val(self): def is_multi_val(self):
return True return True
...@@ -495,13 +502,11 @@ class TypeMultiAttr(Type): ...@@ -495,13 +502,11 @@ class TypeMultiAttr(Type):
else: else:
raise Exception(f"Free of MultiAttr sub-type {self.attr['type']} not supported yet") raise Exception(f"Free of MultiAttr sub-type {self.attr['type']} not supported yet")
def _attr_policy(self, policy):
return self.base_type._attr_policy(policy)
def _attr_typol(self): def _attr_typol(self):
if 'type' not in self.attr or self.attr['type'] == 'nest': return self.base_type._attr_typol()
return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
elif self.attr['type'] in scalars:
return f".type = YNL_PT_U{self.attr['type'][1:]}, "
else:
raise Exception(f"Sub-type {self.attr['type']} not supported yet")
def _attr_get(self, ri, var): def _attr_get(self, ri, var):
return f'n_{self.c_name}++;', None, None return f'n_{self.c_name}++;', None, None
...@@ -676,6 +681,15 @@ class EnumSet(SpecEnumSet): ...@@ -676,6 +681,15 @@ class EnumSet(SpecEnumSet):
def new_entry(self, entry, prev_entry, value_start): def new_entry(self, entry, prev_entry, value_start):
return EnumEntry(self, entry, prev_entry, value_start) return EnumEntry(self, entry, prev_entry, value_start)
def value_range(self):
low = min([x.value for x in self.entries.values()])
high = max([x.value for x in self.entries.values()])
if high - low + 1 != len(self.entries):
raise Exception("Can't get value range for a noncontiguous enum")
return low, high
class AttrSet(SpecAttrSet): class AttrSet(SpecAttrSet):
def __init__(self, family, yaml): def __init__(self, family, yaml):
...@@ -706,29 +720,32 @@ class AttrSet(SpecAttrSet): ...@@ -706,29 +720,32 @@ class AttrSet(SpecAttrSet):
self.c_name = '' self.c_name = ''
def new_attr(self, elem, value): def new_attr(self, elem, value):
if 'multi-attr' in elem and elem['multi-attr']: if elem['type'] in scalars:
return TypeMultiAttr(self.family, self, elem, value) t = TypeScalar(self.family, self, elem, value)
elif elem['type'] in scalars:
return TypeScalar(self.family, self, elem, value)
elif elem['type'] == 'unused': elif elem['type'] == 'unused':
return TypeUnused(self.family, self, elem, value) t = TypeUnused(self.family, self, elem, value)
elif elem['type'] == 'pad': elif elem['type'] == 'pad':
return TypePad(self.family, self, elem, value) t = TypePad(self.family, self, elem, value)
elif elem['type'] == 'flag': elif elem['type'] == 'flag':
return TypeFlag(self.family, self, elem, value) t = TypeFlag(self.family, self, elem, value)
elif elem['type'] == 'string': elif elem['type'] == 'string':
return TypeString(self.family, self, elem, value) t = TypeString(self.family, self, elem, value)
elif elem['type'] == 'binary': elif elem['type'] == 'binary':
return TypeBinary(self.family, self, elem, value) t = TypeBinary(self.family, self, elem, value)
elif elem['type'] == 'nest': elif elem['type'] == 'nest':
return TypeNest(self.family, self, elem, value) t = TypeNest(self.family, self, elem, value)
elif elem['type'] == 'array-nest': elif elem['type'] == 'array-nest':
return TypeArrayNest(self.family, self, elem, value) t = TypeArrayNest(self.family, self, elem, value)
elif elem['type'] == 'nest-type-value': elif elem['type'] == 'nest-type-value':
return TypeNestTypeValue(self.family, self, elem, value) t = TypeNestTypeValue(self.family, self, elem, value)
else: else:
raise Exception(f"No typed class for type {elem['type']}") raise Exception(f"No typed class for type {elem['type']}")
if 'multi-attr' in elem and elem['multi-attr']:
t = TypeMultiAttr(self.family, self, elem, value, t)
return t
class Operation(SpecOperation): class Operation(SpecOperation):
def __init__(self, family, yaml, req_value, rsp_value): def __init__(self, family, yaml, req_value, rsp_value):
......
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