16c8d8eccSSepherosa Ziehau /* 26c8d8eccSSepherosa Ziehau * Copyright (c) 2001 Wind River Systems 36c8d8eccSSepherosa Ziehau * Copyright (c) 1997, 1998, 1999, 2001 46c8d8eccSSepherosa Ziehau * Bill Paul <wpaul@windriver.com>. All rights reserved. 56c8d8eccSSepherosa Ziehau * 66c8d8eccSSepherosa Ziehau * Redistribution and use in source and binary forms, with or without 76c8d8eccSSepherosa Ziehau * modification, are permitted provided that the following conditions 86c8d8eccSSepherosa Ziehau * are met: 96c8d8eccSSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright 106c8d8eccSSepherosa Ziehau * notice, this list of conditions and the following disclaimer. 116c8d8eccSSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright 126c8d8eccSSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the 136c8d8eccSSepherosa Ziehau * documentation and/or other materials provided with the distribution. 146c8d8eccSSepherosa Ziehau * 3. All advertising materials mentioning features or use of this software 156c8d8eccSSepherosa Ziehau * must display the following acknowledgement: 166c8d8eccSSepherosa Ziehau * This product includes software developed by Bill Paul. 176c8d8eccSSepherosa Ziehau * 4. Neither the name of the author nor the names of any co-contributors 186c8d8eccSSepherosa Ziehau * may be used to endorse or promote products derived from this software 196c8d8eccSSepherosa Ziehau * without specific prior written permission. 206c8d8eccSSepherosa Ziehau * 216c8d8eccSSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 226c8d8eccSSepherosa Ziehau * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 236c8d8eccSSepherosa Ziehau * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 246c8d8eccSSepherosa Ziehau * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 256c8d8eccSSepherosa Ziehau * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 266c8d8eccSSepherosa Ziehau * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 276c8d8eccSSepherosa Ziehau * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 286c8d8eccSSepherosa Ziehau * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 296c8d8eccSSepherosa Ziehau * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 306c8d8eccSSepherosa Ziehau * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 316c8d8eccSSepherosa Ziehau * THE POSSIBILITY OF SUCH DAMAGE. 326c8d8eccSSepherosa Ziehau * 336c8d8eccSSepherosa Ziehau * $FreeBSD: src/sys/dev/bge/if_bge.c,v 1.3.2.39 2005/07/03 03:41:18 silby Exp $ 346c8d8eccSSepherosa Ziehau */ 356c8d8eccSSepherosa Ziehau 3666deb1c1SSepherosa Ziehau #include "opt_bnx.h" 3739a8d43aSSepherosa Ziehau #include "opt_ifpoll.h" 386c8d8eccSSepherosa Ziehau 396c8d8eccSSepherosa Ziehau #include <sys/param.h> 406c8d8eccSSepherosa Ziehau #include <sys/bus.h> 416c8d8eccSSepherosa Ziehau #include <sys/endian.h> 426c8d8eccSSepherosa Ziehau #include <sys/kernel.h> 436c8d8eccSSepherosa Ziehau #include <sys/interrupt.h> 446c8d8eccSSepherosa Ziehau #include <sys/mbuf.h> 456c8d8eccSSepherosa Ziehau #include <sys/malloc.h> 466c8d8eccSSepherosa Ziehau #include <sys/queue.h> 476c8d8eccSSepherosa Ziehau #include <sys/rman.h> 486c8d8eccSSepherosa Ziehau #include <sys/serialize.h> 496c8d8eccSSepherosa Ziehau #include <sys/socket.h> 506c8d8eccSSepherosa Ziehau #include <sys/sockio.h> 516c8d8eccSSepherosa Ziehau #include <sys/sysctl.h> 526c8d8eccSSepherosa Ziehau 5366deb1c1SSepherosa Ziehau #include <netinet/ip.h> 5466deb1c1SSepherosa Ziehau #include <netinet/tcp.h> 5566deb1c1SSepherosa Ziehau 566c8d8eccSSepherosa Ziehau #include <net/bpf.h> 576c8d8eccSSepherosa Ziehau #include <net/ethernet.h> 586c8d8eccSSepherosa Ziehau #include <net/if.h> 596c8d8eccSSepherosa Ziehau #include <net/if_arp.h> 606c8d8eccSSepherosa Ziehau #include <net/if_dl.h> 616c8d8eccSSepherosa Ziehau #include <net/if_media.h> 6239a8d43aSSepherosa Ziehau #include <net/if_poll.h> 636c8d8eccSSepherosa Ziehau #include <net/if_types.h> 646c8d8eccSSepherosa Ziehau #include <net/ifq_var.h> 656c8d8eccSSepherosa Ziehau #include <net/vlan/if_vlan_var.h> 666c8d8eccSSepherosa Ziehau #include <net/vlan/if_vlan_ether.h> 676c8d8eccSSepherosa Ziehau 686c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/mii.h> 696c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/miivar.h> 706c8d8eccSSepherosa Ziehau #include <dev/netif/mii_layer/brgphyreg.h> 716c8d8eccSSepherosa Ziehau 726c8d8eccSSepherosa Ziehau #include <bus/pci/pcidevs.h> 736c8d8eccSSepherosa Ziehau #include <bus/pci/pcireg.h> 746c8d8eccSSepherosa Ziehau #include <bus/pci/pcivar.h> 756c8d8eccSSepherosa Ziehau 766c8d8eccSSepherosa Ziehau #include <dev/netif/bge/if_bgereg.h> 776c8d8eccSSepherosa Ziehau #include <dev/netif/bnx/if_bnxvar.h> 786c8d8eccSSepherosa Ziehau 796c8d8eccSSepherosa Ziehau /* "device miibus" required. See GENERIC if you get errors here. */ 806c8d8eccSSepherosa Ziehau #include "miibus_if.h" 816c8d8eccSSepherosa Ziehau 823b18363fSSepherosa Ziehau #define BNX_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) 836c8d8eccSSepherosa Ziehau 84df9ccc98SSepherosa Ziehau #define BNX_INTR_CKINTVL ((10 * hz) / 1000) /* 10ms */ 85df9ccc98SSepherosa Ziehau 866c8d8eccSSepherosa Ziehau static const struct bnx_type { 876c8d8eccSSepherosa Ziehau uint16_t bnx_vid; 886c8d8eccSSepherosa Ziehau uint16_t bnx_did; 896c8d8eccSSepherosa Ziehau char *bnx_name; 906c8d8eccSSepherosa Ziehau } bnx_devs[] = { 916c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717, 926c8d8eccSSepherosa Ziehau "Broadcom BCM5717 Gigabit Ethernet" }, 93d79f5d8fSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717C, 94d79f5d8fSSepherosa Ziehau "Broadcom BCM5717C Gigabit Ethernet" }, 956c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5718, 966c8d8eccSSepherosa Ziehau "Broadcom BCM5718 Gigabit Ethernet" }, 976c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5719, 986c8d8eccSSepherosa Ziehau "Broadcom BCM5719 Gigabit Ethernet" }, 996c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5720_ALT, 1006c8d8eccSSepherosa Ziehau "Broadcom BCM5720 Gigabit Ethernet" }, 1016c8d8eccSSepherosa Ziehau 102b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5725, 103b96cbbb6SSepherosa Ziehau "Broadcom BCM5725 Gigabit Ethernet" }, 104b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5727, 105b96cbbb6SSepherosa Ziehau "Broadcom BCM5727 Gigabit Ethernet" }, 106b96cbbb6SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5762, 107b96cbbb6SSepherosa Ziehau "Broadcom BCM5762 Gigabit Ethernet" }, 108b96cbbb6SSepherosa Ziehau 1096c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57761, 1106c8d8eccSSepherosa Ziehau "Broadcom BCM57761 Gigabit Ethernet" }, 11132ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57762, 11232ff3c80SSepherosa Ziehau "Broadcom BCM57762 Gigabit Ethernet" }, 1136c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57765, 1146c8d8eccSSepherosa Ziehau "Broadcom BCM57765 Gigabit Ethernet" }, 11532ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57766, 11632ff3c80SSepherosa Ziehau "Broadcom BCM57766 Gigabit Ethernet" }, 11732ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57781, 11832ff3c80SSepherosa Ziehau "Broadcom BCM57781 Gigabit Ethernet" }, 11932ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57782, 12032ff3c80SSepherosa Ziehau "Broadcom BCM57782 Gigabit Ethernet" }, 1216c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57785, 1226c8d8eccSSepherosa Ziehau "Broadcom BCM57785 Gigabit Ethernet" }, 12332ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57786, 12432ff3c80SSepherosa Ziehau "Broadcom BCM57786 Gigabit Ethernet" }, 12532ff3c80SSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57791, 12632ff3c80SSepherosa Ziehau "Broadcom BCM57791 Fast Ethernet" }, 1276c8d8eccSSepherosa Ziehau { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57795, 1286c8d8eccSSepherosa Ziehau "Broadcom BCM57795 Fast Ethernet" }, 1296c8d8eccSSepherosa Ziehau 1306c8d8eccSSepherosa Ziehau { 0, 0, NULL } 1316c8d8eccSSepherosa Ziehau }; 1326c8d8eccSSepherosa Ziehau 1331c9d03f6SSepherosa Ziehau static const int bnx_tx_mailbox[BNX_TX_RING_MAX] = { 1341c9d03f6SSepherosa Ziehau BGE_MBX_TX_HOST_PROD0_LO, 1351c9d03f6SSepherosa Ziehau BGE_MBX_TX_HOST_PROD0_HI, 1361c9d03f6SSepherosa Ziehau BGE_MBX_TX_HOST_PROD1_LO, 1371c9d03f6SSepherosa Ziehau BGE_MBX_TX_HOST_PROD1_HI 1381c9d03f6SSepherosa Ziehau }; 1391c9d03f6SSepherosa Ziehau 1406c8d8eccSSepherosa Ziehau #define BNX_IS_JUMBO_CAPABLE(sc) ((sc)->bnx_flags & BNX_FLAG_JUMBO) 1416c8d8eccSSepherosa Ziehau #define BNX_IS_5717_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_5717_PLUS) 142f368d0d9SSepherosa Ziehau #define BNX_IS_57765_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_57765_PLUS) 143f368d0d9SSepherosa Ziehau #define BNX_IS_57765_FAMILY(sc) \ 144f368d0d9SSepherosa Ziehau ((sc)->bnx_flags & BNX_FLAG_57765_FAMILY) 1456c8d8eccSSepherosa Ziehau 1466c8d8eccSSepherosa Ziehau typedef int (*bnx_eaddr_fcn_t)(struct bnx_softc *, uint8_t[]); 1476c8d8eccSSepherosa Ziehau 1486c8d8eccSSepherosa Ziehau static int bnx_probe(device_t); 1496c8d8eccSSepherosa Ziehau static int bnx_attach(device_t); 1506c8d8eccSSepherosa Ziehau static int bnx_detach(device_t); 1516c8d8eccSSepherosa Ziehau static void bnx_shutdown(device_t); 1526c8d8eccSSepherosa Ziehau static int bnx_suspend(device_t); 1536c8d8eccSSepherosa Ziehau static int bnx_resume(device_t); 1546c8d8eccSSepherosa Ziehau static int bnx_miibus_readreg(device_t, int, int); 1556c8d8eccSSepherosa Ziehau static int bnx_miibus_writereg(device_t, int, int, int); 1566c8d8eccSSepherosa Ziehau static void bnx_miibus_statchg(device_t); 1576c8d8eccSSepherosa Ziehau 15839a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 15939a8d43aSSepherosa Ziehau static void bnx_npoll(struct ifnet *, struct ifpoll_info *); 1604fa38985SSepherosa Ziehau static void bnx_npoll_rx(struct ifnet *, void *, int); 1614fa38985SSepherosa Ziehau static void bnx_npoll_tx(struct ifnet *, void *, int); 1624fa38985SSepherosa Ziehau static void bnx_npoll_status(struct ifnet *); 1636c8d8eccSSepherosa Ziehau #endif 1646c8d8eccSSepherosa Ziehau static void bnx_intr_legacy(void *); 1656c8d8eccSSepherosa Ziehau static void bnx_msi_oneshot(void *); 1666c8d8eccSSepherosa Ziehau static void bnx_intr(struct bnx_softc *); 1676c8d8eccSSepherosa Ziehau static void bnx_enable_intr(struct bnx_softc *); 1686c8d8eccSSepherosa Ziehau static void bnx_disable_intr(struct bnx_softc *); 16933a04907SSepherosa Ziehau static void bnx_txeof(struct bnx_tx_ring *, uint16_t); 170beedf5beSSepherosa Ziehau static void bnx_rxeof(struct bnx_rx_ret_ring *, uint16_t, int); 1710c7da01dSSepherosa Ziehau static int bnx_alloc_intr(struct bnx_softc *); 1720c7da01dSSepherosa Ziehau static int bnx_setup_intr(struct bnx_softc *); 1730c7da01dSSepherosa Ziehau static void bnx_free_intr(struct bnx_softc *); 174f33ac8a4SSepherosa Ziehau static void bnx_teardown_intr(struct bnx_softc *, int); 175f33ac8a4SSepherosa Ziehau static void bnx_check_intr(void *); 176841cdf08SSepherosa Ziehau static void bnx_rx_std_refill_ithread(void *); 177841cdf08SSepherosa Ziehau static void bnx_rx_std_refill(void *, void *); 1786c8d8eccSSepherosa Ziehau 179f0a26983SSepherosa Ziehau static void bnx_start(struct ifnet *, struct ifaltq_subque *); 1806c8d8eccSSepherosa Ziehau static int bnx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); 1816c8d8eccSSepherosa Ziehau static void bnx_init(void *); 1826c8d8eccSSepherosa Ziehau static void bnx_stop(struct bnx_softc *); 1833397dea6SSepherosa Ziehau static void bnx_watchdog(struct ifaltq_subque *); 1846c8d8eccSSepherosa Ziehau static int bnx_ifmedia_upd(struct ifnet *); 1856c8d8eccSSepherosa Ziehau static void bnx_ifmedia_sts(struct ifnet *, struct ifmediareq *); 1866c8d8eccSSepherosa Ziehau static void bnx_tick(void *); 187329f9016SSepherosa Ziehau static void bnx_serialize(struct ifnet *, enum ifnet_serialize); 188329f9016SSepherosa Ziehau static void bnx_deserialize(struct ifnet *, enum ifnet_serialize); 189329f9016SSepherosa Ziehau static int bnx_tryserialize(struct ifnet *, enum ifnet_serialize); 190329f9016SSepherosa Ziehau #ifdef INVARIANTS 191329f9016SSepherosa Ziehau static void bnx_serialize_assert(struct ifnet *, enum ifnet_serialize, 192329f9016SSepherosa Ziehau boolean_t); 193329f9016SSepherosa Ziehau #endif 1946c8d8eccSSepherosa Ziehau 1956c8d8eccSSepherosa Ziehau static int bnx_alloc_jumbo_mem(struct bnx_softc *); 1966c8d8eccSSepherosa Ziehau static void bnx_free_jumbo_mem(struct bnx_softc *); 1976c8d8eccSSepherosa Ziehau static struct bnx_jslot 1986c8d8eccSSepherosa Ziehau *bnx_jalloc(struct bnx_softc *); 1996c8d8eccSSepherosa Ziehau static void bnx_jfree(void *); 2006c8d8eccSSepherosa Ziehau static void bnx_jref(void *); 201beedf5beSSepherosa Ziehau static int bnx_newbuf_std(struct bnx_rx_ret_ring *, int, int); 2026c8d8eccSSepherosa Ziehau static int bnx_newbuf_jumbo(struct bnx_softc *, int, int); 203beedf5beSSepherosa Ziehau static void bnx_setup_rxdesc_std(struct bnx_rx_std_ring *, int); 2046c8d8eccSSepherosa Ziehau static void bnx_setup_rxdesc_jumbo(struct bnx_softc *, int); 205beedf5beSSepherosa Ziehau static int bnx_init_rx_ring_std(struct bnx_rx_std_ring *); 206beedf5beSSepherosa Ziehau static void bnx_free_rx_ring_std(struct bnx_rx_std_ring *); 2076c8d8eccSSepherosa Ziehau static int bnx_init_rx_ring_jumbo(struct bnx_softc *); 2086c8d8eccSSepherosa Ziehau static void bnx_free_rx_ring_jumbo(struct bnx_softc *); 20933a04907SSepherosa Ziehau static void bnx_free_tx_ring(struct bnx_tx_ring *); 21033a04907SSepherosa Ziehau static int bnx_init_tx_ring(struct bnx_tx_ring *); 21133a04907SSepherosa Ziehau static int bnx_create_tx_ring(struct bnx_tx_ring *); 21233a04907SSepherosa Ziehau static void bnx_destroy_tx_ring(struct bnx_tx_ring *); 213beedf5beSSepherosa Ziehau static int bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *); 214beedf5beSSepherosa Ziehau static void bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *); 215beedf5beSSepherosa Ziehau static int bnx_dma_alloc(device_t); 2166c8d8eccSSepherosa Ziehau static void bnx_dma_free(struct bnx_softc *); 2176c8d8eccSSepherosa Ziehau static int bnx_dma_block_alloc(struct bnx_softc *, bus_size_t, 2186c8d8eccSSepherosa Ziehau bus_dma_tag_t *, bus_dmamap_t *, void **, bus_addr_t *); 2196c8d8eccSSepherosa Ziehau static void bnx_dma_block_free(bus_dma_tag_t, bus_dmamap_t, void *); 2206c8d8eccSSepherosa Ziehau static struct mbuf * 2216c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *); 22233a04907SSepherosa Ziehau static int bnx_encap(struct bnx_tx_ring *, struct mbuf **, 223c9b7f592SSepherosa Ziehau uint32_t *, int *); 22433a04907SSepherosa Ziehau static int bnx_setup_tso(struct bnx_tx_ring *, struct mbuf **, 22566deb1c1SSepherosa Ziehau uint16_t *, uint16_t *); 226329f9016SSepherosa Ziehau static void bnx_setup_serialize(struct bnx_softc *); 2277dbaa833SSepherosa Ziehau static void bnx_set_tick_cpuid(struct bnx_softc *, boolean_t); 2286c8d8eccSSepherosa Ziehau 2296c8d8eccSSepherosa Ziehau static void bnx_reset(struct bnx_softc *); 2306c8d8eccSSepherosa Ziehau static int bnx_chipinit(struct bnx_softc *); 2316c8d8eccSSepherosa Ziehau static int bnx_blockinit(struct bnx_softc *); 2326c8d8eccSSepherosa Ziehau static void bnx_stop_block(struct bnx_softc *, bus_size_t, uint32_t); 2336c8d8eccSSepherosa Ziehau static void bnx_enable_msi(struct bnx_softc *sc); 2346c8d8eccSSepherosa Ziehau static void bnx_setmulti(struct bnx_softc *); 2356c8d8eccSSepherosa Ziehau static void bnx_setpromisc(struct bnx_softc *); 2366c8d8eccSSepherosa Ziehau static void bnx_stats_update_regs(struct bnx_softc *); 2376c8d8eccSSepherosa Ziehau static uint32_t bnx_dma_swap_options(struct bnx_softc *); 2386c8d8eccSSepherosa Ziehau 2396c8d8eccSSepherosa Ziehau static uint32_t bnx_readmem_ind(struct bnx_softc *, uint32_t); 2406c8d8eccSSepherosa Ziehau static void bnx_writemem_ind(struct bnx_softc *, uint32_t, uint32_t); 2416c8d8eccSSepherosa Ziehau #ifdef notdef 2426c8d8eccSSepherosa Ziehau static uint32_t bnx_readreg_ind(struct bnx_softc *, uint32_t); 2436c8d8eccSSepherosa Ziehau #endif 2446c8d8eccSSepherosa Ziehau static void bnx_writemem_direct(struct bnx_softc *, uint32_t, uint32_t); 2456c8d8eccSSepherosa Ziehau static void bnx_writembx(struct bnx_softc *, int, int); 2466c8d8eccSSepherosa Ziehau static int bnx_read_nvram(struct bnx_softc *, caddr_t, int, int); 2476c8d8eccSSepherosa Ziehau static uint8_t bnx_eeprom_getbyte(struct bnx_softc *, uint32_t, uint8_t *); 2486c8d8eccSSepherosa Ziehau static int bnx_read_eeprom(struct bnx_softc *, caddr_t, uint32_t, size_t); 2496c8d8eccSSepherosa Ziehau 2506c8d8eccSSepherosa Ziehau static void bnx_tbi_link_upd(struct bnx_softc *, uint32_t); 2516c8d8eccSSepherosa Ziehau static void bnx_copper_link_upd(struct bnx_softc *, uint32_t); 2526c8d8eccSSepherosa Ziehau static void bnx_autopoll_link_upd(struct bnx_softc *, uint32_t); 2536c8d8eccSSepherosa Ziehau static void bnx_link_poll(struct bnx_softc *); 2546c8d8eccSSepherosa Ziehau 2556c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_mem(struct bnx_softc *, uint8_t[]); 2566c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_nvram(struct bnx_softc *, uint8_t[]); 2576c8d8eccSSepherosa Ziehau static int bnx_get_eaddr_eeprom(struct bnx_softc *, uint8_t[]); 2586c8d8eccSSepherosa Ziehau static int bnx_get_eaddr(struct bnx_softc *, uint8_t[]); 2596c8d8eccSSepherosa Ziehau 2606c8d8eccSSepherosa Ziehau static void bnx_coal_change(struct bnx_softc *); 261aad4de2bSSepherosa Ziehau static int bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS); 262472c99c8SSepherosa Ziehau static int bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS); 2636c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS); 2646c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS); 2656c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS); 2666c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS); 2676c8d8eccSSepherosa Ziehau static int bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2686c8d8eccSSepherosa Ziehau static int bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS); 2696c8d8eccSSepherosa Ziehau static int bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *, 2706c8d8eccSSepherosa Ziehau int, int, uint32_t); 2714fa38985SSepherosa Ziehau #ifdef IFPOLL_ENABLE 2724fa38985SSepherosa Ziehau static int bnx_sysctl_npoll_offset(SYSCTL_HANDLER_ARGS); 2734fa38985SSepherosa Ziehau static int bnx_sysctl_npoll_rxoff(SYSCTL_HANDLER_ARGS); 2744fa38985SSepherosa Ziehau static int bnx_sysctl_npoll_txoff(SYSCTL_HANDLER_ARGS); 2754fa38985SSepherosa Ziehau #endif 276841cdf08SSepherosa Ziehau static int bnx_sysctl_std_refill(SYSCTL_HANDLER_ARGS); 2776c8d8eccSSepherosa Ziehau 2786c8d8eccSSepherosa Ziehau static int bnx_msi_enable = 1; 2796c8d8eccSSepherosa Ziehau TUNABLE_INT("hw.bnx.msi.enable", &bnx_msi_enable); 2806c8d8eccSSepherosa Ziehau 2816c8d8eccSSepherosa Ziehau static device_method_t bnx_methods[] = { 2826c8d8eccSSepherosa Ziehau /* Device interface */ 2836c8d8eccSSepherosa Ziehau DEVMETHOD(device_probe, bnx_probe), 2846c8d8eccSSepherosa Ziehau DEVMETHOD(device_attach, bnx_attach), 2856c8d8eccSSepherosa Ziehau DEVMETHOD(device_detach, bnx_detach), 2866c8d8eccSSepherosa Ziehau DEVMETHOD(device_shutdown, bnx_shutdown), 2876c8d8eccSSepherosa Ziehau DEVMETHOD(device_suspend, bnx_suspend), 2886c8d8eccSSepherosa Ziehau DEVMETHOD(device_resume, bnx_resume), 2896c8d8eccSSepherosa Ziehau 2906c8d8eccSSepherosa Ziehau /* bus interface */ 2916c8d8eccSSepherosa Ziehau DEVMETHOD(bus_print_child, bus_generic_print_child), 2926c8d8eccSSepherosa Ziehau DEVMETHOD(bus_driver_added, bus_generic_driver_added), 2936c8d8eccSSepherosa Ziehau 2946c8d8eccSSepherosa Ziehau /* MII interface */ 2956c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_readreg, bnx_miibus_readreg), 2966c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_writereg, bnx_miibus_writereg), 2976c8d8eccSSepherosa Ziehau DEVMETHOD(miibus_statchg, bnx_miibus_statchg), 2986c8d8eccSSepherosa Ziehau 299d3c9c58eSSascha Wildner DEVMETHOD_END 3006c8d8eccSSepherosa Ziehau }; 3016c8d8eccSSepherosa Ziehau 3026c8d8eccSSepherosa Ziehau static DEFINE_CLASS_0(bnx, bnx_driver, bnx_methods, sizeof(struct bnx_softc)); 3036c8d8eccSSepherosa Ziehau static devclass_t bnx_devclass; 3046c8d8eccSSepherosa Ziehau 3056c8d8eccSSepherosa Ziehau DECLARE_DUMMY_MODULE(if_bnx); 3066c8d8eccSSepherosa Ziehau DRIVER_MODULE(if_bnx, pci, bnx_driver, bnx_devclass, NULL, NULL); 3076c8d8eccSSepherosa Ziehau DRIVER_MODULE(miibus, bnx, miibus_driver, miibus_devclass, NULL, NULL); 3086c8d8eccSSepherosa Ziehau 3096c8d8eccSSepherosa Ziehau static uint32_t 3106c8d8eccSSepherosa Ziehau bnx_readmem_ind(struct bnx_softc *sc, uint32_t off) 3116c8d8eccSSepherosa Ziehau { 3126c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 3136c8d8eccSSepherosa Ziehau uint32_t val; 3146c8d8eccSSepherosa Ziehau 3156c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 3166c8d8eccSSepherosa Ziehau val = pci_read_config(dev, BGE_PCI_MEMWIN_DATA, 4); 3176c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 3186c8d8eccSSepherosa Ziehau return (val); 3196c8d8eccSSepherosa Ziehau } 3206c8d8eccSSepherosa Ziehau 3216c8d8eccSSepherosa Ziehau static void 3226c8d8eccSSepherosa Ziehau bnx_writemem_ind(struct bnx_softc *sc, uint32_t off, uint32_t val) 3236c8d8eccSSepherosa Ziehau { 3246c8d8eccSSepherosa Ziehau device_t dev = sc->bnx_dev; 3256c8d8eccSSepherosa Ziehau 3266c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4); 3276c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_DATA, val, 4); 3286c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4); 3296c8d8eccSSepherosa Ziehau } 3306c8d8eccSSepherosa Ziehau 3316c8d8eccSSepherosa Ziehau static void 3326c8d8eccSSepherosa Ziehau bnx_writemem_direct(struct bnx_softc *sc, uint32_t off, uint32_t val) 3336c8d8eccSSepherosa Ziehau { 3346c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3356c8d8eccSSepherosa Ziehau } 3366c8d8eccSSepherosa Ziehau 3376c8d8eccSSepherosa Ziehau static void 3386c8d8eccSSepherosa Ziehau bnx_writembx(struct bnx_softc *sc, int off, int val) 3396c8d8eccSSepherosa Ziehau { 3406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, off, val); 3416c8d8eccSSepherosa Ziehau } 3426c8d8eccSSepherosa Ziehau 3436c8d8eccSSepherosa Ziehau /* 3446c8d8eccSSepherosa Ziehau * Read a sequence of bytes from NVRAM. 3456c8d8eccSSepherosa Ziehau */ 3466c8d8eccSSepherosa Ziehau static int 3476c8d8eccSSepherosa Ziehau bnx_read_nvram(struct bnx_softc *sc, caddr_t dest, int off, int cnt) 3486c8d8eccSSepherosa Ziehau { 3496c8d8eccSSepherosa Ziehau return (1); 3506c8d8eccSSepherosa Ziehau } 3516c8d8eccSSepherosa Ziehau 3526c8d8eccSSepherosa Ziehau /* 3536c8d8eccSSepherosa Ziehau * Read a byte of data stored in the EEPROM at address 'addr.' The 3546c8d8eccSSepherosa Ziehau * BCM570x supports both the traditional bitbang interface and an 3556c8d8eccSSepherosa Ziehau * auto access interface for reading the EEPROM. We use the auto 3566c8d8eccSSepherosa Ziehau * access method. 3576c8d8eccSSepherosa Ziehau */ 3586c8d8eccSSepherosa Ziehau static uint8_t 3596c8d8eccSSepherosa Ziehau bnx_eeprom_getbyte(struct bnx_softc *sc, uint32_t addr, uint8_t *dest) 3606c8d8eccSSepherosa Ziehau { 3616c8d8eccSSepherosa Ziehau int i; 3626c8d8eccSSepherosa Ziehau uint32_t byte = 0; 3636c8d8eccSSepherosa Ziehau 3646c8d8eccSSepherosa Ziehau /* 3656c8d8eccSSepherosa Ziehau * Enable use of auto EEPROM access so we can avoid 3666c8d8eccSSepherosa Ziehau * having to use the bitbang method. 3676c8d8eccSSepherosa Ziehau */ 3686c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_AUTO_EEPROM); 3696c8d8eccSSepherosa Ziehau 3706c8d8eccSSepherosa Ziehau /* Reset the EEPROM, load the clock period. */ 3716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, 3726c8d8eccSSepherosa Ziehau BGE_EEADDR_RESET|BGE_EEHALFCLK(BGE_HALFCLK_384SCL)); 3736c8d8eccSSepherosa Ziehau DELAY(20); 3746c8d8eccSSepherosa Ziehau 3756c8d8eccSSepherosa Ziehau /* Issue the read EEPROM command. */ 3766c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_EE_ADDR, BGE_EE_READCMD | addr); 3776c8d8eccSSepherosa Ziehau 3786c8d8eccSSepherosa Ziehau /* Wait for completion */ 3796c8d8eccSSepherosa Ziehau for(i = 0; i < BNX_TIMEOUT * 10; i++) { 3806c8d8eccSSepherosa Ziehau DELAY(10); 3816c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_EE_ADDR) & BGE_EEADDR_DONE) 3826c8d8eccSSepherosa Ziehau break; 3836c8d8eccSSepherosa Ziehau } 3846c8d8eccSSepherosa Ziehau 3856c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 3866c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "eeprom read timed out\n"); 3876c8d8eccSSepherosa Ziehau return(1); 3886c8d8eccSSepherosa Ziehau } 3896c8d8eccSSepherosa Ziehau 3906c8d8eccSSepherosa Ziehau /* Get result. */ 3916c8d8eccSSepherosa Ziehau byte = CSR_READ_4(sc, BGE_EE_DATA); 3926c8d8eccSSepherosa Ziehau 3936c8d8eccSSepherosa Ziehau *dest = (byte >> ((addr % 4) * 8)) & 0xFF; 3946c8d8eccSSepherosa Ziehau 3956c8d8eccSSepherosa Ziehau return(0); 3966c8d8eccSSepherosa Ziehau } 3976c8d8eccSSepherosa Ziehau 3986c8d8eccSSepherosa Ziehau /* 3996c8d8eccSSepherosa Ziehau * Read a sequence of bytes from the EEPROM. 4006c8d8eccSSepherosa Ziehau */ 4016c8d8eccSSepherosa Ziehau static int 4026c8d8eccSSepherosa Ziehau bnx_read_eeprom(struct bnx_softc *sc, caddr_t dest, uint32_t off, size_t len) 4036c8d8eccSSepherosa Ziehau { 4046c8d8eccSSepherosa Ziehau size_t i; 4056c8d8eccSSepherosa Ziehau int err; 4066c8d8eccSSepherosa Ziehau uint8_t byte; 4076c8d8eccSSepherosa Ziehau 4086c8d8eccSSepherosa Ziehau for (byte = 0, err = 0, i = 0; i < len; i++) { 4096c8d8eccSSepherosa Ziehau err = bnx_eeprom_getbyte(sc, off + i, &byte); 4106c8d8eccSSepherosa Ziehau if (err) 4116c8d8eccSSepherosa Ziehau break; 4126c8d8eccSSepherosa Ziehau *(dest + i) = byte; 4136c8d8eccSSepherosa Ziehau } 4146c8d8eccSSepherosa Ziehau 4156c8d8eccSSepherosa Ziehau return(err ? 1 : 0); 4166c8d8eccSSepherosa Ziehau } 4176c8d8eccSSepherosa Ziehau 4186c8d8eccSSepherosa Ziehau static int 4196c8d8eccSSepherosa Ziehau bnx_miibus_readreg(device_t dev, int phy, int reg) 4206c8d8eccSSepherosa Ziehau { 4216c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4226c8d8eccSSepherosa Ziehau uint32_t val; 4236c8d8eccSSepherosa Ziehau int i; 4246c8d8eccSSepherosa Ziehau 4256c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4266c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4276c8d8eccSSepherosa Ziehau 4286c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4296c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4306c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4316c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4326c8d8eccSSepherosa Ziehau DELAY(80); 4336c8d8eccSSepherosa Ziehau } 4346c8d8eccSSepherosa Ziehau 4356c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ | BGE_MICOMM_BUSY | 4366c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg)); 4376c8d8eccSSepherosa Ziehau 4386c8d8eccSSepherosa Ziehau /* Poll for the PHY register access to complete. */ 4396c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4406c8d8eccSSepherosa Ziehau DELAY(10); 4416c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4426c8d8eccSSepherosa Ziehau if ((val & BGE_MICOMM_BUSY) == 0) { 4436c8d8eccSSepherosa Ziehau DELAY(5); 4446c8d8eccSSepherosa Ziehau val = CSR_READ_4(sc, BGE_MI_COMM); 4456c8d8eccSSepherosa Ziehau break; 4466c8d8eccSSepherosa Ziehau } 4476c8d8eccSSepherosa Ziehau } 4486c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4496c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY read timed out " 4506c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val 0x%08x)\n", phy, reg, val); 4516c8d8eccSSepherosa Ziehau val = 0; 4526c8d8eccSSepherosa Ziehau } 4536c8d8eccSSepherosa Ziehau 4546c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4556c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 4576c8d8eccSSepherosa Ziehau DELAY(80); 4586c8d8eccSSepherosa Ziehau } 4596c8d8eccSSepherosa Ziehau 4606c8d8eccSSepherosa Ziehau if (val & BGE_MICOMM_READFAIL) 4616c8d8eccSSepherosa Ziehau return 0; 4626c8d8eccSSepherosa Ziehau 4636c8d8eccSSepherosa Ziehau return (val & 0xFFFF); 4646c8d8eccSSepherosa Ziehau } 4656c8d8eccSSepherosa Ziehau 4666c8d8eccSSepherosa Ziehau static int 4676c8d8eccSSepherosa Ziehau bnx_miibus_writereg(device_t dev, int phy, int reg, int val) 4686c8d8eccSSepherosa Ziehau { 4696c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 4706c8d8eccSSepherosa Ziehau int i; 4716c8d8eccSSepherosa Ziehau 4726c8d8eccSSepherosa Ziehau KASSERT(phy == sc->bnx_phyno, 4736c8d8eccSSepherosa Ziehau ("invalid phyno %d, should be %d", phy, sc->bnx_phyno)); 4746c8d8eccSSepherosa Ziehau 4756c8d8eccSSepherosa Ziehau /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ 4766c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 4776c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 4786c8d8eccSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 4796c8d8eccSSepherosa Ziehau DELAY(80); 4806c8d8eccSSepherosa Ziehau } 4816c8d8eccSSepherosa Ziehau 4826c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY | 4836c8d8eccSSepherosa Ziehau BGE_MIPHY(phy) | BGE_MIREG(reg) | val); 4846c8d8eccSSepherosa Ziehau 4856c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 4866c8d8eccSSepherosa Ziehau DELAY(10); 4876c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) { 4886c8d8eccSSepherosa Ziehau DELAY(5); 4896c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */ 4906c8d8eccSSepherosa Ziehau break; 4916c8d8eccSSepherosa Ziehau } 4926c8d8eccSSepherosa Ziehau } 4936c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 4946c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "PHY write timed out " 4956c8d8eccSSepherosa Ziehau "(phy %d, reg %d, val %d)\n", phy, reg, val); 4966c8d8eccSSepherosa Ziehau } 4976c8d8eccSSepherosa Ziehau 4986c8d8eccSSepherosa Ziehau /* Restore the autopoll bit if necessary. */ 4996c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 5006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 5016c8d8eccSSepherosa Ziehau DELAY(80); 5026c8d8eccSSepherosa Ziehau } 5036c8d8eccSSepherosa Ziehau 5046c8d8eccSSepherosa Ziehau return 0; 5056c8d8eccSSepherosa Ziehau } 5066c8d8eccSSepherosa Ziehau 5076c8d8eccSSepherosa Ziehau static void 5086c8d8eccSSepherosa Ziehau bnx_miibus_statchg(device_t dev) 5096c8d8eccSSepherosa Ziehau { 5106c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 5116c8d8eccSSepherosa Ziehau struct mii_data *mii; 5126c8d8eccSSepherosa Ziehau 5136c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 5146c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 5156c8d8eccSSepherosa Ziehau 5166c8d8eccSSepherosa Ziehau if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 5176c8d8eccSSepherosa Ziehau (IFM_ACTIVE | IFM_AVALID)) { 5186c8d8eccSSepherosa Ziehau switch (IFM_SUBTYPE(mii->mii_media_active)) { 5196c8d8eccSSepherosa Ziehau case IFM_10_T: 5206c8d8eccSSepherosa Ziehau case IFM_100_TX: 5216c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5226c8d8eccSSepherosa Ziehau break; 5236c8d8eccSSepherosa Ziehau case IFM_1000_T: 5246c8d8eccSSepherosa Ziehau case IFM_1000_SX: 5256c8d8eccSSepherosa Ziehau case IFM_2500_SX: 5266c8d8eccSSepherosa Ziehau sc->bnx_link = 1; 5276c8d8eccSSepherosa Ziehau break; 5286c8d8eccSSepherosa Ziehau default: 5296c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5306c8d8eccSSepherosa Ziehau break; 5316c8d8eccSSepherosa Ziehau } 5326c8d8eccSSepherosa Ziehau } else { 5336c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 5346c8d8eccSSepherosa Ziehau } 5356c8d8eccSSepherosa Ziehau if (sc->bnx_link == 0) 5366c8d8eccSSepherosa Ziehau return; 5376c8d8eccSSepherosa Ziehau 5386c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); 5396c8d8eccSSepherosa Ziehau if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T || 5406c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) { 5416c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); 5426c8d8eccSSepherosa Ziehau } else { 5436c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII); 5446c8d8eccSSepherosa Ziehau } 5456c8d8eccSSepherosa Ziehau 5466c8d8eccSSepherosa Ziehau if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 5476c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5486c8d8eccSSepherosa Ziehau } else { 5496c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); 5506c8d8eccSSepherosa Ziehau } 5516c8d8eccSSepherosa Ziehau } 5526c8d8eccSSepherosa Ziehau 5536c8d8eccSSepherosa Ziehau /* 5546c8d8eccSSepherosa Ziehau * Memory management for jumbo frames. 5556c8d8eccSSepherosa Ziehau */ 5566c8d8eccSSepherosa Ziehau static int 5576c8d8eccSSepherosa Ziehau bnx_alloc_jumbo_mem(struct bnx_softc *sc) 5586c8d8eccSSepherosa Ziehau { 5596c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 5606c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 5616c8d8eccSSepherosa Ziehau uint8_t *ptr; 5626c8d8eccSSepherosa Ziehau bus_addr_t paddr; 5636c8d8eccSSepherosa Ziehau int i, error; 5646c8d8eccSSepherosa Ziehau 5656c8d8eccSSepherosa Ziehau /* 5666c8d8eccSSepherosa Ziehau * Create tag for jumbo mbufs. 5676c8d8eccSSepherosa Ziehau * This is really a bit of a kludge. We allocate a special 5686c8d8eccSSepherosa Ziehau * jumbo buffer pool which (thanks to the way our DMA 5696c8d8eccSSepherosa Ziehau * memory allocation works) will consist of contiguous 5706c8d8eccSSepherosa Ziehau * pages. This means that even though a jumbo buffer might 5716c8d8eccSSepherosa Ziehau * be larger than a page size, we don't really need to 5726c8d8eccSSepherosa Ziehau * map it into more than one DMA segment. However, the 5736c8d8eccSSepherosa Ziehau * default mbuf tag will result in multi-segment mappings, 5746c8d8eccSSepherosa Ziehau * so we have to create a special jumbo mbuf tag that 5756c8d8eccSSepherosa Ziehau * lets us get away with mapping the jumbo buffers as 5766c8d8eccSSepherosa Ziehau * a single segment. I think eventually the driver should 5776c8d8eccSSepherosa Ziehau * be changed so that it uses ordinary mbufs and cluster 5786c8d8eccSSepherosa Ziehau * buffers, i.e. jumbo frames can span multiple DMA 5796c8d8eccSSepherosa Ziehau * descriptors. But that's a project for another day. 5806c8d8eccSSepherosa Ziehau */ 5816c8d8eccSSepherosa Ziehau 5826c8d8eccSSepherosa Ziehau /* 5836c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo RX ring. 5846c8d8eccSSepherosa Ziehau */ 5856c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_JUMBO_RX_RING_SZ, 5866c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 5876c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_rx_jumbo_ring_map, 5886c8d8eccSSepherosa Ziehau (void *)&sc->bnx_ldata.bnx_rx_jumbo_ring, 5896c8d8eccSSepherosa Ziehau &sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 5906c8d8eccSSepherosa Ziehau if (error) { 5916c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo RX ring\n"); 5926c8d8eccSSepherosa Ziehau return error; 5936c8d8eccSSepherosa Ziehau } 5946c8d8eccSSepherosa Ziehau 5956c8d8eccSSepherosa Ziehau /* 5966c8d8eccSSepherosa Ziehau * Create DMA stuffs for jumbo buffer block. 5976c8d8eccSSepherosa Ziehau */ 5986c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BNX_JMEM, 5996c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_tag, 6006c8d8eccSSepherosa Ziehau &sc->bnx_cdata.bnx_jumbo_map, 6016c8d8eccSSepherosa Ziehau (void **)&sc->bnx_ldata.bnx_jumbo_buf, 6026c8d8eccSSepherosa Ziehau &paddr); 6036c8d8eccSSepherosa Ziehau if (error) { 6046c8d8eccSSepherosa Ziehau if_printf(ifp, "could not create jumbo buffer\n"); 6056c8d8eccSSepherosa Ziehau return error; 6066c8d8eccSSepherosa Ziehau } 6076c8d8eccSSepherosa Ziehau 6086c8d8eccSSepherosa Ziehau SLIST_INIT(&sc->bnx_jfree_listhead); 6096c8d8eccSSepherosa Ziehau 6106c8d8eccSSepherosa Ziehau /* 6116c8d8eccSSepherosa Ziehau * Now divide it up into 9K pieces and save the addresses 6126c8d8eccSSepherosa Ziehau * in an array. Note that we play an evil trick here by using 6136c8d8eccSSepherosa Ziehau * the first few bytes in the buffer to hold the the address 6146c8d8eccSSepherosa Ziehau * of the softc structure for this interface. This is because 6156c8d8eccSSepherosa Ziehau * bnx_jfree() needs it, but it is called by the mbuf management 6166c8d8eccSSepherosa Ziehau * code which will not pass it to us explicitly. 6176c8d8eccSSepherosa Ziehau */ 6186c8d8eccSSepherosa Ziehau for (i = 0, ptr = sc->bnx_ldata.bnx_jumbo_buf; i < BNX_JSLOTS; i++) { 6196c8d8eccSSepherosa Ziehau entry = &sc->bnx_cdata.bnx_jslots[i]; 6206c8d8eccSSepherosa Ziehau entry->bnx_sc = sc; 6216c8d8eccSSepherosa Ziehau entry->bnx_buf = ptr; 6226c8d8eccSSepherosa Ziehau entry->bnx_paddr = paddr; 6236c8d8eccSSepherosa Ziehau entry->bnx_inuse = 0; 6246c8d8eccSSepherosa Ziehau entry->bnx_slot = i; 6256c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, entry, jslot_link); 6266c8d8eccSSepherosa Ziehau 6276c8d8eccSSepherosa Ziehau ptr += BNX_JLEN; 6286c8d8eccSSepherosa Ziehau paddr += BNX_JLEN; 6296c8d8eccSSepherosa Ziehau } 6306c8d8eccSSepherosa Ziehau return 0; 6316c8d8eccSSepherosa Ziehau } 6326c8d8eccSSepherosa Ziehau 6336c8d8eccSSepherosa Ziehau static void 6346c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(struct bnx_softc *sc) 6356c8d8eccSSepherosa Ziehau { 6366c8d8eccSSepherosa Ziehau /* Destroy jumbo RX ring. */ 6376c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_rx_jumbo_ring_tag, 6386c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_ring_map, 6396c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_rx_jumbo_ring); 6406c8d8eccSSepherosa Ziehau 6416c8d8eccSSepherosa Ziehau /* Destroy jumbo buffer block. */ 6426c8d8eccSSepherosa Ziehau bnx_dma_block_free(sc->bnx_cdata.bnx_jumbo_tag, 6436c8d8eccSSepherosa Ziehau sc->bnx_cdata.bnx_jumbo_map, 6446c8d8eccSSepherosa Ziehau sc->bnx_ldata.bnx_jumbo_buf); 6456c8d8eccSSepherosa Ziehau } 6466c8d8eccSSepherosa Ziehau 6476c8d8eccSSepherosa Ziehau /* 6486c8d8eccSSepherosa Ziehau * Allocate a jumbo buffer. 6496c8d8eccSSepherosa Ziehau */ 6506c8d8eccSSepherosa Ziehau static struct bnx_jslot * 6516c8d8eccSSepherosa Ziehau bnx_jalloc(struct bnx_softc *sc) 6526c8d8eccSSepherosa Ziehau { 6536c8d8eccSSepherosa Ziehau struct bnx_jslot *entry; 6546c8d8eccSSepherosa Ziehau 6556c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 6566c8d8eccSSepherosa Ziehau entry = SLIST_FIRST(&sc->bnx_jfree_listhead); 6576c8d8eccSSepherosa Ziehau if (entry) { 6586c8d8eccSSepherosa Ziehau SLIST_REMOVE_HEAD(&sc->bnx_jfree_listhead, jslot_link); 6596c8d8eccSSepherosa Ziehau entry->bnx_inuse = 1; 6606c8d8eccSSepherosa Ziehau } else { 6616c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "no free jumbo buffers\n"); 6626c8d8eccSSepherosa Ziehau } 6636c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 6646c8d8eccSSepherosa Ziehau return(entry); 6656c8d8eccSSepherosa Ziehau } 6666c8d8eccSSepherosa Ziehau 6676c8d8eccSSepherosa Ziehau /* 6686c8d8eccSSepherosa Ziehau * Adjust usage count on a jumbo buffer. 6696c8d8eccSSepherosa Ziehau */ 6706c8d8eccSSepherosa Ziehau static void 6716c8d8eccSSepherosa Ziehau bnx_jref(void *arg) 6726c8d8eccSSepherosa Ziehau { 6736c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6746c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6756c8d8eccSSepherosa Ziehau 6766c8d8eccSSepherosa Ziehau if (sc == NULL) 6776c8d8eccSSepherosa Ziehau panic("bnx_jref: can't find softc pointer!"); 6786c8d8eccSSepherosa Ziehau 6796c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 6806c8d8eccSSepherosa Ziehau panic("bnx_jref: asked to reference buffer " 6816c8d8eccSSepherosa Ziehau "that we don't manage!"); 6826c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 6836c8d8eccSSepherosa Ziehau panic("bnx_jref: buffer already free!"); 6846c8d8eccSSepherosa Ziehau } else { 6856c8d8eccSSepherosa Ziehau atomic_add_int(&entry->bnx_inuse, 1); 6866c8d8eccSSepherosa Ziehau } 6876c8d8eccSSepherosa Ziehau } 6886c8d8eccSSepherosa Ziehau 6896c8d8eccSSepherosa Ziehau /* 6906c8d8eccSSepherosa Ziehau * Release a jumbo buffer. 6916c8d8eccSSepherosa Ziehau */ 6926c8d8eccSSepherosa Ziehau static void 6936c8d8eccSSepherosa Ziehau bnx_jfree(void *arg) 6946c8d8eccSSepherosa Ziehau { 6956c8d8eccSSepherosa Ziehau struct bnx_jslot *entry = (struct bnx_jslot *)arg; 6966c8d8eccSSepherosa Ziehau struct bnx_softc *sc = entry->bnx_sc; 6976c8d8eccSSepherosa Ziehau 6986c8d8eccSSepherosa Ziehau if (sc == NULL) 6996c8d8eccSSepherosa Ziehau panic("bnx_jfree: can't find softc pointer!"); 7006c8d8eccSSepherosa Ziehau 7016c8d8eccSSepherosa Ziehau if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) { 7026c8d8eccSSepherosa Ziehau panic("bnx_jfree: asked to free buffer that we don't manage!"); 7036c8d8eccSSepherosa Ziehau } else if (entry->bnx_inuse == 0) { 7046c8d8eccSSepherosa Ziehau panic("bnx_jfree: buffer already free!"); 7056c8d8eccSSepherosa Ziehau } else { 7066c8d8eccSSepherosa Ziehau /* 7076c8d8eccSSepherosa Ziehau * Possible MP race to 0, use the serializer. The atomic insn 7086c8d8eccSSepherosa Ziehau * is still needed for races against bnx_jref(). 7096c8d8eccSSepherosa Ziehau */ 7106c8d8eccSSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_jslot_serializer); 7116c8d8eccSSepherosa Ziehau atomic_subtract_int(&entry->bnx_inuse, 1); 7126c8d8eccSSepherosa Ziehau if (entry->bnx_inuse == 0) { 7136c8d8eccSSepherosa Ziehau SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, 7146c8d8eccSSepherosa Ziehau entry, jslot_link); 7156c8d8eccSSepherosa Ziehau } 7166c8d8eccSSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_jslot_serializer); 7176c8d8eccSSepherosa Ziehau } 7186c8d8eccSSepherosa Ziehau } 7196c8d8eccSSepherosa Ziehau 7206c8d8eccSSepherosa Ziehau 7216c8d8eccSSepherosa Ziehau /* 7226c8d8eccSSepherosa Ziehau * Intialize a standard receive ring descriptor. 7236c8d8eccSSepherosa Ziehau */ 7246c8d8eccSSepherosa Ziehau static int 725beedf5beSSepherosa Ziehau bnx_newbuf_std(struct bnx_rx_ret_ring *ret, int i, int init) 7266c8d8eccSSepherosa Ziehau { 7276c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7286c8d8eccSSepherosa Ziehau bus_dma_segment_t seg; 7296c8d8eccSSepherosa Ziehau bus_dmamap_t map; 7306c8d8eccSSepherosa Ziehau int error, nsegs; 731beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb; 7326c8d8eccSSepherosa Ziehau 733841cdf08SSepherosa Ziehau rb = &ret->bnx_std->bnx_rx_std_buf[i]; 734841cdf08SSepherosa Ziehau KASSERT(!rb->bnx_rx_refilled, ("RX buf %dth has been refilled", i)); 735841cdf08SSepherosa Ziehau 7366c8d8eccSSepherosa Ziehau m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR); 737841cdf08SSepherosa Ziehau if (m_new == NULL) { 738841cdf08SSepherosa Ziehau error = ENOBUFS; 739841cdf08SSepherosa Ziehau goto back; 740841cdf08SSepherosa Ziehau } 7416c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 7426c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 7436c8d8eccSSepherosa Ziehau 744beedf5beSSepherosa Ziehau error = bus_dmamap_load_mbuf_segment(ret->bnx_rx_mtag, 745beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap, m_new, &seg, 1, &nsegs, BUS_DMA_NOWAIT); 7466c8d8eccSSepherosa Ziehau if (error) { 7476c8d8eccSSepherosa Ziehau m_freem(m_new); 748841cdf08SSepherosa Ziehau goto back; 7496c8d8eccSSepherosa Ziehau } 7506c8d8eccSSepherosa Ziehau 7516c8d8eccSSepherosa Ziehau if (!init) { 752beedf5beSSepherosa Ziehau bus_dmamap_sync(ret->bnx_rx_mtag, rb->bnx_rx_dmamap, 7536c8d8eccSSepherosa Ziehau BUS_DMASYNC_POSTREAD); 754beedf5beSSepherosa Ziehau bus_dmamap_unload(ret->bnx_rx_mtag, rb->bnx_rx_dmamap); 7556c8d8eccSSepherosa Ziehau } 7566c8d8eccSSepherosa Ziehau 757beedf5beSSepherosa Ziehau map = ret->bnx_rx_tmpmap; 758beedf5beSSepherosa Ziehau ret->bnx_rx_tmpmap = rb->bnx_rx_dmamap; 7596c8d8eccSSepherosa Ziehau 760841cdf08SSepherosa Ziehau rb->bnx_rx_dmamap = map; 761beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = m_new; 762beedf5beSSepherosa Ziehau rb->bnx_rx_paddr = seg.ds_addr; 763841cdf08SSepherosa Ziehau back: 764841cdf08SSepherosa Ziehau cpu_sfence(); 765841cdf08SSepherosa Ziehau rb->bnx_rx_refilled = 1; 766841cdf08SSepherosa Ziehau return error; 7676c8d8eccSSepherosa Ziehau } 7686c8d8eccSSepherosa Ziehau 7696c8d8eccSSepherosa Ziehau static void 770beedf5beSSepherosa Ziehau bnx_setup_rxdesc_std(struct bnx_rx_std_ring *std, int i) 7716c8d8eccSSepherosa Ziehau { 772841cdf08SSepherosa Ziehau struct bnx_rx_buf *rb; 7736c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 7746c8d8eccSSepherosa Ziehau 775beedf5beSSepherosa Ziehau rb = &std->bnx_rx_std_buf[i]; 776841cdf08SSepherosa Ziehau KASSERT(rb->bnx_rx_refilled, ("RX buf %dth is not refilled", i)); 777841cdf08SSepherosa Ziehau rb->bnx_rx_refilled = 0; 7786c8d8eccSSepherosa Ziehau 779841cdf08SSepherosa Ziehau r = &std->bnx_rx_std_ring[i]; 780beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rb->bnx_rx_paddr); 781beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rb->bnx_rx_paddr); 782beedf5beSSepherosa Ziehau r->bge_len = rb->bnx_rx_mbuf->m_len; 7836c8d8eccSSepherosa Ziehau r->bge_idx = i; 7846c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END; 7856c8d8eccSSepherosa Ziehau } 7866c8d8eccSSepherosa Ziehau 7876c8d8eccSSepherosa Ziehau /* 7886c8d8eccSSepherosa Ziehau * Initialize a jumbo receive ring descriptor. This allocates 7896c8d8eccSSepherosa Ziehau * a jumbo buffer from the pool managed internally by the driver. 7906c8d8eccSSepherosa Ziehau */ 7916c8d8eccSSepherosa Ziehau static int 7926c8d8eccSSepherosa Ziehau bnx_newbuf_jumbo(struct bnx_softc *sc, int i, int init) 7936c8d8eccSSepherosa Ziehau { 7946c8d8eccSSepherosa Ziehau struct mbuf *m_new = NULL; 7956c8d8eccSSepherosa Ziehau struct bnx_jslot *buf; 7966c8d8eccSSepherosa Ziehau bus_addr_t paddr; 7976c8d8eccSSepherosa Ziehau 7986c8d8eccSSepherosa Ziehau /* Allocate the mbuf. */ 7996c8d8eccSSepherosa Ziehau MGETHDR(m_new, init ? MB_WAIT : MB_DONTWAIT, MT_DATA); 8006c8d8eccSSepherosa Ziehau if (m_new == NULL) 8016c8d8eccSSepherosa Ziehau return ENOBUFS; 8026c8d8eccSSepherosa Ziehau 8036c8d8eccSSepherosa Ziehau /* Allocate the jumbo buffer */ 8046c8d8eccSSepherosa Ziehau buf = bnx_jalloc(sc); 8056c8d8eccSSepherosa Ziehau if (buf == NULL) { 8066c8d8eccSSepherosa Ziehau m_freem(m_new); 8076c8d8eccSSepherosa Ziehau return ENOBUFS; 8086c8d8eccSSepherosa Ziehau } 8096c8d8eccSSepherosa Ziehau 8106c8d8eccSSepherosa Ziehau /* Attach the buffer to the mbuf. */ 8116c8d8eccSSepherosa Ziehau m_new->m_ext.ext_arg = buf; 8126c8d8eccSSepherosa Ziehau m_new->m_ext.ext_buf = buf->bnx_buf; 8136c8d8eccSSepherosa Ziehau m_new->m_ext.ext_free = bnx_jfree; 8146c8d8eccSSepherosa Ziehau m_new->m_ext.ext_ref = bnx_jref; 8156c8d8eccSSepherosa Ziehau m_new->m_ext.ext_size = BNX_JUMBO_FRAMELEN; 8166c8d8eccSSepherosa Ziehau 8176c8d8eccSSepherosa Ziehau m_new->m_flags |= M_EXT; 8186c8d8eccSSepherosa Ziehau 8196c8d8eccSSepherosa Ziehau m_new->m_data = m_new->m_ext.ext_buf; 8206c8d8eccSSepherosa Ziehau m_new->m_len = m_new->m_pkthdr.len = m_new->m_ext.ext_size; 8216c8d8eccSSepherosa Ziehau 8226c8d8eccSSepherosa Ziehau paddr = buf->bnx_paddr; 8236c8d8eccSSepherosa Ziehau m_adj(m_new, ETHER_ALIGN); 8246c8d8eccSSepherosa Ziehau paddr += ETHER_ALIGN; 8256c8d8eccSSepherosa Ziehau 8266c8d8eccSSepherosa Ziehau /* Save necessary information */ 827beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_mbuf = m_new; 828beedf5beSSepherosa Ziehau sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_paddr = paddr; 8296c8d8eccSSepherosa Ziehau 8306c8d8eccSSepherosa Ziehau /* Set up the descriptor. */ 8316c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(sc, i); 8326c8d8eccSSepherosa Ziehau return 0; 8336c8d8eccSSepherosa Ziehau } 8346c8d8eccSSepherosa Ziehau 8356c8d8eccSSepherosa Ziehau static void 8366c8d8eccSSepherosa Ziehau bnx_setup_rxdesc_jumbo(struct bnx_softc *sc, int i) 8376c8d8eccSSepherosa Ziehau { 8386c8d8eccSSepherosa Ziehau struct bge_rx_bd *r; 839beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc; 8406c8d8eccSSepherosa Ziehau 8416c8d8eccSSepherosa Ziehau r = &sc->bnx_ldata.bnx_rx_jumbo_ring[i]; 8426c8d8eccSSepherosa Ziehau rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 8436c8d8eccSSepherosa Ziehau 844beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_rx_paddr); 845beedf5beSSepherosa Ziehau r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_rx_paddr); 846beedf5beSSepherosa Ziehau r->bge_len = rc->bnx_rx_mbuf->m_len; 8476c8d8eccSSepherosa Ziehau r->bge_idx = i; 8486c8d8eccSSepherosa Ziehau r->bge_flags = BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING; 8496c8d8eccSSepherosa Ziehau } 8506c8d8eccSSepherosa Ziehau 8516c8d8eccSSepherosa Ziehau static int 852beedf5beSSepherosa Ziehau bnx_init_rx_ring_std(struct bnx_rx_std_ring *std) 8536c8d8eccSSepherosa Ziehau { 8546c8d8eccSSepherosa Ziehau int i, error; 8556c8d8eccSSepherosa Ziehau 8566c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 857beedf5beSSepherosa Ziehau /* Use the first RX return ring's tmp RX mbuf DMA map */ 858beedf5beSSepherosa Ziehau error = bnx_newbuf_std(&std->bnx_sc->bnx_rx_ret_ring[0], i, 1); 8596c8d8eccSSepherosa Ziehau if (error) 8606c8d8eccSSepherosa Ziehau return error; 861841cdf08SSepherosa Ziehau bnx_setup_rxdesc_std(std, i); 86287c7a7cfSSascha Wildner } 8636c8d8eccSSepherosa Ziehau 864841cdf08SSepherosa Ziehau std->bnx_rx_std_refill = 0; 865841cdf08SSepherosa Ziehau std->bnx_rx_std_running = 0; 866841cdf08SSepherosa Ziehau cpu_sfence(); 867841cdf08SSepherosa Ziehau lwkt_serialize_handler_enable(&std->bnx_rx_std_serialize); 868841cdf08SSepherosa Ziehau 869beedf5beSSepherosa Ziehau std->bnx_rx_std = BGE_STD_RX_RING_CNT - 1; 870beedf5beSSepherosa Ziehau bnx_writembx(std->bnx_sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std); 8716c8d8eccSSepherosa Ziehau 8726c8d8eccSSepherosa Ziehau return(0); 8736c8d8eccSSepherosa Ziehau } 8746c8d8eccSSepherosa Ziehau 8756c8d8eccSSepherosa Ziehau static void 876beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(struct bnx_rx_std_ring *std) 8776c8d8eccSSepherosa Ziehau { 8786c8d8eccSSepherosa Ziehau int i; 8796c8d8eccSSepherosa Ziehau 880841cdf08SSepherosa Ziehau lwkt_serialize_handler_disable(&std->bnx_rx_std_serialize); 881841cdf08SSepherosa Ziehau 8826c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 883beedf5beSSepherosa Ziehau struct bnx_rx_buf *rb = &std->bnx_rx_std_buf[i]; 8846c8d8eccSSepherosa Ziehau 885841cdf08SSepherosa Ziehau rb->bnx_rx_refilled = 0; 886beedf5beSSepherosa Ziehau if (rb->bnx_rx_mbuf != NULL) { 887beedf5beSSepherosa Ziehau bus_dmamap_unload(std->bnx_rx_mtag, rb->bnx_rx_dmamap); 888beedf5beSSepherosa Ziehau m_freem(rb->bnx_rx_mbuf); 889beedf5beSSepherosa Ziehau rb->bnx_rx_mbuf = NULL; 8906c8d8eccSSepherosa Ziehau } 891beedf5beSSepherosa Ziehau bzero(&std->bnx_rx_std_ring[i], sizeof(struct bge_rx_bd)); 8926c8d8eccSSepherosa Ziehau } 8936c8d8eccSSepherosa Ziehau } 8946c8d8eccSSepherosa Ziehau 8956c8d8eccSSepherosa Ziehau static int 8966c8d8eccSSepherosa Ziehau bnx_init_rx_ring_jumbo(struct bnx_softc *sc) 8976c8d8eccSSepherosa Ziehau { 8986c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 8996c8d8eccSSepherosa Ziehau int i, error; 9006c8d8eccSSepherosa Ziehau 9016c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 9026c8d8eccSSepherosa Ziehau error = bnx_newbuf_jumbo(sc, i, 1); 9036c8d8eccSSepherosa Ziehau if (error) 9046c8d8eccSSepherosa Ziehau return error; 90587c7a7cfSSascha Wildner } 9066c8d8eccSSepherosa Ziehau 9076c8d8eccSSepherosa Ziehau sc->bnx_jumbo = BGE_JUMBO_RX_RING_CNT - 1; 9086c8d8eccSSepherosa Ziehau 9096c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 9106c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0); 9116c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 9126c8d8eccSSepherosa Ziehau 9136c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo); 9146c8d8eccSSepherosa Ziehau 9156c8d8eccSSepherosa Ziehau return(0); 9166c8d8eccSSepherosa Ziehau } 9176c8d8eccSSepherosa Ziehau 9186c8d8eccSSepherosa Ziehau static void 9196c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(struct bnx_softc *sc) 9206c8d8eccSSepherosa Ziehau { 9216c8d8eccSSepherosa Ziehau int i; 9226c8d8eccSSepherosa Ziehau 9236c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) { 924beedf5beSSepherosa Ziehau struct bnx_rx_buf *rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i]; 9256c8d8eccSSepherosa Ziehau 926beedf5beSSepherosa Ziehau if (rc->bnx_rx_mbuf != NULL) { 927beedf5beSSepherosa Ziehau m_freem(rc->bnx_rx_mbuf); 928beedf5beSSepherosa Ziehau rc->bnx_rx_mbuf = NULL; 9296c8d8eccSSepherosa Ziehau } 9306c8d8eccSSepherosa Ziehau bzero(&sc->bnx_ldata.bnx_rx_jumbo_ring[i], 9316c8d8eccSSepherosa Ziehau sizeof(struct bge_rx_bd)); 9326c8d8eccSSepherosa Ziehau } 9336c8d8eccSSepherosa Ziehau } 9346c8d8eccSSepherosa Ziehau 9356c8d8eccSSepherosa Ziehau static void 93633a04907SSepherosa Ziehau bnx_free_tx_ring(struct bnx_tx_ring *txr) 9376c8d8eccSSepherosa Ziehau { 9386c8d8eccSSepherosa Ziehau int i; 9396c8d8eccSSepherosa Ziehau 9406c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 941fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf = &txr->bnx_tx_buf[i]; 942fa4b1067SSepherosa Ziehau 943fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 94433a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 945fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 946fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 947fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 9486c8d8eccSSepherosa Ziehau } 94933a04907SSepherosa Ziehau bzero(&txr->bnx_tx_ring[i], sizeof(struct bge_tx_bd)); 9506c8d8eccSSepherosa Ziehau } 95133a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = BNX_TXCONS_UNSET; 9526c8d8eccSSepherosa Ziehau } 9536c8d8eccSSepherosa Ziehau 9546c8d8eccSSepherosa Ziehau static int 95533a04907SSepherosa Ziehau bnx_init_tx_ring(struct bnx_tx_ring *txr) 9566c8d8eccSSepherosa Ziehau { 957fa639b88SSepherosa Ziehau txr->bnx_tx_cnt = 0; 95833a04907SSepherosa Ziehau txr->bnx_tx_saved_considx = 0; 95933a04907SSepherosa Ziehau txr->bnx_tx_prodidx = 0; 9606c8d8eccSSepherosa Ziehau 9616c8d8eccSSepherosa Ziehau /* Initialize transmit producer index for host-memory send ring. */ 9628bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, txr->bnx_tx_prodidx); 9636c8d8eccSSepherosa Ziehau 9646c8d8eccSSepherosa Ziehau return(0); 9656c8d8eccSSepherosa Ziehau } 9666c8d8eccSSepherosa Ziehau 9676c8d8eccSSepherosa Ziehau static void 9686c8d8eccSSepherosa Ziehau bnx_setmulti(struct bnx_softc *sc) 9696c8d8eccSSepherosa Ziehau { 9706c8d8eccSSepherosa Ziehau struct ifnet *ifp; 9716c8d8eccSSepherosa Ziehau struct ifmultiaddr *ifma; 9726c8d8eccSSepherosa Ziehau uint32_t hashes[4] = { 0, 0, 0, 0 }; 9736c8d8eccSSepherosa Ziehau int h, i; 9746c8d8eccSSepherosa Ziehau 9756c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 9766c8d8eccSSepherosa Ziehau 9776c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 9786c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0xFFFFFFFF); 9806c8d8eccSSepherosa Ziehau return; 9816c8d8eccSSepherosa Ziehau } 9826c8d8eccSSepherosa Ziehau 9836c8d8eccSSepherosa Ziehau /* First, zot all the existing filters. */ 9846c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9856c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0); 9866c8d8eccSSepherosa Ziehau 9876c8d8eccSSepherosa Ziehau /* Now program new ones. */ 9886c8d8eccSSepherosa Ziehau TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 9896c8d8eccSSepherosa Ziehau if (ifma->ifma_addr->sa_family != AF_LINK) 9906c8d8eccSSepherosa Ziehau continue; 9916c8d8eccSSepherosa Ziehau h = ether_crc32_le( 9926c8d8eccSSepherosa Ziehau LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 9936c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN) & 0x7f; 9946c8d8eccSSepherosa Ziehau hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F); 9956c8d8eccSSepherosa Ziehau } 9966c8d8eccSSepherosa Ziehau 9976c8d8eccSSepherosa Ziehau for (i = 0; i < 4; i++) 9986c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]); 9996c8d8eccSSepherosa Ziehau } 10006c8d8eccSSepherosa Ziehau 10016c8d8eccSSepherosa Ziehau /* 10026c8d8eccSSepherosa Ziehau * Do endian, PCI and DMA initialization. Also check the on-board ROM 10036c8d8eccSSepherosa Ziehau * self-test results. 10046c8d8eccSSepherosa Ziehau */ 10056c8d8eccSSepherosa Ziehau static int 10066c8d8eccSSepherosa Ziehau bnx_chipinit(struct bnx_softc *sc) 10076c8d8eccSSepherosa Ziehau { 10086c8d8eccSSepherosa Ziehau uint32_t dma_rw_ctl, mode_ctl; 10096c8d8eccSSepherosa Ziehau int i; 10106c8d8eccSSepherosa Ziehau 10116c8d8eccSSepherosa Ziehau /* Set endian type before we access any non-PCI registers. */ 10126c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_MISC_CTL, 10136c8d8eccSSepherosa Ziehau BGE_INIT | BGE_PCIMISCCTL_TAGGED_STATUS, 4); 10146c8d8eccSSepherosa Ziehau 10156c8d8eccSSepherosa Ziehau /* Clear the MAC control register */ 10166c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 10176c8d8eccSSepherosa Ziehau 10186c8d8eccSSepherosa Ziehau /* 10196c8d8eccSSepherosa Ziehau * Clear the MAC statistics block in the NIC's 10206c8d8eccSSepherosa Ziehau * internal memory. 10216c8d8eccSSepherosa Ziehau */ 10226c8d8eccSSepherosa Ziehau for (i = BGE_STATS_BLOCK; 10236c8d8eccSSepherosa Ziehau i < BGE_STATS_BLOCK_END + 1; i += sizeof(uint32_t)) 10246c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 10256c8d8eccSSepherosa Ziehau 10266c8d8eccSSepherosa Ziehau for (i = BGE_STATUS_BLOCK; 10276c8d8eccSSepherosa Ziehau i < BGE_STATUS_BLOCK_END + 1; i += sizeof(uint32_t)) 10286c8d8eccSSepherosa Ziehau BNX_MEMWIN_WRITE(sc, i, 0); 10296c8d8eccSSepherosa Ziehau 1030d7872545SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) { 1031d7872545SSepherosa Ziehau uint32_t val; 1032d7872545SSepherosa Ziehau 1033d7872545SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) { 1034d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1035d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1036d7872545SSepherosa Ziehau 1037d7872545SSepherosa Ziehau /* Access the lower 1K of PL PCI-E block registers. */ 1038d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1039d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_PL_SEL); 1040d7872545SSepherosa Ziehau 1041d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_PL_LO_PHYCTL5); 1042d7872545SSepherosa Ziehau val |= BGE_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ; 1043d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PL_LO_PHYCTL5, val); 1044d7872545SSepherosa Ziehau 1045d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1046d7872545SSepherosa Ziehau } 1047d7872545SSepherosa Ziehau if (sc->bnx_chiprev != BGE_CHIPREV_57765_AX) { 10481749651bSSepherosa Ziehau /* Fix transmit hangs */ 10491749651bSSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_PADRNG_CTL); 10501749651bSSepherosa Ziehau val |= BGE_CPMU_PADRNG_CTL_RDIV2; 10511749651bSSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_PADRNG_CTL, val); 10521749651bSSepherosa Ziehau 1053d7872545SSepherosa Ziehau mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL); 1054d7872545SSepherosa Ziehau val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS; 1055d7872545SSepherosa Ziehau 1056d7872545SSepherosa Ziehau /* Access the lower 1K of DL PCI-E block registers. */ 1057d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, 1058d7872545SSepherosa Ziehau val | BGE_MODECTL_PCIE_DL_SEL); 1059d7872545SSepherosa Ziehau 1060d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_PCIE_DL_LO_FTSMAX); 1061d7872545SSepherosa Ziehau val &= ~BGE_PCIE_DL_LO_FTSMAX_MASK; 1062d7872545SSepherosa Ziehau val |= BGE_PCIE_DL_LO_FTSMAX_VAL; 1063d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_DL_LO_FTSMAX, val); 1064d7872545SSepherosa Ziehau 1065d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 1066d7872545SSepherosa Ziehau } 1067d7872545SSepherosa Ziehau 1068d7872545SSepherosa Ziehau val = CSR_READ_4(sc, BGE_CPMU_LSPD_10MB_CLK); 1069d7872545SSepherosa Ziehau val &= ~BGE_CPMU_LSPD_10MB_MACCLK_MASK; 1070d7872545SSepherosa Ziehau val |= BGE_CPMU_LSPD_10MB_MACCLK_6_25; 1071d7872545SSepherosa Ziehau CSR_WRITE_4(sc, BGE_CPMU_LSPD_10MB_CLK, val); 1072d7872545SSepherosa Ziehau } 1073d7872545SSepherosa Ziehau 10742890cca3SSepherosa Ziehau /* 10752890cca3SSepherosa Ziehau * Set up the PCI DMA control register. 10762890cca3SSepherosa Ziehau */ 10772890cca3SSepherosa Ziehau dma_rw_ctl = pci_read_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, 4); 10782890cca3SSepherosa Ziehau /* 10792890cca3SSepherosa Ziehau * Disable 32bytes cache alignment for DMA write to host memory 10802890cca3SSepherosa Ziehau * 10812890cca3SSepherosa Ziehau * NOTE: 10822890cca3SSepherosa Ziehau * 64bytes cache alignment for DMA write to host memory is still 10832890cca3SSepherosa Ziehau * enabled. 10842890cca3SSepherosa Ziehau */ 10852890cca3SSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT; 10866c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 10876c8d8eccSSepherosa Ziehau dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK; 10886c8d8eccSSepherosa Ziehau /* 10896c8d8eccSSepherosa Ziehau * Enable HW workaround for controllers that misinterpret 10906c8d8eccSSepherosa Ziehau * a status tag update and leave interrupts permanently 10916c8d8eccSSepherosa Ziehau * disabled. 10926c8d8eccSSepherosa Ziehau */ 10936c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev != BGE_ASICREV_BCM5717 && 1094b96cbbb6SSepherosa Ziehau sc->bnx_asicrev != BGE_ASICREV_BCM5762 && 10952890cca3SSepherosa Ziehau !BNX_IS_57765_FAMILY(sc)) 10966c8d8eccSSepherosa Ziehau dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA; 10972890cca3SSepherosa Ziehau if (bootverbose) { 10982890cca3SSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "DMA read/write %#x\n", 10992890cca3SSepherosa Ziehau dma_rw_ctl); 11006c8d8eccSSepherosa Ziehau } 11016c8d8eccSSepherosa Ziehau pci_write_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, dma_rw_ctl, 4); 11026c8d8eccSSepherosa Ziehau 11036c8d8eccSSepherosa Ziehau /* 11046c8d8eccSSepherosa Ziehau * Set up general mode register. 11056c8d8eccSSepherosa Ziehau */ 11066c8d8eccSSepherosa Ziehau mode_ctl = bnx_dma_swap_options(sc) | BGE_MODECTL_MAC_ATTN_INTR | 11076c8d8eccSSepherosa Ziehau BGE_MODECTL_HOST_SEND_BDS | BGE_MODECTL_TX_NO_PHDR_CSUM; 11086c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); 11096c8d8eccSSepherosa Ziehau 11106c8d8eccSSepherosa Ziehau /* 11116c8d8eccSSepherosa Ziehau * Disable memory write invalidate. Apparently it is not supported 11126c8d8eccSSepherosa Ziehau * properly by these devices. Also ensure that INTx isn't disabled, 11136c8d8eccSSepherosa Ziehau * as these chips need it even when using MSI. 11146c8d8eccSSepherosa Ziehau */ 11156c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_CMD, 11166c8d8eccSSepherosa Ziehau (PCIM_CMD_MWRICEN | PCIM_CMD_INTxDIS), 4); 11176c8d8eccSSepherosa Ziehau 11186c8d8eccSSepherosa Ziehau /* Set the timer prescaler (always 66Mhz) */ 11196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, 65 << 1/*BGE_32BITTIME_66MHZ*/); 11206c8d8eccSSepherosa Ziehau 11216c8d8eccSSepherosa Ziehau return(0); 11226c8d8eccSSepherosa Ziehau } 11236c8d8eccSSepherosa Ziehau 11246c8d8eccSSepherosa Ziehau static int 11256c8d8eccSSepherosa Ziehau bnx_blockinit(struct bnx_softc *sc) 11266c8d8eccSSepherosa Ziehau { 112733a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 1128beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 11290a806e3aSSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[0]; 11306c8d8eccSSepherosa Ziehau struct bge_rcb *rcb; 11316c8d8eccSSepherosa Ziehau bus_size_t vrcb; 11326c8d8eccSSepherosa Ziehau bge_hostaddr taddr; 11336c8d8eccSSepherosa Ziehau uint32_t val; 11346c8d8eccSSepherosa Ziehau int i, limit; 11356c8d8eccSSepherosa Ziehau 11366c8d8eccSSepherosa Ziehau /* 11376c8d8eccSSepherosa Ziehau * Initialize the memory window pointer register so that 11386c8d8eccSSepherosa Ziehau * we can access the first 32K of internal NIC RAM. This will 11396c8d8eccSSepherosa Ziehau * allow us to set up the TX send ring RCBs and the RX return 11406c8d8eccSSepherosa Ziehau * ring RCBs, plus other things which live in NIC memory. 11416c8d8eccSSepherosa Ziehau */ 11426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0); 11436c8d8eccSSepherosa Ziehau 11446c8d8eccSSepherosa Ziehau /* Configure mbuf pool watermarks */ 1145f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 11466c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11476c8d8eccSSepherosa Ziehau if (sc->arpcom.ac_if.if_mtu > ETHERMTU) { 11486c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x7e); 11496c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xea); 11506c8d8eccSSepherosa Ziehau } else { 11516c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x2a); 11526c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xa0); 11536c8d8eccSSepherosa Ziehau } 11546c8d8eccSSepherosa Ziehau } else { 11556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0); 11566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10); 11576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60); 11586c8d8eccSSepherosa Ziehau } 11596c8d8eccSSepherosa Ziehau 11606c8d8eccSSepherosa Ziehau /* Configure DMA resource watermarks */ 11616c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5); 11626c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10); 11636c8d8eccSSepherosa Ziehau 11646c8d8eccSSepherosa Ziehau /* Enable buffer manager */ 11656c8d8eccSSepherosa Ziehau val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN; 11666c8d8eccSSepherosa Ziehau /* 11676c8d8eccSSepherosa Ziehau * Change the arbitration algorithm of TXMBUF read request to 11686c8d8eccSSepherosa Ziehau * round-robin instead of priority based for BCM5719. When 11696c8d8eccSSepherosa Ziehau * TXFIFO is almost empty, RDMA will hold its request until 11706c8d8eccSSepherosa Ziehau * TXFIFO is not almost empty. 11716c8d8eccSSepherosa Ziehau */ 11726c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) 11736c8d8eccSSepherosa Ziehau val |= BGE_BMANMODE_NO_TX_UNDERRUN; 1174e5eebe34SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1175e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0 || 1176e5eebe34SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5720_A0) 1177e5eebe34SSepherosa Ziehau val |= BGE_BMANMODE_LOMBUF_ATTN; 11786c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_BMAN_MODE, val); 11796c8d8eccSSepherosa Ziehau 11806c8d8eccSSepherosa Ziehau /* Poll for buffer manager start indication */ 11816c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11826c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_BMAN_MODE) & BGE_BMANMODE_ENABLE) 11836c8d8eccSSepherosa Ziehau break; 11846c8d8eccSSepherosa Ziehau DELAY(10); 11856c8d8eccSSepherosa Ziehau } 11866c8d8eccSSepherosa Ziehau 11876c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 11886c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 11896c8d8eccSSepherosa Ziehau "buffer manager failed to start\n"); 11906c8d8eccSSepherosa Ziehau return(ENXIO); 11916c8d8eccSSepherosa Ziehau } 11926c8d8eccSSepherosa Ziehau 11936c8d8eccSSepherosa Ziehau /* Enable flow-through queues */ 11946c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 11956c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 11966c8d8eccSSepherosa Ziehau 11976c8d8eccSSepherosa Ziehau /* Wait until queue initialization is complete */ 11986c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 11996c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_FTQ_RESET) == 0) 12006c8d8eccSSepherosa Ziehau break; 12016c8d8eccSSepherosa Ziehau DELAY(10); 12026c8d8eccSSepherosa Ziehau } 12036c8d8eccSSepherosa Ziehau 12046c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 12056c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 12066c8d8eccSSepherosa Ziehau "flow-through queue init failed\n"); 12076c8d8eccSSepherosa Ziehau return(ENXIO); 12086c8d8eccSSepherosa Ziehau } 12096c8d8eccSSepherosa Ziehau 12106c8d8eccSSepherosa Ziehau /* 12116c8d8eccSSepherosa Ziehau * Summary of rings supported by the controller: 12126c8d8eccSSepherosa Ziehau * 12136c8d8eccSSepherosa Ziehau * Standard Receive Producer Ring 12146c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "standard" 12156c8d8eccSSepherosa Ziehau * sized frames (typically 1536 bytes) to the controller. 12166c8d8eccSSepherosa Ziehau * 12176c8d8eccSSepherosa Ziehau * Jumbo Receive Producer Ring 12186c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for jumbo sized 12196c8d8eccSSepherosa Ziehau * frames (i.e. anything bigger than the "standard" frames) 12206c8d8eccSSepherosa Ziehau * to the controller. 12216c8d8eccSSepherosa Ziehau * 12226c8d8eccSSepherosa Ziehau * Mini Receive Producer Ring 12236c8d8eccSSepherosa Ziehau * - This ring is used to feed receive buffers for "mini" 12246c8d8eccSSepherosa Ziehau * sized frames to the controller. 12256c8d8eccSSepherosa Ziehau * - This feature required external memory for the controller 12266c8d8eccSSepherosa Ziehau * but was never used in a production system. Should always 12276c8d8eccSSepherosa Ziehau * be disabled. 12286c8d8eccSSepherosa Ziehau * 12296c8d8eccSSepherosa Ziehau * Receive Return Ring 12306c8d8eccSSepherosa Ziehau * - After the controller has placed an incoming frame into a 12316c8d8eccSSepherosa Ziehau * receive buffer that buffer is moved into a receive return 12326c8d8eccSSepherosa Ziehau * ring. The driver is then responsible to passing the 12336c8d8eccSSepherosa Ziehau * buffer up to the stack. Many versions of the controller 12346c8d8eccSSepherosa Ziehau * support multiple RR rings. 12356c8d8eccSSepherosa Ziehau * 12366c8d8eccSSepherosa Ziehau * Send Ring 12376c8d8eccSSepherosa Ziehau * - This ring is used for outgoing frames. Many versions of 12386c8d8eccSSepherosa Ziehau * the controller support multiple send rings. 12396c8d8eccSSepherosa Ziehau */ 12406c8d8eccSSepherosa Ziehau 12416c8d8eccSSepherosa Ziehau /* Initialize the standard receive producer ring control block. */ 12426c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_std_rx_rcb; 12436c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 1244beedf5beSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 12456c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 1246beedf5beSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr); 1247f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 12486c8d8eccSSepherosa Ziehau /* 12496c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (2048, 1024, 512, .., 32) 12506c8d8eccSSepherosa Ziehau * Bits 15-2 : Maximum RX frame size 12516c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring ENabled 12526c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12536c8d8eccSSepherosa Ziehau */ 12546c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12556c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(512, BNX_MAX_FRAMELEN << 2); 12566c8d8eccSSepherosa Ziehau } else { 12576c8d8eccSSepherosa Ziehau /* 12586c8d8eccSSepherosa Ziehau * Bits 31-16: Programmable ring size (512, 256, 128, 64, 32) 12596c8d8eccSSepherosa Ziehau * Bits 15-2 : Reserved (should be 0) 12606c8d8eccSSepherosa Ziehau * Bit 1 : 1 = Ring Disabled, 0 = Ring Enabled 12616c8d8eccSSepherosa Ziehau * Bit 0 : Reserved 12626c8d8eccSSepherosa Ziehau */ 12636c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(512, 0); 12646c8d8eccSSepherosa Ziehau } 1265303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12666c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717; 12676c8d8eccSSepherosa Ziehau else 12686c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_STD_RX_RINGS; 12696c8d8eccSSepherosa Ziehau /* Write the standard receive producer ring control block. */ 12706c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); 12716c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); 12726c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); 12736c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_STD_RCB_NICADDR, rcb->bge_nicaddr); 12746c8d8eccSSepherosa Ziehau /* Reset the standard receive producer ring producer index. */ 12756c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0); 12766c8d8eccSSepherosa Ziehau 12776c8d8eccSSepherosa Ziehau /* 12786c8d8eccSSepherosa Ziehau * Initialize the jumbo RX producer ring control 12796c8d8eccSSepherosa Ziehau * block. We set the 'ring disabled' bit in the 12806c8d8eccSSepherosa Ziehau * flags field until we're actually ready to start 12816c8d8eccSSepherosa Ziehau * using this ring (i.e. once we set the MTU 12826c8d8eccSSepherosa Ziehau * high enough to require it). 12836c8d8eccSSepherosa Ziehau */ 12846c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 12856c8d8eccSSepherosa Ziehau rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb; 12866c8d8eccSSepherosa Ziehau /* Get the jumbo receive producer ring RCB parameters. */ 12876c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo = 12886c8d8eccSSepherosa Ziehau BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12896c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi = 12906c8d8eccSSepherosa Ziehau BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr); 12916c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags = 12926c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_MAX_FRAMELEN, 12936c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 1294303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 12956c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717; 12966c8d8eccSSepherosa Ziehau else 12976c8d8eccSSepherosa Ziehau rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; 12986c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI, 12996c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_hi); 13006c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO, 13016c8d8eccSSepherosa Ziehau rcb->bge_hostaddr.bge_addr_lo); 13026c8d8eccSSepherosa Ziehau /* Program the jumbo receive producer ring RCB parameters. */ 13036c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, 13046c8d8eccSSepherosa Ziehau rcb->bge_maxlen_flags); 13056c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr); 13066c8d8eccSSepherosa Ziehau /* Reset the jumbo receive producer ring producer index. */ 13076c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); 13086c8d8eccSSepherosa Ziehau } 13096c8d8eccSSepherosa Ziehau 13106c8d8eccSSepherosa Ziehau /* 13116c8d8eccSSepherosa Ziehau * The BD ring replenish thresholds control how often the 13126c8d8eccSSepherosa Ziehau * hardware fetches new BD's from the producer rings in host 13136c8d8eccSSepherosa Ziehau * memory. Setting the value too low on a busy system can 13146c8d8eccSSepherosa Ziehau * starve the hardware and recue the throughpout. 13156c8d8eccSSepherosa Ziehau * 13166c8d8eccSSepherosa Ziehau * Set the BD ring replentish thresholds. The recommended 13176c8d8eccSSepherosa Ziehau * values are 1/8th the number of descriptors allocated to 13186c8d8eccSSepherosa Ziehau * each ring. 13196c8d8eccSSepherosa Ziehau */ 13206c8d8eccSSepherosa Ziehau val = 8; 13216c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_STD_REPL_THRESH, val); 13226c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 13236c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_JUMBO_REPL_THRESH, 13246c8d8eccSSepherosa Ziehau BGE_JUMBO_RX_RING_CNT/8); 13256c8d8eccSSepherosa Ziehau } 1326f368d0d9SSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 13276c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_STD_REPLENISH_LWM, 32); 13286c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_JMB_REPLENISH_LWM, 16); 13296c8d8eccSSepherosa Ziehau } 13306c8d8eccSSepherosa Ziehau 13316c8d8eccSSepherosa Ziehau /* 13326c8d8eccSSepherosa Ziehau * Disable all send rings by setting the 'ring disabled' bit 13336c8d8eccSSepherosa Ziehau * in the flags field of all the TX send ring control blocks, 13346c8d8eccSSepherosa Ziehau * located in NIC memory. 13356c8d8eccSSepherosa Ziehau */ 133680969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) 133780969639SSepherosa Ziehau limit = 4; 1338b96cbbb6SSepherosa Ziehau else if (BNX_IS_57765_FAMILY(sc) || 1339b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) 13404f23029eSSepherosa Ziehau limit = 2; 134180969639SSepherosa Ziehau else 13426c8d8eccSSepherosa Ziehau limit = 1; 13436c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 13446c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13456c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13466c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED)); 13476c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13486c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13496c8d8eccSSepherosa Ziehau } 13506c8d8eccSSepherosa Ziehau 13516c8d8eccSSepherosa Ziehau /* Configure send ring RCB 0 (we use only the first ring) */ 13526c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB; 135333a04907SSepherosa Ziehau BGE_HOSTADDR(taddr, txr->bnx_tx_ring_paddr); 13546c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 13556c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 1356303fdc72SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13576c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, BGE_SEND_RING_5717); 13586c8d8eccSSepherosa Ziehau } else { 13596c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 13606c8d8eccSSepherosa Ziehau BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT)); 13616c8d8eccSSepherosa Ziehau } 13626c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13636c8d8eccSSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BGE_TX_RING_CNT, 0)); 13646c8d8eccSSepherosa Ziehau 13656c8d8eccSSepherosa Ziehau /* 13666c8d8eccSSepherosa Ziehau * Disable all receive return rings by setting the 13676c8d8eccSSepherosa Ziehau * 'ring disabled' bit in the flags field of all the receive 13686c8d8eccSSepherosa Ziehau * return ring control blocks, located in NIC memory. 13696c8d8eccSSepherosa Ziehau */ 137080969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 13716c8d8eccSSepherosa Ziehau /* Should be 17, use 16 until we get an SRAM map. */ 13726c8d8eccSSepherosa Ziehau limit = 16; 1373b96cbbb6SSepherosa Ziehau } else if (BNX_IS_57765_FAMILY(sc) || 1374b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 13756c8d8eccSSepherosa Ziehau limit = 4; 13766c8d8eccSSepherosa Ziehau } else { 13776c8d8eccSSepherosa Ziehau limit = 1; 13786c8d8eccSSepherosa Ziehau } 13796c8d8eccSSepherosa Ziehau /* Disable all receive return rings. */ 13806c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 13816c8d8eccSSepherosa Ziehau for (i = 0; i < limit; i++) { 13826c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, 0); 13836c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, 0); 13846c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 13856c8d8eccSSepherosa Ziehau BGE_RCB_FLAG_RING_DISABLED); 13866c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 13876c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_RX_CONS0_LO + 13886c8d8eccSSepherosa Ziehau (i * (sizeof(uint64_t))), 0); 13896c8d8eccSSepherosa Ziehau vrcb += sizeof(struct bge_rcb); 13906c8d8eccSSepherosa Ziehau } 13916c8d8eccSSepherosa Ziehau 13926c8d8eccSSepherosa Ziehau /* 13936c8d8eccSSepherosa Ziehau * Set up receive return ring 0. Note that the NIC address 13946c8d8eccSSepherosa Ziehau * for RX return rings is 0x0. The return rings live entirely 13956c8d8eccSSepherosa Ziehau * within the host, so the nicaddr field in the RCB isn't used. 13966c8d8eccSSepherosa Ziehau */ 13976c8d8eccSSepherosa Ziehau vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB; 1398beedf5beSSepherosa Ziehau BGE_HOSTADDR(taddr, ret->bnx_rx_ret_ring_paddr); 13996c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); 14006c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); 14016c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0); 14026c8d8eccSSepherosa Ziehau RCB_WRITE_4(sc, vrcb, bge_maxlen_flags, 1403e0f74fc8SSepherosa Ziehau BGE_RCB_MAXLEN_FLAGS(BNX_RETURN_RING_CNT, 0)); 14046c8d8eccSSepherosa Ziehau 14056c8d8eccSSepherosa Ziehau /* Set random backoff seed for TX */ 14066c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_RANDOM_BACKOFF, 14076c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[0] + sc->arpcom.ac_enaddr[1] + 14086c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[2] + sc->arpcom.ac_enaddr[3] + 14096c8d8eccSSepherosa Ziehau sc->arpcom.ac_enaddr[4] + sc->arpcom.ac_enaddr[5] + 14106c8d8eccSSepherosa Ziehau BGE_TX_BACKOFF_SEED_MASK); 14116c8d8eccSSepherosa Ziehau 14126c8d8eccSSepherosa Ziehau /* Set inter-packet gap */ 14136c8d8eccSSepherosa Ziehau val = 0x2620; 1414b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1415b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 14166c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_TX_LENGTHS) & 14176c8d8eccSSepherosa Ziehau (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK); 14186c8d8eccSSepherosa Ziehau } 14196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_LENGTHS, val); 14206c8d8eccSSepherosa Ziehau 14216c8d8eccSSepherosa Ziehau /* 14226c8d8eccSSepherosa Ziehau * Specify which ring to use for packets that don't match 14236c8d8eccSSepherosa Ziehau * any RX rules. 14246c8d8eccSSepherosa Ziehau */ 14256c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_RULES_CFG, 0x08); 14266c8d8eccSSepherosa Ziehau 14276c8d8eccSSepherosa Ziehau /* 14286c8d8eccSSepherosa Ziehau * Configure number of RX lists. One interrupt distribution 14296c8d8eccSSepherosa Ziehau * list, sixteen active lists, one bad frames class. 14306c8d8eccSSepherosa Ziehau */ 14316c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181); 14326c8d8eccSSepherosa Ziehau 14336c8d8eccSSepherosa Ziehau /* Inialize RX list placement stats mask. */ 14346c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF); 14356c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1); 14366c8d8eccSSepherosa Ziehau 14376c8d8eccSSepherosa Ziehau /* Disable host coalescing until we get it set up */ 14386c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, 0x00000000); 14396c8d8eccSSepherosa Ziehau 14406c8d8eccSSepherosa Ziehau /* Poll to make sure it's shut down. */ 14416c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 14426c8d8eccSSepherosa Ziehau if (!(CSR_READ_4(sc, BGE_HCC_MODE) & BGE_HCCMODE_ENABLE)) 14436c8d8eccSSepherosa Ziehau break; 14446c8d8eccSSepherosa Ziehau DELAY(10); 14456c8d8eccSSepherosa Ziehau } 14466c8d8eccSSepherosa Ziehau 14476c8d8eccSSepherosa Ziehau if (i == BNX_TIMEOUT) { 14486c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, 14496c8d8eccSSepherosa Ziehau "host coalescing engine failed to idle\n"); 14506c8d8eccSSepherosa Ziehau return(ENXIO); 14516c8d8eccSSepherosa Ziehau } 14526c8d8eccSSepherosa Ziehau 14536c8d8eccSSepherosa Ziehau /* Set up host coalescing defaults */ 14546c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, sc->bnx_rx_coal_ticks); 14556c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bnx_tx_coal_ticks); 14566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bnx_rx_coal_bds); 14576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bnx_tx_coal_bds); 14586c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, sc->bnx_rx_coal_bds_int); 14596c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, sc->bnx_tx_coal_bds_int); 14606c8d8eccSSepherosa Ziehau 14616c8d8eccSSepherosa Ziehau /* Set up address of status block */ 14620a806e3aSSepherosa Ziehau bzero(intr->bnx_status_block, BGE_STATUS_BLK_SZ); 14636c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_HI, 14640a806e3aSSepherosa Ziehau BGE_ADDR_HI(intr->bnx_status_block_paddr)); 14656c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_LO, 14660a806e3aSSepherosa Ziehau BGE_ADDR_LO(intr->bnx_status_block_paddr)); 14676c8d8eccSSepherosa Ziehau 14686c8d8eccSSepherosa Ziehau /* Set up status block partail update size. */ 14696c8d8eccSSepherosa Ziehau val = BGE_STATBLKSZ_32BYTE; 14706c8d8eccSSepherosa Ziehau #if 0 14716c8d8eccSSepherosa Ziehau /* 14726c8d8eccSSepherosa Ziehau * Does not seem to have visible effect in both 14736c8d8eccSSepherosa Ziehau * bulk data (1472B UDP datagram) and tiny data 14746c8d8eccSSepherosa Ziehau * (18B UDP datagram) TX tests. 14756c8d8eccSSepherosa Ziehau */ 14766c8d8eccSSepherosa Ziehau val |= BGE_HCCMODE_CLRTICK_TX; 14776c8d8eccSSepherosa Ziehau #endif 14786c8d8eccSSepherosa Ziehau /* Turn on host coalescing state machine */ 14796c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE); 14806c8d8eccSSepherosa Ziehau 14816c8d8eccSSepherosa Ziehau /* Turn on RX BD completion state machine and enable attentions */ 14826c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDC_MODE, 14836c8d8eccSSepherosa Ziehau BGE_RBDCMODE_ENABLE|BGE_RBDCMODE_ATTN); 14846c8d8eccSSepherosa Ziehau 14856c8d8eccSSepherosa Ziehau /* Turn on RX list placement state machine */ 14866c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 14876c8d8eccSSepherosa Ziehau 14886c8d8eccSSepherosa Ziehau val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB | 14896c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_CLEAR | BGE_MACMODE_TX_STATS_CLEAR | 14906c8d8eccSSepherosa Ziehau BGE_MACMODE_RX_STATS_ENB | BGE_MACMODE_TX_STATS_ENB | 14916c8d8eccSSepherosa Ziehau BGE_MACMODE_FRMHDR_DMA_ENB; 14926c8d8eccSSepherosa Ziehau 14936c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 14946c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_TBI; 14956c8d8eccSSepherosa Ziehau else if (sc->bnx_flags & BNX_FLAG_MII_SERDES) 14966c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_GMII; 14976c8d8eccSSepherosa Ziehau else 14986c8d8eccSSepherosa Ziehau val |= BGE_PORTMODE_MII; 14996c8d8eccSSepherosa Ziehau 15006c8d8eccSSepherosa Ziehau /* Turn on DMA, clear stats */ 15016c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, val); 15026c8d8eccSSepherosa Ziehau 15036c8d8eccSSepherosa Ziehau /* Set misc. local control, enable interrupts on attentions */ 15046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN); 15056c8d8eccSSepherosa Ziehau 15066c8d8eccSSepherosa Ziehau #ifdef notdef 15076c8d8eccSSepherosa Ziehau /* Assert GPIO pins for PHY reset */ 15086c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUT0| 15096c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUT1|BGE_MLC_MISCIO_OUT2); 15106c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUTEN0| 15116c8d8eccSSepherosa Ziehau BGE_MLC_MISCIO_OUTEN1|BGE_MLC_MISCIO_OUTEN2); 15126c8d8eccSSepherosa Ziehau #endif 15136c8d8eccSSepherosa Ziehau 15146c8d8eccSSepherosa Ziehau /* Turn on write DMA state machine */ 15156c8d8eccSSepherosa Ziehau val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS; 15166c8d8eccSSepherosa Ziehau /* Enable host coalescing bug fix. */ 15176c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_STATUS_TAG_FIX; 15186c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5785) { 15196c8d8eccSSepherosa Ziehau /* Request larger DMA burst size to get better performance. */ 15206c8d8eccSSepherosa Ziehau val |= BGE_WDMAMODE_BURST_ALL_DATA; 15216c8d8eccSSepherosa Ziehau } 15226c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_WDMA_MODE, val); 15236c8d8eccSSepherosa Ziehau DELAY(40); 15246c8d8eccSSepherosa Ziehau 15253730a14dSSepherosa Ziehau if (BNX_IS_57765_PLUS(sc)) { 1526b96cbbb6SSepherosa Ziehau uint32_t dmactl, dmactl_reg; 15276c8d8eccSSepherosa Ziehau 1528b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1529b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL2; 1530b96cbbb6SSepherosa Ziehau else 1531b96cbbb6SSepherosa Ziehau dmactl_reg = BGE_RDMA_RSRVCTRL; 1532b96cbbb6SSepherosa Ziehau 1533b96cbbb6SSepherosa Ziehau dmactl = CSR_READ_4(sc, dmactl_reg); 15346c8d8eccSSepherosa Ziehau /* 15356c8d8eccSSepherosa Ziehau * Adjust tx margin to prevent TX data corruption and 15366c8d8eccSSepherosa Ziehau * fix internal FIFO overflow. 15376c8d8eccSSepherosa Ziehau */ 15386c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 1539b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1540b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 15416c8d8eccSSepherosa Ziehau dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK | 15426c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK | 15436c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_MASK); 15446c8d8eccSSepherosa Ziehau dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K | 15456c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K | 15466c8d8eccSSepherosa Ziehau BGE_RDMA_RSRVCTRL_TXMRGN_320B; 15476c8d8eccSSepherosa Ziehau } 15486c8d8eccSSepherosa Ziehau /* 15496c8d8eccSSepherosa Ziehau * Enable fix for read DMA FIFO overruns. 15506c8d8eccSSepherosa Ziehau * The fix is to limit the number of RX BDs 15516c8d8eccSSepherosa Ziehau * the hardware would fetch at a fime. 15526c8d8eccSSepherosa Ziehau */ 1553b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, dmactl_reg, 15546c8d8eccSSepherosa Ziehau dmactl | BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX); 15556c8d8eccSSepherosa Ziehau } 15566c8d8eccSSepherosa Ziehau 15576c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) { 15586c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, 15596c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | 15606c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K | 15616c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 1562b96cbbb6SSepherosa Ziehau } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1563b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 1564b96cbbb6SSepherosa Ziehau uint32_t ctrl_reg; 1565b96cbbb6SSepherosa Ziehau 1566b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5762) 1567b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL2; 1568b96cbbb6SSepherosa Ziehau else 1569b96cbbb6SSepherosa Ziehau ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL; 1570b96cbbb6SSepherosa Ziehau 15716c8d8eccSSepherosa Ziehau /* 15726c8d8eccSSepherosa Ziehau * Allow 4KB burst length reads for non-LSO frames. 15736c8d8eccSSepherosa Ziehau * Enable 512B burst length reads for buffer descriptors. 15746c8d8eccSSepherosa Ziehau */ 1575b96cbbb6SSepherosa Ziehau CSR_WRITE_4(sc, ctrl_reg, 1576b96cbbb6SSepherosa Ziehau CSR_READ_4(sc, ctrl_reg) | 15776c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 | 15786c8d8eccSSepherosa Ziehau BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); 15796c8d8eccSSepherosa Ziehau } 15806c8d8eccSSepherosa Ziehau 15816c8d8eccSSepherosa Ziehau /* Turn on read DMA state machine */ 15826c8d8eccSSepherosa Ziehau val = BGE_RDMAMODE_ENABLE | BGE_RDMAMODE_ALL_ATTNS; 15836c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717) 15846c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_MULT_DMA_RD_DIS; 15856c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5784 || 15866c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5785 || 15876c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM57780) { 15886c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_BD_SBD_CRPT_ATTN | 15896c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_RBD_CRPT_ATTN | 15906c8d8eccSSepherosa Ziehau BGE_RDMAMODE_MBUF_SBD_CRPT_ATTN; 15916c8d8eccSSepherosa Ziehau } 1592b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 1593b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 15946c8d8eccSSepherosa Ziehau val |= CSR_READ_4(sc, BGE_RDMA_MODE) & 15956c8d8eccSSepherosa Ziehau BGE_RDMAMODE_H2BNC_VLAN_DET; 15966c8d8eccSSepherosa Ziehau /* 15976c8d8eccSSepherosa Ziehau * Allow multiple outstanding read requests from 15986c8d8eccSSepherosa Ziehau * non-LSO read DMA engine. 15996c8d8eccSSepherosa Ziehau */ 16006c8d8eccSSepherosa Ziehau val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS; 16016c8d8eccSSepherosa Ziehau } 160260e67e3fSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM57766) 160360e67e3fSSepherosa Ziehau val |= BGE_RDMAMODE_JMB_2K_MMRR; 160466deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) 160566deb1c1SSepherosa Ziehau val |= BGE_RDMAMODE_TSO4_ENABLE; 16066c8d8eccSSepherosa Ziehau val |= BGE_RDMAMODE_FIFO_LONG_BURST; 16076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDMA_MODE, val); 16086c8d8eccSSepherosa Ziehau DELAY(40); 16096c8d8eccSSepherosa Ziehau 16106c8d8eccSSepherosa Ziehau /* Turn on RX data completion state machine */ 16116c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 16126c8d8eccSSepherosa Ziehau 16136c8d8eccSSepherosa Ziehau /* Turn on RX BD initiator state machine */ 16146c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 16156c8d8eccSSepherosa Ziehau 16166c8d8eccSSepherosa Ziehau /* Turn on RX data and RX BD initiator state machine */ 16176c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE); 16186c8d8eccSSepherosa Ziehau 16196c8d8eccSSepherosa Ziehau /* Turn on send BD completion state machine */ 16206c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 16216c8d8eccSSepherosa Ziehau 16226c8d8eccSSepherosa Ziehau /* Turn on send data completion state machine */ 16236c8d8eccSSepherosa Ziehau val = BGE_SDCMODE_ENABLE; 16246c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5761) 16256c8d8eccSSepherosa Ziehau val |= BGE_SDCMODE_CDELAY; 16266c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDC_MODE, val); 16276c8d8eccSSepherosa Ziehau 16286c8d8eccSSepherosa Ziehau /* Turn on send data initiator state machine */ 162966deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 163066deb1c1SSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE | 163166deb1c1SSepherosa Ziehau BGE_SDIMODE_HW_LSO_PRE_DMA); 163266deb1c1SSepherosa Ziehau } else { 16336c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 163466deb1c1SSepherosa Ziehau } 16356c8d8eccSSepherosa Ziehau 16366c8d8eccSSepherosa Ziehau /* Turn on send BD initiator state machine */ 16376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 16386c8d8eccSSepherosa Ziehau 16396c8d8eccSSepherosa Ziehau /* Turn on send BD selector state machine */ 16406c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 16416c8d8eccSSepherosa Ziehau 16426c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF); 16436c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SDI_STATS_CTL, 16446c8d8eccSSepherosa Ziehau BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER); 16456c8d8eccSSepherosa Ziehau 16466c8d8eccSSepherosa Ziehau /* ack/clear link change events */ 16476c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16486c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16496c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16506c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, 0); 16516c8d8eccSSepherosa Ziehau 16526c8d8eccSSepherosa Ziehau /* 16536c8d8eccSSepherosa Ziehau * Enable attention when the link has changed state for 16546c8d8eccSSepherosa Ziehau * devices that use auto polling. 16556c8d8eccSSepherosa Ziehau */ 16566c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 16576c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK); 16586c8d8eccSSepherosa Ziehau } else { 16596c8d8eccSSepherosa Ziehau if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 16606c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode); 16616c8d8eccSSepherosa Ziehau DELAY(80); 16626c8d8eccSSepherosa Ziehau } 16636c8d8eccSSepherosa Ziehau } 16646c8d8eccSSepherosa Ziehau 16656c8d8eccSSepherosa Ziehau /* 16666c8d8eccSSepherosa Ziehau * Clear any pending link state attention. 16676c8d8eccSSepherosa Ziehau * Otherwise some link state change events may be lost until attention 16686c8d8eccSSepherosa Ziehau * is cleared by bnx_intr() -> bnx_softc.bnx_link_upd() sequence. 16696c8d8eccSSepherosa Ziehau * It's not necessary on newer BCM chips - perhaps enabling link 16706c8d8eccSSepherosa Ziehau * state change attentions implies clearing pending attention. 16716c8d8eccSSepherosa Ziehau */ 16726c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| 16736c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| 16746c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 16756c8d8eccSSepherosa Ziehau 16766c8d8eccSSepherosa Ziehau /* Enable link state change attentions. */ 16776c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_LINK_CHANGED); 16786c8d8eccSSepherosa Ziehau 16796c8d8eccSSepherosa Ziehau return(0); 16806c8d8eccSSepherosa Ziehau } 16816c8d8eccSSepherosa Ziehau 16826c8d8eccSSepherosa Ziehau /* 16836c8d8eccSSepherosa Ziehau * Probe for a Broadcom chip. Check the PCI vendor and device IDs 16846c8d8eccSSepherosa Ziehau * against our list and return its name if we find a match. Note 16856c8d8eccSSepherosa Ziehau * that since the Broadcom controller contains VPD support, we 16866c8d8eccSSepherosa Ziehau * can get the device name string from the controller itself instead 16876c8d8eccSSepherosa Ziehau * of the compiled-in string. This is a little slow, but it guarantees 16886c8d8eccSSepherosa Ziehau * we'll always announce the right product name. 16896c8d8eccSSepherosa Ziehau */ 16906c8d8eccSSepherosa Ziehau static int 16916c8d8eccSSepherosa Ziehau bnx_probe(device_t dev) 16926c8d8eccSSepherosa Ziehau { 16936c8d8eccSSepherosa Ziehau const struct bnx_type *t; 16946c8d8eccSSepherosa Ziehau uint16_t product, vendor; 16956c8d8eccSSepherosa Ziehau 16966c8d8eccSSepherosa Ziehau if (!pci_is_pcie(dev)) 16976c8d8eccSSepherosa Ziehau return ENXIO; 16986c8d8eccSSepherosa Ziehau 16996c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 17006c8d8eccSSepherosa Ziehau vendor = pci_get_vendor(dev); 17016c8d8eccSSepherosa Ziehau 17026c8d8eccSSepherosa Ziehau for (t = bnx_devs; t->bnx_name != NULL; t++) { 17036c8d8eccSSepherosa Ziehau if (vendor == t->bnx_vid && product == t->bnx_did) 17046c8d8eccSSepherosa Ziehau break; 17056c8d8eccSSepherosa Ziehau } 17066c8d8eccSSepherosa Ziehau if (t->bnx_name == NULL) 17076c8d8eccSSepherosa Ziehau return ENXIO; 17086c8d8eccSSepherosa Ziehau 17096c8d8eccSSepherosa Ziehau device_set_desc(dev, t->bnx_name); 17106c8d8eccSSepherosa Ziehau return 0; 17116c8d8eccSSepherosa Ziehau } 17126c8d8eccSSepherosa Ziehau 17136c8d8eccSSepherosa Ziehau static int 17146c8d8eccSSepherosa Ziehau bnx_attach(device_t dev) 17156c8d8eccSSepherosa Ziehau { 17166c8d8eccSSepherosa Ziehau struct ifnet *ifp; 17176c8d8eccSSepherosa Ziehau struct bnx_softc *sc; 1718841cdf08SSepherosa Ziehau struct bnx_rx_std_ring *std; 1719e594b5c4SSepherosa Ziehau uint32_t hwcfg = 0; 1720841cdf08SSepherosa Ziehau int error = 0, rid, capmask, i, std_cpuid, std_cpuid_def; 17216c8d8eccSSepherosa Ziehau uint8_t ether_addr[ETHER_ADDR_LEN]; 172207e9f7c0SSascha Wildner uint16_t product; 17236c8d8eccSSepherosa Ziehau uintptr_t mii_priv = 0; 172466deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 172566deb1c1SSepherosa Ziehau char desc[32]; 172666deb1c1SSepherosa Ziehau #endif 17274fa38985SSepherosa Ziehau #ifdef IFPOLL_ENABLE 17284fa38985SSepherosa Ziehau int offset, offset_def; 17294fa38985SSepherosa Ziehau #endif 17306c8d8eccSSepherosa Ziehau 17316c8d8eccSSepherosa Ziehau sc = device_get_softc(dev); 17326c8d8eccSSepherosa Ziehau sc->bnx_dev = dev; 17337dbaa833SSepherosa Ziehau callout_init_mp(&sc->bnx_tick_timer); 17346c8d8eccSSepherosa Ziehau lwkt_serialize_init(&sc->bnx_jslot_serializer); 1735f33ac8a4SSepherosa Ziehau lwkt_serialize_init(&sc->bnx_main_serialize); 17366c8d8eccSSepherosa Ziehau 17376c8d8eccSSepherosa Ziehau product = pci_get_device(dev); 17386c8d8eccSSepherosa Ziehau 17396c8d8eccSSepherosa Ziehau #ifndef BURN_BRIDGES 17406c8d8eccSSepherosa Ziehau if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 17416c8d8eccSSepherosa Ziehau uint32_t irq, mem; 17426c8d8eccSSepherosa Ziehau 17436c8d8eccSSepherosa Ziehau irq = pci_read_config(dev, PCIR_INTLINE, 4); 17446c8d8eccSSepherosa Ziehau mem = pci_read_config(dev, BGE_PCI_BAR0, 4); 17456c8d8eccSSepherosa Ziehau 17466c8d8eccSSepherosa Ziehau device_printf(dev, "chip is in D%d power mode " 17476c8d8eccSSepherosa Ziehau "-- setting to D0\n", pci_get_powerstate(dev)); 17486c8d8eccSSepherosa Ziehau 17496c8d8eccSSepherosa Ziehau pci_set_powerstate(dev, PCI_POWERSTATE_D0); 17506c8d8eccSSepherosa Ziehau 17516c8d8eccSSepherosa Ziehau pci_write_config(dev, PCIR_INTLINE, irq, 4); 17526c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_BAR0, mem, 4); 17536c8d8eccSSepherosa Ziehau } 17546c8d8eccSSepherosa Ziehau #endif /* !BURN_BRIDGE */ 17556c8d8eccSSepherosa Ziehau 17566c8d8eccSSepherosa Ziehau /* 17576c8d8eccSSepherosa Ziehau * Map control/status registers. 17586c8d8eccSSepherosa Ziehau */ 17596c8d8eccSSepherosa Ziehau pci_enable_busmaster(dev); 17606c8d8eccSSepherosa Ziehau 17616c8d8eccSSepherosa Ziehau rid = BGE_PCI_BAR0; 17626c8d8eccSSepherosa Ziehau sc->bnx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 17636c8d8eccSSepherosa Ziehau RF_ACTIVE); 17646c8d8eccSSepherosa Ziehau 17656c8d8eccSSepherosa Ziehau if (sc->bnx_res == NULL) { 17666c8d8eccSSepherosa Ziehau device_printf(dev, "couldn't map memory\n"); 17676c8d8eccSSepherosa Ziehau return ENXIO; 17686c8d8eccSSepherosa Ziehau } 17696c8d8eccSSepherosa Ziehau 17706c8d8eccSSepherosa Ziehau sc->bnx_btag = rman_get_bustag(sc->bnx_res); 17716c8d8eccSSepherosa Ziehau sc->bnx_bhandle = rman_get_bushandle(sc->bnx_res); 17726c8d8eccSSepherosa Ziehau 17736c8d8eccSSepherosa Ziehau /* Save various chip information */ 17746c8d8eccSSepherosa Ziehau sc->bnx_chipid = 17756c8d8eccSSepherosa Ziehau pci_read_config(dev, BGE_PCI_MISC_CTL, 4) >> 17766c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_ASICREV_SHIFT; 17776c8d8eccSSepherosa Ziehau if (BGE_ASICREV(sc->bnx_chipid) == BGE_ASICREV_USE_PRODID_REG) { 17786c8d8eccSSepherosa Ziehau /* All chips having dedicated ASICREV register have CPMU */ 17796c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_CPMU; 17806c8d8eccSSepherosa Ziehau 17816c8d8eccSSepherosa Ziehau switch (product) { 17826c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717: 1783d79f5d8fSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5717C: 17846c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5718: 17856c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5719: 17866c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5720_ALT: 1787b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5725: 1788b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5727: 1789b96cbbb6SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM5762: 17906c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 17916c8d8eccSSepherosa Ziehau BGE_PCI_GEN2_PRODID_ASICREV, 4); 17926c8d8eccSSepherosa Ziehau break; 17936c8d8eccSSepherosa Ziehau 17946c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57761: 179532ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57762: 17966c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57765: 179732ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57766: 17986c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57781: 179932ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57782: 18006c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57785: 180132ff3c80SSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57786: 18026c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57791: 18036c8d8eccSSepherosa Ziehau case PCI_PRODUCT_BROADCOM_BCM57795: 18046c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 18056c8d8eccSSepherosa Ziehau BGE_PCI_GEN15_PRODID_ASICREV, 4); 18066c8d8eccSSepherosa Ziehau break; 18076c8d8eccSSepherosa Ziehau 18086c8d8eccSSepherosa Ziehau default: 18096c8d8eccSSepherosa Ziehau sc->bnx_chipid = pci_read_config(dev, 18106c8d8eccSSepherosa Ziehau BGE_PCI_PRODID_ASICREV, 4); 18116c8d8eccSSepherosa Ziehau break; 18126c8d8eccSSepherosa Ziehau } 18136c8d8eccSSepherosa Ziehau } 1814d79f5d8fSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_C0) 1815d79f5d8fSSepherosa Ziehau sc->bnx_chipid = BGE_CHIPID_BCM5720_A0; 1816d79f5d8fSSepherosa Ziehau 18176c8d8eccSSepherosa Ziehau sc->bnx_asicrev = BGE_ASICREV(sc->bnx_chipid); 18186c8d8eccSSepherosa Ziehau sc->bnx_chiprev = BGE_CHIPREV(sc->bnx_chipid); 18196c8d8eccSSepherosa Ziehau 18206c8d8eccSSepherosa Ziehau switch (sc->bnx_asicrev) { 18216c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5717: 18226c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5719: 18236c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM5720: 1824f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_5717_PLUS | BNX_FLAG_57765_PLUS; 1825f368d0d9SSepherosa Ziehau break; 1826f368d0d9SSepherosa Ziehau 1827b96cbbb6SSepherosa Ziehau case BGE_ASICREV_BCM5762: 1828b96cbbb6SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_PLUS; 1829b96cbbb6SSepherosa Ziehau break; 1830b96cbbb6SSepherosa Ziehau 18316c8d8eccSSepherosa Ziehau case BGE_ASICREV_BCM57765: 183232ff3c80SSepherosa Ziehau case BGE_ASICREV_BCM57766: 1833f368d0d9SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_57765_FAMILY | BNX_FLAG_57765_PLUS; 18346c8d8eccSSepherosa Ziehau break; 18356c8d8eccSSepherosa Ziehau } 18366c8d8eccSSepherosa Ziehau 183766deb1c1SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TSO; 183866deb1c1SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 && 183966deb1c1SSepherosa Ziehau sc->bnx_chipid == BGE_CHIPID_BCM5719_A0) 184066deb1c1SSepherosa Ziehau sc->bnx_flags &= ~BNX_FLAG_TSO; 184166deb1c1SSepherosa Ziehau 1842df9ccc98SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 || 1843df9ccc98SSepherosa Ziehau BNX_IS_57765_FAMILY(sc)) { 1844df9ccc98SSepherosa Ziehau /* 1845df9ccc98SSepherosa Ziehau * All BCM57785 and BCM5718 families chips have a bug that 1846df9ccc98SSepherosa Ziehau * under certain situation interrupt will not be enabled 1847df9ccc98SSepherosa Ziehau * even if status tag is written to BGE_MBX_IRQ0_LO mailbox. 1848df9ccc98SSepherosa Ziehau * 1849df9ccc98SSepherosa Ziehau * While BCM5719 and BCM5720 have a hardware workaround 1850df9ccc98SSepherosa Ziehau * which could fix the above bug. 1851df9ccc98SSepherosa Ziehau * See the comment near BGE_PCIDMARWCTL_TAGGED_STATUS_WA in 1852df9ccc98SSepherosa Ziehau * bnx_chipinit(). 1853df9ccc98SSepherosa Ziehau * 1854df9ccc98SSepherosa Ziehau * For the rest of the chips in these two families, we will 1855df9ccc98SSepherosa Ziehau * have to poll the status block at high rate (10ms currently) 1856df9ccc98SSepherosa Ziehau * to check whether the interrupt is hosed or not. 1857f33ac8a4SSepherosa Ziehau * See bnx_check_intr() for details. 1858df9ccc98SSepherosa Ziehau */ 1859df9ccc98SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_STATUSTAG_BUG; 1860df9ccc98SSepherosa Ziehau } 1861df9ccc98SSepherosa Ziehau 18626c8d8eccSSepherosa Ziehau sc->bnx_pciecap = pci_get_pciecap_ptr(sc->bnx_dev); 18636c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 || 18646c8d8eccSSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5720) 18656c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_2048); 18666c8d8eccSSepherosa Ziehau else 18676c8d8eccSSepherosa Ziehau pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_4096); 18686c8d8eccSSepherosa Ziehau device_printf(dev, "CHIP ID 0x%08x; " 18696c8d8eccSSepherosa Ziehau "ASIC REV 0x%02x; CHIP REV 0x%02x\n", 18706c8d8eccSSepherosa Ziehau sc->bnx_chipid, sc->bnx_asicrev, sc->bnx_chiprev); 18716c8d8eccSSepherosa Ziehau 18726c8d8eccSSepherosa Ziehau /* 18736c8d8eccSSepherosa Ziehau * Set various PHY quirk flags. 18746c8d8eccSSepherosa Ziehau */ 18756c8d8eccSSepherosa Ziehau 18766c8d8eccSSepherosa Ziehau capmask = MII_CAPMASK_DEFAULT; 187746283a40SSepherosa Ziehau if (product == PCI_PRODUCT_BROADCOM_BCM57791 || 187846283a40SSepherosa Ziehau product == PCI_PRODUCT_BROADCOM_BCM57795) { 18796c8d8eccSSepherosa Ziehau /* 10/100 only */ 18806c8d8eccSSepherosa Ziehau capmask &= ~BMSR_EXTSTAT; 18816c8d8eccSSepherosa Ziehau } 18826c8d8eccSSepherosa Ziehau 18836c8d8eccSSepherosa Ziehau mii_priv |= BRGPHY_FLAG_WIRESPEED; 1884b96cbbb6SSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5762_A0) 1885b96cbbb6SSepherosa Ziehau mii_priv |= BRGPHY_FLAG_5762_A0; 18866c8d8eccSSepherosa Ziehau 18876c8d8eccSSepherosa Ziehau /* Initialize if_name earlier, so if_printf could be used */ 18886c8d8eccSSepherosa Ziehau ifp = &sc->arpcom.ac_if; 18896c8d8eccSSepherosa Ziehau if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 18906c8d8eccSSepherosa Ziehau 18916c8d8eccSSepherosa Ziehau /* Try to reset the chip. */ 18926c8d8eccSSepherosa Ziehau bnx_reset(sc); 18936c8d8eccSSepherosa Ziehau 18946c8d8eccSSepherosa Ziehau if (bnx_chipinit(sc)) { 18956c8d8eccSSepherosa Ziehau device_printf(dev, "chip initialization failed\n"); 18966c8d8eccSSepherosa Ziehau error = ENXIO; 18976c8d8eccSSepherosa Ziehau goto fail; 18986c8d8eccSSepherosa Ziehau } 18996c8d8eccSSepherosa Ziehau 19006c8d8eccSSepherosa Ziehau /* 19016c8d8eccSSepherosa Ziehau * Get station address 19026c8d8eccSSepherosa Ziehau */ 19036c8d8eccSSepherosa Ziehau error = bnx_get_eaddr(sc, ether_addr); 19046c8d8eccSSepherosa Ziehau if (error) { 19056c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read station address\n"); 19066c8d8eccSSepherosa Ziehau goto fail; 19076c8d8eccSSepherosa Ziehau } 19086c8d8eccSSepherosa Ziehau 190933a04907SSepherosa Ziehau /* XXX */ 191033a04907SSepherosa Ziehau sc->bnx_tx_ringcnt = 1; 1911beedf5beSSepherosa Ziehau sc->bnx_rx_retcnt = 1; 19120a806e3aSSepherosa Ziehau sc->bnx_intr_cnt = 1; 191333a04907SSepherosa Ziehau 19144fa38985SSepherosa Ziehau if ((sc->bnx_rx_retcnt == 1 && sc->bnx_tx_ringcnt == 1) || 19154fa38985SSepherosa Ziehau (sc->bnx_rx_retcnt > 1 && sc->bnx_tx_ringcnt > 1)) { 19164fa38985SSepherosa Ziehau /* 19174fa38985SSepherosa Ziehau * The RX ring and the corresponding TX ring processing 19184fa38985SSepherosa Ziehau * should be on the same CPU, since they share the same 19194fa38985SSepherosa Ziehau * status block. 19204fa38985SSepherosa Ziehau */ 19214fa38985SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_RXTX_BUNDLE; 19224fa38985SSepherosa Ziehau if (bootverbose) 19234fa38985SSepherosa Ziehau device_printf(dev, "RX/TX bundle\n"); 19244fa38985SSepherosa Ziehau } else { 19254fa38985SSepherosa Ziehau KKASSERT(sc->bnx_rx_retcnt > 1 && sc->bnx_tx_ringcnt == 1); 19264fa38985SSepherosa Ziehau } 19274fa38985SSepherosa Ziehau 1928beedf5beSSepherosa Ziehau error = bnx_dma_alloc(dev); 19296c8d8eccSSepherosa Ziehau if (error) 19306c8d8eccSSepherosa Ziehau goto fail; 19316c8d8eccSSepherosa Ziehau 19324fa38985SSepherosa Ziehau #ifdef IFPOLL_ENABLE 19334fa38985SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_RXTX_BUNDLE) { 19344fa38985SSepherosa Ziehau /* 19354fa38985SSepherosa Ziehau * NPOLLING RX/TX CPU offset 19364fa38985SSepherosa Ziehau */ 19374fa38985SSepherosa Ziehau if (sc->bnx_rx_retcnt == ncpus2) { 19384fa38985SSepherosa Ziehau offset = 0; 19394fa38985SSepherosa Ziehau } else { 19404fa38985SSepherosa Ziehau offset_def = 19414fa38985SSepherosa Ziehau (sc->bnx_rx_retcnt * device_get_unit(dev)) % ncpus2; 19424fa38985SSepherosa Ziehau offset = device_getenv_int(dev, "npoll.offset", 19434fa38985SSepherosa Ziehau offset_def); 19444fa38985SSepherosa Ziehau if (offset >= ncpus2 || 19454fa38985SSepherosa Ziehau offset % sc->bnx_rx_retcnt != 0) { 19464fa38985SSepherosa Ziehau device_printf(dev, "invalid npoll.offset %d, " 19474fa38985SSepherosa Ziehau "use %d\n", offset, offset_def); 19484fa38985SSepherosa Ziehau offset = offset_def; 19494fa38985SSepherosa Ziehau } 19504fa38985SSepherosa Ziehau } 19514fa38985SSepherosa Ziehau sc->bnx_npoll_rxoff = offset; 19524fa38985SSepherosa Ziehau sc->bnx_npoll_txoff = offset; 19534fa38985SSepherosa Ziehau } else { 19544fa38985SSepherosa Ziehau /* 19554fa38985SSepherosa Ziehau * NPOLLING RX CPU offset 19564fa38985SSepherosa Ziehau */ 19574fa38985SSepherosa Ziehau if (sc->bnx_rx_retcnt == ncpus2) { 19584fa38985SSepherosa Ziehau offset = 0; 19594fa38985SSepherosa Ziehau } else { 19604fa38985SSepherosa Ziehau offset_def = 19614fa38985SSepherosa Ziehau (sc->bnx_rx_retcnt * device_get_unit(dev)) % ncpus2; 19624fa38985SSepherosa Ziehau offset = device_getenv_int(dev, "npoll.rxoff", 19634fa38985SSepherosa Ziehau offset_def); 19644fa38985SSepherosa Ziehau if (offset >= ncpus2 || 19654fa38985SSepherosa Ziehau offset % sc->bnx_rx_retcnt != 0) { 19664fa38985SSepherosa Ziehau device_printf(dev, "invalid npoll.rxoff %d, " 19674fa38985SSepherosa Ziehau "use %d\n", offset, offset_def); 19684fa38985SSepherosa Ziehau offset = offset_def; 19694fa38985SSepherosa Ziehau } 19704fa38985SSepherosa Ziehau } 19714fa38985SSepherosa Ziehau sc->bnx_npoll_rxoff = offset; 19724fa38985SSepherosa Ziehau 19734fa38985SSepherosa Ziehau /* 19744fa38985SSepherosa Ziehau * NPOLLING TX CPU offset 19754fa38985SSepherosa Ziehau */ 19764fa38985SSepherosa Ziehau offset_def = device_get_unit(dev) % ncpus2; 19774fa38985SSepherosa Ziehau offset = device_getenv_int(dev, "npoll.txoff", offset_def); 19784fa38985SSepherosa Ziehau if (offset >= ncpus2) { 19794fa38985SSepherosa Ziehau device_printf(dev, "invalid npoll.txoff %d, use %d\n", 19804fa38985SSepherosa Ziehau offset, offset_def); 19814fa38985SSepherosa Ziehau offset = offset_def; 19824fa38985SSepherosa Ziehau } 19834fa38985SSepherosa Ziehau sc->bnx_npoll_txoff = offset; 19844fa38985SSepherosa Ziehau } 19854fa38985SSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 19864fa38985SSepherosa Ziehau 198716b32c4cSSepherosa Ziehau /* 198816b32c4cSSepherosa Ziehau * Allocate interrupt 198916b32c4cSSepherosa Ziehau */ 19900c7da01dSSepherosa Ziehau error = bnx_alloc_intr(sc); 19910c7da01dSSepherosa Ziehau if (error) 199216b32c4cSSepherosa Ziehau goto fail; 199316b32c4cSSepherosa Ziehau 1994329f9016SSepherosa Ziehau /* Setup serializers */ 1995329f9016SSepherosa Ziehau bnx_setup_serialize(sc); 1996329f9016SSepherosa Ziehau 19976c8d8eccSSepherosa Ziehau /* Set default tuneable values. */ 19986c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks = BNX_RX_COAL_TICKS_DEF; 19996c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks = BNX_TX_COAL_TICKS_DEF; 20006c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds = BNX_RX_COAL_BDS_DEF; 20016c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds = BNX_TX_COAL_BDS_DEF; 2002306e5498SSepherosa Ziehau sc->bnx_rx_coal_bds_int = BNX_RX_COAL_BDS_INT_DEF; 2003306e5498SSepherosa Ziehau sc->bnx_tx_coal_bds_int = BNX_TX_COAL_BDS_INT_DEF; 20046c8d8eccSSepherosa Ziehau 20056c8d8eccSSepherosa Ziehau /* Set up ifnet structure */ 20066c8d8eccSSepherosa Ziehau ifp->if_softc = sc; 20076c8d8eccSSepherosa Ziehau ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 20086c8d8eccSSepherosa Ziehau ifp->if_ioctl = bnx_ioctl; 20096c8d8eccSSepherosa Ziehau ifp->if_start = bnx_start; 201039a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 201139a8d43aSSepherosa Ziehau ifp->if_npoll = bnx_npoll; 20126c8d8eccSSepherosa Ziehau #endif 20136c8d8eccSSepherosa Ziehau ifp->if_init = bnx_init; 2014329f9016SSepherosa Ziehau ifp->if_serialize = bnx_serialize; 2015329f9016SSepherosa Ziehau ifp->if_deserialize = bnx_deserialize; 2016329f9016SSepherosa Ziehau ifp->if_tryserialize = bnx_tryserialize; 2017329f9016SSepherosa Ziehau #ifdef INVARIANTS 2018329f9016SSepherosa Ziehau ifp->if_serialize_assert = bnx_serialize_assert; 2019329f9016SSepherosa Ziehau #endif 20206c8d8eccSSepherosa Ziehau ifp->if_mtu = ETHERMTU; 20216c8d8eccSSepherosa Ziehau ifp->if_capabilities = IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; 20226c8d8eccSSepherosa Ziehau 20236c8d8eccSSepherosa Ziehau ifp->if_capabilities |= IFCAP_HWCSUM; 20246c8d8eccSSepherosa Ziehau ifp->if_hwassist = BNX_CSUM_FEATURES; 202566deb1c1SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TSO) { 202666deb1c1SSepherosa Ziehau ifp->if_capabilities |= IFCAP_TSO; 202766deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 202866deb1c1SSepherosa Ziehau } 20296c8d8eccSSepherosa Ziehau ifp->if_capenable = ifp->if_capabilities; 20306c8d8eccSSepherosa Ziehau 2031329f9016SSepherosa Ziehau ifq_set_maxlen(&ifp->if_snd, BGE_TX_RING_CNT - 1); 2032329f9016SSepherosa Ziehau ifq_set_ready(&ifp->if_snd); 2033329f9016SSepherosa Ziehau ifq_set_subq_cnt(&ifp->if_snd, sc->bnx_tx_ringcnt); 2034329f9016SSepherosa Ziehau 20356c8d8eccSSepherosa Ziehau /* 20366c8d8eccSSepherosa Ziehau * Figure out what sort of media we have by checking the 20376c8d8eccSSepherosa Ziehau * hardware config word in the first 32k of NIC internal memory, 20386c8d8eccSSepherosa Ziehau * or fall back to examining the EEPROM if necessary. 20396c8d8eccSSepherosa Ziehau * Note: on some BCM5700 cards, this value appears to be unset. 20406c8d8eccSSepherosa Ziehau * If that's the case, we have to rely on identifying the NIC 20416c8d8eccSSepherosa Ziehau * by its PCI subsystem ID, as we do below for the SysKonnect 20426c8d8eccSSepherosa Ziehau * SK-9D41. 20436c8d8eccSSepherosa Ziehau */ 20446c8d8eccSSepherosa Ziehau if (bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER) { 20456c8d8eccSSepherosa Ziehau hwcfg = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG); 20466c8d8eccSSepherosa Ziehau } else { 20476c8d8eccSSepherosa Ziehau if (bnx_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET, 20486c8d8eccSSepherosa Ziehau sizeof(hwcfg))) { 20496c8d8eccSSepherosa Ziehau device_printf(dev, "failed to read EEPROM\n"); 20506c8d8eccSSepherosa Ziehau error = ENXIO; 20516c8d8eccSSepherosa Ziehau goto fail; 20526c8d8eccSSepherosa Ziehau } 20536c8d8eccSSepherosa Ziehau hwcfg = ntohl(hwcfg); 20546c8d8eccSSepherosa Ziehau } 20556c8d8eccSSepherosa Ziehau 20566c8d8eccSSepherosa Ziehau /* The SysKonnect SK-9D41 is a 1000baseSX card. */ 20576c8d8eccSSepherosa Ziehau if (pci_get_subvendor(dev) == PCI_PRODUCT_SCHNEIDERKOCH_SK_9D41 || 20586c8d8eccSSepherosa Ziehau (hwcfg & BGE_HWCFG_MEDIA) == BGE_MEDIA_FIBER) 20596c8d8eccSSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_TBI; 20606c8d8eccSSepherosa Ziehau 20616c8d8eccSSepherosa Ziehau /* Setup MI MODE */ 20626c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_CPMU) 20636c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_500KHZ_CONST; 20646c8d8eccSSepherosa Ziehau else 20656c8d8eccSSepherosa Ziehau sc->bnx_mi_mode = BGE_MIMODE_BASE; 20666c8d8eccSSepherosa Ziehau 20676c8d8eccSSepherosa Ziehau /* Setup link status update stuffs */ 20686c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 20696c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_tbi_link_upd; 20706c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20716c8d8eccSSepherosa Ziehau } else if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) { 20726c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_autopoll_link_upd; 20736c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20746c8d8eccSSepherosa Ziehau } else { 20756c8d8eccSSepherosa Ziehau sc->bnx_link_upd = bnx_copper_link_upd; 20766c8d8eccSSepherosa Ziehau sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED; 20776c8d8eccSSepherosa Ziehau } 20786c8d8eccSSepherosa Ziehau 20796c8d8eccSSepherosa Ziehau /* Set default PHY address */ 20806c8d8eccSSepherosa Ziehau sc->bnx_phyno = 1; 20816c8d8eccSSepherosa Ziehau 20826c8d8eccSSepherosa Ziehau /* 20836c8d8eccSSepherosa Ziehau * PHY address mapping for various devices. 20846c8d8eccSSepherosa Ziehau * 20856c8d8eccSSepherosa Ziehau * | F0 Cu | F0 Sr | F1 Cu | F1 Sr | 20866c8d8eccSSepherosa Ziehau * ---------+-------+-------+-------+-------+ 20876c8d8eccSSepherosa Ziehau * BCM57XX | 1 | X | X | X | 20886c8d8eccSSepherosa Ziehau * BCM5704 | 1 | X | 1 | X | 20896c8d8eccSSepherosa Ziehau * BCM5717 | 1 | 8 | 2 | 9 | 20906c8d8eccSSepherosa Ziehau * BCM5719 | 1 | 8 | 2 | 9 | 20916c8d8eccSSepherosa Ziehau * BCM5720 | 1 | 8 | 2 | 9 | 20926c8d8eccSSepherosa Ziehau * 20936c8d8eccSSepherosa Ziehau * Other addresses may respond but they are not 20946c8d8eccSSepherosa Ziehau * IEEE compliant PHYs and should be ignored. 20956c8d8eccSSepherosa Ziehau */ 209680969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 20976c8d8eccSSepherosa Ziehau int f; 20986c8d8eccSSepherosa Ziehau 20996c8d8eccSSepherosa Ziehau f = pci_get_function(dev); 21006c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5717_A0) { 21016c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_SGDIG_STS) & 21026c8d8eccSSepherosa Ziehau BGE_SGDIGSTS_IS_SERDES) 21036c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 21046c8d8eccSSepherosa Ziehau else 21056c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 21066c8d8eccSSepherosa Ziehau } else { 21076c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_CPMU_PHY_STRAP) & 21086c8d8eccSSepherosa Ziehau BGE_CPMU_PHY_STRAP_IS_SERDES) 21096c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 8; 21106c8d8eccSSepherosa Ziehau else 21116c8d8eccSSepherosa Ziehau sc->bnx_phyno = f + 1; 21126c8d8eccSSepherosa Ziehau } 21136c8d8eccSSepherosa Ziehau } 21146c8d8eccSSepherosa Ziehau 21156c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 21166c8d8eccSSepherosa Ziehau ifmedia_init(&sc->bnx_ifmedia, IFM_IMASK, 21176c8d8eccSSepherosa Ziehau bnx_ifmedia_upd, bnx_ifmedia_sts); 21186c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL); 21196c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, 21206c8d8eccSSepherosa Ziehau IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL); 21216c8d8eccSSepherosa Ziehau ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 21226c8d8eccSSepherosa Ziehau ifmedia_set(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO); 21236c8d8eccSSepherosa Ziehau sc->bnx_ifmedia.ifm_media = sc->bnx_ifmedia.ifm_cur->ifm_media; 21246c8d8eccSSepherosa Ziehau } else { 21256c8d8eccSSepherosa Ziehau struct mii_probe_args mii_args; 21266c8d8eccSSepherosa Ziehau 21276c8d8eccSSepherosa Ziehau mii_probe_args_init(&mii_args, bnx_ifmedia_upd, bnx_ifmedia_sts); 21286c8d8eccSSepherosa Ziehau mii_args.mii_probemask = 1 << sc->bnx_phyno; 21296c8d8eccSSepherosa Ziehau mii_args.mii_capmask = capmask; 21306c8d8eccSSepherosa Ziehau mii_args.mii_privtag = MII_PRIVTAG_BRGPHY; 21316c8d8eccSSepherosa Ziehau mii_args.mii_priv = mii_priv; 21326c8d8eccSSepherosa Ziehau 21336c8d8eccSSepherosa Ziehau error = mii_probe(dev, &sc->bnx_miibus, &mii_args); 21346c8d8eccSSepherosa Ziehau if (error) { 21356c8d8eccSSepherosa Ziehau device_printf(dev, "MII without any PHY!\n"); 21366c8d8eccSSepherosa Ziehau goto fail; 21376c8d8eccSSepherosa Ziehau } 21386c8d8eccSSepherosa Ziehau } 21396c8d8eccSSepherosa Ziehau 21406c8d8eccSSepherosa Ziehau /* 21416c8d8eccSSepherosa Ziehau * Create sysctl nodes. 21426c8d8eccSSepherosa Ziehau */ 21436c8d8eccSSepherosa Ziehau sysctl_ctx_init(&sc->bnx_sysctl_ctx); 21446c8d8eccSSepherosa Ziehau sc->bnx_sysctl_tree = SYSCTL_ADD_NODE(&sc->bnx_sysctl_ctx, 21456c8d8eccSSepherosa Ziehau SYSCTL_STATIC_CHILDREN(_hw), 21466c8d8eccSSepherosa Ziehau OID_AUTO, 21476c8d8eccSSepherosa Ziehau device_get_nameunit(dev), 21486c8d8eccSSepherosa Ziehau CTLFLAG_RD, 0, ""); 21496c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree == NULL) { 21506c8d8eccSSepherosa Ziehau device_printf(dev, "can't add sysctl node\n"); 21516c8d8eccSSepherosa Ziehau error = ENXIO; 21526c8d8eccSSepherosa Ziehau goto fail; 21536c8d8eccSSepherosa Ziehau } 21546c8d8eccSSepherosa Ziehau 215593146551SSepherosa Ziehau SYSCTL_ADD_INT(&sc->bnx_sysctl_ctx, 215693146551SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 215793146551SSepherosa Ziehau "rx_rings", CTLFLAG_RD, &sc->bnx_rx_retcnt, 0, "# of RX rings"); 215893146551SSepherosa Ziehau SYSCTL_ADD_INT(&sc->bnx_sysctl_ctx, 215993146551SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 216093146551SSepherosa Ziehau "tx_rings", CTLFLAG_RD, &sc->bnx_tx_ringcnt, 0, "# of TX rings"); 216193146551SSepherosa Ziehau 21626c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21636c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21646c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_ticks", 21656c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21666c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_ticks, "I", 21676c8d8eccSSepherosa Ziehau "Receive coalescing ticks (usec)."); 21686c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21696c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21706c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_ticks", 21716c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21726c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_ticks, "I", 21736c8d8eccSSepherosa Ziehau "Transmit coalescing ticks (usec)."); 21746c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21756c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21766c8d8eccSSepherosa Ziehau OID_AUTO, "rx_coal_bds", 21776c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21786c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds, "I", 21796c8d8eccSSepherosa Ziehau "Receive max coalesced BD count."); 21806c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 21816c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), 21826c8d8eccSSepherosa Ziehau OID_AUTO, "tx_coal_bds", 21836c8d8eccSSepherosa Ziehau CTLTYPE_INT | CTLFLAG_RW, 21846c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds, "I", 21856c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count."); 21866c8d8eccSSepherosa Ziehau /* 21876c8d8eccSSepherosa Ziehau * A common design characteristic for many Broadcom 21886c8d8eccSSepherosa Ziehau * client controllers is that they only support a 21896c8d8eccSSepherosa Ziehau * single outstanding DMA read operation on the PCIe 21906c8d8eccSSepherosa Ziehau * bus. This means that it will take twice as long to 21916c8d8eccSSepherosa Ziehau * fetch a TX frame that is split into header and 21926c8d8eccSSepherosa Ziehau * payload buffers as it does to fetch a single, 21936c8d8eccSSepherosa Ziehau * contiguous TX frame (2 reads vs. 1 read). For these 21946c8d8eccSSepherosa Ziehau * controllers, coalescing buffers to reduce the number 21956c8d8eccSSepherosa Ziehau * of memory reads is effective way to get maximum 21966c8d8eccSSepherosa Ziehau * performance(about 940Mbps). Without collapsing TX 21976c8d8eccSSepherosa Ziehau * buffers the maximum TCP bulk transfer performance 21986c8d8eccSSepherosa Ziehau * is about 850Mbps. However forcing coalescing mbufs 21996c8d8eccSSepherosa Ziehau * consumes a lot of CPU cycles, so leave it off by 22006c8d8eccSSepherosa Ziehau * default. 22016c8d8eccSSepherosa Ziehau */ 2202aad4de2bSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22036c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2204aad4de2bSSepherosa Ziehau "force_defrag", CTLTYPE_INT | CTLFLAG_RW, 2205aad4de2bSSepherosa Ziehau sc, 0, bnx_sysctl_force_defrag, "I", 22066c8d8eccSSepherosa Ziehau "Force defragment on TX path"); 22076c8d8eccSSepherosa Ziehau 2208472c99c8SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 2209c9b7f592SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2210472c99c8SSepherosa Ziehau "tx_wreg", CTLTYPE_INT | CTLFLAG_RW, 2211472c99c8SSepherosa Ziehau sc, 0, bnx_sysctl_tx_wreg, "I", 2212c9b7f592SSepherosa Ziehau "# of segments before writing to hardware register"); 2213c9b7f592SSepherosa Ziehau 22146c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22156c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 2216841cdf08SSepherosa Ziehau "std_refill", CTLTYPE_INT | CTLFLAG_RW, 2217841cdf08SSepherosa Ziehau sc, 0, bnx_sysctl_std_refill, "I", 2218841cdf08SSepherosa Ziehau "# of packets received before scheduling standard refilling"); 2219841cdf08SSepherosa Ziehau 2220841cdf08SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 2221841cdf08SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 22226c8d8eccSSepherosa Ziehau "rx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 22236c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_rx_coal_bds_int, "I", 22246c8d8eccSSepherosa Ziehau "Receive max coalesced BD count during interrupt."); 22256c8d8eccSSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22266c8d8eccSSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 22276c8d8eccSSepherosa Ziehau "tx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW, 22286c8d8eccSSepherosa Ziehau sc, 0, bnx_sysctl_tx_coal_bds_int, "I", 22296c8d8eccSSepherosa Ziehau "Transmit max coalesced BD count during interrupt."); 22306c8d8eccSSepherosa Ziehau 22314fa38985SSepherosa Ziehau #ifdef IFPOLL_ENABLE 22324fa38985SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_RXTX_BUNDLE) { 22334fa38985SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22344fa38985SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 22354fa38985SSepherosa Ziehau "npoll_offset", CTLTYPE_INT | CTLFLAG_RW, 22364fa38985SSepherosa Ziehau sc, 0, bnx_sysctl_npoll_offset, "I", 22374fa38985SSepherosa Ziehau "NPOLLING cpu offset"); 22384fa38985SSepherosa Ziehau } else { 22394fa38985SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22404fa38985SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 22414fa38985SSepherosa Ziehau "npoll_rxoff", CTLTYPE_INT | CTLFLAG_RW, 22424fa38985SSepherosa Ziehau sc, 0, bnx_sysctl_npoll_rxoff, "I", 22434fa38985SSepherosa Ziehau "NPOLLING RX cpu offset"); 22444fa38985SSepherosa Ziehau SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx, 22454fa38985SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 22464fa38985SSepherosa Ziehau "npoll_txoff", CTLTYPE_INT | CTLFLAG_RW, 22474fa38985SSepherosa Ziehau sc, 0, bnx_sysctl_npoll_txoff, "I", 22484fa38985SSepherosa Ziehau "NPOLLING TX cpu offset"); 22494fa38985SSepherosa Ziehau } 22504fa38985SSepherosa Ziehau #endif 22514fa38985SSepherosa Ziehau 225266deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 225366deb1c1SSepherosa Ziehau for (i = 0; i < BNX_TSO_NSTATS; ++i) { 225466deb1c1SSepherosa Ziehau ksnprintf(desc, sizeof(desc), "tso%d", i + 1); 225566deb1c1SSepherosa Ziehau SYSCTL_ADD_ULONG(&sc->bnx_sysctl_ctx, 225666deb1c1SSepherosa Ziehau SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO, 225766deb1c1SSepherosa Ziehau desc, CTLFLAG_RW, &sc->bnx_tsosegs[i], ""); 225866deb1c1SSepherosa Ziehau } 225966deb1c1SSepherosa Ziehau #endif 226066deb1c1SSepherosa Ziehau 22616c8d8eccSSepherosa Ziehau /* 22626c8d8eccSSepherosa Ziehau * Call MI attach routine. 22636c8d8eccSSepherosa Ziehau */ 2264329f9016SSepherosa Ziehau ether_ifattach(ifp, ether_addr, NULL); 22656c8d8eccSSepherosa Ziehau 2266329f9016SSepherosa Ziehau /* Setup TX rings and subqueues */ 2267329f9016SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 2268329f9016SSepherosa Ziehau struct ifaltq_subque *ifsq = ifq_get_subq(&ifp->if_snd, i); 2269329f9016SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 2270329f9016SSepherosa Ziehau 2271329f9016SSepherosa Ziehau ifsq_set_cpuid(ifsq, txr->bnx_tx_cpuid); 2272329f9016SSepherosa Ziehau ifsq_set_hw_serialize(ifsq, &txr->bnx_tx_serialize); 2273329f9016SSepherosa Ziehau ifsq_set_priv(ifsq, txr); 22743397dea6SSepherosa Ziehau txr->bnx_ifsq = ifsq; 2275329f9016SSepherosa Ziehau 22763397dea6SSepherosa Ziehau ifsq_watchdog_init(&txr->bnx_tx_watchdog, ifsq, bnx_watchdog); 2277329f9016SSepherosa Ziehau } 22784c77af2dSSepherosa Ziehau 22790c7da01dSSepherosa Ziehau error = bnx_setup_intr(sc); 22806c8d8eccSSepherosa Ziehau if (error) { 22816c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 22826c8d8eccSSepherosa Ziehau goto fail; 22836c8d8eccSSepherosa Ziehau } 22847dbaa833SSepherosa Ziehau bnx_set_tick_cpuid(sc, FALSE); 22858ca0f604SSepherosa Ziehau 2286841cdf08SSepherosa Ziehau /* 2287841cdf08SSepherosa Ziehau * Create RX standard ring refilling thread 2288841cdf08SSepherosa Ziehau */ 2289841cdf08SSepherosa Ziehau std_cpuid_def = device_get_unit(dev) % ncpus; 2290841cdf08SSepherosa Ziehau std_cpuid = device_getenv_int(dev, "std.cpuid", std_cpuid_def); 2291841cdf08SSepherosa Ziehau if (std_cpuid < 0 || std_cpuid >= ncpus) { 2292841cdf08SSepherosa Ziehau device_printf(dev, "invalid std.cpuid %d, use %d\n", 2293841cdf08SSepherosa Ziehau std_cpuid, std_cpuid_def); 2294841cdf08SSepherosa Ziehau std_cpuid = std_cpuid_def; 2295841cdf08SSepherosa Ziehau } 2296841cdf08SSepherosa Ziehau 2297841cdf08SSepherosa Ziehau std = &sc->bnx_rx_std_ring; 2298841cdf08SSepherosa Ziehau lwkt_create(bnx_rx_std_refill_ithread, std, NULL, 2299841cdf08SSepherosa Ziehau &std->bnx_rx_std_ithread, TDF_NOSTART | TDF_INTTHREAD, std_cpuid, 2300841cdf08SSepherosa Ziehau "%s std", device_get_nameunit(dev)); 2301841cdf08SSepherosa Ziehau lwkt_setpri(&std->bnx_rx_std_ithread, TDPRI_INT_MED); 2302841cdf08SSepherosa Ziehau std->bnx_rx_std_ithread.td_preemptable = lwkt_preempt; 2303841cdf08SSepherosa Ziehau sc->bnx_flags |= BNX_FLAG_STD_THREAD; 2304841cdf08SSepherosa Ziehau 23056c8d8eccSSepherosa Ziehau return(0); 23066c8d8eccSSepherosa Ziehau fail: 23076c8d8eccSSepherosa Ziehau bnx_detach(dev); 23086c8d8eccSSepherosa Ziehau return(error); 23096c8d8eccSSepherosa Ziehau } 23106c8d8eccSSepherosa Ziehau 23116c8d8eccSSepherosa Ziehau static int 23126c8d8eccSSepherosa Ziehau bnx_detach(device_t dev) 23136c8d8eccSSepherosa Ziehau { 23146c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 23156c8d8eccSSepherosa Ziehau 23166c8d8eccSSepherosa Ziehau if (device_is_attached(dev)) { 23176c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 23186c8d8eccSSepherosa Ziehau 2319329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 23206c8d8eccSSepherosa Ziehau bnx_stop(sc); 23216c8d8eccSSepherosa Ziehau bnx_reset(sc); 2322f33ac8a4SSepherosa Ziehau bnx_teardown_intr(sc, sc->bnx_intr_cnt); 2323329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 23246c8d8eccSSepherosa Ziehau 23256c8d8eccSSepherosa Ziehau ether_ifdetach(ifp); 23266c8d8eccSSepherosa Ziehau } 23276c8d8eccSSepherosa Ziehau 2328841cdf08SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_STD_THREAD) { 2329841cdf08SSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 2330841cdf08SSepherosa Ziehau 2331841cdf08SSepherosa Ziehau tsleep_interlock(std, 0); 2332841cdf08SSepherosa Ziehau std->bnx_rx_std_stop = 1; 2333841cdf08SSepherosa Ziehau cpu_sfence(); 2334841cdf08SSepherosa Ziehau lwkt_schedule(&std->bnx_rx_std_ithread); 2335841cdf08SSepherosa Ziehau tsleep(std, PINTERLOCKED, "bnx_detach", 0); 2336841cdf08SSepherosa Ziehau if (bootverbose) 2337841cdf08SSepherosa Ziehau device_printf(dev, "RX std ithread exited\n"); 2338841cdf08SSepherosa Ziehau } 2339841cdf08SSepherosa Ziehau 23406c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) 23416c8d8eccSSepherosa Ziehau ifmedia_removeall(&sc->bnx_ifmedia); 23426c8d8eccSSepherosa Ziehau if (sc->bnx_miibus) 23436c8d8eccSSepherosa Ziehau device_delete_child(dev, sc->bnx_miibus); 23446c8d8eccSSepherosa Ziehau bus_generic_detach(dev); 23456c8d8eccSSepherosa Ziehau 23460c7da01dSSepherosa Ziehau bnx_free_intr(sc); 23476c8d8eccSSepherosa Ziehau 23486c8d8eccSSepherosa Ziehau if (sc->bnx_res != NULL) { 23496c8d8eccSSepherosa Ziehau bus_release_resource(dev, SYS_RES_MEMORY, 23506c8d8eccSSepherosa Ziehau BGE_PCI_BAR0, sc->bnx_res); 23516c8d8eccSSepherosa Ziehau } 23526c8d8eccSSepherosa Ziehau 23536c8d8eccSSepherosa Ziehau if (sc->bnx_sysctl_tree != NULL) 23546c8d8eccSSepherosa Ziehau sysctl_ctx_free(&sc->bnx_sysctl_ctx); 23556c8d8eccSSepherosa Ziehau 23566c8d8eccSSepherosa Ziehau bnx_dma_free(sc); 23576c8d8eccSSepherosa Ziehau 2358329f9016SSepherosa Ziehau if (sc->bnx_serialize != NULL) 2359329f9016SSepherosa Ziehau kfree(sc->bnx_serialize, M_DEVBUF); 2360329f9016SSepherosa Ziehau 23616c8d8eccSSepherosa Ziehau return 0; 23626c8d8eccSSepherosa Ziehau } 23636c8d8eccSSepherosa Ziehau 23646c8d8eccSSepherosa Ziehau static void 23656c8d8eccSSepherosa Ziehau bnx_reset(struct bnx_softc *sc) 23666c8d8eccSSepherosa Ziehau { 23676c8d8eccSSepherosa Ziehau device_t dev; 23686c8d8eccSSepherosa Ziehau uint32_t cachesize, command, pcistate, reset; 23696c8d8eccSSepherosa Ziehau void (*write_op)(struct bnx_softc *, uint32_t, uint32_t); 23706c8d8eccSSepherosa Ziehau int i, val = 0; 23716c8d8eccSSepherosa Ziehau uint16_t devctl; 23726c8d8eccSSepherosa Ziehau 23736c8d8eccSSepherosa Ziehau dev = sc->bnx_dev; 23746c8d8eccSSepherosa Ziehau 23756c8d8eccSSepherosa Ziehau write_op = bnx_writemem_direct; 23766c8d8eccSSepherosa Ziehau 23776c8d8eccSSepherosa Ziehau /* Save some important PCI state. */ 23786c8d8eccSSepherosa Ziehau cachesize = pci_read_config(dev, BGE_PCI_CACHESZ, 4); 23796c8d8eccSSepherosa Ziehau command = pci_read_config(dev, BGE_PCI_CMD, 4); 23806c8d8eccSSepherosa Ziehau pcistate = pci_read_config(dev, BGE_PCI_PCISTATE, 4); 23816c8d8eccSSepherosa Ziehau 23826c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 23836c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 23846c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 23856c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 23866c8d8eccSSepherosa Ziehau 23876c8d8eccSSepherosa Ziehau /* Disable fastboot on controllers that support it. */ 23886c8d8eccSSepherosa Ziehau if (bootverbose) 23896c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "Disabling fastboot\n"); 23906c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0x0); 23916c8d8eccSSepherosa Ziehau 23926c8d8eccSSepherosa Ziehau /* 23936c8d8eccSSepherosa Ziehau * Write the magic number to SRAM at offset 0xB50. 23946c8d8eccSSepherosa Ziehau * When firmware finishes its initialization it will 23956c8d8eccSSepherosa Ziehau * write ~BGE_MAGIC_NUMBER to the same location. 23966c8d8eccSSepherosa Ziehau */ 23976c8d8eccSSepherosa Ziehau bnx_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); 23986c8d8eccSSepherosa Ziehau 23996c8d8eccSSepherosa Ziehau reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1); 24006c8d8eccSSepherosa Ziehau 24016c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 24026c8d8eccSSepherosa Ziehau /* Force PCI-E 1.0a mode */ 24033730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc) && 24046c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_PCIE_PHY_TSTCTL) == 24056c8d8eccSSepherosa Ziehau (BGE_PCIE_PHY_TSTCTL_PSCRAM | 24066c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PCIE10)) { 24076c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_PHY_TSTCTL, 24086c8d8eccSSepherosa Ziehau BGE_PCIE_PHY_TSTCTL_PSCRAM); 24096c8d8eccSSepherosa Ziehau } 24106c8d8eccSSepherosa Ziehau if (sc->bnx_chipid != BGE_CHIPID_BCM5750_A0) { 24116c8d8eccSSepherosa Ziehau /* Prevent PCIE link training during global reset */ 24126c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MISC_CFG, (1<<29)); 24136c8d8eccSSepherosa Ziehau reset |= (1<<29); 24146c8d8eccSSepherosa Ziehau } 24156c8d8eccSSepherosa Ziehau 24166c8d8eccSSepherosa Ziehau /* 24176c8d8eccSSepherosa Ziehau * Set GPHY Power Down Override to leave GPHY 24186c8d8eccSSepherosa Ziehau * powered up in D0 uninitialized. 24196c8d8eccSSepherosa Ziehau */ 24206c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) 24216c8d8eccSSepherosa Ziehau reset |= BGE_MISCCFG_GPHY_PD_OVERRIDE; 24226c8d8eccSSepherosa Ziehau 24236c8d8eccSSepherosa Ziehau /* Issue global reset */ 24246c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, reset); 24256c8d8eccSSepherosa Ziehau 24266c8d8eccSSepherosa Ziehau DELAY(1000); 24276c8d8eccSSepherosa Ziehau 24286c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 24296c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM5750_A0) { 24306c8d8eccSSepherosa Ziehau uint32_t v; 24316c8d8eccSSepherosa Ziehau 24326c8d8eccSSepherosa Ziehau DELAY(500000); /* wait for link training to complete */ 24336c8d8eccSSepherosa Ziehau v = pci_read_config(dev, 0xc4, 4); 24346c8d8eccSSepherosa Ziehau pci_write_config(dev, 0xc4, v | (1<<15), 4); 24356c8d8eccSSepherosa Ziehau } 24366c8d8eccSSepherosa Ziehau 24376c8d8eccSSepherosa Ziehau devctl = pci_read_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 2); 24386c8d8eccSSepherosa Ziehau 24396c8d8eccSSepherosa Ziehau /* Disable no snoop and disable relaxed ordering. */ 24406c8d8eccSSepherosa Ziehau devctl &= ~(PCIEM_DEVCTL_RELAX_ORDER | PCIEM_DEVCTL_NOSNOOP); 24416c8d8eccSSepherosa Ziehau 24426c8d8eccSSepherosa Ziehau /* Old PCI-E chips only support 128 bytes Max PayLoad Size. */ 24436c8d8eccSSepherosa Ziehau if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) { 24446c8d8eccSSepherosa Ziehau devctl &= ~PCIEM_DEVCTL_MAX_PAYLOAD_MASK; 24456c8d8eccSSepherosa Ziehau devctl |= PCIEM_DEVCTL_MAX_PAYLOAD_128; 24466c8d8eccSSepherosa Ziehau } 24476c8d8eccSSepherosa Ziehau 24486c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 24496c8d8eccSSepherosa Ziehau devctl, 2); 24506c8d8eccSSepherosa Ziehau 24516c8d8eccSSepherosa Ziehau /* Clear error status. */ 24526c8d8eccSSepherosa Ziehau pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVSTS, 24536c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_CORR_ERR | 24546c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_NFATAL_ERR | 24556c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_FATAL_ERR | 24566c8d8eccSSepherosa Ziehau PCIEM_DEVSTS_UNSUPP_REQ, 2); 24576c8d8eccSSepherosa Ziehau 24586c8d8eccSSepherosa Ziehau /* Reset some of the PCI state that got zapped by reset */ 24596c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_MISC_CTL, 24606c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| 24616c8d8eccSSepherosa Ziehau BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW| 24626c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_TAGGED_STATUS, 4); 24636c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CACHESZ, cachesize, 4); 24646c8d8eccSSepherosa Ziehau pci_write_config(dev, BGE_PCI_CMD, command, 4); 24656c8d8eccSSepherosa Ziehau write_op(sc, BGE_MISC_CFG, (65 << 1)); 24666c8d8eccSSepherosa Ziehau 24676c8d8eccSSepherosa Ziehau /* Enable memory arbiter */ 24686c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); 24696c8d8eccSSepherosa Ziehau 24706c8d8eccSSepherosa Ziehau /* 24716c8d8eccSSepherosa Ziehau * Poll until we see the 1's complement of the magic number. 2472ddd93a5cSSepherosa Ziehau * This indicates that the firmware initialization is complete. 24736c8d8eccSSepherosa Ziehau */ 24746c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_FIRMWARE_TIMEOUT; i++) { 24756c8d8eccSSepherosa Ziehau val = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM); 24766c8d8eccSSepherosa Ziehau if (val == ~BGE_MAGIC_NUMBER) 24776c8d8eccSSepherosa Ziehau break; 24786c8d8eccSSepherosa Ziehau DELAY(10); 24796c8d8eccSSepherosa Ziehau } 24806c8d8eccSSepherosa Ziehau if (i == BNX_FIRMWARE_TIMEOUT) { 24816c8d8eccSSepherosa Ziehau if_printf(&sc->arpcom.ac_if, "firmware handshake " 24826c8d8eccSSepherosa Ziehau "timed out, found 0x%08x\n", val); 24836c8d8eccSSepherosa Ziehau } 24846c8d8eccSSepherosa Ziehau 24856c8d8eccSSepherosa Ziehau /* BCM57765 A0 needs additional time before accessing. */ 24866c8d8eccSSepherosa Ziehau if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) 24876c8d8eccSSepherosa Ziehau DELAY(10 * 1000); 24886c8d8eccSSepherosa Ziehau 24896c8d8eccSSepherosa Ziehau /* 24906c8d8eccSSepherosa Ziehau * XXX Wait for the value of the PCISTATE register to 24916c8d8eccSSepherosa Ziehau * return to its original pre-reset state. This is a 24926c8d8eccSSepherosa Ziehau * fairly good indicator of reset completion. If we don't 24936c8d8eccSSepherosa Ziehau * wait for the reset to fully complete, trying to read 24946c8d8eccSSepherosa Ziehau * from the device's non-PCI registers may yield garbage 24956c8d8eccSSepherosa Ziehau * results. 24966c8d8eccSSepherosa Ziehau */ 24976c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 24986c8d8eccSSepherosa Ziehau if (pci_read_config(dev, BGE_PCI_PCISTATE, 4) == pcistate) 24996c8d8eccSSepherosa Ziehau break; 25006c8d8eccSSepherosa Ziehau DELAY(10); 25016c8d8eccSSepherosa Ziehau } 25026c8d8eccSSepherosa Ziehau 25036c8d8eccSSepherosa Ziehau /* Fix up byte swapping */ 25046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MODE_CTL, bnx_dma_swap_options(sc)); 25056c8d8eccSSepherosa Ziehau 25066c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_MODE, 0); 25076c8d8eccSSepherosa Ziehau 25086c8d8eccSSepherosa Ziehau /* 25096c8d8eccSSepherosa Ziehau * The 5704 in TBI mode apparently needs some special 25106c8d8eccSSepherosa Ziehau * adjustment to insure the SERDES drive level is set 25116c8d8eccSSepherosa Ziehau * to 1.2V. 25126c8d8eccSSepherosa Ziehau */ 25136c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704 && 25146c8d8eccSSepherosa Ziehau (sc->bnx_flags & BNX_FLAG_TBI)) { 25156c8d8eccSSepherosa Ziehau uint32_t serdescfg; 25166c8d8eccSSepherosa Ziehau 25176c8d8eccSSepherosa Ziehau serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG); 25186c8d8eccSSepherosa Ziehau serdescfg = (serdescfg & ~0xFFF) | 0x880; 25196c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg); 25206c8d8eccSSepherosa Ziehau } 25216c8d8eccSSepherosa Ziehau 25227892075dSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MI_MODE, 25237892075dSSepherosa Ziehau sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL); 25247892075dSSepherosa Ziehau DELAY(80); 25257892075dSSepherosa Ziehau 25266c8d8eccSSepherosa Ziehau /* XXX: Broadcom Linux driver. */ 25273730a14dSSepherosa Ziehau if (!BNX_IS_57765_PLUS(sc)) { 25286c8d8eccSSepherosa Ziehau uint32_t v; 25296c8d8eccSSepherosa Ziehau 25306c8d8eccSSepherosa Ziehau /* Enable Data FIFO protection. */ 2531f1f34fc4SSepherosa Ziehau v = CSR_READ_4(sc, BGE_PCIE_TLDLPL_PORT); 2532f1f34fc4SSepherosa Ziehau CSR_WRITE_4(sc, BGE_PCIE_TLDLPL_PORT, v | (1 << 25)); 25336c8d8eccSSepherosa Ziehau } 25346c8d8eccSSepherosa Ziehau 25356c8d8eccSSepherosa Ziehau DELAY(10000); 25366c8d8eccSSepherosa Ziehau 25376c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) { 25386c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE, 25396c8d8eccSSepherosa Ziehau CPMU_CLCK_ORIDE_MAC_ORIDE_EN); 25406c8d8eccSSepherosa Ziehau } 25416c8d8eccSSepherosa Ziehau } 25426c8d8eccSSepherosa Ziehau 25436c8d8eccSSepherosa Ziehau /* 25446c8d8eccSSepherosa Ziehau * Frame reception handling. This is called if there's a frame 25456c8d8eccSSepherosa Ziehau * on the receive return list. 25466c8d8eccSSepherosa Ziehau * 25476c8d8eccSSepherosa Ziehau * Note: we have to be able to handle two possibilities here: 25486c8d8eccSSepherosa Ziehau * 1) the frame is from the jumbo recieve ring 25496c8d8eccSSepherosa Ziehau * 2) the frame is from the standard receive ring 25506c8d8eccSSepherosa Ziehau */ 25516c8d8eccSSepherosa Ziehau 25526c8d8eccSSepherosa Ziehau static void 2553beedf5beSSepherosa Ziehau bnx_rxeof(struct bnx_rx_ret_ring *ret, uint16_t rx_prod, int count) 25546c8d8eccSSepherosa Ziehau { 2555beedf5beSSepherosa Ziehau struct bnx_softc *sc = ret->bnx_sc; 2556beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = ret->bnx_std; 2557beedf5beSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 25586c8d8eccSSepherosa Ziehau 2559beedf5beSSepherosa Ziehau while (ret->bnx_rx_saved_considx != rx_prod && count != 0) { 25606c8d8eccSSepherosa Ziehau struct bge_rx_bd *cur_rx; 2561841cdf08SSepherosa Ziehau struct bnx_rx_buf *rb; 25626c8d8eccSSepherosa Ziehau uint32_t rxidx; 25636c8d8eccSSepherosa Ziehau struct mbuf *m = NULL; 25646c8d8eccSSepherosa Ziehau uint16_t vlan_tag = 0; 25656c8d8eccSSepherosa Ziehau int have_tag = 0; 25666c8d8eccSSepherosa Ziehau 256797381780SSepherosa Ziehau --count; 256897381780SSepherosa Ziehau 2569beedf5beSSepherosa Ziehau cur_rx = &ret->bnx_rx_ret_ring[ret->bnx_rx_saved_considx]; 25706c8d8eccSSepherosa Ziehau 25716c8d8eccSSepherosa Ziehau rxidx = cur_rx->bge_idx; 2572beedf5beSSepherosa Ziehau BNX_INC(ret->bnx_rx_saved_considx, BNX_RETURN_RING_CNT); 25736c8d8eccSSepherosa Ziehau 25746c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) { 25756c8d8eccSSepherosa Ziehau have_tag = 1; 25766c8d8eccSSepherosa Ziehau vlan_tag = cur_rx->bge_vlan_tag; 25776c8d8eccSSepherosa Ziehau } 25786c8d8eccSSepherosa Ziehau 2579841cdf08SSepherosa Ziehau if (ret->bnx_rx_cnt >= ret->bnx_rx_cntmax) { 2580841cdf08SSepherosa Ziehau ret->bnx_rx_cnt = 0; 2581841cdf08SSepherosa Ziehau cpu_sfence(); 2582841cdf08SSepherosa Ziehau atomic_set_int(&std->bnx_rx_std_refill, 2583841cdf08SSepherosa Ziehau ret->bnx_rx_mask); 2584841cdf08SSepherosa Ziehau if (atomic_poll_acquire_int(&std->bnx_rx_std_running)) 2585841cdf08SSepherosa Ziehau lwkt_schedule(&std->bnx_rx_std_ithread); 25866c8d8eccSSepherosa Ziehau } 2587841cdf08SSepherosa Ziehau ret->bnx_rx_cnt++; 25886c8d8eccSSepherosa Ziehau 2589841cdf08SSepherosa Ziehau rb = &std->bnx_rx_std_buf[rxidx]; 2590841cdf08SSepherosa Ziehau m = rb->bnx_rx_mbuf; 25916c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) { 2592d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 2593841cdf08SSepherosa Ziehau cpu_sfence(); 2594841cdf08SSepherosa Ziehau rb->bnx_rx_refilled = 1; 25956c8d8eccSSepherosa Ziehau continue; 25966c8d8eccSSepherosa Ziehau } 2597841cdf08SSepherosa Ziehau if (bnx_newbuf_std(ret, rxidx, 0)) { 2598d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ierrors, 1); 25996c8d8eccSSepherosa Ziehau continue; 26006c8d8eccSSepherosa Ziehau } 26016c8d8eccSSepherosa Ziehau 2602d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, ipackets, 1); 26036c8d8eccSSepherosa Ziehau m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; 26046c8d8eccSSepherosa Ziehau m->m_pkthdr.rcvif = ifp; 26056c8d8eccSSepherosa Ziehau 26066c8d8eccSSepherosa Ziehau if ((ifp->if_capenable & IFCAP_RXCSUM) && 26076c8d8eccSSepherosa Ziehau (cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) { 26086c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) { 26096c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; 26106c8d8eccSSepherosa Ziehau if ((cur_rx->bge_error_flag & 26116c8d8eccSSepherosa Ziehau BGE_RXERRFLAG_IP_CSUM_NOK) == 0) 26126c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 26136c8d8eccSSepherosa Ziehau } 26146c8d8eccSSepherosa Ziehau if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) { 26156c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_data = 26166c8d8eccSSepherosa Ziehau cur_rx->bge_tcp_udp_csum; 26176c8d8eccSSepherosa Ziehau m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | 26186c8d8eccSSepherosa Ziehau CSUM_PSEUDO_HDR; 26196c8d8eccSSepherosa Ziehau } 26206c8d8eccSSepherosa Ziehau } 26216c8d8eccSSepherosa Ziehau 26226c8d8eccSSepherosa Ziehau /* 26236c8d8eccSSepherosa Ziehau * If we received a packet with a vlan tag, pass it 26246c8d8eccSSepherosa Ziehau * to vlan_input() instead of ether_input(). 26256c8d8eccSSepherosa Ziehau */ 26266c8d8eccSSepherosa Ziehau if (have_tag) { 26276c8d8eccSSepherosa Ziehau m->m_flags |= M_VLANTAG; 26286c8d8eccSSepherosa Ziehau m->m_pkthdr.ether_vlantag = vlan_tag; 26296c8d8eccSSepherosa Ziehau } 26306c8d8eccSSepherosa Ziehau ifp->if_input(ifp, m); 26316c8d8eccSSepherosa Ziehau } 2632ac2936fdSSepherosa Ziehau bnx_writembx(sc, ret->bnx_rx_mbx, ret->bnx_rx_saved_considx); 26336c8d8eccSSepherosa Ziehau } 26346c8d8eccSSepherosa Ziehau 26356c8d8eccSSepherosa Ziehau static void 263633a04907SSepherosa Ziehau bnx_txeof(struct bnx_tx_ring *txr, uint16_t tx_cons) 26376c8d8eccSSepherosa Ziehau { 263833a04907SSepherosa Ziehau struct ifnet *ifp = &txr->bnx_sc->arpcom.ac_if; 26396c8d8eccSSepherosa Ziehau 26406c8d8eccSSepherosa Ziehau /* 26416c8d8eccSSepherosa Ziehau * Go through our tx ring and free mbufs for those 26426c8d8eccSSepherosa Ziehau * frames that have been sent. 26436c8d8eccSSepherosa Ziehau */ 264433a04907SSepherosa Ziehau while (txr->bnx_tx_saved_considx != tx_cons) { 2645fa4b1067SSepherosa Ziehau struct bnx_tx_buf *buf; 26466c8d8eccSSepherosa Ziehau uint32_t idx = 0; 26476c8d8eccSSepherosa Ziehau 264833a04907SSepherosa Ziehau idx = txr->bnx_tx_saved_considx; 2649fa4b1067SSepherosa Ziehau buf = &txr->bnx_tx_buf[idx]; 2650fa4b1067SSepherosa Ziehau if (buf->bnx_tx_mbuf != NULL) { 2651d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, opackets, 1); 265233a04907SSepherosa Ziehau bus_dmamap_unload(txr->bnx_tx_mtag, 2653fa4b1067SSepherosa Ziehau buf->bnx_tx_dmamap); 2654fa4b1067SSepherosa Ziehau m_freem(buf->bnx_tx_mbuf); 2655fa4b1067SSepherosa Ziehau buf->bnx_tx_mbuf = NULL; 26566c8d8eccSSepherosa Ziehau } 2657fa639b88SSepherosa Ziehau txr->bnx_tx_cnt--; 265833a04907SSepherosa Ziehau BNX_INC(txr->bnx_tx_saved_considx, BGE_TX_RING_CNT); 26596c8d8eccSSepherosa Ziehau } 26606c8d8eccSSepherosa Ziehau 2661fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) >= 26626c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) 26633397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 26646c8d8eccSSepherosa Ziehau 2665fa639b88SSepherosa Ziehau if (txr->bnx_tx_cnt == 0) 26663397dea6SSepherosa Ziehau txr->bnx_tx_watchdog.wd_timer = 0; 26676c8d8eccSSepherosa Ziehau 26683397dea6SSepherosa Ziehau if (!ifsq_is_empty(txr->bnx_ifsq)) 26693397dea6SSepherosa Ziehau ifsq_devstart(txr->bnx_ifsq); 26706c8d8eccSSepherosa Ziehau } 26716c8d8eccSSepherosa Ziehau 267239a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 26736c8d8eccSSepherosa Ziehau 26746c8d8eccSSepherosa Ziehau static void 26754fa38985SSepherosa Ziehau bnx_npoll_rx(struct ifnet *ifp __unused, void *xret, int cycle) 26764fa38985SSepherosa Ziehau { 26774fa38985SSepherosa Ziehau struct bnx_rx_ret_ring *ret = xret; 26784fa38985SSepherosa Ziehau uint16_t rx_prod; 26794fa38985SSepherosa Ziehau 26804fa38985SSepherosa Ziehau ASSERT_SERIALIZED(&ret->bnx_rx_ret_serialize); 26814fa38985SSepherosa Ziehau 26824fa38985SSepherosa Ziehau ret->bnx_saved_status_tag = *ret->bnx_hw_status_tag; 26834fa38985SSepherosa Ziehau cpu_lfence(); 26844fa38985SSepherosa Ziehau 26854fa38985SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 26864fa38985SSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 26874fa38985SSepherosa Ziehau bnx_rxeof(ret, rx_prod, cycle); 26884fa38985SSepherosa Ziehau } 26894fa38985SSepherosa Ziehau 26904fa38985SSepherosa Ziehau static void 26914fa38985SSepherosa Ziehau bnx_npoll_tx(struct ifnet *ifp __unused, void *xtxr, int cycle __unused) 26924fa38985SSepherosa Ziehau { 26934fa38985SSepherosa Ziehau struct bnx_tx_ring *txr = xtxr; 26944fa38985SSepherosa Ziehau uint16_t tx_cons; 26954fa38985SSepherosa Ziehau 26964fa38985SSepherosa Ziehau ASSERT_SERIALIZED(&txr->bnx_tx_serialize); 26974fa38985SSepherosa Ziehau 26984fa38985SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 26994fa38985SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 27004fa38985SSepherosa Ziehau bnx_txeof(txr, tx_cons); 27014fa38985SSepherosa Ziehau } 27024fa38985SSepherosa Ziehau 27034fa38985SSepherosa Ziehau static void 27044fa38985SSepherosa Ziehau bnx_npoll_status(struct ifnet *ifp) 27054fa38985SSepherosa Ziehau { 27064fa38985SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 27070a806e3aSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_intr_data[0].bnx_status_block; 27084fa38985SSepherosa Ziehau 27094fa38985SSepherosa Ziehau ASSERT_SERIALIZED(&sc->bnx_main_serialize); 27104fa38985SSepherosa Ziehau 27114fa38985SSepherosa Ziehau if ((sblk->bge_status & BGE_STATFLAG_LINKSTATE_CHANGED) || 27124fa38985SSepherosa Ziehau sc->bnx_link_evt) 27134fa38985SSepherosa Ziehau bnx_link_poll(sc); 27144fa38985SSepherosa Ziehau } 27154fa38985SSepherosa Ziehau 27164fa38985SSepherosa Ziehau static void 271739a8d43aSSepherosa Ziehau bnx_npoll(struct ifnet *ifp, struct ifpoll_info *info) 271839a8d43aSSepherosa Ziehau { 271939a8d43aSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 27204fa38985SSepherosa Ziehau int i; 272139a8d43aSSepherosa Ziehau 2722329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 272339a8d43aSSepherosa Ziehau 272439a8d43aSSepherosa Ziehau if (info != NULL) { 27254fa38985SSepherosa Ziehau /* 27264fa38985SSepherosa Ziehau * TODO handle RXTX bundle and non-bundle 27274fa38985SSepherosa Ziehau */ 27284fa38985SSepherosa Ziehau info->ifpi_status.status_func = bnx_npoll_status; 27294fa38985SSepherosa Ziehau info->ifpi_status.serializer = &sc->bnx_main_serialize; 273039a8d43aSSepherosa Ziehau 27314fa38985SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 27324fa38985SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 27334fa38985SSepherosa Ziehau int idx = i + sc->bnx_npoll_txoff; 27344fa38985SSepherosa Ziehau 27354fa38985SSepherosa Ziehau KKASSERT(idx < ncpus2); 27364fa38985SSepherosa Ziehau info->ifpi_tx[idx].poll_func = bnx_npoll_tx; 27374fa38985SSepherosa Ziehau info->ifpi_tx[idx].arg = txr; 27384fa38985SSepherosa Ziehau info->ifpi_tx[idx].serializer = &txr->bnx_tx_serialize; 27394fa38985SSepherosa Ziehau ifsq_set_cpuid(txr->bnx_ifsq, idx); 27404fa38985SSepherosa Ziehau } 27414fa38985SSepherosa Ziehau 27424fa38985SSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) { 27434fa38985SSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i]; 27444fa38985SSepherosa Ziehau int idx = i + sc->bnx_npoll_rxoff; 27454fa38985SSepherosa Ziehau 27464fa38985SSepherosa Ziehau KKASSERT(idx < ncpus2); 27474fa38985SSepherosa Ziehau info->ifpi_rx[idx].poll_func = bnx_npoll_rx; 27484fa38985SSepherosa Ziehau info->ifpi_rx[idx].arg = ret; 27494fa38985SSepherosa Ziehau info->ifpi_rx[idx].serializer = 27504fa38985SSepherosa Ziehau &ret->bnx_rx_ret_serialize; 27514fa38985SSepherosa Ziehau } 275239a8d43aSSepherosa Ziehau 27537dbaa833SSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 275439a8d43aSSepherosa Ziehau bnx_disable_intr(sc); 27557dbaa833SSepherosa Ziehau bnx_set_tick_cpuid(sc, TRUE); 27567dbaa833SSepherosa Ziehau } 275739a8d43aSSepherosa Ziehau } else { 27584fa38985SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 27594fa38985SSepherosa Ziehau ifsq_set_cpuid(sc->bnx_tx_ring[i].bnx_ifsq, 27604fa38985SSepherosa Ziehau sc->bnx_tx_ring[i].bnx_tx_cpuid); 27614fa38985SSepherosa Ziehau } 27627dbaa833SSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 276339a8d43aSSepherosa Ziehau bnx_enable_intr(sc); 27647dbaa833SSepherosa Ziehau bnx_set_tick_cpuid(sc, FALSE); 27657dbaa833SSepherosa Ziehau } 276639a8d43aSSepherosa Ziehau } 276739a8d43aSSepherosa Ziehau } 276839a8d43aSSepherosa Ziehau 276939a8d43aSSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 27706c8d8eccSSepherosa Ziehau 27716c8d8eccSSepherosa Ziehau static void 27726c8d8eccSSepherosa Ziehau bnx_intr_legacy(void *xsc) 27736c8d8eccSSepherosa Ziehau { 27746c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 27754fa38985SSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 27766c8d8eccSSepherosa Ziehau 27774fa38985SSepherosa Ziehau if (ret->bnx_saved_status_tag == *ret->bnx_hw_status_tag) { 27786c8d8eccSSepherosa Ziehau uint32_t val; 27796c8d8eccSSepherosa Ziehau 27806c8d8eccSSepherosa Ziehau val = pci_read_config(sc->bnx_dev, BGE_PCI_PCISTATE, 4); 27816c8d8eccSSepherosa Ziehau if (val & BGE_PCISTAT_INTR_NOTACT) 27826c8d8eccSSepherosa Ziehau return; 27836c8d8eccSSepherosa Ziehau } 27846c8d8eccSSepherosa Ziehau 27856c8d8eccSSepherosa Ziehau /* 27866c8d8eccSSepherosa Ziehau * NOTE: 27876c8d8eccSSepherosa Ziehau * Interrupt will have to be disabled if tagged status 27886c8d8eccSSepherosa Ziehau * is used, else interrupt will always be asserted on 27896c8d8eccSSepherosa Ziehau * certain chips (at least on BCM5750 AX/BX). 27906c8d8eccSSepherosa Ziehau */ 27916c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 27926c8d8eccSSepherosa Ziehau 27936c8d8eccSSepherosa Ziehau bnx_intr(sc); 27946c8d8eccSSepherosa Ziehau } 27956c8d8eccSSepherosa Ziehau 27966c8d8eccSSepherosa Ziehau static void 27976c8d8eccSSepherosa Ziehau bnx_msi_oneshot(void *xsc) 27986c8d8eccSSepherosa Ziehau { 27996c8d8eccSSepherosa Ziehau bnx_intr(xsc); 28006c8d8eccSSepherosa Ziehau } 28016c8d8eccSSepherosa Ziehau 28026c8d8eccSSepherosa Ziehau static void 28036c8d8eccSSepherosa Ziehau bnx_intr(struct bnx_softc *sc) 28046c8d8eccSSepherosa Ziehau { 28056c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 28064fa38985SSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 28070a806e3aSSepherosa Ziehau struct bge_status_block *sblk = sc->bnx_intr_data[0].bnx_status_block; 28086c8d8eccSSepherosa Ziehau uint32_t status; 28096c8d8eccSSepherosa Ziehau 2810329f9016SSepherosa Ziehau ASSERT_SERIALIZED(&sc->bnx_main_serialize); 2811329f9016SSepherosa Ziehau 28124fa38985SSepherosa Ziehau ret->bnx_saved_status_tag = *ret->bnx_hw_status_tag; 28136c8d8eccSSepherosa Ziehau /* 28146c8d8eccSSepherosa Ziehau * Use a load fence to ensure that status_tag is saved 28156c8d8eccSSepherosa Ziehau * before rx_prod, tx_cons and status. 28166c8d8eccSSepherosa Ziehau */ 28176c8d8eccSSepherosa Ziehau cpu_lfence(); 28186c8d8eccSSepherosa Ziehau 28196c8d8eccSSepherosa Ziehau status = sblk->bge_status; 28206c8d8eccSSepherosa Ziehau 28216c8d8eccSSepherosa Ziehau if ((status & BGE_STATFLAG_LINKSTATE_CHANGED) || sc->bnx_link_evt) 28226c8d8eccSSepherosa Ziehau bnx_link_poll(sc); 28236c8d8eccSSepherosa Ziehau 28246c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 28254fa38985SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 28263a16b7b8SSepherosa Ziehau uint16_t rx_prod, tx_cons; 28273a16b7b8SSepherosa Ziehau 2828329f9016SSepherosa Ziehau lwkt_serialize_enter(&ret->bnx_rx_ret_serialize); 28293a16b7b8SSepherosa Ziehau rx_prod = *ret->bnx_rx_considx; 2830beedf5beSSepherosa Ziehau if (ret->bnx_rx_saved_considx != rx_prod) 2831beedf5beSSepherosa Ziehau bnx_rxeof(ret, rx_prod, -1); 2832329f9016SSepherosa Ziehau lwkt_serialize_exit(&ret->bnx_rx_ret_serialize); 28336c8d8eccSSepherosa Ziehau 2834329f9016SSepherosa Ziehau lwkt_serialize_enter(&txr->bnx_tx_serialize); 2835329f9016SSepherosa Ziehau tx_cons = *txr->bnx_tx_considx; 283633a04907SSepherosa Ziehau if (txr->bnx_tx_saved_considx != tx_cons) 283733a04907SSepherosa Ziehau bnx_txeof(txr, tx_cons); 2838329f9016SSepherosa Ziehau lwkt_serialize_exit(&txr->bnx_tx_serialize); 28396c8d8eccSSepherosa Ziehau } 28406c8d8eccSSepherosa Ziehau 28414fa38985SSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, ret->bnx_saved_status_tag << 24); 28426c8d8eccSSepherosa Ziehau } 28436c8d8eccSSepherosa Ziehau 28446c8d8eccSSepherosa Ziehau static void 28456c8d8eccSSepherosa Ziehau bnx_tick(void *xsc) 28466c8d8eccSSepherosa Ziehau { 28476c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 28486c8d8eccSSepherosa Ziehau 2849329f9016SSepherosa Ziehau lwkt_serialize_enter(&sc->bnx_main_serialize); 28506c8d8eccSSepherosa Ziehau 28516c8d8eccSSepherosa Ziehau bnx_stats_update_regs(sc); 28526c8d8eccSSepherosa Ziehau 28536c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 28546c8d8eccSSepherosa Ziehau /* 28556c8d8eccSSepherosa Ziehau * Since in TBI mode auto-polling can't be used we should poll 28566c8d8eccSSepherosa Ziehau * link status manually. Here we register pending link event 28576c8d8eccSSepherosa Ziehau * and trigger interrupt. 28586c8d8eccSSepherosa Ziehau */ 28596c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 28606c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 28616c8d8eccSSepherosa Ziehau } else if (!sc->bnx_link) { 28626c8d8eccSSepherosa Ziehau mii_tick(device_get_softc(sc->bnx_miibus)); 28636c8d8eccSSepherosa Ziehau } 28646c8d8eccSSepherosa Ziehau 28657dbaa833SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_tick_timer, hz, bnx_tick, sc, 28667dbaa833SSepherosa Ziehau sc->bnx_tick_cpuid); 28676c8d8eccSSepherosa Ziehau 2868329f9016SSepherosa Ziehau lwkt_serialize_exit(&sc->bnx_main_serialize); 28696c8d8eccSSepherosa Ziehau } 28706c8d8eccSSepherosa Ziehau 28716c8d8eccSSepherosa Ziehau static void 28726c8d8eccSSepherosa Ziehau bnx_stats_update_regs(struct bnx_softc *sc) 28736c8d8eccSSepherosa Ziehau { 28746c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 28756c8d8eccSSepherosa Ziehau struct bge_mac_stats_regs stats; 28766c8d8eccSSepherosa Ziehau uint32_t *s; 28776c8d8eccSSepherosa Ziehau int i; 28786c8d8eccSSepherosa Ziehau 28796c8d8eccSSepherosa Ziehau s = (uint32_t *)&stats; 28806c8d8eccSSepherosa Ziehau for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) { 28816c8d8eccSSepherosa Ziehau *s = CSR_READ_4(sc, BGE_RX_STATS + i); 28826c8d8eccSSepherosa Ziehau s++; 28836c8d8eccSSepherosa Ziehau } 28846c8d8eccSSepherosa Ziehau 2885d40991efSSepherosa Ziehau IFNET_STAT_SET(ifp, collisions, 28866c8d8eccSSepherosa Ziehau (stats.dot3StatsSingleCollisionFrames + 28876c8d8eccSSepherosa Ziehau stats.dot3StatsMultipleCollisionFrames + 28886c8d8eccSSepherosa Ziehau stats.dot3StatsExcessiveCollisions + 2889d40991efSSepherosa Ziehau stats.dot3StatsLateCollisions)); 28906c8d8eccSSepherosa Ziehau } 28916c8d8eccSSepherosa Ziehau 28926c8d8eccSSepherosa Ziehau /* 28936c8d8eccSSepherosa Ziehau * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data 28946c8d8eccSSepherosa Ziehau * pointers to descriptors. 28956c8d8eccSSepherosa Ziehau */ 28966c8d8eccSSepherosa Ziehau static int 289733a04907SSepherosa Ziehau bnx_encap(struct bnx_tx_ring *txr, struct mbuf **m_head0, uint32_t *txidx, 2898c9b7f592SSepherosa Ziehau int *segs_used) 28996c8d8eccSSepherosa Ziehau { 29006c8d8eccSSepherosa Ziehau struct bge_tx_bd *d = NULL; 290166deb1c1SSepherosa Ziehau uint16_t csum_flags = 0, vlan_tag = 0, mss = 0; 29026c8d8eccSSepherosa Ziehau bus_dma_segment_t segs[BNX_NSEG_NEW]; 29036c8d8eccSSepherosa Ziehau bus_dmamap_t map; 29046c8d8eccSSepherosa Ziehau int error, maxsegs, nsegs, idx, i; 29056c8d8eccSSepherosa Ziehau struct mbuf *m_head = *m_head0, *m_new; 29066c8d8eccSSepherosa Ziehau 290766deb1c1SSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { 290866deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 290966deb1c1SSepherosa Ziehau int tso_nsegs; 291066deb1c1SSepherosa Ziehau #endif 291166deb1c1SSepherosa Ziehau 291233a04907SSepherosa Ziehau error = bnx_setup_tso(txr, m_head0, &mss, &csum_flags); 291366deb1c1SSepherosa Ziehau if (error) 291466deb1c1SSepherosa Ziehau return error; 291566deb1c1SSepherosa Ziehau m_head = *m_head0; 291666deb1c1SSepherosa Ziehau 291766deb1c1SSepherosa Ziehau #ifdef BNX_TSO_DEBUG 2918f0336d39SSepherosa Ziehau tso_nsegs = (m_head->m_pkthdr.len / 2919f0336d39SSepherosa Ziehau m_head->m_pkthdr.tso_segsz) - 1; 292066deb1c1SSepherosa Ziehau if (tso_nsegs > (BNX_TSO_NSTATS - 1)) 292166deb1c1SSepherosa Ziehau tso_nsegs = BNX_TSO_NSTATS - 1; 292266deb1c1SSepherosa Ziehau else if (tso_nsegs < 0) 292366deb1c1SSepherosa Ziehau tso_nsegs = 0; 29245a0c3c3aSSascha Wildner txr->bnx_sc->bnx_tsosegs[tso_nsegs]++; 292566deb1c1SSepherosa Ziehau #endif 292666deb1c1SSepherosa Ziehau } else if (m_head->m_pkthdr.csum_flags & BNX_CSUM_FEATURES) { 29276c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & CSUM_IP) 29286c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_CSUM; 29296c8d8eccSSepherosa Ziehau if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP)) 29306c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_TCP_UDP_CSUM; 29316c8d8eccSSepherosa Ziehau if (m_head->m_flags & M_LASTFRAG) 29326c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG_END; 29336c8d8eccSSepherosa Ziehau else if (m_head->m_flags & M_FRAG) 29346c8d8eccSSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_IP_FRAG; 29356c8d8eccSSepherosa Ziehau } 293666deb1c1SSepherosa Ziehau if (m_head->m_flags & M_VLANTAG) { 293766deb1c1SSepherosa Ziehau csum_flags |= BGE_TXBDFLAG_VLAN_TAG; 293866deb1c1SSepherosa Ziehau vlan_tag = m_head->m_pkthdr.ether_vlantag; 293966deb1c1SSepherosa Ziehau } 29406c8d8eccSSepherosa Ziehau 29416c8d8eccSSepherosa Ziehau idx = *txidx; 2942fa4b1067SSepherosa Ziehau map = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 29436c8d8eccSSepherosa Ziehau 2944fa639b88SSepherosa Ziehau maxsegs = (BGE_TX_RING_CNT - txr->bnx_tx_cnt) - BNX_NSEG_RSVD; 29456c8d8eccSSepherosa Ziehau KASSERT(maxsegs >= BNX_NSEG_SPARE, 29466c8d8eccSSepherosa Ziehau ("not enough segments %d", maxsegs)); 29476c8d8eccSSepherosa Ziehau 29486c8d8eccSSepherosa Ziehau if (maxsegs > BNX_NSEG_NEW) 29496c8d8eccSSepherosa Ziehau maxsegs = BNX_NSEG_NEW; 29506c8d8eccSSepherosa Ziehau 29516c8d8eccSSepherosa Ziehau /* 29526c8d8eccSSepherosa Ziehau * Pad outbound frame to BGE_MIN_FRAMELEN for an unusual reason. 29536c8d8eccSSepherosa Ziehau * The bge hardware will pad out Tx runts to BGE_MIN_FRAMELEN, 29546c8d8eccSSepherosa Ziehau * but when such padded frames employ the bge IP/TCP checksum 29556c8d8eccSSepherosa Ziehau * offload, the hardware checksum assist gives incorrect results 29566c8d8eccSSepherosa Ziehau * (possibly from incorporating its own padding into the UDP/TCP 29576c8d8eccSSepherosa Ziehau * checksum; who knows). If we pad such runts with zeros, the 29586c8d8eccSSepherosa Ziehau * onboard checksum comes out correct. 29596c8d8eccSSepherosa Ziehau */ 29606c8d8eccSSepherosa Ziehau if ((csum_flags & BGE_TXBDFLAG_TCP_UDP_CSUM) && 29616c8d8eccSSepherosa Ziehau m_head->m_pkthdr.len < BNX_MIN_FRAMELEN) { 29626c8d8eccSSepherosa Ziehau error = m_devpad(m_head, BNX_MIN_FRAMELEN); 29636c8d8eccSSepherosa Ziehau if (error) 29646c8d8eccSSepherosa Ziehau goto back; 29656c8d8eccSSepherosa Ziehau } 29666c8d8eccSSepherosa Ziehau 296779a64343SSepherosa Ziehau if ((txr->bnx_tx_flags & BNX_TX_FLAG_SHORTDMA) && 296833a04907SSepherosa Ziehau m_head->m_next != NULL) { 29696c8d8eccSSepherosa Ziehau m_new = bnx_defrag_shortdma(m_head); 29706c8d8eccSSepherosa Ziehau if (m_new == NULL) { 29716c8d8eccSSepherosa Ziehau error = ENOBUFS; 29726c8d8eccSSepherosa Ziehau goto back; 29736c8d8eccSSepherosa Ziehau } 29746c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 29756c8d8eccSSepherosa Ziehau } 297666deb1c1SSepherosa Ziehau if ((m_head->m_pkthdr.csum_flags & CSUM_TSO) == 0 && 2977aad4de2bSSepherosa Ziehau (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) && 2978aad4de2bSSepherosa Ziehau m_head->m_next != NULL) { 29796c8d8eccSSepherosa Ziehau /* 29806c8d8eccSSepherosa Ziehau * Forcefully defragment mbuf chain to overcome hardware 29816c8d8eccSSepherosa Ziehau * limitation which only support a single outstanding 29826c8d8eccSSepherosa Ziehau * DMA read operation. If it fails, keep moving on using 29836c8d8eccSSepherosa Ziehau * the original mbuf chain. 29846c8d8eccSSepherosa Ziehau */ 29856c8d8eccSSepherosa Ziehau m_new = m_defrag(m_head, MB_DONTWAIT); 29866c8d8eccSSepherosa Ziehau if (m_new != NULL) 29876c8d8eccSSepherosa Ziehau *m_head0 = m_head = m_new; 29886c8d8eccSSepherosa Ziehau } 29896c8d8eccSSepherosa Ziehau 299033a04907SSepherosa Ziehau error = bus_dmamap_load_mbuf_defrag(txr->bnx_tx_mtag, map, 29916c8d8eccSSepherosa Ziehau m_head0, segs, maxsegs, &nsegs, BUS_DMA_NOWAIT); 29926c8d8eccSSepherosa Ziehau if (error) 29936c8d8eccSSepherosa Ziehau goto back; 2994c9b7f592SSepherosa Ziehau *segs_used += nsegs; 29956c8d8eccSSepherosa Ziehau 29966c8d8eccSSepherosa Ziehau m_head = *m_head0; 299733a04907SSepherosa Ziehau bus_dmamap_sync(txr->bnx_tx_mtag, map, BUS_DMASYNC_PREWRITE); 29986c8d8eccSSepherosa Ziehau 29996c8d8eccSSepherosa Ziehau for (i = 0; ; i++) { 300033a04907SSepherosa Ziehau d = &txr->bnx_tx_ring[idx]; 30016c8d8eccSSepherosa Ziehau 30026c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_lo = BGE_ADDR_LO(segs[i].ds_addr); 30036c8d8eccSSepherosa Ziehau d->bge_addr.bge_addr_hi = BGE_ADDR_HI(segs[i].ds_addr); 30046c8d8eccSSepherosa Ziehau d->bge_len = segs[i].ds_len; 30056c8d8eccSSepherosa Ziehau d->bge_flags = csum_flags; 300666deb1c1SSepherosa Ziehau d->bge_vlan_tag = vlan_tag; 300766deb1c1SSepherosa Ziehau d->bge_mss = mss; 30086c8d8eccSSepherosa Ziehau 30096c8d8eccSSepherosa Ziehau if (i == nsegs - 1) 30106c8d8eccSSepherosa Ziehau break; 30116c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 30126c8d8eccSSepherosa Ziehau } 30136c8d8eccSSepherosa Ziehau /* Mark the last segment as end of packet... */ 30146c8d8eccSSepherosa Ziehau d->bge_flags |= BGE_TXBDFLAG_END; 30156c8d8eccSSepherosa Ziehau 30166c8d8eccSSepherosa Ziehau /* 30176c8d8eccSSepherosa Ziehau * Insure that the map for this transmission is placed at 30186c8d8eccSSepherosa Ziehau * the array index of the last descriptor in this chain. 30196c8d8eccSSepherosa Ziehau */ 3020fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[*txidx].bnx_tx_dmamap = txr->bnx_tx_buf[idx].bnx_tx_dmamap; 3021fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_dmamap = map; 3022fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[idx].bnx_tx_mbuf = m_head; 3023fa639b88SSepherosa Ziehau txr->bnx_tx_cnt += nsegs; 30246c8d8eccSSepherosa Ziehau 30256c8d8eccSSepherosa Ziehau BNX_INC(idx, BGE_TX_RING_CNT); 30266c8d8eccSSepherosa Ziehau *txidx = idx; 30276c8d8eccSSepherosa Ziehau back: 30286c8d8eccSSepherosa Ziehau if (error) { 30296c8d8eccSSepherosa Ziehau m_freem(*m_head0); 30306c8d8eccSSepherosa Ziehau *m_head0 = NULL; 30316c8d8eccSSepherosa Ziehau } 30326c8d8eccSSepherosa Ziehau return error; 30336c8d8eccSSepherosa Ziehau } 30346c8d8eccSSepherosa Ziehau 30356c8d8eccSSepherosa Ziehau /* 30366c8d8eccSSepherosa Ziehau * Main transmit routine. To avoid having to do mbuf copies, we put pointers 30376c8d8eccSSepherosa Ziehau * to the mbuf data regions directly in the transmit descriptors. 30386c8d8eccSSepherosa Ziehau */ 30396c8d8eccSSepherosa Ziehau static void 3040f0a26983SSepherosa Ziehau bnx_start(struct ifnet *ifp, struct ifaltq_subque *ifsq) 30416c8d8eccSSepherosa Ziehau { 30423397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = ifsq_get_priv(ifsq); 30436c8d8eccSSepherosa Ziehau struct mbuf *m_head = NULL; 30446c8d8eccSSepherosa Ziehau uint32_t prodidx; 3045c9b7f592SSepherosa Ziehau int nsegs = 0; 30466c8d8eccSSepherosa Ziehau 30473397dea6SSepherosa Ziehau KKASSERT(txr->bnx_ifsq == ifsq); 3048329f9016SSepherosa Ziehau ASSERT_SERIALIZED(&txr->bnx_tx_serialize); 3049f0a26983SSepherosa Ziehau 30503397dea6SSepherosa Ziehau if ((ifp->if_flags & IFF_RUNNING) == 0 || ifsq_is_oactive(ifsq)) 30516c8d8eccSSepherosa Ziehau return; 30526c8d8eccSSepherosa Ziehau 305333a04907SSepherosa Ziehau prodidx = txr->bnx_tx_prodidx; 30546c8d8eccSSepherosa Ziehau 3055fa4b1067SSepherosa Ziehau while (txr->bnx_tx_buf[prodidx].bnx_tx_mbuf == NULL) { 30566c8d8eccSSepherosa Ziehau /* 30576c8d8eccSSepherosa Ziehau * Sanity check: avoid coming within BGE_NSEG_RSVD 30586c8d8eccSSepherosa Ziehau * descriptors of the end of the ring. Also make 30596c8d8eccSSepherosa Ziehau * sure there are BGE_NSEG_SPARE descriptors for 3060a1bd58c9SSepherosa Ziehau * jumbo buffers' or TSO segments' defragmentation. 30616c8d8eccSSepherosa Ziehau */ 3062fa639b88SSepherosa Ziehau if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) < 30636c8d8eccSSepherosa Ziehau (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) { 30643397dea6SSepherosa Ziehau ifsq_set_oactive(ifsq); 30656c8d8eccSSepherosa Ziehau break; 30666c8d8eccSSepherosa Ziehau } 30676c8d8eccSSepherosa Ziehau 30683397dea6SSepherosa Ziehau m_head = ifsq_dequeue(ifsq, NULL); 3069a1bd58c9SSepherosa Ziehau if (m_head == NULL) 3070a1bd58c9SSepherosa Ziehau break; 3071a1bd58c9SSepherosa Ziehau 30726c8d8eccSSepherosa Ziehau /* 30736c8d8eccSSepherosa Ziehau * Pack the data into the transmit ring. If we 30746c8d8eccSSepherosa Ziehau * don't have room, set the OACTIVE flag and wait 30756c8d8eccSSepherosa Ziehau * for the NIC to drain the ring. 30766c8d8eccSSepherosa Ziehau */ 307733a04907SSepherosa Ziehau if (bnx_encap(txr, &m_head, &prodidx, &nsegs)) { 30783397dea6SSepherosa Ziehau ifsq_set_oactive(ifsq); 3079d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 30806c8d8eccSSepherosa Ziehau break; 30816c8d8eccSSepherosa Ziehau } 30826c8d8eccSSepherosa Ziehau 308333a04907SSepherosa Ziehau if (nsegs >= txr->bnx_tx_wreg) { 30846c8d8eccSSepherosa Ziehau /* Transmit */ 30858bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 3086c9b7f592SSepherosa Ziehau nsegs = 0; 3087c9b7f592SSepherosa Ziehau } 30886c8d8eccSSepherosa Ziehau 3089c9b7f592SSepherosa Ziehau ETHER_BPF_MTAP(ifp, m_head); 30906c8d8eccSSepherosa Ziehau 30916c8d8eccSSepherosa Ziehau /* 30926c8d8eccSSepherosa Ziehau * Set a timeout in case the chip goes out to lunch. 30936c8d8eccSSepherosa Ziehau */ 30943397dea6SSepherosa Ziehau txr->bnx_tx_watchdog.wd_timer = 5; 30956c8d8eccSSepherosa Ziehau } 30966c8d8eccSSepherosa Ziehau 3097c9b7f592SSepherosa Ziehau if (nsegs > 0) { 3098c9b7f592SSepherosa Ziehau /* Transmit */ 30998bd43d5dSSepherosa Ziehau bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx); 3100c9b7f592SSepherosa Ziehau } 310133a04907SSepherosa Ziehau txr->bnx_tx_prodidx = prodidx; 3102c9b7f592SSepherosa Ziehau } 3103c9b7f592SSepherosa Ziehau 31046c8d8eccSSepherosa Ziehau static void 31056c8d8eccSSepherosa Ziehau bnx_init(void *xsc) 31066c8d8eccSSepherosa Ziehau { 31076c8d8eccSSepherosa Ziehau struct bnx_softc *sc = xsc; 31086c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 31096c8d8eccSSepherosa Ziehau uint16_t *m; 31106c8d8eccSSepherosa Ziehau uint32_t mode; 311133a04907SSepherosa Ziehau int i; 31127dbaa833SSepherosa Ziehau boolean_t polling; 31136c8d8eccSSepherosa Ziehau 3114329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 31156c8d8eccSSepherosa Ziehau 31166c8d8eccSSepherosa Ziehau /* Cancel pending I/O and flush buffers. */ 31176c8d8eccSSepherosa Ziehau bnx_stop(sc); 31186c8d8eccSSepherosa Ziehau bnx_reset(sc); 31196c8d8eccSSepherosa Ziehau bnx_chipinit(sc); 31206c8d8eccSSepherosa Ziehau 31216c8d8eccSSepherosa Ziehau /* 31226c8d8eccSSepherosa Ziehau * Init the various state machines, ring 31236c8d8eccSSepherosa Ziehau * control blocks and firmware. 31246c8d8eccSSepherosa Ziehau */ 31256c8d8eccSSepherosa Ziehau if (bnx_blockinit(sc)) { 31266c8d8eccSSepherosa Ziehau if_printf(ifp, "initialization failure\n"); 31276c8d8eccSSepherosa Ziehau bnx_stop(sc); 31286c8d8eccSSepherosa Ziehau return; 31296c8d8eccSSepherosa Ziehau } 31306c8d8eccSSepherosa Ziehau 31316c8d8eccSSepherosa Ziehau /* Specify MTU. */ 31326c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu + 31336c8d8eccSSepherosa Ziehau ETHER_HDR_LEN + ETHER_CRC_LEN + EVL_ENCAPLEN); 31346c8d8eccSSepherosa Ziehau 31356c8d8eccSSepherosa Ziehau /* Load our MAC address. */ 31366c8d8eccSSepherosa Ziehau m = (uint16_t *)&sc->arpcom.ac_enaddr[0]; 31376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_LO, htons(m[0])); 31386c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_ADDR1_HI, (htons(m[1]) << 16) | htons(m[2])); 31396c8d8eccSSepherosa Ziehau 31406c8d8eccSSepherosa Ziehau /* Enable or disable promiscuous mode as needed. */ 31416c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 31426c8d8eccSSepherosa Ziehau 31436c8d8eccSSepherosa Ziehau /* Program multicast filter. */ 31446c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 31456c8d8eccSSepherosa Ziehau 31466c8d8eccSSepherosa Ziehau /* Init RX ring. */ 3147beedf5beSSepherosa Ziehau if (bnx_init_rx_ring_std(&sc->bnx_rx_std_ring)) { 31486c8d8eccSSepherosa Ziehau if_printf(ifp, "RX ring initialization failed\n"); 31496c8d8eccSSepherosa Ziehau bnx_stop(sc); 31506c8d8eccSSepherosa Ziehau return; 31516c8d8eccSSepherosa Ziehau } 31526c8d8eccSSepherosa Ziehau 31536c8d8eccSSepherosa Ziehau /* Init jumbo RX ring. */ 31546c8d8eccSSepherosa Ziehau if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) { 31556c8d8eccSSepherosa Ziehau if (bnx_init_rx_ring_jumbo(sc)) { 31566c8d8eccSSepherosa Ziehau if_printf(ifp, "Jumbo RX ring initialization failed\n"); 31576c8d8eccSSepherosa Ziehau bnx_stop(sc); 31586c8d8eccSSepherosa Ziehau return; 31596c8d8eccSSepherosa Ziehau } 31606c8d8eccSSepherosa Ziehau } 31616c8d8eccSSepherosa Ziehau 31626c8d8eccSSepherosa Ziehau /* Init our RX return ring index */ 3163841cdf08SSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) { 3164841cdf08SSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i]; 3165841cdf08SSepherosa Ziehau 3166841cdf08SSepherosa Ziehau ret->bnx_rx_saved_considx = 0; 3167841cdf08SSepherosa Ziehau ret->bnx_rx_cnt = 0; 3168841cdf08SSepherosa Ziehau } 31696c8d8eccSSepherosa Ziehau 31706c8d8eccSSepherosa Ziehau /* Init TX ring. */ 317133a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 317233a04907SSepherosa Ziehau bnx_init_tx_ring(&sc->bnx_tx_ring[i]); 31736c8d8eccSSepherosa Ziehau 31746c8d8eccSSepherosa Ziehau /* Enable TX MAC state machine lockup fix. */ 31756c8d8eccSSepherosa Ziehau mode = CSR_READ_4(sc, BGE_TX_MODE); 31766c8d8eccSSepherosa Ziehau mode |= BGE_TXMODE_MBUF_LOCKUP_FIX; 3177b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 3178b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 31796c8d8eccSSepherosa Ziehau mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 31806c8d8eccSSepherosa Ziehau mode |= CSR_READ_4(sc, BGE_TX_MODE) & 31816c8d8eccSSepherosa Ziehau (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); 31826c8d8eccSSepherosa Ziehau } 31836c8d8eccSSepherosa Ziehau /* Turn on transmitter */ 31846c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE); 31856c8d8eccSSepherosa Ziehau 31866c8d8eccSSepherosa Ziehau /* Turn on receiver */ 31876c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 31886c8d8eccSSepherosa Ziehau 31896c8d8eccSSepherosa Ziehau /* 31906c8d8eccSSepherosa Ziehau * Set the number of good frames to receive after RX MBUF 31916c8d8eccSSepherosa Ziehau * Low Watermark has been reached. After the RX MAC receives 31926c8d8eccSSepherosa Ziehau * this number of frames, it will drop subsequent incoming 31936c8d8eccSSepherosa Ziehau * frames until the MBUF High Watermark is reached. 31946c8d8eccSSepherosa Ziehau */ 3195bcb29629SSepherosa Ziehau if (BNX_IS_57765_FAMILY(sc)) 31966c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 1); 31976c8d8eccSSepherosa Ziehau else 31986c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2); 31996c8d8eccSSepherosa Ziehau 3200f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) { 32016c8d8eccSSepherosa Ziehau if (bootverbose) { 32026c8d8eccSSepherosa Ziehau if_printf(ifp, "MSI_MODE: %#x\n", 32036c8d8eccSSepherosa Ziehau CSR_READ_4(sc, BGE_MSI_MODE)); 32046c8d8eccSSepherosa Ziehau } 32056c8d8eccSSepherosa Ziehau } 32066c8d8eccSSepherosa Ziehau 32076c8d8eccSSepherosa Ziehau /* Tell firmware we're alive. */ 32086c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 32096c8d8eccSSepherosa Ziehau 32106c8d8eccSSepherosa Ziehau /* Enable host interrupts if polling(4) is not enabled. */ 32116c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA, 4); 32127dbaa833SSepherosa Ziehau 32137dbaa833SSepherosa Ziehau polling = FALSE; 321439a8d43aSSepherosa Ziehau #ifdef IFPOLL_ENABLE 321539a8d43aSSepherosa Ziehau if (ifp->if_flags & IFF_NPOLLING) 32167dbaa833SSepherosa Ziehau polling = TRUE; 32177dbaa833SSepherosa Ziehau #endif 32187dbaa833SSepherosa Ziehau if (polling) 32196c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 32206c8d8eccSSepherosa Ziehau else 32216c8d8eccSSepherosa Ziehau bnx_enable_intr(sc); 32227dbaa833SSepherosa Ziehau bnx_set_tick_cpuid(sc, polling); 32236c8d8eccSSepherosa Ziehau 32246c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(ifp); 32256c8d8eccSSepherosa Ziehau 32266c8d8eccSSepherosa Ziehau ifp->if_flags |= IFF_RUNNING; 32273397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 32283397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 32293397dea6SSepherosa Ziehau 32303397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 32313397dea6SSepherosa Ziehau ifsq_watchdog_start(&txr->bnx_tx_watchdog); 32323397dea6SSepherosa Ziehau } 32336c8d8eccSSepherosa Ziehau 32347dbaa833SSepherosa Ziehau callout_reset_bycpu(&sc->bnx_tick_timer, hz, bnx_tick, sc, 32357dbaa833SSepherosa Ziehau sc->bnx_tick_cpuid); 32366c8d8eccSSepherosa Ziehau } 32376c8d8eccSSepherosa Ziehau 32386c8d8eccSSepherosa Ziehau /* 32396c8d8eccSSepherosa Ziehau * Set media options. 32406c8d8eccSSepherosa Ziehau */ 32416c8d8eccSSepherosa Ziehau static int 32426c8d8eccSSepherosa Ziehau bnx_ifmedia_upd(struct ifnet *ifp) 32436c8d8eccSSepherosa Ziehau { 32446c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 32456c8d8eccSSepherosa Ziehau 32466c8d8eccSSepherosa Ziehau /* If this is a 1000baseX NIC, enable the TBI port. */ 32476c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 32486c8d8eccSSepherosa Ziehau struct ifmedia *ifm = &sc->bnx_ifmedia; 32496c8d8eccSSepherosa Ziehau 32506c8d8eccSSepherosa Ziehau if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 32516c8d8eccSSepherosa Ziehau return(EINVAL); 32526c8d8eccSSepherosa Ziehau 32536c8d8eccSSepherosa Ziehau switch(IFM_SUBTYPE(ifm->ifm_media)) { 32546c8d8eccSSepherosa Ziehau case IFM_AUTO: 32556c8d8eccSSepherosa Ziehau break; 32566c8d8eccSSepherosa Ziehau 32576c8d8eccSSepherosa Ziehau case IFM_1000_SX: 32586c8d8eccSSepherosa Ziehau if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 32596c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 32606c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 32616c8d8eccSSepherosa Ziehau } else { 32626c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MAC_MODE, 32636c8d8eccSSepherosa Ziehau BGE_MACMODE_HALF_DUPLEX); 32646c8d8eccSSepherosa Ziehau } 32656c8d8eccSSepherosa Ziehau break; 32666c8d8eccSSepherosa Ziehau default: 32676c8d8eccSSepherosa Ziehau return(EINVAL); 32686c8d8eccSSepherosa Ziehau } 32696c8d8eccSSepherosa Ziehau } else { 32706c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 32716c8d8eccSSepherosa Ziehau 32726c8d8eccSSepherosa Ziehau sc->bnx_link_evt++; 32736c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 32746c8d8eccSSepherosa Ziehau if (mii->mii_instance) { 32756c8d8eccSSepherosa Ziehau struct mii_softc *miisc; 32766c8d8eccSSepherosa Ziehau 32776c8d8eccSSepherosa Ziehau LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 32786c8d8eccSSepherosa Ziehau mii_phy_reset(miisc); 32796c8d8eccSSepherosa Ziehau } 32806c8d8eccSSepherosa Ziehau mii_mediachg(mii); 32816c8d8eccSSepherosa Ziehau 32826c8d8eccSSepherosa Ziehau /* 32836c8d8eccSSepherosa Ziehau * Force an interrupt so that we will call bnx_link_upd 32846c8d8eccSSepherosa Ziehau * if needed and clear any pending link state attention. 32856c8d8eccSSepherosa Ziehau * Without this we are not getting any further interrupts 32866c8d8eccSSepherosa Ziehau * for link state changes and thus will not UP the link and 32876c8d8eccSSepherosa Ziehau * not be able to send in bnx_start. The only way to get 32886c8d8eccSSepherosa Ziehau * things working was to receive a packet and get an RX 32896c8d8eccSSepherosa Ziehau * intr. 32906c8d8eccSSepherosa Ziehau * 32916c8d8eccSSepherosa Ziehau * bnx_tick should help for fiber cards and we might not 32926c8d8eccSSepherosa Ziehau * need to do this here if BNX_FLAG_TBI is set but as 32936c8d8eccSSepherosa Ziehau * we poll for fiber anyway it should not harm. 32946c8d8eccSSepherosa Ziehau */ 32956c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW); 32966c8d8eccSSepherosa Ziehau } 32976c8d8eccSSepherosa Ziehau return(0); 32986c8d8eccSSepherosa Ziehau } 32996c8d8eccSSepherosa Ziehau 33006c8d8eccSSepherosa Ziehau /* 33016c8d8eccSSepherosa Ziehau * Report current media status. 33026c8d8eccSSepherosa Ziehau */ 33036c8d8eccSSepherosa Ziehau static void 33046c8d8eccSSepherosa Ziehau bnx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 33056c8d8eccSSepherosa Ziehau { 33066c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 33076c8d8eccSSepherosa Ziehau 33086c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 33096c8d8eccSSepherosa Ziehau ifmr->ifm_status = IFM_AVALID; 33106c8d8eccSSepherosa Ziehau ifmr->ifm_active = IFM_ETHER; 33116c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_STS) & 33126c8d8eccSSepherosa Ziehau BGE_MACSTAT_TBI_PCS_SYNCHED) { 33136c8d8eccSSepherosa Ziehau ifmr->ifm_status |= IFM_ACTIVE; 33146c8d8eccSSepherosa Ziehau } else { 33156c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_NONE; 33166c8d8eccSSepherosa Ziehau return; 33176c8d8eccSSepherosa Ziehau } 33186c8d8eccSSepherosa Ziehau 33196c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_1000_SX; 33206c8d8eccSSepherosa Ziehau if (CSR_READ_4(sc, BGE_MAC_MODE) & BGE_MACMODE_HALF_DUPLEX) 33216c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_HDX; 33226c8d8eccSSepherosa Ziehau else 33236c8d8eccSSepherosa Ziehau ifmr->ifm_active |= IFM_FDX; 33246c8d8eccSSepherosa Ziehau } else { 33256c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 33266c8d8eccSSepherosa Ziehau 33276c8d8eccSSepherosa Ziehau mii_pollstat(mii); 33286c8d8eccSSepherosa Ziehau ifmr->ifm_active = mii->mii_media_active; 33296c8d8eccSSepherosa Ziehau ifmr->ifm_status = mii->mii_media_status; 33306c8d8eccSSepherosa Ziehau } 33316c8d8eccSSepherosa Ziehau } 33326c8d8eccSSepherosa Ziehau 33336c8d8eccSSepherosa Ziehau static int 33346c8d8eccSSepherosa Ziehau bnx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) 33356c8d8eccSSepherosa Ziehau { 33366c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 33376c8d8eccSSepherosa Ziehau struct ifreq *ifr = (struct ifreq *)data; 33386c8d8eccSSepherosa Ziehau int mask, error = 0; 33396c8d8eccSSepherosa Ziehau 3340329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 33416c8d8eccSSepherosa Ziehau 33426c8d8eccSSepherosa Ziehau switch (command) { 33436c8d8eccSSepherosa Ziehau case SIOCSIFMTU: 33446c8d8eccSSepherosa Ziehau if ((!BNX_IS_JUMBO_CAPABLE(sc) && ifr->ifr_mtu > ETHERMTU) || 33456c8d8eccSSepherosa Ziehau (BNX_IS_JUMBO_CAPABLE(sc) && 33466c8d8eccSSepherosa Ziehau ifr->ifr_mtu > BNX_JUMBO_MTU)) { 33476c8d8eccSSepherosa Ziehau error = EINVAL; 33486c8d8eccSSepherosa Ziehau } else if (ifp->if_mtu != ifr->ifr_mtu) { 33496c8d8eccSSepherosa Ziehau ifp->if_mtu = ifr->ifr_mtu; 33506c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 33516c8d8eccSSepherosa Ziehau bnx_init(sc); 33526c8d8eccSSepherosa Ziehau } 33536c8d8eccSSepherosa Ziehau break; 33546c8d8eccSSepherosa Ziehau case SIOCSIFFLAGS: 33556c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 33566c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) { 33576c8d8eccSSepherosa Ziehau mask = ifp->if_flags ^ sc->bnx_if_flags; 33586c8d8eccSSepherosa Ziehau 33596c8d8eccSSepherosa Ziehau /* 33606c8d8eccSSepherosa Ziehau * If only the state of the PROMISC flag 33616c8d8eccSSepherosa Ziehau * changed, then just use the 'set promisc 33626c8d8eccSSepherosa Ziehau * mode' command instead of reinitializing 33636c8d8eccSSepherosa Ziehau * the entire NIC. Doing a full re-init 33646c8d8eccSSepherosa Ziehau * means reloading the firmware and waiting 33656c8d8eccSSepherosa Ziehau * for it to start up, which may take a 33666c8d8eccSSepherosa Ziehau * second or two. Similarly for ALLMULTI. 33676c8d8eccSSepherosa Ziehau */ 33686c8d8eccSSepherosa Ziehau if (mask & IFF_PROMISC) 33696c8d8eccSSepherosa Ziehau bnx_setpromisc(sc); 33706c8d8eccSSepherosa Ziehau if (mask & IFF_ALLMULTI) 33716c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 33726c8d8eccSSepherosa Ziehau } else { 33736c8d8eccSSepherosa Ziehau bnx_init(sc); 33746c8d8eccSSepherosa Ziehau } 33756c8d8eccSSepherosa Ziehau } else if (ifp->if_flags & IFF_RUNNING) { 33766c8d8eccSSepherosa Ziehau bnx_stop(sc); 33776c8d8eccSSepherosa Ziehau } 33786c8d8eccSSepherosa Ziehau sc->bnx_if_flags = ifp->if_flags; 33796c8d8eccSSepherosa Ziehau break; 33806c8d8eccSSepherosa Ziehau case SIOCADDMULTI: 33816c8d8eccSSepherosa Ziehau case SIOCDELMULTI: 33826c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_RUNNING) 33836c8d8eccSSepherosa Ziehau bnx_setmulti(sc); 33846c8d8eccSSepherosa Ziehau break; 33856c8d8eccSSepherosa Ziehau case SIOCSIFMEDIA: 33866c8d8eccSSepherosa Ziehau case SIOCGIFMEDIA: 33876c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_TBI) { 33886c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 33896c8d8eccSSepherosa Ziehau &sc->bnx_ifmedia, command); 33906c8d8eccSSepherosa Ziehau } else { 33916c8d8eccSSepherosa Ziehau struct mii_data *mii; 33926c8d8eccSSepherosa Ziehau 33936c8d8eccSSepherosa Ziehau mii = device_get_softc(sc->bnx_miibus); 33946c8d8eccSSepherosa Ziehau error = ifmedia_ioctl(ifp, ifr, 33956c8d8eccSSepherosa Ziehau &mii->mii_media, command); 33966c8d8eccSSepherosa Ziehau } 33976c8d8eccSSepherosa Ziehau break; 33986c8d8eccSSepherosa Ziehau case SIOCSIFCAP: 33996c8d8eccSSepherosa Ziehau mask = ifr->ifr_reqcap ^ ifp->if_capenable; 34006c8d8eccSSepherosa Ziehau if (mask & IFCAP_HWCSUM) { 34016c8d8eccSSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_HWCSUM); 340266deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TXCSUM) 340366deb1c1SSepherosa Ziehau ifp->if_hwassist |= BNX_CSUM_FEATURES; 34046c8d8eccSSepherosa Ziehau else 340566deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~BNX_CSUM_FEATURES; 340666deb1c1SSepherosa Ziehau } 340766deb1c1SSepherosa Ziehau if (mask & IFCAP_TSO) { 340866deb1c1SSepherosa Ziehau ifp->if_capenable ^= (mask & IFCAP_TSO); 340966deb1c1SSepherosa Ziehau if (ifp->if_capenable & IFCAP_TSO) 341066deb1c1SSepherosa Ziehau ifp->if_hwassist |= CSUM_TSO; 341166deb1c1SSepherosa Ziehau else 341266deb1c1SSepherosa Ziehau ifp->if_hwassist &= ~CSUM_TSO; 34136c8d8eccSSepherosa Ziehau } 34146c8d8eccSSepherosa Ziehau break; 34156c8d8eccSSepherosa Ziehau default: 34166c8d8eccSSepherosa Ziehau error = ether_ioctl(ifp, command, data); 34176c8d8eccSSepherosa Ziehau break; 34186c8d8eccSSepherosa Ziehau } 34196c8d8eccSSepherosa Ziehau return error; 34206c8d8eccSSepherosa Ziehau } 34216c8d8eccSSepherosa Ziehau 34226c8d8eccSSepherosa Ziehau static void 34233397dea6SSepherosa Ziehau bnx_watchdog(struct ifaltq_subque *ifsq) 34246c8d8eccSSepherosa Ziehau { 34253397dea6SSepherosa Ziehau struct ifnet *ifp = ifsq_get_ifp(ifsq); 34266c8d8eccSSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 34273397dea6SSepherosa Ziehau int i; 34283397dea6SSepherosa Ziehau 34293397dea6SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 34306c8d8eccSSepherosa Ziehau 34316c8d8eccSSepherosa Ziehau if_printf(ifp, "watchdog timeout -- resetting\n"); 34326c8d8eccSSepherosa Ziehau 34336c8d8eccSSepherosa Ziehau bnx_init(sc); 34346c8d8eccSSepherosa Ziehau 3435d40991efSSepherosa Ziehau IFNET_STAT_INC(ifp, oerrors, 1); 34366c8d8eccSSepherosa Ziehau 34373397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 34383397dea6SSepherosa Ziehau ifsq_devstart_sched(sc->bnx_tx_ring[i].bnx_ifsq); 34396c8d8eccSSepherosa Ziehau } 34406c8d8eccSSepherosa Ziehau 34416c8d8eccSSepherosa Ziehau /* 34426c8d8eccSSepherosa Ziehau * Stop the adapter and free any mbufs allocated to the 34436c8d8eccSSepherosa Ziehau * RX and TX lists. 34446c8d8eccSSepherosa Ziehau */ 34456c8d8eccSSepherosa Ziehau static void 34466c8d8eccSSepherosa Ziehau bnx_stop(struct bnx_softc *sc) 34476c8d8eccSSepherosa Ziehau { 34486c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 344933a04907SSepherosa Ziehau int i; 34506c8d8eccSSepherosa Ziehau 3451329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 34526c8d8eccSSepherosa Ziehau 34537dbaa833SSepherosa Ziehau callout_stop(&sc->bnx_tick_timer); 34546c8d8eccSSepherosa Ziehau 34556c8d8eccSSepherosa Ziehau /* 34566c8d8eccSSepherosa Ziehau * Disable all of the receiver blocks 34576c8d8eccSSepherosa Ziehau */ 34586c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); 34596c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE); 34606c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); 34616c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDBDI_MODE, BGE_RBDIMODE_ENABLE); 34626c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); 34636c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RBDC_MODE, BGE_RBDCMODE_ENABLE); 34646c8d8eccSSepherosa Ziehau 34656c8d8eccSSepherosa Ziehau /* 34666c8d8eccSSepherosa Ziehau * Disable all of the transmit blocks 34676c8d8eccSSepherosa Ziehau */ 34686c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); 34696c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE); 34706c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE); 34716c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_RDMA_MODE, BGE_RDMAMODE_ENABLE); 34726c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SDC_MODE, BGE_SDCMODE_ENABLE); 34736c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); 34746c8d8eccSSepherosa Ziehau 34756c8d8eccSSepherosa Ziehau /* 34766c8d8eccSSepherosa Ziehau * Shut down all of the memory managers and related 34776c8d8eccSSepherosa Ziehau * state machines. 34786c8d8eccSSepherosa Ziehau */ 34796c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE); 34806c8d8eccSSepherosa Ziehau bnx_stop_block(sc, BGE_WDMA_MODE, BGE_WDMAMODE_ENABLE); 34816c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); 34826c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); 34836c8d8eccSSepherosa Ziehau 34846c8d8eccSSepherosa Ziehau /* Disable host interrupts. */ 34856c8d8eccSSepherosa Ziehau bnx_disable_intr(sc); 34866c8d8eccSSepherosa Ziehau 34876c8d8eccSSepherosa Ziehau /* 34886c8d8eccSSepherosa Ziehau * Tell firmware we're shutting down. 34896c8d8eccSSepherosa Ziehau */ 34906c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP); 34916c8d8eccSSepherosa Ziehau 34926c8d8eccSSepherosa Ziehau /* Free the RX lists. */ 3493beedf5beSSepherosa Ziehau bnx_free_rx_ring_std(&sc->bnx_rx_std_ring); 34946c8d8eccSSepherosa Ziehau 34956c8d8eccSSepherosa Ziehau /* Free jumbo RX list. */ 34966c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 34976c8d8eccSSepherosa Ziehau bnx_free_rx_ring_jumbo(sc); 34986c8d8eccSSepherosa Ziehau 34996c8d8eccSSepherosa Ziehau /* Free TX buffers. */ 35004fa38985SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 35014fa38985SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 35026c8d8eccSSepherosa Ziehau 35034fa38985SSepherosa Ziehau txr->bnx_saved_status_tag = 0; 35044fa38985SSepherosa Ziehau bnx_free_tx_ring(txr); 35054fa38985SSepherosa Ziehau } 35064fa38985SSepherosa Ziehau 35074fa38985SSepherosa Ziehau /* Clear saved status tag */ 35084fa38985SSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 35094fa38985SSepherosa Ziehau sc->bnx_rx_ret_ring[i].bnx_saved_status_tag = 0; 35104fa38985SSepherosa Ziehau 35116c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 35126c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 35136c8d8eccSSepherosa Ziehau 35149ed293e0SSepherosa Ziehau ifp->if_flags &= ~IFF_RUNNING; 35153397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 35163397dea6SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 35173397dea6SSepherosa Ziehau 35183397dea6SSepherosa Ziehau ifsq_clr_oactive(txr->bnx_ifsq); 35193397dea6SSepherosa Ziehau ifsq_watchdog_stop(&txr->bnx_tx_watchdog); 35203397dea6SSepherosa Ziehau } 35216c8d8eccSSepherosa Ziehau } 35226c8d8eccSSepherosa Ziehau 35236c8d8eccSSepherosa Ziehau /* 35246c8d8eccSSepherosa Ziehau * Stop all chip I/O so that the kernel's probe routines don't 35256c8d8eccSSepherosa Ziehau * get confused by errant DMAs when rebooting. 35266c8d8eccSSepherosa Ziehau */ 35276c8d8eccSSepherosa Ziehau static void 35286c8d8eccSSepherosa Ziehau bnx_shutdown(device_t dev) 35296c8d8eccSSepherosa Ziehau { 35306c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 35316c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 35326c8d8eccSSepherosa Ziehau 3533329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 35346c8d8eccSSepherosa Ziehau bnx_stop(sc); 35356c8d8eccSSepherosa Ziehau bnx_reset(sc); 3536329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 35376c8d8eccSSepherosa Ziehau } 35386c8d8eccSSepherosa Ziehau 35396c8d8eccSSepherosa Ziehau static int 35406c8d8eccSSepherosa Ziehau bnx_suspend(device_t dev) 35416c8d8eccSSepherosa Ziehau { 35426c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 35436c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 35446c8d8eccSSepherosa Ziehau 3545329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 35466c8d8eccSSepherosa Ziehau bnx_stop(sc); 3547329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 35486c8d8eccSSepherosa Ziehau 35496c8d8eccSSepherosa Ziehau return 0; 35506c8d8eccSSepherosa Ziehau } 35516c8d8eccSSepherosa Ziehau 35526c8d8eccSSepherosa Ziehau static int 35536c8d8eccSSepherosa Ziehau bnx_resume(device_t dev) 35546c8d8eccSSepherosa Ziehau { 35556c8d8eccSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 35566c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 35576c8d8eccSSepherosa Ziehau 3558329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 35596c8d8eccSSepherosa Ziehau 35606c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_UP) { 35613397dea6SSepherosa Ziehau int i; 35626c8d8eccSSepherosa Ziehau 35633397dea6SSepherosa Ziehau bnx_init(sc); 35643397dea6SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 35653397dea6SSepherosa Ziehau ifsq_devstart_sched(sc->bnx_tx_ring[i].bnx_ifsq); 35666c8d8eccSSepherosa Ziehau } 35676c8d8eccSSepherosa Ziehau 3568329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 35696c8d8eccSSepherosa Ziehau 35706c8d8eccSSepherosa Ziehau return 0; 35716c8d8eccSSepherosa Ziehau } 35726c8d8eccSSepherosa Ziehau 35736c8d8eccSSepherosa Ziehau static void 35746c8d8eccSSepherosa Ziehau bnx_setpromisc(struct bnx_softc *sc) 35756c8d8eccSSepherosa Ziehau { 35766c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 35776c8d8eccSSepherosa Ziehau 35786c8d8eccSSepherosa Ziehau if (ifp->if_flags & IFF_PROMISC) 35796c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 35806c8d8eccSSepherosa Ziehau else 35816c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC); 35826c8d8eccSSepherosa Ziehau } 35836c8d8eccSSepherosa Ziehau 35846c8d8eccSSepherosa Ziehau static void 35856c8d8eccSSepherosa Ziehau bnx_dma_free(struct bnx_softc *sc) 35866c8d8eccSSepherosa Ziehau { 3587beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 35886c8d8eccSSepherosa Ziehau int i; 35896c8d8eccSSepherosa Ziehau 3590beedf5beSSepherosa Ziehau /* Destroy RX return rings */ 3591beedf5beSSepherosa Ziehau if (sc->bnx_rx_ret_ring != NULL) { 3592beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) 3593beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(&sc->bnx_rx_ret_ring[i]); 3594beedf5beSSepherosa Ziehau kfree(sc->bnx_rx_ret_ring, M_DEVBUF); 3595beedf5beSSepherosa Ziehau } 3596beedf5beSSepherosa Ziehau 35976c8d8eccSSepherosa Ziehau /* Destroy RX mbuf DMA stuffs. */ 3598beedf5beSSepherosa Ziehau if (std->bnx_rx_mtag != NULL) { 35996c8d8eccSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; i++) { 3600beedf5beSSepherosa Ziehau KKASSERT(std->bnx_rx_std_buf[i].bnx_rx_mbuf == NULL); 3601beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3602beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[i].bnx_rx_dmamap); 36036c8d8eccSSepherosa Ziehau } 3604beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 36056c8d8eccSSepherosa Ziehau } 36066c8d8eccSSepherosa Ziehau 3607beedf5beSSepherosa Ziehau /* Destroy standard RX ring */ 3608beedf5beSSepherosa Ziehau bnx_dma_block_free(std->bnx_rx_std_ring_tag, 3609beedf5beSSepherosa Ziehau std->bnx_rx_std_ring_map, std->bnx_rx_std_ring); 3610beedf5beSSepherosa Ziehau 361133a04907SSepherosa Ziehau /* Destroy TX rings */ 361233a04907SSepherosa Ziehau if (sc->bnx_tx_ring != NULL) { 361333a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 361433a04907SSepherosa Ziehau bnx_destroy_tx_ring(&sc->bnx_tx_ring[i]); 361533a04907SSepherosa Ziehau kfree(sc->bnx_tx_ring, M_DEVBUF); 36166c8d8eccSSepherosa Ziehau } 36176c8d8eccSSepherosa Ziehau 36186c8d8eccSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) 36196c8d8eccSSepherosa Ziehau bnx_free_jumbo_mem(sc); 36206c8d8eccSSepherosa Ziehau 36210a806e3aSSepherosa Ziehau /* Destroy status blocks */ 36220a806e3aSSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 36230a806e3aSSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 36240a806e3aSSepherosa Ziehau 36250a806e3aSSepherosa Ziehau bnx_dma_block_free(intr->bnx_status_tag, 36260a806e3aSSepherosa Ziehau intr->bnx_status_map, intr->bnx_status_block); 36270a806e3aSSepherosa Ziehau } 36286c8d8eccSSepherosa Ziehau 36296c8d8eccSSepherosa Ziehau /* Destroy the parent tag */ 36306c8d8eccSSepherosa Ziehau if (sc->bnx_cdata.bnx_parent_tag != NULL) 36316c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(sc->bnx_cdata.bnx_parent_tag); 36326c8d8eccSSepherosa Ziehau } 36336c8d8eccSSepherosa Ziehau 36346c8d8eccSSepherosa Ziehau static int 3635beedf5beSSepherosa Ziehau bnx_dma_alloc(device_t dev) 36366c8d8eccSSepherosa Ziehau { 3637beedf5beSSepherosa Ziehau struct bnx_softc *sc = device_get_softc(dev); 3638beedf5beSSepherosa Ziehau struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring; 3639ac2936fdSSepherosa Ziehau int i, error, mbx; 36406c8d8eccSSepherosa Ziehau 36416c8d8eccSSepherosa Ziehau /* 36426c8d8eccSSepherosa Ziehau * Allocate the parent bus DMA tag appropriate for PCI. 36436c8d8eccSSepherosa Ziehau * 36446c8d8eccSSepherosa Ziehau * All of the NetExtreme/NetLink controllers have 4GB boundary 36456c8d8eccSSepherosa Ziehau * DMA bug. 36466c8d8eccSSepherosa Ziehau * Whenever an address crosses a multiple of the 4GB boundary 36476c8d8eccSSepherosa Ziehau * (including 4GB, 8Gb, 12Gb, etc.) and makes the transition 36486c8d8eccSSepherosa Ziehau * from 0xX_FFFF_FFFF to 0x(X+1)_0000_0000 an internal DMA 36496c8d8eccSSepherosa Ziehau * state machine will lockup and cause the device to hang. 36506c8d8eccSSepherosa Ziehau */ 36516c8d8eccSSepherosa Ziehau error = bus_dma_tag_create(NULL, 1, BGE_DMA_BOUNDARY_4G, 3652beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 3653beedf5beSSepherosa Ziehau BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 36546c8d8eccSSepherosa Ziehau 0, &sc->bnx_cdata.bnx_parent_tag); 36556c8d8eccSSepherosa Ziehau if (error) { 3656beedf5beSSepherosa Ziehau device_printf(dev, "could not create parent DMA tag\n"); 36576c8d8eccSSepherosa Ziehau return error; 36586c8d8eccSSepherosa Ziehau } 36596c8d8eccSSepherosa Ziehau 36606c8d8eccSSepherosa Ziehau /* 36610a806e3aSSepherosa Ziehau * Create DMA stuffs for status blocks. 36626c8d8eccSSepherosa Ziehau */ 36630a806e3aSSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 36640a806e3aSSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 36650a806e3aSSepherosa Ziehau 36666c8d8eccSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STATUS_BLK_SZ, 36670a806e3aSSepherosa Ziehau &intr->bnx_status_tag, &intr->bnx_status_map, 36680a806e3aSSepherosa Ziehau (void *)&intr->bnx_status_block, 36690a806e3aSSepherosa Ziehau &intr->bnx_status_block_paddr); 36706c8d8eccSSepherosa Ziehau if (error) { 36710a806e3aSSepherosa Ziehau device_printf(dev, 36720a806e3aSSepherosa Ziehau "could not create %dth status block\n", i); 36736c8d8eccSSepherosa Ziehau return error; 36746c8d8eccSSepherosa Ziehau } 36750a806e3aSSepherosa Ziehau } 36766c8d8eccSSepherosa Ziehau 3677beedf5beSSepherosa Ziehau /* 3678beedf5beSSepherosa Ziehau * Create DMA tag and maps for RX mbufs. 3679beedf5beSSepherosa Ziehau */ 3680beedf5beSSepherosa Ziehau std->bnx_sc = sc; 3681329f9016SSepherosa Ziehau lwkt_serialize_init(&std->bnx_rx_std_serialize); 3682beedf5beSSepherosa Ziehau error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0, 3683beedf5beSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 3684beedf5beSSepherosa Ziehau NULL, NULL, MCLBYTES, 1, MCLBYTES, 3685beedf5beSSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK, &std->bnx_rx_mtag); 3686beedf5beSSepherosa Ziehau if (error) { 3687beedf5beSSepherosa Ziehau device_printf(dev, "could not create RX mbuf DMA tag\n"); 3688beedf5beSSepherosa Ziehau return error; 3689beedf5beSSepherosa Ziehau } 3690beedf5beSSepherosa Ziehau 3691beedf5beSSepherosa Ziehau for (i = 0; i < BGE_STD_RX_RING_CNT; ++i) { 3692beedf5beSSepherosa Ziehau error = bus_dmamap_create(std->bnx_rx_mtag, BUS_DMA_WAITOK, 3693beedf5beSSepherosa Ziehau &std->bnx_rx_std_buf[i].bnx_rx_dmamap); 3694beedf5beSSepherosa Ziehau if (error) { 3695beedf5beSSepherosa Ziehau int j; 3696beedf5beSSepherosa Ziehau 3697beedf5beSSepherosa Ziehau for (j = 0; j < i; ++j) { 3698beedf5beSSepherosa Ziehau bus_dmamap_destroy(std->bnx_rx_mtag, 3699beedf5beSSepherosa Ziehau std->bnx_rx_std_buf[j].bnx_rx_dmamap); 3700beedf5beSSepherosa Ziehau } 3701beedf5beSSepherosa Ziehau bus_dma_tag_destroy(std->bnx_rx_mtag); 3702beedf5beSSepherosa Ziehau std->bnx_rx_mtag = NULL; 3703beedf5beSSepherosa Ziehau 3704beedf5beSSepherosa Ziehau device_printf(dev, 3705beedf5beSSepherosa Ziehau "could not create %dth RX mbuf DMA map\n", i); 3706beedf5beSSepherosa Ziehau return error; 3707beedf5beSSepherosa Ziehau } 3708beedf5beSSepherosa Ziehau } 3709beedf5beSSepherosa Ziehau 3710beedf5beSSepherosa Ziehau /* 3711beedf5beSSepherosa Ziehau * Create DMA stuffs for standard RX ring. 3712beedf5beSSepherosa Ziehau */ 3713beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(sc, BGE_STD_RX_RING_SZ, 3714beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_tag, 3715beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_map, 3716beedf5beSSepherosa Ziehau (void *)&std->bnx_rx_std_ring, 3717beedf5beSSepherosa Ziehau &std->bnx_rx_std_ring_paddr); 3718beedf5beSSepherosa Ziehau if (error) { 3719beedf5beSSepherosa Ziehau device_printf(dev, "could not create std RX ring\n"); 3720beedf5beSSepherosa Ziehau return error; 3721beedf5beSSepherosa Ziehau } 3722beedf5beSSepherosa Ziehau 3723beedf5beSSepherosa Ziehau /* 3724beedf5beSSepherosa Ziehau * Create RX return rings 3725beedf5beSSepherosa Ziehau */ 3726ac2936fdSSepherosa Ziehau mbx = BGE_MBX_RX_CONS0_LO; 3727beedf5beSSepherosa Ziehau sc->bnx_rx_ret_ring = kmalloc_cachealign( 3728beedf5beSSepherosa Ziehau sizeof(struct bnx_rx_ret_ring) * sc->bnx_rx_retcnt, M_DEVBUF, 3729beedf5beSSepherosa Ziehau M_WAITOK | M_ZERO); 3730beedf5beSSepherosa Ziehau for (i = 0; i < sc->bnx_rx_retcnt; ++i) { 3731beedf5beSSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i]; 37320a806e3aSSepherosa Ziehau struct bnx_intr_data *intr; 3733beedf5beSSepherosa Ziehau 3734beedf5beSSepherosa Ziehau ret->bnx_sc = sc; 3735beedf5beSSepherosa Ziehau ret->bnx_std = std; 3736ac2936fdSSepherosa Ziehau ret->bnx_rx_mbx = mbx; 3737841cdf08SSepherosa Ziehau ret->bnx_rx_cntmax = (BGE_STD_RX_RING_CNT / 4) / 3738841cdf08SSepherosa Ziehau sc->bnx_rx_retcnt; 3739841cdf08SSepherosa Ziehau ret->bnx_rx_mask = 1 << i; 37403a16b7b8SSepherosa Ziehau 37410a806e3aSSepherosa Ziehau if (sc->bnx_rx_retcnt == 1) { 37420a806e3aSSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 37430a806e3aSSepherosa Ziehau } else { 37440a806e3aSSepherosa Ziehau KKASSERT(i + 1 < sc->bnx_intr_cnt); 37450a806e3aSSepherosa Ziehau intr = &sc->bnx_intr_data[i + 1]; 37460a806e3aSSepherosa Ziehau } 37470a806e3aSSepherosa Ziehau 37483a16b7b8SSepherosa Ziehau ret->bnx_rx_considx = 37490a806e3aSSepherosa Ziehau &intr->bnx_status_block->bge_idx[0].bge_rx_prod_idx; 37504fa38985SSepherosa Ziehau ret->bnx_hw_status_tag = 37510a806e3aSSepherosa Ziehau &intr->bnx_status_block->bge_status_tag; 37523a16b7b8SSepherosa Ziehau 3753beedf5beSSepherosa Ziehau error = bnx_create_rx_ret_ring(ret); 3754beedf5beSSepherosa Ziehau if (error) { 3755beedf5beSSepherosa Ziehau device_printf(dev, 3756beedf5beSSepherosa Ziehau "could not create %dth RX ret ring\n", i); 3757beedf5beSSepherosa Ziehau return error; 3758beedf5beSSepherosa Ziehau } 3759ac2936fdSSepherosa Ziehau mbx += 8; 3760beedf5beSSepherosa Ziehau } 3761beedf5beSSepherosa Ziehau 3762beedf5beSSepherosa Ziehau /* 3763beedf5beSSepherosa Ziehau * Create TX rings 3764beedf5beSSepherosa Ziehau */ 376533a04907SSepherosa Ziehau sc->bnx_tx_ring = kmalloc_cachealign( 376633a04907SSepherosa Ziehau sizeof(struct bnx_tx_ring) * sc->bnx_tx_ringcnt, M_DEVBUF, 376733a04907SSepherosa Ziehau M_WAITOK | M_ZERO); 376833a04907SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 376933a04907SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i]; 37700a806e3aSSepherosa Ziehau struct bnx_intr_data *intr; 377133a04907SSepherosa Ziehau 377233a04907SSepherosa Ziehau txr->bnx_sc = sc; 37731c9d03f6SSepherosa Ziehau txr->bnx_tx_mbx = bnx_tx_mailbox[i]; 37748bd43d5dSSepherosa Ziehau 37750a806e3aSSepherosa Ziehau if (sc->bnx_tx_ringcnt == 1) { 37760a806e3aSSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 37770a806e3aSSepherosa Ziehau } else { 37780a806e3aSSepherosa Ziehau KKASSERT(i + 1 < sc->bnx_intr_cnt); 37790a806e3aSSepherosa Ziehau intr = &sc->bnx_intr_data[i + 1]; 37800a806e3aSSepherosa Ziehau } 37810a806e3aSSepherosa Ziehau 37823a16b7b8SSepherosa Ziehau txr->bnx_tx_considx = 37830a806e3aSSepherosa Ziehau &intr->bnx_status_block->bge_idx[0].bge_tx_cons_idx; 37843a16b7b8SSepherosa Ziehau 378533a04907SSepherosa Ziehau error = bnx_create_tx_ring(txr); 378633a04907SSepherosa Ziehau if (error) { 3787beedf5beSSepherosa Ziehau device_printf(dev, 3788beedf5beSSepherosa Ziehau "could not create %dth TX ring\n", i); 3789beedf5beSSepherosa Ziehau return error; 3790beedf5beSSepherosa Ziehau } 3791beedf5beSSepherosa Ziehau } 3792beedf5beSSepherosa Ziehau 3793beedf5beSSepherosa Ziehau /* 3794beedf5beSSepherosa Ziehau * Create jumbo buffer pool. 3795beedf5beSSepherosa Ziehau */ 3796beedf5beSSepherosa Ziehau if (BNX_IS_JUMBO_CAPABLE(sc)) { 3797beedf5beSSepherosa Ziehau error = bnx_alloc_jumbo_mem(sc); 3798beedf5beSSepherosa Ziehau if (error) { 3799beedf5beSSepherosa Ziehau device_printf(dev, 3800beedf5beSSepherosa Ziehau "could not create jumbo buffer pool\n"); 380133a04907SSepherosa Ziehau return error; 380233a04907SSepherosa Ziehau } 380333a04907SSepherosa Ziehau } 380433a04907SSepherosa Ziehau 38056c8d8eccSSepherosa Ziehau return 0; 38066c8d8eccSSepherosa Ziehau } 38076c8d8eccSSepherosa Ziehau 38086c8d8eccSSepherosa Ziehau static int 38096c8d8eccSSepherosa Ziehau bnx_dma_block_alloc(struct bnx_softc *sc, bus_size_t size, bus_dma_tag_t *tag, 38106c8d8eccSSepherosa Ziehau bus_dmamap_t *map, void **addr, bus_addr_t *paddr) 38116c8d8eccSSepherosa Ziehau { 38126c8d8eccSSepherosa Ziehau bus_dmamem_t dmem; 38136c8d8eccSSepherosa Ziehau int error; 38146c8d8eccSSepherosa Ziehau 38156c8d8eccSSepherosa Ziehau error = bus_dmamem_coherent(sc->bnx_cdata.bnx_parent_tag, PAGE_SIZE, 0, 38166c8d8eccSSepherosa Ziehau BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 38176c8d8eccSSepherosa Ziehau size, BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmem); 38186c8d8eccSSepherosa Ziehau if (error) 38196c8d8eccSSepherosa Ziehau return error; 38206c8d8eccSSepherosa Ziehau 38216c8d8eccSSepherosa Ziehau *tag = dmem.dmem_tag; 38226c8d8eccSSepherosa Ziehau *map = dmem.dmem_map; 38236c8d8eccSSepherosa Ziehau *addr = dmem.dmem_addr; 38246c8d8eccSSepherosa Ziehau *paddr = dmem.dmem_busaddr; 38256c8d8eccSSepherosa Ziehau 38266c8d8eccSSepherosa Ziehau return 0; 38276c8d8eccSSepherosa Ziehau } 38286c8d8eccSSepherosa Ziehau 38296c8d8eccSSepherosa Ziehau static void 38306c8d8eccSSepherosa Ziehau bnx_dma_block_free(bus_dma_tag_t tag, bus_dmamap_t map, void *addr) 38316c8d8eccSSepherosa Ziehau { 38326c8d8eccSSepherosa Ziehau if (tag != NULL) { 38336c8d8eccSSepherosa Ziehau bus_dmamap_unload(tag, map); 38346c8d8eccSSepherosa Ziehau bus_dmamem_free(tag, addr, map); 38356c8d8eccSSepherosa Ziehau bus_dma_tag_destroy(tag); 38366c8d8eccSSepherosa Ziehau } 38376c8d8eccSSepherosa Ziehau } 38386c8d8eccSSepherosa Ziehau 38396c8d8eccSSepherosa Ziehau static void 38406c8d8eccSSepherosa Ziehau bnx_tbi_link_upd(struct bnx_softc *sc, uint32_t status) 38416c8d8eccSSepherosa Ziehau { 38426c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38436c8d8eccSSepherosa Ziehau 38446c8d8eccSSepherosa Ziehau #define PCS_ENCODE_ERR (BGE_MACSTAT_PORT_DECODE_ERROR|BGE_MACSTAT_MI_COMPLETE) 38456c8d8eccSSepherosa Ziehau 38466c8d8eccSSepherosa Ziehau /* 38476c8d8eccSSepherosa Ziehau * Sometimes PCS encoding errors are detected in 38486c8d8eccSSepherosa Ziehau * TBI mode (on fiber NICs), and for some reason 38496c8d8eccSSepherosa Ziehau * the chip will signal them as link changes. 38506c8d8eccSSepherosa Ziehau * If we get a link change event, but the 'PCS 38516c8d8eccSSepherosa Ziehau * encoding error' bit in the MAC status register 38526c8d8eccSSepherosa Ziehau * is set, don't bother doing a link check. 38536c8d8eccSSepherosa Ziehau * This avoids spurious "gigabit link up" messages 38546c8d8eccSSepherosa Ziehau * that sometimes appear on fiber NICs during 38556c8d8eccSSepherosa Ziehau * periods of heavy traffic. 38566c8d8eccSSepherosa Ziehau */ 38576c8d8eccSSepherosa Ziehau if (status & BGE_MACSTAT_TBI_PCS_SYNCHED) { 38586c8d8eccSSepherosa Ziehau if (!sc->bnx_link) { 38596c8d8eccSSepherosa Ziehau sc->bnx_link++; 38606c8d8eccSSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5704) { 38616c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, BGE_MAC_MODE, 38626c8d8eccSSepherosa Ziehau BGE_MACMODE_TBI_SEND_CFGS); 38636c8d8eccSSepherosa Ziehau } 38646c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, 0xFFFFFFFF); 38656c8d8eccSSepherosa Ziehau 38666c8d8eccSSepherosa Ziehau if (bootverbose) 38676c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 38686c8d8eccSSepherosa Ziehau 38696c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_UP; 38706c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 38716c8d8eccSSepherosa Ziehau } 38726c8d8eccSSepherosa Ziehau } else if ((status & PCS_ENCODE_ERR) != PCS_ENCODE_ERR) { 38736c8d8eccSSepherosa Ziehau if (sc->bnx_link) { 38746c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 38756c8d8eccSSepherosa Ziehau 38766c8d8eccSSepherosa Ziehau if (bootverbose) 38776c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 38786c8d8eccSSepherosa Ziehau 38796c8d8eccSSepherosa Ziehau ifp->if_link_state = LINK_STATE_DOWN; 38806c8d8eccSSepherosa Ziehau if_link_state_change(ifp); 38816c8d8eccSSepherosa Ziehau } 38826c8d8eccSSepherosa Ziehau } 38836c8d8eccSSepherosa Ziehau 38846c8d8eccSSepherosa Ziehau #undef PCS_ENCODE_ERR 38856c8d8eccSSepherosa Ziehau 38866c8d8eccSSepherosa Ziehau /* Clear the attention. */ 38876c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 38886c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 38896c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 38906c8d8eccSSepherosa Ziehau } 38916c8d8eccSSepherosa Ziehau 38926c8d8eccSSepherosa Ziehau static void 38936c8d8eccSSepherosa Ziehau bnx_copper_link_upd(struct bnx_softc *sc, uint32_t status __unused) 38946c8d8eccSSepherosa Ziehau { 38956c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 38966c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 38976c8d8eccSSepherosa Ziehau 38986c8d8eccSSepherosa Ziehau mii_pollstat(mii); 38996c8d8eccSSepherosa Ziehau bnx_miibus_statchg(sc->bnx_dev); 39006c8d8eccSSepherosa Ziehau 39016c8d8eccSSepherosa Ziehau if (bootverbose) { 39026c8d8eccSSepherosa Ziehau if (sc->bnx_link) 39036c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 39046c8d8eccSSepherosa Ziehau else 39056c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 39066c8d8eccSSepherosa Ziehau } 39076c8d8eccSSepherosa Ziehau 39086c8d8eccSSepherosa Ziehau /* Clear the attention. */ 39096c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 39106c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 39116c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 39126c8d8eccSSepherosa Ziehau } 39136c8d8eccSSepherosa Ziehau 39146c8d8eccSSepherosa Ziehau static void 39156c8d8eccSSepherosa Ziehau bnx_autopoll_link_upd(struct bnx_softc *sc, uint32_t status __unused) 39166c8d8eccSSepherosa Ziehau { 39176c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 39186c8d8eccSSepherosa Ziehau struct mii_data *mii = device_get_softc(sc->bnx_miibus); 39196c8d8eccSSepherosa Ziehau 39206c8d8eccSSepherosa Ziehau mii_pollstat(mii); 39216c8d8eccSSepherosa Ziehau 39226c8d8eccSSepherosa Ziehau if (!sc->bnx_link && 39236c8d8eccSSepherosa Ziehau (mii->mii_media_status & IFM_ACTIVE) && 39246c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 39256c8d8eccSSepherosa Ziehau sc->bnx_link++; 39266c8d8eccSSepherosa Ziehau if (bootverbose) 39276c8d8eccSSepherosa Ziehau if_printf(ifp, "link UP\n"); 39286c8d8eccSSepherosa Ziehau } else if (sc->bnx_link && 39296c8d8eccSSepherosa Ziehau (!(mii->mii_media_status & IFM_ACTIVE) || 39306c8d8eccSSepherosa Ziehau IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)) { 39316c8d8eccSSepherosa Ziehau sc->bnx_link = 0; 39326c8d8eccSSepherosa Ziehau if (bootverbose) 39336c8d8eccSSepherosa Ziehau if_printf(ifp, "link DOWN\n"); 39346c8d8eccSSepherosa Ziehau } 39356c8d8eccSSepherosa Ziehau 39366c8d8eccSSepherosa Ziehau /* Clear the attention. */ 39376c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | 39386c8d8eccSSepherosa Ziehau BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | 39396c8d8eccSSepherosa Ziehau BGE_MACSTAT_LINK_CHANGED); 39406c8d8eccSSepherosa Ziehau } 39416c8d8eccSSepherosa Ziehau 39426c8d8eccSSepherosa Ziehau static int 39436c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS) 39446c8d8eccSSepherosa Ziehau { 39456c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39466c8d8eccSSepherosa Ziehau 39476c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39486c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_ticks, 39496c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_MIN, BNX_RX_COAL_TICKS_MAX, 39506c8d8eccSSepherosa Ziehau BNX_RX_COAL_TICKS_CHG); 39516c8d8eccSSepherosa Ziehau } 39526c8d8eccSSepherosa Ziehau 39536c8d8eccSSepherosa Ziehau static int 39546c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS) 39556c8d8eccSSepherosa Ziehau { 39566c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39576c8d8eccSSepherosa Ziehau 39586c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39596c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_ticks, 39606c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_MIN, BNX_TX_COAL_TICKS_MAX, 39616c8d8eccSSepherosa Ziehau BNX_TX_COAL_TICKS_CHG); 39626c8d8eccSSepherosa Ziehau } 39636c8d8eccSSepherosa Ziehau 39646c8d8eccSSepherosa Ziehau static int 39656c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS) 39666c8d8eccSSepherosa Ziehau { 39676c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39686c8d8eccSSepherosa Ziehau 39696c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39706c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds, 39716c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 39726c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_CHG); 39736c8d8eccSSepherosa Ziehau } 39746c8d8eccSSepherosa Ziehau 39756c8d8eccSSepherosa Ziehau static int 39766c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS) 39776c8d8eccSSepherosa Ziehau { 39786c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39796c8d8eccSSepherosa Ziehau 39806c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39816c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds, 39826c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 39836c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_CHG); 39846c8d8eccSSepherosa Ziehau } 39856c8d8eccSSepherosa Ziehau 39866c8d8eccSSepherosa Ziehau static int 39876c8d8eccSSepherosa Ziehau bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS) 39886c8d8eccSSepherosa Ziehau { 39896c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 39906c8d8eccSSepherosa Ziehau 39916c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 39926c8d8eccSSepherosa Ziehau &sc->bnx_rx_coal_bds_int, 39936c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX, 39946c8d8eccSSepherosa Ziehau BNX_RX_COAL_BDS_INT_CHG); 39956c8d8eccSSepherosa Ziehau } 39966c8d8eccSSepherosa Ziehau 39976c8d8eccSSepherosa Ziehau static int 39986c8d8eccSSepherosa Ziehau bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS) 39996c8d8eccSSepherosa Ziehau { 40006c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 40016c8d8eccSSepherosa Ziehau 40026c8d8eccSSepherosa Ziehau return bnx_sysctl_coal_chg(oidp, arg1, arg2, req, 40036c8d8eccSSepherosa Ziehau &sc->bnx_tx_coal_bds_int, 40046c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX, 40056c8d8eccSSepherosa Ziehau BNX_TX_COAL_BDS_INT_CHG); 40066c8d8eccSSepherosa Ziehau } 40076c8d8eccSSepherosa Ziehau 40086c8d8eccSSepherosa Ziehau static int 40096c8d8eccSSepherosa Ziehau bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *coal, 40106c8d8eccSSepherosa Ziehau int coal_min, int coal_max, uint32_t coal_chg_mask) 40116c8d8eccSSepherosa Ziehau { 40126c8d8eccSSepherosa Ziehau struct bnx_softc *sc = arg1; 40136c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 40146c8d8eccSSepherosa Ziehau int error = 0, v; 40156c8d8eccSSepherosa Ziehau 4016329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 40176c8d8eccSSepherosa Ziehau 40186c8d8eccSSepherosa Ziehau v = *coal; 40196c8d8eccSSepherosa Ziehau error = sysctl_handle_int(oidp, &v, 0, req); 40206c8d8eccSSepherosa Ziehau if (!error && req->newptr != NULL) { 40216c8d8eccSSepherosa Ziehau if (v < coal_min || v > coal_max) { 40226c8d8eccSSepherosa Ziehau error = EINVAL; 40236c8d8eccSSepherosa Ziehau } else { 40246c8d8eccSSepherosa Ziehau *coal = v; 40256c8d8eccSSepherosa Ziehau sc->bnx_coal_chg |= coal_chg_mask; 4026f5014362SSepherosa Ziehau 4027f5014362SSepherosa Ziehau /* Commit changes */ 4028f5014362SSepherosa Ziehau bnx_coal_change(sc); 40296c8d8eccSSepherosa Ziehau } 40306c8d8eccSSepherosa Ziehau } 40316c8d8eccSSepherosa Ziehau 4032329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 40336c8d8eccSSepherosa Ziehau return error; 40346c8d8eccSSepherosa Ziehau } 40356c8d8eccSSepherosa Ziehau 40366c8d8eccSSepherosa Ziehau static void 40376c8d8eccSSepherosa Ziehau bnx_coal_change(struct bnx_softc *sc) 40386c8d8eccSSepherosa Ziehau { 40396c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 40406c8d8eccSSepherosa Ziehau 4041329f9016SSepherosa Ziehau ASSERT_IFNET_SERIALIZED_ALL(ifp); 40426c8d8eccSSepherosa Ziehau 40436c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_TICKS_CHG) { 40446c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, 40456c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 40466c8d8eccSSepherosa Ziehau DELAY(10); 4047e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_COAL_TICKS); 40486c8d8eccSSepherosa Ziehau 40496c8d8eccSSepherosa Ziehau if (bootverbose) { 40506c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_ticks -> %u\n", 40516c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_ticks); 40526c8d8eccSSepherosa Ziehau } 40536c8d8eccSSepherosa Ziehau } 40546c8d8eccSSepherosa Ziehau 40556c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_TICKS_CHG) { 40566c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, 40576c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 40586c8d8eccSSepherosa Ziehau DELAY(10); 4059e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_COAL_TICKS); 40606c8d8eccSSepherosa Ziehau 40616c8d8eccSSepherosa Ziehau if (bootverbose) { 40626c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_ticks -> %u\n", 40636c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_ticks); 40646c8d8eccSSepherosa Ziehau } 40656c8d8eccSSepherosa Ziehau } 40666c8d8eccSSepherosa Ziehau 40676c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_CHG) { 40686c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, 40696c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 40706c8d8eccSSepherosa Ziehau DELAY(10); 4071e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS); 40726c8d8eccSSepherosa Ziehau 40736c8d8eccSSepherosa Ziehau if (bootverbose) { 40746c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds -> %u\n", 40756c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds); 40766c8d8eccSSepherosa Ziehau } 40776c8d8eccSSepherosa Ziehau } 40786c8d8eccSSepherosa Ziehau 40796c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_CHG) { 40806c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, 40816c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 40826c8d8eccSSepherosa Ziehau DELAY(10); 4083e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS); 40846c8d8eccSSepherosa Ziehau 40856c8d8eccSSepherosa Ziehau if (bootverbose) { 4086cc98a7c2SSepherosa Ziehau if_printf(ifp, "tx_coal_bds -> %u\n", 40876c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds); 40886c8d8eccSSepherosa Ziehau } 40896c8d8eccSSepherosa Ziehau } 40906c8d8eccSSepherosa Ziehau 40916c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_INT_CHG) { 40926c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, 40936c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 40946c8d8eccSSepherosa Ziehau DELAY(10); 4095e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT); 40966c8d8eccSSepherosa Ziehau 40976c8d8eccSSepherosa Ziehau if (bootverbose) { 40986c8d8eccSSepherosa Ziehau if_printf(ifp, "rx_coal_bds_int -> %u\n", 40996c8d8eccSSepherosa Ziehau sc->bnx_rx_coal_bds_int); 41006c8d8eccSSepherosa Ziehau } 41016c8d8eccSSepherosa Ziehau } 41026c8d8eccSSepherosa Ziehau 41036c8d8eccSSepherosa Ziehau if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_INT_CHG) { 41046c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, 41056c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 41066c8d8eccSSepherosa Ziehau DELAY(10); 4107e594b5c4SSepherosa Ziehau CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT); 41086c8d8eccSSepherosa Ziehau 41096c8d8eccSSepherosa Ziehau if (bootverbose) { 41106c8d8eccSSepherosa Ziehau if_printf(ifp, "tx_coal_bds_int -> %u\n", 41116c8d8eccSSepherosa Ziehau sc->bnx_tx_coal_bds_int); 41126c8d8eccSSepherosa Ziehau } 41136c8d8eccSSepherosa Ziehau } 41146c8d8eccSSepherosa Ziehau 41156c8d8eccSSepherosa Ziehau sc->bnx_coal_chg = 0; 41166c8d8eccSSepherosa Ziehau } 41176c8d8eccSSepherosa Ziehau 41186c8d8eccSSepherosa Ziehau static void 4119f33ac8a4SSepherosa Ziehau bnx_check_intr(void *xintr) 4120df9ccc98SSepherosa Ziehau { 4121f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = xintr; 4122f33ac8a4SSepherosa Ziehau struct bnx_rx_ret_ring *ret; 4123f33ac8a4SSepherosa Ziehau struct bnx_tx_ring *txr; 4124f33ac8a4SSepherosa Ziehau struct ifnet *ifp; 4125df9ccc98SSepherosa Ziehau 4126f33ac8a4SSepherosa Ziehau lwkt_serialize_enter(intr->bnx_intr_serialize); 4127df9ccc98SSepherosa Ziehau 4128f33ac8a4SSepherosa Ziehau KKASSERT(mycpuid == intr->bnx_intr_cpuid); 4129df9ccc98SSepherosa Ziehau 4130f33ac8a4SSepherosa Ziehau ifp = &intr->bnx_sc->arpcom.ac_if; 413139a8d43aSSepherosa Ziehau if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) { 4132f33ac8a4SSepherosa Ziehau lwkt_serialize_exit(intr->bnx_intr_serialize); 4133df9ccc98SSepherosa Ziehau return; 4134df9ccc98SSepherosa Ziehau } 4135df9ccc98SSepherosa Ziehau 4136f33ac8a4SSepherosa Ziehau txr = intr->bnx_txr; 4137f33ac8a4SSepherosa Ziehau ret = intr->bnx_ret; 4138f33ac8a4SSepherosa Ziehau 41393a16b7b8SSepherosa Ziehau if (*ret->bnx_rx_considx != ret->bnx_rx_saved_considx || 41403a16b7b8SSepherosa Ziehau *txr->bnx_tx_considx != txr->bnx_tx_saved_considx) { 4141f33ac8a4SSepherosa Ziehau if (intr->bnx_rx_check_considx == ret->bnx_rx_saved_considx && 4142f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx == txr->bnx_tx_saved_considx) { 4143f33ac8a4SSepherosa Ziehau if (!intr->bnx_intr_maylose) { 4144f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = TRUE; 4145df9ccc98SSepherosa Ziehau goto done; 4146df9ccc98SSepherosa Ziehau } 4147df9ccc98SSepherosa Ziehau if (bootverbose) 4148df9ccc98SSepherosa Ziehau if_printf(ifp, "lost interrupt\n"); 4149f33ac8a4SSepherosa Ziehau intr->bnx_intr_func(intr->bnx_intr_arg); 4150df9ccc98SSepherosa Ziehau } 4151df9ccc98SSepherosa Ziehau } 4152f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 4153f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = ret->bnx_rx_saved_considx; 4154f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = txr->bnx_tx_saved_considx; 4155df9ccc98SSepherosa Ziehau 4156df9ccc98SSepherosa Ziehau done: 4157f33ac8a4SSepherosa Ziehau callout_reset(&intr->bnx_intr_timer, BNX_INTR_CKINTVL, 4158f33ac8a4SSepherosa Ziehau intr->bnx_intr_check, intr); 4159f33ac8a4SSepherosa Ziehau lwkt_serialize_exit(intr->bnx_intr_serialize); 4160df9ccc98SSepherosa Ziehau } 4161df9ccc98SSepherosa Ziehau 4162df9ccc98SSepherosa Ziehau static void 41636c8d8eccSSepherosa Ziehau bnx_enable_intr(struct bnx_softc *sc) 41646c8d8eccSSepherosa Ziehau { 41656c8d8eccSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 41664fa38985SSepherosa Ziehau struct bnx_intr_data *intr; 4167f33ac8a4SSepherosa Ziehau int i; 41686c8d8eccSSepherosa Ziehau 4169f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4170f33ac8a4SSepherosa Ziehau lwkt_serialize_handler_enable( 4171f33ac8a4SSepherosa Ziehau sc->bnx_intr_data[i].bnx_intr_serialize); 4172f33ac8a4SSepherosa Ziehau } 41736c8d8eccSSepherosa Ziehau 41746c8d8eccSSepherosa Ziehau /* 41756c8d8eccSSepherosa Ziehau * Enable interrupt. 41766c8d8eccSSepherosa Ziehau */ 41774fa38985SSepherosa Ziehau intr = &sc->bnx_intr_data[0]; /* XXX */ 41784fa38985SSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, (*intr->bnx_saved_status_tag) << 24); 41796c8d8eccSSepherosa Ziehau /* XXX Linux driver */ 4180*0b4feeacSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, (*intr->bnx_saved_status_tag) << 24); 41816c8d8eccSSepherosa Ziehau 41826c8d8eccSSepherosa Ziehau /* 41836c8d8eccSSepherosa Ziehau * Unmask the interrupt when we stop polling. 41846c8d8eccSSepherosa Ziehau */ 41856c8d8eccSSepherosa Ziehau PCI_CLRBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 41866c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 41876c8d8eccSSepherosa Ziehau 41886c8d8eccSSepherosa Ziehau /* 41896c8d8eccSSepherosa Ziehau * Trigger another interrupt, since above writing 41906c8d8eccSSepherosa Ziehau * to interrupt mailbox0 may acknowledge pending 41916c8d8eccSSepherosa Ziehau * interrupt. 41926c8d8eccSSepherosa Ziehau */ 41936c8d8eccSSepherosa Ziehau BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET); 4194df9ccc98SSepherosa Ziehau 4195df9ccc98SSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_STATUSTAG_BUG) { 4196df9ccc98SSepherosa Ziehau if (bootverbose) 4197df9ccc98SSepherosa Ziehau if_printf(ifp, "status tag bug workaround\n"); 4198df9ccc98SSepherosa Ziehau 4199f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 42004fa38985SSepherosa Ziehau intr = &sc->bnx_intr_data[i]; 4201f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 4202f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = 0; 4203f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = 0; 4204f33ac8a4SSepherosa Ziehau callout_reset_bycpu(&intr->bnx_intr_timer, 4205f33ac8a4SSepherosa Ziehau BNX_INTR_CKINTVL, intr->bnx_intr_check, intr, 4206f33ac8a4SSepherosa Ziehau intr->bnx_intr_cpuid); 4207f33ac8a4SSepherosa Ziehau } 4208df9ccc98SSepherosa Ziehau } 42096c8d8eccSSepherosa Ziehau } 42106c8d8eccSSepherosa Ziehau 42116c8d8eccSSepherosa Ziehau static void 42126c8d8eccSSepherosa Ziehau bnx_disable_intr(struct bnx_softc *sc) 42136c8d8eccSSepherosa Ziehau { 4214f33ac8a4SSepherosa Ziehau int i; 4215f33ac8a4SSepherosa Ziehau 4216f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4217f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4218f33ac8a4SSepherosa Ziehau 4219f33ac8a4SSepherosa Ziehau callout_stop(&intr->bnx_intr_timer); 4220f33ac8a4SSepherosa Ziehau intr->bnx_intr_maylose = FALSE; 4221f33ac8a4SSepherosa Ziehau intr->bnx_rx_check_considx = 0; 4222f33ac8a4SSepherosa Ziehau intr->bnx_tx_check_considx = 0; 4223f33ac8a4SSepherosa Ziehau } 42246c8d8eccSSepherosa Ziehau 42256c8d8eccSSepherosa Ziehau /* 42266c8d8eccSSepherosa Ziehau * Mask the interrupt when we start polling. 42276c8d8eccSSepherosa Ziehau */ 42286c8d8eccSSepherosa Ziehau PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, 42296c8d8eccSSepherosa Ziehau BGE_PCIMISCCTL_MASK_PCI_INTR, 4); 42306c8d8eccSSepherosa Ziehau 42316c8d8eccSSepherosa Ziehau /* 42326c8d8eccSSepherosa Ziehau * Acknowledge possible asserted interrupt. 42336c8d8eccSSepherosa Ziehau */ 42346c8d8eccSSepherosa Ziehau bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1); 42356c8d8eccSSepherosa Ziehau 4236f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4237f33ac8a4SSepherosa Ziehau lwkt_serialize_handler_disable( 4238f33ac8a4SSepherosa Ziehau sc->bnx_intr_data[i].bnx_intr_serialize); 4239f33ac8a4SSepherosa Ziehau } 42406c8d8eccSSepherosa Ziehau } 42416c8d8eccSSepherosa Ziehau 42426c8d8eccSSepherosa Ziehau static int 42436c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem(struct bnx_softc *sc, uint8_t ether_addr[]) 42446c8d8eccSSepherosa Ziehau { 42456c8d8eccSSepherosa Ziehau uint32_t mac_addr; 42466c8d8eccSSepherosa Ziehau int ret = 1; 42476c8d8eccSSepherosa Ziehau 42486c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c14); 42496c8d8eccSSepherosa Ziehau if ((mac_addr >> 16) == 0x484b) { 42506c8d8eccSSepherosa Ziehau ether_addr[0] = (uint8_t)(mac_addr >> 8); 42516c8d8eccSSepherosa Ziehau ether_addr[1] = (uint8_t)mac_addr; 42526c8d8eccSSepherosa Ziehau mac_addr = bnx_readmem_ind(sc, 0x0c18); 42536c8d8eccSSepherosa Ziehau ether_addr[2] = (uint8_t)(mac_addr >> 24); 42546c8d8eccSSepherosa Ziehau ether_addr[3] = (uint8_t)(mac_addr >> 16); 42556c8d8eccSSepherosa Ziehau ether_addr[4] = (uint8_t)(mac_addr >> 8); 42566c8d8eccSSepherosa Ziehau ether_addr[5] = (uint8_t)mac_addr; 42576c8d8eccSSepherosa Ziehau ret = 0; 42586c8d8eccSSepherosa Ziehau } 42596c8d8eccSSepherosa Ziehau return ret; 42606c8d8eccSSepherosa Ziehau } 42616c8d8eccSSepherosa Ziehau 42626c8d8eccSSepherosa Ziehau static int 42636c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram(struct bnx_softc *sc, uint8_t ether_addr[]) 42646c8d8eccSSepherosa Ziehau { 42656c8d8eccSSepherosa Ziehau int mac_offset = BGE_EE_MAC_OFFSET; 42666c8d8eccSSepherosa Ziehau 426780969639SSepherosa Ziehau if (BNX_IS_5717_PLUS(sc)) { 426880969639SSepherosa Ziehau int f; 426980969639SSepherosa Ziehau 427080969639SSepherosa Ziehau f = pci_get_function(sc->bnx_dev); 427180969639SSepherosa Ziehau if (f & 1) 427280969639SSepherosa Ziehau mac_offset = BGE_EE_MAC_OFFSET_5717; 427380969639SSepherosa Ziehau if (f > 1) 427480969639SSepherosa Ziehau mac_offset += BGE_EE_MAC_OFFSET_5717_OFF; 427580969639SSepherosa Ziehau } 42766c8d8eccSSepherosa Ziehau 42776c8d8eccSSepherosa Ziehau return bnx_read_nvram(sc, ether_addr, mac_offset + 2, ETHER_ADDR_LEN); 42786c8d8eccSSepherosa Ziehau } 42796c8d8eccSSepherosa Ziehau 42806c8d8eccSSepherosa Ziehau static int 42816c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom(struct bnx_softc *sc, uint8_t ether_addr[]) 42826c8d8eccSSepherosa Ziehau { 42836c8d8eccSSepherosa Ziehau if (sc->bnx_flags & BNX_FLAG_NO_EEPROM) 42846c8d8eccSSepherosa Ziehau return 1; 42856c8d8eccSSepherosa Ziehau 42866c8d8eccSSepherosa Ziehau return bnx_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2, 42876c8d8eccSSepherosa Ziehau ETHER_ADDR_LEN); 42886c8d8eccSSepherosa Ziehau } 42896c8d8eccSSepherosa Ziehau 42906c8d8eccSSepherosa Ziehau static int 42916c8d8eccSSepherosa Ziehau bnx_get_eaddr(struct bnx_softc *sc, uint8_t eaddr[]) 42926c8d8eccSSepherosa Ziehau { 42936c8d8eccSSepherosa Ziehau static const bnx_eaddr_fcn_t bnx_eaddr_funcs[] = { 42946c8d8eccSSepherosa Ziehau /* NOTE: Order is critical */ 42956c8d8eccSSepherosa Ziehau bnx_get_eaddr_mem, 42966c8d8eccSSepherosa Ziehau bnx_get_eaddr_nvram, 42976c8d8eccSSepherosa Ziehau bnx_get_eaddr_eeprom, 42986c8d8eccSSepherosa Ziehau NULL 42996c8d8eccSSepherosa Ziehau }; 43006c8d8eccSSepherosa Ziehau const bnx_eaddr_fcn_t *func; 43016c8d8eccSSepherosa Ziehau 43026c8d8eccSSepherosa Ziehau for (func = bnx_eaddr_funcs; *func != NULL; ++func) { 43036c8d8eccSSepherosa Ziehau if ((*func)(sc, eaddr) == 0) 43046c8d8eccSSepherosa Ziehau break; 43056c8d8eccSSepherosa Ziehau } 43066c8d8eccSSepherosa Ziehau return (*func == NULL ? ENXIO : 0); 43076c8d8eccSSepherosa Ziehau } 43086c8d8eccSSepherosa Ziehau 43096c8d8eccSSepherosa Ziehau /* 43106c8d8eccSSepherosa Ziehau * NOTE: 'm' is not freed upon failure 43116c8d8eccSSepherosa Ziehau */ 43126c8d8eccSSepherosa Ziehau struct mbuf * 43136c8d8eccSSepherosa Ziehau bnx_defrag_shortdma(struct mbuf *m) 43146c8d8eccSSepherosa Ziehau { 43156c8d8eccSSepherosa Ziehau struct mbuf *n; 43166c8d8eccSSepherosa Ziehau int found; 43176c8d8eccSSepherosa Ziehau 43186c8d8eccSSepherosa Ziehau /* 43196c8d8eccSSepherosa Ziehau * If device receive two back-to-back send BDs with less than 43206c8d8eccSSepherosa Ziehau * or equal to 8 total bytes then the device may hang. The two 43216c8d8eccSSepherosa Ziehau * back-to-back send BDs must in the same frame for this failure 43226c8d8eccSSepherosa Ziehau * to occur. Scan mbuf chains and see whether two back-to-back 43236c8d8eccSSepherosa Ziehau * send BDs are there. If this is the case, allocate new mbuf 43246c8d8eccSSepherosa Ziehau * and copy the frame to workaround the silicon bug. 43256c8d8eccSSepherosa Ziehau */ 43266c8d8eccSSepherosa Ziehau for (n = m, found = 0; n != NULL; n = n->m_next) { 43276c8d8eccSSepherosa Ziehau if (n->m_len < 8) { 43286c8d8eccSSepherosa Ziehau found++; 43296c8d8eccSSepherosa Ziehau if (found > 1) 43306c8d8eccSSepherosa Ziehau break; 43316c8d8eccSSepherosa Ziehau continue; 43326c8d8eccSSepherosa Ziehau } 43336c8d8eccSSepherosa Ziehau found = 0; 43346c8d8eccSSepherosa Ziehau } 43356c8d8eccSSepherosa Ziehau 43366c8d8eccSSepherosa Ziehau if (found > 1) 43376c8d8eccSSepherosa Ziehau n = m_defrag(m, MB_DONTWAIT); 43386c8d8eccSSepherosa Ziehau else 43396c8d8eccSSepherosa Ziehau n = m; 43406c8d8eccSSepherosa Ziehau return n; 43416c8d8eccSSepherosa Ziehau } 43426c8d8eccSSepherosa Ziehau 43436c8d8eccSSepherosa Ziehau static void 43446c8d8eccSSepherosa Ziehau bnx_stop_block(struct bnx_softc *sc, bus_size_t reg, uint32_t bit) 43456c8d8eccSSepherosa Ziehau { 43466c8d8eccSSepherosa Ziehau int i; 43476c8d8eccSSepherosa Ziehau 43486c8d8eccSSepherosa Ziehau BNX_CLRBIT(sc, reg, bit); 43496c8d8eccSSepherosa Ziehau for (i = 0; i < BNX_TIMEOUT; i++) { 43506c8d8eccSSepherosa Ziehau if ((CSR_READ_4(sc, reg) & bit) == 0) 43516c8d8eccSSepherosa Ziehau return; 43526c8d8eccSSepherosa Ziehau DELAY(100); 43536c8d8eccSSepherosa Ziehau } 43546c8d8eccSSepherosa Ziehau } 43556c8d8eccSSepherosa Ziehau 43566c8d8eccSSepherosa Ziehau static void 43576c8d8eccSSepherosa Ziehau bnx_link_poll(struct bnx_softc *sc) 43586c8d8eccSSepherosa Ziehau { 43596c8d8eccSSepherosa Ziehau uint32_t status; 43606c8d8eccSSepherosa Ziehau 43616c8d8eccSSepherosa Ziehau status = CSR_READ_4(sc, BGE_MAC_STS); 43626c8d8eccSSepherosa Ziehau if ((status & sc->bnx_link_chg) || sc->bnx_link_evt) { 43636c8d8eccSSepherosa Ziehau sc->bnx_link_evt = 0; 43646c8d8eccSSepherosa Ziehau sc->bnx_link_upd(sc, status); 43656c8d8eccSSepherosa Ziehau } 43666c8d8eccSSepherosa Ziehau } 43676c8d8eccSSepherosa Ziehau 43686c8d8eccSSepherosa Ziehau static void 43696c8d8eccSSepherosa Ziehau bnx_enable_msi(struct bnx_softc *sc) 43706c8d8eccSSepherosa Ziehau { 43716c8d8eccSSepherosa Ziehau uint32_t msi_mode; 43726c8d8eccSSepherosa Ziehau 43736c8d8eccSSepherosa Ziehau msi_mode = CSR_READ_4(sc, BGE_MSI_MODE); 43746c8d8eccSSepherosa Ziehau msi_mode |= BGE_MSIMODE_ENABLE; 43756c8d8eccSSepherosa Ziehau /* 43766c8d8eccSSepherosa Ziehau * NOTE: 4377*0b4feeacSSepherosa Ziehau * 5718-PG105-R says that "one shot" mode does not work 4378*0b4feeacSSepherosa Ziehau * if MSI is used, however, it obviously works. 43796c8d8eccSSepherosa Ziehau */ 43806c8d8eccSSepherosa Ziehau msi_mode &= ~BGE_MSIMODE_ONESHOT_DISABLE; 43816c8d8eccSSepherosa Ziehau CSR_WRITE_4(sc, BGE_MSI_MODE, msi_mode); 43826c8d8eccSSepherosa Ziehau } 43836c8d8eccSSepherosa Ziehau 43846c8d8eccSSepherosa Ziehau static uint32_t 43856c8d8eccSSepherosa Ziehau bnx_dma_swap_options(struct bnx_softc *sc) 43866c8d8eccSSepherosa Ziehau { 43876c8d8eccSSepherosa Ziehau uint32_t dma_options; 43886c8d8eccSSepherosa Ziehau 43896c8d8eccSSepherosa Ziehau dma_options = BGE_MODECTL_WORDSWAP_NONFRAME | 43906c8d8eccSSepherosa Ziehau BGE_MODECTL_BYTESWAP_DATA | BGE_MODECTL_WORDSWAP_DATA; 43916c8d8eccSSepherosa Ziehau #if BYTE_ORDER == BIG_ENDIAN 43926c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_NONFRAME; 43936c8d8eccSSepherosa Ziehau #endif 4394b96cbbb6SSepherosa Ziehau if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 || 4395b96cbbb6SSepherosa Ziehau sc->bnx_asicrev == BGE_ASICREV_BCM5762) { 43966c8d8eccSSepherosa Ziehau dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA | 43976c8d8eccSSepherosa Ziehau BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE | 43986c8d8eccSSepherosa Ziehau BGE_MODECTL_HTX2B_ENABLE; 43996c8d8eccSSepherosa Ziehau } 44006c8d8eccSSepherosa Ziehau return dma_options; 44016c8d8eccSSepherosa Ziehau } 440266deb1c1SSepherosa Ziehau 440366deb1c1SSepherosa Ziehau static int 440433a04907SSepherosa Ziehau bnx_setup_tso(struct bnx_tx_ring *txr, struct mbuf **mp, 440566deb1c1SSepherosa Ziehau uint16_t *mss0, uint16_t *flags0) 440666deb1c1SSepherosa Ziehau { 440766deb1c1SSepherosa Ziehau struct mbuf *m; 440866deb1c1SSepherosa Ziehau struct ip *ip; 440966deb1c1SSepherosa Ziehau struct tcphdr *th; 441066deb1c1SSepherosa Ziehau int thoff, iphlen, hoff, hlen; 441166deb1c1SSepherosa Ziehau uint16_t flags, mss; 441266deb1c1SSepherosa Ziehau 4413f7a2269aSSepherosa Ziehau m = *mp; 4414f7a2269aSSepherosa Ziehau KASSERT(M_WRITABLE(m), ("TSO mbuf not writable")); 4415f7a2269aSSepherosa Ziehau 4416f7a2269aSSepherosa Ziehau hoff = m->m_pkthdr.csum_lhlen; 4417f7a2269aSSepherosa Ziehau iphlen = m->m_pkthdr.csum_iphlen; 4418f7a2269aSSepherosa Ziehau thoff = m->m_pkthdr.csum_thlen; 4419f7a2269aSSepherosa Ziehau 4420f7a2269aSSepherosa Ziehau KASSERT(hoff > 0, ("invalid ether header len")); 4421f7a2269aSSepherosa Ziehau KASSERT(iphlen > 0, ("invalid ip header len")); 4422f7a2269aSSepherosa Ziehau KASSERT(thoff > 0, ("invalid tcp header len")); 4423f7a2269aSSepherosa Ziehau 4424f7a2269aSSepherosa Ziehau if (__predict_false(m->m_len < hoff + iphlen + thoff)) { 4425f7a2269aSSepherosa Ziehau m = m_pullup(m, hoff + iphlen + thoff); 4426f7a2269aSSepherosa Ziehau if (m == NULL) { 4427f7a2269aSSepherosa Ziehau *mp = NULL; 4428f7a2269aSSepherosa Ziehau return ENOBUFS; 4429f7a2269aSSepherosa Ziehau } 4430f7a2269aSSepherosa Ziehau *mp = m; 4431f7a2269aSSepherosa Ziehau } 4432f7a2269aSSepherosa Ziehau ip = mtodoff(m, struct ip *, hoff); 4433f7a2269aSSepherosa Ziehau th = mtodoff(m, struct tcphdr *, hoff + iphlen); 4434f7a2269aSSepherosa Ziehau 4435f0336d39SSepherosa Ziehau mss = m->m_pkthdr.tso_segsz; 443666deb1c1SSepherosa Ziehau flags = BGE_TXBDFLAG_CPU_PRE_DMA | BGE_TXBDFLAG_CPU_POST_DMA; 443766deb1c1SSepherosa Ziehau 443866deb1c1SSepherosa Ziehau ip->ip_len = htons(mss + iphlen + thoff); 443966deb1c1SSepherosa Ziehau th->th_sum = 0; 444066deb1c1SSepherosa Ziehau 444166deb1c1SSepherosa Ziehau hlen = (iphlen + thoff) >> 2; 444266deb1c1SSepherosa Ziehau mss |= ((hlen & 0x3) << 14); 444366deb1c1SSepherosa Ziehau flags |= ((hlen & 0xf8) << 7) | ((hlen & 0x4) << 2); 444466deb1c1SSepherosa Ziehau 444566deb1c1SSepherosa Ziehau *mss0 = mss; 444666deb1c1SSepherosa Ziehau *flags0 = flags; 444766deb1c1SSepherosa Ziehau 444866deb1c1SSepherosa Ziehau return 0; 444966deb1c1SSepherosa Ziehau } 445033a04907SSepherosa Ziehau 445133a04907SSepherosa Ziehau static int 445233a04907SSepherosa Ziehau bnx_create_tx_ring(struct bnx_tx_ring *txr) 445333a04907SSepherosa Ziehau { 445433a04907SSepherosa Ziehau bus_size_t txmaxsz, txmaxsegsz; 445533a04907SSepherosa Ziehau int i, error; 445633a04907SSepherosa Ziehau 4457329f9016SSepherosa Ziehau lwkt_serialize_init(&txr->bnx_tx_serialize); 4458329f9016SSepherosa Ziehau 445933a04907SSepherosa Ziehau /* 446033a04907SSepherosa Ziehau * Create DMA tag and maps for TX mbufs. 446133a04907SSepherosa Ziehau */ 446233a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_flags & BNX_FLAG_TSO) 446333a04907SSepherosa Ziehau txmaxsz = IP_MAXPACKET + sizeof(struct ether_vlan_header); 446433a04907SSepherosa Ziehau else 446533a04907SSepherosa Ziehau txmaxsz = BNX_JUMBO_FRAMELEN; 446633a04907SSepherosa Ziehau if (txr->bnx_sc->bnx_asicrev == BGE_ASICREV_BCM57766) 446733a04907SSepherosa Ziehau txmaxsegsz = MCLBYTES; 446833a04907SSepherosa Ziehau else 446933a04907SSepherosa Ziehau txmaxsegsz = PAGE_SIZE; 447033a04907SSepherosa Ziehau error = bus_dma_tag_create(txr->bnx_sc->bnx_cdata.bnx_parent_tag, 447133a04907SSepherosa Ziehau 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 447233a04907SSepherosa Ziehau txmaxsz, BNX_NSEG_NEW, txmaxsegsz, 447333a04907SSepherosa Ziehau BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 447433a04907SSepherosa Ziehau &txr->bnx_tx_mtag); 447533a04907SSepherosa Ziehau if (error) { 447633a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4477beedf5beSSepherosa Ziehau "could not create TX mbuf DMA tag\n"); 447833a04907SSepherosa Ziehau return error; 447933a04907SSepherosa Ziehau } 448033a04907SSepherosa Ziehau 448133a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 448233a04907SSepherosa Ziehau error = bus_dmamap_create(txr->bnx_tx_mtag, 448333a04907SSepherosa Ziehau BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, 4484fa4b1067SSepherosa Ziehau &txr->bnx_tx_buf[i].bnx_tx_dmamap); 448533a04907SSepherosa Ziehau if (error) { 448633a04907SSepherosa Ziehau int j; 448733a04907SSepherosa Ziehau 448833a04907SSepherosa Ziehau for (j = 0; j < i; ++j) { 448933a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4490fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[j].bnx_tx_dmamap); 449133a04907SSepherosa Ziehau } 449233a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 449333a04907SSepherosa Ziehau txr->bnx_tx_mtag = NULL; 449433a04907SSepherosa Ziehau 449533a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 4496beedf5beSSepherosa Ziehau "could not create TX mbuf DMA map\n"); 449733a04907SSepherosa Ziehau return error; 449833a04907SSepherosa Ziehau } 449933a04907SSepherosa Ziehau } 450033a04907SSepherosa Ziehau 450133a04907SSepherosa Ziehau /* 450233a04907SSepherosa Ziehau * Create DMA stuffs for TX ring. 450333a04907SSepherosa Ziehau */ 450433a04907SSepherosa Ziehau error = bnx_dma_block_alloc(txr->bnx_sc, BGE_TX_RING_SZ, 4505beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_tag, 4506beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_map, 4507beedf5beSSepherosa Ziehau (void *)&txr->bnx_tx_ring, 4508beedf5beSSepherosa Ziehau &txr->bnx_tx_ring_paddr); 450933a04907SSepherosa Ziehau if (error) { 451033a04907SSepherosa Ziehau device_printf(txr->bnx_sc->bnx_dev, 451133a04907SSepherosa Ziehau "could not create TX ring\n"); 451233a04907SSepherosa Ziehau return error; 451333a04907SSepherosa Ziehau } 451433a04907SSepherosa Ziehau 451579a64343SSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_SHORTDMA; 451633a04907SSepherosa Ziehau txr->bnx_tx_wreg = BNX_TX_WREG_NSEGS; 451733a04907SSepherosa Ziehau 451833a04907SSepherosa Ziehau return 0; 451933a04907SSepherosa Ziehau } 452033a04907SSepherosa Ziehau 452133a04907SSepherosa Ziehau static void 452233a04907SSepherosa Ziehau bnx_destroy_tx_ring(struct bnx_tx_ring *txr) 452333a04907SSepherosa Ziehau { 452433a04907SSepherosa Ziehau /* Destroy TX mbuf DMA stuffs. */ 452533a04907SSepherosa Ziehau if (txr->bnx_tx_mtag != NULL) { 452633a04907SSepherosa Ziehau int i; 452733a04907SSepherosa Ziehau 452833a04907SSepherosa Ziehau for (i = 0; i < BGE_TX_RING_CNT; i++) { 4529fa4b1067SSepherosa Ziehau KKASSERT(txr->bnx_tx_buf[i].bnx_tx_mbuf == NULL); 453033a04907SSepherosa Ziehau bus_dmamap_destroy(txr->bnx_tx_mtag, 4531fa4b1067SSepherosa Ziehau txr->bnx_tx_buf[i].bnx_tx_dmamap); 453233a04907SSepherosa Ziehau } 453333a04907SSepherosa Ziehau bus_dma_tag_destroy(txr->bnx_tx_mtag); 453433a04907SSepherosa Ziehau } 453533a04907SSepherosa Ziehau 453633a04907SSepherosa Ziehau /* Destroy TX ring */ 453733a04907SSepherosa Ziehau bnx_dma_block_free(txr->bnx_tx_ring_tag, 453833a04907SSepherosa Ziehau txr->bnx_tx_ring_map, txr->bnx_tx_ring); 453933a04907SSepherosa Ziehau } 4540aad4de2bSSepherosa Ziehau 4541aad4de2bSSepherosa Ziehau static int 4542aad4de2bSSepherosa Ziehau bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS) 4543aad4de2bSSepherosa Ziehau { 4544aad4de2bSSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4545aad4de2bSSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4546aad4de2bSSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4547aad4de2bSSepherosa Ziehau int error, defrag, i; 4548aad4de2bSSepherosa Ziehau 4549aad4de2bSSepherosa Ziehau if (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) 4550aad4de2bSSepherosa Ziehau defrag = 1; 4551aad4de2bSSepherosa Ziehau else 4552aad4de2bSSepherosa Ziehau defrag = 0; 4553aad4de2bSSepherosa Ziehau 4554aad4de2bSSepherosa Ziehau error = sysctl_handle_int(oidp, &defrag, 0, req); 4555aad4de2bSSepherosa Ziehau if (error || req->newptr == NULL) 4556aad4de2bSSepherosa Ziehau return error; 4557aad4de2bSSepherosa Ziehau 4558329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 4559aad4de2bSSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) { 4560aad4de2bSSepherosa Ziehau txr = &sc->bnx_tx_ring[i]; 4561aad4de2bSSepherosa Ziehau if (defrag) 4562aad4de2bSSepherosa Ziehau txr->bnx_tx_flags |= BNX_TX_FLAG_FORCE_DEFRAG; 4563aad4de2bSSepherosa Ziehau else 4564aad4de2bSSepherosa Ziehau txr->bnx_tx_flags &= ~BNX_TX_FLAG_FORCE_DEFRAG; 4565aad4de2bSSepherosa Ziehau } 4566329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 4567aad4de2bSSepherosa Ziehau 4568aad4de2bSSepherosa Ziehau return 0; 4569aad4de2bSSepherosa Ziehau } 4570472c99c8SSepherosa Ziehau 4571472c99c8SSepherosa Ziehau static int 4572472c99c8SSepherosa Ziehau bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS) 4573472c99c8SSepherosa Ziehau { 4574472c99c8SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4575472c99c8SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4576472c99c8SSepherosa Ziehau struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; 4577472c99c8SSepherosa Ziehau int error, tx_wreg, i; 4578472c99c8SSepherosa Ziehau 4579472c99c8SSepherosa Ziehau tx_wreg = txr->bnx_tx_wreg; 4580472c99c8SSepherosa Ziehau error = sysctl_handle_int(oidp, &tx_wreg, 0, req); 4581472c99c8SSepherosa Ziehau if (error || req->newptr == NULL) 4582472c99c8SSepherosa Ziehau return error; 4583472c99c8SSepherosa Ziehau 4584329f9016SSepherosa Ziehau ifnet_serialize_all(ifp); 4585472c99c8SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 4586472c99c8SSepherosa Ziehau sc->bnx_tx_ring[i].bnx_tx_wreg = tx_wreg; 4587329f9016SSepherosa Ziehau ifnet_deserialize_all(ifp); 4588472c99c8SSepherosa Ziehau 4589472c99c8SSepherosa Ziehau return 0; 4590472c99c8SSepherosa Ziehau } 4591beedf5beSSepherosa Ziehau 4592beedf5beSSepherosa Ziehau static int 4593beedf5beSSepherosa Ziehau bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4594beedf5beSSepherosa Ziehau { 4595beedf5beSSepherosa Ziehau int error; 4596beedf5beSSepherosa Ziehau 4597329f9016SSepherosa Ziehau lwkt_serialize_init(&ret->bnx_rx_ret_serialize); 4598329f9016SSepherosa Ziehau 4599beedf5beSSepherosa Ziehau /* 4600beedf5beSSepherosa Ziehau * Create DMA stuffs for RX return ring. 4601beedf5beSSepherosa Ziehau */ 4602beedf5beSSepherosa Ziehau error = bnx_dma_block_alloc(ret->bnx_sc, 4603beedf5beSSepherosa Ziehau BGE_RX_RTN_RING_SZ(BNX_RETURN_RING_CNT), 4604beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_tag, 4605beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_map, 4606beedf5beSSepherosa Ziehau (void *)&ret->bnx_rx_ret_ring, 4607beedf5beSSepherosa Ziehau &ret->bnx_rx_ret_ring_paddr); 4608beedf5beSSepherosa Ziehau if (error) { 4609beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4610beedf5beSSepherosa Ziehau "could not create RX ret ring\n"); 4611beedf5beSSepherosa Ziehau return error; 4612beedf5beSSepherosa Ziehau } 4613beedf5beSSepherosa Ziehau 4614beedf5beSSepherosa Ziehau /* Shadow standard ring's RX mbuf DMA tag */ 4615beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = ret->bnx_std->bnx_rx_mtag; 4616beedf5beSSepherosa Ziehau 4617beedf5beSSepherosa Ziehau /* 4618beedf5beSSepherosa Ziehau * Create tmp DMA map for RX mbufs. 4619beedf5beSSepherosa Ziehau */ 4620beedf5beSSepherosa Ziehau error = bus_dmamap_create(ret->bnx_rx_mtag, BUS_DMA_WAITOK, 4621beedf5beSSepherosa Ziehau &ret->bnx_rx_tmpmap); 4622beedf5beSSepherosa Ziehau if (error) { 4623beedf5beSSepherosa Ziehau device_printf(ret->bnx_sc->bnx_dev, 4624beedf5beSSepherosa Ziehau "could not create tmp RX mbuf DMA map\n"); 4625beedf5beSSepherosa Ziehau ret->bnx_rx_mtag = NULL; 4626beedf5beSSepherosa Ziehau return error; 4627beedf5beSSepherosa Ziehau } 4628beedf5beSSepherosa Ziehau return 0; 4629beedf5beSSepherosa Ziehau } 4630beedf5beSSepherosa Ziehau 4631beedf5beSSepherosa Ziehau static void 4632beedf5beSSepherosa Ziehau bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *ret) 4633beedf5beSSepherosa Ziehau { 4634beedf5beSSepherosa Ziehau /* Destroy tmp RX mbuf DMA map */ 4635beedf5beSSepherosa Ziehau if (ret->bnx_rx_mtag != NULL) 4636beedf5beSSepherosa Ziehau bus_dmamap_destroy(ret->bnx_rx_mtag, ret->bnx_rx_tmpmap); 4637beedf5beSSepherosa Ziehau 4638beedf5beSSepherosa Ziehau /* Destroy RX return ring */ 4639beedf5beSSepherosa Ziehau bnx_dma_block_free(ret->bnx_rx_ret_ring_tag, 4640beedf5beSSepherosa Ziehau ret->bnx_rx_ret_ring_map, ret->bnx_rx_ret_ring); 4641beedf5beSSepherosa Ziehau } 46420c7da01dSSepherosa Ziehau 46430c7da01dSSepherosa Ziehau static int 46440c7da01dSSepherosa Ziehau bnx_alloc_intr(struct bnx_softc *sc) 46450c7da01dSSepherosa Ziehau { 4646f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr; 46470c7da01dSSepherosa Ziehau u_int intr_flags; 46480c7da01dSSepherosa Ziehau 46490a806e3aSSepherosa Ziehau KKASSERT(sc->bnx_intr_cnt == 1); 46500c7da01dSSepherosa Ziehau 4651f33ac8a4SSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 4652f33ac8a4SSepherosa Ziehau intr->bnx_sc = sc; 4653f33ac8a4SSepherosa Ziehau intr->bnx_ret = &sc->bnx_rx_ret_ring[0]; 4654f33ac8a4SSepherosa Ziehau intr->bnx_txr = &sc->bnx_tx_ring[0]; 4655f33ac8a4SSepherosa Ziehau intr->bnx_intr_serialize = &sc->bnx_main_serialize; 4656f33ac8a4SSepherosa Ziehau callout_init_mp(&intr->bnx_intr_timer); 4657f33ac8a4SSepherosa Ziehau intr->bnx_intr_check = bnx_check_intr; 46584fa38985SSepherosa Ziehau intr->bnx_saved_status_tag = &intr->bnx_ret->bnx_saved_status_tag; 4659f33ac8a4SSepherosa Ziehau 4660f33ac8a4SSepherosa Ziehau sc->bnx_intr_type = pci_alloc_1intr(sc->bnx_dev, bnx_msi_enable, 4661f33ac8a4SSepherosa Ziehau &intr->bnx_intr_rid, &intr_flags); 4662f33ac8a4SSepherosa Ziehau 4663f33ac8a4SSepherosa Ziehau intr->bnx_intr_res = bus_alloc_resource_any(sc->bnx_dev, SYS_RES_IRQ, 4664f33ac8a4SSepherosa Ziehau &intr->bnx_intr_rid, intr_flags); 4665f33ac8a4SSepherosa Ziehau if (intr->bnx_intr_res == NULL) { 46660c7da01dSSepherosa Ziehau device_printf(sc->bnx_dev, "could not alloc interrupt\n"); 46670c7da01dSSepherosa Ziehau return ENXIO; 46680c7da01dSSepherosa Ziehau } 46690c7da01dSSepherosa Ziehau 4670f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) { 46710c7da01dSSepherosa Ziehau bnx_enable_msi(sc); 4672f33ac8a4SSepherosa Ziehau intr->bnx_intr_func = bnx_msi_oneshot; 4673f33ac8a4SSepherosa Ziehau if (bootverbose) 4674f33ac8a4SSepherosa Ziehau device_printf(sc->bnx_dev, "oneshot MSI\n"); 4675f33ac8a4SSepherosa Ziehau } else { 4676f33ac8a4SSepherosa Ziehau intr->bnx_intr_func = bnx_intr_legacy; 4677f33ac8a4SSepherosa Ziehau } 4678f33ac8a4SSepherosa Ziehau intr->bnx_intr_arg = sc; 4679f33ac8a4SSepherosa Ziehau intr->bnx_intr_cpuid = rman_get_cpuid(intr->bnx_intr_res); 4680f33ac8a4SSepherosa Ziehau 4681f33ac8a4SSepherosa Ziehau intr->bnx_txr->bnx_tx_cpuid = intr->bnx_intr_cpuid; 4682f33ac8a4SSepherosa Ziehau 46830c7da01dSSepherosa Ziehau return 0; 46840c7da01dSSepherosa Ziehau } 46850c7da01dSSepherosa Ziehau 46860c7da01dSSepherosa Ziehau static int 46870c7da01dSSepherosa Ziehau bnx_setup_intr(struct bnx_softc *sc) 46880c7da01dSSepherosa Ziehau { 4689f33ac8a4SSepherosa Ziehau int error, i; 46900c7da01dSSepherosa Ziehau 4691f33ac8a4SSepherosa Ziehau for (i = 0; i < sc->bnx_intr_cnt; ++i) { 4692f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4693f33ac8a4SSepherosa Ziehau 4694f33ac8a4SSepherosa Ziehau error = bus_setup_intr_descr(sc->bnx_dev, intr->bnx_intr_res, 4695f33ac8a4SSepherosa Ziehau INTR_MPSAFE, intr->bnx_intr_func, intr->bnx_intr_arg, 4696f33ac8a4SSepherosa Ziehau &intr->bnx_intr_hand, intr->bnx_intr_serialize, 4697f33ac8a4SSepherosa Ziehau intr->bnx_intr_desc); 46980c7da01dSSepherosa Ziehau if (error) { 4699f33ac8a4SSepherosa Ziehau device_printf(sc->bnx_dev, 4700f33ac8a4SSepherosa Ziehau "could not set up %dth intr\n", i); 4701f33ac8a4SSepherosa Ziehau bnx_teardown_intr(sc, i); 47020c7da01dSSepherosa Ziehau return error; 47030c7da01dSSepherosa Ziehau } 4704f33ac8a4SSepherosa Ziehau } 47050c7da01dSSepherosa Ziehau return 0; 47060c7da01dSSepherosa Ziehau } 47070c7da01dSSepherosa Ziehau 47080c7da01dSSepherosa Ziehau static void 4709f33ac8a4SSepherosa Ziehau bnx_teardown_intr(struct bnx_softc *sc, int cnt) 4710f33ac8a4SSepherosa Ziehau { 4711f33ac8a4SSepherosa Ziehau int i; 4712f33ac8a4SSepherosa Ziehau 4713f33ac8a4SSepherosa Ziehau for (i = 0; i < cnt; ++i) { 4714f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr = &sc->bnx_intr_data[i]; 4715f33ac8a4SSepherosa Ziehau 4716f33ac8a4SSepherosa Ziehau bus_teardown_intr(sc->bnx_dev, intr->bnx_intr_res, 4717f33ac8a4SSepherosa Ziehau intr->bnx_intr_hand); 4718f33ac8a4SSepherosa Ziehau } 4719f33ac8a4SSepherosa Ziehau } 4720f33ac8a4SSepherosa Ziehau 4721f33ac8a4SSepherosa Ziehau static void 47220c7da01dSSepherosa Ziehau bnx_free_intr(struct bnx_softc *sc) 47230c7da01dSSepherosa Ziehau { 4724f33ac8a4SSepherosa Ziehau struct bnx_intr_data *intr; 4725f33ac8a4SSepherosa Ziehau 4726f33ac8a4SSepherosa Ziehau KKASSERT(sc->bnx_intr_cnt <= 1); 4727f33ac8a4SSepherosa Ziehau intr = &sc->bnx_intr_data[0]; 4728f33ac8a4SSepherosa Ziehau 4729f33ac8a4SSepherosa Ziehau if (intr->bnx_intr_res != NULL) { 47300c7da01dSSepherosa Ziehau bus_release_resource(sc->bnx_dev, SYS_RES_IRQ, 4731f33ac8a4SSepherosa Ziehau intr->bnx_intr_rid, intr->bnx_intr_res); 47320c7da01dSSepherosa Ziehau } 4733f33ac8a4SSepherosa Ziehau if (sc->bnx_intr_type == PCI_INTR_TYPE_MSI) 47340c7da01dSSepherosa Ziehau pci_release_msi(sc->bnx_dev); 47350c7da01dSSepherosa Ziehau } 4736329f9016SSepherosa Ziehau 4737329f9016SSepherosa Ziehau static void 4738329f9016SSepherosa Ziehau bnx_setup_serialize(struct bnx_softc *sc) 4739329f9016SSepherosa Ziehau { 4740329f9016SSepherosa Ziehau int i, j; 4741329f9016SSepherosa Ziehau 4742329f9016SSepherosa Ziehau /* 4743329f9016SSepherosa Ziehau * Allocate serializer array 4744329f9016SSepherosa Ziehau */ 4745329f9016SSepherosa Ziehau 4746329f9016SSepherosa Ziehau /* Main + RX STD + TX + RX RET */ 4747329f9016SSepherosa Ziehau sc->bnx_serialize_cnt = 1 + 1 + sc->bnx_tx_ringcnt + sc->bnx_rx_retcnt; 4748329f9016SSepherosa Ziehau 4749329f9016SSepherosa Ziehau sc->bnx_serialize = 4750329f9016SSepherosa Ziehau kmalloc(sc->bnx_serialize_cnt * sizeof(struct lwkt_serialize *), 4751329f9016SSepherosa Ziehau M_DEVBUF, M_WAITOK | M_ZERO); 4752329f9016SSepherosa Ziehau 4753329f9016SSepherosa Ziehau /* 4754329f9016SSepherosa Ziehau * Setup serializers 4755329f9016SSepherosa Ziehau * 4756329f9016SSepherosa Ziehau * NOTE: Order is critical 4757329f9016SSepherosa Ziehau */ 4758329f9016SSepherosa Ziehau 4759329f9016SSepherosa Ziehau i = 0; 4760329f9016SSepherosa Ziehau 4761329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4762329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = &sc->bnx_main_serialize; 4763329f9016SSepherosa Ziehau 4764329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4765329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = &sc->bnx_rx_std_ring.bnx_rx_std_serialize; 4766329f9016SSepherosa Ziehau 4767329f9016SSepherosa Ziehau for (j = 0; j < sc->bnx_rx_retcnt; ++j) { 4768329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4769329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = 4770329f9016SSepherosa Ziehau &sc->bnx_rx_ret_ring[j].bnx_rx_ret_serialize; 4771329f9016SSepherosa Ziehau } 4772329f9016SSepherosa Ziehau 4773329f9016SSepherosa Ziehau for (j = 0; j < sc->bnx_tx_ringcnt; ++j) { 4774329f9016SSepherosa Ziehau KKASSERT(i < sc->bnx_serialize_cnt); 4775329f9016SSepherosa Ziehau sc->bnx_serialize[i++] = 4776329f9016SSepherosa Ziehau &sc->bnx_tx_ring[j].bnx_tx_serialize; 4777329f9016SSepherosa Ziehau } 4778329f9016SSepherosa Ziehau 4779329f9016SSepherosa Ziehau KKASSERT(i == sc->bnx_serialize_cnt); 4780329f9016SSepherosa Ziehau } 4781329f9016SSepherosa Ziehau 4782329f9016SSepherosa Ziehau static void 4783329f9016SSepherosa Ziehau bnx_serialize(struct ifnet *ifp, enum ifnet_serialize slz) 4784329f9016SSepherosa Ziehau { 4785329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4786329f9016SSepherosa Ziehau 4787329f9016SSepherosa Ziehau ifnet_serialize_array_enter(sc->bnx_serialize, 4788329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4789329f9016SSepherosa Ziehau } 4790329f9016SSepherosa Ziehau 4791329f9016SSepherosa Ziehau static void 4792329f9016SSepherosa Ziehau bnx_deserialize(struct ifnet *ifp, enum ifnet_serialize slz) 4793329f9016SSepherosa Ziehau { 4794329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4795329f9016SSepherosa Ziehau 4796329f9016SSepherosa Ziehau ifnet_serialize_array_exit(sc->bnx_serialize, 4797329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4798329f9016SSepherosa Ziehau } 4799329f9016SSepherosa Ziehau 4800329f9016SSepherosa Ziehau static int 4801329f9016SSepherosa Ziehau bnx_tryserialize(struct ifnet *ifp, enum ifnet_serialize slz) 4802329f9016SSepherosa Ziehau { 4803329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4804329f9016SSepherosa Ziehau 4805329f9016SSepherosa Ziehau return ifnet_serialize_array_try(sc->bnx_serialize, 4806329f9016SSepherosa Ziehau sc->bnx_serialize_cnt, slz); 4807329f9016SSepherosa Ziehau } 4808329f9016SSepherosa Ziehau 4809329f9016SSepherosa Ziehau #ifdef INVARIANTS 4810329f9016SSepherosa Ziehau 4811329f9016SSepherosa Ziehau static void 4812329f9016SSepherosa Ziehau bnx_serialize_assert(struct ifnet *ifp, enum ifnet_serialize slz, 4813329f9016SSepherosa Ziehau boolean_t serialized) 4814329f9016SSepherosa Ziehau { 4815329f9016SSepherosa Ziehau struct bnx_softc *sc = ifp->if_softc; 4816329f9016SSepherosa Ziehau 4817329f9016SSepherosa Ziehau ifnet_serialize_array_assert(sc->bnx_serialize, sc->bnx_serialize_cnt, 4818329f9016SSepherosa Ziehau slz, serialized); 4819329f9016SSepherosa Ziehau } 4820329f9016SSepherosa Ziehau 4821329f9016SSepherosa Ziehau #endif /* INVARIANTS */ 48224fa38985SSepherosa Ziehau 48234fa38985SSepherosa Ziehau #ifdef IFPOLL_ENABLE 48244fa38985SSepherosa Ziehau 48254fa38985SSepherosa Ziehau static int 48264fa38985SSepherosa Ziehau bnx_sysctl_npoll_offset(SYSCTL_HANDLER_ARGS) 48274fa38985SSepherosa Ziehau { 48284fa38985SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 48294fa38985SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 48304fa38985SSepherosa Ziehau int error, off; 48314fa38985SSepherosa Ziehau 48324fa38985SSepherosa Ziehau off = sc->bnx_npoll_rxoff; 48334fa38985SSepherosa Ziehau error = sysctl_handle_int(oidp, &off, 0, req); 48344fa38985SSepherosa Ziehau if (error || req->newptr == NULL) 48354fa38985SSepherosa Ziehau return error; 48364fa38985SSepherosa Ziehau if (off < 0) 48374fa38985SSepherosa Ziehau return EINVAL; 48384fa38985SSepherosa Ziehau 48394fa38985SSepherosa Ziehau ifnet_serialize_all(ifp); 48404fa38985SSepherosa Ziehau if (off >= ncpus2 || off % sc->bnx_rx_retcnt != 0) { 48414fa38985SSepherosa Ziehau error = EINVAL; 48424fa38985SSepherosa Ziehau } else { 48434fa38985SSepherosa Ziehau error = 0; 48444fa38985SSepherosa Ziehau sc->bnx_npoll_txoff = off; 48454fa38985SSepherosa Ziehau sc->bnx_npoll_rxoff = off; 48464fa38985SSepherosa Ziehau } 48474fa38985SSepherosa Ziehau ifnet_deserialize_all(ifp); 48484fa38985SSepherosa Ziehau 48494fa38985SSepherosa Ziehau return error; 48504fa38985SSepherosa Ziehau } 48514fa38985SSepherosa Ziehau 48524fa38985SSepherosa Ziehau static int 48534fa38985SSepherosa Ziehau bnx_sysctl_npoll_rxoff(SYSCTL_HANDLER_ARGS) 48544fa38985SSepherosa Ziehau { 48554fa38985SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 48564fa38985SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 48574fa38985SSepherosa Ziehau int error, off; 48584fa38985SSepherosa Ziehau 48594fa38985SSepherosa Ziehau off = sc->bnx_npoll_rxoff; 48604fa38985SSepherosa Ziehau error = sysctl_handle_int(oidp, &off, 0, req); 48614fa38985SSepherosa Ziehau if (error || req->newptr == NULL) 48624fa38985SSepherosa Ziehau return error; 48634fa38985SSepherosa Ziehau if (off < 0) 48644fa38985SSepherosa Ziehau return EINVAL; 48654fa38985SSepherosa Ziehau 48664fa38985SSepherosa Ziehau ifnet_serialize_all(ifp); 48674fa38985SSepherosa Ziehau if (off >= ncpus2 || off % sc->bnx_rx_retcnt != 0) { 48684fa38985SSepherosa Ziehau error = EINVAL; 48694fa38985SSepherosa Ziehau } else { 48704fa38985SSepherosa Ziehau error = 0; 48714fa38985SSepherosa Ziehau sc->bnx_npoll_rxoff = off; 48724fa38985SSepherosa Ziehau } 48734fa38985SSepherosa Ziehau ifnet_deserialize_all(ifp); 48744fa38985SSepherosa Ziehau 48754fa38985SSepherosa Ziehau return error; 48764fa38985SSepherosa Ziehau } 48774fa38985SSepherosa Ziehau 48784fa38985SSepherosa Ziehau static int 48794fa38985SSepherosa Ziehau bnx_sysctl_npoll_txoff(SYSCTL_HANDLER_ARGS) 48804fa38985SSepherosa Ziehau { 48814fa38985SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 48824fa38985SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 48834fa38985SSepherosa Ziehau int error, off; 48844fa38985SSepherosa Ziehau 48854fa38985SSepherosa Ziehau off = sc->bnx_npoll_txoff; 48864fa38985SSepherosa Ziehau error = sysctl_handle_int(oidp, &off, 0, req); 48874fa38985SSepherosa Ziehau if (error || req->newptr == NULL) 48884fa38985SSepherosa Ziehau return error; 48894fa38985SSepherosa Ziehau if (off < 0) 48904fa38985SSepherosa Ziehau return EINVAL; 48914fa38985SSepherosa Ziehau 48924fa38985SSepherosa Ziehau ifnet_serialize_all(ifp); 48934fa38985SSepherosa Ziehau if (off >= ncpus2) { 48944fa38985SSepherosa Ziehau error = EINVAL; 48954fa38985SSepherosa Ziehau } else { 48964fa38985SSepherosa Ziehau error = 0; 48974fa38985SSepherosa Ziehau sc->bnx_npoll_txoff = off; 48984fa38985SSepherosa Ziehau } 48994fa38985SSepherosa Ziehau ifnet_deserialize_all(ifp); 49004fa38985SSepherosa Ziehau 49014fa38985SSepherosa Ziehau return error; 49024fa38985SSepherosa Ziehau } 49034fa38985SSepherosa Ziehau 49044fa38985SSepherosa Ziehau #endif /* IFPOLL_ENABLE */ 49057dbaa833SSepherosa Ziehau 49067dbaa833SSepherosa Ziehau static void 49077dbaa833SSepherosa Ziehau bnx_set_tick_cpuid(struct bnx_softc *sc, boolean_t polling) 49087dbaa833SSepherosa Ziehau { 49097dbaa833SSepherosa Ziehau if (polling) 49107dbaa833SSepherosa Ziehau sc->bnx_tick_cpuid = 0; /* XXX */ 49117dbaa833SSepherosa Ziehau else 49127dbaa833SSepherosa Ziehau sc->bnx_tick_cpuid = sc->bnx_intr_data[0].bnx_intr_cpuid; 49137dbaa833SSepherosa Ziehau } 4914841cdf08SSepherosa Ziehau 4915841cdf08SSepherosa Ziehau static void 4916841cdf08SSepherosa Ziehau bnx_rx_std_refill_ithread(void *xstd) 4917841cdf08SSepherosa Ziehau { 4918841cdf08SSepherosa Ziehau struct bnx_rx_std_ring *std = xstd; 4919841cdf08SSepherosa Ziehau struct globaldata *gd = mycpu; 4920841cdf08SSepherosa Ziehau 4921841cdf08SSepherosa Ziehau crit_enter_gd(gd); 4922841cdf08SSepherosa Ziehau 4923841cdf08SSepherosa Ziehau while (!std->bnx_rx_std_stop) { 4924841cdf08SSepherosa Ziehau if (std->bnx_rx_std_refill) { 4925841cdf08SSepherosa Ziehau lwkt_serialize_handler_call( 4926841cdf08SSepherosa Ziehau &std->bnx_rx_std_serialize, 4927841cdf08SSepherosa Ziehau bnx_rx_std_refill, std, NULL); 4928841cdf08SSepherosa Ziehau } 4929841cdf08SSepherosa Ziehau 4930841cdf08SSepherosa Ziehau crit_exit_gd(gd); 4931841cdf08SSepherosa Ziehau crit_enter_gd(gd); 4932841cdf08SSepherosa Ziehau 4933841cdf08SSepherosa Ziehau if (!std->bnx_rx_std_refill && !std->bnx_rx_std_stop) { 4934841cdf08SSepherosa Ziehau lwkt_deschedule_self(gd->gd_curthread); 4935841cdf08SSepherosa Ziehau lwkt_switch(); 4936841cdf08SSepherosa Ziehau } 4937841cdf08SSepherosa Ziehau } 4938841cdf08SSepherosa Ziehau 4939841cdf08SSepherosa Ziehau crit_exit_gd(gd); 4940841cdf08SSepherosa Ziehau 4941841cdf08SSepherosa Ziehau wakeup(std); 4942841cdf08SSepherosa Ziehau 4943841cdf08SSepherosa Ziehau lwkt_exit(); 4944841cdf08SSepherosa Ziehau } 4945841cdf08SSepherosa Ziehau 4946841cdf08SSepherosa Ziehau static void 4947841cdf08SSepherosa Ziehau bnx_rx_std_refill(void *xstd, void *frame __unused) 4948841cdf08SSepherosa Ziehau { 4949841cdf08SSepherosa Ziehau struct bnx_rx_std_ring *std = xstd; 4950841cdf08SSepherosa Ziehau uint16_t check_idx; 4951841cdf08SSepherosa Ziehau int cnt, refill; 4952841cdf08SSepherosa Ziehau 4953841cdf08SSepherosa Ziehau again: 4954841cdf08SSepherosa Ziehau cnt = 0; 4955841cdf08SSepherosa Ziehau check_idx = std->bnx_rx_std; 4956841cdf08SSepherosa Ziehau 4957841cdf08SSepherosa Ziehau cpu_lfence(); 4958841cdf08SSepherosa Ziehau refill = std->bnx_rx_std_refill; 4959841cdf08SSepherosa Ziehau atomic_clear_int(&std->bnx_rx_std_refill, refill); 4960841cdf08SSepherosa Ziehau 4961841cdf08SSepherosa Ziehau for (;;) { 4962841cdf08SSepherosa Ziehau struct bnx_rx_buf *rb; 4963841cdf08SSepherosa Ziehau 4964841cdf08SSepherosa Ziehau BNX_INC(check_idx, BGE_STD_RX_RING_CNT); 4965841cdf08SSepherosa Ziehau rb = &std->bnx_rx_std_buf[check_idx]; 4966841cdf08SSepherosa Ziehau 4967841cdf08SSepherosa Ziehau if (rb->bnx_rx_refilled) { 4968841cdf08SSepherosa Ziehau cpu_lfence(); 4969841cdf08SSepherosa Ziehau bnx_setup_rxdesc_std(std, check_idx); 4970841cdf08SSepherosa Ziehau std->bnx_rx_std = check_idx; 4971841cdf08SSepherosa Ziehau ++cnt; 4972841cdf08SSepherosa Ziehau } else { 4973841cdf08SSepherosa Ziehau break; 4974841cdf08SSepherosa Ziehau } 4975841cdf08SSepherosa Ziehau } 4976841cdf08SSepherosa Ziehau 4977841cdf08SSepherosa Ziehau if (cnt) { 4978841cdf08SSepherosa Ziehau bnx_writembx(std->bnx_sc, BGE_MBX_RX_STD_PROD_LO, 4979841cdf08SSepherosa Ziehau std->bnx_rx_std); 4980841cdf08SSepherosa Ziehau } 4981841cdf08SSepherosa Ziehau 4982841cdf08SSepherosa Ziehau if (std->bnx_rx_std_refill) 4983841cdf08SSepherosa Ziehau goto again; 4984841cdf08SSepherosa Ziehau 4985841cdf08SSepherosa Ziehau atomic_poll_release_int(&std->bnx_rx_std_running); 4986841cdf08SSepherosa Ziehau cpu_mfence(); 4987841cdf08SSepherosa Ziehau 4988841cdf08SSepherosa Ziehau if (std->bnx_rx_std_refill) 4989841cdf08SSepherosa Ziehau goto again; 4990841cdf08SSepherosa Ziehau } 4991841cdf08SSepherosa Ziehau 4992841cdf08SSepherosa Ziehau static int 4993841cdf08SSepherosa Ziehau bnx_sysctl_std_refill(SYSCTL_HANDLER_ARGS) 4994841cdf08SSepherosa Ziehau { 4995841cdf08SSepherosa Ziehau struct bnx_softc *sc = (void *)arg1; 4996841cdf08SSepherosa Ziehau struct ifnet *ifp = &sc->arpcom.ac_if; 4997841cdf08SSepherosa Ziehau struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; 4998841cdf08SSepherosa Ziehau int error, cntmax, i; 4999841cdf08SSepherosa Ziehau 5000841cdf08SSepherosa Ziehau cntmax = ret->bnx_rx_cntmax; 5001841cdf08SSepherosa Ziehau error = sysctl_handle_int(oidp, &cntmax, 0, req); 5002841cdf08SSepherosa Ziehau if (error || req->newptr == NULL) 5003841cdf08SSepherosa Ziehau return error; 5004841cdf08SSepherosa Ziehau 5005841cdf08SSepherosa Ziehau ifnet_serialize_all(ifp); 5006841cdf08SSepherosa Ziehau 5007841cdf08SSepherosa Ziehau if ((cntmax * sc->bnx_rx_retcnt) > BGE_STD_RX_RING_CNT / 2) { 5008841cdf08SSepherosa Ziehau error = EINVAL; 5009841cdf08SSepherosa Ziehau goto back; 5010841cdf08SSepherosa Ziehau } 5011841cdf08SSepherosa Ziehau 5012841cdf08SSepherosa Ziehau for (i = 0; i < sc->bnx_tx_ringcnt; ++i) 5013841cdf08SSepherosa Ziehau sc->bnx_rx_ret_ring[i].bnx_rx_cntmax = cntmax; 5014841cdf08SSepherosa Ziehau error = 0; 5015841cdf08SSepherosa Ziehau 5016841cdf08SSepherosa Ziehau back: 5017841cdf08SSepherosa Ziehau ifnet_deserialize_all(ifp); 5018841cdf08SSepherosa Ziehau 5019841cdf08SSepherosa Ziehau return error; 5020841cdf08SSepherosa Ziehau } 5021