2009-11-29 22:14:45 +07:00
|
|
|
/****************************************************************************
|
|
|
|
* Driver for Solarflare Solarstorm network controllers and boards
|
|
|
|
* Copyright 2005-2006 Fen Systems Ltd.
|
2011-02-25 07:01:34 +07:00
|
|
|
* Copyright 2006-2011 Solarflare Communications Inc.
|
2009-11-29 22:14:45 +07: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/bitops.h>
|
|
|
|
#include <linux/delay.h>
|
2011-06-06 17:43:46 +07:00
|
|
|
#include <linux/interrupt.h>
|
2009-11-29 22:14:45 +07:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/seq_file.h>
|
2013-05-23 00:03:35 +07:00
|
|
|
#include <linux/cpu_rmap.h>
|
2009-11-29 22:14:45 +07:00
|
|
|
#include "net_driver.h"
|
|
|
|
#include "bitfield.h"
|
|
|
|
#include "efx.h"
|
|
|
|
#include "nic.h"
|
2012-09-18 07:57:07 +07:00
|
|
|
#include "farch_regs.h"
|
2009-11-29 22:14:45 +07:00
|
|
|
#include "io.h"
|
|
|
|
#include "workarounds.h"
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Generic buffer handling
|
2012-05-18 00:40:54 +07:00
|
|
|
* These buffers are used for interrupt status, MAC stats, etc.
|
2009-11-29 22:14:45 +07:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
|
2012-09-19 03:59:52 +07:00
|
|
|
unsigned int len, gfp_t gfp_flags)
|
2009-11-29 22:14:45 +07:00
|
|
|
{
|
2012-05-17 23:46:55 +07:00
|
|
|
buffer->addr = dma_alloc_coherent(&efx->pci_dev->dev, len,
|
2013-03-15 14:23:58 +07:00
|
|
|
&buffer->dma_addr,
|
2012-09-19 03:59:52 +07:00
|
|
|
gfp_flags | __GFP_ZERO);
|
2009-11-29 22:14:45 +07:00
|
|
|
if (!buffer->addr)
|
|
|
|
return -ENOMEM;
|
|
|
|
buffer->len = len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
|
|
|
|
{
|
|
|
|
if (buffer->addr) {
|
2012-05-17 23:46:55 +07:00
|
|
|
dma_free_coherent(&efx->pci_dev->dev, buffer->len,
|
|
|
|
buffer->addr, buffer->dma_addr);
|
2009-11-29 22:14:45 +07:00
|
|
|
buffer->addr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-04 20:22:11 +07:00
|
|
|
/* Check whether an event is present in the eventq at the current
|
|
|
|
* read pointer. Only useful for self-test.
|
|
|
|
*/
|
|
|
|
bool efx_nic_event_present(struct efx_channel *channel)
|
|
|
|
{
|
|
|
|
return efx_event_present(efx_event(channel, channel->eventq_read_ptr));
|
|
|
|
}
|
2009-11-29 22:14:45 +07:00
|
|
|
|
2012-02-29 06:37:35 +07:00
|
|
|
void efx_nic_event_test_start(struct efx_channel *channel)
|
2009-11-29 22:14:45 +07:00
|
|
|
{
|
2012-02-29 06:40:21 +07:00
|
|
|
channel->event_test_cpu = -1;
|
2012-02-29 06:37:35 +07:00
|
|
|
smp_wmb();
|
2013-08-22 01:51:04 +07:00
|
|
|
channel->efx->type->ev_test_generate(channel);
|
2009-11-29 22:14:45 +07:00
|
|
|
}
|
|
|
|
|
2012-02-29 06:37:35 +07:00
|
|
|
void efx_nic_irq_test_start(struct efx_nic *efx)
|
2009-11-29 22:14:45 +07:00
|
|
|
{
|
2012-02-29 06:37:35 +07:00
|
|
|
efx->last_irq_cpu = -1;
|
|
|
|
smp_wmb();
|
2013-08-22 01:51:04 +07:00
|
|
|
efx->type->irq_test_generate(efx);
|
2009-11-29 22:14:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hook interrupt handler(s)
|
|
|
|
* Try MSI and then legacy interrupts.
|
|
|
|
*/
|
|
|
|
int efx_nic_init_interrupt(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_channel *channel;
|
2013-05-23 00:03:35 +07:00
|
|
|
unsigned int n_irqs;
|
2009-11-29 22:14:45 +07:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!EFX_INT_MODE_USE_MSI(efx)) {
|
2013-08-22 01:51:04 +07:00
|
|
|
rc = request_irq(efx->legacy_irq,
|
|
|
|
efx->type->irq_handle_legacy, IRQF_SHARED,
|
2009-11-29 22:14:45 +07:00
|
|
|
efx->name, efx);
|
|
|
|
if (rc) {
|
2010-06-23 18:30:07 +07:00
|
|
|
netif_err(efx, drv, efx->net_dev,
|
|
|
|
"failed to hook legacy IRQ %d\n",
|
|
|
|
efx->pci_dev->irq);
|
2009-11-29 22:14:45 +07:00
|
|
|
goto fail1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-23 00:03:35 +07:00
|
|
|
#ifdef CONFIG_RFS_ACCEL
|
|
|
|
if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
|
|
|
|
efx->net_dev->rx_cpu_rmap =
|
|
|
|
alloc_irq_cpu_rmap(efx->n_rx_channels);
|
|
|
|
if (!efx->net_dev->rx_cpu_rmap) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto fail1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 22:14:45 +07:00
|
|
|
/* Hook MSI or MSI-X interrupt */
|
2013-05-23 00:03:35 +07:00
|
|
|
n_irqs = 0;
|
2009-11-29 22:14:45 +07:00
|
|
|
efx_for_each_channel(channel, efx) {
|
2013-08-22 01:51:04 +07:00
|
|
|
rc = request_irq(channel->irq, efx->type->irq_handle_msi,
|
2009-11-29 22:14:45 +07:00
|
|
|
IRQF_PROBE_SHARED, /* Not shared */
|
2012-10-06 05:35:41 +07:00
|
|
|
efx->msi_context[channel->channel].name,
|
|
|
|
&efx->msi_context[channel->channel]);
|
2009-11-29 22:14:45 +07:00
|
|
|
if (rc) {
|
2010-06-23 18:30:07 +07:00
|
|
|
netif_err(efx, drv, efx->net_dev,
|
|
|
|
"failed to hook IRQ %d\n", channel->irq);
|
2009-11-29 22:14:45 +07:00
|
|
|
goto fail2;
|
|
|
|
}
|
2013-05-23 00:03:35 +07:00
|
|
|
++n_irqs;
|
|
|
|
|
|
|
|
#ifdef CONFIG_RFS_ACCEL
|
|
|
|
if (efx->interrupt_mode == EFX_INT_MODE_MSIX &&
|
|
|
|
channel->channel < efx->n_rx_channels) {
|
|
|
|
rc = irq_cpu_rmap_add(efx->net_dev->rx_cpu_rmap,
|
|
|
|
channel->irq);
|
|
|
|
if (rc)
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
#endif
|
2009-11-29 22:14:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail2:
|
2013-05-23 00:03:35 +07:00
|
|
|
#ifdef CONFIG_RFS_ACCEL
|
|
|
|
free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
|
|
|
|
efx->net_dev->rx_cpu_rmap = NULL;
|
|
|
|
#endif
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
if (n_irqs-- == 0)
|
|
|
|
break;
|
2012-10-06 05:35:41 +07:00
|
|
|
free_irq(channel->irq, &efx->msi_context[channel->channel]);
|
2013-05-23 00:03:35 +07:00
|
|
|
}
|
2009-11-29 22:14:45 +07:00
|
|
|
fail1:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_nic_fini_interrupt(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_channel *channel;
|
|
|
|
|
2013-05-23 00:03:35 +07:00
|
|
|
#ifdef CONFIG_RFS_ACCEL
|
|
|
|
free_irq_cpu_rmap(efx->net_dev->rx_cpu_rmap);
|
|
|
|
efx->net_dev->rx_cpu_rmap = NULL;
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 22:14:45 +07:00
|
|
|
/* Disable MSI/MSI-X interrupts */
|
2013-05-23 00:03:35 +07:00
|
|
|
efx_for_each_channel(channel, efx)
|
2012-10-06 05:35:41 +07:00
|
|
|
free_irq(channel->irq, &efx->msi_context[channel->channel]);
|
2009-11-29 22:14:45 +07:00
|
|
|
|
|
|
|
/* Disable legacy interrupt */
|
|
|
|
if (efx->legacy_irq)
|
|
|
|
free_irq(efx->legacy_irq, efx);
|
|
|
|
}
|
|
|
|
|
2010-06-21 10:06:53 +07:00
|
|
|
/* Register dump */
|
|
|
|
|
|
|
|
#define REGISTER_REVISION_A 1
|
|
|
|
#define REGISTER_REVISION_B 2
|
|
|
|
#define REGISTER_REVISION_C 3
|
|
|
|
#define REGISTER_REVISION_Z 3 /* latest revision */
|
|
|
|
|
|
|
|
struct efx_nic_reg {
|
|
|
|
u32 offset:24;
|
|
|
|
u32 min_revision:2, max_revision:2;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define REGISTER(name, min_rev, max_rev) { \
|
|
|
|
FR_ ## min_rev ## max_rev ## _ ## name, \
|
|
|
|
REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev \
|
|
|
|
}
|
|
|
|
#define REGISTER_AA(name) REGISTER(name, A, A)
|
|
|
|
#define REGISTER_AB(name) REGISTER(name, A, B)
|
|
|
|
#define REGISTER_AZ(name) REGISTER(name, A, Z)
|
|
|
|
#define REGISTER_BB(name) REGISTER(name, B, B)
|
|
|
|
#define REGISTER_BZ(name) REGISTER(name, B, Z)
|
|
|
|
#define REGISTER_CZ(name) REGISTER(name, C, Z)
|
|
|
|
|
|
|
|
static const struct efx_nic_reg efx_nic_regs[] = {
|
|
|
|
REGISTER_AZ(ADR_REGION),
|
|
|
|
REGISTER_AZ(INT_EN_KER),
|
|
|
|
REGISTER_BZ(INT_EN_CHAR),
|
|
|
|
REGISTER_AZ(INT_ADR_KER),
|
|
|
|
REGISTER_BZ(INT_ADR_CHAR),
|
|
|
|
/* INT_ACK_KER is WO */
|
|
|
|
/* INT_ISR0 is RC */
|
|
|
|
REGISTER_AZ(HW_INIT),
|
|
|
|
REGISTER_CZ(USR_EV_CFG),
|
|
|
|
REGISTER_AB(EE_SPI_HCMD),
|
|
|
|
REGISTER_AB(EE_SPI_HADR),
|
|
|
|
REGISTER_AB(EE_SPI_HDATA),
|
|
|
|
REGISTER_AB(EE_BASE_PAGE),
|
|
|
|
REGISTER_AB(EE_VPD_CFG0),
|
|
|
|
/* EE_VPD_SW_CNTL and EE_VPD_SW_DATA are not used */
|
|
|
|
/* PMBX_DBG_IADDR and PBMX_DBG_IDATA are indirect */
|
|
|
|
/* PCIE_CORE_INDIRECT is indirect */
|
|
|
|
REGISTER_AB(NIC_STAT),
|
|
|
|
REGISTER_AB(GPIO_CTL),
|
|
|
|
REGISTER_AB(GLB_CTL),
|
|
|
|
/* FATAL_INTR_KER and FATAL_INTR_CHAR are partly RC */
|
|
|
|
REGISTER_BZ(DP_CTRL),
|
|
|
|
REGISTER_AZ(MEM_STAT),
|
|
|
|
REGISTER_AZ(CS_DEBUG),
|
|
|
|
REGISTER_AZ(ALTERA_BUILD),
|
|
|
|
REGISTER_AZ(CSR_SPARE),
|
|
|
|
REGISTER_AB(PCIE_SD_CTL0123),
|
|
|
|
REGISTER_AB(PCIE_SD_CTL45),
|
|
|
|
REGISTER_AB(PCIE_PCS_CTL_STAT),
|
|
|
|
/* DEBUG_DATA_OUT is not used */
|
|
|
|
/* DRV_EV is WO */
|
|
|
|
REGISTER_AZ(EVQ_CTL),
|
|
|
|
REGISTER_AZ(EVQ_CNT1),
|
|
|
|
REGISTER_AZ(EVQ_CNT2),
|
|
|
|
REGISTER_AZ(BUF_TBL_CFG),
|
|
|
|
REGISTER_AZ(SRM_RX_DC_CFG),
|
|
|
|
REGISTER_AZ(SRM_TX_DC_CFG),
|
|
|
|
REGISTER_AZ(SRM_CFG),
|
|
|
|
/* BUF_TBL_UPD is WO */
|
|
|
|
REGISTER_AZ(SRM_UPD_EVQ),
|
|
|
|
REGISTER_AZ(SRAM_PARITY),
|
|
|
|
REGISTER_AZ(RX_CFG),
|
|
|
|
REGISTER_BZ(RX_FILTER_CTL),
|
|
|
|
/* RX_FLUSH_DESCQ is WO */
|
|
|
|
REGISTER_AZ(RX_DC_CFG),
|
|
|
|
REGISTER_AZ(RX_DC_PF_WM),
|
|
|
|
REGISTER_BZ(RX_RSS_TKEY),
|
|
|
|
/* RX_NODESC_DROP is RC */
|
|
|
|
REGISTER_AA(RX_SELF_RST),
|
|
|
|
/* RX_DEBUG, RX_PUSH_DROP are not used */
|
|
|
|
REGISTER_CZ(RX_RSS_IPV6_REG1),
|
|
|
|
REGISTER_CZ(RX_RSS_IPV6_REG2),
|
|
|
|
REGISTER_CZ(RX_RSS_IPV6_REG3),
|
|
|
|
/* TX_FLUSH_DESCQ is WO */
|
|
|
|
REGISTER_AZ(TX_DC_CFG),
|
|
|
|
REGISTER_AA(TX_CHKSM_CFG),
|
|
|
|
REGISTER_AZ(TX_CFG),
|
|
|
|
/* TX_PUSH_DROP is not used */
|
|
|
|
REGISTER_AZ(TX_RESERVED),
|
|
|
|
REGISTER_BZ(TX_PACE),
|
|
|
|
/* TX_PACE_DROP_QID is RC */
|
|
|
|
REGISTER_BB(TX_VLAN),
|
|
|
|
REGISTER_BZ(TX_IPFIL_PORTEN),
|
|
|
|
REGISTER_AB(MD_TXD),
|
|
|
|
REGISTER_AB(MD_RXD),
|
|
|
|
REGISTER_AB(MD_CS),
|
|
|
|
REGISTER_AB(MD_PHY_ADR),
|
|
|
|
REGISTER_AB(MD_ID),
|
|
|
|
/* MD_STAT is RC */
|
|
|
|
REGISTER_AB(MAC_STAT_DMA),
|
|
|
|
REGISTER_AB(MAC_CTRL),
|
|
|
|
REGISTER_BB(GEN_MODE),
|
|
|
|
REGISTER_AB(MAC_MC_HASH_REG0),
|
|
|
|
REGISTER_AB(MAC_MC_HASH_REG1),
|
|
|
|
REGISTER_AB(GM_CFG1),
|
|
|
|
REGISTER_AB(GM_CFG2),
|
|
|
|
/* GM_IPG and GM_HD are not used */
|
|
|
|
REGISTER_AB(GM_MAX_FLEN),
|
|
|
|
/* GM_TEST is not used */
|
|
|
|
REGISTER_AB(GM_ADR1),
|
|
|
|
REGISTER_AB(GM_ADR2),
|
|
|
|
REGISTER_AB(GMF_CFG0),
|
|
|
|
REGISTER_AB(GMF_CFG1),
|
|
|
|
REGISTER_AB(GMF_CFG2),
|
|
|
|
REGISTER_AB(GMF_CFG3),
|
|
|
|
REGISTER_AB(GMF_CFG4),
|
|
|
|
REGISTER_AB(GMF_CFG5),
|
|
|
|
REGISTER_BB(TX_SRC_MAC_CTL),
|
|
|
|
REGISTER_AB(XM_ADR_LO),
|
|
|
|
REGISTER_AB(XM_ADR_HI),
|
|
|
|
REGISTER_AB(XM_GLB_CFG),
|
|
|
|
REGISTER_AB(XM_TX_CFG),
|
|
|
|
REGISTER_AB(XM_RX_CFG),
|
|
|
|
REGISTER_AB(XM_MGT_INT_MASK),
|
|
|
|
REGISTER_AB(XM_FC),
|
|
|
|
REGISTER_AB(XM_PAUSE_TIME),
|
|
|
|
REGISTER_AB(XM_TX_PARAM),
|
|
|
|
REGISTER_AB(XM_RX_PARAM),
|
|
|
|
/* XM_MGT_INT_MSK (note no 'A') is RC */
|
|
|
|
REGISTER_AB(XX_PWR_RST),
|
|
|
|
REGISTER_AB(XX_SD_CTL),
|
|
|
|
REGISTER_AB(XX_TXDRV_CTL),
|
|
|
|
/* XX_PRBS_CTL, XX_PRBS_CHK and XX_PRBS_ERR are not used */
|
|
|
|
/* XX_CORE_STAT is partly RC */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct efx_nic_reg_table {
|
|
|
|
u32 offset:24;
|
|
|
|
u32 min_revision:2, max_revision:2;
|
|
|
|
u32 step:6, rows:21;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define REGISTER_TABLE_DIMENSIONS(_, offset, min_rev, max_rev, step, rows) { \
|
|
|
|
offset, \
|
|
|
|
REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev, \
|
|
|
|
step, rows \
|
|
|
|
}
|
2012-01-06 00:19:45 +07:00
|
|
|
#define REGISTER_TABLE(name, min_rev, max_rev) \
|
2010-06-21 10:06:53 +07:00
|
|
|
REGISTER_TABLE_DIMENSIONS( \
|
|
|
|
name, FR_ ## min_rev ## max_rev ## _ ## name, \
|
|
|
|
min_rev, max_rev, \
|
|
|
|
FR_ ## min_rev ## max_rev ## _ ## name ## _STEP, \
|
|
|
|
FR_ ## min_rev ## max_rev ## _ ## name ## _ROWS)
|
|
|
|
#define REGISTER_TABLE_AA(name) REGISTER_TABLE(name, A, A)
|
|
|
|
#define REGISTER_TABLE_AZ(name) REGISTER_TABLE(name, A, Z)
|
|
|
|
#define REGISTER_TABLE_BB(name) REGISTER_TABLE(name, B, B)
|
|
|
|
#define REGISTER_TABLE_BZ(name) REGISTER_TABLE(name, B, Z)
|
|
|
|
#define REGISTER_TABLE_BB_CZ(name) \
|
|
|
|
REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, B, B, \
|
|
|
|
FR_BZ_ ## name ## _STEP, \
|
|
|
|
FR_BB_ ## name ## _ROWS), \
|
|
|
|
REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, C, Z, \
|
|
|
|
FR_BZ_ ## name ## _STEP, \
|
|
|
|
FR_CZ_ ## name ## _ROWS)
|
|
|
|
#define REGISTER_TABLE_CZ(name) REGISTER_TABLE(name, C, Z)
|
|
|
|
|
|
|
|
static const struct efx_nic_reg_table efx_nic_reg_tables[] = {
|
|
|
|
/* DRIVER is not used */
|
|
|
|
/* EVQ_RPTR, TIMER_COMMAND, USR_EV and {RX,TX}_DESC_UPD are WO */
|
|
|
|
REGISTER_TABLE_BB(TX_IPFIL_TBL),
|
|
|
|
REGISTER_TABLE_BB(TX_SRC_MAC_TBL),
|
|
|
|
REGISTER_TABLE_AA(RX_DESC_PTR_TBL_KER),
|
|
|
|
REGISTER_TABLE_BB_CZ(RX_DESC_PTR_TBL),
|
|
|
|
REGISTER_TABLE_AA(TX_DESC_PTR_TBL_KER),
|
|
|
|
REGISTER_TABLE_BB_CZ(TX_DESC_PTR_TBL),
|
|
|
|
REGISTER_TABLE_AA(EVQ_PTR_TBL_KER),
|
|
|
|
REGISTER_TABLE_BB_CZ(EVQ_PTR_TBL),
|
2010-09-20 15:43:53 +07:00
|
|
|
/* We can't reasonably read all of the buffer table (up to 8MB!).
|
2010-06-21 10:06:53 +07:00
|
|
|
* However this driver will only use a few entries. Reading
|
|
|
|
* 1K entries allows for some expansion of queue count and
|
|
|
|
* size before we need to change the version. */
|
|
|
|
REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL_KER, FR_AA_BUF_FULL_TBL_KER,
|
|
|
|
A, A, 8, 1024),
|
|
|
|
REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL, FR_BZ_BUF_FULL_TBL,
|
|
|
|
B, Z, 8, 1024),
|
|
|
|
REGISTER_TABLE_CZ(RX_MAC_FILTER_TBL0),
|
|
|
|
REGISTER_TABLE_BB_CZ(TIMER_TBL),
|
|
|
|
REGISTER_TABLE_BB_CZ(TX_PACE_TBL),
|
|
|
|
REGISTER_TABLE_BZ(RX_INDIRECTION_TBL),
|
|
|
|
/* TX_FILTER_TBL0 is huge and not used by this driver */
|
|
|
|
REGISTER_TABLE_CZ(TX_MAC_FILTER_TBL0),
|
|
|
|
REGISTER_TABLE_CZ(MC_TREG_SMEM),
|
|
|
|
/* MSIX_PBA_TABLE is not mapped */
|
|
|
|
/* SRM_DBG is not mapped (and is redundant with BUF_FLL_TBL) */
|
2010-09-20 15:43:53 +07:00
|
|
|
REGISTER_TABLE_BZ(RX_FILTER_TBL0),
|
2010-06-21 10:06:53 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
size_t efx_nic_get_regs_len(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
const struct efx_nic_reg *reg;
|
|
|
|
const struct efx_nic_reg_table *table;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
for (reg = efx_nic_regs;
|
|
|
|
reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs);
|
|
|
|
reg++)
|
|
|
|
if (efx->type->revision >= reg->min_revision &&
|
|
|
|
efx->type->revision <= reg->max_revision)
|
|
|
|
len += sizeof(efx_oword_t);
|
|
|
|
|
|
|
|
for (table = efx_nic_reg_tables;
|
|
|
|
table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables);
|
|
|
|
table++)
|
|
|
|
if (efx->type->revision >= table->min_revision &&
|
|
|
|
efx->type->revision <= table->max_revision)
|
|
|
|
len += table->rows * min_t(size_t, table->step, 16);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_nic_get_regs(struct efx_nic *efx, void *buf)
|
|
|
|
{
|
|
|
|
const struct efx_nic_reg *reg;
|
|
|
|
const struct efx_nic_reg_table *table;
|
|
|
|
|
|
|
|
for (reg = efx_nic_regs;
|
|
|
|
reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs);
|
|
|
|
reg++) {
|
|
|
|
if (efx->type->revision >= reg->min_revision &&
|
|
|
|
efx->type->revision <= reg->max_revision) {
|
|
|
|
efx_reado(efx, (efx_oword_t *)buf, reg->offset);
|
|
|
|
buf += sizeof(efx_oword_t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (table = efx_nic_reg_tables;
|
|
|
|
table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables);
|
|
|
|
table++) {
|
|
|
|
size_t size, i;
|
|
|
|
|
|
|
|
if (!(efx->type->revision >= table->min_revision &&
|
|
|
|
efx->type->revision <= table->max_revision))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size = min_t(size_t, table->step, 16);
|
|
|
|
|
|
|
|
for (i = 0; i < table->rows; i++) {
|
|
|
|
switch (table->step) {
|
sfc: Remove confusing MMIO functions
efx_writed_table() uses a step of 16 bytes but efx_readd_table() uses
a step of 4 bytes. Why are they different?
Firstly, register access is asymmetric:
- The EVQ_RPTR table and RX_INDIRECTION_TBL can (or must?) be written
as dwords even though they have a step size of 16 bytes, unlike
most other CSRs.
- In general, a read of any width is valid for registers, so long as
it does not cross register boundaries. There is also no latching
behaviour in the BIU, contrary to rumour.
We write to the EVQ_RPTR table with efx_writed_table() but never read
it back as it's write-only. We write to the RX_INDIRECTION_TBL with
efx_writed_table(), but only read it back for the register dump, where
we use efx_reado_table() as for any other table with step size of 16.
We read MC_TREG_SMEM with efx_readd_table() for the register dump, but
normally read and write it with efx_readd() and efx_writed() using
offsets calculated in bytes.
Since these functions are trivial and have few callers, it's clearer
to open-code them at the call sites. While we're at it, update the
comments on the BIU behaviour again.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-09-18 07:56:50 +07:00
|
|
|
case 4: /* 32-bit SRAM */
|
|
|
|
efx_readd(efx, buf, table->offset + 4 * i);
|
2010-06-21 10:06:53 +07:00
|
|
|
break;
|
|
|
|
case 8: /* 64-bit SRAM */
|
|
|
|
efx_sram_readq(efx,
|
|
|
|
efx->membase + table->offset,
|
|
|
|
buf, i);
|
|
|
|
break;
|
sfc: Remove confusing MMIO functions
efx_writed_table() uses a step of 16 bytes but efx_readd_table() uses
a step of 4 bytes. Why are they different?
Firstly, register access is asymmetric:
- The EVQ_RPTR table and RX_INDIRECTION_TBL can (or must?) be written
as dwords even though they have a step size of 16 bytes, unlike
most other CSRs.
- In general, a read of any width is valid for registers, so long as
it does not cross register boundaries. There is also no latching
behaviour in the BIU, contrary to rumour.
We write to the EVQ_RPTR table with efx_writed_table() but never read
it back as it's write-only. We write to the RX_INDIRECTION_TBL with
efx_writed_table(), but only read it back for the register dump, where
we use efx_reado_table() as for any other table with step size of 16.
We read MC_TREG_SMEM with efx_readd_table() for the register dump, but
normally read and write it with efx_readd() and efx_writed() using
offsets calculated in bytes.
Since these functions are trivial and have few callers, it's clearer
to open-code them at the call sites. While we're at it, update the
comments on the BIU behaviour again.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
2012-09-18 07:56:50 +07:00
|
|
|
case 16: /* 128-bit-readable register */
|
2010-06-21 10:06:53 +07:00
|
|
|
efx_reado_table(efx, buf, table->offset, i);
|
|
|
|
break;
|
|
|
|
case 32: /* 128-bit register, interleaved */
|
|
|
|
efx_reado_table(efx, buf, table->offset, 2 * i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|