2008-04-27 19:55:59 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Driver for Solarflare Solarstorm network controllers and boards
|
2011-02-25 08:01:34 +08:00
|
|
|
* Copyright 2006-2010 Solarflare Communications Inc.
|
2008-04-27 19:55:59 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation, incorporated herein by reference.
|
|
|
|
*/
|
|
|
|
/*
|
2009-10-23 16:33:42 +08:00
|
|
|
* Driver for AMCC QT202x SFP+ and XFP adapters; see www.amcc.com for details
|
2008-04-27 19:55:59 +08:00
|
|
|
*/
|
|
|
|
|
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>
|
2008-04-27 19:55:59 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include "efx.h"
|
|
|
|
#include "mdio_10g.h"
|
|
|
|
#include "phy.h"
|
2009-11-29 23:12:08 +08:00
|
|
|
#include "nic.h"
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
#define QT202X_REQUIRED_DEVS (MDIO_DEVS_PCS | \
|
|
|
|
MDIO_DEVS_PMAPMD | \
|
|
|
|
MDIO_DEVS_PHYXS)
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
#define QT202X_LOOPBACKS ((1 << LOOPBACK_PCS) | \
|
|
|
|
(1 << LOOPBACK_PMAPMD) | \
|
2009-11-29 23:08:41 +08:00
|
|
|
(1 << LOOPBACK_PHYXS_WS))
|
2008-05-07 20:36:19 +08:00
|
|
|
|
2008-04-27 19:55:59 +08:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Quake-specific MDIO registers */
|
|
|
|
#define MDIO_QUAKE_LED0_REG (0xD006)
|
|
|
|
|
2009-02-27 21:07:33 +08:00
|
|
|
/* QT2025C only */
|
|
|
|
#define PCS_FW_HEARTBEAT_REG 0xd7ee
|
|
|
|
#define PCS_FW_HEARTB_LBN 0
|
|
|
|
#define PCS_FW_HEARTB_WIDTH 8
|
2009-12-23 21:48:04 +08:00
|
|
|
#define PCS_FW_PRODUCT_CODE_1 0xd7f0
|
|
|
|
#define PCS_FW_VERSION_1 0xd7f3
|
|
|
|
#define PCS_FW_BUILD_1 0xd7f6
|
2009-02-27 21:07:33 +08:00
|
|
|
#define PCS_UC8051_STATUS_REG 0xd7fd
|
|
|
|
#define PCS_UC_STATUS_LBN 0
|
|
|
|
#define PCS_UC_STATUS_WIDTH 8
|
|
|
|
#define PCS_UC_STATUS_FW_SAVE 0x20
|
2010-12-02 21:46:37 +08:00
|
|
|
#define PMA_PMD_MODE_REG 0xc301
|
|
|
|
#define PMA_PMD_RXIN_SEL_LBN 6
|
2009-02-27 21:07:33 +08:00
|
|
|
#define PMA_PMD_FTX_CTRL2_REG 0xc309
|
|
|
|
#define PMA_PMD_FTX_STATIC_LBN 13
|
|
|
|
#define PMA_PMD_VEND1_REG 0xc001
|
|
|
|
#define PMA_PMD_VEND1_LBTXD_LBN 15
|
2012-01-06 01:19:45 +08:00
|
|
|
#define PCS_VEND1_REG 0xc000
|
2009-02-27 21:07:33 +08:00
|
|
|
#define PCS_VEND1_LBTXD_LBN 5
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
void falcon_qt202x_set_led(struct efx_nic *p, int led, int mode)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
|
|
|
int addr = MDIO_QUAKE_LED0_REG + led;
|
2009-04-29 16:05:08 +08:00
|
|
|
efx_mdio_write(p, MDIO_MMD_PMAPMD, addr, mode);
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
struct qt202x_phy_data {
|
2008-09-01 19:48:17 +08:00
|
|
|
enum efx_phy_mode phy_mode;
|
2009-12-23 21:47:37 +08:00
|
|
|
bool bug17190_in_bad_state;
|
|
|
|
unsigned long bug17190_timer;
|
2009-12-23 21:48:04 +08:00
|
|
|
u32 firmware_ver;
|
2008-05-07 20:36:19 +08:00
|
|
|
};
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
#define QT2022C2_MAX_RESET_TIME 500
|
|
|
|
#define QT2022C2_RESET_WAIT 10
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2009-12-23 21:48:32 +08:00
|
|
|
#define QT2025C_MAX_HEARTB_TIME (5 * HZ)
|
|
|
|
#define QT2025C_HEARTB_WAIT 100
|
|
|
|
#define QT2025C_MAX_FWSTART_TIME (25 * HZ / 10)
|
|
|
|
#define QT2025C_FWSTART_WAIT 100
|
|
|
|
|
2009-12-23 21:47:37 +08:00
|
|
|
#define BUG17190_INTERVAL (2 * HZ)
|
|
|
|
|
2009-12-23 21:48:32 +08:00
|
|
|
static int qt2025c_wait_heartbeat(struct efx_nic *efx)
|
2009-02-27 21:07:33 +08:00
|
|
|
{
|
2009-12-23 21:48:32 +08:00
|
|
|
unsigned long timeout = jiffies + QT2025C_MAX_HEARTB_TIME;
|
2009-02-27 21:07:33 +08:00
|
|
|
int reg, old_counter = 0;
|
|
|
|
|
|
|
|
/* Wait for firmware heartbeat to start */
|
|
|
|
for (;;) {
|
|
|
|
int counter;
|
2009-04-29 16:05:08 +08:00
|
|
|
reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_FW_HEARTBEAT_REG);
|
2009-02-27 21:07:33 +08:00
|
|
|
if (reg < 0)
|
|
|
|
return reg;
|
|
|
|
counter = ((reg >> PCS_FW_HEARTB_LBN) &
|
|
|
|
((1 << PCS_FW_HEARTB_WIDTH) - 1));
|
|
|
|
if (old_counter == 0)
|
|
|
|
old_counter = counter;
|
|
|
|
else if (counter != old_counter)
|
|
|
|
break;
|
2009-12-23 21:48:42 +08:00
|
|
|
if (time_after(jiffies, timeout)) {
|
|
|
|
/* Some cables have EEPROMs that conflict with the
|
|
|
|
* PHY's on-board EEPROM so it cannot load firmware */
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"If an SFP+ direct attach cable is"
|
|
|
|
" connected, please check that it complies"
|
|
|
|
" with the SFP+ specification\n");
|
2009-02-27 21:07:33 +08:00
|
|
|
return -ETIMEDOUT;
|
2009-12-23 21:48:42 +08:00
|
|
|
}
|
2009-12-23 21:48:32 +08:00
|
|
|
msleep(QT2025C_HEARTB_WAIT);
|
2009-02-27 21:07:33 +08:00
|
|
|
}
|
|
|
|
|
2009-12-23 21:48:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qt2025c_wait_fw_status_good(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
unsigned long timeout = jiffies + QT2025C_MAX_FWSTART_TIME;
|
|
|
|
int reg;
|
|
|
|
|
2009-02-27 21:07:33 +08:00
|
|
|
/* Wait for firmware status to look good */
|
|
|
|
for (;;) {
|
2009-04-29 16:05:08 +08:00
|
|
|
reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_UC8051_STATUS_REG);
|
2009-02-27 21:07:33 +08:00
|
|
|
if (reg < 0)
|
|
|
|
return reg;
|
|
|
|
if ((reg &
|
|
|
|
((1 << PCS_UC_STATUS_WIDTH) - 1) << PCS_UC_STATUS_LBN) >=
|
|
|
|
PCS_UC_STATUS_FW_SAVE)
|
|
|
|
break;
|
|
|
|
if (time_after(jiffies, timeout))
|
|
|
|
return -ETIMEDOUT;
|
2009-12-23 21:48:32 +08:00
|
|
|
msleep(QT2025C_FWSTART_WAIT);
|
2009-02-27 21:07:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-23 21:48:32 +08:00
|
|
|
static void qt2025c_restart_firmware(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
/* Restart microcontroller execution of firmware from RAM */
|
|
|
|
efx_mdio_write(efx, 3, 0xe854, 0x00c0);
|
|
|
|
efx_mdio_write(efx, 3, 0xe854, 0x0040);
|
|
|
|
msleep(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qt2025c_wait_reset(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = qt2025c_wait_heartbeat(efx);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = qt2025c_wait_fw_status_good(efx);
|
|
|
|
if (rc == -ETIMEDOUT) {
|
|
|
|
/* Bug 17689: occasionally heartbeat starts but firmware status
|
|
|
|
* code never progresses beyond 0x00. Try again, once, after
|
|
|
|
* restarting execution of the firmware image. */
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_dbg(efx, hw, efx->net_dev,
|
|
|
|
"bashing QT2025C microcontroller\n");
|
2009-12-23 21:48:32 +08:00
|
|
|
qt2025c_restart_firmware(efx);
|
|
|
|
rc = qt2025c_wait_heartbeat(efx);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
rc = qt2025c_wait_fw_status_good(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-12-23 21:48:04 +08:00
|
|
|
static void qt2025c_firmware_id(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct qt202x_phy_data *phy_data = efx->phy_data;
|
|
|
|
u8 firmware_id[9];
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(firmware_id); i++)
|
|
|
|
firmware_id[i] = efx_mdio_read(efx, MDIO_MMD_PCS,
|
|
|
|
PCS_FW_PRODUCT_CODE_1 + i);
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_info(efx, probe, efx->net_dev,
|
|
|
|
"QT2025C firmware %xr%d v%d.%d.%d.%d [20%02d-%02d-%02d]\n",
|
|
|
|
(firmware_id[0] << 8) | firmware_id[1], firmware_id[2],
|
|
|
|
firmware_id[3] >> 4, firmware_id[3] & 0xf,
|
|
|
|
firmware_id[4], firmware_id[5],
|
|
|
|
firmware_id[6], firmware_id[7], firmware_id[8]);
|
2009-12-23 21:48:04 +08:00
|
|
|
phy_data->firmware_ver = ((firmware_id[3] & 0xf0) << 20) |
|
|
|
|
((firmware_id[3] & 0x0f) << 16) |
|
|
|
|
(firmware_id[4] << 8) | firmware_id[5];
|
|
|
|
}
|
|
|
|
|
2009-12-23 21:47:37 +08:00
|
|
|
static void qt2025c_bug17190_workaround(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct qt202x_phy_data *phy_data = efx->phy_data;
|
|
|
|
|
|
|
|
/* The PHY can get stuck in a state where it reports PHY_XS and PMA/PMD
|
|
|
|
* layers up, but PCS down (no block_lock). If we notice this state
|
|
|
|
* persisting for a couple of seconds, we switch PMA/PMD loopback
|
|
|
|
* briefly on and then off again, which is normally sufficient to
|
|
|
|
* recover it.
|
|
|
|
*/
|
|
|
|
if (efx->link_state.up ||
|
|
|
|
!efx_mdio_links_ok(efx, MDIO_DEVS_PMAPMD | MDIO_DEVS_PHYXS)) {
|
|
|
|
phy_data->bug17190_in_bad_state = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!phy_data->bug17190_in_bad_state) {
|
|
|
|
phy_data->bug17190_in_bad_state = true;
|
|
|
|
phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time_after_eq(jiffies, phy_data->bug17190_timer)) {
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_dbg(efx, hw, efx->net_dev, "bashing QT2025C PMA/PMD\n");
|
2009-12-23 21:47:37 +08:00
|
|
|
efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
|
|
|
|
MDIO_PMA_CTRL1_LOOPBACK, true);
|
|
|
|
msleep(100);
|
|
|
|
efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
|
|
|
|
MDIO_PMA_CTRL1_LOOPBACK, false);
|
|
|
|
phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-23 21:48:04 +08:00
|
|
|
static int qt2025c_select_phy_mode(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct qt202x_phy_data *phy_data = efx->phy_data;
|
|
|
|
struct falcon_board *board = falcon_board(efx);
|
|
|
|
int reg, rc, i;
|
|
|
|
uint16_t phy_op_mode;
|
|
|
|
|
|
|
|
/* Only 2.0.1.0+ PHY firmware supports the more optimal SFP+
|
|
|
|
* Self-Configure mode. Don't attempt any switching if we encounter
|
|
|
|
* older firmware. */
|
|
|
|
if (phy_data->firmware_ver < 0x02000100)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* In general we will get optimal behaviour in "SFP+ Self-Configure"
|
|
|
|
* mode; however, that powers down most of the PHY when no module is
|
|
|
|
* present, so we must use a different mode (any fixed mode will do)
|
|
|
|
* to be sure that loopbacks will work. */
|
|
|
|
phy_op_mode = (efx->loopback_mode == LOOPBACK_NONE) ? 0x0038 : 0x0020;
|
|
|
|
|
|
|
|
/* Only change mode if really necessary */
|
|
|
|
reg = efx_mdio_read(efx, 1, 0xc319);
|
|
|
|
if ((reg & 0x0038) == phy_op_mode)
|
|
|
|
return 0;
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_dbg(efx, hw, efx->net_dev, "Switching PHY to mode 0x%04x\n",
|
|
|
|
phy_op_mode);
|
2009-12-23 21:48:04 +08:00
|
|
|
|
|
|
|
/* This sequence replicates the register writes configured in the boot
|
|
|
|
* EEPROM (including the differences between board revisions), except
|
|
|
|
* that the operating mode is changed, and the PHY is prevented from
|
|
|
|
* unnecessarily reloading the main firmware image again. */
|
|
|
|
efx_mdio_write(efx, 1, 0xc300, 0x0000);
|
|
|
|
/* (Note: this portion of the boot EEPROM sequence, which bit-bashes 9
|
|
|
|
* STOPs onto the firmware/module I2C bus to reset it, varies across
|
|
|
|
* board revisions, as the bus is connected to different GPIO/LED
|
|
|
|
* outputs on the PHY.) */
|
|
|
|
if (board->major == 0 && board->minor < 2) {
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4498);
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4488);
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4480);
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4490);
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4498);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x0920);
|
|
|
|
efx_mdio_write(efx, 1, 0xd008, 0x0004);
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x0900);
|
|
|
|
efx_mdio_write(efx, 1, 0xd008, 0x0005);
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x0920);
|
|
|
|
efx_mdio_write(efx, 1, 0xd008, 0x0004);
|
|
|
|
}
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4900);
|
|
|
|
}
|
|
|
|
efx_mdio_write(efx, 1, 0xc303, 0x4900);
|
|
|
|
efx_mdio_write(efx, 1, 0xc302, 0x0004);
|
|
|
|
efx_mdio_write(efx, 1, 0xc316, 0x0013);
|
|
|
|
efx_mdio_write(efx, 1, 0xc318, 0x0054);
|
|
|
|
efx_mdio_write(efx, 1, 0xc319, phy_op_mode);
|
|
|
|
efx_mdio_write(efx, 1, 0xc31a, 0x0098);
|
|
|
|
efx_mdio_write(efx, 3, 0x0026, 0x0e00);
|
|
|
|
efx_mdio_write(efx, 3, 0x0027, 0x0013);
|
|
|
|
efx_mdio_write(efx, 3, 0x0028, 0xa528);
|
|
|
|
efx_mdio_write(efx, 1, 0xd006, 0x000a);
|
|
|
|
efx_mdio_write(efx, 1, 0xd007, 0x0009);
|
|
|
|
efx_mdio_write(efx, 1, 0xd008, 0x0004);
|
|
|
|
/* This additional write is not present in the boot EEPROM. It
|
|
|
|
* prevents the PHY's internal boot ROM doing another pointless (and
|
|
|
|
* slow) reload of the firmware image (the microcontroller's code
|
|
|
|
* memory is not affected by the microcontroller reset). */
|
|
|
|
efx_mdio_write(efx, 1, 0xc317, 0x00ff);
|
2010-12-02 21:46:37 +08:00
|
|
|
/* PMA/PMD loopback sets RXIN to inverse polarity and the firmware
|
|
|
|
* restart doesn't reset it. We need to do that ourselves. */
|
|
|
|
efx_mdio_set_flag(efx, 1, PMA_PMD_MODE_REG,
|
|
|
|
1 << PMA_PMD_RXIN_SEL_LBN, false);
|
2009-12-23 21:48:04 +08:00
|
|
|
efx_mdio_write(efx, 1, 0xc300, 0x0002);
|
|
|
|
msleep(20);
|
|
|
|
|
2009-12-23 21:48:32 +08:00
|
|
|
/* Restart microcontroller execution of firmware from RAM */
|
|
|
|
qt2025c_restart_firmware(efx);
|
2009-12-23 21:48:04 +08:00
|
|
|
|
|
|
|
/* Wait for the microcontroller to be ready again */
|
|
|
|
rc = qt2025c_wait_reset(efx);
|
|
|
|
if (rc < 0) {
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"PHY microcontroller reset during mode switch "
|
|
|
|
"timed out\n");
|
2009-12-23 21:48:04 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
static int qt202x_reset_phy(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2009-02-27 21:07:33 +08:00
|
|
|
if (efx->phy_type == PHY_TYPE_QT2025C) {
|
2009-08-26 16:17:19 +08:00
|
|
|
/* Wait for the reset triggered by falcon_reset_hw()
|
|
|
|
* to complete */
|
2009-02-27 21:07:33 +08:00
|
|
|
rc = qt2025c_wait_reset(efx);
|
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2009-08-26 16:17:19 +08:00
|
|
|
} else {
|
|
|
|
/* Reset the PHYXS MMD. This is documented as doing
|
|
|
|
* a complete soft reset. */
|
|
|
|
rc = efx_mdio_reset_mmd(efx, MDIO_MMD_PHYXS,
|
2009-10-23 16:33:42 +08:00
|
|
|
QT2022C2_MAX_RESET_TIME /
|
|
|
|
QT2022C2_RESET_WAIT,
|
|
|
|
QT2022C2_RESET_WAIT);
|
2009-08-26 16:17:19 +08:00
|
|
|
if (rc < 0)
|
|
|
|
goto fail;
|
2009-02-27 21:07:33 +08:00
|
|
|
}
|
|
|
|
|
2008-04-27 19:55:59 +08:00
|
|
|
/* Wait 250ms for the PHY to complete bootup */
|
|
|
|
msleep(250);
|
|
|
|
|
2009-11-26 00:09:41 +08:00
|
|
|
falcon_board(efx)->type->init_phy(efx);
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2010-02-13 04:32:27 +08:00
|
|
|
return 0;
|
2008-04-27 19:55:59 +08:00
|
|
|
|
|
|
|
fail:
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, hw, efx->net_dev, "PHY reset timed out\n");
|
2008-04-27 19:55:59 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-11-29 23:08:55 +08:00
|
|
|
static int qt202x_phy_probe(struct efx_nic *efx)
|
|
|
|
{
|
2009-12-23 21:46:36 +08:00
|
|
|
struct qt202x_phy_data *phy_data;
|
|
|
|
|
|
|
|
phy_data = kzalloc(sizeof(struct qt202x_phy_data), GFP_KERNEL);
|
|
|
|
if (!phy_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
efx->phy_data = phy_data;
|
|
|
|
phy_data->phy_mode = efx->phy_mode;
|
2009-12-23 21:47:37 +08:00
|
|
|
phy_data->bug17190_in_bad_state = false;
|
|
|
|
phy_data->bug17190_timer = 0;
|
2009-12-23 21:46:36 +08:00
|
|
|
|
2009-11-29 23:08:55 +08:00
|
|
|
efx->mdio.mmds = QT202X_REQUIRED_DEVS;
|
|
|
|
efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
|
|
|
|
efx->loopback_modes = QT202X_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
static int qt202x_phy_init(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
2009-11-28 13:34:29 +08:00
|
|
|
u32 devid;
|
2008-04-27 19:55:59 +08:00
|
|
|
int rc;
|
|
|
|
|
2009-11-28 13:34:29 +08:00
|
|
|
rc = qt202x_reset_phy(efx);
|
|
|
|
if (rc) {
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_err(efx, probe, efx->net_dev, "PHY init failed\n");
|
2009-11-28 13:34:29 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
devid = efx_mdio_read_id(efx, MDIO_MMD_PHYXS);
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_info(efx, probe, efx->net_dev,
|
|
|
|
"PHY ID reg %x (OUI %06x model %02x revision %x)\n",
|
|
|
|
devid, efx_mdio_id_oui(devid), efx_mdio_id_model(devid),
|
|
|
|
efx_mdio_id_rev(devid));
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2009-12-23 21:48:04 +08:00
|
|
|
if (efx->phy_type == PHY_TYPE_QT2025C)
|
|
|
|
qt2025c_firmware_id(efx);
|
|
|
|
|
2008-05-07 20:36:19 +08:00
|
|
|
return 0;
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
static int qt202x_link_ok(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
2009-10-23 16:33:42 +08:00
|
|
|
return efx_mdio_links_ok(efx, QT202X_REQUIRED_DEVS);
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2009-11-28 13:34:05 +08:00
|
|
|
static bool qt202x_phy_poll(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
2009-11-28 13:34:05 +08:00
|
|
|
bool was_up = efx->link_state.up;
|
|
|
|
|
|
|
|
efx->link_state.up = qt202x_link_ok(efx);
|
|
|
|
efx->link_state.speed = 10000;
|
|
|
|
efx->link_state.fd = true;
|
|
|
|
efx->link_state.fc = efx->wanted_fc;
|
|
|
|
|
2009-12-23 21:47:37 +08:00
|
|
|
if (efx->phy_type == PHY_TYPE_QT2025C)
|
|
|
|
qt2025c_bug17190_workaround(efx);
|
|
|
|
|
2009-11-28 13:34:05 +08:00
|
|
|
return efx->link_state.up != was_up;
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2009-11-29 11:42:41 +08:00
|
|
|
static int qt202x_phy_reconfigure(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
2009-10-23 16:33:42 +08:00
|
|
|
struct qt202x_phy_data *phy_data = efx->phy_data;
|
2008-05-07 20:36:19 +08:00
|
|
|
|
2009-02-27 21:07:33 +08:00
|
|
|
if (efx->phy_type == PHY_TYPE_QT2025C) {
|
2009-12-23 21:48:04 +08:00
|
|
|
int rc = qt2025c_select_phy_mode(efx);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2009-02-27 21:07:33 +08:00
|
|
|
/* There are several different register bits which can
|
|
|
|
* disable TX (and save power) on direct-attach cables
|
|
|
|
* or optical transceivers, varying somewhat between
|
|
|
|
* firmware versions. Only 'static mode' appears to
|
|
|
|
* cover everything. */
|
2009-04-29 16:05:08 +08:00
|
|
|
mdio_set_flag(
|
|
|
|
&efx->mdio, efx->mdio.prtad, MDIO_MMD_PMAPMD,
|
|
|
|
PMA_PMD_FTX_CTRL2_REG, 1 << PMA_PMD_FTX_STATIC_LBN,
|
2009-02-27 21:07:33 +08:00
|
|
|
efx->phy_mode & PHY_MODE_TX_DISABLED ||
|
|
|
|
efx->phy_mode & PHY_MODE_LOW_POWER ||
|
|
|
|
efx->loopback_mode == LOOPBACK_PCS ||
|
|
|
|
efx->loopback_mode == LOOPBACK_PMAPMD);
|
|
|
|
} else {
|
|
|
|
/* Reset the PHY when moving from tx off to tx on */
|
|
|
|
if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
|
|
|
|
(phy_data->phy_mode & PHY_MODE_TX_DISABLED))
|
2009-10-23 16:33:42 +08:00
|
|
|
qt202x_reset_phy(efx);
|
2009-02-27 21:07:33 +08:00
|
|
|
|
2009-04-29 16:05:08 +08:00
|
|
|
efx_mdio_transmit_disable(efx);
|
2009-02-27 21:07:33 +08:00
|
|
|
}
|
2008-05-07 20:36:19 +08:00
|
|
|
|
2009-04-29 16:05:08 +08:00
|
|
|
efx_mdio_phy_reconfigure(efx);
|
2008-05-07 20:36:19 +08:00
|
|
|
|
2008-09-01 19:48:17 +08:00
|
|
|
phy_data->phy_mode = efx->phy_mode;
|
2009-11-29 11:42:41 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2009-10-23 16:33:42 +08:00
|
|
|
static void qt202x_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
|
2009-04-29 16:05:08 +08:00
|
|
|
{
|
|
|
|
mdio45_ethtool_gset(&efx->mdio, ecmd);
|
|
|
|
}
|
2008-04-27 19:55:59 +08:00
|
|
|
|
2009-12-23 21:46:36 +08:00
|
|
|
static void qt202x_phy_remove(struct efx_nic *efx)
|
2008-04-27 19:55:59 +08:00
|
|
|
{
|
2008-05-07 20:36:19 +08:00
|
|
|
/* Free the context block */
|
|
|
|
kfree(efx->phy_data);
|
|
|
|
efx->phy_data = NULL;
|
2008-04-27 19:55:59 +08:00
|
|
|
}
|
|
|
|
|
2012-05-05 08:36:50 +08:00
|
|
|
static int qt202x_phy_get_module_info(struct efx_nic *efx,
|
|
|
|
struct ethtool_modinfo *modinfo)
|
|
|
|
{
|
|
|
|
modinfo->type = ETH_MODULE_SFF_8079;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qt202x_phy_get_module_eeprom(struct efx_nic *efx,
|
|
|
|
struct ethtool_eeprom *ee, u8 *data)
|
|
|
|
{
|
|
|
|
int mmd, reg_base, rc, i;
|
|
|
|
|
|
|
|
if (efx->phy_type == PHY_TYPE_QT2025C) {
|
|
|
|
mmd = MDIO_MMD_PCS;
|
|
|
|
reg_base = 0xd000;
|
|
|
|
} else {
|
|
|
|
mmd = MDIO_MMD_PMAPMD;
|
|
|
|
reg_base = 0x8007;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ee->len; i++) {
|
|
|
|
rc = efx_mdio_read(efx, mmd, reg_base + ee->offset + i);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
data[i] = rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-14 13:50:12 +08:00
|
|
|
const struct efx_phy_operations falcon_qt202x_phy_ops = {
|
2009-11-29 23:08:55 +08:00
|
|
|
.probe = qt202x_phy_probe,
|
2009-10-23 16:33:42 +08:00
|
|
|
.init = qt202x_phy_init,
|
|
|
|
.reconfigure = qt202x_phy_reconfigure,
|
2012-01-06 01:19:45 +08:00
|
|
|
.poll = qt202x_phy_poll,
|
2009-12-23 21:46:36 +08:00
|
|
|
.fini = efx_port_dummy_op_void,
|
2012-01-06 01:19:45 +08:00
|
|
|
.remove = qt202x_phy_remove,
|
2009-10-23 16:33:42 +08:00
|
|
|
.get_settings = qt202x_phy_get_settings,
|
2009-04-29 16:05:08 +08:00
|
|
|
.set_settings = efx_mdio_set_settings,
|
2010-02-03 17:30:50 +08:00
|
|
|
.test_alive = efx_mdio_test_alive,
|
2012-05-05 08:36:50 +08:00
|
|
|
.get_module_eeprom = qt202x_phy_get_module_eeprom,
|
|
|
|
.get_module_info = qt202x_phy_get_module_info,
|
2008-04-27 19:55:59 +08:00
|
|
|
};
|