2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-11-29 23:15:25 +08:00
|
|
|
/****************************************************************************
|
2013-08-30 06:32:48 +08:00
|
|
|
* Driver for Solarflare network controllers and boards
|
|
|
|
* Copyright 2009-2013 Solarflare Communications Inc.
|
2009-11-29 23:15:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for PHY related operations via MCDI.
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-11-29 23:15:25 +08:00
|
|
|
#include "efx.h"
|
|
|
|
#include "mcdi.h"
|
|
|
|
#include "mcdi_pcol.h"
|
2010-04-28 17:30:22 +08:00
|
|
|
#include "nic.h"
|
|
|
|
#include "selftest.h"
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data {
|
2009-11-29 23:15:25 +08:00
|
|
|
u32 flags;
|
|
|
|
u32 type;
|
|
|
|
u32 supported_cap;
|
|
|
|
u32 channel;
|
|
|
|
u32 port;
|
|
|
|
u32 stats_mask;
|
|
|
|
u8 name[20];
|
|
|
|
u32 media;
|
|
|
|
u32 mmd_mask;
|
|
|
|
u8 revision[20];
|
|
|
|
u32 forced_cap;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2010-06-01 19:17:06 +08:00
|
|
|
efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_data *cfg)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_CFG_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0);
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name));
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) {
|
2010-04-28 17:27:14 +08:00
|
|
|
rc = -EIO;
|
2009-11-29 23:15:25 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS);
|
|
|
|
cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE);
|
|
|
|
cfg->supported_cap =
|
|
|
|
MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP);
|
|
|
|
cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL);
|
|
|
|
cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT);
|
|
|
|
cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK);
|
|
|
|
memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME),
|
|
|
|
sizeof(cfg->name));
|
|
|
|
cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE);
|
|
|
|
cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK);
|
|
|
|
memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION),
|
|
|
|
sizeof(cfg->revision));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 23:15:25 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities,
|
|
|
|
u32 flags, u32 loopback_mode,
|
|
|
|
u32 loopback_speed)
|
|
|
|
{
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_LINK_IN_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0);
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities);
|
|
|
|
MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags);
|
|
|
|
MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode);
|
|
|
|
MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes)
|
|
|
|
{
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LOOPBACK_MODES_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
2013-08-21 03:35:50 +08:00
|
|
|
if (outlen < (MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_OFST +
|
|
|
|
MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_LEN)) {
|
2010-04-28 17:27:14 +08:00
|
|
|
rc = -EIO;
|
2009-11-29 23:15:25 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-12-20 08:44:06 +08:00
|
|
|
*loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_OUT_SUGGESTED);
|
2009-11-29 23:15:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 23:15:25 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
static int efx_mcdi_mdio_read(struct net_device *net_dev,
|
|
|
|
int prtad, int devad, u16 addr)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2012-09-18 09:33:54 +08:00
|
|
|
struct efx_nic *efx = netdev_priv(net_dev);
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, efx->mdio_bus);
|
2009-11-29 23:15:25 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad);
|
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad);
|
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
2013-06-01 01:36:12 +08:00
|
|
|
return rc;
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
if (MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS) !=
|
|
|
|
MC_CMD_MDIO_STATUS_GOOD)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE);
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
static int efx_mcdi_mdio_write(struct net_device *net_dev,
|
|
|
|
int prtad, int devad, u16 addr, u16 value)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2012-09-18 09:33:54 +08:00
|
|
|
struct efx_nic *efx = netdev_priv(net_dev);
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, efx->mdio_bus);
|
2009-11-29 23:15:25 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad);
|
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad);
|
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr);
|
|
|
|
MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
2013-06-01 01:36:12 +08:00
|
|
|
return rc;
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
if (MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS) !=
|
|
|
|
MC_CMD_MDIO_STATUS_GOOD)
|
|
|
|
return -EIO;
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
static void mcdi_to_ethtool_linkset(u32 media, u32 cap, unsigned long *linkset)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2018-01-11 02:00:14 +08:00
|
|
|
#define SET_BIT(name) __set_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
|
|
|
|
linkset)
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
bitmap_zero(linkset, __ETHTOOL_LINK_MODE_MASK_NBITS);
|
2009-11-29 23:15:25 +08:00
|
|
|
switch (media) {
|
|
|
|
case MC_CMD_MEDIA_KX4:
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(Backplane);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(1000baseKX_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(10000baseKX4_Full);
|
2014-07-14 15:39:07 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(40000baseKR4_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_CMD_MEDIA_XFP:
|
|
|
|
case MC_CMD_MEDIA_SFP_PLUS:
|
2014-07-14 15:39:07 +08:00
|
|
|
case MC_CMD_MEDIA_QSFP_PLUS:
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(FIBRE);
|
2016-06-07 00:29:30 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(1000baseT_Full);
|
2016-06-07 00:29:30 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(10000baseT_Full);
|
2014-07-14 15:39:07 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(40000baseCR4_Full);
|
2018-01-11 02:00:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_100000FDX_LBN))
|
|
|
|
SET_BIT(100000baseCR4_Full);
|
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_25000FDX_LBN))
|
|
|
|
SET_BIT(25000baseCR_Full);
|
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_50000FDX_LBN))
|
|
|
|
SET_BIT(50000baseCR2_Full);
|
2014-07-14 15:39:07 +08:00
|
|
|
break;
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
case MC_CMD_MEDIA_BASE_T:
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(TP);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(10baseT_Half);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(10baseT_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(100baseT_Half);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(100baseT_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(1000baseT_Half);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(1000baseT_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(10000baseT_Full);
|
2009-11-29 23:15:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(Pause);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(Asym_Pause);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
SET_BIT(Autoneg);
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
#undef SET_BIT
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
static u32 ethtool_linkset_to_mcdi_cap(const unsigned long *linkset)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
|
|
|
u32 result = 0;
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
#define TEST_BIT(name) test_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
|
|
|
|
linkset)
|
|
|
|
|
|
|
|
if (TEST_BIT(10baseT_Half))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(10baseT_Full))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(100baseT_Half))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(100baseT_Full))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(1000baseT_Half))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(1000baseT_Full) || TEST_BIT(1000baseKX_Full))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(10000baseT_Full) || TEST_BIT(10000baseKX4_Full))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(40000baseCR4_Full) || TEST_BIT(40000baseKR4_Full))
|
2014-07-14 15:39:07 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_40000FDX_LBN);
|
2018-01-11 02:00:25 +08:00
|
|
|
if (TEST_BIT(100000baseCR4_Full))
|
|
|
|
result |= (1 << MC_CMD_PHY_CAP_100000FDX_LBN);
|
|
|
|
if (TEST_BIT(25000baseCR_Full))
|
|
|
|
result |= (1 << MC_CMD_PHY_CAP_25000FDX_LBN);
|
|
|
|
if (TEST_BIT(50000baseCR2_Full))
|
|
|
|
result |= (1 << MC_CMD_PHY_CAP_50000FDX_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(Pause))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(Asym_Pause))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN);
|
2018-01-11 02:00:14 +08:00
|
|
|
if (TEST_BIT(Autoneg))
|
2009-11-29 23:15:25 +08:00
|
|
|
result |= (1 << MC_CMD_PHY_CAP_AN_LBN);
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
#undef TEST_BIT
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx)
|
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2009-11-29 23:15:25 +08:00
|
|
|
enum efx_phy_mode mode, supported;
|
|
|
|
u32 flags;
|
|
|
|
|
|
|
|
/* TODO: Advertise the capabilities supported by this PHY */
|
|
|
|
supported = 0;
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_TXDIS_LBN))
|
2009-11-29 23:15:25 +08:00
|
|
|
supported |= PHY_MODE_TX_DISABLED;
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_LOWPOWER_LBN))
|
2009-11-29 23:15:25 +08:00
|
|
|
supported |= PHY_MODE_LOW_POWER;
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_POWEROFF_LBN))
|
2009-11-29 23:15:25 +08:00
|
|
|
supported |= PHY_MODE_OFF;
|
|
|
|
|
|
|
|
mode = efx->phy_mode & supported;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if (mode & PHY_MODE_TX_DISABLED)
|
2011-12-20 08:44:06 +08:00
|
|
|
flags |= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (mode & PHY_MODE_LOW_POWER)
|
2011-12-20 08:44:06 +08:00
|
|
|
flags |= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (mode & PHY_MODE_OFF)
|
2011-12-20 08:44:06 +08:00
|
|
|
flags |= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN);
|
2009-11-29 23:15:25 +08:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
static u8 mcdi_to_ethtool_media(u32 media)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
|
|
|
switch (media) {
|
|
|
|
case MC_CMD_MEDIA_XAUI:
|
|
|
|
case MC_CMD_MEDIA_CX4:
|
|
|
|
case MC_CMD_MEDIA_KX4:
|
|
|
|
return PORT_OTHER;
|
|
|
|
|
|
|
|
case MC_CMD_MEDIA_XFP:
|
|
|
|
case MC_CMD_MEDIA_SFP_PLUS:
|
2014-07-14 15:39:07 +08:00
|
|
|
case MC_CMD_MEDIA_QSFP_PLUS:
|
2009-11-29 23:15:25 +08:00
|
|
|
return PORT_FIBRE;
|
|
|
|
|
|
|
|
case MC_CMD_MEDIA_BASE_T:
|
|
|
|
return PORT_TP;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return PORT_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
static void efx_mcdi_phy_decode_link(struct efx_nic *efx,
|
|
|
|
struct efx_link_state *link_state,
|
|
|
|
u32 speed, u32 flags, u32 fcntl)
|
|
|
|
{
|
|
|
|
switch (fcntl) {
|
|
|
|
case MC_CMD_FCNTL_AUTO:
|
|
|
|
WARN_ON(1); /* This is not a link mode */
|
|
|
|
link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX;
|
|
|
|
break;
|
|
|
|
case MC_CMD_FCNTL_BIDIR:
|
|
|
|
link_state->fc = EFX_FC_TX | EFX_FC_RX;
|
|
|
|
break;
|
|
|
|
case MC_CMD_FCNTL_RESPOND:
|
|
|
|
link_state->fc = EFX_FC_RX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
2019-04-29 23:37:55 +08:00
|
|
|
/* Fall through */
|
2012-09-18 09:33:54 +08:00
|
|
|
case MC_CMD_FCNTL_OFF:
|
|
|
|
link_state->fc = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
|
|
|
|
link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
|
|
|
|
link_state->speed = speed;
|
|
|
|
}
|
|
|
|
|
2018-03-14 22:21:26 +08:00
|
|
|
/* The semantics of the ethtool FEC mode bitmask are not well defined,
|
|
|
|
* particularly the meaning of combinations of bits. Which means we get to
|
|
|
|
* define our own semantics, as follows:
|
|
|
|
* OFF overrides any other bits, and means "disable all FEC" (with the
|
|
|
|
* exception of 25G KR4/CR4, where it is not possible to reject it if AN
|
|
|
|
* partner requests it).
|
|
|
|
* AUTO on its own means use cable requirements and link partner autoneg with
|
|
|
|
* fw-default preferences for the cable type.
|
|
|
|
* AUTO and either RS or BASER means use the specified FEC type if cable and
|
|
|
|
* link partner support it, otherwise autoneg/fw-default.
|
|
|
|
* RS or BASER alone means use the specified FEC type if cable and link partner
|
|
|
|
* support it and either requests it, otherwise no FEC.
|
|
|
|
* Both RS and BASER (whether AUTO or not) means use FEC if cable and link
|
|
|
|
* partner support it, preferring RS to BASER.
|
|
|
|
*/
|
|
|
|
static u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap)
|
|
|
|
{
|
|
|
|
u32 ret = 0;
|
|
|
|
|
|
|
|
if (ethtool_cap & ETHTOOL_FEC_OFF)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ethtool_cap & ETHTOOL_FEC_AUTO)
|
|
|
|
ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_RS_FEC_LBN);
|
|
|
|
if (ethtool_cap & ETHTOOL_FEC_RS)
|
|
|
|
ret |= (1 << MC_CMD_PHY_CAP_RS_FEC_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN);
|
|
|
|
if (ethtool_cap & ETHTOOL_FEC_BASER)
|
|
|
|
ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN) |
|
|
|
|
(1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invert ethtool_fec_caps_to_mcdi. There are two combinations that function
|
|
|
|
* can never produce, (baser xor rs) and neither req; the implementation below
|
|
|
|
* maps both of those to AUTO. This should never matter, and it's not clear
|
|
|
|
* what a better mapping would be anyway.
|
|
|
|
*/
|
|
|
|
static u32 mcdi_fec_caps_to_ethtool(u32 caps, bool is_25g)
|
|
|
|
{
|
|
|
|
bool rs = caps & (1 << MC_CMD_PHY_CAP_RS_FEC_LBN),
|
|
|
|
rs_req = caps & (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN),
|
|
|
|
baser = is_25g ? caps & (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN)
|
|
|
|
: caps & (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN),
|
|
|
|
baser_req = is_25g ? caps & (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN)
|
|
|
|
: caps & (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN);
|
|
|
|
|
|
|
|
if (!baser && !rs)
|
|
|
|
return ETHTOOL_FEC_OFF;
|
|
|
|
return (rs_req ? ETHTOOL_FEC_RS : 0) |
|
|
|
|
(baser_req ? ETHTOOL_FEC_BASER : 0) |
|
|
|
|
(baser == baser_req && rs == rs_req ? 0 : ETHTOOL_FEC_AUTO);
|
|
|
|
}
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
static int efx_mcdi_phy_probe(struct efx_nic *efx)
|
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_data;
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
|
2009-12-23 21:46:36 +08:00
|
|
|
u32 caps;
|
2009-11-29 23:15:25 +08:00
|
|
|
int rc;
|
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
/* Initialise and populate phy_data */
|
|
|
|
phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
|
|
|
|
if (phy_data == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = efx_mcdi_get_phy_cfg(efx, phy_data);
|
2009-11-29 23:15:25 +08:00
|
|
|
if (rc != 0)
|
|
|
|
goto fail;
|
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
/* Read initial link advertisement */
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Fill out nic state */
|
|
|
|
efx->phy_data = phy_data;
|
|
|
|
efx->phy_type = phy_data->type;
|
2009-11-29 23:15:25 +08:00
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
efx->mdio_bus = phy_data->channel;
|
|
|
|
efx->mdio.prtad = phy_data->port;
|
|
|
|
efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22);
|
2009-11-29 23:15:25 +08:00
|
|
|
efx->mdio.mode_support = 0;
|
2009-12-23 21:46:36 +08:00
|
|
|
if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22))
|
2009-11-29 23:15:25 +08:00
|
|
|
efx->mdio.mode_support |= MDIO_SUPPORTS_C22;
|
2009-12-23 21:46:36 +08:00
|
|
|
if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22))
|
2009-11-29 23:15:25 +08:00
|
|
|
efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
|
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP);
|
|
|
|
if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN))
|
2018-01-11 02:00:14 +08:00
|
|
|
mcdi_to_ethtool_linkset(phy_data->media, caps,
|
|
|
|
efx->link_advertising);
|
2009-12-23 21:46:36 +08:00
|
|
|
else
|
|
|
|
phy_data->forced_cap = caps;
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
/* Assert that we can map efx -> mcdi loopback modes */
|
|
|
|
BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR);
|
|
|
|
BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS);
|
|
|
|
|
|
|
|
rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail;
|
|
|
|
/* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
|
|
|
|
* but by convention we don't */
|
|
|
|
efx->loopback_modes &= ~(1 << LOOPBACK_NONE);
|
|
|
|
|
2010-02-03 17:30:38 +08:00
|
|
|
/* Set the initial link mode */
|
|
|
|
efx_mcdi_phy_decode_link(
|
|
|
|
efx, &efx->link_state,
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
|
|
|
|
|
2018-03-14 22:21:26 +08:00
|
|
|
/* Record the initial FEC configuration (or nearest approximation
|
|
|
|
* representable in the ethtool configuration space)
|
|
|
|
*/
|
|
|
|
efx->fec_config = mcdi_fec_caps_to_ethtool(caps,
|
|
|
|
efx->link_state.speed == 25000 ||
|
|
|
|
efx->link_state.speed == 50000);
|
|
|
|
|
2010-02-03 17:30:38 +08:00
|
|
|
/* Default to Autonegotiated flow control if the PHY supports it */
|
|
|
|
efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
|
|
|
|
if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
|
|
|
|
efx->wanted_fc |= EFX_FC_AUTO;
|
2010-06-01 19:18:08 +08:00
|
|
|
efx_link_set_wanted_fc(efx, efx->wanted_fc);
|
2010-02-03 17:30:38 +08:00
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
kfree(phy_data);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
int efx_mcdi_port_reconfigure(struct efx_nic *efx)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2018-01-11 02:00:14 +08:00
|
|
|
u32 caps = (efx->link_advertising[0] ?
|
|
|
|
ethtool_linkset_to_mcdi_cap(efx->link_advertising) :
|
2009-11-29 23:15:25 +08:00
|
|
|
phy_cfg->forced_cap);
|
|
|
|
|
2018-03-14 22:21:26 +08:00
|
|
|
caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
|
|
|
|
efx->loopback_mode, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify that the forced flow control settings (!EFX_FC_AUTO) are
|
|
|
|
* supported by the link partner. Warn the user if this isn't the case
|
|
|
|
*/
|
2012-09-18 09:33:54 +08:00
|
|
|
static void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2009-11-29 23:15:25 +08:00
|
|
|
u32 rmtadv;
|
|
|
|
|
2011-03-31 09:57:33 +08:00
|
|
|
/* The link partner capabilities are only relevant if the
|
2009-11-29 23:15:25 +08:00
|
|
|
* link supports flow control autonegotiation */
|
2010-02-03 17:30:38 +08:00
|
|
|
if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
|
2009-11-29 23:15:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If flow control autoneg is supported and enabled, then fine */
|
|
|
|
if (efx->wanted_fc & EFX_FC_AUTO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rmtadv = 0;
|
|
|
|
if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
|
|
|
|
rmtadv |= ADVERTISED_Pause;
|
|
|
|
if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
|
|
|
|
rmtadv |= ADVERTISED_Asym_Pause;
|
|
|
|
|
|
|
|
if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause)
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, link, efx->net_dev,
|
|
|
|
"warning: link partner doesn't support pause frames");
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool efx_mcdi_phy_poll(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_link_state old_state = efx->link_state;
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
WARN_ON(!mutex_is_locked(&efx->mac_lock));
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), NULL);
|
2013-06-01 01:36:12 +08:00
|
|
|
if (rc)
|
2009-11-29 23:15:25 +08:00
|
|
|
efx->link_state.up = false;
|
2013-06-01 01:36:12 +08:00
|
|
|
else
|
2009-11-29 23:15:25 +08:00
|
|
|
efx_mcdi_phy_decode_link(
|
|
|
|
efx, &efx->link_state,
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
|
|
|
|
|
|
|
|
return !efx_link_state_equal(&efx->link_state, &old_state);
|
|
|
|
}
|
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
static void efx_mcdi_phy_remove(struct efx_nic *efx)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
|
|
|
struct efx_mcdi_phy_data *phy_data = efx->phy_data;
|
|
|
|
|
|
|
|
efx->phy_data = NULL;
|
|
|
|
kfree(phy_data);
|
|
|
|
}
|
|
|
|
|
2016-12-15 07:12:53 +08:00
|
|
|
static void efx_mcdi_phy_get_link_ksettings(struct efx_nic *efx,
|
|
|
|
struct ethtool_link_ksettings *cmd)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
|
2009-11-29 23:15:25 +08:00
|
|
|
int rc;
|
2016-12-15 07:12:53 +08:00
|
|
|
|
|
|
|
cmd->base.speed = efx->link_state.speed;
|
|
|
|
cmd->base.duplex = efx->link_state.fd;
|
|
|
|
cmd->base.port = mcdi_to_ethtool_media(phy_cfg->media);
|
|
|
|
cmd->base.phy_address = phy_cfg->port;
|
2018-01-11 02:00:14 +08:00
|
|
|
cmd->base.autoneg = !!(efx->link_advertising[0] & ADVERTISED_Autoneg);
|
2016-12-15 07:12:53 +08:00
|
|
|
cmd->base.mdio_support = (efx->mdio.mode_support &
|
2009-11-29 23:15:25 +08:00
|
|
|
(MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22));
|
|
|
|
|
2018-01-11 02:00:14 +08:00
|
|
|
mcdi_to_ethtool_linkset(phy_cfg->media, phy_cfg->supported_cap,
|
|
|
|
cmd->link_modes.supported);
|
|
|
|
memcpy(cmd->link_modes.advertising, efx->link_advertising,
|
|
|
|
sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
|
2016-12-15 07:12:53 +08:00
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), NULL);
|
2013-06-01 01:36:12 +08:00
|
|
|
if (rc)
|
2009-11-29 23:15:25 +08:00
|
|
|
return;
|
2018-01-11 02:00:14 +08:00
|
|
|
mcdi_to_ethtool_linkset(phy_cfg->media,
|
|
|
|
MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP),
|
|
|
|
cmd->link_modes.lp_advertising);
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
|
2016-12-15 07:12:53 +08:00
|
|
|
static int
|
|
|
|
efx_mcdi_phy_set_link_ksettings(struct efx_nic *efx,
|
|
|
|
const struct ethtool_link_ksettings *cmd)
|
2009-11-29 23:15:25 +08:00
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2009-11-29 23:15:25 +08:00
|
|
|
u32 caps;
|
|
|
|
int rc;
|
|
|
|
|
2016-12-15 07:12:53 +08:00
|
|
|
if (cmd->base.autoneg) {
|
2018-01-11 02:00:14 +08:00
|
|
|
caps = (ethtool_linkset_to_mcdi_cap(cmd->link_modes.advertising) |
|
|
|
|
1 << MC_CMD_PHY_CAP_AN_LBN);
|
2016-12-15 07:12:53 +08:00
|
|
|
} else if (cmd->base.duplex) {
|
|
|
|
switch (cmd->base.speed) {
|
2018-01-11 01:59:59 +08:00
|
|
|
case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break;
|
|
|
|
case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break;
|
|
|
|
case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break;
|
|
|
|
case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break;
|
|
|
|
case 40000: caps = 1 << MC_CMD_PHY_CAP_40000FDX_LBN; break;
|
|
|
|
case 100000: caps = 1 << MC_CMD_PHY_CAP_100000FDX_LBN; break;
|
|
|
|
case 25000: caps = 1 << MC_CMD_PHY_CAP_25000FDX_LBN; break;
|
|
|
|
case 50000: caps = 1 << MC_CMD_PHY_CAP_50000FDX_LBN; break;
|
|
|
|
default: return -EINVAL;
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-15 07:12:53 +08:00
|
|
|
switch (cmd->base.speed) {
|
2018-01-11 01:59:59 +08:00
|
|
|
case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break;
|
|
|
|
case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break;
|
|
|
|
case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break;
|
|
|
|
default: return -EINVAL;
|
2009-11-29 23:15:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 22:21:26 +08:00
|
|
|
caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
|
|
|
|
|
2009-11-29 23:15:25 +08:00
|
|
|
rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
|
|
|
|
efx->loopback_mode, 0);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2016-12-15 07:12:53 +08:00
|
|
|
if (cmd->base.autoneg) {
|
2018-01-11 02:00:14 +08:00
|
|
|
efx_link_set_advertising(efx, cmd->link_modes.advertising);
|
2009-11-29 23:15:25 +08:00
|
|
|
phy_cfg->forced_cap = 0;
|
|
|
|
} else {
|
2018-01-11 02:00:14 +08:00
|
|
|
efx_link_clear_advertising(efx);
|
2009-11-29 23:15:25 +08:00
|
|
|
phy_cfg->forced_cap = caps;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-14 22:21:26 +08:00
|
|
|
static int efx_mcdi_phy_get_fecparam(struct efx_nic *efx,
|
|
|
|
struct ethtool_fecparam *fec)
|
|
|
|
{
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_V2_LEN);
|
|
|
|
u32 caps, active, speed; /* MCDI format */
|
|
|
|
bool is_25g = false;
|
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (outlen < MC_CMD_GET_LINK_OUT_V2_LEN)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
/* behaviour for 25G/50G links depends on 25G BASER bit */
|
|
|
|
speed = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_LINK_SPEED);
|
|
|
|
is_25g = speed == 25000 || speed == 50000;
|
|
|
|
|
|
|
|
caps = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_CAP);
|
|
|
|
fec->fec = mcdi_fec_caps_to_ethtool(caps, is_25g);
|
|
|
|
/* BASER is never supported on 100G */
|
|
|
|
if (speed == 100000)
|
|
|
|
fec->fec &= ~ETHTOOL_FEC_BASER;
|
|
|
|
|
|
|
|
active = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_FEC_TYPE);
|
|
|
|
switch (active) {
|
|
|
|
case MC_CMD_FEC_NONE:
|
|
|
|
fec->active_fec = ETHTOOL_FEC_OFF;
|
|
|
|
break;
|
|
|
|
case MC_CMD_FEC_BASER:
|
|
|
|
fec->active_fec = ETHTOOL_FEC_BASER;
|
|
|
|
break;
|
|
|
|
case MC_CMD_FEC_RS:
|
|
|
|
fec->active_fec = ETHTOOL_FEC_RS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
netif_warn(efx, hw, efx->net_dev,
|
|
|
|
"Firmware reports unrecognised FEC_TYPE %u\n",
|
|
|
|
active);
|
|
|
|
/* We don't know what firmware has picked. AUTO is as good a
|
|
|
|
* "can't happen" value as any other.
|
|
|
|
*/
|
|
|
|
fec->active_fec = ETHTOOL_FEC_AUTO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_set_fecparam(struct efx_nic *efx,
|
|
|
|
const struct ethtool_fecparam *fec)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
|
|
|
u32 caps;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Work out what efx_mcdi_phy_set_link_ksettings() would produce from
|
|
|
|
* saved advertising bits
|
|
|
|
*/
|
|
|
|
if (test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, efx->link_advertising))
|
|
|
|
caps = (ethtool_linkset_to_mcdi_cap(efx->link_advertising) |
|
|
|
|
1 << MC_CMD_PHY_CAP_AN_LBN);
|
|
|
|
else
|
|
|
|
caps = phy_cfg->forced_cap;
|
|
|
|
|
|
|
|
caps |= ethtool_fec_caps_to_mcdi(fec->fec);
|
|
|
|
rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
|
|
|
|
efx->loopback_mode, 0);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Record the new FEC setting for subsequent set_link calls */
|
|
|
|
efx->fec_config = fec->fec;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 17:30:50 +08:00
|
|
|
static int efx_mcdi_phy_test_alive(struct efx_nic *efx)
|
|
|
|
{
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN);
|
2010-02-03 17:30:50 +08:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN)
|
2010-04-28 17:27:14 +08:00
|
|
|
return -EIO;
|
2011-12-20 08:44:06 +08:00
|
|
|
if (MCDI_DWORD(outbuf, GET_PHY_STATE_OUT_STATE) != MC_CMD_PHY_STATE_OK)
|
2010-02-03 17:30:50 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-28 17:30:22 +08:00
|
|
|
static const char *const mcdi_sft9001_cable_diag_names[] = {
|
|
|
|
"cable.pairA.length",
|
|
|
|
"cable.pairB.length",
|
|
|
|
"cable.pairC.length",
|
|
|
|
"cable.pairD.length",
|
|
|
|
"cable.pairA.status",
|
|
|
|
"cable.pairB.status",
|
|
|
|
"cable.pairC.status",
|
|
|
|
"cable.pairD.status",
|
|
|
|
};
|
|
|
|
|
|
|
|
static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode,
|
|
|
|
int *results)
|
|
|
|
{
|
|
|
|
unsigned int retry, i, count = 0;
|
|
|
|
size_t outlen;
|
|
|
|
u32 status;
|
2012-09-15 00:31:33 +08:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN);
|
|
|
|
u8 *ptr;
|
2010-04-28 17:30:22 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0);
|
2012-09-15 00:31:33 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST,
|
|
|
|
inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL);
|
2010-04-28 17:30:22 +08:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Wait up to 10s for BIST to finish */
|
|
|
|
for (retry = 0; retry < 100; ++retry) {
|
|
|
|
BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
|
2012-09-15 00:31:33 +08:00
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
2010-04-28 17:30:22 +08:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
2012-09-15 00:31:33 +08:00
|
|
|
status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
|
2010-04-28 17:30:22 +08:00
|
|
|
if (status != MC_CMD_POLL_BIST_RUNNING)
|
|
|
|
goto finished;
|
|
|
|
|
|
|
|
msleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = -ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
finished:
|
|
|
|
results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1;
|
|
|
|
|
|
|
|
/* SFT9001 specific cable diagnostics output */
|
|
|
|
if (efx->phy_type == PHY_TYPE_SFT9001B &&
|
|
|
|
(bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT ||
|
|
|
|
bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) {
|
2012-09-15 00:31:33 +08:00
|
|
|
ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A);
|
2010-04-28 17:30:22 +08:00
|
|
|
if (status == MC_CMD_POLL_BIST_PASSED &&
|
|
|
|
outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) {
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
results[count + i] =
|
|
|
|
EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i],
|
|
|
|
EFX_DWORD_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count += 8;
|
|
|
|
}
|
|
|
|
rc = count;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2010-04-28 17:30:22 +08:00
|
|
|
u32 mode;
|
|
|
|
int rc;
|
|
|
|
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
|
2010-04-28 17:30:22 +08:00
|
|
|
rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
results += rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we support both LONG and SHORT, then run each in response to
|
|
|
|
* break or not. Otherwise, run the one we support */
|
|
|
|
mode = 0;
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN)) {
|
2010-04-28 17:30:22 +08:00
|
|
|
if ((flags & ETH_TEST_FL_OFFLINE) &&
|
|
|
|
(phy_cfg->flags &
|
2011-12-20 08:44:06 +08:00
|
|
|
(1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)))
|
2010-04-28 17:30:22 +08:00
|
|
|
mode = MC_CMD_PHY_BIST_CABLE_LONG;
|
|
|
|
else
|
|
|
|
mode = MC_CMD_PHY_BIST_CABLE_SHORT;
|
|
|
|
} else if (phy_cfg->flags &
|
2011-12-20 08:44:06 +08:00
|
|
|
(1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))
|
2010-04-28 17:30:22 +08:00
|
|
|
mode = MC_CMD_PHY_BIST_CABLE_LONG;
|
|
|
|
|
|
|
|
if (mode != 0) {
|
|
|
|
rc = efx_mcdi_bist(efx, mode, results);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
results += rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-18 13:27:31 +08:00
|
|
|
static const char *efx_mcdi_phy_test_name(struct efx_nic *efx,
|
|
|
|
unsigned int index)
|
2010-04-28 17:30:22 +08:00
|
|
|
{
|
2010-06-01 19:17:06 +08:00
|
|
|
struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
|
2010-04-28 17:30:22 +08:00
|
|
|
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
|
2010-04-28 17:30:22 +08:00
|
|
|
if (index == 0)
|
|
|
|
return "bist";
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
|
2011-12-20 08:44:06 +08:00
|
|
|
if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) |
|
|
|
|
(1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) {
|
2010-04-28 17:30:22 +08:00
|
|
|
if (index == 0)
|
|
|
|
return "cable";
|
|
|
|
--index;
|
|
|
|
|
|
|
|
if (efx->phy_type == PHY_TYPE_SFT9001B) {
|
|
|
|
if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names))
|
|
|
|
return mcdi_sft9001_cable_diag_names[index];
|
|
|
|
index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
#define SFP_PAGE_SIZE 128
|
|
|
|
#define SFF_DIAG_TYPE_OFFSET 92
|
|
|
|
#define SFF_DIAG_ADDR_CHANGE BIT(2)
|
|
|
|
#define SFF_8079_NUM_PAGES 2
|
|
|
|
#define SFF_8472_NUM_PAGES 4
|
|
|
|
#define SFF_8436_NUM_PAGES 5
|
|
|
|
#define SFF_DMT_LEVEL_OFFSET 94
|
|
|
|
|
|
|
|
/** efx_mcdi_phy_get_module_eeprom_page() - Get a single page of module eeprom
|
|
|
|
* @efx: NIC context
|
|
|
|
* @page: EEPROM page number
|
|
|
|
* @data: Destination data pointer
|
|
|
|
* @offset: Offset in page to copy from in to data
|
|
|
|
* @space: Space available in data
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 - amount of data copied
|
|
|
|
* <0 - error
|
|
|
|
*/
|
|
|
|
static int efx_mcdi_phy_get_module_eeprom_page(struct efx_nic *efx,
|
|
|
|
unsigned int page,
|
|
|
|
u8 *data, ssize_t offset,
|
|
|
|
ssize_t space)
|
2012-05-02 01:50:43 +08:00
|
|
|
{
|
2012-09-15 00:30:10 +08:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX);
|
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN);
|
2012-05-02 01:50:43 +08:00
|
|
|
size_t outlen;
|
|
|
|
unsigned int payload_len;
|
|
|
|
unsigned int to_copy;
|
2017-07-18 23:43:19 +08:00
|
|
|
int rc;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
if (offset > SFP_PAGE_SIZE)
|
|
|
|
return -EINVAL;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
to_copy = min(space, SFP_PAGE_SIZE - offset);
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page);
|
|
|
|
rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_PHY_MEDIA_INFO,
|
|
|
|
inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf),
|
|
|
|
&outlen);
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST +
|
|
|
|
SFP_PAGE_SIZE))
|
|
|
|
return -EIO;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
payload_len = MCDI_DWORD(outbuf, GET_PHY_MEDIA_INFO_OUT_DATALEN);
|
|
|
|
if (payload_len != SFP_PAGE_SIZE)
|
|
|
|
return -EIO;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
memcpy(data, MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + offset,
|
|
|
|
to_copy);
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
return to_copy;
|
|
|
|
}
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
static int efx_mcdi_phy_get_module_eeprom_byte(struct efx_nic *efx,
|
|
|
|
unsigned int page,
|
|
|
|
u8 byte)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
u8 data;
|
|
|
|
|
|
|
|
rc = efx_mcdi_phy_get_module_eeprom_page(efx, page, &data, byte, 1);
|
|
|
|
if (rc == 1)
|
|
|
|
return data;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_diag_type(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
/* Page zero of the EEPROM includes the diagnostic type at byte 92. */
|
|
|
|
return efx_mcdi_phy_get_module_eeprom_byte(efx, 0,
|
|
|
|
SFF_DIAG_TYPE_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_sff_8472_level(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
/* Page zero of the EEPROM includes the DMT level at byte 94. */
|
|
|
|
return efx_mcdi_phy_get_module_eeprom_byte(efx, 0,
|
|
|
|
SFF_DMT_LEVEL_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 efx_mcdi_phy_module_type(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_phy_data *phy_data = efx->phy_data;
|
|
|
|
|
|
|
|
if (phy_data->media != MC_CMD_MEDIA_QSFP_PLUS)
|
|
|
|
return phy_data->media;
|
|
|
|
|
|
|
|
/* A QSFP+ NIC may actually have an SFP+ module attached.
|
|
|
|
* The ID is page 0, byte 0.
|
|
|
|
*/
|
|
|
|
switch (efx_mcdi_phy_get_module_eeprom_byte(efx, 0, 0)) {
|
|
|
|
case 0x3:
|
|
|
|
return MC_CMD_MEDIA_SFP_PLUS;
|
|
|
|
case 0xc:
|
|
|
|
case 0xd:
|
|
|
|
return MC_CMD_MEDIA_QSFP_PLUS;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx,
|
|
|
|
struct ethtool_eeprom *ee, u8 *data)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
ssize_t space_remaining = ee->len;
|
|
|
|
unsigned int page_off;
|
|
|
|
bool ignore_missing;
|
|
|
|
int num_pages;
|
|
|
|
int page;
|
|
|
|
|
|
|
|
switch (efx_mcdi_phy_module_type(efx)) {
|
|
|
|
case MC_CMD_MEDIA_SFP_PLUS:
|
|
|
|
num_pages = efx_mcdi_phy_sff_8472_level(efx) > 0 ?
|
|
|
|
SFF_8472_NUM_PAGES : SFF_8079_NUM_PAGES;
|
|
|
|
page = 0;
|
|
|
|
ignore_missing = false;
|
|
|
|
break;
|
|
|
|
case MC_CMD_MEDIA_QSFP_PLUS:
|
|
|
|
num_pages = SFF_8436_NUM_PAGES;
|
|
|
|
page = -1; /* We obtain the lower page by asking for -1. */
|
|
|
|
ignore_missing = true; /* Ignore missing pages after page 0. */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
page_off = ee->offset % SFP_PAGE_SIZE;
|
|
|
|
page += ee->offset / SFP_PAGE_SIZE;
|
|
|
|
|
|
|
|
while (space_remaining && (page < num_pages)) {
|
|
|
|
rc = efx_mcdi_phy_get_module_eeprom_page(efx, page,
|
|
|
|
data, page_off,
|
|
|
|
space_remaining);
|
|
|
|
|
|
|
|
if (rc > 0) {
|
|
|
|
space_remaining -= rc;
|
|
|
|
data += rc;
|
|
|
|
page_off = 0;
|
|
|
|
page++;
|
|
|
|
} else if (rc == 0) {
|
|
|
|
space_remaining = 0;
|
|
|
|
} else if (ignore_missing && (page > 0)) {
|
|
|
|
int intended_size = SFP_PAGE_SIZE - page_off;
|
|
|
|
|
|
|
|
space_remaining -= intended_size;
|
|
|
|
if (space_remaining < 0) {
|
|
|
|
space_remaining = 0;
|
|
|
|
} else {
|
|
|
|
memset(data, 0, intended_size);
|
|
|
|
data += intended_size;
|
|
|
|
page_off = 0;
|
|
|
|
page++;
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return rc;
|
|
|
|
}
|
2012-05-02 01:50:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_phy_get_module_info(struct efx_nic *efx,
|
|
|
|
struct ethtool_modinfo *modinfo)
|
|
|
|
{
|
2017-07-18 23:43:19 +08:00
|
|
|
int sff_8472_level;
|
|
|
|
int diag_type;
|
2012-05-02 01:50:43 +08:00
|
|
|
|
2017-07-18 23:43:19 +08:00
|
|
|
switch (efx_mcdi_phy_module_type(efx)) {
|
2012-05-02 01:50:43 +08:00
|
|
|
case MC_CMD_MEDIA_SFP_PLUS:
|
2017-07-18 23:43:19 +08:00
|
|
|
sff_8472_level = efx_mcdi_phy_sff_8472_level(efx);
|
|
|
|
|
|
|
|
/* If we can't read the diagnostics level we have none. */
|
|
|
|
if (sff_8472_level < 0)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
/* Check if this module requires the (unsupported) address
|
|
|
|
* change operation.
|
|
|
|
*/
|
|
|
|
diag_type = efx_mcdi_phy_diag_type(efx);
|
|
|
|
|
|
|
|
if ((sff_8472_level == 0) ||
|
|
|
|
(diag_type & SFF_DIAG_ADDR_CHANGE)) {
|
|
|
|
modinfo->type = ETH_MODULE_SFF_8079;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
|
|
|
|
} else {
|
|
|
|
modinfo->type = ETH_MODULE_SFF_8472;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_CMD_MEDIA_QSFP_PLUS:
|
|
|
|
modinfo->type = ETH_MODULE_SFF_8436;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
|
|
|
|
break;
|
|
|
|
|
2012-05-02 01:50:43 +08:00
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2017-07-18 23:43:19 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-05-02 01:50:43 +08:00
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
static const struct efx_phy_operations efx_mcdi_phy_ops = {
|
2009-11-29 23:15:25 +08:00
|
|
|
.probe = efx_mcdi_phy_probe,
|
2012-01-06 01:19:45 +08:00
|
|
|
.init = efx_port_dummy_op_int,
|
2012-09-18 09:33:54 +08:00
|
|
|
.reconfigure = efx_mcdi_port_reconfigure,
|
2009-11-29 23:15:25 +08:00
|
|
|
.poll = efx_mcdi_phy_poll,
|
2009-12-23 21:46:36 +08:00
|
|
|
.fini = efx_port_dummy_op_void,
|
|
|
|
.remove = efx_mcdi_phy_remove,
|
2016-12-15 07:12:53 +08:00
|
|
|
.get_link_ksettings = efx_mcdi_phy_get_link_ksettings,
|
|
|
|
.set_link_ksettings = efx_mcdi_phy_set_link_ksettings,
|
2018-03-14 22:21:26 +08:00
|
|
|
.get_fecparam = efx_mcdi_phy_get_fecparam,
|
|
|
|
.set_fecparam = efx_mcdi_phy_set_fecparam,
|
2010-02-03 17:30:50 +08:00
|
|
|
.test_alive = efx_mcdi_phy_test_alive,
|
2010-04-28 17:30:22 +08:00
|
|
|
.run_tests = efx_mcdi_phy_run_tests,
|
|
|
|
.test_name = efx_mcdi_phy_test_name,
|
2012-05-02 01:50:43 +08:00
|
|
|
.get_module_eeprom = efx_mcdi_phy_get_module_eeprom,
|
|
|
|
.get_module_info = efx_mcdi_phy_get_module_info,
|
2009-11-29 23:15:25 +08:00
|
|
|
};
|
2012-09-18 09:33:54 +08:00
|
|
|
|
2013-08-30 02:19:29 +08:00
|
|
|
u32 efx_mcdi_phy_get_caps(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_phy_data *phy_data = efx->phy_data;
|
|
|
|
|
|
|
|
return phy_data->supported_cap;
|
|
|
|
}
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
static unsigned int efx_mcdi_event_link_speed[] = {
|
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100,
|
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000,
|
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000,
|
2013-09-06 00:53:57 +08:00
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_40G] = 40000,
|
2018-01-11 01:59:59 +08:00
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_25G] = 25000,
|
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_50G] = 50000,
|
|
|
|
[MCDI_EVENT_LINKCHANGE_SPEED_100G] = 100000,
|
2012-09-18 09:33:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev)
|
|
|
|
{
|
|
|
|
u32 flags, fcntl, speed, lpa;
|
|
|
|
|
|
|
|
speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED);
|
2016-12-02 23:51:33 +08:00
|
|
|
EFX_WARN_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
|
2012-09-18 09:33:54 +08:00
|
|
|
speed = efx_mcdi_event_link_speed[speed];
|
|
|
|
|
|
|
|
flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS);
|
|
|
|
fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL);
|
|
|
|
lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP);
|
|
|
|
|
|
|
|
/* efx->link_state is only modified by efx_mcdi_phy_get_link(),
|
|
|
|
* which is only run after flushing the event queues. Therefore, it
|
|
|
|
* is safe to modify the link state outside of the mac_lock here.
|
|
|
|
*/
|
|
|
|
efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl);
|
|
|
|
|
|
|
|
efx_mcdi_phy_check_fcntl(efx, lpa);
|
|
|
|
|
|
|
|
efx_link_status_changed(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_set_mac(struct efx_nic *efx)
|
|
|
|
{
|
2012-11-20 07:08:22 +08:00
|
|
|
u32 fcntl;
|
2012-09-18 09:33:54 +08:00
|
|
|
MCDI_DECLARE_BUF(cmdbytes, MC_CMD_SET_MAC_IN_LEN);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0);
|
|
|
|
|
sfc: set the MAC address using MC_CMD_VADAPTOR_SET_MAC
Add a set_mac_address() NIC-type function for EF10 only, and
use this to set the MAC address on the vadaptor. For Siena and
earlier, the MAC address continues to be set by MC_CMD_SET_MAC;
this is still called on EF10, and including a MAC address in
this command has no effect.
The sriov_mac_address_changed() NIC-type function is no longer
needed on EF10, but it is needed for Siena where it is used to
update the peer address of the PF for VFDI. Change this to use
the new set_mac_address function pointer.
efx_ef10_sriov_mac_address_changed() is no longer called, as VFs
will try to change the MAC address on their vadaptor rather than
trying to change to the context of the PF to alter the vport.
When a VF is running in direct passthrough mode with MAC spoofing
enabled, it will be able to change the MAC address on its vadaptor.
In this case, there is a link to the PF, so find the correct VF in
its ef10_vf array and update the MAC address.
ndo_set_mac_address() can be called during driver unload while
bonding, and in this case the device has already been stopped, so
don't call efx_net_open() to restart it after reconfiguration.
efx->port_enabled is set to false in efx_stop_port(), so it is
indicator of whether the device needs to be restarted.
Signed-off-by: Shradha Shah <sshah@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-05-20 18:12:48 +08:00
|
|
|
/* This has no effect on EF10 */
|
2014-03-08 02:27:41 +08:00
|
|
|
ether_addr_copy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR),
|
|
|
|
efx->net_dev->dev_addr);
|
2012-09-18 09:33:54 +08:00
|
|
|
|
|
|
|
MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
|
|
|
|
EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
|
|
|
|
MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
|
|
|
|
|
2012-11-20 07:08:22 +08:00
|
|
|
/* Set simple MAC filter for Siena */
|
|
|
|
MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_REJECT,
|
|
|
|
SET_MAC_IN_REJECT_UNCST, efx->unicast_filter);
|
2012-09-18 09:33:54 +08:00
|
|
|
|
2017-10-31 22:29:47 +08:00
|
|
|
MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_FLAGS,
|
|
|
|
SET_MAC_IN_FLAG_INCLUDE_FCS,
|
|
|
|
!!(efx->net_dev->features & NETIF_F_RXFCS));
|
|
|
|
|
2012-09-18 09:33:54 +08:00
|
|
|
switch (efx->wanted_fc) {
|
|
|
|
case EFX_FC_RX | EFX_FC_TX:
|
|
|
|
fcntl = MC_CMD_FCNTL_BIDIR;
|
|
|
|
break;
|
|
|
|
case EFX_FC_RX:
|
|
|
|
fcntl = MC_CMD_FCNTL_RESPOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fcntl = MC_CMD_FCNTL_OFF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (efx->wanted_fc & EFX_FC_AUTO)
|
|
|
|
fcntl = MC_CMD_FCNTL_AUTO;
|
|
|
|
if (efx->fc_disable)
|
|
|
|
fcntl = MC_CMD_FCNTL_OFF;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
|
|
|
|
|
|
|
|
return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
|
|
|
|
size_t outlength;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlength);
|
2013-06-01 01:36:12 +08:00
|
|
|
if (rc)
|
2012-09-18 09:33:54 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
|
|
|
|
}
|
|
|
|
|
2013-10-01 00:36:50 +08:00
|
|
|
enum efx_stats_action {
|
|
|
|
EFX_STATS_ENABLE,
|
|
|
|
EFX_STATS_DISABLE,
|
|
|
|
EFX_STATS_PULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int efx_mcdi_mac_stats(struct efx_nic *efx,
|
|
|
|
enum efx_stats_action action, int clear)
|
2012-09-18 09:33:54 +08:00
|
|
|
{
|
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
|
|
|
|
int rc;
|
2013-10-01 00:36:50 +08:00
|
|
|
int change = action == EFX_STATS_PULL ? 0 : 1;
|
|
|
|
int enable = action == EFX_STATS_ENABLE ? 1 : 0;
|
|
|
|
int period = action == EFX_STATS_ENABLE ? 1000 : 0;
|
|
|
|
dma_addr_t dma_addr = efx->stats_buffer.dma_addr;
|
|
|
|
u32 dma_len = action != EFX_STATS_DISABLE ?
|
2017-12-21 17:00:26 +08:00
|
|
|
efx->num_mac_stats * sizeof(u64) : 0;
|
2012-09-18 09:33:54 +08:00
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
|
|
|
|
|
|
|
|
MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, dma_addr);
|
2012-10-11 06:24:51 +08:00
|
|
|
MCDI_POPULATE_DWORD_7(inbuf, MAC_STATS_IN_CMD,
|
|
|
|
MAC_STATS_IN_DMA, !!enable,
|
|
|
|
MAC_STATS_IN_CLEAR, clear,
|
2013-10-01 00:36:50 +08:00
|
|
|
MAC_STATS_IN_PERIODIC_CHANGE, change,
|
|
|
|
MAC_STATS_IN_PERIODIC_ENABLE, enable,
|
2012-10-11 06:24:51 +08:00
|
|
|
MAC_STATS_IN_PERIODIC_CLEAR, 0,
|
|
|
|
MAC_STATS_IN_PERIODIC_NOEVENT, 1,
|
|
|
|
MAC_STATS_IN_PERIOD_MS, period);
|
2012-09-18 09:33:54 +08:00
|
|
|
MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
|
2017-08-15 21:55:32 +08:00
|
|
|
|
|
|
|
if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) {
|
|
|
|
struct efx_ef10_nic_data *nic_data = efx->nic_data;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, nic_data->vport_id);
|
|
|
|
}
|
2012-09-18 09:33:54 +08:00
|
|
|
|
2015-06-02 18:39:49 +08:00
|
|
|
rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
/* Expect ENOENT if DMA queues have not been set up */
|
|
|
|
if (rc && (rc != -ENOENT || atomic_read(&efx->active_queues)))
|
|
|
|
efx_mcdi_display_error(efx, MC_CMD_MAC_STATS, sizeof(inbuf),
|
|
|
|
NULL, 0, rc);
|
2012-09-18 09:33:54 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_mac_start_stats(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
__le64 *dma_stats = efx->stats_buffer.addr;
|
|
|
|
|
2017-12-21 17:00:26 +08:00
|
|
|
dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
|
2012-09-18 09:33:54 +08:00
|
|
|
|
2013-10-01 00:36:50 +08:00
|
|
|
efx_mcdi_mac_stats(efx, EFX_STATS_ENABLE, 0);
|
2012-09-18 09:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_mac_stop_stats(struct efx_nic *efx)
|
|
|
|
{
|
2013-10-01 00:36:50 +08:00
|
|
|
efx_mcdi_mac_stats(efx, EFX_STATS_DISABLE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EFX_MAC_STATS_WAIT_US 100
|
|
|
|
#define EFX_MAC_STATS_WAIT_ATTEMPTS 10
|
|
|
|
|
|
|
|
void efx_mcdi_mac_pull_stats(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
__le64 *dma_stats = efx->stats_buffer.addr;
|
|
|
|
int attempts = EFX_MAC_STATS_WAIT_ATTEMPTS;
|
|
|
|
|
2017-12-21 17:00:26 +08:00
|
|
|
dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
|
2013-10-01 00:36:50 +08:00
|
|
|
efx_mcdi_mac_stats(efx, EFX_STATS_PULL, 0);
|
|
|
|
|
2017-12-21 17:00:26 +08:00
|
|
|
while (dma_stats[efx->num_mac_stats - 1] ==
|
2013-10-01 00:36:50 +08:00
|
|
|
EFX_MC_STATS_GENERATION_INVALID &&
|
|
|
|
attempts-- != 0)
|
|
|
|
udelay(EFX_MAC_STATS_WAIT_US);
|
2012-09-18 09:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_port_probe(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Hook in PHY operations table */
|
|
|
|
efx->phy_op = &efx_mcdi_phy_ops;
|
|
|
|
|
|
|
|
/* Set up MDIO structure for PHY */
|
|
|
|
efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
|
|
|
|
efx->mdio.mdio_read = efx_mcdi_mdio_read;
|
|
|
|
efx->mdio.mdio_write = efx_mcdi_mdio_write;
|
|
|
|
|
|
|
|
/* Fill out MDIO structure, loopback modes, and initial link state */
|
|
|
|
rc = efx->phy_op->probe(efx);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Allocate buffer for stats */
|
|
|
|
rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
|
2017-12-21 17:00:26 +08:00
|
|
|
efx->num_mac_stats * sizeof(u64), GFP_KERNEL);
|
2012-09-18 09:33:54 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
netif_dbg(efx, probe, efx->net_dev,
|
|
|
|
"stats buffer at %llx (virt %p phys %llx)\n",
|
|
|
|
(u64)efx->stats_buffer.dma_addr,
|
|
|
|
efx->stats_buffer.addr,
|
|
|
|
(u64)virt_to_phys(efx->stats_buffer.addr));
|
|
|
|
|
2013-10-01 00:36:50 +08:00
|
|
|
efx_mcdi_mac_stats(efx, EFX_STATS_DISABLE, 1);
|
2012-09-18 09:33:54 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_port_remove(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
efx->phy_op->remove(efx);
|
|
|
|
efx_nic_free_buffer(efx, &efx->stats_buffer);
|
|
|
|
}
|
2013-08-30 02:19:29 +08:00
|
|
|
|
|
|
|
/* Get physical port number (EF10 only; on Siena it is same as PF number) */
|
|
|
|
int efx_mcdi_port_get_number(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_PORT_ASSIGNMENT, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), NULL);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return MCDI_DWORD(outbuf, GET_PORT_ASSIGNMENT_OUT_PORT);
|
|
|
|
}
|