RFC: new ETHTOOL_GSETTINGS/SSETTINGS API
Subsystems (15)
v3 cover RFC: new ETHTOOL_GSETTINGS/SSETTINGS API
From: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[email protected]>
History:
v3
- rebased v2 on top of latest net-next, minor checkpatch/printf %*pb updates
v2
- keep return 0 in get_settings when successful, instead of propagating positive result from driver's get_settings callback.
v1
- original submission
The main goal of this series is to support ethtool link mode masks larger than 32 bits. It implements a new ioctl pair (ETHTOOL_GSETTINGS/SSETTINGS), its associated callbacks (get/set_settings) and a new struct ethtool_settings, which should eventually replace legacy ethtool_cmd. Internally, the kernel uses fixed length link mode masks defined at compilation time in ethtool.h (for now: 31 bits), that can be increased by changing __ETHTOOL_LINK_MODE_LAST in ethtool.h (absolute max is 4064 bits, checked at compile time), and the user/kernel interface allows this length to be arbitrary within 1..4064. This should allow some flexibility without using too much malloc/stack space, at the cost of a small kernel/user handshake for the user to determine the sizes of those bitmaps.
Along the way, I chose to drop in the new structure the 3 ethtool_cmd fields marked "deprecated" (transceiver/maxrxpkt/maxtxpkt). They are still available for old drivers via the old ETHTOOL_GSET/SSET API, but are not available to drivers that switch to new API. Of those 3 fields, ethtool_cmd::transceiver seems to be still actively used by several drivers, maybe we should not consider this field deprecated? The 2 other fields are basically not used. This transition requires some care in the way old and new ethtool talk to the kernel.
More technical details provided in the description for main patch. In particular details about backward compatibility properties.
Some questions to more experts than me:
- the kernel/interface multiplexes the "tell me the bitmap length" handshake and the "give me the settings" inside the new ETHTOOL_GSETTINGS cmd. I was thinking of making this into 2 separate cmds: 1 cmd ETHTOOL_GKERNELPROPERTIES which would be kernel-wide rather than device-specific, would return properties like "length of the link mode bitmaps", and possibly others. And ETHTOOL_GSETTINGS would expect the proper bitmaps
- the link mode bitmaps are piggybacked at tail of the new struct ethtool_settings. Since its user-visible definition does not assume specific bitmap width, I am using a 0-length array as the publicly visible placeholder. But then, the kernel needs to specialize it (struct ethtool_ksettings) to specify its current link mode masks. This means that kernel code is "littered" with "ksettings->parent.field" to access "field" inside ethtool_settings:
+ I don't like the field name "parent", any suggestion welcome
+ and/or: I could use ethtool_settings everywhere (instead of a new ethtool_ksettings) and an accessor to retrieve the link mode masks?
+ or: we could decide to make the link mode masks statically bounded again, ie. make their width public, but larger than current 32, and unchangeable forever. This would make everything straightforward, but we might hit limits later, or have an unneeded memory/stack usage for unused bits.
any preference?
- crossing user/kernel boundary requires conversion of the kernel bitmaps (unsigned long[]) to something more strict (in my case:
u32) to accomodate for 32/64 compat. Maybe I should add a copy_bitmap_from_user/copy_bitmap_to_user API inside bitmap.h instead of defining my own in ethtool.c?
- I am using a typedef struct (ethtool_link_mode_mask_t) to build and hold the new masks. Makes it handy to use in the drivers (see mlx4 for an example). Not very nice.
- I foresee bugs where people use the legacy/deprecated SUPPORTED_x macros instead of the new ETHTOOL_LINK_MODE_x_BIT enums in the new get/set__ksettings callbacks. Not sure how to prevent problems with this.
The only driver which was converted for now is mlx4. I am not considering fcoe as fully converted, but I updated it a minima to be able to remove __ethtool_get_settings, now known as __ethtool_get_ksettings.
Tested with legacy and "future" ethtool on 64b x86 kernel and 32+64b ethtool, and on a 32b x86 kernel + 32b ethtool.
############################################
# Patch Set Summary:
David Decotigny (17):
net: usnic: remove unused call to ethtool_ops::get_settings
net: usnic: use __ethtool_get_settings
net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
tx4939: use __ethtool_get_ksettings
net: usnic: use __ethtool_get_ksettings
net: bonding: use __ethtool_get_ksettings
net: ipvlan: use __ethtool_get_ksettings
net: macvlan: use __ethtool_get_ksettings
net: team: use __ethtool_get_ksettings
net: fcoe: use __ethtool_get_ksettings
net: rdma: use __ethtool_get_ksettings
net: 8021q: use __ethtool_get_ksettings
net: bridge: use __ethtool_get_ksettings
net: core: use __ethtool_get_ksettings
net: ethtool: remove unused __ethtool_get_settings
net: mlx4: convenience predicate for debug messages
net: mlx4: use new ETHTOOL_G/SSETTINGS API
arch/mips/txx9/generic/setup_tx4939.c | 7 +- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 10 +- drivers/net/bonding/bond_main.c | 14 +- drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 323 ++++++++-------- drivers/net/ethernet/mellanox/mlx4/en_main.c | 1 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 5 +- drivers/net/ipvlan/ipvlan_main.c | 8 +- drivers/net/macvlan.c | 8 +- drivers/net/team/team.c | 8 +- drivers/scsi/fcoe/fcoe_transport.c | 36 +- include/linux/ethtool.h | 97 ++++- include/rdma/ib_addr.h | 14 +- include/uapi/linux/ethtool.h | 323 ++++++++++++---- net/8021q/vlan_dev.c | 8 +- net/bridge/br_if.c | 6 +- net/core/ethtool.c | 478 +++++++++++++++++++++++- net/core/net-sysfs.c | 15 +- net/packet/af_packet.c | 11 +- 18 files changed, 1046 insertions(+), 326 deletions(-)
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 1/17 net: usnic: remove unused call to ethtool_ops::get_settings
From: David Decotigny <[email protected]>
--- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 2 -- 1 file changed, 2 deletions(-)
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +0 -2
@@ -269,7 +269,6 @@ int usnic_ib_query_device(struct ib_device *ibdev,struct usnic_ib_dev *us_ibdev =to_usdev (ibdev);union ib_gid gid;struct ethtool_drvinfo info; -struct ethtool_cmd cmd;int qp_per_vf;usnic_dbg ("\n" );
@@ -278,7 +277,6 @@ int usnic_ib_query_device(struct ib_device *ibdev,mutex_lock (&us_ibdev->usdev_lock); us_ibdev->netdev->ethtool_ops->get_drvinfo (us_ibdev->netdev, &info); - us_ibdev->netdev->ethtool_ops->get_settings (us_ibdev->netdev, &cmd);memset (props,0 ,sizeof (*props));usnic_mac_ip_to_gid (us_ibdev->ufdev->mac, us_ibdev->ufdev->inaddr, &gid.raw[0 ]);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 2/17 net: usnic: use __ethtool_get_settings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +1 -1
@@ -329,7 +329,7 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,usnic_dbg ("\n" );mutex_lock (&us_ibdev->usdev_lock); - us_ibdev->netdev->ethtool_ops->get_settings (us_ibdev->netdev, &cmd); +__ethtool_get_settings (us_ibdev->netdev, &cmd);memset (props,0 ,sizeof (*props)); props->lid =0 ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 3/17 net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
In reply to David DecotignyFrom: David Decotigny <[email protected]>
This patch defines a new ETHTOOL_GSETTINGS/SSETTINGS API, handled by the new get_ksettings/set_ksettings callbacks. This API provides support for most legacy ethtool_cmd fields, adds support for larger link mode masks (up to 4064 bits, variable length), and removes ethtool_cmd deprecated fields (transceiver/maxrxpkt/maxtxpkt).
This API is deprecating the legacy ETHTOOL_GSET/SSET API and provides the following backward compatibility properties:
- legacy ethtool with legacy drivers: no change, still using the get_settings/set_settings callbacks.
- legacy ethtool with new get/set_ksettings drivers: the new driver callbacks are used, data internally converted to legacy ethtool_cmd. ETHTOOL_GSET will return only the 1st 32b of each link mode mask. ETHTOOL_SSET will fail if user tries to set the ethtool_cmd deprecated fields to non-0 (transceiver/maxrxpkt/maxtxpkt). A kernel warning is printed if driver exports higher bits or if user request changes in deprecated fields mentioned earlier.
- future ethtool with legacy drivers: no change, still using the get_settings/set_settings callbacks, internally converted to new data structure. Note that that "future" ethtool tool will not allow changes to deprecated fields (transceiver/maxrxpkt/maxtxpkt), as they cannot be expressed for the kernel.
- future ethtool with new drivers: direct call to the new callbacks.
By "future" ethtool, what is meant is:
- query: first try ETHTOOL_GSETTINGS, and revert to ETHTOOL_GSET if fails
- set: query first and remember which of ETHTOOL_GSETTINGS or ETHTOOL_GSET was successful
- if ETHTOOL_GSETTINGS was successful, then change config with ETHTOOL_SSETTINGS. A failure there is final (do not try ETHTOOL_SSET).
- otherwise ETHTOOL_GSET was successful, change config with ETHTOOL_SSET. A failure there is final (do not try ETHTOOL_SSETTINGS).
The interaction user/kernel via the new API requires a small ETHTOOL_GSETTINGS handshake first to agree on the length of the link mode bitmaps. If kernel doesn't agree with user, it returns the bitmap length it is expecting from user as a negative length (and cmd field is 0). When kernel and user agree, kernel returns valid info in all fields (ie. link mode length > 0 and cmd is ETHTOOL_GSETTINGS).
Data structure crossing user/kernel boundary is 32/64-bit agnostic. Converted internally to a legal kernel bitmap.
The internal __ethtool_get_settings kernel helper will gradually be replaced by __ethtool_get_ksettings by the time the first ksettings drivers start to appear. So this patch doesn't change it, it will be removed before it needs to be changed.
--- include/linux/ethtool.h | 101 ++++++++- include/uapi/linux/ethtool.h | 323 ++++++++++++++++++++++------ net/core/ethtool.c | 489 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 833 insertions(+), 80 deletions(-)
include/linux/ethtool.h +93 -8
@@ -12,6 +12,7 @@#ifndef _LINUX_ETHTOOL_H#define _LINUX_ETHTOOL_H +#include <linux/bitmap.h> #include <linux/compat.h> #include <uapi/linux/ethtool.h>
@@ -40,9 +41,6 @@ struct compat_ethtool_rxnfc {#include <linux/rculist.h> -extern int __ethtool_get_settings (struct net_device *dev, -struct ethtool_cmd *cmd); -/** * enum ethtool_phys_id_state - indicator state for physical identification * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated
@@ -97,13 +95,85 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)return index % n_rx_rings; } +#define __ETHTOOL_LINK_MODE_IS_VALID_BIT (indice) \ + ((indice) >= 0 && (indice) <= __ETHTOOL_LINK_MODE_LAST) + +/* number of link mode bits handled internally by kernel */ +#define __ETHTOOL_LINK_MODE_MASK_NBITS (__ETHTOOL_LINK_MODE_LAST+1) + +typedef struct { +unsigned long mask[BITS_TO_LONGS (__ETHTOOL_LINK_MODE_MASK_NBITS)]; +}ethtool_link_mode_mask_t ; + +/* drivers must ignore parent.cmd and parent.link_mode_masks_nwords +* fields, but they are allowed to overwrite them (will be ignored). +*/ +struct ethtool_ksettings { +struct ethtool_settings parent; +struct { +ethtool_link_mode_mask_t supported; +ethtool_link_mode_mask_t advertising; +ethtool_link_mode_mask_t lp_advertising; + } link_modes; +}; + +/* helper function for ethtool_build_link_mode and ethtool_add_link_modes */ +static inline int +__ethtool_add_link_modes (ethtool_link_mode_mask_t *dst, +unsigned nindices, +const enum ethtool_link_mode_bit_indices *indices) { +unsigned i; +int rv =0 ; + +for (i =0 ; i < nindices ; ++i) { +if (__ETHTOOL_LINK_MODE_IS_VALID_BIT (indices[i])) +set_bit (indices[i], dst->mask); +else + rv =-1 ; + } +return rv; +} + +/* build link mode mask from variadic list of bit indices, return 0 +* when all indices are valid, -1 otherwise +*/ +#define ethtool_build_link_mode (dst, ...) \ + ({ \ + const enum ethtool_link_mode_bit_indices indices[] = { \ + __VA_ARGS__ }; \ + bitmap_zero((dst)->mask, \ + __ETHTOOL_LINK_MODE_MASK_NBITS); \ + __ethtool_add_link_modes((dst), \ + ARRAY_SIZE(indices), indices); \ + }) + +/* update link mode mask by setting variadic list of bit indices, +* return 0 when all indices are valid, -1 otherwise +*/ +#define ethtool_add_link_modes (dst, ...) \ + ({ \ + const enum ethtool_link_mode_bit_indices indices[] = { \ + __VA_ARGS__ }; \ + __ethtool_add_link_modes((dst), \ + ARRAY_SIZE(indices), indices); \ + }) + +extern int __ethtool_get_ksettings (struct net_device *dev, +struct ethtool_ksettings *ksettings); + +/* DEPRECATED, use __ethtool_get_ksettings */ +extern int __ethtool_get_settings (struct net_device *dev, +struct ethtool_cmd *cmd); +/** * struct ethtool_ops - optional netdev operations -* @get_settings: Get various device settings including Ethernet link +* @get_settings: DEPRECATED, use %get_ksettings/%set_ksettings +* API. Get various device settings including Ethernet link * settings. The @cmd parameter is expected to have been cleared -* before get_settings is called. Returns a negative error code or -* zero. -* @set_settings: Set various device settings including Ethernet link +* before get_settings is called. Returns a negative error code +* or zero. +* @set_settings: DEPRECATED, use %get_ksettings/%set_ksettings +* API. Set various device settings including Ethernet link * settings. Returns a negative error code or zero. * @get_drvinfo: Report driver/device information. Should only set the * @driver, @version, @fw_version and @bus_info fields. If not
@@ -201,6 +271,18 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)* @get_module_eeprom: Get the eeprom information from the plug-in module * @get_eee: Get Energy-Efficient (EEE) supported and status. * @set_eee: Set EEE status (enable/disable) as well as LPI timers. +* @get_ksettings: When defined, takes precedence over the +* %get_settings method. Get various device settings including Ethernet +* link settings. The %cmd and %link_mode_masks_nwords fields should be +* ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter), +* any change to them will be overwritten by kernel. Returns a negative +* error code or zero. +* @set_ksettings: When defined, takes precedence over the +* %set_settings method. Set various device settings including +* Ethernet link settings. The %cmd and %link_mode_masks_nwords fields +* should be ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of +* the latter), any change to them will be overwritten by +* kernel. Returns a negative error code or zero. * * All operations are optional (i.e. the function pointer may be set * to %NULL) and callers must take this into account. Callers must
@@ -280,6 +362,9 @@ struct ethtool_ops {int (*set_tunable)(struct net_device *,const struct ethtool_tunable *,const void *); - +int (*get_ksettings)(struct net_device *, +struct ethtool_ksettings *); +int (*set_ksettings)(struct net_device *, + const struct ethtool_ksettings *); };#endif /* _LINUX_ETHTOOL_H */
include/uapi/linux/ethtool.h +257 -66
349 lines not on this page · raw message
net/core/ethtool.c +483 -6
525 lines not on this page · raw message
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
kbuild test robot
build botRe: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi David,
[auto build test WARNING on: net-next/master] [also build test WARNING on: v4.4-rc3 next-20151127]
url: https://github.com/0day-ci/linux/commits/David-Decotigny/RFC-new-ETHTOOL_GSETTINGS-SSETTINGS-API/20151201-062040 config: blackfin-allyesconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=blackfin
All warnings (new ones prefixed by >>):
In file included from include/linux/netdevice.h:42:0,
from drivers/staging/rtl8723au/include/osdep_service.h:30,
from drivers/staging/rtl8723au/core/rtw_cmd.c:17:
include/linux/ethtool.h: In function '__ethtool_add_link_modes':
>> include/linux/ethtool.h:129:3: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]vim +129 include/linux/ethtool.h
113 struct {
114 ethtool_link_mode_mask_t supported;
115 ethtool_link_mode_mask_t advertising;
116 ethtool_link_mode_mask_t lp_advertising;
117 } link_modes;
118 };
119
120 /* helper function for ethtool_build_link_mode and ethtool_add_link_modes */
121 static inline int
122 __ethtool_add_link_modes(ethtool_link_mode_mask_t *dst,
123 unsigned nindices,
124 const enum ethtool_link_mode_bit_indices *indices) {
125 unsigned i;
126 int rv = 0;
127
128 for (i = 0 ; i < nindices ; ++i) {
> 129 if (__ETHTOOL_LINK_MODE_IS_VALID_BIT(indices[i]))
130 set_bit(indices[i], dst->mask);
131 else
132 rv = -1;
133 }
134 return rv;
135 }
136
137 /* build link mode mask from variadic list of bit indices, return 0
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
Quoted 1 line · kbuild test robot
Quoted 1 line
Quoted 1 line
include/linux/ethtool.h:129:3: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
prepared a fix for that, will be part of next patch update after feedback.
Re: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
In reply to David DecotignyQuoted 7 lines · David Decotigny
From: David Decotigny <[email protected]>
This patch defines a new ETHTOOL_GSETTINGS/SSETTINGS API, handled by the new get_ksettings/set_ksettings callbacks. This API provides support for most legacy
ethtool_cmdfields, adds support for larger link mode masks (up to 4064 bits, variable length), and removesethtool_cmddeprecated fields (transceiver/maxrxpkt/maxtxpkt).
As you have to introduce new commands and a new structure, please include the word 'link' in their names.
[...]
Quoted 26 lines
include/linux/ethtool.h +0
-0@@ -12,6 +12,7 @@ #ifndef _LINUX_ETHTOOL_H #define _LINUX_ETHTOOL_H
+#include
#include
#includeinclude/linux/ethtool.h +0
-0@@ -40,9 +41,6 @@ struct compat_ethtool_rxnfc {
#includeinclude/linux/ethtool.h +0
-3-extern int __ethtool_get_settings (struct net_device *dev, - struct ethtool_cmd *cmd); -/**
* enumethtool_phys_id_state- indicator state for physical identification
* @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivatedinclude/linux/ethtool.h +0
-0@@ -97,13 +95,85 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) return index % n_rx_rings; }
include/linux/ethtool.h static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) · line 99
Quoted 2 lines
include/linux/ethtool.h +2
-0+#define __ETHTOOL_LINK_MODE_IS_VALID_BIT (indice) \ + ((indice) >= 0 && (indice) <= __ETHTOOL_LINK_MODE_LAST)
'indice'? Shoudn't this be 'index' or 'mode'?
include/linux/ethtool.h static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) · line 102
Quoted 3 lines
include/linux/ethtool.h +2
-0+/* number of link mode bits handled internally by kernel */ +#define __ETHTOOL_LINK_MODE_MASK_NBITS (__ETHTOOL_LINK_MODE_LAST+1)
Spaces around the + sign.
include/linux/ethtool.h static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) · line 106
Quoted 4 lines
include/linux/ethtool.h +3
-0+typedef struct { +unsigned long mask[BITS_TO_LONGS (__ETHTOOL_LINK_MODE_MASK_NBITS)]; +}ethtool_link_mode_mask_t ;
checkpatch claims you shouldn't introduce such typedefs.
[...]
Quoted 4 lines
+/**
+ * structethtool_settings- link control and status
+ * This structure deprecates struct %ethtool_cmd.
We do the deprecating; the structures are purely passive.
[...]
Quoted 2 lines
+ * Deprecated fields should be ignored by both users and drivers.
Delete this last paragraph.
[...]
Quoted 7 lines
net/core/ethtool.c +0
-0@@ -352,6 +352,388 @@ static int __ethtool_set_flags(struct net_device *dev, u32 data) return 0; }
+/* TODO: remove when %ETHTOOL_GSET/%ETHTOOL_SSET disappear */
Please delete this TODO and all the similar ones; we don't remove userland APIs just because they're deprecated.
[...]
net/core/ethtool.c static int __ethtool_set_flags(struct net_device *dev, u32 data) · line 466
Quoted 4 lines
net/core/ethtool.c +3
-0+/* number of 32-bit words to store the user's link mode bitmaps */ +#define __ETHTOOL_LINK_MODE_MASK_NU32 \ + ((__ETHTOOL_LINK_MODE_MASK_NBITS + 31) / 32)
Should use DIV_ROUND_UP().
net/core/ethtool.c static int __ethtool_set_flags(struct net_device *dev, u32 data) · line 475
Quoted 9 lines
net/core/ethtool.c +8
-0+/* layout of the struct passed from/to userland */ +struct ethtool_usettings { +struct ethtool_settings parent; +struct { +__u32 supported[__ETHTOOL_LINK_MODE_MASK_NU32]__aligned(4) ; +__u32 advertising[__ETHTOOL_LINK_MODE_MASK_NU32]__aligned(4) ; +__u32 lp_advertising[ + __ETHTOOL_LINK_MODE_MASK_NU32]__aligned(4) ;
Why __aligned(4)? Do you have any reason to think that some padding might be added otherwise?
[...]
Quoted 35 lines
net/core/ethtool.c +35
-0+#if BITS_PER_LONG ==64 +static unsigned long _shl32 (__u32 v) +{ +return ((unsigned long )v) <<32 ; +} +#endif + +/* convert a user's __u32[] bitmap in user space to a kernel internal +* bitmap. return 0 on success, errno on error. this assumes that +* link_mode_masks_nwords was already verified +*/ +static int load_ksettings_from_user (struct ethtool_ksettings *to, + const void __user *from) +{ +struct ethtool_usettings usettings; +#if BITS_PER_LONG !=32 +unsigned i; +#endif + +if (copy_from_user (&usettings, from,sizeof (usettings))) +return -EFAULT ; + +/* make sure we didn't receive garbage between last allowed bit +* and end of last u32 word +*/ +if (__ETHTOOL_LINK_MODE_MASK_NBITS %32 ) { +const u32 allowed = ( +1U << (__ETHTOOL_LINK_MODE_MASK_NBITS %32 )) -1 ; +if (usettings.link_modes.supported[ + __ETHTOOL_LINK_MODE_MASK_NU32 - 1] & ~allowed) +return -EINVAL ; +if (usettings.link_modes.advertising[ + __ETHTOOL_LINK_MODE_MASK_NU32 - 1] & ~allowed) +return -EINVAL ; + if (usettings.link_modes.lp_advertising[
net/core/ethtool.c static int __ethtool_set_flags(struct net_device *dev, u32 data) · line 565
Quoted 10 lines
net/core/ethtool.c +10
-0+ __ETHTOOL_LINK_MODE_MASK_NU32 - 1] & ~allowed) +return -EINVAL ; + } + +#if BITS_PER_LONG ==32 +compiletime_assert (sizeof (*to) ==sizeof (usettings), + "sizeof(ulong) != 32"); +memcpy (to, &usettings,sizeof (*to)); +#elif BITS_PER_LONG ==64 +memset (to,0 ,sizeof (*to));
This memset() looks redundant.
Quoted 13 lines
net/core/ethtool.c +13
-0+memcpy (&to->parent, &usettings.parent,sizeof (to->parent)); +for (i =0 ; i < __ETHTOOL_LINK_MODE_MASK_NU32 ; ++i) { +if (0 == (i &1 )) { + to->link_modes.supported.mask[i >>1 ] + = usettings.link_modes.supported[i]; + to->link_modes.advertising.mask[i >>1 ] + = usettings.link_modes.advertising[i]; + to->link_modes.lp_advertising.mask[i >>1 ] + = usettings.link_modes.lp_advertising[i]; + }else { + to->link_modes.supported.mask[i >>1 ] |=_shl32 ( + usettings.link_modes.supported[i]); + to->link_modes.advertising.mask[i >> 1] |= _shl32(
net/core/ethtool.c static int __ethtool_set_flags(struct net_device *dev, u32 data) · line 588
Quoted 10 lines
net/core/ethtool.c +10
-0+ usettings.link_modes.advertising[i]); + to->link_modes.lp_advertising.mask[i >>1 ] |=_shl32 ( + usettings.link_modes.lp_advertising[i]); + } + } +#else +# error "unsupported ulong width" +#endif +return 0 ; +}
I think the array conversion ought to be a separate function that you can call 3 times here, rather than repeating it here. In fact that could be a general function in lib/bitmap.c.
Similarly for the opposite conversion below.
[...]
Quoted 18 lines
static int
ethtool_get_settings(struct net_device *dev, void __user *useraddr){net/core/ethtool.c +0
-1-int err;struct
ethtool_cmdcmd;net/core/ethtool.c +10
-3- err =__ethtool_get_settings (dev, &cmd); -if (err <0 ) -return err; +ASSERT_RTNL (); + +if (dev->ethtool_ops->get_ksettings) { +/* First, use ksettings API if it is supported */ +int err; +struct ethtool_ksettings ksettings; + +memset (&ksettings,0 ,sizeof (ksettings)); + err = dev->ethtool_ops->get_ksettings (dev, &ksettings); +if (err <0 )
net/core/ethtool.c int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) · line 785
Quoted 10 lines
net/core/ethtool.c +10
-0+return err; +if (!convert_ksettings_to_legacy_settings (&cmd, &ksettings)) { +static int __warned; + +/* not all bitmaps could be translated +* acurately to legacy API: print warning with +* netdev name, but does still succeed +*/ +if (!__warned) +netdev_warn (dev,"please upgrade ethtool\n" );
ethtool isn't the only program that uses this API, not by a long way. And since it's the program at fault, not the device, it doesn't make a lot of sense to use netdev_warn().
So I suggest a message more like that in warn_legacy_capability_use() in kernel/capability.c.
[...]
Quoted 13 lines
static int
ethtool_set_settings(struct net_device *dev, void __user *useraddr){
structethtool_cmdcmd;net/core/ethtool.c +1
-2-if (!dev->ethtool_ops->set_settings) -return -EOPNOTSUPP ; +ASSERT_RTNL ();
if (copy_from_user(&cmd, useraddr, sizeof(cmd))) return-EFAULT;net/core/ethtool.c +2
-0+/* first, try new %ethtool_ksettings API. */ +if (dev->ethtool_ops->set_ksettings) {
net/core/ethtool.c int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) · line 843
Quoted 10 lines
net/core/ethtool.c +10
-0+struct ethtool_ksettings ksettings; + +if (!convert_legacy_settings_to_ksettings (&ksettings, &cmd)) { +static int __warned; + +/* rejecting setting deprecated fields +* transceiver/maxtxpkt/maxrxpkt +*/ +if (!__warned) +netdev_warn (dev,"please upgrade ethtool" );
I don't think this makes sense - it's not as if ethtool will automatically try to set these without it being explicitly requested by the user. Just return -EINVAL without logging anything.
net/core/ethtool.c int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) · line 846
Quoted 3 lines
net/core/ethtool.c +3
-0+ __warned =1 ; +return -EINVAL ; + }
[...]
Ben.
Signature · 3 lines
Ben Hutchings
Theory and practice are closer in theory than in practice.
- John Levine, moderator of comp.compilersDavid Miller
maintainerRe: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
In reply to David DecotignyFrom: David Decotigny <[email protected]>
Date: Mon, 30 Nov 2015 14:05:41 -0800
Quoted 5 lines
This patch defines a new ETHTOOL_GSETTINGS/SSETTINGS API, handled by the new get_ksettings/set_ksettings callbacks. This API provides support for most legacy
ethtool_cmdfields, adds support for larger link mode masks (up to 4064 bits, variable length), and removesethtool_cmddeprecated fields (transceiver/maxrxpkt/maxtxpkt).
Please do not define the mask using a non-fixed type. I know it makes it easier to use the various bitmap helper routines if you use 'long', but here it is clearly superior to use "u32" for the bitmap type and do the bit operations by hand if necessary.
Otherwise you have to have all of this ulong size CPP conditional code which is incredibly ugly.
Furthermore you have to use fixed sized types anyways so that we don't need compat code to deal with 32-bit userspace applications making these ethtool calls into a 64-bit kernel.
THanks.
Re: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
Hello,
There is a set of conversion routines ulong[]<->u32[] to address this 32/64-bit compat issue. Using a u32-based bitmap would require drivers to handle the u32 bitmaps themselves, this might be confusing, considering there is a standard bitmap api; and might be error-prone as well. Plus there is %*pb[l] format that's very helpful for debugging. That's why I preferred to handle the relative complexity of u32 bitmaps with the CPP conditionals in the non-driver code that handles the user/kernel interactions, and drivers can use the standard bitmap api transparently.
I was currently moving/rewriting the u32/ulong conversion code to bitmap.{c,h} as Ben Hutchings was suggesting, which should hopefully make the code more digestible; and could possibly be used for other user/kernel interfaces. How about I send an updated version with this solution, and if it's still not right, I'll revisit with either u32[] everywhere or fixed-size bitmap instead of variable-size as here? Or maybe another option would be to implement a new u32[] bitmap_u32.{c,h} api, possibly using a set of macro tricks to share code with bitmap.{c,h}?
Quoted 22 lines · David Miller
From: David Decotigny <[email protected]>
Date: Mon, 30 Nov 2015 14:05:41 -0800Quoted 5 lines
This patch defines a new ETHTOOL_GSETTINGS/SSETTINGS API, handled by the new get_ksettings/set_ksettings callbacks. This API provides support for most legacy
ethtool_cmdfields, adds support for larger link mode masks (up to 4064 bits, variable length), and removesethtool_cmddeprecated fields (transceiver/maxrxpkt/maxtxpkt).Please do not define the mask using a non-fixed type. I know it makes it easier to use the various bitmap helper routines if you use 'long', but here it is clearly superior to use "u32" for the bitmap type and do the bit operations by hand if necessary.
Otherwise you have to have all of this ulong size CPP conditional code which is incredibly ugly.
Furthermore you have to use fixed sized types anyways so that we don't need compat code to deal with 32-bit userspace applications making these ethtool calls into a 64-bit kernel.
THanks.
David Miller
maintainerRe: [PATCH net-next v3 03/17] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
From: David Decotigny <[email protected]>
Date: Tue, 1 Dec 2015 22:00:58 -0800
Quoted 2 lines
There is a set of conversion routines ulong[]<->u32[] to address this 32/64-bit compat issue.
And it's extremely ugly.
There is nothing stopping you from adding bitmap_set32() et al. helpers to facilitate things.
PATCH v3 4/17 tx4939: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- arch/mips/txx9/generic/setup_tx4939.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/mips/txx9/generic/setup_tx4939.c +4 -3
@@ -320,11 +320,12 @@ void __init tx4939_sio_init(unsigned int sclk, unsigned int cts_mask)#if IS_ENABLED (CONFIG_TC35815 )static u32 tx4939_get_eth_speed (struct net_device *dev) { -struct ethtool_cmd cmd; -if (__ethtool_get_settings (dev, &cmd)) +struct ethtool_ksettings cmd; + +if (__ethtool_get_ksettings (dev, &cmd))return 100 ;/* default 100Mbps */ -return ethtool_cmd_speed (&cmd); +return cmd.parent.speed; } static int tx4939_netdev_event(struct notifier_block *this,
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH net-next v3 04/17] tx4939: use __ethtool_get_ksettings
On Mon, Nov 30, 2015 at 02:05:42PM -0800, David Decotigny wrote:
Ralf
PATCH v3 5/17 net: usnic: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +4 -4
@@ -324,12 +324,12 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr *props) {struct usnic_ib_dev *us_ibdev =to_usdev (ibdev); -struct ethtool_cmd cmd; +struct ethtool_ksettings cmd;usnic_dbg ("\n" );mutex_lock (&us_ibdev->usdev_lock); -__ethtool_get_settings (us_ibdev->netdev, &cmd); +__ethtool_get_ksettings (us_ibdev->netdev, &cmd);memset (props,0 ,sizeof (*props)); props->lid =0 ;
@@ -353,8 +353,8 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, props->pkey_tbl_len =1 ; props->bad_pkey_cntr =0 ; props->qkey_viol_cntr =0 ; -eth_speed_to_ib_speed (cmd.speed, &props->active_speed, - &props->active_width); +eth_speed_to_ib_speed (cmd.parent.speed, &props->active_speed, + &props->active_width); props->max_mtu =IB_MTU_4096 ; props->active_mtu =iboe_get_mtu (us_ibdev->ufdev->mtu);/* Userspace will adjust for hdrs */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 6/17 net: bonding: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/bonding/bond_main.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/bonding/bond_main.c +6 -8
@@ -374,22 +374,20 @@ down:static void bond_update_speed_duplex (struct slave *slave) {struct net_device *slave_dev = slave->dev; -struct ethtool_cmd ecmd; -u32 slave_speed; +struct ethtool_ksettings ecmd;int res; slave->speed =SPEED_UNKNOWN ; slave->duplex =DUPLEX_UNKNOWN ; - res =__ethtool_get_settings (slave_dev, &ecmd); + res =__ethtool_get_ksettings (slave_dev, &ecmd);if (res <0 )return ; - slave_speed =ethtool_cmd_speed (&ecmd); -if (slave_speed ==0 || slave_speed == ((__u32) -1 )) +if (ecmd.parent.speed ==0 || ecmd.parent.speed == ((__u32)-1 ))return ; -switch (ecmd.duplex) { +switch (ecmd.parent.duplex) {case DUPLEX_FULL :case DUPLEX_HALF :break ;
@@ -397,8 +395,8 @@ static void bond_update_speed_duplex(struct slave *slave)return ; } - slave->speed = slave_speed; - slave->duplex = ecmd.duplex; + slave->speed = ecmd.parent.speed; + slave->duplex = ecmd.parent.duplex;return ; }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 7/17 net: ipvlan: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/ipvlan/ipvlan_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ipvlan/ipvlan_main.c +4 -4
@@ -346,12 +346,12 @@ static const struct header_ops ipvlan_header_ops = { .cache_update = eth_header_cache_update, }; -static int ipvlan_ethtool_get_settings (struct net_device *dev, -struct ethtool_cmd *cmd) +static int ipvlan_ethtool_get_ksettings (struct net_device *dev, +struct ethtool_ksettings *cmd) {const struct ipvl_dev *ipvlan =netdev_priv (dev); -return __ethtool_get_settings (ipvlan->phy_dev, cmd); +return __ethtool_get_ksettings (ipvlan->phy_dev, cmd); } static void ipvlan_ethtool_get_drvinfo(struct net_device *dev,
@@ -377,7 +377,7 @@ static void ipvlan_ethtool_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops ipvlan_ethtool_ops = { .get_link = ethtool_op_get_link, - .get_settings = ipvlan_ethtool_get_settings, + .get_ksettings = ipvlan_ethtool_get_ksettings, .get_drvinfo = ipvlan_ethtool_get_drvinfo, .get_msglevel = ipvlan_ethtool_get_msglevel, .set_msglevel = ipvlan_ethtool_set_msglevel,
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 8/17 net: macvlan: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/macvlan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/macvlan.c +4 -4
@@ -940,12 +940,12 @@ static void macvlan_ethtool_get_drvinfo(struct net_device *dev,strlcpy (drvinfo->version,"0.1" ,sizeof (drvinfo->version)); } -static int macvlan_ethtool_get_settings (struct net_device *dev, -struct ethtool_cmd *cmd) +static int macvlan_ethtool_get_ksettings (struct net_device *dev, +struct ethtool_ksettings *cmd) {const struct macvlan_dev *vlan =netdev_priv (dev); -return __ethtool_get_settings (vlan->lowerdev, cmd); +return __ethtool_get_ksettings (vlan->lowerdev, cmd); } static netdev_features_t macvlan_fix_features(struct net_device *dev,
@@ -1020,7 +1020,7 @@ static int macvlan_dev_get_iflink(const struct net_device *dev)static const struct ethtool_ops macvlan_ethtool_ops = { .get_link = ethtool_op_get_link, - .get_settings = macvlan_ethtool_get_settings, + .get_ksettings = macvlan_ethtool_get_ksettings, .get_drvinfo = macvlan_ethtool_get_drvinfo, };
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 9/17 net: team: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/team/team.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/team/team.c +4 -4
@@ -2776,12 +2776,12 @@ static void __team_port_change_send(struct team_port *port, bool linkup) port->state.linkup = linkup;team_refresh_port_linkup (port);if (linkup) { -struct ethtool_cmd ecmd; +struct ethtool_ksettings ecmd; - err =__ethtool_get_settings (port->dev, &ecmd); + err =__ethtool_get_ksettings (port->dev, &ecmd);if (!err) { - port->state.speed =ethtool_cmd_speed (&ecmd); - port->state.duplex = ecmd.duplex; + port->state.speed = ecmd.parent.speed; + port->state.duplex = ecmd.parent.duplex; goto send_event; } }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 10/17 net: fcoe: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/scsi/fcoe/fcoe_transport.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/scsi/fcoe/fcoe_transport.c +20 -16
@@ -93,36 +93,40 @@ static struct notifier_block libfcoe_notifier = {int fcoe_link_speed_update (struct fc_lport *lport) {struct net_device *netdev =fcoe_get_netdev (lport); -struct ethtool_cmd ecmd; +struct ethtool_ksettings ecmd; -if (!__ethtool_get_settings (netdev, &ecmd)) { +if (!__ethtool_get_ksettings (netdev, &ecmd)) { lport->link_supported_speeds &= ~(FC_PORTSPEED_1GBIT |FC_PORTSPEED_10GBIT |FC_PORTSPEED_20GBIT |FC_PORTSPEED_40GBIT ); -if (ecmd.supported & (SUPPORTED_1000baseT_Half | - SUPPORTED_1000baseT_Full | - SUPPORTED_1000baseKX_Full)) +if (ecmd.link_modes.supported.mask[0 ] & ( + SUPPORTED_1000baseT_Half | + SUPPORTED_1000baseT_Full | + SUPPORTED_1000baseKX_Full)) lport->link_supported_speeds |=FC_PORTSPEED_1GBIT ; -if (ecmd.supported & (SUPPORTED_10000baseT_Full | - SUPPORTED_10000baseKX4_Full | - SUPPORTED_10000baseKR_Full | - SUPPORTED_10000baseR_FEC)) +if (ecmd.link_modes.supported.mask[0 ] & ( + SUPPORTED_10000baseT_Full | + SUPPORTED_10000baseKX4_Full | + SUPPORTED_10000baseKR_Full | + SUPPORTED_10000baseR_FEC)) lport->link_supported_speeds |=FC_PORTSPEED_10GBIT ; -if (ecmd.supported & (SUPPORTED_20000baseMLD2_Full | - SUPPORTED_20000baseKR2_Full)) +if (ecmd.link_modes.supported.mask[0 ] & ( + SUPPORTED_20000baseMLD2_Full | + SUPPORTED_20000baseKR2_Full)) lport->link_supported_speeds |=FC_PORTSPEED_20GBIT ; -if (ecmd.supported & (SUPPORTED_40000baseKR4_Full | - SUPPORTED_40000baseCR4_Full | - SUPPORTED_40000baseSR4_Full | - SUPPORTED_40000baseLR4_Full)) +if (ecmd.link_modes.supported.mask[0 ] & ( + SUPPORTED_40000baseKR4_Full | + SUPPORTED_40000baseCR4_Full | + SUPPORTED_40000baseSR4_Full | + SUPPORTED_40000baseLR4_Full)) lport->link_supported_speeds |=FC_PORTSPEED_40GBIT ; -switch (ethtool_cmd_speed (&ecmd)) { +switch (ecmd.parent.speed) {case SPEED_1000 : lport->link_speed =FC_PORTSPEED_1GBIT ;break ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 11/17 net: rdma: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- include/rdma/ib_addr.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
include/rdma/ib_addr.h +6 -8
@@ -254,24 +254,22 @@ static inline enum ib_mtu iboe_get_mtu(int mtu)static inline int iboe_get_rate (struct net_device *dev) { -struct ethtool_cmd cmd; -u32 speed; +struct ethtool_ksettings cmd;int err;rtnl_lock (); - err =__ethtool_get_settings (dev, &cmd); + err =__ethtool_get_ksettings (dev, &cmd);rtnl_unlock ();if (err)return IB_RATE_PORT_CURRENT ; - speed =ethtool_cmd_speed (&cmd); -if (speed >=40000 ) +if (cmd.parent.speed >=40000 )return IB_RATE_40_GBPS ; -else if (speed >=30000 ) +else if (cmd.parent.speed >=30000 )return IB_RATE_30_GBPS ; -else if (speed >=20000 ) +else if (cmd.parent.speed >=20000 )return IB_RATE_20_GBPS ; -else if (speed >=10000 ) +else if (cmd.parent.speed >=10000 )return IB_RATE_10_GBPS ;else return IB_RATE_PORT_CURRENT ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 12/17 net: 8021q: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- net/8021q/vlan_dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/8021q/vlan_dev.c +4 -4
@@ -620,12 +620,12 @@ static netdev_features_t vlan_dev_fix_features(struct net_device *dev,return features; } -static int vlan_ethtool_get_settings (struct net_device *dev, -struct ethtool_cmd *cmd) +static int vlan_ethtool_get_ksettings (struct net_device *dev, +struct ethtool_ksettings *cmd) {const struct vlan_dev_priv *vlan =vlan_dev_priv (dev); -return __ethtool_get_settings (vlan->real_dev, cmd); +return __ethtool_get_ksettings (vlan->real_dev, cmd); } static void vlan_ethtool_get_drvinfo(struct net_device *dev,
@@ -740,7 +740,7 @@ static int vlan_dev_get_iflink(const struct net_device *dev) }static const struct ethtool_ops vlan_ethtool_ops = { - .get_settings = vlan_ethtool_get_settings, + .get_ksettings = vlan_ethtool_get_ksettings, .get_drvinfo = vlan_ethtool_get_drvinfo, .get_link = ethtool_op_get_link, .get_ts_info = vlan_ethtool_get_ts_info,
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 13/17 net: bridge: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- net/bridge/br_if.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/bridge/br_if.c +3 -3
@@ -36,10 +36,10 @@*/ static int port_cost (struct net_device *dev) { -struct ethtool_cmd ecmd; +struct ethtool_ksettings ecmd; -if (!__ethtool_get_settings (dev, &ecmd)) { -switch (ethtool_cmd_speed (&ecmd)) { +if (!__ethtool_get_ksettings (dev, &ecmd)) { +switch (ecmd.parent.speed) {case SPEED_10000 :return 2 ;case SPEED_1000 :
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 14/17 net: core: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- net/core/net-sysfs.c | 15 +++++++++------ net/packet/af_packet.c | 11 +++++------ 2 files changed, 14 insertions(+), 12 deletions(-)
net/core/net-sysfs.c +9 -6
@@ -199,9 +199,10 @@ static ssize_t speed_show(struct device *dev,return restart_syscall ();if (netif_running (netdev)) { -struct ethtool_cmd cmd; -if (!__ethtool_get_settings (netdev, &cmd)) - ret =sprintf (buf, fmt_dec,ethtool_cmd_speed (&cmd)); +struct ethtool_ksettings cmd; + +if (!__ethtool_get_ksettings (netdev, &cmd)) + ret =sprintf (buf, fmt_dec, cmd.parent.speed); }rtnl_unlock ();return ret;
@@ -218,10 +219,12 @@ static ssize_t duplex_show(struct device *dev,return restart_syscall ();if (netif_running (netdev)) { -struct ethtool_cmd cmd; -if (!__ethtool_get_settings (netdev, &cmd)) { +struct ethtool_ksettings cmd; + +if (!__ethtool_get_ksettings (netdev, &cmd)) {const char *duplex; -switch (cmd.duplex) { + +switch (cmd.parent.duplex) {case DUPLEX_HALF : duplex ="half" ;break ;
net/packet/af_packet.c +5 -6
@@ -557,9 +557,8 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, {struct net_device *dev;unsigned int mbits =0 , msec =0 , div =0 , tmo =0 ; -struct ethtool_cmd ecmd; +struct ethtool_ksettings ecmd;int err; -u32 speed;rtnl_lock (); dev =__dev_get_by_index (sock_net (&po->sk), po->ifindex);
@@ -567,19 +566,19 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,rtnl_unlock ();return DEFAULT_PRB_RETIRE_TOV ; } - err =__ethtool_get_settings (dev, &ecmd); - speed =ethtool_cmd_speed (&ecmd); + err =__ethtool_get_ksettings (dev, &ecmd);rtnl_unlock ();if (!err) {/* * If the link speed is so slow you don't really * need to worry about perf anyways */ -if (speed <SPEED_1000 || speed ==SPEED_UNKNOWN ) { +if (ecmd.parent.speed <SPEED_1000 || + ecmd.parent.speed ==SPEED_UNKNOWN ) {return DEFAULT_PRB_RETIRE_TOV ; }else { msec =1 ; - div = speed /1000 ; + div = ecmd.parent.speed /1000 ; } }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 15/17 net: ethtool: remove unused __ethtool_get_settings
In reply to David DecotignyFrom: David Decotigny <[email protected]>
replaced by __ethtool_get_ksettings.
--- include/linux/ethtool.h | 4 ---- net/core/ethtool.c | 49 ++++++++++++++----------------------------------- 2 files changed, 14 insertions(+), 39 deletions(-)
include/linux/ethtool.h +0 -4
@@ -161,10 +161,6 @@ __ethtool_add_link_modes(ethtool_link_mode_mask_t *dst,extern int __ethtool_get_ksettings (struct net_device *dev,struct ethtool_ksettings *ksettings); -/* DEPRECATED, use __ethtool_get_ksettings */ -extern int __ethtool_get_settings (struct net_device *dev, -struct ethtool_cmd *cmd); -/** * struct ethtool_ops - optional netdev operations * @get_settings: DEPRECATED, use %get_ksettings/%set_ksettings
net/core/ethtool.c +14 -35
75 lines not on this page · raw message
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 16/17 net: mlx4: convenience predicate for debug messages
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +3 -1
@@ -740,9 +740,11 @@ __printf(3, 4)void en_print (const char *level,const struct mlx4_en_priv *priv,const char *format, ...); +#define en_dbg_enabled (mlevel, priv) \ + (NETIF_MSG_##mlevel & (priv)->msg_enable)#define en_dbg (mlevel, priv, format, ...) \ do { \ - if (NETIF_MSG_##mlevel & (priv)->msg_enable) \ + if (en_dbg_enabled(mlevel, priv)) \ en_print(KERN_DEBUG, priv, format, ##__VA_ARGS__); \ } while (0)#define en_warn (priv, format, ...) \
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v3 17/17 net: mlx4: use new ETHTOOL_G/SSETTINGS API
In reply to David DecotignyFrom: David Decotigny <[email protected]>
--- drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 323 ++++++++++++------------ drivers/net/ethernet/mellanox/mlx4/en_main.c | 1 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 1 + 3 files changed, 157 insertions(+), 168 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +155 -168
@@ -501,34 +501,30 @@ static u32 mlx4_en_autoneg_get(struct net_device *dev)return autoneg; } -static u32 ptys_get_supported_port (struct mlx4_ptys_reg *ptys_reg) +static void ptys2ethtool_update_supported_port (ethtool_link_mode_mask_t *mask, +struct mlx4_ptys_reg *ptys_reg) {u32 eth_proto =be32_to_cpu (ptys_reg->eth_proto_cap);if (eth_proto & (MLX4_PROT_MASK (MLX4_10GBASE_T ) |MLX4_PROT_MASK (MLX4_1000BASE_T ) |MLX4_PROT_MASK (MLX4_100BASE_TX ))) { -return SUPPORTED_TP ; - } - -if (eth_proto & (MLX4_PROT_MASK (MLX4_10GBASE_CR ) +ethtool_add_link_modes (mask,ETHTOOL_LINK_MODE_TP_BIT ); + }else if (eth_proto & (MLX4_PROT_MASK (MLX4_10GBASE_CR ) |MLX4_PROT_MASK (MLX4_10GBASE_SR ) |MLX4_PROT_MASK (MLX4_56GBASE_SR4 ) |MLX4_PROT_MASK (MLX4_40GBASE_CR4 ) |MLX4_PROT_MASK (MLX4_40GBASE_SR4 ) |MLX4_PROT_MASK (MLX4_1000BASE_CX_SGMII ))) { -return SUPPORTED_FIBRE ; - } - -if (eth_proto & (MLX4_PROT_MASK (MLX4_56GBASE_KR4 ) +ethtool_add_link_modes (mask,ETHTOOL_LINK_MODE_FIBRE_BIT ); + }else if (eth_proto & (MLX4_PROT_MASK (MLX4_56GBASE_KR4 ) |MLX4_PROT_MASK (MLX4_40GBASE_KR4 ) |MLX4_PROT_MASK (MLX4_20GBASE_KR2 ) |MLX4_PROT_MASK (MLX4_10GBASE_KR ) |MLX4_PROT_MASK (MLX4_10GBASE_KX4 ) |MLX4_PROT_MASK (MLX4_1000BASE_KX ))) { -return SUPPORTED_Backplane; +ethtool_add_link_modes (mask, ETHTOOL_LINK_MODE_Backplane_BIT); } -return 0 ; }static u32 ptys_get_active_port (struct mlx4_ptys_reg *ptys_reg)
@@ -574,122 +570,91 @@ static u32 ptys_get_active_port(struct mlx4_ptys_reg *ptys_reg)enum ethtool_report {SUPPORTED =0 ,ADVERTISED =1 , -SPEED =2 }; +struct ptys2ethtool_config { +ethtool_link_mode_mask_t link_modes[2 ];/* SUPPORTED/ADVERTISED */ +u32 speed; +}; + +#define MLX4_BUILD_PTYS2ETHTOOL_CONFIG (reg_, speed_, ...) \ + ({ \ + struct ptys2ethtool_config *cfg; \ + cfg = &ptys2ethtool_map[reg_]; \ + cfg->speed = speed_; \ + ethtool_build_link_mode(&cfg->link_modes[SUPPORTED], \ + __VA_ARGS__); \ + ethtool_build_link_mode(&cfg->link_modes[ADVERTISED], \ + __VA_ARGS__); \ + }) +/* Translates mlx4 link mode to equivalent ethtool Link modes/speed */ -static u32 ptys2ethtool_map[MLX4_LINK_MODES_SZ ][3 ] = { - [MLX4_100BASE_TX ] = { - SUPPORTED_100baseT_Full, - ADVERTISED_100baseT_Full, -SPEED_100 - }, - - [MLX4_1000BASE_T ] = { - SUPPORTED_1000baseT_Full, - ADVERTISED_1000baseT_Full, -SPEED_1000 - }, - [MLX4_1000BASE_CX_SGMII ] = { - SUPPORTED_1000baseKX_Full, - ADVERTISED_1000baseKX_Full, -SPEED_1000 - }, - [MLX4_1000BASE_KX ] = { - SUPPORTED_1000baseKX_Full, - ADVERTISED_1000baseKX_Full, -SPEED_1000 - }, - - [MLX4_10GBASE_T ] = { - SUPPORTED_10000baseT_Full, - ADVERTISED_10000baseT_Full, -SPEED_10000 - }, - [MLX4_10GBASE_CX4 ] = { - SUPPORTED_10000baseKX4_Full, - ADVERTISED_10000baseKX4_Full, -SPEED_10000 - }, - [MLX4_10GBASE_KX4 ] = { - SUPPORTED_10000baseKX4_Full, - ADVERTISED_10000baseKX4_Full, -SPEED_10000 - }, - [MLX4_10GBASE_KR ] = { - SUPPORTED_10000baseKR_Full, - ADVERTISED_10000baseKR_Full, -SPEED_10000 - }, - [MLX4_10GBASE_CR ] = { - SUPPORTED_10000baseKR_Full, - ADVERTISED_10000baseKR_Full, -SPEED_10000 - }, - [MLX4_10GBASE_SR ] = { - SUPPORTED_10000baseKR_Full, - ADVERTISED_10000baseKR_Full, -SPEED_10000 - }, - - [MLX4_20GBASE_KR2 ] = { - SUPPORTED_20000baseMLD2_Full | SUPPORTED_20000baseKR2_Full, - ADVERTISED_20000baseMLD2_Full | ADVERTISED_20000baseKR2_Full, -SPEED_20000 - }, - - [MLX4_40GBASE_CR4 ] = { - SUPPORTED_40000baseCR4_Full, - ADVERTISED_40000baseCR4_Full, -SPEED_40000 - }, - [MLX4_40GBASE_KR4 ] = { - SUPPORTED_40000baseKR4_Full, - ADVERTISED_40000baseKR4_Full, -SPEED_40000 - }, - [MLX4_40GBASE_SR4 ] = { - SUPPORTED_40000baseSR4_Full, - ADVERTISED_40000baseSR4_Full, -SPEED_40000 - }, - - [MLX4_56GBASE_KR4 ] = { - SUPPORTED_56000baseKR4_Full, - ADVERTISED_56000baseKR4_Full, -SPEED_56000 - }, - [MLX4_56GBASE_CR4 ] = { - SUPPORTED_56000baseCR4_Full, - ADVERTISED_56000baseCR4_Full, -SPEED_56000 - }, - [MLX4_56GBASE_SR4 ] = { - SUPPORTED_56000baseSR4_Full, - ADVERTISED_56000baseSR4_Full, -SPEED_56000 - }, +static struct ptys2ethtool_config ptys2ethtool_map[MLX4_LINK_MODES_SZ ]; + +void __init mlx4_en_init_ptys2ethtool_map (void ) +{ +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_100BASE_TX ,SPEED_100 , + ETHTOOL_LINK_MODE_100baseT_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_1000BASE_T ,SPEED_1000 , + ETHTOOL_LINK_MODE_1000baseT_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_1000BASE_CX_SGMII ,SPEED_1000 , + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_1000BASE_KX ,SPEED_1000 , + ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_T ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseT_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_CX4 ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_KX4 ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_KR ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_CR ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_10GBASE_SR ,SPEED_10000 , + ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_20GBASE_KR2 ,SPEED_20000 , + ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT, + ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_40GBASE_CR4 ,SPEED_40000 , + ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_40GBASE_KR4 ,SPEED_40000 , + ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_40GBASE_SR4 ,SPEED_40000 , + ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_56GBASE_KR4 ,SPEED_56000 , + ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_56GBASE_CR4 ,SPEED_56000 , + ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT); +MLX4_BUILD_PTYS2ETHTOOL_CONFIG (MLX4_56GBASE_SR4 ,SPEED_56000 , + ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT); }; -static u32 ptys2ethtool_link_modes (u32 eth_proto,enum ethtool_report report) +static void ptys2ethtool_update_link_modes (ethtool_link_mode_mask_t *link_modes, +u32 eth_proto, +enum ethtool_report report) {int i; -u32 link_modes =0 ; -for (i =0 ; i <MLX4_LINK_MODES_SZ ; i++) {if (eth_proto &MLX4_PROT_MASK (i)) - link_modes |= ptys2ethtool_map[i][report]; +bitmap_or (link_modes->mask, + link_modes->mask, + ptys2ethtool_map[i].link_modes[report].mask, + __ETHTOOL_LINK_MODE_MASK_NBITS); } -return link_modes; } -static u32 ethtool2ptys_link_modes (u32 link_modes,enum ethtool_report report) +static u32 ethtool2ptys_link_modes (const ethtool_link_mode_mask_t *link_modes, +enum ethtool_report report) {int i;u32 ptys_modes =0 ;for (i =0 ; i <MLX4_LINK_MODES_SZ ; i++) { -if (ptys2ethtool_map[i][report] & link_modes) +if (bitmap_intersects ( + ptys2ethtool_map[i].link_modes[report].mask, + link_modes->mask, + __ETHTOOL_LINK_MODE_MASK_NBITS)) ptys_modes |=1 << i; }return ptys_modes;
@@ -702,14 +667,14 @@ static u32 speed2ptys_link_modes(u32 speed)u32 ptys_modes =0 ;for (i =0 ; i <MLX4_LINK_MODES_SZ ; i++) { -if (ptys2ethtool_map[i][SPEED ] == speed) +if (ptys2ethtool_map[i].speed == speed) ptys_modes |=1 << i; }return ptys_modes; } -static int ethtool_get_ptys_settings (struct net_device *dev, -struct ethtool_cmd *cmd) +static int ethtool_get_ptys_ksettings (struct net_device *dev, +struct ethtool_ksettings *ksettings) {struct mlx4_en_priv *priv =netdev_priv (dev);struct mlx4_ptys_reg ptys_reg;
@@ -737,79 +702,94 @@ static int ethtool_get_ptys_settings(struct net_device *dev,en_dbg (DRV , priv,"ptys_reg.eth_proto_lp_adv %x\n" ,be32_to_cpu (ptys_reg.eth_proto_lp_adv)); - cmd->supported =0 ; - cmd->advertising =0 ; +/* reset supported/advertising masks */ +ethtool_build_link_mode (&ksettings->link_modes.supported); +ethtool_build_link_mode (&ksettings->link_modes.advertising); - cmd->supported |=ptys_get_supported_port (&ptys_reg); +ptys2ethtool_update_supported_port (&ksettings->link_modes.supported, + &ptys_reg); eth_proto =be32_to_cpu (ptys_reg.eth_proto_cap); - cmd->supported |=ptys2ethtool_link_modes (eth_proto,SUPPORTED ); +ptys2ethtool_update_link_modes (&ksettings->link_modes.supported, + eth_proto,SUPPORTED ); eth_proto =be32_to_cpu (ptys_reg.eth_proto_admin); - cmd->advertising |=ptys2ethtool_link_modes (eth_proto,ADVERTISED ); +ptys2ethtool_update_link_modes (&ksettings->link_modes.advertising, + eth_proto,ADVERTISED ); - cmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; - cmd->advertising |= (priv->prof->tx_pause) ? ADVERTISED_Pause :0 ; +ethtool_add_link_modes (&ksettings->link_modes.supported, + ETHTOOL_LINK_MODE_Pause_BIT, + ETHTOOL_LINK_MODE_Pause_BIT); - cmd->advertising |= (priv->prof->tx_pause ^ priv->prof->rx_pause) ? - ADVERTISED_Asym_Pause :0 ; +if (priv->prof->tx_pause) +ethtool_add_link_modes (&ksettings->link_modes.advertising, + ETHTOOL_LINK_MODE_Pause_BIT); +if (priv->prof->tx_pause ^ priv->prof->rx_pause) +ethtool_add_link_modes (&ksettings->link_modes.advertising, + ETHTOOL_LINK_MODE_Asym_Pause_BIT); - cmd->port =ptys_get_active_port (&ptys_reg); - cmd->transceiver = (SUPPORTED_TP & cmd->supported) ? -XCVR_EXTERNAL :XCVR_INTERNAL ; + ksettings->parent.port =ptys_get_active_port (&ptys_reg);if (mlx4_en_autoneg_get (dev)) { - cmd->supported |= SUPPORTED_Autoneg; - cmd->advertising |= ADVERTISED_Autoneg; +ethtool_add_link_modes (&ksettings->link_modes.supported, + ETHTOOL_LINK_MODE_Autoneg_BIT); +ethtool_add_link_modes (&ksettings->link_modes.advertising, + ETHTOOL_LINK_MODE_Autoneg_BIT); } - cmd->autoneg = (priv->port_state.flags &MLX4_EN_PORT_ANC ) ? + ksettings->parent.autoneg + = (priv->port_state.flags &MLX4_EN_PORT_ANC ) ?AUTONEG_ENABLE :AUTONEG_DISABLE ; eth_proto =be32_to_cpu (ptys_reg.eth_proto_lp_adv); - cmd->lp_advertising =ptys2ethtool_link_modes (eth_proto,ADVERTISED ); - cmd->lp_advertising |= (priv->port_state.flags &MLX4_EN_PORT_ANC ) ? - ADVERTISED_Autoneg :0 ; +ethtool_build_link_mode (&ksettings->link_modes.lp_advertising); +ptys2ethtool_update_link_modes (&ksettings->link_modes.lp_advertising, + eth_proto,ADVERTISED ); +if (priv->port_state.flags &MLX4_EN_PORT_ANC ) +ethtool_add_link_modes (&ksettings->link_modes.lp_advertising, + ETHTOOL_LINK_MODE_Autoneg_BIT); - cmd->phy_address =0 ; - cmd->mdio_support =0 ; - cmd->maxtxpkt =0 ; - cmd->maxrxpkt =0 ; - cmd->eth_tp_mdix =ETH_TP_MDI_INVALID ; - cmd->eth_tp_mdix_ctrl =ETH_TP_MDI_AUTO ; + ksettings->parent.phy_address =0 ; + ksettings->parent.mdio_support =0 ; + ksettings->parent.eth_tp_mdix =ETH_TP_MDI_INVALID ; + ksettings->parent.eth_tp_mdix_ctrl =ETH_TP_MDI_AUTO ;return ret; } -static void ethtool_get_default_settings (struct net_device *dev, -struct ethtool_cmd *cmd) +static void ethtool_get_default_ksettings (struct net_device *dev, +struct ethtool_ksettings *ksettings) {struct mlx4_en_priv *priv =netdev_priv (dev);int trans_type; - cmd->autoneg =AUTONEG_DISABLE ; - cmd->supported = SUPPORTED_10000baseT_Full; - cmd->advertising = ADVERTISED_10000baseT_Full; + ksettings->parent.autoneg =AUTONEG_DISABLE ; +ethtool_build_link_mode (&ksettings->link_modes.supported, + ETHTOOL_LINK_MODE_10000baseT_Full_BIT); +ethtool_build_link_mode (&ksettings->link_modes.advertising, + ETHTOOL_LINK_MODE_10000baseT_Full_BIT); trans_type = priv->port_state.transceiver;if (trans_type >0 && trans_type <=0xC ) { - cmd->port =PORT_FIBRE ; - cmd->transceiver =XCVR_EXTERNAL ; - cmd->supported |=SUPPORTED_FIBRE ; - cmd->advertising |=ADVERTISED_FIBRE ; + ksettings->parent.port =PORT_FIBRE ; +ethtool_add_link_modes (&ksettings->link_modes.supported, +ETHTOOL_LINK_MODE_FIBRE_BIT ); +ethtool_add_link_modes (&ksettings->link_modes.advertising, +ETHTOOL_LINK_MODE_FIBRE_BIT ); }else if (trans_type ==0x80 || trans_type ==0 ) { - cmd->port =PORT_TP ; - cmd->transceiver =XCVR_INTERNAL ; - cmd->supported |=SUPPORTED_TP ; - cmd->advertising |=ADVERTISED_TP ; + ksettings->parent.port =PORT_TP ; +ethtool_add_link_modes (&ksettings->link_modes.supported, +ETHTOOL_LINK_MODE_TP_BIT ); +ethtool_add_link_modes (&ksettings->link_modes.advertising, +ETHTOOL_LINK_MODE_TP_BIT ); }else { - cmd->port =-1 ; - cmd->transceiver =-1 ; + ksettings->parent.port =-1 ; } } -static int mlx4_en_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) +static int mlx4_en_get_ksettings (struct net_device *dev, +struct ethtool_ksettings *ksettings) {struct mlx4_en_priv *priv =netdev_priv (dev);int ret = -EINVAL ;
@@ -822,16 +802,16 @@ static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) priv->port_state.flags & MLX4_EN_PORT_ANE);if (priv->mdev->dev->caps.flags2 &MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL ) - ret =ethtool_get_ptys_settings (dev, cmd); + ret =ethtool_get_ptys_ksettings (dev, ksettings);if (ret)/* ETH PROT CRTL is not supported or PTYS CMD failed */ -ethtool_get_default_settings (dev, cmd); +ethtool_get_default_ksettings (dev, ksettings);if (netif_carrier_ok (dev)) { -ethtool_cmd_speed_set (cmd, priv->port_state.link_speed); - cmd->duplex =DUPLEX_FULL ; + ksettings->parent.speed = priv->port_state.link_speed; + ksettings->parent.duplex =DUPLEX_FULL ; }else { -ethtool_cmd_speed_set (cmd,SPEED_UNKNOWN ); - cmd->duplex =DUPLEX_UNKNOWN ; + ksettings->parent.speed =SPEED_UNKNOWN ; + ksettings->parent.duplex =DUPLEX_UNKNOWN ; }return 0 ; }
@@ -855,21 +835,28 @@ static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed,return proto_admin; } -static int mlx4_en_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +static int mlx4_en_set_ksettings (struct net_device *dev, +const struct ethtool_ksettings *ksettings) {struct mlx4_en_priv *priv =netdev_priv (dev);struct mlx4_ptys_reg ptys_reg;__be32 proto_admin;int ret; -u32 ptys_adv =ethtool2ptys_link_modes (cmd->advertising,ADVERTISED ); -int speed =ethtool_cmd_speed (cmd); +u32 ptys_adv =ethtool2ptys_link_modes ( + &ksettings->link_modes.advertising,ADVERTISED ); +const int speed = ksettings->parent.speed; -en_dbg (DRV , priv,"Set Speed=%d adv=0x%x autoneg=%d duplex=%d\n" , - speed, cmd->advertising, cmd->autoneg, cmd->duplex); +if (en_dbg_enabled (DRV , priv)) { +en_dbg (DRV , priv, +"Set Speed=%d adv={%*pbl} autoneg=%d duplex=%d\n" , + speed, __ETHTOOL_LINK_MODE_MASK_NBITS, + ksettings->link_modes.supported.mask, + ksettings->parent.autoneg, ksettings->parent.duplex); + }if (!(priv->mdev->dev->caps.flags2 &MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL ) || - (cmd->duplex ==DUPLEX_HALF )) + (ksettings->parent.duplex ==DUPLEX_HALF ))return -EINVAL ;memset (&ptys_reg,0 ,sizeof (ptys_reg));
@@ -883,7 +870,7 @@ static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)return 0 ; } - proto_admin = cmd->autoneg ==AUTONEG_ENABLE ? + proto_admin = ksettings->parent.autoneg ==AUTONEG_ENABLE ?cpu_to_be32 (ptys_adv) :speed_set_ptys_admin (priv, speed, ptys_reg.eth_proto_cap);
@@ -1982,8 +1969,8 @@ static int mlx4_en_set_phys_id(struct net_device *dev,const struct ethtool_ops mlx4_en_ethtool_ops = { .get_drvinfo = mlx4_en_get_drvinfo, - .get_settings = mlx4_en_get_settings, - .set_settings = mlx4_en_set_settings, + .get_ksettings = mlx4_en_get_ksettings, + .set_ksettings = mlx4_en_set_ksettings, .get_link = ethtool_op_get_link, .get_strings = mlx4_en_get_strings, .get_sset_count = mlx4_en_get_sset_count,
drivers/net/ethernet/mellanox/mlx4/en_main.c +1 -0
@@ -389,6 +389,7 @@ static void mlx4_en_verify_params(void)static int __init mlx4_en_init (void ) {mlx4_en_verify_params (); +mlx4_en_init_ptys2ethtool_map ();return mlx4_register_interface (&mlx4_en_interface); }
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +1 -0
@@ -607,6 +607,7 @@ static inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz)#define MLX4_EN_WOL_DO_MODIFY (1ULL << 63) +void mlx4_en_init_ptys2ethtool_map (void );void mlx4_en_update_loopback_state (struct net_device *dev,netdev_features_t features);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0