2 * Copyright (c) 2006-2007 Broadcom Corporation
3 * David Christensen <davidch@broadcom.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * 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. Neither the name of Broadcom Corporation nor the name of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written consent.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/dev/bce/if_bce.c,v 1.31 2007/05/16 23:34:11 davidch Exp $
31 * $DragonFly: src/sys/dev/netif/bce/if_bce.c,v 1.6 2008/05/26 14:23:25 sephe Exp $
35 * The following controllers are supported by this driver:
39 * The following controllers are not supported by this driver:
41 * BCM5706S A0, A1, A2, A3
43 * BCM5708S A0, B0, B1, B2
47 #include "opt_polling.h"
49 #include <sys/param.h>
51 #include <sys/endian.h>
52 #include <sys/kernel.h>
53 #include <sys/interrupt.h>
55 #include <sys/malloc.h>
56 #include <sys/queue.h>
58 #include <sys/random.h>
61 #include <sys/serialize.h>
62 #include <sys/socket.h>
63 #include <sys/sockio.h>
64 #include <sys/sysctl.h>
67 #include <net/ethernet.h>
69 #include <net/if_arp.h>
70 #include <net/if_dl.h>
71 #include <net/if_media.h>
72 #include <net/if_types.h>
73 #include <net/ifq_var.h>
74 #include <net/vlan/if_vlan_var.h>
75 #include <net/vlan/if_vlan_ether.h>
77 #include <dev/netif/mii_layer/mii.h>
78 #include <dev/netif/mii_layer/miivar.h>
80 #include <bus/pci/pcireg.h>
81 #include <bus/pci/pcivar.h>
83 #include "miibus_if.h"
85 #include "if_bcereg.h"
88 /****************************************************************************/
89 /* BCE Debug Options */
90 /****************************************************************************/
93 static uint32_t bce_debug = BCE_WARN;
97 * 1 = 1 in 2,147,483,648
98 * 256 = 1 in 8,388,608
99 * 2048 = 1 in 1,048,576
100 * 65536 = 1 in 32,768
101 * 1048576 = 1 in 2,048
104 * 1073741824 = 1 in 2
106 * bce_debug_l2fhdr_status_check:
107 * How often the l2_fhdr frame error check will fail.
109 * bce_debug_unexpected_attention:
110 * How often the unexpected attention check will fail.
112 * bce_debug_mbuf_allocation_failure:
113 * How often to simulate an mbuf allocation failure.
115 * bce_debug_dma_map_addr_failure:
116 * How often to simulate a DMA mapping failure.
118 * bce_debug_bootcode_running_failure:
119 * How often to simulate a bootcode failure.
121 static int bce_debug_l2fhdr_status_check = 0;
122 static int bce_debug_unexpected_attention = 0;
123 static int bce_debug_mbuf_allocation_failure = 0;
124 static int bce_debug_dma_map_addr_failure = 0;
125 static int bce_debug_bootcode_running_failure = 0;
127 #endif /* BCE_DEBUG */
130 /****************************************************************************/
131 /* PCI Device ID Table */
133 /* Used by bce_probe() to identify the devices supported by this driver. */
134 /****************************************************************************/
135 #define BCE_DEVDESC_MAX 64
137 static struct bce_type bce_devs[] = {
138 /* BCM5706C Controllers and OEM boards. */
139 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
140 "HP NC370T Multifunction Gigabit Server Adapter" },
141 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
142 "HP NC370i Multifunction Gigabit Server Adapter" },
143 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
144 "Broadcom NetXtreme II BCM5706 1000Base-T" },
146 /* BCM5706S controllers and OEM boards. */
147 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
148 "HP NC370F Multifunction Gigabit Server Adapter" },
149 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
150 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
152 /* BCM5708C controllers and OEM boards. */
153 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
154 "Broadcom NetXtreme II BCM5708 1000Base-T" },
156 /* BCM5708S controllers and OEM boards. */
157 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
158 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
163 /****************************************************************************/
164 /* Supported Flash NVRAM device data. */
165 /****************************************************************************/
166 static const struct flash_spec flash_table[] =
169 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
170 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
171 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
173 /* Expansion entry 0001 */
174 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
175 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
176 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
178 /* Saifun SA25F010 (non-buffered flash) */
179 /* strap, cfg1, & write1 need updates */
180 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
181 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
182 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
183 "Non-buffered flash (128kB)"},
184 /* Saifun SA25F020 (non-buffered flash) */
185 /* strap, cfg1, & write1 need updates */
186 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
187 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
188 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
189 "Non-buffered flash (256kB)"},
190 /* Expansion entry 0100 */
191 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
192 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
193 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
195 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
196 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
197 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
198 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
199 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
200 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
201 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
202 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
203 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
204 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
205 /* Saifun SA25F005 (non-buffered flash) */
206 /* strap, cfg1, & write1 need updates */
207 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
208 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
209 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
210 "Non-buffered flash (64kB)"},
212 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
213 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
214 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
216 /* Expansion entry 1001 */
217 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
218 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
219 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
221 /* Expansion entry 1010 */
222 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
223 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
224 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
226 /* ATMEL AT45DB011B (buffered flash) */
227 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
228 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
229 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
230 "Buffered flash (128kB)"},
231 /* Expansion entry 1100 */
232 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
233 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
234 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
236 /* Expansion entry 1101 */
237 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
238 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
239 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
241 /* Ateml Expansion entry 1110 */
242 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
243 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
244 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
245 "Entry 1110 (Atmel)"},
246 /* ATMEL AT45DB021B (buffered flash) */
247 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
248 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
249 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
250 "Buffered flash (256kB)"},
254 /****************************************************************************/
255 /* DragonFly device entry points. */
256 /****************************************************************************/
257 static int bce_probe(device_t);
258 static int bce_attach(device_t);
259 static int bce_detach(device_t);
260 static void bce_shutdown(device_t);
262 /****************************************************************************/
263 /* BCE Debug Data Structure Dump Routines */
264 /****************************************************************************/
266 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
267 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
268 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
269 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
270 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
271 static void bce_dump_l2fhdr(struct bce_softc *, int,
272 struct l2_fhdr *) __unused;
273 static void bce_dump_tx_chain(struct bce_softc *, int, int);
274 static void bce_dump_rx_chain(struct bce_softc *, int, int);
275 static void bce_dump_status_block(struct bce_softc *);
276 static void bce_dump_driver_state(struct bce_softc *);
277 static void bce_dump_stats_block(struct bce_softc *) __unused;
278 static void bce_dump_hw_state(struct bce_softc *);
279 static void bce_dump_txp_state(struct bce_softc *);
280 static void bce_dump_rxp_state(struct bce_softc *) __unused;
281 static void bce_dump_tpat_state(struct bce_softc *) __unused;
282 static void bce_freeze_controller(struct bce_softc *) __unused;
283 static void bce_unfreeze_controller(struct bce_softc *) __unused;
284 static void bce_breakpoint(struct bce_softc *);
285 #endif /* BCE_DEBUG */
288 /****************************************************************************/
289 /* BCE Register/Memory Access Routines */
290 /****************************************************************************/
291 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
292 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
293 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
294 static int bce_miibus_read_reg(device_t, int, int);
295 static int bce_miibus_write_reg(device_t, int, int, int);
296 static void bce_miibus_statchg(device_t);
299 /****************************************************************************/
300 /* BCE NVRAM Access Routines */
301 /****************************************************************************/
302 static int bce_acquire_nvram_lock(struct bce_softc *);
303 static int bce_release_nvram_lock(struct bce_softc *);
304 static void bce_enable_nvram_access(struct bce_softc *);
305 static void bce_disable_nvram_access(struct bce_softc *);
306 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
308 static int bce_init_nvram(struct bce_softc *);
309 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
310 static int bce_nvram_test(struct bce_softc *);
311 #ifdef BCE_NVRAM_WRITE_SUPPORT
312 static int bce_enable_nvram_write(struct bce_softc *);
313 static void bce_disable_nvram_write(struct bce_softc *);
314 static int bce_nvram_erase_page(struct bce_softc *, uint32_t);
315 static int bce_nvram_write_dword(struct bce_softc *, uint32_t, uint8_t *, uint32_t);
316 static int bce_nvram_write(struct bce_softc *, uint32_t, uint8_t *,
320 /****************************************************************************/
321 /* BCE DMA Allocate/Free Routines */
322 /****************************************************************************/
323 static int bce_dma_alloc(struct bce_softc *);
324 static void bce_dma_free(struct bce_softc *);
325 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
326 static void bce_dma_map_mbuf(void *, bus_dma_segment_t *, int,
329 /****************************************************************************/
330 /* BCE Firmware Synchronization and Load */
331 /****************************************************************************/
332 static int bce_fw_sync(struct bce_softc *, uint32_t);
333 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
335 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
337 static void bce_init_cpus(struct bce_softc *);
339 static void bce_stop(struct bce_softc *);
340 static int bce_reset(struct bce_softc *, uint32_t);
341 static int bce_chipinit(struct bce_softc *);
342 static int bce_blockinit(struct bce_softc *);
343 static int bce_newbuf_std(struct bce_softc *, struct mbuf *,
344 uint16_t *, uint16_t *, uint32_t *);
346 static int bce_init_tx_chain(struct bce_softc *);
347 static int bce_init_rx_chain(struct bce_softc *);
348 static void bce_free_rx_chain(struct bce_softc *);
349 static void bce_free_tx_chain(struct bce_softc *);
351 static int bce_encap(struct bce_softc *, struct mbuf **);
352 static void bce_start(struct ifnet *);
353 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
354 static void bce_watchdog(struct ifnet *);
355 static int bce_ifmedia_upd(struct ifnet *);
356 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
357 static void bce_init(void *);
358 static void bce_mgmt_init(struct bce_softc *);
360 static void bce_init_context(struct bce_softc *);
361 static void bce_get_mac_addr(struct bce_softc *);
362 static void bce_set_mac_addr(struct bce_softc *);
363 static void bce_phy_intr(struct bce_softc *);
364 static void bce_rx_intr(struct bce_softc *, int);
365 static void bce_tx_intr(struct bce_softc *);
366 static void bce_disable_intr(struct bce_softc *);
367 static void bce_enable_intr(struct bce_softc *);
369 #ifdef DEVICE_POLLING
370 static void bce_poll(struct ifnet *, enum poll_cmd, int);
372 static void bce_intr(void *);
373 static void bce_set_rx_mode(struct bce_softc *);
374 static void bce_stats_update(struct bce_softc *);
375 static void bce_tick(void *);
376 static void bce_tick_serialized(struct bce_softc *);
377 static void bce_add_sysctls(struct bce_softc *);
380 /****************************************************************************/
381 /* DragonFly device dispatch table. */
382 /****************************************************************************/
383 static device_method_t bce_methods[] = {
384 /* Device interface */
385 DEVMETHOD(device_probe, bce_probe),
386 DEVMETHOD(device_attach, bce_attach),
387 DEVMETHOD(device_detach, bce_detach),
388 DEVMETHOD(device_shutdown, bce_shutdown),
391 DEVMETHOD(bus_print_child, bus_generic_print_child),
392 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
395 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
396 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
397 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
402 static driver_t bce_driver = {
405 sizeof(struct bce_softc)
408 static devclass_t bce_devclass;
410 MODULE_DEPEND(bce, pci, 1, 1, 1);
411 MODULE_DEPEND(bce, ether, 1, 1, 1);
412 MODULE_DEPEND(bce, miibus, 1, 1, 1);
414 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
415 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
418 /****************************************************************************/
419 /* Device probe function. */
421 /* Compares the device to the driver's list of supported devices and */
422 /* reports back to the OS whether this is the right driver for the device. */
425 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
426 /****************************************************************************/
428 bce_probe(device_t dev)
431 uint16_t vid, did, svid, sdid;
433 /* Get the data for the device to be probed. */
434 vid = pci_get_vendor(dev);
435 did = pci_get_device(dev);
436 svid = pci_get_subvendor(dev);
437 sdid = pci_get_subdevice(dev);
439 /* Look through the list of known devices for a match. */
440 for (t = bce_devs; t->bce_name != NULL; ++t) {
441 if (vid == t->bce_vid && did == t->bce_did &&
442 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
443 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
444 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
447 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
449 /* Print out the device identity. */
450 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
452 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
454 device_set_desc_copy(dev, descbuf);
455 kfree(descbuf, M_TEMP);
463 /****************************************************************************/
464 /* Device attach function. */
466 /* Allocates device resources, performs secondary chip identification, */
467 /* resets and initializes the hardware, and initializes driver instance */
471 /* 0 on success, positive value on failure. */
472 /****************************************************************************/
474 bce_attach(device_t dev)
476 struct bce_softc *sc = device_get_softc(dev);
477 struct ifnet *ifp = &sc->arpcom.ac_if;
485 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
487 pci_enable_busmaster(dev);
489 /* Allocate PCI memory resources. */
491 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
492 RF_ACTIVE | PCI_RF_DENSE);
493 if (sc->bce_res_mem == NULL) {
494 device_printf(dev, "PCI memory allocation failed\n");
497 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
498 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
500 /* Allocate PCI IRQ resources. */
502 count = pci_msi_count(dev);
503 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
505 sc->bce_flags |= BCE_USING_MSI_FLAG;
509 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
510 RF_SHAREABLE | RF_ACTIVE);
511 if (sc->bce_res_irq == NULL) {
512 device_printf(dev, "PCI map interrupt failed\n");
518 * Configure byte swap and enable indirect register access.
519 * Rely on CPU to do target byte swapping on big endian systems.
520 * Access to registers outside of PCI configurtion space are not
521 * valid until this is done.
523 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
524 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
525 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
527 /* Save ASIC revsion info. */
528 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
530 /* Weed out any non-production controller revisions. */
531 switch(BCE_CHIP_ID(sc)) {
532 case BCE_CHIP_ID_5706_A0:
533 case BCE_CHIP_ID_5706_A1:
534 case BCE_CHIP_ID_5708_A0:
535 case BCE_CHIP_ID_5708_B0:
536 device_printf(dev, "Unsupported chip id 0x%08x!\n",
543 * The embedded PCIe to PCI-X bridge (EPB)
544 * in the 5708 cannot address memory above
545 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
547 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
548 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
550 sc->max_bus_addr = BUS_SPACE_MAXADDR;
553 * Find the base address for shared memory access.
554 * Newer versions of bootcode use a signature and offset
555 * while older versions use a fixed address.
557 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
558 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
559 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0);
561 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
563 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
565 /* Get PCI bus information (speed and type). */
566 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
567 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
570 sc->bce_flags |= BCE_PCIX_FLAG;
572 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
573 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
575 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
576 sc->bus_speed_mhz = 133;
579 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
580 sc->bus_speed_mhz = 100;
583 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
584 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
585 sc->bus_speed_mhz = 66;
588 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
589 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
590 sc->bus_speed_mhz = 50;
593 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
594 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
595 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
596 sc->bus_speed_mhz = 33;
600 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
601 sc->bus_speed_mhz = 66;
603 sc->bus_speed_mhz = 33;
606 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
607 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
609 device_printf(dev, "ASIC ID 0x%08X; Revision (%c%d); PCI%s %s %dMHz\n",
611 ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
612 (BCE_CHIP_ID(sc) & 0x0ff0) >> 4,
613 (sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : "",
614 (sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
615 "32-bit" : "64-bit", sc->bus_speed_mhz);
617 /* Reset the controller. */
618 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
622 /* Initialize the controller. */
623 rc = bce_chipinit(sc);
625 device_printf(dev, "Controller initialization failed!\n");
629 /* Perform NVRAM test. */
630 rc = bce_nvram_test(sc);
632 device_printf(dev, "NVRAM test failed!\n");
636 /* Fetch the permanent Ethernet MAC address. */
637 bce_get_mac_addr(sc);
640 * Trip points control how many BDs
641 * should be ready before generating an
642 * interrupt while ticks control how long
643 * a BD can sit in the chain before
644 * generating an interrupt. Set the default
645 * values for the RX and TX rings.
649 /* Force more frequent interrupts. */
650 sc->bce_tx_quick_cons_trip_int = 1;
651 sc->bce_tx_quick_cons_trip = 1;
652 sc->bce_tx_ticks_int = 0;
653 sc->bce_tx_ticks = 0;
655 sc->bce_rx_quick_cons_trip_int = 1;
656 sc->bce_rx_quick_cons_trip = 1;
657 sc->bce_rx_ticks_int = 0;
658 sc->bce_rx_ticks = 0;
660 sc->bce_tx_quick_cons_trip_int = 20;
661 sc->bce_tx_quick_cons_trip = 20;
662 sc->bce_tx_ticks_int = 80;
663 sc->bce_tx_ticks = 80;
665 sc->bce_rx_quick_cons_trip_int = 6;
666 sc->bce_rx_quick_cons_trip = 6;
667 sc->bce_rx_ticks_int = 18;
668 sc->bce_rx_ticks = 18;
671 /* Update statistics once every second. */
672 sc->bce_stats_ticks = 1000000 & 0xffff00;
675 * The copper based NetXtreme II controllers
676 * use an integrated PHY at address 1 while
677 * the SerDes controllers use a PHY at
680 sc->bce_phy_addr = 1;
682 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
683 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
684 sc->bce_flags |= BCE_NO_WOL_FLAG;
685 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708) {
686 sc->bce_phy_addr = 2;
687 val = REG_RD_IND(sc, sc->bce_shmem_base +
688 BCE_SHARED_HW_CFG_CONFIG);
689 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
690 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
694 /* Allocate DMA memory resources. */
695 rc = bce_dma_alloc(sc);
697 device_printf(dev, "DMA resource allocation failed!\n");
701 /* Initialize the ifnet interface. */
703 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
704 ifp->if_ioctl = bce_ioctl;
705 ifp->if_start = bce_start;
706 ifp->if_init = bce_init;
707 ifp->if_watchdog = bce_watchdog;
708 #ifdef DEVICE_POLLING
709 ifp->if_poll = bce_poll;
711 ifp->if_mtu = ETHERMTU;
712 ifp->if_hwassist = BCE_IF_HWASSIST;
713 ifp->if_capabilities = BCE_IF_CAPABILITIES;
714 ifp->if_capenable = ifp->if_capabilities;
715 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
716 ifq_set_ready(&ifp->if_snd);
718 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
719 ifp->if_baudrate = IF_Gbps(2.5);
721 ifp->if_baudrate = IF_Gbps(1);
723 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
724 sc->mbuf_alloc_size = MCLBYTES;
726 /* Look for our PHY. */
727 rc = mii_phy_probe(dev, &sc->bce_miibus,
728 bce_ifmedia_upd, bce_ifmedia_sts);
730 device_printf(dev, "PHY probe failed!\n");
734 /* Attach to the Ethernet interface list. */
735 ether_ifattach(ifp, sc->eaddr, NULL);
737 callout_init(&sc->bce_stat_ch);
739 /* Hookup IRQ last. */
740 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_NETSAFE, bce_intr, sc,
741 &sc->bce_intrhand, ifp->if_serializer);
743 device_printf(dev, "Failed to setup IRQ!\n");
748 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
749 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
751 /* Print some important debugging info. */
752 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
754 /* Add the supported sysctls to the kernel. */
757 /* Get the firmware running so IPMI still works */
767 /****************************************************************************/
768 /* Device detach function. */
770 /* Stops the controller, resets the controller, and releases resources. */
773 /* 0 on success, positive value on failure. */
774 /****************************************************************************/
776 bce_detach(device_t dev)
778 struct bce_softc *sc = device_get_softc(dev);
780 if (device_is_attached(dev)) {
781 struct ifnet *ifp = &sc->arpcom.ac_if;
783 /* Stop and reset the controller. */
784 lwkt_serialize_enter(ifp->if_serializer);
786 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
787 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
788 lwkt_serialize_exit(ifp->if_serializer);
793 /* If we have a child device on the MII bus remove it too. */
795 device_delete_child(dev, sc->bce_miibus);
796 bus_generic_detach(dev);
798 if (sc->bce_res_irq != NULL) {
799 bus_release_resource(dev, SYS_RES_IRQ,
800 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
805 if (sc->bce_flags & BCE_USING_MSI_FLAG)
806 pci_release_msi(dev);
809 if (sc->bce_res_mem != NULL) {
810 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
816 if (sc->bce_sysctl_tree != NULL)
817 sysctl_ctx_free(&sc->bce_sysctl_ctx);
823 /****************************************************************************/
824 /* Device shutdown function. */
826 /* Stops and resets the controller. */
830 /****************************************************************************/
832 bce_shutdown(device_t dev)
834 struct bce_softc *sc = device_get_softc(dev);
835 struct ifnet *ifp = &sc->arpcom.ac_if;
837 lwkt_serialize_enter(ifp->if_serializer);
839 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
840 lwkt_serialize_exit(ifp->if_serializer);
844 /****************************************************************************/
845 /* Indirect register read. */
847 /* Reads NetXtreme II registers using an index/data register pair in PCI */
848 /* configuration space. Using this mechanism avoids issues with posted */
849 /* reads but is much slower than memory-mapped I/O. */
852 /* The value of the register. */
853 /****************************************************************************/
855 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
857 device_t dev = sc->bce_dev;
859 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
863 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
864 DBPRINT(sc, BCE_EXCESSIVE,
865 "%s(); offset = 0x%08X, val = 0x%08X\n",
866 __func__, offset, val);
870 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
875 /****************************************************************************/
876 /* Indirect register write. */
878 /* Writes NetXtreme II registers using an index/data register pair in PCI */
879 /* configuration space. Using this mechanism avoids issues with posted */
880 /* writes but is muchh slower than memory-mapped I/O. */
884 /****************************************************************************/
886 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
888 device_t dev = sc->bce_dev;
890 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
891 __func__, offset, val);
893 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
894 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
898 /****************************************************************************/
899 /* Context memory write. */
901 /* The NetXtreme II controller uses context memory to track connection */
902 /* information for L2 and higher network protocols. */
906 /****************************************************************************/
908 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t offset,
911 DBPRINT(sc, BCE_EXCESSIVE, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
912 "val = 0x%08X\n", __func__, cid_addr, offset, val);
915 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
916 REG_WR(sc, BCE_CTX_DATA, val);
920 /****************************************************************************/
921 /* PHY register read. */
923 /* Implements register reads on the MII bus. */
926 /* The value of the register. */
927 /****************************************************************************/
929 bce_miibus_read_reg(device_t dev, int phy, int reg)
931 struct bce_softc *sc = device_get_softc(dev);
935 /* Make sure we are accessing the correct PHY address. */
936 if (phy != sc->bce_phy_addr) {
937 DBPRINT(sc, BCE_VERBOSE,
938 "Invalid PHY address %d for PHY read!\n", phy);
942 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
943 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
944 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
946 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
947 REG_RD(sc, BCE_EMAC_MDIO_MODE);
952 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
953 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
954 BCE_EMAC_MDIO_COMM_START_BUSY;
955 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
957 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
960 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
961 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
964 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
965 val &= BCE_EMAC_MDIO_COMM_DATA;
970 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
971 if_printf(&sc->arpcom.ac_if,
972 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
976 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
979 DBPRINT(sc, BCE_EXCESSIVE,
980 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
981 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
983 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
984 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
985 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
987 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
988 REG_RD(sc, BCE_EMAC_MDIO_MODE);
992 return (val & 0xffff);
996 /****************************************************************************/
997 /* PHY register write. */
999 /* Implements register writes on the MII bus. */
1002 /* The value of the register. */
1003 /****************************************************************************/
1005 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1007 struct bce_softc *sc = device_get_softc(dev);
1011 /* Make sure we are accessing the correct PHY address. */
1012 if (phy != sc->bce_phy_addr) {
1013 DBPRINT(sc, BCE_WARN,
1014 "Invalid PHY address %d for PHY write!\n", phy);
1018 DBPRINT(sc, BCE_EXCESSIVE,
1019 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1020 __func__, phy, (uint16_t)(reg & 0xffff),
1021 (uint16_t)(val & 0xffff));
1023 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1024 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1025 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1027 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1028 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1033 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1034 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1035 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1036 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1038 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1041 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1042 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1048 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1049 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1051 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1052 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1053 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1055 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1056 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1064 /****************************************************************************/
1065 /* MII bus status change. */
1067 /* Called by the MII bus driver when the PHY establishes link to set the */
1068 /* MAC interface registers. */
1072 /****************************************************************************/
1074 bce_miibus_statchg(device_t dev)
1076 struct bce_softc *sc = device_get_softc(dev);
1077 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1079 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1080 mii->mii_media_active);
1083 /* Decode the interface media flags. */
1084 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1085 switch(IFM_TYPE(mii->mii_media_active)) {
1087 kprintf("Ethernet )");
1090 kprintf("Unknown )");
1094 kprintf(" Media Options: ( ");
1095 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1097 kprintf("Autoselect )");
1100 kprintf("Manual )");
1106 kprintf("10Base-T )");
1109 kprintf("100Base-TX )");
1112 kprintf("1000Base-SX )");
1115 kprintf("1000Base-T )");
1122 kprintf(" Global Options: (");
1123 if (mii->mii_media_active & IFM_FDX)
1124 kprintf(" FullDuplex");
1125 if (mii->mii_media_active & IFM_HDX)
1126 kprintf(" HalfDuplex");
1127 if (mii->mii_media_active & IFM_LOOP)
1128 kprintf(" Loopback");
1129 if (mii->mii_media_active & IFM_FLAG0)
1131 if (mii->mii_media_active & IFM_FLAG1)
1133 if (mii->mii_media_active & IFM_FLAG2)
1138 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1141 * Set MII or GMII interface based on the speed negotiated
1144 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1145 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1146 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1147 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1149 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1150 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1154 * Set half or full duplex based on the duplicity negotiated
1157 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1158 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1159 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1161 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1162 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1167 /****************************************************************************/
1168 /* Acquire NVRAM lock. */
1170 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1171 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1172 /* for use by the driver. */
1175 /* 0 on success, positive value on failure. */
1176 /****************************************************************************/
1178 bce_acquire_nvram_lock(struct bce_softc *sc)
1183 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1185 /* Request access to the flash interface. */
1186 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1187 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1188 val = REG_RD(sc, BCE_NVM_SW_ARB);
1189 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1195 if (j >= NVRAM_TIMEOUT_COUNT) {
1196 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1203 /****************************************************************************/
1204 /* Release NVRAM lock. */
1206 /* When the caller is finished accessing NVRAM the lock must be released. */
1207 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1208 /* for use by the driver. */
1211 /* 0 on success, positive value on failure. */
1212 /****************************************************************************/
1214 bce_release_nvram_lock(struct bce_softc *sc)
1219 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1222 * Relinquish nvram interface.
1224 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1226 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1227 val = REG_RD(sc, BCE_NVM_SW_ARB);
1228 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1234 if (j >= NVRAM_TIMEOUT_COUNT) {
1235 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1242 #ifdef BCE_NVRAM_WRITE_SUPPORT
1243 /****************************************************************************/
1244 /* Enable NVRAM write access. */
1246 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1249 /* 0 on success, positive value on failure. */
1250 /****************************************************************************/
1252 bce_enable_nvram_write(struct bce_softc *sc)
1256 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM write.\n");
1258 val = REG_RD(sc, BCE_MISC_CFG);
1259 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1261 if (!sc->bce_flash_info->buffered) {
1264 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1265 REG_WR(sc, BCE_NVM_COMMAND,
1266 BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1268 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1271 val = REG_RD(sc, BCE_NVM_COMMAND);
1272 if (val & BCE_NVM_COMMAND_DONE)
1276 if (j >= NVRAM_TIMEOUT_COUNT) {
1277 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1285 /****************************************************************************/
1286 /* Disable NVRAM write access. */
1288 /* When the caller is finished writing to NVRAM write access must be */
1293 /****************************************************************************/
1295 bce_disable_nvram_write(struct bce_softc *sc)
1299 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM write.\n");
1301 val = REG_RD(sc, BCE_MISC_CFG);
1302 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1304 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1307 /****************************************************************************/
1308 /* Enable NVRAM access. */
1310 /* Before accessing NVRAM for read or write operations the caller must */
1311 /* enabled NVRAM access. */
1315 /****************************************************************************/
1317 bce_enable_nvram_access(struct bce_softc *sc)
1321 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1323 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1324 /* Enable both bits, even on read. */
1325 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1326 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1330 /****************************************************************************/
1331 /* Disable NVRAM access. */
1333 /* When the caller is finished accessing NVRAM access must be disabled. */
1337 /****************************************************************************/
1339 bce_disable_nvram_access(struct bce_softc *sc)
1343 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1345 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1347 /* Disable both bits, even after read. */
1348 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1349 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1353 #ifdef BCE_NVRAM_WRITE_SUPPORT
1354 /****************************************************************************/
1355 /* Erase NVRAM page before writing. */
1357 /* Non-buffered flash parts require that a page be erased before it is */
1361 /* 0 on success, positive value on failure. */
1362 /****************************************************************************/
1364 bce_nvram_erase_page(struct bce_softc *sc, uint32_t offset)
1369 /* Buffered flash doesn't require an erase. */
1370 if (sc->bce_flash_info->buffered)
1373 DBPRINT(sc, BCE_VERBOSE, "Erasing NVRAM page.\n");
1375 /* Build an erase command. */
1376 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
1377 BCE_NVM_COMMAND_DOIT;
1380 * Clear the DONE bit separately, set the NVRAM adress to erase,
1381 * and issue the erase command.
1383 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1384 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1385 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1387 /* Wait for completion. */
1388 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1393 val = REG_RD(sc, BCE_NVM_COMMAND);
1394 if (val & BCE_NVM_COMMAND_DONE)
1398 if (j >= NVRAM_TIMEOUT_COUNT) {
1399 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
1404 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1407 /****************************************************************************/
1408 /* Read a dword (32 bits) from NVRAM. */
1410 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1411 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1414 /* 0 on success and the 32 bit value read, positive value on failure. */
1415 /****************************************************************************/
1417 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1423 /* Build the command word. */
1424 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1426 /* Calculate the offset for buffered flash. */
1427 if (sc->bce_flash_info->buffered) {
1428 offset = ((offset / sc->bce_flash_info->page_size) <<
1429 sc->bce_flash_info->page_bits) +
1430 (offset % sc->bce_flash_info->page_size);
1434 * Clear the DONE bit separately, set the address to read,
1435 * and issue the read.
1437 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1438 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1439 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1441 /* Wait for completion. */
1442 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1447 val = REG_RD(sc, BCE_NVM_COMMAND);
1448 if (val & BCE_NVM_COMMAND_DONE) {
1449 val = REG_RD(sc, BCE_NVM_READ);
1452 memcpy(ret_val, &val, 4);
1457 /* Check for errors. */
1458 if (i >= NVRAM_TIMEOUT_COUNT) {
1459 if_printf(&sc->arpcom.ac_if,
1460 "Timeout error reading NVRAM at offset 0x%08X!\n",
1468 #ifdef BCE_NVRAM_WRITE_SUPPORT
1469 /****************************************************************************/
1470 /* Write a dword (32 bits) to NVRAM. */
1472 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
1473 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
1474 /* enabled NVRAM write access. */
1477 /* 0 on success, positive value on failure. */
1478 /****************************************************************************/
1480 bce_nvram_write_dword(struct bce_softc *sc, uint32_t offset, uint8_t *val,
1483 uint32_t cmd, val32;
1486 /* Build the command word. */
1487 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
1489 /* Calculate the offset for buffered flash. */
1490 if (sc->bce_flash_info->buffered) {
1491 offset = ((offset / sc->bce_flash_info->page_size) <<
1492 sc->bce_flash_info->page_bits) +
1493 (offset % sc->bce_flash_info->page_size);
1497 * Clear the DONE bit separately, convert NVRAM data to big-endian,
1498 * set the NVRAM address to write, and issue the write command
1500 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1501 memcpy(&val32, val, 4);
1502 val32 = htobe32(val32);
1503 REG_WR(sc, BCE_NVM_WRITE, val32);
1504 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1505 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1507 /* Wait for completion. */
1508 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1511 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
1514 if (j >= NVRAM_TIMEOUT_COUNT) {
1515 if_printf(&sc->arpcom.ac_if,
1516 "Timeout error writing NVRAM at offset 0x%08X\n",
1522 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1525 /****************************************************************************/
1526 /* Initialize NVRAM access. */
1528 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1529 /* access that device. */
1532 /* 0 on success, positive value on failure. */
1533 /****************************************************************************/
1535 bce_init_nvram(struct bce_softc *sc)
1538 int j, entry_count, rc = 0;
1539 const struct flash_spec *flash;
1541 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1543 /* Determine the selected interface. */
1544 val = REG_RD(sc, BCE_NVM_CFG1);
1546 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1549 * Flash reconfiguration is required to support additional
1550 * NVRAM devices not directly supported in hardware.
1551 * Check if the flash interface was reconfigured
1555 if (val & 0x40000000) {
1556 /* Flash interface reconfigured by bootcode. */
1558 DBPRINT(sc, BCE_INFO_LOAD,
1559 "%s(): Flash WAS reconfigured.\n", __func__);
1561 for (j = 0, flash = flash_table; j < entry_count;
1563 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1564 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1565 sc->bce_flash_info = flash;
1570 /* Flash interface not yet reconfigured. */
1573 DBPRINT(sc, BCE_INFO_LOAD,
1574 "%s(): Flash was NOT reconfigured.\n", __func__);
1576 if (val & (1 << 23))
1577 mask = FLASH_BACKUP_STRAP_MASK;
1579 mask = FLASH_STRAP_MASK;
1581 /* Look for the matching NVRAM device configuration data. */
1582 for (j = 0, flash = flash_table; j < entry_count;
1584 /* Check if the device matches any of the known devices. */
1585 if ((val & mask) == (flash->strapping & mask)) {
1586 /* Found a device match. */
1587 sc->bce_flash_info = flash;
1589 /* Request access to the flash interface. */
1590 rc = bce_acquire_nvram_lock(sc);
1594 /* Reconfigure the flash interface. */
1595 bce_enable_nvram_access(sc);
1596 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1597 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1598 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1599 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1600 bce_disable_nvram_access(sc);
1601 bce_release_nvram_lock(sc);
1607 /* Check if a matching device was found. */
1608 if (j == entry_count) {
1609 sc->bce_flash_info = NULL;
1610 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1614 /* Write the flash config data to the shared memory interface. */
1615 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_SHARED_HW_CFG_CONFIG2) &
1616 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1618 sc->bce_flash_size = val;
1620 sc->bce_flash_size = sc->bce_flash_info->total_size;
1622 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1623 __func__, sc->bce_flash_info->total_size);
1625 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1631 /****************************************************************************/
1632 /* Read an arbitrary range of data from NVRAM. */
1634 /* Prepares the NVRAM interface for access and reads the requested data */
1635 /* into the supplied buffer. */
1638 /* 0 on success and the data read, positive value on failure. */
1639 /****************************************************************************/
1641 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1644 uint32_t cmd_flags, offset32, len32, extra;
1650 /* Request access to the flash interface. */
1651 rc = bce_acquire_nvram_lock(sc);
1655 /* Enable access to flash interface */
1656 bce_enable_nvram_access(sc);
1664 /* XXX should we release nvram lock if read_dword() fails? */
1670 pre_len = 4 - (offset & 3);
1672 if (pre_len >= len32) {
1674 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1676 cmd_flags = BCE_NVM_COMMAND_FIRST;
1679 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1683 memcpy(ret_buf, buf + (offset & 3), pre_len);
1691 extra = 4 - (len32 & 3);
1692 len32 = (len32 + 4) & ~3;
1699 cmd_flags = BCE_NVM_COMMAND_LAST;
1701 cmd_flags = BCE_NVM_COMMAND_FIRST |
1702 BCE_NVM_COMMAND_LAST;
1704 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1706 memcpy(ret_buf, buf, 4 - extra);
1707 } else if (len32 > 0) {
1710 /* Read the first word. */
1714 cmd_flags = BCE_NVM_COMMAND_FIRST;
1716 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1718 /* Advance to the next dword. */
1723 while (len32 > 4 && rc == 0) {
1724 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1726 /* Advance to the next dword. */
1735 cmd_flags = BCE_NVM_COMMAND_LAST;
1736 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1738 memcpy(ret_buf, buf, 4 - extra);
1741 /* Disable access to flash interface and release the lock. */
1742 bce_disable_nvram_access(sc);
1743 bce_release_nvram_lock(sc);
1749 #ifdef BCE_NVRAM_WRITE_SUPPORT
1750 /****************************************************************************/
1751 /* Write an arbitrary range of data from NVRAM. */
1753 /* Prepares the NVRAM interface for write access and writes the requested */
1754 /* data from the supplied buffer. The caller is responsible for */
1755 /* calculating any appropriate CRCs. */
1758 /* 0 on success, positive value on failure. */
1759 /****************************************************************************/
1761 bce_nvram_write(struct bce_softc *sc, uint32_t offset, uint8_t *data_buf,
1764 uint32_t written, offset32, len32;
1765 uint8_t *buf, start[4], end[4];
1767 int align_start, align_end;
1773 align_start = (offset32 & 3);
1777 len32 += align_start;
1778 rc = bce_nvram_read(sc, offset32, start, 4);
1784 if (len32 > 4 || !align_start) {
1785 align_end = 4 - (len32 & 3);
1787 rc = bce_nvram_read(sc, offset32 + len32 - 4, end, 4);
1793 if (align_start || align_end) {
1794 buf = kmalloc(len32, M_DEVBUF, M_NOWAIT);
1798 memcpy(buf, start, 4);
1800 memcpy(buf + len32 - 4, end, 4);
1801 memcpy(buf + align_start, data_buf, buf_size);
1805 while (written < len32 && rc == 0) {
1806 uint32_t page_start, page_end, data_start, data_end;
1807 uint32_t addr, cmd_flags;
1809 uint8_t flash_buffer[264];
1811 /* Find the page_start addr */
1812 page_start = offset32 + written;
1813 page_start -= (page_start % sc->bce_flash_info->page_size);
1814 /* Find the page_end addr */
1815 page_end = page_start + sc->bce_flash_info->page_size;
1816 /* Find the data_start addr */
1817 data_start = (written == 0) ? offset32 : page_start;
1818 /* Find the data_end addr */
1819 data_end = (page_end > offset32 + len32) ? (offset32 + len32)
1822 /* Request access to the flash interface. */
1823 rc = bce_acquire_nvram_lock(sc);
1825 goto nvram_write_end;
1827 /* Enable access to flash interface */
1828 bce_enable_nvram_access(sc);
1830 cmd_flags = BCE_NVM_COMMAND_FIRST;
1831 if (sc->bce_flash_info->buffered == 0) {
1835 * Read the whole page into the buffer
1836 * (non-buffer flash only)
1838 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
1839 if (j == (sc->bce_flash_info->page_size - 4))
1840 cmd_flags |= BCE_NVM_COMMAND_LAST;
1842 rc = bce_nvram_read_dword(sc, page_start + j,
1846 goto nvram_write_end;
1852 /* Enable writes to flash interface (unlock write-protect) */
1853 rc = bce_enable_nvram_write(sc);
1855 goto nvram_write_end;
1857 /* Erase the page */
1858 rc = bce_nvram_erase_page(sc, page_start);
1860 goto nvram_write_end;
1862 /* Re-enable the write again for the actual write */
1863 bce_enable_nvram_write(sc);
1865 /* Loop to write back the buffer data from page_start to
1868 if (sc->bce_flash_info->buffered == 0) {
1869 for (addr = page_start; addr < data_start;
1870 addr += 4, i += 4) {
1871 rc = bce_nvram_write_dword(sc, addr,
1875 goto nvram_write_end;
1881 /* Loop to write the new data from data_start to data_end */
1882 for (addr = data_start; addr < data_end; addr += 4, i++) {
1883 if (addr == page_end - 4 ||
1884 (sc->bce_flash_info->buffered &&
1885 addr == data_end - 4))
1886 cmd_flags |= BCE_NVM_COMMAND_LAST;
1888 rc = bce_nvram_write_dword(sc, addr, buf, cmd_flags);
1890 goto nvram_write_end;
1896 /* Loop to write back the buffer data from data_end
1898 if (sc->bce_flash_info->buffered == 0) {
1899 for (addr = data_end; addr < page_end;
1900 addr += 4, i += 4) {
1901 if (addr == page_end-4)
1902 cmd_flags = BCE_NVM_COMMAND_LAST;
1904 rc = bce_nvram_write_dword(sc, addr,
1905 &flash_buffer[i], cmd_flags);
1907 goto nvram_write_end;
1913 /* Disable writes to flash interface (lock write-protect) */
1914 bce_disable_nvram_write(sc);
1916 /* Disable access to flash interface */
1917 bce_disable_nvram_access(sc);
1918 bce_release_nvram_lock(sc);
1920 /* Increment written */
1921 written += data_end - data_start;
1925 if (align_start || align_end)
1926 kfree(buf, M_DEVBUF);
1929 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1932 /****************************************************************************/
1933 /* Verifies that NVRAM is accessible and contains valid data. */
1935 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1939 /* 0 on success, positive value on failure. */
1940 /****************************************************************************/
1942 bce_nvram_test(struct bce_softc *sc)
1944 uint32_t buf[BCE_NVRAM_SIZE / 4];
1945 uint32_t magic, csum;
1946 uint8_t *data = (uint8_t *)buf;
1950 * Check that the device NVRAM is valid by reading
1951 * the magic value at offset 0.
1953 rc = bce_nvram_read(sc, 0, data, 4);
1957 magic = be32toh(buf[0]);
1958 if (magic != BCE_NVRAM_MAGIC) {
1959 if_printf(&sc->arpcom.ac_if,
1960 "Invalid NVRAM magic value! Expected: 0x%08X, "
1961 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1966 * Verify that the device NVRAM includes valid
1967 * configuration data.
1969 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1973 csum = ether_crc32_le(data, 0x100);
1974 if (csum != BCE_CRC32_RESIDUAL) {
1975 if_printf(&sc->arpcom.ac_if,
1976 "Invalid Manufacturing Information NVRAM CRC! "
1977 "Expected: 0x%08X, Found: 0x%08X\n",
1978 BCE_CRC32_RESIDUAL, csum);
1982 csum = ether_crc32_le(data + 0x100, 0x100);
1983 if (csum != BCE_CRC32_RESIDUAL) {
1984 if_printf(&sc->arpcom.ac_if,
1985 "Invalid Feature Configuration Information "
1986 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1987 BCE_CRC32_RESIDUAL, csum);
1994 /****************************************************************************/
1995 /* Free any DMA memory owned by the driver. */
1997 /* Scans through each data structre that requires DMA memory and frees */
1998 /* the memory if allocated. */
2002 /****************************************************************************/
2004 bce_dma_free(struct bce_softc *sc)
2008 /* Destroy the status block. */
2009 if (sc->status_tag != NULL) {
2010 if (sc->status_block != NULL) {
2011 bus_dmamap_unload(sc->status_tag, sc->status_map);
2012 bus_dmamem_free(sc->status_tag, sc->status_block,
2015 bus_dma_tag_destroy(sc->status_tag);
2019 /* Destroy the statistics block. */
2020 if (sc->stats_tag != NULL) {
2021 if (sc->stats_block != NULL) {
2022 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2023 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2026 bus_dma_tag_destroy(sc->stats_tag);
2029 /* Destroy the TX buffer descriptor DMA stuffs. */
2030 if (sc->tx_bd_chain_tag != NULL) {
2031 for (i = 0; i < TX_PAGES; i++) {
2032 if (sc->tx_bd_chain[i] != NULL) {
2033 bus_dmamap_unload(sc->tx_bd_chain_tag,
2034 sc->tx_bd_chain_map[i]);
2035 bus_dmamem_free(sc->tx_bd_chain_tag,
2037 sc->tx_bd_chain_map[i]);
2040 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2043 /* Destroy the RX buffer descriptor DMA stuffs. */
2044 if (sc->rx_bd_chain_tag != NULL) {
2045 for (i = 0; i < RX_PAGES; i++) {
2046 if (sc->rx_bd_chain[i] != NULL) {
2047 bus_dmamap_unload(sc->rx_bd_chain_tag,
2048 sc->rx_bd_chain_map[i]);
2049 bus_dmamem_free(sc->rx_bd_chain_tag,
2051 sc->rx_bd_chain_map[i]);
2054 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2057 /* Destroy the TX mbuf DMA stuffs. */
2058 if (sc->tx_mbuf_tag != NULL) {
2059 for (i = 0; i < TOTAL_TX_BD; i++) {
2060 /* Must have been unloaded in bce_stop() */
2061 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2062 bus_dmamap_destroy(sc->tx_mbuf_tag,
2063 sc->tx_mbuf_map[i]);
2065 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2068 /* Destroy the RX mbuf DMA stuffs. */
2069 if (sc->rx_mbuf_tag != NULL) {
2070 for (i = 0; i < TOTAL_RX_BD; i++) {
2071 /* Must have been unloaded in bce_stop() */
2072 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2073 bus_dmamap_destroy(sc->rx_mbuf_tag,
2074 sc->rx_mbuf_map[i]);
2076 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2079 /* Destroy the parent tag */
2080 if (sc->parent_tag != NULL)
2081 bus_dma_tag_destroy(sc->parent_tag);
2085 /****************************************************************************/
2086 /* Get DMA memory from the OS. */
2088 /* Validates that the OS has provided DMA buffers in response to a */
2089 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2090 /* When the callback is used the OS will return 0 for the mapping function */
2091 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2092 /* failures back to the caller. */
2096 /****************************************************************************/
2098 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2100 bus_addr_t *busaddr = arg;
2103 * Simulate a mapping failure.
2106 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2107 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2108 __FILE__, __LINE__);
2111 /* Check for an error and signal the caller that an error occurred. */
2115 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2116 *busaddr = segs->ds_addr;
2121 bce_dma_map_mbuf(void *arg, bus_dma_segment_t *segs, int nsegs,
2122 bus_size_t mapsz __unused, int error)
2124 struct bce_dmamap_arg *ctx = arg;
2130 if (nsegs > ctx->bce_maxsegs) {
2131 ctx->bce_maxsegs = 0;
2135 ctx->bce_maxsegs = nsegs;
2136 for (i = 0; i < nsegs; ++i)
2137 ctx->bce_segs[i] = segs[i];
2141 /****************************************************************************/
2142 /* Allocate any DMA memory needed by the driver. */
2144 /* Allocates DMA memory needed for the various global structures needed by */
2148 /* 0 for success, positive value for failure. */
2149 /****************************************************************************/
2151 bce_dma_alloc(struct bce_softc *sc)
2153 struct ifnet *ifp = &sc->arpcom.ac_if;
2158 * Allocate the parent bus DMA tag appropriate for PCI.
2160 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2161 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2163 MAXBSIZE, BUS_SPACE_UNRESTRICTED,
2164 BUS_SPACE_MAXSIZE_32BIT,
2165 0, &sc->parent_tag);
2167 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2172 * Create a DMA tag for the status block, allocate and clear the
2173 * memory, map the memory into DMA space, and fetch the physical
2174 * address of the block.
2176 rc = bus_dma_tag_create(sc->parent_tag,
2177 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2178 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2180 BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
2181 0, &sc->status_tag);
2183 if_printf(ifp, "Could not allocate status block DMA tag!\n");
2187 rc = bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
2188 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2191 if_printf(ifp, "Could not allocate status block DMA memory!\n");
2195 rc = bus_dmamap_load(sc->status_tag, sc->status_map,
2196 sc->status_block, BCE_STATUS_BLK_SZ,
2197 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2199 if_printf(ifp, "Could not map status block DMA memory!\n");
2200 bus_dmamem_free(sc->status_tag, sc->status_block,
2202 sc->status_block = NULL;
2206 sc->status_block_paddr = busaddr;
2207 /* DRC - Fix for 64 bit addresses. */
2208 DBPRINT(sc, BCE_INFO, "status_block_paddr = 0x%08X\n",
2209 (uint32_t)sc->status_block_paddr);
2212 * Create a DMA tag for the statistics block, allocate and clear the
2213 * memory, map the memory into DMA space, and fetch the physical
2214 * address of the block.
2216 rc = bus_dma_tag_create(sc->parent_tag,
2217 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2218 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2220 BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
2223 if_printf(ifp, "Could not allocate "
2224 "statistics block DMA tag!\n");
2228 rc = bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
2229 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2232 if_printf(ifp, "Could not allocate "
2233 "statistics block DMA memory!\n");
2237 rc = bus_dmamap_load(sc->stats_tag, sc->stats_map,
2238 sc->stats_block, BCE_STATS_BLK_SZ,
2239 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2241 if_printf(ifp, "Could not map statistics block DMA memory!\n");
2242 bus_dmamem_free(sc->stats_tag, sc->stats_block, sc->stats_map);
2243 sc->stats_block = NULL;
2247 sc->stats_block_paddr = busaddr;
2248 /* DRC - Fix for 64 bit address. */
2249 DBPRINT(sc, BCE_INFO, "stats_block_paddr = 0x%08X\n",
2250 (uint32_t)sc->stats_block_paddr);
2253 * Create a DMA tag for the TX buffer descriptor chain,
2254 * allocate and clear the memory, and fetch the
2255 * physical address of the block.
2257 rc = bus_dma_tag_create(sc->parent_tag,
2258 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2259 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2261 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2262 0, &sc->tx_bd_chain_tag);
2264 if_printf(ifp, "Could not allocate "
2265 "TX descriptor chain DMA tag!\n");
2269 for (i = 0; i < TX_PAGES; i++) {
2270 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2271 (void **)&sc->tx_bd_chain[i],
2272 BUS_DMA_WAITOK, &sc->tx_bd_chain_map[i]);
2274 if_printf(ifp, "Could not allocate %dth TX descriptor "
2275 "chain DMA memory!\n", i);
2279 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2280 sc->tx_bd_chain_map[i],
2281 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2282 bce_dma_map_addr, &busaddr,
2285 if_printf(ifp, "Could not map %dth TX descriptor "
2286 "chain DMA memory!\n", i);
2287 bus_dmamem_free(sc->tx_bd_chain_tag,
2289 sc->tx_bd_chain_map[i]);
2290 sc->tx_bd_chain[i] = NULL;
2294 sc->tx_bd_chain_paddr[i] = busaddr;
2295 /* DRC - Fix for 64 bit systems. */
2296 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2297 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2300 /* Create a DMA tag for TX mbufs. */
2301 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2302 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2304 MCLBYTES * BCE_MAX_SEGMENTS,
2305 BCE_MAX_SEGMENTS, MCLBYTES,
2306 0, &sc->tx_mbuf_tag);
2308 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2312 /* Create DMA maps for the TX mbufs clusters. */
2313 for (i = 0; i < TOTAL_TX_BD; i++) {
2314 rc = bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_WAITOK,
2315 &sc->tx_mbuf_map[i]);
2317 for (j = 0; j < i; ++j) {
2318 bus_dmamap_destroy(sc->tx_mbuf_tag,
2319 sc->tx_mbuf_map[i]);
2321 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2322 sc->tx_mbuf_tag = NULL;
2324 if_printf(ifp, "Unable to create "
2325 "%dth TX mbuf DMA map!\n", i);
2331 * Create a DMA tag for the RX buffer descriptor chain,
2332 * allocate and clear the memory, and fetch the physical
2333 * address of the blocks.
2335 rc = bus_dma_tag_create(sc->parent_tag,
2336 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2337 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2339 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2340 0, &sc->rx_bd_chain_tag);
2342 if_printf(ifp, "Could not allocate "
2343 "RX descriptor chain DMA tag!\n");
2347 for (i = 0; i < RX_PAGES; i++) {
2348 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2349 (void **)&sc->rx_bd_chain[i],
2350 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2351 &sc->rx_bd_chain_map[i]);
2353 if_printf(ifp, "Could not allocate %dth RX descriptor "
2354 "chain DMA memory!\n", i);
2358 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2359 sc->rx_bd_chain_map[i],
2360 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2361 bce_dma_map_addr, &busaddr,
2364 if_printf(ifp, "Could not map %dth RX descriptor "
2365 "chain DMA memory!\n", i);
2366 bus_dmamem_free(sc->rx_bd_chain_tag,
2368 sc->rx_bd_chain_map[i]);
2369 sc->rx_bd_chain[i] = NULL;
2373 sc->rx_bd_chain_paddr[i] = busaddr;
2374 /* DRC - Fix for 64 bit systems. */
2375 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2376 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2379 /* Create a DMA tag for RX mbufs. */
2380 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2381 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2383 MCLBYTES, 1/* BCE_MAX_SEGMENTS */, MCLBYTES,
2384 0, &sc->rx_mbuf_tag);
2386 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2390 /* Create DMA maps for the RX mbuf clusters. */
2391 for (i = 0; i < TOTAL_RX_BD; i++) {
2392 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2393 &sc->rx_mbuf_map[i]);
2395 for (j = 0; j < i; ++j) {
2396 bus_dmamap_destroy(sc->rx_mbuf_tag,
2397 sc->rx_mbuf_map[j]);
2399 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2400 sc->rx_mbuf_tag = NULL;
2402 if_printf(ifp, "Unable to create "
2403 "%dth RX mbuf DMA map!\n", i);
2411 /****************************************************************************/
2412 /* Firmware synchronization. */
2414 /* Before performing certain events such as a chip reset, synchronize with */
2415 /* the firmware first. */
2418 /* 0 for success, positive value for failure. */
2419 /****************************************************************************/
2421 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2426 /* Don't waste any time if we've timed out before. */
2427 if (sc->bce_fw_timed_out)
2430 /* Increment the message sequence number. */
2431 sc->bce_fw_wr_seq++;
2432 msg_data |= sc->bce_fw_wr_seq;
2434 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2436 /* Send the message to the bootcode driver mailbox. */
2437 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2439 /* Wait for the bootcode to acknowledge the message. */
2440 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2441 /* Check for a response in the bootcode firmware mailbox. */
2442 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_FW_MB);
2443 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2448 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2449 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2450 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2451 if_printf(&sc->arpcom.ac_if,
2452 "Firmware synchronization timeout! "
2453 "msg_data = 0x%08X\n", msg_data);
2455 msg_data &= ~BCE_DRV_MSG_CODE;
2456 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2458 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2460 sc->bce_fw_timed_out = 1;
2467 /****************************************************************************/
2468 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2472 /****************************************************************************/
2474 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2475 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2480 for (i = 0; i < rv2p_code_len; i += 8) {
2481 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2483 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2486 if (rv2p_proc == RV2P_PROC1) {
2487 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2488 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2490 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2491 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2495 /* Reset the processor, un-stall is done later. */
2496 if (rv2p_proc == RV2P_PROC1)
2497 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2499 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2503 /****************************************************************************/
2504 /* Load RISC processor firmware. */
2506 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2507 /* associated with a particular processor. */
2511 /****************************************************************************/
2513 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2516 uint32_t offset, val;
2520 val = REG_RD_IND(sc, cpu_reg->mode);
2521 val |= cpu_reg->mode_value_halt;
2522 REG_WR_IND(sc, cpu_reg->mode, val);
2523 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2525 /* Load the Text area. */
2526 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2528 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2529 REG_WR_IND(sc, offset, fw->text[j]);
2532 /* Load the Data area. */
2533 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2535 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2536 REG_WR_IND(sc, offset, fw->data[j]);
2539 /* Load the SBSS area. */
2540 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2542 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2543 REG_WR_IND(sc, offset, fw->sbss[j]);
2546 /* Load the BSS area. */
2547 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2549 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2550 REG_WR_IND(sc, offset, fw->bss[j]);
2553 /* Load the Read-Only area. */
2554 offset = cpu_reg->spad_base +
2555 (fw->rodata_addr - cpu_reg->mips_view_base);
2557 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2558 REG_WR_IND(sc, offset, fw->rodata[j]);
2561 /* Clear the pre-fetch instruction. */
2562 REG_WR_IND(sc, cpu_reg->inst, 0);
2563 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2565 /* Start the CPU. */
2566 val = REG_RD_IND(sc, cpu_reg->mode);
2567 val &= ~cpu_reg->mode_value_halt;
2568 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2569 REG_WR_IND(sc, cpu_reg->mode, val);
2573 /****************************************************************************/
2574 /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs. */
2576 /* Loads the firmware for each CPU and starts the CPU. */
2580 /****************************************************************************/
2582 bce_init_cpus(struct bce_softc *sc)
2584 struct cpu_reg cpu_reg;
2587 /* Initialize the RV2P processor. */
2588 bce_load_rv2p_fw(sc, bce_rv2p_proc1, sizeof(bce_rv2p_proc1), RV2P_PROC1);
2589 bce_load_rv2p_fw(sc, bce_rv2p_proc2, sizeof(bce_rv2p_proc2), RV2P_PROC2);
2591 /* Initialize the RX Processor. */
2592 cpu_reg.mode = BCE_RXP_CPU_MODE;
2593 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2594 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2595 cpu_reg.state = BCE_RXP_CPU_STATE;
2596 cpu_reg.state_value_clear = 0xffffff;
2597 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2598 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2599 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2600 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2601 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2602 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2603 cpu_reg.mips_view_base = 0x8000000;
2605 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2606 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2607 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2608 fw.start_addr = bce_RXP_b06FwStartAddr;
2610 fw.text_addr = bce_RXP_b06FwTextAddr;
2611 fw.text_len = bce_RXP_b06FwTextLen;
2613 fw.text = bce_RXP_b06FwText;
2615 fw.data_addr = bce_RXP_b06FwDataAddr;
2616 fw.data_len = bce_RXP_b06FwDataLen;
2618 fw.data = bce_RXP_b06FwData;
2620 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2621 fw.sbss_len = bce_RXP_b06FwSbssLen;
2623 fw.sbss = bce_RXP_b06FwSbss;
2625 fw.bss_addr = bce_RXP_b06FwBssAddr;
2626 fw.bss_len = bce_RXP_b06FwBssLen;
2628 fw.bss = bce_RXP_b06FwBss;
2630 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2631 fw.rodata_len = bce_RXP_b06FwRodataLen;
2632 fw.rodata_index = 0;
2633 fw.rodata = bce_RXP_b06FwRodata;
2635 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2636 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2638 /* Initialize the TX Processor. */
2639 cpu_reg.mode = BCE_TXP_CPU_MODE;
2640 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2641 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2642 cpu_reg.state = BCE_TXP_CPU_STATE;
2643 cpu_reg.state_value_clear = 0xffffff;
2644 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2645 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2646 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2647 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2648 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2649 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2650 cpu_reg.mips_view_base = 0x8000000;
2652 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2653 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2654 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2655 fw.start_addr = bce_TXP_b06FwStartAddr;
2657 fw.text_addr = bce_TXP_b06FwTextAddr;
2658 fw.text_len = bce_TXP_b06FwTextLen;
2660 fw.text = bce_TXP_b06FwText;
2662 fw.data_addr = bce_TXP_b06FwDataAddr;
2663 fw.data_len = bce_TXP_b06FwDataLen;
2665 fw.data = bce_TXP_b06FwData;
2667 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2668 fw.sbss_len = bce_TXP_b06FwSbssLen;
2670 fw.sbss = bce_TXP_b06FwSbss;
2672 fw.bss_addr = bce_TXP_b06FwBssAddr;
2673 fw.bss_len = bce_TXP_b06FwBssLen;
2675 fw.bss = bce_TXP_b06FwBss;
2677 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2678 fw.rodata_len = bce_TXP_b06FwRodataLen;
2679 fw.rodata_index = 0;
2680 fw.rodata = bce_TXP_b06FwRodata;
2682 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2683 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2685 /* Initialize the TX Patch-up Processor. */
2686 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2687 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2688 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2689 cpu_reg.state = BCE_TPAT_CPU_STATE;
2690 cpu_reg.state_value_clear = 0xffffff;
2691 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2692 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2693 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2694 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2695 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2696 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2697 cpu_reg.mips_view_base = 0x8000000;
2699 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2700 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2701 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2702 fw.start_addr = bce_TPAT_b06FwStartAddr;
2704 fw.text_addr = bce_TPAT_b06FwTextAddr;
2705 fw.text_len = bce_TPAT_b06FwTextLen;
2707 fw.text = bce_TPAT_b06FwText;
2709 fw.data_addr = bce_TPAT_b06FwDataAddr;
2710 fw.data_len = bce_TPAT_b06FwDataLen;
2712 fw.data = bce_TPAT_b06FwData;
2714 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2715 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2717 fw.sbss = bce_TPAT_b06FwSbss;
2719 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2720 fw.bss_len = bce_TPAT_b06FwBssLen;
2722 fw.bss = bce_TPAT_b06FwBss;
2724 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2725 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2726 fw.rodata_index = 0;
2727 fw.rodata = bce_TPAT_b06FwRodata;
2729 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2730 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2732 /* Initialize the Completion Processor. */
2733 cpu_reg.mode = BCE_COM_CPU_MODE;
2734 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
2735 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
2736 cpu_reg.state = BCE_COM_CPU_STATE;
2737 cpu_reg.state_value_clear = 0xffffff;
2738 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
2739 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
2740 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
2741 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
2742 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
2743 cpu_reg.spad_base = BCE_COM_SCRATCH;
2744 cpu_reg.mips_view_base = 0x8000000;
2746 fw.ver_major = bce_COM_b06FwReleaseMajor;
2747 fw.ver_minor = bce_COM_b06FwReleaseMinor;
2748 fw.ver_fix = bce_COM_b06FwReleaseFix;
2749 fw.start_addr = bce_COM_b06FwStartAddr;
2751 fw.text_addr = bce_COM_b06FwTextAddr;
2752 fw.text_len = bce_COM_b06FwTextLen;
2754 fw.text = bce_COM_b06FwText;
2756 fw.data_addr = bce_COM_b06FwDataAddr;
2757 fw.data_len = bce_COM_b06FwDataLen;
2759 fw.data = bce_COM_b06FwData;
2761 fw.sbss_addr = bce_COM_b06FwSbssAddr;
2762 fw.sbss_len = bce_COM_b06FwSbssLen;
2764 fw.sbss = bce_COM_b06FwSbss;
2766 fw.bss_addr = bce_COM_b06FwBssAddr;
2767 fw.bss_len = bce_COM_b06FwBssLen;
2769 fw.bss = bce_COM_b06FwBss;
2771 fw.rodata_addr = bce_COM_b06FwRodataAddr;
2772 fw.rodata_len = bce_COM_b06FwRodataLen;
2773 fw.rodata_index = 0;
2774 fw.rodata = bce_COM_b06FwRodata;
2776 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
2777 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2781 /****************************************************************************/
2782 /* Initialize context memory. */
2784 /* Clears the memory associated with each Context ID (CID). */
2788 /****************************************************************************/
2790 bce_init_context(struct bce_softc *sc)
2796 uint32_t vcid_addr, pcid_addr, offset;
2800 vcid_addr = GET_CID_ADDR(vcid);
2801 pcid_addr = vcid_addr;
2803 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0x00);
2804 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2806 /* Zero out the context. */
2807 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
2808 CTX_WR(sc, 0x00, offset, 0);
2810 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
2811 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2816 /****************************************************************************/
2817 /* Fetch the permanent MAC address of the controller. */
2821 /****************************************************************************/
2823 bce_get_mac_addr(struct bce_softc *sc)
2825 uint32_t mac_lo = 0, mac_hi = 0;
2828 * The NetXtreme II bootcode populates various NIC
2829 * power-on and runtime configuration items in a
2830 * shared memory area. The factory configured MAC
2831 * address is available from both NVRAM and the
2832 * shared memory area so we'll read the value from
2833 * shared memory for speed.
2836 mac_hi = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_UPPER);
2837 mac_lo = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_LOWER);
2839 if (mac_lo == 0 && mac_hi == 0) {
2840 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
2842 sc->eaddr[0] = (u_char)(mac_hi >> 8);
2843 sc->eaddr[1] = (u_char)(mac_hi >> 0);
2844 sc->eaddr[2] = (u_char)(mac_lo >> 24);
2845 sc->eaddr[3] = (u_char)(mac_lo >> 16);
2846 sc->eaddr[4] = (u_char)(mac_lo >> 8);
2847 sc->eaddr[5] = (u_char)(mac_lo >> 0);
2850 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
2854 /****************************************************************************/
2855 /* Program the MAC address. */
2859 /****************************************************************************/
2861 bce_set_mac_addr(struct bce_softc *sc)
2863 const uint8_t *mac_addr = sc->eaddr;
2866 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
2869 val = (mac_addr[0] << 8) | mac_addr[1];
2870 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
2872 val = (mac_addr[2] << 24) |
2873 (mac_addr[3] << 16) |
2874 (mac_addr[4] << 8) |
2876 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
2880 /****************************************************************************/
2881 /* Stop the controller. */
2885 /****************************************************************************/
2887 bce_stop(struct bce_softc *sc)
2889 struct ifnet *ifp = &sc->arpcom.ac_if;
2890 struct mii_data *mii = device_get_softc(sc->bce_miibus);
2891 struct ifmedia_entry *ifm;
2894 ASSERT_SERIALIZED(ifp->if_serializer);
2896 callout_stop(&sc->bce_stat_ch);
2898 /* Disable the transmit/receive blocks. */
2899 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, 0x5ffffff);
2900 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2903 bce_disable_intr(sc);
2905 /* Tell firmware that the driver is going away. */
2906 bce_reset(sc, BCE_DRV_MSG_CODE_SUSPEND_NO_WOL);
2908 /* Free the RX lists. */
2909 bce_free_rx_chain(sc);
2911 /* Free TX buffers. */
2912 bce_free_tx_chain(sc);
2915 * Isolate/power down the PHY, but leave the media selection
2916 * unchanged so that things will be put back to normal when
2917 * we bring the interface back up.
2919 * 'mii' may be NULL if bce_stop() is called by bce_detach().
2922 itmp = ifp->if_flags;
2923 ifp->if_flags |= IFF_UP;
2924 ifm = mii->mii_media.ifm_cur;
2925 mtmp = ifm->ifm_media;
2926 ifm->ifm_media = IFM_ETHER | IFM_NONE;
2928 ifm->ifm_media = mtmp;
2929 ifp->if_flags = itmp;
2934 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2942 bce_reset(struct bce_softc *sc, uint32_t reset_code)
2947 /* Wait for pending PCI transactions to complete. */
2948 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
2949 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
2950 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
2951 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
2952 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
2953 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2956 /* Assume bootcode is running. */
2957 sc->bce_fw_timed_out = 0;
2959 /* Give the firmware a chance to prepare for the reset. */
2960 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
2962 if_printf(&sc->arpcom.ac_if,
2963 "Firmware is not ready for reset\n");
2967 /* Set a firmware reminder that this is a soft reset. */
2968 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_RESET_SIGNATURE,
2969 BCE_DRV_RESET_SIGNATURE_MAGIC);
2971 /* Dummy read to force the chip to complete all current transactions. */
2972 val = REG_RD(sc, BCE_MISC_ID);
2975 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2976 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
2977 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
2978 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
2980 /* Allow up to 30us for reset to complete. */
2981 for (i = 0; i < 10; i++) {
2982 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
2983 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2984 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
2990 /* Check that reset completed successfully. */
2991 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2992 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
2993 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
2997 /* Make sure byte swapping is properly configured. */
2998 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
2999 if (val != 0x01020304) {
3000 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3004 /* Just completed a reset, assume that firmware is running again. */
3005 sc->bce_fw_timed_out = 0;
3007 /* Wait for the firmware to finish its initialization. */
3008 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3010 if_printf(&sc->arpcom.ac_if,
3011 "Firmware did not complete initialization!\n");
3018 bce_chipinit(struct bce_softc *sc)
3023 /* Make sure the interrupt is not active. */
3024 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3027 * Initialize DMA byte/word swapping, configure the number of DMA
3028 * channels and PCI clock compensation delay.
3030 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3031 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3032 #if BYTE_ORDER == BIG_ENDIAN
3033 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3035 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3036 DMA_READ_CHANS << 12 |
3037 DMA_WRITE_CHANS << 16;
3039 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3041 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3042 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3045 * This setting resolves a problem observed on certain Intel PCI
3046 * chipsets that cannot handle multiple outstanding DMA operations.
3047 * See errata E9_5706A1_65.
3049 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3050 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3051 !(sc->bce_flags & BCE_PCIX_FLAG))
3052 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3054 REG_WR(sc, BCE_DMA_CONFIG, val);
3056 /* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
3057 if (sc->bce_flags & BCE_PCIX_FLAG) {
3060 cmd = pci_read_config(sc->bce_dev, BCE_PCI_PCIX_CMD, 2);
3061 pci_write_config(sc->bce_dev, BCE_PCI_PCIX_CMD, cmd & ~0x2, 2);
3064 /* Enable the RX_V2P and Context state machines before access. */
3065 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3066 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3067 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3068 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3070 /* Initialize context mapping and zero out the quick contexts. */
3071 bce_init_context(sc);
3073 /* Initialize the on-boards CPUs */
3076 /* Prepare NVRAM for access. */
3077 rc = bce_init_nvram(sc);
3081 /* Set the kernel bypass block size */
3082 val = REG_RD(sc, BCE_MQ_CONFIG);
3083 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3084 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3085 REG_WR(sc, BCE_MQ_CONFIG, val);
3087 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3088 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3089 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3091 /* Set the page size and clear the RV2P processor stall bits. */
3092 val = (BCM_PAGE_BITS - 8) << 24;
3093 REG_WR(sc, BCE_RV2P_CONFIG, val);
3095 /* Configure page size. */
3096 val = REG_RD(sc, BCE_TBDR_CONFIG);
3097 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3098 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3099 REG_WR(sc, BCE_TBDR_CONFIG, val);
3105 /****************************************************************************/
3106 /* Initialize the controller in preparation to send/receive traffic. */
3109 /* 0 for success, positive value for failure. */
3110 /****************************************************************************/
3112 bce_blockinit(struct bce_softc *sc)
3117 /* Load the hardware default MAC address. */
3118 bce_set_mac_addr(sc);
3120 /* Set the Ethernet backoff seed value */
3121 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3122 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3123 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3125 sc->last_status_idx = 0;
3126 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3128 /* Set up link change interrupt generation. */
3129 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3131 /* Program the physical address of the status block. */
3132 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3133 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3135 /* Program the physical address of the statistics block. */
3136 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3137 BCE_ADDR_LO(sc->stats_block_paddr));
3138 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3139 BCE_ADDR_HI(sc->stats_block_paddr));
3141 /* Program various host coalescing parameters. */
3142 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3143 (sc->bce_tx_quick_cons_trip_int << 16) |
3144 sc->bce_tx_quick_cons_trip);
3145 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3146 (sc->bce_rx_quick_cons_trip_int << 16) |
3147 sc->bce_rx_quick_cons_trip);
3148 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3149 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3150 REG_WR(sc, BCE_HC_TX_TICKS,
3151 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3152 REG_WR(sc, BCE_HC_RX_TICKS,
3153 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3154 REG_WR(sc, BCE_HC_COM_TICKS,
3155 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3156 REG_WR(sc, BCE_HC_CMD_TICKS,
3157 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3158 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3159 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3160 REG_WR(sc, BCE_HC_CONFIG,
3161 BCE_HC_CONFIG_RX_TMR_MODE |
3162 BCE_HC_CONFIG_TX_TMR_MODE |
3163 BCE_HC_CONFIG_COLLECT_STATS);
3165 /* Clear the internal statistics counters. */
3166 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3168 /* Verify that bootcode is running. */
3169 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_SIGNATURE);
3171 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3172 if_printf(&sc->arpcom.ac_if,
3173 "%s(%d): Simulating bootcode failure.\n",
3174 __FILE__, __LINE__);
3177 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3178 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3179 if_printf(&sc->arpcom.ac_if,
3180 "Bootcode not running! Found: 0x%08X, "
3181 "Expected: 08%08X\n",
3182 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3183 BCE_DEV_INFO_SIGNATURE_MAGIC);
3187 /* Check if any management firmware is running. */
3188 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_FEATURE);
3189 if (reg & (BCE_PORT_FEATURE_ASF_ENABLED |
3190 BCE_PORT_FEATURE_IMD_ENABLED)) {
3191 DBPRINT(sc, BCE_INFO, "Management F/W Enabled.\n");
3192 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
3196 REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_BC_REV);
3197 DBPRINT(sc, BCE_INFO, "bootcode rev = 0x%08X\n", sc->bce_fw_ver);
3199 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3200 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3202 /* Enable link state change interrupt generation. */
3203 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3205 /* Enable all remaining blocks in the MAC. */
3206 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, 0x5ffffff);
3207 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3214 /****************************************************************************/
3215 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3217 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3218 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3222 /* 0 for success, positive value for failure. */
3223 /****************************************************************************/
3225 bce_newbuf_std(struct bce_softc *sc, struct mbuf *m,
3226 uint16_t *prod, uint16_t *chain_prod, uint32_t *prod_bseq)
3229 struct bce_dmamap_arg ctx;
3230 bus_dma_segment_t seg;
3235 uint16_t debug_chain_prod = *chain_prod;
3238 /* Make sure the inputs are valid. */
3239 DBRUNIF((*chain_prod > MAX_RX_BD),
3240 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3241 "RX producer out of range: 0x%04X > 0x%04X\n",
3243 *chain_prod, (uint16_t)MAX_RX_BD));
3245 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3246 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3249 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3250 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3251 "Simulating mbuf allocation failure.\n",
3252 __FILE__, __LINE__);
3253 sc->mbuf_alloc_failed++;
3256 /* This is a new mbuf allocation. */
3257 m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3260 DBRUNIF(1, sc->rx_mbuf_alloc++);
3263 m_new->m_data = m_new->m_ext.ext_buf;
3265 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3267 /* Map the mbuf cluster into device memory. */
3268 map = sc->rx_mbuf_map[*chain_prod];
3270 ctx.bce_maxsegs = 1;
3271 ctx.bce_segs = &seg;
3272 error = bus_dmamap_load_mbuf(sc->rx_mbuf_tag, map, m_new,
3273 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
3274 if (error || ctx.bce_maxsegs == 0) {
3275 if_printf(&sc->arpcom.ac_if,
3276 "Error mapping mbuf into RX chain!\n");
3281 DBRUNIF(1, sc->rx_mbuf_alloc--);
3285 /* Watch for overflow. */
3286 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3287 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3288 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3289 __FILE__, __LINE__, sc->free_rx_bd,
3290 (uint16_t)USABLE_RX_BD));
3292 /* Update some debug statistic counters */
3293 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3294 sc->rx_low_watermark = sc->free_rx_bd);
3295 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3297 /* Setup the rx_bd for the first segment. */
3298 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3300 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(seg.ds_addr));
3301 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(seg.ds_addr));
3302 rxbd->rx_bd_len = htole32(seg.ds_len);
3303 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3304 *prod_bseq += seg.ds_len;
3306 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3308 /* Save the mbuf and update our counter. */
3309 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3312 DBRUN(BCE_VERBOSE_RECV,
3313 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3315 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3316 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3322 /****************************************************************************/
3323 /* Allocate memory and initialize the TX data structures. */
3326 /* 0 for success, positive value for failure. */
3327 /****************************************************************************/
3329 bce_init_tx_chain(struct bce_softc *sc)
3335 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3337 /* Set the initial TX producer/consumer indices. */
3340 sc->tx_prod_bseq = 0;
3342 sc->max_tx_bd = USABLE_TX_BD;
3343 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3344 DBRUNIF(1, sc->tx_full_count = 0);
3347 * The NetXtreme II supports a linked-list structre called
3348 * a Buffer Descriptor Chain (or BD chain). A BD chain
3349 * consists of a series of 1 or more chain pages, each of which
3350 * consists of a fixed number of BD entries.
3351 * The last BD entry on each page is a pointer to the next page
3352 * in the chain, and the last pointer in the BD chain
3353 * points back to the beginning of the chain.
3356 /* Set the TX next pointer chain entries. */
3357 for (i = 0; i < TX_PAGES; i++) {
3360 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3362 /* Check if we've reached the last page. */
3363 if (i == (TX_PAGES - 1))
3368 txbd->tx_bd_haddr_hi =
3369 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3370 txbd->tx_bd_haddr_lo =
3371 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3374 for (i = 0; i < TX_PAGES; ++i) {
3375 bus_dmamap_sync(sc->tx_bd_chain_tag, sc->tx_bd_chain_map[i],
3376 BUS_DMASYNC_PREWRITE);
3379 /* Initialize the context ID for an L2 TX chain. */
3380 val = BCE_L2CTX_TYPE_TYPE_L2;
3381 val |= BCE_L2CTX_TYPE_SIZE_L2;
3382 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TYPE, val);
3384 val = BCE_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
3385 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_CMD_TYPE, val);
3387 /* Point the hardware to the first page in the chain. */
3388 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3389 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_HI, val);
3390 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3391 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_LO, val);
3393 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
3395 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3401 /****************************************************************************/
3402 /* Free memory and clear the TX data structures. */
3406 /****************************************************************************/
3408 bce_free_tx_chain(struct bce_softc *sc)
3412 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3414 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3415 for (i = 0; i < TOTAL_TX_BD; i++) {
3416 if (sc->tx_mbuf_ptr[i] != NULL) {
3417 bus_dmamap_sync(sc->tx_mbuf_tag, sc->tx_mbuf_map[i],
3418 BUS_DMASYNC_POSTWRITE);
3419 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3420 m_freem(sc->tx_mbuf_ptr[i]);
3421 sc->tx_mbuf_ptr[i] = NULL;
3422 DBRUNIF(1, sc->tx_mbuf_alloc--);
3426 /* Clear each TX chain page. */
3427 for (i = 0; i < TX_PAGES; i++)
3428 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3430 /* Check if we lost any mbufs in the process. */
3431 DBRUNIF((sc->tx_mbuf_alloc),
3432 if_printf(&sc->arpcom.ac_if,
3433 "%s(%d): Memory leak! "
3434 "Lost %d mbufs from tx chain!\n",
3435 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3437 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3441 /****************************************************************************/
3442 /* Allocate memory and initialize the RX data structures. */
3445 /* 0 for success, positive value for failure. */
3446 /****************************************************************************/
3448 bce_init_rx_chain(struct bce_softc *sc)
3452 uint16_t prod, chain_prod;
3453 uint32_t prod_bseq, val;
3455 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3457 /* Initialize the RX producer and consumer indices. */
3460 sc->rx_prod_bseq = 0;
3461 sc->free_rx_bd = USABLE_RX_BD;
3462 sc->max_rx_bd = USABLE_RX_BD;
3463 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3464 DBRUNIF(1, sc->rx_empty_count = 0);
3466 /* Initialize the RX next pointer chain entries. */
3467 for (i = 0; i < RX_PAGES; i++) {
3470 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3472 /* Check if we've reached the last page. */
3473 if (i == (RX_PAGES - 1))
3478 /* Setup the chain page pointers. */
3479 rxbd->rx_bd_haddr_hi =
3480 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
3481 rxbd->rx_bd_haddr_lo =
3482 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
3485 /* Initialize the context ID for an L2 RX chain. */
3486 val = BCE_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3487 val |= BCE_L2CTX_CTX_TYPE_SIZE_L2;
3489 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_CTX_TYPE, val);
3491 /* Point the hardware to the first page in the chain. */
3492 /* XXX shouldn't this after RX descriptor initialization? */
3493 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3494 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_HI, val);
3495 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3496 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_LO, val);
3498 /* Allocate mbuf clusters for the rx_bd chain. */
3499 prod = prod_bseq = 0;
3500 while (prod < TOTAL_RX_BD) {
3501 chain_prod = RX_CHAIN_IDX(prod);
3502 if (bce_newbuf_std(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
3503 if_printf(&sc->arpcom.ac_if,
3504 "Error filling RX chain: rx_bd[0x%04X]!\n",
3509 prod = NEXT_RX_BD(prod);
3512 /* Save the RX chain producer index. */
3514 sc->rx_prod_bseq = prod_bseq;
3516 for (i = 0; i < RX_PAGES; i++) {
3517 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
3518 BUS_DMASYNC_PREWRITE);
3521 /* Tell the chip about the waiting rx_bd's. */
3522 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3523 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3525 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_chain(sc, 0, TOTAL_RX_BD));
3527 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3533 /****************************************************************************/
3534 /* Free memory and clear the RX data structures. */
3538 /****************************************************************************/
3540 bce_free_rx_chain(struct bce_softc *sc)
3544 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3546 /* Free any mbufs still in the RX mbuf chain. */
3547 for (i = 0; i < TOTAL_RX_BD; i++) {
3548 if (sc->rx_mbuf_ptr[i] != NULL) {
3549 bus_dmamap_sync(sc->rx_mbuf_tag, sc->rx_mbuf_map[i],
3550 BUS_DMASYNC_POSTREAD);
3551 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
3552 m_freem(sc->rx_mbuf_ptr[i]);
3553 sc->rx_mbuf_ptr[i] = NULL;
3554 DBRUNIF(1, sc->rx_mbuf_alloc--);
3558 /* Clear each RX chain page. */
3559 for (i = 0; i < RX_PAGES; i++)
3560 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3562 /* Check if we lost any mbufs in the process. */
3563 DBRUNIF((sc->rx_mbuf_alloc),
3564 if_printf(&sc->arpcom.ac_if,
3565 "%s(%d): Memory leak! "
3566 "Lost %d mbufs from rx chain!\n",
3567 __FILE__, __LINE__, sc->rx_mbuf_alloc));
3569 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3573 /****************************************************************************/
3574 /* Set media options. */
3577 /* 0 for success, positive value for failure. */
3578 /****************************************************************************/
3580 bce_ifmedia_upd(struct ifnet *ifp)
3582 struct bce_softc *sc = ifp->if_softc;
3583 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3586 * 'mii' will be NULL, when this function is called on following
3587 * code path: bce_attach() -> bce_mgmt_init()
3590 /* Make sure the MII bus has been enumerated. */
3592 if (mii->mii_instance) {
3593 struct mii_softc *miisc;
3595 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
3596 mii_phy_reset(miisc);
3604 /****************************************************************************/
3605 /* Reports current media status. */
3609 /****************************************************************************/
3611 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3613 struct bce_softc *sc = ifp->if_softc;
3614 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3617 ifmr->ifm_active = mii->mii_media_active;
3618 ifmr->ifm_status = mii->mii_media_status;
3622 /****************************************************************************/
3623 /* Handles PHY generated interrupt events. */
3627 /****************************************************************************/
3629 bce_phy_intr(struct bce_softc *sc)
3631 uint32_t new_link_state, old_link_state;
3632 struct ifnet *ifp = &sc->arpcom.ac_if;
3634 ASSERT_SERIALIZED(ifp->if_serializer);
3636 new_link_state = sc->status_block->status_attn_bits &
3637 STATUS_ATTN_BITS_LINK_STATE;
3638 old_link_state = sc->status_block->status_attn_bits_ack &
3639 STATUS_ATTN_BITS_LINK_STATE;
3641 /* Handle any changes if the link state has changed. */
3642 if (new_link_state != old_link_state) { /* XXX redundant? */
3643 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
3646 callout_stop(&sc->bce_stat_ch);
3647 bce_tick_serialized(sc);
3649 /* Update the status_attn_bits_ack field in the status block. */
3650 if (new_link_state) {
3651 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
3652 STATUS_ATTN_BITS_LINK_STATE);
3654 if_printf(ifp, "Link is now UP.\n");
3656 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
3657 STATUS_ATTN_BITS_LINK_STATE);
3659 if_printf(ifp, "Link is now DOWN.\n");
3663 /* Acknowledge the link change interrupt. */
3664 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
3668 /****************************************************************************/
3669 /* Handles received frame interrupt events. */
3673 /****************************************************************************/
3675 bce_rx_intr(struct bce_softc *sc, int count)
3677 struct status_block *sblk = sc->status_block;
3678 struct ifnet *ifp = &sc->arpcom.ac_if;
3679 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
3680 uint32_t sw_prod_bseq;
3683 ASSERT_SERIALIZED(ifp->if_serializer);
3685 DBRUNIF(1, sc->rx_interrupts++);
3687 /* Prepare the RX chain pages to be accessed by the host CPU. */
3688 for (i = 0; i < RX_PAGES; i++) {
3689 bus_dmamap_sync(sc->rx_bd_chain_tag,
3690 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
3693 /* Get the hardware's view of the RX consumer index. */
3694 hw_cons = sc->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
3695 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
3698 /* Get working copies of the driver's view of the RX indices. */
3699 sw_cons = sc->rx_cons;
3700 sw_prod = sc->rx_prod;
3701 sw_prod_bseq = sc->rx_prod_bseq;
3703 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
3704 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
3705 __func__, sw_prod, sw_cons, sw_prod_bseq);
3707 /* Prevent speculative reads from getting ahead of the status block. */
3708 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
3709 BUS_SPACE_BARRIER_READ);
3711 /* Update some debug statistics counters */
3712 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3713 sc->rx_low_watermark = sc->free_rx_bd);
3714 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3716 /* Scan through the receive chain as long as there is work to do. */
3717 while (sw_cons != hw_cons) {
3718 struct mbuf *m = NULL;
3719 struct l2_fhdr *l2fhdr = NULL;
3722 uint32_t status = 0;
3724 #ifdef foo /* DEVICE_POLLING */
3726 * Even if polling(4) is enabled, we can't just reap
3727 * 'count' RX descriptors and leave. It seems that RX
3728 * engine would be left in a wired state, if we broke
3729 * out the loop in the middle.
3731 if (count >= 0 && count-- == 0)
3736 * Convert the producer/consumer indices
3737 * to an actual rx_bd index.
3739 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
3740 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
3742 /* Get the used rx_bd. */
3743 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
3744 [RX_IDX(sw_chain_cons)];
3747 DBRUN(BCE_VERBOSE_RECV,
3748 if_printf(ifp, "%s(): ", __func__);
3749 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
3751 /* The mbuf is stored with the last rx_bd entry of a packet. */
3752 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
3753 /* Validate that this is the last rx_bd. */
3754 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
3755 if_printf(ifp, "%s(%d): "
3756 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
3757 __FILE__, __LINE__, sw_chain_cons);
3758 bce_breakpoint(sc));
3761 * ToDo: If the received packet is small enough
3762 * to fit into a single, non-M_EXT mbuf,
3763 * allocate a new mbuf here, copy the data to
3764 * that mbuf, and recycle the mapped jumbo frame.
3767 /* Unmap the mbuf from DMA space. */
3768 bus_dmamap_sync(sc->rx_mbuf_tag,
3769 sc->rx_mbuf_map[sw_chain_cons],
3770 BUS_DMASYNC_POSTREAD);
3771 bus_dmamap_unload(sc->rx_mbuf_tag,
3772 sc->rx_mbuf_map[sw_chain_cons]);
3774 /* Remove the mbuf from the driver's chain. */
3775 m = sc->rx_mbuf_ptr[sw_chain_cons];
3776 sc->rx_mbuf_ptr[sw_chain_cons] = NULL;
3779 * Frames received on the NetXteme II are prepended
3780 * with an l2_fhdr structure which provides status
3781 * information about the received frame (including
3782 * VLAN tags and checksum info). The frames are also
3783 * automatically adjusted to align the IP header
3784 * (i.e. two null bytes are inserted before the
3787 l2fhdr = mtod(m, struct l2_fhdr *);
3789 len = l2fhdr->l2_fhdr_pkt_len;
3790 status = l2fhdr->l2_fhdr_status;
3792 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
3794 "Simulating l2_fhdr status error.\n");
3795 status = status | L2_FHDR_ERRORS_PHY_DECODE);
3797 /* Watch for unusual sized frames. */
3798 DBRUNIF((len < BCE_MIN_MTU ||
3799 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
3801 "%s(%d): Unusual frame size found. "
3802 "Min(%d), Actual(%d), Max(%d)\n",
3804 (int)BCE_MIN_MTU, len,
3805 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
3806 bce_dump_mbuf(sc, m);
3807 bce_breakpoint(sc));
3809 len -= ETHER_CRC_LEN;
3811 /* Check the received frame for errors. */
3812 if (status & (L2_FHDR_ERRORS_BAD_CRC |
3813 L2_FHDR_ERRORS_PHY_DECODE |
3814 L2_FHDR_ERRORS_ALIGNMENT |
3815 L2_FHDR_ERRORS_TOO_SHORT |
3816 L2_FHDR_ERRORS_GIANT_FRAME)) {
3818 DBRUNIF(1, sc->l2fhdr_status_errors++);
3820 /* Reuse the mbuf for a new frame. */
3821 if (bce_newbuf_std(sc, m, &sw_prod,
3824 DBRUNIF(1, bce_breakpoint(sc));
3826 panic("%s: Can't reuse RX mbuf!\n",
3830 goto bce_rx_int_next_rx;
3834 * Get a new mbuf for the rx_bd. If no new
3835 * mbufs are available then reuse the current mbuf,
3836 * log an ierror on the interface, and generate
3837 * an error in the system log.
3839 if (bce_newbuf_std(sc, NULL, &sw_prod, &sw_chain_prod,
3843 "%s(%d): Failed to allocate new mbuf, "
3844 "incoming frame dropped!\n",
3845 __FILE__, __LINE__));
3849 /* Try and reuse the exisitng mbuf. */
3850 if (bce_newbuf_std(sc, m, &sw_prod,
3853 DBRUNIF(1, bce_breakpoint(sc));
3855 panic("%s: Double mbuf allocation "
3856 "failure!", ifp->if_xname);
3859 goto bce_rx_int_next_rx;
3863 * Skip over the l2_fhdr when passing
3864 * the data up the stack.
3866 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
3868 m->m_pkthdr.len = m->m_len = len;
3869 m->m_pkthdr.rcvif = ifp;
3871 DBRUN(BCE_VERBOSE_RECV,
3872 struct ether_header *eh;
3873 eh = mtod(m, struct ether_header *);
3874 if_printf(ifp, "%s(): to: %6D, from: %6D, "
3875 "type: 0x%04X\n", __func__,
3876 eh->ether_dhost, ":",
3877 eh->ether_shost, ":",
3878 htons(eh->ether_type)));
3880 /* Validate the checksum if offload enabled. */
3881 if (ifp->if_capenable & IFCAP_RXCSUM) {
3882 /* Check for an IP datagram. */
3883 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
3884 m->m_pkthdr.csum_flags |=
3887 /* Check if the IP checksum is valid. */
3888 if ((l2fhdr->l2_fhdr_ip_xsum ^
3890 m->m_pkthdr.csum_flags |=
3893 DBPRINT(sc, BCE_WARN_RECV,
3894 "%s(): Invalid IP checksum = 0x%04X!\n",
3895 __func__, l2fhdr->l2_fhdr_ip_xsum);
3899 /* Check for a valid TCP/UDP frame. */
3900 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
3901 L2_FHDR_STATUS_UDP_DATAGRAM)) {
3903 /* Check for a good TCP/UDP checksum. */
3905 (L2_FHDR_ERRORS_TCP_XSUM |
3906 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
3907 m->m_pkthdr.csum_data =
3908 l2fhdr->l2_fhdr_tcp_udp_xsum;
3909 m->m_pkthdr.csum_flags |=
3913 DBPRINT(sc, BCE_WARN_RECV,
3914 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
3915 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
3922 sw_prod = NEXT_RX_BD(sw_prod);
3925 sw_cons = NEXT_RX_BD(sw_cons);
3927 /* If we have a packet, pass it up the stack */
3929 DBPRINT(sc, BCE_VERBOSE_RECV,
3930 "%s(): Passing received frame up.\n", __func__);
3932 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
3933 m->m_flags |= M_VLANTAG;
3934 m->m_pkthdr.ether_vlantag =
3935 l2fhdr->l2_fhdr_vlan_tag;
3937 ifp->if_input(ifp, m);
3939 DBRUNIF(1, sc->rx_mbuf_alloc--);
3943 * If polling(4) is not enabled, refresh hw_cons to see
3944 * whether there's new work.
3946 * If polling(4) is enabled, i.e count >= 0, refreshing
3947 * should not be performed, so that we would not spend
3948 * too much time in RX processing.
3950 if (count < 0 && sw_cons == hw_cons) {
3951 hw_cons = sc->hw_rx_cons =
3952 sblk->status_rx_quick_consumer_index0;
3953 if ((hw_cons & USABLE_RX_BD_PER_PAGE) ==
3954 USABLE_RX_BD_PER_PAGE)
3959 * Prevent speculative reads from getting ahead
3960 * of the status block.
3962 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
3963 BUS_SPACE_BARRIER_READ);
3966 for (i = 0; i < RX_PAGES; i++) {
3967 bus_dmamap_sync(sc->rx_bd_chain_tag,
3968 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
3971 sc->rx_cons = sw_cons;
3972 sc->rx_prod = sw_prod;
3973 sc->rx_prod_bseq = sw_prod_bseq;
3975 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3976 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3978 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
3979 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
3980 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
3984 /****************************************************************************/
3985 /* Handles transmit completion interrupt events. */
3989 /****************************************************************************/
3991 bce_tx_intr(struct bce_softc *sc)
3993 struct status_block *sblk = sc->status_block;
3994 struct ifnet *ifp = &sc->arpcom.ac_if;
3995 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
3997 ASSERT_SERIALIZED(ifp->if_serializer);
3999 DBRUNIF(1, sc->tx_interrupts++);
4001 /* Get the hardware's view of the TX consumer index. */
4002 hw_tx_cons = sc->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
4004 /* Skip to the next entry if this is a chain page pointer. */
4005 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4008 sw_tx_cons = sc->tx_cons;
4010 /* Prevent speculative reads from getting ahead of the status block. */
4011 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4012 BUS_SPACE_BARRIER_READ);
4014 /* Cycle through any completed TX chain page entries. */
4015 while (sw_tx_cons != hw_tx_cons) {
4017 struct tx_bd *txbd = NULL;
4019 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4021 DBPRINT(sc, BCE_INFO_SEND,
4022 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4023 "sw_tx_chain_cons = 0x%04X\n",
4024 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4026 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4027 if_printf(ifp, "%s(%d): "
4028 "TX chain consumer out of range! "
4029 " 0x%04X > 0x%04X\n",
4030 __FILE__, __LINE__, sw_tx_chain_cons,
4032 bce_breakpoint(sc));
4034 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4035 [TX_IDX(sw_tx_chain_cons)]);
4037 DBRUNIF((txbd == NULL),
4038 if_printf(ifp, "%s(%d): "
4039 "Unexpected NULL tx_bd[0x%04X]!\n",
4040 __FILE__, __LINE__, sw_tx_chain_cons);
4041 bce_breakpoint(sc));
4043 DBRUN(BCE_INFO_SEND,
4044 if_printf(ifp, "%s(): ", __func__);
4045 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4048 * Free the associated mbuf. Remember
4049 * that only the last tx_bd of a packet
4050 * has an mbuf pointer and DMA map.
4052 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4053 /* Validate that this is the last tx_bd. */
4054 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4055 if_printf(ifp, "%s(%d): "
4056 "tx_bd END flag not set but "
4057 "txmbuf == NULL!\n", __FILE__, __LINE__);
4058 bce_breakpoint(sc));
4060 DBRUN(BCE_INFO_SEND,
4061 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4062 "from tx_bd[0x%04X]\n", __func__,
4065 /* Unmap the mbuf. */
4066 bus_dmamap_unload(sc->tx_mbuf_tag,
4067 sc->tx_mbuf_map[sw_tx_chain_cons]);
4069 /* Free the mbuf. */
4070 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4071 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4072 DBRUNIF(1, sc->tx_mbuf_alloc--);
4078 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4080 if (sw_tx_cons == hw_tx_cons) {
4081 /* Refresh hw_cons to see if there's new work. */
4082 hw_tx_cons = sc->hw_tx_cons =
4083 sblk->status_tx_quick_consumer_index0;
4084 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) ==
4085 USABLE_TX_BD_PER_PAGE)
4090 * Prevent speculative reads from getting
4091 * ahead of the status block.
4093 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4094 BUS_SPACE_BARRIER_READ);
4097 if (sc->used_tx_bd == 0) {
4098 /* Clear the TX timeout timer. */
4102 /* Clear the tx hardware queue full flag. */
4103 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4104 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4105 DBPRINT(sc, BCE_WARN_SEND,
4106 "%s(): Open TX chain! %d/%d (used/total)\n",
4107 __func__, sc->used_tx_bd, sc->max_tx_bd));
4108 ifp->if_flags &= ~IFF_OACTIVE;
4110 sc->tx_cons = sw_tx_cons;
4114 /****************************************************************************/
4115 /* Disables interrupt generation. */
4119 /****************************************************************************/
4121 bce_disable_intr(struct bce_softc *sc)
4123 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4124 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4125 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4129 /****************************************************************************/
4130 /* Enables interrupt generation. */
4134 /****************************************************************************/
4136 bce_enable_intr(struct bce_softc *sc)
4140 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4142 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4143 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4144 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4146 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4147 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4149 val = REG_RD(sc, BCE_HC_COMMAND);
4150 REG_WR(sc, BCE_HC_COMMAND, val | BCE_HC_COMMAND_COAL_NOW);
4154 /****************************************************************************/
4155 /* Handles controller initialization. */
4159 /****************************************************************************/
4163 struct bce_softc *sc = xsc;
4164 struct ifnet *ifp = &sc->arpcom.ac_if;
4168 ASSERT_SERIALIZED(ifp->if_serializer);
4170 /* Check if the driver is still running and bail out if it is. */
4171 if (ifp->if_flags & IFF_RUNNING)
4176 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4178 if_printf(ifp, "Controller reset failed!\n");
4182 error = bce_chipinit(sc);
4184 if_printf(ifp, "Controller initialization failed!\n");
4188 error = bce_blockinit(sc);
4190 if_printf(ifp, "Block initialization failed!\n");
4194 /* Load our MAC address. */
4195 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4196 bce_set_mac_addr(sc);
4198 /* Calculate and program the Ethernet MTU size. */
4199 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4201 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4204 * Program the mtu, enabling jumbo frame
4205 * support if necessary. Also set the mbuf
4206 * allocation count for RX frames.
4208 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4210 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4211 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4212 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4213 sc->mbuf_alloc_size = MJUM9BYTES;
4215 panic("jumbo buffer is not supported yet\n");
4218 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4219 sc->mbuf_alloc_size = MCLBYTES;
4222 /* Calculate the RX Ethernet frame size for rx_bd's. */
4223 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4225 DBPRINT(sc, BCE_INFO,
4226 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4227 "max_frame_size = %d\n",
4228 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4229 sc->max_frame_size);
4231 /* Program appropriate promiscuous/multicast filtering. */
4232 bce_set_rx_mode(sc);
4234 /* Init RX buffer descriptor chain. */
4235 bce_init_rx_chain(sc); /* XXX return value */
4237 /* Init TX buffer descriptor chain. */
4238 bce_init_tx_chain(sc); /* XXX return value */
4240 #ifdef DEVICE_POLLING
4241 /* Disable interrupts if we are polling. */
4242 if (ifp->if_flags & IFF_POLLING) {
4243 bce_disable_intr(sc);
4245 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4246 (1 << 16) | sc->bce_rx_quick_cons_trip);
4247 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4248 (1 << 16) | sc->bce_tx_quick_cons_trip);
4251 /* Enable host interrupts. */
4252 bce_enable_intr(sc);
4254 bce_ifmedia_upd(ifp);
4256 ifp->if_flags |= IFF_RUNNING;
4257 ifp->if_flags &= ~IFF_OACTIVE;
4259 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
4266 /****************************************************************************/
4267 /* Initialize the controller just enough so that any management firmware */
4268 /* running on the device will continue to operate corectly. */
4272 /****************************************************************************/
4274 bce_mgmt_init(struct bce_softc *sc)
4276 struct ifnet *ifp = &sc->arpcom.ac_if;
4279 /* Check if the driver is still running and bail out if it is. */
4280 if (ifp->if_flags & IFF_RUNNING)
4283 /* Initialize the on-boards CPUs */
4286 /* Set the page size and clear the RV2P processor stall bits. */
4287 val = (BCM_PAGE_BITS - 8) << 24;
4288 REG_WR(sc, BCE_RV2P_CONFIG, val);
4290 /* Enable all critical blocks in the MAC. */
4291 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4292 BCE_MISC_ENABLE_SET_BITS_RX_V2P_ENABLE |
4293 BCE_MISC_ENABLE_SET_BITS_RX_DMA_ENABLE |
4294 BCE_MISC_ENABLE_SET_BITS_COMPLETION_ENABLE);
4295 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4298 bce_ifmedia_upd(ifp);
4302 /****************************************************************************/
4303 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4304 /* memory visible to the controller. */
4307 /* 0 for success, positive value for failure. */
4308 /****************************************************************************/
4310 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4312 struct bce_dmamap_arg ctx;
4313 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4314 bus_dmamap_t map, tmp_map;
4315 struct mbuf *m0 = *m_head;
4316 struct tx_bd *txbd = NULL;
4317 uint16_t vlan_tag = 0, flags = 0;
4318 uint16_t chain_prod, chain_prod_start, prod;
4320 int i, error, maxsegs;
4322 uint16_t debug_prod;
4325 /* Transfer any checksum offload flags to the bd. */
4326 if (m0->m_pkthdr.csum_flags) {
4327 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4328 flags |= TX_BD_FLAGS_IP_CKSUM;
4329 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4330 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4333 /* Transfer any VLAN tags to the bd. */
4334 if (m0->m_flags & M_VLANTAG) {
4335 flags |= TX_BD_FLAGS_VLAN_TAG;
4336 vlan_tag = m0->m_pkthdr.ether_vlantag;
4340 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4342 /* Map the mbuf into DMAable memory. */
4343 map = sc->tx_mbuf_map[chain_prod_start];
4345 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4346 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4347 ("not enough segements %d\n", maxsegs));
4348 if (maxsegs > BCE_MAX_SEGMENTS)
4349 maxsegs = BCE_MAX_SEGMENTS;
4351 /* Map the mbuf into our DMA address space. */
4352 ctx.bce_maxsegs = maxsegs;
4353 ctx.bce_segs = segs;
4354 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4355 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
4356 if (error == EFBIG || ctx.bce_maxsegs == 0) {
4357 DBPRINT(sc, BCE_WARN, "%s(): fragmented mbuf\n", __func__);
4358 DBRUNIF(1, bce_dump_mbuf(sc, m0););
4360 m0 = m_defrag(*m_head, MB_DONTWAIT);
4367 ctx.bce_maxsegs = maxsegs;
4368 ctx.bce_segs = segs;
4369 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4370 bce_dma_map_mbuf, &ctx,
4372 if (error || ctx.bce_maxsegs == 0) {
4373 if_printf(&sc->arpcom.ac_if,
4374 "Error mapping mbuf into TX chain\n");
4380 if_printf(&sc->arpcom.ac_if,
4381 "Error mapping mbuf into TX chain\n");
4385 /* prod points to an empty tx_bd at this point. */
4386 prod_bseq = sc->tx_prod_bseq;
4389 debug_prod = chain_prod;
4392 DBPRINT(sc, BCE_INFO_SEND,
4393 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4394 "prod_bseq = 0x%08X\n",
4395 __func__, prod, chain_prod, prod_bseq);
4398 * Cycle through each mbuf segment that makes up
4399 * the outgoing frame, gathering the mapping info
4400 * for that segment and creating a tx_bd to for
4403 for (i = 0; i < ctx.bce_maxsegs; i++) {
4404 chain_prod = TX_CHAIN_IDX(prod);
4405 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4407 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4408 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4409 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4410 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4411 txbd->tx_bd_flags = htole16(flags);
4412 prod_bseq += segs[i].ds_len;
4414 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4415 prod = NEXT_TX_BD(prod);
4418 /* Set the END flag on the last TX buffer descriptor. */
4419 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4421 DBRUN(BCE_EXCESSIVE_SEND,
4422 bce_dump_tx_chain(sc, debug_prod, ctx.bce_maxsegs));
4424 DBPRINT(sc, BCE_INFO_SEND,
4425 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4426 "prod_bseq = 0x%08X\n",
4427 __func__, prod, chain_prod, prod_bseq);
4429 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4432 * Ensure that the mbuf pointer for this transmission
4433 * is placed at the array index of the last
4434 * descriptor in this chain. This is done
4435 * because a single map is used for all
4436 * segments of the mbuf and we don't want to
4437 * unload the map before all of the segments
4440 sc->tx_mbuf_ptr[chain_prod] = m0;
4442 tmp_map = sc->tx_mbuf_map[chain_prod];
4443 sc->tx_mbuf_map[chain_prod] = map;
4444 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4446 sc->used_tx_bd += ctx.bce_maxsegs;
4448 /* Update some debug statistic counters */
4449 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4450 sc->tx_hi_watermark = sc->used_tx_bd);
4451 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
4452 DBRUNIF(1, sc->tx_mbuf_alloc++);
4454 DBRUN(BCE_VERBOSE_SEND,
4455 bce_dump_tx_mbuf_chain(sc, chain_prod, ctx.bce_maxsegs));
4457 /* prod points to the next free tx_bd at this point. */
4459 sc->tx_prod_bseq = prod_bseq;
4469 /****************************************************************************/
4470 /* Main transmit routine when called from another routine with a lock. */
4474 /****************************************************************************/
4476 bce_start(struct ifnet *ifp)
4478 struct bce_softc *sc = ifp->if_softc;
4481 ASSERT_SERIALIZED(ifp->if_serializer);
4483 /* If there's no link or the transmit queue is empty then just exit. */
4484 if (!sc->bce_link) {
4485 ifq_purge(&ifp->if_snd);
4489 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
4492 DBPRINT(sc, BCE_INFO_SEND,
4493 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04X, "
4494 "tx_prod_bseq = 0x%08X\n",
4496 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4499 struct mbuf *m_head;
4502 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4505 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4506 ifp->if_flags |= IFF_OACTIVE;
4510 /* Check for any frames to send. */
4511 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4516 * Pack the data into the transmit ring. If we
4517 * don't have room, place the mbuf back at the
4518 * head of the queue and set the OACTIVE flag
4519 * to wait for the NIC to drain the chain.
4521 if (bce_encap(sc, &m_head)) {
4522 ifp->if_flags |= IFF_OACTIVE;
4523 DBPRINT(sc, BCE_INFO_SEND,
4524 "TX chain is closed for business! "
4525 "Total tx_bd used = %d\n",
4532 /* Send a copy of the frame to any BPF listeners. */
4533 ETHER_BPF_MTAP(ifp, m_head);
4537 /* no packets were dequeued */
4538 DBPRINT(sc, BCE_VERBOSE_SEND,
4539 "%s(): No packets were dequeued\n", __func__);
4543 DBPRINT(sc, BCE_INFO_SEND,
4544 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
4545 "tx_prod_bseq = 0x%08X\n",
4547 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4549 /* Start the transmit. */
4550 REG_WR16(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
4551 REG_WR(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
4553 /* Set the tx timeout. */
4554 ifp->if_timer = BCE_TX_TIMEOUT;
4558 /****************************************************************************/
4559 /* Handles any IOCTL calls from the operating system. */
4562 /* 0 for success, positive value for failure. */
4563 /****************************************************************************/
4565 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
4567 struct bce_softc *sc = ifp->if_softc;
4568 struct ifreq *ifr = (struct ifreq *)data;
4569 struct mii_data *mii;
4570 int mask, error = 0;
4572 ASSERT_SERIALIZED(ifp->if_serializer);
4576 /* Check that the MTU setting is supported. */
4577 if (ifr->ifr_mtu < BCE_MIN_MTU ||
4579 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
4581 ifr->ifr_mtu > ETHERMTU
4588 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
4590 ifp->if_mtu = ifr->ifr_mtu;
4591 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4596 if (ifp->if_flags & IFF_UP) {
4597 if (ifp->if_flags & IFF_RUNNING) {
4598 mask = ifp->if_flags ^ sc->bce_if_flags;
4600 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
4601 bce_set_rx_mode(sc);
4605 } else if (ifp->if_flags & IFF_RUNNING) {
4608 sc->bce_if_flags = ifp->if_flags;
4613 if (ifp->if_flags & IFF_RUNNING)
4614 bce_set_rx_mode(sc);
4619 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
4621 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
4623 mii = device_get_softc(sc->bce_miibus);
4624 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
4628 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
4629 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
4632 if (mask & IFCAP_HWCSUM) {
4633 ifp->if_capenable ^= IFCAP_HWCSUM;
4634 if (IFCAP_HWCSUM & ifp->if_capenable)
4635 ifp->if_hwassist = BCE_IF_HWASSIST;
4637 ifp->if_hwassist = 0;
4642 error = ether_ioctl(ifp, command, data);
4649 /****************************************************************************/
4650 /* Transmit timeout handler. */
4654 /****************************************************************************/
4656 bce_watchdog(struct ifnet *ifp)
4658 struct bce_softc *sc = ifp->if_softc;
4660 ASSERT_SERIALIZED(ifp->if_serializer);
4662 DBRUN(BCE_VERBOSE_SEND,
4663 bce_dump_driver_state(sc);
4664 bce_dump_status_block(sc));
4667 * If we are in this routine because of pause frames, then
4668 * don't reset the hardware.
4670 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
4673 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
4675 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
4677 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4682 if (!ifq_is_empty(&ifp->if_snd))
4687 #ifdef DEVICE_POLLING
4690 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
4692 struct bce_softc *sc = ifp->if_softc;
4693 struct status_block *sblk = sc->status_block;
4695 ASSERT_SERIALIZED(ifp->if_serializer);
4699 bce_disable_intr(sc);
4701 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4702 (1 << 16) | sc->bce_rx_quick_cons_trip);
4703 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4704 (1 << 16) | sc->bce_tx_quick_cons_trip);
4706 case POLL_DEREGISTER:
4707 bce_enable_intr(sc);
4709 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4710 (sc->bce_tx_quick_cons_trip_int << 16) |
4711 sc->bce_tx_quick_cons_trip);
4712 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4713 (sc->bce_rx_quick_cons_trip_int << 16) |
4714 sc->bce_rx_quick_cons_trip);
4720 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4722 if (cmd == POLL_AND_CHECK_STATUS) {
4723 uint32_t status_attn_bits;
4725 status_attn_bits = sblk->status_attn_bits;
4727 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4729 "Simulating unexpected status attention bit set.");
4730 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4732 /* Was it a link change interrupt? */
4733 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4734 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4738 * If any other attention is asserted then
4739 * the chip is toast.
4741 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4742 (sblk->status_attn_bits_ack &
4743 ~STATUS_ATTN_BITS_LINK_STATE)) {
4744 DBRUN(1, sc->unexpected_attentions++);
4746 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4747 sblk->status_attn_bits);
4750 if (bce_debug_unexpected_attention == 0)
4751 bce_breakpoint(sc));
4758 /* Check for any completed RX frames. */
4759 if (sblk->status_rx_quick_consumer_index0 != sc->hw_rx_cons)
4760 bce_rx_intr(sc, count);
4762 /* Check for any completed TX frames. */
4763 if (sblk->status_tx_quick_consumer_index0 != sc->hw_tx_cons)
4766 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4768 /* Check for new frames to transmit. */
4769 if (!ifq_is_empty(&ifp->if_snd))
4773 #endif /* DEVICE_POLLING */
4778 bce_has_work(struct bce_softc *sc)
4780 struct status_block *stat = sc->status_block;
4782 if ((stat->status_rx_quick_consumer_index0 != sc->hw_rx_cons) ||
4783 (stat->status_tx_quick_consumer_index0 != sc->hw_tx_cons))
4786 if (((stat->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != 0) !=
4796 * Interrupt handler.
4798 /****************************************************************************/
4799 /* Main interrupt entry point. Verifies that the controller generated the */
4800 /* interrupt and then calls a separate routine for handle the various */
4801 /* interrupt causes (PHY, TX, RX). */
4804 /* 0 for success, positive value for failure. */
4805 /****************************************************************************/
4809 struct bce_softc *sc = xsc;
4810 struct ifnet *ifp = &sc->arpcom.ac_if;
4811 struct status_block *sblk;
4813 ASSERT_SERIALIZED(ifp->if_serializer);
4815 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
4816 DBRUNIF(1, sc->interrupts_generated++);
4818 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4819 sblk = sc->status_block;
4822 * If the hardware status block index matches the last value
4823 * read by the driver and we haven't asserted our interrupt
4824 * then there's nothing to do.
4826 if (sblk->status_idx == sc->last_status_idx &&
4827 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
4828 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
4831 /* Ack the interrupt and stop others from occuring. */
4832 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4833 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
4834 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4836 /* Keep processing data as long as there is work to do. */
4838 uint32_t status_attn_bits;
4840 status_attn_bits = sblk->status_attn_bits;
4842 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4844 "Simulating unexpected status attention bit set.");
4845 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4847 /* Was it a link change interrupt? */
4848 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4849 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4853 * If any other attention is asserted then
4854 * the chip is toast.
4856 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4857 (sblk->status_attn_bits_ack &
4858 ~STATUS_ATTN_BITS_LINK_STATE)) {
4859 DBRUN(1, sc->unexpected_attentions++);
4861 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4862 sblk->status_attn_bits);
4865 if (bce_debug_unexpected_attention == 0)
4866 bce_breakpoint(sc));
4872 /* Check for any completed RX frames. */
4873 if (sblk->status_rx_quick_consumer_index0 != sc->hw_rx_cons)
4874 bce_rx_intr(sc, -1);
4876 /* Check for any completed TX frames. */
4877 if (sblk->status_tx_quick_consumer_index0 != sc->hw_tx_cons)
4881 * Save the status block index value
4882 * for use during the next interrupt.
4884 sc->last_status_idx = sblk->status_idx;
4887 * Prevent speculative reads from getting
4888 * ahead of the status block.
4890 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4891 BUS_SPACE_BARRIER_READ);
4894 * If there's no work left then exit the
4895 * interrupt service routine.
4897 if (sblk->status_rx_quick_consumer_index0 == sc->hw_rx_cons &&
4898 sblk->status_tx_quick_consumer_index0 == sc->hw_tx_cons)
4902 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4904 /* Re-enable interrupts. */
4905 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4906 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
4907 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4908 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4909 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4911 /* Handle any frames that arrived while handling the interrupt. */
4912 if (!ifq_is_empty(&ifp->if_snd))
4917 /****************************************************************************/
4918 /* Programs the various packet receive modes (broadcast and multicast). */
4922 /****************************************************************************/
4924 bce_set_rx_mode(struct bce_softc *sc)
4926 struct ifnet *ifp = &sc->arpcom.ac_if;
4927 struct ifmultiaddr *ifma;
4928 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4929 uint32_t rx_mode, sort_mode;
4932 ASSERT_SERIALIZED(ifp->if_serializer);
4934 /* Initialize receive mode default settings. */
4935 rx_mode = sc->rx_mode &
4936 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
4937 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
4938 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
4941 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
4944 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
4945 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4946 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
4949 * Check for promiscuous, all multicast, or selected
4950 * multicast address filtering.
4952 if (ifp->if_flags & IFF_PROMISC) {
4953 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
4955 /* Enable promiscuous mode. */
4956 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
4957 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
4958 } else if (ifp->if_flags & IFF_ALLMULTI) {
4959 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
4961 /* Enable all multicast addresses. */
4962 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
4963 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
4966 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
4968 /* Accept one or more multicast(s). */
4969 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
4971 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4972 if (ifma->ifma_addr->sa_family != AF_LINK)
4975 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
4976 ETHER_ADDR_LEN) & 0xFF;
4977 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
4980 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
4981 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
4984 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
4987 /* Only make changes if the recive mode has actually changed. */
4988 if (rx_mode != sc->rx_mode) {
4989 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
4992 sc->rx_mode = rx_mode;
4993 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
4996 /* Disable and clear the exisitng sort before enabling a new sort. */
4997 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
4998 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
4999 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5003 /****************************************************************************/
5004 /* Called periodically to updates statistics from the controllers */
5005 /* statistics block. */
5009 /****************************************************************************/
5011 bce_stats_update(struct bce_softc *sc)
5013 struct ifnet *ifp = &sc->arpcom.ac_if;
5014 struct statistics_block *stats = sc->stats_block;
5016 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5018 ASSERT_SERIALIZED(ifp->if_serializer);
5021 * Update the interface statistics from the hardware statistics.
5023 ifp->if_collisions = (u_long)stats->stat_EtherStatsCollisions;
5025 ifp->if_ierrors = (u_long)stats->stat_EtherStatsUndersizePkts +
5026 (u_long)stats->stat_EtherStatsOverrsizePkts +
5027 (u_long)stats->stat_IfInMBUFDiscards +
5028 (u_long)stats->stat_Dot3StatsAlignmentErrors +
5029 (u_long)stats->stat_Dot3StatsFCSErrors;
5032 (u_long)stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5033 (u_long)stats->stat_Dot3StatsExcessiveCollisions +
5034 (u_long)stats->stat_Dot3StatsLateCollisions;
5037 * Certain controllers don't report carrier sense errors correctly.
5038 * See errata E11_5708CA0_1165.
5040 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5041 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5043 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5047 * Update the sysctl statistics from the hardware statistics.
5049 sc->stat_IfHCInOctets =
5050 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5051 (uint64_t)stats->stat_IfHCInOctets_lo;
5053 sc->stat_IfHCInBadOctets =
5054 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5055 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5057 sc->stat_IfHCOutOctets =
5058 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5059 (uint64_t)stats->stat_IfHCOutOctets_lo;
5061 sc->stat_IfHCOutBadOctets =
5062 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5063 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5065 sc->stat_IfHCInUcastPkts =
5066 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5067 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5069 sc->stat_IfHCInMulticastPkts =
5070 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5071 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5073 sc->stat_IfHCInBroadcastPkts =
5074 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5075 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5077 sc->stat_IfHCOutUcastPkts =
5078 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5079 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5081 sc->stat_IfHCOutMulticastPkts =
5082 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5083 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5085 sc->stat_IfHCOutBroadcastPkts =
5086 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5087 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5089 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5090 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5092 sc->stat_Dot3StatsCarrierSenseErrors =
5093 stats->stat_Dot3StatsCarrierSenseErrors;
5095 sc->stat_Dot3StatsFCSErrors =
5096 stats->stat_Dot3StatsFCSErrors;
5098 sc->stat_Dot3StatsAlignmentErrors =
5099 stats->stat_Dot3StatsAlignmentErrors;
5101 sc->stat_Dot3StatsSingleCollisionFrames =
5102 stats->stat_Dot3StatsSingleCollisionFrames;
5104 sc->stat_Dot3StatsMultipleCollisionFrames =
5105 stats->stat_Dot3StatsMultipleCollisionFrames;
5107 sc->stat_Dot3StatsDeferredTransmissions =
5108 stats->stat_Dot3StatsDeferredTransmissions;
5110 sc->stat_Dot3StatsExcessiveCollisions =
5111 stats->stat_Dot3StatsExcessiveCollisions;
5113 sc->stat_Dot3StatsLateCollisions =
5114 stats->stat_Dot3StatsLateCollisions;
5116 sc->stat_EtherStatsCollisions =
5117 stats->stat_EtherStatsCollisions;
5119 sc->stat_EtherStatsFragments =
5120 stats->stat_EtherStatsFragments;
5122 sc->stat_EtherStatsJabbers =
5123 stats->stat_EtherStatsJabbers;
5125 sc->stat_EtherStatsUndersizePkts =
5126 stats->stat_EtherStatsUndersizePkts;
5128 sc->stat_EtherStatsOverrsizePkts =
5129 stats->stat_EtherStatsOverrsizePkts;
5131 sc->stat_EtherStatsPktsRx64Octets =
5132 stats->stat_EtherStatsPktsRx64Octets;
5134 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5135 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5137 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5138 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5140 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5141 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5143 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5144 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5146 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5147 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5149 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5150 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5152 sc->stat_EtherStatsPktsTx64Octets =
5153 stats->stat_EtherStatsPktsTx64Octets;
5155 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5156 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5158 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5159 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5161 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5162 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5164 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5165 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5167 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5168 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5170 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5171 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5173 sc->stat_XonPauseFramesReceived =
5174 stats->stat_XonPauseFramesReceived;
5176 sc->stat_XoffPauseFramesReceived =
5177 stats->stat_XoffPauseFramesReceived;
5179 sc->stat_OutXonSent =
5180 stats->stat_OutXonSent;
5182 sc->stat_OutXoffSent =
5183 stats->stat_OutXoffSent;
5185 sc->stat_FlowControlDone =
5186 stats->stat_FlowControlDone;
5188 sc->stat_MacControlFramesReceived =
5189 stats->stat_MacControlFramesReceived;
5191 sc->stat_XoffStateEntered =
5192 stats->stat_XoffStateEntered;
5194 sc->stat_IfInFramesL2FilterDiscards =
5195 stats->stat_IfInFramesL2FilterDiscards;
5197 sc->stat_IfInRuleCheckerDiscards =
5198 stats->stat_IfInRuleCheckerDiscards;
5200 sc->stat_IfInFTQDiscards =
5201 stats->stat_IfInFTQDiscards;
5203 sc->stat_IfInMBUFDiscards =
5204 stats->stat_IfInMBUFDiscards;
5206 sc->stat_IfInRuleCheckerP4Hit =
5207 stats->stat_IfInRuleCheckerP4Hit;
5209 sc->stat_CatchupInRuleCheckerDiscards =
5210 stats->stat_CatchupInRuleCheckerDiscards;
5212 sc->stat_CatchupInFTQDiscards =
5213 stats->stat_CatchupInFTQDiscards;
5215 sc->stat_CatchupInMBUFDiscards =
5216 stats->stat_CatchupInMBUFDiscards;
5218 sc->stat_CatchupInRuleCheckerP4Hit =
5219 stats->stat_CatchupInRuleCheckerP4Hit;
5221 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5223 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5227 /****************************************************************************/
5228 /* Periodic function to perform maintenance tasks. */
5232 /****************************************************************************/
5234 bce_tick_serialized(struct bce_softc *sc)
5236 struct ifnet *ifp = &sc->arpcom.ac_if;
5237 struct mii_data *mii;
5240 ASSERT_SERIALIZED(ifp->if_serializer);
5242 /* Tell the firmware that the driver is still running. */
5244 msg = (uint32_t)BCE_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
5246 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5248 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_PULSE_MB, msg);
5250 /* Update the statistics from the hardware statistics block. */
5251 bce_stats_update(sc);
5253 /* Schedule the next tick. */
5254 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
5256 /* If link is up already up then we're done. */
5260 mii = device_get_softc(sc->bce_miibus);
5263 /* Check if the link has come up. */
5264 if (!sc->bce_link && (mii->mii_media_status & IFM_ACTIVE) &&
5265 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5267 /* Now that link is up, handle any outstanding TX traffic. */
5268 if (!ifq_is_empty(&ifp->if_snd))
5277 struct bce_softc *sc = xsc;
5278 struct ifnet *ifp = &sc->arpcom.ac_if;
5280 lwkt_serialize_enter(ifp->if_serializer);
5281 bce_tick_serialized(sc);
5282 lwkt_serialize_exit(ifp->if_serializer);
5287 /****************************************************************************/
5288 /* Allows the driver state to be dumped through the sysctl interface. */
5291 /* 0 for success, positive value for failure. */
5292 /****************************************************************************/
5294 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5298 struct bce_softc *sc;
5301 error = sysctl_handle_int(oidp, &result, 0, req);
5303 if (error || !req->newptr)
5307 sc = (struct bce_softc *)arg1;
5308 bce_dump_driver_state(sc);
5315 /****************************************************************************/
5316 /* Allows the hardware state to be dumped through the sysctl interface. */
5319 /* 0 for success, positive value for failure. */
5320 /****************************************************************************/
5322 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5326 struct bce_softc *sc;
5329 error = sysctl_handle_int(oidp, &result, 0, req);
5331 if (error || !req->newptr)
5335 sc = (struct bce_softc *)arg1;
5336 bce_dump_hw_state(sc);
5343 /****************************************************************************/
5344 /* Provides a sysctl interface to allows dumping the RX chain. */
5347 /* 0 for success, positive value for failure. */
5348 /****************************************************************************/
5350 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5354 struct bce_softc *sc;
5357 error = sysctl_handle_int(oidp, &result, 0, req);
5359 if (error || !req->newptr)
5363 sc = (struct bce_softc *)arg1;
5364 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5371 /****************************************************************************/
5372 /* Provides a sysctl interface to allows dumping the TX chain. */
5375 /* 0 for success, positive value for failure. */
5376 /****************************************************************************/
5378 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5382 struct bce_softc *sc;
5385 error = sysctl_handle_int(oidp, &result, 0, req);
5387 if (error || !req->newptr)
5391 sc = (struct bce_softc *)arg1;
5392 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
5399 /****************************************************************************/
5400 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5401 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5404 /* 0 for success, positive value for failure. */
5405 /****************************************************************************/
5407 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5409 struct bce_softc *sc;
5411 uint32_t val, result;
5414 error = sysctl_handle_int(oidp, &result, 0, req);
5415 if (error || (req->newptr == NULL))
5418 /* Make sure the register is accessible. */
5419 if (result < 0x8000) {
5420 sc = (struct bce_softc *)arg1;
5421 val = REG_RD(sc, result);
5422 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5424 } else if (result < 0x0280000) {
5425 sc = (struct bce_softc *)arg1;
5426 val = REG_RD_IND(sc, result);
5427 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5434 /****************************************************************************/
5435 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
\r
5436 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
\r
5439 /* 0 for success, positive value for failure. */
5440 /****************************************************************************/
5442 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
5444 struct bce_softc *sc;
5450 error = sysctl_handle_int(oidp, &result, 0, req);
5451 if (error || (req->newptr == NULL))
5454 /* Make sure the register is accessible. */
5455 if (result < 0x20) {
5456 sc = (struct bce_softc *)arg1;
5458 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
5459 if_printf(&sc->arpcom.ac_if,
5460 "phy 0x%02X = 0x%04X\n", result, val);
5466 /****************************************************************************/
5467 /* Provides a sysctl interface to forcing the driver to dump state and */
\r
5468 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5471 /* 0 for success, positive value for failure. */
5472 /****************************************************************************/
5474 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
5478 struct bce_softc *sc;
5481 error = sysctl_handle_int(oidp, &result, 0, req);
5483 if (error || !req->newptr)
5487 sc = (struct bce_softc *)arg1;
5496 /****************************************************************************/
5497 /* Adds any sysctl parameters for tuning or debugging purposes. */
5500 /* 0 for success, positive value for failure. */
5501 /****************************************************************************/
5503 bce_add_sysctls(struct bce_softc *sc)
5505 struct sysctl_ctx_list *ctx;
5506 struct sysctl_oid_list *children;
5508 sysctl_ctx_init(&sc->bce_sysctl_ctx);
5509 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
5510 SYSCTL_STATIC_CHILDREN(_hw),
5512 device_get_nameunit(sc->bce_dev),
5514 if (sc->bce_sysctl_tree == NULL) {
5515 device_printf(sc->bce_dev, "can't add sysctl node\n");
5519 ctx = &sc->bce_sysctl_ctx;
5520 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
5523 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5525 CTLFLAG_RD, &sc->rx_low_watermark,
5526 0, "Lowest level of free rx_bd's");
5528 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5530 CTLFLAG_RD, &sc->rx_empty_count,
5531 0, "Number of times the RX chain was empty");
5533 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5535 CTLFLAG_RD, &sc->tx_hi_watermark,
5536 0, "Highest level of used tx_bd's");
5538 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5540 CTLFLAG_RD, &sc->tx_full_count,
5541 0, "Number of times the TX chain was full");
5543 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5544 "l2fhdr_status_errors",
5545 CTLFLAG_RD, &sc->l2fhdr_status_errors,
5546 0, "l2_fhdr status errors");
5548 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5549 "unexpected_attentions",
5550 CTLFLAG_RD, &sc->unexpected_attentions,
5551 0, "unexpected attentions");
5553 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5554 "lost_status_block_updates",
5555 CTLFLAG_RD, &sc->lost_status_block_updates,
5556 0, "lost status block updates");
5558 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5559 "mbuf_alloc_failed",
5560 CTLFLAG_RD, &sc->mbuf_alloc_failed,
5561 0, "mbuf cluster allocation failures");
5564 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5565 "stat_IfHcInOctets",
5566 CTLFLAG_RD, &sc->stat_IfHCInOctets,
5569 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5570 "stat_IfHCInBadOctets",
5571 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
5572 "Bad bytes received");
5574 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5575 "stat_IfHCOutOctets",
5576 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
5579 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5580 "stat_IfHCOutBadOctets",
5581 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
5584 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5585 "stat_IfHCInUcastPkts",
5586 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
5587 "Unicast packets received");
5589 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5590 "stat_IfHCInMulticastPkts",
5591 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
5592 "Multicast packets received");
5594 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5595 "stat_IfHCInBroadcastPkts",
5596 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
5597 "Broadcast packets received");
5599 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5600 "stat_IfHCOutUcastPkts",
5601 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
5602 "Unicast packets sent");
5604 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5605 "stat_IfHCOutMulticastPkts",
5606 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
5607 "Multicast packets sent");
5609 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5610 "stat_IfHCOutBroadcastPkts",
5611 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
5612 "Broadcast packets sent");
5614 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5615 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
5616 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
5617 0, "Internal MAC transmit errors");
5619 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5620 "stat_Dot3StatsCarrierSenseErrors",
5621 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
5622 0, "Carrier sense errors");
5624 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5625 "stat_Dot3StatsFCSErrors",
5626 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
5627 0, "Frame check sequence errors");
5629 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5630 "stat_Dot3StatsAlignmentErrors",
5631 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
5632 0, "Alignment errors");
5634 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5635 "stat_Dot3StatsSingleCollisionFrames",
5636 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
5637 0, "Single Collision Frames");
5639 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5640 "stat_Dot3StatsMultipleCollisionFrames",
5641 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
5642 0, "Multiple Collision Frames");
5644 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5645 "stat_Dot3StatsDeferredTransmissions",
5646 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
5647 0, "Deferred Transmissions");
5649 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5650 "stat_Dot3StatsExcessiveCollisions",
5651 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
5652 0, "Excessive Collisions");
5654 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5655 "stat_Dot3StatsLateCollisions",
5656 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
5657 0, "Late Collisions");
5659 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5660 "stat_EtherStatsCollisions",
5661 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
5664 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5665 "stat_EtherStatsFragments",
5666 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
5669 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5670 "stat_EtherStatsJabbers",
5671 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
5674 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5675 "stat_EtherStatsUndersizePkts",
5676 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
5677 0, "Undersize packets");
5679 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5680 "stat_EtherStatsOverrsizePkts",
5681 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
5682 0, "stat_EtherStatsOverrsizePkts");
5684 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5685 "stat_EtherStatsPktsRx64Octets",
5686 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
5687 0, "Bytes received in 64 byte packets");
5689 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5690 "stat_EtherStatsPktsRx65Octetsto127Octets",
5691 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
5692 0, "Bytes received in 65 to 127 byte packets");
5694 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5695 "stat_EtherStatsPktsRx128Octetsto255Octets",
5696 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
5697 0, "Bytes received in 128 to 255 byte packets");
5699 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5700 "stat_EtherStatsPktsRx256Octetsto511Octets",
5701 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
5702 0, "Bytes received in 256 to 511 byte packets");
5704 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5705 "stat_EtherStatsPktsRx512Octetsto1023Octets",
5706 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
5707 0, "Bytes received in 512 to 1023 byte packets");
5709 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5710 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
5711 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
5712 0, "Bytes received in 1024 t0 1522 byte packets");
5714 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5715 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
5716 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
5717 0, "Bytes received in 1523 to 9022 byte packets");
5719 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5720 "stat_EtherStatsPktsTx64Octets",
5721 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
5722 0, "Bytes sent in 64 byte packets");
5724 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5725 "stat_EtherStatsPktsTx65Octetsto127Octets",
5726 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
5727 0, "Bytes sent in 65 to 127 byte packets");
5729 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5730 "stat_EtherStatsPktsTx128Octetsto255Octets",
5731 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
5732 0, "Bytes sent in 128 to 255 byte packets");
5734 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5735 "stat_EtherStatsPktsTx256Octetsto511Octets",
5736 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
5737 0, "Bytes sent in 256 to 511 byte packets");
5739 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5740 "stat_EtherStatsPktsTx512Octetsto1023Octets",
5741 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
5742 0, "Bytes sent in 512 to 1023 byte packets");
5744 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5745 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
5746 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
5747 0, "Bytes sent in 1024 to 1522 byte packets");
5749 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5750 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
5751 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
5752 0, "Bytes sent in 1523 to 9022 byte packets");
5754 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5755 "stat_XonPauseFramesReceived",
5756 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
5757 0, "XON pause frames receved");
5759 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5760 "stat_XoffPauseFramesReceived",
5761 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
5762 0, "XOFF pause frames received");
5764 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5766 CTLFLAG_RD, &sc->stat_OutXonSent,
5767 0, "XON pause frames sent");
5769 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5771 CTLFLAG_RD, &sc->stat_OutXoffSent,
5772 0, "XOFF pause frames sent");
5774 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5775 "stat_FlowControlDone",
5776 CTLFLAG_RD, &sc->stat_FlowControlDone,
5777 0, "Flow control done");
5779 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5780 "stat_MacControlFramesReceived",
5781 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
5782 0, "MAC control frames received");
5784 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5785 "stat_XoffStateEntered",
5786 CTLFLAG_RD, &sc->stat_XoffStateEntered,
5787 0, "XOFF state entered");
5789 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5790 "stat_IfInFramesL2FilterDiscards",
5791 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
5792 0, "Received L2 packets discarded");
5794 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5795 "stat_IfInRuleCheckerDiscards",
5796 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
5797 0, "Received packets discarded by rule");
5799 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5800 "stat_IfInFTQDiscards",
5801 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
5802 0, "Received packet FTQ discards");
5804 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5805 "stat_IfInMBUFDiscards",
5806 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
5807 0, "Received packets discarded due to lack of controller buffer memory");
5809 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5810 "stat_IfInRuleCheckerP4Hit",
5811 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
5812 0, "Received packets rule checker hits");
5814 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5815 "stat_CatchupInRuleCheckerDiscards",
5816 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
5817 0, "Received packets discarded in Catchup path");
5819 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5820 "stat_CatchupInFTQDiscards",
5821 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
5822 0, "Received packets discarded in FTQ in Catchup path");
5824 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5825 "stat_CatchupInMBUFDiscards",
5826 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
5827 0, "Received packets discarded in controller buffer memory in Catchup path");
5829 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5830 "stat_CatchupInRuleCheckerP4Hit",
5831 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
5832 0, "Received packets rule checker hits in Catchup path");
5834 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5836 CTLFLAG_RD, &sc->com_no_buffers,
5837 0, "Valid packets received but no RX buffers available");
5840 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5841 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
5843 bce_sysctl_driver_state, "I", "Drive state information");
5845 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5846 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
5848 bce_sysctl_hw_state, "I", "Hardware state information");
5850 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5851 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
5853 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
5855 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5856 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
5858 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
5860 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5861 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
5863 bce_sysctl_breakpoint, "I", "Driver breakpoint");
5865 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5866 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
5868 bce_sysctl_reg_read, "I", "Register read");
5870 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
\r
5871 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
\r
5873 bce_sysctl_phy_read, "I", "PHY register read");
5880 /****************************************************************************/
5881 /* BCE Debug Routines */
5882 /****************************************************************************/
5885 /****************************************************************************/
5886 /* Freezes the controller to allow for a cohesive state dump. */
5890 /****************************************************************************/
5892 bce_freeze_controller(struct bce_softc *sc)
5896 val = REG_RD(sc, BCE_MISC_COMMAND);
5897 val |= BCE_MISC_COMMAND_DISABLE_ALL;
5898 REG_WR(sc, BCE_MISC_COMMAND, val);
5902 /****************************************************************************/
5903 /* Unfreezes the controller after a freeze operation. This may not always */
\r
5904 /* work and the controller will require a reset! */
5908 /****************************************************************************/
5910 bce_unfreeze_controller(struct bce_softc *sc)
5914 val = REG_RD(sc, BCE_MISC_COMMAND);
5915 val |= BCE_MISC_COMMAND_ENABLE_ALL;
5916 REG_WR(sc, BCE_MISC_COMMAND, val);
5920 /****************************************************************************/
5921 /* Prints out information about an mbuf. */
5925 /****************************************************************************/
5927 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
5929 struct ifnet *ifp = &sc->arpcom.ac_if;
5930 uint32_t val_hi, val_lo;
5931 struct mbuf *mp = m;
5934 /* Index out of range. */
5935 if_printf(ifp, "mbuf: null pointer\n");
5940 val_hi = BCE_ADDR_HI(mp);
5941 val_lo = BCE_ADDR_LO(mp);
5942 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
5943 "m_flags = ( ", val_hi, val_lo, mp->m_len);
5945 if (mp->m_flags & M_EXT)
5947 if (mp->m_flags & M_PKTHDR)
5948 kprintf("M_PKTHDR ");
5949 if (mp->m_flags & M_EOR)
5952 if (mp->m_flags & M_RDONLY)
5953 kprintf("M_RDONLY ");
5956 val_hi = BCE_ADDR_HI(mp->m_data);
5957 val_lo = BCE_ADDR_LO(mp->m_data);
5958 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
5960 if (mp->m_flags & M_PKTHDR) {
5961 if_printf(ifp, "- m_pkthdr: flags = ( ");
5962 if (mp->m_flags & M_BCAST)
5963 kprintf("M_BCAST ");
5964 if (mp->m_flags & M_MCAST)
5965 kprintf("M_MCAST ");
5966 if (mp->m_flags & M_FRAG)
5968 if (mp->m_flags & M_FIRSTFRAG)
5969 kprintf("M_FIRSTFRAG ");
5970 if (mp->m_flags & M_LASTFRAG)
5971 kprintf("M_LASTFRAG ");
5973 if (mp->m_flags & M_VLANTAG)
5974 kprintf("M_VLANTAG ");
5977 if (mp->m_flags & M_PROMISC)
5978 kprintf("M_PROMISC ");
5980 kprintf(") csum_flags = ( ");
5981 if (mp->m_pkthdr.csum_flags & CSUM_IP)
5982 kprintf("CSUM_IP ");
5983 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
5984 kprintf("CSUM_TCP ");
5985 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
5986 kprintf("CSUM_UDP ");
5987 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
5988 kprintf("CSUM_IP_FRAGS ");
5989 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
5990 kprintf("CSUM_FRAGMENT ");
5992 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
5993 kprintf("CSUM_TSO ");
5995 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
5996 kprintf("CSUM_IP_CHECKED ");
5997 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
5998 kprintf("CSUM_IP_VALID ");
5999 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6000 kprintf("CSUM_DATA_VALID ");
6004 if (mp->m_flags & M_EXT) {
6005 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6006 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6007 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6009 val_hi, val_lo, mp->m_ext.ext_size);
6016 /****************************************************************************/
6017 /* Prints out the mbufs in the TX mbuf chain. */
6021 /****************************************************************************/
6023 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6025 struct ifnet *ifp = &sc->arpcom.ac_if;
6029 "----------------------------"
6031 "----------------------------\n");
6033 for (i = 0; i < count; i++) {
6034 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6035 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6036 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6040 "----------------------------"
6042 "----------------------------\n");
6046 /****************************************************************************/
6047 /* Prints out the mbufs in the RX mbuf chain. */
6051 /****************************************************************************/
6053 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6055 struct ifnet *ifp = &sc->arpcom.ac_if;
6059 "----------------------------"
6061 "----------------------------\n");
6063 for (i = 0; i < count; i++) {
6064 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6065 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6066 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6070 "----------------------------"
6072 "----------------------------\n");
6076 /****************************************************************************/
6077 /* Prints out a tx_bd structure. */
6081 /****************************************************************************/
6083 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6085 struct ifnet *ifp = &sc->arpcom.ac_if;
6087 if (idx > MAX_TX_BD) {
6088 /* Index out of range. */
6089 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6090 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6091 /* TX Chain page pointer. */
6092 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6093 "chain page pointer\n",
6094 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6096 /* Normal tx_bd entry. */
6097 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6099 "vlan tag= 0x%04X, flags = 0x%04X (",
6100 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6101 txbd->tx_bd_mss_nbytes,
6102 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6104 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6105 kprintf(" CONN_FAULT");
6107 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6108 kprintf(" TCP_UDP_CKSUM");
6110 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6111 kprintf(" IP_CKSUM");
6113 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6116 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6117 kprintf(" COAL_NOW");
6119 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6120 kprintf(" DONT_GEN_CRC");
6122 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6125 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6128 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6131 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6132 kprintf(" OPTION_WORD");
6134 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6137 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6145 /****************************************************************************/
6146 /* Prints out a rx_bd structure. */
6150 /****************************************************************************/
6152 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6154 struct ifnet *ifp = &sc->arpcom.ac_if;
6156 if (idx > MAX_RX_BD) {
6157 /* Index out of range. */
6158 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6159 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6160 /* TX Chain page pointer. */
6161 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6162 "chain page pointer\n",
6163 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6165 /* Normal tx_bd entry. */
6166 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6167 "nbytes = 0x%08X, flags = 0x%08X\n",
6168 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6169 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6174 /****************************************************************************/
6175 /* Prints out a l2_fhdr structure. */
6179 /****************************************************************************/
6181 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6183 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6184 "pkt_len = 0x%04X, vlan = 0x%04x, "
6185 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6186 idx, l2fhdr->l2_fhdr_status,
6187 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6188 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6192 /****************************************************************************/
6193 /* Prints out the tx chain. */
6197 /****************************************************************************/
6199 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6201 struct ifnet *ifp = &sc->arpcom.ac_if;
6204 /* First some info about the tx_bd chain structure. */
6206 "----------------------------"
6208 "----------------------------\n");
6210 if_printf(ifp, "page size = 0x%08X, "
6211 "tx chain pages = 0x%08X\n",
6212 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6214 if_printf(ifp, "tx_bd per page = 0x%08X, "
6215 "usable tx_bd per page = 0x%08X\n",
6216 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6217 (uint32_t)USABLE_TX_BD_PER_PAGE);
6219 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6222 "----------------------------"
6224 "----------------------------\n");
6226 /* Now print out the tx_bd's themselves. */
6227 for (i = 0; i < count; i++) {
6230 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6231 bce_dump_txbd(sc, tx_prod, txbd);
6232 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6236 "----------------------------"
6238 "----------------------------\n");
6242 /****************************************************************************/
6243 /* Prints out the rx chain. */
6247 /****************************************************************************/
6249 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6251 struct ifnet *ifp = &sc->arpcom.ac_if;
6254 /* First some info about the tx_bd chain structure. */
6256 "----------------------------"
6258 "----------------------------\n");
6260 if_printf(ifp, "page size = 0x%08X, "
6261 "rx chain pages = 0x%08X\n",
6262 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6264 if_printf(ifp, "rx_bd per page = 0x%08X, "
6265 "usable rx_bd per page = 0x%08X\n",
6266 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6267 (uint32_t)USABLE_RX_BD_PER_PAGE);
6269 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6272 "----------------------------"
6274 "----------------------------\n");
6276 /* Now print out the rx_bd's themselves. */
6277 for (i = 0; i < count; i++) {
6280 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6281 bce_dump_rxbd(sc, rx_prod, rxbd);
6282 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6286 "----------------------------"
6288 "----------------------------\n");
6292 /****************************************************************************/
6293 /* Prints out the status block from host memory. */
6297 /****************************************************************************/
6299 bce_dump_status_block(struct bce_softc *sc)
6301 struct status_block *sblk = sc->status_block;
6302 struct ifnet *ifp = &sc->arpcom.ac_if;
6305 "----------------------------"
6307 "----------------------------\n");
6309 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6311 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6312 sblk->status_attn_bits_ack);
6314 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6315 sblk->status_rx_quick_consumer_index0,
6316 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6318 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6319 sblk->status_tx_quick_consumer_index0,
6320 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6322 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6324 /* Theses indices are not used for normal L2 drivers. */
6325 if (sblk->status_rx_quick_consumer_index1) {
6326 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6327 sblk->status_rx_quick_consumer_index1,
6328 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
6331 if (sblk->status_tx_quick_consumer_index1) {
6332 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6333 sblk->status_tx_quick_consumer_index1,
6334 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
6337 if (sblk->status_rx_quick_consumer_index2) {
6338 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6339 sblk->status_rx_quick_consumer_index2,
6340 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
6343 if (sblk->status_tx_quick_consumer_index2) {
6344 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6345 sblk->status_tx_quick_consumer_index2,
6346 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
6349 if (sblk->status_rx_quick_consumer_index3) {
6350 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6351 sblk->status_rx_quick_consumer_index3,
6352 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
6355 if (sblk->status_tx_quick_consumer_index3) {
6356 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6357 sblk->status_tx_quick_consumer_index3,
6358 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
6361 if (sblk->status_rx_quick_consumer_index4 ||
6362 sblk->status_rx_quick_consumer_index5) {
6363 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6364 sblk->status_rx_quick_consumer_index4,
6365 sblk->status_rx_quick_consumer_index5);
6368 if (sblk->status_rx_quick_consumer_index6 ||
6369 sblk->status_rx_quick_consumer_index7) {
6370 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6371 sblk->status_rx_quick_consumer_index6,
6372 sblk->status_rx_quick_consumer_index7);
6375 if (sblk->status_rx_quick_consumer_index8 ||
6376 sblk->status_rx_quick_consumer_index9) {
6377 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6378 sblk->status_rx_quick_consumer_index8,
6379 sblk->status_rx_quick_consumer_index9);
6382 if (sblk->status_rx_quick_consumer_index10 ||
6383 sblk->status_rx_quick_consumer_index11) {
6384 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6385 sblk->status_rx_quick_consumer_index10,
6386 sblk->status_rx_quick_consumer_index11);
6389 if (sblk->status_rx_quick_consumer_index12 ||
6390 sblk->status_rx_quick_consumer_index13) {
6391 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6392 sblk->status_rx_quick_consumer_index12,
6393 sblk->status_rx_quick_consumer_index13);
6396 if (sblk->status_rx_quick_consumer_index14 ||
6397 sblk->status_rx_quick_consumer_index15) {
6398 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6399 sblk->status_rx_quick_consumer_index14,
6400 sblk->status_rx_quick_consumer_index15);
6403 if (sblk->status_completion_producer_index ||
6404 sblk->status_cmd_consumer_index) {
6405 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6406 sblk->status_completion_producer_index,
6407 sblk->status_cmd_consumer_index);
6411 "----------------------------"
6413 "----------------------------\n");
6417 /****************************************************************************/
6418 /* Prints out the statistics block. */
6422 /****************************************************************************/
6424 bce_dump_stats_block(struct bce_softc *sc)
6426 struct statistics_block *sblk = sc->stats_block;
6427 struct ifnet *ifp = &sc->arpcom.ac_if;
6431 " Stats Block (All Stats Not Shown Are 0) "
6432 "---------------\n");
6434 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
6435 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
6436 sblk->stat_IfHCInOctets_hi,
6437 sblk->stat_IfHCInOctets_lo);
6440 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
6441 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
6442 sblk->stat_IfHCInBadOctets_hi,
6443 sblk->stat_IfHCInBadOctets_lo);
6446 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
6447 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
6448 sblk->stat_IfHCOutOctets_hi,
6449 sblk->stat_IfHCOutOctets_lo);
6452 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
6453 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
6454 sblk->stat_IfHCOutBadOctets_hi,
6455 sblk->stat_IfHCOutBadOctets_lo);
6458 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
6459 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
6460 sblk->stat_IfHCInUcastPkts_hi,
6461 sblk->stat_IfHCInUcastPkts_lo);
6464 if (sblk->stat_IfHCInBroadcastPkts_hi ||
6465 sblk->stat_IfHCInBroadcastPkts_lo) {
6466 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
6467 sblk->stat_IfHCInBroadcastPkts_hi,
6468 sblk->stat_IfHCInBroadcastPkts_lo);
6471 if (sblk->stat_IfHCInMulticastPkts_hi ||
6472 sblk->stat_IfHCInMulticastPkts_lo) {
6473 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
6474 sblk->stat_IfHCInMulticastPkts_hi,
6475 sblk->stat_IfHCInMulticastPkts_lo);
6478 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
6479 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
6480 sblk->stat_IfHCOutUcastPkts_hi,
6481 sblk->stat_IfHCOutUcastPkts_lo);
6484 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
6485 sblk->stat_IfHCOutBroadcastPkts_lo) {
6486 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
6487 sblk->stat_IfHCOutBroadcastPkts_hi,
6488 sblk->stat_IfHCOutBroadcastPkts_lo);
6491 if (sblk->stat_IfHCOutMulticastPkts_hi ||
6492 sblk->stat_IfHCOutMulticastPkts_lo) {
6493 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
6494 sblk->stat_IfHCOutMulticastPkts_hi,
6495 sblk->stat_IfHCOutMulticastPkts_lo);
6498 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
6499 if_printf(ifp, " 0x%08X : "
6500 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
6501 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
6504 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
6505 if_printf(ifp, " 0x%08X : "
6506 "Dot3StatsCarrierSenseErrors\n",
6507 sblk->stat_Dot3StatsCarrierSenseErrors);
6510 if (sblk->stat_Dot3StatsFCSErrors) {
6511 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
6512 sblk->stat_Dot3StatsFCSErrors);
6515 if (sblk->stat_Dot3StatsAlignmentErrors) {
6516 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
6517 sblk->stat_Dot3StatsAlignmentErrors);
6520 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
6521 if_printf(ifp, " 0x%08X : "
6522 "Dot3StatsSingleCollisionFrames\n",
6523 sblk->stat_Dot3StatsSingleCollisionFrames);
6526 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
6527 if_printf(ifp, " 0x%08X : "
6528 "Dot3StatsMultipleCollisionFrames\n",
6529 sblk->stat_Dot3StatsMultipleCollisionFrames);
6532 if (sblk->stat_Dot3StatsDeferredTransmissions) {
6533 if_printf(ifp, " 0x%08X : "
6534 "Dot3StatsDeferredTransmissions\n",
6535 sblk->stat_Dot3StatsDeferredTransmissions);
6538 if (sblk->stat_Dot3StatsExcessiveCollisions) {
6539 if_printf(ifp, " 0x%08X : "
6540 "Dot3StatsExcessiveCollisions\n",
6541 sblk->stat_Dot3StatsExcessiveCollisions);
6544 if (sblk->stat_Dot3StatsLateCollisions) {
6545 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
6546 sblk->stat_Dot3StatsLateCollisions);
6549 if (sblk->stat_EtherStatsCollisions) {
6550 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
6551 sblk->stat_EtherStatsCollisions);
6554 if (sblk->stat_EtherStatsFragments) {
6555 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
6556 sblk->stat_EtherStatsFragments);
6559 if (sblk->stat_EtherStatsJabbers) {
6560 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
6561 sblk->stat_EtherStatsJabbers);
6564 if (sblk->stat_EtherStatsUndersizePkts) {
6565 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
6566 sblk->stat_EtherStatsUndersizePkts);
6569 if (sblk->stat_EtherStatsOverrsizePkts) {
6570 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
6571 sblk->stat_EtherStatsOverrsizePkts);
6574 if (sblk->stat_EtherStatsPktsRx64Octets) {
6575 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
6576 sblk->stat_EtherStatsPktsRx64Octets);
6579 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
6580 if_printf(ifp, " 0x%08X : "
6581 "EtherStatsPktsRx65Octetsto127Octets\n",
6582 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
6585 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
6586 if_printf(ifp, " 0x%08X : "
6587 "EtherStatsPktsRx128Octetsto255Octets\n",
6588 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
6591 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
6592 if_printf(ifp, " 0x%08X : "
6593 "EtherStatsPktsRx256Octetsto511Octets\n",
6594 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
6597 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
6598 if_printf(ifp, " 0x%08X : "
6599 "EtherStatsPktsRx512Octetsto1023Octets\n",
6600 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
6603 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
6604 if_printf(ifp, " 0x%08X : "
6605 "EtherStatsPktsRx1024Octetsto1522Octets\n",
6606 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
6609 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
6610 if_printf(ifp, " 0x%08X : "
6611 "EtherStatsPktsRx1523Octetsto9022Octets\n",
6612 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
6615 if (sblk->stat_EtherStatsPktsTx64Octets) {
6616 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
6617 sblk->stat_EtherStatsPktsTx64Octets);
6620 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
6621 if_printf(ifp, " 0x%08X : "
6622 "EtherStatsPktsTx65Octetsto127Octets\n",
6623 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
6626 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
6627 if_printf(ifp, " 0x%08X : "
6628 "EtherStatsPktsTx128Octetsto255Octets\n",
6629 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
6632 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
6633 if_printf(ifp, " 0x%08X : "
6634 "EtherStatsPktsTx256Octetsto511Octets\n",
6635 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
6638 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
6639 if_printf(ifp, " 0x%08X : "
6640 "EtherStatsPktsTx512Octetsto1023Octets\n",
6641 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
6644 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
6645 if_printf(ifp, " 0x%08X : "
6646 "EtherStatsPktsTx1024Octetsto1522Octets\n",
6647 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
6650 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
6651 if_printf(ifp, " 0x%08X : "
6652 "EtherStatsPktsTx1523Octetsto9022Octets\n",
6653 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
6656 if (sblk->stat_XonPauseFramesReceived) {
6657 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
6658 sblk->stat_XonPauseFramesReceived);
6661 if (sblk->stat_XoffPauseFramesReceived) {
6662 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
6663 sblk->stat_XoffPauseFramesReceived);
6666 if (sblk->stat_OutXonSent) {
6667 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6668 sblk->stat_OutXonSent);
6671 if (sblk->stat_OutXoffSent) {
6672 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6673 sblk->stat_OutXoffSent);
6676 if (sblk->stat_FlowControlDone) {
6677 if_printf(ifp, " 0x%08X : FlowControlDone\n",
6678 sblk->stat_FlowControlDone);
6681 if (sblk->stat_MacControlFramesReceived) {
6682 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
6683 sblk->stat_MacControlFramesReceived);
6686 if (sblk->stat_XoffStateEntered) {
6687 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
6688 sblk->stat_XoffStateEntered);
6691 if (sblk->stat_IfInFramesL2FilterDiscards) {
6692 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
6695 if (sblk->stat_IfInRuleCheckerDiscards) {
6696 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
6697 sblk->stat_IfInRuleCheckerDiscards);
6700 if (sblk->stat_IfInFTQDiscards) {
6701 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
6702 sblk->stat_IfInFTQDiscards);
6705 if (sblk->stat_IfInMBUFDiscards) {
6706 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
6707 sblk->stat_IfInMBUFDiscards);
6710 if (sblk->stat_IfInRuleCheckerP4Hit) {
6711 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
6712 sblk->stat_IfInRuleCheckerP4Hit);
6715 if (sblk->stat_CatchupInRuleCheckerDiscards) {
6716 if_printf(ifp, " 0x%08X : "
6717 "CatchupInRuleCheckerDiscards\n",
6718 sblk->stat_CatchupInRuleCheckerDiscards);
6721 if (sblk->stat_CatchupInFTQDiscards) {
6722 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
6723 sblk->stat_CatchupInFTQDiscards);
6726 if (sblk->stat_CatchupInMBUFDiscards) {
6727 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
6728 sblk->stat_CatchupInMBUFDiscards);
6731 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
6732 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
6733 sblk->stat_CatchupInRuleCheckerP4Hit);
6737 "----------------------------"
6739 "----------------------------\n");
6743 /****************************************************************************/
6744 /* Prints out a summary of the driver state. */
6748 /****************************************************************************/
6750 bce_dump_driver_state(struct bce_softc *sc)
6752 struct ifnet *ifp = &sc->arpcom.ac_if;
6753 uint32_t val_hi, val_lo;
6756 "-----------------------------"
6758 "-----------------------------\n");
6760 val_hi = BCE_ADDR_HI(sc);
6761 val_lo = BCE_ADDR_LO(sc);
6762 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
6763 "virtual address\n", val_hi, val_lo);
6765 val_hi = BCE_ADDR_HI(sc->status_block);
6766 val_lo = BCE_ADDR_LO(sc->status_block);
6767 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
6768 "virtual address\n", val_hi, val_lo);
6770 val_hi = BCE_ADDR_HI(sc->stats_block);
6771 val_lo = BCE_ADDR_LO(sc->stats_block);
6772 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
6773 "virtual address\n", val_hi, val_lo);
6775 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
6776 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
6777 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
6778 "virtual adddress\n", val_hi, val_lo);
6780 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
6781 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
6782 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
6783 "virtual address\n", val_hi, val_lo);
6785 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
6786 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
6787 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
6788 "virtual address\n", val_hi, val_lo);
6790 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
6791 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
6792 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
6793 "virtual address\n", val_hi, val_lo);
6795 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
6796 "h/w intrs\n", sc->interrupts_generated);
6798 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
6799 "rx interrupts handled\n", sc->rx_interrupts);
6801 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
6802 "tx interrupts handled\n", sc->tx_interrupts);
6804 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
6805 "status block index\n", sc->last_status_idx);
6807 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
6808 "tx producer index\n",
6809 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
6811 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
6812 "tx consumer index\n",
6813 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
6815 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
6816 "tx producer bseq index\n", sc->tx_prod_bseq);
6818 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
6819 "rx producer index\n",
6820 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
6822 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
6823 "rx consumer index\n",
6824 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
6826 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
6827 "rx producer bseq index\n", sc->rx_prod_bseq);
6829 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6830 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6832 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
6833 "free rx_bd's\n", sc->free_rx_bd);
6835 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
6836 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
6838 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
6839 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
6841 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6842 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6844 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
6847 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
6848 sc->tx_hi_watermark, sc->max_tx_bd);
6850 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
6851 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
6854 "----------------------------"
6856 "----------------------------\n");
6860 /****************************************************************************/
6861 /* Prints out the hardware state through a summary of important registers, */
\r
6862 /* followed by a complete register dump. */
6866 /****************************************************************************/
6868 bce_dump_hw_state(struct bce_softc *sc)
6870 struct ifnet *ifp = &sc->arpcom.ac_if;
6875 "----------------------------"
6877 "----------------------------\n");
6879 if_printf(ifp, "0x%08X - bootcode version\n", sc->bce_fw_ver);
6881 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
6882 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
6883 val1, BCE_MISC_ENABLE_STATUS_BITS);
6885 val1 = REG_RD(sc, BCE_DMA_STATUS);
6886 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
6888 val1 = REG_RD(sc, BCE_CTX_STATUS);
6889 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
6891 val1 = REG_RD(sc, BCE_EMAC_STATUS);
6892 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
6893 val1, BCE_EMAC_STATUS);
6895 val1 = REG_RD(sc, BCE_RPM_STATUS);
6896 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
6898 val1 = REG_RD(sc, BCE_TBDR_STATUS);
6899 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
6900 val1, BCE_TBDR_STATUS);
6902 val1 = REG_RD(sc, BCE_TDMA_STATUS);
6903 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
6904 val1, BCE_TDMA_STATUS);
6906 val1 = REG_RD(sc, BCE_HC_STATUS);
6907 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
6909 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
6910 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
6911 val1, BCE_TXP_CPU_STATE);
6913 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
6914 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
6915 val1, BCE_TPAT_CPU_STATE);
6917 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
6918 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
6919 val1, BCE_RXP_CPU_STATE);
6921 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
6922 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
6923 val1, BCE_COM_CPU_STATE);
6925 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
6926 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
6927 val1, BCE_MCP_CPU_STATE);
6929 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
6930 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
6931 val1, BCE_CP_CPU_STATE);
6934 "----------------------------"
6936 "----------------------------\n");
6939 "----------------------------"
6941 "----------------------------\n");
6943 for (i = 0x400; i < 0x8000; i += 0x10) {
6944 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
6946 REG_RD(sc, i + 0x4),
6947 REG_RD(sc, i + 0x8),
6948 REG_RD(sc, i + 0xc));
6952 "----------------------------"
6954 "----------------------------\n");
6958 /****************************************************************************/
6959 /* Prints out the TXP state. */
\r
6963 /****************************************************************************/
6965 bce_dump_txp_state(struct bce_softc *sc)
6967 struct ifnet *ifp = &sc->arpcom.ac_if;
6972 "----------------------------"
6974 "----------------------------\n");
6976 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
6977 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
6978 val1, BCE_TXP_CPU_MODE);
6980 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
6981 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
6982 val1, BCE_TXP_CPU_STATE);
6984 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
6985 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
6986 val1, BCE_TXP_CPU_EVENT_MASK);
6989 "----------------------------"
6991 "----------------------------\n");
6993 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
6994 /* Skip the big blank spaces */
6995 if (i < 0x454000 && i > 0x5ffff) {
6996 if_printf(ifp, "0x%04X: "
6997 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
6999 REG_RD_IND(sc, i + 0x4),
7000 REG_RD_IND(sc, i + 0x8),
7001 REG_RD_IND(sc, i + 0xc));
7006 "----------------------------"
7008 "----------------------------\n");
7012 /****************************************************************************/
7013 /* Prints out the RXP state. */
\r
7017 /****************************************************************************/
7019 bce_dump_rxp_state(struct bce_softc *sc)
7021 struct ifnet *ifp = &sc->arpcom.ac_if;
7026 "----------------------------"
7028 "----------------------------\n");
7030 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7031 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7032 val1, BCE_RXP_CPU_MODE);
7034 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7035 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7036 val1, BCE_RXP_CPU_STATE);
7038 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7039 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7040 val1, BCE_RXP_CPU_EVENT_MASK);
7043 "----------------------------"
7045 "----------------------------\n");
7047 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7048 /* Skip the big blank sapces */
7049 if (i < 0xc5400 && i > 0xdffff) {
7050 if_printf(ifp, "0x%04X: "
7051 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7053 REG_RD_IND(sc, i + 0x4),
7054 REG_RD_IND(sc, i + 0x8),
7055 REG_RD_IND(sc, i + 0xc));
7060 "----------------------------"
7062 "----------------------------\n");
7066 /****************************************************************************/
7067 /* Prints out the TPAT state. */
\r
7071 /****************************************************************************/
7073 bce_dump_tpat_state(struct bce_softc *sc)
7075 struct ifnet *ifp = &sc->arpcom.ac_if;
7080 "----------------------------"
7082 "----------------------------\n");
7084 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7085 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7086 val1, BCE_TPAT_CPU_MODE);
7088 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7089 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7090 val1, BCE_TPAT_CPU_STATE);
7092 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7093 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7094 val1, BCE_TPAT_CPU_EVENT_MASK);
7097 "----------------------------"
7099 "----------------------------\n");
7101 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7102 /* Skip the big blank spaces */
7103 if (i < 0x854000 && i > 0x9ffff) {
7104 if_printf(ifp, "0x%04X: "
7105 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7107 REG_RD_IND(sc, i + 0x4),
7108 REG_RD_IND(sc, i + 0x8),
7109 REG_RD_IND(sc, i + 0xc));
7114 "----------------------------"
7116 "----------------------------\n");
7120 /****************************************************************************/
7121 /* Prints out the driver state and then enters the debugger. */
7125 /****************************************************************************/
7127 bce_breakpoint(struct bce_softc *sc)
7130 bce_freeze_controller(sc);
7133 bce_dump_driver_state(sc);
7134 bce_dump_status_block(sc);
7135 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7136 bce_dump_hw_state(sc);
7137 bce_dump_txp_state(sc);
7140 bce_unfreeze_controller(sc);
7143 /* Call the debugger. */
7147 #endif /* BCE_DEBUG */