Netdev List
 help / color / mirror / Atom feed
* [PATCH 1/2] ethtool: Add generic structure and functions for named flags
@ 2010-05-18 16:32 Ben Hutchings
  2010-05-18 16:33 ` [PATCH 2/2] ethtool: Implement named message type flags Ben Hutchings
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Hutchings @ 2010-05-18 16:32 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: netdev, sf-linux-drivers

This will be used to support named message type flags.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
 ethtool.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 4226a67..7004b7f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -355,6 +355,12 @@ struct cmdline_info {
 	void *ioctl_val;
 };
 
+struct named_flag {
+	const char *name;
+	u32 flag;
+	int *wanted;
+};
+
 static struct cmdline_info cmdline_gregs[] = {
 	{ "raw", CMDL_BOOL, &gregs_dump_raw, NULL },
 	{ "hex", CMDL_BOOL, &gregs_dump_hex, NULL },
@@ -520,6 +526,41 @@ static void parse_generic_cmdline(int argc, char **argp,
 	}
 }
 
+static void
+print_flags(const struct named_flag *flags, unsigned int n_flags, u32 value)
+{
+	const char *sep = "";
+
+	while (n_flags) {
+		if (value & flags->flag) {
+			printf("%s%s", sep, flags->name);
+			sep = " ";
+			value &= ~flags->flag;
+		}
+		++flags;
+		--n_flags;
+	}
+
+	/* Print any unrecognised flags in hex */
+	if (value)
+		printf("%s%#x", sep, value);
+}
+
+static u32
+update_flags(const struct named_flag *flags, unsigned int n_flags, u32 value)
+{
+	while (n_flags) {
+		if (*flags->wanted == 0)
+			value &= ~flags->flag;
+		else if (*flags->wanted == 1)
+			value |= flags->flag;
+		++flags;
+		--n_flags;
+	}
+
+	return value;
+}
+
 static int rxflow_str_to_type(const char *str)
 {
 	int flow_type = 0;
-- 
1.6.2.5


-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-18 16:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-18 16:32 [PATCH 1/2] ethtool: Add generic structure and functions for named flags Ben Hutchings
2010-05-18 16:33 ` [PATCH 2/2] ethtool: Implement named message type flags Ben Hutchings

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox