new ETHTOOL_GSETTINGS/SSETTINGS API
Subsystems (18)
v7 cover new ETHTOOL_GSETTINGS/SSETTINGS API
From: David Decotigny <[email protected]>
History:
v7
- module_exit in test_bitmap
v6
- fix copy_from_user in user/kernel handshake
v5
note: please see v4 bullets for a question regarding bitmap.c
- minor fix to make allyesconfig/allmodconfig
v4
- removed typedef for link mode bitmaps
- moved bitmap<->u32[] conversion routines to bitmap.c . This is the naive implementation. I have an endian-aware version that uses memcpy/memset as much as possible, but I find it harder to follow (see http://paste.ubuntu.com/13863722/). Please let me know if I should use it instead.
- fixes suggested by Ben Hutchings
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 heap/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?
- 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 (19):
lib/bitmap.c: conversion routines to/from u32 array
test_bitmap: unit tests for lib/bitmap.c
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 | 344 ++++++++++---------- 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/bitmap.h | 6 + include/linux/ethtool.h | 84 ++++- include/rdma/ib_addr.h | 14 +- include/uapi/linux/ethtool.h | 320 ++++++++++++++---- lib/Kconfig.debug | 8 + lib/Makefile | 1 + lib/bitmap.c | 86 +++++ lib/test_bitmap.c | 348 ++++++++++++++++++++ net/8021q/vlan_dev.c | 8 +- net/bridge/br_if.c | 6 +- net/core/ethtool.c | 413 +++++++++++++++++++++++- net/core/net-sysfs.c | 15 +- net/packet/af_packet.c | 11 +- tools/testing/selftests/lib/Makefile | 2 +- tools/testing/selftests/lib/bitmap.sh | 10 + 25 files changed, 1445 insertions(+), 328 deletions(-) create mode 100644 lib/test_bitmap.c create mode 100644 tools/testing/selftests/lib/bitmap.sh
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v7 1/19 lib/bitmap.c: conversion routines to/from u32 array
From: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[email protected]>
Aimed at transferring bitmaps to/from user-space in a 32/64-bit agnostic way.
Tested:
unit tests (next patch) on qemu i386, x86_64, ppc, ppc64 BE and LE, ARM.
--- include/linux/bitmap.h | 6 ++++ lib/bitmap.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+)
include/linux/bitmap.h +6 -0
@@ -59,6 +59,8 @@* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region * bitmap_release_region(bitmap, pos, order) Free specified bit region * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region +* bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words) +* bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words) */ /*
@@ -163,6 +165,10 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,extern int bitmap_find_free_region (unsigned long *bitmap,unsigned int bits,int order);extern void bitmap_release_region (unsigned long *bitmap,unsigned int pos,int order);extern int bitmap_allocate_region (unsigned long *bitmap,unsigned int pos,int order); +extern void bitmap_from_u32array (unsigned long *bitmap,unsigned int nbits, +const u32 *buf,unsigned int nwords); +extern void bitmap_to_u32array (u32 *buf,unsigned int nwords, +const unsigned long *bitmap,unsigned int nbits);#ifdef __BIG_ENDIANextern void bitmap_copy_le (unsigned long *dst,const unsigned long *src,unsigned int nbits);#else
lib/bitmap.c +86 -0
98 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v7 2/19 test_bitmap: unit tests for lib/bitmap.c
In reply to David DecotignyFrom: David Decotigny <[email protected]>
This is mainly testing bitmap construction and conversion to/from u32[] for now.
Tested:
qemu i386, x86_64, ppc, ppc64 BE and LE, ARM.
--- lib/Kconfig.debug | 8 + lib/Makefile | 1 + lib/test_bitmap.c | 348 ++++++++++++++++++++++++++++++++++ tools/testing/selftests/lib/Makefile | 2 +- tools/testing/selftests/lib/bitmap.sh | 10 + 5 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 lib/test_bitmap.c create mode 100644 tools/testing/selftests/lib/bitmap.sh
lib/Kconfig.debug +8 -0
@@ -1738,6 +1738,14 @@ config TEST_KSTRTOX config TEST_PRINTF tristate "Test printf() family of functions at runtime" +config TEST_BITMAP + tristate "Test bitmap_*() family of functions at runtime" + default n + help + Enable this option to test the bitmap functions at boot. + + If unsure, say N. + config TEST_RHASHTABLE tristate "Perform selftest on resizable hash table" default n
lib/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o obj-$(CONFIG_TEST_PRINTF) += test_printf.o +obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o += -DDEBUG
lib/test_bitmap.c new file +348 -0
348 lines not on this page · raw message
tools/testing/selftests/lib/Makefile +1 -1
@@ -3,6 +3,6 @@ # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" all: -TEST_PROGS := printf.sh +TEST_PROGS := printf.sh bitmap.sh include ../lib.mk
tools/testing/selftests/lib/bitmap.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/sh +# Runs bitmap infrastructure tests using test_bitmap kernel module + +if /sbin/modprobe -q test_bitmap; then + /sbin/modprobe -q -r test_bitmap + echo "bitmap: ok" +else + echo "bitmap: [FAIL]" + exit 1 +fi
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v7 3/19 net: usnic: remove unused call to ethtool_ops::get_settings
In reply to David DecotignyFrom: 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.7.0.rc3.207.g0ac5344
PATCH v7 4/19 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.7.0.rc3.207.g0ac5344
PATCH v7 5/19 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 logged if driver sets higher bits.
- future ethtool with legacy drivers: no change, still using the get_settings/set_settings callbacks, internally converted to new data structure. Deprecated fields (transceiver/maxrxpkt/maxtxpkt) will be ignored and seen as 0 from user space. Note that that "future" ethtool tool will not allow changes to these deprecated fields.
- 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 | 88 ++++++++- include/uapi/linux/ethtool.h | 320 ++++++++++++++++++++++++++------- net/core/ethtool.c | 420 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 748 insertions(+), 80 deletions(-)
include/linux/ethtool.h +80 -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,72 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)return index % n_rx_rings; } +/* number of link mode bits/ulongs handled internally by kernel */ +#define __ETHTOOL_LINK_MODE_MASK_NBITS \ + (__ETHTOOL_LINK_MODE_LAST + 1) + +/* declare a link mode bitmap */ +#define __ETHTOOL_DECLARE_LINK_MODE_MASK (name) \ + DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) + +/* 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_DECLARE_LINK_MODE_MASK (supported); +__ETHTOOL_DECLARE_LINK_MODE_MASK (advertising); +__ETHTOOL_DECLARE_LINK_MODE_MASK (lp_advertising); + } link_modes; +}; + +/** +* ethtool_ksettings_zero_link_mode - clear ksettings link mode mask +* @ptr : pointer to struct ethtool_ksettings +* @name : one of supported/advertising/lp_advertising +*/ +#define ethtool_ksettings_zero_link_mode (ptr, name) \ + bitmap_zero((ptr)->link_modes.name, __ETHTOOL_LINK_MODE_MASK_NBITS) + +/** +* ethtool_ksettings_add_link_mode - set bit in ksettings link mode mask +* @ptr : pointer to struct ethtool_ksettings +* @name : one of supported/advertising/lp_advertising +* @mode : one of the ETHTOOL_LINK_MODE_*_BIT +* (not atomic, no bound checking) +*/ +#define ethtool_ksettings_add_link_mode (ptr, name, mode) \ + __set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name) + +/** +* ethtool_ksettings_test_link_mode - test bit in ksettings link mode mask +* @ptr : pointer to struct ethtool_ksettings +* @name : one of supported/advertising/lp_advertising +* @mode : one of the ETHTOOL_LINK_MODE_*_BIT +* (not atomic, no bound checking) +* +* Returns true/false. +*/ +#define ethtool_ksettings_test_link_mode (ptr, name, mode) \ + test_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name) + +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 +258,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 +349,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 +254 -66
346 lines not on this page · raw message
net/core/ethtool.c +414 -6
456 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v7 6/19 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.7.0.rc3.207.g0ac5344
PATCH v7 7/19 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.7.0.rc3.207.g0ac5344
PATCH v7 8/19 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.7.0.rc3.207.g0ac5344
PATCH v7 9/19 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.7.0.rc3.207.g0ac5344
PATCH v7 10/19 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.7.0.rc3.207.g0ac5344
PATCH v7 11/19 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
@@ -2813,12 +2813,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.7.0.rc3.207.g0ac5344
PATCH v7 12/19 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[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[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[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[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.7.0.rc3.207.g0ac5344
PATCH v7 13/19 net: rdma: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[email protected]>
--- include/rdma/ib_addr.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
include/rdma/ib_addr.h +6 -8
@@ -262,24 +262,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.7.0.rc3.207.g0ac5344
PATCH v7 14/19 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
@@ -621,12 +621,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,
@@ -741,7 +741,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.7.0.rc3.207.g0ac5344
PATCH v7 15/19 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.7.0.rc3.207.g0ac5344
PATCH v7 16/19 net: core: use __ethtool_get_ksettings
In reply to David DecotignyFrom: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[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.7.0.rc3.207.g0ac5344
PATCH v7 17/19 net: ethtool: remove unused __ethtool_get_settings
In reply to David DecotignyFrom: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[email protected]>
replaced by __ethtool_get_ksettings.
--- include/linux/ethtool.h | 4 ---- net/core/ethtool.c | 45 ++++++++++++++------------------------------- 2 files changed, 14 insertions(+), 35 deletions(-)
include/linux/ethtool.h +0 -4
@@ -148,10 +148,6 @@ struct ethtool_ksettings {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 -31
67 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v7 18/19 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.7.0.rc3.207.g0ac5344
PATCH v7 19/19 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 | 344 ++++++++++++------------ drivers/net/ethernet/mellanox/mlx4/en_main.c | 1 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 1 + 3 files changed, 177 insertions(+), 169 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +175 -169
@@ -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 (unsigned long *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 ) +__set_bit (ETHTOOL_LINK_MODE_TP_BIT , mask); + }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 ) +__set_bit (ETHTOOL_LINK_MODE_FIBRE_BIT , mask); + }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; +__set_bit (ETHTOOL_LINK_MODE_Backplane_BIT, mask); } -return 0 ; }static u32 ptys_get_active_port (struct mlx4_ptys_reg *ptys_reg)
@@ -574,122 +570,111 @@ 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_DECLARE_LINK_MODE_MASK (supported); +__ETHTOOL_DECLARE_LINK_MODE_MASK (advertised); +u32 speed; +}; + +static unsigned long *ptys2ethtool_link_mode (struct ptys2ethtool_config *cfg, +enum ethtool_report report) +{ +switch (report) { +case SUPPORTED : +return cfg->supported; +case ADVERTISED : +return cfg->advertised; + } +return NULL ; +} + +#define MLX4_BUILD_PTYS2ETHTOOL_CONFIG (reg_, speed_, ...) \ + ({ \ + struct ptys2ethtool_config *cfg; \ + const unsigned int modes[] = { __VA_ARGS__ }; \ + unsigned int i; \ + cfg = &ptys2ethtool_map[reg_]; \ + cfg->speed = speed_; \ + bitmap_zero(cfg->supported, \ + __ETHTOOL_LINK_MODE_MASK_NBITS); \ + bitmap_zero(cfg->advertised, \ + __ETHTOOL_LINK_MODE_MASK_NBITS); \ + for (i = 0 ; i < ARRAY_SIZE(modes) ; ++i) { \ + __set_bit(modes[i], cfg->supported); \ + __set_bit(modes[i], cfg->advertised); \ + } \ + }) +/* 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 (unsigned long *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, link_modes, +ptys2ethtool_link_mode (&ptys2ethtool_map[i], + report), + __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 unsigned long *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_link_mode (&ptys2ethtool_map[i], + report), + link_modes, + __ETHTOOL_LINK_MODE_MASK_NBITS)) ptys_modes |=1 << i; }return ptys_modes;
@@ -702,14 +687,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 +722,93 @@ 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_ksettings_zero_link_mode (ksettings, supported); +ethtool_ksettings_zero_link_mode (ksettings, 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_ksettings_add_link_mode (ksettings, supported, Pause); +ethtool_ksettings_add_link_mode (ksettings, supported, Asym_Pause); - cmd->advertising |= (priv->prof->tx_pause ^ priv->prof->rx_pause) ? - ADVERTISED_Asym_Pause :0 ; +if (priv->prof->tx_pause) +ethtool_ksettings_add_link_mode (ksettings, advertising, + Pause); +if (priv->prof->tx_pause ^ priv->prof->rx_pause) +ethtool_ksettings_add_link_mode (ksettings, advertising, + Asym_Pause); - 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_ksettings_add_link_mode (ksettings, supported, + Autoneg); +ethtool_ksettings_add_link_mode (ksettings, advertising, + Autoneg); } - 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_ksettings_zero_link_mode (ksettings, lp_advertising); +ptys2ethtool_update_link_modes (ksettings->link_modes.lp_advertising, + eth_proto,ADVERTISED ); +if (priv->port_state.flags &MLX4_EN_PORT_ANC ) +ethtool_ksettings_add_link_mode (ksettings, lp_advertising, + Autoneg); - 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; - trans_type = priv->port_state.transceiver; + ksettings->parent.autoneg =AUTONEG_DISABLE ; +ethtool_ksettings_zero_link_mode (ksettings, supported); +ethtool_ksettings_add_link_mode (ksettings, supported, + 10000baseT_Full); + +ethtool_ksettings_zero_link_mode (ksettings, advertising); +ethtool_ksettings_add_link_mode (ksettings, advertising, + 10000baseT_Full); + + 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_ksettings_add_link_mode (ksettings, supported,FIBRE ); +ethtool_ksettings_add_link_mode (ksettings, advertising,FIBRE ); }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_ksettings_add_link_mode (ksettings, supported,TP ); +ethtool_ksettings_add_link_mode (ksettings, advertising,TP ); }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 +821,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 +854,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.advertising, + 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 +889,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 +1988,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
@@ -382,6 +382,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.7.0.rc3.207.g0ac5344
Andrew Morton
maintainerRe: [PATCH net-next v7 01/19] lib/bitmap.c: conversion routines to/from u32 array
In reply to David DecotignyQuoted 14 lines · On Sun, 7 Feb 2016 17:08:45 -0800 David Decotigny…
From: David Decotigny <decot-Ypc/8FJVVoBWk0Htik3J/[email protected]>
Aimed at transferring bitmaps to/from user-space in a 32/64-bit agnostic way.
Tested:
unit tests (next patch) on qemu i386,x86_64, ppc, ppc64 BE and LE, ARM.lib/bitmap.c +1
-0@@ -1060,6 +1062,90 @@ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order)EXPORT_SYMBOL (bitmap_allocate_region);/** +* bitmap_from_u32array - copy the contents of a u32 array of bits to bitmap
lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1075
Quoted 10 lines
lib/bitmap.c +10
-0+* @bitmap: array of unsigned longs, the destination bitmap, non NULL +* @nbits: number of bits in @bitmap +* @buf: array of u32 (in host byte order), the source bitmap, non NULL +* @nwords: number of u32 words in @buf +* +* copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining +* bits between nword and nbits in @bitmap (if any) are cleared. In +* last word of @bitmap, the bits beyond nbits (if any) are kept +* unchanged. +*/
This will leave the caller not knowing how many valid bits are actually present in the resulting bitmap. To determine that, the caller will need to perform (duplicated) math on nbits' and nwords'.
lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1077
Quoted 2 lines
lib/bitmap.c +2
-0+void bitmap_from_u32array (unsigned long *bitmap,unsigned int nbits, +const u32 *buf,unsigned int nwords)
So how about we make this return the number of valid bits in *bitmap?
lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1119
Quoted 12 lines
lib/bitmap.c +12
-0+/** +* bitmap_to_u32array - copy the contents of bitmap to a u32 array of bits +* @buf: array of u32 (in host byte order), the dest bitmap, non NULL +* @nwords: number of u32 words in @buf +* @bitmap: array of unsigned longs, the source bitmap, non NULL +* @nbits: number of bits in @bitmap +* +* copy min(nbits, 32*nwords) bits from @bitmap to @buf. Remaining +* bits after nbits in @buf (if any) are cleared. +*/ +void bitmap_to_u32array (u32 *buf,unsigned int nwords, +const unsigned long *bitmap,unsigned int nbits)
Ditto.
Re: [PATCH net-next v7 01/19] lib/bitmap.c: conversion routines to/from u32 array
thanks. done in v8 I am sending right now.
Quoted 52 lines · Andrew Morton
Quoted 14 lines · On Sun, 7 Feb 2016 17:08:45 -0800 David Decotigny <[email protected]> wrote:
From: David Decotigny <[email protected]>
Aimed at transferring bitmaps to/from user-space in a 32/64-bit agnostic way.
Tested:
unit tests (next patch) on qemu i386,x86_64, ppc, ppc64 BE and LE, ARM.lib/bitmap.c +1
-0@@ -1060,6 +1062,90 @@ int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order)EXPORT_SYMBOL (bitmap_allocate_region);/** +* bitmap_from_u32array - copy the contents of a u32 array of bits to bitmap lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1075
Quoted 10 lines
lib/bitmap.c +10
-0+* @bitmap: array of unsigned longs, the destination bitmap, non NULL +* @nbits: number of bits in @bitmap +* @buf: array of u32 (in host byte order), the source bitmap, non NULL +* @nwords: number of u32 words in @buf +* +* copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining +* bits between nword and nbits in @bitmap (if any) are cleared. In +* last word of @bitmap, the bits beyond nbits (if any) are kept +* unchanged. +*/ This will leave the caller not knowing how many valid bits are actually present in the resulting bitmap. To determine that, the caller will need to perform (duplicated) math on
nbits' andnwords'.lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1077
Quoted 2 lines
lib/bitmap.c +2
-0+void bitmap_from_u32array (unsigned long *bitmap,unsigned int nbits, +const u32 *buf,unsigned int nwords)So how about we make this return the number of valid bits in *bitmap?
lib/bitmap.c int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) · line 1119
Quoted 12 lines
lib/bitmap.c +12
-0+/** +* bitmap_to_u32array - copy the contents of bitmap to a u32 array of bits +* @buf: array of u32 (in host byte order), the dest bitmap, non NULL +* @nwords: number of u32 words in @buf +* @bitmap: array of unsigned longs, the source bitmap, non NULL +* @nbits: number of bits in @bitmap +* +* copy min(nbits, 32*nwords) bits from @bitmap to @buf. Remaining +* bits after nbits in @buf (if any) are cleared. +*/ +void bitmap_to_u32array (u32 *buf,unsigned int nwords, +const unsigned long *bitmap,unsigned int nbits)Ditto.
Re: [PATCH net-next v7 15/19] net: bridge: use __ethtool_get_ksettings
In reply to David DecotignyQuoted 15 lines · On Sun, 7 Feb 2016 17:08:59 -0800 David Decotigny <[email protected]> wrote:
From: David Decotigny <[email protected]>
Signed-off-by David Decotigny <[email protected]>--- net/bridge/br_if.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/bridge/br_if.c +0
-0@@ -36,10 +36,10 @@*/ static int port_cost (struct net_device *dev) {
net/bridge/br_if.c line 45
Quoted 10 lines
net/bridge/br_if.c +3
-3-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 :
Sure looks fine for bridge.
This reminds me that bridge code needs to transition to this decade and do latest STP.