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 $
34 * The following controllers are supported by this driver:
42 * The following controllers are not supported by this driver:
48 * BCM5709S A0, A1, B0, B1, B2, C0
52 #include "opt_polling.h"
54 #include <sys/param.h>
56 #include <sys/endian.h>
57 #include <sys/kernel.h>
58 #include <sys/interrupt.h>
60 #include <sys/malloc.h>
61 #include <sys/queue.h>
63 #include <sys/random.h>
66 #include <sys/serialize.h>
67 #include <sys/socket.h>
68 #include <sys/sockio.h>
69 #include <sys/sysctl.h>
72 #include <net/ethernet.h>
74 #include <net/if_arp.h>
75 #include <net/if_dl.h>
76 #include <net/if_media.h>
77 #include <net/if_types.h>
78 #include <net/ifq_var.h>
79 #include <net/vlan/if_vlan_var.h>
80 #include <net/vlan/if_vlan_ether.h>
82 #include <dev/netif/mii_layer/mii.h>
83 #include <dev/netif/mii_layer/miivar.h>
85 #include <bus/pci/pcireg.h>
86 #include <bus/pci/pcivar.h>
88 #include "miibus_if.h"
90 #include <dev/netif/bce/if_bcereg.h>
91 #include <dev/netif/bce/if_bcefw.h>
93 /****************************************************************************/
94 /* BCE Debug Options */
95 /****************************************************************************/
98 static uint32_t bce_debug = BCE_WARN;
102 * 1 = 1 in 2,147,483,648
103 * 256 = 1 in 8,388,608
104 * 2048 = 1 in 1,048,576
105 * 65536 = 1 in 32,768
106 * 1048576 = 1 in 2,048
109 * 1073741824 = 1 in 2
111 * bce_debug_l2fhdr_status_check:
112 * How often the l2_fhdr frame error check will fail.
114 * bce_debug_unexpected_attention:
115 * How often the unexpected attention check will fail.
117 * bce_debug_mbuf_allocation_failure:
118 * How often to simulate an mbuf allocation failure.
120 * bce_debug_dma_map_addr_failure:
121 * How often to simulate a DMA mapping failure.
123 * bce_debug_bootcode_running_failure:
124 * How often to simulate a bootcode failure.
126 static int bce_debug_l2fhdr_status_check = 0;
127 static int bce_debug_unexpected_attention = 0;
128 static int bce_debug_mbuf_allocation_failure = 0;
129 static int bce_debug_dma_map_addr_failure = 0;
130 static int bce_debug_bootcode_running_failure = 0;
132 #endif /* BCE_DEBUG */
135 /****************************************************************************/
136 /* PCI Device ID Table */
138 /* Used by bce_probe() to identify the devices supported by this driver. */
139 /****************************************************************************/
140 #define BCE_DEVDESC_MAX 64
142 static struct bce_type bce_devs[] = {
143 /* BCM5706C Controllers and OEM boards. */
144 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
145 "HP NC370T Multifunction Gigabit Server Adapter" },
146 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
147 "HP NC370i Multifunction Gigabit Server Adapter" },
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
149 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
150 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
151 "HP NC371i Multifunction Gigabit Server Adapter" },
152 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
153 "Broadcom NetXtreme II BCM5706 1000Base-T" },
155 /* BCM5706S controllers and OEM boards. */
156 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
157 "HP NC370F Multifunction Gigabit Server Adapter" },
158 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
159 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
161 /* BCM5708C controllers and OEM boards. */
162 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
163 "HP NC373T PCIe Multifunction Gig Server Adapter" },
164 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
165 "HP NC373i Multifunction Gigabit Server Adapter" },
166 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
167 "HP NC374m PCIe Multifunction Adapter" },
168 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
169 "Broadcom NetXtreme II BCM5708 1000Base-T" },
171 /* BCM5708S controllers and OEM boards. */
172 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
173 "HP NC373m Multifunction Gigabit Server Adapter" },
174 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
175 "HP NC373i Multifunction Gigabit Server Adapter" },
176 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
177 "HP NC373F PCIe Multifunc Giga Server Adapter" },
178 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
179 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
181 /* BCM5709C controllers and OEM boards. */
182 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
183 "HP NC382i DP Multifunction Gigabit Server Adapter" },
184 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
185 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
186 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
187 "Broadcom NetXtreme II BCM5709 1000Base-T" },
189 /* BCM5709S controllers and OEM boards. */
190 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
191 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
192 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
193 "HP NC382i DP Multifunction Gigabit Server Adapter" },
194 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
195 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
197 /* BCM5716 controllers and OEM boards. */
198 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
199 "Broadcom NetXtreme II BCM5716 1000Base-T" },
205 /****************************************************************************/
206 /* Supported Flash NVRAM device data. */
207 /****************************************************************************/
208 static const struct flash_spec flash_table[] =
210 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
211 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
214 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
215 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
216 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
218 /* Expansion entry 0001 */
219 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
220 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
221 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
223 /* Saifun SA25F010 (non-buffered flash) */
224 /* strap, cfg1, & write1 need updates */
225 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
226 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
227 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
228 "Non-buffered flash (128kB)"},
229 /* Saifun SA25F020 (non-buffered flash) */
230 /* strap, cfg1, & write1 need updates */
231 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
232 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
233 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
234 "Non-buffered flash (256kB)"},
235 /* Expansion entry 0100 */
236 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
237 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
238 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
240 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
241 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
242 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
243 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
244 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
245 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
246 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
247 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
248 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
249 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
250 /* Saifun SA25F005 (non-buffered flash) */
251 /* strap, cfg1, & write1 need updates */
252 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
253 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
254 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
255 "Non-buffered flash (64kB)"},
257 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
258 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
259 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
261 /* Expansion entry 1001 */
262 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
263 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
264 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
266 /* Expansion entry 1010 */
267 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
268 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
269 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
271 /* ATMEL AT45DB011B (buffered flash) */
272 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
273 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
274 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
275 "Buffered flash (128kB)"},
276 /* Expansion entry 1100 */
277 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
278 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
279 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
281 /* Expansion entry 1101 */
282 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
283 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
284 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
286 /* Ateml Expansion entry 1110 */
287 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
288 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
289 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
290 "Entry 1110 (Atmel)"},
291 /* ATMEL AT45DB021B (buffered flash) */
292 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
293 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
294 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
295 "Buffered flash (256kB)"},
299 * The BCM5709 controllers transparently handle the
300 * differences between Atmel 264 byte pages and all
301 * flash devices which use 256 byte pages, so no
302 * logical-to-physical mapping is required in the
305 static struct flash_spec flash_5709 = {
306 .flags = BCE_NV_BUFFERED,
307 .page_bits = BCM5709_FLASH_PAGE_BITS,
308 .page_size = BCM5709_FLASH_PAGE_SIZE,
309 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
310 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
311 .name = "5709/5716 buffered flash (256kB)",
315 /****************************************************************************/
316 /* DragonFly device entry points. */
317 /****************************************************************************/
318 static int bce_probe(device_t);
319 static int bce_attach(device_t);
320 static int bce_detach(device_t);
321 static void bce_shutdown(device_t);
323 /****************************************************************************/
324 /* BCE Debug Data Structure Dump Routines */
325 /****************************************************************************/
327 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
328 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
329 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
330 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
331 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
332 static void bce_dump_l2fhdr(struct bce_softc *, int,
333 struct l2_fhdr *) __unused;
334 static void bce_dump_tx_chain(struct bce_softc *, int, int);
335 static void bce_dump_rx_chain(struct bce_softc *, int, int);
336 static void bce_dump_status_block(struct bce_softc *);
337 static void bce_dump_driver_state(struct bce_softc *);
338 static void bce_dump_stats_block(struct bce_softc *) __unused;
339 static void bce_dump_hw_state(struct bce_softc *);
340 static void bce_dump_txp_state(struct bce_softc *);
341 static void bce_dump_rxp_state(struct bce_softc *) __unused;
342 static void bce_dump_tpat_state(struct bce_softc *) __unused;
343 static void bce_freeze_controller(struct bce_softc *) __unused;
344 static void bce_unfreeze_controller(struct bce_softc *) __unused;
345 static void bce_breakpoint(struct bce_softc *);
346 #endif /* BCE_DEBUG */
349 /****************************************************************************/
350 /* BCE Register/Memory Access Routines */
351 /****************************************************************************/
352 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
353 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
354 static void bce_shmem_wr(struct bce_softc *, uint32_t, uint32_t);
355 static uint32_t bce_shmem_rd(struct bce_softc *, u32);
356 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
357 static int bce_miibus_read_reg(device_t, int, int);
358 static int bce_miibus_write_reg(device_t, int, int, int);
359 static void bce_miibus_statchg(device_t);
362 /****************************************************************************/
363 /* BCE NVRAM Access Routines */
364 /****************************************************************************/
365 static int bce_acquire_nvram_lock(struct bce_softc *);
366 static int bce_release_nvram_lock(struct bce_softc *);
367 static void bce_enable_nvram_access(struct bce_softc *);
368 static void bce_disable_nvram_access(struct bce_softc *);
369 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
371 static int bce_init_nvram(struct bce_softc *);
372 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
373 static int bce_nvram_test(struct bce_softc *);
375 /****************************************************************************/
376 /* BCE DMA Allocate/Free Routines */
377 /****************************************************************************/
378 static int bce_dma_alloc(struct bce_softc *);
379 static void bce_dma_free(struct bce_softc *);
380 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
382 /****************************************************************************/
383 /* BCE Firmware Synchronization and Load */
384 /****************************************************************************/
385 static int bce_fw_sync(struct bce_softc *, uint32_t);
386 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
388 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
390 static void bce_start_cpu(struct bce_softc *, struct cpu_reg *);
391 static void bce_halt_cpu(struct bce_softc *, struct cpu_reg *);
392 static void bce_start_rxp_cpu(struct bce_softc *);
393 static void bce_init_rxp_cpu(struct bce_softc *);
394 static void bce_init_txp_cpu(struct bce_softc *);
395 static void bce_init_tpat_cpu(struct bce_softc *);
396 static void bce_init_cp_cpu(struct bce_softc *);
397 static void bce_init_com_cpu(struct bce_softc *);
398 static void bce_init_cpus(struct bce_softc *);
400 static void bce_stop(struct bce_softc *);
401 static int bce_reset(struct bce_softc *, uint32_t);
402 static int bce_chipinit(struct bce_softc *);
403 static int bce_blockinit(struct bce_softc *);
404 static int bce_newbuf_std(struct bce_softc *, uint16_t *, uint16_t *,
406 static void bce_setup_rxdesc_std(struct bce_softc *, uint16_t, uint32_t *);
407 static void bce_probe_pci_caps(struct bce_softc *);
408 static void bce_print_adapter_info(struct bce_softc *);
409 static void bce_get_media(struct bce_softc *);
411 static void bce_init_tx_context(struct bce_softc *);
412 static int bce_init_tx_chain(struct bce_softc *);
413 static void bce_init_rx_context(struct bce_softc *);
414 static int bce_init_rx_chain(struct bce_softc *);
415 static void bce_free_rx_chain(struct bce_softc *);
416 static void bce_free_tx_chain(struct bce_softc *);
418 static int bce_encap(struct bce_softc *, struct mbuf **);
419 static void bce_start(struct ifnet *);
420 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
421 static void bce_watchdog(struct ifnet *);
422 static int bce_ifmedia_upd(struct ifnet *);
423 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
424 static void bce_init(void *);
425 static void bce_mgmt_init(struct bce_softc *);
427 static int bce_init_ctx(struct bce_softc *);
428 static void bce_get_mac_addr(struct bce_softc *);
429 static void bce_set_mac_addr(struct bce_softc *);
430 static void bce_phy_intr(struct bce_softc *);
431 static void bce_rx_intr(struct bce_softc *, int);
432 static void bce_tx_intr(struct bce_softc *);
433 static void bce_disable_intr(struct bce_softc *);
434 static void bce_enable_intr(struct bce_softc *, int);
436 #ifdef DEVICE_POLLING
437 static void bce_poll(struct ifnet *, enum poll_cmd, int);
439 static void bce_intr(struct bce_softc *);
440 static void bce_intr_legacy(void *);
441 static void bce_intr_msi(void *);
442 static void bce_intr_msi_oneshot(void *);
443 static void bce_set_rx_mode(struct bce_softc *);
444 static void bce_stats_update(struct bce_softc *);
445 static void bce_tick(void *);
446 static void bce_tick_serialized(struct bce_softc *);
447 static void bce_pulse(void *);
448 static void bce_add_sysctls(struct bce_softc *);
450 static void bce_coal_change(struct bce_softc *);
451 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
452 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
453 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
454 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
455 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
456 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
457 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
458 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
459 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
460 uint32_t *, uint32_t);
464 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
465 * takes 1023 as the TX ticks limit. However, using 1023 will
466 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
467 * there is _no_ network activity on the NIC.
469 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
470 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
471 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
472 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
473 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
474 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
475 static uint32_t bce_rx_ticks_int = 125; /* bcm: 18 */
476 static uint32_t bce_rx_ticks = 125; /* bcm: 18 */
478 static int bce_msi_enable = 1;
480 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
481 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
482 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
483 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
484 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
485 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
486 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
487 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
488 TUNABLE_INT("hw.bce.msi.enable", &bce_msi_enable);
490 /****************************************************************************/
491 /* DragonFly device dispatch table. */
492 /****************************************************************************/
493 static device_method_t bce_methods[] = {
494 /* Device interface */
495 DEVMETHOD(device_probe, bce_probe),
496 DEVMETHOD(device_attach, bce_attach),
497 DEVMETHOD(device_detach, bce_detach),
498 DEVMETHOD(device_shutdown, bce_shutdown),
501 DEVMETHOD(bus_print_child, bus_generic_print_child),
502 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
505 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
506 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
507 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
512 static driver_t bce_driver = {
515 sizeof(struct bce_softc)
518 static devclass_t bce_devclass;
521 DECLARE_DUMMY_MODULE(if_bce);
522 MODULE_DEPEND(bce, miibus, 1, 1, 1);
523 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
524 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
527 /****************************************************************************/
528 /* Device probe function. */
530 /* Compares the device to the driver's list of supported devices and */
531 /* reports back to the OS whether this is the right driver for the device. */
534 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
535 /****************************************************************************/
537 bce_probe(device_t dev)
540 uint16_t vid, did, svid, sdid;
542 /* Get the data for the device to be probed. */
543 vid = pci_get_vendor(dev);
544 did = pci_get_device(dev);
545 svid = pci_get_subvendor(dev);
546 sdid = pci_get_subdevice(dev);
548 /* Look through the list of known devices for a match. */
549 for (t = bce_devs; t->bce_name != NULL; ++t) {
550 if (vid == t->bce_vid && did == t->bce_did &&
551 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
552 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
553 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
556 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
558 /* Print out the device identity. */
559 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
561 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
563 device_set_desc_copy(dev, descbuf);
564 kfree(descbuf, M_TEMP);
572 /****************************************************************************/
573 /* PCI Capabilities Probe Function. */
575 /* Walks the PCI capabiites list for the device to find what features are */
580 /****************************************************************************/
582 bce_print_adapter_info(struct bce_softc *sc)
584 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
586 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
587 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
590 if (sc->bce_flags & BCE_PCIE_FLAG) {
591 kprintf("Bus (PCIe x%d, ", sc->link_width);
592 switch (sc->link_speed) {
594 kprintf("2.5Gbps); ");
600 kprintf("Unknown link speed); ");
604 kprintf("Bus (PCI%s, %s, %dMHz); ",
605 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
606 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
610 /* Firmware version and device features. */
611 kprintf("B/C (%s)", sc->bce_bc_ver);
613 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
614 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
616 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
617 kprintf("MFW[%s]", sc->bce_mfw_ver);
618 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
626 /****************************************************************************/
627 /* PCI Capabilities Probe Function. */
629 /* Walks the PCI capabiites list for the device to find what features are */
634 /****************************************************************************/
636 bce_probe_pci_caps(struct bce_softc *sc)
638 device_t dev = sc->bce_dev;
641 if (pci_is_pcix(dev))
642 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
644 ptr = pci_get_pciecap_ptr(dev);
646 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
648 sc->link_speed = link_status & 0xf;
649 sc->link_width = (link_status >> 4) & 0x3f;
650 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
651 sc->bce_flags |= BCE_PCIE_FLAG;
656 /****************************************************************************/
657 /* Device attach function. */
659 /* Allocates device resources, performs secondary chip identification, */
660 /* resets and initializes the hardware, and initializes driver instance */
664 /* 0 on success, positive value on failure. */
665 /****************************************************************************/
667 bce_attach(device_t dev)
669 struct bce_softc *sc = device_get_softc(dev);
670 struct ifnet *ifp = &sc->arpcom.ac_if;
673 void (*irq_handle)(void *);
678 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
680 pci_enable_busmaster(dev);
682 bce_probe_pci_caps(sc);
684 /* Allocate PCI memory resources. */
686 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
687 RF_ACTIVE | PCI_RF_DENSE);
688 if (sc->bce_res_mem == NULL) {
689 device_printf(dev, "PCI memory allocation failed\n");
692 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
693 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
695 /* Allocate PCI IRQ resources. */
696 sc->bce_irq_type = pci_alloc_1intr(dev, bce_msi_enable,
697 &sc->bce_irq_rid, &irq_flags);
699 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
700 &sc->bce_irq_rid, irq_flags);
701 if (sc->bce_res_irq == NULL) {
702 device_printf(dev, "PCI map interrupt failed\n");
708 * Configure byte swap and enable indirect register access.
709 * Rely on CPU to do target byte swapping on big endian systems.
710 * Access to registers outside of PCI configurtion space are not
711 * valid until this is done.
713 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
714 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
715 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
717 /* Save ASIC revsion info. */
718 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
720 /* Weed out any non-production controller revisions. */
721 switch (BCE_CHIP_ID(sc)) {
722 case BCE_CHIP_ID_5706_A0:
723 case BCE_CHIP_ID_5706_A1:
724 case BCE_CHIP_ID_5708_A0:
725 case BCE_CHIP_ID_5708_B0:
726 case BCE_CHIP_ID_5709_A0:
727 case BCE_CHIP_ID_5709_B0:
728 case BCE_CHIP_ID_5709_B1:
730 /* 5709C B2 seems to work fine */
731 case BCE_CHIP_ID_5709_B2:
733 device_printf(dev, "Unsupported chip id 0x%08x!\n",
739 if (sc->bce_irq_type == PCI_INTR_TYPE_LEGACY) {
740 irq_handle = bce_intr_legacy;
741 } else if (sc->bce_irq_type == PCI_INTR_TYPE_MSI) {
742 irq_handle = bce_intr_msi;
743 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
744 irq_handle = bce_intr_msi_oneshot;
745 sc->bce_flags |= BCE_ONESHOT_MSI_FLAG;
748 panic("%s: unsupported intr type %d\n",
749 device_get_nameunit(dev), sc->bce_irq_type);
753 * Find the base address for shared memory access.
754 * Newer versions of bootcode use a signature and offset
755 * while older versions use a fixed address.
757 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
758 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
759 BCE_SHM_HDR_SIGNATURE_SIG) {
760 /* Multi-port devices use different offsets in shared memory. */
761 sc->bce_shmem_base = REG_RD_IND(sc,
762 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
764 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
766 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
768 /* Fetch the bootcode revision. */
769 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
770 for (i = 0, j = 0; i < 3; i++) {
774 num = (uint8_t)(val >> (24 - (i * 8)));
775 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
776 if (num >= k || !skip0 || k == 1) {
777 sc->bce_bc_ver[j++] = (num / k) + '0';
782 sc->bce_bc_ver[j++] = '.';
785 /* Check if any management firwmare is running. */
786 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
787 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
788 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
790 /* Allow time for firmware to enter the running state. */
791 for (i = 0; i < 30; i++) {
792 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
793 if (val & BCE_CONDITION_MFW_RUN_MASK)
799 /* Check the current bootcode state. */
800 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
801 BCE_CONDITION_MFW_RUN_MASK;
802 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
803 val != BCE_CONDITION_MFW_RUN_NONE) {
804 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
806 for (i = 0, j = 0; j < 3; j++) {
807 val = bce_reg_rd_ind(sc, addr + j * 4);
809 memcpy(&sc->bce_mfw_ver[i], &val, 4);
814 /* Get PCI bus information (speed and type). */
815 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
816 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
819 sc->bce_flags |= BCE_PCIX_FLAG;
821 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
822 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
824 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
825 sc->bus_speed_mhz = 133;
828 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
829 sc->bus_speed_mhz = 100;
832 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
833 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
834 sc->bus_speed_mhz = 66;
837 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
838 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
839 sc->bus_speed_mhz = 50;
842 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
843 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
844 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
845 sc->bus_speed_mhz = 33;
849 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
850 sc->bus_speed_mhz = 66;
852 sc->bus_speed_mhz = 33;
855 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
856 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
858 /* Reset the controller. */
859 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
863 /* Initialize the controller. */
864 rc = bce_chipinit(sc);
866 device_printf(dev, "Controller initialization failed!\n");
870 /* Perform NVRAM test. */
871 rc = bce_nvram_test(sc);
873 device_printf(dev, "NVRAM test failed!\n");
877 /* Fetch the permanent Ethernet MAC address. */
878 bce_get_mac_addr(sc);
881 * Trip points control how many BDs
882 * should be ready before generating an
883 * interrupt while ticks control how long
884 * a BD can sit in the chain before
885 * generating an interrupt. Set the default
886 * values for the RX and TX rings.
890 /* Force more frequent interrupts. */
891 sc->bce_tx_quick_cons_trip_int = 1;
892 sc->bce_tx_quick_cons_trip = 1;
893 sc->bce_tx_ticks_int = 0;
894 sc->bce_tx_ticks = 0;
896 sc->bce_rx_quick_cons_trip_int = 1;
897 sc->bce_rx_quick_cons_trip = 1;
898 sc->bce_rx_ticks_int = 0;
899 sc->bce_rx_ticks = 0;
901 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
902 sc->bce_tx_quick_cons_trip = bce_tx_bds;
903 sc->bce_tx_ticks_int = bce_tx_ticks_int;
904 sc->bce_tx_ticks = bce_tx_ticks;
906 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
907 sc->bce_rx_quick_cons_trip = bce_rx_bds;
908 sc->bce_rx_ticks_int = bce_rx_ticks_int;
909 sc->bce_rx_ticks = bce_rx_ticks;
912 /* Update statistics once every second. */
913 sc->bce_stats_ticks = 1000000 & 0xffff00;
915 /* Find the media type for the adapter. */
918 /* Allocate DMA memory resources. */
919 rc = bce_dma_alloc(sc);
921 device_printf(dev, "DMA resource allocation failed!\n");
925 /* Initialize the ifnet interface. */
927 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
928 ifp->if_ioctl = bce_ioctl;
929 ifp->if_start = bce_start;
930 ifp->if_init = bce_init;
931 ifp->if_watchdog = bce_watchdog;
932 #ifdef DEVICE_POLLING
933 ifp->if_poll = bce_poll;
935 ifp->if_mtu = ETHERMTU;
936 ifp->if_hwassist = BCE_IF_HWASSIST;
937 ifp->if_capabilities = BCE_IF_CAPABILITIES;
938 ifp->if_capenable = ifp->if_capabilities;
939 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
940 ifq_set_ready(&ifp->if_snd);
942 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
943 ifp->if_baudrate = IF_Gbps(2.5);
945 ifp->if_baudrate = IF_Gbps(1);
947 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
948 sc->mbuf_alloc_size = MCLBYTES;
950 /* Look for our PHY. */
951 rc = mii_phy_probe(dev, &sc->bce_miibus,
952 bce_ifmedia_upd, bce_ifmedia_sts);
954 device_printf(dev, "PHY probe failed!\n");
958 /* Attach to the Ethernet interface list. */
959 ether_ifattach(ifp, sc->eaddr, NULL);
961 callout_init_mp(&sc->bce_tick_callout);
962 callout_init_mp(&sc->bce_pulse_callout);
964 /* Hookup IRQ last. */
965 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, irq_handle, sc,
966 &sc->bce_intrhand, ifp->if_serializer);
968 device_printf(dev, "Failed to setup IRQ!\n");
973 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
974 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
976 /* Print some important debugging info. */
977 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
979 /* Add the supported sysctls to the kernel. */
983 * The chip reset earlier notified the bootcode that
984 * a driver is present. We now need to start our pulse
985 * routine so that the bootcode is reminded that we're
990 /* Get the firmware running so IPMI still works */
994 bce_print_adapter_info(sc);
1003 /****************************************************************************/
1004 /* Device detach function. */
1006 /* Stops the controller, resets the controller, and releases resources. */
1009 /* 0 on success, positive value on failure. */
1010 /****************************************************************************/
1012 bce_detach(device_t dev)
1014 struct bce_softc *sc = device_get_softc(dev);
1016 if (device_is_attached(dev)) {
1017 struct ifnet *ifp = &sc->arpcom.ac_if;
1020 /* Stop and reset the controller. */
1021 lwkt_serialize_enter(ifp->if_serializer);
1022 callout_stop(&sc->bce_pulse_callout);
1024 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1025 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1027 msg = BCE_DRV_MSG_CODE_UNLOAD;
1029 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1030 lwkt_serialize_exit(ifp->if_serializer);
1032 ether_ifdetach(ifp);
1035 /* If we have a child device on the MII bus remove it too. */
1037 device_delete_child(dev, sc->bce_miibus);
1038 bus_generic_detach(dev);
1040 if (sc->bce_res_irq != NULL) {
1041 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
1045 if (sc->bce_irq_type == PCI_INTR_TYPE_MSI)
1046 pci_release_msi(dev);
1048 if (sc->bce_res_mem != NULL) {
1049 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1055 if (sc->bce_sysctl_tree != NULL)
1056 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1062 /****************************************************************************/
1063 /* Device shutdown function. */
1065 /* Stops and resets the controller. */
1069 /****************************************************************************/
1071 bce_shutdown(device_t dev)
1073 struct bce_softc *sc = device_get_softc(dev);
1074 struct ifnet *ifp = &sc->arpcom.ac_if;
1077 lwkt_serialize_enter(ifp->if_serializer);
1079 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1080 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1082 msg = BCE_DRV_MSG_CODE_UNLOAD;
1084 lwkt_serialize_exit(ifp->if_serializer);
1088 /****************************************************************************/
1089 /* Indirect register read. */
1091 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1092 /* configuration space. Using this mechanism avoids issues with posted */
1093 /* reads but is much slower than memory-mapped I/O. */
1096 /* The value of the register. */
1097 /****************************************************************************/
1099 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1101 device_t dev = sc->bce_dev;
1103 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1107 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1108 DBPRINT(sc, BCE_EXCESSIVE,
1109 "%s(); offset = 0x%08X, val = 0x%08X\n",
1110 __func__, offset, val);
1114 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1119 /****************************************************************************/
1120 /* Indirect register write. */
1122 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1123 /* configuration space. Using this mechanism avoids issues with posted */
1124 /* writes but is muchh slower than memory-mapped I/O. */
1128 /****************************************************************************/
1130 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1132 device_t dev = sc->bce_dev;
1134 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1135 __func__, offset, val);
1137 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1138 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1142 /****************************************************************************/
1143 /* Shared memory write. */
1145 /* Writes NetXtreme II shared memory region. */
1149 /****************************************************************************/
1151 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1153 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1157 /****************************************************************************/
1158 /* Shared memory read. */
1160 /* Reads NetXtreme II shared memory region. */
1163 /* The 32 bit value read. */
1164 /****************************************************************************/
1166 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1168 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1172 /****************************************************************************/
1173 /* Context memory write. */
1175 /* The NetXtreme II controller uses context memory to track connection */
1176 /* information for L2 and higher network protocols. */
1180 /****************************************************************************/
1182 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1185 uint32_t idx, offset = ctx_offset + cid_addr;
1186 uint32_t val, retry_cnt = 5;
1188 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1189 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1190 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1191 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1193 for (idx = 0; idx < retry_cnt; idx++) {
1194 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1195 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1200 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1201 device_printf(sc->bce_dev,
1202 "Unable to write CTX memory: "
1203 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1204 cid_addr, ctx_offset);
1207 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1208 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1213 /****************************************************************************/
1214 /* PHY register read. */
1216 /* Implements register reads on the MII bus. */
1219 /* The value of the register. */
1220 /****************************************************************************/
1222 bce_miibus_read_reg(device_t dev, int phy, int reg)
1224 struct bce_softc *sc = device_get_softc(dev);
1228 /* Make sure we are accessing the correct PHY address. */
1229 if (phy != sc->bce_phy_addr) {
1230 DBPRINT(sc, BCE_VERBOSE,
1231 "Invalid PHY address %d for PHY read!\n", phy);
1235 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1236 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1237 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1239 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1240 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1245 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1246 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1247 BCE_EMAC_MDIO_COMM_START_BUSY;
1248 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1250 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1253 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1254 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1257 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1258 val &= BCE_EMAC_MDIO_COMM_DATA;
1263 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1264 if_printf(&sc->arpcom.ac_if,
1265 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1269 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1272 DBPRINT(sc, BCE_EXCESSIVE,
1273 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1274 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1276 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1277 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1278 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1280 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1281 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1285 return (val & 0xffff);
1289 /****************************************************************************/
1290 /* PHY register write. */
1292 /* Implements register writes on the MII bus. */
1295 /* The value of the register. */
1296 /****************************************************************************/
1298 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1300 struct bce_softc *sc = device_get_softc(dev);
1304 /* Make sure we are accessing the correct PHY address. */
1305 if (phy != sc->bce_phy_addr) {
1306 DBPRINT(sc, BCE_WARN,
1307 "Invalid PHY address %d for PHY write!\n", phy);
1311 DBPRINT(sc, BCE_EXCESSIVE,
1312 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1313 __func__, phy, (uint16_t)(reg & 0xffff),
1314 (uint16_t)(val & 0xffff));
1316 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1317 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1318 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1320 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1321 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1326 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1327 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1328 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1329 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1331 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1334 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1335 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1341 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1342 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1344 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1345 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1346 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1348 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1349 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1357 /****************************************************************************/
1358 /* MII bus status change. */
1360 /* Called by the MII bus driver when the PHY establishes link to set the */
1361 /* MAC interface registers. */
1365 /****************************************************************************/
1367 bce_miibus_statchg(device_t dev)
1369 struct bce_softc *sc = device_get_softc(dev);
1370 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1372 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1373 mii->mii_media_active);
1376 /* Decode the interface media flags. */
1377 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1378 switch(IFM_TYPE(mii->mii_media_active)) {
1380 kprintf("Ethernet )");
1383 kprintf("Unknown )");
1387 kprintf(" Media Options: ( ");
1388 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1390 kprintf("Autoselect )");
1393 kprintf("Manual )");
1399 kprintf("10Base-T )");
1402 kprintf("100Base-TX )");
1405 kprintf("1000Base-SX )");
1408 kprintf("1000Base-T )");
1415 kprintf(" Global Options: (");
1416 if (mii->mii_media_active & IFM_FDX)
1417 kprintf(" FullDuplex");
1418 if (mii->mii_media_active & IFM_HDX)
1419 kprintf(" HalfDuplex");
1420 if (mii->mii_media_active & IFM_LOOP)
1421 kprintf(" Loopback");
1422 if (mii->mii_media_active & IFM_FLAG0)
1424 if (mii->mii_media_active & IFM_FLAG1)
1426 if (mii->mii_media_active & IFM_FLAG2)
1431 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1434 * Set MII or GMII interface based on the speed negotiated
1437 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1438 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1439 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1440 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1442 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1443 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1447 * Set half or full duplex based on the duplicity negotiated
1450 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1451 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1452 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1454 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1455 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1460 /****************************************************************************/
1461 /* Acquire NVRAM lock. */
1463 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1464 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1465 /* for use by the driver. */
1468 /* 0 on success, positive value on failure. */
1469 /****************************************************************************/
1471 bce_acquire_nvram_lock(struct bce_softc *sc)
1476 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1478 /* Request access to the flash interface. */
1479 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1480 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1481 val = REG_RD(sc, BCE_NVM_SW_ARB);
1482 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1488 if (j >= NVRAM_TIMEOUT_COUNT) {
1489 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1496 /****************************************************************************/
1497 /* Release NVRAM lock. */
1499 /* When the caller is finished accessing NVRAM the lock must be released. */
1500 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1501 /* for use by the driver. */
1504 /* 0 on success, positive value on failure. */
1505 /****************************************************************************/
1507 bce_release_nvram_lock(struct bce_softc *sc)
1512 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1515 * Relinquish nvram interface.
1517 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1519 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1520 val = REG_RD(sc, BCE_NVM_SW_ARB);
1521 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1527 if (j >= NVRAM_TIMEOUT_COUNT) {
1528 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1535 /****************************************************************************/
1536 /* Enable NVRAM access. */
1538 /* Before accessing NVRAM for read or write operations the caller must */
1539 /* enabled NVRAM access. */
1543 /****************************************************************************/
1545 bce_enable_nvram_access(struct bce_softc *sc)
1549 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1551 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1552 /* Enable both bits, even on read. */
1553 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1554 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1558 /****************************************************************************/
1559 /* Disable NVRAM access. */
1561 /* When the caller is finished accessing NVRAM access must be disabled. */
1565 /****************************************************************************/
1567 bce_disable_nvram_access(struct bce_softc *sc)
1571 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1573 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1575 /* Disable both bits, even after read. */
1576 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1577 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1581 /****************************************************************************/
1582 /* Read a dword (32 bits) from NVRAM. */
1584 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1585 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1588 /* 0 on success and the 32 bit value read, positive value on failure. */
1589 /****************************************************************************/
1591 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1597 /* Build the command word. */
1598 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1600 /* Calculate the offset for buffered flash. */
1601 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1602 offset = ((offset / sc->bce_flash_info->page_size) <<
1603 sc->bce_flash_info->page_bits) +
1604 (offset % sc->bce_flash_info->page_size);
1608 * Clear the DONE bit separately, set the address to read,
1609 * and issue the read.
1611 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1612 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1613 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1615 /* Wait for completion. */
1616 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1621 val = REG_RD(sc, BCE_NVM_COMMAND);
1622 if (val & BCE_NVM_COMMAND_DONE) {
1623 val = REG_RD(sc, BCE_NVM_READ);
1626 memcpy(ret_val, &val, 4);
1631 /* Check for errors. */
1632 if (i >= NVRAM_TIMEOUT_COUNT) {
1633 if_printf(&sc->arpcom.ac_if,
1634 "Timeout error reading NVRAM at offset 0x%08X!\n",
1642 /****************************************************************************/
1643 /* Initialize NVRAM access. */
1645 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1646 /* access that device. */
1649 /* 0 on success, positive value on failure. */
1650 /****************************************************************************/
1652 bce_init_nvram(struct bce_softc *sc)
1655 int j, entry_count, rc = 0;
1656 const struct flash_spec *flash;
1658 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1660 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1661 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1662 sc->bce_flash_info = &flash_5709;
1663 goto bce_init_nvram_get_flash_size;
1666 /* Determine the selected interface. */
1667 val = REG_RD(sc, BCE_NVM_CFG1);
1669 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1672 * Flash reconfiguration is required to support additional
1673 * NVRAM devices not directly supported in hardware.
1674 * Check if the flash interface was reconfigured
1678 if (val & 0x40000000) {
1679 /* Flash interface reconfigured by bootcode. */
1681 DBPRINT(sc, BCE_INFO_LOAD,
1682 "%s(): Flash WAS reconfigured.\n", __func__);
1684 for (j = 0, flash = flash_table; j < entry_count;
1686 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1687 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1688 sc->bce_flash_info = flash;
1693 /* Flash interface not yet reconfigured. */
1696 DBPRINT(sc, BCE_INFO_LOAD,
1697 "%s(): Flash was NOT reconfigured.\n", __func__);
1699 if (val & (1 << 23))
1700 mask = FLASH_BACKUP_STRAP_MASK;
1702 mask = FLASH_STRAP_MASK;
1704 /* Look for the matching NVRAM device configuration data. */
1705 for (j = 0, flash = flash_table; j < entry_count;
1707 /* Check if the device matches any of the known devices. */
1708 if ((val & mask) == (flash->strapping & mask)) {
1709 /* Found a device match. */
1710 sc->bce_flash_info = flash;
1712 /* Request access to the flash interface. */
1713 rc = bce_acquire_nvram_lock(sc);
1717 /* Reconfigure the flash interface. */
1718 bce_enable_nvram_access(sc);
1719 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1720 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1721 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1722 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1723 bce_disable_nvram_access(sc);
1724 bce_release_nvram_lock(sc);
1730 /* Check if a matching device was found. */
1731 if (j == entry_count) {
1732 sc->bce_flash_info = NULL;
1733 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1737 bce_init_nvram_get_flash_size:
1738 /* Write the flash config data to the shared memory interface. */
1739 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1740 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1742 sc->bce_flash_size = val;
1744 sc->bce_flash_size = sc->bce_flash_info->total_size;
1746 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1747 __func__, sc->bce_flash_info->total_size);
1749 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1755 /****************************************************************************/
1756 /* Read an arbitrary range of data from NVRAM. */
1758 /* Prepares the NVRAM interface for access and reads the requested data */
1759 /* into the supplied buffer. */
1762 /* 0 on success and the data read, positive value on failure. */
1763 /****************************************************************************/
1765 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1768 uint32_t cmd_flags, offset32, len32, extra;
1774 /* Request access to the flash interface. */
1775 rc = bce_acquire_nvram_lock(sc);
1779 /* Enable access to flash interface */
1780 bce_enable_nvram_access(sc);
1788 /* XXX should we release nvram lock if read_dword() fails? */
1794 pre_len = 4 - (offset & 3);
1796 if (pre_len >= len32) {
1798 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1800 cmd_flags = BCE_NVM_COMMAND_FIRST;
1803 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1807 memcpy(ret_buf, buf + (offset & 3), pre_len);
1815 extra = 4 - (len32 & 3);
1816 len32 = (len32 + 4) & ~3;
1823 cmd_flags = BCE_NVM_COMMAND_LAST;
1825 cmd_flags = BCE_NVM_COMMAND_FIRST |
1826 BCE_NVM_COMMAND_LAST;
1828 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1830 memcpy(ret_buf, buf, 4 - extra);
1831 } else if (len32 > 0) {
1834 /* Read the first word. */
1838 cmd_flags = BCE_NVM_COMMAND_FIRST;
1840 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1842 /* Advance to the next dword. */
1847 while (len32 > 4 && rc == 0) {
1848 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1850 /* Advance to the next dword. */
1857 goto bce_nvram_read_locked_exit;
1859 cmd_flags = BCE_NVM_COMMAND_LAST;
1860 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1862 memcpy(ret_buf, buf, 4 - extra);
1865 bce_nvram_read_locked_exit:
1866 /* Disable access to flash interface and release the lock. */
1867 bce_disable_nvram_access(sc);
1868 bce_release_nvram_lock(sc);
1874 /****************************************************************************/
1875 /* Verifies that NVRAM is accessible and contains valid data. */
1877 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1881 /* 0 on success, positive value on failure. */
1882 /****************************************************************************/
1884 bce_nvram_test(struct bce_softc *sc)
1886 uint32_t buf[BCE_NVRAM_SIZE / 4];
1887 uint32_t magic, csum;
1888 uint8_t *data = (uint8_t *)buf;
1892 * Check that the device NVRAM is valid by reading
1893 * the magic value at offset 0.
1895 rc = bce_nvram_read(sc, 0, data, 4);
1899 magic = be32toh(buf[0]);
1900 if (magic != BCE_NVRAM_MAGIC) {
1901 if_printf(&sc->arpcom.ac_if,
1902 "Invalid NVRAM magic value! Expected: 0x%08X, "
1903 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1908 * Verify that the device NVRAM includes valid
1909 * configuration data.
1911 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1915 csum = ether_crc32_le(data, 0x100);
1916 if (csum != BCE_CRC32_RESIDUAL) {
1917 if_printf(&sc->arpcom.ac_if,
1918 "Invalid Manufacturing Information NVRAM CRC! "
1919 "Expected: 0x%08X, Found: 0x%08X\n",
1920 BCE_CRC32_RESIDUAL, csum);
1924 csum = ether_crc32_le(data + 0x100, 0x100);
1925 if (csum != BCE_CRC32_RESIDUAL) {
1926 if_printf(&sc->arpcom.ac_if,
1927 "Invalid Feature Configuration Information "
1928 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1929 BCE_CRC32_RESIDUAL, csum);
1936 /****************************************************************************/
1937 /* Identifies the current media type of the controller and sets the PHY */
1942 /****************************************************************************/
1944 bce_get_media(struct bce_softc *sc)
1948 sc->bce_phy_addr = 1;
1950 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1951 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1952 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1953 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1957 * The BCM5709S is software configurable
1958 * for Copper or SerDes operation.
1960 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1962 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1963 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1967 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1968 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
1971 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
1974 if (pci_get_function(sc->bce_dev) == 0) {
1979 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1987 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1991 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
1992 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1995 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
1996 sc->bce_flags |= BCE_NO_WOL_FLAG;
1997 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
1998 sc->bce_phy_addr = 2;
1999 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
2000 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
2001 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
2003 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
2004 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
2005 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
2010 /****************************************************************************/
2011 /* Free any DMA memory owned by the driver. */
2013 /* Scans through each data structre that requires DMA memory and frees */
2014 /* the memory if allocated. */
2018 /****************************************************************************/
2020 bce_dma_free(struct bce_softc *sc)
2024 /* Destroy the status block. */
2025 if (sc->status_tag != NULL) {
2026 if (sc->status_block != NULL) {
2027 bus_dmamap_unload(sc->status_tag, sc->status_map);
2028 bus_dmamem_free(sc->status_tag, sc->status_block,
2031 bus_dma_tag_destroy(sc->status_tag);
2035 /* Destroy the statistics block. */
2036 if (sc->stats_tag != NULL) {
2037 if (sc->stats_block != NULL) {
2038 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2039 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2042 bus_dma_tag_destroy(sc->stats_tag);
2045 /* Destroy the CTX DMA stuffs. */
2046 if (sc->ctx_tag != NULL) {
2047 for (i = 0; i < sc->ctx_pages; i++) {
2048 if (sc->ctx_block[i] != NULL) {
2049 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2050 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2054 bus_dma_tag_destroy(sc->ctx_tag);
2057 /* Destroy the TX buffer descriptor DMA stuffs. */
2058 if (sc->tx_bd_chain_tag != NULL) {
2059 for (i = 0; i < TX_PAGES; i++) {
2060 if (sc->tx_bd_chain[i] != NULL) {
2061 bus_dmamap_unload(sc->tx_bd_chain_tag,
2062 sc->tx_bd_chain_map[i]);
2063 bus_dmamem_free(sc->tx_bd_chain_tag,
2065 sc->tx_bd_chain_map[i]);
2068 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2071 /* Destroy the RX buffer descriptor DMA stuffs. */
2072 if (sc->rx_bd_chain_tag != NULL) {
2073 for (i = 0; i < RX_PAGES; i++) {
2074 if (sc->rx_bd_chain[i] != NULL) {
2075 bus_dmamap_unload(sc->rx_bd_chain_tag,
2076 sc->rx_bd_chain_map[i]);
2077 bus_dmamem_free(sc->rx_bd_chain_tag,
2079 sc->rx_bd_chain_map[i]);
2082 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2085 /* Destroy the TX mbuf DMA stuffs. */
2086 if (sc->tx_mbuf_tag != NULL) {
2087 for (i = 0; i < TOTAL_TX_BD; i++) {
2088 /* Must have been unloaded in bce_stop() */
2089 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2090 bus_dmamap_destroy(sc->tx_mbuf_tag,
2091 sc->tx_mbuf_map[i]);
2093 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2096 /* Destroy the RX mbuf DMA stuffs. */
2097 if (sc->rx_mbuf_tag != NULL) {
2098 for (i = 0; i < TOTAL_RX_BD; i++) {
2099 /* Must have been unloaded in bce_stop() */
2100 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2101 bus_dmamap_destroy(sc->rx_mbuf_tag,
2102 sc->rx_mbuf_map[i]);
2104 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2105 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2108 /* Destroy the parent tag */
2109 if (sc->parent_tag != NULL)
2110 bus_dma_tag_destroy(sc->parent_tag);
2114 /****************************************************************************/
2115 /* Get DMA memory from the OS. */
2117 /* Validates that the OS has provided DMA buffers in response to a */
2118 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2119 /* When the callback is used the OS will return 0 for the mapping function */
2120 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2121 /* failures back to the caller. */
2125 /****************************************************************************/
2127 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2129 bus_addr_t *busaddr = arg;
2132 * Simulate a mapping failure.
2135 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2136 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2137 __FILE__, __LINE__);
2140 /* Check for an error and signal the caller that an error occurred. */
2144 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2145 *busaddr = segs->ds_addr;
2149 /****************************************************************************/
2150 /* Allocate any DMA memory needed by the driver. */
2152 /* Allocates DMA memory needed for the various global structures needed by */
2155 /* Memory alignment requirements: */
2156 /* -----------------+----------+----------+----------+----------+ */
2157 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2158 /* -----------------+----------+----------+----------+----------+ */
2159 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2160 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2161 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2162 /* PG Buffers | none | none | none | none | */
2163 /* TX Buffers | none | none | none | none | */
2164 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2165 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2166 /* -----------------+----------+----------+----------+----------+ */
2168 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2171 /* 0 for success, positive value for failure. */
2172 /****************************************************************************/
2174 bce_dma_alloc(struct bce_softc *sc)
2176 struct ifnet *ifp = &sc->arpcom.ac_if;
2178 bus_addr_t busaddr, max_busaddr;
2179 bus_size_t status_align, stats_align;
2182 * The embedded PCIe to PCI-X bridge (EPB)
2183 * in the 5708 cannot address memory above
2184 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2186 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2187 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2189 max_busaddr = BUS_SPACE_MAXADDR;
2192 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2194 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2195 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2196 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2197 if (sc->ctx_pages == 0)
2199 if (sc->ctx_pages > BCE_CTX_PAGES) {
2200 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2212 * Allocate the parent bus DMA tag appropriate for PCI.
2214 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2215 max_busaddr, BUS_SPACE_MAXADDR,
2217 BUS_SPACE_MAXSIZE_32BIT, 0,
2218 BUS_SPACE_MAXSIZE_32BIT,
2219 0, &sc->parent_tag);
2221 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2226 * Allocate status block.
2228 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2229 status_align, BCE_STATUS_BLK_SZ,
2230 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2231 &sc->status_tag, &sc->status_map,
2232 &sc->status_block_paddr);
2233 if (sc->status_block == NULL) {
2234 if_printf(ifp, "Could not allocate status block!\n");
2239 * Allocate statistics block.
2241 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2242 stats_align, BCE_STATS_BLK_SZ,
2243 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2244 &sc->stats_tag, &sc->stats_map,
2245 &sc->stats_block_paddr);
2246 if (sc->stats_block == NULL) {
2247 if_printf(ifp, "Could not allocate statistics block!\n");
2252 * Allocate context block, if needed
2254 if (sc->ctx_pages != 0) {
2255 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2256 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2258 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2261 if_printf(ifp, "Could not allocate "
2262 "context block DMA tag!\n");
2266 for (i = 0; i < sc->ctx_pages; i++) {
2267 rc = bus_dmamem_alloc(sc->ctx_tag,
2268 (void **)&sc->ctx_block[i],
2269 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2273 if_printf(ifp, "Could not allocate %dth context "
2274 "DMA memory!\n", i);
2278 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2279 sc->ctx_block[i], BCM_PAGE_SIZE,
2280 bce_dma_map_addr, &busaddr,
2283 if (rc == EINPROGRESS) {
2284 panic("%s coherent memory loading "
2285 "is still in progress!", ifp->if_xname);
2287 if_printf(ifp, "Could not map %dth context "
2288 "DMA memory!\n", i);
2289 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2291 sc->ctx_block[i] = NULL;
2294 sc->ctx_paddr[i] = busaddr;
2299 * Create a DMA tag for the TX buffer descriptor chain,
2300 * allocate and clear the memory, and fetch the
2301 * physical address of the block.
2303 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2304 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2306 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2307 0, &sc->tx_bd_chain_tag);
2309 if_printf(ifp, "Could not allocate "
2310 "TX descriptor chain DMA tag!\n");
2314 for (i = 0; i < TX_PAGES; i++) {
2315 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2316 (void **)&sc->tx_bd_chain[i],
2317 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2319 &sc->tx_bd_chain_map[i]);
2321 if_printf(ifp, "Could not allocate %dth TX descriptor "
2322 "chain DMA memory!\n", i);
2326 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2327 sc->tx_bd_chain_map[i],
2328 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2329 bce_dma_map_addr, &busaddr,
2332 if (rc == EINPROGRESS) {
2333 panic("%s coherent memory loading "
2334 "is still in progress!", ifp->if_xname);
2336 if_printf(ifp, "Could not map %dth TX descriptor "
2337 "chain DMA memory!\n", i);
2338 bus_dmamem_free(sc->tx_bd_chain_tag,
2340 sc->tx_bd_chain_map[i]);
2341 sc->tx_bd_chain[i] = NULL;
2345 sc->tx_bd_chain_paddr[i] = busaddr;
2346 /* DRC - Fix for 64 bit systems. */
2347 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2348 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2351 /* Create a DMA tag for TX mbufs. */
2352 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2353 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2355 /* BCE_MAX_JUMBO_ETHER_MTU_VLAN */MCLBYTES,
2356 BCE_MAX_SEGMENTS, MCLBYTES,
2357 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2361 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2365 /* Create DMA maps for the TX mbufs clusters. */
2366 for (i = 0; i < TOTAL_TX_BD; i++) {
2367 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2368 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2369 &sc->tx_mbuf_map[i]);
2371 for (j = 0; j < i; ++j) {
2372 bus_dmamap_destroy(sc->tx_mbuf_tag,
2373 sc->tx_mbuf_map[i]);
2375 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2376 sc->tx_mbuf_tag = NULL;
2378 if_printf(ifp, "Unable to create "
2379 "%dth TX mbuf DMA map!\n", i);
2385 * Create a DMA tag for the RX buffer descriptor chain,
2386 * allocate and clear the memory, and fetch the physical
2387 * address of the blocks.
2389 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2390 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2392 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2393 0, &sc->rx_bd_chain_tag);
2395 if_printf(ifp, "Could not allocate "
2396 "RX descriptor chain DMA tag!\n");
2400 for (i = 0; i < RX_PAGES; i++) {
2401 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2402 (void **)&sc->rx_bd_chain[i],
2403 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2405 &sc->rx_bd_chain_map[i]);
2407 if_printf(ifp, "Could not allocate %dth RX descriptor "
2408 "chain DMA memory!\n", i);
2412 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2413 sc->rx_bd_chain_map[i],
2414 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2415 bce_dma_map_addr, &busaddr,
2418 if (rc == EINPROGRESS) {
2419 panic("%s coherent memory loading "
2420 "is still in progress!", ifp->if_xname);
2422 if_printf(ifp, "Could not map %dth RX descriptor "
2423 "chain DMA memory!\n", i);
2424 bus_dmamem_free(sc->rx_bd_chain_tag,
2426 sc->rx_bd_chain_map[i]);
2427 sc->rx_bd_chain[i] = NULL;
2431 sc->rx_bd_chain_paddr[i] = busaddr;
2432 /* DRC - Fix for 64 bit systems. */
2433 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2434 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2437 /* Create a DMA tag for RX mbufs. */
2438 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2439 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2441 MCLBYTES, 1, MCLBYTES,
2442 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2446 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2450 /* Create tmp DMA map for RX mbuf clusters. */
2451 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2452 &sc->rx_mbuf_tmpmap);
2454 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2455 sc->rx_mbuf_tag = NULL;
2457 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2461 /* Create DMA maps for the RX mbuf clusters. */
2462 for (i = 0; i < TOTAL_RX_BD; i++) {
2463 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2464 &sc->rx_mbuf_map[i]);
2466 for (j = 0; j < i; ++j) {
2467 bus_dmamap_destroy(sc->rx_mbuf_tag,
2468 sc->rx_mbuf_map[j]);
2470 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2471 sc->rx_mbuf_tag = NULL;
2473 if_printf(ifp, "Unable to create "
2474 "%dth RX mbuf DMA map!\n", i);
2482 /****************************************************************************/
2483 /* Firmware synchronization. */
2485 /* Before performing certain events such as a chip reset, synchronize with */
2486 /* the firmware first. */
2489 /* 0 for success, positive value for failure. */
2490 /****************************************************************************/
2492 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2497 /* Don't waste any time if we've timed out before. */
2498 if (sc->bce_fw_timed_out)
2501 /* Increment the message sequence number. */
2502 sc->bce_fw_wr_seq++;
2503 msg_data |= sc->bce_fw_wr_seq;
2505 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2507 /* Send the message to the bootcode driver mailbox. */
2508 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2510 /* Wait for the bootcode to acknowledge the message. */
2511 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2512 /* Check for a response in the bootcode firmware mailbox. */
2513 val = bce_shmem_rd(sc, BCE_FW_MB);
2514 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2519 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2520 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2521 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2522 if_printf(&sc->arpcom.ac_if,
2523 "Firmware synchronization timeout! "
2524 "msg_data = 0x%08X\n", msg_data);
2526 msg_data &= ~BCE_DRV_MSG_CODE;
2527 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2529 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2531 sc->bce_fw_timed_out = 1;
2538 /****************************************************************************/
2539 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2543 /****************************************************************************/
2545 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2546 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2551 for (i = 0; i < rv2p_code_len; i += 8) {
2552 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2554 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2557 if (rv2p_proc == RV2P_PROC1) {
2558 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2559 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2561 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2562 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2566 /* Reset the processor, un-stall is done later. */
2567 if (rv2p_proc == RV2P_PROC1)
2568 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2570 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2574 /****************************************************************************/
2575 /* Load RISC processor firmware. */
2577 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2578 /* associated with a particular processor. */
2582 /****************************************************************************/
2584 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2590 bce_halt_cpu(sc, cpu_reg);
2592 /* Load the Text area. */
2593 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2595 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2596 REG_WR_IND(sc, offset, fw->text[j]);
2599 /* Load the Data area. */
2600 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2602 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2603 REG_WR_IND(sc, offset, fw->data[j]);
2606 /* Load the SBSS area. */
2607 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2609 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2610 REG_WR_IND(sc, offset, fw->sbss[j]);
2613 /* Load the BSS area. */
2614 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2616 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2617 REG_WR_IND(sc, offset, fw->bss[j]);
2620 /* Load the Read-Only area. */
2621 offset = cpu_reg->spad_base +
2622 (fw->rodata_addr - cpu_reg->mips_view_base);
2624 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2625 REG_WR_IND(sc, offset, fw->rodata[j]);
2628 /* Clear the pre-fetch instruction and set the FW start address. */
2629 REG_WR_IND(sc, cpu_reg->inst, 0);
2630 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2634 /****************************************************************************/
2635 /* Starts the RISC processor. */
2637 /* Assumes the CPU starting address has already been set. */
2641 /****************************************************************************/
2643 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2647 /* Start the CPU. */
2648 val = REG_RD_IND(sc, cpu_reg->mode);
2649 val &= ~cpu_reg->mode_value_halt;
2650 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2651 REG_WR_IND(sc, cpu_reg->mode, val);
2655 /****************************************************************************/
2656 /* Halts the RISC processor. */
2660 /****************************************************************************/
2662 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2667 val = REG_RD_IND(sc, cpu_reg->mode);
2668 val |= cpu_reg->mode_value_halt;
2669 REG_WR_IND(sc, cpu_reg->mode, val);
2670 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2674 /****************************************************************************/
2675 /* Start the RX CPU. */
2679 /****************************************************************************/
2681 bce_start_rxp_cpu(struct bce_softc *sc)
2683 struct cpu_reg cpu_reg;
2685 cpu_reg.mode = BCE_RXP_CPU_MODE;
2686 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2687 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2688 cpu_reg.state = BCE_RXP_CPU_STATE;
2689 cpu_reg.state_value_clear = 0xffffff;
2690 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2691 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2692 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2693 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2694 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2695 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2696 cpu_reg.mips_view_base = 0x8000000;
2698 bce_start_cpu(sc, &cpu_reg);
2702 /****************************************************************************/
2703 /* Initialize the RX CPU. */
2707 /****************************************************************************/
2709 bce_init_rxp_cpu(struct bce_softc *sc)
2711 struct cpu_reg cpu_reg;
2714 cpu_reg.mode = BCE_RXP_CPU_MODE;
2715 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2716 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2717 cpu_reg.state = BCE_RXP_CPU_STATE;
2718 cpu_reg.state_value_clear = 0xffffff;
2719 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2720 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2721 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2722 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2723 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2724 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2725 cpu_reg.mips_view_base = 0x8000000;
2727 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2728 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2729 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2730 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2731 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2732 fw.start_addr = bce_RXP_b09FwStartAddr;
2734 fw.text_addr = bce_RXP_b09FwTextAddr;
2735 fw.text_len = bce_RXP_b09FwTextLen;
2737 fw.text = bce_RXP_b09FwText;
2739 fw.data_addr = bce_RXP_b09FwDataAddr;
2740 fw.data_len = bce_RXP_b09FwDataLen;
2742 fw.data = bce_RXP_b09FwData;
2744 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2745 fw.sbss_len = bce_RXP_b09FwSbssLen;
2747 fw.sbss = bce_RXP_b09FwSbss;
2749 fw.bss_addr = bce_RXP_b09FwBssAddr;
2750 fw.bss_len = bce_RXP_b09FwBssLen;
2752 fw.bss = bce_RXP_b09FwBss;
2754 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2755 fw.rodata_len = bce_RXP_b09FwRodataLen;
2756 fw.rodata_index = 0;
2757 fw.rodata = bce_RXP_b09FwRodata;
2759 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2760 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2761 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2762 fw.start_addr = bce_RXP_b06FwStartAddr;
2764 fw.text_addr = bce_RXP_b06FwTextAddr;
2765 fw.text_len = bce_RXP_b06FwTextLen;
2767 fw.text = bce_RXP_b06FwText;
2769 fw.data_addr = bce_RXP_b06FwDataAddr;
2770 fw.data_len = bce_RXP_b06FwDataLen;
2772 fw.data = bce_RXP_b06FwData;
2774 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2775 fw.sbss_len = bce_RXP_b06FwSbssLen;
2777 fw.sbss = bce_RXP_b06FwSbss;
2779 fw.bss_addr = bce_RXP_b06FwBssAddr;
2780 fw.bss_len = bce_RXP_b06FwBssLen;
2782 fw.bss = bce_RXP_b06FwBss;
2784 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2785 fw.rodata_len = bce_RXP_b06FwRodataLen;
2786 fw.rodata_index = 0;
2787 fw.rodata = bce_RXP_b06FwRodata;
2790 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2791 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2792 /* Delay RXP start until initialization is complete. */
2796 /****************************************************************************/
2797 /* Initialize the TX CPU. */
2801 /****************************************************************************/
2803 bce_init_txp_cpu(struct bce_softc *sc)
2805 struct cpu_reg cpu_reg;
2808 cpu_reg.mode = BCE_TXP_CPU_MODE;
2809 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2810 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2811 cpu_reg.state = BCE_TXP_CPU_STATE;
2812 cpu_reg.state_value_clear = 0xffffff;
2813 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2814 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2815 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2816 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2817 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2818 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2819 cpu_reg.mips_view_base = 0x8000000;
2821 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2822 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2823 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2824 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2825 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2826 fw.start_addr = bce_TXP_b09FwStartAddr;
2828 fw.text_addr = bce_TXP_b09FwTextAddr;
2829 fw.text_len = bce_TXP_b09FwTextLen;
2831 fw.text = bce_TXP_b09FwText;
2833 fw.data_addr = bce_TXP_b09FwDataAddr;
2834 fw.data_len = bce_TXP_b09FwDataLen;
2836 fw.data = bce_TXP_b09FwData;
2838 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2839 fw.sbss_len = bce_TXP_b09FwSbssLen;
2841 fw.sbss = bce_TXP_b09FwSbss;
2843 fw.bss_addr = bce_TXP_b09FwBssAddr;
2844 fw.bss_len = bce_TXP_b09FwBssLen;
2846 fw.bss = bce_TXP_b09FwBss;
2848 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2849 fw.rodata_len = bce_TXP_b09FwRodataLen;
2850 fw.rodata_index = 0;
2851 fw.rodata = bce_TXP_b09FwRodata;
2853 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2854 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2855 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2856 fw.start_addr = bce_TXP_b06FwStartAddr;
2858 fw.text_addr = bce_TXP_b06FwTextAddr;
2859 fw.text_len = bce_TXP_b06FwTextLen;
2861 fw.text = bce_TXP_b06FwText;
2863 fw.data_addr = bce_TXP_b06FwDataAddr;
2864 fw.data_len = bce_TXP_b06FwDataLen;
2866 fw.data = bce_TXP_b06FwData;
2868 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2869 fw.sbss_len = bce_TXP_b06FwSbssLen;
2871 fw.sbss = bce_TXP_b06FwSbss;
2873 fw.bss_addr = bce_TXP_b06FwBssAddr;
2874 fw.bss_len = bce_TXP_b06FwBssLen;
2876 fw.bss = bce_TXP_b06FwBss;
2878 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2879 fw.rodata_len = bce_TXP_b06FwRodataLen;
2880 fw.rodata_index = 0;
2881 fw.rodata = bce_TXP_b06FwRodata;
2884 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2885 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2886 bce_start_cpu(sc, &cpu_reg);
2890 /****************************************************************************/
2891 /* Initialize the TPAT CPU. */
2895 /****************************************************************************/
2897 bce_init_tpat_cpu(struct bce_softc *sc)
2899 struct cpu_reg cpu_reg;
2902 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2903 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2904 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2905 cpu_reg.state = BCE_TPAT_CPU_STATE;
2906 cpu_reg.state_value_clear = 0xffffff;
2907 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2908 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2909 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2910 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2911 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2912 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2913 cpu_reg.mips_view_base = 0x8000000;
2915 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2916 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2917 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
2918 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
2919 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
2920 fw.start_addr = bce_TPAT_b09FwStartAddr;
2922 fw.text_addr = bce_TPAT_b09FwTextAddr;
2923 fw.text_len = bce_TPAT_b09FwTextLen;
2925 fw.text = bce_TPAT_b09FwText;
2927 fw.data_addr = bce_TPAT_b09FwDataAddr;
2928 fw.data_len = bce_TPAT_b09FwDataLen;
2930 fw.data = bce_TPAT_b09FwData;
2932 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
2933 fw.sbss_len = bce_TPAT_b09FwSbssLen;
2935 fw.sbss = bce_TPAT_b09FwSbss;
2937 fw.bss_addr = bce_TPAT_b09FwBssAddr;
2938 fw.bss_len = bce_TPAT_b09FwBssLen;
2940 fw.bss = bce_TPAT_b09FwBss;
2942 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
2943 fw.rodata_len = bce_TPAT_b09FwRodataLen;
2944 fw.rodata_index = 0;
2945 fw.rodata = bce_TPAT_b09FwRodata;
2947 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2948 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2949 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2950 fw.start_addr = bce_TPAT_b06FwStartAddr;
2952 fw.text_addr = bce_TPAT_b06FwTextAddr;
2953 fw.text_len = bce_TPAT_b06FwTextLen;
2955 fw.text = bce_TPAT_b06FwText;
2957 fw.data_addr = bce_TPAT_b06FwDataAddr;
2958 fw.data_len = bce_TPAT_b06FwDataLen;
2960 fw.data = bce_TPAT_b06FwData;
2962 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2963 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2965 fw.sbss = bce_TPAT_b06FwSbss;
2967 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2968 fw.bss_len = bce_TPAT_b06FwBssLen;
2970 fw.bss = bce_TPAT_b06FwBss;
2972 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2973 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2974 fw.rodata_index = 0;
2975 fw.rodata = bce_TPAT_b06FwRodata;
2978 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2979 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2980 bce_start_cpu(sc, &cpu_reg);
2984 /****************************************************************************/
2985 /* Initialize the CP CPU. */
2989 /****************************************************************************/
2991 bce_init_cp_cpu(struct bce_softc *sc)
2993 struct cpu_reg cpu_reg;
2996 cpu_reg.mode = BCE_CP_CPU_MODE;
2997 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
2998 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
2999 cpu_reg.state = BCE_CP_CPU_STATE;
3000 cpu_reg.state_value_clear = 0xffffff;
3001 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
3002 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
3003 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
3004 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
3005 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
3006 cpu_reg.spad_base = BCE_CP_SCRATCH;
3007 cpu_reg.mips_view_base = 0x8000000;
3009 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3010 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3011 fw.ver_major = bce_CP_b09FwReleaseMajor;
3012 fw.ver_minor = bce_CP_b09FwReleaseMinor;
3013 fw.ver_fix = bce_CP_b09FwReleaseFix;
3014 fw.start_addr = bce_CP_b09FwStartAddr;
3016 fw.text_addr = bce_CP_b09FwTextAddr;
3017 fw.text_len = bce_CP_b09FwTextLen;
3019 fw.text = bce_CP_b09FwText;
3021 fw.data_addr = bce_CP_b09FwDataAddr;
3022 fw.data_len = bce_CP_b09FwDataLen;
3024 fw.data = bce_CP_b09FwData;
3026 fw.sbss_addr = bce_CP_b09FwSbssAddr;
3027 fw.sbss_len = bce_CP_b09FwSbssLen;
3029 fw.sbss = bce_CP_b09FwSbss;
3031 fw.bss_addr = bce_CP_b09FwBssAddr;
3032 fw.bss_len = bce_CP_b09FwBssLen;
3034 fw.bss = bce_CP_b09FwBss;
3036 fw.rodata_addr = bce_CP_b09FwRodataAddr;
3037 fw.rodata_len = bce_CP_b09FwRodataLen;
3038 fw.rodata_index = 0;
3039 fw.rodata = bce_CP_b09FwRodata;
3041 fw.ver_major = bce_CP_b06FwReleaseMajor;
3042 fw.ver_minor = bce_CP_b06FwReleaseMinor;
3043 fw.ver_fix = bce_CP_b06FwReleaseFix;
3044 fw.start_addr = bce_CP_b06FwStartAddr;
3046 fw.text_addr = bce_CP_b06FwTextAddr;
3047 fw.text_len = bce_CP_b06FwTextLen;
3049 fw.text = bce_CP_b06FwText;
3051 fw.data_addr = bce_CP_b06FwDataAddr;
3052 fw.data_len = bce_CP_b06FwDataLen;
3054 fw.data = bce_CP_b06FwData;
3056 fw.sbss_addr = bce_CP_b06FwSbssAddr;
3057 fw.sbss_len = bce_CP_b06FwSbssLen;
3059 fw.sbss = bce_CP_b06FwSbss;
3061 fw.bss_addr = bce_CP_b06FwBssAddr;
3062 fw.bss_len = bce_CP_b06FwBssLen;
3064 fw.bss = bce_CP_b06FwBss;
3066 fw.rodata_addr = bce_CP_b06FwRodataAddr;
3067 fw.rodata_len = bce_CP_b06FwRodataLen;
3068 fw.rodata_index = 0;
3069 fw.rodata = bce_CP_b06FwRodata;
3072 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
3073 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3074 bce_start_cpu(sc, &cpu_reg);
3078 /****************************************************************************/
3079 /* Initialize the COM CPU. */
3083 /****************************************************************************/
3085 bce_init_com_cpu(struct bce_softc *sc)
3087 struct cpu_reg cpu_reg;
3090 cpu_reg.mode = BCE_COM_CPU_MODE;
3091 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3092 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3093 cpu_reg.state = BCE_COM_CPU_STATE;
3094 cpu_reg.state_value_clear = 0xffffff;
3095 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3096 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3097 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3098 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3099 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3100 cpu_reg.spad_base = BCE_COM_SCRATCH;
3101 cpu_reg.mips_view_base = 0x8000000;
3103 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3104 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3105 fw.ver_major = bce_COM_b09FwReleaseMajor;
3106 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3107 fw.ver_fix = bce_COM_b09FwReleaseFix;
3108 fw.start_addr = bce_COM_b09FwStartAddr;
3110 fw.text_addr = bce_COM_b09FwTextAddr;
3111 fw.text_len = bce_COM_b09FwTextLen;
3113 fw.text = bce_COM_b09FwText;
3115 fw.data_addr = bce_COM_b09FwDataAddr;
3116 fw.data_len = bce_COM_b09FwDataLen;
3118 fw.data = bce_COM_b09FwData;
3120 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3121 fw.sbss_len = bce_COM_b09FwSbssLen;
3123 fw.sbss = bce_COM_b09FwSbss;
3125 fw.bss_addr = bce_COM_b09FwBssAddr;
3126 fw.bss_len = bce_COM_b09FwBssLen;
3128 fw.bss = bce_COM_b09FwBss;
3130 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3131 fw.rodata_len = bce_COM_b09FwRodataLen;
3132 fw.rodata_index = 0;
3133 fw.rodata = bce_COM_b09FwRodata;
3135 fw.ver_major = bce_COM_b06FwReleaseMajor;
3136 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3137 fw.ver_fix = bce_COM_b06FwReleaseFix;
3138 fw.start_addr = bce_COM_b06FwStartAddr;
3140 fw.text_addr = bce_COM_b06FwTextAddr;
3141 fw.text_len = bce_COM_b06FwTextLen;
3143 fw.text = bce_COM_b06FwText;
3145 fw.data_addr = bce_COM_b06FwDataAddr;
3146 fw.data_len = bce_COM_b06FwDataLen;
3148 fw.data = bce_COM_b06FwData;
3150 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3151 fw.sbss_len = bce_COM_b06FwSbssLen;
3153 fw.sbss = bce_COM_b06FwSbss;
3155 fw.bss_addr = bce_COM_b06FwBssAddr;
3156 fw.bss_len = bce_COM_b06FwBssLen;
3158 fw.bss = bce_COM_b06FwBss;
3160 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3161 fw.rodata_len = bce_COM_b06FwRodataLen;
3162 fw.rodata_index = 0;
3163 fw.rodata = bce_COM_b06FwRodata;
3166 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3167 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3168 bce_start_cpu(sc, &cpu_reg);
3172 /****************************************************************************/
3173 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3175 /* Loads the firmware for each CPU and starts the CPU. */
3179 /****************************************************************************/
3181 bce_init_cpus(struct bce_softc *sc)
3183 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3184 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3185 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3186 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3187 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3188 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3189 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3191 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3192 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3193 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3194 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3197 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3198 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3199 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3200 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3203 bce_init_rxp_cpu(sc);
3204 bce_init_txp_cpu(sc);
3205 bce_init_tpat_cpu(sc);
3206 bce_init_com_cpu(sc);
3207 bce_init_cp_cpu(sc);
3211 /****************************************************************************/
3212 /* Initialize context memory. */
3214 /* Clears the memory associated with each Context ID (CID). */
3218 /****************************************************************************/
3220 bce_init_ctx(struct bce_softc *sc)
3222 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3223 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3224 /* DRC: Replace this constant value with a #define. */
3225 int i, retry_cnt = 10;
3229 * BCM5709 context memory may be cached
3230 * in host memory so prepare the host memory
3233 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3235 val |= (BCM_PAGE_BITS - 8) << 16;
3236 REG_WR(sc, BCE_CTX_COMMAND, val);
3238 /* Wait for mem init command to complete. */
3239 for (i = 0; i < retry_cnt; i++) {
3240 val = REG_RD(sc, BCE_CTX_COMMAND);
3241 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3245 if (i == retry_cnt) {
3246 device_printf(sc->bce_dev,
3247 "Context memory initialization failed!\n");
3251 for (i = 0; i < sc->ctx_pages; i++) {
3255 * Set the physical address of the context
3258 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3259 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3260 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3261 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3262 BCE_ADDR_HI(sc->ctx_paddr[i]));
3263 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3264 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3267 * Verify that the context memory write was successful.
3269 for (j = 0; j < retry_cnt; j++) {
3270 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3272 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3276 if (j == retry_cnt) {
3277 device_printf(sc->bce_dev,
3278 "Failed to initialize context page!\n");
3283 uint32_t vcid_addr, offset;
3286 * For the 5706/5708, context memory is local to
3287 * the controller, so initialize the controller
3291 vcid_addr = GET_CID_ADDR(96);
3293 vcid_addr -= PHY_CTX_SIZE;
3295 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3296 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3298 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3299 CTX_WR(sc, 0x00, offset, 0);
3301 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3302 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3309 /****************************************************************************/
3310 /* Fetch the permanent MAC address of the controller. */
3314 /****************************************************************************/
3316 bce_get_mac_addr(struct bce_softc *sc)
3318 uint32_t mac_lo = 0, mac_hi = 0;
3321 * The NetXtreme II bootcode populates various NIC
3322 * power-on and runtime configuration items in a
3323 * shared memory area. The factory configured MAC
3324 * address is available from both NVRAM and the
3325 * shared memory area so we'll read the value from
3326 * shared memory for speed.
3329 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3330 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3332 if (mac_lo == 0 && mac_hi == 0) {
3333 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3335 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3336 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3337 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3338 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3339 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3340 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3343 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3347 /****************************************************************************/
3348 /* Program the MAC address. */
3352 /****************************************************************************/
3354 bce_set_mac_addr(struct bce_softc *sc)
3356 const uint8_t *mac_addr = sc->eaddr;
3359 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3362 val = (mac_addr[0] << 8) | mac_addr[1];
3363 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3365 val = (mac_addr[2] << 24) |
3366 (mac_addr[3] << 16) |
3367 (mac_addr[4] << 8) |
3369 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3373 /****************************************************************************/
3374 /* Stop the controller. */
3378 /****************************************************************************/
3380 bce_stop(struct bce_softc *sc)
3382 struct ifnet *ifp = &sc->arpcom.ac_if;
3384 ASSERT_SERIALIZED(ifp->if_serializer);
3386 callout_stop(&sc->bce_tick_callout);
3388 /* Disable the transmit/receive blocks. */
3389 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3390 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3393 bce_disable_intr(sc);
3395 /* Free the RX lists. */
3396 bce_free_rx_chain(sc);
3398 /* Free TX buffers. */
3399 bce_free_tx_chain(sc);
3402 sc->bce_coalchg_mask = 0;
3404 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3410 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3415 /* Wait for pending PCI transactions to complete. */
3416 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3417 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3418 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3419 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3420 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3421 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3425 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3426 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3427 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3428 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3429 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3432 /* Assume bootcode is running. */
3433 sc->bce_fw_timed_out = 0;
3434 sc->bce_drv_cardiac_arrest = 0;
3436 /* Give the firmware a chance to prepare for the reset. */
3437 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3439 if_printf(&sc->arpcom.ac_if,
3440 "Firmware is not ready for reset\n");
3444 /* Set a firmware reminder that this is a soft reset. */
3445 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3446 BCE_DRV_RESET_SIGNATURE_MAGIC);
3448 /* Dummy read to force the chip to complete all current transactions. */
3449 val = REG_RD(sc, BCE_MISC_ID);
3452 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3453 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3454 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3455 REG_RD(sc, BCE_MISC_COMMAND);
3458 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3459 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3461 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3463 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3464 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3465 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3466 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3468 /* Allow up to 30us for reset to complete. */
3469 for (i = 0; i < 10; i++) {
3470 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3471 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3472 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3477 /* Check that reset completed successfully. */
3478 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3479 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3480 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3485 /* Make sure byte swapping is properly configured. */
3486 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3487 if (val != 0x01020304) {
3488 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3492 /* Just completed a reset, assume that firmware is running again. */
3493 sc->bce_fw_timed_out = 0;
3494 sc->bce_drv_cardiac_arrest = 0;
3496 /* Wait for the firmware to finish its initialization. */
3497 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3499 if_printf(&sc->arpcom.ac_if,
3500 "Firmware did not complete initialization!\n");
3507 bce_chipinit(struct bce_softc *sc)
3512 /* Make sure the interrupt is not active. */
3513 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3514 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3517 * Initialize DMA byte/word swapping, configure the number of DMA
3518 * channels and PCI clock compensation delay.
3520 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3521 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3522 #if BYTE_ORDER == BIG_ENDIAN
3523 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3525 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3526 DMA_READ_CHANS << 12 |
3527 DMA_WRITE_CHANS << 16;
3529 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3531 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3532 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3535 * This setting resolves a problem observed on certain Intel PCI
3536 * chipsets that cannot handle multiple outstanding DMA operations.
3537 * See errata E9_5706A1_65.
3539 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3540 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3541 !(sc->bce_flags & BCE_PCIX_FLAG))
3542 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3544 REG_WR(sc, BCE_DMA_CONFIG, val);
3546 /* Enable the RX_V2P and Context state machines before access. */
3547 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3548 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3549 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3550 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3552 /* Initialize context mapping and zero out the quick contexts. */
3553 rc = bce_init_ctx(sc);
3557 /* Initialize the on-boards CPUs */
3560 /* Enable management frames (NC-SI) to flow to the MCP. */
3561 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3562 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) |
3563 BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3564 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3567 /* Prepare NVRAM for access. */
3568 rc = bce_init_nvram(sc);
3572 /* Set the kernel bypass block size */
3573 val = REG_RD(sc, BCE_MQ_CONFIG);
3574 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3575 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3577 /* Enable bins used on the 5709/5716. */
3578 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3579 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3580 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3581 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3582 val |= BCE_MQ_CONFIG_HALT_DIS;
3585 REG_WR(sc, BCE_MQ_CONFIG, val);
3587 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3588 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3589 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3591 /* Set the page size and clear the RV2P processor stall bits. */
3592 val = (BCM_PAGE_BITS - 8) << 24;
3593 REG_WR(sc, BCE_RV2P_CONFIG, val);
3595 /* Configure page size. */
3596 val = REG_RD(sc, BCE_TBDR_CONFIG);
3597 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3598 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3599 REG_WR(sc, BCE_TBDR_CONFIG, val);
3601 /* Set the perfect match control register to default. */
3602 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3608 /****************************************************************************/
3609 /* Initialize the controller in preparation to send/receive traffic. */
3612 /* 0 for success, positive value for failure. */
3613 /****************************************************************************/
3615 bce_blockinit(struct bce_softc *sc)
3620 /* Load the hardware default MAC address. */
3621 bce_set_mac_addr(sc);
3623 /* Set the Ethernet backoff seed value */
3624 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3625 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3626 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3628 sc->last_status_idx = 0;
3629 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3631 /* Set up link change interrupt generation. */
3632 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3634 /* Program the physical address of the status block. */
3635 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3636 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3638 /* Program the physical address of the statistics block. */
3639 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3640 BCE_ADDR_LO(sc->stats_block_paddr));
3641 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3642 BCE_ADDR_HI(sc->stats_block_paddr));
3644 /* Program various host coalescing parameters. */
3645 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3646 (sc->bce_tx_quick_cons_trip_int << 16) |
3647 sc->bce_tx_quick_cons_trip);
3648 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3649 (sc->bce_rx_quick_cons_trip_int << 16) |
3650 sc->bce_rx_quick_cons_trip);
3651 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3652 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3653 REG_WR(sc, BCE_HC_TX_TICKS,
3654 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3655 REG_WR(sc, BCE_HC_RX_TICKS,
3656 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3657 REG_WR(sc, BCE_HC_COM_TICKS,
3658 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3659 REG_WR(sc, BCE_HC_CMD_TICKS,
3660 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3661 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3662 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3664 val = BCE_HC_CONFIG_TX_TMR_MODE | BCE_HC_CONFIG_COLLECT_STATS;
3665 if (sc->bce_flags & BCE_ONESHOT_MSI_FLAG) {
3667 if_printf(&sc->arpcom.ac_if, "oneshot MSI\n");
3668 val |= BCE_HC_CONFIG_ONE_SHOT | BCE_HC_CONFIG_USE_INT_PARAM;
3670 REG_WR(sc, BCE_HC_CONFIG, val);
3672 /* Clear the internal statistics counters. */
3673 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3675 /* Verify that bootcode is running. */
3676 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
3678 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3679 if_printf(&sc->arpcom.ac_if,
3680 "%s(%d): Simulating bootcode failure.\n",
3681 __FILE__, __LINE__);
3684 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3685 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3686 if_printf(&sc->arpcom.ac_if,
3687 "Bootcode not running! Found: 0x%08X, "
3688 "Expected: 08%08X\n",
3689 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3690 BCE_DEV_INFO_SIGNATURE_MAGIC);
3695 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3696 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3697 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3698 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3699 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3702 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3703 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3705 /* Enable link state change interrupt generation. */
3706 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3708 /* Enable the RXP. */
3709 bce_start_rxp_cpu(sc);
3711 /* Disable management frames (NC-SI) from flowing to the MCP. */
3712 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3713 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
3714 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3715 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3718 /* Enable all remaining blocks in the MAC. */
3719 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3720 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3721 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3722 BCE_MISC_ENABLE_DEFAULT_XI);
3724 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
3726 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3729 /* Save the current host coalescing block settings. */
3730 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
3736 /****************************************************************************/
3737 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3739 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3740 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3744 /* 0 for success, positive value for failure. */
3745 /****************************************************************************/
3747 bce_newbuf_std(struct bce_softc *sc, uint16_t *prod, uint16_t *chain_prod,
3748 uint32_t *prod_bseq, int init)
3751 bus_dma_segment_t seg;
3755 uint16_t debug_chain_prod = *chain_prod;
3758 /* Make sure the inputs are valid. */
3759 DBRUNIF((*chain_prod > MAX_RX_BD),
3760 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3761 "RX producer out of range: 0x%04X > 0x%04X\n",
3763 *chain_prod, (uint16_t)MAX_RX_BD));
3765 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3766 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3768 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3769 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3770 "Simulating mbuf allocation failure.\n",
3771 __FILE__, __LINE__);
3772 sc->mbuf_alloc_failed++;
3775 /* This is a new mbuf allocation. */
3776 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
3779 DBRUNIF(1, sc->rx_mbuf_alloc++);
3781 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3783 /* Map the mbuf cluster into device memory. */
3784 error = bus_dmamap_load_mbuf_segment(sc->rx_mbuf_tag,
3785 sc->rx_mbuf_tmpmap, m_new, &seg, 1, &nseg,
3790 if_printf(&sc->arpcom.ac_if,
3791 "Error mapping mbuf into RX chain!\n");
3793 DBRUNIF(1, sc->rx_mbuf_alloc--);
3797 if (sc->rx_mbuf_ptr[*chain_prod] != NULL) {
3798 bus_dmamap_unload(sc->rx_mbuf_tag,
3799 sc->rx_mbuf_map[*chain_prod]);
3802 map = sc->rx_mbuf_map[*chain_prod];
3803 sc->rx_mbuf_map[*chain_prod] = sc->rx_mbuf_tmpmap;
3804 sc->rx_mbuf_tmpmap = map;
3806 /* Watch for overflow. */
3807 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3808 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3809 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3810 __FILE__, __LINE__, sc->free_rx_bd,
3811 (uint16_t)USABLE_RX_BD));
3813 /* Update some debug statistic counters */
3814 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3815 sc->rx_low_watermark = sc->free_rx_bd);
3816 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3818 /* Save the mbuf and update our counter. */
3819 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3820 sc->rx_mbuf_paddr[*chain_prod] = seg.ds_addr;
3823 bce_setup_rxdesc_std(sc, *chain_prod, prod_bseq);
3825 DBRUN(BCE_VERBOSE_RECV,
3826 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3828 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3829 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3836 bce_setup_rxdesc_std(struct bce_softc *sc, uint16_t chain_prod, uint32_t *prod_bseq)
3842 paddr = sc->rx_mbuf_paddr[chain_prod];
3843 len = sc->rx_mbuf_ptr[chain_prod]->m_len;
3845 /* Setup the rx_bd for the first segment. */
3846 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
3848 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(paddr));
3849 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(paddr));
3850 rxbd->rx_bd_len = htole32(len);
3851 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3854 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3858 /****************************************************************************/
3859 /* Initialize the TX context memory. */
3863 /****************************************************************************/
3865 bce_init_tx_context(struct bce_softc *sc)
3869 /* Initialize the context ID for an L2 TX chain. */
3870 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3871 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3872 /* Set the CID type to support an L2 connection. */
3873 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3874 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
3875 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3876 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE_XI, val);
3878 /* Point the hardware to the first page in the chain. */
3879 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3880 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3881 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
3882 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3883 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3884 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
3886 /* Set the CID type to support an L2 connection. */
3887 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3888 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
3889 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3890 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
3892 /* Point the hardware to the first page in the chain. */
3893 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3894 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3895 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
3896 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3897 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3898 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
3903 /****************************************************************************/
3904 /* Allocate memory and initialize the TX data structures. */
3907 /* 0 for success, positive value for failure. */
3908 /****************************************************************************/
3910 bce_init_tx_chain(struct bce_softc *sc)
3915 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3917 /* Set the initial TX producer/consumer indices. */
3920 sc->tx_prod_bseq = 0;
3922 sc->max_tx_bd = USABLE_TX_BD;
3923 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3924 DBRUNIF(1, sc->tx_full_count = 0);
3927 * The NetXtreme II supports a linked-list structre called
3928 * a Buffer Descriptor Chain (or BD chain). A BD chain
3929 * consists of a series of 1 or more chain pages, each of which
3930 * consists of a fixed number of BD entries.
3931 * The last BD entry on each page is a pointer to the next page
3932 * in the chain, and the last pointer in the BD chain
3933 * points back to the beginning of the chain.
3936 /* Set the TX next pointer chain entries. */
3937 for (i = 0; i < TX_PAGES; i++) {
3940 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3942 /* Check if we've reached the last page. */
3943 if (i == (TX_PAGES - 1))
3948 txbd->tx_bd_haddr_hi =
3949 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3950 txbd->tx_bd_haddr_lo =
3951 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3953 bce_init_tx_context(sc);
3959 /****************************************************************************/
3960 /* Free memory and clear the TX data structures. */
3964 /****************************************************************************/
3966 bce_free_tx_chain(struct bce_softc *sc)
3970 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3972 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3973 for (i = 0; i < TOTAL_TX_BD; i++) {
3974 if (sc->tx_mbuf_ptr[i] != NULL) {
3975 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3976 m_freem(sc->tx_mbuf_ptr[i]);
3977 sc->tx_mbuf_ptr[i] = NULL;
3978 DBRUNIF(1, sc->tx_mbuf_alloc--);
3982 /* Clear each TX chain page. */
3983 for (i = 0; i < TX_PAGES; i++)
3984 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3987 /* Check if we lost any mbufs in the process. */
3988 DBRUNIF((sc->tx_mbuf_alloc),
3989 if_printf(&sc->arpcom.ac_if,
3990 "%s(%d): Memory leak! "
3991 "Lost %d mbufs from tx chain!\n",
3992 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3994 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3998 /****************************************************************************/
3999 /* Initialize the RX context memory. */
4003 /****************************************************************************/
4005 bce_init_rx_context(struct bce_softc *sc)
4009 /* Initialize the context ID for an L2 RX chain. */
4010 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
4011 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
4014 * Set the level for generating pause frames
4015 * when the number of available rx_bd's gets
4016 * too low (the low watermark) and the level
4017 * when pause frames can be stopped (the high
4020 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4021 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4022 uint32_t lo_water, hi_water;
4024 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
4025 hi_water = USABLE_RX_BD / 4;
4027 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
4028 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
4032 else if (hi_water == 0)
4035 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
4038 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
4040 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
4041 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4042 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4043 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
4044 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
4047 /* Point the hardware to the first page in the chain. */
4048 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
4049 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
4050 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
4051 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
4055 /****************************************************************************/
4056 /* Allocate memory and initialize the RX data structures. */
4059 /* 0 for success, positive value for failure. */
4060 /****************************************************************************/
4062 bce_init_rx_chain(struct bce_softc *sc)
4066 uint16_t prod, chain_prod;
4069 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4071 /* Initialize the RX producer and consumer indices. */
4074 sc->rx_prod_bseq = 0;
4075 sc->free_rx_bd = USABLE_RX_BD;
4076 sc->max_rx_bd = USABLE_RX_BD;
4077 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
4078 DBRUNIF(1, sc->rx_empty_count = 0);
4080 /* Initialize the RX next pointer chain entries. */
4081 for (i = 0; i < RX_PAGES; i++) {
4084 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
4086 /* Check if we've reached the last page. */
4087 if (i == (RX_PAGES - 1))
4092 /* Setup the chain page pointers. */
4093 rxbd->rx_bd_haddr_hi =
4094 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
4095 rxbd->rx_bd_haddr_lo =
4096 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
4099 /* Allocate mbuf clusters for the rx_bd chain. */
4100 prod = prod_bseq = 0;
4101 while (prod < TOTAL_RX_BD) {
4102 chain_prod = RX_CHAIN_IDX(prod);
4103 if (bce_newbuf_std(sc, &prod, &chain_prod, &prod_bseq, 1)) {
4104 if_printf(&sc->arpcom.ac_if,
4105 "Error filling RX chain: rx_bd[0x%04X]!\n",
4110 prod = NEXT_RX_BD(prod);
4113 /* Save the RX chain producer index. */
4115 sc->rx_prod_bseq = prod_bseq;
4117 /* Tell the chip about the waiting rx_bd's. */
4118 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4120 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4123 bce_init_rx_context(sc);
4129 /****************************************************************************/
4130 /* Free memory and clear the RX data structures. */
4134 /****************************************************************************/
4136 bce_free_rx_chain(struct bce_softc *sc)
4140 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4142 /* Free any mbufs still in the RX mbuf chain. */
4143 for (i = 0; i < TOTAL_RX_BD; i++) {
4144 if (sc->rx_mbuf_ptr[i] != NULL) {
4145 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
4146 m_freem(sc->rx_mbuf_ptr[i]);
4147 sc->rx_mbuf_ptr[i] = NULL;
4148 DBRUNIF(1, sc->rx_mbuf_alloc--);
4152 /* Clear each RX chain page. */
4153 for (i = 0; i < RX_PAGES; i++)
4154 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
4156 /* Check if we lost any mbufs in the process. */
4157 DBRUNIF((sc->rx_mbuf_alloc),
4158 if_printf(&sc->arpcom.ac_if,
4159 "%s(%d): Memory leak! "
4160 "Lost %d mbufs from rx chain!\n",
4161 __FILE__, __LINE__, sc->rx_mbuf_alloc));
4163 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4167 /****************************************************************************/
4168 /* Set media options. */
4171 /* 0 for success, positive value for failure. */
4172 /****************************************************************************/
4174 bce_ifmedia_upd(struct ifnet *ifp)
4176 struct bce_softc *sc = ifp->if_softc;
4177 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4181 * 'mii' will be NULL, when this function is called on following
4182 * code path: bce_attach() -> bce_mgmt_init()
4185 /* Make sure the MII bus has been enumerated. */
4187 if (mii->mii_instance) {
4188 struct mii_softc *miisc;
4190 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
4191 mii_phy_reset(miisc);
4193 error = mii_mediachg(mii);
4199 /****************************************************************************/
4200 /* Reports current media status. */
4204 /****************************************************************************/
4206 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
4208 struct bce_softc *sc = ifp->if_softc;
4209 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4212 ifmr->ifm_active = mii->mii_media_active;
4213 ifmr->ifm_status = mii->mii_media_status;
4217 /****************************************************************************/
4218 /* Handles PHY generated interrupt events. */
4222 /****************************************************************************/
4224 bce_phy_intr(struct bce_softc *sc)
4226 uint32_t new_link_state, old_link_state;
4227 struct ifnet *ifp = &sc->arpcom.ac_if;
4229 ASSERT_SERIALIZED(ifp->if_serializer);
4231 new_link_state = sc->status_block->status_attn_bits &
4232 STATUS_ATTN_BITS_LINK_STATE;
4233 old_link_state = sc->status_block->status_attn_bits_ack &
4234 STATUS_ATTN_BITS_LINK_STATE;
4236 /* Handle any changes if the link state has changed. */
4237 if (new_link_state != old_link_state) { /* XXX redundant? */
4238 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4240 /* Update the status_attn_bits_ack field in the status block. */
4241 if (new_link_state) {
4242 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4243 STATUS_ATTN_BITS_LINK_STATE);
4245 if_printf(ifp, "Link is now UP.\n");
4247 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4248 STATUS_ATTN_BITS_LINK_STATE);
4250 if_printf(ifp, "Link is now DOWN.\n");
4254 * Assume link is down and allow tick routine to
4255 * update the state based on the actual media state.
4258 callout_stop(&sc->bce_tick_callout);
4259 bce_tick_serialized(sc);
4262 /* Acknowledge the link change interrupt. */
4263 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4267 /****************************************************************************/
4268 /* Reads the receive consumer value from the status block (skipping over */
4269 /* chain page pointer if necessary). */
4273 /****************************************************************************/
4274 static __inline uint16_t
4275 bce_get_hw_rx_cons(struct bce_softc *sc)
4277 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
4279 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4285 /****************************************************************************/
4286 /* Handles received frame interrupt events. */
4290 /****************************************************************************/
4292 bce_rx_intr(struct bce_softc *sc, int count)
4294 struct ifnet *ifp = &sc->arpcom.ac_if;
4295 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4296 uint32_t sw_prod_bseq;
4297 struct mbuf_chain chain[MAXCPU];
4299 ASSERT_SERIALIZED(ifp->if_serializer);
4301 ether_input_chain_init(chain);
4303 DBRUNIF(1, sc->rx_interrupts++);
4305 /* Get the hardware's view of the RX consumer index. */
4306 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4308 /* Get working copies of the driver's view of the RX indices. */
4309 sw_cons = sc->rx_cons;
4310 sw_prod = sc->rx_prod;
4311 sw_prod_bseq = sc->rx_prod_bseq;
4313 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
4314 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
4315 __func__, sw_prod, sw_cons, sw_prod_bseq);
4317 /* Prevent speculative reads from getting ahead of the status block. */
4318 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4319 BUS_SPACE_BARRIER_READ);
4321 /* Update some debug statistics counters */
4322 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
4323 sc->rx_low_watermark = sc->free_rx_bd);
4324 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
4326 /* Scan through the receive chain as long as there is work to do. */
4327 while (sw_cons != hw_cons) {
4328 struct mbuf *m = NULL;
4329 struct l2_fhdr *l2fhdr = NULL;
4332 uint32_t status = 0;
4334 #ifdef DEVICE_POLLING
4335 if (count >= 0 && count-- == 0) {
4336 sc->hw_rx_cons = sw_cons;
4342 * Convert the producer/consumer indices
4343 * to an actual rx_bd index.
4345 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
4346 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
4348 /* Get the used rx_bd. */
4349 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
4350 [RX_IDX(sw_chain_cons)];
4353 DBRUN(BCE_VERBOSE_RECV,
4354 if_printf(ifp, "%s(): ", __func__);
4355 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
4357 /* The mbuf is stored with the last rx_bd entry of a packet. */
4358 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4359 /* Validate that this is the last rx_bd. */
4360 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
4361 if_printf(ifp, "%s(%d): "
4362 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
4363 __FILE__, __LINE__, sw_chain_cons);
4364 bce_breakpoint(sc));
4366 if (sw_chain_cons != sw_chain_prod) {
4367 if_printf(ifp, "RX cons(%d) != prod(%d), "
4368 "drop!\n", sw_chain_cons,
4372 bce_setup_rxdesc_std(sc, sw_chain_cons,
4375 goto bce_rx_int_next_rx;
4378 /* Unmap the mbuf from DMA space. */
4379 bus_dmamap_sync(sc->rx_mbuf_tag,
4380 sc->rx_mbuf_map[sw_chain_cons],
4381 BUS_DMASYNC_POSTREAD);
4383 /* Save the mbuf from the driver's chain. */
4384 m = sc->rx_mbuf_ptr[sw_chain_cons];
4387 * Frames received on the NetXteme II are prepended
4388 * with an l2_fhdr structure which provides status
4389 * information about the received frame (including
4390 * VLAN tags and checksum info). The frames are also
4391 * automatically adjusted to align the IP header
4392 * (i.e. two null bytes are inserted before the
4393 * Ethernet header). As a result the data DMA'd by
4394 * the controller into the mbuf is as follows:
4396 * +---------+-----+---------------------+-----+
4397 * | l2_fhdr | pad | packet data | FCS |
4398 * +---------+-----+---------------------+-----+
4400 * The l2_fhdr needs to be checked and skipped and the
4401 * FCS needs to be stripped before sending the packet
4404 l2fhdr = mtod(m, struct l2_fhdr *);
4406 len = l2fhdr->l2_fhdr_pkt_len;
4407 status = l2fhdr->l2_fhdr_status;
4409 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
4411 "Simulating l2_fhdr status error.\n");
4412 status = status | L2_FHDR_ERRORS_PHY_DECODE);
4414 /* Watch for unusual sized frames. */
4415 DBRUNIF((len < BCE_MIN_MTU ||
4416 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
4418 "%s(%d): Unusual frame size found. "
4419 "Min(%d), Actual(%d), Max(%d)\n",
4421 (int)BCE_MIN_MTU, len,
4422 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
4423 bce_dump_mbuf(sc, m);
4424 bce_breakpoint(sc));
4426 len -= ETHER_CRC_LEN;
4428 /* Check the received frame for errors. */
4429 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4430 L2_FHDR_ERRORS_PHY_DECODE |
4431 L2_FHDR_ERRORS_ALIGNMENT |
4432 L2_FHDR_ERRORS_TOO_SHORT |
4433 L2_FHDR_ERRORS_GIANT_FRAME)) {
4435 DBRUNIF(1, sc->l2fhdr_status_errors++);
4437 /* Reuse the mbuf for a new frame. */
4438 bce_setup_rxdesc_std(sc, sw_chain_prod,
4441 goto bce_rx_int_next_rx;
4445 * Get a new mbuf for the rx_bd. If no new
4446 * mbufs are available then reuse the current mbuf,
4447 * log an ierror on the interface, and generate
4448 * an error in the system log.
4450 if (bce_newbuf_std(sc, &sw_prod, &sw_chain_prod,
4451 &sw_prod_bseq, 0)) {
4454 "%s(%d): Failed to allocate new mbuf, "
4455 "incoming frame dropped!\n",
4456 __FILE__, __LINE__));
4460 /* Try and reuse the exisitng mbuf. */
4461 bce_setup_rxdesc_std(sc, sw_chain_prod,
4464 goto bce_rx_int_next_rx;
4468 * Skip over the l2_fhdr when passing
4469 * the data up the stack.
4471 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4473 m->m_pkthdr.len = m->m_len = len;
4474 m->m_pkthdr.rcvif = ifp;
4476 DBRUN(BCE_VERBOSE_RECV,
4477 struct ether_header *eh;
4478 eh = mtod(m, struct ether_header *);
4479 if_printf(ifp, "%s(): to: %6D, from: %6D, "
4480 "type: 0x%04X\n", __func__,
4481 eh->ether_dhost, ":",
4482 eh->ether_shost, ":",
4483 htons(eh->ether_type)));
4485 /* Validate the checksum if offload enabled. */
4486 if (ifp->if_capenable & IFCAP_RXCSUM) {
4487 /* Check for an IP datagram. */
4488 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4489 m->m_pkthdr.csum_flags |=
4492 /* Check if the IP checksum is valid. */
4493 if ((l2fhdr->l2_fhdr_ip_xsum ^
4495 m->m_pkthdr.csum_flags |=
4498 DBPRINT(sc, BCE_WARN_RECV,
4499 "%s(): Invalid IP checksum = 0x%04X!\n",
4500 __func__, l2fhdr->l2_fhdr_ip_xsum);
4504 /* Check for a valid TCP/UDP frame. */
4505 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4506 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4508 /* Check for a good TCP/UDP checksum. */
4510 (L2_FHDR_ERRORS_TCP_XSUM |
4511 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4512 m->m_pkthdr.csum_data =
4513 l2fhdr->l2_fhdr_tcp_udp_xsum;
4514 m->m_pkthdr.csum_flags |=
4518 DBPRINT(sc, BCE_WARN_RECV,
4519 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
4520 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
4527 sw_prod = NEXT_RX_BD(sw_prod);
4530 sw_cons = NEXT_RX_BD(sw_cons);
4532 /* If we have a packet, pass it up the stack */
4534 DBPRINT(sc, BCE_VERBOSE_RECV,
4535 "%s(): Passing received frame up.\n", __func__);
4537 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4538 m->m_flags |= M_VLANTAG;
4539 m->m_pkthdr.ether_vlantag =
4540 l2fhdr->l2_fhdr_vlan_tag;
4542 ether_input_chain(ifp, m, NULL, chain);
4544 DBRUNIF(1, sc->rx_mbuf_alloc--);
4548 * If polling(4) is not enabled, refresh hw_cons to see
4549 * whether there's new work.
4551 * If polling(4) is enabled, i.e count >= 0, refreshing
4552 * should not be performed, so that we would not spend
4553 * too much time in RX processing.
4555 if (count < 0 && sw_cons == hw_cons)
4556 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4559 * Prevent speculative reads from getting ahead
4560 * of the status block.
4562 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4563 BUS_SPACE_BARRIER_READ);
4566 ether_input_dispatch(chain);
4568 sc->rx_cons = sw_cons;
4569 sc->rx_prod = sw_prod;
4570 sc->rx_prod_bseq = sw_prod_bseq;
4572 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4574 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4577 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4578 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4579 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4583 /****************************************************************************/
4584 /* Reads the transmit consumer value from the status block (skipping over */
4585 /* chain page pointer if necessary). */
4589 /****************************************************************************/
4590 static __inline uint16_t
4591 bce_get_hw_tx_cons(struct bce_softc *sc)
4593 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4595 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4601 /****************************************************************************/
4602 /* Handles transmit completion interrupt events. */
4606 /****************************************************************************/
4608 bce_tx_intr(struct bce_softc *sc)
4610 struct ifnet *ifp = &sc->arpcom.ac_if;
4611 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4613 ASSERT_SERIALIZED(ifp->if_serializer);
4615 DBRUNIF(1, sc->tx_interrupts++);
4617 /* Get the hardware's view of the TX consumer index. */
4618 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4619 sw_tx_cons = sc->tx_cons;
4621 /* Prevent speculative reads from getting ahead of the status block. */
4622 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4623 BUS_SPACE_BARRIER_READ);
4625 /* Cycle through any completed TX chain page entries. */
4626 while (sw_tx_cons != hw_tx_cons) {
4628 struct tx_bd *txbd = NULL;
4630 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4632 DBPRINT(sc, BCE_INFO_SEND,
4633 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4634 "sw_tx_chain_cons = 0x%04X\n",
4635 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4637 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4638 if_printf(ifp, "%s(%d): "
4639 "TX chain consumer out of range! "
4640 " 0x%04X > 0x%04X\n",
4641 __FILE__, __LINE__, sw_tx_chain_cons,
4643 bce_breakpoint(sc));
4645 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4646 [TX_IDX(sw_tx_chain_cons)]);
4648 DBRUNIF((txbd == NULL),
4649 if_printf(ifp, "%s(%d): "
4650 "Unexpected NULL tx_bd[0x%04X]!\n",
4651 __FILE__, __LINE__, sw_tx_chain_cons);
4652 bce_breakpoint(sc));
4654 DBRUN(BCE_INFO_SEND,
4655 if_printf(ifp, "%s(): ", __func__);
4656 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4659 * Free the associated mbuf. Remember
4660 * that only the last tx_bd of a packet
4661 * has an mbuf pointer and DMA map.
4663 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4664 /* Validate that this is the last tx_bd. */
4665 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4666 if_printf(ifp, "%s(%d): "
4667 "tx_bd END flag not set but "
4668 "txmbuf == NULL!\n", __FILE__, __LINE__);
4669 bce_breakpoint(sc));
4671 DBRUN(BCE_INFO_SEND,
4672 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4673 "from tx_bd[0x%04X]\n", __func__,
4676 /* Unmap the mbuf. */
4677 bus_dmamap_unload(sc->tx_mbuf_tag,
4678 sc->tx_mbuf_map[sw_tx_chain_cons]);
4680 /* Free the mbuf. */
4681 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4682 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4683 DBRUNIF(1, sc->tx_mbuf_alloc--);
4689 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4691 if (sw_tx_cons == hw_tx_cons) {
4692 /* Refresh hw_cons to see if there's new work. */
4693 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4697 * Prevent speculative reads from getting
4698 * ahead of the status block.
4700 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4701 BUS_SPACE_BARRIER_READ);
4704 if (sc->used_tx_bd == 0) {
4705 /* Clear the TX timeout timer. */
4709 /* Clear the tx hardware queue full flag. */
4710 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4711 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4712 DBPRINT(sc, BCE_WARN_SEND,
4713 "%s(): Open TX chain! %d/%d (used/total)\n",
4714 __func__, sc->used_tx_bd, sc->max_tx_bd));
4715 ifp->if_flags &= ~IFF_OACTIVE;
4717 sc->tx_cons = sw_tx_cons;
4721 /****************************************************************************/
4722 /* Disables interrupt generation. */
4726 /****************************************************************************/
4728 bce_disable_intr(struct bce_softc *sc)
4730 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4731 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4732 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4736 /****************************************************************************/
4737 /* Enables interrupt generation. */
4741 /****************************************************************************/
4743 bce_enable_intr(struct bce_softc *sc, int coal_now)
4745 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4747 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4748 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4749 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4751 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4752 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4755 REG_WR(sc, BCE_HC_COMMAND,
4756 sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
4761 /****************************************************************************/
4762 /* Handles controller initialization. */
4766 /****************************************************************************/
4770 struct bce_softc *sc = xsc;
4771 struct ifnet *ifp = &sc->arpcom.ac_if;
4775 ASSERT_SERIALIZED(ifp->if_serializer);
4777 /* Check if the driver is still running and bail out if it is. */
4778 if (ifp->if_flags & IFF_RUNNING)
4783 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4785 if_printf(ifp, "Controller reset failed!\n");
4789 error = bce_chipinit(sc);
4791 if_printf(ifp, "Controller initialization failed!\n");
4795 error = bce_blockinit(sc);
4797 if_printf(ifp, "Block initialization failed!\n");
4801 /* Load our MAC address. */
4802 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4803 bce_set_mac_addr(sc);
4805 /* Calculate and program the Ethernet MTU size. */
4806 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4808 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4811 * Program the mtu, enabling jumbo frame
4812 * support if necessary. Also set the mbuf
4813 * allocation count for RX frames.
4815 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4817 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4818 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4819 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4820 sc->mbuf_alloc_size = MJUM9BYTES;
4822 panic("jumbo buffer is not supported yet\n");
4825 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4826 sc->mbuf_alloc_size = MCLBYTES;
4829 /* Calculate the RX Ethernet frame size for rx_bd's. */
4830 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4832 DBPRINT(sc, BCE_INFO,
4833 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4834 "max_frame_size = %d\n",
4835 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4836 sc->max_frame_size);
4838 /* Program appropriate promiscuous/multicast filtering. */
4839 bce_set_rx_mode(sc);
4841 /* Init RX buffer descriptor chain. */
4842 bce_init_rx_chain(sc); /* XXX return value */
4844 /* Init TX buffer descriptor chain. */
4845 bce_init_tx_chain(sc); /* XXX return value */
4847 #ifdef DEVICE_POLLING
4848 /* Disable interrupts if we are polling. */
4849 if (ifp->if_flags & IFF_POLLING) {
4850 bce_disable_intr(sc);
4852 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4853 (1 << 16) | sc->bce_rx_quick_cons_trip);
4854 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4855 (1 << 16) | sc->bce_tx_quick_cons_trip);
4858 /* Enable host interrupts. */
4859 bce_enable_intr(sc, 1);
4861 bce_ifmedia_upd(ifp);
4863 ifp->if_flags |= IFF_RUNNING;
4864 ifp->if_flags &= ~IFF_OACTIVE;
4866 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
4873 /****************************************************************************/
4874 /* Initialize the controller just enough so that any management firmware */
4875 /* running on the device will continue to operate corectly. */
4879 /****************************************************************************/
4881 bce_mgmt_init(struct bce_softc *sc)
4883 struct ifnet *ifp = &sc->arpcom.ac_if;
4885 /* Bail out if management firmware is not running. */
4886 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4889 /* Enable all critical blocks in the MAC. */
4890 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4891 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4892 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4893 BCE_MISC_ENABLE_DEFAULT_XI);
4895 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
4897 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4900 bce_ifmedia_upd(ifp);
4904 /****************************************************************************/
4905 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4906 /* memory visible to the controller. */
4909 /* 0 for success, positive value for failure. */
4910 /****************************************************************************/
4912 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4914 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4915 bus_dmamap_t map, tmp_map;
4916 struct mbuf *m0 = *m_head;
4917 struct tx_bd *txbd = NULL;
4918 uint16_t vlan_tag = 0, flags = 0;
4919 uint16_t chain_prod, chain_prod_start, prod;
4921 int i, error, maxsegs, nsegs;
4923 uint16_t debug_prod;
4926 /* Transfer any checksum offload flags to the bd. */
4927 if (m0->m_pkthdr.csum_flags) {
4928 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4929 flags |= TX_BD_FLAGS_IP_CKSUM;
4930 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4931 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4934 /* Transfer any VLAN tags to the bd. */
4935 if (m0->m_flags & M_VLANTAG) {
4936 flags |= TX_BD_FLAGS_VLAN_TAG;
4937 vlan_tag = m0->m_pkthdr.ether_vlantag;
4941 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4943 /* Map the mbuf into DMAable memory. */
4944 map = sc->tx_mbuf_map[chain_prod_start];
4946 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4947 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4948 ("not enough segements %d\n", maxsegs));
4949 if (maxsegs > BCE_MAX_SEGMENTS)
4950 maxsegs = BCE_MAX_SEGMENTS;
4952 /* Map the mbuf into our DMA address space. */
4953 error = bus_dmamap_load_mbuf_defrag(sc->tx_mbuf_tag, map, m_head,
4954 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
4957 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4962 /* prod points to an empty tx_bd at this point. */
4963 prod_bseq = sc->tx_prod_bseq;
4966 debug_prod = chain_prod;
4969 DBPRINT(sc, BCE_INFO_SEND,
4970 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4971 "prod_bseq = 0x%08X\n",
4972 __func__, prod, chain_prod, prod_bseq);
4975 * Cycle through each mbuf segment that makes up
4976 * the outgoing frame, gathering the mapping info
4977 * for that segment and creating a tx_bd to for
4980 for (i = 0; i < nsegs; i++) {
4981 chain_prod = TX_CHAIN_IDX(prod);
4982 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4984 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4985 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4986 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4987 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4988 txbd->tx_bd_flags = htole16(flags);
4989 prod_bseq += segs[i].ds_len;
4991 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4992 prod = NEXT_TX_BD(prod);
4995 /* Set the END flag on the last TX buffer descriptor. */
4996 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4998 DBRUN(BCE_EXCESSIVE_SEND,
4999 bce_dump_tx_chain(sc, debug_prod, nsegs));
5001 DBPRINT(sc, BCE_INFO_SEND,
5002 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
5003 "prod_bseq = 0x%08X\n",
5004 __func__, prod, chain_prod, prod_bseq);
5007 * Ensure that the mbuf pointer for this transmission
5008 * is placed at the array index of the last
5009 * descriptor in this chain. This is done
5010 * because a single map is used for all
5011 * segments of the mbuf and we don't want to
5012 * unload the map before all of the segments
5015 sc->tx_mbuf_ptr[chain_prod] = m0;
5017 tmp_map = sc->tx_mbuf_map[chain_prod];
5018 sc->tx_mbuf_map[chain_prod] = map;
5019 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
5021 sc->used_tx_bd += nsegs;
5023 /* Update some debug statistic counters */
5024 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
5025 sc->tx_hi_watermark = sc->used_tx_bd);
5026 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
5027 DBRUNIF(1, sc->tx_mbuf_alloc++);
5029 DBRUN(BCE_VERBOSE_SEND,
5030 bce_dump_tx_mbuf_chain(sc, chain_prod, nsegs));
5032 /* prod points to the next free tx_bd at this point. */
5034 sc->tx_prod_bseq = prod_bseq;
5044 /****************************************************************************/
5045 /* Main transmit routine when called from another routine with a lock. */
5049 /****************************************************************************/
5051 bce_start(struct ifnet *ifp)
5053 struct bce_softc *sc = ifp->if_softc;
5056 ASSERT_SERIALIZED(ifp->if_serializer);
5058 /* If there's no link or the transmit queue is empty then just exit. */
5059 if (!sc->bce_link) {
5060 ifq_purge(&ifp->if_snd);
5064 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
5067 DBPRINT(sc, BCE_INFO_SEND,
5068 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04zX, "
5069 "tx_prod_bseq = 0x%08X\n",
5071 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
5074 struct mbuf *m_head;
5077 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
5080 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
5081 ifp->if_flags |= IFF_OACTIVE;
5085 /* Check for any frames to send. */
5086 m_head = ifq_dequeue(&ifp->if_snd, NULL);
5091 * Pack the data into the transmit ring. If we
5092 * don't have room, place the mbuf back at the
5093 * head of the queue and set the OACTIVE flag
5094 * to wait for the NIC to drain the chain.
5096 if (bce_encap(sc, &m_head)) {
5098 if (sc->used_tx_bd == 0) {
5101 ifp->if_flags |= IFF_OACTIVE;
5108 /* Send a copy of the frame to any BPF listeners. */
5109 ETHER_BPF_MTAP(ifp, m_head);
5113 /* no packets were dequeued */
5114 DBPRINT(sc, BCE_VERBOSE_SEND,
5115 "%s(): No packets were dequeued\n", __func__);
5119 DBPRINT(sc, BCE_INFO_SEND,
5120 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04zX, "
5121 "tx_prod_bseq = 0x%08X\n",
5123 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
5125 REG_WR(sc, BCE_MQ_COMMAND,
5126 REG_RD(sc, BCE_MQ_COMMAND) | BCE_MQ_COMMAND_NO_MAP_ERROR);
5128 /* Start the transmit. */
5129 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
5130 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
5132 /* Set the tx timeout. */
5133 ifp->if_timer = BCE_TX_TIMEOUT;
5137 /****************************************************************************/
5138 /* Handles any IOCTL calls from the operating system. */
5141 /* 0 for success, positive value for failure. */
5142 /****************************************************************************/
5144 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
5146 struct bce_softc *sc = ifp->if_softc;
5147 struct ifreq *ifr = (struct ifreq *)data;
5148 struct mii_data *mii;
5149 int mask, error = 0;
5151 ASSERT_SERIALIZED(ifp->if_serializer);
5155 /* Check that the MTU setting is supported. */
5156 if (ifr->ifr_mtu < BCE_MIN_MTU ||
5158 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
5160 ifr->ifr_mtu > ETHERMTU
5167 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
5169 ifp->if_mtu = ifr->ifr_mtu;
5170 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5175 if (ifp->if_flags & IFF_UP) {
5176 if (ifp->if_flags & IFF_RUNNING) {
5177 mask = ifp->if_flags ^ sc->bce_if_flags;
5179 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
5180 bce_set_rx_mode(sc);
5184 } else if (ifp->if_flags & IFF_RUNNING) {
5187 /* If MFW is running, restart the controller a bit. */
5188 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5189 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
5194 sc->bce_if_flags = ifp->if_flags;
5199 if (ifp->if_flags & IFF_RUNNING)
5200 bce_set_rx_mode(sc);
5205 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
5207 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
5209 mii = device_get_softc(sc->bce_miibus);
5210 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
5214 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
5215 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
5218 if (mask & IFCAP_HWCSUM) {
5219 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
5220 if (IFCAP_HWCSUM & ifp->if_capenable)
5221 ifp->if_hwassist = BCE_IF_HWASSIST;
5223 ifp->if_hwassist = 0;
5228 error = ether_ioctl(ifp, command, data);
5235 /****************************************************************************/
5236 /* Transmit timeout handler. */
5240 /****************************************************************************/
5242 bce_watchdog(struct ifnet *ifp)
5244 struct bce_softc *sc = ifp->if_softc;
5246 ASSERT_SERIALIZED(ifp->if_serializer);
5248 DBRUN(BCE_VERBOSE_SEND,
5249 bce_dump_driver_state(sc);
5250 bce_dump_status_block(sc));
5253 * If we are in this routine because of pause frames, then
5254 * don't reset the hardware.
5256 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
5259 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
5261 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5263 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5268 if (!ifq_is_empty(&ifp->if_snd))
5273 #ifdef DEVICE_POLLING
5276 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
5278 struct bce_softc *sc = ifp->if_softc;
5279 struct status_block *sblk = sc->status_block;
5280 uint16_t hw_tx_cons, hw_rx_cons;
5282 ASSERT_SERIALIZED(ifp->if_serializer);
5286 bce_disable_intr(sc);
5288 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5289 (1 << 16) | sc->bce_rx_quick_cons_trip);
5290 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5291 (1 << 16) | sc->bce_tx_quick_cons_trip);
5293 case POLL_DEREGISTER:
5294 bce_enable_intr(sc, 1);
5296 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5297 (sc->bce_tx_quick_cons_trip_int << 16) |
5298 sc->bce_tx_quick_cons_trip);
5299 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5300 (sc->bce_rx_quick_cons_trip_int << 16) |
5301 sc->bce_rx_quick_cons_trip);
5307 if (cmd == POLL_AND_CHECK_STATUS) {
5308 uint32_t status_attn_bits;
5310 status_attn_bits = sblk->status_attn_bits;
5312 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5314 "Simulating unexpected status attention bit set.");
5315 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
5317 /* Was it a link change interrupt? */
5318 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5319 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5322 /* Clear any transient status updates during link state change. */
5323 REG_WR(sc, BCE_HC_COMMAND,
5324 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5325 REG_RD(sc, BCE_HC_COMMAND);
5328 * If any other attention is asserted then
5329 * the chip is toast.
5331 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5332 (sblk->status_attn_bits_ack &
5333 ~STATUS_ATTN_BITS_LINK_STATE)) {
5334 DBRUN(1, sc->unexpected_attentions++);
5336 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5337 sblk->status_attn_bits);
5340 if (bce_debug_unexpected_attention == 0)
5341 bce_breakpoint(sc));
5348 hw_rx_cons = bce_get_hw_rx_cons(sc);
5349 hw_tx_cons = bce_get_hw_tx_cons(sc);
5351 /* Check for any completed RX frames. */
5352 if (hw_rx_cons != sc->hw_rx_cons)
5353 bce_rx_intr(sc, count);
5355 /* Check for any completed TX frames. */
5356 if (hw_tx_cons != sc->hw_tx_cons)
5359 /* Check for new frames to transmit. */
5360 if (!ifq_is_empty(&ifp->if_snd))
5364 #endif /* DEVICE_POLLING */
5368 * Interrupt handler.
5370 /****************************************************************************/
5371 /* Main interrupt entry point. Verifies that the controller generated the */
5372 /* interrupt and then calls a separate routine for handle the various */
5373 /* interrupt causes (PHY, TX, RX). */
5376 /* 0 for success, positive value for failure. */
5377 /****************************************************************************/
5379 bce_intr(struct bce_softc *sc)
5381 struct ifnet *ifp = &sc->arpcom.ac_if;
5382 struct status_block *sblk;
5383 uint16_t hw_rx_cons, hw_tx_cons;
5385 ASSERT_SERIALIZED(ifp->if_serializer);
5387 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5388 DBRUNIF(1, sc->interrupts_generated++);
5390 sblk = sc->status_block;
5392 /* Check if the hardware has finished any work. */
5393 hw_rx_cons = bce_get_hw_rx_cons(sc);
5394 hw_tx_cons = bce_get_hw_tx_cons(sc);
5396 /* Keep processing data as long as there is work to do. */
5398 uint32_t status_attn_bits;
5400 status_attn_bits = sblk->status_attn_bits;
5402 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5404 "Simulating unexpected status attention bit set.");
5405 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
5407 /* Was it a link change interrupt? */
5408 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5409 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5413 * Clear any transient status updates during link state
5416 REG_WR(sc, BCE_HC_COMMAND,
5417 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5418 REG_RD(sc, BCE_HC_COMMAND);
5422 * If any other attention is asserted then
5423 * the chip is toast.
5425 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5426 (sblk->status_attn_bits_ack &
5427 ~STATUS_ATTN_BITS_LINK_STATE)) {
5428 DBRUN(1, sc->unexpected_attentions++);
5430 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5431 sblk->status_attn_bits);
5434 if (bce_debug_unexpected_attention == 0)
5435 bce_breakpoint(sc));
5441 /* Check for any completed RX frames. */
5442 if (hw_rx_cons != sc->hw_rx_cons)
5443 bce_rx_intr(sc, -1);
5445 /* Check for any completed TX frames. */
5446 if (hw_tx_cons != sc->hw_tx_cons)
5450 * Save the status block index value
5451 * for use during the next interrupt.
5453 sc->last_status_idx = sblk->status_idx;
5456 * Prevent speculative reads from getting
5457 * ahead of the status block.
5459 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
5460 BUS_SPACE_BARRIER_READ);
5463 * If there's no work left then exit the
5464 * interrupt service routine.
5466 hw_rx_cons = bce_get_hw_rx_cons(sc);
5467 hw_tx_cons = bce_get_hw_tx_cons(sc);
5468 if ((hw_rx_cons == sc->hw_rx_cons) && (hw_tx_cons == sc->hw_tx_cons))
5472 /* Re-enable interrupts. */
5473 bce_enable_intr(sc, 0);
5475 if (sc->bce_coalchg_mask)
5476 bce_coal_change(sc);
5478 /* Handle any frames that arrived while handling the interrupt. */
5479 if (!ifq_is_empty(&ifp->if_snd))
5484 bce_intr_legacy(void *xsc)
5486 struct bce_softc *sc = xsc;
5487 struct status_block *sblk;
5489 sblk = sc->status_block;
5492 * If the hardware status block index matches the last value
5493 * read by the driver and we haven't asserted our interrupt
5494 * then there's nothing to do.
5496 if (sblk->status_idx == sc->last_status_idx &&
5497 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
5498 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5501 /* Ack the interrupt and stop others from occuring. */
5502 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5503 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5504 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5507 * Read back to deassert IRQ immediately to avoid too
5508 * many spurious interrupts.
5510 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
5516 bce_intr_msi(void *xsc)
5518 struct bce_softc *sc = xsc;
5520 /* Ack the interrupt and stop others from occuring. */
5521 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5522 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5523 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5529 bce_intr_msi_oneshot(void *xsc)
5535 /****************************************************************************/
5536 /* Programs the various packet receive modes (broadcast and multicast). */
5540 /****************************************************************************/
5542 bce_set_rx_mode(struct bce_softc *sc)
5544 struct ifnet *ifp = &sc->arpcom.ac_if;
5545 struct ifmultiaddr *ifma;
5546 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5547 uint32_t rx_mode, sort_mode;
5550 ASSERT_SERIALIZED(ifp->if_serializer);
5552 /* Initialize receive mode default settings. */
5553 rx_mode = sc->rx_mode &
5554 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5555 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5556 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5559 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5562 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5563 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5564 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5567 * Check for promiscuous, all multicast, or selected
5568 * multicast address filtering.
5570 if (ifp->if_flags & IFF_PROMISC) {
5571 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5573 /* Enable promiscuous mode. */
5574 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5575 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5576 } else if (ifp->if_flags & IFF_ALLMULTI) {
5577 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5579 /* Enable all multicast addresses. */
5580 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5581 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5584 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5586 /* Accept one or more multicast(s). */
5587 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5589 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5590 if (ifma->ifma_addr->sa_family != AF_LINK)
5593 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5594 ETHER_ADDR_LEN) & 0xFF;
5595 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5598 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5599 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5602 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5605 /* Only make changes if the recive mode has actually changed. */
5606 if (rx_mode != sc->rx_mode) {
5607 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5610 sc->rx_mode = rx_mode;
5611 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5614 /* Disable and clear the exisitng sort before enabling a new sort. */
5615 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5616 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5617 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5621 /****************************************************************************/
5622 /* Called periodically to updates statistics from the controllers */
5623 /* statistics block. */
5627 /****************************************************************************/
5629 bce_stats_update(struct bce_softc *sc)
5631 struct ifnet *ifp = &sc->arpcom.ac_if;
5632 struct statistics_block *stats = sc->stats_block;
5634 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5636 ASSERT_SERIALIZED(ifp->if_serializer);
5639 * Certain controllers don't report carrier sense errors correctly.
5640 * See errata E11_5708CA0_1165.
5642 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5643 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5645 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5649 * Update the sysctl statistics from the hardware statistics.
5651 sc->stat_IfHCInOctets =
5652 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5653 (uint64_t)stats->stat_IfHCInOctets_lo;
5655 sc->stat_IfHCInBadOctets =
5656 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5657 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5659 sc->stat_IfHCOutOctets =
5660 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5661 (uint64_t)stats->stat_IfHCOutOctets_lo;
5663 sc->stat_IfHCOutBadOctets =
5664 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5665 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5667 sc->stat_IfHCInUcastPkts =
5668 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5669 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5671 sc->stat_IfHCInMulticastPkts =
5672 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5673 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5675 sc->stat_IfHCInBroadcastPkts =
5676 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5677 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5679 sc->stat_IfHCOutUcastPkts =
5680 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5681 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5683 sc->stat_IfHCOutMulticastPkts =
5684 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5685 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5687 sc->stat_IfHCOutBroadcastPkts =
5688 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5689 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5691 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5692 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5694 sc->stat_Dot3StatsCarrierSenseErrors =
5695 stats->stat_Dot3StatsCarrierSenseErrors;
5697 sc->stat_Dot3StatsFCSErrors =
5698 stats->stat_Dot3StatsFCSErrors;
5700 sc->stat_Dot3StatsAlignmentErrors =
5701 stats->stat_Dot3StatsAlignmentErrors;
5703 sc->stat_Dot3StatsSingleCollisionFrames =
5704 stats->stat_Dot3StatsSingleCollisionFrames;
5706 sc->stat_Dot3StatsMultipleCollisionFrames =
5707 stats->stat_Dot3StatsMultipleCollisionFrames;
5709 sc->stat_Dot3StatsDeferredTransmissions =
5710 stats->stat_Dot3StatsDeferredTransmissions;
5712 sc->stat_Dot3StatsExcessiveCollisions =
5713 stats->stat_Dot3StatsExcessiveCollisions;
5715 sc->stat_Dot3StatsLateCollisions =
5716 stats->stat_Dot3StatsLateCollisions;
5718 sc->stat_EtherStatsCollisions =
5719 stats->stat_EtherStatsCollisions;
5721 sc->stat_EtherStatsFragments =
5722 stats->stat_EtherStatsFragments;
5724 sc->stat_EtherStatsJabbers =
5725 stats->stat_EtherStatsJabbers;
5727 sc->stat_EtherStatsUndersizePkts =
5728 stats->stat_EtherStatsUndersizePkts;
5730 sc->stat_EtherStatsOverrsizePkts =
5731 stats->stat_EtherStatsOverrsizePkts;
5733 sc->stat_EtherStatsPktsRx64Octets =
5734 stats->stat_EtherStatsPktsRx64Octets;
5736 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5737 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5739 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5740 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5742 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5743 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5745 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5746 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5748 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5749 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5751 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5752 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5754 sc->stat_EtherStatsPktsTx64Octets =
5755 stats->stat_EtherStatsPktsTx64Octets;
5757 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5758 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5760 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5761 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5763 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5764 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5766 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5767 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5769 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5770 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5772 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5773 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5775 sc->stat_XonPauseFramesReceived =
5776 stats->stat_XonPauseFramesReceived;
5778 sc->stat_XoffPauseFramesReceived =
5779 stats->stat_XoffPauseFramesReceived;
5781 sc->stat_OutXonSent =
5782 stats->stat_OutXonSent;
5784 sc->stat_OutXoffSent =
5785 stats->stat_OutXoffSent;
5787 sc->stat_FlowControlDone =
5788 stats->stat_FlowControlDone;
5790 sc->stat_MacControlFramesReceived =
5791 stats->stat_MacControlFramesReceived;
5793 sc->stat_XoffStateEntered =
5794 stats->stat_XoffStateEntered;
5796 sc->stat_IfInFramesL2FilterDiscards =
5797 stats->stat_IfInFramesL2FilterDiscards;
5799 sc->stat_IfInRuleCheckerDiscards =
5800 stats->stat_IfInRuleCheckerDiscards;
5802 sc->stat_IfInFTQDiscards =
5803 stats->stat_IfInFTQDiscards;
5805 sc->stat_IfInMBUFDiscards =
5806 stats->stat_IfInMBUFDiscards;
5808 sc->stat_IfInRuleCheckerP4Hit =
5809 stats->stat_IfInRuleCheckerP4Hit;
5811 sc->stat_CatchupInRuleCheckerDiscards =
5812 stats->stat_CatchupInRuleCheckerDiscards;
5814 sc->stat_CatchupInFTQDiscards =
5815 stats->stat_CatchupInFTQDiscards;
5817 sc->stat_CatchupInMBUFDiscards =
5818 stats->stat_CatchupInMBUFDiscards;
5820 sc->stat_CatchupInRuleCheckerP4Hit =
5821 stats->stat_CatchupInRuleCheckerP4Hit;
5823 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5826 * Update the interface statistics from the
5827 * hardware statistics.
5829 ifp->if_collisions = (u_long)sc->stat_EtherStatsCollisions;
5831 ifp->if_ierrors = (u_long)sc->stat_EtherStatsUndersizePkts +
5832 (u_long)sc->stat_EtherStatsOverrsizePkts +
5833 (u_long)sc->stat_IfInMBUFDiscards +
5834 (u_long)sc->stat_Dot3StatsAlignmentErrors +
5835 (u_long)sc->stat_Dot3StatsFCSErrors +
5836 (u_long)sc->stat_IfInRuleCheckerDiscards +
5837 (u_long)sc->stat_IfInFTQDiscards +
5838 (u_long)sc->com_no_buffers;
5841 (u_long)sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5842 (u_long)sc->stat_Dot3StatsExcessiveCollisions +
5843 (u_long)sc->stat_Dot3StatsLateCollisions;
5845 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5849 /****************************************************************************/
5850 /* Periodic function to notify the bootcode that the driver is still */
5855 /****************************************************************************/
5857 bce_pulse(void *xsc)
5859 struct bce_softc *sc = xsc;
5860 struct ifnet *ifp = &sc->arpcom.ac_if;
5863 lwkt_serialize_enter(ifp->if_serializer);
5865 /* Tell the firmware that the driver is still running. */
5866 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5867 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
5869 /* Update the bootcode condition. */
5870 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
5872 /* Report whether the bootcode still knows the driver is running. */
5873 if (!sc->bce_drv_cardiac_arrest) {
5874 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
5875 sc->bce_drv_cardiac_arrest = 1;
5876 if_printf(ifp, "Bootcode lost the driver pulse! "
5877 "(bc_state = 0x%08X)\n", sc->bc_state);
5881 * Not supported by all bootcode versions.
5882 * (v5.0.11+ and v5.2.1+) Older bootcode
5883 * will require the driver to reset the
5884 * controller to clear this condition.
5886 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
5887 sc->bce_drv_cardiac_arrest = 0;
5888 if_printf(ifp, "Bootcode found the driver pulse! "
5889 "(bc_state = 0x%08X)\n", sc->bc_state);
5893 /* Schedule the next pulse. */
5894 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
5896 lwkt_serialize_exit(ifp->if_serializer);
5900 /****************************************************************************/
5901 /* Periodic function to perform maintenance tasks. */
5905 /****************************************************************************/
5907 bce_tick_serialized(struct bce_softc *sc)
5909 struct ifnet *ifp = &sc->arpcom.ac_if;
5910 struct mii_data *mii;
5912 ASSERT_SERIALIZED(ifp->if_serializer);
5914 /* Update the statistics from the hardware statistics block. */
5915 bce_stats_update(sc);
5917 /* Schedule the next tick. */
5918 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
5920 /* If link is up already up then we're done. */
5924 mii = device_get_softc(sc->bce_miibus);
5927 /* Check if the link has come up. */
5928 if ((mii->mii_media_status & IFM_ACTIVE) &&
5929 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5931 /* Now that link is up, handle any outstanding TX traffic. */
5932 if (!ifq_is_empty(&ifp->if_snd))
5941 struct bce_softc *sc = xsc;
5942 struct ifnet *ifp = &sc->arpcom.ac_if;
5944 lwkt_serialize_enter(ifp->if_serializer);
5945 bce_tick_serialized(sc);
5946 lwkt_serialize_exit(ifp->if_serializer);
5951 /****************************************************************************/
5952 /* Allows the driver state to be dumped through the sysctl interface. */
5955 /* 0 for success, positive value for failure. */
5956 /****************************************************************************/
5958 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5962 struct bce_softc *sc;
5965 error = sysctl_handle_int(oidp, &result, 0, req);
5967 if (error || !req->newptr)
5971 sc = (struct bce_softc *)arg1;
5972 bce_dump_driver_state(sc);
5979 /****************************************************************************/
5980 /* Allows the hardware state to be dumped through the sysctl interface. */
5983 /* 0 for success, positive value for failure. */
5984 /****************************************************************************/
5986 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5990 struct bce_softc *sc;
5993 error = sysctl_handle_int(oidp, &result, 0, req);
5995 if (error || !req->newptr)
5999 sc = (struct bce_softc *)arg1;
6000 bce_dump_hw_state(sc);
6007 /****************************************************************************/
6008 /* Provides a sysctl interface to allows dumping the RX chain. */
6011 /* 0 for success, positive value for failure. */
6012 /****************************************************************************/
6014 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
6018 struct bce_softc *sc;
6021 error = sysctl_handle_int(oidp, &result, 0, req);
6023 if (error || !req->newptr)
6027 sc = (struct bce_softc *)arg1;
6028 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
6035 /****************************************************************************/
6036 /* Provides a sysctl interface to allows dumping the TX chain. */
6039 /* 0 for success, positive value for failure. */
6040 /****************************************************************************/
6042 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
6046 struct bce_softc *sc;
6049 error = sysctl_handle_int(oidp, &result, 0, req);
6051 if (error || !req->newptr)
6055 sc = (struct bce_softc *)arg1;
6056 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
6063 /****************************************************************************/
6064 /* Provides a sysctl interface to allow reading arbitrary registers in the */
6065 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6068 /* 0 for success, positive value for failure. */
6069 /****************************************************************************/
6071 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
6073 struct bce_softc *sc;
6075 uint32_t val, result;
6078 error = sysctl_handle_int(oidp, &result, 0, req);
6079 if (error || (req->newptr == NULL))
6082 /* Make sure the register is accessible. */
6083 if (result < 0x8000) {
6084 sc = (struct bce_softc *)arg1;
6085 val = REG_RD(sc, result);
6086 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6088 } else if (result < 0x0280000) {
6089 sc = (struct bce_softc *)arg1;
6090 val = REG_RD_IND(sc, result);
6091 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6098 /****************************************************************************/
6099 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
6100 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6103 /* 0 for success, positive value for failure. */
6104 /****************************************************************************/
6106 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
6108 struct bce_softc *sc;
6114 error = sysctl_handle_int(oidp, &result, 0, req);
6115 if (error || (req->newptr == NULL))
6118 /* Make sure the register is accessible. */
6119 if (result < 0x20) {
6120 sc = (struct bce_softc *)arg1;
6122 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
6123 if_printf(&sc->arpcom.ac_if,
6124 "phy 0x%02X = 0x%04X\n", result, val);
6130 /****************************************************************************/
6131 /* Provides a sysctl interface to forcing the driver to dump state and */
6132 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6135 /* 0 for success, positive value for failure. */
6136 /****************************************************************************/
6138 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
6142 struct bce_softc *sc;
6145 error = sysctl_handle_int(oidp, &result, 0, req);
6147 if (error || !req->newptr)
6151 sc = (struct bce_softc *)arg1;
6160 /****************************************************************************/
6161 /* Adds any sysctl parameters for tuning or debugging purposes. */
6164 /* 0 for success, positive value for failure. */
6165 /****************************************************************************/
6167 bce_add_sysctls(struct bce_softc *sc)
6169 struct sysctl_ctx_list *ctx;
6170 struct sysctl_oid_list *children;
6172 sysctl_ctx_init(&sc->bce_sysctl_ctx);
6173 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
6174 SYSCTL_STATIC_CHILDREN(_hw),
6176 device_get_nameunit(sc->bce_dev),
6178 if (sc->bce_sysctl_tree == NULL) {
6179 device_printf(sc->bce_dev, "can't add sysctl node\n");
6183 ctx = &sc->bce_sysctl_ctx;
6184 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
6186 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
6187 CTLTYPE_INT | CTLFLAG_RW,
6188 sc, 0, bce_sysctl_tx_bds_int, "I",
6189 "Send max coalesced BD count during interrupt");
6190 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
6191 CTLTYPE_INT | CTLFLAG_RW,
6192 sc, 0, bce_sysctl_tx_bds, "I",
6193 "Send max coalesced BD count");
6194 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
6195 CTLTYPE_INT | CTLFLAG_RW,
6196 sc, 0, bce_sysctl_tx_ticks_int, "I",
6197 "Send coalescing ticks during interrupt");
6198 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
6199 CTLTYPE_INT | CTLFLAG_RW,
6200 sc, 0, bce_sysctl_tx_ticks, "I",
6201 "Send coalescing ticks");
6203 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
6204 CTLTYPE_INT | CTLFLAG_RW,
6205 sc, 0, bce_sysctl_rx_bds_int, "I",
6206 "Receive max coalesced BD count during interrupt");
6207 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
6208 CTLTYPE_INT | CTLFLAG_RW,
6209 sc, 0, bce_sysctl_rx_bds, "I",
6210 "Receive max coalesced BD count");
6211 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
6212 CTLTYPE_INT | CTLFLAG_RW,
6213 sc, 0, bce_sysctl_rx_ticks_int, "I",
6214 "Receive coalescing ticks during interrupt");
6215 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
6216 CTLTYPE_INT | CTLFLAG_RW,
6217 sc, 0, bce_sysctl_rx_ticks, "I",
6218 "Receive coalescing ticks");
6221 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6223 CTLFLAG_RD, &sc->rx_low_watermark,
6224 0, "Lowest level of free rx_bd's");
6226 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6228 CTLFLAG_RD, &sc->rx_empty_count,
6229 0, "Number of times the RX chain was empty");
6231 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6233 CTLFLAG_RD, &sc->tx_hi_watermark,
6234 0, "Highest level of used tx_bd's");
6236 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6238 CTLFLAG_RD, &sc->tx_full_count,
6239 0, "Number of times the TX chain was full");
6241 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6242 "l2fhdr_status_errors",
6243 CTLFLAG_RD, &sc->l2fhdr_status_errors,
6244 0, "l2_fhdr status errors");
6246 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6247 "unexpected_attentions",
6248 CTLFLAG_RD, &sc->unexpected_attentions,
6249 0, "unexpected attentions");
6251 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6252 "lost_status_block_updates",
6253 CTLFLAG_RD, &sc->lost_status_block_updates,
6254 0, "lost status block updates");
6256 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6257 "mbuf_alloc_failed",
6258 CTLFLAG_RD, &sc->mbuf_alloc_failed,
6259 0, "mbuf cluster allocation failures");
6262 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6263 "stat_IfHCInOctets",
6264 CTLFLAG_RD, &sc->stat_IfHCInOctets,
6267 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6268 "stat_IfHCInBadOctets",
6269 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
6270 "Bad bytes received");
6272 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6273 "stat_IfHCOutOctets",
6274 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
6277 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6278 "stat_IfHCOutBadOctets",
6279 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
6282 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6283 "stat_IfHCInUcastPkts",
6284 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
6285 "Unicast packets received");
6287 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6288 "stat_IfHCInMulticastPkts",
6289 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
6290 "Multicast packets received");
6292 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6293 "stat_IfHCInBroadcastPkts",
6294 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
6295 "Broadcast packets received");
6297 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6298 "stat_IfHCOutUcastPkts",
6299 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
6300 "Unicast packets sent");
6302 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6303 "stat_IfHCOutMulticastPkts",
6304 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
6305 "Multicast packets sent");
6307 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6308 "stat_IfHCOutBroadcastPkts",
6309 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
6310 "Broadcast packets sent");
6312 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6313 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
6314 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
6315 0, "Internal MAC transmit errors");
6317 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6318 "stat_Dot3StatsCarrierSenseErrors",
6319 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
6320 0, "Carrier sense errors");
6322 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6323 "stat_Dot3StatsFCSErrors",
6324 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
6325 0, "Frame check sequence errors");
6327 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6328 "stat_Dot3StatsAlignmentErrors",
6329 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
6330 0, "Alignment errors");
6332 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6333 "stat_Dot3StatsSingleCollisionFrames",
6334 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
6335 0, "Single Collision Frames");
6337 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6338 "stat_Dot3StatsMultipleCollisionFrames",
6339 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
6340 0, "Multiple Collision Frames");
6342 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6343 "stat_Dot3StatsDeferredTransmissions",
6344 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
6345 0, "Deferred Transmissions");
6347 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6348 "stat_Dot3StatsExcessiveCollisions",
6349 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
6350 0, "Excessive Collisions");
6352 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6353 "stat_Dot3StatsLateCollisions",
6354 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
6355 0, "Late Collisions");
6357 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6358 "stat_EtherStatsCollisions",
6359 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
6362 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6363 "stat_EtherStatsFragments",
6364 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
6367 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6368 "stat_EtherStatsJabbers",
6369 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
6372 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6373 "stat_EtherStatsUndersizePkts",
6374 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
6375 0, "Undersize packets");
6377 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6378 "stat_EtherStatsOverrsizePkts",
6379 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
6380 0, "stat_EtherStatsOverrsizePkts");
6382 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6383 "stat_EtherStatsPktsRx64Octets",
6384 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
6385 0, "Bytes received in 64 byte packets");
6387 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6388 "stat_EtherStatsPktsRx65Octetsto127Octets",
6389 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
6390 0, "Bytes received in 65 to 127 byte packets");
6392 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6393 "stat_EtherStatsPktsRx128Octetsto255Octets",
6394 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
6395 0, "Bytes received in 128 to 255 byte packets");
6397 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6398 "stat_EtherStatsPktsRx256Octetsto511Octets",
6399 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
6400 0, "Bytes received in 256 to 511 byte packets");
6402 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6403 "stat_EtherStatsPktsRx512Octetsto1023Octets",
6404 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
6405 0, "Bytes received in 512 to 1023 byte packets");
6407 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6408 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
6409 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
6410 0, "Bytes received in 1024 t0 1522 byte packets");
6412 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6413 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
6414 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
6415 0, "Bytes received in 1523 to 9022 byte packets");
6417 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6418 "stat_EtherStatsPktsTx64Octets",
6419 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
6420 0, "Bytes sent in 64 byte packets");
6422 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6423 "stat_EtherStatsPktsTx65Octetsto127Octets",
6424 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
6425 0, "Bytes sent in 65 to 127 byte packets");
6427 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6428 "stat_EtherStatsPktsTx128Octetsto255Octets",
6429 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
6430 0, "Bytes sent in 128 to 255 byte packets");
6432 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6433 "stat_EtherStatsPktsTx256Octetsto511Octets",
6434 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
6435 0, "Bytes sent in 256 to 511 byte packets");
6437 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6438 "stat_EtherStatsPktsTx512Octetsto1023Octets",
6439 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
6440 0, "Bytes sent in 512 to 1023 byte packets");
6442 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6443 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
6444 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
6445 0, "Bytes sent in 1024 to 1522 byte packets");
6447 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6448 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
6449 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
6450 0, "Bytes sent in 1523 to 9022 byte packets");
6452 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6453 "stat_XonPauseFramesReceived",
6454 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
6455 0, "XON pause frames receved");
6457 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6458 "stat_XoffPauseFramesReceived",
6459 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
6460 0, "XOFF pause frames received");
6462 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6464 CTLFLAG_RD, &sc->stat_OutXonSent,
6465 0, "XON pause frames sent");
6467 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6469 CTLFLAG_RD, &sc->stat_OutXoffSent,
6470 0, "XOFF pause frames sent");
6472 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6473 "stat_FlowControlDone",
6474 CTLFLAG_RD, &sc->stat_FlowControlDone,
6475 0, "Flow control done");
6477 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6478 "stat_MacControlFramesReceived",
6479 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
6480 0, "MAC control frames received");
6482 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6483 "stat_XoffStateEntered",
6484 CTLFLAG_RD, &sc->stat_XoffStateEntered,
6485 0, "XOFF state entered");
6487 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6488 "stat_IfInFramesL2FilterDiscards",
6489 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
6490 0, "Received L2 packets discarded");
6492 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6493 "stat_IfInRuleCheckerDiscards",
6494 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
6495 0, "Received packets discarded by rule");
6497 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6498 "stat_IfInFTQDiscards",
6499 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
6500 0, "Received packet FTQ discards");
6502 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6503 "stat_IfInMBUFDiscards",
6504 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
6505 0, "Received packets discarded due to lack of controller buffer memory");
6507 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6508 "stat_IfInRuleCheckerP4Hit",
6509 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6510 0, "Received packets rule checker hits");
6512 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6513 "stat_CatchupInRuleCheckerDiscards",
6514 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6515 0, "Received packets discarded in Catchup path");
6517 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6518 "stat_CatchupInFTQDiscards",
6519 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6520 0, "Received packets discarded in FTQ in Catchup path");
6522 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6523 "stat_CatchupInMBUFDiscards",
6524 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6525 0, "Received packets discarded in controller buffer memory in Catchup path");
6527 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6528 "stat_CatchupInRuleCheckerP4Hit",
6529 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6530 0, "Received packets rule checker hits in Catchup path");
6532 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6534 CTLFLAG_RD, &sc->com_no_buffers,
6535 0, "Valid packets received but no RX buffers available");
6538 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6539 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6541 bce_sysctl_driver_state, "I", "Drive state information");
6543 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6544 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6546 bce_sysctl_hw_state, "I", "Hardware state information");
6548 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6549 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6551 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6553 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6554 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
6556 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
6558 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6559 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6561 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6563 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6564 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
6566 bce_sysctl_reg_read, "I", "Register read");
6568 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6569 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
6571 bce_sysctl_phy_read, "I", "PHY register read");
6578 /****************************************************************************/
6579 /* BCE Debug Routines */
6580 /****************************************************************************/
6583 /****************************************************************************/
6584 /* Freezes the controller to allow for a cohesive state dump. */
6588 /****************************************************************************/
6590 bce_freeze_controller(struct bce_softc *sc)
6594 val = REG_RD(sc, BCE_MISC_COMMAND);
6595 val |= BCE_MISC_COMMAND_DISABLE_ALL;
6596 REG_WR(sc, BCE_MISC_COMMAND, val);
6600 /****************************************************************************/
6601 /* Unfreezes the controller after a freeze operation. This may not always */
6602 /* work and the controller will require a reset! */
6606 /****************************************************************************/
6608 bce_unfreeze_controller(struct bce_softc *sc)
6612 val = REG_RD(sc, BCE_MISC_COMMAND);
6613 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6614 REG_WR(sc, BCE_MISC_COMMAND, val);
6618 /****************************************************************************/
6619 /* Prints out information about an mbuf. */
6623 /****************************************************************************/
6625 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6627 struct ifnet *ifp = &sc->arpcom.ac_if;
6628 uint32_t val_hi, val_lo;
6629 struct mbuf *mp = m;
6632 /* Index out of range. */
6633 if_printf(ifp, "mbuf: null pointer\n");
6638 val_hi = BCE_ADDR_HI(mp);
6639 val_lo = BCE_ADDR_LO(mp);
6640 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6641 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6643 if (mp->m_flags & M_EXT)
6645 if (mp->m_flags & M_PKTHDR)
6646 kprintf("M_PKTHDR ");
6647 if (mp->m_flags & M_EOR)
6650 if (mp->m_flags & M_RDONLY)
6651 kprintf("M_RDONLY ");
6654 val_hi = BCE_ADDR_HI(mp->m_data);
6655 val_lo = BCE_ADDR_LO(mp->m_data);
6656 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6658 if (mp->m_flags & M_PKTHDR) {
6659 if_printf(ifp, "- m_pkthdr: flags = ( ");
6660 if (mp->m_flags & M_BCAST)
6661 kprintf("M_BCAST ");
6662 if (mp->m_flags & M_MCAST)
6663 kprintf("M_MCAST ");
6664 if (mp->m_flags & M_FRAG)
6666 if (mp->m_flags & M_FIRSTFRAG)
6667 kprintf("M_FIRSTFRAG ");
6668 if (mp->m_flags & M_LASTFRAG)
6669 kprintf("M_LASTFRAG ");
6671 if (mp->m_flags & M_VLANTAG)
6672 kprintf("M_VLANTAG ");
6675 if (mp->m_flags & M_PROMISC)
6676 kprintf("M_PROMISC ");
6678 kprintf(") csum_flags = ( ");
6679 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6680 kprintf("CSUM_IP ");
6681 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6682 kprintf("CSUM_TCP ");
6683 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6684 kprintf("CSUM_UDP ");
6685 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6686 kprintf("CSUM_IP_FRAGS ");
6687 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6688 kprintf("CSUM_FRAGMENT ");
6690 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6691 kprintf("CSUM_TSO ");
6693 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6694 kprintf("CSUM_IP_CHECKED ");
6695 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6696 kprintf("CSUM_IP_VALID ");
6697 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6698 kprintf("CSUM_DATA_VALID ");
6702 if (mp->m_flags & M_EXT) {
6703 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6704 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6705 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6707 val_hi, val_lo, mp->m_ext.ext_size);
6714 /****************************************************************************/
6715 /* Prints out the mbufs in the TX mbuf chain. */
6719 /****************************************************************************/
6721 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6723 struct ifnet *ifp = &sc->arpcom.ac_if;
6727 "----------------------------"
6729 "----------------------------\n");
6731 for (i = 0; i < count; i++) {
6732 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6733 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6734 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6738 "----------------------------"
6740 "----------------------------\n");
6744 /****************************************************************************/
6745 /* Prints out the mbufs in the RX mbuf chain. */
6749 /****************************************************************************/
6751 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6753 struct ifnet *ifp = &sc->arpcom.ac_if;
6757 "----------------------------"
6759 "----------------------------\n");
6761 for (i = 0; i < count; i++) {
6762 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6763 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6764 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6768 "----------------------------"
6770 "----------------------------\n");
6774 /****************************************************************************/
6775 /* Prints out a tx_bd structure. */
6779 /****************************************************************************/
6781 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6783 struct ifnet *ifp = &sc->arpcom.ac_if;
6785 if (idx > MAX_TX_BD) {
6786 /* Index out of range. */
6787 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6788 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6789 /* TX Chain page pointer. */
6790 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6791 "chain page pointer\n",
6792 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6794 /* Normal tx_bd entry. */
6795 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6797 "vlan tag= 0x%04X, flags = 0x%04X (",
6798 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6799 txbd->tx_bd_mss_nbytes,
6800 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6802 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6803 kprintf(" CONN_FAULT");
6805 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6806 kprintf(" TCP_UDP_CKSUM");
6808 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6809 kprintf(" IP_CKSUM");
6811 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6814 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6815 kprintf(" COAL_NOW");
6817 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6818 kprintf(" DONT_GEN_CRC");
6820 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6823 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6826 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6829 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6830 kprintf(" OPTION_WORD");
6832 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6835 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6843 /****************************************************************************/
6844 /* Prints out a rx_bd structure. */
6848 /****************************************************************************/
6850 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6852 struct ifnet *ifp = &sc->arpcom.ac_if;
6854 if (idx > MAX_RX_BD) {
6855 /* Index out of range. */
6856 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6857 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6858 /* TX Chain page pointer. */
6859 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6860 "chain page pointer\n",
6861 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6863 /* Normal tx_bd entry. */
6864 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6865 "nbytes = 0x%08X, flags = 0x%08X\n",
6866 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6867 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6872 /****************************************************************************/
6873 /* Prints out a l2_fhdr structure. */
6877 /****************************************************************************/
6879 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6881 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6882 "pkt_len = 0x%04X, vlan = 0x%04x, "
6883 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6884 idx, l2fhdr->l2_fhdr_status,
6885 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6886 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6890 /****************************************************************************/
6891 /* Prints out the tx chain. */
6895 /****************************************************************************/
6897 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6899 struct ifnet *ifp = &sc->arpcom.ac_if;
6902 /* First some info about the tx_bd chain structure. */
6904 "----------------------------"
6906 "----------------------------\n");
6908 if_printf(ifp, "page size = 0x%08X, "
6909 "tx chain pages = 0x%08X\n",
6910 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6912 if_printf(ifp, "tx_bd per page = 0x%08X, "
6913 "usable tx_bd per page = 0x%08X\n",
6914 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6915 (uint32_t)USABLE_TX_BD_PER_PAGE);
6917 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6920 "----------------------------"
6922 "----------------------------\n");
6924 /* Now print out the tx_bd's themselves. */
6925 for (i = 0; i < count; i++) {
6928 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6929 bce_dump_txbd(sc, tx_prod, txbd);
6930 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6934 "----------------------------"
6936 "----------------------------\n");
6940 /****************************************************************************/
6941 /* Prints out the rx chain. */
6945 /****************************************************************************/
6947 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6949 struct ifnet *ifp = &sc->arpcom.ac_if;
6952 /* First some info about the tx_bd chain structure. */
6954 "----------------------------"
6956 "----------------------------\n");
6958 if_printf(ifp, "page size = 0x%08X, "
6959 "rx chain pages = 0x%08X\n",
6960 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6962 if_printf(ifp, "rx_bd per page = 0x%08X, "
6963 "usable rx_bd per page = 0x%08X\n",
6964 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6965 (uint32_t)USABLE_RX_BD_PER_PAGE);
6967 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6970 "----------------------------"
6972 "----------------------------\n");
6974 /* Now print out the rx_bd's themselves. */
6975 for (i = 0; i < count; i++) {
6978 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6979 bce_dump_rxbd(sc, rx_prod, rxbd);
6980 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6984 "----------------------------"
6986 "----------------------------\n");
6990 /****************************************************************************/
6991 /* Prints out the status block from host memory. */
6995 /****************************************************************************/
6997 bce_dump_status_block(struct bce_softc *sc)
6999 struct status_block *sblk = sc->status_block;
7000 struct ifnet *ifp = &sc->arpcom.ac_if;
7003 "----------------------------"
7005 "----------------------------\n");
7007 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
7009 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
7010 sblk->status_attn_bits_ack);
7012 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
7013 sblk->status_rx_quick_consumer_index0,
7014 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
7016 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
7017 sblk->status_tx_quick_consumer_index0,
7018 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
7020 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
7022 /* Theses indices are not used for normal L2 drivers. */
7023 if (sblk->status_rx_quick_consumer_index1) {
7024 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
7025 sblk->status_rx_quick_consumer_index1,
7026 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
7029 if (sblk->status_tx_quick_consumer_index1) {
7030 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
7031 sblk->status_tx_quick_consumer_index1,
7032 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
7035 if (sblk->status_rx_quick_consumer_index2) {
7036 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
7037 sblk->status_rx_quick_consumer_index2,
7038 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
7041 if (sblk->status_tx_quick_consumer_index2) {
7042 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
7043 sblk->status_tx_quick_consumer_index2,
7044 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
7047 if (sblk->status_rx_quick_consumer_index3) {
7048 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
7049 sblk->status_rx_quick_consumer_index3,
7050 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
7053 if (sblk->status_tx_quick_consumer_index3) {
7054 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
7055 sblk->status_tx_quick_consumer_index3,
7056 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
7059 if (sblk->status_rx_quick_consumer_index4 ||
7060 sblk->status_rx_quick_consumer_index5) {
7061 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
7062 sblk->status_rx_quick_consumer_index4,
7063 sblk->status_rx_quick_consumer_index5);
7066 if (sblk->status_rx_quick_consumer_index6 ||
7067 sblk->status_rx_quick_consumer_index7) {
7068 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
7069 sblk->status_rx_quick_consumer_index6,
7070 sblk->status_rx_quick_consumer_index7);
7073 if (sblk->status_rx_quick_consumer_index8 ||
7074 sblk->status_rx_quick_consumer_index9) {
7075 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
7076 sblk->status_rx_quick_consumer_index8,
7077 sblk->status_rx_quick_consumer_index9);
7080 if (sblk->status_rx_quick_consumer_index10 ||
7081 sblk->status_rx_quick_consumer_index11) {
7082 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
7083 sblk->status_rx_quick_consumer_index10,
7084 sblk->status_rx_quick_consumer_index11);
7087 if (sblk->status_rx_quick_consumer_index12 ||
7088 sblk->status_rx_quick_consumer_index13) {
7089 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
7090 sblk->status_rx_quick_consumer_index12,
7091 sblk->status_rx_quick_consumer_index13);
7094 if (sblk->status_rx_quick_consumer_index14 ||
7095 sblk->status_rx_quick_consumer_index15) {
7096 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
7097 sblk->status_rx_quick_consumer_index14,
7098 sblk->status_rx_quick_consumer_index15);
7101 if (sblk->status_completion_producer_index ||
7102 sblk->status_cmd_consumer_index) {
7103 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
7104 sblk->status_completion_producer_index,
7105 sblk->status_cmd_consumer_index);
7109 "----------------------------"
7111 "----------------------------\n");
7115 /****************************************************************************/
7116 /* Prints out the statistics block. */
7120 /****************************************************************************/
7122 bce_dump_stats_block(struct bce_softc *sc)
7124 struct statistics_block *sblk = sc->stats_block;
7125 struct ifnet *ifp = &sc->arpcom.ac_if;
7129 " Stats Block (All Stats Not Shown Are 0) "
7130 "---------------\n");
7132 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
7133 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
7134 sblk->stat_IfHCInOctets_hi,
7135 sblk->stat_IfHCInOctets_lo);
7138 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
7139 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
7140 sblk->stat_IfHCInBadOctets_hi,
7141 sblk->stat_IfHCInBadOctets_lo);
7144 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
7145 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
7146 sblk->stat_IfHCOutOctets_hi,
7147 sblk->stat_IfHCOutOctets_lo);
7150 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
7151 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
7152 sblk->stat_IfHCOutBadOctets_hi,
7153 sblk->stat_IfHCOutBadOctets_lo);
7156 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
7157 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
7158 sblk->stat_IfHCInUcastPkts_hi,
7159 sblk->stat_IfHCInUcastPkts_lo);
7162 if (sblk->stat_IfHCInBroadcastPkts_hi ||
7163 sblk->stat_IfHCInBroadcastPkts_lo) {
7164 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
7165 sblk->stat_IfHCInBroadcastPkts_hi,
7166 sblk->stat_IfHCInBroadcastPkts_lo);
7169 if (sblk->stat_IfHCInMulticastPkts_hi ||
7170 sblk->stat_IfHCInMulticastPkts_lo) {
7171 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
7172 sblk->stat_IfHCInMulticastPkts_hi,
7173 sblk->stat_IfHCInMulticastPkts_lo);
7176 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
7177 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
7178 sblk->stat_IfHCOutUcastPkts_hi,
7179 sblk->stat_IfHCOutUcastPkts_lo);
7182 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
7183 sblk->stat_IfHCOutBroadcastPkts_lo) {
7184 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
7185 sblk->stat_IfHCOutBroadcastPkts_hi,
7186 sblk->stat_IfHCOutBroadcastPkts_lo);
7189 if (sblk->stat_IfHCOutMulticastPkts_hi ||
7190 sblk->stat_IfHCOutMulticastPkts_lo) {
7191 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
7192 sblk->stat_IfHCOutMulticastPkts_hi,
7193 sblk->stat_IfHCOutMulticastPkts_lo);
7196 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
7197 if_printf(ifp, " 0x%08X : "
7198 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
7199 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
7202 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
7203 if_printf(ifp, " 0x%08X : "
7204 "Dot3StatsCarrierSenseErrors\n",
7205 sblk->stat_Dot3StatsCarrierSenseErrors);
7208 if (sblk->stat_Dot3StatsFCSErrors) {
7209 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
7210 sblk->stat_Dot3StatsFCSErrors);
7213 if (sblk->stat_Dot3StatsAlignmentErrors) {
7214 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
7215 sblk->stat_Dot3StatsAlignmentErrors);
7218 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
7219 if_printf(ifp, " 0x%08X : "
7220 "Dot3StatsSingleCollisionFrames\n",
7221 sblk->stat_Dot3StatsSingleCollisionFrames);
7224 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
7225 if_printf(ifp, " 0x%08X : "
7226 "Dot3StatsMultipleCollisionFrames\n",
7227 sblk->stat_Dot3StatsMultipleCollisionFrames);
7230 if (sblk->stat_Dot3StatsDeferredTransmissions) {
7231 if_printf(ifp, " 0x%08X : "
7232 "Dot3StatsDeferredTransmissions\n",
7233 sblk->stat_Dot3StatsDeferredTransmissions);
7236 if (sblk->stat_Dot3StatsExcessiveCollisions) {
7237 if_printf(ifp, " 0x%08X : "
7238 "Dot3StatsExcessiveCollisions\n",
7239 sblk->stat_Dot3StatsExcessiveCollisions);
7242 if (sblk->stat_Dot3StatsLateCollisions) {
7243 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
7244 sblk->stat_Dot3StatsLateCollisions);
7247 if (sblk->stat_EtherStatsCollisions) {
7248 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
7249 sblk->stat_EtherStatsCollisions);
7252 if (sblk->stat_EtherStatsFragments) {
7253 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
7254 sblk->stat_EtherStatsFragments);
7257 if (sblk->stat_EtherStatsJabbers) {
7258 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
7259 sblk->stat_EtherStatsJabbers);
7262 if (sblk->stat_EtherStatsUndersizePkts) {
7263 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
7264 sblk->stat_EtherStatsUndersizePkts);
7267 if (sblk->stat_EtherStatsOverrsizePkts) {
7268 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
7269 sblk->stat_EtherStatsOverrsizePkts);
7272 if (sblk->stat_EtherStatsPktsRx64Octets) {
7273 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
7274 sblk->stat_EtherStatsPktsRx64Octets);
7277 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
7278 if_printf(ifp, " 0x%08X : "
7279 "EtherStatsPktsRx65Octetsto127Octets\n",
7280 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
7283 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
7284 if_printf(ifp, " 0x%08X : "
7285 "EtherStatsPktsRx128Octetsto255Octets\n",
7286 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
7289 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
7290 if_printf(ifp, " 0x%08X : "
7291 "EtherStatsPktsRx256Octetsto511Octets\n",
7292 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
7295 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
7296 if_printf(ifp, " 0x%08X : "
7297 "EtherStatsPktsRx512Octetsto1023Octets\n",
7298 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
7301 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
7302 if_printf(ifp, " 0x%08X : "
7303 "EtherStatsPktsRx1024Octetsto1522Octets\n",
7304 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
7307 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
7308 if_printf(ifp, " 0x%08X : "
7309 "EtherStatsPktsRx1523Octetsto9022Octets\n",
7310 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
7313 if (sblk->stat_EtherStatsPktsTx64Octets) {
7314 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
7315 sblk->stat_EtherStatsPktsTx64Octets);
7318 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
7319 if_printf(ifp, " 0x%08X : "
7320 "EtherStatsPktsTx65Octetsto127Octets\n",
7321 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
7324 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
7325 if_printf(ifp, " 0x%08X : "
7326 "EtherStatsPktsTx128Octetsto255Octets\n",
7327 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
7330 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
7331 if_printf(ifp, " 0x%08X : "
7332 "EtherStatsPktsTx256Octetsto511Octets\n",
7333 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
7336 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
7337 if_printf(ifp, " 0x%08X : "
7338 "EtherStatsPktsTx512Octetsto1023Octets\n",
7339 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
7342 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
7343 if_printf(ifp, " 0x%08X : "
7344 "EtherStatsPktsTx1024Octetsto1522Octets\n",
7345 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
7348 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
7349 if_printf(ifp, " 0x%08X : "
7350 "EtherStatsPktsTx1523Octetsto9022Octets\n",
7351 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
7354 if (sblk->stat_XonPauseFramesReceived) {
7355 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
7356 sblk->stat_XonPauseFramesReceived);
7359 if (sblk->stat_XoffPauseFramesReceived) {
7360 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
7361 sblk->stat_XoffPauseFramesReceived);
7364 if (sblk->stat_OutXonSent) {
7365 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7366 sblk->stat_OutXonSent);
7369 if (sblk->stat_OutXoffSent) {
7370 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7371 sblk->stat_OutXoffSent);
7374 if (sblk->stat_FlowControlDone) {
7375 if_printf(ifp, " 0x%08X : FlowControlDone\n",
7376 sblk->stat_FlowControlDone);
7379 if (sblk->stat_MacControlFramesReceived) {
7380 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
7381 sblk->stat_MacControlFramesReceived);
7384 if (sblk->stat_XoffStateEntered) {
7385 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
7386 sblk->stat_XoffStateEntered);
7389 if (sblk->stat_IfInFramesL2FilterDiscards) {
7390 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
7393 if (sblk->stat_IfInRuleCheckerDiscards) {
7394 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
7395 sblk->stat_IfInRuleCheckerDiscards);
7398 if (sblk->stat_IfInFTQDiscards) {
7399 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
7400 sblk->stat_IfInFTQDiscards);
7403 if (sblk->stat_IfInMBUFDiscards) {
7404 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
7405 sblk->stat_IfInMBUFDiscards);
7408 if (sblk->stat_IfInRuleCheckerP4Hit) {
7409 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
7410 sblk->stat_IfInRuleCheckerP4Hit);
7413 if (sblk->stat_CatchupInRuleCheckerDiscards) {
7414 if_printf(ifp, " 0x%08X : "
7415 "CatchupInRuleCheckerDiscards\n",
7416 sblk->stat_CatchupInRuleCheckerDiscards);
7419 if (sblk->stat_CatchupInFTQDiscards) {
7420 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
7421 sblk->stat_CatchupInFTQDiscards);
7424 if (sblk->stat_CatchupInMBUFDiscards) {
7425 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
7426 sblk->stat_CatchupInMBUFDiscards);
7429 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
7430 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
7431 sblk->stat_CatchupInRuleCheckerP4Hit);
7435 "----------------------------"
7437 "----------------------------\n");
7441 /****************************************************************************/
7442 /* Prints out a summary of the driver state. */
7446 /****************************************************************************/
7448 bce_dump_driver_state(struct bce_softc *sc)
7450 struct ifnet *ifp = &sc->arpcom.ac_if;
7451 uint32_t val_hi, val_lo;
7454 "-----------------------------"
7456 "-----------------------------\n");
7458 val_hi = BCE_ADDR_HI(sc);
7459 val_lo = BCE_ADDR_LO(sc);
7460 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
7461 "virtual address\n", val_hi, val_lo);
7463 val_hi = BCE_ADDR_HI(sc->status_block);
7464 val_lo = BCE_ADDR_LO(sc->status_block);
7465 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
7466 "virtual address\n", val_hi, val_lo);
7468 val_hi = BCE_ADDR_HI(sc->stats_block);
7469 val_lo = BCE_ADDR_LO(sc->stats_block);
7470 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
7471 "virtual address\n", val_hi, val_lo);
7473 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
7474 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
7475 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
7476 "virtual adddress\n", val_hi, val_lo);
7478 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
7479 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
7480 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
7481 "virtual address\n", val_hi, val_lo);
7483 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
7484 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
7485 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
7486 "virtual address\n", val_hi, val_lo);
7488 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
7489 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
7490 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
7491 "virtual address\n", val_hi, val_lo);
7493 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
7494 "h/w intrs\n", sc->interrupts_generated);
7496 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
7497 "rx interrupts handled\n", sc->rx_interrupts);
7499 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
7500 "tx interrupts handled\n", sc->tx_interrupts);
7502 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
7503 "status block index\n", sc->last_status_idx);
7505 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
7506 "tx producer index\n",
7507 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
7509 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
7510 "tx consumer index\n",
7511 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
7513 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
7514 "tx producer bseq index\n", sc->tx_prod_bseq);
7516 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
7517 "rx producer index\n",
7518 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
7520 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
7521 "rx consumer index\n",
7522 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
7524 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
7525 "rx producer bseq index\n", sc->rx_prod_bseq);
7527 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7528 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7530 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
7531 "free rx_bd's\n", sc->free_rx_bd);
7533 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
7534 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
7536 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
7537 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
7539 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7540 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7542 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
7545 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
7546 sc->tx_hi_watermark, sc->max_tx_bd);
7548 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
7549 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
7552 "----------------------------"
7554 "----------------------------\n");
7558 /****************************************************************************/
7559 /* Prints out the hardware state through a summary of important registers, */
7560 /* followed by a complete register dump. */
7564 /****************************************************************************/
7566 bce_dump_hw_state(struct bce_softc *sc)
7568 struct ifnet *ifp = &sc->arpcom.ac_if;
7573 "----------------------------"
7575 "----------------------------\n");
7577 if_printf(ifp, "%s - bootcode version\n", sc->bce_bc_ver);
7579 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
7580 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
7581 val1, BCE_MISC_ENABLE_STATUS_BITS);
7583 val1 = REG_RD(sc, BCE_DMA_STATUS);
7584 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
7586 val1 = REG_RD(sc, BCE_CTX_STATUS);
7587 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
7589 val1 = REG_RD(sc, BCE_EMAC_STATUS);
7590 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
7591 val1, BCE_EMAC_STATUS);
7593 val1 = REG_RD(sc, BCE_RPM_STATUS);
7594 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
7596 val1 = REG_RD(sc, BCE_TBDR_STATUS);
7597 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
7598 val1, BCE_TBDR_STATUS);
7600 val1 = REG_RD(sc, BCE_TDMA_STATUS);
7601 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
7602 val1, BCE_TDMA_STATUS);
7604 val1 = REG_RD(sc, BCE_HC_STATUS);
7605 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7607 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7608 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7609 val1, BCE_TXP_CPU_STATE);
7611 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7612 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7613 val1, BCE_TPAT_CPU_STATE);
7615 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7616 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7617 val1, BCE_RXP_CPU_STATE);
7619 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7620 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7621 val1, BCE_COM_CPU_STATE);
7623 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7624 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7625 val1, BCE_MCP_CPU_STATE);
7627 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7628 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7629 val1, BCE_CP_CPU_STATE);
7632 "----------------------------"
7634 "----------------------------\n");
7637 "----------------------------"
7639 "----------------------------\n");
7641 for (i = 0x400; i < 0x8000; i += 0x10) {
7642 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7644 REG_RD(sc, i + 0x4),
7645 REG_RD(sc, i + 0x8),
7646 REG_RD(sc, i + 0xc));
7650 "----------------------------"
7652 "----------------------------\n");
7656 /****************************************************************************/
7657 /* Prints out the TXP state. */
7661 /****************************************************************************/
7663 bce_dump_txp_state(struct bce_softc *sc)
7665 struct ifnet *ifp = &sc->arpcom.ac_if;
7670 "----------------------------"
7672 "----------------------------\n");
7674 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7675 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7676 val1, BCE_TXP_CPU_MODE);
7678 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7679 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7680 val1, BCE_TXP_CPU_STATE);
7682 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7683 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7684 val1, BCE_TXP_CPU_EVENT_MASK);
7687 "----------------------------"
7689 "----------------------------\n");
7691 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7692 /* Skip the big blank spaces */
7693 if (i < 0x454000 && i > 0x5ffff) {
7694 if_printf(ifp, "0x%04X: "
7695 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7697 REG_RD_IND(sc, i + 0x4),
7698 REG_RD_IND(sc, i + 0x8),
7699 REG_RD_IND(sc, i + 0xc));
7704 "----------------------------"
7706 "----------------------------\n");
7710 /****************************************************************************/
7711 /* Prints out the RXP state. */
7715 /****************************************************************************/
7717 bce_dump_rxp_state(struct bce_softc *sc)
7719 struct ifnet *ifp = &sc->arpcom.ac_if;
7724 "----------------------------"
7726 "----------------------------\n");
7728 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7729 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7730 val1, BCE_RXP_CPU_MODE);
7732 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7733 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7734 val1, BCE_RXP_CPU_STATE);
7736 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7737 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7738 val1, BCE_RXP_CPU_EVENT_MASK);
7741 "----------------------------"
7743 "----------------------------\n");
7745 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7746 /* Skip the big blank sapces */
7747 if (i < 0xc5400 && i > 0xdffff) {
7748 if_printf(ifp, "0x%04X: "
7749 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7751 REG_RD_IND(sc, i + 0x4),
7752 REG_RD_IND(sc, i + 0x8),
7753 REG_RD_IND(sc, i + 0xc));
7758 "----------------------------"
7760 "----------------------------\n");
7764 /****************************************************************************/
7765 /* Prints out the TPAT state. */
7769 /****************************************************************************/
7771 bce_dump_tpat_state(struct bce_softc *sc)
7773 struct ifnet *ifp = &sc->arpcom.ac_if;
7778 "----------------------------"
7780 "----------------------------\n");
7782 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7783 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7784 val1, BCE_TPAT_CPU_MODE);
7786 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7787 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7788 val1, BCE_TPAT_CPU_STATE);
7790 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7791 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7792 val1, BCE_TPAT_CPU_EVENT_MASK);
7795 "----------------------------"
7797 "----------------------------\n");
7799 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7800 /* Skip the big blank spaces */
7801 if (i < 0x854000 && i > 0x9ffff) {
7802 if_printf(ifp, "0x%04X: "
7803 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7805 REG_RD_IND(sc, i + 0x4),
7806 REG_RD_IND(sc, i + 0x8),
7807 REG_RD_IND(sc, i + 0xc));
7812 "----------------------------"
7814 "----------------------------\n");
7818 /****************************************************************************/
7819 /* Prints out the driver state and then enters the debugger. */
7823 /****************************************************************************/
7825 bce_breakpoint(struct bce_softc *sc)
7828 bce_freeze_controller(sc);
7831 bce_dump_driver_state(sc);
7832 bce_dump_status_block(sc);
7833 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7834 bce_dump_hw_state(sc);
7835 bce_dump_txp_state(sc);
7838 bce_unfreeze_controller(sc);
7841 /* Call the debugger. */
7845 #endif /* BCE_DEBUG */
7848 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7850 struct bce_softc *sc = arg1;
7852 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7853 &sc->bce_tx_quick_cons_trip_int,
7854 BCE_COALMASK_TX_BDS_INT);
7858 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7860 struct bce_softc *sc = arg1;
7862 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7863 &sc->bce_tx_quick_cons_trip,
7864 BCE_COALMASK_TX_BDS);
7868 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7870 struct bce_softc *sc = arg1;
7872 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7873 &sc->bce_tx_ticks_int,
7874 BCE_COALMASK_TX_TICKS_INT);
7878 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7880 struct bce_softc *sc = arg1;
7882 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7884 BCE_COALMASK_TX_TICKS);
7888 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7890 struct bce_softc *sc = arg1;
7892 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7893 &sc->bce_rx_quick_cons_trip_int,
7894 BCE_COALMASK_RX_BDS_INT);
7898 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7900 struct bce_softc *sc = arg1;
7902 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7903 &sc->bce_rx_quick_cons_trip,
7904 BCE_COALMASK_RX_BDS);
7908 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7910 struct bce_softc *sc = arg1;
7912 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7913 &sc->bce_rx_ticks_int,
7914 BCE_COALMASK_RX_TICKS_INT);
7918 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7920 struct bce_softc *sc = arg1;
7922 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7924 BCE_COALMASK_RX_TICKS);
7928 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7929 uint32_t coalchg_mask)
7931 struct bce_softc *sc = arg1;
7932 struct ifnet *ifp = &sc->arpcom.ac_if;
7935 lwkt_serialize_enter(ifp->if_serializer);
7938 error = sysctl_handle_int(oidp, &v, 0, req);
7939 if (!error && req->newptr != NULL) {
7944 sc->bce_coalchg_mask |= coalchg_mask;
7948 lwkt_serialize_exit(ifp->if_serializer);
7953 bce_coal_change(struct bce_softc *sc)
7955 struct ifnet *ifp = &sc->arpcom.ac_if;
7957 ASSERT_SERIALIZED(ifp->if_serializer);
7959 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7960 sc->bce_coalchg_mask = 0;
7964 if (sc->bce_coalchg_mask &
7965 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7966 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7967 (sc->bce_tx_quick_cons_trip_int << 16) |
7968 sc->bce_tx_quick_cons_trip);
7970 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7971 sc->bce_tx_quick_cons_trip,
7972 sc->bce_tx_quick_cons_trip_int);
7976 if (sc->bce_coalchg_mask &
7977 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7978 REG_WR(sc, BCE_HC_TX_TICKS,
7979 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7981 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7982 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7986 if (sc->bce_coalchg_mask &
7987 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7988 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7989 (sc->bce_rx_quick_cons_trip_int << 16) |
7990 sc->bce_rx_quick_cons_trip);
7992 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7993 sc->bce_rx_quick_cons_trip,
7994 sc->bce_rx_quick_cons_trip_int);
7998 if (sc->bce_coalchg_mask &
7999 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
8000 REG_WR(sc, BCE_HC_RX_TICKS,
8001 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
8003 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
8004 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
8008 sc->bce_coalchg_mask = 0;