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,7 +353,7 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, ...@@ -355,7 +353,7 @@ 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);
......
...@@ -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;
} }
......
...@@ -501,34 +501,30 @@ static u32 mlx4_en_autoneg_get(struct net_device *dev) ...@@ -501,34 +501,30 @@ static u32 mlx4_en_autoneg_get(struct net_device *dev)
return autoneg; 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); u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap);
if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T) if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T)
| MLX4_PROT_MASK(MLX4_1000BASE_T) | MLX4_PROT_MASK(MLX4_1000BASE_T)
| MLX4_PROT_MASK(MLX4_100BASE_TX))) { | MLX4_PROT_MASK(MLX4_100BASE_TX))) {
return SUPPORTED_TP; __set_bit(ETHTOOL_LINK_MODE_TP_BIT, mask);
} } else if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
| MLX4_PROT_MASK(MLX4_10GBASE_SR) | MLX4_PROT_MASK(MLX4_10GBASE_SR)
| MLX4_PROT_MASK(MLX4_56GBASE_SR4) | MLX4_PROT_MASK(MLX4_56GBASE_SR4)
| MLX4_PROT_MASK(MLX4_40GBASE_CR4) | MLX4_PROT_MASK(MLX4_40GBASE_CR4)
| MLX4_PROT_MASK(MLX4_40GBASE_SR4) | MLX4_PROT_MASK(MLX4_40GBASE_SR4)
| MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) { | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) {
return SUPPORTED_FIBRE; __set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, mask);
} } else if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
| MLX4_PROT_MASK(MLX4_40GBASE_KR4) | MLX4_PROT_MASK(MLX4_40GBASE_KR4)
| MLX4_PROT_MASK(MLX4_20GBASE_KR2) | MLX4_PROT_MASK(MLX4_20GBASE_KR2)
| MLX4_PROT_MASK(MLX4_10GBASE_KR) | MLX4_PROT_MASK(MLX4_10GBASE_KR)
| MLX4_PROT_MASK(MLX4_10GBASE_KX4) | MLX4_PROT_MASK(MLX4_10GBASE_KX4)
| MLX4_PROT_MASK(MLX4_1000BASE_KX))) { | 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) 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) ...@@ -574,122 +570,111 @@ static u32 ptys_get_active_port(struct mlx4_ptys_reg *ptys_reg)
enum ethtool_report { enum ethtool_report {
SUPPORTED = 0, SUPPORTED = 0,
ADVERTISED = 1, 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 */ /* Translates mlx4 link mode to equivalent ethtool Link modes/speed */
static u32 ptys2ethtool_map[MLX4_LINK_MODES_SZ][3] = { static struct ptys2ethtool_config ptys2ethtool_map[MLX4_LINK_MODES_SZ];
[MLX4_100BASE_TX] = {
SUPPORTED_100baseT_Full, void __init mlx4_en_init_ptys2ethtool_map(void)
ADVERTISED_100baseT_Full, {
SPEED_100 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_100BASE_TX, SPEED_100,
}, ETHTOOL_LINK_MODE_100baseT_Full_BIT);
MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_T, SPEED_1000,
[MLX4_1000BASE_T] = { ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
SUPPORTED_1000baseT_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_CX_SGMII, SPEED_1000,
ADVERTISED_1000baseT_Full, ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
SPEED_1000 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_KX, SPEED_1000,
}, ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
[MLX4_1000BASE_CX_SGMII] = { MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_T, SPEED_10000,
SUPPORTED_1000baseKX_Full, ETHTOOL_LINK_MODE_10000baseT_Full_BIT);
ADVERTISED_1000baseKX_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CX4, SPEED_10000,
SPEED_1000 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
}, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KX4, SPEED_10000,
[MLX4_1000BASE_KX] = { ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
SUPPORTED_1000baseKX_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KR, SPEED_10000,
ADVERTISED_1000baseKX_Full, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
SPEED_1000 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CR, SPEED_10000,
}, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_SR, SPEED_10000,
[MLX4_10GBASE_T] = { ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
SUPPORTED_10000baseT_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_20GBASE_KR2, SPEED_20000,
ADVERTISED_10000baseT_Full, ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
SPEED_10000 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT);
}, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_CR4, SPEED_40000,
[MLX4_10GBASE_CX4] = { ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT);
SUPPORTED_10000baseKX4_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_KR4, SPEED_40000,
ADVERTISED_10000baseKX4_Full, ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT);
SPEED_10000 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_SR4, SPEED_40000,
}, ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT);
[MLX4_10GBASE_KX4] = { MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_KR4, SPEED_56000,
SUPPORTED_10000baseKX4_Full, ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT);
ADVERTISED_10000baseKX4_Full, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_CR4, SPEED_56000,
SPEED_10000 ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT);
}, MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_SR4, SPEED_56000,
[MLX4_10GBASE_KR] = { ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT);
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 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; int i;
u32 link_modes = 0;
for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
if (eth_proto & MLX4_PROT_MASK(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; int i;
u32 ptys_modes = 0; u32 ptys_modes = 0;
for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { 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; ptys_modes |= 1 << i;
} }
return ptys_modes; return ptys_modes;
...@@ -702,14 +687,15 @@ static u32 speed2ptys_link_modes(u32 speed) ...@@ -702,14 +687,15 @@ static u32 speed2ptys_link_modes(u32 speed)
u32 ptys_modes = 0; u32 ptys_modes = 0;
for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { 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; ptys_modes |= 1 << i;
} }
return ptys_modes; return ptys_modes;
} }
static int ethtool_get_ptys_settings(struct net_device *dev, static int
struct ethtool_cmd *cmd) ethtool_get_ptys_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *link_ksettings)
{ {
struct mlx4_en_priv *priv = netdev_priv(dev); struct mlx4_en_priv *priv = netdev_priv(dev);
struct mlx4_ptys_reg ptys_reg; struct mlx4_ptys_reg ptys_reg;
...@@ -737,79 +723,102 @@ static int ethtool_get_ptys_settings(struct net_device *dev, ...@@ -737,79 +723,102 @@ static int ethtool_get_ptys_settings(struct net_device *dev,
en_dbg(DRV, priv, "ptys_reg.eth_proto_lp_adv %x\n", en_dbg(DRV, priv, "ptys_reg.eth_proto_lp_adv %x\n",
be32_to_cpu(ptys_reg.eth_proto_lp_adv)); be32_to_cpu(ptys_reg.eth_proto_lp_adv));
cmd->supported = 0; /* reset supported/advertising masks */
cmd->advertising = 0; ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
cmd->supported |= ptys_get_supported_port(&ptys_reg); ptys2ethtool_update_supported_port(link_ksettings->link_modes.supported,
&ptys_reg);
eth_proto = be32_to_cpu(ptys_reg.eth_proto_cap); eth_proto = be32_to_cpu(ptys_reg.eth_proto_cap);
cmd->supported |= ptys2ethtool_link_modes(eth_proto, SUPPORTED); ptys2ethtool_update_link_modes(link_ksettings->link_modes.supported,
eth_proto, SUPPORTED);
eth_proto = be32_to_cpu(ptys_reg.eth_proto_admin); eth_proto = be32_to_cpu(ptys_reg.eth_proto_admin);
cmd->advertising |= ptys2ethtool_link_modes(eth_proto, ADVERTISED); ptys2ethtool_update_link_modes(link_ksettings->link_modes.advertising,
eth_proto, ADVERTISED);
cmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
cmd->advertising |= (priv->prof->tx_pause) ? ADVERTISED_Pause : 0; Pause);
ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
Asym_Pause);
cmd->advertising |= (priv->prof->tx_pause ^ priv->prof->rx_pause) ? if (priv->prof->tx_pause)
ADVERTISED_Asym_Pause : 0; ethtool_link_ksettings_add_link_mode(link_ksettings,
advertising, Pause);
if (priv->prof->tx_pause ^ priv->prof->rx_pause)
ethtool_link_ksettings_add_link_mode(link_ksettings,
advertising, Asym_Pause);
cmd->port = ptys_get_active_port(&ptys_reg); link_ksettings->base.port = ptys_get_active_port(&ptys_reg);
cmd->transceiver = (SUPPORTED_TP & cmd->supported) ?
XCVR_EXTERNAL : XCVR_INTERNAL;
if (mlx4_en_autoneg_get(dev)) { if (mlx4_en_autoneg_get(dev)) {
cmd->supported |= SUPPORTED_Autoneg; ethtool_link_ksettings_add_link_mode(link_ksettings,
cmd->advertising |= ADVERTISED_Autoneg; supported, Autoneg);
ethtool_link_ksettings_add_link_mode(link_ksettings,
advertising, Autoneg);
} }
cmd->autoneg = (priv->port_state.flags & MLX4_EN_PORT_ANC) ? link_ksettings->base.autoneg
= (priv->port_state.flags & MLX4_EN_PORT_ANC) ?
AUTONEG_ENABLE : AUTONEG_DISABLE; AUTONEG_ENABLE : AUTONEG_DISABLE;
eth_proto = be32_to_cpu(ptys_reg.eth_proto_lp_adv); 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) ? ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
ADVERTISED_Autoneg : 0; ptys2ethtool_update_link_modes(
link_ksettings->link_modes.lp_advertising,
eth_proto, ADVERTISED);
if (priv->port_state.flags & MLX4_EN_PORT_ANC)
ethtool_link_ksettings_add_link_mode(link_ksettings,
lp_advertising, Autoneg);
cmd->phy_address = 0; link_ksettings->base.phy_address = 0;
cmd->mdio_support = 0; link_ksettings->base.mdio_support = 0;
cmd->maxtxpkt = 0; link_ksettings->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
cmd->maxrxpkt = 0; link_ksettings->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
cmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
cmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
return ret; return ret;
} }
static void ethtool_get_default_settings(struct net_device *dev, static void
struct ethtool_cmd *cmd) ethtool_get_default_link_ksettings(
struct net_device *dev, struct ethtool_link_ksettings *link_ksettings)
{ {
struct mlx4_en_priv *priv = netdev_priv(dev); struct mlx4_en_priv *priv = netdev_priv(dev);
int trans_type; int trans_type;
cmd->autoneg = AUTONEG_DISABLE; link_ksettings->base.autoneg = AUTONEG_DISABLE;
cmd->supported = SUPPORTED_10000baseT_Full;
cmd->advertising = ADVERTISED_10000baseT_Full; ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
trans_type = priv->port_state.transceiver; ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
10000baseT_Full);
ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
ethtool_link_ksettings_add_link_mode(link_ksettings, advertising,
10000baseT_Full);
trans_type = priv->port_state.transceiver;
if (trans_type > 0 && trans_type <= 0xC) { if (trans_type > 0 && trans_type <= 0xC) {
cmd->port = PORT_FIBRE; link_ksettings->base.port = PORT_FIBRE;
cmd->transceiver = XCVR_EXTERNAL; ethtool_link_ksettings_add_link_mode(link_ksettings,
cmd->supported |= SUPPORTED_FIBRE; supported, FIBRE);
cmd->advertising |= ADVERTISED_FIBRE; ethtool_link_ksettings_add_link_mode(link_ksettings,
advertising, FIBRE);
} else if (trans_type == 0x80 || trans_type == 0) { } else if (trans_type == 0x80 || trans_type == 0) {
cmd->port = PORT_TP; link_ksettings->base.port = PORT_TP;
cmd->transceiver = XCVR_INTERNAL; ethtool_link_ksettings_add_link_mode(link_ksettings,
cmd->supported |= SUPPORTED_TP; supported, TP);
cmd->advertising |= ADVERTISED_TP; ethtool_link_ksettings_add_link_mode(link_ksettings,
advertising, TP);
} else { } else {
cmd->port = -1; link_ksettings->base.port = -1;
cmd->transceiver = -1;
} }
} }
static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) static int
mlx4_en_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *link_ksettings)
{ {
struct mlx4_en_priv *priv = netdev_priv(dev); struct mlx4_en_priv *priv = netdev_priv(dev);
int ret = -EINVAL; int ret = -EINVAL;
...@@ -822,16 +831,16 @@ static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) ...@@ -822,16 +831,16 @@ static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
priv->port_state.flags & MLX4_EN_PORT_ANE); priv->port_state.flags & MLX4_EN_PORT_ANE);
if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL)
ret = ethtool_get_ptys_settings(dev, cmd); ret = ethtool_get_ptys_link_ksettings(dev, link_ksettings);
if (ret) /* ETH PROT CRTL is not supported or PTYS CMD failed */ if (ret) /* ETH PROT CRTL is not supported or PTYS CMD failed */
ethtool_get_default_settings(dev, cmd); ethtool_get_default_link_ksettings(dev, link_ksettings);
if (netif_carrier_ok(dev)) { if (netif_carrier_ok(dev)) {
ethtool_cmd_speed_set(cmd, priv->port_state.link_speed); link_ksettings->base.speed = priv->port_state.link_speed;
cmd->duplex = DUPLEX_FULL; link_ksettings->base.duplex = DUPLEX_FULL;
} else { } else {
ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); link_ksettings->base.speed = SPEED_UNKNOWN;
cmd->duplex = DUPLEX_UNKNOWN; link_ksettings->base.duplex = DUPLEX_UNKNOWN;
} }
return 0; return 0;
} }
...@@ -855,21 +864,29 @@ static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed, ...@@ -855,21 +864,29 @@ static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed,
return proto_admin; return proto_admin;
} }
static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) static int
mlx4_en_set_link_ksettings(struct net_device *dev,
const struct ethtool_link_ksettings *link_ksettings)
{ {
struct mlx4_en_priv *priv = netdev_priv(dev); struct mlx4_en_priv *priv = netdev_priv(dev);
struct mlx4_ptys_reg ptys_reg; struct mlx4_ptys_reg ptys_reg;
__be32 proto_admin; __be32 proto_admin;
int ret; int ret;
u32 ptys_adv = ethtool2ptys_link_modes(cmd->advertising, ADVERTISED); u32 ptys_adv = ethtool2ptys_link_modes(
int speed = ethtool_cmd_speed(cmd); link_ksettings->link_modes.advertising, ADVERTISED);
const int speed = link_ksettings->base.speed;
en_dbg(DRV, priv, "Set Speed=%d adv=0x%x autoneg=%d duplex=%d\n",
speed, cmd->advertising, cmd->autoneg, cmd->duplex);
if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) || en_dbg(DRV, priv,
(cmd->duplex == DUPLEX_HALF)) "Set Speed=%d adv={%*pbl} autoneg=%d duplex=%d\n",
speed, __ETHTOOL_LINK_MODE_MASK_NBITS,
link_ksettings->link_modes.advertising,
link_ksettings->base.autoneg,
link_ksettings->base.duplex);
if (!(priv->mdev->dev->caps.flags2 &
MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) ||
(link_ksettings->base.duplex == DUPLEX_HALF))
return -EINVAL; return -EINVAL;
memset(&ptys_reg, 0, sizeof(ptys_reg)); memset(&ptys_reg, 0, sizeof(ptys_reg));
...@@ -883,7 +900,7 @@ static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) ...@@ -883,7 +900,7 @@ static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
return 0; return 0;
} }
proto_admin = cmd->autoneg == AUTONEG_ENABLE ? proto_admin = link_ksettings->base.autoneg == AUTONEG_ENABLE ?
cpu_to_be32(ptys_adv) : cpu_to_be32(ptys_adv) :
speed_set_ptys_admin(priv, speed, speed_set_ptys_admin(priv, speed,
ptys_reg.eth_proto_cap); ptys_reg.eth_proto_cap);
...@@ -1982,8 +1999,8 @@ static int mlx4_en_set_phys_id(struct net_device *dev, ...@@ -1982,8 +1999,8 @@ static int mlx4_en_set_phys_id(struct net_device *dev,
const struct ethtool_ops mlx4_en_ethtool_ops = { const struct ethtool_ops mlx4_en_ethtool_ops = {
.get_drvinfo = mlx4_en_get_drvinfo, .get_drvinfo = mlx4_en_get_drvinfo,
.get_settings = mlx4_en_get_settings, .get_link_ksettings = mlx4_en_get_link_ksettings,
.set_settings = mlx4_en_set_settings, .set_link_ksettings = mlx4_en_set_link_ksettings,
.get_link = ethtool_op_get_link, .get_link = ethtool_op_get_link,
.get_strings = mlx4_en_get_strings, .get_strings = mlx4_en_get_strings,
.get_sset_count = mlx4_en_get_sset_count, .get_sset_count = mlx4_en_get_sset_count,
......
...@@ -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_Half |
SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Full |
SUPPORTED_1000baseKX_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_10000baseT_Full |
SUPPORTED_10000baseKX4_Full | SUPPORTED_10000baseKX4_Full |
SUPPORTED_10000baseKR_Full | SUPPORTED_10000baseKR_Full |
SUPPORTED_10000baseR_FEC)) 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_20000baseMLD2_Full |
SUPPORTED_20000baseKR2_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_40000baseKR4_Full |
SUPPORTED_40000baseCR4_Full | SUPPORTED_40000baseCR4_Full |
SUPPORTED_40000baseSR4_Full | SUPPORTED_40000baseSR4_Full |
SUPPORTED_40000baseLR4_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;
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
*/ */
/** /**
* struct ethtool_cmd - link control and status * struct ethtool_cmd - DEPRECATED, link control and status
* This structure is DEPRECATED, please use struct ethtool_link_settings.
* @cmd: Command number = %ETHTOOL_GSET or %ETHTOOL_SSET * @cmd: Command number = %ETHTOOL_GSET or %ETHTOOL_SSET
* @supported: Bitmask of %SUPPORTED_* flags for the link modes, * @supported: Bitmask of %SUPPORTED_* flags for the link modes,
* physical connectors and other link features for which the * physical connectors and other link features for which the
...@@ -1219,8 +1220,12 @@ struct ethtool_per_queue_op { ...@@ -1219,8 +1220,12 @@ struct ethtool_per_queue_op {
}; };
/* CMDs currently supported */ /* CMDs currently supported */
#define ETHTOOL_GSET 0x00000001 /* Get settings. */ #define ETHTOOL_GSET 0x00000001 /* DEPRECATED, Get settings.
#define ETHTOOL_SSET 0x00000002 /* Set settings. */ * Please use ETHTOOL_GLINKSETTINGS
*/
#define ETHTOOL_SSET 0x00000002 /* DEPRECATED, Set settings.
* Please use ETHTOOL_SLINKSETTINGS
*/
#define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */ #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */
#define ETHTOOL_GREGS 0x00000004 /* Get NIC registers. */ #define ETHTOOL_GREGS 0x00000004 /* Get NIC registers. */
#define ETHTOOL_GWOL 0x00000005 /* Get wake-on-lan options. */ #define ETHTOOL_GWOL 0x00000005 /* Get wake-on-lan options. */
...@@ -1302,73 +1307,139 @@ struct ethtool_per_queue_op { ...@@ -1302,73 +1307,139 @@ struct ethtool_per_queue_op {
#define ETHTOOL_PERQUEUE 0x0000004b /* Set per queue options */ #define ETHTOOL_PERQUEUE 0x0000004b /* Set per queue options */
#define ETHTOOL_GLINKSETTINGS 0x0000004c /* Get ethtool_link_settings */
#define ETHTOOL_SLINKSETTINGS 0x0000004d /* Set ethtool_link_settings */
/* compatibility with older code */ /* compatibility with older code */
#define SPARC_ETH_GSET ETHTOOL_GSET #define SPARC_ETH_GSET ETHTOOL_GSET
#define SPARC_ETH_SSET ETHTOOL_SSET #define SPARC_ETH_SSET ETHTOOL_SSET
#define SUPPORTED_10baseT_Half (1 << 0) /* Link mode bit indices */
#define SUPPORTED_10baseT_Full (1 << 1) enum ethtool_link_mode_bit_indices {
#define SUPPORTED_100baseT_Half (1 << 2) ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0,
#define SUPPORTED_100baseT_Full (1 << 3) ETHTOOL_LINK_MODE_10baseT_Full_BIT = 1,
#define SUPPORTED_1000baseT_Half (1 << 4) ETHTOOL_LINK_MODE_100baseT_Half_BIT = 2,
#define SUPPORTED_1000baseT_Full (1 << 5) ETHTOOL_LINK_MODE_100baseT_Full_BIT = 3,
#define SUPPORTED_Autoneg (1 << 6) ETHTOOL_LINK_MODE_1000baseT_Half_BIT = 4,
#define SUPPORTED_TP (1 << 7) ETHTOOL_LINK_MODE_1000baseT_Full_BIT = 5,
#define SUPPORTED_AUI (1 << 8) ETHTOOL_LINK_MODE_Autoneg_BIT = 6,
#define SUPPORTED_MII (1 << 9) ETHTOOL_LINK_MODE_TP_BIT = 7,
#define SUPPORTED_FIBRE (1 << 10) ETHTOOL_LINK_MODE_AUI_BIT = 8,
#define SUPPORTED_BNC (1 << 11) ETHTOOL_LINK_MODE_MII_BIT = 9,
#define SUPPORTED_10000baseT_Full (1 << 12) ETHTOOL_LINK_MODE_FIBRE_BIT = 10,
#define SUPPORTED_Pause (1 << 13) ETHTOOL_LINK_MODE_BNC_BIT = 11,
#define SUPPORTED_Asym_Pause (1 << 14) ETHTOOL_LINK_MODE_10000baseT_Full_BIT = 12,
#define SUPPORTED_2500baseX_Full (1 << 15) ETHTOOL_LINK_MODE_Pause_BIT = 13,
#define SUPPORTED_Backplane (1 << 16) ETHTOOL_LINK_MODE_Asym_Pause_BIT = 14,
#define SUPPORTED_1000baseKX_Full (1 << 17) ETHTOOL_LINK_MODE_2500baseX_Full_BIT = 15,
#define SUPPORTED_10000baseKX4_Full (1 << 18) ETHTOOL_LINK_MODE_Backplane_BIT = 16,
#define SUPPORTED_10000baseKR_Full (1 << 19) ETHTOOL_LINK_MODE_1000baseKX_Full_BIT = 17,
#define SUPPORTED_10000baseR_FEC (1 << 20) ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT = 18,
#define SUPPORTED_20000baseMLD2_Full (1 << 21) ETHTOOL_LINK_MODE_10000baseKR_Full_BIT = 19,
#define SUPPORTED_20000baseKR2_Full (1 << 22) ETHTOOL_LINK_MODE_10000baseR_FEC_BIT = 20,
#define SUPPORTED_40000baseKR4_Full (1 << 23) ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT = 21,
#define SUPPORTED_40000baseCR4_Full (1 << 24) ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT = 22,
#define SUPPORTED_40000baseSR4_Full (1 << 25) ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT = 23,
#define SUPPORTED_40000baseLR4_Full (1 << 26) ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT = 24,
#define SUPPORTED_56000baseKR4_Full (1 << 27) ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT = 25,
#define SUPPORTED_56000baseCR4_Full (1 << 28) ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT = 26,
#define SUPPORTED_56000baseSR4_Full (1 << 29) ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT = 27,
#define SUPPORTED_56000baseLR4_Full (1 << 30) ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT = 28,
ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT = 29,
#define ADVERTISED_10baseT_Half (1 << 0) ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT = 30,
#define ADVERTISED_10baseT_Full (1 << 1)
#define ADVERTISED_100baseT_Half (1 << 2) /* Last allowed bit for __ETHTOOL_LINK_MODE_LEGACY_MASK is bit
#define ADVERTISED_100baseT_Full (1 << 3) * 31. Please do NOT define any SUPPORTED_* or ADVERTISED_*
#define ADVERTISED_1000baseT_Half (1 << 4) * macro for bits > 31. The only way to use indices > 31 is to
#define ADVERTISED_1000baseT_Full (1 << 5) * use the new ETHTOOL_GLINKSETTINGS/ETHTOOL_SLINKSETTINGS API.
#define ADVERTISED_Autoneg (1 << 6) */
#define ADVERTISED_TP (1 << 7)
#define ADVERTISED_AUI (1 << 8) __ETHTOOL_LINK_MODE_LAST
#define ADVERTISED_MII (1 << 9) = ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT,
#define ADVERTISED_FIBRE (1 << 10) };
#define ADVERTISED_BNC (1 << 11)
#define ADVERTISED_10000baseT_Full (1 << 12) #define __ETHTOOL_LINK_MODE_LEGACY_MASK(base_name) \
#define ADVERTISED_Pause (1 << 13) (1UL << (ETHTOOL_LINK_MODE_ ## base_name ## _BIT))
#define ADVERTISED_Asym_Pause (1 << 14)
#define ADVERTISED_2500baseX_Full (1 << 15) /* DEPRECATED macros. Please migrate to
#define ADVERTISED_Backplane (1 << 16) * ETHTOOL_GLINKSETTINGS/ETHTOOL_SLINKSETTINGS API. Please do NOT
#define ADVERTISED_1000baseKX_Full (1 << 17) * define any new SUPPORTED_* macro for bits > 31.
#define ADVERTISED_10000baseKX4_Full (1 << 18) */
#define ADVERTISED_10000baseKR_Full (1 << 19) #define SUPPORTED_10baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(10baseT_Half)
#define ADVERTISED_10000baseR_FEC (1 << 20) #define SUPPORTED_10baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10baseT_Full)
#define ADVERTISED_20000baseMLD2_Full (1 << 21) #define SUPPORTED_100baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(100baseT_Half)
#define ADVERTISED_20000baseKR2_Full (1 << 22) #define SUPPORTED_100baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(100baseT_Full)
#define ADVERTISED_40000baseKR4_Full (1 << 23) #define SUPPORTED_1000baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseT_Half)
#define ADVERTISED_40000baseCR4_Full (1 << 24) #define SUPPORTED_1000baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseT_Full)
#define ADVERTISED_40000baseSR4_Full (1 << 25) #define SUPPORTED_Autoneg __ETHTOOL_LINK_MODE_LEGACY_MASK(Autoneg)
#define ADVERTISED_40000baseLR4_Full (1 << 26) #define SUPPORTED_TP __ETHTOOL_LINK_MODE_LEGACY_MASK(TP)
#define ADVERTISED_56000baseKR4_Full (1 << 27) #define SUPPORTED_AUI __ETHTOOL_LINK_MODE_LEGACY_MASK(AUI)
#define ADVERTISED_56000baseCR4_Full (1 << 28) #define SUPPORTED_MII __ETHTOOL_LINK_MODE_LEGACY_MASK(MII)
#define ADVERTISED_56000baseSR4_Full (1 << 29) #define SUPPORTED_FIBRE __ETHTOOL_LINK_MODE_LEGACY_MASK(FIBRE)
#define ADVERTISED_56000baseLR4_Full (1 << 30) #define SUPPORTED_BNC __ETHTOOL_LINK_MODE_LEGACY_MASK(BNC)
#define SUPPORTED_10000baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseT_Full)
#define SUPPORTED_Pause __ETHTOOL_LINK_MODE_LEGACY_MASK(Pause)
#define SUPPORTED_Asym_Pause __ETHTOOL_LINK_MODE_LEGACY_MASK(Asym_Pause)
#define SUPPORTED_2500baseX_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(2500baseX_Full)
#define SUPPORTED_Backplane __ETHTOOL_LINK_MODE_LEGACY_MASK(Backplane)
#define SUPPORTED_1000baseKX_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseKX_Full)
#define SUPPORTED_10000baseKX4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseKX4_Full)
#define SUPPORTED_10000baseKR_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseKR_Full)
#define SUPPORTED_10000baseR_FEC __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseR_FEC)
#define SUPPORTED_20000baseMLD2_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(20000baseMLD2_Full)
#define SUPPORTED_20000baseKR2_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(20000baseKR2_Full)
#define SUPPORTED_40000baseKR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseKR4_Full)
#define SUPPORTED_40000baseCR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseCR4_Full)
#define SUPPORTED_40000baseSR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseSR4_Full)
#define SUPPORTED_40000baseLR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseLR4_Full)
#define SUPPORTED_56000baseKR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseKR4_Full)
#define SUPPORTED_56000baseCR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseCR4_Full)
#define SUPPORTED_56000baseSR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseSR4_Full)
#define SUPPORTED_56000baseLR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseLR4_Full)
/* Please do not define any new SUPPORTED_* macro for bits > 31, see
* notice above.
*/
/*
* DEPRECATED macros. Please migrate to
* ETHTOOL_GLINKSETTINGS/ETHTOOL_SLINKSETTINGS API. Please do NOT
* define any new ADERTISE_* macro for bits > 31.
*/
#define ADVERTISED_10baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(10baseT_Half)
#define ADVERTISED_10baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10baseT_Full)
#define ADVERTISED_100baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(100baseT_Half)
#define ADVERTISED_100baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(100baseT_Full)
#define ADVERTISED_1000baseT_Half __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseT_Half)
#define ADVERTISED_1000baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseT_Full)
#define ADVERTISED_Autoneg __ETHTOOL_LINK_MODE_LEGACY_MASK(Autoneg)
#define ADVERTISED_TP __ETHTOOL_LINK_MODE_LEGACY_MASK(TP)
#define ADVERTISED_AUI __ETHTOOL_LINK_MODE_LEGACY_MASK(AUI)
#define ADVERTISED_MII __ETHTOOL_LINK_MODE_LEGACY_MASK(MII)
#define ADVERTISED_FIBRE __ETHTOOL_LINK_MODE_LEGACY_MASK(FIBRE)
#define ADVERTISED_BNC __ETHTOOL_LINK_MODE_LEGACY_MASK(BNC)
#define ADVERTISED_10000baseT_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseT_Full)
#define ADVERTISED_Pause __ETHTOOL_LINK_MODE_LEGACY_MASK(Pause)
#define ADVERTISED_Asym_Pause __ETHTOOL_LINK_MODE_LEGACY_MASK(Asym_Pause)
#define ADVERTISED_2500baseX_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(2500baseX_Full)
#define ADVERTISED_Backplane __ETHTOOL_LINK_MODE_LEGACY_MASK(Backplane)
#define ADVERTISED_1000baseKX_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(1000baseKX_Full)
#define ADVERTISED_10000baseKX4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseKX4_Full)
#define ADVERTISED_10000baseKR_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseKR_Full)
#define ADVERTISED_10000baseR_FEC __ETHTOOL_LINK_MODE_LEGACY_MASK(10000baseR_FEC)
#define ADVERTISED_20000baseMLD2_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(20000baseMLD2_Full)
#define ADVERTISED_20000baseKR2_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(20000baseKR2_Full)
#define ADVERTISED_40000baseKR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseKR4_Full)
#define ADVERTISED_40000baseCR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseCR4_Full)
#define ADVERTISED_40000baseSR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseSR4_Full)
#define ADVERTISED_40000baseLR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(40000baseLR4_Full)
#define ADVERTISED_56000baseKR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseKR4_Full)
#define ADVERTISED_56000baseCR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseCR4_Full)
#define ADVERTISED_56000baseSR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseSR4_Full)
#define ADVERTISED_56000baseLR4_Full __ETHTOOL_LINK_MODE_LEGACY_MASK(56000baseLR4_Full)
/* Please do not define any new ADVERTISED_* macro for bits > 31, see
* notice above.
*/
/* The following are all involved in forcing a particular link /* The following are all involved in forcing a particular link
* mode for the device for setting things. When getting the * mode for the device for setting things. When getting the
...@@ -1533,4 +1604,123 @@ enum ethtool_reset_flags { ...@@ -1533,4 +1604,123 @@ enum ethtool_reset_flags {
}; };
#define ETH_RESET_SHARED_SHIFT 16 #define ETH_RESET_SHARED_SHIFT 16
/**
* struct ethtool_link_settings - link control and status
*
* IMPORTANT, Backward compatibility notice: When implementing new
* user-space tools, please first try %ETHTOOL_GLINKSETTINGS, and
* if it succeeds use %ETHTOOL_SLINKSETTINGS to change link
* settings; do not use %ETHTOOL_SSET if %ETHTOOL_GLINKSETTINGS
* succeeded: stick to %ETHTOOL_GLINKSETTINGS/%SLINKSETTINGS in
* that case. Conversely, if %ETHTOOL_GLINKSETTINGS fails, use
* %ETHTOOL_GSET to query and %ETHTOOL_SSET to change link
* settings; do not use %ETHTOOL_SLINKSETTINGS if
* %ETHTOOL_GLINKSETTINGS failed: stick to
* %ETHTOOL_GSET/%ETHTOOL_SSET in that case.
*
* @cmd: Command number = %ETHTOOL_GLINKSETTINGS or %ETHTOOL_SLINKSETTINGS
* @speed: Link speed (Mbps)
* @duplex: Duplex mode; one of %DUPLEX_*
* @port: Physical connector type; one of %PORT_*
* @phy_address: MDIO address of PHY (transceiver); 0 or 255 if not
* applicable. For clause 45 PHYs this is the PRTAD.
* @autoneg: Enable/disable autonegotiation and auto-detection;
* either %AUTONEG_DISABLE or %AUTONEG_ENABLE
* @mdio_support: Bitmask of %ETH_MDIO_SUPPORTS_* flags for the MDIO
* protocols supported by the interface; 0 if unknown.
* Read-only.
* @eth_tp_mdix: Ethernet twisted-pair MDI(-X) status; one of
* %ETH_TP_MDI_*. If the status is unknown or not applicable, the
* value will be %ETH_TP_MDI_INVALID. Read-only.
* @eth_tp_mdix_ctrl: Ethernet twisted pair MDI(-X) control; one of
* %ETH_TP_MDI_*. If MDI(-X) control is not implemented, reads
* yield %ETH_TP_MDI_INVALID and writes may be ignored or rejected.
* When written successfully, the link should be renegotiated if
* necessary.
* @link_mode_masks_nwords: Number of 32-bit words for each of the
* supported, advertising, lp_advertising link mode bitmaps. For
* %ETHTOOL_GLINKSETTINGS: on entry, number of words passed by user
* (>= 0); on return, if handshake in progress, negative if
* request size unsupported by kernel: absolute value indicates
* kernel recommended size and cmd field is 0, as well as all the
* other fields; otherwise (handshake completed), strictly
* positive to indicate size used by kernel and cmd field is
* %ETHTOOL_GLINKSETTINGS, all other fields populated by driver. For
* %ETHTOOL_SLINKSETTINGS: must be valid on entry, ie. a positive
* value returned previously by %ETHTOOL_GLINKSETTINGS, otherwise
* refused. For drivers: ignore this field (use kernel's
* __ETHTOOL_LINK_MODE_MASK_NBITS instead), any change to it will
* be overwritten by kernel.
* @supported: Bitmap with each bit meaning given by
* %ethtool_link_mode_bit_indices for the link modes, physical
* connectors and other link features for which the interface
* supports autonegotiation or auto-detection. Read-only.
* @advertising: Bitmap with each bit meaning given by
* %ethtool_link_mode_bit_indices for the link modes, physical
* connectors and other link features that are advertised through
* autonegotiation or enabled for auto-detection.
* @lp_advertising: Bitmap with each bit meaning given by
* %ethtool_link_mode_bit_indices for the link modes, and other
* link features that the link partner advertised through
* autonegotiation; 0 if unknown or not applicable. Read-only.
*
* If autonegotiation is disabled, the speed and @duplex represent the
* fixed link mode and are writable if the driver supports multiple
* link modes. If it is enabled then they are read-only; if the link
* is up they represent the negotiated link mode; if the link is down,
* the speed is 0, %SPEED_UNKNOWN or the highest enabled speed and
* @duplex is %DUPLEX_UNKNOWN or the best enabled duplex mode.
*
* Some hardware interfaces may have multiple PHYs and/or physical
* connectors fitted or do not allow the driver to detect which are
* fitted. For these interfaces @port and/or @phy_address may be
* writable, possibly dependent on @autoneg being %AUTONEG_DISABLE.
* Otherwise, attempts to write different values may be ignored or
* rejected.
*
* Deprecated %ethtool_cmd fields transceiver, maxtxpkt and maxrxpkt
* are not available in %ethtool_link_settings. Until all drivers are
* converted to ignore them or to the new %ethtool_link_settings API,
* for both queries and changes, users should always try
* %ETHTOOL_GLINKSETTINGS first, and if it fails with -ENOTSUPP stick
* only to %ETHTOOL_GSET and %ETHTOOL_SSET consistently. If it
* succeeds, then users should stick to %ETHTOOL_GLINKSETTINGS and
* %ETHTOOL_SLINKSETTINGS (which would support drivers implementing
* either %ethtool_cmd or %ethtool_link_settings).
*
* Users should assume that all fields not marked read-only are
* writable and subject to validation by the driver. They should use
* %ETHTOOL_GLINKSETTINGS to get the current values before making specific
* changes and then applying them with %ETHTOOL_SLINKSETTINGS.
*
* Drivers that implement %get_link_ksettings and/or
* %set_link_ksettings should ignore the @cmd
* and @link_mode_masks_nwords fields (any change to them overwritten
* by kernel), and rely only on kernel's internal
* %__ETHTOOL_LINK_MODE_MASK_NBITS and
* %ethtool_link_mode_mask_t. Drivers that implement
* %set_link_ksettings() should validate all fields other than @cmd
* and @link_mode_masks_nwords that are not described as read-only or
* deprecated, and must ignore all fields described as read-only.
*/
struct ethtool_link_settings {
__u32 cmd;
__u32 speed;
__u8 duplex;
__u8 port;
__u8 phy_address;
__u8 autoneg;
__u8 mdio_support;
__u8 eth_tp_mdix;
__u8 eth_tp_mdix_ctrl;
__s8 link_mode_masks_nwords;
__u32 reserved[8];
__u32 link_mode_masks[0];
/* layout of link_mode_masks fields:
* __u32 map_supported[link_mode_masks_nwords];
* __u32 map_advertising[link_mode_masks_nwords];
* __u32 map_lp_advertising[link_mode_masks_nwords];
*/
};
#endif /* _UAPI_LINUX_ETHTOOL_H */ #endif /* _UAPI_LINUX_ETHTOOL_H */
...@@ -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:
......
...@@ -387,43 +387,461 @@ static int __ethtool_set_flags(struct net_device *dev, u32 data) ...@@ -387,43 +387,461 @@ static int __ethtool_set_flags(struct net_device *dev, u32 data)
return 0; return 0;
} }
int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) static void convert_legacy_u32_to_link_mode(unsigned long *dst, u32 legacy_u32)
{ {
bitmap_zero(dst, __ETHTOOL_LINK_MODE_MASK_NBITS);
dst[0] = legacy_u32;
}
/* return false if src had higher bits set. lower bits always updated. */
static bool convert_link_mode_to_legacy_u32(u32 *legacy_u32,
const unsigned long *src)
{
bool retval = true;
/* TODO: following test will soon always be true */
if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) {
__ETHTOOL_DECLARE_LINK_MODE_MASK(ext);
bitmap_zero(ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_fill(ext, 32);
bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
if (bitmap_intersects(ext, src,
__ETHTOOL_LINK_MODE_MASK_NBITS)) {
/* src mask goes beyond bit 31 */
retval = false;
}
}
*legacy_u32 = src[0];
return retval;
}
/* return false if legacy contained non-0 deprecated fields
* transceiver/maxtxpkt/maxrxpkt. rest of ksettings always updated
*/
static bool
convert_legacy_settings_to_link_ksettings(
struct ethtool_link_ksettings *link_ksettings,
const struct ethtool_cmd *legacy_settings)
{
bool retval = true;
memset(link_ksettings, 0, sizeof(*link_ksettings));
/* This is used to tell users that driver is still using these
* deprecated legacy fields, and they should not use
* %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS
*/
if (legacy_settings->transceiver ||
legacy_settings->maxtxpkt ||
legacy_settings->maxrxpkt)
retval = false;
convert_legacy_u32_to_link_mode(
link_ksettings->link_modes.supported,
legacy_settings->supported);
convert_legacy_u32_to_link_mode(
link_ksettings->link_modes.advertising,
legacy_settings->advertising);
convert_legacy_u32_to_link_mode(
link_ksettings->link_modes.lp_advertising,
legacy_settings->lp_advertising);
link_ksettings->base.speed
= ethtool_cmd_speed(legacy_settings);
link_ksettings->base.duplex
= legacy_settings->duplex;
link_ksettings->base.port
= legacy_settings->port;
link_ksettings->base.phy_address
= legacy_settings->phy_address;
link_ksettings->base.autoneg
= legacy_settings->autoneg;
link_ksettings->base.mdio_support
= legacy_settings->mdio_support;
link_ksettings->base.eth_tp_mdix
= legacy_settings->eth_tp_mdix;
link_ksettings->base.eth_tp_mdix_ctrl
= legacy_settings->eth_tp_mdix_ctrl;
return retval;
}
/* return false if ksettings link modes had higher bits
* set. legacy_settings always updated (best effort)
*/
static bool
convert_link_ksettings_to_legacy_settings(
struct ethtool_cmd *legacy_settings,
const struct ethtool_link_ksettings *link_ksettings)
{
bool retval = true;
memset(legacy_settings, 0, sizeof(*legacy_settings));
/* this also clears the deprecated fields in legacy structure:
* __u8 transceiver;
* __u32 maxtxpkt;
* __u32 maxrxpkt;
*/
retval &= convert_link_mode_to_legacy_u32(
&legacy_settings->supported,
link_ksettings->link_modes.supported);
retval &= convert_link_mode_to_legacy_u32(
&legacy_settings->advertising,
link_ksettings->link_modes.advertising);
retval &= convert_link_mode_to_legacy_u32(
&legacy_settings->lp_advertising,
link_ksettings->link_modes.lp_advertising);
ethtool_cmd_speed_set(legacy_settings, link_ksettings->base.speed);
legacy_settings->duplex
= link_ksettings->base.duplex;
legacy_settings->port
= link_ksettings->base.port;
legacy_settings->phy_address
= link_ksettings->base.phy_address;
legacy_settings->autoneg
= link_ksettings->base.autoneg;
legacy_settings->mdio_support
= link_ksettings->base.mdio_support;
legacy_settings->eth_tp_mdix
= link_ksettings->base.eth_tp_mdix;
legacy_settings->eth_tp_mdix_ctrl
= link_ksettings->base.eth_tp_mdix_ctrl;
return retval;
}
/* number of 32-bit words to store the user's link mode bitmaps */
#define __ETHTOOL_LINK_MODE_MASK_NU32 \
DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
/* layout of the struct passed from/to userland */
struct ethtool_link_usettings {
struct ethtool_link_settings base;
struct {
__u32 supported[__ETHTOOL_LINK_MODE_MASK_NU32];
__u32 advertising[__ETHTOOL_LINK_MODE_MASK_NU32];
__u32 lp_advertising[__ETHTOOL_LINK_MODE_MASK_NU32];
} link_modes;
};
/* Internal kernel helper to query a device ethtool_link_settings.
*
* Backward compatibility note: for compatibility with legacy drivers
* that implement only the ethtool_cmd API, this has to work with both
* drivers implementing get_link_ksettings API and drivers
* implementing get_settings API. When drivers implement get_settings
* and report ethtool_cmd deprecated fields
* (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored
* because the resulting struct ethtool_link_settings does not report them.
*/
int __ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *link_ksettings)
{
int err;
struct ethtool_cmd cmd;
ASSERT_RTNL(); ASSERT_RTNL();
if (dev->ethtool_ops->get_link_ksettings) {
memset(link_ksettings, 0, sizeof(*link_ksettings));
return dev->ethtool_ops->get_link_ksettings(dev,
link_ksettings);
}
/* driver doesn't support %ethtool_link_ksettings API. revert to
* legacy %ethtool_cmd API, unless it's not supported either.
* TODO: remove when ethtool_ops::get_settings disappears internally
*/
if (!dev->ethtool_ops->get_settings) if (!dev->ethtool_ops->get_settings)
return -EOPNOTSUPP; return -EOPNOTSUPP;
memset(cmd, 0, sizeof(struct ethtool_cmd)); memset(&cmd, 0, sizeof(cmd));
cmd->cmd = ETHTOOL_GSET; cmd.cmd = ETHTOOL_GSET;
return dev->ethtool_ops->get_settings(dev, cmd); err = dev->ethtool_ops->get_settings(dev, &cmd);
if (err < 0)
return err;
/* we ignore deprecated fields transceiver/maxrxpkt/maxtxpkt
*/
convert_legacy_settings_to_link_ksettings(link_ksettings, &cmd);
return err;
} }
EXPORT_SYMBOL(__ethtool_get_settings); EXPORT_SYMBOL(__ethtool_get_link_ksettings);
static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) /* convert ethtool_link_usettings in user space to a kernel internal
* ethtool_link_ksettings. return 0 on success, errno on error.
*/
static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to,
const void __user *from)
{
struct ethtool_link_usettings link_usettings;
if (copy_from_user(&link_usettings, from, sizeof(link_usettings)))
return -EFAULT;
memcpy(&to->base, &link_usettings.base, sizeof(to->base));
bitmap_from_u32array(to->link_modes.supported,
__ETHTOOL_LINK_MODE_MASK_NBITS,
link_usettings.link_modes.supported,
__ETHTOOL_LINK_MODE_MASK_NU32);
bitmap_from_u32array(to->link_modes.advertising,
__ETHTOOL_LINK_MODE_MASK_NBITS,
link_usettings.link_modes.advertising,
__ETHTOOL_LINK_MODE_MASK_NU32);
bitmap_from_u32array(to->link_modes.lp_advertising,
__ETHTOOL_LINK_MODE_MASK_NBITS,
link_usettings.link_modes.lp_advertising,
__ETHTOOL_LINK_MODE_MASK_NU32);
return 0;
}
/* convert a kernel internal ethtool_link_ksettings to
* ethtool_link_usettings in user space. return 0 on success, errno on
* error.
*/
static int
store_link_ksettings_for_user(void __user *to,
const struct ethtool_link_ksettings *from)
{
struct ethtool_link_usettings link_usettings;
memcpy(&link_usettings.base, &from->base, sizeof(link_usettings));
bitmap_to_u32array(link_usettings.link_modes.supported,
__ETHTOOL_LINK_MODE_MASK_NU32,
from->link_modes.supported,
__ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_to_u32array(link_usettings.link_modes.advertising,
__ETHTOOL_LINK_MODE_MASK_NU32,
from->link_modes.advertising,
__ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_to_u32array(link_usettings.link_modes.lp_advertising,
__ETHTOOL_LINK_MODE_MASK_NU32,
from->link_modes.lp_advertising,
__ETHTOOL_LINK_MODE_MASK_NBITS);
if (copy_to_user(to, &link_usettings, sizeof(link_usettings)))
return -EFAULT;
return 0;
}
/* Query device for its ethtool_link_settings.
*
* Backward compatibility note: this function must fail when driver
* does not implement ethtool::get_link_ksettings, even if legacy
* ethtool_ops::get_settings is implemented. This tells new versions
* of ethtool that they should use the legacy API %ETHTOOL_GSET for
* this driver, so that they can correctly access the ethtool_cmd
* deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver
* implements ethtool_ops::get_settings anymore.
*/
static int ethtool_get_link_ksettings(struct net_device *dev,
void __user *useraddr)
{
int err = 0;
struct ethtool_link_ksettings link_ksettings;
ASSERT_RTNL();
if (!dev->ethtool_ops->get_link_ksettings)
return -EOPNOTSUPP;
/* handle bitmap nbits handshake */
if (copy_from_user(&link_ksettings.base, useraddr,
sizeof(link_ksettings.base)))
return -EFAULT;
if (__ETHTOOL_LINK_MODE_MASK_NU32
!= link_ksettings.base.link_mode_masks_nwords) {
/* wrong link mode nbits requested */
memset(&link_ksettings, 0, sizeof(link_ksettings));
/* keep cmd field reset to 0 */
/* send back number of words required as negative val */
compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32 <= S8_MAX,
"need too many bits for link modes!");
link_ksettings.base.link_mode_masks_nwords
= -((s8)__ETHTOOL_LINK_MODE_MASK_NU32);
/* copy the base fields back to user, not the link
* mode bitmaps
*/
if (copy_to_user(useraddr, &link_ksettings.base,
sizeof(link_ksettings.base)))
return -EFAULT;
return 0;
}
/* handshake successful: user/kernel agree on
* link_mode_masks_nwords
*/
memset(&link_ksettings, 0, sizeof(link_ksettings));
err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings);
if (err < 0)
return err;
/* make sure we tell the right values to user */
link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS;
link_ksettings.base.link_mode_masks_nwords
= __ETHTOOL_LINK_MODE_MASK_NU32;
return store_link_ksettings_for_user(useraddr, &link_ksettings);
}
/* Update device ethtool_link_settings.
*
* Backward compatibility note: this function must fail when driver
* does not implement ethtool::set_link_ksettings, even if legacy
* ethtool_ops::set_settings is implemented. This tells new versions
* of ethtool that they should use the legacy API %ETHTOOL_SSET for
* this driver, so that they can correctly update the ethtool_cmd
* deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver
* implements ethtool_ops::get_settings anymore.
*/
static int ethtool_set_link_ksettings(struct net_device *dev,
void __user *useraddr)
{ {
int err; int err;
struct ethtool_link_ksettings link_ksettings;
ASSERT_RTNL();
if (!dev->ethtool_ops->set_link_ksettings)
return -EOPNOTSUPP;
/* make sure nbits field has expected value */
if (copy_from_user(&link_ksettings.base, useraddr,
sizeof(link_ksettings.base)))
return -EFAULT;
if (__ETHTOOL_LINK_MODE_MASK_NU32
!= link_ksettings.base.link_mode_masks_nwords)
return -EINVAL;
/* copy the whole structure, now that we know it has expected
* format
*/
err = load_link_ksettings_from_user(&link_ksettings, useraddr);
if (err)
return err;
/* re-check nwords field, just in case */
if (__ETHTOOL_LINK_MODE_MASK_NU32
!= link_ksettings.base.link_mode_masks_nwords)
return -EINVAL;
return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
}
static void
warn_incomplete_ethtool_legacy_settings_conversion(const char *details)
{
char name[sizeof(current->comm)];
pr_info_once("warning: `%s' uses legacy ethtool link settings API, %s\n",
get_task_comm(name, current), details);
}
/* Query device for its ethtool_cmd settings.
*
* Backward compatibility note: for compatibility with legacy ethtool,
* this has to work with both drivers implementing get_link_ksettings
* API and drivers implementing get_settings API. When drivers
* implement get_link_ksettings and report higher link mode bits, a
* kernel warning is logged once (with name of 1st driver/device) to
* recommend user to upgrade ethtool, but the command is successful
* (only the lower link mode bits reported back to user).
*/
static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
{
struct ethtool_cmd cmd; struct ethtool_cmd cmd;
err = __ethtool_get_settings(dev, &cmd); ASSERT_RTNL();
if (dev->ethtool_ops->get_link_ksettings) {
/* First, use link_ksettings API if it is supported */
int err;
struct ethtool_link_ksettings link_ksettings;
memset(&link_ksettings, 0, sizeof(link_ksettings));
err = dev->ethtool_ops->get_link_ksettings(dev,
&link_ksettings);
if (err < 0)
return err;
if (!convert_link_ksettings_to_legacy_settings(&cmd,
&link_ksettings))
warn_incomplete_ethtool_legacy_settings_conversion(
"link modes are only partially reported");
/* send a sensible cmd tag back to user */
cmd.cmd = ETHTOOL_GSET;
} else {
/* driver doesn't support %ethtool_link_ksettings
* API. revert to legacy %ethtool_cmd API, unless it's
* not supported either.
*/
int err;
if (!dev->ethtool_ops->get_settings)
return -EOPNOTSUPP;
memset(&cmd, 0, sizeof(cmd));
cmd.cmd = ETHTOOL_GSET;
err = dev->ethtool_ops->get_settings(dev, &cmd);
if (err < 0) if (err < 0)
return err; return err;
}
if (copy_to_user(useraddr, &cmd, sizeof(cmd))) if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
/* Update device link settings with given ethtool_cmd.
*
* Backward compatibility note: for compatibility with legacy ethtool,
* this has to work with both drivers implementing set_link_ksettings
* API and drivers implementing set_settings API. When drivers
* implement set_link_ksettings and user's request updates deprecated
* ethtool_cmd fields (transceiver/maxrxpkt/maxtxpkt), a kernel
* warning is logged once (with name of 1st driver/device) to
* recommend user to upgrade ethtool, and the request is rejected.
*/
static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
{ {
struct ethtool_cmd cmd; struct ethtool_cmd cmd;
if (!dev->ethtool_ops->set_settings) ASSERT_RTNL();
return -EOPNOTSUPP;
if (copy_from_user(&cmd, useraddr, sizeof(cmd))) if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
return -EFAULT; return -EFAULT;
/* first, try new %ethtool_link_ksettings API. */
if (dev->ethtool_ops->set_link_ksettings) {
struct ethtool_link_ksettings link_ksettings;
if (!convert_legacy_settings_to_link_ksettings(&link_ksettings,
&cmd))
return -EINVAL;
link_ksettings.base.cmd = ETHTOOL_SLINKSETTINGS;
link_ksettings.base.link_mode_masks_nwords
= __ETHTOOL_LINK_MODE_MASK_NU32;
return dev->ethtool_ops->set_link_ksettings(dev,
&link_ksettings);
}
/* legacy %ethtool_cmd API */
/* TODO: return -EOPNOTSUPP when ethtool_ops::get_settings
* disappears internally
*/
if (!dev->ethtool_ops->set_settings)
return -EOPNOTSUPP;
return dev->ethtool_ops->set_settings(dev, &cmd); return dev->ethtool_ops->set_settings(dev, &cmd);
} }
...@@ -2252,6 +2670,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) ...@@ -2252,6 +2670,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
case ETHTOOL_PERQUEUE: case ETHTOOL_PERQUEUE:
rc = ethtool_set_per_queue(dev, useraddr); rc = ethtool_set_per_queue(dev, useraddr);
break; break;
case ETHTOOL_GLINKSETTINGS:
rc = ethtool_get_link_ksettings(dev, useraddr);
break;
case ETHTOOL_SLINKSETTINGS:
rc = ethtool_set_link_ksettings(dev, useraddr);
break;
default: default:
rc = -EOPNOTSUPP; rc = -EOPNOTSUPP;
} }
......
...@@ -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