1098ca2bdSWarner Losh /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4ba8c6fd5SDavid Greenman * Copyright (c) 1995, David Greenman 5ba8c6fd5SDavid Greenman * All rights reserved. 6ba8c6fd5SDavid Greenman * 7ba8c6fd5SDavid Greenman * Redistribution and use in source and binary forms, with or without 8ba8c6fd5SDavid Greenman * modification, are permitted provided that the following conditions 9ba8c6fd5SDavid Greenman * are met: 10ba8c6fd5SDavid Greenman * 1. Redistributions of source code must retain the above copyright 11ba8c6fd5SDavid Greenman * notice unmodified, this list of conditions, and the following 12ba8c6fd5SDavid Greenman * disclaimer. 13ba8c6fd5SDavid Greenman * 2. Redistributions in binary form must reproduce the above copyright 14ba8c6fd5SDavid Greenman * notice, this list of conditions and the following disclaimer in the 15ba8c6fd5SDavid Greenman * documentation and/or other materials provided with the distribution. 16ba8c6fd5SDavid Greenman * 17ba8c6fd5SDavid Greenman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18ba8c6fd5SDavid Greenman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19ba8c6fd5SDavid Greenman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20ba8c6fd5SDavid Greenman * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21ba8c6fd5SDavid Greenman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22ba8c6fd5SDavid Greenman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23ba8c6fd5SDavid Greenman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24ba8c6fd5SDavid Greenman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25ba8c6fd5SDavid Greenman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26ba8c6fd5SDavid Greenman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27ba8c6fd5SDavid Greenman * SUCH DAMAGE. 28ba8c6fd5SDavid Greenman */ 29ba8c6fd5SDavid Greenman 30ba8c6fd5SDavid Greenman /* 31ba8c6fd5SDavid Greenman * Misc. defintions for the Intel EtherExpress Pro/100B PCI Fast 32ba8c6fd5SDavid Greenman * Ethernet driver 33ba8c6fd5SDavid Greenman */ 34f7788e8eSJonathan Lemon 35f7788e8eSJonathan Lemon /* 36f7788e8eSJonathan Lemon * Number of transmit control blocks. This determines the number 37f7788e8eSJonathan Lemon * of transmit buffers that can be chained in the CB list. 38f7788e8eSJonathan Lemon * This must be a power of two. 39f7788e8eSJonathan Lemon */ 40f7788e8eSJonathan Lemon #define FXP_NTXCB 128 414e53f837SPyun YongHyeon #define FXP_NTXCB_HIWAT ((FXP_NTXCB * 7) / 10) 42f7788e8eSJonathan Lemon 43f7788e8eSJonathan Lemon /* 44c21e84e4SPyun YongHyeon * Maximum size of a DMA segment. 45c21e84e4SPyun YongHyeon */ 46c21e84e4SPyun YongHyeon #define FXP_TSO_SEGSIZE 4096 47c21e84e4SPyun YongHyeon 48c21e84e4SPyun YongHyeon /* 49b2badf02SMaxime Henrion * Size of the TxCB list. 50b2badf02SMaxime Henrion */ 51b2badf02SMaxime Henrion #define FXP_TXCB_SZ (FXP_NTXCB * sizeof(struct fxp_cb_tx)) 52b2badf02SMaxime Henrion 53b2badf02SMaxime Henrion /* 54b2badf02SMaxime Henrion * Macro to obtain the DMA address of a virtual address in the 55b2badf02SMaxime Henrion * TxCB list based on the base DMA address of the TxCB list. 56b2badf02SMaxime Henrion */ 57b2badf02SMaxime Henrion #define FXP_TXCB_DMA_ADDR(sc, addr) \ 58b2badf02SMaxime Henrion (sc->fxp_desc.cbl_addr + (uintptr_t)addr - \ 59b2badf02SMaxime Henrion (uintptr_t)sc->fxp_desc.cbl_list) 60b2badf02SMaxime Henrion 61b2badf02SMaxime Henrion /* 62f7788e8eSJonathan Lemon * Number of completed TX commands at which point an interrupt 63f7788e8eSJonathan Lemon * will be generated to garbage collect the attached buffers. 64f7788e8eSJonathan Lemon * Must be at least one less than FXP_NTXCB, and should be 65f7788e8eSJonathan Lemon * enough less so that the transmitter doesn't becomes idle 66f7788e8eSJonathan Lemon * during the buffer rundown (which would reduce performance). 67f7788e8eSJonathan Lemon */ 68f7788e8eSJonathan Lemon #define FXP_CXINT_THRESH 120 69f7788e8eSJonathan Lemon 70f7788e8eSJonathan Lemon /* 71f7788e8eSJonathan Lemon * TxCB list index mask. This is used to do list wrap-around. 72f7788e8eSJonathan Lemon */ 73f7788e8eSJonathan Lemon #define FXP_TXCB_MASK (FXP_NTXCB - 1) 74f7788e8eSJonathan Lemon 75f7788e8eSJonathan Lemon /* 76f7788e8eSJonathan Lemon * Number of receive frame area buffers. These are large so chose 77f7788e8eSJonathan Lemon * wisely. 78f7788e8eSJonathan Lemon */ 79e4fc250cSLuigi Rizzo #ifdef DEVICE_POLLING 80e4fc250cSLuigi Rizzo #define FXP_NRFABUFS 192 81e4fc250cSLuigi Rizzo #else 82f7788e8eSJonathan Lemon #define FXP_NRFABUFS 64 83e4fc250cSLuigi Rizzo #endif 84f7788e8eSJonathan Lemon 85f7788e8eSJonathan Lemon /* 86f7788e8eSJonathan Lemon * Maximum number of seconds that the receiver can be idle before we 87f7788e8eSJonathan Lemon * assume it's dead and attempt to reset it by reprogramming the 88f7788e8eSJonathan Lemon * multicast filter. This is part of a work-around for a bug in the 89f7788e8eSJonathan Lemon * NIC. See fxp_stats_update(). 90f7788e8eSJonathan Lemon */ 91f7788e8eSJonathan Lemon #define FXP_MAX_RX_IDLE 15 92f7788e8eSJonathan Lemon 939a7a8c90SJonathan Lemon /* 949a7a8c90SJonathan Lemon * Default maximum time, in microseconds, that an interrupt may be delayed 959a7a8c90SJonathan Lemon * in an attempt to coalesce interrupts. This is only effective if the Intel 969a7a8c90SJonathan Lemon * microcode is loaded, and may be changed via either loader tunables or 979a7a8c90SJonathan Lemon * sysctl. See also the CPUSAVER_DWORD entry in rcvbundl.h. 989a7a8c90SJonathan Lemon */ 999a7a8c90SJonathan Lemon #define TUNABLE_INT_DELAY 1000 1009a7a8c90SJonathan Lemon 1019a7a8c90SJonathan Lemon /* 1029a7a8c90SJonathan Lemon * Default number of packets that will be bundled, before an interrupt is 1039a7a8c90SJonathan Lemon * generated. This is only effective if the Intel microcode is loaded, and 1049a7a8c90SJonathan Lemon * may be changed via either loader tunables or sysctl. This may not be 1059a7a8c90SJonathan Lemon * present in all microcode revisions, see also the CPUSAVER_BUNDLE_MAX_DWORD 1069a7a8c90SJonathan Lemon * entry in rcvbundl.h. 1079a7a8c90SJonathan Lemon */ 1089a7a8c90SJonathan Lemon #define TUNABLE_BUNDLE_MAX 6 1099a7a8c90SJonathan Lemon 110f7788e8eSJonathan Lemon #define FXP_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 111f7788e8eSJonathan Lemon #define FXP_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 11267fc050fSMaxime Henrion #define FXP_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what)) 113f7788e8eSJonathan Lemon 114b2badf02SMaxime Henrion /* 115b2badf02SMaxime Henrion * Structures to handle TX and RX descriptors. 116b2badf02SMaxime Henrion */ 117b2badf02SMaxime Henrion struct fxp_rx { 118b2badf02SMaxime Henrion struct fxp_rx *rx_next; 119b2badf02SMaxime Henrion struct mbuf *rx_mbuf; 120b2badf02SMaxime Henrion bus_dmamap_t rx_map; 12174d1ed23SMaxime Henrion uint32_t rx_addr; 122b2badf02SMaxime Henrion }; 123b2badf02SMaxime Henrion 124b2badf02SMaxime Henrion struct fxp_tx { 125b2badf02SMaxime Henrion struct fxp_tx *tx_next; 126b2badf02SMaxime Henrion struct fxp_cb_tx *tx_cb; 127b2badf02SMaxime Henrion struct mbuf *tx_mbuf; 128b2badf02SMaxime Henrion bus_dmamap_t tx_map; 129b2badf02SMaxime Henrion }; 130b2badf02SMaxime Henrion 131b2badf02SMaxime Henrion struct fxp_desc_list { 132b2badf02SMaxime Henrion struct fxp_rx rx_list[FXP_NRFABUFS]; 133b2badf02SMaxime Henrion struct fxp_tx tx_list[FXP_NTXCB]; 134b2badf02SMaxime Henrion struct fxp_tx mcs_tx; 135b2badf02SMaxime Henrion struct fxp_rx *rx_head; 136b2badf02SMaxime Henrion struct fxp_rx *rx_tail; 137b2badf02SMaxime Henrion struct fxp_tx *tx_first; 138b2badf02SMaxime Henrion struct fxp_tx *tx_last; 139b2badf02SMaxime Henrion struct fxp_rfa *rfa_list; 140b2badf02SMaxime Henrion struct fxp_cb_tx *cbl_list; 14174d1ed23SMaxime Henrion uint32_t cbl_addr; 142b2badf02SMaxime Henrion bus_dma_tag_t rx_tag; 143b2badf02SMaxime Henrion }; 144f7788e8eSJonathan Lemon 145b96ad4b2SPyun YongHyeon struct fxp_ident { 146aa6b24dcSWarner Losh uint16_t vendor; 147aa6b24dcSWarner Losh uint16_t device; 148b96ad4b2SPyun YongHyeon int16_t revid; /* -1 matches anything */ 149b96ad4b2SPyun YongHyeon uint8_t ich; 150e0fe5c6dSMarius Strobl const char *name; 151b96ad4b2SPyun YongHyeon }; 152b96ad4b2SPyun YongHyeon 1538da9c507SPyun YongHyeon struct fxp_hwstats { 1548da9c507SPyun YongHyeon uint32_t tx_good; 1558da9c507SPyun YongHyeon uint32_t tx_maxcols; 1568da9c507SPyun YongHyeon uint32_t tx_latecols; 1578da9c507SPyun YongHyeon uint32_t tx_underruns; 1588da9c507SPyun YongHyeon uint32_t tx_lostcrs; 1598da9c507SPyun YongHyeon uint32_t tx_deffered; 1608da9c507SPyun YongHyeon uint32_t tx_single_collisions; 1618da9c507SPyun YongHyeon uint32_t tx_multiple_collisions; 1628da9c507SPyun YongHyeon uint32_t tx_total_collisions; 1638da9c507SPyun YongHyeon uint32_t tx_pause; 1648da9c507SPyun YongHyeon uint32_t tx_tco; 1658da9c507SPyun YongHyeon uint32_t rx_good; 1668da9c507SPyun YongHyeon uint32_t rx_crc_errors; 1678da9c507SPyun YongHyeon uint32_t rx_alignment_errors; 1688da9c507SPyun YongHyeon uint32_t rx_rnr_errors; 1698da9c507SPyun YongHyeon uint32_t rx_overrun_errors; 1708da9c507SPyun YongHyeon uint32_t rx_cdt_errors; 1718da9c507SPyun YongHyeon uint32_t rx_shortframes; 1728da9c507SPyun YongHyeon uint32_t rx_pause; 1738da9c507SPyun YongHyeon uint32_t rx_controls; 1748da9c507SPyun YongHyeon uint32_t rx_tco; 1758da9c507SPyun YongHyeon }; 1768da9c507SPyun YongHyeon 17736143875SDavid Greenman /* 17836143875SDavid Greenman * NOTE: Elements are ordered for optimal cacheline behavior, and NOT 17936143875SDavid Greenman * for functional grouping. 18036143875SDavid Greenman */ 181ba8c6fd5SDavid Greenman struct fxp_softc { 18241eb5ac3SMarcel Moolenaar void *ifp; /* per-interface network data */ 18305bd8c22SMaxime Henrion struct resource *fxp_res[2]; /* I/O and IRQ resources */ 18405bd8c22SMaxime Henrion struct resource_spec *fxp_spec; /* the resource spec we used */ 1856182fdbdSPeter Wemm void *ih; /* interrupt handler cookie */ 186e0fe5c6dSMarius Strobl const struct fxp_ident *ident; 1870f4dc94cSChuck Paterson struct mtx sc_mtx; 188a2057a72SPyun YongHyeon bus_dma_tag_t fxp_txmtag; /* bus DMA tag for Tx mbufs */ 189a2057a72SPyun YongHyeon bus_dma_tag_t fxp_rxmtag; /* bus DMA tag for Rx mbufs */ 190b2badf02SMaxime Henrion bus_dma_tag_t fxp_stag; /* bus DMA tag for stats */ 191b2badf02SMaxime Henrion bus_dmamap_t fxp_smap; /* bus DMA map for stats */ 192b2badf02SMaxime Henrion bus_dma_tag_t cbl_tag; /* DMA tag for the TxCB list */ 193b2badf02SMaxime Henrion bus_dmamap_t cbl_map; /* DMA map for the TxCB list */ 194b2badf02SMaxime Henrion bus_dma_tag_t mcs_tag; /* DMA tag for the multicast setup */ 195b2badf02SMaxime Henrion bus_dmamap_t mcs_map; /* DMA map for the multicast setup */ 196b2badf02SMaxime Henrion bus_dmamap_t spare_map; /* spare DMA map */ 197b2badf02SMaxime Henrion struct fxp_desc_list fxp_desc; /* descriptors management struct */ 19840c20505SMaxime Henrion int maxtxseg; /* maximum # of TX segments */ 199c21e84e4SPyun YongHyeon int maxsegsize; /* maximum size of a TX segment */ 20036143875SDavid Greenman int tx_queued; /* # of active TxCB's */ 201ba8c6fd5SDavid Greenman struct fxp_stats *fxp_stats; /* Pointer to interface stats */ 20274d1ed23SMaxime Henrion uint32_t stats_addr; /* DMA address of the stats structure */ 2038da9c507SPyun YongHyeon struct fxp_hwstats fxp_hwstats; 204188e6434SDavid Greenman int rx_idle_secs; /* # of seconds RX has been idle */ 20545276e4aSSam Leffler struct callout stat_ch; /* stat callout */ 206df79d527SGleb Smirnoff int watchdog_timer; /* seconds until chip reset */ 207188e6434SDavid Greenman struct fxp_cb_mcs *mcsp; /* Pointer to mcast setup descriptor */ 20874d1ed23SMaxime Henrion uint32_t mcs_addr; /* DMA address of the multicast cmd */ 20936143875SDavid Greenman struct ifmedia sc_media; /* media information */ 210f7788e8eSJonathan Lemon device_t miibus; 211f7788e8eSJonathan Lemon device_t dev; 2129a7a8c90SJonathan Lemon int tunable_int_delay; /* interrupt delay value for ucode */ 2139a7a8c90SJonathan Lemon int tunable_bundle_max; /* max # frames per interrupt (ucode) */ 2140f1db1d6SMaxime Henrion int rnr; /* RNR events */ 215e9bf2fa7SDavid Greenman int eeprom_size; /* size of serial EEPROM */ 216704d1965SWarner Losh int suspended; /* 0 = normal 1 = suspended or dead */ 2172e2b8238SJonathan Lemon int cu_resume_bug; 2189a7a8c90SJonathan Lemon int revision; 219f7788e8eSJonathan Lemon int flags; 2206b24912cSPyun YongHyeon int if_flags; 22174d1ed23SMaxime Henrion uint8_t rfa_size; 22274d1ed23SMaxime Henrion uint32_t tx_cmd; 2238262183eSPyun YongHyeon uint16_t eeprom[256]; 224ba8c6fd5SDavid Greenman }; 225ba8c6fd5SDavid Greenman 226f7788e8eSJonathan Lemon #define FXP_FLAG_MWI_ENABLE 0x0001 /* MWI enable */ 227f7788e8eSJonathan Lemon #define FXP_FLAG_READ_ALIGN 0x0002 /* align read access with cacheline */ 228f7788e8eSJonathan Lemon #define FXP_FLAG_WRITE_ALIGN 0x0004 /* end write on cacheline */ 229f7788e8eSJonathan Lemon #define FXP_FLAG_EXT_TXCB 0x0008 /* enable use of extended TXCB */ 230f7788e8eSJonathan Lemon #define FXP_FLAG_SERIAL_MEDIA 0x0010 /* 10Mbps serial interface */ 231f7788e8eSJonathan Lemon #define FXP_FLAG_LONG_PKT_EN 0x0020 /* enable long packet reception */ 2322e2b8238SJonathan Lemon #define FXP_FLAG_CU_RESUME_BUG 0x0080 /* requires workaround for CU_RESUME */ 2339a7a8c90SJonathan Lemon #define FXP_FLAG_UCODE 0x0100 /* ucode is loaded */ 234947e3815SIan Dowse #define FXP_FLAG_DEFERRED_RNR 0x0200 /* DEVICE_POLLING deferred RNR */ 235c8bca6dcSBill Paul #define FXP_FLAG_EXT_RFA 0x0400 /* extended RFDs for csum offload */ 2368ef1f631SYaroslav Tykhiy #define FXP_FLAG_SAVE_BAD 0x0800 /* save bad pkts: bad size, CRC, etc */ 237f13075afSPyun YongHyeon #define FXP_FLAG_82559_RXCSUM 0x1000 /* 82559 compatible RX checksum */ 2387137cea0SPyun YongHyeon #define FXP_FLAG_WOLCAP 0x2000 /* WOL capability */ 2397137cea0SPyun YongHyeon #define FXP_FLAG_WOL 0x4000 /* WOL active */ 24043d8b117SPyun YongHyeon #define FXP_FLAG_RXBUG 0x8000 /* Rx lock-up bug */ 2411343a72fSPyun YongHyeon #define FXP_FLAG_NO_UCODE 0x10000 /* ucode is not applicable */ 242f7788e8eSJonathan Lemon 243ba8c6fd5SDavid Greenman /* Macros to ease CSR access. */ 24405bd8c22SMaxime Henrion #define CSR_READ_1(sc, reg) bus_read_1(sc->fxp_res[0], reg) 24505bd8c22SMaxime Henrion #define CSR_READ_2(sc, reg) bus_read_2(sc->fxp_res[0], reg) 24605bd8c22SMaxime Henrion #define CSR_READ_4(sc, reg) bus_read_4(sc->fxp_res[0], reg) 24705bd8c22SMaxime Henrion #define CSR_WRITE_1(sc, reg, val) bus_write_1(sc->fxp_res[0], reg, val) 24805bd8c22SMaxime Henrion #define CSR_WRITE_2(sc, reg, val) bus_write_2(sc->fxp_res[0], reg, val) 24905bd8c22SMaxime Henrion #define CSR_WRITE_4(sc, reg, val) bus_write_4(sc->fxp_res[0], reg, val) 250