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.17 2008/08/17 04:32:32 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"
48 #include "opt_ethernet.h"
50 #include <sys/param.h>
52 #include <sys/endian.h>
53 #include <sys/kernel.h>
54 #include <sys/interrupt.h>
56 #include <sys/malloc.h>
57 #include <sys/queue.h>
59 #include <sys/random.h>
62 #include <sys/serialize.h>
63 #include <sys/socket.h>
64 #include <sys/sockio.h>
65 #include <sys/sysctl.h>
68 #include <net/ethernet.h>
70 #include <net/if_arp.h>
71 #include <net/if_dl.h>
72 #include <net/if_media.h>
73 #include <net/if_types.h>
74 #include <net/ifq_var.h>
75 #include <net/vlan/if_vlan_var.h>
76 #include <net/vlan/if_vlan_ether.h>
78 #include <dev/netif/mii_layer/mii.h>
79 #include <dev/netif/mii_layer/miivar.h>
81 #include <bus/pci/pcireg.h>
82 #include <bus/pci/pcivar.h>
84 #include "miibus_if.h"
86 #include <dev/netif/bce/if_bcereg.h>
87 #include <dev/netif/bce/if_bcefw.h>
89 /****************************************************************************/
90 /* BCE Debug Options */
91 /****************************************************************************/
94 static uint32_t bce_debug = BCE_WARN;
98 * 1 = 1 in 2,147,483,648
99 * 256 = 1 in 8,388,608
100 * 2048 = 1 in 1,048,576
101 * 65536 = 1 in 32,768
102 * 1048576 = 1 in 2,048
105 * 1073741824 = 1 in 2
107 * bce_debug_l2fhdr_status_check:
108 * How often the l2_fhdr frame error check will fail.
110 * bce_debug_unexpected_attention:
111 * How often the unexpected attention check will fail.
113 * bce_debug_mbuf_allocation_failure:
114 * How often to simulate an mbuf allocation failure.
116 * bce_debug_dma_map_addr_failure:
117 * How often to simulate a DMA mapping failure.
119 * bce_debug_bootcode_running_failure:
120 * How often to simulate a bootcode failure.
122 static int bce_debug_l2fhdr_status_check = 0;
123 static int bce_debug_unexpected_attention = 0;
124 static int bce_debug_mbuf_allocation_failure = 0;
125 static int bce_debug_dma_map_addr_failure = 0;
126 static int bce_debug_bootcode_running_failure = 0;
128 #endif /* BCE_DEBUG */
131 /****************************************************************************/
132 /* PCI Device ID Table */
134 /* Used by bce_probe() to identify the devices supported by this driver. */
135 /****************************************************************************/
136 #define BCE_DEVDESC_MAX 64
138 static struct bce_type bce_devs[] = {
139 /* BCM5706C Controllers and OEM boards. */
140 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
141 "HP NC370T Multifunction Gigabit Server Adapter" },
142 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
143 "HP NC370i Multifunction Gigabit Server Adapter" },
144 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
145 "Broadcom NetXtreme II BCM5706 1000Base-T" },
147 /* BCM5706S controllers and OEM boards. */
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
149 "HP NC370F Multifunction Gigabit Server Adapter" },
150 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
151 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
153 /* BCM5708C controllers and OEM boards. */
154 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
155 "Broadcom NetXtreme II BCM5708 1000Base-T" },
157 /* BCM5708S controllers and OEM boards. */
158 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
159 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
164 /****************************************************************************/
165 /* Supported Flash NVRAM device data. */
166 /****************************************************************************/
167 static const struct flash_spec flash_table[] =
170 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
171 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
172 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
174 /* Expansion entry 0001 */
175 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
176 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
177 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
179 /* Saifun SA25F010 (non-buffered flash) */
180 /* strap, cfg1, & write1 need updates */
181 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
182 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
183 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
184 "Non-buffered flash (128kB)"},
185 /* Saifun SA25F020 (non-buffered flash) */
186 /* strap, cfg1, & write1 need updates */
187 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
188 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
189 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
190 "Non-buffered flash (256kB)"},
191 /* Expansion entry 0100 */
192 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
193 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
194 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
196 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
197 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
198 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
199 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
200 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
201 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
202 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
203 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
204 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
205 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
206 /* Saifun SA25F005 (non-buffered flash) */
207 /* strap, cfg1, & write1 need updates */
208 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
209 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
210 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
211 "Non-buffered flash (64kB)"},
213 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
214 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
215 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
217 /* Expansion entry 1001 */
218 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
219 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
220 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
222 /* Expansion entry 1010 */
223 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
224 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
225 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
227 /* ATMEL AT45DB011B (buffered flash) */
228 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
229 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
230 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
231 "Buffered flash (128kB)"},
232 /* Expansion entry 1100 */
233 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
234 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
235 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
237 /* Expansion entry 1101 */
238 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
239 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
240 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
242 /* Ateml Expansion entry 1110 */
243 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
244 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
245 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
246 "Entry 1110 (Atmel)"},
247 /* ATMEL AT45DB021B (buffered flash) */
248 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
249 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
250 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
251 "Buffered flash (256kB)"},
255 /****************************************************************************/
256 /* DragonFly device entry points. */
257 /****************************************************************************/
258 static int bce_probe(device_t);
259 static int bce_attach(device_t);
260 static int bce_detach(device_t);
261 static void bce_shutdown(device_t);
263 /****************************************************************************/
264 /* BCE Debug Data Structure Dump Routines */
265 /****************************************************************************/
267 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
268 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
269 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
270 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
271 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
272 static void bce_dump_l2fhdr(struct bce_softc *, int,
273 struct l2_fhdr *) __unused;
274 static void bce_dump_tx_chain(struct bce_softc *, int, int);
275 static void bce_dump_rx_chain(struct bce_softc *, int, int);
276 static void bce_dump_status_block(struct bce_softc *);
277 static void bce_dump_driver_state(struct bce_softc *);
278 static void bce_dump_stats_block(struct bce_softc *) __unused;
279 static void bce_dump_hw_state(struct bce_softc *);
280 static void bce_dump_txp_state(struct bce_softc *);
281 static void bce_dump_rxp_state(struct bce_softc *) __unused;
282 static void bce_dump_tpat_state(struct bce_softc *) __unused;
283 static void bce_freeze_controller(struct bce_softc *) __unused;
284 static void bce_unfreeze_controller(struct bce_softc *) __unused;
285 static void bce_breakpoint(struct bce_softc *);
286 #endif /* BCE_DEBUG */
289 /****************************************************************************/
290 /* BCE Register/Memory Access Routines */
291 /****************************************************************************/
292 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
293 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
294 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
295 static int bce_miibus_read_reg(device_t, int, int);
296 static int bce_miibus_write_reg(device_t, int, int, int);
297 static void bce_miibus_statchg(device_t);
300 /****************************************************************************/
301 /* BCE NVRAM Access Routines */
302 /****************************************************************************/
303 static int bce_acquire_nvram_lock(struct bce_softc *);
304 static int bce_release_nvram_lock(struct bce_softc *);
305 static void bce_enable_nvram_access(struct bce_softc *);
306 static void bce_disable_nvram_access(struct bce_softc *);
307 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
309 static int bce_init_nvram(struct bce_softc *);
310 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
311 static int bce_nvram_test(struct bce_softc *);
312 #ifdef BCE_NVRAM_WRITE_SUPPORT
313 static int bce_enable_nvram_write(struct bce_softc *);
314 static void bce_disable_nvram_write(struct bce_softc *);
315 static int bce_nvram_erase_page(struct bce_softc *, uint32_t);
316 static int bce_nvram_write_dword(struct bce_softc *, uint32_t, uint8_t *,
318 static int bce_nvram_write(struct bce_softc *, uint32_t, uint8_t *,
322 /****************************************************************************/
323 /* BCE DMA Allocate/Free Routines */
324 /****************************************************************************/
325 static int bce_dma_alloc(struct bce_softc *);
326 static void bce_dma_free(struct bce_softc *);
327 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
328 static void bce_dma_map_mbuf(void *, bus_dma_segment_t *, int,
331 /****************************************************************************/
332 /* BCE Firmware Synchronization and Load */
333 /****************************************************************************/
334 static int bce_fw_sync(struct bce_softc *, uint32_t);
335 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
337 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
339 static void bce_init_cpus(struct bce_softc *);
341 static void bce_stop(struct bce_softc *);
342 static int bce_reset(struct bce_softc *, uint32_t);
343 static int bce_chipinit(struct bce_softc *);
344 static int bce_blockinit(struct bce_softc *);
345 static int bce_newbuf_std(struct bce_softc *, struct mbuf *,
346 uint16_t *, uint16_t *, uint32_t *);
348 static int bce_init_tx_chain(struct bce_softc *);
349 static int bce_init_rx_chain(struct bce_softc *);
350 static void bce_free_rx_chain(struct bce_softc *);
351 static void bce_free_tx_chain(struct bce_softc *);
353 static int bce_encap(struct bce_softc *, struct mbuf **);
354 static void bce_start(struct ifnet *);
355 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
356 static void bce_watchdog(struct ifnet *);
357 static int bce_ifmedia_upd(struct ifnet *);
358 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
359 static void bce_init(void *);
360 static void bce_mgmt_init(struct bce_softc *);
362 static void bce_init_ctx(struct bce_softc *);
363 static void bce_get_mac_addr(struct bce_softc *);
364 static void bce_set_mac_addr(struct bce_softc *);
365 static void bce_phy_intr(struct bce_softc *);
366 static void bce_rx_intr(struct bce_softc *, int);
367 static void bce_tx_intr(struct bce_softc *);
368 static void bce_disable_intr(struct bce_softc *);
369 static void bce_enable_intr(struct bce_softc *);
371 #ifdef DEVICE_POLLING
372 static void bce_poll(struct ifnet *, enum poll_cmd, int);
374 static void bce_intr(void *);
375 static void bce_set_rx_mode(struct bce_softc *);
376 static void bce_stats_update(struct bce_softc *);
377 static void bce_tick(void *);
378 static void bce_tick_serialized(struct bce_softc *);
379 static void bce_add_sysctls(struct bce_softc *);
381 static void bce_coal_change(struct bce_softc *);
382 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
383 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
384 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
385 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
386 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
387 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
388 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
389 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
390 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
391 uint32_t *, uint32_t);
393 static uint32_t bce_tx_bds_int = 20; /* bcm: 20 */
394 static uint32_t bce_tx_bds = 24; /* bcm: 20 */
395 static uint32_t bce_tx_ticks_int = 80; /* bcm: 80 */
396 static uint32_t bce_tx_ticks = 1000; /* bcm: 80 */
397 static uint32_t bce_rx_bds_int = 6; /* bcm: 6 */
398 static uint32_t bce_rx_bds = 24; /* bcm: 6 */
399 static uint32_t bce_rx_ticks_int = 18; /* bcm: 18 */
400 static uint32_t bce_rx_ticks = 100; /* bcm: 18 */
402 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
403 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
404 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
405 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
406 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
407 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
408 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
409 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
411 /****************************************************************************/
412 /* DragonFly device dispatch table. */
413 /****************************************************************************/
414 static device_method_t bce_methods[] = {
415 /* Device interface */
416 DEVMETHOD(device_probe, bce_probe),
417 DEVMETHOD(device_attach, bce_attach),
418 DEVMETHOD(device_detach, bce_detach),
419 DEVMETHOD(device_shutdown, bce_shutdown),
422 DEVMETHOD(bus_print_child, bus_generic_print_child),
423 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
426 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
427 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
428 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
433 static driver_t bce_driver = {
436 sizeof(struct bce_softc)
439 static devclass_t bce_devclass;
441 MODULE_DEPEND(bce, pci, 1, 1, 1);
442 MODULE_DEPEND(bce, ether, 1, 1, 1);
443 MODULE_DEPEND(bce, miibus, 1, 1, 1);
445 DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
446 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
449 /****************************************************************************/
450 /* Device probe function. */
452 /* Compares the device to the driver's list of supported devices and */
453 /* reports back to the OS whether this is the right driver for the device. */
456 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
457 /****************************************************************************/
459 bce_probe(device_t dev)
462 uint16_t vid, did, svid, sdid;
464 /* Get the data for the device to be probed. */
465 vid = pci_get_vendor(dev);
466 did = pci_get_device(dev);
467 svid = pci_get_subvendor(dev);
468 sdid = pci_get_subdevice(dev);
470 /* Look through the list of known devices for a match. */
471 for (t = bce_devs; t->bce_name != NULL; ++t) {
472 if (vid == t->bce_vid && did == t->bce_did &&
473 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
474 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
475 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
478 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
480 /* Print out the device identity. */
481 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
483 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
485 device_set_desc_copy(dev, descbuf);
486 kfree(descbuf, M_TEMP);
494 /****************************************************************************/
495 /* Device attach function. */
497 /* Allocates device resources, performs secondary chip identification, */
498 /* resets and initializes the hardware, and initializes driver instance */
502 /* 0 on success, positive value on failure. */
503 /****************************************************************************/
505 bce_attach(device_t dev)
507 struct bce_softc *sc = device_get_softc(dev);
508 struct ifnet *ifp = &sc->arpcom.ac_if;
516 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
518 pci_enable_busmaster(dev);
520 /* Allocate PCI memory resources. */
522 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
523 RF_ACTIVE | PCI_RF_DENSE);
524 if (sc->bce_res_mem == NULL) {
525 device_printf(dev, "PCI memory allocation failed\n");
528 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
529 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
531 /* Allocate PCI IRQ resources. */
533 count = pci_msi_count(dev);
534 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
536 sc->bce_flags |= BCE_USING_MSI_FLAG;
540 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
541 RF_SHAREABLE | RF_ACTIVE);
542 if (sc->bce_res_irq == NULL) {
543 device_printf(dev, "PCI map interrupt failed\n");
549 * Configure byte swap and enable indirect register access.
550 * Rely on CPU to do target byte swapping on big endian systems.
551 * Access to registers outside of PCI configurtion space are not
552 * valid until this is done.
554 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
555 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
556 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
558 /* Save ASIC revsion info. */
559 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
561 /* Weed out any non-production controller revisions. */
562 switch(BCE_CHIP_ID(sc)) {
563 case BCE_CHIP_ID_5706_A0:
564 case BCE_CHIP_ID_5706_A1:
565 case BCE_CHIP_ID_5708_A0:
566 case BCE_CHIP_ID_5708_B0:
567 device_printf(dev, "Unsupported chip id 0x%08x!\n",
574 * The embedded PCIe to PCI-X bridge (EPB)
575 * in the 5708 cannot address memory above
576 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
578 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
579 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
581 sc->max_bus_addr = BUS_SPACE_MAXADDR;
584 * Find the base address for shared memory access.
585 * Newer versions of bootcode use a signature and offset
586 * while older versions use a fixed address.
588 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
589 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
590 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0);
592 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
594 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
596 /* Get PCI bus information (speed and type). */
597 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
598 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
601 sc->bce_flags |= BCE_PCIX_FLAG;
603 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
604 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
606 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
607 sc->bus_speed_mhz = 133;
610 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
611 sc->bus_speed_mhz = 100;
614 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
615 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
616 sc->bus_speed_mhz = 66;
619 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
620 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
621 sc->bus_speed_mhz = 50;
624 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
625 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
626 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
627 sc->bus_speed_mhz = 33;
631 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
632 sc->bus_speed_mhz = 66;
634 sc->bus_speed_mhz = 33;
637 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
638 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
640 device_printf(dev, "ASIC ID 0x%08X; Revision (%c%d); PCI%s %s %dMHz\n",
642 ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
643 (BCE_CHIP_ID(sc) & 0x0ff0) >> 4,
644 (sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : "",
645 (sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
646 "32-bit" : "64-bit", sc->bus_speed_mhz);
648 /* Reset the controller. */
649 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
653 /* Initialize the controller. */
654 rc = bce_chipinit(sc);
656 device_printf(dev, "Controller initialization failed!\n");
660 /* Perform NVRAM test. */
661 rc = bce_nvram_test(sc);
663 device_printf(dev, "NVRAM test failed!\n");
667 /* Fetch the permanent Ethernet MAC address. */
668 bce_get_mac_addr(sc);
671 * Trip points control how many BDs
672 * should be ready before generating an
673 * interrupt while ticks control how long
674 * a BD can sit in the chain before
675 * generating an interrupt. Set the default
676 * values for the RX and TX rings.
680 /* Force more frequent interrupts. */
681 sc->bce_tx_quick_cons_trip_int = 1;
682 sc->bce_tx_quick_cons_trip = 1;
683 sc->bce_tx_ticks_int = 0;
684 sc->bce_tx_ticks = 0;
686 sc->bce_rx_quick_cons_trip_int = 1;
687 sc->bce_rx_quick_cons_trip = 1;
688 sc->bce_rx_ticks_int = 0;
689 sc->bce_rx_ticks = 0;
691 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
692 sc->bce_tx_quick_cons_trip = bce_tx_bds;
693 sc->bce_tx_ticks_int = bce_tx_ticks_int;
694 sc->bce_tx_ticks = bce_tx_ticks;
696 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
697 sc->bce_rx_quick_cons_trip = bce_rx_bds;
698 sc->bce_rx_ticks_int = bce_rx_ticks_int;
699 sc->bce_rx_ticks = bce_rx_ticks;
702 /* Update statistics once every second. */
703 sc->bce_stats_ticks = 1000000 & 0xffff00;
706 * The copper based NetXtreme II controllers
707 * use an integrated PHY at address 1 while
708 * the SerDes controllers use a PHY at
711 sc->bce_phy_addr = 1;
713 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
714 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
715 sc->bce_flags |= BCE_NO_WOL_FLAG;
716 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708) {
717 sc->bce_phy_addr = 2;
718 val = REG_RD_IND(sc, sc->bce_shmem_base +
719 BCE_SHARED_HW_CFG_CONFIG);
720 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
721 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
725 /* Allocate DMA memory resources. */
726 rc = bce_dma_alloc(sc);
728 device_printf(dev, "DMA resource allocation failed!\n");
732 /* Initialize the ifnet interface. */
734 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
735 ifp->if_ioctl = bce_ioctl;
736 ifp->if_start = bce_start;
737 ifp->if_init = bce_init;
738 ifp->if_watchdog = bce_watchdog;
739 #ifdef DEVICE_POLLING
740 ifp->if_poll = bce_poll;
742 ifp->if_mtu = ETHERMTU;
743 ifp->if_hwassist = BCE_IF_HWASSIST;
744 ifp->if_capabilities = BCE_IF_CAPABILITIES;
745 ifp->if_capenable = ifp->if_capabilities;
746 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
747 ifq_set_ready(&ifp->if_snd);
749 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
750 ifp->if_baudrate = IF_Gbps(2.5);
752 ifp->if_baudrate = IF_Gbps(1);
754 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
755 sc->mbuf_alloc_size = MCLBYTES;
757 /* Look for our PHY. */
758 rc = mii_phy_probe(dev, &sc->bce_miibus,
759 bce_ifmedia_upd, bce_ifmedia_sts);
761 device_printf(dev, "PHY probe failed!\n");
765 /* Attach to the Ethernet interface list. */
766 ether_ifattach(ifp, sc->eaddr, NULL);
768 callout_init(&sc->bce_stat_ch);
770 /* Hookup IRQ last. */
771 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, bce_intr, sc,
772 &sc->bce_intrhand, ifp->if_serializer);
774 device_printf(dev, "Failed to setup IRQ!\n");
779 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
780 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
782 /* Print some important debugging info. */
783 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
785 /* Add the supported sysctls to the kernel. */
788 /* Get the firmware running so IPMI still works */
798 /****************************************************************************/
799 /* Device detach function. */
801 /* Stops the controller, resets the controller, and releases resources. */
804 /* 0 on success, positive value on failure. */
805 /****************************************************************************/
807 bce_detach(device_t dev)
809 struct bce_softc *sc = device_get_softc(dev);
811 if (device_is_attached(dev)) {
812 struct ifnet *ifp = &sc->arpcom.ac_if;
814 /* Stop and reset the controller. */
815 lwkt_serialize_enter(ifp->if_serializer);
817 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
818 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
819 lwkt_serialize_exit(ifp->if_serializer);
824 /* If we have a child device on the MII bus remove it too. */
826 device_delete_child(dev, sc->bce_miibus);
827 bus_generic_detach(dev);
829 if (sc->bce_res_irq != NULL) {
830 bus_release_resource(dev, SYS_RES_IRQ,
831 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
836 if (sc->bce_flags & BCE_USING_MSI_FLAG)
837 pci_release_msi(dev);
840 if (sc->bce_res_mem != NULL) {
841 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
847 if (sc->bce_sysctl_tree != NULL)
848 sysctl_ctx_free(&sc->bce_sysctl_ctx);
854 /****************************************************************************/
855 /* Device shutdown function. */
857 /* Stops and resets the controller. */
861 /****************************************************************************/
863 bce_shutdown(device_t dev)
865 struct bce_softc *sc = device_get_softc(dev);
866 struct ifnet *ifp = &sc->arpcom.ac_if;
868 lwkt_serialize_enter(ifp->if_serializer);
870 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
871 lwkt_serialize_exit(ifp->if_serializer);
875 /****************************************************************************/
876 /* Indirect register read. */
878 /* Reads NetXtreme II registers using an index/data register pair in PCI */
879 /* configuration space. Using this mechanism avoids issues with posted */
880 /* reads but is much slower than memory-mapped I/O. */
883 /* The value of the register. */
884 /****************************************************************************/
886 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
888 device_t dev = sc->bce_dev;
890 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
894 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
895 DBPRINT(sc, BCE_EXCESSIVE,
896 "%s(); offset = 0x%08X, val = 0x%08X\n",
897 __func__, offset, val);
901 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
906 /****************************************************************************/
907 /* Indirect register write. */
909 /* Writes NetXtreme II registers using an index/data register pair in PCI */
910 /* configuration space. Using this mechanism avoids issues with posted */
911 /* writes but is muchh slower than memory-mapped I/O. */
915 /****************************************************************************/
917 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
919 device_t dev = sc->bce_dev;
921 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
922 __func__, offset, val);
924 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
925 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
929 /****************************************************************************/
930 /* Context memory write. */
932 /* The NetXtreme II controller uses context memory to track connection */
933 /* information for L2 and higher network protocols. */
937 /****************************************************************************/
939 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t offset,
942 DBPRINT(sc, BCE_EXCESSIVE, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
943 "val = 0x%08X\n", __func__, cid_addr, offset, val);
946 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
947 REG_WR(sc, BCE_CTX_DATA, val);
951 /****************************************************************************/
952 /* PHY register read. */
954 /* Implements register reads on the MII bus. */
957 /* The value of the register. */
958 /****************************************************************************/
960 bce_miibus_read_reg(device_t dev, int phy, int reg)
962 struct bce_softc *sc = device_get_softc(dev);
966 /* Make sure we are accessing the correct PHY address. */
967 if (phy != sc->bce_phy_addr) {
968 DBPRINT(sc, BCE_VERBOSE,
969 "Invalid PHY address %d for PHY read!\n", phy);
973 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
974 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
975 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
977 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
978 REG_RD(sc, BCE_EMAC_MDIO_MODE);
983 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
984 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
985 BCE_EMAC_MDIO_COMM_START_BUSY;
986 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
988 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
991 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
992 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
995 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
996 val &= BCE_EMAC_MDIO_COMM_DATA;
1001 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1002 if_printf(&sc->arpcom.ac_if,
1003 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1007 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1010 DBPRINT(sc, BCE_EXCESSIVE,
1011 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1012 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1014 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1015 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1016 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1018 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1019 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1023 return (val & 0xffff);
1027 /****************************************************************************/
1028 /* PHY register write. */
1030 /* Implements register writes on the MII bus. */
1033 /* The value of the register. */
1034 /****************************************************************************/
1036 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1038 struct bce_softc *sc = device_get_softc(dev);
1042 /* Make sure we are accessing the correct PHY address. */
1043 if (phy != sc->bce_phy_addr) {
1044 DBPRINT(sc, BCE_WARN,
1045 "Invalid PHY address %d for PHY write!\n", phy);
1049 DBPRINT(sc, BCE_EXCESSIVE,
1050 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1051 __func__, phy, (uint16_t)(reg & 0xffff),
1052 (uint16_t)(val & 0xffff));
1054 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1055 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1056 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1058 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1059 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1064 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1065 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1066 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1067 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1069 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1072 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1073 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1079 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1080 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1082 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1083 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1084 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1086 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1087 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1095 /****************************************************************************/
1096 /* MII bus status change. */
1098 /* Called by the MII bus driver when the PHY establishes link to set the */
1099 /* MAC interface registers. */
1103 /****************************************************************************/
1105 bce_miibus_statchg(device_t dev)
1107 struct bce_softc *sc = device_get_softc(dev);
1108 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1110 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1111 mii->mii_media_active);
1114 /* Decode the interface media flags. */
1115 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1116 switch(IFM_TYPE(mii->mii_media_active)) {
1118 kprintf("Ethernet )");
1121 kprintf("Unknown )");
1125 kprintf(" Media Options: ( ");
1126 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1128 kprintf("Autoselect )");
1131 kprintf("Manual )");
1137 kprintf("10Base-T )");
1140 kprintf("100Base-TX )");
1143 kprintf("1000Base-SX )");
1146 kprintf("1000Base-T )");
1153 kprintf(" Global Options: (");
1154 if (mii->mii_media_active & IFM_FDX)
1155 kprintf(" FullDuplex");
1156 if (mii->mii_media_active & IFM_HDX)
1157 kprintf(" HalfDuplex");
1158 if (mii->mii_media_active & IFM_LOOP)
1159 kprintf(" Loopback");
1160 if (mii->mii_media_active & IFM_FLAG0)
1162 if (mii->mii_media_active & IFM_FLAG1)
1164 if (mii->mii_media_active & IFM_FLAG2)
1169 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1172 * Set MII or GMII interface based on the speed negotiated
1175 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1176 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1177 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1178 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1180 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1181 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1185 * Set half or full duplex based on the duplicity negotiated
1188 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1189 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1190 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1192 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1193 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1198 /****************************************************************************/
1199 /* Acquire NVRAM lock. */
1201 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
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_acquire_nvram_lock(struct bce_softc *sc)
1214 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1216 /* Request access to the flash interface. */
1217 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1218 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1219 val = REG_RD(sc, BCE_NVM_SW_ARB);
1220 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1226 if (j >= NVRAM_TIMEOUT_COUNT) {
1227 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1234 /****************************************************************************/
1235 /* Release NVRAM lock. */
1237 /* When the caller is finished accessing NVRAM the lock must be released. */
1238 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1239 /* for use by the driver. */
1242 /* 0 on success, positive value on failure. */
1243 /****************************************************************************/
1245 bce_release_nvram_lock(struct bce_softc *sc)
1250 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1253 * Relinquish nvram interface.
1255 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1257 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1258 val = REG_RD(sc, BCE_NVM_SW_ARB);
1259 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1265 if (j >= NVRAM_TIMEOUT_COUNT) {
1266 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1273 #ifdef BCE_NVRAM_WRITE_SUPPORT
1274 /****************************************************************************/
1275 /* Enable NVRAM write access. */
1277 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1280 /* 0 on success, positive value on failure. */
1281 /****************************************************************************/
1283 bce_enable_nvram_write(struct bce_softc *sc)
1287 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM write.\n");
1289 val = REG_RD(sc, BCE_MISC_CFG);
1290 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1292 if (!sc->bce_flash_info->buffered) {
1295 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1296 REG_WR(sc, BCE_NVM_COMMAND,
1297 BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1299 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1302 val = REG_RD(sc, BCE_NVM_COMMAND);
1303 if (val & BCE_NVM_COMMAND_DONE)
1307 if (j >= NVRAM_TIMEOUT_COUNT) {
1308 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1316 /****************************************************************************/
1317 /* Disable NVRAM write access. */
1319 /* When the caller is finished writing to NVRAM write access must be */
1324 /****************************************************************************/
1326 bce_disable_nvram_write(struct bce_softc *sc)
1330 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM write.\n");
1332 val = REG_RD(sc, BCE_MISC_CFG);
1333 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1335 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1338 /****************************************************************************/
1339 /* Enable NVRAM access. */
1341 /* Before accessing NVRAM for read or write operations the caller must */
1342 /* enabled NVRAM access. */
1346 /****************************************************************************/
1348 bce_enable_nvram_access(struct bce_softc *sc)
1352 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1354 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1355 /* Enable both bits, even on read. */
1356 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1357 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1361 /****************************************************************************/
1362 /* Disable NVRAM access. */
1364 /* When the caller is finished accessing NVRAM access must be disabled. */
1368 /****************************************************************************/
1370 bce_disable_nvram_access(struct bce_softc *sc)
1374 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1376 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1378 /* Disable both bits, even after read. */
1379 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1380 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1384 #ifdef BCE_NVRAM_WRITE_SUPPORT
1385 /****************************************************************************/
1386 /* Erase NVRAM page before writing. */
1388 /* Non-buffered flash parts require that a page be erased before it is */
1392 /* 0 on success, positive value on failure. */
1393 /****************************************************************************/
1395 bce_nvram_erase_page(struct bce_softc *sc, uint32_t offset)
1400 /* Buffered flash doesn't require an erase. */
1401 if (sc->bce_flash_info->buffered)
1404 DBPRINT(sc, BCE_VERBOSE, "Erasing NVRAM page.\n");
1406 /* Build an erase command. */
1407 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
1408 BCE_NVM_COMMAND_DOIT;
1411 * Clear the DONE bit separately, set the NVRAM adress to erase,
1412 * and issue the erase command.
1414 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1415 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1416 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1418 /* Wait for completion. */
1419 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1424 val = REG_RD(sc, BCE_NVM_COMMAND);
1425 if (val & BCE_NVM_COMMAND_DONE)
1429 if (j >= NVRAM_TIMEOUT_COUNT) {
1430 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
1435 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1438 /****************************************************************************/
1439 /* Read a dword (32 bits) from NVRAM. */
1441 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1442 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1445 /* 0 on success and the 32 bit value read, positive value on failure. */
1446 /****************************************************************************/
1448 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1454 /* Build the command word. */
1455 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1457 /* Calculate the offset for buffered flash. */
1458 if (sc->bce_flash_info->buffered) {
1459 offset = ((offset / sc->bce_flash_info->page_size) <<
1460 sc->bce_flash_info->page_bits) +
1461 (offset % sc->bce_flash_info->page_size);
1465 * Clear the DONE bit separately, set the address to read,
1466 * and issue the read.
1468 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1469 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1470 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1472 /* Wait for completion. */
1473 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1478 val = REG_RD(sc, BCE_NVM_COMMAND);
1479 if (val & BCE_NVM_COMMAND_DONE) {
1480 val = REG_RD(sc, BCE_NVM_READ);
1483 memcpy(ret_val, &val, 4);
1488 /* Check for errors. */
1489 if (i >= NVRAM_TIMEOUT_COUNT) {
1490 if_printf(&sc->arpcom.ac_if,
1491 "Timeout error reading NVRAM at offset 0x%08X!\n",
1499 #ifdef BCE_NVRAM_WRITE_SUPPORT
1500 /****************************************************************************/
1501 /* Write a dword (32 bits) to NVRAM. */
1503 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
1504 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
1505 /* enabled NVRAM write access. */
1508 /* 0 on success, positive value on failure. */
1509 /****************************************************************************/
1511 bce_nvram_write_dword(struct bce_softc *sc, uint32_t offset, uint8_t *val,
1514 uint32_t cmd, val32;
1517 /* Build the command word. */
1518 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
1520 /* Calculate the offset for buffered flash. */
1521 if (sc->bce_flash_info->buffered) {
1522 offset = ((offset / sc->bce_flash_info->page_size) <<
1523 sc->bce_flash_info->page_bits) +
1524 (offset % sc->bce_flash_info->page_size);
1528 * Clear the DONE bit separately, convert NVRAM data to big-endian,
1529 * set the NVRAM address to write, and issue the write command
1531 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1532 memcpy(&val32, val, 4);
1533 val32 = htobe32(val32);
1534 REG_WR(sc, BCE_NVM_WRITE, val32);
1535 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1536 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1538 /* Wait for completion. */
1539 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1542 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
1545 if (j >= NVRAM_TIMEOUT_COUNT) {
1546 if_printf(&sc->arpcom.ac_if,
1547 "Timeout error writing NVRAM at offset 0x%08X\n",
1553 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1556 /****************************************************************************/
1557 /* Initialize NVRAM access. */
1559 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1560 /* access that device. */
1563 /* 0 on success, positive value on failure. */
1564 /****************************************************************************/
1566 bce_init_nvram(struct bce_softc *sc)
1569 int j, entry_count, rc = 0;
1570 const struct flash_spec *flash;
1572 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1574 /* Determine the selected interface. */
1575 val = REG_RD(sc, BCE_NVM_CFG1);
1577 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1580 * Flash reconfiguration is required to support additional
1581 * NVRAM devices not directly supported in hardware.
1582 * Check if the flash interface was reconfigured
1586 if (val & 0x40000000) {
1587 /* Flash interface reconfigured by bootcode. */
1589 DBPRINT(sc, BCE_INFO_LOAD,
1590 "%s(): Flash WAS reconfigured.\n", __func__);
1592 for (j = 0, flash = flash_table; j < entry_count;
1594 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1595 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1596 sc->bce_flash_info = flash;
1601 /* Flash interface not yet reconfigured. */
1604 DBPRINT(sc, BCE_INFO_LOAD,
1605 "%s(): Flash was NOT reconfigured.\n", __func__);
1607 if (val & (1 << 23))
1608 mask = FLASH_BACKUP_STRAP_MASK;
1610 mask = FLASH_STRAP_MASK;
1612 /* Look for the matching NVRAM device configuration data. */
1613 for (j = 0, flash = flash_table; j < entry_count;
1615 /* Check if the device matches any of the known devices. */
1616 if ((val & mask) == (flash->strapping & mask)) {
1617 /* Found a device match. */
1618 sc->bce_flash_info = flash;
1620 /* Request access to the flash interface. */
1621 rc = bce_acquire_nvram_lock(sc);
1625 /* Reconfigure the flash interface. */
1626 bce_enable_nvram_access(sc);
1627 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1628 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1629 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1630 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1631 bce_disable_nvram_access(sc);
1632 bce_release_nvram_lock(sc);
1638 /* Check if a matching device was found. */
1639 if (j == entry_count) {
1640 sc->bce_flash_info = NULL;
1641 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1645 /* Write the flash config data to the shared memory interface. */
1646 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_SHARED_HW_CFG_CONFIG2) &
1647 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1649 sc->bce_flash_size = val;
1651 sc->bce_flash_size = sc->bce_flash_info->total_size;
1653 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1654 __func__, sc->bce_flash_info->total_size);
1656 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1662 /****************************************************************************/
1663 /* Read an arbitrary range of data from NVRAM. */
1665 /* Prepares the NVRAM interface for access and reads the requested data */
1666 /* into the supplied buffer. */
1669 /* 0 on success and the data read, positive value on failure. */
1670 /****************************************************************************/
1672 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1675 uint32_t cmd_flags, offset32, len32, extra;
1681 /* Request access to the flash interface. */
1682 rc = bce_acquire_nvram_lock(sc);
1686 /* Enable access to flash interface */
1687 bce_enable_nvram_access(sc);
1695 /* XXX should we release nvram lock if read_dword() fails? */
1701 pre_len = 4 - (offset & 3);
1703 if (pre_len >= len32) {
1705 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1707 cmd_flags = BCE_NVM_COMMAND_FIRST;
1710 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1714 memcpy(ret_buf, buf + (offset & 3), pre_len);
1722 extra = 4 - (len32 & 3);
1723 len32 = (len32 + 4) & ~3;
1730 cmd_flags = BCE_NVM_COMMAND_LAST;
1732 cmd_flags = BCE_NVM_COMMAND_FIRST |
1733 BCE_NVM_COMMAND_LAST;
1735 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1737 memcpy(ret_buf, buf, 4 - extra);
1738 } else if (len32 > 0) {
1741 /* Read the first word. */
1745 cmd_flags = BCE_NVM_COMMAND_FIRST;
1747 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1749 /* Advance to the next dword. */
1754 while (len32 > 4 && rc == 0) {
1755 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1757 /* Advance to the next dword. */
1766 cmd_flags = BCE_NVM_COMMAND_LAST;
1767 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1769 memcpy(ret_buf, buf, 4 - extra);
1772 /* Disable access to flash interface and release the lock. */
1773 bce_disable_nvram_access(sc);
1774 bce_release_nvram_lock(sc);
1780 #ifdef BCE_NVRAM_WRITE_SUPPORT
1781 /****************************************************************************/
1782 /* Write an arbitrary range of data from NVRAM. */
1784 /* Prepares the NVRAM interface for write access and writes the requested */
1785 /* data from the supplied buffer. The caller is responsible for */
1786 /* calculating any appropriate CRCs. */
1789 /* 0 on success, positive value on failure. */
1790 /****************************************************************************/
1792 bce_nvram_write(struct bce_softc *sc, uint32_t offset, uint8_t *data_buf,
1795 uint32_t written, offset32, len32;
1796 uint8_t *buf, start[4], end[4];
1798 int align_start, align_end;
1804 align_start = (offset32 & 3);
1808 len32 += align_start;
1809 rc = bce_nvram_read(sc, offset32, start, 4);
1815 if (len32 > 4 || !align_start) {
1816 align_end = 4 - (len32 & 3);
1818 rc = bce_nvram_read(sc, offset32 + len32 - 4, end, 4);
1824 if (align_start || align_end) {
1825 buf = kmalloc(len32, M_DEVBUF, M_NOWAIT);
1829 memcpy(buf, start, 4);
1831 memcpy(buf + len32 - 4, end, 4);
1832 memcpy(buf + align_start, data_buf, buf_size);
1836 while (written < len32 && rc == 0) {
1837 uint32_t page_start, page_end, data_start, data_end;
1838 uint32_t addr, cmd_flags;
1840 uint8_t flash_buffer[264];
1842 /* Find the page_start addr */
1843 page_start = offset32 + written;
1844 page_start -= (page_start % sc->bce_flash_info->page_size);
1845 /* Find the page_end addr */
1846 page_end = page_start + sc->bce_flash_info->page_size;
1847 /* Find the data_start addr */
1848 data_start = (written == 0) ? offset32 : page_start;
1849 /* Find the data_end addr */
1850 data_end = (page_end > offset32 + len32) ? (offset32 + len32)
1853 /* Request access to the flash interface. */
1854 rc = bce_acquire_nvram_lock(sc);
1856 goto nvram_write_end;
1858 /* Enable access to flash interface */
1859 bce_enable_nvram_access(sc);
1861 cmd_flags = BCE_NVM_COMMAND_FIRST;
1862 if (sc->bce_flash_info->buffered == 0) {
1866 * Read the whole page into the buffer
1867 * (non-buffer flash only)
1869 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
1870 if (j == (sc->bce_flash_info->page_size - 4))
1871 cmd_flags |= BCE_NVM_COMMAND_LAST;
1873 rc = bce_nvram_read_dword(sc, page_start + j,
1877 goto nvram_write_end;
1883 /* Enable writes to flash interface (unlock write-protect) */
1884 rc = bce_enable_nvram_write(sc);
1886 goto nvram_write_end;
1888 /* Erase the page */
1889 rc = bce_nvram_erase_page(sc, page_start);
1891 goto nvram_write_end;
1893 /* Re-enable the write again for the actual write */
1894 bce_enable_nvram_write(sc);
1896 /* Loop to write back the buffer data from page_start to
1899 if (sc->bce_flash_info->buffered == 0) {
1900 for (addr = page_start; addr < data_start;
1901 addr += 4, i += 4) {
1902 rc = bce_nvram_write_dword(sc, addr,
1906 goto nvram_write_end;
1912 /* Loop to write the new data from data_start to data_end */
1913 for (addr = data_start; addr < data_end; addr += 4, i++) {
1914 if (addr == page_end - 4 ||
1915 (sc->bce_flash_info->buffered &&
1916 addr == data_end - 4))
1917 cmd_flags |= BCE_NVM_COMMAND_LAST;
1919 rc = bce_nvram_write_dword(sc, addr, buf, cmd_flags);
1921 goto nvram_write_end;
1927 /* Loop to write back the buffer data from data_end
1929 if (sc->bce_flash_info->buffered == 0) {
1930 for (addr = data_end; addr < page_end;
1931 addr += 4, i += 4) {
1932 if (addr == page_end-4)
1933 cmd_flags = BCE_NVM_COMMAND_LAST;
1935 rc = bce_nvram_write_dword(sc, addr,
1936 &flash_buffer[i], cmd_flags);
1938 goto nvram_write_end;
1944 /* Disable writes to flash interface (lock write-protect) */
1945 bce_disable_nvram_write(sc);
1947 /* Disable access to flash interface */
1948 bce_disable_nvram_access(sc);
1949 bce_release_nvram_lock(sc);
1951 /* Increment written */
1952 written += data_end - data_start;
1956 if (align_start || align_end)
1957 kfree(buf, M_DEVBUF);
1960 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1963 /****************************************************************************/
1964 /* Verifies that NVRAM is accessible and contains valid data. */
1966 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1970 /* 0 on success, positive value on failure. */
1971 /****************************************************************************/
1973 bce_nvram_test(struct bce_softc *sc)
1975 uint32_t buf[BCE_NVRAM_SIZE / 4];
1976 uint32_t magic, csum;
1977 uint8_t *data = (uint8_t *)buf;
1981 * Check that the device NVRAM is valid by reading
1982 * the magic value at offset 0.
1984 rc = bce_nvram_read(sc, 0, data, 4);
1988 magic = be32toh(buf[0]);
1989 if (magic != BCE_NVRAM_MAGIC) {
1990 if_printf(&sc->arpcom.ac_if,
1991 "Invalid NVRAM magic value! Expected: 0x%08X, "
1992 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1997 * Verify that the device NVRAM includes valid
1998 * configuration data.
2000 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
2004 csum = ether_crc32_le(data, 0x100);
2005 if (csum != BCE_CRC32_RESIDUAL) {
2006 if_printf(&sc->arpcom.ac_if,
2007 "Invalid Manufacturing Information NVRAM CRC! "
2008 "Expected: 0x%08X, Found: 0x%08X\n",
2009 BCE_CRC32_RESIDUAL, csum);
2013 csum = ether_crc32_le(data + 0x100, 0x100);
2014 if (csum != BCE_CRC32_RESIDUAL) {
2015 if_printf(&sc->arpcom.ac_if,
2016 "Invalid Feature Configuration Information "
2017 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
2018 BCE_CRC32_RESIDUAL, csum);
2025 /****************************************************************************/
2026 /* Free any DMA memory owned by the driver. */
2028 /* Scans through each data structre that requires DMA memory and frees */
2029 /* the memory if allocated. */
2033 /****************************************************************************/
2035 bce_dma_free(struct bce_softc *sc)
2039 /* Destroy the status block. */
2040 if (sc->status_tag != NULL) {
2041 if (sc->status_block != NULL) {
2042 bus_dmamap_unload(sc->status_tag, sc->status_map);
2043 bus_dmamem_free(sc->status_tag, sc->status_block,
2046 bus_dma_tag_destroy(sc->status_tag);
2050 /* Destroy the statistics block. */
2051 if (sc->stats_tag != NULL) {
2052 if (sc->stats_block != NULL) {
2053 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2054 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2057 bus_dma_tag_destroy(sc->stats_tag);
2060 /* Destroy the TX buffer descriptor DMA stuffs. */
2061 if (sc->tx_bd_chain_tag != NULL) {
2062 for (i = 0; i < TX_PAGES; i++) {
2063 if (sc->tx_bd_chain[i] != NULL) {
2064 bus_dmamap_unload(sc->tx_bd_chain_tag,
2065 sc->tx_bd_chain_map[i]);
2066 bus_dmamem_free(sc->tx_bd_chain_tag,
2068 sc->tx_bd_chain_map[i]);
2071 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2074 /* Destroy the RX buffer descriptor DMA stuffs. */
2075 if (sc->rx_bd_chain_tag != NULL) {
2076 for (i = 0; i < RX_PAGES; i++) {
2077 if (sc->rx_bd_chain[i] != NULL) {
2078 bus_dmamap_unload(sc->rx_bd_chain_tag,
2079 sc->rx_bd_chain_map[i]);
2080 bus_dmamem_free(sc->rx_bd_chain_tag,
2082 sc->rx_bd_chain_map[i]);
2085 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2088 /* Destroy the TX mbuf DMA stuffs. */
2089 if (sc->tx_mbuf_tag != NULL) {
2090 for (i = 0; i < TOTAL_TX_BD; i++) {
2091 /* Must have been unloaded in bce_stop() */
2092 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2093 bus_dmamap_destroy(sc->tx_mbuf_tag,
2094 sc->tx_mbuf_map[i]);
2096 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2099 /* Destroy the RX mbuf DMA stuffs. */
2100 if (sc->rx_mbuf_tag != NULL) {
2101 for (i = 0; i < TOTAL_RX_BD; i++) {
2102 /* Must have been unloaded in bce_stop() */
2103 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2104 bus_dmamap_destroy(sc->rx_mbuf_tag,
2105 sc->rx_mbuf_map[i]);
2107 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2110 /* Destroy the parent tag */
2111 if (sc->parent_tag != NULL)
2112 bus_dma_tag_destroy(sc->parent_tag);
2116 /****************************************************************************/
2117 /* Get DMA memory from the OS. */
2119 /* Validates that the OS has provided DMA buffers in response to a */
2120 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2121 /* When the callback is used the OS will return 0 for the mapping function */
2122 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2123 /* failures back to the caller. */
2127 /****************************************************************************/
2129 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2131 bus_addr_t *busaddr = arg;
2134 * Simulate a mapping failure.
2137 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2138 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2139 __FILE__, __LINE__);
2142 /* Check for an error and signal the caller that an error occurred. */
2146 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2147 *busaddr = segs->ds_addr;
2152 bce_dma_map_mbuf(void *arg, bus_dma_segment_t *segs, int nsegs,
2153 bus_size_t mapsz __unused, int error)
2155 struct bce_dmamap_arg *ctx = arg;
2161 if (nsegs > ctx->bce_maxsegs) {
2162 ctx->bce_maxsegs = 0;
2166 ctx->bce_maxsegs = nsegs;
2167 for (i = 0; i < nsegs; ++i)
2168 ctx->bce_segs[i] = segs[i];
2172 /****************************************************************************/
2173 /* Allocate any DMA memory needed by the driver. */
2175 /* Allocates DMA memory needed for the various global structures needed by */
2179 /* 0 for success, positive value for failure. */
2180 /****************************************************************************/
2182 bce_dma_alloc(struct bce_softc *sc)
2184 struct ifnet *ifp = &sc->arpcom.ac_if;
2189 * Allocate the parent bus DMA tag appropriate for PCI.
2191 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2192 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2194 MAXBSIZE, BUS_SPACE_UNRESTRICTED,
2195 BUS_SPACE_MAXSIZE_32BIT,
2196 0, &sc->parent_tag);
2198 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2203 * Create a DMA tag for the status block, allocate and clear the
2204 * memory, map the memory into DMA space, and fetch the physical
2205 * address of the block.
2207 rc = bus_dma_tag_create(sc->parent_tag,
2208 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2209 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2211 BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
2212 0, &sc->status_tag);
2214 if_printf(ifp, "Could not allocate status block DMA tag!\n");
2218 rc = bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
2219 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2222 if_printf(ifp, "Could not allocate status block DMA memory!\n");
2226 rc = bus_dmamap_load(sc->status_tag, sc->status_map,
2227 sc->status_block, BCE_STATUS_BLK_SZ,
2228 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2230 if_printf(ifp, "Could not map status block DMA memory!\n");
2231 bus_dmamem_free(sc->status_tag, sc->status_block,
2233 sc->status_block = NULL;
2237 sc->status_block_paddr = busaddr;
2238 /* DRC - Fix for 64 bit addresses. */
2239 DBPRINT(sc, BCE_INFO, "status_block_paddr = 0x%08X\n",
2240 (uint32_t)sc->status_block_paddr);
2243 * Create a DMA tag for the statistics block, allocate and clear the
2244 * memory, map the memory into DMA space, and fetch the physical
2245 * address of the block.
2247 rc = bus_dma_tag_create(sc->parent_tag,
2248 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2249 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2251 BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
2254 if_printf(ifp, "Could not allocate "
2255 "statistics block DMA tag!\n");
2259 rc = bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
2260 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2263 if_printf(ifp, "Could not allocate "
2264 "statistics block DMA memory!\n");
2268 rc = bus_dmamap_load(sc->stats_tag, sc->stats_map,
2269 sc->stats_block, BCE_STATS_BLK_SZ,
2270 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2272 if_printf(ifp, "Could not map statistics block DMA memory!\n");
2273 bus_dmamem_free(sc->stats_tag, sc->stats_block, sc->stats_map);
2274 sc->stats_block = NULL;
2278 sc->stats_block_paddr = busaddr;
2279 /* DRC - Fix for 64 bit address. */
2280 DBPRINT(sc, BCE_INFO, "stats_block_paddr = 0x%08X\n",
2281 (uint32_t)sc->stats_block_paddr);
2284 * Create a DMA tag for the TX buffer descriptor chain,
2285 * allocate and clear the memory, and fetch the
2286 * physical address of the block.
2288 rc = bus_dma_tag_create(sc->parent_tag,
2289 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2290 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2292 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2293 0, &sc->tx_bd_chain_tag);
2295 if_printf(ifp, "Could not allocate "
2296 "TX descriptor chain DMA tag!\n");
2300 for (i = 0; i < TX_PAGES; i++) {
2301 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2302 (void **)&sc->tx_bd_chain[i],
2303 BUS_DMA_WAITOK, &sc->tx_bd_chain_map[i]);
2305 if_printf(ifp, "Could not allocate %dth TX descriptor "
2306 "chain DMA memory!\n", i);
2310 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2311 sc->tx_bd_chain_map[i],
2312 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2313 bce_dma_map_addr, &busaddr,
2316 if_printf(ifp, "Could not map %dth TX descriptor "
2317 "chain DMA memory!\n", i);
2318 bus_dmamem_free(sc->tx_bd_chain_tag,
2320 sc->tx_bd_chain_map[i]);
2321 sc->tx_bd_chain[i] = NULL;
2325 sc->tx_bd_chain_paddr[i] = busaddr;
2326 /* DRC - Fix for 64 bit systems. */
2327 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2328 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2331 /* Create a DMA tag for TX mbufs. */
2332 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2333 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2335 MCLBYTES * BCE_MAX_SEGMENTS,
2336 BCE_MAX_SEGMENTS, MCLBYTES,
2337 0, &sc->tx_mbuf_tag);
2339 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2343 /* Create DMA maps for the TX mbufs clusters. */
2344 for (i = 0; i < TOTAL_TX_BD; i++) {
2345 rc = bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_WAITOK,
2346 &sc->tx_mbuf_map[i]);
2348 for (j = 0; j < i; ++j) {
2349 bus_dmamap_destroy(sc->tx_mbuf_tag,
2350 sc->tx_mbuf_map[i]);
2352 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2353 sc->tx_mbuf_tag = NULL;
2355 if_printf(ifp, "Unable to create "
2356 "%dth TX mbuf DMA map!\n", i);
2362 * Create a DMA tag for the RX buffer descriptor chain,
2363 * allocate and clear the memory, and fetch the physical
2364 * address of the blocks.
2366 rc = bus_dma_tag_create(sc->parent_tag,
2367 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2368 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2370 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2371 0, &sc->rx_bd_chain_tag);
2373 if_printf(ifp, "Could not allocate "
2374 "RX descriptor chain DMA tag!\n");
2378 for (i = 0; i < RX_PAGES; i++) {
2379 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2380 (void **)&sc->rx_bd_chain[i],
2381 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2382 &sc->rx_bd_chain_map[i]);
2384 if_printf(ifp, "Could not allocate %dth RX descriptor "
2385 "chain DMA memory!\n", i);
2389 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2390 sc->rx_bd_chain_map[i],
2391 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2392 bce_dma_map_addr, &busaddr,
2395 if_printf(ifp, "Could not map %dth RX descriptor "
2396 "chain DMA memory!\n", i);
2397 bus_dmamem_free(sc->rx_bd_chain_tag,
2399 sc->rx_bd_chain_map[i]);
2400 sc->rx_bd_chain[i] = NULL;
2404 sc->rx_bd_chain_paddr[i] = busaddr;
2405 /* DRC - Fix for 64 bit systems. */
2406 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2407 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2410 /* Create a DMA tag for RX mbufs. */
2411 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2412 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2414 MCLBYTES, 1/* BCE_MAX_SEGMENTS */, MCLBYTES,
2415 0, &sc->rx_mbuf_tag);
2417 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2421 /* Create DMA maps for the RX mbuf clusters. */
2422 for (i = 0; i < TOTAL_RX_BD; i++) {
2423 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2424 &sc->rx_mbuf_map[i]);
2426 for (j = 0; j < i; ++j) {
2427 bus_dmamap_destroy(sc->rx_mbuf_tag,
2428 sc->rx_mbuf_map[j]);
2430 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2431 sc->rx_mbuf_tag = NULL;
2433 if_printf(ifp, "Unable to create "
2434 "%dth RX mbuf DMA map!\n", i);
2442 /****************************************************************************/
2443 /* Firmware synchronization. */
2445 /* Before performing certain events such as a chip reset, synchronize with */
2446 /* the firmware first. */
2449 /* 0 for success, positive value for failure. */
2450 /****************************************************************************/
2452 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2457 /* Don't waste any time if we've timed out before. */
2458 if (sc->bce_fw_timed_out)
2461 /* Increment the message sequence number. */
2462 sc->bce_fw_wr_seq++;
2463 msg_data |= sc->bce_fw_wr_seq;
2465 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2467 /* Send the message to the bootcode driver mailbox. */
2468 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2470 /* Wait for the bootcode to acknowledge the message. */
2471 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2472 /* Check for a response in the bootcode firmware mailbox. */
2473 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_FW_MB);
2474 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2479 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2480 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2481 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2482 if_printf(&sc->arpcom.ac_if,
2483 "Firmware synchronization timeout! "
2484 "msg_data = 0x%08X\n", msg_data);
2486 msg_data &= ~BCE_DRV_MSG_CODE;
2487 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2489 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2491 sc->bce_fw_timed_out = 1;
2498 /****************************************************************************/
2499 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2503 /****************************************************************************/
2505 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2506 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2511 for (i = 0; i < rv2p_code_len; i += 8) {
2512 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2514 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2517 if (rv2p_proc == RV2P_PROC1) {
2518 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2519 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2521 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2522 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2526 /* Reset the processor, un-stall is done later. */
2527 if (rv2p_proc == RV2P_PROC1)
2528 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2530 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2534 /****************************************************************************/
2535 /* Load RISC processor firmware. */
2537 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2538 /* associated with a particular processor. */
2542 /****************************************************************************/
2544 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2547 uint32_t offset, val;
2551 val = REG_RD_IND(sc, cpu_reg->mode);
2552 val |= cpu_reg->mode_value_halt;
2553 REG_WR_IND(sc, cpu_reg->mode, val);
2554 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2556 /* Load the Text area. */
2557 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2559 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2560 REG_WR_IND(sc, offset, fw->text[j]);
2563 /* Load the Data area. */
2564 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2566 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2567 REG_WR_IND(sc, offset, fw->data[j]);
2570 /* Load the SBSS area. */
2571 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2573 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2574 REG_WR_IND(sc, offset, fw->sbss[j]);
2577 /* Load the BSS area. */
2578 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2580 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2581 REG_WR_IND(sc, offset, fw->bss[j]);
2584 /* Load the Read-Only area. */
2585 offset = cpu_reg->spad_base +
2586 (fw->rodata_addr - cpu_reg->mips_view_base);
2588 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2589 REG_WR_IND(sc, offset, fw->rodata[j]);
2592 /* Clear the pre-fetch instruction. */
2593 REG_WR_IND(sc, cpu_reg->inst, 0);
2594 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2596 /* Start the CPU. */
2597 val = REG_RD_IND(sc, cpu_reg->mode);
2598 val &= ~cpu_reg->mode_value_halt;
2599 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2600 REG_WR_IND(sc, cpu_reg->mode, val);
2604 /****************************************************************************/
2605 /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs. */
2607 /* Loads the firmware for each CPU and starts the CPU. */
2611 /****************************************************************************/
2613 bce_init_cpus(struct bce_softc *sc)
2615 struct cpu_reg cpu_reg;
2618 /* Initialize the RV2P processor. */
2619 bce_load_rv2p_fw(sc, bce_rv2p_proc1, sizeof(bce_rv2p_proc1), RV2P_PROC1);
2620 bce_load_rv2p_fw(sc, bce_rv2p_proc2, sizeof(bce_rv2p_proc2), RV2P_PROC2);
2622 /* Initialize the RX Processor. */
2623 cpu_reg.mode = BCE_RXP_CPU_MODE;
2624 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2625 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2626 cpu_reg.state = BCE_RXP_CPU_STATE;
2627 cpu_reg.state_value_clear = 0xffffff;
2628 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2629 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2630 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2631 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2632 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2633 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2634 cpu_reg.mips_view_base = 0x8000000;
2636 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2637 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2638 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2639 fw.start_addr = bce_RXP_b06FwStartAddr;
2641 fw.text_addr = bce_RXP_b06FwTextAddr;
2642 fw.text_len = bce_RXP_b06FwTextLen;
2644 fw.text = bce_RXP_b06FwText;
2646 fw.data_addr = bce_RXP_b06FwDataAddr;
2647 fw.data_len = bce_RXP_b06FwDataLen;
2649 fw.data = bce_RXP_b06FwData;
2651 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2652 fw.sbss_len = bce_RXP_b06FwSbssLen;
2654 fw.sbss = bce_RXP_b06FwSbss;
2656 fw.bss_addr = bce_RXP_b06FwBssAddr;
2657 fw.bss_len = bce_RXP_b06FwBssLen;
2659 fw.bss = bce_RXP_b06FwBss;
2661 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2662 fw.rodata_len = bce_RXP_b06FwRodataLen;
2663 fw.rodata_index = 0;
2664 fw.rodata = bce_RXP_b06FwRodata;
2666 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2667 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2669 /* Initialize the TX Processor. */
2670 cpu_reg.mode = BCE_TXP_CPU_MODE;
2671 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2672 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2673 cpu_reg.state = BCE_TXP_CPU_STATE;
2674 cpu_reg.state_value_clear = 0xffffff;
2675 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2676 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2677 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2678 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2679 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2680 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2681 cpu_reg.mips_view_base = 0x8000000;
2683 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2684 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2685 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2686 fw.start_addr = bce_TXP_b06FwStartAddr;
2688 fw.text_addr = bce_TXP_b06FwTextAddr;
2689 fw.text_len = bce_TXP_b06FwTextLen;
2691 fw.text = bce_TXP_b06FwText;
2693 fw.data_addr = bce_TXP_b06FwDataAddr;
2694 fw.data_len = bce_TXP_b06FwDataLen;
2696 fw.data = bce_TXP_b06FwData;
2698 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2699 fw.sbss_len = bce_TXP_b06FwSbssLen;
2701 fw.sbss = bce_TXP_b06FwSbss;
2703 fw.bss_addr = bce_TXP_b06FwBssAddr;
2704 fw.bss_len = bce_TXP_b06FwBssLen;
2706 fw.bss = bce_TXP_b06FwBss;
2708 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2709 fw.rodata_len = bce_TXP_b06FwRodataLen;
2710 fw.rodata_index = 0;
2711 fw.rodata = bce_TXP_b06FwRodata;
2713 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2714 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2716 /* Initialize the TX Patch-up Processor. */
2717 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2718 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2719 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2720 cpu_reg.state = BCE_TPAT_CPU_STATE;
2721 cpu_reg.state_value_clear = 0xffffff;
2722 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2723 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2724 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2725 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2726 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2727 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2728 cpu_reg.mips_view_base = 0x8000000;
2730 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2731 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2732 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2733 fw.start_addr = bce_TPAT_b06FwStartAddr;
2735 fw.text_addr = bce_TPAT_b06FwTextAddr;
2736 fw.text_len = bce_TPAT_b06FwTextLen;
2738 fw.text = bce_TPAT_b06FwText;
2740 fw.data_addr = bce_TPAT_b06FwDataAddr;
2741 fw.data_len = bce_TPAT_b06FwDataLen;
2743 fw.data = bce_TPAT_b06FwData;
2745 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2746 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2748 fw.sbss = bce_TPAT_b06FwSbss;
2750 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2751 fw.bss_len = bce_TPAT_b06FwBssLen;
2753 fw.bss = bce_TPAT_b06FwBss;
2755 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2756 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2757 fw.rodata_index = 0;
2758 fw.rodata = bce_TPAT_b06FwRodata;
2760 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2761 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2763 /* Initialize the Completion Processor. */
2764 cpu_reg.mode = BCE_COM_CPU_MODE;
2765 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
2766 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
2767 cpu_reg.state = BCE_COM_CPU_STATE;
2768 cpu_reg.state_value_clear = 0xffffff;
2769 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
2770 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
2771 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
2772 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
2773 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
2774 cpu_reg.spad_base = BCE_COM_SCRATCH;
2775 cpu_reg.mips_view_base = 0x8000000;
2777 fw.ver_major = bce_COM_b06FwReleaseMajor;
2778 fw.ver_minor = bce_COM_b06FwReleaseMinor;
2779 fw.ver_fix = bce_COM_b06FwReleaseFix;
2780 fw.start_addr = bce_COM_b06FwStartAddr;
2782 fw.text_addr = bce_COM_b06FwTextAddr;
2783 fw.text_len = bce_COM_b06FwTextLen;
2785 fw.text = bce_COM_b06FwText;
2787 fw.data_addr = bce_COM_b06FwDataAddr;
2788 fw.data_len = bce_COM_b06FwDataLen;
2790 fw.data = bce_COM_b06FwData;
2792 fw.sbss_addr = bce_COM_b06FwSbssAddr;
2793 fw.sbss_len = bce_COM_b06FwSbssLen;
2795 fw.sbss = bce_COM_b06FwSbss;
2797 fw.bss_addr = bce_COM_b06FwBssAddr;
2798 fw.bss_len = bce_COM_b06FwBssLen;
2800 fw.bss = bce_COM_b06FwBss;
2802 fw.rodata_addr = bce_COM_b06FwRodataAddr;
2803 fw.rodata_len = bce_COM_b06FwRodataLen;
2804 fw.rodata_index = 0;
2805 fw.rodata = bce_COM_b06FwRodata;
2807 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
2808 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2812 /****************************************************************************/
2813 /* Initialize context memory. */
2815 /* Clears the memory associated with each Context ID (CID). */
2819 /****************************************************************************/
2821 bce_init_ctx(struct bce_softc *sc)
2826 uint32_t vcid_addr, pcid_addr, offset;
2831 vcid_addr = GET_CID_ADDR(vcid);
2832 pcid_addr = vcid_addr;
2834 for (i = 0; i < (CTX_SIZE / PHY_CTX_SIZE); i++) {
2835 vcid_addr += (i << PHY_CTX_SHIFT);
2836 pcid_addr += (i << PHY_CTX_SHIFT);
2838 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
2839 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2841 /* Zero out the context. */
2842 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
2843 CTX_WR(sc, vcid_addr, offset, 0);
2849 /****************************************************************************/
2850 /* Fetch the permanent MAC address of the controller. */
2854 /****************************************************************************/
2856 bce_get_mac_addr(struct bce_softc *sc)
2858 uint32_t mac_lo = 0, mac_hi = 0;
2861 * The NetXtreme II bootcode populates various NIC
2862 * power-on and runtime configuration items in a
2863 * shared memory area. The factory configured MAC
2864 * address is available from both NVRAM and the
2865 * shared memory area so we'll read the value from
2866 * shared memory for speed.
2869 mac_hi = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_UPPER);
2870 mac_lo = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_LOWER);
2872 if (mac_lo == 0 && mac_hi == 0) {
2873 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
2875 sc->eaddr[0] = (u_char)(mac_hi >> 8);
2876 sc->eaddr[1] = (u_char)(mac_hi >> 0);
2877 sc->eaddr[2] = (u_char)(mac_lo >> 24);
2878 sc->eaddr[3] = (u_char)(mac_lo >> 16);
2879 sc->eaddr[4] = (u_char)(mac_lo >> 8);
2880 sc->eaddr[5] = (u_char)(mac_lo >> 0);
2883 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
2887 /****************************************************************************/
2888 /* Program the MAC address. */
2892 /****************************************************************************/
2894 bce_set_mac_addr(struct bce_softc *sc)
2896 const uint8_t *mac_addr = sc->eaddr;
2899 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
2902 val = (mac_addr[0] << 8) | mac_addr[1];
2903 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
2905 val = (mac_addr[2] << 24) |
2906 (mac_addr[3] << 16) |
2907 (mac_addr[4] << 8) |
2909 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
2913 /****************************************************************************/
2914 /* Stop the controller. */
2918 /****************************************************************************/
2920 bce_stop(struct bce_softc *sc)
2922 struct ifnet *ifp = &sc->arpcom.ac_if;
2923 struct mii_data *mii = device_get_softc(sc->bce_miibus);
2924 struct ifmedia_entry *ifm;
2927 ASSERT_SERIALIZED(ifp->if_serializer);
2929 callout_stop(&sc->bce_stat_ch);
2931 /* Disable the transmit/receive blocks. */
2932 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, 0x5ffffff);
2933 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2936 bce_disable_intr(sc);
2938 /* Tell firmware that the driver is going away. */
2939 bce_reset(sc, BCE_DRV_MSG_CODE_SUSPEND_NO_WOL);
2941 /* Free the RX lists. */
2942 bce_free_rx_chain(sc);
2944 /* Free TX buffers. */
2945 bce_free_tx_chain(sc);
2948 * Isolate/power down the PHY, but leave the media selection
2949 * unchanged so that things will be put back to normal when
2950 * we bring the interface back up.
2952 * 'mii' may be NULL if bce_stop() is called by bce_detach().
2955 itmp = ifp->if_flags;
2956 ifp->if_flags |= IFF_UP;
2957 ifm = mii->mii_media.ifm_cur;
2958 mtmp = ifm->ifm_media;
2959 ifm->ifm_media = IFM_ETHER | IFM_NONE;
2961 ifm->ifm_media = mtmp;
2962 ifp->if_flags = itmp;
2966 sc->bce_coalchg_mask = 0;
2968 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2976 bce_reset(struct bce_softc *sc, uint32_t reset_code)
2981 /* Wait for pending PCI transactions to complete. */
2982 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
2983 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
2984 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
2985 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
2986 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
2987 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2990 /* Assume bootcode is running. */
2991 sc->bce_fw_timed_out = 0;
2993 /* Give the firmware a chance to prepare for the reset. */
2994 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
2996 if_printf(&sc->arpcom.ac_if,
2997 "Firmware is not ready for reset\n");
3001 /* Set a firmware reminder that this is a soft reset. */
3002 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_RESET_SIGNATURE,
3003 BCE_DRV_RESET_SIGNATURE_MAGIC);
3005 /* Dummy read to force the chip to complete all current transactions. */
3006 val = REG_RD(sc, BCE_MISC_ID);
3009 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3010 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3011 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3012 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3014 /* Allow up to 30us for reset to complete. */
3015 for (i = 0; i < 10; i++) {
3016 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3017 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3018 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
3024 /* Check that reset completed successfully. */
3025 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3026 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3027 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3031 /* Make sure byte swapping is properly configured. */
3032 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3033 if (val != 0x01020304) {
3034 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3038 /* Just completed a reset, assume that firmware is running again. */
3039 sc->bce_fw_timed_out = 0;
3041 /* Wait for the firmware to finish its initialization. */
3042 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3044 if_printf(&sc->arpcom.ac_if,
3045 "Firmware did not complete initialization!\n");
3052 bce_chipinit(struct bce_softc *sc)
3057 /* Make sure the interrupt is not active. */
3058 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3061 * Initialize DMA byte/word swapping, configure the number of DMA
3062 * channels and PCI clock compensation delay.
3064 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3065 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3066 #if BYTE_ORDER == BIG_ENDIAN
3067 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3069 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3070 DMA_READ_CHANS << 12 |
3071 DMA_WRITE_CHANS << 16;
3073 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3075 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3076 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3079 * This setting resolves a problem observed on certain Intel PCI
3080 * chipsets that cannot handle multiple outstanding DMA operations.
3081 * See errata E9_5706A1_65.
3083 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3084 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3085 !(sc->bce_flags & BCE_PCIX_FLAG))
3086 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3088 REG_WR(sc, BCE_DMA_CONFIG, val);
3090 /* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
3091 if (sc->bce_flags & BCE_PCIX_FLAG) {
3094 cmd = pci_read_config(sc->bce_dev, BCE_PCI_PCIX_CMD, 2);
3095 pci_write_config(sc->bce_dev, BCE_PCI_PCIX_CMD, cmd & ~0x2, 2);
3098 /* Enable the RX_V2P and Context state machines before access. */
3099 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3100 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3101 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3102 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3104 /* Initialize context mapping and zero out the quick contexts. */
3107 /* Initialize the on-boards CPUs */
3110 /* Prepare NVRAM for access. */
3111 rc = bce_init_nvram(sc);
3115 /* Set the kernel bypass block size */
3116 val = REG_RD(sc, BCE_MQ_CONFIG);
3117 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3118 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3119 REG_WR(sc, BCE_MQ_CONFIG, val);
3121 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3122 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3123 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3125 /* Set the page size and clear the RV2P processor stall bits. */
3126 val = (BCM_PAGE_BITS - 8) << 24;
3127 REG_WR(sc, BCE_RV2P_CONFIG, val);
3129 /* Configure page size. */
3130 val = REG_RD(sc, BCE_TBDR_CONFIG);
3131 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3132 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3133 REG_WR(sc, BCE_TBDR_CONFIG, val);
3139 /****************************************************************************/
3140 /* Initialize the controller in preparation to send/receive traffic. */
3143 /* 0 for success, positive value for failure. */
3144 /****************************************************************************/
3146 bce_blockinit(struct bce_softc *sc)
3151 /* Load the hardware default MAC address. */
3152 bce_set_mac_addr(sc);
3154 /* Set the Ethernet backoff seed value */
3155 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3156 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3157 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3159 sc->last_status_idx = 0;
3160 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3162 /* Set up link change interrupt generation. */
3163 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3165 /* Program the physical address of the status block. */
3166 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3167 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3169 /* Program the physical address of the statistics block. */
3170 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3171 BCE_ADDR_LO(sc->stats_block_paddr));
3172 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3173 BCE_ADDR_HI(sc->stats_block_paddr));
3175 /* Program various host coalescing parameters. */
3176 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3177 (sc->bce_tx_quick_cons_trip_int << 16) |
3178 sc->bce_tx_quick_cons_trip);
3179 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3180 (sc->bce_rx_quick_cons_trip_int << 16) |
3181 sc->bce_rx_quick_cons_trip);
3182 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3183 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3184 REG_WR(sc, BCE_HC_TX_TICKS,
3185 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3186 REG_WR(sc, BCE_HC_RX_TICKS,
3187 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3188 REG_WR(sc, BCE_HC_COM_TICKS,
3189 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3190 REG_WR(sc, BCE_HC_CMD_TICKS,
3191 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3192 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3193 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3194 REG_WR(sc, BCE_HC_CONFIG,
3195 BCE_HC_CONFIG_RX_TMR_MODE |
3196 BCE_HC_CONFIG_TX_TMR_MODE |
3197 BCE_HC_CONFIG_COLLECT_STATS);
3199 /* Clear the internal statistics counters. */
3200 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3202 /* Verify that bootcode is running. */
3203 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_SIGNATURE);
3205 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3206 if_printf(&sc->arpcom.ac_if,
3207 "%s(%d): Simulating bootcode failure.\n",
3208 __FILE__, __LINE__);
3211 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3212 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3213 if_printf(&sc->arpcom.ac_if,
3214 "Bootcode not running! Found: 0x%08X, "
3215 "Expected: 08%08X\n",
3216 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3217 BCE_DEV_INFO_SIGNATURE_MAGIC);
3221 /* Check if any management firmware is running. */
3222 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_FEATURE);
3223 if (reg & (BCE_PORT_FEATURE_ASF_ENABLED |
3224 BCE_PORT_FEATURE_IMD_ENABLED)) {
3225 DBPRINT(sc, BCE_INFO, "Management F/W Enabled.\n");
3226 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
3230 REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_BC_REV);
3231 DBPRINT(sc, BCE_INFO, "bootcode rev = 0x%08X\n", sc->bce_fw_ver);
3233 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3234 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3236 /* Enable link state change interrupt generation. */
3237 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3239 /* Enable all remaining blocks in the MAC. */
3240 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, 0x5ffffff);
3241 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3248 /****************************************************************************/
3249 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3251 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3252 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3256 /* 0 for success, positive value for failure. */
3257 /****************************************************************************/
3259 bce_newbuf_std(struct bce_softc *sc, struct mbuf *m,
3260 uint16_t *prod, uint16_t *chain_prod, uint32_t *prod_bseq)
3263 struct bce_dmamap_arg ctx;
3264 bus_dma_segment_t seg;
3269 uint16_t debug_chain_prod = *chain_prod;
3272 /* Make sure the inputs are valid. */
3273 DBRUNIF((*chain_prod > MAX_RX_BD),
3274 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3275 "RX producer out of range: 0x%04X > 0x%04X\n",
3277 *chain_prod, (uint16_t)MAX_RX_BD));
3279 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3280 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3283 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3284 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3285 "Simulating mbuf allocation failure.\n",
3286 __FILE__, __LINE__);
3287 sc->mbuf_alloc_failed++;
3290 /* This is a new mbuf allocation. */
3291 m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3294 DBRUNIF(1, sc->rx_mbuf_alloc++);
3297 m_new->m_data = m_new->m_ext.ext_buf;
3299 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3301 /* Map the mbuf cluster into device memory. */
3302 map = sc->rx_mbuf_map[*chain_prod];
3304 ctx.bce_maxsegs = 1;
3305 ctx.bce_segs = &seg;
3306 error = bus_dmamap_load_mbuf(sc->rx_mbuf_tag, map, m_new,
3307 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
3308 if (error || ctx.bce_maxsegs == 0) {
3309 if_printf(&sc->arpcom.ac_if,
3310 "Error mapping mbuf into RX chain!\n");
3315 DBRUNIF(1, sc->rx_mbuf_alloc--);
3319 /* Watch for overflow. */
3320 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3321 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3322 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3323 __FILE__, __LINE__, sc->free_rx_bd,
3324 (uint16_t)USABLE_RX_BD));
3326 /* Update some debug statistic counters */
3327 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3328 sc->rx_low_watermark = sc->free_rx_bd);
3329 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3331 /* Setup the rx_bd for the first segment. */
3332 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3334 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(seg.ds_addr));
3335 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(seg.ds_addr));
3336 rxbd->rx_bd_len = htole32(seg.ds_len);
3337 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3338 *prod_bseq += seg.ds_len;
3340 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3342 /* Save the mbuf and update our counter. */
3343 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3346 DBRUN(BCE_VERBOSE_RECV,
3347 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3349 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3350 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3356 /****************************************************************************/
3357 /* Allocate memory and initialize the TX data structures. */
3360 /* 0 for success, positive value for failure. */
3361 /****************************************************************************/
3363 bce_init_tx_chain(struct bce_softc *sc)
3369 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3371 /* Set the initial TX producer/consumer indices. */
3374 sc->tx_prod_bseq = 0;
3376 sc->max_tx_bd = USABLE_TX_BD;
3377 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3378 DBRUNIF(1, sc->tx_full_count = 0);
3381 * The NetXtreme II supports a linked-list structre called
3382 * a Buffer Descriptor Chain (or BD chain). A BD chain
3383 * consists of a series of 1 or more chain pages, each of which
3384 * consists of a fixed number of BD entries.
3385 * The last BD entry on each page is a pointer to the next page
3386 * in the chain, and the last pointer in the BD chain
3387 * points back to the beginning of the chain.
3390 /* Set the TX next pointer chain entries. */
3391 for (i = 0; i < TX_PAGES; i++) {
3394 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3396 /* Check if we've reached the last page. */
3397 if (i == (TX_PAGES - 1))
3402 txbd->tx_bd_haddr_hi =
3403 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3404 txbd->tx_bd_haddr_lo =
3405 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3408 for (i = 0; i < TX_PAGES; ++i) {
3409 bus_dmamap_sync(sc->tx_bd_chain_tag, sc->tx_bd_chain_map[i],
3410 BUS_DMASYNC_PREWRITE);
3413 /* Initialize the context ID for an L2 TX chain. */
3414 val = BCE_L2CTX_TYPE_TYPE_L2;
3415 val |= BCE_L2CTX_TYPE_SIZE_L2;
3416 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TYPE, val);
3418 val = BCE_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
3419 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_CMD_TYPE, val);
3421 /* Point the hardware to the first page in the chain. */
3422 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3423 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_HI, val);
3424 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3425 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_LO, val);
3427 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
3429 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3435 /****************************************************************************/
3436 /* Free memory and clear the TX data structures. */
3440 /****************************************************************************/
3442 bce_free_tx_chain(struct bce_softc *sc)
3446 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3448 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3449 for (i = 0; i < TOTAL_TX_BD; i++) {
3450 if (sc->tx_mbuf_ptr[i] != NULL) {
3451 bus_dmamap_sync(sc->tx_mbuf_tag, sc->tx_mbuf_map[i],
3452 BUS_DMASYNC_POSTWRITE);
3453 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3454 m_freem(sc->tx_mbuf_ptr[i]);
3455 sc->tx_mbuf_ptr[i] = NULL;
3456 DBRUNIF(1, sc->tx_mbuf_alloc--);
3460 /* Clear each TX chain page. */
3461 for (i = 0; i < TX_PAGES; i++)
3462 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3465 /* Check if we lost any mbufs in the process. */
3466 DBRUNIF((sc->tx_mbuf_alloc),
3467 if_printf(&sc->arpcom.ac_if,
3468 "%s(%d): Memory leak! "
3469 "Lost %d mbufs from tx chain!\n",
3470 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3472 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3476 /****************************************************************************/
3477 /* Allocate memory and initialize the RX data structures. */
3480 /* 0 for success, positive value for failure. */
3481 /****************************************************************************/
3483 bce_init_rx_chain(struct bce_softc *sc)
3487 uint16_t prod, chain_prod;
3488 uint32_t prod_bseq, val;
3490 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3492 /* Initialize the RX producer and consumer indices. */
3495 sc->rx_prod_bseq = 0;
3496 sc->free_rx_bd = USABLE_RX_BD;
3497 sc->max_rx_bd = USABLE_RX_BD;
3498 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3499 DBRUNIF(1, sc->rx_empty_count = 0);
3501 /* Initialize the RX next pointer chain entries. */
3502 for (i = 0; i < RX_PAGES; i++) {
3505 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3507 /* Check if we've reached the last page. */
3508 if (i == (RX_PAGES - 1))
3513 /* Setup the chain page pointers. */
3514 rxbd->rx_bd_haddr_hi =
3515 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
3516 rxbd->rx_bd_haddr_lo =
3517 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
3520 /* Initialize the context ID for an L2 RX chain. */
3521 val = BCE_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3522 val |= BCE_L2CTX_CTX_TYPE_SIZE_L2;
3524 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_CTX_TYPE, val);
3526 /* Point the hardware to the first page in the chain. */
3527 /* XXX shouldn't this after RX descriptor initialization? */
3528 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3529 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_HI, val);
3530 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3531 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_LO, val);
3533 /* Allocate mbuf clusters for the rx_bd chain. */
3534 prod = prod_bseq = 0;
3535 while (prod < TOTAL_RX_BD) {
3536 chain_prod = RX_CHAIN_IDX(prod);
3537 if (bce_newbuf_std(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
3538 if_printf(&sc->arpcom.ac_if,
3539 "Error filling RX chain: rx_bd[0x%04X]!\n",
3544 prod = NEXT_RX_BD(prod);
3547 /* Save the RX chain producer index. */
3549 sc->rx_prod_bseq = prod_bseq;
3551 for (i = 0; i < RX_PAGES; i++) {
3552 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
3553 BUS_DMASYNC_PREWRITE);
3556 /* Tell the chip about the waiting rx_bd's. */
3557 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3558 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3560 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_chain(sc, 0, TOTAL_RX_BD));
3562 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3568 /****************************************************************************/
3569 /* Free memory and clear the RX data structures. */
3573 /****************************************************************************/
3575 bce_free_rx_chain(struct bce_softc *sc)
3579 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3581 /* Free any mbufs still in the RX mbuf chain. */
3582 for (i = 0; i < TOTAL_RX_BD; i++) {
3583 if (sc->rx_mbuf_ptr[i] != NULL) {
3584 bus_dmamap_sync(sc->rx_mbuf_tag, sc->rx_mbuf_map[i],
3585 BUS_DMASYNC_POSTREAD);
3586 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
3587 m_freem(sc->rx_mbuf_ptr[i]);
3588 sc->rx_mbuf_ptr[i] = NULL;
3589 DBRUNIF(1, sc->rx_mbuf_alloc--);
3593 /* Clear each RX chain page. */
3594 for (i = 0; i < RX_PAGES; i++)
3595 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3597 /* Check if we lost any mbufs in the process. */
3598 DBRUNIF((sc->rx_mbuf_alloc),
3599 if_printf(&sc->arpcom.ac_if,
3600 "%s(%d): Memory leak! "
3601 "Lost %d mbufs from rx chain!\n",
3602 __FILE__, __LINE__, sc->rx_mbuf_alloc));
3604 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3608 /****************************************************************************/
3609 /* Set media options. */
3612 /* 0 for success, positive value for failure. */
3613 /****************************************************************************/
3615 bce_ifmedia_upd(struct ifnet *ifp)
3617 struct bce_softc *sc = ifp->if_softc;
3618 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3621 * 'mii' will be NULL, when this function is called on following
3622 * code path: bce_attach() -> bce_mgmt_init()
3625 /* Make sure the MII bus has been enumerated. */
3627 if (mii->mii_instance) {
3628 struct mii_softc *miisc;
3630 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
3631 mii_phy_reset(miisc);
3639 /****************************************************************************/
3640 /* Reports current media status. */
3644 /****************************************************************************/
3646 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3648 struct bce_softc *sc = ifp->if_softc;
3649 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3652 ifmr->ifm_active = mii->mii_media_active;
3653 ifmr->ifm_status = mii->mii_media_status;
3657 /****************************************************************************/
3658 /* Handles PHY generated interrupt events. */
3662 /****************************************************************************/
3664 bce_phy_intr(struct bce_softc *sc)
3666 uint32_t new_link_state, old_link_state;
3667 struct ifnet *ifp = &sc->arpcom.ac_if;
3669 ASSERT_SERIALIZED(ifp->if_serializer);
3671 new_link_state = sc->status_block->status_attn_bits &
3672 STATUS_ATTN_BITS_LINK_STATE;
3673 old_link_state = sc->status_block->status_attn_bits_ack &
3674 STATUS_ATTN_BITS_LINK_STATE;
3676 /* Handle any changes if the link state has changed. */
3677 if (new_link_state != old_link_state) { /* XXX redundant? */
3678 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
3681 callout_stop(&sc->bce_stat_ch);
3682 bce_tick_serialized(sc);
3684 /* Update the status_attn_bits_ack field in the status block. */
3685 if (new_link_state) {
3686 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
3687 STATUS_ATTN_BITS_LINK_STATE);
3689 if_printf(ifp, "Link is now UP.\n");
3691 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
3692 STATUS_ATTN_BITS_LINK_STATE);
3694 if_printf(ifp, "Link is now DOWN.\n");
3698 /* Acknowledge the link change interrupt. */
3699 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
3703 /****************************************************************************/
3704 /* Reads the receive consumer value from the status block (skipping over */
3705 /* chain page pointer if necessary). */
3709 /****************************************************************************/
3710 static __inline uint16_t
3711 bce_get_hw_rx_cons(struct bce_softc *sc)
3713 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
3715 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
3721 /****************************************************************************/
3722 /* Handles received frame interrupt events. */
3726 /****************************************************************************/
3728 bce_rx_intr(struct bce_softc *sc, int count)
3730 struct ifnet *ifp = &sc->arpcom.ac_if;
3731 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
3732 uint32_t sw_prod_bseq;
3734 #ifdef ETHER_INPUT_CHAIN
3735 struct mbuf_chain chain[MAXCPU];
3738 ASSERT_SERIALIZED(ifp->if_serializer);
3740 #ifdef ETHER_INPUT_CHAIN
3741 ether_input_chain_init(chain);
3744 DBRUNIF(1, sc->rx_interrupts++);
3746 /* Prepare the RX chain pages to be accessed by the host CPU. */
3747 for (i = 0; i < RX_PAGES; i++) {
3748 bus_dmamap_sync(sc->rx_bd_chain_tag,
3749 sc->rx_bd_chain_map[i], BUS_DMASYNC_POSTREAD);
3752 /* Get the hardware's view of the RX consumer index. */
3753 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
3755 /* Get working copies of the driver's view of the RX indices. */
3756 sw_cons = sc->rx_cons;
3757 sw_prod = sc->rx_prod;
3758 sw_prod_bseq = sc->rx_prod_bseq;
3760 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
3761 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
3762 __func__, sw_prod, sw_cons, sw_prod_bseq);
3764 /* Prevent speculative reads from getting ahead of the status block. */
3765 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
3766 BUS_SPACE_BARRIER_READ);
3768 /* Update some debug statistics counters */
3769 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3770 sc->rx_low_watermark = sc->free_rx_bd);
3771 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3773 /* Scan through the receive chain as long as there is work to do. */
3774 while (sw_cons != hw_cons) {
3775 struct mbuf *m = NULL;
3776 struct l2_fhdr *l2fhdr = NULL;
3779 uint32_t status = 0;
3781 #ifdef DEVICE_POLLING
3782 if (count >= 0 && count-- == 0) {
3783 sc->hw_rx_cons = sw_cons;
3789 * Convert the producer/consumer indices
3790 * to an actual rx_bd index.
3792 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
3793 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
3795 /* Get the used rx_bd. */
3796 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
3797 [RX_IDX(sw_chain_cons)];
3800 DBRUN(BCE_VERBOSE_RECV,
3801 if_printf(ifp, "%s(): ", __func__);
3802 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
3804 /* The mbuf is stored with the last rx_bd entry of a packet. */
3805 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
3806 /* Validate that this is the last rx_bd. */
3807 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
3808 if_printf(ifp, "%s(%d): "
3809 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
3810 __FILE__, __LINE__, sw_chain_cons);
3811 bce_breakpoint(sc));
3814 * ToDo: If the received packet is small enough
3815 * to fit into a single, non-M_EXT mbuf,
3816 * allocate a new mbuf here, copy the data to
3817 * that mbuf, and recycle the mapped jumbo frame.
3820 /* Unmap the mbuf from DMA space. */
3821 bus_dmamap_sync(sc->rx_mbuf_tag,
3822 sc->rx_mbuf_map[sw_chain_cons],
3823 BUS_DMASYNC_POSTREAD);
3824 bus_dmamap_unload(sc->rx_mbuf_tag,
3825 sc->rx_mbuf_map[sw_chain_cons]);
3827 /* Remove the mbuf from the driver's chain. */
3828 m = sc->rx_mbuf_ptr[sw_chain_cons];
3829 sc->rx_mbuf_ptr[sw_chain_cons] = NULL;
3832 * Frames received on the NetXteme II are prepended
3833 * with an l2_fhdr structure which provides status
3834 * information about the received frame (including
3835 * VLAN tags and checksum info). The frames are also
3836 * automatically adjusted to align the IP header
3837 * (i.e. two null bytes are inserted before the
3840 l2fhdr = mtod(m, struct l2_fhdr *);
3842 len = l2fhdr->l2_fhdr_pkt_len;
3843 status = l2fhdr->l2_fhdr_status;
3845 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
3847 "Simulating l2_fhdr status error.\n");
3848 status = status | L2_FHDR_ERRORS_PHY_DECODE);
3850 /* Watch for unusual sized frames. */
3851 DBRUNIF((len < BCE_MIN_MTU ||
3852 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
3854 "%s(%d): Unusual frame size found. "
3855 "Min(%d), Actual(%d), Max(%d)\n",
3857 (int)BCE_MIN_MTU, len,
3858 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
3859 bce_dump_mbuf(sc, m);
3860 bce_breakpoint(sc));
3862 len -= ETHER_CRC_LEN;
3864 /* Check the received frame for errors. */
3865 if (status & (L2_FHDR_ERRORS_BAD_CRC |
3866 L2_FHDR_ERRORS_PHY_DECODE |
3867 L2_FHDR_ERRORS_ALIGNMENT |
3868 L2_FHDR_ERRORS_TOO_SHORT |
3869 L2_FHDR_ERRORS_GIANT_FRAME)) {
3871 DBRUNIF(1, sc->l2fhdr_status_errors++);
3873 /* Reuse the mbuf for a new frame. */
3874 if (bce_newbuf_std(sc, m, &sw_prod,
3877 DBRUNIF(1, bce_breakpoint(sc));
3879 panic("%s: Can't reuse RX mbuf!\n",
3883 goto bce_rx_int_next_rx;
3887 * Get a new mbuf for the rx_bd. If no new
3888 * mbufs are available then reuse the current mbuf,
3889 * log an ierror on the interface, and generate
3890 * an error in the system log.
3892 if (bce_newbuf_std(sc, NULL, &sw_prod, &sw_chain_prod,
3896 "%s(%d): Failed to allocate new mbuf, "
3897 "incoming frame dropped!\n",
3898 __FILE__, __LINE__));
3902 /* Try and reuse the exisitng mbuf. */
3903 if (bce_newbuf_std(sc, m, &sw_prod,
3906 DBRUNIF(1, bce_breakpoint(sc));
3908 panic("%s: Double mbuf allocation "
3909 "failure!", ifp->if_xname);
3912 goto bce_rx_int_next_rx;
3916 * Skip over the l2_fhdr when passing
3917 * the data up the stack.
3919 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
3921 m->m_pkthdr.len = m->m_len = len;
3922 m->m_pkthdr.rcvif = ifp;
3924 DBRUN(BCE_VERBOSE_RECV,
3925 struct ether_header *eh;
3926 eh = mtod(m, struct ether_header *);
3927 if_printf(ifp, "%s(): to: %6D, from: %6D, "
3928 "type: 0x%04X\n", __func__,
3929 eh->ether_dhost, ":",
3930 eh->ether_shost, ":",
3931 htons(eh->ether_type)));
3933 /* Validate the checksum if offload enabled. */
3934 if (ifp->if_capenable & IFCAP_RXCSUM) {
3935 /* Check for an IP datagram. */
3936 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
3937 m->m_pkthdr.csum_flags |=
3940 /* Check if the IP checksum is valid. */
3941 if ((l2fhdr->l2_fhdr_ip_xsum ^
3943 m->m_pkthdr.csum_flags |=
3946 DBPRINT(sc, BCE_WARN_RECV,
3947 "%s(): Invalid IP checksum = 0x%04X!\n",
3948 __func__, l2fhdr->l2_fhdr_ip_xsum);
3952 /* Check for a valid TCP/UDP frame. */
3953 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
3954 L2_FHDR_STATUS_UDP_DATAGRAM)) {
3956 /* Check for a good TCP/UDP checksum. */
3958 (L2_FHDR_ERRORS_TCP_XSUM |
3959 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
3960 m->m_pkthdr.csum_data =
3961 l2fhdr->l2_fhdr_tcp_udp_xsum;
3962 m->m_pkthdr.csum_flags |=
3966 DBPRINT(sc, BCE_WARN_RECV,
3967 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
3968 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
3975 sw_prod = NEXT_RX_BD(sw_prod);
3978 sw_cons = NEXT_RX_BD(sw_cons);
3980 /* If we have a packet, pass it up the stack */
3982 DBPRINT(sc, BCE_VERBOSE_RECV,
3983 "%s(): Passing received frame up.\n", __func__);
3985 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
3986 m->m_flags |= M_VLANTAG;
3987 m->m_pkthdr.ether_vlantag =
3988 l2fhdr->l2_fhdr_vlan_tag;
3990 #ifdef ETHER_INPUT_CHAIN
3991 ether_input_chain2(ifp, m, chain);
3993 ifp->if_input(ifp, m);
3996 DBRUNIF(1, sc->rx_mbuf_alloc--);
4000 * If polling(4) is not enabled, refresh hw_cons to see
4001 * whether there's new work.
4003 * If polling(4) is enabled, i.e count >= 0, refreshing
4004 * should not be performed, so that we would not spend
4005 * too much time in RX processing.
4007 if (count < 0 && sw_cons == hw_cons)
4008 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4011 * Prevent speculative reads from getting ahead
4012 * of the status block.
4014 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4015 BUS_SPACE_BARRIER_READ);
4018 #ifdef ETHER_INPUT_CHAIN
4019 ether_input_dispatch(chain);
4022 for (i = 0; i < RX_PAGES; i++) {
4023 bus_dmamap_sync(sc->rx_bd_chain_tag,
4024 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
4027 sc->rx_cons = sw_cons;
4028 sc->rx_prod = sw_prod;
4029 sc->rx_prod_bseq = sw_prod_bseq;
4031 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
4032 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
4034 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4035 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4036 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4040 /****************************************************************************/
4041 /* Reads the transmit consumer value from the status block (skipping over */
4042 /* chain page pointer if necessary). */
4046 /****************************************************************************/
4047 static __inline uint16_t
4048 bce_get_hw_tx_cons(struct bce_softc *sc)
4050 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4052 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4058 /****************************************************************************/
4059 /* Handles transmit completion interrupt events. */
4063 /****************************************************************************/
4065 bce_tx_intr(struct bce_softc *sc)
4067 struct ifnet *ifp = &sc->arpcom.ac_if;
4068 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4070 ASSERT_SERIALIZED(ifp->if_serializer);
4072 DBRUNIF(1, sc->tx_interrupts++);
4074 /* Get the hardware's view of the TX consumer index. */
4075 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4076 sw_tx_cons = sc->tx_cons;
4078 /* Prevent speculative reads from getting ahead of the status block. */
4079 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4080 BUS_SPACE_BARRIER_READ);
4082 /* Cycle through any completed TX chain page entries. */
4083 while (sw_tx_cons != hw_tx_cons) {
4085 struct tx_bd *txbd = NULL;
4087 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4089 DBPRINT(sc, BCE_INFO_SEND,
4090 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4091 "sw_tx_chain_cons = 0x%04X\n",
4092 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4094 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4095 if_printf(ifp, "%s(%d): "
4096 "TX chain consumer out of range! "
4097 " 0x%04X > 0x%04X\n",
4098 __FILE__, __LINE__, sw_tx_chain_cons,
4100 bce_breakpoint(sc));
4102 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4103 [TX_IDX(sw_tx_chain_cons)]);
4105 DBRUNIF((txbd == NULL),
4106 if_printf(ifp, "%s(%d): "
4107 "Unexpected NULL tx_bd[0x%04X]!\n",
4108 __FILE__, __LINE__, sw_tx_chain_cons);
4109 bce_breakpoint(sc));
4111 DBRUN(BCE_INFO_SEND,
4112 if_printf(ifp, "%s(): ", __func__);
4113 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4116 * Free the associated mbuf. Remember
4117 * that only the last tx_bd of a packet
4118 * has an mbuf pointer and DMA map.
4120 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4121 /* Validate that this is the last tx_bd. */
4122 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4123 if_printf(ifp, "%s(%d): "
4124 "tx_bd END flag not set but "
4125 "txmbuf == NULL!\n", __FILE__, __LINE__);
4126 bce_breakpoint(sc));
4128 DBRUN(BCE_INFO_SEND,
4129 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4130 "from tx_bd[0x%04X]\n", __func__,
4133 /* Unmap the mbuf. */
4134 bus_dmamap_unload(sc->tx_mbuf_tag,
4135 sc->tx_mbuf_map[sw_tx_chain_cons]);
4137 /* Free the mbuf. */
4138 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4139 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4140 DBRUNIF(1, sc->tx_mbuf_alloc--);
4146 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4148 if (sw_tx_cons == hw_tx_cons) {
4149 /* Refresh hw_cons to see if there's new work. */
4150 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4154 * Prevent speculative reads from getting
4155 * ahead of the status block.
4157 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4158 BUS_SPACE_BARRIER_READ);
4161 if (sc->used_tx_bd == 0) {
4162 /* Clear the TX timeout timer. */
4166 /* Clear the tx hardware queue full flag. */
4167 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4168 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4169 DBPRINT(sc, BCE_WARN_SEND,
4170 "%s(): Open TX chain! %d/%d (used/total)\n",
4171 __func__, sc->used_tx_bd, sc->max_tx_bd));
4172 ifp->if_flags &= ~IFF_OACTIVE;
4174 sc->tx_cons = sw_tx_cons;
4178 /****************************************************************************/
4179 /* Disables interrupt generation. */
4183 /****************************************************************************/
4185 bce_disable_intr(struct bce_softc *sc)
4187 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4188 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4189 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4193 /****************************************************************************/
4194 /* Enables interrupt generation. */
4198 /****************************************************************************/
4200 bce_enable_intr(struct bce_softc *sc)
4204 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4206 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4207 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4208 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4210 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4211 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4213 val = REG_RD(sc, BCE_HC_COMMAND);
4214 REG_WR(sc, BCE_HC_COMMAND, val | BCE_HC_COMMAND_COAL_NOW);
4218 /****************************************************************************/
4219 /* Handles controller initialization. */
4223 /****************************************************************************/
4227 struct bce_softc *sc = xsc;
4228 struct ifnet *ifp = &sc->arpcom.ac_if;
4232 ASSERT_SERIALIZED(ifp->if_serializer);
4234 /* Check if the driver is still running and bail out if it is. */
4235 if (ifp->if_flags & IFF_RUNNING)
4240 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4242 if_printf(ifp, "Controller reset failed!\n");
4246 error = bce_chipinit(sc);
4248 if_printf(ifp, "Controller initialization failed!\n");
4252 error = bce_blockinit(sc);
4254 if_printf(ifp, "Block initialization failed!\n");
4258 /* Load our MAC address. */
4259 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4260 bce_set_mac_addr(sc);
4262 /* Calculate and program the Ethernet MTU size. */
4263 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4265 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4268 * Program the mtu, enabling jumbo frame
4269 * support if necessary. Also set the mbuf
4270 * allocation count for RX frames.
4272 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4274 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4275 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4276 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4277 sc->mbuf_alloc_size = MJUM9BYTES;
4279 panic("jumbo buffer is not supported yet\n");
4282 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4283 sc->mbuf_alloc_size = MCLBYTES;
4286 /* Calculate the RX Ethernet frame size for rx_bd's. */
4287 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4289 DBPRINT(sc, BCE_INFO,
4290 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4291 "max_frame_size = %d\n",
4292 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4293 sc->max_frame_size);
4295 /* Program appropriate promiscuous/multicast filtering. */
4296 bce_set_rx_mode(sc);
4298 /* Init RX buffer descriptor chain. */
4299 bce_init_rx_chain(sc); /* XXX return value */
4301 /* Init TX buffer descriptor chain. */
4302 bce_init_tx_chain(sc); /* XXX return value */
4304 #ifdef DEVICE_POLLING
4305 /* Disable interrupts if we are polling. */
4306 if (ifp->if_flags & IFF_POLLING) {
4307 bce_disable_intr(sc);
4309 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4310 (1 << 16) | sc->bce_rx_quick_cons_trip);
4311 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4312 (1 << 16) | sc->bce_tx_quick_cons_trip);
4315 /* Enable host interrupts. */
4316 bce_enable_intr(sc);
4318 bce_ifmedia_upd(ifp);
4320 ifp->if_flags |= IFF_RUNNING;
4321 ifp->if_flags &= ~IFF_OACTIVE;
4323 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
4330 /****************************************************************************/
4331 /* Initialize the controller just enough so that any management firmware */
4332 /* running on the device will continue to operate corectly. */
4336 /****************************************************************************/
4338 bce_mgmt_init(struct bce_softc *sc)
4340 struct ifnet *ifp = &sc->arpcom.ac_if;
4343 /* Check if the driver is still running and bail out if it is. */
4344 if (ifp->if_flags & IFF_RUNNING)
4347 /* Initialize the on-boards CPUs */
4350 /* Set the page size and clear the RV2P processor stall bits. */
4351 val = (BCM_PAGE_BITS - 8) << 24;
4352 REG_WR(sc, BCE_RV2P_CONFIG, val);
4354 /* Enable all critical blocks in the MAC. */
4355 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4356 BCE_MISC_ENABLE_SET_BITS_RX_V2P_ENABLE |
4357 BCE_MISC_ENABLE_SET_BITS_RX_DMA_ENABLE |
4358 BCE_MISC_ENABLE_SET_BITS_COMPLETION_ENABLE);
4359 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4362 bce_ifmedia_upd(ifp);
4366 /****************************************************************************/
4367 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4368 /* memory visible to the controller. */
4371 /* 0 for success, positive value for failure. */
4372 /****************************************************************************/
4374 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4376 struct bce_dmamap_arg ctx;
4377 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4378 bus_dmamap_t map, tmp_map;
4379 struct mbuf *m0 = *m_head;
4380 struct tx_bd *txbd = NULL;
4381 uint16_t vlan_tag = 0, flags = 0;
4382 uint16_t chain_prod, chain_prod_start, prod;
4384 int i, error, maxsegs;
4386 uint16_t debug_prod;
4389 /* Transfer any checksum offload flags to the bd. */
4390 if (m0->m_pkthdr.csum_flags) {
4391 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4392 flags |= TX_BD_FLAGS_IP_CKSUM;
4393 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4394 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4397 /* Transfer any VLAN tags to the bd. */
4398 if (m0->m_flags & M_VLANTAG) {
4399 flags |= TX_BD_FLAGS_VLAN_TAG;
4400 vlan_tag = m0->m_pkthdr.ether_vlantag;
4404 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4406 /* Map the mbuf into DMAable memory. */
4407 map = sc->tx_mbuf_map[chain_prod_start];
4409 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4410 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4411 ("not enough segements %d\n", maxsegs));
4412 if (maxsegs > BCE_MAX_SEGMENTS)
4413 maxsegs = BCE_MAX_SEGMENTS;
4415 /* Map the mbuf into our DMA address space. */
4416 ctx.bce_maxsegs = maxsegs;
4417 ctx.bce_segs = segs;
4418 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4419 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
4420 if (error == EFBIG || ctx.bce_maxsegs == 0) {
4421 DBPRINT(sc, BCE_WARN, "%s(): fragmented mbuf\n", __func__);
4422 DBRUNIF(1, bce_dump_mbuf(sc, m0););
4424 m0 = m_defrag(*m_head, MB_DONTWAIT);
4431 ctx.bce_maxsegs = maxsegs;
4432 ctx.bce_segs = segs;
4433 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4434 bce_dma_map_mbuf, &ctx,
4436 if (error || ctx.bce_maxsegs == 0) {
4437 if_printf(&sc->arpcom.ac_if,
4438 "Error mapping mbuf into TX chain\n");
4444 if_printf(&sc->arpcom.ac_if,
4445 "Error mapping mbuf into TX chain\n");
4449 /* prod points to an empty tx_bd at this point. */
4450 prod_bseq = sc->tx_prod_bseq;
4453 debug_prod = chain_prod;
4456 DBPRINT(sc, BCE_INFO_SEND,
4457 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4458 "prod_bseq = 0x%08X\n",
4459 __func__, prod, chain_prod, prod_bseq);
4462 * Cycle through each mbuf segment that makes up
4463 * the outgoing frame, gathering the mapping info
4464 * for that segment and creating a tx_bd to for
4467 for (i = 0; i < ctx.bce_maxsegs; i++) {
4468 chain_prod = TX_CHAIN_IDX(prod);
4469 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4471 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4472 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4473 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4474 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4475 txbd->tx_bd_flags = htole16(flags);
4476 prod_bseq += segs[i].ds_len;
4478 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4479 prod = NEXT_TX_BD(prod);
4482 /* Set the END flag on the last TX buffer descriptor. */
4483 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4485 DBRUN(BCE_EXCESSIVE_SEND,
4486 bce_dump_tx_chain(sc, debug_prod, ctx.bce_maxsegs));
4488 DBPRINT(sc, BCE_INFO_SEND,
4489 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4490 "prod_bseq = 0x%08X\n",
4491 __func__, prod, chain_prod, prod_bseq);
4493 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4496 * Ensure that the mbuf pointer for this transmission
4497 * is placed at the array index of the last
4498 * descriptor in this chain. This is done
4499 * because a single map is used for all
4500 * segments of the mbuf and we don't want to
4501 * unload the map before all of the segments
4504 sc->tx_mbuf_ptr[chain_prod] = m0;
4506 tmp_map = sc->tx_mbuf_map[chain_prod];
4507 sc->tx_mbuf_map[chain_prod] = map;
4508 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4510 sc->used_tx_bd += ctx.bce_maxsegs;
4512 /* Update some debug statistic counters */
4513 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4514 sc->tx_hi_watermark = sc->used_tx_bd);
4515 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
4516 DBRUNIF(1, sc->tx_mbuf_alloc++);
4518 DBRUN(BCE_VERBOSE_SEND,
4519 bce_dump_tx_mbuf_chain(sc, chain_prod, ctx.bce_maxsegs));
4521 /* prod points to the next free tx_bd at this point. */
4523 sc->tx_prod_bseq = prod_bseq;
4533 /****************************************************************************/
4534 /* Main transmit routine when called from another routine with a lock. */
4538 /****************************************************************************/
4540 bce_start(struct ifnet *ifp)
4542 struct bce_softc *sc = ifp->if_softc;
4545 ASSERT_SERIALIZED(ifp->if_serializer);
4547 /* If there's no link or the transmit queue is empty then just exit. */
4548 if (!sc->bce_link) {
4549 ifq_purge(&ifp->if_snd);
4553 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
4556 DBPRINT(sc, BCE_INFO_SEND,
4557 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04X, "
4558 "tx_prod_bseq = 0x%08X\n",
4560 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4563 struct mbuf *m_head;
4566 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4569 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4570 ifp->if_flags |= IFF_OACTIVE;
4574 /* Check for any frames to send. */
4575 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4580 * Pack the data into the transmit ring. If we
4581 * don't have room, place the mbuf back at the
4582 * head of the queue and set the OACTIVE flag
4583 * to wait for the NIC to drain the chain.
4585 if (bce_encap(sc, &m_head)) {
4586 ifp->if_flags |= IFF_OACTIVE;
4587 DBPRINT(sc, BCE_INFO_SEND,
4588 "TX chain is closed for business! "
4589 "Total tx_bd used = %d\n",
4596 /* Send a copy of the frame to any BPF listeners. */
4597 ETHER_BPF_MTAP(ifp, m_head);
4601 /* no packets were dequeued */
4602 DBPRINT(sc, BCE_VERBOSE_SEND,
4603 "%s(): No packets were dequeued\n", __func__);
4607 DBPRINT(sc, BCE_INFO_SEND,
4608 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
4609 "tx_prod_bseq = 0x%08X\n",
4611 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4613 /* Start the transmit. */
4614 REG_WR16(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
4615 REG_WR(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
4617 /* Set the tx timeout. */
4618 ifp->if_timer = BCE_TX_TIMEOUT;
4622 /****************************************************************************/
4623 /* Handles any IOCTL calls from the operating system. */
4626 /* 0 for success, positive value for failure. */
4627 /****************************************************************************/
4629 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
4631 struct bce_softc *sc = ifp->if_softc;
4632 struct ifreq *ifr = (struct ifreq *)data;
4633 struct mii_data *mii;
4634 int mask, error = 0;
4636 ASSERT_SERIALIZED(ifp->if_serializer);
4640 /* Check that the MTU setting is supported. */
4641 if (ifr->ifr_mtu < BCE_MIN_MTU ||
4643 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
4645 ifr->ifr_mtu > ETHERMTU
4652 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
4654 ifp->if_mtu = ifr->ifr_mtu;
4655 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4660 if (ifp->if_flags & IFF_UP) {
4661 if (ifp->if_flags & IFF_RUNNING) {
4662 mask = ifp->if_flags ^ sc->bce_if_flags;
4664 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
4665 bce_set_rx_mode(sc);
4669 } else if (ifp->if_flags & IFF_RUNNING) {
4672 sc->bce_if_flags = ifp->if_flags;
4677 if (ifp->if_flags & IFF_RUNNING)
4678 bce_set_rx_mode(sc);
4683 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
4685 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
4687 mii = device_get_softc(sc->bce_miibus);
4688 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
4692 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
4693 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
4696 if (mask & IFCAP_HWCSUM) {
4697 ifp->if_capenable ^= IFCAP_HWCSUM;
4698 if (IFCAP_HWCSUM & ifp->if_capenable)
4699 ifp->if_hwassist = BCE_IF_HWASSIST;
4701 ifp->if_hwassist = 0;
4706 error = ether_ioctl(ifp, command, data);
4713 /****************************************************************************/
4714 /* Transmit timeout handler. */
4718 /****************************************************************************/
4720 bce_watchdog(struct ifnet *ifp)
4722 struct bce_softc *sc = ifp->if_softc;
4724 ASSERT_SERIALIZED(ifp->if_serializer);
4726 DBRUN(BCE_VERBOSE_SEND,
4727 bce_dump_driver_state(sc);
4728 bce_dump_status_block(sc));
4731 * If we are in this routine because of pause frames, then
4732 * don't reset the hardware.
4734 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
4737 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
4739 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
4741 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4746 if (!ifq_is_empty(&ifp->if_snd))
4751 #ifdef DEVICE_POLLING
4754 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
4756 struct bce_softc *sc = ifp->if_softc;
4757 struct status_block *sblk = sc->status_block;
4758 uint16_t hw_tx_cons, hw_rx_cons;
4760 ASSERT_SERIALIZED(ifp->if_serializer);
4764 bce_disable_intr(sc);
4766 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4767 (1 << 16) | sc->bce_rx_quick_cons_trip);
4768 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4769 (1 << 16) | sc->bce_tx_quick_cons_trip);
4771 case POLL_DEREGISTER:
4772 bce_enable_intr(sc);
4774 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4775 (sc->bce_tx_quick_cons_trip_int << 16) |
4776 sc->bce_tx_quick_cons_trip);
4777 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4778 (sc->bce_rx_quick_cons_trip_int << 16) |
4779 sc->bce_rx_quick_cons_trip);
4785 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4787 if (cmd == POLL_AND_CHECK_STATUS) {
4788 uint32_t status_attn_bits;
4790 status_attn_bits = sblk->status_attn_bits;
4792 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4794 "Simulating unexpected status attention bit set.");
4795 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4797 /* Was it a link change interrupt? */
4798 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4799 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4803 * If any other attention is asserted then
4804 * the chip is toast.
4806 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4807 (sblk->status_attn_bits_ack &
4808 ~STATUS_ATTN_BITS_LINK_STATE)) {
4809 DBRUN(1, sc->unexpected_attentions++);
4811 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4812 sblk->status_attn_bits);
4815 if (bce_debug_unexpected_attention == 0)
4816 bce_breakpoint(sc));
4823 hw_rx_cons = bce_get_hw_rx_cons(sc);
4824 hw_tx_cons = bce_get_hw_tx_cons(sc);
4826 /* Check for any completed RX frames. */
4827 if (hw_rx_cons != sc->hw_rx_cons)
4828 bce_rx_intr(sc, count);
4830 /* Check for any completed TX frames. */
4831 if (hw_tx_cons != sc->hw_tx_cons)
4834 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4836 /* Check for new frames to transmit. */
4837 if (!ifq_is_empty(&ifp->if_snd))
4841 #endif /* DEVICE_POLLING */
4845 * Interrupt handler.
4847 /****************************************************************************/
4848 /* Main interrupt entry point. Verifies that the controller generated the */
4849 /* interrupt and then calls a separate routine for handle the various */
4850 /* interrupt causes (PHY, TX, RX). */
4853 /* 0 for success, positive value for failure. */
4854 /****************************************************************************/
4858 struct bce_softc *sc = xsc;
4859 struct ifnet *ifp = &sc->arpcom.ac_if;
4860 struct status_block *sblk;
4861 uint16_t hw_rx_cons, hw_tx_cons;
4863 ASSERT_SERIALIZED(ifp->if_serializer);
4865 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
4866 DBRUNIF(1, sc->interrupts_generated++);
4868 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4869 sblk = sc->status_block;
4872 * If the hardware status block index matches the last value
4873 * read by the driver and we haven't asserted our interrupt
4874 * then there's nothing to do.
4876 if (sblk->status_idx == sc->last_status_idx &&
4877 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
4878 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
4881 /* Ack the interrupt and stop others from occuring. */
4882 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4883 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
4884 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4886 /* Check if the hardware has finished any work. */
4887 hw_rx_cons = bce_get_hw_rx_cons(sc);
4888 hw_tx_cons = bce_get_hw_tx_cons(sc);
4890 /* Keep processing data as long as there is work to do. */
4892 uint32_t status_attn_bits;
4894 status_attn_bits = sblk->status_attn_bits;
4896 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4898 "Simulating unexpected status attention bit set.");
4899 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4901 /* Was it a link change interrupt? */
4902 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4903 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4907 * If any other attention is asserted then
4908 * the chip is toast.
4910 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4911 (sblk->status_attn_bits_ack &
4912 ~STATUS_ATTN_BITS_LINK_STATE)) {
4913 DBRUN(1, sc->unexpected_attentions++);
4915 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4916 sblk->status_attn_bits);
4919 if (bce_debug_unexpected_attention == 0)
4920 bce_breakpoint(sc));
4926 /* Check for any completed RX frames. */
4927 if (hw_rx_cons != sc->hw_rx_cons)
4928 bce_rx_intr(sc, -1);
4930 /* Check for any completed TX frames. */
4931 if (hw_tx_cons != sc->hw_tx_cons)
4935 * Save the status block index value
4936 * for use during the next interrupt.
4938 sc->last_status_idx = sblk->status_idx;
4941 * Prevent speculative reads from getting
4942 * ahead of the status block.
4944 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4945 BUS_SPACE_BARRIER_READ);
4948 * If there's no work left then exit the
4949 * interrupt service routine.
4951 hw_rx_cons = bce_get_hw_rx_cons(sc);
4952 hw_tx_cons = bce_get_hw_tx_cons(sc);
4953 if ((hw_rx_cons == sc->hw_rx_cons) && (hw_tx_cons == sc->hw_tx_cons))
4957 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4959 /* Re-enable interrupts. */
4960 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4961 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
4962 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4963 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4964 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4966 if (sc->bce_coalchg_mask)
4967 bce_coal_change(sc);
4969 /* Handle any frames that arrived while handling the interrupt. */
4970 if (!ifq_is_empty(&ifp->if_snd))
4975 /****************************************************************************/
4976 /* Programs the various packet receive modes (broadcast and multicast). */
4980 /****************************************************************************/
4982 bce_set_rx_mode(struct bce_softc *sc)
4984 struct ifnet *ifp = &sc->arpcom.ac_if;
4985 struct ifmultiaddr *ifma;
4986 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4987 uint32_t rx_mode, sort_mode;
4990 ASSERT_SERIALIZED(ifp->if_serializer);
4992 /* Initialize receive mode default settings. */
4993 rx_mode = sc->rx_mode &
4994 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
4995 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
4996 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
4999 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5002 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5003 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5004 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5007 * Check for promiscuous, all multicast, or selected
5008 * multicast address filtering.
5010 if (ifp->if_flags & IFF_PROMISC) {
5011 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5013 /* Enable promiscuous mode. */
5014 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5015 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5016 } else if (ifp->if_flags & IFF_ALLMULTI) {
5017 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5019 /* Enable all multicast addresses. */
5020 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5021 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5024 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5026 /* Accept one or more multicast(s). */
5027 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5029 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5030 if (ifma->ifma_addr->sa_family != AF_LINK)
5033 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5034 ETHER_ADDR_LEN) & 0xFF;
5035 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5038 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5039 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5042 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5045 /* Only make changes if the recive mode has actually changed. */
5046 if (rx_mode != sc->rx_mode) {
5047 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5050 sc->rx_mode = rx_mode;
5051 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5054 /* Disable and clear the exisitng sort before enabling a new sort. */
5055 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5056 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5057 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5061 /****************************************************************************/
5062 /* Called periodically to updates statistics from the controllers */
5063 /* statistics block. */
5067 /****************************************************************************/
5069 bce_stats_update(struct bce_softc *sc)
5071 struct ifnet *ifp = &sc->arpcom.ac_if;
5072 struct statistics_block *stats = sc->stats_block;
5074 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5076 ASSERT_SERIALIZED(ifp->if_serializer);
5079 * Update the interface statistics from the hardware statistics.
5081 ifp->if_collisions = (u_long)stats->stat_EtherStatsCollisions;
5083 ifp->if_ierrors = (u_long)stats->stat_EtherStatsUndersizePkts +
5084 (u_long)stats->stat_EtherStatsOverrsizePkts +
5085 (u_long)stats->stat_IfInMBUFDiscards +
5086 (u_long)stats->stat_Dot3StatsAlignmentErrors +
5087 (u_long)stats->stat_Dot3StatsFCSErrors;
5090 (u_long)stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5091 (u_long)stats->stat_Dot3StatsExcessiveCollisions +
5092 (u_long)stats->stat_Dot3StatsLateCollisions;
5095 * Certain controllers don't report carrier sense errors correctly.
5096 * See errata E11_5708CA0_1165.
5098 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5099 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5101 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5105 * Update the sysctl statistics from the hardware statistics.
5107 sc->stat_IfHCInOctets =
5108 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5109 (uint64_t)stats->stat_IfHCInOctets_lo;
5111 sc->stat_IfHCInBadOctets =
5112 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5113 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5115 sc->stat_IfHCOutOctets =
5116 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5117 (uint64_t)stats->stat_IfHCOutOctets_lo;
5119 sc->stat_IfHCOutBadOctets =
5120 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5121 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5123 sc->stat_IfHCInUcastPkts =
5124 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5125 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5127 sc->stat_IfHCInMulticastPkts =
5128 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5129 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5131 sc->stat_IfHCInBroadcastPkts =
5132 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5133 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5135 sc->stat_IfHCOutUcastPkts =
5136 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5137 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5139 sc->stat_IfHCOutMulticastPkts =
5140 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5141 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5143 sc->stat_IfHCOutBroadcastPkts =
5144 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5145 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5147 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5148 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5150 sc->stat_Dot3StatsCarrierSenseErrors =
5151 stats->stat_Dot3StatsCarrierSenseErrors;
5153 sc->stat_Dot3StatsFCSErrors =
5154 stats->stat_Dot3StatsFCSErrors;
5156 sc->stat_Dot3StatsAlignmentErrors =
5157 stats->stat_Dot3StatsAlignmentErrors;
5159 sc->stat_Dot3StatsSingleCollisionFrames =
5160 stats->stat_Dot3StatsSingleCollisionFrames;
5162 sc->stat_Dot3StatsMultipleCollisionFrames =
5163 stats->stat_Dot3StatsMultipleCollisionFrames;
5165 sc->stat_Dot3StatsDeferredTransmissions =
5166 stats->stat_Dot3StatsDeferredTransmissions;
5168 sc->stat_Dot3StatsExcessiveCollisions =
5169 stats->stat_Dot3StatsExcessiveCollisions;
5171 sc->stat_Dot3StatsLateCollisions =
5172 stats->stat_Dot3StatsLateCollisions;
5174 sc->stat_EtherStatsCollisions =
5175 stats->stat_EtherStatsCollisions;
5177 sc->stat_EtherStatsFragments =
5178 stats->stat_EtherStatsFragments;
5180 sc->stat_EtherStatsJabbers =
5181 stats->stat_EtherStatsJabbers;
5183 sc->stat_EtherStatsUndersizePkts =
5184 stats->stat_EtherStatsUndersizePkts;
5186 sc->stat_EtherStatsOverrsizePkts =
5187 stats->stat_EtherStatsOverrsizePkts;
5189 sc->stat_EtherStatsPktsRx64Octets =
5190 stats->stat_EtherStatsPktsRx64Octets;
5192 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5193 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5195 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5196 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5198 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5199 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5201 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5202 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5204 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5205 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5207 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5208 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5210 sc->stat_EtherStatsPktsTx64Octets =
5211 stats->stat_EtherStatsPktsTx64Octets;
5213 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5214 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5216 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5217 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5219 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5220 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5222 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5223 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5225 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5226 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5228 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5229 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5231 sc->stat_XonPauseFramesReceived =
5232 stats->stat_XonPauseFramesReceived;
5234 sc->stat_XoffPauseFramesReceived =
5235 stats->stat_XoffPauseFramesReceived;
5237 sc->stat_OutXonSent =
5238 stats->stat_OutXonSent;
5240 sc->stat_OutXoffSent =
5241 stats->stat_OutXoffSent;
5243 sc->stat_FlowControlDone =
5244 stats->stat_FlowControlDone;
5246 sc->stat_MacControlFramesReceived =
5247 stats->stat_MacControlFramesReceived;
5249 sc->stat_XoffStateEntered =
5250 stats->stat_XoffStateEntered;
5252 sc->stat_IfInFramesL2FilterDiscards =
5253 stats->stat_IfInFramesL2FilterDiscards;
5255 sc->stat_IfInRuleCheckerDiscards =
5256 stats->stat_IfInRuleCheckerDiscards;
5258 sc->stat_IfInFTQDiscards =
5259 stats->stat_IfInFTQDiscards;
5261 sc->stat_IfInMBUFDiscards =
5262 stats->stat_IfInMBUFDiscards;
5264 sc->stat_IfInRuleCheckerP4Hit =
5265 stats->stat_IfInRuleCheckerP4Hit;
5267 sc->stat_CatchupInRuleCheckerDiscards =
5268 stats->stat_CatchupInRuleCheckerDiscards;
5270 sc->stat_CatchupInFTQDiscards =
5271 stats->stat_CatchupInFTQDiscards;
5273 sc->stat_CatchupInMBUFDiscards =
5274 stats->stat_CatchupInMBUFDiscards;
5276 sc->stat_CatchupInRuleCheckerP4Hit =
5277 stats->stat_CatchupInRuleCheckerP4Hit;
5279 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5281 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5285 /****************************************************************************/
5286 /* Periodic function to perform maintenance tasks. */
5290 /****************************************************************************/
5292 bce_tick_serialized(struct bce_softc *sc)
5294 struct ifnet *ifp = &sc->arpcom.ac_if;
5295 struct mii_data *mii;
5298 ASSERT_SERIALIZED(ifp->if_serializer);
5300 /* Tell the firmware that the driver is still running. */
5302 msg = (uint32_t)BCE_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
5304 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5306 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_PULSE_MB, msg);
5308 /* Update the statistics from the hardware statistics block. */
5309 bce_stats_update(sc);
5311 /* Schedule the next tick. */
5312 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
5314 /* If link is up already up then we're done. */
5318 mii = device_get_softc(sc->bce_miibus);
5321 /* Check if the link has come up. */
5322 if (!sc->bce_link && (mii->mii_media_status & IFM_ACTIVE) &&
5323 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5325 /* Now that link is up, handle any outstanding TX traffic. */
5326 if (!ifq_is_empty(&ifp->if_snd))
5335 struct bce_softc *sc = xsc;
5336 struct ifnet *ifp = &sc->arpcom.ac_if;
5338 lwkt_serialize_enter(ifp->if_serializer);
5339 bce_tick_serialized(sc);
5340 lwkt_serialize_exit(ifp->if_serializer);
5345 /****************************************************************************/
5346 /* Allows the driver state to be dumped through the sysctl interface. */
5349 /* 0 for success, positive value for failure. */
5350 /****************************************************************************/
5352 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5356 struct bce_softc *sc;
5359 error = sysctl_handle_int(oidp, &result, 0, req);
5361 if (error || !req->newptr)
5365 sc = (struct bce_softc *)arg1;
5366 bce_dump_driver_state(sc);
5373 /****************************************************************************/
5374 /* Allows the hardware state to be dumped through the sysctl interface. */
5377 /* 0 for success, positive value for failure. */
5378 /****************************************************************************/
5380 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5384 struct bce_softc *sc;
5387 error = sysctl_handle_int(oidp, &result, 0, req);
5389 if (error || !req->newptr)
5393 sc = (struct bce_softc *)arg1;
5394 bce_dump_hw_state(sc);
5401 /****************************************************************************/
5402 /* Provides a sysctl interface to allows dumping the RX chain. */
5405 /* 0 for success, positive value for failure. */
5406 /****************************************************************************/
5408 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5412 struct bce_softc *sc;
5415 error = sysctl_handle_int(oidp, &result, 0, req);
5417 if (error || !req->newptr)
5421 sc = (struct bce_softc *)arg1;
5422 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5429 /****************************************************************************/
5430 /* Provides a sysctl interface to allows dumping the TX chain. */
5433 /* 0 for success, positive value for failure. */
5434 /****************************************************************************/
5436 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5440 struct bce_softc *sc;
5443 error = sysctl_handle_int(oidp, &result, 0, req);
5445 if (error || !req->newptr)
5449 sc = (struct bce_softc *)arg1;
5450 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
5457 /****************************************************************************/
5458 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5459 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5462 /* 0 for success, positive value for failure. */
5463 /****************************************************************************/
5465 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5467 struct bce_softc *sc;
5469 uint32_t val, result;
5472 error = sysctl_handle_int(oidp, &result, 0, req);
5473 if (error || (req->newptr == NULL))
5476 /* Make sure the register is accessible. */
5477 if (result < 0x8000) {
5478 sc = (struct bce_softc *)arg1;
5479 val = REG_RD(sc, result);
5480 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5482 } else if (result < 0x0280000) {
5483 sc = (struct bce_softc *)arg1;
5484 val = REG_RD_IND(sc, result);
5485 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5492 /****************************************************************************/
5493 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
\r
5494 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
\r
5497 /* 0 for success, positive value for failure. */
5498 /****************************************************************************/
5500 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
5502 struct bce_softc *sc;
5508 error = sysctl_handle_int(oidp, &result, 0, req);
5509 if (error || (req->newptr == NULL))
5512 /* Make sure the register is accessible. */
5513 if (result < 0x20) {
5514 sc = (struct bce_softc *)arg1;
5516 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
5517 if_printf(&sc->arpcom.ac_if,
5518 "phy 0x%02X = 0x%04X\n", result, val);
5524 /****************************************************************************/
5525 /* Provides a sysctl interface to forcing the driver to dump state and */
\r
5526 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5529 /* 0 for success, positive value for failure. */
5530 /****************************************************************************/
5532 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
5536 struct bce_softc *sc;
5539 error = sysctl_handle_int(oidp, &result, 0, req);
5541 if (error || !req->newptr)
5545 sc = (struct bce_softc *)arg1;
5554 /****************************************************************************/
5555 /* Adds any sysctl parameters for tuning or debugging purposes. */
5558 /* 0 for success, positive value for failure. */
5559 /****************************************************************************/
5561 bce_add_sysctls(struct bce_softc *sc)
5563 struct sysctl_ctx_list *ctx;
5564 struct sysctl_oid_list *children;
5566 sysctl_ctx_init(&sc->bce_sysctl_ctx);
5567 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
5568 SYSCTL_STATIC_CHILDREN(_hw),
5570 device_get_nameunit(sc->bce_dev),
5572 if (sc->bce_sysctl_tree == NULL) {
5573 device_printf(sc->bce_dev, "can't add sysctl node\n");
5577 ctx = &sc->bce_sysctl_ctx;
5578 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
5580 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
5581 CTLTYPE_INT | CTLFLAG_RW,
5582 sc, 0, bce_sysctl_tx_bds_int, "I",
5583 "Send max coalesced BD count during interrupt");
5584 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
5585 CTLTYPE_INT | CTLFLAG_RW,
5586 sc, 0, bce_sysctl_tx_bds, "I",
5587 "Send max coalesced BD count");
5588 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
5589 CTLTYPE_INT | CTLFLAG_RW,
5590 sc, 0, bce_sysctl_tx_ticks_int, "I",
5591 "Send coalescing ticks during interrupt");
5592 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
5593 CTLTYPE_INT | CTLFLAG_RW,
5594 sc, 0, bce_sysctl_tx_ticks, "I",
5595 "Send coalescing ticks");
5597 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
5598 CTLTYPE_INT | CTLFLAG_RW,
5599 sc, 0, bce_sysctl_rx_bds_int, "I",
5600 "Receive max coalesced BD count during interrupt");
5601 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
5602 CTLTYPE_INT | CTLFLAG_RW,
5603 sc, 0, bce_sysctl_rx_bds, "I",
5604 "Receive max coalesced BD count");
5605 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
5606 CTLTYPE_INT | CTLFLAG_RW,
5607 sc, 0, bce_sysctl_rx_ticks_int, "I",
5608 "Receive coalescing ticks during interrupt");
5609 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
5610 CTLTYPE_INT | CTLFLAG_RW,
5611 sc, 0, bce_sysctl_rx_ticks, "I",
5612 "Receive coalescing ticks");
5615 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5617 CTLFLAG_RD, &sc->rx_low_watermark,
5618 0, "Lowest level of free rx_bd's");
5620 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5622 CTLFLAG_RD, &sc->rx_empty_count,
5623 0, "Number of times the RX chain was empty");
5625 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5627 CTLFLAG_RD, &sc->tx_hi_watermark,
5628 0, "Highest level of used tx_bd's");
5630 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5632 CTLFLAG_RD, &sc->tx_full_count,
5633 0, "Number of times the TX chain was full");
5635 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5636 "l2fhdr_status_errors",
5637 CTLFLAG_RD, &sc->l2fhdr_status_errors,
5638 0, "l2_fhdr status errors");
5640 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5641 "unexpected_attentions",
5642 CTLFLAG_RD, &sc->unexpected_attentions,
5643 0, "unexpected attentions");
5645 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5646 "lost_status_block_updates",
5647 CTLFLAG_RD, &sc->lost_status_block_updates,
5648 0, "lost status block updates");
5650 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5651 "mbuf_alloc_failed",
5652 CTLFLAG_RD, &sc->mbuf_alloc_failed,
5653 0, "mbuf cluster allocation failures");
5656 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5657 "stat_IfHCInOctets",
5658 CTLFLAG_RD, &sc->stat_IfHCInOctets,
5661 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5662 "stat_IfHCInBadOctets",
5663 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
5664 "Bad bytes received");
5666 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5667 "stat_IfHCOutOctets",
5668 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
5671 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5672 "stat_IfHCOutBadOctets",
5673 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
5676 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5677 "stat_IfHCInUcastPkts",
5678 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
5679 "Unicast packets received");
5681 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5682 "stat_IfHCInMulticastPkts",
5683 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
5684 "Multicast packets received");
5686 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5687 "stat_IfHCInBroadcastPkts",
5688 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
5689 "Broadcast packets received");
5691 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5692 "stat_IfHCOutUcastPkts",
5693 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
5694 "Unicast packets sent");
5696 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5697 "stat_IfHCOutMulticastPkts",
5698 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
5699 "Multicast packets sent");
5701 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5702 "stat_IfHCOutBroadcastPkts",
5703 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
5704 "Broadcast packets sent");
5706 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5707 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
5708 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
5709 0, "Internal MAC transmit errors");
5711 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5712 "stat_Dot3StatsCarrierSenseErrors",
5713 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
5714 0, "Carrier sense errors");
5716 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5717 "stat_Dot3StatsFCSErrors",
5718 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
5719 0, "Frame check sequence errors");
5721 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5722 "stat_Dot3StatsAlignmentErrors",
5723 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
5724 0, "Alignment errors");
5726 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5727 "stat_Dot3StatsSingleCollisionFrames",
5728 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
5729 0, "Single Collision Frames");
5731 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5732 "stat_Dot3StatsMultipleCollisionFrames",
5733 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
5734 0, "Multiple Collision Frames");
5736 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5737 "stat_Dot3StatsDeferredTransmissions",
5738 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
5739 0, "Deferred Transmissions");
5741 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5742 "stat_Dot3StatsExcessiveCollisions",
5743 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
5744 0, "Excessive Collisions");
5746 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5747 "stat_Dot3StatsLateCollisions",
5748 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
5749 0, "Late Collisions");
5751 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5752 "stat_EtherStatsCollisions",
5753 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
5756 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5757 "stat_EtherStatsFragments",
5758 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
5761 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5762 "stat_EtherStatsJabbers",
5763 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
5766 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5767 "stat_EtherStatsUndersizePkts",
5768 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
5769 0, "Undersize packets");
5771 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5772 "stat_EtherStatsOverrsizePkts",
5773 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
5774 0, "stat_EtherStatsOverrsizePkts");
5776 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5777 "stat_EtherStatsPktsRx64Octets",
5778 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
5779 0, "Bytes received in 64 byte packets");
5781 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5782 "stat_EtherStatsPktsRx65Octetsto127Octets",
5783 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
5784 0, "Bytes received in 65 to 127 byte packets");
5786 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5787 "stat_EtherStatsPktsRx128Octetsto255Octets",
5788 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
5789 0, "Bytes received in 128 to 255 byte packets");
5791 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5792 "stat_EtherStatsPktsRx256Octetsto511Octets",
5793 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
5794 0, "Bytes received in 256 to 511 byte packets");
5796 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5797 "stat_EtherStatsPktsRx512Octetsto1023Octets",
5798 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
5799 0, "Bytes received in 512 to 1023 byte packets");
5801 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5802 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
5803 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
5804 0, "Bytes received in 1024 t0 1522 byte packets");
5806 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5807 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
5808 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
5809 0, "Bytes received in 1523 to 9022 byte packets");
5811 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5812 "stat_EtherStatsPktsTx64Octets",
5813 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
5814 0, "Bytes sent in 64 byte packets");
5816 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5817 "stat_EtherStatsPktsTx65Octetsto127Octets",
5818 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
5819 0, "Bytes sent in 65 to 127 byte packets");
5821 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5822 "stat_EtherStatsPktsTx128Octetsto255Octets",
5823 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
5824 0, "Bytes sent in 128 to 255 byte packets");
5826 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5827 "stat_EtherStatsPktsTx256Octetsto511Octets",
5828 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
5829 0, "Bytes sent in 256 to 511 byte packets");
5831 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5832 "stat_EtherStatsPktsTx512Octetsto1023Octets",
5833 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
5834 0, "Bytes sent in 512 to 1023 byte packets");
5836 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5837 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
5838 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
5839 0, "Bytes sent in 1024 to 1522 byte packets");
5841 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5842 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
5843 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
5844 0, "Bytes sent in 1523 to 9022 byte packets");
5846 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5847 "stat_XonPauseFramesReceived",
5848 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
5849 0, "XON pause frames receved");
5851 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5852 "stat_XoffPauseFramesReceived",
5853 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
5854 0, "XOFF pause frames received");
5856 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5858 CTLFLAG_RD, &sc->stat_OutXonSent,
5859 0, "XON pause frames sent");
5861 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5863 CTLFLAG_RD, &sc->stat_OutXoffSent,
5864 0, "XOFF pause frames sent");
5866 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5867 "stat_FlowControlDone",
5868 CTLFLAG_RD, &sc->stat_FlowControlDone,
5869 0, "Flow control done");
5871 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5872 "stat_MacControlFramesReceived",
5873 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
5874 0, "MAC control frames received");
5876 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5877 "stat_XoffStateEntered",
5878 CTLFLAG_RD, &sc->stat_XoffStateEntered,
5879 0, "XOFF state entered");
5881 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5882 "stat_IfInFramesL2FilterDiscards",
5883 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
5884 0, "Received L2 packets discarded");
5886 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5887 "stat_IfInRuleCheckerDiscards",
5888 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
5889 0, "Received packets discarded by rule");
5891 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5892 "stat_IfInFTQDiscards",
5893 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
5894 0, "Received packet FTQ discards");
5896 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5897 "stat_IfInMBUFDiscards",
5898 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
5899 0, "Received packets discarded due to lack of controller buffer memory");
5901 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5902 "stat_IfInRuleCheckerP4Hit",
5903 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
5904 0, "Received packets rule checker hits");
5906 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5907 "stat_CatchupInRuleCheckerDiscards",
5908 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
5909 0, "Received packets discarded in Catchup path");
5911 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5912 "stat_CatchupInFTQDiscards",
5913 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
5914 0, "Received packets discarded in FTQ in Catchup path");
5916 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5917 "stat_CatchupInMBUFDiscards",
5918 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
5919 0, "Received packets discarded in controller buffer memory in Catchup path");
5921 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5922 "stat_CatchupInRuleCheckerP4Hit",
5923 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
5924 0, "Received packets rule checker hits in Catchup path");
5926 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5928 CTLFLAG_RD, &sc->com_no_buffers,
5929 0, "Valid packets received but no RX buffers available");
5932 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5933 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
5935 bce_sysctl_driver_state, "I", "Drive state information");
5937 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5938 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
5940 bce_sysctl_hw_state, "I", "Hardware state information");
5942 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5943 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
5945 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
5947 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5948 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
5950 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
5952 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5953 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
5955 bce_sysctl_breakpoint, "I", "Driver breakpoint");
5957 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5958 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
5960 bce_sysctl_reg_read, "I", "Register read");
5962 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
\r
5963 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
\r
5965 bce_sysctl_phy_read, "I", "PHY register read");
5972 /****************************************************************************/
5973 /* BCE Debug Routines */
5974 /****************************************************************************/
5977 /****************************************************************************/
5978 /* Freezes the controller to allow for a cohesive state dump. */
5982 /****************************************************************************/
5984 bce_freeze_controller(struct bce_softc *sc)
5988 val = REG_RD(sc, BCE_MISC_COMMAND);
5989 val |= BCE_MISC_COMMAND_DISABLE_ALL;
5990 REG_WR(sc, BCE_MISC_COMMAND, val);
5994 /****************************************************************************/
5995 /* Unfreezes the controller after a freeze operation. This may not always */
\r
5996 /* work and the controller will require a reset! */
6000 /****************************************************************************/
6002 bce_unfreeze_controller(struct bce_softc *sc)
6006 val = REG_RD(sc, BCE_MISC_COMMAND);
6007 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6008 REG_WR(sc, BCE_MISC_COMMAND, val);
6012 /****************************************************************************/
6013 /* Prints out information about an mbuf. */
6017 /****************************************************************************/
6019 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6021 struct ifnet *ifp = &sc->arpcom.ac_if;
6022 uint32_t val_hi, val_lo;
6023 struct mbuf *mp = m;
6026 /* Index out of range. */
6027 if_printf(ifp, "mbuf: null pointer\n");
6032 val_hi = BCE_ADDR_HI(mp);
6033 val_lo = BCE_ADDR_LO(mp);
6034 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6035 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6037 if (mp->m_flags & M_EXT)
6039 if (mp->m_flags & M_PKTHDR)
6040 kprintf("M_PKTHDR ");
6041 if (mp->m_flags & M_EOR)
6044 if (mp->m_flags & M_RDONLY)
6045 kprintf("M_RDONLY ");
6048 val_hi = BCE_ADDR_HI(mp->m_data);
6049 val_lo = BCE_ADDR_LO(mp->m_data);
6050 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6052 if (mp->m_flags & M_PKTHDR) {
6053 if_printf(ifp, "- m_pkthdr: flags = ( ");
6054 if (mp->m_flags & M_BCAST)
6055 kprintf("M_BCAST ");
6056 if (mp->m_flags & M_MCAST)
6057 kprintf("M_MCAST ");
6058 if (mp->m_flags & M_FRAG)
6060 if (mp->m_flags & M_FIRSTFRAG)
6061 kprintf("M_FIRSTFRAG ");
6062 if (mp->m_flags & M_LASTFRAG)
6063 kprintf("M_LASTFRAG ");
6065 if (mp->m_flags & M_VLANTAG)
6066 kprintf("M_VLANTAG ");
6069 if (mp->m_flags & M_PROMISC)
6070 kprintf("M_PROMISC ");
6072 kprintf(") csum_flags = ( ");
6073 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6074 kprintf("CSUM_IP ");
6075 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6076 kprintf("CSUM_TCP ");
6077 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6078 kprintf("CSUM_UDP ");
6079 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6080 kprintf("CSUM_IP_FRAGS ");
6081 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6082 kprintf("CSUM_FRAGMENT ");
6084 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6085 kprintf("CSUM_TSO ");
6087 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6088 kprintf("CSUM_IP_CHECKED ");
6089 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6090 kprintf("CSUM_IP_VALID ");
6091 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6092 kprintf("CSUM_DATA_VALID ");
6096 if (mp->m_flags & M_EXT) {
6097 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6098 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6099 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6101 val_hi, val_lo, mp->m_ext.ext_size);
6108 /****************************************************************************/
6109 /* Prints out the mbufs in the TX mbuf chain. */
6113 /****************************************************************************/
6115 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6117 struct ifnet *ifp = &sc->arpcom.ac_if;
6121 "----------------------------"
6123 "----------------------------\n");
6125 for (i = 0; i < count; i++) {
6126 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6127 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6128 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6132 "----------------------------"
6134 "----------------------------\n");
6138 /****************************************************************************/
6139 /* Prints out the mbufs in the RX mbuf chain. */
6143 /****************************************************************************/
6145 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6147 struct ifnet *ifp = &sc->arpcom.ac_if;
6151 "----------------------------"
6153 "----------------------------\n");
6155 for (i = 0; i < count; i++) {
6156 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6157 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6158 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6162 "----------------------------"
6164 "----------------------------\n");
6168 /****************************************************************************/
6169 /* Prints out a tx_bd structure. */
6173 /****************************************************************************/
6175 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6177 struct ifnet *ifp = &sc->arpcom.ac_if;
6179 if (idx > MAX_TX_BD) {
6180 /* Index out of range. */
6181 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6182 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6183 /* TX Chain page pointer. */
6184 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6185 "chain page pointer\n",
6186 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6188 /* Normal tx_bd entry. */
6189 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6191 "vlan tag= 0x%04X, flags = 0x%04X (",
6192 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6193 txbd->tx_bd_mss_nbytes,
6194 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6196 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6197 kprintf(" CONN_FAULT");
6199 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6200 kprintf(" TCP_UDP_CKSUM");
6202 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6203 kprintf(" IP_CKSUM");
6205 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6208 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6209 kprintf(" COAL_NOW");
6211 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6212 kprintf(" DONT_GEN_CRC");
6214 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6217 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6220 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6223 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6224 kprintf(" OPTION_WORD");
6226 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6229 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6237 /****************************************************************************/
6238 /* Prints out a rx_bd structure. */
6242 /****************************************************************************/
6244 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6246 struct ifnet *ifp = &sc->arpcom.ac_if;
6248 if (idx > MAX_RX_BD) {
6249 /* Index out of range. */
6250 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6251 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6252 /* TX Chain page pointer. */
6253 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6254 "chain page pointer\n",
6255 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6257 /* Normal tx_bd entry. */
6258 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6259 "nbytes = 0x%08X, flags = 0x%08X\n",
6260 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6261 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6266 /****************************************************************************/
6267 /* Prints out a l2_fhdr structure. */
6271 /****************************************************************************/
6273 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6275 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6276 "pkt_len = 0x%04X, vlan = 0x%04x, "
6277 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6278 idx, l2fhdr->l2_fhdr_status,
6279 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6280 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6284 /****************************************************************************/
6285 /* Prints out the tx chain. */
6289 /****************************************************************************/
6291 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6293 struct ifnet *ifp = &sc->arpcom.ac_if;
6296 /* First some info about the tx_bd chain structure. */
6298 "----------------------------"
6300 "----------------------------\n");
6302 if_printf(ifp, "page size = 0x%08X, "
6303 "tx chain pages = 0x%08X\n",
6304 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6306 if_printf(ifp, "tx_bd per page = 0x%08X, "
6307 "usable tx_bd per page = 0x%08X\n",
6308 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6309 (uint32_t)USABLE_TX_BD_PER_PAGE);
6311 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6314 "----------------------------"
6316 "----------------------------\n");
6318 /* Now print out the tx_bd's themselves. */
6319 for (i = 0; i < count; i++) {
6322 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6323 bce_dump_txbd(sc, tx_prod, txbd);
6324 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6328 "----------------------------"
6330 "----------------------------\n");
6334 /****************************************************************************/
6335 /* Prints out the rx chain. */
6339 /****************************************************************************/
6341 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6343 struct ifnet *ifp = &sc->arpcom.ac_if;
6346 /* First some info about the tx_bd chain structure. */
6348 "----------------------------"
6350 "----------------------------\n");
6352 if_printf(ifp, "page size = 0x%08X, "
6353 "rx chain pages = 0x%08X\n",
6354 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6356 if_printf(ifp, "rx_bd per page = 0x%08X, "
6357 "usable rx_bd per page = 0x%08X\n",
6358 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6359 (uint32_t)USABLE_RX_BD_PER_PAGE);
6361 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6364 "----------------------------"
6366 "----------------------------\n");
6368 /* Now print out the rx_bd's themselves. */
6369 for (i = 0; i < count; i++) {
6372 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6373 bce_dump_rxbd(sc, rx_prod, rxbd);
6374 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6378 "----------------------------"
6380 "----------------------------\n");
6384 /****************************************************************************/
6385 /* Prints out the status block from host memory. */
6389 /****************************************************************************/
6391 bce_dump_status_block(struct bce_softc *sc)
6393 struct status_block *sblk = sc->status_block;
6394 struct ifnet *ifp = &sc->arpcom.ac_if;
6397 "----------------------------"
6399 "----------------------------\n");
6401 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6403 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6404 sblk->status_attn_bits_ack);
6406 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6407 sblk->status_rx_quick_consumer_index0,
6408 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6410 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6411 sblk->status_tx_quick_consumer_index0,
6412 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6414 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6416 /* Theses indices are not used for normal L2 drivers. */
6417 if (sblk->status_rx_quick_consumer_index1) {
6418 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6419 sblk->status_rx_quick_consumer_index1,
6420 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
6423 if (sblk->status_tx_quick_consumer_index1) {
6424 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6425 sblk->status_tx_quick_consumer_index1,
6426 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
6429 if (sblk->status_rx_quick_consumer_index2) {
6430 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6431 sblk->status_rx_quick_consumer_index2,
6432 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
6435 if (sblk->status_tx_quick_consumer_index2) {
6436 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6437 sblk->status_tx_quick_consumer_index2,
6438 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
6441 if (sblk->status_rx_quick_consumer_index3) {
6442 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6443 sblk->status_rx_quick_consumer_index3,
6444 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
6447 if (sblk->status_tx_quick_consumer_index3) {
6448 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6449 sblk->status_tx_quick_consumer_index3,
6450 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
6453 if (sblk->status_rx_quick_consumer_index4 ||
6454 sblk->status_rx_quick_consumer_index5) {
6455 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6456 sblk->status_rx_quick_consumer_index4,
6457 sblk->status_rx_quick_consumer_index5);
6460 if (sblk->status_rx_quick_consumer_index6 ||
6461 sblk->status_rx_quick_consumer_index7) {
6462 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6463 sblk->status_rx_quick_consumer_index6,
6464 sblk->status_rx_quick_consumer_index7);
6467 if (sblk->status_rx_quick_consumer_index8 ||
6468 sblk->status_rx_quick_consumer_index9) {
6469 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6470 sblk->status_rx_quick_consumer_index8,
6471 sblk->status_rx_quick_consumer_index9);
6474 if (sblk->status_rx_quick_consumer_index10 ||
6475 sblk->status_rx_quick_consumer_index11) {
6476 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6477 sblk->status_rx_quick_consumer_index10,
6478 sblk->status_rx_quick_consumer_index11);
6481 if (sblk->status_rx_quick_consumer_index12 ||
6482 sblk->status_rx_quick_consumer_index13) {
6483 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6484 sblk->status_rx_quick_consumer_index12,
6485 sblk->status_rx_quick_consumer_index13);
6488 if (sblk->status_rx_quick_consumer_index14 ||
6489 sblk->status_rx_quick_consumer_index15) {
6490 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6491 sblk->status_rx_quick_consumer_index14,
6492 sblk->status_rx_quick_consumer_index15);
6495 if (sblk->status_completion_producer_index ||
6496 sblk->status_cmd_consumer_index) {
6497 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6498 sblk->status_completion_producer_index,
6499 sblk->status_cmd_consumer_index);
6503 "----------------------------"
6505 "----------------------------\n");
6509 /****************************************************************************/
6510 /* Prints out the statistics block. */
6514 /****************************************************************************/
6516 bce_dump_stats_block(struct bce_softc *sc)
6518 struct statistics_block *sblk = sc->stats_block;
6519 struct ifnet *ifp = &sc->arpcom.ac_if;
6523 " Stats Block (All Stats Not Shown Are 0) "
6524 "---------------\n");
6526 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
6527 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
6528 sblk->stat_IfHCInOctets_hi,
6529 sblk->stat_IfHCInOctets_lo);
6532 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
6533 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
6534 sblk->stat_IfHCInBadOctets_hi,
6535 sblk->stat_IfHCInBadOctets_lo);
6538 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
6539 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
6540 sblk->stat_IfHCOutOctets_hi,
6541 sblk->stat_IfHCOutOctets_lo);
6544 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
6545 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
6546 sblk->stat_IfHCOutBadOctets_hi,
6547 sblk->stat_IfHCOutBadOctets_lo);
6550 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
6551 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
6552 sblk->stat_IfHCInUcastPkts_hi,
6553 sblk->stat_IfHCInUcastPkts_lo);
6556 if (sblk->stat_IfHCInBroadcastPkts_hi ||
6557 sblk->stat_IfHCInBroadcastPkts_lo) {
6558 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
6559 sblk->stat_IfHCInBroadcastPkts_hi,
6560 sblk->stat_IfHCInBroadcastPkts_lo);
6563 if (sblk->stat_IfHCInMulticastPkts_hi ||
6564 sblk->stat_IfHCInMulticastPkts_lo) {
6565 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
6566 sblk->stat_IfHCInMulticastPkts_hi,
6567 sblk->stat_IfHCInMulticastPkts_lo);
6570 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
6571 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
6572 sblk->stat_IfHCOutUcastPkts_hi,
6573 sblk->stat_IfHCOutUcastPkts_lo);
6576 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
6577 sblk->stat_IfHCOutBroadcastPkts_lo) {
6578 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
6579 sblk->stat_IfHCOutBroadcastPkts_hi,
6580 sblk->stat_IfHCOutBroadcastPkts_lo);
6583 if (sblk->stat_IfHCOutMulticastPkts_hi ||
6584 sblk->stat_IfHCOutMulticastPkts_lo) {
6585 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
6586 sblk->stat_IfHCOutMulticastPkts_hi,
6587 sblk->stat_IfHCOutMulticastPkts_lo);
6590 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
6591 if_printf(ifp, " 0x%08X : "
6592 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
6593 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
6596 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
6597 if_printf(ifp, " 0x%08X : "
6598 "Dot3StatsCarrierSenseErrors\n",
6599 sblk->stat_Dot3StatsCarrierSenseErrors);
6602 if (sblk->stat_Dot3StatsFCSErrors) {
6603 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
6604 sblk->stat_Dot3StatsFCSErrors);
6607 if (sblk->stat_Dot3StatsAlignmentErrors) {
6608 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
6609 sblk->stat_Dot3StatsAlignmentErrors);
6612 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
6613 if_printf(ifp, " 0x%08X : "
6614 "Dot3StatsSingleCollisionFrames\n",
6615 sblk->stat_Dot3StatsSingleCollisionFrames);
6618 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
6619 if_printf(ifp, " 0x%08X : "
6620 "Dot3StatsMultipleCollisionFrames\n",
6621 sblk->stat_Dot3StatsMultipleCollisionFrames);
6624 if (sblk->stat_Dot3StatsDeferredTransmissions) {
6625 if_printf(ifp, " 0x%08X : "
6626 "Dot3StatsDeferredTransmissions\n",
6627 sblk->stat_Dot3StatsDeferredTransmissions);
6630 if (sblk->stat_Dot3StatsExcessiveCollisions) {
6631 if_printf(ifp, " 0x%08X : "
6632 "Dot3StatsExcessiveCollisions\n",
6633 sblk->stat_Dot3StatsExcessiveCollisions);
6636 if (sblk->stat_Dot3StatsLateCollisions) {
6637 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
6638 sblk->stat_Dot3StatsLateCollisions);
6641 if (sblk->stat_EtherStatsCollisions) {
6642 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
6643 sblk->stat_EtherStatsCollisions);
6646 if (sblk->stat_EtherStatsFragments) {
6647 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
6648 sblk->stat_EtherStatsFragments);
6651 if (sblk->stat_EtherStatsJabbers) {
6652 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
6653 sblk->stat_EtherStatsJabbers);
6656 if (sblk->stat_EtherStatsUndersizePkts) {
6657 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
6658 sblk->stat_EtherStatsUndersizePkts);
6661 if (sblk->stat_EtherStatsOverrsizePkts) {
6662 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
6663 sblk->stat_EtherStatsOverrsizePkts);
6666 if (sblk->stat_EtherStatsPktsRx64Octets) {
6667 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
6668 sblk->stat_EtherStatsPktsRx64Octets);
6671 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
6672 if_printf(ifp, " 0x%08X : "
6673 "EtherStatsPktsRx65Octetsto127Octets\n",
6674 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
6677 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
6678 if_printf(ifp, " 0x%08X : "
6679 "EtherStatsPktsRx128Octetsto255Octets\n",
6680 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
6683 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
6684 if_printf(ifp, " 0x%08X : "
6685 "EtherStatsPktsRx256Octetsto511Octets\n",
6686 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
6689 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
6690 if_printf(ifp, " 0x%08X : "
6691 "EtherStatsPktsRx512Octetsto1023Octets\n",
6692 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
6695 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
6696 if_printf(ifp, " 0x%08X : "
6697 "EtherStatsPktsRx1024Octetsto1522Octets\n",
6698 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
6701 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
6702 if_printf(ifp, " 0x%08X : "
6703 "EtherStatsPktsRx1523Octetsto9022Octets\n",
6704 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
6707 if (sblk->stat_EtherStatsPktsTx64Octets) {
6708 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
6709 sblk->stat_EtherStatsPktsTx64Octets);
6712 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
6713 if_printf(ifp, " 0x%08X : "
6714 "EtherStatsPktsTx65Octetsto127Octets\n",
6715 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
6718 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
6719 if_printf(ifp, " 0x%08X : "
6720 "EtherStatsPktsTx128Octetsto255Octets\n",
6721 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
6724 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
6725 if_printf(ifp, " 0x%08X : "
6726 "EtherStatsPktsTx256Octetsto511Octets\n",
6727 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
6730 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
6731 if_printf(ifp, " 0x%08X : "
6732 "EtherStatsPktsTx512Octetsto1023Octets\n",
6733 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
6736 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
6737 if_printf(ifp, " 0x%08X : "
6738 "EtherStatsPktsTx1024Octetsto1522Octets\n",
6739 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
6742 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
6743 if_printf(ifp, " 0x%08X : "
6744 "EtherStatsPktsTx1523Octetsto9022Octets\n",
6745 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
6748 if (sblk->stat_XonPauseFramesReceived) {
6749 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
6750 sblk->stat_XonPauseFramesReceived);
6753 if (sblk->stat_XoffPauseFramesReceived) {
6754 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
6755 sblk->stat_XoffPauseFramesReceived);
6758 if (sblk->stat_OutXonSent) {
6759 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6760 sblk->stat_OutXonSent);
6763 if (sblk->stat_OutXoffSent) {
6764 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6765 sblk->stat_OutXoffSent);
6768 if (sblk->stat_FlowControlDone) {
6769 if_printf(ifp, " 0x%08X : FlowControlDone\n",
6770 sblk->stat_FlowControlDone);
6773 if (sblk->stat_MacControlFramesReceived) {
6774 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
6775 sblk->stat_MacControlFramesReceived);
6778 if (sblk->stat_XoffStateEntered) {
6779 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
6780 sblk->stat_XoffStateEntered);
6783 if (sblk->stat_IfInFramesL2FilterDiscards) {
6784 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
6787 if (sblk->stat_IfInRuleCheckerDiscards) {
6788 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
6789 sblk->stat_IfInRuleCheckerDiscards);
6792 if (sblk->stat_IfInFTQDiscards) {
6793 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
6794 sblk->stat_IfInFTQDiscards);
6797 if (sblk->stat_IfInMBUFDiscards) {
6798 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
6799 sblk->stat_IfInMBUFDiscards);
6802 if (sblk->stat_IfInRuleCheckerP4Hit) {
6803 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
6804 sblk->stat_IfInRuleCheckerP4Hit);
6807 if (sblk->stat_CatchupInRuleCheckerDiscards) {
6808 if_printf(ifp, " 0x%08X : "
6809 "CatchupInRuleCheckerDiscards\n",
6810 sblk->stat_CatchupInRuleCheckerDiscards);
6813 if (sblk->stat_CatchupInFTQDiscards) {
6814 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
6815 sblk->stat_CatchupInFTQDiscards);
6818 if (sblk->stat_CatchupInMBUFDiscards) {
6819 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
6820 sblk->stat_CatchupInMBUFDiscards);
6823 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
6824 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
6825 sblk->stat_CatchupInRuleCheckerP4Hit);
6829 "----------------------------"
6831 "----------------------------\n");
6835 /****************************************************************************/
6836 /* Prints out a summary of the driver state. */
6840 /****************************************************************************/
6842 bce_dump_driver_state(struct bce_softc *sc)
6844 struct ifnet *ifp = &sc->arpcom.ac_if;
6845 uint32_t val_hi, val_lo;
6848 "-----------------------------"
6850 "-----------------------------\n");
6852 val_hi = BCE_ADDR_HI(sc);
6853 val_lo = BCE_ADDR_LO(sc);
6854 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
6855 "virtual address\n", val_hi, val_lo);
6857 val_hi = BCE_ADDR_HI(sc->status_block);
6858 val_lo = BCE_ADDR_LO(sc->status_block);
6859 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
6860 "virtual address\n", val_hi, val_lo);
6862 val_hi = BCE_ADDR_HI(sc->stats_block);
6863 val_lo = BCE_ADDR_LO(sc->stats_block);
6864 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
6865 "virtual address\n", val_hi, val_lo);
6867 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
6868 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
6869 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
6870 "virtual adddress\n", val_hi, val_lo);
6872 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
6873 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
6874 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
6875 "virtual address\n", val_hi, val_lo);
6877 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
6878 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
6879 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
6880 "virtual address\n", val_hi, val_lo);
6882 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
6883 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
6884 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
6885 "virtual address\n", val_hi, val_lo);
6887 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
6888 "h/w intrs\n", sc->interrupts_generated);
6890 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
6891 "rx interrupts handled\n", sc->rx_interrupts);
6893 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
6894 "tx interrupts handled\n", sc->tx_interrupts);
6896 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
6897 "status block index\n", sc->last_status_idx);
6899 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
6900 "tx producer index\n",
6901 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
6903 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
6904 "tx consumer index\n",
6905 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
6907 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
6908 "tx producer bseq index\n", sc->tx_prod_bseq);
6910 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
6911 "rx producer index\n",
6912 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
6914 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
6915 "rx consumer index\n",
6916 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
6918 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
6919 "rx producer bseq index\n", sc->rx_prod_bseq);
6921 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6922 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6924 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
6925 "free rx_bd's\n", sc->free_rx_bd);
6927 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
6928 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
6930 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
6931 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
6933 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6934 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6936 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
6939 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
6940 sc->tx_hi_watermark, sc->max_tx_bd);
6942 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
6943 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
6946 "----------------------------"
6948 "----------------------------\n");
6952 /****************************************************************************/
6953 /* Prints out the hardware state through a summary of important registers, */
\r
6954 /* followed by a complete register dump. */
6958 /****************************************************************************/
6960 bce_dump_hw_state(struct bce_softc *sc)
6962 struct ifnet *ifp = &sc->arpcom.ac_if;
6967 "----------------------------"
6969 "----------------------------\n");
6971 if_printf(ifp, "0x%08X - bootcode version\n", sc->bce_fw_ver);
6973 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
6974 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
6975 val1, BCE_MISC_ENABLE_STATUS_BITS);
6977 val1 = REG_RD(sc, BCE_DMA_STATUS);
6978 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
6980 val1 = REG_RD(sc, BCE_CTX_STATUS);
6981 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
6983 val1 = REG_RD(sc, BCE_EMAC_STATUS);
6984 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
6985 val1, BCE_EMAC_STATUS);
6987 val1 = REG_RD(sc, BCE_RPM_STATUS);
6988 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
6990 val1 = REG_RD(sc, BCE_TBDR_STATUS);
6991 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
6992 val1, BCE_TBDR_STATUS);
6994 val1 = REG_RD(sc, BCE_TDMA_STATUS);
6995 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
6996 val1, BCE_TDMA_STATUS);
6998 val1 = REG_RD(sc, BCE_HC_STATUS);
6999 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7001 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7002 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7003 val1, BCE_TXP_CPU_STATE);
7005 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7006 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7007 val1, BCE_TPAT_CPU_STATE);
7009 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7010 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7011 val1, BCE_RXP_CPU_STATE);
7013 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7014 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7015 val1, BCE_COM_CPU_STATE);
7017 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7018 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7019 val1, BCE_MCP_CPU_STATE);
7021 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7022 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7023 val1, BCE_CP_CPU_STATE);
7026 "----------------------------"
7028 "----------------------------\n");
7031 "----------------------------"
7033 "----------------------------\n");
7035 for (i = 0x400; i < 0x8000; i += 0x10) {
7036 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7038 REG_RD(sc, i + 0x4),
7039 REG_RD(sc, i + 0x8),
7040 REG_RD(sc, i + 0xc));
7044 "----------------------------"
7046 "----------------------------\n");
7050 /****************************************************************************/
7051 /* Prints out the TXP state. */
\r
7055 /****************************************************************************/
7057 bce_dump_txp_state(struct bce_softc *sc)
7059 struct ifnet *ifp = &sc->arpcom.ac_if;
7064 "----------------------------"
7066 "----------------------------\n");
7068 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7069 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7070 val1, BCE_TXP_CPU_MODE);
7072 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7073 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7074 val1, BCE_TXP_CPU_STATE);
7076 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7077 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7078 val1, BCE_TXP_CPU_EVENT_MASK);
7081 "----------------------------"
7083 "----------------------------\n");
7085 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7086 /* Skip the big blank spaces */
7087 if (i < 0x454000 && i > 0x5ffff) {
7088 if_printf(ifp, "0x%04X: "
7089 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7091 REG_RD_IND(sc, i + 0x4),
7092 REG_RD_IND(sc, i + 0x8),
7093 REG_RD_IND(sc, i + 0xc));
7098 "----------------------------"
7100 "----------------------------\n");
7104 /****************************************************************************/
7105 /* Prints out the RXP state. */
\r
7109 /****************************************************************************/
7111 bce_dump_rxp_state(struct bce_softc *sc)
7113 struct ifnet *ifp = &sc->arpcom.ac_if;
7118 "----------------------------"
7120 "----------------------------\n");
7122 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7123 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7124 val1, BCE_RXP_CPU_MODE);
7126 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7127 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7128 val1, BCE_RXP_CPU_STATE);
7130 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7131 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7132 val1, BCE_RXP_CPU_EVENT_MASK);
7135 "----------------------------"
7137 "----------------------------\n");
7139 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7140 /* Skip the big blank sapces */
7141 if (i < 0xc5400 && i > 0xdffff) {
7142 if_printf(ifp, "0x%04X: "
7143 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7145 REG_RD_IND(sc, i + 0x4),
7146 REG_RD_IND(sc, i + 0x8),
7147 REG_RD_IND(sc, i + 0xc));
7152 "----------------------------"
7154 "----------------------------\n");
7158 /****************************************************************************/
7159 /* Prints out the TPAT state. */
\r
7163 /****************************************************************************/
7165 bce_dump_tpat_state(struct bce_softc *sc)
7167 struct ifnet *ifp = &sc->arpcom.ac_if;
7172 "----------------------------"
7174 "----------------------------\n");
7176 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7177 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7178 val1, BCE_TPAT_CPU_MODE);
7180 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7181 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7182 val1, BCE_TPAT_CPU_STATE);
7184 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7185 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7186 val1, BCE_TPAT_CPU_EVENT_MASK);
7189 "----------------------------"
7191 "----------------------------\n");
7193 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7194 /* Skip the big blank spaces */
7195 if (i < 0x854000 && i > 0x9ffff) {
7196 if_printf(ifp, "0x%04X: "
7197 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7199 REG_RD_IND(sc, i + 0x4),
7200 REG_RD_IND(sc, i + 0x8),
7201 REG_RD_IND(sc, i + 0xc));
7206 "----------------------------"
7208 "----------------------------\n");
7212 /****************************************************************************/
7213 /* Prints out the driver state and then enters the debugger. */
7217 /****************************************************************************/
7219 bce_breakpoint(struct bce_softc *sc)
7222 bce_freeze_controller(sc);
7225 bce_dump_driver_state(sc);
7226 bce_dump_status_block(sc);
7227 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7228 bce_dump_hw_state(sc);
7229 bce_dump_txp_state(sc);
7232 bce_unfreeze_controller(sc);
7235 /* Call the debugger. */
7239 #endif /* BCE_DEBUG */
7242 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7244 struct bce_softc *sc = arg1;
7246 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7247 &sc->bce_tx_quick_cons_trip_int,
7248 BCE_COALMASK_TX_BDS_INT);
7252 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7254 struct bce_softc *sc = arg1;
7256 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7257 &sc->bce_tx_quick_cons_trip,
7258 BCE_COALMASK_TX_BDS);
7262 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7264 struct bce_softc *sc = arg1;
7266 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7267 &sc->bce_tx_ticks_int,
7268 BCE_COALMASK_TX_TICKS_INT);
7272 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7274 struct bce_softc *sc = arg1;
7276 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7278 BCE_COALMASK_TX_TICKS);
7282 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7284 struct bce_softc *sc = arg1;
7286 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7287 &sc->bce_rx_quick_cons_trip_int,
7288 BCE_COALMASK_RX_BDS_INT);
7292 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7294 struct bce_softc *sc = arg1;
7296 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7297 &sc->bce_rx_quick_cons_trip,
7298 BCE_COALMASK_RX_BDS);
7302 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7304 struct bce_softc *sc = arg1;
7306 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7307 &sc->bce_rx_ticks_int,
7308 BCE_COALMASK_RX_TICKS_INT);
7312 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7314 struct bce_softc *sc = arg1;
7316 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7318 BCE_COALMASK_RX_TICKS);
7322 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7323 uint32_t coalchg_mask)
7325 struct bce_softc *sc = arg1;
7326 struct ifnet *ifp = &sc->arpcom.ac_if;
7329 lwkt_serialize_enter(ifp->if_serializer);
7332 error = sysctl_handle_int(oidp, &v, 0, req);
7333 if (!error && req->newptr != NULL) {
7338 sc->bce_coalchg_mask |= coalchg_mask;
7342 lwkt_serialize_exit(ifp->if_serializer);
7347 bce_coal_change(struct bce_softc *sc)
7349 struct ifnet *ifp = &sc->arpcom.ac_if;
7351 ASSERT_SERIALIZED(ifp->if_serializer);
7353 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7354 sc->bce_coalchg_mask = 0;
7358 if (sc->bce_coalchg_mask &
7359 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7360 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7361 (sc->bce_tx_quick_cons_trip_int << 16) |
7362 sc->bce_tx_quick_cons_trip);
7364 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7365 sc->bce_tx_quick_cons_trip,
7366 sc->bce_tx_quick_cons_trip_int);
7370 if (sc->bce_coalchg_mask &
7371 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7372 REG_WR(sc, BCE_HC_TX_TICKS,
7373 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7375 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7376 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7380 if (sc->bce_coalchg_mask &
7381 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7382 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7383 (sc->bce_rx_quick_cons_trip_int << 16) |
7384 sc->bce_rx_quick_cons_trip);
7386 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7387 sc->bce_rx_quick_cons_trip,
7388 sc->bce_rx_quick_cons_trip_int);
7392 if (sc->bce_coalchg_mask &
7393 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7394 REG_WR(sc, BCE_HC_RX_TICKS,
7395 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7397 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7398 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7402 sc->bce_coalchg_mask = 0;