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>
71 #include <netinet/ip.h>
72 #include <netinet/tcp.h>
75 #include <net/ethernet.h>
77 #include <net/if_arp.h>
78 #include <net/if_dl.h>
79 #include <net/if_media.h>
80 #include <net/if_types.h>
81 #include <net/ifq_var.h>
82 #include <net/vlan/if_vlan_var.h>
83 #include <net/vlan/if_vlan_ether.h>
85 #include <dev/netif/mii_layer/mii.h>
86 #include <dev/netif/mii_layer/miivar.h>
87 #include <dev/netif/mii_layer/brgphyreg.h>
89 #include <bus/pci/pcireg.h>
90 #include <bus/pci/pcivar.h>
92 #include "miibus_if.h"
94 #include <dev/netif/bce/if_bcereg.h>
95 #include <dev/netif/bce/if_bcefw.h>
97 /****************************************************************************/
98 /* BCE Debug Options */
99 /****************************************************************************/
102 static uint32_t bce_debug = BCE_WARN;
106 * 1 = 1 in 2,147,483,648
107 * 256 = 1 in 8,388,608
108 * 2048 = 1 in 1,048,576
109 * 65536 = 1 in 32,768
110 * 1048576 = 1 in 2,048
113 * 1073741824 = 1 in 2
115 * bce_debug_mbuf_allocation_failure:
116 * How often to simulate an mbuf allocation failure.
118 * bce_debug_dma_map_addr_failure:
119 * How often to simulate a DMA mapping failure.
121 * bce_debug_bootcode_running_failure:
122 * How often to simulate a bootcode failure.
124 static int bce_debug_mbuf_allocation_failure = 0;
125 static int bce_debug_dma_map_addr_failure = 0;
126 static int bce_debug_bootcode_running_failure = 0;
128 #endif /* BCE_DEBUG */
131 /****************************************************************************/
132 /* PCI Device ID Table */
134 /* Used by bce_probe() to identify the devices supported by this driver. */
135 /****************************************************************************/
136 #define BCE_DEVDESC_MAX 64
138 static struct bce_type bce_devs[] = {
139 /* BCM5706C Controllers and OEM boards. */
140 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
141 "HP NC370T Multifunction Gigabit Server Adapter" },
142 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
143 "HP NC370i Multifunction Gigabit Server Adapter" },
144 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
145 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
146 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
147 "HP NC371i Multifunction Gigabit Server Adapter" },
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
149 "Broadcom NetXtreme II BCM5706 1000Base-T" },
151 /* BCM5706S controllers and OEM boards. */
152 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
153 "HP NC370F Multifunction Gigabit Server Adapter" },
154 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
155 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
157 /* BCM5708C controllers and OEM boards. */
158 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
159 "HP NC373T PCIe Multifunction Gig Server Adapter" },
160 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
161 "HP NC373i Multifunction Gigabit Server Adapter" },
162 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
163 "HP NC374m PCIe Multifunction Adapter" },
164 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
165 "Broadcom NetXtreme II BCM5708 1000Base-T" },
167 /* BCM5708S controllers and OEM boards. */
168 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
169 "HP NC373m Multifunction Gigabit Server Adapter" },
170 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
171 "HP NC373i Multifunction Gigabit Server Adapter" },
172 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
173 "HP NC373F PCIe Multifunc Giga Server Adapter" },
174 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
175 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
177 /* BCM5709C controllers and OEM boards. */
178 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
179 "HP NC382i DP Multifunction Gigabit Server Adapter" },
180 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
181 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
182 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
183 "Broadcom NetXtreme II BCM5709 1000Base-T" },
185 /* BCM5709S controllers and OEM boards. */
186 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
187 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
188 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
189 "HP NC382i DP Multifunction Gigabit Server Adapter" },
190 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
191 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
193 /* BCM5716 controllers and OEM boards. */
194 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
195 "Broadcom NetXtreme II BCM5716 1000Base-T" },
201 /****************************************************************************/
202 /* Supported Flash NVRAM device data. */
203 /****************************************************************************/
204 static const struct flash_spec flash_table[] =
206 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
207 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
210 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
211 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
212 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
214 /* Expansion entry 0001 */
215 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
216 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
217 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
219 /* Saifun SA25F010 (non-buffered flash) */
220 /* strap, cfg1, & write1 need updates */
221 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
222 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
223 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
224 "Non-buffered flash (128kB)"},
225 /* Saifun SA25F020 (non-buffered flash) */
226 /* strap, cfg1, & write1 need updates */
227 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
228 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
229 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
230 "Non-buffered flash (256kB)"},
231 /* Expansion entry 0100 */
232 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
233 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
234 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
236 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
237 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
238 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
239 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
240 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
241 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
242 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
243 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
244 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
245 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
246 /* Saifun SA25F005 (non-buffered flash) */
247 /* strap, cfg1, & write1 need updates */
248 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
249 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
250 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
251 "Non-buffered flash (64kB)"},
253 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
254 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
255 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
257 /* Expansion entry 1001 */
258 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
259 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
260 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
262 /* Expansion entry 1010 */
263 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
264 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
265 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
267 /* ATMEL AT45DB011B (buffered flash) */
268 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
269 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
270 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
271 "Buffered flash (128kB)"},
272 /* Expansion entry 1100 */
273 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
274 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
275 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
277 /* Expansion entry 1101 */
278 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
279 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
280 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
282 /* Ateml Expansion entry 1110 */
283 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
284 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
285 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
286 "Entry 1110 (Atmel)"},
287 /* ATMEL AT45DB021B (buffered flash) */
288 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
289 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
290 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
291 "Buffered flash (256kB)"},
295 * The BCM5709 controllers transparently handle the
296 * differences between Atmel 264 byte pages and all
297 * flash devices which use 256 byte pages, so no
298 * logical-to-physical mapping is required in the
301 static struct flash_spec flash_5709 = {
302 .flags = BCE_NV_BUFFERED,
303 .page_bits = BCM5709_FLASH_PAGE_BITS,
304 .page_size = BCM5709_FLASH_PAGE_SIZE,
305 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
306 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
307 .name = "5709/5716 buffered flash (256kB)",
311 /****************************************************************************/
312 /* DragonFly device entry points. */
313 /****************************************************************************/
314 static int bce_probe(device_t);
315 static int bce_attach(device_t);
316 static int bce_detach(device_t);
317 static void bce_shutdown(device_t);
319 /****************************************************************************/
320 /* BCE Debug Data Structure Dump Routines */
321 /****************************************************************************/
323 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
324 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
325 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
326 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
327 static void bce_dump_l2fhdr(struct bce_softc *, int,
328 struct l2_fhdr *) __unused;
329 static void bce_dump_tx_chain(struct bce_softc *, int, int);
330 static void bce_dump_rx_chain(struct bce_softc *, int, int);
331 static void bce_dump_status_block(struct bce_softc *);
332 static void bce_dump_driver_state(struct bce_softc *);
333 static void bce_dump_stats_block(struct bce_softc *) __unused;
334 static void bce_dump_hw_state(struct bce_softc *);
335 static void bce_dump_txp_state(struct bce_softc *);
336 static void bce_dump_rxp_state(struct bce_softc *) __unused;
337 static void bce_dump_tpat_state(struct bce_softc *) __unused;
338 static void bce_freeze_controller(struct bce_softc *) __unused;
339 static void bce_unfreeze_controller(struct bce_softc *) __unused;
340 static void bce_breakpoint(struct bce_softc *);
341 #endif /* BCE_DEBUG */
344 /****************************************************************************/
345 /* BCE Register/Memory Access Routines */
346 /****************************************************************************/
347 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
348 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
349 static void bce_shmem_wr(struct bce_softc *, uint32_t, uint32_t);
350 static uint32_t bce_shmem_rd(struct bce_softc *, u32);
351 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
352 static int bce_miibus_read_reg(device_t, int, int);
353 static int bce_miibus_write_reg(device_t, int, int, int);
354 static void bce_miibus_statchg(device_t);
357 /****************************************************************************/
358 /* BCE NVRAM Access Routines */
359 /****************************************************************************/
360 static int bce_acquire_nvram_lock(struct bce_softc *);
361 static int bce_release_nvram_lock(struct bce_softc *);
362 static void bce_enable_nvram_access(struct bce_softc *);
363 static void bce_disable_nvram_access(struct bce_softc *);
364 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
366 static int bce_init_nvram(struct bce_softc *);
367 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
368 static int bce_nvram_test(struct bce_softc *);
370 /****************************************************************************/
371 /* BCE DMA Allocate/Free Routines */
372 /****************************************************************************/
373 static int bce_dma_alloc(struct bce_softc *);
374 static void bce_dma_free(struct bce_softc *);
375 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
377 /****************************************************************************/
378 /* BCE Firmware Synchronization and Load */
379 /****************************************************************************/
380 static int bce_fw_sync(struct bce_softc *, uint32_t);
381 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
383 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
385 static void bce_start_cpu(struct bce_softc *, struct cpu_reg *);
386 static void bce_halt_cpu(struct bce_softc *, struct cpu_reg *);
387 static void bce_start_rxp_cpu(struct bce_softc *);
388 static void bce_init_rxp_cpu(struct bce_softc *);
389 static void bce_init_txp_cpu(struct bce_softc *);
390 static void bce_init_tpat_cpu(struct bce_softc *);
391 static void bce_init_cp_cpu(struct bce_softc *);
392 static void bce_init_com_cpu(struct bce_softc *);
393 static void bce_init_cpus(struct bce_softc *);
395 static void bce_stop(struct bce_softc *);
396 static int bce_reset(struct bce_softc *, uint32_t);
397 static int bce_chipinit(struct bce_softc *);
398 static int bce_blockinit(struct bce_softc *);
399 static int bce_newbuf_std(struct bce_softc *, uint16_t *, uint16_t *,
401 static void bce_setup_rxdesc_std(struct bce_softc *, uint16_t, uint32_t *);
402 static void bce_probe_pci_caps(struct bce_softc *);
403 static void bce_print_adapter_info(struct bce_softc *);
404 static void bce_get_media(struct bce_softc *);
406 static void bce_init_tx_context(struct bce_softc *);
407 static int bce_init_tx_chain(struct bce_softc *);
408 static void bce_init_rx_context(struct bce_softc *);
409 static int bce_init_rx_chain(struct bce_softc *);
410 static void bce_free_rx_chain(struct bce_softc *);
411 static void bce_free_tx_chain(struct bce_softc *);
413 static int bce_encap(struct bce_softc *, struct mbuf **);
414 static int bce_tso_setup(struct bce_softc *, struct mbuf **,
415 uint16_t *, uint16_t *);
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 int 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, uint16_t);
429 static void bce_tx_intr(struct bce_softc *, uint16_t);
430 static void bce_disable_intr(struct bce_softc *);
431 static void bce_enable_intr(struct bce_softc *);
432 static void bce_reenable_intr(struct bce_softc *);
434 #ifdef DEVICE_POLLING
435 static void bce_poll(struct ifnet *, enum poll_cmd, int);
437 static void bce_intr(struct bce_softc *);
438 static void bce_intr_legacy(void *);
439 static void bce_intr_msi(void *);
440 static void bce_intr_msi_oneshot(void *);
441 static void bce_set_rx_mode(struct bce_softc *);
442 static void bce_stats_update(struct bce_softc *);
443 static void bce_tick(void *);
444 static void bce_tick_serialized(struct bce_softc *);
445 static void bce_pulse(void *);
446 static void bce_pulse_check_msi(struct bce_softc *);
447 static void bce_add_sysctls(struct bce_softc *);
449 static void bce_coal_change(struct bce_softc *);
450 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
451 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
452 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
453 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
454 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
455 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
456 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
457 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
458 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
459 uint32_t *, uint32_t);
463 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
464 * takes 1023 as the TX ticks limit. However, using 1023 will
465 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
466 * there is _no_ network activity on the NIC.
468 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
469 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
470 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
471 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
472 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
473 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
474 static uint32_t bce_rx_ticks_int = 150; /* bcm: 18 */
475 static uint32_t bce_rx_ticks = 150; /* bcm: 18 */
477 static int bce_msi_enable = 1;
479 static int bce_rx_pages = RX_PAGES_DEFAULT;
480 static int bce_tx_pages = TX_PAGES_DEFAULT;
482 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
483 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
484 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
485 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
486 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
487 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
488 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
489 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
490 TUNABLE_INT("hw.bce.msi.enable", &bce_msi_enable);
491 TUNABLE_INT("hw.bce.rx_pages", &bce_rx_pages);
492 TUNABLE_INT("hw.bce.tx_pages", &bce_tx_pages);
494 /****************************************************************************/
495 /* DragonFly device dispatch table. */
496 /****************************************************************************/
497 static device_method_t bce_methods[] = {
498 /* Device interface */
499 DEVMETHOD(device_probe, bce_probe),
500 DEVMETHOD(device_attach, bce_attach),
501 DEVMETHOD(device_detach, bce_detach),
502 DEVMETHOD(device_shutdown, bce_shutdown),
505 DEVMETHOD(bus_print_child, bus_generic_print_child),
506 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
509 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
510 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
511 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
516 static driver_t bce_driver = {
519 sizeof(struct bce_softc)
522 static devclass_t bce_devclass;
525 DECLARE_DUMMY_MODULE(if_bce);
526 MODULE_DEPEND(bce, miibus, 1, 1, 1);
527 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
528 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
531 /****************************************************************************/
532 /* Device probe function. */
534 /* Compares the device to the driver's list of supported devices and */
535 /* reports back to the OS whether this is the right driver for the device. */
538 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
539 /****************************************************************************/
541 bce_probe(device_t dev)
544 uint16_t vid, did, svid, sdid;
546 /* Get the data for the device to be probed. */
547 vid = pci_get_vendor(dev);
548 did = pci_get_device(dev);
549 svid = pci_get_subvendor(dev);
550 sdid = pci_get_subdevice(dev);
552 /* Look through the list of known devices for a match. */
553 for (t = bce_devs; t->bce_name != NULL; ++t) {
554 if (vid == t->bce_vid && did == t->bce_did &&
555 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
556 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
557 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
560 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
562 /* Print out the device identity. */
563 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
565 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
567 device_set_desc_copy(dev, descbuf);
568 kfree(descbuf, M_TEMP);
576 /****************************************************************************/
577 /* PCI Capabilities Probe Function. */
579 /* Walks the PCI capabiites list for the device to find what features are */
584 /****************************************************************************/
586 bce_print_adapter_info(struct bce_softc *sc)
588 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
590 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
591 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
594 if (sc->bce_flags & BCE_PCIE_FLAG) {
595 kprintf("Bus (PCIe x%d, ", sc->link_width);
596 switch (sc->link_speed) {
598 kprintf("2.5Gbps); ");
604 kprintf("Unknown link speed); ");
608 kprintf("Bus (PCI%s, %s, %dMHz); ",
609 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
610 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
614 /* Firmware version and device features. */
615 kprintf("B/C (%s)", sc->bce_bc_ver);
617 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
618 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
620 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
621 kprintf("MFW[%s]", sc->bce_mfw_ver);
622 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
630 /****************************************************************************/
631 /* PCI Capabilities Probe Function. */
633 /* Walks the PCI capabiites list for the device to find what features are */
638 /****************************************************************************/
640 bce_probe_pci_caps(struct bce_softc *sc)
642 device_t dev = sc->bce_dev;
645 if (pci_is_pcix(dev))
646 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
648 ptr = pci_get_pciecap_ptr(dev);
650 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
652 sc->link_speed = link_status & 0xf;
653 sc->link_width = (link_status >> 4) & 0x3f;
654 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
655 sc->bce_flags |= BCE_PCIE_FLAG;
660 /****************************************************************************/
661 /* Device attach function. */
663 /* Allocates device resources, performs secondary chip identification, */
664 /* resets and initializes the hardware, and initializes driver instance */
668 /* 0 on success, positive value on failure. */
669 /****************************************************************************/
671 bce_attach(device_t dev)
673 struct bce_softc *sc = device_get_softc(dev);
674 struct ifnet *ifp = &sc->arpcom.ac_if;
677 void (*irq_handle)(void *);
680 struct mii_probe_args mii_args;
681 uintptr_t mii_priv = 0;
684 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
686 pci_enable_busmaster(dev);
688 bce_probe_pci_caps(sc);
690 /* Allocate PCI memory resources. */
692 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
693 RF_ACTIVE | PCI_RF_DENSE);
694 if (sc->bce_res_mem == NULL) {
695 device_printf(dev, "PCI memory allocation failed\n");
698 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
699 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
701 /* Allocate PCI IRQ resources. */
702 sc->bce_irq_type = pci_alloc_1intr(dev, bce_msi_enable,
703 &sc->bce_irq_rid, &irq_flags);
705 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
706 &sc->bce_irq_rid, irq_flags);
707 if (sc->bce_res_irq == NULL) {
708 device_printf(dev, "PCI map interrupt failed\n");
714 * Configure byte swap and enable indirect register access.
715 * Rely on CPU to do target byte swapping on big endian systems.
716 * Access to registers outside of PCI configurtion space are not
717 * valid until this is done.
719 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
720 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
721 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
723 /* Save ASIC revsion info. */
724 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
726 /* Weed out any non-production controller revisions. */
727 switch (BCE_CHIP_ID(sc)) {
728 case BCE_CHIP_ID_5706_A0:
729 case BCE_CHIP_ID_5706_A1:
730 case BCE_CHIP_ID_5708_A0:
731 case BCE_CHIP_ID_5708_B0:
732 case BCE_CHIP_ID_5709_A0:
733 case BCE_CHIP_ID_5709_B0:
734 case BCE_CHIP_ID_5709_B1:
736 /* 5709C B2 seems to work fine */
737 case BCE_CHIP_ID_5709_B2:
739 device_printf(dev, "Unsupported chip id 0x%08x!\n",
745 mii_priv |= BRGPHY_FLAG_WIRESPEED;
746 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
747 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax ||
748 BCE_CHIP_REV(sc) == BCE_CHIP_REV_Bx)
749 mii_priv |= BRGPHY_FLAG_NO_EARLYDAC;
751 mii_priv |= BRGPHY_FLAG_BER_BUG;
754 if (sc->bce_irq_type == PCI_INTR_TYPE_LEGACY) {
755 irq_handle = bce_intr_legacy;
756 } else if (sc->bce_irq_type == PCI_INTR_TYPE_MSI) {
757 irq_handle = bce_intr_msi;
758 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
759 irq_handle = bce_intr_msi_oneshot;
760 sc->bce_flags |= BCE_ONESHOT_MSI_FLAG;
763 panic("%s: unsupported intr type %d",
764 device_get_nameunit(dev), sc->bce_irq_type);
768 * Find the base address for shared memory access.
769 * Newer versions of bootcode use a signature and offset
770 * while older versions use a fixed address.
772 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
773 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
774 BCE_SHM_HDR_SIGNATURE_SIG) {
775 /* Multi-port devices use different offsets in shared memory. */
776 sc->bce_shmem_base = REG_RD_IND(sc,
777 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
779 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
781 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
783 /* Fetch the bootcode revision. */
784 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
785 for (i = 0, j = 0; i < 3; i++) {
789 num = (uint8_t)(val >> (24 - (i * 8)));
790 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
791 if (num >= k || !skip0 || k == 1) {
792 sc->bce_bc_ver[j++] = (num / k) + '0';
797 sc->bce_bc_ver[j++] = '.';
800 /* Check if any management firwmare is running. */
801 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
802 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
803 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
805 /* Allow time for firmware to enter the running state. */
806 for (i = 0; i < 30; i++) {
807 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
808 if (val & BCE_CONDITION_MFW_RUN_MASK)
814 /* Check the current bootcode state. */
815 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
816 BCE_CONDITION_MFW_RUN_MASK;
817 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
818 val != BCE_CONDITION_MFW_RUN_NONE) {
819 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
821 for (i = 0, j = 0; j < 3; j++) {
822 val = bce_reg_rd_ind(sc, addr + j * 4);
824 memcpy(&sc->bce_mfw_ver[i], &val, 4);
829 /* Get PCI bus information (speed and type). */
830 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
831 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
834 sc->bce_flags |= BCE_PCIX_FLAG;
836 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
837 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
839 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
840 sc->bus_speed_mhz = 133;
843 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
844 sc->bus_speed_mhz = 100;
847 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
848 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
849 sc->bus_speed_mhz = 66;
852 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
853 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
854 sc->bus_speed_mhz = 50;
857 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
858 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
859 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
860 sc->bus_speed_mhz = 33;
864 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
865 sc->bus_speed_mhz = 66;
867 sc->bus_speed_mhz = 33;
870 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
871 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
873 /* Reset the controller. */
874 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
878 /* Initialize the controller. */
879 rc = bce_chipinit(sc);
881 device_printf(dev, "Controller initialization failed!\n");
885 /* Perform NVRAM test. */
886 rc = bce_nvram_test(sc);
888 device_printf(dev, "NVRAM test failed!\n");
892 /* Fetch the permanent Ethernet MAC address. */
893 bce_get_mac_addr(sc);
896 * Trip points control how many BDs
897 * should be ready before generating an
898 * interrupt while ticks control how long
899 * a BD can sit in the chain before
900 * generating an interrupt. Set the default
901 * values for the RX and TX rings.
905 /* Force more frequent interrupts. */
906 sc->bce_tx_quick_cons_trip_int = 1;
907 sc->bce_tx_quick_cons_trip = 1;
908 sc->bce_tx_ticks_int = 0;
909 sc->bce_tx_ticks = 0;
911 sc->bce_rx_quick_cons_trip_int = 1;
912 sc->bce_rx_quick_cons_trip = 1;
913 sc->bce_rx_ticks_int = 0;
914 sc->bce_rx_ticks = 0;
916 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
917 sc->bce_tx_quick_cons_trip = bce_tx_bds;
918 sc->bce_tx_ticks_int = bce_tx_ticks_int;
919 sc->bce_tx_ticks = bce_tx_ticks;
921 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
922 sc->bce_rx_quick_cons_trip = bce_rx_bds;
923 sc->bce_rx_ticks_int = bce_rx_ticks_int;
924 sc->bce_rx_ticks = bce_rx_ticks;
927 /* Update statistics once every second. */
928 sc->bce_stats_ticks = 1000000 & 0xffff00;
930 /* Find the media type for the adapter. */
933 /* Allocate DMA memory resources. */
934 rc = bce_dma_alloc(sc);
936 device_printf(dev, "DMA resource allocation failed!\n");
940 /* Initialize the ifnet interface. */
942 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
943 ifp->if_ioctl = bce_ioctl;
944 ifp->if_start = bce_start;
945 ifp->if_init = bce_init;
946 ifp->if_watchdog = bce_watchdog;
947 #ifdef DEVICE_POLLING
948 ifp->if_poll = bce_poll;
950 ifp->if_mtu = ETHERMTU;
951 ifp->if_hwassist = BCE_CSUM_FEATURES | CSUM_TSO;
952 ifp->if_capabilities = BCE_IF_CAPABILITIES;
953 ifp->if_capenable = ifp->if_capabilities;
954 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD(sc));
955 ifq_set_ready(&ifp->if_snd);
957 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
958 ifp->if_baudrate = IF_Gbps(2.5);
960 ifp->if_baudrate = IF_Gbps(1);
962 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
963 sc->mbuf_alloc_size = MCLBYTES;
968 mii_probe_args_init(&mii_args, bce_ifmedia_upd, bce_ifmedia_sts);
969 mii_args.mii_probemask = 1 << sc->bce_phy_addr;
970 mii_args.mii_privtag = MII_PRIVTAG_BRGPHY;
971 mii_args.mii_priv = mii_priv;
973 rc = mii_probe(dev, &sc->bce_miibus, &mii_args);
975 device_printf(dev, "PHY probe failed!\n");
979 /* Attach to the Ethernet interface list. */
980 ether_ifattach(ifp, sc->eaddr, NULL);
982 callout_init_mp(&sc->bce_tick_callout);
983 callout_init_mp(&sc->bce_pulse_callout);
985 /* Hookup IRQ last. */
986 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, irq_handle, sc,
987 &sc->bce_intrhand, ifp->if_serializer);
989 device_printf(dev, "Failed to setup IRQ!\n");
994 ifp->if_cpuid = rman_get_cpuid(sc->bce_res_irq);
995 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
997 /* Print some important debugging info. */
998 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
1000 /* Add the supported sysctls to the kernel. */
1001 bce_add_sysctls(sc);
1004 * The chip reset earlier notified the bootcode that
1005 * a driver is present. We now need to start our pulse
1006 * routine so that the bootcode is reminded that we're
1011 /* Get the firmware running so IPMI still works */
1015 bce_print_adapter_info(sc);
1024 /****************************************************************************/
1025 /* Device detach function. */
1027 /* Stops the controller, resets the controller, and releases resources. */
1030 /* 0 on success, positive value on failure. */
1031 /****************************************************************************/
1033 bce_detach(device_t dev)
1035 struct bce_softc *sc = device_get_softc(dev);
1037 if (device_is_attached(dev)) {
1038 struct ifnet *ifp = &sc->arpcom.ac_if;
1041 /* Stop and reset the controller. */
1042 lwkt_serialize_enter(ifp->if_serializer);
1043 callout_stop(&sc->bce_pulse_callout);
1045 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1046 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1048 msg = BCE_DRV_MSG_CODE_UNLOAD;
1050 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1051 lwkt_serialize_exit(ifp->if_serializer);
1053 ether_ifdetach(ifp);
1056 /* If we have a child device on the MII bus remove it too. */
1058 device_delete_child(dev, sc->bce_miibus);
1059 bus_generic_detach(dev);
1061 if (sc->bce_res_irq != NULL) {
1062 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
1066 if (sc->bce_irq_type == PCI_INTR_TYPE_MSI)
1067 pci_release_msi(dev);
1069 if (sc->bce_res_mem != NULL) {
1070 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1076 if (sc->bce_sysctl_tree != NULL)
1077 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1083 /****************************************************************************/
1084 /* Device shutdown function. */
1086 /* Stops and resets the controller. */
1090 /****************************************************************************/
1092 bce_shutdown(device_t dev)
1094 struct bce_softc *sc = device_get_softc(dev);
1095 struct ifnet *ifp = &sc->arpcom.ac_if;
1098 lwkt_serialize_enter(ifp->if_serializer);
1100 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1101 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1103 msg = BCE_DRV_MSG_CODE_UNLOAD;
1105 lwkt_serialize_exit(ifp->if_serializer);
1109 /****************************************************************************/
1110 /* Indirect register read. */
1112 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1113 /* configuration space. Using this mechanism avoids issues with posted */
1114 /* reads but is much slower than memory-mapped I/O. */
1117 /* The value of the register. */
1118 /****************************************************************************/
1120 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1122 device_t dev = sc->bce_dev;
1124 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1128 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1129 DBPRINT(sc, BCE_EXCESSIVE,
1130 "%s(); offset = 0x%08X, val = 0x%08X\n",
1131 __func__, offset, val);
1135 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1140 /****************************************************************************/
1141 /* Indirect register write. */
1143 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1144 /* configuration space. Using this mechanism avoids issues with posted */
1145 /* writes but is muchh slower than memory-mapped I/O. */
1149 /****************************************************************************/
1151 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1153 device_t dev = sc->bce_dev;
1155 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1156 __func__, offset, val);
1158 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1159 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1163 /****************************************************************************/
1164 /* Shared memory write. */
1166 /* Writes NetXtreme II shared memory region. */
1170 /****************************************************************************/
1172 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1174 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1178 /****************************************************************************/
1179 /* Shared memory read. */
1181 /* Reads NetXtreme II shared memory region. */
1184 /* The 32 bit value read. */
1185 /****************************************************************************/
1187 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1189 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1193 /****************************************************************************/
1194 /* Context memory write. */
1196 /* The NetXtreme II controller uses context memory to track connection */
1197 /* information for L2 and higher network protocols. */
1201 /****************************************************************************/
1203 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1206 uint32_t idx, offset = ctx_offset + cid_addr;
1207 uint32_t val, retry_cnt = 5;
1209 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1210 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1211 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1212 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1214 for (idx = 0; idx < retry_cnt; idx++) {
1215 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1216 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1221 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1222 device_printf(sc->bce_dev,
1223 "Unable to write CTX memory: "
1224 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1225 cid_addr, ctx_offset);
1228 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1229 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1234 /****************************************************************************/
1235 /* PHY register read. */
1237 /* Implements register reads on the MII bus. */
1240 /* The value of the register. */
1241 /****************************************************************************/
1243 bce_miibus_read_reg(device_t dev, int phy, int reg)
1245 struct bce_softc *sc = device_get_softc(dev);
1249 /* Make sure we are accessing the correct PHY address. */
1250 KASSERT(phy == sc->bce_phy_addr,
1251 ("invalid phyno %d, should be %d\n", phy, sc->bce_phy_addr));
1253 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1254 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1255 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1257 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1258 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1263 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1264 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1265 BCE_EMAC_MDIO_COMM_START_BUSY;
1266 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1268 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1271 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1272 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1275 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1276 val &= BCE_EMAC_MDIO_COMM_DATA;
1281 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1282 if_printf(&sc->arpcom.ac_if,
1283 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1287 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1290 DBPRINT(sc, BCE_EXCESSIVE,
1291 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1292 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1294 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1295 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1296 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1298 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1299 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1303 return (val & 0xffff);
1307 /****************************************************************************/
1308 /* PHY register write. */
1310 /* Implements register writes on the MII bus. */
1313 /* The value of the register. */
1314 /****************************************************************************/
1316 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1318 struct bce_softc *sc = device_get_softc(dev);
1322 /* Make sure we are accessing the correct PHY address. */
1323 KASSERT(phy == sc->bce_phy_addr,
1324 ("invalid phyno %d, should be %d\n", phy, sc->bce_phy_addr));
1326 DBPRINT(sc, BCE_EXCESSIVE,
1327 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1328 __func__, phy, (uint16_t)(reg & 0xffff),
1329 (uint16_t)(val & 0xffff));
1331 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1332 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1333 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1335 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1336 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1341 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1342 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1343 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1344 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1346 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1349 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1350 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1356 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1357 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1359 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1360 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1361 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1363 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1364 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1372 /****************************************************************************/
1373 /* MII bus status change. */
1375 /* Called by the MII bus driver when the PHY establishes link to set the */
1376 /* MAC interface registers. */
1380 /****************************************************************************/
1382 bce_miibus_statchg(device_t dev)
1384 struct bce_softc *sc = device_get_softc(dev);
1385 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1387 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1388 mii->mii_media_active);
1391 /* Decode the interface media flags. */
1392 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1393 switch(IFM_TYPE(mii->mii_media_active)) {
1395 kprintf("Ethernet )");
1398 kprintf("Unknown )");
1402 kprintf(" Media Options: ( ");
1403 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1405 kprintf("Autoselect )");
1408 kprintf("Manual )");
1414 kprintf("10Base-T )");
1417 kprintf("100Base-TX )");
1420 kprintf("1000Base-SX )");
1423 kprintf("1000Base-T )");
1430 kprintf(" Global Options: (");
1431 if (mii->mii_media_active & IFM_FDX)
1432 kprintf(" FullDuplex");
1433 if (mii->mii_media_active & IFM_HDX)
1434 kprintf(" HalfDuplex");
1435 if (mii->mii_media_active & IFM_LOOP)
1436 kprintf(" Loopback");
1437 if (mii->mii_media_active & IFM_FLAG0)
1439 if (mii->mii_media_active & IFM_FLAG1)
1441 if (mii->mii_media_active & IFM_FLAG2)
1446 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1449 * Set MII or GMII interface based on the speed negotiated
1452 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1453 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1454 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1455 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1457 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1458 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1462 * Set half or full duplex based on the duplicity negotiated
1465 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1466 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1467 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1469 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1470 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1475 /****************************************************************************/
1476 /* Acquire NVRAM lock. */
1478 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1479 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1480 /* for use by the driver. */
1483 /* 0 on success, positive value on failure. */
1484 /****************************************************************************/
1486 bce_acquire_nvram_lock(struct bce_softc *sc)
1491 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1493 /* Request access to the flash interface. */
1494 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1495 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1496 val = REG_RD(sc, BCE_NVM_SW_ARB);
1497 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1503 if (j >= NVRAM_TIMEOUT_COUNT) {
1504 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1511 /****************************************************************************/
1512 /* Release NVRAM lock. */
1514 /* When the caller is finished accessing NVRAM the lock must be released. */
1515 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1516 /* for use by the driver. */
1519 /* 0 on success, positive value on failure. */
1520 /****************************************************************************/
1522 bce_release_nvram_lock(struct bce_softc *sc)
1527 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1530 * Relinquish nvram interface.
1532 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1534 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1535 val = REG_RD(sc, BCE_NVM_SW_ARB);
1536 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1542 if (j >= NVRAM_TIMEOUT_COUNT) {
1543 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1550 /****************************************************************************/
1551 /* Enable NVRAM access. */
1553 /* Before accessing NVRAM for read or write operations the caller must */
1554 /* enabled NVRAM access. */
1558 /****************************************************************************/
1560 bce_enable_nvram_access(struct bce_softc *sc)
1564 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1566 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1567 /* Enable both bits, even on read. */
1568 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1569 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1573 /****************************************************************************/
1574 /* Disable NVRAM access. */
1576 /* When the caller is finished accessing NVRAM access must be disabled. */
1580 /****************************************************************************/
1582 bce_disable_nvram_access(struct bce_softc *sc)
1586 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1588 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1590 /* Disable both bits, even after read. */
1591 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1592 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1596 /****************************************************************************/
1597 /* Read a dword (32 bits) from NVRAM. */
1599 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1600 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1603 /* 0 on success and the 32 bit value read, positive value on failure. */
1604 /****************************************************************************/
1606 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1612 /* Build the command word. */
1613 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1615 /* Calculate the offset for buffered flash. */
1616 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1617 offset = ((offset / sc->bce_flash_info->page_size) <<
1618 sc->bce_flash_info->page_bits) +
1619 (offset % sc->bce_flash_info->page_size);
1623 * Clear the DONE bit separately, set the address to read,
1624 * and issue the read.
1626 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1627 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1628 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1630 /* Wait for completion. */
1631 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1636 val = REG_RD(sc, BCE_NVM_COMMAND);
1637 if (val & BCE_NVM_COMMAND_DONE) {
1638 val = REG_RD(sc, BCE_NVM_READ);
1641 memcpy(ret_val, &val, 4);
1646 /* Check for errors. */
1647 if (i >= NVRAM_TIMEOUT_COUNT) {
1648 if_printf(&sc->arpcom.ac_if,
1649 "Timeout error reading NVRAM at offset 0x%08X!\n",
1657 /****************************************************************************/
1658 /* Initialize NVRAM access. */
1660 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1661 /* access that device. */
1664 /* 0 on success, positive value on failure. */
1665 /****************************************************************************/
1667 bce_init_nvram(struct bce_softc *sc)
1670 int j, entry_count, rc = 0;
1671 const struct flash_spec *flash;
1673 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1675 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1676 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1677 sc->bce_flash_info = &flash_5709;
1678 goto bce_init_nvram_get_flash_size;
1681 /* Determine the selected interface. */
1682 val = REG_RD(sc, BCE_NVM_CFG1);
1684 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1687 * Flash reconfiguration is required to support additional
1688 * NVRAM devices not directly supported in hardware.
1689 * Check if the flash interface was reconfigured
1693 if (val & 0x40000000) {
1694 /* Flash interface reconfigured by bootcode. */
1696 DBPRINT(sc, BCE_INFO_LOAD,
1697 "%s(): Flash WAS reconfigured.\n", __func__);
1699 for (j = 0, flash = flash_table; j < entry_count;
1701 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1702 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1703 sc->bce_flash_info = flash;
1708 /* Flash interface not yet reconfigured. */
1711 DBPRINT(sc, BCE_INFO_LOAD,
1712 "%s(): Flash was NOT reconfigured.\n", __func__);
1714 if (val & (1 << 23))
1715 mask = FLASH_BACKUP_STRAP_MASK;
1717 mask = FLASH_STRAP_MASK;
1719 /* Look for the matching NVRAM device configuration data. */
1720 for (j = 0, flash = flash_table; j < entry_count;
1722 /* Check if the device matches any of the known devices. */
1723 if ((val & mask) == (flash->strapping & mask)) {
1724 /* Found a device match. */
1725 sc->bce_flash_info = flash;
1727 /* Request access to the flash interface. */
1728 rc = bce_acquire_nvram_lock(sc);
1732 /* Reconfigure the flash interface. */
1733 bce_enable_nvram_access(sc);
1734 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1735 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1736 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1737 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1738 bce_disable_nvram_access(sc);
1739 bce_release_nvram_lock(sc);
1745 /* Check if a matching device was found. */
1746 if (j == entry_count) {
1747 sc->bce_flash_info = NULL;
1748 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1752 bce_init_nvram_get_flash_size:
1753 /* Write the flash config data to the shared memory interface. */
1754 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1755 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1757 sc->bce_flash_size = val;
1759 sc->bce_flash_size = sc->bce_flash_info->total_size;
1761 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1762 __func__, sc->bce_flash_info->total_size);
1764 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1770 /****************************************************************************/
1771 /* Read an arbitrary range of data from NVRAM. */
1773 /* Prepares the NVRAM interface for access and reads the requested data */
1774 /* into the supplied buffer. */
1777 /* 0 on success and the data read, positive value on failure. */
1778 /****************************************************************************/
1780 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1783 uint32_t cmd_flags, offset32, len32, extra;
1789 /* Request access to the flash interface. */
1790 rc = bce_acquire_nvram_lock(sc);
1794 /* Enable access to flash interface */
1795 bce_enable_nvram_access(sc);
1803 /* XXX should we release nvram lock if read_dword() fails? */
1809 pre_len = 4 - (offset & 3);
1811 if (pre_len >= len32) {
1813 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1815 cmd_flags = BCE_NVM_COMMAND_FIRST;
1818 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1822 memcpy(ret_buf, buf + (offset & 3), pre_len);
1830 extra = 4 - (len32 & 3);
1831 len32 = (len32 + 4) & ~3;
1838 cmd_flags = BCE_NVM_COMMAND_LAST;
1840 cmd_flags = BCE_NVM_COMMAND_FIRST |
1841 BCE_NVM_COMMAND_LAST;
1843 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1845 memcpy(ret_buf, buf, 4 - extra);
1846 } else if (len32 > 0) {
1849 /* Read the first word. */
1853 cmd_flags = BCE_NVM_COMMAND_FIRST;
1855 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1857 /* Advance to the next dword. */
1862 while (len32 > 4 && rc == 0) {
1863 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1865 /* Advance to the next dword. */
1872 goto bce_nvram_read_locked_exit;
1874 cmd_flags = BCE_NVM_COMMAND_LAST;
1875 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1877 memcpy(ret_buf, buf, 4 - extra);
1880 bce_nvram_read_locked_exit:
1881 /* Disable access to flash interface and release the lock. */
1882 bce_disable_nvram_access(sc);
1883 bce_release_nvram_lock(sc);
1889 /****************************************************************************/
1890 /* Verifies that NVRAM is accessible and contains valid data. */
1892 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1896 /* 0 on success, positive value on failure. */
1897 /****************************************************************************/
1899 bce_nvram_test(struct bce_softc *sc)
1901 uint32_t buf[BCE_NVRAM_SIZE / 4];
1902 uint32_t magic, csum;
1903 uint8_t *data = (uint8_t *)buf;
1907 * Check that the device NVRAM is valid by reading
1908 * the magic value at offset 0.
1910 rc = bce_nvram_read(sc, 0, data, 4);
1914 magic = be32toh(buf[0]);
1915 if (magic != BCE_NVRAM_MAGIC) {
1916 if_printf(&sc->arpcom.ac_if,
1917 "Invalid NVRAM magic value! Expected: 0x%08X, "
1918 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1923 * Verify that the device NVRAM includes valid
1924 * configuration data.
1926 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1930 csum = ether_crc32_le(data, 0x100);
1931 if (csum != BCE_CRC32_RESIDUAL) {
1932 if_printf(&sc->arpcom.ac_if,
1933 "Invalid Manufacturing Information NVRAM CRC! "
1934 "Expected: 0x%08X, Found: 0x%08X\n",
1935 BCE_CRC32_RESIDUAL, csum);
1939 csum = ether_crc32_le(data + 0x100, 0x100);
1940 if (csum != BCE_CRC32_RESIDUAL) {
1941 if_printf(&sc->arpcom.ac_if,
1942 "Invalid Feature Configuration Information "
1943 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1944 BCE_CRC32_RESIDUAL, csum);
1951 /****************************************************************************/
1952 /* Identifies the current media type of the controller and sets the PHY */
1957 /****************************************************************************/
1959 bce_get_media(struct bce_softc *sc)
1963 sc->bce_phy_addr = 1;
1965 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1966 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1967 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1968 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1972 * The BCM5709S is software configurable
1973 * for Copper or SerDes operation.
1975 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1977 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1978 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1982 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1983 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
1986 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
1989 if (pci_get_function(sc->bce_dev) == 0) {
1994 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2002 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2006 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
2007 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2010 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
2011 sc->bce_flags |= BCE_NO_WOL_FLAG;
2012 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2013 sc->bce_phy_addr = 2;
2014 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
2015 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
2016 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
2018 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
2019 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
2020 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
2025 /****************************************************************************/
2026 /* Free any DMA memory owned by the driver. */
2028 /* Scans through each data structre that requires DMA memory and frees */
2029 /* the memory if allocated. */
2033 /****************************************************************************/
2035 bce_dma_free(struct bce_softc *sc)
2039 /* Destroy the status block. */
2040 if (sc->status_tag != NULL) {
2041 if (sc->status_block != NULL) {
2042 bus_dmamap_unload(sc->status_tag, sc->status_map);
2043 bus_dmamem_free(sc->status_tag, sc->status_block,
2046 bus_dma_tag_destroy(sc->status_tag);
2049 /* Destroy the statistics block. */
2050 if (sc->stats_tag != NULL) {
2051 if (sc->stats_block != NULL) {
2052 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2053 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2056 bus_dma_tag_destroy(sc->stats_tag);
2059 /* Destroy the CTX DMA stuffs. */
2060 if (sc->ctx_tag != NULL) {
2061 for (i = 0; i < sc->ctx_pages; i++) {
2062 if (sc->ctx_block[i] != NULL) {
2063 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2064 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2068 bus_dma_tag_destroy(sc->ctx_tag);
2071 /* Destroy the TX buffer descriptor DMA stuffs. */
2072 if (sc->tx_bd_chain_tag != NULL) {
2073 for (i = 0; i < sc->tx_pages; i++) {
2074 if (sc->tx_bd_chain[i] != NULL) {
2075 bus_dmamap_unload(sc->tx_bd_chain_tag,
2076 sc->tx_bd_chain_map[i]);
2077 bus_dmamem_free(sc->tx_bd_chain_tag,
2079 sc->tx_bd_chain_map[i]);
2082 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2085 /* Destroy the RX buffer descriptor DMA stuffs. */
2086 if (sc->rx_bd_chain_tag != NULL) {
2087 for (i = 0; i < sc->rx_pages; i++) {
2088 if (sc->rx_bd_chain[i] != NULL) {
2089 bus_dmamap_unload(sc->rx_bd_chain_tag,
2090 sc->rx_bd_chain_map[i]);
2091 bus_dmamem_free(sc->rx_bd_chain_tag,
2093 sc->rx_bd_chain_map[i]);
2096 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2099 /* Destroy the TX mbuf DMA stuffs. */
2100 if (sc->tx_mbuf_tag != NULL) {
2101 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
2102 /* Must have been unloaded in bce_stop() */
2103 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2104 bus_dmamap_destroy(sc->tx_mbuf_tag,
2105 sc->tx_mbuf_map[i]);
2107 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2110 /* Destroy the RX mbuf DMA stuffs. */
2111 if (sc->rx_mbuf_tag != NULL) {
2112 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
2113 /* Must have been unloaded in bce_stop() */
2114 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2115 bus_dmamap_destroy(sc->rx_mbuf_tag,
2116 sc->rx_mbuf_map[i]);
2118 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2119 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2122 /* Destroy the parent tag */
2123 if (sc->parent_tag != NULL)
2124 bus_dma_tag_destroy(sc->parent_tag);
2126 if (sc->tx_bd_chain_map != NULL)
2127 kfree(sc->tx_bd_chain_map, M_DEVBUF);
2128 if (sc->tx_bd_chain != NULL)
2129 kfree(sc->tx_bd_chain, M_DEVBUF);
2130 if (sc->tx_bd_chain_paddr != NULL)
2131 kfree(sc->tx_bd_chain_paddr, M_DEVBUF);
2133 if (sc->rx_bd_chain_map != NULL)
2134 kfree(sc->rx_bd_chain_map, M_DEVBUF);
2135 if (sc->rx_bd_chain != NULL)
2136 kfree(sc->rx_bd_chain, M_DEVBUF);
2137 if (sc->rx_bd_chain_paddr != NULL)
2138 kfree(sc->rx_bd_chain_paddr, M_DEVBUF);
2140 if (sc->tx_mbuf_map != NULL)
2141 kfree(sc->tx_mbuf_map, M_DEVBUF);
2142 if (sc->tx_mbuf_ptr != NULL)
2143 kfree(sc->tx_mbuf_ptr, M_DEVBUF);
2145 if (sc->rx_mbuf_map != NULL)
2146 kfree(sc->rx_mbuf_map, M_DEVBUF);
2147 if (sc->rx_mbuf_ptr != NULL)
2148 kfree(sc->rx_mbuf_ptr, M_DEVBUF);
2149 if (sc->rx_mbuf_paddr != NULL)
2150 kfree(sc->rx_mbuf_paddr, M_DEVBUF);
2154 /****************************************************************************/
2155 /* Get DMA memory from the OS. */
2157 /* Validates that the OS has provided DMA buffers in response to a */
2158 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2159 /* When the callback is used the OS will return 0 for the mapping function */
2160 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2161 /* failures back to the caller. */
2165 /****************************************************************************/
2167 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2169 bus_addr_t *busaddr = arg;
2172 * Simulate a mapping failure.
2175 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2176 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2177 __FILE__, __LINE__);
2180 /* Check for an error and signal the caller that an error occurred. */
2184 KASSERT(nseg == 1, ("only one segment is allowed"));
2185 *busaddr = segs->ds_addr;
2189 /****************************************************************************/
2190 /* Allocate any DMA memory needed by the driver. */
2192 /* Allocates DMA memory needed for the various global structures needed by */
2195 /* Memory alignment requirements: */
2196 /* -----------------+----------+----------+----------+----------+ */
2197 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2198 /* -----------------+----------+----------+----------+----------+ */
2199 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2200 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2201 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2202 /* PG Buffers | none | none | none | none | */
2203 /* TX Buffers | none | none | none | none | */
2204 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2205 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2206 /* -----------------+----------+----------+----------+----------+ */
2208 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2211 /* 0 for success, positive value for failure. */
2212 /****************************************************************************/
2214 bce_dma_alloc(struct bce_softc *sc)
2216 struct ifnet *ifp = &sc->arpcom.ac_if;
2217 int i, j, rc = 0, pages;
2218 bus_addr_t busaddr, max_busaddr;
2219 bus_size_t status_align, stats_align;
2221 pages = device_getenv_int(sc->bce_dev, "rx_pages", bce_rx_pages);
2222 if (pages <= 0 || pages > RX_PAGES_MAX || !powerof2(pages)) {
2223 device_printf(sc->bce_dev, "invalid # of RX pages\n");
2224 pages = RX_PAGES_DEFAULT;
2226 sc->rx_pages = pages;
2228 pages = device_getenv_int(sc->bce_dev, "tx_pages", bce_tx_pages);
2229 if (pages <= 0 || pages > TX_PAGES_MAX || !powerof2(pages)) {
2230 device_printf(sc->bce_dev, "invalid # of TX pages\n");
2231 pages = TX_PAGES_DEFAULT;
2233 sc->tx_pages = pages;
2235 sc->tx_bd_chain_map = kmalloc(sizeof(bus_dmamap_t) * sc->tx_pages,
2236 M_DEVBUF, M_WAITOK | M_ZERO);
2237 sc->tx_bd_chain = kmalloc(sizeof(struct tx_bd *) * sc->tx_pages,
2238 M_DEVBUF, M_WAITOK | M_ZERO);
2239 sc->tx_bd_chain_paddr = kmalloc(sizeof(bus_addr_t) * sc->tx_pages,
2240 M_DEVBUF, M_WAITOK | M_ZERO);
2242 sc->rx_bd_chain_map = kmalloc(sizeof(bus_dmamap_t) * sc->rx_pages,
2243 M_DEVBUF, M_WAITOK | M_ZERO);
2244 sc->rx_bd_chain = kmalloc(sizeof(struct rx_bd *) * sc->rx_pages,
2245 M_DEVBUF, M_WAITOK | M_ZERO);
2246 sc->rx_bd_chain_paddr = kmalloc(sizeof(bus_addr_t) * sc->rx_pages,
2247 M_DEVBUF, M_WAITOK | M_ZERO);
2249 sc->tx_mbuf_map = kmalloc(sizeof(bus_dmamap_t) * TOTAL_TX_BD(sc),
2250 M_DEVBUF, M_WAITOK | M_ZERO);
2251 sc->tx_mbuf_ptr = kmalloc(sizeof(struct mbuf *) * TOTAL_TX_BD(sc),
2252 M_DEVBUF, M_WAITOK | M_ZERO);
2254 sc->rx_mbuf_map = kmalloc(sizeof(bus_dmamap_t) * TOTAL_RX_BD(sc),
2255 M_DEVBUF, M_WAITOK | M_ZERO);
2256 sc->rx_mbuf_ptr = kmalloc(sizeof(struct mbuf *) * TOTAL_RX_BD(sc),
2257 M_DEVBUF, M_WAITOK | M_ZERO);
2258 sc->rx_mbuf_paddr = kmalloc(sizeof(bus_addr_t) * TOTAL_RX_BD(sc),
2259 M_DEVBUF, M_WAITOK | M_ZERO);
2262 * The embedded PCIe to PCI-X bridge (EPB)
2263 * in the 5708 cannot address memory above
2264 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2266 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2267 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2269 max_busaddr = BUS_SPACE_MAXADDR;
2272 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2274 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2275 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2276 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2277 if (sc->ctx_pages == 0)
2279 if (sc->ctx_pages > BCE_CTX_PAGES) {
2280 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2292 * Allocate the parent bus DMA tag appropriate for PCI.
2294 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2295 max_busaddr, BUS_SPACE_MAXADDR,
2297 BUS_SPACE_MAXSIZE_32BIT, 0,
2298 BUS_SPACE_MAXSIZE_32BIT,
2299 0, &sc->parent_tag);
2301 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2306 * Allocate status block.
2308 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2309 status_align, BCE_STATUS_BLK_SZ,
2310 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2311 &sc->status_tag, &sc->status_map,
2312 &sc->status_block_paddr);
2313 if (sc->status_block == NULL) {
2314 if_printf(ifp, "Could not allocate status block!\n");
2319 * Allocate statistics block.
2321 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2322 stats_align, BCE_STATS_BLK_SZ,
2323 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2324 &sc->stats_tag, &sc->stats_map,
2325 &sc->stats_block_paddr);
2326 if (sc->stats_block == NULL) {
2327 if_printf(ifp, "Could not allocate statistics block!\n");
2332 * Allocate context block, if needed
2334 if (sc->ctx_pages != 0) {
2335 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2336 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2338 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2341 if_printf(ifp, "Could not allocate "
2342 "context block DMA tag!\n");
2346 for (i = 0; i < sc->ctx_pages; i++) {
2347 rc = bus_dmamem_alloc(sc->ctx_tag,
2348 (void **)&sc->ctx_block[i],
2349 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2353 if_printf(ifp, "Could not allocate %dth context "
2354 "DMA memory!\n", i);
2358 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2359 sc->ctx_block[i], BCM_PAGE_SIZE,
2360 bce_dma_map_addr, &busaddr,
2363 if (rc == EINPROGRESS) {
2364 panic("%s coherent memory loading "
2365 "is still in progress!", ifp->if_xname);
2367 if_printf(ifp, "Could not map %dth context "
2368 "DMA memory!\n", i);
2369 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2371 sc->ctx_block[i] = NULL;
2374 sc->ctx_paddr[i] = busaddr;
2379 * Create a DMA tag for the TX buffer descriptor chain,
2380 * allocate and clear the memory, and fetch the
2381 * physical address of the block.
2383 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2384 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2386 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2387 0, &sc->tx_bd_chain_tag);
2389 if_printf(ifp, "Could not allocate "
2390 "TX descriptor chain DMA tag!\n");
2394 for (i = 0; i < sc->tx_pages; i++) {
2395 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2396 (void **)&sc->tx_bd_chain[i],
2397 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2399 &sc->tx_bd_chain_map[i]);
2401 if_printf(ifp, "Could not allocate %dth TX descriptor "
2402 "chain DMA memory!\n", i);
2406 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2407 sc->tx_bd_chain_map[i],
2408 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2409 bce_dma_map_addr, &busaddr,
2412 if (rc == EINPROGRESS) {
2413 panic("%s coherent memory loading "
2414 "is still in progress!", ifp->if_xname);
2416 if_printf(ifp, "Could not map %dth TX descriptor "
2417 "chain DMA memory!\n", i);
2418 bus_dmamem_free(sc->tx_bd_chain_tag,
2420 sc->tx_bd_chain_map[i]);
2421 sc->tx_bd_chain[i] = NULL;
2425 sc->tx_bd_chain_paddr[i] = busaddr;
2426 /* DRC - Fix for 64 bit systems. */
2427 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2428 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2431 /* Create a DMA tag for TX mbufs. */
2432 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2433 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2435 IP_MAXPACKET + sizeof(struct ether_vlan_header),
2436 BCE_MAX_SEGMENTS, PAGE_SIZE,
2437 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2441 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2445 /* Create DMA maps for the TX mbufs clusters. */
2446 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
2447 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2448 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2449 &sc->tx_mbuf_map[i]);
2451 for (j = 0; j < i; ++j) {
2452 bus_dmamap_destroy(sc->tx_mbuf_tag,
2453 sc->tx_mbuf_map[i]);
2455 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2456 sc->tx_mbuf_tag = NULL;
2458 if_printf(ifp, "Unable to create "
2459 "%dth TX mbuf DMA map!\n", i);
2465 * Create a DMA tag for the RX buffer descriptor chain,
2466 * allocate and clear the memory, and fetch the physical
2467 * address of the blocks.
2469 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2470 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2472 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2473 0, &sc->rx_bd_chain_tag);
2475 if_printf(ifp, "Could not allocate "
2476 "RX descriptor chain DMA tag!\n");
2480 for (i = 0; i < sc->rx_pages; i++) {
2481 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2482 (void **)&sc->rx_bd_chain[i],
2483 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2485 &sc->rx_bd_chain_map[i]);
2487 if_printf(ifp, "Could not allocate %dth RX descriptor "
2488 "chain DMA memory!\n", i);
2492 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2493 sc->rx_bd_chain_map[i],
2494 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2495 bce_dma_map_addr, &busaddr,
2498 if (rc == EINPROGRESS) {
2499 panic("%s coherent memory loading "
2500 "is still in progress!", ifp->if_xname);
2502 if_printf(ifp, "Could not map %dth RX descriptor "
2503 "chain DMA memory!\n", i);
2504 bus_dmamem_free(sc->rx_bd_chain_tag,
2506 sc->rx_bd_chain_map[i]);
2507 sc->rx_bd_chain[i] = NULL;
2511 sc->rx_bd_chain_paddr[i] = busaddr;
2512 /* DRC - Fix for 64 bit systems. */
2513 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2514 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2517 /* Create a DMA tag for RX mbufs. */
2518 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2519 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2521 MCLBYTES, 1, MCLBYTES,
2522 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2526 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2530 /* Create tmp DMA map for RX mbuf clusters. */
2531 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2532 &sc->rx_mbuf_tmpmap);
2534 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2535 sc->rx_mbuf_tag = NULL;
2537 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2541 /* Create DMA maps for the RX mbuf clusters. */
2542 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
2543 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2544 &sc->rx_mbuf_map[i]);
2546 for (j = 0; j < i; ++j) {
2547 bus_dmamap_destroy(sc->rx_mbuf_tag,
2548 sc->rx_mbuf_map[j]);
2550 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2551 sc->rx_mbuf_tag = NULL;
2553 if_printf(ifp, "Unable to create "
2554 "%dth RX mbuf DMA map!\n", i);
2562 /****************************************************************************/
2563 /* Firmware synchronization. */
2565 /* Before performing certain events such as a chip reset, synchronize with */
2566 /* the firmware first. */
2569 /* 0 for success, positive value for failure. */
2570 /****************************************************************************/
2572 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2577 /* Don't waste any time if we've timed out before. */
2578 if (sc->bce_fw_timed_out)
2581 /* Increment the message sequence number. */
2582 sc->bce_fw_wr_seq++;
2583 msg_data |= sc->bce_fw_wr_seq;
2585 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2587 /* Send the message to the bootcode driver mailbox. */
2588 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2590 /* Wait for the bootcode to acknowledge the message. */
2591 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2592 /* Check for a response in the bootcode firmware mailbox. */
2593 val = bce_shmem_rd(sc, BCE_FW_MB);
2594 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2599 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2600 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2601 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2602 if_printf(&sc->arpcom.ac_if,
2603 "Firmware synchronization timeout! "
2604 "msg_data = 0x%08X\n", msg_data);
2606 msg_data &= ~BCE_DRV_MSG_CODE;
2607 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2609 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2611 sc->bce_fw_timed_out = 1;
2618 /****************************************************************************/
2619 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2623 /****************************************************************************/
2625 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2626 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2631 for (i = 0; i < rv2p_code_len; i += 8) {
2632 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2634 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2637 if (rv2p_proc == RV2P_PROC1) {
2638 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2639 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2641 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2642 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2646 /* Reset the processor, un-stall is done later. */
2647 if (rv2p_proc == RV2P_PROC1)
2648 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2650 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2654 /****************************************************************************/
2655 /* Load RISC processor firmware. */
2657 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2658 /* associated with a particular processor. */
2662 /****************************************************************************/
2664 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2670 bce_halt_cpu(sc, cpu_reg);
2672 /* Load the Text area. */
2673 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2675 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2676 REG_WR_IND(sc, offset, fw->text[j]);
2679 /* Load the Data area. */
2680 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2682 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2683 REG_WR_IND(sc, offset, fw->data[j]);
2686 /* Load the SBSS area. */
2687 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2689 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2690 REG_WR_IND(sc, offset, fw->sbss[j]);
2693 /* Load the BSS area. */
2694 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2696 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2697 REG_WR_IND(sc, offset, fw->bss[j]);
2700 /* Load the Read-Only area. */
2701 offset = cpu_reg->spad_base +
2702 (fw->rodata_addr - cpu_reg->mips_view_base);
2704 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2705 REG_WR_IND(sc, offset, fw->rodata[j]);
2708 /* Clear the pre-fetch instruction and set the FW start address. */
2709 REG_WR_IND(sc, cpu_reg->inst, 0);
2710 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2714 /****************************************************************************/
2715 /* Starts the RISC processor. */
2717 /* Assumes the CPU starting address has already been set. */
2721 /****************************************************************************/
2723 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2727 /* Start the CPU. */
2728 val = REG_RD_IND(sc, cpu_reg->mode);
2729 val &= ~cpu_reg->mode_value_halt;
2730 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2731 REG_WR_IND(sc, cpu_reg->mode, val);
2735 /****************************************************************************/
2736 /* Halts the RISC processor. */
2740 /****************************************************************************/
2742 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2747 val = REG_RD_IND(sc, cpu_reg->mode);
2748 val |= cpu_reg->mode_value_halt;
2749 REG_WR_IND(sc, cpu_reg->mode, val);
2750 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2754 /****************************************************************************/
2755 /* Start the RX CPU. */
2759 /****************************************************************************/
2761 bce_start_rxp_cpu(struct bce_softc *sc)
2763 struct cpu_reg cpu_reg;
2765 cpu_reg.mode = BCE_RXP_CPU_MODE;
2766 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2767 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2768 cpu_reg.state = BCE_RXP_CPU_STATE;
2769 cpu_reg.state_value_clear = 0xffffff;
2770 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2771 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2772 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2773 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2774 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2775 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2776 cpu_reg.mips_view_base = 0x8000000;
2778 bce_start_cpu(sc, &cpu_reg);
2782 /****************************************************************************/
2783 /* Initialize the RX CPU. */
2787 /****************************************************************************/
2789 bce_init_rxp_cpu(struct bce_softc *sc)
2791 struct cpu_reg cpu_reg;
2794 cpu_reg.mode = BCE_RXP_CPU_MODE;
2795 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2796 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2797 cpu_reg.state = BCE_RXP_CPU_STATE;
2798 cpu_reg.state_value_clear = 0xffffff;
2799 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2800 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2801 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2802 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2803 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2804 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2805 cpu_reg.mips_view_base = 0x8000000;
2807 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2808 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2809 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2810 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2811 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2812 fw.start_addr = bce_RXP_b09FwStartAddr;
2814 fw.text_addr = bce_RXP_b09FwTextAddr;
2815 fw.text_len = bce_RXP_b09FwTextLen;
2817 fw.text = bce_RXP_b09FwText;
2819 fw.data_addr = bce_RXP_b09FwDataAddr;
2820 fw.data_len = bce_RXP_b09FwDataLen;
2822 fw.data = bce_RXP_b09FwData;
2824 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2825 fw.sbss_len = bce_RXP_b09FwSbssLen;
2827 fw.sbss = bce_RXP_b09FwSbss;
2829 fw.bss_addr = bce_RXP_b09FwBssAddr;
2830 fw.bss_len = bce_RXP_b09FwBssLen;
2832 fw.bss = bce_RXP_b09FwBss;
2834 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2835 fw.rodata_len = bce_RXP_b09FwRodataLen;
2836 fw.rodata_index = 0;
2837 fw.rodata = bce_RXP_b09FwRodata;
2839 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2840 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2841 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2842 fw.start_addr = bce_RXP_b06FwStartAddr;
2844 fw.text_addr = bce_RXP_b06FwTextAddr;
2845 fw.text_len = bce_RXP_b06FwTextLen;
2847 fw.text = bce_RXP_b06FwText;
2849 fw.data_addr = bce_RXP_b06FwDataAddr;
2850 fw.data_len = bce_RXP_b06FwDataLen;
2852 fw.data = bce_RXP_b06FwData;
2854 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2855 fw.sbss_len = bce_RXP_b06FwSbssLen;
2857 fw.sbss = bce_RXP_b06FwSbss;
2859 fw.bss_addr = bce_RXP_b06FwBssAddr;
2860 fw.bss_len = bce_RXP_b06FwBssLen;
2862 fw.bss = bce_RXP_b06FwBss;
2864 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2865 fw.rodata_len = bce_RXP_b06FwRodataLen;
2866 fw.rodata_index = 0;
2867 fw.rodata = bce_RXP_b06FwRodata;
2870 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2871 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2872 /* Delay RXP start until initialization is complete. */
2876 /****************************************************************************/
2877 /* Initialize the TX CPU. */
2881 /****************************************************************************/
2883 bce_init_txp_cpu(struct bce_softc *sc)
2885 struct cpu_reg cpu_reg;
2888 cpu_reg.mode = BCE_TXP_CPU_MODE;
2889 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2890 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2891 cpu_reg.state = BCE_TXP_CPU_STATE;
2892 cpu_reg.state_value_clear = 0xffffff;
2893 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2894 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2895 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2896 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2897 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2898 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2899 cpu_reg.mips_view_base = 0x8000000;
2901 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2902 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2903 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2904 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2905 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2906 fw.start_addr = bce_TXP_b09FwStartAddr;
2908 fw.text_addr = bce_TXP_b09FwTextAddr;
2909 fw.text_len = bce_TXP_b09FwTextLen;
2911 fw.text = bce_TXP_b09FwText;
2913 fw.data_addr = bce_TXP_b09FwDataAddr;
2914 fw.data_len = bce_TXP_b09FwDataLen;
2916 fw.data = bce_TXP_b09FwData;
2918 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2919 fw.sbss_len = bce_TXP_b09FwSbssLen;
2921 fw.sbss = bce_TXP_b09FwSbss;
2923 fw.bss_addr = bce_TXP_b09FwBssAddr;
2924 fw.bss_len = bce_TXP_b09FwBssLen;
2926 fw.bss = bce_TXP_b09FwBss;
2928 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2929 fw.rodata_len = bce_TXP_b09FwRodataLen;
2930 fw.rodata_index = 0;
2931 fw.rodata = bce_TXP_b09FwRodata;
2933 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2934 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2935 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2936 fw.start_addr = bce_TXP_b06FwStartAddr;
2938 fw.text_addr = bce_TXP_b06FwTextAddr;
2939 fw.text_len = bce_TXP_b06FwTextLen;
2941 fw.text = bce_TXP_b06FwText;
2943 fw.data_addr = bce_TXP_b06FwDataAddr;
2944 fw.data_len = bce_TXP_b06FwDataLen;
2946 fw.data = bce_TXP_b06FwData;
2948 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2949 fw.sbss_len = bce_TXP_b06FwSbssLen;
2951 fw.sbss = bce_TXP_b06FwSbss;
2953 fw.bss_addr = bce_TXP_b06FwBssAddr;
2954 fw.bss_len = bce_TXP_b06FwBssLen;
2956 fw.bss = bce_TXP_b06FwBss;
2958 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2959 fw.rodata_len = bce_TXP_b06FwRodataLen;
2960 fw.rodata_index = 0;
2961 fw.rodata = bce_TXP_b06FwRodata;
2964 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2965 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2966 bce_start_cpu(sc, &cpu_reg);
2970 /****************************************************************************/
2971 /* Initialize the TPAT CPU. */
2975 /****************************************************************************/
2977 bce_init_tpat_cpu(struct bce_softc *sc)
2979 struct cpu_reg cpu_reg;
2982 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2983 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2984 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2985 cpu_reg.state = BCE_TPAT_CPU_STATE;
2986 cpu_reg.state_value_clear = 0xffffff;
2987 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2988 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2989 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2990 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2991 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2992 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2993 cpu_reg.mips_view_base = 0x8000000;
2995 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2996 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2997 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
2998 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
2999 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
3000 fw.start_addr = bce_TPAT_b09FwStartAddr;
3002 fw.text_addr = bce_TPAT_b09FwTextAddr;
3003 fw.text_len = bce_TPAT_b09FwTextLen;
3005 fw.text = bce_TPAT_b09FwText;
3007 fw.data_addr = bce_TPAT_b09FwDataAddr;
3008 fw.data_len = bce_TPAT_b09FwDataLen;
3010 fw.data = bce_TPAT_b09FwData;
3012 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
3013 fw.sbss_len = bce_TPAT_b09FwSbssLen;
3015 fw.sbss = bce_TPAT_b09FwSbss;
3017 fw.bss_addr = bce_TPAT_b09FwBssAddr;
3018 fw.bss_len = bce_TPAT_b09FwBssLen;
3020 fw.bss = bce_TPAT_b09FwBss;
3022 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
3023 fw.rodata_len = bce_TPAT_b09FwRodataLen;
3024 fw.rodata_index = 0;
3025 fw.rodata = bce_TPAT_b09FwRodata;
3027 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
3028 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
3029 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
3030 fw.start_addr = bce_TPAT_b06FwStartAddr;
3032 fw.text_addr = bce_TPAT_b06FwTextAddr;
3033 fw.text_len = bce_TPAT_b06FwTextLen;
3035 fw.text = bce_TPAT_b06FwText;
3037 fw.data_addr = bce_TPAT_b06FwDataAddr;
3038 fw.data_len = bce_TPAT_b06FwDataLen;
3040 fw.data = bce_TPAT_b06FwData;
3042 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
3043 fw.sbss_len = bce_TPAT_b06FwSbssLen;
3045 fw.sbss = bce_TPAT_b06FwSbss;
3047 fw.bss_addr = bce_TPAT_b06FwBssAddr;
3048 fw.bss_len = bce_TPAT_b06FwBssLen;
3050 fw.bss = bce_TPAT_b06FwBss;
3052 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
3053 fw.rodata_len = bce_TPAT_b06FwRodataLen;
3054 fw.rodata_index = 0;
3055 fw.rodata = bce_TPAT_b06FwRodata;
3058 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
3059 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3060 bce_start_cpu(sc, &cpu_reg);
3064 /****************************************************************************/
3065 /* Initialize the CP CPU. */
3069 /****************************************************************************/
3071 bce_init_cp_cpu(struct bce_softc *sc)
3073 struct cpu_reg cpu_reg;
3076 cpu_reg.mode = BCE_CP_CPU_MODE;
3077 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
3078 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
3079 cpu_reg.state = BCE_CP_CPU_STATE;
3080 cpu_reg.state_value_clear = 0xffffff;
3081 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
3082 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
3083 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
3084 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
3085 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
3086 cpu_reg.spad_base = BCE_CP_SCRATCH;
3087 cpu_reg.mips_view_base = 0x8000000;
3089 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3090 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3091 fw.ver_major = bce_CP_b09FwReleaseMajor;
3092 fw.ver_minor = bce_CP_b09FwReleaseMinor;
3093 fw.ver_fix = bce_CP_b09FwReleaseFix;
3094 fw.start_addr = bce_CP_b09FwStartAddr;
3096 fw.text_addr = bce_CP_b09FwTextAddr;
3097 fw.text_len = bce_CP_b09FwTextLen;
3099 fw.text = bce_CP_b09FwText;
3101 fw.data_addr = bce_CP_b09FwDataAddr;
3102 fw.data_len = bce_CP_b09FwDataLen;
3104 fw.data = bce_CP_b09FwData;
3106 fw.sbss_addr = bce_CP_b09FwSbssAddr;
3107 fw.sbss_len = bce_CP_b09FwSbssLen;
3109 fw.sbss = bce_CP_b09FwSbss;
3111 fw.bss_addr = bce_CP_b09FwBssAddr;
3112 fw.bss_len = bce_CP_b09FwBssLen;
3114 fw.bss = bce_CP_b09FwBss;
3116 fw.rodata_addr = bce_CP_b09FwRodataAddr;
3117 fw.rodata_len = bce_CP_b09FwRodataLen;
3118 fw.rodata_index = 0;
3119 fw.rodata = bce_CP_b09FwRodata;
3121 fw.ver_major = bce_CP_b06FwReleaseMajor;
3122 fw.ver_minor = bce_CP_b06FwReleaseMinor;
3123 fw.ver_fix = bce_CP_b06FwReleaseFix;
3124 fw.start_addr = bce_CP_b06FwStartAddr;
3126 fw.text_addr = bce_CP_b06FwTextAddr;
3127 fw.text_len = bce_CP_b06FwTextLen;
3129 fw.text = bce_CP_b06FwText;
3131 fw.data_addr = bce_CP_b06FwDataAddr;
3132 fw.data_len = bce_CP_b06FwDataLen;
3134 fw.data = bce_CP_b06FwData;
3136 fw.sbss_addr = bce_CP_b06FwSbssAddr;
3137 fw.sbss_len = bce_CP_b06FwSbssLen;
3139 fw.sbss = bce_CP_b06FwSbss;
3141 fw.bss_addr = bce_CP_b06FwBssAddr;
3142 fw.bss_len = bce_CP_b06FwBssLen;
3144 fw.bss = bce_CP_b06FwBss;
3146 fw.rodata_addr = bce_CP_b06FwRodataAddr;
3147 fw.rodata_len = bce_CP_b06FwRodataLen;
3148 fw.rodata_index = 0;
3149 fw.rodata = bce_CP_b06FwRodata;
3152 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
3153 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3154 bce_start_cpu(sc, &cpu_reg);
3158 /****************************************************************************/
3159 /* Initialize the COM CPU. */
3163 /****************************************************************************/
3165 bce_init_com_cpu(struct bce_softc *sc)
3167 struct cpu_reg cpu_reg;
3170 cpu_reg.mode = BCE_COM_CPU_MODE;
3171 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3172 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3173 cpu_reg.state = BCE_COM_CPU_STATE;
3174 cpu_reg.state_value_clear = 0xffffff;
3175 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3176 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3177 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3178 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3179 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3180 cpu_reg.spad_base = BCE_COM_SCRATCH;
3181 cpu_reg.mips_view_base = 0x8000000;
3183 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3184 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3185 fw.ver_major = bce_COM_b09FwReleaseMajor;
3186 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3187 fw.ver_fix = bce_COM_b09FwReleaseFix;
3188 fw.start_addr = bce_COM_b09FwStartAddr;
3190 fw.text_addr = bce_COM_b09FwTextAddr;
3191 fw.text_len = bce_COM_b09FwTextLen;
3193 fw.text = bce_COM_b09FwText;
3195 fw.data_addr = bce_COM_b09FwDataAddr;
3196 fw.data_len = bce_COM_b09FwDataLen;
3198 fw.data = bce_COM_b09FwData;
3200 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3201 fw.sbss_len = bce_COM_b09FwSbssLen;
3203 fw.sbss = bce_COM_b09FwSbss;
3205 fw.bss_addr = bce_COM_b09FwBssAddr;
3206 fw.bss_len = bce_COM_b09FwBssLen;
3208 fw.bss = bce_COM_b09FwBss;
3210 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3211 fw.rodata_len = bce_COM_b09FwRodataLen;
3212 fw.rodata_index = 0;
3213 fw.rodata = bce_COM_b09FwRodata;
3215 fw.ver_major = bce_COM_b06FwReleaseMajor;
3216 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3217 fw.ver_fix = bce_COM_b06FwReleaseFix;
3218 fw.start_addr = bce_COM_b06FwStartAddr;
3220 fw.text_addr = bce_COM_b06FwTextAddr;
3221 fw.text_len = bce_COM_b06FwTextLen;
3223 fw.text = bce_COM_b06FwText;
3225 fw.data_addr = bce_COM_b06FwDataAddr;
3226 fw.data_len = bce_COM_b06FwDataLen;
3228 fw.data = bce_COM_b06FwData;
3230 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3231 fw.sbss_len = bce_COM_b06FwSbssLen;
3233 fw.sbss = bce_COM_b06FwSbss;
3235 fw.bss_addr = bce_COM_b06FwBssAddr;
3236 fw.bss_len = bce_COM_b06FwBssLen;
3238 fw.bss = bce_COM_b06FwBss;
3240 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3241 fw.rodata_len = bce_COM_b06FwRodataLen;
3242 fw.rodata_index = 0;
3243 fw.rodata = bce_COM_b06FwRodata;
3246 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3247 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3248 bce_start_cpu(sc, &cpu_reg);
3252 /****************************************************************************/
3253 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3255 /* Loads the firmware for each CPU and starts the CPU. */
3259 /****************************************************************************/
3261 bce_init_cpus(struct bce_softc *sc)
3263 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3264 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3265 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3266 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3267 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3268 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3269 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3271 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3272 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3273 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3274 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3277 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3278 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3279 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3280 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3283 bce_init_rxp_cpu(sc);
3284 bce_init_txp_cpu(sc);
3285 bce_init_tpat_cpu(sc);
3286 bce_init_com_cpu(sc);
3287 bce_init_cp_cpu(sc);
3291 /****************************************************************************/
3292 /* Initialize context memory. */
3294 /* Clears the memory associated with each Context ID (CID). */
3298 /****************************************************************************/
3300 bce_init_ctx(struct bce_softc *sc)
3302 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3303 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3304 /* DRC: Replace this constant value with a #define. */
3305 int i, retry_cnt = 10;
3309 * BCM5709 context memory may be cached
3310 * in host memory so prepare the host memory
3313 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3315 val |= (BCM_PAGE_BITS - 8) << 16;
3316 REG_WR(sc, BCE_CTX_COMMAND, val);
3318 /* Wait for mem init command to complete. */
3319 for (i = 0; i < retry_cnt; i++) {
3320 val = REG_RD(sc, BCE_CTX_COMMAND);
3321 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3325 if (i == retry_cnt) {
3326 device_printf(sc->bce_dev,
3327 "Context memory initialization failed!\n");
3331 for (i = 0; i < sc->ctx_pages; i++) {
3335 * Set the physical address of the context
3338 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3339 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3340 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3341 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3342 BCE_ADDR_HI(sc->ctx_paddr[i]));
3343 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3344 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3347 * Verify that the context memory write was successful.
3349 for (j = 0; j < retry_cnt; j++) {
3350 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3352 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3356 if (j == retry_cnt) {
3357 device_printf(sc->bce_dev,
3358 "Failed to initialize context page!\n");
3363 uint32_t vcid_addr, offset;
3366 * For the 5706/5708, context memory is local to
3367 * the controller, so initialize the controller
3371 vcid_addr = GET_CID_ADDR(96);
3373 vcid_addr -= PHY_CTX_SIZE;
3375 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3376 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3378 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3379 CTX_WR(sc, 0x00, offset, 0);
3381 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3382 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3389 /****************************************************************************/
3390 /* Fetch the permanent MAC address of the controller. */
3394 /****************************************************************************/
3396 bce_get_mac_addr(struct bce_softc *sc)
3398 uint32_t mac_lo = 0, mac_hi = 0;
3401 * The NetXtreme II bootcode populates various NIC
3402 * power-on and runtime configuration items in a
3403 * shared memory area. The factory configured MAC
3404 * address is available from both NVRAM and the
3405 * shared memory area so we'll read the value from
3406 * shared memory for speed.
3409 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3410 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3412 if (mac_lo == 0 && mac_hi == 0) {
3413 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3415 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3416 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3417 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3418 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3419 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3420 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3423 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3427 /****************************************************************************/
3428 /* Program the MAC address. */
3432 /****************************************************************************/
3434 bce_set_mac_addr(struct bce_softc *sc)
3436 const uint8_t *mac_addr = sc->eaddr;
3439 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3442 val = (mac_addr[0] << 8) | mac_addr[1];
3443 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3445 val = (mac_addr[2] << 24) |
3446 (mac_addr[3] << 16) |
3447 (mac_addr[4] << 8) |
3449 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3453 /****************************************************************************/
3454 /* Stop the controller. */
3458 /****************************************************************************/
3460 bce_stop(struct bce_softc *sc)
3462 struct ifnet *ifp = &sc->arpcom.ac_if;
3464 ASSERT_SERIALIZED(ifp->if_serializer);
3466 callout_stop(&sc->bce_tick_callout);
3468 /* Disable the transmit/receive blocks. */
3469 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3470 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3473 bce_disable_intr(sc);
3475 /* Free the RX lists. */
3476 bce_free_rx_chain(sc);
3478 /* Free TX buffers. */
3479 bce_free_tx_chain(sc);
3482 sc->bce_coalchg_mask = 0;
3484 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3490 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3495 /* Wait for pending PCI transactions to complete. */
3496 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3497 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3498 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3499 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3500 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3501 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3505 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3506 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3507 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3508 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3509 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3512 /* Assume bootcode is running. */
3513 sc->bce_fw_timed_out = 0;
3514 sc->bce_drv_cardiac_arrest = 0;
3516 /* Give the firmware a chance to prepare for the reset. */
3517 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3519 if_printf(&sc->arpcom.ac_if,
3520 "Firmware is not ready for reset\n");
3524 /* Set a firmware reminder that this is a soft reset. */
3525 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3526 BCE_DRV_RESET_SIGNATURE_MAGIC);
3528 /* Dummy read to force the chip to complete all current transactions. */
3529 val = REG_RD(sc, BCE_MISC_ID);
3532 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3533 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3534 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3535 REG_RD(sc, BCE_MISC_COMMAND);
3538 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3539 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3541 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3543 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3544 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3545 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3546 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3548 /* Allow up to 30us for reset to complete. */
3549 for (i = 0; i < 10; i++) {
3550 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3551 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3552 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3557 /* Check that reset completed successfully. */
3558 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3559 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3560 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3565 /* Make sure byte swapping is properly configured. */
3566 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3567 if (val != 0x01020304) {
3568 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3572 /* Just completed a reset, assume that firmware is running again. */
3573 sc->bce_fw_timed_out = 0;
3574 sc->bce_drv_cardiac_arrest = 0;
3576 /* Wait for the firmware to finish its initialization. */
3577 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3579 if_printf(&sc->arpcom.ac_if,
3580 "Firmware did not complete initialization!\n");
3587 bce_chipinit(struct bce_softc *sc)
3592 /* Make sure the interrupt is not active. */
3593 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3594 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3597 * Initialize DMA byte/word swapping, configure the number of DMA
3598 * channels and PCI clock compensation delay.
3600 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3601 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3602 #if BYTE_ORDER == BIG_ENDIAN
3603 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3605 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3606 DMA_READ_CHANS << 12 |
3607 DMA_WRITE_CHANS << 16;
3609 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3611 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3612 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3615 * This setting resolves a problem observed on certain Intel PCI
3616 * chipsets that cannot handle multiple outstanding DMA operations.
3617 * See errata E9_5706A1_65.
3619 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3620 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3621 !(sc->bce_flags & BCE_PCIX_FLAG))
3622 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3624 REG_WR(sc, BCE_DMA_CONFIG, val);
3626 /* Enable the RX_V2P and Context state machines before access. */
3627 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3628 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3629 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3630 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3632 /* Initialize context mapping and zero out the quick contexts. */
3633 rc = bce_init_ctx(sc);
3637 /* Initialize the on-boards CPUs */
3640 /* Enable management frames (NC-SI) to flow to the MCP. */
3641 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3642 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) |
3643 BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3644 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3647 /* Prepare NVRAM for access. */
3648 rc = bce_init_nvram(sc);
3652 /* Set the kernel bypass block size */
3653 val = REG_RD(sc, BCE_MQ_CONFIG);
3654 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3655 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3657 /* Enable bins used on the 5709/5716. */
3658 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3659 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3660 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3661 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3662 val |= BCE_MQ_CONFIG_HALT_DIS;
3665 REG_WR(sc, BCE_MQ_CONFIG, val);
3667 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3668 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3669 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3671 /* Set the page size and clear the RV2P processor stall bits. */
3672 val = (BCM_PAGE_BITS - 8) << 24;
3673 REG_WR(sc, BCE_RV2P_CONFIG, val);
3675 /* Configure page size. */
3676 val = REG_RD(sc, BCE_TBDR_CONFIG);
3677 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3678 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3679 REG_WR(sc, BCE_TBDR_CONFIG, val);
3681 /* Set the perfect match control register to default. */
3682 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3688 /****************************************************************************/
3689 /* Initialize the controller in preparation to send/receive traffic. */
3692 /* 0 for success, positive value for failure. */
3693 /****************************************************************************/
3695 bce_blockinit(struct bce_softc *sc)
3700 /* Load the hardware default MAC address. */
3701 bce_set_mac_addr(sc);
3703 /* Set the Ethernet backoff seed value */
3704 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3705 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3706 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3708 sc->last_status_idx = 0;
3709 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3711 sc->pulse_check_status_idx = 0xffff;
3713 /* Set up link change interrupt generation. */
3714 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3716 /* Program the physical address of the status block. */
3717 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3718 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3720 /* Program the physical address of the statistics block. */
3721 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3722 BCE_ADDR_LO(sc->stats_block_paddr));
3723 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3724 BCE_ADDR_HI(sc->stats_block_paddr));
3726 /* Program various host coalescing parameters. */
3727 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3728 (sc->bce_tx_quick_cons_trip_int << 16) |
3729 sc->bce_tx_quick_cons_trip);
3730 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3731 (sc->bce_rx_quick_cons_trip_int << 16) |
3732 sc->bce_rx_quick_cons_trip);
3733 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3734 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3735 REG_WR(sc, BCE_HC_TX_TICKS,
3736 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3737 REG_WR(sc, BCE_HC_RX_TICKS,
3738 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3739 REG_WR(sc, BCE_HC_COM_TICKS,
3740 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3741 REG_WR(sc, BCE_HC_CMD_TICKS,
3742 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3743 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3744 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3746 val = BCE_HC_CONFIG_TX_TMR_MODE | BCE_HC_CONFIG_COLLECT_STATS;
3747 if (sc->bce_flags & BCE_ONESHOT_MSI_FLAG) {
3749 if_printf(&sc->arpcom.ac_if, "oneshot MSI\n");
3750 val |= BCE_HC_CONFIG_ONE_SHOT | BCE_HC_CONFIG_USE_INT_PARAM;
3752 REG_WR(sc, BCE_HC_CONFIG, val);
3754 /* Clear the internal statistics counters. */
3755 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3757 /* Verify that bootcode is running. */
3758 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
3760 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3761 if_printf(&sc->arpcom.ac_if,
3762 "%s(%d): Simulating bootcode failure.\n",
3763 __FILE__, __LINE__);
3766 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3767 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3768 if_printf(&sc->arpcom.ac_if,
3769 "Bootcode not running! Found: 0x%08X, "
3770 "Expected: 08%08X\n",
3771 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3772 BCE_DEV_INFO_SIGNATURE_MAGIC);
3777 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3778 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3779 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3780 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3781 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3784 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3785 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3787 /* Enable link state change interrupt generation. */
3788 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3790 /* Enable the RXP. */
3791 bce_start_rxp_cpu(sc);
3793 /* Disable management frames (NC-SI) from flowing to the MCP. */
3794 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3795 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
3796 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3797 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3800 /* Enable all remaining blocks in the MAC. */
3801 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3802 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3803 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3804 BCE_MISC_ENABLE_DEFAULT_XI);
3806 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
3808 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3811 /* Save the current host coalescing block settings. */
3812 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
3818 /****************************************************************************/
3819 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3821 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3822 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3826 /* 0 for success, positive value for failure. */
3827 /****************************************************************************/
3829 bce_newbuf_std(struct bce_softc *sc, uint16_t *prod, uint16_t *chain_prod,
3830 uint32_t *prod_bseq, int init)
3833 bus_dma_segment_t seg;
3837 uint16_t debug_chain_prod = *chain_prod;
3840 /* Make sure the inputs are valid. */
3841 DBRUNIF((*chain_prod > MAX_RX_BD(sc)),
3842 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3843 "RX producer out of range: 0x%04X > 0x%04X\n",
3845 *chain_prod, (uint16_t)MAX_RX_BD(sc)));
3847 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3848 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3850 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3851 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3852 "Simulating mbuf allocation failure.\n",
3853 __FILE__, __LINE__);
3854 sc->mbuf_alloc_failed++;
3857 /* This is a new mbuf allocation. */
3858 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
3861 DBRUNIF(1, sc->rx_mbuf_alloc++);
3863 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3865 /* Map the mbuf cluster into device memory. */
3866 error = bus_dmamap_load_mbuf_segment(sc->rx_mbuf_tag,
3867 sc->rx_mbuf_tmpmap, m_new, &seg, 1, &nseg,
3872 if_printf(&sc->arpcom.ac_if,
3873 "Error mapping mbuf into RX chain!\n");
3875 DBRUNIF(1, sc->rx_mbuf_alloc--);
3879 if (sc->rx_mbuf_ptr[*chain_prod] != NULL) {
3880 bus_dmamap_unload(sc->rx_mbuf_tag,
3881 sc->rx_mbuf_map[*chain_prod]);
3884 map = sc->rx_mbuf_map[*chain_prod];
3885 sc->rx_mbuf_map[*chain_prod] = sc->rx_mbuf_tmpmap;
3886 sc->rx_mbuf_tmpmap = map;
3888 /* Watch for overflow. */
3889 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD(sc)),
3890 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3891 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3892 __FILE__, __LINE__, sc->free_rx_bd,
3893 (uint16_t)USABLE_RX_BD(sc)));
3895 /* Update some debug statistic counters */
3896 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3897 sc->rx_low_watermark = sc->free_rx_bd);
3898 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3900 /* Save the mbuf and update our counter. */
3901 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3902 sc->rx_mbuf_paddr[*chain_prod] = seg.ds_addr;
3905 bce_setup_rxdesc_std(sc, *chain_prod, prod_bseq);
3907 DBRUN(BCE_VERBOSE_RECV,
3908 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3910 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3911 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3918 bce_setup_rxdesc_std(struct bce_softc *sc, uint16_t chain_prod, uint32_t *prod_bseq)
3924 paddr = sc->rx_mbuf_paddr[chain_prod];
3925 len = sc->rx_mbuf_ptr[chain_prod]->m_len;
3927 /* Setup the rx_bd for the first segment. */
3928 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
3930 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(paddr));
3931 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(paddr));
3932 rxbd->rx_bd_len = htole32(len);
3933 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3936 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3940 /****************************************************************************/
3941 /* Initialize the TX context memory. */
3945 /****************************************************************************/
3947 bce_init_tx_context(struct bce_softc *sc)
3951 /* Initialize the context ID for an L2 TX chain. */
3952 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3953 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3954 /* Set the CID type to support an L2 connection. */
3955 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3956 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
3957 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3958 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE_XI, val);
3960 /* Point the hardware to the first page in the chain. */
3961 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3962 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3963 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
3964 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3965 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3966 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
3968 /* Set the CID type to support an L2 connection. */
3969 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3970 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
3971 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3972 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
3974 /* Point the hardware to the first page in the chain. */
3975 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3976 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3977 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
3978 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3979 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3980 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
3985 /****************************************************************************/
3986 /* Allocate memory and initialize the TX data structures. */
3989 /* 0 for success, positive value for failure. */
3990 /****************************************************************************/
3992 bce_init_tx_chain(struct bce_softc *sc)
3997 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3999 /* Set the initial TX producer/consumer indices. */
4002 sc->tx_prod_bseq = 0;
4004 sc->max_tx_bd = USABLE_TX_BD(sc);
4005 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD(sc));
4006 DBRUNIF(1, sc->tx_full_count = 0);
4009 * The NetXtreme II supports a linked-list structre called
4010 * a Buffer Descriptor Chain (or BD chain). A BD chain
4011 * consists of a series of 1 or more chain pages, each of which
4012 * consists of a fixed number of BD entries.
4013 * The last BD entry on each page is a pointer to the next page
4014 * in the chain, and the last pointer in the BD chain
4015 * points back to the beginning of the chain.
4018 /* Set the TX next pointer chain entries. */
4019 for (i = 0; i < sc->tx_pages; i++) {
4022 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
4024 /* Check if we've reached the last page. */
4025 if (i == (sc->tx_pages - 1))
4030 txbd->tx_bd_haddr_hi =
4031 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
4032 txbd->tx_bd_haddr_lo =
4033 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
4035 bce_init_tx_context(sc);
4041 /****************************************************************************/
4042 /* Free memory and clear the TX data structures. */
4046 /****************************************************************************/
4048 bce_free_tx_chain(struct bce_softc *sc)
4052 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4054 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
4055 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
4056 if (sc->tx_mbuf_ptr[i] != NULL) {
4057 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
4058 m_freem(sc->tx_mbuf_ptr[i]);
4059 sc->tx_mbuf_ptr[i] = NULL;
4060 DBRUNIF(1, sc->tx_mbuf_alloc--);
4064 /* Clear each TX chain page. */
4065 for (i = 0; i < sc->tx_pages; i++)
4066 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
4069 /* Check if we lost any mbufs in the process. */
4070 DBRUNIF((sc->tx_mbuf_alloc),
4071 if_printf(&sc->arpcom.ac_if,
4072 "%s(%d): Memory leak! "
4073 "Lost %d mbufs from tx chain!\n",
4074 __FILE__, __LINE__, sc->tx_mbuf_alloc));
4076 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4080 /****************************************************************************/
4081 /* Initialize the RX context memory. */
4085 /****************************************************************************/
4087 bce_init_rx_context(struct bce_softc *sc)
4091 /* Initialize the context ID for an L2 RX chain. */
4092 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
4093 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
4096 * Set the level for generating pause frames
4097 * when the number of available rx_bd's gets
4098 * too low (the low watermark) and the level
4099 * when pause frames can be stopped (the high
4102 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4103 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4104 uint32_t lo_water, hi_water;
4106 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
4107 hi_water = USABLE_RX_BD(sc) / 4;
4109 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
4110 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
4114 else if (hi_water == 0)
4117 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
4120 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
4122 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
4123 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4124 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4125 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
4126 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
4129 /* Point the hardware to the first page in the chain. */
4130 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
4131 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
4132 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
4133 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
4137 /****************************************************************************/
4138 /* Allocate memory and initialize the RX data structures. */
4141 /* 0 for success, positive value for failure. */
4142 /****************************************************************************/
4144 bce_init_rx_chain(struct bce_softc *sc)
4148 uint16_t prod, chain_prod;
4151 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4153 /* Initialize the RX producer and consumer indices. */
4156 sc->rx_prod_bseq = 0;
4157 sc->free_rx_bd = USABLE_RX_BD(sc);
4158 sc->max_rx_bd = USABLE_RX_BD(sc);
4159 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD(sc));
4160 DBRUNIF(1, sc->rx_empty_count = 0);
4162 /* Initialize the RX next pointer chain entries. */
4163 for (i = 0; i < sc->rx_pages; i++) {
4166 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
4168 /* Check if we've reached the last page. */
4169 if (i == (sc->rx_pages - 1))
4174 /* Setup the chain page pointers. */
4175 rxbd->rx_bd_haddr_hi =
4176 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
4177 rxbd->rx_bd_haddr_lo =
4178 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
4181 /* Allocate mbuf clusters for the rx_bd chain. */
4182 prod = prod_bseq = 0;
4183 while (prod < TOTAL_RX_BD(sc)) {
4184 chain_prod = RX_CHAIN_IDX(sc, prod);
4185 if (bce_newbuf_std(sc, &prod, &chain_prod, &prod_bseq, 1)) {
4186 if_printf(&sc->arpcom.ac_if,
4187 "Error filling RX chain: rx_bd[0x%04X]!\n",
4192 prod = NEXT_RX_BD(prod);
4195 /* Save the RX chain producer index. */
4197 sc->rx_prod_bseq = prod_bseq;
4199 /* Tell the chip about the waiting rx_bd's. */
4200 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4202 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4205 bce_init_rx_context(sc);
4211 /****************************************************************************/
4212 /* Free memory and clear the RX data structures. */
4216 /****************************************************************************/
4218 bce_free_rx_chain(struct bce_softc *sc)
4222 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4224 /* Free any mbufs still in the RX mbuf chain. */
4225 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
4226 if (sc->rx_mbuf_ptr[i] != NULL) {
4227 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
4228 m_freem(sc->rx_mbuf_ptr[i]);
4229 sc->rx_mbuf_ptr[i] = NULL;
4230 DBRUNIF(1, sc->rx_mbuf_alloc--);
4234 /* Clear each RX chain page. */
4235 for (i = 0; i < sc->rx_pages; i++)
4236 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
4238 /* Check if we lost any mbufs in the process. */
4239 DBRUNIF((sc->rx_mbuf_alloc),
4240 if_printf(&sc->arpcom.ac_if,
4241 "%s(%d): Memory leak! "
4242 "Lost %d mbufs from rx chain!\n",
4243 __FILE__, __LINE__, sc->rx_mbuf_alloc));
4245 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4249 /****************************************************************************/
4250 /* Set media options. */
4253 /* 0 for success, positive value for failure. */
4254 /****************************************************************************/
4256 bce_ifmedia_upd(struct ifnet *ifp)
4258 struct bce_softc *sc = ifp->if_softc;
4259 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4263 * 'mii' will be NULL, when this function is called on following
4264 * code path: bce_attach() -> bce_mgmt_init()
4267 /* Make sure the MII bus has been enumerated. */
4269 if (mii->mii_instance) {
4270 struct mii_softc *miisc;
4272 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
4273 mii_phy_reset(miisc);
4275 error = mii_mediachg(mii);
4281 /****************************************************************************/
4282 /* Reports current media status. */
4286 /****************************************************************************/
4288 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
4290 struct bce_softc *sc = ifp->if_softc;
4291 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4294 ifmr->ifm_active = mii->mii_media_active;
4295 ifmr->ifm_status = mii->mii_media_status;
4299 /****************************************************************************/
4300 /* Handles PHY generated interrupt events. */
4304 /****************************************************************************/
4306 bce_phy_intr(struct bce_softc *sc)
4308 uint32_t new_link_state, old_link_state;
4309 struct ifnet *ifp = &sc->arpcom.ac_if;
4311 ASSERT_SERIALIZED(ifp->if_serializer);
4313 new_link_state = sc->status_block->status_attn_bits &
4314 STATUS_ATTN_BITS_LINK_STATE;
4315 old_link_state = sc->status_block->status_attn_bits_ack &
4316 STATUS_ATTN_BITS_LINK_STATE;
4318 /* Handle any changes if the link state has changed. */
4319 if (new_link_state != old_link_state) { /* XXX redundant? */
4320 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4322 /* Update the status_attn_bits_ack field in the status block. */
4323 if (new_link_state) {
4324 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4325 STATUS_ATTN_BITS_LINK_STATE);
4327 if_printf(ifp, "Link is now UP.\n");
4329 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4330 STATUS_ATTN_BITS_LINK_STATE);
4332 if_printf(ifp, "Link is now DOWN.\n");
4336 * Assume link is down and allow tick routine to
4337 * update the state based on the actual media state.
4340 callout_stop(&sc->bce_tick_callout);
4341 bce_tick_serialized(sc);
4344 /* Acknowledge the link change interrupt. */
4345 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4349 /****************************************************************************/
4350 /* Reads the receive consumer value from the status block (skipping over */
4351 /* chain page pointer if necessary). */
4355 /****************************************************************************/
4356 static __inline uint16_t
4357 bce_get_hw_rx_cons(struct bce_softc *sc)
4359 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
4361 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4367 /****************************************************************************/
4368 /* Handles received frame interrupt events. */
4372 /****************************************************************************/
4374 bce_rx_intr(struct bce_softc *sc, int count, uint16_t hw_cons)
4376 struct ifnet *ifp = &sc->arpcom.ac_if;
4377 uint16_t sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4378 uint32_t sw_prod_bseq;
4380 ASSERT_SERIALIZED(ifp->if_serializer);
4382 /* Get working copies of the driver's view of the RX indices. */
4383 sw_cons = sc->rx_cons;
4384 sw_prod = sc->rx_prod;
4385 sw_prod_bseq = sc->rx_prod_bseq;
4387 /* Scan through the receive chain as long as there is work to do. */
4388 while (sw_cons != hw_cons) {
4389 struct mbuf *m = NULL;
4390 struct l2_fhdr *l2fhdr = NULL;
4393 uint32_t status = 0;
4395 #ifdef DEVICE_POLLING
4396 if (count >= 0 && count-- == 0)
4401 * Convert the producer/consumer indices
4402 * to an actual rx_bd index.
4404 sw_chain_cons = RX_CHAIN_IDX(sc, sw_cons);
4405 sw_chain_prod = RX_CHAIN_IDX(sc, sw_prod);
4407 /* Get the used rx_bd. */
4408 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
4409 [RX_IDX(sw_chain_cons)];
4412 /* The mbuf is stored with the last rx_bd entry of a packet. */
4413 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4414 if (sw_chain_cons != sw_chain_prod) {
4415 if_printf(ifp, "RX cons(%d) != prod(%d), "
4416 "drop!\n", sw_chain_cons,
4420 bce_setup_rxdesc_std(sc, sw_chain_cons,
4423 goto bce_rx_int_next_rx;
4426 /* Unmap the mbuf from DMA space. */
4427 bus_dmamap_sync(sc->rx_mbuf_tag,
4428 sc->rx_mbuf_map[sw_chain_cons],
4429 BUS_DMASYNC_POSTREAD);
4431 /* Save the mbuf from the driver's chain. */
4432 m = sc->rx_mbuf_ptr[sw_chain_cons];
4435 * Frames received on the NetXteme II are prepended
4436 * with an l2_fhdr structure which provides status
4437 * information about the received frame (including
4438 * VLAN tags and checksum info). The frames are also
4439 * automatically adjusted to align the IP header
4440 * (i.e. two null bytes are inserted before the
4441 * Ethernet header). As a result the data DMA'd by
4442 * the controller into the mbuf is as follows:
4444 * +---------+-----+---------------------+-----+
4445 * | l2_fhdr | pad | packet data | FCS |
4446 * +---------+-----+---------------------+-----+
4448 * The l2_fhdr needs to be checked and skipped and the
4449 * FCS needs to be stripped before sending the packet
4452 l2fhdr = mtod(m, struct l2_fhdr *);
4454 len = l2fhdr->l2_fhdr_pkt_len;
4455 status = l2fhdr->l2_fhdr_status;
4457 len -= ETHER_CRC_LEN;
4459 /* Check the received frame for errors. */
4460 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4461 L2_FHDR_ERRORS_PHY_DECODE |
4462 L2_FHDR_ERRORS_ALIGNMENT |
4463 L2_FHDR_ERRORS_TOO_SHORT |
4464 L2_FHDR_ERRORS_GIANT_FRAME)) {
4467 /* Reuse the mbuf for a new frame. */
4468 bce_setup_rxdesc_std(sc, sw_chain_prod,
4471 goto bce_rx_int_next_rx;
4475 * Get a new mbuf for the rx_bd. If no new
4476 * mbufs are available then reuse the current mbuf,
4477 * log an ierror on the interface, and generate
4478 * an error in the system log.
4480 if (bce_newbuf_std(sc, &sw_prod, &sw_chain_prod,
4481 &sw_prod_bseq, 0)) {
4484 /* Try and reuse the exisitng mbuf. */
4485 bce_setup_rxdesc_std(sc, sw_chain_prod,
4488 goto bce_rx_int_next_rx;
4492 * Skip over the l2_fhdr when passing
4493 * the data up the stack.
4495 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4497 m->m_pkthdr.len = m->m_len = len;
4498 m->m_pkthdr.rcvif = ifp;
4500 /* Validate the checksum if offload enabled. */
4501 if (ifp->if_capenable & IFCAP_RXCSUM) {
4502 /* Check for an IP datagram. */
4503 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4504 m->m_pkthdr.csum_flags |=
4507 /* Check if the IP checksum is valid. */
4508 if ((l2fhdr->l2_fhdr_ip_xsum ^
4510 m->m_pkthdr.csum_flags |=
4515 /* Check for a valid TCP/UDP frame. */
4516 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4517 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4519 /* Check for a good TCP/UDP checksum. */
4521 (L2_FHDR_ERRORS_TCP_XSUM |
4522 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4523 m->m_pkthdr.csum_data =
4524 l2fhdr->l2_fhdr_tcp_udp_xsum;
4525 m->m_pkthdr.csum_flags |=
4534 sw_prod = NEXT_RX_BD(sw_prod);
4537 sw_cons = NEXT_RX_BD(sw_cons);
4539 /* If we have a packet, pass it up the stack */
4541 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4542 m->m_flags |= M_VLANTAG;
4543 m->m_pkthdr.ether_vlantag =
4544 l2fhdr->l2_fhdr_vlan_tag;
4546 ifp->if_input(ifp, m);
4550 sc->rx_cons = sw_cons;
4551 sc->rx_prod = sw_prod;
4552 sc->rx_prod_bseq = sw_prod_bseq;
4554 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4556 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4561 /****************************************************************************/
4562 /* Reads the transmit consumer value from the status block (skipping over */
4563 /* chain page pointer if necessary). */
4567 /****************************************************************************/
4568 static __inline uint16_t
4569 bce_get_hw_tx_cons(struct bce_softc *sc)
4571 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4573 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4579 /****************************************************************************/
4580 /* Handles transmit completion interrupt events. */
4584 /****************************************************************************/
4586 bce_tx_intr(struct bce_softc *sc, uint16_t hw_tx_cons)
4588 struct ifnet *ifp = &sc->arpcom.ac_if;
4589 uint16_t sw_tx_cons, sw_tx_chain_cons;
4591 ASSERT_SERIALIZED(ifp->if_serializer);
4593 /* Get the hardware's view of the TX consumer index. */
4594 sw_tx_cons = sc->tx_cons;
4596 /* Cycle through any completed TX chain page entries. */
4597 while (sw_tx_cons != hw_tx_cons) {
4598 sw_tx_chain_cons = TX_CHAIN_IDX(sc, sw_tx_cons);
4601 * Free the associated mbuf. Remember
4602 * that only the last tx_bd of a packet
4603 * has an mbuf pointer and DMA map.
4605 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4606 /* Unmap the mbuf. */
4607 bus_dmamap_unload(sc->tx_mbuf_tag,
4608 sc->tx_mbuf_map[sw_tx_chain_cons]);
4610 /* Free the mbuf. */
4611 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4612 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4618 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4621 if (sc->used_tx_bd == 0) {
4622 /* Clear the TX timeout timer. */
4626 /* Clear the tx hardware queue full flag. */
4627 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE)
4628 ifp->if_flags &= ~IFF_OACTIVE;
4629 sc->tx_cons = sw_tx_cons;
4633 /****************************************************************************/
4634 /* Disables interrupt generation. */
4638 /****************************************************************************/
4640 bce_disable_intr(struct bce_softc *sc)
4642 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4643 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4644 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4648 /****************************************************************************/
4649 /* Enables interrupt generation. */
4653 /****************************************************************************/
4655 bce_enable_intr(struct bce_softc *sc)
4657 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4659 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4660 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4661 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4662 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4663 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4665 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
4669 /****************************************************************************/
4670 /* Reenables interrupt generation during interrupt handling. */
4674 /****************************************************************************/
4676 bce_reenable_intr(struct bce_softc *sc)
4678 if (sc->bce_irq_type == PCI_INTR_TYPE_LEGACY) {
4679 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4680 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4681 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4683 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4684 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4687 /****************************************************************************/
4688 /* Handles controller initialization. */
4692 /****************************************************************************/
4696 struct bce_softc *sc = xsc;
4697 struct ifnet *ifp = &sc->arpcom.ac_if;
4701 ASSERT_SERIALIZED(ifp->if_serializer);
4703 /* Check if the driver is still running and bail out if it is. */
4704 if (ifp->if_flags & IFF_RUNNING)
4709 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4711 if_printf(ifp, "Controller reset failed!\n");
4715 error = bce_chipinit(sc);
4717 if_printf(ifp, "Controller initialization failed!\n");
4721 error = bce_blockinit(sc);
4723 if_printf(ifp, "Block initialization failed!\n");
4727 /* Load our MAC address. */
4728 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4729 bce_set_mac_addr(sc);
4731 /* Calculate and program the Ethernet MTU size. */
4732 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4734 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4737 * Program the mtu, enabling jumbo frame
4738 * support if necessary. Also set the mbuf
4739 * allocation count for RX frames.
4741 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4743 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4744 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4745 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4746 sc->mbuf_alloc_size = MJUM9BYTES;
4748 panic("jumbo buffer is not supported yet");
4751 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4752 sc->mbuf_alloc_size = MCLBYTES;
4755 /* Calculate the RX Ethernet frame size for rx_bd's. */
4756 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4758 DBPRINT(sc, BCE_INFO,
4759 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4760 "max_frame_size = %d\n",
4761 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4762 sc->max_frame_size);
4764 /* Program appropriate promiscuous/multicast filtering. */
4765 bce_set_rx_mode(sc);
4767 /* Init RX buffer descriptor chain. */
4768 bce_init_rx_chain(sc); /* XXX return value */
4770 /* Init TX buffer descriptor chain. */
4771 bce_init_tx_chain(sc); /* XXX return value */
4773 #ifdef DEVICE_POLLING
4774 /* Disable interrupts if we are polling. */
4775 if (ifp->if_flags & IFF_POLLING) {
4776 bce_disable_intr(sc);
4778 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4779 (1 << 16) | sc->bce_rx_quick_cons_trip);
4780 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4781 (1 << 16) | sc->bce_tx_quick_cons_trip);
4784 /* Enable host interrupts. */
4785 bce_enable_intr(sc);
4787 bce_ifmedia_upd(ifp);
4789 ifp->if_flags |= IFF_RUNNING;
4790 ifp->if_flags &= ~IFF_OACTIVE;
4792 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
4799 /****************************************************************************/
4800 /* Initialize the controller just enough so that any management firmware */
4801 /* running on the device will continue to operate corectly. */
4805 /****************************************************************************/
4807 bce_mgmt_init(struct bce_softc *sc)
4809 struct ifnet *ifp = &sc->arpcom.ac_if;
4811 /* Bail out if management firmware is not running. */
4812 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4815 /* Enable all critical blocks in the MAC. */
4816 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4817 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4818 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4819 BCE_MISC_ENABLE_DEFAULT_XI);
4821 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
4823 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4826 bce_ifmedia_upd(ifp);
4830 /****************************************************************************/
4831 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4832 /* memory visible to the controller. */
4835 /* 0 for success, positive value for failure. */
4836 /****************************************************************************/
4838 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4840 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4841 bus_dmamap_t map, tmp_map;
4842 struct mbuf *m0 = *m_head;
4843 struct tx_bd *txbd = NULL;
4844 uint16_t vlan_tag = 0, flags = 0, mss = 0;
4845 uint16_t chain_prod, chain_prod_start, prod;
4847 int i, error, maxsegs, nsegs;
4849 /* Transfer any checksum offload flags to the bd. */
4850 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
4851 error = bce_tso_setup(sc, m_head, &flags, &mss);
4855 } else if (m0->m_pkthdr.csum_flags & BCE_CSUM_FEATURES) {
4856 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4857 flags |= TX_BD_FLAGS_IP_CKSUM;
4858 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4859 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4862 /* Transfer any VLAN tags to the bd. */
4863 if (m0->m_flags & M_VLANTAG) {
4864 flags |= TX_BD_FLAGS_VLAN_TAG;
4865 vlan_tag = m0->m_pkthdr.ether_vlantag;
4869 chain_prod_start = chain_prod = TX_CHAIN_IDX(sc, prod);
4871 /* Map the mbuf into DMAable memory. */
4872 map = sc->tx_mbuf_map[chain_prod_start];
4874 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4875 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4876 ("not enough segments %d", maxsegs));
4877 if (maxsegs > BCE_MAX_SEGMENTS)
4878 maxsegs = BCE_MAX_SEGMENTS;
4880 /* Map the mbuf into our DMA address space. */
4881 error = bus_dmamap_load_mbuf_defrag(sc->tx_mbuf_tag, map, m_head,
4882 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
4885 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4890 /* prod points to an empty tx_bd at this point. */
4891 prod_bseq = sc->tx_prod_bseq;
4894 * Cycle through each mbuf segment that makes up
4895 * the outgoing frame, gathering the mapping info
4896 * for that segment and creating a tx_bd to for
4899 for (i = 0; i < nsegs; i++) {
4900 chain_prod = TX_CHAIN_IDX(sc, prod);
4901 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4903 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4904 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4905 txbd->tx_bd_mss_nbytes = htole32(mss << 16) |
4906 htole16(segs[i].ds_len);
4907 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4908 txbd->tx_bd_flags = htole16(flags);
4910 prod_bseq += segs[i].ds_len;
4912 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4913 prod = NEXT_TX_BD(prod);
4916 /* Set the END flag on the last TX buffer descriptor. */
4917 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4920 * Ensure that the mbuf pointer for this transmission
4921 * is placed at the array index of the last
4922 * descriptor in this chain. This is done
4923 * because a single map is used for all
4924 * segments of the mbuf and we don't want to
4925 * unload the map before all of the segments
4928 sc->tx_mbuf_ptr[chain_prod] = m0;
4930 tmp_map = sc->tx_mbuf_map[chain_prod];
4931 sc->tx_mbuf_map[chain_prod] = map;
4932 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4934 sc->used_tx_bd += nsegs;
4936 /* prod points to the next free tx_bd at this point. */
4938 sc->tx_prod_bseq = prod_bseq;
4948 /****************************************************************************/
4949 /* Main transmit routine when called from another routine with a lock. */
4953 /****************************************************************************/
4955 bce_start(struct ifnet *ifp)
4957 struct bce_softc *sc = ifp->if_softc;
4960 ASSERT_SERIALIZED(ifp->if_serializer);
4962 /* If there's no link or the transmit queue is empty then just exit. */
4963 if (!sc->bce_link) {
4964 ifq_purge(&ifp->if_snd);
4968 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
4972 struct mbuf *m_head;
4975 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
4978 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
4979 ifp->if_flags |= IFF_OACTIVE;
4983 /* Check for any frames to send. */
4984 m_head = ifq_dequeue(&ifp->if_snd, NULL);
4989 * Pack the data into the transmit ring. If we
4990 * don't have room, place the mbuf back at the
4991 * head of the queue and set the OACTIVE flag
4992 * to wait for the NIC to drain the chain.
4994 if (bce_encap(sc, &m_head)) {
4996 if (sc->used_tx_bd == 0) {
4999 ifp->if_flags |= IFF_OACTIVE;
5006 /* Send a copy of the frame to any BPF listeners. */
5007 ETHER_BPF_MTAP(ifp, m_head);
5011 /* no packets were dequeued */
5015 REG_WR(sc, BCE_MQ_COMMAND,
5016 REG_RD(sc, BCE_MQ_COMMAND) | BCE_MQ_COMMAND_NO_MAP_ERROR);
5018 /* Start the transmit. */
5019 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BIDX,
5021 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BSEQ,
5024 /* Set the tx timeout. */
5025 ifp->if_timer = BCE_TX_TIMEOUT;
5029 /****************************************************************************/
5030 /* Handles any IOCTL calls from the operating system. */
5033 /* 0 for success, positive value for failure. */
5034 /****************************************************************************/
5036 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
5038 struct bce_softc *sc = ifp->if_softc;
5039 struct ifreq *ifr = (struct ifreq *)data;
5040 struct mii_data *mii;
5041 int mask, error = 0;
5043 ASSERT_SERIALIZED(ifp->if_serializer);
5047 /* Check that the MTU setting is supported. */
5048 if (ifr->ifr_mtu < BCE_MIN_MTU ||
5050 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
5052 ifr->ifr_mtu > ETHERMTU
5059 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
5061 ifp->if_mtu = ifr->ifr_mtu;
5062 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5067 if (ifp->if_flags & IFF_UP) {
5068 if (ifp->if_flags & IFF_RUNNING) {
5069 mask = ifp->if_flags ^ sc->bce_if_flags;
5071 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
5072 bce_set_rx_mode(sc);
5076 } else if (ifp->if_flags & IFF_RUNNING) {
5079 /* If MFW is running, restart the controller a bit. */
5080 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5081 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
5086 sc->bce_if_flags = ifp->if_flags;
5091 if (ifp->if_flags & IFF_RUNNING)
5092 bce_set_rx_mode(sc);
5097 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
5099 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
5101 mii = device_get_softc(sc->bce_miibus);
5102 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
5106 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
5107 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
5110 if (mask & IFCAP_HWCSUM) {
5111 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
5112 if (ifp->if_capenable & IFCAP_TXCSUM)
5113 ifp->if_hwassist |= BCE_CSUM_FEATURES;
5115 ifp->if_hwassist &= ~BCE_CSUM_FEATURES;
5117 if (mask & IFCAP_TSO) {
5118 ifp->if_capenable ^= IFCAP_TSO;
5119 if (ifp->if_capenable & IFCAP_TSO)
5120 ifp->if_hwassist |= CSUM_TSO;
5122 ifp->if_hwassist &= ~CSUM_TSO;
5127 error = ether_ioctl(ifp, command, data);
5134 /****************************************************************************/
5135 /* Transmit timeout handler. */
5139 /****************************************************************************/
5141 bce_watchdog(struct ifnet *ifp)
5143 struct bce_softc *sc = ifp->if_softc;
5145 ASSERT_SERIALIZED(ifp->if_serializer);
5147 DBRUN(BCE_VERBOSE_SEND,
5148 bce_dump_driver_state(sc);
5149 bce_dump_status_block(sc));
5152 * If we are in this routine because of pause frames, then
5153 * don't reset the hardware.
5155 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
5158 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
5160 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5162 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5167 if (!ifq_is_empty(&ifp->if_snd))
5172 #ifdef DEVICE_POLLING
5175 bce_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
5177 struct bce_softc *sc = ifp->if_softc;
5178 struct status_block *sblk = sc->status_block;
5179 uint16_t hw_tx_cons, hw_rx_cons;
5181 ASSERT_SERIALIZED(ifp->if_serializer);
5185 bce_disable_intr(sc);
5187 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5188 (1 << 16) | sc->bce_rx_quick_cons_trip);
5189 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5190 (1 << 16) | sc->bce_tx_quick_cons_trip);
5192 case POLL_DEREGISTER:
5193 bce_enable_intr(sc);
5195 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5196 (sc->bce_tx_quick_cons_trip_int << 16) |
5197 sc->bce_tx_quick_cons_trip);
5198 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5199 (sc->bce_rx_quick_cons_trip_int << 16) |
5200 sc->bce_rx_quick_cons_trip);
5207 * Save the status block index value for use when enabling
5210 sc->last_status_idx = sblk->status_idx;
5212 /* Make sure status index is extracted before rx/tx cons */
5215 if (cmd == POLL_AND_CHECK_STATUS) {
5216 uint32_t status_attn_bits;
5218 status_attn_bits = sblk->status_attn_bits;
5220 /* Was it a link change interrupt? */
5221 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5222 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5225 /* Clear any transient status updates during link state change. */
5226 REG_WR(sc, BCE_HC_COMMAND,
5227 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5228 REG_RD(sc, BCE_HC_COMMAND);
5231 * If any other attention is asserted then
5232 * the chip is toast.
5234 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5235 (sblk->status_attn_bits_ack &
5236 ~STATUS_ATTN_BITS_LINK_STATE)) {
5237 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5238 sblk->status_attn_bits);
5244 hw_rx_cons = bce_get_hw_rx_cons(sc);
5245 hw_tx_cons = bce_get_hw_tx_cons(sc);
5247 /* Check for any completed RX frames. */
5248 if (hw_rx_cons != sc->rx_cons)
5249 bce_rx_intr(sc, count, hw_rx_cons);
5251 /* Check for any completed TX frames. */
5252 if (hw_tx_cons != sc->tx_cons)
5253 bce_tx_intr(sc, hw_tx_cons);
5255 /* Check for new frames to transmit. */
5256 if (!ifq_is_empty(&ifp->if_snd))
5260 #endif /* DEVICE_POLLING */
5264 * Interrupt handler.
5266 /****************************************************************************/
5267 /* Main interrupt entry point. Verifies that the controller generated the */
5268 /* interrupt and then calls a separate routine for handle the various */
5269 /* interrupt causes (PHY, TX, RX). */
5272 /* 0 for success, positive value for failure. */
5273 /****************************************************************************/
5275 bce_intr(struct bce_softc *sc)
5277 struct ifnet *ifp = &sc->arpcom.ac_if;
5278 struct status_block *sblk;
5279 uint16_t hw_rx_cons, hw_tx_cons;
5280 uint32_t status_attn_bits;
5282 ASSERT_SERIALIZED(ifp->if_serializer);
5284 sblk = sc->status_block;
5287 * Save the status block index value for use during
5288 * the next interrupt.
5290 sc->last_status_idx = sblk->status_idx;
5292 /* Make sure status index is extracted before rx/tx cons */
5295 /* Check if the hardware has finished any work. */
5296 hw_rx_cons = bce_get_hw_rx_cons(sc);
5297 hw_tx_cons = bce_get_hw_tx_cons(sc);
5299 status_attn_bits = sblk->status_attn_bits;
5301 /* Was it a link change interrupt? */
5302 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5303 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5307 * Clear any transient status updates during link state
5310 REG_WR(sc, BCE_HC_COMMAND,
5311 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5312 REG_RD(sc, BCE_HC_COMMAND);
5316 * If any other attention is asserted then
5317 * the chip is toast.
5319 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5320 (sblk->status_attn_bits_ack & ~STATUS_ATTN_BITS_LINK_STATE)) {
5321 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5322 sblk->status_attn_bits);
5327 /* Check for any completed RX frames. */
5328 if (hw_rx_cons != sc->rx_cons)
5329 bce_rx_intr(sc, -1, hw_rx_cons);
5331 /* Check for any completed TX frames. */
5332 if (hw_tx_cons != sc->tx_cons)
5333 bce_tx_intr(sc, hw_tx_cons);
5335 /* Re-enable interrupts. */
5336 bce_reenable_intr(sc);
5338 if (sc->bce_coalchg_mask)
5339 bce_coal_change(sc);
5341 /* Handle any frames that arrived while handling the interrupt. */
5342 if (!ifq_is_empty(&ifp->if_snd))
5347 bce_intr_legacy(void *xsc)
5349 struct bce_softc *sc = xsc;
5350 struct status_block *sblk;
5352 sblk = sc->status_block;
5355 * If the hardware status block index matches the last value
5356 * read by the driver and we haven't asserted our interrupt
5357 * then there's nothing to do.
5359 if (sblk->status_idx == sc->last_status_idx &&
5360 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
5361 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5364 /* Ack the interrupt and stop others from occuring. */
5365 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5366 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5367 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5370 * Read back to deassert IRQ immediately to avoid too
5371 * many spurious interrupts.
5373 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
5379 bce_intr_msi(void *xsc)
5381 struct bce_softc *sc = xsc;
5383 /* Ack the interrupt and stop others from occuring. */
5384 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5385 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5386 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5392 bce_intr_msi_oneshot(void *xsc)
5398 /****************************************************************************/
5399 /* Programs the various packet receive modes (broadcast and multicast). */
5403 /****************************************************************************/
5405 bce_set_rx_mode(struct bce_softc *sc)
5407 struct ifnet *ifp = &sc->arpcom.ac_if;
5408 struct ifmultiaddr *ifma;
5409 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5410 uint32_t rx_mode, sort_mode;
5413 ASSERT_SERIALIZED(ifp->if_serializer);
5415 /* Initialize receive mode default settings. */
5416 rx_mode = sc->rx_mode &
5417 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5418 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5419 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5422 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5425 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5426 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5427 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5430 * Check for promiscuous, all multicast, or selected
5431 * multicast address filtering.
5433 if (ifp->if_flags & IFF_PROMISC) {
5434 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5436 /* Enable promiscuous mode. */
5437 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5438 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5439 } else if (ifp->if_flags & IFF_ALLMULTI) {
5440 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5442 /* Enable all multicast addresses. */
5443 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5444 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5447 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5449 /* Accept one or more multicast(s). */
5450 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5452 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5453 if (ifma->ifma_addr->sa_family != AF_LINK)
5456 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5457 ETHER_ADDR_LEN) & 0xFF;
5458 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5461 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5462 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5465 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5468 /* Only make changes if the recive mode has actually changed. */
5469 if (rx_mode != sc->rx_mode) {
5470 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5473 sc->rx_mode = rx_mode;
5474 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5477 /* Disable and clear the exisitng sort before enabling a new sort. */
5478 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5479 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5480 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5484 /****************************************************************************/
5485 /* Called periodically to updates statistics from the controllers */
5486 /* statistics block. */
5490 /****************************************************************************/
5492 bce_stats_update(struct bce_softc *sc)
5494 struct ifnet *ifp = &sc->arpcom.ac_if;
5495 struct statistics_block *stats = sc->stats_block;
5497 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5499 ASSERT_SERIALIZED(ifp->if_serializer);
5502 * Certain controllers don't report carrier sense errors correctly.
5503 * See errata E11_5708CA0_1165.
5505 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5506 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5508 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5512 * Update the sysctl statistics from the hardware statistics.
5514 sc->stat_IfHCInOctets =
5515 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5516 (uint64_t)stats->stat_IfHCInOctets_lo;
5518 sc->stat_IfHCInBadOctets =
5519 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5520 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5522 sc->stat_IfHCOutOctets =
5523 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5524 (uint64_t)stats->stat_IfHCOutOctets_lo;
5526 sc->stat_IfHCOutBadOctets =
5527 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5528 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5530 sc->stat_IfHCInUcastPkts =
5531 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5532 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5534 sc->stat_IfHCInMulticastPkts =
5535 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5536 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5538 sc->stat_IfHCInBroadcastPkts =
5539 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5540 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5542 sc->stat_IfHCOutUcastPkts =
5543 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5544 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5546 sc->stat_IfHCOutMulticastPkts =
5547 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5548 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5550 sc->stat_IfHCOutBroadcastPkts =
5551 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5552 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5554 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5555 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5557 sc->stat_Dot3StatsCarrierSenseErrors =
5558 stats->stat_Dot3StatsCarrierSenseErrors;
5560 sc->stat_Dot3StatsFCSErrors =
5561 stats->stat_Dot3StatsFCSErrors;
5563 sc->stat_Dot3StatsAlignmentErrors =
5564 stats->stat_Dot3StatsAlignmentErrors;
5566 sc->stat_Dot3StatsSingleCollisionFrames =
5567 stats->stat_Dot3StatsSingleCollisionFrames;
5569 sc->stat_Dot3StatsMultipleCollisionFrames =
5570 stats->stat_Dot3StatsMultipleCollisionFrames;
5572 sc->stat_Dot3StatsDeferredTransmissions =
5573 stats->stat_Dot3StatsDeferredTransmissions;
5575 sc->stat_Dot3StatsExcessiveCollisions =
5576 stats->stat_Dot3StatsExcessiveCollisions;
5578 sc->stat_Dot3StatsLateCollisions =
5579 stats->stat_Dot3StatsLateCollisions;
5581 sc->stat_EtherStatsCollisions =
5582 stats->stat_EtherStatsCollisions;
5584 sc->stat_EtherStatsFragments =
5585 stats->stat_EtherStatsFragments;
5587 sc->stat_EtherStatsJabbers =
5588 stats->stat_EtherStatsJabbers;
5590 sc->stat_EtherStatsUndersizePkts =
5591 stats->stat_EtherStatsUndersizePkts;
5593 sc->stat_EtherStatsOverrsizePkts =
5594 stats->stat_EtherStatsOverrsizePkts;
5596 sc->stat_EtherStatsPktsRx64Octets =
5597 stats->stat_EtherStatsPktsRx64Octets;
5599 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5600 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5602 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5603 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5605 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5606 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5608 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5609 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5611 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5612 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5614 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5615 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5617 sc->stat_EtherStatsPktsTx64Octets =
5618 stats->stat_EtherStatsPktsTx64Octets;
5620 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5621 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5623 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5624 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5626 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5627 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5629 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5630 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5632 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5633 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5635 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5636 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5638 sc->stat_XonPauseFramesReceived =
5639 stats->stat_XonPauseFramesReceived;
5641 sc->stat_XoffPauseFramesReceived =
5642 stats->stat_XoffPauseFramesReceived;
5644 sc->stat_OutXonSent =
5645 stats->stat_OutXonSent;
5647 sc->stat_OutXoffSent =
5648 stats->stat_OutXoffSent;
5650 sc->stat_FlowControlDone =
5651 stats->stat_FlowControlDone;
5653 sc->stat_MacControlFramesReceived =
5654 stats->stat_MacControlFramesReceived;
5656 sc->stat_XoffStateEntered =
5657 stats->stat_XoffStateEntered;
5659 sc->stat_IfInFramesL2FilterDiscards =
5660 stats->stat_IfInFramesL2FilterDiscards;
5662 sc->stat_IfInRuleCheckerDiscards =
5663 stats->stat_IfInRuleCheckerDiscards;
5665 sc->stat_IfInFTQDiscards =
5666 stats->stat_IfInFTQDiscards;
5668 sc->stat_IfInMBUFDiscards =
5669 stats->stat_IfInMBUFDiscards;
5671 sc->stat_IfInRuleCheckerP4Hit =
5672 stats->stat_IfInRuleCheckerP4Hit;
5674 sc->stat_CatchupInRuleCheckerDiscards =
5675 stats->stat_CatchupInRuleCheckerDiscards;
5677 sc->stat_CatchupInFTQDiscards =
5678 stats->stat_CatchupInFTQDiscards;
5680 sc->stat_CatchupInMBUFDiscards =
5681 stats->stat_CatchupInMBUFDiscards;
5683 sc->stat_CatchupInRuleCheckerP4Hit =
5684 stats->stat_CatchupInRuleCheckerP4Hit;
5686 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5689 * Update the interface statistics from the
5690 * hardware statistics.
5692 ifp->if_collisions = (u_long)sc->stat_EtherStatsCollisions;
5694 ifp->if_ierrors = (u_long)sc->stat_EtherStatsUndersizePkts +
5695 (u_long)sc->stat_EtherStatsOverrsizePkts +
5696 (u_long)sc->stat_IfInMBUFDiscards +
5697 (u_long)sc->stat_Dot3StatsAlignmentErrors +
5698 (u_long)sc->stat_Dot3StatsFCSErrors +
5699 (u_long)sc->stat_IfInRuleCheckerDiscards +
5700 (u_long)sc->stat_IfInFTQDiscards +
5701 (u_long)sc->com_no_buffers;
5704 (u_long)sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5705 (u_long)sc->stat_Dot3StatsExcessiveCollisions +
5706 (u_long)sc->stat_Dot3StatsLateCollisions;
5708 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5712 /****************************************************************************/
5713 /* Periodic function to notify the bootcode that the driver is still */
5718 /****************************************************************************/
5720 bce_pulse(void *xsc)
5722 struct bce_softc *sc = xsc;
5723 struct ifnet *ifp = &sc->arpcom.ac_if;
5726 lwkt_serialize_enter(ifp->if_serializer);
5728 if (ifp->if_flags & IFF_RUNNING) {
5729 if (sc->bce_irq_type == PCI_INTR_TYPE_MSI &&
5730 (sc->bce_flags & BCE_ONESHOT_MSI_FLAG) == 0)
5731 bce_pulse_check_msi(sc);
5734 /* Tell the firmware that the driver is still running. */
5735 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5736 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
5738 /* Update the bootcode condition. */
5739 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
5741 /* Report whether the bootcode still knows the driver is running. */
5742 if (!sc->bce_drv_cardiac_arrest) {
5743 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
5744 sc->bce_drv_cardiac_arrest = 1;
5745 if_printf(ifp, "Bootcode lost the driver pulse! "
5746 "(bc_state = 0x%08X)\n", sc->bc_state);
5750 * Not supported by all bootcode versions.
5751 * (v5.0.11+ and v5.2.1+) Older bootcode
5752 * will require the driver to reset the
5753 * controller to clear this condition.
5755 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
5756 sc->bce_drv_cardiac_arrest = 0;
5757 if_printf(ifp, "Bootcode found the driver pulse! "
5758 "(bc_state = 0x%08X)\n", sc->bc_state);
5762 /* Schedule the next pulse. */
5763 callout_reset(&sc->bce_pulse_callout, hz, bce_pulse, sc);
5765 lwkt_serialize_exit(ifp->if_serializer);
5769 bce_pulse_check_msi(struct bce_softc *sc)
5773 if (bce_get_hw_rx_cons(sc) != sc->rx_cons) {
5775 } else if (bce_get_hw_tx_cons(sc) != sc->tx_cons) {
5778 struct status_block *sblk = sc->status_block;
5780 if ((sblk->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5781 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5788 msi_ctrl = REG_RD(sc, BCE_PCICFG_MSI_CONTROL);
5789 if ((msi_ctrl & BCE_PCICFG_MSI_CONTROL_ENABLE) == 0)
5792 if (sc->pulse_check_status_idx == sc->last_status_idx) {
5793 if_printf(&sc->arpcom.ac_if, "missing MSI\n");
5795 REG_WR(sc, BCE_PCICFG_MSI_CONTROL,
5796 msi_ctrl & ~BCE_PCICFG_MSI_CONTROL_ENABLE);
5797 REG_WR(sc, BCE_PCICFG_MSI_CONTROL, msi_ctrl);
5802 sc->pulse_check_status_idx = sc->last_status_idx;
5805 /****************************************************************************/
5806 /* Periodic function to perform maintenance tasks. */
5810 /****************************************************************************/
5812 bce_tick_serialized(struct bce_softc *sc)
5814 struct ifnet *ifp = &sc->arpcom.ac_if;
5815 struct mii_data *mii;
5817 ASSERT_SERIALIZED(ifp->if_serializer);
5819 /* Update the statistics from the hardware statistics block. */
5820 bce_stats_update(sc);
5822 /* Schedule the next tick. */
5823 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
5825 /* If link is up already up then we're done. */
5829 mii = device_get_softc(sc->bce_miibus);
5832 /* Check if the link has come up. */
5833 if ((mii->mii_media_status & IFM_ACTIVE) &&
5834 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5836 /* Now that link is up, handle any outstanding TX traffic. */
5837 if (!ifq_is_empty(&ifp->if_snd))
5846 struct bce_softc *sc = xsc;
5847 struct ifnet *ifp = &sc->arpcom.ac_if;
5849 lwkt_serialize_enter(ifp->if_serializer);
5850 bce_tick_serialized(sc);
5851 lwkt_serialize_exit(ifp->if_serializer);
5856 /****************************************************************************/
5857 /* Allows the driver state to be dumped through the sysctl interface. */
5860 /* 0 for success, positive value for failure. */
5861 /****************************************************************************/
5863 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5867 struct bce_softc *sc;
5870 error = sysctl_handle_int(oidp, &result, 0, req);
5872 if (error || !req->newptr)
5876 sc = (struct bce_softc *)arg1;
5877 bce_dump_driver_state(sc);
5884 /****************************************************************************/
5885 /* Allows the hardware state to be dumped through the sysctl interface. */
5888 /* 0 for success, positive value for failure. */
5889 /****************************************************************************/
5891 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5895 struct bce_softc *sc;
5898 error = sysctl_handle_int(oidp, &result, 0, req);
5900 if (error || !req->newptr)
5904 sc = (struct bce_softc *)arg1;
5905 bce_dump_hw_state(sc);
5912 /****************************************************************************/
5913 /* Provides a sysctl interface to allows dumping the RX chain. */
5916 /* 0 for success, positive value for failure. */
5917 /****************************************************************************/
5919 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
5923 struct bce_softc *sc;
5926 error = sysctl_handle_int(oidp, &result, 0, req);
5928 if (error || !req->newptr)
5932 sc = (struct bce_softc *)arg1;
5933 bce_dump_rx_chain(sc, 0, USABLE_RX_BD(sc));
5940 /****************************************************************************/
5941 /* Provides a sysctl interface to allows dumping the TX chain. */
5944 /* 0 for success, positive value for failure. */
5945 /****************************************************************************/
5947 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
5951 struct bce_softc *sc;
5954 error = sysctl_handle_int(oidp, &result, 0, req);
5956 if (error || !req->newptr)
5960 sc = (struct bce_softc *)arg1;
5961 bce_dump_tx_chain(sc, 0, USABLE_TX_BD(sc));
5968 /****************************************************************************/
5969 /* Provides a sysctl interface to allow reading arbitrary registers in the */
5970 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
5973 /* 0 for success, positive value for failure. */
5974 /****************************************************************************/
5976 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
5978 struct bce_softc *sc;
5980 uint32_t val, result;
5983 error = sysctl_handle_int(oidp, &result, 0, req);
5984 if (error || (req->newptr == NULL))
5987 /* Make sure the register is accessible. */
5988 if (result < 0x8000) {
5989 sc = (struct bce_softc *)arg1;
5990 val = REG_RD(sc, result);
5991 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
5993 } else if (result < 0x0280000) {
5994 sc = (struct bce_softc *)arg1;
5995 val = REG_RD_IND(sc, result);
5996 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6003 /****************************************************************************/
6004 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
6005 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6008 /* 0 for success, positive value for failure. */
6009 /****************************************************************************/
6011 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
6013 struct bce_softc *sc;
6019 error = sysctl_handle_int(oidp, &result, 0, req);
6020 if (error || (req->newptr == NULL))
6023 /* Make sure the register is accessible. */
6024 if (result < 0x20) {
6025 sc = (struct bce_softc *)arg1;
6027 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
6028 if_printf(&sc->arpcom.ac_if,
6029 "phy 0x%02X = 0x%04X\n", result, val);
6035 /****************************************************************************/
6036 /* Provides a sysctl interface to forcing the driver to dump state and */
6037 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6040 /* 0 for success, positive value for failure. */
6041 /****************************************************************************/
6043 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
6047 struct bce_softc *sc;
6050 error = sysctl_handle_int(oidp, &result, 0, req);
6052 if (error || !req->newptr)
6056 sc = (struct bce_softc *)arg1;
6065 /****************************************************************************/
6066 /* Adds any sysctl parameters for tuning or debugging purposes. */
6069 /* 0 for success, positive value for failure. */
6070 /****************************************************************************/
6072 bce_add_sysctls(struct bce_softc *sc)
6074 struct sysctl_ctx_list *ctx;
6075 struct sysctl_oid_list *children;
6077 sysctl_ctx_init(&sc->bce_sysctl_ctx);
6078 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
6079 SYSCTL_STATIC_CHILDREN(_hw),
6081 device_get_nameunit(sc->bce_dev),
6083 if (sc->bce_sysctl_tree == NULL) {
6084 device_printf(sc->bce_dev, "can't add sysctl node\n");
6088 ctx = &sc->bce_sysctl_ctx;
6089 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
6091 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
6092 CTLTYPE_INT | CTLFLAG_RW,
6093 sc, 0, bce_sysctl_tx_bds_int, "I",
6094 "Send max coalesced BD count during interrupt");
6095 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
6096 CTLTYPE_INT | CTLFLAG_RW,
6097 sc, 0, bce_sysctl_tx_bds, "I",
6098 "Send max coalesced BD count");
6099 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
6100 CTLTYPE_INT | CTLFLAG_RW,
6101 sc, 0, bce_sysctl_tx_ticks_int, "I",
6102 "Send coalescing ticks during interrupt");
6103 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
6104 CTLTYPE_INT | CTLFLAG_RW,
6105 sc, 0, bce_sysctl_tx_ticks, "I",
6106 "Send coalescing ticks");
6108 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
6109 CTLTYPE_INT | CTLFLAG_RW,
6110 sc, 0, bce_sysctl_rx_bds_int, "I",
6111 "Receive max coalesced BD count during interrupt");
6112 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
6113 CTLTYPE_INT | CTLFLAG_RW,
6114 sc, 0, bce_sysctl_rx_bds, "I",
6115 "Receive max coalesced BD count");
6116 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
6117 CTLTYPE_INT | CTLFLAG_RW,
6118 sc, 0, bce_sysctl_rx_ticks_int, "I",
6119 "Receive coalescing ticks during interrupt");
6120 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
6121 CTLTYPE_INT | CTLFLAG_RW,
6122 sc, 0, bce_sysctl_rx_ticks, "I",
6123 "Receive coalescing ticks");
6125 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_pages",
6126 CTLFLAG_RD, &sc->rx_pages, 0, "# of RX pages");
6127 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_pages",
6128 CTLFLAG_RD, &sc->tx_pages, 0, "# of TX pages");
6131 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6133 CTLFLAG_RD, &sc->rx_low_watermark,
6134 0, "Lowest level of free rx_bd's");
6136 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6138 CTLFLAG_RD, &sc->rx_empty_count,
6139 0, "Number of times the RX chain was empty");
6141 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6143 CTLFLAG_RD, &sc->tx_hi_watermark,
6144 0, "Highest level of used tx_bd's");
6146 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6148 CTLFLAG_RD, &sc->tx_full_count,
6149 0, "Number of times the TX chain was full");
6151 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6152 "l2fhdr_status_errors",
6153 CTLFLAG_RD, &sc->l2fhdr_status_errors,
6154 0, "l2_fhdr status errors");
6156 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6157 "unexpected_attentions",
6158 CTLFLAG_RD, &sc->unexpected_attentions,
6159 0, "unexpected attentions");
6161 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6162 "lost_status_block_updates",
6163 CTLFLAG_RD, &sc->lost_status_block_updates,
6164 0, "lost status block updates");
6166 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6167 "mbuf_alloc_failed",
6168 CTLFLAG_RD, &sc->mbuf_alloc_failed,
6169 0, "mbuf cluster allocation failures");
6172 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6173 "stat_IfHCInOctets",
6174 CTLFLAG_RD, &sc->stat_IfHCInOctets,
6177 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6178 "stat_IfHCInBadOctets",
6179 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
6180 "Bad bytes received");
6182 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6183 "stat_IfHCOutOctets",
6184 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
6187 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6188 "stat_IfHCOutBadOctets",
6189 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
6192 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6193 "stat_IfHCInUcastPkts",
6194 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
6195 "Unicast packets received");
6197 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6198 "stat_IfHCInMulticastPkts",
6199 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
6200 "Multicast packets received");
6202 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6203 "stat_IfHCInBroadcastPkts",
6204 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
6205 "Broadcast packets received");
6207 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6208 "stat_IfHCOutUcastPkts",
6209 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
6210 "Unicast packets sent");
6212 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6213 "stat_IfHCOutMulticastPkts",
6214 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
6215 "Multicast packets sent");
6217 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6218 "stat_IfHCOutBroadcastPkts",
6219 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
6220 "Broadcast packets sent");
6222 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6223 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
6224 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
6225 0, "Internal MAC transmit errors");
6227 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6228 "stat_Dot3StatsCarrierSenseErrors",
6229 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
6230 0, "Carrier sense errors");
6232 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6233 "stat_Dot3StatsFCSErrors",
6234 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
6235 0, "Frame check sequence errors");
6237 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6238 "stat_Dot3StatsAlignmentErrors",
6239 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
6240 0, "Alignment errors");
6242 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6243 "stat_Dot3StatsSingleCollisionFrames",
6244 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
6245 0, "Single Collision Frames");
6247 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6248 "stat_Dot3StatsMultipleCollisionFrames",
6249 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
6250 0, "Multiple Collision Frames");
6252 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6253 "stat_Dot3StatsDeferredTransmissions",
6254 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
6255 0, "Deferred Transmissions");
6257 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6258 "stat_Dot3StatsExcessiveCollisions",
6259 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
6260 0, "Excessive Collisions");
6262 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6263 "stat_Dot3StatsLateCollisions",
6264 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
6265 0, "Late Collisions");
6267 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6268 "stat_EtherStatsCollisions",
6269 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
6272 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6273 "stat_EtherStatsFragments",
6274 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
6277 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6278 "stat_EtherStatsJabbers",
6279 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
6282 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6283 "stat_EtherStatsUndersizePkts",
6284 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
6285 0, "Undersize packets");
6287 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6288 "stat_EtherStatsOverrsizePkts",
6289 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
6290 0, "stat_EtherStatsOverrsizePkts");
6292 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6293 "stat_EtherStatsPktsRx64Octets",
6294 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
6295 0, "Bytes received in 64 byte packets");
6297 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6298 "stat_EtherStatsPktsRx65Octetsto127Octets",
6299 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
6300 0, "Bytes received in 65 to 127 byte packets");
6302 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6303 "stat_EtherStatsPktsRx128Octetsto255Octets",
6304 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
6305 0, "Bytes received in 128 to 255 byte packets");
6307 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6308 "stat_EtherStatsPktsRx256Octetsto511Octets",
6309 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
6310 0, "Bytes received in 256 to 511 byte packets");
6312 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6313 "stat_EtherStatsPktsRx512Octetsto1023Octets",
6314 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
6315 0, "Bytes received in 512 to 1023 byte packets");
6317 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6318 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
6319 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
6320 0, "Bytes received in 1024 t0 1522 byte packets");
6322 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6323 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
6324 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
6325 0, "Bytes received in 1523 to 9022 byte packets");
6327 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6328 "stat_EtherStatsPktsTx64Octets",
6329 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
6330 0, "Bytes sent in 64 byte packets");
6332 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6333 "stat_EtherStatsPktsTx65Octetsto127Octets",
6334 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
6335 0, "Bytes sent in 65 to 127 byte packets");
6337 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6338 "stat_EtherStatsPktsTx128Octetsto255Octets",
6339 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
6340 0, "Bytes sent in 128 to 255 byte packets");
6342 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6343 "stat_EtherStatsPktsTx256Octetsto511Octets",
6344 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
6345 0, "Bytes sent in 256 to 511 byte packets");
6347 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6348 "stat_EtherStatsPktsTx512Octetsto1023Octets",
6349 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
6350 0, "Bytes sent in 512 to 1023 byte packets");
6352 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6353 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
6354 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
6355 0, "Bytes sent in 1024 to 1522 byte packets");
6357 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6358 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
6359 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
6360 0, "Bytes sent in 1523 to 9022 byte packets");
6362 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6363 "stat_XonPauseFramesReceived",
6364 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
6365 0, "XON pause frames receved");
6367 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6368 "stat_XoffPauseFramesReceived",
6369 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
6370 0, "XOFF pause frames received");
6372 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6374 CTLFLAG_RD, &sc->stat_OutXonSent,
6375 0, "XON pause frames sent");
6377 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6379 CTLFLAG_RD, &sc->stat_OutXoffSent,
6380 0, "XOFF pause frames sent");
6382 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6383 "stat_FlowControlDone",
6384 CTLFLAG_RD, &sc->stat_FlowControlDone,
6385 0, "Flow control done");
6387 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6388 "stat_MacControlFramesReceived",
6389 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
6390 0, "MAC control frames received");
6392 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6393 "stat_XoffStateEntered",
6394 CTLFLAG_RD, &sc->stat_XoffStateEntered,
6395 0, "XOFF state entered");
6397 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6398 "stat_IfInFramesL2FilterDiscards",
6399 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
6400 0, "Received L2 packets discarded");
6402 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6403 "stat_IfInRuleCheckerDiscards",
6404 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
6405 0, "Received packets discarded by rule");
6407 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6408 "stat_IfInFTQDiscards",
6409 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
6410 0, "Received packet FTQ discards");
6412 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6413 "stat_IfInMBUFDiscards",
6414 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
6415 0, "Received packets discarded due to lack of controller buffer memory");
6417 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6418 "stat_IfInRuleCheckerP4Hit",
6419 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6420 0, "Received packets rule checker hits");
6422 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6423 "stat_CatchupInRuleCheckerDiscards",
6424 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6425 0, "Received packets discarded in Catchup path");
6427 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6428 "stat_CatchupInFTQDiscards",
6429 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6430 0, "Received packets discarded in FTQ in Catchup path");
6432 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6433 "stat_CatchupInMBUFDiscards",
6434 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6435 0, "Received packets discarded in controller buffer memory in Catchup path");
6437 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6438 "stat_CatchupInRuleCheckerP4Hit",
6439 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6440 0, "Received packets rule checker hits in Catchup path");
6442 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6444 CTLFLAG_RD, &sc->com_no_buffers,
6445 0, "Valid packets received but no RX buffers available");
6448 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6449 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6451 bce_sysctl_driver_state, "I", "Drive state information");
6453 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6454 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6456 bce_sysctl_hw_state, "I", "Hardware state information");
6458 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6459 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6461 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6463 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6464 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
6466 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
6468 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6469 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6471 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6473 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6474 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
6476 bce_sysctl_reg_read, "I", "Register read");
6478 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6479 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
6481 bce_sysctl_phy_read, "I", "PHY register read");
6488 /****************************************************************************/
6489 /* BCE Debug Routines */
6490 /****************************************************************************/
6493 /****************************************************************************/
6494 /* Freezes the controller to allow for a cohesive state dump. */
6498 /****************************************************************************/
6500 bce_freeze_controller(struct bce_softc *sc)
6504 val = REG_RD(sc, BCE_MISC_COMMAND);
6505 val |= BCE_MISC_COMMAND_DISABLE_ALL;
6506 REG_WR(sc, BCE_MISC_COMMAND, val);
6510 /****************************************************************************/
6511 /* Unfreezes the controller after a freeze operation. This may not always */
6512 /* work and the controller will require a reset! */
6516 /****************************************************************************/
6518 bce_unfreeze_controller(struct bce_softc *sc)
6522 val = REG_RD(sc, BCE_MISC_COMMAND);
6523 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6524 REG_WR(sc, BCE_MISC_COMMAND, val);
6528 /****************************************************************************/
6529 /* Prints out information about an mbuf. */
6533 /****************************************************************************/
6535 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6537 struct ifnet *ifp = &sc->arpcom.ac_if;
6538 uint32_t val_hi, val_lo;
6539 struct mbuf *mp = m;
6542 /* Index out of range. */
6543 if_printf(ifp, "mbuf: null pointer\n");
6548 val_hi = BCE_ADDR_HI(mp);
6549 val_lo = BCE_ADDR_LO(mp);
6550 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6551 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6553 if (mp->m_flags & M_EXT)
6555 if (mp->m_flags & M_PKTHDR)
6556 kprintf("M_PKTHDR ");
6557 if (mp->m_flags & M_EOR)
6560 if (mp->m_flags & M_RDONLY)
6561 kprintf("M_RDONLY ");
6564 val_hi = BCE_ADDR_HI(mp->m_data);
6565 val_lo = BCE_ADDR_LO(mp->m_data);
6566 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6568 if (mp->m_flags & M_PKTHDR) {
6569 if_printf(ifp, "- m_pkthdr: flags = ( ");
6570 if (mp->m_flags & M_BCAST)
6571 kprintf("M_BCAST ");
6572 if (mp->m_flags & M_MCAST)
6573 kprintf("M_MCAST ");
6574 if (mp->m_flags & M_FRAG)
6576 if (mp->m_flags & M_FIRSTFRAG)
6577 kprintf("M_FIRSTFRAG ");
6578 if (mp->m_flags & M_LASTFRAG)
6579 kprintf("M_LASTFRAG ");
6581 if (mp->m_flags & M_VLANTAG)
6582 kprintf("M_VLANTAG ");
6585 if (mp->m_flags & M_PROMISC)
6586 kprintf("M_PROMISC ");
6588 kprintf(") csum_flags = ( ");
6589 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6590 kprintf("CSUM_IP ");
6591 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6592 kprintf("CSUM_TCP ");
6593 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6594 kprintf("CSUM_UDP ");
6595 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6596 kprintf("CSUM_IP_FRAGS ");
6597 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6598 kprintf("CSUM_FRAGMENT ");
6600 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6601 kprintf("CSUM_TSO ");
6603 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6604 kprintf("CSUM_IP_CHECKED ");
6605 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6606 kprintf("CSUM_IP_VALID ");
6607 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6608 kprintf("CSUM_DATA_VALID ");
6612 if (mp->m_flags & M_EXT) {
6613 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6614 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6615 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6617 val_hi, val_lo, mp->m_ext.ext_size);
6624 /****************************************************************************/
6625 /* Prints out the mbufs in the RX mbuf chain. */
6629 /****************************************************************************/
6631 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6633 struct ifnet *ifp = &sc->arpcom.ac_if;
6637 "----------------------------"
6639 "----------------------------\n");
6641 for (i = 0; i < count; i++) {
6642 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6643 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6644 chain_prod = RX_CHAIN_IDX(sc, NEXT_RX_BD(chain_prod));
6648 "----------------------------"
6650 "----------------------------\n");
6654 /****************************************************************************/
6655 /* Prints out a tx_bd structure. */
6659 /****************************************************************************/
6661 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6663 struct ifnet *ifp = &sc->arpcom.ac_if;
6665 if (idx > MAX_TX_BD(sc)) {
6666 /* Index out of range. */
6667 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6668 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6669 /* TX Chain page pointer. */
6670 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6671 "chain page pointer\n",
6672 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6674 /* Normal tx_bd entry. */
6675 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6677 "vlan tag= 0x%04X, flags = 0x%04X (",
6678 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6679 txbd->tx_bd_mss_nbytes,
6680 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6682 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6683 kprintf(" CONN_FAULT");
6685 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6686 kprintf(" TCP_UDP_CKSUM");
6688 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6689 kprintf(" IP_CKSUM");
6691 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6694 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6695 kprintf(" COAL_NOW");
6697 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6698 kprintf(" DONT_GEN_CRC");
6700 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6703 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6706 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6709 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6710 kprintf(" OPTION_WORD");
6712 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6715 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6723 /****************************************************************************/
6724 /* Prints out a rx_bd structure. */
6728 /****************************************************************************/
6730 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6732 struct ifnet *ifp = &sc->arpcom.ac_if;
6734 if (idx > MAX_RX_BD(sc)) {
6735 /* Index out of range. */
6736 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6737 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6738 /* TX Chain page pointer. */
6739 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6740 "chain page pointer\n",
6741 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6743 /* Normal tx_bd entry. */
6744 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6745 "nbytes = 0x%08X, flags = 0x%08X\n",
6746 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6747 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6752 /****************************************************************************/
6753 /* Prints out a l2_fhdr structure. */
6757 /****************************************************************************/
6759 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6761 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6762 "pkt_len = 0x%04X, vlan = 0x%04x, "
6763 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6764 idx, l2fhdr->l2_fhdr_status,
6765 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6766 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6770 /****************************************************************************/
6771 /* Prints out the tx chain. */
6775 /****************************************************************************/
6777 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6779 struct ifnet *ifp = &sc->arpcom.ac_if;
6782 /* First some info about the tx_bd chain structure. */
6784 "----------------------------"
6786 "----------------------------\n");
6788 if_printf(ifp, "page size = 0x%08X, "
6789 "tx chain pages = 0x%08X\n",
6790 (uint32_t)BCM_PAGE_SIZE, (uint32_t)sc->tx_pages);
6792 if_printf(ifp, "tx_bd per page = 0x%08X, "
6793 "usable tx_bd per page = 0x%08X\n",
6794 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6795 (uint32_t)USABLE_TX_BD_PER_PAGE);
6797 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD(sc));
6800 "----------------------------"
6802 "----------------------------\n");
6804 /* Now print out the tx_bd's themselves. */
6805 for (i = 0; i < count; i++) {
6808 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6809 bce_dump_txbd(sc, tx_prod, txbd);
6810 tx_prod = TX_CHAIN_IDX(sc, NEXT_TX_BD(tx_prod));
6814 "----------------------------"
6816 "----------------------------\n");
6820 /****************************************************************************/
6821 /* Prints out the rx chain. */
6825 /****************************************************************************/
6827 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6829 struct ifnet *ifp = &sc->arpcom.ac_if;
6832 /* First some info about the tx_bd chain structure. */
6834 "----------------------------"
6836 "----------------------------\n");
6838 if_printf(ifp, "page size = 0x%08X, "
6839 "rx chain pages = 0x%08X\n",
6840 (uint32_t)BCM_PAGE_SIZE, (uint32_t)sc->rx_pages);
6842 if_printf(ifp, "rx_bd per page = 0x%08X, "
6843 "usable rx_bd per page = 0x%08X\n",
6844 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6845 (uint32_t)USABLE_RX_BD_PER_PAGE);
6847 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD(sc));
6850 "----------------------------"
6852 "----------------------------\n");
6854 /* Now print out the rx_bd's themselves. */
6855 for (i = 0; i < count; i++) {
6858 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6859 bce_dump_rxbd(sc, rx_prod, rxbd);
6860 rx_prod = RX_CHAIN_IDX(sc, NEXT_RX_BD(rx_prod));
6864 "----------------------------"
6866 "----------------------------\n");
6870 /****************************************************************************/
6871 /* Prints out the status block from host memory. */
6875 /****************************************************************************/
6877 bce_dump_status_block(struct bce_softc *sc)
6879 struct status_block *sblk = sc->status_block;
6880 struct ifnet *ifp = &sc->arpcom.ac_if;
6883 "----------------------------"
6885 "----------------------------\n");
6887 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6889 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6890 sblk->status_attn_bits_ack);
6892 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6893 sblk->status_rx_quick_consumer_index0,
6894 (uint16_t)RX_CHAIN_IDX(sc, sblk->status_rx_quick_consumer_index0));
6896 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6897 sblk->status_tx_quick_consumer_index0,
6898 (uint16_t)TX_CHAIN_IDX(sc, sblk->status_tx_quick_consumer_index0));
6900 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6902 /* Theses indices are not used for normal L2 drivers. */
6903 if (sblk->status_rx_quick_consumer_index1) {
6904 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6905 sblk->status_rx_quick_consumer_index1,
6906 (uint16_t)RX_CHAIN_IDX(sc,
6907 sblk->status_rx_quick_consumer_index1));
6910 if (sblk->status_tx_quick_consumer_index1) {
6911 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6912 sblk->status_tx_quick_consumer_index1,
6913 (uint16_t)TX_CHAIN_IDX(sc,
6914 sblk->status_tx_quick_consumer_index1));
6917 if (sblk->status_rx_quick_consumer_index2) {
6918 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
6919 sblk->status_rx_quick_consumer_index2,
6920 (uint16_t)RX_CHAIN_IDX(sc,
6921 sblk->status_rx_quick_consumer_index2));
6924 if (sblk->status_tx_quick_consumer_index2) {
6925 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
6926 sblk->status_tx_quick_consumer_index2,
6927 (uint16_t)TX_CHAIN_IDX(sc,
6928 sblk->status_tx_quick_consumer_index2));
6931 if (sblk->status_rx_quick_consumer_index3) {
6932 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
6933 sblk->status_rx_quick_consumer_index3,
6934 (uint16_t)RX_CHAIN_IDX(sc,
6935 sblk->status_rx_quick_consumer_index3));
6938 if (sblk->status_tx_quick_consumer_index3) {
6939 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
6940 sblk->status_tx_quick_consumer_index3,
6941 (uint16_t)TX_CHAIN_IDX(sc,
6942 sblk->status_tx_quick_consumer_index3));
6945 if (sblk->status_rx_quick_consumer_index4 ||
6946 sblk->status_rx_quick_consumer_index5) {
6947 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
6948 sblk->status_rx_quick_consumer_index4,
6949 sblk->status_rx_quick_consumer_index5);
6952 if (sblk->status_rx_quick_consumer_index6 ||
6953 sblk->status_rx_quick_consumer_index7) {
6954 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
6955 sblk->status_rx_quick_consumer_index6,
6956 sblk->status_rx_quick_consumer_index7);
6959 if (sblk->status_rx_quick_consumer_index8 ||
6960 sblk->status_rx_quick_consumer_index9) {
6961 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
6962 sblk->status_rx_quick_consumer_index8,
6963 sblk->status_rx_quick_consumer_index9);
6966 if (sblk->status_rx_quick_consumer_index10 ||
6967 sblk->status_rx_quick_consumer_index11) {
6968 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
6969 sblk->status_rx_quick_consumer_index10,
6970 sblk->status_rx_quick_consumer_index11);
6973 if (sblk->status_rx_quick_consumer_index12 ||
6974 sblk->status_rx_quick_consumer_index13) {
6975 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
6976 sblk->status_rx_quick_consumer_index12,
6977 sblk->status_rx_quick_consumer_index13);
6980 if (sblk->status_rx_quick_consumer_index14 ||
6981 sblk->status_rx_quick_consumer_index15) {
6982 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
6983 sblk->status_rx_quick_consumer_index14,
6984 sblk->status_rx_quick_consumer_index15);
6987 if (sblk->status_completion_producer_index ||
6988 sblk->status_cmd_consumer_index) {
6989 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
6990 sblk->status_completion_producer_index,
6991 sblk->status_cmd_consumer_index);
6995 "----------------------------"
6997 "----------------------------\n");
7001 /****************************************************************************/
7002 /* Prints out the statistics block. */
7006 /****************************************************************************/
7008 bce_dump_stats_block(struct bce_softc *sc)
7010 struct statistics_block *sblk = sc->stats_block;
7011 struct ifnet *ifp = &sc->arpcom.ac_if;
7015 " Stats Block (All Stats Not Shown Are 0) "
7016 "---------------\n");
7018 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
7019 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
7020 sblk->stat_IfHCInOctets_hi,
7021 sblk->stat_IfHCInOctets_lo);
7024 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
7025 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
7026 sblk->stat_IfHCInBadOctets_hi,
7027 sblk->stat_IfHCInBadOctets_lo);
7030 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
7031 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
7032 sblk->stat_IfHCOutOctets_hi,
7033 sblk->stat_IfHCOutOctets_lo);
7036 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
7037 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
7038 sblk->stat_IfHCOutBadOctets_hi,
7039 sblk->stat_IfHCOutBadOctets_lo);
7042 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
7043 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
7044 sblk->stat_IfHCInUcastPkts_hi,
7045 sblk->stat_IfHCInUcastPkts_lo);
7048 if (sblk->stat_IfHCInBroadcastPkts_hi ||
7049 sblk->stat_IfHCInBroadcastPkts_lo) {
7050 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
7051 sblk->stat_IfHCInBroadcastPkts_hi,
7052 sblk->stat_IfHCInBroadcastPkts_lo);
7055 if (sblk->stat_IfHCInMulticastPkts_hi ||
7056 sblk->stat_IfHCInMulticastPkts_lo) {
7057 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
7058 sblk->stat_IfHCInMulticastPkts_hi,
7059 sblk->stat_IfHCInMulticastPkts_lo);
7062 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
7063 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
7064 sblk->stat_IfHCOutUcastPkts_hi,
7065 sblk->stat_IfHCOutUcastPkts_lo);
7068 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
7069 sblk->stat_IfHCOutBroadcastPkts_lo) {
7070 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
7071 sblk->stat_IfHCOutBroadcastPkts_hi,
7072 sblk->stat_IfHCOutBroadcastPkts_lo);
7075 if (sblk->stat_IfHCOutMulticastPkts_hi ||
7076 sblk->stat_IfHCOutMulticastPkts_lo) {
7077 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
7078 sblk->stat_IfHCOutMulticastPkts_hi,
7079 sblk->stat_IfHCOutMulticastPkts_lo);
7082 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
7083 if_printf(ifp, " 0x%08X : "
7084 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
7085 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
7088 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
7089 if_printf(ifp, " 0x%08X : "
7090 "Dot3StatsCarrierSenseErrors\n",
7091 sblk->stat_Dot3StatsCarrierSenseErrors);
7094 if (sblk->stat_Dot3StatsFCSErrors) {
7095 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
7096 sblk->stat_Dot3StatsFCSErrors);
7099 if (sblk->stat_Dot3StatsAlignmentErrors) {
7100 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
7101 sblk->stat_Dot3StatsAlignmentErrors);
7104 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
7105 if_printf(ifp, " 0x%08X : "
7106 "Dot3StatsSingleCollisionFrames\n",
7107 sblk->stat_Dot3StatsSingleCollisionFrames);
7110 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
7111 if_printf(ifp, " 0x%08X : "
7112 "Dot3StatsMultipleCollisionFrames\n",
7113 sblk->stat_Dot3StatsMultipleCollisionFrames);
7116 if (sblk->stat_Dot3StatsDeferredTransmissions) {
7117 if_printf(ifp, " 0x%08X : "
7118 "Dot3StatsDeferredTransmissions\n",
7119 sblk->stat_Dot3StatsDeferredTransmissions);
7122 if (sblk->stat_Dot3StatsExcessiveCollisions) {
7123 if_printf(ifp, " 0x%08X : "
7124 "Dot3StatsExcessiveCollisions\n",
7125 sblk->stat_Dot3StatsExcessiveCollisions);
7128 if (sblk->stat_Dot3StatsLateCollisions) {
7129 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
7130 sblk->stat_Dot3StatsLateCollisions);
7133 if (sblk->stat_EtherStatsCollisions) {
7134 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
7135 sblk->stat_EtherStatsCollisions);
7138 if (sblk->stat_EtherStatsFragments) {
7139 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
7140 sblk->stat_EtherStatsFragments);
7143 if (sblk->stat_EtherStatsJabbers) {
7144 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
7145 sblk->stat_EtherStatsJabbers);
7148 if (sblk->stat_EtherStatsUndersizePkts) {
7149 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
7150 sblk->stat_EtherStatsUndersizePkts);
7153 if (sblk->stat_EtherStatsOverrsizePkts) {
7154 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
7155 sblk->stat_EtherStatsOverrsizePkts);
7158 if (sblk->stat_EtherStatsPktsRx64Octets) {
7159 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
7160 sblk->stat_EtherStatsPktsRx64Octets);
7163 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
7164 if_printf(ifp, " 0x%08X : "
7165 "EtherStatsPktsRx65Octetsto127Octets\n",
7166 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
7169 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
7170 if_printf(ifp, " 0x%08X : "
7171 "EtherStatsPktsRx128Octetsto255Octets\n",
7172 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
7175 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
7176 if_printf(ifp, " 0x%08X : "
7177 "EtherStatsPktsRx256Octetsto511Octets\n",
7178 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
7181 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
7182 if_printf(ifp, " 0x%08X : "
7183 "EtherStatsPktsRx512Octetsto1023Octets\n",
7184 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
7187 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
7188 if_printf(ifp, " 0x%08X : "
7189 "EtherStatsPktsRx1024Octetsto1522Octets\n",
7190 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
7193 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
7194 if_printf(ifp, " 0x%08X : "
7195 "EtherStatsPktsRx1523Octetsto9022Octets\n",
7196 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
7199 if (sblk->stat_EtherStatsPktsTx64Octets) {
7200 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
7201 sblk->stat_EtherStatsPktsTx64Octets);
7204 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
7205 if_printf(ifp, " 0x%08X : "
7206 "EtherStatsPktsTx65Octetsto127Octets\n",
7207 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
7210 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
7211 if_printf(ifp, " 0x%08X : "
7212 "EtherStatsPktsTx128Octetsto255Octets\n",
7213 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
7216 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
7217 if_printf(ifp, " 0x%08X : "
7218 "EtherStatsPktsTx256Octetsto511Octets\n",
7219 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
7222 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
7223 if_printf(ifp, " 0x%08X : "
7224 "EtherStatsPktsTx512Octetsto1023Octets\n",
7225 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
7228 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
7229 if_printf(ifp, " 0x%08X : "
7230 "EtherStatsPktsTx1024Octetsto1522Octets\n",
7231 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
7234 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
7235 if_printf(ifp, " 0x%08X : "
7236 "EtherStatsPktsTx1523Octetsto9022Octets\n",
7237 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
7240 if (sblk->stat_XonPauseFramesReceived) {
7241 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
7242 sblk->stat_XonPauseFramesReceived);
7245 if (sblk->stat_XoffPauseFramesReceived) {
7246 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
7247 sblk->stat_XoffPauseFramesReceived);
7250 if (sblk->stat_OutXonSent) {
7251 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7252 sblk->stat_OutXonSent);
7255 if (sblk->stat_OutXoffSent) {
7256 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7257 sblk->stat_OutXoffSent);
7260 if (sblk->stat_FlowControlDone) {
7261 if_printf(ifp, " 0x%08X : FlowControlDone\n",
7262 sblk->stat_FlowControlDone);
7265 if (sblk->stat_MacControlFramesReceived) {
7266 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
7267 sblk->stat_MacControlFramesReceived);
7270 if (sblk->stat_XoffStateEntered) {
7271 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
7272 sblk->stat_XoffStateEntered);
7275 if (sblk->stat_IfInFramesL2FilterDiscards) {
7276 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
7279 if (sblk->stat_IfInRuleCheckerDiscards) {
7280 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
7281 sblk->stat_IfInRuleCheckerDiscards);
7284 if (sblk->stat_IfInFTQDiscards) {
7285 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
7286 sblk->stat_IfInFTQDiscards);
7289 if (sblk->stat_IfInMBUFDiscards) {
7290 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
7291 sblk->stat_IfInMBUFDiscards);
7294 if (sblk->stat_IfInRuleCheckerP4Hit) {
7295 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
7296 sblk->stat_IfInRuleCheckerP4Hit);
7299 if (sblk->stat_CatchupInRuleCheckerDiscards) {
7300 if_printf(ifp, " 0x%08X : "
7301 "CatchupInRuleCheckerDiscards\n",
7302 sblk->stat_CatchupInRuleCheckerDiscards);
7305 if (sblk->stat_CatchupInFTQDiscards) {
7306 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
7307 sblk->stat_CatchupInFTQDiscards);
7310 if (sblk->stat_CatchupInMBUFDiscards) {
7311 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
7312 sblk->stat_CatchupInMBUFDiscards);
7315 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
7316 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
7317 sblk->stat_CatchupInRuleCheckerP4Hit);
7321 "----------------------------"
7323 "----------------------------\n");
7327 /****************************************************************************/
7328 /* Prints out a summary of the driver state. */
7332 /****************************************************************************/
7334 bce_dump_driver_state(struct bce_softc *sc)
7336 struct ifnet *ifp = &sc->arpcom.ac_if;
7337 uint32_t val_hi, val_lo;
7340 "-----------------------------"
7342 "-----------------------------\n");
7344 val_hi = BCE_ADDR_HI(sc);
7345 val_lo = BCE_ADDR_LO(sc);
7346 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
7347 "virtual address\n", val_hi, val_lo);
7349 val_hi = BCE_ADDR_HI(sc->status_block);
7350 val_lo = BCE_ADDR_LO(sc->status_block);
7351 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
7352 "virtual address\n", val_hi, val_lo);
7354 val_hi = BCE_ADDR_HI(sc->stats_block);
7355 val_lo = BCE_ADDR_LO(sc->stats_block);
7356 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
7357 "virtual address\n", val_hi, val_lo);
7359 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
7360 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
7361 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
7362 "virtual adddress\n", val_hi, val_lo);
7364 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
7365 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
7366 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
7367 "virtual address\n", val_hi, val_lo);
7369 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
7370 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
7371 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
7372 "virtual address\n", val_hi, val_lo);
7374 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
7375 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
7376 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
7377 "virtual address\n", val_hi, val_lo);
7379 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
7380 "h/w intrs\n", sc->interrupts_generated);
7382 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
7383 "rx interrupts handled\n", sc->rx_interrupts);
7385 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
7386 "tx interrupts handled\n", sc->tx_interrupts);
7388 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
7389 "status block index\n", sc->last_status_idx);
7391 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
7392 "tx producer index\n",
7393 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc, sc->tx_prod));
7395 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
7396 "tx consumer index\n",
7397 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc, sc->tx_cons));
7399 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
7400 "tx producer bseq index\n", sc->tx_prod_bseq);
7402 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
7403 "rx producer index\n",
7404 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc, sc->rx_prod));
7406 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
7407 "rx consumer index\n",
7408 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc, sc->rx_cons));
7410 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
7411 "rx producer bseq index\n", sc->rx_prod_bseq);
7413 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7414 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7416 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
7417 "free rx_bd's\n", sc->free_rx_bd);
7419 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
7420 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
7422 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
7423 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
7425 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7426 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7428 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
7431 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
7432 sc->tx_hi_watermark, sc->max_tx_bd);
7434 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
7435 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
7438 "----------------------------"
7440 "----------------------------\n");
7444 /****************************************************************************/
7445 /* Prints out the hardware state through a summary of important registers, */
7446 /* followed by a complete register dump. */
7450 /****************************************************************************/
7452 bce_dump_hw_state(struct bce_softc *sc)
7454 struct ifnet *ifp = &sc->arpcom.ac_if;
7459 "----------------------------"
7461 "----------------------------\n");
7463 if_printf(ifp, "%s - bootcode version\n", sc->bce_bc_ver);
7465 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
7466 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
7467 val1, BCE_MISC_ENABLE_STATUS_BITS);
7469 val1 = REG_RD(sc, BCE_DMA_STATUS);
7470 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
7472 val1 = REG_RD(sc, BCE_CTX_STATUS);
7473 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
7475 val1 = REG_RD(sc, BCE_EMAC_STATUS);
7476 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
7477 val1, BCE_EMAC_STATUS);
7479 val1 = REG_RD(sc, BCE_RPM_STATUS);
7480 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
7482 val1 = REG_RD(sc, BCE_TBDR_STATUS);
7483 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
7484 val1, BCE_TBDR_STATUS);
7486 val1 = REG_RD(sc, BCE_TDMA_STATUS);
7487 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
7488 val1, BCE_TDMA_STATUS);
7490 val1 = REG_RD(sc, BCE_HC_STATUS);
7491 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7493 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7494 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7495 val1, BCE_TXP_CPU_STATE);
7497 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7498 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7499 val1, BCE_TPAT_CPU_STATE);
7501 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7502 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7503 val1, BCE_RXP_CPU_STATE);
7505 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7506 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7507 val1, BCE_COM_CPU_STATE);
7509 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7510 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7511 val1, BCE_MCP_CPU_STATE);
7513 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7514 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7515 val1, BCE_CP_CPU_STATE);
7518 "----------------------------"
7520 "----------------------------\n");
7523 "----------------------------"
7525 "----------------------------\n");
7527 for (i = 0x400; i < 0x8000; i += 0x10) {
7528 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7530 REG_RD(sc, i + 0x4),
7531 REG_RD(sc, i + 0x8),
7532 REG_RD(sc, i + 0xc));
7536 "----------------------------"
7538 "----------------------------\n");
7542 /****************************************************************************/
7543 /* Prints out the TXP state. */
7547 /****************************************************************************/
7549 bce_dump_txp_state(struct bce_softc *sc)
7551 struct ifnet *ifp = &sc->arpcom.ac_if;
7556 "----------------------------"
7558 "----------------------------\n");
7560 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7561 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7562 val1, BCE_TXP_CPU_MODE);
7564 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7565 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7566 val1, BCE_TXP_CPU_STATE);
7568 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7569 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7570 val1, BCE_TXP_CPU_EVENT_MASK);
7573 "----------------------------"
7575 "----------------------------\n");
7577 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7578 /* Skip the big blank spaces */
7579 if (i < 0x454000 && i > 0x5ffff) {
7580 if_printf(ifp, "0x%04X: "
7581 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7583 REG_RD_IND(sc, i + 0x4),
7584 REG_RD_IND(sc, i + 0x8),
7585 REG_RD_IND(sc, i + 0xc));
7590 "----------------------------"
7592 "----------------------------\n");
7596 /****************************************************************************/
7597 /* Prints out the RXP state. */
7601 /****************************************************************************/
7603 bce_dump_rxp_state(struct bce_softc *sc)
7605 struct ifnet *ifp = &sc->arpcom.ac_if;
7610 "----------------------------"
7612 "----------------------------\n");
7614 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7615 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7616 val1, BCE_RXP_CPU_MODE);
7618 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7619 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7620 val1, BCE_RXP_CPU_STATE);
7622 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7623 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7624 val1, BCE_RXP_CPU_EVENT_MASK);
7627 "----------------------------"
7629 "----------------------------\n");
7631 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7632 /* Skip the big blank sapces */
7633 if (i < 0xc5400 && i > 0xdffff) {
7634 if_printf(ifp, "0x%04X: "
7635 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7637 REG_RD_IND(sc, i + 0x4),
7638 REG_RD_IND(sc, i + 0x8),
7639 REG_RD_IND(sc, i + 0xc));
7644 "----------------------------"
7646 "----------------------------\n");
7650 /****************************************************************************/
7651 /* Prints out the TPAT state. */
7655 /****************************************************************************/
7657 bce_dump_tpat_state(struct bce_softc *sc)
7659 struct ifnet *ifp = &sc->arpcom.ac_if;
7664 "----------------------------"
7666 "----------------------------\n");
7668 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7669 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7670 val1, BCE_TPAT_CPU_MODE);
7672 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7673 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7674 val1, BCE_TPAT_CPU_STATE);
7676 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7677 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7678 val1, BCE_TPAT_CPU_EVENT_MASK);
7681 "----------------------------"
7683 "----------------------------\n");
7685 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7686 /* Skip the big blank spaces */
7687 if (i < 0x854000 && i > 0x9ffff) {
7688 if_printf(ifp, "0x%04X: "
7689 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7691 REG_RD_IND(sc, i + 0x4),
7692 REG_RD_IND(sc, i + 0x8),
7693 REG_RD_IND(sc, i + 0xc));
7698 "----------------------------"
7700 "----------------------------\n");
7704 /****************************************************************************/
7705 /* Prints out the driver state and then enters the debugger. */
7709 /****************************************************************************/
7711 bce_breakpoint(struct bce_softc *sc)
7714 bce_freeze_controller(sc);
7717 bce_dump_driver_state(sc);
7718 bce_dump_status_block(sc);
7719 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD(sc));
7720 bce_dump_hw_state(sc);
7721 bce_dump_txp_state(sc);
7724 bce_unfreeze_controller(sc);
7727 /* Call the debugger. */
7731 #endif /* BCE_DEBUG */
7734 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7736 struct bce_softc *sc = arg1;
7738 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7739 &sc->bce_tx_quick_cons_trip_int,
7740 BCE_COALMASK_TX_BDS_INT);
7744 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7746 struct bce_softc *sc = arg1;
7748 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7749 &sc->bce_tx_quick_cons_trip,
7750 BCE_COALMASK_TX_BDS);
7754 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7756 struct bce_softc *sc = arg1;
7758 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7759 &sc->bce_tx_ticks_int,
7760 BCE_COALMASK_TX_TICKS_INT);
7764 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7766 struct bce_softc *sc = arg1;
7768 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7770 BCE_COALMASK_TX_TICKS);
7774 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7776 struct bce_softc *sc = arg1;
7778 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7779 &sc->bce_rx_quick_cons_trip_int,
7780 BCE_COALMASK_RX_BDS_INT);
7784 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7786 struct bce_softc *sc = arg1;
7788 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7789 &sc->bce_rx_quick_cons_trip,
7790 BCE_COALMASK_RX_BDS);
7794 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7796 struct bce_softc *sc = arg1;
7798 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7799 &sc->bce_rx_ticks_int,
7800 BCE_COALMASK_RX_TICKS_INT);
7804 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7806 struct bce_softc *sc = arg1;
7808 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7810 BCE_COALMASK_RX_TICKS);
7814 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7815 uint32_t coalchg_mask)
7817 struct bce_softc *sc = arg1;
7818 struct ifnet *ifp = &sc->arpcom.ac_if;
7821 lwkt_serialize_enter(ifp->if_serializer);
7824 error = sysctl_handle_int(oidp, &v, 0, req);
7825 if (!error && req->newptr != NULL) {
7830 sc->bce_coalchg_mask |= coalchg_mask;
7834 lwkt_serialize_exit(ifp->if_serializer);
7839 bce_coal_change(struct bce_softc *sc)
7841 struct ifnet *ifp = &sc->arpcom.ac_if;
7843 ASSERT_SERIALIZED(ifp->if_serializer);
7845 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7846 sc->bce_coalchg_mask = 0;
7850 if (sc->bce_coalchg_mask &
7851 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7852 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7853 (sc->bce_tx_quick_cons_trip_int << 16) |
7854 sc->bce_tx_quick_cons_trip);
7856 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7857 sc->bce_tx_quick_cons_trip,
7858 sc->bce_tx_quick_cons_trip_int);
7862 if (sc->bce_coalchg_mask &
7863 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7864 REG_WR(sc, BCE_HC_TX_TICKS,
7865 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7867 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7868 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7872 if (sc->bce_coalchg_mask &
7873 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7874 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7875 (sc->bce_rx_quick_cons_trip_int << 16) |
7876 sc->bce_rx_quick_cons_trip);
7878 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7879 sc->bce_rx_quick_cons_trip,
7880 sc->bce_rx_quick_cons_trip_int);
7884 if (sc->bce_coalchg_mask &
7885 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7886 REG_WR(sc, BCE_HC_RX_TICKS,
7887 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7889 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7890 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7894 sc->bce_coalchg_mask = 0;
7898 bce_tso_setup(struct bce_softc *sc, struct mbuf **mp,
7899 uint16_t *flags0, uint16_t *mss0)
7903 int thoff, iphlen, hoff;
7906 KASSERT(M_WRITABLE(m), ("TSO mbuf not writable"));
7908 hoff = m->m_pkthdr.csum_lhlen;
7909 iphlen = m->m_pkthdr.csum_iphlen;
7910 thoff = m->m_pkthdr.csum_thlen;
7912 KASSERT(hoff >= sizeof(struct ether_header),
7913 ("invalid ether header len %d", hoff));
7914 KASSERT(iphlen >= sizeof(struct ip),
7915 ("invalid ip header len %d", iphlen));
7916 KASSERT(thoff >= sizeof(struct tcphdr),
7917 ("invalid tcp header len %d", thoff));
7919 if (__predict_false(m->m_len < hoff + iphlen + thoff)) {
7920 m = m_pullup(m, hoff + iphlen + thoff);
7928 /* Set the LSO flag in the TX BD */
7929 flags = TX_BD_FLAGS_SW_LSO;
7931 /* Set the length of IP + TCP options (in 32 bit words) */
7932 flags |= (((iphlen + thoff -
7933 sizeof(struct ip) - sizeof(struct tcphdr)) >> 2) << 8);
7935 *mss0 = htole16(m->m_pkthdr.tso_segsz);