netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 10/12] tools: ynl-gen: support code gen for events
Date: Thu,  8 Jun 2023 14:11:58 -0700	[thread overview]
Message-ID: <20230608211200.1247213-11-kuba@kernel.org> (raw)
In-Reply-To: <20230608211200.1247213-1-kuba@kernel.org>

Netlink specs support both events and notifications (former can
define their own message contents). Plug in missing code to
generate types, parsers and include events into notification
tables.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/lib/nlspec.py |  2 +-
 tools/net/ynl/ynl-gen-c.py  | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index 623c5702bd10..c5d4a6d476a0 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -423,7 +423,7 @@ jsonschema = None
         self.fixed_header = self.yaml['operations'].get('fixed-header')
         req_val = rsp_val = 1
         for elem in self.yaml['operations']['list']:
-            if 'notify' in elem:
+            if 'notify' in elem or 'event' in elem:
                 if 'value' in elem:
                     rsp_val = elem['value']
                 req_val_next = req_val
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index a230598d216f..ccd73f10384c 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -828,7 +828,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
                 }
 
     def _load_root_sets(self):
-        for op_name, op in self.ops.items():
+        for op_name, op in self.msgs.items():
             if 'attribute-set' not in op:
                 continue
 
@@ -839,6 +839,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
                     req_attrs.update(set(op[op_mode]['request']['attributes']))
                 if op_mode in op and 'reply' in op[op_mode]:
                     rsp_attrs.update(set(op[op_mode]['reply']['attributes']))
+            if 'event' in op:
+                rsp_attrs.update(set(op['event']['attributes']))
 
             if op['attribute-set'] not in self.root_sets:
                 self.root_sets[op['attribute-set']] = {'request': req_attrs, 'reply': rsp_attrs}
@@ -2193,10 +2195,13 @@ _C_KW = {
     if family.ntfs:
         cw.block_start(line=f"static const struct ynl_ntf_info {family['name']}_ntf_info[] = ")
         for ntf_op_name, ntf_op in family.ntfs.items():
-            if 'notify' not in ntf_op:
-                continue
-            op = family.ops[ntf_op['notify']]
-            ri = RenderInfo(cw, family, "user", op, op.name, "notify")
+            if 'notify' in ntf_op:
+                op = family.ops[ntf_op['notify']]
+                ri = RenderInfo(cw, family, "user", op, op.name, "notify")
+            elif 'event' in ntf_op:
+                ri = RenderInfo(cw, family, "user", ntf_op, ntf_op_name, "event")
+            else:
+                raise Exception('Invalid notification ' + ntf_op_name)
             _render_user_ntf_entry(ri, ntf_op)
         for op_name, op in family.ops.items():
             if 'event' not in op:
@@ -2424,6 +2429,7 @@ _C_KW = {
                         raise Exception(f'Only notifications with consistent types supported ({op.name})')
                     print_wrapped_type(ri)
 
+            for op_name, op in parsed.ntfs.items():
                 if 'event' in op:
                     ri = RenderInfo(cw, parsed, args.mode, op, op_name, 'event')
                     cw.p(f"/* {op.enum_name} - event */")
@@ -2485,6 +2491,7 @@ _C_KW = {
                         raise Exception(f'Only notifications with consistent types supported ({op.name})')
                     print_ntf_type_free(ri)
 
+            for op_name, op in parsed.ntfs.items():
                 if 'event' in op:
                     cw.p(f"/* {op.enum_name} - event */")
 
-- 
2.40.1


  parent reply	other threads:[~2023-06-08 21:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08 21:11 [PATCH net-next 00/12] tools: ynl-gen: code gen improvements before ethtool Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 01/12] tools: ynl-gen: cleanup user space header includes Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 02/12] tools: ynl: regen: " Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 03/12] tools: ynl-gen: complete the C keyword list Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 04/12] tools: ynl-gen: combine else with closing bracket Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 05/12] tools: ynl-gen: get attr type outside of if() Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 06/12] tools: ynl: regen: regenerate the if ladders Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 07/12] tools: ynl-gen: stop generating common notification handlers Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 08/12] tools: ynl: regen: " Jakub Kicinski
2023-06-08 21:11 ` [PATCH net-next 09/12] tools: ynl-gen: sanitize notification tracking Jakub Kicinski
2023-06-08 21:11 ` Jakub Kicinski [this message]
2023-06-08 21:11 ` [PATCH net-next 11/12] tools: ynl-gen: don't pass op_name to RenderInfo Jakub Kicinski
2023-06-08 21:12 ` [PATCH net-next 12/12] tools: ynl-gen: support / skip pads on the way to kernel Jakub Kicinski
2023-06-09 21:50 ` [PATCH net-next 00/12] tools: ynl-gen: code gen improvements before ethtool patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230608211200.1247213-11-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).