/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008 Stanislav Sedov <[email protected]>.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef IF_AEVAR_H28#define IF_AEVAR_H2930/*31* Supported chips identifiers.32*/33#define VENDORID_ATTANSIC 0x196934#define DEVICEID_ATTANSIC_L2 0x20483536/* How much to wait for reset to complete (10 microsecond units). */37#define AE_RESET_TIMEOUT 1003839/* How much to wait for device to enter idle state (100 microsecond units). */40#define AE_IDLE_TIMEOUT 1004142/* How much to wait for MDIO to do the work (2 microsecond units). */43#define AE_MDIO_TIMEOUT 104445/* How much to wait for VPD reading operation to complete (2 ms units). */46#define AE_VPD_TIMEOUT 104748/* How much to wait for send operation to complete (HZ units). */49#define AE_TX_TIMEOUT 55051/* Default PHY address. */52#define AE_PHYADDR_DEFAULT 05354/* Tx packet descriptor header format. */55typedef struct ae_txd {56uint16_t len;57uint16_t vlan;58} __packed ae_txd_t;5960/* Tx status descriptor format. */61typedef struct ae_txs {62uint16_t len;63uint16_t flags;64} __packed ae_txs_t;6566/* Rx packet descriptor format. */67typedef struct ae_rxd {68uint16_t len;69uint16_t flags;70uint16_t vlan;71uint16_t __pad;72uint8_t data[1528];73} __packed ae_rxd_t;7475/* Statistics. */76typedef struct ae_stats {77uint32_t rx_bcast;78uint32_t rx_mcast;79uint32_t rx_pause;80uint32_t rx_ctrl;81uint32_t rx_crcerr;82uint32_t rx_codeerr;83uint32_t rx_runt;84uint32_t rx_frag;85uint32_t rx_trunc;86uint32_t rx_align;87uint32_t tx_bcast;88uint32_t tx_mcast;89uint32_t tx_pause;90uint32_t tx_ctrl;91uint32_t tx_defer;92uint32_t tx_excdefer;93uint32_t tx_singlecol;94uint32_t tx_multicol;95uint32_t tx_latecol;96uint32_t tx_abortcol;97uint32_t tx_underrun;98} ae_stats_t;99100/* Software state structure. */101typedef struct ae_softc {102if_t ifp;103device_t dev;104device_t miibus;105struct resource *mem[1];106struct resource_spec *spec_mem;107struct resource *irq[1];108struct resource_spec *spec_irq;109void *intrhand;110111struct mtx mtx;112113uint8_t eaddr[ETHER_ADDR_LEN];114uint8_t flags;115int if_flags;116117struct callout tick_ch;118119/* Tasks. */120struct task int_task;121struct task link_task;122struct taskqueue *tq;123124/* DMA tags. */125bus_dma_tag_t dma_parent_tag;126bus_dma_tag_t dma_rxd_tag;127bus_dma_tag_t dma_txd_tag;128bus_dma_tag_t dma_txs_tag;129bus_dmamap_t dma_rxd_map;130bus_dmamap_t dma_txd_map;131bus_dmamap_t dma_txs_map;132133bus_addr_t dma_rxd_busaddr;134bus_addr_t dma_txd_busaddr;135bus_addr_t dma_txs_busaddr;136137char *rxd_base_dma; /* Start of allocated area. */138ae_rxd_t *rxd_base; /* Start of RxD ring. */139char *txd_base; /* Start of TxD ring. */140ae_txs_t *txs_base; /* Start of TxS ring. */141142/* Ring pointers. */143unsigned int rxd_cur;144unsigned int txd_cur;145unsigned int txs_cur;146unsigned int txs_ack;147unsigned int txd_ack;148149int tx_inproc; /* Active Tx frames in ring. */150int wd_timer;151152ae_stats_t stats;153} ae_softc_t;154155#define AE_LOCK(_sc) mtx_lock(&(_sc)->mtx)156#define AE_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx)157#define AE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED)158159#define BUS_ADDR_LO(x) ((uint64_t) (x) & 0xFFFFFFFF)160#define BUS_ADDR_HI(x) ((uint64_t) (x) >> 32)161162#define AE_FLAG_LINK 0x01 /* Has link. */163#define AE_FLAG_DETACH 0x02 /* Is detaching. */164#define AE_FLAG_TXAVAIL 0x04 /* Tx'es available. */165#define AE_FLAG_MSI 0x08 /* Using MSI. */166#define AE_FLAG_PMG 0x10 /* Supports PCI power management. */167168#endif /* IF_AEVAR_H */169170171