Re: [ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
On Fri, 2016-03-25 at 09:21 -0700, David Decotigny wrote: > From: David Decotigny > > More info with kernel commit 8d3f2806f8fb ("Merge branch > 'ethtool-ksettings'"). > > Note: The new features implemented in this patch depend on kernel > commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to > wrong nwords"). [...] Applied, with some style changes. Thanks for your patience. Ben. -- Ben Hutchings compatible: Gracefully accepts erroneous data from any source signature.asc Description: This is a digitally signed message part
Re: [ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
Acked-by:Vidya Sagar Ravipati Validated this patch with various modules. Replied from wrong email alias earlier. On Thu, Jun 9, 2016 at 5:55 PM, David Decotigny wrote: > From: David Decotigny > > More info with kernel commit 8d3f2806f8fb ("Merge branch > 'ethtool-ksettings'"). > > Note: The new features implemented in this patch depend on kernel > commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to > wrong nwords"). > > > Signed-off-by: David Decotigny > --- > ethtool.c | 681 > - > internal.h | 67 ++ > test-cmdline.c | 13 ++ > 3 files changed, 603 insertions(+), 158 deletions(-) > > diff --git a/ethtool.c b/ethtool.c > index 0cd0d4f..cb3d971 100644 > --- a/ethtool.c > +++ b/ethtool.c > @@ -47,42 +47,6 @@ > #define MAX_ADDR_LEN 32 > #endif > > -#define ALL_ADVERTISED_MODES \ > - (ADVERTISED_10baseT_Half | \ > -ADVERTISED_10baseT_Full | \ > -ADVERTISED_100baseT_Half | \ > -ADVERTISED_100baseT_Full | \ > -ADVERTISED_1000baseT_Half |\ > -ADVERTISED_1000baseT_Full |\ > -ADVERTISED_1000baseKX_Full|\ > -ADVERTISED_2500baseX_Full |\ > -ADVERTISED_1baseT_Full | \ > -ADVERTISED_1baseKX4_Full | \ > -ADVERTISED_1baseKR_Full | \ > -ADVERTISED_1baseR_FEC |\ > -ADVERTISED_2baseMLD2_Full |\ > -ADVERTISED_2baseKR2_Full | \ > -ADVERTISED_4baseKR4_Full | \ > -ADVERTISED_4baseCR4_Full | \ > -ADVERTISED_4baseSR4_Full | \ > -ADVERTISED_4baseLR4_Full | \ > -ADVERTISED_56000baseKR4_Full | \ > -ADVERTISED_56000baseCR4_Full | \ > -ADVERTISED_56000baseSR4_Full | \ > -ADVERTISED_56000baseLR4_Full) > - > -#define ALL_ADVERTISED_FLAGS \ > - (ADVERTISED_Autoneg | \ > -ADVERTISED_TP |\ > -ADVERTISED_AUI | \ > -ADVERTISED_MII | \ > -ADVERTISED_FIBRE | \ > -ADVERTISED_BNC | \ > -ADVERTISED_Pause | \ > -ADVERTISED_Asym_Pause |\ > -ADVERTISED_Backplane | \ > -ALL_ADVERTISED_MODES) > - > #ifndef HAVE_NETIF_MSG > enum { > NETIF_MSG_DRV = 0x0001, > @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) > } > } > > +static int parse_hex_u32_bitmap(const char *s, > + unsigned int nbits, u32 *result) > +{ > + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); > + size_t slen = strlen(s); > + size_t i; > + > + /* ignore optional '0x' prefix */ > + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { > + slen -= 2; > + s += 2; > + } > + > + if (slen > 8 * nwords) /* up to 2 digits per byte */ > + return -1; > + > + memset(result, 0, 4 * nwords); > + for (i = 0 ; i < slen ; ++i) { > + const unsigned int shift = (slen - 1 - i) * 4; > + u32 *dest = &result[shift / 32]; > + u32 nibble; > + > + if ('a' <= s[i] && s[i] <= 'f') > + nibble = 0xa + (s[i] - 'a'); > + else if ('A' <= s[i] && s[i] <= 'F') > + nibble = 0xa + (s[i] - 'A'); > + else if ('0' <= s[i] && s[i] <= '9') > + nibble = (s[i] - '0'); > + else > + return -1; > + > + *dest |= (nibble << (shift % 32)); > + } > + > + return 0; > +} > + > static void parse_generic_cmdline(struct cmd_context *ctx, > int *changed, > struct cmdline_info *info, > @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) > return 0; > } > > -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 > mask, > - int link_mode_only); > +/* link mode routines */ > > -static void dump_supported(struct ethtool_cmd *ep) > +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); > +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); > + > +static void init_global_link_mode_masks(void) > { > - u32 mask = ep->supported; > + static const enum ethtool_link_mode_bit_indices > + all_advertised_modes_bits[] = { > + ETHTOOL_LINK_MODE_10baseT_Half_BIT, > + ETHTOOL_LINK_MODE_10baseT_Full_BIT, > + ETHTOOL_LINK_MODE_100
Re: [ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
Acked-by:Vidya Sagar Ravipati Validated this patch with various modules. On Thu, Jun 9, 2016 at 5:55 PM, David Decotigny wrote: > From: David Decotigny > > More info with kernel commit 8d3f2806f8fb ("Merge branch > 'ethtool-ksettings'"). > > Note: The new features implemented in this patch depend on kernel > commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to > wrong nwords"). > > > Signed-off-by: David Decotigny > --- > ethtool.c | 681 > - > internal.h | 67 ++ > test-cmdline.c | 13 ++ > 3 files changed, 603 insertions(+), 158 deletions(-) > > diff --git a/ethtool.c b/ethtool.c > index 0cd0d4f..cb3d971 100644 > --- a/ethtool.c > +++ b/ethtool.c > @@ -47,42 +47,6 @@ > #define MAX_ADDR_LEN 32 > #endif > > -#define ALL_ADVERTISED_MODES \ > - (ADVERTISED_10baseT_Half | \ > -ADVERTISED_10baseT_Full | \ > -ADVERTISED_100baseT_Half | \ > -ADVERTISED_100baseT_Full | \ > -ADVERTISED_1000baseT_Half |\ > -ADVERTISED_1000baseT_Full |\ > -ADVERTISED_1000baseKX_Full|\ > -ADVERTISED_2500baseX_Full |\ > -ADVERTISED_1baseT_Full | \ > -ADVERTISED_1baseKX4_Full | \ > -ADVERTISED_1baseKR_Full | \ > -ADVERTISED_1baseR_FEC |\ > -ADVERTISED_2baseMLD2_Full |\ > -ADVERTISED_2baseKR2_Full | \ > -ADVERTISED_4baseKR4_Full | \ > -ADVERTISED_4baseCR4_Full | \ > -ADVERTISED_4baseSR4_Full | \ > -ADVERTISED_4baseLR4_Full | \ > -ADVERTISED_56000baseKR4_Full | \ > -ADVERTISED_56000baseCR4_Full | \ > -ADVERTISED_56000baseSR4_Full | \ > -ADVERTISED_56000baseLR4_Full) > - > -#define ALL_ADVERTISED_FLAGS \ > - (ADVERTISED_Autoneg | \ > -ADVERTISED_TP |\ > -ADVERTISED_AUI | \ > -ADVERTISED_MII | \ > -ADVERTISED_FIBRE | \ > -ADVERTISED_BNC | \ > -ADVERTISED_Pause | \ > -ADVERTISED_Asym_Pause |\ > -ADVERTISED_Backplane | \ > -ALL_ADVERTISED_MODES) > - > #ifndef HAVE_NETIF_MSG > enum { > NETIF_MSG_DRV = 0x0001, > @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) > } > } > > +static int parse_hex_u32_bitmap(const char *s, > + unsigned int nbits, u32 *result) > +{ > + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); > + size_t slen = strlen(s); > + size_t i; > + > + /* ignore optional '0x' prefix */ > + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { > + slen -= 2; > + s += 2; > + } > + > + if (slen > 8 * nwords) /* up to 2 digits per byte */ > + return -1; > + > + memset(result, 0, 4 * nwords); > + for (i = 0 ; i < slen ; ++i) { > + const unsigned int shift = (slen - 1 - i) * 4; > + u32 *dest = &result[shift / 32]; > + u32 nibble; > + > + if ('a' <= s[i] && s[i] <= 'f') > + nibble = 0xa + (s[i] - 'a'); > + else if ('A' <= s[i] && s[i] <= 'F') > + nibble = 0xa + (s[i] - 'A'); > + else if ('0' <= s[i] && s[i] <= '9') > + nibble = (s[i] - '0'); > + else > + return -1; > + > + *dest |= (nibble << (shift % 32)); > + } > + > + return 0; > +} > + > static void parse_generic_cmdline(struct cmd_context *ctx, > int *changed, > struct cmdline_info *info, > @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) > return 0; > } > > -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 > mask, > - int link_mode_only); > +/* link mode routines */ > > -static void dump_supported(struct ethtool_cmd *ep) > +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); > +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); > + > +static void init_global_link_mode_masks(void) > { > - u32 mask = ep->supported; > + static const enum ethtool_link_mode_bit_indices > + all_advertised_modes_bits[] = { > + ETHTOOL_LINK_MODE_10baseT_Half_BIT, > + ETHTOOL_LINK_MODE_10baseT_Full_BIT, > + ETHTOOL_LINK_MODE_100baseT_Half_BIT, > + ETHTOOL
[ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
From: David Decotigny More info with kernel commit 8d3f2806f8fb ("Merge branch 'ethtool-ksettings'"). Note: The new features implemented in this patch depend on kernel commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to wrong nwords"). Signed-off-by: David Decotigny --- ethtool.c | 681 - internal.h | 67 ++ test-cmdline.c | 13 ++ 3 files changed, 603 insertions(+), 158 deletions(-) diff --git a/ethtool.c b/ethtool.c index 0cd0d4f..cb3d971 100644 --- a/ethtool.c +++ b/ethtool.c @@ -47,42 +47,6 @@ #define MAX_ADDR_LEN 32 #endif -#define ALL_ADVERTISED_MODES \ - (ADVERTISED_10baseT_Half | \ -ADVERTISED_10baseT_Full | \ -ADVERTISED_100baseT_Half | \ -ADVERTISED_100baseT_Full | \ -ADVERTISED_1000baseT_Half |\ -ADVERTISED_1000baseT_Full |\ -ADVERTISED_1000baseKX_Full|\ -ADVERTISED_2500baseX_Full |\ -ADVERTISED_1baseT_Full | \ -ADVERTISED_1baseKX4_Full | \ -ADVERTISED_1baseKR_Full | \ -ADVERTISED_1baseR_FEC |\ -ADVERTISED_2baseMLD2_Full |\ -ADVERTISED_2baseKR2_Full | \ -ADVERTISED_4baseKR4_Full | \ -ADVERTISED_4baseCR4_Full | \ -ADVERTISED_4baseSR4_Full | \ -ADVERTISED_4baseLR4_Full | \ -ADVERTISED_56000baseKR4_Full | \ -ADVERTISED_56000baseCR4_Full | \ -ADVERTISED_56000baseSR4_Full | \ -ADVERTISED_56000baseLR4_Full) - -#define ALL_ADVERTISED_FLAGS \ - (ADVERTISED_Autoneg | \ -ADVERTISED_TP |\ -ADVERTISED_AUI | \ -ADVERTISED_MII | \ -ADVERTISED_FIBRE | \ -ADVERTISED_BNC | \ -ADVERTISED_Pause | \ -ADVERTISED_Asym_Pause |\ -ADVERTISED_Backplane | \ -ALL_ADVERTISED_MODES) - #ifndef HAVE_NETIF_MSG enum { NETIF_MSG_DRV = 0x0001, @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) } } +static int parse_hex_u32_bitmap(const char *s, + unsigned int nbits, u32 *result) +{ + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); + size_t slen = strlen(s); + size_t i; + + /* ignore optional '0x' prefix */ + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { + slen -= 2; + s += 2; + } + + if (slen > 8 * nwords) /* up to 2 digits per byte */ + return -1; + + memset(result, 0, 4 * nwords); + for (i = 0 ; i < slen ; ++i) { + const unsigned int shift = (slen - 1 - i) * 4; + u32 *dest = &result[shift / 32]; + u32 nibble; + + if ('a' <= s[i] && s[i] <= 'f') + nibble = 0xa + (s[i] - 'a'); + else if ('A' <= s[i] && s[i] <= 'F') + nibble = 0xa + (s[i] - 'A'); + else if ('0' <= s[i] && s[i] <= '9') + nibble = (s[i] - '0'); + else + return -1; + + *dest |= (nibble << (shift % 32)); + } + + return 0; +} + static void parse_generic_cmdline(struct cmd_context *ctx, int *changed, struct cmdline_info *info, @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) return 0; } -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, - int link_mode_only); +/* link mode routines */ -static void dump_supported(struct ethtool_cmd *ep) +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); + +static void init_global_link_mode_masks(void) { - u32 mask = ep->supported; + static const enum ethtool_link_mode_bit_indices + all_advertised_modes_bits[] = { + ETHTOOL_LINK_MODE_10baseT_Half_BIT, + ETHTOOL_LINK_MODE_10baseT_Full_BIT, + ETHTOOL_LINK_MODE_100baseT_Half_BIT, + ETHTOOL_LINK_MODE_100baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + ETHTOOL_LINK_MODE_2500baseX_Full_BIT, + ETHTOOL_LINK_MODE_1baseT_Full_BIT, + ETHTOOL_LINK_MODE_1baseKX4_Full_BIT, + ETHTOOL_
[ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
From: David Decotigny More info with kernel commit 8d3f2806f8fb ("Merge branch 'ethtool-ksettings'"). Note: The new features implemented in this patch depend on kernel commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to wrong nwords"). Signed-off-by: David Decotigny --- ethtool.c | 681 - internal.h | 67 ++ test-cmdline.c | 13 ++ 3 files changed, 603 insertions(+), 158 deletions(-) diff --git a/ethtool.c b/ethtool.c index 0cd0d4f..cb3d971 100644 --- a/ethtool.c +++ b/ethtool.c @@ -47,42 +47,6 @@ #define MAX_ADDR_LEN 32 #endif -#define ALL_ADVERTISED_MODES \ - (ADVERTISED_10baseT_Half | \ -ADVERTISED_10baseT_Full | \ -ADVERTISED_100baseT_Half | \ -ADVERTISED_100baseT_Full | \ -ADVERTISED_1000baseT_Half |\ -ADVERTISED_1000baseT_Full |\ -ADVERTISED_1000baseKX_Full|\ -ADVERTISED_2500baseX_Full |\ -ADVERTISED_1baseT_Full | \ -ADVERTISED_1baseKX4_Full | \ -ADVERTISED_1baseKR_Full | \ -ADVERTISED_1baseR_FEC |\ -ADVERTISED_2baseMLD2_Full |\ -ADVERTISED_2baseKR2_Full | \ -ADVERTISED_4baseKR4_Full | \ -ADVERTISED_4baseCR4_Full | \ -ADVERTISED_4baseSR4_Full | \ -ADVERTISED_4baseLR4_Full | \ -ADVERTISED_56000baseKR4_Full | \ -ADVERTISED_56000baseCR4_Full | \ -ADVERTISED_56000baseSR4_Full | \ -ADVERTISED_56000baseLR4_Full) - -#define ALL_ADVERTISED_FLAGS \ - (ADVERTISED_Autoneg | \ -ADVERTISED_TP |\ -ADVERTISED_AUI | \ -ADVERTISED_MII | \ -ADVERTISED_FIBRE | \ -ADVERTISED_BNC | \ -ADVERTISED_Pause | \ -ADVERTISED_Asym_Pause |\ -ADVERTISED_Backplane | \ -ALL_ADVERTISED_MODES) - #ifndef HAVE_NETIF_MSG enum { NETIF_MSG_DRV = 0x0001, @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) } } +static int parse_hex_u32_bitmap(const char *s, + unsigned int nbits, u32 *result) +{ + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); + size_t slen = strlen(s); + size_t i; + + /* ignore optional '0x' prefix */ + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { + slen -= 2; + s += 2; + } + + if (slen > 8 * nwords) /* up to 2 digits per byte */ + return -1; + + memset(result, 0, 4 * nwords); + for (i = 0 ; i < slen ; ++i) { + const unsigned int shift = (slen - 1 - i) * 4; + u32 *dest = &result[shift / 32]; + u32 nibble; + + if ('a' <= s[i] && s[i] <= 'f') + nibble = 0xa + (s[i] - 'a'); + else if ('A' <= s[i] && s[i] <= 'F') + nibble = 0xa + (s[i] - 'A'); + else if ('0' <= s[i] && s[i] <= '9') + nibble = (s[i] - '0'); + else + return -1; + + *dest |= (nibble << (shift % 32)); + } + + return 0; +} + static void parse_generic_cmdline(struct cmd_context *ctx, int *changed, struct cmdline_info *info, @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) return 0; } -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, - int link_mode_only); +/* link mode routines */ -static void dump_supported(struct ethtool_cmd *ep) +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); + +static void init_global_link_mode_masks(void) { - u32 mask = ep->supported; + static const enum ethtool_link_mode_bit_indices + all_advertised_modes_bits[] = { + ETHTOOL_LINK_MODE_10baseT_Half_BIT, + ETHTOOL_LINK_MODE_10baseT_Full_BIT, + ETHTOOL_LINK_MODE_100baseT_Half_BIT, + ETHTOOL_LINK_MODE_100baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + ETHTOOL_LINK_MODE_2500baseX_Full_BIT, + ETHTOOL_LINK_MODE_1baseT_Full_BIT, + ETHTOOL_LINK_MODE_1baseKX4_Full_BIT, + ETHTOOL_
[ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
From: David Decotigny More info with kernel commit 8d3f2806f8fb ("Merge branch 'ethtool-ksettings'"). Note: The new features implemented in this patch depend on kernel commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to wrong nwords"). Signed-off-by: David Decotigny --- ethtool.c | 681 - internal.h | 67 ++ test-cmdline.c | 13 ++ 3 files changed, 603 insertions(+), 158 deletions(-) diff --git a/ethtool.c b/ethtool.c index 0cd0d4f..cb3d971 100644 --- a/ethtool.c +++ b/ethtool.c @@ -47,42 +47,6 @@ #define MAX_ADDR_LEN 32 #endif -#define ALL_ADVERTISED_MODES \ - (ADVERTISED_10baseT_Half | \ -ADVERTISED_10baseT_Full | \ -ADVERTISED_100baseT_Half | \ -ADVERTISED_100baseT_Full | \ -ADVERTISED_1000baseT_Half |\ -ADVERTISED_1000baseT_Full |\ -ADVERTISED_1000baseKX_Full|\ -ADVERTISED_2500baseX_Full |\ -ADVERTISED_1baseT_Full | \ -ADVERTISED_1baseKX4_Full | \ -ADVERTISED_1baseKR_Full | \ -ADVERTISED_1baseR_FEC |\ -ADVERTISED_2baseMLD2_Full |\ -ADVERTISED_2baseKR2_Full | \ -ADVERTISED_4baseKR4_Full | \ -ADVERTISED_4baseCR4_Full | \ -ADVERTISED_4baseSR4_Full | \ -ADVERTISED_4baseLR4_Full | \ -ADVERTISED_56000baseKR4_Full | \ -ADVERTISED_56000baseCR4_Full | \ -ADVERTISED_56000baseSR4_Full | \ -ADVERTISED_56000baseLR4_Full) - -#define ALL_ADVERTISED_FLAGS \ - (ADVERTISED_Autoneg | \ -ADVERTISED_TP |\ -ADVERTISED_AUI | \ -ADVERTISED_MII | \ -ADVERTISED_FIBRE | \ -ADVERTISED_BNC | \ -ADVERTISED_Pause | \ -ADVERTISED_Asym_Pause |\ -ADVERTISED_Backplane | \ -ALL_ADVERTISED_MODES) - #ifndef HAVE_NETIF_MSG enum { NETIF_MSG_DRV = 0x0001, @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) } } +static int parse_hex_u32_bitmap(const char *s, + unsigned int nbits, u32 *result) +{ + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); + size_t slen = strlen(s); + size_t i; + + /* ignore optional '0x' prefix */ + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { + slen -= 2; + s += 2; + } + + if (slen > 8 * nwords) /* up to 2 digits per byte */ + return -1; + + memset(result, 0, 4 * nwords); + for (i = 0 ; i < slen ; ++i) { + const unsigned int shift = (slen - 1 - i) * 4; + u32 *dest = &result[shift / 32]; + u32 nibble; + + if ('a' <= s[i] && s[i] <= 'f') + nibble = 0xa + (s[i] - 'a'); + else if ('A' <= s[i] && s[i] <= 'F') + nibble = 0xa + (s[i] - 'A'); + else if ('0' <= s[i] && s[i] <= '9') + nibble = (s[i] - '0'); + else + return -1; + + *dest |= (nibble << (shift % 32)); + } + + return 0; +} + static void parse_generic_cmdline(struct cmd_context *ctx, int *changed, struct cmdline_info *info, @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) return 0; } -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, - int link_mode_only); +/* link mode routines */ -static void dump_supported(struct ethtool_cmd *ep) +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); + +static void init_global_link_mode_masks(void) { - u32 mask = ep->supported; + static const enum ethtool_link_mode_bit_indices + all_advertised_modes_bits[] = { + ETHTOOL_LINK_MODE_10baseT_Half_BIT, + ETHTOOL_LINK_MODE_10baseT_Full_BIT, + ETHTOOL_LINK_MODE_100baseT_Half_BIT, + ETHTOOL_LINK_MODE_100baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + ETHTOOL_LINK_MODE_2500baseX_Full_BIT, + ETHTOOL_LINK_MODE_1baseT_Full_BIT, + ETHTOOL_LINK_MODE_1baseKX4_Full_BIT, + ETHTOOL_
[ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
From: David Decotigny More info with kernel commit 8d3f2806f8fb ("Merge branch 'ethtool-ksettings'"). Note: The new features implemented in this patch depend on kernel commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to wrong nwords"). Signed-off-by: David Decotigny --- ethtool.c | 681 - internal.h | 67 ++ test-cmdline.c | 13 ++ 3 files changed, 603 insertions(+), 158 deletions(-) diff --git a/ethtool.c b/ethtool.c index 0cd0d4f..cb3d971 100644 --- a/ethtool.c +++ b/ethtool.c @@ -47,42 +47,6 @@ #define MAX_ADDR_LEN 32 #endif -#define ALL_ADVERTISED_MODES \ - (ADVERTISED_10baseT_Half | \ -ADVERTISED_10baseT_Full | \ -ADVERTISED_100baseT_Half | \ -ADVERTISED_100baseT_Full | \ -ADVERTISED_1000baseT_Half |\ -ADVERTISED_1000baseT_Full |\ -ADVERTISED_1000baseKX_Full|\ -ADVERTISED_2500baseX_Full |\ -ADVERTISED_1baseT_Full | \ -ADVERTISED_1baseKX4_Full | \ -ADVERTISED_1baseKR_Full | \ -ADVERTISED_1baseR_FEC |\ -ADVERTISED_2baseMLD2_Full |\ -ADVERTISED_2baseKR2_Full | \ -ADVERTISED_4baseKR4_Full | \ -ADVERTISED_4baseCR4_Full | \ -ADVERTISED_4baseSR4_Full | \ -ADVERTISED_4baseLR4_Full | \ -ADVERTISED_56000baseKR4_Full | \ -ADVERTISED_56000baseCR4_Full | \ -ADVERTISED_56000baseSR4_Full | \ -ADVERTISED_56000baseLR4_Full) - -#define ALL_ADVERTISED_FLAGS \ - (ADVERTISED_Autoneg | \ -ADVERTISED_TP |\ -ADVERTISED_AUI | \ -ADVERTISED_MII | \ -ADVERTISED_FIBRE | \ -ADVERTISED_BNC | \ -ADVERTISED_Pause | \ -ADVERTISED_Asym_Pause |\ -ADVERTISED_Backplane | \ -ALL_ADVERTISED_MODES) - #ifndef HAVE_NETIF_MSG enum { NETIF_MSG_DRV = 0x0001, @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) } } +static int parse_hex_u32_bitmap(const char *s, + unsigned int nbits, u32 *result) +{ + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); + size_t slen = strlen(s); + size_t i; + + /* ignore optional '0x' prefix */ + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { + slen -= 2; + s += 2; + } + + if (slen > 8 * nwords) /* up to 2 digits per byte */ + return -1; + + memset(result, 0, 4 * nwords); + for (i = 0 ; i < slen ; ++i) { + const unsigned int shift = (slen - 1 - i) * 4; + u32 *dest = &result[shift / 32]; + u32 nibble; + + if ('a' <= s[i] && s[i] <= 'f') + nibble = 0xa + (s[i] - 'a'); + else if ('A' <= s[i] && s[i] <= 'F') + nibble = 0xa + (s[i] - 'A'); + else if ('0' <= s[i] && s[i] <= '9') + nibble = (s[i] - '0'); + else + return -1; + + *dest |= (nibble << (shift % 32)); + } + + return 0; +} + static void parse_generic_cmdline(struct cmd_context *ctx, int *changed, struct cmdline_info *info, @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) return 0; } -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, - int link_mode_only); +/* link mode routines */ -static void dump_supported(struct ethtool_cmd *ep) +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); + +static void init_global_link_mode_masks(void) { - u32 mask = ep->supported; + static const enum ethtool_link_mode_bit_indices + all_advertised_modes_bits[] = { + ETHTOOL_LINK_MODE_10baseT_Half_BIT, + ETHTOOL_LINK_MODE_10baseT_Full_BIT, + ETHTOOL_LINK_MODE_100baseT_Half_BIT, + ETHTOOL_LINK_MODE_100baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + ETHTOOL_LINK_MODE_2500baseX_Full_BIT, + ETHTOOL_LINK_MODE_1baseT_Full_BIT, + ETHTOOL_LINK_MODE_1baseKX4_Full_BIT, + ETHTOOL_
[ethtool PATCH v7 1/2] ethtool.c: add support for ETHTOOL_xLINKSETTINGS ioctls
From: David Decotigny More info with kernel commit 8d3f2806f8fb ("Merge branch 'ethtool-ksettings'"). Note: The new features implemented in this patch depend on kernel commit 793cf87de9d1 ("Set cmd field in ETHTOOL_GLINKSETTINGS response to wrong nwords"). Signed-off-by: David Decotigny --- ethtool.c | 681 - internal.h | 67 ++ test-cmdline.c | 13 ++ 3 files changed, 603 insertions(+), 158 deletions(-) diff --git a/ethtool.c b/ethtool.c index 0cd0d4f..cb3d971 100644 --- a/ethtool.c +++ b/ethtool.c @@ -47,42 +47,6 @@ #define MAX_ADDR_LEN 32 #endif -#define ALL_ADVERTISED_MODES \ - (ADVERTISED_10baseT_Half | \ -ADVERTISED_10baseT_Full | \ -ADVERTISED_100baseT_Half | \ -ADVERTISED_100baseT_Full | \ -ADVERTISED_1000baseT_Half |\ -ADVERTISED_1000baseT_Full |\ -ADVERTISED_1000baseKX_Full|\ -ADVERTISED_2500baseX_Full |\ -ADVERTISED_1baseT_Full | \ -ADVERTISED_1baseKX4_Full | \ -ADVERTISED_1baseKR_Full | \ -ADVERTISED_1baseR_FEC |\ -ADVERTISED_2baseMLD2_Full |\ -ADVERTISED_2baseKR2_Full | \ -ADVERTISED_4baseKR4_Full | \ -ADVERTISED_4baseCR4_Full | \ -ADVERTISED_4baseSR4_Full | \ -ADVERTISED_4baseLR4_Full | \ -ADVERTISED_56000baseKR4_Full | \ -ADVERTISED_56000baseCR4_Full | \ -ADVERTISED_56000baseSR4_Full | \ -ADVERTISED_56000baseLR4_Full) - -#define ALL_ADVERTISED_FLAGS \ - (ADVERTISED_Autoneg | \ -ADVERTISED_TP |\ -ADVERTISED_AUI | \ -ADVERTISED_MII | \ -ADVERTISED_FIBRE | \ -ADVERTISED_BNC | \ -ADVERTISED_Pause | \ -ADVERTISED_Asym_Pause |\ -ADVERTISED_Backplane | \ -ALL_ADVERTISED_MODES) - #ifndef HAVE_NETIF_MSG enum { NETIF_MSG_DRV = 0x0001, @@ -293,6 +257,43 @@ static void get_mac_addr(char *src, unsigned char *dest) } } +static int parse_hex_u32_bitmap(const char *s, + unsigned int nbits, u32 *result) +{ + const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); + size_t slen = strlen(s); + size_t i; + + /* ignore optional '0x' prefix */ + if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { + slen -= 2; + s += 2; + } + + if (slen > 8 * nwords) /* up to 2 digits per byte */ + return -1; + + memset(result, 0, 4 * nwords); + for (i = 0 ; i < slen ; ++i) { + const unsigned int shift = (slen - 1 - i) * 4; + u32 *dest = &result[shift / 32]; + u32 nibble; + + if ('a' <= s[i] && s[i] <= 'f') + nibble = 0xa + (s[i] - 'a'); + else if ('A' <= s[i] && s[i] <= 'F') + nibble = 0xa + (s[i] - 'A'); + else if ('0' <= s[i] && s[i] <= '9') + nibble = (s[i] - '0'); + else + return -1; + + *dest |= (nibble << (shift % 32)); + } + + return 0; +} + static void parse_generic_cmdline(struct cmd_context *ctx, int *changed, struct cmdline_info *info, @@ -472,64 +473,157 @@ static int do_version(struct cmd_context *ctx) return 0; } -static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, - int link_mode_only); +/* link mode routines */ -static void dump_supported(struct ethtool_cmd *ep) +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); +static __ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); + +static void init_global_link_mode_masks(void) { - u32 mask = ep->supported; + static const enum ethtool_link_mode_bit_indices + all_advertised_modes_bits[] = { + ETHTOOL_LINK_MODE_10baseT_Half_BIT, + ETHTOOL_LINK_MODE_10baseT_Full_BIT, + ETHTOOL_LINK_MODE_100baseT_Half_BIT, + ETHTOOL_LINK_MODE_100baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + ETHTOOL_LINK_MODE_2500baseX_Full_BIT, + ETHTOOL_LINK_MODE_1baseT_Full_BIT, + ETHTOOL_LINK_MODE_1baseKX4_Full_BIT, + ETHTOOL_