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" }, 936c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5718, 946c8d8eccSSepherosa Ziehau "Broadcom BCM5718 Gigabit Ethernet" }, 956c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5719, 966c8d8eccSSepherosa Ziehau "Broadcom BCM5719 Gigabit Ethernet" }, 976c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5720_ALT, 986c8d8eccSSepherosa Ziehau "Broadcom BCM5720 Gigabit Ethernet" }, 996c8d8eccSSepherosa Ziehau 1006c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57761, 1016c8d8eccSSepherosa Ziehau "Broadcom BCM57761 Gigabit Ethernet" }, 10232ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57762, 10332ff3c80SSepherosa Ziehau "Broadcom BCM57762 Gigabit Ethernet" }, 1046c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57765, 1056c8d8eccSSepherosa Ziehau "Broadcom BCM57765 Gigabit Ethernet" }, 10632ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57766, 10732ff3c80SSepherosa Ziehau "Broadcom BCM57766 Gigabit Ethernet" }, 10832ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57781, 10932ff3c80SSepherosa Ziehau "Broadcom BCM57781 Gigabit Ethernet" }, 11032ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57782, 11132ff3c80SSepherosa Ziehau "Broadcom BCM57782 Gigabit Ethernet" }, 1126c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57785, 1136c8d8eccSSepherosa Ziehau "Broadcom BCM57785 Gigabit Ethernet" }, 11432ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57786, 11532ff3c80SSepherosa Ziehau "Broadcom BCM57786 Gigabit Ethernet" }, 11632ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57791, 11732ff3c80SSepherosa Ziehau "Broadcom BCM57791 Fast Ethernet" }, 1186c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57795, 1196c8d8eccSSepherosa Ziehau "Broadcom BCM57795 Fast Ethernet" }, 1206c8d8eccSSepherosa Ziehau 1216c8d8eccSSepherosa Ziehau { 0, 0, NULL } 1226c8d8eccSSepherosa Ziehau }; 1236c8d8eccSSepherosa Ziehau 1246c8d8eccSSepherosa Ziehau #define BNX_IS_JUMBO_CAPABLE(sc) ((sc)->bnx_flags & BNX_FLAG_JUMBO) 1256c8d8eccSSepherosa Ziehau #define BNX_IS_5717_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_5717_PLUS) 126f368d0d9SSepherosa Ziehau #define BNX_IS_57765_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_57765_PLUS) 127f368d0d9SSepherosa Ziehau #define BNX_IS_57765_FAMILY(sc) \ 128f368d0d9SSepherosa Ziehau ((sc)->bnx_flags & BNX_FLAG_57765_FAMILY) 1296c8d8eccSSepherosa Ziehau 1306c8d8eccSSepherosa Ziehau typedef int (*bnx_eaddr_fcn_t)(struct bnx_softc *, uint8_t[]); 1316c8d8eccSSepherosa Ziehau 1326c8d8eccSSepherosa Ziehau static int bnx_probe(device_t); 1336c8d8eccSSepherosa Ziehau static int bnx_attach(device_t); 1346c8d8eccSSepherosa Ziehau static int bnx_detach(device_t); 1356c8d8eccSSepherosa Ziehau static void bnx_shutdown(device_t); 1366c8d8eccSSepherosa Ziehau static int bnx_suspend(device_t); 1376c8d8eccSSepherosa Ziehau static int bnx_resume(device_t); 1386c8d8eccSSepherosa Ziehau static int bnx_miibus_readreg(device_t, int, int); 1396c8d8eccSSepherosa Ziehau static int bnx_miibus_writereg(device_t, int, int, int); 1406c8d8eccSSepherosa Ziehau static void bnx_miibus_statchg(device_t); 1416c8d8eccSSepherosa Ziehau 14239a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 14339a8d43aSSepherosa Ziehau static void bnx_npoll(struct ifnet *, struct ifpoll_info *); 14439a8d43aSSepherosa Ziehau static void bnx_npoll_compat(struct ifnet *, void *, int); 1456c8d8eccSSepherosa Ziehau #endif 1466c8d8eccSSepherosa Ziehau static void bnx_intr_legacy(void *); 1476c8d8eccSSepherosa Ziehau static void bnx_msi(void *); 1486c8d8eccSSepherosa Ziehau static void bnx_msi_oneshot(void *); 1496c8d8eccSSepherosa Ziehau static void bnx_intr(struct bnx_softc *); 1506c8d8eccSSepherosa Ziehau static void bnx_enable_intr(struct bnx_softc *); 1516c8d8eccSSepherosa Ziehau static void bnx_disable_intr(struct bnx_softc *); 1526c8d8eccSSepherosa Ziehau static void bnx_txeof(struct bnx_softc *, uint16_t); 15397381780SSepherosa Ziehau static void bnx_rxeof(struct bnx_softc *, uint16_t, int); 1546c8d8eccSSepherosa Ziehau 1556c8d8eccSSepherosa Ziehau static void bnx_start(struct ifnet *); 1566c8d8eccSSepherosa Ziehau static int bnx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); 1576c8d8eccSSepherosa Ziehau static void bnx_init(void *); 1586c8d8eccSSepherosa Ziehau static void bnx_stop(struct bnx_softc *); 1596c8d8eccSSepherosa Ziehau static void bnx_watchdog(struct ifnet *); 1606c8d8eccSSepherosa Ziehau static int bnx_ifmedia_upd(struct ifnet *); 1616c8d8eccSSepherosa Ziehau static void bnx_ifmedia_sts(struct ifnet *, struct ifmediareq *); 1626c8d8eccSSepherosa Ziehau static void bnx_tick(void *); 1636c8d8eccSSepherosa Ziehau 1646c8d8eccSSepherosa Ziehau static int bnx_alloc_jumbo_mem(struct bnx_softc *); 1656c8d8eccSSepherosa Ziehau static void bnx_free_jumbo_mem(struct bnx_softc *); 1666c8d8eccSSepherosa Ziehau static struct bnx_jslot 1676c8d8eccSSepherosa Ziehau *bnx_jalloc(struct bnx_softc *); 1686c8d8eccSSepherosa Ziehau static void bnx_jfree(void *); 1696c8d8eccSSepherosa Ziehau static void bnx_jref(void *); 1706c8d8eccSSepherosa Ziehau static int bnx_newbuf_std(struct bnx_softc *, int, int); 1716c8d8eccSSepherosa Ziehau static int bnx_newbuf_jumbo(struct bnx_softc *, int, int); 1726c8d8eccSSepherosa Ziehau static void bnx_setup_rxdesc_std(struct bnx_softc *, int); 1736c8d8eccSSepherosa Ziehau static void bnx_setup_rxdesc_jumbo(struct bnx_softc *, int); 1746c8d8eccSSepherosa Ziehau static int bnx_init_rx_ring_std(struct bnx_softc *); 1756c8d8eccSSepherosa Ziehau static void bnx_free_rx_ring_std(struct bnx_softc *); 1766c8d8eccSSepherosa Ziehau static int bnx_init_rx_ring_jumbo(struct bnx_softc *); 1776c8d8eccSSepherosa Ziehau static void bnx_free_rx_ring_jumbo(struct bnx_softc *); 1786c8d8eccSSepherosa Ziehau static void bnx_free_tx_ring(struct bnx_softc *); 1796c8d8eccSSepherosa Ziehau static int bnx_init_tx_ring(struct bnx_softc *); 1806c8d8eccSSepherosa Ziehau static int bnx_dma_alloc(struct bnx_softc *); 1816c8d8eccSSepherosa Ziehau static void bnx_dma_free(struct bnx_softc *); 1826c8d8eccSSepherosa Ziehau static int bnx_dma_block_alloc(struct bnx_softc *, bus_size_t, 1836c8d8eccSSepherosa Ziehau bus_dma_tag_t *, bus_dmamap_t *, void **, bus_addr_t *); 1846c8d8eccSSepherosa Ziehau static void bnx_dma_block_free(bus_dma_tag_t, bus_dmamap_t, void *); 1856c8d8eccSSepherosa Ziehau static struct mbuf * 1866c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *); 187c9b7f592SSepherosa Ziehau static int bnx_encap(struct bnx_softc *, struct mbuf **, 188c9b7f592SSepherosa Ziehau uint32_t *, int *); 18966deb1c1SSepherosa Ziehau static int bnx_setup_tso(struct bnx_softc *, struct mbuf **, 19066deb1c1SSepherosa Ziehau uint16_t *, uint16_t *); 1916c8d8eccSSepherosa Ziehau 1926c8d8eccSSepherosa Ziehau static void bnx_reset(struct bnx_softc *); 1936c8d8eccSSepherosa Ziehau static int bnx_chipinit(struct bnx_softc *); 1946c8d8eccSSepherosa Ziehau static int bnx_blockinit(struct bnx_softc *); 1956c8d8eccSSepherosa Ziehau static void bnx_stop_block(struct bnx_softc *, bus_size_t, uint32_t); 1966c8d8eccSSepherosa Ziehau static void bnx_enable_msi(struct bnx_softc *sc); 1976c8d8eccSSepherosa Ziehau static void bnx_setmulti(struct bnx_softc *); 1986c8d8eccSSepherosa Ziehau static void bnx_setpromisc(struct bnx_softc *); 1996c8d8eccSSepherosa Ziehau static void bnx_stats_update_regs(struct bnx_softc *); 2006c8d8eccSSepherosa Ziehau static uint32_t bnx_dma_swap_options(struct bnx_softc *); 2016c8d8eccSSepherosa Ziehau 2026c8d8eccSSepherosa Ziehau static uint32_t bnx_readmem_ind(struct bnx_softc *, uint32_t); 2036c8d8eccSSepherosa Ziehau static void bnx_writemem_ind(struct bnx_softc *, uint32_t, uint32_t); 2046c8d8eccSSepherosa Ziehau #ifdef notdef 2056c8d8eccSSepherosa Ziehau static uint32_t bnx_readreg_ind(struct bnx_softc *, uint32_t); 2066c8d8eccSSepherosa Ziehau #endif 2076c8d8eccSSepherosa Ziehau static void bnx_writereg_ind(struct bnx_softc *, uint32_t, uint32_t); 2086c8d8eccSSepherosa Ziehau static void bnx_writemem_direct(struct bnx_softc *, uint32_t, uint32_t); 2096c8d8eccSSepherosa Ziehau static void bnx_writembx(struct bnx_softc *, int, int); 2106c8d8eccSSepherosa Ziehau static uint8_t bnx_nvram_getbyte(struct bnx_softc *, int, uint8_t *); 2116c8d8eccSSepherosa Ziehau static int bnx_read_nvram(struct bnx_softc *, caddr_t, int, int); 2126c8d8eccSSepherosa Ziehau static uint8_t bnx_eeprom_getbyte(struct bnx_softc *, uint32_t, uint8_t *); 2136c8d8eccSSepherosa Ziehau static int bnx_read_eeprom(struct bnx_softc *, caddr_t, uint32_t, size_t); 2146c8d8eccSSepherosa Ziehau 2156c8d8eccSSepherosa Ziehau static void bnx_tbi_link_upd(struct bnx_softc *, uint32_t); 2166c8d8eccSSepherosa Ziehau static void bnx_copper_link_upd(struct bnx_softc *, uint32_t); 2176c8d8eccSSepherosa Ziehau static void bnx_autopoll_link_upd(struct bnx_softc *, uint32_t); 2186c8d8eccSSepherosa Ziehau static void bnx_link_poll(struct bnx_softc *); 2196c8d8eccSSepherosa Ziehau 2206c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_mem(struct bnx_softc *, uint8_t[]); 2216c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_nvram(struct bnx_softc *, uint8_t[]); 2226c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_eeprom(struct bnx_softc *, uint8_t[]); 2236c8d8eccSSepherosa Ziehau static int bnx_get_eaddr(struct bnx_softc *, uint8_t[]); 2246c8d8eccSSepherosa Ziehau 2256c8d8eccSSepherosa Ziehau static void bnx_coal_change(struct bnx_softc *); 2266c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS); 2276c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS); 2286c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS); 2296c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS); 2306c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2316c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2326c8d8eccSSepherosa Ziehau static int bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *, 2336c8d8eccSSepherosa Ziehau int, int, uint32_t); 2346c8d8eccSSepherosa Ziehau 2356c8d8eccSSepherosa Ziehau static int bnx_msi_enable = 1; 2366c8d8eccSSepherosa Ziehau TUNABLE_INT("hw.bnx.msi.enable", &bnx_msi_enable); 2376c8d8eccSSepherosa Ziehau 2386c8d8eccSSepherosa Ziehau static device_method_t bnx_methods[] = { 2396c8d8eccSSepherosa Ziehau /* Device interface */ 2406c8d8eccSSepherosa Ziehau DEVMETHOD(device_probe, bnx_probe), 2416c8d8eccSSepherosa Ziehau DEVMETHOD(device_attach, bnx_attach), 2426c8d8eccSSepherosa Ziehau DEVMETHOD(device_detach, bnx_detach), 2436c8d8eccSSepherosa Ziehau DEVMETHOD(device_shutdown, bnx_shutdown), 2446c8d8eccSSepherosa Ziehau DEVMETHOD(device_suspend, bnx_suspend), 2456c8d8eccSSepherosa Ziehau DEVMETHOD(device_resume, bnx_resume), 2466c8d8eccSSepherosa Ziehau 2476c8d8eccSSepherosa Ziehau /* bus interface */ 2486c8d8eccSSepherosa Ziehau DEVMETHOD(bus_print_child, bus_generic_print_child), 2496c8d8eccSSepherosa Ziehau DEVMETHOD(bus_driver_added, bus_generic_driver_added), 2506c8d8eccSSepherosa Ziehau 2516c8d8eccSSepherosa Ziehau /* MII interface */ 2526c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_readreg, bnx_miibus_readreg), 2536c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_writereg, bnx_miibus_writereg), 2546c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_statchg, bnx_miibus_statchg), 2556c8d8eccSSepherosa Ziehau 2566c8d8eccSSepherosa Ziehau { 0, 0 } 2576c8d8eccSSepherosa Ziehau }; 2586c8d8eccSSepherosa Ziehau 2596c8d8eccSSepherosa Ziehau static DEFINE_CLASS_0(bnx, bnx_driver, bnx_methods, sizeof(struct bnx_softc)); 2606c8d8eccSSepherosa Ziehau static devclass_t bnx_devclass; 2616c8d8eccSSepherosa Ziehau 2626c8d8eccSSepherosa Ziehau DECLARE_DUMMY_MODULE(if_bnx); 2636c8d8eccSSepherosa Ziehau DRIVER_MODULE(if_bnx, pci, bnx_driver, bnx_devclass, NULL, NULL); 2646c8d8eccSSepherosa Ziehau DRIVER_MODULE(miibus, bnx, miibus_driver, miibus_devclass, NULL, NULL); 2656c8d8eccSSepherosa Ziehau 2666c8d8eccSSepherosa Ziehau static uint32_t 2676c8d8eccSSepherosa Ziehau bnx_readmem_ind(struct bnx_softc *sc, uint32_t off) 2686c8d8eccSSepherosa Ziehau { 2696c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 2706c8d8eccSSepherosa Ziehau uint32_t val; 2716c8d8eccSSepherosa Ziehau 2726c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906 && 2736c8d8eccSSepherosa Ziehau off >= BGE_STATS_BLOCK && off < BGE_SEND_RING_1_TO_4) 2746c8d8eccSSepherosa Ziehau return 0; 2756c8d8eccSSepherosa Ziehau 2766c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 2776c8d8eccSSepherosa Ziehau val = pci_read_config(dev, BGE_PCI_MEMWIN_DATA, 4); 2786c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 2796c8d8eccSSepherosa Ziehau return (val); 2806c8d8eccSSepherosa Ziehau } 2816c8d8eccSSepherosa Ziehau 2826c8d8eccSSepherosa Ziehau static void 2836c8d8eccSSepherosa Ziehau bnx_writemem_ind(struct bnx_softc *sc, uint32_t off, uint32_t val) 2846c8d8eccSSepherosa Ziehau { 2856c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 2866c8d8eccSSepherosa Ziehau 2876c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906 && 2886c8d8eccSSepherosa Ziehau off >= BGE_STATS_BLOCK && off < BGE_SEND_RING_1_TO_4) 2896c8d8eccSSepherosa Ziehau return; 2906c8d8eccSSepherosa Ziehau 2916c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 2926c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_DATA, val, 4); 2936c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 2946c8d8eccSSepherosa Ziehau } 2956c8d8eccSSepherosa Ziehau 2966c8d8eccSSepherosa Ziehau #ifdef notdef 2976c8d8eccSSepherosa Ziehau static uint32_t 2986c8d8eccSSepherosa Ziehau bnx_readreg_ind(struct bnx_softc *sc, uin32_t off) 2996c8d8eccSSepherosa Ziehau { 3006c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 3016c8d8eccSSepherosa Ziehau 3026c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_REG_BASEADDR, off, 4); 3036c8d8eccSSepherosa Ziehau return(pci_read_config(dev, BGE_PCI_REG_DATA, 4)); 3046c8d8eccSSepherosa Ziehau } 3056c8d8eccSSepherosa Ziehau #endif 3066c8d8eccSSepherosa Ziehau 3076c8d8eccSSepherosa Ziehau static void 3086c8d8eccSSepherosa Ziehau bnx_writereg_ind(struct bnx_softc *sc, uint32_t off, uint32_t val) 3096c8d8eccSSepherosa Ziehau { 3106c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 3116c8d8eccSSepherosa Ziehau 3126c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_REG_BASEADDR, off, 4); 3136c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_REG_DATA, val, 4); 3146c8d8eccSSepherosa Ziehau } 3156c8d8eccSSepherosa Ziehau 3166c8d8eccSSepherosa Ziehau static void 3176c8d8eccSSepherosa Ziehau bnx_writemem_direct(struct bnx_softc *sc, uint32_t off, uint32_t val) 3186c8d8eccSSepherosa Ziehau { 3196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3206c8d8eccSSepherosa Ziehau } 3216c8d8eccSSepherosa Ziehau 3226c8d8eccSSepherosa Ziehau static void 3236c8d8eccSSepherosa Ziehau bnx_writembx(struct bnx_softc *sc, int off, int val) 3246c8d8eccSSepherosa Ziehau { 3256c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) 3266c8d8eccSSepherosa Ziehau off += BGE_LPMBX_IRQ0_HI - BGE_MBX_IRQ0_HI; 3276c8d8eccSSepherosa Ziehau 3286c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3296c8d8eccSSepherosa Ziehau } 3306c8d8eccSSepherosa Ziehau 3316c8d8eccSSepherosa Ziehau static uint8_t 3326c8d8eccSSepherosa Ziehau bnx_nvram_getbyte(struct bnx_softc *sc, int addr, uint8_t *dest) 3336c8d8eccSSepherosa Ziehau { 3346c8d8eccSSepherosa Ziehau uint32_t access, byte = 0; 3356c8d8eccSSepherosa Ziehau int i; 3366c8d8eccSSepherosa Ziehau 3376c8d8eccSSepherosa Ziehau /* Lock. */ 3386c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_SET1); 3396c8d8eccSSepherosa Ziehau for (i = 0; i < 8000; i++) { 3406c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_NVRAM_SWARB) & BGE_NVRAMSWARB_GNT1) 3416c8d8eccSSepherosa Ziehau break; 3426c8d8eccSSepherosa Ziehau DELAY(20); 3436c8d8eccSSepherosa Ziehau } 3446c8d8eccSSepherosa Ziehau if (i == 8000) 3456c8d8eccSSepherosa Ziehau return (1); 3466c8d8eccSSepherosa Ziehau 3476c8d8eccSSepherosa Ziehau /* Enable access. */ 3486c8d8eccSSepherosa Ziehau access = CSR_READ_4(sc, BGE_NVRAM_ACCESS); 3496c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access | BGE_NVRAMACC_ENABLE); 3506c8d8eccSSepherosa Ziehau 3516c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_ADDR, addr & 0xfffffffc); 3526c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_CMD, BGE_NVRAM_READCMD); 3536c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT * 10; i++) { 3546c8d8eccSSepherosa Ziehau DELAY(10); 3556c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_NVRAM_CMD) & BGE_NVRAMCMD_DONE) { 3566c8d8eccSSepherosa Ziehau DELAY(10); 3576c8d8eccSSepherosa Ziehau break; 3586c8d8eccSSepherosa Ziehau } 3596c8d8eccSSepherosa Ziehau } 3606c8d8eccSSepherosa Ziehau 3616c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT * 10) { 3626c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "nvram read timed out\n"); 3636c8d8eccSSepherosa Ziehau return (1); 3646c8d8eccSSepherosa Ziehau } 3656c8d8eccSSepherosa Ziehau 3666c8d8eccSSepherosa Ziehau /* Get result. */ 3676c8d8eccSSepherosa Ziehau byte = CSR_READ_4(sc, BGE_NVRAM_RDDATA); 3686c8d8eccSSepherosa Ziehau 3696c8d8eccSSepherosa Ziehau *dest = (bswap32(byte) >> ((addr % 4) * 8)) & 0xFF; 3706c8d8eccSSepherosa Ziehau 3716c8d8eccSSepherosa Ziehau /* Disable access. */ 3726c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access); 3736c8d8eccSSepherosa Ziehau 3746c8d8eccSSepherosa Ziehau /* Unlock. */ 3756c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_CLR1); 3766c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_NVRAM_SWARB); 3776c8d8eccSSepherosa Ziehau 3786c8d8eccSSepherosa Ziehau return (0); 3796c8d8eccSSepherosa Ziehau } 3806c8d8eccSSepherosa Ziehau 3816c8d8eccSSepherosa Ziehau /* 3826c8d8eccSSepherosa Ziehau * Read a sequence of bytes from NVRAM. 3836c8d8eccSSepherosa Ziehau */ 3846c8d8eccSSepherosa Ziehau static int 3856c8d8eccSSepherosa Ziehau bnx_read_nvram(struct bnx_softc *sc, caddr_t dest, int off, int cnt) 3866c8d8eccSSepherosa Ziehau { 3876c8d8eccSSepherosa Ziehau int err = 0, i; 3886c8d8eccSSepherosa Ziehau uint8_t byte = 0; 3896c8d8eccSSepherosa Ziehau 3906c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5906) 3916c8d8eccSSepherosa Ziehau return (1); 3926c8d8eccSSepherosa Ziehau 3936c8d8eccSSepherosa Ziehau for (i = 0; i < cnt; i++) { 3946c8d8eccSSepherosa Ziehau err = bnx_nvram_getbyte(sc, off + i, &byte); 3956c8d8eccSSepherosa Ziehau if (err) 3966c8d8eccSSepherosa Ziehau break; 3976c8d8eccSSepherosa Ziehau *(dest + i) = byte; 3986c8d8eccSSepherosa Ziehau } 3996c8d8eccSSepherosa Ziehau 4006c8d8eccSSepherosa Ziehau return (err ? 1 : 0); 4016c8d8eccSSepherosa Ziehau } 4026c8d8eccSSepherosa Ziehau 4036c8d8eccSSepherosa Ziehau /* 4046c8d8eccSSepherosa Ziehau * Read a byte of data stored in the EEPROM at address 'addr.' The 4056c8d8eccSSepherosa Ziehau * BCM570x supports both the traditional bitbang interface and an 4066c8d8eccSSepherosa Ziehau * auto access interface for reading the EEPROM. We use the auto 4076c8d8eccSSepherosa Ziehau * access method. 4086c8d8eccSSepherosa Ziehau */ 4096c8d8eccSSepherosa Ziehau static uint8_t 4106c8d8eccSSepherosa Ziehau bnx_eeprom_getbyte(struct bnx_softc *sc, uint32_t addr, uint8_t *dest) 4116c8d8eccSSepherosa Ziehau { 4126c8d8eccSSepherosa Ziehau int i; 4136c8d8eccSSepherosa Ziehau uint32_t byte = 0; 4146c8d8eccSSepherosa Ziehau 4156c8d8eccSSepherosa Ziehau /* 4166c8d8eccSSepherosa Ziehau * Enable use of auto EEPROM access so we can avoid 4176c8d8eccSSepherosa Ziehau * having to use the bitbang method. 4186c8d8eccSSepherosa Ziehau */ 4196c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_AUTO_EEPROM); 4206c8d8eccSSepherosa Ziehau 4216c8d8eccSSepherosa Ziehau /* Reset the EEPROM, load the clock period. */ 4226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, 4236c8d8eccSSepherosa Ziehau BGE_EEADDR_RESET|BGE_EEHALFCLK(BGE_HALFCLK_384SCL)); 4246c8d8eccSSepherosa Ziehau DELAY(20); 4256c8d8eccSSepherosa Ziehau 4266c8d8eccSSepherosa Ziehau /* Issue the read EEPROM command. */ 4276c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, BGE_EE_READCMD | addr); 4286c8d8eccSSepherosa Ziehau 4296c8d8eccSSepherosa Ziehau /* Wait for completion */ 4306c8d8eccSSepherosa Ziehau for(i = 0; i < BNX_TIMEOUT * 10; i++) { 4316c8d8eccSSepherosa Ziehau DELAY(10); 4326c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_EE_ADDR) & BGE_EEADDR_DONE) 4336c8d8eccSSepherosa Ziehau break; 4346c8d8eccSSepherosa Ziehau } 4356c8d8eccSSepherosa Ziehau 4366c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4376c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "eeprom read timed out\n"); 4386c8d8eccSSepherosa Ziehau return(1); 4396c8d8eccSSepherosa Ziehau } 4406c8d8eccSSepherosa Ziehau 4416c8d8eccSSepherosa Ziehau /* Get result. */ 4426c8d8eccSSepherosa Ziehau byte = CSR_READ_4(sc, BGE_EE_DATA); 4436c8d8eccSSepherosa Ziehau 4446c8d8eccSSepherosa Ziehau *dest = (byte >> ((addr % 4) * 8)) & 0xFF; 4456c8d8eccSSepherosa Ziehau 4466c8d8eccSSepherosa Ziehau return(0); 4476c8d8eccSSepherosa Ziehau } 4486c8d8eccSSepherosa Ziehau 4496c8d8eccSSepherosa Ziehau /* 4506c8d8eccSSepherosa Ziehau * Read a sequence of bytes from the EEPROM. 4516c8d8eccSSepherosa Ziehau */ 4526c8d8eccSSepherosa Ziehau static int 4536c8d8eccSSepherosa Ziehau bnx_read_eeprom(struct bnx_softc *sc, caddr_t dest, uint32_t off, size_t len) 4546c8d8eccSSepherosa Ziehau { 4556c8d8eccSSepherosa Ziehau size_t i; 4566c8d8eccSSepherosa Ziehau int err; 4576c8d8eccSSepherosa Ziehau uint8_t byte; 4586c8d8eccSSepherosa Ziehau 4596c8d8eccSSepherosa Ziehau for (byte = 0, err = 0, i = 0; i < len; i++) { 4606c8d8eccSSepherosa Ziehau err = bnx_eeprom_getbyte(sc, off + i, &byte); 4616c8d8eccSSepherosa Ziehau if (err) 4626c8d8eccSSepherosa Ziehau break; 4636c8d8eccSSepherosa Ziehau *(dest + i) = byte; 4646c8d8eccSSepherosa Ziehau } 4656c8d8eccSSepherosa Ziehau 4666c8d8eccSSepherosa Ziehau return(err ? 1 : 0); 4676c8d8eccSSepherosa Ziehau } 4686c8d8eccSSepherosa Ziehau 4696c8d8eccSSepherosa Ziehau static int 4706c8d8eccSSepherosa Ziehau bnx_miibus_readreg(device_t dev, int phy, int reg) 4716c8d8eccSSepherosa Ziehau { 4726c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4736c8d8eccSSepherosa Ziehau uint32_t val; 4746c8d8eccSSepherosa Ziehau int i; 4756c8d8eccSSepherosa Ziehau 4766c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4776c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4786c8d8eccSSepherosa Ziehau 4796c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4806c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4816c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4826c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4836c8d8eccSSepherosa Ziehau DELAY(80); 4846c8d8eccSSepherosa Ziehau } 4856c8d8eccSSepherosa Ziehau 4866c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ | BGE_MICOMM_BUSY | 4876c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg)); 4886c8d8eccSSepherosa Ziehau 4896c8d8eccSSepherosa Ziehau /* Poll for the PHY register access to complete. */ 4906c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4916c8d8eccSSepherosa Ziehau DELAY(10); 4926c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4936c8d8eccSSepherosa Ziehau if ((val & BGE_MICOMM_BUSY) == 0) { 4946c8d8eccSSepherosa Ziehau DELAY(5); 4956c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4966c8d8eccSSepherosa Ziehau break; 4976c8d8eccSSepherosa Ziehau } 4986c8d8eccSSepherosa Ziehau } 4996c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 5006c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY read timed out " 5016c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val 0x%08x)\n", phy, reg, val); 5026c8d8eccSSepherosa Ziehau val = 0; 5036c8d8eccSSepherosa Ziehau } 5046c8d8eccSSepherosa Ziehau 5056c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 5066c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 5076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 5086c8d8eccSSepherosa Ziehau DELAY(80); 5096c8d8eccSSepherosa Ziehau } 5106c8d8eccSSepherosa Ziehau 5116c8d8eccSSepherosa Ziehau if (val & BGE_MICOMM_READFAIL) 5126c8d8eccSSepherosa Ziehau return 0; 5136c8d8eccSSepherosa Ziehau 5146c8d8eccSSepherosa Ziehau return (val & 0xFFFF); 5156c8d8eccSSepherosa Ziehau } 5166c8d8eccSSepherosa Ziehau 5176c8d8eccSSepherosa Ziehau static int 5186c8d8eccSSepherosa Ziehau bnx_miibus_writereg(device_t dev, int phy, int reg, int val) 5196c8d8eccSSepherosa Ziehau { 5206c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 5216c8d8eccSSepherosa Ziehau int i; 5226c8d8eccSSepherosa Ziehau 5236c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 5246c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 5256c8d8eccSSepherosa Ziehau 5266c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906 && 5276c8d8eccSSepherosa Ziehau (reg == BRGPHY_MII_1000CTL || reg == BRGPHY_MII_AUXCTL)) 5286c8d8eccSSepherosa Ziehau return 0; 5296c8d8eccSSepherosa Ziehau 5306c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 5316c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 5326c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 5336c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 5346c8d8eccSSepherosa Ziehau DELAY(80); 5356c8d8eccSSepherosa Ziehau } 5366c8d8eccSSepherosa Ziehau 5376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY | 5386c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg) | val); 5396c8d8eccSSepherosa Ziehau 5406c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 5416c8d8eccSSepherosa Ziehau DELAY(10); 5426c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) { 5436c8d8eccSSepherosa Ziehau DELAY(5); 5446c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */ 5456c8d8eccSSepherosa Ziehau break; 5466c8d8eccSSepherosa Ziehau } 5476c8d8eccSSepherosa Ziehau } 5486c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 5496c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY write timed out " 5506c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val %d)\n", phy, reg, val); 5516c8d8eccSSepherosa Ziehau } 5526c8d8eccSSepherosa Ziehau 5536c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 5546c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 5556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 5566c8d8eccSSepherosa Ziehau DELAY(80); 5576c8d8eccSSepherosa Ziehau } 5586c8d8eccSSepherosa Ziehau 5596c8d8eccSSepherosa Ziehau return 0; 5606c8d8eccSSepherosa Ziehau } 5616c8d8eccSSepherosa Ziehau 5626c8d8eccSSepherosa Ziehau static void 5636c8d8eccSSepherosa Ziehau bnx_miibus_statchg(device_t dev) 5646c8d8eccSSepherosa Ziehau { 5656c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 5666c8d8eccSSepherosa Ziehau struct mii_data *mii; 5676c8d8eccSSepherosa Ziehau 5686c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 5696c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 5706c8d8eccSSepherosa Ziehau 5716c8d8eccSSepherosa Ziehau if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 5726c8d8eccSSepherosa Ziehau (IFM_ACTIVE | IFM_AVALID)) { 5736c8d8eccSSepherosa Ziehau switch (IFM_SUBTYPE(mii->mii_media_active)) { 5746c8d8eccSSepherosa Ziehau case IFM_10_T: 5756c8d8eccSSepherosa Ziehau case IFM_100_TX: 5766c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5776c8d8eccSSepherosa Ziehau break; 5786c8d8eccSSepherosa Ziehau case IFM_1000_T: 5796c8d8eccSSepherosa Ziehau case IFM_1000_SX: 5806c8d8eccSSepherosa Ziehau case IFM_2500_SX: 5816c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5906) 5826c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5836c8d8eccSSepherosa Ziehau else 5846c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5856c8d8eccSSepherosa Ziehau break; 5866c8d8eccSSepherosa Ziehau default: 5876c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5886c8d8eccSSepherosa Ziehau break; 5896c8d8eccSSepherosa Ziehau } 5906c8d8eccSSepherosa Ziehau } else { 5916c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5926c8d8eccSSepherosa Ziehau } 5936c8d8eccSSepherosa Ziehau if (sc->bnx_link == 0) 5946c8d8eccSSepherosa Ziehau return; 5956c8d8eccSSepherosa Ziehau 5966c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); 5976c8d8eccSSepherosa Ziehau if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T || 5986c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) { 5996c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); 6006c8d8eccSSepherosa Ziehau } else { 6016c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII); 6026c8d8eccSSepherosa Ziehau } 6036c8d8eccSSepherosa Ziehau 6046c8d8eccSSepherosa Ziehau if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 6056c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 6066c8d8eccSSepherosa Ziehau } else { 6076c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 6086c8d8eccSSepherosa Ziehau } 6096c8d8eccSSepherosa Ziehau } 6106c8d8eccSSepherosa Ziehau 6116c8d8eccSSepherosa Ziehau /* 6126c8d8eccSSepherosa Ziehau * Memory management for jumbo frames. 6136c8d8eccSSepherosa Ziehau */ 6146c8d8eccSSepherosa Ziehau static int 6156c8d8eccSSepherosa Ziehau bnx_alloc_jumbo_mem(struct bnx_softc *sc) 6166c8d8eccSSepherosa Ziehau { 6176c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 6186c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 6196c8d8eccSSepherosa Ziehau uint8_t *ptr; 6206c8d8eccSSepherosa Ziehau bus_addr_t paddr; 6216c8d8eccSSepherosa Ziehau int i, error; 6226c8d8eccSSepherosa Ziehau 6236c8d8eccSSepherosa Ziehau /* 6246c8d8eccSSepherosa Ziehau * Create tag for jumbo mbufs. 6256c8d8eccSSepherosa Ziehau * This is really a bit of a kludge. We allocate a special 6266c8d8eccSSepherosa Ziehau * jumbo buffer pool which (thanks to the way our DMA 6276c8d8eccSSepherosa Ziehau * memory allocation works) will consist of contiguous 6286c8d8eccSSepherosa Ziehau * pages. This means that even though a jumbo buffer might 6296c8d8eccSSepherosa Ziehau * be larger than a page size, we don't really need to 6306c8d8eccSSepherosa Ziehau * map it into more than one DMA segment. However, the 6316c8d8eccSSepherosa Ziehau * default mbuf tag will result in multi-segment mappings, 6326c8d8eccSSepherosa Ziehau * so we have to create a special jumbo mbuf tag that 6336c8d8eccSSepherosa Ziehau * lets us get away with mapping the jumbo buffers as 6346c8d8eccSSepherosa Ziehau * a single segment. I think eventually the driver should 6356c8d8eccSSepherosa Ziehau * be changed so that it uses ordinary mbufs and cluster 6366c8d8eccSSepherosa Ziehau * buffers, i.e. jumbo frames can span multiple DMA 6376c8d8eccSSepherosa Ziehau * descriptors. But that's a project for another day. 6386c8d8eccSSepherosa Ziehau */ 6396c8d8eccSSepherosa Ziehau 6406c8d8eccSSepherosa Ziehau /* 6416c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo RX ring. 6426c8d8eccSSepherosa Ziehau */ 6436c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_JUMBO_RX_RING_SZ, 6446c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 6456c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_map, 6466c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_jumbo_ring, 6476c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 6486c8d8eccSSepherosa Ziehau if (error) { 6496c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo RX ring\n"); 6506c8d8eccSSepherosa Ziehau return error; 6516c8d8eccSSepherosa Ziehau } 6526c8d8eccSSepherosa Ziehau 6536c8d8eccSSepherosa Ziehau /* 6546c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo buffer block. 6556c8d8eccSSepherosa Ziehau */ 6566c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BNX_JMEM, 6576c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_tag, 6586c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_map, 6596c8d8eccSSepherosa Ziehau (void **)&sc->bnx_ldata.bnx_jumbo_buf, 6606c8d8eccSSepherosa Ziehau &paddr); 6616c8d8eccSSepherosa Ziehau if (error) { 6626c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo buffer\n"); 6636c8d8eccSSepherosa Ziehau return error; 6646c8d8eccSSepherosa Ziehau } 6656c8d8eccSSepherosa Ziehau 6666c8d8eccSSepherosa Ziehau SLIST_INIT(&sc->bnx_jfree_listhead); 6676c8d8eccSSepherosa Ziehau 6686c8d8eccSSepherosa Ziehau /* 6696c8d8eccSSepherosa Ziehau * Now divide it up into 9K pieces and save the addresses 6706c8d8eccSSepherosa Ziehau * in an array. Note that we play an evil trick here by using 6716c8d8eccSSepherosa Ziehau * the first few bytes in the buffer to hold the the address 6726c8d8eccSSepherosa Ziehau * of the softc structure for this interface. This is because 6736c8d8eccSSepherosa Ziehau * bnx_jfree() needs it, but it is called by the mbuf management 6746c8d8eccSSepherosa Ziehau * code which will not pass it to us explicitly. 6756c8d8eccSSepherosa Ziehau */ 6766c8d8eccSSepherosa Ziehau for (i = 0, ptr = sc->bnx_ldata.bnx_jumbo_buf; i < BNX_JSLOTS; i++) { 6776c8d8eccSSepherosa Ziehau entry = &sc->bnx_cdata.bnx_jslots[i]; 6786c8d8eccSSepherosa Ziehau entry->bnx_sc = sc; 6796c8d8eccSSepherosa Ziehau entry->bnx_buf = ptr; 6806c8d8eccSSepherosa Ziehau entry->bnx_paddr = paddr; 6816c8d8eccSSepherosa Ziehau entry->bnx_inuse = 0; 6826c8d8eccSSepherosa Ziehau entry->bnx_slot = i; 6836c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, entry, jslot_link); 6846c8d8eccSSepherosa Ziehau 6856c8d8eccSSepherosa Ziehau ptr += BNX_JLEN; 6866c8d8eccSSepherosa Ziehau paddr += BNX_JLEN; 6876c8d8eccSSepherosa Ziehau } 6886c8d8eccSSepherosa Ziehau return 0; 6896c8d8eccSSepherosa Ziehau } 6906c8d8eccSSepherosa Ziehau 6916c8d8eccSSepherosa Ziehau static void 6926c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(struct bnx_softc *sc) 6936c8d8eccSSepherosa Ziehau { 6946c8d8eccSSepherosa Ziehau /* Destroy jumbo RX ring. */ 6956c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 6966c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_ring_map, 6976c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_jumbo_ring); 6986c8d8eccSSepherosa Ziehau 6996c8d8eccSSepherosa Ziehau /* Destroy jumbo buffer block. */ 7006c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_jumbo_tag, 7016c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_jumbo_map, 7026c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_jumbo_buf); 7036c8d8eccSSepherosa Ziehau } 7046c8d8eccSSepherosa Ziehau 7056c8d8eccSSepherosa Ziehau /* 7066c8d8eccSSepherosa Ziehau * Allocate a jumbo buffer. 7076c8d8eccSSepherosa Ziehau */ 7086c8d8eccSSepherosa Ziehau static struct bnx_jslot * 7096c8d8eccSSepherosa Ziehau bnx_jalloc(struct bnx_softc *sc) 7106c8d8eccSSepherosa Ziehau { 7116c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 7126c8d8eccSSepherosa Ziehau 7136c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 7146c8d8eccSSepherosa Ziehau entry = SLIST_FIRST(&sc->bnx_jfree_listhead); 7156c8d8eccSSepherosa Ziehau if (entry) { 7166c8d8eccSSepherosa Ziehau SLIST_REMOVE_HEAD(&sc->bnx_jfree_listhead, jslot_link); 7176c8d8eccSSepherosa Ziehau entry->bnx_inuse = 1; 7186c8d8eccSSepherosa Ziehau } else { 7196c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "no free jumbo buffers\n"); 7206c8d8eccSSepherosa Ziehau } 7216c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 7226c8d8eccSSepherosa Ziehau return(entry); 7236c8d8eccSSepherosa Ziehau } 7246c8d8eccSSepherosa Ziehau 7256c8d8eccSSepherosa Ziehau /* 7266c8d8eccSSepherosa Ziehau * Adjust usage count on a jumbo buffer. 7276c8d8eccSSepherosa Ziehau */ 7286c8d8eccSSepherosa Ziehau static void 7296c8d8eccSSepherosa Ziehau bnx_jref(void *arg) 7306c8d8eccSSepherosa Ziehau { 7316c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 7326c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 7336c8d8eccSSepherosa Ziehau 7346c8d8eccSSepherosa Ziehau if (sc == NULL) 7356c8d8eccSSepherosa Ziehau panic("bnx_jref: can't find softc pointer!"); 7366c8d8eccSSepherosa Ziehau 7376c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 7386c8d8eccSSepherosa Ziehau panic("bnx_jref: asked to reference buffer " 7396c8d8eccSSepherosa Ziehau "that we don't manage!"); 7406c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 7416c8d8eccSSepherosa Ziehau panic("bnx_jref: buffer already free!"); 7426c8d8eccSSepherosa Ziehau } else { 7436c8d8eccSSepherosa Ziehau atomic_add_int(&entry->bnx_inuse, 1); 7446c8d8eccSSepherosa Ziehau } 7456c8d8eccSSepherosa Ziehau } 7466c8d8eccSSepherosa Ziehau 7476c8d8eccSSepherosa Ziehau /* 7486c8d8eccSSepherosa Ziehau * Release a jumbo buffer. 7496c8d8eccSSepherosa Ziehau */ 7506c8d8eccSSepherosa Ziehau static void 7516c8d8eccSSepherosa Ziehau bnx_jfree(void *arg) 7526c8d8eccSSepherosa Ziehau { 7536c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 7546c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 7556c8d8eccSSepherosa Ziehau 7566c8d8eccSSepherosa Ziehau if (sc == NULL) 7576c8d8eccSSepherosa Ziehau panic("bnx_jfree: can't find softc pointer!"); 7586c8d8eccSSepherosa Ziehau 7596c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 7606c8d8eccSSepherosa Ziehau panic("bnx_jfree: asked to free buffer that we don't manage!"); 7616c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 7626c8d8eccSSepherosa Ziehau panic("bnx_jfree: buffer already free!"); 7636c8d8eccSSepherosa Ziehau } else { 7646c8d8eccSSepherosa Ziehau /* 7656c8d8eccSSepherosa Ziehau * Possible MP race to 0, use the serializer. The atomic insn 7666c8d8eccSSepherosa Ziehau * is still needed for races against bnx_jref(). 7676c8d8eccSSepherosa Ziehau */ 7686c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 7696c8d8eccSSepherosa Ziehau atomic_subtract_int(&entry->bnx_inuse, 1); 7706c8d8eccSSepherosa Ziehau if (entry->bnx_inuse == 0) { 7716c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, 7726c8d8eccSSepherosa Ziehau entry, jslot_link); 7736c8d8eccSSepherosa Ziehau } 7746c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 7756c8d8eccSSepherosa Ziehau } 7766c8d8eccSSepherosa Ziehau } 7776c8d8eccSSepherosa Ziehau 7786c8d8eccSSepherosa Ziehau 7796c8d8eccSSepherosa Ziehau /* 7806c8d8eccSSepherosa Ziehau * Intialize a standard receive ring descriptor. 7816c8d8eccSSepherosa Ziehau */ 7826c8d8eccSSepherosa Ziehau static int 7836c8d8eccSSepherosa Ziehau bnx_newbuf_std(struct bnx_softc *sc, int i, int init) 7846c8d8eccSSepherosa Ziehau { 7856c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7866c8d8eccSSepherosa Ziehau bus_dma_segment_t seg; 7876c8d8eccSSepherosa Ziehau bus_dmamap_t map; 7886c8d8eccSSepherosa Ziehau int error, nsegs; 7896c8d8eccSSepherosa Ziehau 7906c8d8eccSSepherosa Ziehau m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR); 7916c8d8eccSSepherosa Ziehau if (m_new == NULL) 7926c8d8eccSSepherosa Ziehau return ENOBUFS; 7936c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 7946c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 7956c8d8eccSSepherosa Ziehau 7966c8d8eccSSepherosa Ziehau error = bus_dmamap_load_mbuf_segment(sc->bnx_cdata.bnx_rx_mtag, 7976c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_tmpmap, m_new, 7986c8d8eccSSepherosa Ziehau &seg, 1, &nsegs, BUS_DMA_NOWAIT); 7996c8d8eccSSepherosa Ziehau if (error) { 8006c8d8eccSSepherosa Ziehau m_freem(m_new); 8016c8d8eccSSepherosa Ziehau return error; 8026c8d8eccSSepherosa Ziehau } 8036c8d8eccSSepherosa Ziehau 8046c8d8eccSSepherosa Ziehau if (!init) { 8056c8d8eccSSepherosa Ziehau bus_dmamap_sync(sc->bnx_cdata.bnx_rx_mtag, 8066c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[i], 8076c8d8eccSSepherosa Ziehau BUS_DMASYNC_POSTREAD); 8086c8d8eccSSepherosa Ziehau bus_dmamap_unload(sc->bnx_cdata.bnx_rx_mtag, 8096c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[i]); 8106c8d8eccSSepherosa Ziehau } 8116c8d8eccSSepherosa Ziehau 8126c8d8eccSSepherosa Ziehau map = sc->bnx_cdata.bnx_rx_tmpmap; 8136c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_tmpmap = sc->bnx_cdata.bnx_rx_std_dmamap[i]; 8146c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[i] = map; 8156c8d8eccSSepherosa Ziehau 8166c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_chain[i].bnx_mbuf = m_new; 8176c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_chain[i].bnx_paddr = seg.ds_addr; 8186c8d8eccSSepherosa Ziehau 8196c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_std(sc, i); 8206c8d8eccSSepherosa Ziehau return 0; 8216c8d8eccSSepherosa Ziehau } 8226c8d8eccSSepherosa Ziehau 8236c8d8eccSSepherosa Ziehau static void 8246c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_std(struct bnx_softc *sc, int i) 8256c8d8eccSSepherosa Ziehau { 8266c8d8eccSSepherosa Ziehau struct bnx_rxchain *rc; 8276c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 8286c8d8eccSSepherosa Ziehau 8296c8d8eccSSepherosa Ziehau rc = &sc->bnx_cdata.bnx_rx_std_chain[i]; 8306c8d8eccSSepherosa Ziehau r = &sc->bnx_ldata.bnx_rx_std_ring[i]; 8316c8d8eccSSepherosa Ziehau 8326c8d8eccSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_paddr); 8336c8d8eccSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_paddr); 8346c8d8eccSSepherosa Ziehau r->bge_len = rc->bnx_mbuf->m_len; 8356c8d8eccSSepherosa Ziehau r->bge_idx = i; 8366c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END; 8376c8d8eccSSepherosa Ziehau } 8386c8d8eccSSepherosa Ziehau 8396c8d8eccSSepherosa Ziehau /* 8406c8d8eccSSepherosa Ziehau * Initialize a jumbo receive ring descriptor. This allocates 8416c8d8eccSSepherosa Ziehau * a jumbo buffer from the pool managed internally by the driver. 8426c8d8eccSSepherosa Ziehau */ 8436c8d8eccSSepherosa Ziehau static int 8446c8d8eccSSepherosa Ziehau bnx_newbuf_jumbo(struct bnx_softc *sc, int i, int init) 8456c8d8eccSSepherosa Ziehau { 8466c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 8476c8d8eccSSepherosa Ziehau struct bnx_jslot *buf; 8486c8d8eccSSepherosa Ziehau bus_addr_t paddr; 8496c8d8eccSSepherosa Ziehau 8506c8d8eccSSepherosa Ziehau /* Allocate the mbuf. */ 8516c8d8eccSSepherosa Ziehau MGETHDR(m_new, init ? MB_WAIT : MB_DONTWAIT, MT_DATA); 8526c8d8eccSSepherosa Ziehau if (m_new == NULL) 8536c8d8eccSSepherosa Ziehau return ENOBUFS; 8546c8d8eccSSepherosa Ziehau 8556c8d8eccSSepherosa Ziehau /* Allocate the jumbo buffer */ 8566c8d8eccSSepherosa Ziehau buf = bnx_jalloc(sc); 8576c8d8eccSSepherosa Ziehau if (buf == NULL) { 8586c8d8eccSSepherosa Ziehau m_freem(m_new); 8596c8d8eccSSepherosa Ziehau return ENOBUFS; 8606c8d8eccSSepherosa Ziehau } 8616c8d8eccSSepherosa Ziehau 8626c8d8eccSSepherosa Ziehau /* Attach the buffer to the mbuf. */ 8636c8d8eccSSepherosa Ziehau m_new->m_ext.ext_arg = buf; 8646c8d8eccSSepherosa Ziehau m_new->m_ext.ext_buf = buf->bnx_buf; 8656c8d8eccSSepherosa Ziehau m_new->m_ext.ext_free = bnx_jfree; 8666c8d8eccSSepherosa Ziehau m_new->m_ext.ext_ref = bnx_jref; 8676c8d8eccSSepherosa Ziehau m_new->m_ext.ext_size = BNX_JUMBO_FRAMELEN; 8686c8d8eccSSepherosa Ziehau 8696c8d8eccSSepherosa Ziehau m_new->m_flags |= M_EXT; 8706c8d8eccSSepherosa Ziehau 8716c8d8eccSSepherosa Ziehau m_new->m_data = m_new->m_ext.ext_buf; 8726c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = m_new->m_ext.ext_size; 8736c8d8eccSSepherosa Ziehau 8746c8d8eccSSepherosa Ziehau paddr = buf->bnx_paddr; 8756c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 8766c8d8eccSSepherosa Ziehau paddr += ETHER_ALIGN; 8776c8d8eccSSepherosa Ziehau 8786c8d8eccSSepherosa Ziehau /* Save necessary information */ 8796c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_mbuf = m_new; 8806c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_paddr = paddr; 8816c8d8eccSSepherosa Ziehau 8826c8d8eccSSepherosa Ziehau /* Set up the descriptor. */ 8836c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, i); 8846c8d8eccSSepherosa Ziehau return 0; 8856c8d8eccSSepherosa Ziehau } 8866c8d8eccSSepherosa Ziehau 8876c8d8eccSSepherosa Ziehau static void 8886c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(struct bnx_softc *sc, int i) 8896c8d8eccSSepherosa Ziehau { 8906c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 8916c8d8eccSSepherosa Ziehau struct bnx_rxchain *rc; 8926c8d8eccSSepherosa Ziehau 8936c8d8eccSSepherosa Ziehau r = &sc->bnx_ldata.bnx_rx_jumbo_ring[i]; 8946c8d8eccSSepherosa Ziehau rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8956c8d8eccSSepherosa Ziehau 8966c8d8eccSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_paddr); 8976c8d8eccSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_paddr); 8986c8d8eccSSepherosa Ziehau r->bge_len = rc->bnx_mbuf->m_len; 8996c8d8eccSSepherosa Ziehau r->bge_idx = i; 9006c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING; 9016c8d8eccSSepherosa Ziehau } 9026c8d8eccSSepherosa Ziehau 9036c8d8eccSSepherosa Ziehau static int 9046c8d8eccSSepherosa Ziehau bnx_init_rx_ring_std(struct bnx_softc *sc) 9056c8d8eccSSepherosa Ziehau { 9066c8d8eccSSepherosa Ziehau int i, error; 9076c8d8eccSSepherosa Ziehau 9086c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 9096c8d8eccSSepherosa Ziehau error = bnx_newbuf_std(sc, i, 1); 9106c8d8eccSSepherosa Ziehau if (error) 9116c8d8eccSSepherosa Ziehau return error; 91287c7a7cfSSascha Wildner } 9136c8d8eccSSepherosa Ziehau 9146c8d8eccSSepherosa Ziehau sc->bnx_std = BGE_STD_RX_RING_CNT - 1; 9156c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bnx_std); 9166c8d8eccSSepherosa Ziehau 9176c8d8eccSSepherosa Ziehau return(0); 9186c8d8eccSSepherosa Ziehau } 9196c8d8eccSSepherosa Ziehau 9206c8d8eccSSepherosa Ziehau static void 9216c8d8eccSSepherosa Ziehau bnx_free_rx_ring_std(struct bnx_softc *sc) 9226c8d8eccSSepherosa Ziehau { 9236c8d8eccSSepherosa Ziehau int i; 9246c8d8eccSSepherosa Ziehau 9256c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 9266c8d8eccSSepherosa Ziehau struct bnx_rxchain *rc = &sc->bnx_cdata.bnx_rx_std_chain[i]; 9276c8d8eccSSepherosa Ziehau 9286c8d8eccSSepherosa Ziehau if (rc->bnx_mbuf != NULL) { 9296c8d8eccSSepherosa Ziehau bus_dmamap_unload(sc->bnx_cdata.bnx_rx_mtag, 9306c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[i]); 9316c8d8eccSSepherosa Ziehau m_freem(rc->bnx_mbuf); 9326c8d8eccSSepherosa Ziehau rc->bnx_mbuf = NULL; 9336c8d8eccSSepherosa Ziehau } 9346c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_rx_std_ring[i], 9356c8d8eccSSepherosa Ziehau sizeof(struct bge_rx_bd)); 9366c8d8eccSSepherosa Ziehau } 9376c8d8eccSSepherosa Ziehau } 9386c8d8eccSSepherosa Ziehau 9396c8d8eccSSepherosa Ziehau static int 9406c8d8eccSSepherosa Ziehau bnx_init_rx_ring_jumbo(struct bnx_softc *sc) 9416c8d8eccSSepherosa Ziehau { 9426c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 9436c8d8eccSSepherosa Ziehau int i, error; 9446c8d8eccSSepherosa Ziehau 9456c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 9466c8d8eccSSepherosa Ziehau error = bnx_newbuf_jumbo(sc, i, 1); 9476c8d8eccSSepherosa Ziehau if (error) 9486c8d8eccSSepherosa Ziehau return error; 94987c7a7cfSSascha Wildner } 9506c8d8eccSSepherosa Ziehau 9516c8d8eccSSepherosa Ziehau sc->bnx_jumbo = BGE_JUMBO_RX_RING_CNT - 1; 9526c8d8eccSSepherosa Ziehau 9536c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 9546c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0); 9556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 9566c8d8eccSSepherosa Ziehau 9576c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 9586c8d8eccSSepherosa Ziehau 9596c8d8eccSSepherosa Ziehau return(0); 9606c8d8eccSSepherosa Ziehau } 9616c8d8eccSSepherosa Ziehau 9626c8d8eccSSepherosa Ziehau static void 9636c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(struct bnx_softc *sc) 9646c8d8eccSSepherosa Ziehau { 9656c8d8eccSSepherosa Ziehau int i; 9666c8d8eccSSepherosa Ziehau 9676c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 9686c8d8eccSSepherosa Ziehau struct bnx_rxchain *rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 9696c8d8eccSSepherosa Ziehau 9706c8d8eccSSepherosa Ziehau if (rc->bnx_mbuf != NULL) { 9716c8d8eccSSepherosa Ziehau m_freem(rc->bnx_mbuf); 9726c8d8eccSSepherosa Ziehau rc->bnx_mbuf = NULL; 9736c8d8eccSSepherosa Ziehau } 9746c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_rx_jumbo_ring[i], 9756c8d8eccSSepherosa Ziehau sizeof(struct bge_rx_bd)); 9766c8d8eccSSepherosa Ziehau } 9776c8d8eccSSepherosa Ziehau } 9786c8d8eccSSepherosa Ziehau 9796c8d8eccSSepherosa Ziehau static void 9806c8d8eccSSepherosa Ziehau bnx_free_tx_ring(struct bnx_softc *sc) 9816c8d8eccSSepherosa Ziehau { 9826c8d8eccSSepherosa Ziehau int i; 9836c8d8eccSSepherosa Ziehau 9846c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 9856c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_tx_chain[i] != NULL) { 9866c8d8eccSSepherosa Ziehau bus_dmamap_unload(sc->bnx_cdata.bnx_tx_mtag, 9876c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[i]); 9886c8d8eccSSepherosa Ziehau m_freem(sc->bnx_cdata.bnx_tx_chain[i]); 9896c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_chain[i] = NULL; 9906c8d8eccSSepherosa Ziehau } 9916c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_tx_ring[i], 9926c8d8eccSSepherosa Ziehau sizeof(struct bge_tx_bd)); 9936c8d8eccSSepherosa Ziehau } 9946c8d8eccSSepherosa Ziehau } 9956c8d8eccSSepherosa Ziehau 9966c8d8eccSSepherosa Ziehau static int 9976c8d8eccSSepherosa Ziehau bnx_init_tx_ring(struct bnx_softc *sc) 9986c8d8eccSSepherosa Ziehau { 9996c8d8eccSSepherosa Ziehau sc->bnx_txcnt = 0; 10006c8d8eccSSepherosa Ziehau sc->bnx_tx_saved_considx = 0; 10016c8d8eccSSepherosa Ziehau sc->bnx_tx_prodidx = 0; 10026c8d8eccSSepherosa Ziehau 10036c8d8eccSSepherosa Ziehau /* Initialize transmit producer index for host-memory send ring. */ 10046c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bnx_tx_prodidx); 10056c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_TX_NIC_PROD0_LO, 0); 10066c8d8eccSSepherosa Ziehau 10076c8d8eccSSepherosa Ziehau return(0); 10086c8d8eccSSepherosa Ziehau } 10096c8d8eccSSepherosa Ziehau 10106c8d8eccSSepherosa Ziehau static void 10116c8d8eccSSepherosa Ziehau bnx_setmulti(struct bnx_softc *sc) 10126c8d8eccSSepherosa Ziehau { 10136c8d8eccSSepherosa Ziehau struct ifnet *ifp; 10146c8d8eccSSepherosa Ziehau struct ifmultiaddr *ifma; 10156c8d8eccSSepherosa Ziehau uint32_t hashes[4] = { 0, 0, 0, 0 }; 10166c8d8eccSSepherosa Ziehau int h, i; 10176c8d8eccSSepherosa Ziehau 10186c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 10196c8d8eccSSepherosa Ziehau 10206c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 10216c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 10226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0xFFFFFFFF); 10236c8d8eccSSepherosa Ziehau return; 10246c8d8eccSSepherosa Ziehau } 10256c8d8eccSSepherosa Ziehau 10266c8d8eccSSepherosa Ziehau /* First, zot all the existing filters. */ 10276c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 10286c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0); 10296c8d8eccSSepherosa Ziehau 10306c8d8eccSSepherosa Ziehau /* Now program new ones. */ 10316c8d8eccSSepherosa Ziehau TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 10326c8d8eccSSepherosa Ziehau if (ifma->ifma_addr->sa_family != AF_LINK) 10336c8d8eccSSepherosa Ziehau continue; 10346c8d8eccSSepherosa Ziehau h = ether_crc32_le( 10356c8d8eccSSepherosa Ziehau LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 10366c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN) & 0x7f; 10376c8d8eccSSepherosa Ziehau hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F); 10386c8d8eccSSepherosa Ziehau } 10396c8d8eccSSepherosa Ziehau 10406c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 10416c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]); 10426c8d8eccSSepherosa Ziehau } 10436c8d8eccSSepherosa Ziehau 10446c8d8eccSSepherosa Ziehau /* 10456c8d8eccSSepherosa Ziehau * Do endian, PCI and DMA initialization. Also check the on-board ROM 10466c8d8eccSSepherosa Ziehau * self-test results. 10476c8d8eccSSepherosa Ziehau */ 10486c8d8eccSSepherosa Ziehau static int 10496c8d8eccSSepherosa Ziehau bnx_chipinit(struct bnx_softc *sc) 10506c8d8eccSSepherosa Ziehau { 10516c8d8eccSSepherosa Ziehau uint32_t dma_rw_ctl, mode_ctl; 10526c8d8eccSSepherosa Ziehau int i; 10536c8d8eccSSepherosa Ziehau 10546c8d8eccSSepherosa Ziehau /* Set endian type before we access any non-PCI registers. */ 10556c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_MISC_CTL, 10566c8d8eccSSepherosa Ziehau BGE_INIT | BGE_PCIMISCCTL_TAGGED_STATUS, 4); 10576c8d8eccSSepherosa Ziehau 10586c8d8eccSSepherosa Ziehau /* Clear the MAC control register */ 10596c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 10606c8d8eccSSepherosa Ziehau 10616c8d8eccSSepherosa Ziehau /* 10626c8d8eccSSepherosa Ziehau * Clear the MAC statistics block in the NIC's 10636c8d8eccSSepherosa Ziehau * internal memory. 10646c8d8eccSSepherosa Ziehau */ 10656c8d8eccSSepherosa Ziehau for (i = BGE_STATS_BLOCK; 10666c8d8eccSSepherosa Ziehau i < BGE_STATS_BLOCK_END + 1; i += sizeof(uint32_t)) 10676c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 10686c8d8eccSSepherosa Ziehau 10696c8d8eccSSepherosa Ziehau for (i = BGE_STATUS_BLOCK; 10706c8d8eccSSepherosa Ziehau i < BGE_STATUS_BLOCK_END + 1; i += sizeof(uint32_t)) 10716c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 10726c8d8eccSSepherosa Ziehau 1073d7872545SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) { 1074d7872545SSepherosa Ziehau uint32_t val; 1075d7872545SSepherosa Ziehau 1076d7872545SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) { 1077d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1078d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1079d7872545SSepherosa Ziehau 1080d7872545SSepherosa Ziehau /* Access the lower 1K of PL PCI-E block registers. */ 1081d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1082d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_PL_SEL); 1083d7872545SSepherosa Ziehau 1084d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_PL_LO_PHYCTL5); 1085d7872545SSepherosa Ziehau val |= BGE_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ; 1086d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PL_LO_PHYCTL5, val); 1087d7872545SSepherosa Ziehau 1088d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1089d7872545SSepherosa Ziehau } 1090d7872545SSepherosa Ziehau if (sc->bnx_chiprev != BGE_CHIPREV_57765_AX) { 1091d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1092d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1093d7872545SSepherosa Ziehau 1094d7872545SSepherosa Ziehau /* Access the lower 1K of DL PCI-E block registers. */ 1095d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1096d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_DL_SEL); 1097d7872545SSepherosa Ziehau 1098d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_DL_LO_FTSMAX); 1099d7872545SSepherosa Ziehau val &= ~BGE_PCIE_DL_LO_FTSMAX_MASK; 1100d7872545SSepherosa Ziehau val |= BGE_PCIE_DL_LO_FTSMAX_VAL; 1101d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_DL_LO_FTSMAX, val); 1102d7872545SSepherosa Ziehau 1103d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1104d7872545SSepherosa Ziehau } 1105d7872545SSepherosa Ziehau 1106d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_LSPD_10MB_CLK); 1107d7872545SSepherosa Ziehau val &= ~BGE_CPMU_LSPD_10MB_MACCLK_MASK; 1108d7872545SSepherosa Ziehau val |= BGE_CPMU_LSPD_10MB_MACCLK_6_25; 1109d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_LSPD_10MB_CLK, val); 1110d7872545SSepherosa Ziehau } 1111d7872545SSepherosa Ziehau 11122890cca3SSepherosa Ziehau /* 11132890cca3SSepherosa Ziehau * Set up the PCI DMA control register. 11142890cca3SSepherosa Ziehau */ 11152890cca3SSepherosa Ziehau dma_rw_ctl = pci_read_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, 4); 11162890cca3SSepherosa Ziehau /* 11172890cca3SSepherosa Ziehau * Disable 32bytes cache alignment for DMA write to host memory 11182890cca3SSepherosa Ziehau * 11192890cca3SSepherosa Ziehau * NOTE: 11202890cca3SSepherosa Ziehau * 64bytes cache alignment for DMA write to host memory is still 11212890cca3SSepherosa Ziehau * enabled. 11222890cca3SSepherosa Ziehau */ 11232890cca3SSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT; 11246c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 11256c8d8eccSSepherosa Ziehau dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK; 11266c8d8eccSSepherosa Ziehau /* 11276c8d8eccSSepherosa Ziehau * Enable HW workaround for controllers that misinterpret 11286c8d8eccSSepherosa Ziehau * a status tag update and leave interrupts permanently 11296c8d8eccSSepherosa Ziehau * disabled. 11306c8d8eccSSepherosa Ziehau */ 11316c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5717 && 11322890cca3SSepherosa Ziehau !BNX_IS_57765_FAMILY(sc)) 11336c8d8eccSSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA; 11342890cca3SSepherosa Ziehau if (bootverbose) { 11352890cca3SSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "DMA read/write %#x\n", 11362890cca3SSepherosa Ziehau dma_rw_ctl); 11376c8d8eccSSepherosa Ziehau } 11386c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, dma_rw_ctl, 4); 11396c8d8eccSSepherosa Ziehau 11406c8d8eccSSepherosa Ziehau /* 11416c8d8eccSSepherosa Ziehau * Set up general mode register. 11426c8d8eccSSepherosa Ziehau */ 11436c8d8eccSSepherosa Ziehau mode_ctl = bnx_dma_swap_options(sc) | BGE_MODECTL_MAC_ATTN_INTR | 11446c8d8eccSSepherosa Ziehau BGE_MODECTL_HOST_SEND_BDS | BGE_MODECTL_TX_NO_PHDR_CSUM; 11456c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 11466c8d8eccSSepherosa Ziehau 11476c8d8eccSSepherosa Ziehau /* 11486c8d8eccSSepherosa Ziehau * Disable memory write invalidate. Apparently it is not supported 11496c8d8eccSSepherosa Ziehau * properly by these devices. Also ensure that INTx isn't disabled, 11506c8d8eccSSepherosa Ziehau * as these chips need it even when using MSI. 11516c8d8eccSSepherosa Ziehau */ 11526c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_CMD, 11536c8d8eccSSepherosa Ziehau (PCIM_CMD_MWRICEN | PCIM_CMD_INTxDIS), 4); 11546c8d8eccSSepherosa Ziehau 11556c8d8eccSSepherosa Ziehau /* Set the timer prescaler (always 66Mhz) */ 11566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, 65 << 1/*BGE_32BITTIME_66MHZ*/); 11576c8d8eccSSepherosa Ziehau 11586c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) { 11596c8d8eccSSepherosa Ziehau DELAY(40); /* XXX */ 11606c8d8eccSSepherosa Ziehau 11616c8d8eccSSepherosa Ziehau /* Put PHY into ready state */ 11626c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MISC_CFG, BGE_MISCCFG_EPHY_IDDQ); 11636c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MISC_CFG); /* Flush */ 11646c8d8eccSSepherosa Ziehau DELAY(40); 11656c8d8eccSSepherosa Ziehau } 11666c8d8eccSSepherosa Ziehau 11676c8d8eccSSepherosa Ziehau return(0); 11686c8d8eccSSepherosa Ziehau } 11696c8d8eccSSepherosa Ziehau 11706c8d8eccSSepherosa Ziehau static int 11716c8d8eccSSepherosa Ziehau bnx_blockinit(struct bnx_softc *sc) 11726c8d8eccSSepherosa Ziehau { 11736c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 11746c8d8eccSSepherosa Ziehau bus_size_t vrcb; 11756c8d8eccSSepherosa Ziehau bge_hostaddr taddr; 11766c8d8eccSSepherosa Ziehau uint32_t val; 11776c8d8eccSSepherosa Ziehau int i, limit; 11786c8d8eccSSepherosa Ziehau 11796c8d8eccSSepherosa Ziehau /* 11806c8d8eccSSepherosa Ziehau * Initialize the memory window pointer register so that 11816c8d8eccSSepherosa Ziehau * we can access the first 32K of internal NIC RAM. This will 11826c8d8eccSSepherosa Ziehau * allow us to set up the TX send ring RCBs and the RX return 11836c8d8eccSSepherosa Ziehau * ring RCBs, plus other things which live in NIC memory. 11846c8d8eccSSepherosa Ziehau */ 11856c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0); 11866c8d8eccSSepherosa Ziehau 11876c8d8eccSSepherosa Ziehau /* Configure mbuf pool watermarks */ 1188f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 11896c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11906c8d8eccSSepherosa Ziehau if (sc->arpcom.ac_if.if_mtu > ETHERMTU) { 11916c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x7e); 11926c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xea); 11936c8d8eccSSepherosa Ziehau } else { 11946c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x2a); 11956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xa0); 11966c8d8eccSSepherosa Ziehau } 11976c8d8eccSSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) { 11986c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11996c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x04); 12006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x10); 12016c8d8eccSSepherosa Ziehau } else { 12026c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 12036c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10); 12046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60); 12056c8d8eccSSepherosa Ziehau } 12066c8d8eccSSepherosa Ziehau 12076c8d8eccSSepherosa Ziehau /* Configure DMA resource watermarks */ 12086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5); 12096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10); 12106c8d8eccSSepherosa Ziehau 12116c8d8eccSSepherosa Ziehau /* Enable buffer manager */ 12126c8d8eccSSepherosa Ziehau val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN; 12136c8d8eccSSepherosa Ziehau /* 12146c8d8eccSSepherosa Ziehau * Change the arbitration algorithm of TXMBUF read request to 12156c8d8eccSSepherosa Ziehau * round-robin instead of priority based for BCM5719. When 12166c8d8eccSSepherosa Ziehau * TXFIFO is almost empty, RDMA will hold its request until 12176c8d8eccSSepherosa Ziehau * TXFIFO is not almost empty. 12186c8d8eccSSepherosa Ziehau */ 12196c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) 12206c8d8eccSSepherosa Ziehau val |= BGE_BMANMODE_NO_TX_UNDERRUN; 1221e5eebe34SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1222e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0 || 1223e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5720_A0) 1224e5eebe34SSepherosa Ziehau val |= BGE_BMANMODE_LOMBUF_ATTN; 12256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MODE, val); 12266c8d8eccSSepherosa Ziehau 12276c8d8eccSSepherosa Ziehau /* Poll for buffer manager start indication */ 12286c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 12296c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_BMAN_MODE) & BGE_BMANMODE_ENABLE) 12306c8d8eccSSepherosa Ziehau break; 12316c8d8eccSSepherosa Ziehau DELAY(10); 12326c8d8eccSSepherosa Ziehau } 12336c8d8eccSSepherosa Ziehau 12346c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 12356c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 12366c8d8eccSSepherosa Ziehau "buffer manager failed to start\n"); 12376c8d8eccSSepherosa Ziehau return(ENXIO); 12386c8d8eccSSepherosa Ziehau } 12396c8d8eccSSepherosa Ziehau 12406c8d8eccSSepherosa Ziehau /* Enable flow-through queues */ 12416c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 12426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 12436c8d8eccSSepherosa Ziehau 12446c8d8eccSSepherosa Ziehau /* Wait until queue initialization is complete */ 12456c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 12466c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_FTQ_RESET) == 0) 12476c8d8eccSSepherosa Ziehau break; 12486c8d8eccSSepherosa Ziehau DELAY(10); 12496c8d8eccSSepherosa Ziehau } 12506c8d8eccSSepherosa Ziehau 12516c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 12526c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 12536c8d8eccSSepherosa Ziehau "flow-through queue init failed\n"); 12546c8d8eccSSepherosa Ziehau return(ENXIO); 12556c8d8eccSSepherosa Ziehau } 12566c8d8eccSSepherosa Ziehau 12576c8d8eccSSepherosa Ziehau /* 12586c8d8eccSSepherosa Ziehau * Summary of rings supported by the controller: 12596c8d8eccSSepherosa Ziehau * 12606c8d8eccSSepherosa Ziehau * Standard Receive Producer Ring 12616c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "standard" 12626c8d8eccSSepherosa Ziehau * sized frames (typically 1536 bytes) to the controller. 12636c8d8eccSSepherosa Ziehau * 12646c8d8eccSSepherosa Ziehau * Jumbo Receive Producer Ring 12656c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for jumbo sized 12666c8d8eccSSepherosa Ziehau * frames (i.e. anything bigger than the "standard" frames) 12676c8d8eccSSepherosa Ziehau * to the controller. 12686c8d8eccSSepherosa Ziehau * 12696c8d8eccSSepherosa Ziehau * Mini Receive Producer Ring 12706c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "mini" 12716c8d8eccSSepherosa Ziehau * sized frames to the controller. 12726c8d8eccSSepherosa Ziehau * - This feature required external memory for the controller 12736c8d8eccSSepherosa Ziehau * but was never used in a production system. Should always 12746c8d8eccSSepherosa Ziehau * be disabled. 12756c8d8eccSSepherosa Ziehau * 12766c8d8eccSSepherosa Ziehau * Receive Return Ring 12776c8d8eccSSepherosa Ziehau * - After the controller has placed an incoming frame into a 12786c8d8eccSSepherosa Ziehau * receive buffer that buffer is moved into a receive return 12796c8d8eccSSepherosa Ziehau * ring. The driver is then responsible to passing the 12806c8d8eccSSepherosa Ziehau * buffer up to the stack. Many versions of the controller 12816c8d8eccSSepherosa Ziehau * support multiple RR rings. 12826c8d8eccSSepherosa Ziehau * 12836c8d8eccSSepherosa Ziehau * Send Ring 12846c8d8eccSSepherosa Ziehau * - This ring is used for outgoing frames. Many versions of 12856c8d8eccSSepherosa Ziehau * the controller support multiple send rings. 12866c8d8eccSSepherosa Ziehau */ 12876c8d8eccSSepherosa Ziehau 12886c8d8eccSSepherosa Ziehau /* Initialize the standard receive producer ring control block. */ 12896c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_std_rx_rcb; 12906c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 12916c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_std_ring_paddr); 12926c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 12936c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_std_ring_paddr); 1294f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12956c8d8eccSSepherosa Ziehau /* 12966c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (2048, 1024, 512, .., 32) 12976c8d8eccSSepherosa Ziehau * Bits 15-2 : Maximum RX frame size 12986c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring ENabled 12996c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 13006c8d8eccSSepherosa Ziehau */ 13016c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 13026c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(512, BNX_MAX_FRAMELEN << 2); 13036c8d8eccSSepherosa Ziehau } else { 13046c8d8eccSSepherosa Ziehau /* 13056c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (512, 256, 128, 64, 32) 13066c8d8eccSSepherosa Ziehau * Bits 15-2 : Reserved (should be 0) 13076c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring Enabled 13086c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 13096c8d8eccSSepherosa Ziehau */ 13106c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(512, 0); 13116c8d8eccSSepherosa Ziehau } 1312303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 13136c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717; 13146c8d8eccSSepherosa Ziehau else 13156c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS; 13166c8d8eccSSepherosa Ziehau /* Write the standard receive producer ring control block. */ 13176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); 13186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); 13196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 13206c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_NICADDR, rcb->bge_nicaddr); 13216c8d8eccSSepherosa Ziehau /* Reset the standard receive producer ring producer index. */ 13226c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0); 13236c8d8eccSSepherosa Ziehau 13246c8d8eccSSepherosa Ziehau /* 13256c8d8eccSSepherosa Ziehau * Initialize the jumbo RX producer ring control 13266c8d8eccSSepherosa Ziehau * block. We set the 'ring disabled' bit in the 13276c8d8eccSSepherosa Ziehau * flags field until we're actually ready to start 13286c8d8eccSSepherosa Ziehau * using this ring (i.e. once we set the MTU 13296c8d8eccSSepherosa Ziehau * high enough to require it). 13306c8d8eccSSepherosa Ziehau */ 13316c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 13326c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 13336c8d8eccSSepherosa Ziehau /* Get the jumbo receive producer ring RCB parameters. */ 13346c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 13356c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 13366c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 13376c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 13386c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 13396c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_MAX_FRAMELEN, 13406c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 1341303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 13426c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717; 13436c8d8eccSSepherosa Ziehau else 13446c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; 13456c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI, 13466c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi); 13476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO, 13486c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo); 13496c8d8eccSSepherosa Ziehau /* Program the jumbo receive producer ring RCB parameters. */ 13506c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, 13516c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags); 13526c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr); 13536c8d8eccSSepherosa Ziehau /* Reset the jumbo receive producer ring producer index. */ 13546c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); 13556c8d8eccSSepherosa Ziehau } 13566c8d8eccSSepherosa Ziehau 13576c8d8eccSSepherosa Ziehau /* Choose de-pipeline mode for BCM5906 A0, A1 and A2. */ 13586c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906 && 13596c8d8eccSSepherosa Ziehau (sc->bnx_chipid == BGE_CHIPID_BCM5906_A0 || 13606c8d8eccSSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5906_A1 || 13616c8d8eccSSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5906_A2)) { 13626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_ISO_PKT_TX, 13636c8d8eccSSepherosa Ziehau (CSR_READ_4(sc, BGE_ISO_PKT_TX) & ~3) | 2); 13646c8d8eccSSepherosa Ziehau } 13656c8d8eccSSepherosa Ziehau 13666c8d8eccSSepherosa Ziehau /* 13676c8d8eccSSepherosa Ziehau * The BD ring replenish thresholds control how often the 13686c8d8eccSSepherosa Ziehau * hardware fetches new BD's from the producer rings in host 13696c8d8eccSSepherosa Ziehau * memory. Setting the value too low on a busy system can 13706c8d8eccSSepherosa Ziehau * starve the hardware and recue the throughpout. 13716c8d8eccSSepherosa Ziehau * 13726c8d8eccSSepherosa Ziehau * Set the BD ring replentish thresholds. The recommended 13736c8d8eccSSepherosa Ziehau * values are 1/8th the number of descriptors allocated to 13746c8d8eccSSepherosa Ziehau * each ring. 13756c8d8eccSSepherosa Ziehau */ 13766c8d8eccSSepherosa Ziehau val = 8; 13776c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_STD_REPL_THRESH, val); 13786c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 13796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_JUMBO_REPL_THRESH, 13806c8d8eccSSepherosa Ziehau BGE_JUMBO_RX_RING_CNT/8); 13816c8d8eccSSepherosa Ziehau } 1382f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 13836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_STD_REPLENISH_LWM, 32); 13846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_JMB_REPLENISH_LWM, 16); 13856c8d8eccSSepherosa Ziehau } 13866c8d8eccSSepherosa Ziehau 13876c8d8eccSSepherosa Ziehau /* 13886c8d8eccSSepherosa Ziehau * Disable all send rings by setting the 'ring disabled' bit 13896c8d8eccSSepherosa Ziehau * in the flags field of all the TX send ring control blocks, 13906c8d8eccSSepherosa Ziehau * located in NIC memory. 13916c8d8eccSSepherosa Ziehau */ 139280969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 139380969639SSepherosa Ziehau limit = 4; 13944f23029eSSepherosa Ziehau else if (BNX_IS_57765_FAMILY(sc)) 13954f23029eSSepherosa Ziehau limit = 2; 139680969639SSepherosa Ziehau else 13976c8d8eccSSepherosa Ziehau limit = 1; 13986c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 13996c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 14006c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 14016c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED)); 14026c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 14036c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 14046c8d8eccSSepherosa Ziehau } 14056c8d8eccSSepherosa Ziehau 14066c8d8eccSSepherosa Ziehau /* Configure send ring RCB 0 (we use only the first ring) */ 14076c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 14086c8d8eccSSepherosa Ziehau BGE_HOSTADDR(taddr, sc->bnx_ldata.bnx_tx_ring_paddr); 14096c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 14106c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 1411303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 14126c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, BGE_SEND_RING_5717); 14136c8d8eccSSepherosa Ziehau } else { 14146c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 14156c8d8eccSSepherosa Ziehau BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT)); 14166c8d8eccSSepherosa Ziehau } 14176c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 14186c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BGE_TX_RING_CNT, 0)); 14196c8d8eccSSepherosa Ziehau 14206c8d8eccSSepherosa Ziehau /* 14216c8d8eccSSepherosa Ziehau * Disable all receive return rings by setting the 14226c8d8eccSSepherosa Ziehau * 'ring disabled' bit in the flags field of all the receive 14236c8d8eccSSepherosa Ziehau * return ring control blocks, located in NIC memory. 14246c8d8eccSSepherosa Ziehau */ 142580969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 14266c8d8eccSSepherosa Ziehau /* Should be 17, use 16 until we get an SRAM map. */ 14276c8d8eccSSepherosa Ziehau limit = 16; 14284f23029eSSepherosa Ziehau } else if (BNX_IS_57765_FAMILY(sc)) { 14296c8d8eccSSepherosa Ziehau limit = 4; 14306c8d8eccSSepherosa Ziehau } else { 14316c8d8eccSSepherosa Ziehau limit = 1; 14326c8d8eccSSepherosa Ziehau } 14336c8d8eccSSepherosa Ziehau /* Disable all receive return rings. */ 14346c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 14356c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 14366c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, 0); 14376c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, 0); 14386c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 14396c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 14406c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 14416c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO + 14426c8d8eccSSepherosa Ziehau (i * (sizeof(uint64_t))), 0); 14436c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 14446c8d8eccSSepherosa Ziehau } 14456c8d8eccSSepherosa Ziehau 14466c8d8eccSSepherosa Ziehau /* 14476c8d8eccSSepherosa Ziehau * Set up receive return ring 0. Note that the NIC address 14486c8d8eccSSepherosa Ziehau * for RX return rings is 0x0. The return rings live entirely 14496c8d8eccSSepherosa Ziehau * within the host, so the nicaddr field in the RCB isn't used. 14506c8d8eccSSepherosa Ziehau */ 14516c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 14526c8d8eccSSepherosa Ziehau BGE_HOSTADDR(taddr, sc->bnx_ldata.bnx_rx_return_ring_paddr); 14536c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 14546c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 14556c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 14566c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 14576c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(sc->bnx_return_ring_cnt, 0)); 14586c8d8eccSSepherosa Ziehau 14596c8d8eccSSepherosa Ziehau /* Set random backoff seed for TX */ 14606c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_RANDOM_BACKOFF, 14616c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[0] + sc->arpcom.ac_enaddr[1] + 14626c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[2] + sc->arpcom.ac_enaddr[3] + 14636c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[4] + sc->arpcom.ac_enaddr[5] + 14646c8d8eccSSepherosa Ziehau BGE_TX_BACKOFF_SEED_MASK); 14656c8d8eccSSepherosa Ziehau 14666c8d8eccSSepherosa Ziehau /* Set inter-packet gap */ 14676c8d8eccSSepherosa Ziehau val = 0x2620; 14686c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 14696c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_TX_LENGTHS) & 14706c8d8eccSSepherosa Ziehau (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK); 14716c8d8eccSSepherosa Ziehau } 14726c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_LENGTHS, val); 14736c8d8eccSSepherosa Ziehau 14746c8d8eccSSepherosa Ziehau /* 14756c8d8eccSSepherosa Ziehau * Specify which ring to use for packets that don't match 14766c8d8eccSSepherosa Ziehau * any RX rules. 14776c8d8eccSSepherosa Ziehau */ 14786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_RULES_CFG, 0x08); 14796c8d8eccSSepherosa Ziehau 14806c8d8eccSSepherosa Ziehau /* 14816c8d8eccSSepherosa Ziehau * Configure number of RX lists. One interrupt distribution 14826c8d8eccSSepherosa Ziehau * list, sixteen active lists, one bad frames class. 14836c8d8eccSSepherosa Ziehau */ 14846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181); 14856c8d8eccSSepherosa Ziehau 14866c8d8eccSSepherosa Ziehau /* Inialize RX list placement stats mask. */ 14876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF); 14886c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1); 14896c8d8eccSSepherosa Ziehau 14906c8d8eccSSepherosa Ziehau /* Disable host coalescing until we get it set up */ 14916c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, 0x00000000); 14926c8d8eccSSepherosa Ziehau 14936c8d8eccSSepherosa Ziehau /* Poll to make sure it's shut down. */ 14946c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 14956c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_HCC_MODE) & BGE_HCCMODE_ENABLE)) 14966c8d8eccSSepherosa Ziehau break; 14976c8d8eccSSepherosa Ziehau DELAY(10); 14986c8d8eccSSepherosa Ziehau } 14996c8d8eccSSepherosa Ziehau 15006c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 15016c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 15026c8d8eccSSepherosa Ziehau "host coalescing engine failed to idle\n"); 15036c8d8eccSSepherosa Ziehau return(ENXIO); 15046c8d8eccSSepherosa Ziehau } 15056c8d8eccSSepherosa Ziehau 15066c8d8eccSSepherosa Ziehau /* Set up host coalescing defaults */ 15076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, sc->bnx_rx_coal_ticks); 15086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bnx_tx_coal_ticks); 15096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bnx_rx_coal_bds); 15106c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bnx_tx_coal_bds); 15116c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, sc->bnx_rx_coal_bds_int); 15126c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, sc->bnx_tx_coal_bds_int); 15136c8d8eccSSepherosa Ziehau 15146c8d8eccSSepherosa Ziehau /* Set up address of status block */ 15156c8d8eccSSepherosa Ziehau bzero(sc->bnx_ldata.bnx_status_block, BGE_STATUS_BLK_SZ); 15166c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_HI, 15176c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_status_block_paddr)); 15186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_LO, 15196c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_status_block_paddr)); 15206c8d8eccSSepherosa Ziehau 15216c8d8eccSSepherosa Ziehau /* Set up status block partail update size. */ 15226c8d8eccSSepherosa Ziehau val = BGE_STATBLKSZ_32BYTE; 15236c8d8eccSSepherosa Ziehau #if 0 15246c8d8eccSSepherosa Ziehau /* 15256c8d8eccSSepherosa Ziehau * Does not seem to have visible effect in both 15266c8d8eccSSepherosa Ziehau * bulk data (1472B UDP datagram) and tiny data 15276c8d8eccSSepherosa Ziehau * (18B UDP datagram) TX tests. 15286c8d8eccSSepherosa Ziehau */ 15296c8d8eccSSepherosa Ziehau val |= BGE_HCCMODE_CLRTICK_TX; 15306c8d8eccSSepherosa Ziehau #endif 15316c8d8eccSSepherosa Ziehau /* Turn on host coalescing state machine */ 15326c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE); 15336c8d8eccSSepherosa Ziehau 15346c8d8eccSSepherosa Ziehau /* Turn on RX BD completion state machine and enable attentions */ 15356c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDC_MODE, 15366c8d8eccSSepherosa Ziehau BGE_RBDCMODE_ENABLE|BGE_RBDCMODE_ATTN); 15376c8d8eccSSepherosa Ziehau 15386c8d8eccSSepherosa Ziehau /* Turn on RX list placement state machine */ 15396c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 15406c8d8eccSSepherosa Ziehau 15416c8d8eccSSepherosa Ziehau val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB | 15426c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_CLEAR | BGE_MACMODE_TX_STATS_CLEAR | 15436c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_ENB | BGE_MACMODE_TX_STATS_ENB | 15446c8d8eccSSepherosa Ziehau BGE_MACMODE_FRMHDR_DMA_ENB; 15456c8d8eccSSepherosa Ziehau 15466c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 15476c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_TBI; 15486c8d8eccSSepherosa Ziehau else if (sc->bnx_flags & BNX_FLAG_MII_SERDES) 15496c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_GMII; 15506c8d8eccSSepherosa Ziehau else 15516c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_MII; 15526c8d8eccSSepherosa Ziehau 15536c8d8eccSSepherosa Ziehau /* Turn on DMA, clear stats */ 15546c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, val); 15556c8d8eccSSepherosa Ziehau 15566c8d8eccSSepherosa Ziehau /* Set misc. local control, enable interrupts on attentions */ 15576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN); 15586c8d8eccSSepherosa Ziehau 15596c8d8eccSSepherosa Ziehau #ifdef notdef 15606c8d8eccSSepherosa Ziehau /* Assert GPIO pins for PHY reset */ 15616c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUT0| 15626c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUT1|BGE_MLC_MISCIO_OUT2); 15636c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUTEN0| 15646c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUTEN1|BGE_MLC_MISCIO_OUTEN2); 15656c8d8eccSSepherosa Ziehau #endif 15666c8d8eccSSepherosa Ziehau 15676c8d8eccSSepherosa Ziehau /* Turn on write DMA state machine */ 15686c8d8eccSSepherosa Ziehau val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS; 15696c8d8eccSSepherosa Ziehau /* Enable host coalescing bug fix. */ 15706c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_STATUS_TAG_FIX; 15716c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5785) { 15726c8d8eccSSepherosa Ziehau /* Request larger DMA burst size to get better performance. */ 15736c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_BURST_ALL_DATA; 15746c8d8eccSSepherosa Ziehau } 15756c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_WDMA_MODE, val); 15766c8d8eccSSepherosa Ziehau DELAY(40); 15776c8d8eccSSepherosa Ziehau 15783730a14dSSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 15796c8d8eccSSepherosa Ziehau uint32_t dmactl; 15806c8d8eccSSepherosa Ziehau 15816c8d8eccSSepherosa Ziehau dmactl = CSR_READ_4(sc, BGE_RDMA_RSRVCTRL); 15826c8d8eccSSepherosa Ziehau /* 15836c8d8eccSSepherosa Ziehau * Adjust tx margin to prevent TX data corruption and 15846c8d8eccSSepherosa Ziehau * fix internal FIFO overflow. 15856c8d8eccSSepherosa Ziehau */ 15866c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 15876c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 15886c8d8eccSSepherosa Ziehau dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK | 15896c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK | 15906c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_MASK); 15916c8d8eccSSepherosa Ziehau dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K | 15926c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K | 15936c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_320B; 15946c8d8eccSSepherosa Ziehau } 15956c8d8eccSSepherosa Ziehau /* 15966c8d8eccSSepherosa Ziehau * Enable fix for read DMA FIFO overruns. 15976c8d8eccSSepherosa Ziehau * The fix is to limit the number of RX BDs 15986c8d8eccSSepherosa Ziehau * the hardware would fetch at a fime. 15996c8d8eccSSepherosa Ziehau */ 16006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_RSRVCTRL, 16016c8d8eccSSepherosa Ziehau dmactl | BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX); 16026c8d8eccSSepherosa Ziehau } 16036c8d8eccSSepherosa Ziehau 16046c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) { 16056c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, 16066c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | 16076c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K | 16086c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 16096c8d8eccSSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 16106c8d8eccSSepherosa Ziehau /* 16116c8d8eccSSepherosa Ziehau * Allow 4KB burst length reads for non-LSO frames. 16126c8d8eccSSepherosa Ziehau * Enable 512B burst length reads for buffer descriptors. 16136c8d8eccSSepherosa Ziehau */ 16146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, 16156c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | 16166c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 | 16176c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 16186c8d8eccSSepherosa Ziehau } 16196c8d8eccSSepherosa Ziehau 16206c8d8eccSSepherosa Ziehau /* Turn on read DMA state machine */ 16216c8d8eccSSepherosa Ziehau val = BGE_RDMAMODE_ENABLE | BGE_RDMAMODE_ALL_ATTNS; 16226c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717) 16236c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_MULT_DMA_RD_DIS; 16246c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5784 || 16256c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5785 || 16266c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM57780) { 16276c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_BD_SBD_CRPT_ATTN | 16286c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_RBD_CRPT_ATTN | 16296c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_SBD_CRPT_ATTN; 16306c8d8eccSSepherosa Ziehau } 16316c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 16326c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_RDMA_MODE) & 16336c8d8eccSSepherosa Ziehau BGE_RDMAMODE_H2BNC_VLAN_DET; 16346c8d8eccSSepherosa Ziehau /* 16356c8d8eccSSepherosa Ziehau * Allow multiple outstanding read requests from 16366c8d8eccSSepherosa Ziehau * non-LSO read DMA engine. 16376c8d8eccSSepherosa Ziehau */ 16386c8d8eccSSepherosa Ziehau val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS; 16396c8d8eccSSepherosa Ziehau } 164066deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) 164166deb1c1SSepherosa Ziehau val |= BGE_RDMAMODE_TSO4_ENABLE; 16426c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_FIFO_LONG_BURST; 16436c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_MODE, val); 16446c8d8eccSSepherosa Ziehau DELAY(40); 16456c8d8eccSSepherosa Ziehau 16466c8d8eccSSepherosa Ziehau /* Turn on RX data completion state machine */ 16476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 16486c8d8eccSSepherosa Ziehau 16496c8d8eccSSepherosa Ziehau /* Turn on RX BD initiator state machine */ 16506c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 16516c8d8eccSSepherosa Ziehau 16526c8d8eccSSepherosa Ziehau /* Turn on RX data and RX BD initiator state machine */ 16536c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE); 16546c8d8eccSSepherosa Ziehau 16556c8d8eccSSepherosa Ziehau /* Turn on send BD completion state machine */ 16566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 16576c8d8eccSSepherosa Ziehau 16586c8d8eccSSepherosa Ziehau /* Turn on send data completion state machine */ 16596c8d8eccSSepherosa Ziehau val = BGE_SDCMODE_ENABLE; 16606c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5761) 16616c8d8eccSSepherosa Ziehau val |= BGE_SDCMODE_CDELAY; 16626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDC_MODE, val); 16636c8d8eccSSepherosa Ziehau 16646c8d8eccSSepherosa Ziehau /* Turn on send data initiator state machine */ 166566deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 166666deb1c1SSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE | 166766deb1c1SSepherosa Ziehau BGE_SDIMODE_HW_LSO_PRE_DMA); 166866deb1c1SSepherosa Ziehau } else { 16696c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 167066deb1c1SSepherosa Ziehau } 16716c8d8eccSSepherosa Ziehau 16726c8d8eccSSepherosa Ziehau /* Turn on send BD initiator state machine */ 16736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 16746c8d8eccSSepherosa Ziehau 16756c8d8eccSSepherosa Ziehau /* Turn on send BD selector state machine */ 16766c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 16776c8d8eccSSepherosa Ziehau 16786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF); 16796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_CTL, 16806c8d8eccSSepherosa Ziehau BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER); 16816c8d8eccSSepherosa Ziehau 16826c8d8eccSSepherosa Ziehau /* ack/clear link change events */ 16836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16846c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16856c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16866c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, 0); 16876c8d8eccSSepherosa Ziehau 16886c8d8eccSSepherosa Ziehau /* 16896c8d8eccSSepherosa Ziehau * Enable attention when the link has changed state for 16906c8d8eccSSepherosa Ziehau * devices that use auto polling. 16916c8d8eccSSepherosa Ziehau */ 16926c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 16936c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK); 16946c8d8eccSSepherosa Ziehau } else { 16956c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 16966c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 16976c8d8eccSSepherosa Ziehau DELAY(80); 16986c8d8eccSSepherosa Ziehau } 16996c8d8eccSSepherosa Ziehau } 17006c8d8eccSSepherosa Ziehau 17016c8d8eccSSepherosa Ziehau /* 17026c8d8eccSSepherosa Ziehau * Clear any pending link state attention. 17036c8d8eccSSepherosa Ziehau * Otherwise some link state change events may be lost until attention 17046c8d8eccSSepherosa Ziehau * is cleared by bnx_intr() -> bnx_softc.bnx_link_upd() sequence. 17056c8d8eccSSepherosa Ziehau * It's not necessary on newer BCM chips - perhaps enabling link 17066c8d8eccSSepherosa Ziehau * state change attentions implies clearing pending attention. 17076c8d8eccSSepherosa Ziehau */ 17086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 17096c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 17106c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 17116c8d8eccSSepherosa Ziehau 17126c8d8eccSSepherosa Ziehau /* Enable link state change attentions. */ 17136c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_LINK_CHANGED); 17146c8d8eccSSepherosa Ziehau 17156c8d8eccSSepherosa Ziehau return(0); 17166c8d8eccSSepherosa Ziehau } 17176c8d8eccSSepherosa Ziehau 17186c8d8eccSSepherosa Ziehau /* 17196c8d8eccSSepherosa Ziehau * Probe for a Broadcom chip. Check the PCI vendor and device IDs 17206c8d8eccSSepherosa Ziehau * against our list and return its name if we find a match. Note 17216c8d8eccSSepherosa Ziehau * that since the Broadcom controller contains VPD support, we 17226c8d8eccSSepherosa Ziehau * can get the device name string from the controller itself instead 17236c8d8eccSSepherosa Ziehau * of the compiled-in string. This is a little slow, but it guarantees 17246c8d8eccSSepherosa Ziehau * we'll always announce the right product name. 17256c8d8eccSSepherosa Ziehau */ 17266c8d8eccSSepherosa Ziehau static int 17276c8d8eccSSepherosa Ziehau bnx_probe(device_t dev) 17286c8d8eccSSepherosa Ziehau { 17296c8d8eccSSepherosa Ziehau const struct bnx_type *t; 17306c8d8eccSSepherosa Ziehau uint16_t product, vendor; 17316c8d8eccSSepherosa Ziehau 17326c8d8eccSSepherosa Ziehau if (!pci_is_pcie(dev)) 17336c8d8eccSSepherosa Ziehau return ENXIO; 17346c8d8eccSSepherosa Ziehau 17356c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 17366c8d8eccSSepherosa Ziehau vendor = pci_get_vendor(dev); 17376c8d8eccSSepherosa Ziehau 17386c8d8eccSSepherosa Ziehau for (t = bnx_devs; t->bnx_name != NULL; t++) { 17396c8d8eccSSepherosa Ziehau if (vendor == t->bnx_vid && product == t->bnx_did) 17406c8d8eccSSepherosa Ziehau break; 17416c8d8eccSSepherosa Ziehau } 17426c8d8eccSSepherosa Ziehau if (t->bnx_name == NULL) 17436c8d8eccSSepherosa Ziehau return ENXIO; 17446c8d8eccSSepherosa Ziehau 17456c8d8eccSSepherosa Ziehau device_set_desc(dev, t->bnx_name); 17466c8d8eccSSepherosa Ziehau return 0; 17476c8d8eccSSepherosa Ziehau } 17486c8d8eccSSepherosa Ziehau 17496c8d8eccSSepherosa Ziehau static int 17506c8d8eccSSepherosa Ziehau bnx_attach(device_t dev) 17516c8d8eccSSepherosa Ziehau { 17526c8d8eccSSepherosa Ziehau struct ifnet *ifp; 17536c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 17546c8d8eccSSepherosa Ziehau uint32_t hwcfg = 0, misccfg; 17556c8d8eccSSepherosa Ziehau int error = 0, rid, capmask; 17566c8d8eccSSepherosa Ziehau uint8_t ether_addr[ETHER_ADDR_LEN]; 17576c8d8eccSSepherosa Ziehau uint16_t product, vendor; 17586c8d8eccSSepherosa Ziehau driver_intr_t *intr_func; 17596c8d8eccSSepherosa Ziehau uintptr_t mii_priv = 0; 17606c8d8eccSSepherosa Ziehau u_int intr_flags; 176166deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 176266deb1c1SSepherosa Ziehau char desc[32]; 176366deb1c1SSepherosa Ziehau int i; 176466deb1c1SSepherosa Ziehau #endif 17656c8d8eccSSepherosa Ziehau 17666c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 17676c8d8eccSSepherosa Ziehau sc->bnx_dev = dev; 176850668ed5SSepherosa Ziehau callout_init_mp(&sc->bnx_stat_timer); 1769df9ccc98SSepherosa Ziehau callout_init_mp(&sc->bnx_intr_timer); 17706c8d8eccSSepherosa Ziehau lwkt_serialize_init(&sc->bnx_jslot_serializer); 17716c8d8eccSSepherosa Ziehau 17726c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 17736c8d8eccSSepherosa Ziehau vendor = pci_get_vendor(dev); 17746c8d8eccSSepherosa Ziehau 17756c8d8eccSSepherosa Ziehau #ifndef BURN_BRIDGES 17766c8d8eccSSepherosa Ziehau if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 17776c8d8eccSSepherosa Ziehau uint32_t irq, mem; 17786c8d8eccSSepherosa Ziehau 17796c8d8eccSSepherosa Ziehau irq = pci_read_config(dev, PCIR_INTLINE, 4); 17806c8d8eccSSepherosa Ziehau mem = pci_read_config(dev, BGE_PCI_BAR0, 4); 17816c8d8eccSSepherosa Ziehau 17826c8d8eccSSepherosa Ziehau device_printf(dev, "chip is in D%d power mode " 17836c8d8eccSSepherosa Ziehau "-- setting to D0\n", pci_get_powerstate(dev)); 17846c8d8eccSSepherosa Ziehau 17856c8d8eccSSepherosa Ziehau pci_set_powerstate(dev, PCI_POWERSTATE_D0); 17866c8d8eccSSepherosa Ziehau 17876c8d8eccSSepherosa Ziehau pci_write_config(dev, PCIR_INTLINE, irq, 4); 17886c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_BAR0, mem, 4); 17896c8d8eccSSepherosa Ziehau } 17906c8d8eccSSepherosa Ziehau #endif /* !BURN_BRIDGE */ 17916c8d8eccSSepherosa Ziehau 17926c8d8eccSSepherosa Ziehau /* 17936c8d8eccSSepherosa Ziehau * Map control/status registers. 17946c8d8eccSSepherosa Ziehau */ 17956c8d8eccSSepherosa Ziehau pci_enable_busmaster(dev); 17966c8d8eccSSepherosa Ziehau 17976c8d8eccSSepherosa Ziehau rid = BGE_PCI_BAR0; 17986c8d8eccSSepherosa Ziehau sc->bnx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 17996c8d8eccSSepherosa Ziehau RF_ACTIVE); 18006c8d8eccSSepherosa Ziehau 18016c8d8eccSSepherosa Ziehau if (sc->bnx_res == NULL) { 18026c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't map memory\n"); 18036c8d8eccSSepherosa Ziehau return ENXIO; 18046c8d8eccSSepherosa Ziehau } 18056c8d8eccSSepherosa Ziehau 18066c8d8eccSSepherosa Ziehau sc->bnx_btag = rman_get_bustag(sc->bnx_res); 18076c8d8eccSSepherosa Ziehau sc->bnx_bhandle = rman_get_bushandle(sc->bnx_res); 18086c8d8eccSSepherosa Ziehau 18096c8d8eccSSepherosa Ziehau /* Save various chip information */ 18106c8d8eccSSepherosa Ziehau sc->bnx_chipid = 18116c8d8eccSSepherosa Ziehau pci_read_config(dev, BGE_PCI_MISC_CTL, 4) >> 18126c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_ASICREV_SHIFT; 18136c8d8eccSSepherosa Ziehau if (BGE_ASICREV(sc->bnx_chipid) == BGE_ASICREV_USE_PRODID_REG) { 18146c8d8eccSSepherosa Ziehau /* All chips having dedicated ASICREV register have CPMU */ 18156c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_CPMU; 18166c8d8eccSSepherosa Ziehau 18176c8d8eccSSepherosa Ziehau switch (product) { 18186c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717: 18196c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5718: 18206c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5719: 18216c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5720_ALT: 18226c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 18236c8d8eccSSepherosa Ziehau BGE_PCI_GEN2_PRODID_ASICREV, 4); 18246c8d8eccSSepherosa Ziehau break; 18256c8d8eccSSepherosa Ziehau 18266c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57761: 182732ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57762: 18286c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57765: 182932ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57766: 18306c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57781: 183132ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57782: 18326c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57785: 183332ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57786: 18346c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57791: 18356c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57795: 18366c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 18376c8d8eccSSepherosa Ziehau BGE_PCI_GEN15_PRODID_ASICREV, 4); 18386c8d8eccSSepherosa Ziehau break; 18396c8d8eccSSepherosa Ziehau 18406c8d8eccSSepherosa Ziehau default: 18416c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 18426c8d8eccSSepherosa Ziehau BGE_PCI_PRODID_ASICREV, 4); 18436c8d8eccSSepherosa Ziehau break; 18446c8d8eccSSepherosa Ziehau } 18456c8d8eccSSepherosa Ziehau } 18466c8d8eccSSepherosa Ziehau sc->bnx_asicrev = BGE_ASICREV(sc->bnx_chipid); 18476c8d8eccSSepherosa Ziehau sc->bnx_chiprev = BGE_CHIPREV(sc->bnx_chipid); 18486c8d8eccSSepherosa Ziehau 18496c8d8eccSSepherosa Ziehau switch (sc->bnx_asicrev) { 18506c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5717: 18516c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5719: 18526c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5720: 1853f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_5717_PLUS | BNX_FLAG_57765_PLUS; 1854f368d0d9SSepherosa Ziehau break; 1855f368d0d9SSepherosa Ziehau 18566c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM57765: 185732ff3c80SSepherosa Ziehau case BGE_ASICREV_BCM57766: 1858f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_FAMILY | BNX_FLAG_57765_PLUS; 18596c8d8eccSSepherosa Ziehau break; 18606c8d8eccSSepherosa Ziehau } 18616c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_SHORTDMA; 18626c8d8eccSSepherosa Ziehau 186366deb1c1SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TSO; 186466deb1c1SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 && 186566deb1c1SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0) 186666deb1c1SSepherosa Ziehau sc->bnx_flags &= ~BNX_FLAG_TSO; 186766deb1c1SSepherosa Ziehau 1868df9ccc98SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1869df9ccc98SSepherosa Ziehau BNX_IS_57765_FAMILY(sc)) { 1870df9ccc98SSepherosa Ziehau /* 1871df9ccc98SSepherosa Ziehau * All BCM57785 and BCM5718 families chips have a bug that 1872df9ccc98SSepherosa Ziehau * under certain situation interrupt will not be enabled 1873df9ccc98SSepherosa Ziehau * even if status tag is written to BGE_MBX_IRQ0_LO mailbox. 1874df9ccc98SSepherosa Ziehau * 1875df9ccc98SSepherosa Ziehau * While BCM5719 and BCM5720 have a hardware workaround 1876df9ccc98SSepherosa Ziehau * which could fix the above bug. 1877df9ccc98SSepherosa Ziehau * See the comment near BGE_PCIDMARWCTL_TAGGED_STATUS_WA in 1878df9ccc98SSepherosa Ziehau * bnx_chipinit(). 1879df9ccc98SSepherosa Ziehau * 1880df9ccc98SSepherosa Ziehau * For the rest of the chips in these two families, we will 1881df9ccc98SSepherosa Ziehau * have to poll the status block at high rate (10ms currently) 1882df9ccc98SSepherosa Ziehau * to check whether the interrupt is hosed or not. 1883df9ccc98SSepherosa Ziehau * See bnx_intr_check() for details. 1884df9ccc98SSepherosa Ziehau */ 1885df9ccc98SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_STATUSTAG_BUG; 1886df9ccc98SSepherosa Ziehau } 1887df9ccc98SSepherosa Ziehau 18886c8d8eccSSepherosa Ziehau misccfg = CSR_READ_4(sc, BGE_MISC_CFG) & BGE_MISCCFG_BOARD_ID_MASK; 18896c8d8eccSSepherosa Ziehau 18906c8d8eccSSepherosa Ziehau sc->bnx_pciecap = pci_get_pciecap_ptr(sc->bnx_dev); 18916c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 18926c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720) 18936c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_2048); 18946c8d8eccSSepherosa Ziehau else 18956c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_4096); 18966c8d8eccSSepherosa Ziehau device_printf(dev, "CHIP ID 0x%08x; " 18976c8d8eccSSepherosa Ziehau "ASIC REV 0x%02x; CHIP REV 0x%02x\n", 18986c8d8eccSSepherosa Ziehau sc->bnx_chipid, sc->bnx_asicrev, sc->bnx_chiprev); 18996c8d8eccSSepherosa Ziehau 19006c8d8eccSSepherosa Ziehau /* 19016c8d8eccSSepherosa Ziehau * Set various PHY quirk flags. 19026c8d8eccSSepherosa Ziehau */ 19036c8d8eccSSepherosa Ziehau 19046c8d8eccSSepherosa Ziehau capmask = MII_CAPMASK_DEFAULT; 190546283a40SSepherosa Ziehau if (product == PCI_PRODUCT_BROADCOM_BCM57791 || 190646283a40SSepherosa Ziehau product == PCI_PRODUCT_BROADCOM_BCM57795) { 19076c8d8eccSSepherosa Ziehau /* 10/100 only */ 19086c8d8eccSSepherosa Ziehau capmask &= ~BMSR_EXTSTAT; 19096c8d8eccSSepherosa Ziehau } 19106c8d8eccSSepherosa Ziehau 19116c8d8eccSSepherosa Ziehau mii_priv |= BRGPHY_FLAG_WIRESPEED; 19126c8d8eccSSepherosa Ziehau 19136c8d8eccSSepherosa Ziehau /* 19146c8d8eccSSepherosa Ziehau * Allocate interrupt 19156c8d8eccSSepherosa Ziehau */ 19166c8d8eccSSepherosa Ziehau sc->bnx_irq_type = pci_alloc_1intr(dev, bnx_msi_enable, &sc->bnx_irq_rid, 19176c8d8eccSSepherosa Ziehau &intr_flags); 19186c8d8eccSSepherosa Ziehau 19196c8d8eccSSepherosa Ziehau sc->bnx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->bnx_irq_rid, 19206c8d8eccSSepherosa Ziehau intr_flags); 19216c8d8eccSSepherosa Ziehau if (sc->bnx_irq == NULL) { 19226c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't map interrupt\n"); 19236c8d8eccSSepherosa Ziehau error = ENXIO; 19246c8d8eccSSepherosa Ziehau goto fail; 19256c8d8eccSSepherosa Ziehau } 19266c8d8eccSSepherosa Ziehau 19276c8d8eccSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 19286c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_ONESHOT_MSI; 19296c8d8eccSSepherosa Ziehau bnx_enable_msi(sc); 19306c8d8eccSSepherosa Ziehau } 19316c8d8eccSSepherosa Ziehau 19326c8d8eccSSepherosa Ziehau /* Initialize if_name earlier, so if_printf could be used */ 19336c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 19346c8d8eccSSepherosa Ziehau if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 19356c8d8eccSSepherosa Ziehau 19366c8d8eccSSepherosa Ziehau /* Try to reset the chip. */ 19376c8d8eccSSepherosa Ziehau bnx_reset(sc); 19386c8d8eccSSepherosa Ziehau 19396c8d8eccSSepherosa Ziehau if (bnx_chipinit(sc)) { 19406c8d8eccSSepherosa Ziehau device_printf(dev, "chip initialization failed\n"); 19416c8d8eccSSepherosa Ziehau error = ENXIO; 19426c8d8eccSSepherosa Ziehau goto fail; 19436c8d8eccSSepherosa Ziehau } 19446c8d8eccSSepherosa Ziehau 19456c8d8eccSSepherosa Ziehau /* 19466c8d8eccSSepherosa Ziehau * Get station address 19476c8d8eccSSepherosa Ziehau */ 19486c8d8eccSSepherosa Ziehau error = bnx_get_eaddr(sc, ether_addr); 19496c8d8eccSSepherosa Ziehau if (error) { 19506c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read station address\n"); 19516c8d8eccSSepherosa Ziehau goto fail; 19526c8d8eccSSepherosa Ziehau } 19536c8d8eccSSepherosa Ziehau 1954f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 19556c8d8eccSSepherosa Ziehau sc->bnx_return_ring_cnt = BGE_RETURN_RING_CNT; 19566c8d8eccSSepherosa Ziehau } else { 19576c8d8eccSSepherosa Ziehau /* 5705/5750 limits RX return ring to 512 entries. */ 19586c8d8eccSSepherosa Ziehau sc->bnx_return_ring_cnt = BGE_RETURN_RING_CNT_5705; 19596c8d8eccSSepherosa Ziehau } 19606c8d8eccSSepherosa Ziehau 19616c8d8eccSSepherosa Ziehau error = bnx_dma_alloc(sc); 19626c8d8eccSSepherosa Ziehau if (error) 19636c8d8eccSSepherosa Ziehau goto fail; 19646c8d8eccSSepherosa Ziehau 19656c8d8eccSSepherosa Ziehau /* Set default tuneable values. */ 19666c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks = BNX_RX_COAL_TICKS_DEF; 19676c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks = BNX_TX_COAL_TICKS_DEF; 19686c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds = BNX_RX_COAL_BDS_DEF; 19696c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds = BNX_TX_COAL_BDS_DEF; 1970306e5498SSepherosa Ziehau sc->bnx_rx_coal_bds_int = BNX_RX_COAL_BDS_INT_DEF; 1971306e5498SSepherosa Ziehau sc->bnx_tx_coal_bds_int = BNX_TX_COAL_BDS_INT_DEF; 1972c9b7f592SSepherosa Ziehau sc->bnx_tx_wreg = 8; 19736c8d8eccSSepherosa Ziehau 19746c8d8eccSSepherosa Ziehau /* Set up ifnet structure */ 19756c8d8eccSSepherosa Ziehau ifp->if_softc = sc; 19766c8d8eccSSepherosa Ziehau ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 19776c8d8eccSSepherosa Ziehau ifp->if_ioctl = bnx_ioctl; 19786c8d8eccSSepherosa Ziehau ifp->if_start = bnx_start; 197939a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 198039a8d43aSSepherosa Ziehau ifp->if_npoll = bnx_npoll; 19816c8d8eccSSepherosa Ziehau #endif 19826c8d8eccSSepherosa Ziehau ifp->if_watchdog = bnx_watchdog; 19836c8d8eccSSepherosa Ziehau ifp->if_init = bnx_init; 19846c8d8eccSSepherosa Ziehau ifp->if_mtu = ETHERMTU; 19856c8d8eccSSepherosa Ziehau ifp->if_capabilities = IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; 19866c8d8eccSSepherosa Ziehau ifq_set_maxlen(&ifp->if_snd, BGE_TX_RING_CNT - 1); 19876c8d8eccSSepherosa Ziehau ifq_set_ready(&ifp->if_snd); 19886c8d8eccSSepherosa Ziehau 19896c8d8eccSSepherosa Ziehau ifp->if_capabilities |= IFCAP_HWCSUM; 19906c8d8eccSSepherosa Ziehau ifp->if_hwassist = BNX_CSUM_FEATURES; 199166deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 199266deb1c1SSepherosa Ziehau ifp->if_capabilities |= IFCAP_TSO; 199366deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 199466deb1c1SSepherosa Ziehau } 19956c8d8eccSSepherosa Ziehau ifp->if_capenable = ifp->if_capabilities; 19966c8d8eccSSepherosa Ziehau 19976c8d8eccSSepherosa Ziehau /* 19986c8d8eccSSepherosa Ziehau * Figure out what sort of media we have by checking the 19996c8d8eccSSepherosa Ziehau * hardware config word in the first 32k of NIC internal memory, 20006c8d8eccSSepherosa Ziehau * or fall back to examining the EEPROM if necessary. 20016c8d8eccSSepherosa Ziehau * Note: on some BCM5700 cards, this value appears to be unset. 20026c8d8eccSSepherosa Ziehau * If that's the case, we have to rely on identifying the NIC 20036c8d8eccSSepherosa Ziehau * by its PCI subsystem ID, as we do below for the SysKonnect 20046c8d8eccSSepherosa Ziehau * SK-9D41. 20056c8d8eccSSepherosa Ziehau */ 20066c8d8eccSSepherosa Ziehau if (bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER) { 20076c8d8eccSSepherosa Ziehau hwcfg = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG); 20086c8d8eccSSepherosa Ziehau } else { 20096c8d8eccSSepherosa Ziehau if (bnx_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET, 20106c8d8eccSSepherosa Ziehau sizeof(hwcfg))) { 20116c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read EEPROM\n"); 20126c8d8eccSSepherosa Ziehau error = ENXIO; 20136c8d8eccSSepherosa Ziehau goto fail; 20146c8d8eccSSepherosa Ziehau } 20156c8d8eccSSepherosa Ziehau hwcfg = ntohl(hwcfg); 20166c8d8eccSSepherosa Ziehau } 20176c8d8eccSSepherosa Ziehau 20186c8d8eccSSepherosa Ziehau /* The SysKonnect SK-9D41 is a 1000baseSX card. */ 20196c8d8eccSSepherosa Ziehau if (pci_get_subvendor(dev) == PCI_PRODUCT_SCHNEIDERKOCH_SK_9D41 || 20206c8d8eccSSepherosa Ziehau (hwcfg & BGE_HWCFG_MEDIA) == BGE_MEDIA_FIBER) 20216c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TBI; 20226c8d8eccSSepherosa Ziehau 20236c8d8eccSSepherosa Ziehau /* Setup MI MODE */ 20246c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_CPMU) 20256c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_500KHZ_CONST; 20266c8d8eccSSepherosa Ziehau else 20276c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_BASE; 20286c8d8eccSSepherosa Ziehau 20296c8d8eccSSepherosa Ziehau /* Setup link status update stuffs */ 20306c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 20316c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_tbi_link_upd; 20326c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20336c8d8eccSSepherosa Ziehau } else if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 20346c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_autopoll_link_upd; 20356c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20366c8d8eccSSepherosa Ziehau } else { 20376c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_copper_link_upd; 20386c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20396c8d8eccSSepherosa Ziehau } 20406c8d8eccSSepherosa Ziehau 20416c8d8eccSSepherosa Ziehau /* Set default PHY address */ 20426c8d8eccSSepherosa Ziehau sc->bnx_phyno = 1; 20436c8d8eccSSepherosa Ziehau 20446c8d8eccSSepherosa Ziehau /* 20456c8d8eccSSepherosa Ziehau * PHY address mapping for various devices. 20466c8d8eccSSepherosa Ziehau * 20476c8d8eccSSepherosa Ziehau * | F0 Cu | F0 Sr | F1 Cu | F1 Sr | 20486c8d8eccSSepherosa Ziehau * ---------+-------+-------+-------+-------+ 20496c8d8eccSSepherosa Ziehau * BCM57XX | 1 | X | X | X | 20506c8d8eccSSepherosa Ziehau * BCM5704 | 1 | X | 1 | X | 20516c8d8eccSSepherosa Ziehau * BCM5717 | 1 | 8 | 2 | 9 | 20526c8d8eccSSepherosa Ziehau * BCM5719 | 1 | 8 | 2 | 9 | 20536c8d8eccSSepherosa Ziehau * BCM5720 | 1 | 8 | 2 | 9 | 20546c8d8eccSSepherosa Ziehau * 20556c8d8eccSSepherosa Ziehau * Other addresses may respond but they are not 20566c8d8eccSSepherosa Ziehau * IEEE compliant PHYs and should be ignored. 20576c8d8eccSSepherosa Ziehau */ 205880969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 20596c8d8eccSSepherosa Ziehau int f; 20606c8d8eccSSepherosa Ziehau 20616c8d8eccSSepherosa Ziehau f = pci_get_function(dev); 20626c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_A0) { 20636c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_SGDIG_STS) & 20646c8d8eccSSepherosa Ziehau BGE_SGDIGSTS_IS_SERDES) 20656c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 20666c8d8eccSSepherosa Ziehau else 20676c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 20686c8d8eccSSepherosa Ziehau } else { 20696c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_CPMU_PHY_STRAP) & 20706c8d8eccSSepherosa Ziehau BGE_CPMU_PHY_STRAP_IS_SERDES) 20716c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 20726c8d8eccSSepherosa Ziehau else 20736c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 20746c8d8eccSSepherosa Ziehau } 20756c8d8eccSSepherosa Ziehau } 20766c8d8eccSSepherosa Ziehau 20776c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 20786c8d8eccSSepherosa Ziehau ifmedia_init(&sc->bnx_ifmedia, IFM_IMASK, 20796c8d8eccSSepherosa Ziehau bnx_ifmedia_upd, bnx_ifmedia_sts); 20806c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL); 20816c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, 20826c8d8eccSSepherosa Ziehau IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL); 20836c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 20846c8d8eccSSepherosa Ziehau ifmedia_set(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO); 20856c8d8eccSSepherosa Ziehau sc->bnx_ifmedia.ifm_media = sc->bnx_ifmedia.ifm_cur->ifm_media; 20866c8d8eccSSepherosa Ziehau } else { 20876c8d8eccSSepherosa Ziehau struct mii_probe_args mii_args; 20886c8d8eccSSepherosa Ziehau 20896c8d8eccSSepherosa Ziehau mii_probe_args_init(&mii_args, bnx_ifmedia_upd, bnx_ifmedia_sts); 20906c8d8eccSSepherosa Ziehau mii_args.mii_probemask = 1 << sc->bnx_phyno; 20916c8d8eccSSepherosa Ziehau mii_args.mii_capmask = capmask; 20926c8d8eccSSepherosa Ziehau mii_args.mii_privtag = MII_PRIVTAG_BRGPHY; 20936c8d8eccSSepherosa Ziehau mii_args.mii_priv = mii_priv; 20946c8d8eccSSepherosa Ziehau 20956c8d8eccSSepherosa Ziehau error = mii_probe(dev, &sc->bnx_miibus, &mii_args); 20966c8d8eccSSepherosa Ziehau if (error) { 20976c8d8eccSSepherosa Ziehau device_printf(dev, "MII without any PHY!\n"); 20986c8d8eccSSepherosa Ziehau goto fail; 20996c8d8eccSSepherosa Ziehau } 21006c8d8eccSSepherosa Ziehau } 21016c8d8eccSSepherosa Ziehau 21026c8d8eccSSepherosa Ziehau /* 21036c8d8eccSSepherosa Ziehau * Create sysctl nodes. 21046c8d8eccSSepherosa Ziehau */ 21056c8d8eccSSepherosa Ziehau sysctl_ctx_init(&sc->bnx_sysctl_ctx); 21066c8d8eccSSepherosa Ziehau sc->bnx_sysctl_tree = SYSCTL_ADD_NODE(&sc->bnx_sysctl_ctx, 21076c8d8eccSSepherosa Ziehau SYSCTL_STATIC_CHILDREN(_hw), 21086c8d8eccSSepherosa Ziehau OID_AUTO, 21096c8d8eccSSepherosa Ziehau device_get_nameunit(dev), 21106c8d8eccSSepherosa Ziehau CTLFLAG_RD, 0, ""); 21116c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree == NULL) { 21126c8d8eccSSepherosa Ziehau device_printf(dev, "can't add sysctl node\n"); 21136c8d8eccSSepherosa Ziehau error = ENXIO; 21146c8d8eccSSepherosa Ziehau goto fail; 21156c8d8eccSSepherosa Ziehau } 21166c8d8eccSSepherosa Ziehau 21176c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21186c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21196c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_ticks", 21206c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21216c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_ticks, "I", 21226c8d8eccSSepherosa Ziehau "Receive coalescing ticks (usec)."); 21236c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21246c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21256c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_ticks", 21266c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21276c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_ticks, "I", 21286c8d8eccSSepherosa Ziehau "Transmit coalescing ticks (usec)."); 21296c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21306c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21316c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_bds", 21326c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21336c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds, "I", 21346c8d8eccSSepherosa Ziehau "Receive max coalesced BD count."); 21356c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21366c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21376c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_bds", 21386c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21396c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds, "I", 21406c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count."); 21416c8d8eccSSepherosa Ziehau /* 21426c8d8eccSSepherosa Ziehau * A common design characteristic for many Broadcom 21436c8d8eccSSepherosa Ziehau * client controllers is that they only support a 21446c8d8eccSSepherosa Ziehau * single outstanding DMA read operation on the PCIe 21456c8d8eccSSepherosa Ziehau * bus. This means that it will take twice as long to 21466c8d8eccSSepherosa Ziehau * fetch a TX frame that is split into header and 21476c8d8eccSSepherosa Ziehau * payload buffers as it does to fetch a single, 21486c8d8eccSSepherosa Ziehau * contiguous TX frame (2 reads vs. 1 read). For these 21496c8d8eccSSepherosa Ziehau * controllers, coalescing buffers to reduce the number 21506c8d8eccSSepherosa Ziehau * of memory reads is effective way to get maximum 21516c8d8eccSSepherosa Ziehau * performance(about 940Mbps). Without collapsing TX 21526c8d8eccSSepherosa Ziehau * buffers the maximum TCP bulk transfer performance 21536c8d8eccSSepherosa Ziehau * is about 850Mbps. However forcing coalescing mbufs 21546c8d8eccSSepherosa Ziehau * consumes a lot of CPU cycles, so leave it off by 21556c8d8eccSSepherosa Ziehau * default. 21566c8d8eccSSepherosa Ziehau */ 21576c8d8eccSSepherosa Ziehau SYSCTL_ADD_INT(&sc->bnx_sysctl_ctx, 21586c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 21596c8d8eccSSepherosa Ziehau "force_defrag", CTLFLAG_RW, &sc->bnx_force_defrag, 0, 21606c8d8eccSSepherosa Ziehau "Force defragment on TX path"); 21616c8d8eccSSepherosa Ziehau 2162c9b7f592SSepherosa Ziehau SYSCTL_ADD_INT(&sc->bnx_sysctl_ctx, 2163c9b7f592SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2164c9b7f592SSepherosa Ziehau "tx_wreg", CTLFLAG_RW, &sc->bnx_tx_wreg, 0, 2165c9b7f592SSepherosa Ziehau "# of segments before writing to hardware register"); 2166c9b7f592SSepherosa Ziehau 21676c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21686c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 21696c8d8eccSSepherosa Ziehau "rx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 21706c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds_int, "I", 21716c8d8eccSSepherosa Ziehau "Receive max coalesced BD count during interrupt."); 21726c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21736c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 21746c8d8eccSSepherosa Ziehau "tx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 21756c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds_int, "I", 21766c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count during interrupt."); 21776c8d8eccSSepherosa Ziehau 217866deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 217966deb1c1SSepherosa Ziehau for (i = 0; i < BNX_TSO_NSTATS; ++i) { 218066deb1c1SSepherosa Ziehau ksnprintf(desc, sizeof(desc), "tso%d", i + 1); 218166deb1c1SSepherosa Ziehau SYSCTL_ADD_ULONG(&sc->bnx_sysctl_ctx, 218266deb1c1SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 218366deb1c1SSepherosa Ziehau desc, CTLFLAG_RW, &sc->bnx_tsosegs[i], ""); 218466deb1c1SSepherosa Ziehau } 218566deb1c1SSepherosa Ziehau #endif 218666deb1c1SSepherosa Ziehau 21876c8d8eccSSepherosa Ziehau /* 21886c8d8eccSSepherosa Ziehau * Call MI attach routine. 21896c8d8eccSSepherosa Ziehau */ 21906c8d8eccSSepherosa Ziehau ether_ifattach(ifp, ether_addr, NULL); 21916c8d8eccSSepherosa Ziehau 2192b5de76b1SSepherosa Ziehau #ifdef IFPOLL_ENABLE 2193b5de76b1SSepherosa Ziehau ifpoll_compat_setup(&sc->bnx_npoll, 2194b5de76b1SSepherosa Ziehau &sc->bnx_sysctl_ctx, sc->bnx_sysctl_tree, 2195b5de76b1SSepherosa Ziehau device_get_unit(dev), ifp->if_serializer); 2196b5de76b1SSepherosa Ziehau #endif 2197b5de76b1SSepherosa Ziehau 21986c8d8eccSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 21996c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 22006c8d8eccSSepherosa Ziehau intr_func = bnx_msi_oneshot; 22016c8d8eccSSepherosa Ziehau if (bootverbose) 22026c8d8eccSSepherosa Ziehau device_printf(dev, "oneshot MSI\n"); 22036c8d8eccSSepherosa Ziehau } else { 22046c8d8eccSSepherosa Ziehau intr_func = bnx_msi; 22056c8d8eccSSepherosa Ziehau } 22066c8d8eccSSepherosa Ziehau } else { 22076c8d8eccSSepherosa Ziehau intr_func = bnx_intr_legacy; 22086c8d8eccSSepherosa Ziehau } 22096c8d8eccSSepherosa Ziehau error = bus_setup_intr(dev, sc->bnx_irq, INTR_MPSAFE, intr_func, sc, 22106c8d8eccSSepherosa Ziehau &sc->bnx_intrhand, ifp->if_serializer); 22116c8d8eccSSepherosa Ziehau if (error) { 22126c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 22136c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't set up irq\n"); 22146c8d8eccSSepherosa Ziehau goto fail; 22156c8d8eccSSepherosa Ziehau } 22166c8d8eccSSepherosa Ziehau 22176c8d8eccSSepherosa Ziehau ifp->if_cpuid = rman_get_cpuid(sc->bnx_irq); 22186c8d8eccSSepherosa Ziehau KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus); 22196c8d8eccSSepherosa Ziehau 22208ca0f604SSepherosa Ziehau sc->bnx_stat_cpuid = ifp->if_cpuid; 2221df9ccc98SSepherosa Ziehau sc->bnx_intr_cpuid = ifp->if_cpuid; 22228ca0f604SSepherosa Ziehau 22236c8d8eccSSepherosa Ziehau return(0); 22246c8d8eccSSepherosa Ziehau fail: 22256c8d8eccSSepherosa Ziehau bnx_detach(dev); 22266c8d8eccSSepherosa Ziehau return(error); 22276c8d8eccSSepherosa Ziehau } 22286c8d8eccSSepherosa Ziehau 22296c8d8eccSSepherosa Ziehau static int 22306c8d8eccSSepherosa Ziehau bnx_detach(device_t dev) 22316c8d8eccSSepherosa Ziehau { 22326c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 22336c8d8eccSSepherosa Ziehau 22346c8d8eccSSepherosa Ziehau if (device_is_attached(dev)) { 22356c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 22366c8d8eccSSepherosa Ziehau 22376c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 22386c8d8eccSSepherosa Ziehau bnx_stop(sc); 22396c8d8eccSSepherosa Ziehau bnx_reset(sc); 22406c8d8eccSSepherosa Ziehau bus_teardown_intr(dev, sc->bnx_irq, sc->bnx_intrhand); 22416c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 22426c8d8eccSSepherosa Ziehau 22436c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 22446c8d8eccSSepherosa Ziehau } 22456c8d8eccSSepherosa Ziehau 22466c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 22476c8d8eccSSepherosa Ziehau ifmedia_removeall(&sc->bnx_ifmedia); 22486c8d8eccSSepherosa Ziehau if (sc->bnx_miibus) 22496c8d8eccSSepherosa Ziehau device_delete_child(dev, sc->bnx_miibus); 22506c8d8eccSSepherosa Ziehau bus_generic_detach(dev); 22516c8d8eccSSepherosa Ziehau 22526c8d8eccSSepherosa Ziehau if (sc->bnx_irq != NULL) { 22536c8d8eccSSepherosa Ziehau bus_release_resource(dev, SYS_RES_IRQ, sc->bnx_irq_rid, 22546c8d8eccSSepherosa Ziehau sc->bnx_irq); 22556c8d8eccSSepherosa Ziehau } 22566c8d8eccSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) 22576c8d8eccSSepherosa Ziehau pci_release_msi(dev); 22586c8d8eccSSepherosa Ziehau 22596c8d8eccSSepherosa Ziehau if (sc->bnx_res != NULL) { 22606c8d8eccSSepherosa Ziehau bus_release_resource(dev, SYS_RES_MEMORY, 22616c8d8eccSSepherosa Ziehau BGE_PCI_BAR0, sc->bnx_res); 22626c8d8eccSSepherosa Ziehau } 22636c8d8eccSSepherosa Ziehau 22646c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree != NULL) 22656c8d8eccSSepherosa Ziehau sysctl_ctx_free(&sc->bnx_sysctl_ctx); 22666c8d8eccSSepherosa Ziehau 22676c8d8eccSSepherosa Ziehau bnx_dma_free(sc); 22686c8d8eccSSepherosa Ziehau 22696c8d8eccSSepherosa Ziehau return 0; 22706c8d8eccSSepherosa Ziehau } 22716c8d8eccSSepherosa Ziehau 22726c8d8eccSSepherosa Ziehau static void 22736c8d8eccSSepherosa Ziehau bnx_reset(struct bnx_softc *sc) 22746c8d8eccSSepherosa Ziehau { 22756c8d8eccSSepherosa Ziehau device_t dev; 22766c8d8eccSSepherosa Ziehau uint32_t cachesize, command, pcistate, reset; 22776c8d8eccSSepherosa Ziehau void (*write_op)(struct bnx_softc *, uint32_t, uint32_t); 22786c8d8eccSSepherosa Ziehau int i, val = 0; 22796c8d8eccSSepherosa Ziehau uint16_t devctl; 22806c8d8eccSSepherosa Ziehau 22816c8d8eccSSepherosa Ziehau dev = sc->bnx_dev; 22826c8d8eccSSepherosa Ziehau 22836c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5906) 22846c8d8eccSSepherosa Ziehau write_op = bnx_writemem_direct; 22856c8d8eccSSepherosa Ziehau else 22866c8d8eccSSepherosa Ziehau write_op = bnx_writereg_ind; 22876c8d8eccSSepherosa Ziehau 22886c8d8eccSSepherosa Ziehau /* Save some important PCI state. */ 22896c8d8eccSSepherosa Ziehau cachesize = pci_read_config(dev, BGE_PCI_CACHESZ, 4); 22906c8d8eccSSepherosa Ziehau command = pci_read_config(dev, BGE_PCI_CMD, 4); 22916c8d8eccSSepherosa Ziehau pcistate = pci_read_config(dev, BGE_PCI_PCISTATE, 4); 22926c8d8eccSSepherosa Ziehau 22936c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 22946c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 22956c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 22966c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 22976c8d8eccSSepherosa Ziehau 22986c8d8eccSSepherosa Ziehau /* Disable fastboot on controllers that support it. */ 22996c8d8eccSSepherosa Ziehau if (bootverbose) 23006c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "Disabling fastboot\n"); 23016c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0x0); 23026c8d8eccSSepherosa Ziehau 23036c8d8eccSSepherosa Ziehau /* 23046c8d8eccSSepherosa Ziehau * Write the magic number to SRAM at offset 0xB50. 23056c8d8eccSSepherosa Ziehau * When firmware finishes its initialization it will 23066c8d8eccSSepherosa Ziehau * write ~BGE_MAGIC_NUMBER to the same location. 23076c8d8eccSSepherosa Ziehau */ 23086c8d8eccSSepherosa Ziehau bnx_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); 23096c8d8eccSSepherosa Ziehau 23106c8d8eccSSepherosa Ziehau reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1); 23116c8d8eccSSepherosa Ziehau 23126c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 23136c8d8eccSSepherosa Ziehau /* Force PCI-E 1.0a mode */ 23143730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc) && 23156c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_PCIE_PHY_TSTCTL) == 23166c8d8eccSSepherosa Ziehau (BGE_PCIE_PHY_TSTCTL_PSCRAM | 23176c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PCIE10)) { 23186c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PHY_TSTCTL, 23196c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PSCRAM); 23206c8d8eccSSepherosa Ziehau } 23216c8d8eccSSepherosa Ziehau if (sc->bnx_chipid != BGE_CHIPID_BCM5750_A0) { 23226c8d8eccSSepherosa Ziehau /* Prevent PCIE link training during global reset */ 23236c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, (1<<29)); 23246c8d8eccSSepherosa Ziehau reset |= (1<<29); 23256c8d8eccSSepherosa Ziehau } 23266c8d8eccSSepherosa Ziehau 23276c8d8eccSSepherosa Ziehau /* 23286c8d8eccSSepherosa Ziehau * Set GPHY Power Down Override to leave GPHY 23296c8d8eccSSepherosa Ziehau * powered up in D0 uninitialized. 23306c8d8eccSSepherosa Ziehau */ 23316c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) 23326c8d8eccSSepherosa Ziehau reset |= BGE_MISCCFG_GPHY_PD_OVERRIDE; 23336c8d8eccSSepherosa Ziehau 23346c8d8eccSSepherosa Ziehau /* Issue global reset */ 23356c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, reset); 23366c8d8eccSSepherosa Ziehau 23376c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) { 23386c8d8eccSSepherosa Ziehau uint32_t status, ctrl; 23396c8d8eccSSepherosa Ziehau 23406c8d8eccSSepherosa Ziehau status = CSR_READ_4(sc, BGE_VCPU_STATUS); 23416c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_VCPU_STATUS, 23426c8d8eccSSepherosa Ziehau status | BGE_VCPU_STATUS_DRV_RESET); 23436c8d8eccSSepherosa Ziehau ctrl = CSR_READ_4(sc, BGE_VCPU_EXT_CTRL); 23446c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_VCPU_EXT_CTRL, 23456c8d8eccSSepherosa Ziehau ctrl & ~BGE_VCPU_EXT_CTRL_HALT_CPU); 23466c8d8eccSSepherosa Ziehau } 23476c8d8eccSSepherosa Ziehau 23486c8d8eccSSepherosa Ziehau DELAY(1000); 23496c8d8eccSSepherosa Ziehau 23506c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 23516c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5750_A0) { 23526c8d8eccSSepherosa Ziehau uint32_t v; 23536c8d8eccSSepherosa Ziehau 23546c8d8eccSSepherosa Ziehau DELAY(500000); /* wait for link training to complete */ 23556c8d8eccSSepherosa Ziehau v = pci_read_config(dev, 0xc4, 4); 23566c8d8eccSSepherosa Ziehau pci_write_config(dev, 0xc4, v | (1<<15), 4); 23576c8d8eccSSepherosa Ziehau } 23586c8d8eccSSepherosa Ziehau 23596c8d8eccSSepherosa Ziehau devctl = pci_read_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 2); 23606c8d8eccSSepherosa Ziehau 23616c8d8eccSSepherosa Ziehau /* Disable no snoop and disable relaxed ordering. */ 23626c8d8eccSSepherosa Ziehau devctl &= ~(PCIEM_DEVCTL_RELAX_ORDER | PCIEM_DEVCTL_NOSNOOP); 23636c8d8eccSSepherosa Ziehau 23646c8d8eccSSepherosa Ziehau /* Old PCI-E chips only support 128 bytes Max PayLoad Size. */ 23656c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) { 23666c8d8eccSSepherosa Ziehau devctl &= ~PCIEM_DEVCTL_MAX_PAYLOAD_MASK; 23676c8d8eccSSepherosa Ziehau devctl |= PCIEM_DEVCTL_MAX_PAYLOAD_128; 23686c8d8eccSSepherosa Ziehau } 23696c8d8eccSSepherosa Ziehau 23706c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 23716c8d8eccSSepherosa Ziehau devctl, 2); 23726c8d8eccSSepherosa Ziehau 23736c8d8eccSSepherosa Ziehau /* Clear error status. */ 23746c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVSTS, 23756c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_CORR_ERR | 23766c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_NFATAL_ERR | 23776c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_FATAL_ERR | 23786c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_UNSUPP_REQ, 2); 23796c8d8eccSSepherosa Ziehau 23806c8d8eccSSepherosa Ziehau /* Reset some of the PCI state that got zapped by reset */ 23816c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 23826c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 23836c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 23846c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 23856c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CACHESZ, cachesize, 4); 23866c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CMD, command, 4); 23876c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, (65 << 1)); 23886c8d8eccSSepherosa Ziehau 23896c8d8eccSSepherosa Ziehau /* Enable memory arbiter */ 23906c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); 23916c8d8eccSSepherosa Ziehau 23926c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) { 23936c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 23946c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_VCPU_STATUS); 23956c8d8eccSSepherosa Ziehau if (val & BGE_VCPU_STATUS_INIT_DONE) 23966c8d8eccSSepherosa Ziehau break; 23976c8d8eccSSepherosa Ziehau DELAY(100); 23986c8d8eccSSepherosa Ziehau } 23996c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 24006c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "reset timed out\n"); 24016c8d8eccSSepherosa Ziehau return; 24026c8d8eccSSepherosa Ziehau } 24036c8d8eccSSepherosa Ziehau } else { 24046c8d8eccSSepherosa Ziehau /* 24056c8d8eccSSepherosa Ziehau * Poll until we see the 1's complement of the magic number. 24066c8d8eccSSepherosa Ziehau * This indicates that the firmware initialization 24076c8d8eccSSepherosa Ziehau * is complete. 24086c8d8eccSSepherosa Ziehau */ 24096c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_FIRMWARE_TIMEOUT; i++) { 24106c8d8eccSSepherosa Ziehau val = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM); 24116c8d8eccSSepherosa Ziehau if (val == ~BGE_MAGIC_NUMBER) 24126c8d8eccSSepherosa Ziehau break; 24136c8d8eccSSepherosa Ziehau DELAY(10); 24146c8d8eccSSepherosa Ziehau } 24156c8d8eccSSepherosa Ziehau if (i == BNX_FIRMWARE_TIMEOUT) { 24166c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "firmware handshake " 24176c8d8eccSSepherosa Ziehau "timed out, found 0x%08x\n", val); 24186c8d8eccSSepherosa Ziehau } 24196c8d8eccSSepherosa Ziehau 24206c8d8eccSSepherosa Ziehau /* BCM57765 A0 needs additional time before accessing. */ 24216c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 24226c8d8eccSSepherosa Ziehau DELAY(10 * 1000); 24236c8d8eccSSepherosa Ziehau } 24246c8d8eccSSepherosa Ziehau 24256c8d8eccSSepherosa Ziehau /* 24266c8d8eccSSepherosa Ziehau * XXX Wait for the value of the PCISTATE register to 24276c8d8eccSSepherosa Ziehau * return to its original pre-reset state. This is a 24286c8d8eccSSepherosa Ziehau * fairly good indicator of reset completion. If we don't 24296c8d8eccSSepherosa Ziehau * wait for the reset to fully complete, trying to read 24306c8d8eccSSepherosa Ziehau * from the device's non-PCI registers may yield garbage 24316c8d8eccSSepherosa Ziehau * results. 24326c8d8eccSSepherosa Ziehau */ 24336c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 24346c8d8eccSSepherosa Ziehau if (pci_read_config(dev, BGE_PCI_PCISTATE, 4) == pcistate) 24356c8d8eccSSepherosa Ziehau break; 24366c8d8eccSSepherosa Ziehau DELAY(10); 24376c8d8eccSSepherosa Ziehau } 24386c8d8eccSSepherosa Ziehau 24396c8d8eccSSepherosa Ziehau /* Fix up byte swapping */ 24406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, bnx_dma_swap_options(sc)); 24416c8d8eccSSepherosa Ziehau 24426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 24436c8d8eccSSepherosa Ziehau 24446c8d8eccSSepherosa Ziehau /* 24456c8d8eccSSepherosa Ziehau * The 5704 in TBI mode apparently needs some special 24466c8d8eccSSepherosa Ziehau * adjustment to insure the SERDES drive level is set 24476c8d8eccSSepherosa Ziehau * to 1.2V. 24486c8d8eccSSepherosa Ziehau */ 24496c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704 && 24506c8d8eccSSepherosa Ziehau (sc->bnx_flags & BNX_FLAG_TBI)) { 24516c8d8eccSSepherosa Ziehau uint32_t serdescfg; 24526c8d8eccSSepherosa Ziehau 24536c8d8eccSSepherosa Ziehau serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG); 24546c8d8eccSSepherosa Ziehau serdescfg = (serdescfg & ~0xFFF) | 0x880; 24556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg); 24566c8d8eccSSepherosa Ziehau } 24576c8d8eccSSepherosa Ziehau 24587892075dSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 24597892075dSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 24607892075dSSepherosa Ziehau DELAY(80); 24617892075dSSepherosa Ziehau 24626c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 24633730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc)) { 24646c8d8eccSSepherosa Ziehau uint32_t v; 24656c8d8eccSSepherosa Ziehau 24666c8d8eccSSepherosa Ziehau /* Enable Data FIFO protection. */ 2467f1f34fc4SSepherosa Ziehau v = CSR_READ_4(sc, BGE_PCIE_TLDLPL_PORT); 2468f1f34fc4SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_TLDLPL_PORT, v | (1 << 25)); 24696c8d8eccSSepherosa Ziehau } 24706c8d8eccSSepherosa Ziehau 24716c8d8eccSSepherosa Ziehau DELAY(10000); 24726c8d8eccSSepherosa Ziehau 24736c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 24746c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE, 24756c8d8eccSSepherosa Ziehau CPMU_CLCK_ORIDE_MAC_ORIDE_EN); 24766c8d8eccSSepherosa Ziehau } 24776c8d8eccSSepherosa Ziehau } 24786c8d8eccSSepherosa Ziehau 24796c8d8eccSSepherosa Ziehau /* 24806c8d8eccSSepherosa Ziehau * Frame reception handling. This is called if there's a frame 24816c8d8eccSSepherosa Ziehau * on the receive return list. 24826c8d8eccSSepherosa Ziehau * 24836c8d8eccSSepherosa Ziehau * Note: we have to be able to handle two possibilities here: 24846c8d8eccSSepherosa Ziehau * 1) the frame is from the jumbo recieve ring 24856c8d8eccSSepherosa Ziehau * 2) the frame is from the standard receive ring 24866c8d8eccSSepherosa Ziehau */ 24876c8d8eccSSepherosa Ziehau 24886c8d8eccSSepherosa Ziehau static void 248997381780SSepherosa Ziehau bnx_rxeof(struct bnx_softc *sc, uint16_t rx_prod, int count) 24906c8d8eccSSepherosa Ziehau { 24916c8d8eccSSepherosa Ziehau struct ifnet *ifp; 24926c8d8eccSSepherosa Ziehau int stdcnt = 0, jumbocnt = 0; 24936c8d8eccSSepherosa Ziehau 24946c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 24956c8d8eccSSepherosa Ziehau 249697381780SSepherosa Ziehau while (sc->bnx_rx_saved_considx != rx_prod && count != 0) { 24976c8d8eccSSepherosa Ziehau struct bge_rx_bd *cur_rx; 24986c8d8eccSSepherosa Ziehau uint32_t rxidx; 24996c8d8eccSSepherosa Ziehau struct mbuf *m = NULL; 25006c8d8eccSSepherosa Ziehau uint16_t vlan_tag = 0; 25016c8d8eccSSepherosa Ziehau int have_tag = 0; 25026c8d8eccSSepherosa Ziehau 250397381780SSepherosa Ziehau --count; 250497381780SSepherosa Ziehau 25056c8d8eccSSepherosa Ziehau cur_rx = 25066c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_return_ring[sc->bnx_rx_saved_considx]; 25076c8d8eccSSepherosa Ziehau 25086c8d8eccSSepherosa Ziehau rxidx = cur_rx->bge_idx; 25096c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_rx_saved_considx, sc->bnx_return_ring_cnt); 25106c8d8eccSSepherosa Ziehau 25116c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) { 25126c8d8eccSSepherosa Ziehau have_tag = 1; 25136c8d8eccSSepherosa Ziehau vlan_tag = cur_rx->bge_vlan_tag; 25146c8d8eccSSepherosa Ziehau } 25156c8d8eccSSepherosa Ziehau 25166c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_JUMBO_RING) { 25176c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_jumbo, BGE_JUMBO_RX_RING_CNT); 25186c8d8eccSSepherosa Ziehau jumbocnt++; 25196c8d8eccSSepherosa Ziehau 25206c8d8eccSSepherosa Ziehau if (rxidx != sc->bnx_jumbo) { 25216c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25226c8d8eccSSepherosa Ziehau if_printf(ifp, "sw jumbo index(%d) " 25236c8d8eccSSepherosa Ziehau "and hw jumbo index(%d) mismatch, drop!\n", 25246c8d8eccSSepherosa Ziehau sc->bnx_jumbo, rxidx); 25256c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, rxidx); 25266c8d8eccSSepherosa Ziehau continue; 25276c8d8eccSSepherosa Ziehau } 25286c8d8eccSSepherosa Ziehau 25296c8d8eccSSepherosa Ziehau m = sc->bnx_cdata.bnx_rx_jumbo_chain[rxidx].bnx_mbuf; 25306c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 25316c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25326c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 25336c8d8eccSSepherosa Ziehau continue; 25346c8d8eccSSepherosa Ziehau } 25356c8d8eccSSepherosa Ziehau if (bnx_newbuf_jumbo(sc, sc->bnx_jumbo, 0)) { 25366c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25376c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo); 25386c8d8eccSSepherosa Ziehau continue; 25396c8d8eccSSepherosa Ziehau } 25406c8d8eccSSepherosa Ziehau } else { 25416c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_std, BGE_STD_RX_RING_CNT); 25426c8d8eccSSepherosa Ziehau stdcnt++; 25436c8d8eccSSepherosa Ziehau 25446c8d8eccSSepherosa Ziehau if (rxidx != sc->bnx_std) { 25456c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25466c8d8eccSSepherosa Ziehau if_printf(ifp, "sw std index(%d) " 25476c8d8eccSSepherosa Ziehau "and hw std index(%d) mismatch, drop!\n", 25486c8d8eccSSepherosa Ziehau sc->bnx_std, rxidx); 25496c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_std(sc, rxidx); 25506c8d8eccSSepherosa Ziehau continue; 25516c8d8eccSSepherosa Ziehau } 25526c8d8eccSSepherosa Ziehau 25536c8d8eccSSepherosa Ziehau m = sc->bnx_cdata.bnx_rx_std_chain[rxidx].bnx_mbuf; 25546c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 25556c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25566c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_std(sc, sc->bnx_std); 25576c8d8eccSSepherosa Ziehau continue; 25586c8d8eccSSepherosa Ziehau } 25596c8d8eccSSepherosa Ziehau if (bnx_newbuf_std(sc, sc->bnx_std, 0)) { 25606c8d8eccSSepherosa Ziehau ifp->if_ierrors++; 25616c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_std(sc, sc->bnx_std); 25626c8d8eccSSepherosa Ziehau continue; 25636c8d8eccSSepherosa Ziehau } 25646c8d8eccSSepherosa Ziehau } 25656c8d8eccSSepherosa Ziehau 25666c8d8eccSSepherosa Ziehau ifp->if_ipackets++; 25676c8d8eccSSepherosa Ziehau m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; 25686c8d8eccSSepherosa Ziehau m->m_pkthdr.rcvif = ifp; 25696c8d8eccSSepherosa Ziehau 25706c8d8eccSSepherosa Ziehau if ((ifp->if_capenable & IFCAP_RXCSUM) && 25716c8d8eccSSepherosa Ziehau (cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) { 25726c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) { 25736c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; 25746c8d8eccSSepherosa Ziehau if ((cur_rx->bge_error_flag & 25756c8d8eccSSepherosa Ziehau BGE_RXERRFLAG_IP_CSUM_NOK) == 0) 25766c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 25776c8d8eccSSepherosa Ziehau } 25786c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) { 25796c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_data = 25806c8d8eccSSepherosa Ziehau cur_rx->bge_tcp_udp_csum; 25816c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | 25826c8d8eccSSepherosa Ziehau CSUM_PSEUDO_HDR; 25836c8d8eccSSepherosa Ziehau } 25846c8d8eccSSepherosa Ziehau } 25856c8d8eccSSepherosa Ziehau 25866c8d8eccSSepherosa Ziehau /* 25876c8d8eccSSepherosa Ziehau * If we received a packet with a vlan tag, pass it 25886c8d8eccSSepherosa Ziehau * to vlan_input() instead of ether_input(). 25896c8d8eccSSepherosa Ziehau */ 25906c8d8eccSSepherosa Ziehau if (have_tag) { 25916c8d8eccSSepherosa Ziehau m->m_flags |= M_VLANTAG; 25926c8d8eccSSepherosa Ziehau m->m_pkthdr.ether_vlantag = vlan_tag; 25936c8d8eccSSepherosa Ziehau } 25946c8d8eccSSepherosa Ziehau ifp->if_input(ifp, m); 25956c8d8eccSSepherosa Ziehau } 25966c8d8eccSSepherosa Ziehau 25976c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO, sc->bnx_rx_saved_considx); 25986c8d8eccSSepherosa Ziehau if (stdcnt) 25996c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bnx_std); 26006c8d8eccSSepherosa Ziehau if (jumbocnt) 26016c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 26026c8d8eccSSepherosa Ziehau } 26036c8d8eccSSepherosa Ziehau 26046c8d8eccSSepherosa Ziehau static void 26056c8d8eccSSepherosa Ziehau bnx_txeof(struct bnx_softc *sc, uint16_t tx_cons) 26066c8d8eccSSepherosa Ziehau { 26076c8d8eccSSepherosa Ziehau struct ifnet *ifp; 26086c8d8eccSSepherosa Ziehau 26096c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 26106c8d8eccSSepherosa Ziehau 26116c8d8eccSSepherosa Ziehau /* 26126c8d8eccSSepherosa Ziehau * Go through our tx ring and free mbufs for those 26136c8d8eccSSepherosa Ziehau * frames that have been sent. 26146c8d8eccSSepherosa Ziehau */ 26156c8d8eccSSepherosa Ziehau while (sc->bnx_tx_saved_considx != tx_cons) { 26166c8d8eccSSepherosa Ziehau uint32_t idx = 0; 26176c8d8eccSSepherosa Ziehau 26186c8d8eccSSepherosa Ziehau idx = sc->bnx_tx_saved_considx; 26196c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_tx_chain[idx] != NULL) { 26209a103adfSSepherosa Ziehau ifp->if_opackets++; 26216c8d8eccSSepherosa Ziehau bus_dmamap_unload(sc->bnx_cdata.bnx_tx_mtag, 26226c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[idx]); 26236c8d8eccSSepherosa Ziehau m_freem(sc->bnx_cdata.bnx_tx_chain[idx]); 26246c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_chain[idx] = NULL; 26256c8d8eccSSepherosa Ziehau } 26266c8d8eccSSepherosa Ziehau sc->bnx_txcnt--; 26276c8d8eccSSepherosa Ziehau BNX_INC(sc->bnx_tx_saved_considx, BGE_TX_RING_CNT); 26286c8d8eccSSepherosa Ziehau } 26296c8d8eccSSepherosa Ziehau 26309a103adfSSepherosa Ziehau if ((BGE_TX_RING_CNT - sc->bnx_txcnt) >= 26316c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) 2632*9ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 26336c8d8eccSSepherosa Ziehau 26346c8d8eccSSepherosa Ziehau if (sc->bnx_txcnt == 0) 26356c8d8eccSSepherosa Ziehau ifp->if_timer = 0; 26366c8d8eccSSepherosa Ziehau 26376c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 26386c8d8eccSSepherosa Ziehau if_devstart(ifp); 26396c8d8eccSSepherosa Ziehau } 26406c8d8eccSSepherosa Ziehau 264139a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 26426c8d8eccSSepherosa Ziehau 26436c8d8eccSSepherosa Ziehau static void 264439a8d43aSSepherosa Ziehau bnx_npoll(struct ifnet *ifp, struct ifpoll_info *info) 264539a8d43aSSepherosa Ziehau { 264639a8d43aSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 264739a8d43aSSepherosa Ziehau 264839a8d43aSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 264939a8d43aSSepherosa Ziehau 265039a8d43aSSepherosa Ziehau if (info != NULL) { 2651b5de76b1SSepherosa Ziehau int cpuid = sc->bnx_npoll.ifpc_cpuid; 265239a8d43aSSepherosa Ziehau 265339a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].poll_func = bnx_npoll_compat; 265439a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].arg = NULL; 265539a8d43aSSepherosa Ziehau info->ifpi_rx[cpuid].serializer = ifp->if_serializer; 265639a8d43aSSepherosa Ziehau 265739a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 265839a8d43aSSepherosa Ziehau bnx_disable_intr(sc); 265939a8d43aSSepherosa Ziehau ifp->if_npoll_cpuid = cpuid; 266039a8d43aSSepherosa Ziehau } else { 266139a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 266239a8d43aSSepherosa Ziehau bnx_enable_intr(sc); 266339a8d43aSSepherosa Ziehau ifp->if_npoll_cpuid = -1; 266439a8d43aSSepherosa Ziehau } 266539a8d43aSSepherosa Ziehau } 266639a8d43aSSepherosa Ziehau 266739a8d43aSSepherosa Ziehau static void 266897381780SSepherosa Ziehau bnx_npoll_compat(struct ifnet *ifp, void *arg __unused, int cycle) 26696c8d8eccSSepherosa Ziehau { 26706c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 26716c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 26726c8d8eccSSepherosa Ziehau uint16_t rx_prod, tx_cons; 26736c8d8eccSSepherosa Ziehau 267439a8d43aSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 267539a8d43aSSepherosa Ziehau 2676b5de76b1SSepherosa Ziehau if (sc->bnx_npoll.ifpc_stcount-- == 0) { 2677b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = sc->bnx_npoll.ifpc_stfrac; 26786c8d8eccSSepherosa Ziehau /* 26796c8d8eccSSepherosa Ziehau * Process link state changes. 26806c8d8eccSSepherosa Ziehau */ 26816c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 268239a8d43aSSepherosa Ziehau } 268339a8d43aSSepherosa Ziehau 26846c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 268539a8d43aSSepherosa Ziehau 26866c8d8eccSSepherosa Ziehau /* 268739a8d43aSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 268839a8d43aSSepherosa Ziehau * before rx_prod and tx_cons. 26896c8d8eccSSepherosa Ziehau */ 26906c8d8eccSSepherosa Ziehau cpu_lfence(); 26916c8d8eccSSepherosa Ziehau 26926c8d8eccSSepherosa Ziehau rx_prod = sblk->bge_idx[0].bge_rx_prod_idx; 26936c8d8eccSSepherosa Ziehau tx_cons = sblk->bge_idx[0].bge_tx_cons_idx; 269439a8d43aSSepherosa Ziehau 26956c8d8eccSSepherosa Ziehau if (sc->bnx_rx_saved_considx != rx_prod) 269697381780SSepherosa Ziehau bnx_rxeof(sc, rx_prod, cycle); 26976c8d8eccSSepherosa Ziehau 26986c8d8eccSSepherosa Ziehau if (sc->bnx_tx_saved_considx != tx_cons) 26996c8d8eccSSepherosa Ziehau bnx_txeof(sc, tx_cons); 2700dca60051SSepherosa Ziehau 2701dca60051SSepherosa Ziehau if (sc->bnx_coal_chg) 2702dca60051SSepherosa Ziehau bnx_coal_change(sc); 27036c8d8eccSSepherosa Ziehau } 27046c8d8eccSSepherosa Ziehau 270539a8d43aSSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 27066c8d8eccSSepherosa Ziehau 27076c8d8eccSSepherosa Ziehau static void 27086c8d8eccSSepherosa Ziehau bnx_intr_legacy(void *xsc) 27096c8d8eccSSepherosa Ziehau { 27106c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 27116c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 27126c8d8eccSSepherosa Ziehau 27136c8d8eccSSepherosa Ziehau if (sc->bnx_status_tag == sblk->bge_status_tag) { 27146c8d8eccSSepherosa Ziehau uint32_t val; 27156c8d8eccSSepherosa Ziehau 27166c8d8eccSSepherosa Ziehau val = pci_read_config(sc->bnx_dev, BGE_PCI_PCISTATE, 4); 27176c8d8eccSSepherosa Ziehau if (val & BGE_PCISTAT_INTR_NOTACT) 27186c8d8eccSSepherosa Ziehau return; 27196c8d8eccSSepherosa Ziehau } 27206c8d8eccSSepherosa Ziehau 27216c8d8eccSSepherosa Ziehau /* 27226c8d8eccSSepherosa Ziehau * NOTE: 27236c8d8eccSSepherosa Ziehau * Interrupt will have to be disabled if tagged status 27246c8d8eccSSepherosa Ziehau * is used, else interrupt will always be asserted on 27256c8d8eccSSepherosa Ziehau * certain chips (at least on BCM5750 AX/BX). 27266c8d8eccSSepherosa Ziehau */ 27276c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 27286c8d8eccSSepherosa Ziehau 27296c8d8eccSSepherosa Ziehau bnx_intr(sc); 27306c8d8eccSSepherosa Ziehau } 27316c8d8eccSSepherosa Ziehau 27326c8d8eccSSepherosa Ziehau static void 27336c8d8eccSSepherosa Ziehau bnx_msi(void *xsc) 27346c8d8eccSSepherosa Ziehau { 27356c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 27366c8d8eccSSepherosa Ziehau 27376c8d8eccSSepherosa Ziehau /* Disable interrupt first */ 27386c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 27396c8d8eccSSepherosa Ziehau bnx_intr(sc); 27406c8d8eccSSepherosa Ziehau } 27416c8d8eccSSepherosa Ziehau 27426c8d8eccSSepherosa Ziehau static void 27436c8d8eccSSepherosa Ziehau bnx_msi_oneshot(void *xsc) 27446c8d8eccSSepherosa Ziehau { 27456c8d8eccSSepherosa Ziehau bnx_intr(xsc); 27466c8d8eccSSepherosa Ziehau } 27476c8d8eccSSepherosa Ziehau 27486c8d8eccSSepherosa Ziehau static void 27496c8d8eccSSepherosa Ziehau bnx_intr(struct bnx_softc *sc) 27506c8d8eccSSepherosa Ziehau { 27516c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 27526c8d8eccSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 27536c8d8eccSSepherosa Ziehau uint16_t rx_prod, tx_cons; 27546c8d8eccSSepherosa Ziehau uint32_t status; 27556c8d8eccSSepherosa Ziehau 27566c8d8eccSSepherosa Ziehau sc->bnx_status_tag = sblk->bge_status_tag; 27576c8d8eccSSepherosa Ziehau /* 27586c8d8eccSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 27596c8d8eccSSepherosa Ziehau * before rx_prod, tx_cons and status. 27606c8d8eccSSepherosa Ziehau */ 27616c8d8eccSSepherosa Ziehau cpu_lfence(); 27626c8d8eccSSepherosa Ziehau 27636c8d8eccSSepherosa Ziehau rx_prod = sblk->bge_idx[0].bge_rx_prod_idx; 27646c8d8eccSSepherosa Ziehau tx_cons = sblk->bge_idx[0].bge_tx_cons_idx; 27656c8d8eccSSepherosa Ziehau status = sblk->bge_status; 27666c8d8eccSSepherosa Ziehau 27676c8d8eccSSepherosa Ziehau if ((status & BGE_STATFLAG_LINKSTATE_CHANGED) || sc->bnx_link_evt) 27686c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 27696c8d8eccSSepherosa Ziehau 27706c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 27716c8d8eccSSepherosa Ziehau if (sc->bnx_rx_saved_considx != rx_prod) 277297381780SSepherosa Ziehau bnx_rxeof(sc, rx_prod, -1); 27736c8d8eccSSepherosa Ziehau 27746c8d8eccSSepherosa Ziehau if (sc->bnx_tx_saved_considx != tx_cons) 27756c8d8eccSSepherosa Ziehau bnx_txeof(sc, tx_cons); 27766c8d8eccSSepherosa Ziehau } 27776c8d8eccSSepherosa Ziehau 27786c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 27796c8d8eccSSepherosa Ziehau 27806c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg) 27816c8d8eccSSepherosa Ziehau bnx_coal_change(sc); 27826c8d8eccSSepherosa Ziehau } 27836c8d8eccSSepherosa Ziehau 27846c8d8eccSSepherosa Ziehau static void 27856c8d8eccSSepherosa Ziehau bnx_tick(void *xsc) 27866c8d8eccSSepherosa Ziehau { 27876c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 27886c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 27896c8d8eccSSepherosa Ziehau 27906c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 27916c8d8eccSSepherosa Ziehau 27928ca0f604SSepherosa Ziehau KKASSERT(mycpuid == sc->bnx_stat_cpuid); 27938ca0f604SSepherosa Ziehau 27946c8d8eccSSepherosa Ziehau bnx_stats_update_regs(sc); 27956c8d8eccSSepherosa Ziehau 27966c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 27976c8d8eccSSepherosa Ziehau /* 27986c8d8eccSSepherosa Ziehau * Since in TBI mode auto-polling can't be used we should poll 27996c8d8eccSSepherosa Ziehau * link status manually. Here we register pending link event 28006c8d8eccSSepherosa Ziehau * and trigger interrupt. 28016c8d8eccSSepherosa Ziehau */ 28026c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 28036c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 28046c8d8eccSSepherosa Ziehau } else if (!sc->bnx_link) { 28056c8d8eccSSepherosa Ziehau mii_tick(device_get_softc(sc->bnx_miibus)); 28066c8d8eccSSepherosa Ziehau } 28076c8d8eccSSepherosa Ziehau 28086c8d8eccSSepherosa Ziehau callout_reset(&sc->bnx_stat_timer, hz, bnx_tick, sc); 28096c8d8eccSSepherosa Ziehau 28106c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 28116c8d8eccSSepherosa Ziehau } 28126c8d8eccSSepherosa Ziehau 28136c8d8eccSSepherosa Ziehau static void 28146c8d8eccSSepherosa Ziehau bnx_stats_update_regs(struct bnx_softc *sc) 28156c8d8eccSSepherosa Ziehau { 28166c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 28176c8d8eccSSepherosa Ziehau struct bge_mac_stats_regs stats; 28186c8d8eccSSepherosa Ziehau uint32_t *s; 28196c8d8eccSSepherosa Ziehau int i; 28206c8d8eccSSepherosa Ziehau 28216c8d8eccSSepherosa Ziehau s = (uint32_t *)&stats; 28226c8d8eccSSepherosa Ziehau for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) { 28236c8d8eccSSepherosa Ziehau *s = CSR_READ_4(sc, BGE_RX_STATS + i); 28246c8d8eccSSepherosa Ziehau s++; 28256c8d8eccSSepherosa Ziehau } 28266c8d8eccSSepherosa Ziehau 28276c8d8eccSSepherosa Ziehau ifp->if_collisions += 28286c8d8eccSSepherosa Ziehau (stats.dot3StatsSingleCollisionFrames + 28296c8d8eccSSepherosa Ziehau stats.dot3StatsMultipleCollisionFrames + 28306c8d8eccSSepherosa Ziehau stats.dot3StatsExcessiveCollisions + 28316c8d8eccSSepherosa Ziehau stats.dot3StatsLateCollisions) - 28326c8d8eccSSepherosa Ziehau ifp->if_collisions; 28336c8d8eccSSepherosa Ziehau } 28346c8d8eccSSepherosa Ziehau 28356c8d8eccSSepherosa Ziehau /* 28366c8d8eccSSepherosa Ziehau * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data 28376c8d8eccSSepherosa Ziehau * pointers to descriptors. 28386c8d8eccSSepherosa Ziehau */ 28396c8d8eccSSepherosa Ziehau static int 2840c9b7f592SSepherosa Ziehau bnx_encap(struct bnx_softc *sc, struct mbuf **m_head0, uint32_t *txidx, 2841c9b7f592SSepherosa Ziehau int *segs_used) 28426c8d8eccSSepherosa Ziehau { 28436c8d8eccSSepherosa Ziehau struct bge_tx_bd *d = NULL; 284466deb1c1SSepherosa Ziehau uint16_t csum_flags = 0, vlan_tag = 0, mss = 0; 28456c8d8eccSSepherosa Ziehau bus_dma_segment_t segs[BNX_NSEG_NEW]; 28466c8d8eccSSepherosa Ziehau bus_dmamap_t map; 28476c8d8eccSSepherosa Ziehau int error, maxsegs, nsegs, idx, i; 28486c8d8eccSSepherosa Ziehau struct mbuf *m_head = *m_head0, *m_new; 28496c8d8eccSSepherosa Ziehau 285066deb1c1SSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { 285166deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 285266deb1c1SSepherosa Ziehau int tso_nsegs; 285366deb1c1SSepherosa Ziehau #endif 285466deb1c1SSepherosa Ziehau 285566deb1c1SSepherosa Ziehau error = bnx_setup_tso(sc, m_head0, &mss, &csum_flags); 285666deb1c1SSepherosa Ziehau if (error) 285766deb1c1SSepherosa Ziehau return error; 285866deb1c1SSepherosa Ziehau m_head = *m_head0; 285966deb1c1SSepherosa Ziehau 286066deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 2861f0336d39SSepherosa Ziehau tso_nsegs = (m_head->m_pkthdr.len / 2862f0336d39SSepherosa Ziehau m_head->m_pkthdr.tso_segsz) - 1; 286366deb1c1SSepherosa Ziehau if (tso_nsegs > (BNX_TSO_NSTATS - 1)) 286466deb1c1SSepherosa Ziehau tso_nsegs = BNX_TSO_NSTATS - 1; 286566deb1c1SSepherosa Ziehau else if (tso_nsegs < 0) 286666deb1c1SSepherosa Ziehau tso_nsegs = 0; 286766deb1c1SSepherosa Ziehau sc->bnx_tsosegs[tso_nsegs]++; 286866deb1c1SSepherosa Ziehau #endif 286966deb1c1SSepherosa Ziehau } else if (m_head->m_pkthdr.csum_flags & BNX_CSUM_FEATURES) { 28706c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_IP) 28716c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_CSUM; 28726c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP)) 28736c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_TCP_UDP_CSUM; 28746c8d8eccSSepherosa Ziehau if (m_head->m_flags & M_LASTFRAG) 28756c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG_END; 28766c8d8eccSSepherosa Ziehau else if (m_head->m_flags & M_FRAG) 28776c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG; 28786c8d8eccSSepherosa Ziehau } 287966deb1c1SSepherosa Ziehau if (m_head->m_flags & M_VLANTAG) { 288066deb1c1SSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_VLAN_TAG; 288166deb1c1SSepherosa Ziehau vlan_tag = m_head->m_pkthdr.ether_vlantag; 288266deb1c1SSepherosa Ziehau } 28836c8d8eccSSepherosa Ziehau 28846c8d8eccSSepherosa Ziehau idx = *txidx; 28856c8d8eccSSepherosa Ziehau map = sc->bnx_cdata.bnx_tx_dmamap[idx]; 28866c8d8eccSSepherosa Ziehau 28876c8d8eccSSepherosa Ziehau maxsegs = (BGE_TX_RING_CNT - sc->bnx_txcnt) - BNX_NSEG_RSVD; 28886c8d8eccSSepherosa Ziehau KASSERT(maxsegs >= BNX_NSEG_SPARE, 28896c8d8eccSSepherosa Ziehau ("not enough segments %d", maxsegs)); 28906c8d8eccSSepherosa Ziehau 28916c8d8eccSSepherosa Ziehau if (maxsegs > BNX_NSEG_NEW) 28926c8d8eccSSepherosa Ziehau maxsegs = BNX_NSEG_NEW; 28936c8d8eccSSepherosa Ziehau 28946c8d8eccSSepherosa Ziehau /* 28956c8d8eccSSepherosa Ziehau * Pad outbound frame to BGE_MIN_FRAMELEN for an unusual reason. 28966c8d8eccSSepherosa Ziehau * The bge hardware will pad out Tx runts to BGE_MIN_FRAMELEN, 28976c8d8eccSSepherosa Ziehau * but when such padded frames employ the bge IP/TCP checksum 28986c8d8eccSSepherosa Ziehau * offload, the hardware checksum assist gives incorrect results 28996c8d8eccSSepherosa Ziehau * (possibly from incorporating its own padding into the UDP/TCP 29006c8d8eccSSepherosa Ziehau * checksum; who knows). If we pad such runts with zeros, the 29016c8d8eccSSepherosa Ziehau * onboard checksum comes out correct. 29026c8d8eccSSepherosa Ziehau */ 29036c8d8eccSSepherosa Ziehau if ((csum_flags & BGE_TXBDFLAG_TCP_UDP_CSUM) && 29046c8d8eccSSepherosa Ziehau m_head->m_pkthdr.len < BNX_MIN_FRAMELEN) { 29056c8d8eccSSepherosa Ziehau error = m_devpad(m_head, BNX_MIN_FRAMELEN); 29066c8d8eccSSepherosa Ziehau if (error) 29076c8d8eccSSepherosa Ziehau goto back; 29086c8d8eccSSepherosa Ziehau } 29096c8d8eccSSepherosa Ziehau 29106c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_SHORTDMA) && m_head->m_next != NULL) { 29116c8d8eccSSepherosa Ziehau m_new = bnx_defrag_shortdma(m_head); 29126c8d8eccSSepherosa Ziehau if (m_new == NULL) { 29136c8d8eccSSepherosa Ziehau error = ENOBUFS; 29146c8d8eccSSepherosa Ziehau goto back; 29156c8d8eccSSepherosa Ziehau } 29166c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 29176c8d8eccSSepherosa Ziehau } 291866deb1c1SSepherosa Ziehau if ((m_head->m_pkthdr.csum_flags & CSUM_TSO) == 0 && 291966deb1c1SSepherosa Ziehau sc->bnx_force_defrag && m_head->m_next != NULL) { 29206c8d8eccSSepherosa Ziehau /* 29216c8d8eccSSepherosa Ziehau * Forcefully defragment mbuf chain to overcome hardware 29226c8d8eccSSepherosa Ziehau * limitation which only support a single outstanding 29236c8d8eccSSepherosa Ziehau * DMA read operation. If it fails, keep moving on using 29246c8d8eccSSepherosa Ziehau * the original mbuf chain. 29256c8d8eccSSepherosa Ziehau */ 29266c8d8eccSSepherosa Ziehau m_new = m_defrag(m_head, MB_DONTWAIT); 29276c8d8eccSSepherosa Ziehau if (m_new != NULL) 29286c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 29296c8d8eccSSepherosa Ziehau } 29306c8d8eccSSepherosa Ziehau 29316c8d8eccSSepherosa Ziehau error = bus_dmamap_load_mbuf_defrag(sc->bnx_cdata.bnx_tx_mtag, map, 29326c8d8eccSSepherosa Ziehau m_head0, segs, maxsegs, &nsegs, BUS_DMA_NOWAIT); 29336c8d8eccSSepherosa Ziehau if (error) 29346c8d8eccSSepherosa Ziehau goto back; 2935c9b7f592SSepherosa Ziehau *segs_used += nsegs; 29366c8d8eccSSepherosa Ziehau 29376c8d8eccSSepherosa Ziehau m_head = *m_head0; 29386c8d8eccSSepherosa Ziehau bus_dmamap_sync(sc->bnx_cdata.bnx_tx_mtag, map, BUS_DMASYNC_PREWRITE); 29396c8d8eccSSepherosa Ziehau 29406c8d8eccSSepherosa Ziehau for (i = 0; ; i++) { 29416c8d8eccSSepherosa Ziehau d = &sc->bnx_ldata.bnx_tx_ring[idx]; 29426c8d8eccSSepherosa Ziehau 29436c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_lo = BGE_ADDR_LO(segs[i].ds_addr); 29446c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_hi = BGE_ADDR_HI(segs[i].ds_addr); 29456c8d8eccSSepherosa Ziehau d->bge_len = segs[i].ds_len; 29466c8d8eccSSepherosa Ziehau d->bge_flags = csum_flags; 294766deb1c1SSepherosa Ziehau d->bge_vlan_tag = vlan_tag; 294866deb1c1SSepherosa Ziehau d->bge_mss = mss; 29496c8d8eccSSepherosa Ziehau 29506c8d8eccSSepherosa Ziehau if (i == nsegs - 1) 29516c8d8eccSSepherosa Ziehau break; 29526c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 29536c8d8eccSSepherosa Ziehau } 29546c8d8eccSSepherosa Ziehau /* Mark the last segment as end of packet... */ 29556c8d8eccSSepherosa Ziehau d->bge_flags |= BGE_TXBDFLAG_END; 29566c8d8eccSSepherosa Ziehau 29576c8d8eccSSepherosa Ziehau /* 29586c8d8eccSSepherosa Ziehau * Insure that the map for this transmission is placed at 29596c8d8eccSSepherosa Ziehau * the array index of the last descriptor in this chain. 29606c8d8eccSSepherosa Ziehau */ 29616c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[*txidx] = sc->bnx_cdata.bnx_tx_dmamap[idx]; 29626c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[idx] = map; 29636c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_chain[idx] = m_head; 29646c8d8eccSSepherosa Ziehau sc->bnx_txcnt += nsegs; 29656c8d8eccSSepherosa Ziehau 29666c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 29676c8d8eccSSepherosa Ziehau *txidx = idx; 29686c8d8eccSSepherosa Ziehau back: 29696c8d8eccSSepherosa Ziehau if (error) { 29706c8d8eccSSepherosa Ziehau m_freem(*m_head0); 29716c8d8eccSSepherosa Ziehau *m_head0 = NULL; 29726c8d8eccSSepherosa Ziehau } 29736c8d8eccSSepherosa Ziehau return error; 29746c8d8eccSSepherosa Ziehau } 29756c8d8eccSSepherosa Ziehau 29766c8d8eccSSepherosa Ziehau /* 29776c8d8eccSSepherosa Ziehau * Main transmit routine. To avoid having to do mbuf copies, we put pointers 29786c8d8eccSSepherosa Ziehau * to the mbuf data regions directly in the transmit descriptors. 29796c8d8eccSSepherosa Ziehau */ 29806c8d8eccSSepherosa Ziehau static void 29816c8d8eccSSepherosa Ziehau bnx_start(struct ifnet *ifp) 29826c8d8eccSSepherosa Ziehau { 29836c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 29846c8d8eccSSepherosa Ziehau struct mbuf *m_head = NULL; 29856c8d8eccSSepherosa Ziehau uint32_t prodidx; 2986c9b7f592SSepherosa Ziehau int nsegs = 0; 29876c8d8eccSSepherosa Ziehau 2988*9ed293e0SSepherosa Ziehau if ((ifp->if_flags & IFF_RUNNING) == 0 || ifq_is_oactive(&ifp->if_snd)) 29896c8d8eccSSepherosa Ziehau return; 29906c8d8eccSSepherosa Ziehau 29916c8d8eccSSepherosa Ziehau prodidx = sc->bnx_tx_prodidx; 29926c8d8eccSSepherosa Ziehau 29936c8d8eccSSepherosa Ziehau while (sc->bnx_cdata.bnx_tx_chain[prodidx] == NULL) { 29946c8d8eccSSepherosa Ziehau /* 29956c8d8eccSSepherosa Ziehau * Sanity check: avoid coming within BGE_NSEG_RSVD 29966c8d8eccSSepherosa Ziehau * descriptors of the end of the ring. Also make 29976c8d8eccSSepherosa Ziehau * sure there are BGE_NSEG_SPARE descriptors for 2998a1bd58c9SSepherosa Ziehau * jumbo buffers' or TSO segments' defragmentation. 29996c8d8eccSSepherosa Ziehau */ 30006c8d8eccSSepherosa Ziehau if ((BGE_TX_RING_CNT - sc->bnx_txcnt) < 30016c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) { 3002*9ed293e0SSepherosa Ziehau ifq_set_oactive(&ifp->if_snd); 30036c8d8eccSSepherosa Ziehau break; 30046c8d8eccSSepherosa Ziehau } 30056c8d8eccSSepherosa Ziehau 3006a1bd58c9SSepherosa Ziehau m_head = ifq_dequeue(&ifp->if_snd, NULL); 3007a1bd58c9SSepherosa Ziehau if (m_head == NULL) 3008a1bd58c9SSepherosa Ziehau break; 3009a1bd58c9SSepherosa Ziehau 30106c8d8eccSSepherosa Ziehau /* 30116c8d8eccSSepherosa Ziehau * Pack the data into the transmit ring. If we 30126c8d8eccSSepherosa Ziehau * don't have room, set the OACTIVE flag and wait 30136c8d8eccSSepherosa Ziehau * for the NIC to drain the ring. 30146c8d8eccSSepherosa Ziehau */ 3015c9b7f592SSepherosa Ziehau if (bnx_encap(sc, &m_head, &prodidx, &nsegs)) { 3016*9ed293e0SSepherosa Ziehau ifq_set_oactive(&ifp->if_snd); 30176c8d8eccSSepherosa Ziehau ifp->if_oerrors++; 30186c8d8eccSSepherosa Ziehau break; 30196c8d8eccSSepherosa Ziehau } 30206c8d8eccSSepherosa Ziehau 3021c9b7f592SSepherosa Ziehau if (nsegs >= sc->bnx_tx_wreg) { 30226c8d8eccSSepherosa Ziehau /* Transmit */ 30236c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx); 3024c9b7f592SSepherosa Ziehau nsegs = 0; 3025c9b7f592SSepherosa Ziehau } 30266c8d8eccSSepherosa Ziehau 3027c9b7f592SSepherosa Ziehau ETHER_BPF_MTAP(ifp, m_head); 30286c8d8eccSSepherosa Ziehau 30296c8d8eccSSepherosa Ziehau /* 30306c8d8eccSSepherosa Ziehau * Set a timeout in case the chip goes out to lunch. 30316c8d8eccSSepherosa Ziehau */ 30326c8d8eccSSepherosa Ziehau ifp->if_timer = 5; 30336c8d8eccSSepherosa Ziehau } 30346c8d8eccSSepherosa Ziehau 3035c9b7f592SSepherosa Ziehau if (nsegs > 0) { 3036c9b7f592SSepherosa Ziehau /* Transmit */ 3037c9b7f592SSepherosa Ziehau bnx_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx); 3038c9b7f592SSepherosa Ziehau } 3039c9b7f592SSepherosa Ziehau sc->bnx_tx_prodidx = prodidx; 3040c9b7f592SSepherosa Ziehau } 3041c9b7f592SSepherosa Ziehau 30426c8d8eccSSepherosa Ziehau static void 30436c8d8eccSSepherosa Ziehau bnx_init(void *xsc) 30446c8d8eccSSepherosa Ziehau { 30456c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 30466c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 30476c8d8eccSSepherosa Ziehau uint16_t *m; 30486c8d8eccSSepherosa Ziehau uint32_t mode; 30496c8d8eccSSepherosa Ziehau 30506c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 30516c8d8eccSSepherosa Ziehau 30526c8d8eccSSepherosa Ziehau /* Cancel pending I/O and flush buffers. */ 30536c8d8eccSSepherosa Ziehau bnx_stop(sc); 30546c8d8eccSSepherosa Ziehau bnx_reset(sc); 30556c8d8eccSSepherosa Ziehau bnx_chipinit(sc); 30566c8d8eccSSepherosa Ziehau 30576c8d8eccSSepherosa Ziehau /* 30586c8d8eccSSepherosa Ziehau * Init the various state machines, ring 30596c8d8eccSSepherosa Ziehau * control blocks and firmware. 30606c8d8eccSSepherosa Ziehau */ 30616c8d8eccSSepherosa Ziehau if (bnx_blockinit(sc)) { 30626c8d8eccSSepherosa Ziehau if_printf(ifp, "initialization failure\n"); 30636c8d8eccSSepherosa Ziehau bnx_stop(sc); 30646c8d8eccSSepherosa Ziehau return; 30656c8d8eccSSepherosa Ziehau } 30666c8d8eccSSepherosa Ziehau 30676c8d8eccSSepherosa Ziehau /* Specify MTU. */ 30686c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu + 30696c8d8eccSSepherosa Ziehau ETHER_HDR_LEN + ETHER_CRC_LEN + EVL_ENCAPLEN); 30706c8d8eccSSepherosa Ziehau 30716c8d8eccSSepherosa Ziehau /* Load our MAC address. */ 30726c8d8eccSSepherosa Ziehau m = (uint16_t *)&sc->arpcom.ac_enaddr[0]; 30736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_LO, htons(m[0])); 30746c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_HI, (htons(m[1]) << 16) | htons(m[2])); 30756c8d8eccSSepherosa Ziehau 30766c8d8eccSSepherosa Ziehau /* Enable or disable promiscuous mode as needed. */ 30776c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 30786c8d8eccSSepherosa Ziehau 30796c8d8eccSSepherosa Ziehau /* Program multicast filter. */ 30806c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 30816c8d8eccSSepherosa Ziehau 30826c8d8eccSSepherosa Ziehau /* Init RX ring. */ 30836c8d8eccSSepherosa Ziehau if (bnx_init_rx_ring_std(sc)) { 30846c8d8eccSSepherosa Ziehau if_printf(ifp, "RX ring initialization failed\n"); 30856c8d8eccSSepherosa Ziehau bnx_stop(sc); 30866c8d8eccSSepherosa Ziehau return; 30876c8d8eccSSepherosa Ziehau } 30886c8d8eccSSepherosa Ziehau 30896c8d8eccSSepherosa Ziehau /* Init jumbo RX ring. */ 30906c8d8eccSSepherosa Ziehau if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) { 30916c8d8eccSSepherosa Ziehau if (bnx_init_rx_ring_jumbo(sc)) { 30926c8d8eccSSepherosa Ziehau if_printf(ifp, "Jumbo RX ring initialization failed\n"); 30936c8d8eccSSepherosa Ziehau bnx_stop(sc); 30946c8d8eccSSepherosa Ziehau return; 30956c8d8eccSSepherosa Ziehau } 30966c8d8eccSSepherosa Ziehau } 30976c8d8eccSSepherosa Ziehau 30986c8d8eccSSepherosa Ziehau /* Init our RX return ring index */ 30996c8d8eccSSepherosa Ziehau sc->bnx_rx_saved_considx = 0; 31006c8d8eccSSepherosa Ziehau 31016c8d8eccSSepherosa Ziehau /* Init TX ring. */ 31026c8d8eccSSepherosa Ziehau bnx_init_tx_ring(sc); 31036c8d8eccSSepherosa Ziehau 31046c8d8eccSSepherosa Ziehau /* Enable TX MAC state machine lockup fix. */ 31056c8d8eccSSepherosa Ziehau mode = CSR_READ_4(sc, BGE_TX_MODE); 31066c8d8eccSSepherosa Ziehau mode |= BGE_TXMODE_MBUF_LOCKUP_FIX; 31076c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 31086c8d8eccSSepherosa Ziehau mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 31096c8d8eccSSepherosa Ziehau mode |= CSR_READ_4(sc, BGE_TX_MODE) & 31106c8d8eccSSepherosa Ziehau (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 31116c8d8eccSSepherosa Ziehau } 31126c8d8eccSSepherosa Ziehau /* Turn on transmitter */ 31136c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE); 31146c8d8eccSSepherosa Ziehau 31156c8d8eccSSepherosa Ziehau /* Turn on receiver */ 31166c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 31176c8d8eccSSepherosa Ziehau 31186c8d8eccSSepherosa Ziehau /* 31196c8d8eccSSepherosa Ziehau * Set the number of good frames to receive after RX MBUF 31206c8d8eccSSepherosa Ziehau * Low Watermark has been reached. After the RX MAC receives 31216c8d8eccSSepherosa Ziehau * this number of frames, it will drop subsequent incoming 31226c8d8eccSSepherosa Ziehau * frames until the MBUF High Watermark is reached. 31236c8d8eccSSepherosa Ziehau */ 3124bcb29629SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) 31256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 1); 31266c8d8eccSSepherosa Ziehau else 31276c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2); 31286c8d8eccSSepherosa Ziehau 31296c8d8eccSSepherosa Ziehau if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) { 31306c8d8eccSSepherosa Ziehau if (bootverbose) { 31316c8d8eccSSepherosa Ziehau if_printf(ifp, "MSI_MODE: %#x\n", 31326c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MSI_MODE)); 31336c8d8eccSSepherosa Ziehau } 31346c8d8eccSSepherosa Ziehau } 31356c8d8eccSSepherosa Ziehau 31366c8d8eccSSepherosa Ziehau /* Tell firmware we're alive. */ 31376c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 31386c8d8eccSSepherosa Ziehau 31396c8d8eccSSepherosa Ziehau /* Enable host interrupts if polling(4) is not enabled. */ 31406c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA, 4); 314139a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 314239a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_NPOLLING) 31436c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 31446c8d8eccSSepherosa Ziehau else 31456c8d8eccSSepherosa Ziehau #endif 31466c8d8eccSSepherosa Ziehau bnx_enable_intr(sc); 31476c8d8eccSSepherosa Ziehau 31486c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(ifp); 31496c8d8eccSSepherosa Ziehau 31506c8d8eccSSepherosa Ziehau ifp->if_flags |= IFF_RUNNING; 3151*9ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 31526c8d8eccSSepherosa Ziehau 31538ca0f604SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_stat_timer, hz, bnx_tick, sc, 31548ca0f604SSepherosa Ziehau sc->bnx_stat_cpuid); 31556c8d8eccSSepherosa Ziehau } 31566c8d8eccSSepherosa Ziehau 31576c8d8eccSSepherosa Ziehau /* 31586c8d8eccSSepherosa Ziehau * Set media options. 31596c8d8eccSSepherosa Ziehau */ 31606c8d8eccSSepherosa Ziehau static int 31616c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(struct ifnet *ifp) 31626c8d8eccSSepherosa Ziehau { 31636c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 31646c8d8eccSSepherosa Ziehau 31656c8d8eccSSepherosa Ziehau /* If this is a 1000baseX NIC, enable the TBI port. */ 31666c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 31676c8d8eccSSepherosa Ziehau struct ifmedia *ifm = &sc->bnx_ifmedia; 31686c8d8eccSSepherosa Ziehau 31696c8d8eccSSepherosa Ziehau if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 31706c8d8eccSSepherosa Ziehau return(EINVAL); 31716c8d8eccSSepherosa Ziehau 31726c8d8eccSSepherosa Ziehau switch(IFM_SUBTYPE(ifm->ifm_media)) { 31736c8d8eccSSepherosa Ziehau case IFM_AUTO: 31746c8d8eccSSepherosa Ziehau break; 31756c8d8eccSSepherosa Ziehau 31766c8d8eccSSepherosa Ziehau case IFM_1000_SX: 31776c8d8eccSSepherosa Ziehau if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 31786c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 31796c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 31806c8d8eccSSepherosa Ziehau } else { 31816c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, 31826c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 31836c8d8eccSSepherosa Ziehau } 31846c8d8eccSSepherosa Ziehau break; 31856c8d8eccSSepherosa Ziehau default: 31866c8d8eccSSepherosa Ziehau return(EINVAL); 31876c8d8eccSSepherosa Ziehau } 31886c8d8eccSSepherosa Ziehau } else { 31896c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 31906c8d8eccSSepherosa Ziehau 31916c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 31926c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 31936c8d8eccSSepherosa Ziehau if (mii->mii_instance) { 31946c8d8eccSSepherosa Ziehau struct mii_softc *miisc; 31956c8d8eccSSepherosa Ziehau 31966c8d8eccSSepherosa Ziehau LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 31976c8d8eccSSepherosa Ziehau mii_phy_reset(miisc); 31986c8d8eccSSepherosa Ziehau } 31996c8d8eccSSepherosa Ziehau mii_mediachg(mii); 32006c8d8eccSSepherosa Ziehau 32016c8d8eccSSepherosa Ziehau /* 32026c8d8eccSSepherosa Ziehau * Force an interrupt so that we will call bnx_link_upd 32036c8d8eccSSepherosa Ziehau * if needed and clear any pending link state attention. 32046c8d8eccSSepherosa Ziehau * Without this we are not getting any further interrupts 32056c8d8eccSSepherosa Ziehau * for link state changes and thus will not UP the link and 32066c8d8eccSSepherosa Ziehau * not be able to send in bnx_start. The only way to get 32076c8d8eccSSepherosa Ziehau * things working was to receive a packet and get an RX 32086c8d8eccSSepherosa Ziehau * intr. 32096c8d8eccSSepherosa Ziehau * 32106c8d8eccSSepherosa Ziehau * bnx_tick should help for fiber cards and we might not 32116c8d8eccSSepherosa Ziehau * need to do this here if BNX_FLAG_TBI is set but as 32126c8d8eccSSepherosa Ziehau * we poll for fiber anyway it should not harm. 32136c8d8eccSSepherosa Ziehau */ 32146c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 32156c8d8eccSSepherosa Ziehau } 32166c8d8eccSSepherosa Ziehau return(0); 32176c8d8eccSSepherosa Ziehau } 32186c8d8eccSSepherosa Ziehau 32196c8d8eccSSepherosa Ziehau /* 32206c8d8eccSSepherosa Ziehau * Report current media status. 32216c8d8eccSSepherosa Ziehau */ 32226c8d8eccSSepherosa Ziehau static void 32236c8d8eccSSepherosa Ziehau bnx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 32246c8d8eccSSepherosa Ziehau { 32256c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 32266c8d8eccSSepherosa Ziehau 32276c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 32286c8d8eccSSepherosa Ziehau ifmr->ifm_status = IFM_AVALID; 32296c8d8eccSSepherosa Ziehau ifmr->ifm_active = IFM_ETHER; 32306c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_STS) & 32316c8d8eccSSepherosa Ziehau BGE_MACSTAT_TBI_PCS_SYNCHED) { 32326c8d8eccSSepherosa Ziehau ifmr->ifm_status |= IFM_ACTIVE; 32336c8d8eccSSepherosa Ziehau } else { 32346c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_NONE; 32356c8d8eccSSepherosa Ziehau return; 32366c8d8eccSSepherosa Ziehau } 32376c8d8eccSSepherosa Ziehau 32386c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_1000_SX; 32396c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_MODE) & BGE_MACMODE_HALF_DUPLEX) 32406c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_HDX; 32416c8d8eccSSepherosa Ziehau else 32426c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_FDX; 32436c8d8eccSSepherosa Ziehau } else { 32446c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 32456c8d8eccSSepherosa Ziehau 32466c8d8eccSSepherosa Ziehau mii_pollstat(mii); 32476c8d8eccSSepherosa Ziehau ifmr->ifm_active = mii->mii_media_active; 32486c8d8eccSSepherosa Ziehau ifmr->ifm_status = mii->mii_media_status; 32496c8d8eccSSepherosa Ziehau } 32506c8d8eccSSepherosa Ziehau } 32516c8d8eccSSepherosa Ziehau 32526c8d8eccSSepherosa Ziehau static int 32536c8d8eccSSepherosa Ziehau bnx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) 32546c8d8eccSSepherosa Ziehau { 32556c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 32566c8d8eccSSepherosa Ziehau struct ifreq *ifr = (struct ifreq *)data; 32576c8d8eccSSepherosa Ziehau int mask, error = 0; 32586c8d8eccSSepherosa Ziehau 32596c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 32606c8d8eccSSepherosa Ziehau 32616c8d8eccSSepherosa Ziehau switch (command) { 32626c8d8eccSSepherosa Ziehau case SIOCSIFMTU: 32636c8d8eccSSepherosa Ziehau if ((!BNX_IS_JUMBO_CAPABLE(sc) && ifr->ifr_mtu > ETHERMTU) || 32646c8d8eccSSepherosa Ziehau (BNX_IS_JUMBO_CAPABLE(sc) && 32656c8d8eccSSepherosa Ziehau ifr->ifr_mtu > BNX_JUMBO_MTU)) { 32666c8d8eccSSepherosa Ziehau error = EINVAL; 32676c8d8eccSSepherosa Ziehau } else if (ifp->if_mtu != ifr->ifr_mtu) { 32686c8d8eccSSepherosa Ziehau ifp->if_mtu = ifr->ifr_mtu; 32696c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 32706c8d8eccSSepherosa Ziehau bnx_init(sc); 32716c8d8eccSSepherosa Ziehau } 32726c8d8eccSSepherosa Ziehau break; 32736c8d8eccSSepherosa Ziehau case SIOCSIFFLAGS: 32746c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 32756c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 32766c8d8eccSSepherosa Ziehau mask = ifp->if_flags ^ sc->bnx_if_flags; 32776c8d8eccSSepherosa Ziehau 32786c8d8eccSSepherosa Ziehau /* 32796c8d8eccSSepherosa Ziehau * If only the state of the PROMISC flag 32806c8d8eccSSepherosa Ziehau * changed, then just use the 'set promisc 32816c8d8eccSSepherosa Ziehau * mode' command instead of reinitializing 32826c8d8eccSSepherosa Ziehau * the entire NIC. Doing a full re-init 32836c8d8eccSSepherosa Ziehau * means reloading the firmware and waiting 32846c8d8eccSSepherosa Ziehau * for it to start up, which may take a 32856c8d8eccSSepherosa Ziehau * second or two. Similarly for ALLMULTI. 32866c8d8eccSSepherosa Ziehau */ 32876c8d8eccSSepherosa Ziehau if (mask & IFF_PROMISC) 32886c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 32896c8d8eccSSepherosa Ziehau if (mask & IFF_ALLMULTI) 32906c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 32916c8d8eccSSepherosa Ziehau } else { 32926c8d8eccSSepherosa Ziehau bnx_init(sc); 32936c8d8eccSSepherosa Ziehau } 32946c8d8eccSSepherosa Ziehau } else if (ifp->if_flags & IFF_RUNNING) { 32956c8d8eccSSepherosa Ziehau bnx_stop(sc); 32966c8d8eccSSepherosa Ziehau } 32976c8d8eccSSepherosa Ziehau sc->bnx_if_flags = ifp->if_flags; 32986c8d8eccSSepherosa Ziehau break; 32996c8d8eccSSepherosa Ziehau case SIOCADDMULTI: 33006c8d8eccSSepherosa Ziehau case SIOCDELMULTI: 33016c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 33026c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 33036c8d8eccSSepherosa Ziehau break; 33046c8d8eccSSepherosa Ziehau case SIOCSIFMEDIA: 33056c8d8eccSSepherosa Ziehau case SIOCGIFMEDIA: 33066c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 33076c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 33086c8d8eccSSepherosa Ziehau &sc->bnx_ifmedia, command); 33096c8d8eccSSepherosa Ziehau } else { 33106c8d8eccSSepherosa Ziehau struct mii_data *mii; 33116c8d8eccSSepherosa Ziehau 33126c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 33136c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 33146c8d8eccSSepherosa Ziehau &mii->mii_media, command); 33156c8d8eccSSepherosa Ziehau } 33166c8d8eccSSepherosa Ziehau break; 33176c8d8eccSSepherosa Ziehau case SIOCSIFCAP: 33186c8d8eccSSepherosa Ziehau mask = ifr->ifr_reqcap ^ ifp->if_capenable; 33196c8d8eccSSepherosa Ziehau if (mask & IFCAP_HWCSUM) { 33206c8d8eccSSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_HWCSUM); 332166deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TXCSUM) 332266deb1c1SSepherosa Ziehau ifp->if_hwassist |= BNX_CSUM_FEATURES; 33236c8d8eccSSepherosa Ziehau else 332466deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~BNX_CSUM_FEATURES; 332566deb1c1SSepherosa Ziehau } 332666deb1c1SSepherosa Ziehau if (mask & IFCAP_TSO) { 332766deb1c1SSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_TSO); 332866deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TSO) 332966deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 333066deb1c1SSepherosa Ziehau else 333166deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~CSUM_TSO; 33326c8d8eccSSepherosa Ziehau } 33336c8d8eccSSepherosa Ziehau break; 33346c8d8eccSSepherosa Ziehau default: 33356c8d8eccSSepherosa Ziehau error = ether_ioctl(ifp, command, data); 33366c8d8eccSSepherosa Ziehau break; 33376c8d8eccSSepherosa Ziehau } 33386c8d8eccSSepherosa Ziehau return error; 33396c8d8eccSSepherosa Ziehau } 33406c8d8eccSSepherosa Ziehau 33416c8d8eccSSepherosa Ziehau static void 33426c8d8eccSSepherosa Ziehau bnx_watchdog(struct ifnet *ifp) 33436c8d8eccSSepherosa Ziehau { 33446c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 33456c8d8eccSSepherosa Ziehau 33466c8d8eccSSepherosa Ziehau if_printf(ifp, "watchdog timeout -- resetting\n"); 33476c8d8eccSSepherosa Ziehau 33486c8d8eccSSepherosa Ziehau bnx_init(sc); 33496c8d8eccSSepherosa Ziehau 33506c8d8eccSSepherosa Ziehau ifp->if_oerrors++; 33516c8d8eccSSepherosa Ziehau 33526c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 33536c8d8eccSSepherosa Ziehau if_devstart(ifp); 33546c8d8eccSSepherosa Ziehau } 33556c8d8eccSSepherosa Ziehau 33566c8d8eccSSepherosa Ziehau /* 33576c8d8eccSSepherosa Ziehau * Stop the adapter and free any mbufs allocated to the 33586c8d8eccSSepherosa Ziehau * RX and TX lists. 33596c8d8eccSSepherosa Ziehau */ 33606c8d8eccSSepherosa Ziehau static void 33616c8d8eccSSepherosa Ziehau bnx_stop(struct bnx_softc *sc) 33626c8d8eccSSepherosa Ziehau { 33636c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 33646c8d8eccSSepherosa Ziehau 33656c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 33666c8d8eccSSepherosa Ziehau 33676c8d8eccSSepherosa Ziehau callout_stop(&sc->bnx_stat_timer); 33686c8d8eccSSepherosa Ziehau 33696c8d8eccSSepherosa Ziehau /* 33706c8d8eccSSepherosa Ziehau * Disable all of the receiver blocks 33716c8d8eccSSepherosa Ziehau */ 33726c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 33736c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 33746c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 33756c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDBDI_MODE, BGE_RBDIMODE_ENABLE); 33766c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 33776c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDC_MODE, BGE_RBDCMODE_ENABLE); 33786c8d8eccSSepherosa Ziehau 33796c8d8eccSSepherosa Ziehau /* 33806c8d8eccSSepherosa Ziehau * Disable all of the transmit blocks 33816c8d8eccSSepherosa Ziehau */ 33826c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 33836c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 33846c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 33856c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDMA_MODE, BGE_RDMAMODE_ENABLE); 33866c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDC_MODE, BGE_SDCMODE_ENABLE); 33876c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 33886c8d8eccSSepherosa Ziehau 33896c8d8eccSSepherosa Ziehau /* 33906c8d8eccSSepherosa Ziehau * Shut down all of the memory managers and related 33916c8d8eccSSepherosa Ziehau * state machines. 33926c8d8eccSSepherosa Ziehau */ 33936c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE); 33946c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_WDMA_MODE, BGE_WDMAMODE_ENABLE); 33956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 33966c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 33976c8d8eccSSepherosa Ziehau 33986c8d8eccSSepherosa Ziehau /* Disable host interrupts. */ 33996c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 34006c8d8eccSSepherosa Ziehau 34016c8d8eccSSepherosa Ziehau /* 34026c8d8eccSSepherosa Ziehau * Tell firmware we're shutting down. 34036c8d8eccSSepherosa Ziehau */ 34046c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 34056c8d8eccSSepherosa Ziehau 34066c8d8eccSSepherosa Ziehau /* Free the RX lists. */ 34076c8d8eccSSepherosa Ziehau bnx_free_rx_ring_std(sc); 34086c8d8eccSSepherosa Ziehau 34096c8d8eccSSepherosa Ziehau /* Free jumbo RX list. */ 34106c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 34116c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(sc); 34126c8d8eccSSepherosa Ziehau 34136c8d8eccSSepherosa Ziehau /* Free TX buffers. */ 34146c8d8eccSSepherosa Ziehau bnx_free_tx_ring(sc); 34156c8d8eccSSepherosa Ziehau 34166c8d8eccSSepherosa Ziehau sc->bnx_status_tag = 0; 34176c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 34186c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 34196c8d8eccSSepherosa Ziehau 34206c8d8eccSSepherosa Ziehau sc->bnx_tx_saved_considx = BNX_TXCONS_UNSET; 34216c8d8eccSSepherosa Ziehau 3422*9ed293e0SSepherosa Ziehau ifp->if_flags &= ~IFF_RUNNING; 3423*9ed293e0SSepherosa Ziehau ifq_clr_oactive(&ifp->if_snd); 34246c8d8eccSSepherosa Ziehau ifp->if_timer = 0; 34256c8d8eccSSepherosa Ziehau } 34266c8d8eccSSepherosa Ziehau 34276c8d8eccSSepherosa Ziehau /* 34286c8d8eccSSepherosa Ziehau * Stop all chip I/O so that the kernel's probe routines don't 34296c8d8eccSSepherosa Ziehau * get confused by errant DMAs when rebooting. 34306c8d8eccSSepherosa Ziehau */ 34316c8d8eccSSepherosa Ziehau static void 34326c8d8eccSSepherosa Ziehau bnx_shutdown(device_t dev) 34336c8d8eccSSepherosa Ziehau { 34346c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 34356c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 34366c8d8eccSSepherosa Ziehau 34376c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 34386c8d8eccSSepherosa Ziehau bnx_stop(sc); 34396c8d8eccSSepherosa Ziehau bnx_reset(sc); 34406c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 34416c8d8eccSSepherosa Ziehau } 34426c8d8eccSSepherosa Ziehau 34436c8d8eccSSepherosa Ziehau static int 34446c8d8eccSSepherosa Ziehau bnx_suspend(device_t dev) 34456c8d8eccSSepherosa Ziehau { 34466c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 34476c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 34486c8d8eccSSepherosa Ziehau 34496c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 34506c8d8eccSSepherosa Ziehau bnx_stop(sc); 34516c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 34526c8d8eccSSepherosa Ziehau 34536c8d8eccSSepherosa Ziehau return 0; 34546c8d8eccSSepherosa Ziehau } 34556c8d8eccSSepherosa Ziehau 34566c8d8eccSSepherosa Ziehau static int 34576c8d8eccSSepherosa Ziehau bnx_resume(device_t dev) 34586c8d8eccSSepherosa Ziehau { 34596c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 34606c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 34616c8d8eccSSepherosa Ziehau 34626c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 34636c8d8eccSSepherosa Ziehau 34646c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 34656c8d8eccSSepherosa Ziehau bnx_init(sc); 34666c8d8eccSSepherosa Ziehau 34676c8d8eccSSepherosa Ziehau if (!ifq_is_empty(&ifp->if_snd)) 34686c8d8eccSSepherosa Ziehau if_devstart(ifp); 34696c8d8eccSSepherosa Ziehau } 34706c8d8eccSSepherosa Ziehau 34716c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 34726c8d8eccSSepherosa Ziehau 34736c8d8eccSSepherosa Ziehau return 0; 34746c8d8eccSSepherosa Ziehau } 34756c8d8eccSSepherosa Ziehau 34766c8d8eccSSepherosa Ziehau static void 34776c8d8eccSSepherosa Ziehau bnx_setpromisc(struct bnx_softc *sc) 34786c8d8eccSSepherosa Ziehau { 34796c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 34806c8d8eccSSepherosa Ziehau 34816c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_PROMISC) 34826c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 34836c8d8eccSSepherosa Ziehau else 34846c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 34856c8d8eccSSepherosa Ziehau } 34866c8d8eccSSepherosa Ziehau 34876c8d8eccSSepherosa Ziehau static void 34886c8d8eccSSepherosa Ziehau bnx_dma_free(struct bnx_softc *sc) 34896c8d8eccSSepherosa Ziehau { 34906c8d8eccSSepherosa Ziehau int i; 34916c8d8eccSSepherosa Ziehau 34926c8d8eccSSepherosa Ziehau /* Destroy RX mbuf DMA stuffs. */ 34936c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_rx_mtag != NULL) { 34946c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 34956c8d8eccSSepherosa Ziehau bus_dmamap_destroy(sc->bnx_cdata.bnx_rx_mtag, 34966c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[i]); 34976c8d8eccSSepherosa Ziehau } 34986c8d8eccSSepherosa Ziehau bus_dmamap_destroy(sc->bnx_cdata.bnx_rx_mtag, 34996c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_tmpmap); 35006c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_rx_mtag); 35016c8d8eccSSepherosa Ziehau } 35026c8d8eccSSepherosa Ziehau 35036c8d8eccSSepherosa Ziehau /* Destroy TX mbuf DMA stuffs. */ 35046c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_tx_mtag != NULL) { 35056c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 35066c8d8eccSSepherosa Ziehau bus_dmamap_destroy(sc->bnx_cdata.bnx_tx_mtag, 35076c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[i]); 35086c8d8eccSSepherosa Ziehau } 35096c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_tx_mtag); 35106c8d8eccSSepherosa Ziehau } 35116c8d8eccSSepherosa Ziehau 35126c8d8eccSSepherosa Ziehau /* Destroy standard RX ring */ 35136c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_std_ring_tag, 35146c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_ring_map, 35156c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_std_ring); 35166c8d8eccSSepherosa Ziehau 35176c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 35186c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(sc); 35196c8d8eccSSepherosa Ziehau 35206c8d8eccSSepherosa Ziehau /* Destroy RX return ring */ 35216c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_return_ring_tag, 35226c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_return_ring_map, 35236c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_return_ring); 35246c8d8eccSSepherosa Ziehau 35256c8d8eccSSepherosa Ziehau /* Destroy TX ring */ 35266c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_tx_ring_tag, 35276c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_ring_map, 35286c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_tx_ring); 35296c8d8eccSSepherosa Ziehau 35306c8d8eccSSepherosa Ziehau /* Destroy status block */ 35316c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_status_tag, 35326c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_status_map, 35336c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_status_block); 35346c8d8eccSSepherosa Ziehau 35356c8d8eccSSepherosa Ziehau /* Destroy the parent tag */ 35366c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_parent_tag != NULL) 35376c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_parent_tag); 35386c8d8eccSSepherosa Ziehau } 35396c8d8eccSSepherosa Ziehau 35406c8d8eccSSepherosa Ziehau static int 35416c8d8eccSSepherosa Ziehau bnx_dma_alloc(struct bnx_softc *sc) 35426c8d8eccSSepherosa Ziehau { 35436c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 354466deb1c1SSepherosa Ziehau bus_size_t txmaxsz; 35456c8d8eccSSepherosa Ziehau int i, error; 35466c8d8eccSSepherosa Ziehau 35476c8d8eccSSepherosa Ziehau /* 35486c8d8eccSSepherosa Ziehau * Allocate the parent bus DMA tag appropriate for PCI. 35496c8d8eccSSepherosa Ziehau * 35506c8d8eccSSepherosa Ziehau * All of the NetExtreme/NetLink controllers have 4GB boundary 35516c8d8eccSSepherosa Ziehau * DMA bug. 35526c8d8eccSSepherosa Ziehau * Whenever an address crosses a multiple of the 4GB boundary 35536c8d8eccSSepherosa Ziehau * (including 4GB, 8Gb, 12Gb, etc.) and makes the transition 35546c8d8eccSSepherosa Ziehau * from 0xX_FFFF_FFFF to 0x(X+1)_0000_0000 an internal DMA 35556c8d8eccSSepherosa Ziehau * state machine will lockup and cause the device to hang. 35566c8d8eccSSepherosa Ziehau */ 35576c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(NULL, 1, BGE_DMA_BOUNDARY_4G, 35586c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 35596c8d8eccSSepherosa Ziehau NULL, NULL, 35606c8d8eccSSepherosa Ziehau BUS_SPACE_MAXSIZE_32BIT, 0, 35616c8d8eccSSepherosa Ziehau BUS_SPACE_MAXSIZE_32BIT, 35626c8d8eccSSepherosa Ziehau 0, &sc->bnx_cdata.bnx_parent_tag); 35636c8d8eccSSepherosa Ziehau if (error) { 35646c8d8eccSSepherosa Ziehau if_printf(ifp, "could not allocate parent dma tag\n"); 35656c8d8eccSSepherosa Ziehau return error; 35666c8d8eccSSepherosa Ziehau } 35676c8d8eccSSepherosa Ziehau 35686c8d8eccSSepherosa Ziehau /* 35696c8d8eccSSepherosa Ziehau * Create DMA tag and maps for RX mbufs. 35706c8d8eccSSepherosa Ziehau */ 35716c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0, 35726c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 35736c8d8eccSSepherosa Ziehau NULL, NULL, MCLBYTES, 1, MCLBYTES, 35746c8d8eccSSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK, 35756c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_mtag); 35766c8d8eccSSepherosa Ziehau if (error) { 35776c8d8eccSSepherosa Ziehau if_printf(ifp, "could not allocate RX mbuf dma tag\n"); 35786c8d8eccSSepherosa Ziehau return error; 35796c8d8eccSSepherosa Ziehau } 35806c8d8eccSSepherosa Ziehau 35816c8d8eccSSepherosa Ziehau error = bus_dmamap_create(sc->bnx_cdata.bnx_rx_mtag, 35826c8d8eccSSepherosa Ziehau BUS_DMA_WAITOK, &sc->bnx_cdata.bnx_rx_tmpmap); 35836c8d8eccSSepherosa Ziehau if (error) { 35846c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_rx_mtag); 35856c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_mtag = NULL; 35866c8d8eccSSepherosa Ziehau return error; 35876c8d8eccSSepherosa Ziehau } 35886c8d8eccSSepherosa Ziehau 35896c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 35906c8d8eccSSepherosa Ziehau error = bus_dmamap_create(sc->bnx_cdata.bnx_rx_mtag, 35916c8d8eccSSepherosa Ziehau BUS_DMA_WAITOK, 35926c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_std_dmamap[i]); 35936c8d8eccSSepherosa Ziehau if (error) { 35946c8d8eccSSepherosa Ziehau int j; 35956c8d8eccSSepherosa Ziehau 35966c8d8eccSSepherosa Ziehau for (j = 0; j < i; ++j) { 35976c8d8eccSSepherosa Ziehau bus_dmamap_destroy(sc->bnx_cdata.bnx_rx_mtag, 35986c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_std_dmamap[j]); 35996c8d8eccSSepherosa Ziehau } 36006c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_rx_mtag); 36016c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_mtag = NULL; 36026c8d8eccSSepherosa Ziehau 36036c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create DMA map for RX\n"); 36046c8d8eccSSepherosa Ziehau return error; 36056c8d8eccSSepherosa Ziehau } 36066c8d8eccSSepherosa Ziehau } 36076c8d8eccSSepherosa Ziehau 36086c8d8eccSSepherosa Ziehau /* 36096c8d8eccSSepherosa Ziehau * Create DMA tag and maps for TX mbufs. 36106c8d8eccSSepherosa Ziehau */ 361166deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) 361266deb1c1SSepherosa Ziehau txmaxsz = IP_MAXPACKET + sizeof(struct ether_vlan_header); 361366deb1c1SSepherosa Ziehau else 361466deb1c1SSepherosa Ziehau txmaxsz = BNX_JUMBO_FRAMELEN; 36156c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0, 36166c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 36176c8d8eccSSepherosa Ziehau NULL, NULL, 361866deb1c1SSepherosa Ziehau txmaxsz, BNX_NSEG_NEW, PAGE_SIZE, 36196c8d8eccSSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK | 36206c8d8eccSSepherosa Ziehau BUS_DMA_ONEBPAGE, 36216c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_tx_mtag); 36226c8d8eccSSepherosa Ziehau if (error) { 36236c8d8eccSSepherosa Ziehau if_printf(ifp, "could not allocate TX mbuf dma tag\n"); 36246c8d8eccSSepherosa Ziehau return error; 36256c8d8eccSSepherosa Ziehau } 36266c8d8eccSSepherosa Ziehau 36276c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 36286c8d8eccSSepherosa Ziehau error = bus_dmamap_create(sc->bnx_cdata.bnx_tx_mtag, 36296c8d8eccSSepherosa Ziehau BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 36306c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_tx_dmamap[i]); 36316c8d8eccSSepherosa Ziehau if (error) { 36326c8d8eccSSepherosa Ziehau int j; 36336c8d8eccSSepherosa Ziehau 36346c8d8eccSSepherosa Ziehau for (j = 0; j < i; ++j) { 36356c8d8eccSSepherosa Ziehau bus_dmamap_destroy(sc->bnx_cdata.bnx_tx_mtag, 36366c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_dmamap[j]); 36376c8d8eccSSepherosa Ziehau } 36386c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_tx_mtag); 36396c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_tx_mtag = NULL; 36406c8d8eccSSepherosa Ziehau 36416c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create DMA map for TX\n"); 36426c8d8eccSSepherosa Ziehau return error; 36436c8d8eccSSepherosa Ziehau } 36446c8d8eccSSepherosa Ziehau } 36456c8d8eccSSepherosa Ziehau 36466c8d8eccSSepherosa Ziehau /* 36476c8d8eccSSepherosa Ziehau * Create DMA stuffs for standard RX ring. 36486c8d8eccSSepherosa Ziehau */ 36496c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STD_RX_RING_SZ, 36506c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_std_ring_tag, 36516c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_std_ring_map, 36526c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_std_ring, 36536c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_std_ring_paddr); 36546c8d8eccSSepherosa Ziehau if (error) { 36556c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create std RX ring\n"); 36566c8d8eccSSepherosa Ziehau return error; 36576c8d8eccSSepherosa Ziehau } 36586c8d8eccSSepherosa Ziehau 36596c8d8eccSSepherosa Ziehau /* 36606c8d8eccSSepherosa Ziehau * Create jumbo buffer pool. 36616c8d8eccSSepherosa Ziehau */ 36626c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 36636c8d8eccSSepherosa Ziehau error = bnx_alloc_jumbo_mem(sc); 36646c8d8eccSSepherosa Ziehau if (error) { 36656c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo buffer pool\n"); 36666c8d8eccSSepherosa Ziehau return error; 36676c8d8eccSSepherosa Ziehau } 36686c8d8eccSSepherosa Ziehau } 36696c8d8eccSSepherosa Ziehau 36706c8d8eccSSepherosa Ziehau /* 36716c8d8eccSSepherosa Ziehau * Create DMA stuffs for RX return ring. 36726c8d8eccSSepherosa Ziehau */ 36736c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, 36746c8d8eccSSepherosa Ziehau BGE_RX_RTN_RING_SZ(sc->bnx_return_ring_cnt), 36756c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_return_ring_tag, 36766c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_return_ring_map, 36776c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_return_ring, 36786c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_return_ring_paddr); 36796c8d8eccSSepherosa Ziehau if (error) { 36806c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create RX ret ring\n"); 36816c8d8eccSSepherosa Ziehau return error; 36826c8d8eccSSepherosa Ziehau } 36836c8d8eccSSepherosa Ziehau 36846c8d8eccSSepherosa Ziehau /* 36856c8d8eccSSepherosa Ziehau * Create DMA stuffs for TX ring. 36866c8d8eccSSepherosa Ziehau */ 36876c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_TX_RING_SZ, 36886c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_tx_ring_tag, 36896c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_tx_ring_map, 36906c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_tx_ring, 36916c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_tx_ring_paddr); 36926c8d8eccSSepherosa Ziehau if (error) { 36936c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create TX ring\n"); 36946c8d8eccSSepherosa Ziehau return error; 36956c8d8eccSSepherosa Ziehau } 36966c8d8eccSSepherosa Ziehau 36976c8d8eccSSepherosa Ziehau /* 36986c8d8eccSSepherosa Ziehau * Create DMA stuffs for status block. 36996c8d8eccSSepherosa Ziehau */ 37006c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STATUS_BLK_SZ, 37016c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_tag, 37026c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_status_map, 37036c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_status_block, 37046c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_status_block_paddr); 37056c8d8eccSSepherosa Ziehau if (error) { 37066c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create status block\n"); 37076c8d8eccSSepherosa Ziehau return error; 37086c8d8eccSSepherosa Ziehau } 37096c8d8eccSSepherosa Ziehau 37106c8d8eccSSepherosa Ziehau return 0; 37116c8d8eccSSepherosa Ziehau } 37126c8d8eccSSepherosa Ziehau 37136c8d8eccSSepherosa Ziehau static int 37146c8d8eccSSepherosa Ziehau bnx_dma_block_alloc(struct bnx_softc *sc, bus_size_t size, bus_dma_tag_t *tag, 37156c8d8eccSSepherosa Ziehau bus_dmamap_t *map, void **addr, bus_addr_t *paddr) 37166c8d8eccSSepherosa Ziehau { 37176c8d8eccSSepherosa Ziehau bus_dmamem_t dmem; 37186c8d8eccSSepherosa Ziehau int error; 37196c8d8eccSSepherosa Ziehau 37206c8d8eccSSepherosa Ziehau error = bus_dmamem_coherent(sc->bnx_cdata.bnx_parent_tag, PAGE_SIZE, 0, 37216c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 37226c8d8eccSSepherosa Ziehau size, BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmem); 37236c8d8eccSSepherosa Ziehau if (error) 37246c8d8eccSSepherosa Ziehau return error; 37256c8d8eccSSepherosa Ziehau 37266c8d8eccSSepherosa Ziehau *tag = dmem.dmem_tag; 37276c8d8eccSSepherosa Ziehau *map = dmem.dmem_map; 37286c8d8eccSSepherosa Ziehau *addr = dmem.dmem_addr; 37296c8d8eccSSepherosa Ziehau *paddr = dmem.dmem_busaddr; 37306c8d8eccSSepherosa Ziehau 37316c8d8eccSSepherosa Ziehau return 0; 37326c8d8eccSSepherosa Ziehau } 37336c8d8eccSSepherosa Ziehau 37346c8d8eccSSepherosa Ziehau static void 37356c8d8eccSSepherosa Ziehau bnx_dma_block_free(bus_dma_tag_t tag, bus_dmamap_t map, void *addr) 37366c8d8eccSSepherosa Ziehau { 37376c8d8eccSSepherosa Ziehau if (tag != NULL) { 37386c8d8eccSSepherosa Ziehau bus_dmamap_unload(tag, map); 37396c8d8eccSSepherosa Ziehau bus_dmamem_free(tag, addr, map); 37406c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(tag); 37416c8d8eccSSepherosa Ziehau } 37426c8d8eccSSepherosa Ziehau } 37436c8d8eccSSepherosa Ziehau 37446c8d8eccSSepherosa Ziehau static void 37456c8d8eccSSepherosa Ziehau bnx_tbi_link_upd(struct bnx_softc *sc, uint32_t status) 37466c8d8eccSSepherosa Ziehau { 37476c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 37486c8d8eccSSepherosa Ziehau 37496c8d8eccSSepherosa Ziehau #define PCS_ENCODE_ERR (BGE_MACSTAT_PORT_DECODE_ERROR|BGE_MACSTAT_MI_COMPLETE) 37506c8d8eccSSepherosa Ziehau 37516c8d8eccSSepherosa Ziehau /* 37526c8d8eccSSepherosa Ziehau * Sometimes PCS encoding errors are detected in 37536c8d8eccSSepherosa Ziehau * TBI mode (on fiber NICs), and for some reason 37546c8d8eccSSepherosa Ziehau * the chip will signal them as link changes. 37556c8d8eccSSepherosa Ziehau * If we get a link change event, but the 'PCS 37566c8d8eccSSepherosa Ziehau * encoding error' bit in the MAC status register 37576c8d8eccSSepherosa Ziehau * is set, don't bother doing a link check. 37586c8d8eccSSepherosa Ziehau * This avoids spurious "gigabit link up" messages 37596c8d8eccSSepherosa Ziehau * that sometimes appear on fiber NICs during 37606c8d8eccSSepherosa Ziehau * periods of heavy traffic. 37616c8d8eccSSepherosa Ziehau */ 37626c8d8eccSSepherosa Ziehau if (status & BGE_MACSTAT_TBI_PCS_SYNCHED) { 37636c8d8eccSSepherosa Ziehau if (!sc->bnx_link) { 37646c8d8eccSSepherosa Ziehau sc->bnx_link++; 37656c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704) { 37666c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 37676c8d8eccSSepherosa Ziehau BGE_MACMODE_TBI_SEND_CFGS); 37686c8d8eccSSepherosa Ziehau } 37696c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, 0xFFFFFFFF); 37706c8d8eccSSepherosa Ziehau 37716c8d8eccSSepherosa Ziehau if (bootverbose) 37726c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 37736c8d8eccSSepherosa Ziehau 37746c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_UP; 37756c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 37766c8d8eccSSepherosa Ziehau } 37776c8d8eccSSepherosa Ziehau } else if ((status & PCS_ENCODE_ERR) != PCS_ENCODE_ERR) { 37786c8d8eccSSepherosa Ziehau if (sc->bnx_link) { 37796c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 37806c8d8eccSSepherosa Ziehau 37816c8d8eccSSepherosa Ziehau if (bootverbose) 37826c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 37836c8d8eccSSepherosa Ziehau 37846c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_DOWN; 37856c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 37866c8d8eccSSepherosa Ziehau } 37876c8d8eccSSepherosa Ziehau } 37886c8d8eccSSepherosa Ziehau 37896c8d8eccSSepherosa Ziehau #undef PCS_ENCODE_ERR 37906c8d8eccSSepherosa Ziehau 37916c8d8eccSSepherosa Ziehau /* Clear the attention. */ 37926c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 37936c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 37946c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 37956c8d8eccSSepherosa Ziehau } 37966c8d8eccSSepherosa Ziehau 37976c8d8eccSSepherosa Ziehau static void 37986c8d8eccSSepherosa Ziehau bnx_copper_link_upd(struct bnx_softc *sc, uint32_t status __unused) 37996c8d8eccSSepherosa Ziehau { 38006c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38016c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 38026c8d8eccSSepherosa Ziehau 38036c8d8eccSSepherosa Ziehau mii_pollstat(mii); 38046c8d8eccSSepherosa Ziehau bnx_miibus_statchg(sc->bnx_dev); 38056c8d8eccSSepherosa Ziehau 38066c8d8eccSSepherosa Ziehau if (bootverbose) { 38076c8d8eccSSepherosa Ziehau if (sc->bnx_link) 38086c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 38096c8d8eccSSepherosa Ziehau else 38106c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 38116c8d8eccSSepherosa Ziehau } 38126c8d8eccSSepherosa Ziehau 38136c8d8eccSSepherosa Ziehau /* Clear the attention. */ 38146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 38156c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 38166c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 38176c8d8eccSSepherosa Ziehau } 38186c8d8eccSSepherosa Ziehau 38196c8d8eccSSepherosa Ziehau static void 38206c8d8eccSSepherosa Ziehau bnx_autopoll_link_upd(struct bnx_softc *sc, uint32_t status __unused) 38216c8d8eccSSepherosa Ziehau { 38226c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38236c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 38246c8d8eccSSepherosa Ziehau 38256c8d8eccSSepherosa Ziehau mii_pollstat(mii); 38266c8d8eccSSepherosa Ziehau 38276c8d8eccSSepherosa Ziehau if (!sc->bnx_link && 38286c8d8eccSSepherosa Ziehau (mii->mii_media_status & IFM_ACTIVE) && 38296c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 38306c8d8eccSSepherosa Ziehau sc->bnx_link++; 38316c8d8eccSSepherosa Ziehau if (bootverbose) 38326c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 38336c8d8eccSSepherosa Ziehau } else if (sc->bnx_link && 38346c8d8eccSSepherosa Ziehau (!(mii->mii_media_status & IFM_ACTIVE) || 38356c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)) { 38366c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 38376c8d8eccSSepherosa Ziehau if (bootverbose) 38386c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 38396c8d8eccSSepherosa Ziehau } 38406c8d8eccSSepherosa Ziehau 38416c8d8eccSSepherosa Ziehau /* Clear the attention. */ 38426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 38436c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 38446c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 38456c8d8eccSSepherosa Ziehau } 38466c8d8eccSSepherosa Ziehau 38476c8d8eccSSepherosa Ziehau static int 38486c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS) 38496c8d8eccSSepherosa Ziehau { 38506c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38516c8d8eccSSepherosa Ziehau 38526c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38536c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_ticks, 38546c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_MIN, BNX_RX_COAL_TICKS_MAX, 38556c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_CHG); 38566c8d8eccSSepherosa Ziehau } 38576c8d8eccSSepherosa Ziehau 38586c8d8eccSSepherosa Ziehau static int 38596c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS) 38606c8d8eccSSepherosa Ziehau { 38616c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38626c8d8eccSSepherosa Ziehau 38636c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38646c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_ticks, 38656c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_MIN, BNX_TX_COAL_TICKS_MAX, 38666c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_CHG); 38676c8d8eccSSepherosa Ziehau } 38686c8d8eccSSepherosa Ziehau 38696c8d8eccSSepherosa Ziehau static int 38706c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS) 38716c8d8eccSSepherosa Ziehau { 38726c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38736c8d8eccSSepherosa Ziehau 38746c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38756c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds, 38766c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 38776c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_CHG); 38786c8d8eccSSepherosa Ziehau } 38796c8d8eccSSepherosa Ziehau 38806c8d8eccSSepherosa Ziehau static int 38816c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS) 38826c8d8eccSSepherosa Ziehau { 38836c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38846c8d8eccSSepherosa Ziehau 38856c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38866c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds, 38876c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 38886c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_CHG); 38896c8d8eccSSepherosa Ziehau } 38906c8d8eccSSepherosa Ziehau 38916c8d8eccSSepherosa Ziehau static int 38926c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS) 38936c8d8eccSSepherosa Ziehau { 38946c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 38956c8d8eccSSepherosa Ziehau 38966c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 38976c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds_int, 38986c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 38996c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_INT_CHG); 39006c8d8eccSSepherosa Ziehau } 39016c8d8eccSSepherosa Ziehau 39026c8d8eccSSepherosa Ziehau static int 39036c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS) 39046c8d8eccSSepherosa Ziehau { 39056c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39066c8d8eccSSepherosa Ziehau 39076c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39086c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds_int, 39096c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 39106c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_INT_CHG); 39116c8d8eccSSepherosa Ziehau } 39126c8d8eccSSepherosa Ziehau 39136c8d8eccSSepherosa Ziehau static int 39146c8d8eccSSepherosa Ziehau bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *coal, 39156c8d8eccSSepherosa Ziehau int coal_min, int coal_max, uint32_t coal_chg_mask) 39166c8d8eccSSepherosa Ziehau { 39176c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39186c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 39196c8d8eccSSepherosa Ziehau int error = 0, v; 39206c8d8eccSSepherosa Ziehau 39216c8d8eccSSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 39226c8d8eccSSepherosa Ziehau 39236c8d8eccSSepherosa Ziehau v = *coal; 39246c8d8eccSSepherosa Ziehau error = sysctl_handle_int(oidp, &v, 0, req); 39256c8d8eccSSepherosa Ziehau if (!error && req->newptr != NULL) { 39266c8d8eccSSepherosa Ziehau if (v < coal_min || v > coal_max) { 39276c8d8eccSSepherosa Ziehau error = EINVAL; 39286c8d8eccSSepherosa Ziehau } else { 39296c8d8eccSSepherosa Ziehau *coal = v; 39306c8d8eccSSepherosa Ziehau sc->bnx_coal_chg |= coal_chg_mask; 39316c8d8eccSSepherosa Ziehau } 39326c8d8eccSSepherosa Ziehau } 39336c8d8eccSSepherosa Ziehau 39346c8d8eccSSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 39356c8d8eccSSepherosa Ziehau return error; 39366c8d8eccSSepherosa Ziehau } 39376c8d8eccSSepherosa Ziehau 39386c8d8eccSSepherosa Ziehau static void 39396c8d8eccSSepherosa Ziehau bnx_coal_change(struct bnx_softc *sc) 39406c8d8eccSSepherosa Ziehau { 39416c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 39426c8d8eccSSepherosa Ziehau uint32_t val; 39436c8d8eccSSepherosa Ziehau 39446c8d8eccSSepherosa Ziehau ASSERT_SERIALIZED(ifp->if_serializer); 39456c8d8eccSSepherosa Ziehau 39466c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_TICKS_CHG) { 39476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, 39486c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 39496c8d8eccSSepherosa Ziehau DELAY(10); 39506c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_RX_COAL_TICKS); 39516c8d8eccSSepherosa Ziehau 39526c8d8eccSSepherosa Ziehau if (bootverbose) { 39536c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_ticks -> %u\n", 39546c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 39556c8d8eccSSepherosa Ziehau } 39566c8d8eccSSepherosa Ziehau } 39576c8d8eccSSepherosa Ziehau 39586c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_TICKS_CHG) { 39596c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, 39606c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 39616c8d8eccSSepherosa Ziehau DELAY(10); 39626c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_TX_COAL_TICKS); 39636c8d8eccSSepherosa Ziehau 39646c8d8eccSSepherosa Ziehau if (bootverbose) { 39656c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_ticks -> %u\n", 39666c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 39676c8d8eccSSepherosa Ziehau } 39686c8d8eccSSepherosa Ziehau } 39696c8d8eccSSepherosa Ziehau 39706c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_CHG) { 39716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, 39726c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 39736c8d8eccSSepherosa Ziehau DELAY(10); 39746c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS); 39756c8d8eccSSepherosa Ziehau 39766c8d8eccSSepherosa Ziehau if (bootverbose) { 39776c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds -> %u\n", 39786c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 39796c8d8eccSSepherosa Ziehau } 39806c8d8eccSSepherosa Ziehau } 39816c8d8eccSSepherosa Ziehau 39826c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_CHG) { 39836c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, 39846c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 39856c8d8eccSSepherosa Ziehau DELAY(10); 39866c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS); 39876c8d8eccSSepherosa Ziehau 39886c8d8eccSSepherosa Ziehau if (bootverbose) { 3989cc98a7c2SSepherosa Ziehau if_printf(ifp, "tx_coal_bds -> %u\n", 39906c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 39916c8d8eccSSepherosa Ziehau } 39926c8d8eccSSepherosa Ziehau } 39936c8d8eccSSepherosa Ziehau 39946c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_INT_CHG) { 39956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, 39966c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 39976c8d8eccSSepherosa Ziehau DELAY(10); 39986c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT); 39996c8d8eccSSepherosa Ziehau 40006c8d8eccSSepherosa Ziehau if (bootverbose) { 40016c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds_int -> %u\n", 40026c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 40036c8d8eccSSepherosa Ziehau } 40046c8d8eccSSepherosa Ziehau } 40056c8d8eccSSepherosa Ziehau 40066c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_INT_CHG) { 40076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, 40086c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 40096c8d8eccSSepherosa Ziehau DELAY(10); 40106c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT); 40116c8d8eccSSepherosa Ziehau 40126c8d8eccSSepherosa Ziehau if (bootverbose) { 40136c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_bds_int -> %u\n", 40146c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 40156c8d8eccSSepherosa Ziehau } 40166c8d8eccSSepherosa Ziehau } 40176c8d8eccSSepherosa Ziehau 40186c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 40196c8d8eccSSepherosa Ziehau } 40206c8d8eccSSepherosa Ziehau 40216c8d8eccSSepherosa Ziehau static void 4022df9ccc98SSepherosa Ziehau bnx_intr_check(void *xsc) 4023df9ccc98SSepherosa Ziehau { 4024df9ccc98SSepherosa Ziehau struct bnx_softc *sc = xsc; 4025df9ccc98SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4026df9ccc98SSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block; 4027df9ccc98SSepherosa Ziehau 4028df9ccc98SSepherosa Ziehau lwkt_serialize_enter(ifp->if_serializer); 4029df9ccc98SSepherosa Ziehau 4030df9ccc98SSepherosa Ziehau KKASSERT(mycpuid == sc->bnx_intr_cpuid); 4031df9ccc98SSepherosa Ziehau 403239a8d43aSSepherosa Ziehau if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) { 4033df9ccc98SSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 4034df9ccc98SSepherosa Ziehau return; 4035df9ccc98SSepherosa Ziehau } 4036df9ccc98SSepherosa Ziehau 4037df9ccc98SSepherosa Ziehau if (sblk->bge_idx[0].bge_rx_prod_idx != sc->bnx_rx_saved_considx || 4038df9ccc98SSepherosa Ziehau sblk->bge_idx[0].bge_tx_cons_idx != sc->bnx_tx_saved_considx) { 4039df9ccc98SSepherosa Ziehau if (sc->bnx_rx_check_considx == sc->bnx_rx_saved_considx && 4040df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx == sc->bnx_tx_saved_considx) { 4041df9ccc98SSepherosa Ziehau if (!sc->bnx_intr_maylose) { 4042df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = TRUE; 4043df9ccc98SSepherosa Ziehau goto done; 4044df9ccc98SSepherosa Ziehau } 4045df9ccc98SSepherosa Ziehau if (bootverbose) 4046df9ccc98SSepherosa Ziehau if_printf(ifp, "lost interrupt\n"); 4047df9ccc98SSepherosa Ziehau bnx_msi(sc); 4048df9ccc98SSepherosa Ziehau } 4049df9ccc98SSepherosa Ziehau } 4050df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 4051df9ccc98SSepherosa Ziehau sc->bnx_rx_check_considx = sc->bnx_rx_saved_considx; 4052df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx = sc->bnx_tx_saved_considx; 4053df9ccc98SSepherosa Ziehau 4054df9ccc98SSepherosa Ziehau done: 4055df9ccc98SSepherosa Ziehau callout_reset(&sc->bnx_intr_timer, BNX_INTR_CKINTVL, 4056df9ccc98SSepherosa Ziehau bnx_intr_check, sc); 4057df9ccc98SSepherosa Ziehau lwkt_serialize_exit(ifp->if_serializer); 4058df9ccc98SSepherosa Ziehau } 4059df9ccc98SSepherosa Ziehau 4060df9ccc98SSepherosa Ziehau static void 40616c8d8eccSSepherosa Ziehau bnx_enable_intr(struct bnx_softc *sc) 40626c8d8eccSSepherosa Ziehau { 40636c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 40646c8d8eccSSepherosa Ziehau 40656c8d8eccSSepherosa Ziehau lwkt_serialize_handler_enable(ifp->if_serializer); 40666c8d8eccSSepherosa Ziehau 40676c8d8eccSSepherosa Ziehau /* 40686c8d8eccSSepherosa Ziehau * Enable interrupt. 40696c8d8eccSSepherosa Ziehau */ 40706c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 40716c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 40726c8d8eccSSepherosa Ziehau /* XXX Linux driver */ 40736c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24); 40746c8d8eccSSepherosa Ziehau } 40756c8d8eccSSepherosa Ziehau 40766c8d8eccSSepherosa Ziehau /* 40776c8d8eccSSepherosa Ziehau * Unmask the interrupt when we stop polling. 40786c8d8eccSSepherosa Ziehau */ 40796c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 40806c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 40816c8d8eccSSepherosa Ziehau 40826c8d8eccSSepherosa Ziehau /* 40836c8d8eccSSepherosa Ziehau * Trigger another interrupt, since above writing 40846c8d8eccSSepherosa Ziehau * to interrupt mailbox0 may acknowledge pending 40856c8d8eccSSepherosa Ziehau * interrupt. 40866c8d8eccSSepherosa Ziehau */ 40876c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET); 4088df9ccc98SSepherosa Ziehau 4089df9ccc98SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_STATUSTAG_BUG) { 4090df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 4091df9ccc98SSepherosa Ziehau sc->bnx_rx_check_considx = 0; 4092df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx = 0; 4093df9ccc98SSepherosa Ziehau 4094df9ccc98SSepherosa Ziehau if (bootverbose) 4095df9ccc98SSepherosa Ziehau if_printf(ifp, "status tag bug workaround\n"); 4096df9ccc98SSepherosa Ziehau 4097df9ccc98SSepherosa Ziehau /* 10ms check interval */ 4098df9ccc98SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_intr_timer, BNX_INTR_CKINTVL, 4099df9ccc98SSepherosa Ziehau bnx_intr_check, sc, sc->bnx_intr_cpuid); 4100df9ccc98SSepherosa Ziehau } 41016c8d8eccSSepherosa Ziehau } 41026c8d8eccSSepherosa Ziehau 41036c8d8eccSSepherosa Ziehau static void 41046c8d8eccSSepherosa Ziehau bnx_disable_intr(struct bnx_softc *sc) 41056c8d8eccSSepherosa Ziehau { 41066c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 41076c8d8eccSSepherosa Ziehau 41086c8d8eccSSepherosa Ziehau /* 41096c8d8eccSSepherosa Ziehau * Mask the interrupt when we start polling. 41106c8d8eccSSepherosa Ziehau */ 41116c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 41126c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 41136c8d8eccSSepherosa Ziehau 41146c8d8eccSSepherosa Ziehau /* 41156c8d8eccSSepherosa Ziehau * Acknowledge possible asserted interrupt. 41166c8d8eccSSepherosa Ziehau */ 41176c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 41186c8d8eccSSepherosa Ziehau 4119df9ccc98SSepherosa Ziehau callout_stop(&sc->bnx_intr_timer); 4120df9ccc98SSepherosa Ziehau sc->bnx_intr_maylose = FALSE; 4121df9ccc98SSepherosa Ziehau sc->bnx_rx_check_considx = 0; 4122df9ccc98SSepherosa Ziehau sc->bnx_tx_check_considx = 0; 4123df9ccc98SSepherosa Ziehau 4124b5de76b1SSepherosa Ziehau sc->bnx_npoll.ifpc_stcount = 0; 412539a8d43aSSepherosa Ziehau 41266c8d8eccSSepherosa Ziehau lwkt_serialize_handler_disable(ifp->if_serializer); 41276c8d8eccSSepherosa Ziehau } 41286c8d8eccSSepherosa Ziehau 41296c8d8eccSSepherosa Ziehau static int 41306c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem(struct bnx_softc *sc, uint8_t ether_addr[]) 41316c8d8eccSSepherosa Ziehau { 41326c8d8eccSSepherosa Ziehau uint32_t mac_addr; 41336c8d8eccSSepherosa Ziehau int ret = 1; 41346c8d8eccSSepherosa Ziehau 41356c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c14); 41366c8d8eccSSepherosa Ziehau if ((mac_addr >> 16) == 0x484b) { 41376c8d8eccSSepherosa Ziehau ether_addr[0] = (uint8_t)(mac_addr >> 8); 41386c8d8eccSSepherosa Ziehau ether_addr[1] = (uint8_t)mac_addr; 41396c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c18); 41406c8d8eccSSepherosa Ziehau ether_addr[2] = (uint8_t)(mac_addr >> 24); 41416c8d8eccSSepherosa Ziehau ether_addr[3] = (uint8_t)(mac_addr >> 16); 41426c8d8eccSSepherosa Ziehau ether_addr[4] = (uint8_t)(mac_addr >> 8); 41436c8d8eccSSepherosa Ziehau ether_addr[5] = (uint8_t)mac_addr; 41446c8d8eccSSepherosa Ziehau ret = 0; 41456c8d8eccSSepherosa Ziehau } 41466c8d8eccSSepherosa Ziehau return ret; 41476c8d8eccSSepherosa Ziehau } 41486c8d8eccSSepherosa Ziehau 41496c8d8eccSSepherosa Ziehau static int 41506c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram(struct bnx_softc *sc, uint8_t ether_addr[]) 41516c8d8eccSSepherosa Ziehau { 41526c8d8eccSSepherosa Ziehau int mac_offset = BGE_EE_MAC_OFFSET; 41536c8d8eccSSepherosa Ziehau 415480969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 415580969639SSepherosa Ziehau int f; 415680969639SSepherosa Ziehau 415780969639SSepherosa Ziehau f = pci_get_function(sc->bnx_dev); 415880969639SSepherosa Ziehau if (f & 1) 415980969639SSepherosa Ziehau mac_offset = BGE_EE_MAC_OFFSET_5717; 416080969639SSepherosa Ziehau if (f > 1) 416180969639SSepherosa Ziehau mac_offset += BGE_EE_MAC_OFFSET_5717_OFF; 416280969639SSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5906) { 41636c8d8eccSSepherosa Ziehau mac_offset = BGE_EE_MAC_OFFSET_5906; 416480969639SSepherosa Ziehau } 41656c8d8eccSSepherosa Ziehau 41666c8d8eccSSepherosa Ziehau return bnx_read_nvram(sc, ether_addr, mac_offset + 2, ETHER_ADDR_LEN); 41676c8d8eccSSepherosa Ziehau } 41686c8d8eccSSepherosa Ziehau 41696c8d8eccSSepherosa Ziehau static int 41706c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom(struct bnx_softc *sc, uint8_t ether_addr[]) 41716c8d8eccSSepherosa Ziehau { 41726c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_NO_EEPROM) 41736c8d8eccSSepherosa Ziehau return 1; 41746c8d8eccSSepherosa Ziehau 41756c8d8eccSSepherosa Ziehau return bnx_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2, 41766c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN); 41776c8d8eccSSepherosa Ziehau } 41786c8d8eccSSepherosa Ziehau 41796c8d8eccSSepherosa Ziehau static int 41806c8d8eccSSepherosa Ziehau bnx_get_eaddr(struct bnx_softc *sc, uint8_t eaddr[]) 41816c8d8eccSSepherosa Ziehau { 41826c8d8eccSSepherosa Ziehau static const bnx_eaddr_fcn_t bnx_eaddr_funcs[] = { 41836c8d8eccSSepherosa Ziehau /* NOTE: Order is critical */ 41846c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem, 41856c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram, 41866c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom, 41876c8d8eccSSepherosa Ziehau NULL 41886c8d8eccSSepherosa Ziehau }; 41896c8d8eccSSepherosa Ziehau const bnx_eaddr_fcn_t *func; 41906c8d8eccSSepherosa Ziehau 41916c8d8eccSSepherosa Ziehau for (func = bnx_eaddr_funcs; *func != NULL; ++func) { 41926c8d8eccSSepherosa Ziehau if ((*func)(sc, eaddr) == 0) 41936c8d8eccSSepherosa Ziehau break; 41946c8d8eccSSepherosa Ziehau } 41956c8d8eccSSepherosa Ziehau return (*func == NULL ? ENXIO : 0); 41966c8d8eccSSepherosa Ziehau } 41976c8d8eccSSepherosa Ziehau 41986c8d8eccSSepherosa Ziehau /* 41996c8d8eccSSepherosa Ziehau * NOTE: 'm' is not freed upon failure 42006c8d8eccSSepherosa Ziehau */ 42016c8d8eccSSepherosa Ziehau struct mbuf * 42026c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *m) 42036c8d8eccSSepherosa Ziehau { 42046c8d8eccSSepherosa Ziehau struct mbuf *n; 42056c8d8eccSSepherosa Ziehau int found; 42066c8d8eccSSepherosa Ziehau 42076c8d8eccSSepherosa Ziehau /* 42086c8d8eccSSepherosa Ziehau * If device receive two back-to-back send BDs with less than 42096c8d8eccSSepherosa Ziehau * or equal to 8 total bytes then the device may hang. The two 42106c8d8eccSSepherosa Ziehau * back-to-back send BDs must in the same frame for this failure 42116c8d8eccSSepherosa Ziehau * to occur. Scan mbuf chains and see whether two back-to-back 42126c8d8eccSSepherosa Ziehau * send BDs are there. If this is the case, allocate new mbuf 42136c8d8eccSSepherosa Ziehau * and copy the frame to workaround the silicon bug. 42146c8d8eccSSepherosa Ziehau */ 42156c8d8eccSSepherosa Ziehau for (n = m, found = 0; n != NULL; n = n->m_next) { 42166c8d8eccSSepherosa Ziehau if (n->m_len < 8) { 42176c8d8eccSSepherosa Ziehau found++; 42186c8d8eccSSepherosa Ziehau if (found > 1) 42196c8d8eccSSepherosa Ziehau break; 42206c8d8eccSSepherosa Ziehau continue; 42216c8d8eccSSepherosa Ziehau } 42226c8d8eccSSepherosa Ziehau found = 0; 42236c8d8eccSSepherosa Ziehau } 42246c8d8eccSSepherosa Ziehau 42256c8d8eccSSepherosa Ziehau if (found > 1) 42266c8d8eccSSepherosa Ziehau n = m_defrag(m, MB_DONTWAIT); 42276c8d8eccSSepherosa Ziehau else 42286c8d8eccSSepherosa Ziehau n = m; 42296c8d8eccSSepherosa Ziehau return n; 42306c8d8eccSSepherosa Ziehau } 42316c8d8eccSSepherosa Ziehau 42326c8d8eccSSepherosa Ziehau static void 42336c8d8eccSSepherosa Ziehau bnx_stop_block(struct bnx_softc *sc, bus_size_t reg, uint32_t bit) 42346c8d8eccSSepherosa Ziehau { 42356c8d8eccSSepherosa Ziehau int i; 42366c8d8eccSSepherosa Ziehau 42376c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, reg, bit); 42386c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 42396c8d8eccSSepherosa Ziehau if ((CSR_READ_4(sc, reg) & bit) == 0) 42406c8d8eccSSepherosa Ziehau return; 42416c8d8eccSSepherosa Ziehau DELAY(100); 42426c8d8eccSSepherosa Ziehau } 42436c8d8eccSSepherosa Ziehau } 42446c8d8eccSSepherosa Ziehau 42456c8d8eccSSepherosa Ziehau static void 42466c8d8eccSSepherosa Ziehau bnx_link_poll(struct bnx_softc *sc) 42476c8d8eccSSepherosa Ziehau { 42486c8d8eccSSepherosa Ziehau uint32_t status; 42496c8d8eccSSepherosa Ziehau 42506c8d8eccSSepherosa Ziehau status = CSR_READ_4(sc, BGE_MAC_STS); 42516c8d8eccSSepherosa Ziehau if ((status & sc->bnx_link_chg) || sc->bnx_link_evt) { 42526c8d8eccSSepherosa Ziehau sc->bnx_link_evt = 0; 42536c8d8eccSSepherosa Ziehau sc->bnx_link_upd(sc, status); 42546c8d8eccSSepherosa Ziehau } 42556c8d8eccSSepherosa Ziehau } 42566c8d8eccSSepherosa Ziehau 42576c8d8eccSSepherosa Ziehau static void 42586c8d8eccSSepherosa Ziehau bnx_enable_msi(struct bnx_softc *sc) 42596c8d8eccSSepherosa Ziehau { 42606c8d8eccSSepherosa Ziehau uint32_t msi_mode; 42616c8d8eccSSepherosa Ziehau 42626c8d8eccSSepherosa Ziehau msi_mode = CSR_READ_4(sc, BGE_MSI_MODE); 42636c8d8eccSSepherosa Ziehau msi_mode |= BGE_MSIMODE_ENABLE; 42646c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) { 42656c8d8eccSSepherosa Ziehau /* 42666c8d8eccSSepherosa Ziehau * NOTE: 42676c8d8eccSSepherosa Ziehau * 5718-PG105-R says that "one shot" mode 42686c8d8eccSSepherosa Ziehau * does not work if MSI is used, however, 42696c8d8eccSSepherosa Ziehau * it obviously works. 42706c8d8eccSSepherosa Ziehau */ 42716c8d8eccSSepherosa Ziehau msi_mode &= ~BGE_MSIMODE_ONESHOT_DISABLE; 42726c8d8eccSSepherosa Ziehau } 42736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MSI_MODE, msi_mode); 42746c8d8eccSSepherosa Ziehau } 42756c8d8eccSSepherosa Ziehau 42766c8d8eccSSepherosa Ziehau static uint32_t 42776c8d8eccSSepherosa Ziehau bnx_dma_swap_options(struct bnx_softc *sc) 42786c8d8eccSSepherosa Ziehau { 42796c8d8eccSSepherosa Ziehau uint32_t dma_options; 42806c8d8eccSSepherosa Ziehau 42816c8d8eccSSepherosa Ziehau dma_options = BGE_MODECTL_WORDSWAP_NONFRAME | 42826c8d8eccSSepherosa Ziehau BGE_MODECTL_BYTESWAP_DATA | BGE_MODECTL_WORDSWAP_DATA; 42836c8d8eccSSepherosa Ziehau #if BYTE_ORDER == BIG_ENDIAN 42846c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_NONFRAME; 42856c8d8eccSSepherosa Ziehau #endif 42866c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 42876c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA | 42886c8d8eccSSepherosa Ziehau BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE | 42896c8d8eccSSepherosa Ziehau BGE_MODECTL_HTX2B_ENABLE; 42906c8d8eccSSepherosa Ziehau } 42916c8d8eccSSepherosa Ziehau return dma_options; 42926c8d8eccSSepherosa Ziehau } 429366deb1c1SSepherosa Ziehau 429466deb1c1SSepherosa Ziehau static int 429566deb1c1SSepherosa Ziehau bnx_setup_tso(struct bnx_softc *sc, struct mbuf **mp, 429666deb1c1SSepherosa Ziehau uint16_t *mss0, uint16_t *flags0) 429766deb1c1SSepherosa Ziehau { 429866deb1c1SSepherosa Ziehau struct mbuf *m; 429966deb1c1SSepherosa Ziehau struct ip *ip; 430066deb1c1SSepherosa Ziehau struct tcphdr *th; 430166deb1c1SSepherosa Ziehau int thoff, iphlen, hoff, hlen; 430266deb1c1SSepherosa Ziehau uint16_t flags, mss; 430366deb1c1SSepherosa Ziehau 4304f7a2269aSSepherosa Ziehau m = *mp; 4305f7a2269aSSepherosa Ziehau KASSERT(M_WRITABLE(m), ("TSO mbuf not writable")); 4306f7a2269aSSepherosa Ziehau 4307f7a2269aSSepherosa Ziehau hoff = m->m_pkthdr.csum_lhlen; 4308f7a2269aSSepherosa Ziehau iphlen = m->m_pkthdr.csum_iphlen; 4309f7a2269aSSepherosa Ziehau thoff = m->m_pkthdr.csum_thlen; 4310f7a2269aSSepherosa Ziehau 4311f7a2269aSSepherosa Ziehau KASSERT(hoff > 0, ("invalid ether header len")); 4312f7a2269aSSepherosa Ziehau KASSERT(iphlen > 0, ("invalid ip header len")); 4313f7a2269aSSepherosa Ziehau KASSERT(thoff > 0, ("invalid tcp header len")); 4314f7a2269aSSepherosa Ziehau 4315f7a2269aSSepherosa Ziehau if (__predict_false(m->m_len < hoff + iphlen + thoff)) { 4316f7a2269aSSepherosa Ziehau m = m_pullup(m, hoff + iphlen + thoff); 4317f7a2269aSSepherosa Ziehau if (m == NULL) { 4318f7a2269aSSepherosa Ziehau *mp = NULL; 4319f7a2269aSSepherosa Ziehau return ENOBUFS; 4320f7a2269aSSepherosa Ziehau } 4321f7a2269aSSepherosa Ziehau *mp = m; 4322f7a2269aSSepherosa Ziehau } 4323f7a2269aSSepherosa Ziehau ip = mtodoff(m, struct ip *, hoff); 4324f7a2269aSSepherosa Ziehau th = mtodoff(m, struct tcphdr *, hoff + iphlen); 4325f7a2269aSSepherosa Ziehau 4326f0336d39SSepherosa Ziehau mss = m->m_pkthdr.tso_segsz; 432766deb1c1SSepherosa Ziehau flags = BGE_TXBDFLAG_CPU_PRE_DMA | BGE_TXBDFLAG_CPU_POST_DMA; 432866deb1c1SSepherosa Ziehau 432966deb1c1SSepherosa Ziehau ip->ip_len = htons(mss + iphlen + thoff); 433066deb1c1SSepherosa Ziehau th->th_sum = 0; 433166deb1c1SSepherosa Ziehau 433266deb1c1SSepherosa Ziehau hlen = (iphlen + thoff) >> 2; 433366deb1c1SSepherosa Ziehau mss |= ((hlen & 0x3) << 14); 433466deb1c1SSepherosa Ziehau flags |= ((hlen & 0xf8) << 7) | ((hlen & 0x4) << 2); 433566deb1c1SSepherosa Ziehau 433666deb1c1SSepherosa Ziehau *mss0 = mss; 433766deb1c1SSepherosa Ziehau *flags0 = flags; 433866deb1c1SSepherosa Ziehau 433966deb1c1SSepherosa Ziehau return 0; 434066deb1c1SSepherosa Ziehau } 4341