NetBSD/sys/dev/pci/if_bgevar.h

349 lines
12 KiB
C
Raw Normal View History

/* $NetBSD: if_bgevar.h,v 1.21 2015/11/18 10:26:57 msaitoh Exp $ */
2009-04-23 14:47:43 +04:00
/*
* Copyright (c) 2001 Wind River Systems
* Copyright (c) 1997, 1998, 1999, 2001
* Bill Paul <wpaul@windriver.com>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Bill Paul.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: if_bgereg.h,v 1.1.2.7 2002/11/02 18:17:55 mp Exp $
*/
/*
* BCM570x memory map. The internal memory layout varies somewhat
* depending on whether or not we have external SSRAM attached.
* The BCM5700 can have up to 16MB of external memory. The BCM5701
* is apparently not designed to use external SSRAM. The mappings
* up to the first 4 send rings are the same for both internal and
* external memory configurations. Note that mini RX ring space is
* only available with external SSRAM configurations, which means
* the mini RX ring is not supported on the BCM5701.
*
* The NIC's memory can be accessed by the host in one of 3 ways:
*
* 1) Indirect register access. The MEMWIN_BASEADDR and MEMWIN_DATA
* registers in PCI config space can be used to read any 32-bit
* address within the NIC's memory.
*
* 2) Memory window access. The MEMWIN_BASEADDR register in PCI config
* space can be used in conjunction with the memory window in the
* device register space at offset 0x8000 to read any 32K chunk
* of NIC memory.
*
* 3) Flat mode. If the 'flat mode' bit in the PCI state register is
* set, the device I/O mapping consumes 32MB of host address space,
* allowing all of the registers and internal NIC memory to be
* accessed directly. NIC memory addresses are offset by 0x01000000.
* Flat mode consumes so much host address space that it is not
* recommended.
*/
#ifndef _DEV_PCI_IF_BGEVAR_H_
#define _DEV_PCI_IF_BGEVAR_H_
#include <sys/bus.h>
#include <sys/rndsource.h>
2009-04-23 14:47:43 +04:00
#include <net/if_ether.h>
#include <dev/pci/pcivar.h>
#define BGE_HOSTADDR(x, y) \
do { \
(x).bge_addr_lo = ((uint64_t) (y) & 0xffffffff); \
if (sizeof (bus_addr_t) == 8) \
2010-02-03 18:37:51 +03:00
(x).bge_addr_hi = ((uint64_t) (y) >> 32); \
else \
(x).bge_addr_hi = 0; \
} while(0)
2009-04-23 14:47:43 +04:00
#define RCB_WRITE_4(sc, rcb, offset, val) \
bus_space_write_4(sc->bge_btag, sc->bge_bhandle, \
rcb + offsetof(struct bge_rcb, offset), val)
/*
* Other utility macros.
*/
#define BGE_INC(x, y) (x) = (x + 1) % y
/*
* Register access macros. The Tigon always uses memory mapped register
* accesses and all registers must be accessed with 32 bit operations.
*/
#define CSR_WRITE_4(sc, reg, val) \
bus_space_write_4(sc->bge_btag, sc->bge_bhandle, reg, val)
#define CSR_READ_4(sc, reg) \
bus_space_read_4(sc->bge_btag, sc->bge_bhandle, reg)
#define CSR_WRITE_4_FLUSH(sc, reg, val) \
do { \
CSR_WRITE_4(sc, reg, val); \
CSR_READ_4(sc, reg); \
} while(0)
2009-04-23 14:47:43 +04:00
#define BGE_SETBIT(sc, reg, x) \
CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) | (x)))
#define BGE_SETBIT_FLUSH(sc, reg, x) \
do { \
BGE_SETBIT(sc, reg, x); \
CSR_READ_4(sc, reg); \
} while(0)
2009-04-23 14:47:43 +04:00
#define BGE_CLRBIT(sc, reg, x) \
CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) & ~(x)))
#define BGE_CLRBIT_FLUSH(sc, reg, x) \
do { \
BGE_CLRBIT(sc, reg, x); \
CSR_READ_4(sc, reg); \
} while(0)
2009-04-23 14:47:43 +04:00
/* BAR2 APE register access macros. */
#define APE_WRITE_4(sc, reg, val) \
bus_space_write_4(sc->bge_apetag, sc->bge_apehandle, reg, val)
#define APE_READ_4(sc, reg) \
bus_space_read_4(sc->bge_apetag, sc->bge_apehandle, reg)
#define APE_WRITE_4_FLUSH(sc, reg, val) \
do { \
APE_WRITE_4(sc, reg, val); \
APE_READ_4(sc, reg); \
} while(0)
#define APE_SETBIT(sc, reg, x) \
APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) | (x)))
#define APE_CLRBIT(sc, reg, x) \
APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) & ~(x)))
#define PCI_SETBIT(pc, tag, reg, x) \
pci_conf_write(pc, tag, reg, (pci_conf_read(pc, tag, reg) | (x)))
2009-04-23 14:47:43 +04:00
#define PCI_CLRBIT(pc, tag, reg, x) \
pci_conf_write(pc, tag, reg, (pci_conf_read(pc, tag, reg) & ~(x)))
2009-04-23 14:47:43 +04:00
/*
* Memory management stuff. Note: the SSLOTS, MSLOTS and JSLOTS
* values are tuneable. They control the actual amount of buffers
* allocated for the standard, mini and jumbo receive rings.
*/
#define BGE_SSLOTS 256
#define BGE_MSLOTS 256
#define BGE_JSLOTS 384
#define BGE_JRAWLEN (BGE_JUMBO_FRAMELEN + ETHER_ALIGN)
2010-02-03 18:37:51 +03:00
#define BGE_JLEN (BGE_JRAWLEN + (sizeof(uint64_t) - \
(BGE_JRAWLEN % sizeof(uint64_t))))
2009-04-23 14:47:43 +04:00
#define BGE_JPAGESZ PAGE_SIZE
#define BGE_RESID (BGE_JPAGESZ - (BGE_JLEN * BGE_JSLOTS) % BGE_JPAGESZ)
#define BGE_JMEM ((BGE_JLEN * BGE_JSLOTS) + BGE_RESID)
/*
* Ring structures. Most of these reside in host memory and we tell
* the NIC where they are via the ring control blocks. The exceptions
* are the tx and command rings, which live in NIC memory and which
* we access via the shared memory window.
*/
struct bge_ring_data {
struct bge_rx_bd bge_rx_std_ring[BGE_STD_RX_RING_CNT];
struct bge_rx_bd bge_rx_jumbo_ring[BGE_JUMBO_RX_RING_CNT];
struct bge_rx_bd bge_rx_return_ring[BGE_RETURN_RING_CNT];
struct bge_tx_bd bge_tx_ring[BGE_TX_RING_CNT];
struct bge_status_block bge_status_block;
struct bge_tx_desc *bge_tx_ring_nic;/* pointer to shared mem */
struct bge_cmd_desc *bge_cmd_ring; /* pointer to shared mem */
struct bge_gib bge_info;
};
#define BGE_RING_DMA_ADDR(sc, offset) \
((sc)->bge_ring_map->dm_segs[0].ds_addr + \
offsetof(struct bge_ring_data, offset))
/*
* Number of DMA segments in a TxCB. Note that this is carefully
* chosen to make the total struct size an even power of two. It's
* critical that no TxCB be split across a page boundary since
* no attempt is made to allocate physically contiguous memory.
*
*/
#if 0 /* pre-TSO values */
#define BGE_TXDMA_MAX ETHER_MAX_LEN_JUMBO
#ifdef _LP64
#define BGE_NTXSEG 30
#else
#define BGE_NTXSEG 31
#endif
#else /* TSO values */
#define BGE_TXDMA_MAX (round_page(IP_MAXPACKET)) /* for TSO */
#ifdef _LP64
#define BGE_NTXSEG 120 /* XXX just a guess */
#else
#define BGE_NTXSEG 124 /* XXX just a guess */
#endif
#endif /* TSO values */
#define BGE_STATUS_BLK_SZ sizeof (struct bge_status_block)
2009-04-23 14:47:43 +04:00
/*
* Mbuf pointers. We need these to keep track of the virtual addresses
* of our mbuf chains since we can only convert from physical to virtual,
* not the other way around.
*/
struct bge_chain_data {
struct mbuf *bge_tx_chain[BGE_TX_RING_CNT];
struct mbuf *bge_rx_std_chain[BGE_STD_RX_RING_CNT];
struct mbuf *bge_rx_jumbo_chain[BGE_JUMBO_RX_RING_CNT];
struct mbuf *bge_rx_mini_chain[BGE_MINI_RX_RING_CNT];
bus_dmamap_t bge_rx_std_map[BGE_STD_RX_RING_CNT];
bus_dmamap_t bge_rx_jumbo_map;
/* Stick the jumbo mem management stuff here too. */
void * bge_jslots[BGE_JSLOTS];
void * bge_jumbo_buf;
};
#define BGE_JUMBO_DMA_ADDR(sc, m) \
((sc)->bge_cdata.bge_rx_jumbo_map->dm_segs[0].ds_addr + \
(mtod((m), char *) - (char *)(sc)->bge_cdata.bge_jumbo_buf))
struct bge_type {
2010-02-03 18:37:51 +03:00
uint16_t bge_vid;
uint16_t bge_did;
2009-04-23 14:47:43 +04:00
char *bge_name;
};
#define BGE_TIMEOUT 100000
2009-04-23 14:47:43 +04:00
#define BGE_TXCONS_UNSET 0xFFFF /* impossible value */
struct bge_jpool_entry {
int slot;
SLIST_ENTRY(bge_jpool_entry) jpool_entries;
};
struct bge_bcom_hack {
int reg;
int val;
};
struct txdmamap_pool_entry {
bus_dmamap_t dmamap;
SLIST_ENTRY(txdmamap_pool_entry) link;
};
#define ASF_ENABLE 1
#define ASF_NEW_HANDSHAKE 2
#define ASF_STACKUP 4
2009-04-23 14:47:43 +04:00
struct bge_softc {
device_t bge_dev;
2010-02-03 18:37:51 +03:00
struct ethercom ethercom; /* interface info */
2009-04-23 14:47:43 +04:00
bus_space_handle_t bge_bhandle;
bus_space_tag_t bge_btag;
bus_size_t bge_bsize;
bus_space_handle_t bge_apehandle;
bus_space_tag_t bge_apetag;
bus_size_t bge_apesize;
2009-04-23 14:47:43 +04:00
void *bge_intrhand;
pci_intr_handle_t *bge_pihp;
2009-04-23 14:47:43 +04:00
pci_chipset_tag_t sc_pc;
pcitag_t sc_pcitag;
struct pci_attach_args bge_pa;
2009-04-23 14:47:43 +04:00
struct mii_data bge_mii;
struct ifmedia bge_ifmedia; /* media info */
2010-02-03 18:37:51 +03:00
uint32_t bge_return_ring_cnt;
uint32_t bge_tx_prodidx;
2009-04-23 14:47:43 +04:00
bus_dma_tag_t bge_dmatag;
uint32_t bge_pcixcap;
uint32_t bge_pciecap;
uint32_t bge_msicap;
uint16_t bge_mps;
int bge_expmrq;
uint32_t bge_lasttag;
u_int32_t bge_mfw_flags; /* Management F/W flags */
#define BGE_MFW_ON_RXCPU 0x00000001
#define BGE_MFW_ON_APE 0x00000002
#define BGE_MFW_TYPE_NCSI 0x00000004
#define BGE_MFW_TYPE_DASH 0x00000008
int bge_phy_ape_lock;
int bge_phy_addr;
2010-02-03 18:37:51 +03:00
uint32_t bge_chipid;
uint8_t bge_asf_mode;
uint8_t bge_asf_count;
2009-04-23 14:47:43 +04:00
struct bge_ring_data *bge_rdata; /* rings */
struct bge_chain_data bge_cdata; /* mbufs */
bus_dmamap_t bge_ring_map;
bus_dma_segment_t bge_ring_seg;
int bge_ring_rseg;
2010-02-03 18:37:51 +03:00
uint16_t bge_tx_saved_considx;
uint16_t bge_rx_saved_considx;
uint16_t bge_ev_saved_considx;
uint16_t bge_std; /* current std ring head */
uint16_t bge_jumbo; /* current jumo ring head */
2009-04-23 14:47:43 +04:00
SLIST_HEAD(__bge_jfreehead, bge_jpool_entry) bge_jfree_listhead;
SLIST_HEAD(__bge_jinusehead, bge_jpool_entry) bge_jinuse_listhead;
2010-02-03 18:37:51 +03:00
uint32_t bge_stat_ticks;
uint32_t bge_rx_coal_ticks;
uint32_t bge_tx_coal_ticks;
uint32_t bge_rx_max_coal_bds;
uint32_t bge_tx_max_coal_bds;
uint32_t bge_tx_buf_ratio;
2009-04-23 14:47:43 +04:00
uint32_t bge_sts;
#define BGE_STS_LINK 0x00000001 /* MAC link status */
#define BGE_STS_LINK_EVT 0x00000002 /* pending link event */
#define BGE_STS_AUTOPOLL 0x00000004 /* PHY auto-polling */
#define BGE_STS_BIT(sc, x) ((sc)->bge_sts & (x))
#define BGE_STS_SETBIT(sc, x) ((sc)->bge_sts |= (x))
#define BGE_STS_CLRBIT(sc, x) ((sc)->bge_sts &= ~(x))
int bge_if_flags;
uint32_t bge_flags;
uint32_t bge_phy_flags;
2009-04-23 14:47:43 +04:00
int bge_flowflags;
#ifdef BGE_EVENT_COUNTERS
/*
* Event counters.
*/
struct evcnt bge_ev_intr; /* interrupts */
struct evcnt bge_ev_tx_xoff; /* send PAUSE(len>0) packets */
struct evcnt bge_ev_tx_xon; /* send PAUSE(len=0) packets */
struct evcnt bge_ev_rx_xoff; /* receive PAUSE(len>0) packets */
struct evcnt bge_ev_rx_xon; /* receive PAUSE(len=0) packets */
struct evcnt bge_ev_rx_macctl; /* receive MAC control packets */
struct evcnt bge_ev_xoffentered;/* XOFF state entered */
#endif /* BGE_EVENT_COUNTERS */
int bge_txcnt;
struct callout bge_timeout;
int bge_pending_rxintr_change;
int bge_detaching;
2009-04-23 14:47:43 +04:00
SLIST_HEAD(, txdmamap_pool_entry) txdma_list;
struct txdmamap_pool_entry *txdma[BGE_TX_RING_CNT];
2011-01-09 16:01:03 +03:00
struct sysctllog *bge_log;
First step of random number subsystem rework described in <20111022023242.BA26F14A158@mail.netbsd.org>. This change includes the following: An initial cleanup and minor reorganization of the entropy pool code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are fixed. Some effort is made to accumulate entropy more quickly at boot time. A generic interface, "rndsink", is added, for stream generators to request that they be re-keyed with good quality entropy from the pool as soon as it is available. The arc4random()/arc4randbytes() implementation in libkern is adjusted to use the rndsink interface for rekeying, which helps address the problem of low-quality keys at boot time. An implementation of the FIPS 140-2 statistical tests for random number generator quality is provided (libkern/rngtest.c). This is based on Greg Rose's implementation from Qualcomm. A new random stream generator, nist_ctr_drbg, is provided. It is based on an implementation of the NIST SP800-90 CTR_DRBG by Henric Jungheim. This generator users AES in a modified counter mode to generate a backtracking-resistant random stream. An abstraction layer, "cprng", is provided for in-kernel consumers of randomness. The arc4random/arc4randbytes API is deprecated for in-kernel use. It is replaced by "cprng_strong". The current cprng_fast implementation wraps the existing arc4random implementation. The current cprng_strong implementation wraps the new CTR_DRBG implementation. Both interfaces are rekeyed from the entropy pool automatically at intervals justifiable from best current cryptographic practice. In some quick tests, cprng_fast() is about the same speed as the old arc4randbytes(), and cprng_strong() is about 20% faster than rnd_extract_data(). Performance is expected to improve. The AES code in src/crypto/rijndael is no longer an optional kernel component, as it is required by cprng_strong, which is not an optional kernel component. The entropy pool output is subjected to the rngtest tests at startup time; if it fails, the system will reboot. There is approximately a 3/10000 chance of a false positive from these tests. Entropy pool _input_ from hardware random numbers is subjected to the rngtest tests at attach time, as well as the FIPS continuous-output test, to detect bad or stuck hardware RNGs; if any are detected, they are detached, but the system continues to run. A problem with rndctl(8) is fixed -- datastructures with pointers in arrays are no longer passed to userspace (this was not a security problem, but rather a major issue for compat32). A new kernel will require a new rndctl. The sysctl kern.arandom() and kern.urandom() nodes are hooked up to the new generators, but the /dev/*random pseudodevices are not, yet. Manual pages for the new kernel interfaces are forthcoming.
2011-11-20 02:51:18 +04:00
krndsource_t rnd_source; /* random source */
2009-04-23 14:47:43 +04:00
};
#endif /* _DEV_PCI_IF_BGEVAR_H_ */