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_init_rxp_cpu(struct bce_softc *);
391 static void bce_init_txp_cpu(struct bce_softc *);
392 static void bce_init_tpat_cpu(struct bce_softc *);
393 static void bce_init_cp_cpu(struct bce_softc *);
394 static void bce_init_com_cpu(struct bce_softc *);
395 static void bce_init_cpus(struct bce_softc *);
397 static void bce_stop(struct bce_softc *);
398 static int bce_reset(struct bce_softc *, uint32_t);
399 static int bce_chipinit(struct bce_softc *);
400 static int bce_blockinit(struct bce_softc *);
401 static int bce_newbuf_std(struct bce_softc *, uint16_t *, uint16_t *,
403 static void bce_setup_rxdesc_std(struct bce_softc *, uint16_t, uint32_t *);
404 static void bce_probe_pci_caps(struct bce_softc *);
405 static void bce_print_adapter_info(struct bce_softc *);
406 static void bce_get_media(struct bce_softc *);
408 static void bce_init_tx_context(struct bce_softc *);
409 static int bce_init_tx_chain(struct bce_softc *);
410 static void bce_init_rx_context(struct bce_softc *);
411 static int bce_init_rx_chain(struct bce_softc *);
412 static void bce_free_rx_chain(struct bce_softc *);
413 static void bce_free_tx_chain(struct bce_softc *);
415 static int bce_encap(struct bce_softc *, struct mbuf **);
416 static void bce_start(struct ifnet *);
417 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
418 static void bce_watchdog(struct ifnet *);
419 static int bce_ifmedia_upd(struct ifnet *);
420 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
421 static void bce_init(void *);
422 static void bce_mgmt_init(struct bce_softc *);
424 static void bce_init_ctx(struct bce_softc *);
425 static void bce_get_mac_addr(struct bce_softc *);
426 static void bce_set_mac_addr(struct bce_softc *);
427 static void bce_phy_intr(struct bce_softc *);
428 static void bce_rx_intr(struct bce_softc *, int);
429 static void bce_tx_intr(struct bce_softc *);
430 static void bce_disable_intr(struct bce_softc *);
431 static void bce_enable_intr(struct bce_softc *, int);
433 #ifdef DEVICE_POLLING
434 static void bce_poll(struct ifnet *, enum poll_cmd, int);
436 static void bce_intr(void *);
437 static void bce_set_rx_mode(struct bce_softc *);
438 static void bce_stats_update(struct bce_softc *);
439 static void bce_tick(void *);
440 static void bce_tick_serialized(struct bce_softc *);
441 static void bce_pulse(void *);
442 static void bce_add_sysctls(struct bce_softc *);
444 static void bce_coal_change(struct bce_softc *);
445 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
446 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
447 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
448 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
449 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
450 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
451 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
452 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
453 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
454 uint32_t *, uint32_t);
458 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
459 * takes 1023 as the TX ticks limit. However, using 1023 will
460 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
461 * there is _no_ network activity on the NIC.
463 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
464 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
465 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
466 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
467 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
468 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
469 static uint32_t bce_rx_ticks_int = 125; /* bcm: 18 */
470 static uint32_t bce_rx_ticks = 125; /* bcm: 18 */
472 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
473 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
474 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
475 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
476 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
477 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
478 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
479 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
481 /****************************************************************************/
482 /* DragonFly device dispatch table. */
483 /****************************************************************************/
484 static device_method_t bce_methods[] = {
485 /* Device interface */
486 DEVMETHOD(device_probe, bce_probe),
487 DEVMETHOD(device_attach, bce_attach),
488 DEVMETHOD(device_detach, bce_detach),
489 DEVMETHOD(device_shutdown, bce_shutdown),
492 DEVMETHOD(bus_print_child, bus_generic_print_child),
493 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
496 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
497 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
498 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
503 static driver_t bce_driver = {
506 sizeof(struct bce_softc)
509 static devclass_t bce_devclass;
512 DECLARE_DUMMY_MODULE(if_bce);
513 MODULE_DEPEND(bce, miibus, 1, 1, 1);
514 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
515 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
518 /****************************************************************************/
519 /* Device probe function. */
521 /* Compares the device to the driver's list of supported devices and */
522 /* reports back to the OS whether this is the right driver for the device. */
525 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
526 /****************************************************************************/
528 bce_probe(device_t dev)
531 uint16_t vid, did, svid, sdid;
533 /* Get the data for the device to be probed. */
534 vid = pci_get_vendor(dev);
535 did = pci_get_device(dev);
536 svid = pci_get_subvendor(dev);
537 sdid = pci_get_subdevice(dev);
539 /* Look through the list of known devices for a match. */
540 for (t = bce_devs; t->bce_name != NULL; ++t) {
541 if (vid == t->bce_vid && did == t->bce_did &&
542 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
543 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
544 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
547 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
549 /* Print out the device identity. */
550 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
552 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
554 device_set_desc_copy(dev, descbuf);
555 kfree(descbuf, M_TEMP);
563 /****************************************************************************/
564 /* PCI Capabilities Probe Function. */
566 /* Walks the PCI capabiites list for the device to find what features are */
571 /****************************************************************************/
573 bce_print_adapter_info(struct bce_softc *sc)
575 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
577 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
578 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
581 if (sc->bce_flags & BCE_PCIE_FLAG) {
582 kprintf("Bus (PCIe x%d, ", sc->link_width);
583 switch (sc->link_speed) {
585 kprintf("2.5Gbps); ");
591 kprintf("Unknown link speed); ");
595 kprintf("Bus (PCI%s, %s, %dMHz); ",
596 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
597 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
601 /* Firmware version and device features. */
602 kprintf("B/C (%s)", sc->bce_bc_ver);
604 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
605 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
607 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
608 kprintf("MFW[%s]", sc->bce_mfw_ver);
609 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
617 /****************************************************************************/
618 /* PCI Capabilities Probe Function. */
620 /* Walks the PCI capabiites list for the device to find what features are */
625 /****************************************************************************/
627 bce_probe_pci_caps(struct bce_softc *sc)
629 device_t dev = sc->bce_dev;
632 if (pci_is_pcix(dev))
633 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
635 ptr = pci_get_pciecap_ptr(dev);
637 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
639 sc->link_speed = link_status & 0xf;
640 sc->link_width = (link_status >> 4) & 0x3f;
641 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
642 sc->bce_flags |= BCE_PCIE_FLAG;
647 /****************************************************************************/
648 /* Device attach function. */
650 /* Allocates device resources, performs secondary chip identification, */
651 /* resets and initializes the hardware, and initializes driver instance */
655 /* 0 on success, positive value on failure. */
656 /****************************************************************************/
658 bce_attach(device_t dev)
660 struct bce_softc *sc = device_get_softc(dev);
661 struct ifnet *ifp = &sc->arpcom.ac_if;
670 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
672 pci_enable_busmaster(dev);
674 bce_probe_pci_caps(sc);
676 /* Allocate PCI memory resources. */
678 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
679 RF_ACTIVE | PCI_RF_DENSE);
680 if (sc->bce_res_mem == NULL) {
681 device_printf(dev, "PCI memory allocation failed\n");
684 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
685 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
687 /* Allocate PCI IRQ resources. */
689 count = pci_msi_count(dev);
690 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
692 sc->bce_flags |= BCE_USING_MSI_FLAG;
696 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
697 RF_SHAREABLE | RF_ACTIVE);
698 if (sc->bce_res_irq == NULL) {
699 device_printf(dev, "PCI map interrupt failed\n");
705 * Configure byte swap and enable indirect register access.
706 * Rely on CPU to do target byte swapping on big endian systems.
707 * Access to registers outside of PCI configurtion space are not
708 * valid until this is done.
710 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
711 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
712 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
714 /* Save ASIC revsion info. */
715 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
717 /* Weed out any non-production controller revisions. */
718 switch (BCE_CHIP_ID(sc)) {
719 case BCE_CHIP_ID_5706_A0:
720 case BCE_CHIP_ID_5706_A1:
721 case BCE_CHIP_ID_5708_A0:
722 case BCE_CHIP_ID_5708_B0:
723 case BCE_CHIP_ID_5709_A0:
724 case BCE_CHIP_ID_5709_B0:
725 case BCE_CHIP_ID_5709_B1:
727 /* 5709C B2 seems to work fine */
728 case BCE_CHIP_ID_5709_B2:
730 device_printf(dev, "Unsupported chip id 0x%08x!\n",
737 * Find the base address for shared memory access.
738 * Newer versions of bootcode use a signature and offset
739 * while older versions use a fixed address.
741 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
742 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
743 BCE_SHM_HDR_SIGNATURE_SIG) {
744 /* Multi-port devices use different offsets in shared memory. */
745 sc->bce_shmem_base = REG_RD_IND(sc,
746 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
748 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
750 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
752 /* Fetch the bootcode revision. */
753 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
754 for (i = 0, j = 0; i < 3; i++) {
758 num = (uint8_t)(val >> (24 - (i * 8)));
759 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
760 if (num >= k || !skip0 || k == 1) {
761 sc->bce_bc_ver[j++] = (num / k) + '0';
766 sc->bce_bc_ver[j++] = '.';
769 /* Check if any management firwmare is running. */
770 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
771 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
772 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
774 /* Allow time for firmware to enter the running state. */
775 for (i = 0; i < 30; i++) {
776 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
777 if (val & BCE_CONDITION_MFW_RUN_MASK)
783 /* Check the current bootcode state. */
784 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
785 BCE_CONDITION_MFW_RUN_MASK;
786 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
787 val != BCE_CONDITION_MFW_RUN_NONE) {
788 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
790 for (i = 0, j = 0; j < 3; j++) {
791 val = bce_reg_rd_ind(sc, addr + j * 4);
793 memcpy(&sc->bce_mfw_ver[i], &val, 4);
798 /* Get PCI bus information (speed and type). */
799 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
800 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
803 sc->bce_flags |= BCE_PCIX_FLAG;
805 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
806 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
808 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
809 sc->bus_speed_mhz = 133;
812 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
813 sc->bus_speed_mhz = 100;
816 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
817 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
818 sc->bus_speed_mhz = 66;
821 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
822 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
823 sc->bus_speed_mhz = 50;
826 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
827 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
828 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
829 sc->bus_speed_mhz = 33;
833 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
834 sc->bus_speed_mhz = 66;
836 sc->bus_speed_mhz = 33;
839 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
840 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
842 /* Reset the controller. */
843 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
847 /* Initialize the controller. */
848 rc = bce_chipinit(sc);
850 device_printf(dev, "Controller initialization failed!\n");
854 /* Perform NVRAM test. */
855 rc = bce_nvram_test(sc);
857 device_printf(dev, "NVRAM test failed!\n");
861 /* Fetch the permanent Ethernet MAC address. */
862 bce_get_mac_addr(sc);
865 * Trip points control how many BDs
866 * should be ready before generating an
867 * interrupt while ticks control how long
868 * a BD can sit in the chain before
869 * generating an interrupt. Set the default
870 * values for the RX and TX rings.
874 /* Force more frequent interrupts. */
875 sc->bce_tx_quick_cons_trip_int = 1;
876 sc->bce_tx_quick_cons_trip = 1;
877 sc->bce_tx_ticks_int = 0;
878 sc->bce_tx_ticks = 0;
880 sc->bce_rx_quick_cons_trip_int = 1;
881 sc->bce_rx_quick_cons_trip = 1;
882 sc->bce_rx_ticks_int = 0;
883 sc->bce_rx_ticks = 0;
885 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
886 sc->bce_tx_quick_cons_trip = bce_tx_bds;
887 sc->bce_tx_ticks_int = bce_tx_ticks_int;
888 sc->bce_tx_ticks = bce_tx_ticks;
890 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
891 sc->bce_rx_quick_cons_trip = bce_rx_bds;
892 sc->bce_rx_ticks_int = bce_rx_ticks_int;
893 sc->bce_rx_ticks = bce_rx_ticks;
896 /* Update statistics once every second. */
897 sc->bce_stats_ticks = 1000000 & 0xffff00;
899 /* Find the media type for the adapter. */
902 /* Allocate DMA memory resources. */
903 rc = bce_dma_alloc(sc);
905 device_printf(dev, "DMA resource allocation failed!\n");
909 /* Initialize the ifnet interface. */
911 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
912 ifp->if_ioctl = bce_ioctl;
913 ifp->if_start = bce_start;
914 ifp->if_init = bce_init;
915 ifp->if_watchdog = bce_watchdog;
916 #ifdef DEVICE_POLLING
917 ifp->if_poll = bce_poll;
919 ifp->if_mtu = ETHERMTU;
920 ifp->if_hwassist = BCE_IF_HWASSIST;
921 ifp->if_capabilities = BCE_IF_CAPABILITIES;
922 ifp->if_capenable = ifp->if_capabilities;
923 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
924 ifq_set_ready(&ifp->if_snd);
926 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
927 ifp->if_baudrate = IF_Gbps(2.5);
929 ifp->if_baudrate = IF_Gbps(1);
931 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
932 sc->mbuf_alloc_size = MCLBYTES;
934 /* Look for our PHY. */
935 rc = mii_phy_probe(dev, &sc->bce_miibus,
936 bce_ifmedia_upd, bce_ifmedia_sts);
938 device_printf(dev, "PHY probe failed!\n");
942 /* Attach to the Ethernet interface list. */
943 ether_ifattach(ifp, sc->eaddr, NULL);
945 callout_init(&sc->bce_tick_callout);
946 callout_init(&sc->bce_pulse_callout);
948 /* Hookup IRQ last. */
949 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, bce_intr, sc,
950 &sc->bce_intrhand, ifp->if_serializer);
952 device_printf(dev, "Failed to setup IRQ!\n");
957 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
958 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
960 /* Print some important debugging info. */
961 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
963 /* Add the supported sysctls to the kernel. */
967 * The chip reset earlier notified the bootcode that
968 * a driver is present. We now need to start our pulse
969 * routine so that the bootcode is reminded that we're
974 /* Get the firmware running so IPMI still works */
977 bce_print_adapter_info(sc);
986 /****************************************************************************/
987 /* Device detach function. */
989 /* Stops the controller, resets the controller, and releases resources. */
992 /* 0 on success, positive value on failure. */
993 /****************************************************************************/
995 bce_detach(device_t dev)
997 struct bce_softc *sc = device_get_softc(dev);
999 if (device_is_attached(dev)) {
1000 struct ifnet *ifp = &sc->arpcom.ac_if;
1003 /* Stop and reset the controller. */
1004 lwkt_serialize_enter(ifp->if_serializer);
1005 callout_stop(&sc->bce_pulse_callout);
1007 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1008 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1010 msg = BCE_DRV_MSG_CODE_UNLOAD;
1012 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1013 lwkt_serialize_exit(ifp->if_serializer);
1015 ether_ifdetach(ifp);
1018 /* If we have a child device on the MII bus remove it too. */
1020 device_delete_child(dev, sc->bce_miibus);
1021 bus_generic_detach(dev);
1023 if (sc->bce_res_irq != NULL) {
1024 bus_release_resource(dev, SYS_RES_IRQ,
1025 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
1030 if (sc->bce_flags & BCE_USING_MSI_FLAG)
1031 pci_release_msi(dev);
1034 if (sc->bce_res_mem != NULL) {
1035 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1041 if (sc->bce_sysctl_tree != NULL)
1042 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1048 /****************************************************************************/
1049 /* Device shutdown function. */
1051 /* Stops and resets the controller. */
1055 /****************************************************************************/
1057 bce_shutdown(device_t dev)
1059 struct bce_softc *sc = device_get_softc(dev);
1060 struct ifnet *ifp = &sc->arpcom.ac_if;
1063 lwkt_serialize_enter(ifp->if_serializer);
1065 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1066 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1068 msg = BCE_DRV_MSG_CODE_UNLOAD;
1070 lwkt_serialize_exit(ifp->if_serializer);
1074 /****************************************************************************/
1075 /* Indirect register read. */
1077 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1078 /* configuration space. Using this mechanism avoids issues with posted */
1079 /* reads but is much slower than memory-mapped I/O. */
1082 /* The value of the register. */
1083 /****************************************************************************/
1085 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1087 device_t dev = sc->bce_dev;
1089 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1093 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1094 DBPRINT(sc, BCE_EXCESSIVE,
1095 "%s(); offset = 0x%08X, val = 0x%08X\n",
1096 __func__, offset, val);
1100 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1105 /****************************************************************************/
1106 /* Indirect register write. */
1108 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1109 /* configuration space. Using this mechanism avoids issues with posted */
1110 /* writes but is muchh slower than memory-mapped I/O. */
1114 /****************************************************************************/
1116 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1118 device_t dev = sc->bce_dev;
1120 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1121 __func__, offset, val);
1123 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1124 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1128 /****************************************************************************/
1129 /* Shared memory write. */
1131 /* Writes NetXtreme II shared memory region. */
1135 /****************************************************************************/
1137 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1139 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1143 /****************************************************************************/
1144 /* Shared memory read. */
1146 /* Reads NetXtreme II shared memory region. */
1149 /* The 32 bit value read. */
1150 /****************************************************************************/
1152 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1154 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1158 /****************************************************************************/
1159 /* Context memory write. */
1161 /* The NetXtreme II controller uses context memory to track connection */
1162 /* information for L2 and higher network protocols. */
1166 /****************************************************************************/
1168 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1171 uint32_t idx, offset = ctx_offset + cid_addr;
1172 uint32_t val, retry_cnt = 5;
1174 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1175 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1176 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1177 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1179 for (idx = 0; idx < retry_cnt; idx++) {
1180 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1181 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1186 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1187 device_printf(sc->bce_dev,
1188 "Unable to write CTX memory: "
1189 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1190 cid_addr, ctx_offset);
1193 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1194 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1199 /****************************************************************************/
1200 /* PHY register read. */
1202 /* Implements register reads on the MII bus. */
1205 /* The value of the register. */
1206 /****************************************************************************/
1208 bce_miibus_read_reg(device_t dev, int phy, int reg)
1210 struct bce_softc *sc = device_get_softc(dev);
1214 /* Make sure we are accessing the correct PHY address. */
1215 if (phy != sc->bce_phy_addr) {
1216 DBPRINT(sc, BCE_VERBOSE,
1217 "Invalid PHY address %d for PHY read!\n", phy);
1221 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1222 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1223 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1225 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1226 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1231 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1232 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1233 BCE_EMAC_MDIO_COMM_START_BUSY;
1234 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1236 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1239 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1240 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1243 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1244 val &= BCE_EMAC_MDIO_COMM_DATA;
1249 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1250 if_printf(&sc->arpcom.ac_if,
1251 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1255 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1258 DBPRINT(sc, BCE_EXCESSIVE,
1259 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1260 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1262 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1263 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1264 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1266 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1267 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1271 return (val & 0xffff);
1275 /****************************************************************************/
1276 /* PHY register write. */
1278 /* Implements register writes on the MII bus. */
1281 /* The value of the register. */
1282 /****************************************************************************/
1284 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1286 struct bce_softc *sc = device_get_softc(dev);
1290 /* Make sure we are accessing the correct PHY address. */
1291 if (phy != sc->bce_phy_addr) {
1292 DBPRINT(sc, BCE_WARN,
1293 "Invalid PHY address %d for PHY write!\n", phy);
1297 DBPRINT(sc, BCE_EXCESSIVE,
1298 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1299 __func__, phy, (uint16_t)(reg & 0xffff),
1300 (uint16_t)(val & 0xffff));
1302 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1303 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1304 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1306 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1307 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1312 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1313 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1314 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1315 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1317 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1320 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1321 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1327 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1328 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1330 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1331 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1332 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1334 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1335 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1343 /****************************************************************************/
1344 /* MII bus status change. */
1346 /* Called by the MII bus driver when the PHY establishes link to set the */
1347 /* MAC interface registers. */
1351 /****************************************************************************/
1353 bce_miibus_statchg(device_t dev)
1355 struct bce_softc *sc = device_get_softc(dev);
1356 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1358 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1359 mii->mii_media_active);
1362 /* Decode the interface media flags. */
1363 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1364 switch(IFM_TYPE(mii->mii_media_active)) {
1366 kprintf("Ethernet )");
1369 kprintf("Unknown )");
1373 kprintf(" Media Options: ( ");
1374 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1376 kprintf("Autoselect )");
1379 kprintf("Manual )");
1385 kprintf("10Base-T )");
1388 kprintf("100Base-TX )");
1391 kprintf("1000Base-SX )");
1394 kprintf("1000Base-T )");
1401 kprintf(" Global Options: (");
1402 if (mii->mii_media_active & IFM_FDX)
1403 kprintf(" FullDuplex");
1404 if (mii->mii_media_active & IFM_HDX)
1405 kprintf(" HalfDuplex");
1406 if (mii->mii_media_active & IFM_LOOP)
1407 kprintf(" Loopback");
1408 if (mii->mii_media_active & IFM_FLAG0)
1410 if (mii->mii_media_active & IFM_FLAG1)
1412 if (mii->mii_media_active & IFM_FLAG2)
1417 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1420 * Set MII or GMII interface based on the speed negotiated
1423 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1424 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1425 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1426 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1428 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1429 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1433 * Set half or full duplex based on the duplicity negotiated
1436 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1437 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1438 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1440 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1441 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1446 /****************************************************************************/
1447 /* Acquire NVRAM lock. */
1449 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1450 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1451 /* for use by the driver. */
1454 /* 0 on success, positive value on failure. */
1455 /****************************************************************************/
1457 bce_acquire_nvram_lock(struct bce_softc *sc)
1462 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1464 /* Request access to the flash interface. */
1465 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1466 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1467 val = REG_RD(sc, BCE_NVM_SW_ARB);
1468 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1474 if (j >= NVRAM_TIMEOUT_COUNT) {
1475 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1482 /****************************************************************************/
1483 /* Release NVRAM lock. */
1485 /* When the caller is finished accessing NVRAM the lock must be released. */
1486 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1487 /* for use by the driver. */
1490 /* 0 on success, positive value on failure. */
1491 /****************************************************************************/
1493 bce_release_nvram_lock(struct bce_softc *sc)
1498 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1501 * Relinquish nvram interface.
1503 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1505 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1506 val = REG_RD(sc, BCE_NVM_SW_ARB);
1507 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1513 if (j >= NVRAM_TIMEOUT_COUNT) {
1514 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1521 /****************************************************************************/
1522 /* Enable NVRAM access. */
1524 /* Before accessing NVRAM for read or write operations the caller must */
1525 /* enabled NVRAM access. */
1529 /****************************************************************************/
1531 bce_enable_nvram_access(struct bce_softc *sc)
1535 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1537 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1538 /* Enable both bits, even on read. */
1539 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1540 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1544 /****************************************************************************/
1545 /* Disable NVRAM access. */
1547 /* When the caller is finished accessing NVRAM access must be disabled. */
1551 /****************************************************************************/
1553 bce_disable_nvram_access(struct bce_softc *sc)
1557 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1559 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1561 /* Disable both bits, even after read. */
1562 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1563 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1567 /****************************************************************************/
1568 /* Read a dword (32 bits) from NVRAM. */
1570 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1571 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1574 /* 0 on success and the 32 bit value read, positive value on failure. */
1575 /****************************************************************************/
1577 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1583 /* Build the command word. */
1584 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1586 /* Calculate the offset for buffered flash. */
1587 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1588 offset = ((offset / sc->bce_flash_info->page_size) <<
1589 sc->bce_flash_info->page_bits) +
1590 (offset % sc->bce_flash_info->page_size);
1594 * Clear the DONE bit separately, set the address to read,
1595 * and issue the read.
1597 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1598 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1599 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1601 /* Wait for completion. */
1602 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1607 val = REG_RD(sc, BCE_NVM_COMMAND);
1608 if (val & BCE_NVM_COMMAND_DONE) {
1609 val = REG_RD(sc, BCE_NVM_READ);
1612 memcpy(ret_val, &val, 4);
1617 /* Check for errors. */
1618 if (i >= NVRAM_TIMEOUT_COUNT) {
1619 if_printf(&sc->arpcom.ac_if,
1620 "Timeout error reading NVRAM at offset 0x%08X!\n",
1628 /****************************************************************************/
1629 /* Initialize NVRAM access. */
1631 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1632 /* access that device. */
1635 /* 0 on success, positive value on failure. */
1636 /****************************************************************************/
1638 bce_init_nvram(struct bce_softc *sc)
1641 int j, entry_count, rc = 0;
1642 const struct flash_spec *flash;
1644 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1646 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1647 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1648 sc->bce_flash_info = &flash_5709;
1649 goto bce_init_nvram_get_flash_size;
1652 /* Determine the selected interface. */
1653 val = REG_RD(sc, BCE_NVM_CFG1);
1655 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1658 * Flash reconfiguration is required to support additional
1659 * NVRAM devices not directly supported in hardware.
1660 * Check if the flash interface was reconfigured
1664 if (val & 0x40000000) {
1665 /* Flash interface reconfigured by bootcode. */
1667 DBPRINT(sc, BCE_INFO_LOAD,
1668 "%s(): Flash WAS reconfigured.\n", __func__);
1670 for (j = 0, flash = flash_table; j < entry_count;
1672 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1673 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1674 sc->bce_flash_info = flash;
1679 /* Flash interface not yet reconfigured. */
1682 DBPRINT(sc, BCE_INFO_LOAD,
1683 "%s(): Flash was NOT reconfigured.\n", __func__);
1685 if (val & (1 << 23))
1686 mask = FLASH_BACKUP_STRAP_MASK;
1688 mask = FLASH_STRAP_MASK;
1690 /* Look for the matching NVRAM device configuration data. */
1691 for (j = 0, flash = flash_table; j < entry_count;
1693 /* Check if the device matches any of the known devices. */
1694 if ((val & mask) == (flash->strapping & mask)) {
1695 /* Found a device match. */
1696 sc->bce_flash_info = flash;
1698 /* Request access to the flash interface. */
1699 rc = bce_acquire_nvram_lock(sc);
1703 /* Reconfigure the flash interface. */
1704 bce_enable_nvram_access(sc);
1705 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1706 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1707 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1708 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1709 bce_disable_nvram_access(sc);
1710 bce_release_nvram_lock(sc);
1716 /* Check if a matching device was found. */
1717 if (j == entry_count) {
1718 sc->bce_flash_info = NULL;
1719 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1723 bce_init_nvram_get_flash_size:
1724 /* Write the flash config data to the shared memory interface. */
1725 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1726 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1728 sc->bce_flash_size = val;
1730 sc->bce_flash_size = sc->bce_flash_info->total_size;
1732 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1733 __func__, sc->bce_flash_info->total_size);
1735 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1741 /****************************************************************************/
1742 /* Read an arbitrary range of data from NVRAM. */
1744 /* Prepares the NVRAM interface for access and reads the requested data */
1745 /* into the supplied buffer. */
1748 /* 0 on success and the data read, positive value on failure. */
1749 /****************************************************************************/
1751 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1754 uint32_t cmd_flags, offset32, len32, extra;
1760 /* Request access to the flash interface. */
1761 rc = bce_acquire_nvram_lock(sc);
1765 /* Enable access to flash interface */
1766 bce_enable_nvram_access(sc);
1774 /* XXX should we release nvram lock if read_dword() fails? */
1780 pre_len = 4 - (offset & 3);
1782 if (pre_len >= len32) {
1784 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1786 cmd_flags = BCE_NVM_COMMAND_FIRST;
1789 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1793 memcpy(ret_buf, buf + (offset & 3), pre_len);
1801 extra = 4 - (len32 & 3);
1802 len32 = (len32 + 4) & ~3;
1809 cmd_flags = BCE_NVM_COMMAND_LAST;
1811 cmd_flags = BCE_NVM_COMMAND_FIRST |
1812 BCE_NVM_COMMAND_LAST;
1814 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1816 memcpy(ret_buf, buf, 4 - extra);
1817 } else if (len32 > 0) {
1820 /* Read the first word. */
1824 cmd_flags = BCE_NVM_COMMAND_FIRST;
1826 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1828 /* Advance to the next dword. */
1833 while (len32 > 4 && rc == 0) {
1834 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1836 /* Advance to the next dword. */
1843 goto bce_nvram_read_locked_exit;
1845 cmd_flags = BCE_NVM_COMMAND_LAST;
1846 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1848 memcpy(ret_buf, buf, 4 - extra);
1851 bce_nvram_read_locked_exit:
1852 /* Disable access to flash interface and release the lock. */
1853 bce_disable_nvram_access(sc);
1854 bce_release_nvram_lock(sc);
1860 /****************************************************************************/
1861 /* Verifies that NVRAM is accessible and contains valid data. */
1863 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1867 /* 0 on success, positive value on failure. */
1868 /****************************************************************************/
1870 bce_nvram_test(struct bce_softc *sc)
1872 uint32_t buf[BCE_NVRAM_SIZE / 4];
1873 uint32_t magic, csum;
1874 uint8_t *data = (uint8_t *)buf;
1878 * Check that the device NVRAM is valid by reading
1879 * the magic value at offset 0.
1881 rc = bce_nvram_read(sc, 0, data, 4);
1885 magic = be32toh(buf[0]);
1886 if (magic != BCE_NVRAM_MAGIC) {
1887 if_printf(&sc->arpcom.ac_if,
1888 "Invalid NVRAM magic value! Expected: 0x%08X, "
1889 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1894 * Verify that the device NVRAM includes valid
1895 * configuration data.
1897 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1901 csum = ether_crc32_le(data, 0x100);
1902 if (csum != BCE_CRC32_RESIDUAL) {
1903 if_printf(&sc->arpcom.ac_if,
1904 "Invalid Manufacturing Information NVRAM CRC! "
1905 "Expected: 0x%08X, Found: 0x%08X\n",
1906 BCE_CRC32_RESIDUAL, csum);
1910 csum = ether_crc32_le(data + 0x100, 0x100);
1911 if (csum != BCE_CRC32_RESIDUAL) {
1912 if_printf(&sc->arpcom.ac_if,
1913 "Invalid Feature Configuration Information "
1914 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1915 BCE_CRC32_RESIDUAL, csum);
1922 /****************************************************************************/
1923 /* Identifies the current media type of the controller and sets the PHY */
1928 /****************************************************************************/
1930 bce_get_media(struct bce_softc *sc)
1934 sc->bce_phy_addr = 1;
1936 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1937 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1938 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1939 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1943 * The BCM5709S is software configurable
1944 * for Copper or SerDes operation.
1946 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1948 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1949 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1953 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1954 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
1957 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
1960 if (pci_get_function(sc->bce_dev) == 0) {
1965 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1973 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1977 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
1978 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1981 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
1982 sc->bce_flags |= BCE_NO_WOL_FLAG;
1983 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
1984 sc->bce_phy_addr = 2;
1985 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
1986 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
1987 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
1989 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
1990 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
1991 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
1996 /****************************************************************************/
1997 /* Free any DMA memory owned by the driver. */
1999 /* Scans through each data structre that requires DMA memory and frees */
2000 /* the memory if allocated. */
2004 /****************************************************************************/
2006 bce_dma_free(struct bce_softc *sc)
2010 /* Destroy the status block. */
2011 if (sc->status_tag != NULL) {
2012 if (sc->status_block != NULL) {
2013 bus_dmamap_unload(sc->status_tag, sc->status_map);
2014 bus_dmamem_free(sc->status_tag, sc->status_block,
2017 bus_dma_tag_destroy(sc->status_tag);
2021 /* Destroy the statistics block. */
2022 if (sc->stats_tag != NULL) {
2023 if (sc->stats_block != NULL) {
2024 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2025 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2028 bus_dma_tag_destroy(sc->stats_tag);
2031 /* Destroy the CTX DMA stuffs. */
2032 if (sc->ctx_tag != NULL) {
2033 for (i = 0; i < sc->ctx_pages; i++) {
2034 if (sc->ctx_block[i] != NULL) {
2035 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2036 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2040 bus_dma_tag_destroy(sc->ctx_tag);
2043 /* Destroy the TX buffer descriptor DMA stuffs. */
2044 if (sc->tx_bd_chain_tag != NULL) {
2045 for (i = 0; i < TX_PAGES; i++) {
2046 if (sc->tx_bd_chain[i] != NULL) {
2047 bus_dmamap_unload(sc->tx_bd_chain_tag,
2048 sc->tx_bd_chain_map[i]);
2049 bus_dmamem_free(sc->tx_bd_chain_tag,
2051 sc->tx_bd_chain_map[i]);
2054 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2057 /* Destroy the RX buffer descriptor DMA stuffs. */
2058 if (sc->rx_bd_chain_tag != NULL) {
2059 for (i = 0; i < RX_PAGES; i++) {
2060 if (sc->rx_bd_chain[i] != NULL) {
2061 bus_dmamap_unload(sc->rx_bd_chain_tag,
2062 sc->rx_bd_chain_map[i]);
2063 bus_dmamem_free(sc->rx_bd_chain_tag,
2065 sc->rx_bd_chain_map[i]);
2068 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2071 /* Destroy the TX mbuf DMA stuffs. */
2072 if (sc->tx_mbuf_tag != NULL) {
2073 for (i = 0; i < TOTAL_TX_BD; i++) {
2074 /* Must have been unloaded in bce_stop() */
2075 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2076 bus_dmamap_destroy(sc->tx_mbuf_tag,
2077 sc->tx_mbuf_map[i]);
2079 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2082 /* Destroy the RX mbuf DMA stuffs. */
2083 if (sc->rx_mbuf_tag != NULL) {
2084 for (i = 0; i < TOTAL_RX_BD; i++) {
2085 /* Must have been unloaded in bce_stop() */
2086 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2087 bus_dmamap_destroy(sc->rx_mbuf_tag,
2088 sc->rx_mbuf_map[i]);
2090 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2091 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2094 /* Destroy the parent tag */
2095 if (sc->parent_tag != NULL)
2096 bus_dma_tag_destroy(sc->parent_tag);
2100 /****************************************************************************/
2101 /* Get DMA memory from the OS. */
2103 /* Validates that the OS has provided DMA buffers in response to a */
2104 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2105 /* When the callback is used the OS will return 0 for the mapping function */
2106 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2107 /* failures back to the caller. */
2111 /****************************************************************************/
2113 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2115 bus_addr_t *busaddr = arg;
2118 * Simulate a mapping failure.
2121 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2122 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2123 __FILE__, __LINE__);
2126 /* Check for an error and signal the caller that an error occurred. */
2130 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2131 *busaddr = segs->ds_addr;
2135 /****************************************************************************/
2136 /* Allocate any DMA memory needed by the driver. */
2138 /* Allocates DMA memory needed for the various global structures needed by */
2141 /* Memory alignment requirements: */
2142 /* -----------------+----------+----------+----------+----------+ */
2143 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2144 /* -----------------+----------+----------+----------+----------+ */
2145 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2146 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2147 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2148 /* PG Buffers | none | none | none | none | */
2149 /* TX Buffers | none | none | none | none | */
2150 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2151 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2152 /* -----------------+----------+----------+----------+----------+ */
2154 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2157 /* 0 for success, positive value for failure. */
2158 /****************************************************************************/
2160 bce_dma_alloc(struct bce_softc *sc)
2162 struct ifnet *ifp = &sc->arpcom.ac_if;
2164 bus_addr_t busaddr, max_busaddr;
2165 bus_size_t status_align, stats_align;
2168 * The embedded PCIe to PCI-X bridge (EPB)
2169 * in the 5708 cannot address memory above
2170 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2172 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2173 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2175 max_busaddr = BUS_SPACE_MAXADDR;
2178 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2180 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2181 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2182 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2183 if (sc->ctx_pages == 0)
2185 if (sc->ctx_pages > BCE_CTX_PAGES) {
2186 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2198 * Allocate the parent bus DMA tag appropriate for PCI.
2200 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2201 max_busaddr, BUS_SPACE_MAXADDR,
2203 BUS_SPACE_MAXSIZE_32BIT, 0,
2204 BUS_SPACE_MAXSIZE_32BIT,
2205 0, &sc->parent_tag);
2207 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2212 * Allocate status block.
2214 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2215 status_align, BCE_STATUS_BLK_SZ,
2216 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2217 &sc->status_tag, &sc->status_map,
2218 &sc->status_block_paddr);
2219 if (sc->status_block == NULL) {
2220 if_printf(ifp, "Could not allocate status block!\n");
2225 * Allocate statistics block.
2227 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2228 stats_align, BCE_STATS_BLK_SZ,
2229 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2230 &sc->stats_tag, &sc->stats_map,
2231 &sc->stats_block_paddr);
2232 if (sc->stats_block == NULL) {
2233 if_printf(ifp, "Could not allocate statistics block!\n");
2238 * Allocate context block, if needed
2240 if (sc->ctx_pages != 0) {
2241 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2242 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2244 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2247 if_printf(ifp, "Could not allocate "
2248 "context block DMA tag!\n");
2252 for (i = 0; i < sc->ctx_pages; i++) {
2253 rc = bus_dmamem_alloc(sc->ctx_tag,
2254 (void **)&sc->ctx_block[i],
2255 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2259 if_printf(ifp, "Could not allocate %dth context "
2260 "DMA memory!\n", i);
2264 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2265 sc->ctx_block[i], BCM_PAGE_SIZE,
2266 bce_dma_map_addr, &busaddr,
2269 if (rc == EINPROGRESS) {
2270 panic("%s coherent memory loading "
2271 "is still in progress!", ifp->if_xname);
2273 if_printf(ifp, "Could not map %dth context "
2274 "DMA memory!\n", i);
2275 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2277 sc->ctx_block[i] = NULL;
2280 sc->ctx_paddr[i] = busaddr;
2285 * Create a DMA tag for the TX buffer descriptor chain,
2286 * allocate and clear the memory, and fetch the
2287 * physical address of the block.
2289 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2290 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2292 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2293 0, &sc->tx_bd_chain_tag);
2295 if_printf(ifp, "Could not allocate "
2296 "TX descriptor chain DMA tag!\n");
2300 for (i = 0; i < TX_PAGES; i++) {
2301 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2302 (void **)&sc->tx_bd_chain[i],
2303 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2305 &sc->tx_bd_chain_map[i]);
2307 if_printf(ifp, "Could not allocate %dth TX descriptor "
2308 "chain DMA memory!\n", i);
2312 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2313 sc->tx_bd_chain_map[i],
2314 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2315 bce_dma_map_addr, &busaddr,
2318 if (rc == EINPROGRESS) {
2319 panic("%s coherent memory loading "
2320 "is still in progress!", ifp->if_xname);
2322 if_printf(ifp, "Could not map %dth TX descriptor "
2323 "chain DMA memory!\n", i);
2324 bus_dmamem_free(sc->tx_bd_chain_tag,
2326 sc->tx_bd_chain_map[i]);
2327 sc->tx_bd_chain[i] = NULL;
2331 sc->tx_bd_chain_paddr[i] = busaddr;
2332 /* DRC - Fix for 64 bit systems. */
2333 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2334 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2337 /* Create a DMA tag for TX mbufs. */
2338 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2339 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2341 /* BCE_MAX_JUMBO_ETHER_MTU_VLAN */MCLBYTES,
2342 BCE_MAX_SEGMENTS, MCLBYTES,
2343 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2347 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2351 /* Create DMA maps for the TX mbufs clusters. */
2352 for (i = 0; i < TOTAL_TX_BD; i++) {
2353 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2354 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2355 &sc->tx_mbuf_map[i]);
2357 for (j = 0; j < i; ++j) {
2358 bus_dmamap_destroy(sc->tx_mbuf_tag,
2359 sc->tx_mbuf_map[i]);
2361 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2362 sc->tx_mbuf_tag = NULL;
2364 if_printf(ifp, "Unable to create "
2365 "%dth TX mbuf DMA map!\n", i);
2371 * Create a DMA tag for the RX buffer descriptor chain,
2372 * allocate and clear the memory, and fetch the physical
2373 * address of the blocks.
2375 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2376 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2378 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2379 0, &sc->rx_bd_chain_tag);
2381 if_printf(ifp, "Could not allocate "
2382 "RX descriptor chain DMA tag!\n");
2386 for (i = 0; i < RX_PAGES; i++) {
2387 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2388 (void **)&sc->rx_bd_chain[i],
2389 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2391 &sc->rx_bd_chain_map[i]);
2393 if_printf(ifp, "Could not allocate %dth RX descriptor "
2394 "chain DMA memory!\n", i);
2398 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2399 sc->rx_bd_chain_map[i],
2400 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2401 bce_dma_map_addr, &busaddr,
2404 if (rc == EINPROGRESS) {
2405 panic("%s coherent memory loading "
2406 "is still in progress!", ifp->if_xname);
2408 if_printf(ifp, "Could not map %dth RX descriptor "
2409 "chain DMA memory!\n", i);
2410 bus_dmamem_free(sc->rx_bd_chain_tag,
2412 sc->rx_bd_chain_map[i]);
2413 sc->rx_bd_chain[i] = NULL;
2417 sc->rx_bd_chain_paddr[i] = busaddr;
2418 /* DRC - Fix for 64 bit systems. */
2419 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2420 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2423 /* Create a DMA tag for RX mbufs. */
2424 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2425 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2427 MCLBYTES, 1, MCLBYTES,
2428 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2432 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2436 /* Create tmp DMA map for RX mbuf clusters. */
2437 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2438 &sc->rx_mbuf_tmpmap);
2440 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2441 sc->rx_mbuf_tag = NULL;
2443 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2447 /* Create DMA maps for the RX mbuf clusters. */
2448 for (i = 0; i < TOTAL_RX_BD; i++) {
2449 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2450 &sc->rx_mbuf_map[i]);
2452 for (j = 0; j < i; ++j) {
2453 bus_dmamap_destroy(sc->rx_mbuf_tag,
2454 sc->rx_mbuf_map[j]);
2456 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2457 sc->rx_mbuf_tag = NULL;
2459 if_printf(ifp, "Unable to create "
2460 "%dth RX mbuf DMA map!\n", i);
2468 /****************************************************************************/
2469 /* Firmware synchronization. */
2471 /* Before performing certain events such as a chip reset, synchronize with */
2472 /* the firmware first. */
2475 /* 0 for success, positive value for failure. */
2476 /****************************************************************************/
2478 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2483 /* Don't waste any time if we've timed out before. */
2484 if (sc->bce_fw_timed_out)
2487 /* Increment the message sequence number. */
2488 sc->bce_fw_wr_seq++;
2489 msg_data |= sc->bce_fw_wr_seq;
2491 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2493 /* Send the message to the bootcode driver mailbox. */
2494 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2496 /* Wait for the bootcode to acknowledge the message. */
2497 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2498 /* Check for a response in the bootcode firmware mailbox. */
2499 val = bce_shmem_rd(sc, BCE_FW_MB);
2500 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2505 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2506 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2507 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2508 if_printf(&sc->arpcom.ac_if,
2509 "Firmware synchronization timeout! "
2510 "msg_data = 0x%08X\n", msg_data);
2512 msg_data &= ~BCE_DRV_MSG_CODE;
2513 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2515 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2517 sc->bce_fw_timed_out = 1;
2524 /****************************************************************************/
2525 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2529 /****************************************************************************/
2531 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2532 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2537 for (i = 0; i < rv2p_code_len; i += 8) {
2538 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2540 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2543 if (rv2p_proc == RV2P_PROC1) {
2544 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2545 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2547 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2548 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2552 /* Reset the processor, un-stall is done later. */
2553 if (rv2p_proc == RV2P_PROC1)
2554 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2556 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2560 /****************************************************************************/
2561 /* Load RISC processor firmware. */
2563 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2564 /* associated with a particular processor. */
2568 /****************************************************************************/
2570 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2573 uint32_t offset, val;
2577 val = REG_RD_IND(sc, cpu_reg->mode);
2578 val |= cpu_reg->mode_value_halt;
2579 REG_WR_IND(sc, cpu_reg->mode, val);
2580 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2582 /* Load the Text area. */
2583 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2585 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2586 REG_WR_IND(sc, offset, fw->text[j]);
2589 /* Load the Data area. */
2590 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2592 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2593 REG_WR_IND(sc, offset, fw->data[j]);
2596 /* Load the SBSS area. */
2597 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2599 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2600 REG_WR_IND(sc, offset, fw->sbss[j]);
2603 /* Load the BSS area. */
2604 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2606 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2607 REG_WR_IND(sc, offset, fw->bss[j]);
2610 /* Load the Read-Only area. */
2611 offset = cpu_reg->spad_base +
2612 (fw->rodata_addr - cpu_reg->mips_view_base);
2614 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2615 REG_WR_IND(sc, offset, fw->rodata[j]);
2618 /* Clear the pre-fetch instruction. */
2619 REG_WR_IND(sc, cpu_reg->inst, 0);
2620 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2622 /* Start the CPU. */
2623 val = REG_RD_IND(sc, cpu_reg->mode);
2624 val &= ~cpu_reg->mode_value_halt;
2625 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2626 REG_WR_IND(sc, cpu_reg->mode, val);
2630 /****************************************************************************/
2631 /* Initialize the RX CPU. */
2635 /****************************************************************************/
2637 bce_init_rxp_cpu(struct bce_softc *sc)
2639 struct cpu_reg cpu_reg;
2642 cpu_reg.mode = BCE_RXP_CPU_MODE;
2643 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2644 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2645 cpu_reg.state = BCE_RXP_CPU_STATE;
2646 cpu_reg.state_value_clear = 0xffffff;
2647 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2648 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2649 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2650 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2651 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2652 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2653 cpu_reg.mips_view_base = 0x8000000;
2655 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2656 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2657 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2658 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2659 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2660 fw.start_addr = bce_RXP_b09FwStartAddr;
2662 fw.text_addr = bce_RXP_b09FwTextAddr;
2663 fw.text_len = bce_RXP_b09FwTextLen;
2665 fw.text = bce_RXP_b09FwText;
2667 fw.data_addr = bce_RXP_b09FwDataAddr;
2668 fw.data_len = bce_RXP_b09FwDataLen;
2670 fw.data = bce_RXP_b09FwData;
2672 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2673 fw.sbss_len = bce_RXP_b09FwSbssLen;
2675 fw.sbss = bce_RXP_b09FwSbss;
2677 fw.bss_addr = bce_RXP_b09FwBssAddr;
2678 fw.bss_len = bce_RXP_b09FwBssLen;
2680 fw.bss = bce_RXP_b09FwBss;
2682 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2683 fw.rodata_len = bce_RXP_b09FwRodataLen;
2684 fw.rodata_index = 0;
2685 fw.rodata = bce_RXP_b09FwRodata;
2687 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2688 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2689 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2690 fw.start_addr = bce_RXP_b06FwStartAddr;
2692 fw.text_addr = bce_RXP_b06FwTextAddr;
2693 fw.text_len = bce_RXP_b06FwTextLen;
2695 fw.text = bce_RXP_b06FwText;
2697 fw.data_addr = bce_RXP_b06FwDataAddr;
2698 fw.data_len = bce_RXP_b06FwDataLen;
2700 fw.data = bce_RXP_b06FwData;
2702 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2703 fw.sbss_len = bce_RXP_b06FwSbssLen;
2705 fw.sbss = bce_RXP_b06FwSbss;
2707 fw.bss_addr = bce_RXP_b06FwBssAddr;
2708 fw.bss_len = bce_RXP_b06FwBssLen;
2710 fw.bss = bce_RXP_b06FwBss;
2712 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2713 fw.rodata_len = bce_RXP_b06FwRodataLen;
2714 fw.rodata_index = 0;
2715 fw.rodata = bce_RXP_b06FwRodata;
2718 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2719 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2723 /****************************************************************************/
2724 /* Initialize the TX CPU. */
2728 /****************************************************************************/
2730 bce_init_txp_cpu(struct bce_softc *sc)
2732 struct cpu_reg cpu_reg;
2735 cpu_reg.mode = BCE_TXP_CPU_MODE;
2736 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2737 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2738 cpu_reg.state = BCE_TXP_CPU_STATE;
2739 cpu_reg.state_value_clear = 0xffffff;
2740 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2741 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2742 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2743 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2744 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2745 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2746 cpu_reg.mips_view_base = 0x8000000;
2748 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2749 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2750 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2751 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2752 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2753 fw.start_addr = bce_TXP_b09FwStartAddr;
2755 fw.text_addr = bce_TXP_b09FwTextAddr;
2756 fw.text_len = bce_TXP_b09FwTextLen;
2758 fw.text = bce_TXP_b09FwText;
2760 fw.data_addr = bce_TXP_b09FwDataAddr;
2761 fw.data_len = bce_TXP_b09FwDataLen;
2763 fw.data = bce_TXP_b09FwData;
2765 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2766 fw.sbss_len = bce_TXP_b09FwSbssLen;
2768 fw.sbss = bce_TXP_b09FwSbss;
2770 fw.bss_addr = bce_TXP_b09FwBssAddr;
2771 fw.bss_len = bce_TXP_b09FwBssLen;
2773 fw.bss = bce_TXP_b09FwBss;
2775 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2776 fw.rodata_len = bce_TXP_b09FwRodataLen;
2777 fw.rodata_index = 0;
2778 fw.rodata = bce_TXP_b09FwRodata;
2780 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2781 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2782 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2783 fw.start_addr = bce_TXP_b06FwStartAddr;
2785 fw.text_addr = bce_TXP_b06FwTextAddr;
2786 fw.text_len = bce_TXP_b06FwTextLen;
2788 fw.text = bce_TXP_b06FwText;
2790 fw.data_addr = bce_TXP_b06FwDataAddr;
2791 fw.data_len = bce_TXP_b06FwDataLen;
2793 fw.data = bce_TXP_b06FwData;
2795 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2796 fw.sbss_len = bce_TXP_b06FwSbssLen;
2798 fw.sbss = bce_TXP_b06FwSbss;
2800 fw.bss_addr = bce_TXP_b06FwBssAddr;
2801 fw.bss_len = bce_TXP_b06FwBssLen;
2803 fw.bss = bce_TXP_b06FwBss;
2805 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2806 fw.rodata_len = bce_TXP_b06FwRodataLen;
2807 fw.rodata_index = 0;
2808 fw.rodata = bce_TXP_b06FwRodata;
2811 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2812 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2816 /****************************************************************************/
2817 /* Initialize the TPAT CPU. */
2821 /****************************************************************************/
2823 bce_init_tpat_cpu(struct bce_softc *sc)
2825 struct cpu_reg cpu_reg;
2828 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2829 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2830 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2831 cpu_reg.state = BCE_TPAT_CPU_STATE;
2832 cpu_reg.state_value_clear = 0xffffff;
2833 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2834 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2835 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2836 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2837 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2838 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2839 cpu_reg.mips_view_base = 0x8000000;
2841 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2842 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2843 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
2844 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
2845 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
2846 fw.start_addr = bce_TPAT_b09FwStartAddr;
2848 fw.text_addr = bce_TPAT_b09FwTextAddr;
2849 fw.text_len = bce_TPAT_b09FwTextLen;
2851 fw.text = bce_TPAT_b09FwText;
2853 fw.data_addr = bce_TPAT_b09FwDataAddr;
2854 fw.data_len = bce_TPAT_b09FwDataLen;
2856 fw.data = bce_TPAT_b09FwData;
2858 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
2859 fw.sbss_len = bce_TPAT_b09FwSbssLen;
2861 fw.sbss = bce_TPAT_b09FwSbss;
2863 fw.bss_addr = bce_TPAT_b09FwBssAddr;
2864 fw.bss_len = bce_TPAT_b09FwBssLen;
2866 fw.bss = bce_TPAT_b09FwBss;
2868 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
2869 fw.rodata_len = bce_TPAT_b09FwRodataLen;
2870 fw.rodata_index = 0;
2871 fw.rodata = bce_TPAT_b09FwRodata;
2873 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2874 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2875 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2876 fw.start_addr = bce_TPAT_b06FwStartAddr;
2878 fw.text_addr = bce_TPAT_b06FwTextAddr;
2879 fw.text_len = bce_TPAT_b06FwTextLen;
2881 fw.text = bce_TPAT_b06FwText;
2883 fw.data_addr = bce_TPAT_b06FwDataAddr;
2884 fw.data_len = bce_TPAT_b06FwDataLen;
2886 fw.data = bce_TPAT_b06FwData;
2888 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2889 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2891 fw.sbss = bce_TPAT_b06FwSbss;
2893 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2894 fw.bss_len = bce_TPAT_b06FwBssLen;
2896 fw.bss = bce_TPAT_b06FwBss;
2898 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2899 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2900 fw.rodata_index = 0;
2901 fw.rodata = bce_TPAT_b06FwRodata;
2904 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2905 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2909 /****************************************************************************/
2910 /* Initialize the CP CPU. */
2914 /****************************************************************************/
2916 bce_init_cp_cpu(struct bce_softc *sc)
2918 struct cpu_reg cpu_reg;
2921 cpu_reg.mode = BCE_CP_CPU_MODE;
2922 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
2923 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
2924 cpu_reg.state = BCE_CP_CPU_STATE;
2925 cpu_reg.state_value_clear = 0xffffff;
2926 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
2927 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
2928 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
2929 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
2930 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
2931 cpu_reg.spad_base = BCE_CP_SCRATCH;
2932 cpu_reg.mips_view_base = 0x8000000;
2934 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2935 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2936 fw.ver_major = bce_CP_b09FwReleaseMajor;
2937 fw.ver_minor = bce_CP_b09FwReleaseMinor;
2938 fw.ver_fix = bce_CP_b09FwReleaseFix;
2939 fw.start_addr = bce_CP_b09FwStartAddr;
2941 fw.text_addr = bce_CP_b09FwTextAddr;
2942 fw.text_len = bce_CP_b09FwTextLen;
2944 fw.text = bce_CP_b09FwText;
2946 fw.data_addr = bce_CP_b09FwDataAddr;
2947 fw.data_len = bce_CP_b09FwDataLen;
2949 fw.data = bce_CP_b09FwData;
2951 fw.sbss_addr = bce_CP_b09FwSbssAddr;
2952 fw.sbss_len = bce_CP_b09FwSbssLen;
2954 fw.sbss = bce_CP_b09FwSbss;
2956 fw.bss_addr = bce_CP_b09FwBssAddr;
2957 fw.bss_len = bce_CP_b09FwBssLen;
2959 fw.bss = bce_CP_b09FwBss;
2961 fw.rodata_addr = bce_CP_b09FwRodataAddr;
2962 fw.rodata_len = bce_CP_b09FwRodataLen;
2963 fw.rodata_index = 0;
2964 fw.rodata = bce_CP_b09FwRodata;
2966 fw.ver_major = bce_CP_b06FwReleaseMajor;
2967 fw.ver_minor = bce_CP_b06FwReleaseMinor;
2968 fw.ver_fix = bce_CP_b06FwReleaseFix;
2969 fw.start_addr = bce_CP_b06FwStartAddr;
2971 fw.text_addr = bce_CP_b06FwTextAddr;
2972 fw.text_len = bce_CP_b06FwTextLen;
2974 fw.text = bce_CP_b06FwText;
2976 fw.data_addr = bce_CP_b06FwDataAddr;
2977 fw.data_len = bce_CP_b06FwDataLen;
2979 fw.data = bce_CP_b06FwData;
2981 fw.sbss_addr = bce_CP_b06FwSbssAddr;
2982 fw.sbss_len = bce_CP_b06FwSbssLen;
2984 fw.sbss = bce_CP_b06FwSbss;
2986 fw.bss_addr = bce_CP_b06FwBssAddr;
2987 fw.bss_len = bce_CP_b06FwBssLen;
2989 fw.bss = bce_CP_b06FwBss;
2991 fw.rodata_addr = bce_CP_b06FwRodataAddr;
2992 fw.rodata_len = bce_CP_b06FwRodataLen;
2993 fw.rodata_index = 0;
2994 fw.rodata = bce_CP_b06FwRodata;
2997 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
2998 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3002 /****************************************************************************/
3003 /* Initialize the COM CPU. */
3007 /****************************************************************************/
3009 bce_init_com_cpu(struct bce_softc *sc)
3011 struct cpu_reg cpu_reg;
3014 cpu_reg.mode = BCE_COM_CPU_MODE;
3015 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3016 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3017 cpu_reg.state = BCE_COM_CPU_STATE;
3018 cpu_reg.state_value_clear = 0xffffff;
3019 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3020 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3021 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3022 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3023 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3024 cpu_reg.spad_base = BCE_COM_SCRATCH;
3025 cpu_reg.mips_view_base = 0x8000000;
3027 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3028 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3029 fw.ver_major = bce_COM_b09FwReleaseMajor;
3030 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3031 fw.ver_fix = bce_COM_b09FwReleaseFix;
3032 fw.start_addr = bce_COM_b09FwStartAddr;
3034 fw.text_addr = bce_COM_b09FwTextAddr;
3035 fw.text_len = bce_COM_b09FwTextLen;
3037 fw.text = bce_COM_b09FwText;
3039 fw.data_addr = bce_COM_b09FwDataAddr;
3040 fw.data_len = bce_COM_b09FwDataLen;
3042 fw.data = bce_COM_b09FwData;
3044 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3045 fw.sbss_len = bce_COM_b09FwSbssLen;
3047 fw.sbss = bce_COM_b09FwSbss;
3049 fw.bss_addr = bce_COM_b09FwBssAddr;
3050 fw.bss_len = bce_COM_b09FwBssLen;
3052 fw.bss = bce_COM_b09FwBss;
3054 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3055 fw.rodata_len = bce_COM_b09FwRodataLen;
3056 fw.rodata_index = 0;
3057 fw.rodata = bce_COM_b09FwRodata;
3059 fw.ver_major = bce_COM_b06FwReleaseMajor;
3060 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3061 fw.ver_fix = bce_COM_b06FwReleaseFix;
3062 fw.start_addr = bce_COM_b06FwStartAddr;
3064 fw.text_addr = bce_COM_b06FwTextAddr;
3065 fw.text_len = bce_COM_b06FwTextLen;
3067 fw.text = bce_COM_b06FwText;
3069 fw.data_addr = bce_COM_b06FwDataAddr;
3070 fw.data_len = bce_COM_b06FwDataLen;
3072 fw.data = bce_COM_b06FwData;
3074 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3075 fw.sbss_len = bce_COM_b06FwSbssLen;
3077 fw.sbss = bce_COM_b06FwSbss;
3079 fw.bss_addr = bce_COM_b06FwBssAddr;
3080 fw.bss_len = bce_COM_b06FwBssLen;
3082 fw.bss = bce_COM_b06FwBss;
3084 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3085 fw.rodata_len = bce_COM_b06FwRodataLen;
3086 fw.rodata_index = 0;
3087 fw.rodata = bce_COM_b06FwRodata;
3090 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3091 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3095 /****************************************************************************/
3096 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3098 /* Loads the firmware for each CPU and starts the CPU. */
3102 /****************************************************************************/
3104 bce_init_cpus(struct bce_softc *sc)
3106 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3107 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3108 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3109 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3110 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3111 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3112 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3114 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3115 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3116 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3117 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3120 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3121 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3122 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3123 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3126 bce_init_rxp_cpu(sc);
3127 bce_init_txp_cpu(sc);
3128 bce_init_tpat_cpu(sc);
3129 bce_init_com_cpu(sc);
3130 bce_init_cp_cpu(sc);
3134 /****************************************************************************/
3135 /* Initialize context memory. */
3137 /* Clears the memory associated with each Context ID (CID). */
3141 /****************************************************************************/
3143 bce_init_ctx(struct bce_softc *sc)
3145 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3146 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3147 /* DRC: Replace this constant value with a #define. */
3148 int i, retry_cnt = 10;
3152 * BCM5709 context memory may be cached
3153 * in host memory so prepare the host memory
3156 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3158 val |= (BCM_PAGE_BITS - 8) << 16;
3159 REG_WR(sc, BCE_CTX_COMMAND, val);
3161 /* Wait for mem init command to complete. */
3162 for (i = 0; i < retry_cnt; i++) {
3163 val = REG_RD(sc, BCE_CTX_COMMAND);
3164 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3169 for (i = 0; i < sc->ctx_pages; i++) {
3173 * Set the physical address of the context
3176 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3177 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3178 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3179 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3180 BCE_ADDR_HI(sc->ctx_paddr[i]));
3181 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3182 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3185 * Verify that the context memory write was successful.
3187 for (j = 0; j < retry_cnt; j++) {
3188 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3190 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3196 uint32_t vcid_addr, offset;
3199 * For the 5706/5708, context memory is local to
3200 * the controller, so initialize the controller
3204 vcid_addr = GET_CID_ADDR(96);
3206 vcid_addr -= PHY_CTX_SIZE;
3208 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3209 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3211 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3212 CTX_WR(sc, 0x00, offset, 0);
3214 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3215 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3221 /****************************************************************************/
3222 /* Fetch the permanent MAC address of the controller. */
3226 /****************************************************************************/
3228 bce_get_mac_addr(struct bce_softc *sc)
3230 uint32_t mac_lo = 0, mac_hi = 0;
3233 * The NetXtreme II bootcode populates various NIC
3234 * power-on and runtime configuration items in a
3235 * shared memory area. The factory configured MAC
3236 * address is available from both NVRAM and the
3237 * shared memory area so we'll read the value from
3238 * shared memory for speed.
3241 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3242 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3244 if (mac_lo == 0 && mac_hi == 0) {
3245 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3247 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3248 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3249 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3250 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3251 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3252 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3255 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3259 /****************************************************************************/
3260 /* Program the MAC address. */
3264 /****************************************************************************/
3266 bce_set_mac_addr(struct bce_softc *sc)
3268 const uint8_t *mac_addr = sc->eaddr;
3271 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3274 val = (mac_addr[0] << 8) | mac_addr[1];
3275 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3277 val = (mac_addr[2] << 24) |
3278 (mac_addr[3] << 16) |
3279 (mac_addr[4] << 8) |
3281 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3285 /****************************************************************************/
3286 /* Stop the controller. */
3290 /****************************************************************************/
3292 bce_stop(struct bce_softc *sc)
3294 struct ifnet *ifp = &sc->arpcom.ac_if;
3295 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3296 struct ifmedia_entry *ifm;
3299 ASSERT_SERIALIZED(ifp->if_serializer);
3301 callout_stop(&sc->bce_tick_callout);
3303 /* Disable the transmit/receive blocks. */
3304 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3305 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3308 bce_disable_intr(sc);
3310 /* Free the RX lists. */
3311 bce_free_rx_chain(sc);
3313 /* Free TX buffers. */
3314 bce_free_tx_chain(sc);
3317 * Isolate/power down the PHY, but leave the media selection
3318 * unchanged so that things will be put back to normal when
3319 * we bring the interface back up.
3321 * 'mii' may be NULL if bce_stop() is called by bce_detach().
3324 itmp = ifp->if_flags;
3325 ifp->if_flags |= IFF_UP;
3326 ifm = mii->mii_media.ifm_cur;
3327 mtmp = ifm->ifm_media;
3328 ifm->ifm_media = IFM_ETHER | IFM_NONE;
3330 ifm->ifm_media = mtmp;
3331 ifp->if_flags = itmp;
3335 sc->bce_coalchg_mask = 0;
3337 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3343 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3348 /* Wait for pending PCI transactions to complete. */
3349 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3350 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3351 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3352 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3353 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3354 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3358 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3359 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3360 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3361 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3362 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3365 /* Assume bootcode is running. */
3366 sc->bce_fw_timed_out = 0;
3368 /* Give the firmware a chance to prepare for the reset. */
3369 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3371 if_printf(&sc->arpcom.ac_if,
3372 "Firmware is not ready for reset\n");
3376 /* Set a firmware reminder that this is a soft reset. */
3377 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3378 BCE_DRV_RESET_SIGNATURE_MAGIC);
3380 /* Dummy read to force the chip to complete all current transactions. */
3381 val = REG_RD(sc, BCE_MISC_ID);
3384 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3385 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3386 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3387 REG_RD(sc, BCE_MISC_COMMAND);
3390 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3391 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3393 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3395 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3396 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3397 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3398 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3400 /* Allow up to 30us for reset to complete. */
3401 for (i = 0; i < 10; i++) {
3402 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3403 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3404 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3409 /* Check that reset completed successfully. */
3410 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3411 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3412 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3417 /* Make sure byte swapping is properly configured. */
3418 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3419 if (val != 0x01020304) {
3420 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3424 /* Just completed a reset, assume that firmware is running again. */
3425 sc->bce_fw_timed_out = 0;
3427 /* Wait for the firmware to finish its initialization. */
3428 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3430 if_printf(&sc->arpcom.ac_if,
3431 "Firmware did not complete initialization!\n");
3438 bce_chipinit(struct bce_softc *sc)
3443 /* Make sure the interrupt is not active. */
3444 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3445 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3448 * Initialize DMA byte/word swapping, configure the number of DMA
3449 * channels and PCI clock compensation delay.
3451 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3452 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3453 #if BYTE_ORDER == BIG_ENDIAN
3454 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3456 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3457 DMA_READ_CHANS << 12 |
3458 DMA_WRITE_CHANS << 16;
3460 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3462 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3463 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3466 * This setting resolves a problem observed on certain Intel PCI
3467 * chipsets that cannot handle multiple outstanding DMA operations.
3468 * See errata E9_5706A1_65.
3470 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3471 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3472 !(sc->bce_flags & BCE_PCIX_FLAG))
3473 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3475 REG_WR(sc, BCE_DMA_CONFIG, val);
3477 /* Enable the RX_V2P and Context state machines before access. */
3478 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3479 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3480 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3481 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3483 /* Initialize context mapping and zero out the quick contexts. */
3486 /* Initialize the on-boards CPUs */
3489 /* Prepare NVRAM for access. */
3490 rc = bce_init_nvram(sc);
3494 /* Set the kernel bypass block size */
3495 val = REG_RD(sc, BCE_MQ_CONFIG);
3496 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3497 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3499 /* Enable bins used on the 5709/5716. */
3500 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3501 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3502 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3503 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3504 val |= BCE_MQ_CONFIG_HALT_DIS;
3507 REG_WR(sc, BCE_MQ_CONFIG, val);
3509 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3510 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3511 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3513 /* Set the page size and clear the RV2P processor stall bits. */
3514 val = (BCM_PAGE_BITS - 8) << 24;
3515 REG_WR(sc, BCE_RV2P_CONFIG, val);
3517 /* Configure page size. */
3518 val = REG_RD(sc, BCE_TBDR_CONFIG);
3519 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3520 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3521 REG_WR(sc, BCE_TBDR_CONFIG, val);
3523 /* Set the perfect match control register to default. */
3524 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3530 /****************************************************************************/
3531 /* Initialize the controller in preparation to send/receive traffic. */
3534 /* 0 for success, positive value for failure. */
3535 /****************************************************************************/
3537 bce_blockinit(struct bce_softc *sc)
3542 /* Load the hardware default MAC address. */
3543 bce_set_mac_addr(sc);
3545 /* Set the Ethernet backoff seed value */
3546 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3547 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3548 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3550 sc->last_status_idx = 0;
3551 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3553 /* Set up link change interrupt generation. */
3554 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3556 /* Program the physical address of the status block. */
3557 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3558 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3560 /* Program the physical address of the statistics block. */
3561 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3562 BCE_ADDR_LO(sc->stats_block_paddr));
3563 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3564 BCE_ADDR_HI(sc->stats_block_paddr));
3566 /* Program various host coalescing parameters. */
3567 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3568 (sc->bce_tx_quick_cons_trip_int << 16) |
3569 sc->bce_tx_quick_cons_trip);
3570 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3571 (sc->bce_rx_quick_cons_trip_int << 16) |
3572 sc->bce_rx_quick_cons_trip);
3573 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3574 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3575 REG_WR(sc, BCE_HC_TX_TICKS,
3576 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3577 REG_WR(sc, BCE_HC_RX_TICKS,
3578 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3579 REG_WR(sc, BCE_HC_COM_TICKS,
3580 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3581 REG_WR(sc, BCE_HC_CMD_TICKS,
3582 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3583 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3584 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3585 REG_WR(sc, BCE_HC_CONFIG,
3586 BCE_HC_CONFIG_TX_TMR_MODE |
3587 BCE_HC_CONFIG_COLLECT_STATS);
3589 /* Clear the internal statistics counters. */
3590 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3592 /* Verify that bootcode is running. */
3593 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
3595 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3596 if_printf(&sc->arpcom.ac_if,
3597 "%s(%d): Simulating bootcode failure.\n",
3598 __FILE__, __LINE__);
3601 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3602 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3603 if_printf(&sc->arpcom.ac_if,
3604 "Bootcode not running! Found: 0x%08X, "
3605 "Expected: 08%08X\n",
3606 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3607 BCE_DEV_INFO_SIGNATURE_MAGIC);
3612 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3613 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3614 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3615 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3616 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3619 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3620 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3622 /* Enable link state change interrupt generation. */
3623 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3625 /* Enable all remaining blocks in the MAC. */
3626 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3627 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3628 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3629 BCE_MISC_ENABLE_DEFAULT_XI);
3631 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
3633 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3636 /* Save the current host coalescing block settings. */
3637 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
3643 /****************************************************************************/
3644 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3646 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3647 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3651 /* 0 for success, positive value for failure. */
3652 /****************************************************************************/
3654 bce_newbuf_std(struct bce_softc *sc, uint16_t *prod, uint16_t *chain_prod,
3655 uint32_t *prod_bseq, int init)
3658 bus_dma_segment_t seg;
3662 uint16_t debug_chain_prod = *chain_prod;
3665 /* Make sure the inputs are valid. */
3666 DBRUNIF((*chain_prod > MAX_RX_BD),
3667 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3668 "RX producer out of range: 0x%04X > 0x%04X\n",
3670 *chain_prod, (uint16_t)MAX_RX_BD));
3672 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3673 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3675 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3676 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3677 "Simulating mbuf allocation failure.\n",
3678 __FILE__, __LINE__);
3679 sc->mbuf_alloc_failed++;
3682 /* This is a new mbuf allocation. */
3683 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
3686 DBRUNIF(1, sc->rx_mbuf_alloc++);
3688 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3690 /* Map the mbuf cluster into device memory. */
3691 error = bus_dmamap_load_mbuf_segment(sc->rx_mbuf_tag,
3692 sc->rx_mbuf_tmpmap, m_new, &seg, 1, &nseg,
3697 if_printf(&sc->arpcom.ac_if,
3698 "Error mapping mbuf into RX chain!\n");
3700 DBRUNIF(1, sc->rx_mbuf_alloc--);
3704 if (sc->rx_mbuf_ptr[*chain_prod] != NULL) {
3705 bus_dmamap_unload(sc->rx_mbuf_tag,
3706 sc->rx_mbuf_map[*chain_prod]);
3709 map = sc->rx_mbuf_map[*chain_prod];
3710 sc->rx_mbuf_map[*chain_prod] = sc->rx_mbuf_tmpmap;
3711 sc->rx_mbuf_tmpmap = map;
3713 /* Watch for overflow. */
3714 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3715 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3716 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3717 __FILE__, __LINE__, sc->free_rx_bd,
3718 (uint16_t)USABLE_RX_BD));
3720 /* Update some debug statistic counters */
3721 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3722 sc->rx_low_watermark = sc->free_rx_bd);
3723 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3725 /* Save the mbuf and update our counter. */
3726 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3727 sc->rx_mbuf_paddr[*chain_prod] = seg.ds_addr;
3730 bce_setup_rxdesc_std(sc, *chain_prod, prod_bseq);
3732 DBRUN(BCE_VERBOSE_RECV,
3733 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3735 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3736 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3743 bce_setup_rxdesc_std(struct bce_softc *sc, uint16_t chain_prod, uint32_t *prod_bseq)
3749 paddr = sc->rx_mbuf_paddr[chain_prod];
3750 len = sc->rx_mbuf_ptr[chain_prod]->m_len;
3752 /* Setup the rx_bd for the first segment. */
3753 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
3755 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(paddr));
3756 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(paddr));
3757 rxbd->rx_bd_len = htole32(len);
3758 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3761 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3765 /****************************************************************************/
3766 /* Initialize the TX context memory. */
3770 /****************************************************************************/
3772 bce_init_tx_context(struct bce_softc *sc)
3776 /* Initialize the context ID for an L2 TX chain. */
3777 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3778 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3779 /* Set the CID type to support an L2 connection. */
3780 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3781 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
3782 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3783 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE_XI, val);
3785 /* Point the hardware to the first page in the chain. */
3786 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3787 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3788 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
3789 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3790 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3791 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
3793 /* Set the CID type to support an L2 connection. */
3794 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3795 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
3796 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3797 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
3799 /* Point the hardware to the first page in the chain. */
3800 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3801 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3802 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
3803 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3804 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3805 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
3810 /****************************************************************************/
3811 /* Allocate memory and initialize the TX data structures. */
3814 /* 0 for success, positive value for failure. */
3815 /****************************************************************************/
3817 bce_init_tx_chain(struct bce_softc *sc)
3822 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3824 /* Set the initial TX producer/consumer indices. */
3827 sc->tx_prod_bseq = 0;
3829 sc->max_tx_bd = USABLE_TX_BD;
3830 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3831 DBRUNIF(1, sc->tx_full_count = 0);
3834 * The NetXtreme II supports a linked-list structre called
3835 * a Buffer Descriptor Chain (or BD chain). A BD chain
3836 * consists of a series of 1 or more chain pages, each of which
3837 * consists of a fixed number of BD entries.
3838 * The last BD entry on each page is a pointer to the next page
3839 * in the chain, and the last pointer in the BD chain
3840 * points back to the beginning of the chain.
3843 /* Set the TX next pointer chain entries. */
3844 for (i = 0; i < TX_PAGES; i++) {
3847 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3849 /* Check if we've reached the last page. */
3850 if (i == (TX_PAGES - 1))
3855 txbd->tx_bd_haddr_hi =
3856 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3857 txbd->tx_bd_haddr_lo =
3858 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3860 bce_init_tx_context(sc);
3866 /****************************************************************************/
3867 /* Free memory and clear the TX data structures. */
3871 /****************************************************************************/
3873 bce_free_tx_chain(struct bce_softc *sc)
3877 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3879 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3880 for (i = 0; i < TOTAL_TX_BD; i++) {
3881 if (sc->tx_mbuf_ptr[i] != NULL) {
3882 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3883 m_freem(sc->tx_mbuf_ptr[i]);
3884 sc->tx_mbuf_ptr[i] = NULL;
3885 DBRUNIF(1, sc->tx_mbuf_alloc--);
3889 /* Clear each TX chain page. */
3890 for (i = 0; i < TX_PAGES; i++)
3891 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3894 /* Check if we lost any mbufs in the process. */
3895 DBRUNIF((sc->tx_mbuf_alloc),
3896 if_printf(&sc->arpcom.ac_if,
3897 "%s(%d): Memory leak! "
3898 "Lost %d mbufs from tx chain!\n",
3899 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3901 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3905 /****************************************************************************/
3906 /* Initialize the RX context memory. */
3910 /****************************************************************************/
3912 bce_init_rx_context(struct bce_softc *sc)
3916 /* Initialize the context ID for an L2 RX chain. */
3917 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
3918 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
3921 * Set the level for generating pause frames
3922 * when the number of available rx_bd's gets
3923 * too low (the low watermark) and the level
3924 * when pause frames can be stopped (the high
3927 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3928 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3929 uint32_t lo_water, hi_water;
3931 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
3932 hi_water = USABLE_RX_BD / 4;
3934 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
3935 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
3939 else if (hi_water == 0)
3942 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
3945 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
3947 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
3948 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3949 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3950 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
3951 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
3954 /* Point the hardware to the first page in the chain. */
3955 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
3956 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
3957 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
3958 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
3962 /****************************************************************************/
3963 /* Allocate memory and initialize the RX data structures. */
3966 /* 0 for success, positive value for failure. */
3967 /****************************************************************************/
3969 bce_init_rx_chain(struct bce_softc *sc)
3973 uint16_t prod, chain_prod;
3976 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3978 /* Initialize the RX producer and consumer indices. */
3981 sc->rx_prod_bseq = 0;
3982 sc->free_rx_bd = USABLE_RX_BD;
3983 sc->max_rx_bd = USABLE_RX_BD;
3984 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
3985 DBRUNIF(1, sc->rx_empty_count = 0);
3987 /* Initialize the RX next pointer chain entries. */
3988 for (i = 0; i < RX_PAGES; i++) {
3991 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
3993 /* Check if we've reached the last page. */
3994 if (i == (RX_PAGES - 1))
3999 /* Setup the chain page pointers. */
4000 rxbd->rx_bd_haddr_hi =
4001 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
4002 rxbd->rx_bd_haddr_lo =
4003 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
4006 /* Allocate mbuf clusters for the rx_bd chain. */
4007 prod = prod_bseq = 0;
4008 while (prod < TOTAL_RX_BD) {
4009 chain_prod = RX_CHAIN_IDX(prod);
4010 if (bce_newbuf_std(sc, &prod, &chain_prod, &prod_bseq, 1)) {
4011 if_printf(&sc->arpcom.ac_if,
4012 "Error filling RX chain: rx_bd[0x%04X]!\n",
4017 prod = NEXT_RX_BD(prod);
4020 /* Save the RX chain producer index. */
4022 sc->rx_prod_bseq = prod_bseq;
4024 /* Tell the chip about the waiting rx_bd's. */
4025 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4027 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4030 bce_init_rx_context(sc);
4036 /****************************************************************************/
4037 /* Free memory and clear the RX data structures. */
4041 /****************************************************************************/
4043 bce_free_rx_chain(struct bce_softc *sc)
4047 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4049 /* Free any mbufs still in the RX mbuf chain. */
4050 for (i = 0; i < TOTAL_RX_BD; i++) {
4051 if (sc->rx_mbuf_ptr[i] != NULL) {
4052 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
4053 m_freem(sc->rx_mbuf_ptr[i]);
4054 sc->rx_mbuf_ptr[i] = NULL;
4055 DBRUNIF(1, sc->rx_mbuf_alloc--);
4059 /* Clear each RX chain page. */
4060 for (i = 0; i < RX_PAGES; i++)
4061 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
4063 /* Check if we lost any mbufs in the process. */
4064 DBRUNIF((sc->rx_mbuf_alloc),
4065 if_printf(&sc->arpcom.ac_if,
4066 "%s(%d): Memory leak! "
4067 "Lost %d mbufs from rx chain!\n",
4068 __FILE__, __LINE__, sc->rx_mbuf_alloc));
4070 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4074 /****************************************************************************/
4075 /* Set media options. */
4078 /* 0 for success, positive value for failure. */
4079 /****************************************************************************/
4081 bce_ifmedia_upd(struct ifnet *ifp)
4083 struct bce_softc *sc = ifp->if_softc;
4084 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4087 * 'mii' will be NULL, when this function is called on following
4088 * code path: bce_attach() -> bce_mgmt_init()
4091 /* Make sure the MII bus has been enumerated. */
4093 if (mii->mii_instance) {
4094 struct mii_softc *miisc;
4096 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
4097 mii_phy_reset(miisc);
4105 /****************************************************************************/
4106 /* Reports current media status. */
4110 /****************************************************************************/
4112 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
4114 struct bce_softc *sc = ifp->if_softc;
4115 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4118 ifmr->ifm_active = mii->mii_media_active;
4119 ifmr->ifm_status = mii->mii_media_status;
4123 /****************************************************************************/
4124 /* Handles PHY generated interrupt events. */
4128 /****************************************************************************/
4130 bce_phy_intr(struct bce_softc *sc)
4132 uint32_t new_link_state, old_link_state;
4133 struct ifnet *ifp = &sc->arpcom.ac_if;
4135 ASSERT_SERIALIZED(ifp->if_serializer);
4137 new_link_state = sc->status_block->status_attn_bits &
4138 STATUS_ATTN_BITS_LINK_STATE;
4139 old_link_state = sc->status_block->status_attn_bits_ack &
4140 STATUS_ATTN_BITS_LINK_STATE;
4142 /* Handle any changes if the link state has changed. */
4143 if (new_link_state != old_link_state) { /* XXX redundant? */
4144 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4146 /* Update the status_attn_bits_ack field in the status block. */
4147 if (new_link_state) {
4148 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4149 STATUS_ATTN_BITS_LINK_STATE);
4151 if_printf(ifp, "Link is now UP.\n");
4153 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4154 STATUS_ATTN_BITS_LINK_STATE);
4156 if_printf(ifp, "Link is now DOWN.\n");
4160 * Assume link is down and allow tick routine to
4161 * update the state based on the actual media state.
4164 callout_stop(&sc->bce_tick_callout);
4165 bce_tick_serialized(sc);
4168 /* Acknowledge the link change interrupt. */
4169 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4173 /****************************************************************************/
4174 /* Reads the receive consumer value from the status block (skipping over */
4175 /* chain page pointer if necessary). */
4179 /****************************************************************************/
4180 static __inline uint16_t
4181 bce_get_hw_rx_cons(struct bce_softc *sc)
4183 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
4185 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4191 /****************************************************************************/
4192 /* Handles received frame interrupt events. */
4196 /****************************************************************************/
4198 bce_rx_intr(struct bce_softc *sc, int count)
4200 struct ifnet *ifp = &sc->arpcom.ac_if;
4201 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4202 uint32_t sw_prod_bseq;
4203 struct mbuf_chain chain[MAXCPU];
4205 ASSERT_SERIALIZED(ifp->if_serializer);
4207 ether_input_chain_init(chain);
4209 DBRUNIF(1, sc->rx_interrupts++);
4211 /* Get the hardware's view of the RX consumer index. */
4212 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4214 /* Get working copies of the driver's view of the RX indices. */
4215 sw_cons = sc->rx_cons;
4216 sw_prod = sc->rx_prod;
4217 sw_prod_bseq = sc->rx_prod_bseq;
4219 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
4220 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
4221 __func__, sw_prod, sw_cons, sw_prod_bseq);
4223 /* Prevent speculative reads from getting ahead of the status block. */
4224 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4225 BUS_SPACE_BARRIER_READ);
4227 /* Update some debug statistics counters */
4228 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
4229 sc->rx_low_watermark = sc->free_rx_bd);
4230 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
4232 /* Scan through the receive chain as long as there is work to do. */
4233 while (sw_cons != hw_cons) {
4234 struct mbuf *m = NULL;
4235 struct l2_fhdr *l2fhdr = NULL;
4238 uint32_t status = 0;
4240 #ifdef DEVICE_POLLING
4241 if (count >= 0 && count-- == 0) {
4242 sc->hw_rx_cons = sw_cons;
4248 * Convert the producer/consumer indices
4249 * to an actual rx_bd index.
4251 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
4252 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
4254 /* Get the used rx_bd. */
4255 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
4256 [RX_IDX(sw_chain_cons)];
4259 DBRUN(BCE_VERBOSE_RECV,
4260 if_printf(ifp, "%s(): ", __func__);
4261 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
4263 /* The mbuf is stored with the last rx_bd entry of a packet. */
4264 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4265 /* Validate that this is the last rx_bd. */
4266 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
4267 if_printf(ifp, "%s(%d): "
4268 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
4269 __FILE__, __LINE__, sw_chain_cons);
4270 bce_breakpoint(sc));
4272 if (sw_chain_cons != sw_chain_prod) {
4273 if_printf(ifp, "RX cons(%d) != prod(%d), "
4274 "drop!\n", sw_chain_cons,
4278 bce_setup_rxdesc_std(sc, sw_chain_cons,
4281 goto bce_rx_int_next_rx;
4284 /* Unmap the mbuf from DMA space. */
4285 bus_dmamap_sync(sc->rx_mbuf_tag,
4286 sc->rx_mbuf_map[sw_chain_cons],
4287 BUS_DMASYNC_POSTREAD);
4289 /* Save the mbuf from the driver's chain. */
4290 m = sc->rx_mbuf_ptr[sw_chain_cons];
4293 * Frames received on the NetXteme II are prepended
4294 * with an l2_fhdr structure which provides status
4295 * information about the received frame (including
4296 * VLAN tags and checksum info). The frames are also
4297 * automatically adjusted to align the IP header
4298 * (i.e. two null bytes are inserted before the
4299 * Ethernet header). As a result the data DMA'd by
4300 * the controller into the mbuf is as follows:
4302 * +---------+-----+---------------------+-----+
4303 * | l2_fhdr | pad | packet data | FCS |
4304 * +---------+-----+---------------------+-----+
4306 * The l2_fhdr needs to be checked and skipped and the
4307 * FCS needs to be stripped before sending the packet
4310 l2fhdr = mtod(m, struct l2_fhdr *);
4312 len = l2fhdr->l2_fhdr_pkt_len;
4313 status = l2fhdr->l2_fhdr_status;
4315 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
4317 "Simulating l2_fhdr status error.\n");
4318 status = status | L2_FHDR_ERRORS_PHY_DECODE);
4320 /* Watch for unusual sized frames. */
4321 DBRUNIF((len < BCE_MIN_MTU ||
4322 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
4324 "%s(%d): Unusual frame size found. "
4325 "Min(%d), Actual(%d), Max(%d)\n",
4327 (int)BCE_MIN_MTU, len,
4328 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
4329 bce_dump_mbuf(sc, m);
4330 bce_breakpoint(sc));
4332 len -= ETHER_CRC_LEN;
4334 /* Check the received frame for errors. */
4335 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4336 L2_FHDR_ERRORS_PHY_DECODE |
4337 L2_FHDR_ERRORS_ALIGNMENT |
4338 L2_FHDR_ERRORS_TOO_SHORT |
4339 L2_FHDR_ERRORS_GIANT_FRAME)) {
4341 DBRUNIF(1, sc->l2fhdr_status_errors++);
4343 /* Reuse the mbuf for a new frame. */
4344 bce_setup_rxdesc_std(sc, sw_chain_prod,
4347 goto bce_rx_int_next_rx;
4351 * Get a new mbuf for the rx_bd. If no new
4352 * mbufs are available then reuse the current mbuf,
4353 * log an ierror on the interface, and generate
4354 * an error in the system log.
4356 if (bce_newbuf_std(sc, &sw_prod, &sw_chain_prod,
4357 &sw_prod_bseq, 0)) {
4360 "%s(%d): Failed to allocate new mbuf, "
4361 "incoming frame dropped!\n",
4362 __FILE__, __LINE__));
4366 /* Try and reuse the exisitng mbuf. */
4367 bce_setup_rxdesc_std(sc, sw_chain_prod,
4370 goto bce_rx_int_next_rx;
4374 * Skip over the l2_fhdr when passing
4375 * the data up the stack.
4377 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4379 m->m_pkthdr.len = m->m_len = len;
4380 m->m_pkthdr.rcvif = ifp;
4382 DBRUN(BCE_VERBOSE_RECV,
4383 struct ether_header *eh;
4384 eh = mtod(m, struct ether_header *);
4385 if_printf(ifp, "%s(): to: %6D, from: %6D, "
4386 "type: 0x%04X\n", __func__,
4387 eh->ether_dhost, ":",
4388 eh->ether_shost, ":",
4389 htons(eh->ether_type)));
4391 /* Validate the checksum if offload enabled. */
4392 if (ifp->if_capenable & IFCAP_RXCSUM) {
4393 /* Check for an IP datagram. */
4394 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4395 m->m_pkthdr.csum_flags |=
4398 /* Check if the IP checksum is valid. */
4399 if ((l2fhdr->l2_fhdr_ip_xsum ^
4401 m->m_pkthdr.csum_flags |=
4404 DBPRINT(sc, BCE_WARN_RECV,
4405 "%s(): Invalid IP checksum = 0x%04X!\n",
4406 __func__, l2fhdr->l2_fhdr_ip_xsum);
4410 /* Check for a valid TCP/UDP frame. */
4411 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4412 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4414 /* Check for a good TCP/UDP checksum. */
4416 (L2_FHDR_ERRORS_TCP_XSUM |
4417 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4418 m->m_pkthdr.csum_data =
4419 l2fhdr->l2_fhdr_tcp_udp_xsum;
4420 m->m_pkthdr.csum_flags |=
4424 DBPRINT(sc, BCE_WARN_RECV,
4425 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
4426 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
4433 sw_prod = NEXT_RX_BD(sw_prod);
4436 sw_cons = NEXT_RX_BD(sw_cons);
4438 /* If we have a packet, pass it up the stack */
4440 DBPRINT(sc, BCE_VERBOSE_RECV,
4441 "%s(): Passing received frame up.\n", __func__);
4443 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4444 m->m_flags |= M_VLANTAG;
4445 m->m_pkthdr.ether_vlantag =
4446 l2fhdr->l2_fhdr_vlan_tag;
4448 ether_input_chain(ifp, m, NULL, chain);
4450 DBRUNIF(1, sc->rx_mbuf_alloc--);
4454 * If polling(4) is not enabled, refresh hw_cons to see
4455 * whether there's new work.
4457 * If polling(4) is enabled, i.e count >= 0, refreshing
4458 * should not be performed, so that we would not spend
4459 * too much time in RX processing.
4461 if (count < 0 && sw_cons == hw_cons)
4462 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4465 * Prevent speculative reads from getting ahead
4466 * of the status block.
4468 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4469 BUS_SPACE_BARRIER_READ);
4472 ether_input_dispatch(chain);
4474 sc->rx_cons = sw_cons;
4475 sc->rx_prod = sw_prod;
4476 sc->rx_prod_bseq = sw_prod_bseq;
4478 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4480 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4483 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4484 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4485 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4489 /****************************************************************************/
4490 /* Reads the transmit consumer value from the status block (skipping over */
4491 /* chain page pointer if necessary). */
4495 /****************************************************************************/
4496 static __inline uint16_t
4497 bce_get_hw_tx_cons(struct bce_softc *sc)
4499 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4501 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4507 /****************************************************************************/
4508 /* Handles transmit completion interrupt events. */
4512 /****************************************************************************/
4514 bce_tx_intr(struct bce_softc *sc)
4516 struct ifnet *ifp = &sc->arpcom.ac_if;
4517 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4519 ASSERT_SERIALIZED(ifp->if_serializer);
4521 DBRUNIF(1, sc->tx_interrupts++);
4523 /* Get the hardware's view of the TX consumer index. */
4524 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4525 sw_tx_cons = sc->tx_cons;
4527 /* Prevent speculative reads from getting ahead of the status block. */
4528 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4529 BUS_SPACE_BARRIER_READ);
4531 /* Cycle through any completed TX chain page entries. */
4532 while (sw_tx_cons != hw_tx_cons) {
4534 struct tx_bd *txbd = NULL;
4536 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4538 DBPRINT(sc, BCE_INFO_SEND,
4539 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4540 "sw_tx_chain_cons = 0x%04X\n",
4541 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4543 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4544 if_printf(ifp, "%s(%d): "
4545 "TX chain consumer out of range! "
4546 " 0x%04X > 0x%04X\n",
4547 __FILE__, __LINE__, sw_tx_chain_cons,
4549 bce_breakpoint(sc));
4551 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4552 [TX_IDX(sw_tx_chain_cons)]);
4554 DBRUNIF((txbd == NULL),
4555 if_printf(ifp, "%s(%d): "
4556 "Unexpected NULL tx_bd[0x%04X]!\n",
4557 __FILE__, __LINE__, sw_tx_chain_cons);
4558 bce_breakpoint(sc));
4560 DBRUN(BCE_INFO_SEND,
4561 if_printf(ifp, "%s(): ", __func__);
4562 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4565 * Free the associated mbuf. Remember
4566 * that only the last tx_bd of a packet
4567 * has an mbuf pointer and DMA map.
4569 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4570 /* Validate that this is the last tx_bd. */
4571 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4572 if_printf(ifp, "%s(%d): "
4573 "tx_bd END flag not set but "
4574 "txmbuf == NULL!\n", __FILE__, __LINE__);
4575 bce_breakpoint(sc));
4577 DBRUN(BCE_INFO_SEND,
4578 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4579 "from tx_bd[0x%04X]\n", __func__,
4582 /* Unmap the mbuf. */
4583 bus_dmamap_unload(sc->tx_mbuf_tag,
4584 sc->tx_mbuf_map[sw_tx_chain_cons]);
4586 /* Free the mbuf. */
4587 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4588 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4589 DBRUNIF(1, sc->tx_mbuf_alloc--);
4595 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4597 if (sw_tx_cons == hw_tx_cons) {
4598 /* Refresh hw_cons to see if there's new work. */
4599 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4603 * Prevent speculative reads from getting
4604 * ahead of the status block.
4606 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4607 BUS_SPACE_BARRIER_READ);
4610 if (sc->used_tx_bd == 0) {
4611 /* Clear the TX timeout timer. */
4615 /* Clear the tx hardware queue full flag. */
4616 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4617 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4618 DBPRINT(sc, BCE_WARN_SEND,
4619 "%s(): Open TX chain! %d/%d (used/total)\n",
4620 __func__, sc->used_tx_bd, sc->max_tx_bd));
4621 ifp->if_flags &= ~IFF_OACTIVE;
4623 sc->tx_cons = sw_tx_cons;
4627 /****************************************************************************/
4628 /* Disables interrupt generation. */
4632 /****************************************************************************/
4634 bce_disable_intr(struct bce_softc *sc)
4636 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4637 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4638 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4642 /****************************************************************************/
4643 /* Enables interrupt generation. */
4647 /****************************************************************************/
4649 bce_enable_intr(struct bce_softc *sc, int coal_now)
4651 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4653 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4654 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4655 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4657 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4658 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4661 REG_WR(sc, BCE_HC_COMMAND,
4662 sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
4667 /****************************************************************************/
4668 /* Handles controller initialization. */
4672 /****************************************************************************/
4676 struct bce_softc *sc = xsc;
4677 struct ifnet *ifp = &sc->arpcom.ac_if;
4681 ASSERT_SERIALIZED(ifp->if_serializer);
4683 /* Check if the driver is still running and bail out if it is. */
4684 if (ifp->if_flags & IFF_RUNNING)
4689 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4691 if_printf(ifp, "Controller reset failed!\n");
4695 error = bce_chipinit(sc);
4697 if_printf(ifp, "Controller initialization failed!\n");
4701 error = bce_blockinit(sc);
4703 if_printf(ifp, "Block initialization failed!\n");
4707 /* Load our MAC address. */
4708 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4709 bce_set_mac_addr(sc);
4711 /* Calculate and program the Ethernet MTU size. */
4712 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4714 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4717 * Program the mtu, enabling jumbo frame
4718 * support if necessary. Also set the mbuf
4719 * allocation count for RX frames.
4721 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4723 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4724 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4725 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4726 sc->mbuf_alloc_size = MJUM9BYTES;
4728 panic("jumbo buffer is not supported yet\n");
4731 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4732 sc->mbuf_alloc_size = MCLBYTES;
4735 /* Calculate the RX Ethernet frame size for rx_bd's. */
4736 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4738 DBPRINT(sc, BCE_INFO,
4739 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4740 "max_frame_size = %d\n",
4741 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4742 sc->max_frame_size);
4744 /* Program appropriate promiscuous/multicast filtering. */
4745 bce_set_rx_mode(sc);
4747 /* Init RX buffer descriptor chain. */
4748 bce_init_rx_chain(sc); /* XXX return value */
4750 /* Init TX buffer descriptor chain. */
4751 bce_init_tx_chain(sc); /* XXX return value */
4753 #ifdef DEVICE_POLLING
4754 /* Disable interrupts if we are polling. */
4755 if (ifp->if_flags & IFF_POLLING) {
4756 bce_disable_intr(sc);
4758 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4759 (1 << 16) | sc->bce_rx_quick_cons_trip);
4760 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4761 (1 << 16) | sc->bce_tx_quick_cons_trip);
4764 /* Enable host interrupts. */
4765 bce_enable_intr(sc, 1);
4767 bce_ifmedia_upd(ifp);
4769 ifp->if_flags |= IFF_RUNNING;
4770 ifp->if_flags &= ~IFF_OACTIVE;
4772 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
4779 /****************************************************************************/
4780 /* Initialize the controller just enough so that any management firmware */
4781 /* running on the device will continue to operate corectly. */
4785 /****************************************************************************/
4787 bce_mgmt_init(struct bce_softc *sc)
4789 struct ifnet *ifp = &sc->arpcom.ac_if;
4791 /* Bail out if management firmware is not running. */
4792 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4795 /* Enable all critical blocks in the MAC. */
4796 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4797 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4798 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4799 BCE_MISC_ENABLE_DEFAULT_XI);
4801 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
4803 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4806 bce_ifmedia_upd(ifp);
4810 /****************************************************************************/
4811 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4812 /* memory visible to the controller. */
4815 /* 0 for success, positive value for failure. */
4816 /****************************************************************************/
4818 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4820 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4821 bus_dmamap_t map, tmp_map;
4822 struct mbuf *m0 = *m_head;
4823 struct tx_bd *txbd = NULL;
4824 uint16_t vlan_tag = 0, flags = 0;
4825 uint16_t chain_prod, chain_prod_start, prod;
4827 int i, error, maxsegs, nsegs;
4829 uint16_t debug_prod;
4832 /* Transfer any checksum offload flags to the bd. */
4833 if (m0->m_pkthdr.csum_flags) {
4834 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4835 flags |= TX_BD_FLAGS_IP_CKSUM;
4836 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4837 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4840 /* Transfer any VLAN tags to the bd. */
4841 if (m0->m_flags & M_VLANTAG) {
4842 flags |= TX_BD_FLAGS_VLAN_TAG;
4843 vlan_tag = m0->m_pkthdr.ether_vlantag;
4847 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4849 /* Map the mbuf into DMAable memory. */
4850 map = sc->tx_mbuf_map[chain_prod_start];
4852 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4853 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4854 ("not enough segements %d\n", maxsegs));
4855 if (maxsegs > BCE_MAX_SEGMENTS)
4856 maxsegs = BCE_MAX_SEGMENTS;
4858 /* Map the mbuf into our DMA address space. */
4859 error = bus_dmamap_load_mbuf_defrag(sc->tx_mbuf_tag, map, m_head,
4860 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
4863 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4868 /* prod points to an empty tx_bd at this point. */
4869 prod_bseq = sc->tx_prod_bseq;
4872 debug_prod = chain_prod;
4875 DBPRINT(sc, BCE_INFO_SEND,
4876 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4877 "prod_bseq = 0x%08X\n",
4878 __func__, prod, chain_prod, prod_bseq);
4881 * Cycle through each mbuf segment that makes up
4882 * the outgoing frame, gathering the mapping info
4883 * for that segment and creating a tx_bd to for
4886 for (i = 0; i < nsegs; i++) {
4887 chain_prod = TX_CHAIN_IDX(prod);
4888 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4890 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4891 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4892 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4893 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4894 txbd->tx_bd_flags = htole16(flags);
4895 prod_bseq += segs[i].ds_len;
4897 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4898 prod = NEXT_TX_BD(prod);
4901 /* Set the END flag on the last TX buffer descriptor. */
4902 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4904 DBRUN(BCE_EXCESSIVE_SEND,
4905 bce_dump_tx_chain(sc, debug_prod, nsegs));
4907 DBPRINT(sc, BCE_INFO_SEND,
4908 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4909 "prod_bseq = 0x%08X\n",
4910 __func__, prod, chain_prod, prod_bseq);
4913 * Ensure that the mbuf pointer for this transmission
4914 * is placed at the array index of the last
4915 * descriptor in this chain. This is done
4916 * because a single map is used for all
4917 * segments of the mbuf and we don't want to
4918 * unload the map before all of the segments
4921 sc->tx_mbuf_ptr[chain_prod] = m0;
4923 tmp_map = sc->tx_mbuf_map[chain_prod];
4924 sc->tx_mbuf_map[chain_prod] = map;
4925 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4927 sc->used_tx_bd += nsegs;
4929 /* Update some debug statistic counters */
4930 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
4931 sc->tx_hi_watermark = sc->used_tx_bd);
4932 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
4933 DBRUNIF(1, sc->tx_mbuf_alloc++);
4935 DBRUN(BCE_VERBOSE_SEND,
4936 bce_dump_tx_mbuf_chain(sc, chain_prod, nsegs));
4938 /* prod points to the next free tx_bd at this point. */
4940 sc->tx_prod_bseq = prod_bseq;
4950 /****************************************************************************/
4951 /* Main transmit routine when called from another routine with a lock. */
4955 /****************************************************************************/
4957 bce_start(struct ifnet *ifp)
4959 struct bce_softc *sc = ifp->if_softc;
4962 ASSERT_SERIALIZED(ifp->if_serializer);
4964 /* If there's no link or the transmit queue is empty then just exit. */
4965 if (!sc->bce_link) {
4966 ifq_purge(&ifp->if_snd);
4970 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
4973 DBPRINT(sc, BCE_INFO_SEND,
4974 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04zX, "
4975 "tx_prod_bseq = 0x%08X\n",
4977 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
4980 struct mbuf *m_head;
4983 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4986 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4987 ifp->if_flags |= IFF_OACTIVE;
4991 /* Check for any frames to send. */
4992 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4997 * Pack the data into the transmit ring. If we
4998 * don't have room, place the mbuf back at the
4999 * head of the queue and set the OACTIVE flag
5000 * to wait for the NIC to drain the chain.
5002 if (bce_encap(sc, &m_head)) {
5004 if (sc->used_tx_bd == 0) {
5007 ifp->if_flags |= IFF_OACTIVE;
5014 /* Send a copy of the frame to any BPF listeners. */
5015 ETHER_BPF_MTAP(ifp, m_head);
5019 /* no packets were dequeued */
5020 DBPRINT(sc, BCE_VERBOSE_SEND,
5021 "%s(): No packets were dequeued\n", __func__);
5025 DBPRINT(sc, BCE_INFO_SEND,
5026 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04zX, "
5027 "tx_prod_bseq = 0x%08X\n",
5029 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
5031 REG_WR(sc, BCE_MQ_COMMAND,
5032 REG_RD(sc, BCE_MQ_COMMAND) | BCE_MQ_COMMAND_NO_MAP_ERROR);
5034 /* Start the transmit. */
5035 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
5036 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
5038 /* Set the tx timeout. */
5039 ifp->if_timer = BCE_TX_TIMEOUT;
5043 /****************************************************************************/
5044 /* Handles any IOCTL calls from the operating system. */
5047 /* 0 for success, positive value for failure. */
5048 /****************************************************************************/
5050 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
5052 struct bce_softc *sc = ifp->if_softc;
5053 struct ifreq *ifr = (struct ifreq *)data;
5054 struct mii_data *mii;
5055 int mask, error = 0;
5057 ASSERT_SERIALIZED(ifp->if_serializer);
5061 /* Check that the MTU setting is supported. */
5062 if (ifr->ifr_mtu < BCE_MIN_MTU ||
5064 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
5066 ifr->ifr_mtu > ETHERMTU
5073 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
5075 ifp->if_mtu = ifr->ifr_mtu;
5076 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5081 if (ifp->if_flags & IFF_UP) {
5082 if (ifp->if_flags & IFF_RUNNING) {
5083 mask = ifp->if_flags ^ sc->bce_if_flags;
5085 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
5086 bce_set_rx_mode(sc);
5090 } else if (ifp->if_flags & IFF_RUNNING) {
5093 /* If MFW is running, restart the controller a bit. */
5094 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5095 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
5100 sc->bce_if_flags = ifp->if_flags;
5105 if (ifp->if_flags & IFF_RUNNING)
5106 bce_set_rx_mode(sc);
5111 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
5113 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
5115 mii = device_get_softc(sc->bce_miibus);
5116 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
5120 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
5121 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
5124 if (mask & IFCAP_HWCSUM) {
5125 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
5126 if (IFCAP_HWCSUM & ifp->if_capenable)
5127 ifp->if_hwassist = BCE_IF_HWASSIST;
5129 ifp->if_hwassist = 0;
5134 error = ether_ioctl(ifp, command, data);
5141 /****************************************************************************/
5142 /* Transmit timeout handler. */
5146 /****************************************************************************/
5148 bce_watchdog(struct ifnet *ifp)
5150 struct bce_softc *sc = ifp->if_softc;
5152 ASSERT_SERIALIZED(ifp->if_serializer);
5154 DBRUN(BCE_VERBOSE_SEND,
5155 bce_dump_driver_state(sc);
5156 bce_dump_status_block(sc));
5159 * If we are in this routine because of pause frames, then
5160 * don't reset the hardware.
5162 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
5165 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
5167 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5169 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5174 if (!ifq_is_empty(&ifp->if_snd))
5179 #ifdef DEVICE_POLLING
5182 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
5184 struct bce_softc *sc = ifp->if_softc;
5185 struct status_block *sblk = sc->status_block;
5186 uint16_t hw_tx_cons, hw_rx_cons;
5188 ASSERT_SERIALIZED(ifp->if_serializer);
5192 bce_disable_intr(sc);
5194 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5195 (1 << 16) | sc->bce_rx_quick_cons_trip);
5196 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5197 (1 << 16) | sc->bce_tx_quick_cons_trip);
5199 case POLL_DEREGISTER:
5200 bce_enable_intr(sc, 1);
5202 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5203 (sc->bce_tx_quick_cons_trip_int << 16) |
5204 sc->bce_tx_quick_cons_trip);
5205 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5206 (sc->bce_rx_quick_cons_trip_int << 16) |
5207 sc->bce_rx_quick_cons_trip);
5213 if (cmd == POLL_AND_CHECK_STATUS) {
5214 uint32_t status_attn_bits;
5216 status_attn_bits = sblk->status_attn_bits;
5218 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5220 "Simulating unexpected status attention bit set.");
5221 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
5223 /* Was it a link change interrupt? */
5224 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5225 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5228 /* Clear any transient status updates during link state change. */
5229 REG_WR(sc, BCE_HC_COMMAND,
5230 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5231 REG_RD(sc, BCE_HC_COMMAND);
5234 * If any other attention is asserted then
5235 * the chip is toast.
5237 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5238 (sblk->status_attn_bits_ack &
5239 ~STATUS_ATTN_BITS_LINK_STATE)) {
5240 DBRUN(1, sc->unexpected_attentions++);
5242 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5243 sblk->status_attn_bits);
5246 if (bce_debug_unexpected_attention == 0)
5247 bce_breakpoint(sc));
5254 hw_rx_cons = bce_get_hw_rx_cons(sc);
5255 hw_tx_cons = bce_get_hw_tx_cons(sc);
5257 /* Check for any completed RX frames. */
5258 if (hw_rx_cons != sc->hw_rx_cons)
5259 bce_rx_intr(sc, count);
5261 /* Check for any completed TX frames. */
5262 if (hw_tx_cons != sc->hw_tx_cons)
5265 /* Check for new frames to transmit. */
5266 if (!ifq_is_empty(&ifp->if_snd))
5270 #endif /* DEVICE_POLLING */
5274 * Interrupt handler.
5276 /****************************************************************************/
5277 /* Main interrupt entry point. Verifies that the controller generated the */
5278 /* interrupt and then calls a separate routine for handle the various */
5279 /* interrupt causes (PHY, TX, RX). */
5282 /* 0 for success, positive value for failure. */
5283 /****************************************************************************/
5287 struct bce_softc *sc = xsc;
5288 struct ifnet *ifp = &sc->arpcom.ac_if;
5289 struct status_block *sblk;
5290 uint16_t hw_rx_cons, hw_tx_cons;
5292 ASSERT_SERIALIZED(ifp->if_serializer);
5294 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5295 DBRUNIF(1, sc->interrupts_generated++);
5297 sblk = sc->status_block;
5300 * If the hardware status block index matches the last value
5301 * read by the driver and we haven't asserted our interrupt
5302 * then there's nothing to do.
5304 if (sblk->status_idx == sc->last_status_idx &&
5305 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
5306 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5309 /* Ack the interrupt and stop others from occuring. */
5310 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5311 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5312 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5314 /* Check if the hardware has finished any work. */
5315 hw_rx_cons = bce_get_hw_rx_cons(sc);
5316 hw_tx_cons = bce_get_hw_tx_cons(sc);
5318 /* Keep processing data as long as there is work to do. */
5320 uint32_t status_attn_bits;
5322 status_attn_bits = sblk->status_attn_bits;
5324 DBRUNIF(DB_RANDOMTRUE(bce_debug_unexpected_attention),
5326 "Simulating unexpected status attention bit set.");
5327 status_attn_bits |= STATUS_ATTN_BITS_PARITY_ERROR);
5329 /* Was it a link change interrupt? */
5330 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5331 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5335 * Clear any transient status updates during link state
5338 REG_WR(sc, BCE_HC_COMMAND,
5339 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5340 REG_RD(sc, BCE_HC_COMMAND);
5344 * If any other attention is asserted then
5345 * the chip is toast.
5347 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5348 (sblk->status_attn_bits_ack &
5349 ~STATUS_ATTN_BITS_LINK_STATE)) {
5350 DBRUN(1, sc->unexpected_attentions++);
5352 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5353 sblk->status_attn_bits);
5356 if (bce_debug_unexpected_attention == 0)
5357 bce_breakpoint(sc));
5363 /* Check for any completed RX frames. */
5364 if (hw_rx_cons != sc->hw_rx_cons)
5365 bce_rx_intr(sc, -1);
5367 /* Check for any completed TX frames. */
5368 if (hw_tx_cons != sc->hw_tx_cons)
5372 * Save the status block index value
5373 * for use during the next interrupt.
5375 sc->last_status_idx = sblk->status_idx;
5378 * Prevent speculative reads from getting
5379 * ahead of the status block.
5381 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
5382 BUS_SPACE_BARRIER_READ);
5385 * If there's no work left then exit the
5386 * interrupt service routine.
5388 hw_rx_cons = bce_get_hw_rx_cons(sc);
5389 hw_tx_cons = bce_get_hw_tx_cons(sc);
5390 if ((hw_rx_cons == sc->hw_rx_cons) && (hw_tx_cons == sc->hw_tx_cons))
5394 /* Re-enable interrupts. */
5395 bce_enable_intr(sc, 0);
5397 if (sc->bce_coalchg_mask)
5398 bce_coal_change(sc);
5400 /* Handle any frames that arrived while handling the interrupt. */
5401 if (!ifq_is_empty(&ifp->if_snd))
5406 /****************************************************************************/
5407 /* Programs the various packet receive modes (broadcast and multicast). */
5411 /****************************************************************************/
5413 bce_set_rx_mode(struct bce_softc *sc)
5415 struct ifnet *ifp = &sc->arpcom.ac_if;
5416 struct ifmultiaddr *ifma;
5417 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5418 uint32_t rx_mode, sort_mode;
5421 ASSERT_SERIALIZED(ifp->if_serializer);
5423 /* Initialize receive mode default settings. */
5424 rx_mode = sc->rx_mode &
5425 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5426 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5427 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5430 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5433 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5434 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5435 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5438 * Check for promiscuous, all multicast, or selected
5439 * multicast address filtering.
5441 if (ifp->if_flags & IFF_PROMISC) {
5442 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5444 /* Enable promiscuous mode. */
5445 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5446 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5447 } else if (ifp->if_flags & IFF_ALLMULTI) {
5448 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5450 /* Enable all multicast addresses. */
5451 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5452 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5455 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5457 /* Accept one or more multicast(s). */
5458 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5460 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5461 if (ifma->ifma_addr->sa_family != AF_LINK)
5464 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5465 ETHER_ADDR_LEN) & 0xFF;
5466 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5469 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5470 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5473 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5476 /* Only make changes if the recive mode has actually changed. */
5477 if (rx_mode != sc->rx_mode) {
5478 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5481 sc->rx_mode = rx_mode;
5482 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5485 /* Disable and clear the exisitng sort before enabling a new sort. */
5486 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5487 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5488 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5492 /****************************************************************************/
5493 /* Called periodically to updates statistics from the controllers */
5494 /* statistics block. */
5498 /****************************************************************************/
5500 bce_stats_update(struct bce_softc *sc)
5502 struct ifnet *ifp = &sc->arpcom.ac_if;
5503 struct statistics_block *stats = sc->stats_block;
5505 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5507 ASSERT_SERIALIZED(ifp->if_serializer);
5510 * Certain controllers don't report carrier sense errors correctly.
5511 * See errata E11_5708CA0_1165.
5513 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5514 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5516 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5520 * Update the sysctl statistics from the hardware statistics.
5522 sc->stat_IfHCInOctets =
5523 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5524 (uint64_t)stats->stat_IfHCInOctets_lo;
5526 sc->stat_IfHCInBadOctets =
5527 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5528 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5530 sc->stat_IfHCOutOctets =
5531 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5532 (uint64_t)stats->stat_IfHCOutOctets_lo;
5534 sc->stat_IfHCOutBadOctets =
5535 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5536 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5538 sc->stat_IfHCInUcastPkts =
5539 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5540 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5542 sc->stat_IfHCInMulticastPkts =
5543 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5544 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5546 sc->stat_IfHCInBroadcastPkts =
5547 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5548 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5550 sc->stat_IfHCOutUcastPkts =
5551 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5552 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5554 sc->stat_IfHCOutMulticastPkts =
5555 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5556 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5558 sc->stat_IfHCOutBroadcastPkts =
5559 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5560 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5562 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5563 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5565 sc->stat_Dot3StatsCarrierSenseErrors =
5566 stats->stat_Dot3StatsCarrierSenseErrors;
5568 sc->stat_Dot3StatsFCSErrors =
5569 stats->stat_Dot3StatsFCSErrors;
5571 sc->stat_Dot3StatsAlignmentErrors =
5572 stats->stat_Dot3StatsAlignmentErrors;
5574 sc->stat_Dot3StatsSingleCollisionFrames =
5575 stats->stat_Dot3StatsSingleCollisionFrames;
5577 sc->stat_Dot3StatsMultipleCollisionFrames =
5578 stats->stat_Dot3StatsMultipleCollisionFrames;
5580 sc->stat_Dot3StatsDeferredTransmissions =
5581 stats->stat_Dot3StatsDeferredTransmissions;
5583 sc->stat_Dot3StatsExcessiveCollisions =
5584 stats->stat_Dot3StatsExcessiveCollisions;
5586 sc->stat_Dot3StatsLateCollisions =
5587 stats->stat_Dot3StatsLateCollisions;
5589 sc->stat_EtherStatsCollisions =
5590 stats->stat_EtherStatsCollisions;
5592 sc->stat_EtherStatsFragments =
5593 stats->stat_EtherStatsFragments;
5595 sc->stat_EtherStatsJabbers =
5596 stats->stat_EtherStatsJabbers;
5598 sc->stat_EtherStatsUndersizePkts =
5599 stats->stat_EtherStatsUndersizePkts;
5601 sc->stat_EtherStatsOverrsizePkts =
5602 stats->stat_EtherStatsOverrsizePkts;
5604 sc->stat_EtherStatsPktsRx64Octets =
5605 stats->stat_EtherStatsPktsRx64Octets;
5607 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5608 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5610 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5611 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5613 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5614 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5616 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5617 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5619 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5620 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5622 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5623 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5625 sc->stat_EtherStatsPktsTx64Octets =
5626 stats->stat_EtherStatsPktsTx64Octets;
5628 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5629 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5631 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5632 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5634 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5635 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5637 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5638 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5640 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5641 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5643 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5644 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5646 sc->stat_XonPauseFramesReceived =
5647 stats->stat_XonPauseFramesReceived;
5649 sc->stat_XoffPauseFramesReceived =
5650 stats->stat_XoffPauseFramesReceived;
5652 sc->stat_OutXonSent =
5653 stats->stat_OutXonSent;
5655 sc->stat_OutXoffSent =
5656 stats->stat_OutXoffSent;
5658 sc->stat_FlowControlDone =
5659 stats->stat_FlowControlDone;
5661 sc->stat_MacControlFramesReceived =
5662 stats->stat_MacControlFramesReceived;
5664 sc->stat_XoffStateEntered =
5665 stats->stat_XoffStateEntered;
5667 sc->stat_IfInFramesL2FilterDiscards =
5668 stats->stat_IfInFramesL2FilterDiscards;
5670 sc->stat_IfInRuleCheckerDiscards =
5671 stats->stat_IfInRuleCheckerDiscards;
5673 sc->stat_IfInFTQDiscards =
5674 stats->stat_IfInFTQDiscards;
5676 sc->stat_IfInMBUFDiscards =
5677 stats->stat_IfInMBUFDiscards;
5679 sc->stat_IfInRuleCheckerP4Hit =
5680 stats->stat_IfInRuleCheckerP4Hit;
5682 sc->stat_CatchupInRuleCheckerDiscards =
5683 stats->stat_CatchupInRuleCheckerDiscards;
5685 sc->stat_CatchupInFTQDiscards =
5686 stats->stat_CatchupInFTQDiscards;
5688 sc->stat_CatchupInMBUFDiscards =
5689 stats->stat_CatchupInMBUFDiscards;
5691 sc->stat_CatchupInRuleCheckerP4Hit =
5692 stats->stat_CatchupInRuleCheckerP4Hit;
5694 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5697 * Update the interface statistics from the
5698 * hardware statistics.
5700 ifp->if_collisions = (u_long)sc->stat_EtherStatsCollisions;
5702 ifp->if_ierrors = (u_long)sc->stat_EtherStatsUndersizePkts +
5703 (u_long)sc->stat_EtherStatsOverrsizePkts +
5704 (u_long)sc->stat_IfInMBUFDiscards +
5705 (u_long)sc->stat_Dot3StatsAlignmentErrors +
5706 (u_long)sc->stat_Dot3StatsFCSErrors +
5707 (u_long)sc->stat_IfInRuleCheckerDiscards +
5708 (u_long)sc->stat_IfInFTQDiscards +
5709 (u_long)sc->com_no_buffers;
5712 (u_long)sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5713 (u_long)sc->stat_Dot3StatsExcessiveCollisions +
5714 (u_long)sc->stat_Dot3StatsLateCollisions;
5716 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5720 /****************************************************************************/
5721 /* Periodic function to notify the bootcode that the driver is still */
5726 /****************************************************************************/
5728 bce_pulse(void *xsc)
5730 struct bce_softc *sc = xsc;
5731 struct ifnet *ifp = &sc->arpcom.ac_if;
5734 lwkt_serialize_enter(ifp->if_serializer);
5736 /* Tell the firmware that the driver is still running. */
5737 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5738 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
5740 /* Schedule the next pulse. */
5741 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
5743 lwkt_serialize_exit(ifp->if_serializer);
5747 /****************************************************************************/
5748 /* Periodic function to perform maintenance tasks. */
5752 /****************************************************************************/
5754 bce_tick_serialized(struct bce_softc *sc)
5756 struct ifnet *ifp = &sc->arpcom.ac_if;
5757 struct mii_data *mii;
5759 ASSERT_SERIALIZED(ifp->if_serializer);
5761 /* Update the statistics from the hardware statistics block. */
5762 bce_stats_update(sc);
5764 /* Schedule the next tick. */
5765 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
5767 /* If link is up already up then we're done. */
5771 mii = device_get_softc(sc->bce_miibus);
5774 /* Check if the link has come up. */
5775 if ((mii->mii_media_status & IFM_ACTIVE) &&
5776 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5778 /* Now that link is up, handle any outstanding TX traffic. */
5779 if (!ifq_is_empty(&ifp->if_snd))
5788 struct bce_softc *sc = xsc;
5789 struct ifnet *ifp = &sc->arpcom.ac_if;
5791 lwkt_serialize_enter(ifp->if_serializer);
5792 bce_tick_serialized(sc);
5793 lwkt_serialize_exit(ifp->if_serializer);
5798 /****************************************************************************/
5799 /* Allows the driver state to be dumped through the sysctl interface. */
5802 /* 0 for success, positive value for failure. */
5803 /****************************************************************************/
5805 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5809 struct bce_softc *sc;
5812 error = sysctl_handle_int(oidp, &result, 0, req);
5814 if (error || !req->newptr)
5818 sc = (struct bce_softc *)arg1;
5819 bce_dump_driver_state(sc);
5826 /****************************************************************************/
5827 /* Allows the hardware state to be dumped through the sysctl interface. */
5830 /* 0 for success, positive value for failure. */
5831 /****************************************************************************/
5833 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5837 struct bce_softc *sc;
5840 error = sysctl_handle_int(oidp, &result, 0, req);
5842 if (error || !req->newptr)
5846 sc = (struct bce_softc *)arg1;
5847 bce_dump_hw_state(sc);
5854 /****************************************************************************/
5855 /* Provides a sysctl interface to allows dumping the RX chain. */
5858 /* 0 for success, positive value for failure. */
5859 /****************************************************************************/
5861 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5865 struct bce_softc *sc;
5868 error = sysctl_handle_int(oidp, &result, 0, req);
5870 if (error || !req->newptr)
5874 sc = (struct bce_softc *)arg1;
5875 bce_dump_rx_chain(sc, 0, USABLE_RX_BD);
5882 /****************************************************************************/
5883 /* Provides a sysctl interface to allows dumping the TX chain. */
5886 /* 0 for success, positive value for failure. */
5887 /****************************************************************************/
5889 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5893 struct bce_softc *sc;
5896 error = sysctl_handle_int(oidp, &result, 0, req);
5898 if (error || !req->newptr)
5902 sc = (struct bce_softc *)arg1;
5903 bce_dump_tx_chain(sc, 0, USABLE_TX_BD);
5910 /****************************************************************************/
5911 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5912 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5915 /* 0 for success, positive value for failure. */
5916 /****************************************************************************/
5918 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5920 struct bce_softc *sc;
5922 uint32_t val, result;
5925 error = sysctl_handle_int(oidp, &result, 0, req);
5926 if (error || (req->newptr == NULL))
5929 /* Make sure the register is accessible. */
5930 if (result < 0x8000) {
5931 sc = (struct bce_softc *)arg1;
5932 val = REG_RD(sc, result);
5933 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5935 } else if (result < 0x0280000) {
5936 sc = (struct bce_softc *)arg1;
5937 val = REG_RD_IND(sc, result);
5938 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5945 /****************************************************************************/
5946 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
5947 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5950 /* 0 for success, positive value for failure. */
5951 /****************************************************************************/
5953 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
5955 struct bce_softc *sc;
5961 error = sysctl_handle_int(oidp, &result, 0, req);
5962 if (error || (req->newptr == NULL))
5965 /* Make sure the register is accessible. */
5966 if (result < 0x20) {
5967 sc = (struct bce_softc *)arg1;
5969 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
5970 if_printf(&sc->arpcom.ac_if,
5971 "phy 0x%02X = 0x%04X\n", result, val);
5977 /****************************************************************************/
5978 /* Provides a sysctl interface to forcing the driver to dump state and */
5979 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5982 /* 0 for success, positive value for failure. */
5983 /****************************************************************************/
5985 bce_sysctl_breakpoint(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;
6007 /****************************************************************************/
6008 /* Adds any sysctl parameters for tuning or debugging purposes. */
6011 /* 0 for success, positive value for failure. */
6012 /****************************************************************************/
6014 bce_add_sysctls(struct bce_softc *sc)
6016 struct sysctl_ctx_list *ctx;
6017 struct sysctl_oid_list *children;
6019 sysctl_ctx_init(&sc->bce_sysctl_ctx);
6020 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
6021 SYSCTL_STATIC_CHILDREN(_hw),
6023 device_get_nameunit(sc->bce_dev),
6025 if (sc->bce_sysctl_tree == NULL) {
6026 device_printf(sc->bce_dev, "can't add sysctl node\n");
6030 ctx = &sc->bce_sysctl_ctx;
6031 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
6033 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
6034 CTLTYPE_INT | CTLFLAG_RW,
6035 sc, 0, bce_sysctl_tx_bds_int, "I",
6036 "Send max coalesced BD count during interrupt");
6037 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
6038 CTLTYPE_INT | CTLFLAG_RW,
6039 sc, 0, bce_sysctl_tx_bds, "I",
6040 "Send max coalesced BD count");
6041 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
6042 CTLTYPE_INT | CTLFLAG_RW,
6043 sc, 0, bce_sysctl_tx_ticks_int, "I",
6044 "Send coalescing ticks during interrupt");
6045 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
6046 CTLTYPE_INT | CTLFLAG_RW,
6047 sc, 0, bce_sysctl_tx_ticks, "I",
6048 "Send coalescing ticks");
6050 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
6051 CTLTYPE_INT | CTLFLAG_RW,
6052 sc, 0, bce_sysctl_rx_bds_int, "I",
6053 "Receive max coalesced BD count during interrupt");
6054 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
6055 CTLTYPE_INT | CTLFLAG_RW,
6056 sc, 0, bce_sysctl_rx_bds, "I",
6057 "Receive max coalesced BD count");
6058 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
6059 CTLTYPE_INT | CTLFLAG_RW,
6060 sc, 0, bce_sysctl_rx_ticks_int, "I",
6061 "Receive coalescing ticks during interrupt");
6062 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
6063 CTLTYPE_INT | CTLFLAG_RW,
6064 sc, 0, bce_sysctl_rx_ticks, "I",
6065 "Receive coalescing ticks");
6068 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6070 CTLFLAG_RD, &sc->rx_low_watermark,
6071 0, "Lowest level of free rx_bd's");
6073 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6075 CTLFLAG_RD, &sc->rx_empty_count,
6076 0, "Number of times the RX chain was empty");
6078 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6080 CTLFLAG_RD, &sc->tx_hi_watermark,
6081 0, "Highest level of used tx_bd's");
6083 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6085 CTLFLAG_RD, &sc->tx_full_count,
6086 0, "Number of times the TX chain was full");
6088 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6089 "l2fhdr_status_errors",
6090 CTLFLAG_RD, &sc->l2fhdr_status_errors,
6091 0, "l2_fhdr status errors");
6093 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6094 "unexpected_attentions",
6095 CTLFLAG_RD, &sc->unexpected_attentions,
6096 0, "unexpected attentions");
6098 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6099 "lost_status_block_updates",
6100 CTLFLAG_RD, &sc->lost_status_block_updates,
6101 0, "lost status block updates");
6103 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6104 "mbuf_alloc_failed",
6105 CTLFLAG_RD, &sc->mbuf_alloc_failed,
6106 0, "mbuf cluster allocation failures");
6109 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6110 "stat_IfHCInOctets",
6111 CTLFLAG_RD, &sc->stat_IfHCInOctets,
6114 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6115 "stat_IfHCInBadOctets",
6116 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
6117 "Bad bytes received");
6119 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6120 "stat_IfHCOutOctets",
6121 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
6124 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6125 "stat_IfHCOutBadOctets",
6126 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
6129 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6130 "stat_IfHCInUcastPkts",
6131 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
6132 "Unicast packets received");
6134 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6135 "stat_IfHCInMulticastPkts",
6136 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
6137 "Multicast packets received");
6139 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6140 "stat_IfHCInBroadcastPkts",
6141 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
6142 "Broadcast packets received");
6144 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6145 "stat_IfHCOutUcastPkts",
6146 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
6147 "Unicast packets sent");
6149 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6150 "stat_IfHCOutMulticastPkts",
6151 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
6152 "Multicast packets sent");
6154 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6155 "stat_IfHCOutBroadcastPkts",
6156 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
6157 "Broadcast packets sent");
6159 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6160 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
6161 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
6162 0, "Internal MAC transmit errors");
6164 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6165 "stat_Dot3StatsCarrierSenseErrors",
6166 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
6167 0, "Carrier sense errors");
6169 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6170 "stat_Dot3StatsFCSErrors",
6171 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
6172 0, "Frame check sequence errors");
6174 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6175 "stat_Dot3StatsAlignmentErrors",
6176 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
6177 0, "Alignment errors");
6179 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6180 "stat_Dot3StatsSingleCollisionFrames",
6181 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
6182 0, "Single Collision Frames");
6184 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6185 "stat_Dot3StatsMultipleCollisionFrames",
6186 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
6187 0, "Multiple Collision Frames");
6189 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6190 "stat_Dot3StatsDeferredTransmissions",
6191 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
6192 0, "Deferred Transmissions");
6194 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6195 "stat_Dot3StatsExcessiveCollisions",
6196 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
6197 0, "Excessive Collisions");
6199 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6200 "stat_Dot3StatsLateCollisions",
6201 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
6202 0, "Late Collisions");
6204 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6205 "stat_EtherStatsCollisions",
6206 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
6209 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6210 "stat_EtherStatsFragments",
6211 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
6214 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6215 "stat_EtherStatsJabbers",
6216 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
6219 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6220 "stat_EtherStatsUndersizePkts",
6221 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
6222 0, "Undersize packets");
6224 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6225 "stat_EtherStatsOverrsizePkts",
6226 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
6227 0, "stat_EtherStatsOverrsizePkts");
6229 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6230 "stat_EtherStatsPktsRx64Octets",
6231 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
6232 0, "Bytes received in 64 byte packets");
6234 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6235 "stat_EtherStatsPktsRx65Octetsto127Octets",
6236 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
6237 0, "Bytes received in 65 to 127 byte packets");
6239 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6240 "stat_EtherStatsPktsRx128Octetsto255Octets",
6241 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
6242 0, "Bytes received in 128 to 255 byte packets");
6244 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6245 "stat_EtherStatsPktsRx256Octetsto511Octets",
6246 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
6247 0, "Bytes received in 256 to 511 byte packets");
6249 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6250 "stat_EtherStatsPktsRx512Octetsto1023Octets",
6251 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
6252 0, "Bytes received in 512 to 1023 byte packets");
6254 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6255 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
6256 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
6257 0, "Bytes received in 1024 t0 1522 byte packets");
6259 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6260 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
6261 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
6262 0, "Bytes received in 1523 to 9022 byte packets");
6264 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6265 "stat_EtherStatsPktsTx64Octets",
6266 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
6267 0, "Bytes sent in 64 byte packets");
6269 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6270 "stat_EtherStatsPktsTx65Octetsto127Octets",
6271 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
6272 0, "Bytes sent in 65 to 127 byte packets");
6274 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6275 "stat_EtherStatsPktsTx128Octetsto255Octets",
6276 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
6277 0, "Bytes sent in 128 to 255 byte packets");
6279 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6280 "stat_EtherStatsPktsTx256Octetsto511Octets",
6281 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
6282 0, "Bytes sent in 256 to 511 byte packets");
6284 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6285 "stat_EtherStatsPktsTx512Octetsto1023Octets",
6286 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
6287 0, "Bytes sent in 512 to 1023 byte packets");
6289 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6290 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
6291 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
6292 0, "Bytes sent in 1024 to 1522 byte packets");
6294 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6295 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
6296 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
6297 0, "Bytes sent in 1523 to 9022 byte packets");
6299 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6300 "stat_XonPauseFramesReceived",
6301 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
6302 0, "XON pause frames receved");
6304 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6305 "stat_XoffPauseFramesReceived",
6306 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
6307 0, "XOFF pause frames received");
6309 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6311 CTLFLAG_RD, &sc->stat_OutXonSent,
6312 0, "XON pause frames sent");
6314 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6316 CTLFLAG_RD, &sc->stat_OutXoffSent,
6317 0, "XOFF pause frames sent");
6319 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6320 "stat_FlowControlDone",
6321 CTLFLAG_RD, &sc->stat_FlowControlDone,
6322 0, "Flow control done");
6324 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6325 "stat_MacControlFramesReceived",
6326 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
6327 0, "MAC control frames received");
6329 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6330 "stat_XoffStateEntered",
6331 CTLFLAG_RD, &sc->stat_XoffStateEntered,
6332 0, "XOFF state entered");
6334 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6335 "stat_IfInFramesL2FilterDiscards",
6336 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
6337 0, "Received L2 packets discarded");
6339 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6340 "stat_IfInRuleCheckerDiscards",
6341 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
6342 0, "Received packets discarded by rule");
6344 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6345 "stat_IfInFTQDiscards",
6346 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
6347 0, "Received packet FTQ discards");
6349 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6350 "stat_IfInMBUFDiscards",
6351 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
6352 0, "Received packets discarded due to lack of controller buffer memory");
6354 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6355 "stat_IfInRuleCheckerP4Hit",
6356 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6357 0, "Received packets rule checker hits");
6359 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6360 "stat_CatchupInRuleCheckerDiscards",
6361 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6362 0, "Received packets discarded in Catchup path");
6364 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6365 "stat_CatchupInFTQDiscards",
6366 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6367 0, "Received packets discarded in FTQ in Catchup path");
6369 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6370 "stat_CatchupInMBUFDiscards",
6371 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6372 0, "Received packets discarded in controller buffer memory in Catchup path");
6374 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6375 "stat_CatchupInRuleCheckerP4Hit",
6376 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6377 0, "Received packets rule checker hits in Catchup path");
6379 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6381 CTLFLAG_RD, &sc->com_no_buffers,
6382 0, "Valid packets received but no RX buffers available");
6385 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6386 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6388 bce_sysctl_driver_state, "I", "Drive state information");
6390 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6391 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6393 bce_sysctl_hw_state, "I", "Hardware state information");
6395 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6396 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6398 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6400 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6401 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
6403 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
6405 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6406 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6408 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6410 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6411 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
6413 bce_sysctl_reg_read, "I", "Register read");
6415 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6416 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
6418 bce_sysctl_phy_read, "I", "PHY register read");
6425 /****************************************************************************/
6426 /* BCE Debug Routines */
6427 /****************************************************************************/
6430 /****************************************************************************/
6431 /* Freezes the controller to allow for a cohesive state dump. */
6435 /****************************************************************************/
6437 bce_freeze_controller(struct bce_softc *sc)
6441 val = REG_RD(sc, BCE_MISC_COMMAND);
6442 val |= BCE_MISC_COMMAND_DISABLE_ALL;
6443 REG_WR(sc, BCE_MISC_COMMAND, val);
6447 /****************************************************************************/
6448 /* Unfreezes the controller after a freeze operation. This may not always */
6449 /* work and the controller will require a reset! */
6453 /****************************************************************************/
6455 bce_unfreeze_controller(struct bce_softc *sc)
6459 val = REG_RD(sc, BCE_MISC_COMMAND);
6460 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6461 REG_WR(sc, BCE_MISC_COMMAND, val);
6465 /****************************************************************************/
6466 /* Prints out information about an mbuf. */
6470 /****************************************************************************/
6472 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6474 struct ifnet *ifp = &sc->arpcom.ac_if;
6475 uint32_t val_hi, val_lo;
6476 struct mbuf *mp = m;
6479 /* Index out of range. */
6480 if_printf(ifp, "mbuf: null pointer\n");
6485 val_hi = BCE_ADDR_HI(mp);
6486 val_lo = BCE_ADDR_LO(mp);
6487 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6488 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6490 if (mp->m_flags & M_EXT)
6492 if (mp->m_flags & M_PKTHDR)
6493 kprintf("M_PKTHDR ");
6494 if (mp->m_flags & M_EOR)
6497 if (mp->m_flags & M_RDONLY)
6498 kprintf("M_RDONLY ");
6501 val_hi = BCE_ADDR_HI(mp->m_data);
6502 val_lo = BCE_ADDR_LO(mp->m_data);
6503 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6505 if (mp->m_flags & M_PKTHDR) {
6506 if_printf(ifp, "- m_pkthdr: flags = ( ");
6507 if (mp->m_flags & M_BCAST)
6508 kprintf("M_BCAST ");
6509 if (mp->m_flags & M_MCAST)
6510 kprintf("M_MCAST ");
6511 if (mp->m_flags & M_FRAG)
6513 if (mp->m_flags & M_FIRSTFRAG)
6514 kprintf("M_FIRSTFRAG ");
6515 if (mp->m_flags & M_LASTFRAG)
6516 kprintf("M_LASTFRAG ");
6518 if (mp->m_flags & M_VLANTAG)
6519 kprintf("M_VLANTAG ");
6522 if (mp->m_flags & M_PROMISC)
6523 kprintf("M_PROMISC ");
6525 kprintf(") csum_flags = ( ");
6526 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6527 kprintf("CSUM_IP ");
6528 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6529 kprintf("CSUM_TCP ");
6530 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6531 kprintf("CSUM_UDP ");
6532 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6533 kprintf("CSUM_IP_FRAGS ");
6534 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6535 kprintf("CSUM_FRAGMENT ");
6537 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6538 kprintf("CSUM_TSO ");
6540 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6541 kprintf("CSUM_IP_CHECKED ");
6542 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6543 kprintf("CSUM_IP_VALID ");
6544 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6545 kprintf("CSUM_DATA_VALID ");
6549 if (mp->m_flags & M_EXT) {
6550 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6551 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6552 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6554 val_hi, val_lo, mp->m_ext.ext_size);
6561 /****************************************************************************/
6562 /* Prints out the mbufs in the TX mbuf chain. */
6566 /****************************************************************************/
6568 bce_dump_tx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6570 struct ifnet *ifp = &sc->arpcom.ac_if;
6574 "----------------------------"
6576 "----------------------------\n");
6578 for (i = 0; i < count; i++) {
6579 if_printf(ifp, "txmbuf[%d]\n", chain_prod);
6580 bce_dump_mbuf(sc, sc->tx_mbuf_ptr[chain_prod]);
6581 chain_prod = TX_CHAIN_IDX(NEXT_TX_BD(chain_prod));
6585 "----------------------------"
6587 "----------------------------\n");
6591 /****************************************************************************/
6592 /* Prints out the mbufs in the RX mbuf chain. */
6596 /****************************************************************************/
6598 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6600 struct ifnet *ifp = &sc->arpcom.ac_if;
6604 "----------------------------"
6606 "----------------------------\n");
6608 for (i = 0; i < count; i++) {
6609 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6610 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6611 chain_prod = RX_CHAIN_IDX(NEXT_RX_BD(chain_prod));
6615 "----------------------------"
6617 "----------------------------\n");
6621 /****************************************************************************/
6622 /* Prints out a tx_bd structure. */
6626 /****************************************************************************/
6628 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6630 struct ifnet *ifp = &sc->arpcom.ac_if;
6632 if (idx > MAX_TX_BD) {
6633 /* Index out of range. */
6634 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6635 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6636 /* TX Chain page pointer. */
6637 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6638 "chain page pointer\n",
6639 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6641 /* Normal tx_bd entry. */
6642 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6644 "vlan tag= 0x%04X, flags = 0x%04X (",
6645 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6646 txbd->tx_bd_mss_nbytes,
6647 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6649 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6650 kprintf(" CONN_FAULT");
6652 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6653 kprintf(" TCP_UDP_CKSUM");
6655 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6656 kprintf(" IP_CKSUM");
6658 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6661 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6662 kprintf(" COAL_NOW");
6664 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6665 kprintf(" DONT_GEN_CRC");
6667 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6670 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6673 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6676 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6677 kprintf(" OPTION_WORD");
6679 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6682 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6690 /****************************************************************************/
6691 /* Prints out a rx_bd structure. */
6695 /****************************************************************************/
6697 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6699 struct ifnet *ifp = &sc->arpcom.ac_if;
6701 if (idx > MAX_RX_BD) {
6702 /* Index out of range. */
6703 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6704 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6705 /* TX Chain page pointer. */
6706 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6707 "chain page pointer\n",
6708 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6710 /* Normal tx_bd entry. */
6711 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6712 "nbytes = 0x%08X, flags = 0x%08X\n",
6713 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6714 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6719 /****************************************************************************/
6720 /* Prints out a l2_fhdr structure. */
6724 /****************************************************************************/
6726 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6728 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6729 "pkt_len = 0x%04X, vlan = 0x%04x, "
6730 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6731 idx, l2fhdr->l2_fhdr_status,
6732 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6733 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6737 /****************************************************************************/
6738 /* Prints out the tx chain. */
6742 /****************************************************************************/
6744 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6746 struct ifnet *ifp = &sc->arpcom.ac_if;
6749 /* First some info about the tx_bd chain structure. */
6751 "----------------------------"
6753 "----------------------------\n");
6755 if_printf(ifp, "page size = 0x%08X, "
6756 "tx chain pages = 0x%08X\n",
6757 (uint32_t)BCM_PAGE_SIZE, (uint32_t)TX_PAGES);
6759 if_printf(ifp, "tx_bd per page = 0x%08X, "
6760 "usable tx_bd per page = 0x%08X\n",
6761 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6762 (uint32_t)USABLE_TX_BD_PER_PAGE);
6764 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD);
6767 "----------------------------"
6769 "----------------------------\n");
6771 /* Now print out the tx_bd's themselves. */
6772 for (i = 0; i < count; i++) {
6775 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6776 bce_dump_txbd(sc, tx_prod, txbd);
6777 tx_prod = TX_CHAIN_IDX(NEXT_TX_BD(tx_prod));
6781 "----------------------------"
6783 "----------------------------\n");
6787 /****************************************************************************/
6788 /* Prints out the rx chain. */
6792 /****************************************************************************/
6794 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6796 struct ifnet *ifp = &sc->arpcom.ac_if;
6799 /* First some info about the tx_bd chain structure. */
6801 "----------------------------"
6803 "----------------------------\n");
6805 if_printf(ifp, "page size = 0x%08X, "
6806 "rx chain pages = 0x%08X\n",
6807 (uint32_t)BCM_PAGE_SIZE, (uint32_t)RX_PAGES);
6809 if_printf(ifp, "rx_bd per page = 0x%08X, "
6810 "usable rx_bd per page = 0x%08X\n",
6811 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6812 (uint32_t)USABLE_RX_BD_PER_PAGE);
6814 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD);
6817 "----------------------------"
6819 "----------------------------\n");
6821 /* Now print out the rx_bd's themselves. */
6822 for (i = 0; i < count; i++) {
6825 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6826 bce_dump_rxbd(sc, rx_prod, rxbd);
6827 rx_prod = RX_CHAIN_IDX(NEXT_RX_BD(rx_prod));
6831 "----------------------------"
6833 "----------------------------\n");
6837 /****************************************************************************/
6838 /* Prints out the status block from host memory. */
6842 /****************************************************************************/
6844 bce_dump_status_block(struct bce_softc *sc)
6846 struct status_block *sblk = sc->status_block;
6847 struct ifnet *ifp = &sc->arpcom.ac_if;
6850 "----------------------------"
6852 "----------------------------\n");
6854 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6856 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6857 sblk->status_attn_bits_ack);
6859 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6860 sblk->status_rx_quick_consumer_index0,
6861 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index0));
6863 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6864 sblk->status_tx_quick_consumer_index0,
6865 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index0));
6867 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6869 /* Theses indices are not used for normal L2 drivers. */
6870 if (sblk->status_rx_quick_consumer_index1) {
6871 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6872 sblk->status_rx_quick_consumer_index1,
6873 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index1));
6876 if (sblk->status_tx_quick_consumer_index1) {
6877 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6878 sblk->status_tx_quick_consumer_index1,
6879 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index1));
6882 if (sblk->status_rx_quick_consumer_index2) {
6883 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6884 sblk->status_rx_quick_consumer_index2,
6885 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index2));
6888 if (sblk->status_tx_quick_consumer_index2) {
6889 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6890 sblk->status_tx_quick_consumer_index2,
6891 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index2));
6894 if (sblk->status_rx_quick_consumer_index3) {
6895 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6896 sblk->status_rx_quick_consumer_index3,
6897 (uint16_t)RX_CHAIN_IDX(sblk->status_rx_quick_consumer_index3));
6900 if (sblk->status_tx_quick_consumer_index3) {
6901 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6902 sblk->status_tx_quick_consumer_index3,
6903 (uint16_t)TX_CHAIN_IDX(sblk->status_tx_quick_consumer_index3));
6906 if (sblk->status_rx_quick_consumer_index4 ||
6907 sblk->status_rx_quick_consumer_index5) {
6908 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6909 sblk->status_rx_quick_consumer_index4,
6910 sblk->status_rx_quick_consumer_index5);
6913 if (sblk->status_rx_quick_consumer_index6 ||
6914 sblk->status_rx_quick_consumer_index7) {
6915 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6916 sblk->status_rx_quick_consumer_index6,
6917 sblk->status_rx_quick_consumer_index7);
6920 if (sblk->status_rx_quick_consumer_index8 ||
6921 sblk->status_rx_quick_consumer_index9) {
6922 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6923 sblk->status_rx_quick_consumer_index8,
6924 sblk->status_rx_quick_consumer_index9);
6927 if (sblk->status_rx_quick_consumer_index10 ||
6928 sblk->status_rx_quick_consumer_index11) {
6929 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6930 sblk->status_rx_quick_consumer_index10,
6931 sblk->status_rx_quick_consumer_index11);
6934 if (sblk->status_rx_quick_consumer_index12 ||
6935 sblk->status_rx_quick_consumer_index13) {
6936 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6937 sblk->status_rx_quick_consumer_index12,
6938 sblk->status_rx_quick_consumer_index13);
6941 if (sblk->status_rx_quick_consumer_index14 ||
6942 sblk->status_rx_quick_consumer_index15) {
6943 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6944 sblk->status_rx_quick_consumer_index14,
6945 sblk->status_rx_quick_consumer_index15);
6948 if (sblk->status_completion_producer_index ||
6949 sblk->status_cmd_consumer_index) {
6950 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6951 sblk->status_completion_producer_index,
6952 sblk->status_cmd_consumer_index);
6956 "----------------------------"
6958 "----------------------------\n");
6962 /****************************************************************************/
6963 /* Prints out the statistics block. */
6967 /****************************************************************************/
6969 bce_dump_stats_block(struct bce_softc *sc)
6971 struct statistics_block *sblk = sc->stats_block;
6972 struct ifnet *ifp = &sc->arpcom.ac_if;
6976 " Stats Block (All Stats Not Shown Are 0) "
6977 "---------------\n");
6979 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
6980 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
6981 sblk->stat_IfHCInOctets_hi,
6982 sblk->stat_IfHCInOctets_lo);
6985 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
6986 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
6987 sblk->stat_IfHCInBadOctets_hi,
6988 sblk->stat_IfHCInBadOctets_lo);
6991 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
6992 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
6993 sblk->stat_IfHCOutOctets_hi,
6994 sblk->stat_IfHCOutOctets_lo);
6997 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
6998 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
6999 sblk->stat_IfHCOutBadOctets_hi,
7000 sblk->stat_IfHCOutBadOctets_lo);
7003 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
7004 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
7005 sblk->stat_IfHCInUcastPkts_hi,
7006 sblk->stat_IfHCInUcastPkts_lo);
7009 if (sblk->stat_IfHCInBroadcastPkts_hi ||
7010 sblk->stat_IfHCInBroadcastPkts_lo) {
7011 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
7012 sblk->stat_IfHCInBroadcastPkts_hi,
7013 sblk->stat_IfHCInBroadcastPkts_lo);
7016 if (sblk->stat_IfHCInMulticastPkts_hi ||
7017 sblk->stat_IfHCInMulticastPkts_lo) {
7018 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
7019 sblk->stat_IfHCInMulticastPkts_hi,
7020 sblk->stat_IfHCInMulticastPkts_lo);
7023 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
7024 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
7025 sblk->stat_IfHCOutUcastPkts_hi,
7026 sblk->stat_IfHCOutUcastPkts_lo);
7029 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
7030 sblk->stat_IfHCOutBroadcastPkts_lo) {
7031 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
7032 sblk->stat_IfHCOutBroadcastPkts_hi,
7033 sblk->stat_IfHCOutBroadcastPkts_lo);
7036 if (sblk->stat_IfHCOutMulticastPkts_hi ||
7037 sblk->stat_IfHCOutMulticastPkts_lo) {
7038 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
7039 sblk->stat_IfHCOutMulticastPkts_hi,
7040 sblk->stat_IfHCOutMulticastPkts_lo);
7043 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
7044 if_printf(ifp, " 0x%08X : "
7045 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
7046 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
7049 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
7050 if_printf(ifp, " 0x%08X : "
7051 "Dot3StatsCarrierSenseErrors\n",
7052 sblk->stat_Dot3StatsCarrierSenseErrors);
7055 if (sblk->stat_Dot3StatsFCSErrors) {
7056 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
7057 sblk->stat_Dot3StatsFCSErrors);
7060 if (sblk->stat_Dot3StatsAlignmentErrors) {
7061 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
7062 sblk->stat_Dot3StatsAlignmentErrors);
7065 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
7066 if_printf(ifp, " 0x%08X : "
7067 "Dot3StatsSingleCollisionFrames\n",
7068 sblk->stat_Dot3StatsSingleCollisionFrames);
7071 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
7072 if_printf(ifp, " 0x%08X : "
7073 "Dot3StatsMultipleCollisionFrames\n",
7074 sblk->stat_Dot3StatsMultipleCollisionFrames);
7077 if (sblk->stat_Dot3StatsDeferredTransmissions) {
7078 if_printf(ifp, " 0x%08X : "
7079 "Dot3StatsDeferredTransmissions\n",
7080 sblk->stat_Dot3StatsDeferredTransmissions);
7083 if (sblk->stat_Dot3StatsExcessiveCollisions) {
7084 if_printf(ifp, " 0x%08X : "
7085 "Dot3StatsExcessiveCollisions\n",
7086 sblk->stat_Dot3StatsExcessiveCollisions);
7089 if (sblk->stat_Dot3StatsLateCollisions) {
7090 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
7091 sblk->stat_Dot3StatsLateCollisions);
7094 if (sblk->stat_EtherStatsCollisions) {
7095 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
7096 sblk->stat_EtherStatsCollisions);
7099 if (sblk->stat_EtherStatsFragments) {
7100 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
7101 sblk->stat_EtherStatsFragments);
7104 if (sblk->stat_EtherStatsJabbers) {
7105 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
7106 sblk->stat_EtherStatsJabbers);
7109 if (sblk->stat_EtherStatsUndersizePkts) {
7110 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
7111 sblk->stat_EtherStatsUndersizePkts);
7114 if (sblk->stat_EtherStatsOverrsizePkts) {
7115 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
7116 sblk->stat_EtherStatsOverrsizePkts);
7119 if (sblk->stat_EtherStatsPktsRx64Octets) {
7120 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
7121 sblk->stat_EtherStatsPktsRx64Octets);
7124 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
7125 if_printf(ifp, " 0x%08X : "
7126 "EtherStatsPktsRx65Octetsto127Octets\n",
7127 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
7130 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
7131 if_printf(ifp, " 0x%08X : "
7132 "EtherStatsPktsRx128Octetsto255Octets\n",
7133 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
7136 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
7137 if_printf(ifp, " 0x%08X : "
7138 "EtherStatsPktsRx256Octetsto511Octets\n",
7139 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
7142 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
7143 if_printf(ifp, " 0x%08X : "
7144 "EtherStatsPktsRx512Octetsto1023Octets\n",
7145 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
7148 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
7149 if_printf(ifp, " 0x%08X : "
7150 "EtherStatsPktsRx1024Octetsto1522Octets\n",
7151 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
7154 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
7155 if_printf(ifp, " 0x%08X : "
7156 "EtherStatsPktsRx1523Octetsto9022Octets\n",
7157 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
7160 if (sblk->stat_EtherStatsPktsTx64Octets) {
7161 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
7162 sblk->stat_EtherStatsPktsTx64Octets);
7165 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
7166 if_printf(ifp, " 0x%08X : "
7167 "EtherStatsPktsTx65Octetsto127Octets\n",
7168 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
7171 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
7172 if_printf(ifp, " 0x%08X : "
7173 "EtherStatsPktsTx128Octetsto255Octets\n",
7174 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
7177 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
7178 if_printf(ifp, " 0x%08X : "
7179 "EtherStatsPktsTx256Octetsto511Octets\n",
7180 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
7183 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
7184 if_printf(ifp, " 0x%08X : "
7185 "EtherStatsPktsTx512Octetsto1023Octets\n",
7186 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
7189 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
7190 if_printf(ifp, " 0x%08X : "
7191 "EtherStatsPktsTx1024Octetsto1522Octets\n",
7192 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
7195 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
7196 if_printf(ifp, " 0x%08X : "
7197 "EtherStatsPktsTx1523Octetsto9022Octets\n",
7198 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
7201 if (sblk->stat_XonPauseFramesReceived) {
7202 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
7203 sblk->stat_XonPauseFramesReceived);
7206 if (sblk->stat_XoffPauseFramesReceived) {
7207 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
7208 sblk->stat_XoffPauseFramesReceived);
7211 if (sblk->stat_OutXonSent) {
7212 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7213 sblk->stat_OutXonSent);
7216 if (sblk->stat_OutXoffSent) {
7217 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7218 sblk->stat_OutXoffSent);
7221 if (sblk->stat_FlowControlDone) {
7222 if_printf(ifp, " 0x%08X : FlowControlDone\n",
7223 sblk->stat_FlowControlDone);
7226 if (sblk->stat_MacControlFramesReceived) {
7227 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
7228 sblk->stat_MacControlFramesReceived);
7231 if (sblk->stat_XoffStateEntered) {
7232 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
7233 sblk->stat_XoffStateEntered);
7236 if (sblk->stat_IfInFramesL2FilterDiscards) {
7237 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
7240 if (sblk->stat_IfInRuleCheckerDiscards) {
7241 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
7242 sblk->stat_IfInRuleCheckerDiscards);
7245 if (sblk->stat_IfInFTQDiscards) {
7246 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
7247 sblk->stat_IfInFTQDiscards);
7250 if (sblk->stat_IfInMBUFDiscards) {
7251 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
7252 sblk->stat_IfInMBUFDiscards);
7255 if (sblk->stat_IfInRuleCheckerP4Hit) {
7256 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
7257 sblk->stat_IfInRuleCheckerP4Hit);
7260 if (sblk->stat_CatchupInRuleCheckerDiscards) {
7261 if_printf(ifp, " 0x%08X : "
7262 "CatchupInRuleCheckerDiscards\n",
7263 sblk->stat_CatchupInRuleCheckerDiscards);
7266 if (sblk->stat_CatchupInFTQDiscards) {
7267 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
7268 sblk->stat_CatchupInFTQDiscards);
7271 if (sblk->stat_CatchupInMBUFDiscards) {
7272 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
7273 sblk->stat_CatchupInMBUFDiscards);
7276 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
7277 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
7278 sblk->stat_CatchupInRuleCheckerP4Hit);
7282 "----------------------------"
7284 "----------------------------\n");
7288 /****************************************************************************/
7289 /* Prints out a summary of the driver state. */
7293 /****************************************************************************/
7295 bce_dump_driver_state(struct bce_softc *sc)
7297 struct ifnet *ifp = &sc->arpcom.ac_if;
7298 uint32_t val_hi, val_lo;
7301 "-----------------------------"
7303 "-----------------------------\n");
7305 val_hi = BCE_ADDR_HI(sc);
7306 val_lo = BCE_ADDR_LO(sc);
7307 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
7308 "virtual address\n", val_hi, val_lo);
7310 val_hi = BCE_ADDR_HI(sc->status_block);
7311 val_lo = BCE_ADDR_LO(sc->status_block);
7312 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
7313 "virtual address\n", val_hi, val_lo);
7315 val_hi = BCE_ADDR_HI(sc->stats_block);
7316 val_lo = BCE_ADDR_LO(sc->stats_block);
7317 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
7318 "virtual address\n", val_hi, val_lo);
7320 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
7321 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
7322 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
7323 "virtual adddress\n", val_hi, val_lo);
7325 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
7326 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
7327 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
7328 "virtual address\n", val_hi, val_lo);
7330 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
7331 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
7332 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
7333 "virtual address\n", val_hi, val_lo);
7335 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
7336 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
7337 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
7338 "virtual address\n", val_hi, val_lo);
7340 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
7341 "h/w intrs\n", sc->interrupts_generated);
7343 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
7344 "rx interrupts handled\n", sc->rx_interrupts);
7346 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
7347 "tx interrupts handled\n", sc->tx_interrupts);
7349 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
7350 "status block index\n", sc->last_status_idx);
7352 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
7353 "tx producer index\n",
7354 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc->tx_prod));
7356 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
7357 "tx consumer index\n",
7358 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc->tx_cons));
7360 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
7361 "tx producer bseq index\n", sc->tx_prod_bseq);
7363 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
7364 "rx producer index\n",
7365 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc->rx_prod));
7367 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
7368 "rx consumer index\n",
7369 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc->rx_cons));
7371 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
7372 "rx producer bseq index\n", sc->rx_prod_bseq);
7374 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7375 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7377 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
7378 "free rx_bd's\n", sc->free_rx_bd);
7380 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
7381 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
7383 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
7384 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
7386 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7387 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7389 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
7392 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
7393 sc->tx_hi_watermark, sc->max_tx_bd);
7395 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
7396 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
7399 "----------------------------"
7401 "----------------------------\n");
7405 /****************************************************************************/
7406 /* Prints out the hardware state through a summary of important registers, */
7407 /* followed by a complete register dump. */
7411 /****************************************************************************/
7413 bce_dump_hw_state(struct bce_softc *sc)
7415 struct ifnet *ifp = &sc->arpcom.ac_if;
7420 "----------------------------"
7422 "----------------------------\n");
7424 if_printf(ifp, "0x%08X - bootcode version\n", sc->bce_bc_ver);
7426 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
7427 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
7428 val1, BCE_MISC_ENABLE_STATUS_BITS);
7430 val1 = REG_RD(sc, BCE_DMA_STATUS);
7431 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
7433 val1 = REG_RD(sc, BCE_CTX_STATUS);
7434 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
7436 val1 = REG_RD(sc, BCE_EMAC_STATUS);
7437 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
7438 val1, BCE_EMAC_STATUS);
7440 val1 = REG_RD(sc, BCE_RPM_STATUS);
7441 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
7443 val1 = REG_RD(sc, BCE_TBDR_STATUS);
7444 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
7445 val1, BCE_TBDR_STATUS);
7447 val1 = REG_RD(sc, BCE_TDMA_STATUS);
7448 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
7449 val1, BCE_TDMA_STATUS);
7451 val1 = REG_RD(sc, BCE_HC_STATUS);
7452 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7454 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7455 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7456 val1, BCE_TXP_CPU_STATE);
7458 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7459 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7460 val1, BCE_TPAT_CPU_STATE);
7462 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7463 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7464 val1, BCE_RXP_CPU_STATE);
7466 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7467 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7468 val1, BCE_COM_CPU_STATE);
7470 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7471 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7472 val1, BCE_MCP_CPU_STATE);
7474 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7475 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7476 val1, BCE_CP_CPU_STATE);
7479 "----------------------------"
7481 "----------------------------\n");
7484 "----------------------------"
7486 "----------------------------\n");
7488 for (i = 0x400; i < 0x8000; i += 0x10) {
7489 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7491 REG_RD(sc, i + 0x4),
7492 REG_RD(sc, i + 0x8),
7493 REG_RD(sc, i + 0xc));
7497 "----------------------------"
7499 "----------------------------\n");
7503 /****************************************************************************/
7504 /* Prints out the TXP state. */
7508 /****************************************************************************/
7510 bce_dump_txp_state(struct bce_softc *sc)
7512 struct ifnet *ifp = &sc->arpcom.ac_if;
7517 "----------------------------"
7519 "----------------------------\n");
7521 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7522 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7523 val1, BCE_TXP_CPU_MODE);
7525 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7526 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7527 val1, BCE_TXP_CPU_STATE);
7529 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7530 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7531 val1, BCE_TXP_CPU_EVENT_MASK);
7534 "----------------------------"
7536 "----------------------------\n");
7538 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7539 /* Skip the big blank spaces */
7540 if (i < 0x454000 && i > 0x5ffff) {
7541 if_printf(ifp, "0x%04X: "
7542 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7544 REG_RD_IND(sc, i + 0x4),
7545 REG_RD_IND(sc, i + 0x8),
7546 REG_RD_IND(sc, i + 0xc));
7551 "----------------------------"
7553 "----------------------------\n");
7557 /****************************************************************************/
7558 /* Prints out the RXP state. */
7562 /****************************************************************************/
7564 bce_dump_rxp_state(struct bce_softc *sc)
7566 struct ifnet *ifp = &sc->arpcom.ac_if;
7571 "----------------------------"
7573 "----------------------------\n");
7575 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7576 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7577 val1, BCE_RXP_CPU_MODE);
7579 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7580 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7581 val1, BCE_RXP_CPU_STATE);
7583 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7584 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7585 val1, BCE_RXP_CPU_EVENT_MASK);
7588 "----------------------------"
7590 "----------------------------\n");
7592 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7593 /* Skip the big blank sapces */
7594 if (i < 0xc5400 && i > 0xdffff) {
7595 if_printf(ifp, "0x%04X: "
7596 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7598 REG_RD_IND(sc, i + 0x4),
7599 REG_RD_IND(sc, i + 0x8),
7600 REG_RD_IND(sc, i + 0xc));
7605 "----------------------------"
7607 "----------------------------\n");
7611 /****************************************************************************/
7612 /* Prints out the TPAT state. */
7616 /****************************************************************************/
7618 bce_dump_tpat_state(struct bce_softc *sc)
7620 struct ifnet *ifp = &sc->arpcom.ac_if;
7625 "----------------------------"
7627 "----------------------------\n");
7629 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7630 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7631 val1, BCE_TPAT_CPU_MODE);
7633 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7634 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7635 val1, BCE_TPAT_CPU_STATE);
7637 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7638 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7639 val1, BCE_TPAT_CPU_EVENT_MASK);
7642 "----------------------------"
7644 "----------------------------\n");
7646 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7647 /* Skip the big blank spaces */
7648 if (i < 0x854000 && i > 0x9ffff) {
7649 if_printf(ifp, "0x%04X: "
7650 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7652 REG_RD_IND(sc, i + 0x4),
7653 REG_RD_IND(sc, i + 0x8),
7654 REG_RD_IND(sc, i + 0xc));
7659 "----------------------------"
7661 "----------------------------\n");
7665 /****************************************************************************/
7666 /* Prints out the driver state and then enters the debugger. */
7670 /****************************************************************************/
7672 bce_breakpoint(struct bce_softc *sc)
7675 bce_freeze_controller(sc);
7678 bce_dump_driver_state(sc);
7679 bce_dump_status_block(sc);
7680 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD);
7681 bce_dump_hw_state(sc);
7682 bce_dump_txp_state(sc);
7685 bce_unfreeze_controller(sc);
7688 /* Call the debugger. */
7692 #endif /* BCE_DEBUG */
7695 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7697 struct bce_softc *sc = arg1;
7699 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7700 &sc->bce_tx_quick_cons_trip_int,
7701 BCE_COALMASK_TX_BDS_INT);
7705 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7707 struct bce_softc *sc = arg1;
7709 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7710 &sc->bce_tx_quick_cons_trip,
7711 BCE_COALMASK_TX_BDS);
7715 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7717 struct bce_softc *sc = arg1;
7719 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7720 &sc->bce_tx_ticks_int,
7721 BCE_COALMASK_TX_TICKS_INT);
7725 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7727 struct bce_softc *sc = arg1;
7729 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7731 BCE_COALMASK_TX_TICKS);
7735 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7737 struct bce_softc *sc = arg1;
7739 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7740 &sc->bce_rx_quick_cons_trip_int,
7741 BCE_COALMASK_RX_BDS_INT);
7745 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7747 struct bce_softc *sc = arg1;
7749 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7750 &sc->bce_rx_quick_cons_trip,
7751 BCE_COALMASK_RX_BDS);
7755 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7757 struct bce_softc *sc = arg1;
7759 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7760 &sc->bce_rx_ticks_int,
7761 BCE_COALMASK_RX_TICKS_INT);
7765 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7767 struct bce_softc *sc = arg1;
7769 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7771 BCE_COALMASK_RX_TICKS);
7775 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7776 uint32_t coalchg_mask)
7778 struct bce_softc *sc = arg1;
7779 struct ifnet *ifp = &sc->arpcom.ac_if;
7782 lwkt_serialize_enter(ifp->if_serializer);
7785 error = sysctl_handle_int(oidp, &v, 0, req);
7786 if (!error && req->newptr != NULL) {
7791 sc->bce_coalchg_mask |= coalchg_mask;
7795 lwkt_serialize_exit(ifp->if_serializer);
7800 bce_coal_change(struct bce_softc *sc)
7802 struct ifnet *ifp = &sc->arpcom.ac_if;
7804 ASSERT_SERIALIZED(ifp->if_serializer);
7806 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7807 sc->bce_coalchg_mask = 0;
7811 if (sc->bce_coalchg_mask &
7812 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7813 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7814 (sc->bce_tx_quick_cons_trip_int << 16) |
7815 sc->bce_tx_quick_cons_trip);
7817 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7818 sc->bce_tx_quick_cons_trip,
7819 sc->bce_tx_quick_cons_trip_int);
7823 if (sc->bce_coalchg_mask &
7824 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7825 REG_WR(sc, BCE_HC_TX_TICKS,
7826 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7828 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7829 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7833 if (sc->bce_coalchg_mask &
7834 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7835 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7836 (sc->bce_rx_quick_cons_trip_int << 16) |
7837 sc->bce_rx_quick_cons_trip);
7839 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7840 sc->bce_rx_quick_cons_trip,
7841 sc->bce_rx_quick_cons_trip_int);
7845 if (sc->bce_coalchg_mask &
7846 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7847 REG_WR(sc, BCE_HC_RX_TICKS,
7848 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7850 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7851 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7855 sc->bce_coalchg_mask = 0;