Commit 8d3f2806 authored by David S. Miller's avatar David S. Miller

Merge branch 'ethtool-ksettings'

David Decotigny says:

====================
new ETHTOOL_GLINKSETTINGS/SLINKSETTINGS API

History:
 v9
 - add 'link' in macro, struct and function names
 - rename ethtool_link_ksettings::parent -> ::base
 - remove un-needed mlx4 en_dbg_enabled() companion patch
 - note: bitmap u32[] API patches were merged separately by Kan Liang
 v8
 - bitmap u32 API returns number of bits copied, unit tests updated
 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_GLINKSETTINGS/SLINKSETTINGS), its associated callbacks
(get/set_link_ksettings) and a new struct ethtool_link_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 open questions:
 - the kernel/interface multiplexes the "tell me the bitmap length"
   handshake and the "give me the settings" inside the new
   ETHTOOL_GLINKSETTINGS 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_GLINKSETTINGS would expect the proper bitmaps
 - the link mode bitmaps are piggybacked at tail of the new struct
   ethtool_link_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_link_ksettings) to specify its
   current link mode masks. This means that kernel code is "littered"
   with "ksettings->base.field" to access "field" inside
   ethtool_settings:
   + I could use ethtool_link_settings everywhere (instead of a new
     ethtool_ksettings) and an container_of accessor (or a plain cast)
     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_link_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_link_ksettings.

Tested with legacy and "future" ethtool on 64b x86 kernel and 32+64b
ethtool, and on a 32b x86 kernel + 32b ethtool.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a87cb3e4 3d8f7cc7
...@@ -320,11 +320,12 @@ void __init tx4939_sio_init(unsigned int sclk, unsigned int cts_mask) ...@@ -320,11 +320,12 @@ void __init tx4939_sio_init(unsigned int sclk, unsigned int cts_mask)
#if IS_ENABLED(CONFIG_TC35815) #if IS_ENABLED(CONFIG_TC35815)
static u32 tx4939_get_eth_speed(struct net_device *dev) static u32 tx4939_get_eth_speed(struct net_device *dev)
{ {
struct ethtool_cmd cmd; struct ethtool_link_ksettings cmd;
if (__ethtool_get_settings(dev, &cmd))
if (__ethtool_get_link_ksettings(dev, &cmd))
return 100; /* default 100Mbps */ return 100; /* default 100Mbps */
return ethtool_cmd_speed(&cmd); return cmd.base.speed;
} }
static int tx4939_netdev_event(struct notifier_block *this, static int tx4939_netdev_event(struct notifier_block *this,
......
...@@ -269,7 +269,6 @@ int usnic_ib_query_device(struct ib_device *ibdev, ...@@ -269,7 +269,6 @@ int usnic_ib_query_device(struct ib_device *ibdev,
struct usnic_ib_dev *us_ibdev = to_usdev(ibdev); struct usnic_ib_dev *us_ibdev = to_usdev(ibdev);
union ib_gid gid; union ib_gid gid;
struct ethtool_drvinfo info; struct ethtool_drvinfo info;
struct ethtool_cmd cmd;
int qp_per_vf; int qp_per_vf;
usnic_dbg("\n"); usnic_dbg("\n");
...@@ -278,7 +277,6 @@ int usnic_ib_query_device(struct ib_device *ibdev, ...@@ -278,7 +277,6 @@ int usnic_ib_query_device(struct ib_device *ibdev,
mutex_lock(&us_ibdev->usdev_lock); mutex_lock(&us_ibdev->usdev_lock);
us_ibdev->netdev->ethtool_ops->get_drvinfo(us_ibdev->netdev, &info); 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)); memset(props, 0, sizeof(*props));
usnic_mac_ip_to_gid(us_ibdev->ufdev->mac, us_ibdev->ufdev->inaddr, usnic_mac_ip_to_gid(us_ibdev->ufdev->mac, us_ibdev->ufdev->inaddr,
&gid.raw[0]); &gid.raw[0]);
...@@ -326,12 +324,12 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, ...@@ -326,12 +324,12 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
struct ib_port_attr *props) struct ib_port_attr *props)
{ {
struct usnic_ib_dev *us_ibdev = to_usdev(ibdev); struct usnic_ib_dev *us_ibdev = to_usdev(ibdev);
struct ethtool_cmd cmd; struct ethtool_link_ksettings cmd;
usnic_dbg("\n"); usnic_dbg("\n");
mutex_lock(&us_ibdev->usdev_lock); mutex_lock(&us_ibdev->usdev_lock);
us_ibdev->netdev->ethtool_ops->get_settings(us_ibdev->netdev, &cmd); __ethtool_get_link_ksettings(us_ibdev->netdev, &cmd);
memset(props, 0, sizeof(*props)); memset(props, 0, sizeof(*props));
props->lid = 0; props->lid = 0;
...@@ -355,8 +353,8 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, ...@@ -355,8 +353,8 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
props->pkey_tbl_len = 1; props->pkey_tbl_len = 1;
props->bad_pkey_cntr = 0; props->bad_pkey_cntr = 0;
props->qkey_viol_cntr = 0; props->qkey_viol_cntr = 0;
eth_speed_to_ib_speed(cmd.speed, &props->active_speed, eth_speed_to_ib_speed(cmd.base.speed, &props->active_speed,
&props->active_width); &props->active_width);
props->max_mtu = IB_MTU_4096; props->max_mtu = IB_MTU_4096;
props->active_mtu = iboe_get_mtu(us_ibdev->ufdev->mtu); props->active_mtu = iboe_get_mtu(us_ibdev->ufdev->mtu);
/* Userspace will adjust for hdrs */ /* Userspace will adjust for hdrs */
......
...@@ -376,22 +376,20 @@ int bond_set_carrier(struct bonding *bond) ...@@ -376,22 +376,20 @@ int bond_set_carrier(struct bonding *bond)
static void bond_update_speed_duplex(struct slave *slave) static void bond_update_speed_duplex(struct slave *slave)
{ {
struct net_device *slave_dev = slave->dev; struct net_device *slave_dev = slave->dev;
struct ethtool_cmd ecmd; struct ethtool_link_ksettings ecmd;
u32 slave_speed;
int res; int res;
slave->speed = SPEED_UNKNOWN; slave->speed = SPEED_UNKNOWN;
slave->duplex = DUPLEX_UNKNOWN; slave->duplex = DUPLEX_UNKNOWN;
res = __ethtool_get_settings(slave_dev, &ecmd); res = __ethtool_get_link_ksettings(slave_dev, &ecmd);
if (res < 0) if (res < 0)
return; return;
slave_speed = ethtool_cmd_speed(&ecmd); if (ecmd.base.speed == 0 || ecmd.base.speed == ((__u32)-1))
if (slave_speed == 0 || slave_speed == ((__u32) -1))
return; return;
switch (ecmd.duplex) { switch (ecmd.base.duplex) {
case DUPLEX_FULL: case DUPLEX_FULL:
case DUPLEX_HALF: case DUPLEX_HALF:
break; break;
...@@ -399,8 +397,8 @@ static void bond_update_speed_duplex(struct slave *slave) ...@@ -399,8 +397,8 @@ static void bond_update_speed_duplex(struct slave *slave)
return; return;
} }
slave->speed = slave_speed; slave->speed = ecmd.base.speed;
slave->duplex = ecmd.duplex; slave->duplex = ecmd.base.duplex;
return; return;
} }
......
...@@ -382,6 +382,7 @@ static void mlx4_en_verify_params(void) ...@@ -382,6 +382,7 @@ static void mlx4_en_verify_params(void)
static int __init mlx4_en_init(void) static int __init mlx4_en_init(void)
{ {
mlx4_en_verify_params(); mlx4_en_verify_params();
mlx4_en_init_ptys2ethtool_map();
return mlx4_register_interface(&mlx4_en_interface); return mlx4_register_interface(&mlx4_en_interface);
} }
......
...@@ -607,6 +607,7 @@ static inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz) ...@@ -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) #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, void mlx4_en_update_loopback_state(struct net_device *dev,
netdev_features_t features); netdev_features_t features);
......
...@@ -346,12 +346,12 @@ static const struct header_ops ipvlan_header_ops = { ...@@ -346,12 +346,12 @@ static const struct header_ops ipvlan_header_ops = {
.cache_update = eth_header_cache_update, .cache_update = eth_header_cache_update,
}; };
static int ipvlan_ethtool_get_settings(struct net_device *dev, static int ipvlan_ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_cmd *cmd) struct ethtool_link_ksettings *cmd)
{ {
const struct ipvl_dev *ipvlan = netdev_priv(dev); const struct ipvl_dev *ipvlan = netdev_priv(dev);
return __ethtool_get_settings(ipvlan->phy_dev, cmd); return __ethtool_get_link_ksettings(ipvlan->phy_dev, cmd);
} }
static void ipvlan_ethtool_get_drvinfo(struct net_device *dev, 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) ...@@ -377,7 +377,7 @@ static void ipvlan_ethtool_set_msglevel(struct net_device *dev, u32 value)
static const struct ethtool_ops ipvlan_ethtool_ops = { static const struct ethtool_ops ipvlan_ethtool_ops = {
.get_link = ethtool_op_get_link, .get_link = ethtool_op_get_link,
.get_settings = ipvlan_ethtool_get_settings, .get_link_ksettings = ipvlan_ethtool_get_link_ksettings,
.get_drvinfo = ipvlan_ethtool_get_drvinfo, .get_drvinfo = ipvlan_ethtool_get_drvinfo,
.get_msglevel = ipvlan_ethtool_get_msglevel, .get_msglevel = ipvlan_ethtool_get_msglevel,
.set_msglevel = ipvlan_ethtool_set_msglevel, .set_msglevel = ipvlan_ethtool_set_msglevel,
......
...@@ -940,12 +940,12 @@ static void macvlan_ethtool_get_drvinfo(struct net_device *dev, ...@@ -940,12 +940,12 @@ static void macvlan_ethtool_get_drvinfo(struct net_device *dev,
strlcpy(drvinfo->version, "0.1", sizeof(drvinfo->version)); strlcpy(drvinfo->version, "0.1", sizeof(drvinfo->version));
} }
static int macvlan_ethtool_get_settings(struct net_device *dev, static int macvlan_ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_cmd *cmd) struct ethtool_link_ksettings *cmd)
{ {
const struct macvlan_dev *vlan = netdev_priv(dev); const struct macvlan_dev *vlan = netdev_priv(dev);
return __ethtool_get_settings(vlan->lowerdev, cmd); return __ethtool_get_link_ksettings(vlan->lowerdev, cmd);
} }
static netdev_features_t macvlan_fix_features(struct net_device *dev, 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) ...@@ -1020,7 +1020,7 @@ static int macvlan_dev_get_iflink(const struct net_device *dev)
static const struct ethtool_ops macvlan_ethtool_ops = { static const struct ethtool_ops macvlan_ethtool_ops = {
.get_link = ethtool_op_get_link, .get_link = ethtool_op_get_link,
.get_settings = macvlan_ethtool_get_settings, .get_link_ksettings = macvlan_ethtool_get_link_ksettings,
.get_drvinfo = macvlan_ethtool_get_drvinfo, .get_drvinfo = macvlan_ethtool_get_drvinfo,
}; };
......
...@@ -2813,12 +2813,12 @@ static void __team_port_change_send(struct team_port *port, bool linkup) ...@@ -2813,12 +2813,12 @@ static void __team_port_change_send(struct team_port *port, bool linkup)
port->state.linkup = linkup; port->state.linkup = linkup;
team_refresh_port_linkup(port); team_refresh_port_linkup(port);
if (linkup) { if (linkup) {
struct ethtool_cmd ecmd; struct ethtool_link_ksettings ecmd;
err = __ethtool_get_settings(port->dev, &ecmd); err = __ethtool_get_link_ksettings(port->dev, &ecmd);
if (!err) { if (!err) {
port->state.speed = ethtool_cmd_speed(&ecmd); port->state.speed = ecmd.base.speed;
port->state.duplex = ecmd.duplex; port->state.duplex = ecmd.base.duplex;
goto send_event; goto send_event;
} }
} }
......
...@@ -93,36 +93,40 @@ static struct notifier_block libfcoe_notifier = { ...@@ -93,36 +93,40 @@ static struct notifier_block libfcoe_notifier = {
int fcoe_link_speed_update(struct fc_lport *lport) int fcoe_link_speed_update(struct fc_lport *lport)
{ {
struct net_device *netdev = fcoe_get_netdev(lport); struct net_device *netdev = fcoe_get_netdev(lport);
struct ethtool_cmd ecmd; struct ethtool_link_ksettings ecmd;
if (!__ethtool_get_settings(netdev, &ecmd)) { if (!__ethtool_get_link_ksettings(netdev, &ecmd)) {
lport->link_supported_speeds &= ~(FC_PORTSPEED_1GBIT | lport->link_supported_speeds &= ~(FC_PORTSPEED_1GBIT |
FC_PORTSPEED_10GBIT | FC_PORTSPEED_10GBIT |
FC_PORTSPEED_20GBIT | FC_PORTSPEED_20GBIT |
FC_PORTSPEED_40GBIT); FC_PORTSPEED_40GBIT);
if (ecmd.supported & (SUPPORTED_1000baseT_Half | if (ecmd.link_modes.supported[0] & (
SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half |
SUPPORTED_1000baseKX_Full)) SUPPORTED_1000baseT_Full |
SUPPORTED_1000baseKX_Full))
lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
if (ecmd.supported & (SUPPORTED_10000baseT_Full | if (ecmd.link_modes.supported[0] & (
SUPPORTED_10000baseKX4_Full | SUPPORTED_10000baseT_Full |
SUPPORTED_10000baseKR_Full | SUPPORTED_10000baseKX4_Full |
SUPPORTED_10000baseR_FEC)) SUPPORTED_10000baseKR_Full |
SUPPORTED_10000baseR_FEC))
lport->link_supported_speeds |= FC_PORTSPEED_10GBIT; lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
if (ecmd.supported & (SUPPORTED_20000baseMLD2_Full | if (ecmd.link_modes.supported[0] & (
SUPPORTED_20000baseKR2_Full)) SUPPORTED_20000baseMLD2_Full |
SUPPORTED_20000baseKR2_Full))
lport->link_supported_speeds |= FC_PORTSPEED_20GBIT; lport->link_supported_speeds |= FC_PORTSPEED_20GBIT;
if (ecmd.supported & (SUPPORTED_40000baseKR4_Full | if (ecmd.link_modes.supported[0] & (
SUPPORTED_40000baseCR4_Full | SUPPORTED_40000baseKR4_Full |
SUPPORTED_40000baseSR4_Full | SUPPORTED_40000baseCR4_Full |
SUPPORTED_40000baseLR4_Full)) SUPPORTED_40000baseSR4_Full |
SUPPORTED_40000baseLR4_Full))
lport->link_supported_speeds |= FC_PORTSPEED_40GBIT; lport->link_supported_speeds |= FC_PORTSPEED_40GBIT;
switch (ethtool_cmd_speed(&ecmd)) { switch (ecmd.base.speed) {
case SPEED_1000: case SPEED_1000:
lport->link_speed = FC_PORTSPEED_1GBIT; lport->link_speed = FC_PORTSPEED_1GBIT;
break; break;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#ifndef _LINUX_ETHTOOL_H #ifndef _LINUX_ETHTOOL_H
#define _LINUX_ETHTOOL_H #define _LINUX_ETHTOOL_H
#include <linux/bitmap.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <uapi/linux/ethtool.h> #include <uapi/linux/ethtool.h>
...@@ -40,9 +41,6 @@ struct compat_ethtool_rxnfc { ...@@ -40,9 +41,6 @@ struct compat_ethtool_rxnfc {
#include <linux/rculist.h> #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 * enum ethtool_phys_id_state - indicator state for physical identification
* @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated
...@@ -97,13 +95,70 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) ...@@ -97,13 +95,70 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
return index % 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 base.cmd and base.link_mode_masks_nwords
* fields, but they are allowed to overwrite them (will be ignored).
*/
struct ethtool_link_ksettings {
struct ethtool_link_settings base;
struct {
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
} link_modes;
};
/**
* ethtool_link_ksettings_zero_link_mode - clear link_ksettings link mode mask
* @ptr : pointer to struct ethtool_link_ksettings
* @name : one of supported/advertising/lp_advertising
*/
#define ethtool_link_ksettings_zero_link_mode(ptr, name) \
bitmap_zero((ptr)->link_modes.name, __ETHTOOL_LINK_MODE_MASK_NBITS)
/**
* ethtool_link_ksettings_add_link_mode - set bit in link_ksettings
* link mode mask
* @ptr : pointer to struct ethtool_link_ksettings
* @name : one of supported/advertising/lp_advertising
* @mode : one of the ETHTOOL_LINK_MODE_*_BIT
* (not atomic, no bound checking)
*/
#define ethtool_link_ksettings_add_link_mode(ptr, name, mode) \
__set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
/**
* ethtool_link_ksettings_test_link_mode - test bit in ksettings link mode mask
* @ptr : pointer to struct ethtool_link_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_link_ksettings_test_link_mode(ptr, name, mode) \
test_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
extern int
__ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *link_ksettings);
/** /**
* struct ethtool_ops - optional netdev operations * struct ethtool_ops - optional netdev operations
* @get_settings: Get various device settings including Ethernet link * @get_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
* API. Get various device settings including Ethernet link
* settings. The @cmd parameter is expected to have been cleared * settings. The @cmd parameter is expected to have been cleared
* before get_settings is called. Returns a negative error code or * before get_settings is called. Returns a negative error code
* zero. * or zero.
* @set_settings: Set various device settings including Ethernet link * @set_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
* API. Set various device settings including Ethernet link
* settings. Returns a negative error code or zero. * settings. Returns a negative error code or zero.
* @get_drvinfo: Report driver/device information. Should only set the * @get_drvinfo: Report driver/device information. Should only set the
* @driver, @version, @fw_version and @bus_info fields. If not * @driver, @version, @fw_version and @bus_info fields. If not
...@@ -211,6 +266,19 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) ...@@ -211,6 +266,19 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
* a TX queue has this number, return -EINVAL. If only a RX queue or a TX * a TX queue has this number, return -EINVAL. If only a RX queue or a TX
* queue has this number, ignore the inapplicable fields. * queue has this number, ignore the inapplicable fields.
* Returns a negative error code or zero. * Returns a negative error code or zero.
* @get_link_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_link_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 * All operations are optional (i.e. the function pointer may be set
* to %NULL) and callers must take this into account. Callers must * to %NULL) and callers must take this into account. Callers must
...@@ -293,6 +361,9 @@ struct ethtool_ops { ...@@ -293,6 +361,9 @@ struct ethtool_ops {
struct ethtool_coalesce *); struct ethtool_coalesce *);
int (*set_per_queue_coalesce)(struct net_device *, u32, int (*set_per_queue_coalesce)(struct net_device *, u32,
struct ethtool_coalesce *); struct ethtool_coalesce *);
int (*get_link_ksettings)(struct net_device *,
struct ethtool_link_ksettings *);
int (*set_link_ksettings)(struct net_device *,
const struct ethtool_link_ksettings *);
}; };
#endif /* _LINUX_ETHTOOL_H */ #endif /* _LINUX_ETHTOOL_H */
...@@ -262,24 +262,22 @@ static inline enum ib_mtu iboe_get_mtu(int mtu) ...@@ -262,24 +262,22 @@ static inline enum ib_mtu iboe_get_mtu(int mtu)
static inline int iboe_get_rate(struct net_device *dev) static inline int iboe_get_rate(struct net_device *dev)
{ {
struct ethtool_cmd cmd; struct ethtool_link_ksettings cmd;
u32 speed;
int err; int err;
rtnl_lock(); rtnl_lock();
err = __ethtool_get_settings(dev, &cmd); err = __ethtool_get_link_ksettings(dev, &cmd);
rtnl_unlock(); rtnl_unlock();
if (err) if (err)
return IB_RATE_PORT_CURRENT; return IB_RATE_PORT_CURRENT;
speed = ethtool_cmd_speed(&cmd); if (cmd.base.speed >= 40000)
if (speed >= 40000)
return IB_RATE_40_GBPS; return IB_RATE_40_GBPS;
else if (speed >= 30000) else if (cmd.base.speed >= 30000)
return IB_RATE_30_GBPS; return IB_RATE_30_GBPS;
else if (speed >= 20000) else if (cmd.base.speed >= 20000)
return IB_RATE_20_GBPS; return IB_RATE_20_GBPS;
else if (speed >= 10000) else if (cmd.base.speed >= 10000)
return IB_RATE_10_GBPS; return IB_RATE_10_GBPS;
else else
return IB_RATE_PORT_CURRENT; return IB_RATE_PORT_CURRENT;
......
This diff is collapsed.
...@@ -621,12 +621,12 @@ static netdev_features_t vlan_dev_fix_features(struct net_device *dev, ...@@ -621,12 +621,12 @@ static netdev_features_t vlan_dev_fix_features(struct net_device *dev,
return features; return features;
} }
static int vlan_ethtool_get_settings(struct net_device *dev, static int vlan_ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_cmd *cmd) struct ethtool_link_ksettings *cmd)
{ {
const struct vlan_dev_priv *vlan = vlan_dev_priv(dev); const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
return __ethtool_get_settings(vlan->real_dev, cmd); return __ethtool_get_link_ksettings(vlan->real_dev, cmd);
} }
static void vlan_ethtool_get_drvinfo(struct net_device *dev, 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) ...@@ -741,7 +741,7 @@ static int vlan_dev_get_iflink(const struct net_device *dev)
} }
static const struct ethtool_ops vlan_ethtool_ops = { static const struct ethtool_ops vlan_ethtool_ops = {
.get_settings = vlan_ethtool_get_settings, .get_link_ksettings = vlan_ethtool_get_link_ksettings,
.get_drvinfo = vlan_ethtool_get_drvinfo, .get_drvinfo = vlan_ethtool_get_drvinfo,
.get_link = ethtool_op_get_link, .get_link = ethtool_op_get_link,
.get_ts_info = vlan_ethtool_get_ts_info, .get_ts_info = vlan_ethtool_get_ts_info,
......
...@@ -36,10 +36,10 @@ ...@@ -36,10 +36,10 @@
*/ */
static int port_cost(struct net_device *dev) static int port_cost(struct net_device *dev)
{ {
struct ethtool_cmd ecmd; struct ethtool_link_ksettings ecmd;
if (!__ethtool_get_settings(dev, &ecmd)) { if (!__ethtool_get_link_ksettings(dev, &ecmd)) {
switch (ethtool_cmd_speed(&ecmd)) { switch (ecmd.base.speed) {
case SPEED_10000: case SPEED_10000:
return 2; return 2;
case SPEED_1000: case SPEED_1000:
......
This diff is collapsed.
...@@ -198,9 +198,10 @@ static ssize_t speed_show(struct device *dev, ...@@ -198,9 +198,10 @@ static ssize_t speed_show(struct device *dev,
return restart_syscall(); return restart_syscall();
if (netif_running(netdev)) { if (netif_running(netdev)) {
struct ethtool_cmd cmd; struct ethtool_link_ksettings cmd;
if (!__ethtool_get_settings(netdev, &cmd))
ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd)); if (!__ethtool_get_link_ksettings(netdev, &cmd))
ret = sprintf(buf, fmt_dec, cmd.base.speed);
} }
rtnl_unlock(); rtnl_unlock();
return ret; return ret;
...@@ -217,10 +218,12 @@ static ssize_t duplex_show(struct device *dev, ...@@ -217,10 +218,12 @@ static ssize_t duplex_show(struct device *dev,
return restart_syscall(); return restart_syscall();
if (netif_running(netdev)) { if (netif_running(netdev)) {
struct ethtool_cmd cmd; struct ethtool_link_ksettings cmd;
if (!__ethtool_get_settings(netdev, &cmd)) {
if (!__ethtool_get_link_ksettings(netdev, &cmd)) {
const char *duplex; const char *duplex;
switch (cmd.duplex) {
switch (cmd.base.duplex) {
case DUPLEX_HALF: case DUPLEX_HALF:
duplex = "half"; duplex = "half";
break; break;
......
...@@ -557,9 +557,8 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, ...@@ -557,9 +557,8 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,
{ {
struct net_device *dev; struct net_device *dev;
unsigned int mbits = 0, msec = 0, div = 0, tmo = 0; unsigned int mbits = 0, msec = 0, div = 0, tmo = 0;
struct ethtool_cmd ecmd; struct ethtool_link_ksettings ecmd;
int err; int err;
u32 speed;
rtnl_lock(); rtnl_lock();
dev = __dev_get_by_index(sock_net(&po->sk), po->ifindex); 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, ...@@ -567,19 +566,19 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,
rtnl_unlock(); rtnl_unlock();
return DEFAULT_PRB_RETIRE_TOV; return DEFAULT_PRB_RETIRE_TOV;
} }
err = __ethtool_get_settings(dev, &ecmd); err = __ethtool_get_link_ksettings(dev, &ecmd);
speed = ethtool_cmd_speed(&ecmd);
rtnl_unlock(); rtnl_unlock();
if (!err) { if (!err) {
/* /*
* If the link speed is so slow you don't really * If the link speed is so slow you don't really
* need to worry about perf anyways * need to worry about perf anyways
*/ */
if (speed < SPEED_1000 || speed == SPEED_UNKNOWN) { if (ecmd.base.speed < SPEED_1000 ||
ecmd.base.speed == SPEED_UNKNOWN) {
return DEFAULT_PRB_RETIRE_TOV; return DEFAULT_PRB_RETIRE_TOV;
} else { } else {
msec = 1; msec = 1;
div = speed / 1000; div = ecmd.base.speed / 1000;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment