2009-10-23 16:30:46 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Driver for Solarflare Solarstorm network controllers and boards
|
|
|
|
* Copyright 2005-2006 Fen Systems Ltd.
|
2011-02-25 08:01:34 +08:00
|
|
|
* Copyright 2006-2010 Solarflare Communications Inc.
|
2009-10-23 16:30:46 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EFX_IO_H
|
|
|
|
#define EFX_IO_H
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* NIC register I/O
|
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
*
|
2012-09-20 00:47:08 +08:00
|
|
|
* Notes on locking strategy for the Falcon architecture:
|
2009-10-23 16:30:46 +08:00
|
|
|
*
|
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 08:56:50 +08:00
|
|
|
* Many CSRs are very wide and cannot be read or written atomically.
|
|
|
|
* Writes from the host are buffered by the Bus Interface Unit (BIU)
|
|
|
|
* up to 128 bits. Whenever the host writes part of such a register,
|
|
|
|
* the BIU collects the written value and does not write to the
|
|
|
|
* underlying register until all 4 dwords have been written. A
|
|
|
|
* similar buffering scheme applies to host access to the NIC's 64-bit
|
|
|
|
* SRAM.
|
2009-10-23 16:30:46 +08:00
|
|
|
*
|
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 08:56:50 +08:00
|
|
|
* Writes to different CSRs and 64-bit SRAM words must be serialised,
|
|
|
|
* since interleaved access can result in lost writes. We use
|
|
|
|
* efx_nic::biu_lock for this.
|
|
|
|
*
|
|
|
|
* We also serialise reads from 128-bit CSRs and SRAM with the same
|
|
|
|
* spinlock. This may not be necessary, but it doesn't really matter
|
|
|
|
* as there are no such reads on the fast path.
|
2009-10-23 16:30:46 +08:00
|
|
|
*
|
2010-12-07 06:55:00 +08:00
|
|
|
* The DMA descriptor pointers (RX_DESC_UPD and TX_DESC_UPD) are
|
|
|
|
* 128-bit but are special-cased in the BIU to avoid the need for
|
|
|
|
* locking in the host:
|
2009-10-23 16:30:46 +08:00
|
|
|
*
|
2010-12-07 06:55:00 +08:00
|
|
|
* - They are write-only.
|
|
|
|
* - The semantics of writing to these registers are such that
|
|
|
|
* replacing the low 96 bits with zero does not affect functionality.
|
|
|
|
* - If the host writes to the last dword address of such a register
|
|
|
|
* (i.e. the high 32 bits) the underlying register will always be
|
2011-09-01 20:09:59 +08:00
|
|
|
* written. If the collector and the current write together do not
|
|
|
|
* provide values for all 128 bits of the register, the low 96 bits
|
|
|
|
* will be written as zero.
|
2010-12-07 06:55:00 +08:00
|
|
|
* - If the host writes to the address of any other part of such a
|
|
|
|
* register while the collector already holds values for some other
|
|
|
|
* register, the write is discarded and the collector maintains its
|
|
|
|
* current state.
|
2012-09-20 00:47:08 +08:00
|
|
|
*
|
|
|
|
* The EF10 architecture exposes very few registers to the host and
|
|
|
|
* most of them are only 32 bits wide. The only exceptions are the MC
|
|
|
|
* doorbell register pair, which has its own latching, and
|
|
|
|
* TX_DESC_UPD, which works in a similar way to the Falcon
|
|
|
|
* architecture.
|
2009-10-23 16:30:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if BITS_PER_LONG == 64
|
|
|
|
#define EFX_USE_QWORD_IO 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EFX_USE_QWORD_IO
|
|
|
|
static inline void _efx_writeq(struct efx_nic *efx, __le64 value,
|
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
__raw_writeq((__force u64)value, efx->membase + reg);
|
|
|
|
}
|
|
|
|
static inline __le64 _efx_readq(struct efx_nic *efx, unsigned int reg)
|
|
|
|
{
|
|
|
|
return (__force __le64)__raw_readq(efx->membase + reg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void _efx_writed(struct efx_nic *efx, __le32 value,
|
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
__raw_writel((__force u32)value, efx->membase + reg);
|
|
|
|
}
|
|
|
|
static inline __le32 _efx_readd(struct efx_nic *efx, unsigned int reg)
|
|
|
|
{
|
|
|
|
return (__force __le32)__raw_readl(efx->membase + reg);
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write a normal 128-bit CSR, locking as appropriate. */
|
2012-09-13 08:11:23 +08:00
|
|
|
static inline void efx_writeo(struct efx_nic *efx, const efx_oword_t *value,
|
2009-10-23 16:30:46 +08:00
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
unsigned long flags __attribute__ ((unused));
|
|
|
|
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"writing register %x with " EFX_OWORD_FMT "\n", reg,
|
|
|
|
EFX_OWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&efx->biu_lock, flags);
|
|
|
|
#ifdef EFX_USE_QWORD_IO
|
|
|
|
_efx_writeq(efx, value->u64[0], reg + 0);
|
|
|
|
_efx_writeq(efx, value->u64[1], reg + 8);
|
|
|
|
#else
|
|
|
|
_efx_writed(efx, value->u32[0], reg + 0);
|
|
|
|
_efx_writed(efx, value->u32[1], reg + 4);
|
|
|
|
_efx_writed(efx, value->u32[2], reg + 8);
|
|
|
|
_efx_writed(efx, value->u32[3], reg + 12);
|
|
|
|
#endif
|
|
|
|
mmiowb();
|
|
|
|
spin_unlock_irqrestore(&efx->biu_lock, flags);
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write 64-bit SRAM through the supplied mapping, locking as appropriate. */
|
2009-10-23 16:30:46 +08:00
|
|
|
static inline void efx_sram_writeq(struct efx_nic *efx, void __iomem *membase,
|
2012-09-13 08:11:23 +08:00
|
|
|
const efx_qword_t *value, unsigned int index)
|
2009-10-23 16:30:46 +08:00
|
|
|
{
|
|
|
|
unsigned int addr = index * sizeof(*value);
|
|
|
|
unsigned long flags __attribute__ ((unused));
|
|
|
|
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"writing SRAM address %x with " EFX_QWORD_FMT "\n",
|
|
|
|
addr, EFX_QWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&efx->biu_lock, flags);
|
|
|
|
#ifdef EFX_USE_QWORD_IO
|
|
|
|
__raw_writeq((__force u64)value->u64[0], membase + addr);
|
|
|
|
#else
|
|
|
|
__raw_writel((__force u32)value->u32[0], membase + addr);
|
|
|
|
__raw_writel((__force u32)value->u32[1], membase + addr + 4);
|
|
|
|
#endif
|
|
|
|
mmiowb();
|
|
|
|
spin_unlock_irqrestore(&efx->biu_lock, flags);
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write a 32-bit CSR or the last dword of a special 128-bit CSR */
|
2012-09-13 08:11:23 +08:00
|
|
|
static inline void efx_writed(struct efx_nic *efx, const efx_dword_t *value,
|
2009-10-23 16:30:46 +08:00
|
|
|
unsigned int reg)
|
|
|
|
{
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
2010-12-07 06:55:00 +08:00
|
|
|
"writing register %x with "EFX_DWORD_FMT"\n",
|
2010-06-23 19:30:07 +08:00
|
|
|
reg, EFX_DWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
|
|
|
|
/* No lock required */
|
|
|
|
_efx_writed(efx, value->u32[0], reg);
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Read a 128-bit CSR, locking as appropriate. */
|
2009-10-23 16:30:46 +08:00
|
|
|
static inline void efx_reado(struct efx_nic *efx, efx_oword_t *value,
|
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
unsigned long flags __attribute__ ((unused));
|
|
|
|
|
|
|
|
spin_lock_irqsave(&efx->biu_lock, flags);
|
|
|
|
value->u32[0] = _efx_readd(efx, reg + 0);
|
|
|
|
value->u32[1] = _efx_readd(efx, reg + 4);
|
|
|
|
value->u32[2] = _efx_readd(efx, reg + 8);
|
|
|
|
value->u32[3] = _efx_readd(efx, reg + 12);
|
|
|
|
spin_unlock_irqrestore(&efx->biu_lock, flags);
|
|
|
|
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"read from register %x, got " EFX_OWORD_FMT "\n", reg,
|
|
|
|
EFX_OWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Read 64-bit SRAM through the supplied mapping, locking as appropriate. */
|
2009-10-23 16:30:46 +08:00
|
|
|
static inline void efx_sram_readq(struct efx_nic *efx, void __iomem *membase,
|
|
|
|
efx_qword_t *value, unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int addr = index * sizeof(*value);
|
|
|
|
unsigned long flags __attribute__ ((unused));
|
|
|
|
|
|
|
|
spin_lock_irqsave(&efx->biu_lock, flags);
|
|
|
|
#ifdef EFX_USE_QWORD_IO
|
|
|
|
value->u64[0] = (__force __le64)__raw_readq(membase + addr);
|
|
|
|
#else
|
|
|
|
value->u32[0] = (__force __le32)__raw_readl(membase + addr);
|
|
|
|
value->u32[1] = (__force __le32)__raw_readl(membase + addr + 4);
|
|
|
|
#endif
|
|
|
|
spin_unlock_irqrestore(&efx->biu_lock, flags);
|
|
|
|
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"read from SRAM address %x, got "EFX_QWORD_FMT"\n",
|
|
|
|
addr, EFX_QWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Read a 32-bit CSR or SRAM */
|
2009-10-23 16:30:46 +08:00
|
|
|
static inline void efx_readd(struct efx_nic *efx, efx_dword_t *value,
|
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
value->u32[0] = _efx_readd(efx, reg);
|
2010-06-23 19:30:07 +08:00
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"read from register %x, got "EFX_DWORD_FMT"\n",
|
|
|
|
reg, EFX_DWORD_VAL(*value));
|
2009-10-23 16:30:46 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write a 128-bit CSR forming part of a table */
|
2012-09-13 08:11:23 +08:00
|
|
|
static inline void
|
|
|
|
efx_writeo_table(struct efx_nic *efx, const efx_oword_t *value,
|
|
|
|
unsigned int reg, unsigned int index)
|
2009-10-23 16:30:46 +08:00
|
|
|
{
|
|
|
|
efx_writeo(efx, value, reg + index * sizeof(efx_oword_t));
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Read a 128-bit CSR forming part of a table */
|
2009-10-23 16:30:46 +08:00
|
|
|
static inline void efx_reado_table(struct efx_nic *efx, efx_oword_t *value,
|
|
|
|
unsigned int reg, unsigned int index)
|
|
|
|
{
|
|
|
|
efx_reado(efx, value, reg + index * sizeof(efx_oword_t));
|
|
|
|
}
|
|
|
|
|
2013-06-29 03:14:46 +08:00
|
|
|
/* Page size used as step between per-VI registers */
|
|
|
|
#define EFX_VI_PAGE_SIZE 0x2000
|
2009-10-23 16:30:46 +08:00
|
|
|
|
2013-06-29 03:14:46 +08:00
|
|
|
/* Calculate offset to page-mapped register */
|
2009-10-23 16:30:46 +08:00
|
|
|
#define EFX_PAGED_REG(page, reg) \
|
2013-06-29 03:14:46 +08:00
|
|
|
((page) * EFX_VI_PAGE_SIZE + (reg))
|
2009-10-23 16:30:46 +08:00
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write the whole of RX_DESC_UPD or TX_DESC_UPD */
|
2010-12-07 06:55:33 +08:00
|
|
|
static inline void _efx_writeo_page(struct efx_nic *efx, efx_oword_t *value,
|
|
|
|
unsigned int reg, unsigned int page)
|
2009-10-23 16:30:46 +08:00
|
|
|
{
|
2010-12-07 06:58:41 +08:00
|
|
|
reg = EFX_PAGED_REG(page, reg);
|
|
|
|
|
|
|
|
netif_vdbg(efx, hw, efx->net_dev,
|
|
|
|
"writing register %x with " EFX_OWORD_FMT "\n", reg,
|
|
|
|
EFX_OWORD_VAL(*value));
|
|
|
|
|
|
|
|
#ifdef EFX_USE_QWORD_IO
|
|
|
|
_efx_writeq(efx, value->u64[0], reg + 0);
|
2011-09-01 20:09:59 +08:00
|
|
|
_efx_writeq(efx, value->u64[1], reg + 8);
|
2010-12-07 06:58:41 +08:00
|
|
|
#else
|
|
|
|
_efx_writed(efx, value->u32[0], reg + 0);
|
|
|
|
_efx_writed(efx, value->u32[1], reg + 4);
|
|
|
|
_efx_writed(efx, value->u32[2], reg + 8);
|
|
|
|
_efx_writed(efx, value->u32[3], reg + 12);
|
2011-09-01 20:09:59 +08:00
|
|
|
#endif
|
2009-10-23 16:30:46 +08:00
|
|
|
}
|
2010-12-07 06:55:33 +08:00
|
|
|
#define efx_writeo_page(efx, value, reg, page) \
|
|
|
|
_efx_writeo_page(efx, value, \
|
|
|
|
reg + \
|
|
|
|
BUILD_BUG_ON_ZERO((reg) != 0x830 && (reg) != 0xa10), \
|
|
|
|
page)
|
2009-10-23 16:30:46 +08:00
|
|
|
|
2012-09-20 00:47:08 +08:00
|
|
|
/* Write a page-mapped 32-bit CSR (EVQ_RPTR, EVQ_TMR (EF10), or the
|
|
|
|
* high bits of RX_DESC_UPD or TX_DESC_UPD)
|
2010-12-07 06:55:00 +08:00
|
|
|
*/
|
2012-09-13 08:11:23 +08:00
|
|
|
static inline void
|
|
|
|
_efx_writed_page(struct efx_nic *efx, const efx_dword_t *value,
|
|
|
|
unsigned int reg, unsigned int page)
|
2009-10-23 16:30:46 +08:00
|
|
|
{
|
|
|
|
efx_writed(efx, value, EFX_PAGED_REG(page, reg));
|
|
|
|
}
|
2010-12-07 06:55:33 +08:00
|
|
|
#define efx_writed_page(efx, value, reg, page) \
|
|
|
|
_efx_writed_page(efx, value, \
|
|
|
|
reg + \
|
2012-09-20 00:47:08 +08:00
|
|
|
BUILD_BUG_ON_ZERO((reg) != 0x400 && \
|
|
|
|
(reg) != 0x420 && \
|
|
|
|
(reg) != 0x830 && \
|
|
|
|
(reg) != 0x83c && \
|
|
|
|
(reg) != 0xa18 && \
|
|
|
|
(reg) != 0xa1c), \
|
2010-12-07 06:55:33 +08:00
|
|
|
page)
|
2009-10-23 16:30:46 +08:00
|
|
|
|
2010-12-07 06:55:00 +08:00
|
|
|
/* Write TIMER_COMMAND. This is a page-mapped 32-bit CSR, but a bug
|
|
|
|
* in the BIU means that writes to TIMER_COMMAND[0] invalidate the
|
|
|
|
* collector register.
|
|
|
|
*/
|
2010-12-07 06:55:33 +08:00
|
|
|
static inline void _efx_writed_page_locked(struct efx_nic *efx,
|
2012-09-13 08:11:23 +08:00
|
|
|
const efx_dword_t *value,
|
2010-12-07 06:55:33 +08:00
|
|
|
unsigned int reg,
|
|
|
|
unsigned int page)
|
2009-10-23 16:30:46 +08:00
|
|
|
{
|
|
|
|
unsigned long flags __attribute__ ((unused));
|
|
|
|
|
|
|
|
if (page == 0) {
|
|
|
|
spin_lock_irqsave(&efx->biu_lock, flags);
|
|
|
|
efx_writed(efx, value, EFX_PAGED_REG(page, reg));
|
|
|
|
spin_unlock_irqrestore(&efx->biu_lock, flags);
|
|
|
|
} else {
|
|
|
|
efx_writed(efx, value, EFX_PAGED_REG(page, reg));
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 06:55:33 +08:00
|
|
|
#define efx_writed_page_locked(efx, value, reg, page) \
|
|
|
|
_efx_writed_page_locked(efx, value, \
|
|
|
|
reg + BUILD_BUG_ON_ZERO((reg) != 0x420), \
|
|
|
|
page)
|
2009-10-23 16:30:46 +08:00
|
|
|
|
|
|
|
#endif /* EFX_IO_H */
|