2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2001
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Bill Paul.
17 * 4. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
33 * $FreeBSD: src/sys/dev/bge/if_bge.c,v 1.3.2.39 2005/07/03 03:41:18 silby Exp $
37 #include "opt_ifpoll.h"
39 #include <sys/param.h>
41 #include <sys/endian.h>
42 #include <sys/kernel.h>
43 #include <sys/interrupt.h>
45 #include <sys/malloc.h>
46 #include <sys/queue.h>
48 #include <sys/serialize.h>
49 #include <sys/socket.h>
50 #include <sys/sockio.h>
51 #include <sys/sysctl.h>
53 #include <netinet/ip.h>
54 #include <netinet/tcp.h>
57 #include <net/ethernet.h>
59 #include <net/if_arp.h>
60 #include <net/if_dl.h>
61 #include <net/if_media.h>
62 #include <net/if_poll.h>
63 #include <net/if_types.h>
64 #include <net/ifq_var.h>
65 #include <net/vlan/if_vlan_var.h>
66 #include <net/vlan/if_vlan_ether.h>
68 #include <dev/netif/mii_layer/mii.h>
69 #include <dev/netif/mii_layer/miivar.h>
70 #include <dev/netif/mii_layer/brgphyreg.h>
72 #include <bus/pci/pcidevs.h>
73 #include <bus/pci/pcireg.h>
74 #include <bus/pci/pcivar.h>
76 #include <dev/netif/bge/if_bgereg.h>
77 #include <dev/netif/bnx/if_bnxvar.h>
79 /* "device miibus" required. See GENERIC if you get errors here. */
80 #include "miibus_if.h"
82 #define BNX_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP)
84 #define BNX_INTR_CKINTVL ((10 * hz) / 1000) /* 10ms */
86 static const struct bnx_type {
91 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717,
92 "Broadcom BCM5717 Gigabit Ethernet" },
93 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717C,
94 "Broadcom BCM5717C Gigabit Ethernet" },
95 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5718,
96 "Broadcom BCM5718 Gigabit Ethernet" },
97 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5719,
98 "Broadcom BCM5719 Gigabit Ethernet" },
99 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5720_ALT,
100 "Broadcom BCM5720 Gigabit Ethernet" },
102 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5725,
103 "Broadcom BCM5725 Gigabit Ethernet" },
104 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5727,
105 "Broadcom BCM5727 Gigabit Ethernet" },
106 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5762,
107 "Broadcom BCM5762 Gigabit Ethernet" },
109 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57761,
110 "Broadcom BCM57761 Gigabit Ethernet" },
111 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57762,
112 "Broadcom BCM57762 Gigabit Ethernet" },
113 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57765,
114 "Broadcom BCM57765 Gigabit Ethernet" },
115 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57766,
116 "Broadcom BCM57766 Gigabit Ethernet" },
117 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57781,
118 "Broadcom BCM57781 Gigabit Ethernet" },
119 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57782,
120 "Broadcom BCM57782 Gigabit Ethernet" },
121 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57785,
122 "Broadcom BCM57785 Gigabit Ethernet" },
123 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57786,
124 "Broadcom BCM57786 Gigabit Ethernet" },
125 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57791,
126 "Broadcom BCM57791 Fast Ethernet" },
127 { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM57795,
128 "Broadcom BCM57795 Fast Ethernet" },
133 #define BNX_IS_JUMBO_CAPABLE(sc) ((sc)->bnx_flags & BNX_FLAG_JUMBO)
134 #define BNX_IS_5717_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_5717_PLUS)
135 #define BNX_IS_57765_PLUS(sc) ((sc)->bnx_flags & BNX_FLAG_57765_PLUS)
136 #define BNX_IS_57765_FAMILY(sc) \
137 ((sc)->bnx_flags & BNX_FLAG_57765_FAMILY)
139 typedef int (*bnx_eaddr_fcn_t)(struct bnx_softc *, uint8_t[]);
141 static int bnx_probe(device_t);
142 static int bnx_attach(device_t);
143 static int bnx_detach(device_t);
144 static void bnx_shutdown(device_t);
145 static int bnx_suspend(device_t);
146 static int bnx_resume(device_t);
147 static int bnx_miibus_readreg(device_t, int, int);
148 static int bnx_miibus_writereg(device_t, int, int, int);
149 static void bnx_miibus_statchg(device_t);
152 static void bnx_npoll(struct ifnet *, struct ifpoll_info *);
153 static void bnx_npoll_compat(struct ifnet *, void *, int);
155 static void bnx_intr_legacy(void *);
156 static void bnx_msi(void *);
157 static void bnx_msi_oneshot(void *);
158 static void bnx_intr(struct bnx_softc *);
159 static void bnx_enable_intr(struct bnx_softc *);
160 static void bnx_disable_intr(struct bnx_softc *);
161 static void bnx_txeof(struct bnx_tx_ring *, uint16_t);
162 static void bnx_rxeof(struct bnx_rx_ret_ring *, uint16_t, int);
163 static int bnx_alloc_intr(struct bnx_softc *);
164 static int bnx_setup_intr(struct bnx_softc *);
165 static void bnx_free_intr(struct bnx_softc *);
167 static void bnx_start(struct ifnet *, struct ifaltq_subque *);
168 static int bnx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
169 static void bnx_init(void *);
170 static void bnx_stop(struct bnx_softc *);
171 static void bnx_watchdog(struct ifnet *);
172 static int bnx_ifmedia_upd(struct ifnet *);
173 static void bnx_ifmedia_sts(struct ifnet *, struct ifmediareq *);
174 static void bnx_tick(void *);
176 static int bnx_alloc_jumbo_mem(struct bnx_softc *);
177 static void bnx_free_jumbo_mem(struct bnx_softc *);
178 static struct bnx_jslot
179 *bnx_jalloc(struct bnx_softc *);
180 static void bnx_jfree(void *);
181 static void bnx_jref(void *);
182 static int bnx_newbuf_std(struct bnx_rx_ret_ring *, int, int);
183 static int bnx_newbuf_jumbo(struct bnx_softc *, int, int);
184 static void bnx_setup_rxdesc_std(struct bnx_rx_std_ring *, int);
185 static void bnx_setup_rxdesc_jumbo(struct bnx_softc *, int);
186 static int bnx_init_rx_ring_std(struct bnx_rx_std_ring *);
187 static void bnx_free_rx_ring_std(struct bnx_rx_std_ring *);
188 static int bnx_init_rx_ring_jumbo(struct bnx_softc *);
189 static void bnx_free_rx_ring_jumbo(struct bnx_softc *);
190 static void bnx_free_tx_ring(struct bnx_tx_ring *);
191 static int bnx_init_tx_ring(struct bnx_tx_ring *);
192 static int bnx_create_tx_ring(struct bnx_tx_ring *);
193 static void bnx_destroy_tx_ring(struct bnx_tx_ring *);
194 static int bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *);
195 static void bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *);
196 static int bnx_dma_alloc(device_t);
197 static void bnx_dma_free(struct bnx_softc *);
198 static int bnx_dma_block_alloc(struct bnx_softc *, bus_size_t,
199 bus_dma_tag_t *, bus_dmamap_t *, void **, bus_addr_t *);
200 static void bnx_dma_block_free(bus_dma_tag_t, bus_dmamap_t, void *);
202 bnx_defrag_shortdma(struct mbuf *);
203 static int bnx_encap(struct bnx_tx_ring *, struct mbuf **,
205 static int bnx_setup_tso(struct bnx_tx_ring *, struct mbuf **,
206 uint16_t *, uint16_t *);
208 static void bnx_reset(struct bnx_softc *);
209 static int bnx_chipinit(struct bnx_softc *);
210 static int bnx_blockinit(struct bnx_softc *);
211 static void bnx_stop_block(struct bnx_softc *, bus_size_t, uint32_t);
212 static void bnx_enable_msi(struct bnx_softc *sc);
213 static void bnx_setmulti(struct bnx_softc *);
214 static void bnx_setpromisc(struct bnx_softc *);
215 static void bnx_stats_update_regs(struct bnx_softc *);
216 static uint32_t bnx_dma_swap_options(struct bnx_softc *);
218 static uint32_t bnx_readmem_ind(struct bnx_softc *, uint32_t);
219 static void bnx_writemem_ind(struct bnx_softc *, uint32_t, uint32_t);
221 static uint32_t bnx_readreg_ind(struct bnx_softc *, uint32_t);
223 static void bnx_writemem_direct(struct bnx_softc *, uint32_t, uint32_t);
224 static void bnx_writembx(struct bnx_softc *, int, int);
225 static int bnx_read_nvram(struct bnx_softc *, caddr_t, int, int);
226 static uint8_t bnx_eeprom_getbyte(struct bnx_softc *, uint32_t, uint8_t *);
227 static int bnx_read_eeprom(struct bnx_softc *, caddr_t, uint32_t, size_t);
229 static void bnx_tbi_link_upd(struct bnx_softc *, uint32_t);
230 static void bnx_copper_link_upd(struct bnx_softc *, uint32_t);
231 static void bnx_autopoll_link_upd(struct bnx_softc *, uint32_t);
232 static void bnx_link_poll(struct bnx_softc *);
234 static int bnx_get_eaddr_mem(struct bnx_softc *, uint8_t[]);
235 static int bnx_get_eaddr_nvram(struct bnx_softc *, uint8_t[]);
236 static int bnx_get_eaddr_eeprom(struct bnx_softc *, uint8_t[]);
237 static int bnx_get_eaddr(struct bnx_softc *, uint8_t[]);
239 static void bnx_coal_change(struct bnx_softc *);
240 static int bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS);
241 static int bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS);
242 static int bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS);
243 static int bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS);
244 static int bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS);
245 static int bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS);
246 static int bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS);
247 static int bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS);
248 static int bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *,
251 static int bnx_msi_enable = 1;
252 TUNABLE_INT("hw.bnx.msi.enable", &bnx_msi_enable);
254 static device_method_t bnx_methods[] = {
255 /* Device interface */
256 DEVMETHOD(device_probe, bnx_probe),
257 DEVMETHOD(device_attach, bnx_attach),
258 DEVMETHOD(device_detach, bnx_detach),
259 DEVMETHOD(device_shutdown, bnx_shutdown),
260 DEVMETHOD(device_suspend, bnx_suspend),
261 DEVMETHOD(device_resume, bnx_resume),
264 DEVMETHOD(bus_print_child, bus_generic_print_child),
265 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
268 DEVMETHOD(miibus_readreg, bnx_miibus_readreg),
269 DEVMETHOD(miibus_writereg, bnx_miibus_writereg),
270 DEVMETHOD(miibus_statchg, bnx_miibus_statchg),
275 static DEFINE_CLASS_0(bnx, bnx_driver, bnx_methods, sizeof(struct bnx_softc));
276 static devclass_t bnx_devclass;
278 DECLARE_DUMMY_MODULE(if_bnx);
279 DRIVER_MODULE(if_bnx, pci, bnx_driver, bnx_devclass, NULL, NULL);
280 DRIVER_MODULE(miibus, bnx, miibus_driver, miibus_devclass, NULL, NULL);
283 bnx_readmem_ind(struct bnx_softc *sc, uint32_t off)
285 device_t dev = sc->bnx_dev;
288 pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4);
289 val = pci_read_config(dev, BGE_PCI_MEMWIN_DATA, 4);
290 pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4);
295 bnx_writemem_ind(struct bnx_softc *sc, uint32_t off, uint32_t val)
297 device_t dev = sc->bnx_dev;
299 pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, off, 4);
300 pci_write_config(dev, BGE_PCI_MEMWIN_DATA, val, 4);
301 pci_write_config(dev, BGE_PCI_MEMWIN_BASEADDR, 0, 4);
305 bnx_writemem_direct(struct bnx_softc *sc, uint32_t off, uint32_t val)
307 CSR_WRITE_4(sc, off, val);
311 bnx_writembx(struct bnx_softc *sc, int off, int val)
313 CSR_WRITE_4(sc, off, val);
317 * Read a sequence of bytes from NVRAM.
320 bnx_read_nvram(struct bnx_softc *sc, caddr_t dest, int off, int cnt)
326 * Read a byte of data stored in the EEPROM at address 'addr.' The
327 * BCM570x supports both the traditional bitbang interface and an
328 * auto access interface for reading the EEPROM. We use the auto
332 bnx_eeprom_getbyte(struct bnx_softc *sc, uint32_t addr, uint8_t *dest)
338 * Enable use of auto EEPROM access so we can avoid
339 * having to use the bitbang method.
341 BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_AUTO_EEPROM);
343 /* Reset the EEPROM, load the clock period. */
344 CSR_WRITE_4(sc, BGE_EE_ADDR,
345 BGE_EEADDR_RESET|BGE_EEHALFCLK(BGE_HALFCLK_384SCL));
348 /* Issue the read EEPROM command. */
349 CSR_WRITE_4(sc, BGE_EE_ADDR, BGE_EE_READCMD | addr);
351 /* Wait for completion */
352 for(i = 0; i < BNX_TIMEOUT * 10; i++) {
354 if (CSR_READ_4(sc, BGE_EE_ADDR) & BGE_EEADDR_DONE)
358 if (i == BNX_TIMEOUT) {
359 if_printf(&sc->arpcom.ac_if, "eeprom read timed out\n");
364 byte = CSR_READ_4(sc, BGE_EE_DATA);
366 *dest = (byte >> ((addr % 4) * 8)) & 0xFF;
372 * Read a sequence of bytes from the EEPROM.
375 bnx_read_eeprom(struct bnx_softc *sc, caddr_t dest, uint32_t off, size_t len)
381 for (byte = 0, err = 0, i = 0; i < len; i++) {
382 err = bnx_eeprom_getbyte(sc, off + i, &byte);
392 bnx_miibus_readreg(device_t dev, int phy, int reg)
394 struct bnx_softc *sc = device_get_softc(dev);
398 KASSERT(phy == sc->bnx_phyno,
399 ("invalid phyno %d, should be %d", phy, sc->bnx_phyno));
401 /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */
402 if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
403 CSR_WRITE_4(sc, BGE_MI_MODE,
404 sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL);
408 CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ | BGE_MICOMM_BUSY |
409 BGE_MIPHY(phy) | BGE_MIREG(reg));
411 /* Poll for the PHY register access to complete. */
412 for (i = 0; i < BNX_TIMEOUT; i++) {
414 val = CSR_READ_4(sc, BGE_MI_COMM);
415 if ((val & BGE_MICOMM_BUSY) == 0) {
417 val = CSR_READ_4(sc, BGE_MI_COMM);
421 if (i == BNX_TIMEOUT) {
422 if_printf(&sc->arpcom.ac_if, "PHY read timed out "
423 "(phy %d, reg %d, val 0x%08x)\n", phy, reg, val);
427 /* Restore the autopoll bit if necessary. */
428 if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
429 CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode);
433 if (val & BGE_MICOMM_READFAIL)
436 return (val & 0xFFFF);
440 bnx_miibus_writereg(device_t dev, int phy, int reg, int val)
442 struct bnx_softc *sc = device_get_softc(dev);
445 KASSERT(phy == sc->bnx_phyno,
446 ("invalid phyno %d, should be %d", phy, sc->bnx_phyno));
448 /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */
449 if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
450 CSR_WRITE_4(sc, BGE_MI_MODE,
451 sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL);
455 CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY |
456 BGE_MIPHY(phy) | BGE_MIREG(reg) | val);
458 for (i = 0; i < BNX_TIMEOUT; i++) {
460 if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) {
462 CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */
466 if (i == BNX_TIMEOUT) {
467 if_printf(&sc->arpcom.ac_if, "PHY write timed out "
468 "(phy %d, reg %d, val %d)\n", phy, reg, val);
471 /* Restore the autopoll bit if necessary. */
472 if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
473 CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode);
481 bnx_miibus_statchg(device_t dev)
483 struct bnx_softc *sc;
484 struct mii_data *mii;
486 sc = device_get_softc(dev);
487 mii = device_get_softc(sc->bnx_miibus);
489 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
490 (IFM_ACTIVE | IFM_AVALID)) {
491 switch (IFM_SUBTYPE(mii->mii_media_active)) {
508 if (sc->bnx_link == 0)
511 BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE);
512 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
513 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
514 BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII);
516 BNX_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII);
519 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
520 BNX_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX);
522 BNX_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX);
527 * Memory management for jumbo frames.
530 bnx_alloc_jumbo_mem(struct bnx_softc *sc)
532 struct ifnet *ifp = &sc->arpcom.ac_if;
533 struct bnx_jslot *entry;
539 * Create tag for jumbo mbufs.
540 * This is really a bit of a kludge. We allocate a special
541 * jumbo buffer pool which (thanks to the way our DMA
542 * memory allocation works) will consist of contiguous
543 * pages. This means that even though a jumbo buffer might
544 * be larger than a page size, we don't really need to
545 * map it into more than one DMA segment. However, the
546 * default mbuf tag will result in multi-segment mappings,
547 * so we have to create a special jumbo mbuf tag that
548 * lets us get away with mapping the jumbo buffers as
549 * a single segment. I think eventually the driver should
550 * be changed so that it uses ordinary mbufs and cluster
551 * buffers, i.e. jumbo frames can span multiple DMA
552 * descriptors. But that's a project for another day.
556 * Create DMA stuffs for jumbo RX ring.
558 error = bnx_dma_block_alloc(sc, BGE_JUMBO_RX_RING_SZ,
559 &sc->bnx_cdata.bnx_rx_jumbo_ring_tag,
560 &sc->bnx_cdata.bnx_rx_jumbo_ring_map,
561 (void *)&sc->bnx_ldata.bnx_rx_jumbo_ring,
562 &sc->bnx_ldata.bnx_rx_jumbo_ring_paddr);
564 if_printf(ifp, "could not create jumbo RX ring\n");
569 * Create DMA stuffs for jumbo buffer block.
571 error = bnx_dma_block_alloc(sc, BNX_JMEM,
572 &sc->bnx_cdata.bnx_jumbo_tag,
573 &sc->bnx_cdata.bnx_jumbo_map,
574 (void **)&sc->bnx_ldata.bnx_jumbo_buf,
577 if_printf(ifp, "could not create jumbo buffer\n");
581 SLIST_INIT(&sc->bnx_jfree_listhead);
584 * Now divide it up into 9K pieces and save the addresses
585 * in an array. Note that we play an evil trick here by using
586 * the first few bytes in the buffer to hold the the address
587 * of the softc structure for this interface. This is because
588 * bnx_jfree() needs it, but it is called by the mbuf management
589 * code which will not pass it to us explicitly.
591 for (i = 0, ptr = sc->bnx_ldata.bnx_jumbo_buf; i < BNX_JSLOTS; i++) {
592 entry = &sc->bnx_cdata.bnx_jslots[i];
594 entry->bnx_buf = ptr;
595 entry->bnx_paddr = paddr;
596 entry->bnx_inuse = 0;
598 SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead, entry, jslot_link);
607 bnx_free_jumbo_mem(struct bnx_softc *sc)
609 /* Destroy jumbo RX ring. */
610 bnx_dma_block_free(sc->bnx_cdata.bnx_rx_jumbo_ring_tag,
611 sc->bnx_cdata.bnx_rx_jumbo_ring_map,
612 sc->bnx_ldata.bnx_rx_jumbo_ring);
614 /* Destroy jumbo buffer block. */
615 bnx_dma_block_free(sc->bnx_cdata.bnx_jumbo_tag,
616 sc->bnx_cdata.bnx_jumbo_map,
617 sc->bnx_ldata.bnx_jumbo_buf);
621 * Allocate a jumbo buffer.
623 static struct bnx_jslot *
624 bnx_jalloc(struct bnx_softc *sc)
626 struct bnx_jslot *entry;
628 lwkt_serialize_enter(&sc->bnx_jslot_serializer);
629 entry = SLIST_FIRST(&sc->bnx_jfree_listhead);
631 SLIST_REMOVE_HEAD(&sc->bnx_jfree_listhead, jslot_link);
632 entry->bnx_inuse = 1;
634 if_printf(&sc->arpcom.ac_if, "no free jumbo buffers\n");
636 lwkt_serialize_exit(&sc->bnx_jslot_serializer);
641 * Adjust usage count on a jumbo buffer.
646 struct bnx_jslot *entry = (struct bnx_jslot *)arg;
647 struct bnx_softc *sc = entry->bnx_sc;
650 panic("bnx_jref: can't find softc pointer!");
652 if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) {
653 panic("bnx_jref: asked to reference buffer "
654 "that we don't manage!");
655 } else if (entry->bnx_inuse == 0) {
656 panic("bnx_jref: buffer already free!");
658 atomic_add_int(&entry->bnx_inuse, 1);
663 * Release a jumbo buffer.
668 struct bnx_jslot *entry = (struct bnx_jslot *)arg;
669 struct bnx_softc *sc = entry->bnx_sc;
672 panic("bnx_jfree: can't find softc pointer!");
674 if (&sc->bnx_cdata.bnx_jslots[entry->bnx_slot] != entry) {
675 panic("bnx_jfree: asked to free buffer that we don't manage!");
676 } else if (entry->bnx_inuse == 0) {
677 panic("bnx_jfree: buffer already free!");
680 * Possible MP race to 0, use the serializer. The atomic insn
681 * is still needed for races against bnx_jref().
683 lwkt_serialize_enter(&sc->bnx_jslot_serializer);
684 atomic_subtract_int(&entry->bnx_inuse, 1);
685 if (entry->bnx_inuse == 0) {
686 SLIST_INSERT_HEAD(&sc->bnx_jfree_listhead,
689 lwkt_serialize_exit(&sc->bnx_jslot_serializer);
695 * Intialize a standard receive ring descriptor.
698 bnx_newbuf_std(struct bnx_rx_ret_ring *ret, int i, int init)
700 struct mbuf *m_new = NULL;
701 bus_dma_segment_t seg;
704 struct bnx_rx_buf *rb;
706 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
709 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
710 m_adj(m_new, ETHER_ALIGN);
712 error = bus_dmamap_load_mbuf_segment(ret->bnx_rx_mtag,
713 ret->bnx_rx_tmpmap, m_new, &seg, 1, &nsegs, BUS_DMA_NOWAIT);
719 rb = &ret->bnx_std->bnx_rx_std_buf[i];
722 bus_dmamap_sync(ret->bnx_rx_mtag, rb->bnx_rx_dmamap,
723 BUS_DMASYNC_POSTREAD);
724 bus_dmamap_unload(ret->bnx_rx_mtag, rb->bnx_rx_dmamap);
727 map = ret->bnx_rx_tmpmap;
728 ret->bnx_rx_tmpmap = rb->bnx_rx_dmamap;
729 rb->bnx_rx_dmamap = map;
731 rb->bnx_rx_mbuf = m_new;
732 rb->bnx_rx_paddr = seg.ds_addr;
734 bnx_setup_rxdesc_std(ret->bnx_std, i);
739 bnx_setup_rxdesc_std(struct bnx_rx_std_ring *std, int i)
741 const struct bnx_rx_buf *rb;
744 rb = &std->bnx_rx_std_buf[i];
745 r = &std->bnx_rx_std_ring[i];
747 r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rb->bnx_rx_paddr);
748 r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rb->bnx_rx_paddr);
749 r->bge_len = rb->bnx_rx_mbuf->m_len;
751 r->bge_flags = BGE_RXBDFLAG_END;
755 * Initialize a jumbo receive ring descriptor. This allocates
756 * a jumbo buffer from the pool managed internally by the driver.
759 bnx_newbuf_jumbo(struct bnx_softc *sc, int i, int init)
761 struct mbuf *m_new = NULL;
762 struct bnx_jslot *buf;
765 /* Allocate the mbuf. */
766 MGETHDR(m_new, init ? MB_WAIT : MB_DONTWAIT, MT_DATA);
770 /* Allocate the jumbo buffer */
771 buf = bnx_jalloc(sc);
777 /* Attach the buffer to the mbuf. */
778 m_new->m_ext.ext_arg = buf;
779 m_new->m_ext.ext_buf = buf->bnx_buf;
780 m_new->m_ext.ext_free = bnx_jfree;
781 m_new->m_ext.ext_ref = bnx_jref;
782 m_new->m_ext.ext_size = BNX_JUMBO_FRAMELEN;
784 m_new->m_flags |= M_EXT;
786 m_new->m_data = m_new->m_ext.ext_buf;
787 m_new->m_len = m_new->m_pkthdr.len = m_new->m_ext.ext_size;
789 paddr = buf->bnx_paddr;
790 m_adj(m_new, ETHER_ALIGN);
791 paddr += ETHER_ALIGN;
793 /* Save necessary information */
794 sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_mbuf = m_new;
795 sc->bnx_cdata.bnx_rx_jumbo_chain[i].bnx_rx_paddr = paddr;
797 /* Set up the descriptor. */
798 bnx_setup_rxdesc_jumbo(sc, i);
803 bnx_setup_rxdesc_jumbo(struct bnx_softc *sc, int i)
806 struct bnx_rx_buf *rc;
808 r = &sc->bnx_ldata.bnx_rx_jumbo_ring[i];
809 rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i];
811 r->bge_addr.bge_addr_lo = BGE_ADDR_LO(rc->bnx_rx_paddr);
812 r->bge_addr.bge_addr_hi = BGE_ADDR_HI(rc->bnx_rx_paddr);
813 r->bge_len = rc->bnx_rx_mbuf->m_len;
815 r->bge_flags = BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING;
819 bnx_init_rx_ring_std(struct bnx_rx_std_ring *std)
823 for (i = 0; i < BGE_STD_RX_RING_CNT; i++) {
824 /* Use the first RX return ring's tmp RX mbuf DMA map */
825 error = bnx_newbuf_std(&std->bnx_sc->bnx_rx_ret_ring[0], i, 1);
830 std->bnx_rx_std = BGE_STD_RX_RING_CNT - 1;
831 bnx_writembx(std->bnx_sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std);
837 bnx_free_rx_ring_std(struct bnx_rx_std_ring *std)
841 for (i = 0; i < BGE_STD_RX_RING_CNT; i++) {
842 struct bnx_rx_buf *rb = &std->bnx_rx_std_buf[i];
844 if (rb->bnx_rx_mbuf != NULL) {
845 bus_dmamap_unload(std->bnx_rx_mtag, rb->bnx_rx_dmamap);
846 m_freem(rb->bnx_rx_mbuf);
847 rb->bnx_rx_mbuf = NULL;
849 bzero(&std->bnx_rx_std_ring[i], sizeof(struct bge_rx_bd));
854 bnx_init_rx_ring_jumbo(struct bnx_softc *sc)
859 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
860 error = bnx_newbuf_jumbo(sc, i, 1);
865 sc->bnx_jumbo = BGE_JUMBO_RX_RING_CNT - 1;
867 rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb;
868 rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0);
869 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
871 bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo);
877 bnx_free_rx_ring_jumbo(struct bnx_softc *sc)
881 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
882 struct bnx_rx_buf *rc = &sc->bnx_cdata.bnx_rx_jumbo_chain[i];
884 if (rc->bnx_rx_mbuf != NULL) {
885 m_freem(rc->bnx_rx_mbuf);
886 rc->bnx_rx_mbuf = NULL;
888 bzero(&sc->bnx_ldata.bnx_rx_jumbo_ring[i],
889 sizeof(struct bge_rx_bd));
894 bnx_free_tx_ring(struct bnx_tx_ring *txr)
898 for (i = 0; i < BGE_TX_RING_CNT; i++) {
899 struct bnx_tx_buf *buf = &txr->bnx_tx_buf[i];
901 if (buf->bnx_tx_mbuf != NULL) {
902 bus_dmamap_unload(txr->bnx_tx_mtag,
904 m_freem(buf->bnx_tx_mbuf);
905 buf->bnx_tx_mbuf = NULL;
907 bzero(&txr->bnx_tx_ring[i], sizeof(struct bge_tx_bd));
909 txr->bnx_tx_saved_considx = BNX_TXCONS_UNSET;
913 bnx_init_tx_ring(struct bnx_tx_ring *txr)
916 txr->bnx_tx_saved_considx = 0;
917 txr->bnx_tx_prodidx = 0;
919 /* Initialize transmit producer index for host-memory send ring. */
920 bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, txr->bnx_tx_prodidx);
926 bnx_setmulti(struct bnx_softc *sc)
929 struct ifmultiaddr *ifma;
930 uint32_t hashes[4] = { 0, 0, 0, 0 };
933 ifp = &sc->arpcom.ac_if;
935 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
936 for (i = 0; i < 4; i++)
937 CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0xFFFFFFFF);
941 /* First, zot all the existing filters. */
942 for (i = 0; i < 4; i++)
943 CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), 0);
945 /* Now program new ones. */
946 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
947 if (ifma->ifma_addr->sa_family != AF_LINK)
950 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
951 ETHER_ADDR_LEN) & 0x7f;
952 hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F);
955 for (i = 0; i < 4; i++)
956 CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]);
960 * Do endian, PCI and DMA initialization. Also check the on-board ROM
964 bnx_chipinit(struct bnx_softc *sc)
966 uint32_t dma_rw_ctl, mode_ctl;
969 /* Set endian type before we access any non-PCI registers. */
970 pci_write_config(sc->bnx_dev, BGE_PCI_MISC_CTL,
971 BGE_INIT | BGE_PCIMISCCTL_TAGGED_STATUS, 4);
973 /* Clear the MAC control register */
974 CSR_WRITE_4(sc, BGE_MAC_MODE, 0);
977 * Clear the MAC statistics block in the NIC's
980 for (i = BGE_STATS_BLOCK;
981 i < BGE_STATS_BLOCK_END + 1; i += sizeof(uint32_t))
982 BNX_MEMWIN_WRITE(sc, i, 0);
984 for (i = BGE_STATUS_BLOCK;
985 i < BGE_STATUS_BLOCK_END + 1; i += sizeof(uint32_t))
986 BNX_MEMWIN_WRITE(sc, i, 0);
988 if (BNX_IS_57765_FAMILY(sc)) {
991 if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0) {
992 mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL);
993 val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS;
995 /* Access the lower 1K of PL PCI-E block registers. */
996 CSR_WRITE_4(sc, BGE_MODE_CTL,
997 val | BGE_MODECTL_PCIE_PL_SEL);
999 val = CSR_READ_4(sc, BGE_PCIE_PL_LO_PHYCTL5);
1000 val |= BGE_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ;
1001 CSR_WRITE_4(sc, BGE_PCIE_PL_LO_PHYCTL5, val);
1003 CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl);
1005 if (sc->bnx_chiprev != BGE_CHIPREV_57765_AX) {
1006 /* Fix transmit hangs */
1007 val = CSR_READ_4(sc, BGE_CPMU_PADRNG_CTL);
1008 val |= BGE_CPMU_PADRNG_CTL_RDIV2;
1009 CSR_WRITE_4(sc, BGE_CPMU_PADRNG_CTL, val);
1011 mode_ctl = CSR_READ_4(sc, BGE_MODE_CTL);
1012 val = mode_ctl & ~BGE_MODECTL_PCIE_PORTS;
1014 /* Access the lower 1K of DL PCI-E block registers. */
1015 CSR_WRITE_4(sc, BGE_MODE_CTL,
1016 val | BGE_MODECTL_PCIE_DL_SEL);
1018 val = CSR_READ_4(sc, BGE_PCIE_DL_LO_FTSMAX);
1019 val &= ~BGE_PCIE_DL_LO_FTSMAX_MASK;
1020 val |= BGE_PCIE_DL_LO_FTSMAX_VAL;
1021 CSR_WRITE_4(sc, BGE_PCIE_DL_LO_FTSMAX, val);
1023 CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl);
1026 val = CSR_READ_4(sc, BGE_CPMU_LSPD_10MB_CLK);
1027 val &= ~BGE_CPMU_LSPD_10MB_MACCLK_MASK;
1028 val |= BGE_CPMU_LSPD_10MB_MACCLK_6_25;
1029 CSR_WRITE_4(sc, BGE_CPMU_LSPD_10MB_CLK, val);
1033 * Set up the PCI DMA control register.
1035 dma_rw_ctl = pci_read_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, 4);
1037 * Disable 32bytes cache alignment for DMA write to host memory
1040 * 64bytes cache alignment for DMA write to host memory is still
1043 dma_rw_ctl |= BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT;
1044 if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0)
1045 dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK;
1047 * Enable HW workaround for controllers that misinterpret
1048 * a status tag update and leave interrupts permanently
1051 if (sc->bnx_asicrev != BGE_ASICREV_BCM5717 &&
1052 sc->bnx_asicrev != BGE_ASICREV_BCM5762 &&
1053 !BNX_IS_57765_FAMILY(sc))
1054 dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA;
1056 if_printf(&sc->arpcom.ac_if, "DMA read/write %#x\n",
1059 pci_write_config(sc->bnx_dev, BGE_PCI_DMA_RW_CTL, dma_rw_ctl, 4);
1062 * Set up general mode register.
1064 mode_ctl = bnx_dma_swap_options(sc) | BGE_MODECTL_MAC_ATTN_INTR |
1065 BGE_MODECTL_HOST_SEND_BDS | BGE_MODECTL_TX_NO_PHDR_CSUM;
1066 CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl);
1069 * Disable memory write invalidate. Apparently it is not supported
1070 * properly by these devices. Also ensure that INTx isn't disabled,
1071 * as these chips need it even when using MSI.
1073 PCI_CLRBIT(sc->bnx_dev, BGE_PCI_CMD,
1074 (PCIM_CMD_MWRICEN | PCIM_CMD_INTxDIS), 4);
1076 /* Set the timer prescaler (always 66Mhz) */
1077 CSR_WRITE_4(sc, BGE_MISC_CFG, 65 << 1/*BGE_32BITTIME_66MHZ*/);
1083 bnx_blockinit(struct bnx_softc *sc)
1085 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0];
1086 struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0];
1087 struct bge_rcb *rcb;
1094 * Initialize the memory window pointer register so that
1095 * we can access the first 32K of internal NIC RAM. This will
1096 * allow us to set up the TX send ring RCBs and the RX return
1097 * ring RCBs, plus other things which live in NIC memory.
1099 CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0);
1101 /* Configure mbuf pool watermarks */
1102 if (BNX_IS_57765_PLUS(sc)) {
1103 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
1104 if (sc->arpcom.ac_if.if_mtu > ETHERMTU) {
1105 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x7e);
1106 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xea);
1108 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x2a);
1109 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0xa0);
1112 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
1113 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10);
1114 CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
1117 /* Configure DMA resource watermarks */
1118 CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5);
1119 CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10);
1121 /* Enable buffer manager */
1122 val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN;
1124 * Change the arbitration algorithm of TXMBUF read request to
1125 * round-robin instead of priority based for BCM5719. When
1126 * TXFIFO is almost empty, RDMA will hold its request until
1127 * TXFIFO is not almost empty.
1129 if (sc->bnx_asicrev == BGE_ASICREV_BCM5719)
1130 val |= BGE_BMANMODE_NO_TX_UNDERRUN;
1131 if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 ||
1132 sc->bnx_chipid == BGE_CHIPID_BCM5719_A0 ||
1133 sc->bnx_chipid == BGE_CHIPID_BCM5720_A0)
1134 val |= BGE_BMANMODE_LOMBUF_ATTN;
1135 CSR_WRITE_4(sc, BGE_BMAN_MODE, val);
1137 /* Poll for buffer manager start indication */
1138 for (i = 0; i < BNX_TIMEOUT; i++) {
1139 if (CSR_READ_4(sc, BGE_BMAN_MODE) & BGE_BMANMODE_ENABLE)
1144 if (i == BNX_TIMEOUT) {
1145 if_printf(&sc->arpcom.ac_if,
1146 "buffer manager failed to start\n");
1150 /* Enable flow-through queues */
1151 CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF);
1152 CSR_WRITE_4(sc, BGE_FTQ_RESET, 0);
1154 /* Wait until queue initialization is complete */
1155 for (i = 0; i < BNX_TIMEOUT; i++) {
1156 if (CSR_READ_4(sc, BGE_FTQ_RESET) == 0)
1161 if (i == BNX_TIMEOUT) {
1162 if_printf(&sc->arpcom.ac_if,
1163 "flow-through queue init failed\n");
1168 * Summary of rings supported by the controller:
1170 * Standard Receive Producer Ring
1171 * - This ring is used to feed receive buffers for "standard"
1172 * sized frames (typically 1536 bytes) to the controller.
1174 * Jumbo Receive Producer Ring
1175 * - This ring is used to feed receive buffers for jumbo sized
1176 * frames (i.e. anything bigger than the "standard" frames)
1177 * to the controller.
1179 * Mini Receive Producer Ring
1180 * - This ring is used to feed receive buffers for "mini"
1181 * sized frames to the controller.
1182 * - This feature required external memory for the controller
1183 * but was never used in a production system. Should always
1186 * Receive Return Ring
1187 * - After the controller has placed an incoming frame into a
1188 * receive buffer that buffer is moved into a receive return
1189 * ring. The driver is then responsible to passing the
1190 * buffer up to the stack. Many versions of the controller
1191 * support multiple RR rings.
1194 * - This ring is used for outgoing frames. Many versions of
1195 * the controller support multiple send rings.
1198 /* Initialize the standard receive producer ring control block. */
1199 rcb = &sc->bnx_ldata.bnx_info.bnx_std_rx_rcb;
1200 rcb->bge_hostaddr.bge_addr_lo =
1201 BGE_ADDR_LO(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr);
1202 rcb->bge_hostaddr.bge_addr_hi =
1203 BGE_ADDR_HI(sc->bnx_rx_std_ring.bnx_rx_std_ring_paddr);
1204 if (BNX_IS_57765_PLUS(sc)) {
1206 * Bits 31-16: Programmable ring size (2048, 1024, 512, .., 32)
1207 * Bits 15-2 : Maximum RX frame size
1208 * Bit 1 : 1 = Ring Disabled, 0 = Ring ENabled
1211 rcb->bge_maxlen_flags =
1212 BGE_RCB_MAXLEN_FLAGS(512, BNX_MAX_FRAMELEN << 2);
1215 * Bits 31-16: Programmable ring size (512, 256, 128, 64, 32)
1216 * Bits 15-2 : Reserved (should be 0)
1217 * Bit 1 : 1 = Ring Disabled, 0 = Ring Enabled
1220 rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(512, 0);
1222 if (BNX_IS_5717_PLUS(sc))
1223 rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717;
1225 rcb->bge_nicaddr = BGE_STD_RX_RINGS;
1226 /* Write the standard receive producer ring control block. */
1227 CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi);
1228 CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo);
1229 CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
1230 CSR_WRITE_4(sc, BGE_RX_STD_RCB_NICADDR, rcb->bge_nicaddr);
1231 /* Reset the standard receive producer ring producer index. */
1232 bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0);
1235 * Initialize the jumbo RX producer ring control
1236 * block. We set the 'ring disabled' bit in the
1237 * flags field until we're actually ready to start
1238 * using this ring (i.e. once we set the MTU
1239 * high enough to require it).
1241 if (BNX_IS_JUMBO_CAPABLE(sc)) {
1242 rcb = &sc->bnx_ldata.bnx_info.bnx_jumbo_rx_rcb;
1243 /* Get the jumbo receive producer ring RCB parameters. */
1244 rcb->bge_hostaddr.bge_addr_lo =
1245 BGE_ADDR_LO(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr);
1246 rcb->bge_hostaddr.bge_addr_hi =
1247 BGE_ADDR_HI(sc->bnx_ldata.bnx_rx_jumbo_ring_paddr);
1248 rcb->bge_maxlen_flags =
1249 BGE_RCB_MAXLEN_FLAGS(BNX_MAX_FRAMELEN,
1250 BGE_RCB_FLAG_RING_DISABLED);
1251 if (BNX_IS_5717_PLUS(sc))
1252 rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717;
1254 rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS;
1255 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI,
1256 rcb->bge_hostaddr.bge_addr_hi);
1257 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO,
1258 rcb->bge_hostaddr.bge_addr_lo);
1259 /* Program the jumbo receive producer ring RCB parameters. */
1260 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS,
1261 rcb->bge_maxlen_flags);
1262 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr);
1263 /* Reset the jumbo receive producer ring producer index. */
1264 bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0);
1268 * The BD ring replenish thresholds control how often the
1269 * hardware fetches new BD's from the producer rings in host
1270 * memory. Setting the value too low on a busy system can
1271 * starve the hardware and recue the throughpout.
1273 * Set the BD ring replentish thresholds. The recommended
1274 * values are 1/8th the number of descriptors allocated to
1278 CSR_WRITE_4(sc, BGE_RBDI_STD_REPL_THRESH, val);
1279 if (BNX_IS_JUMBO_CAPABLE(sc)) {
1280 CSR_WRITE_4(sc, BGE_RBDI_JUMBO_REPL_THRESH,
1281 BGE_JUMBO_RX_RING_CNT/8);
1283 if (BNX_IS_57765_PLUS(sc)) {
1284 CSR_WRITE_4(sc, BGE_STD_REPLENISH_LWM, 32);
1285 CSR_WRITE_4(sc, BGE_JMB_REPLENISH_LWM, 16);
1289 * Disable all send rings by setting the 'ring disabled' bit
1290 * in the flags field of all the TX send ring control blocks,
1291 * located in NIC memory.
1293 if (BNX_IS_5717_PLUS(sc))
1295 else if (BNX_IS_57765_FAMILY(sc) ||
1296 sc->bnx_asicrev == BGE_ASICREV_BCM5762)
1300 vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB;
1301 for (i = 0; i < limit; i++) {
1302 RCB_WRITE_4(sc, vrcb, bge_maxlen_flags,
1303 BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED));
1304 RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0);
1305 vrcb += sizeof(struct bge_rcb);
1308 /* Configure send ring RCB 0 (we use only the first ring) */
1309 vrcb = BGE_MEMWIN_START + BGE_SEND_RING_RCB;
1310 BGE_HOSTADDR(taddr, txr->bnx_tx_ring_paddr);
1311 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi);
1312 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo);
1313 if (BNX_IS_5717_PLUS(sc)) {
1314 RCB_WRITE_4(sc, vrcb, bge_nicaddr, BGE_SEND_RING_5717);
1316 RCB_WRITE_4(sc, vrcb, bge_nicaddr,
1317 BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT));
1319 RCB_WRITE_4(sc, vrcb, bge_maxlen_flags,
1320 BGE_RCB_MAXLEN_FLAGS(BGE_TX_RING_CNT, 0));
1323 * Disable all receive return rings by setting the
1324 * 'ring disabled' bit in the flags field of all the receive
1325 * return ring control blocks, located in NIC memory.
1327 if (BNX_IS_5717_PLUS(sc)) {
1328 /* Should be 17, use 16 until we get an SRAM map. */
1330 } else if (BNX_IS_57765_FAMILY(sc) ||
1331 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
1336 /* Disable all receive return rings. */
1337 vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB;
1338 for (i = 0; i < limit; i++) {
1339 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, 0);
1340 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, 0);
1341 RCB_WRITE_4(sc, vrcb, bge_maxlen_flags,
1342 BGE_RCB_FLAG_RING_DISABLED);
1343 RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0);
1344 bnx_writembx(sc, BGE_MBX_RX_CONS0_LO +
1345 (i * (sizeof(uint64_t))), 0);
1346 vrcb += sizeof(struct bge_rcb);
1350 * Set up receive return ring 0. Note that the NIC address
1351 * for RX return rings is 0x0. The return rings live entirely
1352 * within the host, so the nicaddr field in the RCB isn't used.
1354 vrcb = BGE_MEMWIN_START + BGE_RX_RETURN_RING_RCB;
1355 BGE_HOSTADDR(taddr, ret->bnx_rx_ret_ring_paddr);
1356 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi);
1357 RCB_WRITE_4(sc, vrcb, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo);
1358 RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0);
1359 RCB_WRITE_4(sc, vrcb, bge_maxlen_flags,
1360 BGE_RCB_MAXLEN_FLAGS(BNX_RETURN_RING_CNT, 0));
1362 /* Set random backoff seed for TX */
1363 CSR_WRITE_4(sc, BGE_TX_RANDOM_BACKOFF,
1364 sc->arpcom.ac_enaddr[0] + sc->arpcom.ac_enaddr[1] +
1365 sc->arpcom.ac_enaddr[2] + sc->arpcom.ac_enaddr[3] +
1366 sc->arpcom.ac_enaddr[4] + sc->arpcom.ac_enaddr[5] +
1367 BGE_TX_BACKOFF_SEED_MASK);
1369 /* Set inter-packet gap */
1371 if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
1372 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
1373 val |= CSR_READ_4(sc, BGE_TX_LENGTHS) &
1374 (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK);
1376 CSR_WRITE_4(sc, BGE_TX_LENGTHS, val);
1379 * Specify which ring to use for packets that don't match
1382 CSR_WRITE_4(sc, BGE_RX_RULES_CFG, 0x08);
1385 * Configure number of RX lists. One interrupt distribution
1386 * list, sixteen active lists, one bad frames class.
1388 CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181);
1390 /* Inialize RX list placement stats mask. */
1391 CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF);
1392 CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1);
1394 /* Disable host coalescing until we get it set up */
1395 CSR_WRITE_4(sc, BGE_HCC_MODE, 0x00000000);
1397 /* Poll to make sure it's shut down. */
1398 for (i = 0; i < BNX_TIMEOUT; i++) {
1399 if (!(CSR_READ_4(sc, BGE_HCC_MODE) & BGE_HCCMODE_ENABLE))
1404 if (i == BNX_TIMEOUT) {
1405 if_printf(&sc->arpcom.ac_if,
1406 "host coalescing engine failed to idle\n");
1410 /* Set up host coalescing defaults */
1411 CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS, sc->bnx_rx_coal_ticks);
1412 CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bnx_tx_coal_ticks);
1413 CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bnx_rx_coal_bds);
1414 CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bnx_tx_coal_bds);
1415 CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT, sc->bnx_rx_coal_bds_int);
1416 CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, sc->bnx_tx_coal_bds_int);
1418 /* Set up address of status block */
1419 bzero(sc->bnx_ldata.bnx_status_block, BGE_STATUS_BLK_SZ);
1420 CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_HI,
1421 BGE_ADDR_HI(sc->bnx_ldata.bnx_status_block_paddr));
1422 CSR_WRITE_4(sc, BGE_HCC_STATUSBLK_ADDR_LO,
1423 BGE_ADDR_LO(sc->bnx_ldata.bnx_status_block_paddr));
1425 /* Set up status block partail update size. */
1426 val = BGE_STATBLKSZ_32BYTE;
1429 * Does not seem to have visible effect in both
1430 * bulk data (1472B UDP datagram) and tiny data
1431 * (18B UDP datagram) TX tests.
1433 val |= BGE_HCCMODE_CLRTICK_TX;
1435 /* Turn on host coalescing state machine */
1436 CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE);
1438 /* Turn on RX BD completion state machine and enable attentions */
1439 CSR_WRITE_4(sc, BGE_RBDC_MODE,
1440 BGE_RBDCMODE_ENABLE|BGE_RBDCMODE_ATTN);
1442 /* Turn on RX list placement state machine */
1443 CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE);
1445 val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB |
1446 BGE_MACMODE_RX_STATS_CLEAR | BGE_MACMODE_TX_STATS_CLEAR |
1447 BGE_MACMODE_RX_STATS_ENB | BGE_MACMODE_TX_STATS_ENB |
1448 BGE_MACMODE_FRMHDR_DMA_ENB;
1450 if (sc->bnx_flags & BNX_FLAG_TBI)
1451 val |= BGE_PORTMODE_TBI;
1452 else if (sc->bnx_flags & BNX_FLAG_MII_SERDES)
1453 val |= BGE_PORTMODE_GMII;
1455 val |= BGE_PORTMODE_MII;
1457 /* Turn on DMA, clear stats */
1458 CSR_WRITE_4(sc, BGE_MAC_MODE, val);
1460 /* Set misc. local control, enable interrupts on attentions */
1461 CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN);
1464 /* Assert GPIO pins for PHY reset */
1465 BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUT0|
1466 BGE_MLC_MISCIO_OUT1|BGE_MLC_MISCIO_OUT2);
1467 BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_MISCIO_OUTEN0|
1468 BGE_MLC_MISCIO_OUTEN1|BGE_MLC_MISCIO_OUTEN2);
1471 /* Turn on write DMA state machine */
1472 val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS;
1473 /* Enable host coalescing bug fix. */
1474 val |= BGE_WDMAMODE_STATUS_TAG_FIX;
1475 if (sc->bnx_asicrev == BGE_ASICREV_BCM5785) {
1476 /* Request larger DMA burst size to get better performance. */
1477 val |= BGE_WDMAMODE_BURST_ALL_DATA;
1479 CSR_WRITE_4(sc, BGE_WDMA_MODE, val);
1482 if (BNX_IS_57765_PLUS(sc)) {
1483 uint32_t dmactl, dmactl_reg;
1485 if (sc->bnx_asicrev == BGE_ASICREV_BCM5762)
1486 dmactl_reg = BGE_RDMA_RSRVCTRL2;
1488 dmactl_reg = BGE_RDMA_RSRVCTRL;
1490 dmactl = CSR_READ_4(sc, dmactl_reg);
1492 * Adjust tx margin to prevent TX data corruption and
1493 * fix internal FIFO overflow.
1495 if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 ||
1496 sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
1497 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
1498 dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK |
1499 BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK |
1500 BGE_RDMA_RSRVCTRL_TXMRGN_MASK);
1501 dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K |
1502 BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K |
1503 BGE_RDMA_RSRVCTRL_TXMRGN_320B;
1506 * Enable fix for read DMA FIFO overruns.
1507 * The fix is to limit the number of RX BDs
1508 * the hardware would fetch at a fime.
1510 CSR_WRITE_4(sc, dmactl_reg,
1511 dmactl | BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX);
1514 if (sc->bnx_asicrev == BGE_ASICREV_BCM5719) {
1515 CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL,
1516 CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) |
1517 BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K |
1518 BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K);
1519 } else if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
1520 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
1523 if (sc->bnx_asicrev == BGE_ASICREV_BCM5762)
1524 ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL2;
1526 ctrl_reg = BGE_RDMA_LSO_CRPTEN_CTRL;
1529 * Allow 4KB burst length reads for non-LSO frames.
1530 * Enable 512B burst length reads for buffer descriptors.
1532 CSR_WRITE_4(sc, ctrl_reg,
1533 CSR_READ_4(sc, ctrl_reg) |
1534 BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 |
1535 BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K);
1538 /* Turn on read DMA state machine */
1539 val = BGE_RDMAMODE_ENABLE | BGE_RDMAMODE_ALL_ATTNS;
1540 if (sc->bnx_asicrev == BGE_ASICREV_BCM5717)
1541 val |= BGE_RDMAMODE_MULT_DMA_RD_DIS;
1542 if (sc->bnx_asicrev == BGE_ASICREV_BCM5784 ||
1543 sc->bnx_asicrev == BGE_ASICREV_BCM5785 ||
1544 sc->bnx_asicrev == BGE_ASICREV_BCM57780) {
1545 val |= BGE_RDMAMODE_BD_SBD_CRPT_ATTN |
1546 BGE_RDMAMODE_MBUF_RBD_CRPT_ATTN |
1547 BGE_RDMAMODE_MBUF_SBD_CRPT_ATTN;
1549 if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
1550 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
1551 val |= CSR_READ_4(sc, BGE_RDMA_MODE) &
1552 BGE_RDMAMODE_H2BNC_VLAN_DET;
1554 * Allow multiple outstanding read requests from
1555 * non-LSO read DMA engine.
1557 val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS;
1559 if (sc->bnx_asicrev == BGE_ASICREV_BCM57766)
1560 val |= BGE_RDMAMODE_JMB_2K_MMRR;
1561 if (sc->bnx_flags & BNX_FLAG_TSO)
1562 val |= BGE_RDMAMODE_TSO4_ENABLE;
1563 val |= BGE_RDMAMODE_FIFO_LONG_BURST;
1564 CSR_WRITE_4(sc, BGE_RDMA_MODE, val);
1567 /* Turn on RX data completion state machine */
1568 CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE);
1570 /* Turn on RX BD initiator state machine */
1571 CSR_WRITE_4(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE);
1573 /* Turn on RX data and RX BD initiator state machine */
1574 CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE);
1576 /* Turn on send BD completion state machine */
1577 CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE);
1579 /* Turn on send data completion state machine */
1580 val = BGE_SDCMODE_ENABLE;
1581 if (sc->bnx_asicrev == BGE_ASICREV_BCM5761)
1582 val |= BGE_SDCMODE_CDELAY;
1583 CSR_WRITE_4(sc, BGE_SDC_MODE, val);
1585 /* Turn on send data initiator state machine */
1586 if (sc->bnx_flags & BNX_FLAG_TSO) {
1587 CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE |
1588 BGE_SDIMODE_HW_LSO_PRE_DMA);
1590 CSR_WRITE_4(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE);
1593 /* Turn on send BD initiator state machine */
1594 CSR_WRITE_4(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE);
1596 /* Turn on send BD selector state machine */
1597 CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE);
1599 CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF);
1600 CSR_WRITE_4(sc, BGE_SDI_STATS_CTL,
1601 BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER);
1603 /* ack/clear link change events */
1604 CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED|
1605 BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE|
1606 BGE_MACSTAT_LINK_CHANGED);
1607 CSR_WRITE_4(sc, BGE_MI_STS, 0);
1610 * Enable attention when the link has changed state for
1611 * devices that use auto polling.
1613 if (sc->bnx_flags & BNX_FLAG_TBI) {
1614 CSR_WRITE_4(sc, BGE_MI_STS, BGE_MISTS_LINK);
1616 if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
1617 CSR_WRITE_4(sc, BGE_MI_MODE, sc->bnx_mi_mode);
1623 * Clear any pending link state attention.
1624 * Otherwise some link state change events may be lost until attention
1625 * is cleared by bnx_intr() -> bnx_softc.bnx_link_upd() sequence.
1626 * It's not necessary on newer BCM chips - perhaps enabling link
1627 * state change attentions implies clearing pending attention.
1629 CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED|
1630 BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE|
1631 BGE_MACSTAT_LINK_CHANGED);
1633 /* Enable link state change attentions. */
1634 BNX_SETBIT(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_LINK_CHANGED);
1640 * Probe for a Broadcom chip. Check the PCI vendor and device IDs
1641 * against our list and return its name if we find a match. Note
1642 * that since the Broadcom controller contains VPD support, we
1643 * can get the device name string from the controller itself instead
1644 * of the compiled-in string. This is a little slow, but it guarantees
1645 * we'll always announce the right product name.
1648 bnx_probe(device_t dev)
1650 const struct bnx_type *t;
1651 uint16_t product, vendor;
1653 if (!pci_is_pcie(dev))
1656 product = pci_get_device(dev);
1657 vendor = pci_get_vendor(dev);
1659 for (t = bnx_devs; t->bnx_name != NULL; t++) {
1660 if (vendor == t->bnx_vid && product == t->bnx_did)
1663 if (t->bnx_name == NULL)
1666 device_set_desc(dev, t->bnx_name);
1671 bnx_attach(device_t dev)
1674 struct bnx_softc *sc;
1676 int error = 0, rid, capmask;
1677 uint8_t ether_addr[ETHER_ADDR_LEN];
1679 uintptr_t mii_priv = 0;
1680 #ifdef BNX_TSO_DEBUG
1685 sc = device_get_softc(dev);
1687 callout_init_mp(&sc->bnx_stat_timer);
1688 callout_init_mp(&sc->bnx_intr_timer);
1689 lwkt_serialize_init(&sc->bnx_jslot_serializer);
1691 product = pci_get_device(dev);
1693 #ifndef BURN_BRIDGES
1694 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
1697 irq = pci_read_config(dev, PCIR_INTLINE, 4);
1698 mem = pci_read_config(dev, BGE_PCI_BAR0, 4);
1700 device_printf(dev, "chip is in D%d power mode "
1701 "-- setting to D0\n", pci_get_powerstate(dev));
1703 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
1705 pci_write_config(dev, PCIR_INTLINE, irq, 4);
1706 pci_write_config(dev, BGE_PCI_BAR0, mem, 4);
1708 #endif /* !BURN_BRIDGE */
1711 * Map control/status registers.
1713 pci_enable_busmaster(dev);
1716 sc->bnx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
1719 if (sc->bnx_res == NULL) {
1720 device_printf(dev, "couldn't map memory\n");
1724 sc->bnx_btag = rman_get_bustag(sc->bnx_res);
1725 sc->bnx_bhandle = rman_get_bushandle(sc->bnx_res);
1727 /* Save various chip information */
1729 pci_read_config(dev, BGE_PCI_MISC_CTL, 4) >>
1730 BGE_PCIMISCCTL_ASICREV_SHIFT;
1731 if (BGE_ASICREV(sc->bnx_chipid) == BGE_ASICREV_USE_PRODID_REG) {
1732 /* All chips having dedicated ASICREV register have CPMU */
1733 sc->bnx_flags |= BNX_FLAG_CPMU;
1736 case PCI_PRODUCT_BROADCOM_BCM5717:
1737 case PCI_PRODUCT_BROADCOM_BCM5717C:
1738 case PCI_PRODUCT_BROADCOM_BCM5718:
1739 case PCI_PRODUCT_BROADCOM_BCM5719:
1740 case PCI_PRODUCT_BROADCOM_BCM5720_ALT:
1741 case PCI_PRODUCT_BROADCOM_BCM5725:
1742 case PCI_PRODUCT_BROADCOM_BCM5727:
1743 case PCI_PRODUCT_BROADCOM_BCM5762:
1744 sc->bnx_chipid = pci_read_config(dev,
1745 BGE_PCI_GEN2_PRODID_ASICREV, 4);
1748 case PCI_PRODUCT_BROADCOM_BCM57761:
1749 case PCI_PRODUCT_BROADCOM_BCM57762:
1750 case PCI_PRODUCT_BROADCOM_BCM57765:
1751 case PCI_PRODUCT_BROADCOM_BCM57766:
1752 case PCI_PRODUCT_BROADCOM_BCM57781:
1753 case PCI_PRODUCT_BROADCOM_BCM57782:
1754 case PCI_PRODUCT_BROADCOM_BCM57785:
1755 case PCI_PRODUCT_BROADCOM_BCM57786:
1756 case PCI_PRODUCT_BROADCOM_BCM57791:
1757 case PCI_PRODUCT_BROADCOM_BCM57795:
1758 sc->bnx_chipid = pci_read_config(dev,
1759 BGE_PCI_GEN15_PRODID_ASICREV, 4);
1763 sc->bnx_chipid = pci_read_config(dev,
1764 BGE_PCI_PRODID_ASICREV, 4);
1768 if (sc->bnx_chipid == BGE_CHIPID_BCM5717_C0)
1769 sc->bnx_chipid = BGE_CHIPID_BCM5720_A0;
1771 sc->bnx_asicrev = BGE_ASICREV(sc->bnx_chipid);
1772 sc->bnx_chiprev = BGE_CHIPREV(sc->bnx_chipid);
1774 switch (sc->bnx_asicrev) {
1775 case BGE_ASICREV_BCM5717:
1776 case BGE_ASICREV_BCM5719:
1777 case BGE_ASICREV_BCM5720:
1778 sc->bnx_flags |= BNX_FLAG_5717_PLUS | BNX_FLAG_57765_PLUS;
1781 case BGE_ASICREV_BCM5762:
1782 sc->bnx_flags |= BNX_FLAG_57765_PLUS;
1785 case BGE_ASICREV_BCM57765:
1786 case BGE_ASICREV_BCM57766:
1787 sc->bnx_flags |= BNX_FLAG_57765_FAMILY | BNX_FLAG_57765_PLUS;
1791 sc->bnx_flags |= BNX_FLAG_TSO;
1792 if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 &&
1793 sc->bnx_chipid == BGE_CHIPID_BCM5719_A0)
1794 sc->bnx_flags &= ~BNX_FLAG_TSO;
1796 if (sc->bnx_asicrev == BGE_ASICREV_BCM5717 ||
1797 BNX_IS_57765_FAMILY(sc)) {
1799 * All BCM57785 and BCM5718 families chips have a bug that
1800 * under certain situation interrupt will not be enabled
1801 * even if status tag is written to BGE_MBX_IRQ0_LO mailbox.
1803 * While BCM5719 and BCM5720 have a hardware workaround
1804 * which could fix the above bug.
1805 * See the comment near BGE_PCIDMARWCTL_TAGGED_STATUS_WA in
1808 * For the rest of the chips in these two families, we will
1809 * have to poll the status block at high rate (10ms currently)
1810 * to check whether the interrupt is hosed or not.
1811 * See bnx_intr_check() for details.
1813 sc->bnx_flags |= BNX_FLAG_STATUSTAG_BUG;
1816 sc->bnx_pciecap = pci_get_pciecap_ptr(sc->bnx_dev);
1817 if (sc->bnx_asicrev == BGE_ASICREV_BCM5719 ||
1818 sc->bnx_asicrev == BGE_ASICREV_BCM5720)
1819 pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_2048);
1821 pcie_set_max_readrq(dev, PCIEM_DEVCTL_MAX_READRQ_4096);
1822 device_printf(dev, "CHIP ID 0x%08x; "
1823 "ASIC REV 0x%02x; CHIP REV 0x%02x\n",
1824 sc->bnx_chipid, sc->bnx_asicrev, sc->bnx_chiprev);
1827 * Set various PHY quirk flags.
1830 capmask = MII_CAPMASK_DEFAULT;
1831 if (product == PCI_PRODUCT_BROADCOM_BCM57791 ||
1832 product == PCI_PRODUCT_BROADCOM_BCM57795) {
1834 capmask &= ~BMSR_EXTSTAT;
1837 mii_priv |= BRGPHY_FLAG_WIRESPEED;
1838 if (sc->bnx_chipid == BGE_CHIPID_BCM5762_A0)
1839 mii_priv |= BRGPHY_FLAG_5762_A0;
1841 /* Initialize if_name earlier, so if_printf could be used */
1842 ifp = &sc->arpcom.ac_if;
1843 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1845 /* Try to reset the chip. */
1848 if (bnx_chipinit(sc)) {
1849 device_printf(dev, "chip initialization failed\n");
1855 * Get station address
1857 error = bnx_get_eaddr(sc, ether_addr);
1859 device_printf(dev, "failed to read station address\n");
1864 sc->bnx_tx_ringcnt = 1;
1865 sc->bnx_rx_retcnt = 1;
1867 error = bnx_dma_alloc(dev);
1872 * Allocate interrupt
1874 error = bnx_alloc_intr(sc);
1878 /* Set default tuneable values. */
1879 sc->bnx_rx_coal_ticks = BNX_RX_COAL_TICKS_DEF;
1880 sc->bnx_tx_coal_ticks = BNX_TX_COAL_TICKS_DEF;
1881 sc->bnx_rx_coal_bds = BNX_RX_COAL_BDS_DEF;
1882 sc->bnx_tx_coal_bds = BNX_TX_COAL_BDS_DEF;
1883 sc->bnx_rx_coal_bds_int = BNX_RX_COAL_BDS_INT_DEF;
1884 sc->bnx_tx_coal_bds_int = BNX_TX_COAL_BDS_INT_DEF;
1886 /* Set up ifnet structure */
1888 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1889 ifp->if_ioctl = bnx_ioctl;
1890 ifp->if_start = bnx_start;
1891 #ifdef IFPOLL_ENABLE
1892 ifp->if_npoll = bnx_npoll;
1894 ifp->if_watchdog = bnx_watchdog;
1895 ifp->if_init = bnx_init;
1896 ifp->if_mtu = ETHERMTU;
1897 ifp->if_capabilities = IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
1898 ifq_set_maxlen(&ifp->if_snd, BGE_TX_RING_CNT - 1);
1899 ifq_set_ready(&ifp->if_snd);
1901 ifp->if_capabilities |= IFCAP_HWCSUM;
1902 ifp->if_hwassist = BNX_CSUM_FEATURES;
1903 if (sc->bnx_flags & BNX_FLAG_TSO) {
1904 ifp->if_capabilities |= IFCAP_TSO;
1905 ifp->if_hwassist |= CSUM_TSO;
1907 ifp->if_capenable = ifp->if_capabilities;
1910 * Figure out what sort of media we have by checking the
1911 * hardware config word in the first 32k of NIC internal memory,
1912 * or fall back to examining the EEPROM if necessary.
1913 * Note: on some BCM5700 cards, this value appears to be unset.
1914 * If that's the case, we have to rely on identifying the NIC
1915 * by its PCI subsystem ID, as we do below for the SysKonnect
1918 if (bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER) {
1919 hwcfg = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG);
1921 if (bnx_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET,
1923 device_printf(dev, "failed to read EEPROM\n");
1927 hwcfg = ntohl(hwcfg);
1930 /* The SysKonnect SK-9D41 is a 1000baseSX card. */
1931 if (pci_get_subvendor(dev) == PCI_PRODUCT_SCHNEIDERKOCH_SK_9D41 ||
1932 (hwcfg & BGE_HWCFG_MEDIA) == BGE_MEDIA_FIBER)
1933 sc->bnx_flags |= BNX_FLAG_TBI;
1936 if (sc->bnx_flags & BNX_FLAG_CPMU)
1937 sc->bnx_mi_mode = BGE_MIMODE_500KHZ_CONST;
1939 sc->bnx_mi_mode = BGE_MIMODE_BASE;
1941 /* Setup link status update stuffs */
1942 if (sc->bnx_flags & BNX_FLAG_TBI) {
1943 sc->bnx_link_upd = bnx_tbi_link_upd;
1944 sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED;
1945 } else if (sc->bnx_mi_mode & BGE_MIMODE_AUTOPOLL) {
1946 sc->bnx_link_upd = bnx_autopoll_link_upd;
1947 sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED;
1949 sc->bnx_link_upd = bnx_copper_link_upd;
1950 sc->bnx_link_chg = BGE_MACSTAT_LINK_CHANGED;
1953 /* Set default PHY address */
1957 * PHY address mapping for various devices.
1959 * | F0 Cu | F0 Sr | F1 Cu | F1 Sr |
1960 * ---------+-------+-------+-------+-------+
1961 * BCM57XX | 1 | X | X | X |
1962 * BCM5704 | 1 | X | 1 | X |
1963 * BCM5717 | 1 | 8 | 2 | 9 |
1964 * BCM5719 | 1 | 8 | 2 | 9 |
1965 * BCM5720 | 1 | 8 | 2 | 9 |
1967 * Other addresses may respond but they are not
1968 * IEEE compliant PHYs and should be ignored.
1970 if (BNX_IS_5717_PLUS(sc)) {
1973 f = pci_get_function(dev);
1974 if (sc->bnx_chipid == BGE_CHIPID_BCM5717_A0) {
1975 if (CSR_READ_4(sc, BGE_SGDIG_STS) &
1976 BGE_SGDIGSTS_IS_SERDES)
1977 sc->bnx_phyno = f + 8;
1979 sc->bnx_phyno = f + 1;
1981 if (CSR_READ_4(sc, BGE_CPMU_PHY_STRAP) &
1982 BGE_CPMU_PHY_STRAP_IS_SERDES)
1983 sc->bnx_phyno = f + 8;
1985 sc->bnx_phyno = f + 1;
1989 if (sc->bnx_flags & BNX_FLAG_TBI) {
1990 ifmedia_init(&sc->bnx_ifmedia, IFM_IMASK,
1991 bnx_ifmedia_upd, bnx_ifmedia_sts);
1992 ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
1993 ifmedia_add(&sc->bnx_ifmedia,
1994 IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
1995 ifmedia_add(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
1996 ifmedia_set(&sc->bnx_ifmedia, IFM_ETHER|IFM_AUTO);
1997 sc->bnx_ifmedia.ifm_media = sc->bnx_ifmedia.ifm_cur->ifm_media;
1999 struct mii_probe_args mii_args;
2001 mii_probe_args_init(&mii_args, bnx_ifmedia_upd, bnx_ifmedia_sts);
2002 mii_args.mii_probemask = 1 << sc->bnx_phyno;
2003 mii_args.mii_capmask = capmask;
2004 mii_args.mii_privtag = MII_PRIVTAG_BRGPHY;
2005 mii_args.mii_priv = mii_priv;
2007 error = mii_probe(dev, &sc->bnx_miibus, &mii_args);
2009 device_printf(dev, "MII without any PHY!\n");
2015 * Create sysctl nodes.
2017 sysctl_ctx_init(&sc->bnx_sysctl_ctx);
2018 sc->bnx_sysctl_tree = SYSCTL_ADD_NODE(&sc->bnx_sysctl_ctx,
2019 SYSCTL_STATIC_CHILDREN(_hw),
2021 device_get_nameunit(dev),
2023 if (sc->bnx_sysctl_tree == NULL) {
2024 device_printf(dev, "can't add sysctl node\n");
2029 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2030 SYSCTL_CHILDREN(sc->bnx_sysctl_tree),
2031 OID_AUTO, "rx_coal_ticks",
2032 CTLTYPE_INT | CTLFLAG_RW,
2033 sc, 0, bnx_sysctl_rx_coal_ticks, "I",
2034 "Receive coalescing ticks (usec).");
2035 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2036 SYSCTL_CHILDREN(sc->bnx_sysctl_tree),
2037 OID_AUTO, "tx_coal_ticks",
2038 CTLTYPE_INT | CTLFLAG_RW,
2039 sc, 0, bnx_sysctl_tx_coal_ticks, "I",
2040 "Transmit coalescing ticks (usec).");
2041 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2042 SYSCTL_CHILDREN(sc->bnx_sysctl_tree),
2043 OID_AUTO, "rx_coal_bds",
2044 CTLTYPE_INT | CTLFLAG_RW,
2045 sc, 0, bnx_sysctl_rx_coal_bds, "I",
2046 "Receive max coalesced BD count.");
2047 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2048 SYSCTL_CHILDREN(sc->bnx_sysctl_tree),
2049 OID_AUTO, "tx_coal_bds",
2050 CTLTYPE_INT | CTLFLAG_RW,
2051 sc, 0, bnx_sysctl_tx_coal_bds, "I",
2052 "Transmit max coalesced BD count.");
2054 * A common design characteristic for many Broadcom
2055 * client controllers is that they only support a
2056 * single outstanding DMA read operation on the PCIe
2057 * bus. This means that it will take twice as long to
2058 * fetch a TX frame that is split into header and
2059 * payload buffers as it does to fetch a single,
2060 * contiguous TX frame (2 reads vs. 1 read). For these
2061 * controllers, coalescing buffers to reduce the number
2062 * of memory reads is effective way to get maximum
2063 * performance(about 940Mbps). Without collapsing TX
2064 * buffers the maximum TCP bulk transfer performance
2065 * is about 850Mbps. However forcing coalescing mbufs
2066 * consumes a lot of CPU cycles, so leave it off by
2069 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2070 SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO,
2071 "force_defrag", CTLTYPE_INT | CTLFLAG_RW,
2072 sc, 0, bnx_sysctl_force_defrag, "I",
2073 "Force defragment on TX path");
2075 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2076 SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO,
2077 "tx_wreg", CTLTYPE_INT | CTLFLAG_RW,
2078 sc, 0, bnx_sysctl_tx_wreg, "I",
2079 "# of segments before writing to hardware register");
2081 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2082 SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO,
2083 "rx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW,
2084 sc, 0, bnx_sysctl_rx_coal_bds_int, "I",
2085 "Receive max coalesced BD count during interrupt.");
2086 SYSCTL_ADD_PROC(&sc->bnx_sysctl_ctx,
2087 SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO,
2088 "tx_coal_bds_int", CTLTYPE_INT | CTLFLAG_RW,
2089 sc, 0, bnx_sysctl_tx_coal_bds_int, "I",
2090 "Transmit max coalesced BD count during interrupt.");
2092 #ifdef BNX_TSO_DEBUG
2093 for (i = 0; i < BNX_TSO_NSTATS; ++i) {
2094 ksnprintf(desc, sizeof(desc), "tso%d", i + 1);
2095 SYSCTL_ADD_ULONG(&sc->bnx_sysctl_ctx,
2096 SYSCTL_CHILDREN(sc->bnx_sysctl_tree), OID_AUTO,
2097 desc, CTLFLAG_RW, &sc->bnx_tsosegs[i], "");
2102 * Call MI attach routine.
2104 ether_ifattach(ifp, ether_addr, NULL);
2106 ifq_set_cpuid(&ifp->if_snd, sc->bnx_intr_cpuid);
2108 #ifdef IFPOLL_ENABLE
2109 ifpoll_compat_setup(&sc->bnx_npoll,
2110 &sc->bnx_sysctl_ctx, sc->bnx_sysctl_tree,
2111 device_get_unit(dev), ifp->if_serializer);
2114 error = bnx_setup_intr(sc);
2116 ether_ifdetach(ifp);
2120 sc->bnx_intr_cpuid = rman_get_cpuid(sc->bnx_irq);
2121 sc->bnx_stat_cpuid = sc->bnx_intr_cpuid;
2130 bnx_detach(device_t dev)
2132 struct bnx_softc *sc = device_get_softc(dev);
2134 if (device_is_attached(dev)) {
2135 struct ifnet *ifp = &sc->arpcom.ac_if;
2137 lwkt_serialize_enter(ifp->if_serializer);
2140 bus_teardown_intr(dev, sc->bnx_irq, sc->bnx_intrhand);
2141 lwkt_serialize_exit(ifp->if_serializer);
2143 ether_ifdetach(ifp);
2146 if (sc->bnx_flags & BNX_FLAG_TBI)
2147 ifmedia_removeall(&sc->bnx_ifmedia);
2149 device_delete_child(dev, sc->bnx_miibus);
2150 bus_generic_detach(dev);
2154 if (sc->bnx_res != NULL) {
2155 bus_release_resource(dev, SYS_RES_MEMORY,
2156 BGE_PCI_BAR0, sc->bnx_res);
2159 if (sc->bnx_sysctl_tree != NULL)
2160 sysctl_ctx_free(&sc->bnx_sysctl_ctx);
2168 bnx_reset(struct bnx_softc *sc)
2171 uint32_t cachesize, command, pcistate, reset;
2172 void (*write_op)(struct bnx_softc *, uint32_t, uint32_t);
2178 write_op = bnx_writemem_direct;
2180 /* Save some important PCI state. */
2181 cachesize = pci_read_config(dev, BGE_PCI_CACHESZ, 4);
2182 command = pci_read_config(dev, BGE_PCI_CMD, 4);
2183 pcistate = pci_read_config(dev, BGE_PCI_PCISTATE, 4);
2185 pci_write_config(dev, BGE_PCI_MISC_CTL,
2186 BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR|
2187 BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW|
2188 BGE_PCIMISCCTL_TAGGED_STATUS, 4);
2190 /* Disable fastboot on controllers that support it. */
2192 if_printf(&sc->arpcom.ac_if, "Disabling fastboot\n");
2193 CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0x0);
2196 * Write the magic number to SRAM at offset 0xB50.
2197 * When firmware finishes its initialization it will
2198 * write ~BGE_MAGIC_NUMBER to the same location.
2200 bnx_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER);
2202 reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1);
2204 /* XXX: Broadcom Linux driver. */
2205 /* Force PCI-E 1.0a mode */
2206 if (!BNX_IS_57765_PLUS(sc) &&
2207 CSR_READ_4(sc, BGE_PCIE_PHY_TSTCTL) ==
2208 (BGE_PCIE_PHY_TSTCTL_PSCRAM |
2209 BGE_PCIE_PHY_TSTCTL_PCIE10)) {
2210 CSR_WRITE_4(sc, BGE_PCIE_PHY_TSTCTL,
2211 BGE_PCIE_PHY_TSTCTL_PSCRAM);
2213 if (sc->bnx_chipid != BGE_CHIPID_BCM5750_A0) {
2214 /* Prevent PCIE link training during global reset */
2215 CSR_WRITE_4(sc, BGE_MISC_CFG, (1<<29));
2220 * Set GPHY Power Down Override to leave GPHY
2221 * powered up in D0 uninitialized.
2223 if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0)
2224 reset |= BGE_MISCCFG_GPHY_PD_OVERRIDE;
2226 /* Issue global reset */
2227 write_op(sc, BGE_MISC_CFG, reset);
2231 /* XXX: Broadcom Linux driver. */
2232 if (sc->bnx_chipid == BGE_CHIPID_BCM5750_A0) {
2235 DELAY(500000); /* wait for link training to complete */
2236 v = pci_read_config(dev, 0xc4, 4);
2237 pci_write_config(dev, 0xc4, v | (1<<15), 4);
2240 devctl = pci_read_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL, 2);
2242 /* Disable no snoop and disable relaxed ordering. */
2243 devctl &= ~(PCIEM_DEVCTL_RELAX_ORDER | PCIEM_DEVCTL_NOSNOOP);
2245 /* Old PCI-E chips only support 128 bytes Max PayLoad Size. */
2246 if ((sc->bnx_flags & BNX_FLAG_CPMU) == 0) {
2247 devctl &= ~PCIEM_DEVCTL_MAX_PAYLOAD_MASK;
2248 devctl |= PCIEM_DEVCTL_MAX_PAYLOAD_128;
2251 pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVCTRL,
2254 /* Clear error status. */
2255 pci_write_config(dev, sc->bnx_pciecap + PCIER_DEVSTS,
2256 PCIEM_DEVSTS_CORR_ERR |
2257 PCIEM_DEVSTS_NFATAL_ERR |
2258 PCIEM_DEVSTS_FATAL_ERR |
2259 PCIEM_DEVSTS_UNSUPP_REQ, 2);
2261 /* Reset some of the PCI state that got zapped by reset */
2262 pci_write_config(dev, BGE_PCI_MISC_CTL,
2263 BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR|
2264 BGE_HIF_SWAP_OPTIONS|BGE_PCIMISCCTL_PCISTATE_RW|
2265 BGE_PCIMISCCTL_TAGGED_STATUS, 4);
2266 pci_write_config(dev, BGE_PCI_CACHESZ, cachesize, 4);
2267 pci_write_config(dev, BGE_PCI_CMD, command, 4);
2268 write_op(sc, BGE_MISC_CFG, (65 << 1));
2270 /* Enable memory arbiter */
2271 CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE);
2274 * Poll until we see the 1's complement of the magic number.
2275 * This indicates that the firmware initialization is complete.
2277 for (i = 0; i < BNX_FIRMWARE_TIMEOUT; i++) {
2278 val = bnx_readmem_ind(sc, BGE_SOFTWARE_GENCOMM);
2279 if (val == ~BGE_MAGIC_NUMBER)
2283 if (i == BNX_FIRMWARE_TIMEOUT) {
2284 if_printf(&sc->arpcom.ac_if, "firmware handshake "
2285 "timed out, found 0x%08x\n", val);
2288 /* BCM57765 A0 needs additional time before accessing. */
2289 if (sc->bnx_chipid == BGE_CHIPID_BCM57765_A0)
2293 * XXX Wait for the value of the PCISTATE register to
2294 * return to its original pre-reset state. This is a
2295 * fairly good indicator of reset completion. If we don't
2296 * wait for the reset to fully complete, trying to read
2297 * from the device's non-PCI registers may yield garbage
2300 for (i = 0; i < BNX_TIMEOUT; i++) {
2301 if (pci_read_config(dev, BGE_PCI_PCISTATE, 4) == pcistate)
2306 /* Fix up byte swapping */
2307 CSR_WRITE_4(sc, BGE_MODE_CTL, bnx_dma_swap_options(sc));
2309 CSR_WRITE_4(sc, BGE_MAC_MODE, 0);
2312 * The 5704 in TBI mode apparently needs some special
2313 * adjustment to insure the SERDES drive level is set
2316 if (sc->bnx_asicrev == BGE_ASICREV_BCM5704 &&
2317 (sc->bnx_flags & BNX_FLAG_TBI)) {
2320 serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG);
2321 serdescfg = (serdescfg & ~0xFFF) | 0x880;
2322 CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg);
2325 CSR_WRITE_4(sc, BGE_MI_MODE,
2326 sc->bnx_mi_mode & ~BGE_MIMODE_AUTOPOLL);
2329 /* XXX: Broadcom Linux driver. */
2330 if (!BNX_IS_57765_PLUS(sc)) {
2333 /* Enable Data FIFO protection. */
2334 v = CSR_READ_4(sc, BGE_PCIE_TLDLPL_PORT);
2335 CSR_WRITE_4(sc, BGE_PCIE_TLDLPL_PORT, v | (1 << 25));
2340 if (sc->bnx_asicrev == BGE_ASICREV_BCM5720) {
2341 BNX_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE,
2342 CPMU_CLCK_ORIDE_MAC_ORIDE_EN);
2347 * Frame reception handling. This is called if there's a frame
2348 * on the receive return list.
2350 * Note: we have to be able to handle two possibilities here:
2351 * 1) the frame is from the jumbo recieve ring
2352 * 2) the frame is from the standard receive ring
2356 bnx_rxeof(struct bnx_rx_ret_ring *ret, uint16_t rx_prod, int count)
2358 struct bnx_softc *sc = ret->bnx_sc;
2359 struct bnx_rx_std_ring *std = ret->bnx_std;
2360 struct ifnet *ifp = &sc->arpcom.ac_if;
2361 int stdcnt = 0, jumbocnt = 0;
2363 while (ret->bnx_rx_saved_considx != rx_prod && count != 0) {
2364 struct bge_rx_bd *cur_rx;
2366 struct mbuf *m = NULL;
2367 uint16_t vlan_tag = 0;
2372 cur_rx = &ret->bnx_rx_ret_ring[ret->bnx_rx_saved_considx];
2374 rxidx = cur_rx->bge_idx;
2375 BNX_INC(ret->bnx_rx_saved_considx, BNX_RETURN_RING_CNT);
2377 if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) {
2379 vlan_tag = cur_rx->bge_vlan_tag;
2382 if (cur_rx->bge_flags & BGE_RXBDFLAG_JUMBO_RING) {
2383 BNX_INC(sc->bnx_jumbo, BGE_JUMBO_RX_RING_CNT);
2386 if (rxidx != sc->bnx_jumbo) {
2387 IFNET_STAT_INC(ifp, ierrors, 1);
2388 if_printf(ifp, "sw jumbo index(%d) "
2389 "and hw jumbo index(%d) mismatch, drop!\n",
2390 sc->bnx_jumbo, rxidx);
2391 bnx_setup_rxdesc_jumbo(sc, rxidx);
2395 m = sc->bnx_cdata.bnx_rx_jumbo_chain[rxidx].bnx_rx_mbuf;
2396 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
2397 IFNET_STAT_INC(ifp, ierrors, 1);
2398 bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo);
2401 if (bnx_newbuf_jumbo(sc, sc->bnx_jumbo, 0)) {
2402 IFNET_STAT_INC(ifp, ierrors, 1);
2403 bnx_setup_rxdesc_jumbo(sc, sc->bnx_jumbo);
2407 BNX_INC(std->bnx_rx_std, BGE_STD_RX_RING_CNT);
2410 if (rxidx != std->bnx_rx_std) {
2411 IFNET_STAT_INC(ifp, ierrors, 1);
2412 if_printf(ifp, "sw std index(%d) "
2413 "and hw std index(%d) mismatch, drop!\n",
2414 std->bnx_rx_std, rxidx);
2415 bnx_setup_rxdesc_std(std, rxidx);
2419 m = std->bnx_rx_std_buf[rxidx].bnx_rx_mbuf;
2420 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
2421 IFNET_STAT_INC(ifp, ierrors, 1);
2422 bnx_setup_rxdesc_std(std, std->bnx_rx_std);
2425 if (bnx_newbuf_std(ret, std->bnx_rx_std, 0)) {
2426 IFNET_STAT_INC(ifp, ierrors, 1);
2427 bnx_setup_rxdesc_std(std, std->bnx_rx_std);
2432 IFNET_STAT_INC(ifp, ipackets, 1);
2433 m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN;
2434 m->m_pkthdr.rcvif = ifp;
2436 if ((ifp->if_capenable & IFCAP_RXCSUM) &&
2437 (cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) {
2438 if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) {
2439 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
2440 if ((cur_rx->bge_error_flag &
2441 BGE_RXERRFLAG_IP_CSUM_NOK) == 0)
2442 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2444 if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) {
2445 m->m_pkthdr.csum_data =
2446 cur_rx->bge_tcp_udp_csum;
2447 m->m_pkthdr.csum_flags |= CSUM_DATA_VALID |
2453 * If we received a packet with a vlan tag, pass it
2454 * to vlan_input() instead of ether_input().
2457 m->m_flags |= M_VLANTAG;
2458 m->m_pkthdr.ether_vlantag = vlan_tag;
2460 ifp->if_input(ifp, m);
2463 bnx_writembx(sc, BGE_MBX_RX_CONS0_LO, ret->bnx_rx_saved_considx);
2465 bnx_writembx(sc, BGE_MBX_RX_STD_PROD_LO, std->bnx_rx_std);
2467 bnx_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bnx_jumbo);
2471 bnx_txeof(struct bnx_tx_ring *txr, uint16_t tx_cons)
2473 struct ifnet *ifp = &txr->bnx_sc->arpcom.ac_if;
2476 * Go through our tx ring and free mbufs for those
2477 * frames that have been sent.
2479 while (txr->bnx_tx_saved_considx != tx_cons) {
2480 struct bnx_tx_buf *buf;
2483 idx = txr->bnx_tx_saved_considx;
2484 buf = &txr->bnx_tx_buf[idx];
2485 if (buf->bnx_tx_mbuf != NULL) {
2486 IFNET_STAT_INC(ifp, opackets, 1);
2487 bus_dmamap_unload(txr->bnx_tx_mtag,
2488 buf->bnx_tx_dmamap);
2489 m_freem(buf->bnx_tx_mbuf);
2490 buf->bnx_tx_mbuf = NULL;
2493 BNX_INC(txr->bnx_tx_saved_considx, BGE_TX_RING_CNT);
2496 if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) >=
2497 (BNX_NSEG_RSVD + BNX_NSEG_SPARE))
2498 ifq_clr_oactive(&ifp->if_snd);
2500 if (txr->bnx_tx_cnt == 0)
2503 if (!ifq_is_empty(&ifp->if_snd))
2507 #ifdef IFPOLL_ENABLE
2510 bnx_npoll(struct ifnet *ifp, struct ifpoll_info *info)
2512 struct bnx_softc *sc = ifp->if_softc;
2514 ASSERT_SERIALIZED(ifp->if_serializer);
2517 int cpuid = sc->bnx_npoll.ifpc_cpuid;
2519 info->ifpi_rx[cpuid].poll_func = bnx_npoll_compat;
2520 info->ifpi_rx[cpuid].arg = NULL;
2521 info->ifpi_rx[cpuid].serializer = ifp->if_serializer;
2523 if (ifp->if_flags & IFF_RUNNING)
2524 bnx_disable_intr(sc);
2525 ifq_set_cpuid(&ifp->if_snd, cpuid);
2527 if (ifp->if_flags & IFF_RUNNING)
2528 bnx_enable_intr(sc);
2529 ifq_set_cpuid(&ifp->if_snd, sc->bnx_intr_cpuid);
2534 bnx_npoll_compat(struct ifnet *ifp, void *arg __unused, int cycle)
2536 struct bnx_softc *sc = ifp->if_softc;
2537 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */
2538 struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */
2539 struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block;
2540 uint16_t rx_prod, tx_cons;
2542 ASSERT_SERIALIZED(ifp->if_serializer);
2544 if (sc->bnx_npoll.ifpc_stcount-- == 0) {
2545 sc->bnx_npoll.ifpc_stcount = sc->bnx_npoll.ifpc_stfrac;
2547 * Process link state changes.
2552 sc->bnx_status_tag = sblk->bge_status_tag;
2555 * Use a load fence to ensure that status_tag is saved
2556 * before rx_prod and tx_cons.
2560 rx_prod = *ret->bnx_rx_considx;
2561 tx_cons = *txr->bnx_tx_considx;
2563 if (ret->bnx_rx_saved_considx != rx_prod)
2564 bnx_rxeof(ret, rx_prod, cycle);
2566 if (txr->bnx_tx_saved_considx != tx_cons)
2567 bnx_txeof(txr, tx_cons);
2570 #endif /* IFPOLL_ENABLE */
2573 bnx_intr_legacy(void *xsc)
2575 struct bnx_softc *sc = xsc;
2576 struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block;
2578 if (sc->bnx_status_tag == sblk->bge_status_tag) {
2581 val = pci_read_config(sc->bnx_dev, BGE_PCI_PCISTATE, 4);
2582 if (val & BGE_PCISTAT_INTR_NOTACT)
2588 * Interrupt will have to be disabled if tagged status
2589 * is used, else interrupt will always be asserted on
2590 * certain chips (at least on BCM5750 AX/BX).
2592 bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1);
2600 struct bnx_softc *sc = xsc;
2602 /* Disable interrupt first */
2603 bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1);
2608 bnx_msi_oneshot(void *xsc)
2614 bnx_intr(struct bnx_softc *sc)
2616 struct ifnet *ifp = &sc->arpcom.ac_if;
2617 struct bge_status_block *sblk = sc->bnx_ldata.bnx_status_block;
2620 sc->bnx_status_tag = sblk->bge_status_tag;
2622 * Use a load fence to ensure that status_tag is saved
2623 * before rx_prod, tx_cons and status.
2627 status = sblk->bge_status;
2629 if ((status & BGE_STATFLAG_LINKSTATE_CHANGED) || sc->bnx_link_evt)
2632 if (ifp->if_flags & IFF_RUNNING) {
2633 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */
2634 struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */
2635 uint16_t rx_prod, tx_cons;
2637 rx_prod = *ret->bnx_rx_considx;
2638 tx_cons = *txr->bnx_tx_considx;
2640 if (ret->bnx_rx_saved_considx != rx_prod)
2641 bnx_rxeof(ret, rx_prod, -1);
2643 if (txr->bnx_tx_saved_considx != tx_cons)
2644 bnx_txeof(txr, tx_cons);
2647 bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24);
2653 struct bnx_softc *sc = xsc;
2654 struct ifnet *ifp = &sc->arpcom.ac_if;
2656 lwkt_serialize_enter(ifp->if_serializer);
2658 KKASSERT(mycpuid == sc->bnx_stat_cpuid);
2660 bnx_stats_update_regs(sc);
2662 if (sc->bnx_flags & BNX_FLAG_TBI) {
2664 * Since in TBI mode auto-polling can't be used we should poll
2665 * link status manually. Here we register pending link event
2666 * and trigger interrupt.
2669 BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
2670 } else if (!sc->bnx_link) {
2671 mii_tick(device_get_softc(sc->bnx_miibus));
2674 callout_reset(&sc->bnx_stat_timer, hz, bnx_tick, sc);
2676 lwkt_serialize_exit(ifp->if_serializer);
2680 bnx_stats_update_regs(struct bnx_softc *sc)
2682 struct ifnet *ifp = &sc->arpcom.ac_if;
2683 struct bge_mac_stats_regs stats;
2687 s = (uint32_t *)&stats;
2688 for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) {
2689 *s = CSR_READ_4(sc, BGE_RX_STATS + i);
2693 IFNET_STAT_SET(ifp, collisions,
2694 (stats.dot3StatsSingleCollisionFrames +
2695 stats.dot3StatsMultipleCollisionFrames +
2696 stats.dot3StatsExcessiveCollisions +
2697 stats.dot3StatsLateCollisions));
2701 * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data
2702 * pointers to descriptors.
2705 bnx_encap(struct bnx_tx_ring *txr, struct mbuf **m_head0, uint32_t *txidx,
2708 struct bge_tx_bd *d = NULL;
2709 uint16_t csum_flags = 0, vlan_tag = 0, mss = 0;
2710 bus_dma_segment_t segs[BNX_NSEG_NEW];
2712 int error, maxsegs, nsegs, idx, i;
2713 struct mbuf *m_head = *m_head0, *m_new;
2715 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
2716 #ifdef BNX_TSO_DEBUG
2720 error = bnx_setup_tso(txr, m_head0, &mss, &csum_flags);
2725 #ifdef BNX_TSO_DEBUG
2726 tso_nsegs = (m_head->m_pkthdr.len /
2727 m_head->m_pkthdr.tso_segsz) - 1;
2728 if (tso_nsegs > (BNX_TSO_NSTATS - 1))
2729 tso_nsegs = BNX_TSO_NSTATS - 1;
2730 else if (tso_nsegs < 0)
2732 txr->bnx_sc->bnx_tsosegs[tso_nsegs]++;
2734 } else if (m_head->m_pkthdr.csum_flags & BNX_CSUM_FEATURES) {
2735 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
2736 csum_flags |= BGE_TXBDFLAG_IP_CSUM;
2737 if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
2738 csum_flags |= BGE_TXBDFLAG_TCP_UDP_CSUM;
2739 if (m_head->m_flags & M_LASTFRAG)
2740 csum_flags |= BGE_TXBDFLAG_IP_FRAG_END;
2741 else if (m_head->m_flags & M_FRAG)
2742 csum_flags |= BGE_TXBDFLAG_IP_FRAG;
2744 if (m_head->m_flags & M_VLANTAG) {
2745 csum_flags |= BGE_TXBDFLAG_VLAN_TAG;
2746 vlan_tag = m_head->m_pkthdr.ether_vlantag;
2750 map = txr->bnx_tx_buf[idx].bnx_tx_dmamap;
2752 maxsegs = (BGE_TX_RING_CNT - txr->bnx_tx_cnt) - BNX_NSEG_RSVD;
2753 KASSERT(maxsegs >= BNX_NSEG_SPARE,
2754 ("not enough segments %d", maxsegs));
2756 if (maxsegs > BNX_NSEG_NEW)
2757 maxsegs = BNX_NSEG_NEW;
2760 * Pad outbound frame to BGE_MIN_FRAMELEN for an unusual reason.
2761 * The bge hardware will pad out Tx runts to BGE_MIN_FRAMELEN,
2762 * but when such padded frames employ the bge IP/TCP checksum
2763 * offload, the hardware checksum assist gives incorrect results
2764 * (possibly from incorporating its own padding into the UDP/TCP
2765 * checksum; who knows). If we pad such runts with zeros, the
2766 * onboard checksum comes out correct.
2768 if ((csum_flags & BGE_TXBDFLAG_TCP_UDP_CSUM) &&
2769 m_head->m_pkthdr.len < BNX_MIN_FRAMELEN) {
2770 error = m_devpad(m_head, BNX_MIN_FRAMELEN);
2775 if ((txr->bnx_tx_flags & BNX_TX_FLAG_SHORTDMA) &&
2776 m_head->m_next != NULL) {
2777 m_new = bnx_defrag_shortdma(m_head);
2778 if (m_new == NULL) {
2782 *m_head0 = m_head = m_new;
2784 if ((m_head->m_pkthdr.csum_flags & CSUM_TSO) == 0 &&
2785 (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG) &&
2786 m_head->m_next != NULL) {
2788 * Forcefully defragment mbuf chain to overcome hardware
2789 * limitation which only support a single outstanding
2790 * DMA read operation. If it fails, keep moving on using
2791 * the original mbuf chain.
2793 m_new = m_defrag(m_head, MB_DONTWAIT);
2795 *m_head0 = m_head = m_new;
2798 error = bus_dmamap_load_mbuf_defrag(txr->bnx_tx_mtag, map,
2799 m_head0, segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
2802 *segs_used += nsegs;
2805 bus_dmamap_sync(txr->bnx_tx_mtag, map, BUS_DMASYNC_PREWRITE);
2807 for (i = 0; ; i++) {
2808 d = &txr->bnx_tx_ring[idx];
2810 d->bge_addr.bge_addr_lo = BGE_ADDR_LO(segs[i].ds_addr);
2811 d->bge_addr.bge_addr_hi = BGE_ADDR_HI(segs[i].ds_addr);
2812 d->bge_len = segs[i].ds_len;
2813 d->bge_flags = csum_flags;
2814 d->bge_vlan_tag = vlan_tag;
2819 BNX_INC(idx, BGE_TX_RING_CNT);
2821 /* Mark the last segment as end of packet... */
2822 d->bge_flags |= BGE_TXBDFLAG_END;
2825 * Insure that the map for this transmission is placed at
2826 * the array index of the last descriptor in this chain.
2828 txr->bnx_tx_buf[*txidx].bnx_tx_dmamap = txr->bnx_tx_buf[idx].bnx_tx_dmamap;
2829 txr->bnx_tx_buf[idx].bnx_tx_dmamap = map;
2830 txr->bnx_tx_buf[idx].bnx_tx_mbuf = m_head;
2831 txr->bnx_tx_cnt += nsegs;
2833 BNX_INC(idx, BGE_TX_RING_CNT);
2844 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
2845 * to the mbuf data regions directly in the transmit descriptors.
2848 bnx_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
2850 struct bnx_softc *sc = ifp->if_softc;
2851 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */
2852 struct mbuf *m_head = NULL;
2856 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
2858 if ((ifp->if_flags & IFF_RUNNING) == 0 || ifq_is_oactive(&ifp->if_snd))
2861 prodidx = txr->bnx_tx_prodidx;
2863 while (txr->bnx_tx_buf[prodidx].bnx_tx_mbuf == NULL) {
2865 * Sanity check: avoid coming within BGE_NSEG_RSVD
2866 * descriptors of the end of the ring. Also make
2867 * sure there are BGE_NSEG_SPARE descriptors for
2868 * jumbo buffers' or TSO segments' defragmentation.
2870 if ((BGE_TX_RING_CNT - txr->bnx_tx_cnt) <
2871 (BNX_NSEG_RSVD + BNX_NSEG_SPARE)) {
2872 ifq_set_oactive(&ifp->if_snd);
2876 m_head = ifq_dequeue(&ifp->if_snd, NULL);
2881 * Pack the data into the transmit ring. If we
2882 * don't have room, set the OACTIVE flag and wait
2883 * for the NIC to drain the ring.
2885 if (bnx_encap(txr, &m_head, &prodidx, &nsegs)) {
2886 ifq_set_oactive(&ifp->if_snd);
2887 IFNET_STAT_INC(ifp, oerrors, 1);
2891 if (nsegs >= txr->bnx_tx_wreg) {
2893 bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx);
2897 ETHER_BPF_MTAP(ifp, m_head);
2900 * Set a timeout in case the chip goes out to lunch.
2907 bnx_writembx(txr->bnx_sc, txr->bnx_tx_mbx, prodidx);
2909 txr->bnx_tx_prodidx = prodidx;
2915 struct bnx_softc *sc = xsc;
2916 struct ifnet *ifp = &sc->arpcom.ac_if;
2921 ASSERT_SERIALIZED(ifp->if_serializer);
2923 /* Cancel pending I/O and flush buffers. */
2929 * Init the various state machines, ring
2930 * control blocks and firmware.
2932 if (bnx_blockinit(sc)) {
2933 if_printf(ifp, "initialization failure\n");
2939 CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu +
2940 ETHER_HDR_LEN + ETHER_CRC_LEN + EVL_ENCAPLEN);
2942 /* Load our MAC address. */
2943 m = (uint16_t *)&sc->arpcom.ac_enaddr[0];
2944 CSR_WRITE_4(sc, BGE_MAC_ADDR1_LO, htons(m[0]));
2945 CSR_WRITE_4(sc, BGE_MAC_ADDR1_HI, (htons(m[1]) << 16) | htons(m[2]));
2947 /* Enable or disable promiscuous mode as needed. */
2950 /* Program multicast filter. */
2954 if (bnx_init_rx_ring_std(&sc->bnx_rx_std_ring)) {
2955 if_printf(ifp, "RX ring initialization failed\n");
2960 /* Init jumbo RX ring. */
2961 if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) {
2962 if (bnx_init_rx_ring_jumbo(sc)) {
2963 if_printf(ifp, "Jumbo RX ring initialization failed\n");
2969 /* Init our RX return ring index */
2970 for (i = 0; i < sc->bnx_rx_retcnt; ++i)
2971 sc->bnx_rx_ret_ring[i].bnx_rx_saved_considx = 0;
2974 for (i = 0; i < sc->bnx_tx_ringcnt; ++i)
2975 bnx_init_tx_ring(&sc->bnx_tx_ring[i]);
2977 /* Enable TX MAC state machine lockup fix. */
2978 mode = CSR_READ_4(sc, BGE_TX_MODE);
2979 mode |= BGE_TXMODE_MBUF_LOCKUP_FIX;
2980 if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
2981 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
2982 mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE);
2983 mode |= CSR_READ_4(sc, BGE_TX_MODE) &
2984 (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE);
2986 /* Turn on transmitter */
2987 CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE);
2989 /* Turn on receiver */
2990 BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE);
2993 * Set the number of good frames to receive after RX MBUF
2994 * Low Watermark has been reached. After the RX MAC receives
2995 * this number of frames, it will drop subsequent incoming
2996 * frames until the MBUF High Watermark is reached.
2998 if (BNX_IS_57765_FAMILY(sc))
2999 CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 1);
3001 CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2);
3003 if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) {
3005 if_printf(ifp, "MSI_MODE: %#x\n",
3006 CSR_READ_4(sc, BGE_MSI_MODE));
3010 /* Tell firmware we're alive. */
3011 BNX_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP);
3013 /* Enable host interrupts if polling(4) is not enabled. */
3014 PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA, 4);
3015 #ifdef IFPOLL_ENABLE
3016 if (ifp->if_flags & IFF_NPOLLING)
3017 bnx_disable_intr(sc);
3020 bnx_enable_intr(sc);
3022 bnx_ifmedia_upd(ifp);
3024 ifp->if_flags |= IFF_RUNNING;
3025 ifq_clr_oactive(&ifp->if_snd);
3027 callout_reset_bycpu(&sc->bnx_stat_timer, hz, bnx_tick, sc,
3028 sc->bnx_stat_cpuid);
3032 * Set media options.
3035 bnx_ifmedia_upd(struct ifnet *ifp)
3037 struct bnx_softc *sc = ifp->if_softc;
3039 /* If this is a 1000baseX NIC, enable the TBI port. */
3040 if (sc->bnx_flags & BNX_FLAG_TBI) {
3041 struct ifmedia *ifm = &sc->bnx_ifmedia;
3043 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
3046 switch(IFM_SUBTYPE(ifm->ifm_media)) {
3051 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
3052 BNX_CLRBIT(sc, BGE_MAC_MODE,
3053 BGE_MACMODE_HALF_DUPLEX);
3055 BNX_SETBIT(sc, BGE_MAC_MODE,
3056 BGE_MACMODE_HALF_DUPLEX);
3063 struct mii_data *mii = device_get_softc(sc->bnx_miibus);
3067 if (mii->mii_instance) {
3068 struct mii_softc *miisc;
3070 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
3071 mii_phy_reset(miisc);
3076 * Force an interrupt so that we will call bnx_link_upd
3077 * if needed and clear any pending link state attention.
3078 * Without this we are not getting any further interrupts
3079 * for link state changes and thus will not UP the link and
3080 * not be able to send in bnx_start. The only way to get
3081 * things working was to receive a packet and get an RX
3084 * bnx_tick should help for fiber cards and we might not
3085 * need to do this here if BNX_FLAG_TBI is set but as
3086 * we poll for fiber anyway it should not harm.
3088 BNX_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
3094 * Report current media status.
3097 bnx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3099 struct bnx_softc *sc = ifp->if_softc;
3101 if (sc->bnx_flags & BNX_FLAG_TBI) {
3102 ifmr->ifm_status = IFM_AVALID;
3103 ifmr->ifm_active = IFM_ETHER;
3104 if (CSR_READ_4(sc, BGE_MAC_STS) &
3105 BGE_MACSTAT_TBI_PCS_SYNCHED) {
3106 ifmr->ifm_status |= IFM_ACTIVE;
3108 ifmr->ifm_active |= IFM_NONE;
3112 ifmr->ifm_active |= IFM_1000_SX;
3113 if (CSR_READ_4(sc, BGE_MAC_MODE) & BGE_MACMODE_HALF_DUPLEX)
3114 ifmr->ifm_active |= IFM_HDX;
3116 ifmr->ifm_active |= IFM_FDX;
3118 struct mii_data *mii = device_get_softc(sc->bnx_miibus);
3121 ifmr->ifm_active = mii->mii_media_active;
3122 ifmr->ifm_status = mii->mii_media_status;
3127 bnx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
3129 struct bnx_softc *sc = ifp->if_softc;
3130 struct ifreq *ifr = (struct ifreq *)data;
3131 int mask, error = 0;
3133 ASSERT_SERIALIZED(ifp->if_serializer);
3137 if ((!BNX_IS_JUMBO_CAPABLE(sc) && ifr->ifr_mtu > ETHERMTU) ||
3138 (BNX_IS_JUMBO_CAPABLE(sc) &&
3139 ifr->ifr_mtu > BNX_JUMBO_MTU)) {
3141 } else if (ifp->if_mtu != ifr->ifr_mtu) {
3142 ifp->if_mtu = ifr->ifr_mtu;
3143 if (ifp->if_flags & IFF_RUNNING)
3148 if (ifp->if_flags & IFF_UP) {
3149 if (ifp->if_flags & IFF_RUNNING) {
3150 mask = ifp->if_flags ^ sc->bnx_if_flags;
3153 * If only the state of the PROMISC flag
3154 * changed, then just use the 'set promisc
3155 * mode' command instead of reinitializing
3156 * the entire NIC. Doing a full re-init
3157 * means reloading the firmware and waiting
3158 * for it to start up, which may take a
3159 * second or two. Similarly for ALLMULTI.
3161 if (mask & IFF_PROMISC)
3163 if (mask & IFF_ALLMULTI)
3168 } else if (ifp->if_flags & IFF_RUNNING) {
3171 sc->bnx_if_flags = ifp->if_flags;
3175 if (ifp->if_flags & IFF_RUNNING)
3180 if (sc->bnx_flags & BNX_FLAG_TBI) {
3181 error = ifmedia_ioctl(ifp, ifr,
3182 &sc->bnx_ifmedia, command);
3184 struct mii_data *mii;
3186 mii = device_get_softc(sc->bnx_miibus);
3187 error = ifmedia_ioctl(ifp, ifr,
3188 &mii->mii_media, command);
3192 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
3193 if (mask & IFCAP_HWCSUM) {
3194 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
3195 if (ifp->if_capenable & IFCAP_TXCSUM)
3196 ifp->if_hwassist |= BNX_CSUM_FEATURES;
3198 ifp->if_hwassist &= ~BNX_CSUM_FEATURES;
3200 if (mask & IFCAP_TSO) {
3201 ifp->if_capenable ^= (mask & IFCAP_TSO);
3202 if (ifp->if_capenable & IFCAP_TSO)
3203 ifp->if_hwassist |= CSUM_TSO;
3205 ifp->if_hwassist &= ~CSUM_TSO;
3209 error = ether_ioctl(ifp, command, data);
3216 bnx_watchdog(struct ifnet *ifp)
3218 struct bnx_softc *sc = ifp->if_softc;
3220 if_printf(ifp, "watchdog timeout -- resetting\n");
3224 IFNET_STAT_INC(ifp, oerrors, 1);
3226 if (!ifq_is_empty(&ifp->if_snd))
3231 * Stop the adapter and free any mbufs allocated to the
3235 bnx_stop(struct bnx_softc *sc)
3237 struct ifnet *ifp = &sc->arpcom.ac_if;
3240 ASSERT_SERIALIZED(ifp->if_serializer);
3242 callout_stop(&sc->bnx_stat_timer);
3245 * Disable all of the receiver blocks
3247 bnx_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE);
3248 bnx_stop_block(sc, BGE_RBDI_MODE, BGE_RBDIMODE_ENABLE);
3249 bnx_stop_block(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE);
3250 bnx_stop_block(sc, BGE_RDBDI_MODE, BGE_RBDIMODE_ENABLE);
3251 bnx_stop_block(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE);
3252 bnx_stop_block(sc, BGE_RBDC_MODE, BGE_RBDCMODE_ENABLE);
3255 * Disable all of the transmit blocks
3257 bnx_stop_block(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE);
3258 bnx_stop_block(sc, BGE_SBDI_MODE, BGE_SBDIMODE_ENABLE);
3259 bnx_stop_block(sc, BGE_SDI_MODE, BGE_SDIMODE_ENABLE);
3260 bnx_stop_block(sc, BGE_RDMA_MODE, BGE_RDMAMODE_ENABLE);
3261 bnx_stop_block(sc, BGE_SDC_MODE, BGE_SDCMODE_ENABLE);
3262 bnx_stop_block(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE);
3265 * Shut down all of the memory managers and related
3268 bnx_stop_block(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE);
3269 bnx_stop_block(sc, BGE_WDMA_MODE, BGE_WDMAMODE_ENABLE);
3270 CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF);
3271 CSR_WRITE_4(sc, BGE_FTQ_RESET, 0);
3273 /* Disable host interrupts. */
3274 bnx_disable_intr(sc);
3277 * Tell firmware we're shutting down.
3279 BNX_CLRBIT(sc, BGE_MODE_CTL, BGE_MODECTL_STACKUP);
3281 /* Free the RX lists. */
3282 bnx_free_rx_ring_std(&sc->bnx_rx_std_ring);
3284 /* Free jumbo RX list. */
3285 if (BNX_IS_JUMBO_CAPABLE(sc))
3286 bnx_free_rx_ring_jumbo(sc);
3288 /* Free TX buffers. */
3289 for (i = 0; i < sc->bnx_tx_ringcnt; ++i)
3290 bnx_free_tx_ring(&sc->bnx_tx_ring[i]);
3292 sc->bnx_status_tag = 0;
3294 sc->bnx_coal_chg = 0;
3296 ifp->if_flags &= ~IFF_RUNNING;
3297 ifq_clr_oactive(&ifp->if_snd);
3302 * Stop all chip I/O so that the kernel's probe routines don't
3303 * get confused by errant DMAs when rebooting.
3306 bnx_shutdown(device_t dev)
3308 struct bnx_softc *sc = device_get_softc(dev);
3309 struct ifnet *ifp = &sc->arpcom.ac_if;
3311 lwkt_serialize_enter(ifp->if_serializer);
3314 lwkt_serialize_exit(ifp->if_serializer);
3318 bnx_suspend(device_t dev)
3320 struct bnx_softc *sc = device_get_softc(dev);
3321 struct ifnet *ifp = &sc->arpcom.ac_if;
3323 lwkt_serialize_enter(ifp->if_serializer);
3325 lwkt_serialize_exit(ifp->if_serializer);
3331 bnx_resume(device_t dev)
3333 struct bnx_softc *sc = device_get_softc(dev);
3334 struct ifnet *ifp = &sc->arpcom.ac_if;
3336 lwkt_serialize_enter(ifp->if_serializer);
3338 if (ifp->if_flags & IFF_UP) {
3341 if (!ifq_is_empty(&ifp->if_snd))
3345 lwkt_serialize_exit(ifp->if_serializer);
3351 bnx_setpromisc(struct bnx_softc *sc)
3353 struct ifnet *ifp = &sc->arpcom.ac_if;
3355 if (ifp->if_flags & IFF_PROMISC)
3356 BNX_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC);
3358 BNX_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_RX_PROMISC);
3362 bnx_dma_free(struct bnx_softc *sc)
3364 struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring;
3367 /* Destroy RX return rings */
3368 if (sc->bnx_rx_ret_ring != NULL) {
3369 for (i = 0; i < sc->bnx_rx_retcnt; ++i)
3370 bnx_destroy_rx_ret_ring(&sc->bnx_rx_ret_ring[i]);
3371 kfree(sc->bnx_rx_ret_ring, M_DEVBUF);
3374 /* Destroy RX mbuf DMA stuffs. */
3375 if (std->bnx_rx_mtag != NULL) {
3376 for (i = 0; i < BGE_STD_RX_RING_CNT; i++) {
3377 KKASSERT(std->bnx_rx_std_buf[i].bnx_rx_mbuf == NULL);
3378 bus_dmamap_destroy(std->bnx_rx_mtag,
3379 std->bnx_rx_std_buf[i].bnx_rx_dmamap);
3381 bus_dma_tag_destroy(std->bnx_rx_mtag);
3384 /* Destroy standard RX ring */
3385 bnx_dma_block_free(std->bnx_rx_std_ring_tag,
3386 std->bnx_rx_std_ring_map, std->bnx_rx_std_ring);
3388 /* Destroy TX rings */
3389 if (sc->bnx_tx_ring != NULL) {
3390 for (i = 0; i < sc->bnx_tx_ringcnt; ++i)
3391 bnx_destroy_tx_ring(&sc->bnx_tx_ring[i]);
3392 kfree(sc->bnx_tx_ring, M_DEVBUF);
3395 if (BNX_IS_JUMBO_CAPABLE(sc))
3396 bnx_free_jumbo_mem(sc);
3398 /* Destroy status block */
3399 bnx_dma_block_free(sc->bnx_cdata.bnx_status_tag,
3400 sc->bnx_cdata.bnx_status_map,
3401 sc->bnx_ldata.bnx_status_block);
3403 /* Destroy the parent tag */
3404 if (sc->bnx_cdata.bnx_parent_tag != NULL)
3405 bus_dma_tag_destroy(sc->bnx_cdata.bnx_parent_tag);
3409 bnx_dma_alloc(device_t dev)
3411 struct bnx_softc *sc = device_get_softc(dev);
3412 struct bnx_rx_std_ring *std = &sc->bnx_rx_std_ring;
3416 * Allocate the parent bus DMA tag appropriate for PCI.
3418 * All of the NetExtreme/NetLink controllers have 4GB boundary
3420 * Whenever an address crosses a multiple of the 4GB boundary
3421 * (including 4GB, 8Gb, 12Gb, etc.) and makes the transition
3422 * from 0xX_FFFF_FFFF to 0x(X+1)_0000_0000 an internal DMA
3423 * state machine will lockup and cause the device to hang.
3425 error = bus_dma_tag_create(NULL, 1, BGE_DMA_BOUNDARY_4G,
3426 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
3427 BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT,
3428 0, &sc->bnx_cdata.bnx_parent_tag);
3430 device_printf(dev, "could not create parent DMA tag\n");
3435 * Create DMA stuffs for status block.
3437 error = bnx_dma_block_alloc(sc, BGE_STATUS_BLK_SZ,
3438 &sc->bnx_cdata.bnx_status_tag,
3439 &sc->bnx_cdata.bnx_status_map,
3440 (void *)&sc->bnx_ldata.bnx_status_block,
3441 &sc->bnx_ldata.bnx_status_block_paddr);
3443 device_printf(dev, "could not create status block\n");
3448 * Create DMA tag and maps for RX mbufs.
3451 error = bus_dma_tag_create(sc->bnx_cdata.bnx_parent_tag, 1, 0,
3452 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
3453 NULL, NULL, MCLBYTES, 1, MCLBYTES,
3454 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK, &std->bnx_rx_mtag);
3456 device_printf(dev, "could not create RX mbuf DMA tag\n");
3460 for (i = 0; i < BGE_STD_RX_RING_CNT; ++i) {
3461 error = bus_dmamap_create(std->bnx_rx_mtag, BUS_DMA_WAITOK,
3462 &std->bnx_rx_std_buf[i].bnx_rx_dmamap);
3466 for (j = 0; j < i; ++j) {
3467 bus_dmamap_destroy(std->bnx_rx_mtag,
3468 std->bnx_rx_std_buf[j].bnx_rx_dmamap);
3470 bus_dma_tag_destroy(std->bnx_rx_mtag);
3471 std->bnx_rx_mtag = NULL;
3474 "could not create %dth RX mbuf DMA map\n", i);
3480 * Create DMA stuffs for standard RX ring.
3482 error = bnx_dma_block_alloc(sc, BGE_STD_RX_RING_SZ,
3483 &std->bnx_rx_std_ring_tag,
3484 &std->bnx_rx_std_ring_map,
3485 (void *)&std->bnx_rx_std_ring,
3486 &std->bnx_rx_std_ring_paddr);
3488 device_printf(dev, "could not create std RX ring\n");
3493 * Create RX return rings
3495 sc->bnx_rx_ret_ring = kmalloc_cachealign(
3496 sizeof(struct bnx_rx_ret_ring) * sc->bnx_rx_retcnt, M_DEVBUF,
3498 for (i = 0; i < sc->bnx_rx_retcnt; ++i) {
3499 struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[i];
3505 ret->bnx_rx_considx =
3506 &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_rx_prod_idx;
3508 error = bnx_create_rx_ret_ring(ret);
3511 "could not create %dth RX ret ring\n", i);
3519 mbx = BGE_MBX_TX_HOST_PROD0_LO;
3520 sc->bnx_tx_ring = kmalloc_cachealign(
3521 sizeof(struct bnx_tx_ring) * sc->bnx_tx_ringcnt, M_DEVBUF,
3523 for (i = 0; i < sc->bnx_tx_ringcnt; ++i) {
3524 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[i];
3527 txr->bnx_tx_mbx = mbx;
3535 txr->bnx_tx_considx =
3536 &sc->bnx_ldata.bnx_status_block->bge_idx[0].bge_tx_cons_idx;
3538 error = bnx_create_tx_ring(txr);
3541 "could not create %dth TX ring\n", i);
3547 * Create jumbo buffer pool.
3549 if (BNX_IS_JUMBO_CAPABLE(sc)) {
3550 error = bnx_alloc_jumbo_mem(sc);
3553 "could not create jumbo buffer pool\n");
3562 bnx_dma_block_alloc(struct bnx_softc *sc, bus_size_t size, bus_dma_tag_t *tag,
3563 bus_dmamap_t *map, void **addr, bus_addr_t *paddr)
3568 error = bus_dmamem_coherent(sc->bnx_cdata.bnx_parent_tag, PAGE_SIZE, 0,
3569 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
3570 size, BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmem);
3574 *tag = dmem.dmem_tag;
3575 *map = dmem.dmem_map;
3576 *addr = dmem.dmem_addr;
3577 *paddr = dmem.dmem_busaddr;
3583 bnx_dma_block_free(bus_dma_tag_t tag, bus_dmamap_t map, void *addr)
3586 bus_dmamap_unload(tag, map);
3587 bus_dmamem_free(tag, addr, map);
3588 bus_dma_tag_destroy(tag);
3593 bnx_tbi_link_upd(struct bnx_softc *sc, uint32_t status)
3595 struct ifnet *ifp = &sc->arpcom.ac_if;
3597 #define PCS_ENCODE_ERR (BGE_MACSTAT_PORT_DECODE_ERROR|BGE_MACSTAT_MI_COMPLETE)
3600 * Sometimes PCS encoding errors are detected in
3601 * TBI mode (on fiber NICs), and for some reason
3602 * the chip will signal them as link changes.
3603 * If we get a link change event, but the 'PCS
3604 * encoding error' bit in the MAC status register
3605 * is set, don't bother doing a link check.
3606 * This avoids spurious "gigabit link up" messages
3607 * that sometimes appear on fiber NICs during
3608 * periods of heavy traffic.
3610 if (status & BGE_MACSTAT_TBI_PCS_SYNCHED) {
3611 if (!sc->bnx_link) {
3613 if (sc->bnx_asicrev == BGE_ASICREV_BCM5704) {
3614 BNX_CLRBIT(sc, BGE_MAC_MODE,
3615 BGE_MACMODE_TBI_SEND_CFGS);
3617 CSR_WRITE_4(sc, BGE_MAC_STS, 0xFFFFFFFF);
3620 if_printf(ifp, "link UP\n");
3622 ifp->if_link_state = LINK_STATE_UP;
3623 if_link_state_change(ifp);
3625 } else if ((status & PCS_ENCODE_ERR) != PCS_ENCODE_ERR) {
3630 if_printf(ifp, "link DOWN\n");
3632 ifp->if_link_state = LINK_STATE_DOWN;
3633 if_link_state_change(ifp);
3637 #undef PCS_ENCODE_ERR
3639 /* Clear the attention. */
3640 CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED |
3641 BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE |
3642 BGE_MACSTAT_LINK_CHANGED);
3646 bnx_copper_link_upd(struct bnx_softc *sc, uint32_t status __unused)
3648 struct ifnet *ifp = &sc->arpcom.ac_if;
3649 struct mii_data *mii = device_get_softc(sc->bnx_miibus);
3652 bnx_miibus_statchg(sc->bnx_dev);
3656 if_printf(ifp, "link UP\n");
3658 if_printf(ifp, "link DOWN\n");
3661 /* Clear the attention. */
3662 CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED |
3663 BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE |
3664 BGE_MACSTAT_LINK_CHANGED);
3668 bnx_autopoll_link_upd(struct bnx_softc *sc, uint32_t status __unused)
3670 struct ifnet *ifp = &sc->arpcom.ac_if;
3671 struct mii_data *mii = device_get_softc(sc->bnx_miibus);
3675 if (!sc->bnx_link &&
3676 (mii->mii_media_status & IFM_ACTIVE) &&
3677 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
3680 if_printf(ifp, "link UP\n");
3681 } else if (sc->bnx_link &&
3682 (!(mii->mii_media_status & IFM_ACTIVE) ||
3683 IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)) {
3686 if_printf(ifp, "link DOWN\n");
3689 /* Clear the attention. */
3690 CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED |
3691 BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE |
3692 BGE_MACSTAT_LINK_CHANGED);
3696 bnx_sysctl_rx_coal_ticks(SYSCTL_HANDLER_ARGS)
3698 struct bnx_softc *sc = arg1;
3700 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3701 &sc->bnx_rx_coal_ticks,
3702 BNX_RX_COAL_TICKS_MIN, BNX_RX_COAL_TICKS_MAX,
3703 BNX_RX_COAL_TICKS_CHG);
3707 bnx_sysctl_tx_coal_ticks(SYSCTL_HANDLER_ARGS)
3709 struct bnx_softc *sc = arg1;
3711 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3712 &sc->bnx_tx_coal_ticks,
3713 BNX_TX_COAL_TICKS_MIN, BNX_TX_COAL_TICKS_MAX,
3714 BNX_TX_COAL_TICKS_CHG);
3718 bnx_sysctl_rx_coal_bds(SYSCTL_HANDLER_ARGS)
3720 struct bnx_softc *sc = arg1;
3722 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3723 &sc->bnx_rx_coal_bds,
3724 BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX,
3725 BNX_RX_COAL_BDS_CHG);
3729 bnx_sysctl_tx_coal_bds(SYSCTL_HANDLER_ARGS)
3731 struct bnx_softc *sc = arg1;
3733 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3734 &sc->bnx_tx_coal_bds,
3735 BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX,
3736 BNX_TX_COAL_BDS_CHG);
3740 bnx_sysctl_rx_coal_bds_int(SYSCTL_HANDLER_ARGS)
3742 struct bnx_softc *sc = arg1;
3744 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3745 &sc->bnx_rx_coal_bds_int,
3746 BNX_RX_COAL_BDS_MIN, BNX_RX_COAL_BDS_MAX,
3747 BNX_RX_COAL_BDS_INT_CHG);
3751 bnx_sysctl_tx_coal_bds_int(SYSCTL_HANDLER_ARGS)
3753 struct bnx_softc *sc = arg1;
3755 return bnx_sysctl_coal_chg(oidp, arg1, arg2, req,
3756 &sc->bnx_tx_coal_bds_int,
3757 BNX_TX_COAL_BDS_MIN, BNX_TX_COAL_BDS_MAX,
3758 BNX_TX_COAL_BDS_INT_CHG);
3762 bnx_sysctl_coal_chg(SYSCTL_HANDLER_ARGS, uint32_t *coal,
3763 int coal_min, int coal_max, uint32_t coal_chg_mask)
3765 struct bnx_softc *sc = arg1;
3766 struct ifnet *ifp = &sc->arpcom.ac_if;
3769 lwkt_serialize_enter(ifp->if_serializer);
3772 error = sysctl_handle_int(oidp, &v, 0, req);
3773 if (!error && req->newptr != NULL) {
3774 if (v < coal_min || v > coal_max) {
3778 sc->bnx_coal_chg |= coal_chg_mask;
3780 /* Commit changes */
3781 bnx_coal_change(sc);
3785 lwkt_serialize_exit(ifp->if_serializer);
3790 bnx_coal_change(struct bnx_softc *sc)
3792 struct ifnet *ifp = &sc->arpcom.ac_if;
3794 ASSERT_SERIALIZED(ifp->if_serializer);
3796 if (sc->bnx_coal_chg & BNX_RX_COAL_TICKS_CHG) {
3797 CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS,
3798 sc->bnx_rx_coal_ticks);
3800 CSR_READ_4(sc, BGE_HCC_RX_COAL_TICKS);
3803 if_printf(ifp, "rx_coal_ticks -> %u\n",
3804 sc->bnx_rx_coal_ticks);
3808 if (sc->bnx_coal_chg & BNX_TX_COAL_TICKS_CHG) {
3809 CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS,
3810 sc->bnx_tx_coal_ticks);
3812 CSR_READ_4(sc, BGE_HCC_TX_COAL_TICKS);
3815 if_printf(ifp, "tx_coal_ticks -> %u\n",
3816 sc->bnx_tx_coal_ticks);
3820 if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_CHG) {
3821 CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS,
3822 sc->bnx_rx_coal_bds);
3824 CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS);
3827 if_printf(ifp, "rx_coal_bds -> %u\n",
3828 sc->bnx_rx_coal_bds);
3832 if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_CHG) {
3833 CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS,
3834 sc->bnx_tx_coal_bds);
3836 CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS);
3839 if_printf(ifp, "tx_coal_bds -> %u\n",
3840 sc->bnx_tx_coal_bds);
3844 if (sc->bnx_coal_chg & BNX_RX_COAL_BDS_INT_CHG) {
3845 CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT,
3846 sc->bnx_rx_coal_bds_int);
3848 CSR_READ_4(sc, BGE_HCC_RX_MAX_COAL_BDS_INT);
3851 if_printf(ifp, "rx_coal_bds_int -> %u\n",
3852 sc->bnx_rx_coal_bds_int);
3856 if (sc->bnx_coal_chg & BNX_TX_COAL_BDS_INT_CHG) {
3857 CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT,
3858 sc->bnx_tx_coal_bds_int);
3860 CSR_READ_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT);
3863 if_printf(ifp, "tx_coal_bds_int -> %u\n",
3864 sc->bnx_tx_coal_bds_int);
3868 sc->bnx_coal_chg = 0;
3872 bnx_intr_check(void *xsc)
3874 struct bnx_softc *sc = xsc;
3875 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0]; /* XXX */
3876 struct bnx_rx_ret_ring *ret = &sc->bnx_rx_ret_ring[0]; /* XXX */
3877 struct ifnet *ifp = &sc->arpcom.ac_if;
3879 lwkt_serialize_enter(ifp->if_serializer);
3881 KKASSERT(mycpuid == sc->bnx_intr_cpuid);
3883 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) {
3884 lwkt_serialize_exit(ifp->if_serializer);
3888 if (*ret->bnx_rx_considx != ret->bnx_rx_saved_considx ||
3889 *txr->bnx_tx_considx != txr->bnx_tx_saved_considx) {
3890 if (sc->bnx_rx_check_considx == ret->bnx_rx_saved_considx &&
3891 sc->bnx_tx_check_considx == txr->bnx_tx_saved_considx) {
3892 if (!sc->bnx_intr_maylose) {
3893 sc->bnx_intr_maylose = TRUE;
3897 if_printf(ifp, "lost interrupt\n");
3901 sc->bnx_intr_maylose = FALSE;
3902 sc->bnx_rx_check_considx = ret->bnx_rx_saved_considx;
3903 sc->bnx_tx_check_considx = txr->bnx_tx_saved_considx;
3906 callout_reset(&sc->bnx_intr_timer, BNX_INTR_CKINTVL,
3907 bnx_intr_check, sc);
3908 lwkt_serialize_exit(ifp->if_serializer);
3912 bnx_enable_intr(struct bnx_softc *sc)
3914 struct ifnet *ifp = &sc->arpcom.ac_if;
3916 lwkt_serialize_handler_enable(ifp->if_serializer);
3921 bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24);
3922 if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) {
3923 /* XXX Linux driver */
3924 bnx_writembx(sc, BGE_MBX_IRQ0_LO, sc->bnx_status_tag << 24);
3928 * Unmask the interrupt when we stop polling.
3930 PCI_CLRBIT(sc->bnx_dev, BGE_PCI_MISC_CTL,
3931 BGE_PCIMISCCTL_MASK_PCI_INTR, 4);
3934 * Trigger another interrupt, since above writing
3935 * to interrupt mailbox0 may acknowledge pending
3938 BNX_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
3940 if (sc->bnx_flags & BNX_FLAG_STATUSTAG_BUG) {
3941 sc->bnx_intr_maylose = FALSE;
3942 sc->bnx_rx_check_considx = 0;
3943 sc->bnx_tx_check_considx = 0;
3946 if_printf(ifp, "status tag bug workaround\n");
3948 /* 10ms check interval */
3949 callout_reset_bycpu(&sc->bnx_intr_timer, BNX_INTR_CKINTVL,
3950 bnx_intr_check, sc, sc->bnx_intr_cpuid);
3955 bnx_disable_intr(struct bnx_softc *sc)
3957 struct ifnet *ifp = &sc->arpcom.ac_if;
3960 * Mask the interrupt when we start polling.
3962 PCI_SETBIT(sc->bnx_dev, BGE_PCI_MISC_CTL,
3963 BGE_PCIMISCCTL_MASK_PCI_INTR, 4);
3966 * Acknowledge possible asserted interrupt.
3968 bnx_writembx(sc, BGE_MBX_IRQ0_LO, 1);
3970 callout_stop(&sc->bnx_intr_timer);
3971 sc->bnx_intr_maylose = FALSE;
3972 sc->bnx_rx_check_considx = 0;
3973 sc->bnx_tx_check_considx = 0;
3975 sc->bnx_npoll.ifpc_stcount = 0;
3977 lwkt_serialize_handler_disable(ifp->if_serializer);
3981 bnx_get_eaddr_mem(struct bnx_softc *sc, uint8_t ether_addr[])
3986 mac_addr = bnx_readmem_ind(sc, 0x0c14);
3987 if ((mac_addr >> 16) == 0x484b) {
3988 ether_addr[0] = (uint8_t)(mac_addr >> 8);
3989 ether_addr[1] = (uint8_t)mac_addr;
3990 mac_addr = bnx_readmem_ind(sc, 0x0c18);
3991 ether_addr[2] = (uint8_t)(mac_addr >> 24);
3992 ether_addr[3] = (uint8_t)(mac_addr >> 16);
3993 ether_addr[4] = (uint8_t)(mac_addr >> 8);
3994 ether_addr[5] = (uint8_t)mac_addr;
4001 bnx_get_eaddr_nvram(struct bnx_softc *sc, uint8_t ether_addr[])
4003 int mac_offset = BGE_EE_MAC_OFFSET;
4005 if (BNX_IS_5717_PLUS(sc)) {
4008 f = pci_get_function(sc->bnx_dev);
4010 mac_offset = BGE_EE_MAC_OFFSET_5717;
4012 mac_offset += BGE_EE_MAC_OFFSET_5717_OFF;
4015 return bnx_read_nvram(sc, ether_addr, mac_offset + 2, ETHER_ADDR_LEN);
4019 bnx_get_eaddr_eeprom(struct bnx_softc *sc, uint8_t ether_addr[])
4021 if (sc->bnx_flags & BNX_FLAG_NO_EEPROM)
4024 return bnx_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2,
4029 bnx_get_eaddr(struct bnx_softc *sc, uint8_t eaddr[])
4031 static const bnx_eaddr_fcn_t bnx_eaddr_funcs[] = {
4032 /* NOTE: Order is critical */
4034 bnx_get_eaddr_nvram,
4035 bnx_get_eaddr_eeprom,
4038 const bnx_eaddr_fcn_t *func;
4040 for (func = bnx_eaddr_funcs; *func != NULL; ++func) {
4041 if ((*func)(sc, eaddr) == 0)
4044 return (*func == NULL ? ENXIO : 0);
4048 * NOTE: 'm' is not freed upon failure
4051 bnx_defrag_shortdma(struct mbuf *m)
4057 * If device receive two back-to-back send BDs with less than
4058 * or equal to 8 total bytes then the device may hang. The two
4059 * back-to-back send BDs must in the same frame for this failure
4060 * to occur. Scan mbuf chains and see whether two back-to-back
4061 * send BDs are there. If this is the case, allocate new mbuf
4062 * and copy the frame to workaround the silicon bug.
4064 for (n = m, found = 0; n != NULL; n = n->m_next) {
4075 n = m_defrag(m, MB_DONTWAIT);
4082 bnx_stop_block(struct bnx_softc *sc, bus_size_t reg, uint32_t bit)
4086 BNX_CLRBIT(sc, reg, bit);
4087 for (i = 0; i < BNX_TIMEOUT; i++) {
4088 if ((CSR_READ_4(sc, reg) & bit) == 0)
4095 bnx_link_poll(struct bnx_softc *sc)
4099 status = CSR_READ_4(sc, BGE_MAC_STS);
4100 if ((status & sc->bnx_link_chg) || sc->bnx_link_evt) {
4101 sc->bnx_link_evt = 0;
4102 sc->bnx_link_upd(sc, status);
4107 bnx_enable_msi(struct bnx_softc *sc)
4111 msi_mode = CSR_READ_4(sc, BGE_MSI_MODE);
4112 msi_mode |= BGE_MSIMODE_ENABLE;
4113 if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) {
4116 * 5718-PG105-R says that "one shot" mode
4117 * does not work if MSI is used, however,
4118 * it obviously works.
4120 msi_mode &= ~BGE_MSIMODE_ONESHOT_DISABLE;
4122 CSR_WRITE_4(sc, BGE_MSI_MODE, msi_mode);
4126 bnx_dma_swap_options(struct bnx_softc *sc)
4128 uint32_t dma_options;
4130 dma_options = BGE_MODECTL_WORDSWAP_NONFRAME |
4131 BGE_MODECTL_BYTESWAP_DATA | BGE_MODECTL_WORDSWAP_DATA;
4132 #if BYTE_ORDER == BIG_ENDIAN
4133 dma_options |= BGE_MODECTL_BYTESWAP_NONFRAME;
4135 if (sc->bnx_asicrev == BGE_ASICREV_BCM5720 ||
4136 sc->bnx_asicrev == BGE_ASICREV_BCM5762) {
4137 dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA |
4138 BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE |
4139 BGE_MODECTL_HTX2B_ENABLE;
4145 bnx_setup_tso(struct bnx_tx_ring *txr, struct mbuf **mp,
4146 uint16_t *mss0, uint16_t *flags0)
4151 int thoff, iphlen, hoff, hlen;
4152 uint16_t flags, mss;
4155 KASSERT(M_WRITABLE(m), ("TSO mbuf not writable"));
4157 hoff = m->m_pkthdr.csum_lhlen;
4158 iphlen = m->m_pkthdr.csum_iphlen;
4159 thoff = m->m_pkthdr.csum_thlen;
4161 KASSERT(hoff > 0, ("invalid ether header len"));
4162 KASSERT(iphlen > 0, ("invalid ip header len"));
4163 KASSERT(thoff > 0, ("invalid tcp header len"));
4165 if (__predict_false(m->m_len < hoff + iphlen + thoff)) {
4166 m = m_pullup(m, hoff + iphlen + thoff);
4173 ip = mtodoff(m, struct ip *, hoff);
4174 th = mtodoff(m, struct tcphdr *, hoff + iphlen);
4176 mss = m->m_pkthdr.tso_segsz;
4177 flags = BGE_TXBDFLAG_CPU_PRE_DMA | BGE_TXBDFLAG_CPU_POST_DMA;
4179 ip->ip_len = htons(mss + iphlen + thoff);
4182 hlen = (iphlen + thoff) >> 2;
4183 mss |= ((hlen & 0x3) << 14);
4184 flags |= ((hlen & 0xf8) << 7) | ((hlen & 0x4) << 2);
4193 bnx_create_tx_ring(struct bnx_tx_ring *txr)
4195 bus_size_t txmaxsz, txmaxsegsz;
4199 * Create DMA tag and maps for TX mbufs.
4201 if (txr->bnx_sc->bnx_flags & BNX_FLAG_TSO)
4202 txmaxsz = IP_MAXPACKET + sizeof(struct ether_vlan_header);
4204 txmaxsz = BNX_JUMBO_FRAMELEN;
4205 if (txr->bnx_sc->bnx_asicrev == BGE_ASICREV_BCM57766)
4206 txmaxsegsz = MCLBYTES;
4208 txmaxsegsz = PAGE_SIZE;
4209 error = bus_dma_tag_create(txr->bnx_sc->bnx_cdata.bnx_parent_tag,
4210 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
4211 txmaxsz, BNX_NSEG_NEW, txmaxsegsz,
4212 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
4215 device_printf(txr->bnx_sc->bnx_dev,
4216 "could not create TX mbuf DMA tag\n");
4220 for (i = 0; i < BGE_TX_RING_CNT; i++) {
4221 error = bus_dmamap_create(txr->bnx_tx_mtag,
4222 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
4223 &txr->bnx_tx_buf[i].bnx_tx_dmamap);
4227 for (j = 0; j < i; ++j) {
4228 bus_dmamap_destroy(txr->bnx_tx_mtag,
4229 txr->bnx_tx_buf[j].bnx_tx_dmamap);
4231 bus_dma_tag_destroy(txr->bnx_tx_mtag);
4232 txr->bnx_tx_mtag = NULL;
4234 device_printf(txr->bnx_sc->bnx_dev,
4235 "could not create TX mbuf DMA map\n");
4241 * Create DMA stuffs for TX ring.
4243 error = bnx_dma_block_alloc(txr->bnx_sc, BGE_TX_RING_SZ,
4244 &txr->bnx_tx_ring_tag,
4245 &txr->bnx_tx_ring_map,
4246 (void *)&txr->bnx_tx_ring,
4247 &txr->bnx_tx_ring_paddr);
4249 device_printf(txr->bnx_sc->bnx_dev,
4250 "could not create TX ring\n");
4254 txr->bnx_tx_flags |= BNX_TX_FLAG_SHORTDMA;
4255 txr->bnx_tx_wreg = BNX_TX_WREG_NSEGS;
4261 bnx_destroy_tx_ring(struct bnx_tx_ring *txr)
4263 /* Destroy TX mbuf DMA stuffs. */
4264 if (txr->bnx_tx_mtag != NULL) {
4267 for (i = 0; i < BGE_TX_RING_CNT; i++) {
4268 KKASSERT(txr->bnx_tx_buf[i].bnx_tx_mbuf == NULL);
4269 bus_dmamap_destroy(txr->bnx_tx_mtag,
4270 txr->bnx_tx_buf[i].bnx_tx_dmamap);
4272 bus_dma_tag_destroy(txr->bnx_tx_mtag);
4275 /* Destroy TX ring */
4276 bnx_dma_block_free(txr->bnx_tx_ring_tag,
4277 txr->bnx_tx_ring_map, txr->bnx_tx_ring);
4281 bnx_sysctl_force_defrag(SYSCTL_HANDLER_ARGS)
4283 struct bnx_softc *sc = (void *)arg1;
4284 struct ifnet *ifp = &sc->arpcom.ac_if;
4285 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0];
4286 int error, defrag, i;
4288 if (txr->bnx_tx_flags & BNX_TX_FLAG_FORCE_DEFRAG)
4293 error = sysctl_handle_int(oidp, &defrag, 0, req);
4294 if (error || req->newptr == NULL)
4297 lwkt_serialize_enter(ifp->if_serializer);
4298 for (i = 0; i < sc->bnx_tx_ringcnt; ++i) {
4299 txr = &sc->bnx_tx_ring[i];
4301 txr->bnx_tx_flags |= BNX_TX_FLAG_FORCE_DEFRAG;
4303 txr->bnx_tx_flags &= ~BNX_TX_FLAG_FORCE_DEFRAG;
4305 lwkt_serialize_exit(ifp->if_serializer);
4311 bnx_sysctl_tx_wreg(SYSCTL_HANDLER_ARGS)
4313 struct bnx_softc *sc = (void *)arg1;
4314 struct ifnet *ifp = &sc->arpcom.ac_if;
4315 struct bnx_tx_ring *txr = &sc->bnx_tx_ring[0];
4316 int error, tx_wreg, i;
4318 tx_wreg = txr->bnx_tx_wreg;
4319 error = sysctl_handle_int(oidp, &tx_wreg, 0, req);
4320 if (error || req->newptr == NULL)
4323 lwkt_serialize_enter(ifp->if_serializer);
4324 for (i = 0; i < sc->bnx_tx_ringcnt; ++i)
4325 sc->bnx_tx_ring[i].bnx_tx_wreg = tx_wreg;
4326 lwkt_serialize_exit(ifp->if_serializer);
4332 bnx_create_rx_ret_ring(struct bnx_rx_ret_ring *ret)
4337 * Create DMA stuffs for RX return ring.
4339 error = bnx_dma_block_alloc(ret->bnx_sc,
4340 BGE_RX_RTN_RING_SZ(BNX_RETURN_RING_CNT),
4341 &ret->bnx_rx_ret_ring_tag,
4342 &ret->bnx_rx_ret_ring_map,
4343 (void *)&ret->bnx_rx_ret_ring,
4344 &ret->bnx_rx_ret_ring_paddr);
4346 device_printf(ret->bnx_sc->bnx_dev,
4347 "could not create RX ret ring\n");
4351 /* Shadow standard ring's RX mbuf DMA tag */
4352 ret->bnx_rx_mtag = ret->bnx_std->bnx_rx_mtag;
4355 * Create tmp DMA map for RX mbufs.
4357 error = bus_dmamap_create(ret->bnx_rx_mtag, BUS_DMA_WAITOK,
4358 &ret->bnx_rx_tmpmap);
4360 device_printf(ret->bnx_sc->bnx_dev,
4361 "could not create tmp RX mbuf DMA map\n");
4362 ret->bnx_rx_mtag = NULL;
4369 bnx_destroy_rx_ret_ring(struct bnx_rx_ret_ring *ret)
4371 /* Destroy tmp RX mbuf DMA map */
4372 if (ret->bnx_rx_mtag != NULL)
4373 bus_dmamap_destroy(ret->bnx_rx_mtag, ret->bnx_rx_tmpmap);
4375 /* Destroy RX return ring */
4376 bnx_dma_block_free(ret->bnx_rx_ret_ring_tag,
4377 ret->bnx_rx_ret_ring_map, ret->bnx_rx_ret_ring);
4381 bnx_alloc_intr(struct bnx_softc *sc)
4385 sc->bnx_irq_type = pci_alloc_1intr(sc->bnx_dev, bnx_msi_enable,
4386 &sc->bnx_irq_rid, &intr_flags);
4388 sc->bnx_irq = bus_alloc_resource_any(sc->bnx_dev, SYS_RES_IRQ,
4389 &sc->bnx_irq_rid, intr_flags);
4390 if (sc->bnx_irq == NULL) {
4391 device_printf(sc->bnx_dev, "could not alloc interrupt\n");
4395 if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) {
4396 sc->bnx_flags |= BNX_FLAG_ONESHOT_MSI;
4403 bnx_setup_intr(struct bnx_softc *sc)
4405 driver_intr_t *intr_func;
4408 if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI) {
4409 if (sc->bnx_flags & BNX_FLAG_ONESHOT_MSI) {
4410 intr_func = bnx_msi_oneshot;
4412 device_printf(sc->bnx_dev, "oneshot MSI\n");
4414 intr_func = bnx_msi;
4417 intr_func = bnx_intr_legacy;
4419 error = bus_setup_intr(sc->bnx_dev, sc->bnx_irq, INTR_MPSAFE,
4420 intr_func, sc, &sc->bnx_intrhand, sc->arpcom.ac_if.if_serializer);
4422 device_printf(sc->bnx_dev, "could not set up irq\n");
4429 bnx_free_intr(struct bnx_softc *sc)
4431 if (sc->bnx_irq != NULL) {
4432 bus_release_resource(sc->bnx_dev, SYS_RES_IRQ,
4433 sc->bnx_irq_rid, sc->bnx_irq);
4435 if (sc->bnx_irq_type == PCI_INTR_TYPE_MSI)
4436 pci_release_msi(sc->bnx_dev);