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 *); 166f33ac8a4SSepherosa Ziehau static void bnx_teardown_intr(struct bnx_softc *, int); 167f33ac8a4SSepherosa Ziehau static void bnx_check_intr(void *); 1686c8d8eccSSepherosa Ziehau 169f0a26983SSepherosa Ziehau static void bnx_start(struct ifnet *, struct ifaltq_subque *); 1706c8d8eccSSepherosa Ziehau static int bnx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); 1716c8d8eccSSepherosa Ziehau static void bnx_init(void *); 1726c8d8eccSSepherosa Ziehau static void bnx_stop(struct bnx_softc *); 173*3397dea6SSepherosa Ziehau static void bnx_watchdog(struct ifaltq_subque *); 1746c8d8eccSSepherosa Ziehau static int bnx_ifmedia_upd(struct ifnet *); 1756c8d8eccSSepherosa Ziehau static void bnx_ifmedia_sts(struct ifnet *, struct ifmediareq *); 1766c8d8eccSSepherosa Ziehau static void bnx_tick(void *); 177329f9016SSepherosa Ziehau static void bnx_serialize(struct ifnet *, enum ifnet_serialize); 178329f9016SSepherosa Ziehau static void bnx_deserialize(struct ifnet *, enum ifnet_serialize); 179329f9016SSepherosa Ziehau static int bnx_tryserialize(struct ifnet *, enum ifnet_serialize); 180329f9016SSepherosa Ziehau #ifdef INVARIANTS 181329f9016SSepherosa Ziehau static void bnx_serialize_assert(struct ifnet *, enum ifnet_serialize, 182329f9016SSepherosa Ziehau boolean_t); 183329f9016SSepherosa Ziehau #endif 1846c8d8eccSSepherosa Ziehau 1856c8d8eccSSepherosa Ziehau static int bnx_alloc_jumbo_mem(struct bnx_softc *); 1866c8d8eccSSepherosa Ziehau static void bnx_free_jumbo_mem(struct bnx_softc *); 1876c8d8eccSSepherosa Ziehau static struct bnx_jslot 1886c8d8eccSSepherosa Ziehau *bnx_jalloc(struct bnx_softc *); 1896c8d8eccSSepherosa Ziehau static void bnx_jfree(void *); 1906c8d8eccSSepherosa Ziehau static void bnx_jref(void *); 191beedf5beSSepherosa Ziehau static int bnx_newbuf_std(struct bnx_rx_ret_ring *, int, int); 1926c8d8eccSSepherosa Ziehau static int bnx_newbuf_jumbo(struct bnx_softc *, int, int); 193beedf5beSSepherosa Ziehau static void bnx_setup_rxdesc_std(struct bnx_rx_std_ring *, int); 1946c8d8eccSSepherosa Ziehau static void bnx_setup_rxdesc_jumbo(struct bnx_softc *, int); 195beedf5beSSepherosa Ziehau static int bnx_init_rx_ring_std(struct bnx_rx_std_ring *); 196beedf5beSSepherosa Ziehau static void bnx_free_rx_ring_std(struct bnx_rx_std_ring *); 1976c8d8eccSSepherosa Ziehau static int bnx_init_rx_ring_jumbo(struct bnx_softc *); 1986c8d8eccSSepherosa Ziehau static void bnx_free_rx_ring_jumbo(struct bnx_softc *); 19933a04907SSepherosa Ziehau static void bnx_free_tx_ring(struct bnx_tx_ring *); 20033a04907SSepherosa Ziehau static int bnx_init_tx_ring(struct bnx_tx_ring *); 20133a04907SSepherosa Ziehau static int bnx_create_tx_ring(struct bnx_tx_ring *); 20233a04907SSepherosa Ziehau static void bnx_destroy_tx_ring(struct bnx_tx_ring *); 203beedf5beSSepherosa Ziehau static int bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *); 204beedf5beSSepherosa Ziehau static void bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *); 205beedf5beSSepherosa Ziehau static int bnx_dma_alloc(device_t); 2066c8d8eccSSepherosa Ziehau static void bnx_dma_free(struct bnx_softc *); 2076c8d8eccSSepherosa Ziehau static int bnx_dma_block_alloc(struct bnx_softc *, bus_size_t, 2086c8d8eccSSepherosa Ziehau bus_dma_tag_t *, bus_dmamap_t *, void **, bus_addr_t *); 2096c8d8eccSSepherosa Ziehau static void bnx_dma_block_free(bus_dma_tag_t, bus_dmamap_t, void *); 2106c8d8eccSSepherosa Ziehau static struct mbuf * 2116c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *); 21233a04907SSepherosa Ziehau static int bnx_encap(struct bnx_tx_ring *, struct mbuf **, 213c9b7f592SSepherosa Ziehau uint32_t *, int *); 21433a04907SSepherosa Ziehau static int bnx_setup_tso(struct bnx_tx_ring *, struct mbuf **, 21566deb1c1SSepherosa Ziehau uint16_t *, uint16_t *); 216329f9016SSepherosa Ziehau static void bnx_setup_serialize(struct bnx_softc *); 2176c8d8eccSSepherosa Ziehau 2186c8d8eccSSepherosa Ziehau static void bnx_reset(struct bnx_softc *); 2196c8d8eccSSepherosa Ziehau static int bnx_chipinit(struct bnx_softc *); 2206c8d8eccSSepherosa Ziehau static int bnx_blockinit(struct bnx_softc *); 2216c8d8eccSSepherosa Ziehau static void bnx_stop_block(struct bnx_softc *, bus_size_t, uint32_t); 2226c8d8eccSSepherosa Ziehau static void bnx_enable_msi(struct bnx_softc *sc); 2236c8d8eccSSepherosa Ziehau static void bnx_setmulti(struct bnx_softc *); 2246c8d8eccSSepherosa Ziehau static void bnx_setpromisc(struct bnx_softc *); 2256c8d8eccSSepherosa Ziehau static void bnx_stats_update_regs(struct bnx_softc *); 2266c8d8eccSSepherosa Ziehau static uint32_t bnx_dma_swap_options(struct bnx_softc *); 2276c8d8eccSSepherosa Ziehau 2286c8d8eccSSepherosa Ziehau static uint32_t bnx_readmem_ind(struct bnx_softc *, uint32_t); 2296c8d8eccSSepherosa Ziehau static void bnx_writemem_ind(struct bnx_softc *, uint32_t, uint32_t); 2306c8d8eccSSepherosa Ziehau #ifdef notdef 2316c8d8eccSSepherosa Ziehau static uint32_t bnx_readreg_ind(struct bnx_softc *, uint32_t); 2326c8d8eccSSepherosa Ziehau #endif 2336c8d8eccSSepherosa Ziehau static void bnx_writemem_direct(struct bnx_softc *, uint32_t, uint32_t); 2346c8d8eccSSepherosa Ziehau static void bnx_writembx(struct bnx_softc *, int, int); 2356c8d8eccSSepherosa Ziehau static int bnx_read_nvram(struct bnx_softc *, caddr_t, int, int); 2366c8d8eccSSepherosa Ziehau static uint8_t bnx_eeprom_getbyte(struct bnx_softc *, uint32_t, uint8_t *); 2376c8d8eccSSepherosa Ziehau static int bnx_read_eeprom(struct bnx_softc *, caddr_t, uint32_t, size_t); 2386c8d8eccSSepherosa Ziehau 2396c8d8eccSSepherosa Ziehau static void bnx_tbi_link_upd(struct bnx_softc *, uint32_t); 2406c8d8eccSSepherosa Ziehau static void bnx_copper_link_upd(struct bnx_softc *, uint32_t); 2416c8d8eccSSepherosa Ziehau static void bnx_autopoll_link_upd(struct bnx_softc *, uint32_t); 2426c8d8eccSSepherosa Ziehau static void bnx_link_poll(struct bnx_softc *); 2436c8d8eccSSepherosa Ziehau 2446c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_mem(struct bnx_softc *, uint8_t[]); 2456c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_nvram(struct bnx_softc *, uint8_t[]); 2466c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_eeprom(struct bnx_softc *, uint8_t[]); 2476c8d8eccSSepherosa Ziehau static int bnx_get_eaddr(struct bnx_softc *, uint8_t[]); 2486c8d8eccSSepherosa Ziehau 2496c8d8eccSSepherosa Ziehau static void bnx_coal_change(struct bnx_softc *); 250aad4de2bSSepherosa Ziehau static int bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS); 251472c99c8SSepherosa Ziehau static int bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS); 2526c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS); 2536c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS); 2546c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS); 2556c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS); 2566c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2576c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2586c8d8eccSSepherosa Ziehau static int bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *, 2596c8d8eccSSepherosa Ziehau int, int, uint32_t); 2606c8d8eccSSepherosa Ziehau 2616c8d8eccSSepherosa Ziehau static int bnx_msi_enable = 1; 2626c8d8eccSSepherosa Ziehau TUNABLE_INT("hw.bnx.msi.enable", &bnx_msi_enable); 2636c8d8eccSSepherosa Ziehau 2646c8d8eccSSepherosa Ziehau static device_method_t bnx_methods[] = { 2656c8d8eccSSepherosa Ziehau /* Device interface */ 2666c8d8eccSSepherosa Ziehau DEVMETHOD(device_probe, bnx_probe), 2676c8d8eccSSepherosa Ziehau DEVMETHOD(device_attach, bnx_attach), 2686c8d8eccSSepherosa Ziehau DEVMETHOD(device_detach, bnx_detach), 2696c8d8eccSSepherosa Ziehau DEVMETHOD(device_shutdown, bnx_shutdown), 2706c8d8eccSSepherosa Ziehau DEVMETHOD(device_suspend, bnx_suspend), 2716c8d8eccSSepherosa Ziehau DEVMETHOD(device_resume, bnx_resume), 2726c8d8eccSSepherosa Ziehau 2736c8d8eccSSepherosa Ziehau /* bus interface */ 2746c8d8eccSSepherosa Ziehau DEVMETHOD(bus_print_child, bus_generic_print_child), 2756c8d8eccSSepherosa Ziehau DEVMETHOD(bus_driver_added, bus_generic_driver_added), 2766c8d8eccSSepherosa Ziehau 2776c8d8eccSSepherosa Ziehau /* MII interface */ 2786c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_readreg, bnx_miibus_readreg), 2796c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_writereg, bnx_miibus_writereg), 2806c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_statchg, bnx_miibus_statchg), 2816c8d8eccSSepherosa Ziehau 282d3c9c58eSSascha Wildner DEVMETHOD_END 2836c8d8eccSSepherosa Ziehau }; 2846c8d8eccSSepherosa Ziehau 2856c8d8eccSSepherosa Ziehau static DEFINE_CLASS_0(bnx, bnx_driver, bnx_methods, sizeof(struct bnx_softc)); 2866c8d8eccSSepherosa Ziehau static devclass_t bnx_devclass; 2876c8d8eccSSepherosa Ziehau 2886c8d8eccSSepherosa Ziehau DECLARE_DUMMY_MODULE(if_bnx); 2896c8d8eccSSepherosa Ziehau DRIVER_MODULE(if_bnx, pci, bnx_driver, bnx_devclass, NULL, NULL); 2906c8d8eccSSepherosa Ziehau DRIVER_MODULE(miibus, bnx, miibus_driver, miibus_devclass, NULL, NULL); 2916c8d8eccSSepherosa Ziehau 2926c8d8eccSSepherosa Ziehau static uint32_t 2936c8d8eccSSepherosa Ziehau bnx_readmem_ind(struct bnx_softc *sc, uint32_t off) 2946c8d8eccSSepherosa Ziehau { 2956c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 2966c8d8eccSSepherosa Ziehau uint32_t val; 2976c8d8eccSSepherosa Ziehau 2986c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 2996c8d8eccSSepherosa Ziehau val = pci_read_config(dev, BGE_PCI_MEMWIN_DATA, 4); 3006c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 3016c8d8eccSSepherosa Ziehau return (val); 3026c8d8eccSSepherosa Ziehau } 3036c8d8eccSSepherosa Ziehau 3046c8d8eccSSepherosa Ziehau static void 3056c8d8eccSSepherosa Ziehau bnx_writemem_ind(struct bnx_softc *sc, uint32_t off, uint32_t val) 3066c8d8eccSSepherosa Ziehau { 3076c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 3086c8d8eccSSepherosa Ziehau 3096c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 3106c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_DATA, val, 4); 3116c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 3126c8d8eccSSepherosa Ziehau } 3136c8d8eccSSepherosa Ziehau 3146c8d8eccSSepherosa Ziehau static void 3156c8d8eccSSepherosa Ziehau bnx_writemem_direct(struct bnx_softc *sc, uint32_t off, uint32_t val) 3166c8d8eccSSepherosa Ziehau { 3176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3186c8d8eccSSepherosa Ziehau } 3196c8d8eccSSepherosa Ziehau 3206c8d8eccSSepherosa Ziehau static void 3216c8d8eccSSepherosa Ziehau bnx_writembx(struct bnx_softc *sc, int off, int val) 3226c8d8eccSSepherosa Ziehau { 3236c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3246c8d8eccSSepherosa Ziehau } 3256c8d8eccSSepherosa Ziehau 3266c8d8eccSSepherosa Ziehau /* 3276c8d8eccSSepherosa Ziehau * Read a sequence of bytes from NVRAM. 3286c8d8eccSSepherosa Ziehau */ 3296c8d8eccSSepherosa Ziehau static int 3306c8d8eccSSepherosa Ziehau bnx_read_nvram(struct bnx_softc *sc, caddr_t dest, int off, int cnt) 3316c8d8eccSSepherosa Ziehau { 3326c8d8eccSSepherosa Ziehau return (1); 3336c8d8eccSSepherosa Ziehau } 3346c8d8eccSSepherosa Ziehau 3356c8d8eccSSepherosa Ziehau /* 3366c8d8eccSSepherosa Ziehau * Read a byte of data stored in the EEPROM at address 'addr.' The 3376c8d8eccSSepherosa Ziehau * BCM570x supports both the traditional bitbang interface and an 3386c8d8eccSSepherosa Ziehau * auto access interface for reading the EEPROM. We use the auto 3396c8d8eccSSepherosa Ziehau * access method. 3406c8d8eccSSepherosa Ziehau */ 3416c8d8eccSSepherosa Ziehau static uint8_t 3426c8d8eccSSepherosa Ziehau bnx_eeprom_getbyte(struct bnx_softc *sc, uint32_t addr, uint8_t *dest) 3436c8d8eccSSepherosa Ziehau { 3446c8d8eccSSepherosa Ziehau int i; 3456c8d8eccSSepherosa Ziehau uint32_t byte = 0; 3466c8d8eccSSepherosa Ziehau 3476c8d8eccSSepherosa Ziehau /* 3486c8d8eccSSepherosa Ziehau * Enable use of auto EEPROM access so we can avoid 3496c8d8eccSSepherosa Ziehau * having to use the bitbang method. 3506c8d8eccSSepherosa Ziehau */ 3516c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_AUTO_EEPROM); 3526c8d8eccSSepherosa Ziehau 3536c8d8eccSSepherosa Ziehau /* Reset the EEPROM, load the clock period. */ 3546c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, 3556c8d8eccSSepherosa Ziehau BGE_EEADDR_RESET|BGE_EEHALFCLK(BGE_HALFCLK_384SCL)); 3566c8d8eccSSepherosa Ziehau DELAY(20); 3576c8d8eccSSepherosa Ziehau 3586c8d8eccSSepherosa Ziehau /* Issue the read EEPROM command. */ 3596c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, BGE_EE_READCMD | addr); 3606c8d8eccSSepherosa Ziehau 3616c8d8eccSSepherosa Ziehau /* Wait for completion */ 3626c8d8eccSSepherosa Ziehau for(i = 0; i < BNX_TIMEOUT * 10; i++) { 3636c8d8eccSSepherosa Ziehau DELAY(10); 3646c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_EE_ADDR) & BGE_EEADDR_DONE) 3656c8d8eccSSepherosa Ziehau break; 3666c8d8eccSSepherosa Ziehau } 3676c8d8eccSSepherosa Ziehau 3686c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 3696c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "eeprom read timed out\n"); 3706c8d8eccSSepherosa Ziehau return(1); 3716c8d8eccSSepherosa Ziehau } 3726c8d8eccSSepherosa Ziehau 3736c8d8eccSSepherosa Ziehau /* Get result. */ 3746c8d8eccSSepherosa Ziehau byte = CSR_READ_4(sc, BGE_EE_DATA); 3756c8d8eccSSepherosa Ziehau 3766c8d8eccSSepherosa Ziehau *dest = (byte >> ((addr % 4) * 8)) & 0xFF; 3776c8d8eccSSepherosa Ziehau 3786c8d8eccSSepherosa Ziehau return(0); 3796c8d8eccSSepherosa Ziehau } 3806c8d8eccSSepherosa Ziehau 3816c8d8eccSSepherosa Ziehau /* 3826c8d8eccSSepherosa Ziehau * Read a sequence of bytes from the EEPROM. 3836c8d8eccSSepherosa Ziehau */ 3846c8d8eccSSepherosa Ziehau static int 3856c8d8eccSSepherosa Ziehau bnx_read_eeprom(struct bnx_softc *sc, caddr_t dest, uint32_t off, size_t len) 3866c8d8eccSSepherosa Ziehau { 3876c8d8eccSSepherosa Ziehau size_t i; 3886c8d8eccSSepherosa Ziehau int err; 3896c8d8eccSSepherosa Ziehau uint8_t byte; 3906c8d8eccSSepherosa Ziehau 3916c8d8eccSSepherosa Ziehau for (byte = 0, err = 0, i = 0; i < len; i++) { 3926c8d8eccSSepherosa Ziehau err = bnx_eeprom_getbyte(sc, off + i, &byte); 3936c8d8eccSSepherosa Ziehau if (err) 3946c8d8eccSSepherosa Ziehau break; 3956c8d8eccSSepherosa Ziehau *(dest + i) = byte; 3966c8d8eccSSepherosa Ziehau } 3976c8d8eccSSepherosa Ziehau 3986c8d8eccSSepherosa Ziehau return(err ? 1 : 0); 3996c8d8eccSSepherosa Ziehau } 4006c8d8eccSSepherosa Ziehau 4016c8d8eccSSepherosa Ziehau static int 4026c8d8eccSSepherosa Ziehau bnx_miibus_readreg(device_t dev, int phy, int reg) 4036c8d8eccSSepherosa Ziehau { 4046c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4056c8d8eccSSepherosa Ziehau uint32_t val; 4066c8d8eccSSepherosa Ziehau int i; 4076c8d8eccSSepherosa Ziehau 4086c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4096c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4106c8d8eccSSepherosa Ziehau 4116c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4126c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4146c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4156c8d8eccSSepherosa Ziehau DELAY(80); 4166c8d8eccSSepherosa Ziehau } 4176c8d8eccSSepherosa Ziehau 4186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ | BGE_MICOMM_BUSY | 4196c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg)); 4206c8d8eccSSepherosa Ziehau 4216c8d8eccSSepherosa Ziehau /* Poll for the PHY register access to complete. */ 4226c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4236c8d8eccSSepherosa Ziehau DELAY(10); 4246c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4256c8d8eccSSepherosa Ziehau if ((val & BGE_MICOMM_BUSY) == 0) { 4266c8d8eccSSepherosa Ziehau DELAY(5); 4276c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4286c8d8eccSSepherosa Ziehau break; 4296c8d8eccSSepherosa Ziehau } 4306c8d8eccSSepherosa Ziehau } 4316c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4326c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY read timed out " 4336c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val 0x%08x)\n", phy, reg, val); 4346c8d8eccSSepherosa Ziehau val = 0; 4356c8d8eccSSepherosa Ziehau } 4366c8d8eccSSepherosa Ziehau 4376c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4386c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 4406c8d8eccSSepherosa Ziehau DELAY(80); 4416c8d8eccSSepherosa Ziehau } 4426c8d8eccSSepherosa Ziehau 4436c8d8eccSSepherosa Ziehau if (val & BGE_MICOMM_READFAIL) 4446c8d8eccSSepherosa Ziehau return 0; 4456c8d8eccSSepherosa Ziehau 4466c8d8eccSSepherosa Ziehau return (val & 0xFFFF); 4476c8d8eccSSepherosa Ziehau } 4486c8d8eccSSepherosa Ziehau 4496c8d8eccSSepherosa Ziehau static int 4506c8d8eccSSepherosa Ziehau bnx_miibus_writereg(device_t dev, int phy, int reg, int val) 4516c8d8eccSSepherosa Ziehau { 4526c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4536c8d8eccSSepherosa Ziehau int i; 4546c8d8eccSSepherosa Ziehau 4556c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4566c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4576c8d8eccSSepherosa Ziehau 4586c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4596c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4606c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4616c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4626c8d8eccSSepherosa Ziehau DELAY(80); 4636c8d8eccSSepherosa Ziehau } 4646c8d8eccSSepherosa Ziehau 4656c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY | 4666c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg) | val); 4676c8d8eccSSepherosa Ziehau 4686c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4696c8d8eccSSepherosa Ziehau DELAY(10); 4706c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) { 4716c8d8eccSSepherosa Ziehau DELAY(5); 4726c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */ 4736c8d8eccSSepherosa Ziehau break; 4746c8d8eccSSepherosa Ziehau } 4756c8d8eccSSepherosa Ziehau } 4766c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4776c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY write timed out " 4786c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val %d)\n", phy, reg, val); 4796c8d8eccSSepherosa Ziehau } 4806c8d8eccSSepherosa Ziehau 4816c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4826c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 4846c8d8eccSSepherosa Ziehau DELAY(80); 4856c8d8eccSSepherosa Ziehau } 4866c8d8eccSSepherosa Ziehau 4876c8d8eccSSepherosa Ziehau return 0; 4886c8d8eccSSepherosa Ziehau } 4896c8d8eccSSepherosa Ziehau 4906c8d8eccSSepherosa Ziehau static void 4916c8d8eccSSepherosa Ziehau bnx_miibus_statchg(device_t dev) 4926c8d8eccSSepherosa Ziehau { 4936c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 4946c8d8eccSSepherosa Ziehau struct mii_data *mii; 4956c8d8eccSSepherosa Ziehau 4966c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 4976c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 4986c8d8eccSSepherosa Ziehau 4996c8d8eccSSepherosa Ziehau if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 5006c8d8eccSSepherosa Ziehau (IFM_ACTIVE | IFM_AVALID)) { 5016c8d8eccSSepherosa Ziehau switch (IFM_SUBTYPE(mii->mii_media_active)) { 5026c8d8eccSSepherosa Ziehau case IFM_10_T: 5036c8d8eccSSepherosa Ziehau case IFM_100_TX: 5046c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5056c8d8eccSSepherosa Ziehau break; 5066c8d8eccSSepherosa Ziehau case IFM_1000_T: 5076c8d8eccSSepherosa Ziehau case IFM_1000_SX: 5086c8d8eccSSepherosa Ziehau case IFM_2500_SX: 5096c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5106c8d8eccSSepherosa Ziehau break; 5116c8d8eccSSepherosa Ziehau default: 5126c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5136c8d8eccSSepherosa Ziehau break; 5146c8d8eccSSepherosa Ziehau } 5156c8d8eccSSepherosa Ziehau } else { 5166c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5176c8d8eccSSepherosa Ziehau } 5186c8d8eccSSepherosa Ziehau if (sc->bnx_link == 0) 5196c8d8eccSSepherosa Ziehau return; 5206c8d8eccSSepherosa Ziehau 5216c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); 5226c8d8eccSSepherosa Ziehau if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T || 5236c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) { 5246c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); 5256c8d8eccSSepherosa Ziehau } else { 5266c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII); 5276c8d8eccSSepherosa Ziehau } 5286c8d8eccSSepherosa Ziehau 5296c8d8eccSSepherosa Ziehau if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 5306c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5316c8d8eccSSepherosa Ziehau } else { 5326c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5336c8d8eccSSepherosa Ziehau } 5346c8d8eccSSepherosa Ziehau } 5356c8d8eccSSepherosa Ziehau 5366c8d8eccSSepherosa Ziehau /* 5376c8d8eccSSepherosa Ziehau * Memory management for jumbo frames. 5386c8d8eccSSepherosa Ziehau */ 5396c8d8eccSSepherosa Ziehau static int 5406c8d8eccSSepherosa Ziehau bnx_alloc_jumbo_mem(struct bnx_softc *sc) 5416c8d8eccSSepherosa Ziehau { 5426c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 5436c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 5446c8d8eccSSepherosa Ziehau uint8_t *ptr; 5456c8d8eccSSepherosa Ziehau bus_addr_t paddr; 5466c8d8eccSSepherosa Ziehau int i, error; 5476c8d8eccSSepherosa Ziehau 5486c8d8eccSSepherosa Ziehau /* 5496c8d8eccSSepherosa Ziehau * Create tag for jumbo mbufs. 5506c8d8eccSSepherosa Ziehau * This is really a bit of a kludge. We allocate a special 5516c8d8eccSSepherosa Ziehau * jumbo buffer pool which (thanks to the way our DMA 5526c8d8eccSSepherosa Ziehau * memory allocation works) will consist of contiguous 5536c8d8eccSSepherosa Ziehau * pages. This means that even though a jumbo buffer might 5546c8d8eccSSepherosa Ziehau * be larger than a page size, we don't really need to 5556c8d8eccSSepherosa Ziehau * map it into more than one DMA segment. However, the 5566c8d8eccSSepherosa Ziehau * default mbuf tag will result in multi-segment mappings, 5576c8d8eccSSepherosa Ziehau * so we have to create a special jumbo mbuf tag that 5586c8d8eccSSepherosa Ziehau * lets us get away with mapping the jumbo buffers as 5596c8d8eccSSepherosa Ziehau * a single segment. I think eventually the driver should 5606c8d8eccSSepherosa Ziehau * be changed so that it uses ordinary mbufs and cluster 5616c8d8eccSSepherosa Ziehau * buffers, i.e. jumbo frames can span multiple DMA 5626c8d8eccSSepherosa Ziehau * descriptors. But that's a project for another day. 5636c8d8eccSSepherosa Ziehau */ 5646c8d8eccSSepherosa Ziehau 5656c8d8eccSSepherosa Ziehau /* 5666c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo RX ring. 5676c8d8eccSSepherosa Ziehau */ 5686c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_JUMBO_RX_RING_SZ, 5696c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 5706c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_map, 5716c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_jumbo_ring, 5726c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 5736c8d8eccSSepherosa Ziehau if (error) { 5746c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo RX ring\n"); 5756c8d8eccSSepherosa Ziehau return error; 5766c8d8eccSSepherosa Ziehau } 5776c8d8eccSSepherosa Ziehau 5786c8d8eccSSepherosa Ziehau /* 5796c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo buffer block. 5806c8d8eccSSepherosa Ziehau */ 5816c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BNX_JMEM, 5826c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_tag, 5836c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_map, 5846c8d8eccSSepherosa Ziehau (void **)&sc->bnx_ldata.bnx_jumbo_buf, 5856c8d8eccSSepherosa Ziehau &paddr); 5866c8d8eccSSepherosa Ziehau if (error) { 5876c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo buffer\n"); 5886c8d8eccSSepherosa Ziehau return error; 5896c8d8eccSSepherosa Ziehau } 5906c8d8eccSSepherosa Ziehau 5916c8d8eccSSepherosa Ziehau SLIST_INIT(&sc->bnx_jfree_listhead); 5926c8d8eccSSepherosa Ziehau 5936c8d8eccSSepherosa Ziehau /* 5946c8d8eccSSepherosa Ziehau * Now divide it up into 9K pieces and save the addresses 5956c8d8eccSSepherosa Ziehau * in an array. Note that we play an evil trick here by using 5966c8d8eccSSepherosa Ziehau * the first few bytes in the buffer to hold the the address 5976c8d8eccSSepherosa Ziehau * of the softc structure for this interface. This is because 5986c8d8eccSSepherosa Ziehau * bnx_jfree() needs it, but it is called by the mbuf management 5996c8d8eccSSepherosa Ziehau * code which will not pass it to us explicitly. 6006c8d8eccSSepherosa Ziehau */ 6016c8d8eccSSepherosa Ziehau for (i = 0, ptr = sc->bnx_ldata.bnx_jumbo_buf; i < BNX_JSLOTS; i++) { 6026c8d8eccSSepherosa Ziehau entry = &sc->bnx_cdata.bnx_jslots[i]; 6036c8d8eccSSepherosa Ziehau entry->bnx_sc = sc; 6046c8d8eccSSepherosa Ziehau entry->bnx_buf = ptr; 6056c8d8eccSSepherosa Ziehau entry->bnx_paddr = paddr; 6066c8d8eccSSepherosa Ziehau entry->bnx_inuse = 0; 6076c8d8eccSSepherosa Ziehau entry->bnx_slot = i; 6086c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, entry, jslot_link); 6096c8d8eccSSepherosa Ziehau 6106c8d8eccSSepherosa Ziehau ptr += BNX_JLEN; 6116c8d8eccSSepherosa Ziehau paddr += BNX_JLEN; 6126c8d8eccSSepherosa Ziehau } 6136c8d8eccSSepherosa Ziehau return 0; 6146c8d8eccSSepherosa Ziehau } 6156c8d8eccSSepherosa Ziehau 6166c8d8eccSSepherosa Ziehau static void 6176c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(struct bnx_softc *sc) 6186c8d8eccSSepherosa Ziehau { 6196c8d8eccSSepherosa Ziehau /* Destroy jumbo RX ring. */ 6206c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 6216c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_ring_map, 6226c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_jumbo_ring); 6236c8d8eccSSepherosa Ziehau 6246c8d8eccSSepherosa Ziehau /* Destroy jumbo buffer block. */ 6256c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_jumbo_tag, 6266c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_jumbo_map, 6276c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_jumbo_buf); 6286c8d8eccSSepherosa Ziehau } 6296c8d8eccSSepherosa Ziehau 6306c8d8eccSSepherosa Ziehau /* 6316c8d8eccSSepherosa Ziehau * Allocate a jumbo buffer. 6326c8d8eccSSepherosa Ziehau */ 6336c8d8eccSSepherosa Ziehau static struct bnx_jslot * 6346c8d8eccSSepherosa Ziehau bnx_jalloc(struct bnx_softc *sc) 6356c8d8eccSSepherosa Ziehau { 6366c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 6376c8d8eccSSepherosa Ziehau 6386c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 6396c8d8eccSSepherosa Ziehau entry = SLIST_FIRST(&sc->bnx_jfree_listhead); 6406c8d8eccSSepherosa Ziehau if (entry) { 6416c8d8eccSSepherosa Ziehau SLIST_REMOVE_HEAD(&sc->bnx_jfree_listhead, jslot_link); 6426c8d8eccSSepherosa Ziehau entry->bnx_inuse = 1; 6436c8d8eccSSepherosa Ziehau } else { 6446c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "no free jumbo buffers\n"); 6456c8d8eccSSepherosa Ziehau } 6466c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 6476c8d8eccSSepherosa Ziehau return(entry); 6486c8d8eccSSepherosa Ziehau } 6496c8d8eccSSepherosa Ziehau 6506c8d8eccSSepherosa Ziehau /* 6516c8d8eccSSepherosa Ziehau * Adjust usage count on a jumbo buffer. 6526c8d8eccSSepherosa Ziehau */ 6536c8d8eccSSepherosa Ziehau static void 6546c8d8eccSSepherosa Ziehau bnx_jref(void *arg) 6556c8d8eccSSepherosa Ziehau { 6566c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6576c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6586c8d8eccSSepherosa Ziehau 6596c8d8eccSSepherosa Ziehau if (sc == NULL) 6606c8d8eccSSepherosa Ziehau panic("bnx_jref: can't find softc pointer!"); 6616c8d8eccSSepherosa Ziehau 6626c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 6636c8d8eccSSepherosa Ziehau panic("bnx_jref: asked to reference buffer " 6646c8d8eccSSepherosa Ziehau "that we don't manage!"); 6656c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 6666c8d8eccSSepherosa Ziehau panic("bnx_jref: buffer already free!"); 6676c8d8eccSSepherosa Ziehau } else { 6686c8d8eccSSepherosa Ziehau atomic_add_int(&entry->bnx_inuse, 1); 6696c8d8eccSSepherosa Ziehau } 6706c8d8eccSSepherosa Ziehau } 6716c8d8eccSSepherosa Ziehau 6726c8d8eccSSepherosa Ziehau /* 6736c8d8eccSSepherosa Ziehau * Release a jumbo buffer. 6746c8d8eccSSepherosa Ziehau */ 6756c8d8eccSSepherosa Ziehau static void 6766c8d8eccSSepherosa Ziehau bnx_jfree(void *arg) 6776c8d8eccSSepherosa Ziehau { 6786c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6796c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6806c8d8eccSSepherosa Ziehau 6816c8d8eccSSepherosa Ziehau if (sc == NULL) 6826c8d8eccSSepherosa Ziehau panic("bnx_jfree: can't find softc pointer!"); 6836c8d8eccSSepherosa Ziehau 6846c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 6856c8d8eccSSepherosa Ziehau panic("bnx_jfree: asked to free buffer that we don't manage!"); 6866c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 6876c8d8eccSSepherosa Ziehau panic("bnx_jfree: buffer already free!"); 6886c8d8eccSSepherosa Ziehau } else { 6896c8d8eccSSepherosa Ziehau /* 6906c8d8eccSSepherosa Ziehau * Possible MP race to 0, use the serializer. The atomic insn 6916c8d8eccSSepherosa Ziehau * is still needed for races against bnx_jref(). 6926c8d8eccSSepherosa Ziehau */ 6936c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 6946c8d8eccSSepherosa Ziehau atomic_subtract_int(&entry->bnx_inuse, 1); 6956c8d8eccSSepherosa Ziehau if (entry->bnx_inuse == 0) { 6966c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, 6976c8d8eccSSepherosa Ziehau entry, jslot_link); 6986c8d8eccSSepherosa Ziehau } 6996c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 7006c8d8eccSSepherosa Ziehau } 7016c8d8eccSSepherosa Ziehau } 7026c8d8eccSSepherosa Ziehau 7036c8d8eccSSepherosa Ziehau 7046c8d8eccSSepherosa Ziehau /* 7056c8d8eccSSepherosa Ziehau * Intialize a standard receive ring descriptor. 7066c8d8eccSSepherosa Ziehau */ 7076c8d8eccSSepherosa Ziehau static int 708beedf5beSSepherosa Ziehau bnx_newbuf_std(struct bnx_rx_ret_ring *ret, int i, int init) 7096c8d8eccSSepherosa Ziehau { 7106c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7116c8d8eccSSepherosa Ziehau bus_dma_segment_t seg; 7126c8d8eccSSepherosa Ziehau bus_dmamap_t map; 7136c8d8eccSSepherosa Ziehau int error, nsegs; 714beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb; 7156c8d8eccSSepherosa Ziehau 7166c8d8eccSSepherosa Ziehau m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR); 7176c8d8eccSSepherosa Ziehau if (m_new == NULL) 7186c8d8eccSSepherosa Ziehau return ENOBUFS; 7196c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 7206c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 7216c8d8eccSSepherosa Ziehau 722beedf5beSSepherosa Ziehau error = bus_dmamap_load_mbuf_segment(ret->bnx_rx_mtag, 723beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap, m_new, &seg, 1, &nsegs, BUS_DMA_NOWAIT); 7246c8d8eccSSepherosa Ziehau if (error) { 7256c8d8eccSSepherosa Ziehau m_freem(m_new); 7266c8d8eccSSepherosa Ziehau return error; 7276c8d8eccSSepherosa Ziehau } 7286c8d8eccSSepherosa Ziehau 729beedf5beSSepherosa Ziehau rb = &ret->bnx_std->bnx_rx_std_buf[i]; 730beedf5beSSepherosa Ziehau 7316c8d8eccSSepherosa Ziehau if (!init) { 732beedf5beSSepherosa Ziehau bus_dmamap_sync(ret->bnx_rx_mtag, rb->bnx_rx_dmamap, 7336c8d8eccSSepherosa Ziehau BUS_DMASYNC_POSTREAD); 734beedf5beSSepherosa Ziehau bus_dmamap_unload(ret->bnx_rx_mtag, rb->bnx_rx_dmamap); 7356c8d8eccSSepherosa Ziehau } 7366c8d8eccSSepherosa Ziehau 737beedf5beSSepherosa Ziehau map = ret->bnx_rx_tmpmap; 738beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap = rb->bnx_rx_dmamap; 739beedf5beSSepherosa Ziehau rb->bnx_rx_dmamap = map; 7406c8d8eccSSepherosa Ziehau 741beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = m_new; 742beedf5beSSepherosa Ziehau rb->bnx_rx_paddr = seg.ds_addr; 7436c8d8eccSSepherosa Ziehau 744beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(ret->bnx_std, i); 7456c8d8eccSSepherosa Ziehau return 0; 7466c8d8eccSSepherosa Ziehau } 7476c8d8eccSSepherosa Ziehau 7486c8d8eccSSepherosa Ziehau static void 749beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(struct bnx_rx_std_ring *std, int i) 7506c8d8eccSSepherosa Ziehau { 751beedf5beSSepherosa Ziehau const struct bnx_rx_buf *rb; 7526c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 7536c8d8eccSSepherosa Ziehau 754beedf5beSSepherosa Ziehau rb = &std->bnx_rx_std_buf[i]; 755beedf5beSSepherosa Ziehau r = &std->bnx_rx_std_ring[i]; 7566c8d8eccSSepherosa Ziehau 757beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rb->bnx_rx_paddr); 758beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rb->bnx_rx_paddr); 759beedf5beSSepherosa Ziehau r->bge_len = rb->bnx_rx_mbuf->m_len; 7606c8d8eccSSepherosa Ziehau r->bge_idx = i; 7616c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END; 7626c8d8eccSSepherosa Ziehau } 7636c8d8eccSSepherosa Ziehau 7646c8d8eccSSepherosa Ziehau /* 7656c8d8eccSSepherosa Ziehau * Initialize a jumbo receive ring descriptor. This allocates 7666c8d8eccSSepherosa Ziehau * a jumbo buffer from the pool managed internally by the driver. 7676c8d8eccSSepherosa Ziehau */ 7686c8d8eccSSepherosa Ziehau static int 7696c8d8eccSSepherosa Ziehau bnx_newbuf_jumbo(struct bnx_softc *sc, int i, int init) 7706c8d8eccSSepherosa Ziehau { 7716c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7726c8d8eccSSepherosa Ziehau struct bnx_jslot *buf; 7736c8d8eccSSepherosa Ziehau bus_addr_t paddr; 7746c8d8eccSSepherosa Ziehau 7756c8d8eccSSepherosa Ziehau /* Allocate the mbuf. */ 7766c8d8eccSSepherosa Ziehau MGETHDR(m_new, init ? MB_WAIT : MB_DONTWAIT, MT_DATA); 7776c8d8eccSSepherosa Ziehau if (m_new == NULL) 7786c8d8eccSSepherosa Ziehau return ENOBUFS; 7796c8d8eccSSepherosa Ziehau 7806c8d8eccSSepherosa Ziehau /* Allocate the jumbo buffer */ 7816c8d8eccSSepherosa Ziehau buf = bnx_jalloc(sc); 7826c8d8eccSSepherosa Ziehau if (buf == NULL) { 7836c8d8eccSSepherosa Ziehau m_freem(m_new); 7846c8d8eccSSepherosa Ziehau return ENOBUFS; 7856c8d8eccSSepherosa Ziehau } 7866c8d8eccSSepherosa Ziehau 7876c8d8eccSSepherosa Ziehau /* Attach the buffer to the mbuf. */ 7886c8d8eccSSepherosa Ziehau m_new->m_ext.ext_arg = buf; 7896c8d8eccSSepherosa Ziehau m_new->m_ext.ext_buf = buf->bnx_buf; 7906c8d8eccSSepherosa Ziehau m_new->m_ext.ext_free = bnx_jfree; 7916c8d8eccSSepherosa Ziehau m_new->m_ext.ext_ref = bnx_jref; 7926c8d8eccSSepherosa Ziehau m_new->m_ext.ext_size = BNX_JUMBO_FRAMELEN; 7936c8d8eccSSepherosa Ziehau 7946c8d8eccSSepherosa Ziehau m_new->m_flags |= M_EXT; 7956c8d8eccSSepherosa Ziehau 7966c8d8eccSSepherosa Ziehau m_new->m_data = m_new->m_ext.ext_buf; 7976c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = m_new->m_ext.ext_size; 7986c8d8eccSSepherosa Ziehau 7996c8d8eccSSepherosa Ziehau paddr = buf->bnx_paddr; 8006c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 8016c8d8eccSSepherosa Ziehau paddr += ETHER_ALIGN; 8026c8d8eccSSepherosa Ziehau 8036c8d8eccSSepherosa Ziehau /* Save necessary information */ 804beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_mbuf = m_new; 805beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_paddr = paddr; 8066c8d8eccSSepherosa Ziehau 8076c8d8eccSSepherosa Ziehau /* Set up the descriptor. */ 8086c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, i); 8096c8d8eccSSepherosa Ziehau return 0; 8106c8d8eccSSepherosa Ziehau } 8116c8d8eccSSepherosa Ziehau 8126c8d8eccSSepherosa Ziehau static void 8136c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(struct bnx_softc *sc, int i) 8146c8d8eccSSepherosa Ziehau { 8156c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 816beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc; 8176c8d8eccSSepherosa Ziehau 8186c8d8eccSSepherosa Ziehau r = &sc->bnx_ldata.bnx_rx_jumbo_ring[i]; 8196c8d8eccSSepherosa Ziehau rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8206c8d8eccSSepherosa Ziehau 821beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_rx_paddr); 822beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_rx_paddr); 823beedf5beSSepherosa Ziehau r->bge_len = rc->bnx_rx_mbuf->m_len; 8246c8d8eccSSepherosa Ziehau r->bge_idx = i; 8256c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING; 8266c8d8eccSSepherosa Ziehau } 8276c8d8eccSSepherosa Ziehau 8286c8d8eccSSepherosa Ziehau static int 829beedf5beSSepherosa Ziehau bnx_init_rx_ring_std(struct bnx_rx_std_ring *std) 8306c8d8eccSSepherosa Ziehau { 8316c8d8eccSSepherosa Ziehau int i, error; 8326c8d8eccSSepherosa Ziehau 8336c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 834beedf5beSSepherosa Ziehau /* Use the first RX return ring's tmp RX mbuf DMA map */ 835beedf5beSSepherosa Ziehau error = bnx_newbuf_std(&std->bnx_sc->bnx_rx_ret_ring[0], i, 1); 8366c8d8eccSSepherosa Ziehau if (error) 8376c8d8eccSSepherosa Ziehau return error; 83887c7a7cfSSascha Wildner } 8396c8d8eccSSepherosa Ziehau 840beedf5beSSepherosa Ziehau std->bnx_rx_std = BGE_STD_RX_RING_CNT - 1; 841beedf5beSSepherosa Ziehau bnx_writembx(std->bnx_sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std); 8426c8d8eccSSepherosa Ziehau 8436c8d8eccSSepherosa Ziehau return(0); 8446c8d8eccSSepherosa Ziehau } 8456c8d8eccSSepherosa Ziehau 8466c8d8eccSSepherosa Ziehau static void 847beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(struct bnx_rx_std_ring *std) 8486c8d8eccSSepherosa Ziehau { 8496c8d8eccSSepherosa Ziehau int i; 8506c8d8eccSSepherosa Ziehau 8516c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 852beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb = &std->bnx_rx_std_buf[i]; 8536c8d8eccSSepherosa Ziehau 854beedf5beSSepherosa Ziehau if (rb->bnx_rx_mbuf != NULL) { 855beedf5beSSepherosa Ziehau bus_dmamap_unload(std->bnx_rx_mtag, rb->bnx_rx_dmamap); 856beedf5beSSepherosa Ziehau m_freem(rb->bnx_rx_mbuf); 857beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = NULL; 8586c8d8eccSSepherosa Ziehau } 859beedf5beSSepherosa Ziehau bzero(&std->bnx_rx_std_ring[i], sizeof(struct bge_rx_bd)); 8606c8d8eccSSepherosa Ziehau } 8616c8d8eccSSepherosa Ziehau } 8626c8d8eccSSepherosa Ziehau 8636c8d8eccSSepherosa Ziehau static int 8646c8d8eccSSepherosa Ziehau bnx_init_rx_ring_jumbo(struct bnx_softc *sc) 8656c8d8eccSSepherosa Ziehau { 8666c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 8676c8d8eccSSepherosa Ziehau int i, error; 8686c8d8eccSSepherosa Ziehau 8696c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 8706c8d8eccSSepherosa Ziehau error = bnx_newbuf_jumbo(sc, i, 1); 8716c8d8eccSSepherosa Ziehau if (error) 8726c8d8eccSSepherosa Ziehau return error; 87387c7a7cfSSascha Wildner } 8746c8d8eccSSepherosa Ziehau 8756c8d8eccSSepherosa Ziehau sc->bnx_jumbo = BGE_JUMBO_RX_RING_CNT - 1; 8766c8d8eccSSepherosa Ziehau 8776c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 8786c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0); 8796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 8806c8d8eccSSepherosa Ziehau 8816c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 8826c8d8eccSSepherosa Ziehau 8836c8d8eccSSepherosa Ziehau return(0); 8846c8d8eccSSepherosa Ziehau } 8856c8d8eccSSepherosa Ziehau 8866c8d8eccSSepherosa Ziehau static void 8876c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(struct bnx_softc *sc) 8886c8d8eccSSepherosa Ziehau { 8896c8d8eccSSepherosa Ziehau int i; 8906c8d8eccSSepherosa Ziehau 8916c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 892beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8936c8d8eccSSepherosa Ziehau 894beedf5beSSepherosa Ziehau if (rc->bnx_rx_mbuf != NULL) { 895beedf5beSSepherosa Ziehau m_freem(rc->bnx_rx_mbuf); 896beedf5beSSepherosa Ziehau rc->bnx_rx_mbuf = NULL; 8976c8d8eccSSepherosa Ziehau } 8986c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_rx_jumbo_ring[i], 8996c8d8eccSSepherosa Ziehau sizeof(struct bge_rx_bd)); 9006c8d8eccSSepherosa Ziehau } 9016c8d8eccSSepherosa Ziehau } 9026c8d8eccSSepherosa Ziehau 9036c8d8eccSSepherosa Ziehau static void 90433a04907SSepherosa Ziehau bnx_free_tx_ring(struct bnx_tx_ring *txr) 9056c8d8eccSSepherosa Ziehau { 9066c8d8eccSSepherosa Ziehau int i; 9076c8d8eccSSepherosa Ziehau 9086c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 909fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf = &txr->bnx_tx_buf[i]; 910fa4b1067SSepherosa Ziehau 911fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 91233a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 913fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 914fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 915fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 9166c8d8eccSSepherosa Ziehau } 91733a04907SSepherosa Ziehau bzero(&txr->bnx_tx_ring[i], sizeof(struct bge_tx_bd)); 9186c8d8eccSSepherosa Ziehau } 91933a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = BNX_TXCONS_UNSET; 9206c8d8eccSSepherosa Ziehau } 9216c8d8eccSSepherosa Ziehau 9226c8d8eccSSepherosa Ziehau static int 92333a04907SSepherosa Ziehau bnx_init_tx_ring(struct bnx_tx_ring *txr) 9246c8d8eccSSepherosa Ziehau { 925fa639b88SSepherosa Ziehau txr->bnx_tx_cnt = 0; 92633a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = 0; 92733a04907SSepherosa Ziehau txr->bnx_tx_prodidx = 0; 9286c8d8eccSSepherosa Ziehau 9296c8d8eccSSepherosa Ziehau /* Initialize transmit producer index for host-memory send ring. */ 9308bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, txr->bnx_tx_prodidx); 9316c8d8eccSSepherosa Ziehau 9326c8d8eccSSepherosa Ziehau return(0); 9336c8d8eccSSepherosa Ziehau } 9346c8d8eccSSepherosa Ziehau 9356c8d8eccSSepherosa Ziehau static void 9366c8d8eccSSepherosa Ziehau bnx_setmulti(struct bnx_softc *sc) 9376c8d8eccSSepherosa Ziehau { 9386c8d8eccSSepherosa Ziehau struct ifnet *ifp; 9396c8d8eccSSepherosa Ziehau struct ifmultiaddr *ifma; 9406c8d8eccSSepherosa Ziehau uint32_t hashes[4] = { 0, 0, 0, 0 }; 9416c8d8eccSSepherosa Ziehau int h, i; 9426c8d8eccSSepherosa Ziehau 9436c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 9446c8d8eccSSepherosa Ziehau 9456c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 9466c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0xFFFFFFFF); 9486c8d8eccSSepherosa Ziehau return; 9496c8d8eccSSepherosa Ziehau } 9506c8d8eccSSepherosa Ziehau 9516c8d8eccSSepherosa Ziehau /* First, zot all the existing filters. */ 9526c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9536c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0); 9546c8d8eccSSepherosa Ziehau 9556c8d8eccSSepherosa Ziehau /* Now program new ones. */ 9566c8d8eccSSepherosa Ziehau TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 9576c8d8eccSSepherosa Ziehau if (ifma->ifma_addr->sa_family != AF_LINK) 9586c8d8eccSSepherosa Ziehau continue; 9596c8d8eccSSepherosa Ziehau h = ether_crc32_le( 9606c8d8eccSSepherosa Ziehau LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 9616c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN) & 0x7f; 9626c8d8eccSSepherosa Ziehau hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F); 9636c8d8eccSSepherosa Ziehau } 9646c8d8eccSSepherosa Ziehau 9656c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9666c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]); 9676c8d8eccSSepherosa Ziehau } 9686c8d8eccSSepherosa Ziehau 9696c8d8eccSSepherosa Ziehau /* 9706c8d8eccSSepherosa Ziehau * Do endian, PCI and DMA initialization. Also check the on-board ROM 9716c8d8eccSSepherosa Ziehau * self-test results. 9726c8d8eccSSepherosa Ziehau */ 9736c8d8eccSSepherosa Ziehau static int 9746c8d8eccSSepherosa Ziehau bnx_chipinit(struct bnx_softc *sc) 9756c8d8eccSSepherosa Ziehau { 9766c8d8eccSSepherosa Ziehau uint32_t dma_rw_ctl, mode_ctl; 9776c8d8eccSSepherosa Ziehau int i; 9786c8d8eccSSepherosa Ziehau 9796c8d8eccSSepherosa Ziehau /* Set endian type before we access any non-PCI registers. */ 9806c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_MISC_CTL, 9816c8d8eccSSepherosa Ziehau BGE_INIT | BGE_PCIMISCCTL_TAGGED_STATUS, 4); 9826c8d8eccSSepherosa Ziehau 9836c8d8eccSSepherosa Ziehau /* Clear the MAC control register */ 9846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 9856c8d8eccSSepherosa Ziehau 9866c8d8eccSSepherosa Ziehau /* 9876c8d8eccSSepherosa Ziehau * Clear the MAC statistics block in the NIC's 9886c8d8eccSSepherosa Ziehau * internal memory. 9896c8d8eccSSepherosa Ziehau */ 9906c8d8eccSSepherosa Ziehau for (i = BGE_STATS_BLOCK; 9916c8d8eccSSepherosa Ziehau i < BGE_STATS_BLOCK_END + 1; i += sizeof(uint32_t)) 9926c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 9936c8d8eccSSepherosa Ziehau 9946c8d8eccSSepherosa Ziehau for (i = BGE_STATUS_BLOCK; 9956c8d8eccSSepherosa Ziehau i < BGE_STATUS_BLOCK_END + 1; i += sizeof(uint32_t)) 9966c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 9976c8d8eccSSepherosa Ziehau 998d7872545SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) { 999d7872545SSepherosa Ziehau uint32_t val; 1000d7872545SSepherosa Ziehau 1001d7872545SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) { 1002d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1003d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1004d7872545SSepherosa Ziehau 1005d7872545SSepherosa Ziehau /* Access the lower 1K of PL PCI-E block registers. */ 1006d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1007d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_PL_SEL); 1008d7872545SSepherosa Ziehau 1009d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_PL_LO_PHYCTL5); 1010d7872545SSepherosa Ziehau val |= BGE_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ; 1011d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PL_LO_PHYCTL5, val); 1012d7872545SSepherosa Ziehau 1013d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1014d7872545SSepherosa Ziehau } 1015d7872545SSepherosa Ziehau if (sc->bnx_chiprev != BGE_CHIPREV_57765_AX) { 10161749651bSSepherosa Ziehau /* Fix transmit hangs */ 10171749651bSSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_PADRNG_CTL); 10181749651bSSepherosa Ziehau val |= BGE_CPMU_PADRNG_CTL_RDIV2; 10191749651bSSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_PADRNG_CTL, val); 10201749651bSSepherosa Ziehau 1021d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1022d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1023d7872545SSepherosa Ziehau 1024d7872545SSepherosa Ziehau /* Access the lower 1K of DL PCI-E block registers. */ 1025d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1026d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_DL_SEL); 1027d7872545SSepherosa Ziehau 1028d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_DL_LO_FTSMAX); 1029d7872545SSepherosa Ziehau val &= ~BGE_PCIE_DL_LO_FTSMAX_MASK; 1030d7872545SSepherosa Ziehau val |= BGE_PCIE_DL_LO_FTSMAX_VAL; 1031d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_DL_LO_FTSMAX, val); 1032d7872545SSepherosa Ziehau 1033d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1034d7872545SSepherosa Ziehau } 1035d7872545SSepherosa Ziehau 1036d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_LSPD_10MB_CLK); 1037d7872545SSepherosa Ziehau val &= ~BGE_CPMU_LSPD_10MB_MACCLK_MASK; 1038d7872545SSepherosa Ziehau val |= BGE_CPMU_LSPD_10MB_MACCLK_6_25; 1039d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_LSPD_10MB_CLK, val); 1040d7872545SSepherosa Ziehau } 1041d7872545SSepherosa Ziehau 10422890cca3SSepherosa Ziehau /* 10432890cca3SSepherosa Ziehau * Set up the PCI DMA control register. 10442890cca3SSepherosa Ziehau */ 10452890cca3SSepherosa Ziehau dma_rw_ctl = pci_read_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, 4); 10462890cca3SSepherosa Ziehau /* 10472890cca3SSepherosa Ziehau * Disable 32bytes cache alignment for DMA write to host memory 10482890cca3SSepherosa Ziehau * 10492890cca3SSepherosa Ziehau * NOTE: 10502890cca3SSepherosa Ziehau * 64bytes cache alignment for DMA write to host memory is still 10512890cca3SSepherosa Ziehau * enabled. 10522890cca3SSepherosa Ziehau */ 10532890cca3SSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT; 10546c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 10556c8d8eccSSepherosa Ziehau dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK; 10566c8d8eccSSepherosa Ziehau /* 10576c8d8eccSSepherosa Ziehau * Enable HW workaround for controllers that misinterpret 10586c8d8eccSSepherosa Ziehau * a status tag update and leave interrupts permanently 10596c8d8eccSSepherosa Ziehau * disabled. 10606c8d8eccSSepherosa Ziehau */ 10616c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5717 && 1062b96cbbb6SSepherosa Ziehau sc->bnx_asicrev != BGE_ASICREV_BCM5762 && 10632890cca3SSepherosa Ziehau !BNX_IS_57765_FAMILY(sc)) 10646c8d8eccSSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA; 10652890cca3SSepherosa Ziehau if (bootverbose) { 10662890cca3SSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "DMA read/write %#x\n", 10672890cca3SSepherosa Ziehau dma_rw_ctl); 10686c8d8eccSSepherosa Ziehau } 10696c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, dma_rw_ctl, 4); 10706c8d8eccSSepherosa Ziehau 10716c8d8eccSSepherosa Ziehau /* 10726c8d8eccSSepherosa Ziehau * Set up general mode register. 10736c8d8eccSSepherosa Ziehau */ 10746c8d8eccSSepherosa Ziehau mode_ctl = bnx_dma_swap_options(sc) | BGE_MODECTL_MAC_ATTN_INTR | 10756c8d8eccSSepherosa Ziehau BGE_MODECTL_HOST_SEND_BDS | BGE_MODECTL_TX_NO_PHDR_CSUM; 10766c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 10776c8d8eccSSepherosa Ziehau 10786c8d8eccSSepherosa Ziehau /* 10796c8d8eccSSepherosa Ziehau * Disable memory write invalidate. Apparently it is not supported 10806c8d8eccSSepherosa Ziehau * properly by these devices. Also ensure that INTx isn't disabled, 10816c8d8eccSSepherosa Ziehau * as these chips need it even when using MSI. 10826c8d8eccSSepherosa Ziehau */ 10836c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_CMD, 10846c8d8eccSSepherosa Ziehau (PCIM_CMD_MWRICEN | PCIM_CMD_INTxDIS), 4); 10856c8d8eccSSepherosa Ziehau 10866c8d8eccSSepherosa Ziehau /* Set the timer prescaler (always 66Mhz) */ 10876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, 65 << 1/*BGE_32BITTIME_66MHZ*/); 10886c8d8eccSSepherosa Ziehau 10896c8d8eccSSepherosa Ziehau return(0); 10906c8d8eccSSepherosa Ziehau } 10916c8d8eccSSepherosa Ziehau 10926c8d8eccSSepherosa Ziehau static int 10936c8d8eccSSepherosa Ziehau bnx_blockinit(struct bnx_softc *sc) 10946c8d8eccSSepherosa Ziehau { 109533a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 1096beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 10976c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 10986c8d8eccSSepherosa Ziehau bus_size_t vrcb; 10996c8d8eccSSepherosa Ziehau bge_hostaddr taddr; 11006c8d8eccSSepherosa Ziehau uint32_t val; 11016c8d8eccSSepherosa Ziehau int i, limit; 11026c8d8eccSSepherosa Ziehau 11036c8d8eccSSepherosa Ziehau /* 11046c8d8eccSSepherosa Ziehau * Initialize the memory window pointer register so that 11056c8d8eccSSepherosa Ziehau * we can access the first 32K of internal NIC RAM. This will 11066c8d8eccSSepherosa Ziehau * allow us to set up the TX send ring RCBs and the RX return 11076c8d8eccSSepherosa Ziehau * ring RCBs, plus other things which live in NIC memory. 11086c8d8eccSSepherosa Ziehau */ 11096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0); 11106c8d8eccSSepherosa Ziehau 11116c8d8eccSSepherosa Ziehau /* Configure mbuf pool watermarks */ 1112f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 11136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11146c8d8eccSSepherosa Ziehau if (sc->arpcom.ac_if.if_mtu > ETHERMTU) { 11156c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x7e); 11166c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xea); 11176c8d8eccSSepherosa Ziehau } else { 11186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x2a); 11196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xa0); 11206c8d8eccSSepherosa Ziehau } 11216c8d8eccSSepherosa Ziehau } else { 11226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11236c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10); 11246c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60); 11256c8d8eccSSepherosa Ziehau } 11266c8d8eccSSepherosa Ziehau 11276c8d8eccSSepherosa Ziehau /* Configure DMA resource watermarks */ 11286c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5); 11296c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10); 11306c8d8eccSSepherosa Ziehau 11316c8d8eccSSepherosa Ziehau /* Enable buffer manager */ 11326c8d8eccSSepherosa Ziehau val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN; 11336c8d8eccSSepherosa Ziehau /* 11346c8d8eccSSepherosa Ziehau * Change the arbitration algorithm of TXMBUF read request to 11356c8d8eccSSepherosa Ziehau * round-robin instead of priority based for BCM5719. When 11366c8d8eccSSepherosa Ziehau * TXFIFO is almost empty, RDMA will hold its request until 11376c8d8eccSSepherosa Ziehau * TXFIFO is not almost empty. 11386c8d8eccSSepherosa Ziehau */ 11396c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) 11406c8d8eccSSepherosa Ziehau val |= BGE_BMANMODE_NO_TX_UNDERRUN; 1141e5eebe34SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1142e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0 || 1143e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5720_A0) 1144e5eebe34SSepherosa Ziehau val |= BGE_BMANMODE_LOMBUF_ATTN; 11456c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MODE, val); 11466c8d8eccSSepherosa Ziehau 11476c8d8eccSSepherosa Ziehau /* Poll for buffer manager start indication */ 11486c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11496c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_BMAN_MODE) & BGE_BMANMODE_ENABLE) 11506c8d8eccSSepherosa Ziehau break; 11516c8d8eccSSepherosa Ziehau DELAY(10); 11526c8d8eccSSepherosa Ziehau } 11536c8d8eccSSepherosa Ziehau 11546c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 11556c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 11566c8d8eccSSepherosa Ziehau "buffer manager failed to start\n"); 11576c8d8eccSSepherosa Ziehau return(ENXIO); 11586c8d8eccSSepherosa Ziehau } 11596c8d8eccSSepherosa Ziehau 11606c8d8eccSSepherosa Ziehau /* Enable flow-through queues */ 11616c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 11626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 11636c8d8eccSSepherosa Ziehau 11646c8d8eccSSepherosa Ziehau /* Wait until queue initialization is complete */ 11656c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11666c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_FTQ_RESET) == 0) 11676c8d8eccSSepherosa Ziehau break; 11686c8d8eccSSepherosa Ziehau DELAY(10); 11696c8d8eccSSepherosa Ziehau } 11706c8d8eccSSepherosa Ziehau 11716c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 11726c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 11736c8d8eccSSepherosa Ziehau "flow-through queue init failed\n"); 11746c8d8eccSSepherosa Ziehau return(ENXIO); 11756c8d8eccSSepherosa Ziehau } 11766c8d8eccSSepherosa Ziehau 11776c8d8eccSSepherosa Ziehau /* 11786c8d8eccSSepherosa Ziehau * Summary of rings supported by the controller: 11796c8d8eccSSepherosa Ziehau * 11806c8d8eccSSepherosa Ziehau * Standard Receive Producer Ring 11816c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "standard" 11826c8d8eccSSepherosa Ziehau * sized frames (typically 1536 bytes) to the controller. 11836c8d8eccSSepherosa Ziehau * 11846c8d8eccSSepherosa Ziehau * Jumbo Receive Producer Ring 11856c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for jumbo sized 11866c8d8eccSSepherosa Ziehau * frames (i.e. anything bigger than the "standard" frames) 11876c8d8eccSSepherosa Ziehau * to the controller. 11886c8d8eccSSepherosa Ziehau * 11896c8d8eccSSepherosa Ziehau * Mini Receive Producer Ring 11906c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "mini" 11916c8d8eccSSepherosa Ziehau * sized frames to the controller. 11926c8d8eccSSepherosa Ziehau * - This feature required external memory for the controller 11936c8d8eccSSepherosa Ziehau * but was never used in a production system. Should always 11946c8d8eccSSepherosa Ziehau * be disabled. 11956c8d8eccSSepherosa Ziehau * 11966c8d8eccSSepherosa Ziehau * Receive Return Ring 11976c8d8eccSSepherosa Ziehau * - After the controller has placed an incoming frame into a 11986c8d8eccSSepherosa Ziehau * receive buffer that buffer is moved into a receive return 11996c8d8eccSSepherosa Ziehau * ring. The driver is then responsible to passing the 12006c8d8eccSSepherosa Ziehau * buffer up to the stack. Many versions of the controller 12016c8d8eccSSepherosa Ziehau * support multiple RR rings. 12026c8d8eccSSepherosa Ziehau * 12036c8d8eccSSepherosa Ziehau * Send Ring 12046c8d8eccSSepherosa Ziehau * - This ring is used for outgoing frames. Many versions of 12056c8d8eccSSepherosa Ziehau * the controller support multiple send rings. 12066c8d8eccSSepherosa Ziehau */ 12076c8d8eccSSepherosa Ziehau 12086c8d8eccSSepherosa Ziehau /* Initialize the standard receive producer ring control block. */ 12096c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_std_rx_rcb; 12106c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 1211beedf5beSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 12126c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 1213beedf5beSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 1214f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12156c8d8eccSSepherosa Ziehau /* 12166c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (2048, 1024, 512, .., 32) 12176c8d8eccSSepherosa Ziehau * Bits 15-2 : Maximum RX frame size 12186c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring ENabled 12196c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12206c8d8eccSSepherosa Ziehau */ 12216c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12226c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(512, BNX_MAX_FRAMELEN << 2); 12236c8d8eccSSepherosa Ziehau } else { 12246c8d8eccSSepherosa Ziehau /* 12256c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (512, 256, 128, 64, 32) 12266c8d8eccSSepherosa Ziehau * Bits 15-2 : Reserved (should be 0) 12276c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring Enabled 12286c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12296c8d8eccSSepherosa Ziehau */ 12306c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(512, 0); 12316c8d8eccSSepherosa Ziehau } 1232303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12336c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717; 12346c8d8eccSSepherosa Ziehau else 12356c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS; 12366c8d8eccSSepherosa Ziehau /* Write the standard receive producer ring control block. */ 12376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); 12386c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); 12396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 12406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_NICADDR, rcb->bge_nicaddr); 12416c8d8eccSSepherosa Ziehau /* Reset the standard receive producer ring producer index. */ 12426c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0); 12436c8d8eccSSepherosa Ziehau 12446c8d8eccSSepherosa Ziehau /* 12456c8d8eccSSepherosa Ziehau * Initialize the jumbo RX producer ring control 12466c8d8eccSSepherosa Ziehau * block. We set the 'ring disabled' bit in the 12476c8d8eccSSepherosa Ziehau * flags field until we're actually ready to start 12486c8d8eccSSepherosa Ziehau * using this ring (i.e. once we set the MTU 12496c8d8eccSSepherosa Ziehau * high enough to require it). 12506c8d8eccSSepherosa Ziehau */ 12516c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 12526c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 12536c8d8eccSSepherosa Ziehau /* Get the jumbo receive producer ring RCB parameters. */ 12546c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 12556c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12566c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 12576c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12586c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12596c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_MAX_FRAMELEN, 12606c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 1261303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12626c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717; 12636c8d8eccSSepherosa Ziehau else 12646c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; 12656c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI, 12666c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi); 12676c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO, 12686c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo); 12696c8d8eccSSepherosa Ziehau /* Program the jumbo receive producer ring RCB parameters. */ 12706c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, 12716c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags); 12726c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr); 12736c8d8eccSSepherosa Ziehau /* Reset the jumbo receive producer ring producer index. */ 12746c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); 12756c8d8eccSSepherosa Ziehau } 12766c8d8eccSSepherosa Ziehau 12776c8d8eccSSepherosa Ziehau /* 12786c8d8eccSSepherosa Ziehau * The BD ring replenish thresholds control how often the 12796c8d8eccSSepherosa Ziehau * hardware fetches new BD's from the producer rings in host 12806c8d8eccSSepherosa Ziehau * memory. Setting the value too low on a busy system can 12816c8d8eccSSepherosa Ziehau * starve the hardware and recue the throughpout. 12826c8d8eccSSepherosa Ziehau * 12836c8d8eccSSepherosa Ziehau * Set the BD ring replentish thresholds. The recommended 12846c8d8eccSSepherosa Ziehau * values are 1/8th the number of descriptors allocated to 12856c8d8eccSSepherosa Ziehau * each ring. 12866c8d8eccSSepherosa Ziehau */ 12876c8d8eccSSepherosa Ziehau val = 8; 12886c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_STD_REPL_THRESH, val); 12896c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 12906c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_JUMBO_REPL_THRESH, 12916c8d8eccSSepherosa Ziehau BGE_JUMBO_RX_RING_CNT/8); 12926c8d8eccSSepherosa Ziehau } 1293f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12946c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_STD_REPLENISH_LWM, 32); 12956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_JMB_REPLENISH_LWM, 16); 12966c8d8eccSSepherosa Ziehau } 12976c8d8eccSSepherosa Ziehau 12986c8d8eccSSepherosa Ziehau /* 12996c8d8eccSSepherosa Ziehau * Disable all send rings by setting the 'ring disabled' bit 13006c8d8eccSSepherosa Ziehau * in the flags field of all the TX send ring control blocks, 13016c8d8eccSSepherosa Ziehau * located in NIC memory. 13026c8d8eccSSepherosa Ziehau */ 130380969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 130480969639SSepherosa Ziehau limit = 4; 1305b96cbbb6SSepherosa Ziehau else if (BNX_IS_57765_FAMILY(sc) || 1306b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) 13074f23029eSSepherosa Ziehau limit = 2; 130880969639SSepherosa Ziehau else 13096c8d8eccSSepherosa Ziehau limit = 1; 13106c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 13116c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13126c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13136c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED)); 13146c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13156c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13166c8d8eccSSepherosa Ziehau } 13176c8d8eccSSepherosa Ziehau 13186c8d8eccSSepherosa Ziehau /* Configure send ring RCB 0 (we use only the first ring) */ 13196c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 132033a04907SSepherosa Ziehau BGE_HOSTADDR(taddr, txr->bnx_tx_ring_paddr); 13216c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 13226c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 1323303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13246c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, BGE_SEND_RING_5717); 13256c8d8eccSSepherosa Ziehau } else { 13266c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 13276c8d8eccSSepherosa Ziehau BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT)); 13286c8d8eccSSepherosa Ziehau } 13296c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13306c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BGE_TX_RING_CNT, 0)); 13316c8d8eccSSepherosa Ziehau 13326c8d8eccSSepherosa Ziehau /* 13336c8d8eccSSepherosa Ziehau * Disable all receive return rings by setting the 13346c8d8eccSSepherosa Ziehau * 'ring disabled' bit in the flags field of all the receive 13356c8d8eccSSepherosa Ziehau * return ring control blocks, located in NIC memory. 13366c8d8eccSSepherosa Ziehau */ 133780969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13386c8d8eccSSepherosa Ziehau /* Should be 17, use 16 until we get an SRAM map. */ 13396c8d8eccSSepherosa Ziehau limit = 16; 1340b96cbbb6SSepherosa Ziehau } else if (BNX_IS_57765_FAMILY(sc) || 1341b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 13426c8d8eccSSepherosa Ziehau limit = 4; 13436c8d8eccSSepherosa Ziehau } else { 13446c8d8eccSSepherosa Ziehau limit = 1; 13456c8d8eccSSepherosa Ziehau } 13466c8d8eccSSepherosa Ziehau /* Disable all receive return rings. */ 13476c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 13486c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13496c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, 0); 13506c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, 0); 13516c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13526c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 13536c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13546c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO + 13556c8d8eccSSepherosa Ziehau (i * (sizeof(uint64_t))), 0); 13566c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13576c8d8eccSSepherosa Ziehau } 13586c8d8eccSSepherosa Ziehau 13596c8d8eccSSepherosa Ziehau /* 13606c8d8eccSSepherosa Ziehau * Set up receive return ring 0. Note that the NIC address 13616c8d8eccSSepherosa Ziehau * for RX return rings is 0x0. The return rings live entirely 13626c8d8eccSSepherosa Ziehau * within the host, so the nicaddr field in the RCB isn't used. 13636c8d8eccSSepherosa Ziehau */ 13646c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 1365beedf5beSSepherosa Ziehau BGE_HOSTADDR(taddr, ret->bnx_rx_ret_ring_paddr); 13666c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 13676c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 13686c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13696c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 1370e0f74fc8SSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_RETURN_RING_CNT, 0)); 13716c8d8eccSSepherosa Ziehau 13726c8d8eccSSepherosa Ziehau /* Set random backoff seed for TX */ 13736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_RANDOM_BACKOFF, 13746c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[0] + sc->arpcom.ac_enaddr[1] + 13756c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[2] + sc->arpcom.ac_enaddr[3] + 13766c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[4] + sc->arpcom.ac_enaddr[5] + 13776c8d8eccSSepherosa Ziehau BGE_TX_BACKOFF_SEED_MASK); 13786c8d8eccSSepherosa Ziehau 13796c8d8eccSSepherosa Ziehau /* Set inter-packet gap */ 13806c8d8eccSSepherosa Ziehau val = 0x2620; 1381b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1382b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 13836c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_TX_LENGTHS) & 13846c8d8eccSSepherosa Ziehau (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK); 13856c8d8eccSSepherosa Ziehau } 13866c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_LENGTHS, val); 13876c8d8eccSSepherosa Ziehau 13886c8d8eccSSepherosa Ziehau /* 13896c8d8eccSSepherosa Ziehau * Specify which ring to use for packets that don't match 13906c8d8eccSSepherosa Ziehau * any RX rules. 13916c8d8eccSSepherosa Ziehau */ 13926c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_RULES_CFG, 0x08); 13936c8d8eccSSepherosa Ziehau 13946c8d8eccSSepherosa Ziehau /* 13956c8d8eccSSepherosa Ziehau * Configure number of RX lists. One interrupt distribution 13966c8d8eccSSepherosa Ziehau * list, sixteen active lists, one bad frames class. 13976c8d8eccSSepherosa Ziehau */ 13986c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181); 13996c8d8eccSSepherosa Ziehau 14006c8d8eccSSepherosa Ziehau /* Inialize RX list placement stats mask. */ 14016c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF); 14026c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1); 14036c8d8eccSSepherosa Ziehau 14046c8d8eccSSepherosa Ziehau /* Disable host coalescing until we get it set up */ 14056c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, 0x00000000); 14066c8d8eccSSepherosa Ziehau 14076c8d8eccSSepherosa Ziehau /* Poll to make sure it's shut down. */ 14086c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 14096c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_HCC_MODE) & BGE_HCCMODE_ENABLE)) 14106c8d8eccSSepherosa Ziehau break; 14116c8d8eccSSepherosa Ziehau DELAY(10); 14126c8d8eccSSepherosa Ziehau } 14136c8d8eccSSepherosa Ziehau 14146c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 14156c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 14166c8d8eccSSepherosa Ziehau "host coalescing engine failed to idle\n"); 14176c8d8eccSSepherosa Ziehau return(ENXIO); 14186c8d8eccSSepherosa Ziehau } 14196c8d8eccSSepherosa Ziehau 14206c8d8eccSSepherosa Ziehau /* Set up host coalescing defaults */ 14216c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, sc->bnx_rx_coal_ticks); 14226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bnx_tx_coal_ticks); 14236c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bnx_rx_coal_bds); 14246c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bnx_tx_coal_bds); 14256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, sc->bnx_rx_coal_bds_int); 14266c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, sc->bnx_tx_coal_bds_int); 14276c8d8eccSSepherosa Ziehau 14286c8d8eccSSepherosa Ziehau /* Set up address of status block */ 14296c8d8eccSSepherosa Ziehau bzero(sc->bnx_ldata.bnx_status_block, BGE_STATUS_BLK_SZ); 14306c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_HI, 14316c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_status_block_paddr)); 14326c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_LO, 14336c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_status_block_paddr)); 14346c8d8eccSSepherosa Ziehau 14356c8d8eccSSepherosa Ziehau /* Set up status block partail update size. */ 14366c8d8eccSSepherosa Ziehau val = BGE_STATBLKSZ_32BYTE; 14376c8d8eccSSepherosa Ziehau #if 0 14386c8d8eccSSepherosa Ziehau /* 14396c8d8eccSSepherosa Ziehau * Does not seem to have visible effect in both 14406c8d8eccSSepherosa Ziehau * bulk data (1472B UDP datagram) and tiny data 14416c8d8eccSSepherosa Ziehau * (18B UDP datagram) TX tests. 14426c8d8eccSSepherosa Ziehau */ 14436c8d8eccSSepherosa Ziehau val |= BGE_HCCMODE_CLRTICK_TX; 14446c8d8eccSSepherosa Ziehau #endif 14456c8d8eccSSepherosa Ziehau /* Turn on host coalescing state machine */ 14466c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE); 14476c8d8eccSSepherosa Ziehau 14486c8d8eccSSepherosa Ziehau /* Turn on RX BD completion state machine and enable attentions */ 14496c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDC_MODE, 14506c8d8eccSSepherosa Ziehau BGE_RBDCMODE_ENABLE|BGE_RBDCMODE_ATTN); 14516c8d8eccSSepherosa Ziehau 14526c8d8eccSSepherosa Ziehau /* Turn on RX list placement state machine */ 14536c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 14546c8d8eccSSepherosa Ziehau 14556c8d8eccSSepherosa Ziehau val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB | 14566c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_CLEAR | BGE_MACMODE_TX_STATS_CLEAR | 14576c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_ENB | BGE_MACMODE_TX_STATS_ENB | 14586c8d8eccSSepherosa Ziehau BGE_MACMODE_FRMHDR_DMA_ENB; 14596c8d8eccSSepherosa Ziehau 14606c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 14616c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_TBI; 14626c8d8eccSSepherosa Ziehau else if (sc->bnx_flags & BNX_FLAG_MII_SERDES) 14636c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_GMII; 14646c8d8eccSSepherosa Ziehau else 14656c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_MII; 14666c8d8eccSSepherosa Ziehau 14676c8d8eccSSepherosa Ziehau /* Turn on DMA, clear stats */ 14686c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, val); 14696c8d8eccSSepherosa Ziehau 14706c8d8eccSSepherosa Ziehau /* Set misc. local control, enable interrupts on attentions */ 14716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN); 14726c8d8eccSSepherosa Ziehau 14736c8d8eccSSepherosa Ziehau #ifdef notdef 14746c8d8eccSSepherosa Ziehau /* Assert GPIO pins for PHY reset */ 14756c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUT0| 14766c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUT1|BGE_MLC_MISCIO_OUT2); 14776c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUTEN0| 14786c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUTEN1|BGE_MLC_MISCIO_OUTEN2); 14796c8d8eccSSepherosa Ziehau #endif 14806c8d8eccSSepherosa Ziehau 14816c8d8eccSSepherosa Ziehau /* Turn on write DMA state machine */ 14826c8d8eccSSepherosa Ziehau val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS; 14836c8d8eccSSepherosa Ziehau /* Enable host coalescing bug fix. */ 14846c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_STATUS_TAG_FIX; 14856c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5785) { 14866c8d8eccSSepherosa Ziehau /* Request larger DMA burst size to get better performance. */ 14876c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_BURST_ALL_DATA; 14886c8d8eccSSepherosa Ziehau } 14896c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_WDMA_MODE, val); 14906c8d8eccSSepherosa Ziehau DELAY(40); 14916c8d8eccSSepherosa Ziehau 14923730a14dSSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 1493b96cbbb6SSepherosa Ziehau uint32_t dmactl, dmactl_reg; 14946c8d8eccSSepherosa Ziehau 1495b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1496b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL2; 1497b96cbbb6SSepherosa Ziehau else 1498b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL; 1499b96cbbb6SSepherosa Ziehau 1500b96cbbb6SSepherosa Ziehau dmactl = CSR_READ_4(sc, dmactl_reg); 15016c8d8eccSSepherosa Ziehau /* 15026c8d8eccSSepherosa Ziehau * Adjust tx margin to prevent TX data corruption and 15036c8d8eccSSepherosa Ziehau * fix internal FIFO overflow. 15046c8d8eccSSepherosa Ziehau */ 15056c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 1506b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1507b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 15086c8d8eccSSepherosa Ziehau dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK | 15096c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK | 15106c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_MASK); 15116c8d8eccSSepherosa Ziehau dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K | 15126c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K | 15136c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_320B; 15146c8d8eccSSepherosa Ziehau } 15156c8d8eccSSepherosa Ziehau /* 15166c8d8eccSSepherosa Ziehau * Enable fix for read DMA FIFO overruns. 15176c8d8eccSSepherosa Ziehau * The fix is to limit the number of RX BDs 15186c8d8eccSSepherosa Ziehau * the hardware would fetch at a fime. 15196c8d8eccSSepherosa Ziehau */ 1520b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, dmactl_reg, 15216c8d8eccSSepherosa Ziehau dmactl | BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX); 15226c8d8eccSSepherosa Ziehau } 15236c8d8eccSSepherosa Ziehau 15246c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) { 15256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, 15266c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | 15276c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K | 15286c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 1529b96cbbb6SSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1530b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 1531b96cbbb6SSepherosa Ziehau uint32_t ctrl_reg; 1532b96cbbb6SSepherosa Ziehau 1533b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1534b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL2; 1535b96cbbb6SSepherosa Ziehau else 1536b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL; 1537b96cbbb6SSepherosa Ziehau 15386c8d8eccSSepherosa Ziehau /* 15396c8d8eccSSepherosa Ziehau * Allow 4KB burst length reads for non-LSO frames. 15406c8d8eccSSepherosa Ziehau * Enable 512B burst length reads for buffer descriptors. 15416c8d8eccSSepherosa Ziehau */ 1542b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, ctrl_reg, 1543b96cbbb6SSepherosa Ziehau CSR_READ_4(sc, ctrl_reg) | 15446c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 | 15456c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 15466c8d8eccSSepherosa Ziehau } 15476c8d8eccSSepherosa Ziehau 15486c8d8eccSSepherosa Ziehau /* Turn on read DMA state machine */ 15496c8d8eccSSepherosa Ziehau val = BGE_RDMAMODE_ENABLE | BGE_RDMAMODE_ALL_ATTNS; 15506c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717) 15516c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_MULT_DMA_RD_DIS; 15526c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5784 || 15536c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5785 || 15546c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM57780) { 15556c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_BD_SBD_CRPT_ATTN | 15566c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_RBD_CRPT_ATTN | 15576c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_SBD_CRPT_ATTN; 15586c8d8eccSSepherosa Ziehau } 1559b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1560b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 15616c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_RDMA_MODE) & 15626c8d8eccSSepherosa Ziehau BGE_RDMAMODE_H2BNC_VLAN_DET; 15636c8d8eccSSepherosa Ziehau /* 15646c8d8eccSSepherosa Ziehau * Allow multiple outstanding read requests from 15656c8d8eccSSepherosa Ziehau * non-LSO read DMA engine. 15666c8d8eccSSepherosa Ziehau */ 15676c8d8eccSSepherosa Ziehau val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS; 15686c8d8eccSSepherosa Ziehau } 156960e67e3fSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM57766) 157060e67e3fSSepherosa Ziehau val |= BGE_RDMAMODE_JMB_2K_MMRR; 157166deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) 157266deb1c1SSepherosa Ziehau val |= BGE_RDMAMODE_TSO4_ENABLE; 15736c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_FIFO_LONG_BURST; 15746c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_MODE, val); 15756c8d8eccSSepherosa Ziehau DELAY(40); 15766c8d8eccSSepherosa Ziehau 15776c8d8eccSSepherosa Ziehau /* Turn on RX data completion state machine */ 15786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 15796c8d8eccSSepherosa Ziehau 15806c8d8eccSSepherosa Ziehau /* Turn on RX BD initiator state machine */ 15816c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 15826c8d8eccSSepherosa Ziehau 15836c8d8eccSSepherosa Ziehau /* Turn on RX data and RX BD initiator state machine */ 15846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE); 15856c8d8eccSSepherosa Ziehau 15866c8d8eccSSepherosa Ziehau /* Turn on send BD completion state machine */ 15876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 15886c8d8eccSSepherosa Ziehau 15896c8d8eccSSepherosa Ziehau /* Turn on send data completion state machine */ 15906c8d8eccSSepherosa Ziehau val = BGE_SDCMODE_ENABLE; 15916c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5761) 15926c8d8eccSSepherosa Ziehau val |= BGE_SDCMODE_CDELAY; 15936c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDC_MODE, val); 15946c8d8eccSSepherosa Ziehau 15956c8d8eccSSepherosa Ziehau /* Turn on send data initiator state machine */ 159666deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 159766deb1c1SSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE | 159866deb1c1SSepherosa Ziehau BGE_SDIMODE_HW_LSO_PRE_DMA); 159966deb1c1SSepherosa Ziehau } else { 16006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 160166deb1c1SSepherosa Ziehau } 16026c8d8eccSSepherosa Ziehau 16036c8d8eccSSepherosa Ziehau /* Turn on send BD initiator state machine */ 16046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 16056c8d8eccSSepherosa Ziehau 16066c8d8eccSSepherosa Ziehau /* Turn on send BD selector state machine */ 16076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 16086c8d8eccSSepherosa Ziehau 16096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF); 16106c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_CTL, 16116c8d8eccSSepherosa Ziehau BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER); 16126c8d8eccSSepherosa Ziehau 16136c8d8eccSSepherosa Ziehau /* ack/clear link change events */ 16146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16156c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16166c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, 0); 16186c8d8eccSSepherosa Ziehau 16196c8d8eccSSepherosa Ziehau /* 16206c8d8eccSSepherosa Ziehau * Enable attention when the link has changed state for 16216c8d8eccSSepherosa Ziehau * devices that use auto polling. 16226c8d8eccSSepherosa Ziehau */ 16236c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 16246c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK); 16256c8d8eccSSepherosa Ziehau } else { 16266c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 16276c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 16286c8d8eccSSepherosa Ziehau DELAY(80); 16296c8d8eccSSepherosa Ziehau } 16306c8d8eccSSepherosa Ziehau } 16316c8d8eccSSepherosa Ziehau 16326c8d8eccSSepherosa Ziehau /* 16336c8d8eccSSepherosa Ziehau * Clear any pending link state attention. 16346c8d8eccSSepherosa Ziehau * Otherwise some link state change events may be lost until attention 16356c8d8eccSSepherosa Ziehau * is cleared by bnx_intr() -> bnx_softc.bnx_link_upd() sequence. 16366c8d8eccSSepherosa Ziehau * It's not necessary on newer BCM chips - perhaps enabling link 16376c8d8eccSSepherosa Ziehau * state change attentions implies clearing pending attention. 16386c8d8eccSSepherosa Ziehau */ 16396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16406c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16416c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16426c8d8eccSSepherosa Ziehau 16436c8d8eccSSepherosa Ziehau /* Enable link state change attentions. */ 16446c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_LINK_CHANGED); 16456c8d8eccSSepherosa Ziehau 16466c8d8eccSSepherosa Ziehau return(0); 16476c8d8eccSSepherosa Ziehau } 16486c8d8eccSSepherosa Ziehau 16496c8d8eccSSepherosa Ziehau /* 16506c8d8eccSSepherosa Ziehau * Probe for a Broadcom chip. Check the PCI vendor and device IDs 16516c8d8eccSSepherosa Ziehau * against our list and return its name if we find a match. Note 16526c8d8eccSSepherosa Ziehau * that since the Broadcom controller contains VPD support, we 16536c8d8eccSSepherosa Ziehau * can get the device name string from the controller itself instead 16546c8d8eccSSepherosa Ziehau * of the compiled-in string. This is a little slow, but it guarantees 16556c8d8eccSSepherosa Ziehau * we'll always announce the right product name. 16566c8d8eccSSepherosa Ziehau */ 16576c8d8eccSSepherosa Ziehau static int 16586c8d8eccSSepherosa Ziehau bnx_probe(device_t dev) 16596c8d8eccSSepherosa Ziehau { 16606c8d8eccSSepherosa Ziehau const struct bnx_type *t; 16616c8d8eccSSepherosa Ziehau uint16_t product, vendor; 16626c8d8eccSSepherosa Ziehau 16636c8d8eccSSepherosa Ziehau if (!pci_is_pcie(dev)) 16646c8d8eccSSepherosa Ziehau return ENXIO; 16656c8d8eccSSepherosa Ziehau 16666c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 16676c8d8eccSSepherosa Ziehau vendor = pci_get_vendor(dev); 16686c8d8eccSSepherosa Ziehau 16696c8d8eccSSepherosa Ziehau for (t = bnx_devs; t->bnx_name != NULL; t++) { 16706c8d8eccSSepherosa Ziehau if (vendor == t->bnx_vid && product == t->bnx_did) 16716c8d8eccSSepherosa Ziehau break; 16726c8d8eccSSepherosa Ziehau } 16736c8d8eccSSepherosa Ziehau if (t->bnx_name == NULL) 16746c8d8eccSSepherosa Ziehau return ENXIO; 16756c8d8eccSSepherosa Ziehau 16766c8d8eccSSepherosa Ziehau device_set_desc(dev, t->bnx_name); 16776c8d8eccSSepherosa Ziehau return 0; 16786c8d8eccSSepherosa Ziehau } 16796c8d8eccSSepherosa Ziehau 16806c8d8eccSSepherosa Ziehau static int 16816c8d8eccSSepherosa Ziehau bnx_attach(device_t dev) 16826c8d8eccSSepherosa Ziehau { 16836c8d8eccSSepherosa Ziehau struct ifnet *ifp; 16846c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 1685e594b5c4SSepherosa Ziehau uint32_t hwcfg = 0; 1686329f9016SSepherosa Ziehau int error = 0, rid, capmask, i; 16876c8d8eccSSepherosa Ziehau uint8_t ether_addr[ETHER_ADDR_LEN]; 168807e9f7c0SSascha Wildner uint16_t product; 16896c8d8eccSSepherosa Ziehau uintptr_t mii_priv = 0; 169066deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 169166deb1c1SSepherosa Ziehau char desc[32]; 169266deb1c1SSepherosa Ziehau #endif 16936c8d8eccSSepherosa Ziehau 16946c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 16956c8d8eccSSepherosa Ziehau sc->bnx_dev = dev; 169650668ed5SSepherosa Ziehau callout_init_mp(&sc->bnx_stat_timer); 16976c8d8eccSSepherosa Ziehau lwkt_serialize_init(&sc->bnx_jslot_serializer); 1698f33ac8a4SSepherosa Ziehau lwkt_serialize_init(&sc->bnx_main_serialize); 16996c8d8eccSSepherosa Ziehau 17006c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 17016c8d8eccSSepherosa Ziehau 17026c8d8eccSSepherosa Ziehau #ifndef BURN_BRIDGES 17036c8d8eccSSepherosa Ziehau if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 17046c8d8eccSSepherosa Ziehau uint32_t irq, mem; 17056c8d8eccSSepherosa Ziehau 17066c8d8eccSSepherosa Ziehau irq = pci_read_config(dev, PCIR_INTLINE, 4); 17076c8d8eccSSepherosa Ziehau mem = pci_read_config(dev, BGE_PCI_BAR0, 4); 17086c8d8eccSSepherosa Ziehau 17096c8d8eccSSepherosa Ziehau device_printf(dev, "chip is in D%d power mode " 17106c8d8eccSSepherosa Ziehau "-- setting to D0\n", pci_get_powerstate(dev)); 17116c8d8eccSSepherosa Ziehau 17126c8d8eccSSepherosa Ziehau pci_set_powerstate(dev, PCI_POWERSTATE_D0); 17136c8d8eccSSepherosa Ziehau 17146c8d8eccSSepherosa Ziehau pci_write_config(dev, PCIR_INTLINE, irq, 4); 17156c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_BAR0, mem, 4); 17166c8d8eccSSepherosa Ziehau } 17176c8d8eccSSepherosa Ziehau #endif /* !BURN_BRIDGE */ 17186c8d8eccSSepherosa Ziehau 17196c8d8eccSSepherosa Ziehau /* 17206c8d8eccSSepherosa Ziehau * Map control/status registers. 17216c8d8eccSSepherosa Ziehau */ 17226c8d8eccSSepherosa Ziehau pci_enable_busmaster(dev); 17236c8d8eccSSepherosa Ziehau 17246c8d8eccSSepherosa Ziehau rid = BGE_PCI_BAR0; 17256c8d8eccSSepherosa Ziehau sc->bnx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 17266c8d8eccSSepherosa Ziehau RF_ACTIVE); 17276c8d8eccSSepherosa Ziehau 17286c8d8eccSSepherosa Ziehau if (sc->bnx_res == NULL) { 17296c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't map memory\n"); 17306c8d8eccSSepherosa Ziehau return ENXIO; 17316c8d8eccSSepherosa Ziehau } 17326c8d8eccSSepherosa Ziehau 17336c8d8eccSSepherosa Ziehau sc->bnx_btag = rman_get_bustag(sc->bnx_res); 17346c8d8eccSSepherosa Ziehau sc->bnx_bhandle = rman_get_bushandle(sc->bnx_res); 17356c8d8eccSSepherosa Ziehau 17366c8d8eccSSepherosa Ziehau /* Save various chip information */ 17376c8d8eccSSepherosa Ziehau sc->bnx_chipid = 17386c8d8eccSSepherosa Ziehau pci_read_config(dev, BGE_PCI_MISC_CTL, 4) >> 17396c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_ASICREV_SHIFT; 17406c8d8eccSSepherosa Ziehau if (BGE_ASICREV(sc->bnx_chipid) == BGE_ASICREV_USE_PRODID_REG) { 17416c8d8eccSSepherosa Ziehau /* All chips having dedicated ASICREV register have CPMU */ 17426c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_CPMU; 17436c8d8eccSSepherosa Ziehau 17446c8d8eccSSepherosa Ziehau switch (product) { 17456c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717: 1746d79f5d8fSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717C: 17476c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5718: 17486c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5719: 17496c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5720_ALT: 1750b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5725: 1751b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5727: 1752b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5762: 17536c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17546c8d8eccSSepherosa Ziehau BGE_PCI_GEN2_PRODID_ASICREV, 4); 17556c8d8eccSSepherosa Ziehau break; 17566c8d8eccSSepherosa Ziehau 17576c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57761: 175832ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57762: 17596c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57765: 176032ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57766: 17616c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57781: 176232ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57782: 17636c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57785: 176432ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57786: 17656c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57791: 17666c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57795: 17676c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17686c8d8eccSSepherosa Ziehau BGE_PCI_GEN15_PRODID_ASICREV, 4); 17696c8d8eccSSepherosa Ziehau break; 17706c8d8eccSSepherosa Ziehau 17716c8d8eccSSepherosa Ziehau default: 17726c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17736c8d8eccSSepherosa Ziehau BGE_PCI_PRODID_ASICREV, 4); 17746c8d8eccSSepherosa Ziehau break; 17756c8d8eccSSepherosa Ziehau } 17766c8d8eccSSepherosa Ziehau } 1777d79f5d8fSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_C0) 1778d79f5d8fSSepherosa Ziehau sc->bnx_chipid = BGE_CHIPID_BCM5720_A0; 1779d79f5d8fSSepherosa Ziehau 17806c8d8eccSSepherosa Ziehau sc->bnx_asicrev = BGE_ASICREV(sc->bnx_chipid); 17816c8d8eccSSepherosa Ziehau sc->bnx_chiprev = BGE_CHIPREV(sc->bnx_chipid); 17826c8d8eccSSepherosa Ziehau 17836c8d8eccSSepherosa Ziehau switch (sc->bnx_asicrev) { 17846c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5717: 17856c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5719: 17866c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5720: 1787f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_5717_PLUS | BNX_FLAG_57765_PLUS; 1788f368d0d9SSepherosa Ziehau break; 1789f368d0d9SSepherosa Ziehau 1790b96cbbb6SSepherosa Ziehau case BGE_ASICREV_BCM5762: 1791b96cbbb6SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_PLUS; 1792b96cbbb6SSepherosa Ziehau break; 1793b96cbbb6SSepherosa Ziehau 17946c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM57765: 179532ff3c80SSepherosa Ziehau case BGE_ASICREV_BCM57766: 1796f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_FAMILY | BNX_FLAG_57765_PLUS; 17976c8d8eccSSepherosa Ziehau break; 17986c8d8eccSSepherosa Ziehau } 17996c8d8eccSSepherosa Ziehau 180066deb1c1SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TSO; 180166deb1c1SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 && 180266deb1c1SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0) 180366deb1c1SSepherosa Ziehau sc->bnx_flags &= ~BNX_FLAG_TSO; 180466deb1c1SSepherosa Ziehau 1805df9ccc98SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1806df9ccc98SSepherosa Ziehau BNX_IS_57765_FAMILY(sc)) { 1807df9ccc98SSepherosa Ziehau /* 1808df9ccc98SSepherosa Ziehau * All BCM57785 and BCM5718 families chips have a bug that 1809df9ccc98SSepherosa Ziehau * under certain situation interrupt will not be enabled 1810df9ccc98SSepherosa Ziehau * even if status tag is written to BGE_MBX_IRQ0_LO mailbox. 1811df9ccc98SSepherosa Ziehau * 1812df9ccc98SSepherosa Ziehau * While BCM5719 and BCM5720 have a hardware workaround 1813df9ccc98SSepherosa Ziehau * which could fix the above bug. 1814df9ccc98SSepherosa Ziehau * See the comment near BGE_PCIDMARWCTL_TAGGED_STATUS_WA in 1815df9ccc98SSepherosa Ziehau * bnx_chipinit(). 1816df9ccc98SSepherosa Ziehau * 1817df9ccc98SSepherosa Ziehau * For the rest of the chips in these two families, we will 1818df9ccc98SSepherosa Ziehau * have to poll the status block at high rate (10ms currently) 1819df9ccc98SSepherosa Ziehau * to check whether the interrupt is hosed or not. 1820f33ac8a4SSepherosa Ziehau * See bnx_check_intr() for details. 1821df9ccc98SSepherosa Ziehau */ 1822df9ccc98SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_STATUSTAG_BUG; 1823df9ccc98SSepherosa Ziehau } 1824df9ccc98SSepherosa Ziehau 18256c8d8eccSSepherosa Ziehau sc->bnx_pciecap = pci_get_pciecap_ptr(sc->bnx_dev); 18266c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 18276c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720) 18286c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_2048); 18296c8d8eccSSepherosa Ziehau else 18306c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_4096); 18316c8d8eccSSepherosa Ziehau device_printf(dev, "CHIP ID 0x%08x; " 18326c8d8eccSSepherosa Ziehau "ASIC REV 0x%02x; CHIP REV 0x%02x\n", 18336c8d8eccSSepherosa Ziehau sc->bnx_chipid, sc->bnx_asicrev, sc->bnx_chiprev); 18346c8d8eccSSepherosa Ziehau 18356c8d8eccSSepherosa Ziehau /* 18366c8d8eccSSepherosa Ziehau * Set various PHY quirk flags. 18376c8d8eccSSepherosa Ziehau */ 18386c8d8eccSSepherosa Ziehau 18396c8d8eccSSepherosa Ziehau capmask = MII_CAPMASK_DEFAULT; 184046283a40SSepherosa Ziehau if (product == PCI_PRODUCT_BROADCOM_BCM57791 || 184146283a40SSepherosa Ziehau product == PCI_PRODUCT_BROADCOM_BCM57795) { 18426c8d8eccSSepherosa Ziehau /* 10/100 only */ 18436c8d8eccSSepherosa Ziehau capmask &= ~BMSR_EXTSTAT; 18446c8d8eccSSepherosa Ziehau } 18456c8d8eccSSepherosa Ziehau 18466c8d8eccSSepherosa Ziehau mii_priv |= BRGPHY_FLAG_WIRESPEED; 1847b96cbbb6SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5762_A0) 1848b96cbbb6SSepherosa Ziehau mii_priv |= BRGPHY_FLAG_5762_A0; 18496c8d8eccSSepherosa Ziehau 18506c8d8eccSSepherosa Ziehau /* Initialize if_name earlier, so if_printf could be used */ 18516c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 18526c8d8eccSSepherosa Ziehau if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 18536c8d8eccSSepherosa Ziehau 18546c8d8eccSSepherosa Ziehau /* Try to reset the chip. */ 18556c8d8eccSSepherosa Ziehau bnx_reset(sc); 18566c8d8eccSSepherosa Ziehau 18576c8d8eccSSepherosa Ziehau if (bnx_chipinit(sc)) { 18586c8d8eccSSepherosa Ziehau device_printf(dev, "chip initialization failed\n"); 18596c8d8eccSSepherosa Ziehau error = ENXIO; 18606c8d8eccSSepherosa Ziehau goto fail; 18616c8d8eccSSepherosa Ziehau } 18626c8d8eccSSepherosa Ziehau 18636c8d8eccSSepherosa Ziehau /* 18646c8d8eccSSepherosa Ziehau * Get station address 18656c8d8eccSSepherosa Ziehau */ 18666c8d8eccSSepherosa Ziehau error = bnx_get_eaddr(sc, ether_addr); 18676c8d8eccSSepherosa Ziehau if (error) { 18686c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read station address\n"); 18696c8d8eccSSepherosa Ziehau goto fail; 18706c8d8eccSSepherosa Ziehau } 18716c8d8eccSSepherosa Ziehau 187233a04907SSepherosa Ziehau /* XXX */ 187333a04907SSepherosa Ziehau sc->bnx_tx_ringcnt = 1; 1874beedf5beSSepherosa Ziehau sc->bnx_rx_retcnt = 1; 187533a04907SSepherosa Ziehau 1876beedf5beSSepherosa Ziehau error = bnx_dma_alloc(dev); 18776c8d8eccSSepherosa Ziehau if (error) 18786c8d8eccSSepherosa Ziehau goto fail; 18796c8d8eccSSepherosa Ziehau 188016b32c4cSSepherosa Ziehau /* 188116b32c4cSSepherosa Ziehau * Allocate interrupt 188216b32c4cSSepherosa Ziehau */ 18830c7da01dSSepherosa Ziehau error = bnx_alloc_intr(sc); 18840c7da01dSSepherosa Ziehau if (error) 188516b32c4cSSepherosa Ziehau goto fail; 188616b32c4cSSepherosa Ziehau 1887329f9016SSepherosa Ziehau /* Setup serializers */ 1888329f9016SSepherosa Ziehau bnx_setup_serialize(sc); 1889329f9016SSepherosa Ziehau 18906c8d8eccSSepherosa Ziehau /* Set default tuneable values. */ 18916c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks = BNX_RX_COAL_TICKS_DEF; 18926c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks = BNX_TX_COAL_TICKS_DEF; 18936c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds = BNX_RX_COAL_BDS_DEF; 18946c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds = BNX_TX_COAL_BDS_DEF; 1895306e5498SSepherosa Ziehau sc->bnx_rx_coal_bds_int = BNX_RX_COAL_BDS_INT_DEF; 1896306e5498SSepherosa Ziehau sc->bnx_tx_coal_bds_int = BNX_TX_COAL_BDS_INT_DEF; 18976c8d8eccSSepherosa Ziehau 18986c8d8eccSSepherosa Ziehau /* Set up ifnet structure */ 18996c8d8eccSSepherosa Ziehau ifp->if_softc = sc; 19006c8d8eccSSepherosa Ziehau ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 19016c8d8eccSSepherosa Ziehau ifp->if_ioctl = bnx_ioctl; 19026c8d8eccSSepherosa Ziehau ifp->if_start = bnx_start; 190339a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 190439a8d43aSSepherosa Ziehau ifp->if_npoll = bnx_npoll; 19056c8d8eccSSepherosa Ziehau #endif 19066c8d8eccSSepherosa Ziehau ifp->if_init = bnx_init; 1907329f9016SSepherosa Ziehau ifp->if_serialize = bnx_serialize; 1908329f9016SSepherosa Ziehau ifp->if_deserialize = bnx_deserialize; 1909329f9016SSepherosa Ziehau ifp->if_tryserialize = bnx_tryserialize; 1910329f9016SSepherosa Ziehau #ifdef INVARIANTS 1911329f9016SSepherosa Ziehau ifp->if_serialize_assert = bnx_serialize_assert; 1912329f9016SSepherosa Ziehau #endif 19136c8d8eccSSepherosa Ziehau ifp->if_mtu = ETHERMTU; 19146c8d8eccSSepherosa Ziehau ifp->if_capabilities = IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; 19156c8d8eccSSepherosa Ziehau 19166c8d8eccSSepherosa Ziehau ifp->if_capabilities |= IFCAP_HWCSUM; 19176c8d8eccSSepherosa Ziehau ifp->if_hwassist = BNX_CSUM_FEATURES; 191866deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 191966deb1c1SSepherosa Ziehau ifp->if_capabilities |= IFCAP_TSO; 192066deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 192166deb1c1SSepherosa Ziehau } 19226c8d8eccSSepherosa Ziehau ifp->if_capenable = ifp->if_capabilities; 19236c8d8eccSSepherosa Ziehau 1924329f9016SSepherosa Ziehau ifq_set_maxlen(&ifp->if_snd, BGE_TX_RING_CNT - 1); 1925329f9016SSepherosa Ziehau ifq_set_ready(&ifp->if_snd); 1926329f9016SSepherosa Ziehau ifq_set_subq_cnt(&ifp->if_snd, sc->bnx_tx_ringcnt); 1927329f9016SSepherosa Ziehau 19286c8d8eccSSepherosa Ziehau /* 19296c8d8eccSSepherosa Ziehau * Figure out what sort of media we have by checking the 19306c8d8eccSSepherosa Ziehau * hardware config word in the first 32k of NIC internal memory, 19316c8d8eccSSepherosa Ziehau * or fall back to examining the EEPROM if necessary. 19326c8d8eccSSepherosa Ziehau * Note: on some BCM5700 cards, this value appears to be unset. 19336c8d8eccSSepherosa Ziehau * If that's the case, we have to rely on identifying the NIC 19346c8d8eccSSepherosa Ziehau * by its PCI subsystem ID, as we do below for the SysKonnect 19356c8d8eccSSepherosa Ziehau * SK-9D41. 19366c8d8eccSSepherosa Ziehau */ 19376c8d8eccSSepherosa Ziehau if (bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER) { 19386c8d8eccSSepherosa Ziehau hwcfg = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG); 19396c8d8eccSSepherosa Ziehau } else { 19406c8d8eccSSepherosa Ziehau if (bnx_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET, 19416c8d8eccSSepherosa Ziehau sizeof(hwcfg))) { 19426c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read EEPROM\n"); 19436c8d8eccSSepherosa Ziehau error = ENXIO; 19446c8d8eccSSepherosa Ziehau goto fail; 19456c8d8eccSSepherosa Ziehau } 19466c8d8eccSSepherosa Ziehau hwcfg = ntohl(hwcfg); 19476c8d8eccSSepherosa Ziehau } 19486c8d8eccSSepherosa Ziehau 19496c8d8eccSSepherosa Ziehau /* The SysKonnect SK-9D41 is a 1000baseSX card. */ 19506c8d8eccSSepherosa Ziehau if (pci_get_subvendor(dev) == PCI_PRODUCT_SCHNEIDERKOCH_SK_9D41 || 19516c8d8eccSSepherosa Ziehau (hwcfg & BGE_HWCFG_MEDIA) == BGE_MEDIA_FIBER) 19526c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TBI; 19536c8d8eccSSepherosa Ziehau 19546c8d8eccSSepherosa Ziehau /* Setup MI MODE */ 19556c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_CPMU) 19566c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_500KHZ_CONST; 19576c8d8eccSSepherosa Ziehau else 19586c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_BASE; 19596c8d8eccSSepherosa Ziehau 19606c8d8eccSSepherosa Ziehau /* Setup link status update stuffs */ 19616c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 19626c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_tbi_link_upd; 19636c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19646c8d8eccSSepherosa Ziehau } else if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 19656c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_autopoll_link_upd; 19666c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19676c8d8eccSSepherosa Ziehau } else { 19686c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_copper_link_upd; 19696c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 19706c8d8eccSSepherosa Ziehau } 19716c8d8eccSSepherosa Ziehau 19726c8d8eccSSepherosa Ziehau /* Set default PHY address */ 19736c8d8eccSSepherosa Ziehau sc->bnx_phyno = 1; 19746c8d8eccSSepherosa Ziehau 19756c8d8eccSSepherosa Ziehau /* 19766c8d8eccSSepherosa Ziehau * PHY address mapping for various devices. 19776c8d8eccSSepherosa Ziehau * 19786c8d8eccSSepherosa Ziehau * | F0 Cu | F0 Sr | F1 Cu | F1 Sr | 19796c8d8eccSSepherosa Ziehau * ---------+-------+-------+-------+-------+ 19806c8d8eccSSepherosa Ziehau * BCM57XX | 1 | X | X | X | 19816c8d8eccSSepherosa Ziehau * BCM5704 | 1 | X | 1 | X | 19826c8d8eccSSepherosa Ziehau * BCM5717 | 1 | 8 | 2 | 9 | 19836c8d8eccSSepherosa Ziehau * BCM5719 | 1 | 8 | 2 | 9 | 19846c8d8eccSSepherosa Ziehau * BCM5720 | 1 | 8 | 2 | 9 | 19856c8d8eccSSepherosa Ziehau * 19866c8d8eccSSepherosa Ziehau * Other addresses may respond but they are not 19876c8d8eccSSepherosa Ziehau * IEEE compliant PHYs and should be ignored. 19886c8d8eccSSepherosa Ziehau */ 198980969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 19906c8d8eccSSepherosa Ziehau int f; 19916c8d8eccSSepherosa Ziehau 19926c8d8eccSSepherosa Ziehau f = pci_get_function(dev); 19936c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_A0) { 19946c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_SGDIG_STS) & 19956c8d8eccSSepherosa Ziehau BGE_SGDIGSTS_IS_SERDES) 19966c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 19976c8d8eccSSepherosa Ziehau else 19986c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 19996c8d8eccSSepherosa Ziehau } else { 20006c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_CPMU_PHY_STRAP) & 20016c8d8eccSSepherosa Ziehau BGE_CPMU_PHY_STRAP_IS_SERDES) 20026c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 20036c8d8eccSSepherosa Ziehau else 20046c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 20056c8d8eccSSepherosa Ziehau } 20066c8d8eccSSepherosa Ziehau } 20076c8d8eccSSepherosa Ziehau 20086c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 20096c8d8eccSSepherosa Ziehau ifmedia_init(&sc->bnx_ifmedia, IFM_IMASK, 20106c8d8eccSSepherosa Ziehau bnx_ifmedia_upd, bnx_ifmedia_sts); 20116c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL); 20126c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, 20136c8d8eccSSepherosa Ziehau IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL); 20146c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 20156c8d8eccSSepherosa Ziehau ifmedia_set(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO); 20166c8d8eccSSepherosa Ziehau sc->bnx_ifmedia.ifm_media = sc->bnx_ifmedia.ifm_cur->ifm_media; 20176c8d8eccSSepherosa Ziehau } else { 20186c8d8eccSSepherosa Ziehau struct mii_probe_args mii_args; 20196c8d8eccSSepherosa Ziehau 20206c8d8eccSSepherosa Ziehau mii_probe_args_init(&mii_args, bnx_ifmedia_upd, bnx_ifmedia_sts); 20216c8d8eccSSepherosa Ziehau mii_args.mii_probemask = 1 << sc->bnx_phyno; 20226c8d8eccSSepherosa Ziehau mii_args.mii_capmask = capmask; 20236c8d8eccSSepherosa Ziehau mii_args.mii_privtag = MII_PRIVTAG_BRGPHY; 20246c8d8eccSSepherosa Ziehau mii_args.mii_priv = mii_priv; 20256c8d8eccSSepherosa Ziehau 20266c8d8eccSSepherosa Ziehau error = mii_probe(dev, &sc->bnx_miibus, &mii_args); 20276c8d8eccSSepherosa Ziehau if (error) { 20286c8d8eccSSepherosa Ziehau device_printf(dev, "MII without any PHY!\n"); 20296c8d8eccSSepherosa Ziehau goto fail; 20306c8d8eccSSepherosa Ziehau } 20316c8d8eccSSepherosa Ziehau } 20326c8d8eccSSepherosa Ziehau 20336c8d8eccSSepherosa Ziehau /* 20346c8d8eccSSepherosa Ziehau * Create sysctl nodes. 20356c8d8eccSSepherosa Ziehau */ 20366c8d8eccSSepherosa Ziehau sysctl_ctx_init(&sc->bnx_sysctl_ctx); 20376c8d8eccSSepherosa Ziehau sc->bnx_sysctl_tree = SYSCTL_ADD_NODE(&sc->bnx_sysctl_ctx, 20386c8d8eccSSepherosa Ziehau SYSCTL_STATIC_CHILDREN(_hw), 20396c8d8eccSSepherosa Ziehau OID_AUTO, 20406c8d8eccSSepherosa Ziehau device_get_nameunit(dev), 20416c8d8eccSSepherosa Ziehau CTLFLAG_RD, 0, ""); 20426c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree == NULL) { 20436c8d8eccSSepherosa Ziehau device_printf(dev, "can't add sysctl node\n"); 20446c8d8eccSSepherosa Ziehau error = ENXIO; 20456c8d8eccSSepherosa Ziehau goto fail; 20466c8d8eccSSepherosa Ziehau } 20476c8d8eccSSepherosa Ziehau 20486c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20496c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20506c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_ticks", 20516c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20526c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_ticks, "I", 20536c8d8eccSSepherosa Ziehau "Receive coalescing ticks (usec)."); 20546c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20556c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20566c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_ticks", 20576c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20586c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_ticks, "I", 20596c8d8eccSSepherosa Ziehau "Transmit coalescing ticks (usec)."); 20606c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20616c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20626c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_bds", 20636c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20646c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds, "I", 20656c8d8eccSSepherosa Ziehau "Receive max coalesced BD count."); 20666c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20676c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 20686c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_bds", 20696c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 20706c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds, "I", 20716c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count."); 20726c8d8eccSSepherosa Ziehau /* 20736c8d8eccSSepherosa Ziehau * A common design characteristic for many Broadcom 20746c8d8eccSSepherosa Ziehau * client controllers is that they only support a 20756c8d8eccSSepherosa Ziehau * single outstanding DMA read operation on the PCIe 20766c8d8eccSSepherosa Ziehau * bus. This means that it will take twice as long to 20776c8d8eccSSepherosa Ziehau * fetch a TX frame that is split into header and 20786c8d8eccSSepherosa Ziehau * payload buffers as it does to fetch a single, 20796c8d8eccSSepherosa Ziehau * contiguous TX frame (2 reads vs. 1 read). For these 20806c8d8eccSSepherosa Ziehau * controllers, coalescing buffers to reduce the number 20816c8d8eccSSepherosa Ziehau * of memory reads is effective way to get maximum 20826c8d8eccSSepherosa Ziehau * performance(about 940Mbps). Without collapsing TX 20836c8d8eccSSepherosa Ziehau * buffers the maximum TCP bulk transfer performance 20846c8d8eccSSepherosa Ziehau * is about 850Mbps. However forcing coalescing mbufs 20856c8d8eccSSepherosa Ziehau * consumes a lot of CPU cycles, so leave it off by 20866c8d8eccSSepherosa Ziehau * default. 20876c8d8eccSSepherosa Ziehau */ 2088aad4de2bSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 20896c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2090aad4de2bSSepherosa Ziehau "force_defrag", CTLTYPE_INT | CTLFLAG_RW, 2091aad4de2bSSepherosa Ziehau sc, 0, bnx_sysctl_force_defrag, "I", 20926c8d8eccSSepherosa Ziehau "Force defragment on TX path"); 20936c8d8eccSSepherosa Ziehau 2094472c99c8SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 2095c9b7f592SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2096472c99c8SSepherosa Ziehau "tx_wreg", CTLTYPE_INT | CTLFLAG_RW, 2097472c99c8SSepherosa Ziehau sc, 0, bnx_sysctl_tx_wreg, "I", 2098c9b7f592SSepherosa Ziehau "# of segments before writing to hardware register"); 2099c9b7f592SSepherosa Ziehau 21006c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21016c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 21026c8d8eccSSepherosa Ziehau "rx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 21036c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds_int, "I", 21046c8d8eccSSepherosa Ziehau "Receive max coalesced BD count during interrupt."); 21056c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21066c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 21076c8d8eccSSepherosa Ziehau "tx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 21086c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds_int, "I", 21096c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count during interrupt."); 21106c8d8eccSSepherosa Ziehau 211166deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 211266deb1c1SSepherosa Ziehau for (i = 0; i < BNX_TSO_NSTATS; ++i) { 211366deb1c1SSepherosa Ziehau ksnprintf(desc, sizeof(desc), "tso%d", i + 1); 211466deb1c1SSepherosa Ziehau SYSCTL_ADD_ULONG(&sc->bnx_sysctl_ctx, 211566deb1c1SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 211666deb1c1SSepherosa Ziehau desc, CTLFLAG_RW, &sc->bnx_tsosegs[i], ""); 211766deb1c1SSepherosa Ziehau } 211866deb1c1SSepherosa Ziehau #endif 211966deb1c1SSepherosa Ziehau 21206c8d8eccSSepherosa Ziehau /* 21216c8d8eccSSepherosa Ziehau * Call MI attach routine. 21226c8d8eccSSepherosa Ziehau */ 2123329f9016SSepherosa Ziehau ether_ifattach(ifp, ether_addr, NULL); 21246c8d8eccSSepherosa Ziehau 2125329f9016SSepherosa Ziehau /* Setup TX rings and subqueues */ 2126329f9016SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 2127329f9016SSepherosa Ziehau struct ifaltq_subque *ifsq = ifq_get_subq(&ifp->if_snd, i); 2128329f9016SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 2129329f9016SSepherosa Ziehau 2130329f9016SSepherosa Ziehau ifsq_set_cpuid(ifsq, txr->bnx_tx_cpuid); 2131329f9016SSepherosa Ziehau ifsq_set_hw_serialize(ifsq, &txr->bnx_tx_serialize); 2132329f9016SSepherosa Ziehau ifsq_set_priv(ifsq, txr); 2133*3397dea6SSepherosa Ziehau txr->bnx_ifsq = ifsq; 2134329f9016SSepherosa Ziehau 2135*3397dea6SSepherosa Ziehau ifsq_watchdog_init(&txr->bnx_tx_watchdog, ifsq, bnx_watchdog); 2136329f9016SSepherosa Ziehau } 21374c77af2dSSepherosa Ziehau 2138b5de76b1SSepherosa Ziehau #ifdef IFPOLL_ENABLE 2139b5de76b1SSepherosa Ziehau ifpoll_compat_setup(&sc->bnx_npoll, 2140b5de76b1SSepherosa Ziehau &sc->bnx_sysctl_ctx, sc->bnx_sysctl_tree, 2141329f9016SSepherosa Ziehau device_get_unit(dev), &sc->bnx_main_serialize); 2142b5de76b1SSepherosa Ziehau #endif 2143b5de76b1SSepherosa Ziehau 21440c7da01dSSepherosa Ziehau error = bnx_setup_intr(sc); 21456c8d8eccSSepherosa Ziehau if (error) { 21466c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 21476c8d8eccSSepherosa Ziehau goto fail; 21486c8d8eccSSepherosa Ziehau } 21496c8d8eccSSepherosa Ziehau 2150f33ac8a4SSepherosa Ziehau sc->bnx_stat_cpuid = sc->bnx_intr_data[0].bnx_intr_cpuid; 21518ca0f604SSepherosa Ziehau 21526c8d8eccSSepherosa Ziehau return(0); 21536c8d8eccSSepherosa Ziehau fail: 21546c8d8eccSSepherosa Ziehau bnx_detach(dev); 21556c8d8eccSSepherosa Ziehau return(error); 21566c8d8eccSSepherosa Ziehau } 21576c8d8eccSSepherosa Ziehau 21586c8d8eccSSepherosa Ziehau static int 21596c8d8eccSSepherosa Ziehau bnx_detach(device_t dev) 21606c8d8eccSSepherosa Ziehau { 21616c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 21626c8d8eccSSepherosa Ziehau 21636c8d8eccSSepherosa Ziehau if (device_is_attached(dev)) { 21646c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 21656c8d8eccSSepherosa Ziehau 2166329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 21676c8d8eccSSepherosa Ziehau bnx_stop(sc); 21686c8d8eccSSepherosa Ziehau bnx_reset(sc); 2169f33ac8a4SSepherosa Ziehau bnx_teardown_intr(sc, sc->bnx_intr_cnt); 2170329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 21716c8d8eccSSepherosa Ziehau 21726c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 21736c8d8eccSSepherosa Ziehau } 21746c8d8eccSSepherosa Ziehau 21756c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 21766c8d8eccSSepherosa Ziehau ifmedia_removeall(&sc->bnx_ifmedia); 21776c8d8eccSSepherosa Ziehau if (sc->bnx_miibus) 21786c8d8eccSSepherosa Ziehau device_delete_child(dev, sc->bnx_miibus); 21796c8d8eccSSepherosa Ziehau bus_generic_detach(dev); 21806c8d8eccSSepherosa Ziehau 21810c7da01dSSepherosa Ziehau bnx_free_intr(sc); 21826c8d8eccSSepherosa Ziehau 21836c8d8eccSSepherosa Ziehau if (sc->bnx_res != NULL) { 21846c8d8eccSSepherosa Ziehau bus_release_resource(dev, SYS_RES_MEMORY, 21856c8d8eccSSepherosa Ziehau BGE_PCI_BAR0, sc->bnx_res); 21866c8d8eccSSepherosa Ziehau } 21876c8d8eccSSepherosa Ziehau 21886c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree != NULL) 21896c8d8eccSSepherosa Ziehau sysctl_ctx_free(&sc->bnx_sysctl_ctx); 21906c8d8eccSSepherosa Ziehau 21916c8d8eccSSepherosa Ziehau bnx_dma_free(sc); 21926c8d8eccSSepherosa Ziehau 2193329f9016SSepherosa Ziehau if (sc->bnx_serialize != NULL) 2194329f9016SSepherosa Ziehau kfree(sc->bnx_serialize, M_DEVBUF); 2195329f9016SSepherosa Ziehau 21966c8d8eccSSepherosa Ziehau return 0; 21976c8d8eccSSepherosa Ziehau } 21986c8d8eccSSepherosa Ziehau 21996c8d8eccSSepherosa Ziehau static void 22006c8d8eccSSepherosa Ziehau bnx_reset(struct bnx_softc *sc) 22016c8d8eccSSepherosa Ziehau { 22026c8d8eccSSepherosa Ziehau device_t dev; 22036c8d8eccSSepherosa Ziehau uint32_t cachesize, command, pcistate, reset; 22046c8d8eccSSepherosa Ziehau void (*write_op)(struct bnx_softc *, uint32_t, uint32_t); 22056c8d8eccSSepherosa Ziehau int i, val = 0; 22066c8d8eccSSepherosa Ziehau uint16_t devctl; 22076c8d8eccSSepherosa Ziehau 22086c8d8eccSSepherosa Ziehau dev = sc->bnx_dev; 22096c8d8eccSSepherosa Ziehau 22106c8d8eccSSepherosa Ziehau write_op = bnx_writemem_direct; 22116c8d8eccSSepherosa Ziehau 22126c8d8eccSSepherosa Ziehau /* Save some important PCI state. */ 22136c8d8eccSSepherosa Ziehau cachesize = pci_read_config(dev, BGE_PCI_CACHESZ, 4); 22146c8d8eccSSepherosa Ziehau command = pci_read_config(dev, BGE_PCI_CMD, 4); 22156c8d8eccSSepherosa Ziehau pcistate = pci_read_config(dev, BGE_PCI_PCISTATE, 4); 22166c8d8eccSSepherosa Ziehau 22176c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 22186c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 22196c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 22206c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 22216c8d8eccSSepherosa Ziehau 22226c8d8eccSSepherosa Ziehau /* Disable fastboot on controllers that support it. */ 22236c8d8eccSSepherosa Ziehau if (bootverbose) 22246c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "Disabling fastboot\n"); 22256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0x0); 22266c8d8eccSSepherosa Ziehau 22276c8d8eccSSepherosa Ziehau /* 22286c8d8eccSSepherosa Ziehau * Write the magic number to SRAM at offset 0xB50. 22296c8d8eccSSepherosa Ziehau * When firmware finishes its initialization it will 22306c8d8eccSSepherosa Ziehau * write ~BGE_MAGIC_NUMBER to the same location. 22316c8d8eccSSepherosa Ziehau */ 22326c8d8eccSSepherosa Ziehau bnx_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); 22336c8d8eccSSepherosa Ziehau 22346c8d8eccSSepherosa Ziehau reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1); 22356c8d8eccSSepherosa Ziehau 22366c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 22376c8d8eccSSepherosa Ziehau /* Force PCI-E 1.0a mode */ 22383730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc) && 22396c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_PCIE_PHY_TSTCTL) == 22406c8d8eccSSepherosa Ziehau (BGE_PCIE_PHY_TSTCTL_PSCRAM | 22416c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PCIE10)) { 22426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PHY_TSTCTL, 22436c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PSCRAM); 22446c8d8eccSSepherosa Ziehau } 22456c8d8eccSSepherosa Ziehau if (sc->bnx_chipid != BGE_CHIPID_BCM5750_A0) { 22466c8d8eccSSepherosa Ziehau /* Prevent PCIE link training during global reset */ 22476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, (1<<29)); 22486c8d8eccSSepherosa Ziehau reset |= (1<<29); 22496c8d8eccSSepherosa Ziehau } 22506c8d8eccSSepherosa Ziehau 22516c8d8eccSSepherosa Ziehau /* 22526c8d8eccSSepherosa Ziehau * Set GPHY Power Down Override to leave GPHY 22536c8d8eccSSepherosa Ziehau * powered up in D0 uninitialized. 22546c8d8eccSSepherosa Ziehau */ 22556c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) 22566c8d8eccSSepherosa Ziehau reset |= BGE_MISCCFG_GPHY_PD_OVERRIDE; 22576c8d8eccSSepherosa Ziehau 22586c8d8eccSSepherosa Ziehau /* Issue global reset */ 22596c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, reset); 22606c8d8eccSSepherosa Ziehau 22616c8d8eccSSepherosa Ziehau DELAY(1000); 22626c8d8eccSSepherosa Ziehau 22636c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 22646c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5750_A0) { 22656c8d8eccSSepherosa Ziehau uint32_t v; 22666c8d8eccSSepherosa Ziehau 22676c8d8eccSSepherosa Ziehau DELAY(500000); /* wait for link training to complete */ 22686c8d8eccSSepherosa Ziehau v = pci_read_config(dev, 0xc4, 4); 22696c8d8eccSSepherosa Ziehau pci_write_config(dev, 0xc4, v | (1<<15), 4); 22706c8d8eccSSepherosa Ziehau } 22716c8d8eccSSepherosa Ziehau 22726c8d8eccSSepherosa Ziehau devctl = pci_read_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 2); 22736c8d8eccSSepherosa Ziehau 22746c8d8eccSSepherosa Ziehau /* Disable no snoop and disable relaxed ordering. */ 22756c8d8eccSSepherosa Ziehau devctl &= ~(PCIEM_DEVCTL_RELAX_ORDER | PCIEM_DEVCTL_NOSNOOP); 22766c8d8eccSSepherosa Ziehau 22776c8d8eccSSepherosa Ziehau /* Old PCI-E chips only support 128 bytes Max PayLoad Size. */ 22786c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) { 22796c8d8eccSSepherosa Ziehau devctl &= ~PCIEM_DEVCTL_MAX_PAYLOAD_MASK; 22806c8d8eccSSepherosa Ziehau devctl |= PCIEM_DEVCTL_MAX_PAYLOAD_128; 22816c8d8eccSSepherosa Ziehau } 22826c8d8eccSSepherosa Ziehau 22836c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 22846c8d8eccSSepherosa Ziehau devctl, 2); 22856c8d8eccSSepherosa Ziehau 22866c8d8eccSSepherosa Ziehau /* Clear error status. */ 22876c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVSTS, 22886c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_CORR_ERR | 22896c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_NFATAL_ERR | 22906c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_FATAL_ERR | 22916c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_UNSUPP_REQ, 2); 22926c8d8eccSSepherosa Ziehau 22936c8d8eccSSepherosa Ziehau /* Reset some of the PCI state that got zapped by reset */ 22946c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 22956c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 22966c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 22976c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 22986c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CACHESZ, cachesize, 4); 22996c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CMD, command, 4); 23006c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, (65 << 1)); 23016c8d8eccSSepherosa Ziehau 23026c8d8eccSSepherosa Ziehau /* Enable memory arbiter */ 23036c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); 23046c8d8eccSSepherosa Ziehau 23056c8d8eccSSepherosa Ziehau /* 23066c8d8eccSSepherosa Ziehau * Poll until we see the 1's complement of the magic number. 2307ddd93a5cSSepherosa Ziehau * This indicates that the firmware initialization is complete. 23086c8d8eccSSepherosa Ziehau */ 23096c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_FIRMWARE_TIMEOUT; i++) { 23106c8d8eccSSepherosa Ziehau val = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM); 23116c8d8eccSSepherosa Ziehau if (val == ~BGE_MAGIC_NUMBER) 23126c8d8eccSSepherosa Ziehau break; 23136c8d8eccSSepherosa Ziehau DELAY(10); 23146c8d8eccSSepherosa Ziehau } 23156c8d8eccSSepherosa Ziehau if (i == BNX_FIRMWARE_TIMEOUT) { 23166c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "firmware handshake " 23176c8d8eccSSepherosa Ziehau "timed out, found 0x%08x\n", val); 23186c8d8eccSSepherosa Ziehau } 23196c8d8eccSSepherosa Ziehau 23206c8d8eccSSepherosa Ziehau /* BCM57765 A0 needs additional time before accessing. */ 23216c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 23226c8d8eccSSepherosa Ziehau DELAY(10 * 1000); 23236c8d8eccSSepherosa Ziehau 23246c8d8eccSSepherosa Ziehau /* 23256c8d8eccSSepherosa Ziehau * XXX Wait for the value of the PCISTATE register to 23266c8d8eccSSepherosa Ziehau * return to its original pre-reset state. This is a 23276c8d8eccSSepherosa Ziehau * fairly good indicator of reset completion. If we don't 23286c8d8eccSSepherosa Ziehau * wait for the reset to fully complete, trying to read 23296c8d8eccSSepherosa Ziehau * from the device's non-PCI registers may yield garbage 23306c8d8eccSSepherosa Ziehau * results. 23316c8d8eccSSepherosa Ziehau */ 23326c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 23336c8d8eccSSepherosa Ziehau if (pci_read_config(dev, BGE_PCI_PCISTATE, 4) == pcistate) 23346c8d8eccSSepherosa Ziehau break; 23356c8d8eccSSepherosa Ziehau DELAY(10); 23366c8d8eccSSepherosa Ziehau } 23376c8d8eccSSepherosa Ziehau 23386c8d8eccSSepherosa Ziehau /* Fix up byte swapping */ 23396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, bnx_dma_swap_options(sc)); 23406c8d8eccSSepherosa Ziehau 23416c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 23426c8d8eccSSepherosa Ziehau 23436c8d8eccSSepherosa Ziehau /* 23446c8d8eccSSepherosa Ziehau * The 5704 in TBI mode apparently needs some special 23456c8d8eccSSepherosa Ziehau * adjustment to insure the SERDES drive level is set 23466c8d8eccSSepherosa Ziehau * to 1.2V. 23476c8d8eccSSepherosa Ziehau */ 23486c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704 && 23496c8d8eccSSepherosa Ziehau (sc->bnx_flags & BNX_FLAG_TBI)) { 23506c8d8eccSSepherosa Ziehau uint32_t serdescfg; 23516c8d8eccSSepherosa Ziehau 23526c8d8eccSSepherosa Ziehau serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG); 23536c8d8eccSSepherosa Ziehau serdescfg = (serdescfg & ~0xFFF) | 0x880; 23546c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg); 23556c8d8eccSSepherosa Ziehau } 23566c8d8eccSSepherosa Ziehau 23577892075dSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 23587892075dSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 23597892075dSSepherosa Ziehau DELAY(80); 23607892075dSSepherosa Ziehau 23616c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 23623730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc)) { 23636c8d8eccSSepherosa Ziehau uint32_t v; 23646c8d8eccSSepherosa Ziehau 23656c8d8eccSSepherosa Ziehau /* Enable Data FIFO protection. */ 2366f1f34fc4SSepherosa Ziehau v = CSR_READ_4(sc, BGE_PCIE_TLDLPL_PORT); 2367f1f34fc4SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_TLDLPL_PORT, v | (1 << 25)); 23686c8d8eccSSepherosa Ziehau } 23696c8d8eccSSepherosa Ziehau 23706c8d8eccSSepherosa Ziehau DELAY(10000); 23716c8d8eccSSepherosa Ziehau 23726c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 23736c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE, 23746c8d8eccSSepherosa Ziehau CPMU_CLCK_ORIDE_MAC_ORIDE_EN); 23756c8d8eccSSepherosa Ziehau } 23766c8d8eccSSepherosa Ziehau } 23776c8d8eccSSepherosa Ziehau 23786c8d8eccSSepherosa Ziehau /* 23796c8d8eccSSepherosa Ziehau * Frame reception handling. This is called if there's a frame 23806c8d8eccSSepherosa Ziehau * on the receive return list. 23816c8d8eccSSepherosa Ziehau * 23826c8d8eccSSepherosa Ziehau * Note: we have to be able to handle two possibilities here: 23836c8d8eccSSepherosa Ziehau * 1) the frame is from the jumbo recieve ring 23846c8d8eccSSepherosa Ziehau * 2) the frame is from the standard receive ring 23856c8d8eccSSepherosa Ziehau */ 23866c8d8eccSSepherosa Ziehau 23876c8d8eccSSepherosa Ziehau static void 2388beedf5beSSepherosa Ziehau bnx_rxeof(struct bnx_rx_ret_ring *ret, uint16_t rx_prod, int count) 23896c8d8eccSSepherosa Ziehau { 2390beedf5beSSepherosa Ziehau struct bnx_softc *sc = ret->bnx_sc; 2391beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = ret->bnx_std; 2392beedf5beSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 23936c8d8eccSSepherosa Ziehau int stdcnt = 0, jumbocnt = 0; 23946c8d8eccSSepherosa Ziehau 2395beedf5beSSepherosa Ziehau while (ret->bnx_rx_saved_considx != rx_prod && count != 0) { 23966c8d8eccSSepherosa Ziehau struct bge_rx_bd *cur_rx; 23976c8d8eccSSepherosa Ziehau uint32_t rxidx; 23986c8d8eccSSepherosa Ziehau struct mbuf *m = NULL; 23996c8d8eccSSepherosa Ziehau uint16_t vlan_tag = 0; 24006c8d8eccSSepherosa Ziehau int have_tag = 0; 24016c8d8eccSSepherosa Ziehau 240297381780SSepherosa Ziehau --count; 240397381780SSepherosa Ziehau 2404beedf5beSSepherosa Ziehau cur_rx = &ret->bnx_rx_ret_ring[ret->bnx_rx_saved_considx]; 24056c8d8eccSSepherosa Ziehau 24066c8d8eccSSepherosa Ziehau rxidx = cur_rx->bge_idx; 2407beedf5beSSepherosa Ziehau BNX_INC(ret->bnx_rx_saved_considx, BNX_RETURN_RING_CNT); 24086c8d8eccSSepherosa Ziehau 24096c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) { 24106c8d8eccSSepherosa Ziehau have_tag = 1; 24116c8d8eccSSepherosa Ziehau vlan_tag = cur_rx->bge_vlan_tag; 24126c8d8eccSSepherosa Ziehau } 24136c8d8eccSSepherosa Ziehau 24146c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_JUMBO_RING) { 24156c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_jumbo, BGE_JUMBO_RX_RING_CNT); 24166c8d8eccSSepherosa Ziehau jumbocnt++; 24176c8d8eccSSepherosa Ziehau 24186c8d8eccSSepherosa Ziehau if (rxidx != sc->bnx_jumbo) { 2419d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24206c8d8eccSSepherosa Ziehau if_printf(ifp, "sw jumbo index(%d) " 24216c8d8eccSSepherosa Ziehau "and hw jumbo index(%d) mismatch, drop!\n", 24226c8d8eccSSepherosa Ziehau sc->bnx_jumbo, rxidx); 24236c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, rxidx); 24246c8d8eccSSepherosa Ziehau continue; 24256c8d8eccSSepherosa Ziehau } 24266c8d8eccSSepherosa Ziehau 2427beedf5beSSepherosa Ziehau m = sc->bnx_cdata.bnx_rx_jumbo_chain[rxidx].bnx_rx_mbuf; 24286c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 2429d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24306c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 24316c8d8eccSSepherosa Ziehau continue; 24326c8d8eccSSepherosa Ziehau } 24336c8d8eccSSepherosa Ziehau if (bnx_newbuf_jumbo(sc, sc->bnx_jumbo, 0)) { 2434d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24356c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 24366c8d8eccSSepherosa Ziehau continue; 24376c8d8eccSSepherosa Ziehau } 24386c8d8eccSSepherosa Ziehau } else { 2439beedf5beSSepherosa Ziehau BNX_INC(std->bnx_rx_std, BGE_STD_RX_RING_CNT); 24406c8d8eccSSepherosa Ziehau stdcnt++; 24416c8d8eccSSepherosa Ziehau 2442beedf5beSSepherosa Ziehau if (rxidx != std->bnx_rx_std) { 2443d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 24446c8d8eccSSepherosa Ziehau if_printf(ifp, "sw std index(%d) " 24456c8d8eccSSepherosa Ziehau "and hw std index(%d) mismatch, drop!\n", 2446beedf5beSSepherosa Ziehau std->bnx_rx_std, rxidx); 2447beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, rxidx); 24486c8d8eccSSepherosa Ziehau continue; 24496c8d8eccSSepherosa Ziehau } 24506c8d8eccSSepherosa Ziehau 2451beedf5beSSepherosa Ziehau m = std->bnx_rx_std_buf[rxidx].bnx_rx_mbuf; 24526c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 2453d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 2454beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, std->bnx_rx_std); 24556c8d8eccSSepherosa Ziehau continue; 24566c8d8eccSSepherosa Ziehau } 2457beedf5beSSepherosa Ziehau if (bnx_newbuf_std(ret, std->bnx_rx_std, 0)) { 2458d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 2459beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(std, std->bnx_rx_std); 24606c8d8eccSSepherosa Ziehau continue; 24616c8d8eccSSepherosa Ziehau } 24626c8d8eccSSepherosa Ziehau } 24636c8d8eccSSepherosa Ziehau 2464d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ipackets, 1); 24656c8d8eccSSepherosa Ziehau m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; 24666c8d8eccSSepherosa Ziehau m->m_pkthdr.rcvif = ifp; 24676c8d8eccSSepherosa Ziehau 24686c8d8eccSSepherosa Ziehau if ((ifp->if_capenable & IFCAP_RXCSUM) && 24696c8d8eccSSepherosa Ziehau (cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) { 24706c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) { 24716c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; 24726c8d8eccSSepherosa Ziehau if ((cur_rx->bge_error_flag & 24736c8d8eccSSepherosa Ziehau BGE_RXERRFLAG_IP_CSUM_NOK) == 0) 24746c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 24756c8d8eccSSepherosa Ziehau } 24766c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) { 24776c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_data = 24786c8d8eccSSepherosa Ziehau cur_rx->bge_tcp_udp_csum; 24796c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | 24806c8d8eccSSepherosa Ziehau CSUM_PSEUDO_HDR; 24816c8d8eccSSepherosa Ziehau } 24826c8d8eccSSepherosa Ziehau } 24836c8d8eccSSepherosa Ziehau 24846c8d8eccSSepherosa Ziehau /* 24856c8d8eccSSepherosa Ziehau * If we received a packet with a vlan tag, pass it 24866c8d8eccSSepherosa Ziehau * to vlan_input() instead of ether_input(). 24876c8d8eccSSepherosa Ziehau */ 24886c8d8eccSSepherosa Ziehau if (have_tag) { 24896c8d8eccSSepherosa Ziehau m->m_flags |= M_VLANTAG; 24906c8d8eccSSepherosa Ziehau m->m_pkthdr.ether_vlantag = vlan_tag; 24916c8d8eccSSepherosa Ziehau } 24926c8d8eccSSepherosa Ziehau ifp->if_input(ifp, m); 24936c8d8eccSSepherosa Ziehau } 24946c8d8eccSSepherosa Ziehau 2495beedf5beSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO, ret->bnx_rx_saved_considx); 24966c8d8eccSSepherosa Ziehau if (stdcnt) 2497beedf5beSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std); 24986c8d8eccSSepherosa Ziehau if (jumbocnt) 24996c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 25006c8d8eccSSepherosa Ziehau } 25016c8d8eccSSepherosa Ziehau 25026c8d8eccSSepherosa Ziehau static void 250333a04907SSepherosa Ziehau bnx_txeof(struct bnx_tx_ring *txr, uint16_t tx_cons) 25046c8d8eccSSepherosa Ziehau { 250533a04907SSepherosa Ziehau struct ifnet *ifp = &txr->bnx_sc->arpcom.ac_if; 25066c8d8eccSSepherosa Ziehau 25076c8d8eccSSepherosa Ziehau /* 25086c8d8eccSSepherosa Ziehau * Go through our tx ring and free mbufs for those 25096c8d8eccSSepherosa Ziehau * frames that have been sent. 25106c8d8eccSSepherosa Ziehau */ 251133a04907SSepherosa Ziehau while (txr->bnx_tx_saved_considx != tx_cons) { 2512fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf; 25136c8d8eccSSepherosa Ziehau uint32_t idx = 0; 25146c8d8eccSSepherosa Ziehau 251533a04907SSepherosa Ziehau idx = txr->bnx_tx_saved_considx; 2516fa4b1067SSepherosa Ziehau buf = &txr->bnx_tx_buf[idx]; 2517fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 2518d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, opackets, 1); 251933a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 2520fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 2521fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 2522fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 25236c8d8eccSSepherosa Ziehau } 2524fa639b88SSepherosa Ziehau txr->bnx_tx_cnt--; 252533a04907SSepherosa Ziehau BNX_INC(txr->bnx_tx_saved_considx, BGE_TX_RING_CNT); 25266c8d8eccSSepherosa Ziehau } 25276c8d8eccSSepherosa Ziehau 2528fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) >= 25296c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) 2530*3397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 25316c8d8eccSSepherosa Ziehau 2532fa639b88SSepherosa Ziehau if (txr->bnx_tx_cnt == 0) 2533*3397dea6SSepherosa Ziehau txr->bnx_tx_watchdog.wd_timer = 0; 25346c8d8eccSSepherosa Ziehau 2535*3397dea6SSepherosa Ziehau if (!ifsq_is_empty(txr->bnx_ifsq)) 2536*3397dea6SSepherosa Ziehau ifsq_devstart(txr->bnx_ifsq); 25376c8d8eccSSepherosa Ziehau } 25386c8d8eccSSepherosa Ziehau 253939a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 25406c8d8eccSSepherosa Ziehau 25416c8d8eccSSepherosa Ziehau static void 254239a8d43aSSepherosa Ziehau bnx_npoll(struct ifnet *ifp, struct ifpoll_info *info) 254339a8d43aSSepherosa Ziehau { 254439a8d43aSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 254539a8d43aSSepherosa Ziehau 2546329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 254739a8d43aSSepherosa Ziehau 254839a8d43aSSepherosa Ziehau if (info != NULL) { 2549b5de76b1SSepherosa Ziehau int cpuid = sc->bnx_npoll.ifpc_cpuid; 255039a8d43aSSepherosa Ziehau 255139a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].poll_func = bnx_npoll_compat; 255239a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].arg = NULL; 2553329f9016SSepherosa Ziehau info->ifpi_rx[cpuid].serializer = &sc->bnx_main_serialize; 255439a8d43aSSepherosa Ziehau 255539a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 255639a8d43aSSepherosa Ziehau bnx_disable_intr(sc); 2557dfd3b18bSSepherosa Ziehau ifq_set_cpuid(&ifp->if_snd, cpuid); 255839a8d43aSSepherosa Ziehau } else { 255939a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 256039a8d43aSSepherosa Ziehau bnx_enable_intr(sc); 2561f33ac8a4SSepherosa Ziehau ifq_set_cpuid(&ifp->if_snd, sc->bnx_tx_ring[0].bnx_tx_cpuid); 256239a8d43aSSepherosa Ziehau } 256339a8d43aSSepherosa Ziehau } 256439a8d43aSSepherosa Ziehau 256539a8d43aSSepherosa Ziehau static void 256697381780SSepherosa Ziehau bnx_npoll_compat(struct ifnet *ifp, void *arg __unused, int cycle) 25676c8d8eccSSepherosa Ziehau { 25686c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 256933a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 2570beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */ 25716c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 25726c8d8eccSSepherosa Ziehau uint16_t rx_prod, tx_cons; 25736c8d8eccSSepherosa Ziehau 2574329f9016SSepherosa Ziehau ASSERT_SERIALIZED(&sc->bnx_main_serialize); 257539a8d43aSSepherosa Ziehau 2576b5de76b1SSepherosa Ziehau if (sc->bnx_npoll.ifpc_stcount-- == 0) { 2577b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = sc->bnx_npoll.ifpc_stfrac; 25786c8d8eccSSepherosa Ziehau /* 25796c8d8eccSSepherosa Ziehau * Process link state changes. 25806c8d8eccSSepherosa Ziehau */ 25816c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 258239a8d43aSSepherosa Ziehau } 258339a8d43aSSepherosa Ziehau 25846c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 258539a8d43aSSepherosa Ziehau 25866c8d8eccSSepherosa Ziehau /* 258739a8d43aSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 258839a8d43aSSepherosa Ziehau * before rx_prod and tx_cons. 25896c8d8eccSSepherosa Ziehau */ 25906c8d8eccSSepherosa Ziehau cpu_lfence(); 25916c8d8eccSSepherosa Ziehau 2592329f9016SSepherosa Ziehau lwkt_serialize_enter(&ret->bnx_rx_ret_serialize); 25933a16b7b8SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 2594beedf5beSSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 2595beedf5beSSepherosa Ziehau bnx_rxeof(ret, rx_prod, cycle); 2596329f9016SSepherosa Ziehau lwkt_serialize_exit(&ret->bnx_rx_ret_serialize); 25976c8d8eccSSepherosa Ziehau 2598329f9016SSepherosa Ziehau lwkt_serialize_enter(&txr->bnx_tx_serialize); 2599329f9016SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 260033a04907SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 260133a04907SSepherosa Ziehau bnx_txeof(txr, tx_cons); 2602329f9016SSepherosa Ziehau lwkt_serialize_exit(&txr->bnx_tx_serialize); 26036c8d8eccSSepherosa Ziehau } 26046c8d8eccSSepherosa Ziehau 260539a8d43aSSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 26066c8d8eccSSepherosa Ziehau 26076c8d8eccSSepherosa Ziehau static void 26086c8d8eccSSepherosa Ziehau bnx_intr_legacy(void *xsc) 26096c8d8eccSSepherosa Ziehau { 26106c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 26116c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 26126c8d8eccSSepherosa Ziehau 26136c8d8eccSSepherosa Ziehau if (sc->bnx_status_tag == sblk->bge_status_tag) { 26146c8d8eccSSepherosa Ziehau uint32_t val; 26156c8d8eccSSepherosa Ziehau 26166c8d8eccSSepherosa Ziehau val = pci_read_config(sc->bnx_dev, BGE_PCI_PCISTATE, 4); 26176c8d8eccSSepherosa Ziehau if (val & BGE_PCISTAT_INTR_NOTACT) 26186c8d8eccSSepherosa Ziehau return; 26196c8d8eccSSepherosa Ziehau } 26206c8d8eccSSepherosa Ziehau 26216c8d8eccSSepherosa Ziehau /* 26226c8d8eccSSepherosa Ziehau * NOTE: 26236c8d8eccSSepherosa Ziehau * Interrupt will have to be disabled if tagged status 26246c8d8eccSSepherosa Ziehau * is used, else interrupt will always be asserted on 26256c8d8eccSSepherosa Ziehau * certain chips (at least on BCM5750 AX/BX). 26266c8d8eccSSepherosa Ziehau */ 26276c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 26286c8d8eccSSepherosa Ziehau 26296c8d8eccSSepherosa Ziehau bnx_intr(sc); 26306c8d8eccSSepherosa Ziehau } 26316c8d8eccSSepherosa Ziehau 26326c8d8eccSSepherosa Ziehau static void 26336c8d8eccSSepherosa Ziehau bnx_msi(void *xsc) 26346c8d8eccSSepherosa Ziehau { 26356c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 26366c8d8eccSSepherosa Ziehau 26376c8d8eccSSepherosa Ziehau /* Disable interrupt first */ 26386c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 26396c8d8eccSSepherosa Ziehau bnx_intr(sc); 26406c8d8eccSSepherosa Ziehau } 26416c8d8eccSSepherosa Ziehau 26426c8d8eccSSepherosa Ziehau static void 26436c8d8eccSSepherosa Ziehau bnx_msi_oneshot(void *xsc) 26446c8d8eccSSepherosa Ziehau { 26456c8d8eccSSepherosa Ziehau bnx_intr(xsc); 26466c8d8eccSSepherosa Ziehau } 26476c8d8eccSSepherosa Ziehau 26486c8d8eccSSepherosa Ziehau static void 26496c8d8eccSSepherosa Ziehau bnx_intr(struct bnx_softc *sc) 26506c8d8eccSSepherosa Ziehau { 26516c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 26526c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 26536c8d8eccSSepherosa Ziehau uint32_t status; 26546c8d8eccSSepherosa Ziehau 2655329f9016SSepherosa Ziehau ASSERT_SERIALIZED(&sc->bnx_main_serialize); 2656329f9016SSepherosa Ziehau 26576c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 26586c8d8eccSSepherosa Ziehau /* 26596c8d8eccSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 26606c8d8eccSSepherosa Ziehau * before rx_prod, tx_cons and status. 26616c8d8eccSSepherosa Ziehau */ 26626c8d8eccSSepherosa Ziehau cpu_lfence(); 26636c8d8eccSSepherosa Ziehau 26646c8d8eccSSepherosa Ziehau status = sblk->bge_status; 26656c8d8eccSSepherosa Ziehau 26666c8d8eccSSepherosa Ziehau if ((status & BGE_STATFLAG_LINKSTATE_CHANGED) || sc->bnx_link_evt) 26676c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 26686c8d8eccSSepherosa Ziehau 26696c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 267033a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */ 2671beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */ 26723a16b7b8SSepherosa Ziehau uint16_t rx_prod, tx_cons; 26733a16b7b8SSepherosa Ziehau 2674329f9016SSepherosa Ziehau lwkt_serialize_enter(&ret->bnx_rx_ret_serialize); 26753a16b7b8SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 2676beedf5beSSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 2677beedf5beSSepherosa Ziehau bnx_rxeof(ret, rx_prod, -1); 2678329f9016SSepherosa Ziehau lwkt_serialize_exit(&ret->bnx_rx_ret_serialize); 26796c8d8eccSSepherosa Ziehau 2680329f9016SSepherosa Ziehau lwkt_serialize_enter(&txr->bnx_tx_serialize); 2681329f9016SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 268233a04907SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 268333a04907SSepherosa Ziehau bnx_txeof(txr, tx_cons); 2684329f9016SSepherosa Ziehau lwkt_serialize_exit(&txr->bnx_tx_serialize); 26856c8d8eccSSepherosa Ziehau } 26866c8d8eccSSepherosa Ziehau 26876c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 26886c8d8eccSSepherosa Ziehau } 26896c8d8eccSSepherosa Ziehau 26906c8d8eccSSepherosa Ziehau static void 26916c8d8eccSSepherosa Ziehau bnx_tick(void *xsc) 26926c8d8eccSSepherosa Ziehau { 26936c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 26946c8d8eccSSepherosa Ziehau 2695329f9016SSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_main_serialize); 26966c8d8eccSSepherosa Ziehau 26978ca0f604SSepherosa Ziehau KKASSERT(mycpuid == sc->bnx_stat_cpuid); 26988ca0f604SSepherosa Ziehau 26996c8d8eccSSepherosa Ziehau bnx_stats_update_regs(sc); 27006c8d8eccSSepherosa Ziehau 27016c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 27026c8d8eccSSepherosa Ziehau /* 27036c8d8eccSSepherosa Ziehau * Since in TBI mode auto-polling can't be used we should poll 27046c8d8eccSSepherosa Ziehau * link status manually. Here we register pending link event 27056c8d8eccSSepherosa Ziehau * and trigger interrupt. 27066c8d8eccSSepherosa Ziehau */ 27076c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 27086c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 27096c8d8eccSSepherosa Ziehau } else if (!sc->bnx_link) { 27106c8d8eccSSepherosa Ziehau mii_tick(device_get_softc(sc->bnx_miibus)); 27116c8d8eccSSepherosa Ziehau } 27126c8d8eccSSepherosa Ziehau 27136c8d8eccSSepherosa Ziehau callout_reset(&sc->bnx_stat_timer, hz, bnx_tick, sc); 27146c8d8eccSSepherosa Ziehau 2715329f9016SSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_main_serialize); 27166c8d8eccSSepherosa Ziehau } 27176c8d8eccSSepherosa Ziehau 27186c8d8eccSSepherosa Ziehau static void 27196c8d8eccSSepherosa Ziehau bnx_stats_update_regs(struct bnx_softc *sc) 27206c8d8eccSSepherosa Ziehau { 27216c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 27226c8d8eccSSepherosa Ziehau struct bge_mac_stats_regs stats; 27236c8d8eccSSepherosa Ziehau uint32_t *s; 27246c8d8eccSSepherosa Ziehau int i; 27256c8d8eccSSepherosa Ziehau 27266c8d8eccSSepherosa Ziehau s = (uint32_t *)&stats; 27276c8d8eccSSepherosa Ziehau for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) { 27286c8d8eccSSepherosa Ziehau *s = CSR_READ_4(sc, BGE_RX_STATS + i); 27296c8d8eccSSepherosa Ziehau s++; 27306c8d8eccSSepherosa Ziehau } 27316c8d8eccSSepherosa Ziehau 2732d40991efSSepherosa Ziehau IFNET_STAT_SET(ifp, collisions, 27336c8d8eccSSepherosa Ziehau (stats.dot3StatsSingleCollisionFrames + 27346c8d8eccSSepherosa Ziehau stats.dot3StatsMultipleCollisionFrames + 27356c8d8eccSSepherosa Ziehau stats.dot3StatsExcessiveCollisions + 2736d40991efSSepherosa Ziehau stats.dot3StatsLateCollisions)); 27376c8d8eccSSepherosa Ziehau } 27386c8d8eccSSepherosa Ziehau 27396c8d8eccSSepherosa Ziehau /* 27406c8d8eccSSepherosa Ziehau * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data 27416c8d8eccSSepherosa Ziehau * pointers to descriptors. 27426c8d8eccSSepherosa Ziehau */ 27436c8d8eccSSepherosa Ziehau static int 274433a04907SSepherosa Ziehau bnx_encap(struct bnx_tx_ring *txr, struct mbuf **m_head0, uint32_t *txidx, 2745c9b7f592SSepherosa Ziehau int *segs_used) 27466c8d8eccSSepherosa Ziehau { 27476c8d8eccSSepherosa Ziehau struct bge_tx_bd *d = NULL; 274866deb1c1SSepherosa Ziehau uint16_t csum_flags = 0, vlan_tag = 0, mss = 0; 27496c8d8eccSSepherosa Ziehau bus_dma_segment_t segs[BNX_NSEG_NEW]; 27506c8d8eccSSepherosa Ziehau bus_dmamap_t map; 27516c8d8eccSSepherosa Ziehau int error, maxsegs, nsegs, idx, i; 27526c8d8eccSSepherosa Ziehau struct mbuf *m_head = *m_head0, *m_new; 27536c8d8eccSSepherosa Ziehau 275466deb1c1SSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { 275566deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 275666deb1c1SSepherosa Ziehau int tso_nsegs; 275766deb1c1SSepherosa Ziehau #endif 275866deb1c1SSepherosa Ziehau 275933a04907SSepherosa Ziehau error = bnx_setup_tso(txr, m_head0, &mss, &csum_flags); 276066deb1c1SSepherosa Ziehau if (error) 276166deb1c1SSepherosa Ziehau return error; 276266deb1c1SSepherosa Ziehau m_head = *m_head0; 276366deb1c1SSepherosa Ziehau 276466deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 2765f0336d39SSepherosa Ziehau tso_nsegs = (m_head->m_pkthdr.len / 2766f0336d39SSepherosa Ziehau m_head->m_pkthdr.tso_segsz) - 1; 276766deb1c1SSepherosa Ziehau if (tso_nsegs > (BNX_TSO_NSTATS - 1)) 276866deb1c1SSepherosa Ziehau tso_nsegs = BNX_TSO_NSTATS - 1; 276966deb1c1SSepherosa Ziehau else if (tso_nsegs < 0) 277066deb1c1SSepherosa Ziehau tso_nsegs = 0; 27715a0c3c3aSSascha Wildner txr->bnx_sc->bnx_tsosegs[tso_nsegs]++; 277266deb1c1SSepherosa Ziehau #endif 277366deb1c1SSepherosa Ziehau } else if (m_head->m_pkthdr.csum_flags & BNX_CSUM_FEATURES) { 27746c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_IP) 27756c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_CSUM; 27766c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP)) 27776c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_TCP_UDP_CSUM; 27786c8d8eccSSepherosa Ziehau if (m_head->m_flags & M_LASTFRAG) 27796c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG_END; 27806c8d8eccSSepherosa Ziehau else if (m_head->m_flags & M_FRAG) 27816c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG; 27826c8d8eccSSepherosa Ziehau } 278366deb1c1SSepherosa Ziehau if (m_head->m_flags & M_VLANTAG) { 278466deb1c1SSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_VLAN_TAG; 278566deb1c1SSepherosa Ziehau vlan_tag = m_head->m_pkthdr.ether_vlantag; 278666deb1c1SSepherosa Ziehau } 27876c8d8eccSSepherosa Ziehau 27886c8d8eccSSepherosa Ziehau idx = *txidx; 2789fa4b1067SSepherosa Ziehau map = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 27906c8d8eccSSepherosa Ziehau 2791fa639b88SSepherosa Ziehau maxsegs = (BGE_TX_RING_CNT - txr->bnx_tx_cnt) - BNX_NSEG_RSVD; 27926c8d8eccSSepherosa Ziehau KASSERT(maxsegs >= BNX_NSEG_SPARE, 27936c8d8eccSSepherosa Ziehau ("not enough segments %d", maxsegs)); 27946c8d8eccSSepherosa Ziehau 27956c8d8eccSSepherosa Ziehau if (maxsegs > BNX_NSEG_NEW) 27966c8d8eccSSepherosa Ziehau maxsegs = BNX_NSEG_NEW; 27976c8d8eccSSepherosa Ziehau 27986c8d8eccSSepherosa Ziehau /* 27996c8d8eccSSepherosa Ziehau * Pad outbound frame to BGE_MIN_FRAMELEN for an unusual reason. 28006c8d8eccSSepherosa Ziehau * The bge hardware will pad out Tx runts to BGE_MIN_FRAMELEN, 28016c8d8eccSSepherosa Ziehau * but when such padded frames employ the bge IP/TCP checksum 28026c8d8eccSSepherosa Ziehau * offload, the hardware checksum assist gives incorrect results 28036c8d8eccSSepherosa Ziehau * (possibly from incorporating its own padding into the UDP/TCP 28046c8d8eccSSepherosa Ziehau * checksum; who knows). If we pad such runts with zeros, the 28056c8d8eccSSepherosa Ziehau * onboard checksum comes out correct. 28066c8d8eccSSepherosa Ziehau */ 28076c8d8eccSSepherosa Ziehau if ((csum_flags & BGE_TXBDFLAG_TCP_UDP_CSUM) && 28086c8d8eccSSepherosa Ziehau m_head->m_pkthdr.len < BNX_MIN_FRAMELEN) { 28096c8d8eccSSepherosa Ziehau error = m_devpad(m_head, BNX_MIN_FRAMELEN); 28106c8d8eccSSepherosa Ziehau if (error) 28116c8d8eccSSepherosa Ziehau goto back; 28126c8d8eccSSepherosa Ziehau } 28136c8d8eccSSepherosa Ziehau 281479a64343SSepherosa Ziehau if ((txr->bnx_tx_flags & BNX_TX_FLAG_SHORTDMA) && 281533a04907SSepherosa Ziehau m_head->m_next != NULL) { 28166c8d8eccSSepherosa Ziehau m_new = bnx_defrag_shortdma(m_head); 28176c8d8eccSSepherosa Ziehau if (m_new == NULL) { 28186c8d8eccSSepherosa Ziehau error = ENOBUFS; 28196c8d8eccSSepherosa Ziehau goto back; 28206c8d8eccSSepherosa Ziehau } 28216c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 28226c8d8eccSSepherosa Ziehau } 282366deb1c1SSepherosa Ziehau if ((m_head->m_pkthdr.csum_flags & CSUM_TSO) == 0 && 2824aad4de2bSSepherosa Ziehau (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) && 2825aad4de2bSSepherosa Ziehau m_head->m_next != NULL) { 28266c8d8eccSSepherosa Ziehau /* 28276c8d8eccSSepherosa Ziehau * Forcefully defragment mbuf chain to overcome hardware 28286c8d8eccSSepherosa Ziehau * limitation which only support a single outstanding 28296c8d8eccSSepherosa Ziehau * DMA read operation. If it fails, keep moving on using 28306c8d8eccSSepherosa Ziehau * the original mbuf chain. 28316c8d8eccSSepherosa Ziehau */ 28326c8d8eccSSepherosa Ziehau m_new = m_defrag(m_head, MB_DONTWAIT); 28336c8d8eccSSepherosa Ziehau if (m_new != NULL) 28346c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 28356c8d8eccSSepherosa Ziehau } 28366c8d8eccSSepherosa Ziehau 283733a04907SSepherosa Ziehau error = bus_dmamap_load_mbuf_defrag(txr->bnx_tx_mtag, map, 28386c8d8eccSSepherosa Ziehau m_head0, segs, maxsegs, &nsegs, BUS_DMA_NOWAIT); 28396c8d8eccSSepherosa Ziehau if (error) 28406c8d8eccSSepherosa Ziehau goto back; 2841c9b7f592SSepherosa Ziehau *segs_used += nsegs; 28426c8d8eccSSepherosa Ziehau 28436c8d8eccSSepherosa Ziehau m_head = *m_head0; 284433a04907SSepherosa Ziehau bus_dmamap_sync(txr->bnx_tx_mtag, map, BUS_DMASYNC_PREWRITE); 28456c8d8eccSSepherosa Ziehau 28466c8d8eccSSepherosa Ziehau for (i = 0; ; i++) { 284733a04907SSepherosa Ziehau d = &txr->bnx_tx_ring[idx]; 28486c8d8eccSSepherosa Ziehau 28496c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_lo = BGE_ADDR_LO(segs[i].ds_addr); 28506c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_hi = BGE_ADDR_HI(segs[i].ds_addr); 28516c8d8eccSSepherosa Ziehau d->bge_len = segs[i].ds_len; 28526c8d8eccSSepherosa Ziehau d->bge_flags = csum_flags; 285366deb1c1SSepherosa Ziehau d->bge_vlan_tag = vlan_tag; 285466deb1c1SSepherosa Ziehau d->bge_mss = mss; 28556c8d8eccSSepherosa Ziehau 28566c8d8eccSSepherosa Ziehau if (i == nsegs - 1) 28576c8d8eccSSepherosa Ziehau break; 28586c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 28596c8d8eccSSepherosa Ziehau } 28606c8d8eccSSepherosa Ziehau /* Mark the last segment as end of packet... */ 28616c8d8eccSSepherosa Ziehau d->bge_flags |= BGE_TXBDFLAG_END; 28626c8d8eccSSepherosa Ziehau 28636c8d8eccSSepherosa Ziehau /* 28646c8d8eccSSepherosa Ziehau * Insure that the map for this transmission is placed at 28656c8d8eccSSepherosa Ziehau * the array index of the last descriptor in this chain. 28666c8d8eccSSepherosa Ziehau */ 2867fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[*txidx].bnx_tx_dmamap = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 2868fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_dmamap = map; 2869fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_mbuf = m_head; 2870fa639b88SSepherosa Ziehau txr->bnx_tx_cnt += nsegs; 28716c8d8eccSSepherosa Ziehau 28726c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 28736c8d8eccSSepherosa Ziehau *txidx = idx; 28746c8d8eccSSepherosa Ziehau back: 28756c8d8eccSSepherosa Ziehau if (error) { 28766c8d8eccSSepherosa Ziehau m_freem(*m_head0); 28776c8d8eccSSepherosa Ziehau *m_head0 = NULL; 28786c8d8eccSSepherosa Ziehau } 28796c8d8eccSSepherosa Ziehau return error; 28806c8d8eccSSepherosa Ziehau } 28816c8d8eccSSepherosa Ziehau 28826c8d8eccSSepherosa Ziehau /* 28836c8d8eccSSepherosa Ziehau * Main transmit routine. To avoid having to do mbuf copies, we put pointers 28846c8d8eccSSepherosa Ziehau * to the mbuf data regions directly in the transmit descriptors. 28856c8d8eccSSepherosa Ziehau */ 28866c8d8eccSSepherosa Ziehau static void 2887f0a26983SSepherosa Ziehau bnx_start(struct ifnet *ifp, struct ifaltq_subque *ifsq) 28886c8d8eccSSepherosa Ziehau { 2889*3397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = ifsq_get_priv(ifsq); 28906c8d8eccSSepherosa Ziehau struct mbuf *m_head = NULL; 28916c8d8eccSSepherosa Ziehau uint32_t prodidx; 2892c9b7f592SSepherosa Ziehau int nsegs = 0; 28936c8d8eccSSepherosa Ziehau 2894*3397dea6SSepherosa Ziehau KKASSERT(txr->bnx_ifsq == ifsq); 2895329f9016SSepherosa Ziehau ASSERT_SERIALIZED(&txr->bnx_tx_serialize); 2896f0a26983SSepherosa Ziehau 2897*3397dea6SSepherosa Ziehau if ((ifp->if_flags & IFF_RUNNING) == 0 || ifsq_is_oactive(ifsq)) 28986c8d8eccSSepherosa Ziehau return; 28996c8d8eccSSepherosa Ziehau 290033a04907SSepherosa Ziehau prodidx = txr->bnx_tx_prodidx; 29016c8d8eccSSepherosa Ziehau 2902fa4b1067SSepherosa Ziehau while (txr->bnx_tx_buf[prodidx].bnx_tx_mbuf == NULL) { 29036c8d8eccSSepherosa Ziehau /* 29046c8d8eccSSepherosa Ziehau * Sanity check: avoid coming within BGE_NSEG_RSVD 29056c8d8eccSSepherosa Ziehau * descriptors of the end of the ring. Also make 29066c8d8eccSSepherosa Ziehau * sure there are BGE_NSEG_SPARE descriptors for 2907a1bd58c9SSepherosa Ziehau * jumbo buffers' or TSO segments' defragmentation. 29086c8d8eccSSepherosa Ziehau */ 2909fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) < 29106c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) { 2911*3397dea6SSepherosa Ziehau ifsq_set_oactive(ifsq); 29126c8d8eccSSepherosa Ziehau break; 29136c8d8eccSSepherosa Ziehau } 29146c8d8eccSSepherosa Ziehau 2915*3397dea6SSepherosa Ziehau m_head = ifsq_dequeue(ifsq, NULL); 2916a1bd58c9SSepherosa Ziehau if (m_head == NULL) 2917a1bd58c9SSepherosa Ziehau break; 2918a1bd58c9SSepherosa Ziehau 29196c8d8eccSSepherosa Ziehau /* 29206c8d8eccSSepherosa Ziehau * Pack the data into the transmit ring. If we 29216c8d8eccSSepherosa Ziehau * don't have room, set the OACTIVE flag and wait 29226c8d8eccSSepherosa Ziehau * for the NIC to drain the ring. 29236c8d8eccSSepherosa Ziehau */ 292433a04907SSepherosa Ziehau if (bnx_encap(txr, &m_head, &prodidx, &nsegs)) { 2925*3397dea6SSepherosa Ziehau ifsq_set_oactive(ifsq); 2926d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 29276c8d8eccSSepherosa Ziehau break; 29286c8d8eccSSepherosa Ziehau } 29296c8d8eccSSepherosa Ziehau 293033a04907SSepherosa Ziehau if (nsegs >= txr->bnx_tx_wreg) { 29316c8d8eccSSepherosa Ziehau /* Transmit */ 29328bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 2933c9b7f592SSepherosa Ziehau nsegs = 0; 2934c9b7f592SSepherosa Ziehau } 29356c8d8eccSSepherosa Ziehau 2936c9b7f592SSepherosa Ziehau ETHER_BPF_MTAP(ifp, m_head); 29376c8d8eccSSepherosa Ziehau 29386c8d8eccSSepherosa Ziehau /* 29396c8d8eccSSepherosa Ziehau * Set a timeout in case the chip goes out to lunch. 29406c8d8eccSSepherosa Ziehau */ 2941*3397dea6SSepherosa Ziehau txr->bnx_tx_watchdog.wd_timer = 5; 29426c8d8eccSSepherosa Ziehau } 29436c8d8eccSSepherosa Ziehau 2944c9b7f592SSepherosa Ziehau if (nsegs > 0) { 2945c9b7f592SSepherosa Ziehau /* Transmit */ 29468bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 2947c9b7f592SSepherosa Ziehau } 294833a04907SSepherosa Ziehau txr->bnx_tx_prodidx = prodidx; 2949c9b7f592SSepherosa Ziehau } 2950c9b7f592SSepherosa Ziehau 29516c8d8eccSSepherosa Ziehau static void 29526c8d8eccSSepherosa Ziehau bnx_init(void *xsc) 29536c8d8eccSSepherosa Ziehau { 29546c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 29556c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 29566c8d8eccSSepherosa Ziehau uint16_t *m; 29576c8d8eccSSepherosa Ziehau uint32_t mode; 295833a04907SSepherosa Ziehau int i; 29596c8d8eccSSepherosa Ziehau 2960329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 29616c8d8eccSSepherosa Ziehau 29626c8d8eccSSepherosa Ziehau /* Cancel pending I/O and flush buffers. */ 29636c8d8eccSSepherosa Ziehau bnx_stop(sc); 29646c8d8eccSSepherosa Ziehau bnx_reset(sc); 29656c8d8eccSSepherosa Ziehau bnx_chipinit(sc); 29666c8d8eccSSepherosa Ziehau 29676c8d8eccSSepherosa Ziehau /* 29686c8d8eccSSepherosa Ziehau * Init the various state machines, ring 29696c8d8eccSSepherosa Ziehau * control blocks and firmware. 29706c8d8eccSSepherosa Ziehau */ 29716c8d8eccSSepherosa Ziehau if (bnx_blockinit(sc)) { 29726c8d8eccSSepherosa Ziehau if_printf(ifp, "initialization failure\n"); 29736c8d8eccSSepherosa Ziehau bnx_stop(sc); 29746c8d8eccSSepherosa Ziehau return; 29756c8d8eccSSepherosa Ziehau } 29766c8d8eccSSepherosa Ziehau 29776c8d8eccSSepherosa Ziehau /* Specify MTU. */ 29786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu + 29796c8d8eccSSepherosa Ziehau ETHER_HDR_LEN + ETHER_CRC_LEN + EVL_ENCAPLEN); 29806c8d8eccSSepherosa Ziehau 29816c8d8eccSSepherosa Ziehau /* Load our MAC address. */ 29826c8d8eccSSepherosa Ziehau m = (uint16_t *)&sc->arpcom.ac_enaddr[0]; 29836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_LO, htons(m[0])); 29846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_HI, (htons(m[1]) << 16) | htons(m[2])); 29856c8d8eccSSepherosa Ziehau 29866c8d8eccSSepherosa Ziehau /* Enable or disable promiscuous mode as needed. */ 29876c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 29886c8d8eccSSepherosa Ziehau 29896c8d8eccSSepherosa Ziehau /* Program multicast filter. */ 29906c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 29916c8d8eccSSepherosa Ziehau 29926c8d8eccSSepherosa Ziehau /* Init RX ring. */ 2993beedf5beSSepherosa Ziehau if (bnx_init_rx_ring_std(&sc->bnx_rx_std_ring)) { 29946c8d8eccSSepherosa Ziehau if_printf(ifp, "RX ring initialization failed\n"); 29956c8d8eccSSepherosa Ziehau bnx_stop(sc); 29966c8d8eccSSepherosa Ziehau return; 29976c8d8eccSSepherosa Ziehau } 29986c8d8eccSSepherosa Ziehau 29996c8d8eccSSepherosa Ziehau /* Init jumbo RX ring. */ 30006c8d8eccSSepherosa Ziehau if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) { 30016c8d8eccSSepherosa Ziehau if (bnx_init_rx_ring_jumbo(sc)) { 30026c8d8eccSSepherosa Ziehau if_printf(ifp, "Jumbo RX ring initialization failed\n"); 30036c8d8eccSSepherosa Ziehau bnx_stop(sc); 30046c8d8eccSSepherosa Ziehau return; 30056c8d8eccSSepherosa Ziehau } 30066c8d8eccSSepherosa Ziehau } 30076c8d8eccSSepherosa Ziehau 30086c8d8eccSSepherosa Ziehau /* Init our RX return ring index */ 3009beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 3010beedf5beSSepherosa Ziehau sc->bnx_rx_ret_ring[i].bnx_rx_saved_considx = 0; 30116c8d8eccSSepherosa Ziehau 30126c8d8eccSSepherosa Ziehau /* Init TX ring. */ 301333a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 301433a04907SSepherosa Ziehau bnx_init_tx_ring(&sc->bnx_tx_ring[i]); 30156c8d8eccSSepherosa Ziehau 30166c8d8eccSSepherosa Ziehau /* Enable TX MAC state machine lockup fix. */ 30176c8d8eccSSepherosa Ziehau mode = CSR_READ_4(sc, BGE_TX_MODE); 30186c8d8eccSSepherosa Ziehau mode |= BGE_TXMODE_MBUF_LOCKUP_FIX; 3019b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 3020b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 30216c8d8eccSSepherosa Ziehau mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 30226c8d8eccSSepherosa Ziehau mode |= CSR_READ_4(sc, BGE_TX_MODE) & 30236c8d8eccSSepherosa Ziehau (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 30246c8d8eccSSepherosa Ziehau } 30256c8d8eccSSepherosa Ziehau /* Turn on transmitter */ 30266c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE); 30276c8d8eccSSepherosa Ziehau 30286c8d8eccSSepherosa Ziehau /* Turn on receiver */ 30296c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 30306c8d8eccSSepherosa Ziehau 30316c8d8eccSSepherosa Ziehau /* 30326c8d8eccSSepherosa Ziehau * Set the number of good frames to receive after RX MBUF 30336c8d8eccSSepherosa Ziehau * Low Watermark has been reached. After the RX MAC receives 30346c8d8eccSSepherosa Ziehau * this number of frames, it will drop subsequent incoming 30356c8d8eccSSepherosa Ziehau * frames until the MBUF High Watermark is reached. 30366c8d8eccSSepherosa Ziehau */ 3037bcb29629SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) 30386c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 1); 30396c8d8eccSSepherosa Ziehau else 30406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2); 30416c8d8eccSSepherosa Ziehau 3042f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) { 30436c8d8eccSSepherosa Ziehau if (bootverbose) { 30446c8d8eccSSepherosa Ziehau if_printf(ifp, "MSI_MODE: %#x\n", 30456c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MSI_MODE)); 30466c8d8eccSSepherosa Ziehau } 30476c8d8eccSSepherosa Ziehau } 30486c8d8eccSSepherosa Ziehau 30496c8d8eccSSepherosa Ziehau /* Tell firmware we're alive. */ 30506c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 30516c8d8eccSSepherosa Ziehau 30526c8d8eccSSepherosa Ziehau /* Enable host interrupts if polling(4) is not enabled. */ 30536c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA, 4); 305439a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 305539a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_NPOLLING) 30566c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 30576c8d8eccSSepherosa Ziehau else 30586c8d8eccSSepherosa Ziehau #endif 30596c8d8eccSSepherosa Ziehau bnx_enable_intr(sc); 30606c8d8eccSSepherosa Ziehau 30616c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(ifp); 30626c8d8eccSSepherosa Ziehau 30636c8d8eccSSepherosa Ziehau ifp->if_flags |= IFF_RUNNING; 3064*3397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 3065*3397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 3066*3397dea6SSepherosa Ziehau 3067*3397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 3068*3397dea6SSepherosa Ziehau ifsq_watchdog_start(&txr->bnx_tx_watchdog); 3069*3397dea6SSepherosa Ziehau } 30706c8d8eccSSepherosa Ziehau 30718ca0f604SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_stat_timer, hz, bnx_tick, sc, 30728ca0f604SSepherosa Ziehau sc->bnx_stat_cpuid); 30736c8d8eccSSepherosa Ziehau } 30746c8d8eccSSepherosa Ziehau 30756c8d8eccSSepherosa Ziehau /* 30766c8d8eccSSepherosa Ziehau * Set media options. 30776c8d8eccSSepherosa Ziehau */ 30786c8d8eccSSepherosa Ziehau static int 30796c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(struct ifnet *ifp) 30806c8d8eccSSepherosa Ziehau { 30816c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 30826c8d8eccSSepherosa Ziehau 30836c8d8eccSSepherosa Ziehau /* If this is a 1000baseX NIC, enable the TBI port. */ 30846c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 30856c8d8eccSSepherosa Ziehau struct ifmedia *ifm = &sc->bnx_ifmedia; 30866c8d8eccSSepherosa Ziehau 30876c8d8eccSSepherosa Ziehau if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 30886c8d8eccSSepherosa Ziehau return(EINVAL); 30896c8d8eccSSepherosa Ziehau 30906c8d8eccSSepherosa Ziehau switch(IFM_SUBTYPE(ifm->ifm_media)) { 30916c8d8eccSSepherosa Ziehau case IFM_AUTO: 30926c8d8eccSSepherosa Ziehau break; 30936c8d8eccSSepherosa Ziehau 30946c8d8eccSSepherosa Ziehau case IFM_1000_SX: 30956c8d8eccSSepherosa Ziehau if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 30966c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 30976c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 30986c8d8eccSSepherosa Ziehau } else { 30996c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, 31006c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 31016c8d8eccSSepherosa Ziehau } 31026c8d8eccSSepherosa Ziehau break; 31036c8d8eccSSepherosa Ziehau default: 31046c8d8eccSSepherosa Ziehau return(EINVAL); 31056c8d8eccSSepherosa Ziehau } 31066c8d8eccSSepherosa Ziehau } else { 31076c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 31086c8d8eccSSepherosa Ziehau 31096c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 31106c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 31116c8d8eccSSepherosa Ziehau if (mii->mii_instance) { 31126c8d8eccSSepherosa Ziehau struct mii_softc *miisc; 31136c8d8eccSSepherosa Ziehau 31146c8d8eccSSepherosa Ziehau LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 31156c8d8eccSSepherosa Ziehau mii_phy_reset(miisc); 31166c8d8eccSSepherosa Ziehau } 31176c8d8eccSSepherosa Ziehau mii_mediachg(mii); 31186c8d8eccSSepherosa Ziehau 31196c8d8eccSSepherosa Ziehau /* 31206c8d8eccSSepherosa Ziehau * Force an interrupt so that we will call bnx_link_upd 31216c8d8eccSSepherosa Ziehau * if needed and clear any pending link state attention. 31226c8d8eccSSepherosa Ziehau * Without this we are not getting any further interrupts 31236c8d8eccSSepherosa Ziehau * for link state changes and thus will not UP the link and 31246c8d8eccSSepherosa Ziehau * not be able to send in bnx_start. The only way to get 31256c8d8eccSSepherosa Ziehau * things working was to receive a packet and get an RX 31266c8d8eccSSepherosa Ziehau * intr. 31276c8d8eccSSepherosa Ziehau * 31286c8d8eccSSepherosa Ziehau * bnx_tick should help for fiber cards and we might not 31296c8d8eccSSepherosa Ziehau * need to do this here if BNX_FLAG_TBI is set but as 31306c8d8eccSSepherosa Ziehau * we poll for fiber anyway it should not harm. 31316c8d8eccSSepherosa Ziehau */ 31326c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 31336c8d8eccSSepherosa Ziehau } 31346c8d8eccSSepherosa Ziehau return(0); 31356c8d8eccSSepherosa Ziehau } 31366c8d8eccSSepherosa Ziehau 31376c8d8eccSSepherosa Ziehau /* 31386c8d8eccSSepherosa Ziehau * Report current media status. 31396c8d8eccSSepherosa Ziehau */ 31406c8d8eccSSepherosa Ziehau static void 31416c8d8eccSSepherosa Ziehau bnx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 31426c8d8eccSSepherosa Ziehau { 31436c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 31446c8d8eccSSepherosa Ziehau 31456c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 31466c8d8eccSSepherosa Ziehau ifmr->ifm_status = IFM_AVALID; 31476c8d8eccSSepherosa Ziehau ifmr->ifm_active = IFM_ETHER; 31486c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_STS) & 31496c8d8eccSSepherosa Ziehau BGE_MACSTAT_TBI_PCS_SYNCHED) { 31506c8d8eccSSepherosa Ziehau ifmr->ifm_status |= IFM_ACTIVE; 31516c8d8eccSSepherosa Ziehau } else { 31526c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_NONE; 31536c8d8eccSSepherosa Ziehau return; 31546c8d8eccSSepherosa Ziehau } 31556c8d8eccSSepherosa Ziehau 31566c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_1000_SX; 31576c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_MODE) & BGE_MACMODE_HALF_DUPLEX) 31586c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_HDX; 31596c8d8eccSSepherosa Ziehau else 31606c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_FDX; 31616c8d8eccSSepherosa Ziehau } else { 31626c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 31636c8d8eccSSepherosa Ziehau 31646c8d8eccSSepherosa Ziehau mii_pollstat(mii); 31656c8d8eccSSepherosa Ziehau ifmr->ifm_active = mii->mii_media_active; 31666c8d8eccSSepherosa Ziehau ifmr->ifm_status = mii->mii_media_status; 31676c8d8eccSSepherosa Ziehau } 31686c8d8eccSSepherosa Ziehau } 31696c8d8eccSSepherosa Ziehau 31706c8d8eccSSepherosa Ziehau static int 31716c8d8eccSSepherosa Ziehau bnx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) 31726c8d8eccSSepherosa Ziehau { 31736c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 31746c8d8eccSSepherosa Ziehau struct ifreq *ifr = (struct ifreq *)data; 31756c8d8eccSSepherosa Ziehau int mask, error = 0; 31766c8d8eccSSepherosa Ziehau 3177329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 31786c8d8eccSSepherosa Ziehau 31796c8d8eccSSepherosa Ziehau switch (command) { 31806c8d8eccSSepherosa Ziehau case SIOCSIFMTU: 31816c8d8eccSSepherosa Ziehau if ((!BNX_IS_JUMBO_CAPABLE(sc) && ifr->ifr_mtu > ETHERMTU) || 31826c8d8eccSSepherosa Ziehau (BNX_IS_JUMBO_CAPABLE(sc) && 31836c8d8eccSSepherosa Ziehau ifr->ifr_mtu > BNX_JUMBO_MTU)) { 31846c8d8eccSSepherosa Ziehau error = EINVAL; 31856c8d8eccSSepherosa Ziehau } else if (ifp->if_mtu != ifr->ifr_mtu) { 31866c8d8eccSSepherosa Ziehau ifp->if_mtu = ifr->ifr_mtu; 31876c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 31886c8d8eccSSepherosa Ziehau bnx_init(sc); 31896c8d8eccSSepherosa Ziehau } 31906c8d8eccSSepherosa Ziehau break; 31916c8d8eccSSepherosa Ziehau case SIOCSIFFLAGS: 31926c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 31936c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 31946c8d8eccSSepherosa Ziehau mask = ifp->if_flags ^ sc->bnx_if_flags; 31956c8d8eccSSepherosa Ziehau 31966c8d8eccSSepherosa Ziehau /* 31976c8d8eccSSepherosa Ziehau * If only the state of the PROMISC flag 31986c8d8eccSSepherosa Ziehau * changed, then just use the 'set promisc 31996c8d8eccSSepherosa Ziehau * mode' command instead of reinitializing 32006c8d8eccSSepherosa Ziehau * the entire NIC. Doing a full re-init 32016c8d8eccSSepherosa Ziehau * means reloading the firmware and waiting 32026c8d8eccSSepherosa Ziehau * for it to start up, which may take a 32036c8d8eccSSepherosa Ziehau * second or two. Similarly for ALLMULTI. 32046c8d8eccSSepherosa Ziehau */ 32056c8d8eccSSepherosa Ziehau if (mask & IFF_PROMISC) 32066c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 32076c8d8eccSSepherosa Ziehau if (mask & IFF_ALLMULTI) 32086c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 32096c8d8eccSSepherosa Ziehau } else { 32106c8d8eccSSepherosa Ziehau bnx_init(sc); 32116c8d8eccSSepherosa Ziehau } 32126c8d8eccSSepherosa Ziehau } else if (ifp->if_flags & IFF_RUNNING) { 32136c8d8eccSSepherosa Ziehau bnx_stop(sc); 32146c8d8eccSSepherosa Ziehau } 32156c8d8eccSSepherosa Ziehau sc->bnx_if_flags = ifp->if_flags; 32166c8d8eccSSepherosa Ziehau break; 32176c8d8eccSSepherosa Ziehau case SIOCADDMULTI: 32186c8d8eccSSepherosa Ziehau case SIOCDELMULTI: 32196c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 32206c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 32216c8d8eccSSepherosa Ziehau break; 32226c8d8eccSSepherosa Ziehau case SIOCSIFMEDIA: 32236c8d8eccSSepherosa Ziehau case SIOCGIFMEDIA: 32246c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 32256c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 32266c8d8eccSSepherosa Ziehau &sc->bnx_ifmedia, command); 32276c8d8eccSSepherosa Ziehau } else { 32286c8d8eccSSepherosa Ziehau struct mii_data *mii; 32296c8d8eccSSepherosa Ziehau 32306c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 32316c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 32326c8d8eccSSepherosa Ziehau &mii->mii_media, command); 32336c8d8eccSSepherosa Ziehau } 32346c8d8eccSSepherosa Ziehau break; 32356c8d8eccSSepherosa Ziehau case SIOCSIFCAP: 32366c8d8eccSSepherosa Ziehau mask = ifr->ifr_reqcap ^ ifp->if_capenable; 32376c8d8eccSSepherosa Ziehau if (mask & IFCAP_HWCSUM) { 32386c8d8eccSSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_HWCSUM); 323966deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TXCSUM) 324066deb1c1SSepherosa Ziehau ifp->if_hwassist |= BNX_CSUM_FEATURES; 32416c8d8eccSSepherosa Ziehau else 324266deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~BNX_CSUM_FEATURES; 324366deb1c1SSepherosa Ziehau } 324466deb1c1SSepherosa Ziehau if (mask & IFCAP_TSO) { 324566deb1c1SSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_TSO); 324666deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TSO) 324766deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 324866deb1c1SSepherosa Ziehau else 324966deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~CSUM_TSO; 32506c8d8eccSSepherosa Ziehau } 32516c8d8eccSSepherosa Ziehau break; 32526c8d8eccSSepherosa Ziehau default: 32536c8d8eccSSepherosa Ziehau error = ether_ioctl(ifp, command, data); 32546c8d8eccSSepherosa Ziehau break; 32556c8d8eccSSepherosa Ziehau } 32566c8d8eccSSepherosa Ziehau return error; 32576c8d8eccSSepherosa Ziehau } 32586c8d8eccSSepherosa Ziehau 32596c8d8eccSSepherosa Ziehau static void 3260*3397dea6SSepherosa Ziehau bnx_watchdog(struct ifaltq_subque *ifsq) 32616c8d8eccSSepherosa Ziehau { 3262*3397dea6SSepherosa Ziehau struct ifnet *ifp = ifsq_get_ifp(ifsq); 32636c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 3264*3397dea6SSepherosa Ziehau int i; 3265*3397dea6SSepherosa Ziehau 3266*3397dea6SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 32676c8d8eccSSepherosa Ziehau 32686c8d8eccSSepherosa Ziehau if_printf(ifp, "watchdog timeout -- resetting\n"); 32696c8d8eccSSepherosa Ziehau 32706c8d8eccSSepherosa Ziehau bnx_init(sc); 32716c8d8eccSSepherosa Ziehau 3272d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 32736c8d8eccSSepherosa Ziehau 3274*3397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 3275*3397dea6SSepherosa Ziehau ifsq_devstart_sched(sc->bnx_tx_ring[i].bnx_ifsq); 32766c8d8eccSSepherosa Ziehau } 32776c8d8eccSSepherosa Ziehau 32786c8d8eccSSepherosa Ziehau /* 32796c8d8eccSSepherosa Ziehau * Stop the adapter and free any mbufs allocated to the 32806c8d8eccSSepherosa Ziehau * RX and TX lists. 32816c8d8eccSSepherosa Ziehau */ 32826c8d8eccSSepherosa Ziehau static void 32836c8d8eccSSepherosa Ziehau bnx_stop(struct bnx_softc *sc) 32846c8d8eccSSepherosa Ziehau { 32856c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 328633a04907SSepherosa Ziehau int i; 32876c8d8eccSSepherosa Ziehau 3288329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 32896c8d8eccSSepherosa Ziehau 32906c8d8eccSSepherosa Ziehau callout_stop(&sc->bnx_stat_timer); 32916c8d8eccSSepherosa Ziehau 32926c8d8eccSSepherosa Ziehau /* 32936c8d8eccSSepherosa Ziehau * Disable all of the receiver blocks 32946c8d8eccSSepherosa Ziehau */ 32956c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 32966c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 32976c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 32986c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDBDI_MODE, BGE_RBDIMODE_ENABLE); 32996c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 33006c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDC_MODE, BGE_RBDCMODE_ENABLE); 33016c8d8eccSSepherosa Ziehau 33026c8d8eccSSepherosa Ziehau /* 33036c8d8eccSSepherosa Ziehau * Disable all of the transmit blocks 33046c8d8eccSSepherosa Ziehau */ 33056c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 33066c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 33076c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 33086c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDMA_MODE, BGE_RDMAMODE_ENABLE); 33096c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDC_MODE, BGE_SDCMODE_ENABLE); 33106c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 33116c8d8eccSSepherosa Ziehau 33126c8d8eccSSepherosa Ziehau /* 33136c8d8eccSSepherosa Ziehau * Shut down all of the memory managers and related 33146c8d8eccSSepherosa Ziehau * state machines. 33156c8d8eccSSepherosa Ziehau */ 33166c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE); 33176c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_WDMA_MODE, BGE_WDMAMODE_ENABLE); 33186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 33196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 33206c8d8eccSSepherosa Ziehau 33216c8d8eccSSepherosa Ziehau /* Disable host interrupts. */ 33226c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 33236c8d8eccSSepherosa Ziehau 33246c8d8eccSSepherosa Ziehau /* 33256c8d8eccSSepherosa Ziehau * Tell firmware we're shutting down. 33266c8d8eccSSepherosa Ziehau */ 33276c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 33286c8d8eccSSepherosa Ziehau 33296c8d8eccSSepherosa Ziehau /* Free the RX lists. */ 3330beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(&sc->bnx_rx_std_ring); 33316c8d8eccSSepherosa Ziehau 33326c8d8eccSSepherosa Ziehau /* Free jumbo RX list. */ 33336c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 33346c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(sc); 33356c8d8eccSSepherosa Ziehau 33366c8d8eccSSepherosa Ziehau /* Free TX buffers. */ 333733a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 333833a04907SSepherosa Ziehau bnx_free_tx_ring(&sc->bnx_tx_ring[i]); 33396c8d8eccSSepherosa Ziehau 33406c8d8eccSSepherosa Ziehau sc->bnx_status_tag = 0; 33416c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 33426c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 33436c8d8eccSSepherosa Ziehau 33449ed293e0SSepherosa Ziehau ifp->if_flags &= ~IFF_RUNNING; 3345*3397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 3346*3397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 3347*3397dea6SSepherosa Ziehau 3348*3397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 3349*3397dea6SSepherosa Ziehau ifsq_watchdog_stop(&txr->bnx_tx_watchdog); 3350*3397dea6SSepherosa Ziehau } 33516c8d8eccSSepherosa Ziehau } 33526c8d8eccSSepherosa Ziehau 33536c8d8eccSSepherosa Ziehau /* 33546c8d8eccSSepherosa Ziehau * Stop all chip I/O so that the kernel's probe routines don't 33556c8d8eccSSepherosa Ziehau * get confused by errant DMAs when rebooting. 33566c8d8eccSSepherosa Ziehau */ 33576c8d8eccSSepherosa Ziehau static void 33586c8d8eccSSepherosa Ziehau bnx_shutdown(device_t dev) 33596c8d8eccSSepherosa Ziehau { 33606c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33616c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33626c8d8eccSSepherosa Ziehau 3363329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 33646c8d8eccSSepherosa Ziehau bnx_stop(sc); 33656c8d8eccSSepherosa Ziehau bnx_reset(sc); 3366329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 33676c8d8eccSSepherosa Ziehau } 33686c8d8eccSSepherosa Ziehau 33696c8d8eccSSepherosa Ziehau static int 33706c8d8eccSSepherosa Ziehau bnx_suspend(device_t dev) 33716c8d8eccSSepherosa Ziehau { 33726c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33736c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33746c8d8eccSSepherosa Ziehau 3375329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 33766c8d8eccSSepherosa Ziehau bnx_stop(sc); 3377329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 33786c8d8eccSSepherosa Ziehau 33796c8d8eccSSepherosa Ziehau return 0; 33806c8d8eccSSepherosa Ziehau } 33816c8d8eccSSepherosa Ziehau 33826c8d8eccSSepherosa Ziehau static int 33836c8d8eccSSepherosa Ziehau bnx_resume(device_t dev) 33846c8d8eccSSepherosa Ziehau { 33856c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 33866c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33876c8d8eccSSepherosa Ziehau 3388329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 33896c8d8eccSSepherosa Ziehau 33906c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 3391*3397dea6SSepherosa Ziehau int i; 33926c8d8eccSSepherosa Ziehau 3393*3397dea6SSepherosa Ziehau bnx_init(sc); 3394*3397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 3395*3397dea6SSepherosa Ziehau ifsq_devstart_sched(sc->bnx_tx_ring[i].bnx_ifsq); 33966c8d8eccSSepherosa Ziehau } 33976c8d8eccSSepherosa Ziehau 3398329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 33996c8d8eccSSepherosa Ziehau 34006c8d8eccSSepherosa Ziehau return 0; 34016c8d8eccSSepherosa Ziehau } 34026c8d8eccSSepherosa Ziehau 34036c8d8eccSSepherosa Ziehau static void 34046c8d8eccSSepherosa Ziehau bnx_setpromisc(struct bnx_softc *sc) 34056c8d8eccSSepherosa Ziehau { 34066c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 34076c8d8eccSSepherosa Ziehau 34086c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_PROMISC) 34096c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 34106c8d8eccSSepherosa Ziehau else 34116c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 34126c8d8eccSSepherosa Ziehau } 34136c8d8eccSSepherosa Ziehau 34146c8d8eccSSepherosa Ziehau static void 34156c8d8eccSSepherosa Ziehau bnx_dma_free(struct bnx_softc *sc) 34166c8d8eccSSepherosa Ziehau { 3417beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 34186c8d8eccSSepherosa Ziehau int i; 34196c8d8eccSSepherosa Ziehau 3420beedf5beSSepherosa Ziehau /* Destroy RX return rings */ 3421beedf5beSSepherosa Ziehau if (sc->bnx_rx_ret_ring != NULL) { 3422beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 3423beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(&sc->bnx_rx_ret_ring[i]); 3424beedf5beSSepherosa Ziehau kfree(sc->bnx_rx_ret_ring, M_DEVBUF); 3425beedf5beSSepherosa Ziehau } 3426beedf5beSSepherosa Ziehau 34276c8d8eccSSepherosa Ziehau /* Destroy RX mbuf DMA stuffs. */ 3428beedf5beSSepherosa Ziehau if (std->bnx_rx_mtag != NULL) { 34296c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 3430beedf5beSSepherosa Ziehau KKASSERT(std->bnx_rx_std_buf[i].bnx_rx_mbuf == NULL); 3431beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3432beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[i].bnx_rx_dmamap); 34336c8d8eccSSepherosa Ziehau } 3434beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 34356c8d8eccSSepherosa Ziehau } 34366c8d8eccSSepherosa Ziehau 3437beedf5beSSepherosa Ziehau /* Destroy standard RX ring */ 3438beedf5beSSepherosa Ziehau bnx_dma_block_free(std->bnx_rx_std_ring_tag, 3439beedf5beSSepherosa Ziehau std->bnx_rx_std_ring_map, std->bnx_rx_std_ring); 3440beedf5beSSepherosa Ziehau 344133a04907SSepherosa Ziehau /* Destroy TX rings */ 344233a04907SSepherosa Ziehau if (sc->bnx_tx_ring != NULL) { 344333a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 344433a04907SSepherosa Ziehau bnx_destroy_tx_ring(&sc->bnx_tx_ring[i]); 344533a04907SSepherosa Ziehau kfree(sc->bnx_tx_ring, M_DEVBUF); 34466c8d8eccSSepherosa Ziehau } 34476c8d8eccSSepherosa Ziehau 34486c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 34496c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(sc); 34506c8d8eccSSepherosa Ziehau 34516c8d8eccSSepherosa Ziehau /* Destroy status block */ 34526c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_status_tag, 34536c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_status_map, 34546c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_status_block); 34556c8d8eccSSepherosa Ziehau 34566c8d8eccSSepherosa Ziehau /* Destroy the parent tag */ 34576c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_parent_tag != NULL) 34586c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_parent_tag); 34596c8d8eccSSepherosa Ziehau } 34606c8d8eccSSepherosa Ziehau 34616c8d8eccSSepherosa Ziehau static int 3462beedf5beSSepherosa Ziehau bnx_dma_alloc(device_t dev) 34636c8d8eccSSepherosa Ziehau { 3464beedf5beSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 3465beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 34668bd43d5dSSepherosa Ziehau int i, error, mbx; 34676c8d8eccSSepherosa Ziehau 34686c8d8eccSSepherosa Ziehau /* 34696c8d8eccSSepherosa Ziehau * Allocate the parent bus DMA tag appropriate for PCI. 34706c8d8eccSSepherosa Ziehau * 34716c8d8eccSSepherosa Ziehau * All of the NetExtreme/NetLink controllers have 4GB boundary 34726c8d8eccSSepherosa Ziehau * DMA bug. 34736c8d8eccSSepherosa Ziehau * Whenever an address crosses a multiple of the 4GB boundary 34746c8d8eccSSepherosa Ziehau * (including 4GB, 8Gb, 12Gb, etc.) and makes the transition 34756c8d8eccSSepherosa Ziehau * from 0xX_FFFF_FFFF to 0x(X+1)_0000_0000 an internal DMA 34766c8d8eccSSepherosa Ziehau * state machine will lockup and cause the device to hang. 34776c8d8eccSSepherosa Ziehau */ 34786c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(NULL, 1, BGE_DMA_BOUNDARY_4G, 3479beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 3480beedf5beSSepherosa Ziehau BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 34816c8d8eccSSepherosa Ziehau 0, &sc->bnx_cdata.bnx_parent_tag); 34826c8d8eccSSepherosa Ziehau if (error) { 3483beedf5beSSepherosa Ziehau device_printf(dev, "could not create parent DMA tag\n"); 34846c8d8eccSSepherosa Ziehau return error; 34856c8d8eccSSepherosa Ziehau } 34866c8d8eccSSepherosa Ziehau 34876c8d8eccSSepherosa Ziehau /* 34886c8d8eccSSepherosa Ziehau * Create DMA stuffs for status block. 34896c8d8eccSSepherosa Ziehau */ 34906c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STATUS_BLK_SZ, 34916c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_tag, 34926c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_map, 34936c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_status_block, 34946c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_status_block_paddr); 34956c8d8eccSSepherosa Ziehau if (error) { 3496beedf5beSSepherosa Ziehau device_printf(dev, "could not create status block\n"); 34976c8d8eccSSepherosa Ziehau return error; 34986c8d8eccSSepherosa Ziehau } 34996c8d8eccSSepherosa Ziehau 3500beedf5beSSepherosa Ziehau /* 3501beedf5beSSepherosa Ziehau * Create DMA tag and maps for RX mbufs. 3502beedf5beSSepherosa Ziehau */ 3503beedf5beSSepherosa Ziehau std->bnx_sc = sc; 3504329f9016SSepherosa Ziehau lwkt_serialize_init(&std->bnx_rx_std_serialize); 3505beedf5beSSepherosa Ziehau error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0, 3506beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 3507beedf5beSSepherosa Ziehau NULL, NULL, MCLBYTES, 1, MCLBYTES, 3508beedf5beSSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK, &std->bnx_rx_mtag); 3509beedf5beSSepherosa Ziehau if (error) { 3510beedf5beSSepherosa Ziehau device_printf(dev, "could not create RX mbuf DMA tag\n"); 3511beedf5beSSepherosa Ziehau return error; 3512beedf5beSSepherosa Ziehau } 3513beedf5beSSepherosa Ziehau 3514beedf5beSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; ++i) { 3515beedf5beSSepherosa Ziehau error = bus_dmamap_create(std->bnx_rx_mtag, BUS_DMA_WAITOK, 3516beedf5beSSepherosa Ziehau &std->bnx_rx_std_buf[i].bnx_rx_dmamap); 3517beedf5beSSepherosa Ziehau if (error) { 3518beedf5beSSepherosa Ziehau int j; 3519beedf5beSSepherosa Ziehau 3520beedf5beSSepherosa Ziehau for (j = 0; j < i; ++j) { 3521beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3522beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[j].bnx_rx_dmamap); 3523beedf5beSSepherosa Ziehau } 3524beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 3525beedf5beSSepherosa Ziehau std->bnx_rx_mtag = NULL; 3526beedf5beSSepherosa Ziehau 3527beedf5beSSepherosa Ziehau device_printf(dev, 3528beedf5beSSepherosa Ziehau "could not create %dth RX mbuf DMA map\n", i); 3529beedf5beSSepherosa Ziehau return error; 3530beedf5beSSepherosa Ziehau } 3531beedf5beSSepherosa Ziehau } 3532beedf5beSSepherosa Ziehau 3533beedf5beSSepherosa Ziehau /* 3534beedf5beSSepherosa Ziehau * Create DMA stuffs for standard RX ring. 3535beedf5beSSepherosa Ziehau */ 3536beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STD_RX_RING_SZ, 3537beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_tag, 3538beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_map, 3539beedf5beSSepherosa Ziehau (void *)&std->bnx_rx_std_ring, 3540beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_paddr); 3541beedf5beSSepherosa Ziehau if (error) { 3542beedf5beSSepherosa Ziehau device_printf(dev, "could not create std RX ring\n"); 3543beedf5beSSepherosa Ziehau return error; 3544beedf5beSSepherosa Ziehau } 3545beedf5beSSepherosa Ziehau 3546beedf5beSSepherosa Ziehau /* 3547beedf5beSSepherosa Ziehau * Create RX return rings 3548beedf5beSSepherosa Ziehau */ 3549beedf5beSSepherosa Ziehau sc->bnx_rx_ret_ring = kmalloc_cachealign( 3550beedf5beSSepherosa Ziehau sizeof(struct bnx_rx_ret_ring) * sc->bnx_rx_retcnt, M_DEVBUF, 3551beedf5beSSepherosa Ziehau M_WAITOK | M_ZERO); 3552beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) { 3553beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i]; 3554beedf5beSSepherosa Ziehau 3555beedf5beSSepherosa Ziehau ret->bnx_sc = sc; 3556beedf5beSSepherosa Ziehau ret->bnx_std = std; 35573a16b7b8SSepherosa Ziehau 35583a16b7b8SSepherosa Ziehau /* XXX */ 35593a16b7b8SSepherosa Ziehau ret->bnx_rx_considx = 35603a16b7b8SSepherosa Ziehau &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_rx_prod_idx; 35613a16b7b8SSepherosa Ziehau 3562beedf5beSSepherosa Ziehau error = bnx_create_rx_ret_ring(ret); 3563beedf5beSSepherosa Ziehau if (error) { 3564beedf5beSSepherosa Ziehau device_printf(dev, 3565beedf5beSSepherosa Ziehau "could not create %dth RX ret ring\n", i); 3566beedf5beSSepherosa Ziehau return error; 3567beedf5beSSepherosa Ziehau } 3568beedf5beSSepherosa Ziehau } 3569beedf5beSSepherosa Ziehau 3570beedf5beSSepherosa Ziehau /* 3571beedf5beSSepherosa Ziehau * Create TX rings 3572beedf5beSSepherosa Ziehau */ 35738bd43d5dSSepherosa Ziehau mbx = BGE_MBX_TX_HOST_PROD0_LO; 357433a04907SSepherosa Ziehau sc->bnx_tx_ring = kmalloc_cachealign( 357533a04907SSepherosa Ziehau sizeof(struct bnx_tx_ring) * sc->bnx_tx_ringcnt, M_DEVBUF, 357633a04907SSepherosa Ziehau M_WAITOK | M_ZERO); 357733a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 357833a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 357933a04907SSepherosa Ziehau 358033a04907SSepherosa Ziehau txr->bnx_sc = sc; 35818bd43d5dSSepherosa Ziehau txr->bnx_tx_mbx = mbx; 35828bd43d5dSSepherosa Ziehau 35838bd43d5dSSepherosa Ziehau if (mbx & 0x4) 35848bd43d5dSSepherosa Ziehau mbx -= 0x4; 35858bd43d5dSSepherosa Ziehau else 35868bd43d5dSSepherosa Ziehau mbx += 0xc; 35878bd43d5dSSepherosa Ziehau 35883a16b7b8SSepherosa Ziehau /* XXX */ 35893a16b7b8SSepherosa Ziehau txr->bnx_tx_considx = 35903a16b7b8SSepherosa Ziehau &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_tx_cons_idx; 35913a16b7b8SSepherosa Ziehau 359233a04907SSepherosa Ziehau error = bnx_create_tx_ring(txr); 359333a04907SSepherosa Ziehau if (error) { 3594beedf5beSSepherosa Ziehau device_printf(dev, 3595beedf5beSSepherosa Ziehau "could not create %dth TX ring\n", i); 3596beedf5beSSepherosa Ziehau return error; 3597beedf5beSSepherosa Ziehau } 3598beedf5beSSepherosa Ziehau } 3599beedf5beSSepherosa Ziehau 3600beedf5beSSepherosa Ziehau /* 3601beedf5beSSepherosa Ziehau * Create jumbo buffer pool. 3602beedf5beSSepherosa Ziehau */ 3603beedf5beSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 3604beedf5beSSepherosa Ziehau error = bnx_alloc_jumbo_mem(sc); 3605beedf5beSSepherosa Ziehau if (error) { 3606beedf5beSSepherosa Ziehau device_printf(dev, 3607beedf5beSSepherosa Ziehau "could not create jumbo buffer pool\n"); 360833a04907SSepherosa Ziehau return error; 360933a04907SSepherosa Ziehau } 361033a04907SSepherosa Ziehau } 361133a04907SSepherosa Ziehau 36126c8d8eccSSepherosa Ziehau return 0; 36136c8d8eccSSepherosa Ziehau } 36146c8d8eccSSepherosa Ziehau 36156c8d8eccSSepherosa Ziehau static int 36166c8d8eccSSepherosa Ziehau bnx_dma_block_alloc(struct bnx_softc *sc, bus_size_t size, bus_dma_tag_t *tag, 36176c8d8eccSSepherosa Ziehau bus_dmamap_t *map, void **addr, bus_addr_t *paddr) 36186c8d8eccSSepherosa Ziehau { 36196c8d8eccSSepherosa Ziehau bus_dmamem_t dmem; 36206c8d8eccSSepherosa Ziehau int error; 36216c8d8eccSSepherosa Ziehau 36226c8d8eccSSepherosa Ziehau error = bus_dmamem_coherent(sc->bnx_cdata.bnx_parent_tag, PAGE_SIZE, 0, 36236c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 36246c8d8eccSSepherosa Ziehau size, BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmem); 36256c8d8eccSSepherosa Ziehau if (error) 36266c8d8eccSSepherosa Ziehau return error; 36276c8d8eccSSepherosa Ziehau 36286c8d8eccSSepherosa Ziehau *tag = dmem.dmem_tag; 36296c8d8eccSSepherosa Ziehau *map = dmem.dmem_map; 36306c8d8eccSSepherosa Ziehau *addr = dmem.dmem_addr; 36316c8d8eccSSepherosa Ziehau *paddr = dmem.dmem_busaddr; 36326c8d8eccSSepherosa Ziehau 36336c8d8eccSSepherosa Ziehau return 0; 36346c8d8eccSSepherosa Ziehau } 36356c8d8eccSSepherosa Ziehau 36366c8d8eccSSepherosa Ziehau static void 36376c8d8eccSSepherosa Ziehau bnx_dma_block_free(bus_dma_tag_t tag, bus_dmamap_t map, void *addr) 36386c8d8eccSSepherosa Ziehau { 36396c8d8eccSSepherosa Ziehau if (tag != NULL) { 36406c8d8eccSSepherosa Ziehau bus_dmamap_unload(tag, map); 36416c8d8eccSSepherosa Ziehau bus_dmamem_free(tag, addr, map); 36426c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(tag); 36436c8d8eccSSepherosa Ziehau } 36446c8d8eccSSepherosa Ziehau } 36456c8d8eccSSepherosa Ziehau 36466c8d8eccSSepherosa Ziehau static void 36476c8d8eccSSepherosa Ziehau bnx_tbi_link_upd(struct bnx_softc *sc, uint32_t status) 36486c8d8eccSSepherosa Ziehau { 36496c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 36506c8d8eccSSepherosa Ziehau 36516c8d8eccSSepherosa Ziehau #define PCS_ENCODE_ERR (BGE_MACSTAT_PORT_DECODE_ERROR|BGE_MACSTAT_MI_COMPLETE) 36526c8d8eccSSepherosa Ziehau 36536c8d8eccSSepherosa Ziehau /* 36546c8d8eccSSepherosa Ziehau * Sometimes PCS encoding errors are detected in 36556c8d8eccSSepherosa Ziehau * TBI mode (on fiber NICs), and for some reason 36566c8d8eccSSepherosa Ziehau * the chip will signal them as link changes. 36576c8d8eccSSepherosa Ziehau * If we get a link change event, but the 'PCS 36586c8d8eccSSepherosa Ziehau * encoding error' bit in the MAC status register 36596c8d8eccSSepherosa Ziehau * is set, don't bother doing a link check. 36606c8d8eccSSepherosa Ziehau * This avoids spurious "gigabit link up" messages 36616c8d8eccSSepherosa Ziehau * that sometimes appear on fiber NICs during 36626c8d8eccSSepherosa Ziehau * periods of heavy traffic. 36636c8d8eccSSepherosa Ziehau */ 36646c8d8eccSSepherosa Ziehau if (status & BGE_MACSTAT_TBI_PCS_SYNCHED) { 36656c8d8eccSSepherosa Ziehau if (!sc->bnx_link) { 36666c8d8eccSSepherosa Ziehau sc->bnx_link++; 36676c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704) { 36686c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 36696c8d8eccSSepherosa Ziehau BGE_MACMODE_TBI_SEND_CFGS); 36706c8d8eccSSepherosa Ziehau } 36716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, 0xFFFFFFFF); 36726c8d8eccSSepherosa Ziehau 36736c8d8eccSSepherosa Ziehau if (bootverbose) 36746c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 36756c8d8eccSSepherosa Ziehau 36766c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_UP; 36776c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 36786c8d8eccSSepherosa Ziehau } 36796c8d8eccSSepherosa Ziehau } else if ((status & PCS_ENCODE_ERR) != PCS_ENCODE_ERR) { 36806c8d8eccSSepherosa Ziehau if (sc->bnx_link) { 36816c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 36826c8d8eccSSepherosa Ziehau 36836c8d8eccSSepherosa Ziehau if (bootverbose) 36846c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 36856c8d8eccSSepherosa Ziehau 36866c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_DOWN; 36876c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 36886c8d8eccSSepherosa Ziehau } 36896c8d8eccSSepherosa Ziehau } 36906c8d8eccSSepherosa Ziehau 36916c8d8eccSSepherosa Ziehau #undef PCS_ENCODE_ERR 36926c8d8eccSSepherosa Ziehau 36936c8d8eccSSepherosa Ziehau /* Clear the attention. */ 36946c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 36956c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 36966c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 36976c8d8eccSSepherosa Ziehau } 36986c8d8eccSSepherosa Ziehau 36996c8d8eccSSepherosa Ziehau static void 37006c8d8eccSSepherosa Ziehau bnx_copper_link_upd(struct bnx_softc *sc, uint32_t status __unused) 37016c8d8eccSSepherosa Ziehau { 37026c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 37036c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 37046c8d8eccSSepherosa Ziehau 37056c8d8eccSSepherosa Ziehau mii_pollstat(mii); 37066c8d8eccSSepherosa Ziehau bnx_miibus_statchg(sc->bnx_dev); 37076c8d8eccSSepherosa Ziehau 37086c8d8eccSSepherosa Ziehau if (bootverbose) { 37096c8d8eccSSepherosa Ziehau if (sc->bnx_link) 37106c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 37116c8d8eccSSepherosa Ziehau else 37126c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 37136c8d8eccSSepherosa Ziehau } 37146c8d8eccSSepherosa Ziehau 37156c8d8eccSSepherosa Ziehau /* Clear the attention. */ 37166c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 37176c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 37186c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 37196c8d8eccSSepherosa Ziehau } 37206c8d8eccSSepherosa Ziehau 37216c8d8eccSSepherosa Ziehau static void 37226c8d8eccSSepherosa Ziehau bnx_autopoll_link_upd(struct bnx_softc *sc, uint32_t status __unused) 37236c8d8eccSSepherosa Ziehau { 37246c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 37256c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 37266c8d8eccSSepherosa Ziehau 37276c8d8eccSSepherosa Ziehau mii_pollstat(mii); 37286c8d8eccSSepherosa Ziehau 37296c8d8eccSSepherosa Ziehau if (!sc->bnx_link && 37306c8d8eccSSepherosa Ziehau (mii->mii_media_status & IFM_ACTIVE) && 37316c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 37326c8d8eccSSepherosa Ziehau sc->bnx_link++; 37336c8d8eccSSepherosa Ziehau if (bootverbose) 37346c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 37356c8d8eccSSepherosa Ziehau } else if (sc->bnx_link && 37366c8d8eccSSepherosa Ziehau (!(mii->mii_media_status & IFM_ACTIVE) || 37376c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)) { 37386c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 37396c8d8eccSSepherosa Ziehau if (bootverbose) 37406c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 37416c8d8eccSSepherosa Ziehau } 37426c8d8eccSSepherosa Ziehau 37436c8d8eccSSepherosa Ziehau /* Clear the attention. */ 37446c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 37456c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 37466c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 37476c8d8eccSSepherosa Ziehau } 37486c8d8eccSSepherosa Ziehau 37496c8d8eccSSepherosa Ziehau static int 37506c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS) 37516c8d8eccSSepherosa Ziehau { 37526c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37536c8d8eccSSepherosa Ziehau 37546c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37556c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_ticks, 37566c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_MIN, BNX_RX_COAL_TICKS_MAX, 37576c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_CHG); 37586c8d8eccSSepherosa Ziehau } 37596c8d8eccSSepherosa Ziehau 37606c8d8eccSSepherosa Ziehau static int 37616c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS) 37626c8d8eccSSepherosa Ziehau { 37636c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37646c8d8eccSSepherosa Ziehau 37656c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37666c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_ticks, 37676c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_MIN, BNX_TX_COAL_TICKS_MAX, 37686c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_CHG); 37696c8d8eccSSepherosa Ziehau } 37706c8d8eccSSepherosa Ziehau 37716c8d8eccSSepherosa Ziehau static int 37726c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS) 37736c8d8eccSSepherosa Ziehau { 37746c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37756c8d8eccSSepherosa Ziehau 37766c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37776c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds, 37786c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 37796c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_CHG); 37806c8d8eccSSepherosa Ziehau } 37816c8d8eccSSepherosa Ziehau 37826c8d8eccSSepherosa Ziehau static int 37836c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS) 37846c8d8eccSSepherosa Ziehau { 37856c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37866c8d8eccSSepherosa Ziehau 37876c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37886c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds, 37896c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 37906c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_CHG); 37916c8d8eccSSepherosa Ziehau } 37926c8d8eccSSepherosa Ziehau 37936c8d8eccSSepherosa Ziehau static int 37946c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS) 37956c8d8eccSSepherosa Ziehau { 37966c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 37976c8d8eccSSepherosa Ziehau 37986c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 37996c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds_int, 38006c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 38016c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_INT_CHG); 38026c8d8eccSSepherosa Ziehau } 38036c8d8eccSSepherosa Ziehau 38046c8d8eccSSepherosa Ziehau static int 38056c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS) 38066c8d8eccSSepherosa Ziehau { 38076c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38086c8d8eccSSepherosa Ziehau 38096c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38106c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds_int, 38116c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 38126c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_INT_CHG); 38136c8d8eccSSepherosa Ziehau } 38146c8d8eccSSepherosa Ziehau 38156c8d8eccSSepherosa Ziehau static int 38166c8d8eccSSepherosa Ziehau bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *coal, 38176c8d8eccSSepherosa Ziehau int coal_min, int coal_max, uint32_t coal_chg_mask) 38186c8d8eccSSepherosa Ziehau { 38196c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38206c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38216c8d8eccSSepherosa Ziehau int error = 0, v; 38226c8d8eccSSepherosa Ziehau 3823329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 38246c8d8eccSSepherosa Ziehau 38256c8d8eccSSepherosa Ziehau v = *coal; 38266c8d8eccSSepherosa Ziehau error = sysctl_handle_int(oidp, &v, 0, req); 38276c8d8eccSSepherosa Ziehau if (!error && req->newptr != NULL) { 38286c8d8eccSSepherosa Ziehau if (v < coal_min || v > coal_max) { 38296c8d8eccSSepherosa Ziehau error = EINVAL; 38306c8d8eccSSepherosa Ziehau } else { 38316c8d8eccSSepherosa Ziehau *coal = v; 38326c8d8eccSSepherosa Ziehau sc->bnx_coal_chg |= coal_chg_mask; 3833f5014362SSepherosa Ziehau 3834f5014362SSepherosa Ziehau /* Commit changes */ 3835f5014362SSepherosa Ziehau bnx_coal_change(sc); 38366c8d8eccSSepherosa Ziehau } 38376c8d8eccSSepherosa Ziehau } 38386c8d8eccSSepherosa Ziehau 3839329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 38406c8d8eccSSepherosa Ziehau return error; 38416c8d8eccSSepherosa Ziehau } 38426c8d8eccSSepherosa Ziehau 38436c8d8eccSSepherosa Ziehau static void 38446c8d8eccSSepherosa Ziehau bnx_coal_change(struct bnx_softc *sc) 38456c8d8eccSSepherosa Ziehau { 38466c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38476c8d8eccSSepherosa Ziehau 3848329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 38496c8d8eccSSepherosa Ziehau 38506c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_TICKS_CHG) { 38516c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, 38526c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 38536c8d8eccSSepherosa Ziehau DELAY(10); 3854e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_COAL_TICKS); 38556c8d8eccSSepherosa Ziehau 38566c8d8eccSSepherosa Ziehau if (bootverbose) { 38576c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_ticks -> %u\n", 38586c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 38596c8d8eccSSepherosa Ziehau } 38606c8d8eccSSepherosa Ziehau } 38616c8d8eccSSepherosa Ziehau 38626c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_TICKS_CHG) { 38636c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, 38646c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 38656c8d8eccSSepherosa Ziehau DELAY(10); 3866e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_COAL_TICKS); 38676c8d8eccSSepherosa Ziehau 38686c8d8eccSSepherosa Ziehau if (bootverbose) { 38696c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_ticks -> %u\n", 38706c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 38716c8d8eccSSepherosa Ziehau } 38726c8d8eccSSepherosa Ziehau } 38736c8d8eccSSepherosa Ziehau 38746c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_CHG) { 38756c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, 38766c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 38776c8d8eccSSepherosa Ziehau DELAY(10); 3878e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS); 38796c8d8eccSSepherosa Ziehau 38806c8d8eccSSepherosa Ziehau if (bootverbose) { 38816c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds -> %u\n", 38826c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 38836c8d8eccSSepherosa Ziehau } 38846c8d8eccSSepherosa Ziehau } 38856c8d8eccSSepherosa Ziehau 38866c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_CHG) { 38876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, 38886c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 38896c8d8eccSSepherosa Ziehau DELAY(10); 3890e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS); 38916c8d8eccSSepherosa Ziehau 38926c8d8eccSSepherosa Ziehau if (bootverbose) { 3893cc98a7c2SSepherosa Ziehau if_printf(ifp, "tx_coal_bds -> %u\n", 38946c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 38956c8d8eccSSepherosa Ziehau } 38966c8d8eccSSepherosa Ziehau } 38976c8d8eccSSepherosa Ziehau 38986c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_INT_CHG) { 38996c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, 39006c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 39016c8d8eccSSepherosa Ziehau DELAY(10); 3902e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT); 39036c8d8eccSSepherosa Ziehau 39046c8d8eccSSepherosa Ziehau if (bootverbose) { 39056c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds_int -> %u\n", 39066c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 39076c8d8eccSSepherosa Ziehau } 39086c8d8eccSSepherosa Ziehau } 39096c8d8eccSSepherosa Ziehau 39106c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_INT_CHG) { 39116c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, 39126c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 39136c8d8eccSSepherosa Ziehau DELAY(10); 3914e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT); 39156c8d8eccSSepherosa Ziehau 39166c8d8eccSSepherosa Ziehau if (bootverbose) { 39176c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_bds_int -> %u\n", 39186c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 39196c8d8eccSSepherosa Ziehau } 39206c8d8eccSSepherosa Ziehau } 39216c8d8eccSSepherosa Ziehau 39226c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 39236c8d8eccSSepherosa Ziehau } 39246c8d8eccSSepherosa Ziehau 39256c8d8eccSSepherosa Ziehau static void 3926f33ac8a4SSepherosa Ziehau bnx_check_intr(void *xintr) 3927df9ccc98SSepherosa Ziehau { 3928f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = xintr; 3929f33ac8a4SSepherosa Ziehau struct bnx_rx_ret_ring *ret; 3930f33ac8a4SSepherosa Ziehau struct bnx_tx_ring *txr; 3931f33ac8a4SSepherosa Ziehau struct ifnet *ifp; 3932df9ccc98SSepherosa Ziehau 3933f33ac8a4SSepherosa Ziehau lwkt_serialize_enter(intr->bnx_intr_serialize); 3934df9ccc98SSepherosa Ziehau 3935f33ac8a4SSepherosa Ziehau KKASSERT(mycpuid == intr->bnx_intr_cpuid); 3936df9ccc98SSepherosa Ziehau 3937f33ac8a4SSepherosa Ziehau ifp = &intr->bnx_sc->arpcom.ac_if; 393839a8d43aSSepherosa Ziehau if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) { 3939f33ac8a4SSepherosa Ziehau lwkt_serialize_exit(intr->bnx_intr_serialize); 3940df9ccc98SSepherosa Ziehau return; 3941df9ccc98SSepherosa Ziehau } 3942df9ccc98SSepherosa Ziehau 3943f33ac8a4SSepherosa Ziehau txr = intr->bnx_txr; 3944f33ac8a4SSepherosa Ziehau ret = intr->bnx_ret; 3945f33ac8a4SSepherosa Ziehau 39463a16b7b8SSepherosa Ziehau if (*ret->bnx_rx_considx != ret->bnx_rx_saved_considx || 39473a16b7b8SSepherosa Ziehau *txr->bnx_tx_considx != txr->bnx_tx_saved_considx) { 3948f33ac8a4SSepherosa Ziehau if (intr->bnx_rx_check_considx == ret->bnx_rx_saved_considx && 3949f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx == txr->bnx_tx_saved_considx) { 3950f33ac8a4SSepherosa Ziehau if (!intr->bnx_intr_maylose) { 3951f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = TRUE; 3952df9ccc98SSepherosa Ziehau goto done; 3953df9ccc98SSepherosa Ziehau } 3954df9ccc98SSepherosa Ziehau if (bootverbose) 3955df9ccc98SSepherosa Ziehau if_printf(ifp, "lost interrupt\n"); 3956f33ac8a4SSepherosa Ziehau intr->bnx_intr_func(intr->bnx_intr_arg); 3957df9ccc98SSepherosa Ziehau } 3958df9ccc98SSepherosa Ziehau } 3959f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 3960f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = ret->bnx_rx_saved_considx; 3961f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = txr->bnx_tx_saved_considx; 3962df9ccc98SSepherosa Ziehau 3963df9ccc98SSepherosa Ziehau done: 3964f33ac8a4SSepherosa Ziehau callout_reset(&intr->bnx_intr_timer, BNX_INTR_CKINTVL, 3965f33ac8a4SSepherosa Ziehau intr->bnx_intr_check, intr); 3966f33ac8a4SSepherosa Ziehau lwkt_serialize_exit(intr->bnx_intr_serialize); 3967df9ccc98SSepherosa Ziehau } 3968df9ccc98SSepherosa Ziehau 3969df9ccc98SSepherosa Ziehau static void 39706c8d8eccSSepherosa Ziehau bnx_enable_intr(struct bnx_softc *sc) 39716c8d8eccSSepherosa Ziehau { 39726c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 3973f33ac8a4SSepherosa Ziehau int i; 39746c8d8eccSSepherosa Ziehau 3975f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 3976f33ac8a4SSepherosa Ziehau lwkt_serialize_handler_enable( 3977f33ac8a4SSepherosa Ziehau sc->bnx_intr_data[i].bnx_intr_serialize); 3978f33ac8a4SSepherosa Ziehau } 39796c8d8eccSSepherosa Ziehau 39806c8d8eccSSepherosa Ziehau /* 39816c8d8eccSSepherosa Ziehau * Enable interrupt. 39826c8d8eccSSepherosa Ziehau */ 39836c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 39846c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 39856c8d8eccSSepherosa Ziehau /* XXX Linux driver */ 39866c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 39876c8d8eccSSepherosa Ziehau } 39886c8d8eccSSepherosa Ziehau 39896c8d8eccSSepherosa Ziehau /* 39906c8d8eccSSepherosa Ziehau * Unmask the interrupt when we stop polling. 39916c8d8eccSSepherosa Ziehau */ 39926c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 39936c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 39946c8d8eccSSepherosa Ziehau 39956c8d8eccSSepherosa Ziehau /* 39966c8d8eccSSepherosa Ziehau * Trigger another interrupt, since above writing 39976c8d8eccSSepherosa Ziehau * to interrupt mailbox0 may acknowledge pending 39986c8d8eccSSepherosa Ziehau * interrupt. 39996c8d8eccSSepherosa Ziehau */ 40006c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET); 4001df9ccc98SSepherosa Ziehau 4002df9ccc98SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_STATUSTAG_BUG) { 4003df9ccc98SSepherosa Ziehau if (bootverbose) 4004df9ccc98SSepherosa Ziehau if_printf(ifp, "status tag bug workaround\n"); 4005df9ccc98SSepherosa Ziehau 4006f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4007f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4008f33ac8a4SSepherosa Ziehau 4009f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 4010f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = 0; 4011f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = 0; 4012f33ac8a4SSepherosa Ziehau callout_reset_bycpu(&intr->bnx_intr_timer, 4013f33ac8a4SSepherosa Ziehau BNX_INTR_CKINTVL, intr->bnx_intr_check, intr, 4014f33ac8a4SSepherosa Ziehau intr->bnx_intr_cpuid); 4015f33ac8a4SSepherosa Ziehau } 4016df9ccc98SSepherosa Ziehau } 40176c8d8eccSSepherosa Ziehau } 40186c8d8eccSSepherosa Ziehau 40196c8d8eccSSepherosa Ziehau static void 40206c8d8eccSSepherosa Ziehau bnx_disable_intr(struct bnx_softc *sc) 40216c8d8eccSSepherosa Ziehau { 4022f33ac8a4SSepherosa Ziehau int i; 4023f33ac8a4SSepherosa Ziehau 4024f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4025f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4026f33ac8a4SSepherosa Ziehau 4027f33ac8a4SSepherosa Ziehau callout_stop(&intr->bnx_intr_timer); 4028f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 4029f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = 0; 4030f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = 0; 4031f33ac8a4SSepherosa Ziehau } 40326c8d8eccSSepherosa Ziehau 40336c8d8eccSSepherosa Ziehau /* 40346c8d8eccSSepherosa Ziehau * Mask the interrupt when we start polling. 40356c8d8eccSSepherosa Ziehau */ 40366c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 40376c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 40386c8d8eccSSepherosa Ziehau 40396c8d8eccSSepherosa Ziehau /* 40406c8d8eccSSepherosa Ziehau * Acknowledge possible asserted interrupt. 40416c8d8eccSSepherosa Ziehau */ 40426c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 40436c8d8eccSSepherosa Ziehau 4044b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = 0; 4045f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4046f33ac8a4SSepherosa Ziehau lwkt_serialize_handler_disable( 4047f33ac8a4SSepherosa Ziehau sc->bnx_intr_data[i].bnx_intr_serialize); 4048f33ac8a4SSepherosa Ziehau } 40496c8d8eccSSepherosa Ziehau } 40506c8d8eccSSepherosa Ziehau 40516c8d8eccSSepherosa Ziehau static int 40526c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem(struct bnx_softc *sc, uint8_t ether_addr[]) 40536c8d8eccSSepherosa Ziehau { 40546c8d8eccSSepherosa Ziehau uint32_t mac_addr; 40556c8d8eccSSepherosa Ziehau int ret = 1; 40566c8d8eccSSepherosa Ziehau 40576c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c14); 40586c8d8eccSSepherosa Ziehau if ((mac_addr >> 16) == 0x484b) { 40596c8d8eccSSepherosa Ziehau ether_addr[0] = (uint8_t)(mac_addr >> 8); 40606c8d8eccSSepherosa Ziehau ether_addr[1] = (uint8_t)mac_addr; 40616c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c18); 40626c8d8eccSSepherosa Ziehau ether_addr[2] = (uint8_t)(mac_addr >> 24); 40636c8d8eccSSepherosa Ziehau ether_addr[3] = (uint8_t)(mac_addr >> 16); 40646c8d8eccSSepherosa Ziehau ether_addr[4] = (uint8_t)(mac_addr >> 8); 40656c8d8eccSSepherosa Ziehau ether_addr[5] = (uint8_t)mac_addr; 40666c8d8eccSSepherosa Ziehau ret = 0; 40676c8d8eccSSepherosa Ziehau } 40686c8d8eccSSepherosa Ziehau return ret; 40696c8d8eccSSepherosa Ziehau } 40706c8d8eccSSepherosa Ziehau 40716c8d8eccSSepherosa Ziehau static int 40726c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram(struct bnx_softc *sc, uint8_t ether_addr[]) 40736c8d8eccSSepherosa Ziehau { 40746c8d8eccSSepherosa Ziehau int mac_offset = BGE_EE_MAC_OFFSET; 40756c8d8eccSSepherosa Ziehau 407680969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 407780969639SSepherosa Ziehau int f; 407880969639SSepherosa Ziehau 407980969639SSepherosa Ziehau f = pci_get_function(sc->bnx_dev); 408080969639SSepherosa Ziehau if (f & 1) 408180969639SSepherosa Ziehau mac_offset = BGE_EE_MAC_OFFSET_5717; 408280969639SSepherosa Ziehau if (f > 1) 408380969639SSepherosa Ziehau mac_offset += BGE_EE_MAC_OFFSET_5717_OFF; 408480969639SSepherosa Ziehau } 40856c8d8eccSSepherosa Ziehau 40866c8d8eccSSepherosa Ziehau return bnx_read_nvram(sc, ether_addr, mac_offset + 2, ETHER_ADDR_LEN); 40876c8d8eccSSepherosa Ziehau } 40886c8d8eccSSepherosa Ziehau 40896c8d8eccSSepherosa Ziehau static int 40906c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom(struct bnx_softc *sc, uint8_t ether_addr[]) 40916c8d8eccSSepherosa Ziehau { 40926c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_NO_EEPROM) 40936c8d8eccSSepherosa Ziehau return 1; 40946c8d8eccSSepherosa Ziehau 40956c8d8eccSSepherosa Ziehau return bnx_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2, 40966c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN); 40976c8d8eccSSepherosa Ziehau } 40986c8d8eccSSepherosa Ziehau 40996c8d8eccSSepherosa Ziehau static int 41006c8d8eccSSepherosa Ziehau bnx_get_eaddr(struct bnx_softc *sc, uint8_t eaddr[]) 41016c8d8eccSSepherosa Ziehau { 41026c8d8eccSSepherosa Ziehau static const bnx_eaddr_fcn_t bnx_eaddr_funcs[] = { 41036c8d8eccSSepherosa Ziehau /* NOTE: Order is critical */ 41046c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem, 41056c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram, 41066c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom, 41076c8d8eccSSepherosa Ziehau NULL 41086c8d8eccSSepherosa Ziehau }; 41096c8d8eccSSepherosa Ziehau const bnx_eaddr_fcn_t *func; 41106c8d8eccSSepherosa Ziehau 41116c8d8eccSSepherosa Ziehau for (func = bnx_eaddr_funcs; *func != NULL; ++func) { 41126c8d8eccSSepherosa Ziehau if ((*func)(sc, eaddr) == 0) 41136c8d8eccSSepherosa Ziehau break; 41146c8d8eccSSepherosa Ziehau } 41156c8d8eccSSepherosa Ziehau return (*func == NULL ? ENXIO : 0); 41166c8d8eccSSepherosa Ziehau } 41176c8d8eccSSepherosa Ziehau 41186c8d8eccSSepherosa Ziehau /* 41196c8d8eccSSepherosa Ziehau * NOTE: 'm' is not freed upon failure 41206c8d8eccSSepherosa Ziehau */ 41216c8d8eccSSepherosa Ziehau struct mbuf * 41226c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *m) 41236c8d8eccSSepherosa Ziehau { 41246c8d8eccSSepherosa Ziehau struct mbuf *n; 41256c8d8eccSSepherosa Ziehau int found; 41266c8d8eccSSepherosa Ziehau 41276c8d8eccSSepherosa Ziehau /* 41286c8d8eccSSepherosa Ziehau * If device receive two back-to-back send BDs with less than 41296c8d8eccSSepherosa Ziehau * or equal to 8 total bytes then the device may hang. The two 41306c8d8eccSSepherosa Ziehau * back-to-back send BDs must in the same frame for this failure 41316c8d8eccSSepherosa Ziehau * to occur. Scan mbuf chains and see whether two back-to-back 41326c8d8eccSSepherosa Ziehau * send BDs are there. If this is the case, allocate new mbuf 41336c8d8eccSSepherosa Ziehau * and copy the frame to workaround the silicon bug. 41346c8d8eccSSepherosa Ziehau */ 41356c8d8eccSSepherosa Ziehau for (n = m, found = 0; n != NULL; n = n->m_next) { 41366c8d8eccSSepherosa Ziehau if (n->m_len < 8) { 41376c8d8eccSSepherosa Ziehau found++; 41386c8d8eccSSepherosa Ziehau if (found > 1) 41396c8d8eccSSepherosa Ziehau break; 41406c8d8eccSSepherosa Ziehau continue; 41416c8d8eccSSepherosa Ziehau } 41426c8d8eccSSepherosa Ziehau found = 0; 41436c8d8eccSSepherosa Ziehau } 41446c8d8eccSSepherosa Ziehau 41456c8d8eccSSepherosa Ziehau if (found > 1) 41466c8d8eccSSepherosa Ziehau n = m_defrag(m, MB_DONTWAIT); 41476c8d8eccSSepherosa Ziehau else 41486c8d8eccSSepherosa Ziehau n = m; 41496c8d8eccSSepherosa Ziehau return n; 41506c8d8eccSSepherosa Ziehau } 41516c8d8eccSSepherosa Ziehau 41526c8d8eccSSepherosa Ziehau static void 41536c8d8eccSSepherosa Ziehau bnx_stop_block(struct bnx_softc *sc, bus_size_t reg, uint32_t bit) 41546c8d8eccSSepherosa Ziehau { 41556c8d8eccSSepherosa Ziehau int i; 41566c8d8eccSSepherosa Ziehau 41576c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, reg, bit); 41586c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 41596c8d8eccSSepherosa Ziehau if ((CSR_READ_4(sc, reg) & bit) == 0) 41606c8d8eccSSepherosa Ziehau return; 41616c8d8eccSSepherosa Ziehau DELAY(100); 41626c8d8eccSSepherosa Ziehau } 41636c8d8eccSSepherosa Ziehau } 41646c8d8eccSSepherosa Ziehau 41656c8d8eccSSepherosa Ziehau static void 41666c8d8eccSSepherosa Ziehau bnx_link_poll(struct bnx_softc *sc) 41676c8d8eccSSepherosa Ziehau { 41686c8d8eccSSepherosa Ziehau uint32_t status; 41696c8d8eccSSepherosa Ziehau 41706c8d8eccSSepherosa Ziehau status = CSR_READ_4(sc, BGE_MAC_STS); 41716c8d8eccSSepherosa Ziehau if ((status & sc->bnx_link_chg) || sc->bnx_link_evt) { 41726c8d8eccSSepherosa Ziehau sc->bnx_link_evt = 0; 41736c8d8eccSSepherosa Ziehau sc->bnx_link_upd(sc, status); 41746c8d8eccSSepherosa Ziehau } 41756c8d8eccSSepherosa Ziehau } 41766c8d8eccSSepherosa Ziehau 41776c8d8eccSSepherosa Ziehau static void 41786c8d8eccSSepherosa Ziehau bnx_enable_msi(struct bnx_softc *sc) 41796c8d8eccSSepherosa Ziehau { 41806c8d8eccSSepherosa Ziehau uint32_t msi_mode; 41816c8d8eccSSepherosa Ziehau 41826c8d8eccSSepherosa Ziehau msi_mode = CSR_READ_4(sc, BGE_MSI_MODE); 41836c8d8eccSSepherosa Ziehau msi_mode |= BGE_MSIMODE_ENABLE; 41846c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 41856c8d8eccSSepherosa Ziehau /* 41866c8d8eccSSepherosa Ziehau * NOTE: 41876c8d8eccSSepherosa Ziehau * 5718-PG105-R says that "one shot" mode 41886c8d8eccSSepherosa Ziehau * does not work if MSI is used, however, 41896c8d8eccSSepherosa Ziehau * it obviously works. 41906c8d8eccSSepherosa Ziehau */ 41916c8d8eccSSepherosa Ziehau msi_mode &= ~BGE_MSIMODE_ONESHOT_DISABLE; 41926c8d8eccSSepherosa Ziehau } 41936c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MSI_MODE, msi_mode); 41946c8d8eccSSepherosa Ziehau } 41956c8d8eccSSepherosa Ziehau 41966c8d8eccSSepherosa Ziehau static uint32_t 41976c8d8eccSSepherosa Ziehau bnx_dma_swap_options(struct bnx_softc *sc) 41986c8d8eccSSepherosa Ziehau { 41996c8d8eccSSepherosa Ziehau uint32_t dma_options; 42006c8d8eccSSepherosa Ziehau 42016c8d8eccSSepherosa Ziehau dma_options = BGE_MODECTL_WORDSWAP_NONFRAME | 42026c8d8eccSSepherosa Ziehau BGE_MODECTL_BYTESWAP_DATA | BGE_MODECTL_WORDSWAP_DATA; 42036c8d8eccSSepherosa Ziehau #if BYTE_ORDER == BIG_ENDIAN 42046c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_NONFRAME; 42056c8d8eccSSepherosa Ziehau #endif 4206b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 4207b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 42086c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA | 42096c8d8eccSSepherosa Ziehau BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE | 42106c8d8eccSSepherosa Ziehau BGE_MODECTL_HTX2B_ENABLE; 42116c8d8eccSSepherosa Ziehau } 42126c8d8eccSSepherosa Ziehau return dma_options; 42136c8d8eccSSepherosa Ziehau } 421466deb1c1SSepherosa Ziehau 421566deb1c1SSepherosa Ziehau static int 421633a04907SSepherosa Ziehau bnx_setup_tso(struct bnx_tx_ring *txr, struct mbuf **mp, 421766deb1c1SSepherosa Ziehau uint16_t *mss0, uint16_t *flags0) 421866deb1c1SSepherosa Ziehau { 421966deb1c1SSepherosa Ziehau struct mbuf *m; 422066deb1c1SSepherosa Ziehau struct ip *ip; 422166deb1c1SSepherosa Ziehau struct tcphdr *th; 422266deb1c1SSepherosa Ziehau int thoff, iphlen, hoff, hlen; 422366deb1c1SSepherosa Ziehau uint16_t flags, mss; 422466deb1c1SSepherosa Ziehau 4225f7a2269aSSepherosa Ziehau m = *mp; 4226f7a2269aSSepherosa Ziehau KASSERT(M_WRITABLE(m), ("TSO mbuf not writable")); 4227f7a2269aSSepherosa Ziehau 4228f7a2269aSSepherosa Ziehau hoff = m->m_pkthdr.csum_lhlen; 4229f7a2269aSSepherosa Ziehau iphlen = m->m_pkthdr.csum_iphlen; 4230f7a2269aSSepherosa Ziehau thoff = m->m_pkthdr.csum_thlen; 4231f7a2269aSSepherosa Ziehau 4232f7a2269aSSepherosa Ziehau KASSERT(hoff > 0, ("invalid ether header len")); 4233f7a2269aSSepherosa Ziehau KASSERT(iphlen > 0, ("invalid ip header len")); 4234f7a2269aSSepherosa Ziehau KASSERT(thoff > 0, ("invalid tcp header len")); 4235f7a2269aSSepherosa Ziehau 4236f7a2269aSSepherosa Ziehau if (__predict_false(m->m_len < hoff + iphlen + thoff)) { 4237f7a2269aSSepherosa Ziehau m = m_pullup(m, hoff + iphlen + thoff); 4238f7a2269aSSepherosa Ziehau if (m == NULL) { 4239f7a2269aSSepherosa Ziehau *mp = NULL; 4240f7a2269aSSepherosa Ziehau return ENOBUFS; 4241f7a2269aSSepherosa Ziehau } 4242f7a2269aSSepherosa Ziehau *mp = m; 4243f7a2269aSSepherosa Ziehau } 4244f7a2269aSSepherosa Ziehau ip = mtodoff(m, struct ip *, hoff); 4245f7a2269aSSepherosa Ziehau th = mtodoff(m, struct tcphdr *, hoff + iphlen); 4246f7a2269aSSepherosa Ziehau 4247f0336d39SSepherosa Ziehau mss = m->m_pkthdr.tso_segsz; 424866deb1c1SSepherosa Ziehau flags = BGE_TXBDFLAG_CPU_PRE_DMA | BGE_TXBDFLAG_CPU_POST_DMA; 424966deb1c1SSepherosa Ziehau 425066deb1c1SSepherosa Ziehau ip->ip_len = htons(mss + iphlen + thoff); 425166deb1c1SSepherosa Ziehau th->th_sum = 0; 425266deb1c1SSepherosa Ziehau 425366deb1c1SSepherosa Ziehau hlen = (iphlen + thoff) >> 2; 425466deb1c1SSepherosa Ziehau mss |= ((hlen & 0x3) << 14); 425566deb1c1SSepherosa Ziehau flags |= ((hlen & 0xf8) << 7) | ((hlen & 0x4) << 2); 425666deb1c1SSepherosa Ziehau 425766deb1c1SSepherosa Ziehau *mss0 = mss; 425866deb1c1SSepherosa Ziehau *flags0 = flags; 425966deb1c1SSepherosa Ziehau 426066deb1c1SSepherosa Ziehau return 0; 426166deb1c1SSepherosa Ziehau } 426233a04907SSepherosa Ziehau 426333a04907SSepherosa Ziehau static int 426433a04907SSepherosa Ziehau bnx_create_tx_ring(struct bnx_tx_ring *txr) 426533a04907SSepherosa Ziehau { 426633a04907SSepherosa Ziehau bus_size_t txmaxsz, txmaxsegsz; 426733a04907SSepherosa Ziehau int i, error; 426833a04907SSepherosa Ziehau 4269329f9016SSepherosa Ziehau lwkt_serialize_init(&txr->bnx_tx_serialize); 4270329f9016SSepherosa Ziehau 427133a04907SSepherosa Ziehau /* 427233a04907SSepherosa Ziehau * Create DMA tag and maps for TX mbufs. 427333a04907SSepherosa Ziehau */ 427433a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_flags & BNX_FLAG_TSO) 427533a04907SSepherosa Ziehau txmaxsz = IP_MAXPACKET + sizeof(struct ether_vlan_header); 427633a04907SSepherosa Ziehau else 427733a04907SSepherosa Ziehau txmaxsz = BNX_JUMBO_FRAMELEN; 427833a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_asicrev == BGE_ASICREV_BCM57766) 427933a04907SSepherosa Ziehau txmaxsegsz = MCLBYTES; 428033a04907SSepherosa Ziehau else 428133a04907SSepherosa Ziehau txmaxsegsz = PAGE_SIZE; 428233a04907SSepherosa Ziehau error = bus_dma_tag_create(txr->bnx_sc->bnx_cdata.bnx_parent_tag, 428333a04907SSepherosa Ziehau 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 428433a04907SSepherosa Ziehau txmaxsz, BNX_NSEG_NEW, txmaxsegsz, 428533a04907SSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 428633a04907SSepherosa Ziehau &txr->bnx_tx_mtag); 428733a04907SSepherosa Ziehau if (error) { 428833a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4289beedf5beSSepherosa Ziehau "could not create TX mbuf DMA tag\n"); 429033a04907SSepherosa Ziehau return error; 429133a04907SSepherosa Ziehau } 429233a04907SSepherosa Ziehau 429333a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 429433a04907SSepherosa Ziehau error = bus_dmamap_create(txr->bnx_tx_mtag, 429533a04907SSepherosa Ziehau BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 4296fa4b1067SSepherosa Ziehau &txr->bnx_tx_buf[i].bnx_tx_dmamap); 429733a04907SSepherosa Ziehau if (error) { 429833a04907SSepherosa Ziehau int j; 429933a04907SSepherosa Ziehau 430033a04907SSepherosa Ziehau for (j = 0; j < i; ++j) { 430133a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4302fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[j].bnx_tx_dmamap); 430333a04907SSepherosa Ziehau } 430433a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 430533a04907SSepherosa Ziehau txr->bnx_tx_mtag = NULL; 430633a04907SSepherosa Ziehau 430733a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4308beedf5beSSepherosa Ziehau "could not create TX mbuf DMA map\n"); 430933a04907SSepherosa Ziehau return error; 431033a04907SSepherosa Ziehau } 431133a04907SSepherosa Ziehau } 431233a04907SSepherosa Ziehau 431333a04907SSepherosa Ziehau /* 431433a04907SSepherosa Ziehau * Create DMA stuffs for TX ring. 431533a04907SSepherosa Ziehau */ 431633a04907SSepherosa Ziehau error = bnx_dma_block_alloc(txr->bnx_sc, BGE_TX_RING_SZ, 4317beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_tag, 4318beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_map, 4319beedf5beSSepherosa Ziehau (void *)&txr->bnx_tx_ring, 4320beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_paddr); 432133a04907SSepherosa Ziehau if (error) { 432233a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 432333a04907SSepherosa Ziehau "could not create TX ring\n"); 432433a04907SSepherosa Ziehau return error; 432533a04907SSepherosa Ziehau } 432633a04907SSepherosa Ziehau 432779a64343SSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_SHORTDMA; 432833a04907SSepherosa Ziehau txr->bnx_tx_wreg = BNX_TX_WREG_NSEGS; 432933a04907SSepherosa Ziehau 433033a04907SSepherosa Ziehau return 0; 433133a04907SSepherosa Ziehau } 433233a04907SSepherosa Ziehau 433333a04907SSepherosa Ziehau static void 433433a04907SSepherosa Ziehau bnx_destroy_tx_ring(struct bnx_tx_ring *txr) 433533a04907SSepherosa Ziehau { 433633a04907SSepherosa Ziehau /* Destroy TX mbuf DMA stuffs. */ 433733a04907SSepherosa Ziehau if (txr->bnx_tx_mtag != NULL) { 433833a04907SSepherosa Ziehau int i; 433933a04907SSepherosa Ziehau 434033a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 4341fa4b1067SSepherosa Ziehau KKASSERT(txr->bnx_tx_buf[i].bnx_tx_mbuf == NULL); 434233a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4343fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[i].bnx_tx_dmamap); 434433a04907SSepherosa Ziehau } 434533a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 434633a04907SSepherosa Ziehau } 434733a04907SSepherosa Ziehau 434833a04907SSepherosa Ziehau /* Destroy TX ring */ 434933a04907SSepherosa Ziehau bnx_dma_block_free(txr->bnx_tx_ring_tag, 435033a04907SSepherosa Ziehau txr->bnx_tx_ring_map, txr->bnx_tx_ring); 435133a04907SSepherosa Ziehau } 4352aad4de2bSSepherosa Ziehau 4353aad4de2bSSepherosa Ziehau static int 4354aad4de2bSSepherosa Ziehau bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS) 4355aad4de2bSSepherosa Ziehau { 4356aad4de2bSSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4357aad4de2bSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4358aad4de2bSSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4359aad4de2bSSepherosa Ziehau int error, defrag, i; 4360aad4de2bSSepherosa Ziehau 4361aad4de2bSSepherosa Ziehau if (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) 4362aad4de2bSSepherosa Ziehau defrag = 1; 4363aad4de2bSSepherosa Ziehau else 4364aad4de2bSSepherosa Ziehau defrag = 0; 4365aad4de2bSSepherosa Ziehau 4366aad4de2bSSepherosa Ziehau error = sysctl_handle_int(oidp, &defrag, 0, req); 4367aad4de2bSSepherosa Ziehau if (error || req->newptr == NULL) 4368aad4de2bSSepherosa Ziehau return error; 4369aad4de2bSSepherosa Ziehau 4370329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 4371aad4de2bSSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 4372aad4de2bSSepherosa Ziehau txr = &sc->bnx_tx_ring[i]; 4373aad4de2bSSepherosa Ziehau if (defrag) 4374aad4de2bSSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_FORCE_DEFRAG; 4375aad4de2bSSepherosa Ziehau else 4376aad4de2bSSepherosa Ziehau txr->bnx_tx_flags &= ~BNX_TX_FLAG_FORCE_DEFRAG; 4377aad4de2bSSepherosa Ziehau } 4378329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 4379aad4de2bSSepherosa Ziehau 4380aad4de2bSSepherosa Ziehau return 0; 4381aad4de2bSSepherosa Ziehau } 4382472c99c8SSepherosa Ziehau 4383472c99c8SSepherosa Ziehau static int 4384472c99c8SSepherosa Ziehau bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS) 4385472c99c8SSepherosa Ziehau { 4386472c99c8SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4387472c99c8SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4388472c99c8SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4389472c99c8SSepherosa Ziehau int error, tx_wreg, i; 4390472c99c8SSepherosa Ziehau 4391472c99c8SSepherosa Ziehau tx_wreg = txr->bnx_tx_wreg; 4392472c99c8SSepherosa Ziehau error = sysctl_handle_int(oidp, &tx_wreg, 0, req); 4393472c99c8SSepherosa Ziehau if (error || req->newptr == NULL) 4394472c99c8SSepherosa Ziehau return error; 4395472c99c8SSepherosa Ziehau 4396329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 4397472c99c8SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 4398472c99c8SSepherosa Ziehau sc->bnx_tx_ring[i].bnx_tx_wreg = tx_wreg; 4399329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 4400472c99c8SSepherosa Ziehau 4401472c99c8SSepherosa Ziehau return 0; 4402472c99c8SSepherosa Ziehau } 4403beedf5beSSepherosa Ziehau 4404beedf5beSSepherosa Ziehau static int 4405beedf5beSSepherosa Ziehau bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4406beedf5beSSepherosa Ziehau { 4407beedf5beSSepherosa Ziehau int error; 4408beedf5beSSepherosa Ziehau 4409329f9016SSepherosa Ziehau lwkt_serialize_init(&ret->bnx_rx_ret_serialize); 4410329f9016SSepherosa Ziehau 4411beedf5beSSepherosa Ziehau /* 4412beedf5beSSepherosa Ziehau * Create DMA stuffs for RX return ring. 4413beedf5beSSepherosa Ziehau */ 4414beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(ret->bnx_sc, 4415beedf5beSSepherosa Ziehau BGE_RX_RTN_RING_SZ(BNX_RETURN_RING_CNT), 4416beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_tag, 4417beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_map, 4418beedf5beSSepherosa Ziehau (void *)&ret->bnx_rx_ret_ring, 4419beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_paddr); 4420beedf5beSSepherosa Ziehau if (error) { 4421beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4422beedf5beSSepherosa Ziehau "could not create RX ret ring\n"); 4423beedf5beSSepherosa Ziehau return error; 4424beedf5beSSepherosa Ziehau } 4425beedf5beSSepherosa Ziehau 4426beedf5beSSepherosa Ziehau /* Shadow standard ring's RX mbuf DMA tag */ 4427beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = ret->bnx_std->bnx_rx_mtag; 4428beedf5beSSepherosa Ziehau 4429beedf5beSSepherosa Ziehau /* 4430beedf5beSSepherosa Ziehau * Create tmp DMA map for RX mbufs. 4431beedf5beSSepherosa Ziehau */ 4432beedf5beSSepherosa Ziehau error = bus_dmamap_create(ret->bnx_rx_mtag, BUS_DMA_WAITOK, 4433beedf5beSSepherosa Ziehau &ret->bnx_rx_tmpmap); 4434beedf5beSSepherosa Ziehau if (error) { 4435beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4436beedf5beSSepherosa Ziehau "could not create tmp RX mbuf DMA map\n"); 4437beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = NULL; 4438beedf5beSSepherosa Ziehau return error; 4439beedf5beSSepherosa Ziehau } 4440beedf5beSSepherosa Ziehau return 0; 4441beedf5beSSepherosa Ziehau } 4442beedf5beSSepherosa Ziehau 4443beedf5beSSepherosa Ziehau static void 4444beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4445beedf5beSSepherosa Ziehau { 4446beedf5beSSepherosa Ziehau /* Destroy tmp RX mbuf DMA map */ 4447beedf5beSSepherosa Ziehau if (ret->bnx_rx_mtag != NULL) 4448beedf5beSSepherosa Ziehau bus_dmamap_destroy(ret->bnx_rx_mtag, ret->bnx_rx_tmpmap); 4449beedf5beSSepherosa Ziehau 4450beedf5beSSepherosa Ziehau /* Destroy RX return ring */ 4451beedf5beSSepherosa Ziehau bnx_dma_block_free(ret->bnx_rx_ret_ring_tag, 4452beedf5beSSepherosa Ziehau ret->bnx_rx_ret_ring_map, ret->bnx_rx_ret_ring); 4453beedf5beSSepherosa Ziehau } 44540c7da01dSSepherosa Ziehau 44550c7da01dSSepherosa Ziehau static int 44560c7da01dSSepherosa Ziehau bnx_alloc_intr(struct bnx_softc *sc) 44570c7da01dSSepherosa Ziehau { 4458f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr; 44590c7da01dSSepherosa Ziehau u_int intr_flags; 44600c7da01dSSepherosa Ziehau 4461f33ac8a4SSepherosa Ziehau sc->bnx_intr_cnt = 1; 44620c7da01dSSepherosa Ziehau 4463f33ac8a4SSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 4464f33ac8a4SSepherosa Ziehau intr->bnx_sc = sc; 4465f33ac8a4SSepherosa Ziehau intr->bnx_ret = &sc->bnx_rx_ret_ring[0]; 4466f33ac8a4SSepherosa Ziehau intr->bnx_txr = &sc->bnx_tx_ring[0]; 4467f33ac8a4SSepherosa Ziehau intr->bnx_intr_serialize = &sc->bnx_main_serialize; 4468f33ac8a4SSepherosa Ziehau callout_init_mp(&intr->bnx_intr_timer); 4469f33ac8a4SSepherosa Ziehau intr->bnx_intr_check = bnx_check_intr; 4470f33ac8a4SSepherosa Ziehau 4471f33ac8a4SSepherosa Ziehau sc->bnx_intr_type = pci_alloc_1intr(sc->bnx_dev, bnx_msi_enable, 4472f33ac8a4SSepherosa Ziehau &intr->bnx_intr_rid, &intr_flags); 4473f33ac8a4SSepherosa Ziehau 4474f33ac8a4SSepherosa Ziehau intr->bnx_intr_res = bus_alloc_resource_any(sc->bnx_dev, SYS_RES_IRQ, 4475f33ac8a4SSepherosa Ziehau &intr->bnx_intr_rid, intr_flags); 4476f33ac8a4SSepherosa Ziehau if (intr->bnx_intr_res == NULL) { 44770c7da01dSSepherosa Ziehau device_printf(sc->bnx_dev, "could not alloc interrupt\n"); 44780c7da01dSSepherosa Ziehau return ENXIO; 44790c7da01dSSepherosa Ziehau } 44800c7da01dSSepherosa Ziehau 4481f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) { 44820c7da01dSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_ONESHOT_MSI; 44830c7da01dSSepherosa Ziehau bnx_enable_msi(sc); 4484f33ac8a4SSepherosa Ziehau 4485f33ac8a4SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 4486f33ac8a4SSepherosa Ziehau intr->bnx_intr_func = bnx_msi_oneshot; 4487f33ac8a4SSepherosa Ziehau if (bootverbose) 4488f33ac8a4SSepherosa Ziehau device_printf(sc->bnx_dev, "oneshot MSI\n"); 4489f33ac8a4SSepherosa Ziehau } else { 4490f33ac8a4SSepherosa Ziehau intr->bnx_intr_func = bnx_msi; 44910c7da01dSSepherosa Ziehau } 4492f33ac8a4SSepherosa Ziehau } else { 4493f33ac8a4SSepherosa Ziehau intr->bnx_intr_func = bnx_intr_legacy; 4494f33ac8a4SSepherosa Ziehau } 4495f33ac8a4SSepherosa Ziehau intr->bnx_intr_arg = sc; 4496f33ac8a4SSepherosa Ziehau intr->bnx_intr_cpuid = rman_get_cpuid(intr->bnx_intr_res); 4497f33ac8a4SSepherosa Ziehau 4498f33ac8a4SSepherosa Ziehau intr->bnx_txr->bnx_tx_cpuid = intr->bnx_intr_cpuid; 4499f33ac8a4SSepherosa Ziehau 45000c7da01dSSepherosa Ziehau return 0; 45010c7da01dSSepherosa Ziehau } 45020c7da01dSSepherosa Ziehau 45030c7da01dSSepherosa Ziehau static int 45040c7da01dSSepherosa Ziehau bnx_setup_intr(struct bnx_softc *sc) 45050c7da01dSSepherosa Ziehau { 4506f33ac8a4SSepherosa Ziehau int error, i; 45070c7da01dSSepherosa Ziehau 4508f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4509f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4510f33ac8a4SSepherosa Ziehau 4511f33ac8a4SSepherosa Ziehau error = bus_setup_intr_descr(sc->bnx_dev, intr->bnx_intr_res, 4512f33ac8a4SSepherosa Ziehau INTR_MPSAFE, intr->bnx_intr_func, intr->bnx_intr_arg, 4513f33ac8a4SSepherosa Ziehau &intr->bnx_intr_hand, intr->bnx_intr_serialize, 4514f33ac8a4SSepherosa Ziehau intr->bnx_intr_desc); 45150c7da01dSSepherosa Ziehau if (error) { 4516f33ac8a4SSepherosa Ziehau device_printf(sc->bnx_dev, 4517f33ac8a4SSepherosa Ziehau "could not set up %dth intr\n", i); 4518f33ac8a4SSepherosa Ziehau bnx_teardown_intr(sc, i); 45190c7da01dSSepherosa Ziehau return error; 45200c7da01dSSepherosa Ziehau } 4521f33ac8a4SSepherosa Ziehau } 45220c7da01dSSepherosa Ziehau return 0; 45230c7da01dSSepherosa Ziehau } 45240c7da01dSSepherosa Ziehau 45250c7da01dSSepherosa Ziehau static void 4526f33ac8a4SSepherosa Ziehau bnx_teardown_intr(struct bnx_softc *sc, int cnt) 4527f33ac8a4SSepherosa Ziehau { 4528f33ac8a4SSepherosa Ziehau int i; 4529f33ac8a4SSepherosa Ziehau 4530f33ac8a4SSepherosa Ziehau for (i = 0; i < cnt; ++i) { 4531f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4532f33ac8a4SSepherosa Ziehau 4533f33ac8a4SSepherosa Ziehau bus_teardown_intr(sc->bnx_dev, intr->bnx_intr_res, 4534f33ac8a4SSepherosa Ziehau intr->bnx_intr_hand); 4535f33ac8a4SSepherosa Ziehau } 4536f33ac8a4SSepherosa Ziehau } 4537f33ac8a4SSepherosa Ziehau 4538f33ac8a4SSepherosa Ziehau static void 45390c7da01dSSepherosa Ziehau bnx_free_intr(struct bnx_softc *sc) 45400c7da01dSSepherosa Ziehau { 4541f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr; 4542f33ac8a4SSepherosa Ziehau 4543f33ac8a4SSepherosa Ziehau KKASSERT(sc->bnx_intr_cnt <= 1); 4544f33ac8a4SSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 4545f33ac8a4SSepherosa Ziehau 4546f33ac8a4SSepherosa Ziehau if (intr->bnx_intr_res != NULL) { 45470c7da01dSSepherosa Ziehau bus_release_resource(sc->bnx_dev, SYS_RES_IRQ, 4548f33ac8a4SSepherosa Ziehau intr->bnx_intr_rid, intr->bnx_intr_res); 45490c7da01dSSepherosa Ziehau } 4550f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) 45510c7da01dSSepherosa Ziehau pci_release_msi(sc->bnx_dev); 45520c7da01dSSepherosa Ziehau } 4553329f9016SSepherosa Ziehau 4554329f9016SSepherosa Ziehau static void 4555329f9016SSepherosa Ziehau bnx_setup_serialize(struct bnx_softc *sc) 4556329f9016SSepherosa Ziehau { 4557329f9016SSepherosa Ziehau int i, j; 4558329f9016SSepherosa Ziehau 4559329f9016SSepherosa Ziehau /* 4560329f9016SSepherosa Ziehau * Allocate serializer array 4561329f9016SSepherosa Ziehau */ 4562329f9016SSepherosa Ziehau 4563329f9016SSepherosa Ziehau /* Main + RX STD + TX + RX RET */ 4564329f9016SSepherosa Ziehau sc->bnx_serialize_cnt = 1 + 1 + sc->bnx_tx_ringcnt + sc->bnx_rx_retcnt; 4565329f9016SSepherosa Ziehau 4566329f9016SSepherosa Ziehau sc->bnx_serialize = 4567329f9016SSepherosa Ziehau kmalloc(sc->bnx_serialize_cnt * sizeof(struct lwkt_serialize *), 4568329f9016SSepherosa Ziehau M_DEVBUF, M_WAITOK | M_ZERO); 4569329f9016SSepherosa Ziehau 4570329f9016SSepherosa Ziehau /* 4571329f9016SSepherosa Ziehau * Setup serializers 4572329f9016SSepherosa Ziehau * 4573329f9016SSepherosa Ziehau * NOTE: Order is critical 4574329f9016SSepherosa Ziehau */ 4575329f9016SSepherosa Ziehau 4576329f9016SSepherosa Ziehau i = 0; 4577329f9016SSepherosa Ziehau 4578329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4579329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = &sc->bnx_main_serialize; 4580329f9016SSepherosa Ziehau 4581329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4582329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = &sc->bnx_rx_std_ring.bnx_rx_std_serialize; 4583329f9016SSepherosa Ziehau 4584329f9016SSepherosa Ziehau for (j = 0; j < sc->bnx_rx_retcnt; ++j) { 4585329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4586329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = 4587329f9016SSepherosa Ziehau &sc->bnx_rx_ret_ring[j].bnx_rx_ret_serialize; 4588329f9016SSepherosa Ziehau } 4589329f9016SSepherosa Ziehau 4590329f9016SSepherosa Ziehau for (j = 0; j < sc->bnx_tx_ringcnt; ++j) { 4591329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4592329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = 4593329f9016SSepherosa Ziehau &sc->bnx_tx_ring[j].bnx_tx_serialize; 4594329f9016SSepherosa Ziehau } 4595329f9016SSepherosa Ziehau 4596329f9016SSepherosa Ziehau KKASSERT(i == sc->bnx_serialize_cnt); 4597329f9016SSepherosa Ziehau } 4598329f9016SSepherosa Ziehau 4599329f9016SSepherosa Ziehau static void 4600329f9016SSepherosa Ziehau bnx_serialize(struct ifnet *ifp, enum ifnet_serialize slz) 4601329f9016SSepherosa Ziehau { 4602329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4603329f9016SSepherosa Ziehau 4604329f9016SSepherosa Ziehau ifnet_serialize_array_enter(sc->bnx_serialize, 4605329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4606329f9016SSepherosa Ziehau } 4607329f9016SSepherosa Ziehau 4608329f9016SSepherosa Ziehau static void 4609329f9016SSepherosa Ziehau bnx_deserialize(struct ifnet *ifp, enum ifnet_serialize slz) 4610329f9016SSepherosa Ziehau { 4611329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4612329f9016SSepherosa Ziehau 4613329f9016SSepherosa Ziehau ifnet_serialize_array_exit(sc->bnx_serialize, 4614329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4615329f9016SSepherosa Ziehau } 4616329f9016SSepherosa Ziehau 4617329f9016SSepherosa Ziehau static int 4618329f9016SSepherosa Ziehau bnx_tryserialize(struct ifnet *ifp, enum ifnet_serialize slz) 4619329f9016SSepherosa Ziehau { 4620329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4621329f9016SSepherosa Ziehau 4622329f9016SSepherosa Ziehau return ifnet_serialize_array_try(sc->bnx_serialize, 4623329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4624329f9016SSepherosa Ziehau } 4625329f9016SSepherosa Ziehau 4626329f9016SSepherosa Ziehau #ifdef INVARIANTS 4627329f9016SSepherosa Ziehau 4628329f9016SSepherosa Ziehau static void 4629329f9016SSepherosa Ziehau bnx_serialize_assert(struct ifnet *ifp, enum ifnet_serialize slz, 4630329f9016SSepherosa Ziehau boolean_t serialized) 4631329f9016SSepherosa Ziehau { 4632329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4633329f9016SSepherosa Ziehau 4634329f9016SSepherosa Ziehau ifnet_serialize_array_assert(sc->bnx_serialize, sc->bnx_serialize_cnt, 4635329f9016SSepherosa Ziehau slz, serialized); 4636329f9016SSepherosa Ziehau } 4637329f9016SSepherosa Ziehau 4638329f9016SSepherosa Ziehau #endif /* INVARIANTS */ 4639