From nobody Fri Nov 22 22:35:40 2024 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D71151E231D; Fri, 15 Nov 2024 19:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731699414; cv=none; b=llwYPUrZhbMxdvMXkdGfFySlVMARjTD5SESOrmoC62UR8JMnqa5edm+Rf1R8ZVnJjxlY3k96FucdhMzuWbYj09iDKRjkPuJ5yWvpjj68OQ+pfvVmAFyFA/yKjzpAHpiw0RavwFhNjK2sjRRmxFOJOJ9js9HMJJC/6bhi8GoWXG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731699414; c=relaxed/simple; bh=YOg3gjQeCmu3PGtzkKN/uoxNDEFbfr1TI3Lssf5OECo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VHw+BlgSHNovDb/IQ8VWEG7T8C+0x1Om1n/1nLQI1O/j7knLCC81ZkTwtO8h05H1cEsJ9hgl+Tw/GyVpRCSrg2wZTa/zDHzRb5RAUE6qwaSRPUTEfo3emDVbcz+qEjvATyKlcqmEYd6bCaae0xdoXveRoX2Dhv8il/KCjlXgktY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20cb7139d9dso23723055ad.1; Fri, 15 Nov 2024 11:36:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731699412; x=1732304212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xd49IMPW8HB/K3Il5x15g7iaHPzUwpcdvWbm5eV+/NI=; b=kWpWbdAH8faLz1m6Oe3PEkWn5VWZGDjilFkYxn9Oc6/v2O3DzEsyldNJLOV+C8DYeK OW6jtQktaNsLJH2vYVQdEZpX1WCclHBsRB3C9OWZZ/EkwCl3zspvq1X6V14xBKHVi1x1 T5fqmbmlmeSfEiWEdPXRV4kt1JtguelUQL1SuMzy5PfGZmgzUslklnttMmsgwkIMi5g+ tUo+qtv9v8mpqlyItBQplsB8MQ3DQBYUY7kMd+EnYuaQA5Hx3A5jFe0pvJEVQOfA3PQL lzvPZd5caOmaJwXxPI8wFhzCfCZEZblOkHnzUHo1tAofPFSvZsui7VR4Myn9/fFAS86v fVxA== X-Forwarded-Encrypted: i=1; AJvYcCW2ZSzYUvLaTOMovGkLQl3NQGtrSGH2BpLu9dGI3mc07sFI0Blq0OR2U2s47B6FRpV7QLybuUHmXyI=@vger.kernel.org, AJvYcCWi5YdGbC5dP66n0vKG2qq96j0zUbbcRg4uVuZaxcInF5TbqXujb8sBx8YYAa8r3AtaiBsSj/vzZjaCsSGp@vger.kernel.org X-Gm-Message-State: AOJu0YwM6uCDmEjZgrQvg0OmyDz7/DfDO+cXmNCkec/u/u5zcRubNeSR j7vcnsX/hAMElVw5dqHY+/zAThWXHdO1lKPHEKRI+qioL3qPeYCTbdqD0H0= X-Google-Smtp-Source: AGHT+IF13fZsqQYvQ0+oMWRWXuGibAGGMQBftQqFf0Hi8uMzS6MG/5fsY8Rq3AL32AmKSnaQSvFJZg== X-Received: by 2002:a17:902:d48c:b0:20c:94f6:3e03 with SMTP id d9443c01a7336-211d0ed2e36mr56282275ad.47.1731699411591; Fri, 15 Nov 2024 11:36:51 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0ecc6a4sm16148095ad.94.2024.11.15.11.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 11:36:51 -0800 (PST) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, donald.hunter@gmail.com, horms@kernel.org, corbet@lwn.net, andrew+netdev@lunn.ch, kory.maincent@bootlin.com, sdf@fomichev.me Subject: [PATCH net-next v2 3/8] ynl: support directional specs in ynl-gen-c.py Date: Fri, 15 Nov 2024 11:36:41 -0800 Message-ID: <20241115193646.1340825-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115193646.1340825-1-sdf@fomichev.me> References: <20241115193646.1340825-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The intent is to generate ethtool uapi headers. For now, some of the things are hard-coded: - _MSG_{USER,KERNEL}_MAX - the split between USER and KERNEL messages Signed-off-by: Stanislav Fomichev --- tools/net/ynl/ynl-gen-c.py | 118 +++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 31 deletions(-) diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py index 8ba252973c2d..e5ac6f89b78a 100755 --- a/tools/net/ynl/ynl-gen-c.py +++ b/tools/net/ynl/ynl-gen-c.py @@ -2419,6 +2419,87 @@ _C_KW =3D { cw.block_start(line=3Dstart_line) =20 =20 +def render_uapi_unified(family, cw, max_by_define, separate_ntf): + max_name =3D c_upper(family.get('cmd-max-name', f"{family.op_prefix}MA= X")) + cnt_name =3D c_upper(family.get('cmd-cnt-name', f"__{family.op_prefix}= MAX")) + max_value =3D f"({cnt_name} - 1)" + + uapi_enum_start(family, cw, family['operations'], 'enum-name') + val =3D 0 + for op in family.msgs.values(): + if separate_ntf and ('notify' in op or 'event' in op): + continue + + suffix =3D ',' + if op.value !=3D val: + suffix =3D f" =3D {op.value}," + val =3D op.value + cw.p(op.enum_name + suffix) + val +=3D 1 + cw.nl() + cw.p(cnt_name + ('' if max_by_define else ',')) + if not max_by_define: + cw.p(f"{max_name} =3D {max_value}") + cw.block_end(line=3D';') + if max_by_define: + cw.p(f"#define {max_name} {max_value}") + cw.nl() + + +def render_uapi_directional(family, cw, max_by_define): + max_name =3D f"{family.op_prefix}USER_MAX" + cnt_name =3D f"__{family.op_prefix}USER_CNT" + max_value =3D f"({cnt_name} - 1)" + + cw.block_start(line=3D'enum') + cw.p(c_upper(f'{family.name}_MSG_USER_NONE =3D 0,')) + val =3D 0 + for op in family.msgs.values(): + if 'do' in op and 'event' not in op: + suffix =3D ',' + if op.value and op.value !=3D val: + suffix =3D f" =3D {op.value}," + val =3D op.value + cw.p(op.enum_name + suffix) + val +=3D 1 + cw.nl() + cw.p(cnt_name + ('' if max_by_define else ',')) + if not max_by_define: + cw.p(f"{max_name} =3D {max_value}") + cw.block_end(line=3D';') + if max_by_define: + cw.p(f"#define {max_name} {max_value}") + cw.nl() + + max_name =3D f"{family.op_prefix}KERNEL_MAX" + cnt_name =3D f"__{family.op_prefix}KERNEL_CNT" + max_value =3D f"({cnt_name} - 1)" + + cw.block_start(line=3D'enum') + cw.p(c_upper(f'{family.name}_MSG_KERNEL_NONE =3D 0,')) + val =3D 0 + for op in family.msgs.values(): + if ('do' in op and 'reply' in op['do']) or 'notify' in op or 'even= t' in op: + enum_name =3D op.enum_name + if 'event' not in op and 'notify' not in op: + enum_name =3D f'{enum_name}_REPLY' + + suffix =3D ',' + if op.value and op.value !=3D val: + suffix =3D f" =3D {op.value}," + val =3D op.value + cw.p(enum_name + suffix) + val +=3D 1 + cw.nl() + cw.p(cnt_name + ('' if max_by_define else ',')) + if not max_by_define: + cw.p(f"{max_name} =3D {max_value}") + cw.block_end(line=3D';') + if max_by_define: + cw.p(f"#define {max_name} {max_value}") + cw.nl() + + def render_uapi(family, cw): hdr_prot =3D f"_UAPI_LINUX_{c_upper(family.uapi_header_name)}_H" cw.p('#ifndef ' + hdr_prot) @@ -2522,30 +2603,12 @@ _C_KW =3D { # Commands separate_ntf =3D 'async-prefix' in family['operations'] =20 - max_name =3D c_upper(family.get('cmd-max-name', f"{family.op_prefix}MA= X")) - cnt_name =3D c_upper(family.get('cmd-cnt-name', f"__{family.op_prefix}= MAX")) - max_value =3D f"({cnt_name} - 1)" - - uapi_enum_start(family, cw, family['operations'], 'enum-name') - val =3D 0 - for op in family.msgs.values(): - if separate_ntf and ('notify' in op or 'event' in op): - continue - - suffix =3D ',' - if op.value !=3D val: - suffix =3D f" =3D {op.value}," - val =3D op.value - cw.p(op.enum_name + suffix) - val +=3D 1 - cw.nl() - cw.p(cnt_name + ('' if max_by_define else ',')) - if not max_by_define: - cw.p(f"{max_name} =3D {max_value}") - cw.block_end(line=3D';') - if max_by_define: - cw.p(f"#define {max_name} {max_value}") - cw.nl() + if family.msg_id_model =3D=3D 'unified': + render_uapi_unified(family, cw, max_by_define, separate_ntf) + elif family.msg_id_model =3D=3D 'directional': + render_uapi_directional(family, cw, max_by_define) + else: + raise Exception(f'Unsupported enum-model {family.msg_id_model}') =20 if separate_ntf: uapi_enum_start(family, cw, family['operations'], enum_name=3D'asy= nc-enum') @@ -2669,13 +2732,6 @@ _C_KW =3D { os.sys.exit(1) return =20 - supported_models =3D ['unified'] - if args.mode in ['user', 'kernel']: - supported_models +=3D ['directional'] - if parsed.msg_id_model not in supported_models: - print(f'Message enum-model {parsed.msg_id_model} not supported for= {args.mode} generation') - os.sys.exit(1) - cw =3D CodeWriter(BaseNlLib(), args.out_file, overwrite=3D(not args.cm= p_out)) =20 _, spec_kernel =3D find_kernel_root(args.spec) --=20 2.47.0