[BACK]Return to if_bgevar.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / pci

File: [cvs.NetBSD.org] / src / sys / dev / pci / if_bgevar.h (download)

Revision 1.9.2.1, Sat Sep 7 16:39:32 2013 UTC (10 years, 9 months ago) by bouyer
Branch: netbsd-6
Changes since 1.9: +57 -10 lines

sys/dev/pci/if_bge.c		1.203-1.237, 1.239-1.241, 1.243-1.258 via patch
sys/dev/pci/if_bgereg.h		1.58-1.74, 1.76-1.83 via patch
sys/dev/pci/if_bgevar.h		1.10-1.16 via patch
sys/dev/pci/pcidevs		1.1149 via patch
sys/dev/pci/pcidevs.h		regen
sys/dev/pci/pcidevs_data.h	regen
sys/dev/mii/brgphy.c		1.61-1.63, 1.65, 1.67 via patch
sys/dev/mii/miivar.h		1.61 via patch
sys/dev/mii/miidevs		1.112-1.113 via patch
sys/dev/mii/miidevs.h		regen
sys/dev/mii/miidevs_data.h	regen
share/man/man4/bge.4		1.13-1.15 via patch

	Add some device support, fix a lot of bugs and add some enahcements.
	- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F,
	  BCM5785G, BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
	- brgphy(4): Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
	- Add some bugfixes and enhancement from FreeBSD:
	  - Workaround for BCM5906 silicon bug. When auto-negotiation results in
	   half-duplex operation, excess collision on the ethernet link may
	   cause internal chip delays that may result in subsequent valid
	   frames being dropped due to insufficient receive buffer resources.
	   (FreeBSD: r214219, r214251, r214292)
	  - Allow write DMA to request larger DMA burst size to get better
	   performance on BCM5785.
	   (FreeBSD r213333: OpenBSD 1.294)
	  - Enable TX MAC state machine lockup fix for both BCM5755 or higher
	   and BCM5906. Publicly available data sheet just says it may happen
	   due to corrupted TxMbuf.
	   (FreeBSD r214216)
	  - Follow Broadcom datasheet:
	   Delay 100 microseconds after enabling transmit MAC.
	   Delay 10 microseconds after enabling receive MAC.
	   (FreeBSD r241220)
	- Insert the completion barrier between register write and the
	  consecutive delay(). It will fix some device timeout problems
	  we have seen before.
	- Add DELAY(40) after turning on write DMA state machine.
	- Add some workarounds for 5717 A0 and 5776[56] to be stable.
	  From Linux tg3 driver.
	- Sync with *BSD. No functional change:
	  - make bge_chipid() and use it.
	  - use switch() instead of a lot of if()s.
	- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case.
	  Note that {tcp,udp}6csum flag is currently not added in the
	  capability.
	- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
	  checking.  FreeBSD has the same delay().
	- Rename PHY related flags for the consistency. It's the same as
	  FreeBSD.
	- Remove BGE_10_100_ONLY flag because this was not used.
	  For 10/100 devices, when calling mii_attach(), mask BMSR_EXTSTAT
	  flag to not to check Gigabit flags. It's the same as FreeBSD.
	- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
	  PHY_RESET() because brgphy_reset() refers those flags.
	- Call brgpy specific autonego function in MII_TICK. Before this commit,
	  only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK calls MI
	  mii_phy_auto(). That was not intended.
	- Sync with FreeBSD and OpenBSD. Almost the same as OpenBSD rev. 1.325:
	  - Sync the ring setup code closer to FreeBSD's driver
	  - Do not touch the jumbo replenish threshold register on chips that
	    do not have jumbo support
	- Wait for the bootcode to complete initialization for 5717 and newer
	  devices.  See BCM5718 programmer's guide's "step 13,
	  Device reset Procedure, Section7".
	  57781's document has the same note.
	- 5718 and 57785 document say we should wait 100us.
	- Change the order of register settings a little to match both
	  Broadcom's document and Linux tg3.
	- Add detach function.
	- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
	- Fix a bug that the NVRAM lock timeout occured on sparc64 onboard bge.
	- Check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd
	  (OpenBSD rev. 1.327).
	- Fix the setting of Tx Random Backoff Register.
	- Add BGE_PCIMISCCTL_PCISTATE_RW in BGE_INIT. It's required to set the
	  PCISTATE register correctly.
	- Update comments from 57XX-PG105-R.pdf and 5718-PG106-R.pdf.
	- Add missing bus_dmamap_sync() in bge_intr(). The status word is
	  in DMAed area. Same as other *BSDs.
	- Check the hardware config words and print them. This change only
	  read them and print the values.
	- Set BGE_MISC_CTL's byte/word swap options before using
	  bge_readmem_ind().
	- For BGE_IS_575X_PLUS() devices, don't set
	  BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
	- bge_init_tx_ring() uses BGE_RSLOTS (==256) but bge_free_tx_ring() uses
	  BGE_TX_RING_CNT (== 512). Delete BGE_RSLOTS and use BGE_TX_RING_CNT.
	  Same as OpenBSD's if_bge.c rev. 1.86.
	- Document says 5717 and newer chips have no
	  BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
	  chips. Same as OpenBSD.
	- Fix a bug that the PHY address bits in MI_MODE register is wrongly
	  cleard.  Set the PHY address correctly.
	- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
	  register to not to modify some GPIO bits.
	- Call bge_poll_fw() before writing BGE_MODE_CTL register like the
	  latest linux tg3 dirver.
	- Set DMA watermark depend on the PCI max payload size.
	- Add BGE_JUMBO_CAPABLE flag to some chips. With this commit, 5714,
	  5780, 5717, 5718, 5719 (exclude rev. A0), 5720, 57765 and 57766 are
	  added to support jumbo frame.
	- Fix the setting of sc->bge_flags for 5717 and newer devices.
	- Fix a link detect bug on non-autopoll systems. Same as OpenBSD
	  (rev.1.329 and 1.336) and FreeBSD (r213710).
	- 57765 series is not based on 5717 series. 5717 series is based on
	  57765 series.
	- Set the TX DMA segment size based on the MTU size.
	- Change the TX ring size for 5717 series and 57764 series.
	- For 57766, set BGE_RDMAMODE_JMB_2K_MMRR for non-jumbo frame.
	  Same as Linux tg3.
	- For 57765 and newer devices, set BGE_MAX_RX_FRAME_LOWAT to 1.
	  This value is recommended by the document.
	- Change sysctl related functions for consistency.
	- Style change.
	- Use macro. Remove duplicated macro. Remove unused variable.
	- Fix comments. Add comments.
	- Remove extra semicolon. Remove unused code.
	[msaitoh, ticket #939]

/*	$NetBSD: if_bgevar.h,v 1.9.2.1 2013/09/07 16:39:32 bouyer Exp $	*/
/*
 * 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 <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)				\
			(x).bge_addr_hi = ((uint64_t) (y) >> 32);	\
		else							\
			(x).bge_addr_hi = 0;				\
	} while(0)

#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)

#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)
#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)

/* 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)))
#define PCI_CLRBIT(pc, tag, reg, x)	\
	pci_conf_write(pc, tag, reg, (pci_conf_read(pc, tag, reg) & ~(x)))

/*
 * 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)
#define BGE_JLEN (BGE_JRAWLEN + (sizeof(uint64_t) - \
	(BGE_JRAWLEN % sizeof(uint64_t))))
#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)

/*
 * 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 {
	uint16_t		bge_vid;
	uint16_t		bge_did;
	char			*bge_name;
};

#define BGE_TIMEOUT		100000
#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

struct bge_softc {
	device_t		bge_dev;
	struct ethercom		ethercom;	/* interface info */
	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;
	void			*bge_intrhand;
	pci_chipset_tag_t	sc_pc;
	pcitag_t		sc_pcitag;

	struct pci_attach_args	bge_pa;
	struct mii_data		bge_mii;
	struct ifmedia		bge_ifmedia;	/* media info */
	uint32_t		bge_return_ring_cnt;
	uint32_t		bge_tx_prodidx;
	bus_dma_tag_t		bge_dmatag;
	uint32_t		bge_pcixcap;
	uint32_t		bge_pciecap;
	uint16_t		bge_mps;
	int			bge_expmrq;
	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;
	uint32_t		bge_chipid;
	uint8_t			bge_asf_mode;
	uint8_t			bge_asf_count;
	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;
	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 */
	SLIST_HEAD(__bge_jfreehead, bge_jpool_entry)	bge_jfree_listhead;
	SLIST_HEAD(__bge_jinusehead, bge_jpool_entry)	bge_jinuse_listhead;
	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;
	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;
	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;
	SLIST_HEAD(, txdmamap_pool_entry) txdma_list;
	struct txdmamap_pool_entry *txdma[BGE_TX_RING_CNT];

	struct sysctllog	*bge_log;

	krndsource_t	rnd_source;	/* random source */
};

#endif /* _DEV_PCI_IF_BGEVAR_H_ */