/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
* 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.
*/
/*
* Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
* Ethernet controller family driver.
*/
/*
* Transmit descriptor list size. This is arbitrary, but allocate
* enough descriptors for 64 pending transmissions and 16 segments
* per packet. Since a descriptor holds 2 buffer addresses, that's
* 8 descriptors per packet. This MUST work out to a power of 2.
*/
#define TULIP_NTXSEGS 16
/*
* Receive descriptor list size. We have one Rx buffer per incoming
* packet, so this logic is a little simpler.
*/
#define TULIP_NRXDESC 64
#define TULIP_NRXDESC_MASK (TULIP_NRXDESC - 1)
#define TULIP_NEXTRX(x) ((x + 1) & TULIP_NRXDESC_MASK)
/*
* Control structures are DMA'd to the TULIP chip. We allocate them in
* a single clump that maps to a single DMA segment to make several things
* easier.
*/
struct tulip_control_data {
/*
* The transmit descriptors.
*/
struct tulip_desc tcd_txdescs[TULIP_NTXDESC];
/*
* The receive descriptors.
*/
struct tulip_desc tcd_rxdescs[TULIP_NRXDESC];
/*
* Software state for transmit jobs.
*/
struct tulip_txsoft {
struct mbuf *txs_mbuf; /* head of our mbuf chain */
bus_dmamap_t txs_dmamap; /* our DMA map */
int txs_firstdesc; /* first descriptor in packet */
int txs_lastdesc; /* last descriptor in packet */
int txs_ndescs; /* number of descriptors */
SIMPLEQ_ENTRY(tulip_txsoft) txs_q;
};
SIMPLEQ_HEAD(tulip_txsq, tulip_txsoft);
/*
* Software state for receive jobs.
*/
struct tulip_rxsoft {
struct mbuf *rxs_mbuf; /* head of our mbuf chain */
bus_dmamap_t rxs_dmamap; /* our DMA map */
};
/*
* Media init, change, status function pointers.
*/
struct tulip_mediasw {
void (*tmsw_init)(struct tulip_softc *);
void (*tmsw_get)(struct tulip_softc *, struct ifmediareq *);
int (*tmsw_set)(struct tulip_softc *);
};
/*
* Table which describes the transmit threshold mode. We generally
* start at index 0. Whenever we get a transmit underrun, we increment
* our index, falling back if we encounter the NULL terminator.
*/
struct tulip_txthresh_tab {
uint32_t txth_opmode; /* OPMODE bits */
const char *txth_name; /* name of mode */
};
/*
* The Winbond 89C840F does transmit threshold control totally
* differently. It simply has a 7-bit field which indicates
* the threshold:
*
* txth = ((OPMODE & OPMODE_WINB_TTH) >> OPMODE_WINB_TTH_SHIFT) * 16;
*
* However, we just do Store-and-Forward mode on these chips, since
* the DMA engines seem to be flaky.
*/
#define TLP_TXTHRESH_TAB_WINB { \
{ 0, "store and forward mode" }, \
{ 0, NULL }, \
}
#define TXTH_WINB_SF 0
/*
* Settings for Tulip SIA media.
*/
struct tulip_sia_media {
uint32_t tsm_siaconn; /* CSR13 value */
uint32_t tsm_siatxrx; /* CSR14 value */
uint32_t tsm_siagen; /* CSR15 value */
};
/*
* Description of 2x14x media.
*/
struct tulip_21x4x_media {
int tm_type; /* type of media; see tulipreg.h */
const char *tm_name; /* name of media */
int tm_gp_length; /* MII select sequence length */
int tm_gp_offset; /* MII select sequence offset */
int tm_reset_length;/* MII reset sequence length */
int tm_reset_offset;/* MII reset sequence offset */
uint32_t tm_opmode; /* OPMODE bits for this media */
uint32_t tm_gpctl; /* GPIO control bits for this media */
uint32_t tm_gpdata; /* GPIO bits for this media */
uint32_t tm_actmask; /* `active' bits for this data */
uint32_t tm_actdata; /* active high/low info */
/*
* Table for converting Tulip SROM media info into ifmedia data.
*/
struct tulip_srom_to_ifmedia {
uint8_t tsti_srom; /* SROM media type */
int tsti_subtype; /* ifmedia subtype */
int tsti_options; /* ifmedia options */
const char *tsti_name; /* media name */
uint32_t tsti_opmode; /* OPMODE bits for this media */
uint32_t tsti_sia_cap; /* "MII" capabilities for this media */
/*
* Settings for 21040, 21041, and 21142/21143 SIA, in the event
* the SROM doesn't have them.
*/
struct tulip_sia_media tsti_21040;
struct tulip_sia_media tsti_21041;
struct tulip_sia_media tsti_21142;
};
#ifndef _STANDALONE
/*
* Software state per device.
*/
struct tulip_softc {
device_t sc_dev; /* generic device information */
bus_space_tag_t sc_st; /* bus space tag */
bus_space_handle_t sc_sh; /* bus space handle */
bus_dma_tag_t sc_dmat; /* bus DMA tag */
struct ethercom sc_ethercom; /* ethernet common data */
/*
* Contents of the SROM.
*/
uint8_t *sc_srom;
int sc_srom_addrbits;
/*
* Media access functions for this chip.
*/
const struct tulip_mediasw *sc_mediasw;
mii_bitbang_ops_t sc_bitbang_ops;
/*
* For chips with built-in NWay blocks, these are state
* variables required for autonegotiation.
*/
int sc_nway_ticks; /* tick counter */
struct ifmedia_entry *sc_nway_active; /* the active media */
struct callout sc_nway_callout;
tulip_chip_t sc_chip; /* chip type */
int sc_rev; /* chip revision */
int sc_flags; /* misc flags. */
char sc_name[32]; /* board name */
uint32_t sc_cacheline; /* cache line size */
uint32_t sc_maxburst; /* maximum burst length */
int sc_devno; /* PCI device # */
struct mii_data sc_mii; /* MII/media information */
const struct tulip_txthresh_tab *sc_txth;
int sc_txthresh; /* current transmit threshold */
uint8_t sc_gp_dir; /* GPIO pin direction bits (21140) */
int sc_media_seen; /* ISV media block types seen */
int sc_tlp_minst; /* Tulip internal media instance */
uint32_t sc_sia_cap; /* SIA media capabilities (21143) */
/* Power management hooks. */
int (*sc_enable)(struct tulip_softc *);
void (*sc_disable)(struct tulip_softc *);
void (*sc_power)(struct tulip_softc *, int);
/*
* The Winbond 89C840F places registers 4 bytes apart, instead
* of 8.
*/
int sc_regshift;
uint32_t sc_busmode; /* copy of CSR_BUSMODE */
uint32_t sc_opmode; /* copy of CSR_OPMODE */
uint32_t sc_inten; /* copy of CSR_INTEN */
uint32_t sc_rxint_mask; /* mask of Rx interrupts we want */
uint32_t sc_txint_mask; /* mask of Tx interrupts we want */
uint32_t sc_filtmode; /* filter mode we're using */
bus_dma_segment_t sc_cdseg; /* control data memory */
int sc_cdnseg; /* number of segments */
bus_dmamap_t sc_cddmamap; /* control data DMA map */
#define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
/*
* Software state for transmit and receive descriptors.
*/
struct tulip_txsoft sc_txsoft[TULIP_TXQUEUELEN];
struct tulip_rxsoft sc_rxsoft[TULIP_NRXDESC];
/*
* Control data structures.
*/
struct tulip_control_data *sc_control_data;
#define sc_txdescs sc_control_data->tcd_txdescs
#define sc_rxdescs sc_control_data->tcd_rxdescs
#define sc_setup_desc sc_control_data->tcd_setup_desc
int sc_txfree; /* number of free Tx descriptors */
int sc_txnext; /* next ready Tx descriptor */
int sc_ntxsegs; /* number of transmit segs per pkt */