2009-11-29 15:15:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Driver for Solarflare Solarstorm network controllers and boards
|
2011-02-25 00:01:34 +00:00
|
|
|
* Copyright 2008-2011 Solarflare Communications Inc.
|
2009-11-29 15:15:25 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include "net_driver.h"
|
|
|
|
#include "nic.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "regs.h"
|
|
|
|
#include "mcdi_pcol.h"
|
|
|
|
#include "phy.h"
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Management-Controller-to-Driver Interface
|
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
*/
|
|
|
|
|
2012-12-01 02:21:17 +00:00
|
|
|
#define MCDI_RPC_TIMEOUT (10 * HZ)
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
#define MCDI_PDU(efx) \
|
2011-12-20 23:52:02 +00:00
|
|
|
(efx_port_num(efx) ? MC_SMEM_P1_PDU_OFST : MC_SMEM_P0_PDU_OFST)
|
2009-11-29 15:15:25 +00:00
|
|
|
#define MCDI_DOORBELL(efx) \
|
2011-12-20 23:52:02 +00:00
|
|
|
(efx_port_num(efx) ? MC_SMEM_P1_DOORBELL_OFST : MC_SMEM_P0_DOORBELL_OFST)
|
2011-12-20 23:39:31 +00:00
|
|
|
#define MCDI_STATUS(efx) \
|
|
|
|
(efx_port_num(efx) ? MC_SMEM_P1_STATUS_OFST : MC_SMEM_P0_STATUS_OFST)
|
|
|
|
|
|
|
|
/* A reboot/assertion causes the MCDI status word to be set after the
|
|
|
|
* command word is set or a REBOOT event is sent. If we notice a reboot
|
|
|
|
* via these mechanisms then wait 10ms for the status word to be set. */
|
|
|
|
#define MCDI_STATUS_DELAY_US 100
|
|
|
|
#define MCDI_STATUS_DELAY_COUNT 100
|
|
|
|
#define MCDI_STATUS_SLEEP_MS \
|
|
|
|
(MCDI_STATUS_DELAY_US * MCDI_STATUS_DELAY_COUNT / 1000)
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
#define SEQ_MASK \
|
|
|
|
EFX_MASK32(EFX_WIDTH(MCDI_HEADER_SEQ))
|
|
|
|
|
|
|
|
static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct siena_nic_data *nic_data;
|
|
|
|
EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
|
|
|
|
nic_data = efx->nic_data;
|
|
|
|
return &nic_data->mcdi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_init(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi;
|
|
|
|
|
|
|
|
if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mcdi = efx_mcdi(efx);
|
|
|
|
init_waitqueue_head(&mcdi->wq);
|
|
|
|
spin_lock_init(&mcdi->iface_lock);
|
|
|
|
atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
|
|
|
|
mcdi->mode = MCDI_MODE_POLL;
|
|
|
|
|
|
|
|
(void) efx_mcdi_poll_reboot(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_copyin(struct efx_nic *efx, unsigned cmd,
|
|
|
|
const u8 *inbuf, size_t inlen)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
2011-09-01 12:09:29 +00:00
|
|
|
unsigned pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
|
|
|
|
unsigned doorbell = FR_CZ_MC_TREG_SMEM + MCDI_DOORBELL(efx);
|
2009-11-29 15:15:25 +00:00
|
|
|
unsigned int i;
|
|
|
|
efx_dword_t hdr;
|
|
|
|
u32 xflags, seqno;
|
|
|
|
|
|
|
|
BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
|
2011-12-20 23:52:02 +00:00
|
|
|
BUG_ON(inlen & 3 || inlen >= MC_SMEM_PDU_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
seqno = mcdi->seqno & SEQ_MASK;
|
|
|
|
xflags = 0;
|
|
|
|
if (mcdi->mode == MCDI_MODE_EVENTS)
|
|
|
|
xflags |= MCDI_HEADER_XFLAGS_EVREQ;
|
|
|
|
|
|
|
|
EFX_POPULATE_DWORD_6(hdr,
|
|
|
|
MCDI_HEADER_RESPONSE, 0,
|
|
|
|
MCDI_HEADER_RESYNC, 1,
|
|
|
|
MCDI_HEADER_CODE, cmd,
|
|
|
|
MCDI_HEADER_DATALEN, inlen,
|
|
|
|
MCDI_HEADER_SEQ, seqno,
|
|
|
|
MCDI_HEADER_XFLAGS, xflags);
|
|
|
|
|
2011-09-01 12:09:29 +00:00
|
|
|
efx_writed(efx, &hdr, pdu);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
2011-05-11 16:41:18 +00:00
|
|
|
for (i = 0; i < inlen; i += 4)
|
2011-09-01 12:09:29 +00:00
|
|
|
_efx_writed(efx, *((__le32 *)(inbuf + i)), pdu + 4 + i);
|
|
|
|
|
|
|
|
/* Ensure the payload is written out before the header */
|
|
|
|
wmb();
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
/* ring the doorbell with a distinctive value */
|
2011-09-01 12:09:29 +00:00
|
|
|
_efx_writed(efx, (__force __le32) 0x45789abc, doorbell);
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_copyout(struct efx_nic *efx, u8 *outbuf, size_t outlen)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
2011-09-01 12:09:29 +00:00
|
|
|
unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
|
2009-11-29 15:15:25 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
|
2011-12-20 23:52:02 +00:00
|
|
|
BUG_ON(outlen & 3 || outlen >= MC_SMEM_PDU_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < outlen; i += 4)
|
2011-09-01 12:09:29 +00:00
|
|
|
*((__le32 *)(outbuf + i)) = _efx_readd(efx, pdu + 4 + i);
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_poll(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
2012-12-01 02:21:17 +00:00
|
|
|
unsigned long time, finish;
|
2009-11-29 15:15:25 +00:00
|
|
|
unsigned int respseq, respcmd, error;
|
2011-09-01 12:09:29 +00:00
|
|
|
unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
|
2009-11-29 15:15:25 +00:00
|
|
|
unsigned int rc, spins;
|
|
|
|
efx_dword_t reg;
|
|
|
|
|
|
|
|
/* Check for a reboot atomically with respect to efx_mcdi_copyout() */
|
2010-02-19 13:29:27 +00:00
|
|
|
rc = -efx_mcdi_poll_reboot(efx);
|
2009-11-29 15:15:25 +00:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Poll for completion. Poll quickly (once a us) for the 1st jiffy,
|
|
|
|
* because generally mcdi responses are fast. After that, back off
|
|
|
|
* and poll once a jiffy (approximately)
|
|
|
|
*/
|
|
|
|
spins = TICK_USEC;
|
2012-12-01 02:21:17 +00:00
|
|
|
finish = jiffies + MCDI_RPC_TIMEOUT;
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (spins != 0) {
|
|
|
|
--spins;
|
|
|
|
udelay(1);
|
2010-01-13 04:34:25 +00:00
|
|
|
} else {
|
|
|
|
schedule_timeout_uninterruptible(1);
|
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
2012-12-01 02:21:17 +00:00
|
|
|
time = jiffies;
|
2009-11-29 15:15:25 +00:00
|
|
|
|
2011-09-01 12:09:29 +00:00
|
|
|
rmb();
|
|
|
|
efx_readd(efx, ®, pdu);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
/* All 1's indicates that shared memory is in reset (and is
|
|
|
|
* not a valid header). Wait for it to come out reset before
|
|
|
|
* completing the command */
|
|
|
|
if (EFX_DWORD_FIELD(reg, EFX_DWORD_0) != 0xffffffff &&
|
|
|
|
EFX_DWORD_FIELD(reg, MCDI_HEADER_RESPONSE))
|
|
|
|
break;
|
|
|
|
|
2012-12-01 02:21:17 +00:00
|
|
|
if (time_after(time, finish))
|
2009-11-29 15:15:25 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcdi->resplen = EFX_DWORD_FIELD(reg, MCDI_HEADER_DATALEN);
|
|
|
|
respseq = EFX_DWORD_FIELD(reg, MCDI_HEADER_SEQ);
|
|
|
|
respcmd = EFX_DWORD_FIELD(reg, MCDI_HEADER_CODE);
|
|
|
|
error = EFX_DWORD_FIELD(reg, MCDI_HEADER_ERROR);
|
|
|
|
|
|
|
|
if (error && mcdi->resplen == 0) {
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "MC rebooted\n");
|
2009-11-29 15:15:25 +00:00
|
|
|
rc = EIO;
|
|
|
|
} else if ((respseq ^ mcdi->seqno) & SEQ_MASK) {
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"MC response mismatch tx seq 0x%x rx seq 0x%x\n",
|
|
|
|
respseq, mcdi->seqno);
|
2009-11-29 15:15:25 +00:00
|
|
|
rc = EIO;
|
|
|
|
} else if (error) {
|
2011-09-01 12:09:29 +00:00
|
|
|
efx_readd(efx, ®, pdu + 4);
|
2009-11-29 15:15:25 +00:00
|
|
|
switch (EFX_DWORD_FIELD(reg, EFX_DWORD_0)) {
|
|
|
|
#define TRANSLATE_ERROR(name) \
|
|
|
|
case MC_CMD_ERR_ ## name: \
|
|
|
|
rc = name; \
|
|
|
|
break
|
|
|
|
TRANSLATE_ERROR(ENOENT);
|
|
|
|
TRANSLATE_ERROR(EINTR);
|
|
|
|
TRANSLATE_ERROR(EACCES);
|
|
|
|
TRANSLATE_ERROR(EBUSY);
|
|
|
|
TRANSLATE_ERROR(EINVAL);
|
|
|
|
TRANSLATE_ERROR(EDEADLK);
|
|
|
|
TRANSLATE_ERROR(ENOSYS);
|
|
|
|
TRANSLATE_ERROR(ETIME);
|
|
|
|
#undef TRANSLATE_ERROR
|
|
|
|
default:
|
|
|
|
rc = EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mcdi->resprc = rc;
|
|
|
|
if (rc)
|
|
|
|
mcdi->resplen = 0;
|
|
|
|
|
|
|
|
/* Return rc=0 like wait_event_timeout() */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-01 19:58:35 +00:00
|
|
|
/* Test and clear MC-rebooted flag for this port/function; reset
|
|
|
|
* software state as necessary.
|
|
|
|
*/
|
2009-11-29 15:15:25 +00:00
|
|
|
int efx_mcdi_poll_reboot(struct efx_nic *efx)
|
|
|
|
{
|
2011-12-20 23:39:31 +00:00
|
|
|
unsigned int addr = FR_CZ_MC_TREG_SMEM + MCDI_STATUS(efx);
|
2009-11-29 15:15:25 +00:00
|
|
|
efx_dword_t reg;
|
|
|
|
uint32_t value;
|
|
|
|
|
|
|
|
if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
|
|
|
|
return false;
|
|
|
|
|
2011-09-01 12:09:29 +00:00
|
|
|
efx_readd(efx, ®, addr);
|
2009-11-29 15:15:25 +00:00
|
|
|
value = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
|
|
|
|
|
|
|
|
if (value == 0)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-01 19:58:35 +00:00
|
|
|
/* MAC statistics have been cleared on the NIC; clear our copy
|
|
|
|
* so that efx_update_diff_stat() can continue to work.
|
|
|
|
*/
|
|
|
|
memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
|
|
|
|
|
2009-11-29 15:15:25 +00:00
|
|
|
EFX_ZERO_DWORD(reg);
|
2011-09-01 12:09:29 +00:00
|
|
|
efx_writed(efx, ®, addr);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
if (value == MC_STATUS_DWORD_ASSERT)
|
|
|
|
return -EINTR;
|
|
|
|
else
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi)
|
|
|
|
{
|
|
|
|
/* Wait until the interface becomes QUIESCENT and we win the race
|
|
|
|
* to mark it RUNNING. */
|
|
|
|
wait_event(mcdi->wq,
|
|
|
|
atomic_cmpxchg(&mcdi->state,
|
|
|
|
MCDI_STATE_QUIESCENT,
|
|
|
|
MCDI_STATE_RUNNING)
|
|
|
|
== MCDI_STATE_QUIESCENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efx_mcdi_await_completion(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
|
|
|
|
|
|
|
if (wait_event_timeout(
|
|
|
|
mcdi->wq,
|
|
|
|
atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
|
2012-12-01 02:21:17 +00:00
|
|
|
MCDI_RPC_TIMEOUT) == 0)
|
2009-11-29 15:15:25 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
/* Check if efx_mcdi_set_mode() switched us back to polled completions.
|
|
|
|
* In which case, poll for completions directly. If efx_mcdi_ev_cpl()
|
|
|
|
* completed the request first, then we'll just end up completing the
|
|
|
|
* request again, which is safe.
|
|
|
|
*
|
|
|
|
* We need an smp_rmb() to synchronise with efx_mcdi_mode_poll(), which
|
|
|
|
* wait_event_timeout() implicitly provides.
|
|
|
|
*/
|
|
|
|
if (mcdi->mode == MCDI_MODE_POLL)
|
|
|
|
return efx_mcdi_poll(efx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
|
|
|
|
{
|
|
|
|
/* If the interface is RUNNING, then move to COMPLETED and wake any
|
|
|
|
* waiters. If the interface isn't in RUNNING then we've received a
|
|
|
|
* duplicate completion after we've already transitioned back to
|
|
|
|
* QUIESCENT. [A subsequent invocation would increment seqno, so would
|
|
|
|
* have failed the seqno check].
|
|
|
|
*/
|
|
|
|
if (atomic_cmpxchg(&mcdi->state,
|
|
|
|
MCDI_STATE_RUNNING,
|
|
|
|
MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) {
|
|
|
|
wake_up(&mcdi->wq);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
|
|
|
|
{
|
|
|
|
atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
|
|
|
|
wake_up(&mcdi->wq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno,
|
|
|
|
unsigned int datalen, unsigned int errno)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
|
|
|
bool wake = false;
|
|
|
|
|
|
|
|
spin_lock(&mcdi->iface_lock);
|
|
|
|
|
|
|
|
if ((seqno ^ mcdi->seqno) & SEQ_MASK) {
|
|
|
|
if (mcdi->credits)
|
|
|
|
/* The request has been cancelled */
|
|
|
|
--mcdi->credits;
|
|
|
|
else
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"MC response mismatch tx seq 0x%x rx "
|
|
|
|
"seq 0x%x\n", seqno, mcdi->seqno);
|
2009-11-29 15:15:25 +00:00
|
|
|
} else {
|
|
|
|
mcdi->resprc = errno;
|
|
|
|
mcdi->resplen = datalen;
|
|
|
|
|
|
|
|
wake = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&mcdi->iface_lock);
|
|
|
|
|
|
|
|
if (wake)
|
|
|
|
efx_mcdi_complete(mcdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
|
|
|
|
const u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen,
|
|
|
|
size_t *outlen_actual)
|
2012-07-16 16:40:47 +00:00
|
|
|
{
|
|
|
|
efx_mcdi_rpc_start(efx, cmd, inbuf, inlen);
|
|
|
|
return efx_mcdi_rpc_finish(efx, cmd, inlen,
|
|
|
|
outbuf, outlen, outlen_actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, const u8 *inbuf,
|
|
|
|
size_t inlen)
|
2009-11-29 15:15:25 +00:00
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
2012-07-16 16:40:47 +00:00
|
|
|
|
2009-11-29 15:15:25 +00:00
|
|
|
BUG_ON(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
|
|
|
|
|
|
|
|
efx_mcdi_acquire(mcdi);
|
|
|
|
|
|
|
|
/* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
|
|
|
|
spin_lock_bh(&mcdi->iface_lock);
|
|
|
|
++mcdi->seqno;
|
|
|
|
spin_unlock_bh(&mcdi->iface_lock);
|
|
|
|
|
|
|
|
efx_mcdi_copyin(efx, cmd, inbuf, inlen);
|
2012-07-16 16:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
|
|
|
|
u8 *outbuf, size_t outlen, size_t *outlen_actual)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUG_ON(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
if (mcdi->mode == MCDI_MODE_POLL)
|
|
|
|
rc = efx_mcdi_poll(efx);
|
|
|
|
else
|
|
|
|
rc = efx_mcdi_await_completion(efx);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
/* Close the race with efx_mcdi_ev_cpl() executing just too late
|
|
|
|
* and completing a request we've just cancelled, by ensuring
|
|
|
|
* that the seqno check therein fails.
|
|
|
|
*/
|
|
|
|
spin_lock_bh(&mcdi->iface_lock);
|
|
|
|
++mcdi->seqno;
|
|
|
|
++mcdi->credits;
|
|
|
|
spin_unlock_bh(&mcdi->iface_lock);
|
|
|
|
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"MC command 0x%x inlen %d mode %d timed out\n",
|
|
|
|
cmd, (int)inlen, mcdi->mode);
|
2009-11-29 15:15:25 +00:00
|
|
|
} else {
|
|
|
|
size_t resplen;
|
|
|
|
|
|
|
|
/* At the very least we need a memory barrier here to ensure
|
|
|
|
* we pick up changes from efx_mcdi_ev_cpl(). Protect against
|
|
|
|
* a spurious efx_mcdi_ev_cpl() running concurrently by
|
|
|
|
* acquiring the iface_lock. */
|
|
|
|
spin_lock_bh(&mcdi->iface_lock);
|
|
|
|
rc = -mcdi->resprc;
|
|
|
|
resplen = mcdi->resplen;
|
|
|
|
spin_unlock_bh(&mcdi->iface_lock);
|
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
efx_mcdi_copyout(efx, outbuf,
|
|
|
|
min(outlen, mcdi->resplen + 3) & ~0x3);
|
|
|
|
if (outlen_actual != NULL)
|
|
|
|
*outlen_actual = resplen;
|
|
|
|
} else if (cmd == MC_CMD_REBOOT && rc == -EIO)
|
|
|
|
; /* Don't reset if MC_CMD_REBOOT returns EIO */
|
|
|
|
else if (rc == -EIO || rc == -EINTR) {
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "MC fatal error %d\n",
|
|
|
|
-rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE);
|
|
|
|
} else
|
2010-12-02 13:46:09 +00:00
|
|
|
netif_dbg(efx, hw, efx->net_dev,
|
2010-06-23 11:30:07 +00:00
|
|
|
"MC command 0x%x inlen %d failed rc=%d\n",
|
|
|
|
cmd, (int)inlen, -rc);
|
2011-12-20 23:39:31 +00:00
|
|
|
|
|
|
|
if (rc == -EIO || rc == -EINTR) {
|
|
|
|
msleep(MCDI_STATUS_SLEEP_MS);
|
|
|
|
efx_mcdi_poll_reboot(efx);
|
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
efx_mcdi_release(mcdi);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_mode_poll(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi;
|
|
|
|
|
|
|
|
if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mcdi = efx_mcdi(efx);
|
|
|
|
if (mcdi->mode == MCDI_MODE_POLL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We can switch from event completion to polled completion, because
|
|
|
|
* mcdi requests are always completed in shared memory. We do this by
|
|
|
|
* switching the mode to POLL'd then completing the request.
|
|
|
|
* efx_mcdi_await_completion() will then call efx_mcdi_poll().
|
|
|
|
*
|
|
|
|
* We need an smp_wmb() to synchronise with efx_mcdi_await_completion(),
|
|
|
|
* which efx_mcdi_complete() provides for us.
|
|
|
|
*/
|
|
|
|
mcdi->mode = MCDI_MODE_POLL;
|
|
|
|
|
|
|
|
efx_mcdi_complete(mcdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_mcdi_mode_event(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi;
|
|
|
|
|
|
|
|
if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mcdi = efx_mcdi(efx);
|
|
|
|
|
|
|
|
if (mcdi->mode == MCDI_MODE_EVENTS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We can't switch from polled to event completion in the middle of a
|
|
|
|
* request, because the completion method is specified in the request.
|
|
|
|
* So acquire the interface to serialise the requestors. We don't need
|
|
|
|
* to acquire the iface_lock to change the mode here, but we do need a
|
|
|
|
* write memory barrier ensure that efx_mcdi_rpc() sees it, which
|
|
|
|
* efx_mcdi_acquire() provides.
|
|
|
|
*/
|
|
|
|
efx_mcdi_acquire(mcdi);
|
|
|
|
mcdi->mode = MCDI_MODE_EVENTS;
|
|
|
|
efx_mcdi_release(mcdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_mcdi_ev_death(struct efx_nic *efx, int rc)
|
|
|
|
{
|
|
|
|
struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
|
|
|
|
|
|
|
|
/* If there is an outstanding MCDI request, it has been terminated
|
|
|
|
* either by a BADASSERT or REBOOT event. If the mcdi interface is
|
|
|
|
* in polled mode, then do nothing because the MC reboot handler will
|
|
|
|
* set the header correctly. However, if the mcdi interface is waiting
|
|
|
|
* for a CMDDONE event it won't receive it [and since all MCDI events
|
|
|
|
* are sent to the same queue, we can't be racing with
|
|
|
|
* efx_mcdi_ev_cpl()]
|
|
|
|
*
|
|
|
|
* There's a race here with efx_mcdi_rpc(), because we might receive
|
|
|
|
* a REBOOT event *before* the request has been copied out. In polled
|
2011-03-31 01:57:33 +00:00
|
|
|
* mode (during startup) this is irrelevant, because efx_mcdi_complete()
|
2009-11-29 15:15:25 +00:00
|
|
|
* is ignored. In event mode, this condition is just an edge-case of
|
|
|
|
* receiving a REBOOT event after posting the MCDI request. Did the mc
|
|
|
|
* reboot before or after the copyout? The best we can do always is
|
|
|
|
* just return failure.
|
|
|
|
*/
|
|
|
|
spin_lock(&mcdi->iface_lock);
|
|
|
|
if (efx_mcdi_complete(mcdi)) {
|
|
|
|
if (mcdi->mode == MCDI_MODE_EVENTS) {
|
|
|
|
mcdi->resprc = rc;
|
|
|
|
mcdi->resplen = 0;
|
2010-12-02 13:46:55 +00:00
|
|
|
++mcdi->credits;
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
2011-12-20 23:39:31 +00:00
|
|
|
} else {
|
|
|
|
int count;
|
|
|
|
|
2009-11-29 15:15:25 +00:00
|
|
|
/* Nobody was waiting for an MCDI request, so trigger a reset */
|
|
|
|
efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE);
|
|
|
|
|
2011-12-20 23:39:31 +00:00
|
|
|
/* Consume the status word since efx_mcdi_rpc_finish() won't */
|
|
|
|
for (count = 0; count < MCDI_STATUS_DELAY_COUNT; ++count) {
|
|
|
|
if (efx_mcdi_poll_reboot(efx))
|
|
|
|
break;
|
|
|
|
udelay(MCDI_STATUS_DELAY_US);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-29 15:15:25 +00:00
|
|
|
spin_unlock(&mcdi->iface_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static 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);
|
|
|
|
EFX_BUG_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called from falcon_process_eventq for MCDI events */
|
|
|
|
void efx_mcdi_process_event(struct efx_channel *channel,
|
|
|
|
efx_qword_t *event)
|
|
|
|
{
|
|
|
|
struct efx_nic *efx = channel->efx;
|
|
|
|
int code = EFX_QWORD_FIELD(*event, MCDI_EVENT_CODE);
|
|
|
|
u32 data = EFX_QWORD_FIELD(*event, MCDI_EVENT_DATA);
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case MCDI_EVENT_CODE_BADSSERT:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"MC watchdog or assertion failure at 0x%x\n", data);
|
2009-11-29 15:15:25 +00:00
|
|
|
efx_mcdi_ev_death(efx, EINTR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCDI_EVENT_CODE_PMNOTICE:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_info(efx, wol, efx->net_dev, "MCDI PM event.\n");
|
2009-11-29 15:15:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MCDI_EVENT_CODE_CMDDONE:
|
|
|
|
efx_mcdi_ev_cpl(efx,
|
|
|
|
MCDI_EVENT_FIELD(*event, CMDDONE_SEQ),
|
|
|
|
MCDI_EVENT_FIELD(*event, CMDDONE_DATALEN),
|
|
|
|
MCDI_EVENT_FIELD(*event, CMDDONE_ERRNO));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCDI_EVENT_CODE_LINKCHANGE:
|
|
|
|
efx_mcdi_process_link_change(efx, event);
|
|
|
|
break;
|
|
|
|
case MCDI_EVENT_CODE_SENSOREVT:
|
|
|
|
efx_mcdi_sensor_event(efx, event);
|
|
|
|
break;
|
|
|
|
case MCDI_EVENT_CODE_SCHEDERR:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_info(efx, hw, efx->net_dev,
|
|
|
|
"MC Scheduler error address=0x%x\n", data);
|
2009-11-29 15:15:25 +00:00
|
|
|
break;
|
|
|
|
case MCDI_EVENT_CODE_REBOOT:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_info(efx, hw, efx->net_dev, "MC Reboot\n");
|
2009-11-29 15:15:25 +00:00
|
|
|
efx_mcdi_ev_death(efx, EIO);
|
|
|
|
break;
|
|
|
|
case MCDI_EVENT_CODE_MAC_STATS_DMA:
|
|
|
|
/* MAC stats are gather lazily. We can ignore this. */
|
|
|
|
break;
|
sfc: Add SR-IOV back-end support for SFC9000 family
On the SFC9000 family, each port has 1024 Virtual Interfaces (VIs),
each with an RX queue, a TX queue, an event queue and a mailbox
register. These may be assigned to up to 127 SR-IOV virtual functions
per port, with up to 64 VIs per VF.
We allocate an extra channel (IRQ and event queue only) to receive
requests from VF drivers.
There is a per-port limit of 4 concurrent RX queue flushes, and queue
flushes may be initiated by the MC in response to a Function Level
Reset (FLR) of a VF. Therefore, when SR-IOV is in use, we submit all
flush requests via the MC.
The RSS indirection table is shared with VFs, so the number of RX
queues used in the PF is limited to the number of VIs per VF.
This is almost entirely the work of Steve Hodgson, formerly
shodgson@solarflare.com.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-02-14 00:48:07 +00:00
|
|
|
case MCDI_EVENT_CODE_FLR:
|
|
|
|
efx_sriov_flr(efx, MCDI_EVENT_FIELD(*event, FLR_VF));
|
|
|
|
break;
|
2012-09-03 10:09:36 +00:00
|
|
|
case MCDI_EVENT_CODE_PTP_RX:
|
|
|
|
case MCDI_EVENT_CODE_PTP_FAULT:
|
|
|
|
case MCDI_EVENT_CODE_PTP_PPS:
|
|
|
|
efx_ptp_event(efx, event);
|
|
|
|
break;
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
default:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "Unknown MCDI event 0x%x\n",
|
|
|
|
code);
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Specific request functions
|
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
*/
|
|
|
|
|
2011-02-24 23:57:47 +00:00
|
|
|
void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len)
|
2009-11-29 15:15:25 +00:00
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlength;
|
|
|
|
const __le16 *ver_words;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_VERSION_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlength);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
2011-12-20 00:44:06 +00:00
|
|
|
if (outlength < MC_CMD_GET_VERSION_OUT_LEN) {
|
2010-04-28 09:27:14 +00:00
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ver_words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_OUT_VERSION);
|
2011-02-24 23:57:47 +00:00
|
|
|
snprintf(buf, len, "%u.%u.%u.%u",
|
|
|
|
le16_to_cpu(ver_words[0]), le16_to_cpu(ver_words[1]),
|
|
|
|
le16_to_cpu(ver_words[2]), le16_to_cpu(ver_words[3]));
|
|
|
|
return;
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2011-02-24 23:57:47 +00:00
|
|
|
buf[0] = 0;
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
|
|
|
|
bool *was_attached)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_DRV_ATTACH_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_DRV_ATTACH_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_NEW_STATE,
|
|
|
|
driver_operating ? 1 : 0);
|
|
|
|
MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_UPDATE, 1);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_DRV_ATTACH, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
if (outlen < MC_CMD_DRV_ATTACH_OUT_LEN) {
|
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
if (was_attached != NULL)
|
|
|
|
*was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
|
2010-07-14 14:36:19 +00:00
|
|
|
u16 *fw_subtype_list, u32 *capabilities)
|
2009-11-29 15:15:25 +00:00
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_BOARD_CFG_OUT_LENMAX);
|
2012-09-06 23:58:10 +00:00
|
|
|
size_t outlen, offset, i;
|
2009-11-29 15:15:25 +00:00
|
|
|
int port_num = efx_port_num(efx);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
2011-12-20 00:44:06 +00:00
|
|
|
if (outlen < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) {
|
2010-04-28 09:27:14 +00:00
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = (port_num)
|
|
|
|
? MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1_OFST
|
|
|
|
: MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0_OFST;
|
|
|
|
if (mac_address)
|
|
|
|
memcpy(mac_address, outbuf + offset, ETH_ALEN);
|
2012-09-06 23:58:10 +00:00
|
|
|
if (fw_subtype_list) {
|
2011-07-04 23:04:42 +00:00
|
|
|
/* Byte-swap and truncate or zero-pad as necessary */
|
2012-09-06 23:58:10 +00:00
|
|
|
offset = MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_OFST;
|
|
|
|
for (i = 0;
|
2011-07-04 23:04:42 +00:00
|
|
|
i < MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MAXNUM;
|
2012-09-06 23:58:10 +00:00
|
|
|
i++) {
|
|
|
|
fw_subtype_list[i] =
|
2011-07-04 23:04:42 +00:00
|
|
|
(offset + 2 <= outlen) ?
|
|
|
|
le16_to_cpup((__le16 *)(outbuf + offset)) : 0;
|
2012-09-06 23:58:10 +00:00
|
|
|
offset += 2;
|
|
|
|
}
|
|
|
|
}
|
2010-07-14 14:36:19 +00:00
|
|
|
if (capabilities) {
|
|
|
|
if (port_num)
|
|
|
|
*capabilities = MCDI_DWORD(outbuf,
|
|
|
|
GET_BOARD_CFG_OUT_CAPABILITIES_PORT1);
|
|
|
|
else
|
|
|
|
*capabilities = MCDI_DWORD(outbuf,
|
|
|
|
GET_BOARD_CFG_OUT_CAPABILITIES_PORT0);
|
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d len=%d\n",
|
|
|
|
__func__, rc, (int)outlen);
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_LOG_CTRL_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
u32 dest = 0;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (uart)
|
|
|
|
dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_UART;
|
|
|
|
if (evq)
|
|
|
|
dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST, dest);
|
|
|
|
MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST_EVQ, dest_evq);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_LOG_CTRL_OUT_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_LOG_CTRL, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TYPES_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_NVRAM_TYPES_IN_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TYPES, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
if (outlen < MC_CMD_NVRAM_TYPES_OUT_LEN) {
|
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
*nvram_types_out = MCDI_DWORD(outbuf, NVRAM_TYPES_OUT_TYPES);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
|
|
|
|
__func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
|
|
|
|
size_t *size_out, size_t *erase_size_out,
|
|
|
|
bool *protected_out)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_INFO_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_INFO_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_INFO_IN_TYPE, type);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_INFO, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
if (outlen < MC_CMD_NVRAM_INFO_OUT_LEN) {
|
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
2010-04-28 09:27:14 +00:00
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
*size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_SIZE);
|
|
|
|
*erase_size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_ERASESIZE);
|
|
|
|
*protected_out = !!(MCDI_DWORD(outbuf, NVRAM_INFO_OUT_FLAGS) &
|
2011-12-20 00:44:06 +00:00
|
|
|
(1 << MC_CMD_NVRAM_INFO_OUT_PROTECTED_LBN));
|
2009-11-29 15:15:25 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_update_start(struct efx_nic *efx, unsigned int type)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_START_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_START_IN_TYPE, type);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_START_OUT_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_START, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
|
|
|
|
loff_t offset, u8 *buffer, size_t length)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_READ_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf,
|
|
|
|
MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX));
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_TYPE, type);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_OFFSET, offset);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_LENGTH, length);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_READ, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(buffer, MCDI_PTR(outbuf, NVRAM_READ_OUT_READ_BUFFER), length);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
|
|
|
|
loff_t offset, const u8 *buffer, size_t length)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf,
|
|
|
|
MC_CMD_NVRAM_WRITE_IN_LEN(EFX_MCDI_NVRAM_LEN_MAX));
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_TYPE, type);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_OFFSET, offset);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_LENGTH, length);
|
|
|
|
memcpy(MCDI_PTR(inbuf, NVRAM_WRITE_IN_WRITE_BUFFER), buffer, length);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_NVRAM_WRITE_OUT_LEN != 0);
|
|
|
|
|
2010-01-25 23:49:59 +00:00
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_WRITE, inbuf,
|
|
|
|
ALIGN(MC_CMD_NVRAM_WRITE_IN_LEN(length), 4),
|
2009-11-29 15:15:25 +00:00
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
|
|
|
|
loff_t offset, size_t length)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_ERASE_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_TYPE, type);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_OFFSET, offset);
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_LENGTH, length);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_NVRAM_ERASE_OUT_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_ERASE, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_update_finish(struct efx_nic *efx, unsigned int type)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_FINISH_IN_TYPE, type);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN != 0);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_FINISH, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-02-03 09:31:01 +00:00
|
|
|
static int efx_mcdi_nvram_test(struct efx_nic *efx, unsigned int type)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_TEST_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TEST_OUT_LEN);
|
2010-02-03 09:31:01 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, NVRAM_TEST_IN_TYPE, type);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TEST, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), NULL);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
switch (MCDI_DWORD(outbuf, NVRAM_TEST_OUT_RESULT)) {
|
|
|
|
case MC_CMD_NVRAM_TEST_PASS:
|
|
|
|
case MC_CMD_NVRAM_TEST_NOTSUPP:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_nvram_test_all(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
u32 nvram_types;
|
|
|
|
unsigned int type;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_nvram_types(efx, &nvram_types);
|
|
|
|
if (rc)
|
2010-04-28 09:28:36 +00:00
|
|
|
goto fail1;
|
2010-02-03 09:31:01 +00:00
|
|
|
|
|
|
|
type = 0;
|
|
|
|
while (nvram_types != 0) {
|
|
|
|
if (nvram_types & 1) {
|
|
|
|
rc = efx_mcdi_nvram_test(efx, type);
|
|
|
|
if (rc)
|
2010-04-28 09:28:36 +00:00
|
|
|
goto fail2;
|
2010-02-03 09:31:01 +00:00
|
|
|
}
|
|
|
|
type++;
|
|
|
|
nvram_types >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-04-28 09:28:36 +00:00
|
|
|
|
|
|
|
fail2:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed type=%u\n",
|
|
|
|
__func__, type);
|
2010-04-28 09:28:36 +00:00
|
|
|
fail1:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2010-04-28 09:28:36 +00:00
|
|
|
return rc;
|
2010-02-03 09:31:01 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 09:30:17 +00:00
|
|
|
static int efx_mcdi_read_assertion(struct efx_nic *efx)
|
2009-11-29 15:15:25 +00:00
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_ASSERTS_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_ASSERTS_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
unsigned int flags, index, ofst;
|
|
|
|
const char *reason;
|
|
|
|
size_t outlen;
|
|
|
|
int retry;
|
|
|
|
int rc;
|
|
|
|
|
2010-02-03 09:30:17 +00:00
|
|
|
/* Attempt to read any stored assertion state before we reboot
|
|
|
|
* the mcfw out of the assertion handler. Retry twice, once
|
2009-11-29 15:15:25 +00:00
|
|
|
* because a boot-time assertion might cause this command to fail
|
|
|
|
* with EINTR. And once again because GET_ASSERTS can race with
|
|
|
|
* MC_CMD_REBOOT running on the other port. */
|
|
|
|
retry = 2;
|
|
|
|
do {
|
2010-02-03 09:30:17 +00:00
|
|
|
MCDI_SET_DWORD(inbuf, GET_ASSERTS_IN_CLEAR, 1);
|
2009-11-29 15:15:25 +00:00
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_GET_ASSERTS,
|
2010-02-03 09:30:17 +00:00
|
|
|
inbuf, MC_CMD_GET_ASSERTS_IN_LEN,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
2009-11-29 15:15:25 +00:00
|
|
|
} while ((rc == -EINTR || rc == -EIO) && retry-- > 0);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (outlen < MC_CMD_GET_ASSERTS_OUT_LEN)
|
2010-04-28 09:27:14 +00:00
|
|
|
return -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
|
2010-02-03 09:30:17 +00:00
|
|
|
/* Print out any recorded assertion state */
|
|
|
|
flags = MCDI_DWORD(outbuf, GET_ASSERTS_OUT_GLOBAL_FLAGS);
|
2009-11-29 15:15:25 +00:00
|
|
|
if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL)
|
|
|
|
? "system-level assertion"
|
|
|
|
: (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL)
|
|
|
|
? "thread-level assertion"
|
|
|
|
: (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED)
|
|
|
|
? "watchdog reset"
|
|
|
|
: "unknown assertion";
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev,
|
|
|
|
"MCPU %s at PC = 0x%.8x in thread 0x%.8x\n", reason,
|
|
|
|
MCDI_DWORD(outbuf, GET_ASSERTS_OUT_SAVED_PC_OFFS),
|
|
|
|
MCDI_DWORD(outbuf, GET_ASSERTS_OUT_THREAD_OFFS));
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
/* Print out the registers */
|
|
|
|
ofst = MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_OFST;
|
|
|
|
for (index = 1; index < 32; index++) {
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "R%.2d (?): 0x%.8x\n", index,
|
2010-02-03 09:30:17 +00:00
|
|
|
MCDI_DWORD2(outbuf, ofst));
|
2009-11-29 15:15:25 +00:00
|
|
|
ofst += sizeof(efx_dword_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 09:30:17 +00:00
|
|
|
static void efx_mcdi_exit_assertion(struct efx_nic *efx)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN);
|
2010-02-03 09:30:17 +00:00
|
|
|
|
2012-07-02 22:37:40 +00:00
|
|
|
/* If the MC is running debug firmware, it might now be
|
|
|
|
* waiting for a debugger to attach, but we just want it to
|
|
|
|
* reboot. We set a flag that makes the command a no-op if it
|
|
|
|
* has already done so. We don't know what return code to
|
|
|
|
* expect (0 or -EIO), so ignore it.
|
|
|
|
*/
|
2010-02-03 09:30:17 +00:00
|
|
|
BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
|
|
|
|
MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS,
|
|
|
|
MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION);
|
2012-07-02 22:37:40 +00:00
|
|
|
(void) efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, MC_CMD_REBOOT_IN_LEN,
|
|
|
|
NULL, 0, NULL);
|
2010-02-03 09:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_handle_assertion(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_read_assertion(efx);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
efx_mcdi_exit_assertion(efx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-29 15:15:25 +00:00
|
|
|
void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_ID_LED_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(EFX_LED_OFF != MC_CMD_LED_OFF);
|
|
|
|
BUILD_BUG_ON(EFX_LED_ON != MC_CMD_LED_ON);
|
|
|
|
BUILD_BUG_ON(EFX_LED_DEFAULT != MC_CMD_LED_DEFAULT);
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_SET_ID_LED_OUT_LEN != 0);
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, SET_ID_LED_IN_STATE, mode);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_SET_ID_LED, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
|
|
|
|
__func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_reset_port(struct efx_nic *efx)
|
|
|
|
{
|
2011-12-20 00:44:06 +00:00
|
|
|
int rc = efx_mcdi_rpc(efx, MC_CMD_ENTITY_RESET, NULL, 0, NULL, 0, NULL);
|
2009-11-29 15:15:25 +00:00
|
|
|
if (rc)
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
|
|
|
|
__func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int efx_mcdi_reset_mc(struct efx_nic *efx)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
|
|
|
|
MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS, 0);
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
/* White is black, and up is down */
|
|
|
|
if (rc == -EIO)
|
|
|
|
return 0;
|
|
|
|
if (rc == 0)
|
|
|
|
rc = -EIO;
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-18 05:27:31 +00:00
|
|
|
static int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type,
|
|
|
|
const u8 *mac, int *id_out)
|
2009-11-29 15:15:25 +00:00
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_SET_IN_LEN);
|
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_SET_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type);
|
|
|
|
MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE,
|
|
|
|
MC_CMD_FILTER_MODE_SIMPLE);
|
|
|
|
memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf),
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (outlen < MC_CMD_WOL_FILTER_SET_OUT_LEN) {
|
2010-04-28 09:27:14 +00:00
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_SET_OUT_FILTER_ID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
*id_out = -1;
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac, int *id_out)
|
|
|
|
{
|
|
|
|
return efx_mcdi_wol_filter_set(efx, MC_CMD_WOL_TYPE_MAGIC, mac, id_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_GET_OUT_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
size_t outlen;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_GET, NULL, 0,
|
|
|
|
outbuf, sizeof(outbuf), &outlen);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (outlen < MC_CMD_WOL_FILTER_GET_OUT_LEN) {
|
2010-04-28 09:27:14 +00:00
|
|
|
rc = -EIO;
|
2009-11-29 15:15:25 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_GET_OUT_FILTER_ID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
*id_out = -1;
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id)
|
|
|
|
{
|
2012-09-14 16:30:10 +00:00
|
|
|
MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_REMOVE_IN_LEN);
|
2009-11-29 15:15:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
MCDI_SET_DWORD(inbuf, WOL_FILTER_REMOVE_IN_FILTER_ID, (u32)id);
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_REMOVE, inbuf, sizeof(inbuf),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
sfc: Add SR-IOV back-end support for SFC9000 family
On the SFC9000 family, each port has 1024 Virtual Interfaces (VIs),
each with an RX queue, a TX queue, an event queue and a mailbox
register. These may be assigned to up to 127 SR-IOV virtual functions
per port, with up to 64 VIs per VF.
We allocate an extra channel (IRQ and event queue only) to receive
requests from VF drivers.
There is a per-port limit of 4 concurrent RX queue flushes, and queue
flushes may be initiated by the MC in response to a Function Level
Reset (FLR) of a VF. Therefore, when SR-IOV is in use, we submit all
flush requests via the MC.
The RSS indirection table is shared with VFs, so the number of RX
queues used in the PF is limited to the number of VIs per VF.
This is almost entirely the work of Steve Hodgson, formerly
shodgson@solarflare.com.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-02-14 00:48:07 +00:00
|
|
|
int efx_mcdi_flush_rxqs(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_channel *channel;
|
|
|
|
struct efx_rx_queue *rx_queue;
|
|
|
|
__le32 *qid;
|
|
|
|
int rc, count;
|
|
|
|
|
2012-09-19 01:53:34 +00:00
|
|
|
BUILD_BUG_ON(EFX_MAX_CHANNELS >
|
|
|
|
MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
|
|
|
|
|
sfc: Add SR-IOV back-end support for SFC9000 family
On the SFC9000 family, each port has 1024 Virtual Interfaces (VIs),
each with an RX queue, a TX queue, an event queue and a mailbox
register. These may be assigned to up to 127 SR-IOV virtual functions
per port, with up to 64 VIs per VF.
We allocate an extra channel (IRQ and event queue only) to receive
requests from VF drivers.
There is a per-port limit of 4 concurrent RX queue flushes, and queue
flushes may be initiated by the MC in response to a Function Level
Reset (FLR) of a VF. Therefore, when SR-IOV is in use, we submit all
flush requests via the MC.
The RSS indirection table is shared with VFs, so the number of RX
queues used in the PF is limited to the number of VIs per VF.
This is almost entirely the work of Steve Hodgson, formerly
shodgson@solarflare.com.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-02-14 00:48:07 +00:00
|
|
|
qid = kmalloc(EFX_MAX_CHANNELS * sizeof(*qid), GFP_KERNEL);
|
|
|
|
if (qid == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
efx_for_each_channel_rx_queue(rx_queue, channel) {
|
|
|
|
if (rx_queue->flush_pending) {
|
|
|
|
rx_queue->flush_pending = false;
|
|
|
|
atomic_dec(&efx->rxq_flush_pending);
|
|
|
|
qid[count++] = cpu_to_le32(
|
|
|
|
efx_rx_queue_index(rx_queue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, (u8 *)qid,
|
|
|
|
count * sizeof(*qid), NULL, 0, NULL);
|
2012-09-11 17:25:13 +00:00
|
|
|
WARN_ON(rc < 0);
|
sfc: Add SR-IOV back-end support for SFC9000 family
On the SFC9000 family, each port has 1024 Virtual Interfaces (VIs),
each with an RX queue, a TX queue, an event queue and a mailbox
register. These may be assigned to up to 127 SR-IOV virtual functions
per port, with up to 64 VIs per VF.
We allocate an extra channel (IRQ and event queue only) to receive
requests from VF drivers.
There is a per-port limit of 4 concurrent RX queue flushes, and queue
flushes may be initiated by the MC in response to a Function Level
Reset (FLR) of a VF. Therefore, when SR-IOV is in use, we submit all
flush requests via the MC.
The RSS indirection table is shared with VFs, so the number of RX
queues used in the PF is limited to the number of VIs per VF.
This is almost entirely the work of Steve Hodgson, formerly
shodgson@solarflare.com.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-02-14 00:48:07 +00:00
|
|
|
|
|
|
|
kfree(qid);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2009-11-29 15:15:25 +00:00
|
|
|
|
|
|
|
int efx_mcdi_wol_filter_reset(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_RESET, NULL, 0, NULL, 0, NULL);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-06-23 11:30:07 +00:00
|
|
|
netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
|
2009-11-29 15:15:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|