16c8d8eccSSepherosa Ziehau /* 26c8d8eccSSepherosa Ziehau * Copyright (c) 2001 Wind River Systems 36c8d8eccSSepherosa Ziehau * Copyright (c) 1997, 1998, 1999, 2001 46c8d8eccSSepherosa Ziehau * Bill Paul <wpaul@windriver.com>. All rights reserved. 56c8d8eccSSepherosa Ziehau * 66c8d8eccSSepherosa Ziehau * Redistribution and use in source and binary forms, with or without 76c8d8eccSSepherosa Ziehau * modification, are permitted provided that the following conditions 86c8d8eccSSepherosa Ziehau * are met: 96c8d8eccSSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright 106c8d8eccSSepherosa Ziehau * notice, this list of conditions and the following disclaimer. 116c8d8eccSSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright 126c8d8eccSSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the 136c8d8eccSSepherosa Ziehau * documentation and/or other materials provided with the distribution. 146c8d8eccSSepherosa Ziehau * 3. All advertising materials mentioning features or use of this software 156c8d8eccSSepherosa Ziehau * must display the following acknowledgement: 166c8d8eccSSepherosa Ziehau * This product includes software developed by Bill Paul. 176c8d8eccSSepherosa Ziehau * 4. Neither the name of the author nor the names of any co-contributors 186c8d8eccSSepherosa Ziehau * may be used to endorse or promote products derived from this software 196c8d8eccSSepherosa Ziehau * without specific prior written permission. 206c8d8eccSSepherosa Ziehau * 216c8d8eccSSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 226c8d8eccSSepherosa Ziehau * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 236c8d8eccSSepherosa Ziehau * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 246c8d8eccSSepherosa Ziehau * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 256c8d8eccSSepherosa Ziehau * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 266c8d8eccSSepherosa Ziehau * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 276c8d8eccSSepherosa Ziehau * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 286c8d8eccSSepherosa Ziehau * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 296c8d8eccSSepherosa Ziehau * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 306c8d8eccSSepherosa Ziehau * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 316c8d8eccSSepherosa Ziehau * THE POSSIBILITY OF SUCH DAMAGE. 326c8d8eccSSepherosa Ziehau * 336c8d8eccSSepherosa Ziehau * $FreeBSD: src/sys/dev/bge/if_bge.c,v 1.3.2.39 2005/07/03 03:41:18 silby Exp $ 346c8d8eccSSepherosa Ziehau */ 356c8d8eccSSepherosa Ziehau 3666deb1c1SSepherosa Ziehau #include "opt_bnx.h" 3739a8d43aSSepherosa Ziehau #include "opt_ifpoll.h" 386c8d8eccSSepherosa Ziehau 396c8d8eccSSepherosa Ziehau #include <sys/param.h> 406c8d8eccSSepherosa Ziehau #include <sys/bus.h> 416c8d8eccSSepherosa Ziehau #include <sys/endian.h> 426c8d8eccSSepherosa Ziehau #include <sys/kernel.h> 436c8d8eccSSepherosa Ziehau #include <sys/interrupt.h> 446c8d8eccSSepherosa Ziehau #include <sys/mbuf.h> 456c8d8eccSSepherosa Ziehau #include <sys/malloc.h> 466c8d8eccSSepherosa Ziehau #include <sys/queue.h> 476c8d8eccSSepherosa Ziehau #include <sys/rman.h> 486c8d8eccSSepherosa Ziehau #include <sys/serialize.h> 496c8d8eccSSepherosa Ziehau #include <sys/socket.h> 506c8d8eccSSepherosa Ziehau #include <sys/sockio.h> 516c8d8eccSSepherosa Ziehau #include <sys/sysctl.h> 526c8d8eccSSepherosa Ziehau 5366deb1c1SSepherosa Ziehau #include <netinet/ip.h> 5466deb1c1SSepherosa Ziehau #include <netinet/tcp.h> 5566deb1c1SSepherosa Ziehau 566c8d8eccSSepherosa Ziehau #include <net/bpf.h> 576c8d8eccSSepherosa Ziehau #include <net/ethernet.h> 586c8d8eccSSepherosa Ziehau #include <net/if.h> 596c8d8eccSSepherosa Ziehau #include <net/if_arp.h> 606c8d8eccSSepherosa Ziehau #include <net/if_dl.h> 616c8d8eccSSepherosa Ziehau #include <net/if_media.h> 6239a8d43aSSepherosa Ziehau #include <net/if_poll.h> 636c8d8eccSSepherosa Ziehau #include <net/if_types.h> 646c8d8eccSSepherosa Ziehau #include <net/ifq_var.h> 656c8d8eccSSepherosa Ziehau #include <net/vlan/if_vlan_var.h> 666c8d8eccSSepherosa Ziehau #include <net/vlan/if_vlan_ether.h> 676c8d8eccSSepherosa Ziehau 686c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/mii.h> 696c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/miivar.h> 706c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/brgphyreg.h> 716c8d8eccSSepherosa Ziehau 726c8d8eccSSepherosa Ziehau #include <bus/pci/pcidevs.h> 736c8d8eccSSepherosa Ziehau #include <bus/pci/pcireg.h> 746c8d8eccSSepherosa Ziehau #include <bus/pci/pcivar.h> 756c8d8eccSSepherosa Ziehau 766c8d8eccSSepherosa Ziehau #include <dev/netif/bge/if_bgereg.h> 776c8d8eccSSepherosa Ziehau #include <dev/netif/bnx/if_bnxvar.h> 786c8d8eccSSepherosa Ziehau 796c8d8eccSSepherosa Ziehau /* "device miibus" required. See GENERIC if you get errors here. */ 806c8d8eccSSepherosa Ziehau #include "miibus_if.h" 816c8d8eccSSepherosa Ziehau 823b18363fSSepherosa Ziehau #define BNX_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) 836c8d8eccSSepherosa Ziehau 84df9ccc98SSepherosa Ziehau #define BNX_INTR_CKINTVL ((10 * hz) / 1000) /* 10ms */ 85df9ccc98SSepherosa Ziehau 866c8d8eccSSepherosa Ziehau static const struct bnx_type { 876c8d8eccSSepherosa Ziehau uint16_t bnx_vid; 886c8d8eccSSepherosa Ziehau uint16_t bnx_did; 896c8d8eccSSepherosa Ziehau char *bnx_name; 906c8d8eccSSepherosa Ziehau } bnx_devs[] = { 916c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717, 926c8d8eccSSepherosa Ziehau "Broadcom BCM5717 Gigabit Ethernet" }, 93d79f5d8fSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717C, 94d79f5d8fSSepherosa Ziehau "Broadcom BCM5717C Gigabit Ethernet" }, 956c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5718, 966c8d8eccSSepherosa Ziehau "Broadcom BCM5718 Gigabit Ethernet" }, 976c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5719, 986c8d8eccSSepherosa Ziehau "Broadcom BCM5719 Gigabit Ethernet" }, 996c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5720_ALT, 1006c8d8eccSSepherosa Ziehau "Broadcom BCM5720 Gigabit Ethernet" }, 1016c8d8eccSSepherosa Ziehau 102b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5725, 103b96cbbb6SSepherosa Ziehau "Broadcom BCM5725 Gigabit Ethernet" }, 104b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5727, 105b96cbbb6SSepherosa Ziehau "Broadcom BCM5727 Gigabit Ethernet" }, 106b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5762, 107b96cbbb6SSepherosa Ziehau "Broadcom BCM5762 Gigabit Ethernet" }, 108b96cbbb6SSepherosa Ziehau 1096c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57761, 1106c8d8eccSSepherosa Ziehau "Broadcom BCM57761 Gigabit Ethernet" }, 11132ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57762, 11232ff3c80SSepherosa Ziehau "Broadcom BCM57762 Gigabit Ethernet" }, 1136c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57765, 1146c8d8eccSSepherosa Ziehau "Broadcom BCM57765 Gigabit Ethernet" }, 11532ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57766, 11632ff3c80SSepherosa Ziehau "Broadcom BCM57766 Gigabit Ethernet" }, 11732ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57781, 11832ff3c80SSepherosa Ziehau "Broadcom BCM57781 Gigabit Ethernet" }, 11932ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57782, 12032ff3c80SSepherosa Ziehau "Broadcom BCM57782 Gigabit Ethernet" }, 1216c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57785, 1226c8d8eccSSepherosa Ziehau "Broadcom BCM57785 Gigabit Ethernet" }, 12332ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57786, 12432ff3c80SSepherosa Ziehau "Broadcom BCM57786 Gigabit Ethernet" }, 12532ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57791, 12632ff3c80SSepherosa Ziehau "Broadcom BCM57791 Fast Ethernet" }, 1276c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57795, 1286c8d8eccSSepherosa Ziehau "Broadcom BCM57795 Fast Ethernet" }, 1296c8d8eccSSepherosa Ziehau 1306c8d8eccSSepherosa Ziehau { 0, 0, NULL } 1316c8d8eccSSepherosa Ziehau }; 1326c8d8eccSSepherosa Ziehau 1336c8d8eccSSepherosa Ziehau #define BNX_IS_JUMBO_CAPABLE(sc) ((sc)->bnx_flags & BNX_FLAG_JUMBO) 1346c8d8eccSSepherosa Ziehau #define BNX_IS_5717_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_5717_PLUS) 135f368d0d9SSepherosa Ziehau #define BNX_IS_57765_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_57765_PLUS) 136f368d0d9SSepherosa Ziehau #define BNX_IS_57765_FAMILY(sc) \ 137f368d0d9SSepherosa Ziehau ((sc)->bnx_flags & BNX_FLAG_57765_FAMILY) 1386c8d8eccSSepherosa Ziehau 1396c8d8eccSSepherosa Ziehau typedef int (*bnx_eaddr_fcn_t)(struct bnx_softc *, uint8_t[]); 1406c8d8eccSSepherosa Ziehau 1416c8d8eccSSepherosa Ziehau static int bnx_probe(device_t); 1426c8d8eccSSepherosa Ziehau static int bnx_attach(device_t); 1436c8d8eccSSepherosa Ziehau static int bnx_detach(device_t); 1446c8d8eccSSepherosa Ziehau static void bnx_shutdown(device_t); 1456c8d8eccSSepherosa Ziehau static int bnx_suspend(device_t); 1466c8d8eccSSepherosa Ziehau static int bnx_resume(device_t); 1476c8d8eccSSepherosa Ziehau static int bnx_miibus_readreg(device_t, int, int); 1486c8d8eccSSepherosa Ziehau static int bnx_miibus_writereg(device_t, int, int, int); 1496c8d8eccSSepherosa Ziehau static void bnx_miibus_statchg(device_t); 1506c8d8eccSSepherosa Ziehau 15139a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 15239a8d43aSSepherosa Ziehau static void bnx_npoll(struct ifnet *, struct ifpoll_info *); 15339a8d43aSSepherosa Ziehau static void bnx_npoll_compat(struct ifnet *, void *, int); 1546c8d8eccSSepherosa Ziehau #endif 1556c8d8eccSSepherosa Ziehau static void bnx_intr_legacy(void *); 1566c8d8eccSSepherosa Ziehau static void bnx_msi(void *); 1576c8d8eccSSepherosa Ziehau static void bnx_msi_oneshot(void *); 1586c8d8eccSSepherosa Ziehau static void bnx_intr(struct bnx_softc *); 1596c8d8eccSSepherosa Ziehau static void bnx_enable_intr(struct bnx_softc *); 1606c8d8eccSSepherosa Ziehau static void bnx_disable_intr(struct bnx_softc *); 16133a04907SSepherosa Ziehau static void bnx_txeof(struct bnx_tx_ring *, uint16_t); 162beedf5beSSepherosa Ziehau static void bnx_rxeof(struct bnx_rx_ret_ring *, uint16_t, int); 1630c7da01dSSepherosa Ziehau static int bnx_alloc_intr(struct bnx_softc *); 1640c7da01dSSepherosa Ziehau static int bnx_setup_intr(struct bnx_softc *); 1650c7da01dSSepherosa Ziehau static void bnx_free_intr(struct bnx_softc *); 1666c8d8eccSSepherosa Ziehau 167f0a26983SSepherosa Ziehau static void bnx_start(struct ifnet *, struct ifaltq_subque *); 1686c8d8eccSSepherosa Ziehau static int bnx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); 1696c8d8eccSSepherosa Ziehau static void bnx_init(void *); 1706c8d8eccSSepherosa Ziehau static void bnx_stop(struct bnx_softc *); 1716c8d8eccSSepherosa Ziehau static void bnx_watchdog(struct ifnet *); 1726c8d8eccSSepherosa Ziehau static int bnx_ifmedia_upd(struct ifnet *); 1736c8d8eccSSepherosa Ziehau static void bnx_ifmedia_sts(struct ifnet *, struct ifmediareq *); 1746c8d8eccSSepherosa Ziehau static void bnx_tick(void *); 1756c8d8eccSSepherosa Ziehau 1766c8d8eccSSepherosa Ziehau static int bnx_alloc_jumbo_mem(struct bnx_softc *); 1776c8d8eccSSepherosa Ziehau static void bnx_free_jumbo_mem(struct bnx_softc *); 1786c8d8eccSSepherosa Ziehau static struct bnx_jslot 1796c8d8eccSSepherosa Ziehau *bnx_jalloc(struct bnx_softc *); 1806c8d8eccSSepherosa Ziehau static void bnx_jfree(void *); 1816c8d8eccSSepherosa Ziehau static void bnx_jref(void *); 182beedf5beSSepherosa Ziehau static int bnx_newbuf_std(struct bnx_rx_ret_ring *, int, int); 1836c8d8eccSSepherosa Ziehau static int bnx_newbuf_jumbo(struct bnx_softc *, int, int); 184beedf5beSSepherosa Ziehau static void bnx_setup_rxdesc_std(struct bnx_rx_std_ring *, int); 1856c8d8eccSSepherosa Ziehau static void bnx_setup_rxdesc_jumbo(struct bnx_softc *, int); 186beedf5beSSepherosa Ziehau static int bnx_init_rx_ring_std(struct bnx_rx_std_ring *); 187beedf5beSSepherosa Ziehau static void bnx_free_rx_ring_std(struct bnx_rx_std_ring *); 1886c8d8eccSSepherosa Ziehau static int bnx_init_rx_ring_jumbo(struct bnx_softc *); 1896c8d8eccSSepherosa Ziehau static void bnx_free_rx_ring_jumbo(struct bnx_softc *); 19033a04907SSepherosa Ziehau static void bnx_free_tx_ring(struct bnx_tx_ring *); 19133a04907SSepherosa Ziehau static int bnx_init_tx_ring(struct bnx_tx_ring *); 19233a04907SSepherosa Ziehau static int bnx_create_tx_ring(struct bnx_tx_ring *); 19333a04907SSepherosa Ziehau static void bnx_destroy_tx_ring(struct bnx_tx_ring *); 194beedf5beSSepherosa Ziehau static int bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *); 195beedf5beSSepherosa Ziehau static void bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *); 196beedf5beSSepherosa Ziehau static int bnx_dma_alloc(device_t); 1976c8d8eccSSepherosa Ziehau static void bnx_dma_free(struct bnx_softc *); 1986c8d8eccSSepherosa Ziehau static int bnx_dma_block_alloc(struct bnx_softc *, bus_size_t, 1996c8d8eccSSepherosa Ziehau bus_dma_tag_t *, bus_dmamap_t *, void **, bus_addr_t *); 2006c8d8eccSSepherosa Ziehau static void bnx_dma_block_free(bus_dma_tag_t, bus_dmamap_t, void *); 2016c8d8eccSSepherosa Ziehau static struct mbuf * 2026c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *); 20333a04907SSepherosa Ziehau static int bnx_encap(struct bnx_tx_ring *, struct mbuf **, 204c9b7f592SSepherosa Ziehau uint32_t *, int *); 20533a04907SSepherosa Ziehau static int bnx_setup_tso(struct bnx_tx_ring *, struct mbuf **, 20666deb1c1SSepherosa Ziehau uint16_t *, uint16_t *); 2076c8d8eccSSepherosa Ziehau 2086c8d8eccSSepherosa Ziehau static void bnx_reset(struct bnx_softc *); 2096c8d8eccSSepherosa Ziehau static int bnx_chipinit(struct bnx_softc *); 2106c8d8eccSSepherosa Ziehau static int bnx_blockinit(struct bnx_softc *); 2116c8d8eccSSepherosa Ziehau static void bnx_stop_block(struct bnx_softc *, bus_size_t, uint32_t); 2126c8d8eccSSepherosa Ziehau static void bnx_enable_msi(struct bnx_softc *sc); 2136c8d8eccSSepherosa Ziehau static void bnx_setmulti(struct bnx_softc *); 2146c8d8eccSSepherosa Ziehau static void bnx_setpromisc(struct bnx_softc *); 2156c8d8eccSSepherosa Ziehau static void bnx_stats_update_regs(struct bnx_softc *); 2166c8d8eccSSepherosa Ziehau static uint32_t bnx_dma_swap_options(struct bnx_softc *); 2176c8d8eccSSepherosa Ziehau 2186c8d8eccSSepherosa Ziehau static uint32_t bnx_readmem_ind(struct bnx_softc *, uint32_t); 2196c8d8eccSSepherosa Ziehau static void bnx_writemem_ind(struct bnx_softc *, uint32_t, uint32_t); 2206c8d8eccSSepherosa Ziehau #ifdef notdef 2216c8d8eccSSepherosa Ziehau static uint32_t bnx_readreg_ind(struct bnx_softc *, uint32_t); 2226c8d8eccSSepherosa Ziehau #endif 2236c8d8eccSSepherosa Ziehau static void bnx_writemem_direct(struct bnx_softc *, uint32_t, uint32_t); 2246c8d8eccSSepherosa Ziehau static void bnx_writembx(struct bnx_softc *, int, int); 2256c8d8eccSSepherosa Ziehau static int bnx_read_nvram(struct bnx_softc *, caddr_t, int, int); 2266c8d8eccSSepherosa Ziehau static uint8_t bnx_eeprom_getbyte(struct bnx_softc *, uint32_t, uint8_t *); 2276c8d8eccSSepherosa Ziehau static int bnx_read_eeprom(struct bnx_softc *, caddr_t, uint32_t, size_t); 2286c8d8eccSSepherosa Ziehau 2296c8d8eccSSepherosa Ziehau static void bnx_tbi_link_upd(struct bnx_softc *, uint32_t); 2306c8d8eccSSepherosa Ziehau static void bnx_copper_link_upd(struct bnx_softc *, uint32_t); 2316c8d8eccSSepherosa Ziehau static void bnx_autopoll_link_upd(struct bnx_softc *, uint32_t); 2326c8d8eccSSepherosa Ziehau static void bnx_link_poll(struct bnx_softc *); 2336c8d8eccSSepherosa Ziehau 2346c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_mem(struct bnx_softc *, uint8_t[]); 2356c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_nvram(struct bnx_softc *, uint8_t[]); 2366c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_eeprom(struct bnx_softc *, uint8_t[]); 2376c8d8eccSSepherosa Ziehau static int bnx_get_eaddr(struct bnx_softc *, uint8_t[]); 2386c8d8eccSSepherosa Ziehau 2396c8d8eccSSepherosa Ziehau static void bnx_coal_change(struct bnx_softc *); 240aad4de2bSSepherosa Ziehau static int bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS); 241472c99c8SSepherosa Ziehau static int bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS); 2426c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS); 2436c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS); 2446c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS); 2456c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS); 2466c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2476c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2486c8d8eccSSepherosa Ziehau static int bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *, 2496c8d8eccSSepherosa Ziehau int, int, uint32_t); 2506c8d8eccSSepherosa Ziehau 2516c8d8eccSSepherosa Ziehau static int bnx_msi_enable = 1; 2526c8d8eccSSepherosa Ziehau TUNABLE_INT("hw.bnx.msi.enable", &bnx_msi_enable); 2536c8d8eccSSepherosa Ziehau 2546c8d8eccSSepherosa Ziehau static device_method_t bnx_methods[] = { 2556c8d8eccSSepherosa Ziehau /* Device interface */ 2566c8d8eccSSepherosa Ziehau DEVMETHOD(device_probe, bnx_probe), 2576c8d8eccSSepherosa Ziehau DEVMETHOD(device_attach, bnx_attach), 2586c8d8eccSSepherosa Ziehau DEVMETHOD(device_detach, bnx_detach), 2596c8d8eccSSepherosa Ziehau DEVMETHOD(device_shutdown, bnx_shutdown), 2606c8d8eccSSepherosa Ziehau DEVMETHOD(device_suspend, bnx_suspend), 2616c8d8eccSSepherosa Ziehau DEVMETHOD(device_resume, bnx_resume), 2626c8d8eccSSepherosa Ziehau 2636c8d8eccSSepherosa Ziehau /* bus interface */ 2646c8d8eccSSepherosa Ziehau DEVMETHOD(bus_print_child, bus_generic_print_child), 2656c8d8eccSSepherosa Ziehau DEVMETHOD(bus_driver_added, bus_generic_driver_added), 2666c8d8eccSSepherosa Ziehau 2676c8d8eccSSepherosa Ziehau /* MII interface */ 2686c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_readreg, bnx_miibus_readreg), 2696c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_writereg, bnx_miibus_writereg), 2706c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_statchg, bnx_miibus_statchg), 2716c8d8eccSSepherosa Ziehau 272d3c9c58eSSascha Wildner DEVMETHOD_END 2736c8d8eccSSepherosa Ziehau }; 2746c8d8eccSSepherosa Ziehau 2756c8d8eccSSepherosa Ziehau static DEFINE_CLASS_0(bnx, bnx_driver, bnx_methods, sizeof(struct bnx_softc)); 2766c8d8eccSSepherosa Ziehau static devclass_t bnx_devclass; 2776c8d8eccSSepherosa Ziehau 2786c8d8eccSSepherosa Ziehau DECLARE_DUMMY_MODULE(if_bnx); 2796c8d8eccSSepherosa Ziehau DRIVER_MODULE(if_bnx, pci, bnx_driver, bnx_devclass, NULL, NULL); 2806c8d8eccSSepherosa Ziehau DRIVER_MODULE(miibus, bnx, miibus_driver, miibus_devclass, NULL, NULL); 2816c8d8eccSSepherosa Ziehau 2826c8d8eccSSepherosa Ziehau static uint32_t 2836c8d8eccSSepherosa Ziehau bnx_readmem_ind(struct bnx_softc *sc, uint32_t off) 2846c8d8eccSSepherosa Ziehau { 2856c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 2866c8d8eccSSepherosa Ziehau uint32_t val; 2876c8d8eccSSepherosa Ziehau 2886c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 2896c8d8eccSSepherosa Ziehau val = pci_read_config(dev, BGE_PCI_MEMWIN_DATA, 4); 2906c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 2916c8d8eccSSepherosa Ziehau return (val); 2926c8d8eccSSepherosa Ziehau } 2936c8d8eccSSepherosa Ziehau 2946c8d8eccSSepherosa Ziehau static void 2956c8d8eccSSepherosa Ziehau bnx_writemem_ind(struct bnx_softc *sc, uint32_t off, uint32_t val) 2966c8d8eccSSepherosa Ziehau { 2976c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 2986c8d8eccSSepherosa Ziehau 2996c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 3006c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_DATA, val, 4); 3016c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 3026c8d8eccSSepherosa Ziehau } 3036c8d8eccSSepherosa Ziehau 3046c8d8eccSSepherosa Ziehau static void 3056c8d8eccSSepherosa Ziehau bnx_writemem_direct(struct bnx_softc *sc, uint32_t off, uint32_t val) 3066c8d8eccSSepherosa Ziehau { 3076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3086c8d8eccSSepherosa Ziehau } 3096c8d8eccSSepherosa Ziehau 3106c8d8eccSSepherosa Ziehau static void 3116c8d8eccSSepherosa Ziehau bnx_writembx(struct bnx_softc *sc, int off, int val) 3126c8d8eccSSepherosa Ziehau { 3136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3146c8d8eccSSepherosa Ziehau } 3156c8d8eccSSepherosa Ziehau 3166c8d8eccSSepherosa Ziehau /* 3176c8d8eccSSepherosa Ziehau * Read a sequence of bytes from NVRAM. 3186c8d8eccSSepherosa Ziehau */ 3196c8d8eccSSepherosa Ziehau static int 3206c8d8eccSSepherosa Ziehau bnx_read_nvram(struct bnx_softc *sc, caddr_t dest, int off, int cnt) 3216c8d8eccSSepherosa Ziehau { 3226c8d8eccSSepherosa Ziehau return (1); 3236c8d8eccSSepherosa Ziehau } 3246c8d8eccSSepherosa Ziehau 3256c8d8eccSSepherosa Ziehau /* 3266c8d8eccSSepherosa Ziehau * Read a byte of data stored in the EEPROM at address 'addr.' The 3276c8d8eccSSepherosa Ziehau * BCM570x supports both the traditional bitbang interface and an 3286c8d8eccSSepherosa Ziehau * auto access interface for reading the EEPROM. We use the auto 3296c8d8eccSSepherosa Ziehau * access method. 3306c8d8eccSSepherosa Ziehau */ 3316c8d8eccSSepherosa Ziehau static uint8_t 3326c8d8eccSSepherosa Ziehau bnx_eeprom_getbyte(struct bnx_softc *sc, uint32_t addr, uint8_t *dest) 3336c8d8eccSSepherosa Ziehau { 3346c8d8eccSSepherosa Ziehau int i; 3356c8d8eccSSepherosa Ziehau uint32_t byte = 0; 3366c8d8eccSSepherosa Ziehau 3376c8d8eccSSepherosa Ziehau /* 3386c8d8eccSSepherosa Ziehau * Enable use of auto EEPROM access so we can avoid 3396c8d8eccSSepherosa Ziehau * having to use the bitbang method. 3406c8d8eccSSepherosa Ziehau */ 3416c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_AUTO_EEPROM); 3426c8d8eccSSepherosa Ziehau 3436c8d8eccSSepherosa Ziehau /* Reset the EEPROM, load the clock period. */ 3446c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, 3456c8d8eccSSepherosa Ziehau BGE_EEADDR_RESET|BGE_EEHALFCLK(BGE_HALFCLK_384SCL)); 3466c8d8eccSSepherosa Ziehau DELAY(20); 3476c8d8eccSSepherosa Ziehau 3486c8d8eccSSepherosa Ziehau /* Issue the read EEPROM command. */ 3496c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, BGE_EE_READCMD | addr); 3506c8d8eccSSepherosa Ziehau 3516c8d8eccSSepherosa Ziehau /* Wait for completion */ 3526c8d8eccSSepherosa Ziehau for(i = 0; i < BNX_TIMEOUT * 10; i++) { 3536c8d8eccSSepherosa Ziehau DELAY(10); 3546c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_EE_ADDR) & BGE_EEADDR_DONE) 3556c8d8eccSSepherosa Ziehau break; 3566c8d8eccSSepherosa Ziehau } 3576c8d8eccSSepherosa Ziehau 3586c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 3596c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "eeprom read timed out\n"); 3606c8d8eccSSepherosa Ziehau return(1); 3616c8d8eccSSepherosa Ziehau } 3626c8d8eccSSepherosa Ziehau 3636c8d8eccSSepherosa Ziehau /* Get result. */ 3646c8d8eccSSepherosa Ziehau byte = CSR_READ_4(sc, BGE_EE_DATA); 3656c8d8eccSSepherosa Ziehau 3666c8d8eccSSepherosa Ziehau *dest = (byte >> ((addr % 4) * 8)) & 0xFF; 3676c8d8eccSSepherosa Ziehau 3686c8d8eccSSepherosa Ziehau return(0); 3696c8d8eccSSepherosa Ziehau } 3706c8d8eccSSepherosa Ziehau 3716c8d8eccSSepherosa Ziehau /* 3726c8d8eccSSepherosa Ziehau * Read a sequence of bytes from the EEPROM. 3736c8d8eccSSepherosa Ziehau */ 3746c8d8eccSSepherosa Ziehau static int 3756c8d8eccSSepherosa Ziehau bnx_read_eeprom(struct bnx_softc *sc, caddr_t dest, uint32_t off, size_t len) 3766c8d8eccSSepherosa Ziehau { 3776c8d8eccSSepherosa Ziehau size_t i; 3786c8d8eccSSepherosa Ziehau int err; 3796c8d8eccSSepherosa Ziehau uint8_t byte; 3806c8d8eccSSepherosa Ziehau 3816c8d8eccSSepherosa Ziehau for (byte = 0, err = 0, i = 0; i < len; i++) { 3826c8d8eccSSepherosa Ziehau err = bnx_eeprom_getbyte(sc, off + i, &byte); 3836c8d8eccSSepherosa Ziehau if (err) 3846c8d8eccSSepherosa Ziehau break; 3856c8d8eccSSepherosa Ziehau *(dest + i) = byte; 3866c8d8eccSSepherosa Ziehau } 3876c8d8eccSSepherosa Ziehau 3886c8d8eccSSepherosa Ziehau return(err ? 1 : 0); 3896c8d8eccSSepherosa Ziehau } 3906c8d8eccSSepherosa Ziehau 3916c8d8eccSSepherosa Ziehau static int 3926c8d8eccSSepherosa Ziehau bnx_miibus_readreg(device_t dev, int phy, int reg) 3936c8d8eccSSepherosa Ziehau { 3946c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 3956c8d8eccSSepherosa Ziehau uint32_t val; 3966c8d8eccSSepherosa Ziehau int i; 3976c8d8eccSSepherosa Ziehau 3986c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 3996c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4006c8d8eccSSepherosa Ziehau 4016c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4026c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4036c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4046c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4056c8d8eccSSepherosa Ziehau DELAY(80); 4066c8d8eccSSepherosa Ziehau } 4076c8d8eccSSepherosa Ziehau 4086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ | BGE_MICOMM_BUSY | 4096c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg)); 4106c8d8eccSSepherosa Ziehau 4116c8d8eccSSepherosa Ziehau /* Poll for the PHY register access to complete. */ 4126c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4136c8d8eccSSepherosa Ziehau DELAY(10); 4146c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4156c8d8eccSSepherosa Ziehau if ((val & BGE_MICOMM_BUSY) == 0) { 4166c8d8eccSSepherosa Ziehau DELAY(5); 4176c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4186c8d8eccSSepherosa Ziehau break; 4196c8d8eccSSepherosa Ziehau } 4206c8d8eccSSepherosa Ziehau } 4216c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4226c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY read timed out " 4236c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val 0x%08x)\n", phy, reg, val); 4246c8d8eccSSepherosa Ziehau val = 0; 4256c8d8eccSSepherosa Ziehau } 4266c8d8eccSSepherosa Ziehau 4276c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4286c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4296c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 4306c8d8eccSSepherosa Ziehau DELAY(80); 4316c8d8eccSSepherosa Ziehau } 4326c8d8eccSSepherosa Ziehau 4336c8d8eccSSepherosa Ziehau if (val & BGE_MICOMM_READFAIL) 4346c8d8eccSSepherosa Ziehau return 0; 4356c8d8eccSSepherosa Ziehau 4366c8d8eccSSepherosa Ziehau return (val & 0xFFFF); 4376c8d8eccSSepherosa Ziehau } 4386c8d8eccSSepherosa Ziehau 4396c8d8eccSSepherosa Ziehau static int 4406c8d8eccSSepherosa Ziehau bnx_miibus_writereg(device_t dev, int phy, int reg, int val) 4416c8d8eccSSepherosa Ziehau { 4426c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4436c8d8eccSSepherosa Ziehau int i; 4446c8d8eccSSepherosa Ziehau 4456c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4466c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4476c8d8eccSSepherosa Ziehau 4486c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4496c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4506c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4516c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4526c8d8eccSSepherosa Ziehau DELAY(80); 4536c8d8eccSSepherosa Ziehau } 4546c8d8eccSSepherosa Ziehau 4556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY | 4566c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg) | val); 4576c8d8eccSSepherosa Ziehau 4586c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4596c8d8eccSSepherosa Ziehau DELAY(10); 4606c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) { 4616c8d8eccSSepherosa Ziehau DELAY(5); 4626c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */ 4636c8d8eccSSepherosa Ziehau break; 4646c8d8eccSSepherosa Ziehau } 4656c8d8eccSSepherosa Ziehau } 4666c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4676c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY write timed out " 4686c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val %d)\n", phy, reg, val); 4696c8d8eccSSepherosa Ziehau } 4706c8d8eccSSepherosa Ziehau 4716c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4726c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 4746c8d8eccSSepherosa Ziehau DELAY(80); 4756c8d8eccSSepherosa Ziehau } 4766c8d8eccSSepherosa Ziehau 4776c8d8eccSSepherosa Ziehau return 0; 4786c8d8eccSSepherosa Ziehau } 4796c8d8eccSSepherosa Ziehau 4806c8d8eccSSepherosa Ziehau static void 4816c8d8eccSSepherosa Ziehau bnx_miibus_statchg(device_t dev) 4826c8d8eccSSepherosa Ziehau { 4836c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 4846c8d8eccSSepherosa Ziehau struct mii_data *mii; 4856c8d8eccSSepherosa Ziehau 4866c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 4876c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 4886c8d8eccSSepherosa Ziehau 4896c8d8eccSSepherosa Ziehau if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 4906c8d8eccSSepherosa Ziehau (IFM_ACTIVE | IFM_AVALID)) { 4916c8d8eccSSepherosa Ziehau switch (IFM_SUBTYPE(mii->mii_media_active)) { 4926c8d8eccSSepherosa Ziehau case IFM_10_T: 4936c8d8eccSSepherosa Ziehau case IFM_100_TX: 4946c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 4956c8d8eccSSepherosa Ziehau break; 4966c8d8eccSSepherosa Ziehau case IFM_1000_T: 4976c8d8eccSSepherosa Ziehau case IFM_1000_SX: 4986c8d8eccSSepherosa Ziehau case IFM_2500_SX: 4996c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5006c8d8eccSSepherosa Ziehau break; 5016c8d8eccSSepherosa Ziehau default: 5026c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5036c8d8eccSSepherosa Ziehau break; 5046c8d8eccSSepherosa Ziehau } 5056c8d8eccSSepherosa Ziehau } else { 5066c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5076c8d8eccSSepherosa Ziehau } 5086c8d8eccSSepherosa Ziehau if (sc->bnx_link == 0) 5096c8d8eccSSepherosa Ziehau return; 5106c8d8eccSSepherosa Ziehau 5116c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); 5126c8d8eccSSepherosa Ziehau if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T || 5136c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) { 5146c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); 5156c8d8eccSSepherosa Ziehau } else { 5166c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII); 5176c8d8eccSSepherosa Ziehau } 5186c8d8eccSSepherosa Ziehau 5196c8d8eccSSepherosa Ziehau if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 5206c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5216c8d8eccSSepherosa Ziehau } else { 5226c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5236c8d8eccSSepherosa Ziehau } 5246c8d8eccSSepherosa Ziehau } 5256c8d8eccSSepherosa Ziehau 5266c8d8eccSSepherosa Ziehau /* 5276c8d8eccSSepherosa Ziehau * Memory management for jumbo frames. 5286c8d8eccSSepherosa Ziehau */ 5296c8d8eccSSepherosa Ziehau static int 5306c8d8eccSSepherosa Ziehau bnx_alloc_jumbo_mem(struct bnx_softc *sc) 5316c8d8eccSSepherosa Ziehau { 5326c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 5336c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 5346c8d8eccSSepherosa Ziehau uint8_t *ptr; 5356c8d8eccSSepherosa Ziehau bus_addr_t paddr; 5366c8d8eccSSepherosa Ziehau int i, error; 5376c8d8eccSSepherosa Ziehau 5386c8d8eccSSepherosa Ziehau /* 5396c8d8eccSSepherosa Ziehau * Create tag for jumbo mbufs. 5406c8d8eccSSepherosa Ziehau * This is really a bit of a kludge. We allocate a special 5416c8d8eccSSepherosa Ziehau * jumbo buffer pool which (thanks to the way our DMA 5426c8d8eccSSepherosa Ziehau * memory allocation works) will consist of contiguous 5436c8d8eccSSepherosa Ziehau * pages. This means that even though a jumbo buffer might 5446c8d8eccSSepherosa Ziehau * be larger than a page size, we don't really need to 5456c8d8eccSSepherosa Ziehau * map it into more than one DMA segment. However, the 5466c8d8eccSSepherosa Ziehau * default mbuf tag will result in multi-segment mappings, 5476c8d8eccSSepherosa Ziehau * so we have to create a special jumbo mbuf tag that 5486c8d8eccSSepherosa Ziehau * lets us get away with mapping the jumbo buffers as 5496c8d8eccSSepherosa Ziehau * a single segment. I think eventually the driver should 5506c8d8eccSSepherosa Ziehau * be changed so that it uses ordinary mbufs and cluster 5516c8d8eccSSepherosa Ziehau * buffers, i.e. jumbo frames can span multiple DMA 5526c8d8eccSSepherosa Ziehau * descriptors. But that's a project for another day. 5536c8d8eccSSepherosa Ziehau */ 5546c8d8eccSSepherosa Ziehau 5556c8d8eccSSepherosa Ziehau /* 5566c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo RX ring. 5576c8d8eccSSepherosa Ziehau */ 5586c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_JUMBO_RX_RING_SZ, 5596c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 5606c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_map, 5616c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_jumbo_ring, 5626c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 5636c8d8eccSSepherosa Ziehau if (error) { 5646c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo RX ring\n"); 5656c8d8eccSSepherosa Ziehau return error; 5666c8d8eccSSepherosa Ziehau } 5676c8d8eccSSepherosa Ziehau 5686c8d8eccSSepherosa Ziehau /* 5696c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo buffer block. 5706c8d8eccSSepherosa Ziehau */ 5716c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BNX_JMEM, 5726c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_tag, 5736c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_map, 5746c8d8eccSSepherosa Ziehau (void **)&sc->bnx_ldata.bnx_jumbo_buf, 5756c8d8eccSSepherosa Ziehau &paddr); 5766c8d8eccSSepherosa Ziehau if (error) { 5776c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo buffer\n"); 5786c8d8eccSSepherosa Ziehau return error; 5796c8d8eccSSepherosa Ziehau } 5806c8d8eccSSepherosa Ziehau 5816c8d8eccSSepherosa Ziehau SLIST_INIT(&sc->bnx_jfree_listhead); 5826c8d8eccSSepherosa Ziehau 5836c8d8eccSSepherosa Ziehau /* 5846c8d8eccSSepherosa Ziehau * Now divide it up into 9K pieces and save the addresses 5856c8d8eccSSepherosa Ziehau * in an array. Note that we play an evil trick here by using 5866c8d8eccSSepherosa Ziehau * the first few bytes in the buffer to hold the the address 5876c8d8eccSSepherosa Ziehau * of the softc structure for this interface. This is because 5886c8d8eccSSepherosa Ziehau * bnx_jfree() needs it, but it is called by the mbuf management 5896c8d8eccSSepherosa Ziehau * code which will not pass it to us explicitly. 5906c8d8eccSSepherosa Ziehau */ 5916c8d8eccSSepherosa Ziehau for (i = 0, ptr = sc->bnx_ldata.bnx_jumbo_buf; i < BNX_JSLOTS; i++) { 5926c8d8eccSSepherosa Ziehau entry = &sc->bnx_cdata.bnx_jslots[i]; 5936c8d8eccSSepherosa Ziehau entry->bnx_sc = sc; 5946c8d8eccSSepherosa Ziehau entry->bnx_buf = ptr; 5956c8d8eccSSepherosa Ziehau entry->bnx_paddr = paddr; 5966c8d8eccSSepherosa Ziehau entry->bnx_inuse = 0; 5976c8d8eccSSepherosa Ziehau entry->bnx_slot = i; 5986c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, entry, jslot_link); 5996c8d8eccSSepherosa Ziehau 6006c8d8eccSSepherosa Ziehau ptr += BNX_JLEN; 6016c8d8eccSSepherosa Ziehau paddr += BNX_JLEN; 6026c8d8eccSSepherosa Ziehau } 6036c8d8eccSSepherosa Ziehau return 0; 6046c8d8eccSSepherosa Ziehau } 6056c8d8eccSSepherosa Ziehau 6066c8d8eccSSepherosa Ziehau static void 6076c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(struct bnx_softc *sc) 6086c8d8eccSSepherosa Ziehau { 6096c8d8eccSSepherosa Ziehau /* Destroy jumbo RX ring. */ 6106c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 6116c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_ring_map, 6126c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_jumbo_ring); 6136c8d8eccSSepherosa Ziehau 6146c8d8eccSSepherosa Ziehau /* Destroy jumbo buffer block. */ 6156c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_jumbo_tag, 6166c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_jumbo_map, 6176c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_jumbo_buf); 6186c8d8eccSSepherosa Ziehau } 6196c8d8eccSSepherosa Ziehau 6206c8d8eccSSepherosa Ziehau /* 6216c8d8eccSSepherosa Ziehau * Allocate a jumbo buffer. 6226c8d8eccSSepherosa Ziehau */ 6236c8d8eccSSepherosa Ziehau static struct bnx_jslot * 6246c8d8eccSSepherosa Ziehau bnx_jalloc(struct bnx_softc *sc) 6256c8d8eccSSepherosa Ziehau { 6266c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 6276c8d8eccSSepherosa Ziehau 6286c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 6296c8d8eccSSepherosa Ziehau entry = SLIST_FIRST(&sc->bnx_jfree_listhead); 6306c8d8eccSSepherosa Ziehau if (entry) { 6316c8d8eccSSepherosa Ziehau SLIST_REMOVE_HEAD(&sc->bnx_jfree_listhead, jslot_link); 6326c8d8eccSSepherosa Ziehau entry->bnx_inuse = 1; 6336c8d8eccSSepherosa Ziehau } else { 6346c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "no free jumbo buffers\n"); 6356c8d8eccSSepherosa Ziehau } 6366c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 6376c8d8eccSSepherosa Ziehau return(entry); 6386c8d8eccSSepherosa Ziehau } 6396c8d8eccSSepherosa Ziehau 6406c8d8eccSSepherosa Ziehau /* 6416c8d8eccSSepherosa Ziehau * Adjust usage count on a jumbo buffer. 6426c8d8eccSSepherosa Ziehau */ 6436c8d8eccSSepherosa Ziehau static void 6446c8d8eccSSepherosa Ziehau bnx_jref(void *arg) 6456c8d8eccSSepherosa Ziehau { 6466c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6476c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6486c8d8eccSSepherosa Ziehau 6496c8d8eccSSepherosa Ziehau if (sc == NULL) 6506c8d8eccSSepherosa Ziehau panic("bnx_jref: can't find softc pointer!"); 6516c8d8eccSSepherosa Ziehau 6526c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 6536c8d8eccSSepherosa Ziehau panic("bnx_jref: asked to reference buffer " 6546c8d8eccSSepherosa Ziehau "that we don't manage!"); 6556c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 6566c8d8eccSSepherosa Ziehau panic("bnx_jref: buffer already free!"); 6576c8d8eccSSepherosa Ziehau } else { 6586c8d8eccSSepherosa Ziehau atomic_add_int(&entry->bnx_inuse, 1); 6596c8d8eccSSepherosa Ziehau } 6606c8d8eccSSepherosa Ziehau } 6616c8d8eccSSepherosa Ziehau 6626c8d8eccSSepherosa Ziehau /* 6636c8d8eccSSepherosa Ziehau * Release a jumbo buffer. 6646c8d8eccSSepherosa Ziehau */ 6656c8d8eccSSepherosa Ziehau static void 6666c8d8eccSSepherosa Ziehau bnx_jfree(void *arg) 6676c8d8eccSSepherosa Ziehau { 6686c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6696c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6706c8d8eccSSepherosa Ziehau 6716c8d8eccSSepherosa Ziehau if (sc == NULL) 6726c8d8eccSSepherosa Ziehau panic("bnx_jfree: can't find softc pointer!"); 6736c8d8eccSSepherosa Ziehau 6746c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 6756c8d8eccSSepherosa Ziehau panic("bnx_jfree: asked to free buffer that we don't manage!"); 6766c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 6776c8d8eccSSepherosa Ziehau panic("bnx_jfree: buffer already free!"); 6786c8d8eccSSepherosa Ziehau } else { 6796c8d8eccSSepherosa Ziehau /* 6806c8d8eccSSepherosa Ziehau * Possible MP race to 0, use the serializer. The atomic insn 6816c8d8eccSSepherosa Ziehau * is still needed for races against bnx_jref(). 6826c8d8eccSSepherosa Ziehau */ 6836c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 6846c8d8eccSSepherosa Ziehau atomic_subtract_int(&entry->bnx_inuse, 1); 6856c8d8eccSSepherosa Ziehau if (entry->bnx_inuse == 0) { 6866c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, 6876c8d8eccSSepherosa Ziehau entry, jslot_link); 6886c8d8eccSSepherosa Ziehau } 6896c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 6906c8d8eccSSepherosa Ziehau } 6916c8d8eccSSepherosa Ziehau } 6926c8d8eccSSepherosa Ziehau 6936c8d8eccSSepherosa Ziehau 6946c8d8eccSSepherosa Ziehau /* 6956c8d8eccSSepherosa Ziehau * Intialize a standard receive ring descriptor. 6966c8d8eccSSepherosa Ziehau */ 6976c8d8eccSSepherosa Ziehau static int 698beedf5beSSepherosa Ziehau bnx_newbuf_std(struct bnx_rx_ret_ring *ret, int i, int init) 6996c8d8eccSSepherosa Ziehau { 7006c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7016c8d8eccSSepherosa Ziehau bus_dma_segment_t seg; 7026c8d8eccSSepherosa Ziehau bus_dmamap_t map; 7036c8d8eccSSepherosa Ziehau int error, nsegs; 704beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb; 7056c8d8eccSSepherosa Ziehau 7066c8d8eccSSepherosa Ziehau m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR); 7076c8d8eccSSepherosa Ziehau if (m_new == NULL) 7086c8d8eccSSepherosa Ziehau return ENOBUFS; 7096c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 7106c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 7116c8d8eccSSepherosa Ziehau 712beedf5beSSepherosa Ziehau error = bus_dmamap_load_mbuf_segment(ret->bnx_rx_mtag, 713beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap, m_new, &seg, 1, &nsegs, BUS_DMA_NOWAIT); 7146c8d8eccSSepherosa Ziehau if (error) { 7156c8d8eccSSepherosa Ziehau m_freem(m_new); 7166c8d8eccSSepherosa Ziehau return error; 7176c8d8eccSSepherosa Ziehau } 7186c8d8eccSSepherosa Ziehau 719beedf5beSSepherosa Ziehau rb = &ret->bnx_std->bnx_rx_std_buf[i]; 720beedf5beSSepherosa Ziehau 7216c8d8eccSSepherosa Ziehau if (!init) { 722beedf5beSSepherosa Ziehau bus_dmamap_sync(ret->bnx_rx_mtag, rb->bnx_rx_dmamap, 7236c8d8eccSSepherosa Ziehau BUS_DMASYNC_POSTREAD); 724beedf5beSSepherosa Ziehau bus_dmamap_unload(ret->bnx_rx_mtag, rb->bnx_rx_dmamap); 7256c8d8eccSSepherosa Ziehau } 7266c8d8eccSSepherosa Ziehau 727beedf5beSSepherosa Ziehau map = ret->bnx_rx_tmpmap; 728beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap = rb->bnx_rx_dmamap; 729beedf5beSSepherosa Ziehau rb->bnx_rx_dmamap = map; 7306c8d8eccSSepherosa Ziehau 731beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = m_new; 732beedf5beSSepherosa Ziehau rb->bnx_rx_paddr = seg.ds_addr; 7336c8d8eccSSepherosa Ziehau 734beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(ret->bnx_std, i); 7356c8d8eccSSepherosa Ziehau return 0; 7366c8d8eccSSepherosa Ziehau } 7376c8d8eccSSepherosa Ziehau 7386c8d8eccSSepherosa Ziehau static void 739beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(struct bnx_rx_std_ring *std, int i) 7406c8d8eccSSepherosa Ziehau { 741beedf5beSSepherosa Ziehau const struct bnx_rx_buf *rb; 7426c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 7436c8d8eccSSepherosa Ziehau 744beedf5beSSepherosa Ziehau rb = &std->bnx_rx_std_buf[i]; 745beedf5beSSepherosa Ziehau r = &std->bnx_rx_std_ring[i]; 7466c8d8eccSSepherosa Ziehau 747beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rb->bnx_rx_paddr); 748beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rb->bnx_rx_paddr); 749beedf5beSSepherosa Ziehau r->bge_len = rb->bnx_rx_mbuf->m_len; 7506c8d8eccSSepherosa Ziehau r->bge_idx = i; 7516c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END; 7526c8d8eccSSepherosa Ziehau } 7536c8d8eccSSepherosa Ziehau 7546c8d8eccSSepherosa Ziehau /* 7556c8d8eccSSepherosa Ziehau * Initialize a jumbo receive ring descriptor. This allocates 7566c8d8eccSSepherosa Ziehau * a jumbo buffer from the pool managed internally by the driver. 7576c8d8eccSSepherosa Ziehau */ 7586c8d8eccSSepherosa Ziehau static int 7596c8d8eccSSepherosa Ziehau bnx_newbuf_jumbo(struct bnx_softc *sc, int i, int init) 7606c8d8eccSSepherosa Ziehau { 7616c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7626c8d8eccSSepherosa Ziehau struct bnx_jslot *buf; 7636c8d8eccSSepherosa Ziehau bus_addr_t paddr; 7646c8d8eccSSepherosa Ziehau 7656c8d8eccSSepherosa Ziehau /* Allocate the mbuf. */ 7666c8d8eccSSepherosa Ziehau MGETHDR(m_new, init ? MB_WAIT : MB_DONTWAIT, MT_DATA); 7676c8d8eccSSepherosa Ziehau if (m_new == NULL) 7686c8d8eccSSepherosa Ziehau return ENOBUFS; 7696c8d8eccSSepherosa Ziehau 7706c8d8eccSSepherosa Ziehau /* Allocate the jumbo buffer */ 7716c8d8eccSSepherosa Ziehau buf = bnx_jalloc(sc); 7726c8d8eccSSepherosa Ziehau if (buf == NULL) { 7736c8d8eccSSepherosa Ziehau m_freem(m_new); 7746c8d8eccSSepherosa Ziehau return ENOBUFS; 7756c8d8eccSSepherosa Ziehau } 7766c8d8eccSSepherosa Ziehau 7776c8d8eccSSepherosa Ziehau /* Attach the buffer to the mbuf. */ 7786c8d8eccSSepherosa Ziehau m_new->m_ext.ext_arg = buf; 7796c8d8eccSSepherosa Ziehau m_new->m_ext.ext_buf = buf->bnx_buf; 7806c8d8eccSSepherosa Ziehau m_new->m_ext.ext_free = bnx_jfree; 7816c8d8eccSSepherosa Ziehau m_new->m_ext.ext_ref = bnx_jref; 7826c8d8eccSSepherosa Ziehau m_new->m_ext.ext_size = BNX_JUMBO_FRAMELEN; 7836c8d8eccSSepherosa Ziehau 7846c8d8eccSSepherosa Ziehau m_new->m_flags |= M_EXT; 7856c8d8eccSSepherosa Ziehau 7866c8d8eccSSepherosa Ziehau m_new->m_data = m_new->m_ext.ext_buf; 7876c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = m_new->m_ext.ext_size; 7886c8d8eccSSepherosa Ziehau 7896c8d8eccSSepherosa Ziehau paddr = buf->bnx_paddr; 7906c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 7916c8d8eccSSepherosa Ziehau paddr += ETHER_ALIGN; 7926c8d8eccSSepherosa Ziehau 7936c8d8eccSSepherosa Ziehau /* Save necessary information */ 794beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_mbuf = m_new; 795beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_paddr = paddr; 7966c8d8eccSSepherosa Ziehau 7976c8d8eccSSepherosa Ziehau /* Set up the descriptor. */ 7986c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, i); 7996c8d8eccSSepherosa Ziehau return 0; 8006c8d8eccSSepherosa Ziehau } 8016c8d8eccSSepherosa Ziehau 8026c8d8eccSSepherosa Ziehau static void 8036c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(struct bnx_softc *sc, int i) 8046c8d8eccSSepherosa Ziehau { 8056c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 806beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc; 8076c8d8eccSSepherosa Ziehau 8086c8d8eccSSepherosa Ziehau r = &sc->bnx_ldata.bnx_rx_jumbo_ring[i]; 8096c8d8eccSSepherosa Ziehau rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8106c8d8eccSSepherosa Ziehau 811beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_rx_paddr); 812beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_rx_paddr); 813beedf5beSSepherosa Ziehau r->bge_len = rc->bnx_rx_mbuf->m_len; 8146c8d8eccSSepherosa Ziehau r->bge_idx = i; 8156c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING; 8166c8d8eccSSepherosa Ziehau } 8176c8d8eccSSepherosa Ziehau 8186c8d8eccSSepherosa Ziehau static int 819beedf5beSSepherosa Ziehau bnx_init_rx_ring_std(struct bnx_rx_std_ring *std) 8206c8d8eccSSepherosa Ziehau { 8216c8d8eccSSepherosa Ziehau int i, error; 8226c8d8eccSSepherosa Ziehau 8236c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 824beedf5beSSepherosa Ziehau /* Use the first RX return ring's tmp RX mbuf DMA map */ 825beedf5beSSepherosa Ziehau error = bnx_newbuf_std(&std->bnx_sc->bnx_rx_ret_ring[0], i, 1); 8266c8d8eccSSepherosa Ziehau if (error) 8276c8d8eccSSepherosa Ziehau return error; 82887c7a7cfSSascha Wildner } 8296c8d8eccSSepherosa Ziehau 830beedf5beSSepherosa Ziehau std->bnx_rx_std = BGE_STD_RX_RING_CNT - 1; 831beedf5beSSepherosa Ziehau bnx_writembx(std->bnx_sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std); 8326c8d8eccSSepherosa Ziehau 8336c8d8eccSSepherosa Ziehau return(0); 8346c8d8eccSSepherosa Ziehau } 8356c8d8eccSSepherosa Ziehau 8366c8d8eccSSepherosa Ziehau static void 837beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(struct bnx_rx_std_ring *std) 8386c8d8eccSSepherosa Ziehau { 8396c8d8eccSSepherosa Ziehau int i; 8406c8d8eccSSepherosa Ziehau 8416c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 842beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb = &std->bnx_rx_std_buf[i]; 8436c8d8eccSSepherosa Ziehau 844beedf5beSSepherosa Ziehau if (rb->bnx_rx_mbuf != NULL) { 845beedf5beSSepherosa Ziehau bus_dmamap_unload(std->bnx_rx_mtag, rb->bnx_rx_dmamap); 846beedf5beSSepherosa Ziehau m_freem(rb->bnx_rx_mbuf); 847beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = NULL; 8486c8d8eccSSepherosa Ziehau } 849beedf5beSSepherosa Ziehau bzero(&std->bnx_rx_std_ring[i], sizeof(struct bge_rx_bd)); 8506c8d8eccSSepherosa Ziehau } 8516c8d8eccSSepherosa Ziehau } 8526c8d8eccSSepherosa Ziehau 8536c8d8eccSSepherosa Ziehau static int 8546c8d8eccSSepherosa Ziehau bnx_init_rx_ring_jumbo(struct bnx_softc *sc) 8556c8d8eccSSepherosa Ziehau { 8566c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 8576c8d8eccSSepherosa Ziehau int i, error; 8586c8d8eccSSepherosa Ziehau 8596c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 8606c8d8eccSSepherosa Ziehau error = bnx_newbuf_jumbo(sc, i, 1); 8616c8d8eccSSepherosa Ziehau if (error) 8626c8d8eccSSepherosa Ziehau return error; 86387c7a7cfSSascha Wildner } 8646c8d8eccSSepherosa Ziehau 8656c8d8eccSSepherosa Ziehau sc->bnx_jumbo = BGE_JUMBO_RX_RING_CNT - 1; 8666c8d8eccSSepherosa Ziehau 8676c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 8686c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0); 8696c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 8706c8d8eccSSepherosa Ziehau 8716c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 8726c8d8eccSSepherosa Ziehau 8736c8d8eccSSepherosa Ziehau return(0); 8746c8d8eccSSepherosa Ziehau } 8756c8d8eccSSepherosa Ziehau 8766c8d8eccSSepherosa Ziehau static void 8776c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(struct bnx_softc *sc) 8786c8d8eccSSepherosa Ziehau { 8796c8d8eccSSepherosa Ziehau int i; 8806c8d8eccSSepherosa Ziehau 8816c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 882beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8836c8d8eccSSepherosa Ziehau 884beedf5beSSepherosa Ziehau if (rc->bnx_rx_mbuf != NULL) { 885beedf5beSSepherosa Ziehau m_freem(rc->bnx_rx_mbuf); 886beedf5beSSepherosa Ziehau rc->bnx_rx_mbuf = NULL; 8876c8d8eccSSepherosa Ziehau } 8886c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_rx_jumbo_ring[i], 8896c8d8eccSSepherosa Ziehau sizeof(struct bge_rx_bd)); 8906c8d8eccSSepherosa Ziehau } 8916c8d8eccSSepherosa Ziehau } 8926c8d8eccSSepherosa Ziehau 8936c8d8eccSSepherosa Ziehau static void 89433a04907SSepherosa Ziehau bnx_free_tx_ring(struct bnx_tx_ring *txr) 8956c8d8eccSSepherosa Ziehau { 8966c8d8eccSSepherosa Ziehau int i; 8976c8d8eccSSepherosa Ziehau 8986c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 899fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf = &txr->bnx_tx_buf[i]; 900fa4b1067SSepherosa Ziehau 901fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 90233a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 903fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 904fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 905fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 9066c8d8eccSSepherosa Ziehau } 90733a04907SSepherosa Ziehau bzero(&txr->bnx_tx_ring[i], sizeof(struct bge_tx_bd)); 9086c8d8eccSSepherosa Ziehau } 90933a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = BNX_TXCONS_UNSET; 9106c8d8eccSSepherosa Ziehau } 9116c8d8eccSSepherosa Ziehau 9126c8d8eccSSepherosa Ziehau static int 91333a04907SSepherosa Ziehau bnx_init_tx_ring(struct bnx_tx_ring *txr) 9146c8d8eccSSepherosa Ziehau { 915fa639b88SSepherosa Ziehau txr->bnx_tx_cnt = 0; 91633a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = 0; 91733a04907SSepherosa Ziehau txr->bnx_tx_prodidx = 0; 9186c8d8eccSSepherosa Ziehau 9196c8d8eccSSepherosa Ziehau /* Initialize transmit producer index for host-memory send ring. */ 9208bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, txr->bnx_tx_prodidx); 9216c8d8eccSSepherosa Ziehau 9226c8d8eccSSepherosa Ziehau return(0); 9236c8d8eccSSepherosa Ziehau } 9246c8d8eccSSepherosa Ziehau 9256c8d8eccSSepherosa Ziehau static void 9266c8d8eccSSepherosa Ziehau bnx_setmulti(struct bnx_softc *sc) 9276c8d8eccSSepherosa Ziehau { 9286c8d8eccSSepherosa Ziehau struct ifnet *ifp; 9296c8d8eccSSepherosa Ziehau struct ifmultiaddr *ifma; 9306c8d8eccSSepherosa Ziehau uint32_t hashes[4] = { 0, 0, 0, 0 }; 9316c8d8eccSSepherosa Ziehau int h, i; 9326c8d8eccSSepherosa Ziehau 9336c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 9346c8d8eccSSepherosa Ziehau 9356c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 9366c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0xFFFFFFFF); 9386c8d8eccSSepherosa Ziehau return; 9396c8d8eccSSepherosa Ziehau } 9406c8d8eccSSepherosa Ziehau 9416c8d8eccSSepherosa Ziehau /* First, zot all the existing filters. */ 9426c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9436c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0); 9446c8d8eccSSepherosa Ziehau 9456c8d8eccSSepherosa Ziehau /* Now program new ones. */ 9466c8d8eccSSepherosa Ziehau TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 9476c8d8eccSSepherosa Ziehau if (ifma->ifma_addr->sa_family != AF_LINK) 9486c8d8eccSSepherosa Ziehau continue; 9496c8d8eccSSepherosa Ziehau h = ether_crc32_le( 9506c8d8eccSSepherosa Ziehau LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 9516c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN) & 0x7f; 9526c8d8eccSSepherosa Ziehau hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F); 9536c8d8eccSSepherosa Ziehau } 9546c8d8eccSSepherosa Ziehau 9556c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]); 9576c8d8eccSSepherosa Ziehau } 9586c8d8eccSSepherosa Ziehau 9596c8d8eccSSepherosa Ziehau /* 9606c8d8eccSSepherosa Ziehau * Do endian, PCI and DMA initialization. Also check the on-board ROM 9616c8d8eccSSepherosa Ziehau * self-test results. 9626c8d8eccSSepherosa Ziehau */ 9636c8d8eccSSepherosa Ziehau static int 9646c8d8eccSSepherosa Ziehau bnx_chipinit(struct bnx_softc *sc) 9656c8d8eccSSepherosa Ziehau { 9666c8d8eccSSepherosa Ziehau uint32_t dma_rw_ctl, mode_ctl; 9676c8d8eccSSepherosa Ziehau int i; 9686c8d8eccSSepherosa Ziehau 9696c8d8eccSSepherosa Ziehau /* Set endian type before we access any non-PCI registers. */ 9706c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_MISC_CTL, 9716c8d8eccSSepherosa Ziehau BGE_INIT | BGE_PCIMISCCTL_TAGGED_STATUS, 4); 9726c8d8eccSSepherosa Ziehau 9736c8d8eccSSepherosa Ziehau /* Clear the MAC control register */ 9746c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 9756c8d8eccSSepherosa Ziehau 9766c8d8eccSSepherosa Ziehau /* 9776c8d8eccSSepherosa Ziehau * Clear the MAC statistics block in the NIC's 9786c8d8eccSSepherosa Ziehau * internal memory. 9796c8d8eccSSepherosa Ziehau */ 9806c8d8eccSSepherosa Ziehau for (i = BGE_STATS_BLOCK; 9816c8d8eccSSepherosa Ziehau i < BGE_STATS_BLOCK_END + 1; i += sizeof(uint32_t)) 9826c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 9836c8d8eccSSepherosa Ziehau 9846c8d8eccSSepherosa Ziehau for (i = BGE_STATUS_BLOCK; 9856c8d8eccSSepherosa Ziehau i < BGE_STATUS_BLOCK_END + 1; i += sizeof(uint32_t)) 9866c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 9876c8d8eccSSepherosa Ziehau 988d7872545SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) { 989d7872545SSepherosa Ziehau uint32_t val; 990d7872545SSepherosa Ziehau 991d7872545SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) { 992d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 993d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 994d7872545SSepherosa Ziehau 995d7872545SSepherosa Ziehau /* Access the lower 1K of PL PCI-E block registers. */ 996d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 997d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_PL_SEL); 998d7872545SSepherosa Ziehau 999d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_PL_LO_PHYCTL5); 1000d7872545SSepherosa Ziehau val |= BGE_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ; 1001d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PL_LO_PHYCTL5, val); 1002d7872545SSepherosa Ziehau 1003d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1004d7872545SSepherosa Ziehau } 1005d7872545SSepherosa Ziehau if (sc->bnx_chiprev != BGE_CHIPREV_57765_AX) { 10061749651bSSepherosa Ziehau /* Fix transmit hangs */ 10071749651bSSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_PADRNG_CTL); 10081749651bSSepherosa Ziehau val |= BGE_CPMU_PADRNG_CTL_RDIV2; 10091749651bSSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_PADRNG_CTL, val); 10101749651bSSepherosa Ziehau 1011d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1012d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1013d7872545SSepherosa Ziehau 1014d7872545SSepherosa Ziehau /* Access the lower 1K of DL PCI-E block registers. */ 1015d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1016d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_DL_SEL); 1017d7872545SSepherosa Ziehau 1018d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_DL_LO_FTSMAX); 1019d7872545SSepherosa Ziehau val &= ~BGE_PCIE_DL_LO_FTSMAX_MASK; 1020d7872545SSepherosa Ziehau val |= BGE_PCIE_DL_LO_FTSMAX_VAL; 1021d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_DL_LO_FTSMAX, val); 1022d7872545SSepherosa Ziehau 1023d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1024d7872545SSepherosa Ziehau } 1025d7872545SSepherosa Ziehau 1026d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_LSPD_10MB_CLK); 1027d7872545SSepherosa Ziehau val &= ~BGE_CPMU_LSPD_10MB_MACCLK_MASK; 1028d7872545SSepherosa Ziehau val |= BGE_CPMU_LSPD_10MB_MACCLK_6_25; 1029d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_LSPD_10MB_CLK, val); 1030d7872545SSepherosa Ziehau } 1031d7872545SSepherosa Ziehau 10322890cca3SSepherosa Ziehau /* 10332890cca3SSepherosa Ziehau * Set up the PCI DMA control register. 10342890cca3SSepherosa Ziehau */ 10352890cca3SSepherosa Ziehau dma_rw_ctl = pci_read_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, 4); 10362890cca3SSepherosa Ziehau /* 10372890cca3SSepherosa Ziehau * Disable 32bytes cache alignment for DMA write to host memory 10382890cca3SSepherosa Ziehau * 10392890cca3SSepherosa Ziehau * NOTE: 10402890cca3SSepherosa Ziehau * 64bytes cache alignment for DMA write to host memory is still 10412890cca3SSepherosa Ziehau * enabled. 10422890cca3SSepherosa Ziehau */ 10432890cca3SSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT; 10446c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 10456c8d8eccSSepherosa Ziehau dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK; 10466c8d8eccSSepherosa Ziehau /* 10476c8d8eccSSepherosa Ziehau * Enable HW workaround for controllers that misinterpret 10486c8d8eccSSepherosa Ziehau * a status tag update and leave interrupts permanently 10496c8d8eccSSepherosa Ziehau * disabled. 10506c8d8eccSSepherosa Ziehau */ 10516c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5717 && 1052b96cbbb6SSepherosa Ziehau sc->bnx_asicrev != BGE_ASICREV_BCM5762 && 10532890cca3SSepherosa Ziehau !BNX_IS_57765_FAMILY(sc)) 10546c8d8eccSSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA; 10552890cca3SSepherosa Ziehau if (bootverbose) { 10562890cca3SSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "DMA read/write %#x\n", 10572890cca3SSepherosa Ziehau dma_rw_ctl); 10586c8d8eccSSepherosa Ziehau } 10596c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, dma_rw_ctl, 4); 10606c8d8eccSSepherosa Ziehau 10616c8d8eccSSepherosa Ziehau /* 10626c8d8eccSSepherosa Ziehau * Set up general mode register. 10636c8d8eccSSepherosa Ziehau */ 10646c8d8eccSSepherosa Ziehau mode_ctl = bnx_dma_swap_options(sc) | BGE_MODECTL_MAC_ATTN_INTR | 10656c8d8eccSSepherosa Ziehau BGE_MODECTL_HOST_SEND_BDS | BGE_MODECTL_TX_NO_PHDR_CSUM; 10666c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 10676c8d8eccSSepherosa Ziehau 10686c8d8eccSSepherosa Ziehau /* 10696c8d8eccSSepherosa Ziehau * Disable memory write invalidate. Apparently it is not supported 10706c8d8eccSSepherosa Ziehau * properly by these devices. Also ensure that INTx isn't disabled, 10716c8d8eccSSepherosa Ziehau * as these chips need it even when using MSI. 10726c8d8eccSSepherosa Ziehau */ 10736c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_CMD, 10746c8d8eccSSepherosa Ziehau (PCIM_CMD_MWRICEN | PCIM_CMD_INTxDIS), 4); 10756c8d8eccSSepherosa Ziehau 10766c8d8eccSSepherosa Ziehau /* Set the timer prescaler (always 66Mhz) */ 10776c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, 65 << 1/*BGE_32BITTIME_66MHZ*/); 10786c8d8eccSSepherosa Ziehau 10796c8d8eccSSepherosa Ziehau return(0); 10806c8d8eccSSepherosa Ziehau } 10816c8d8eccSSepherosa Ziehau 10826c8d8eccSSepherosa Ziehau static int 10836c8d8eccSSepherosa Ziehau bnx_blockinit(struct bnx_softc *sc) 10846c8d8eccSSepherosa Ziehau { 108533a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 1086beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 10876c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 10886c8d8eccSSepherosa Ziehau bus_size_t vrcb; 10896c8d8eccSSepherosa Ziehau bge_hostaddr taddr; 10906c8d8eccSSepherosa Ziehau uint32_t val; 10916c8d8eccSSepherosa Ziehau int i, limit; 10926c8d8eccSSepherosa Ziehau 10936c8d8eccSSepherosa Ziehau /* 10946c8d8eccSSepherosa Ziehau * Initialize the memory window pointer register so that 10956c8d8eccSSepherosa Ziehau * we can access the first 32K of internal NIC RAM. This will 10966c8d8eccSSepherosa Ziehau * allow us to set up the TX send ring RCBs and the RX return 10976c8d8eccSSepherosa Ziehau * ring RCBs, plus other things which live in NIC memory. 10986c8d8eccSSepherosa Ziehau */ 10996c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0); 11006c8d8eccSSepherosa Ziehau 11016c8d8eccSSepherosa Ziehau /* Configure mbuf pool watermarks */ 1102f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 11036c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11046c8d8eccSSepherosa Ziehau if (sc->arpcom.ac_if.if_mtu > ETHERMTU) { 11056c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x7e); 11066c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xea); 11076c8d8eccSSepherosa Ziehau } else { 11086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x2a); 11096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xa0); 11106c8d8eccSSepherosa Ziehau } 11116c8d8eccSSepherosa Ziehau } else { 11126c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10); 11146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60); 11156c8d8eccSSepherosa Ziehau } 11166c8d8eccSSepherosa Ziehau 11176c8d8eccSSepherosa Ziehau /* Configure DMA resource watermarks */ 11186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5); 11196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10); 11206c8d8eccSSepherosa Ziehau 11216c8d8eccSSepherosa Ziehau /* Enable buffer manager */ 11226c8d8eccSSepherosa Ziehau val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN; 11236c8d8eccSSepherosa Ziehau /* 11246c8d8eccSSepherosa Ziehau * Change the arbitration algorithm of TXMBUF read request to 11256c8d8eccSSepherosa Ziehau * round-robin instead of priority based for BCM5719. When 11266c8d8eccSSepherosa Ziehau * TXFIFO is almost empty, RDMA will hold its request until 11276c8d8eccSSepherosa Ziehau * TXFIFO is not almost empty. 11286c8d8eccSSepherosa Ziehau */ 11296c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) 11306c8d8eccSSepherosa Ziehau val |= BGE_BMANMODE_NO_TX_UNDERRUN; 1131e5eebe34SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1132e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0 || 1133e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5720_A0) 1134e5eebe34SSepherosa Ziehau val |= BGE_BMANMODE_LOMBUF_ATTN; 11356c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MODE, val); 11366c8d8eccSSepherosa Ziehau 11376c8d8eccSSepherosa Ziehau /* Poll for buffer manager start indication */ 11386c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11396c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_BMAN_MODE) & BGE_BMANMODE_ENABLE) 11406c8d8eccSSepherosa Ziehau break; 11416c8d8eccSSepherosa Ziehau DELAY(10); 11426c8d8eccSSepherosa Ziehau } 11436c8d8eccSSepherosa Ziehau 11446c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 11456c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 11466c8d8eccSSepherosa Ziehau "buffer manager failed to start\n"); 11476c8d8eccSSepherosa Ziehau return(ENXIO); 11486c8d8eccSSepherosa Ziehau } 11496c8d8eccSSepherosa Ziehau 11506c8d8eccSSepherosa Ziehau /* Enable flow-through queues */ 11516c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 11526c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 11536c8d8eccSSepherosa Ziehau 11546c8d8eccSSepherosa Ziehau /* Wait until queue initialization is complete */ 11556c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11566c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_FTQ_RESET) == 0) 11576c8d8eccSSepherosa Ziehau break; 11586c8d8eccSSepherosa Ziehau DELAY(10); 11596c8d8eccSSepherosa Ziehau } 11606c8d8eccSSepherosa Ziehau 11616c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 11626c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 11636c8d8eccSSepherosa Ziehau "flow-through queue init failed\n"); 11646c8d8eccSSepherosa Ziehau return(ENXIO); 11656c8d8eccSSepherosa Ziehau } 11666c8d8eccSSepherosa Ziehau 11676c8d8eccSSepherosa Ziehau /* 11686c8d8eccSSepherosa Ziehau * Summary of rings supported by the controller: 11696c8d8eccSSepherosa Ziehau * 11706c8d8eccSSepherosa Ziehau * Standard Receive Producer Ring 11716c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "standard" 11726c8d8eccSSepherosa Ziehau * sized frames (typically 1536 bytes) to the controller. 11736c8d8eccSSepherosa Ziehau * 11746c8d8eccSSepherosa Ziehau * Jumbo Receive Producer Ring 11756c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for jumbo sized 11766c8d8eccSSepherosa Ziehau * frames (i.e. anything bigger than the "standard" frames) 11776c8d8eccSSepherosa Ziehau * to the controller. 11786c8d8eccSSepherosa Ziehau * 11796c8d8eccSSepherosa Ziehau * Mini Receive Producer Ring 11806c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "mini" 11816c8d8eccSSepherosa Ziehau * sized frames to the controller. 11826c8d8eccSSepherosa Ziehau * - This feature required external memory for the controller 11836c8d8eccSSepherosa Ziehau * but was never used in a production system. Should always 11846c8d8eccSSepherosa Ziehau * be disabled. 11856c8d8eccSSepherosa Ziehau * 11866c8d8eccSSepherosa Ziehau * Receive Return Ring 11876c8d8eccSSepherosa Ziehau * - After the controller has placed an incoming frame into a 11886c8d8eccSSepherosa Ziehau * receive buffer that buffer is moved into a receive return 11896c8d8eccSSepherosa Ziehau * ring. The driver is then responsible to passing the 11906c8d8eccSSepherosa Ziehau * buffer up to the stack. Many versions of the controller 11916c8d8eccSSepherosa Ziehau * support multiple RR rings. 11926c8d8eccSSepherosa Ziehau * 11936c8d8eccSSepherosa Ziehau * Send Ring 11946c8d8eccSSepherosa Ziehau * - This ring is used for outgoing frames. Many versions of 11956c8d8eccSSepherosa Ziehau * the controller support multiple send rings. 11966c8d8eccSSepherosa Ziehau */ 11976c8d8eccSSepherosa Ziehau 11986c8d8eccSSepherosa Ziehau /* Initialize the standard receive producer ring control block. */ 11996c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_std_rx_rcb; 12006c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 1201beedf5beSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 12026c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 1203beedf5beSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 1204f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12056c8d8eccSSepherosa Ziehau /* 12066c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (2048, 1024, 512, .., 32) 12076c8d8eccSSepherosa Ziehau * Bits 15-2 : Maximum RX frame size 12086c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring ENabled 12096c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12106c8d8eccSSepherosa Ziehau */ 12116c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12126c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(512, BNX_MAX_FRAMELEN << 2); 12136c8d8eccSSepherosa Ziehau } else { 12146c8d8eccSSepherosa Ziehau /* 12156c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (512, 256, 128, 64, 32) 12166c8d8eccSSepherosa Ziehau * Bits 15-2 : Reserved (should be 0) 12176c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring Enabled 12186c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12196c8d8eccSSepherosa Ziehau */ 12206c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(512, 0); 12216c8d8eccSSepherosa Ziehau } 1222303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12236c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717; 12246c8d8eccSSepherosa Ziehau else 12256c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS; 12266c8d8eccSSepherosa Ziehau /* Write the standard receive producer ring control block. */ 12276c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); 12286c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); 12296c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 12306c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_NICADDR, rcb->bge_nicaddr); 12316c8d8eccSSepherosa Ziehau /* Reset the standard receive producer ring producer index. */ 12326c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0); 12336c8d8eccSSepherosa Ziehau 12346c8d8eccSSepherosa Ziehau /* 12356c8d8eccSSepherosa Ziehau * Initialize the jumbo RX producer ring control 12366c8d8eccSSepherosa Ziehau * block. We set the 'ring disabled' bit in the 12376c8d8eccSSepherosa Ziehau * flags field until we're actually ready to start 12386c8d8eccSSepherosa Ziehau * using this ring (i.e. once we set the MTU 12396c8d8eccSSepherosa Ziehau * high enough to require it). 12406c8d8eccSSepherosa Ziehau */ 12416c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 12426c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 12436c8d8eccSSepherosa Ziehau /* Get the jumbo receive producer ring RCB parameters. */ 12446c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 12456c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12466c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 12476c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12486c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12496c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_MAX_FRAMELEN, 12506c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 1251303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12526c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717; 12536c8d8eccSSepherosa Ziehau else 12546c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; 12556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI, 12566c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi); 12576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO, 12586c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo); 12596c8d8eccSSepherosa Ziehau /* Program the jumbo receive producer ring RCB parameters. */ 12606c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, 12616c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags); 12626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr); 12636c8d8eccSSepherosa Ziehau /* Reset the jumbo receive producer ring producer index. */ 12646c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); 12656c8d8eccSSepherosa Ziehau } 12666c8d8eccSSepherosa Ziehau 12676c8d8eccSSepherosa Ziehau /* 12686c8d8eccSSepherosa Ziehau * The BD ring replenish thresholds control how often the 12696c8d8eccSSepherosa Ziehau * hardware fetches new BD's from the producer rings in host 12706c8d8eccSSepherosa Ziehau * memory. Setting the value too low on a busy system can 12716c8d8eccSSepherosa Ziehau * starve the hardware and recue the throughpout. 12726c8d8eccSSepherosa Ziehau * 12736c8d8eccSSepherosa Ziehau * Set the BD ring replentish thresholds. The recommended 12746c8d8eccSSepherosa Ziehau * values are 1/8th the number of descriptors allocated to 12756c8d8eccSSepherosa Ziehau * each ring. 12766c8d8eccSSepherosa Ziehau */ 12776c8d8eccSSepherosa Ziehau val = 8; 12786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_STD_REPL_THRESH, val); 12796c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 12806c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_JUMBO_REPL_THRESH, 12816c8d8eccSSepherosa Ziehau BGE_JUMBO_RX_RING_CNT/8); 12826c8d8eccSSepherosa Ziehau } 1283f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_STD_REPLENISH_LWM, 32); 12856c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_JMB_REPLENISH_LWM, 16); 12866c8d8eccSSepherosa Ziehau } 12876c8d8eccSSepherosa Ziehau 12886c8d8eccSSepherosa Ziehau /* 12896c8d8eccSSepherosa Ziehau * Disable all send rings by setting the 'ring disabled' bit 12906c8d8eccSSepherosa Ziehau * in the flags field of all the TX send ring control blocks, 12916c8d8eccSSepherosa Ziehau * located in NIC memory. 12926c8d8eccSSepherosa Ziehau */ 129380969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 129480969639SSepherosa Ziehau limit = 4; 1295b96cbbb6SSepherosa Ziehau else if (BNX_IS_57765_FAMILY(sc) || 1296b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) 12974f23029eSSepherosa Ziehau limit = 2; 129880969639SSepherosa Ziehau else 12996c8d8eccSSepherosa Ziehau limit = 1; 13006c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 13016c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13026c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13036c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED)); 13046c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13056c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13066c8d8eccSSepherosa Ziehau } 13076c8d8eccSSepherosa Ziehau 13086c8d8eccSSepherosa Ziehau /* Configure send ring RCB 0 (we use only the first ring) */ 13096c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 131033a04907SSepherosa Ziehau BGE_HOSTADDR(taddr, txr->bnx_tx_ring_paddr); 13116c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 13126c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 1313303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13146c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, BGE_SEND_RING_5717); 13156c8d8eccSSepherosa Ziehau } else { 13166c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 13176c8d8eccSSepherosa Ziehau BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT)); 13186c8d8eccSSepherosa Ziehau } 13196c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13206c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BGE_TX_RING_CNT, 0)); 13216c8d8eccSSepherosa Ziehau 13226c8d8eccSSepherosa Ziehau /* 13236c8d8eccSSepherosa Ziehau * Disable all receive return rings by setting the 13246c8d8eccSSepherosa Ziehau * 'ring disabled' bit in the flags field of all the receive 13256c8d8eccSSepherosa Ziehau * return ring control blocks, located in NIC memory. 13266c8d8eccSSepherosa Ziehau */ 132780969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13286c8d8eccSSepherosa Ziehau /* Should be 17, use 16 until we get an SRAM map. */ 13296c8d8eccSSepherosa Ziehau limit = 16; 1330b96cbbb6SSepherosa Ziehau } else if (BNX_IS_57765_FAMILY(sc) || 1331b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 13326c8d8eccSSepherosa Ziehau limit = 4; 13336c8d8eccSSepherosa Ziehau } else { 13346c8d8eccSSepherosa Ziehau limit = 1; 13356c8d8eccSSepherosa Ziehau } 13366c8d8eccSSepherosa Ziehau /* Disable all receive return rings. */ 13376c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 13386c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13396c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, 0); 13406c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, 0); 13416c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13426c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 13436c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13446c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO + 13456c8d8eccSSepherosa Ziehau (i * (sizeof(uint64_t))), 0); 13466c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13476c8d8eccSSepherosa Ziehau } 13486c8d8eccSSepherosa Ziehau 13496c8d8eccSSepherosa Ziehau /* 13506c8d8eccSSepherosa Ziehau * Set up receive return ring 0. Note that the NIC address 13516c8d8eccSSepherosa Ziehau * for RX return rings is 0x0. The return rings live entirely 13526c8d8eccSSepherosa Ziehau * within the host, so the nicaddr field in the RCB isn't used. 13536c8d8eccSSepherosa Ziehau */ 13546c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 1355beedf5beSSepherosa Ziehau BGE_HOSTADDR(taddr, ret->bnx_rx_ret_ring_paddr); 13566c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 13576c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 13586c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13596c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 1360e0f74fc8SSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_RETURN_RING_CNT, 0)); 13616c8d8eccSSepherosa Ziehau 13626c8d8eccSSepherosa Ziehau /* Set random backoff seed for TX */ 13636c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_RANDOM_BACKOFF, 13646c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[0] + sc->arpcom.ac_enaddr[1] + 13656c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[2] + sc->arpcom.ac_enaddr[3] + 13666c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[4] + sc->arpcom.ac_enaddr[5] + 13676c8d8eccSSepherosa Ziehau BGE_TX_BACKOFF_SEED_MASK); 13686c8d8eccSSepherosa Ziehau 13696c8d8eccSSepherosa Ziehau /* Set inter-packet gap */ 13706c8d8eccSSepherosa Ziehau val = 0x2620; 1371b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1372b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 13736c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_TX_LENGTHS) & 13746c8d8eccSSepherosa Ziehau (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK); 13756c8d8eccSSepherosa Ziehau } 13766c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_LENGTHS, val); 13776c8d8eccSSepherosa Ziehau 13786c8d8eccSSepherosa Ziehau /* 13796c8d8eccSSepherosa Ziehau * Specify which ring to use for packets that don't match 13806c8d8eccSSepherosa Ziehau * any RX rules. 13816c8d8eccSSepherosa Ziehau */ 13826c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_RULES_CFG, 0x08); 13836c8d8eccSSepherosa Ziehau 13846c8d8eccSSepherosa Ziehau /* 13856c8d8eccSSepherosa Ziehau * Configure number of RX lists. One interrupt distribution 13866c8d8eccSSepherosa Ziehau * list, sixteen active lists, one bad frames class. 13876c8d8eccSSepherosa Ziehau */ 13886c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181); 13896c8d8eccSSepherosa Ziehau 13906c8d8eccSSepherosa Ziehau /* Inialize RX list placement stats mask. */ 13916c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF); 13926c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1); 13936c8d8eccSSepherosa Ziehau 13946c8d8eccSSepherosa Ziehau /* Disable host coalescing until we get it set up */ 13956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, 0x00000000); 13966c8d8eccSSepherosa Ziehau 13976c8d8eccSSepherosa Ziehau /* Poll to make sure it's shut down. */ 13986c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 13996c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_HCC_MODE) & BGE_HCCMODE_ENABLE)) 14006c8d8eccSSepherosa Ziehau break; 14016c8d8eccSSepherosa Ziehau DELAY(10); 14026c8d8eccSSepherosa Ziehau } 14036c8d8eccSSepherosa Ziehau 14046c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 14056c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 14066c8d8eccSSepherosa Ziehau "host coalescing engine failed to idle\n"); 14076c8d8eccSSepherosa Ziehau return(ENXIO); 14086c8d8eccSSepherosa Ziehau } 14096c8d8eccSSepherosa Ziehau 14106c8d8eccSSepherosa Ziehau /* Set up host coalescing defaults */ 14116c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, sc->bnx_rx_coal_ticks); 14126c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bnx_tx_coal_ticks); 14136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bnx_rx_coal_bds); 14146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bnx_tx_coal_bds); 14156c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, sc->bnx_rx_coal_bds_int); 14166c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, sc->bnx_tx_coal_bds_int); 14176c8d8eccSSepherosa Ziehau 14186c8d8eccSSepherosa Ziehau /* Set up address of status block */ 14196c8d8eccSSepherosa Ziehau bzero(sc->bnx_ldata.bnx_status_block, BGE_STATUS_BLK_SZ); 14206c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_HI, 14216c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_status_block_paddr)); 14226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_LO, 14236c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_status_block_paddr)); 14246c8d8eccSSepherosa Ziehau 14256c8d8eccSSepherosa Ziehau /* Set up status block partail update size. */ 14266c8d8eccSSepherosa Ziehau val = BGE_STATBLKSZ_32BYTE; 14276c8d8eccSSepherosa Ziehau #if 0 14286c8d8eccSSepherosa Ziehau /* 14296c8d8eccSSepherosa Ziehau * Does not seem to have visible effect in both 14306c8d8eccSSepherosa Ziehau * bulk data (1472B UDP datagram) and tiny data 14316c8d8eccSSepherosa Ziehau * (18B UDP datagram) TX tests. 14326c8d8eccSSepherosa Ziehau */ 14336c8d8eccSSepherosa Ziehau val |= BGE_HCCMODE_CLRTICK_TX; 14346c8d8eccSSepherosa Ziehau #endif 14356c8d8eccSSepherosa Ziehau /* Turn on host coalescing state machine */ 14366c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE); 14376c8d8eccSSepherosa Ziehau 14386c8d8eccSSepherosa Ziehau /* Turn on RX BD completion state machine and enable attentions */ 14396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDC_MODE, 14406c8d8eccSSepherosa Ziehau BGE_RBDCMODE_ENABLE|BGE_RBDCMODE_ATTN); 14416c8d8eccSSepherosa Ziehau 14426c8d8eccSSepherosa Ziehau /* Turn on RX list placement state machine */ 14436c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 14446c8d8eccSSepherosa Ziehau 14456c8d8eccSSepherosa Ziehau val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB | 14466c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_CLEAR | BGE_MACMODE_TX_STATS_CLEAR | 14476c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_ENB | BGE_MACMODE_TX_STATS_ENB | 14486c8d8eccSSepherosa Ziehau BGE_MACMODE_FRMHDR_DMA_ENB; 14496c8d8eccSSepherosa Ziehau 14506c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 14516c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_TBI; 14526c8d8eccSSepherosa Ziehau else if (sc->bnx_flags & BNX_FLAG_MII_SERDES) 14536c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_GMII; 14546c8d8eccSSepherosa Ziehau else 14556c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_MII; 14566c8d8eccSSepherosa Ziehau 14576c8d8eccSSepherosa Ziehau /* Turn on DMA, clear stats */ 14586c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, val); 14596c8d8eccSSepherosa Ziehau 14606c8d8eccSSepherosa Ziehau /* Set misc. local control, enable interrupts on attentions */ 14616c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN); 14626c8d8eccSSepherosa Ziehau 14636c8d8eccSSepherosa Ziehau #ifdef notdef 14646c8d8eccSSepherosa Ziehau /* Assert GPIO pins for PHY reset */ 14656c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUT0| 14666c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUT1|BGE_MLC_MISCIO_OUT2); 14676c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUTEN0| 14686c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUTEN1|BGE_MLC_MISCIO_OUTEN2); 14696c8d8eccSSepherosa Ziehau #endif 14706c8d8eccSSepherosa Ziehau 14716c8d8eccSSepherosa Ziehau /* Turn on write DMA state machine */ 14726c8d8eccSSepherosa Ziehau val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS; 14736c8d8eccSSepherosa Ziehau /* Enable host coalescing bug fix. */ 14746c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_STATUS_TAG_FIX; 14756c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5785) { 14766c8d8eccSSepherosa Ziehau /* Request larger DMA burst size to get better performance. */ 14776c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_BURST_ALL_DATA; 14786c8d8eccSSepherosa Ziehau } 14796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_WDMA_MODE, val); 14806c8d8eccSSepherosa Ziehau DELAY(40); 14816c8d8eccSSepherosa Ziehau 14823730a14dSSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 1483b96cbbb6SSepherosa Ziehau uint32_t dmactl, dmactl_reg; 14846c8d8eccSSepherosa Ziehau 1485b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1486b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL2; 1487b96cbbb6SSepherosa Ziehau else 1488b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL; 1489b96cbbb6SSepherosa Ziehau 1490b96cbbb6SSepherosa Ziehau dmactl = CSR_READ_4(sc, dmactl_reg); 14916c8d8eccSSepherosa Ziehau /* 14926c8d8eccSSepherosa Ziehau * Adjust tx margin to prevent TX data corruption and 14936c8d8eccSSepherosa Ziehau * fix internal FIFO overflow. 14946c8d8eccSSepherosa Ziehau */ 14956c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 1496b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1497b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 14986c8d8eccSSepherosa Ziehau dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK | 14996c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK | 15006c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_MASK); 15016c8d8eccSSepherosa Ziehau dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K | 15026c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K | 15036c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_320B; 15046c8d8eccSSepherosa Ziehau } 15056c8d8eccSSepherosa Ziehau /* 15066c8d8eccSSepherosa Ziehau * Enable fix for read DMA FIFO overruns. 15076c8d8eccSSepherosa Ziehau * The fix is to limit the number of RX BDs 15086c8d8eccSSepherosa Ziehau * the hardware would fetch at a fime. 15096c8d8eccSSepherosa Ziehau */ 1510b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, dmactl_reg, 15116c8d8eccSSepherosa Ziehau dmactl | BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX); 15126c8d8eccSSepherosa Ziehau } 15136c8d8eccSSepherosa Ziehau 15146c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) { 15156c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, 15166c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | 15176c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K | 15186c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 1519b96cbbb6SSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1520b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 1521b96cbbb6SSepherosa Ziehau uint32_t ctrl_reg; 1522b96cbbb6SSepherosa Ziehau 1523b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1524b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL2; 1525b96cbbb6SSepherosa Ziehau else 1526b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL; 1527b96cbbb6SSepherosa Ziehau 15286c8d8eccSSepherosa Ziehau /* 15296c8d8eccSSepherosa Ziehau * Allow 4KB burst length reads for non-LSO frames. 15306c8d8eccSSepherosa Ziehau * Enable 512B burst length reads for buffer descriptors. 15316c8d8eccSSepherosa Ziehau */ 1532b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, ctrl_reg, 1533b96cbbb6SSepherosa Ziehau CSR_READ_4(sc, ctrl_reg) | 15346c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 | 15356c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 15366c8d8eccSSepherosa Ziehau } 15376c8d8eccSSepherosa Ziehau 15386c8d8eccSSepherosa Ziehau /* Turn on read DMA state machine */ 15396c8d8eccSSepherosa Ziehau val = BGE_RDMAMODE_ENABLE | BGE_RDMAMODE_ALL_ATTNS; 15406c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717) 15416c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_MULT_DMA_RD_DIS; 15426c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5784 || 15436c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5785 || 15446c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM57780) { 15456c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_BD_SBD_CRPT_ATTN | 15466c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_RBD_CRPT_ATTN | 15476c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_SBD_CRPT_ATTN; 15486c8d8eccSSepherosa Ziehau } 1549b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1550b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 15516c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_RDMA_MODE) & 15526c8d8eccSSepherosa Ziehau BGE_RDMAMODE_H2BNC_VLAN_DET; 15536c8d8eccSSepherosa Ziehau /* 15546c8d8eccSSepherosa Ziehau * Allow multiple outstanding read requests from 15556c8d8eccSSepherosa Ziehau * non-LSO read DMA engine. 15566c8d8eccSSepherosa Ziehau */ 15576c8d8eccSSepherosa Ziehau val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS; 15586c8d8eccSSepherosa Ziehau } 155960e67e3fSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM57766) 156060e67e3fSSepherosa Ziehau val |= BGE_RDMAMODE_JMB_2K_MMRR; 156166deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) 156266deb1c1SSepherosa Ziehau val |= BGE_RDMAMODE_TSO4_ENABLE; 15636c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_FIFO_LONG_BURST; 15646c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_MODE, val); 15656c8d8eccSSepherosa Ziehau DELAY(40); 15666c8d8eccSSepherosa Ziehau 15676c8d8eccSSepherosa Ziehau /* Turn on RX data completion state machine */ 15686c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 15696c8d8eccSSepherosa Ziehau 15706c8d8eccSSepherosa Ziehau /* Turn on RX BD initiator state machine */ 15716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 15726c8d8eccSSepherosa Ziehau 15736c8d8eccSSepherosa Ziehau /* Turn on RX data and RX BD initiator state machine */ 15746c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE); 15756c8d8eccSSepherosa Ziehau 15766c8d8eccSSepherosa Ziehau /* Turn on send BD completion state machine */ 15776c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 15786c8d8eccSSepherosa Ziehau 15796c8d8eccSSepherosa Ziehau /* Turn on send data completion state machine */ 15806c8d8eccSSepherosa Ziehau val = BGE_SDCMODE_ENABLE; 15816c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5761) 15826c8d8eccSSepherosa Ziehau val |= BGE_SDCMODE_CDELAY; 15836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDC_MODE, val); 15846c8d8eccSSepherosa Ziehau 15856c8d8eccSSepherosa Ziehau /* Turn on send data initiator state machine */ 158666deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 158766deb1c1SSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE | 158866deb1c1SSepherosa Ziehau BGE_SDIMODE_HW_LSO_PRE_DMA); 158966deb1c1SSepherosa Ziehau } else { 15906c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 159166deb1c1SSepherosa Ziehau } 15926c8d8eccSSepherosa Ziehau 15936c8d8eccSSepherosa Ziehau /* Turn on send BD initiator state machine */ 15946c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 15956c8d8eccSSepherosa Ziehau 15966c8d8eccSSepherosa Ziehau /* Turn on send BD selector state machine */ 15976c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 15986c8d8eccSSepherosa Ziehau 15996c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF); 16006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_CTL, 16016c8d8eccSSepherosa Ziehau BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER); 16026c8d8eccSSepherosa Ziehau 16036c8d8eccSSepherosa Ziehau /* ack/clear link change events */ 16046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16056c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16066c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, 0); 16086c8d8eccSSepherosa Ziehau 16096c8d8eccSSepherosa Ziehau /* 16106c8d8eccSSepherosa Ziehau * Enable attention when the link has changed state for 16116c8d8eccSSepherosa Ziehau * devices that use auto polling. 16126c8d8eccSSepherosa Ziehau */ 16136c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 16146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK); 16156c8d8eccSSepherosa Ziehau } else { 16166c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 16176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 16186c8d8eccSSepherosa Ziehau DELAY(80); 16196c8d8eccSSepherosa Ziehau } 16206c8d8eccSSepherosa Ziehau } 16216c8d8eccSSepherosa Ziehau 16226c8d8eccSSepherosa Ziehau /* 16236c8d8eccSSepherosa Ziehau * Clear any pending link state attention. 16246c8d8eccSSepherosa Ziehau * Otherwise some link state change events may be lost until attention 16256c8d8eccSSepherosa Ziehau * is cleared by bnx_intr() -> bnx_softc.bnx_link_upd() sequence. 16266c8d8eccSSepherosa Ziehau * It's not necessary on newer BCM chips - perhaps enabling link 16276c8d8eccSSepherosa Ziehau * state change attentions implies clearing pending attention. 16286c8d8eccSSepherosa Ziehau */ 16296c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16306c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16316c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16326c8d8eccSSepherosa Ziehau 16336c8d8eccSSepherosa Ziehau /* Enable link state change attentions. */ 16346c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_LINK_CHANGED); 16356c8d8eccSSepherosa Ziehau 16366c8d8eccSSepherosa Ziehau return(0); 16376c8d8eccSSepherosa Ziehau } 16386c8d8eccSSepherosa Ziehau 16396c8d8eccSSepherosa Ziehau /* 16406c8d8eccSSepherosa Ziehau * Probe for a Broadcom chip. Check the PCI vendor and device IDs 16416c8d8eccSSepherosa Ziehau * against our list and return its name if we find a match. Note 16426c8d8eccSSepherosa Ziehau * that since the Broadcom controller contains VPD support, we 16436c8d8eccSSepherosa Ziehau * can get the device name string from the controller itself instead 16446c8d8eccSSepherosa Ziehau * of the compiled-in string. This is a little slow, but it guarantees 16456c8d8eccSSepherosa Ziehau * we'll always announce the right product name. 16466c8d8eccSSepherosa Ziehau */ 16476c8d8eccSSepherosa Ziehau static int 16486c8d8eccSSepherosa Ziehau bnx_probe(device_t dev) 16496c8d8eccSSepherosa Ziehau { 16506c8d8eccSSepherosa Ziehau const struct bnx_type *t; 16516c8d8eccSSepherosa Ziehau uint16_t product, vendor; 16526c8d8eccSSepherosa Ziehau 16536c8d8eccSSepherosa Ziehau if (!pci_is_pcie(dev)) 16546c8d8eccSSepherosa Ziehau return ENXIO; 16556c8d8eccSSepherosa Ziehau 16566c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 16576c8d8eccSSepherosa Ziehau vendor = pci_get_vendor(dev); 16586c8d8eccSSepherosa Ziehau 16596c8d8eccSSepherosa Ziehau for (t = bnx_devs; t->bnx_name != NULL; t++) { 16606c8d8eccSSepherosa Ziehau if (vendor == t->bnx_vid && product == t->bnx_did) 16616c8d8eccSSepherosa Ziehau break; 16626c8d8eccSSepherosa Ziehau } 16636c8d8eccSSepherosa Ziehau if (t->bnx_name == NULL) 16646c8d8eccSSepherosa Ziehau return ENXIO; 16656c8d8eccSSepherosa Ziehau 16666c8d8eccSSepherosa Ziehau device_set_desc(dev, t->bnx_name); 16676c8d8eccSSepherosa Ziehau return 0; 16686c8d8eccSSepherosa Ziehau } 16696c8d8eccSSepherosa Ziehau 16706c8d8eccSSepherosa Ziehau static int 16716c8d8eccSSepherosa Ziehau bnx_attach(device_t dev) 16726c8d8eccSSepherosa Ziehau { 16736c8d8eccSSepherosa Ziehau struct ifnet *ifp; 16746c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 1675e594b5c4SSepherosa Ziehau uint32_t hwcfg = 0; 16766c8d8eccSSepherosa Ziehau int error = 0, rid, capmask; 16776c8d8eccSSepherosa Ziehau uint8_t ether_addr[ETHER_ADDR_LEN]; 167807e9f7c0SSascha Wildner uint16_t product; 16796c8d8eccSSepherosa Ziehau uintptr_t mii_priv = 0; 168066deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 168166deb1c1SSepherosa Ziehau char desc[32]; 168266deb1c1SSepherosa Ziehau int i; 168366deb1c1SSepherosa Ziehau #endif 16846c8d8eccSSepherosa Ziehau 16856c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 16866c8d8eccSSepherosa Ziehau sc->bnx_dev = dev; 168750668ed5SSepherosa Ziehau callout_init_mp(&sc->bnx_stat_timer); 1688df9ccc98SSepherosa Ziehau callout_init_mp(&sc->bnx_intr_timer); 16896c8d8eccSSepherosa Ziehau lwkt_serialize_init(&sc->bnx_jslot_serializer); 16906c8d8eccSSepherosa Ziehau 16916c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 16926c8d8eccSSepherosa Ziehau 16936c8d8eccSSepherosa Ziehau #ifndef BURN_BRIDGES 16946c8d8eccSSepherosa Ziehau if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 16956c8d8eccSSepherosa Ziehau uint32_t irq, mem; 16966c8d8eccSSepherosa Ziehau 16976c8d8eccSSepherosa Ziehau irq = pci_read_config(dev, PCIR_INTLINE, 4); 16986c8d8eccSSepherosa Ziehau mem = pci_read_config(dev, BGE_PCI_BAR0, 4); 16996c8d8eccSSepherosa Ziehau 17006c8d8eccSSepherosa Ziehau device_printf(dev, "chip is in D%d power mode " 17016c8d8eccSSepherosa Ziehau "-- setting to D0\n", pci_get_powerstate(dev)); 17026c8d8eccSSepherosa Ziehau 17036c8d8eccSSepherosa Ziehau pci_set_powerstate(dev, PCI_POWERSTATE_D0); 17046c8d8eccSSepherosa Ziehau 17056c8d8eccSSepherosa Ziehau pci_write_config(dev, PCIR_INTLINE, irq, 4); 17066c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_BAR0, mem, 4); 17076c8d8eccSSepherosa Ziehau } 17086c8d8eccSSepherosa Ziehau #endif /* !BURN_BRIDGE */ 17096c8d8eccSSepherosa Ziehau 17106c8d8eccSSepherosa Ziehau /* 17116c8d8eccSSepherosa Ziehau * Map control/status registers. 17126c8d8eccSSepherosa Ziehau */ 17136c8d8eccSSepherosa Ziehau pci_enable_busmaster(dev); 17146c8d8eccSSepherosa Ziehau 17156c8d8eccSSepherosa Ziehau rid = BGE_PCI_BAR0; 17166c8d8eccSSepherosa Ziehau sc->bnx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 17176c8d8eccSSepherosa Ziehau RF_ACTIVE); 17186c8d8eccSSepherosa Ziehau 17196c8d8eccSSepherosa Ziehau if (sc->bnx_res == NULL) { 17206c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't map memory\n"); 17216c8d8eccSSepherosa Ziehau return ENXIO; 17226c8d8eccSSepherosa Ziehau } 17236c8d8eccSSepherosa Ziehau 17246c8d8eccSSepherosa Ziehau sc->bnx_btag = rman_get_bustag(sc->bnx_res); 17256c8d8eccSSepherosa Ziehau sc->bnx_bhandle = rman_get_bushandle(sc->bnx_res); 17266c8d8eccSSepherosa Ziehau 17276c8d8eccSSepherosa Ziehau /* Save various chip information */ 17286c8d8eccSSepherosa Ziehau sc->bnx_chipid = 17296c8d8eccSSepherosa Ziehau pci_read_config(dev, BGE_PCI_MISC_CTL, 4) >> 17306c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_ASICREV_SHIFT; 17316c8d8eccSSepherosa Ziehau if (BGE_ASICREV(sc->bnx_chipid) == BGE_ASICREV_USE_PRODID_REG) { 17326c8d8eccSSepherosa Ziehau /* All chips having dedicated ASICREV register have CPMU */ 17336c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_CPMU; 17346c8d8eccSSepherosa Ziehau 17356c8d8eccSSepherosa Ziehau switch (product) { 17366c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717: 1737d79f5d8fSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717C: 17386c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5718: 17396c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5719: 17406c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5720_ALT: 1741b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5725: 1742b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5727: 1743b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5762: 17446c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17456c8d8eccSSepherosa Ziehau BGE_PCI_GEN2_PRODID_ASICREV, 4); 17466c8d8eccSSepherosa Ziehau break; 17476c8d8eccSSepherosa Ziehau 17486c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57761: 174932ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57762: 17506c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57765: 175132ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57766: 17526c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57781: 175332ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57782: 17546c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57785: 175532ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57786: 17566c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57791: 17576c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57795: 17586c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17596c8d8eccSSepherosa Ziehau BGE_PCI_GEN15_PRODID_ASICREV, 4); 17606c8d8eccSSepherosa Ziehau break; 17616c8d8eccSSepherosa Ziehau 17626c8d8eccSSepherosa Ziehau default: 17636c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17646c8d8eccSSepherosa Ziehau BGE_PCI_PRODID_ASICREV, 4); 17656c8d8eccSSepherosa Ziehau break; 17666c8d8eccSSepherosa Ziehau } 17676c8d8eccSSepherosa Ziehau } 1768d79f5d8fSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_C0) 1769d79f5d8fSSepherosa Ziehau sc->bnx_chipid = BGE_CHIPID_BCM5720_A0; 1770d79f5d8fSSepherosa Ziehau 17716c8d8eccSSepherosa Ziehau sc->bnx_asicrev = BGE_ASICREV(sc->bnx_chipid); 17726c8d8eccSSepherosa Ziehau sc->bnx_chiprev = BGE_CHIPREV(sc->bnx_chipid); 17736c8d8eccSSepherosa Ziehau 17746c8d8eccSSepherosa Ziehau switch (sc->bnx_asicrev) { 17756c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5717: 17766c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5719: 17776c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5720: 1778f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_5717_PLUS | BNX_FLAG_57765_PLUS; 1779f368d0d9SSepherosa Ziehau break; 1780f368d0d9SSepherosa Ziehau 1781b96cbbb6SSepherosa Ziehau case BGE_ASICREV_BCM5762: 1782b96cbbb6SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_PLUS; 1783b96cbbb6SSepherosa Ziehau break; 1784b96cbbb6SSepherosa Ziehau 17856c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM57765: 178632ff3c80SSepherosa Ziehau case BGE_ASICREV_BCM57766: 1787f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_FAMILY | BNX_FLAG_57765_PLUS; 17886c8d8eccSSepherosa Ziehau break; 17896c8d8eccSSepherosa Ziehau } 17906c8d8eccSSepherosa Ziehau 179166deb1c1SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TSO; 179266deb1c1SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 && 179366deb1c1SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0) 179466deb1c1SSepherosa Ziehau sc->bnx_flags &= ~BNX_FLAG_TSO; 179566deb1c1SSepherosa Ziehau 1796df9ccc98SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1797df9ccc98SSepherosa Ziehau BNX_IS_57765_FAMILY(sc)) { 1798df9ccc98SSepherosa Ziehau /* 1799df9ccc98SSepherosa Ziehau * All BCM57785 and BCM5718 families chips have a bug that 1800df9ccc98SSepherosa Ziehau * under certain situation interrupt will not be enabled 1801df9ccc98SSepherosa Ziehau * even if status tag is written to BGE_MBX_IRQ0_LO mailbox. 1802df9ccc98SSepherosa Ziehau * 1803df9ccc98SSepherosa Ziehau * While BCM5719 and BCM5720 have a hardware workaround 1804df9ccc98SSepherosa Ziehau * which could fix the above bug. 1805df9ccc98SSepherosa Ziehau * See the comment near BGE_PCIDMARWCTL_TAGGED_STATUS_WA in 1806df9ccc98SSepherosa Ziehau * bnx_chipinit(). 1807df9ccc98SSepherosa Ziehau * 1808df9ccc98SSepherosa Ziehau * For the rest of the chips in these two families, we will 1809df9ccc98SSepherosa Ziehau * have to poll the status block at high rate (10ms currently) 1810df9ccc98SSepherosa Ziehau * to check whether the interrupt is hosed or not. 1811df9ccc98SSepherosa Ziehau * See bnx_intr_check() for details. 1812df9ccc98SSepherosa Ziehau */ 1813df9ccc98SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_STATUSTAG_BUG; 1814df9ccc98SSepherosa Ziehau } 1815df9ccc98SSepherosa Ziehau 18166c8d8eccSSepherosa Ziehau sc->bnx_pciecap = pci_get_pciecap_ptr(sc->bnx_dev); 18176c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 18186c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720) 18196c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_2048); 18206c8d8eccSSepherosa Ziehau else 18216c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_4096); 18226c8d8eccSSepherosa Ziehau device_printf(dev, "CHIP ID 0x%08x; " 18236c8d8eccSSepherosa Ziehau "ASIC REV 0x%02x; CHIP REV 0x%02x\n", 18246c8d8eccSSepherosa Ziehau sc->bnx_chipid, sc->bnx_asicrev, sc->bnx_chiprev); 18256c8d8eccSSepherosa Ziehau 18266c8d8eccSSepherosa Ziehau /* 18276c8d8eccSSepherosa Ziehau * Set various PHY quirk flags. 18286c8d8eccSSepherosa Ziehau */ 18296c8d8eccSSepherosa Ziehau 18306c8d8eccSSepherosa Ziehau capmask = MII_CAPMASK_DEFAULT; 183146283a40SSepherosa Ziehau if (product == PCI_PRODUCT_BROADCOM_BCM57791 || 183246283a40SSepherosa Ziehau product == PCI_PRODUCT_BROADCOM_BCM57795) { 18336c8d8eccSSepherosa Ziehau /* 10/100 only */ 18346c8d8eccSSepherosa Ziehau capmask &= ~BMSR_EXTSTAT; 18356c8d8eccSSepherosa Ziehau } 18366c8d8eccSSepherosa Ziehau 18376c8d8eccSSepherosa Ziehau mii_priv |= BRGPHY_FLAG_WIRESPEED; 1838b96cbbb6SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5762_A0) 1839b96cbbb6SSepherosa Ziehau mii_priv |= BRGPHY_FLAG_5762_A0; 18406c8d8eccSSepherosa Ziehau 18416c8d8eccSSepherosa Ziehau /* Initialize if_name earlier, so if_printf could be used */ 18426c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 18436c8d8eccSSepherosa Ziehau if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 18446c8d8eccSSepherosa Ziehau 18456c8d8eccSSepherosa Ziehau /* Try to reset the chip. */ 18466c8d8eccSSepherosa Ziehau bnx_reset(sc); 18476c8d8eccSSepherosa Ziehau 18486c8d8eccSSepherosa Ziehau if (bnx_chipinit(sc)) { 18496c8d8eccSSepherosa Ziehau device_printf(dev, "chip initialization failed\n"); 18506c8d8eccSSepherosa Ziehau error = ENXIO; 18516c8d8eccSSepherosa Ziehau goto fail; 18526c8d8eccSSepherosa Ziehau } 18536c8d8eccSSepherosa Ziehau 18546c8d8eccSSepherosa Ziehau /* 18556c8d8eccSSepherosa Ziehau * Get station address 18566c8d8eccSSepherosa Ziehau */ 18576c8d8eccSSepherosa Ziehau error = bnx_get_eaddr(sc, ether_addr); 18586c8d8eccSSepherosa Ziehau if (error) { 18596c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read station address\n"); 18606c8d8eccSSepherosa Ziehau goto fail; 18616c8d8eccSSepherosa Ziehau } 18626c8d8eccSSepherosa Ziehau 186333a04907SSepherosa Ziehau /* XXX */ 186433a04907SSepherosa Ziehau sc->bnx_tx_ringcnt = 1; 1865beedf5beSSepherosa Ziehau sc->bnx_rx_retcnt = 1; 186633a04907SSepherosa Ziehau 1867beedf5beSSepherosa Ziehau error = bnx_dma_alloc(dev); 18686c8d8eccSSepherosa Ziehau if (error) 18696c8d8eccSSepherosa Ziehau goto fail; 18706c8d8eccSSepherosa Ziehau 187116b32c4cSSepherosa Ziehau /* 187216b32c4cSSepherosa Ziehau * Allocate interrupt 187316b32c4cSSepherosa Ziehau */ 18740c7da01dSSepherosa Ziehau error = bnx_alloc_intr(sc); 18750c7da01dSSepherosa Ziehau if (error) 187616b32c4cSSepherosa Ziehau goto fail; 187716b32c4cSSepherosa Ziehau 18786c8d8eccSSepherosa Ziehau /* Set default tuneable values. */ 18796c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks = BNX_RX_COAL_TICKS_DEF; 18806c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks = BNX_TX_COAL_TICKS_DEF; 18816c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds = BNX_RX_COAL_BDS_DEF; 18826c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds = BNX_TX_COAL_BDS_DEF; 1883306e5498SSepherosa Ziehau sc->bnx_rx_coal_bds_int = BNX_RX_COAL_BDS_INT_DEF; 1884306e5498SSepherosa Ziehau sc->bnx_tx_coal_bds_int = BNX_TX_COAL_BDS_INT_DEF; 18856c8d8eccSSepherosa Ziehau 18866c8d8eccSSepherosa Ziehau /* Set up ifnet structure */ 18876c8d8eccSSepherosa Ziehau ifp->if_softc = sc; 18886c8d8eccSSepherosa Ziehau ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 18896c8d8eccSSepherosa Ziehau ifp->if_ioctl = bnx_ioctl; 18906c8d8eccSSepherosa Ziehau ifp->if_start = bnx_start; 189139a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 189239a8d43aSSepherosa Ziehau ifp->if_npoll = bnx_npoll; 18936c8d8eccSSepherosa Ziehau #endif 18946c8d8eccSSepherosa Ziehau ifp->if_watchdog = bnx_watchdog; 18956c8d8eccSSepherosa Ziehau ifp->if_init = bnx_init; 18966c8d8eccSSepherosa Ziehau ifp->if_mtu = ETHERMTU; 18976c8d8eccSSepherosa Ziehau ifp->if_capabilities = IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; 18986c8d8eccSSepherosa Ziehau ifq_set_maxlen(&ifp->if_snd, BGE_TX_RING_CNT - 1); 18996c8d8eccSSepherosa Ziehau ifq_set_ready(&ifp->if_snd); 19006c8d8eccSSepherosa Ziehau 19016c8d8eccSSepherosa Ziehau ifp->if_capabilities |= IFCAP_HWCSUM; 19026c8d8eccSSepherosa Ziehau ifp->if_hwassist = BNX_CSUM_FEATURES; 190366deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 190466deb1c1SSepherosa Ziehau ifp->if_capabilities |= IFCAP_TSO; 190566deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 190666deb1c1SSepherosa Ziehau } 19076c8d8eccSSepherosa Ziehau ifp->if_capenable = ifp->if_capabilities; 19086c8d8eccSSepherosa Ziehau 19096c8d8eccSSepherosa Ziehau /* 19106c8d8eccSSepherosa Ziehau * Figure out what sort of media we have by checking the 19116c8d8eccSSepherosa Ziehau * hardware config word in the first 32k of NIC internal memory, 19126c8d8eccSSepherosa Ziehau * or fall back to examining the EEPROM if necessary. 19136c8d8eccSSepherosa Ziehau * Note: on some BCM5700 cards, this value appears to be unset. 19146c8d8eccSSepherosa Ziehau * If that's the case, we have to rely on identifying the NIC 19156c8d8eccSSepherosa Ziehau * by its PCI subsystem ID, as we do below for the SysKonnect 19166c8d8eccSSepherosa Ziehau * SK-9D41. 19176c8d8eccSSepherosa Ziehau */ 19186c8d8eccSSepherosa Ziehau if (bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER) { 19196c8d8eccSSepherosa Ziehau hwcfg = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG); 19206c8d8eccSSepherosa Ziehau } else { 19216c8d8eccSSepherosa Ziehau if (bnx_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET, 19226c8d8eccSSepherosa Ziehau sizeof(hwcfg))) { 19236c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read EEPROM\n"); 19246c8d8eccSSepherosa Ziehau error = ENXIO; 19256c8d8eccSSepherosa Ziehau goto fail; 19266c8d8eccSSepherosa Ziehau } 19276c8d8eccSSepherosa Ziehau hwcfg = ntohl(hwcfg); 19286c8d8eccSSepherosa Ziehau } 19296c8d8eccSSepherosa Ziehau 19306c8d8eccSSepherosa Ziehau /* The SysKonnect SK-9D41 is a 1000baseSX card. */ 19316c8d8eccSSepherosa Ziehau if (pci_get_subvendor(dev) == PCI_PRODUCT_SCHNEIDERKOCH_SK_9D41 || 19326c8d8eccSSepherosa Ziehau (hwcfg & BGE_HWCFG_MEDIA) == BGE_MEDIA_FIBER) 19336c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TBI; 19346c8d8eccSSepherosa Ziehau 19356c8d8eccSSepherosa Ziehau /* Setup MI MODE */ 19366c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_CPMU) 19376c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_500KHZ_CONST; 19386c8d8eccSSepherosa Ziehau else 19396c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_BASE; 19406c8d8eccSSepherosa Ziehau 19416c8d8eccSSepherosa Ziehau /* Setup link status update stuffs */ 19426c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 19436c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_tbi_link_upd; 19446c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19456c8d8eccSSepherosa Ziehau } else if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 19466c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_autopoll_link_upd; 19476c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19486c8d8eccSSepherosa Ziehau } else { 19496c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_copper_link_upd; 19506c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19516c8d8eccSSepherosa Ziehau } 19526c8d8eccSSepherosa Ziehau 19536c8d8eccSSepherosa Ziehau /* Set default PHY address */ 19546c8d8eccSSepherosa Ziehau sc->bnx_phyno = 1; 19556c8d8eccSSepherosa Ziehau 19566c8d8eccSSepherosa Ziehau /* 19576c8d8eccSSepherosa Ziehau * PHY address mapping for various devices. 19586c8d8eccSSepherosa Ziehau * 19596c8d8eccSSepherosa Ziehau * | F0 Cu | F0 Sr | F1 Cu | F1 Sr | 19606c8d8eccSSepherosa Ziehau * ---------+-------+-------+-------+-------+ 19616c8d8eccSSepherosa Ziehau * BCM57XX | 1 | X | X | X | 19626c8d8eccSSepherosa Ziehau * BCM5704 | 1 | X | 1 | X | 19636c8d8eccSSepherosa Ziehau * BCM5717 | 1 | 8 | 2 | 9 | 19646c8d8eccSSepherosa Ziehau * BCM5719 | 1 | 8 | 2 | 9 | 19656c8d8eccSSepherosa Ziehau * BCM5720 | 1 | 8 | 2 | 9 | 19666c8d8eccSSepherosa Ziehau * 19676c8d8eccSSepherosa Ziehau * Other addresses may respond but they are not 19686c8d8eccSSepherosa Ziehau * IEEE compliant PHYs and should be ignored. 19696c8d8eccSSepherosa Ziehau */ 197080969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 19716c8d8eccSSepherosa Ziehau int f; 19726c8d8eccSSepherosa Ziehau 19736c8d8eccSSepherosa Ziehau f = pci_get_function(dev); 19746c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_A0) { 19756c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_SGDIG_STS) & 19766c8d8eccSSepherosa Ziehau BGE_SGDIGSTS_IS_SERDES) 19776c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 19786c8d8eccSSepherosa Ziehau else 19796c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 19806c8d8eccSSepherosa Ziehau } else { 19816c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_CPMU_PHY_STRAP) & 19826c8d8eccSSepherosa Ziehau BGE_CPMU_PHY_STRAP_IS_SERDES) 19836c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 19846c8d8eccSSepherosa Ziehau else 19856c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 19866c8d8eccSSepherosa Ziehau } 19876c8d8eccSSepherosa Ziehau } 19886c8d8eccSSepherosa Ziehau 19896c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 19906c8d8eccSSepherosa Ziehau ifmedia_init(&sc->bnx_ifmedia, IFM_IMASK, 19916c8d8eccSSepherosa Ziehau bnx_ifmedia_upd, bnx_ifmedia_sts); 19926c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL); 19936c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, 19946c8d8eccSSepherosa Ziehau IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL); 19956c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 19966c8d8eccSSepherosa Ziehau ifmedia_set(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO); 19976c8d8eccSSepherosa Ziehau sc->bnx_ifmedia.ifm_media = sc->bnx_ifmedia.ifm_cur->ifm_media; 19986c8d8eccSSepherosa Ziehau } else { 19996c8d8eccSSepherosa Ziehau struct mii_probe_args mii_args; 20006c8d8eccSSepherosa Ziehau 20016c8d8eccSSepherosa Ziehau mii_probe_args_init(&mii_args, bnx_ifmedia_upd, bnx_ifmedia_sts); 20026c8d8eccSSepherosa Ziehau mii_args.mii_probemask = 1 << sc->bnx_phyno; 20036c8d8eccSSepherosa Ziehau mii_args.mii_capmask = capmask; 20046c8d8eccSSepherosa Ziehau mii_args.mii_privtag = MII_PRIVTAG_BRGPHY; 20056c8d8eccSSepherosa Ziehau mii_args.mii_priv = mii_priv; 20066c8d8eccSSepherosa Ziehau 20076c8d8eccSSepherosa Ziehau error = mii_probe(dev, &sc->bnx_miibus, &mii_args); 20086c8d8eccSSepherosa Ziehau if (error) { 20096c8d8eccSSepherosa Ziehau device_printf(dev, "MII without any PHY!\n"); 20106c8d8eccSSepherosa Ziehau goto fail; 20116c8d8eccSSepherosa Ziehau } 20126c8d8eccSSepherosa Ziehau } 20136c8d8eccSSepherosa Ziehau 20146c8d8eccSSepherosa Ziehau /* 20156c8d8eccSSepherosa Ziehau * Create sysctl nodes. 20166c8d8eccSSepherosa Ziehau */ 20176c8d8eccSSepherosa Ziehau sysctl_ctx_init(&sc->bnx_sysctl_ctx); 20186c8d8eccSSepherosa Ziehau sc->bnx_sysctl_tree = SYSCTL_ADD_NODE(&sc->bnx_sysctl_ctx, 20196c8d8eccSSepherosa Ziehau SYSCTL_STATIC_CHILDREN(_hw), 20206c8d8eccSSepherosa Ziehau OID_AUTO, 20216c8d8eccSSepherosa Ziehau device_get_nameunit(dev), 20226c8d8eccSSepherosa Ziehau CTLFLAG_RD, 0, ""); 20236c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree == NULL) { 20246c8d8eccSSepherosa Ziehau device_printf(dev, "can't add sysctl node\n"); 20256c8d8eccSSepherosa Ziehau error = ENXIO; 20266c8d8eccSSepherosa Ziehau goto fail; 20276c8d8eccSSepherosa Ziehau } 20286c8d8eccSSepherosa Ziehau 20296c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20306c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20316c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_ticks", 20326c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20336c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_ticks, "I", 20346c8d8eccSSepherosa Ziehau "Receive coalescing ticks (usec)."); 20356c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20366c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20376c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_ticks", 20386c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20396c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_ticks, "I", 20406c8d8eccSSepherosa Ziehau "Transmit coalescing ticks (usec)."); 20416c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20426c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20436c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_bds", 20446c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20456c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds, "I", 20466c8d8eccSSepherosa Ziehau "Receive max coalesced BD count."); 20476c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20486c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20496c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_bds", 20506c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20516c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds, "I", 20526c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count."); 20536c8d8eccSSepherosa Ziehau /* 20546c8d8eccSSepherosa Ziehau * A common design characteristic for many Broadcom 20556c8d8eccSSepherosa Ziehau * client controllers is that they only support a 20566c8d8eccSSepherosa Ziehau * single outstanding DMA read operation on the PCIe 20576c8d8eccSSepherosa Ziehau * bus. This means that it will take twice as long to 20586c8d8eccSSepherosa Ziehau * fetch a TX frame that is split into header and 20596c8d8eccSSepherosa Ziehau * payload buffers as it does to fetch a single, 20606c8d8eccSSepherosa Ziehau * contiguous TX frame (2 reads vs. 1 read). For these 20616c8d8eccSSepherosa Ziehau * controllers, coalescing buffers to reduce the number 20626c8d8eccSSepherosa Ziehau * of memory reads is effective way to get maximum 20636c8d8eccSSepherosa Ziehau * performance(about 940Mbps). Without collapsing TX 20646c8d8eccSSepherosa Ziehau * buffers the maximum TCP bulk transfer performance 20656c8d8eccSSepherosa Ziehau * is about 850Mbps. However forcing coalescing mbufs 20666c8d8eccSSepherosa Ziehau * consumes a lot of CPU cycles, so leave it off by 20676c8d8eccSSepherosa Ziehau * default. 20686c8d8eccSSepherosa Ziehau */ 2069aad4de2bSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20706c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2071aad4de2bSSepherosa Ziehau "force_defrag", CTLTYPE_INT | CTLFLAG_RW, 2072aad4de2bSSepherosa Ziehau sc, 0, bnx_sysctl_force_defrag, "I", 20736c8d8eccSSepherosa Ziehau "Force defragment on TX path"); 20746c8d8eccSSepherosa Ziehau 2075472c99c8SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 2076c9b7f592SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2077472c99c8SSepherosa Ziehau "tx_wreg", CTLTYPE_INT | CTLFLAG_RW, 2078472c99c8SSepherosa Ziehau sc, 0, bnx_sysctl_tx_wreg, "I", 2079c9b7f592SSepherosa Ziehau "# of segments before writing to hardware register"); 2080c9b7f592SSepherosa Ziehau 20816c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20826c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 20836c8d8eccSSepherosa Ziehau "rx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 20846c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds_int, "I", 20856c8d8eccSSepherosa Ziehau "Receive max coalesced BD count during interrupt."); 20866c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20876c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 20886c8d8eccSSepherosa Ziehau "tx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 20896c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds_int, "I", 20906c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count during interrupt."); 20916c8d8eccSSepherosa Ziehau 209266deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 209366deb1c1SSepherosa Ziehau for (i = 0; i < BNX_TSO_NSTATS; ++i) { 209466deb1c1SSepherosa Ziehau ksnprintf(desc, sizeof(desc), "tso%d", i + 1); 209566deb1c1SSepherosa Ziehau SYSCTL_ADD_ULONG(&sc->bnx_sysctl_ctx, 209666deb1c1SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 209766deb1c1SSepherosa Ziehau desc, CTLFLAG_RW, &sc->bnx_tsosegs[i], ""); 209866deb1c1SSepherosa Ziehau } 209966deb1c1SSepherosa Ziehau #endif 210066deb1c1SSepherosa Ziehau 21016c8d8eccSSepherosa Ziehau /* 21026c8d8eccSSepherosa Ziehau * Call MI attach routine. 21036c8d8eccSSepherosa Ziehau */ 21046c8d8eccSSepherosa Ziehau ether_ifattach(ifp, ether_addr, NULL); 21056c8d8eccSSepherosa Ziehau 21064c77af2dSSepherosa Ziehau ifq_set_cpuid(&ifp->if_snd, sc->bnx_intr_cpuid); 21074c77af2dSSepherosa Ziehau 2108b5de76b1SSepherosa Ziehau #ifdef IFPOLL_ENABLE 2109b5de76b1SSepherosa Ziehau ifpoll_compat_setup(&sc->bnx_npoll, 2110b5de76b1SSepherosa Ziehau &sc->bnx_sysctl_ctx, sc->bnx_sysctl_tree, 2111b5de76b1SSepherosa Ziehau device_get_unit(dev), ifp->if_serializer); 2112b5de76b1SSepherosa Ziehau #endif 2113b5de76b1SSepherosa Ziehau 21140c7da01dSSepherosa Ziehau error = bnx_setup_intr(sc); 21156c8d8eccSSepherosa Ziehau if (error) { 21166c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 21176c8d8eccSSepherosa Ziehau goto fail; 21186c8d8eccSSepherosa Ziehau } 21196c8d8eccSSepherosa Ziehau 2120dfd3b18bSSepherosa Ziehau sc->bnx_intr_cpuid = rman_get_cpuid(sc->bnx_irq); 2121dfd3b18bSSepherosa Ziehau sc->bnx_stat_cpuid = sc->bnx_intr_cpuid; 21228ca0f604SSepherosa Ziehau 21236c8d8eccSSepherosa Ziehau return(0); 21246c8d8eccSSepherosa Ziehau fail: 21256c8d8eccSSepherosa Ziehau bnx_detach(dev); 21266c8d8eccSSepherosa Ziehau return(error); 21276c8d8eccSSepherosa Ziehau } 21286c8d8eccSSepherosa Ziehau 21296c8d8eccSSepherosa Ziehau static int 21306c8d8eccSSepherosa Ziehau bnx_detach(device_t dev) 21316c8d8eccSSepherosa Ziehau { 21326c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 21336c8d8eccSSepherosa Ziehau 21346c8d8eccSSepherosa Ziehau if (device_is_attached(dev)) { 21356c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 21366c8d8eccSSepherosa Ziehau 21376c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 21386c8d8eccSSepherosa Ziehau bnx_stop(sc); 21396c8d8eccSSepherosa Ziehau bnx_reset(sc); 21406c8d8eccSSepherosa Ziehau bus_teardown_intr(dev, sc->bnx_irq, sc->bnx_intrhand); 21416c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 21426c8d8eccSSepherosa Ziehau 21436c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 21446c8d8eccSSepherosa Ziehau } 21456c8d8eccSSepherosa Ziehau 21466c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 21476c8d8eccSSepherosa Ziehau ifmedia_removeall(&sc->bnx_ifmedia); 21486c8d8eccSSepherosa Ziehau if (sc->bnx_miibus) 21496c8d8eccSSepherosa Ziehau device_delete_child(dev, sc->bnx_miibus); 21506c8d8eccSSepherosa Ziehau bus_generic_detach(dev); 21516c8d8eccSSepherosa Ziehau 21520c7da01dSSepherosa Ziehau bnx_free_intr(sc); 21536c8d8eccSSepherosa Ziehau 21546c8d8eccSSepherosa Ziehau if (sc->bnx_res != NULL) { 21556c8d8eccSSepherosa Ziehau bus_release_resource(dev, SYS_RES_MEMORY, 21566c8d8eccSSepherosa Ziehau BGE_PCI_BAR0, sc->bnx_res); 21576c8d8eccSSepherosa Ziehau } 21586c8d8eccSSepherosa Ziehau 21596c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree != NULL) 21606c8d8eccSSepherosa Ziehau sysctl_ctx_free(&sc->bnx_sysctl_ctx); 21616c8d8eccSSepherosa Ziehau 21626c8d8eccSSepherosa Ziehau bnx_dma_free(sc); 21636c8d8eccSSepherosa Ziehau 21646c8d8eccSSepherosa Ziehau return 0; 21656c8d8eccSSepherosa Ziehau } 21666c8d8eccSSepherosa Ziehau 21676c8d8eccSSepherosa Ziehau static void 21686c8d8eccSSepherosa Ziehau bnx_reset(struct bnx_softc *sc) 21696c8d8eccSSepherosa Ziehau { 21706c8d8eccSSepherosa Ziehau device_t dev; 21716c8d8eccSSepherosa Ziehau uint32_t cachesize, command, pcistate, reset; 21726c8d8eccSSepherosa Ziehau void (*write_op)(struct bnx_softc *, uint32_t, uint32_t); 21736c8d8eccSSepherosa Ziehau int i, val = 0; 21746c8d8eccSSepherosa Ziehau uint16_t devctl; 21756c8d8eccSSepherosa Ziehau 21766c8d8eccSSepherosa Ziehau dev = sc->bnx_dev; 21776c8d8eccSSepherosa Ziehau 21786c8d8eccSSepherosa Ziehau write_op = bnx_writemem_direct; 21796c8d8eccSSepherosa Ziehau 21806c8d8eccSSepherosa Ziehau /* Save some important PCI state. */ 21816c8d8eccSSepherosa Ziehau cachesize = pci_read_config(dev, BGE_PCI_CACHESZ, 4); 21826c8d8eccSSepherosa Ziehau command = pci_read_config(dev, BGE_PCI_CMD, 4); 21836c8d8eccSSepherosa Ziehau pcistate = pci_read_config(dev, BGE_PCI_PCISTATE, 4); 21846c8d8eccSSepherosa Ziehau 21856c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 21866c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 21876c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 21886c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 21896c8d8eccSSepherosa Ziehau 21906c8d8eccSSepherosa Ziehau /* Disable fastboot on controllers that support it. */ 21916c8d8eccSSepherosa Ziehau if (bootverbose) 21926c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "Disabling fastboot\n"); 21936c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0x0); 21946c8d8eccSSepherosa Ziehau 21956c8d8eccSSepherosa Ziehau /* 21966c8d8eccSSepherosa Ziehau * Write the magic number to SRAM at offset 0xB50. 21976c8d8eccSSepherosa Ziehau * When firmware finishes its initialization it will 21986c8d8eccSSepherosa Ziehau * write ~BGE_MAGIC_NUMBER to the same location. 21996c8d8eccSSepherosa Ziehau */ 22006c8d8eccSSepherosa Ziehau bnx_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); 22016c8d8eccSSepherosa Ziehau 22026c8d8eccSSepherosa Ziehau reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1); 22036c8d8eccSSepherosa Ziehau 22046c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 22056c8d8eccSSepherosa Ziehau /* Force PCI-E 1.0a mode */ 22063730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc) && 22076c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_PCIE_PHY_TSTCTL) == 22086c8d8eccSSepherosa Ziehau (BGE_PCIE_PHY_TSTCTL_PSCRAM | 22096c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PCIE10)) { 22106c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PHY_TSTCTL, 22116c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PSCRAM); 22126c8d8eccSSepherosa Ziehau } 22136c8d8eccSSepherosa Ziehau if (sc->bnx_chipid != BGE_CHIPID_BCM5750_A0) { 22146c8d8eccSSepherosa Ziehau /* Prevent PCIE link training during global reset */ 22156c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, (1<<29)); 22166c8d8eccSSepherosa Ziehau reset |= (1<<29); 22176c8d8eccSSepherosa Ziehau } 22186c8d8eccSSepherosa Ziehau 22196c8d8eccSSepherosa Ziehau /* 22206c8d8eccSSepherosa Ziehau * Set GPHY Power Down Override to leave GPHY 22216c8d8eccSSepherosa Ziehau * powered up in D0 uninitialized. 22226c8d8eccSSepherosa Ziehau */ 22236c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) 22246c8d8eccSSepherosa Ziehau reset |= BGE_MISCCFG_GPHY_PD_OVERRIDE; 22256c8d8eccSSepherosa Ziehau 22266c8d8eccSSepherosa Ziehau /* Issue global reset */ 22276c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, reset); 22286c8d8eccSSepherosa Ziehau 22296c8d8eccSSepherosa Ziehau DELAY(1000); 22306c8d8eccSSepherosa Ziehau 22316c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 22326c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5750_A0) { 22336c8d8eccSSepherosa Ziehau uint32_t v; 22346c8d8eccSSepherosa Ziehau 22356c8d8eccSSepherosa Ziehau DELAY(500000); /* wait for link training to complete */ 22366c8d8eccSSepherosa Ziehau v = pci_read_config(dev, 0xc4, 4); 22376c8d8eccSSepherosa Ziehau pci_write_config(dev, 0xc4, v | (1<<15), 4); 22386c8d8eccSSepherosa Ziehau } 22396c8d8eccSSepherosa Ziehau 22406c8d8eccSSepherosa Ziehau devctl = pci_read_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 2); 22416c8d8eccSSepherosa Ziehau 22426c8d8eccSSepherosa Ziehau /* Disable no snoop and disable relaxed ordering. */ 22436c8d8eccSSepherosa Ziehau devctl &= ~(PCIEM_DEVCTL_RELAX_ORDER | PCIEM_DEVCTL_NOSNOOP); 22446c8d8eccSSepherosa Ziehau 22456c8d8eccSSepherosa Ziehau /* Old PCI-E chips only support 128 bytes Max PayLoad Size. */ 22466c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) { 22476c8d8eccSSepherosa Ziehau devctl &= ~PCIEM_DEVCTL_MAX_PAYLOAD_MASK; 22486c8d8eccSSepherosa Ziehau devctl |= PCIEM_DEVCTL_MAX_PAYLOAD_128; 22496c8d8eccSSepherosa Ziehau } 22506c8d8eccSSepherosa Ziehau 22516c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 22526c8d8eccSSepherosa Ziehau devctl, 2); 22536c8d8eccSSepherosa Ziehau 22546c8d8eccSSepherosa Ziehau /* Clear error status. */ 22556c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVSTS, 22566c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_CORR_ERR | 22576c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_NFATAL_ERR | 22586c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_FATAL_ERR | 22596c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_UNSUPP_REQ, 2); 22606c8d8eccSSepherosa Ziehau 22616c8d8eccSSepherosa Ziehau /* Reset some of the PCI state that got zapped by reset */ 22626c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 22636c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 22646c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 22656c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 22666c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CACHESZ, cachesize, 4); 22676c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CMD, command, 4); 22686c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, (65 << 1)); 22696c8d8eccSSepherosa Ziehau 22706c8d8eccSSepherosa Ziehau /* Enable memory arbiter */ 22716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); 22726c8d8eccSSepherosa Ziehau 22736c8d8eccSSepherosa Ziehau /* 22746c8d8eccSSepherosa Ziehau * Poll until we see the 1's complement of the magic number. 2275ddd93a5cSSepherosa Ziehau * This indicates that the firmware initialization is complete. 22766c8d8eccSSepherosa Ziehau */ 22776c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_FIRMWARE_TIMEOUT; i++) { 22786c8d8eccSSepherosa Ziehau val = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM); 22796c8d8eccSSepherosa Ziehau if (val == ~BGE_MAGIC_NUMBER) 22806c8d8eccSSepherosa Ziehau break; 22816c8d8eccSSepherosa Ziehau DELAY(10); 22826c8d8eccSSepherosa Ziehau } 22836c8d8eccSSepherosa Ziehau if (i == BNX_FIRMWARE_TIMEOUT) { 22846c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "firmware handshake " 22856c8d8eccSSepherosa Ziehau "timed out, found 0x%08x\n", val); 22866c8d8eccSSepherosa Ziehau } 22876c8d8eccSSepherosa Ziehau 22886c8d8eccSSepherosa Ziehau /* BCM57765 A0 needs additional time before accessing. */ 22896c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 22906c8d8eccSSepherosa Ziehau DELAY(10 * 1000); 22916c8d8eccSSepherosa Ziehau 22926c8d8eccSSepherosa Ziehau /* 22936c8d8eccSSepherosa Ziehau * XXX Wait for the value of the PCISTATE register to 22946c8d8eccSSepherosa Ziehau * return to its original pre-reset state. This is a 22956c8d8eccSSepherosa Ziehau * fairly good indicator of reset completion. If we don't 22966c8d8eccSSepherosa Ziehau * wait for the reset to fully complete, trying to read 22976c8d8eccSSepherosa Ziehau * from the device's non-PCI registers may yield garbage 22986c8d8eccSSepherosa Ziehau * results. 22996c8d8eccSSepherosa Ziehau */ 23006c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 23016c8d8eccSSepherosa Ziehau if (pci_read_config(dev, BGE_PCI_PCISTATE, 4) == pcistate) 23026c8d8eccSSepherosa Ziehau break; 23036c8d8eccSSepherosa Ziehau DELAY(10); 23046c8d8eccSSepherosa Ziehau } 23056c8d8eccSSepherosa Ziehau 23066c8d8eccSSepherosa Ziehau /* Fix up byte swapping */ 23076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, bnx_dma_swap_options(sc)); 23086c8d8eccSSepherosa Ziehau 23096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 23106c8d8eccSSepherosa Ziehau 23116c8d8eccSSepherosa Ziehau /* 23126c8d8eccSSepherosa Ziehau * The 5704 in TBI mode apparently needs some special 23136c8d8eccSSepherosa Ziehau * adjustment to insure the SERDES drive level is set 23146c8d8eccSSepherosa Ziehau * to 1.2V. 23156c8d8eccSSepherosa Ziehau */ 23166c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704 && 23176c8d8eccSSepherosa Ziehau (sc->bnx_flags & BNX_FLAG_TBI)) { 23186c8d8eccSSepherosa Ziehau uint32_t serdescfg; 23196c8d8eccSSepherosa Ziehau 23206c8d8eccSSepherosa Ziehau serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG); 23216c8d8eccSSepherosa Ziehau serdescfg = (serdescfg & ~0xFFF) | 0x880; 23226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg); 23236c8d8eccSSepherosa Ziehau } 23246c8d8eccSSepherosa Ziehau 23257892075dSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 23267892075dSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 23277892075dSSepherosa Ziehau DELAY(80); 23287892075dSSepherosa Ziehau 23296c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 23303730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc)) { 23316c8d8eccSSepherosa Ziehau uint32_t v; 23326c8d8eccSSepherosa Ziehau 23336c8d8eccSSepherosa Ziehau /* Enable Data FIFO protection. */ 2334f1f34fc4SSepherosa Ziehau v = CSR_READ_4(sc, BGE_PCIE_TLDLPL_PORT); 2335f1f34fc4SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_TLDLPL_PORT, v | (1 << 25)); 23366c8d8eccSSepherosa Ziehau } 23376c8d8eccSSepherosa Ziehau 23386c8d8eccSSepherosa Ziehau DELAY(10000); 23396c8d8eccSSepherosa Ziehau 23406c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 23416c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE, 23426c8d8eccSSepherosa Ziehau CPMU_CLCK_ORIDE_MAC_ORIDE_EN); 23436c8d8eccSSepherosa Ziehau } 23446c8d8eccSSepherosa Ziehau } 23456c8d8eccSSepherosa Ziehau 23466c8d8eccSSepherosa Ziehau /* 23476c8d8eccSSepherosa Ziehau * Frame reception handling. This is called if there's a frame 23486c8d8eccSSepherosa Ziehau * on the receive return list. 23496c8d8eccSSepherosa Ziehau * 23506c8d8eccSSepherosa Ziehau * Note: we have to be able to handle two possibilities here: 23516c8d8eccSSepherosa Ziehau * 1) the frame is from the jumbo recieve ring 23526c8d8eccSSepherosa Ziehau * 2) the frame is from the standard receive ring 23536c8d8eccSSepherosa Ziehau */ 23546c8d8eccSSepherosa Ziehau 23556c8d8eccSSepherosa Ziehau static void 2356beedf5beSSepherosa Ziehau bnx_rxeof(struct bnx_rx_ret_ring *ret, uint16_t rx_prod, int count) 23576c8d8eccSSepherosa Ziehau { 2358beedf5beSSepherosa Ziehau struct bnx_softc *sc = ret->bnx_sc; 2359beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = ret->bnx_std; 2360beedf5beSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 23616c8d8eccSSepherosa Ziehau int stdcnt = 0, jumbocnt = 0; 23626c8d8eccSSepherosa Ziehau 2363beedf5beSSepherosa Ziehau while (ret->bnx_rx_saved_considx != rx_prod && count != 0) { 23646c8d8eccSSepherosa Ziehau struct bge_rx_bd *cur_rx; 23656c8d8eccSSepherosa Ziehau uint32_t rxidx; 23666c8d8eccSSepherosa Ziehau struct mbuf *m = NULL; 23676c8d8eccSSepherosa Ziehau uint16_t vlan_tag = 0; 23686c8d8eccSSepherosa Ziehau int have_tag = 0; 23696c8d8eccSSepherosa Ziehau 237097381780SSepherosa Ziehau --count; 237197381780SSepherosa Ziehau 2372beedf5beSSepherosa Ziehau cur_rx = &ret->bnx_rx_ret_ring[ret->bnx_rx_saved_considx]; 23736c8d8eccSSepherosa Ziehau 23746c8d8eccSSepherosa Ziehau rxidx = cur_rx->bge_idx; 2375beedf5beSSepherosa Ziehau BNX_INC(ret->bnx_rx_saved_considx, BNX_RETURN_RING_CNT); 23766c8d8eccSSepherosa Ziehau 23776c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) { 23786c8d8eccSSepherosa Ziehau have_tag = 1; 23796c8d8eccSSepherosa Ziehau vlan_tag = cur_rx->bge_vlan_tag; 23806c8d8eccSSepherosa Ziehau } 23816c8d8eccSSepherosa Ziehau 23826c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_JUMBO_RING) { 23836c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_jumbo, BGE_JUMBO_RX_RING_CNT); 23846c8d8eccSSepherosa Ziehau jumbocnt++; 23856c8d8eccSSepherosa Ziehau 23866c8d8eccSSepherosa Ziehau if (rxidx != sc->bnx_jumbo) { 2387d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 23886c8d8eccSSepherosa Ziehau if_printf(ifp, "sw jumbo index(%d) " 23896c8d8eccSSepherosa Ziehau "and hw jumbo index(%d) mismatch, drop!\n", 23906c8d8eccSSepherosa Ziehau sc->bnx_jumbo, rxidx); 23916c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, rxidx); 23926c8d8eccSSepherosa Ziehau continue; 23936c8d8eccSSepherosa Ziehau } 23946c8d8eccSSepherosa Ziehau 2395beedf5beSSepherosa Ziehau m = sc->bnx_cdata.bnx_rx_jumbo_chain[rxidx].bnx_rx_mbuf; 23966c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 2397d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 23986c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 23996c8d8eccSSepherosa Ziehau continue; 24006c8d8eccSSepherosa Ziehau } 24016c8d8eccSSepherosa Ziehau if (bnx_newbuf_jumbo(sc, sc->bnx_jumbo, 0)) { 2402d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24036c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 24046c8d8eccSSepherosa Ziehau continue; 24056c8d8eccSSepherosa Ziehau } 24066c8d8eccSSepherosa Ziehau } else { 2407beedf5beSSepherosa Ziehau BNX_INC(std->bnx_rx_std, BGE_STD_RX_RING_CNT); 24086c8d8eccSSepherosa Ziehau stdcnt++; 24096c8d8eccSSepherosa Ziehau 2410beedf5beSSepherosa Ziehau if (rxidx != std->bnx_rx_std) { 2411d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24126c8d8eccSSepherosa Ziehau if_printf(ifp, "sw std index(%d) " 24136c8d8eccSSepherosa Ziehau "and hw std index(%d) mismatch, drop!\n", 2414beedf5beSSepherosa Ziehau std->bnx_rx_std, rxidx); 2415beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, rxidx); 24166c8d8eccSSepherosa Ziehau continue; 24176c8d8eccSSepherosa Ziehau } 24186c8d8eccSSepherosa Ziehau 2419beedf5beSSepherosa Ziehau m = std->bnx_rx_std_buf[rxidx].bnx_rx_mbuf; 24206c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 2421d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 2422beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, std->bnx_rx_std); 24236c8d8eccSSepherosa Ziehau continue; 24246c8d8eccSSepherosa Ziehau } 2425beedf5beSSepherosa Ziehau if (bnx_newbuf_std(ret, std->bnx_rx_std, 0)) { 2426d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 2427beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, std->bnx_rx_std); 24286c8d8eccSSepherosa Ziehau continue; 24296c8d8eccSSepherosa Ziehau } 24306c8d8eccSSepherosa Ziehau } 24316c8d8eccSSepherosa Ziehau 2432d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ipackets, 1); 24336c8d8eccSSepherosa Ziehau m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; 24346c8d8eccSSepherosa Ziehau m->m_pkthdr.rcvif = ifp; 24356c8d8eccSSepherosa Ziehau 24366c8d8eccSSepherosa Ziehau if ((ifp->if_capenable & IFCAP_RXCSUM) && 24376c8d8eccSSepherosa Ziehau (cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) { 24386c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) { 24396c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; 24406c8d8eccSSepherosa Ziehau if ((cur_rx->bge_error_flag & 24416c8d8eccSSepherosa Ziehau BGE_RXERRFLAG_IP_CSUM_NOK) == 0) 24426c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 24436c8d8eccSSepherosa Ziehau } 24446c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) { 24456c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_data = 24466c8d8eccSSepherosa Ziehau cur_rx->bge_tcp_udp_csum; 24476c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | 24486c8d8eccSSepherosa Ziehau CSUM_PSEUDO_HDR; 24496c8d8eccSSepherosa Ziehau } 24506c8d8eccSSepherosa Ziehau } 24516c8d8eccSSepherosa Ziehau 24526c8d8eccSSepherosa Ziehau /* 24536c8d8eccSSepherosa Ziehau * If we received a packet with a vlan tag, pass it 24546c8d8eccSSepherosa Ziehau * to vlan_input() instead of ether_input(). 24556c8d8eccSSepherosa Ziehau */ 24566c8d8eccSSepherosa Ziehau if (have_tag) { 24576c8d8eccSSepherosa Ziehau m->m_flags |= M_VLANTAG; 24586c8d8eccSSepherosa Ziehau m->m_pkthdr.ether_vlantag = vlan_tag; 24596c8d8eccSSepherosa Ziehau } 24606c8d8eccSSepherosa Ziehau ifp->if_input(ifp, m); 24616c8d8eccSSepherosa Ziehau } 24626c8d8eccSSepherosa Ziehau 2463beedf5beSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO, ret->bnx_rx_saved_considx); 24646c8d8eccSSepherosa Ziehau if (stdcnt) 2465beedf5beSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std); 24666c8d8eccSSepherosa Ziehau if (jumbocnt) 24676c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 24686c8d8eccSSepherosa Ziehau } 24696c8d8eccSSepherosa Ziehau 24706c8d8eccSSepherosa Ziehau static void 247133a04907SSepherosa Ziehau bnx_txeof(struct bnx_tx_ring *txr, uint16_t tx_cons) 24726c8d8eccSSepherosa Ziehau { 247333a04907SSepherosa Ziehau struct ifnet *ifp = &txr->bnx_sc->arpcom.ac_if; 24746c8d8eccSSepherosa Ziehau 24756c8d8eccSSepherosa Ziehau /* 24766c8d8eccSSepherosa Ziehau * Go through our tx ring and free mbufs for those 24776c8d8eccSSepherosa Ziehau * frames that have been sent. 24786c8d8eccSSepherosa Ziehau */ 247933a04907SSepherosa Ziehau while (txr->bnx_tx_saved_considx != tx_cons) { 2480fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf; 24816c8d8eccSSepherosa Ziehau uint32_t idx = 0; 24826c8d8eccSSepherosa Ziehau 248333a04907SSepherosa Ziehau idx = txr->bnx_tx_saved_considx; 2484fa4b1067SSepherosa Ziehau buf = &txr->bnx_tx_buf[idx]; 2485fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 2486d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, opackets, 1); 248733a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 2488fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 2489fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 2490fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 24916c8d8eccSSepherosa Ziehau } 2492fa639b88SSepherosa Ziehau txr->bnx_tx_cnt--; 249333a04907SSepherosa Ziehau BNX_INC(txr->bnx_tx_saved_considx, BGE_TX_RING_CNT); 24946c8d8eccSSepherosa Ziehau } 24956c8d8eccSSepherosa Ziehau 2496fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) >= 24976c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) 24989ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 24996c8d8eccSSepherosa Ziehau 2500fa639b88SSepherosa Ziehau if (txr->bnx_tx_cnt == 0) 25016c8d8eccSSepherosa Ziehau ifp->if_timer = 0; 25026c8d8eccSSepherosa Ziehau 25036c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 25046c8d8eccSSepherosa Ziehau if_devstart(ifp); 25056c8d8eccSSepherosa Ziehau } 25066c8d8eccSSepherosa Ziehau 250739a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 25086c8d8eccSSepherosa Ziehau 25096c8d8eccSSepherosa Ziehau static void 251039a8d43aSSepherosa Ziehau bnx_npoll(struct ifnet *ifp, struct ifpoll_info *info) 251139a8d43aSSepherosa Ziehau { 251239a8d43aSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 251339a8d43aSSepherosa Ziehau 251439a8d43aSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 251539a8d43aSSepherosa Ziehau 251639a8d43aSSepherosa Ziehau if (info != NULL) { 2517b5de76b1SSepherosa Ziehau int cpuid = sc->bnx_npoll.ifpc_cpuid; 251839a8d43aSSepherosa Ziehau 251939a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].poll_func = bnx_npoll_compat; 252039a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].arg = NULL; 252139a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].serializer = ifp->if_serializer; 252239a8d43aSSepherosa Ziehau 252339a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 252439a8d43aSSepherosa Ziehau bnx_disable_intr(sc); 2525dfd3b18bSSepherosa Ziehau ifq_set_cpuid(&ifp->if_snd, cpuid); 252639a8d43aSSepherosa Ziehau } else { 252739a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 252839a8d43aSSepherosa Ziehau bnx_enable_intr(sc); 2529dfd3b18bSSepherosa Ziehau ifq_set_cpuid(&ifp->if_snd, sc->bnx_intr_cpuid); 253039a8d43aSSepherosa Ziehau } 253139a8d43aSSepherosa Ziehau } 253239a8d43aSSepherosa Ziehau 253339a8d43aSSepherosa Ziehau static void 253497381780SSepherosa Ziehau bnx_npoll_compat(struct ifnet *ifp, void *arg __unused, int cycle) 25356c8d8eccSSepherosa Ziehau { 25366c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 253733a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 2538beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */ 25396c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 25406c8d8eccSSepherosa Ziehau uint16_t rx_prod, tx_cons; 25416c8d8eccSSepherosa Ziehau 254239a8d43aSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 254339a8d43aSSepherosa Ziehau 2544b5de76b1SSepherosa Ziehau if (sc->bnx_npoll.ifpc_stcount-- == 0) { 2545b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = sc->bnx_npoll.ifpc_stfrac; 25466c8d8eccSSepherosa Ziehau /* 25476c8d8eccSSepherosa Ziehau * Process link state changes. 25486c8d8eccSSepherosa Ziehau */ 25496c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 255039a8d43aSSepherosa Ziehau } 255139a8d43aSSepherosa Ziehau 25526c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 255339a8d43aSSepherosa Ziehau 25546c8d8eccSSepherosa Ziehau /* 255539a8d43aSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 255639a8d43aSSepherosa Ziehau * before rx_prod and tx_cons. 25576c8d8eccSSepherosa Ziehau */ 25586c8d8eccSSepherosa Ziehau cpu_lfence(); 25596c8d8eccSSepherosa Ziehau 2560*3a16b7b8SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 2561*3a16b7b8SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 256239a8d43aSSepherosa Ziehau 2563beedf5beSSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 2564beedf5beSSepherosa Ziehau bnx_rxeof(ret, rx_prod, cycle); 25656c8d8eccSSepherosa Ziehau 256633a04907SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 256733a04907SSepherosa Ziehau bnx_txeof(txr, tx_cons); 25686c8d8eccSSepherosa Ziehau } 25696c8d8eccSSepherosa Ziehau 257039a8d43aSSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 25716c8d8eccSSepherosa Ziehau 25726c8d8eccSSepherosa Ziehau static void 25736c8d8eccSSepherosa Ziehau bnx_intr_legacy(void *xsc) 25746c8d8eccSSepherosa Ziehau { 25756c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 25766c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 25776c8d8eccSSepherosa Ziehau 25786c8d8eccSSepherosa Ziehau if (sc->bnx_status_tag == sblk->bge_status_tag) { 25796c8d8eccSSepherosa Ziehau uint32_t val; 25806c8d8eccSSepherosa Ziehau 25816c8d8eccSSepherosa Ziehau val = pci_read_config(sc->bnx_dev, BGE_PCI_PCISTATE, 4); 25826c8d8eccSSepherosa Ziehau if (val & BGE_PCISTAT_INTR_NOTACT) 25836c8d8eccSSepherosa Ziehau return; 25846c8d8eccSSepherosa Ziehau } 25856c8d8eccSSepherosa Ziehau 25866c8d8eccSSepherosa Ziehau /* 25876c8d8eccSSepherosa Ziehau * NOTE: 25886c8d8eccSSepherosa Ziehau * Interrupt will have to be disabled if tagged status 25896c8d8eccSSepherosa Ziehau * is used, else interrupt will always be asserted on 25906c8d8eccSSepherosa Ziehau * certain chips (at least on BCM5750 AX/BX). 25916c8d8eccSSepherosa Ziehau */ 25926c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 25936c8d8eccSSepherosa Ziehau 25946c8d8eccSSepherosa Ziehau bnx_intr(sc); 25956c8d8eccSSepherosa Ziehau } 25966c8d8eccSSepherosa Ziehau 25976c8d8eccSSepherosa Ziehau static void 25986c8d8eccSSepherosa Ziehau bnx_msi(void *xsc) 25996c8d8eccSSepherosa Ziehau { 26006c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 26016c8d8eccSSepherosa Ziehau 26026c8d8eccSSepherosa Ziehau /* Disable interrupt first */ 26036c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 26046c8d8eccSSepherosa Ziehau bnx_intr(sc); 26056c8d8eccSSepherosa Ziehau } 26066c8d8eccSSepherosa Ziehau 26076c8d8eccSSepherosa Ziehau static void 26086c8d8eccSSepherosa Ziehau bnx_msi_oneshot(void *xsc) 26096c8d8eccSSepherosa Ziehau { 26106c8d8eccSSepherosa Ziehau bnx_intr(xsc); 26116c8d8eccSSepherosa Ziehau } 26126c8d8eccSSepherosa Ziehau 26136c8d8eccSSepherosa Ziehau static void 26146c8d8eccSSepherosa Ziehau bnx_intr(struct bnx_softc *sc) 26156c8d8eccSSepherosa Ziehau { 26166c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 26176c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 26186c8d8eccSSepherosa Ziehau uint32_t status; 26196c8d8eccSSepherosa Ziehau 26206c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 26216c8d8eccSSepherosa Ziehau /* 26226c8d8eccSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 26236c8d8eccSSepherosa Ziehau * before rx_prod, tx_cons and status. 26246c8d8eccSSepherosa Ziehau */ 26256c8d8eccSSepherosa Ziehau cpu_lfence(); 26266c8d8eccSSepherosa Ziehau 26276c8d8eccSSepherosa Ziehau status = sblk->bge_status; 26286c8d8eccSSepherosa Ziehau 26296c8d8eccSSepherosa Ziehau if ((status & BGE_STATFLAG_LINKSTATE_CHANGED) || sc->bnx_link_evt) 26306c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 26316c8d8eccSSepherosa Ziehau 26326c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 263333a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 2634beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */ 2635*3a16b7b8SSepherosa Ziehau uint16_t rx_prod, tx_cons; 2636*3a16b7b8SSepherosa Ziehau 2637*3a16b7b8SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 2638*3a16b7b8SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 263933a04907SSepherosa Ziehau 2640beedf5beSSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 2641beedf5beSSepherosa Ziehau bnx_rxeof(ret, rx_prod, -1); 26426c8d8eccSSepherosa Ziehau 264333a04907SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 264433a04907SSepherosa Ziehau bnx_txeof(txr, tx_cons); 26456c8d8eccSSepherosa Ziehau } 26466c8d8eccSSepherosa Ziehau 26476c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 26486c8d8eccSSepherosa Ziehau } 26496c8d8eccSSepherosa Ziehau 26506c8d8eccSSepherosa Ziehau static void 26516c8d8eccSSepherosa Ziehau bnx_tick(void *xsc) 26526c8d8eccSSepherosa Ziehau { 26536c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 26546c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 26556c8d8eccSSepherosa Ziehau 26566c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 26576c8d8eccSSepherosa Ziehau 26588ca0f604SSepherosa Ziehau KKASSERT(mycpuid == sc->bnx_stat_cpuid); 26598ca0f604SSepherosa Ziehau 26606c8d8eccSSepherosa Ziehau bnx_stats_update_regs(sc); 26616c8d8eccSSepherosa Ziehau 26626c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 26636c8d8eccSSepherosa Ziehau /* 26646c8d8eccSSepherosa Ziehau * Since in TBI mode auto-polling can't be used we should poll 26656c8d8eccSSepherosa Ziehau * link status manually. Here we register pending link event 26666c8d8eccSSepherosa Ziehau * and trigger interrupt. 26676c8d8eccSSepherosa Ziehau */ 26686c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 26696c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 26706c8d8eccSSepherosa Ziehau } else if (!sc->bnx_link) { 26716c8d8eccSSepherosa Ziehau mii_tick(device_get_softc(sc->bnx_miibus)); 26726c8d8eccSSepherosa Ziehau } 26736c8d8eccSSepherosa Ziehau 26746c8d8eccSSepherosa Ziehau callout_reset(&sc->bnx_stat_timer, hz, bnx_tick, sc); 26756c8d8eccSSepherosa Ziehau 26766c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 26776c8d8eccSSepherosa Ziehau } 26786c8d8eccSSepherosa Ziehau 26796c8d8eccSSepherosa Ziehau static void 26806c8d8eccSSepherosa Ziehau bnx_stats_update_regs(struct bnx_softc *sc) 26816c8d8eccSSepherosa Ziehau { 26826c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 26836c8d8eccSSepherosa Ziehau struct bge_mac_stats_regs stats; 26846c8d8eccSSepherosa Ziehau uint32_t *s; 26856c8d8eccSSepherosa Ziehau int i; 26866c8d8eccSSepherosa Ziehau 26876c8d8eccSSepherosa Ziehau s = (uint32_t *)&stats; 26886c8d8eccSSepherosa Ziehau for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) { 26896c8d8eccSSepherosa Ziehau *s = CSR_READ_4(sc, BGE_RX_STATS + i); 26906c8d8eccSSepherosa Ziehau s++; 26916c8d8eccSSepherosa Ziehau } 26926c8d8eccSSepherosa Ziehau 2693d40991efSSepherosa Ziehau IFNET_STAT_SET(ifp, collisions, 26946c8d8eccSSepherosa Ziehau (stats.dot3StatsSingleCollisionFrames + 26956c8d8eccSSepherosa Ziehau stats.dot3StatsMultipleCollisionFrames + 26966c8d8eccSSepherosa Ziehau stats.dot3StatsExcessiveCollisions + 2697d40991efSSepherosa Ziehau stats.dot3StatsLateCollisions)); 26986c8d8eccSSepherosa Ziehau } 26996c8d8eccSSepherosa Ziehau 27006c8d8eccSSepherosa Ziehau /* 27016c8d8eccSSepherosa Ziehau * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data 27026c8d8eccSSepherosa Ziehau * pointers to descriptors. 27036c8d8eccSSepherosa Ziehau */ 27046c8d8eccSSepherosa Ziehau static int 270533a04907SSepherosa Ziehau bnx_encap(struct bnx_tx_ring *txr, struct mbuf **m_head0, uint32_t *txidx, 2706c9b7f592SSepherosa Ziehau int *segs_used) 27076c8d8eccSSepherosa Ziehau { 27086c8d8eccSSepherosa Ziehau struct bge_tx_bd *d = NULL; 270966deb1c1SSepherosa Ziehau uint16_t csum_flags = 0, vlan_tag = 0, mss = 0; 27106c8d8eccSSepherosa Ziehau bus_dma_segment_t segs[BNX_NSEG_NEW]; 27116c8d8eccSSepherosa Ziehau bus_dmamap_t map; 27126c8d8eccSSepherosa Ziehau int error, maxsegs, nsegs, idx, i; 27136c8d8eccSSepherosa Ziehau struct mbuf *m_head = *m_head0, *m_new; 27146c8d8eccSSepherosa Ziehau 271566deb1c1SSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { 271666deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 271766deb1c1SSepherosa Ziehau int tso_nsegs; 271866deb1c1SSepherosa Ziehau #endif 271966deb1c1SSepherosa Ziehau 272033a04907SSepherosa Ziehau error = bnx_setup_tso(txr, m_head0, &mss, &csum_flags); 272166deb1c1SSepherosa Ziehau if (error) 272266deb1c1SSepherosa Ziehau return error; 272366deb1c1SSepherosa Ziehau m_head = *m_head0; 272466deb1c1SSepherosa Ziehau 272566deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 2726f0336d39SSepherosa Ziehau tso_nsegs = (m_head->m_pkthdr.len / 2727f0336d39SSepherosa Ziehau m_head->m_pkthdr.tso_segsz) - 1; 272866deb1c1SSepherosa Ziehau if (tso_nsegs > (BNX_TSO_NSTATS - 1)) 272966deb1c1SSepherosa Ziehau tso_nsegs = BNX_TSO_NSTATS - 1; 273066deb1c1SSepherosa Ziehau else if (tso_nsegs < 0) 273166deb1c1SSepherosa Ziehau tso_nsegs = 0; 27325a0c3c3aSSascha Wildner txr->bnx_sc->bnx_tsosegs[tso_nsegs]++; 273366deb1c1SSepherosa Ziehau #endif 273466deb1c1SSepherosa Ziehau } else if (m_head->m_pkthdr.csum_flags & BNX_CSUM_FEATURES) { 27356c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_IP) 27366c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_CSUM; 27376c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP)) 27386c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_TCP_UDP_CSUM; 27396c8d8eccSSepherosa Ziehau if (m_head->m_flags & M_LASTFRAG) 27406c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG_END; 27416c8d8eccSSepherosa Ziehau else if (m_head->m_flags & M_FRAG) 27426c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG; 27436c8d8eccSSepherosa Ziehau } 274466deb1c1SSepherosa Ziehau if (m_head->m_flags & M_VLANTAG) { 274566deb1c1SSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_VLAN_TAG; 274666deb1c1SSepherosa Ziehau vlan_tag = m_head->m_pkthdr.ether_vlantag; 274766deb1c1SSepherosa Ziehau } 27486c8d8eccSSepherosa Ziehau 27496c8d8eccSSepherosa Ziehau idx = *txidx; 2750fa4b1067SSepherosa Ziehau map = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 27516c8d8eccSSepherosa Ziehau 2752fa639b88SSepherosa Ziehau maxsegs = (BGE_TX_RING_CNT - txr->bnx_tx_cnt) - BNX_NSEG_RSVD; 27536c8d8eccSSepherosa Ziehau KASSERT(maxsegs >= BNX_NSEG_SPARE, 27546c8d8eccSSepherosa Ziehau ("not enough segments %d", maxsegs)); 27556c8d8eccSSepherosa Ziehau 27566c8d8eccSSepherosa Ziehau if (maxsegs > BNX_NSEG_NEW) 27576c8d8eccSSepherosa Ziehau maxsegs = BNX_NSEG_NEW; 27586c8d8eccSSepherosa Ziehau 27596c8d8eccSSepherosa Ziehau /* 27606c8d8eccSSepherosa Ziehau * Pad outbound frame to BGE_MIN_FRAMELEN for an unusual reason. 27616c8d8eccSSepherosa Ziehau * The bge hardware will pad out Tx runts to BGE_MIN_FRAMELEN, 27626c8d8eccSSepherosa Ziehau * but when such padded frames employ the bge IP/TCP checksum 27636c8d8eccSSepherosa Ziehau * offload, the hardware checksum assist gives incorrect results 27646c8d8eccSSepherosa Ziehau * (possibly from incorporating its own padding into the UDP/TCP 27656c8d8eccSSepherosa Ziehau * checksum; who knows). If we pad such runts with zeros, the 27666c8d8eccSSepherosa Ziehau * onboard checksum comes out correct. 27676c8d8eccSSepherosa Ziehau */ 27686c8d8eccSSepherosa Ziehau if ((csum_flags & BGE_TXBDFLAG_TCP_UDP_CSUM) && 27696c8d8eccSSepherosa Ziehau m_head->m_pkthdr.len < BNX_MIN_FRAMELEN) { 27706c8d8eccSSepherosa Ziehau error = m_devpad(m_head, BNX_MIN_FRAMELEN); 27716c8d8eccSSepherosa Ziehau if (error) 27726c8d8eccSSepherosa Ziehau goto back; 27736c8d8eccSSepherosa Ziehau } 27746c8d8eccSSepherosa Ziehau 277579a64343SSepherosa Ziehau if ((txr->bnx_tx_flags & BNX_TX_FLAG_SHORTDMA) && 277633a04907SSepherosa Ziehau m_head->m_next != NULL) { 27776c8d8eccSSepherosa Ziehau m_new = bnx_defrag_shortdma(m_head); 27786c8d8eccSSepherosa Ziehau if (m_new == NULL) { 27796c8d8eccSSepherosa Ziehau error = ENOBUFS; 27806c8d8eccSSepherosa Ziehau goto back; 27816c8d8eccSSepherosa Ziehau } 27826c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 27836c8d8eccSSepherosa Ziehau } 278466deb1c1SSepherosa Ziehau if ((m_head->m_pkthdr.csum_flags & CSUM_TSO) == 0 && 2785aad4de2bSSepherosa Ziehau (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) && 2786aad4de2bSSepherosa Ziehau m_head->m_next != NULL) { 27876c8d8eccSSepherosa Ziehau /* 27886c8d8eccSSepherosa Ziehau * Forcefully defragment mbuf chain to overcome hardware 27896c8d8eccSSepherosa Ziehau * limitation which only support a single outstanding 27906c8d8eccSSepherosa Ziehau * DMA read operation. If it fails, keep moving on using 27916c8d8eccSSepherosa Ziehau * the original mbuf chain. 27926c8d8eccSSepherosa Ziehau */ 27936c8d8eccSSepherosa Ziehau m_new = m_defrag(m_head, MB_DONTWAIT); 27946c8d8eccSSepherosa Ziehau if (m_new != NULL) 27956c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 27966c8d8eccSSepherosa Ziehau } 27976c8d8eccSSepherosa Ziehau 279833a04907SSepherosa Ziehau error = bus_dmamap_load_mbuf_defrag(txr->bnx_tx_mtag, map, 27996c8d8eccSSepherosa Ziehau m_head0, segs, maxsegs, &nsegs, BUS_DMA_NOWAIT); 28006c8d8eccSSepherosa Ziehau if (error) 28016c8d8eccSSepherosa Ziehau goto back; 2802c9b7f592SSepherosa Ziehau *segs_used += nsegs; 28036c8d8eccSSepherosa Ziehau 28046c8d8eccSSepherosa Ziehau m_head = *m_head0; 280533a04907SSepherosa Ziehau bus_dmamap_sync(txr->bnx_tx_mtag, map, BUS_DMASYNC_PREWRITE); 28066c8d8eccSSepherosa Ziehau 28076c8d8eccSSepherosa Ziehau for (i = 0; ; i++) { 280833a04907SSepherosa Ziehau d = &txr->bnx_tx_ring[idx]; 28096c8d8eccSSepherosa Ziehau 28106c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_lo = BGE_ADDR_LO(segs[i].ds_addr); 28116c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_hi = BGE_ADDR_HI(segs[i].ds_addr); 28126c8d8eccSSepherosa Ziehau d->bge_len = segs[i].ds_len; 28136c8d8eccSSepherosa Ziehau d->bge_flags = csum_flags; 281466deb1c1SSepherosa Ziehau d->bge_vlan_tag = vlan_tag; 281566deb1c1SSepherosa Ziehau d->bge_mss = mss; 28166c8d8eccSSepherosa Ziehau 28176c8d8eccSSepherosa Ziehau if (i == nsegs - 1) 28186c8d8eccSSepherosa Ziehau break; 28196c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 28206c8d8eccSSepherosa Ziehau } 28216c8d8eccSSepherosa Ziehau /* Mark the last segment as end of packet... */ 28226c8d8eccSSepherosa Ziehau d->bge_flags |= BGE_TXBDFLAG_END; 28236c8d8eccSSepherosa Ziehau 28246c8d8eccSSepherosa Ziehau /* 28256c8d8eccSSepherosa Ziehau * Insure that the map for this transmission is placed at 28266c8d8eccSSepherosa Ziehau * the array index of the last descriptor in this chain. 28276c8d8eccSSepherosa Ziehau */ 2828fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[*txidx].bnx_tx_dmamap = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 2829fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_dmamap = map; 2830fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_mbuf = m_head; 2831fa639b88SSepherosa Ziehau txr->bnx_tx_cnt += nsegs; 28326c8d8eccSSepherosa Ziehau 28336c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 28346c8d8eccSSepherosa Ziehau *txidx = idx; 28356c8d8eccSSepherosa Ziehau back: 28366c8d8eccSSepherosa Ziehau if (error) { 28376c8d8eccSSepherosa Ziehau m_freem(*m_head0); 28386c8d8eccSSepherosa Ziehau *m_head0 = NULL; 28396c8d8eccSSepherosa Ziehau } 28406c8d8eccSSepherosa Ziehau return error; 28416c8d8eccSSepherosa Ziehau } 28426c8d8eccSSepherosa Ziehau 28436c8d8eccSSepherosa Ziehau /* 28446c8d8eccSSepherosa Ziehau * Main transmit routine. To avoid having to do mbuf copies, we put pointers 28456c8d8eccSSepherosa Ziehau * to the mbuf data regions directly in the transmit descriptors. 28466c8d8eccSSepherosa Ziehau */ 28476c8d8eccSSepherosa Ziehau static void 2848f0a26983SSepherosa Ziehau bnx_start(struct ifnet *ifp, struct ifaltq_subque *ifsq) 28496c8d8eccSSepherosa Ziehau { 28506c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 285133a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 28526c8d8eccSSepherosa Ziehau struct mbuf *m_head = NULL; 28536c8d8eccSSepherosa Ziehau uint32_t prodidx; 2854c9b7f592SSepherosa Ziehau int nsegs = 0; 28556c8d8eccSSepherosa Ziehau 2856f0a26983SSepherosa Ziehau ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq); 2857f0a26983SSepherosa Ziehau 28589ed293e0SSepherosa Ziehau if ((ifp->if_flags & IFF_RUNNING) == 0 || ifq_is_oactive(&ifp->if_snd)) 28596c8d8eccSSepherosa Ziehau return; 28606c8d8eccSSepherosa Ziehau 286133a04907SSepherosa Ziehau prodidx = txr->bnx_tx_prodidx; 28626c8d8eccSSepherosa Ziehau 2863fa4b1067SSepherosa Ziehau while (txr->bnx_tx_buf[prodidx].bnx_tx_mbuf == NULL) { 28646c8d8eccSSepherosa Ziehau /* 28656c8d8eccSSepherosa Ziehau * Sanity check: avoid coming within BGE_NSEG_RSVD 28666c8d8eccSSepherosa Ziehau * descriptors of the end of the ring. Also make 28676c8d8eccSSepherosa Ziehau * sure there are BGE_NSEG_SPARE descriptors for 2868a1bd58c9SSepherosa Ziehau * jumbo buffers' or TSO segments' defragmentation. 28696c8d8eccSSepherosa Ziehau */ 2870fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) < 28716c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) { 28729ed293e0SSepherosa Ziehau ifq_set_oactive(&ifp->if_snd); 28736c8d8eccSSepherosa Ziehau break; 28746c8d8eccSSepherosa Ziehau } 28756c8d8eccSSepherosa Ziehau 2876a1bd58c9SSepherosa Ziehau m_head = ifq_dequeue(&ifp->if_snd, NULL); 2877a1bd58c9SSepherosa Ziehau if (m_head == NULL) 2878a1bd58c9SSepherosa Ziehau break; 2879a1bd58c9SSepherosa Ziehau 28806c8d8eccSSepherosa Ziehau /* 28816c8d8eccSSepherosa Ziehau * Pack the data into the transmit ring. If we 28826c8d8eccSSepherosa Ziehau * don't have room, set the OACTIVE flag and wait 28836c8d8eccSSepherosa Ziehau * for the NIC to drain the ring. 28846c8d8eccSSepherosa Ziehau */ 288533a04907SSepherosa Ziehau if (bnx_encap(txr, &m_head, &prodidx, &nsegs)) { 28869ed293e0SSepherosa Ziehau ifq_set_oactive(&ifp->if_snd); 2887d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 28886c8d8eccSSepherosa Ziehau break; 28896c8d8eccSSepherosa Ziehau } 28906c8d8eccSSepherosa Ziehau 289133a04907SSepherosa Ziehau if (nsegs >= txr->bnx_tx_wreg) { 28926c8d8eccSSepherosa Ziehau /* Transmit */ 28938bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 2894c9b7f592SSepherosa Ziehau nsegs = 0; 2895c9b7f592SSepherosa Ziehau } 28966c8d8eccSSepherosa Ziehau 2897c9b7f592SSepherosa Ziehau ETHER_BPF_MTAP(ifp, m_head); 28986c8d8eccSSepherosa Ziehau 28996c8d8eccSSepherosa Ziehau /* 29006c8d8eccSSepherosa Ziehau * Set a timeout in case the chip goes out to lunch. 29016c8d8eccSSepherosa Ziehau */ 29026c8d8eccSSepherosa Ziehau ifp->if_timer = 5; 29036c8d8eccSSepherosa Ziehau } 29046c8d8eccSSepherosa Ziehau 2905c9b7f592SSepherosa Ziehau if (nsegs > 0) { 2906c9b7f592SSepherosa Ziehau /* Transmit */ 29078bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 2908c9b7f592SSepherosa Ziehau } 290933a04907SSepherosa Ziehau txr->bnx_tx_prodidx = prodidx; 2910c9b7f592SSepherosa Ziehau } 2911c9b7f592SSepherosa Ziehau 29126c8d8eccSSepherosa Ziehau static void 29136c8d8eccSSepherosa Ziehau bnx_init(void *xsc) 29146c8d8eccSSepherosa Ziehau { 29156c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 29166c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 29176c8d8eccSSepherosa Ziehau uint16_t *m; 29186c8d8eccSSepherosa Ziehau uint32_t mode; 291933a04907SSepherosa Ziehau int i; 29206c8d8eccSSepherosa Ziehau 29216c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 29226c8d8eccSSepherosa Ziehau 29236c8d8eccSSepherosa Ziehau /* Cancel pending I/O and flush buffers. */ 29246c8d8eccSSepherosa Ziehau bnx_stop(sc); 29256c8d8eccSSepherosa Ziehau bnx_reset(sc); 29266c8d8eccSSepherosa Ziehau bnx_chipinit(sc); 29276c8d8eccSSepherosa Ziehau 29286c8d8eccSSepherosa Ziehau /* 29296c8d8eccSSepherosa Ziehau * Init the various state machines, ring 29306c8d8eccSSepherosa Ziehau * control blocks and firmware. 29316c8d8eccSSepherosa Ziehau */ 29326c8d8eccSSepherosa Ziehau if (bnx_blockinit(sc)) { 29336c8d8eccSSepherosa Ziehau if_printf(ifp, "initialization failure\n"); 29346c8d8eccSSepherosa Ziehau bnx_stop(sc); 29356c8d8eccSSepherosa Ziehau return; 29366c8d8eccSSepherosa Ziehau } 29376c8d8eccSSepherosa Ziehau 29386c8d8eccSSepherosa Ziehau /* Specify MTU. */ 29396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu + 29406c8d8eccSSepherosa Ziehau ETHER_HDR_LEN + ETHER_CRC_LEN + EVL_ENCAPLEN); 29416c8d8eccSSepherosa Ziehau 29426c8d8eccSSepherosa Ziehau /* Load our MAC address. */ 29436c8d8eccSSepherosa Ziehau m = (uint16_t *)&sc->arpcom.ac_enaddr[0]; 29446c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_LO, htons(m[0])); 29456c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_HI, (htons(m[1]) << 16) | htons(m[2])); 29466c8d8eccSSepherosa Ziehau 29476c8d8eccSSepherosa Ziehau /* Enable or disable promiscuous mode as needed. */ 29486c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 29496c8d8eccSSepherosa Ziehau 29506c8d8eccSSepherosa Ziehau /* Program multicast filter. */ 29516c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 29526c8d8eccSSepherosa Ziehau 29536c8d8eccSSepherosa Ziehau /* Init RX ring. */ 2954beedf5beSSepherosa Ziehau if (bnx_init_rx_ring_std(&sc->bnx_rx_std_ring)) { 29556c8d8eccSSepherosa Ziehau if_printf(ifp, "RX ring initialization failed\n"); 29566c8d8eccSSepherosa Ziehau bnx_stop(sc); 29576c8d8eccSSepherosa Ziehau return; 29586c8d8eccSSepherosa Ziehau } 29596c8d8eccSSepherosa Ziehau 29606c8d8eccSSepherosa Ziehau /* Init jumbo RX ring. */ 29616c8d8eccSSepherosa Ziehau if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) { 29626c8d8eccSSepherosa Ziehau if (bnx_init_rx_ring_jumbo(sc)) { 29636c8d8eccSSepherosa Ziehau if_printf(ifp, "Jumbo RX ring initialization failed\n"); 29646c8d8eccSSepherosa Ziehau bnx_stop(sc); 29656c8d8eccSSepherosa Ziehau return; 29666c8d8eccSSepherosa Ziehau } 29676c8d8eccSSepherosa Ziehau } 29686c8d8eccSSepherosa Ziehau 29696c8d8eccSSepherosa Ziehau /* Init our RX return ring index */ 2970beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 2971beedf5beSSepherosa Ziehau sc->bnx_rx_ret_ring[i].bnx_rx_saved_considx = 0; 29726c8d8eccSSepherosa Ziehau 29736c8d8eccSSepherosa Ziehau /* Init TX ring. */ 297433a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 297533a04907SSepherosa Ziehau bnx_init_tx_ring(&sc->bnx_tx_ring[i]); 29766c8d8eccSSepherosa Ziehau 29776c8d8eccSSepherosa Ziehau /* Enable TX MAC state machine lockup fix. */ 29786c8d8eccSSepherosa Ziehau mode = CSR_READ_4(sc, BGE_TX_MODE); 29796c8d8eccSSepherosa Ziehau mode |= BGE_TXMODE_MBUF_LOCKUP_FIX; 2980b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 2981b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 29826c8d8eccSSepherosa Ziehau mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 29836c8d8eccSSepherosa Ziehau mode |= CSR_READ_4(sc, BGE_TX_MODE) & 29846c8d8eccSSepherosa Ziehau (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 29856c8d8eccSSepherosa Ziehau } 29866c8d8eccSSepherosa Ziehau /* Turn on transmitter */ 29876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE); 29886c8d8eccSSepherosa Ziehau 29896c8d8eccSSepherosa Ziehau /* Turn on receiver */ 29906c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 29916c8d8eccSSepherosa Ziehau 29926c8d8eccSSepherosa Ziehau /* 29936c8d8eccSSepherosa Ziehau * Set the number of good frames to receive after RX MBUF 29946c8d8eccSSepherosa Ziehau * Low Watermark has been reached. After the RX MAC receives 29956c8d8eccSSepherosa Ziehau * this number of frames, it will drop subsequent incoming 29966c8d8eccSSepherosa Ziehau * frames until the MBUF High Watermark is reached. 29976c8d8eccSSepherosa Ziehau */ 2998bcb29629SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) 29996c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 1); 30006c8d8eccSSepherosa Ziehau else 30016c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2); 30026c8d8eccSSepherosa Ziehau 30036c8d8eccSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 30046c8d8eccSSepherosa Ziehau if (bootverbose) { 30056c8d8eccSSepherosa Ziehau if_printf(ifp, "MSI_MODE: %#x\n", 30066c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MSI_MODE)); 30076c8d8eccSSepherosa Ziehau } 30086c8d8eccSSepherosa Ziehau } 30096c8d8eccSSepherosa Ziehau 30106c8d8eccSSepherosa Ziehau /* Tell firmware we're alive. */ 30116c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 30126c8d8eccSSepherosa Ziehau 30136c8d8eccSSepherosa Ziehau /* Enable host interrupts if polling(4) is not enabled. */ 30146c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA, 4); 301539a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 301639a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_NPOLLING) 30176c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 30186c8d8eccSSepherosa Ziehau else 30196c8d8eccSSepherosa Ziehau #endif 30206c8d8eccSSepherosa Ziehau bnx_enable_intr(sc); 30216c8d8eccSSepherosa Ziehau 30226c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(ifp); 30236c8d8eccSSepherosa Ziehau 30246c8d8eccSSepherosa Ziehau ifp->if_flags |= IFF_RUNNING; 30259ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 30266c8d8eccSSepherosa Ziehau 30278ca0f604SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_stat_timer, hz, bnx_tick, sc, 30288ca0f604SSepherosa Ziehau sc->bnx_stat_cpuid); 30296c8d8eccSSepherosa Ziehau } 30306c8d8eccSSepherosa Ziehau 30316c8d8eccSSepherosa Ziehau /* 30326c8d8eccSSepherosa Ziehau * Set media options. 30336c8d8eccSSepherosa Ziehau */ 30346c8d8eccSSepherosa Ziehau static int 30356c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(struct ifnet *ifp) 30366c8d8eccSSepherosa Ziehau { 30376c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 30386c8d8eccSSepherosa Ziehau 30396c8d8eccSSepherosa Ziehau /* If this is a 1000baseX NIC, enable the TBI port. */ 30406c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 30416c8d8eccSSepherosa Ziehau struct ifmedia *ifm = &sc->bnx_ifmedia; 30426c8d8eccSSepherosa Ziehau 30436c8d8eccSSepherosa Ziehau if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 30446c8d8eccSSepherosa Ziehau return(EINVAL); 30456c8d8eccSSepherosa Ziehau 30466c8d8eccSSepherosa Ziehau switch(IFM_SUBTYPE(ifm->ifm_media)) { 30476c8d8eccSSepherosa Ziehau case IFM_AUTO: 30486c8d8eccSSepherosa Ziehau break; 30496c8d8eccSSepherosa Ziehau 30506c8d8eccSSepherosa Ziehau case IFM_1000_SX: 30516c8d8eccSSepherosa Ziehau if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 30526c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 30536c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 30546c8d8eccSSepherosa Ziehau } else { 30556c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, 30566c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 30576c8d8eccSSepherosa Ziehau } 30586c8d8eccSSepherosa Ziehau break; 30596c8d8eccSSepherosa Ziehau default: 30606c8d8eccSSepherosa Ziehau return(EINVAL); 30616c8d8eccSSepherosa Ziehau } 30626c8d8eccSSepherosa Ziehau } else { 30636c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 30646c8d8eccSSepherosa Ziehau 30656c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 30666c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 30676c8d8eccSSepherosa Ziehau if (mii->mii_instance) { 30686c8d8eccSSepherosa Ziehau struct mii_softc *miisc; 30696c8d8eccSSepherosa Ziehau 30706c8d8eccSSepherosa Ziehau LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 30716c8d8eccSSepherosa Ziehau mii_phy_reset(miisc); 30726c8d8eccSSepherosa Ziehau } 30736c8d8eccSSepherosa Ziehau mii_mediachg(mii); 30746c8d8eccSSepherosa Ziehau 30756c8d8eccSSepherosa Ziehau /* 30766c8d8eccSSepherosa Ziehau * Force an interrupt so that we will call bnx_link_upd 30776c8d8eccSSepherosa Ziehau * if needed and clear any pending link state attention. 30786c8d8eccSSepherosa Ziehau * Without this we are not getting any further interrupts 30796c8d8eccSSepherosa Ziehau * for link state changes and thus will not UP the link and 30806c8d8eccSSepherosa Ziehau * not be able to send in bnx_start. The only way to get 30816c8d8eccSSepherosa Ziehau * things working was to receive a packet and get an RX 30826c8d8eccSSepherosa Ziehau * intr. 30836c8d8eccSSepherosa Ziehau * 30846c8d8eccSSepherosa Ziehau * bnx_tick should help for fiber cards and we might not 30856c8d8eccSSepherosa Ziehau * need to do this here if BNX_FLAG_TBI is set but as 30866c8d8eccSSepherosa Ziehau * we poll for fiber anyway it should not harm. 30876c8d8eccSSepherosa Ziehau */ 30886c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 30896c8d8eccSSepherosa Ziehau } 30906c8d8eccSSepherosa Ziehau return(0); 30916c8d8eccSSepherosa Ziehau } 30926c8d8eccSSepherosa Ziehau 30936c8d8eccSSepherosa Ziehau /* 30946c8d8eccSSepherosa Ziehau * Report current media status. 30956c8d8eccSSepherosa Ziehau */ 30966c8d8eccSSepherosa Ziehau static void 30976c8d8eccSSepherosa Ziehau bnx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 30986c8d8eccSSepherosa Ziehau { 30996c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 31006c8d8eccSSepherosa Ziehau 31016c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 31026c8d8eccSSepherosa Ziehau ifmr->ifm_status = IFM_AVALID; 31036c8d8eccSSepherosa Ziehau ifmr->ifm_active = IFM_ETHER; 31046c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_STS) & 31056c8d8eccSSepherosa Ziehau BGE_MACSTAT_TBI_PCS_SYNCHED) { 31066c8d8eccSSepherosa Ziehau ifmr->ifm_status |= IFM_ACTIVE; 31076c8d8eccSSepherosa Ziehau } else { 31086c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_NONE; 31096c8d8eccSSepherosa Ziehau return; 31106c8d8eccSSepherosa Ziehau } 31116c8d8eccSSepherosa Ziehau 31126c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_1000_SX; 31136c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_MODE) & BGE_MACMODE_HALF_DUPLEX) 31146c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_HDX; 31156c8d8eccSSepherosa Ziehau else 31166c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_FDX; 31176c8d8eccSSepherosa Ziehau } else { 31186c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 31196c8d8eccSSepherosa Ziehau 31206c8d8eccSSepherosa Ziehau mii_pollstat(mii); 31216c8d8eccSSepherosa Ziehau ifmr->ifm_active = mii->mii_media_active; 31226c8d8eccSSepherosa Ziehau ifmr->ifm_status = mii->mii_media_status; 31236c8d8eccSSepherosa Ziehau } 31246c8d8eccSSepherosa Ziehau } 31256c8d8eccSSepherosa Ziehau 31266c8d8eccSSepherosa Ziehau static int 31276c8d8eccSSepherosa Ziehau bnx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) 31286c8d8eccSSepherosa Ziehau { 31296c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 31306c8d8eccSSepherosa Ziehau struct ifreq *ifr = (struct ifreq *)data; 31316c8d8eccSSepherosa Ziehau int mask, error = 0; 31326c8d8eccSSepherosa Ziehau 31336c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 31346c8d8eccSSepherosa Ziehau 31356c8d8eccSSepherosa Ziehau switch (command) { 31366c8d8eccSSepherosa Ziehau case SIOCSIFMTU: 31376c8d8eccSSepherosa Ziehau if ((!BNX_IS_JUMBO_CAPABLE(sc) && ifr->ifr_mtu > ETHERMTU) || 31386c8d8eccSSepherosa Ziehau (BNX_IS_JUMBO_CAPABLE(sc) && 31396c8d8eccSSepherosa Ziehau ifr->ifr_mtu > BNX_JUMBO_MTU)) { 31406c8d8eccSSepherosa Ziehau error = EINVAL; 31416c8d8eccSSepherosa Ziehau } else if (ifp->if_mtu != ifr->ifr_mtu) { 31426c8d8eccSSepherosa Ziehau ifp->if_mtu = ifr->ifr_mtu; 31436c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 31446c8d8eccSSepherosa Ziehau bnx_init(sc); 31456c8d8eccSSepherosa Ziehau } 31466c8d8eccSSepherosa Ziehau break; 31476c8d8eccSSepherosa Ziehau case SIOCSIFFLAGS: 31486c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 31496c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 31506c8d8eccSSepherosa Ziehau mask = ifp->if_flags ^ sc->bnx_if_flags; 31516c8d8eccSSepherosa Ziehau 31526c8d8eccSSepherosa Ziehau /* 31536c8d8eccSSepherosa Ziehau * If only the state of the PROMISC flag 31546c8d8eccSSepherosa Ziehau * changed, then just use the 'set promisc 31556c8d8eccSSepherosa Ziehau * mode' command instead of reinitializing 31566c8d8eccSSepherosa Ziehau * the entire NIC. Doing a full re-init 31576c8d8eccSSepherosa Ziehau * means reloading the firmware and waiting 31586c8d8eccSSepherosa Ziehau * for it to start up, which may take a 31596c8d8eccSSepherosa Ziehau * second or two. Similarly for ALLMULTI. 31606c8d8eccSSepherosa Ziehau */ 31616c8d8eccSSepherosa Ziehau if (mask & IFF_PROMISC) 31626c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 31636c8d8eccSSepherosa Ziehau if (mask & IFF_ALLMULTI) 31646c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 31656c8d8eccSSepherosa Ziehau } else { 31666c8d8eccSSepherosa Ziehau bnx_init(sc); 31676c8d8eccSSepherosa Ziehau } 31686c8d8eccSSepherosa Ziehau } else if (ifp->if_flags & IFF_RUNNING) { 31696c8d8eccSSepherosa Ziehau bnx_stop(sc); 31706c8d8eccSSepherosa Ziehau } 31716c8d8eccSSepherosa Ziehau sc->bnx_if_flags = ifp->if_flags; 31726c8d8eccSSepherosa Ziehau break; 31736c8d8eccSSepherosa Ziehau case SIOCADDMULTI: 31746c8d8eccSSepherosa Ziehau case SIOCDELMULTI: 31756c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 31766c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 31776c8d8eccSSepherosa Ziehau break; 31786c8d8eccSSepherosa Ziehau case SIOCSIFMEDIA: 31796c8d8eccSSepherosa Ziehau case SIOCGIFMEDIA: 31806c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 31816c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 31826c8d8eccSSepherosa Ziehau &sc->bnx_ifmedia, command); 31836c8d8eccSSepherosa Ziehau } else { 31846c8d8eccSSepherosa Ziehau struct mii_data *mii; 31856c8d8eccSSepherosa Ziehau 31866c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 31876c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 31886c8d8eccSSepherosa Ziehau &mii->mii_media, command); 31896c8d8eccSSepherosa Ziehau } 31906c8d8eccSSepherosa Ziehau break; 31916c8d8eccSSepherosa Ziehau case SIOCSIFCAP: 31926c8d8eccSSepherosa Ziehau mask = ifr->ifr_reqcap ^ ifp->if_capenable; 31936c8d8eccSSepherosa Ziehau if (mask & IFCAP_HWCSUM) { 31946c8d8eccSSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_HWCSUM); 319566deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TXCSUM) 319666deb1c1SSepherosa Ziehau ifp->if_hwassist |= BNX_CSUM_FEATURES; 31976c8d8eccSSepherosa Ziehau else 319866deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~BNX_CSUM_FEATURES; 319966deb1c1SSepherosa Ziehau } 320066deb1c1SSepherosa Ziehau if (mask & IFCAP_TSO) { 320166deb1c1SSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_TSO); 320266deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TSO) 320366deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 320466deb1c1SSepherosa Ziehau else 320566deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~CSUM_TSO; 32066c8d8eccSSepherosa Ziehau } 32076c8d8eccSSepherosa Ziehau break; 32086c8d8eccSSepherosa Ziehau default: 32096c8d8eccSSepherosa Ziehau error = ether_ioctl(ifp, command, data); 32106c8d8eccSSepherosa Ziehau break; 32116c8d8eccSSepherosa Ziehau } 32126c8d8eccSSepherosa Ziehau return error; 32136c8d8eccSSepherosa Ziehau } 32146c8d8eccSSepherosa Ziehau 32156c8d8eccSSepherosa Ziehau static void 32166c8d8eccSSepherosa Ziehau bnx_watchdog(struct ifnet *ifp) 32176c8d8eccSSepherosa Ziehau { 32186c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 32196c8d8eccSSepherosa Ziehau 32206c8d8eccSSepherosa Ziehau if_printf(ifp, "watchdog timeout -- resetting\n"); 32216c8d8eccSSepherosa Ziehau 32226c8d8eccSSepherosa Ziehau bnx_init(sc); 32236c8d8eccSSepherosa Ziehau 3224d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 32256c8d8eccSSepherosa Ziehau 32266c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 32276c8d8eccSSepherosa Ziehau if_devstart(ifp); 32286c8d8eccSSepherosa Ziehau } 32296c8d8eccSSepherosa Ziehau 32306c8d8eccSSepherosa Ziehau /* 32316c8d8eccSSepherosa Ziehau * Stop the adapter and free any mbufs allocated to the 32326c8d8eccSSepherosa Ziehau * RX and TX lists. 32336c8d8eccSSepherosa Ziehau */ 32346c8d8eccSSepherosa Ziehau static void 32356c8d8eccSSepherosa Ziehau bnx_stop(struct bnx_softc *sc) 32366c8d8eccSSepherosa Ziehau { 32376c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 323833a04907SSepherosa Ziehau int i; 32396c8d8eccSSepherosa Ziehau 32406c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 32416c8d8eccSSepherosa Ziehau 32426c8d8eccSSepherosa Ziehau callout_stop(&sc->bnx_stat_timer); 32436c8d8eccSSepherosa Ziehau 32446c8d8eccSSepherosa Ziehau /* 32456c8d8eccSSepherosa Ziehau * Disable all of the receiver blocks 32466c8d8eccSSepherosa Ziehau */ 32476c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 32486c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 32496c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 32506c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDBDI_MODE, BGE_RBDIMODE_ENABLE); 32516c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 32526c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDC_MODE, BGE_RBDCMODE_ENABLE); 32536c8d8eccSSepherosa Ziehau 32546c8d8eccSSepherosa Ziehau /* 32556c8d8eccSSepherosa Ziehau * Disable all of the transmit blocks 32566c8d8eccSSepherosa Ziehau */ 32576c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 32586c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 32596c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 32606c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDMA_MODE, BGE_RDMAMODE_ENABLE); 32616c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDC_MODE, BGE_SDCMODE_ENABLE); 32626c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 32636c8d8eccSSepherosa Ziehau 32646c8d8eccSSepherosa Ziehau /* 32656c8d8eccSSepherosa Ziehau * Shut down all of the memory managers and related 32666c8d8eccSSepherosa Ziehau * state machines. 32676c8d8eccSSepherosa Ziehau */ 32686c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE); 32696c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_WDMA_MODE, BGE_WDMAMODE_ENABLE); 32706c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 32716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 32726c8d8eccSSepherosa Ziehau 32736c8d8eccSSepherosa Ziehau /* Disable host interrupts. */ 32746c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 32756c8d8eccSSepherosa Ziehau 32766c8d8eccSSepherosa Ziehau /* 32776c8d8eccSSepherosa Ziehau * Tell firmware we're shutting down. 32786c8d8eccSSepherosa Ziehau */ 32796c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 32806c8d8eccSSepherosa Ziehau 32816c8d8eccSSepherosa Ziehau /* Free the RX lists. */ 3282beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(&sc->bnx_rx_std_ring); 32836c8d8eccSSepherosa Ziehau 32846c8d8eccSSepherosa Ziehau /* Free jumbo RX list. */ 32856c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 32866c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(sc); 32876c8d8eccSSepherosa Ziehau 32886c8d8eccSSepherosa Ziehau /* Free TX buffers. */ 328933a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 329033a04907SSepherosa Ziehau bnx_free_tx_ring(&sc->bnx_tx_ring[i]); 32916c8d8eccSSepherosa Ziehau 32926c8d8eccSSepherosa Ziehau sc->bnx_status_tag = 0; 32936c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 32946c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 32956c8d8eccSSepherosa Ziehau 32969ed293e0SSepherosa Ziehau ifp->if_flags &= ~IFF_RUNNING; 32979ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 32986c8d8eccSSepherosa Ziehau ifp->if_timer = 0; 32996c8d8eccSSepherosa Ziehau } 33006c8d8eccSSepherosa Ziehau 33016c8d8eccSSepherosa Ziehau /* 33026c8d8eccSSepherosa Ziehau * Stop all chip I/O so that the kernel's probe routines don't 33036c8d8eccSSepherosa Ziehau * get confused by errant DMAs when rebooting. 33046c8d8eccSSepherosa Ziehau */ 33056c8d8eccSSepherosa Ziehau static void 33066c8d8eccSSepherosa Ziehau bnx_shutdown(device_t dev) 33076c8d8eccSSepherosa Ziehau { 33086c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33096c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33106c8d8eccSSepherosa Ziehau 33116c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 33126c8d8eccSSepherosa Ziehau bnx_stop(sc); 33136c8d8eccSSepherosa Ziehau bnx_reset(sc); 33146c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 33156c8d8eccSSepherosa Ziehau } 33166c8d8eccSSepherosa Ziehau 33176c8d8eccSSepherosa Ziehau static int 33186c8d8eccSSepherosa Ziehau bnx_suspend(device_t dev) 33196c8d8eccSSepherosa Ziehau { 33206c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33216c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33226c8d8eccSSepherosa Ziehau 33236c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 33246c8d8eccSSepherosa Ziehau bnx_stop(sc); 33256c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 33266c8d8eccSSepherosa Ziehau 33276c8d8eccSSepherosa Ziehau return 0; 33286c8d8eccSSepherosa Ziehau } 33296c8d8eccSSepherosa Ziehau 33306c8d8eccSSepherosa Ziehau static int 33316c8d8eccSSepherosa Ziehau bnx_resume(device_t dev) 33326c8d8eccSSepherosa Ziehau { 33336c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33346c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33356c8d8eccSSepherosa Ziehau 33366c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 33376c8d8eccSSepherosa Ziehau 33386c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 33396c8d8eccSSepherosa Ziehau bnx_init(sc); 33406c8d8eccSSepherosa Ziehau 33416c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 33426c8d8eccSSepherosa Ziehau if_devstart(ifp); 33436c8d8eccSSepherosa Ziehau } 33446c8d8eccSSepherosa Ziehau 33456c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 33466c8d8eccSSepherosa Ziehau 33476c8d8eccSSepherosa Ziehau return 0; 33486c8d8eccSSepherosa Ziehau } 33496c8d8eccSSepherosa Ziehau 33506c8d8eccSSepherosa Ziehau static void 33516c8d8eccSSepherosa Ziehau bnx_setpromisc(struct bnx_softc *sc) 33526c8d8eccSSepherosa Ziehau { 33536c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33546c8d8eccSSepherosa Ziehau 33556c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_PROMISC) 33566c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 33576c8d8eccSSepherosa Ziehau else 33586c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 33596c8d8eccSSepherosa Ziehau } 33606c8d8eccSSepherosa Ziehau 33616c8d8eccSSepherosa Ziehau static void 33626c8d8eccSSepherosa Ziehau bnx_dma_free(struct bnx_softc *sc) 33636c8d8eccSSepherosa Ziehau { 3364beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 33656c8d8eccSSepherosa Ziehau int i; 33666c8d8eccSSepherosa Ziehau 3367beedf5beSSepherosa Ziehau /* Destroy RX return rings */ 3368beedf5beSSepherosa Ziehau if (sc->bnx_rx_ret_ring != NULL) { 3369beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 3370beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(&sc->bnx_rx_ret_ring[i]); 3371beedf5beSSepherosa Ziehau kfree(sc->bnx_rx_ret_ring, M_DEVBUF); 3372beedf5beSSepherosa Ziehau } 3373beedf5beSSepherosa Ziehau 33746c8d8eccSSepherosa Ziehau /* Destroy RX mbuf DMA stuffs. */ 3375beedf5beSSepherosa Ziehau if (std->bnx_rx_mtag != NULL) { 33766c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 3377beedf5beSSepherosa Ziehau KKASSERT(std->bnx_rx_std_buf[i].bnx_rx_mbuf == NULL); 3378beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3379beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[i].bnx_rx_dmamap); 33806c8d8eccSSepherosa Ziehau } 3381beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 33826c8d8eccSSepherosa Ziehau } 33836c8d8eccSSepherosa Ziehau 3384beedf5beSSepherosa Ziehau /* Destroy standard RX ring */ 3385beedf5beSSepherosa Ziehau bnx_dma_block_free(std->bnx_rx_std_ring_tag, 3386beedf5beSSepherosa Ziehau std->bnx_rx_std_ring_map, std->bnx_rx_std_ring); 3387beedf5beSSepherosa Ziehau 338833a04907SSepherosa Ziehau /* Destroy TX rings */ 338933a04907SSepherosa Ziehau if (sc->bnx_tx_ring != NULL) { 339033a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 339133a04907SSepherosa Ziehau bnx_destroy_tx_ring(&sc->bnx_tx_ring[i]); 339233a04907SSepherosa Ziehau kfree(sc->bnx_tx_ring, M_DEVBUF); 33936c8d8eccSSepherosa Ziehau } 33946c8d8eccSSepherosa Ziehau 33956c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 33966c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(sc); 33976c8d8eccSSepherosa Ziehau 33986c8d8eccSSepherosa Ziehau /* Destroy status block */ 33996c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_status_tag, 34006c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_status_map, 34016c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_status_block); 34026c8d8eccSSepherosa Ziehau 34036c8d8eccSSepherosa Ziehau /* Destroy the parent tag */ 34046c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_parent_tag != NULL) 34056c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_parent_tag); 34066c8d8eccSSepherosa Ziehau } 34076c8d8eccSSepherosa Ziehau 34086c8d8eccSSepherosa Ziehau static int 3409beedf5beSSepherosa Ziehau bnx_dma_alloc(device_t dev) 34106c8d8eccSSepherosa Ziehau { 3411beedf5beSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 3412beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 34138bd43d5dSSepherosa Ziehau int i, error, mbx; 34146c8d8eccSSepherosa Ziehau 34156c8d8eccSSepherosa Ziehau /* 34166c8d8eccSSepherosa Ziehau * Allocate the parent bus DMA tag appropriate for PCI. 34176c8d8eccSSepherosa Ziehau * 34186c8d8eccSSepherosa Ziehau * All of the NetExtreme/NetLink controllers have 4GB boundary 34196c8d8eccSSepherosa Ziehau * DMA bug. 34206c8d8eccSSepherosa Ziehau * Whenever an address crosses a multiple of the 4GB boundary 34216c8d8eccSSepherosa Ziehau * (including 4GB, 8Gb, 12Gb, etc.) and makes the transition 34226c8d8eccSSepherosa Ziehau * from 0xX_FFFF_FFFF to 0x(X+1)_0000_0000 an internal DMA 34236c8d8eccSSepherosa Ziehau * state machine will lockup and cause the device to hang. 34246c8d8eccSSepherosa Ziehau */ 34256c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(NULL, 1, BGE_DMA_BOUNDARY_4G, 3426beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 3427beedf5beSSepherosa Ziehau BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 34286c8d8eccSSepherosa Ziehau 0, &sc->bnx_cdata.bnx_parent_tag); 34296c8d8eccSSepherosa Ziehau if (error) { 3430beedf5beSSepherosa Ziehau device_printf(dev, "could not create parent DMA tag\n"); 34316c8d8eccSSepherosa Ziehau return error; 34326c8d8eccSSepherosa Ziehau } 34336c8d8eccSSepherosa Ziehau 34346c8d8eccSSepherosa Ziehau /* 34356c8d8eccSSepherosa Ziehau * Create DMA stuffs for status block. 34366c8d8eccSSepherosa Ziehau */ 34376c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STATUS_BLK_SZ, 34386c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_tag, 34396c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_map, 34406c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_status_block, 34416c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_status_block_paddr); 34426c8d8eccSSepherosa Ziehau if (error) { 3443beedf5beSSepherosa Ziehau device_printf(dev, "could not create status block\n"); 34446c8d8eccSSepherosa Ziehau return error; 34456c8d8eccSSepherosa Ziehau } 34466c8d8eccSSepherosa Ziehau 3447beedf5beSSepherosa Ziehau /* 3448beedf5beSSepherosa Ziehau * Create DMA tag and maps for RX mbufs. 3449beedf5beSSepherosa Ziehau */ 3450beedf5beSSepherosa Ziehau std->bnx_sc = sc; 3451beedf5beSSepherosa Ziehau error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0, 3452beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 3453beedf5beSSepherosa Ziehau NULL, NULL, MCLBYTES, 1, MCLBYTES, 3454beedf5beSSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK, &std->bnx_rx_mtag); 3455beedf5beSSepherosa Ziehau if (error) { 3456beedf5beSSepherosa Ziehau device_printf(dev, "could not create RX mbuf DMA tag\n"); 3457beedf5beSSepherosa Ziehau return error; 3458beedf5beSSepherosa Ziehau } 3459beedf5beSSepherosa Ziehau 3460beedf5beSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; ++i) { 3461beedf5beSSepherosa Ziehau error = bus_dmamap_create(std->bnx_rx_mtag, BUS_DMA_WAITOK, 3462beedf5beSSepherosa Ziehau &std->bnx_rx_std_buf[i].bnx_rx_dmamap); 3463beedf5beSSepherosa Ziehau if (error) { 3464beedf5beSSepherosa Ziehau int j; 3465beedf5beSSepherosa Ziehau 3466beedf5beSSepherosa Ziehau for (j = 0; j < i; ++j) { 3467beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3468beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[j].bnx_rx_dmamap); 3469beedf5beSSepherosa Ziehau } 3470beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 3471beedf5beSSepherosa Ziehau std->bnx_rx_mtag = NULL; 3472beedf5beSSepherosa Ziehau 3473beedf5beSSepherosa Ziehau device_printf(dev, 3474beedf5beSSepherosa Ziehau "could not create %dth RX mbuf DMA map\n", i); 3475beedf5beSSepherosa Ziehau return error; 3476beedf5beSSepherosa Ziehau } 3477beedf5beSSepherosa Ziehau } 3478beedf5beSSepherosa Ziehau 3479beedf5beSSepherosa Ziehau /* 3480beedf5beSSepherosa Ziehau * Create DMA stuffs for standard RX ring. 3481beedf5beSSepherosa Ziehau */ 3482beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STD_RX_RING_SZ, 3483beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_tag, 3484beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_map, 3485beedf5beSSepherosa Ziehau (void *)&std->bnx_rx_std_ring, 3486beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_paddr); 3487beedf5beSSepherosa Ziehau if (error) { 3488beedf5beSSepherosa Ziehau device_printf(dev, "could not create std RX ring\n"); 3489beedf5beSSepherosa Ziehau return error; 3490beedf5beSSepherosa Ziehau } 3491beedf5beSSepherosa Ziehau 3492beedf5beSSepherosa Ziehau /* 3493beedf5beSSepherosa Ziehau * Create RX return rings 3494beedf5beSSepherosa Ziehau */ 3495beedf5beSSepherosa Ziehau sc->bnx_rx_ret_ring = kmalloc_cachealign( 3496beedf5beSSepherosa Ziehau sizeof(struct bnx_rx_ret_ring) * sc->bnx_rx_retcnt, M_DEVBUF, 3497beedf5beSSepherosa Ziehau M_WAITOK | M_ZERO); 3498beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) { 3499beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i]; 3500beedf5beSSepherosa Ziehau 3501beedf5beSSepherosa Ziehau ret->bnx_sc = sc; 3502beedf5beSSepherosa Ziehau ret->bnx_std = std; 3503*3a16b7b8SSepherosa Ziehau 3504*3a16b7b8SSepherosa Ziehau /* XXX */ 3505*3a16b7b8SSepherosa Ziehau ret->bnx_rx_considx = 3506*3a16b7b8SSepherosa Ziehau &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_rx_prod_idx; 3507*3a16b7b8SSepherosa Ziehau 3508beedf5beSSepherosa Ziehau error = bnx_create_rx_ret_ring(ret); 3509beedf5beSSepherosa Ziehau if (error) { 3510beedf5beSSepherosa Ziehau device_printf(dev, 3511beedf5beSSepherosa Ziehau "could not create %dth RX ret ring\n", i); 3512beedf5beSSepherosa Ziehau return error; 3513beedf5beSSepherosa Ziehau } 3514beedf5beSSepherosa Ziehau } 3515beedf5beSSepherosa Ziehau 3516beedf5beSSepherosa Ziehau /* 3517beedf5beSSepherosa Ziehau * Create TX rings 3518beedf5beSSepherosa Ziehau */ 35198bd43d5dSSepherosa Ziehau mbx = BGE_MBX_TX_HOST_PROD0_LO; 352033a04907SSepherosa Ziehau sc->bnx_tx_ring = kmalloc_cachealign( 352133a04907SSepherosa Ziehau sizeof(struct bnx_tx_ring) * sc->bnx_tx_ringcnt, M_DEVBUF, 352233a04907SSepherosa Ziehau M_WAITOK | M_ZERO); 352333a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 352433a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 352533a04907SSepherosa Ziehau 352633a04907SSepherosa Ziehau txr->bnx_sc = sc; 35278bd43d5dSSepherosa Ziehau txr->bnx_tx_mbx = mbx; 35288bd43d5dSSepherosa Ziehau 35298bd43d5dSSepherosa Ziehau if (mbx & 0x4) 35308bd43d5dSSepherosa Ziehau mbx -= 0x4; 35318bd43d5dSSepherosa Ziehau else 35328bd43d5dSSepherosa Ziehau mbx += 0xc; 35338bd43d5dSSepherosa Ziehau 3534*3a16b7b8SSepherosa Ziehau /* XXX */ 3535*3a16b7b8SSepherosa Ziehau txr->bnx_tx_considx = 3536*3a16b7b8SSepherosa Ziehau &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_tx_cons_idx; 3537*3a16b7b8SSepherosa Ziehau 353833a04907SSepherosa Ziehau error = bnx_create_tx_ring(txr); 353933a04907SSepherosa Ziehau if (error) { 3540beedf5beSSepherosa Ziehau device_printf(dev, 3541beedf5beSSepherosa Ziehau "could not create %dth TX ring\n", i); 3542beedf5beSSepherosa Ziehau return error; 3543beedf5beSSepherosa Ziehau } 3544beedf5beSSepherosa Ziehau } 3545beedf5beSSepherosa Ziehau 3546beedf5beSSepherosa Ziehau /* 3547beedf5beSSepherosa Ziehau * Create jumbo buffer pool. 3548beedf5beSSepherosa Ziehau */ 3549beedf5beSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 3550beedf5beSSepherosa Ziehau error = bnx_alloc_jumbo_mem(sc); 3551beedf5beSSepherosa Ziehau if (error) { 3552beedf5beSSepherosa Ziehau device_printf(dev, 3553beedf5beSSepherosa Ziehau "could not create jumbo buffer pool\n"); 355433a04907SSepherosa Ziehau return error; 355533a04907SSepherosa Ziehau } 355633a04907SSepherosa Ziehau } 355733a04907SSepherosa Ziehau 35586c8d8eccSSepherosa Ziehau return 0; 35596c8d8eccSSepherosa Ziehau } 35606c8d8eccSSepherosa Ziehau 35616c8d8eccSSepherosa Ziehau static int 35626c8d8eccSSepherosa Ziehau bnx_dma_block_alloc(struct bnx_softc *sc, bus_size_t size, bus_dma_tag_t *tag, 35636c8d8eccSSepherosa Ziehau bus_dmamap_t *map, void **addr, bus_addr_t *paddr) 35646c8d8eccSSepherosa Ziehau { 35656c8d8eccSSepherosa Ziehau bus_dmamem_t dmem; 35666c8d8eccSSepherosa Ziehau int error; 35676c8d8eccSSepherosa Ziehau 35686c8d8eccSSepherosa Ziehau error = bus_dmamem_coherent(sc->bnx_cdata.bnx_parent_tag, PAGE_SIZE, 0, 35696c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 35706c8d8eccSSepherosa Ziehau size, BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmem); 35716c8d8eccSSepherosa Ziehau if (error) 35726c8d8eccSSepherosa Ziehau return error; 35736c8d8eccSSepherosa Ziehau 35746c8d8eccSSepherosa Ziehau *tag = dmem.dmem_tag; 35756c8d8eccSSepherosa Ziehau *map = dmem.dmem_map; 35766c8d8eccSSepherosa Ziehau *addr = dmem.dmem_addr; 35776c8d8eccSSepherosa Ziehau *paddr = dmem.dmem_busaddr; 35786c8d8eccSSepherosa Ziehau 35796c8d8eccSSepherosa Ziehau return 0; 35806c8d8eccSSepherosa Ziehau } 35816c8d8eccSSepherosa Ziehau 35826c8d8eccSSepherosa Ziehau static void 35836c8d8eccSSepherosa Ziehau bnx_dma_block_free(bus_dma_tag_t tag, bus_dmamap_t map, void *addr) 35846c8d8eccSSepherosa Ziehau { 35856c8d8eccSSepherosa Ziehau if (tag != NULL) { 35866c8d8eccSSepherosa Ziehau bus_dmamap_unload(tag, map); 35876c8d8eccSSepherosa Ziehau bus_dmamem_free(tag, addr, map); 35886c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(tag); 35896c8d8eccSSepherosa Ziehau } 35906c8d8eccSSepherosa Ziehau } 35916c8d8eccSSepherosa Ziehau 35926c8d8eccSSepherosa Ziehau static void 35936c8d8eccSSepherosa Ziehau bnx_tbi_link_upd(struct bnx_softc *sc, uint32_t status) 35946c8d8eccSSepherosa Ziehau { 35956c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 35966c8d8eccSSepherosa Ziehau 35976c8d8eccSSepherosa Ziehau #define PCS_ENCODE_ERR (BGE_MACSTAT_PORT_DECODE_ERROR|BGE_MACSTAT_MI_COMPLETE) 35986c8d8eccSSepherosa Ziehau 35996c8d8eccSSepherosa Ziehau /* 36006c8d8eccSSepherosa Ziehau * Sometimes PCS encoding errors are detected in 36016c8d8eccSSepherosa Ziehau * TBI mode (on fiber NICs), and for some reason 36026c8d8eccSSepherosa Ziehau * the chip will signal them as link changes. 36036c8d8eccSSepherosa Ziehau * If we get a link change event, but the 'PCS 36046c8d8eccSSepherosa Ziehau * encoding error' bit in the MAC status register 36056c8d8eccSSepherosa Ziehau * is set, don't bother doing a link check. 36066c8d8eccSSepherosa Ziehau * This avoids spurious "gigabit link up" messages 36076c8d8eccSSepherosa Ziehau * that sometimes appear on fiber NICs during 36086c8d8eccSSepherosa Ziehau * periods of heavy traffic. 36096c8d8eccSSepherosa Ziehau */ 36106c8d8eccSSepherosa Ziehau if (status & BGE_MACSTAT_TBI_PCS_SYNCHED) { 36116c8d8eccSSepherosa Ziehau if (!sc->bnx_link) { 36126c8d8eccSSepherosa Ziehau sc->bnx_link++; 36136c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704) { 36146c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 36156c8d8eccSSepherosa Ziehau BGE_MACMODE_TBI_SEND_CFGS); 36166c8d8eccSSepherosa Ziehau } 36176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, 0xFFFFFFFF); 36186c8d8eccSSepherosa Ziehau 36196c8d8eccSSepherosa Ziehau if (bootverbose) 36206c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 36216c8d8eccSSepherosa Ziehau 36226c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_UP; 36236c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 36246c8d8eccSSepherosa Ziehau } 36256c8d8eccSSepherosa Ziehau } else if ((status & PCS_ENCODE_ERR) != PCS_ENCODE_ERR) { 36266c8d8eccSSepherosa Ziehau if (sc->bnx_link) { 36276c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 36286c8d8eccSSepherosa Ziehau 36296c8d8eccSSepherosa Ziehau if (bootverbose) 36306c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 36316c8d8eccSSepherosa Ziehau 36326c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_DOWN; 36336c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 36346c8d8eccSSepherosa Ziehau } 36356c8d8eccSSepherosa Ziehau } 36366c8d8eccSSepherosa Ziehau 36376c8d8eccSSepherosa Ziehau #undef PCS_ENCODE_ERR 36386c8d8eccSSepherosa Ziehau 36396c8d8eccSSepherosa Ziehau /* Clear the attention. */ 36406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 36416c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 36426c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 36436c8d8eccSSepherosa Ziehau } 36446c8d8eccSSepherosa Ziehau 36456c8d8eccSSepherosa Ziehau static void 36466c8d8eccSSepherosa Ziehau bnx_copper_link_upd(struct bnx_softc *sc, uint32_t status __unused) 36476c8d8eccSSepherosa Ziehau { 36486c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 36496c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 36506c8d8eccSSepherosa Ziehau 36516c8d8eccSSepherosa Ziehau mii_pollstat(mii); 36526c8d8eccSSepherosa Ziehau bnx_miibus_statchg(sc->bnx_dev); 36536c8d8eccSSepherosa Ziehau 36546c8d8eccSSepherosa Ziehau if (bootverbose) { 36556c8d8eccSSepherosa Ziehau if (sc->bnx_link) 36566c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 36576c8d8eccSSepherosa Ziehau else 36586c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 36596c8d8eccSSepherosa Ziehau } 36606c8d8eccSSepherosa Ziehau 36616c8d8eccSSepherosa Ziehau /* Clear the attention. */ 36626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 36636c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 36646c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 36656c8d8eccSSepherosa Ziehau } 36666c8d8eccSSepherosa Ziehau 36676c8d8eccSSepherosa Ziehau static void 36686c8d8eccSSepherosa Ziehau bnx_autopoll_link_upd(struct bnx_softc *sc, uint32_t status __unused) 36696c8d8eccSSepherosa Ziehau { 36706c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 36716c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 36726c8d8eccSSepherosa Ziehau 36736c8d8eccSSepherosa Ziehau mii_pollstat(mii); 36746c8d8eccSSepherosa Ziehau 36756c8d8eccSSepherosa Ziehau if (!sc->bnx_link && 36766c8d8eccSSepherosa Ziehau (mii->mii_media_status & IFM_ACTIVE) && 36776c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 36786c8d8eccSSepherosa Ziehau sc->bnx_link++; 36796c8d8eccSSepherosa Ziehau if (bootverbose) 36806c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 36816c8d8eccSSepherosa Ziehau } else if (sc->bnx_link && 36826c8d8eccSSepherosa Ziehau (!(mii->mii_media_status & IFM_ACTIVE) || 36836c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)) { 36846c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 36856c8d8eccSSepherosa Ziehau if (bootverbose) 36866c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 36876c8d8eccSSepherosa Ziehau } 36886c8d8eccSSepherosa Ziehau 36896c8d8eccSSepherosa Ziehau /* Clear the attention. */ 36906c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 36916c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 36926c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 36936c8d8eccSSepherosa Ziehau } 36946c8d8eccSSepherosa Ziehau 36956c8d8eccSSepherosa Ziehau static int 36966c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS) 36976c8d8eccSSepherosa Ziehau { 36986c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 36996c8d8eccSSepherosa Ziehau 37006c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37016c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_ticks, 37026c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_MIN, BNX_RX_COAL_TICKS_MAX, 37036c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_CHG); 37046c8d8eccSSepherosa Ziehau } 37056c8d8eccSSepherosa Ziehau 37066c8d8eccSSepherosa Ziehau static int 37076c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS) 37086c8d8eccSSepherosa Ziehau { 37096c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37106c8d8eccSSepherosa Ziehau 37116c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37126c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_ticks, 37136c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_MIN, BNX_TX_COAL_TICKS_MAX, 37146c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_CHG); 37156c8d8eccSSepherosa Ziehau } 37166c8d8eccSSepherosa Ziehau 37176c8d8eccSSepherosa Ziehau static int 37186c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS) 37196c8d8eccSSepherosa Ziehau { 37206c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37216c8d8eccSSepherosa Ziehau 37226c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37236c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds, 37246c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 37256c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_CHG); 37266c8d8eccSSepherosa Ziehau } 37276c8d8eccSSepherosa Ziehau 37286c8d8eccSSepherosa Ziehau static int 37296c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS) 37306c8d8eccSSepherosa Ziehau { 37316c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37326c8d8eccSSepherosa Ziehau 37336c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37346c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds, 37356c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 37366c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_CHG); 37376c8d8eccSSepherosa Ziehau } 37386c8d8eccSSepherosa Ziehau 37396c8d8eccSSepherosa Ziehau static int 37406c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS) 37416c8d8eccSSepherosa Ziehau { 37426c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37436c8d8eccSSepherosa Ziehau 37446c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37456c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds_int, 37466c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 37476c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_INT_CHG); 37486c8d8eccSSepherosa Ziehau } 37496c8d8eccSSepherosa Ziehau 37506c8d8eccSSepherosa Ziehau static int 37516c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS) 37526c8d8eccSSepherosa Ziehau { 37536c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37546c8d8eccSSepherosa Ziehau 37556c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37566c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds_int, 37576c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 37586c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_INT_CHG); 37596c8d8eccSSepherosa Ziehau } 37606c8d8eccSSepherosa Ziehau 37616c8d8eccSSepherosa Ziehau static int 37626c8d8eccSSepherosa Ziehau bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *coal, 37636c8d8eccSSepherosa Ziehau int coal_min, int coal_max, uint32_t coal_chg_mask) 37646c8d8eccSSepherosa Ziehau { 37656c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37666c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 37676c8d8eccSSepherosa Ziehau int error = 0, v; 37686c8d8eccSSepherosa Ziehau 37696c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 37706c8d8eccSSepherosa Ziehau 37716c8d8eccSSepherosa Ziehau v = *coal; 37726c8d8eccSSepherosa Ziehau error = sysctl_handle_int(oidp, &v, 0, req); 37736c8d8eccSSepherosa Ziehau if (!error && req->newptr != NULL) { 37746c8d8eccSSepherosa Ziehau if (v < coal_min || v > coal_max) { 37756c8d8eccSSepherosa Ziehau error = EINVAL; 37766c8d8eccSSepherosa Ziehau } else { 37776c8d8eccSSepherosa Ziehau *coal = v; 37786c8d8eccSSepherosa Ziehau sc->bnx_coal_chg |= coal_chg_mask; 3779f5014362SSepherosa Ziehau 3780f5014362SSepherosa Ziehau /* Commit changes */ 3781f5014362SSepherosa Ziehau bnx_coal_change(sc); 37826c8d8eccSSepherosa Ziehau } 37836c8d8eccSSepherosa Ziehau } 37846c8d8eccSSepherosa Ziehau 37856c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 37866c8d8eccSSepherosa Ziehau return error; 37876c8d8eccSSepherosa Ziehau } 37886c8d8eccSSepherosa Ziehau 37896c8d8eccSSepherosa Ziehau static void 37906c8d8eccSSepherosa Ziehau bnx_coal_change(struct bnx_softc *sc) 37916c8d8eccSSepherosa Ziehau { 37926c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 37936c8d8eccSSepherosa Ziehau 37946c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 37956c8d8eccSSepherosa Ziehau 37966c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_TICKS_CHG) { 37976c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, 37986c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 37996c8d8eccSSepherosa Ziehau DELAY(10); 3800e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_COAL_TICKS); 38016c8d8eccSSepherosa Ziehau 38026c8d8eccSSepherosa Ziehau if (bootverbose) { 38036c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_ticks -> %u\n", 38046c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 38056c8d8eccSSepherosa Ziehau } 38066c8d8eccSSepherosa Ziehau } 38076c8d8eccSSepherosa Ziehau 38086c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_TICKS_CHG) { 38096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, 38106c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 38116c8d8eccSSepherosa Ziehau DELAY(10); 3812e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_COAL_TICKS); 38136c8d8eccSSepherosa Ziehau 38146c8d8eccSSepherosa Ziehau if (bootverbose) { 38156c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_ticks -> %u\n", 38166c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 38176c8d8eccSSepherosa Ziehau } 38186c8d8eccSSepherosa Ziehau } 38196c8d8eccSSepherosa Ziehau 38206c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_CHG) { 38216c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, 38226c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 38236c8d8eccSSepherosa Ziehau DELAY(10); 3824e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS); 38256c8d8eccSSepherosa Ziehau 38266c8d8eccSSepherosa Ziehau if (bootverbose) { 38276c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds -> %u\n", 38286c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 38296c8d8eccSSepherosa Ziehau } 38306c8d8eccSSepherosa Ziehau } 38316c8d8eccSSepherosa Ziehau 38326c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_CHG) { 38336c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, 38346c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 38356c8d8eccSSepherosa Ziehau DELAY(10); 3836e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS); 38376c8d8eccSSepherosa Ziehau 38386c8d8eccSSepherosa Ziehau if (bootverbose) { 3839cc98a7c2SSepherosa Ziehau if_printf(ifp, "tx_coal_bds -> %u\n", 38406c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 38416c8d8eccSSepherosa Ziehau } 38426c8d8eccSSepherosa Ziehau } 38436c8d8eccSSepherosa Ziehau 38446c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_INT_CHG) { 38456c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, 38466c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 38476c8d8eccSSepherosa Ziehau DELAY(10); 3848e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT); 38496c8d8eccSSepherosa Ziehau 38506c8d8eccSSepherosa Ziehau if (bootverbose) { 38516c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds_int -> %u\n", 38526c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 38536c8d8eccSSepherosa Ziehau } 38546c8d8eccSSepherosa Ziehau } 38556c8d8eccSSepherosa Ziehau 38566c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_INT_CHG) { 38576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, 38586c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 38596c8d8eccSSepherosa Ziehau DELAY(10); 3860e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT); 38616c8d8eccSSepherosa Ziehau 38626c8d8eccSSepherosa Ziehau if (bootverbose) { 38636c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_bds_int -> %u\n", 38646c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 38656c8d8eccSSepherosa Ziehau } 38666c8d8eccSSepherosa Ziehau } 38676c8d8eccSSepherosa Ziehau 38686c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 38696c8d8eccSSepherosa Ziehau } 38706c8d8eccSSepherosa Ziehau 38716c8d8eccSSepherosa Ziehau static void 3872df9ccc98SSepherosa Ziehau bnx_intr_check(void *xsc) 3873df9ccc98SSepherosa Ziehau { 3874df9ccc98SSepherosa Ziehau struct bnx_softc *sc = xsc; 387533a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 3876beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */ 3877df9ccc98SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 3878df9ccc98SSepherosa Ziehau 3879df9ccc98SSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 3880df9ccc98SSepherosa Ziehau 3881df9ccc98SSepherosa Ziehau KKASSERT(mycpuid == sc->bnx_intr_cpuid); 3882df9ccc98SSepherosa Ziehau 388339a8d43aSSepherosa Ziehau if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) { 3884df9ccc98SSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 3885df9ccc98SSepherosa Ziehau return; 3886df9ccc98SSepherosa Ziehau } 3887df9ccc98SSepherosa Ziehau 3888*3a16b7b8SSepherosa Ziehau if (*ret->bnx_rx_considx != ret->bnx_rx_saved_considx || 3889*3a16b7b8SSepherosa Ziehau *txr->bnx_tx_considx != txr->bnx_tx_saved_considx) { 3890beedf5beSSepherosa Ziehau if (sc->bnx_rx_check_considx == ret->bnx_rx_saved_considx && 389133a04907SSepherosa Ziehau sc->bnx_tx_check_considx == txr->bnx_tx_saved_considx) { 3892df9ccc98SSepherosa Ziehau if (!sc->bnx_intr_maylose) { 3893df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = TRUE; 3894df9ccc98SSepherosa Ziehau goto done; 3895df9ccc98SSepherosa Ziehau } 3896df9ccc98SSepherosa Ziehau if (bootverbose) 3897df9ccc98SSepherosa Ziehau if_printf(ifp, "lost interrupt\n"); 3898df9ccc98SSepherosa Ziehau bnx_msi(sc); 3899df9ccc98SSepherosa Ziehau } 3900df9ccc98SSepherosa Ziehau } 3901df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 3902beedf5beSSepherosa Ziehau sc->bnx_rx_check_considx = ret->bnx_rx_saved_considx; 390333a04907SSepherosa Ziehau sc->bnx_tx_check_considx = txr->bnx_tx_saved_considx; 3904df9ccc98SSepherosa Ziehau 3905df9ccc98SSepherosa Ziehau done: 3906df9ccc98SSepherosa Ziehau callout_reset(&sc->bnx_intr_timer, BNX_INTR_CKINTVL, 3907df9ccc98SSepherosa Ziehau bnx_intr_check, sc); 3908df9ccc98SSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 3909df9ccc98SSepherosa Ziehau } 3910df9ccc98SSepherosa Ziehau 3911df9ccc98SSepherosa Ziehau static void 39126c8d8eccSSepherosa Ziehau bnx_enable_intr(struct bnx_softc *sc) 39136c8d8eccSSepherosa Ziehau { 39146c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 39156c8d8eccSSepherosa Ziehau 39166c8d8eccSSepherosa Ziehau lwkt_serialize_handler_enable(ifp->if_serializer); 39176c8d8eccSSepherosa Ziehau 39186c8d8eccSSepherosa Ziehau /* 39196c8d8eccSSepherosa Ziehau * Enable interrupt. 39206c8d8eccSSepherosa Ziehau */ 39216c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 39226c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 39236c8d8eccSSepherosa Ziehau /* XXX Linux driver */ 39246c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 39256c8d8eccSSepherosa Ziehau } 39266c8d8eccSSepherosa Ziehau 39276c8d8eccSSepherosa Ziehau /* 39286c8d8eccSSepherosa Ziehau * Unmask the interrupt when we stop polling. 39296c8d8eccSSepherosa Ziehau */ 39306c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 39316c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 39326c8d8eccSSepherosa Ziehau 39336c8d8eccSSepherosa Ziehau /* 39346c8d8eccSSepherosa Ziehau * Trigger another interrupt, since above writing 39356c8d8eccSSepherosa Ziehau * to interrupt mailbox0 may acknowledge pending 39366c8d8eccSSepherosa Ziehau * interrupt. 39376c8d8eccSSepherosa Ziehau */ 39386c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET); 3939df9ccc98SSepherosa Ziehau 3940df9ccc98SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_STATUSTAG_BUG) { 3941df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 3942df9ccc98SSepherosa Ziehau sc->bnx_rx_check_considx = 0; 3943df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx = 0; 3944df9ccc98SSepherosa Ziehau 3945df9ccc98SSepherosa Ziehau if (bootverbose) 3946df9ccc98SSepherosa Ziehau if_printf(ifp, "status tag bug workaround\n"); 3947df9ccc98SSepherosa Ziehau 3948df9ccc98SSepherosa Ziehau /* 10ms check interval */ 3949df9ccc98SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_intr_timer, BNX_INTR_CKINTVL, 3950df9ccc98SSepherosa Ziehau bnx_intr_check, sc, sc->bnx_intr_cpuid); 3951df9ccc98SSepherosa Ziehau } 39526c8d8eccSSepherosa Ziehau } 39536c8d8eccSSepherosa Ziehau 39546c8d8eccSSepherosa Ziehau static void 39556c8d8eccSSepherosa Ziehau bnx_disable_intr(struct bnx_softc *sc) 39566c8d8eccSSepherosa Ziehau { 39576c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 39586c8d8eccSSepherosa Ziehau 39596c8d8eccSSepherosa Ziehau /* 39606c8d8eccSSepherosa Ziehau * Mask the interrupt when we start polling. 39616c8d8eccSSepherosa Ziehau */ 39626c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 39636c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 39646c8d8eccSSepherosa Ziehau 39656c8d8eccSSepherosa Ziehau /* 39666c8d8eccSSepherosa Ziehau * Acknowledge possible asserted interrupt. 39676c8d8eccSSepherosa Ziehau */ 39686c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 39696c8d8eccSSepherosa Ziehau 3970df9ccc98SSepherosa Ziehau callout_stop(&sc->bnx_intr_timer); 3971df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 3972df9ccc98SSepherosa Ziehau sc->bnx_rx_check_considx = 0; 3973df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx = 0; 3974df9ccc98SSepherosa Ziehau 3975b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = 0; 397639a8d43aSSepherosa Ziehau 39776c8d8eccSSepherosa Ziehau lwkt_serialize_handler_disable(ifp->if_serializer); 39786c8d8eccSSepherosa Ziehau } 39796c8d8eccSSepherosa Ziehau 39806c8d8eccSSepherosa Ziehau static int 39816c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem(struct bnx_softc *sc, uint8_t ether_addr[]) 39826c8d8eccSSepherosa Ziehau { 39836c8d8eccSSepherosa Ziehau uint32_t mac_addr; 39846c8d8eccSSepherosa Ziehau int ret = 1; 39856c8d8eccSSepherosa Ziehau 39866c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c14); 39876c8d8eccSSepherosa Ziehau if ((mac_addr >> 16) == 0x484b) { 39886c8d8eccSSepherosa Ziehau ether_addr[0] = (uint8_t)(mac_addr >> 8); 39896c8d8eccSSepherosa Ziehau ether_addr[1] = (uint8_t)mac_addr; 39906c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c18); 39916c8d8eccSSepherosa Ziehau ether_addr[2] = (uint8_t)(mac_addr >> 24); 39926c8d8eccSSepherosa Ziehau ether_addr[3] = (uint8_t)(mac_addr >> 16); 39936c8d8eccSSepherosa Ziehau ether_addr[4] = (uint8_t)(mac_addr >> 8); 39946c8d8eccSSepherosa Ziehau ether_addr[5] = (uint8_t)mac_addr; 39956c8d8eccSSepherosa Ziehau ret = 0; 39966c8d8eccSSepherosa Ziehau } 39976c8d8eccSSepherosa Ziehau return ret; 39986c8d8eccSSepherosa Ziehau } 39996c8d8eccSSepherosa Ziehau 40006c8d8eccSSepherosa Ziehau static int 40016c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram(struct bnx_softc *sc, uint8_t ether_addr[]) 40026c8d8eccSSepherosa Ziehau { 40036c8d8eccSSepherosa Ziehau int mac_offset = BGE_EE_MAC_OFFSET; 40046c8d8eccSSepherosa Ziehau 400580969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 400680969639SSepherosa Ziehau int f; 400780969639SSepherosa Ziehau 400880969639SSepherosa Ziehau f = pci_get_function(sc->bnx_dev); 400980969639SSepherosa Ziehau if (f & 1) 401080969639SSepherosa Ziehau mac_offset = BGE_EE_MAC_OFFSET_5717; 401180969639SSepherosa Ziehau if (f > 1) 401280969639SSepherosa Ziehau mac_offset += BGE_EE_MAC_OFFSET_5717_OFF; 401380969639SSepherosa Ziehau } 40146c8d8eccSSepherosa Ziehau 40156c8d8eccSSepherosa Ziehau return bnx_read_nvram(sc, ether_addr, mac_offset + 2, ETHER_ADDR_LEN); 40166c8d8eccSSepherosa Ziehau } 40176c8d8eccSSepherosa Ziehau 40186c8d8eccSSepherosa Ziehau static int 40196c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom(struct bnx_softc *sc, uint8_t ether_addr[]) 40206c8d8eccSSepherosa Ziehau { 40216c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_NO_EEPROM) 40226c8d8eccSSepherosa Ziehau return 1; 40236c8d8eccSSepherosa Ziehau 40246c8d8eccSSepherosa Ziehau return bnx_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2, 40256c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN); 40266c8d8eccSSepherosa Ziehau } 40276c8d8eccSSepherosa Ziehau 40286c8d8eccSSepherosa Ziehau static int 40296c8d8eccSSepherosa Ziehau bnx_get_eaddr(struct bnx_softc *sc, uint8_t eaddr[]) 40306c8d8eccSSepherosa Ziehau { 40316c8d8eccSSepherosa Ziehau static const bnx_eaddr_fcn_t bnx_eaddr_funcs[] = { 40326c8d8eccSSepherosa Ziehau /* NOTE: Order is critical */ 40336c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem, 40346c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram, 40356c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom, 40366c8d8eccSSepherosa Ziehau NULL 40376c8d8eccSSepherosa Ziehau }; 40386c8d8eccSSepherosa Ziehau const bnx_eaddr_fcn_t *func; 40396c8d8eccSSepherosa Ziehau 40406c8d8eccSSepherosa Ziehau for (func = bnx_eaddr_funcs; *func != NULL; ++func) { 40416c8d8eccSSepherosa Ziehau if ((*func)(sc, eaddr) == 0) 40426c8d8eccSSepherosa Ziehau break; 40436c8d8eccSSepherosa Ziehau } 40446c8d8eccSSepherosa Ziehau return (*func == NULL ? ENXIO : 0); 40456c8d8eccSSepherosa Ziehau } 40466c8d8eccSSepherosa Ziehau 40476c8d8eccSSepherosa Ziehau /* 40486c8d8eccSSepherosa Ziehau * NOTE: 'm' is not freed upon failure 40496c8d8eccSSepherosa Ziehau */ 40506c8d8eccSSepherosa Ziehau struct mbuf * 40516c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *m) 40526c8d8eccSSepherosa Ziehau { 40536c8d8eccSSepherosa Ziehau struct mbuf *n; 40546c8d8eccSSepherosa Ziehau int found; 40556c8d8eccSSepherosa Ziehau 40566c8d8eccSSepherosa Ziehau /* 40576c8d8eccSSepherosa Ziehau * If device receive two back-to-back send BDs with less than 40586c8d8eccSSepherosa Ziehau * or equal to 8 total bytes then the device may hang. The two 40596c8d8eccSSepherosa Ziehau * back-to-back send BDs must in the same frame for this failure 40606c8d8eccSSepherosa Ziehau * to occur. Scan mbuf chains and see whether two back-to-back 40616c8d8eccSSepherosa Ziehau * send BDs are there. If this is the case, allocate new mbuf 40626c8d8eccSSepherosa Ziehau * and copy the frame to workaround the silicon bug. 40636c8d8eccSSepherosa Ziehau */ 40646c8d8eccSSepherosa Ziehau for (n = m, found = 0; n != NULL; n = n->m_next) { 40656c8d8eccSSepherosa Ziehau if (n->m_len < 8) { 40666c8d8eccSSepherosa Ziehau found++; 40676c8d8eccSSepherosa Ziehau if (found > 1) 40686c8d8eccSSepherosa Ziehau break; 40696c8d8eccSSepherosa Ziehau continue; 40706c8d8eccSSepherosa Ziehau } 40716c8d8eccSSepherosa Ziehau found = 0; 40726c8d8eccSSepherosa Ziehau } 40736c8d8eccSSepherosa Ziehau 40746c8d8eccSSepherosa Ziehau if (found > 1) 40756c8d8eccSSepherosa Ziehau n = m_defrag(m, MB_DONTWAIT); 40766c8d8eccSSepherosa Ziehau else 40776c8d8eccSSepherosa Ziehau n = m; 40786c8d8eccSSepherosa Ziehau return n; 40796c8d8eccSSepherosa Ziehau } 40806c8d8eccSSepherosa Ziehau 40816c8d8eccSSepherosa Ziehau static void 40826c8d8eccSSepherosa Ziehau bnx_stop_block(struct bnx_softc *sc, bus_size_t reg, uint32_t bit) 40836c8d8eccSSepherosa Ziehau { 40846c8d8eccSSepherosa Ziehau int i; 40856c8d8eccSSepherosa Ziehau 40866c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, reg, bit); 40876c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 40886c8d8eccSSepherosa Ziehau if ((CSR_READ_4(sc, reg) & bit) == 0) 40896c8d8eccSSepherosa Ziehau return; 40906c8d8eccSSepherosa Ziehau DELAY(100); 40916c8d8eccSSepherosa Ziehau } 40926c8d8eccSSepherosa Ziehau } 40936c8d8eccSSepherosa Ziehau 40946c8d8eccSSepherosa Ziehau static void 40956c8d8eccSSepherosa Ziehau bnx_link_poll(struct bnx_softc *sc) 40966c8d8eccSSepherosa Ziehau { 40976c8d8eccSSepherosa Ziehau uint32_t status; 40986c8d8eccSSepherosa Ziehau 40996c8d8eccSSepherosa Ziehau status = CSR_READ_4(sc, BGE_MAC_STS); 41006c8d8eccSSepherosa Ziehau if ((status & sc->bnx_link_chg) || sc->bnx_link_evt) { 41016c8d8eccSSepherosa Ziehau sc->bnx_link_evt = 0; 41026c8d8eccSSepherosa Ziehau sc->bnx_link_upd(sc, status); 41036c8d8eccSSepherosa Ziehau } 41046c8d8eccSSepherosa Ziehau } 41056c8d8eccSSepherosa Ziehau 41066c8d8eccSSepherosa Ziehau static void 41076c8d8eccSSepherosa Ziehau bnx_enable_msi(struct bnx_softc *sc) 41086c8d8eccSSepherosa Ziehau { 41096c8d8eccSSepherosa Ziehau uint32_t msi_mode; 41106c8d8eccSSepherosa Ziehau 41116c8d8eccSSepherosa Ziehau msi_mode = CSR_READ_4(sc, BGE_MSI_MODE); 41126c8d8eccSSepherosa Ziehau msi_mode |= BGE_MSIMODE_ENABLE; 41136c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 41146c8d8eccSSepherosa Ziehau /* 41156c8d8eccSSepherosa Ziehau * NOTE: 41166c8d8eccSSepherosa Ziehau * 5718-PG105-R says that "one shot" mode 41176c8d8eccSSepherosa Ziehau * does not work if MSI is used, however, 41186c8d8eccSSepherosa Ziehau * it obviously works. 41196c8d8eccSSepherosa Ziehau */ 41206c8d8eccSSepherosa Ziehau msi_mode &= ~BGE_MSIMODE_ONESHOT_DISABLE; 41216c8d8eccSSepherosa Ziehau } 41226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MSI_MODE, msi_mode); 41236c8d8eccSSepherosa Ziehau } 41246c8d8eccSSepherosa Ziehau 41256c8d8eccSSepherosa Ziehau static uint32_t 41266c8d8eccSSepherosa Ziehau bnx_dma_swap_options(struct bnx_softc *sc) 41276c8d8eccSSepherosa Ziehau { 41286c8d8eccSSepherosa Ziehau uint32_t dma_options; 41296c8d8eccSSepherosa Ziehau 41306c8d8eccSSepherosa Ziehau dma_options = BGE_MODECTL_WORDSWAP_NONFRAME | 41316c8d8eccSSepherosa Ziehau BGE_MODECTL_BYTESWAP_DATA | BGE_MODECTL_WORDSWAP_DATA; 41326c8d8eccSSepherosa Ziehau #if BYTE_ORDER == BIG_ENDIAN 41336c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_NONFRAME; 41346c8d8eccSSepherosa Ziehau #endif 4135b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 4136b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 41376c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA | 41386c8d8eccSSepherosa Ziehau BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE | 41396c8d8eccSSepherosa Ziehau BGE_MODECTL_HTX2B_ENABLE; 41406c8d8eccSSepherosa Ziehau } 41416c8d8eccSSepherosa Ziehau return dma_options; 41426c8d8eccSSepherosa Ziehau } 414366deb1c1SSepherosa Ziehau 414466deb1c1SSepherosa Ziehau static int 414533a04907SSepherosa Ziehau bnx_setup_tso(struct bnx_tx_ring *txr, struct mbuf **mp, 414666deb1c1SSepherosa Ziehau uint16_t *mss0, uint16_t *flags0) 414766deb1c1SSepherosa Ziehau { 414866deb1c1SSepherosa Ziehau struct mbuf *m; 414966deb1c1SSepherosa Ziehau struct ip *ip; 415066deb1c1SSepherosa Ziehau struct tcphdr *th; 415166deb1c1SSepherosa Ziehau int thoff, iphlen, hoff, hlen; 415266deb1c1SSepherosa Ziehau uint16_t flags, mss; 415366deb1c1SSepherosa Ziehau 4154f7a2269aSSepherosa Ziehau m = *mp; 4155f7a2269aSSepherosa Ziehau KASSERT(M_WRITABLE(m), ("TSO mbuf not writable")); 4156f7a2269aSSepherosa Ziehau 4157f7a2269aSSepherosa Ziehau hoff = m->m_pkthdr.csum_lhlen; 4158f7a2269aSSepherosa Ziehau iphlen = m->m_pkthdr.csum_iphlen; 4159f7a2269aSSepherosa Ziehau thoff = m->m_pkthdr.csum_thlen; 4160f7a2269aSSepherosa Ziehau 4161f7a2269aSSepherosa Ziehau KASSERT(hoff > 0, ("invalid ether header len")); 4162f7a2269aSSepherosa Ziehau KASSERT(iphlen > 0, ("invalid ip header len")); 4163f7a2269aSSepherosa Ziehau KASSERT(thoff > 0, ("invalid tcp header len")); 4164f7a2269aSSepherosa Ziehau 4165f7a2269aSSepherosa Ziehau if (__predict_false(m->m_len < hoff + iphlen + thoff)) { 4166f7a2269aSSepherosa Ziehau m = m_pullup(m, hoff + iphlen + thoff); 4167f7a2269aSSepherosa Ziehau if (m == NULL) { 4168f7a2269aSSepherosa Ziehau *mp = NULL; 4169f7a2269aSSepherosa Ziehau return ENOBUFS; 4170f7a2269aSSepherosa Ziehau } 4171f7a2269aSSepherosa Ziehau *mp = m; 4172f7a2269aSSepherosa Ziehau } 4173f7a2269aSSepherosa Ziehau ip = mtodoff(m, struct ip *, hoff); 4174f7a2269aSSepherosa Ziehau th = mtodoff(m, struct tcphdr *, hoff + iphlen); 4175f7a2269aSSepherosa Ziehau 4176f0336d39SSepherosa Ziehau mss = m->m_pkthdr.tso_segsz; 417766deb1c1SSepherosa Ziehau flags = BGE_TXBDFLAG_CPU_PRE_DMA | BGE_TXBDFLAG_CPU_POST_DMA; 417866deb1c1SSepherosa Ziehau 417966deb1c1SSepherosa Ziehau ip->ip_len = htons(mss + iphlen + thoff); 418066deb1c1SSepherosa Ziehau th->th_sum = 0; 418166deb1c1SSepherosa Ziehau 418266deb1c1SSepherosa Ziehau hlen = (iphlen + thoff) >> 2; 418366deb1c1SSepherosa Ziehau mss |= ((hlen & 0x3) << 14); 418466deb1c1SSepherosa Ziehau flags |= ((hlen & 0xf8) << 7) | ((hlen & 0x4) << 2); 418566deb1c1SSepherosa Ziehau 418666deb1c1SSepherosa Ziehau *mss0 = mss; 418766deb1c1SSepherosa Ziehau *flags0 = flags; 418866deb1c1SSepherosa Ziehau 418966deb1c1SSepherosa Ziehau return 0; 419066deb1c1SSepherosa Ziehau } 419133a04907SSepherosa Ziehau 419233a04907SSepherosa Ziehau static int 419333a04907SSepherosa Ziehau bnx_create_tx_ring(struct bnx_tx_ring *txr) 419433a04907SSepherosa Ziehau { 419533a04907SSepherosa Ziehau bus_size_t txmaxsz, txmaxsegsz; 419633a04907SSepherosa Ziehau int i, error; 419733a04907SSepherosa Ziehau 419833a04907SSepherosa Ziehau /* 419933a04907SSepherosa Ziehau * Create DMA tag and maps for TX mbufs. 420033a04907SSepherosa Ziehau */ 420133a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_flags & BNX_FLAG_TSO) 420233a04907SSepherosa Ziehau txmaxsz = IP_MAXPACKET + sizeof(struct ether_vlan_header); 420333a04907SSepherosa Ziehau else 420433a04907SSepherosa Ziehau txmaxsz = BNX_JUMBO_FRAMELEN; 420533a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_asicrev == BGE_ASICREV_BCM57766) 420633a04907SSepherosa Ziehau txmaxsegsz = MCLBYTES; 420733a04907SSepherosa Ziehau else 420833a04907SSepherosa Ziehau txmaxsegsz = PAGE_SIZE; 420933a04907SSepherosa Ziehau error = bus_dma_tag_create(txr->bnx_sc->bnx_cdata.bnx_parent_tag, 421033a04907SSepherosa Ziehau 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 421133a04907SSepherosa Ziehau txmaxsz, BNX_NSEG_NEW, txmaxsegsz, 421233a04907SSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 421333a04907SSepherosa Ziehau &txr->bnx_tx_mtag); 421433a04907SSepherosa Ziehau if (error) { 421533a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4216beedf5beSSepherosa Ziehau "could not create TX mbuf DMA tag\n"); 421733a04907SSepherosa Ziehau return error; 421833a04907SSepherosa Ziehau } 421933a04907SSepherosa Ziehau 422033a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 422133a04907SSepherosa Ziehau error = bus_dmamap_create(txr->bnx_tx_mtag, 422233a04907SSepherosa Ziehau BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 4223fa4b1067SSepherosa Ziehau &txr->bnx_tx_buf[i].bnx_tx_dmamap); 422433a04907SSepherosa Ziehau if (error) { 422533a04907SSepherosa Ziehau int j; 422633a04907SSepherosa Ziehau 422733a04907SSepherosa Ziehau for (j = 0; j < i; ++j) { 422833a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4229fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[j].bnx_tx_dmamap); 423033a04907SSepherosa Ziehau } 423133a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 423233a04907SSepherosa Ziehau txr->bnx_tx_mtag = NULL; 423333a04907SSepherosa Ziehau 423433a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4235beedf5beSSepherosa Ziehau "could not create TX mbuf DMA map\n"); 423633a04907SSepherosa Ziehau return error; 423733a04907SSepherosa Ziehau } 423833a04907SSepherosa Ziehau } 423933a04907SSepherosa Ziehau 424033a04907SSepherosa Ziehau /* 424133a04907SSepherosa Ziehau * Create DMA stuffs for TX ring. 424233a04907SSepherosa Ziehau */ 424333a04907SSepherosa Ziehau error = bnx_dma_block_alloc(txr->bnx_sc, BGE_TX_RING_SZ, 4244beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_tag, 4245beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_map, 4246beedf5beSSepherosa Ziehau (void *)&txr->bnx_tx_ring, 4247beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_paddr); 424833a04907SSepherosa Ziehau if (error) { 424933a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 425033a04907SSepherosa Ziehau "could not create TX ring\n"); 425133a04907SSepherosa Ziehau return error; 425233a04907SSepherosa Ziehau } 425333a04907SSepherosa Ziehau 425479a64343SSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_SHORTDMA; 425533a04907SSepherosa Ziehau txr->bnx_tx_wreg = BNX_TX_WREG_NSEGS; 425633a04907SSepherosa Ziehau 425733a04907SSepherosa Ziehau return 0; 425833a04907SSepherosa Ziehau } 425933a04907SSepherosa Ziehau 426033a04907SSepherosa Ziehau static void 426133a04907SSepherosa Ziehau bnx_destroy_tx_ring(struct bnx_tx_ring *txr) 426233a04907SSepherosa Ziehau { 426333a04907SSepherosa Ziehau /* Destroy TX mbuf DMA stuffs. */ 426433a04907SSepherosa Ziehau if (txr->bnx_tx_mtag != NULL) { 426533a04907SSepherosa Ziehau int i; 426633a04907SSepherosa Ziehau 426733a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 4268fa4b1067SSepherosa Ziehau KKASSERT(txr->bnx_tx_buf[i].bnx_tx_mbuf == NULL); 426933a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4270fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[i].bnx_tx_dmamap); 427133a04907SSepherosa Ziehau } 427233a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 427333a04907SSepherosa Ziehau } 427433a04907SSepherosa Ziehau 427533a04907SSepherosa Ziehau /* Destroy TX ring */ 427633a04907SSepherosa Ziehau bnx_dma_block_free(txr->bnx_tx_ring_tag, 427733a04907SSepherosa Ziehau txr->bnx_tx_ring_map, txr->bnx_tx_ring); 427833a04907SSepherosa Ziehau } 4279aad4de2bSSepherosa Ziehau 4280aad4de2bSSepherosa Ziehau static int 4281aad4de2bSSepherosa Ziehau bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS) 4282aad4de2bSSepherosa Ziehau { 4283aad4de2bSSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4284aad4de2bSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4285aad4de2bSSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4286aad4de2bSSepherosa Ziehau int error, defrag, i; 4287aad4de2bSSepherosa Ziehau 4288aad4de2bSSepherosa Ziehau if (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) 4289aad4de2bSSepherosa Ziehau defrag = 1; 4290aad4de2bSSepherosa Ziehau else 4291aad4de2bSSepherosa Ziehau defrag = 0; 4292aad4de2bSSepherosa Ziehau 4293aad4de2bSSepherosa Ziehau error = sysctl_handle_int(oidp, &defrag, 0, req); 4294aad4de2bSSepherosa Ziehau if (error || req->newptr == NULL) 4295aad4de2bSSepherosa Ziehau return error; 4296aad4de2bSSepherosa Ziehau 4297aad4de2bSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 4298aad4de2bSSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 4299aad4de2bSSepherosa Ziehau txr = &sc->bnx_tx_ring[i]; 4300aad4de2bSSepherosa Ziehau if (defrag) 4301aad4de2bSSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_FORCE_DEFRAG; 4302aad4de2bSSepherosa Ziehau else 4303aad4de2bSSepherosa Ziehau txr->bnx_tx_flags &= ~BNX_TX_FLAG_FORCE_DEFRAG; 4304aad4de2bSSepherosa Ziehau } 4305aad4de2bSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 4306aad4de2bSSepherosa Ziehau 4307aad4de2bSSepherosa Ziehau return 0; 4308aad4de2bSSepherosa Ziehau } 4309472c99c8SSepherosa Ziehau 4310472c99c8SSepherosa Ziehau static int 4311472c99c8SSepherosa Ziehau bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS) 4312472c99c8SSepherosa Ziehau { 4313472c99c8SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4314472c99c8SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4315472c99c8SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4316472c99c8SSepherosa Ziehau int error, tx_wreg, i; 4317472c99c8SSepherosa Ziehau 4318472c99c8SSepherosa Ziehau tx_wreg = txr->bnx_tx_wreg; 4319472c99c8SSepherosa Ziehau error = sysctl_handle_int(oidp, &tx_wreg, 0, req); 4320472c99c8SSepherosa Ziehau if (error || req->newptr == NULL) 4321472c99c8SSepherosa Ziehau return error; 4322472c99c8SSepherosa Ziehau 4323472c99c8SSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 4324472c99c8SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 4325472c99c8SSepherosa Ziehau sc->bnx_tx_ring[i].bnx_tx_wreg = tx_wreg; 4326472c99c8SSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 4327472c99c8SSepherosa Ziehau 4328472c99c8SSepherosa Ziehau return 0; 4329472c99c8SSepherosa Ziehau } 4330beedf5beSSepherosa Ziehau 4331beedf5beSSepherosa Ziehau static int 4332beedf5beSSepherosa Ziehau bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4333beedf5beSSepherosa Ziehau { 4334beedf5beSSepherosa Ziehau int error; 4335beedf5beSSepherosa Ziehau 4336beedf5beSSepherosa Ziehau /* 4337beedf5beSSepherosa Ziehau * Create DMA stuffs for RX return ring. 4338beedf5beSSepherosa Ziehau */ 4339beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(ret->bnx_sc, 4340beedf5beSSepherosa Ziehau BGE_RX_RTN_RING_SZ(BNX_RETURN_RING_CNT), 4341beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_tag, 4342beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_map, 4343beedf5beSSepherosa Ziehau (void *)&ret->bnx_rx_ret_ring, 4344beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_paddr); 4345beedf5beSSepherosa Ziehau if (error) { 4346beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4347beedf5beSSepherosa Ziehau "could not create RX ret ring\n"); 4348beedf5beSSepherosa Ziehau return error; 4349beedf5beSSepherosa Ziehau } 4350beedf5beSSepherosa Ziehau 4351beedf5beSSepherosa Ziehau /* Shadow standard ring's RX mbuf DMA tag */ 4352beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = ret->bnx_std->bnx_rx_mtag; 4353beedf5beSSepherosa Ziehau 4354beedf5beSSepherosa Ziehau /* 4355beedf5beSSepherosa Ziehau * Create tmp DMA map for RX mbufs. 4356beedf5beSSepherosa Ziehau */ 4357beedf5beSSepherosa Ziehau error = bus_dmamap_create(ret->bnx_rx_mtag, BUS_DMA_WAITOK, 4358beedf5beSSepherosa Ziehau &ret->bnx_rx_tmpmap); 4359beedf5beSSepherosa Ziehau if (error) { 4360beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4361beedf5beSSepherosa Ziehau "could not create tmp RX mbuf DMA map\n"); 4362beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = NULL; 4363beedf5beSSepherosa Ziehau return error; 4364beedf5beSSepherosa Ziehau } 4365beedf5beSSepherosa Ziehau return 0; 4366beedf5beSSepherosa Ziehau } 4367beedf5beSSepherosa Ziehau 4368beedf5beSSepherosa Ziehau static void 4369beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4370beedf5beSSepherosa Ziehau { 4371beedf5beSSepherosa Ziehau /* Destroy tmp RX mbuf DMA map */ 4372beedf5beSSepherosa Ziehau if (ret->bnx_rx_mtag != NULL) 4373beedf5beSSepherosa Ziehau bus_dmamap_destroy(ret->bnx_rx_mtag, ret->bnx_rx_tmpmap); 4374beedf5beSSepherosa Ziehau 4375beedf5beSSepherosa Ziehau /* Destroy RX return ring */ 4376beedf5beSSepherosa Ziehau bnx_dma_block_free(ret->bnx_rx_ret_ring_tag, 4377beedf5beSSepherosa Ziehau ret->bnx_rx_ret_ring_map, ret->bnx_rx_ret_ring); 4378beedf5beSSepherosa Ziehau } 43790c7da01dSSepherosa Ziehau 43800c7da01dSSepherosa Ziehau static int 43810c7da01dSSepherosa Ziehau bnx_alloc_intr(struct bnx_softc *sc) 43820c7da01dSSepherosa Ziehau { 43830c7da01dSSepherosa Ziehau u_int intr_flags; 43840c7da01dSSepherosa Ziehau 43850c7da01dSSepherosa Ziehau sc->bnx_irq_type = pci_alloc_1intr(sc->bnx_dev, bnx_msi_enable, 43860c7da01dSSepherosa Ziehau &sc->bnx_irq_rid, &intr_flags); 43870c7da01dSSepherosa Ziehau 43880c7da01dSSepherosa Ziehau sc->bnx_irq = bus_alloc_resource_any(sc->bnx_dev, SYS_RES_IRQ, 43890c7da01dSSepherosa Ziehau &sc->bnx_irq_rid, intr_flags); 43900c7da01dSSepherosa Ziehau if (sc->bnx_irq == NULL) { 43910c7da01dSSepherosa Ziehau device_printf(sc->bnx_dev, "could not alloc interrupt\n"); 43920c7da01dSSepherosa Ziehau return ENXIO; 43930c7da01dSSepherosa Ziehau } 43940c7da01dSSepherosa Ziehau 43950c7da01dSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 43960c7da01dSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_ONESHOT_MSI; 43970c7da01dSSepherosa Ziehau bnx_enable_msi(sc); 43980c7da01dSSepherosa Ziehau } 43990c7da01dSSepherosa Ziehau return 0; 44000c7da01dSSepherosa Ziehau } 44010c7da01dSSepherosa Ziehau 44020c7da01dSSepherosa Ziehau static int 44030c7da01dSSepherosa Ziehau bnx_setup_intr(struct bnx_softc *sc) 44040c7da01dSSepherosa Ziehau { 44050c7da01dSSepherosa Ziehau driver_intr_t *intr_func; 44060c7da01dSSepherosa Ziehau int error; 44070c7da01dSSepherosa Ziehau 44080c7da01dSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 44090c7da01dSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 44100c7da01dSSepherosa Ziehau intr_func = bnx_msi_oneshot; 44110c7da01dSSepherosa Ziehau if (bootverbose) 44120c7da01dSSepherosa Ziehau device_printf(sc->bnx_dev, "oneshot MSI\n"); 44130c7da01dSSepherosa Ziehau } else { 44140c7da01dSSepherosa Ziehau intr_func = bnx_msi; 44150c7da01dSSepherosa Ziehau } 44160c7da01dSSepherosa Ziehau } else { 44170c7da01dSSepherosa Ziehau intr_func = bnx_intr_legacy; 44180c7da01dSSepherosa Ziehau } 44190c7da01dSSepherosa Ziehau error = bus_setup_intr(sc->bnx_dev, sc->bnx_irq, INTR_MPSAFE, 44200c7da01dSSepherosa Ziehau intr_func, sc, &sc->bnx_intrhand, sc->arpcom.ac_if.if_serializer); 44210c7da01dSSepherosa Ziehau if (error) { 44220c7da01dSSepherosa Ziehau device_printf(sc->bnx_dev, "could not set up irq\n"); 44230c7da01dSSepherosa Ziehau return error; 44240c7da01dSSepherosa Ziehau } 44250c7da01dSSepherosa Ziehau return 0; 44260c7da01dSSepherosa Ziehau } 44270c7da01dSSepherosa Ziehau 44280c7da01dSSepherosa Ziehau static void 44290c7da01dSSepherosa Ziehau bnx_free_intr(struct bnx_softc *sc) 44300c7da01dSSepherosa Ziehau { 44310c7da01dSSepherosa Ziehau if (sc->bnx_irq != NULL) { 44320c7da01dSSepherosa Ziehau bus_release_resource(sc->bnx_dev, SYS_RES_IRQ, 44330c7da01dSSepherosa Ziehau sc->bnx_irq_rid, sc->bnx_irq); 44340c7da01dSSepherosa Ziehau } 44350c7da01dSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) 44360c7da01dSSepherosa Ziehau pci_release_msi(sc->bnx_dev); 44370c7da01dSSepherosa Ziehau } 4438