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.2 2008/03/10 10:47:57 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>
54 #include <sys/malloc.h>
55 #include <sys/queue.h>
57 #include <sys/random.h>
60 #include <sys/serialize.h>
61 #include <sys/socket.h>
62 #include <sys/sockio.h>
63 #include <sys/sysctl.h>
66 #include <net/ethernet.h>
68 #include <net/if_arp.h>
69 #include <net/if_dl.h>
70 #include <net/if_media.h>
71 #include <net/if_types.h>
72 #include <net/ifq_var.h>
73 #include <net/vlan/if_vlan_var.h>
75 #include <dev/netif/mii_layer/mii.h>
76 #include <dev/netif/mii_layer/miivar.h>
78 #include <bus/pci/pcireg.h>
79 #include <bus/pci/pcivar.h>
81 #include "miibus_if.h"
83 #include "if_bcereg.h"
86 /****************************************************************************/
87 /* BCE Debug Options */
88 /****************************************************************************/
91 static uint32_t bce_debug = BCE_WARN;
95 * 1 = 1 in 2,147,483,648
96 * 256 = 1 in 8,388,608
97 * 2048 = 1 in 1,048,576
99 * 1048576 = 1 in 2,048
102 * 1073741824 = 1 in 2
104 * bce_debug_l2fhdr_status_check:
105 * How often the l2_fhdr frame error check will fail.
107 * bce_debug_unexpected_attention:
108 * How often the unexpected attention check will fail.
110 * bce_debug_mbuf_allocation_failure:
111 * How often to simulate an mbuf allocation failure.
113 * bce_debug_dma_map_addr_failure:
114 * How often to simulate a DMA mapping failure.
116 * bce_debug_bootcode_running_failure:
117 * How often to simulate a bootcode failure.
119 static int bce_debug_l2fhdr_status_check = 0;
120 static int bce_debug_unexpected_attention = 0;
121 static int bce_debug_mbuf_allocation_failure = 0;
122 static int bce_debug_dma_map_addr_failure = 0;
123 static int bce_debug_bootcode_running_failure = 0;
125 #endif /* BCE_DEBUG */
128 /****************************************************************************/
129 /* PCI Device ID Table */
131 /* Used by bce_probe() to identify the devices supported by this driver. */
132 /****************************************************************************/
133 #define BCE_DEVDESC_MAX 64
135 static struct bce_type bce_devs[] = {
136 /* BCM5706C Controllers and OEM boards. */
137 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
138 "HP NC370T Multifunction Gigabit Server Adapter" },
139 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
140 "HP NC370i Multifunction Gigabit Server Adapter" },
141 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
142 "Broadcom NetXtreme II BCM5706 1000Base-T" },
144 /* BCM5706S controllers and OEM boards. */
145 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
146 "HP NC370F Multifunction Gigabit Server Adapter" },
147 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
148 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
150 /* BCM5708C controllers and OEM boards. */
151 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
152 "Broadcom NetXtreme II BCM5708 1000Base-T" },
154 /* BCM5708S controllers and OEM boards. */
155 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
156 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
161 /****************************************************************************/
162 /* Supported Flash NVRAM device data. */
163 /****************************************************************************/
164 static const struct flash_spec flash_table[] =
167 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
168 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
169 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
171 /* Expansion entry 0001 */
172 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
173 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
174 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
176 /* Saifun SA25F010 (non-buffered flash) */
177 /* strap, cfg1, & write1 need updates */
178 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
179 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
180 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
181 "Non-buffered flash (128kB)"},
182 /* Saifun SA25F020 (non-buffered flash) */
183 /* strap, cfg1, & write1 need updates */
184 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
185 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
186 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
187 "Non-buffered flash (256kB)"},
188 /* Expansion entry 0100 */
189 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
190 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
191 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
193 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
194 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
195 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
196 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
197 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
198 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
199 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
200 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
201 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
202 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
203 /* Saifun SA25F005 (non-buffered flash) */
204 /* strap, cfg1, & write1 need updates */
205 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
206 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
207 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
208 "Non-buffered flash (64kB)"},
210 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
211 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
212 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
214 /* Expansion entry 1001 */
215 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
216 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
217 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
219 /* Expansion entry 1010 */
220 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
221 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
222 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
224 /* ATMEL AT45DB011B (buffered flash) */
225 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
226 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
227 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
228 "Buffered flash (128kB)"},
229 /* Expansion entry 1100 */
230 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
231 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
232 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
234 /* Expansion entry 1101 */
235 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
236 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
237 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
239 /* Ateml Expansion entry 1110 */
240 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
241 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
242 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
243 "Entry 1110 (Atmel)"},
244 /* ATMEL AT45DB021B (buffered flash) */
245 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
246 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
247 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
248 "Buffered flash (256kB)"},
252 /****************************************************************************/
253 /* DragonFly device entry points. */
254 /****************************************************************************/
255 static int bce_probe(device_t);
256 static int bce_attach(device_t);
257 static int bce_detach(device_t);
258 static void bce_shutdown(device_t);
260 /****************************************************************************/
261 /* BCE Debug Data Structure Dump Routines */
262 /****************************************************************************/
264 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
265 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
266 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
267 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
268 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
269 static void bce_dump_l2fhdr(struct bce_softc *, int,
270 struct l2_fhdr *) __unused;
271 static void bce_dump_tx_chain(struct bce_softc *, int, int);
272 static void bce_dump_rx_chain(struct bce_softc *, int, int);
273 static void bce_dump_status_block(struct bce_softc *);
274 static void bce_dump_driver_state(struct bce_softc *);
275 static void bce_dump_stats_block(struct bce_softc *) __unused;
276 static void bce_dump_hw_state(struct bce_softc *);
277 static void bce_dump_txp_state(struct bce_softc *);
278 static void bce_dump_rxp_state(struct bce_softc *) __unused;
279 static void bce_dump_tpat_state(struct bce_softc *) __unused;
280 static void bce_freeze_controller(struct bce_softc *) __unused;
281 static void bce_unfreeze_controller(struct bce_softc *) __unused;
282 static void bce_breakpoint(struct bce_softc *);
283 #endif /* BCE_DEBUG */
286 /****************************************************************************/
287 /* BCE Register/Memory Access Routines */
288 /****************************************************************************/
289 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
290 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
291 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
292 static int bce_miibus_read_reg(device_t, int, int);
293 static int bce_miibus_write_reg(device_t, int, int, int);
294 static void bce_miibus_statchg(device_t);
297 /****************************************************************************/
298 /* BCE NVRAM Access Routines */
299 /****************************************************************************/
300 static int bce_acquire_nvram_lock(struct bce_softc *);
301 static int bce_release_nvram_lock(struct bce_softc *);
302 static void bce_enable_nvram_access(struct bce_softc *);
303 static void bce_disable_nvram_access(struct bce_softc *);
304 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
306 static int bce_init_nvram(struct bce_softc *);
307 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
308 static int bce_nvram_test(struct bce_softc *);
309 #ifdef BCE_NVRAM_WRITE_SUPPORT
310 static int bce_enable_nvram_write(struct bce_softc *);
311 static void bce_disable_nvram_write(struct bce_softc *);
312 static int bce_nvram_erase_page(struct bce_softc *, uint32_t);
313 static int bce_nvram_write_dword(struct bce_softc *, uint32_t, uint8_t *, uint32_t);
314 static int bce_nvram_write(struct bce_softc *, uint32_t, uint8_t *,
318 /****************************************************************************/
319 /* BCE DMA Allocate/Free Routines */
320 /****************************************************************************/
321 static int bce_dma_alloc(struct bce_softc *);
322 static void bce_dma_free(struct bce_softc *);
323 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
324 static void bce_dma_map_mbuf(void *, bus_dma_segment_t *, int,
327 /****************************************************************************/
328 /* BCE Firmware Synchronization and Load */
329 /****************************************************************************/
330 static int bce_fw_sync(struct bce_softc *, uint32_t);
331 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
333 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
335 static void bce_init_cpus(struct bce_softc *);
337 static void bce_stop(struct bce_softc *);
338 static int bce_reset(struct bce_softc *, uint32_t);
339 static int bce_chipinit(struct bce_softc *);
340 static int bce_blockinit(struct bce_softc *);
341 static int bce_newbuf_std(struct bce_softc *, struct mbuf *,
342 uint16_t *, uint16_t *, uint32_t *);
344 static int bce_init_tx_chain(struct bce_softc *);
345 static int bce_init_rx_chain(struct bce_softc *);
346 static void bce_free_rx_chain(struct bce_softc *);
347 static void bce_free_tx_chain(struct bce_softc *);
349 static int bce_encap(struct bce_softc *, struct mbuf **);
350 static void bce_start(struct ifnet *);
351 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
352 static void bce_watchdog(struct ifnet *);
353 static int bce_ifmedia_upd(struct ifnet *);
354 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
355 static void bce_init(void *);
356 static void bce_mgmt_init(struct bce_softc *);
358 static void bce_init_context(struct bce_softc *);
359 static void bce_get_mac_addr(struct bce_softc *);
360 static void bce_set_mac_addr(struct bce_softc *);
361 static void bce_phy_intr(struct bce_softc *);
362 static void bce_rx_intr(struct bce_softc *, int);
363 static void bce_tx_intr(struct bce_softc *);
364 static void bce_disable_intr(struct bce_softc *);
365 static void bce_enable_intr(struct bce_softc *);
367 #ifdef DEVICE_POLLING
368 static void bce_poll(struct ifnet *, enum poll_cmd, int);
370 static void bce_intr(void *);
371 static void bce_set_rx_mode(struct bce_softc *);
372 static void bce_stats_update(struct bce_softc *);
373 static void bce_tick(void *);
374 static void bce_tick_serialized(struct bce_softc *);
375 static void bce_add_sysctls(struct bce_softc *);
378 /****************************************************************************/
379 /* DragonFly device dispatch table. */
380 /****************************************************************************/
381 static device_method_t bce_methods[] = {
382 /* Device interface */
383 DEVMETHOD(device_probe, bce_probe),
384 DEVMETHOD(device_attach, bce_attach),
385 DEVMETHOD(device_detach, bce_detach),
386 DEVMETHOD(device_shutdown, bce_shutdown),
389 DEVMETHOD(bus_print_child, bus_generic_print_child),
390 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
393 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
394 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
395 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
400 static driver_t bce_driver = {
403 sizeof(struct bce_softc)
406 static devclass_t bce_devclass;
408 MODULE_DEPEND(bce, pci, 1, 1, 1);
409 MODULE_DEPEND(bce, ether, 1, 1, 1);
410 MODULE_DEPEND(bce, miibus, 1, 1, 1);
412 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
413 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
416 /****************************************************************************/
417 /* Device probe function. */
419 /* Compares the device to the driver's list of supported devices and */
420 /* reports back to the OS whether this is the right driver for the device. */
423 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
424 /****************************************************************************/
426 bce_probe(device_t dev)
429 uint16_t vid, did, svid, sdid;
431 /* Get the data for the device to be probed. */
432 vid = pci_get_vendor(dev);
433 did = pci_get_device(dev);
434 svid = pci_get_subvendor(dev);
435 sdid = pci_get_subdevice(dev);
437 /* Look through the list of known devices for a match. */
438 for (t = bce_devs; t->bce_name != NULL; ++t) {
439 if (vid == t->bce_vid && did == t->bce_did &&
440 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
441 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
442 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
445 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
447 /* Print out the device identity. */
448 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
450 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
452 device_set_desc_copy(dev, descbuf);
453 kfree(descbuf, M_TEMP);
461 /****************************************************************************/
462 /* Device attach function. */
464 /* Allocates device resources, performs secondary chip identification, */
465 /* resets and initializes the hardware, and initializes driver instance */
469 /* 0 on success, positive value on failure. */
470 /****************************************************************************/
472 bce_attach(device_t dev)
474 struct bce_softc *sc = device_get_softc(dev);
475 struct ifnet *ifp = &sc->arpcom.ac_if;
483 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
485 pci_enable_busmaster(dev);
487 /* Allocate PCI memory resources. */
489 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
490 RF_ACTIVE | PCI_RF_DENSE);
491 if (sc->bce_res_mem == NULL) {
492 device_printf(dev, "PCI memory allocation failed\n");
495 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
496 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
498 /* Allocate PCI IRQ resources. */
500 count = pci_msi_count(dev);
501 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
503 sc->bce_flags |= BCE_USING_MSI_FLAG;
507 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
508 RF_SHAREABLE | RF_ACTIVE);
509 if (sc->bce_res_irq == NULL) {
510 device_printf(dev, "PCI map interrupt failed\n");
516 * Configure byte swap and enable indirect register access.
517 * Rely on CPU to do target byte swapping on big endian systems.
518 * Access to registers outside of PCI configurtion space are not
519 * valid until this is done.
521 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
522 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
523 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
525 /* Save ASIC revsion info. */
526 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
528 /* Weed out any non-production controller revisions. */
529 switch(BCE_CHIP_ID(sc)) {
530 case BCE_CHIP_ID_5706_A0:
531 case BCE_CHIP_ID_5706_A1:
532 case BCE_CHIP_ID_5708_A0:
533 case BCE_CHIP_ID_5708_B0:
534 device_printf(dev, "Unsupported chip id 0x%08x!\n",
541 * The embedded PCIe to PCI-X bridge (EPB)
542 * in the 5708 cannot address memory above
543 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
545 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
546 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
548 sc->max_bus_addr = BUS_SPACE_MAXADDR;
551 * Find the base address for shared memory access.
552 * Newer versions of bootcode use a signature and offset
553 * while older versions use a fixed address.
555 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
556 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
557 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0);
559 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
561 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
563 /* Get PCI bus information (speed and type). */
564 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
565 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
568 sc->bce_flags |= BCE_PCIX_FLAG;
570 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
571 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
573 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
574 sc->bus_speed_mhz = 133;
577 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
578 sc->bus_speed_mhz = 100;
581 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
582 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
583 sc->bus_speed_mhz = 66;
586 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
587 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
588 sc->bus_speed_mhz = 50;
591 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
592 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
593 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
594 sc->bus_speed_mhz = 33;
598 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
599 sc->bus_speed_mhz = 66;
601 sc->bus_speed_mhz = 33;
604 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
605 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
607 device_printf(dev, "ASIC ID 0x%08X; Revision (%c%d); PCI%s %s %dMHz\n",
609 ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
610 (BCE_CHIP_ID(sc) & 0x0ff0) >> 4,
611 (sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : "",
612 (sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
613 "32-bit" : "64-bit", sc->bus_speed_mhz);
615 /* Reset the controller. */
616 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
620 /* Initialize the controller. */
621 rc = bce_chipinit(sc);
623 device_printf(dev, "Controller initialization failed!\n");
627 /* Perform NVRAM test. */
628 rc = bce_nvram_test(sc);
630 device_printf(dev, "NVRAM test failed!\n");
634 /* Fetch the permanent Ethernet MAC address. */
635 bce_get_mac_addr(sc);
638 * Trip points control how many BDs
639 * should be ready before generating an
640 * interrupt while ticks control how long
641 * a BD can sit in the chain before
642 * generating an interrupt. Set the default
643 * values for the RX and TX rings.
647 /* Force more frequent interrupts. */
648 sc->bce_tx_quick_cons_trip_int = 1;
649 sc->bce_tx_quick_cons_trip = 1;
650 sc->bce_tx_ticks_int = 0;
651 sc->bce_tx_ticks = 0;
653 sc->bce_rx_quick_cons_trip_int = 1;
654 sc->bce_rx_quick_cons_trip = 1;
655 sc->bce_rx_ticks_int = 0;
656 sc->bce_rx_ticks = 0;
658 sc->bce_tx_quick_cons_trip_int = 20;
659 sc->bce_tx_quick_cons_trip = 20;
660 sc->bce_tx_ticks_int = 80;
661 sc->bce_tx_ticks = 80;
663 sc->bce_rx_quick_cons_trip_int = 6;
664 sc->bce_rx_quick_cons_trip = 6;
665 sc->bce_rx_ticks_int = 18;
666 sc->bce_rx_ticks = 18;
669 /* Update statistics once every second. */
670 sc->bce_stats_ticks = 1000000 & 0xffff00;
673 * The copper based NetXtreme II controllers
674 * use an integrated PHY at address 1 while
675 * the SerDes controllers use a PHY at
678 sc->bce_phy_addr = 1;
680 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
681 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
682 sc->bce_flags |= BCE_NO_WOL_FLAG;
683 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708) {
684 sc->bce_phy_addr = 2;
685 val = REG_RD_IND(sc, sc->bce_shmem_base +
686 BCE_SHARED_HW_CFG_CONFIG);
687 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
688 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
692 /* Allocate DMA memory resources. */
693 rc = bce_dma_alloc(sc);
695 device_printf(dev, "DMA resource allocation failed!\n");
699 /* Initialize the ifnet interface. */
701 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
702 ifp->if_ioctl = bce_ioctl;
703 ifp->if_start = bce_start;
704 ifp->if_init = bce_init;
705 ifp->if_watchdog = bce_watchdog;
706 #ifdef DEVICE_POLLING
707 ifp->if_poll = bce_poll;
709 ifp->if_mtu = ETHERMTU;
710 ifp->if_hwassist = BCE_IF_HWASSIST;
711 ifp->if_capabilities = BCE_IF_CAPABILITIES;
712 ifp->if_capenable = ifp->if_capabilities;
713 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
714 ifq_set_ready(&ifp->if_snd);
716 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
717 ifp->if_baudrate = IF_Gbps(2.5);
719 ifp->if_baudrate = IF_Gbps(1);
721 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
722 sc->mbuf_alloc_size = MCLBYTES;
724 /* Look for our PHY. */
725 rc = mii_phy_probe(dev, &sc->bce_miibus,
726 bce_ifmedia_upd, bce_ifmedia_sts);
728 device_printf(dev, "PHY probe failed!\n");
732 /* Attach to the Ethernet interface list. */
733 ether_ifattach(ifp, sc->eaddr, NULL);
735 callout_init(&sc->bce_stat_ch);
737 /* Hookup IRQ last. */
738 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_NETSAFE, bce_intr, sc,
739 &sc->bce_intrhand, ifp->if_serializer);
741 device_printf(dev, "Failed to setup IRQ!\n");
746 /* Print some important debugging info. */
747 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
749 /* Add the supported sysctls to the kernel. */
752 /* Get the firmware running so IPMI still works */
762 /****************************************************************************/
763 /* Device detach function. */
765 /* Stops the controller, resets the controller, and releases resources. */
768 /* 0 on success, positive value on failure. */
769 /****************************************************************************/
771 bce_detach(device_t dev)
773 struct bce_softc *sc = device_get_softc(dev);
775 if (device_is_attached(dev)) {
776 struct ifnet *ifp = &sc->arpcom.ac_if;
778 /* Stop and reset the controller. */
779 lwkt_serialize_enter(ifp->if_serializer);
781 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
782 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
783 lwkt_serialize_exit(ifp->if_serializer);
788 /* If we have a child device on the MII bus remove it too. */
790 device_delete_child(dev, sc->bce_miibus);
791 bus_generic_detach(dev);
793 if (sc->bce_res_irq != NULL) {
794 bus_release_resource(dev, SYS_RES_IRQ,
795 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
800 if (sc->bce_flags & BCE_USING_MSI_FLAG)
801 pci_release_msi(dev);
804 if (sc->bce_res_mem != NULL) {
805 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
811 if (sc->bce_sysctl_tree != NULL)
812 sysctl_ctx_free(&sc->bce_sysctl_ctx);
818 /****************************************************************************/
819 /* Device shutdown function. */
821 /* Stops and resets the controller. */
825 /****************************************************************************/
827 bce_shutdown(device_t dev)
829 struct bce_softc *sc = device_get_softc(dev);
830 struct ifnet *ifp = &sc->arpcom.ac_if;
832 lwkt_serialize_enter(ifp->if_serializer);
834 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
835 lwkt_serialize_exit(ifp->if_serializer);
839 /****************************************************************************/
840 /* Indirect register read. */
842 /* Reads NetXtreme II registers using an index/data register pair in PCI */
843 /* configuration space. Using this mechanism avoids issues with posted */
844 /* reads but is much slower than memory-mapped I/O. */
847 /* The value of the register. */
848 /****************************************************************************/
850 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
852 device_t dev = sc->bce_dev;
854 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
858 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
859 DBPRINT(sc, BCE_EXCESSIVE,
860 "%s(); offset = 0x%08X, val = 0x%08X\n",
861 __func__, offset, val);
865 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
870 /****************************************************************************/
871 /* Indirect register write. */
873 /* Writes NetXtreme II registers using an index/data register pair in PCI */
874 /* configuration space. Using this mechanism avoids issues with posted */
875 /* writes but is muchh slower than memory-mapped I/O. */
879 /****************************************************************************/
881 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
883 device_t dev = sc->bce_dev;
885 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
886 __func__, offset, val);
888 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
889 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
893 /****************************************************************************/
894 /* Context memory write. */
896 /* The NetXtreme II controller uses context memory to track connection */
897 /* information for L2 and higher network protocols. */
901 /****************************************************************************/
903 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t offset,
906 DBPRINT(sc, BCE_EXCESSIVE, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
907 "val = 0x%08X\n", __func__, cid_addr, offset, val);
910 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
911 REG_WR(sc, BCE_CTX_DATA, val);
915 /****************************************************************************/
916 /* PHY register read. */
918 /* Implements register reads on the MII bus. */
921 /* The value of the register. */
922 /****************************************************************************/
924 bce_miibus_read_reg(device_t dev, int phy, int reg)
926 struct bce_softc *sc = device_get_softc(dev);
930 /* Make sure we are accessing the correct PHY address. */
931 if (phy != sc->bce_phy_addr) {
932 DBPRINT(sc, BCE_VERBOSE,
933 "Invalid PHY address %d for PHY read!\n", phy);
937 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
938 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
939 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
941 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
942 REG_RD(sc, BCE_EMAC_MDIO_MODE);
947 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
948 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
949 BCE_EMAC_MDIO_COMM_START_BUSY;
950 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
952 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
955 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
956 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
959 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
960 val &= BCE_EMAC_MDIO_COMM_DATA;
965 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
966 if_printf(&sc->arpcom.ac_if,
967 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
971 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
974 DBPRINT(sc, BCE_EXCESSIVE,
975 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
976 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
978 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
979 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
980 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
982 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
983 REG_RD(sc, BCE_EMAC_MDIO_MODE);
987 return (val & 0xffff);
991 /****************************************************************************/
992 /* PHY register write. */
994 /* Implements register writes on the MII bus. */
997 /* The value of the register. */
998 /****************************************************************************/
1000 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1002 struct bce_softc *sc = device_get_softc(dev);
1006 /* Make sure we are accessing the correct PHY address. */
1007 if (phy != sc->bce_phy_addr) {
1008 DBPRINT(sc, BCE_WARN,
1009 "Invalid PHY address %d for PHY write!\n", phy);
1013 DBPRINT(sc, BCE_EXCESSIVE,
1014 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1015 __func__, phy, (uint16_t)(reg & 0xffff),
1016 (uint16_t)(val & 0xffff));
1018 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1019 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1020 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1022 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1023 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1028 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1029 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1030 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1031 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1033 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1036 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1037 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1043 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1044 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1046 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1047 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1048 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1050 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1051 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1059 /****************************************************************************/
1060 /* MII bus status change. */
1062 /* Called by the MII bus driver when the PHY establishes link to set the */
1063 /* MAC interface registers. */
1067 /****************************************************************************/
1069 bce_miibus_statchg(device_t dev)
1071 struct bce_softc *sc = device_get_softc(dev);
1072 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1074 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1075 mii->mii_media_active);
1078 /* Decode the interface media flags. */
1079 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1080 switch(IFM_TYPE(mii->mii_media_active)) {
1082 kprintf("Ethernet )");
1085 kprintf("Unknown )");
1089 kprintf(" Media Options: ( ");
1090 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1092 kprintf("Autoselect )");
1095 kprintf("Manual )");
1101 kprintf("10Base-T )");
1104 kprintf("100Base-TX )");
1107 kprintf("1000Base-SX )");
1110 kprintf("1000Base-T )");
1117 kprintf(" Global Options: (");
1118 if (mii->mii_media_active & IFM_FDX)
1119 kprintf(" FullDuplex");
1120 if (mii->mii_media_active & IFM_HDX)
1121 kprintf(" HalfDuplex");
1122 if (mii->mii_media_active & IFM_LOOP)
1123 kprintf(" Loopback");
1124 if (mii->mii_media_active & IFM_FLAG0)
1126 if (mii->mii_media_active & IFM_FLAG1)
1128 if (mii->mii_media_active & IFM_FLAG2)
1133 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1136 * Set MII or GMII interface based on the speed negotiated
1139 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1140 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1141 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1142 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1144 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1145 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1149 * Set half or full duplex based on the duplicity negotiated
1152 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1153 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1154 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1156 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1157 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1162 /****************************************************************************/
1163 /* Acquire NVRAM lock. */
1165 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1166 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1167 /* for use by the driver. */
1170 /* 0 on success, positive value on failure. */
1171 /****************************************************************************/
1173 bce_acquire_nvram_lock(struct bce_softc *sc)
1178 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1180 /* Request access to the flash interface. */
1181 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1182 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1183 val = REG_RD(sc, BCE_NVM_SW_ARB);
1184 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1190 if (j >= NVRAM_TIMEOUT_COUNT) {
1191 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1198 /****************************************************************************/
1199 /* Release NVRAM lock. */
1201 /* When the caller is finished accessing NVRAM the lock must be released. */
1202 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1203 /* for use by the driver. */
1206 /* 0 on success, positive value on failure. */
1207 /****************************************************************************/
1209 bce_release_nvram_lock(struct bce_softc *sc)
1214 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1217 * Relinquish nvram interface.
1219 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1221 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1222 val = REG_RD(sc, BCE_NVM_SW_ARB);
1223 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1229 if (j >= NVRAM_TIMEOUT_COUNT) {
1230 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1237 #ifdef BCE_NVRAM_WRITE_SUPPORT
1238 /****************************************************************************/
1239 /* Enable NVRAM write access. */
1241 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1244 /* 0 on success, positive value on failure. */
1245 /****************************************************************************/
1247 bce_enable_nvram_write(struct bce_softc *sc)
1251 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM write.\n");
1253 val = REG_RD(sc, BCE_MISC_CFG);
1254 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1256 if (!sc->bce_flash_info->buffered) {
1259 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1260 REG_WR(sc, BCE_NVM_COMMAND,
1261 BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1263 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1266 val = REG_RD(sc, BCE_NVM_COMMAND);
1267 if (val & BCE_NVM_COMMAND_DONE)
1271 if (j >= NVRAM_TIMEOUT_COUNT) {
1272 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1280 /****************************************************************************/
1281 /* Disable NVRAM write access. */
1283 /* When the caller is finished writing to NVRAM write access must be */
1288 /****************************************************************************/
1290 bce_disable_nvram_write(struct bce_softc *sc)
1294 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM write.\n");
1296 val = REG_RD(sc, BCE_MISC_CFG);
1297 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1299 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1302 /****************************************************************************/
1303 /* Enable NVRAM access. */
1305 /* Before accessing NVRAM for read or write operations the caller must */
1306 /* enabled NVRAM access. */
1310 /****************************************************************************/
1312 bce_enable_nvram_access(struct bce_softc *sc)
1316 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1318 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1319 /* Enable both bits, even on read. */
1320 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1321 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1325 /****************************************************************************/
1326 /* Disable NVRAM access. */
1328 /* When the caller is finished accessing NVRAM access must be disabled. */
1332 /****************************************************************************/
1334 bce_disable_nvram_access(struct bce_softc *sc)
1338 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1340 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1342 /* Disable both bits, even after read. */
1343 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1344 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1348 #ifdef BCE_NVRAM_WRITE_SUPPORT
1349 /****************************************************************************/
1350 /* Erase NVRAM page before writing. */
1352 /* Non-buffered flash parts require that a page be erased before it is */
1356 /* 0 on success, positive value on failure. */
1357 /****************************************************************************/
1359 bce_nvram_erase_page(struct bce_softc *sc, uint32_t offset)
1364 /* Buffered flash doesn't require an erase. */
1365 if (sc->bce_flash_info->buffered)
1368 DBPRINT(sc, BCE_VERBOSE, "Erasing NVRAM page.\n");
1370 /* Build an erase command. */
1371 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
1372 BCE_NVM_COMMAND_DOIT;
1375 * Clear the DONE bit separately, set the NVRAM adress to erase,
1376 * and issue the erase command.
1378 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1379 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1380 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1382 /* Wait for completion. */
1383 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1388 val = REG_RD(sc, BCE_NVM_COMMAND);
1389 if (val & BCE_NVM_COMMAND_DONE)
1393 if (j >= NVRAM_TIMEOUT_COUNT) {
1394 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
1399 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1402 /****************************************************************************/
1403 /* Read a dword (32 bits) from NVRAM. */
1405 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1406 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1409 /* 0 on success and the 32 bit value read, positive value on failure. */
1410 /****************************************************************************/
1412 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1418 /* Build the command word. */
1419 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1421 /* Calculate the offset for buffered flash. */
1422 if (sc->bce_flash_info->buffered) {
1423 offset = ((offset / sc->bce_flash_info->page_size) <<
1424 sc->bce_flash_info->page_bits) +
1425 (offset % sc->bce_flash_info->page_size);
1429 * Clear the DONE bit separately, set the address to read,
1430 * and issue the read.
1432 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1433 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1434 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1436 /* Wait for completion. */
1437 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1442 val = REG_RD(sc, BCE_NVM_COMMAND);
1443 if (val & BCE_NVM_COMMAND_DONE) {
1444 val = REG_RD(sc, BCE_NVM_READ);
1447 memcpy(ret_val, &val, 4);
1452 /* Check for errors. */
1453 if (i >= NVRAM_TIMEOUT_COUNT) {
1454 if_printf(&sc->arpcom.ac_if,
1455 "Timeout error reading NVRAM at offset 0x%08X!\n",
1463 #ifdef BCE_NVRAM_WRITE_SUPPORT
1464 /****************************************************************************/
1465 /* Write a dword (32 bits) to NVRAM. */
1467 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
1468 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
1469 /* enabled NVRAM write access. */
1472 /* 0 on success, positive value on failure. */
1473 /****************************************************************************/
1475 bce_nvram_write_dword(struct bce_softc *sc, uint32_t offset, uint8_t *val,
1478 uint32_t cmd, val32;
1481 /* Build the command word. */
1482 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
1484 /* Calculate the offset for buffered flash. */
1485 if (sc->bce_flash_info->buffered) {
1486 offset = ((offset / sc->bce_flash_info->page_size) <<
1487 sc->bce_flash_info->page_bits) +
1488 (offset % sc->bce_flash_info->page_size);
1492 * Clear the DONE bit separately, convert NVRAM data to big-endian,
1493 * set the NVRAM address to write, and issue the write command
1495 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1496 memcpy(&val32, val, 4);
1497 val32 = htobe32(val32);
1498 REG_WR(sc, BCE_NVM_WRITE, val32);
1499 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1500 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1502 /* Wait for completion. */
1503 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1506 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
1509 if (j >= NVRAM_TIMEOUT_COUNT) {
1510 if_printf(&sc->arpcom.ac_if,
1511 "Timeout error writing NVRAM at offset 0x%08X\n",
1517 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1520 /****************************************************************************/
1521 /* Initialize NVRAM access. */
1523 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1524 /* access that device. */
1527 /* 0 on success, positive value on failure. */
1528 /****************************************************************************/
1530 bce_init_nvram(struct bce_softc *sc)
1533 int j, entry_count, rc = 0;
1534 const struct flash_spec *flash;
1536 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1538 /* Determine the selected interface. */
1539 val = REG_RD(sc, BCE_NVM_CFG1);
1541 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1544 * Flash reconfiguration is required to support additional
1545 * NVRAM devices not directly supported in hardware.
1546 * Check if the flash interface was reconfigured
1550 if (val & 0x40000000) {
1551 /* Flash interface reconfigured by bootcode. */
1553 DBPRINT(sc, BCE_INFO_LOAD,
1554 "%s(): Flash WAS reconfigured.\n", __func__);
1556 for (j = 0, flash = flash_table; j < entry_count;
1558 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1559 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1560 sc->bce_flash_info = flash;
1565 /* Flash interface not yet reconfigured. */
1568 DBPRINT(sc, BCE_INFO_LOAD,
1569 "%s(): Flash was NOT reconfigured.\n", __func__);
1571 if (val & (1 << 23))
1572 mask = FLASH_BACKUP_STRAP_MASK;
1574 mask = FLASH_STRAP_MASK;
1576 /* Look for the matching NVRAM device configuration data. */
1577 for (j = 0, flash = flash_table; j < entry_count;
1579 /* Check if the device matches any of the known devices. */
1580 if ((val & mask) == (flash->strapping & mask)) {
1581 /* Found a device match. */
1582 sc->bce_flash_info = flash;
1584 /* Request access to the flash interface. */
1585 rc = bce_acquire_nvram_lock(sc);
1589 /* Reconfigure the flash interface. */
1590 bce_enable_nvram_access(sc);
1591 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1592 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1593 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1594 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1595 bce_disable_nvram_access(sc);
1596 bce_release_nvram_lock(sc);
1602 /* Check if a matching device was found. */
1603 if (j == entry_count) {
1604 sc->bce_flash_info = NULL;
1605 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1609 /* Write the flash config data to the shared memory interface. */
1610 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_SHARED_HW_CFG_CONFIG2) &
1611 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1613 sc->bce_flash_size = val;
1615 sc->bce_flash_size = sc->bce_flash_info->total_size;
1617 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1618 __func__, sc->bce_flash_info->total_size);
1620 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1626 /****************************************************************************/
1627 /* Read an arbitrary range of data from NVRAM. */
1629 /* Prepares the NVRAM interface for access and reads the requested data */
1630 /* into the supplied buffer. */
1633 /* 0 on success and the data read, positive value on failure. */
1634 /****************************************************************************/
1636 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1639 uint32_t cmd_flags, offset32, len32, extra;
1645 /* Request access to the flash interface. */
1646 rc = bce_acquire_nvram_lock(sc);
1650 /* Enable access to flash interface */
1651 bce_enable_nvram_access(sc);
1659 /* XXX should we release nvram lock if read_dword() fails? */
1665 pre_len = 4 - (offset & 3);
1667 if (pre_len >= len32) {
1669 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1671 cmd_flags = BCE_NVM_COMMAND_FIRST;
1674 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1678 memcpy(ret_buf, buf + (offset & 3), pre_len);
1686 extra = 4 - (len32 & 3);
1687 len32 = (len32 + 4) & ~3;
1694 cmd_flags = BCE_NVM_COMMAND_LAST;
1696 cmd_flags = BCE_NVM_COMMAND_FIRST |
1697 BCE_NVM_COMMAND_LAST;
1699 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1701 memcpy(ret_buf, buf, 4 - extra);
1702 } else if (len32 > 0) {
1705 /* Read the first word. */
1709 cmd_flags = BCE_NVM_COMMAND_FIRST;
1711 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1713 /* Advance to the next dword. */
1718 while (len32 > 4 && rc == 0) {
1719 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1721 /* Advance to the next dword. */
1730 cmd_flags = BCE_NVM_COMMAND_LAST;
1731 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1733 memcpy(ret_buf, buf, 4 - extra);
1736 /* Disable access to flash interface and release the lock. */
1737 bce_disable_nvram_access(sc);
1738 bce_release_nvram_lock(sc);
1744 #ifdef BCE_NVRAM_WRITE_SUPPORT
1745 /****************************************************************************/
1746 /* Write an arbitrary range of data from NVRAM. */
1748 /* Prepares the NVRAM interface for write access and writes the requested */
1749 /* data from the supplied buffer. The caller is responsible for */
1750 /* calculating any appropriate CRCs. */
1753 /* 0 on success, positive value on failure. */
1754 /****************************************************************************/
1756 bce_nvram_write(struct bce_softc *sc, uint32_t offset, uint8_t *data_buf,
1759 uint32_t written, offset32, len32;
1760 uint8_t *buf, start[4], end[4];
1762 int align_start, align_end;
1768 align_start = (offset32 & 3);
1772 len32 += align_start;
1773 rc = bce_nvram_read(sc, offset32, start, 4);
1779 if (len32 > 4 || !align_start) {
1780 align_end = 4 - (len32 & 3);
1782 rc = bce_nvram_read(sc, offset32 + len32 - 4, end, 4);
1788 if (align_start || align_end) {
1789 buf = kmalloc(len32, M_DEVBUF, M_NOWAIT);
1793 memcpy(buf, start, 4);
1795 memcpy(buf + len32 - 4, end, 4);
1796 memcpy(buf + align_start, data_buf, buf_size);
1800 while (written < len32 && rc == 0) {
1801 uint32_t page_start, page_end, data_start, data_end;
1802 uint32_t addr, cmd_flags;
1804 uint8_t flash_buffer[264];
1806 /* Find the page_start addr */
1807 page_start = offset32 + written;
1808 page_start -= (page_start % sc->bce_flash_info->page_size);
1809 /* Find the page_end addr */
1810 page_end = page_start + sc->bce_flash_info->page_size;
1811 /* Find the data_start addr */
1812 data_start = (written == 0) ? offset32 : page_start;
1813 /* Find the data_end addr */
1814 data_end = (page_end > offset32 + len32) ? (offset32 + len32)
1817 /* Request access to the flash interface. */
1818 rc = bce_acquire_nvram_lock(sc);
1820 goto nvram_write_end;
1822 /* Enable access to flash interface */
1823 bce_enable_nvram_access(sc);
1825 cmd_flags = BCE_NVM_COMMAND_FIRST;
1826 if (sc->bce_flash_info->buffered == 0) {
1830 * Read the whole page into the buffer
1831 * (non-buffer flash only)
1833 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
1834 if (j == (sc->bce_flash_info->page_size - 4))
1835 cmd_flags |= BCE_NVM_COMMAND_LAST;
1837 rc = bce_nvram_read_dword(sc, page_start + j,
1841 goto nvram_write_end;
1847 /* Enable writes to flash interface (unlock write-protect) */
1848 rc = bce_enable_nvram_write(sc);
1850 goto nvram_write_end;
1852 /* Erase the page */
1853 rc = bce_nvram_erase_page(sc, page_start);
1855 goto nvram_write_end;
1857 /* Re-enable the write again for the actual write */
1858 bce_enable_nvram_write(sc);
1860 /* Loop to write back the buffer data from page_start to
1863 if (sc->bce_flash_info->buffered == 0) {
1864 for (addr = page_start; addr < data_start;
1865 addr += 4, i += 4) {
1866 rc = bce_nvram_write_dword(sc, addr,
1870 goto nvram_write_end;
1876 /* Loop to write the new data from data_start to data_end */
1877 for (addr = data_start; addr < data_end; addr += 4, i++) {
1878 if (addr == page_end - 4 ||
1879 (sc->bce_flash_info->buffered &&
1880 addr == data_end - 4))
1881 cmd_flags |= BCE_NVM_COMMAND_LAST;
1883 rc = bce_nvram_write_dword(sc, addr, buf, cmd_flags);
1885 goto nvram_write_end;
1891 /* Loop to write back the buffer data from data_end
1893 if (sc->bce_flash_info->buffered == 0) {
1894 for (addr = data_end; addr < page_end;
1895 addr += 4, i += 4) {
1896 if (addr == page_end-4)
1897 cmd_flags = BCE_NVM_COMMAND_LAST;
1899 rc = bce_nvram_write_dword(sc, addr,
1900 &flash_buffer[i], cmd_flags);
1902 goto nvram_write_end;
1908 /* Disable writes to flash interface (lock write-protect) */
1909 bce_disable_nvram_write(sc);
1911 /* Disable access to flash interface */
1912 bce_disable_nvram_access(sc);
1913 bce_release_nvram_lock(sc);
1915 /* Increment written */
1916 written += data_end - data_start;
1920 if (align_start || align_end)
1921 kfree(buf, M_DEVBUF);
1924 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1927 /****************************************************************************/
1928 /* Verifies that NVRAM is accessible and contains valid data. */
1930 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1934 /* 0 on success, positive value on failure. */
1935 /****************************************************************************/
1937 bce_nvram_test(struct bce_softc *sc)
1939 uint32_t buf[BCE_NVRAM_SIZE / 4];
1940 uint32_t magic, csum;
1941 uint8_t *data = (uint8_t *)buf;
1945 * Check that the device NVRAM is valid by reading
1946 * the magic value at offset 0.
1948 rc = bce_nvram_read(sc, 0, data, 4);
1952 magic = be32toh(buf[0]);
1953 if (magic != BCE_NVRAM_MAGIC) {
1954 if_printf(&sc->arpcom.ac_if,
1955 "Invalid NVRAM magic value! Expected: 0x%08X, "
1956 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1961 * Verify that the device NVRAM includes valid
1962 * configuration data.
1964 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1968 csum = ether_crc32_le(data, 0x100);
1969 if (csum != BCE_CRC32_RESIDUAL) {
1970 if_printf(&sc->arpcom.ac_if,
1971 "Invalid Manufacturing Information NVRAM CRC! "
1972 "Expected: 0x%08X, Found: 0x%08X\n",
1973 BCE_CRC32_RESIDUAL, csum);
1977 csum = ether_crc32_le(data + 0x100, 0x100);
1978 if (csum != BCE_CRC32_RESIDUAL) {
1979 if_printf(&sc->arpcom.ac_if,
1980 "Invalid Feature Configuration Information "
1981 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1982 BCE_CRC32_RESIDUAL, csum);
1989 /****************************************************************************/
1990 /* Free any DMA memory owned by the driver. */
1992 /* Scans through each data structre that requires DMA memory and frees */
1993 /* the memory if allocated. */
1997 /****************************************************************************/
1999 bce_dma_free(struct bce_softc *sc)
2003 /* Destroy the status block. */
2004 if (sc->status_tag != NULL) {
2005 if (sc->status_block != NULL) {
2006 bus_dmamap_unload(sc->status_tag, sc->status_map);
2007 bus_dmamem_free(sc->status_tag, sc->status_block,
2010 bus_dma_tag_destroy(sc->status_tag);
2014 /* Destroy the statistics block. */
2015 if (sc->stats_tag != NULL) {
2016 if (sc->stats_block != NULL) {
2017 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2018 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2021 bus_dma_tag_destroy(sc->stats_tag);
2024 /* Destroy the TX buffer descriptor DMA stuffs. */
2025 if (sc->tx_bd_chain_tag != NULL) {
2026 for (i = 0; i < TX_PAGES; i++) {
2027 if (sc->tx_bd_chain[i] != NULL) {
2028 bus_dmamap_unload(sc->tx_bd_chain_tag,
2029 sc->tx_bd_chain_map[i]);
2030 bus_dmamem_free(sc->tx_bd_chain_tag,
2032 sc->tx_bd_chain_map[i]);
2035 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2038 /* Destroy the RX buffer descriptor DMA stuffs. */
2039 if (sc->rx_bd_chain_tag != NULL) {
2040 for (i = 0; i < RX_PAGES; i++) {
2041 if (sc->rx_bd_chain[i] != NULL) {
2042 bus_dmamap_unload(sc->rx_bd_chain_tag,
2043 sc->rx_bd_chain_map[i]);
2044 bus_dmamem_free(sc->rx_bd_chain_tag,
2046 sc->rx_bd_chain_map[i]);
2049 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2052 /* Destroy the TX mbuf DMA stuffs. */
2053 if (sc->tx_mbuf_tag != NULL) {
2054 for (i = 0; i < TOTAL_TX_BD; i++) {
2055 /* Must have been unloaded in bce_stop() */
2056 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2057 bus_dmamap_destroy(sc->tx_mbuf_tag,
2058 sc->tx_mbuf_map[i]);
2060 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2063 /* Destroy the RX mbuf DMA stuffs. */
2064 if (sc->rx_mbuf_tag != NULL) {
2065 for (i = 0; i < TOTAL_RX_BD; i++) {
2066 /* Must have been unloaded in bce_stop() */
2067 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2068 bus_dmamap_destroy(sc->rx_mbuf_tag,
2069 sc->rx_mbuf_map[i]);
2071 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2074 /* Destroy the parent tag */
2075 if (sc->parent_tag != NULL)
2076 bus_dma_tag_destroy(sc->parent_tag);
2080 /****************************************************************************/
2081 /* Get DMA memory from the OS. */
2083 /* Validates that the OS has provided DMA buffers in response to a */
2084 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2085 /* When the callback is used the OS will return 0 for the mapping function */
2086 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2087 /* failures back to the caller. */
2091 /****************************************************************************/
2093 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2095 bus_addr_t *busaddr = arg;
2098 * Simulate a mapping failure.
2101 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2102 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2103 __FILE__, __LINE__);
2106 /* Check for an error and signal the caller that an error occurred. */
2110 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2111 *busaddr = segs->ds_addr;
2116 bce_dma_map_mbuf(void *arg, bus_dma_segment_t *segs, int nsegs,
2117 bus_size_t mapsz __unused, int error)
2119 struct bce_dmamap_arg *ctx = arg;
2125 if (nsegs > ctx->bce_maxsegs) {
2126 ctx->bce_maxsegs = 0;
2130 ctx->bce_maxsegs = nsegs;
2131 for (i = 0; i < nsegs; ++i)
2132 ctx->bce_segs[i] = segs[i];
2136 /****************************************************************************/
2137 /* Allocate any DMA memory needed by the driver. */
2139 /* Allocates DMA memory needed for the various global structures needed by */
2143 /* 0 for success, positive value for failure. */
2144 /****************************************************************************/
2146 bce_dma_alloc(struct bce_softc *sc)
2148 struct ifnet *ifp = &sc->arpcom.ac_if;
2153 * Allocate the parent bus DMA tag appropriate for PCI.
2155 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2156 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2158 MAXBSIZE, BUS_SPACE_UNRESTRICTED,
2159 BUS_SPACE_MAXSIZE_32BIT,
2160 0, &sc->parent_tag);
2162 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2167 * Create a DMA tag for the status block, allocate and clear the
2168 * memory, map the memory into DMA space, and fetch the physical
2169 * address of the block.
2171 rc = bus_dma_tag_create(sc->parent_tag,
2172 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2173 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2175 BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
2176 0, &sc->status_tag);
2178 if_printf(ifp, "Could not allocate status block DMA tag!\n");
2182 rc = bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
2183 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2186 if_printf(ifp, "Could not allocate status block DMA memory!\n");
2190 rc = bus_dmamap_load(sc->status_tag, sc->status_map,
2191 sc->status_block, BCE_STATUS_BLK_SZ,
2192 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2194 if_printf(ifp, "Could not map status block DMA memory!\n");
2195 bus_dmamem_free(sc->status_tag, sc->status_block,
2197 sc->status_block = NULL;
2201 sc->status_block_paddr = busaddr;
2202 /* DRC - Fix for 64 bit addresses. */
2203 DBPRINT(sc, BCE_INFO, "status_block_paddr = 0x%08X\n",
2204 (uint32_t)sc->status_block_paddr);
2207 * Create a DMA tag for the statistics block, allocate and clear the
2208 * memory, map the memory into DMA space, and fetch the physical
2209 * address of the block.
2211 rc = bus_dma_tag_create(sc->parent_tag,
2212 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2213 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2215 BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
2218 if_printf(ifp, "Could not allocate "
2219 "statistics block DMA tag!\n");
2223 rc = bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
2224 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2227 if_printf(ifp, "Could not allocate "
2228 "statistics block DMA memory!\n");
2232 rc = bus_dmamap_load(sc->stats_tag, sc->stats_map,
2233 sc->stats_block, BCE_STATS_BLK_SZ,
2234 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2236 if_printf(ifp, "Could not map statistics block DMA memory!\n");
2237 bus_dmamem_free(sc->stats_tag, sc->stats_block, sc->stats_map);
2238 sc->stats_block = NULL;
2242 sc->stats_block_paddr = busaddr;
2243 /* DRC - Fix for 64 bit address. */
2244 DBPRINT(sc, BCE_INFO, "stats_block_paddr = 0x%08X\n",
2245 (uint32_t)sc->stats_block_paddr);
2248 * Create a DMA tag for the TX buffer descriptor chain,
2249 * allocate and clear the memory, and fetch the
2250 * physical address of the block.
2252 rc = bus_dma_tag_create(sc->parent_tag,
2253 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2254 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2256 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2257 0, &sc->tx_bd_chain_tag);
2259 if_printf(ifp, "Could not allocate "
2260 "TX descriptor chain DMA tag!\n");
2264 for (i = 0; i < TX_PAGES; i++) {
2265 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2266 (void **)&sc->tx_bd_chain[i],
2267 BUS_DMA_WAITOK, &sc->tx_bd_chain_map[i]);
2269 if_printf(ifp, "Could not allocate %dth TX descriptor "
2270 "chain DMA memory!\n", i);
2274 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2275 sc->tx_bd_chain_map[i],
2276 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2277 bce_dma_map_addr, &busaddr,
2280 if_printf(ifp, "Could not map %dth TX descriptor "
2281 "chain DMA memory!\n", i);
2282 bus_dmamem_free(sc->tx_bd_chain_tag,
2284 sc->tx_bd_chain_map[i]);
2285 sc->tx_bd_chain[i] = NULL;
2289 sc->tx_bd_chain_paddr[i] = busaddr;
2290 /* DRC - Fix for 64 bit systems. */
2291 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2292 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2295 /* Create a DMA tag for TX mbufs. */
2296 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2297 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2299 MCLBYTES * BCE_MAX_SEGMENTS,
2300 BCE_MAX_SEGMENTS, MCLBYTES,
2301 0, &sc->tx_mbuf_tag);
2303 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2307 /* Create DMA maps for the TX mbufs clusters. */
2308 for (i = 0; i < TOTAL_TX_BD; i++) {
2309 rc = bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_WAITOK,
2310 &sc->tx_mbuf_map[i]);
2312 for (j = 0; j < i; ++j) {
2313 bus_dmamap_destroy(sc->tx_mbuf_tag,
2314 sc->tx_mbuf_map[i]);
2316 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2317 sc->tx_mbuf_tag = NULL;
2319 if_printf(ifp, "Unable to create "
2320 "%dth TX mbuf DMA map!\n", i);
2326 * Create a DMA tag for the RX buffer descriptor chain,
2327 * allocate and clear the memory, and fetch the physical
2328 * address of the blocks.
2330 rc = bus_dma_tag_create(sc->parent_tag,
2331 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2332 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2334 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2335 0, &sc->rx_bd_chain_tag);
2337 if_printf(ifp, "Could not allocate "
2338 "RX descriptor chain DMA tag!\n");
2342 for (i = 0; i < RX_PAGES; i++) {
2343 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2344 (void **)&sc->rx_bd_chain[i],
2345 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2346 &sc->rx_bd_chain_map[i]);
2348 if_printf(ifp, "Could not allocate %dth RX descriptor "
2349 "chain DMA memory!\n", i);
2353 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2354 sc->rx_bd_chain_map[i],
2355 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2356 bce_dma_map_addr, &busaddr,
2359 if_printf(ifp, "Could not map %dth RX descriptor "
2360 "chain DMA memory!\n", i);
2361 bus_dmamem_free(sc->rx_bd_chain_tag,
2363 sc->rx_bd_chain_map[i]);
2364 sc->rx_bd_chain[i] = NULL;
2368 sc->rx_bd_chain_paddr[i] = busaddr;
2369 /* DRC - Fix for 64 bit systems. */
2370 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2371 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2374 /* Create a DMA tag for RX mbufs. */
2375 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2376 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2378 MCLBYTES, 1/* BCE_MAX_SEGMENTS */, MCLBYTES,
2379 0, &sc->rx_mbuf_tag);
2381 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2385 /* Create DMA maps for the RX mbuf clusters. */
2386 for (i = 0; i < TOTAL_RX_BD; i++) {
2387 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2388 &sc->rx_mbuf_map[i]);
2390 for (j = 0; j < i; ++j) {
2391 bus_dmamap_destroy(sc->rx_mbuf_tag,
2392 sc->rx_mbuf_map[j]);
2394 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2395 sc->rx_mbuf_tag = NULL;
2397 if_printf(ifp, "Unable to create "
2398 "%dth RX mbuf DMA map!\n", i);
2406 /****************************************************************************/
2407 /* Firmware synchronization. */
2409 /* Before performing certain events such as a chip reset, synchronize with */
2410 /* the firmware first. */
2413 /* 0 for success, positive value for failure. */
2414 /****************************************************************************/
2416 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2421 /* Don't waste any time if we've timed out before. */
2422 if (sc->bce_fw_timed_out)
2425 /* Increment the message sequence number. */
2426 sc->bce_fw_wr_seq++;
2427 msg_data |= sc->bce_fw_wr_seq;
2429 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2431 /* Send the message to the bootcode driver mailbox. */
2432 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2434 /* Wait for the bootcode to acknowledge the message. */
2435 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2436 /* Check for a response in the bootcode firmware mailbox. */
2437 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_FW_MB);
2438 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2443 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2444 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2445 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2446 if_printf(&sc->arpcom.ac_if,
2447 "Firmware synchronization timeout! "
2448 "msg_data = 0x%08X\n", msg_data);
2450 msg_data &= ~BCE_DRV_MSG_CODE;
2451 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2453 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2455 sc->bce_fw_timed_out = 1;
2462 /****************************************************************************/
2463 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2467 /****************************************************************************/
2469 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2470 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2475 for (i = 0; i < rv2p_code_len; i += 8) {
2476 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2478 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2481 if (rv2p_proc == RV2P_PROC1) {
2482 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2483 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2485 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2486 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2490 /* Reset the processor, un-stall is done later. */
2491 if (rv2p_proc == RV2P_PROC1)
2492 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2494 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2498 /****************************************************************************/
2499 /* Load RISC processor firmware. */
2501 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2502 /* associated with a particular processor. */
2506 /****************************************************************************/
2508 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2511 uint32_t offset, val;
2515 val = REG_RD_IND(sc, cpu_reg->mode);
2516 val |= cpu_reg->mode_value_halt;
2517 REG_WR_IND(sc, cpu_reg->mode, val);
2518 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2520 /* Load the Text area. */
2521 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2523 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2524 REG_WR_IND(sc, offset, fw->text[j]);
2527 /* Load the Data area. */
2528 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2530 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2531 REG_WR_IND(sc, offset, fw->data[j]);
2534 /* Load the SBSS area. */
2535 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2537 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2538 REG_WR_IND(sc, offset, fw->sbss[j]);
2541 /* Load the BSS area. */
2542 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2544 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2545 REG_WR_IND(sc, offset, fw->bss[j]);
2548 /* Load the Read-Only area. */
2549 offset = cpu_reg->spad_base +
2550 (fw->rodata_addr - cpu_reg->mips_view_base);
2552 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2553 REG_WR_IND(sc, offset, fw->rodata[j]);
2556 /* Clear the pre-fetch instruction. */
2557 REG_WR_IND(sc, cpu_reg->inst, 0);
2558 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2560 /* Start the CPU. */
2561 val = REG_RD_IND(sc, cpu_reg->mode);
2562 val &= ~cpu_reg->mode_value_halt;
2563 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2564 REG_WR_IND(sc, cpu_reg->mode, val);
2568 /****************************************************************************/
2569 /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs. */
2571 /* Loads the firmware for each CPU and starts the CPU. */
2575 /****************************************************************************/
2577 bce_init_cpus(struct bce_softc *sc)
2579 struct cpu_reg cpu_reg;
2582 /* Initialize the RV2P processor. */
2583 bce_load_rv2p_fw(sc, bce_rv2p_proc1, sizeof(bce_rv2p_proc1), RV2P_PROC1);
2584 bce_load_rv2p_fw(sc, bce_rv2p_proc2, sizeof(bce_rv2p_proc2), RV2P_PROC2);
2586 /* Initialize the RX Processor. */
2587 cpu_reg.mode = BCE_RXP_CPU_MODE;
2588 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2589 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2590 cpu_reg.state = BCE_RXP_CPU_STATE;
2591 cpu_reg.state_value_clear = 0xffffff;
2592 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2593 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2594 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2595 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2596 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2597 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2598 cpu_reg.mips_view_base = 0x8000000;
2600 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2601 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2602 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2603 fw.start_addr = bce_RXP_b06FwStartAddr;
2605 fw.text_addr = bce_RXP_b06FwTextAddr;
2606 fw.text_len = bce_RXP_b06FwTextLen;
2608 fw.text = bce_RXP_b06FwText;
2610 fw.data_addr = bce_RXP_b06FwDataAddr;
2611 fw.data_len = bce_RXP_b06FwDataLen;
2613 fw.data = bce_RXP_b06FwData;
2615 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2616 fw.sbss_len = bce_RXP_b06FwSbssLen;
2618 fw.sbss = bce_RXP_b06FwSbss;
2620 fw.bss_addr = bce_RXP_b06FwBssAddr;
2621 fw.bss_len = bce_RXP_b06FwBssLen;
2623 fw.bss = bce_RXP_b06FwBss;
2625 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2626 fw.rodata_len = bce_RXP_b06FwRodataLen;
2627 fw.rodata_index = 0;
2628 fw.rodata = bce_RXP_b06FwRodata;
2630 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2631 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2633 /* Initialize the TX Processor. */
2634 cpu_reg.mode = BCE_TXP_CPU_MODE;
2635 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2636 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2637 cpu_reg.state = BCE_TXP_CPU_STATE;
2638 cpu_reg.state_value_clear = 0xffffff;
2639 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2640 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2641 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2642 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2643 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2644 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2645 cpu_reg.mips_view_base = 0x8000000;
2647 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2648 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2649 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2650 fw.start_addr = bce_TXP_b06FwStartAddr;
2652 fw.text_addr = bce_TXP_b06FwTextAddr;
2653 fw.text_len = bce_TXP_b06FwTextLen;
2655 fw.text = bce_TXP_b06FwText;
2657 fw.data_addr = bce_TXP_b06FwDataAddr;
2658 fw.data_len = bce_TXP_b06FwDataLen;
2660 fw.data = bce_TXP_b06FwData;
2662 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2663 fw.sbss_len = bce_TXP_b06FwSbssLen;
2665 fw.sbss = bce_TXP_b06FwSbss;
2667 fw.bss_addr = bce_TXP_b06FwBssAddr;
2668 fw.bss_len = bce_TXP_b06FwBssLen;
2670 fw.bss = bce_TXP_b06FwBss;
2672 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2673 fw.rodata_len = bce_TXP_b06FwRodataLen;
2674 fw.rodata_index = 0;
2675 fw.rodata = bce_TXP_b06FwRodata;
2677 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2678 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2680 /* Initialize the TX Patch-up Processor. */
2681 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2682 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2683 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2684 cpu_reg.state = BCE_TPAT_CPU_STATE;
2685 cpu_reg.state_value_clear = 0xffffff;
2686 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2687 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2688 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2689 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2690 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2691 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2692 cpu_reg.mips_view_base = 0x8000000;
2694 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2695 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2696 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2697 fw.start_addr = bce_TPAT_b06FwStartAddr;
2699 fw.text_addr = bce_TPAT_b06FwTextAddr;
2700 fw.text_len = bce_TPAT_b06FwTextLen;
2702 fw.text = bce_TPAT_b06FwText;
2704 fw.data_addr = bce_TPAT_b06FwDataAddr;
2705 fw.data_len = bce_TPAT_b06FwDataLen;
2707 fw.data = bce_TPAT_b06FwData;
2709 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2710 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2712 fw.sbss = bce_TPAT_b06FwSbss;
2714 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2715 fw.bss_len = bce_TPAT_b06FwBssLen;
2717 fw.bss = bce_TPAT_b06FwBss;
2719 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2720 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2721 fw.rodata_index = 0;
2722 fw.rodata = bce_TPAT_b06FwRodata;
2724 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2725 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2727 /* Initialize the Completion Processor. */
2728 cpu_reg.mode = BCE_COM_CPU_MODE;
2729 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
2730 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
2731 cpu_reg.state = BCE_COM_CPU_STATE;
2732 cpu_reg.state_value_clear = 0xffffff;
2733 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
2734 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
2735 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
2736 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
2737 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
2738 cpu_reg.spad_base = BCE_COM_SCRATCH;
2739 cpu_reg.mips_view_base = 0x8000000;
2741 fw.ver_major = bce_COM_b06FwReleaseMajor;
2742 fw.ver_minor = bce_COM_b06FwReleaseMinor;
2743 fw.ver_fix = bce_COM_b06FwReleaseFix;
2744 fw.start_addr = bce_COM_b06FwStartAddr;
2746 fw.text_addr = bce_COM_b06FwTextAddr;
2747 fw.text_len = bce_COM_b06FwTextLen;
2749 fw.text = bce_COM_b06FwText;
2751 fw.data_addr = bce_COM_b06FwDataAddr;
2752 fw.data_len = bce_COM_b06FwDataLen;
2754 fw.data = bce_COM_b06FwData;
2756 fw.sbss_addr = bce_COM_b06FwSbssAddr;
2757 fw.sbss_len = bce_COM_b06FwSbssLen;
2759 fw.sbss = bce_COM_b06FwSbss;
2761 fw.bss_addr = bce_COM_b06FwBssAddr;
2762 fw.bss_len = bce_COM_b06FwBssLen;
2764 fw.bss = bce_COM_b06FwBss;
2766 fw.rodata_addr = bce_COM_b06FwRodataAddr;
2767 fw.rodata_len = bce_COM_b06FwRodataLen;
2768 fw.rodata_index = 0;
2769 fw.rodata = bce_COM_b06FwRodata;
2771 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
2772 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2776 /****************************************************************************/
2777 /* Initialize context memory. */
2779 /* Clears the memory associated with each Context ID (CID). */
2783 /****************************************************************************/
2785 bce_init_context(struct bce_softc *sc)
2791 uint32_t vcid_addr, pcid_addr, offset;
2795 vcid_addr = GET_CID_ADDR(vcid);
2796 pcid_addr = vcid_addr;
2798 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0x00);
2799 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2801 /* Zero out the context. */
2802 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
2803 CTX_WR(sc, 0x00, offset, 0);
2805 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
2806 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2811 /****************************************************************************/
2812 /* Fetch the permanent MAC address of the controller. */
2816 /****************************************************************************/
2818 bce_get_mac_addr(struct bce_softc *sc)
2820 uint32_t mac_lo = 0, mac_hi = 0;
2823 * The NetXtreme II bootcode populates various NIC
2824 * power-on and runtime configuration items in a
2825 * shared memory area. The factory configured MAC
2826 * address is available from both NVRAM and the
2827 * shared memory area so we'll read the value from
2828 * shared memory for speed.
2831 mac_hi = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_UPPER);
2832 mac_lo = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_LOWER);
2834 if (mac_lo == 0 && mac_hi == 0) {
2835 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
2837 sc->eaddr[0] = (u_char)(mac_hi >> 8);
2838 sc->eaddr[1] = (u_char)(mac_hi >> 0);
2839 sc->eaddr[2] = (u_char)(mac_lo >> 24);
2840 sc->eaddr[3] = (u_char)(mac_lo >> 16);
2841 sc->eaddr[4] = (u_char)(mac_lo >> 8);
2842 sc->eaddr[5] = (u_char)(mac_lo >> 0);
2845 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
2849 /****************************************************************************/
2850 /* Program the MAC address. */
2854 /****************************************************************************/
2856 bce_set_mac_addr(struct bce_softc *sc)
2858 const uint8_t *mac_addr = sc->eaddr;
2861 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
2864 val = (mac_addr[0] << 8) | mac_addr[1];
2865 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
2867 val = (mac_addr[2] << 24) |
2868 (mac_addr[3] << 16) |
2869 (mac_addr[4] << 8) |
2871 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
2875 /****************************************************************************/
2876 /* Stop the controller. */
2880 /****************************************************************************/
2882 bce_stop(struct bce_softc *sc)
2884 struct ifnet *ifp = &sc->arpcom.ac_if;
2885 struct mii_data *mii = device_get_softc(sc->bce_miibus);
2886 struct ifmedia_entry *ifm;
2889 ASSERT_SERIALIZED(ifp->if_serializer);
2891 callout_stop(&sc->bce_stat_ch);
2893 /* Disable the transmit/receive blocks. */
2894 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, 0x5ffffff);
2895 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2898 bce_disable_intr(sc);
2900 /* Tell firmware that the driver is going away. */
2901 bce_reset(sc, BCE_DRV_MSG_CODE_SUSPEND_NO_WOL);
2903 /* Free the RX lists. */
2904 bce_free_rx_chain(sc);
2906 /* Free TX buffers. */
2907 bce_free_tx_chain(sc);
2910 * Isolate/power down the PHY, but leave the media selection
2911 * unchanged so that things will be put back to normal when
2912 * we bring the interface back up.
2914 itmp = ifp->if_flags;
2915 ifp->if_flags |= IFF_UP;
2916 ifm = mii->mii_media.ifm_cur;
2917 mtmp = ifm->ifm_media;
2918 ifm->ifm_media = IFM_ETHER | IFM_NONE;
2920 ifm->ifm_media = mtmp;
2921 ifp->if_flags = itmp;
2925 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2933 bce_reset(struct bce_softc *sc, uint32_t reset_code)
2938 /* Wait for pending PCI transactions to complete. */
2939 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
2940 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
2941 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
2942 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
2943 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
2944 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2947 /* Assume bootcode is running. */
2948 sc->bce_fw_timed_out = 0;
2950 /* Give the firmware a chance to prepare for the reset. */
2951 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
2953 if_printf(&sc->arpcom.ac_if,
2954 "Firmware is not ready for reset\n");
2958 /* Set a firmware reminder that this is a soft reset. */
2959 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_RESET_SIGNATURE,
2960 BCE_DRV_RESET_SIGNATURE_MAGIC);
2962 /* Dummy read to force the chip to complete all current transactions. */
2963 val = REG_RD(sc, BCE_MISC_ID);
2966 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2967 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
2968 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
2969 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
2971 /* Allow up to 30us for reset to complete. */
2972 for (i = 0; i < 10; i++) {
2973 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
2974 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2975 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
2981 /* Check that reset completed successfully. */
2982 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
2983 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
2984 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
2988 /* Make sure byte swapping is properly configured. */
2989 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
2990 if (val != 0x01020304) {
2991 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
2995 /* Just completed a reset, assume that firmware is running again. */
2996 sc->bce_fw_timed_out = 0;
2998 /* Wait for the firmware to finish its initialization. */
2999 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3001 if_printf(&sc->arpcom.ac_if,
3002 "Firmware did not complete initialization!\n");
3009 bce_chipinit(struct bce_softc *sc)
3014 /* Make sure the interrupt is not active. */
3015 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3018 * Initialize DMA byte/word swapping, configure the number of DMA
3019 * channels and PCI clock compensation delay.
3021 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3022 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3023 #if BYTE_ORDER == BIG_ENDIAN
3024 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3026 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3027 DMA_READ_CHANS << 12 |
3028 DMA_WRITE_CHANS << 16;
3030 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3032 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3033 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3036 * This setting resolves a problem observed on certain Intel PCI
3037 * chipsets that cannot handle multiple outstanding DMA operations.
3038 * See errata E9_5706A1_65.
3040 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3041 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3042 !(sc->bce_flags & BCE_PCIX_FLAG))
3043 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3045 REG_WR(sc, BCE_DMA_CONFIG, val);
3047 /* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
3048 if (sc->bce_flags & BCE_PCIX_FLAG) {
3051 cmd = pci_read_config(sc->bce_dev, BCE_PCI_PCIX_CMD, 2);
3052 pci_write_config(sc->bce_dev, BCE_PCI_PCIX_CMD, cmd & ~0x2, 2);
3055 /* Enable the RX_V2P and Context state machines before access. */
3056 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3057 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3058 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3059 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3061 /* Initialize context mapping and zero out the quick contexts. */
3062 bce_init_context(sc);
3064 /* Initialize the on-boards CPUs */
3067 /* Prepare NVRAM for access. */
3068 rc = bce_init_nvram(sc);
3072 /* Set the kernel bypass block size */
3073 val = REG_RD(sc, BCE_MQ_CONFIG);
3074 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3075 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3076 REG_WR(sc, BCE_MQ_CONFIG, val);
3078 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3079 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3080 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3082 /* Set the page size and clear the RV2P processor stall bits. */
3083 val = (BCM_PAGE_BITS - 8) << 24;
3084 REG_WR(sc, BCE_RV2P_CONFIG, val);
3086 /* Configure page size. */
3087 val = REG_RD(sc, BCE_TBDR_CONFIG);
3088 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3089 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3090 REG_WR(sc, BCE_TBDR_CONFIG, val);
3096 /****************************************************************************/
3097 /* Initialize the controller in preparation to send/receive traffic. */
3100 /* 0 for success, positive value for failure. */
3101 /****************************************************************************/
3103 bce_blockinit(struct bce_softc *sc)
3108 /* Load the hardware default MAC address. */
3109 bce_set_mac_addr(sc);
3111 /* Set the Ethernet backoff seed value */
3112 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3113 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3114 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3116 sc->last_status_idx = 0;
3117 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3119 /* Set up link change interrupt generation. */
3120 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3122 /* Program the physical address of the status block. */
3123 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3124 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3126 /* Program the physical address of the statistics block. */
3127 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3128 BCE_ADDR_LO(sc->stats_block_paddr));
3129 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3130 BCE_ADDR_HI(sc->stats_block_paddr));
3132 /* Program various host coalescing parameters. */
3133 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3134 (sc->bce_tx_quick_cons_trip_int << 16) |
3135 sc->bce_tx_quick_cons_trip);
3136 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3137 (sc->bce_rx_quick_cons_trip_int << 16) |
3138 sc->bce_rx_quick_cons_trip);
3139 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3140 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3141 REG_WR(sc, BCE_HC_TX_TICKS,
3142 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3143 REG_WR(sc, BCE_HC_RX_TICKS,
3144 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3145 REG_WR(sc, BCE_HC_COM_TICKS,
3146 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3147 REG_WR(sc, BCE_HC_CMD_TICKS,
3148 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3149 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3150 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3151 REG_WR(sc, BCE_HC_CONFIG,
3152 BCE_HC_CONFIG_RX_TMR_MODE |
3153 BCE_HC_CONFIG_TX_TMR_MODE |
3154 BCE_HC_CONFIG_COLLECT_STATS);
3156 /* Clear the internal statistics counters. */
3157 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3159 /* Verify that bootcode is running. */
3160 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_SIGNATURE);
3162 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3163 if_printf(&sc->arpcom.ac_if,
3164 "%s(%d): Simulating bootcode failure.\n",
3165 __FILE__, __LINE__);
3168 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3169 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3170 if_printf(&sc->arpcom.ac_if,
3171 "Bootcode not running! Found: 0x%08X, "
3172 "Expected: 08%08X\n",
3173 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3174 BCE_DEV_INFO_SIGNATURE_MAGIC);
3178 /* Check if any management firmware is running. */
3179 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_FEATURE);
3180 if (reg & (BCE_PORT_FEATURE_ASF_ENABLED |
3181 BCE_PORT_FEATURE_IMD_ENABLED)) {
3182 DBPRINT(sc, BCE_INFO, "Management F/W Enabled.\n");
3183 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
3187 REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_BC_REV);
3188 DBPRINT(sc, BCE_INFO, "bootcode rev = 0x%08X\n", sc->bce_fw_ver);
3190 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3191 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3193 /* Enable link state change interrupt generation. */
3194 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3196 /* Enable all remaining blocks in the MAC. */
3197 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, 0x5ffffff);
3198 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3205 /****************************************************************************/
3206 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3208 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3209 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3213 /* 0 for success, positive value for failure. */
3214 /****************************************************************************/
3216 bce_newbuf_std(struct bce_softc *sc, struct mbuf *m,
3217 uint16_t *prod, uint16_t *chain_prod, uint32_t *prod_bseq)
3220 struct bce_dmamap_arg ctx;
3221 bus_dma_segment_t seg;
3226 uint16_t debug_chain_prod = *chain_prod;
3229 /* Make sure the inputs are valid. */
3230 DBRUNIF((*chain_prod > MAX_RX_BD),
3231 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3232 "RX producer out of range: 0x%04X > 0x%04X\n",
3234 *chain_prod, (uint16_t)MAX_RX_BD));
3236 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3237 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3240 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3241 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3242 "Simulating mbuf allocation failure.\n",
3243 __FILE__, __LINE__);
3244 sc->mbuf_alloc_failed++;
3247 /* This is a new mbuf allocation. */
3248 m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3251 DBRUNIF(1, sc->rx_mbuf_alloc++);
3254 m_new->m_data = m_new->m_ext.ext_buf;
3256 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3258 /* Map the mbuf cluster into device memory. */
3259 map = sc->rx_mbuf_map[*chain_prod];
3261 ctx.bce_maxsegs = 1;
3262 ctx.bce_segs = &seg;
3263 error = bus_dmamap_load_mbuf(sc->rx_mbuf_tag, map, m_new,
3264 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
3265 if (error || ctx.bce_maxsegs == 0) {
3266 if_printf(&sc->arpcom.ac_if,
3267 "Error mapping mbuf into RX chain!\n");
3272 DBRUNIF(1, sc->rx_mbuf_alloc--);
3276 /* Watch for overflow. */
3277 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3278 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3279 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3280 __FILE__, __LINE__, sc->free_rx_bd,
3281 (uint16_t)USABLE_RX_BD));
3283 /* Update some debug statistic counters */
3284 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3285 sc->rx_low_watermark = sc->free_rx_bd);
3286 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3288 /* Setup the rx_bd for the first segment. */
3289 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3291 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(seg.ds_addr));
3292 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(seg.ds_addr));
3293 rxbd->rx_bd_len = htole32(seg.ds_len);
3294 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3295 *prod_bseq += seg.ds_len;
3297 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3299 /* Save the mbuf and update our counter. */
3300 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3303 DBRUN(BCE_VERBOSE_RECV,
3304 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3306 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3307 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3313 /****************************************************************************/
3314 /* Allocate memory and initialize the TX data structures. */
3317 /* 0 for success, positive value for failure. */
3318 /****************************************************************************/
3320 bce_init_tx_chain(struct bce_softc *sc)
3326 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3328 /* Set the initial TX producer/consumer indices. */
3331 sc->tx_prod_bseq = 0;
3333 sc->max_tx_bd = USABLE_TX_BD;
3334 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3335 DBRUNIF(1, sc->tx_full_count = 0);
3338 * The NetXtreme II supports a linked-list structre called
3339 * a Buffer Descriptor Chain (or BD chain). A BD chain
3340 * consists of a series of 1 or more chain pages, each of which
3341 * consists of a fixed number of BD entries.
3342 * The last BD entry on each page is a pointer to the next page
3343 * in the chain, and the last pointer in the BD chain
3344 * points back to the beginning of the chain.
3347 /* Set the TX next pointer chain entries. */
3348 for (i = 0; i < TX_PAGES; i++) {
3351 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3353 /* Check if we've reached the last page. */
3354 if (i == (TX_PAGES - 1))
3359 txbd->tx_bd_haddr_hi =
3360 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3361 txbd->tx_bd_haddr_lo =
3362 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3365 for (i = 0; i < TX_PAGES; ++i) {
3366 bus_dmamap_sync(sc->tx_bd_chain_tag, sc->tx_bd_chain_map[i],
3367 BUS_DMASYNC_PREWRITE);
3370 /* Initialize the context ID for an L2 TX chain. */
3371 val = BCE_L2CTX_TYPE_TYPE_L2;
3372 val |= BCE_L2CTX_TYPE_SIZE_L2;
3373 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TYPE, val);
3375 val = BCE_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
3376 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_CMD_TYPE, val);
3378 /* Point the hardware to the first page in the chain. */
3379 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3380 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_HI, val);
3381 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3382 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_LO, val);
3384 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
3386 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3392 /****************************************************************************/
3393 /* Free memory and clear the TX data structures. */
3397 /****************************************************************************/
3399 bce_free_tx_chain(struct bce_softc *sc)
3403 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3405 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3406 for (i = 0; i < TOTAL_TX_BD; i++) {
3407 if (sc->tx_mbuf_ptr[i] != NULL) {
3408 bus_dmamap_sync(sc->tx_mbuf_tag, sc->tx_mbuf_map[i],
3409 BUS_DMASYNC_POSTWRITE);
3410 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3411 m_freem(sc->tx_mbuf_ptr[i]);
3412 sc->tx_mbuf_ptr[i] = NULL;
3413 DBRUNIF(1, sc->tx_mbuf_alloc--);
3417 /* Clear each TX chain page. */
3418 for (i = 0; i < TX_PAGES; i++)
3419 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3421 /* Check if we lost any mbufs in the process. */
3422 DBRUNIF((sc->tx_mbuf_alloc),
3423 if_printf(&sc->arpcom.ac_if,
3424 "%s(%d): Memory leak! "
3425 "Lost %d mbufs from tx chain!\n",
3426 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3428 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3432 /****************************************************************************/
3433 /* Allocate memory and initialize the RX data structures. */
3436 /* 0 for success, positive value for failure. */
3437 /****************************************************************************/
3439 bce_init_rx_chain(struct bce_softc *sc)
3443 uint16_t prod, chain_prod;
3444 uint32_t prod_bseq, val;
3446 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3448 /* Initialize the RX producer and consumer indices. */
3451 sc->rx_prod_bseq = 0;
3452 sc->free_rx_bd = USABLE_RX_BD;
3453 sc->max_rx_bd = USABLE_RX_BD;
3454 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3455 DBRUNIF(1, sc->rx_empty_count = 0);
3457 /* Initialize the RX next pointer chain entries. */
3458 for (i = 0; i < RX_PAGES; i++) {
3461 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3463 /* Check if we've reached the last page. */
3464 if (i == (RX_PAGES - 1))
3469 /* Setup the chain page pointers. */
3470 rxbd->rx_bd_haddr_hi =
3471 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
3472 rxbd->rx_bd_haddr_lo =
3473 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
3476 /* Initialize the context ID for an L2 RX chain. */
3477 val = BCE_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3478 val |= BCE_L2CTX_CTX_TYPE_SIZE_L2;
3480 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_CTX_TYPE, val);
3482 /* Point the hardware to the first page in the chain. */
3483 /* XXX shouldn't this after RX descriptor initialization? */
3484 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3485 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_HI, val);
3486 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3487 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_LO, val);
3489 /* Allocate mbuf clusters for the rx_bd chain. */
3490 prod = prod_bseq = 0;
3491 while (prod < TOTAL_RX_BD) {
3492 chain_prod = RX_CHAIN_IDX(prod);
3493 if (bce_newbuf_std(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
3494 if_printf(&sc->arpcom.ac_if,
3495 "Error filling RX chain: rx_bd[0x%04X]!\n",
3500 prod = NEXT_RX_BD(prod);
3503 /* Save the RX chain producer index. */
3505 sc->rx_prod_bseq = prod_bseq;
3507 for (i = 0; i < RX_PAGES; i++) {
3508 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
3509 BUS_DMASYNC_PREWRITE);
3512 /* Tell the chip about the waiting rx_bd's. */
3513 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3514 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3516 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_chain(sc, 0, TOTAL_RX_BD));
3518 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3524 /****************************************************************************/
3525 /* Free memory and clear the RX data structures. */
3529 /****************************************************************************/
3531 bce_free_rx_chain(struct bce_softc *sc)
3535 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3537 /* Free any mbufs still in the RX mbuf chain. */
3538 for (i = 0; i < TOTAL_RX_BD; i++) {
3539 if (sc->rx_mbuf_ptr[i] != NULL) {
3540 bus_dmamap_sync(sc->rx_mbuf_tag, sc->rx_mbuf_map[i],
3541 BUS_DMASYNC_POSTREAD);
3542 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
3543 m_freem(sc->rx_mbuf_ptr[i]);
3544 sc->rx_mbuf_ptr[i] = NULL;
3545 DBRUNIF(1, sc->rx_mbuf_alloc--);
3549 /* Clear each RX chain page. */
3550 for (i = 0; i < RX_PAGES; i++)
3551 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3553 /* Check if we lost any mbufs in the process. */
3554 DBRUNIF((sc->rx_mbuf_alloc),
3555 if_printf(&sc->arpcom.ac_if,
3556 "%s(%d): Memory leak! "
3557 "Lost %d mbufs from rx chain!\n",
3558 __FILE__, __LINE__, sc->rx_mbuf_alloc));
3560 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3564 /****************************************************************************/
3565 /* Set media options. */
3568 /* 0 for success, positive value for failure. */
3569 /****************************************************************************/
3571 bce_ifmedia_upd(struct ifnet *ifp)
3573 struct bce_softc *sc = ifp->if_softc;
3574 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3577 * 'mii' will be NULL, when this function is called on following
3578 * code path: bce_attach() -> bce_mgmt_init()
3581 /* Make sure the MII bus has been enumerated. */
3583 if (mii->mii_instance) {
3584 struct mii_softc *miisc;
3586 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
3587 mii_phy_reset(miisc);
3595 /****************************************************************************/
3596 /* Reports current media status. */
3600 /****************************************************************************/
3602 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3604 struct bce_softc *sc = ifp->if_softc;
3605 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3608 ifmr->ifm_active = mii->mii_media_active;
3609 ifmr->ifm_status = mii->mii_media_status;
3613 /****************************************************************************/
3614 /* Handles PHY generated interrupt events. */
3618 /****************************************************************************/
3620 bce_phy_intr(struct bce_softc *sc)
3622 uint32_t new_link_state, old_link_state;
3623 struct ifnet *ifp = &sc->arpcom.ac_if;
3625 ASSERT_SERIALIZED(ifp->if_serializer);
3627 new_link_state = sc->status_block->status_attn_bits &
3628 STATUS_ATTN_BITS_LINK_STATE;
3629 old_link_state = sc->status_block->status_attn_bits_ack &
3630 STATUS_ATTN_BITS_LINK_STATE;
3632 /* Handle any changes if the link state has changed. */
3633 if (new_link_state != old_link_state) { /* XXX redundant? */
3634 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
3637 callout_stop(&sc->bce_stat_ch);
3638 bce_tick_serialized(sc);
3640 /* Update the status_attn_bits_ack field in the status block. */
3641 if (new_link_state) {
3642 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
3643 STATUS_ATTN_BITS_LINK_STATE);
3645 if_printf(ifp, "Link is now UP.\n");
3647 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
3648 STATUS_ATTN_BITS_LINK_STATE);
3650 if_printf(ifp, "Link is now DOWN.\n");
3654 /* Acknowledge the link change interrupt. */
3655 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
3659 /****************************************************************************/
3660 /* Handles received frame interrupt events. */
3664 /****************************************************************************/
3666 bce_rx_intr(struct bce_softc *sc, int count)
3668 struct status_block *sblk = sc->status_block;
3669 struct ifnet *ifp = &sc->arpcom.ac_if;
3670 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
3671 uint32_t sw_prod_bseq;
3674 ASSERT_SERIALIZED(ifp->if_serializer);
3676 DBRUNIF(1, sc->rx_interrupts++);
3678 /* Prepare the RX chain pages to be accessed by the host CPU. */
3679 for (i = 0; i < RX_PAGES; i++) {
3680 bus_dmamap_sync(sc->rx_bd_chain_tag,
3681 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
3684 /* Get the hardware's view of the RX consumer index. */
3685 hw_cons = sc->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
3686 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
3689 /* Get working copies of the driver's view of the RX indices. */
3690 sw_cons = sc->rx_cons;
3691 sw_prod = sc->rx_prod;
3692 sw_prod_bseq = sc->rx_prod_bseq;
3694 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
3695 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
3696 __func__, sw_prod, sw_cons, sw_prod_bseq);
3698 /* Prevent speculative reads from getting ahead of the status block. */
3699 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
3700 BUS_SPACE_BARRIER_READ);
3702 /* Update some debug statistics counters */
3703 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3704 sc->rx_low_watermark = sc->free_rx_bd);
3705 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3707 /* Scan through the receive chain as long as there is work to do. */
3708 while (sw_cons != hw_cons) {
3709 struct mbuf *m = NULL;
3710 struct l2_fhdr *l2fhdr = NULL;
3713 uint32_t status = 0;
3715 #ifdef foo /* DEVICE_POLLING */
3717 * Even if polling(4) is enabled, we can't just reap
3718 * 'count' RX descriptors and leave. It seems that RX
3719 * engine would be left in a wired state, if we broke
3720 * out the loop in the middle.
3722 if (count >= 0 && count-- == 0)
3727 * Convert the producer/consumer indices
3728 * to an actual rx_bd index.
3730 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
3731 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
3733 /* Get the used rx_bd. */
3734 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
3735 [RX_IDX(sw_chain_cons)];
3738 DBRUN(BCE_VERBOSE_RECV,
3739 if_printf(ifp, "%s(): ", __func__);
3740 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
3742 /* The mbuf is stored with the last rx_bd entry of a packet. */
3743 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
3744 /* Validate that this is the last rx_bd. */
3745 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
3746 if_printf(ifp, "%s(%d): "
3747 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
3748 __FILE__, __LINE__, sw_chain_cons);
3749 bce_breakpoint(sc));
3752 * ToDo: If the received packet is small enough
3753 * to fit into a single, non-M_EXT mbuf,
3754 * allocate a new mbuf here, copy the data to
3755 * that mbuf, and recycle the mapped jumbo frame.
3758 /* Unmap the mbuf from DMA space. */
3759 bus_dmamap_sync(sc->rx_mbuf_tag,
3760 sc->rx_mbuf_map[sw_chain_cons],
3761 BUS_DMASYNC_POSTREAD);
3762 bus_dmamap_unload(sc->rx_mbuf_tag,
3763 sc->rx_mbuf_map[sw_chain_cons]);
3765 /* Remove the mbuf from the driver's chain. */
3766 m = sc->rx_mbuf_ptr[sw_chain_cons];
3767 sc->rx_mbuf_ptr[sw_chain_cons] = NULL;
3770 * Frames received on the NetXteme II are prepended
3771 * with an l2_fhdr structure which provides status
3772 * information about the received frame (including
3773 * VLAN tags and checksum info). The frames are also
3774 * automatically adjusted to align the IP header
3775 * (i.e. two null bytes are inserted before the
3778 l2fhdr = mtod(m, struct l2_fhdr *);
3780 len = l2fhdr->l2_fhdr_pkt_len;
3781 status = l2fhdr->l2_fhdr_status;
3783 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
3785 "Simulating l2_fhdr status error.\n");
3786 status = status | L2_FHDR_ERRORS_PHY_DECODE);
3788 /* Watch for unusual sized frames. */
3789 DBRUNIF((len < BCE_MIN_MTU ||
3790 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
3792 "%s(%d): Unusual frame size found. "
3793 "Min(%d), Actual(%d), Max(%d)\n",
3795 (int)BCE_MIN_MTU, len,
3796 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
3797 bce_dump_mbuf(sc, m);
3798 bce_breakpoint(sc));
3800 len -= ETHER_CRC_LEN;
3802 /* Check the received frame for errors. */
3803 if (status & (L2_FHDR_ERRORS_BAD_CRC |
3804 L2_FHDR_ERRORS_PHY_DECODE |
3805 L2_FHDR_ERRORS_ALIGNMENT |
3806 L2_FHDR_ERRORS_TOO_SHORT |
3807 L2_FHDR_ERRORS_GIANT_FRAME)) {
3809 DBRUNIF(1, sc->l2fhdr_status_errors++);
3811 /* Reuse the mbuf for a new frame. */
3812 if (bce_newbuf_std(sc, m, &sw_prod,
3815 DBRUNIF(1, bce_breakpoint(sc));
3817 panic("%s: Can't reuse RX mbuf!\n",
3821 goto bce_rx_int_next_rx;
3825 * Get a new mbuf for the rx_bd. If no new
3826 * mbufs are available then reuse the current mbuf,
3827 * log an ierror on the interface, and generate
3828 * an error in the system log.
3830 if (bce_newbuf_std(sc, NULL, &sw_prod, &sw_chain_prod,
3834 "%s(%d): Failed to allocate new mbuf, "
3835 "incoming frame dropped!\n",
3836 __FILE__, __LINE__));
3840 /* Try and reuse the exisitng mbuf. */
3841 if (bce_newbuf_std(sc, m, &sw_prod,
3844 DBRUNIF(1, bce_breakpoint(sc));
3846 panic("%s: Double mbuf allocation "
3847 "failure!", ifp->if_xname);
3850 goto bce_rx_int_next_rx;
3854 * Skip over the l2_fhdr when passing
3855 * the data up the stack.
3857 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
3859 m->m_pkthdr.len = m->m_len = len;
3860 m->m_pkthdr.rcvif = ifp;
3862 DBRUN(BCE_VERBOSE_RECV,
3863 struct ether_header *eh;
3864 eh = mtod(m, struct ether_header *);
3865 if_printf(ifp, "%s(): to: %6D, from: %6D, "
3866 "type: 0x%04X\n", __func__,
3867 eh->ether_dhost, ":",
3868 eh->ether_shost, ":",
3869 htons(eh->ether_type)));
3871 /* Validate the checksum if offload enabled. */
3872 if (ifp->if_capenable & IFCAP_RXCSUM) {
3873 /* Check for an IP datagram. */
3874 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
3875 m->m_pkthdr.csum_flags |=
3878 /* Check if the IP checksum is valid. */
3879 if ((l2fhdr->l2_fhdr_ip_xsum ^
3881 m->m_pkthdr.csum_flags |=
3884 DBPRINT(sc, BCE_WARN_RECV,
3885 "%s(): Invalid IP checksum = 0x%04X!\n",
3886 __func__, l2fhdr->l2_fhdr_ip_xsum);
3890 /* Check for a valid TCP/UDP frame. */
3891 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
3892 L2_FHDR_STATUS_UDP_DATAGRAM)) {
3894 /* Check for a good TCP/UDP checksum. */
3896 (L2_FHDR_ERRORS_TCP_XSUM |
3897 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
3898 m->m_pkthdr.csum_data =
3899 l2fhdr->l2_fhdr_tcp_udp_xsum;
3900 m->m_pkthdr.csum_flags |=
3904 DBPRINT(sc, BCE_WARN_RECV,
3905 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
3906 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
3913 sw_prod = NEXT_RX_BD(sw_prod);
3916 sw_cons = NEXT_RX_BD(sw_cons);
3918 /* If we have a packet, pass it up the stack */
3920 DBPRINT(sc, BCE_VERBOSE_RECV,
3921 "%s(): Passing received frame up.\n", __func__);
3923 if (status & L2_FHDR_STATUS_L2_VLAN_TAG)
3924 VLAN_INPUT_TAG(m, l2fhdr->l2_fhdr_vlan_tag);
3926 ifp->if_input(ifp, m);
3928 DBRUNIF(1, sc->rx_mbuf_alloc--);
3932 * If polling(4) is not enabled, refresh hw_cons to see
3933 * whether there's new work.
3935 * If polling(4) is enabled, i.e count >= 0, refreshing
3936 * should not be performed, so that we would not spend
3937 * too much time in RX processing.
3939 if (count < 0 && sw_cons == hw_cons) {
3940 hw_cons = sc->hw_rx_cons =
3941 sblk->status_rx_quick_consumer_index0;
3942 if ((hw_cons & USABLE_RX_BD_PER_PAGE) ==
3943 USABLE_RX_BD_PER_PAGE)
3948 * Prevent speculative reads from getting ahead
3949 * of the status block.
3951 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
3952 BUS_SPACE_BARRIER_READ);
3955 for (i = 0; i < RX_PAGES; i++) {
3956 bus_dmamap_sync(sc->rx_bd_chain_tag,
3957 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
3960 sc->rx_cons = sw_cons;
3961 sc->rx_prod = sw_prod;
3962 sc->rx_prod_bseq = sw_prod_bseq;
3964 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3965 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3967 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
3968 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
3969 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
3973 /****************************************************************************/
3974 /* Handles transmit completion interrupt events. */
3978 /****************************************************************************/
3980 bce_tx_intr(struct bce_softc *sc)
3982 struct status_block *sblk = sc->status_block;
3983 struct ifnet *ifp = &sc->arpcom.ac_if;
3984 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
3986 ASSERT_SERIALIZED(ifp->if_serializer);
3988 DBRUNIF(1, sc->tx_interrupts++);
3990 /* Get the hardware's view of the TX consumer index. */
3991 hw_tx_cons = sc->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
3993 /* Skip to the next entry if this is a chain page pointer. */
3994 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
3997 sw_tx_cons = sc->tx_cons;
3999 /* Prevent speculative reads from getting ahead of the status block. */
4000 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4001 BUS_SPACE_BARRIER_READ);
4003 /* Cycle through any completed TX chain page entries. */
4004 while (sw_tx_cons != hw_tx_cons) {
4006 struct tx_bd *txbd = NULL;
4008 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4010 DBPRINT(sc, BCE_INFO_SEND,
4011 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4012 "sw_tx_chain_cons = 0x%04X\n",
4013 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4015 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4016 if_printf(ifp, "%s(%d): "
4017 "TX chain consumer out of range! "
4018 " 0x%04X > 0x%04X\n",
4019 __FILE__, __LINE__, sw_tx_chain_cons,
4021 bce_breakpoint(sc));
4023 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4024 [TX_IDX(sw_tx_chain_cons)]);
4026 DBRUNIF((txbd == NULL),
4027 if_printf(ifp, "%s(%d): "
4028 "Unexpected NULL tx_bd[0x%04X]!\n",
4029 __FILE__, __LINE__, sw_tx_chain_cons);
4030 bce_breakpoint(sc));
4032 DBRUN(BCE_INFO_SEND,
4033 if_printf(ifp, "%s(): ", __func__);
4034 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4037 * Free the associated mbuf. Remember
4038 * that only the last tx_bd of a packet
4039 * has an mbuf pointer and DMA map.
4041 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4042 /* Validate that this is the last tx_bd. */
4043 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4044 if_printf(ifp, "%s(%d): "
4045 "tx_bd END flag not set but "
4046 "txmbuf == NULL!\n", __FILE__, __LINE__);
4047 bce_breakpoint(sc));
4049 DBRUN(BCE_INFO_SEND,
4050 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4051 "from tx_bd[0x%04X]\n", __func__,
4054 /* Unmap the mbuf. */
4055 bus_dmamap_unload(sc->tx_mbuf_tag,
4056 sc->tx_mbuf_map[sw_tx_chain_cons]);
4058 /* Free the mbuf. */
4059 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4060 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4061 DBRUNIF(1, sc->tx_mbuf_alloc--);
4067 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4069 if (sw_tx_cons == hw_tx_cons) {
4070 /* Refresh hw_cons to see if there's new work. */
4071 hw_tx_cons = sc->hw_tx_cons =
4072 sblk->status_tx_quick_consumer_index0;
4073 if ((hw_tx_cons & USABLE_TX_BD_PER_PAGE) ==
4074 USABLE_TX_BD_PER_PAGE)
4079 * Prevent speculative reads from getting
4080 * ahead of the status block.
4082 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4083 BUS_SPACE_BARRIER_READ);
4086 if (sc->used_tx_bd == 0) {
4087 /* Clear the TX timeout timer. */
4091 /* Clear the tx hardware queue full flag. */
4092 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4093 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4094 DBPRINT(sc, BCE_WARN_SEND,
4095 "%s(): Open TX chain! %d/%d (used/total)\n",
4096 __func__, sc->used_tx_bd, sc->max_tx_bd));
4097 ifp->if_flags &= ~IFF_OACTIVE;
4099 sc->tx_cons = sw_tx_cons;
4103 /****************************************************************************/
4104 /* Disables interrupt generation. */
4108 /****************************************************************************/
4110 bce_disable_intr(struct bce_softc *sc)
4112 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4113 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4114 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4118 /****************************************************************************/
4119 /* Enables interrupt generation. */
4123 /****************************************************************************/
4125 bce_enable_intr(struct bce_softc *sc)
4129 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4131 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4132 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4133 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4135 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4136 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4138 val = REG_RD(sc, BCE_HC_COMMAND);
4139 REG_WR(sc, BCE_HC_COMMAND, val | BCE_HC_COMMAND_COAL_NOW);
4143 /****************************************************************************/
4144 /* Handles controller initialization. */
4148 /****************************************************************************/
4152 struct bce_softc *sc = xsc;
4153 struct ifnet *ifp = &sc->arpcom.ac_if;
4157 ASSERT_SERIALIZED(ifp->if_serializer);
4159 /* Check if the driver is still running and bail out if it is. */
4160 if (ifp->if_flags & IFF_RUNNING)
4165 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4167 if_printf(ifp, "Controller reset failed!\n");
4171 error = bce_chipinit(sc);
4173 if_printf(ifp, "Controller initialization failed!\n");
4177 error = bce_blockinit(sc);
4179 if_printf(ifp, "Block initialization failed!\n");
4183 /* Load our MAC address. */
4184 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4185 bce_set_mac_addr(sc);
4187 /* Calculate and program the Ethernet MTU size. */
4188 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4190 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4193 * Program the mtu, enabling jumbo frame
4194 * support if necessary. Also set the mbuf
4195 * allocation count for RX frames.
4197 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4199 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4200 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4201 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4202 sc->mbuf_alloc_size = MJUM9BYTES;
4204 panic("jumbo buffer is not supported yet\n");
4207 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4208 sc->mbuf_alloc_size = MCLBYTES;
4211 /* Calculate the RX Ethernet frame size for rx_bd's. */
4212 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4214 DBPRINT(sc, BCE_INFO,
4215 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4216 "max_frame_size = %d\n",
4217 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4218 sc->max_frame_size);
4220 /* Program appropriate promiscuous/multicast filtering. */
4221 bce_set_rx_mode(sc);
4223 /* Init RX buffer descriptor chain. */
4224 bce_init_rx_chain(sc); /* XXX return value */
4226 /* Init TX buffer descriptor chain. */
4227 bce_init_tx_chain(sc); /* XXX return value */
4229 #ifdef DEVICE_POLLING
4230 /* Disable interrupts if we are polling. */
4231 if (ifp->if_flags & IFF_POLLING) {
4232 bce_disable_intr(sc);
4234 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4235 (1 << 16) | sc->bce_rx_quick_cons_trip);
4236 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4237 (1 << 16) | sc->bce_tx_quick_cons_trip);
4240 /* Enable host interrupts. */
4241 bce_enable_intr(sc);
4243 bce_ifmedia_upd(ifp);
4245 ifp->if_flags |= IFF_RUNNING;
4246 ifp->if_flags &= ~IFF_OACTIVE;
4248 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
4255 /****************************************************************************/
4256 /* Initialize the controller just enough so that any management firmware */
4257 /* running on the device will continue to operate corectly. */
4261 /****************************************************************************/
4263 bce_mgmt_init(struct bce_softc *sc)
4265 struct ifnet *ifp = &sc->arpcom.ac_if;
4268 /* Check if the driver is still running and bail out if it is. */
4269 if (ifp->if_flags & IFF_RUNNING)
4272 /* Initialize the on-boards CPUs */
4275 /* Set the page size and clear the RV2P processor stall bits. */
4276 val = (BCM_PAGE_BITS - 8) << 24;
4277 REG_WR(sc, BCE_RV2P_CONFIG, val);
4279 /* Enable all critical blocks in the MAC. */
4280 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4281 BCE_MISC_ENABLE_SET_BITS_RX_V2P_ENABLE |
4282 BCE_MISC_ENABLE_SET_BITS_RX_DMA_ENABLE |
4283 BCE_MISC_ENABLE_SET_BITS_COMPLETION_ENABLE);
4284 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4287 bce_ifmedia_upd(ifp);
4291 /****************************************************************************/
4292 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4293 /* memory visible to the controller. */
4296 /* 0 for success, positive value for failure. */
4297 /****************************************************************************/
4299 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4301 struct bce_dmamap_arg ctx;
4302 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4303 bus_dmamap_t map, tmp_map;
4304 struct mbuf *m0 = *m_head;
4305 struct tx_bd *txbd = NULL;
4306 uint16_t vlan_tag = 0, flags = 0;
4307 uint16_t chain_prod, chain_prod_start, prod;
4309 int i, error, maxsegs;
4311 uint16_t debug_prod;
4314 /* Transfer any checksum offload flags to the bd. */
4315 if (m0->m_pkthdr.csum_flags) {
4316 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4317 flags |= TX_BD_FLAGS_IP_CKSUM;
4318 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4319 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4322 /* Transfer any VLAN tags to the bd. */
4323 if (m0->m_flags & M_VLANTAG) {
4324 flags |= TX_BD_FLAGS_VLAN_TAG;
4325 vlan_tag = m0->m_pkthdr.ether_vlantag;
4329 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4331 /* Map the mbuf into DMAable memory. */
4332 map = sc->tx_mbuf_map[chain_prod_start];
4334 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4335 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4336 ("not enough segements %d\n", maxsegs));
4337 if (maxsegs > BCE_MAX_SEGMENTS)
4338 maxsegs = BCE_MAX_SEGMENTS;
4340 /* Map the mbuf into our DMA address space. */
4341 ctx.bce_maxsegs = maxsegs;
4342 ctx.bce_segs = segs;
4343 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4344 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
4345 if (error == EFBIG || ctx.bce_maxsegs == 0) {
4346 DBPRINT(sc, BCE_WARN, "%s(): fragmented mbuf\n", __func__);
4347 DBRUNIF(1, bce_dump_mbuf(sc, m0););
4349 m0 = m_defrag(*m_head, MB_DONTWAIT);
4356 ctx.bce_maxsegs = maxsegs;
4357 ctx.bce_segs = segs;
4358 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4359 bce_dma_map_mbuf, &ctx,
4361 if (error || ctx.bce_maxsegs == 0) {
4362 if_printf(&sc->arpcom.ac_if,
4363 "Error mapping mbuf into TX chain\n");
4369 if_printf(&sc->arpcom.ac_if,
4370 "Error mapping mbuf into TX chain\n");
4374 /* prod points to an empty tx_bd at this point. */
4375 prod_bseq = sc->tx_prod_bseq;
4378 debug_prod = chain_prod;
4381 DBPRINT(sc, BCE_INFO_SEND,
4382 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4383 "prod_bseq = 0x%08X\n",
4384 __func__, prod, chain_prod, prod_bseq);
4387 * Cycle through each mbuf segment that makes up
4388 * the outgoing frame, gathering the mapping info
4389 * for that segment and creating a tx_bd to for
4392 for (i = 0; i < ctx.bce_maxsegs; i++) {
4393 chain_prod = TX_CHAIN_IDX(prod);
4394 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4396 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4397 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4398 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4399 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4400 txbd->tx_bd_flags = htole16(flags);
4401 prod_bseq += segs[i].ds_len;
4403 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4404 prod = NEXT_TX_BD(prod);
4407 /* Set the END flag on the last TX buffer descriptor. */
4408 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4410 DBRUN(BCE_EXCESSIVE_SEND,
4411 bce_dump_tx_chain(sc, debug_prod, ctx.bce_maxsegs));
4413 DBPRINT(sc, BCE_INFO_SEND,
4414 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4415 "prod_bseq = 0x%08X\n",
4416 __func__, prod, chain_prod, prod_bseq);
4418 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4421 * Ensure that the mbuf pointer for this transmission
4422 * is placed at the array index of the last
4423 * descriptor in this chain. This is done
4424 * because a single map is used for all
4425 * segments of the mbuf and we don't want to
4426 * unload the map before all of the segments
4429 sc->tx_mbuf_ptr[chain_prod] = m0;
4431 tmp_map = sc->tx_mbuf_map[chain_prod];
4432 sc->tx_mbuf_map[chain_prod] = map;
4433 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4435 sc->used_tx_bd += ctx.bce_maxsegs;
4437 /* Update some debug statistic counters */
4438 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4439 sc->tx_hi_watermark = sc->used_tx_bd);
4440 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
4441 DBRUNIF(1, sc->tx_mbuf_alloc++);
4443 DBRUN(BCE_VERBOSE_SEND,
4444 bce_dump_tx_mbuf_chain(sc, chain_prod, ctx.bce_maxsegs));
4446 /* prod points to the next free tx_bd at this point. */
4448 sc->tx_prod_bseq = prod_bseq;
4458 /****************************************************************************/
4459 /* Main transmit routine when called from another routine with a lock. */
4463 /****************************************************************************/
4465 bce_start(struct ifnet *ifp)
4467 struct bce_softc *sc = ifp->if_softc;
4470 ASSERT_SERIALIZED(ifp->if_serializer);
4472 /* If there's no link or the transmit queue is empty then just exit. */
4473 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING ||
4477 DBPRINT(sc, BCE_INFO_SEND,
4478 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04X, "
4479 "tx_prod_bseq = 0x%08X\n",
4481 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4484 struct mbuf *m_head;
4487 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4490 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4491 ifp->if_flags |= IFF_OACTIVE;
4495 /* Check for any frames to send. */
4496 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4501 * Pack the data into the transmit ring. If we
4502 * don't have room, place the mbuf back at the
4503 * head of the queue and set the OACTIVE flag
4504 * to wait for the NIC to drain the chain.
4506 if (bce_encap(sc, &m_head)) {
4507 ifp->if_flags |= IFF_OACTIVE;
4508 DBPRINT(sc, BCE_INFO_SEND,
4509 "TX chain is closed for business! "
4510 "Total tx_bd used = %d\n",
4517 /* Send a copy of the frame to any BPF listeners. */
4518 BPF_MTAP(ifp, m_head);
4522 /* no packets were dequeued */
4523 DBPRINT(sc, BCE_VERBOSE_SEND,
4524 "%s(): No packets were dequeued\n", __func__);
4528 DBPRINT(sc, BCE_INFO_SEND,
4529 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
4530 "tx_prod_bseq = 0x%08X\n",
4532 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4534 /* Start the transmit. */
4535 REG_WR16(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
4536 REG_WR(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
4538 /* Set the tx timeout. */
4539 ifp->if_timer = BCE_TX_TIMEOUT;
4543 /****************************************************************************/
4544 /* Handles any IOCTL calls from the operating system. */
4547 /* 0 for success, positive value for failure. */
4548 /****************************************************************************/
4550 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
4552 struct bce_softc *sc = ifp->if_softc;
4553 struct ifreq *ifr = (struct ifreq *)data;
4554 struct mii_data *mii;
4555 int mask, error = 0;
4557 ASSERT_SERIALIZED(ifp->if_serializer);
4561 /* Check that the MTU setting is supported. */
4562 if (ifr->ifr_mtu < BCE_MIN_MTU ||
4564 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
4566 ifr->ifr_mtu > ETHERMTU
4573 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
4575 ifp->if_mtu = ifr->ifr_mtu;
4576 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4581 if (ifp->if_flags & IFF_UP) {
4582 if (ifp->if_flags & IFF_RUNNING) {
4583 mask = ifp->if_flags ^ sc->bce_if_flags;
4585 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
4586 bce_set_rx_mode(sc);
4590 } else if (ifp->if_flags & IFF_RUNNING) {
4593 sc->bce_if_flags = ifp->if_flags;
4598 if (ifp->if_flags & IFF_RUNNING)
4599 bce_set_rx_mode(sc);
4604 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
4606 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
4608 mii = device_get_softc(sc->bce_miibus);
4609 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
4613 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
4614 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
4617 if (mask & IFCAP_HWCSUM) {
4618 ifp->if_capenable ^= IFCAP_HWCSUM;
4619 if (IFCAP_HWCSUM & ifp->if_capenable)
4620 ifp->if_hwassist = BCE_IF_HWASSIST;
4622 ifp->if_hwassist = 0;
4627 error = ether_ioctl(ifp, command, data);
4634 /****************************************************************************/
4635 /* Transmit timeout handler. */
4639 /****************************************************************************/
4641 bce_watchdog(struct ifnet *ifp)
4643 struct bce_softc *sc = ifp->if_softc;
4645 ASSERT_SERIALIZED(ifp->if_serializer);
4647 DBRUN(BCE_VERBOSE_SEND,
4648 bce_dump_driver_state(sc);
4649 bce_dump_status_block(sc));
4652 * If we are in this routine because of pause frames, then
4653 * don't reset the hardware.
4655 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
4658 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
4660 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
4662 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4667 if (!ifq_is_empty(&ifp->if_snd))
4672 #ifdef DEVICE_POLLING
4675 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
4677 struct bce_softc *sc = ifp->if_softc;
4678 struct status_block *sblk = sc->status_block;
4680 ASSERT_SERIALIZED(ifp->if_serializer);
4684 bce_disable_intr(sc);
4686 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4687 (1 << 16) | sc->bce_rx_quick_cons_trip);
4688 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4689 (1 << 16) | sc->bce_tx_quick_cons_trip);
4691 case POLL_DEREGISTER:
4692 bce_enable_intr(sc);
4694 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4695 (sc->bce_tx_quick_cons_trip_int << 16) |
4696 sc->bce_tx_quick_cons_trip);
4697 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4698 (sc->bce_rx_quick_cons_trip_int << 16) |
4699 sc->bce_rx_quick_cons_trip);
4705 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4707 if (cmd == POLL_AND_CHECK_STATUS) {
4708 uint32_t status_attn_bits;
4710 status_attn_bits = sblk->status_attn_bits;
4712 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4714 "Simulating unexpected status attention bit set.");
4715 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4717 /* Was it a link change interrupt? */
4718 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4719 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4723 * If any other attention is asserted then
4724 * the chip is toast.
4726 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4727 (sblk->status_attn_bits_ack &
4728 ~STATUS_ATTN_BITS_LINK_STATE)) {
4729 DBRUN(1, sc->unexpected_attentions++);
4731 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4732 sblk->status_attn_bits);
4735 if (bce_debug_unexpected_attention == 0)
4736 bce_breakpoint(sc));
4743 /* Check for any completed RX frames. */
4744 if (sblk->status_rx_quick_consumer_index0 != sc->hw_rx_cons)
4745 bce_rx_intr(sc, count);
4747 /* Check for any completed TX frames. */
4748 if (sblk->status_tx_quick_consumer_index0 != sc->hw_tx_cons)
4751 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4753 /* Check for new frames to transmit. */
4754 if (!ifq_is_empty(&ifp->if_snd))
4758 #endif /* DEVICE_POLLING */
4763 bce_has_work(struct bce_softc *sc)
4765 struct status_block *stat = sc->status_block;
4767 if ((stat->status_rx_quick_consumer_index0 != sc->hw_rx_cons) ||
4768 (stat->status_tx_quick_consumer_index0 != sc->hw_tx_cons))
4771 if (((stat->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != 0) !=
4781 * Interrupt handler.
4783 /****************************************************************************/
4784 /* Main interrupt entry point. Verifies that the controller generated the */
4785 /* interrupt and then calls a separate routine for handle the various */
4786 /* interrupt causes (PHY, TX, RX). */
4789 /* 0 for success, positive value for failure. */
4790 /****************************************************************************/
4794 struct bce_softc *sc = xsc;
4795 struct ifnet *ifp = &sc->arpcom.ac_if;
4796 struct status_block *sblk;
4798 ASSERT_SERIALIZED(ifp->if_serializer);
4800 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
4801 DBRUNIF(1, sc->interrupts_generated++);
4803 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4804 sblk = sc->status_block;
4807 * If the hardware status block index matches the last value
4808 * read by the driver and we haven't asserted our interrupt
4809 * then there's nothing to do.
4811 if (sblk->status_idx == sc->last_status_idx &&
4812 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
4813 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
4816 /* Ack the interrupt and stop others from occuring. */
4817 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4818 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
4819 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4821 /* Keep processing data as long as there is work to do. */
4823 uint32_t status_attn_bits;
4825 status_attn_bits = sblk->status_attn_bits;
4827 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4829 "Simulating unexpected status attention bit set.");
4830 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4832 /* Was it a link change interrupt? */
4833 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4834 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4838 * If any other attention is asserted then
4839 * the chip is toast.
4841 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4842 (sblk->status_attn_bits_ack &
4843 ~STATUS_ATTN_BITS_LINK_STATE)) {
4844 DBRUN(1, sc->unexpected_attentions++);
4846 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4847 sblk->status_attn_bits);
4850 if (bce_debug_unexpected_attention == 0)
4851 bce_breakpoint(sc));
4857 /* Check for any completed RX frames. */
4858 if (sblk->status_rx_quick_consumer_index0 != sc->hw_rx_cons)
4859 bce_rx_intr(sc, -1);
4861 /* Check for any completed TX frames. */
4862 if (sblk->status_tx_quick_consumer_index0 != sc->hw_tx_cons)
4866 * Save the status block index value
4867 * for use during the next interrupt.
4869 sc->last_status_idx = sblk->status_idx;
4872 * Prevent speculative reads from getting
4873 * ahead of the status block.
4875 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4876 BUS_SPACE_BARRIER_READ);
4879 * If there's no work left then exit the
4880 * interrupt service routine.
4882 if (sblk->status_rx_quick_consumer_index0 == sc->hw_rx_cons &&
4883 sblk->status_tx_quick_consumer_index0 == sc->hw_tx_cons)
4887 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4889 /* Re-enable interrupts. */
4890 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4891 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
4892 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4893 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4894 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4896 /* Handle any frames that arrived while handling the interrupt. */
4897 if (!ifq_is_empty(&ifp->if_snd))
4902 /****************************************************************************/
4903 /* Programs the various packet receive modes (broadcast and multicast). */
4907 /****************************************************************************/
4909 bce_set_rx_mode(struct bce_softc *sc)
4911 struct ifnet *ifp = &sc->arpcom.ac_if;
4912 struct ifmultiaddr *ifma;
4913 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4914 uint32_t rx_mode, sort_mode;
4917 ASSERT_SERIALIZED(ifp->if_serializer);
4919 /* Initialize receive mode default settings. */
4920 rx_mode = sc->rx_mode &
4921 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
4922 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
4923 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
4926 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
4929 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
4930 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4931 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
4934 * Check for promiscuous, all multicast, or selected
4935 * multicast address filtering.
4937 if (ifp->if_flags & IFF_PROMISC) {
4938 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
4940 /* Enable promiscuous mode. */
4941 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
4942 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
4943 } else if (ifp->if_flags & IFF_ALLMULTI) {
4944 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
4946 /* Enable all multicast addresses. */
4947 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
4948 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
4951 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
4953 /* Accept one or more multicast(s). */
4954 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
4956 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4957 if (ifma->ifma_addr->sa_family != AF_LINK)
4960 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
4961 ETHER_ADDR_LEN) & 0xFF;
4962 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
4965 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
4966 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
4969 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
4972 /* Only make changes if the recive mode has actually changed. */
4973 if (rx_mode != sc->rx_mode) {
4974 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
4977 sc->rx_mode = rx_mode;
4978 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
4981 /* Disable and clear the exisitng sort before enabling a new sort. */
4982 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
4983 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
4984 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
4988 /****************************************************************************/
4989 /* Called periodically to updates statistics from the controllers */
4990 /* statistics block. */
4994 /****************************************************************************/
4996 bce_stats_update(struct bce_softc *sc)
4998 struct ifnet *ifp = &sc->arpcom.ac_if;
4999 struct statistics_block *stats = sc->stats_block;
5001 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5003 ASSERT_SERIALIZED(ifp->if_serializer);
5006 * Update the interface statistics from the hardware statistics.
5008 ifp->if_collisions = (u_long)stats->stat_EtherStatsCollisions;
5010 ifp->if_ierrors = (u_long)stats->stat_EtherStatsUndersizePkts +
5011 (u_long)stats->stat_EtherStatsOverrsizePkts +
5012 (u_long)stats->stat_IfInMBUFDiscards +
5013 (u_long)stats->stat_Dot3StatsAlignmentErrors +
5014 (u_long)stats->stat_Dot3StatsFCSErrors;
5017 (u_long)stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5018 (u_long)stats->stat_Dot3StatsExcessiveCollisions +
5019 (u_long)stats->stat_Dot3StatsLateCollisions;
5022 * Certain controllers don't report carrier sense errors correctly.
5023 * See errata E11_5708CA0_1165.
5025 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5026 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5028 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5032 * Update the sysctl statistics from the hardware statistics.
5034 sc->stat_IfHCInOctets =
5035 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5036 (uint64_t)stats->stat_IfHCInOctets_lo;
5038 sc->stat_IfHCInBadOctets =
5039 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5040 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5042 sc->stat_IfHCOutOctets =
5043 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5044 (uint64_t)stats->stat_IfHCOutOctets_lo;
5046 sc->stat_IfHCOutBadOctets =
5047 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5048 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5050 sc->stat_IfHCInUcastPkts =
5051 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5052 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5054 sc->stat_IfHCInMulticastPkts =
5055 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5056 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5058 sc->stat_IfHCInBroadcastPkts =
5059 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5060 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5062 sc->stat_IfHCOutUcastPkts =
5063 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5064 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5066 sc->stat_IfHCOutMulticastPkts =
5067 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5068 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5070 sc->stat_IfHCOutBroadcastPkts =
5071 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5072 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5074 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5075 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5077 sc->stat_Dot3StatsCarrierSenseErrors =
5078 stats->stat_Dot3StatsCarrierSenseErrors;
5080 sc->stat_Dot3StatsFCSErrors =
5081 stats->stat_Dot3StatsFCSErrors;
5083 sc->stat_Dot3StatsAlignmentErrors =
5084 stats->stat_Dot3StatsAlignmentErrors;
5086 sc->stat_Dot3StatsSingleCollisionFrames =
5087 stats->stat_Dot3StatsSingleCollisionFrames;
5089 sc->stat_Dot3StatsMultipleCollisionFrames =
5090 stats->stat_Dot3StatsMultipleCollisionFrames;
5092 sc->stat_Dot3StatsDeferredTransmissions =
5093 stats->stat_Dot3StatsDeferredTransmissions;
5095 sc->stat_Dot3StatsExcessiveCollisions =
5096 stats->stat_Dot3StatsExcessiveCollisions;
5098 sc->stat_Dot3StatsLateCollisions =
5099 stats->stat_Dot3StatsLateCollisions;
5101 sc->stat_EtherStatsCollisions =
5102 stats->stat_EtherStatsCollisions;
5104 sc->stat_EtherStatsFragments =
5105 stats->stat_EtherStatsFragments;
5107 sc->stat_EtherStatsJabbers =
5108 stats->stat_EtherStatsJabbers;
5110 sc->stat_EtherStatsUndersizePkts =
5111 stats->stat_EtherStatsUndersizePkts;
5113 sc->stat_EtherStatsOverrsizePkts =
5114 stats->stat_EtherStatsOverrsizePkts;
5116 sc->stat_EtherStatsPktsRx64Octets =
5117 stats->stat_EtherStatsPktsRx64Octets;
5119 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5120 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5122 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5123 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5125 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5126 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5128 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5129 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5131 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5132 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5134 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5135 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5137 sc->stat_EtherStatsPktsTx64Octets =
5138 stats->stat_EtherStatsPktsTx64Octets;
5140 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5141 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5143 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5144 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5146 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5147 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5149 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5150 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5152 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5153 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5155 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5156 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5158 sc->stat_XonPauseFramesReceived =
5159 stats->stat_XonPauseFramesReceived;
5161 sc->stat_XoffPauseFramesReceived =
5162 stats->stat_XoffPauseFramesReceived;
5164 sc->stat_OutXonSent =
5165 stats->stat_OutXonSent;
5167 sc->stat_OutXoffSent =
5168 stats->stat_OutXoffSent;
5170 sc->stat_FlowControlDone =
5171 stats->stat_FlowControlDone;
5173 sc->stat_MacControlFramesReceived =
5174 stats->stat_MacControlFramesReceived;
5176 sc->stat_XoffStateEntered =
5177 stats->stat_XoffStateEntered;
5179 sc->stat_IfInFramesL2FilterDiscards =
5180 stats->stat_IfInFramesL2FilterDiscards;
5182 sc->stat_IfInRuleCheckerDiscards =
5183 stats->stat_IfInRuleCheckerDiscards;
5185 sc->stat_IfInFTQDiscards =
5186 stats->stat_IfInFTQDiscards;
5188 sc->stat_IfInMBUFDiscards =
5189 stats->stat_IfInMBUFDiscards;
5191 sc->stat_IfInRuleCheckerP4Hit =
5192 stats->stat_IfInRuleCheckerP4Hit;
5194 sc->stat_CatchupInRuleCheckerDiscards =
5195 stats->stat_CatchupInRuleCheckerDiscards;
5197 sc->stat_CatchupInFTQDiscards =
5198 stats->stat_CatchupInFTQDiscards;
5200 sc->stat_CatchupInMBUFDiscards =
5201 stats->stat_CatchupInMBUFDiscards;
5203 sc->stat_CatchupInRuleCheckerP4Hit =
5204 stats->stat_CatchupInRuleCheckerP4Hit;
5206 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5208 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5212 /****************************************************************************/
5213 /* Periodic function to perform maintenance tasks. */
5217 /****************************************************************************/
5219 bce_tick_serialized(struct bce_softc *sc)
5221 struct ifnet *ifp = &sc->arpcom.ac_if;
5222 struct mii_data *mii;
5225 ASSERT_SERIALIZED(ifp->if_serializer);
5227 /* Tell the firmware that the driver is still running. */
5229 msg = (uint32_t)BCE_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
5231 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5233 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_PULSE_MB, msg);
5235 /* Update the statistics from the hardware statistics block. */
5236 bce_stats_update(sc);
5238 /* Schedule the next tick. */
5239 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
5241 /* If link is up already up then we're done. */
5245 mii = device_get_softc(sc->bce_miibus);
5248 /* Check if the link has come up. */
5249 if (!sc->bce_link && (mii->mii_media_status & IFM_ACTIVE) &&
5250 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5252 /* Now that link is up, handle any outstanding TX traffic. */
5253 if (!ifq_is_empty(&ifp->if_snd))
5262 struct bce_softc *sc = xsc;
5263 struct ifnet *ifp = &sc->arpcom.ac_if;
5265 lwkt_serialize_enter(ifp->if_serializer);
5266 bce_tick_serialized(sc);
5267 lwkt_serialize_exit(ifp->if_serializer);
5272 /****************************************************************************/
5273 /* Allows the driver state to be dumped through the sysctl interface. */
5276 /* 0 for success, positive value for failure. */
5277 /****************************************************************************/
5279 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5283 struct bce_softc *sc;
5286 error = sysctl_handle_int(oidp, &result, 0, req);
5288 if (error || !req->newptr)
5292 sc = (struct bce_softc *)arg1;
5293 bce_dump_driver_state(sc);
5300 /****************************************************************************/
5301 /* Allows the hardware state to be dumped through the sysctl interface. */
5304 /* 0 for success, positive value for failure. */
5305 /****************************************************************************/
5307 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5311 struct bce_softc *sc;
5314 error = sysctl_handle_int(oidp, &result, 0, req);
5316 if (error || !req->newptr)
5320 sc = (struct bce_softc *)arg1;
5321 bce_dump_hw_state(sc);
5328 /****************************************************************************/
5329 /* Provides a sysctl interface to allows dumping the RX chain. */
5332 /* 0 for success, positive value for failure. */
5333 /****************************************************************************/
5335 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5339 struct bce_softc *sc;
5342 error = sysctl_handle_int(oidp, &result, 0, req);
5344 if (error || !req->newptr)
5348 sc = (struct bce_softc *)arg1;
5349 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5356 /****************************************************************************/
5357 /* Provides a sysctl interface to allows dumping the TX chain. */
5360 /* 0 for success, positive value for failure. */
5361 /****************************************************************************/
5363 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5367 struct bce_softc *sc;
5370 error = sysctl_handle_int(oidp, &result, 0, req);
5372 if (error || !req->newptr)
5376 sc = (struct bce_softc *)arg1;
5377 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
5384 /****************************************************************************/
5385 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5386 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5389 /* 0 for success, positive value for failure. */
5390 /****************************************************************************/
5392 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5394 struct bce_softc *sc;
5396 uint32_t val, result;
5399 error = sysctl_handle_int(oidp, &result, 0, req);
5400 if (error || (req->newptr == NULL))
5403 /* Make sure the register is accessible. */
5404 if (result < 0x8000) {
5405 sc = (struct bce_softc *)arg1;
5406 val = REG_RD(sc, result);
5407 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5409 } else if (result < 0x0280000) {
5410 sc = (struct bce_softc *)arg1;
5411 val = REG_RD_IND(sc, result);
5412 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5419 /****************************************************************************/
5420 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
\r
5421 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
\r
5424 /* 0 for success, positive value for failure. */
5425 /****************************************************************************/
5427 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
5429 struct bce_softc *sc;
5435 error = sysctl_handle_int(oidp, &result, 0, req);
5436 if (error || (req->newptr == NULL))
5439 /* Make sure the register is accessible. */
5440 if (result < 0x20) {
5441 sc = (struct bce_softc *)arg1;
5443 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
5444 if_printf(&sc->arpcom.ac_if,
5445 "phy 0x%02X = 0x%04X\n", result, val);
5451 /****************************************************************************/
5452 /* Provides a sysctl interface to forcing the driver to dump state and */
\r
5453 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5456 /* 0 for success, positive value for failure. */
5457 /****************************************************************************/
5459 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
5463 struct bce_softc *sc;
5466 error = sysctl_handle_int(oidp, &result, 0, req);
5468 if (error || !req->newptr)
5472 sc = (struct bce_softc *)arg1;
5481 /****************************************************************************/
5482 /* Adds any sysctl parameters for tuning or debugging purposes. */
5485 /* 0 for success, positive value for failure. */
5486 /****************************************************************************/
5488 bce_add_sysctls(struct bce_softc *sc)
5490 struct sysctl_ctx_list *ctx;
5491 struct sysctl_oid_list *children;
5493 sysctl_ctx_init(&sc->bce_sysctl_ctx);
5494 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
5495 SYSCTL_STATIC_CHILDREN(_hw),
5497 device_get_nameunit(sc->bce_dev),
5499 if (sc->bce_sysctl_tree == NULL) {
5500 device_printf(sc->bce_dev, "can't add sysctl node\n");
5504 ctx = &sc->bce_sysctl_ctx;
5505 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
5508 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5510 CTLFLAG_RD, &sc->rx_low_watermark,
5511 0, "Lowest level of free rx_bd's");
5513 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5515 CTLFLAG_RD, &sc->rx_empty_count,
5516 0, "Number of times the RX chain was empty");
5518 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5520 CTLFLAG_RD, &sc->tx_hi_watermark,
5521 0, "Highest level of used tx_bd's");
5523 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5525 CTLFLAG_RD, &sc->tx_full_count,
5526 0, "Number of times the TX chain was full");
5528 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5529 "l2fhdr_status_errors",
5530 CTLFLAG_RD, &sc->l2fhdr_status_errors,
5531 0, "l2_fhdr status errors");
5533 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5534 "unexpected_attentions",
5535 CTLFLAG_RD, &sc->unexpected_attentions,
5536 0, "unexpected attentions");
5538 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5539 "lost_status_block_updates",
5540 CTLFLAG_RD, &sc->lost_status_block_updates,
5541 0, "lost status block updates");
5543 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5544 "mbuf_alloc_failed",
5545 CTLFLAG_RD, &sc->mbuf_alloc_failed,
5546 0, "mbuf cluster allocation failures");
5549 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5550 "stat_IfHcInOctets",
5551 CTLFLAG_RD, &sc->stat_IfHCInOctets,
5554 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5555 "stat_IfHCInBadOctets",
5556 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
5557 "Bad bytes received");
5559 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5560 "stat_IfHCOutOctets",
5561 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
5564 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5565 "stat_IfHCOutBadOctets",
5566 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
5569 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5570 "stat_IfHCInUcastPkts",
5571 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
5572 "Unicast packets received");
5574 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5575 "stat_IfHCInMulticastPkts",
5576 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
5577 "Multicast packets received");
5579 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5580 "stat_IfHCInBroadcastPkts",
5581 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
5582 "Broadcast packets received");
5584 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5585 "stat_IfHCOutUcastPkts",
5586 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
5587 "Unicast packets sent");
5589 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5590 "stat_IfHCOutMulticastPkts",
5591 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
5592 "Multicast packets sent");
5594 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5595 "stat_IfHCOutBroadcastPkts",
5596 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
5597 "Broadcast packets sent");
5599 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5600 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
5601 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
5602 0, "Internal MAC transmit errors");
5604 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5605 "stat_Dot3StatsCarrierSenseErrors",
5606 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
5607 0, "Carrier sense errors");
5609 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5610 "stat_Dot3StatsFCSErrors",
5611 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
5612 0, "Frame check sequence errors");
5614 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5615 "stat_Dot3StatsAlignmentErrors",
5616 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
5617 0, "Alignment errors");
5619 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5620 "stat_Dot3StatsSingleCollisionFrames",
5621 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
5622 0, "Single Collision Frames");
5624 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5625 "stat_Dot3StatsMultipleCollisionFrames",
5626 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
5627 0, "Multiple Collision Frames");
5629 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5630 "stat_Dot3StatsDeferredTransmissions",
5631 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
5632 0, "Deferred Transmissions");
5634 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5635 "stat_Dot3StatsExcessiveCollisions",
5636 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
5637 0, "Excessive Collisions");
5639 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5640 "stat_Dot3StatsLateCollisions",
5641 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
5642 0, "Late Collisions");
5644 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5645 "stat_EtherStatsCollisions",
5646 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
5649 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5650 "stat_EtherStatsFragments",
5651 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
5654 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5655 "stat_EtherStatsJabbers",
5656 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
5659 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5660 "stat_EtherStatsUndersizePkts",
5661 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
5662 0, "Undersize packets");
5664 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5665 "stat_EtherStatsOverrsizePkts",
5666 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
5667 0, "stat_EtherStatsOverrsizePkts");
5669 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5670 "stat_EtherStatsPktsRx64Octets",
5671 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
5672 0, "Bytes received in 64 byte packets");
5674 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5675 "stat_EtherStatsPktsRx65Octetsto127Octets",
5676 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
5677 0, "Bytes received in 65 to 127 byte packets");
5679 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5680 "stat_EtherStatsPktsRx128Octetsto255Octets",
5681 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
5682 0, "Bytes received in 128 to 255 byte packets");
5684 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5685 "stat_EtherStatsPktsRx256Octetsto511Octets",
5686 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
5687 0, "Bytes received in 256 to 511 byte packets");
5689 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5690 "stat_EtherStatsPktsRx512Octetsto1023Octets",
5691 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
5692 0, "Bytes received in 512 to 1023 byte packets");
5694 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5695 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
5696 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
5697 0, "Bytes received in 1024 t0 1522 byte packets");
5699 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5700 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
5701 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
5702 0, "Bytes received in 1523 to 9022 byte packets");
5704 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5705 "stat_EtherStatsPktsTx64Octets",
5706 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
5707 0, "Bytes sent in 64 byte packets");
5709 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5710 "stat_EtherStatsPktsTx65Octetsto127Octets",
5711 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
5712 0, "Bytes sent in 65 to 127 byte packets");
5714 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5715 "stat_EtherStatsPktsTx128Octetsto255Octets",
5716 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
5717 0, "Bytes sent in 128 to 255 byte packets");
5719 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5720 "stat_EtherStatsPktsTx256Octetsto511Octets",
5721 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
5722 0, "Bytes sent in 256 to 511 byte packets");
5724 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5725 "stat_EtherStatsPktsTx512Octetsto1023Octets",
5726 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
5727 0, "Bytes sent in 512 to 1023 byte packets");
5729 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5730 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
5731 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
5732 0, "Bytes sent in 1024 to 1522 byte packets");
5734 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5735 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
5736 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
5737 0, "Bytes sent in 1523 to 9022 byte packets");
5739 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5740 "stat_XonPauseFramesReceived",
5741 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
5742 0, "XON pause frames receved");
5744 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5745 "stat_XoffPauseFramesReceived",
5746 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
5747 0, "XOFF pause frames received");
5749 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5751 CTLFLAG_RD, &sc->stat_OutXonSent,
5752 0, "XON pause frames sent");
5754 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5756 CTLFLAG_RD, &sc->stat_OutXoffSent,
5757 0, "XOFF pause frames sent");
5759 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5760 "stat_FlowControlDone",
5761 CTLFLAG_RD, &sc->stat_FlowControlDone,
5762 0, "Flow control done");
5764 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5765 "stat_MacControlFramesReceived",
5766 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
5767 0, "MAC control frames received");
5769 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5770 "stat_XoffStateEntered",
5771 CTLFLAG_RD, &sc->stat_XoffStateEntered,
5772 0, "XOFF state entered");
5774 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5775 "stat_IfInFramesL2FilterDiscards",
5776 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
5777 0, "Received L2 packets discarded");
5779 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5780 "stat_IfInRuleCheckerDiscards",
5781 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
5782 0, "Received packets discarded by rule");
5784 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5785 "stat_IfInFTQDiscards",
5786 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
5787 0, "Received packet FTQ discards");
5789 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5790 "stat_IfInMBUFDiscards",
5791 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
5792 0, "Received packets discarded due to lack of controller buffer memory");
5794 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5795 "stat_IfInRuleCheckerP4Hit",
5796 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
5797 0, "Received packets rule checker hits");
5799 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5800 "stat_CatchupInRuleCheckerDiscards",
5801 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
5802 0, "Received packets discarded in Catchup path");
5804 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5805 "stat_CatchupInFTQDiscards",
5806 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
5807 0, "Received packets discarded in FTQ in Catchup path");
5809 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5810 "stat_CatchupInMBUFDiscards",
5811 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
5812 0, "Received packets discarded in controller buffer memory in Catchup path");
5814 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5815 "stat_CatchupInRuleCheckerP4Hit",
5816 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
5817 0, "Received packets rule checker hits in Catchup path");
5819 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5821 CTLFLAG_RD, &sc->com_no_buffers,
5822 0, "Valid packets received but no RX buffers available");
5825 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5826 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
5828 bce_sysctl_driver_state, "I", "Drive state information");
5830 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5831 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
5833 bce_sysctl_hw_state, "I", "Hardware state information");
5835 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5836 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
5838 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
5840 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5841 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
5843 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
5845 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5846 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
5848 bce_sysctl_breakpoint, "I", "Driver breakpoint");
5850 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5851 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
5853 bce_sysctl_reg_read, "I", "Register read");
5855 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
\r
5856 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
\r
5858 bce_sysctl_phy_read, "I", "PHY register read");
5865 /****************************************************************************/
5866 /* BCE Debug Routines */
5867 /****************************************************************************/
5870 /****************************************************************************/
5871 /* Freezes the controller to allow for a cohesive state dump. */
5875 /****************************************************************************/
5877 bce_freeze_controller(struct bce_softc *sc)
5881 val = REG_RD(sc, BCE_MISC_COMMAND);
5882 val |= BCE_MISC_COMMAND_DISABLE_ALL;
5883 REG_WR(sc, BCE_MISC_COMMAND, val);
5887 /****************************************************************************/
5888 /* Unfreezes the controller after a freeze operation. This may not always */
\r
5889 /* work and the controller will require a reset! */
5893 /****************************************************************************/
5895 bce_unfreeze_controller(struct bce_softc *sc)
5899 val = REG_RD(sc, BCE_MISC_COMMAND);
5900 val |= BCE_MISC_COMMAND_ENABLE_ALL;
5901 REG_WR(sc, BCE_MISC_COMMAND, val);
5905 /****************************************************************************/
5906 /* Prints out information about an mbuf. */
5910 /****************************************************************************/
5912 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
5914 struct ifnet *ifp = &sc->arpcom.ac_if;
5915 uint32_t val_hi, val_lo;
5916 struct mbuf *mp = m;
5919 /* Index out of range. */
5920 if_printf(ifp, "mbuf: null pointer\n");
5925 val_hi = BCE_ADDR_HI(mp);
5926 val_lo = BCE_ADDR_LO(mp);
5927 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
5928 "m_flags = ( ", val_hi, val_lo, mp->m_len);
5930 if (mp->m_flags & M_EXT)
5932 if (mp->m_flags & M_PKTHDR)
5933 kprintf("M_PKTHDR ");
5934 if (mp->m_flags & M_EOR)
5937 if (mp->m_flags & M_RDONLY)
5938 kprintf("M_RDONLY ");
5941 val_hi = BCE_ADDR_HI(mp->m_data);
5942 val_lo = BCE_ADDR_LO(mp->m_data);
5943 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
5945 if (mp->m_flags & M_PKTHDR) {
5946 if_printf(ifp, "- m_pkthdr: flags = ( ");
5947 if (mp->m_flags & M_BCAST)
5948 kprintf("M_BCAST ");
5949 if (mp->m_flags & M_MCAST)
5950 kprintf("M_MCAST ");
5951 if (mp->m_flags & M_FRAG)
5953 if (mp->m_flags & M_FIRSTFRAG)
5954 kprintf("M_FIRSTFRAG ");
5955 if (mp->m_flags & M_LASTFRAG)
5956 kprintf("M_LASTFRAG ");
5958 if (mp->m_flags & M_VLANTAG)
5959 kprintf("M_VLANTAG ");
5962 if (mp->m_flags & M_PROMISC)
5963 kprintf("M_PROMISC ");
5965 kprintf(") csum_flags = ( ");
5966 if (mp->m_pkthdr.csum_flags & CSUM_IP)
5967 kprintf("CSUM_IP ");
5968 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
5969 kprintf("CSUM_TCP ");
5970 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
5971 kprintf("CSUM_UDP ");
5972 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
5973 kprintf("CSUM_IP_FRAGS ");
5974 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
5975 kprintf("CSUM_FRAGMENT ");
5977 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
5978 kprintf("CSUM_TSO ");
5980 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
5981 kprintf("CSUM_IP_CHECKED ");
5982 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
5983 kprintf("CSUM_IP_VALID ");
5984 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
5985 kprintf("CSUM_DATA_VALID ");
5989 if (mp->m_flags & M_EXT) {
5990 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
5991 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
5992 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
5994 val_hi, val_lo, mp->m_ext.ext_size);
6001 /****************************************************************************/
6002 /* Prints out the mbufs in the TX mbuf chain. */
6006 /****************************************************************************/
6008 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6010 struct ifnet *ifp = &sc->arpcom.ac_if;
6014 "----------------------------"
6016 "----------------------------\n");
6018 for (i = 0; i < count; i++) {
6019 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6020 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6021 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6025 "----------------------------"
6027 "----------------------------\n");
6031 /****************************************************************************/
6032 /* Prints out the mbufs in the RX mbuf chain. */
6036 /****************************************************************************/
6038 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6040 struct ifnet *ifp = &sc->arpcom.ac_if;
6044 "----------------------------"
6046 "----------------------------\n");
6048 for (i = 0; i < count; i++) {
6049 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6050 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6051 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6055 "----------------------------"
6057 "----------------------------\n");
6061 /****************************************************************************/
6062 /* Prints out a tx_bd structure. */
6066 /****************************************************************************/
6068 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6070 struct ifnet *ifp = &sc->arpcom.ac_if;
6072 if (idx > MAX_TX_BD) {
6073 /* Index out of range. */
6074 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6075 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6076 /* TX Chain page pointer. */
6077 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6078 "chain page pointer\n",
6079 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6081 /* Normal tx_bd entry. */
6082 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6084 "vlan tag= 0x%04X, flags = 0x%04X (",
6085 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6086 txbd->tx_bd_mss_nbytes,
6087 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6089 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6090 kprintf(" CONN_FAULT");
6092 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6093 kprintf(" TCP_UDP_CKSUM");
6095 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6096 kprintf(" IP_CKSUM");
6098 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6101 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6102 kprintf(" COAL_NOW");
6104 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6105 kprintf(" DONT_GEN_CRC");
6107 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6110 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6113 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6116 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6117 kprintf(" OPTION_WORD");
6119 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6122 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6130 /****************************************************************************/
6131 /* Prints out a rx_bd structure. */
6135 /****************************************************************************/
6137 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6139 struct ifnet *ifp = &sc->arpcom.ac_if;
6141 if (idx > MAX_RX_BD) {
6142 /* Index out of range. */
6143 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6144 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6145 /* TX Chain page pointer. */
6146 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6147 "chain page pointer\n",
6148 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6150 /* Normal tx_bd entry. */
6151 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6152 "nbytes = 0x%08X, flags = 0x%08X\n",
6153 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6154 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6159 /****************************************************************************/
6160 /* Prints out a l2_fhdr structure. */
6164 /****************************************************************************/
6166 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6168 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6169 "pkt_len = 0x%04X, vlan = 0x%04x, "
6170 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6171 idx, l2fhdr->l2_fhdr_status,
6172 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6173 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6177 /****************************************************************************/
6178 /* Prints out the tx chain. */
6182 /****************************************************************************/
6184 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6186 struct ifnet *ifp = &sc->arpcom.ac_if;
6189 /* First some info about the tx_bd chain structure. */
6191 "----------------------------"
6193 "----------------------------\n");
6195 if_printf(ifp, "page size = 0x%08X, "
6196 "tx chain pages = 0x%08X\n",
6197 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6199 if_printf(ifp, "tx_bd per page = 0x%08X, "
6200 "usable tx_bd per page = 0x%08X\n",
6201 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6202 (uint32_t)USABLE_TX_BD_PER_PAGE);
6204 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6207 "----------------------------"
6209 "----------------------------\n");
6211 /* Now print out the tx_bd's themselves. */
6212 for (i = 0; i < count; i++) {
6215 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6216 bce_dump_txbd(sc, tx_prod, txbd);
6217 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6221 "----------------------------"
6223 "----------------------------\n");
6227 /****************************************************************************/
6228 /* Prints out the rx chain. */
6232 /****************************************************************************/
6234 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6236 struct ifnet *ifp = &sc->arpcom.ac_if;
6239 /* First some info about the tx_bd chain structure. */
6241 "----------------------------"
6243 "----------------------------\n");
6245 if_printf(ifp, "page size = 0x%08X, "
6246 "rx chain pages = 0x%08X\n",
6247 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6249 if_printf(ifp, "rx_bd per page = 0x%08X, "
6250 "usable rx_bd per page = 0x%08X\n",
6251 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6252 (uint32_t)USABLE_RX_BD_PER_PAGE);
6254 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6257 "----------------------------"
6259 "----------------------------\n");
6261 /* Now print out the rx_bd's themselves. */
6262 for (i = 0; i < count; i++) {
6265 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6266 bce_dump_rxbd(sc, rx_prod, rxbd);
6267 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6271 "----------------------------"
6273 "----------------------------\n");
6277 /****************************************************************************/
6278 /* Prints out the status block from host memory. */
6282 /****************************************************************************/
6284 bce_dump_status_block(struct bce_softc *sc)
6286 struct status_block *sblk = sc->status_block;
6287 struct ifnet *ifp = &sc->arpcom.ac_if;
6290 "----------------------------"
6292 "----------------------------\n");
6294 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6296 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6297 sblk->status_attn_bits_ack);
6299 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6300 sblk->status_rx_quick_consumer_index0,
6301 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6303 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6304 sblk->status_tx_quick_consumer_index0,
6305 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6307 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6309 /* Theses indices are not used for normal L2 drivers. */
6310 if (sblk->status_rx_quick_consumer_index1) {
6311 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6312 sblk->status_rx_quick_consumer_index1,
6313 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
6316 if (sblk->status_tx_quick_consumer_index1) {
6317 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6318 sblk->status_tx_quick_consumer_index1,
6319 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
6322 if (sblk->status_rx_quick_consumer_index2) {
6323 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6324 sblk->status_rx_quick_consumer_index2,
6325 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
6328 if (sblk->status_tx_quick_consumer_index2) {
6329 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6330 sblk->status_tx_quick_consumer_index2,
6331 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
6334 if (sblk->status_rx_quick_consumer_index3) {
6335 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6336 sblk->status_rx_quick_consumer_index3,
6337 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
6340 if (sblk->status_tx_quick_consumer_index3) {
6341 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6342 sblk->status_tx_quick_consumer_index3,
6343 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
6346 if (sblk->status_rx_quick_consumer_index4 ||
6347 sblk->status_rx_quick_consumer_index5) {
6348 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6349 sblk->status_rx_quick_consumer_index4,
6350 sblk->status_rx_quick_consumer_index5);
6353 if (sblk->status_rx_quick_consumer_index6 ||
6354 sblk->status_rx_quick_consumer_index7) {
6355 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6356 sblk->status_rx_quick_consumer_index6,
6357 sblk->status_rx_quick_consumer_index7);
6360 if (sblk->status_rx_quick_consumer_index8 ||
6361 sblk->status_rx_quick_consumer_index9) {
6362 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6363 sblk->status_rx_quick_consumer_index8,
6364 sblk->status_rx_quick_consumer_index9);
6367 if (sblk->status_rx_quick_consumer_index10 ||
6368 sblk->status_rx_quick_consumer_index11) {
6369 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6370 sblk->status_rx_quick_consumer_index10,
6371 sblk->status_rx_quick_consumer_index11);
6374 if (sblk->status_rx_quick_consumer_index12 ||
6375 sblk->status_rx_quick_consumer_index13) {
6376 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6377 sblk->status_rx_quick_consumer_index12,
6378 sblk->status_rx_quick_consumer_index13);
6381 if (sblk->status_rx_quick_consumer_index14 ||
6382 sblk->status_rx_quick_consumer_index15) {
6383 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6384 sblk->status_rx_quick_consumer_index14,
6385 sblk->status_rx_quick_consumer_index15);
6388 if (sblk->status_completion_producer_index ||
6389 sblk->status_cmd_consumer_index) {
6390 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6391 sblk->status_completion_producer_index,
6392 sblk->status_cmd_consumer_index);
6396 "----------------------------"
6398 "----------------------------\n");
6402 /****************************************************************************/
6403 /* Prints out the statistics block. */
6407 /****************************************************************************/
6409 bce_dump_stats_block(struct bce_softc *sc)
6411 struct statistics_block *sblk = sc->stats_block;
6412 struct ifnet *ifp = &sc->arpcom.ac_if;
6416 " Stats Block (All Stats Not Shown Are 0) "
6417 "---------------\n");
6419 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
6420 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
6421 sblk->stat_IfHCInOctets_hi,
6422 sblk->stat_IfHCInOctets_lo);
6425 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
6426 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
6427 sblk->stat_IfHCInBadOctets_hi,
6428 sblk->stat_IfHCInBadOctets_lo);
6431 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
6432 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
6433 sblk->stat_IfHCOutOctets_hi,
6434 sblk->stat_IfHCOutOctets_lo);
6437 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
6438 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
6439 sblk->stat_IfHCOutBadOctets_hi,
6440 sblk->stat_IfHCOutBadOctets_lo);
6443 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
6444 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
6445 sblk->stat_IfHCInUcastPkts_hi,
6446 sblk->stat_IfHCInUcastPkts_lo);
6449 if (sblk->stat_IfHCInBroadcastPkts_hi ||
6450 sblk->stat_IfHCInBroadcastPkts_lo) {
6451 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
6452 sblk->stat_IfHCInBroadcastPkts_hi,
6453 sblk->stat_IfHCInBroadcastPkts_lo);
6456 if (sblk->stat_IfHCInMulticastPkts_hi ||
6457 sblk->stat_IfHCInMulticastPkts_lo) {
6458 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
6459 sblk->stat_IfHCInMulticastPkts_hi,
6460 sblk->stat_IfHCInMulticastPkts_lo);
6463 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
6464 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
6465 sblk->stat_IfHCOutUcastPkts_hi,
6466 sblk->stat_IfHCOutUcastPkts_lo);
6469 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
6470 sblk->stat_IfHCOutBroadcastPkts_lo) {
6471 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
6472 sblk->stat_IfHCOutBroadcastPkts_hi,
6473 sblk->stat_IfHCOutBroadcastPkts_lo);
6476 if (sblk->stat_IfHCOutMulticastPkts_hi ||
6477 sblk->stat_IfHCOutMulticastPkts_lo) {
6478 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
6479 sblk->stat_IfHCOutMulticastPkts_hi,
6480 sblk->stat_IfHCOutMulticastPkts_lo);
6483 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
6484 if_printf(ifp, " 0x%08X : "
6485 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
6486 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
6489 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
6490 if_printf(ifp, " 0x%08X : "
6491 "Dot3StatsCarrierSenseErrors\n",
6492 sblk->stat_Dot3StatsCarrierSenseErrors);
6495 if (sblk->stat_Dot3StatsFCSErrors) {
6496 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
6497 sblk->stat_Dot3StatsFCSErrors);
6500 if (sblk->stat_Dot3StatsAlignmentErrors) {
6501 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
6502 sblk->stat_Dot3StatsAlignmentErrors);
6505 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
6506 if_printf(ifp, " 0x%08X : "
6507 "Dot3StatsSingleCollisionFrames\n",
6508 sblk->stat_Dot3StatsSingleCollisionFrames);
6511 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
6512 if_printf(ifp, " 0x%08X : "
6513 "Dot3StatsMultipleCollisionFrames\n",
6514 sblk->stat_Dot3StatsMultipleCollisionFrames);
6517 if (sblk->stat_Dot3StatsDeferredTransmissions) {
6518 if_printf(ifp, " 0x%08X : "
6519 "Dot3StatsDeferredTransmissions\n",
6520 sblk->stat_Dot3StatsDeferredTransmissions);
6523 if (sblk->stat_Dot3StatsExcessiveCollisions) {
6524 if_printf(ifp, " 0x%08X : "
6525 "Dot3StatsExcessiveCollisions\n",
6526 sblk->stat_Dot3StatsExcessiveCollisions);
6529 if (sblk->stat_Dot3StatsLateCollisions) {
6530 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
6531 sblk->stat_Dot3StatsLateCollisions);
6534 if (sblk->stat_EtherStatsCollisions) {
6535 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
6536 sblk->stat_EtherStatsCollisions);
6539 if (sblk->stat_EtherStatsFragments) {
6540 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
6541 sblk->stat_EtherStatsFragments);
6544 if (sblk->stat_EtherStatsJabbers) {
6545 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
6546 sblk->stat_EtherStatsJabbers);
6549 if (sblk->stat_EtherStatsUndersizePkts) {
6550 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
6551 sblk->stat_EtherStatsUndersizePkts);
6554 if (sblk->stat_EtherStatsOverrsizePkts) {
6555 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
6556 sblk->stat_EtherStatsOverrsizePkts);
6559 if (sblk->stat_EtherStatsPktsRx64Octets) {
6560 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
6561 sblk->stat_EtherStatsPktsRx64Octets);
6564 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
6565 if_printf(ifp, " 0x%08X : "
6566 "EtherStatsPktsRx65Octetsto127Octets\n",
6567 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
6570 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
6571 if_printf(ifp, " 0x%08X : "
6572 "EtherStatsPktsRx128Octetsto255Octets\n",
6573 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
6576 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
6577 if_printf(ifp, " 0x%08X : "
6578 "EtherStatsPktsRx256Octetsto511Octets\n",
6579 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
6582 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
6583 if_printf(ifp, " 0x%08X : "
6584 "EtherStatsPktsRx512Octetsto1023Octets\n",
6585 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
6588 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
6589 if_printf(ifp, " 0x%08X : "
6590 "EtherStatsPktsRx1024Octetsto1522Octets\n",
6591 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
6594 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
6595 if_printf(ifp, " 0x%08X : "
6596 "EtherStatsPktsRx1523Octetsto9022Octets\n",
6597 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
6600 if (sblk->stat_EtherStatsPktsTx64Octets) {
6601 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
6602 sblk->stat_EtherStatsPktsTx64Octets);
6605 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
6606 if_printf(ifp, " 0x%08X : "
6607 "EtherStatsPktsTx65Octetsto127Octets\n",
6608 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
6611 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
6612 if_printf(ifp, " 0x%08X : "
6613 "EtherStatsPktsTx128Octetsto255Octets\n",
6614 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
6617 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
6618 if_printf(ifp, " 0x%08X : "
6619 "EtherStatsPktsTx256Octetsto511Octets\n",
6620 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
6623 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
6624 if_printf(ifp, " 0x%08X : "
6625 "EtherStatsPktsTx512Octetsto1023Octets\n",
6626 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
6629 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
6630 if_printf(ifp, " 0x%08X : "
6631 "EtherStatsPktsTx1024Octetsto1522Octets\n",
6632 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
6635 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
6636 if_printf(ifp, " 0x%08X : "
6637 "EtherStatsPktsTx1523Octetsto9022Octets\n",
6638 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
6641 if (sblk->stat_XonPauseFramesReceived) {
6642 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
6643 sblk->stat_XonPauseFramesReceived);
6646 if (sblk->stat_XoffPauseFramesReceived) {
6647 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
6648 sblk->stat_XoffPauseFramesReceived);
6651 if (sblk->stat_OutXonSent) {
6652 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6653 sblk->stat_OutXonSent);
6656 if (sblk->stat_OutXoffSent) {
6657 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6658 sblk->stat_OutXoffSent);
6661 if (sblk->stat_FlowControlDone) {
6662 if_printf(ifp, " 0x%08X : FlowControlDone\n",
6663 sblk->stat_FlowControlDone);
6666 if (sblk->stat_MacControlFramesReceived) {
6667 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
6668 sblk->stat_MacControlFramesReceived);
6671 if (sblk->stat_XoffStateEntered) {
6672 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
6673 sblk->stat_XoffStateEntered);
6676 if (sblk->stat_IfInFramesL2FilterDiscards) {
6677 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
6680 if (sblk->stat_IfInRuleCheckerDiscards) {
6681 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
6682 sblk->stat_IfInRuleCheckerDiscards);
6685 if (sblk->stat_IfInFTQDiscards) {
6686 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
6687 sblk->stat_IfInFTQDiscards);
6690 if (sblk->stat_IfInMBUFDiscards) {
6691 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
6692 sblk->stat_IfInMBUFDiscards);
6695 if (sblk->stat_IfInRuleCheckerP4Hit) {
6696 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
6697 sblk->stat_IfInRuleCheckerP4Hit);
6700 if (sblk->stat_CatchupInRuleCheckerDiscards) {
6701 if_printf(ifp, " 0x%08X : "
6702 "CatchupInRuleCheckerDiscards\n",
6703 sblk->stat_CatchupInRuleCheckerDiscards);
6706 if (sblk->stat_CatchupInFTQDiscards) {
6707 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
6708 sblk->stat_CatchupInFTQDiscards);
6711 if (sblk->stat_CatchupInMBUFDiscards) {
6712 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
6713 sblk->stat_CatchupInMBUFDiscards);
6716 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
6717 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
6718 sblk->stat_CatchupInRuleCheckerP4Hit);
6722 "----------------------------"
6724 "----------------------------\n");
6728 /****************************************************************************/
6729 /* Prints out a summary of the driver state. */
6733 /****************************************************************************/
6735 bce_dump_driver_state(struct bce_softc *sc)
6737 struct ifnet *ifp = &sc->arpcom.ac_if;
6738 uint32_t val_hi, val_lo;
6741 "-----------------------------"
6743 "-----------------------------\n");
6745 val_hi = BCE_ADDR_HI(sc);
6746 val_lo = BCE_ADDR_LO(sc);
6747 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
6748 "virtual address\n", val_hi, val_lo);
6750 val_hi = BCE_ADDR_HI(sc->status_block);
6751 val_lo = BCE_ADDR_LO(sc->status_block);
6752 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
6753 "virtual address\n", val_hi, val_lo);
6755 val_hi = BCE_ADDR_HI(sc->stats_block);
6756 val_lo = BCE_ADDR_LO(sc->stats_block);
6757 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
6758 "virtual address\n", val_hi, val_lo);
6760 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
6761 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
6762 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
6763 "virtual adddress\n", val_hi, val_lo);
6765 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
6766 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
6767 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
6768 "virtual address\n", val_hi, val_lo);
6770 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
6771 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
6772 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
6773 "virtual address\n", val_hi, val_lo);
6775 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
6776 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
6777 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
6778 "virtual address\n", val_hi, val_lo);
6780 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
6781 "h/w intrs\n", sc->interrupts_generated);
6783 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
6784 "rx interrupts handled\n", sc->rx_interrupts);
6786 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
6787 "tx interrupts handled\n", sc->tx_interrupts);
6789 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
6790 "status block index\n", sc->last_status_idx);
6792 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
6793 "tx producer index\n",
6794 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
6796 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
6797 "tx consumer index\n",
6798 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
6800 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
6801 "tx producer bseq index\n", sc->tx_prod_bseq);
6803 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
6804 "rx producer index\n",
6805 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
6807 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
6808 "rx consumer index\n",
6809 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
6811 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
6812 "rx producer bseq index\n", sc->rx_prod_bseq);
6814 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6815 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6817 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
6818 "free rx_bd's\n", sc->free_rx_bd);
6820 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
6821 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
6823 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
6824 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
6826 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6827 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6829 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
6832 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
6833 sc->tx_hi_watermark, sc->max_tx_bd);
6835 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
6836 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
6839 "----------------------------"
6841 "----------------------------\n");
6845 /****************************************************************************/
6846 /* Prints out the hardware state through a summary of important registers, */
\r
6847 /* followed by a complete register dump. */
6851 /****************************************************************************/
6853 bce_dump_hw_state(struct bce_softc *sc)
6855 struct ifnet *ifp = &sc->arpcom.ac_if;
6860 "----------------------------"
6862 "----------------------------\n");
6864 if_printf(ifp, "0x%08X - bootcode version\n", sc->bce_fw_ver);
6866 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
6867 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
6868 val1, BCE_MISC_ENABLE_STATUS_BITS);
6870 val1 = REG_RD(sc, BCE_DMA_STATUS);
6871 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
6873 val1 = REG_RD(sc, BCE_CTX_STATUS);
6874 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
6876 val1 = REG_RD(sc, BCE_EMAC_STATUS);
6877 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
6878 val1, BCE_EMAC_STATUS);
6880 val1 = REG_RD(sc, BCE_RPM_STATUS);
6881 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
6883 val1 = REG_RD(sc, BCE_TBDR_STATUS);
6884 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
6885 val1, BCE_TBDR_STATUS);
6887 val1 = REG_RD(sc, BCE_TDMA_STATUS);
6888 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
6889 val1, BCE_TDMA_STATUS);
6891 val1 = REG_RD(sc, BCE_HC_STATUS);
6892 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
6894 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
6895 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
6896 val1, BCE_TXP_CPU_STATE);
6898 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
6899 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
6900 val1, BCE_TPAT_CPU_STATE);
6902 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
6903 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
6904 val1, BCE_RXP_CPU_STATE);
6906 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
6907 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
6908 val1, BCE_COM_CPU_STATE);
6910 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
6911 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
6912 val1, BCE_MCP_CPU_STATE);
6914 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
6915 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
6916 val1, BCE_CP_CPU_STATE);
6919 "----------------------------"
6921 "----------------------------\n");
6924 "----------------------------"
6926 "----------------------------\n");
6928 for (i = 0x400; i < 0x8000; i += 0x10) {
6929 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
6931 REG_RD(sc, i + 0x4),
6932 REG_RD(sc, i + 0x8),
6933 REG_RD(sc, i + 0xc));
6937 "----------------------------"
6939 "----------------------------\n");
6943 /****************************************************************************/
6944 /* Prints out the TXP state. */
\r
6948 /****************************************************************************/
6950 bce_dump_txp_state(struct bce_softc *sc)
6952 struct ifnet *ifp = &sc->arpcom.ac_if;
6957 "----------------------------"
6959 "----------------------------\n");
6961 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
6962 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
6963 val1, BCE_TXP_CPU_MODE);
6965 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
6966 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
6967 val1, BCE_TXP_CPU_STATE);
6969 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
6970 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
6971 val1, BCE_TXP_CPU_EVENT_MASK);
6974 "----------------------------"
6976 "----------------------------\n");
6978 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
6979 /* Skip the big blank spaces */
6980 if (i < 0x454000 && i > 0x5ffff) {
6981 if_printf(ifp, "0x%04X: "
6982 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
6984 REG_RD_IND(sc, i + 0x4),
6985 REG_RD_IND(sc, i + 0x8),
6986 REG_RD_IND(sc, i + 0xc));
6991 "----------------------------"
6993 "----------------------------\n");
6997 /****************************************************************************/
6998 /* Prints out the RXP state. */
\r
7002 /****************************************************************************/
7004 bce_dump_rxp_state(struct bce_softc *sc)
7006 struct ifnet *ifp = &sc->arpcom.ac_if;
7011 "----------------------------"
7013 "----------------------------\n");
7015 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7016 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7017 val1, BCE_RXP_CPU_MODE);
7019 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7020 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7021 val1, BCE_RXP_CPU_STATE);
7023 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7024 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7025 val1, BCE_RXP_CPU_EVENT_MASK);
7028 "----------------------------"
7030 "----------------------------\n");
7032 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7033 /* Skip the big blank sapces */
7034 if (i < 0xc5400 && i > 0xdffff) {
7035 if_printf(ifp, "0x%04X: "
7036 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7038 REG_RD_IND(sc, i + 0x4),
7039 REG_RD_IND(sc, i + 0x8),
7040 REG_RD_IND(sc, i + 0xc));
7045 "----------------------------"
7047 "----------------------------\n");
7051 /****************************************************************************/
7052 /* Prints out the TPAT state. */
\r
7056 /****************************************************************************/
7058 bce_dump_tpat_state(struct bce_softc *sc)
7060 struct ifnet *ifp = &sc->arpcom.ac_if;
7065 "----------------------------"
7067 "----------------------------\n");
7069 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7070 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7071 val1, BCE_TPAT_CPU_MODE);
7073 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7074 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7075 val1, BCE_TPAT_CPU_STATE);
7077 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7078 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7079 val1, BCE_TPAT_CPU_EVENT_MASK);
7082 "----------------------------"
7084 "----------------------------\n");
7086 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7087 /* Skip the big blank spaces */
7088 if (i < 0x854000 && i > 0x9ffff) {
7089 if_printf(ifp, "0x%04X: "
7090 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7092 REG_RD_IND(sc, i + 0x4),
7093 REG_RD_IND(sc, i + 0x8),
7094 REG_RD_IND(sc, i + 0xc));
7099 "----------------------------"
7101 "----------------------------\n");
7105 /****************************************************************************/
7106 /* Prints out the driver state and then enters the debugger. */
7110 /****************************************************************************/
7112 bce_breakpoint(struct bce_softc *sc)
7115 bce_freeze_controller(sc);
7118 bce_dump_driver_state(sc);
7119 bce_dump_status_block(sc);
7120 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7121 bce_dump_hw_state(sc);
7122 bce_dump_txp_state(sc);
7125 bce_unfreeze_controller(sc);
7128 /* Call the debugger. */
7132 #endif /* BCE_DEBUG */