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.21 2008/11/19 13:57:49 sephe Exp $
35 * The following controllers are supported by this driver:
39 * The following controllers are not supported by this driver:
41 * BCM5706S A0, A1, A2, A3
43 * BCM5708S A0, B0, B1, B2
47 #include "opt_polling.h"
49 #include <sys/param.h>
51 #include <sys/endian.h>
52 #include <sys/kernel.h>
53 #include <sys/interrupt.h>
55 #include <sys/malloc.h>
56 #include <sys/queue.h>
58 #include <sys/random.h>
61 #include <sys/serialize.h>
62 #include <sys/socket.h>
63 #include <sys/sockio.h>
64 #include <sys/sysctl.h>
67 #include <net/ethernet.h>
69 #include <net/if_arp.h>
70 #include <net/if_dl.h>
71 #include <net/if_media.h>
72 #include <net/if_types.h>
73 #include <net/ifq_var.h>
74 #include <net/vlan/if_vlan_var.h>
75 #include <net/vlan/if_vlan_ether.h>
77 #include <dev/netif/mii_layer/mii.h>
78 #include <dev/netif/mii_layer/miivar.h>
80 #include <bus/pci/pcireg.h>
81 #include <bus/pci/pcivar.h>
83 #include "miibus_if.h"
85 #include <dev/netif/bce/if_bcereg.h>
86 #include <dev/netif/bce/if_bcefw.h>
88 /****************************************************************************/
89 /* BCE Debug Options */
90 /****************************************************************************/
93 static uint32_t bce_debug = BCE_WARN;
97 * 1 = 1 in 2,147,483,648
98 * 256 = 1 in 8,388,608
99 * 2048 = 1 in 1,048,576
100 * 65536 = 1 in 32,768
101 * 1048576 = 1 in 2,048
104 * 1073741824 = 1 in 2
106 * bce_debug_l2fhdr_status_check:
107 * How often the l2_fhdr frame error check will fail.
109 * bce_debug_unexpected_attention:
110 * How often the unexpected attention check will fail.
112 * bce_debug_mbuf_allocation_failure:
113 * How often to simulate an mbuf allocation failure.
115 * bce_debug_dma_map_addr_failure:
116 * How often to simulate a DMA mapping failure.
118 * bce_debug_bootcode_running_failure:
119 * How often to simulate a bootcode failure.
121 static int bce_debug_l2fhdr_status_check = 0;
122 static int bce_debug_unexpected_attention = 0;
123 static int bce_debug_mbuf_allocation_failure = 0;
124 static int bce_debug_dma_map_addr_failure = 0;
125 static int bce_debug_bootcode_running_failure = 0;
127 #endif /* BCE_DEBUG */
130 /****************************************************************************/
131 /* PCI Device ID Table */
133 /* Used by bce_probe() to identify the devices supported by this driver. */
134 /****************************************************************************/
135 #define BCE_DEVDESC_MAX 64
137 static struct bce_type bce_devs[] = {
138 /* BCM5706C Controllers and OEM boards. */
139 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
140 "HP NC370T Multifunction Gigabit Server Adapter" },
141 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
142 "HP NC370i Multifunction Gigabit Server Adapter" },
143 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
144 "Broadcom NetXtreme II BCM5706 1000Base-T" },
146 /* BCM5706S controllers and OEM boards. */
147 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
148 "HP NC370F Multifunction Gigabit Server Adapter" },
149 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
150 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
152 /* BCM5708C controllers and OEM boards. */
153 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
154 "Broadcom NetXtreme II BCM5708 1000Base-T" },
156 /* BCM5708S controllers and OEM boards. */
157 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
158 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
163 /****************************************************************************/
164 /* Supported Flash NVRAM device data. */
165 /****************************************************************************/
166 static const struct flash_spec flash_table[] =
169 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
170 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
171 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
173 /* Expansion entry 0001 */
174 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
175 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
176 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
178 /* Saifun SA25F010 (non-buffered flash) */
179 /* strap, cfg1, & write1 need updates */
180 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
181 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
182 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
183 "Non-buffered flash (128kB)"},
184 /* Saifun SA25F020 (non-buffered flash) */
185 /* strap, cfg1, & write1 need updates */
186 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
187 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
188 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
189 "Non-buffered flash (256kB)"},
190 /* Expansion entry 0100 */
191 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
192 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
193 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
195 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
196 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
197 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
198 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
199 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
200 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
201 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
202 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
203 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
204 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
205 /* Saifun SA25F005 (non-buffered flash) */
206 /* strap, cfg1, & write1 need updates */
207 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
208 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
209 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
210 "Non-buffered flash (64kB)"},
212 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
213 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
214 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
216 /* Expansion entry 1001 */
217 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
218 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
219 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
221 /* Expansion entry 1010 */
222 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
223 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
224 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
226 /* ATMEL AT45DB011B (buffered flash) */
227 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
228 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
229 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
230 "Buffered flash (128kB)"},
231 /* Expansion entry 1100 */
232 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
233 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
234 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
236 /* Expansion entry 1101 */
237 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
238 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
239 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
241 /* Ateml Expansion entry 1110 */
242 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
243 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
244 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
245 "Entry 1110 (Atmel)"},
246 /* ATMEL AT45DB021B (buffered flash) */
247 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
248 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
249 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
250 "Buffered flash (256kB)"},
254 /****************************************************************************/
255 /* DragonFly device entry points. */
256 /****************************************************************************/
257 static int bce_probe(device_t);
258 static int bce_attach(device_t);
259 static int bce_detach(device_t);
260 static void bce_shutdown(device_t);
262 /****************************************************************************/
263 /* BCE Debug Data Structure Dump Routines */
264 /****************************************************************************/
266 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
267 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
268 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
269 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
270 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
271 static void bce_dump_l2fhdr(struct bce_softc *, int,
272 struct l2_fhdr *) __unused;
273 static void bce_dump_tx_chain(struct bce_softc *, int, int);
274 static void bce_dump_rx_chain(struct bce_softc *, int, int);
275 static void bce_dump_status_block(struct bce_softc *);
276 static void bce_dump_driver_state(struct bce_softc *);
277 static void bce_dump_stats_block(struct bce_softc *) __unused;
278 static void bce_dump_hw_state(struct bce_softc *);
279 static void bce_dump_txp_state(struct bce_softc *);
280 static void bce_dump_rxp_state(struct bce_softc *) __unused;
281 static void bce_dump_tpat_state(struct bce_softc *) __unused;
282 static void bce_freeze_controller(struct bce_softc *) __unused;
283 static void bce_unfreeze_controller(struct bce_softc *) __unused;
284 static void bce_breakpoint(struct bce_softc *);
285 #endif /* BCE_DEBUG */
288 /****************************************************************************/
289 /* BCE Register/Memory Access Routines */
290 /****************************************************************************/
291 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
292 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
293 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
294 static int bce_miibus_read_reg(device_t, int, int);
295 static int bce_miibus_write_reg(device_t, int, int, int);
296 static void bce_miibus_statchg(device_t);
299 /****************************************************************************/
300 /* BCE NVRAM Access Routines */
301 /****************************************************************************/
302 static int bce_acquire_nvram_lock(struct bce_softc *);
303 static int bce_release_nvram_lock(struct bce_softc *);
304 static void bce_enable_nvram_access(struct bce_softc *);
305 static void bce_disable_nvram_access(struct bce_softc *);
306 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
308 static int bce_init_nvram(struct bce_softc *);
309 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
310 static int bce_nvram_test(struct bce_softc *);
311 #ifdef BCE_NVRAM_WRITE_SUPPORT
312 static int bce_enable_nvram_write(struct bce_softc *);
313 static void bce_disable_nvram_write(struct bce_softc *);
314 static int bce_nvram_erase_page(struct bce_softc *, uint32_t);
315 static int bce_nvram_write_dword(struct bce_softc *, uint32_t, uint8_t *,
317 static int bce_nvram_write(struct bce_softc *, uint32_t, uint8_t *,
321 /****************************************************************************/
322 /* BCE DMA Allocate/Free Routines */
323 /****************************************************************************/
324 static int bce_dma_alloc(struct bce_softc *);
325 static void bce_dma_free(struct bce_softc *);
326 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
327 static void bce_dma_map_mbuf(void *, bus_dma_segment_t *, int,
330 /****************************************************************************/
331 /* BCE Firmware Synchronization and Load */
332 /****************************************************************************/
333 static int bce_fw_sync(struct bce_softc *, uint32_t);
334 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
336 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
338 static void bce_init_cpus(struct bce_softc *);
340 static void bce_stop(struct bce_softc *);
341 static int bce_reset(struct bce_softc *, uint32_t);
342 static int bce_chipinit(struct bce_softc *);
343 static int bce_blockinit(struct bce_softc *);
344 static int bce_newbuf_std(struct bce_softc *, struct mbuf *,
345 uint16_t *, uint16_t *, uint32_t *);
347 static int bce_init_tx_chain(struct bce_softc *);
348 static int bce_init_rx_chain(struct bce_softc *);
349 static void bce_free_rx_chain(struct bce_softc *);
350 static void bce_free_tx_chain(struct bce_softc *);
352 static int bce_encap(struct bce_softc *, struct mbuf **);
353 static void bce_start(struct ifnet *);
354 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
355 static void bce_watchdog(struct ifnet *);
356 static int bce_ifmedia_upd(struct ifnet *);
357 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
358 static void bce_init(void *);
359 static void bce_mgmt_init(struct bce_softc *);
361 static void bce_init_ctx(struct bce_softc *);
362 static void bce_get_mac_addr(struct bce_softc *);
363 static void bce_set_mac_addr(struct bce_softc *);
364 static void bce_phy_intr(struct bce_softc *);
365 static void bce_rx_intr(struct bce_softc *, int);
366 static void bce_tx_intr(struct bce_softc *);
367 static void bce_disable_intr(struct bce_softc *);
368 static void bce_enable_intr(struct bce_softc *);
370 #ifdef DEVICE_POLLING
371 static void bce_poll(struct ifnet *, enum poll_cmd, int);
373 static void bce_intr(void *);
374 static void bce_set_rx_mode(struct bce_softc *);
375 static void bce_stats_update(struct bce_softc *);
376 static void bce_tick(void *);
377 static void bce_tick_serialized(struct bce_softc *);
378 static void bce_add_sysctls(struct bce_softc *);
380 static void bce_coal_change(struct bce_softc *);
381 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
382 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
383 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
384 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
385 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
386 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
387 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
388 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
389 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
390 uint32_t *, uint32_t);
394 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
395 * takes 1023 as the TX ticks limit. However, using 1023 will
396 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
397 * there is _no_ network activity on the NIC.
399 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
400 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
401 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
402 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
403 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
404 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
405 static uint32_t bce_rx_ticks_int = 125; /* bcm: 18 */
406 static uint32_t bce_rx_ticks = 125; /* bcm: 18 */
408 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
409 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
410 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
411 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
412 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
413 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
414 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
415 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
417 /****************************************************************************/
418 /* DragonFly device dispatch table. */
419 /****************************************************************************/
420 static device_method_t bce_methods[] = {
421 /* Device interface */
422 DEVMETHOD(device_probe, bce_probe),
423 DEVMETHOD(device_attach, bce_attach),
424 DEVMETHOD(device_detach, bce_detach),
425 DEVMETHOD(device_shutdown, bce_shutdown),
428 DEVMETHOD(bus_print_child, bus_generic_print_child),
429 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
432 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
433 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
434 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
439 static driver_t bce_driver = {
442 sizeof(struct bce_softc)
445 static devclass_t bce_devclass;
448 DECLARE_DUMMY_MODULE(if_xl);
449 MODULE_DEPEND(bce, miibus, 1, 1, 1);
450 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, 0, 0);
451 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
454 /****************************************************************************/
455 /* Device probe function. */
457 /* Compares the device to the driver's list of supported devices and */
458 /* reports back to the OS whether this is the right driver for the device. */
461 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
462 /****************************************************************************/
464 bce_probe(device_t dev)
467 uint16_t vid, did, svid, sdid;
469 /* Get the data for the device to be probed. */
470 vid = pci_get_vendor(dev);
471 did = pci_get_device(dev);
472 svid = pci_get_subvendor(dev);
473 sdid = pci_get_subdevice(dev);
475 /* Look through the list of known devices for a match. */
476 for (t = bce_devs; t->bce_name != NULL; ++t) {
477 if (vid == t->bce_vid && did == t->bce_did &&
478 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
479 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
480 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
483 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
485 /* Print out the device identity. */
486 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
488 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
490 device_set_desc_copy(dev, descbuf);
491 kfree(descbuf, M_TEMP);
499 /****************************************************************************/
500 /* Device attach function. */
502 /* Allocates device resources, performs secondary chip identification, */
503 /* resets and initializes the hardware, and initializes driver instance */
507 /* 0 on success, positive value on failure. */
508 /****************************************************************************/
510 bce_attach(device_t dev)
512 struct bce_softc *sc = device_get_softc(dev);
513 struct ifnet *ifp = &sc->arpcom.ac_if;
521 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
523 pci_enable_busmaster(dev);
525 /* Allocate PCI memory resources. */
527 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
528 RF_ACTIVE | PCI_RF_DENSE);
529 if (sc->bce_res_mem == NULL) {
530 device_printf(dev, "PCI memory allocation failed\n");
533 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
534 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
536 /* Allocate PCI IRQ resources. */
538 count = pci_msi_count(dev);
539 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
541 sc->bce_flags |= BCE_USING_MSI_FLAG;
545 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
546 RF_SHAREABLE | RF_ACTIVE);
547 if (sc->bce_res_irq == NULL) {
548 device_printf(dev, "PCI map interrupt failed\n");
554 * Configure byte swap and enable indirect register access.
555 * Rely on CPU to do target byte swapping on big endian systems.
556 * Access to registers outside of PCI configurtion space are not
557 * valid until this is done.
559 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
560 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
561 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
563 /* Save ASIC revsion info. */
564 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
566 /* Weed out any non-production controller revisions. */
567 switch(BCE_CHIP_ID(sc)) {
568 case BCE_CHIP_ID_5706_A0:
569 case BCE_CHIP_ID_5706_A1:
570 case BCE_CHIP_ID_5708_A0:
571 case BCE_CHIP_ID_5708_B0:
572 device_printf(dev, "Unsupported chip id 0x%08x!\n",
579 * The embedded PCIe to PCI-X bridge (EPB)
580 * in the 5708 cannot address memory above
581 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
583 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
584 sc->max_bus_addr = BCE_BUS_SPACE_MAXADDR;
586 sc->max_bus_addr = BUS_SPACE_MAXADDR;
589 * Find the base address for shared memory access.
590 * Newer versions of bootcode use a signature and offset
591 * while older versions use a fixed address.
593 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
594 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) == BCE_SHM_HDR_SIGNATURE_SIG)
595 sc->bce_shmem_base = REG_RD_IND(sc, BCE_SHM_HDR_ADDR_0);
597 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
599 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
601 /* Get PCI bus information (speed and type). */
602 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
603 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
606 sc->bce_flags |= BCE_PCIX_FLAG;
608 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
609 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
611 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
612 sc->bus_speed_mhz = 133;
615 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
616 sc->bus_speed_mhz = 100;
619 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
620 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
621 sc->bus_speed_mhz = 66;
624 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
625 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
626 sc->bus_speed_mhz = 50;
629 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
630 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
631 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
632 sc->bus_speed_mhz = 33;
636 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
637 sc->bus_speed_mhz = 66;
639 sc->bus_speed_mhz = 33;
642 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
643 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
645 device_printf(dev, "ASIC ID 0x%08X; Revision (%c%d); PCI%s %s %dMHz\n",
647 ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
648 (BCE_CHIP_ID(sc) & 0x0ff0) >> 4,
649 (sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : "",
650 (sc->bce_flags & BCE_PCI_32BIT_FLAG) ?
651 "32-bit" : "64-bit", sc->bus_speed_mhz);
653 /* Reset the controller. */
654 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
658 /* Initialize the controller. */
659 rc = bce_chipinit(sc);
661 device_printf(dev, "Controller initialization failed!\n");
665 /* Perform NVRAM test. */
666 rc = bce_nvram_test(sc);
668 device_printf(dev, "NVRAM test failed!\n");
672 /* Fetch the permanent Ethernet MAC address. */
673 bce_get_mac_addr(sc);
676 * Trip points control how many BDs
677 * should be ready before generating an
678 * interrupt while ticks control how long
679 * a BD can sit in the chain before
680 * generating an interrupt. Set the default
681 * values for the RX and TX rings.
685 /* Force more frequent interrupts. */
686 sc->bce_tx_quick_cons_trip_int = 1;
687 sc->bce_tx_quick_cons_trip = 1;
688 sc->bce_tx_ticks_int = 0;
689 sc->bce_tx_ticks = 0;
691 sc->bce_rx_quick_cons_trip_int = 1;
692 sc->bce_rx_quick_cons_trip = 1;
693 sc->bce_rx_ticks_int = 0;
694 sc->bce_rx_ticks = 0;
696 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
697 sc->bce_tx_quick_cons_trip = bce_tx_bds;
698 sc->bce_tx_ticks_int = bce_tx_ticks_int;
699 sc->bce_tx_ticks = bce_tx_ticks;
701 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
702 sc->bce_rx_quick_cons_trip = bce_rx_bds;
703 sc->bce_rx_ticks_int = bce_rx_ticks_int;
704 sc->bce_rx_ticks = bce_rx_ticks;
707 /* Update statistics once every second. */
708 sc->bce_stats_ticks = 1000000 & 0xffff00;
711 * The copper based NetXtreme II controllers
712 * use an integrated PHY at address 1 while
713 * the SerDes controllers use a PHY at
716 sc->bce_phy_addr = 1;
718 if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
719 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
720 sc->bce_flags |= BCE_NO_WOL_FLAG;
721 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708) {
722 sc->bce_phy_addr = 2;
723 val = REG_RD_IND(sc, sc->bce_shmem_base +
724 BCE_SHARED_HW_CFG_CONFIG);
725 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
726 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
730 /* Allocate DMA memory resources. */
731 rc = bce_dma_alloc(sc);
733 device_printf(dev, "DMA resource allocation failed!\n");
737 /* Initialize the ifnet interface. */
739 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
740 ifp->if_ioctl = bce_ioctl;
741 ifp->if_start = bce_start;
742 ifp->if_init = bce_init;
743 ifp->if_watchdog = bce_watchdog;
744 #ifdef DEVICE_POLLING
745 ifp->if_poll = bce_poll;
747 ifp->if_mtu = ETHERMTU;
748 ifp->if_hwassist = BCE_IF_HWASSIST;
749 ifp->if_capabilities = BCE_IF_CAPABILITIES;
750 ifp->if_capenable = ifp->if_capabilities;
751 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
752 ifq_set_ready(&ifp->if_snd);
754 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
755 ifp->if_baudrate = IF_Gbps(2.5);
757 ifp->if_baudrate = IF_Gbps(1);
759 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
760 sc->mbuf_alloc_size = MCLBYTES;
762 /* Look for our PHY. */
763 rc = mii_phy_probe(dev, &sc->bce_miibus,
764 bce_ifmedia_upd, bce_ifmedia_sts);
766 device_printf(dev, "PHY probe failed!\n");
770 /* Attach to the Ethernet interface list. */
771 ether_ifattach(ifp, sc->eaddr, NULL);
773 callout_init(&sc->bce_stat_ch);
775 /* Hookup IRQ last. */
776 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, bce_intr, sc,
777 &sc->bce_intrhand, ifp->if_serializer);
779 device_printf(dev, "Failed to setup IRQ!\n");
784 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
785 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
787 /* Print some important debugging info. */
788 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
790 /* Add the supported sysctls to the kernel. */
793 /* Get the firmware running so IPMI still works */
803 /****************************************************************************/
804 /* Device detach function. */
806 /* Stops the controller, resets the controller, and releases resources. */
809 /* 0 on success, positive value on failure. */
810 /****************************************************************************/
812 bce_detach(device_t dev)
814 struct bce_softc *sc = device_get_softc(dev);
816 if (device_is_attached(dev)) {
817 struct ifnet *ifp = &sc->arpcom.ac_if;
819 /* Stop and reset the controller. */
820 lwkt_serialize_enter(ifp->if_serializer);
822 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
823 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
824 lwkt_serialize_exit(ifp->if_serializer);
829 /* If we have a child device on the MII bus remove it too. */
831 device_delete_child(dev, sc->bce_miibus);
832 bus_generic_detach(dev);
834 if (sc->bce_res_irq != NULL) {
835 bus_release_resource(dev, SYS_RES_IRQ,
836 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
841 if (sc->bce_flags & BCE_USING_MSI_FLAG)
842 pci_release_msi(dev);
845 if (sc->bce_res_mem != NULL) {
846 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
852 if (sc->bce_sysctl_tree != NULL)
853 sysctl_ctx_free(&sc->bce_sysctl_ctx);
859 /****************************************************************************/
860 /* Device shutdown function. */
862 /* Stops and resets the controller. */
866 /****************************************************************************/
868 bce_shutdown(device_t dev)
870 struct bce_softc *sc = device_get_softc(dev);
871 struct ifnet *ifp = &sc->arpcom.ac_if;
873 lwkt_serialize_enter(ifp->if_serializer);
875 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
876 lwkt_serialize_exit(ifp->if_serializer);
880 /****************************************************************************/
881 /* Indirect register read. */
883 /* Reads NetXtreme II registers using an index/data register pair in PCI */
884 /* configuration space. Using this mechanism avoids issues with posted */
885 /* reads but is much slower than memory-mapped I/O. */
888 /* The value of the register. */
889 /****************************************************************************/
891 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
893 device_t dev = sc->bce_dev;
895 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
899 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
900 DBPRINT(sc, BCE_EXCESSIVE,
901 "%s(); offset = 0x%08X, val = 0x%08X\n",
902 __func__, offset, val);
906 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
911 /****************************************************************************/
912 /* Indirect register write. */
914 /* Writes NetXtreme II registers using an index/data register pair in PCI */
915 /* configuration space. Using this mechanism avoids issues with posted */
916 /* writes but is muchh slower than memory-mapped I/O. */
920 /****************************************************************************/
922 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
924 device_t dev = sc->bce_dev;
926 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
927 __func__, offset, val);
929 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
930 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
934 /****************************************************************************/
935 /* Context memory write. */
937 /* The NetXtreme II controller uses context memory to track connection */
938 /* information for L2 and higher network protocols. */
942 /****************************************************************************/
944 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t offset,
947 DBPRINT(sc, BCE_EXCESSIVE, "%s(); cid_addr = 0x%08X, offset = 0x%08X, "
948 "val = 0x%08X\n", __func__, cid_addr, offset, val);
951 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
952 REG_WR(sc, BCE_CTX_DATA, val);
956 /****************************************************************************/
957 /* PHY register read. */
959 /* Implements register reads on the MII bus. */
962 /* The value of the register. */
963 /****************************************************************************/
965 bce_miibus_read_reg(device_t dev, int phy, int reg)
967 struct bce_softc *sc = device_get_softc(dev);
971 /* Make sure we are accessing the correct PHY address. */
972 if (phy != sc->bce_phy_addr) {
973 DBPRINT(sc, BCE_VERBOSE,
974 "Invalid PHY address %d for PHY read!\n", phy);
978 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
979 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
980 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
982 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
983 REG_RD(sc, BCE_EMAC_MDIO_MODE);
988 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
989 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
990 BCE_EMAC_MDIO_COMM_START_BUSY;
991 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
993 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
996 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
997 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1000 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1001 val &= BCE_EMAC_MDIO_COMM_DATA;
1006 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1007 if_printf(&sc->arpcom.ac_if,
1008 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1012 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1015 DBPRINT(sc, BCE_EXCESSIVE,
1016 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1017 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1019 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1020 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1021 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1023 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1024 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1028 return (val & 0xffff);
1032 /****************************************************************************/
1033 /* PHY register write. */
1035 /* Implements register writes on the MII bus. */
1038 /* The value of the register. */
1039 /****************************************************************************/
1041 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1043 struct bce_softc *sc = device_get_softc(dev);
1047 /* Make sure we are accessing the correct PHY address. */
1048 if (phy != sc->bce_phy_addr) {
1049 DBPRINT(sc, BCE_WARN,
1050 "Invalid PHY address %d for PHY write!\n", phy);
1054 DBPRINT(sc, BCE_EXCESSIVE,
1055 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1056 __func__, phy, (uint16_t)(reg & 0xffff),
1057 (uint16_t)(val & 0xffff));
1059 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1060 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1061 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1063 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1064 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1069 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1070 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1071 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1072 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1074 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1077 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1078 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1084 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1085 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1087 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1088 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1089 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1091 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1092 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1100 /****************************************************************************/
1101 /* MII bus status change. */
1103 /* Called by the MII bus driver when the PHY establishes link to set the */
1104 /* MAC interface registers. */
1108 /****************************************************************************/
1110 bce_miibus_statchg(device_t dev)
1112 struct bce_softc *sc = device_get_softc(dev);
1113 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1115 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1116 mii->mii_media_active);
1119 /* Decode the interface media flags. */
1120 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1121 switch(IFM_TYPE(mii->mii_media_active)) {
1123 kprintf("Ethernet )");
1126 kprintf("Unknown )");
1130 kprintf(" Media Options: ( ");
1131 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1133 kprintf("Autoselect )");
1136 kprintf("Manual )");
1142 kprintf("10Base-T )");
1145 kprintf("100Base-TX )");
1148 kprintf("1000Base-SX )");
1151 kprintf("1000Base-T )");
1158 kprintf(" Global Options: (");
1159 if (mii->mii_media_active & IFM_FDX)
1160 kprintf(" FullDuplex");
1161 if (mii->mii_media_active & IFM_HDX)
1162 kprintf(" HalfDuplex");
1163 if (mii->mii_media_active & IFM_LOOP)
1164 kprintf(" Loopback");
1165 if (mii->mii_media_active & IFM_FLAG0)
1167 if (mii->mii_media_active & IFM_FLAG1)
1169 if (mii->mii_media_active & IFM_FLAG2)
1174 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1177 * Set MII or GMII interface based on the speed negotiated
1180 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1181 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1182 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1183 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1185 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1186 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1190 * Set half or full duplex based on the duplicity negotiated
1193 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1194 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1195 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1197 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1198 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1203 /****************************************************************************/
1204 /* Acquire NVRAM lock. */
1206 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1207 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1208 /* for use by the driver. */
1211 /* 0 on success, positive value on failure. */
1212 /****************************************************************************/
1214 bce_acquire_nvram_lock(struct bce_softc *sc)
1219 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1221 /* Request access to the flash interface. */
1222 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1223 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1224 val = REG_RD(sc, BCE_NVM_SW_ARB);
1225 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1231 if (j >= NVRAM_TIMEOUT_COUNT) {
1232 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1239 /****************************************************************************/
1240 /* Release NVRAM lock. */
1242 /* When the caller is finished accessing NVRAM the lock must be released. */
1243 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1244 /* for use by the driver. */
1247 /* 0 on success, positive value on failure. */
1248 /****************************************************************************/
1250 bce_release_nvram_lock(struct bce_softc *sc)
1255 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1258 * Relinquish nvram interface.
1260 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1262 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1263 val = REG_RD(sc, BCE_NVM_SW_ARB);
1264 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1270 if (j >= NVRAM_TIMEOUT_COUNT) {
1271 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1278 #ifdef BCE_NVRAM_WRITE_SUPPORT
1279 /****************************************************************************/
1280 /* Enable NVRAM write access. */
1282 /* Before writing to NVRAM the caller must enable NVRAM writes. */
1285 /* 0 on success, positive value on failure. */
1286 /****************************************************************************/
1288 bce_enable_nvram_write(struct bce_softc *sc)
1292 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM write.\n");
1294 val = REG_RD(sc, BCE_MISC_CFG);
1295 REG_WR(sc, BCE_MISC_CFG, val | BCE_MISC_CFG_NVM_WR_EN_PCI);
1297 if (!sc->bce_flash_info->buffered) {
1300 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1301 REG_WR(sc, BCE_NVM_COMMAND,
1302 BCE_NVM_COMMAND_WREN | BCE_NVM_COMMAND_DOIT);
1304 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1307 val = REG_RD(sc, BCE_NVM_COMMAND);
1308 if (val & BCE_NVM_COMMAND_DONE)
1312 if (j >= NVRAM_TIMEOUT_COUNT) {
1313 DBPRINT(sc, BCE_WARN, "Timeout writing NVRAM!\n");
1321 /****************************************************************************/
1322 /* Disable NVRAM write access. */
1324 /* When the caller is finished writing to NVRAM write access must be */
1329 /****************************************************************************/
1331 bce_disable_nvram_write(struct bce_softc *sc)
1335 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM write.\n");
1337 val = REG_RD(sc, BCE_MISC_CFG);
1338 REG_WR(sc, BCE_MISC_CFG, val & ~BCE_MISC_CFG_NVM_WR_EN);
1340 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1343 /****************************************************************************/
1344 /* Enable NVRAM access. */
1346 /* Before accessing NVRAM for read or write operations the caller must */
1347 /* enabled NVRAM access. */
1351 /****************************************************************************/
1353 bce_enable_nvram_access(struct bce_softc *sc)
1357 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1359 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1360 /* Enable both bits, even on read. */
1361 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1362 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1366 /****************************************************************************/
1367 /* Disable NVRAM access. */
1369 /* When the caller is finished accessing NVRAM access must be disabled. */
1373 /****************************************************************************/
1375 bce_disable_nvram_access(struct bce_softc *sc)
1379 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1381 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1383 /* Disable both bits, even after read. */
1384 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1385 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1389 #ifdef BCE_NVRAM_WRITE_SUPPORT
1390 /****************************************************************************/
1391 /* Erase NVRAM page before writing. */
1393 /* Non-buffered flash parts require that a page be erased before it is */
1397 /* 0 on success, positive value on failure. */
1398 /****************************************************************************/
1400 bce_nvram_erase_page(struct bce_softc *sc, uint32_t offset)
1405 /* Buffered flash doesn't require an erase. */
1406 if (sc->bce_flash_info->buffered)
1409 DBPRINT(sc, BCE_VERBOSE, "Erasing NVRAM page.\n");
1411 /* Build an erase command. */
1412 cmd = BCE_NVM_COMMAND_ERASE | BCE_NVM_COMMAND_WR |
1413 BCE_NVM_COMMAND_DOIT;
1416 * Clear the DONE bit separately, set the NVRAM adress to erase,
1417 * and issue the erase command.
1419 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1420 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1421 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1423 /* Wait for completion. */
1424 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1429 val = REG_RD(sc, BCE_NVM_COMMAND);
1430 if (val & BCE_NVM_COMMAND_DONE)
1434 if (j >= NVRAM_TIMEOUT_COUNT) {
1435 DBPRINT(sc, BCE_WARN, "Timeout erasing NVRAM.\n");
1440 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1443 /****************************************************************************/
1444 /* Read a dword (32 bits) from NVRAM. */
1446 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1447 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1450 /* 0 on success and the 32 bit value read, positive value on failure. */
1451 /****************************************************************************/
1453 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1459 /* Build the command word. */
1460 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1462 /* Calculate the offset for buffered flash. */
1463 if (sc->bce_flash_info->buffered) {
1464 offset = ((offset / sc->bce_flash_info->page_size) <<
1465 sc->bce_flash_info->page_bits) +
1466 (offset % sc->bce_flash_info->page_size);
1470 * Clear the DONE bit separately, set the address to read,
1471 * and issue the read.
1473 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1474 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1475 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1477 /* Wait for completion. */
1478 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1483 val = REG_RD(sc, BCE_NVM_COMMAND);
1484 if (val & BCE_NVM_COMMAND_DONE) {
1485 val = REG_RD(sc, BCE_NVM_READ);
1488 memcpy(ret_val, &val, 4);
1493 /* Check for errors. */
1494 if (i >= NVRAM_TIMEOUT_COUNT) {
1495 if_printf(&sc->arpcom.ac_if,
1496 "Timeout error reading NVRAM at offset 0x%08X!\n",
1504 #ifdef BCE_NVRAM_WRITE_SUPPORT
1505 /****************************************************************************/
1506 /* Write a dword (32 bits) to NVRAM. */
1508 /* Write a 32 bit word to NVRAM. The caller is assumed to have already */
1509 /* obtained the NVRAM lock, enabled the controller for NVRAM access, and */
1510 /* enabled NVRAM write access. */
1513 /* 0 on success, positive value on failure. */
1514 /****************************************************************************/
1516 bce_nvram_write_dword(struct bce_softc *sc, uint32_t offset, uint8_t *val,
1519 uint32_t cmd, val32;
1522 /* Build the command word. */
1523 cmd = BCE_NVM_COMMAND_DOIT | BCE_NVM_COMMAND_WR | cmd_flags;
1525 /* Calculate the offset for buffered flash. */
1526 if (sc->bce_flash_info->buffered) {
1527 offset = ((offset / sc->bce_flash_info->page_size) <<
1528 sc->bce_flash_info->page_bits) +
1529 (offset % sc->bce_flash_info->page_size);
1533 * Clear the DONE bit separately, convert NVRAM data to big-endian,
1534 * set the NVRAM address to write, and issue the write command
1536 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1537 memcpy(&val32, val, 4);
1538 val32 = htobe32(val32);
1539 REG_WR(sc, BCE_NVM_WRITE, val32);
1540 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1541 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1543 /* Wait for completion. */
1544 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1547 if (REG_RD(sc, BCE_NVM_COMMAND) & BCE_NVM_COMMAND_DONE)
1550 if (j >= NVRAM_TIMEOUT_COUNT) {
1551 if_printf(&sc->arpcom.ac_if,
1552 "Timeout error writing NVRAM at offset 0x%08X\n",
1558 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1561 /****************************************************************************/
1562 /* Initialize NVRAM access. */
1564 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1565 /* access that device. */
1568 /* 0 on success, positive value on failure. */
1569 /****************************************************************************/
1571 bce_init_nvram(struct bce_softc *sc)
1574 int j, entry_count, rc = 0;
1575 const struct flash_spec *flash;
1577 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1579 /* Determine the selected interface. */
1580 val = REG_RD(sc, BCE_NVM_CFG1);
1582 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1585 * Flash reconfiguration is required to support additional
1586 * NVRAM devices not directly supported in hardware.
1587 * Check if the flash interface was reconfigured
1591 if (val & 0x40000000) {
1592 /* Flash interface reconfigured by bootcode. */
1594 DBPRINT(sc, BCE_INFO_LOAD,
1595 "%s(): Flash WAS reconfigured.\n", __func__);
1597 for (j = 0, flash = flash_table; j < entry_count;
1599 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1600 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1601 sc->bce_flash_info = flash;
1606 /* Flash interface not yet reconfigured. */
1609 DBPRINT(sc, BCE_INFO_LOAD,
1610 "%s(): Flash was NOT reconfigured.\n", __func__);
1612 if (val & (1 << 23))
1613 mask = FLASH_BACKUP_STRAP_MASK;
1615 mask = FLASH_STRAP_MASK;
1617 /* Look for the matching NVRAM device configuration data. */
1618 for (j = 0, flash = flash_table; j < entry_count;
1620 /* Check if the device matches any of the known devices. */
1621 if ((val & mask) == (flash->strapping & mask)) {
1622 /* Found a device match. */
1623 sc->bce_flash_info = flash;
1625 /* Request access to the flash interface. */
1626 rc = bce_acquire_nvram_lock(sc);
1630 /* Reconfigure the flash interface. */
1631 bce_enable_nvram_access(sc);
1632 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1633 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1634 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1635 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1636 bce_disable_nvram_access(sc);
1637 bce_release_nvram_lock(sc);
1643 /* Check if a matching device was found. */
1644 if (j == entry_count) {
1645 sc->bce_flash_info = NULL;
1646 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1650 /* Write the flash config data to the shared memory interface. */
1651 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_SHARED_HW_CFG_CONFIG2) &
1652 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1654 sc->bce_flash_size = val;
1656 sc->bce_flash_size = sc->bce_flash_info->total_size;
1658 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1659 __func__, sc->bce_flash_info->total_size);
1661 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1667 /****************************************************************************/
1668 /* Read an arbitrary range of data from NVRAM. */
1670 /* Prepares the NVRAM interface for access and reads the requested data */
1671 /* into the supplied buffer. */
1674 /* 0 on success and the data read, positive value on failure. */
1675 /****************************************************************************/
1677 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1680 uint32_t cmd_flags, offset32, len32, extra;
1686 /* Request access to the flash interface. */
1687 rc = bce_acquire_nvram_lock(sc);
1691 /* Enable access to flash interface */
1692 bce_enable_nvram_access(sc);
1700 /* XXX should we release nvram lock if read_dword() fails? */
1706 pre_len = 4 - (offset & 3);
1708 if (pre_len >= len32) {
1710 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1712 cmd_flags = BCE_NVM_COMMAND_FIRST;
1715 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1719 memcpy(ret_buf, buf + (offset & 3), pre_len);
1727 extra = 4 - (len32 & 3);
1728 len32 = (len32 + 4) & ~3;
1735 cmd_flags = BCE_NVM_COMMAND_LAST;
1737 cmd_flags = BCE_NVM_COMMAND_FIRST |
1738 BCE_NVM_COMMAND_LAST;
1740 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1742 memcpy(ret_buf, buf, 4 - extra);
1743 } else if (len32 > 0) {
1746 /* Read the first word. */
1750 cmd_flags = BCE_NVM_COMMAND_FIRST;
1752 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1754 /* Advance to the next dword. */
1759 while (len32 > 4 && rc == 0) {
1760 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1762 /* Advance to the next dword. */
1771 cmd_flags = BCE_NVM_COMMAND_LAST;
1772 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1774 memcpy(ret_buf, buf, 4 - extra);
1777 /* Disable access to flash interface and release the lock. */
1778 bce_disable_nvram_access(sc);
1779 bce_release_nvram_lock(sc);
1785 #ifdef BCE_NVRAM_WRITE_SUPPORT
1786 /****************************************************************************/
1787 /* Write an arbitrary range of data from NVRAM. */
1789 /* Prepares the NVRAM interface for write access and writes the requested */
1790 /* data from the supplied buffer. The caller is responsible for */
1791 /* calculating any appropriate CRCs. */
1794 /* 0 on success, positive value on failure. */
1795 /****************************************************************************/
1797 bce_nvram_write(struct bce_softc *sc, uint32_t offset, uint8_t *data_buf,
1800 uint32_t written, offset32, len32;
1801 uint8_t *buf, start[4], end[4];
1803 int align_start, align_end;
1809 align_start = (offset32 & 3);
1813 len32 += align_start;
1814 rc = bce_nvram_read(sc, offset32, start, 4);
1820 if (len32 > 4 || !align_start) {
1821 align_end = 4 - (len32 & 3);
1823 rc = bce_nvram_read(sc, offset32 + len32 - 4, end, 4);
1829 if (align_start || align_end) {
1830 buf = kmalloc(len32, M_DEVBUF, M_NOWAIT);
1834 memcpy(buf, start, 4);
1836 memcpy(buf + len32 - 4, end, 4);
1837 memcpy(buf + align_start, data_buf, buf_size);
1841 while (written < len32 && rc == 0) {
1842 uint32_t page_start, page_end, data_start, data_end;
1843 uint32_t addr, cmd_flags;
1845 uint8_t flash_buffer[264];
1847 /* Find the page_start addr */
1848 page_start = offset32 + written;
1849 page_start -= (page_start % sc->bce_flash_info->page_size);
1850 /* Find the page_end addr */
1851 page_end = page_start + sc->bce_flash_info->page_size;
1852 /* Find the data_start addr */
1853 data_start = (written == 0) ? offset32 : page_start;
1854 /* Find the data_end addr */
1855 data_end = (page_end > offset32 + len32) ? (offset32 + len32)
1858 /* Request access to the flash interface. */
1859 rc = bce_acquire_nvram_lock(sc);
1861 goto nvram_write_end;
1863 /* Enable access to flash interface */
1864 bce_enable_nvram_access(sc);
1866 cmd_flags = BCE_NVM_COMMAND_FIRST;
1867 if (sc->bce_flash_info->buffered == 0) {
1871 * Read the whole page into the buffer
1872 * (non-buffer flash only)
1874 for (j = 0; j < sc->bce_flash_info->page_size; j += 4) {
1875 if (j == (sc->bce_flash_info->page_size - 4))
1876 cmd_flags |= BCE_NVM_COMMAND_LAST;
1878 rc = bce_nvram_read_dword(sc, page_start + j,
1882 goto nvram_write_end;
1888 /* Enable writes to flash interface (unlock write-protect) */
1889 rc = bce_enable_nvram_write(sc);
1891 goto nvram_write_end;
1893 /* Erase the page */
1894 rc = bce_nvram_erase_page(sc, page_start);
1896 goto nvram_write_end;
1898 /* Re-enable the write again for the actual write */
1899 bce_enable_nvram_write(sc);
1901 /* Loop to write back the buffer data from page_start to
1904 if (sc->bce_flash_info->buffered == 0) {
1905 for (addr = page_start; addr < data_start;
1906 addr += 4, i += 4) {
1907 rc = bce_nvram_write_dword(sc, addr,
1911 goto nvram_write_end;
1917 /* Loop to write the new data from data_start to data_end */
1918 for (addr = data_start; addr < data_end; addr += 4, i++) {
1919 if (addr == page_end - 4 ||
1920 (sc->bce_flash_info->buffered &&
1921 addr == data_end - 4))
1922 cmd_flags |= BCE_NVM_COMMAND_LAST;
1924 rc = bce_nvram_write_dword(sc, addr, buf, cmd_flags);
1926 goto nvram_write_end;
1932 /* Loop to write back the buffer data from data_end
1934 if (sc->bce_flash_info->buffered == 0) {
1935 for (addr = data_end; addr < page_end;
1936 addr += 4, i += 4) {
1937 if (addr == page_end-4)
1938 cmd_flags = BCE_NVM_COMMAND_LAST;
1940 rc = bce_nvram_write_dword(sc, addr,
1941 &flash_buffer[i], cmd_flags);
1943 goto nvram_write_end;
1949 /* Disable writes to flash interface (lock write-protect) */
1950 bce_disable_nvram_write(sc);
1952 /* Disable access to flash interface */
1953 bce_disable_nvram_access(sc);
1954 bce_release_nvram_lock(sc);
1956 /* Increment written */
1957 written += data_end - data_start;
1961 if (align_start || align_end)
1962 kfree(buf, M_DEVBUF);
1965 #endif /* BCE_NVRAM_WRITE_SUPPORT */
1968 /****************************************************************************/
1969 /* Verifies that NVRAM is accessible and contains valid data. */
1971 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1975 /* 0 on success, positive value on failure. */
1976 /****************************************************************************/
1978 bce_nvram_test(struct bce_softc *sc)
1980 uint32_t buf[BCE_NVRAM_SIZE / 4];
1981 uint32_t magic, csum;
1982 uint8_t *data = (uint8_t *)buf;
1986 * Check that the device NVRAM is valid by reading
1987 * the magic value at offset 0.
1989 rc = bce_nvram_read(sc, 0, data, 4);
1993 magic = be32toh(buf[0]);
1994 if (magic != BCE_NVRAM_MAGIC) {
1995 if_printf(&sc->arpcom.ac_if,
1996 "Invalid NVRAM magic value! Expected: 0x%08X, "
1997 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
2002 * Verify that the device NVRAM includes valid
2003 * configuration data.
2005 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
2009 csum = ether_crc32_le(data, 0x100);
2010 if (csum != BCE_CRC32_RESIDUAL) {
2011 if_printf(&sc->arpcom.ac_if,
2012 "Invalid Manufacturing Information NVRAM CRC! "
2013 "Expected: 0x%08X, Found: 0x%08X\n",
2014 BCE_CRC32_RESIDUAL, csum);
2018 csum = ether_crc32_le(data + 0x100, 0x100);
2019 if (csum != BCE_CRC32_RESIDUAL) {
2020 if_printf(&sc->arpcom.ac_if,
2021 "Invalid Feature Configuration Information "
2022 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
2023 BCE_CRC32_RESIDUAL, csum);
2030 /****************************************************************************/
2031 /* Free any DMA memory owned by the driver. */
2033 /* Scans through each data structre that requires DMA memory and frees */
2034 /* the memory if allocated. */
2038 /****************************************************************************/
2040 bce_dma_free(struct bce_softc *sc)
2044 /* Destroy the status block. */
2045 if (sc->status_tag != NULL) {
2046 if (sc->status_block != NULL) {
2047 bus_dmamap_unload(sc->status_tag, sc->status_map);
2048 bus_dmamem_free(sc->status_tag, sc->status_block,
2051 bus_dma_tag_destroy(sc->status_tag);
2055 /* Destroy the statistics block. */
2056 if (sc->stats_tag != NULL) {
2057 if (sc->stats_block != NULL) {
2058 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2059 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2062 bus_dma_tag_destroy(sc->stats_tag);
2065 /* Destroy the TX buffer descriptor DMA stuffs. */
2066 if (sc->tx_bd_chain_tag != NULL) {
2067 for (i = 0; i < TX_PAGES; i++) {
2068 if (sc->tx_bd_chain[i] != NULL) {
2069 bus_dmamap_unload(sc->tx_bd_chain_tag,
2070 sc->tx_bd_chain_map[i]);
2071 bus_dmamem_free(sc->tx_bd_chain_tag,
2073 sc->tx_bd_chain_map[i]);
2076 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2079 /* Destroy the RX buffer descriptor DMA stuffs. */
2080 if (sc->rx_bd_chain_tag != NULL) {
2081 for (i = 0; i < RX_PAGES; i++) {
2082 if (sc->rx_bd_chain[i] != NULL) {
2083 bus_dmamap_unload(sc->rx_bd_chain_tag,
2084 sc->rx_bd_chain_map[i]);
2085 bus_dmamem_free(sc->rx_bd_chain_tag,
2087 sc->rx_bd_chain_map[i]);
2090 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2093 /* Destroy the TX mbuf DMA stuffs. */
2094 if (sc->tx_mbuf_tag != NULL) {
2095 for (i = 0; i < TOTAL_TX_BD; i++) {
2096 /* Must have been unloaded in bce_stop() */
2097 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2098 bus_dmamap_destroy(sc->tx_mbuf_tag,
2099 sc->tx_mbuf_map[i]);
2101 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2104 /* Destroy the RX mbuf DMA stuffs. */
2105 if (sc->rx_mbuf_tag != NULL) {
2106 for (i = 0; i < TOTAL_RX_BD; i++) {
2107 /* Must have been unloaded in bce_stop() */
2108 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2109 bus_dmamap_destroy(sc->rx_mbuf_tag,
2110 sc->rx_mbuf_map[i]);
2112 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2115 /* Destroy the parent tag */
2116 if (sc->parent_tag != NULL)
2117 bus_dma_tag_destroy(sc->parent_tag);
2121 /****************************************************************************/
2122 /* Get DMA memory from the OS. */
2124 /* Validates that the OS has provided DMA buffers in response to a */
2125 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2126 /* When the callback is used the OS will return 0 for the mapping function */
2127 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2128 /* failures back to the caller. */
2132 /****************************************************************************/
2134 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2136 bus_addr_t *busaddr = arg;
2139 * Simulate a mapping failure.
2142 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2143 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2144 __FILE__, __LINE__);
2147 /* Check for an error and signal the caller that an error occurred. */
2151 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2152 *busaddr = segs->ds_addr;
2157 bce_dma_map_mbuf(void *arg, bus_dma_segment_t *segs, int nsegs,
2158 bus_size_t mapsz __unused, int error)
2160 struct bce_dmamap_arg *ctx = arg;
2166 if (nsegs > ctx->bce_maxsegs) {
2167 ctx->bce_maxsegs = 0;
2171 ctx->bce_maxsegs = nsegs;
2172 for (i = 0; i < nsegs; ++i)
2173 ctx->bce_segs[i] = segs[i];
2177 /****************************************************************************/
2178 /* Allocate any DMA memory needed by the driver. */
2180 /* Allocates DMA memory needed for the various global structures needed by */
2184 /* 0 for success, positive value for failure. */
2185 /****************************************************************************/
2187 bce_dma_alloc(struct bce_softc *sc)
2189 struct ifnet *ifp = &sc->arpcom.ac_if;
2194 * Allocate the parent bus DMA tag appropriate for PCI.
2196 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2197 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2199 MAXBSIZE, BUS_SPACE_UNRESTRICTED,
2200 BUS_SPACE_MAXSIZE_32BIT,
2201 0, &sc->parent_tag);
2203 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2208 * Create a DMA tag for the status block, allocate and clear the
2209 * memory, map the memory into DMA space, and fetch the physical
2210 * address of the block.
2212 rc = bus_dma_tag_create(sc->parent_tag,
2213 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2214 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2216 BCE_STATUS_BLK_SZ, 1, BCE_STATUS_BLK_SZ,
2217 0, &sc->status_tag);
2219 if_printf(ifp, "Could not allocate status block DMA tag!\n");
2223 rc = bus_dmamem_alloc(sc->status_tag, (void **)&sc->status_block,
2224 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2227 if_printf(ifp, "Could not allocate status block DMA memory!\n");
2231 rc = bus_dmamap_load(sc->status_tag, sc->status_map,
2232 sc->status_block, BCE_STATUS_BLK_SZ,
2233 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2235 if_printf(ifp, "Could not map status block DMA memory!\n");
2236 bus_dmamem_free(sc->status_tag, sc->status_block,
2238 sc->status_block = NULL;
2242 sc->status_block_paddr = busaddr;
2243 /* DRC - Fix for 64 bit addresses. */
2244 DBPRINT(sc, BCE_INFO, "status_block_paddr = 0x%08X\n",
2245 (uint32_t)sc->status_block_paddr);
2248 * Create a DMA tag for the statistics block, allocate and clear the
2249 * memory, map the memory into DMA space, and fetch the physical
2250 * address of the block.
2252 rc = bus_dma_tag_create(sc->parent_tag,
2253 BCE_DMA_ALIGN, BCE_DMA_BOUNDARY,
2254 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2256 BCE_STATS_BLK_SZ, 1, BCE_STATS_BLK_SZ,
2259 if_printf(ifp, "Could not allocate "
2260 "statistics block DMA tag!\n");
2264 rc = bus_dmamem_alloc(sc->stats_tag, (void **)&sc->stats_block,
2265 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2268 if_printf(ifp, "Could not allocate "
2269 "statistics block DMA memory!\n");
2273 rc = bus_dmamap_load(sc->stats_tag, sc->stats_map,
2274 sc->stats_block, BCE_STATS_BLK_SZ,
2275 bce_dma_map_addr, &busaddr, BUS_DMA_WAITOK);
2277 if_printf(ifp, "Could not map statistics block DMA memory!\n");
2278 bus_dmamem_free(sc->stats_tag, sc->stats_block, sc->stats_map);
2279 sc->stats_block = NULL;
2283 sc->stats_block_paddr = busaddr;
2284 /* DRC - Fix for 64 bit address. */
2285 DBPRINT(sc, BCE_INFO, "stats_block_paddr = 0x%08X\n",
2286 (uint32_t)sc->stats_block_paddr);
2289 * Create a DMA tag for the TX buffer descriptor chain,
2290 * allocate and clear the memory, and fetch the
2291 * physical address of the block.
2293 rc = bus_dma_tag_create(sc->parent_tag,
2294 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2295 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2297 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2298 0, &sc->tx_bd_chain_tag);
2300 if_printf(ifp, "Could not allocate "
2301 "TX descriptor chain DMA tag!\n");
2305 for (i = 0; i < TX_PAGES; i++) {
2306 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2307 (void **)&sc->tx_bd_chain[i],
2308 BUS_DMA_WAITOK, &sc->tx_bd_chain_map[i]);
2310 if_printf(ifp, "Could not allocate %dth TX descriptor "
2311 "chain DMA memory!\n", i);
2315 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2316 sc->tx_bd_chain_map[i],
2317 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2318 bce_dma_map_addr, &busaddr,
2321 if_printf(ifp, "Could not map %dth TX descriptor "
2322 "chain DMA memory!\n", i);
2323 bus_dmamem_free(sc->tx_bd_chain_tag,
2325 sc->tx_bd_chain_map[i]);
2326 sc->tx_bd_chain[i] = NULL;
2330 sc->tx_bd_chain_paddr[i] = busaddr;
2331 /* DRC - Fix for 64 bit systems. */
2332 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2333 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2336 /* Create a DMA tag for TX mbufs. */
2337 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2338 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2340 MCLBYTES * BCE_MAX_SEGMENTS,
2341 BCE_MAX_SEGMENTS, MCLBYTES,
2342 0, &sc->tx_mbuf_tag);
2344 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2348 /* Create DMA maps for the TX mbufs clusters. */
2349 for (i = 0; i < TOTAL_TX_BD; i++) {
2350 rc = bus_dmamap_create(sc->tx_mbuf_tag, BUS_DMA_WAITOK,
2351 &sc->tx_mbuf_map[i]);
2353 for (j = 0; j < i; ++j) {
2354 bus_dmamap_destroy(sc->tx_mbuf_tag,
2355 sc->tx_mbuf_map[i]);
2357 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2358 sc->tx_mbuf_tag = NULL;
2360 if_printf(ifp, "Unable to create "
2361 "%dth TX mbuf DMA map!\n", i);
2367 * Create a DMA tag for the RX buffer descriptor chain,
2368 * allocate and clear the memory, and fetch the physical
2369 * address of the blocks.
2371 rc = bus_dma_tag_create(sc->parent_tag,
2372 BCM_PAGE_SIZE, BCE_DMA_BOUNDARY,
2373 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2375 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2376 0, &sc->rx_bd_chain_tag);
2378 if_printf(ifp, "Could not allocate "
2379 "RX descriptor chain DMA tag!\n");
2383 for (i = 0; i < RX_PAGES; i++) {
2384 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2385 (void **)&sc->rx_bd_chain[i],
2386 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2387 &sc->rx_bd_chain_map[i]);
2389 if_printf(ifp, "Could not allocate %dth RX descriptor "
2390 "chain DMA memory!\n", i);
2394 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2395 sc->rx_bd_chain_map[i],
2396 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2397 bce_dma_map_addr, &busaddr,
2400 if_printf(ifp, "Could not map %dth RX descriptor "
2401 "chain DMA memory!\n", i);
2402 bus_dmamem_free(sc->rx_bd_chain_tag,
2404 sc->rx_bd_chain_map[i]);
2405 sc->rx_bd_chain[i] = NULL;
2409 sc->rx_bd_chain_paddr[i] = busaddr;
2410 /* DRC - Fix for 64 bit systems. */
2411 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2412 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2415 /* Create a DMA tag for RX mbufs. */
2416 rc = bus_dma_tag_create(sc->parent_tag, 1, BCE_DMA_BOUNDARY,
2417 sc->max_bus_addr, BUS_SPACE_MAXADDR,
2419 MCLBYTES, 1/* BCE_MAX_SEGMENTS */, MCLBYTES,
2420 0, &sc->rx_mbuf_tag);
2422 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2426 /* Create DMA maps for the RX mbuf clusters. */
2427 for (i = 0; i < TOTAL_RX_BD; i++) {
2428 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2429 &sc->rx_mbuf_map[i]);
2431 for (j = 0; j < i; ++j) {
2432 bus_dmamap_destroy(sc->rx_mbuf_tag,
2433 sc->rx_mbuf_map[j]);
2435 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2436 sc->rx_mbuf_tag = NULL;
2438 if_printf(ifp, "Unable to create "
2439 "%dth RX mbuf DMA map!\n", i);
2447 /****************************************************************************/
2448 /* Firmware synchronization. */
2450 /* Before performing certain events such as a chip reset, synchronize with */
2451 /* the firmware first. */
2454 /* 0 for success, positive value for failure. */
2455 /****************************************************************************/
2457 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2462 /* Don't waste any time if we've timed out before. */
2463 if (sc->bce_fw_timed_out)
2466 /* Increment the message sequence number. */
2467 sc->bce_fw_wr_seq++;
2468 msg_data |= sc->bce_fw_wr_seq;
2470 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2472 /* Send the message to the bootcode driver mailbox. */
2473 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2475 /* Wait for the bootcode to acknowledge the message. */
2476 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2477 /* Check for a response in the bootcode firmware mailbox. */
2478 val = REG_RD_IND(sc, sc->bce_shmem_base + BCE_FW_MB);
2479 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2484 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2485 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2486 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2487 if_printf(&sc->arpcom.ac_if,
2488 "Firmware synchronization timeout! "
2489 "msg_data = 0x%08X\n", msg_data);
2491 msg_data &= ~BCE_DRV_MSG_CODE;
2492 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2494 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_MB, msg_data);
2496 sc->bce_fw_timed_out = 1;
2503 /****************************************************************************/
2504 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2508 /****************************************************************************/
2510 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2511 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2516 for (i = 0; i < rv2p_code_len; i += 8) {
2517 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2519 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2522 if (rv2p_proc == RV2P_PROC1) {
2523 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2524 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2526 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2527 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2531 /* Reset the processor, un-stall is done later. */
2532 if (rv2p_proc == RV2P_PROC1)
2533 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2535 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2539 /****************************************************************************/
2540 /* Load RISC processor firmware. */
2542 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2543 /* associated with a particular processor. */
2547 /****************************************************************************/
2549 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2552 uint32_t offset, val;
2556 val = REG_RD_IND(sc, cpu_reg->mode);
2557 val |= cpu_reg->mode_value_halt;
2558 REG_WR_IND(sc, cpu_reg->mode, val);
2559 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2561 /* Load the Text area. */
2562 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2564 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2565 REG_WR_IND(sc, offset, fw->text[j]);
2568 /* Load the Data area. */
2569 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2571 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2572 REG_WR_IND(sc, offset, fw->data[j]);
2575 /* Load the SBSS area. */
2576 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2578 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2579 REG_WR_IND(sc, offset, fw->sbss[j]);
2582 /* Load the BSS area. */
2583 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2585 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2586 REG_WR_IND(sc, offset, fw->bss[j]);
2589 /* Load the Read-Only area. */
2590 offset = cpu_reg->spad_base +
2591 (fw->rodata_addr - cpu_reg->mips_view_base);
2593 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2594 REG_WR_IND(sc, offset, fw->rodata[j]);
2597 /* Clear the pre-fetch instruction. */
2598 REG_WR_IND(sc, cpu_reg->inst, 0);
2599 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2601 /* Start the CPU. */
2602 val = REG_RD_IND(sc, cpu_reg->mode);
2603 val &= ~cpu_reg->mode_value_halt;
2604 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2605 REG_WR_IND(sc, cpu_reg->mode, val);
2609 /****************************************************************************/
2610 /* Initialize the RV2P, RX, TX, TPAT, and COM CPUs. */
2612 /* Loads the firmware for each CPU and starts the CPU. */
2616 /****************************************************************************/
2618 bce_init_cpus(struct bce_softc *sc)
2620 struct cpu_reg cpu_reg;
2623 /* Initialize the RV2P processor. */
2624 bce_load_rv2p_fw(sc, bce_rv2p_proc1, sizeof(bce_rv2p_proc1), RV2P_PROC1);
2625 bce_load_rv2p_fw(sc, bce_rv2p_proc2, sizeof(bce_rv2p_proc2), RV2P_PROC2);
2627 /* Initialize the RX Processor. */
2628 cpu_reg.mode = BCE_RXP_CPU_MODE;
2629 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2630 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2631 cpu_reg.state = BCE_RXP_CPU_STATE;
2632 cpu_reg.state_value_clear = 0xffffff;
2633 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2634 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2635 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2636 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2637 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2638 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2639 cpu_reg.mips_view_base = 0x8000000;
2641 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2642 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2643 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2644 fw.start_addr = bce_RXP_b06FwStartAddr;
2646 fw.text_addr = bce_RXP_b06FwTextAddr;
2647 fw.text_len = bce_RXP_b06FwTextLen;
2649 fw.text = bce_RXP_b06FwText;
2651 fw.data_addr = bce_RXP_b06FwDataAddr;
2652 fw.data_len = bce_RXP_b06FwDataLen;
2654 fw.data = bce_RXP_b06FwData;
2656 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2657 fw.sbss_len = bce_RXP_b06FwSbssLen;
2659 fw.sbss = bce_RXP_b06FwSbss;
2661 fw.bss_addr = bce_RXP_b06FwBssAddr;
2662 fw.bss_len = bce_RXP_b06FwBssLen;
2664 fw.bss = bce_RXP_b06FwBss;
2666 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2667 fw.rodata_len = bce_RXP_b06FwRodataLen;
2668 fw.rodata_index = 0;
2669 fw.rodata = bce_RXP_b06FwRodata;
2671 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2672 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2674 /* Initialize the TX Processor. */
2675 cpu_reg.mode = BCE_TXP_CPU_MODE;
2676 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2677 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2678 cpu_reg.state = BCE_TXP_CPU_STATE;
2679 cpu_reg.state_value_clear = 0xffffff;
2680 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2681 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2682 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2683 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2684 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2685 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2686 cpu_reg.mips_view_base = 0x8000000;
2688 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2689 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2690 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2691 fw.start_addr = bce_TXP_b06FwStartAddr;
2693 fw.text_addr = bce_TXP_b06FwTextAddr;
2694 fw.text_len = bce_TXP_b06FwTextLen;
2696 fw.text = bce_TXP_b06FwText;
2698 fw.data_addr = bce_TXP_b06FwDataAddr;
2699 fw.data_len = bce_TXP_b06FwDataLen;
2701 fw.data = bce_TXP_b06FwData;
2703 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2704 fw.sbss_len = bce_TXP_b06FwSbssLen;
2706 fw.sbss = bce_TXP_b06FwSbss;
2708 fw.bss_addr = bce_TXP_b06FwBssAddr;
2709 fw.bss_len = bce_TXP_b06FwBssLen;
2711 fw.bss = bce_TXP_b06FwBss;
2713 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2714 fw.rodata_len = bce_TXP_b06FwRodataLen;
2715 fw.rodata_index = 0;
2716 fw.rodata = bce_TXP_b06FwRodata;
2718 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2719 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2721 /* Initialize the TX Patch-up Processor. */
2722 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2723 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2724 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2725 cpu_reg.state = BCE_TPAT_CPU_STATE;
2726 cpu_reg.state_value_clear = 0xffffff;
2727 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2728 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2729 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2730 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2731 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2732 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2733 cpu_reg.mips_view_base = 0x8000000;
2735 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2736 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2737 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2738 fw.start_addr = bce_TPAT_b06FwStartAddr;
2740 fw.text_addr = bce_TPAT_b06FwTextAddr;
2741 fw.text_len = bce_TPAT_b06FwTextLen;
2743 fw.text = bce_TPAT_b06FwText;
2745 fw.data_addr = bce_TPAT_b06FwDataAddr;
2746 fw.data_len = bce_TPAT_b06FwDataLen;
2748 fw.data = bce_TPAT_b06FwData;
2750 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2751 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2753 fw.sbss = bce_TPAT_b06FwSbss;
2755 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2756 fw.bss_len = bce_TPAT_b06FwBssLen;
2758 fw.bss = bce_TPAT_b06FwBss;
2760 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2761 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2762 fw.rodata_index = 0;
2763 fw.rodata = bce_TPAT_b06FwRodata;
2765 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2766 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2768 /* Initialize the Completion Processor. */
2769 cpu_reg.mode = BCE_COM_CPU_MODE;
2770 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
2771 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
2772 cpu_reg.state = BCE_COM_CPU_STATE;
2773 cpu_reg.state_value_clear = 0xffffff;
2774 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
2775 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
2776 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
2777 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
2778 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
2779 cpu_reg.spad_base = BCE_COM_SCRATCH;
2780 cpu_reg.mips_view_base = 0x8000000;
2782 fw.ver_major = bce_COM_b06FwReleaseMajor;
2783 fw.ver_minor = bce_COM_b06FwReleaseMinor;
2784 fw.ver_fix = bce_COM_b06FwReleaseFix;
2785 fw.start_addr = bce_COM_b06FwStartAddr;
2787 fw.text_addr = bce_COM_b06FwTextAddr;
2788 fw.text_len = bce_COM_b06FwTextLen;
2790 fw.text = bce_COM_b06FwText;
2792 fw.data_addr = bce_COM_b06FwDataAddr;
2793 fw.data_len = bce_COM_b06FwDataLen;
2795 fw.data = bce_COM_b06FwData;
2797 fw.sbss_addr = bce_COM_b06FwSbssAddr;
2798 fw.sbss_len = bce_COM_b06FwSbssLen;
2800 fw.sbss = bce_COM_b06FwSbss;
2802 fw.bss_addr = bce_COM_b06FwBssAddr;
2803 fw.bss_len = bce_COM_b06FwBssLen;
2805 fw.bss = bce_COM_b06FwBss;
2807 fw.rodata_addr = bce_COM_b06FwRodataAddr;
2808 fw.rodata_len = bce_COM_b06FwRodataLen;
2809 fw.rodata_index = 0;
2810 fw.rodata = bce_COM_b06FwRodata;
2812 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
2813 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2817 /****************************************************************************/
2818 /* Initialize context memory. */
2820 /* Clears the memory associated with each Context ID (CID). */
2824 /****************************************************************************/
2826 bce_init_ctx(struct bce_softc *sc)
2831 uint32_t vcid_addr, pcid_addr, offset;
2836 vcid_addr = GET_CID_ADDR(vcid);
2837 pcid_addr = vcid_addr;
2839 for (i = 0; i < (CTX_SIZE / PHY_CTX_SIZE); i++) {
2840 vcid_addr += (i << PHY_CTX_SHIFT);
2841 pcid_addr += (i << PHY_CTX_SHIFT);
2843 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
2844 REG_WR(sc, BCE_CTX_PAGE_TBL, pcid_addr);
2846 /* Zero out the context. */
2847 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
2848 CTX_WR(sc, vcid_addr, offset, 0);
2854 /****************************************************************************/
2855 /* Fetch the permanent MAC address of the controller. */
2859 /****************************************************************************/
2861 bce_get_mac_addr(struct bce_softc *sc)
2863 uint32_t mac_lo = 0, mac_hi = 0;
2866 * The NetXtreme II bootcode populates various NIC
2867 * power-on and runtime configuration items in a
2868 * shared memory area. The factory configured MAC
2869 * address is available from both NVRAM and the
2870 * shared memory area so we'll read the value from
2871 * shared memory for speed.
2874 mac_hi = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_UPPER);
2875 mac_lo = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_HW_CFG_MAC_LOWER);
2877 if (mac_lo == 0 && mac_hi == 0) {
2878 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
2880 sc->eaddr[0] = (u_char)(mac_hi >> 8);
2881 sc->eaddr[1] = (u_char)(mac_hi >> 0);
2882 sc->eaddr[2] = (u_char)(mac_lo >> 24);
2883 sc->eaddr[3] = (u_char)(mac_lo >> 16);
2884 sc->eaddr[4] = (u_char)(mac_lo >> 8);
2885 sc->eaddr[5] = (u_char)(mac_lo >> 0);
2888 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
2892 /****************************************************************************/
2893 /* Program the MAC address. */
2897 /****************************************************************************/
2899 bce_set_mac_addr(struct bce_softc *sc)
2901 const uint8_t *mac_addr = sc->eaddr;
2904 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
2907 val = (mac_addr[0] << 8) | mac_addr[1];
2908 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
2910 val = (mac_addr[2] << 24) |
2911 (mac_addr[3] << 16) |
2912 (mac_addr[4] << 8) |
2914 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
2918 /****************************************************************************/
2919 /* Stop the controller. */
2923 /****************************************************************************/
2925 bce_stop(struct bce_softc *sc)
2927 struct ifnet *ifp = &sc->arpcom.ac_if;
2928 struct mii_data *mii = device_get_softc(sc->bce_miibus);
2929 struct ifmedia_entry *ifm;
2932 ASSERT_SERIALIZED(ifp->if_serializer);
2934 callout_stop(&sc->bce_stat_ch);
2936 /* Disable the transmit/receive blocks. */
2937 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, 0x5ffffff);
2938 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2941 bce_disable_intr(sc);
2943 /* Tell firmware that the driver is going away. */
2944 bce_reset(sc, BCE_DRV_MSG_CODE_SUSPEND_NO_WOL);
2946 /* Free the RX lists. */
2947 bce_free_rx_chain(sc);
2949 /* Free TX buffers. */
2950 bce_free_tx_chain(sc);
2953 * Isolate/power down the PHY, but leave the media selection
2954 * unchanged so that things will be put back to normal when
2955 * we bring the interface back up.
2957 * 'mii' may be NULL if bce_stop() is called by bce_detach().
2960 itmp = ifp->if_flags;
2961 ifp->if_flags |= IFF_UP;
2962 ifm = mii->mii_media.ifm_cur;
2963 mtmp = ifm->ifm_media;
2964 ifm->ifm_media = IFM_ETHER | IFM_NONE;
2966 ifm->ifm_media = mtmp;
2967 ifp->if_flags = itmp;
2971 sc->bce_coalchg_mask = 0;
2973 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2981 bce_reset(struct bce_softc *sc, uint32_t reset_code)
2986 /* Wait for pending PCI transactions to complete. */
2987 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
2988 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
2989 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
2990 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
2991 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
2992 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
2995 /* Assume bootcode is running. */
2996 sc->bce_fw_timed_out = 0;
2998 /* Give the firmware a chance to prepare for the reset. */
2999 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3001 if_printf(&sc->arpcom.ac_if,
3002 "Firmware is not ready for reset\n");
3006 /* Set a firmware reminder that this is a soft reset. */
3007 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_RESET_SIGNATURE,
3008 BCE_DRV_RESET_SIGNATURE_MAGIC);
3010 /* Dummy read to force the chip to complete all current transactions. */
3011 val = REG_RD(sc, BCE_MISC_ID);
3014 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3015 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3016 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3017 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3019 /* Allow up to 30us for reset to complete. */
3020 for (i = 0; i < 10; i++) {
3021 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3022 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3023 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
3029 /* Check that reset completed successfully. */
3030 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3031 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3032 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3036 /* Make sure byte swapping is properly configured. */
3037 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3038 if (val != 0x01020304) {
3039 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3043 /* Just completed a reset, assume that firmware is running again. */
3044 sc->bce_fw_timed_out = 0;
3046 /* Wait for the firmware to finish its initialization. */
3047 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3049 if_printf(&sc->arpcom.ac_if,
3050 "Firmware did not complete initialization!\n");
3057 bce_chipinit(struct bce_softc *sc)
3062 /* Make sure the interrupt is not active. */
3063 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3066 * Initialize DMA byte/word swapping, configure the number of DMA
3067 * channels and PCI clock compensation delay.
3069 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3070 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3071 #if BYTE_ORDER == BIG_ENDIAN
3072 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3074 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3075 DMA_READ_CHANS << 12 |
3076 DMA_WRITE_CHANS << 16;
3078 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3080 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3081 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3084 * This setting resolves a problem observed on certain Intel PCI
3085 * chipsets that cannot handle multiple outstanding DMA operations.
3086 * See errata E9_5706A1_65.
3088 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3089 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3090 !(sc->bce_flags & BCE_PCIX_FLAG))
3091 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3093 REG_WR(sc, BCE_DMA_CONFIG, val);
3095 /* Clear the PCI-X relaxed ordering bit. See errata E3_5708CA0_570. */
3096 if (sc->bce_flags & BCE_PCIX_FLAG) {
3099 cmd = pci_read_config(sc->bce_dev, BCE_PCI_PCIX_CMD, 2);
3100 pci_write_config(sc->bce_dev, BCE_PCI_PCIX_CMD, cmd & ~0x2, 2);
3103 /* Enable the RX_V2P and Context state machines before access. */
3104 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3105 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3106 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3107 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3109 /* Initialize context mapping and zero out the quick contexts. */
3112 /* Initialize the on-boards CPUs */
3115 /* Prepare NVRAM for access. */
3116 rc = bce_init_nvram(sc);
3120 /* Set the kernel bypass block size */
3121 val = REG_RD(sc, BCE_MQ_CONFIG);
3122 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3123 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3124 REG_WR(sc, BCE_MQ_CONFIG, val);
3126 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3127 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3128 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3130 /* Set the page size and clear the RV2P processor stall bits. */
3131 val = (BCM_PAGE_BITS - 8) << 24;
3132 REG_WR(sc, BCE_RV2P_CONFIG, val);
3134 /* Configure page size. */
3135 val = REG_RD(sc, BCE_TBDR_CONFIG);
3136 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3137 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3138 REG_WR(sc, BCE_TBDR_CONFIG, val);
3144 /****************************************************************************/
3145 /* Initialize the controller in preparation to send/receive traffic. */
3148 /* 0 for success, positive value for failure. */
3149 /****************************************************************************/
3151 bce_blockinit(struct bce_softc *sc)
3156 /* Load the hardware default MAC address. */
3157 bce_set_mac_addr(sc);
3159 /* Set the Ethernet backoff seed value */
3160 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3161 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3162 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3164 sc->last_status_idx = 0;
3165 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3167 /* Set up link change interrupt generation. */
3168 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3170 /* Program the physical address of the status block. */
3171 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3172 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3174 /* Program the physical address of the statistics block. */
3175 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3176 BCE_ADDR_LO(sc->stats_block_paddr));
3177 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3178 BCE_ADDR_HI(sc->stats_block_paddr));
3180 /* Program various host coalescing parameters. */
3181 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3182 (sc->bce_tx_quick_cons_trip_int << 16) |
3183 sc->bce_tx_quick_cons_trip);
3184 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3185 (sc->bce_rx_quick_cons_trip_int << 16) |
3186 sc->bce_rx_quick_cons_trip);
3187 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3188 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3189 REG_WR(sc, BCE_HC_TX_TICKS,
3190 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3191 REG_WR(sc, BCE_HC_RX_TICKS,
3192 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3193 REG_WR(sc, BCE_HC_COM_TICKS,
3194 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3195 REG_WR(sc, BCE_HC_CMD_TICKS,
3196 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3197 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3198 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3199 REG_WR(sc, BCE_HC_CONFIG,
3200 BCE_HC_CONFIG_TX_TMR_MODE |
3201 BCE_HC_CONFIG_COLLECT_STATS);
3203 /* Clear the internal statistics counters. */
3204 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3206 /* Verify that bootcode is running. */
3207 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_SIGNATURE);
3209 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3210 if_printf(&sc->arpcom.ac_if,
3211 "%s(%d): Simulating bootcode failure.\n",
3212 __FILE__, __LINE__);
3215 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3216 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3217 if_printf(&sc->arpcom.ac_if,
3218 "Bootcode not running! Found: 0x%08X, "
3219 "Expected: 08%08X\n",
3220 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3221 BCE_DEV_INFO_SIGNATURE_MAGIC);
3225 /* Check if any management firmware is running. */
3226 reg = REG_RD_IND(sc, sc->bce_shmem_base + BCE_PORT_FEATURE);
3227 if (reg & (BCE_PORT_FEATURE_ASF_ENABLED |
3228 BCE_PORT_FEATURE_IMD_ENABLED)) {
3229 DBPRINT(sc, BCE_INFO, "Management F/W Enabled.\n");
3230 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
3234 REG_RD_IND(sc, sc->bce_shmem_base + BCE_DEV_INFO_BC_REV);
3235 DBPRINT(sc, BCE_INFO, "bootcode rev = 0x%08X\n", sc->bce_fw_ver);
3237 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3238 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3240 /* Enable link state change interrupt generation. */
3241 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3243 /* Enable all remaining blocks in the MAC. */
3244 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, 0x5ffffff);
3245 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3252 /****************************************************************************/
3253 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3255 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3256 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3260 /* 0 for success, positive value for failure. */
3261 /****************************************************************************/
3263 bce_newbuf_std(struct bce_softc *sc, struct mbuf *m,
3264 uint16_t *prod, uint16_t *chain_prod, uint32_t *prod_bseq)
3267 struct bce_dmamap_arg ctx;
3268 bus_dma_segment_t seg;
3273 uint16_t debug_chain_prod = *chain_prod;
3276 /* Make sure the inputs are valid. */
3277 DBRUNIF((*chain_prod > MAX_RX_BD),
3278 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3279 "RX producer out of range: 0x%04X > 0x%04X\n",
3281 *chain_prod, (uint16_t)MAX_RX_BD));
3283 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3284 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3287 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3288 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3289 "Simulating mbuf allocation failure.\n",
3290 __FILE__, __LINE__);
3291 sc->mbuf_alloc_failed++;
3294 /* This is a new mbuf allocation. */
3295 m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3298 DBRUNIF(1, sc->rx_mbuf_alloc++);
3301 m_new->m_data = m_new->m_ext.ext_buf;
3303 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3305 /* Map the mbuf cluster into device memory. */
3306 map = sc->rx_mbuf_map[*chain_prod];
3308 ctx.bce_maxsegs = 1;
3309 ctx.bce_segs = &seg;
3310 error = bus_dmamap_load_mbuf(sc->rx_mbuf_tag, map, m_new,
3311 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
3312 if (error || ctx.bce_maxsegs == 0) {
3313 if_printf(&sc->arpcom.ac_if,
3314 "Error mapping mbuf into RX chain!\n");
3319 DBRUNIF(1, sc->rx_mbuf_alloc--);
3323 /* Watch for overflow. */
3324 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3325 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3326 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3327 __FILE__, __LINE__, sc->free_rx_bd,
3328 (uint16_t)USABLE_RX_BD));
3330 /* Update some debug statistic counters */
3331 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3332 sc->rx_low_watermark = sc->free_rx_bd);
3333 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3335 /* Setup the rx_bd for the first segment. */
3336 rxbd = &sc->rx_bd_chain[RX_PAGE(*chain_prod)][RX_IDX(*chain_prod)];
3338 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(seg.ds_addr));
3339 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(seg.ds_addr));
3340 rxbd->rx_bd_len = htole32(seg.ds_len);
3341 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3342 *prod_bseq += seg.ds_len;
3344 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3346 /* Save the mbuf and update our counter. */
3347 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3350 DBRUN(BCE_VERBOSE_RECV,
3351 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3353 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3354 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3360 /****************************************************************************/
3361 /* Allocate memory and initialize the TX data structures. */
3364 /* 0 for success, positive value for failure. */
3365 /****************************************************************************/
3367 bce_init_tx_chain(struct bce_softc *sc)
3373 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3375 /* Set the initial TX producer/consumer indices. */
3378 sc->tx_prod_bseq = 0;
3380 sc->max_tx_bd = USABLE_TX_BD;
3381 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3382 DBRUNIF(1, sc->tx_full_count = 0);
3385 * The NetXtreme II supports a linked-list structre called
3386 * a Buffer Descriptor Chain (or BD chain). A BD chain
3387 * consists of a series of 1 or more chain pages, each of which
3388 * consists of a fixed number of BD entries.
3389 * The last BD entry on each page is a pointer to the next page
3390 * in the chain, and the last pointer in the BD chain
3391 * points back to the beginning of the chain.
3394 /* Set the TX next pointer chain entries. */
3395 for (i = 0; i < TX_PAGES; i++) {
3398 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3400 /* Check if we've reached the last page. */
3401 if (i == (TX_PAGES - 1))
3406 txbd->tx_bd_haddr_hi =
3407 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3408 txbd->tx_bd_haddr_lo =
3409 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3412 for (i = 0; i < TX_PAGES; ++i) {
3413 bus_dmamap_sync(sc->tx_bd_chain_tag, sc->tx_bd_chain_map[i],
3414 BUS_DMASYNC_PREWRITE);
3417 /* Initialize the context ID for an L2 TX chain. */
3418 val = BCE_L2CTX_TYPE_TYPE_L2;
3419 val |= BCE_L2CTX_TYPE_SIZE_L2;
3420 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TYPE, val);
3422 val = BCE_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
3423 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_CMD_TYPE, val);
3425 /* Point the hardware to the first page in the chain. */
3426 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3427 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_HI, val);
3428 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3429 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TBDR_BHADDR_LO, val);
3431 DBRUN(BCE_VERBOSE_SEND, bce_dump_tx_chain(sc, 0, TOTAL_TX_BD));
3433 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3439 /****************************************************************************/
3440 /* Free memory and clear the TX data structures. */
3444 /****************************************************************************/
3446 bce_free_tx_chain(struct bce_softc *sc)
3450 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3452 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3453 for (i = 0; i < TOTAL_TX_BD; i++) {
3454 if (sc->tx_mbuf_ptr[i] != NULL) {
3455 bus_dmamap_sync(sc->tx_mbuf_tag, sc->tx_mbuf_map[i],
3456 BUS_DMASYNC_POSTWRITE);
3457 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3458 m_freem(sc->tx_mbuf_ptr[i]);
3459 sc->tx_mbuf_ptr[i] = NULL;
3460 DBRUNIF(1, sc->tx_mbuf_alloc--);
3464 /* Clear each TX chain page. */
3465 for (i = 0; i < TX_PAGES; i++)
3466 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3469 /* Check if we lost any mbufs in the process. */
3470 DBRUNIF((sc->tx_mbuf_alloc),
3471 if_printf(&sc->arpcom.ac_if,
3472 "%s(%d): Memory leak! "
3473 "Lost %d mbufs from tx chain!\n",
3474 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3476 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3480 /****************************************************************************/
3481 /* Allocate memory and initialize the RX data structures. */
3484 /* 0 for success, positive value for failure. */
3485 /****************************************************************************/
3487 bce_init_rx_chain(struct bce_softc *sc)
3491 uint16_t prod, chain_prod;
3492 uint32_t prod_bseq, val;
3494 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3496 /* Initialize the RX producer and consumer indices. */
3499 sc->rx_prod_bseq = 0;
3500 sc->free_rx_bd = USABLE_RX_BD;
3501 sc->max_rx_bd = USABLE_RX_BD;
3502 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3503 DBRUNIF(1, sc->rx_empty_count = 0);
3505 /* Initialize the RX next pointer chain entries. */
3506 for (i = 0; i < RX_PAGES; i++) {
3509 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3511 /* Check if we've reached the last page. */
3512 if (i == (RX_PAGES - 1))
3517 /* Setup the chain page pointers. */
3518 rxbd->rx_bd_haddr_hi =
3519 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
3520 rxbd->rx_bd_haddr_lo =
3521 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
3524 /* Initialize the context ID for an L2 RX chain. */
3525 val = BCE_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
3526 val |= BCE_L2CTX_CTX_TYPE_SIZE_L2;
3528 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_CTX_TYPE, val);
3530 /* Point the hardware to the first page in the chain. */
3531 /* XXX shouldn't this after RX descriptor initialization? */
3532 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3533 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_HI, val);
3534 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3535 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_NX_BDHADDR_LO, val);
3537 /* Allocate mbuf clusters for the rx_bd chain. */
3538 prod = prod_bseq = 0;
3539 while (prod < TOTAL_RX_BD) {
3540 chain_prod = RX_CHAIN_IDX(prod);
3541 if (bce_newbuf_std(sc, NULL, &prod, &chain_prod, &prod_bseq)) {
3542 if_printf(&sc->arpcom.ac_if,
3543 "Error filling RX chain: rx_bd[0x%04X]!\n",
3548 prod = NEXT_RX_BD(prod);
3551 /* Save the RX chain producer index. */
3553 sc->rx_prod_bseq = prod_bseq;
3555 for (i = 0; i < RX_PAGES; i++) {
3556 bus_dmamap_sync(sc->rx_bd_chain_tag, sc->rx_bd_chain_map[i],
3557 BUS_DMASYNC_PREWRITE);
3560 /* Tell the chip about the waiting rx_bd's. */
3561 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
3562 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
3564 DBRUN(BCE_VERBOSE_RECV, bce_dump_rx_chain(sc, 0, TOTAL_RX_BD));
3566 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3572 /****************************************************************************/
3573 /* Free memory and clear the RX data structures. */
3577 /****************************************************************************/
3579 bce_free_rx_chain(struct bce_softc *sc)
3583 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3585 /* Free any mbufs still in the RX mbuf chain. */
3586 for (i = 0; i < TOTAL_RX_BD; i++) {
3587 if (sc->rx_mbuf_ptr[i] != NULL) {
3588 bus_dmamap_sync(sc->rx_mbuf_tag, sc->rx_mbuf_map[i],
3589 BUS_DMASYNC_POSTREAD);
3590 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
3591 m_freem(sc->rx_mbuf_ptr[i]);
3592 sc->rx_mbuf_ptr[i] = NULL;
3593 DBRUNIF(1, sc->rx_mbuf_alloc--);
3597 /* Clear each RX chain page. */
3598 for (i = 0; i < RX_PAGES; i++)
3599 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
3601 /* Check if we lost any mbufs in the process. */
3602 DBRUNIF((sc->rx_mbuf_alloc),
3603 if_printf(&sc->arpcom.ac_if,
3604 "%s(%d): Memory leak! "
3605 "Lost %d mbufs from rx chain!\n",
3606 __FILE__, __LINE__, sc->rx_mbuf_alloc));
3608 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3612 /****************************************************************************/
3613 /* Set media options. */
3616 /* 0 for success, positive value for failure. */
3617 /****************************************************************************/
3619 bce_ifmedia_upd(struct ifnet *ifp)
3621 struct bce_softc *sc = ifp->if_softc;
3622 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3625 * 'mii' will be NULL, when this function is called on following
3626 * code path: bce_attach() -> bce_mgmt_init()
3629 /* Make sure the MII bus has been enumerated. */
3631 if (mii->mii_instance) {
3632 struct mii_softc *miisc;
3634 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
3635 mii_phy_reset(miisc);
3643 /****************************************************************************/
3644 /* Reports current media status. */
3648 /****************************************************************************/
3650 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
3652 struct bce_softc *sc = ifp->if_softc;
3653 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3656 ifmr->ifm_active = mii->mii_media_active;
3657 ifmr->ifm_status = mii->mii_media_status;
3661 /****************************************************************************/
3662 /* Handles PHY generated interrupt events. */
3666 /****************************************************************************/
3668 bce_phy_intr(struct bce_softc *sc)
3670 uint32_t new_link_state, old_link_state;
3671 struct ifnet *ifp = &sc->arpcom.ac_if;
3673 ASSERT_SERIALIZED(ifp->if_serializer);
3675 new_link_state = sc->status_block->status_attn_bits &
3676 STATUS_ATTN_BITS_LINK_STATE;
3677 old_link_state = sc->status_block->status_attn_bits_ack &
3678 STATUS_ATTN_BITS_LINK_STATE;
3680 /* Handle any changes if the link state has changed. */
3681 if (new_link_state != old_link_state) { /* XXX redundant? */
3682 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
3685 callout_stop(&sc->bce_stat_ch);
3686 bce_tick_serialized(sc);
3688 /* Update the status_attn_bits_ack field in the status block. */
3689 if (new_link_state) {
3690 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
3691 STATUS_ATTN_BITS_LINK_STATE);
3693 if_printf(ifp, "Link is now UP.\n");
3695 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
3696 STATUS_ATTN_BITS_LINK_STATE);
3698 if_printf(ifp, "Link is now DOWN.\n");
3702 /* Acknowledge the link change interrupt. */
3703 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
3707 /****************************************************************************/
3708 /* Reads the receive consumer value from the status block (skipping over */
3709 /* chain page pointer if necessary). */
3713 /****************************************************************************/
3714 static __inline uint16_t
3715 bce_get_hw_rx_cons(struct bce_softc *sc)
3717 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
3719 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
3725 /****************************************************************************/
3726 /* Handles received frame interrupt events. */
3730 /****************************************************************************/
3732 bce_rx_intr(struct bce_softc *sc, int count)
3734 struct ifnet *ifp = &sc->arpcom.ac_if;
3735 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
3736 uint32_t sw_prod_bseq;
3738 struct mbuf_chain chain[MAXCPU];
3740 ASSERT_SERIALIZED(ifp->if_serializer);
3742 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 ether_input_chain(ifp, m, chain);
3992 DBRUNIF(1, sc->rx_mbuf_alloc--);
3996 * If polling(4) is not enabled, refresh hw_cons to see
3997 * whether there's new work.
3999 * If polling(4) is enabled, i.e count >= 0, refreshing
4000 * should not be performed, so that we would not spend
4001 * too much time in RX processing.
4003 if (count < 0 && sw_cons == hw_cons)
4004 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4007 * Prevent speculative reads from getting ahead
4008 * of the status block.
4010 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4011 BUS_SPACE_BARRIER_READ);
4014 ether_input_dispatch(chain);
4016 for (i = 0; i < RX_PAGES; i++) {
4017 bus_dmamap_sync(sc->rx_bd_chain_tag,
4018 sc->rx_bd_chain_map[i], BUS_DMASYNC_PREWRITE);
4021 sc->rx_cons = sw_cons;
4022 sc->rx_prod = sw_prod;
4023 sc->rx_prod_bseq = sw_prod_bseq;
4025 REG_WR16(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BDIDX, sc->rx_prod);
4026 REG_WR(sc, MB_RX_CID_ADDR + BCE_L2CTX_HOST_BSEQ, sc->rx_prod_bseq);
4028 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4029 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4030 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4034 /****************************************************************************/
4035 /* Reads the transmit consumer value from the status block (skipping over */
4036 /* chain page pointer if necessary). */
4040 /****************************************************************************/
4041 static __inline uint16_t
4042 bce_get_hw_tx_cons(struct bce_softc *sc)
4044 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4046 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4052 /****************************************************************************/
4053 /* Handles transmit completion interrupt events. */
4057 /****************************************************************************/
4059 bce_tx_intr(struct bce_softc *sc)
4061 struct ifnet *ifp = &sc->arpcom.ac_if;
4062 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4064 ASSERT_SERIALIZED(ifp->if_serializer);
4066 DBRUNIF(1, sc->tx_interrupts++);
4068 /* Get the hardware's view of the TX consumer index. */
4069 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4070 sw_tx_cons = sc->tx_cons;
4072 /* Prevent speculative reads from getting ahead of the status block. */
4073 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4074 BUS_SPACE_BARRIER_READ);
4076 /* Cycle through any completed TX chain page entries. */
4077 while (sw_tx_cons != hw_tx_cons) {
4079 struct tx_bd *txbd = NULL;
4081 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4083 DBPRINT(sc, BCE_INFO_SEND,
4084 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4085 "sw_tx_chain_cons = 0x%04X\n",
4086 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4088 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4089 if_printf(ifp, "%s(%d): "
4090 "TX chain consumer out of range! "
4091 " 0x%04X > 0x%04X\n",
4092 __FILE__, __LINE__, sw_tx_chain_cons,
4094 bce_breakpoint(sc));
4096 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4097 [TX_IDX(sw_tx_chain_cons)]);
4099 DBRUNIF((txbd == NULL),
4100 if_printf(ifp, "%s(%d): "
4101 "Unexpected NULL tx_bd[0x%04X]!\n",
4102 __FILE__, __LINE__, sw_tx_chain_cons);
4103 bce_breakpoint(sc));
4105 DBRUN(BCE_INFO_SEND,
4106 if_printf(ifp, "%s(): ", __func__);
4107 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4110 * Free the associated mbuf. Remember
4111 * that only the last tx_bd of a packet
4112 * has an mbuf pointer and DMA map.
4114 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4115 /* Validate that this is the last tx_bd. */
4116 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4117 if_printf(ifp, "%s(%d): "
4118 "tx_bd END flag not set but "
4119 "txmbuf == NULL!\n", __FILE__, __LINE__);
4120 bce_breakpoint(sc));
4122 DBRUN(BCE_INFO_SEND,
4123 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4124 "from tx_bd[0x%04X]\n", __func__,
4127 /* Unmap the mbuf. */
4128 bus_dmamap_unload(sc->tx_mbuf_tag,
4129 sc->tx_mbuf_map[sw_tx_chain_cons]);
4131 /* Free the mbuf. */
4132 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4133 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4134 DBRUNIF(1, sc->tx_mbuf_alloc--);
4140 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4142 if (sw_tx_cons == hw_tx_cons) {
4143 /* Refresh hw_cons to see if there's new work. */
4144 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4148 * Prevent speculative reads from getting
4149 * ahead of the status block.
4151 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4152 BUS_SPACE_BARRIER_READ);
4155 if (sc->used_tx_bd == 0) {
4156 /* Clear the TX timeout timer. */
4160 /* Clear the tx hardware queue full flag. */
4161 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4162 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4163 DBPRINT(sc, BCE_WARN_SEND,
4164 "%s(): Open TX chain! %d/%d (used/total)\n",
4165 __func__, sc->used_tx_bd, sc->max_tx_bd));
4166 ifp->if_flags &= ~IFF_OACTIVE;
4168 sc->tx_cons = sw_tx_cons;
4172 /****************************************************************************/
4173 /* Disables interrupt generation. */
4177 /****************************************************************************/
4179 bce_disable_intr(struct bce_softc *sc)
4181 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4182 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4183 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4187 /****************************************************************************/
4188 /* Enables interrupt generation. */
4192 /****************************************************************************/
4194 bce_enable_intr(struct bce_softc *sc)
4198 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4200 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4201 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4202 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4204 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4205 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4207 val = REG_RD(sc, BCE_HC_COMMAND);
4208 REG_WR(sc, BCE_HC_COMMAND, val | BCE_HC_COMMAND_COAL_NOW);
4212 /****************************************************************************/
4213 /* Handles controller initialization. */
4217 /****************************************************************************/
4221 struct bce_softc *sc = xsc;
4222 struct ifnet *ifp = &sc->arpcom.ac_if;
4226 ASSERT_SERIALIZED(ifp->if_serializer);
4228 /* Check if the driver is still running and bail out if it is. */
4229 if (ifp->if_flags & IFF_RUNNING)
4234 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4236 if_printf(ifp, "Controller reset failed!\n");
4240 error = bce_chipinit(sc);
4242 if_printf(ifp, "Controller initialization failed!\n");
4246 error = bce_blockinit(sc);
4248 if_printf(ifp, "Block initialization failed!\n");
4252 /* Load our MAC address. */
4253 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4254 bce_set_mac_addr(sc);
4256 /* Calculate and program the Ethernet MTU size. */
4257 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4259 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4262 * Program the mtu, enabling jumbo frame
4263 * support if necessary. Also set the mbuf
4264 * allocation count for RX frames.
4266 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4268 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4269 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4270 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4271 sc->mbuf_alloc_size = MJUM9BYTES;
4273 panic("jumbo buffer is not supported yet\n");
4276 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4277 sc->mbuf_alloc_size = MCLBYTES;
4280 /* Calculate the RX Ethernet frame size for rx_bd's. */
4281 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4283 DBPRINT(sc, BCE_INFO,
4284 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4285 "max_frame_size = %d\n",
4286 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4287 sc->max_frame_size);
4289 /* Program appropriate promiscuous/multicast filtering. */
4290 bce_set_rx_mode(sc);
4292 /* Init RX buffer descriptor chain. */
4293 bce_init_rx_chain(sc); /* XXX return value */
4295 /* Init TX buffer descriptor chain. */
4296 bce_init_tx_chain(sc); /* XXX return value */
4298 #ifdef DEVICE_POLLING
4299 /* Disable interrupts if we are polling. */
4300 if (ifp->if_flags & IFF_POLLING) {
4301 bce_disable_intr(sc);
4303 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4304 (1 << 16) | sc->bce_rx_quick_cons_trip);
4305 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4306 (1 << 16) | sc->bce_tx_quick_cons_trip);
4309 /* Enable host interrupts. */
4310 bce_enable_intr(sc);
4312 bce_ifmedia_upd(ifp);
4314 ifp->if_flags |= IFF_RUNNING;
4315 ifp->if_flags &= ~IFF_OACTIVE;
4317 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
4324 /****************************************************************************/
4325 /* Initialize the controller just enough so that any management firmware */
4326 /* running on the device will continue to operate corectly. */
4330 /****************************************************************************/
4332 bce_mgmt_init(struct bce_softc *sc)
4334 struct ifnet *ifp = &sc->arpcom.ac_if;
4337 /* Check if the driver is still running and bail out if it is. */
4338 if (ifp->if_flags & IFF_RUNNING)
4341 /* Initialize the on-boards CPUs */
4344 /* Set the page size and clear the RV2P processor stall bits. */
4345 val = (BCM_PAGE_BITS - 8) << 24;
4346 REG_WR(sc, BCE_RV2P_CONFIG, val);
4348 /* Enable all critical blocks in the MAC. */
4349 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4350 BCE_MISC_ENABLE_SET_BITS_RX_V2P_ENABLE |
4351 BCE_MISC_ENABLE_SET_BITS_RX_DMA_ENABLE |
4352 BCE_MISC_ENABLE_SET_BITS_COMPLETION_ENABLE);
4353 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4356 bce_ifmedia_upd(ifp);
4360 /****************************************************************************/
4361 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4362 /* memory visible to the controller. */
4365 /* 0 for success, positive value for failure. */
4366 /****************************************************************************/
4368 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4370 struct bce_dmamap_arg ctx;
4371 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4372 bus_dmamap_t map, tmp_map;
4373 struct mbuf *m0 = *m_head;
4374 struct tx_bd *txbd = NULL;
4375 uint16_t vlan_tag = 0, flags = 0;
4376 uint16_t chain_prod, chain_prod_start, prod;
4378 int i, error, maxsegs;
4380 uint16_t debug_prod;
4383 /* Transfer any checksum offload flags to the bd. */
4384 if (m0->m_pkthdr.csum_flags) {
4385 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4386 flags |= TX_BD_FLAGS_IP_CKSUM;
4387 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4388 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4391 /* Transfer any VLAN tags to the bd. */
4392 if (m0->m_flags & M_VLANTAG) {
4393 flags |= TX_BD_FLAGS_VLAN_TAG;
4394 vlan_tag = m0->m_pkthdr.ether_vlantag;
4398 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4400 /* Map the mbuf into DMAable memory. */
4401 map = sc->tx_mbuf_map[chain_prod_start];
4403 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4404 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4405 ("not enough segements %d\n", maxsegs));
4406 if (maxsegs > BCE_MAX_SEGMENTS)
4407 maxsegs = BCE_MAX_SEGMENTS;
4409 /* Map the mbuf into our DMA address space. */
4410 ctx.bce_maxsegs = maxsegs;
4411 ctx.bce_segs = segs;
4412 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4413 bce_dma_map_mbuf, &ctx, BUS_DMA_NOWAIT);
4414 if (error == EFBIG || ctx.bce_maxsegs == 0) {
4415 DBPRINT(sc, BCE_WARN, "%s(): fragmented mbuf\n", __func__);
4416 DBRUNIF(1, bce_dump_mbuf(sc, m0););
4418 m0 = m_defrag(*m_head, MB_DONTWAIT);
4425 ctx.bce_maxsegs = maxsegs;
4426 ctx.bce_segs = segs;
4427 error = bus_dmamap_load_mbuf(sc->tx_mbuf_tag, map, m0,
4428 bce_dma_map_mbuf, &ctx,
4430 if (error || ctx.bce_maxsegs == 0) {
4431 if_printf(&sc->arpcom.ac_if,
4432 "Error mapping mbuf into TX chain\n");
4438 if_printf(&sc->arpcom.ac_if,
4439 "Error mapping mbuf into TX chain\n");
4443 /* prod points to an empty tx_bd at this point. */
4444 prod_bseq = sc->tx_prod_bseq;
4447 debug_prod = chain_prod;
4450 DBPRINT(sc, BCE_INFO_SEND,
4451 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4452 "prod_bseq = 0x%08X\n",
4453 __func__, prod, chain_prod, prod_bseq);
4456 * Cycle through each mbuf segment that makes up
4457 * the outgoing frame, gathering the mapping info
4458 * for that segment and creating a tx_bd to for
4461 for (i = 0; i < ctx.bce_maxsegs; i++) {
4462 chain_prod = TX_CHAIN_IDX(prod);
4463 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4465 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4466 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4467 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4468 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4469 txbd->tx_bd_flags = htole16(flags);
4470 prod_bseq += segs[i].ds_len;
4472 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4473 prod = NEXT_TX_BD(prod);
4476 /* Set the END flag on the last TX buffer descriptor. */
4477 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4479 DBRUN(BCE_EXCESSIVE_SEND,
4480 bce_dump_tx_chain(sc, debug_prod, ctx.bce_maxsegs));
4482 DBPRINT(sc, BCE_INFO_SEND,
4483 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4484 "prod_bseq = 0x%08X\n",
4485 __func__, prod, chain_prod, prod_bseq);
4487 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4490 * Ensure that the mbuf pointer for this transmission
4491 * is placed at the array index of the last
4492 * descriptor in this chain. This is done
4493 * because a single map is used for all
4494 * segments of the mbuf and we don't want to
4495 * unload the map before all of the segments
4498 sc->tx_mbuf_ptr[chain_prod] = m0;
4500 tmp_map = sc->tx_mbuf_map[chain_prod];
4501 sc->tx_mbuf_map[chain_prod] = map;
4502 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4504 sc->used_tx_bd += ctx.bce_maxsegs;
4506 /* Update some debug statistic counters */
4507 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4508 sc->tx_hi_watermark = sc->used_tx_bd);
4509 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
4510 DBRUNIF(1, sc->tx_mbuf_alloc++);
4512 DBRUN(BCE_VERBOSE_SEND,
4513 bce_dump_tx_mbuf_chain(sc, chain_prod, ctx.bce_maxsegs));
4515 /* prod points to the next free tx_bd at this point. */
4517 sc->tx_prod_bseq = prod_bseq;
4527 /****************************************************************************/
4528 /* Main transmit routine when called from another routine with a lock. */
4532 /****************************************************************************/
4534 bce_start(struct ifnet *ifp)
4536 struct bce_softc *sc = ifp->if_softc;
4539 ASSERT_SERIALIZED(ifp->if_serializer);
4541 /* If there's no link or the transmit queue is empty then just exit. */
4542 if (!sc->bce_link) {
4543 ifq_purge(&ifp->if_snd);
4547 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
4550 DBPRINT(sc, BCE_INFO_SEND,
4551 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04X, "
4552 "tx_prod_bseq = 0x%08X\n",
4554 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4557 struct mbuf *m_head;
4560 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4563 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4564 ifp->if_flags |= IFF_OACTIVE;
4568 /* Check for any frames to send. */
4569 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4574 * Pack the data into the transmit ring. If we
4575 * don't have room, place the mbuf back at the
4576 * head of the queue and set the OACTIVE flag
4577 * to wait for the NIC to drain the chain.
4579 if (bce_encap(sc, &m_head)) {
4580 ifp->if_flags |= IFF_OACTIVE;
4581 DBPRINT(sc, BCE_INFO_SEND,
4582 "TX chain is closed for business! "
4583 "Total tx_bd used = %d\n",
4590 /* Send a copy of the frame to any BPF listeners. */
4591 ETHER_BPF_MTAP(ifp, m_head);
4595 /* no packets were dequeued */
4596 DBPRINT(sc, BCE_VERBOSE_SEND,
4597 "%s(): No packets were dequeued\n", __func__);
4601 DBPRINT(sc, BCE_INFO_SEND,
4602 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04X, "
4603 "tx_prod_bseq = 0x%08X\n",
4605 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4607 /* Start the transmit. */
4608 REG_WR16(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
4609 REG_WR(sc, MB_TX_CID_ADDR + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
4611 /* Set the tx timeout. */
4612 ifp->if_timer = BCE_TX_TIMEOUT;
4616 /****************************************************************************/
4617 /* Handles any IOCTL calls from the operating system. */
4620 /* 0 for success, positive value for failure. */
4621 /****************************************************************************/
4623 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
4625 struct bce_softc *sc = ifp->if_softc;
4626 struct ifreq *ifr = (struct ifreq *)data;
4627 struct mii_data *mii;
4628 int mask, error = 0;
4630 ASSERT_SERIALIZED(ifp->if_serializer);
4634 /* Check that the MTU setting is supported. */
4635 if (ifr->ifr_mtu < BCE_MIN_MTU ||
4637 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
4639 ifr->ifr_mtu > ETHERMTU
4646 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
4648 ifp->if_mtu = ifr->ifr_mtu;
4649 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4654 if (ifp->if_flags & IFF_UP) {
4655 if (ifp->if_flags & IFF_RUNNING) {
4656 mask = ifp->if_flags ^ sc->bce_if_flags;
4658 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
4659 bce_set_rx_mode(sc);
4663 } else if (ifp->if_flags & IFF_RUNNING) {
4666 sc->bce_if_flags = ifp->if_flags;
4671 if (ifp->if_flags & IFF_RUNNING)
4672 bce_set_rx_mode(sc);
4677 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
4679 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
4681 mii = device_get_softc(sc->bce_miibus);
4682 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
4686 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
4687 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
4690 if (mask & IFCAP_HWCSUM) {
4691 ifp->if_capenable ^= IFCAP_HWCSUM;
4692 if (IFCAP_HWCSUM & ifp->if_capenable)
4693 ifp->if_hwassist = BCE_IF_HWASSIST;
4695 ifp->if_hwassist = 0;
4700 error = ether_ioctl(ifp, command, data);
4707 /****************************************************************************/
4708 /* Transmit timeout handler. */
4712 /****************************************************************************/
4714 bce_watchdog(struct ifnet *ifp)
4716 struct bce_softc *sc = ifp->if_softc;
4718 ASSERT_SERIALIZED(ifp->if_serializer);
4720 DBRUN(BCE_VERBOSE_SEND,
4721 bce_dump_driver_state(sc);
4722 bce_dump_status_block(sc));
4725 * If we are in this routine because of pause frames, then
4726 * don't reset the hardware.
4728 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
4731 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
4733 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
4735 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
4740 if (!ifq_is_empty(&ifp->if_snd))
4745 #ifdef DEVICE_POLLING
4748 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
4750 struct bce_softc *sc = ifp->if_softc;
4751 struct status_block *sblk = sc->status_block;
4752 uint16_t hw_tx_cons, hw_rx_cons;
4754 ASSERT_SERIALIZED(ifp->if_serializer);
4758 bce_disable_intr(sc);
4760 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4761 (1 << 16) | sc->bce_rx_quick_cons_trip);
4762 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4763 (1 << 16) | sc->bce_tx_quick_cons_trip);
4765 case POLL_DEREGISTER:
4766 bce_enable_intr(sc);
4768 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4769 (sc->bce_tx_quick_cons_trip_int << 16) |
4770 sc->bce_tx_quick_cons_trip);
4771 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4772 (sc->bce_rx_quick_cons_trip_int << 16) |
4773 sc->bce_rx_quick_cons_trip);
4779 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4781 if (cmd == POLL_AND_CHECK_STATUS) {
4782 uint32_t status_attn_bits;
4784 status_attn_bits = sblk->status_attn_bits;
4786 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4788 "Simulating unexpected status attention bit set.");
4789 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4791 /* Was it a link change interrupt? */
4792 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4793 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4797 * If any other attention is asserted then
4798 * the chip is toast.
4800 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4801 (sblk->status_attn_bits_ack &
4802 ~STATUS_ATTN_BITS_LINK_STATE)) {
4803 DBRUN(1, sc->unexpected_attentions++);
4805 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4806 sblk->status_attn_bits);
4809 if (bce_debug_unexpected_attention == 0)
4810 bce_breakpoint(sc));
4817 hw_rx_cons = bce_get_hw_rx_cons(sc);
4818 hw_tx_cons = bce_get_hw_tx_cons(sc);
4820 /* Check for any completed RX frames. */
4821 if (hw_rx_cons != sc->hw_rx_cons)
4822 bce_rx_intr(sc, count);
4824 /* Check for any completed TX frames. */
4825 if (hw_tx_cons != sc->hw_tx_cons)
4828 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4830 /* Check for new frames to transmit. */
4831 if (!ifq_is_empty(&ifp->if_snd))
4835 #endif /* DEVICE_POLLING */
4839 * Interrupt handler.
4841 /****************************************************************************/
4842 /* Main interrupt entry point. Verifies that the controller generated the */
4843 /* interrupt and then calls a separate routine for handle the various */
4844 /* interrupt causes (PHY, TX, RX). */
4847 /* 0 for success, positive value for failure. */
4848 /****************************************************************************/
4852 struct bce_softc *sc = xsc;
4853 struct ifnet *ifp = &sc->arpcom.ac_if;
4854 struct status_block *sblk;
4855 uint16_t hw_rx_cons, hw_tx_cons;
4857 ASSERT_SERIALIZED(ifp->if_serializer);
4859 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
4860 DBRUNIF(1, sc->interrupts_generated++);
4862 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_POSTREAD);
4863 sblk = sc->status_block;
4866 * If the hardware status block index matches the last value
4867 * read by the driver and we haven't asserted our interrupt
4868 * then there's nothing to do.
4870 if (sblk->status_idx == sc->last_status_idx &&
4871 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
4872 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
4875 /* Ack the interrupt and stop others from occuring. */
4876 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4877 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
4878 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4880 /* Check if the hardware has finished any work. */
4881 hw_rx_cons = bce_get_hw_rx_cons(sc);
4882 hw_tx_cons = bce_get_hw_tx_cons(sc);
4884 /* Keep processing data as long as there is work to do. */
4886 uint32_t status_attn_bits;
4888 status_attn_bits = sblk->status_attn_bits;
4890 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
4892 "Simulating unexpected status attention bit set.");
4893 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
4895 /* Was it a link change interrupt? */
4896 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
4897 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
4901 * If any other attention is asserted then
4902 * the chip is toast.
4904 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
4905 (sblk->status_attn_bits_ack &
4906 ~STATUS_ATTN_BITS_LINK_STATE)) {
4907 DBRUN(1, sc->unexpected_attentions++);
4909 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
4910 sblk->status_attn_bits);
4913 if (bce_debug_unexpected_attention == 0)
4914 bce_breakpoint(sc));
4920 /* Check for any completed RX frames. */
4921 if (hw_rx_cons != sc->hw_rx_cons)
4922 bce_rx_intr(sc, -1);
4924 /* Check for any completed TX frames. */
4925 if (hw_tx_cons != sc->hw_tx_cons)
4929 * Save the status block index value
4930 * for use during the next interrupt.
4932 sc->last_status_idx = sblk->status_idx;
4935 * Prevent speculative reads from getting
4936 * ahead of the status block.
4938 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4939 BUS_SPACE_BARRIER_READ);
4942 * If there's no work left then exit the
4943 * interrupt service routine.
4945 hw_rx_cons = bce_get_hw_rx_cons(sc);
4946 hw_tx_cons = bce_get_hw_tx_cons(sc);
4947 if ((hw_rx_cons == sc->hw_rx_cons) && (hw_tx_cons == sc->hw_tx_cons))
4951 bus_dmamap_sync(sc->status_tag, sc->status_map, BUS_DMASYNC_PREWRITE);
4953 /* Re-enable interrupts. */
4954 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4955 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx |
4956 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4957 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4958 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4960 if (sc->bce_coalchg_mask)
4961 bce_coal_change(sc);
4963 /* Handle any frames that arrived while handling the interrupt. */
4964 if (!ifq_is_empty(&ifp->if_snd))
4969 /****************************************************************************/
4970 /* Programs the various packet receive modes (broadcast and multicast). */
4974 /****************************************************************************/
4976 bce_set_rx_mode(struct bce_softc *sc)
4978 struct ifnet *ifp = &sc->arpcom.ac_if;
4979 struct ifmultiaddr *ifma;
4980 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4981 uint32_t rx_mode, sort_mode;
4984 ASSERT_SERIALIZED(ifp->if_serializer);
4986 /* Initialize receive mode default settings. */
4987 rx_mode = sc->rx_mode &
4988 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
4989 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
4990 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
4993 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
4996 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
4997 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4998 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5001 * Check for promiscuous, all multicast, or selected
5002 * multicast address filtering.
5004 if (ifp->if_flags & IFF_PROMISC) {
5005 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5007 /* Enable promiscuous mode. */
5008 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5009 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5010 } else if (ifp->if_flags & IFF_ALLMULTI) {
5011 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5013 /* Enable all multicast addresses. */
5014 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5015 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5018 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5020 /* Accept one or more multicast(s). */
5021 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5023 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5024 if (ifma->ifma_addr->sa_family != AF_LINK)
5027 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5028 ETHER_ADDR_LEN) & 0xFF;
5029 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5032 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5033 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5036 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5039 /* Only make changes if the recive mode has actually changed. */
5040 if (rx_mode != sc->rx_mode) {
5041 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5044 sc->rx_mode = rx_mode;
5045 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5048 /* Disable and clear the exisitng sort before enabling a new sort. */
5049 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5050 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5051 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5055 /****************************************************************************/
5056 /* Called periodically to updates statistics from the controllers */
5057 /* statistics block. */
5061 /****************************************************************************/
5063 bce_stats_update(struct bce_softc *sc)
5065 struct ifnet *ifp = &sc->arpcom.ac_if;
5066 struct statistics_block *stats = sc->stats_block;
5068 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5070 ASSERT_SERIALIZED(ifp->if_serializer);
5073 * Update the interface statistics from the hardware statistics.
5075 ifp->if_collisions = (u_long)stats->stat_EtherStatsCollisions;
5077 ifp->if_ierrors = (u_long)stats->stat_EtherStatsUndersizePkts +
5078 (u_long)stats->stat_EtherStatsOverrsizePkts +
5079 (u_long)stats->stat_IfInMBUFDiscards +
5080 (u_long)stats->stat_Dot3StatsAlignmentErrors +
5081 (u_long)stats->stat_Dot3StatsFCSErrors;
5084 (u_long)stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5085 (u_long)stats->stat_Dot3StatsExcessiveCollisions +
5086 (u_long)stats->stat_Dot3StatsLateCollisions;
5089 * Certain controllers don't report carrier sense errors correctly.
5090 * See errata E11_5708CA0_1165.
5092 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5093 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5095 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5099 * Update the sysctl statistics from the hardware statistics.
5101 sc->stat_IfHCInOctets =
5102 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5103 (uint64_t)stats->stat_IfHCInOctets_lo;
5105 sc->stat_IfHCInBadOctets =
5106 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5107 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5109 sc->stat_IfHCOutOctets =
5110 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5111 (uint64_t)stats->stat_IfHCOutOctets_lo;
5113 sc->stat_IfHCOutBadOctets =
5114 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5115 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5117 sc->stat_IfHCInUcastPkts =
5118 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5119 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5121 sc->stat_IfHCInMulticastPkts =
5122 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5123 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5125 sc->stat_IfHCInBroadcastPkts =
5126 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5127 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5129 sc->stat_IfHCOutUcastPkts =
5130 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5131 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5133 sc->stat_IfHCOutMulticastPkts =
5134 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5135 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5137 sc->stat_IfHCOutBroadcastPkts =
5138 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5139 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5141 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5142 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5144 sc->stat_Dot3StatsCarrierSenseErrors =
5145 stats->stat_Dot3StatsCarrierSenseErrors;
5147 sc->stat_Dot3StatsFCSErrors =
5148 stats->stat_Dot3StatsFCSErrors;
5150 sc->stat_Dot3StatsAlignmentErrors =
5151 stats->stat_Dot3StatsAlignmentErrors;
5153 sc->stat_Dot3StatsSingleCollisionFrames =
5154 stats->stat_Dot3StatsSingleCollisionFrames;
5156 sc->stat_Dot3StatsMultipleCollisionFrames =
5157 stats->stat_Dot3StatsMultipleCollisionFrames;
5159 sc->stat_Dot3StatsDeferredTransmissions =
5160 stats->stat_Dot3StatsDeferredTransmissions;
5162 sc->stat_Dot3StatsExcessiveCollisions =
5163 stats->stat_Dot3StatsExcessiveCollisions;
5165 sc->stat_Dot3StatsLateCollisions =
5166 stats->stat_Dot3StatsLateCollisions;
5168 sc->stat_EtherStatsCollisions =
5169 stats->stat_EtherStatsCollisions;
5171 sc->stat_EtherStatsFragments =
5172 stats->stat_EtherStatsFragments;
5174 sc->stat_EtherStatsJabbers =
5175 stats->stat_EtherStatsJabbers;
5177 sc->stat_EtherStatsUndersizePkts =
5178 stats->stat_EtherStatsUndersizePkts;
5180 sc->stat_EtherStatsOverrsizePkts =
5181 stats->stat_EtherStatsOverrsizePkts;
5183 sc->stat_EtherStatsPktsRx64Octets =
5184 stats->stat_EtherStatsPktsRx64Octets;
5186 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5187 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5189 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5190 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5192 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5193 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5195 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5196 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5198 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5199 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5201 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5202 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5204 sc->stat_EtherStatsPktsTx64Octets =
5205 stats->stat_EtherStatsPktsTx64Octets;
5207 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5208 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5210 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5211 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5213 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5214 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5216 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5217 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5219 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5220 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5222 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5223 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5225 sc->stat_XonPauseFramesReceived =
5226 stats->stat_XonPauseFramesReceived;
5228 sc->stat_XoffPauseFramesReceived =
5229 stats->stat_XoffPauseFramesReceived;
5231 sc->stat_OutXonSent =
5232 stats->stat_OutXonSent;
5234 sc->stat_OutXoffSent =
5235 stats->stat_OutXoffSent;
5237 sc->stat_FlowControlDone =
5238 stats->stat_FlowControlDone;
5240 sc->stat_MacControlFramesReceived =
5241 stats->stat_MacControlFramesReceived;
5243 sc->stat_XoffStateEntered =
5244 stats->stat_XoffStateEntered;
5246 sc->stat_IfInFramesL2FilterDiscards =
5247 stats->stat_IfInFramesL2FilterDiscards;
5249 sc->stat_IfInRuleCheckerDiscards =
5250 stats->stat_IfInRuleCheckerDiscards;
5252 sc->stat_IfInFTQDiscards =
5253 stats->stat_IfInFTQDiscards;
5255 sc->stat_IfInMBUFDiscards =
5256 stats->stat_IfInMBUFDiscards;
5258 sc->stat_IfInRuleCheckerP4Hit =
5259 stats->stat_IfInRuleCheckerP4Hit;
5261 sc->stat_CatchupInRuleCheckerDiscards =
5262 stats->stat_CatchupInRuleCheckerDiscards;
5264 sc->stat_CatchupInFTQDiscards =
5265 stats->stat_CatchupInFTQDiscards;
5267 sc->stat_CatchupInMBUFDiscards =
5268 stats->stat_CatchupInMBUFDiscards;
5270 sc->stat_CatchupInRuleCheckerP4Hit =
5271 stats->stat_CatchupInRuleCheckerP4Hit;
5273 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5275 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5279 /****************************************************************************/
5280 /* Periodic function to perform maintenance tasks. */
5284 /****************************************************************************/
5286 bce_tick_serialized(struct bce_softc *sc)
5288 struct ifnet *ifp = &sc->arpcom.ac_if;
5289 struct mii_data *mii;
5292 ASSERT_SERIALIZED(ifp->if_serializer);
5294 /* Tell the firmware that the driver is still running. */
5296 msg = (uint32_t)BCE_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE;
5298 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5300 REG_WR_IND(sc, sc->bce_shmem_base + BCE_DRV_PULSE_MB, msg);
5302 /* Update the statistics from the hardware statistics block. */
5303 bce_stats_update(sc);
5305 /* Schedule the next tick. */
5306 callout_reset(&sc->bce_stat_ch, hz, bce_tick, sc);
5308 /* If link is up already up then we're done. */
5312 mii = device_get_softc(sc->bce_miibus);
5315 /* Check if the link has come up. */
5316 if (!sc->bce_link && (mii->mii_media_status & IFM_ACTIVE) &&
5317 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5319 /* Now that link is up, handle any outstanding TX traffic. */
5320 if (!ifq_is_empty(&ifp->if_snd))
5329 struct bce_softc *sc = xsc;
5330 struct ifnet *ifp = &sc->arpcom.ac_if;
5332 lwkt_serialize_enter(ifp->if_serializer);
5333 bce_tick_serialized(sc);
5334 lwkt_serialize_exit(ifp->if_serializer);
5339 /****************************************************************************/
5340 /* Allows the driver state to be dumped through the sysctl interface. */
5343 /* 0 for success, positive value for failure. */
5344 /****************************************************************************/
5346 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5350 struct bce_softc *sc;
5353 error = sysctl_handle_int(oidp, &result, 0, req);
5355 if (error || !req->newptr)
5359 sc = (struct bce_softc *)arg1;
5360 bce_dump_driver_state(sc);
5367 /****************************************************************************/
5368 /* Allows the hardware state to be dumped through the sysctl interface. */
5371 /* 0 for success, positive value for failure. */
5372 /****************************************************************************/
5374 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5378 struct bce_softc *sc;
5381 error = sysctl_handle_int(oidp, &result, 0, req);
5383 if (error || !req->newptr)
5387 sc = (struct bce_softc *)arg1;
5388 bce_dump_hw_state(sc);
5395 /****************************************************************************/
5396 /* Provides a sysctl interface to allows dumping the RX chain. */
5399 /* 0 for success, positive value for failure. */
5400 /****************************************************************************/
5402 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5406 struct bce_softc *sc;
5409 error = sysctl_handle_int(oidp, &result, 0, req);
5411 if (error || !req->newptr)
5415 sc = (struct bce_softc *)arg1;
5416 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5423 /****************************************************************************/
5424 /* Provides a sysctl interface to allows dumping the TX chain. */
5427 /* 0 for success, positive value for failure. */
5428 /****************************************************************************/
5430 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5434 struct bce_softc *sc;
5437 error = sysctl_handle_int(oidp, &result, 0, req);
5439 if (error || !req->newptr)
5443 sc = (struct bce_softc *)arg1;
5444 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
5451 /****************************************************************************/
5452 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5453 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5456 /* 0 for success, positive value for failure. */
5457 /****************************************************************************/
5459 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5461 struct bce_softc *sc;
5463 uint32_t val, result;
5466 error = sysctl_handle_int(oidp, &result, 0, req);
5467 if (error || (req->newptr == NULL))
5470 /* Make sure the register is accessible. */
5471 if (result < 0x8000) {
5472 sc = (struct bce_softc *)arg1;
5473 val = REG_RD(sc, result);
5474 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5476 } else if (result < 0x0280000) {
5477 sc = (struct bce_softc *)arg1;
5478 val = REG_RD_IND(sc, result);
5479 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5486 /****************************************************************************/
5487 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
\r
5488 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
\r
5491 /* 0 for success, positive value for failure. */
5492 /****************************************************************************/
5494 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
5496 struct bce_softc *sc;
5502 error = sysctl_handle_int(oidp, &result, 0, req);
5503 if (error || (req->newptr == NULL))
5506 /* Make sure the register is accessible. */
5507 if (result < 0x20) {
5508 sc = (struct bce_softc *)arg1;
5510 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
5511 if_printf(&sc->arpcom.ac_if,
5512 "phy 0x%02X = 0x%04X\n", result, val);
5518 /****************************************************************************/
5519 /* Provides a sysctl interface to forcing the driver to dump state and */
\r
5520 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5523 /* 0 for success, positive value for failure. */
5524 /****************************************************************************/
5526 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
5530 struct bce_softc *sc;
5533 error = sysctl_handle_int(oidp, &result, 0, req);
5535 if (error || !req->newptr)
5539 sc = (struct bce_softc *)arg1;
5548 /****************************************************************************/
5549 /* Adds any sysctl parameters for tuning or debugging purposes. */
5552 /* 0 for success, positive value for failure. */
5553 /****************************************************************************/
5555 bce_add_sysctls(struct bce_softc *sc)
5557 struct sysctl_ctx_list *ctx;
5558 struct sysctl_oid_list *children;
5560 sysctl_ctx_init(&sc->bce_sysctl_ctx);
5561 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
5562 SYSCTL_STATIC_CHILDREN(_hw),
5564 device_get_nameunit(sc->bce_dev),
5566 if (sc->bce_sysctl_tree == NULL) {
5567 device_printf(sc->bce_dev, "can't add sysctl node\n");
5571 ctx = &sc->bce_sysctl_ctx;
5572 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
5574 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
5575 CTLTYPE_INT | CTLFLAG_RW,
5576 sc, 0, bce_sysctl_tx_bds_int, "I",
5577 "Send max coalesced BD count during interrupt");
5578 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
5579 CTLTYPE_INT | CTLFLAG_RW,
5580 sc, 0, bce_sysctl_tx_bds, "I",
5581 "Send max coalesced BD count");
5582 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
5583 CTLTYPE_INT | CTLFLAG_RW,
5584 sc, 0, bce_sysctl_tx_ticks_int, "I",
5585 "Send coalescing ticks during interrupt");
5586 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
5587 CTLTYPE_INT | CTLFLAG_RW,
5588 sc, 0, bce_sysctl_tx_ticks, "I",
5589 "Send coalescing ticks");
5591 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
5592 CTLTYPE_INT | CTLFLAG_RW,
5593 sc, 0, bce_sysctl_rx_bds_int, "I",
5594 "Receive max coalesced BD count during interrupt");
5595 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
5596 CTLTYPE_INT | CTLFLAG_RW,
5597 sc, 0, bce_sysctl_rx_bds, "I",
5598 "Receive max coalesced BD count");
5599 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
5600 CTLTYPE_INT | CTLFLAG_RW,
5601 sc, 0, bce_sysctl_rx_ticks_int, "I",
5602 "Receive coalescing ticks during interrupt");
5603 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
5604 CTLTYPE_INT | CTLFLAG_RW,
5605 sc, 0, bce_sysctl_rx_ticks, "I",
5606 "Receive coalescing ticks");
5609 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5611 CTLFLAG_RD, &sc->rx_low_watermark,
5612 0, "Lowest level of free rx_bd's");
5614 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5616 CTLFLAG_RD, &sc->rx_empty_count,
5617 0, "Number of times the RX chain was empty");
5619 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5621 CTLFLAG_RD, &sc->tx_hi_watermark,
5622 0, "Highest level of used tx_bd's");
5624 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5626 CTLFLAG_RD, &sc->tx_full_count,
5627 0, "Number of times the TX chain was full");
5629 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5630 "l2fhdr_status_errors",
5631 CTLFLAG_RD, &sc->l2fhdr_status_errors,
5632 0, "l2_fhdr status errors");
5634 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5635 "unexpected_attentions",
5636 CTLFLAG_RD, &sc->unexpected_attentions,
5637 0, "unexpected attentions");
5639 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5640 "lost_status_block_updates",
5641 CTLFLAG_RD, &sc->lost_status_block_updates,
5642 0, "lost status block updates");
5644 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5645 "mbuf_alloc_failed",
5646 CTLFLAG_RD, &sc->mbuf_alloc_failed,
5647 0, "mbuf cluster allocation failures");
5650 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5651 "stat_IfHCInOctets",
5652 CTLFLAG_RD, &sc->stat_IfHCInOctets,
5655 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5656 "stat_IfHCInBadOctets",
5657 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
5658 "Bad bytes received");
5660 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5661 "stat_IfHCOutOctets",
5662 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
5665 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5666 "stat_IfHCOutBadOctets",
5667 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
5670 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5671 "stat_IfHCInUcastPkts",
5672 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
5673 "Unicast packets received");
5675 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5676 "stat_IfHCInMulticastPkts",
5677 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
5678 "Multicast packets received");
5680 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5681 "stat_IfHCInBroadcastPkts",
5682 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
5683 "Broadcast packets received");
5685 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5686 "stat_IfHCOutUcastPkts",
5687 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
5688 "Unicast packets sent");
5690 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5691 "stat_IfHCOutMulticastPkts",
5692 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
5693 "Multicast packets sent");
5695 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
5696 "stat_IfHCOutBroadcastPkts",
5697 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
5698 "Broadcast packets sent");
5700 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5701 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
5702 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
5703 0, "Internal MAC transmit errors");
5705 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5706 "stat_Dot3StatsCarrierSenseErrors",
5707 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
5708 0, "Carrier sense errors");
5710 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5711 "stat_Dot3StatsFCSErrors",
5712 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
5713 0, "Frame check sequence errors");
5715 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5716 "stat_Dot3StatsAlignmentErrors",
5717 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
5718 0, "Alignment errors");
5720 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5721 "stat_Dot3StatsSingleCollisionFrames",
5722 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
5723 0, "Single Collision Frames");
5725 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5726 "stat_Dot3StatsMultipleCollisionFrames",
5727 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
5728 0, "Multiple Collision Frames");
5730 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5731 "stat_Dot3StatsDeferredTransmissions",
5732 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
5733 0, "Deferred Transmissions");
5735 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5736 "stat_Dot3StatsExcessiveCollisions",
5737 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
5738 0, "Excessive Collisions");
5740 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5741 "stat_Dot3StatsLateCollisions",
5742 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
5743 0, "Late Collisions");
5745 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5746 "stat_EtherStatsCollisions",
5747 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
5750 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5751 "stat_EtherStatsFragments",
5752 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
5755 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5756 "stat_EtherStatsJabbers",
5757 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
5760 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5761 "stat_EtherStatsUndersizePkts",
5762 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
5763 0, "Undersize packets");
5765 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5766 "stat_EtherStatsOverrsizePkts",
5767 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
5768 0, "stat_EtherStatsOverrsizePkts");
5770 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5771 "stat_EtherStatsPktsRx64Octets",
5772 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
5773 0, "Bytes received in 64 byte packets");
5775 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5776 "stat_EtherStatsPktsRx65Octetsto127Octets",
5777 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
5778 0, "Bytes received in 65 to 127 byte packets");
5780 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5781 "stat_EtherStatsPktsRx128Octetsto255Octets",
5782 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
5783 0, "Bytes received in 128 to 255 byte packets");
5785 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5786 "stat_EtherStatsPktsRx256Octetsto511Octets",
5787 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
5788 0, "Bytes received in 256 to 511 byte packets");
5790 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5791 "stat_EtherStatsPktsRx512Octetsto1023Octets",
5792 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
5793 0, "Bytes received in 512 to 1023 byte packets");
5795 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5796 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
5797 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
5798 0, "Bytes received in 1024 t0 1522 byte packets");
5800 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5801 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
5802 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
5803 0, "Bytes received in 1523 to 9022 byte packets");
5805 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5806 "stat_EtherStatsPktsTx64Octets",
5807 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
5808 0, "Bytes sent in 64 byte packets");
5810 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5811 "stat_EtherStatsPktsTx65Octetsto127Octets",
5812 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
5813 0, "Bytes sent in 65 to 127 byte packets");
5815 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5816 "stat_EtherStatsPktsTx128Octetsto255Octets",
5817 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
5818 0, "Bytes sent in 128 to 255 byte packets");
5820 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5821 "stat_EtherStatsPktsTx256Octetsto511Octets",
5822 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
5823 0, "Bytes sent in 256 to 511 byte packets");
5825 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5826 "stat_EtherStatsPktsTx512Octetsto1023Octets",
5827 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
5828 0, "Bytes sent in 512 to 1023 byte packets");
5830 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5831 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
5832 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
5833 0, "Bytes sent in 1024 to 1522 byte packets");
5835 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5836 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
5837 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
5838 0, "Bytes sent in 1523 to 9022 byte packets");
5840 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5841 "stat_XonPauseFramesReceived",
5842 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
5843 0, "XON pause frames receved");
5845 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5846 "stat_XoffPauseFramesReceived",
5847 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
5848 0, "XOFF pause frames received");
5850 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5852 CTLFLAG_RD, &sc->stat_OutXonSent,
5853 0, "XON pause frames sent");
5855 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5857 CTLFLAG_RD, &sc->stat_OutXoffSent,
5858 0, "XOFF pause frames sent");
5860 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5861 "stat_FlowControlDone",
5862 CTLFLAG_RD, &sc->stat_FlowControlDone,
5863 0, "Flow control done");
5865 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5866 "stat_MacControlFramesReceived",
5867 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
5868 0, "MAC control frames received");
5870 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5871 "stat_XoffStateEntered",
5872 CTLFLAG_RD, &sc->stat_XoffStateEntered,
5873 0, "XOFF state entered");
5875 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5876 "stat_IfInFramesL2FilterDiscards",
5877 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
5878 0, "Received L2 packets discarded");
5880 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5881 "stat_IfInRuleCheckerDiscards",
5882 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
5883 0, "Received packets discarded by rule");
5885 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5886 "stat_IfInFTQDiscards",
5887 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
5888 0, "Received packet FTQ discards");
5890 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5891 "stat_IfInMBUFDiscards",
5892 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
5893 0, "Received packets discarded due to lack of controller buffer memory");
5895 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5896 "stat_IfInRuleCheckerP4Hit",
5897 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
5898 0, "Received packets rule checker hits");
5900 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5901 "stat_CatchupInRuleCheckerDiscards",
5902 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
5903 0, "Received packets discarded in Catchup path");
5905 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5906 "stat_CatchupInFTQDiscards",
5907 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
5908 0, "Received packets discarded in FTQ in Catchup path");
5910 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5911 "stat_CatchupInMBUFDiscards",
5912 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
5913 0, "Received packets discarded in controller buffer memory in Catchup path");
5915 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5916 "stat_CatchupInRuleCheckerP4Hit",
5917 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
5918 0, "Received packets rule checker hits in Catchup path");
5920 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
5922 CTLFLAG_RD, &sc->com_no_buffers,
5923 0, "Valid packets received but no RX buffers available");
5926 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5927 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
5929 bce_sysctl_driver_state, "I", "Drive state information");
5931 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5932 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
5934 bce_sysctl_hw_state, "I", "Hardware state information");
5936 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5937 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
5939 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
5941 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5942 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
5944 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
5946 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5947 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
5949 bce_sysctl_breakpoint, "I", "Driver breakpoint");
5951 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
5952 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
5954 bce_sysctl_reg_read, "I", "Register read");
5956 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
\r
5957 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
\r
5959 bce_sysctl_phy_read, "I", "PHY register read");
5966 /****************************************************************************/
5967 /* BCE Debug Routines */
5968 /****************************************************************************/
5971 /****************************************************************************/
5972 /* Freezes the controller to allow for a cohesive state dump. */
5976 /****************************************************************************/
5978 bce_freeze_controller(struct bce_softc *sc)
5982 val = REG_RD(sc, BCE_MISC_COMMAND);
5983 val |= BCE_MISC_COMMAND_DISABLE_ALL;
5984 REG_WR(sc, BCE_MISC_COMMAND, val);
5988 /****************************************************************************/
5989 /* Unfreezes the controller after a freeze operation. This may not always */
\r
5990 /* work and the controller will require a reset! */
5994 /****************************************************************************/
5996 bce_unfreeze_controller(struct bce_softc *sc)
6000 val = REG_RD(sc, BCE_MISC_COMMAND);
6001 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6002 REG_WR(sc, BCE_MISC_COMMAND, val);
6006 /****************************************************************************/
6007 /* Prints out information about an mbuf. */
6011 /****************************************************************************/
6013 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6015 struct ifnet *ifp = &sc->arpcom.ac_if;
6016 uint32_t val_hi, val_lo;
6017 struct mbuf *mp = m;
6020 /* Index out of range. */
6021 if_printf(ifp, "mbuf: null pointer\n");
6026 val_hi = BCE_ADDR_HI(mp);
6027 val_lo = BCE_ADDR_LO(mp);
6028 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6029 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6031 if (mp->m_flags & M_EXT)
6033 if (mp->m_flags & M_PKTHDR)
6034 kprintf("M_PKTHDR ");
6035 if (mp->m_flags & M_EOR)
6038 if (mp->m_flags & M_RDONLY)
6039 kprintf("M_RDONLY ");
6042 val_hi = BCE_ADDR_HI(mp->m_data);
6043 val_lo = BCE_ADDR_LO(mp->m_data);
6044 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6046 if (mp->m_flags & M_PKTHDR) {
6047 if_printf(ifp, "- m_pkthdr: flags = ( ");
6048 if (mp->m_flags & M_BCAST)
6049 kprintf("M_BCAST ");
6050 if (mp->m_flags & M_MCAST)
6051 kprintf("M_MCAST ");
6052 if (mp->m_flags & M_FRAG)
6054 if (mp->m_flags & M_FIRSTFRAG)
6055 kprintf("M_FIRSTFRAG ");
6056 if (mp->m_flags & M_LASTFRAG)
6057 kprintf("M_LASTFRAG ");
6059 if (mp->m_flags & M_VLANTAG)
6060 kprintf("M_VLANTAG ");
6063 if (mp->m_flags & M_PROMISC)
6064 kprintf("M_PROMISC ");
6066 kprintf(") csum_flags = ( ");
6067 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6068 kprintf("CSUM_IP ");
6069 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6070 kprintf("CSUM_TCP ");
6071 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6072 kprintf("CSUM_UDP ");
6073 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6074 kprintf("CSUM_IP_FRAGS ");
6075 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6076 kprintf("CSUM_FRAGMENT ");
6078 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6079 kprintf("CSUM_TSO ");
6081 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6082 kprintf("CSUM_IP_CHECKED ");
6083 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6084 kprintf("CSUM_IP_VALID ");
6085 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6086 kprintf("CSUM_DATA_VALID ");
6090 if (mp->m_flags & M_EXT) {
6091 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6092 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6093 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6095 val_hi, val_lo, mp->m_ext.ext_size);
6102 /****************************************************************************/
6103 /* Prints out the mbufs in the TX mbuf chain. */
6107 /****************************************************************************/
6109 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6111 struct ifnet *ifp = &sc->arpcom.ac_if;
6115 "----------------------------"
6117 "----------------------------\n");
6119 for (i = 0; i < count; i++) {
6120 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6121 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6122 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6126 "----------------------------"
6128 "----------------------------\n");
6132 /****************************************************************************/
6133 /* Prints out the mbufs in the RX mbuf chain. */
6137 /****************************************************************************/
6139 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6141 struct ifnet *ifp = &sc->arpcom.ac_if;
6145 "----------------------------"
6147 "----------------------------\n");
6149 for (i = 0; i < count; i++) {
6150 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6151 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6152 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6156 "----------------------------"
6158 "----------------------------\n");
6162 /****************************************************************************/
6163 /* Prints out a tx_bd structure. */
6167 /****************************************************************************/
6169 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6171 struct ifnet *ifp = &sc->arpcom.ac_if;
6173 if (idx > MAX_TX_BD) {
6174 /* Index out of range. */
6175 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6176 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6177 /* TX Chain page pointer. */
6178 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6179 "chain page pointer\n",
6180 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6182 /* Normal tx_bd entry. */
6183 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6185 "vlan tag= 0x%04X, flags = 0x%04X (",
6186 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6187 txbd->tx_bd_mss_nbytes,
6188 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6190 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6191 kprintf(" CONN_FAULT");
6193 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6194 kprintf(" TCP_UDP_CKSUM");
6196 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6197 kprintf(" IP_CKSUM");
6199 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6202 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6203 kprintf(" COAL_NOW");
6205 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6206 kprintf(" DONT_GEN_CRC");
6208 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6211 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6214 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6217 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6218 kprintf(" OPTION_WORD");
6220 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6223 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6231 /****************************************************************************/
6232 /* Prints out a rx_bd structure. */
6236 /****************************************************************************/
6238 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6240 struct ifnet *ifp = &sc->arpcom.ac_if;
6242 if (idx > MAX_RX_BD) {
6243 /* Index out of range. */
6244 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6245 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6246 /* TX Chain page pointer. */
6247 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6248 "chain page pointer\n",
6249 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6251 /* Normal tx_bd entry. */
6252 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6253 "nbytes = 0x%08X, flags = 0x%08X\n",
6254 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6255 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6260 /****************************************************************************/
6261 /* Prints out a l2_fhdr structure. */
6265 /****************************************************************************/
6267 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6269 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6270 "pkt_len = 0x%04X, vlan = 0x%04x, "
6271 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6272 idx, l2fhdr->l2_fhdr_status,
6273 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6274 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6278 /****************************************************************************/
6279 /* Prints out the tx chain. */
6283 /****************************************************************************/
6285 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6287 struct ifnet *ifp = &sc->arpcom.ac_if;
6290 /* First some info about the tx_bd chain structure. */
6292 "----------------------------"
6294 "----------------------------\n");
6296 if_printf(ifp, "page size = 0x%08X, "
6297 "tx chain pages = 0x%08X\n",
6298 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6300 if_printf(ifp, "tx_bd per page = 0x%08X, "
6301 "usable tx_bd per page = 0x%08X\n",
6302 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6303 (uint32_t)USABLE_TX_BD_PER_PAGE);
6305 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6308 "----------------------------"
6310 "----------------------------\n");
6312 /* Now print out the tx_bd's themselves. */
6313 for (i = 0; i < count; i++) {
6316 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6317 bce_dump_txbd(sc, tx_prod, txbd);
6318 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6322 "----------------------------"
6324 "----------------------------\n");
6328 /****************************************************************************/
6329 /* Prints out the rx chain. */
6333 /****************************************************************************/
6335 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6337 struct ifnet *ifp = &sc->arpcom.ac_if;
6340 /* First some info about the tx_bd chain structure. */
6342 "----------------------------"
6344 "----------------------------\n");
6346 if_printf(ifp, "page size = 0x%08X, "
6347 "rx chain pages = 0x%08X\n",
6348 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6350 if_printf(ifp, "rx_bd per page = 0x%08X, "
6351 "usable rx_bd per page = 0x%08X\n",
6352 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6353 (uint32_t)USABLE_RX_BD_PER_PAGE);
6355 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6358 "----------------------------"
6360 "----------------------------\n");
6362 /* Now print out the rx_bd's themselves. */
6363 for (i = 0; i < count; i++) {
6366 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6367 bce_dump_rxbd(sc, rx_prod, rxbd);
6368 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6372 "----------------------------"
6374 "----------------------------\n");
6378 /****************************************************************************/
6379 /* Prints out the status block from host memory. */
6383 /****************************************************************************/
6385 bce_dump_status_block(struct bce_softc *sc)
6387 struct status_block *sblk = sc->status_block;
6388 struct ifnet *ifp = &sc->arpcom.ac_if;
6391 "----------------------------"
6393 "----------------------------\n");
6395 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6397 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6398 sblk->status_attn_bits_ack);
6400 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6401 sblk->status_rx_quick_consumer_index0,
6402 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6404 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6405 sblk->status_tx_quick_consumer_index0,
6406 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6408 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6410 /* Theses indices are not used for normal L2 drivers. */
6411 if (sblk->status_rx_quick_consumer_index1) {
6412 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6413 sblk->status_rx_quick_consumer_index1,
6414 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
6417 if (sblk->status_tx_quick_consumer_index1) {
6418 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6419 sblk->status_tx_quick_consumer_index1,
6420 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
6423 if (sblk->status_rx_quick_consumer_index2) {
6424 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6425 sblk->status_rx_quick_consumer_index2,
6426 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
6429 if (sblk->status_tx_quick_consumer_index2) {
6430 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6431 sblk->status_tx_quick_consumer_index2,
6432 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
6435 if (sblk->status_rx_quick_consumer_index3) {
6436 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6437 sblk->status_rx_quick_consumer_index3,
6438 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
6441 if (sblk->status_tx_quick_consumer_index3) {
6442 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6443 sblk->status_tx_quick_consumer_index3,
6444 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
6447 if (sblk->status_rx_quick_consumer_index4 ||
6448 sblk->status_rx_quick_consumer_index5) {
6449 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6450 sblk->status_rx_quick_consumer_index4,
6451 sblk->status_rx_quick_consumer_index5);
6454 if (sblk->status_rx_quick_consumer_index6 ||
6455 sblk->status_rx_quick_consumer_index7) {
6456 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6457 sblk->status_rx_quick_consumer_index6,
6458 sblk->status_rx_quick_consumer_index7);
6461 if (sblk->status_rx_quick_consumer_index8 ||
6462 sblk->status_rx_quick_consumer_index9) {
6463 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6464 sblk->status_rx_quick_consumer_index8,
6465 sblk->status_rx_quick_consumer_index9);
6468 if (sblk->status_rx_quick_consumer_index10 ||
6469 sblk->status_rx_quick_consumer_index11) {
6470 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6471 sblk->status_rx_quick_consumer_index10,
6472 sblk->status_rx_quick_consumer_index11);
6475 if (sblk->status_rx_quick_consumer_index12 ||
6476 sblk->status_rx_quick_consumer_index13) {
6477 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6478 sblk->status_rx_quick_consumer_index12,
6479 sblk->status_rx_quick_consumer_index13);
6482 if (sblk->status_rx_quick_consumer_index14 ||
6483 sblk->status_rx_quick_consumer_index15) {
6484 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6485 sblk->status_rx_quick_consumer_index14,
6486 sblk->status_rx_quick_consumer_index15);
6489 if (sblk->status_completion_producer_index ||
6490 sblk->status_cmd_consumer_index) {
6491 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6492 sblk->status_completion_producer_index,
6493 sblk->status_cmd_consumer_index);
6497 "----------------------------"
6499 "----------------------------\n");
6503 /****************************************************************************/
6504 /* Prints out the statistics block. */
6508 /****************************************************************************/
6510 bce_dump_stats_block(struct bce_softc *sc)
6512 struct statistics_block *sblk = sc->stats_block;
6513 struct ifnet *ifp = &sc->arpcom.ac_if;
6517 " Stats Block (All Stats Not Shown Are 0) "
6518 "---------------\n");
6520 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
6521 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
6522 sblk->stat_IfHCInOctets_hi,
6523 sblk->stat_IfHCInOctets_lo);
6526 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
6527 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
6528 sblk->stat_IfHCInBadOctets_hi,
6529 sblk->stat_IfHCInBadOctets_lo);
6532 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
6533 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
6534 sblk->stat_IfHCOutOctets_hi,
6535 sblk->stat_IfHCOutOctets_lo);
6538 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
6539 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
6540 sblk->stat_IfHCOutBadOctets_hi,
6541 sblk->stat_IfHCOutBadOctets_lo);
6544 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
6545 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
6546 sblk->stat_IfHCInUcastPkts_hi,
6547 sblk->stat_IfHCInUcastPkts_lo);
6550 if (sblk->stat_IfHCInBroadcastPkts_hi ||
6551 sblk->stat_IfHCInBroadcastPkts_lo) {
6552 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
6553 sblk->stat_IfHCInBroadcastPkts_hi,
6554 sblk->stat_IfHCInBroadcastPkts_lo);
6557 if (sblk->stat_IfHCInMulticastPkts_hi ||
6558 sblk->stat_IfHCInMulticastPkts_lo) {
6559 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
6560 sblk->stat_IfHCInMulticastPkts_hi,
6561 sblk->stat_IfHCInMulticastPkts_lo);
6564 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
6565 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
6566 sblk->stat_IfHCOutUcastPkts_hi,
6567 sblk->stat_IfHCOutUcastPkts_lo);
6570 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
6571 sblk->stat_IfHCOutBroadcastPkts_lo) {
6572 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
6573 sblk->stat_IfHCOutBroadcastPkts_hi,
6574 sblk->stat_IfHCOutBroadcastPkts_lo);
6577 if (sblk->stat_IfHCOutMulticastPkts_hi ||
6578 sblk->stat_IfHCOutMulticastPkts_lo) {
6579 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
6580 sblk->stat_IfHCOutMulticastPkts_hi,
6581 sblk->stat_IfHCOutMulticastPkts_lo);
6584 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
6585 if_printf(ifp, " 0x%08X : "
6586 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
6587 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
6590 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
6591 if_printf(ifp, " 0x%08X : "
6592 "Dot3StatsCarrierSenseErrors\n",
6593 sblk->stat_Dot3StatsCarrierSenseErrors);
6596 if (sblk->stat_Dot3StatsFCSErrors) {
6597 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
6598 sblk->stat_Dot3StatsFCSErrors);
6601 if (sblk->stat_Dot3StatsAlignmentErrors) {
6602 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
6603 sblk->stat_Dot3StatsAlignmentErrors);
6606 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
6607 if_printf(ifp, " 0x%08X : "
6608 "Dot3StatsSingleCollisionFrames\n",
6609 sblk->stat_Dot3StatsSingleCollisionFrames);
6612 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
6613 if_printf(ifp, " 0x%08X : "
6614 "Dot3StatsMultipleCollisionFrames\n",
6615 sblk->stat_Dot3StatsMultipleCollisionFrames);
6618 if (sblk->stat_Dot3StatsDeferredTransmissions) {
6619 if_printf(ifp, " 0x%08X : "
6620 "Dot3StatsDeferredTransmissions\n",
6621 sblk->stat_Dot3StatsDeferredTransmissions);
6624 if (sblk->stat_Dot3StatsExcessiveCollisions) {
6625 if_printf(ifp, " 0x%08X : "
6626 "Dot3StatsExcessiveCollisions\n",
6627 sblk->stat_Dot3StatsExcessiveCollisions);
6630 if (sblk->stat_Dot3StatsLateCollisions) {
6631 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
6632 sblk->stat_Dot3StatsLateCollisions);
6635 if (sblk->stat_EtherStatsCollisions) {
6636 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
6637 sblk->stat_EtherStatsCollisions);
6640 if (sblk->stat_EtherStatsFragments) {
6641 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
6642 sblk->stat_EtherStatsFragments);
6645 if (sblk->stat_EtherStatsJabbers) {
6646 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
6647 sblk->stat_EtherStatsJabbers);
6650 if (sblk->stat_EtherStatsUndersizePkts) {
6651 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
6652 sblk->stat_EtherStatsUndersizePkts);
6655 if (sblk->stat_EtherStatsOverrsizePkts) {
6656 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
6657 sblk->stat_EtherStatsOverrsizePkts);
6660 if (sblk->stat_EtherStatsPktsRx64Octets) {
6661 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
6662 sblk->stat_EtherStatsPktsRx64Octets);
6665 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
6666 if_printf(ifp, " 0x%08X : "
6667 "EtherStatsPktsRx65Octetsto127Octets\n",
6668 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
6671 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
6672 if_printf(ifp, " 0x%08X : "
6673 "EtherStatsPktsRx128Octetsto255Octets\n",
6674 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
6677 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
6678 if_printf(ifp, " 0x%08X : "
6679 "EtherStatsPktsRx256Octetsto511Octets\n",
6680 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
6683 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
6684 if_printf(ifp, " 0x%08X : "
6685 "EtherStatsPktsRx512Octetsto1023Octets\n",
6686 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
6689 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
6690 if_printf(ifp, " 0x%08X : "
6691 "EtherStatsPktsRx1024Octetsto1522Octets\n",
6692 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
6695 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
6696 if_printf(ifp, " 0x%08X : "
6697 "EtherStatsPktsRx1523Octetsto9022Octets\n",
6698 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
6701 if (sblk->stat_EtherStatsPktsTx64Octets) {
6702 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
6703 sblk->stat_EtherStatsPktsTx64Octets);
6706 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
6707 if_printf(ifp, " 0x%08X : "
6708 "EtherStatsPktsTx65Octetsto127Octets\n",
6709 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
6712 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
6713 if_printf(ifp, " 0x%08X : "
6714 "EtherStatsPktsTx128Octetsto255Octets\n",
6715 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
6718 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
6719 if_printf(ifp, " 0x%08X : "
6720 "EtherStatsPktsTx256Octetsto511Octets\n",
6721 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
6724 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
6725 if_printf(ifp, " 0x%08X : "
6726 "EtherStatsPktsTx512Octetsto1023Octets\n",
6727 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
6730 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
6731 if_printf(ifp, " 0x%08X : "
6732 "EtherStatsPktsTx1024Octetsto1522Octets\n",
6733 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
6736 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
6737 if_printf(ifp, " 0x%08X : "
6738 "EtherStatsPktsTx1523Octetsto9022Octets\n",
6739 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
6742 if (sblk->stat_XonPauseFramesReceived) {
6743 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
6744 sblk->stat_XonPauseFramesReceived);
6747 if (sblk->stat_XoffPauseFramesReceived) {
6748 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
6749 sblk->stat_XoffPauseFramesReceived);
6752 if (sblk->stat_OutXonSent) {
6753 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6754 sblk->stat_OutXonSent);
6757 if (sblk->stat_OutXoffSent) {
6758 if_printf(ifp, " 0x%08X : OutXoffSent\n",
6759 sblk->stat_OutXoffSent);
6762 if (sblk->stat_FlowControlDone) {
6763 if_printf(ifp, " 0x%08X : FlowControlDone\n",
6764 sblk->stat_FlowControlDone);
6767 if (sblk->stat_MacControlFramesReceived) {
6768 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
6769 sblk->stat_MacControlFramesReceived);
6772 if (sblk->stat_XoffStateEntered) {
6773 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
6774 sblk->stat_XoffStateEntered);
6777 if (sblk->stat_IfInFramesL2FilterDiscards) {
6778 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
6781 if (sblk->stat_IfInRuleCheckerDiscards) {
6782 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
6783 sblk->stat_IfInRuleCheckerDiscards);
6786 if (sblk->stat_IfInFTQDiscards) {
6787 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
6788 sblk->stat_IfInFTQDiscards);
6791 if (sblk->stat_IfInMBUFDiscards) {
6792 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
6793 sblk->stat_IfInMBUFDiscards);
6796 if (sblk->stat_IfInRuleCheckerP4Hit) {
6797 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
6798 sblk->stat_IfInRuleCheckerP4Hit);
6801 if (sblk->stat_CatchupInRuleCheckerDiscards) {
6802 if_printf(ifp, " 0x%08X : "
6803 "CatchupInRuleCheckerDiscards\n",
6804 sblk->stat_CatchupInRuleCheckerDiscards);
6807 if (sblk->stat_CatchupInFTQDiscards) {
6808 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
6809 sblk->stat_CatchupInFTQDiscards);
6812 if (sblk->stat_CatchupInMBUFDiscards) {
6813 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
6814 sblk->stat_CatchupInMBUFDiscards);
6817 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
6818 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
6819 sblk->stat_CatchupInRuleCheckerP4Hit);
6823 "----------------------------"
6825 "----------------------------\n");
6829 /****************************************************************************/
6830 /* Prints out a summary of the driver state. */
6834 /****************************************************************************/
6836 bce_dump_driver_state(struct bce_softc *sc)
6838 struct ifnet *ifp = &sc->arpcom.ac_if;
6839 uint32_t val_hi, val_lo;
6842 "-----------------------------"
6844 "-----------------------------\n");
6846 val_hi = BCE_ADDR_HI(sc);
6847 val_lo = BCE_ADDR_LO(sc);
6848 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
6849 "virtual address\n", val_hi, val_lo);
6851 val_hi = BCE_ADDR_HI(sc->status_block);
6852 val_lo = BCE_ADDR_LO(sc->status_block);
6853 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
6854 "virtual address\n", val_hi, val_lo);
6856 val_hi = BCE_ADDR_HI(sc->stats_block);
6857 val_lo = BCE_ADDR_LO(sc->stats_block);
6858 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
6859 "virtual address\n", val_hi, val_lo);
6861 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
6862 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
6863 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
6864 "virtual adddress\n", val_hi, val_lo);
6866 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
6867 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
6868 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
6869 "virtual address\n", val_hi, val_lo);
6871 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
6872 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
6873 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
6874 "virtual address\n", val_hi, val_lo);
6876 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
6877 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
6878 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
6879 "virtual address\n", val_hi, val_lo);
6881 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
6882 "h/w intrs\n", sc->interrupts_generated);
6884 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
6885 "rx interrupts handled\n", sc->rx_interrupts);
6887 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
6888 "tx interrupts handled\n", sc->tx_interrupts);
6890 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
6891 "status block index\n", sc->last_status_idx);
6893 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
6894 "tx producer index\n",
6895 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
6897 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
6898 "tx consumer index\n",
6899 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
6901 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
6902 "tx producer bseq index\n", sc->tx_prod_bseq);
6904 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
6905 "rx producer index\n",
6906 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
6908 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
6909 "rx consumer index\n",
6910 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
6912 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
6913 "rx producer bseq index\n", sc->rx_prod_bseq);
6915 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6916 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6918 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
6919 "free rx_bd's\n", sc->free_rx_bd);
6921 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
6922 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
6924 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
6925 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
6927 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
6928 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
6930 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
6933 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
6934 sc->tx_hi_watermark, sc->max_tx_bd);
6936 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
6937 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
6940 "----------------------------"
6942 "----------------------------\n");
6946 /****************************************************************************/
6947 /* Prints out the hardware state through a summary of important registers, */
\r
6948 /* followed by a complete register dump. */
6952 /****************************************************************************/
6954 bce_dump_hw_state(struct bce_softc *sc)
6956 struct ifnet *ifp = &sc->arpcom.ac_if;
6961 "----------------------------"
6963 "----------------------------\n");
6965 if_printf(ifp, "0x%08X - bootcode version\n", sc->bce_fw_ver);
6967 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
6968 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
6969 val1, BCE_MISC_ENABLE_STATUS_BITS);
6971 val1 = REG_RD(sc, BCE_DMA_STATUS);
6972 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
6974 val1 = REG_RD(sc, BCE_CTX_STATUS);
6975 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
6977 val1 = REG_RD(sc, BCE_EMAC_STATUS);
6978 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
6979 val1, BCE_EMAC_STATUS);
6981 val1 = REG_RD(sc, BCE_RPM_STATUS);
6982 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
6984 val1 = REG_RD(sc, BCE_TBDR_STATUS);
6985 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
6986 val1, BCE_TBDR_STATUS);
6988 val1 = REG_RD(sc, BCE_TDMA_STATUS);
6989 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
6990 val1, BCE_TDMA_STATUS);
6992 val1 = REG_RD(sc, BCE_HC_STATUS);
6993 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
6995 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
6996 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
6997 val1, BCE_TXP_CPU_STATE);
6999 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7000 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7001 val1, BCE_TPAT_CPU_STATE);
7003 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7004 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7005 val1, BCE_RXP_CPU_STATE);
7007 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7008 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7009 val1, BCE_COM_CPU_STATE);
7011 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7012 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7013 val1, BCE_MCP_CPU_STATE);
7015 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7016 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7017 val1, BCE_CP_CPU_STATE);
7020 "----------------------------"
7022 "----------------------------\n");
7025 "----------------------------"
7027 "----------------------------\n");
7029 for (i = 0x400; i < 0x8000; i += 0x10) {
7030 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7032 REG_RD(sc, i + 0x4),
7033 REG_RD(sc, i + 0x8),
7034 REG_RD(sc, i + 0xc));
7038 "----------------------------"
7040 "----------------------------\n");
7044 /****************************************************************************/
7045 /* Prints out the TXP state. */
\r
7049 /****************************************************************************/
7051 bce_dump_txp_state(struct bce_softc *sc)
7053 struct ifnet *ifp = &sc->arpcom.ac_if;
7058 "----------------------------"
7060 "----------------------------\n");
7062 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7063 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7064 val1, BCE_TXP_CPU_MODE);
7066 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7067 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7068 val1, BCE_TXP_CPU_STATE);
7070 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7071 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7072 val1, BCE_TXP_CPU_EVENT_MASK);
7075 "----------------------------"
7077 "----------------------------\n");
7079 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7080 /* Skip the big blank spaces */
7081 if (i < 0x454000 && i > 0x5ffff) {
7082 if_printf(ifp, "0x%04X: "
7083 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7085 REG_RD_IND(sc, i + 0x4),
7086 REG_RD_IND(sc, i + 0x8),
7087 REG_RD_IND(sc, i + 0xc));
7092 "----------------------------"
7094 "----------------------------\n");
7098 /****************************************************************************/
7099 /* Prints out the RXP state. */
\r
7103 /****************************************************************************/
7105 bce_dump_rxp_state(struct bce_softc *sc)
7107 struct ifnet *ifp = &sc->arpcom.ac_if;
7112 "----------------------------"
7114 "----------------------------\n");
7116 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7117 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7118 val1, BCE_RXP_CPU_MODE);
7120 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7121 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7122 val1, BCE_RXP_CPU_STATE);
7124 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7125 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7126 val1, BCE_RXP_CPU_EVENT_MASK);
7129 "----------------------------"
7131 "----------------------------\n");
7133 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7134 /* Skip the big blank sapces */
7135 if (i < 0xc5400 && i > 0xdffff) {
7136 if_printf(ifp, "0x%04X: "
7137 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7139 REG_RD_IND(sc, i + 0x4),
7140 REG_RD_IND(sc, i + 0x8),
7141 REG_RD_IND(sc, i + 0xc));
7146 "----------------------------"
7148 "----------------------------\n");
7152 /****************************************************************************/
7153 /* Prints out the TPAT state. */
\r
7157 /****************************************************************************/
7159 bce_dump_tpat_state(struct bce_softc *sc)
7161 struct ifnet *ifp = &sc->arpcom.ac_if;
7166 "----------------------------"
7168 "----------------------------\n");
7170 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7171 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7172 val1, BCE_TPAT_CPU_MODE);
7174 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7175 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7176 val1, BCE_TPAT_CPU_STATE);
7178 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7179 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7180 val1, BCE_TPAT_CPU_EVENT_MASK);
7183 "----------------------------"
7185 "----------------------------\n");
7187 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7188 /* Skip the big blank spaces */
7189 if (i < 0x854000 && i > 0x9ffff) {
7190 if_printf(ifp, "0x%04X: "
7191 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7193 REG_RD_IND(sc, i + 0x4),
7194 REG_RD_IND(sc, i + 0x8),
7195 REG_RD_IND(sc, i + 0xc));
7200 "----------------------------"
7202 "----------------------------\n");
7206 /****************************************************************************/
7207 /* Prints out the driver state and then enters the debugger. */
7211 /****************************************************************************/
7213 bce_breakpoint(struct bce_softc *sc)
7216 bce_freeze_controller(sc);
7219 bce_dump_driver_state(sc);
7220 bce_dump_status_block(sc);
7221 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7222 bce_dump_hw_state(sc);
7223 bce_dump_txp_state(sc);
7226 bce_unfreeze_controller(sc);
7229 /* Call the debugger. */
7233 #endif /* BCE_DEBUG */
7236 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7238 struct bce_softc *sc = arg1;
7240 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7241 &sc->bce_tx_quick_cons_trip_int,
7242 BCE_COALMASK_TX_BDS_INT);
7246 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7248 struct bce_softc *sc = arg1;
7250 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7251 &sc->bce_tx_quick_cons_trip,
7252 BCE_COALMASK_TX_BDS);
7256 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7258 struct bce_softc *sc = arg1;
7260 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7261 &sc->bce_tx_ticks_int,
7262 BCE_COALMASK_TX_TICKS_INT);
7266 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7268 struct bce_softc *sc = arg1;
7270 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7272 BCE_COALMASK_TX_TICKS);
7276 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7278 struct bce_softc *sc = arg1;
7280 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7281 &sc->bce_rx_quick_cons_trip_int,
7282 BCE_COALMASK_RX_BDS_INT);
7286 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7288 struct bce_softc *sc = arg1;
7290 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7291 &sc->bce_rx_quick_cons_trip,
7292 BCE_COALMASK_RX_BDS);
7296 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7298 struct bce_softc *sc = arg1;
7300 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7301 &sc->bce_rx_ticks_int,
7302 BCE_COALMASK_RX_TICKS_INT);
7306 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7308 struct bce_softc *sc = arg1;
7310 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7312 BCE_COALMASK_RX_TICKS);
7316 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7317 uint32_t coalchg_mask)
7319 struct bce_softc *sc = arg1;
7320 struct ifnet *ifp = &sc->arpcom.ac_if;
7323 lwkt_serialize_enter(ifp->if_serializer);
7326 error = sysctl_handle_int(oidp, &v, 0, req);
7327 if (!error && req->newptr != NULL) {
7332 sc->bce_coalchg_mask |= coalchg_mask;
7336 lwkt_serialize_exit(ifp->if_serializer);
7341 bce_coal_change(struct bce_softc *sc)
7343 struct ifnet *ifp = &sc->arpcom.ac_if;
7345 ASSERT_SERIALIZED(ifp->if_serializer);
7347 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7348 sc->bce_coalchg_mask = 0;
7352 if (sc->bce_coalchg_mask &
7353 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7354 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7355 (sc->bce_tx_quick_cons_trip_int << 16) |
7356 sc->bce_tx_quick_cons_trip);
7358 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7359 sc->bce_tx_quick_cons_trip,
7360 sc->bce_tx_quick_cons_trip_int);
7364 if (sc->bce_coalchg_mask &
7365 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7366 REG_WR(sc, BCE_HC_TX_TICKS,
7367 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7369 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7370 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7374 if (sc->bce_coalchg_mask &
7375 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7376 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7377 (sc->bce_rx_quick_cons_trip_int << 16) |
7378 sc->bce_rx_quick_cons_trip);
7380 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7381 sc->bce_rx_quick_cons_trip,
7382 sc->bce_rx_quick_cons_trip_int);
7386 if (sc->bce_coalchg_mask &
7387 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7388 REG_WR(sc, BCE_HC_RX_TICKS,
7389 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7391 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7392 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7396 sc->bce_coalchg_mask = 0;