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(void *);
440 static void bce_set_rx_mode(struct bce_softc *);
441 static void bce_stats_update(struct bce_softc *);
442 static void bce_tick(void *);
443 static void bce_tick_serialized(struct bce_softc *);
444 static void bce_pulse(void *);
445 static void bce_add_sysctls(struct bce_softc *);
447 static void bce_coal_change(struct bce_softc *);
448 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
449 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
450 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
451 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
452 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
453 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
454 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
455 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
456 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
457 uint32_t *, uint32_t);
461 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
462 * takes 1023 as the TX ticks limit. However, using 1023 will
463 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
464 * there is _no_ network activity on the NIC.
466 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
467 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
468 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
469 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
470 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
471 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
472 static uint32_t bce_rx_ticks_int = 125; /* bcm: 18 */
473 static uint32_t bce_rx_ticks = 125; /* bcm: 18 */
475 static int bce_msi_enable = 1;
477 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
478 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
479 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
480 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
481 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
482 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
483 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
484 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
485 TUNABLE_INT("hw.bce.msi.enable", &bce_msi_enable);
487 /****************************************************************************/
488 /* DragonFly device dispatch table. */
489 /****************************************************************************/
490 static device_method_t bce_methods[] = {
491 /* Device interface */
492 DEVMETHOD(device_probe, bce_probe),
493 DEVMETHOD(device_attach, bce_attach),
494 DEVMETHOD(device_detach, bce_detach),
495 DEVMETHOD(device_shutdown, bce_shutdown),
498 DEVMETHOD(bus_print_child, bus_generic_print_child),
499 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
502 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
503 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
504 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
509 static driver_t bce_driver = {
512 sizeof(struct bce_softc)
515 static devclass_t bce_devclass;
518 DECLARE_DUMMY_MODULE(if_bce);
519 MODULE_DEPEND(bce, miibus, 1, 1, 1);
520 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
521 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
524 /****************************************************************************/
525 /* Device probe function. */
527 /* Compares the device to the driver's list of supported devices and */
528 /* reports back to the OS whether this is the right driver for the device. */
531 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
532 /****************************************************************************/
534 bce_probe(device_t dev)
537 uint16_t vid, did, svid, sdid;
539 /* Get the data for the device to be probed. */
540 vid = pci_get_vendor(dev);
541 did = pci_get_device(dev);
542 svid = pci_get_subvendor(dev);
543 sdid = pci_get_subdevice(dev);
545 /* Look through the list of known devices for a match. */
546 for (t = bce_devs; t->bce_name != NULL; ++t) {
547 if (vid == t->bce_vid && did == t->bce_did &&
548 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
549 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
550 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
553 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
555 /* Print out the device identity. */
556 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
558 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
560 device_set_desc_copy(dev, descbuf);
561 kfree(descbuf, M_TEMP);
569 /****************************************************************************/
570 /* PCI Capabilities Probe Function. */
572 /* Walks the PCI capabiites list for the device to find what features are */
577 /****************************************************************************/
579 bce_print_adapter_info(struct bce_softc *sc)
581 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
583 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
584 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
587 if (sc->bce_flags & BCE_PCIE_FLAG) {
588 kprintf("Bus (PCIe x%d, ", sc->link_width);
589 switch (sc->link_speed) {
591 kprintf("2.5Gbps); ");
597 kprintf("Unknown link speed); ");
601 kprintf("Bus (PCI%s, %s, %dMHz); ",
602 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
603 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
607 /* Firmware version and device features. */
608 kprintf("B/C (%s)", sc->bce_bc_ver);
610 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
611 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
613 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
614 kprintf("MFW[%s]", sc->bce_mfw_ver);
615 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
623 /****************************************************************************/
624 /* PCI Capabilities Probe Function. */
626 /* Walks the PCI capabiites list for the device to find what features are */
631 /****************************************************************************/
633 bce_probe_pci_caps(struct bce_softc *sc)
635 device_t dev = sc->bce_dev;
638 if (pci_is_pcix(dev))
639 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
641 ptr = pci_get_pciecap_ptr(dev);
643 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
645 sc->link_speed = link_status & 0xf;
646 sc->link_width = (link_status >> 4) & 0x3f;
647 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
648 sc->bce_flags |= BCE_PCIE_FLAG;
653 /****************************************************************************/
654 /* Device attach function. */
656 /* Allocates device resources, performs secondary chip identification, */
657 /* resets and initializes the hardware, and initializes driver instance */
661 /* 0 on success, positive value on failure. */
662 /****************************************************************************/
664 bce_attach(device_t dev)
666 struct bce_softc *sc = device_get_softc(dev);
667 struct ifnet *ifp = &sc->arpcom.ac_if;
670 int rid, rc = 0, msi_enable;
675 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
677 pci_enable_busmaster(dev);
679 bce_probe_pci_caps(sc);
681 /* Allocate PCI memory resources. */
683 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
684 RF_ACTIVE | PCI_RF_DENSE);
685 if (sc->bce_res_mem == NULL) {
686 device_printf(dev, "PCI memory allocation failed\n");
689 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
690 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
692 /* Allocate PCI IRQ resources. */
693 msi_enable = bce_msi_enable;
694 ksnprintf(env, sizeof(env), "hw.%s.msi.enable",
695 device_get_nameunit(dev));
696 kgetenv_int(env, &msi_enable);
699 sc->bce_irq_type = BCE_IRQ_TYPE_LEGACY;
700 irq_flags = RF_SHAREABLE | RF_ACTIVE;
705 ksnprintf(env, sizeof(env), "hw.%s.msi.cpu",
706 device_get_nameunit(dev));
707 kgetenv_int(env, &cpu);
711 if (pci_alloc_msi(dev, &sc->bce_irq_rid, 1, cpu) == 0) {
712 irq_flags &= ~RF_SHAREABLE;
713 sc->bce_irq_type = BCE_IRQ_TYPE_MSI;
717 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
718 &sc->bce_irq_rid, irq_flags);
719 if (sc->bce_res_irq == NULL) {
720 device_printf(dev, "PCI map interrupt failed\n");
726 * Configure byte swap and enable indirect register access.
727 * Rely on CPU to do target byte swapping on big endian systems.
728 * Access to registers outside of PCI configurtion space are not
729 * valid until this is done.
731 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
732 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
733 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
735 /* Save ASIC revsion info. */
736 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
738 /* Weed out any non-production controller revisions. */
739 switch (BCE_CHIP_ID(sc)) {
740 case BCE_CHIP_ID_5706_A0:
741 case BCE_CHIP_ID_5706_A1:
742 case BCE_CHIP_ID_5708_A0:
743 case BCE_CHIP_ID_5708_B0:
744 case BCE_CHIP_ID_5709_A0:
745 case BCE_CHIP_ID_5709_B0:
746 case BCE_CHIP_ID_5709_B1:
748 /* 5709C B2 seems to work fine */
749 case BCE_CHIP_ID_5709_B2:
751 device_printf(dev, "Unsupported chip id 0x%08x!\n",
758 * Find the base address for shared memory access.
759 * Newer versions of bootcode use a signature and offset
760 * while older versions use a fixed address.
762 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
763 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
764 BCE_SHM_HDR_SIGNATURE_SIG) {
765 /* Multi-port devices use different offsets in shared memory. */
766 sc->bce_shmem_base = REG_RD_IND(sc,
767 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
769 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
771 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
773 /* Fetch the bootcode revision. */
774 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
775 for (i = 0, j = 0; i < 3; i++) {
779 num = (uint8_t)(val >> (24 - (i * 8)));
780 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
781 if (num >= k || !skip0 || k == 1) {
782 sc->bce_bc_ver[j++] = (num / k) + '0';
787 sc->bce_bc_ver[j++] = '.';
790 /* Check if any management firwmare is running. */
791 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
792 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
793 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
795 /* Allow time for firmware to enter the running state. */
796 for (i = 0; i < 30; i++) {
797 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
798 if (val & BCE_CONDITION_MFW_RUN_MASK)
804 /* Check the current bootcode state. */
805 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
806 BCE_CONDITION_MFW_RUN_MASK;
807 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
808 val != BCE_CONDITION_MFW_RUN_NONE) {
809 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
811 for (i = 0, j = 0; j < 3; j++) {
812 val = bce_reg_rd_ind(sc, addr + j * 4);
814 memcpy(&sc->bce_mfw_ver[i], &val, 4);
819 /* Get PCI bus information (speed and type). */
820 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
821 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
824 sc->bce_flags |= BCE_PCIX_FLAG;
826 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
827 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
829 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
830 sc->bus_speed_mhz = 133;
833 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
834 sc->bus_speed_mhz = 100;
837 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
838 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
839 sc->bus_speed_mhz = 66;
842 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
843 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
844 sc->bus_speed_mhz = 50;
847 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
848 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
849 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
850 sc->bus_speed_mhz = 33;
854 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
855 sc->bus_speed_mhz = 66;
857 sc->bus_speed_mhz = 33;
860 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
861 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
863 /* Reset the controller. */
864 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
868 /* Initialize the controller. */
869 rc = bce_chipinit(sc);
871 device_printf(dev, "Controller initialization failed!\n");
875 /* Perform NVRAM test. */
876 rc = bce_nvram_test(sc);
878 device_printf(dev, "NVRAM test failed!\n");
882 /* Fetch the permanent Ethernet MAC address. */
883 bce_get_mac_addr(sc);
886 * Trip points control how many BDs
887 * should be ready before generating an
888 * interrupt while ticks control how long
889 * a BD can sit in the chain before
890 * generating an interrupt. Set the default
891 * values for the RX and TX rings.
895 /* Force more frequent interrupts. */
896 sc->bce_tx_quick_cons_trip_int = 1;
897 sc->bce_tx_quick_cons_trip = 1;
898 sc->bce_tx_ticks_int = 0;
899 sc->bce_tx_ticks = 0;
901 sc->bce_rx_quick_cons_trip_int = 1;
902 sc->bce_rx_quick_cons_trip = 1;
903 sc->bce_rx_ticks_int = 0;
904 sc->bce_rx_ticks = 0;
906 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
907 sc->bce_tx_quick_cons_trip = bce_tx_bds;
908 sc->bce_tx_ticks_int = bce_tx_ticks_int;
909 sc->bce_tx_ticks = bce_tx_ticks;
911 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
912 sc->bce_rx_quick_cons_trip = bce_rx_bds;
913 sc->bce_rx_ticks_int = bce_rx_ticks_int;
914 sc->bce_rx_ticks = bce_rx_ticks;
917 /* Update statistics once every second. */
918 sc->bce_stats_ticks = 1000000 & 0xffff00;
920 /* Find the media type for the adapter. */
923 /* Allocate DMA memory resources. */
924 rc = bce_dma_alloc(sc);
926 device_printf(dev, "DMA resource allocation failed!\n");
930 /* Initialize the ifnet interface. */
932 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
933 ifp->if_ioctl = bce_ioctl;
934 ifp->if_start = bce_start;
935 ifp->if_init = bce_init;
936 ifp->if_watchdog = bce_watchdog;
937 #ifdef DEVICE_POLLING
938 ifp->if_poll = bce_poll;
940 ifp->if_mtu = ETHERMTU;
941 ifp->if_hwassist = BCE_IF_HWASSIST;
942 ifp->if_capabilities = BCE_IF_CAPABILITIES;
943 ifp->if_capenable = ifp->if_capabilities;
944 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
945 ifq_set_ready(&ifp->if_snd);
947 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
948 ifp->if_baudrate = IF_Gbps(2.5);
950 ifp->if_baudrate = IF_Gbps(1);
952 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
953 sc->mbuf_alloc_size = MCLBYTES;
955 /* Look for our PHY. */
956 rc = mii_phy_probe(dev, &sc->bce_miibus,
957 bce_ifmedia_upd, bce_ifmedia_sts);
959 device_printf(dev, "PHY probe failed!\n");
963 /* Attach to the Ethernet interface list. */
964 ether_ifattach(ifp, sc->eaddr, NULL);
966 callout_init_mp(&sc->bce_tick_callout);
967 callout_init_mp(&sc->bce_pulse_callout);
969 /* Hookup IRQ last. */
970 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, bce_intr, sc,
971 &sc->bce_intrhand, ifp->if_serializer);
973 device_printf(dev, "Failed to setup IRQ!\n");
978 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
979 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
981 /* Print some important debugging info. */
982 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
984 /* Add the supported sysctls to the kernel. */
988 * The chip reset earlier notified the bootcode that
989 * a driver is present. We now need to start our pulse
990 * routine so that the bootcode is reminded that we're
995 /* Get the firmware running so IPMI still works */
999 bce_print_adapter_info(sc);
1008 /****************************************************************************/
1009 /* Device detach function. */
1011 /* Stops the controller, resets the controller, and releases resources. */
1014 /* 0 on success, positive value on failure. */
1015 /****************************************************************************/
1017 bce_detach(device_t dev)
1019 struct bce_softc *sc = device_get_softc(dev);
1021 if (device_is_attached(dev)) {
1022 struct ifnet *ifp = &sc->arpcom.ac_if;
1025 /* Stop and reset the controller. */
1026 lwkt_serialize_enter(ifp->if_serializer);
1027 callout_stop(&sc->bce_pulse_callout);
1029 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1030 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1032 msg = BCE_DRV_MSG_CODE_UNLOAD;
1034 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1035 lwkt_serialize_exit(ifp->if_serializer);
1037 ether_ifdetach(ifp);
1040 /* If we have a child device on the MII bus remove it too. */
1042 device_delete_child(dev, sc->bce_miibus);
1043 bus_generic_detach(dev);
1045 if (sc->bce_res_irq != NULL) {
1046 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
1050 if (sc->bce_irq_type == BCE_IRQ_TYPE_MSI)
1051 pci_release_msi(dev);
1053 if (sc->bce_res_mem != NULL) {
1054 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1060 if (sc->bce_sysctl_tree != NULL)
1061 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1067 /****************************************************************************/
1068 /* Device shutdown function. */
1070 /* Stops and resets the controller. */
1074 /****************************************************************************/
1076 bce_shutdown(device_t dev)
1078 struct bce_softc *sc = device_get_softc(dev);
1079 struct ifnet *ifp = &sc->arpcom.ac_if;
1082 lwkt_serialize_enter(ifp->if_serializer);
1084 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1085 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1087 msg = BCE_DRV_MSG_CODE_UNLOAD;
1089 lwkt_serialize_exit(ifp->if_serializer);
1093 /****************************************************************************/
1094 /* Indirect register read. */
1096 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1097 /* configuration space. Using this mechanism avoids issues with posted */
1098 /* reads but is much slower than memory-mapped I/O. */
1101 /* The value of the register. */
1102 /****************************************************************************/
1104 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1106 device_t dev = sc->bce_dev;
1108 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1112 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1113 DBPRINT(sc, BCE_EXCESSIVE,
1114 "%s(); offset = 0x%08X, val = 0x%08X\n",
1115 __func__, offset, val);
1119 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1124 /****************************************************************************/
1125 /* Indirect register write. */
1127 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1128 /* configuration space. Using this mechanism avoids issues with posted */
1129 /* writes but is muchh slower than memory-mapped I/O. */
1133 /****************************************************************************/
1135 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1137 device_t dev = sc->bce_dev;
1139 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1140 __func__, offset, val);
1142 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1143 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1147 /****************************************************************************/
1148 /* Shared memory write. */
1150 /* Writes NetXtreme II shared memory region. */
1154 /****************************************************************************/
1156 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1158 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1162 /****************************************************************************/
1163 /* Shared memory read. */
1165 /* Reads NetXtreme II shared memory region. */
1168 /* The 32 bit value read. */
1169 /****************************************************************************/
1171 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1173 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1177 /****************************************************************************/
1178 /* Context memory write. */
1180 /* The NetXtreme II controller uses context memory to track connection */
1181 /* information for L2 and higher network protocols. */
1185 /****************************************************************************/
1187 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1190 uint32_t idx, offset = ctx_offset + cid_addr;
1191 uint32_t val, retry_cnt = 5;
1193 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1194 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1195 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1196 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1198 for (idx = 0; idx < retry_cnt; idx++) {
1199 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1200 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1205 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1206 device_printf(sc->bce_dev,
1207 "Unable to write CTX memory: "
1208 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1209 cid_addr, ctx_offset);
1212 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1213 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1218 /****************************************************************************/
1219 /* PHY register read. */
1221 /* Implements register reads on the MII bus. */
1224 /* The value of the register. */
1225 /****************************************************************************/
1227 bce_miibus_read_reg(device_t dev, int phy, int reg)
1229 struct bce_softc *sc = device_get_softc(dev);
1233 /* Make sure we are accessing the correct PHY address. */
1234 if (phy != sc->bce_phy_addr) {
1235 DBPRINT(sc, BCE_VERBOSE,
1236 "Invalid PHY address %d for PHY read!\n", phy);
1240 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1241 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1242 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1244 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1245 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1250 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1251 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1252 BCE_EMAC_MDIO_COMM_START_BUSY;
1253 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1255 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1258 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1259 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1262 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1263 val &= BCE_EMAC_MDIO_COMM_DATA;
1268 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1269 if_printf(&sc->arpcom.ac_if,
1270 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1274 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1277 DBPRINT(sc, BCE_EXCESSIVE,
1278 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1279 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1281 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1282 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1283 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1285 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1286 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1290 return (val & 0xffff);
1294 /****************************************************************************/
1295 /* PHY register write. */
1297 /* Implements register writes on the MII bus. */
1300 /* The value of the register. */
1301 /****************************************************************************/
1303 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1305 struct bce_softc *sc = device_get_softc(dev);
1309 /* Make sure we are accessing the correct PHY address. */
1310 if (phy != sc->bce_phy_addr) {
1311 DBPRINT(sc, BCE_WARN,
1312 "Invalid PHY address %d for PHY write!\n", phy);
1316 DBPRINT(sc, BCE_EXCESSIVE,
1317 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1318 __func__, phy, (uint16_t)(reg & 0xffff),
1319 (uint16_t)(val & 0xffff));
1321 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1322 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1323 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1325 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1326 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1331 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1332 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1333 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1334 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1336 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1339 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1340 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1346 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1347 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1349 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1350 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1351 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1353 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1354 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1362 /****************************************************************************/
1363 /* MII bus status change. */
1365 /* Called by the MII bus driver when the PHY establishes link to set the */
1366 /* MAC interface registers. */
1370 /****************************************************************************/
1372 bce_miibus_statchg(device_t dev)
1374 struct bce_softc *sc = device_get_softc(dev);
1375 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1377 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1378 mii->mii_media_active);
1381 /* Decode the interface media flags. */
1382 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1383 switch(IFM_TYPE(mii->mii_media_active)) {
1385 kprintf("Ethernet )");
1388 kprintf("Unknown )");
1392 kprintf(" Media Options: ( ");
1393 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1395 kprintf("Autoselect )");
1398 kprintf("Manual )");
1404 kprintf("10Base-T )");
1407 kprintf("100Base-TX )");
1410 kprintf("1000Base-SX )");
1413 kprintf("1000Base-T )");
1420 kprintf(" Global Options: (");
1421 if (mii->mii_media_active & IFM_FDX)
1422 kprintf(" FullDuplex");
1423 if (mii->mii_media_active & IFM_HDX)
1424 kprintf(" HalfDuplex");
1425 if (mii->mii_media_active & IFM_LOOP)
1426 kprintf(" Loopback");
1427 if (mii->mii_media_active & IFM_FLAG0)
1429 if (mii->mii_media_active & IFM_FLAG1)
1431 if (mii->mii_media_active & IFM_FLAG2)
1436 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1439 * Set MII or GMII interface based on the speed negotiated
1442 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1443 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1444 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1445 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1447 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1448 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1452 * Set half or full duplex based on the duplicity negotiated
1455 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1456 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1457 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1459 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1460 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1465 /****************************************************************************/
1466 /* Acquire NVRAM lock. */
1468 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1469 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1470 /* for use by the driver. */
1473 /* 0 on success, positive value on failure. */
1474 /****************************************************************************/
1476 bce_acquire_nvram_lock(struct bce_softc *sc)
1481 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1483 /* Request access to the flash interface. */
1484 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1485 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1486 val = REG_RD(sc, BCE_NVM_SW_ARB);
1487 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1493 if (j >= NVRAM_TIMEOUT_COUNT) {
1494 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1501 /****************************************************************************/
1502 /* Release NVRAM lock. */
1504 /* When the caller is finished accessing NVRAM the lock must be released. */
1505 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1506 /* for use by the driver. */
1509 /* 0 on success, positive value on failure. */
1510 /****************************************************************************/
1512 bce_release_nvram_lock(struct bce_softc *sc)
1517 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1520 * Relinquish nvram interface.
1522 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1524 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1525 val = REG_RD(sc, BCE_NVM_SW_ARB);
1526 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1532 if (j >= NVRAM_TIMEOUT_COUNT) {
1533 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1540 /****************************************************************************/
1541 /* Enable NVRAM access. */
1543 /* Before accessing NVRAM for read or write operations the caller must */
1544 /* enabled NVRAM access. */
1548 /****************************************************************************/
1550 bce_enable_nvram_access(struct bce_softc *sc)
1554 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1556 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1557 /* Enable both bits, even on read. */
1558 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1559 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1563 /****************************************************************************/
1564 /* Disable NVRAM access. */
1566 /* When the caller is finished accessing NVRAM access must be disabled. */
1570 /****************************************************************************/
1572 bce_disable_nvram_access(struct bce_softc *sc)
1576 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1578 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1580 /* Disable both bits, even after read. */
1581 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1582 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1586 /****************************************************************************/
1587 /* Read a dword (32 bits) from NVRAM. */
1589 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1590 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1593 /* 0 on success and the 32 bit value read, positive value on failure. */
1594 /****************************************************************************/
1596 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1602 /* Build the command word. */
1603 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1605 /* Calculate the offset for buffered flash. */
1606 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1607 offset = ((offset / sc->bce_flash_info->page_size) <<
1608 sc->bce_flash_info->page_bits) +
1609 (offset % sc->bce_flash_info->page_size);
1613 * Clear the DONE bit separately, set the address to read,
1614 * and issue the read.
1616 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1617 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1618 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1620 /* Wait for completion. */
1621 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1626 val = REG_RD(sc, BCE_NVM_COMMAND);
1627 if (val & BCE_NVM_COMMAND_DONE) {
1628 val = REG_RD(sc, BCE_NVM_READ);
1631 memcpy(ret_val, &val, 4);
1636 /* Check for errors. */
1637 if (i >= NVRAM_TIMEOUT_COUNT) {
1638 if_printf(&sc->arpcom.ac_if,
1639 "Timeout error reading NVRAM at offset 0x%08X!\n",
1647 /****************************************************************************/
1648 /* Initialize NVRAM access. */
1650 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1651 /* access that device. */
1654 /* 0 on success, positive value on failure. */
1655 /****************************************************************************/
1657 bce_init_nvram(struct bce_softc *sc)
1660 int j, entry_count, rc = 0;
1661 const struct flash_spec *flash;
1663 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1665 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1666 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1667 sc->bce_flash_info = &flash_5709;
1668 goto bce_init_nvram_get_flash_size;
1671 /* Determine the selected interface. */
1672 val = REG_RD(sc, BCE_NVM_CFG1);
1674 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1677 * Flash reconfiguration is required to support additional
1678 * NVRAM devices not directly supported in hardware.
1679 * Check if the flash interface was reconfigured
1683 if (val & 0x40000000) {
1684 /* Flash interface reconfigured by bootcode. */
1686 DBPRINT(sc, BCE_INFO_LOAD,
1687 "%s(): Flash WAS reconfigured.\n", __func__);
1689 for (j = 0, flash = flash_table; j < entry_count;
1691 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1692 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1693 sc->bce_flash_info = flash;
1698 /* Flash interface not yet reconfigured. */
1701 DBPRINT(sc, BCE_INFO_LOAD,
1702 "%s(): Flash was NOT reconfigured.\n", __func__);
1704 if (val & (1 << 23))
1705 mask = FLASH_BACKUP_STRAP_MASK;
1707 mask = FLASH_STRAP_MASK;
1709 /* Look for the matching NVRAM device configuration data. */
1710 for (j = 0, flash = flash_table; j < entry_count;
1712 /* Check if the device matches any of the known devices. */
1713 if ((val & mask) == (flash->strapping & mask)) {
1714 /* Found a device match. */
1715 sc->bce_flash_info = flash;
1717 /* Request access to the flash interface. */
1718 rc = bce_acquire_nvram_lock(sc);
1722 /* Reconfigure the flash interface. */
1723 bce_enable_nvram_access(sc);
1724 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1725 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1726 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1727 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1728 bce_disable_nvram_access(sc);
1729 bce_release_nvram_lock(sc);
1735 /* Check if a matching device was found. */
1736 if (j == entry_count) {
1737 sc->bce_flash_info = NULL;
1738 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1742 bce_init_nvram_get_flash_size:
1743 /* Write the flash config data to the shared memory interface. */
1744 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1745 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1747 sc->bce_flash_size = val;
1749 sc->bce_flash_size = sc->bce_flash_info->total_size;
1751 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1752 __func__, sc->bce_flash_info->total_size);
1754 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1760 /****************************************************************************/
1761 /* Read an arbitrary range of data from NVRAM. */
1763 /* Prepares the NVRAM interface for access and reads the requested data */
1764 /* into the supplied buffer. */
1767 /* 0 on success and the data read, positive value on failure. */
1768 /****************************************************************************/
1770 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1773 uint32_t cmd_flags, offset32, len32, extra;
1779 /* Request access to the flash interface. */
1780 rc = bce_acquire_nvram_lock(sc);
1784 /* Enable access to flash interface */
1785 bce_enable_nvram_access(sc);
1793 /* XXX should we release nvram lock if read_dword() fails? */
1799 pre_len = 4 - (offset & 3);
1801 if (pre_len >= len32) {
1803 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1805 cmd_flags = BCE_NVM_COMMAND_FIRST;
1808 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1812 memcpy(ret_buf, buf + (offset & 3), pre_len);
1820 extra = 4 - (len32 & 3);
1821 len32 = (len32 + 4) & ~3;
1828 cmd_flags = BCE_NVM_COMMAND_LAST;
1830 cmd_flags = BCE_NVM_COMMAND_FIRST |
1831 BCE_NVM_COMMAND_LAST;
1833 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1835 memcpy(ret_buf, buf, 4 - extra);
1836 } else if (len32 > 0) {
1839 /* Read the first word. */
1843 cmd_flags = BCE_NVM_COMMAND_FIRST;
1845 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1847 /* Advance to the next dword. */
1852 while (len32 > 4 && rc == 0) {
1853 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1855 /* Advance to the next dword. */
1862 goto bce_nvram_read_locked_exit;
1864 cmd_flags = BCE_NVM_COMMAND_LAST;
1865 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1867 memcpy(ret_buf, buf, 4 - extra);
1870 bce_nvram_read_locked_exit:
1871 /* Disable access to flash interface and release the lock. */
1872 bce_disable_nvram_access(sc);
1873 bce_release_nvram_lock(sc);
1879 /****************************************************************************/
1880 /* Verifies that NVRAM is accessible and contains valid data. */
1882 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1886 /* 0 on success, positive value on failure. */
1887 /****************************************************************************/
1889 bce_nvram_test(struct bce_softc *sc)
1891 uint32_t buf[BCE_NVRAM_SIZE / 4];
1892 uint32_t magic, csum;
1893 uint8_t *data = (uint8_t *)buf;
1897 * Check that the device NVRAM is valid by reading
1898 * the magic value at offset 0.
1900 rc = bce_nvram_read(sc, 0, data, 4);
1904 magic = be32toh(buf[0]);
1905 if (magic != BCE_NVRAM_MAGIC) {
1906 if_printf(&sc->arpcom.ac_if,
1907 "Invalid NVRAM magic value! Expected: 0x%08X, "
1908 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1913 * Verify that the device NVRAM includes valid
1914 * configuration data.
1916 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1920 csum = ether_crc32_le(data, 0x100);
1921 if (csum != BCE_CRC32_RESIDUAL) {
1922 if_printf(&sc->arpcom.ac_if,
1923 "Invalid Manufacturing Information NVRAM CRC! "
1924 "Expected: 0x%08X, Found: 0x%08X\n",
1925 BCE_CRC32_RESIDUAL, csum);
1929 csum = ether_crc32_le(data + 0x100, 0x100);
1930 if (csum != BCE_CRC32_RESIDUAL) {
1931 if_printf(&sc->arpcom.ac_if,
1932 "Invalid Feature Configuration Information "
1933 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1934 BCE_CRC32_RESIDUAL, csum);
1941 /****************************************************************************/
1942 /* Identifies the current media type of the controller and sets the PHY */
1947 /****************************************************************************/
1949 bce_get_media(struct bce_softc *sc)
1953 sc->bce_phy_addr = 1;
1955 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1956 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1957 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1958 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1962 * The BCM5709S is software configurable
1963 * for Copper or SerDes operation.
1965 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1967 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1968 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1972 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1973 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
1976 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
1979 if (pci_get_function(sc->bce_dev) == 0) {
1984 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1992 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1996 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
1997 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2000 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
2001 sc->bce_flags |= BCE_NO_WOL_FLAG;
2002 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2003 sc->bce_phy_addr = 2;
2004 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
2005 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
2006 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
2008 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
2009 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
2010 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
2015 /****************************************************************************/
2016 /* Free any DMA memory owned by the driver. */
2018 /* Scans through each data structre that requires DMA memory and frees */
2019 /* the memory if allocated. */
2023 /****************************************************************************/
2025 bce_dma_free(struct bce_softc *sc)
2029 /* Destroy the status block. */
2030 if (sc->status_tag != NULL) {
2031 if (sc->status_block != NULL) {
2032 bus_dmamap_unload(sc->status_tag, sc->status_map);
2033 bus_dmamem_free(sc->status_tag, sc->status_block,
2036 bus_dma_tag_destroy(sc->status_tag);
2040 /* Destroy the statistics block. */
2041 if (sc->stats_tag != NULL) {
2042 if (sc->stats_block != NULL) {
2043 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2044 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2047 bus_dma_tag_destroy(sc->stats_tag);
2050 /* Destroy the CTX DMA stuffs. */
2051 if (sc->ctx_tag != NULL) {
2052 for (i = 0; i < sc->ctx_pages; i++) {
2053 if (sc->ctx_block[i] != NULL) {
2054 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2055 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2059 bus_dma_tag_destroy(sc->ctx_tag);
2062 /* Destroy the TX buffer descriptor DMA stuffs. */
2063 if (sc->tx_bd_chain_tag != NULL) {
2064 for (i = 0; i < TX_PAGES; i++) {
2065 if (sc->tx_bd_chain[i] != NULL) {
2066 bus_dmamap_unload(sc->tx_bd_chain_tag,
2067 sc->tx_bd_chain_map[i]);
2068 bus_dmamem_free(sc->tx_bd_chain_tag,
2070 sc->tx_bd_chain_map[i]);
2073 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2076 /* Destroy the RX buffer descriptor DMA stuffs. */
2077 if (sc->rx_bd_chain_tag != NULL) {
2078 for (i = 0; i < RX_PAGES; i++) {
2079 if (sc->rx_bd_chain[i] != NULL) {
2080 bus_dmamap_unload(sc->rx_bd_chain_tag,
2081 sc->rx_bd_chain_map[i]);
2082 bus_dmamem_free(sc->rx_bd_chain_tag,
2084 sc->rx_bd_chain_map[i]);
2087 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2090 /* Destroy the TX mbuf DMA stuffs. */
2091 if (sc->tx_mbuf_tag != NULL) {
2092 for (i = 0; i < TOTAL_TX_BD; i++) {
2093 /* Must have been unloaded in bce_stop() */
2094 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2095 bus_dmamap_destroy(sc->tx_mbuf_tag,
2096 sc->tx_mbuf_map[i]);
2098 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2101 /* Destroy the RX mbuf DMA stuffs. */
2102 if (sc->rx_mbuf_tag != NULL) {
2103 for (i = 0; i < TOTAL_RX_BD; i++) {
2104 /* Must have been unloaded in bce_stop() */
2105 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2106 bus_dmamap_destroy(sc->rx_mbuf_tag,
2107 sc->rx_mbuf_map[i]);
2109 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2110 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2113 /* Destroy the parent tag */
2114 if (sc->parent_tag != NULL)
2115 bus_dma_tag_destroy(sc->parent_tag);
2119 /****************************************************************************/
2120 /* Get DMA memory from the OS. */
2122 /* Validates that the OS has provided DMA buffers in response to a */
2123 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2124 /* When the callback is used the OS will return 0 for the mapping function */
2125 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2126 /* failures back to the caller. */
2130 /****************************************************************************/
2132 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2134 bus_addr_t *busaddr = arg;
2137 * Simulate a mapping failure.
2140 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2141 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2142 __FILE__, __LINE__);
2145 /* Check for an error and signal the caller that an error occurred. */
2149 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2150 *busaddr = segs->ds_addr;
2154 /****************************************************************************/
2155 /* Allocate any DMA memory needed by the driver. */
2157 /* Allocates DMA memory needed for the various global structures needed by */
2160 /* Memory alignment requirements: */
2161 /* -----------------+----------+----------+----------+----------+ */
2162 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2163 /* -----------------+----------+----------+----------+----------+ */
2164 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2165 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2166 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2167 /* PG Buffers | none | none | none | none | */
2168 /* TX Buffers | none | none | none | none | */
2169 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2170 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2171 /* -----------------+----------+----------+----------+----------+ */
2173 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2176 /* 0 for success, positive value for failure. */
2177 /****************************************************************************/
2179 bce_dma_alloc(struct bce_softc *sc)
2181 struct ifnet *ifp = &sc->arpcom.ac_if;
2183 bus_addr_t busaddr, max_busaddr;
2184 bus_size_t status_align, stats_align;
2187 * The embedded PCIe to PCI-X bridge (EPB)
2188 * in the 5708 cannot address memory above
2189 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2191 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2192 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2194 max_busaddr = BUS_SPACE_MAXADDR;
2197 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2199 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2200 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2201 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2202 if (sc->ctx_pages == 0)
2204 if (sc->ctx_pages > BCE_CTX_PAGES) {
2205 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2217 * Allocate the parent bus DMA tag appropriate for PCI.
2219 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2220 max_busaddr, BUS_SPACE_MAXADDR,
2222 BUS_SPACE_MAXSIZE_32BIT, 0,
2223 BUS_SPACE_MAXSIZE_32BIT,
2224 0, &sc->parent_tag);
2226 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2231 * Allocate status block.
2233 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2234 status_align, BCE_STATUS_BLK_SZ,
2235 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2236 &sc->status_tag, &sc->status_map,
2237 &sc->status_block_paddr);
2238 if (sc->status_block == NULL) {
2239 if_printf(ifp, "Could not allocate status block!\n");
2244 * Allocate statistics block.
2246 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2247 stats_align, BCE_STATS_BLK_SZ,
2248 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2249 &sc->stats_tag, &sc->stats_map,
2250 &sc->stats_block_paddr);
2251 if (sc->stats_block == NULL) {
2252 if_printf(ifp, "Could not allocate statistics block!\n");
2257 * Allocate context block, if needed
2259 if (sc->ctx_pages != 0) {
2260 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2261 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2263 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2266 if_printf(ifp, "Could not allocate "
2267 "context block DMA tag!\n");
2271 for (i = 0; i < sc->ctx_pages; i++) {
2272 rc = bus_dmamem_alloc(sc->ctx_tag,
2273 (void **)&sc->ctx_block[i],
2274 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2278 if_printf(ifp, "Could not allocate %dth context "
2279 "DMA memory!\n", i);
2283 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2284 sc->ctx_block[i], BCM_PAGE_SIZE,
2285 bce_dma_map_addr, &busaddr,
2288 if (rc == EINPROGRESS) {
2289 panic("%s coherent memory loading "
2290 "is still in progress!", ifp->if_xname);
2292 if_printf(ifp, "Could not map %dth context "
2293 "DMA memory!\n", i);
2294 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2296 sc->ctx_block[i] = NULL;
2299 sc->ctx_paddr[i] = busaddr;
2304 * Create a DMA tag for the TX buffer descriptor chain,
2305 * allocate and clear the memory, and fetch the
2306 * physical address of the block.
2308 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2309 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2311 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2312 0, &sc->tx_bd_chain_tag);
2314 if_printf(ifp, "Could not allocate "
2315 "TX descriptor chain DMA tag!\n");
2319 for (i = 0; i < TX_PAGES; i++) {
2320 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2321 (void **)&sc->tx_bd_chain[i],
2322 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2324 &sc->tx_bd_chain_map[i]);
2326 if_printf(ifp, "Could not allocate %dth TX descriptor "
2327 "chain DMA memory!\n", i);
2331 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2332 sc->tx_bd_chain_map[i],
2333 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2334 bce_dma_map_addr, &busaddr,
2337 if (rc == EINPROGRESS) {
2338 panic("%s coherent memory loading "
2339 "is still in progress!", ifp->if_xname);
2341 if_printf(ifp, "Could not map %dth TX descriptor "
2342 "chain DMA memory!\n", i);
2343 bus_dmamem_free(sc->tx_bd_chain_tag,
2345 sc->tx_bd_chain_map[i]);
2346 sc->tx_bd_chain[i] = NULL;
2350 sc->tx_bd_chain_paddr[i] = busaddr;
2351 /* DRC - Fix for 64 bit systems. */
2352 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2353 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2356 /* Create a DMA tag for TX mbufs. */
2357 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2358 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2360 /* BCE_MAX_JUMBO_ETHER_MTU_VLAN */MCLBYTES,
2361 BCE_MAX_SEGMENTS, MCLBYTES,
2362 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2366 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2370 /* Create DMA maps for the TX mbufs clusters. */
2371 for (i = 0; i < TOTAL_TX_BD; i++) {
2372 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2373 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2374 &sc->tx_mbuf_map[i]);
2376 for (j = 0; j < i; ++j) {
2377 bus_dmamap_destroy(sc->tx_mbuf_tag,
2378 sc->tx_mbuf_map[i]);
2380 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2381 sc->tx_mbuf_tag = NULL;
2383 if_printf(ifp, "Unable to create "
2384 "%dth TX mbuf DMA map!\n", i);
2390 * Create a DMA tag for the RX buffer descriptor chain,
2391 * allocate and clear the memory, and fetch the physical
2392 * address of the blocks.
2394 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2395 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2397 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2398 0, &sc->rx_bd_chain_tag);
2400 if_printf(ifp, "Could not allocate "
2401 "RX descriptor chain DMA tag!\n");
2405 for (i = 0; i < RX_PAGES; i++) {
2406 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2407 (void **)&sc->rx_bd_chain[i],
2408 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2410 &sc->rx_bd_chain_map[i]);
2412 if_printf(ifp, "Could not allocate %dth RX descriptor "
2413 "chain DMA memory!\n", i);
2417 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2418 sc->rx_bd_chain_map[i],
2419 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2420 bce_dma_map_addr, &busaddr,
2423 if (rc == EINPROGRESS) {
2424 panic("%s coherent memory loading "
2425 "is still in progress!", ifp->if_xname);
2427 if_printf(ifp, "Could not map %dth RX descriptor "
2428 "chain DMA memory!\n", i);
2429 bus_dmamem_free(sc->rx_bd_chain_tag,
2431 sc->rx_bd_chain_map[i]);
2432 sc->rx_bd_chain[i] = NULL;
2436 sc->rx_bd_chain_paddr[i] = busaddr;
2437 /* DRC - Fix for 64 bit systems. */
2438 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2439 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2442 /* Create a DMA tag for RX mbufs. */
2443 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2444 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2446 MCLBYTES, 1, MCLBYTES,
2447 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2451 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2455 /* Create tmp DMA map for RX mbuf clusters. */
2456 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2457 &sc->rx_mbuf_tmpmap);
2459 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2460 sc->rx_mbuf_tag = NULL;
2462 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2466 /* Create DMA maps for the RX mbuf clusters. */
2467 for (i = 0; i < TOTAL_RX_BD; i++) {
2468 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2469 &sc->rx_mbuf_map[i]);
2471 for (j = 0; j < i; ++j) {
2472 bus_dmamap_destroy(sc->rx_mbuf_tag,
2473 sc->rx_mbuf_map[j]);
2475 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2476 sc->rx_mbuf_tag = NULL;
2478 if_printf(ifp, "Unable to create "
2479 "%dth RX mbuf DMA map!\n", i);
2487 /****************************************************************************/
2488 /* Firmware synchronization. */
2490 /* Before performing certain events such as a chip reset, synchronize with */
2491 /* the firmware first. */
2494 /* 0 for success, positive value for failure. */
2495 /****************************************************************************/
2497 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2502 /* Don't waste any time if we've timed out before. */
2503 if (sc->bce_fw_timed_out)
2506 /* Increment the message sequence number. */
2507 sc->bce_fw_wr_seq++;
2508 msg_data |= sc->bce_fw_wr_seq;
2510 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2512 /* Send the message to the bootcode driver mailbox. */
2513 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2515 /* Wait for the bootcode to acknowledge the message. */
2516 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2517 /* Check for a response in the bootcode firmware mailbox. */
2518 val = bce_shmem_rd(sc, BCE_FW_MB);
2519 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2524 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2525 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2526 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2527 if_printf(&sc->arpcom.ac_if,
2528 "Firmware synchronization timeout! "
2529 "msg_data = 0x%08X\n", msg_data);
2531 msg_data &= ~BCE_DRV_MSG_CODE;
2532 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2534 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2536 sc->bce_fw_timed_out = 1;
2543 /****************************************************************************/
2544 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2548 /****************************************************************************/
2550 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2551 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2556 for (i = 0; i < rv2p_code_len; i += 8) {
2557 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2559 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2562 if (rv2p_proc == RV2P_PROC1) {
2563 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2564 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2566 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2567 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2571 /* Reset the processor, un-stall is done later. */
2572 if (rv2p_proc == RV2P_PROC1)
2573 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2575 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2579 /****************************************************************************/
2580 /* Load RISC processor firmware. */
2582 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2583 /* associated with a particular processor. */
2587 /****************************************************************************/
2589 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2595 bce_halt_cpu(sc, cpu_reg);
2597 /* Load the Text area. */
2598 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2600 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2601 REG_WR_IND(sc, offset, fw->text[j]);
2604 /* Load the Data area. */
2605 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2607 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2608 REG_WR_IND(sc, offset, fw->data[j]);
2611 /* Load the SBSS area. */
2612 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2614 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2615 REG_WR_IND(sc, offset, fw->sbss[j]);
2618 /* Load the BSS area. */
2619 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2621 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2622 REG_WR_IND(sc, offset, fw->bss[j]);
2625 /* Load the Read-Only area. */
2626 offset = cpu_reg->spad_base +
2627 (fw->rodata_addr - cpu_reg->mips_view_base);
2629 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2630 REG_WR_IND(sc, offset, fw->rodata[j]);
2633 /* Clear the pre-fetch instruction and set the FW start address. */
2634 REG_WR_IND(sc, cpu_reg->inst, 0);
2635 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2639 /****************************************************************************/
2640 /* Starts the RISC processor. */
2642 /* Assumes the CPU starting address has already been set. */
2646 /****************************************************************************/
2648 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2652 /* Start the CPU. */
2653 val = REG_RD_IND(sc, cpu_reg->mode);
2654 val &= ~cpu_reg->mode_value_halt;
2655 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2656 REG_WR_IND(sc, cpu_reg->mode, val);
2660 /****************************************************************************/
2661 /* Halts the RISC processor. */
2665 /****************************************************************************/
2667 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2672 val = REG_RD_IND(sc, cpu_reg->mode);
2673 val |= cpu_reg->mode_value_halt;
2674 REG_WR_IND(sc, cpu_reg->mode, val);
2675 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2679 /****************************************************************************/
2680 /* Start the RX CPU. */
2684 /****************************************************************************/
2686 bce_start_rxp_cpu(struct bce_softc *sc)
2688 struct cpu_reg cpu_reg;
2690 cpu_reg.mode = BCE_RXP_CPU_MODE;
2691 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2692 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2693 cpu_reg.state = BCE_RXP_CPU_STATE;
2694 cpu_reg.state_value_clear = 0xffffff;
2695 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2696 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2697 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2698 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2699 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2700 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2701 cpu_reg.mips_view_base = 0x8000000;
2703 bce_start_cpu(sc, &cpu_reg);
2707 /****************************************************************************/
2708 /* Initialize the RX CPU. */
2712 /****************************************************************************/
2714 bce_init_rxp_cpu(struct bce_softc *sc)
2716 struct cpu_reg cpu_reg;
2719 cpu_reg.mode = BCE_RXP_CPU_MODE;
2720 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2721 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2722 cpu_reg.state = BCE_RXP_CPU_STATE;
2723 cpu_reg.state_value_clear = 0xffffff;
2724 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2725 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2726 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2727 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2728 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2729 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2730 cpu_reg.mips_view_base = 0x8000000;
2732 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2733 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2734 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2735 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2736 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2737 fw.start_addr = bce_RXP_b09FwStartAddr;
2739 fw.text_addr = bce_RXP_b09FwTextAddr;
2740 fw.text_len = bce_RXP_b09FwTextLen;
2742 fw.text = bce_RXP_b09FwText;
2744 fw.data_addr = bce_RXP_b09FwDataAddr;
2745 fw.data_len = bce_RXP_b09FwDataLen;
2747 fw.data = bce_RXP_b09FwData;
2749 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2750 fw.sbss_len = bce_RXP_b09FwSbssLen;
2752 fw.sbss = bce_RXP_b09FwSbss;
2754 fw.bss_addr = bce_RXP_b09FwBssAddr;
2755 fw.bss_len = bce_RXP_b09FwBssLen;
2757 fw.bss = bce_RXP_b09FwBss;
2759 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2760 fw.rodata_len = bce_RXP_b09FwRodataLen;
2761 fw.rodata_index = 0;
2762 fw.rodata = bce_RXP_b09FwRodata;
2764 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2765 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2766 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2767 fw.start_addr = bce_RXP_b06FwStartAddr;
2769 fw.text_addr = bce_RXP_b06FwTextAddr;
2770 fw.text_len = bce_RXP_b06FwTextLen;
2772 fw.text = bce_RXP_b06FwText;
2774 fw.data_addr = bce_RXP_b06FwDataAddr;
2775 fw.data_len = bce_RXP_b06FwDataLen;
2777 fw.data = bce_RXP_b06FwData;
2779 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2780 fw.sbss_len = bce_RXP_b06FwSbssLen;
2782 fw.sbss = bce_RXP_b06FwSbss;
2784 fw.bss_addr = bce_RXP_b06FwBssAddr;
2785 fw.bss_len = bce_RXP_b06FwBssLen;
2787 fw.bss = bce_RXP_b06FwBss;
2789 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2790 fw.rodata_len = bce_RXP_b06FwRodataLen;
2791 fw.rodata_index = 0;
2792 fw.rodata = bce_RXP_b06FwRodata;
2795 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2796 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2797 /* Delay RXP start until initialization is complete. */
2801 /****************************************************************************/
2802 /* Initialize the TX CPU. */
2806 /****************************************************************************/
2808 bce_init_txp_cpu(struct bce_softc *sc)
2810 struct cpu_reg cpu_reg;
2813 cpu_reg.mode = BCE_TXP_CPU_MODE;
2814 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2815 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2816 cpu_reg.state = BCE_TXP_CPU_STATE;
2817 cpu_reg.state_value_clear = 0xffffff;
2818 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2819 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2820 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2821 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2822 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2823 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2824 cpu_reg.mips_view_base = 0x8000000;
2826 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2827 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2828 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2829 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2830 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2831 fw.start_addr = bce_TXP_b09FwStartAddr;
2833 fw.text_addr = bce_TXP_b09FwTextAddr;
2834 fw.text_len = bce_TXP_b09FwTextLen;
2836 fw.text = bce_TXP_b09FwText;
2838 fw.data_addr = bce_TXP_b09FwDataAddr;
2839 fw.data_len = bce_TXP_b09FwDataLen;
2841 fw.data = bce_TXP_b09FwData;
2843 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2844 fw.sbss_len = bce_TXP_b09FwSbssLen;
2846 fw.sbss = bce_TXP_b09FwSbss;
2848 fw.bss_addr = bce_TXP_b09FwBssAddr;
2849 fw.bss_len = bce_TXP_b09FwBssLen;
2851 fw.bss = bce_TXP_b09FwBss;
2853 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2854 fw.rodata_len = bce_TXP_b09FwRodataLen;
2855 fw.rodata_index = 0;
2856 fw.rodata = bce_TXP_b09FwRodata;
2858 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2859 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2860 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2861 fw.start_addr = bce_TXP_b06FwStartAddr;
2863 fw.text_addr = bce_TXP_b06FwTextAddr;
2864 fw.text_len = bce_TXP_b06FwTextLen;
2866 fw.text = bce_TXP_b06FwText;
2868 fw.data_addr = bce_TXP_b06FwDataAddr;
2869 fw.data_len = bce_TXP_b06FwDataLen;
2871 fw.data = bce_TXP_b06FwData;
2873 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2874 fw.sbss_len = bce_TXP_b06FwSbssLen;
2876 fw.sbss = bce_TXP_b06FwSbss;
2878 fw.bss_addr = bce_TXP_b06FwBssAddr;
2879 fw.bss_len = bce_TXP_b06FwBssLen;
2881 fw.bss = bce_TXP_b06FwBss;
2883 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2884 fw.rodata_len = bce_TXP_b06FwRodataLen;
2885 fw.rodata_index = 0;
2886 fw.rodata = bce_TXP_b06FwRodata;
2889 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2890 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2891 bce_start_cpu(sc, &cpu_reg);
2895 /****************************************************************************/
2896 /* Initialize the TPAT CPU. */
2900 /****************************************************************************/
2902 bce_init_tpat_cpu(struct bce_softc *sc)
2904 struct cpu_reg cpu_reg;
2907 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2908 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2909 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2910 cpu_reg.state = BCE_TPAT_CPU_STATE;
2911 cpu_reg.state_value_clear = 0xffffff;
2912 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2913 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2914 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2915 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2916 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2917 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2918 cpu_reg.mips_view_base = 0x8000000;
2920 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2921 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2922 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
2923 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
2924 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
2925 fw.start_addr = bce_TPAT_b09FwStartAddr;
2927 fw.text_addr = bce_TPAT_b09FwTextAddr;
2928 fw.text_len = bce_TPAT_b09FwTextLen;
2930 fw.text = bce_TPAT_b09FwText;
2932 fw.data_addr = bce_TPAT_b09FwDataAddr;
2933 fw.data_len = bce_TPAT_b09FwDataLen;
2935 fw.data = bce_TPAT_b09FwData;
2937 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
2938 fw.sbss_len = bce_TPAT_b09FwSbssLen;
2940 fw.sbss = bce_TPAT_b09FwSbss;
2942 fw.bss_addr = bce_TPAT_b09FwBssAddr;
2943 fw.bss_len = bce_TPAT_b09FwBssLen;
2945 fw.bss = bce_TPAT_b09FwBss;
2947 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
2948 fw.rodata_len = bce_TPAT_b09FwRodataLen;
2949 fw.rodata_index = 0;
2950 fw.rodata = bce_TPAT_b09FwRodata;
2952 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2953 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2954 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2955 fw.start_addr = bce_TPAT_b06FwStartAddr;
2957 fw.text_addr = bce_TPAT_b06FwTextAddr;
2958 fw.text_len = bce_TPAT_b06FwTextLen;
2960 fw.text = bce_TPAT_b06FwText;
2962 fw.data_addr = bce_TPAT_b06FwDataAddr;
2963 fw.data_len = bce_TPAT_b06FwDataLen;
2965 fw.data = bce_TPAT_b06FwData;
2967 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2968 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2970 fw.sbss = bce_TPAT_b06FwSbss;
2972 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2973 fw.bss_len = bce_TPAT_b06FwBssLen;
2975 fw.bss = bce_TPAT_b06FwBss;
2977 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2978 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2979 fw.rodata_index = 0;
2980 fw.rodata = bce_TPAT_b06FwRodata;
2983 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2984 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2985 bce_start_cpu(sc, &cpu_reg);
2989 /****************************************************************************/
2990 /* Initialize the CP CPU. */
2994 /****************************************************************************/
2996 bce_init_cp_cpu(struct bce_softc *sc)
2998 struct cpu_reg cpu_reg;
3001 cpu_reg.mode = BCE_CP_CPU_MODE;
3002 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
3003 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
3004 cpu_reg.state = BCE_CP_CPU_STATE;
3005 cpu_reg.state_value_clear = 0xffffff;
3006 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
3007 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
3008 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
3009 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
3010 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
3011 cpu_reg.spad_base = BCE_CP_SCRATCH;
3012 cpu_reg.mips_view_base = 0x8000000;
3014 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3015 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3016 fw.ver_major = bce_CP_b09FwReleaseMajor;
3017 fw.ver_minor = bce_CP_b09FwReleaseMinor;
3018 fw.ver_fix = bce_CP_b09FwReleaseFix;
3019 fw.start_addr = bce_CP_b09FwStartAddr;
3021 fw.text_addr = bce_CP_b09FwTextAddr;
3022 fw.text_len = bce_CP_b09FwTextLen;
3024 fw.text = bce_CP_b09FwText;
3026 fw.data_addr = bce_CP_b09FwDataAddr;
3027 fw.data_len = bce_CP_b09FwDataLen;
3029 fw.data = bce_CP_b09FwData;
3031 fw.sbss_addr = bce_CP_b09FwSbssAddr;
3032 fw.sbss_len = bce_CP_b09FwSbssLen;
3034 fw.sbss = bce_CP_b09FwSbss;
3036 fw.bss_addr = bce_CP_b09FwBssAddr;
3037 fw.bss_len = bce_CP_b09FwBssLen;
3039 fw.bss = bce_CP_b09FwBss;
3041 fw.rodata_addr = bce_CP_b09FwRodataAddr;
3042 fw.rodata_len = bce_CP_b09FwRodataLen;
3043 fw.rodata_index = 0;
3044 fw.rodata = bce_CP_b09FwRodata;
3046 fw.ver_major = bce_CP_b06FwReleaseMajor;
3047 fw.ver_minor = bce_CP_b06FwReleaseMinor;
3048 fw.ver_fix = bce_CP_b06FwReleaseFix;
3049 fw.start_addr = bce_CP_b06FwStartAddr;
3051 fw.text_addr = bce_CP_b06FwTextAddr;
3052 fw.text_len = bce_CP_b06FwTextLen;
3054 fw.text = bce_CP_b06FwText;
3056 fw.data_addr = bce_CP_b06FwDataAddr;
3057 fw.data_len = bce_CP_b06FwDataLen;
3059 fw.data = bce_CP_b06FwData;
3061 fw.sbss_addr = bce_CP_b06FwSbssAddr;
3062 fw.sbss_len = bce_CP_b06FwSbssLen;
3064 fw.sbss = bce_CP_b06FwSbss;
3066 fw.bss_addr = bce_CP_b06FwBssAddr;
3067 fw.bss_len = bce_CP_b06FwBssLen;
3069 fw.bss = bce_CP_b06FwBss;
3071 fw.rodata_addr = bce_CP_b06FwRodataAddr;
3072 fw.rodata_len = bce_CP_b06FwRodataLen;
3073 fw.rodata_index = 0;
3074 fw.rodata = bce_CP_b06FwRodata;
3077 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
3078 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3079 bce_start_cpu(sc, &cpu_reg);
3083 /****************************************************************************/
3084 /* Initialize the COM CPU. */
3088 /****************************************************************************/
3090 bce_init_com_cpu(struct bce_softc *sc)
3092 struct cpu_reg cpu_reg;
3095 cpu_reg.mode = BCE_COM_CPU_MODE;
3096 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3097 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3098 cpu_reg.state = BCE_COM_CPU_STATE;
3099 cpu_reg.state_value_clear = 0xffffff;
3100 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3101 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3102 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3103 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3104 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3105 cpu_reg.spad_base = BCE_COM_SCRATCH;
3106 cpu_reg.mips_view_base = 0x8000000;
3108 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3109 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3110 fw.ver_major = bce_COM_b09FwReleaseMajor;
3111 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3112 fw.ver_fix = bce_COM_b09FwReleaseFix;
3113 fw.start_addr = bce_COM_b09FwStartAddr;
3115 fw.text_addr = bce_COM_b09FwTextAddr;
3116 fw.text_len = bce_COM_b09FwTextLen;
3118 fw.text = bce_COM_b09FwText;
3120 fw.data_addr = bce_COM_b09FwDataAddr;
3121 fw.data_len = bce_COM_b09FwDataLen;
3123 fw.data = bce_COM_b09FwData;
3125 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3126 fw.sbss_len = bce_COM_b09FwSbssLen;
3128 fw.sbss = bce_COM_b09FwSbss;
3130 fw.bss_addr = bce_COM_b09FwBssAddr;
3131 fw.bss_len = bce_COM_b09FwBssLen;
3133 fw.bss = bce_COM_b09FwBss;
3135 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3136 fw.rodata_len = bce_COM_b09FwRodataLen;
3137 fw.rodata_index = 0;
3138 fw.rodata = bce_COM_b09FwRodata;
3140 fw.ver_major = bce_COM_b06FwReleaseMajor;
3141 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3142 fw.ver_fix = bce_COM_b06FwReleaseFix;
3143 fw.start_addr = bce_COM_b06FwStartAddr;
3145 fw.text_addr = bce_COM_b06FwTextAddr;
3146 fw.text_len = bce_COM_b06FwTextLen;
3148 fw.text = bce_COM_b06FwText;
3150 fw.data_addr = bce_COM_b06FwDataAddr;
3151 fw.data_len = bce_COM_b06FwDataLen;
3153 fw.data = bce_COM_b06FwData;
3155 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3156 fw.sbss_len = bce_COM_b06FwSbssLen;
3158 fw.sbss = bce_COM_b06FwSbss;
3160 fw.bss_addr = bce_COM_b06FwBssAddr;
3161 fw.bss_len = bce_COM_b06FwBssLen;
3163 fw.bss = bce_COM_b06FwBss;
3165 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3166 fw.rodata_len = bce_COM_b06FwRodataLen;
3167 fw.rodata_index = 0;
3168 fw.rodata = bce_COM_b06FwRodata;
3171 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3172 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3173 bce_start_cpu(sc, &cpu_reg);
3177 /****************************************************************************/
3178 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3180 /* Loads the firmware for each CPU and starts the CPU. */
3184 /****************************************************************************/
3186 bce_init_cpus(struct bce_softc *sc)
3188 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3189 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3190 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3191 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3192 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3193 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3194 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3196 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3197 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3198 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3199 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3202 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3203 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3204 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3205 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3208 bce_init_rxp_cpu(sc);
3209 bce_init_txp_cpu(sc);
3210 bce_init_tpat_cpu(sc);
3211 bce_init_com_cpu(sc);
3212 bce_init_cp_cpu(sc);
3216 /****************************************************************************/
3217 /* Initialize context memory. */
3219 /* Clears the memory associated with each Context ID (CID). */
3223 /****************************************************************************/
3225 bce_init_ctx(struct bce_softc *sc)
3227 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3228 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3229 /* DRC: Replace this constant value with a #define. */
3230 int i, retry_cnt = 10;
3234 * BCM5709 context memory may be cached
3235 * in host memory so prepare the host memory
3238 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3240 val |= (BCM_PAGE_BITS - 8) << 16;
3241 REG_WR(sc, BCE_CTX_COMMAND, val);
3243 /* Wait for mem init command to complete. */
3244 for (i = 0; i < retry_cnt; i++) {
3245 val = REG_RD(sc, BCE_CTX_COMMAND);
3246 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3250 if (i == retry_cnt) {
3251 device_printf(sc->bce_dev,
3252 "Context memory initialization failed!\n");
3256 for (i = 0; i < sc->ctx_pages; i++) {
3260 * Set the physical address of the context
3263 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3264 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3265 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3266 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3267 BCE_ADDR_HI(sc->ctx_paddr[i]));
3268 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3269 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3272 * Verify that the context memory write was successful.
3274 for (j = 0; j < retry_cnt; j++) {
3275 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3277 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3281 if (j == retry_cnt) {
3282 device_printf(sc->bce_dev,
3283 "Failed to initialize context page!\n");
3288 uint32_t vcid_addr, offset;
3291 * For the 5706/5708, context memory is local to
3292 * the controller, so initialize the controller
3296 vcid_addr = GET_CID_ADDR(96);
3298 vcid_addr -= PHY_CTX_SIZE;
3300 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3301 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3303 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3304 CTX_WR(sc, 0x00, offset, 0);
3306 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3307 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3314 /****************************************************************************/
3315 /* Fetch the permanent MAC address of the controller. */
3319 /****************************************************************************/
3321 bce_get_mac_addr(struct bce_softc *sc)
3323 uint32_t mac_lo = 0, mac_hi = 0;
3326 * The NetXtreme II bootcode populates various NIC
3327 * power-on and runtime configuration items in a
3328 * shared memory area. The factory configured MAC
3329 * address is available from both NVRAM and the
3330 * shared memory area so we'll read the value from
3331 * shared memory for speed.
3334 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3335 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3337 if (mac_lo == 0 && mac_hi == 0) {
3338 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3340 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3341 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3342 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3343 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3344 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3345 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3348 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3352 /****************************************************************************/
3353 /* Program the MAC address. */
3357 /****************************************************************************/
3359 bce_set_mac_addr(struct bce_softc *sc)
3361 const uint8_t *mac_addr = sc->eaddr;
3364 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3367 val = (mac_addr[0] << 8) | mac_addr[1];
3368 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3370 val = (mac_addr[2] << 24) |
3371 (mac_addr[3] << 16) |
3372 (mac_addr[4] << 8) |
3374 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3378 /****************************************************************************/
3379 /* Stop the controller. */
3383 /****************************************************************************/
3385 bce_stop(struct bce_softc *sc)
3387 struct ifnet *ifp = &sc->arpcom.ac_if;
3389 ASSERT_SERIALIZED(ifp->if_serializer);
3391 callout_stop(&sc->bce_tick_callout);
3393 /* Disable the transmit/receive blocks. */
3394 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3395 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3398 bce_disable_intr(sc);
3400 /* Free the RX lists. */
3401 bce_free_rx_chain(sc);
3403 /* Free TX buffers. */
3404 bce_free_tx_chain(sc);
3407 sc->bce_coalchg_mask = 0;
3409 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3415 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3420 /* Wait for pending PCI transactions to complete. */
3421 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3422 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3423 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3424 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3425 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3426 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3430 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3431 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3432 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3433 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3434 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3437 /* Assume bootcode is running. */
3438 sc->bce_fw_timed_out = 0;
3439 sc->bce_drv_cardiac_arrest = 0;
3441 /* Give the firmware a chance to prepare for the reset. */
3442 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3444 if_printf(&sc->arpcom.ac_if,
3445 "Firmware is not ready for reset\n");
3449 /* Set a firmware reminder that this is a soft reset. */
3450 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3451 BCE_DRV_RESET_SIGNATURE_MAGIC);
3453 /* Dummy read to force the chip to complete all current transactions. */
3454 val = REG_RD(sc, BCE_MISC_ID);
3457 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3458 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3459 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3460 REG_RD(sc, BCE_MISC_COMMAND);
3463 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3464 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3466 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3468 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3469 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3470 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3471 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3473 /* Allow up to 30us for reset to complete. */
3474 for (i = 0; i < 10; i++) {
3475 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3476 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3477 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3482 /* Check that reset completed successfully. */
3483 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3484 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3485 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3490 /* Make sure byte swapping is properly configured. */
3491 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3492 if (val != 0x01020304) {
3493 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3497 /* Just completed a reset, assume that firmware is running again. */
3498 sc->bce_fw_timed_out = 0;
3499 sc->bce_drv_cardiac_arrest = 0;
3501 /* Wait for the firmware to finish its initialization. */
3502 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3504 if_printf(&sc->arpcom.ac_if,
3505 "Firmware did not complete initialization!\n");
3512 bce_chipinit(struct bce_softc *sc)
3517 /* Make sure the interrupt is not active. */
3518 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3519 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3522 * Initialize DMA byte/word swapping, configure the number of DMA
3523 * channels and PCI clock compensation delay.
3525 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3526 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3527 #if BYTE_ORDER == BIG_ENDIAN
3528 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3530 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3531 DMA_READ_CHANS << 12 |
3532 DMA_WRITE_CHANS << 16;
3534 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3536 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3537 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3540 * This setting resolves a problem observed on certain Intel PCI
3541 * chipsets that cannot handle multiple outstanding DMA operations.
3542 * See errata E9_5706A1_65.
3544 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3545 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3546 !(sc->bce_flags & BCE_PCIX_FLAG))
3547 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3549 REG_WR(sc, BCE_DMA_CONFIG, val);
3551 /* Enable the RX_V2P and Context state machines before access. */
3552 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3553 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3554 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3555 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3557 /* Initialize context mapping and zero out the quick contexts. */
3558 rc = bce_init_ctx(sc);
3562 /* Initialize the on-boards CPUs */
3565 /* Enable management frames (NC-SI) to flow to the MCP. */
3566 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3567 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) |
3568 BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3569 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3572 /* Prepare NVRAM for access. */
3573 rc = bce_init_nvram(sc);
3577 /* Set the kernel bypass block size */
3578 val = REG_RD(sc, BCE_MQ_CONFIG);
3579 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3580 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3582 /* Enable bins used on the 5709/5716. */
3583 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3584 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3585 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3586 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3587 val |= BCE_MQ_CONFIG_HALT_DIS;
3590 REG_WR(sc, BCE_MQ_CONFIG, val);
3592 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3593 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3594 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3596 /* Set the page size and clear the RV2P processor stall bits. */
3597 val = (BCM_PAGE_BITS - 8) << 24;
3598 REG_WR(sc, BCE_RV2P_CONFIG, val);
3600 /* Configure page size. */
3601 val = REG_RD(sc, BCE_TBDR_CONFIG);
3602 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3603 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3604 REG_WR(sc, BCE_TBDR_CONFIG, val);
3606 /* Set the perfect match control register to default. */
3607 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3613 /****************************************************************************/
3614 /* Initialize the controller in preparation to send/receive traffic. */
3617 /* 0 for success, positive value for failure. */
3618 /****************************************************************************/
3620 bce_blockinit(struct bce_softc *sc)
3625 /* Load the hardware default MAC address. */
3626 bce_set_mac_addr(sc);
3628 /* Set the Ethernet backoff seed value */
3629 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3630 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3631 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3633 sc->last_status_idx = 0;
3634 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3636 /* Set up link change interrupt generation. */
3637 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3639 /* Program the physical address of the status block. */
3640 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3641 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3643 /* Program the physical address of the statistics block. */
3644 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3645 BCE_ADDR_LO(sc->stats_block_paddr));
3646 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3647 BCE_ADDR_HI(sc->stats_block_paddr));
3649 /* Program various host coalescing parameters. */
3650 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3651 (sc->bce_tx_quick_cons_trip_int << 16) |
3652 sc->bce_tx_quick_cons_trip);
3653 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3654 (sc->bce_rx_quick_cons_trip_int << 16) |
3655 sc->bce_rx_quick_cons_trip);
3656 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3657 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3658 REG_WR(sc, BCE_HC_TX_TICKS,
3659 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3660 REG_WR(sc, BCE_HC_RX_TICKS,
3661 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3662 REG_WR(sc, BCE_HC_COM_TICKS,
3663 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3664 REG_WR(sc, BCE_HC_CMD_TICKS,
3665 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3666 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3667 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3668 REG_WR(sc, BCE_HC_CONFIG,
3669 BCE_HC_CONFIG_TX_TMR_MODE |
3670 BCE_HC_CONFIG_COLLECT_STATS);
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 /****************************************************************************/
5381 struct bce_softc *sc = xsc;
5382 struct ifnet *ifp = &sc->arpcom.ac_if;
5383 struct status_block *sblk;
5384 uint16_t hw_rx_cons, hw_tx_cons;
5386 ASSERT_SERIALIZED(ifp->if_serializer);
5388 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5389 DBRUNIF(1, sc->interrupts_generated++);
5391 sblk = sc->status_block;
5394 * If the hardware status block index matches the last value
5395 * read by the driver and we haven't asserted our interrupt
5396 * then there's nothing to do.
5398 if (sblk->status_idx == sc->last_status_idx &&
5399 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
5400 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5403 /* Ack the interrupt and stop others from occuring. */
5404 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5405 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5406 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5409 * Read back to deassert IRQ immediately to avoid too
5410 * many spurious interrupts.
5412 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
5414 /* Check if the hardware has finished any work. */
5415 hw_rx_cons = bce_get_hw_rx_cons(sc);
5416 hw_tx_cons = bce_get_hw_tx_cons(sc);
5418 /* Keep processing data as long as there is work to do. */
5420 uint32_t status_attn_bits;
5422 status_attn_bits = sblk->status_attn_bits;
5424 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5426 "Simulating unexpected status attention bit set.");
5427 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
5429 /* Was it a link change interrupt? */
5430 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5431 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5435 * Clear any transient status updates during link state
5438 REG_WR(sc, BCE_HC_COMMAND,
5439 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5440 REG_RD(sc, BCE_HC_COMMAND);
5444 * If any other attention is asserted then
5445 * the chip is toast.
5447 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5448 (sblk->status_attn_bits_ack &
5449 ~STATUS_ATTN_BITS_LINK_STATE)) {
5450 DBRUN(1, sc->unexpected_attentions++);
5452 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5453 sblk->status_attn_bits);
5456 if (bce_debug_unexpected_attention == 0)
5457 bce_breakpoint(sc));
5463 /* Check for any completed RX frames. */
5464 if (hw_rx_cons != sc->hw_rx_cons)
5465 bce_rx_intr(sc, -1);
5467 /* Check for any completed TX frames. */
5468 if (hw_tx_cons != sc->hw_tx_cons)
5472 * Save the status block index value
5473 * for use during the next interrupt.
5475 sc->last_status_idx = sblk->status_idx;
5478 * Prevent speculative reads from getting
5479 * ahead of the status block.
5481 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
5482 BUS_SPACE_BARRIER_READ);
5485 * If there's no work left then exit the
5486 * interrupt service routine.
5488 hw_rx_cons = bce_get_hw_rx_cons(sc);
5489 hw_tx_cons = bce_get_hw_tx_cons(sc);
5490 if ((hw_rx_cons == sc->hw_rx_cons) && (hw_tx_cons == sc->hw_tx_cons))
5494 /* Re-enable interrupts. */
5495 bce_enable_intr(sc, 0);
5497 if (sc->bce_coalchg_mask)
5498 bce_coal_change(sc);
5500 /* Handle any frames that arrived while handling the interrupt. */
5501 if (!ifq_is_empty(&ifp->if_snd))
5506 /****************************************************************************/
5507 /* Programs the various packet receive modes (broadcast and multicast). */
5511 /****************************************************************************/
5513 bce_set_rx_mode(struct bce_softc *sc)
5515 struct ifnet *ifp = &sc->arpcom.ac_if;
5516 struct ifmultiaddr *ifma;
5517 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5518 uint32_t rx_mode, sort_mode;
5521 ASSERT_SERIALIZED(ifp->if_serializer);
5523 /* Initialize receive mode default settings. */
5524 rx_mode = sc->rx_mode &
5525 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5526 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5527 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5530 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5533 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5534 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5535 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5538 * Check for promiscuous, all multicast, or selected
5539 * multicast address filtering.
5541 if (ifp->if_flags & IFF_PROMISC) {
5542 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5544 /* Enable promiscuous mode. */
5545 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5546 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5547 } else if (ifp->if_flags & IFF_ALLMULTI) {
5548 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5550 /* Enable all multicast addresses. */
5551 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5552 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5555 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5557 /* Accept one or more multicast(s). */
5558 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5560 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5561 if (ifma->ifma_addr->sa_family != AF_LINK)
5564 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5565 ETHER_ADDR_LEN) & 0xFF;
5566 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5569 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5570 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5573 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5576 /* Only make changes if the recive mode has actually changed. */
5577 if (rx_mode != sc->rx_mode) {
5578 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5581 sc->rx_mode = rx_mode;
5582 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5585 /* Disable and clear the exisitng sort before enabling a new sort. */
5586 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5587 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5588 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5592 /****************************************************************************/
5593 /* Called periodically to updates statistics from the controllers */
5594 /* statistics block. */
5598 /****************************************************************************/
5600 bce_stats_update(struct bce_softc *sc)
5602 struct ifnet *ifp = &sc->arpcom.ac_if;
5603 struct statistics_block *stats = sc->stats_block;
5605 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5607 ASSERT_SERIALIZED(ifp->if_serializer);
5610 * Certain controllers don't report carrier sense errors correctly.
5611 * See errata E11_5708CA0_1165.
5613 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5614 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5616 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5620 * Update the sysctl statistics from the hardware statistics.
5622 sc->stat_IfHCInOctets =
5623 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5624 (uint64_t)stats->stat_IfHCInOctets_lo;
5626 sc->stat_IfHCInBadOctets =
5627 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5628 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5630 sc->stat_IfHCOutOctets =
5631 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5632 (uint64_t)stats->stat_IfHCOutOctets_lo;
5634 sc->stat_IfHCOutBadOctets =
5635 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5636 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5638 sc->stat_IfHCInUcastPkts =
5639 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5640 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5642 sc->stat_IfHCInMulticastPkts =
5643 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5644 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5646 sc->stat_IfHCInBroadcastPkts =
5647 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5648 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5650 sc->stat_IfHCOutUcastPkts =
5651 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5652 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5654 sc->stat_IfHCOutMulticastPkts =
5655 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5656 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5658 sc->stat_IfHCOutBroadcastPkts =
5659 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5660 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5662 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5663 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5665 sc->stat_Dot3StatsCarrierSenseErrors =
5666 stats->stat_Dot3StatsCarrierSenseErrors;
5668 sc->stat_Dot3StatsFCSErrors =
5669 stats->stat_Dot3StatsFCSErrors;
5671 sc->stat_Dot3StatsAlignmentErrors =
5672 stats->stat_Dot3StatsAlignmentErrors;
5674 sc->stat_Dot3StatsSingleCollisionFrames =
5675 stats->stat_Dot3StatsSingleCollisionFrames;
5677 sc->stat_Dot3StatsMultipleCollisionFrames =
5678 stats->stat_Dot3StatsMultipleCollisionFrames;
5680 sc->stat_Dot3StatsDeferredTransmissions =
5681 stats->stat_Dot3StatsDeferredTransmissions;
5683 sc->stat_Dot3StatsExcessiveCollisions =
5684 stats->stat_Dot3StatsExcessiveCollisions;
5686 sc->stat_Dot3StatsLateCollisions =
5687 stats->stat_Dot3StatsLateCollisions;
5689 sc->stat_EtherStatsCollisions =
5690 stats->stat_EtherStatsCollisions;
5692 sc->stat_EtherStatsFragments =
5693 stats->stat_EtherStatsFragments;
5695 sc->stat_EtherStatsJabbers =
5696 stats->stat_EtherStatsJabbers;
5698 sc->stat_EtherStatsUndersizePkts =
5699 stats->stat_EtherStatsUndersizePkts;
5701 sc->stat_EtherStatsOverrsizePkts =
5702 stats->stat_EtherStatsOverrsizePkts;
5704 sc->stat_EtherStatsPktsRx64Octets =
5705 stats->stat_EtherStatsPktsRx64Octets;
5707 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5708 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5710 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5711 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5713 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5714 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5716 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5717 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5719 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5720 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5722 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5723 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5725 sc->stat_EtherStatsPktsTx64Octets =
5726 stats->stat_EtherStatsPktsTx64Octets;
5728 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5729 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5731 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5732 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5734 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5735 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5737 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5738 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5740 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5741 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5743 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5744 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5746 sc->stat_XonPauseFramesReceived =
5747 stats->stat_XonPauseFramesReceived;
5749 sc->stat_XoffPauseFramesReceived =
5750 stats->stat_XoffPauseFramesReceived;
5752 sc->stat_OutXonSent =
5753 stats->stat_OutXonSent;
5755 sc->stat_OutXoffSent =
5756 stats->stat_OutXoffSent;
5758 sc->stat_FlowControlDone =
5759 stats->stat_FlowControlDone;
5761 sc->stat_MacControlFramesReceived =
5762 stats->stat_MacControlFramesReceived;
5764 sc->stat_XoffStateEntered =
5765 stats->stat_XoffStateEntered;
5767 sc->stat_IfInFramesL2FilterDiscards =
5768 stats->stat_IfInFramesL2FilterDiscards;
5770 sc->stat_IfInRuleCheckerDiscards =
5771 stats->stat_IfInRuleCheckerDiscards;
5773 sc->stat_IfInFTQDiscards =
5774 stats->stat_IfInFTQDiscards;
5776 sc->stat_IfInMBUFDiscards =
5777 stats->stat_IfInMBUFDiscards;
5779 sc->stat_IfInRuleCheckerP4Hit =
5780 stats->stat_IfInRuleCheckerP4Hit;
5782 sc->stat_CatchupInRuleCheckerDiscards =
5783 stats->stat_CatchupInRuleCheckerDiscards;
5785 sc->stat_CatchupInFTQDiscards =
5786 stats->stat_CatchupInFTQDiscards;
5788 sc->stat_CatchupInMBUFDiscards =
5789 stats->stat_CatchupInMBUFDiscards;
5791 sc->stat_CatchupInRuleCheckerP4Hit =
5792 stats->stat_CatchupInRuleCheckerP4Hit;
5794 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5797 * Update the interface statistics from the
5798 * hardware statistics.
5800 ifp->if_collisions = (u_long)sc->stat_EtherStatsCollisions;
5802 ifp->if_ierrors = (u_long)sc->stat_EtherStatsUndersizePkts +
5803 (u_long)sc->stat_EtherStatsOverrsizePkts +
5804 (u_long)sc->stat_IfInMBUFDiscards +
5805 (u_long)sc->stat_Dot3StatsAlignmentErrors +
5806 (u_long)sc->stat_Dot3StatsFCSErrors +
5807 (u_long)sc->stat_IfInRuleCheckerDiscards +
5808 (u_long)sc->stat_IfInFTQDiscards +
5809 (u_long)sc->com_no_buffers;
5812 (u_long)sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5813 (u_long)sc->stat_Dot3StatsExcessiveCollisions +
5814 (u_long)sc->stat_Dot3StatsLateCollisions;
5816 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5820 /****************************************************************************/
5821 /* Periodic function to notify the bootcode that the driver is still */
5826 /****************************************************************************/
5828 bce_pulse(void *xsc)
5830 struct bce_softc *sc = xsc;
5831 struct ifnet *ifp = &sc->arpcom.ac_if;
5834 lwkt_serialize_enter(ifp->if_serializer);
5836 /* Tell the firmware that the driver is still running. */
5837 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5838 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
5840 /* Update the bootcode condition. */
5841 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
5843 /* Report whether the bootcode still knows the driver is running. */
5844 if (!sc->bce_drv_cardiac_arrest) {
5845 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
5846 sc->bce_drv_cardiac_arrest = 1;
5847 if_printf(ifp, "Bootcode lost the driver pulse! "
5848 "(bc_state = 0x%08X)\n", sc->bc_state);
5852 * Not supported by all bootcode versions.
5853 * (v5.0.11+ and v5.2.1+) Older bootcode
5854 * will require the driver to reset the
5855 * controller to clear this condition.
5857 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
5858 sc->bce_drv_cardiac_arrest = 0;
5859 if_printf(ifp, "Bootcode found the driver pulse! "
5860 "(bc_state = 0x%08X)\n", sc->bc_state);
5864 /* Schedule the next pulse. */
5865 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
5867 lwkt_serialize_exit(ifp->if_serializer);
5871 /****************************************************************************/
5872 /* Periodic function to perform maintenance tasks. */
5876 /****************************************************************************/
5878 bce_tick_serialized(struct bce_softc *sc)
5880 struct ifnet *ifp = &sc->arpcom.ac_if;
5881 struct mii_data *mii;
5883 ASSERT_SERIALIZED(ifp->if_serializer);
5885 /* Update the statistics from the hardware statistics block. */
5886 bce_stats_update(sc);
5888 /* Schedule the next tick. */
5889 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
5891 /* If link is up already up then we're done. */
5895 mii = device_get_softc(sc->bce_miibus);
5898 /* Check if the link has come up. */
5899 if ((mii->mii_media_status & IFM_ACTIVE) &&
5900 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5902 /* Now that link is up, handle any outstanding TX traffic. */
5903 if (!ifq_is_empty(&ifp->if_snd))
5912 struct bce_softc *sc = xsc;
5913 struct ifnet *ifp = &sc->arpcom.ac_if;
5915 lwkt_serialize_enter(ifp->if_serializer);
5916 bce_tick_serialized(sc);
5917 lwkt_serialize_exit(ifp->if_serializer);
5922 /****************************************************************************/
5923 /* Allows the driver state to be dumped through the sysctl interface. */
5926 /* 0 for success, positive value for failure. */
5927 /****************************************************************************/
5929 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5933 struct bce_softc *sc;
5936 error = sysctl_handle_int(oidp, &result, 0, req);
5938 if (error || !req->newptr)
5942 sc = (struct bce_softc *)arg1;
5943 bce_dump_driver_state(sc);
5950 /****************************************************************************/
5951 /* Allows the hardware state to be dumped through the sysctl interface. */
5954 /* 0 for success, positive value for failure. */
5955 /****************************************************************************/
5957 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5961 struct bce_softc *sc;
5964 error = sysctl_handle_int(oidp, &result, 0, req);
5966 if (error || !req->newptr)
5970 sc = (struct bce_softc *)arg1;
5971 bce_dump_hw_state(sc);
5978 /****************************************************************************/
5979 /* Provides a sysctl interface to allows dumping the RX chain. */
5982 /* 0 for success, positive value for failure. */
5983 /****************************************************************************/
5985 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5989 struct bce_softc *sc;
5992 error = sysctl_handle_int(oidp, &result, 0, req);
5994 if (error || !req->newptr)
5998 sc = (struct bce_softc *)arg1;
5999 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
6006 /****************************************************************************/
6007 /* Provides a sysctl interface to allows dumping the TX chain. */
6010 /* 0 for success, positive value for failure. */
6011 /****************************************************************************/
6013 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
6017 struct bce_softc *sc;
6020 error = sysctl_handle_int(oidp, &result, 0, req);
6022 if (error || !req->newptr)
6026 sc = (struct bce_softc *)arg1;
6027 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
6034 /****************************************************************************/
6035 /* Provides a sysctl interface to allow reading arbitrary registers in the */
6036 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6039 /* 0 for success, positive value for failure. */
6040 /****************************************************************************/
6042 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
6044 struct bce_softc *sc;
6046 uint32_t val, result;
6049 error = sysctl_handle_int(oidp, &result, 0, req);
6050 if (error || (req->newptr == NULL))
6053 /* Make sure the register is accessible. */
6054 if (result < 0x8000) {
6055 sc = (struct bce_softc *)arg1;
6056 val = REG_RD(sc, result);
6057 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6059 } else if (result < 0x0280000) {
6060 sc = (struct bce_softc *)arg1;
6061 val = REG_RD_IND(sc, result);
6062 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6069 /****************************************************************************/
6070 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
6071 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6074 /* 0 for success, positive value for failure. */
6075 /****************************************************************************/
6077 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
6079 struct bce_softc *sc;
6085 error = sysctl_handle_int(oidp, &result, 0, req);
6086 if (error || (req->newptr == NULL))
6089 /* Make sure the register is accessible. */
6090 if (result < 0x20) {
6091 sc = (struct bce_softc *)arg1;
6093 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
6094 if_printf(&sc->arpcom.ac_if,
6095 "phy 0x%02X = 0x%04X\n", result, val);
6101 /****************************************************************************/
6102 /* Provides a sysctl interface to forcing the driver to dump state and */
6103 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6106 /* 0 for success, positive value for failure. */
6107 /****************************************************************************/
6109 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
6113 struct bce_softc *sc;
6116 error = sysctl_handle_int(oidp, &result, 0, req);
6118 if (error || !req->newptr)
6122 sc = (struct bce_softc *)arg1;
6131 /****************************************************************************/
6132 /* Adds any sysctl parameters for tuning or debugging purposes. */
6135 /* 0 for success, positive value for failure. */
6136 /****************************************************************************/
6138 bce_add_sysctls(struct bce_softc *sc)
6140 struct sysctl_ctx_list *ctx;
6141 struct sysctl_oid_list *children;
6143 sysctl_ctx_init(&sc->bce_sysctl_ctx);
6144 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
6145 SYSCTL_STATIC_CHILDREN(_hw),
6147 device_get_nameunit(sc->bce_dev),
6149 if (sc->bce_sysctl_tree == NULL) {
6150 device_printf(sc->bce_dev, "can't add sysctl node\n");
6154 ctx = &sc->bce_sysctl_ctx;
6155 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
6157 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
6158 CTLTYPE_INT | CTLFLAG_RW,
6159 sc, 0, bce_sysctl_tx_bds_int, "I",
6160 "Send max coalesced BD count during interrupt");
6161 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
6162 CTLTYPE_INT | CTLFLAG_RW,
6163 sc, 0, bce_sysctl_tx_bds, "I",
6164 "Send max coalesced BD count");
6165 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
6166 CTLTYPE_INT | CTLFLAG_RW,
6167 sc, 0, bce_sysctl_tx_ticks_int, "I",
6168 "Send coalescing ticks during interrupt");
6169 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
6170 CTLTYPE_INT | CTLFLAG_RW,
6171 sc, 0, bce_sysctl_tx_ticks, "I",
6172 "Send coalescing ticks");
6174 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
6175 CTLTYPE_INT | CTLFLAG_RW,
6176 sc, 0, bce_sysctl_rx_bds_int, "I",
6177 "Receive max coalesced BD count during interrupt");
6178 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
6179 CTLTYPE_INT | CTLFLAG_RW,
6180 sc, 0, bce_sysctl_rx_bds, "I",
6181 "Receive max coalesced BD count");
6182 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
6183 CTLTYPE_INT | CTLFLAG_RW,
6184 sc, 0, bce_sysctl_rx_ticks_int, "I",
6185 "Receive coalescing ticks during interrupt");
6186 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
6187 CTLTYPE_INT | CTLFLAG_RW,
6188 sc, 0, bce_sysctl_rx_ticks, "I",
6189 "Receive coalescing ticks");
6192 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6194 CTLFLAG_RD, &sc->rx_low_watermark,
6195 0, "Lowest level of free rx_bd's");
6197 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6199 CTLFLAG_RD, &sc->rx_empty_count,
6200 0, "Number of times the RX chain was empty");
6202 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6204 CTLFLAG_RD, &sc->tx_hi_watermark,
6205 0, "Highest level of used tx_bd's");
6207 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6209 CTLFLAG_RD, &sc->tx_full_count,
6210 0, "Number of times the TX chain was full");
6212 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6213 "l2fhdr_status_errors",
6214 CTLFLAG_RD, &sc->l2fhdr_status_errors,
6215 0, "l2_fhdr status errors");
6217 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6218 "unexpected_attentions",
6219 CTLFLAG_RD, &sc->unexpected_attentions,
6220 0, "unexpected attentions");
6222 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6223 "lost_status_block_updates",
6224 CTLFLAG_RD, &sc->lost_status_block_updates,
6225 0, "lost status block updates");
6227 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6228 "mbuf_alloc_failed",
6229 CTLFLAG_RD, &sc->mbuf_alloc_failed,
6230 0, "mbuf cluster allocation failures");
6233 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6234 "stat_IfHCInOctets",
6235 CTLFLAG_RD, &sc->stat_IfHCInOctets,
6238 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6239 "stat_IfHCInBadOctets",
6240 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
6241 "Bad bytes received");
6243 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6244 "stat_IfHCOutOctets",
6245 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
6248 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6249 "stat_IfHCOutBadOctets",
6250 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
6253 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6254 "stat_IfHCInUcastPkts",
6255 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
6256 "Unicast packets received");
6258 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6259 "stat_IfHCInMulticastPkts",
6260 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
6261 "Multicast packets received");
6263 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6264 "stat_IfHCInBroadcastPkts",
6265 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
6266 "Broadcast packets received");
6268 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6269 "stat_IfHCOutUcastPkts",
6270 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
6271 "Unicast packets sent");
6273 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6274 "stat_IfHCOutMulticastPkts",
6275 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
6276 "Multicast packets sent");
6278 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6279 "stat_IfHCOutBroadcastPkts",
6280 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
6281 "Broadcast packets sent");
6283 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6284 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
6285 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
6286 0, "Internal MAC transmit errors");
6288 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6289 "stat_Dot3StatsCarrierSenseErrors",
6290 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
6291 0, "Carrier sense errors");
6293 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6294 "stat_Dot3StatsFCSErrors",
6295 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
6296 0, "Frame check sequence errors");
6298 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6299 "stat_Dot3StatsAlignmentErrors",
6300 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
6301 0, "Alignment errors");
6303 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6304 "stat_Dot3StatsSingleCollisionFrames",
6305 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
6306 0, "Single Collision Frames");
6308 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6309 "stat_Dot3StatsMultipleCollisionFrames",
6310 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
6311 0, "Multiple Collision Frames");
6313 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6314 "stat_Dot3StatsDeferredTransmissions",
6315 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
6316 0, "Deferred Transmissions");
6318 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6319 "stat_Dot3StatsExcessiveCollisions",
6320 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
6321 0, "Excessive Collisions");
6323 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6324 "stat_Dot3StatsLateCollisions",
6325 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
6326 0, "Late Collisions");
6328 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6329 "stat_EtherStatsCollisions",
6330 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
6333 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6334 "stat_EtherStatsFragments",
6335 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
6338 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6339 "stat_EtherStatsJabbers",
6340 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
6343 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6344 "stat_EtherStatsUndersizePkts",
6345 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
6346 0, "Undersize packets");
6348 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6349 "stat_EtherStatsOverrsizePkts",
6350 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
6351 0, "stat_EtherStatsOverrsizePkts");
6353 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6354 "stat_EtherStatsPktsRx64Octets",
6355 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
6356 0, "Bytes received in 64 byte packets");
6358 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6359 "stat_EtherStatsPktsRx65Octetsto127Octets",
6360 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
6361 0, "Bytes received in 65 to 127 byte packets");
6363 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6364 "stat_EtherStatsPktsRx128Octetsto255Octets",
6365 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
6366 0, "Bytes received in 128 to 255 byte packets");
6368 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6369 "stat_EtherStatsPktsRx256Octetsto511Octets",
6370 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
6371 0, "Bytes received in 256 to 511 byte packets");
6373 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6374 "stat_EtherStatsPktsRx512Octetsto1023Octets",
6375 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
6376 0, "Bytes received in 512 to 1023 byte packets");
6378 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6379 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
6380 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
6381 0, "Bytes received in 1024 t0 1522 byte packets");
6383 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6384 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
6385 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
6386 0, "Bytes received in 1523 to 9022 byte packets");
6388 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6389 "stat_EtherStatsPktsTx64Octets",
6390 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
6391 0, "Bytes sent in 64 byte packets");
6393 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6394 "stat_EtherStatsPktsTx65Octetsto127Octets",
6395 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
6396 0, "Bytes sent in 65 to 127 byte packets");
6398 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6399 "stat_EtherStatsPktsTx128Octetsto255Octets",
6400 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
6401 0, "Bytes sent in 128 to 255 byte packets");
6403 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6404 "stat_EtherStatsPktsTx256Octetsto511Octets",
6405 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
6406 0, "Bytes sent in 256 to 511 byte packets");
6408 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6409 "stat_EtherStatsPktsTx512Octetsto1023Octets",
6410 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
6411 0, "Bytes sent in 512 to 1023 byte packets");
6413 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6414 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
6415 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
6416 0, "Bytes sent in 1024 to 1522 byte packets");
6418 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6419 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
6420 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
6421 0, "Bytes sent in 1523 to 9022 byte packets");
6423 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6424 "stat_XonPauseFramesReceived",
6425 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
6426 0, "XON pause frames receved");
6428 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6429 "stat_XoffPauseFramesReceived",
6430 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
6431 0, "XOFF pause frames received");
6433 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6435 CTLFLAG_RD, &sc->stat_OutXonSent,
6436 0, "XON pause frames sent");
6438 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6440 CTLFLAG_RD, &sc->stat_OutXoffSent,
6441 0, "XOFF pause frames sent");
6443 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6444 "stat_FlowControlDone",
6445 CTLFLAG_RD, &sc->stat_FlowControlDone,
6446 0, "Flow control done");
6448 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6449 "stat_MacControlFramesReceived",
6450 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
6451 0, "MAC control frames received");
6453 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6454 "stat_XoffStateEntered",
6455 CTLFLAG_RD, &sc->stat_XoffStateEntered,
6456 0, "XOFF state entered");
6458 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6459 "stat_IfInFramesL2FilterDiscards",
6460 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
6461 0, "Received L2 packets discarded");
6463 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6464 "stat_IfInRuleCheckerDiscards",
6465 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
6466 0, "Received packets discarded by rule");
6468 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6469 "stat_IfInFTQDiscards",
6470 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
6471 0, "Received packet FTQ discards");
6473 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6474 "stat_IfInMBUFDiscards",
6475 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
6476 0, "Received packets discarded due to lack of controller buffer memory");
6478 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6479 "stat_IfInRuleCheckerP4Hit",
6480 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6481 0, "Received packets rule checker hits");
6483 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6484 "stat_CatchupInRuleCheckerDiscards",
6485 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6486 0, "Received packets discarded in Catchup path");
6488 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6489 "stat_CatchupInFTQDiscards",
6490 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6491 0, "Received packets discarded in FTQ in Catchup path");
6493 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6494 "stat_CatchupInMBUFDiscards",
6495 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6496 0, "Received packets discarded in controller buffer memory in Catchup path");
6498 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6499 "stat_CatchupInRuleCheckerP4Hit",
6500 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6501 0, "Received packets rule checker hits in Catchup path");
6503 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6505 CTLFLAG_RD, &sc->com_no_buffers,
6506 0, "Valid packets received but no RX buffers available");
6509 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6510 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6512 bce_sysctl_driver_state, "I", "Drive state information");
6514 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6515 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6517 bce_sysctl_hw_state, "I", "Hardware state information");
6519 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6520 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6522 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6524 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6525 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
6527 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
6529 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6530 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6532 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6534 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6535 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
6537 bce_sysctl_reg_read, "I", "Register read");
6539 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6540 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
6542 bce_sysctl_phy_read, "I", "PHY register read");
6549 /****************************************************************************/
6550 /* BCE Debug Routines */
6551 /****************************************************************************/
6554 /****************************************************************************/
6555 /* Freezes the controller to allow for a cohesive state dump. */
6559 /****************************************************************************/
6561 bce_freeze_controller(struct bce_softc *sc)
6565 val = REG_RD(sc, BCE_MISC_COMMAND);
6566 val |= BCE_MISC_COMMAND_DISABLE_ALL;
6567 REG_WR(sc, BCE_MISC_COMMAND, val);
6571 /****************************************************************************/
6572 /* Unfreezes the controller after a freeze operation. This may not always */
6573 /* work and the controller will require a reset! */
6577 /****************************************************************************/
6579 bce_unfreeze_controller(struct bce_softc *sc)
6583 val = REG_RD(sc, BCE_MISC_COMMAND);
6584 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6585 REG_WR(sc, BCE_MISC_COMMAND, val);
6589 /****************************************************************************/
6590 /* Prints out information about an mbuf. */
6594 /****************************************************************************/
6596 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6598 struct ifnet *ifp = &sc->arpcom.ac_if;
6599 uint32_t val_hi, val_lo;
6600 struct mbuf *mp = m;
6603 /* Index out of range. */
6604 if_printf(ifp, "mbuf: null pointer\n");
6609 val_hi = BCE_ADDR_HI(mp);
6610 val_lo = BCE_ADDR_LO(mp);
6611 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6612 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6614 if (mp->m_flags & M_EXT)
6616 if (mp->m_flags & M_PKTHDR)
6617 kprintf("M_PKTHDR ");
6618 if (mp->m_flags & M_EOR)
6621 if (mp->m_flags & M_RDONLY)
6622 kprintf("M_RDONLY ");
6625 val_hi = BCE_ADDR_HI(mp->m_data);
6626 val_lo = BCE_ADDR_LO(mp->m_data);
6627 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6629 if (mp->m_flags & M_PKTHDR) {
6630 if_printf(ifp, "- m_pkthdr: flags = ( ");
6631 if (mp->m_flags & M_BCAST)
6632 kprintf("M_BCAST ");
6633 if (mp->m_flags & M_MCAST)
6634 kprintf("M_MCAST ");
6635 if (mp->m_flags & M_FRAG)
6637 if (mp->m_flags & M_FIRSTFRAG)
6638 kprintf("M_FIRSTFRAG ");
6639 if (mp->m_flags & M_LASTFRAG)
6640 kprintf("M_LASTFRAG ");
6642 if (mp->m_flags & M_VLANTAG)
6643 kprintf("M_VLANTAG ");
6646 if (mp->m_flags & M_PROMISC)
6647 kprintf("M_PROMISC ");
6649 kprintf(") csum_flags = ( ");
6650 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6651 kprintf("CSUM_IP ");
6652 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6653 kprintf("CSUM_TCP ");
6654 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6655 kprintf("CSUM_UDP ");
6656 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6657 kprintf("CSUM_IP_FRAGS ");
6658 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6659 kprintf("CSUM_FRAGMENT ");
6661 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6662 kprintf("CSUM_TSO ");
6664 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6665 kprintf("CSUM_IP_CHECKED ");
6666 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6667 kprintf("CSUM_IP_VALID ");
6668 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6669 kprintf("CSUM_DATA_VALID ");
6673 if (mp->m_flags & M_EXT) {
6674 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6675 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6676 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6678 val_hi, val_lo, mp->m_ext.ext_size);
6685 /****************************************************************************/
6686 /* Prints out the mbufs in the TX mbuf chain. */
6690 /****************************************************************************/
6692 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6694 struct ifnet *ifp = &sc->arpcom.ac_if;
6698 "----------------------------"
6700 "----------------------------\n");
6702 for (i = 0; i < count; i++) {
6703 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6704 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6705 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6709 "----------------------------"
6711 "----------------------------\n");
6715 /****************************************************************************/
6716 /* Prints out the mbufs in the RX mbuf chain. */
6720 /****************************************************************************/
6722 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6724 struct ifnet *ifp = &sc->arpcom.ac_if;
6728 "----------------------------"
6730 "----------------------------\n");
6732 for (i = 0; i < count; i++) {
6733 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6734 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6735 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6739 "----------------------------"
6741 "----------------------------\n");
6745 /****************************************************************************/
6746 /* Prints out a tx_bd structure. */
6750 /****************************************************************************/
6752 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6754 struct ifnet *ifp = &sc->arpcom.ac_if;
6756 if (idx > MAX_TX_BD) {
6757 /* Index out of range. */
6758 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6759 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6760 /* TX Chain page pointer. */
6761 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6762 "chain page pointer\n",
6763 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6765 /* Normal tx_bd entry. */
6766 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6768 "vlan tag= 0x%04X, flags = 0x%04X (",
6769 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6770 txbd->tx_bd_mss_nbytes,
6771 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6773 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6774 kprintf(" CONN_FAULT");
6776 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6777 kprintf(" TCP_UDP_CKSUM");
6779 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6780 kprintf(" IP_CKSUM");
6782 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6785 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6786 kprintf(" COAL_NOW");
6788 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6789 kprintf(" DONT_GEN_CRC");
6791 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6794 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6797 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6800 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6801 kprintf(" OPTION_WORD");
6803 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6806 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6814 /****************************************************************************/
6815 /* Prints out a rx_bd structure. */
6819 /****************************************************************************/
6821 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6823 struct ifnet *ifp = &sc->arpcom.ac_if;
6825 if (idx > MAX_RX_BD) {
6826 /* Index out of range. */
6827 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6828 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6829 /* TX Chain page pointer. */
6830 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6831 "chain page pointer\n",
6832 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6834 /* Normal tx_bd entry. */
6835 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6836 "nbytes = 0x%08X, flags = 0x%08X\n",
6837 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6838 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6843 /****************************************************************************/
6844 /* Prints out a l2_fhdr structure. */
6848 /****************************************************************************/
6850 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6852 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6853 "pkt_len = 0x%04X, vlan = 0x%04x, "
6854 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6855 idx, l2fhdr->l2_fhdr_status,
6856 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6857 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6861 /****************************************************************************/
6862 /* Prints out the tx chain. */
6866 /****************************************************************************/
6868 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6870 struct ifnet *ifp = &sc->arpcom.ac_if;
6873 /* First some info about the tx_bd chain structure. */
6875 "----------------------------"
6877 "----------------------------\n");
6879 if_printf(ifp, "page size = 0x%08X, "
6880 "tx chain pages = 0x%08X\n",
6881 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6883 if_printf(ifp, "tx_bd per page = 0x%08X, "
6884 "usable tx_bd per page = 0x%08X\n",
6885 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6886 (uint32_t)USABLE_TX_BD_PER_PAGE);
6888 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6891 "----------------------------"
6893 "----------------------------\n");
6895 /* Now print out the tx_bd's themselves. */
6896 for (i = 0; i < count; i++) {
6899 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6900 bce_dump_txbd(sc, tx_prod, txbd);
6901 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6905 "----------------------------"
6907 "----------------------------\n");
6911 /****************************************************************************/
6912 /* Prints out the rx chain. */
6916 /****************************************************************************/
6918 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6920 struct ifnet *ifp = &sc->arpcom.ac_if;
6923 /* First some info about the tx_bd chain structure. */
6925 "----------------------------"
6927 "----------------------------\n");
6929 if_printf(ifp, "page size = 0x%08X, "
6930 "rx chain pages = 0x%08X\n",
6931 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6933 if_printf(ifp, "rx_bd per page = 0x%08X, "
6934 "usable rx_bd per page = 0x%08X\n",
6935 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6936 (uint32_t)USABLE_RX_BD_PER_PAGE);
6938 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6941 "----------------------------"
6943 "----------------------------\n");
6945 /* Now print out the rx_bd's themselves. */
6946 for (i = 0; i < count; i++) {
6949 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6950 bce_dump_rxbd(sc, rx_prod, rxbd);
6951 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6955 "----------------------------"
6957 "----------------------------\n");
6961 /****************************************************************************/
6962 /* Prints out the status block from host memory. */
6966 /****************************************************************************/
6968 bce_dump_status_block(struct bce_softc *sc)
6970 struct status_block *sblk = sc->status_block;
6971 struct ifnet *ifp = &sc->arpcom.ac_if;
6974 "----------------------------"
6976 "----------------------------\n");
6978 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6980 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6981 sblk->status_attn_bits_ack);
6983 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6984 sblk->status_rx_quick_consumer_index0,
6985 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6987 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6988 sblk->status_tx_quick_consumer_index0,
6989 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6991 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6993 /* Theses indices are not used for normal L2 drivers. */
6994 if (sblk->status_rx_quick_consumer_index1) {
6995 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6996 sblk->status_rx_quick_consumer_index1,
6997 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
7000 if (sblk->status_tx_quick_consumer_index1) {
7001 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
7002 sblk->status_tx_quick_consumer_index1,
7003 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
7006 if (sblk->status_rx_quick_consumer_index2) {
7007 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
7008 sblk->status_rx_quick_consumer_index2,
7009 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
7012 if (sblk->status_tx_quick_consumer_index2) {
7013 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
7014 sblk->status_tx_quick_consumer_index2,
7015 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
7018 if (sblk->status_rx_quick_consumer_index3) {
7019 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
7020 sblk->status_rx_quick_consumer_index3,
7021 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
7024 if (sblk->status_tx_quick_consumer_index3) {
7025 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
7026 sblk->status_tx_quick_consumer_index3,
7027 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
7030 if (sblk->status_rx_quick_consumer_index4 ||
7031 sblk->status_rx_quick_consumer_index5) {
7032 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
7033 sblk->status_rx_quick_consumer_index4,
7034 sblk->status_rx_quick_consumer_index5);
7037 if (sblk->status_rx_quick_consumer_index6 ||
7038 sblk->status_rx_quick_consumer_index7) {
7039 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
7040 sblk->status_rx_quick_consumer_index6,
7041 sblk->status_rx_quick_consumer_index7);
7044 if (sblk->status_rx_quick_consumer_index8 ||
7045 sblk->status_rx_quick_consumer_index9) {
7046 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
7047 sblk->status_rx_quick_consumer_index8,
7048 sblk->status_rx_quick_consumer_index9);
7051 if (sblk->status_rx_quick_consumer_index10 ||
7052 sblk->status_rx_quick_consumer_index11) {
7053 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
7054 sblk->status_rx_quick_consumer_index10,
7055 sblk->status_rx_quick_consumer_index11);
7058 if (sblk->status_rx_quick_consumer_index12 ||
7059 sblk->status_rx_quick_consumer_index13) {
7060 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
7061 sblk->status_rx_quick_consumer_index12,
7062 sblk->status_rx_quick_consumer_index13);
7065 if (sblk->status_rx_quick_consumer_index14 ||
7066 sblk->status_rx_quick_consumer_index15) {
7067 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
7068 sblk->status_rx_quick_consumer_index14,
7069 sblk->status_rx_quick_consumer_index15);
7072 if (sblk->status_completion_producer_index ||
7073 sblk->status_cmd_consumer_index) {
7074 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
7075 sblk->status_completion_producer_index,
7076 sblk->status_cmd_consumer_index);
7080 "----------------------------"
7082 "----------------------------\n");
7086 /****************************************************************************/
7087 /* Prints out the statistics block. */
7091 /****************************************************************************/
7093 bce_dump_stats_block(struct bce_softc *sc)
7095 struct statistics_block *sblk = sc->stats_block;
7096 struct ifnet *ifp = &sc->arpcom.ac_if;
7100 " Stats Block (All Stats Not Shown Are 0) "
7101 "---------------\n");
7103 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
7104 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
7105 sblk->stat_IfHCInOctets_hi,
7106 sblk->stat_IfHCInOctets_lo);
7109 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
7110 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
7111 sblk->stat_IfHCInBadOctets_hi,
7112 sblk->stat_IfHCInBadOctets_lo);
7115 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
7116 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
7117 sblk->stat_IfHCOutOctets_hi,
7118 sblk->stat_IfHCOutOctets_lo);
7121 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
7122 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
7123 sblk->stat_IfHCOutBadOctets_hi,
7124 sblk->stat_IfHCOutBadOctets_lo);
7127 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
7128 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
7129 sblk->stat_IfHCInUcastPkts_hi,
7130 sblk->stat_IfHCInUcastPkts_lo);
7133 if (sblk->stat_IfHCInBroadcastPkts_hi ||
7134 sblk->stat_IfHCInBroadcastPkts_lo) {
7135 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
7136 sblk->stat_IfHCInBroadcastPkts_hi,
7137 sblk->stat_IfHCInBroadcastPkts_lo);
7140 if (sblk->stat_IfHCInMulticastPkts_hi ||
7141 sblk->stat_IfHCInMulticastPkts_lo) {
7142 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
7143 sblk->stat_IfHCInMulticastPkts_hi,
7144 sblk->stat_IfHCInMulticastPkts_lo);
7147 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
7148 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
7149 sblk->stat_IfHCOutUcastPkts_hi,
7150 sblk->stat_IfHCOutUcastPkts_lo);
7153 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
7154 sblk->stat_IfHCOutBroadcastPkts_lo) {
7155 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
7156 sblk->stat_IfHCOutBroadcastPkts_hi,
7157 sblk->stat_IfHCOutBroadcastPkts_lo);
7160 if (sblk->stat_IfHCOutMulticastPkts_hi ||
7161 sblk->stat_IfHCOutMulticastPkts_lo) {
7162 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
7163 sblk->stat_IfHCOutMulticastPkts_hi,
7164 sblk->stat_IfHCOutMulticastPkts_lo);
7167 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
7168 if_printf(ifp, " 0x%08X : "
7169 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
7170 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
7173 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
7174 if_printf(ifp, " 0x%08X : "
7175 "Dot3StatsCarrierSenseErrors\n",
7176 sblk->stat_Dot3StatsCarrierSenseErrors);
7179 if (sblk->stat_Dot3StatsFCSErrors) {
7180 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
7181 sblk->stat_Dot3StatsFCSErrors);
7184 if (sblk->stat_Dot3StatsAlignmentErrors) {
7185 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
7186 sblk->stat_Dot3StatsAlignmentErrors);
7189 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
7190 if_printf(ifp, " 0x%08X : "
7191 "Dot3StatsSingleCollisionFrames\n",
7192 sblk->stat_Dot3StatsSingleCollisionFrames);
7195 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
7196 if_printf(ifp, " 0x%08X : "
7197 "Dot3StatsMultipleCollisionFrames\n",
7198 sblk->stat_Dot3StatsMultipleCollisionFrames);
7201 if (sblk->stat_Dot3StatsDeferredTransmissions) {
7202 if_printf(ifp, " 0x%08X : "
7203 "Dot3StatsDeferredTransmissions\n",
7204 sblk->stat_Dot3StatsDeferredTransmissions);
7207 if (sblk->stat_Dot3StatsExcessiveCollisions) {
7208 if_printf(ifp, " 0x%08X : "
7209 "Dot3StatsExcessiveCollisions\n",
7210 sblk->stat_Dot3StatsExcessiveCollisions);
7213 if (sblk->stat_Dot3StatsLateCollisions) {
7214 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
7215 sblk->stat_Dot3StatsLateCollisions);
7218 if (sblk->stat_EtherStatsCollisions) {
7219 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
7220 sblk->stat_EtherStatsCollisions);
7223 if (sblk->stat_EtherStatsFragments) {
7224 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
7225 sblk->stat_EtherStatsFragments);
7228 if (sblk->stat_EtherStatsJabbers) {
7229 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
7230 sblk->stat_EtherStatsJabbers);
7233 if (sblk->stat_EtherStatsUndersizePkts) {
7234 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
7235 sblk->stat_EtherStatsUndersizePkts);
7238 if (sblk->stat_EtherStatsOverrsizePkts) {
7239 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
7240 sblk->stat_EtherStatsOverrsizePkts);
7243 if (sblk->stat_EtherStatsPktsRx64Octets) {
7244 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
7245 sblk->stat_EtherStatsPktsRx64Octets);
7248 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
7249 if_printf(ifp, " 0x%08X : "
7250 "EtherStatsPktsRx65Octetsto127Octets\n",
7251 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
7254 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
7255 if_printf(ifp, " 0x%08X : "
7256 "EtherStatsPktsRx128Octetsto255Octets\n",
7257 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
7260 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
7261 if_printf(ifp, " 0x%08X : "
7262 "EtherStatsPktsRx256Octetsto511Octets\n",
7263 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
7266 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
7267 if_printf(ifp, " 0x%08X : "
7268 "EtherStatsPktsRx512Octetsto1023Octets\n",
7269 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
7272 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
7273 if_printf(ifp, " 0x%08X : "
7274 "EtherStatsPktsRx1024Octetsto1522Octets\n",
7275 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
7278 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
7279 if_printf(ifp, " 0x%08X : "
7280 "EtherStatsPktsRx1523Octetsto9022Octets\n",
7281 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
7284 if (sblk->stat_EtherStatsPktsTx64Octets) {
7285 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
7286 sblk->stat_EtherStatsPktsTx64Octets);
7289 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
7290 if_printf(ifp, " 0x%08X : "
7291 "EtherStatsPktsTx65Octetsto127Octets\n",
7292 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
7295 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
7296 if_printf(ifp, " 0x%08X : "
7297 "EtherStatsPktsTx128Octetsto255Octets\n",
7298 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
7301 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
7302 if_printf(ifp, " 0x%08X : "
7303 "EtherStatsPktsTx256Octetsto511Octets\n",
7304 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
7307 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
7308 if_printf(ifp, " 0x%08X : "
7309 "EtherStatsPktsTx512Octetsto1023Octets\n",
7310 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
7313 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
7314 if_printf(ifp, " 0x%08X : "
7315 "EtherStatsPktsTx1024Octetsto1522Octets\n",
7316 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
7319 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
7320 if_printf(ifp, " 0x%08X : "
7321 "EtherStatsPktsTx1523Octetsto9022Octets\n",
7322 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
7325 if (sblk->stat_XonPauseFramesReceived) {
7326 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
7327 sblk->stat_XonPauseFramesReceived);
7330 if (sblk->stat_XoffPauseFramesReceived) {
7331 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
7332 sblk->stat_XoffPauseFramesReceived);
7335 if (sblk->stat_OutXonSent) {
7336 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7337 sblk->stat_OutXonSent);
7340 if (sblk->stat_OutXoffSent) {
7341 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7342 sblk->stat_OutXoffSent);
7345 if (sblk->stat_FlowControlDone) {
7346 if_printf(ifp, " 0x%08X : FlowControlDone\n",
7347 sblk->stat_FlowControlDone);
7350 if (sblk->stat_MacControlFramesReceived) {
7351 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
7352 sblk->stat_MacControlFramesReceived);
7355 if (sblk->stat_XoffStateEntered) {
7356 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
7357 sblk->stat_XoffStateEntered);
7360 if (sblk->stat_IfInFramesL2FilterDiscards) {
7361 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
7364 if (sblk->stat_IfInRuleCheckerDiscards) {
7365 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
7366 sblk->stat_IfInRuleCheckerDiscards);
7369 if (sblk->stat_IfInFTQDiscards) {
7370 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
7371 sblk->stat_IfInFTQDiscards);
7374 if (sblk->stat_IfInMBUFDiscards) {
7375 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
7376 sblk->stat_IfInMBUFDiscards);
7379 if (sblk->stat_IfInRuleCheckerP4Hit) {
7380 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
7381 sblk->stat_IfInRuleCheckerP4Hit);
7384 if (sblk->stat_CatchupInRuleCheckerDiscards) {
7385 if_printf(ifp, " 0x%08X : "
7386 "CatchupInRuleCheckerDiscards\n",
7387 sblk->stat_CatchupInRuleCheckerDiscards);
7390 if (sblk->stat_CatchupInFTQDiscards) {
7391 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
7392 sblk->stat_CatchupInFTQDiscards);
7395 if (sblk->stat_CatchupInMBUFDiscards) {
7396 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
7397 sblk->stat_CatchupInMBUFDiscards);
7400 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
7401 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
7402 sblk->stat_CatchupInRuleCheckerP4Hit);
7406 "----------------------------"
7408 "----------------------------\n");
7412 /****************************************************************************/
7413 /* Prints out a summary of the driver state. */
7417 /****************************************************************************/
7419 bce_dump_driver_state(struct bce_softc *sc)
7421 struct ifnet *ifp = &sc->arpcom.ac_if;
7422 uint32_t val_hi, val_lo;
7425 "-----------------------------"
7427 "-----------------------------\n");
7429 val_hi = BCE_ADDR_HI(sc);
7430 val_lo = BCE_ADDR_LO(sc);
7431 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
7432 "virtual address\n", val_hi, val_lo);
7434 val_hi = BCE_ADDR_HI(sc->status_block);
7435 val_lo = BCE_ADDR_LO(sc->status_block);
7436 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
7437 "virtual address\n", val_hi, val_lo);
7439 val_hi = BCE_ADDR_HI(sc->stats_block);
7440 val_lo = BCE_ADDR_LO(sc->stats_block);
7441 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
7442 "virtual address\n", val_hi, val_lo);
7444 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
7445 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
7446 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
7447 "virtual adddress\n", val_hi, val_lo);
7449 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
7450 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
7451 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
7452 "virtual address\n", val_hi, val_lo);
7454 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
7455 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
7456 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
7457 "virtual address\n", val_hi, val_lo);
7459 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
7460 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
7461 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
7462 "virtual address\n", val_hi, val_lo);
7464 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
7465 "h/w intrs\n", sc->interrupts_generated);
7467 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
7468 "rx interrupts handled\n", sc->rx_interrupts);
7470 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
7471 "tx interrupts handled\n", sc->tx_interrupts);
7473 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
7474 "status block index\n", sc->last_status_idx);
7476 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
7477 "tx producer index\n",
7478 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
7480 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
7481 "tx consumer index\n",
7482 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
7484 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
7485 "tx producer bseq index\n", sc->tx_prod_bseq);
7487 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
7488 "rx producer index\n",
7489 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
7491 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
7492 "rx consumer index\n",
7493 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
7495 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
7496 "rx producer bseq index\n", sc->rx_prod_bseq);
7498 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7499 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7501 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
7502 "free rx_bd's\n", sc->free_rx_bd);
7504 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
7505 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
7507 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
7508 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
7510 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7511 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7513 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
7516 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
7517 sc->tx_hi_watermark, sc->max_tx_bd);
7519 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
7520 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
7523 "----------------------------"
7525 "----------------------------\n");
7529 /****************************************************************************/
7530 /* Prints out the hardware state through a summary of important registers, */
7531 /* followed by a complete register dump. */
7535 /****************************************************************************/
7537 bce_dump_hw_state(struct bce_softc *sc)
7539 struct ifnet *ifp = &sc->arpcom.ac_if;
7544 "----------------------------"
7546 "----------------------------\n");
7548 if_printf(ifp, "%s - bootcode version\n", sc->bce_bc_ver);
7550 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
7551 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
7552 val1, BCE_MISC_ENABLE_STATUS_BITS);
7554 val1 = REG_RD(sc, BCE_DMA_STATUS);
7555 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
7557 val1 = REG_RD(sc, BCE_CTX_STATUS);
7558 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
7560 val1 = REG_RD(sc, BCE_EMAC_STATUS);
7561 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
7562 val1, BCE_EMAC_STATUS);
7564 val1 = REG_RD(sc, BCE_RPM_STATUS);
7565 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
7567 val1 = REG_RD(sc, BCE_TBDR_STATUS);
7568 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
7569 val1, BCE_TBDR_STATUS);
7571 val1 = REG_RD(sc, BCE_TDMA_STATUS);
7572 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
7573 val1, BCE_TDMA_STATUS);
7575 val1 = REG_RD(sc, BCE_HC_STATUS);
7576 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7578 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7579 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7580 val1, BCE_TXP_CPU_STATE);
7582 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7583 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7584 val1, BCE_TPAT_CPU_STATE);
7586 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7587 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7588 val1, BCE_RXP_CPU_STATE);
7590 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7591 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7592 val1, BCE_COM_CPU_STATE);
7594 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7595 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7596 val1, BCE_MCP_CPU_STATE);
7598 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7599 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7600 val1, BCE_CP_CPU_STATE);
7603 "----------------------------"
7605 "----------------------------\n");
7608 "----------------------------"
7610 "----------------------------\n");
7612 for (i = 0x400; i < 0x8000; i += 0x10) {
7613 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7615 REG_RD(sc, i + 0x4),
7616 REG_RD(sc, i + 0x8),
7617 REG_RD(sc, i + 0xc));
7621 "----------------------------"
7623 "----------------------------\n");
7627 /****************************************************************************/
7628 /* Prints out the TXP state. */
7632 /****************************************************************************/
7634 bce_dump_txp_state(struct bce_softc *sc)
7636 struct ifnet *ifp = &sc->arpcom.ac_if;
7641 "----------------------------"
7643 "----------------------------\n");
7645 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7646 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7647 val1, BCE_TXP_CPU_MODE);
7649 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7650 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7651 val1, BCE_TXP_CPU_STATE);
7653 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7654 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7655 val1, BCE_TXP_CPU_EVENT_MASK);
7658 "----------------------------"
7660 "----------------------------\n");
7662 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7663 /* Skip the big blank spaces */
7664 if (i < 0x454000 && i > 0x5ffff) {
7665 if_printf(ifp, "0x%04X: "
7666 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7668 REG_RD_IND(sc, i + 0x4),
7669 REG_RD_IND(sc, i + 0x8),
7670 REG_RD_IND(sc, i + 0xc));
7675 "----------------------------"
7677 "----------------------------\n");
7681 /****************************************************************************/
7682 /* Prints out the RXP state. */
7686 /****************************************************************************/
7688 bce_dump_rxp_state(struct bce_softc *sc)
7690 struct ifnet *ifp = &sc->arpcom.ac_if;
7695 "----------------------------"
7697 "----------------------------\n");
7699 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7700 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7701 val1, BCE_RXP_CPU_MODE);
7703 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7704 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7705 val1, BCE_RXP_CPU_STATE);
7707 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7708 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7709 val1, BCE_RXP_CPU_EVENT_MASK);
7712 "----------------------------"
7714 "----------------------------\n");
7716 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7717 /* Skip the big blank sapces */
7718 if (i < 0xc5400 && i > 0xdffff) {
7719 if_printf(ifp, "0x%04X: "
7720 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7722 REG_RD_IND(sc, i + 0x4),
7723 REG_RD_IND(sc, i + 0x8),
7724 REG_RD_IND(sc, i + 0xc));
7729 "----------------------------"
7731 "----------------------------\n");
7735 /****************************************************************************/
7736 /* Prints out the TPAT state. */
7740 /****************************************************************************/
7742 bce_dump_tpat_state(struct bce_softc *sc)
7744 struct ifnet *ifp = &sc->arpcom.ac_if;
7749 "----------------------------"
7751 "----------------------------\n");
7753 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7754 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7755 val1, BCE_TPAT_CPU_MODE);
7757 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7758 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7759 val1, BCE_TPAT_CPU_STATE);
7761 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7762 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7763 val1, BCE_TPAT_CPU_EVENT_MASK);
7766 "----------------------------"
7768 "----------------------------\n");
7770 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7771 /* Skip the big blank spaces */
7772 if (i < 0x854000 && i > 0x9ffff) {
7773 if_printf(ifp, "0x%04X: "
7774 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7776 REG_RD_IND(sc, i + 0x4),
7777 REG_RD_IND(sc, i + 0x8),
7778 REG_RD_IND(sc, i + 0xc));
7783 "----------------------------"
7785 "----------------------------\n");
7789 /****************************************************************************/
7790 /* Prints out the driver state and then enters the debugger. */
7794 /****************************************************************************/
7796 bce_breakpoint(struct bce_softc *sc)
7799 bce_freeze_controller(sc);
7802 bce_dump_driver_state(sc);
7803 bce_dump_status_block(sc);
7804 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7805 bce_dump_hw_state(sc);
7806 bce_dump_txp_state(sc);
7809 bce_unfreeze_controller(sc);
7812 /* Call the debugger. */
7816 #endif /* BCE_DEBUG */
7819 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7821 struct bce_softc *sc = arg1;
7823 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7824 &sc->bce_tx_quick_cons_trip_int,
7825 BCE_COALMASK_TX_BDS_INT);
7829 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7831 struct bce_softc *sc = arg1;
7833 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7834 &sc->bce_tx_quick_cons_trip,
7835 BCE_COALMASK_TX_BDS);
7839 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7841 struct bce_softc *sc = arg1;
7843 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7844 &sc->bce_tx_ticks_int,
7845 BCE_COALMASK_TX_TICKS_INT);
7849 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7851 struct bce_softc *sc = arg1;
7853 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7855 BCE_COALMASK_TX_TICKS);
7859 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7861 struct bce_softc *sc = arg1;
7863 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7864 &sc->bce_rx_quick_cons_trip_int,
7865 BCE_COALMASK_RX_BDS_INT);
7869 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7871 struct bce_softc *sc = arg1;
7873 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7874 &sc->bce_rx_quick_cons_trip,
7875 BCE_COALMASK_RX_BDS);
7879 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7881 struct bce_softc *sc = arg1;
7883 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7884 &sc->bce_rx_ticks_int,
7885 BCE_COALMASK_RX_TICKS_INT);
7889 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7891 struct bce_softc *sc = arg1;
7893 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7895 BCE_COALMASK_RX_TICKS);
7899 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7900 uint32_t coalchg_mask)
7902 struct bce_softc *sc = arg1;
7903 struct ifnet *ifp = &sc->arpcom.ac_if;
7906 lwkt_serialize_enter(ifp->if_serializer);
7909 error = sysctl_handle_int(oidp, &v, 0, req);
7910 if (!error && req->newptr != NULL) {
7915 sc->bce_coalchg_mask |= coalchg_mask;
7919 lwkt_serialize_exit(ifp->if_serializer);
7924 bce_coal_change(struct bce_softc *sc)
7926 struct ifnet *ifp = &sc->arpcom.ac_if;
7928 ASSERT_SERIALIZED(ifp->if_serializer);
7930 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7931 sc->bce_coalchg_mask = 0;
7935 if (sc->bce_coalchg_mask &
7936 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7937 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7938 (sc->bce_tx_quick_cons_trip_int << 16) |
7939 sc->bce_tx_quick_cons_trip);
7941 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7942 sc->bce_tx_quick_cons_trip,
7943 sc->bce_tx_quick_cons_trip_int);
7947 if (sc->bce_coalchg_mask &
7948 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7949 REG_WR(sc, BCE_HC_TX_TICKS,
7950 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7952 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7953 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7957 if (sc->bce_coalchg_mask &
7958 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7959 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7960 (sc->bce_rx_quick_cons_trip_int << 16) |
7961 sc->bce_rx_quick_cons_trip);
7963 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7964 sc->bce_rx_quick_cons_trip,
7965 sc->bce_rx_quick_cons_trip_int);
7969 if (sc->bce_coalchg_mask &
7970 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7971 REG_WR(sc, BCE_HC_RX_TICKS,
7972 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7974 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7975 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7979 sc->bce_coalchg_mask = 0;