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_ifpoll.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_poll.h>
81 #include <net/if_types.h>
82 #include <net/ifq_var.h>
83 #include <net/vlan/if_vlan_var.h>
84 #include <net/vlan/if_vlan_ether.h>
86 #include <dev/netif/mii_layer/mii.h>
87 #include <dev/netif/mii_layer/miivar.h>
88 #include <dev/netif/mii_layer/brgphyreg.h>
90 #include <bus/pci/pcireg.h>
91 #include <bus/pci/pcivar.h>
93 #include "miibus_if.h"
95 #include <dev/netif/bce/if_bcereg.h>
96 #include <dev/netif/bce/if_bcefw.h>
98 #define BCE_MSI_CKINTVL ((10 * hz) / 1000) /* 10ms */
100 /****************************************************************************/
101 /* BCE Debug Options */
102 /****************************************************************************/
105 static uint32_t bce_debug = BCE_WARN;
109 * 1 = 1 in 2,147,483,648
110 * 256 = 1 in 8,388,608
111 * 2048 = 1 in 1,048,576
112 * 65536 = 1 in 32,768
113 * 1048576 = 1 in 2,048
116 * 1073741824 = 1 in 2
118 * bce_debug_mbuf_allocation_failure:
119 * How often to simulate an mbuf allocation failure.
121 * bce_debug_dma_map_addr_failure:
122 * How often to simulate a DMA mapping failure.
124 * bce_debug_bootcode_running_failure:
125 * How often to simulate a bootcode failure.
127 static int bce_debug_mbuf_allocation_failure = 0;
128 static int bce_debug_dma_map_addr_failure = 0;
129 static int bce_debug_bootcode_running_failure = 0;
131 #endif /* BCE_DEBUG */
134 /****************************************************************************/
135 /* PCI Device ID Table */
137 /* Used by bce_probe() to identify the devices supported by this driver. */
138 /****************************************************************************/
139 #define BCE_DEVDESC_MAX 64
141 static struct bce_type bce_devs[] = {
142 /* BCM5706C Controllers and OEM boards. */
143 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
144 "HP NC370T Multifunction Gigabit Server Adapter" },
145 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
146 "HP NC370i Multifunction Gigabit Server Adapter" },
147 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
148 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
149 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
150 "HP NC371i Multifunction Gigabit Server Adapter" },
151 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
152 "Broadcom NetXtreme II BCM5706 1000Base-T" },
154 /* BCM5706S controllers and OEM boards. */
155 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
156 "HP NC370F Multifunction Gigabit Server Adapter" },
157 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
158 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
160 /* BCM5708C controllers and OEM boards. */
161 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
162 "HP NC373T PCIe Multifunction Gig Server Adapter" },
163 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
164 "HP NC373i Multifunction Gigabit Server Adapter" },
165 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
166 "HP NC374m PCIe Multifunction Adapter" },
167 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
168 "Broadcom NetXtreme II BCM5708 1000Base-T" },
170 /* BCM5708S controllers and OEM boards. */
171 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
172 "HP NC373m Multifunction Gigabit Server Adapter" },
173 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
174 "HP NC373i Multifunction Gigabit Server Adapter" },
175 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
176 "HP NC373F PCIe Multifunc Giga Server Adapter" },
177 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
178 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
180 /* BCM5709C controllers and OEM boards. */
181 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
182 "HP NC382i DP Multifunction Gigabit Server Adapter" },
183 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
184 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
185 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
186 "Broadcom NetXtreme II BCM5709 1000Base-T" },
188 /* BCM5709S controllers and OEM boards. */
189 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
190 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
191 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
192 "HP NC382i DP Multifunction Gigabit Server Adapter" },
193 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
194 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
196 /* BCM5716 controllers and OEM boards. */
197 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
198 "Broadcom NetXtreme II BCM5716 1000Base-T" },
204 /****************************************************************************/
205 /* Supported Flash NVRAM device data. */
206 /****************************************************************************/
207 static const struct flash_spec flash_table[] =
209 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
210 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
213 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
214 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
215 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
217 /* Expansion entry 0001 */
218 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
219 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
220 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
222 /* Saifun SA25F010 (non-buffered flash) */
223 /* strap, cfg1, & write1 need updates */
224 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
225 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
226 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
227 "Non-buffered flash (128kB)"},
228 /* Saifun SA25F020 (non-buffered flash) */
229 /* strap, cfg1, & write1 need updates */
230 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
231 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
232 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
233 "Non-buffered flash (256kB)"},
234 /* Expansion entry 0100 */
235 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
236 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
237 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
239 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
240 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
241 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
242 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
243 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
244 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
245 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
246 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
247 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
248 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
249 /* Saifun SA25F005 (non-buffered flash) */
250 /* strap, cfg1, & write1 need updates */
251 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
252 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
253 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
254 "Non-buffered flash (64kB)"},
256 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
257 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
258 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
260 /* Expansion entry 1001 */
261 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
262 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
263 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
265 /* Expansion entry 1010 */
266 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
267 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
268 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
270 /* ATMEL AT45DB011B (buffered flash) */
271 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
272 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
273 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
274 "Buffered flash (128kB)"},
275 /* Expansion entry 1100 */
276 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
277 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
278 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
280 /* Expansion entry 1101 */
281 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
282 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
283 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
285 /* Ateml Expansion entry 1110 */
286 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
287 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
288 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
289 "Entry 1110 (Atmel)"},
290 /* ATMEL AT45DB021B (buffered flash) */
291 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
292 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
293 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
294 "Buffered flash (256kB)"},
298 * The BCM5709 controllers transparently handle the
299 * differences between Atmel 264 byte pages and all
300 * flash devices which use 256 byte pages, so no
301 * logical-to-physical mapping is required in the
304 static struct flash_spec flash_5709 = {
305 .flags = BCE_NV_BUFFERED,
306 .page_bits = BCM5709_FLASH_PAGE_BITS,
307 .page_size = BCM5709_FLASH_PAGE_SIZE,
308 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
309 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
310 .name = "5709/5716 buffered flash (256kB)",
314 /****************************************************************************/
315 /* DragonFly device entry points. */
316 /****************************************************************************/
317 static int bce_probe(device_t);
318 static int bce_attach(device_t);
319 static int bce_detach(device_t);
320 static void bce_shutdown(device_t);
322 /****************************************************************************/
323 /* BCE Debug Data Structure Dump Routines */
324 /****************************************************************************/
326 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
327 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
328 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
329 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
330 static void bce_dump_l2fhdr(struct bce_softc *, int,
331 struct l2_fhdr *) __unused;
332 static void bce_dump_tx_chain(struct bce_softc *, int, int);
333 static void bce_dump_rx_chain(struct bce_softc *, int, int);
334 static void bce_dump_status_block(struct bce_softc *);
335 static void bce_dump_driver_state(struct bce_softc *);
336 static void bce_dump_stats_block(struct bce_softc *) __unused;
337 static void bce_dump_hw_state(struct bce_softc *);
338 static void bce_dump_txp_state(struct bce_softc *);
339 static void bce_dump_rxp_state(struct bce_softc *) __unused;
340 static void bce_dump_tpat_state(struct bce_softc *) __unused;
341 static void bce_freeze_controller(struct bce_softc *) __unused;
342 static void bce_unfreeze_controller(struct bce_softc *) __unused;
343 static void bce_breakpoint(struct bce_softc *);
344 #endif /* BCE_DEBUG */
347 /****************************************************************************/
348 /* BCE Register/Memory Access Routines */
349 /****************************************************************************/
350 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
351 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
352 static void bce_shmem_wr(struct bce_softc *, uint32_t, uint32_t);
353 static uint32_t bce_shmem_rd(struct bce_softc *, u32);
354 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
355 static int bce_miibus_read_reg(device_t, int, int);
356 static int bce_miibus_write_reg(device_t, int, int, int);
357 static void bce_miibus_statchg(device_t);
360 /****************************************************************************/
361 /* BCE NVRAM Access Routines */
362 /****************************************************************************/
363 static int bce_acquire_nvram_lock(struct bce_softc *);
364 static int bce_release_nvram_lock(struct bce_softc *);
365 static void bce_enable_nvram_access(struct bce_softc *);
366 static void bce_disable_nvram_access(struct bce_softc *);
367 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
369 static int bce_init_nvram(struct bce_softc *);
370 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
371 static int bce_nvram_test(struct bce_softc *);
373 /****************************************************************************/
374 /* BCE DMA Allocate/Free Routines */
375 /****************************************************************************/
376 static int bce_dma_alloc(struct bce_softc *);
377 static void bce_dma_free(struct bce_softc *);
378 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
380 /****************************************************************************/
381 /* BCE Firmware Synchronization and Load */
382 /****************************************************************************/
383 static int bce_fw_sync(struct bce_softc *, uint32_t);
384 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
386 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
388 static void bce_start_cpu(struct bce_softc *, struct cpu_reg *);
389 static void bce_halt_cpu(struct bce_softc *, struct cpu_reg *);
390 static void bce_start_rxp_cpu(struct bce_softc *);
391 static void bce_init_rxp_cpu(struct bce_softc *);
392 static void bce_init_txp_cpu(struct bce_softc *);
393 static void bce_init_tpat_cpu(struct bce_softc *);
394 static void bce_init_cp_cpu(struct bce_softc *);
395 static void bce_init_com_cpu(struct bce_softc *);
396 static void bce_init_cpus(struct bce_softc *);
398 static void bce_stop(struct bce_softc *);
399 static int bce_reset(struct bce_softc *, uint32_t);
400 static int bce_chipinit(struct bce_softc *);
401 static int bce_blockinit(struct bce_softc *);
402 static int bce_newbuf_std(struct bce_softc *, uint16_t *, uint16_t *,
404 static void bce_setup_rxdesc_std(struct bce_softc *, uint16_t, uint32_t *);
405 static void bce_probe_pci_caps(struct bce_softc *);
406 static void bce_print_adapter_info(struct bce_softc *);
407 static void bce_get_media(struct bce_softc *);
409 static void bce_init_tx_context(struct bce_softc *);
410 static int bce_init_tx_chain(struct bce_softc *);
411 static void bce_init_rx_context(struct bce_softc *);
412 static int bce_init_rx_chain(struct bce_softc *);
413 static void bce_free_rx_chain(struct bce_softc *);
414 static void bce_free_tx_chain(struct bce_softc *);
416 static int bce_encap(struct bce_softc *, struct mbuf **, int *);
417 static int bce_tso_setup(struct bce_softc *, struct mbuf **,
418 uint16_t *, uint16_t *);
419 static void bce_start(struct ifnet *);
420 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
421 static void bce_watchdog(struct ifnet *);
422 static int bce_ifmedia_upd(struct ifnet *);
423 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
424 static void bce_init(void *);
425 static void bce_mgmt_init(struct bce_softc *);
427 static int bce_init_ctx(struct bce_softc *);
428 static void bce_get_mac_addr(struct bce_softc *);
429 static void bce_set_mac_addr(struct bce_softc *);
430 static void bce_phy_intr(struct bce_softc *);
431 static void bce_rx_intr(struct bce_softc *, int, uint16_t);
432 static void bce_tx_intr(struct bce_softc *, uint16_t);
433 static void bce_disable_intr(struct bce_softc *);
434 static void bce_enable_intr(struct bce_softc *);
435 static void bce_reenable_intr(struct bce_softc *);
438 static void bce_npoll(struct ifnet *, struct ifpoll_info *);
439 static void bce_npoll_compat(struct ifnet *, void *, int);
441 static void bce_intr(struct bce_softc *);
442 static void bce_intr_legacy(void *);
443 static void bce_intr_msi(void *);
444 static void bce_intr_msi_oneshot(void *);
445 static void bce_set_rx_mode(struct bce_softc *);
446 static void bce_stats_update(struct bce_softc *);
447 static void bce_tick(void *);
448 static void bce_tick_serialized(struct bce_softc *);
449 static void bce_pulse(void *);
450 static void bce_check_msi(void *);
451 static void bce_add_sysctls(struct bce_softc *);
453 static void bce_coal_change(struct bce_softc *);
454 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
455 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
456 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
457 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
458 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
459 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
460 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
461 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
462 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
463 uint32_t *, uint32_t);
467 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
468 * takes 1023 as the TX ticks limit. However, using 1023 will
469 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
470 * there is _no_ network activity on the NIC.
472 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
473 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
474 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
475 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
476 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
477 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
478 static uint32_t bce_rx_ticks_int = 150; /* bcm: 18 */
479 static uint32_t bce_rx_ticks = 150; /* bcm: 18 */
481 static int bce_msi_enable = 1;
483 static int bce_rx_pages = RX_PAGES_DEFAULT;
484 static int bce_tx_pages = TX_PAGES_DEFAULT;
486 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
487 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
488 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
489 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
490 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
491 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
492 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
493 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
494 TUNABLE_INT("hw.bce.msi.enable", &bce_msi_enable);
495 TUNABLE_INT("hw.bce.rx_pages", &bce_rx_pages);
496 TUNABLE_INT("hw.bce.tx_pages", &bce_tx_pages);
498 /****************************************************************************/
499 /* DragonFly device dispatch table. */
500 /****************************************************************************/
501 static device_method_t bce_methods[] = {
502 /* Device interface */
503 DEVMETHOD(device_probe, bce_probe),
504 DEVMETHOD(device_attach, bce_attach),
505 DEVMETHOD(device_detach, bce_detach),
506 DEVMETHOD(device_shutdown, bce_shutdown),
509 DEVMETHOD(bus_print_child, bus_generic_print_child),
510 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
513 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
514 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
515 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
520 static driver_t bce_driver = {
523 sizeof(struct bce_softc)
526 static devclass_t bce_devclass;
529 DECLARE_DUMMY_MODULE(if_bce);
530 MODULE_DEPEND(bce, miibus, 1, 1, 1);
531 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
532 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
535 /****************************************************************************/
536 /* Device probe function. */
538 /* Compares the device to the driver's list of supported devices and */
539 /* reports back to the OS whether this is the right driver for the device. */
542 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
543 /****************************************************************************/
545 bce_probe(device_t dev)
548 uint16_t vid, did, svid, sdid;
550 /* Get the data for the device to be probed. */
551 vid = pci_get_vendor(dev);
552 did = pci_get_device(dev);
553 svid = pci_get_subvendor(dev);
554 sdid = pci_get_subdevice(dev);
556 /* Look through the list of known devices for a match. */
557 for (t = bce_devs; t->bce_name != NULL; ++t) {
558 if (vid == t->bce_vid && did == t->bce_did &&
559 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
560 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
561 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
564 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
566 /* Print out the device identity. */
567 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
569 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
571 device_set_desc_copy(dev, descbuf);
572 kfree(descbuf, M_TEMP);
580 /****************************************************************************/
581 /* PCI Capabilities Probe Function. */
583 /* Walks the PCI capabiites list for the device to find what features are */
588 /****************************************************************************/
590 bce_print_adapter_info(struct bce_softc *sc)
592 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
594 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
595 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
598 if (sc->bce_flags & BCE_PCIE_FLAG) {
599 kprintf("Bus (PCIe x%d, ", sc->link_width);
600 switch (sc->link_speed) {
602 kprintf("2.5Gbps); ");
608 kprintf("Unknown link speed); ");
612 kprintf("Bus (PCI%s, %s, %dMHz); ",
613 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
614 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
618 /* Firmware version and device features. */
619 kprintf("B/C (%s)", sc->bce_bc_ver);
621 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
622 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
624 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
625 kprintf("MFW[%s]", sc->bce_mfw_ver);
626 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
634 /****************************************************************************/
635 /* PCI Capabilities Probe Function. */
637 /* Walks the PCI capabiites list for the device to find what features are */
642 /****************************************************************************/
644 bce_probe_pci_caps(struct bce_softc *sc)
646 device_t dev = sc->bce_dev;
649 if (pci_is_pcix(dev))
650 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
652 ptr = pci_get_pciecap_ptr(dev);
654 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
656 sc->link_speed = link_status & 0xf;
657 sc->link_width = (link_status >> 4) & 0x3f;
658 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
659 sc->bce_flags |= BCE_PCIE_FLAG;
664 /****************************************************************************/
665 /* Device attach function. */
667 /* Allocates device resources, performs secondary chip identification, */
668 /* resets and initializes the hardware, and initializes driver instance */
672 /* 0 on success, positive value on failure. */
673 /****************************************************************************/
675 bce_attach(device_t dev)
677 struct bce_softc *sc = device_get_softc(dev);
678 struct ifnet *ifp = &sc->arpcom.ac_if;
681 void (*irq_handle)(void *);
684 struct mii_probe_args mii_args;
685 uintptr_t mii_priv = 0;
688 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
690 pci_enable_busmaster(dev);
692 bce_probe_pci_caps(sc);
694 /* Allocate PCI memory resources. */
696 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
697 RF_ACTIVE | PCI_RF_DENSE);
698 if (sc->bce_res_mem == NULL) {
699 device_printf(dev, "PCI memory allocation failed\n");
702 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
703 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
705 /* Allocate PCI IRQ resources. */
706 sc->bce_irq_type = pci_alloc_1intr(dev, bce_msi_enable,
707 &sc->bce_irq_rid, &irq_flags);
709 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
710 &sc->bce_irq_rid, irq_flags);
711 if (sc->bce_res_irq == NULL) {
712 device_printf(dev, "PCI map interrupt failed\n");
718 * Configure byte swap and enable indirect register access.
719 * Rely on CPU to do target byte swapping on big endian systems.
720 * Access to registers outside of PCI configurtion space are not
721 * valid until this is done.
723 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
724 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
725 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
727 /* Save ASIC revsion info. */
728 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
730 /* Weed out any non-production controller revisions. */
731 switch (BCE_CHIP_ID(sc)) {
732 case BCE_CHIP_ID_5706_A0:
733 case BCE_CHIP_ID_5706_A1:
734 case BCE_CHIP_ID_5708_A0:
735 case BCE_CHIP_ID_5708_B0:
736 case BCE_CHIP_ID_5709_A0:
737 case BCE_CHIP_ID_5709_B0:
738 case BCE_CHIP_ID_5709_B1:
740 /* 5709C B2 seems to work fine */
741 case BCE_CHIP_ID_5709_B2:
743 device_printf(dev, "Unsupported chip id 0x%08x!\n",
749 mii_priv |= BRGPHY_FLAG_WIRESPEED;
750 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
751 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax ||
752 BCE_CHIP_REV(sc) == BCE_CHIP_REV_Bx)
753 mii_priv |= BRGPHY_FLAG_NO_EARLYDAC;
755 mii_priv |= BRGPHY_FLAG_BER_BUG;
758 if (sc->bce_irq_type == PCI_INTR_TYPE_LEGACY) {
759 irq_handle = bce_intr_legacy;
760 } else if (sc->bce_irq_type == PCI_INTR_TYPE_MSI) {
761 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709) {
762 irq_handle = bce_intr_msi_oneshot;
763 sc->bce_flags |= BCE_ONESHOT_MSI_FLAG;
765 irq_handle = bce_intr_msi;
766 sc->bce_flags |= BCE_CHECK_MSI_FLAG;
769 panic("%s: unsupported intr type %d",
770 device_get_nameunit(dev), sc->bce_irq_type);
774 * Find the base address for shared memory access.
775 * Newer versions of bootcode use a signature and offset
776 * while older versions use a fixed address.
778 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
779 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
780 BCE_SHM_HDR_SIGNATURE_SIG) {
781 /* Multi-port devices use different offsets in shared memory. */
782 sc->bce_shmem_base = REG_RD_IND(sc,
783 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
785 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
787 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
789 /* Fetch the bootcode revision. */
790 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
791 for (i = 0, j = 0; i < 3; i++) {
795 num = (uint8_t)(val >> (24 - (i * 8)));
796 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
797 if (num >= k || !skip0 || k == 1) {
798 sc->bce_bc_ver[j++] = (num / k) + '0';
803 sc->bce_bc_ver[j++] = '.';
806 /* Check if any management firwmare is running. */
807 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
808 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
809 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
811 /* Allow time for firmware to enter the running state. */
812 for (i = 0; i < 30; i++) {
813 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
814 if (val & BCE_CONDITION_MFW_RUN_MASK)
820 /* Check the current bootcode state. */
821 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
822 BCE_CONDITION_MFW_RUN_MASK;
823 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
824 val != BCE_CONDITION_MFW_RUN_NONE) {
825 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
827 for (i = 0, j = 0; j < 3; j++) {
828 val = bce_reg_rd_ind(sc, addr + j * 4);
830 memcpy(&sc->bce_mfw_ver[i], &val, 4);
835 /* Get PCI bus information (speed and type). */
836 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
837 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
840 sc->bce_flags |= BCE_PCIX_FLAG;
842 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
843 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
845 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
846 sc->bus_speed_mhz = 133;
849 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
850 sc->bus_speed_mhz = 100;
853 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
854 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
855 sc->bus_speed_mhz = 66;
858 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
859 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
860 sc->bus_speed_mhz = 50;
863 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
864 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
865 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
866 sc->bus_speed_mhz = 33;
870 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
871 sc->bus_speed_mhz = 66;
873 sc->bus_speed_mhz = 33;
876 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
877 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
879 /* Reset the controller. */
880 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
884 /* Initialize the controller. */
885 rc = bce_chipinit(sc);
887 device_printf(dev, "Controller initialization failed!\n");
891 /* Perform NVRAM test. */
892 rc = bce_nvram_test(sc);
894 device_printf(dev, "NVRAM test failed!\n");
898 /* Fetch the permanent Ethernet MAC address. */
899 bce_get_mac_addr(sc);
902 * Trip points control how many BDs
903 * should be ready before generating an
904 * interrupt while ticks control how long
905 * a BD can sit in the chain before
906 * generating an interrupt. Set the default
907 * values for the RX and TX rings.
911 /* Force more frequent interrupts. */
912 sc->bce_tx_quick_cons_trip_int = 1;
913 sc->bce_tx_quick_cons_trip = 1;
914 sc->bce_tx_ticks_int = 0;
915 sc->bce_tx_ticks = 0;
917 sc->bce_rx_quick_cons_trip_int = 1;
918 sc->bce_rx_quick_cons_trip = 1;
919 sc->bce_rx_ticks_int = 0;
920 sc->bce_rx_ticks = 0;
922 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
923 sc->bce_tx_quick_cons_trip = bce_tx_bds;
924 sc->bce_tx_ticks_int = bce_tx_ticks_int;
925 sc->bce_tx_ticks = bce_tx_ticks;
927 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
928 sc->bce_rx_quick_cons_trip = bce_rx_bds;
929 sc->bce_rx_ticks_int = bce_rx_ticks_int;
930 sc->bce_rx_ticks = bce_rx_ticks;
934 /* Update statistics once every second. */
935 sc->bce_stats_ticks = 1000000 & 0xffff00;
937 /* Find the media type for the adapter. */
940 /* Allocate DMA memory resources. */
941 rc = bce_dma_alloc(sc);
943 device_printf(dev, "DMA resource allocation failed!\n");
947 /* Initialize the ifnet interface. */
949 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
950 ifp->if_ioctl = bce_ioctl;
951 ifp->if_start = bce_start;
952 ifp->if_init = bce_init;
953 ifp->if_watchdog = bce_watchdog;
955 ifp->if_npoll = bce_npoll;
957 ifp->if_mtu = ETHERMTU;
958 ifp->if_hwassist = BCE_CSUM_FEATURES | CSUM_TSO;
959 ifp->if_capabilities = BCE_IF_CAPABILITIES;
960 ifp->if_capenable = ifp->if_capabilities;
961 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD(sc));
962 ifq_set_ready(&ifp->if_snd);
964 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
965 ifp->if_baudrate = IF_Gbps(2.5);
967 ifp->if_baudrate = IF_Gbps(1);
969 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
970 sc->mbuf_alloc_size = MCLBYTES;
975 mii_probe_args_init(&mii_args, bce_ifmedia_upd, bce_ifmedia_sts);
976 mii_args.mii_probemask = 1 << sc->bce_phy_addr;
977 mii_args.mii_privtag = MII_PRIVTAG_BRGPHY;
978 mii_args.mii_priv = mii_priv;
980 rc = mii_probe(dev, &sc->bce_miibus, &mii_args);
982 device_printf(dev, "PHY probe failed!\n");
986 /* Attach to the Ethernet interface list. */
987 ether_ifattach(ifp, sc->eaddr, NULL);
989 callout_init_mp(&sc->bce_tick_callout);
990 callout_init_mp(&sc->bce_pulse_callout);
991 callout_init_mp(&sc->bce_ckmsi_callout);
993 /* Hookup IRQ last. */
994 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, irq_handle, sc,
995 &sc->bce_intrhand, ifp->if_serializer);
997 device_printf(dev, "Failed to setup IRQ!\n");
1002 ifp->if_cpuid = rman_get_cpuid(sc->bce_res_irq);
1003 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
1004 sc->bce_intr_cpuid = ifp->if_cpuid;
1006 /* Print some important debugging info. */
1007 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
1009 /* Add the supported sysctls to the kernel. */
1010 bce_add_sysctls(sc);
1012 #ifdef IFPOLL_ENABLE
1013 ifpoll_compat_setup(&sc->bce_npoll,
1014 &sc->bce_sysctl_ctx, sc->bce_sysctl_tree, device_get_unit(dev),
1015 ifp->if_serializer);
1019 * The chip reset earlier notified the bootcode that
1020 * a driver is present. We now need to start our pulse
1021 * routine so that the bootcode is reminded that we're
1026 /* Get the firmware running so IPMI still works */
1030 bce_print_adapter_info(sc);
1039 /****************************************************************************/
1040 /* Device detach function. */
1042 /* Stops the controller, resets the controller, and releases resources. */
1045 /* 0 on success, positive value on failure. */
1046 /****************************************************************************/
1048 bce_detach(device_t dev)
1050 struct bce_softc *sc = device_get_softc(dev);
1052 if (device_is_attached(dev)) {
1053 struct ifnet *ifp = &sc->arpcom.ac_if;
1056 /* Stop and reset the controller. */
1057 lwkt_serialize_enter(ifp->if_serializer);
1058 callout_stop(&sc->bce_pulse_callout);
1060 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1061 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1063 msg = BCE_DRV_MSG_CODE_UNLOAD;
1065 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1066 lwkt_serialize_exit(ifp->if_serializer);
1068 ether_ifdetach(ifp);
1071 /* If we have a child device on the MII bus remove it too. */
1073 device_delete_child(dev, sc->bce_miibus);
1074 bus_generic_detach(dev);
1076 if (sc->bce_res_irq != NULL) {
1077 bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
1081 if (sc->bce_irq_type == PCI_INTR_TYPE_MSI)
1082 pci_release_msi(dev);
1084 if (sc->bce_res_mem != NULL) {
1085 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1091 if (sc->bce_sysctl_tree != NULL)
1092 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1098 /****************************************************************************/
1099 /* Device shutdown function. */
1101 /* Stops and resets the controller. */
1105 /****************************************************************************/
1107 bce_shutdown(device_t dev)
1109 struct bce_softc *sc = device_get_softc(dev);
1110 struct ifnet *ifp = &sc->arpcom.ac_if;
1113 lwkt_serialize_enter(ifp->if_serializer);
1115 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1116 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1118 msg = BCE_DRV_MSG_CODE_UNLOAD;
1120 lwkt_serialize_exit(ifp->if_serializer);
1124 /****************************************************************************/
1125 /* Indirect register read. */
1127 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1128 /* configuration space. Using this mechanism avoids issues with posted */
1129 /* reads but is much slower than memory-mapped I/O. */
1132 /* The value of the register. */
1133 /****************************************************************************/
1135 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1137 device_t dev = sc->bce_dev;
1139 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1143 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1144 DBPRINT(sc, BCE_EXCESSIVE,
1145 "%s(); offset = 0x%08X, val = 0x%08X\n",
1146 __func__, offset, val);
1150 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1155 /****************************************************************************/
1156 /* Indirect register write. */
1158 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1159 /* configuration space. Using this mechanism avoids issues with posted */
1160 /* writes but is muchh slower than memory-mapped I/O. */
1164 /****************************************************************************/
1166 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1168 device_t dev = sc->bce_dev;
1170 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1171 __func__, offset, val);
1173 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1174 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1178 /****************************************************************************/
1179 /* Shared memory write. */
1181 /* Writes NetXtreme II shared memory region. */
1185 /****************************************************************************/
1187 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1189 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1193 /****************************************************************************/
1194 /* Shared memory read. */
1196 /* Reads NetXtreme II shared memory region. */
1199 /* The 32 bit value read. */
1200 /****************************************************************************/
1202 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1204 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1208 /****************************************************************************/
1209 /* Context memory write. */
1211 /* The NetXtreme II controller uses context memory to track connection */
1212 /* information for L2 and higher network protocols. */
1216 /****************************************************************************/
1218 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1221 uint32_t idx, offset = ctx_offset + cid_addr;
1222 uint32_t val, retry_cnt = 5;
1224 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1225 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1226 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1227 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1229 for (idx = 0; idx < retry_cnt; idx++) {
1230 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1231 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1236 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1237 device_printf(sc->bce_dev,
1238 "Unable to write CTX memory: "
1239 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1240 cid_addr, ctx_offset);
1243 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1244 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1249 /****************************************************************************/
1250 /* PHY register read. */
1252 /* Implements register reads on the MII bus. */
1255 /* The value of the register. */
1256 /****************************************************************************/
1258 bce_miibus_read_reg(device_t dev, int phy, int reg)
1260 struct bce_softc *sc = device_get_softc(dev);
1264 /* Make sure we are accessing the correct PHY address. */
1265 KASSERT(phy == sc->bce_phy_addr,
1266 ("invalid phyno %d, should be %d\n", phy, sc->bce_phy_addr));
1268 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1269 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1270 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1272 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1273 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1278 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1279 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1280 BCE_EMAC_MDIO_COMM_START_BUSY;
1281 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1283 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1286 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1287 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1290 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1291 val &= BCE_EMAC_MDIO_COMM_DATA;
1296 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1297 if_printf(&sc->arpcom.ac_if,
1298 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1302 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1305 DBPRINT(sc, BCE_EXCESSIVE,
1306 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1307 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1309 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1310 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1311 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1313 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1314 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1318 return (val & 0xffff);
1322 /****************************************************************************/
1323 /* PHY register write. */
1325 /* Implements register writes on the MII bus. */
1328 /* The value of the register. */
1329 /****************************************************************************/
1331 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1333 struct bce_softc *sc = device_get_softc(dev);
1337 /* Make sure we are accessing the correct PHY address. */
1338 KASSERT(phy == sc->bce_phy_addr,
1339 ("invalid phyno %d, should be %d\n", phy, sc->bce_phy_addr));
1341 DBPRINT(sc, BCE_EXCESSIVE,
1342 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1343 __func__, phy, (uint16_t)(reg & 0xffff),
1344 (uint16_t)(val & 0xffff));
1346 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1347 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1348 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1350 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1351 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1356 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1357 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1358 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1359 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1361 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1364 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1365 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1371 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1372 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1374 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1375 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1376 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1378 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1379 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1387 /****************************************************************************/
1388 /* MII bus status change. */
1390 /* Called by the MII bus driver when the PHY establishes link to set the */
1391 /* MAC interface registers. */
1395 /****************************************************************************/
1397 bce_miibus_statchg(device_t dev)
1399 struct bce_softc *sc = device_get_softc(dev);
1400 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1402 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1403 mii->mii_media_active);
1406 /* Decode the interface media flags. */
1407 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1408 switch(IFM_TYPE(mii->mii_media_active)) {
1410 kprintf("Ethernet )");
1413 kprintf("Unknown )");
1417 kprintf(" Media Options: ( ");
1418 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1420 kprintf("Autoselect )");
1423 kprintf("Manual )");
1429 kprintf("10Base-T )");
1432 kprintf("100Base-TX )");
1435 kprintf("1000Base-SX )");
1438 kprintf("1000Base-T )");
1445 kprintf(" Global Options: (");
1446 if (mii->mii_media_active & IFM_FDX)
1447 kprintf(" FullDuplex");
1448 if (mii->mii_media_active & IFM_HDX)
1449 kprintf(" HalfDuplex");
1450 if (mii->mii_media_active & IFM_LOOP)
1451 kprintf(" Loopback");
1452 if (mii->mii_media_active & IFM_FLAG0)
1454 if (mii->mii_media_active & IFM_FLAG1)
1456 if (mii->mii_media_active & IFM_FLAG2)
1461 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1464 * Set MII or GMII interface based on the speed negotiated
1467 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1468 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1469 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1470 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1472 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1473 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1477 * Set half or full duplex based on the duplicity negotiated
1480 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1481 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1482 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1484 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1485 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1490 /****************************************************************************/
1491 /* Acquire NVRAM lock. */
1493 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1494 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1495 /* for use by the driver. */
1498 /* 0 on success, positive value on failure. */
1499 /****************************************************************************/
1501 bce_acquire_nvram_lock(struct bce_softc *sc)
1506 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1508 /* Request access to the flash interface. */
1509 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1510 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1511 val = REG_RD(sc, BCE_NVM_SW_ARB);
1512 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1518 if (j >= NVRAM_TIMEOUT_COUNT) {
1519 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1526 /****************************************************************************/
1527 /* Release NVRAM lock. */
1529 /* When the caller is finished accessing NVRAM the lock must be released. */
1530 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1531 /* for use by the driver. */
1534 /* 0 on success, positive value on failure. */
1535 /****************************************************************************/
1537 bce_release_nvram_lock(struct bce_softc *sc)
1542 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1545 * Relinquish nvram interface.
1547 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1549 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1550 val = REG_RD(sc, BCE_NVM_SW_ARB);
1551 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1557 if (j >= NVRAM_TIMEOUT_COUNT) {
1558 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1565 /****************************************************************************/
1566 /* Enable NVRAM access. */
1568 /* Before accessing NVRAM for read or write operations the caller must */
1569 /* enabled NVRAM access. */
1573 /****************************************************************************/
1575 bce_enable_nvram_access(struct bce_softc *sc)
1579 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1581 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1582 /* Enable both bits, even on read. */
1583 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1584 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1588 /****************************************************************************/
1589 /* Disable NVRAM access. */
1591 /* When the caller is finished accessing NVRAM access must be disabled. */
1595 /****************************************************************************/
1597 bce_disable_nvram_access(struct bce_softc *sc)
1601 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1603 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1605 /* Disable both bits, even after read. */
1606 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1607 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1611 /****************************************************************************/
1612 /* Read a dword (32 bits) from NVRAM. */
1614 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1615 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1618 /* 0 on success and the 32 bit value read, positive value on failure. */
1619 /****************************************************************************/
1621 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1627 /* Build the command word. */
1628 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1630 /* Calculate the offset for buffered flash. */
1631 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1632 offset = ((offset / sc->bce_flash_info->page_size) <<
1633 sc->bce_flash_info->page_bits) +
1634 (offset % sc->bce_flash_info->page_size);
1638 * Clear the DONE bit separately, set the address to read,
1639 * and issue the read.
1641 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1642 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1643 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1645 /* Wait for completion. */
1646 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1651 val = REG_RD(sc, BCE_NVM_COMMAND);
1652 if (val & BCE_NVM_COMMAND_DONE) {
1653 val = REG_RD(sc, BCE_NVM_READ);
1656 memcpy(ret_val, &val, 4);
1661 /* Check for errors. */
1662 if (i >= NVRAM_TIMEOUT_COUNT) {
1663 if_printf(&sc->arpcom.ac_if,
1664 "Timeout error reading NVRAM at offset 0x%08X!\n",
1672 /****************************************************************************/
1673 /* Initialize NVRAM access. */
1675 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1676 /* access that device. */
1679 /* 0 on success, positive value on failure. */
1680 /****************************************************************************/
1682 bce_init_nvram(struct bce_softc *sc)
1685 int j, entry_count, rc = 0;
1686 const struct flash_spec *flash;
1688 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1690 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1691 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1692 sc->bce_flash_info = &flash_5709;
1693 goto bce_init_nvram_get_flash_size;
1696 /* Determine the selected interface. */
1697 val = REG_RD(sc, BCE_NVM_CFG1);
1699 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1702 * Flash reconfiguration is required to support additional
1703 * NVRAM devices not directly supported in hardware.
1704 * Check if the flash interface was reconfigured
1708 if (val & 0x40000000) {
1709 /* Flash interface reconfigured by bootcode. */
1711 DBPRINT(sc, BCE_INFO_LOAD,
1712 "%s(): Flash WAS reconfigured.\n", __func__);
1714 for (j = 0, flash = flash_table; j < entry_count;
1716 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1717 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1718 sc->bce_flash_info = flash;
1723 /* Flash interface not yet reconfigured. */
1726 DBPRINT(sc, BCE_INFO_LOAD,
1727 "%s(): Flash was NOT reconfigured.\n", __func__);
1729 if (val & (1 << 23))
1730 mask = FLASH_BACKUP_STRAP_MASK;
1732 mask = FLASH_STRAP_MASK;
1734 /* Look for the matching NVRAM device configuration data. */
1735 for (j = 0, flash = flash_table; j < entry_count;
1737 /* Check if the device matches any of the known devices. */
1738 if ((val & mask) == (flash->strapping & mask)) {
1739 /* Found a device match. */
1740 sc->bce_flash_info = flash;
1742 /* Request access to the flash interface. */
1743 rc = bce_acquire_nvram_lock(sc);
1747 /* Reconfigure the flash interface. */
1748 bce_enable_nvram_access(sc);
1749 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1750 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1751 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1752 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1753 bce_disable_nvram_access(sc);
1754 bce_release_nvram_lock(sc);
1760 /* Check if a matching device was found. */
1761 if (j == entry_count) {
1762 sc->bce_flash_info = NULL;
1763 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1767 bce_init_nvram_get_flash_size:
1768 /* Write the flash config data to the shared memory interface. */
1769 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1770 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1772 sc->bce_flash_size = val;
1774 sc->bce_flash_size = sc->bce_flash_info->total_size;
1776 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1777 __func__, sc->bce_flash_info->total_size);
1779 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1785 /****************************************************************************/
1786 /* Read an arbitrary range of data from NVRAM. */
1788 /* Prepares the NVRAM interface for access and reads the requested data */
1789 /* into the supplied buffer. */
1792 /* 0 on success and the data read, positive value on failure. */
1793 /****************************************************************************/
1795 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1798 uint32_t cmd_flags, offset32, len32, extra;
1804 /* Request access to the flash interface. */
1805 rc = bce_acquire_nvram_lock(sc);
1809 /* Enable access to flash interface */
1810 bce_enable_nvram_access(sc);
1818 /* XXX should we release nvram lock if read_dword() fails? */
1824 pre_len = 4 - (offset & 3);
1826 if (pre_len >= len32) {
1828 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1830 cmd_flags = BCE_NVM_COMMAND_FIRST;
1833 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1837 memcpy(ret_buf, buf + (offset & 3), pre_len);
1845 extra = 4 - (len32 & 3);
1846 len32 = (len32 + 4) & ~3;
1853 cmd_flags = BCE_NVM_COMMAND_LAST;
1855 cmd_flags = BCE_NVM_COMMAND_FIRST |
1856 BCE_NVM_COMMAND_LAST;
1858 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1860 memcpy(ret_buf, buf, 4 - extra);
1861 } else if (len32 > 0) {
1864 /* Read the first word. */
1868 cmd_flags = BCE_NVM_COMMAND_FIRST;
1870 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1872 /* Advance to the next dword. */
1877 while (len32 > 4 && rc == 0) {
1878 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1880 /* Advance to the next dword. */
1887 goto bce_nvram_read_locked_exit;
1889 cmd_flags = BCE_NVM_COMMAND_LAST;
1890 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1892 memcpy(ret_buf, buf, 4 - extra);
1895 bce_nvram_read_locked_exit:
1896 /* Disable access to flash interface and release the lock. */
1897 bce_disable_nvram_access(sc);
1898 bce_release_nvram_lock(sc);
1904 /****************************************************************************/
1905 /* Verifies that NVRAM is accessible and contains valid data. */
1907 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1911 /* 0 on success, positive value on failure. */
1912 /****************************************************************************/
1914 bce_nvram_test(struct bce_softc *sc)
1916 uint32_t buf[BCE_NVRAM_SIZE / 4];
1917 uint32_t magic, csum;
1918 uint8_t *data = (uint8_t *)buf;
1922 * Check that the device NVRAM is valid by reading
1923 * the magic value at offset 0.
1925 rc = bce_nvram_read(sc, 0, data, 4);
1929 magic = be32toh(buf[0]);
1930 if (magic != BCE_NVRAM_MAGIC) {
1931 if_printf(&sc->arpcom.ac_if,
1932 "Invalid NVRAM magic value! Expected: 0x%08X, "
1933 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1938 * Verify that the device NVRAM includes valid
1939 * configuration data.
1941 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1945 csum = ether_crc32_le(data, 0x100);
1946 if (csum != BCE_CRC32_RESIDUAL) {
1947 if_printf(&sc->arpcom.ac_if,
1948 "Invalid Manufacturing Information NVRAM CRC! "
1949 "Expected: 0x%08X, Found: 0x%08X\n",
1950 BCE_CRC32_RESIDUAL, csum);
1954 csum = ether_crc32_le(data + 0x100, 0x100);
1955 if (csum != BCE_CRC32_RESIDUAL) {
1956 if_printf(&sc->arpcom.ac_if,
1957 "Invalid Feature Configuration Information "
1958 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1959 BCE_CRC32_RESIDUAL, csum);
1966 /****************************************************************************/
1967 /* Identifies the current media type of the controller and sets the PHY */
1972 /****************************************************************************/
1974 bce_get_media(struct bce_softc *sc)
1978 sc->bce_phy_addr = 1;
1980 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1981 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1982 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1983 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1987 * The BCM5709S is software configurable
1988 * for Copper or SerDes operation.
1990 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1992 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1993 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1997 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1998 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
2001 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
2004 if (pci_get_function(sc->bce_dev) == 0) {
2009 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2017 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2021 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
2022 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
2025 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
2026 sc->bce_flags |= BCE_NO_WOL_FLAG;
2027 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
2028 sc->bce_phy_addr = 2;
2029 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
2030 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
2031 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
2033 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
2034 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
2035 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
2040 /****************************************************************************/
2041 /* Free any DMA memory owned by the driver. */
2043 /* Scans through each data structre that requires DMA memory and frees */
2044 /* the memory if allocated. */
2048 /****************************************************************************/
2050 bce_dma_free(struct bce_softc *sc)
2054 /* Destroy the status block. */
2055 if (sc->status_tag != NULL) {
2056 if (sc->status_block != NULL) {
2057 bus_dmamap_unload(sc->status_tag, sc->status_map);
2058 bus_dmamem_free(sc->status_tag, sc->status_block,
2061 bus_dma_tag_destroy(sc->status_tag);
2064 /* Destroy the statistics block. */
2065 if (sc->stats_tag != NULL) {
2066 if (sc->stats_block != NULL) {
2067 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2068 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2071 bus_dma_tag_destroy(sc->stats_tag);
2074 /* Destroy the CTX DMA stuffs. */
2075 if (sc->ctx_tag != NULL) {
2076 for (i = 0; i < sc->ctx_pages; i++) {
2077 if (sc->ctx_block[i] != NULL) {
2078 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2079 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2083 bus_dma_tag_destroy(sc->ctx_tag);
2086 /* Destroy the TX buffer descriptor DMA stuffs. */
2087 if (sc->tx_bd_chain_tag != NULL) {
2088 for (i = 0; i < sc->tx_pages; i++) {
2089 if (sc->tx_bd_chain[i] != NULL) {
2090 bus_dmamap_unload(sc->tx_bd_chain_tag,
2091 sc->tx_bd_chain_map[i]);
2092 bus_dmamem_free(sc->tx_bd_chain_tag,
2094 sc->tx_bd_chain_map[i]);
2097 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2100 /* Destroy the RX buffer descriptor DMA stuffs. */
2101 if (sc->rx_bd_chain_tag != NULL) {
2102 for (i = 0; i < sc->rx_pages; i++) {
2103 if (sc->rx_bd_chain[i] != NULL) {
2104 bus_dmamap_unload(sc->rx_bd_chain_tag,
2105 sc->rx_bd_chain_map[i]);
2106 bus_dmamem_free(sc->rx_bd_chain_tag,
2108 sc->rx_bd_chain_map[i]);
2111 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2114 /* Destroy the TX mbuf DMA stuffs. */
2115 if (sc->tx_mbuf_tag != NULL) {
2116 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
2117 /* Must have been unloaded in bce_stop() */
2118 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2119 bus_dmamap_destroy(sc->tx_mbuf_tag,
2120 sc->tx_mbuf_map[i]);
2122 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2125 /* Destroy the RX mbuf DMA stuffs. */
2126 if (sc->rx_mbuf_tag != NULL) {
2127 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
2128 /* Must have been unloaded in bce_stop() */
2129 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2130 bus_dmamap_destroy(sc->rx_mbuf_tag,
2131 sc->rx_mbuf_map[i]);
2133 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2134 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2137 /* Destroy the parent tag */
2138 if (sc->parent_tag != NULL)
2139 bus_dma_tag_destroy(sc->parent_tag);
2141 if (sc->tx_bd_chain_map != NULL)
2142 kfree(sc->tx_bd_chain_map, M_DEVBUF);
2143 if (sc->tx_bd_chain != NULL)
2144 kfree(sc->tx_bd_chain, M_DEVBUF);
2145 if (sc->tx_bd_chain_paddr != NULL)
2146 kfree(sc->tx_bd_chain_paddr, M_DEVBUF);
2148 if (sc->rx_bd_chain_map != NULL)
2149 kfree(sc->rx_bd_chain_map, M_DEVBUF);
2150 if (sc->rx_bd_chain != NULL)
2151 kfree(sc->rx_bd_chain, M_DEVBUF);
2152 if (sc->rx_bd_chain_paddr != NULL)
2153 kfree(sc->rx_bd_chain_paddr, M_DEVBUF);
2155 if (sc->tx_mbuf_map != NULL)
2156 kfree(sc->tx_mbuf_map, M_DEVBUF);
2157 if (sc->tx_mbuf_ptr != NULL)
2158 kfree(sc->tx_mbuf_ptr, M_DEVBUF);
2160 if (sc->rx_mbuf_map != NULL)
2161 kfree(sc->rx_mbuf_map, M_DEVBUF);
2162 if (sc->rx_mbuf_ptr != NULL)
2163 kfree(sc->rx_mbuf_ptr, M_DEVBUF);
2164 if (sc->rx_mbuf_paddr != NULL)
2165 kfree(sc->rx_mbuf_paddr, M_DEVBUF);
2169 /****************************************************************************/
2170 /* Get DMA memory from the OS. */
2172 /* Validates that the OS has provided DMA buffers in response to a */
2173 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2174 /* When the callback is used the OS will return 0 for the mapping function */
2175 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2176 /* failures back to the caller. */
2180 /****************************************************************************/
2182 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2184 bus_addr_t *busaddr = arg;
2187 * Simulate a mapping failure.
2190 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2191 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2192 __FILE__, __LINE__);
2195 /* Check for an error and signal the caller that an error occurred. */
2199 KASSERT(nseg == 1, ("only one segment is allowed"));
2200 *busaddr = segs->ds_addr;
2204 /****************************************************************************/
2205 /* Allocate any DMA memory needed by the driver. */
2207 /* Allocates DMA memory needed for the various global structures needed by */
2210 /* Memory alignment requirements: */
2211 /* -----------------+----------+----------+----------+----------+ */
2212 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2213 /* -----------------+----------+----------+----------+----------+ */
2214 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2215 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2216 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2217 /* PG Buffers | none | none | none | none | */
2218 /* TX Buffers | none | none | none | none | */
2219 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2220 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2221 /* -----------------+----------+----------+----------+----------+ */
2223 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2226 /* 0 for success, positive value for failure. */
2227 /****************************************************************************/
2229 bce_dma_alloc(struct bce_softc *sc)
2231 struct ifnet *ifp = &sc->arpcom.ac_if;
2232 int i, j, rc = 0, pages;
2233 bus_addr_t busaddr, max_busaddr;
2234 bus_size_t status_align, stats_align;
2236 pages = device_getenv_int(sc->bce_dev, "rx_pages", bce_rx_pages);
2237 if (pages <= 0 || pages > RX_PAGES_MAX || !powerof2(pages)) {
2238 device_printf(sc->bce_dev, "invalid # of RX pages\n");
2239 pages = RX_PAGES_DEFAULT;
2241 sc->rx_pages = pages;
2243 pages = device_getenv_int(sc->bce_dev, "tx_pages", bce_tx_pages);
2244 if (pages <= 0 || pages > TX_PAGES_MAX || !powerof2(pages)) {
2245 device_printf(sc->bce_dev, "invalid # of TX pages\n");
2246 pages = TX_PAGES_DEFAULT;
2248 sc->tx_pages = pages;
2250 sc->tx_bd_chain_map = kmalloc(sizeof(bus_dmamap_t) * sc->tx_pages,
2251 M_DEVBUF, M_WAITOK | M_ZERO);
2252 sc->tx_bd_chain = kmalloc(sizeof(struct tx_bd *) * sc->tx_pages,
2253 M_DEVBUF, M_WAITOK | M_ZERO);
2254 sc->tx_bd_chain_paddr = kmalloc(sizeof(bus_addr_t) * sc->tx_pages,
2255 M_DEVBUF, M_WAITOK | M_ZERO);
2257 sc->rx_bd_chain_map = kmalloc(sizeof(bus_dmamap_t) * sc->rx_pages,
2258 M_DEVBUF, M_WAITOK | M_ZERO);
2259 sc->rx_bd_chain = kmalloc(sizeof(struct rx_bd *) * sc->rx_pages,
2260 M_DEVBUF, M_WAITOK | M_ZERO);
2261 sc->rx_bd_chain_paddr = kmalloc(sizeof(bus_addr_t) * sc->rx_pages,
2262 M_DEVBUF, M_WAITOK | M_ZERO);
2264 sc->tx_mbuf_map = kmalloc(sizeof(bus_dmamap_t) * TOTAL_TX_BD(sc),
2265 M_DEVBUF, M_WAITOK | M_ZERO);
2266 sc->tx_mbuf_ptr = kmalloc(sizeof(struct mbuf *) * TOTAL_TX_BD(sc),
2267 M_DEVBUF, M_WAITOK | M_ZERO);
2269 sc->rx_mbuf_map = kmalloc(sizeof(bus_dmamap_t) * TOTAL_RX_BD(sc),
2270 M_DEVBUF, M_WAITOK | M_ZERO);
2271 sc->rx_mbuf_ptr = kmalloc(sizeof(struct mbuf *) * TOTAL_RX_BD(sc),
2272 M_DEVBUF, M_WAITOK | M_ZERO);
2273 sc->rx_mbuf_paddr = kmalloc(sizeof(bus_addr_t) * TOTAL_RX_BD(sc),
2274 M_DEVBUF, M_WAITOK | M_ZERO);
2277 * The embedded PCIe to PCI-X bridge (EPB)
2278 * in the 5708 cannot address memory above
2279 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2281 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2282 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2284 max_busaddr = BUS_SPACE_MAXADDR;
2287 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2289 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2290 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2291 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2292 if (sc->ctx_pages == 0)
2294 if (sc->ctx_pages > BCE_CTX_PAGES) {
2295 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2307 * Allocate the parent bus DMA tag appropriate for PCI.
2309 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2310 max_busaddr, BUS_SPACE_MAXADDR,
2312 BUS_SPACE_MAXSIZE_32BIT, 0,
2313 BUS_SPACE_MAXSIZE_32BIT,
2314 0, &sc->parent_tag);
2316 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2321 * Allocate status block.
2323 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2324 status_align, BCE_STATUS_BLK_SZ,
2325 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2326 &sc->status_tag, &sc->status_map,
2327 &sc->status_block_paddr);
2328 if (sc->status_block == NULL) {
2329 if_printf(ifp, "Could not allocate status block!\n");
2334 * Allocate statistics block.
2336 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2337 stats_align, BCE_STATS_BLK_SZ,
2338 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2339 &sc->stats_tag, &sc->stats_map,
2340 &sc->stats_block_paddr);
2341 if (sc->stats_block == NULL) {
2342 if_printf(ifp, "Could not allocate statistics block!\n");
2347 * Allocate context block, if needed
2349 if (sc->ctx_pages != 0) {
2350 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2351 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2353 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2356 if_printf(ifp, "Could not allocate "
2357 "context block DMA tag!\n");
2361 for (i = 0; i < sc->ctx_pages; i++) {
2362 rc = bus_dmamem_alloc(sc->ctx_tag,
2363 (void **)&sc->ctx_block[i],
2364 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2368 if_printf(ifp, "Could not allocate %dth context "
2369 "DMA memory!\n", i);
2373 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2374 sc->ctx_block[i], BCM_PAGE_SIZE,
2375 bce_dma_map_addr, &busaddr,
2378 if (rc == EINPROGRESS) {
2379 panic("%s coherent memory loading "
2380 "is still in progress!", ifp->if_xname);
2382 if_printf(ifp, "Could not map %dth context "
2383 "DMA memory!\n", i);
2384 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2386 sc->ctx_block[i] = NULL;
2389 sc->ctx_paddr[i] = busaddr;
2394 * Create a DMA tag for the TX buffer descriptor chain,
2395 * allocate and clear the memory, and fetch the
2396 * physical address of the block.
2398 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2399 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2401 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2402 0, &sc->tx_bd_chain_tag);
2404 if_printf(ifp, "Could not allocate "
2405 "TX descriptor chain DMA tag!\n");
2409 for (i = 0; i < sc->tx_pages; i++) {
2410 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2411 (void **)&sc->tx_bd_chain[i],
2412 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2414 &sc->tx_bd_chain_map[i]);
2416 if_printf(ifp, "Could not allocate %dth TX descriptor "
2417 "chain DMA memory!\n", i);
2421 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2422 sc->tx_bd_chain_map[i],
2423 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2424 bce_dma_map_addr, &busaddr,
2427 if (rc == EINPROGRESS) {
2428 panic("%s coherent memory loading "
2429 "is still in progress!", ifp->if_xname);
2431 if_printf(ifp, "Could not map %dth TX descriptor "
2432 "chain DMA memory!\n", i);
2433 bus_dmamem_free(sc->tx_bd_chain_tag,
2435 sc->tx_bd_chain_map[i]);
2436 sc->tx_bd_chain[i] = NULL;
2440 sc->tx_bd_chain_paddr[i] = busaddr;
2441 /* DRC - Fix for 64 bit systems. */
2442 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2443 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2446 /* Create a DMA tag for TX mbufs. */
2447 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2448 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2450 IP_MAXPACKET + sizeof(struct ether_vlan_header),
2451 BCE_MAX_SEGMENTS, PAGE_SIZE,
2452 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2456 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2460 /* Create DMA maps for the TX mbufs clusters. */
2461 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
2462 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2463 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2464 &sc->tx_mbuf_map[i]);
2466 for (j = 0; j < i; ++j) {
2467 bus_dmamap_destroy(sc->tx_mbuf_tag,
2468 sc->tx_mbuf_map[i]);
2470 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2471 sc->tx_mbuf_tag = NULL;
2473 if_printf(ifp, "Unable to create "
2474 "%dth TX mbuf DMA map!\n", i);
2480 * Create a DMA tag for the RX buffer descriptor chain,
2481 * allocate and clear the memory, and fetch the physical
2482 * address of the blocks.
2484 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2485 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2487 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2488 0, &sc->rx_bd_chain_tag);
2490 if_printf(ifp, "Could not allocate "
2491 "RX descriptor chain DMA tag!\n");
2495 for (i = 0; i < sc->rx_pages; i++) {
2496 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2497 (void **)&sc->rx_bd_chain[i],
2498 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2500 &sc->rx_bd_chain_map[i]);
2502 if_printf(ifp, "Could not allocate %dth RX descriptor "
2503 "chain DMA memory!\n", i);
2507 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2508 sc->rx_bd_chain_map[i],
2509 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2510 bce_dma_map_addr, &busaddr,
2513 if (rc == EINPROGRESS) {
2514 panic("%s coherent memory loading "
2515 "is still in progress!", ifp->if_xname);
2517 if_printf(ifp, "Could not map %dth RX descriptor "
2518 "chain DMA memory!\n", i);
2519 bus_dmamem_free(sc->rx_bd_chain_tag,
2521 sc->rx_bd_chain_map[i]);
2522 sc->rx_bd_chain[i] = NULL;
2526 sc->rx_bd_chain_paddr[i] = busaddr;
2527 /* DRC - Fix for 64 bit systems. */
2528 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2529 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2532 /* Create a DMA tag for RX mbufs. */
2533 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2534 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2536 MCLBYTES, 1, MCLBYTES,
2537 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2541 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2545 /* Create tmp DMA map for RX mbuf clusters. */
2546 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2547 &sc->rx_mbuf_tmpmap);
2549 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2550 sc->rx_mbuf_tag = NULL;
2552 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2556 /* Create DMA maps for the RX mbuf clusters. */
2557 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
2558 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2559 &sc->rx_mbuf_map[i]);
2561 for (j = 0; j < i; ++j) {
2562 bus_dmamap_destroy(sc->rx_mbuf_tag,
2563 sc->rx_mbuf_map[j]);
2565 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2566 sc->rx_mbuf_tag = NULL;
2568 if_printf(ifp, "Unable to create "
2569 "%dth RX mbuf DMA map!\n", i);
2577 /****************************************************************************/
2578 /* Firmware synchronization. */
2580 /* Before performing certain events such as a chip reset, synchronize with */
2581 /* the firmware first. */
2584 /* 0 for success, positive value for failure. */
2585 /****************************************************************************/
2587 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2592 /* Don't waste any time if we've timed out before. */
2593 if (sc->bce_fw_timed_out)
2596 /* Increment the message sequence number. */
2597 sc->bce_fw_wr_seq++;
2598 msg_data |= sc->bce_fw_wr_seq;
2600 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2602 /* Send the message to the bootcode driver mailbox. */
2603 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2605 /* Wait for the bootcode to acknowledge the message. */
2606 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2607 /* Check for a response in the bootcode firmware mailbox. */
2608 val = bce_shmem_rd(sc, BCE_FW_MB);
2609 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2614 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2615 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2616 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2617 if_printf(&sc->arpcom.ac_if,
2618 "Firmware synchronization timeout! "
2619 "msg_data = 0x%08X\n", msg_data);
2621 msg_data &= ~BCE_DRV_MSG_CODE;
2622 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2624 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2626 sc->bce_fw_timed_out = 1;
2633 /****************************************************************************/
2634 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2638 /****************************************************************************/
2640 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2641 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2646 for (i = 0; i < rv2p_code_len; i += 8) {
2647 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2649 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2652 if (rv2p_proc == RV2P_PROC1) {
2653 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2654 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2656 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2657 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2661 /* Reset the processor, un-stall is done later. */
2662 if (rv2p_proc == RV2P_PROC1)
2663 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2665 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2669 /****************************************************************************/
2670 /* Load RISC processor firmware. */
2672 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2673 /* associated with a particular processor. */
2677 /****************************************************************************/
2679 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2685 bce_halt_cpu(sc, cpu_reg);
2687 /* Load the Text area. */
2688 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2690 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2691 REG_WR_IND(sc, offset, fw->text[j]);
2694 /* Load the Data area. */
2695 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2697 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2698 REG_WR_IND(sc, offset, fw->data[j]);
2701 /* Load the SBSS area. */
2702 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2704 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2705 REG_WR_IND(sc, offset, fw->sbss[j]);
2708 /* Load the BSS area. */
2709 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2711 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2712 REG_WR_IND(sc, offset, fw->bss[j]);
2715 /* Load the Read-Only area. */
2716 offset = cpu_reg->spad_base +
2717 (fw->rodata_addr - cpu_reg->mips_view_base);
2719 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2720 REG_WR_IND(sc, offset, fw->rodata[j]);
2723 /* Clear the pre-fetch instruction and set the FW start address. */
2724 REG_WR_IND(sc, cpu_reg->inst, 0);
2725 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2729 /****************************************************************************/
2730 /* Starts the RISC processor. */
2732 /* Assumes the CPU starting address has already been set. */
2736 /****************************************************************************/
2738 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2742 /* Start the CPU. */
2743 val = REG_RD_IND(sc, cpu_reg->mode);
2744 val &= ~cpu_reg->mode_value_halt;
2745 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2746 REG_WR_IND(sc, cpu_reg->mode, val);
2750 /****************************************************************************/
2751 /* Halts the RISC processor. */
2755 /****************************************************************************/
2757 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2762 val = REG_RD_IND(sc, cpu_reg->mode);
2763 val |= cpu_reg->mode_value_halt;
2764 REG_WR_IND(sc, cpu_reg->mode, val);
2765 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2769 /****************************************************************************/
2770 /* Start the RX CPU. */
2774 /****************************************************************************/
2776 bce_start_rxp_cpu(struct bce_softc *sc)
2778 struct cpu_reg cpu_reg;
2780 cpu_reg.mode = BCE_RXP_CPU_MODE;
2781 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2782 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2783 cpu_reg.state = BCE_RXP_CPU_STATE;
2784 cpu_reg.state_value_clear = 0xffffff;
2785 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2786 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2787 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2788 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2789 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2790 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2791 cpu_reg.mips_view_base = 0x8000000;
2793 bce_start_cpu(sc, &cpu_reg);
2797 /****************************************************************************/
2798 /* Initialize the RX CPU. */
2802 /****************************************************************************/
2804 bce_init_rxp_cpu(struct bce_softc *sc)
2806 struct cpu_reg cpu_reg;
2809 cpu_reg.mode = BCE_RXP_CPU_MODE;
2810 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2811 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2812 cpu_reg.state = BCE_RXP_CPU_STATE;
2813 cpu_reg.state_value_clear = 0xffffff;
2814 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2815 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2816 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2817 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2818 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2819 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2820 cpu_reg.mips_view_base = 0x8000000;
2822 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2823 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2824 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2825 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2826 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2827 fw.start_addr = bce_RXP_b09FwStartAddr;
2829 fw.text_addr = bce_RXP_b09FwTextAddr;
2830 fw.text_len = bce_RXP_b09FwTextLen;
2832 fw.text = bce_RXP_b09FwText;
2834 fw.data_addr = bce_RXP_b09FwDataAddr;
2835 fw.data_len = bce_RXP_b09FwDataLen;
2837 fw.data = bce_RXP_b09FwData;
2839 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2840 fw.sbss_len = bce_RXP_b09FwSbssLen;
2842 fw.sbss = bce_RXP_b09FwSbss;
2844 fw.bss_addr = bce_RXP_b09FwBssAddr;
2845 fw.bss_len = bce_RXP_b09FwBssLen;
2847 fw.bss = bce_RXP_b09FwBss;
2849 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2850 fw.rodata_len = bce_RXP_b09FwRodataLen;
2851 fw.rodata_index = 0;
2852 fw.rodata = bce_RXP_b09FwRodata;
2854 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2855 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2856 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2857 fw.start_addr = bce_RXP_b06FwStartAddr;
2859 fw.text_addr = bce_RXP_b06FwTextAddr;
2860 fw.text_len = bce_RXP_b06FwTextLen;
2862 fw.text = bce_RXP_b06FwText;
2864 fw.data_addr = bce_RXP_b06FwDataAddr;
2865 fw.data_len = bce_RXP_b06FwDataLen;
2867 fw.data = bce_RXP_b06FwData;
2869 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2870 fw.sbss_len = bce_RXP_b06FwSbssLen;
2872 fw.sbss = bce_RXP_b06FwSbss;
2874 fw.bss_addr = bce_RXP_b06FwBssAddr;
2875 fw.bss_len = bce_RXP_b06FwBssLen;
2877 fw.bss = bce_RXP_b06FwBss;
2879 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2880 fw.rodata_len = bce_RXP_b06FwRodataLen;
2881 fw.rodata_index = 0;
2882 fw.rodata = bce_RXP_b06FwRodata;
2885 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2886 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2887 /* Delay RXP start until initialization is complete. */
2891 /****************************************************************************/
2892 /* Initialize the TX CPU. */
2896 /****************************************************************************/
2898 bce_init_txp_cpu(struct bce_softc *sc)
2900 struct cpu_reg cpu_reg;
2903 cpu_reg.mode = BCE_TXP_CPU_MODE;
2904 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2905 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2906 cpu_reg.state = BCE_TXP_CPU_STATE;
2907 cpu_reg.state_value_clear = 0xffffff;
2908 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2909 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2910 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2911 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2912 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2913 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2914 cpu_reg.mips_view_base = 0x8000000;
2916 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2917 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2918 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2919 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2920 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2921 fw.start_addr = bce_TXP_b09FwStartAddr;
2923 fw.text_addr = bce_TXP_b09FwTextAddr;
2924 fw.text_len = bce_TXP_b09FwTextLen;
2926 fw.text = bce_TXP_b09FwText;
2928 fw.data_addr = bce_TXP_b09FwDataAddr;
2929 fw.data_len = bce_TXP_b09FwDataLen;
2931 fw.data = bce_TXP_b09FwData;
2933 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2934 fw.sbss_len = bce_TXP_b09FwSbssLen;
2936 fw.sbss = bce_TXP_b09FwSbss;
2938 fw.bss_addr = bce_TXP_b09FwBssAddr;
2939 fw.bss_len = bce_TXP_b09FwBssLen;
2941 fw.bss = bce_TXP_b09FwBss;
2943 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2944 fw.rodata_len = bce_TXP_b09FwRodataLen;
2945 fw.rodata_index = 0;
2946 fw.rodata = bce_TXP_b09FwRodata;
2948 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2949 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2950 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2951 fw.start_addr = bce_TXP_b06FwStartAddr;
2953 fw.text_addr = bce_TXP_b06FwTextAddr;
2954 fw.text_len = bce_TXP_b06FwTextLen;
2956 fw.text = bce_TXP_b06FwText;
2958 fw.data_addr = bce_TXP_b06FwDataAddr;
2959 fw.data_len = bce_TXP_b06FwDataLen;
2961 fw.data = bce_TXP_b06FwData;
2963 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2964 fw.sbss_len = bce_TXP_b06FwSbssLen;
2966 fw.sbss = bce_TXP_b06FwSbss;
2968 fw.bss_addr = bce_TXP_b06FwBssAddr;
2969 fw.bss_len = bce_TXP_b06FwBssLen;
2971 fw.bss = bce_TXP_b06FwBss;
2973 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2974 fw.rodata_len = bce_TXP_b06FwRodataLen;
2975 fw.rodata_index = 0;
2976 fw.rodata = bce_TXP_b06FwRodata;
2979 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2980 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2981 bce_start_cpu(sc, &cpu_reg);
2985 /****************************************************************************/
2986 /* Initialize the TPAT CPU. */
2990 /****************************************************************************/
2992 bce_init_tpat_cpu(struct bce_softc *sc)
2994 struct cpu_reg cpu_reg;
2997 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2998 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2999 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
3000 cpu_reg.state = BCE_TPAT_CPU_STATE;
3001 cpu_reg.state_value_clear = 0xffffff;
3002 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
3003 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
3004 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
3005 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
3006 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
3007 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
3008 cpu_reg.mips_view_base = 0x8000000;
3010 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3011 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3012 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
3013 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
3014 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
3015 fw.start_addr = bce_TPAT_b09FwStartAddr;
3017 fw.text_addr = bce_TPAT_b09FwTextAddr;
3018 fw.text_len = bce_TPAT_b09FwTextLen;
3020 fw.text = bce_TPAT_b09FwText;
3022 fw.data_addr = bce_TPAT_b09FwDataAddr;
3023 fw.data_len = bce_TPAT_b09FwDataLen;
3025 fw.data = bce_TPAT_b09FwData;
3027 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
3028 fw.sbss_len = bce_TPAT_b09FwSbssLen;
3030 fw.sbss = bce_TPAT_b09FwSbss;
3032 fw.bss_addr = bce_TPAT_b09FwBssAddr;
3033 fw.bss_len = bce_TPAT_b09FwBssLen;
3035 fw.bss = bce_TPAT_b09FwBss;
3037 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
3038 fw.rodata_len = bce_TPAT_b09FwRodataLen;
3039 fw.rodata_index = 0;
3040 fw.rodata = bce_TPAT_b09FwRodata;
3042 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
3043 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
3044 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
3045 fw.start_addr = bce_TPAT_b06FwStartAddr;
3047 fw.text_addr = bce_TPAT_b06FwTextAddr;
3048 fw.text_len = bce_TPAT_b06FwTextLen;
3050 fw.text = bce_TPAT_b06FwText;
3052 fw.data_addr = bce_TPAT_b06FwDataAddr;
3053 fw.data_len = bce_TPAT_b06FwDataLen;
3055 fw.data = bce_TPAT_b06FwData;
3057 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
3058 fw.sbss_len = bce_TPAT_b06FwSbssLen;
3060 fw.sbss = bce_TPAT_b06FwSbss;
3062 fw.bss_addr = bce_TPAT_b06FwBssAddr;
3063 fw.bss_len = bce_TPAT_b06FwBssLen;
3065 fw.bss = bce_TPAT_b06FwBss;
3067 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
3068 fw.rodata_len = bce_TPAT_b06FwRodataLen;
3069 fw.rodata_index = 0;
3070 fw.rodata = bce_TPAT_b06FwRodata;
3073 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
3074 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3075 bce_start_cpu(sc, &cpu_reg);
3079 /****************************************************************************/
3080 /* Initialize the CP CPU. */
3084 /****************************************************************************/
3086 bce_init_cp_cpu(struct bce_softc *sc)
3088 struct cpu_reg cpu_reg;
3091 cpu_reg.mode = BCE_CP_CPU_MODE;
3092 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
3093 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
3094 cpu_reg.state = BCE_CP_CPU_STATE;
3095 cpu_reg.state_value_clear = 0xffffff;
3096 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
3097 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
3098 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
3099 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
3100 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
3101 cpu_reg.spad_base = BCE_CP_SCRATCH;
3102 cpu_reg.mips_view_base = 0x8000000;
3104 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3105 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3106 fw.ver_major = bce_CP_b09FwReleaseMajor;
3107 fw.ver_minor = bce_CP_b09FwReleaseMinor;
3108 fw.ver_fix = bce_CP_b09FwReleaseFix;
3109 fw.start_addr = bce_CP_b09FwStartAddr;
3111 fw.text_addr = bce_CP_b09FwTextAddr;
3112 fw.text_len = bce_CP_b09FwTextLen;
3114 fw.text = bce_CP_b09FwText;
3116 fw.data_addr = bce_CP_b09FwDataAddr;
3117 fw.data_len = bce_CP_b09FwDataLen;
3119 fw.data = bce_CP_b09FwData;
3121 fw.sbss_addr = bce_CP_b09FwSbssAddr;
3122 fw.sbss_len = bce_CP_b09FwSbssLen;
3124 fw.sbss = bce_CP_b09FwSbss;
3126 fw.bss_addr = bce_CP_b09FwBssAddr;
3127 fw.bss_len = bce_CP_b09FwBssLen;
3129 fw.bss = bce_CP_b09FwBss;
3131 fw.rodata_addr = bce_CP_b09FwRodataAddr;
3132 fw.rodata_len = bce_CP_b09FwRodataLen;
3133 fw.rodata_index = 0;
3134 fw.rodata = bce_CP_b09FwRodata;
3136 fw.ver_major = bce_CP_b06FwReleaseMajor;
3137 fw.ver_minor = bce_CP_b06FwReleaseMinor;
3138 fw.ver_fix = bce_CP_b06FwReleaseFix;
3139 fw.start_addr = bce_CP_b06FwStartAddr;
3141 fw.text_addr = bce_CP_b06FwTextAddr;
3142 fw.text_len = bce_CP_b06FwTextLen;
3144 fw.text = bce_CP_b06FwText;
3146 fw.data_addr = bce_CP_b06FwDataAddr;
3147 fw.data_len = bce_CP_b06FwDataLen;
3149 fw.data = bce_CP_b06FwData;
3151 fw.sbss_addr = bce_CP_b06FwSbssAddr;
3152 fw.sbss_len = bce_CP_b06FwSbssLen;
3154 fw.sbss = bce_CP_b06FwSbss;
3156 fw.bss_addr = bce_CP_b06FwBssAddr;
3157 fw.bss_len = bce_CP_b06FwBssLen;
3159 fw.bss = bce_CP_b06FwBss;
3161 fw.rodata_addr = bce_CP_b06FwRodataAddr;
3162 fw.rodata_len = bce_CP_b06FwRodataLen;
3163 fw.rodata_index = 0;
3164 fw.rodata = bce_CP_b06FwRodata;
3167 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
3168 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3169 bce_start_cpu(sc, &cpu_reg);
3173 /****************************************************************************/
3174 /* Initialize the COM CPU. */
3178 /****************************************************************************/
3180 bce_init_com_cpu(struct bce_softc *sc)
3182 struct cpu_reg cpu_reg;
3185 cpu_reg.mode = BCE_COM_CPU_MODE;
3186 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3187 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3188 cpu_reg.state = BCE_COM_CPU_STATE;
3189 cpu_reg.state_value_clear = 0xffffff;
3190 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3191 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3192 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3193 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3194 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3195 cpu_reg.spad_base = BCE_COM_SCRATCH;
3196 cpu_reg.mips_view_base = 0x8000000;
3198 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3199 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3200 fw.ver_major = bce_COM_b09FwReleaseMajor;
3201 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3202 fw.ver_fix = bce_COM_b09FwReleaseFix;
3203 fw.start_addr = bce_COM_b09FwStartAddr;
3205 fw.text_addr = bce_COM_b09FwTextAddr;
3206 fw.text_len = bce_COM_b09FwTextLen;
3208 fw.text = bce_COM_b09FwText;
3210 fw.data_addr = bce_COM_b09FwDataAddr;
3211 fw.data_len = bce_COM_b09FwDataLen;
3213 fw.data = bce_COM_b09FwData;
3215 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3216 fw.sbss_len = bce_COM_b09FwSbssLen;
3218 fw.sbss = bce_COM_b09FwSbss;
3220 fw.bss_addr = bce_COM_b09FwBssAddr;
3221 fw.bss_len = bce_COM_b09FwBssLen;
3223 fw.bss = bce_COM_b09FwBss;
3225 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3226 fw.rodata_len = bce_COM_b09FwRodataLen;
3227 fw.rodata_index = 0;
3228 fw.rodata = bce_COM_b09FwRodata;
3230 fw.ver_major = bce_COM_b06FwReleaseMajor;
3231 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3232 fw.ver_fix = bce_COM_b06FwReleaseFix;
3233 fw.start_addr = bce_COM_b06FwStartAddr;
3235 fw.text_addr = bce_COM_b06FwTextAddr;
3236 fw.text_len = bce_COM_b06FwTextLen;
3238 fw.text = bce_COM_b06FwText;
3240 fw.data_addr = bce_COM_b06FwDataAddr;
3241 fw.data_len = bce_COM_b06FwDataLen;
3243 fw.data = bce_COM_b06FwData;
3245 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3246 fw.sbss_len = bce_COM_b06FwSbssLen;
3248 fw.sbss = bce_COM_b06FwSbss;
3250 fw.bss_addr = bce_COM_b06FwBssAddr;
3251 fw.bss_len = bce_COM_b06FwBssLen;
3253 fw.bss = bce_COM_b06FwBss;
3255 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3256 fw.rodata_len = bce_COM_b06FwRodataLen;
3257 fw.rodata_index = 0;
3258 fw.rodata = bce_COM_b06FwRodata;
3261 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3262 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3263 bce_start_cpu(sc, &cpu_reg);
3267 /****************************************************************************/
3268 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3270 /* Loads the firmware for each CPU and starts the CPU. */
3274 /****************************************************************************/
3276 bce_init_cpus(struct bce_softc *sc)
3278 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3279 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3280 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3281 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3282 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3283 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3284 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3286 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3287 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3288 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3289 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3292 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3293 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3294 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3295 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3298 bce_init_rxp_cpu(sc);
3299 bce_init_txp_cpu(sc);
3300 bce_init_tpat_cpu(sc);
3301 bce_init_com_cpu(sc);
3302 bce_init_cp_cpu(sc);
3306 /****************************************************************************/
3307 /* Initialize context memory. */
3309 /* Clears the memory associated with each Context ID (CID). */
3313 /****************************************************************************/
3315 bce_init_ctx(struct bce_softc *sc)
3317 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3318 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3319 /* DRC: Replace this constant value with a #define. */
3320 int i, retry_cnt = 10;
3324 * BCM5709 context memory may be cached
3325 * in host memory so prepare the host memory
3328 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3330 val |= (BCM_PAGE_BITS - 8) << 16;
3331 REG_WR(sc, BCE_CTX_COMMAND, val);
3333 /* Wait for mem init command to complete. */
3334 for (i = 0; i < retry_cnt; i++) {
3335 val = REG_RD(sc, BCE_CTX_COMMAND);
3336 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3340 if (i == retry_cnt) {
3341 device_printf(sc->bce_dev,
3342 "Context memory initialization failed!\n");
3346 for (i = 0; i < sc->ctx_pages; i++) {
3350 * Set the physical address of the context
3353 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3354 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3355 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3356 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3357 BCE_ADDR_HI(sc->ctx_paddr[i]));
3358 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3359 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3362 * Verify that the context memory write was successful.
3364 for (j = 0; j < retry_cnt; j++) {
3365 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3367 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3371 if (j == retry_cnt) {
3372 device_printf(sc->bce_dev,
3373 "Failed to initialize context page!\n");
3378 uint32_t vcid_addr, offset;
3381 * For the 5706/5708, context memory is local to
3382 * the controller, so initialize the controller
3386 vcid_addr = GET_CID_ADDR(96);
3388 vcid_addr -= PHY_CTX_SIZE;
3390 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3391 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3393 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3394 CTX_WR(sc, 0x00, offset, 0);
3396 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3397 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3404 /****************************************************************************/
3405 /* Fetch the permanent MAC address of the controller. */
3409 /****************************************************************************/
3411 bce_get_mac_addr(struct bce_softc *sc)
3413 uint32_t mac_lo = 0, mac_hi = 0;
3416 * The NetXtreme II bootcode populates various NIC
3417 * power-on and runtime configuration items in a
3418 * shared memory area. The factory configured MAC
3419 * address is available from both NVRAM and the
3420 * shared memory area so we'll read the value from
3421 * shared memory for speed.
3424 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3425 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3427 if (mac_lo == 0 && mac_hi == 0) {
3428 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3430 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3431 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3432 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3433 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3434 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3435 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3438 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3442 /****************************************************************************/
3443 /* Program the MAC address. */
3447 /****************************************************************************/
3449 bce_set_mac_addr(struct bce_softc *sc)
3451 const uint8_t *mac_addr = sc->eaddr;
3454 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3457 val = (mac_addr[0] << 8) | mac_addr[1];
3458 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3460 val = (mac_addr[2] << 24) |
3461 (mac_addr[3] << 16) |
3462 (mac_addr[4] << 8) |
3464 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3468 /****************************************************************************/
3469 /* Stop the controller. */
3473 /****************************************************************************/
3475 bce_stop(struct bce_softc *sc)
3477 struct ifnet *ifp = &sc->arpcom.ac_if;
3479 ASSERT_SERIALIZED(ifp->if_serializer);
3481 callout_stop(&sc->bce_tick_callout);
3483 /* Disable the transmit/receive blocks. */
3484 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3485 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3488 bce_disable_intr(sc);
3490 /* Free the RX lists. */
3491 bce_free_rx_chain(sc);
3493 /* Free TX buffers. */
3494 bce_free_tx_chain(sc);
3497 sc->bce_coalchg_mask = 0;
3499 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3505 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3510 /* Wait for pending PCI transactions to complete. */
3511 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3512 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3513 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3514 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3515 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3516 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3520 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3521 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3522 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3523 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3524 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3527 /* Assume bootcode is running. */
3528 sc->bce_fw_timed_out = 0;
3529 sc->bce_drv_cardiac_arrest = 0;
3531 /* Give the firmware a chance to prepare for the reset. */
3532 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3534 if_printf(&sc->arpcom.ac_if,
3535 "Firmware is not ready for reset\n");
3539 /* Set a firmware reminder that this is a soft reset. */
3540 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3541 BCE_DRV_RESET_SIGNATURE_MAGIC);
3543 /* Dummy read to force the chip to complete all current transactions. */
3544 val = REG_RD(sc, BCE_MISC_ID);
3547 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3548 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3549 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3550 REG_RD(sc, BCE_MISC_COMMAND);
3553 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3554 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3556 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3558 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3559 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3560 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3561 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3563 /* Allow up to 30us for reset to complete. */
3564 for (i = 0; i < 10; i++) {
3565 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3566 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3567 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3572 /* Check that reset completed successfully. */
3573 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3574 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3575 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3580 /* Make sure byte swapping is properly configured. */
3581 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3582 if (val != 0x01020304) {
3583 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3587 /* Just completed a reset, assume that firmware is running again. */
3588 sc->bce_fw_timed_out = 0;
3589 sc->bce_drv_cardiac_arrest = 0;
3591 /* Wait for the firmware to finish its initialization. */
3592 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3594 if_printf(&sc->arpcom.ac_if,
3595 "Firmware did not complete initialization!\n");
3602 bce_chipinit(struct bce_softc *sc)
3607 /* Make sure the interrupt is not active. */
3608 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3609 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3612 * Initialize DMA byte/word swapping, configure the number of DMA
3613 * channels and PCI clock compensation delay.
3615 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3616 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3617 #if BYTE_ORDER == BIG_ENDIAN
3618 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3620 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3621 DMA_READ_CHANS << 12 |
3622 DMA_WRITE_CHANS << 16;
3624 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3626 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3627 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3630 * This setting resolves a problem observed on certain Intel PCI
3631 * chipsets that cannot handle multiple outstanding DMA operations.
3632 * See errata E9_5706A1_65.
3634 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3635 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3636 !(sc->bce_flags & BCE_PCIX_FLAG))
3637 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3639 REG_WR(sc, BCE_DMA_CONFIG, val);
3641 /* Enable the RX_V2P and Context state machines before access. */
3642 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3643 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3644 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3645 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3647 /* Initialize context mapping and zero out the quick contexts. */
3648 rc = bce_init_ctx(sc);
3652 /* Initialize the on-boards CPUs */
3655 /* Enable management frames (NC-SI) to flow to the MCP. */
3656 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3657 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) |
3658 BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3659 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3662 /* Prepare NVRAM for access. */
3663 rc = bce_init_nvram(sc);
3667 /* Set the kernel bypass block size */
3668 val = REG_RD(sc, BCE_MQ_CONFIG);
3669 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3670 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3672 /* Enable bins used on the 5709/5716. */
3673 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3674 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3675 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3676 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3677 val |= BCE_MQ_CONFIG_HALT_DIS;
3680 REG_WR(sc, BCE_MQ_CONFIG, val);
3682 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3683 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3684 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3686 /* Set the page size and clear the RV2P processor stall bits. */
3687 val = (BCM_PAGE_BITS - 8) << 24;
3688 REG_WR(sc, BCE_RV2P_CONFIG, val);
3690 /* Configure page size. */
3691 val = REG_RD(sc, BCE_TBDR_CONFIG);
3692 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3693 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3694 REG_WR(sc, BCE_TBDR_CONFIG, val);
3696 /* Set the perfect match control register to default. */
3697 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3703 /****************************************************************************/
3704 /* Initialize the controller in preparation to send/receive traffic. */
3707 /* 0 for success, positive value for failure. */
3708 /****************************************************************************/
3710 bce_blockinit(struct bce_softc *sc)
3715 /* Load the hardware default MAC address. */
3716 bce_set_mac_addr(sc);
3718 /* Set the Ethernet backoff seed value */
3719 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3720 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3721 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3723 sc->last_status_idx = 0;
3724 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3726 /* Set up link change interrupt generation. */
3727 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3729 /* Program the physical address of the status block. */
3730 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3731 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3733 /* Program the physical address of the statistics block. */
3734 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3735 BCE_ADDR_LO(sc->stats_block_paddr));
3736 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3737 BCE_ADDR_HI(sc->stats_block_paddr));
3739 /* Program various host coalescing parameters. */
3740 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3741 (sc->bce_tx_quick_cons_trip_int << 16) |
3742 sc->bce_tx_quick_cons_trip);
3743 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3744 (sc->bce_rx_quick_cons_trip_int << 16) |
3745 sc->bce_rx_quick_cons_trip);
3746 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3747 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3748 REG_WR(sc, BCE_HC_TX_TICKS,
3749 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3750 REG_WR(sc, BCE_HC_RX_TICKS,
3751 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3752 REG_WR(sc, BCE_HC_COM_TICKS,
3753 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3754 REG_WR(sc, BCE_HC_CMD_TICKS,
3755 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3756 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3757 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3759 val = BCE_HC_CONFIG_TX_TMR_MODE | BCE_HC_CONFIG_COLLECT_STATS;
3760 if (sc->bce_flags & BCE_ONESHOT_MSI_FLAG) {
3762 if_printf(&sc->arpcom.ac_if, "oneshot MSI\n");
3763 val |= BCE_HC_CONFIG_ONE_SHOT | BCE_HC_CONFIG_USE_INT_PARAM;
3765 REG_WR(sc, BCE_HC_CONFIG, val);
3767 /* Clear the internal statistics counters. */
3768 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3770 /* Verify that bootcode is running. */
3771 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
3773 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3774 if_printf(&sc->arpcom.ac_if,
3775 "%s(%d): Simulating bootcode failure.\n",
3776 __FILE__, __LINE__);
3779 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3780 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3781 if_printf(&sc->arpcom.ac_if,
3782 "Bootcode not running! Found: 0x%08X, "
3783 "Expected: 08%08X\n",
3784 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3785 BCE_DEV_INFO_SIGNATURE_MAGIC);
3790 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3791 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3792 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3793 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3794 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3797 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3798 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3800 /* Enable link state change interrupt generation. */
3801 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3803 /* Enable the RXP. */
3804 bce_start_rxp_cpu(sc);
3806 /* Disable management frames (NC-SI) from flowing to the MCP. */
3807 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3808 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
3809 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3810 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3813 /* Enable all remaining blocks in the MAC. */
3814 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3815 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3816 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3817 BCE_MISC_ENABLE_DEFAULT_XI);
3819 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
3821 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3824 /* Save the current host coalescing block settings. */
3825 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
3831 /****************************************************************************/
3832 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3834 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3835 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3839 /* 0 for success, positive value for failure. */
3840 /****************************************************************************/
3842 bce_newbuf_std(struct bce_softc *sc, uint16_t *prod, uint16_t *chain_prod,
3843 uint32_t *prod_bseq, int init)
3846 bus_dma_segment_t seg;
3850 uint16_t debug_chain_prod = *chain_prod;
3853 /* Make sure the inputs are valid. */
3854 DBRUNIF((*chain_prod > MAX_RX_BD(sc)),
3855 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3856 "RX producer out of range: 0x%04X > 0x%04X\n",
3858 *chain_prod, (uint16_t)MAX_RX_BD(sc)));
3860 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3861 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3863 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3864 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3865 "Simulating mbuf allocation failure.\n",
3866 __FILE__, __LINE__);
3867 sc->mbuf_alloc_failed++;
3870 /* This is a new mbuf allocation. */
3871 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
3874 DBRUNIF(1, sc->rx_mbuf_alloc++);
3876 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3878 /* Map the mbuf cluster into device memory. */
3879 error = bus_dmamap_load_mbuf_segment(sc->rx_mbuf_tag,
3880 sc->rx_mbuf_tmpmap, m_new, &seg, 1, &nseg,
3885 if_printf(&sc->arpcom.ac_if,
3886 "Error mapping mbuf into RX chain!\n");
3888 DBRUNIF(1, sc->rx_mbuf_alloc--);
3892 if (sc->rx_mbuf_ptr[*chain_prod] != NULL) {
3893 bus_dmamap_unload(sc->rx_mbuf_tag,
3894 sc->rx_mbuf_map[*chain_prod]);
3897 map = sc->rx_mbuf_map[*chain_prod];
3898 sc->rx_mbuf_map[*chain_prod] = sc->rx_mbuf_tmpmap;
3899 sc->rx_mbuf_tmpmap = map;
3901 /* Watch for overflow. */
3902 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD(sc)),
3903 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3904 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3905 __FILE__, __LINE__, sc->free_rx_bd,
3906 (uint16_t)USABLE_RX_BD(sc)));
3908 /* Update some debug statistic counters */
3909 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3910 sc->rx_low_watermark = sc->free_rx_bd);
3911 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3913 /* Save the mbuf and update our counter. */
3914 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3915 sc->rx_mbuf_paddr[*chain_prod] = seg.ds_addr;
3918 bce_setup_rxdesc_std(sc, *chain_prod, prod_bseq);
3920 DBRUN(BCE_VERBOSE_RECV,
3921 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3923 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3924 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3931 bce_setup_rxdesc_std(struct bce_softc *sc, uint16_t chain_prod, uint32_t *prod_bseq)
3937 paddr = sc->rx_mbuf_paddr[chain_prod];
3938 len = sc->rx_mbuf_ptr[chain_prod]->m_len;
3940 /* Setup the rx_bd for the first segment. */
3941 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
3943 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(paddr));
3944 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(paddr));
3945 rxbd->rx_bd_len = htole32(len);
3946 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3949 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3953 /****************************************************************************/
3954 /* Initialize the TX context memory. */
3958 /****************************************************************************/
3960 bce_init_tx_context(struct bce_softc *sc)
3964 /* Initialize the context ID for an L2 TX chain. */
3965 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3966 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3967 /* Set the CID type to support an L2 connection. */
3968 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3969 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
3970 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3971 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE_XI, val);
3973 /* Point the hardware to the first page in the chain. */
3974 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3975 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3976 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
3977 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3978 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3979 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
3981 /* Set the CID type to support an L2 connection. */
3982 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3983 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
3984 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3985 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
3987 /* Point the hardware to the first page in the chain. */
3988 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3989 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3990 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
3991 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3992 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3993 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
3998 /****************************************************************************/
3999 /* Allocate memory and initialize the TX data structures. */
4002 /* 0 for success, positive value for failure. */
4003 /****************************************************************************/
4005 bce_init_tx_chain(struct bce_softc *sc)
4010 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4012 /* Set the initial TX producer/consumer indices. */
4015 sc->tx_prod_bseq = 0;
4017 sc->max_tx_bd = USABLE_TX_BD(sc);
4018 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD(sc));
4019 DBRUNIF(1, sc->tx_full_count = 0);
4022 * The NetXtreme II supports a linked-list structre called
4023 * a Buffer Descriptor Chain (or BD chain). A BD chain
4024 * consists of a series of 1 or more chain pages, each of which
4025 * consists of a fixed number of BD entries.
4026 * The last BD entry on each page is a pointer to the next page
4027 * in the chain, and the last pointer in the BD chain
4028 * points back to the beginning of the chain.
4031 /* Set the TX next pointer chain entries. */
4032 for (i = 0; i < sc->tx_pages; i++) {
4035 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
4037 /* Check if we've reached the last page. */
4038 if (i == (sc->tx_pages - 1))
4043 txbd->tx_bd_haddr_hi =
4044 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
4045 txbd->tx_bd_haddr_lo =
4046 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
4048 bce_init_tx_context(sc);
4054 /****************************************************************************/
4055 /* Free memory and clear the TX data structures. */
4059 /****************************************************************************/
4061 bce_free_tx_chain(struct bce_softc *sc)
4065 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4067 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
4068 for (i = 0; i < TOTAL_TX_BD(sc); i++) {
4069 if (sc->tx_mbuf_ptr[i] != NULL) {
4070 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
4071 m_freem(sc->tx_mbuf_ptr[i]);
4072 sc->tx_mbuf_ptr[i] = NULL;
4073 DBRUNIF(1, sc->tx_mbuf_alloc--);
4077 /* Clear each TX chain page. */
4078 for (i = 0; i < sc->tx_pages; i++)
4079 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
4082 /* Check if we lost any mbufs in the process. */
4083 DBRUNIF((sc->tx_mbuf_alloc),
4084 if_printf(&sc->arpcom.ac_if,
4085 "%s(%d): Memory leak! "
4086 "Lost %d mbufs from tx chain!\n",
4087 __FILE__, __LINE__, sc->tx_mbuf_alloc));
4089 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4093 /****************************************************************************/
4094 /* Initialize the RX context memory. */
4098 /****************************************************************************/
4100 bce_init_rx_context(struct bce_softc *sc)
4104 /* Initialize the context ID for an L2 RX chain. */
4105 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
4106 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
4109 * Set the level for generating pause frames
4110 * when the number of available rx_bd's gets
4111 * too low (the low watermark) and the level
4112 * when pause frames can be stopped (the high
4115 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4116 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4117 uint32_t lo_water, hi_water;
4119 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
4120 hi_water = USABLE_RX_BD(sc) / 4;
4122 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
4123 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
4127 else if (hi_water == 0)
4130 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
4133 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
4135 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
4136 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4137 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4138 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
4139 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
4142 /* Point the hardware to the first page in the chain. */
4143 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
4144 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
4145 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
4146 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
4150 /****************************************************************************/
4151 /* Allocate memory and initialize the RX data structures. */
4154 /* 0 for success, positive value for failure. */
4155 /****************************************************************************/
4157 bce_init_rx_chain(struct bce_softc *sc)
4161 uint16_t prod, chain_prod;
4164 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4166 /* Initialize the RX producer and consumer indices. */
4169 sc->rx_prod_bseq = 0;
4170 sc->free_rx_bd = USABLE_RX_BD(sc);
4171 sc->max_rx_bd = USABLE_RX_BD(sc);
4172 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD(sc));
4173 DBRUNIF(1, sc->rx_empty_count = 0);
4175 /* Initialize the RX next pointer chain entries. */
4176 for (i = 0; i < sc->rx_pages; i++) {
4179 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
4181 /* Check if we've reached the last page. */
4182 if (i == (sc->rx_pages - 1))
4187 /* Setup the chain page pointers. */
4188 rxbd->rx_bd_haddr_hi =
4189 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
4190 rxbd->rx_bd_haddr_lo =
4191 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
4194 /* Allocate mbuf clusters for the rx_bd chain. */
4195 prod = prod_bseq = 0;
4196 while (prod < TOTAL_RX_BD(sc)) {
4197 chain_prod = RX_CHAIN_IDX(sc, prod);
4198 if (bce_newbuf_std(sc, &prod, &chain_prod, &prod_bseq, 1)) {
4199 if_printf(&sc->arpcom.ac_if,
4200 "Error filling RX chain: rx_bd[0x%04X]!\n",
4205 prod = NEXT_RX_BD(prod);
4208 /* Save the RX chain producer index. */
4210 sc->rx_prod_bseq = prod_bseq;
4212 /* Tell the chip about the waiting rx_bd's. */
4213 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4215 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4218 bce_init_rx_context(sc);
4224 /****************************************************************************/
4225 /* Free memory and clear the RX data structures. */
4229 /****************************************************************************/
4231 bce_free_rx_chain(struct bce_softc *sc)
4235 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4237 /* Free any mbufs still in the RX mbuf chain. */
4238 for (i = 0; i < TOTAL_RX_BD(sc); i++) {
4239 if (sc->rx_mbuf_ptr[i] != NULL) {
4240 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
4241 m_freem(sc->rx_mbuf_ptr[i]);
4242 sc->rx_mbuf_ptr[i] = NULL;
4243 DBRUNIF(1, sc->rx_mbuf_alloc--);
4247 /* Clear each RX chain page. */
4248 for (i = 0; i < sc->rx_pages; i++)
4249 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
4251 /* Check if we lost any mbufs in the process. */
4252 DBRUNIF((sc->rx_mbuf_alloc),
4253 if_printf(&sc->arpcom.ac_if,
4254 "%s(%d): Memory leak! "
4255 "Lost %d mbufs from rx chain!\n",
4256 __FILE__, __LINE__, sc->rx_mbuf_alloc));
4258 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4262 /****************************************************************************/
4263 /* Set media options. */
4266 /* 0 for success, positive value for failure. */
4267 /****************************************************************************/
4269 bce_ifmedia_upd(struct ifnet *ifp)
4271 struct bce_softc *sc = ifp->if_softc;
4272 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4276 * 'mii' will be NULL, when this function is called on following
4277 * code path: bce_attach() -> bce_mgmt_init()
4280 /* Make sure the MII bus has been enumerated. */
4282 if (mii->mii_instance) {
4283 struct mii_softc *miisc;
4285 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
4286 mii_phy_reset(miisc);
4288 error = mii_mediachg(mii);
4294 /****************************************************************************/
4295 /* Reports current media status. */
4299 /****************************************************************************/
4301 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
4303 struct bce_softc *sc = ifp->if_softc;
4304 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4307 ifmr->ifm_active = mii->mii_media_active;
4308 ifmr->ifm_status = mii->mii_media_status;
4312 /****************************************************************************/
4313 /* Handles PHY generated interrupt events. */
4317 /****************************************************************************/
4319 bce_phy_intr(struct bce_softc *sc)
4321 uint32_t new_link_state, old_link_state;
4322 struct ifnet *ifp = &sc->arpcom.ac_if;
4324 ASSERT_SERIALIZED(ifp->if_serializer);
4326 new_link_state = sc->status_block->status_attn_bits &
4327 STATUS_ATTN_BITS_LINK_STATE;
4328 old_link_state = sc->status_block->status_attn_bits_ack &
4329 STATUS_ATTN_BITS_LINK_STATE;
4331 /* Handle any changes if the link state has changed. */
4332 if (new_link_state != old_link_state) { /* XXX redundant? */
4333 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4335 /* Update the status_attn_bits_ack field in the status block. */
4336 if (new_link_state) {
4337 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4338 STATUS_ATTN_BITS_LINK_STATE);
4340 if_printf(ifp, "Link is now UP.\n");
4342 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4343 STATUS_ATTN_BITS_LINK_STATE);
4345 if_printf(ifp, "Link is now DOWN.\n");
4349 * Assume link is down and allow tick routine to
4350 * update the state based on the actual media state.
4353 callout_stop(&sc->bce_tick_callout);
4354 bce_tick_serialized(sc);
4357 /* Acknowledge the link change interrupt. */
4358 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4362 /****************************************************************************/
4363 /* Reads the receive consumer value from the status block (skipping over */
4364 /* chain page pointer if necessary). */
4368 /****************************************************************************/
4369 static __inline uint16_t
4370 bce_get_hw_rx_cons(struct bce_softc *sc)
4372 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
4374 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4380 /****************************************************************************/
4381 /* Handles received frame interrupt events. */
4385 /****************************************************************************/
4387 bce_rx_intr(struct bce_softc *sc, int count, uint16_t hw_cons)
4389 struct ifnet *ifp = &sc->arpcom.ac_if;
4390 uint16_t sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4391 uint32_t sw_prod_bseq;
4393 ASSERT_SERIALIZED(ifp->if_serializer);
4395 /* Get working copies of the driver's view of the RX indices. */
4396 sw_cons = sc->rx_cons;
4397 sw_prod = sc->rx_prod;
4398 sw_prod_bseq = sc->rx_prod_bseq;
4400 /* Scan through the receive chain as long as there is work to do. */
4401 while (sw_cons != hw_cons) {
4402 struct mbuf *m = NULL;
4403 struct l2_fhdr *l2fhdr = NULL;
4406 uint32_t status = 0;
4408 #ifdef IFPOLL_ENABLE
4409 if (count >= 0 && count-- == 0)
4414 * Convert the producer/consumer indices
4415 * to an actual rx_bd index.
4417 sw_chain_cons = RX_CHAIN_IDX(sc, sw_cons);
4418 sw_chain_prod = RX_CHAIN_IDX(sc, sw_prod);
4420 /* Get the used rx_bd. */
4421 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
4422 [RX_IDX(sw_chain_cons)];
4425 /* The mbuf is stored with the last rx_bd entry of a packet. */
4426 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4427 if (sw_chain_cons != sw_chain_prod) {
4428 if_printf(ifp, "RX cons(%d) != prod(%d), "
4429 "drop!\n", sw_chain_cons,
4433 bce_setup_rxdesc_std(sc, sw_chain_cons,
4436 goto bce_rx_int_next_rx;
4439 /* Unmap the mbuf from DMA space. */
4440 bus_dmamap_sync(sc->rx_mbuf_tag,
4441 sc->rx_mbuf_map[sw_chain_cons],
4442 BUS_DMASYNC_POSTREAD);
4444 /* Save the mbuf from the driver's chain. */
4445 m = sc->rx_mbuf_ptr[sw_chain_cons];
4448 * Frames received on the NetXteme II are prepended
4449 * with an l2_fhdr structure which provides status
4450 * information about the received frame (including
4451 * VLAN tags and checksum info). The frames are also
4452 * automatically adjusted to align the IP header
4453 * (i.e. two null bytes are inserted before the
4454 * Ethernet header). As a result the data DMA'd by
4455 * the controller into the mbuf is as follows:
4457 * +---------+-----+---------------------+-----+
4458 * | l2_fhdr | pad | packet data | FCS |
4459 * +---------+-----+---------------------+-----+
4461 * The l2_fhdr needs to be checked and skipped and the
4462 * FCS needs to be stripped before sending the packet
4465 l2fhdr = mtod(m, struct l2_fhdr *);
4467 len = l2fhdr->l2_fhdr_pkt_len;
4468 status = l2fhdr->l2_fhdr_status;
4470 len -= ETHER_CRC_LEN;
4472 /* Check the received frame for errors. */
4473 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4474 L2_FHDR_ERRORS_PHY_DECODE |
4475 L2_FHDR_ERRORS_ALIGNMENT |
4476 L2_FHDR_ERRORS_TOO_SHORT |
4477 L2_FHDR_ERRORS_GIANT_FRAME)) {
4480 /* Reuse the mbuf for a new frame. */
4481 bce_setup_rxdesc_std(sc, sw_chain_prod,
4484 goto bce_rx_int_next_rx;
4488 * Get a new mbuf for the rx_bd. If no new
4489 * mbufs are available then reuse the current mbuf,
4490 * log an ierror on the interface, and generate
4491 * an error in the system log.
4493 if (bce_newbuf_std(sc, &sw_prod, &sw_chain_prod,
4494 &sw_prod_bseq, 0)) {
4497 /* Try and reuse the exisitng mbuf. */
4498 bce_setup_rxdesc_std(sc, sw_chain_prod,
4501 goto bce_rx_int_next_rx;
4505 * Skip over the l2_fhdr when passing
4506 * the data up the stack.
4508 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4510 m->m_pkthdr.len = m->m_len = len;
4511 m->m_pkthdr.rcvif = ifp;
4513 /* Validate the checksum if offload enabled. */
4514 if (ifp->if_capenable & IFCAP_RXCSUM) {
4515 /* Check for an IP datagram. */
4516 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4517 m->m_pkthdr.csum_flags |=
4520 /* Check if the IP checksum is valid. */
4521 if ((l2fhdr->l2_fhdr_ip_xsum ^
4523 m->m_pkthdr.csum_flags |=
4528 /* Check for a valid TCP/UDP frame. */
4529 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4530 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4532 /* Check for a good TCP/UDP checksum. */
4534 (L2_FHDR_ERRORS_TCP_XSUM |
4535 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4536 m->m_pkthdr.csum_data =
4537 l2fhdr->l2_fhdr_tcp_udp_xsum;
4538 m->m_pkthdr.csum_flags |=
4547 sw_prod = NEXT_RX_BD(sw_prod);
4550 sw_cons = NEXT_RX_BD(sw_cons);
4552 /* If we have a packet, pass it up the stack */
4554 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4555 m->m_flags |= M_VLANTAG;
4556 m->m_pkthdr.ether_vlantag =
4557 l2fhdr->l2_fhdr_vlan_tag;
4559 ifp->if_input(ifp, m);
4563 sc->rx_cons = sw_cons;
4564 sc->rx_prod = sw_prod;
4565 sc->rx_prod_bseq = sw_prod_bseq;
4567 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4569 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4574 /****************************************************************************/
4575 /* Reads the transmit consumer value from the status block (skipping over */
4576 /* chain page pointer if necessary). */
4580 /****************************************************************************/
4581 static __inline uint16_t
4582 bce_get_hw_tx_cons(struct bce_softc *sc)
4584 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4586 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4592 /****************************************************************************/
4593 /* Handles transmit completion interrupt events. */
4597 /****************************************************************************/
4599 bce_tx_intr(struct bce_softc *sc, uint16_t hw_tx_cons)
4601 struct ifnet *ifp = &sc->arpcom.ac_if;
4602 uint16_t sw_tx_cons, sw_tx_chain_cons;
4604 ASSERT_SERIALIZED(ifp->if_serializer);
4606 /* Get the hardware's view of the TX consumer index. */
4607 sw_tx_cons = sc->tx_cons;
4609 /* Cycle through any completed TX chain page entries. */
4610 while (sw_tx_cons != hw_tx_cons) {
4611 sw_tx_chain_cons = TX_CHAIN_IDX(sc, sw_tx_cons);
4614 * Free the associated mbuf. Remember
4615 * that only the last tx_bd of a packet
4616 * has an mbuf pointer and DMA map.
4618 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4619 /* Unmap the mbuf. */
4620 bus_dmamap_unload(sc->tx_mbuf_tag,
4621 sc->tx_mbuf_map[sw_tx_chain_cons]);
4623 /* Free the mbuf. */
4624 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4625 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4631 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4634 if (sc->used_tx_bd == 0) {
4635 /* Clear the TX timeout timer. */
4639 /* Clear the tx hardware queue full flag. */
4640 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE)
4641 ifp->if_flags &= ~IFF_OACTIVE;
4642 sc->tx_cons = sw_tx_cons;
4646 /****************************************************************************/
4647 /* Disables interrupt generation. */
4651 /****************************************************************************/
4653 bce_disable_intr(struct bce_softc *sc)
4655 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4656 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4658 callout_stop(&sc->bce_ckmsi_callout);
4659 sc->bce_msi_maylose = FALSE;
4660 sc->bce_check_rx_cons = 0;
4661 sc->bce_check_tx_cons = 0;
4662 sc->bce_check_status_idx = 0xffff;
4664 sc->bce_npoll.ifpc_stcount = 0;
4666 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4670 /****************************************************************************/
4671 /* Enables interrupt generation. */
4675 /****************************************************************************/
4677 bce_enable_intr(struct bce_softc *sc)
4679 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4681 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4682 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4683 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4684 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4685 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4687 REG_WR(sc, BCE_HC_COMMAND, sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
4689 if (sc->bce_flags & BCE_CHECK_MSI_FLAG) {
4690 sc->bce_msi_maylose = FALSE;
4691 sc->bce_check_rx_cons = 0;
4692 sc->bce_check_tx_cons = 0;
4693 sc->bce_check_status_idx = 0xffff;
4696 if_printf(&sc->arpcom.ac_if, "check msi\n");
4698 callout_reset_bycpu(&sc->bce_ckmsi_callout, BCE_MSI_CKINTVL,
4699 bce_check_msi, sc, sc->bce_intr_cpuid);
4704 /****************************************************************************/
4705 /* Reenables interrupt generation during interrupt handling. */
4709 /****************************************************************************/
4711 bce_reenable_intr(struct bce_softc *sc)
4713 if (sc->bce_irq_type == PCI_INTR_TYPE_LEGACY) {
4714 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4715 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4716 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4718 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4719 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4723 /****************************************************************************/
4724 /* Handles controller initialization. */
4728 /****************************************************************************/
4732 struct bce_softc *sc = xsc;
4733 struct ifnet *ifp = &sc->arpcom.ac_if;
4737 ASSERT_SERIALIZED(ifp->if_serializer);
4739 /* Check if the driver is still running and bail out if it is. */
4740 if (ifp->if_flags & IFF_RUNNING)
4745 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4747 if_printf(ifp, "Controller reset failed!\n");
4751 error = bce_chipinit(sc);
4753 if_printf(ifp, "Controller initialization failed!\n");
4757 error = bce_blockinit(sc);
4759 if_printf(ifp, "Block initialization failed!\n");
4763 /* Load our MAC address. */
4764 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4765 bce_set_mac_addr(sc);
4767 /* Calculate and program the Ethernet MTU size. */
4768 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4770 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4773 * Program the mtu, enabling jumbo frame
4774 * support if necessary. Also set the mbuf
4775 * allocation count for RX frames.
4777 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4779 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4780 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4781 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4782 sc->mbuf_alloc_size = MJUM9BYTES;
4784 panic("jumbo buffer is not supported yet");
4787 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4788 sc->mbuf_alloc_size = MCLBYTES;
4791 /* Calculate the RX Ethernet frame size for rx_bd's. */
4792 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4794 DBPRINT(sc, BCE_INFO,
4795 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4796 "max_frame_size = %d\n",
4797 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4798 sc->max_frame_size);
4800 /* Program appropriate promiscuous/multicast filtering. */
4801 bce_set_rx_mode(sc);
4803 /* Init RX buffer descriptor chain. */
4804 bce_init_rx_chain(sc); /* XXX return value */
4806 /* Init TX buffer descriptor chain. */
4807 bce_init_tx_chain(sc); /* XXX return value */
4809 #ifdef IFPOLL_ENABLE
4810 /* Disable interrupts if we are polling. */
4811 if (ifp->if_flags & IFF_NPOLLING) {
4812 bce_disable_intr(sc);
4814 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4815 (1 << 16) | sc->bce_rx_quick_cons_trip);
4816 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4817 (1 << 16) | sc->bce_tx_quick_cons_trip);
4820 /* Enable host interrupts. */
4821 bce_enable_intr(sc);
4823 bce_ifmedia_upd(ifp);
4825 ifp->if_flags |= IFF_RUNNING;
4826 ifp->if_flags &= ~IFF_OACTIVE;
4828 callout_reset_bycpu(&sc->bce_tick_callout, hz, bce_tick, sc,
4829 sc->bce_intr_cpuid);
4836 /****************************************************************************/
4837 /* Initialize the controller just enough so that any management firmware */
4838 /* running on the device will continue to operate corectly. */
4842 /****************************************************************************/
4844 bce_mgmt_init(struct bce_softc *sc)
4846 struct ifnet *ifp = &sc->arpcom.ac_if;
4848 /* Bail out if management firmware is not running. */
4849 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4852 /* Enable all critical blocks in the MAC. */
4853 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4854 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4855 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4856 BCE_MISC_ENABLE_DEFAULT_XI);
4858 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
4860 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4863 bce_ifmedia_upd(ifp);
4867 /****************************************************************************/
4868 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4869 /* memory visible to the controller. */
4872 /* 0 for success, positive value for failure. */
4873 /****************************************************************************/
4875 bce_encap(struct bce_softc *sc, struct mbuf **m_head, int *nsegs_used)
4877 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4878 bus_dmamap_t map, tmp_map;
4879 struct mbuf *m0 = *m_head;
4880 struct tx_bd *txbd = NULL;
4881 uint16_t vlan_tag = 0, flags = 0, mss = 0;
4882 uint16_t chain_prod, chain_prod_start, prod;
4884 int i, error, maxsegs, nsegs;
4886 /* Transfer any checksum offload flags to the bd. */
4887 if (m0->m_pkthdr.csum_flags & CSUM_TSO) {
4888 error = bce_tso_setup(sc, m_head, &flags, &mss);
4892 } else if (m0->m_pkthdr.csum_flags & BCE_CSUM_FEATURES) {
4893 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4894 flags |= TX_BD_FLAGS_IP_CKSUM;
4895 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4896 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4899 /* Transfer any VLAN tags to the bd. */
4900 if (m0->m_flags & M_VLANTAG) {
4901 flags |= TX_BD_FLAGS_VLAN_TAG;
4902 vlan_tag = m0->m_pkthdr.ether_vlantag;
4906 chain_prod_start = chain_prod = TX_CHAIN_IDX(sc, prod);
4908 /* Map the mbuf into DMAable memory. */
4909 map = sc->tx_mbuf_map[chain_prod_start];
4911 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4912 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4913 ("not enough segments %d", maxsegs));
4914 if (maxsegs > BCE_MAX_SEGMENTS)
4915 maxsegs = BCE_MAX_SEGMENTS;
4917 /* Map the mbuf into our DMA address space. */
4918 error = bus_dmamap_load_mbuf_defrag(sc->tx_mbuf_tag, map, m_head,
4919 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
4922 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4924 *nsegs_used += nsegs;
4929 /* prod points to an empty tx_bd at this point. */
4930 prod_bseq = sc->tx_prod_bseq;
4933 * Cycle through each mbuf segment that makes up
4934 * the outgoing frame, gathering the mapping info
4935 * for that segment and creating a tx_bd to for
4938 for (i = 0; i < nsegs; i++) {
4939 chain_prod = TX_CHAIN_IDX(sc, prod);
4940 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4942 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4943 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4944 txbd->tx_bd_mss_nbytes = htole32(mss << 16) |
4945 htole16(segs[i].ds_len);
4946 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4947 txbd->tx_bd_flags = htole16(flags);
4949 prod_bseq += segs[i].ds_len;
4951 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4952 prod = NEXT_TX_BD(prod);
4955 /* Set the END flag on the last TX buffer descriptor. */
4956 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4959 * Ensure that the mbuf pointer for this transmission
4960 * is placed at the array index of the last
4961 * descriptor in this chain. This is done
4962 * because a single map is used for all
4963 * segments of the mbuf and we don't want to
4964 * unload the map before all of the segments
4967 sc->tx_mbuf_ptr[chain_prod] = m0;
4969 tmp_map = sc->tx_mbuf_map[chain_prod];
4970 sc->tx_mbuf_map[chain_prod] = map;
4971 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
4973 sc->used_tx_bd += nsegs;
4975 /* prod points to the next free tx_bd at this point. */
4977 sc->tx_prod_bseq = prod_bseq;
4987 /****************************************************************************/
4988 /* Main transmit routine when called from another routine with a lock. */
4992 /****************************************************************************/
4994 bce_start(struct ifnet *ifp)
4996 struct bce_softc *sc = ifp->if_softc;
4999 ASSERT_SERIALIZED(ifp->if_serializer);
5001 /* If there's no link or the transmit queue is empty then just exit. */
5002 if (!sc->bce_link) {
5003 ifq_purge(&ifp->if_snd);
5007 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
5011 struct mbuf *m_head;
5014 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
5017 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
5018 ifp->if_flags |= IFF_OACTIVE;
5022 /* Check for any frames to send. */
5023 m_head = ifq_dequeue(&ifp->if_snd, NULL);
5028 * Pack the data into the transmit ring. If we
5029 * don't have room, place the mbuf back at the
5030 * head of the queue and set the OACTIVE flag
5031 * to wait for the NIC to drain the chain.
5033 if (bce_encap(sc, &m_head, &count)) {
5035 if (sc->used_tx_bd == 0) {
5038 ifp->if_flags |= IFF_OACTIVE;
5043 if (count >= sc->tx_wreg) {
5044 /* Start the transmit. */
5045 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) +
5046 BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
5047 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) +
5048 BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
5052 /* Send a copy of the frame to any BPF listeners. */
5053 ETHER_BPF_MTAP(ifp, m_head);
5055 /* Set the tx timeout. */
5056 ifp->if_timer = BCE_TX_TIMEOUT;
5059 /* Start the transmit. */
5060 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BIDX,
5062 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BSEQ,
5068 /****************************************************************************/
5069 /* Handles any IOCTL calls from the operating system. */
5072 /* 0 for success, positive value for failure. */
5073 /****************************************************************************/
5075 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
5077 struct bce_softc *sc = ifp->if_softc;
5078 struct ifreq *ifr = (struct ifreq *)data;
5079 struct mii_data *mii;
5080 int mask, error = 0;
5082 ASSERT_SERIALIZED(ifp->if_serializer);
5086 /* Check that the MTU setting is supported. */
5087 if (ifr->ifr_mtu < BCE_MIN_MTU ||
5089 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
5091 ifr->ifr_mtu > ETHERMTU
5098 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
5100 ifp->if_mtu = ifr->ifr_mtu;
5101 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5106 if (ifp->if_flags & IFF_UP) {
5107 if (ifp->if_flags & IFF_RUNNING) {
5108 mask = ifp->if_flags ^ sc->bce_if_flags;
5110 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
5111 bce_set_rx_mode(sc);
5115 } else if (ifp->if_flags & IFF_RUNNING) {
5118 /* If MFW is running, restart the controller a bit. */
5119 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5120 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
5125 sc->bce_if_flags = ifp->if_flags;
5130 if (ifp->if_flags & IFF_RUNNING)
5131 bce_set_rx_mode(sc);
5136 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
5138 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
5140 mii = device_get_softc(sc->bce_miibus);
5141 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
5145 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
5146 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
5149 if (mask & IFCAP_HWCSUM) {
5150 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
5151 if (ifp->if_capenable & IFCAP_TXCSUM)
5152 ifp->if_hwassist |= BCE_CSUM_FEATURES;
5154 ifp->if_hwassist &= ~BCE_CSUM_FEATURES;
5156 if (mask & IFCAP_TSO) {
5157 ifp->if_capenable ^= IFCAP_TSO;
5158 if (ifp->if_capenable & IFCAP_TSO)
5159 ifp->if_hwassist |= CSUM_TSO;
5161 ifp->if_hwassist &= ~CSUM_TSO;
5166 error = ether_ioctl(ifp, command, data);
5173 /****************************************************************************/
5174 /* Transmit timeout handler. */
5178 /****************************************************************************/
5180 bce_watchdog(struct ifnet *ifp)
5182 struct bce_softc *sc = ifp->if_softc;
5184 ASSERT_SERIALIZED(ifp->if_serializer);
5186 DBRUN(BCE_VERBOSE_SEND,
5187 bce_dump_driver_state(sc);
5188 bce_dump_status_block(sc));
5191 * If we are in this routine because of pause frames, then
5192 * don't reset the hardware.
5194 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
5197 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
5199 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5201 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5206 if (!ifq_is_empty(&ifp->if_snd))
5211 #ifdef IFPOLL_ENABLE
5214 bce_npoll_compat(struct ifnet *ifp, void *arg __unused, int count)
5216 struct bce_softc *sc = ifp->if_softc;
5217 struct status_block *sblk = sc->status_block;
5218 uint16_t hw_tx_cons, hw_rx_cons;
5220 ASSERT_SERIALIZED(ifp->if_serializer);
5223 * Save the status block index value for use when enabling
5226 sc->last_status_idx = sblk->status_idx;
5228 /* Make sure status index is extracted before rx/tx cons */
5231 if (sc->bce_npoll.ifpc_stcount-- == 0) {
5232 uint32_t status_attn_bits;
5234 sc->bce_npoll.ifpc_stcount = sc->bce_npoll.ifpc_stfrac;
5236 status_attn_bits = sblk->status_attn_bits;
5238 /* Was it a link change interrupt? */
5239 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5240 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
5244 * Clear any transient status updates during link state change.
5246 REG_WR(sc, BCE_HC_COMMAND,
5247 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5248 REG_RD(sc, BCE_HC_COMMAND);
5251 * If any other attention is asserted then the chip is toast.
5253 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5254 (sblk->status_attn_bits_ack &
5255 ~STATUS_ATTN_BITS_LINK_STATE)) {
5256 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5257 sblk->status_attn_bits);
5263 hw_rx_cons = bce_get_hw_rx_cons(sc);
5264 hw_tx_cons = bce_get_hw_tx_cons(sc);
5266 /* Check for any completed RX frames. */
5267 if (hw_rx_cons != sc->rx_cons)
5268 bce_rx_intr(sc, count, hw_rx_cons);
5270 /* Check for any completed TX frames. */
5271 if (hw_tx_cons != sc->tx_cons)
5272 bce_tx_intr(sc, hw_tx_cons);
5274 /* Check for new frames to transmit. */
5275 if (!ifq_is_empty(&ifp->if_snd))
5280 bce_npoll(struct ifnet *ifp, struct ifpoll_info *info)
5282 struct bce_softc *sc = ifp->if_softc;
5284 ASSERT_SERIALIZED(ifp->if_serializer);
5287 int cpuid = sc->bce_npoll.ifpc_cpuid;
5289 info->ifpi_rx[cpuid].poll_func = bce_npoll_compat;
5290 info->ifpi_rx[cpuid].arg = NULL;
5291 info->ifpi_rx[cpuid].serializer = ifp->if_serializer;
5293 if (ifp->if_flags & IFF_RUNNING) {
5294 bce_disable_intr(sc);
5296 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5297 (1 << 16) | sc->bce_rx_quick_cons_trip);
5298 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5299 (1 << 16) | sc->bce_tx_quick_cons_trip);
5301 ifp->if_npoll_cpuid = cpuid;
5303 if (ifp->if_flags & IFF_RUNNING) {
5304 bce_enable_intr(sc);
5306 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
5307 (sc->bce_tx_quick_cons_trip_int << 16) |
5308 sc->bce_tx_quick_cons_trip);
5309 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
5310 (sc->bce_rx_quick_cons_trip_int << 16) |
5311 sc->bce_rx_quick_cons_trip);
5313 ifp->if_npoll_cpuid = -1;
5317 #endif /* IFPOLL_ENABLE */
5321 * Interrupt handler.
5323 /****************************************************************************/
5324 /* Main interrupt entry point. Verifies that the controller generated the */
5325 /* interrupt and then calls a separate routine for handle the various */
5326 /* interrupt causes (PHY, TX, RX). */
5329 /* 0 for success, positive value for failure. */
5330 /****************************************************************************/
5332 bce_intr(struct bce_softc *sc)
5334 struct ifnet *ifp = &sc->arpcom.ac_if;
5335 struct status_block *sblk;
5336 uint16_t hw_rx_cons, hw_tx_cons;
5337 uint32_t status_attn_bits;
5339 ASSERT_SERIALIZED(ifp->if_serializer);
5341 sblk = sc->status_block;
5344 * Save the status block index value for use during
5345 * the next interrupt.
5347 sc->last_status_idx = sblk->status_idx;
5349 /* Make sure status index is extracted before rx/tx cons */
5352 /* Check if the hardware has finished any work. */
5353 hw_rx_cons = bce_get_hw_rx_cons(sc);
5354 hw_tx_cons = bce_get_hw_tx_cons(sc);
5356 status_attn_bits = sblk->status_attn_bits;
5358 /* Was it a link change interrupt? */
5359 if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5360 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5364 * Clear any transient status updates during link state
5367 REG_WR(sc, BCE_HC_COMMAND,
5368 sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT);
5369 REG_RD(sc, BCE_HC_COMMAND);
5373 * If any other attention is asserted then
5374 * the chip is toast.
5376 if ((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) !=
5377 (sblk->status_attn_bits_ack & ~STATUS_ATTN_BITS_LINK_STATE)) {
5378 if_printf(ifp, "Fatal attention detected: 0x%08X\n",
5379 sblk->status_attn_bits);
5384 /* Check for any completed RX frames. */
5385 if (hw_rx_cons != sc->rx_cons)
5386 bce_rx_intr(sc, -1, hw_rx_cons);
5388 /* Check for any completed TX frames. */
5389 if (hw_tx_cons != sc->tx_cons)
5390 bce_tx_intr(sc, hw_tx_cons);
5392 /* Re-enable interrupts. */
5393 bce_reenable_intr(sc);
5395 if (sc->bce_coalchg_mask)
5396 bce_coal_change(sc);
5398 /* Handle any frames that arrived while handling the interrupt. */
5399 if (!ifq_is_empty(&ifp->if_snd))
5404 bce_intr_legacy(void *xsc)
5406 struct bce_softc *sc = xsc;
5407 struct status_block *sblk;
5409 sblk = sc->status_block;
5412 * If the hardware status block index matches the last value
5413 * read by the driver and we haven't asserted our interrupt
5414 * then there's nothing to do.
5416 if (sblk->status_idx == sc->last_status_idx &&
5417 (REG_RD(sc, BCE_PCICFG_MISC_STATUS) &
5418 BCE_PCICFG_MISC_STATUS_INTA_VALUE))
5421 /* Ack the interrupt and stop others from occuring. */
5422 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5423 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5424 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5427 * Read back to deassert IRQ immediately to avoid too
5428 * many spurious interrupts.
5430 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
5436 bce_intr_msi(void *xsc)
5438 struct bce_softc *sc = xsc;
5440 /* Ack the interrupt and stop others from occuring. */
5441 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
5442 BCE_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
5443 BCE_PCICFG_INT_ACK_CMD_MASK_INT);
5449 bce_intr_msi_oneshot(void *xsc)
5455 /****************************************************************************/
5456 /* Programs the various packet receive modes (broadcast and multicast). */
5460 /****************************************************************************/
5462 bce_set_rx_mode(struct bce_softc *sc)
5464 struct ifnet *ifp = &sc->arpcom.ac_if;
5465 struct ifmultiaddr *ifma;
5466 uint32_t hashes[NUM_MC_HASH_REGISTERS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5467 uint32_t rx_mode, sort_mode;
5470 ASSERT_SERIALIZED(ifp->if_serializer);
5472 /* Initialize receive mode default settings. */
5473 rx_mode = sc->rx_mode &
5474 ~(BCE_EMAC_RX_MODE_PROMISCUOUS |
5475 BCE_EMAC_RX_MODE_KEEP_VLAN_TAG);
5476 sort_mode = 1 | BCE_RPM_SORT_USER0_BC_EN;
5479 * ASF/IPMI/UMP firmware requires that VLAN tag stripping
5482 if (!(BCE_IF_CAPABILITIES & IFCAP_VLAN_HWTAGGING) &&
5483 !(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
5484 rx_mode |= BCE_EMAC_RX_MODE_KEEP_VLAN_TAG;
5487 * Check for promiscuous, all multicast, or selected
5488 * multicast address filtering.
5490 if (ifp->if_flags & IFF_PROMISC) {
5491 DBPRINT(sc, BCE_INFO, "Enabling promiscuous mode.\n");
5493 /* Enable promiscuous mode. */
5494 rx_mode |= BCE_EMAC_RX_MODE_PROMISCUOUS;
5495 sort_mode |= BCE_RPM_SORT_USER0_PROM_EN;
5496 } else if (ifp->if_flags & IFF_ALLMULTI) {
5497 DBPRINT(sc, BCE_INFO, "Enabling all multicast mode.\n");
5499 /* Enable all multicast addresses. */
5500 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5501 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5504 sort_mode |= BCE_RPM_SORT_USER0_MC_EN;
5506 /* Accept one or more multicast(s). */
5507 DBPRINT(sc, BCE_INFO, "Enabling selective multicast mode.\n");
5509 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
5510 if (ifma->ifma_addr->sa_family != AF_LINK)
5513 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
5514 ETHER_ADDR_LEN) & 0xFF;
5515 hashes[(h & 0xE0) >> 5] |= 1 << (h & 0x1F);
5518 for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
5519 REG_WR(sc, BCE_EMAC_MULTICAST_HASH0 + (i * 4),
5522 sort_mode |= BCE_RPM_SORT_USER0_MC_HSH_EN;
5525 /* Only make changes if the recive mode has actually changed. */
5526 if (rx_mode != sc->rx_mode) {
5527 DBPRINT(sc, BCE_VERBOSE, "Enabling new receive mode: 0x%08X\n",
5530 sc->rx_mode = rx_mode;
5531 REG_WR(sc, BCE_EMAC_RX_MODE, rx_mode);
5534 /* Disable and clear the exisitng sort before enabling a new sort. */
5535 REG_WR(sc, BCE_RPM_SORT_USER0, 0x0);
5536 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode);
5537 REG_WR(sc, BCE_RPM_SORT_USER0, sort_mode | BCE_RPM_SORT_USER0_ENA);
5541 /****************************************************************************/
5542 /* Called periodically to updates statistics from the controllers */
5543 /* statistics block. */
5547 /****************************************************************************/
5549 bce_stats_update(struct bce_softc *sc)
5551 struct ifnet *ifp = &sc->arpcom.ac_if;
5552 struct statistics_block *stats = sc->stats_block;
5554 DBPRINT(sc, BCE_EXCESSIVE, "Entering %s()\n", __func__);
5556 ASSERT_SERIALIZED(ifp->if_serializer);
5559 * Certain controllers don't report carrier sense errors correctly.
5560 * See errata E11_5708CA0_1165.
5562 if (!(BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) &&
5563 !(BCE_CHIP_ID(sc) == BCE_CHIP_ID_5708_A0)) {
5565 (u_long)stats->stat_Dot3StatsCarrierSenseErrors;
5569 * Update the sysctl statistics from the hardware statistics.
5571 sc->stat_IfHCInOctets =
5572 ((uint64_t)stats->stat_IfHCInOctets_hi << 32) +
5573 (uint64_t)stats->stat_IfHCInOctets_lo;
5575 sc->stat_IfHCInBadOctets =
5576 ((uint64_t)stats->stat_IfHCInBadOctets_hi << 32) +
5577 (uint64_t)stats->stat_IfHCInBadOctets_lo;
5579 sc->stat_IfHCOutOctets =
5580 ((uint64_t)stats->stat_IfHCOutOctets_hi << 32) +
5581 (uint64_t)stats->stat_IfHCOutOctets_lo;
5583 sc->stat_IfHCOutBadOctets =
5584 ((uint64_t)stats->stat_IfHCOutBadOctets_hi << 32) +
5585 (uint64_t)stats->stat_IfHCOutBadOctets_lo;
5587 sc->stat_IfHCInUcastPkts =
5588 ((uint64_t)stats->stat_IfHCInUcastPkts_hi << 32) +
5589 (uint64_t)stats->stat_IfHCInUcastPkts_lo;
5591 sc->stat_IfHCInMulticastPkts =
5592 ((uint64_t)stats->stat_IfHCInMulticastPkts_hi << 32) +
5593 (uint64_t)stats->stat_IfHCInMulticastPkts_lo;
5595 sc->stat_IfHCInBroadcastPkts =
5596 ((uint64_t)stats->stat_IfHCInBroadcastPkts_hi << 32) +
5597 (uint64_t)stats->stat_IfHCInBroadcastPkts_lo;
5599 sc->stat_IfHCOutUcastPkts =
5600 ((uint64_t)stats->stat_IfHCOutUcastPkts_hi << 32) +
5601 (uint64_t)stats->stat_IfHCOutUcastPkts_lo;
5603 sc->stat_IfHCOutMulticastPkts =
5604 ((uint64_t)stats->stat_IfHCOutMulticastPkts_hi << 32) +
5605 (uint64_t)stats->stat_IfHCOutMulticastPkts_lo;
5607 sc->stat_IfHCOutBroadcastPkts =
5608 ((uint64_t)stats->stat_IfHCOutBroadcastPkts_hi << 32) +
5609 (uint64_t)stats->stat_IfHCOutBroadcastPkts_lo;
5611 sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors =
5612 stats->stat_emac_tx_stat_dot3statsinternalmactransmiterrors;
5614 sc->stat_Dot3StatsCarrierSenseErrors =
5615 stats->stat_Dot3StatsCarrierSenseErrors;
5617 sc->stat_Dot3StatsFCSErrors =
5618 stats->stat_Dot3StatsFCSErrors;
5620 sc->stat_Dot3StatsAlignmentErrors =
5621 stats->stat_Dot3StatsAlignmentErrors;
5623 sc->stat_Dot3StatsSingleCollisionFrames =
5624 stats->stat_Dot3StatsSingleCollisionFrames;
5626 sc->stat_Dot3StatsMultipleCollisionFrames =
5627 stats->stat_Dot3StatsMultipleCollisionFrames;
5629 sc->stat_Dot3StatsDeferredTransmissions =
5630 stats->stat_Dot3StatsDeferredTransmissions;
5632 sc->stat_Dot3StatsExcessiveCollisions =
5633 stats->stat_Dot3StatsExcessiveCollisions;
5635 sc->stat_Dot3StatsLateCollisions =
5636 stats->stat_Dot3StatsLateCollisions;
5638 sc->stat_EtherStatsCollisions =
5639 stats->stat_EtherStatsCollisions;
5641 sc->stat_EtherStatsFragments =
5642 stats->stat_EtherStatsFragments;
5644 sc->stat_EtherStatsJabbers =
5645 stats->stat_EtherStatsJabbers;
5647 sc->stat_EtherStatsUndersizePkts =
5648 stats->stat_EtherStatsUndersizePkts;
5650 sc->stat_EtherStatsOverrsizePkts =
5651 stats->stat_EtherStatsOverrsizePkts;
5653 sc->stat_EtherStatsPktsRx64Octets =
5654 stats->stat_EtherStatsPktsRx64Octets;
5656 sc->stat_EtherStatsPktsRx65Octetsto127Octets =
5657 stats->stat_EtherStatsPktsRx65Octetsto127Octets;
5659 sc->stat_EtherStatsPktsRx128Octetsto255Octets =
5660 stats->stat_EtherStatsPktsRx128Octetsto255Octets;
5662 sc->stat_EtherStatsPktsRx256Octetsto511Octets =
5663 stats->stat_EtherStatsPktsRx256Octetsto511Octets;
5665 sc->stat_EtherStatsPktsRx512Octetsto1023Octets =
5666 stats->stat_EtherStatsPktsRx512Octetsto1023Octets;
5668 sc->stat_EtherStatsPktsRx1024Octetsto1522Octets =
5669 stats->stat_EtherStatsPktsRx1024Octetsto1522Octets;
5671 sc->stat_EtherStatsPktsRx1523Octetsto9022Octets =
5672 stats->stat_EtherStatsPktsRx1523Octetsto9022Octets;
5674 sc->stat_EtherStatsPktsTx64Octets =
5675 stats->stat_EtherStatsPktsTx64Octets;
5677 sc->stat_EtherStatsPktsTx65Octetsto127Octets =
5678 stats->stat_EtherStatsPktsTx65Octetsto127Octets;
5680 sc->stat_EtherStatsPktsTx128Octetsto255Octets =
5681 stats->stat_EtherStatsPktsTx128Octetsto255Octets;
5683 sc->stat_EtherStatsPktsTx256Octetsto511Octets =
5684 stats->stat_EtherStatsPktsTx256Octetsto511Octets;
5686 sc->stat_EtherStatsPktsTx512Octetsto1023Octets =
5687 stats->stat_EtherStatsPktsTx512Octetsto1023Octets;
5689 sc->stat_EtherStatsPktsTx1024Octetsto1522Octets =
5690 stats->stat_EtherStatsPktsTx1024Octetsto1522Octets;
5692 sc->stat_EtherStatsPktsTx1523Octetsto9022Octets =
5693 stats->stat_EtherStatsPktsTx1523Octetsto9022Octets;
5695 sc->stat_XonPauseFramesReceived =
5696 stats->stat_XonPauseFramesReceived;
5698 sc->stat_XoffPauseFramesReceived =
5699 stats->stat_XoffPauseFramesReceived;
5701 sc->stat_OutXonSent =
5702 stats->stat_OutXonSent;
5704 sc->stat_OutXoffSent =
5705 stats->stat_OutXoffSent;
5707 sc->stat_FlowControlDone =
5708 stats->stat_FlowControlDone;
5710 sc->stat_MacControlFramesReceived =
5711 stats->stat_MacControlFramesReceived;
5713 sc->stat_XoffStateEntered =
5714 stats->stat_XoffStateEntered;
5716 sc->stat_IfInFramesL2FilterDiscards =
5717 stats->stat_IfInFramesL2FilterDiscards;
5719 sc->stat_IfInRuleCheckerDiscards =
5720 stats->stat_IfInRuleCheckerDiscards;
5722 sc->stat_IfInFTQDiscards =
5723 stats->stat_IfInFTQDiscards;
5725 sc->stat_IfInMBUFDiscards =
5726 stats->stat_IfInMBUFDiscards;
5728 sc->stat_IfInRuleCheckerP4Hit =
5729 stats->stat_IfInRuleCheckerP4Hit;
5731 sc->stat_CatchupInRuleCheckerDiscards =
5732 stats->stat_CatchupInRuleCheckerDiscards;
5734 sc->stat_CatchupInFTQDiscards =
5735 stats->stat_CatchupInFTQDiscards;
5737 sc->stat_CatchupInMBUFDiscards =
5738 stats->stat_CatchupInMBUFDiscards;
5740 sc->stat_CatchupInRuleCheckerP4Hit =
5741 stats->stat_CatchupInRuleCheckerP4Hit;
5743 sc->com_no_buffers = REG_RD_IND(sc, 0x120084);
5746 * Update the interface statistics from the
5747 * hardware statistics.
5749 ifp->if_collisions = (u_long)sc->stat_EtherStatsCollisions;
5751 ifp->if_ierrors = (u_long)sc->stat_EtherStatsUndersizePkts +
5752 (u_long)sc->stat_EtherStatsOverrsizePkts +
5753 (u_long)sc->stat_IfInMBUFDiscards +
5754 (u_long)sc->stat_Dot3StatsAlignmentErrors +
5755 (u_long)sc->stat_Dot3StatsFCSErrors +
5756 (u_long)sc->stat_IfInRuleCheckerDiscards +
5757 (u_long)sc->stat_IfInFTQDiscards +
5758 (u_long)sc->com_no_buffers;
5761 (u_long)sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors +
5762 (u_long)sc->stat_Dot3StatsExcessiveCollisions +
5763 (u_long)sc->stat_Dot3StatsLateCollisions;
5765 DBPRINT(sc, BCE_EXCESSIVE, "Exiting %s()\n", __func__);
5769 /****************************************************************************/
5770 /* Periodic function to notify the bootcode that the driver is still */
5775 /****************************************************************************/
5777 bce_pulse(void *xsc)
5779 struct bce_softc *sc = xsc;
5780 struct ifnet *ifp = &sc->arpcom.ac_if;
5783 lwkt_serialize_enter(ifp->if_serializer);
5785 /* Tell the firmware that the driver is still running. */
5786 msg = (uint32_t)++sc->bce_fw_drv_pulse_wr_seq;
5787 bce_shmem_wr(sc, BCE_DRV_PULSE_MB, msg);
5789 /* Update the bootcode condition. */
5790 sc->bc_state = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
5792 /* Report whether the bootcode still knows the driver is running. */
5793 if (!sc->bce_drv_cardiac_arrest) {
5794 if (!(sc->bc_state & BCE_CONDITION_DRV_PRESENT)) {
5795 sc->bce_drv_cardiac_arrest = 1;
5796 if_printf(ifp, "Bootcode lost the driver pulse! "
5797 "(bc_state = 0x%08X)\n", sc->bc_state);
5801 * Not supported by all bootcode versions.
5802 * (v5.0.11+ and v5.2.1+) Older bootcode
5803 * will require the driver to reset the
5804 * controller to clear this condition.
5806 if (sc->bc_state & BCE_CONDITION_DRV_PRESENT) {
5807 sc->bce_drv_cardiac_arrest = 0;
5808 if_printf(ifp, "Bootcode found the driver pulse! "
5809 "(bc_state = 0x%08X)\n", sc->bc_state);
5813 /* Schedule the next pulse. */
5814 callout_reset_bycpu(&sc->bce_pulse_callout, hz, bce_pulse, sc,
5815 sc->bce_intr_cpuid);
5817 lwkt_serialize_exit(ifp->if_serializer);
5821 /****************************************************************************/
5822 /* Periodic function to check whether MSI is lost */
5826 /****************************************************************************/
5828 bce_check_msi(void *xsc)
5830 struct bce_softc *sc = xsc;
5831 struct ifnet *ifp = &sc->arpcom.ac_if;
5832 struct status_block *sblk = sc->status_block;
5834 lwkt_serialize_enter(ifp->if_serializer);
5836 KKASSERT(mycpuid == sc->bce_intr_cpuid);
5838 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) != IFF_RUNNING) {
5839 lwkt_serialize_exit(ifp->if_serializer);
5843 if (bce_get_hw_rx_cons(sc) != sc->rx_cons ||
5844 bce_get_hw_tx_cons(sc) != sc->tx_cons ||
5845 (sblk->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
5846 (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) {
5847 if (sc->bce_check_rx_cons == sc->rx_cons &&
5848 sc->bce_check_tx_cons == sc->tx_cons &&
5849 sc->bce_check_status_idx == sc->last_status_idx) {
5852 if (!sc->bce_msi_maylose) {
5853 sc->bce_msi_maylose = TRUE;
5857 msi_ctrl = REG_RD(sc, BCE_PCICFG_MSI_CONTROL);
5858 if (msi_ctrl & BCE_PCICFG_MSI_CONTROL_ENABLE) {
5860 if_printf(ifp, "lost MSI\n");
5862 REG_WR(sc, BCE_PCICFG_MSI_CONTROL,
5863 msi_ctrl & ~BCE_PCICFG_MSI_CONTROL_ENABLE);
5864 REG_WR(sc, BCE_PCICFG_MSI_CONTROL, msi_ctrl);
5867 } else if (bootverbose) {
5868 if_printf(ifp, "MSI may be lost\n");
5872 sc->bce_msi_maylose = FALSE;
5873 sc->bce_check_rx_cons = sc->rx_cons;
5874 sc->bce_check_tx_cons = sc->tx_cons;
5875 sc->bce_check_status_idx = sc->last_status_idx;
5878 callout_reset(&sc->bce_ckmsi_callout, BCE_MSI_CKINTVL,
5880 lwkt_serialize_exit(ifp->if_serializer);
5884 /****************************************************************************/
5885 /* Periodic function to perform maintenance tasks. */
5889 /****************************************************************************/
5891 bce_tick_serialized(struct bce_softc *sc)
5893 struct ifnet *ifp = &sc->arpcom.ac_if;
5894 struct mii_data *mii;
5896 ASSERT_SERIALIZED(ifp->if_serializer);
5898 /* Update the statistics from the hardware statistics block. */
5899 bce_stats_update(sc);
5901 /* Schedule the next tick. */
5902 callout_reset_bycpu(&sc->bce_tick_callout, hz, bce_tick, sc,
5903 sc->bce_intr_cpuid);
5905 /* If link is up already up then we're done. */
5909 mii = device_get_softc(sc->bce_miibus);
5912 /* Check if the link has come up. */
5913 if ((mii->mii_media_status & IFM_ACTIVE) &&
5914 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5916 /* Now that link is up, handle any outstanding TX traffic. */
5917 if (!ifq_is_empty(&ifp->if_snd))
5926 struct bce_softc *sc = xsc;
5927 struct ifnet *ifp = &sc->arpcom.ac_if;
5929 lwkt_serialize_enter(ifp->if_serializer);
5930 bce_tick_serialized(sc);
5931 lwkt_serialize_exit(ifp->if_serializer);
5936 /****************************************************************************/
5937 /* Allows the driver state to be dumped through the sysctl interface. */
5940 /* 0 for success, positive value for failure. */
5941 /****************************************************************************/
5943 bce_sysctl_driver_state(SYSCTL_HANDLER_ARGS)
5947 struct bce_softc *sc;
5950 error = sysctl_handle_int(oidp, &result, 0, req);
5952 if (error || !req->newptr)
5956 sc = (struct bce_softc *)arg1;
5957 bce_dump_driver_state(sc);
5964 /****************************************************************************/
5965 /* Allows the hardware state to be dumped through the sysctl interface. */
5968 /* 0 for success, positive value for failure. */
5969 /****************************************************************************/
5971 bce_sysctl_hw_state(SYSCTL_HANDLER_ARGS)
5975 struct bce_softc *sc;
5978 error = sysctl_handle_int(oidp, &result, 0, req);
5980 if (error || !req->newptr)
5984 sc = (struct bce_softc *)arg1;
5985 bce_dump_hw_state(sc);
5992 /****************************************************************************/
5993 /* Provides a sysctl interface to allows dumping the RX chain. */
5996 /* 0 for success, positive value for failure. */
5997 /****************************************************************************/
5999 bce_sysctl_dump_rx_chain(SYSCTL_HANDLER_ARGS)
6003 struct bce_softc *sc;
6006 error = sysctl_handle_int(oidp, &result, 0, req);
6008 if (error || !req->newptr)
6012 sc = (struct bce_softc *)arg1;
6013 bce_dump_rx_chain(sc, 0, USABLE_RX_BD(sc));
6020 /****************************************************************************/
6021 /* Provides a sysctl interface to allows dumping the TX chain. */
6024 /* 0 for success, positive value for failure. */
6025 /****************************************************************************/
6027 bce_sysctl_dump_tx_chain(SYSCTL_HANDLER_ARGS)
6031 struct bce_softc *sc;
6034 error = sysctl_handle_int(oidp, &result, 0, req);
6036 if (error || !req->newptr)
6040 sc = (struct bce_softc *)arg1;
6041 bce_dump_tx_chain(sc, 0, USABLE_TX_BD(sc));
6048 /****************************************************************************/
6049 /* Provides a sysctl interface to allow reading arbitrary registers in the */
6050 /* device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6053 /* 0 for success, positive value for failure. */
6054 /****************************************************************************/
6056 bce_sysctl_reg_read(SYSCTL_HANDLER_ARGS)
6058 struct bce_softc *sc;
6060 uint32_t val, result;
6063 error = sysctl_handle_int(oidp, &result, 0, req);
6064 if (error || (req->newptr == NULL))
6067 /* Make sure the register is accessible. */
6068 if (result < 0x8000) {
6069 sc = (struct bce_softc *)arg1;
6070 val = REG_RD(sc, result);
6071 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6073 } else if (result < 0x0280000) {
6074 sc = (struct bce_softc *)arg1;
6075 val = REG_RD_IND(sc, result);
6076 if_printf(&sc->arpcom.ac_if, "reg 0x%08X = 0x%08X\n",
6083 /****************************************************************************/
6084 /* Provides a sysctl interface to allow reading arbitrary PHY registers in */
6085 /* the device. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6088 /* 0 for success, positive value for failure. */
6089 /****************************************************************************/
6091 bce_sysctl_phy_read(SYSCTL_HANDLER_ARGS)
6093 struct bce_softc *sc;
6099 error = sysctl_handle_int(oidp, &result, 0, req);
6100 if (error || (req->newptr == NULL))
6103 /* Make sure the register is accessible. */
6104 if (result < 0x20) {
6105 sc = (struct bce_softc *)arg1;
6107 val = bce_miibus_read_reg(dev, sc->bce_phy_addr, result);
6108 if_printf(&sc->arpcom.ac_if,
6109 "phy 0x%02X = 0x%04X\n", result, val);
6115 /****************************************************************************/
6116 /* Provides a sysctl interface to forcing the driver to dump state and */
6117 /* enter the debugger. DO NOT ENABLE ON PRODUCTION SYSTEMS! */
6120 /* 0 for success, positive value for failure. */
6121 /****************************************************************************/
6123 bce_sysctl_breakpoint(SYSCTL_HANDLER_ARGS)
6127 struct bce_softc *sc;
6130 error = sysctl_handle_int(oidp, &result, 0, req);
6132 if (error || !req->newptr)
6136 sc = (struct bce_softc *)arg1;
6145 /****************************************************************************/
6146 /* Adds any sysctl parameters for tuning or debugging purposes. */
6149 /* 0 for success, positive value for failure. */
6150 /****************************************************************************/
6152 bce_add_sysctls(struct bce_softc *sc)
6154 struct sysctl_ctx_list *ctx;
6155 struct sysctl_oid_list *children;
6157 sysctl_ctx_init(&sc->bce_sysctl_ctx);
6158 sc->bce_sysctl_tree = SYSCTL_ADD_NODE(&sc->bce_sysctl_ctx,
6159 SYSCTL_STATIC_CHILDREN(_hw),
6161 device_get_nameunit(sc->bce_dev),
6163 if (sc->bce_sysctl_tree == NULL) {
6164 device_printf(sc->bce_dev, "can't add sysctl node\n");
6168 ctx = &sc->bce_sysctl_ctx;
6169 children = SYSCTL_CHILDREN(sc->bce_sysctl_tree);
6171 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds_int",
6172 CTLTYPE_INT | CTLFLAG_RW,
6173 sc, 0, bce_sysctl_tx_bds_int, "I",
6174 "Send max coalesced BD count during interrupt");
6175 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_bds",
6176 CTLTYPE_INT | CTLFLAG_RW,
6177 sc, 0, bce_sysctl_tx_bds, "I",
6178 "Send max coalesced BD count");
6179 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks_int",
6180 CTLTYPE_INT | CTLFLAG_RW,
6181 sc, 0, bce_sysctl_tx_ticks_int, "I",
6182 "Send coalescing ticks during interrupt");
6183 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_ticks",
6184 CTLTYPE_INT | CTLFLAG_RW,
6185 sc, 0, bce_sysctl_tx_ticks, "I",
6186 "Send coalescing ticks");
6188 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds_int",
6189 CTLTYPE_INT | CTLFLAG_RW,
6190 sc, 0, bce_sysctl_rx_bds_int, "I",
6191 "Receive max coalesced BD count during interrupt");
6192 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_bds",
6193 CTLTYPE_INT | CTLFLAG_RW,
6194 sc, 0, bce_sysctl_rx_bds, "I",
6195 "Receive max coalesced BD count");
6196 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks_int",
6197 CTLTYPE_INT | CTLFLAG_RW,
6198 sc, 0, bce_sysctl_rx_ticks_int, "I",
6199 "Receive coalescing ticks during interrupt");
6200 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_ticks",
6201 CTLTYPE_INT | CTLFLAG_RW,
6202 sc, 0, bce_sysctl_rx_ticks, "I",
6203 "Receive coalescing ticks");
6205 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_pages",
6206 CTLFLAG_RD, &sc->rx_pages, 0, "# of RX pages");
6207 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_pages",
6208 CTLFLAG_RD, &sc->tx_pages, 0, "# of TX pages");
6210 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_wreg",
6211 CTLFLAG_RW, &sc->tx_wreg, 0,
6212 "# segments before write to hardware registers");
6215 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6217 CTLFLAG_RD, &sc->rx_low_watermark,
6218 0, "Lowest level of free rx_bd's");
6220 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6222 CTLFLAG_RD, &sc->rx_empty_count,
6223 0, "Number of times the RX chain was empty");
6225 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6227 CTLFLAG_RD, &sc->tx_hi_watermark,
6228 0, "Highest level of used tx_bd's");
6230 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6232 CTLFLAG_RD, &sc->tx_full_count,
6233 0, "Number of times the TX chain was full");
6235 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6236 "l2fhdr_status_errors",
6237 CTLFLAG_RD, &sc->l2fhdr_status_errors,
6238 0, "l2_fhdr status errors");
6240 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6241 "unexpected_attentions",
6242 CTLFLAG_RD, &sc->unexpected_attentions,
6243 0, "unexpected attentions");
6245 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6246 "lost_status_block_updates",
6247 CTLFLAG_RD, &sc->lost_status_block_updates,
6248 0, "lost status block updates");
6250 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
6251 "mbuf_alloc_failed",
6252 CTLFLAG_RD, &sc->mbuf_alloc_failed,
6253 0, "mbuf cluster allocation failures");
6256 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6257 "stat_IfHCInOctets",
6258 CTLFLAG_RD, &sc->stat_IfHCInOctets,
6261 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6262 "stat_IfHCInBadOctets",
6263 CTLFLAG_RD, &sc->stat_IfHCInBadOctets,
6264 "Bad bytes received");
6266 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6267 "stat_IfHCOutOctets",
6268 CTLFLAG_RD, &sc->stat_IfHCOutOctets,
6271 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6272 "stat_IfHCOutBadOctets",
6273 CTLFLAG_RD, &sc->stat_IfHCOutBadOctets,
6276 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6277 "stat_IfHCInUcastPkts",
6278 CTLFLAG_RD, &sc->stat_IfHCInUcastPkts,
6279 "Unicast packets received");
6281 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6282 "stat_IfHCInMulticastPkts",
6283 CTLFLAG_RD, &sc->stat_IfHCInMulticastPkts,
6284 "Multicast packets received");
6286 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6287 "stat_IfHCInBroadcastPkts",
6288 CTLFLAG_RD, &sc->stat_IfHCInBroadcastPkts,
6289 "Broadcast packets received");
6291 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6292 "stat_IfHCOutUcastPkts",
6293 CTLFLAG_RD, &sc->stat_IfHCOutUcastPkts,
6294 "Unicast packets sent");
6296 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6297 "stat_IfHCOutMulticastPkts",
6298 CTLFLAG_RD, &sc->stat_IfHCOutMulticastPkts,
6299 "Multicast packets sent");
6301 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO,
6302 "stat_IfHCOutBroadcastPkts",
6303 CTLFLAG_RD, &sc->stat_IfHCOutBroadcastPkts,
6304 "Broadcast packets sent");
6306 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6307 "stat_emac_tx_stat_dot3statsinternalmactransmiterrors",
6308 CTLFLAG_RD, &sc->stat_emac_tx_stat_dot3statsinternalmactransmiterrors,
6309 0, "Internal MAC transmit errors");
6311 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6312 "stat_Dot3StatsCarrierSenseErrors",
6313 CTLFLAG_RD, &sc->stat_Dot3StatsCarrierSenseErrors,
6314 0, "Carrier sense errors");
6316 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6317 "stat_Dot3StatsFCSErrors",
6318 CTLFLAG_RD, &sc->stat_Dot3StatsFCSErrors,
6319 0, "Frame check sequence errors");
6321 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6322 "stat_Dot3StatsAlignmentErrors",
6323 CTLFLAG_RD, &sc->stat_Dot3StatsAlignmentErrors,
6324 0, "Alignment errors");
6326 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6327 "stat_Dot3StatsSingleCollisionFrames",
6328 CTLFLAG_RD, &sc->stat_Dot3StatsSingleCollisionFrames,
6329 0, "Single Collision Frames");
6331 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6332 "stat_Dot3StatsMultipleCollisionFrames",
6333 CTLFLAG_RD, &sc->stat_Dot3StatsMultipleCollisionFrames,
6334 0, "Multiple Collision Frames");
6336 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6337 "stat_Dot3StatsDeferredTransmissions",
6338 CTLFLAG_RD, &sc->stat_Dot3StatsDeferredTransmissions,
6339 0, "Deferred Transmissions");
6341 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6342 "stat_Dot3StatsExcessiveCollisions",
6343 CTLFLAG_RD, &sc->stat_Dot3StatsExcessiveCollisions,
6344 0, "Excessive Collisions");
6346 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6347 "stat_Dot3StatsLateCollisions",
6348 CTLFLAG_RD, &sc->stat_Dot3StatsLateCollisions,
6349 0, "Late Collisions");
6351 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6352 "stat_EtherStatsCollisions",
6353 CTLFLAG_RD, &sc->stat_EtherStatsCollisions,
6356 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6357 "stat_EtherStatsFragments",
6358 CTLFLAG_RD, &sc->stat_EtherStatsFragments,
6361 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6362 "stat_EtherStatsJabbers",
6363 CTLFLAG_RD, &sc->stat_EtherStatsJabbers,
6366 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6367 "stat_EtherStatsUndersizePkts",
6368 CTLFLAG_RD, &sc->stat_EtherStatsUndersizePkts,
6369 0, "Undersize packets");
6371 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6372 "stat_EtherStatsOverrsizePkts",
6373 CTLFLAG_RD, &sc->stat_EtherStatsOverrsizePkts,
6374 0, "stat_EtherStatsOverrsizePkts");
6376 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6377 "stat_EtherStatsPktsRx64Octets",
6378 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx64Octets,
6379 0, "Bytes received in 64 byte packets");
6381 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6382 "stat_EtherStatsPktsRx65Octetsto127Octets",
6383 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx65Octetsto127Octets,
6384 0, "Bytes received in 65 to 127 byte packets");
6386 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6387 "stat_EtherStatsPktsRx128Octetsto255Octets",
6388 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx128Octetsto255Octets,
6389 0, "Bytes received in 128 to 255 byte packets");
6391 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6392 "stat_EtherStatsPktsRx256Octetsto511Octets",
6393 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx256Octetsto511Octets,
6394 0, "Bytes received in 256 to 511 byte packets");
6396 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6397 "stat_EtherStatsPktsRx512Octetsto1023Octets",
6398 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx512Octetsto1023Octets,
6399 0, "Bytes received in 512 to 1023 byte packets");
6401 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6402 "stat_EtherStatsPktsRx1024Octetsto1522Octets",
6403 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1024Octetsto1522Octets,
6404 0, "Bytes received in 1024 t0 1522 byte packets");
6406 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6407 "stat_EtherStatsPktsRx1523Octetsto9022Octets",
6408 CTLFLAG_RD, &sc->stat_EtherStatsPktsRx1523Octetsto9022Octets,
6409 0, "Bytes received in 1523 to 9022 byte packets");
6411 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6412 "stat_EtherStatsPktsTx64Octets",
6413 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx64Octets,
6414 0, "Bytes sent in 64 byte packets");
6416 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6417 "stat_EtherStatsPktsTx65Octetsto127Octets",
6418 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx65Octetsto127Octets,
6419 0, "Bytes sent in 65 to 127 byte packets");
6421 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6422 "stat_EtherStatsPktsTx128Octetsto255Octets",
6423 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx128Octetsto255Octets,
6424 0, "Bytes sent in 128 to 255 byte packets");
6426 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6427 "stat_EtherStatsPktsTx256Octetsto511Octets",
6428 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx256Octetsto511Octets,
6429 0, "Bytes sent in 256 to 511 byte packets");
6431 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6432 "stat_EtherStatsPktsTx512Octetsto1023Octets",
6433 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx512Octetsto1023Octets,
6434 0, "Bytes sent in 512 to 1023 byte packets");
6436 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6437 "stat_EtherStatsPktsTx1024Octetsto1522Octets",
6438 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1024Octetsto1522Octets,
6439 0, "Bytes sent in 1024 to 1522 byte packets");
6441 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6442 "stat_EtherStatsPktsTx1523Octetsto9022Octets",
6443 CTLFLAG_RD, &sc->stat_EtherStatsPktsTx1523Octetsto9022Octets,
6444 0, "Bytes sent in 1523 to 9022 byte packets");
6446 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6447 "stat_XonPauseFramesReceived",
6448 CTLFLAG_RD, &sc->stat_XonPauseFramesReceived,
6449 0, "XON pause frames receved");
6451 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6452 "stat_XoffPauseFramesReceived",
6453 CTLFLAG_RD, &sc->stat_XoffPauseFramesReceived,
6454 0, "XOFF pause frames received");
6456 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6458 CTLFLAG_RD, &sc->stat_OutXonSent,
6459 0, "XON pause frames sent");
6461 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6463 CTLFLAG_RD, &sc->stat_OutXoffSent,
6464 0, "XOFF pause frames sent");
6466 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6467 "stat_FlowControlDone",
6468 CTLFLAG_RD, &sc->stat_FlowControlDone,
6469 0, "Flow control done");
6471 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6472 "stat_MacControlFramesReceived",
6473 CTLFLAG_RD, &sc->stat_MacControlFramesReceived,
6474 0, "MAC control frames received");
6476 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6477 "stat_XoffStateEntered",
6478 CTLFLAG_RD, &sc->stat_XoffStateEntered,
6479 0, "XOFF state entered");
6481 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6482 "stat_IfInFramesL2FilterDiscards",
6483 CTLFLAG_RD, &sc->stat_IfInFramesL2FilterDiscards,
6484 0, "Received L2 packets discarded");
6486 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6487 "stat_IfInRuleCheckerDiscards",
6488 CTLFLAG_RD, &sc->stat_IfInRuleCheckerDiscards,
6489 0, "Received packets discarded by rule");
6491 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6492 "stat_IfInFTQDiscards",
6493 CTLFLAG_RD, &sc->stat_IfInFTQDiscards,
6494 0, "Received packet FTQ discards");
6496 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6497 "stat_IfInMBUFDiscards",
6498 CTLFLAG_RD, &sc->stat_IfInMBUFDiscards,
6499 0, "Received packets discarded due to lack of controller buffer memory");
6501 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6502 "stat_IfInRuleCheckerP4Hit",
6503 CTLFLAG_RD, &sc->stat_IfInRuleCheckerP4Hit,
6504 0, "Received packets rule checker hits");
6506 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6507 "stat_CatchupInRuleCheckerDiscards",
6508 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerDiscards,
6509 0, "Received packets discarded in Catchup path");
6511 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6512 "stat_CatchupInFTQDiscards",
6513 CTLFLAG_RD, &sc->stat_CatchupInFTQDiscards,
6514 0, "Received packets discarded in FTQ in Catchup path");
6516 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6517 "stat_CatchupInMBUFDiscards",
6518 CTLFLAG_RD, &sc->stat_CatchupInMBUFDiscards,
6519 0, "Received packets discarded in controller buffer memory in Catchup path");
6521 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6522 "stat_CatchupInRuleCheckerP4Hit",
6523 CTLFLAG_RD, &sc->stat_CatchupInRuleCheckerP4Hit,
6524 0, "Received packets rule checker hits in Catchup path");
6526 SYSCTL_ADD_UINT(ctx, children, OID_AUTO,
6528 CTLFLAG_RD, &sc->com_no_buffers,
6529 0, "Valid packets received but no RX buffers available");
6532 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6533 "driver_state", CTLTYPE_INT | CTLFLAG_RW,
6535 bce_sysctl_driver_state, "I", "Drive state information");
6537 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6538 "hw_state", CTLTYPE_INT | CTLFLAG_RW,
6540 bce_sysctl_hw_state, "I", "Hardware state information");
6542 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6543 "dump_rx_chain", CTLTYPE_INT | CTLFLAG_RW,
6545 bce_sysctl_dump_rx_chain, "I", "Dump rx_bd chain");
6547 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6548 "dump_tx_chain", CTLTYPE_INT | CTLFLAG_RW,
6550 bce_sysctl_dump_tx_chain, "I", "Dump tx_bd chain");
6552 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6553 "breakpoint", CTLTYPE_INT | CTLFLAG_RW,
6555 bce_sysctl_breakpoint, "I", "Driver breakpoint");
6557 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6558 "reg_read", CTLTYPE_INT | CTLFLAG_RW,
6560 bce_sysctl_reg_read, "I", "Register read");
6562 SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
6563 "phy_read", CTLTYPE_INT | CTLFLAG_RW,
6565 bce_sysctl_phy_read, "I", "PHY register read");
6572 /****************************************************************************/
6573 /* BCE Debug Routines */
6574 /****************************************************************************/
6577 /****************************************************************************/
6578 /* Freezes the controller to allow for a cohesive state dump. */
6582 /****************************************************************************/
6584 bce_freeze_controller(struct bce_softc *sc)
6588 val = REG_RD(sc, BCE_MISC_COMMAND);
6589 val |= BCE_MISC_COMMAND_DISABLE_ALL;
6590 REG_WR(sc, BCE_MISC_COMMAND, val);
6594 /****************************************************************************/
6595 /* Unfreezes the controller after a freeze operation. This may not always */
6596 /* work and the controller will require a reset! */
6600 /****************************************************************************/
6602 bce_unfreeze_controller(struct bce_softc *sc)
6606 val = REG_RD(sc, BCE_MISC_COMMAND);
6607 val |= BCE_MISC_COMMAND_ENABLE_ALL;
6608 REG_WR(sc, BCE_MISC_COMMAND, val);
6612 /****************************************************************************/
6613 /* Prints out information about an mbuf. */
6617 /****************************************************************************/
6619 bce_dump_mbuf(struct bce_softc *sc, struct mbuf *m)
6621 struct ifnet *ifp = &sc->arpcom.ac_if;
6622 uint32_t val_hi, val_lo;
6623 struct mbuf *mp = m;
6626 /* Index out of range. */
6627 if_printf(ifp, "mbuf: null pointer\n");
6632 val_hi = BCE_ADDR_HI(mp);
6633 val_lo = BCE_ADDR_LO(mp);
6634 if_printf(ifp, "mbuf: vaddr = 0x%08X:%08X, m_len = %d, "
6635 "m_flags = ( ", val_hi, val_lo, mp->m_len);
6637 if (mp->m_flags & M_EXT)
6639 if (mp->m_flags & M_PKTHDR)
6640 kprintf("M_PKTHDR ");
6641 if (mp->m_flags & M_EOR)
6644 if (mp->m_flags & M_RDONLY)
6645 kprintf("M_RDONLY ");
6648 val_hi = BCE_ADDR_HI(mp->m_data);
6649 val_lo = BCE_ADDR_LO(mp->m_data);
6650 kprintf(") m_data = 0x%08X:%08X\n", val_hi, val_lo);
6652 if (mp->m_flags & M_PKTHDR) {
6653 if_printf(ifp, "- m_pkthdr: flags = ( ");
6654 if (mp->m_flags & M_BCAST)
6655 kprintf("M_BCAST ");
6656 if (mp->m_flags & M_MCAST)
6657 kprintf("M_MCAST ");
6658 if (mp->m_flags & M_FRAG)
6660 if (mp->m_flags & M_FIRSTFRAG)
6661 kprintf("M_FIRSTFRAG ");
6662 if (mp->m_flags & M_LASTFRAG)
6663 kprintf("M_LASTFRAG ");
6665 if (mp->m_flags & M_VLANTAG)
6666 kprintf("M_VLANTAG ");
6669 if (mp->m_flags & M_PROMISC)
6670 kprintf("M_PROMISC ");
6672 kprintf(") csum_flags = ( ");
6673 if (mp->m_pkthdr.csum_flags & CSUM_IP)
6674 kprintf("CSUM_IP ");
6675 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
6676 kprintf("CSUM_TCP ");
6677 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
6678 kprintf("CSUM_UDP ");
6679 if (mp->m_pkthdr.csum_flags & CSUM_IP_FRAGS)
6680 kprintf("CSUM_IP_FRAGS ");
6681 if (mp->m_pkthdr.csum_flags & CSUM_FRAGMENT)
6682 kprintf("CSUM_FRAGMENT ");
6684 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
6685 kprintf("CSUM_TSO ");
6687 if (mp->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
6688 kprintf("CSUM_IP_CHECKED ");
6689 if (mp->m_pkthdr.csum_flags & CSUM_IP_VALID)
6690 kprintf("CSUM_IP_VALID ");
6691 if (mp->m_pkthdr.csum_flags & CSUM_DATA_VALID)
6692 kprintf("CSUM_DATA_VALID ");
6696 if (mp->m_flags & M_EXT) {
6697 val_hi = BCE_ADDR_HI(mp->m_ext.ext_buf);
6698 val_lo = BCE_ADDR_LO(mp->m_ext.ext_buf);
6699 if_printf(ifp, "- m_ext: vaddr = 0x%08X:%08X, "
6701 val_hi, val_lo, mp->m_ext.ext_size);
6708 /****************************************************************************/
6709 /* Prints out the mbufs in the RX mbuf chain. */
6713 /****************************************************************************/
6715 bce_dump_rx_mbuf_chain(struct bce_softc *sc, int chain_prod, int count)
6717 struct ifnet *ifp = &sc->arpcom.ac_if;
6721 "----------------------------"
6723 "----------------------------\n");
6725 for (i = 0; i < count; i++) {
6726 if_printf(ifp, "rxmbuf[0x%04X]\n", chain_prod);
6727 bce_dump_mbuf(sc, sc->rx_mbuf_ptr[chain_prod]);
6728 chain_prod = RX_CHAIN_IDX(sc, NEXT_RX_BD(chain_prod));
6732 "----------------------------"
6734 "----------------------------\n");
6738 /****************************************************************************/
6739 /* Prints out a tx_bd structure. */
6743 /****************************************************************************/
6745 bce_dump_txbd(struct bce_softc *sc, int idx, struct tx_bd *txbd)
6747 struct ifnet *ifp = &sc->arpcom.ac_if;
6749 if (idx > MAX_TX_BD(sc)) {
6750 /* Index out of range. */
6751 if_printf(ifp, "tx_bd[0x%04X]: Invalid tx_bd index!\n", idx);
6752 } else if ((idx & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE) {
6753 /* TX Chain page pointer. */
6754 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6755 "chain page pointer\n",
6756 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo);
6758 /* Normal tx_bd entry. */
6759 if_printf(ifp, "tx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6761 "vlan tag= 0x%04X, flags = 0x%04X (",
6762 idx, txbd->tx_bd_haddr_hi, txbd->tx_bd_haddr_lo,
6763 txbd->tx_bd_mss_nbytes,
6764 txbd->tx_bd_vlan_tag, txbd->tx_bd_flags);
6766 if (txbd->tx_bd_flags & TX_BD_FLAGS_CONN_FAULT)
6767 kprintf(" CONN_FAULT");
6769 if (txbd->tx_bd_flags & TX_BD_FLAGS_TCP_UDP_CKSUM)
6770 kprintf(" TCP_UDP_CKSUM");
6772 if (txbd->tx_bd_flags & TX_BD_FLAGS_IP_CKSUM)
6773 kprintf(" IP_CKSUM");
6775 if (txbd->tx_bd_flags & TX_BD_FLAGS_VLAN_TAG)
6778 if (txbd->tx_bd_flags & TX_BD_FLAGS_COAL_NOW)
6779 kprintf(" COAL_NOW");
6781 if (txbd->tx_bd_flags & TX_BD_FLAGS_DONT_GEN_CRC)
6782 kprintf(" DONT_GEN_CRC");
6784 if (txbd->tx_bd_flags & TX_BD_FLAGS_START)
6787 if (txbd->tx_bd_flags & TX_BD_FLAGS_END)
6790 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_LSO)
6793 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_OPTION_WORD)
6794 kprintf(" OPTION_WORD");
6796 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_FLAGS)
6799 if (txbd->tx_bd_flags & TX_BD_FLAGS_SW_SNAP)
6807 /****************************************************************************/
6808 /* Prints out a rx_bd structure. */
6812 /****************************************************************************/
6814 bce_dump_rxbd(struct bce_softc *sc, int idx, struct rx_bd *rxbd)
6816 struct ifnet *ifp = &sc->arpcom.ac_if;
6818 if (idx > MAX_RX_BD(sc)) {
6819 /* Index out of range. */
6820 if_printf(ifp, "rx_bd[0x%04X]: Invalid rx_bd index!\n", idx);
6821 } else if ((idx & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE) {
6822 /* TX Chain page pointer. */
6823 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6824 "chain page pointer\n",
6825 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo);
6827 /* Normal tx_bd entry. */
6828 if_printf(ifp, "rx_bd[0x%04X]: haddr = 0x%08X:%08X, "
6829 "nbytes = 0x%08X, flags = 0x%08X\n",
6830 idx, rxbd->rx_bd_haddr_hi, rxbd->rx_bd_haddr_lo,
6831 rxbd->rx_bd_len, rxbd->rx_bd_flags);
6836 /****************************************************************************/
6837 /* Prints out a l2_fhdr structure. */
6841 /****************************************************************************/
6843 bce_dump_l2fhdr(struct bce_softc *sc, int idx, struct l2_fhdr *l2fhdr)
6845 if_printf(&sc->arpcom.ac_if, "l2_fhdr[0x%04X]: status = 0x%08X, "
6846 "pkt_len = 0x%04X, vlan = 0x%04x, "
6847 "ip_xsum = 0x%04X, tcp_udp_xsum = 0x%04X\n",
6848 idx, l2fhdr->l2_fhdr_status,
6849 l2fhdr->l2_fhdr_pkt_len, l2fhdr->l2_fhdr_vlan_tag,
6850 l2fhdr->l2_fhdr_ip_xsum, l2fhdr->l2_fhdr_tcp_udp_xsum);
6854 /****************************************************************************/
6855 /* Prints out the tx chain. */
6859 /****************************************************************************/
6861 bce_dump_tx_chain(struct bce_softc *sc, int tx_prod, int count)
6863 struct ifnet *ifp = &sc->arpcom.ac_if;
6866 /* First some info about the tx_bd chain structure. */
6868 "----------------------------"
6870 "----------------------------\n");
6872 if_printf(ifp, "page size = 0x%08X, "
6873 "tx chain pages = 0x%08X\n",
6874 (uint32_t)BCM_PAGE_SIZE, (uint32_t)sc->tx_pages);
6876 if_printf(ifp, "tx_bd per page = 0x%08X, "
6877 "usable tx_bd per page = 0x%08X\n",
6878 (uint32_t)TOTAL_TX_BD_PER_PAGE,
6879 (uint32_t)USABLE_TX_BD_PER_PAGE);
6881 if_printf(ifp, "total tx_bd = 0x%08X\n", (uint32_t)TOTAL_TX_BD(sc));
6884 "----------------------------"
6886 "----------------------------\n");
6888 /* Now print out the tx_bd's themselves. */
6889 for (i = 0; i < count; i++) {
6892 txbd = &sc->tx_bd_chain[TX_PAGE(tx_prod)][TX_IDX(tx_prod)];
6893 bce_dump_txbd(sc, tx_prod, txbd);
6894 tx_prod = TX_CHAIN_IDX(sc, NEXT_TX_BD(tx_prod));
6898 "----------------------------"
6900 "----------------------------\n");
6904 /****************************************************************************/
6905 /* Prints out the rx chain. */
6909 /****************************************************************************/
6911 bce_dump_rx_chain(struct bce_softc *sc, int rx_prod, int count)
6913 struct ifnet *ifp = &sc->arpcom.ac_if;
6916 /* First some info about the tx_bd chain structure. */
6918 "----------------------------"
6920 "----------------------------\n");
6922 if_printf(ifp, "page size = 0x%08X, "
6923 "rx chain pages = 0x%08X\n",
6924 (uint32_t)BCM_PAGE_SIZE, (uint32_t)sc->rx_pages);
6926 if_printf(ifp, "rx_bd per page = 0x%08X, "
6927 "usable rx_bd per page = 0x%08X\n",
6928 (uint32_t)TOTAL_RX_BD_PER_PAGE,
6929 (uint32_t)USABLE_RX_BD_PER_PAGE);
6931 if_printf(ifp, "total rx_bd = 0x%08X\n", (uint32_t)TOTAL_RX_BD(sc));
6934 "----------------------------"
6936 "----------------------------\n");
6938 /* Now print out the rx_bd's themselves. */
6939 for (i = 0; i < count; i++) {
6942 rxbd = &sc->rx_bd_chain[RX_PAGE(rx_prod)][RX_IDX(rx_prod)];
6943 bce_dump_rxbd(sc, rx_prod, rxbd);
6944 rx_prod = RX_CHAIN_IDX(sc, NEXT_RX_BD(rx_prod));
6948 "----------------------------"
6950 "----------------------------\n");
6954 /****************************************************************************/
6955 /* Prints out the status block from host memory. */
6959 /****************************************************************************/
6961 bce_dump_status_block(struct bce_softc *sc)
6963 struct status_block *sblk = sc->status_block;
6964 struct ifnet *ifp = &sc->arpcom.ac_if;
6967 "----------------------------"
6969 "----------------------------\n");
6971 if_printf(ifp, " 0x%08X - attn_bits\n", sblk->status_attn_bits);
6973 if_printf(ifp, " 0x%08X - attn_bits_ack\n",
6974 sblk->status_attn_bits_ack);
6976 if_printf(ifp, "0x%04X(0x%04X) - rx_cons0\n",
6977 sblk->status_rx_quick_consumer_index0,
6978 (uint16_t)RX_CHAIN_IDX(sc, sblk->status_rx_quick_consumer_index0));
6980 if_printf(ifp, "0x%04X(0x%04X) - tx_cons0\n",
6981 sblk->status_tx_quick_consumer_index0,
6982 (uint16_t)TX_CHAIN_IDX(sc, sblk->status_tx_quick_consumer_index0));
6984 if_printf(ifp, " 0x%04X - status_idx\n", sblk->status_idx);
6986 /* Theses indices are not used for normal L2 drivers. */
6987 if (sblk->status_rx_quick_consumer_index1) {
6988 if_printf(ifp, "0x%04X(0x%04X) - rx_cons1\n",
6989 sblk->status_rx_quick_consumer_index1,
6990 (uint16_t)RX_CHAIN_IDX(sc,
6991 sblk->status_rx_quick_consumer_index1));
6994 if (sblk->status_tx_quick_consumer_index1) {
6995 if_printf(ifp, "0x%04X(0x%04X) - tx_cons1\n",
6996 sblk->status_tx_quick_consumer_index1,
6997 (uint16_t)TX_CHAIN_IDX(sc,
6998 sblk->status_tx_quick_consumer_index1));
7001 if (sblk->status_rx_quick_consumer_index2) {
7002 if_printf(ifp, "0x%04X(0x%04X)- rx_cons2\n",
7003 sblk->status_rx_quick_consumer_index2,
7004 (uint16_t)RX_CHAIN_IDX(sc,
7005 sblk->status_rx_quick_consumer_index2));
7008 if (sblk->status_tx_quick_consumer_index2) {
7009 if_printf(ifp, "0x%04X(0x%04X) - tx_cons2\n",
7010 sblk->status_tx_quick_consumer_index2,
7011 (uint16_t)TX_CHAIN_IDX(sc,
7012 sblk->status_tx_quick_consumer_index2));
7015 if (sblk->status_rx_quick_consumer_index3) {
7016 if_printf(ifp, "0x%04X(0x%04X) - rx_cons3\n",
7017 sblk->status_rx_quick_consumer_index3,
7018 (uint16_t)RX_CHAIN_IDX(sc,
7019 sblk->status_rx_quick_consumer_index3));
7022 if (sblk->status_tx_quick_consumer_index3) {
7023 if_printf(ifp, "0x%04X(0x%04X) - tx_cons3\n",
7024 sblk->status_tx_quick_consumer_index3,
7025 (uint16_t)TX_CHAIN_IDX(sc,
7026 sblk->status_tx_quick_consumer_index3));
7029 if (sblk->status_rx_quick_consumer_index4 ||
7030 sblk->status_rx_quick_consumer_index5) {
7031 if_printf(ifp, "rx_cons4 = 0x%08X, rx_cons5 = 0x%08X\n",
7032 sblk->status_rx_quick_consumer_index4,
7033 sblk->status_rx_quick_consumer_index5);
7036 if (sblk->status_rx_quick_consumer_index6 ||
7037 sblk->status_rx_quick_consumer_index7) {
7038 if_printf(ifp, "rx_cons6 = 0x%08X, rx_cons7 = 0x%08X\n",
7039 sblk->status_rx_quick_consumer_index6,
7040 sblk->status_rx_quick_consumer_index7);
7043 if (sblk->status_rx_quick_consumer_index8 ||
7044 sblk->status_rx_quick_consumer_index9) {
7045 if_printf(ifp, "rx_cons8 = 0x%08X, rx_cons9 = 0x%08X\n",
7046 sblk->status_rx_quick_consumer_index8,
7047 sblk->status_rx_quick_consumer_index9);
7050 if (sblk->status_rx_quick_consumer_index10 ||
7051 sblk->status_rx_quick_consumer_index11) {
7052 if_printf(ifp, "rx_cons10 = 0x%08X, rx_cons11 = 0x%08X\n",
7053 sblk->status_rx_quick_consumer_index10,
7054 sblk->status_rx_quick_consumer_index11);
7057 if (sblk->status_rx_quick_consumer_index12 ||
7058 sblk->status_rx_quick_consumer_index13) {
7059 if_printf(ifp, "rx_cons12 = 0x%08X, rx_cons13 = 0x%08X\n",
7060 sblk->status_rx_quick_consumer_index12,
7061 sblk->status_rx_quick_consumer_index13);
7064 if (sblk->status_rx_quick_consumer_index14 ||
7065 sblk->status_rx_quick_consumer_index15) {
7066 if_printf(ifp, "rx_cons14 = 0x%08X, rx_cons15 = 0x%08X\n",
7067 sblk->status_rx_quick_consumer_index14,
7068 sblk->status_rx_quick_consumer_index15);
7071 if (sblk->status_completion_producer_index ||
7072 sblk->status_cmd_consumer_index) {
7073 if_printf(ifp, "com_prod = 0x%08X, cmd_cons = 0x%08X\n",
7074 sblk->status_completion_producer_index,
7075 sblk->status_cmd_consumer_index);
7079 "----------------------------"
7081 "----------------------------\n");
7085 /****************************************************************************/
7086 /* Prints out the statistics block. */
7090 /****************************************************************************/
7092 bce_dump_stats_block(struct bce_softc *sc)
7094 struct statistics_block *sblk = sc->stats_block;
7095 struct ifnet *ifp = &sc->arpcom.ac_if;
7099 " Stats Block (All Stats Not Shown Are 0) "
7100 "---------------\n");
7102 if (sblk->stat_IfHCInOctets_hi || sblk->stat_IfHCInOctets_lo) {
7103 if_printf(ifp, "0x%08X:%08X : IfHcInOctets\n",
7104 sblk->stat_IfHCInOctets_hi,
7105 sblk->stat_IfHCInOctets_lo);
7108 if (sblk->stat_IfHCInBadOctets_hi || sblk->stat_IfHCInBadOctets_lo) {
7109 if_printf(ifp, "0x%08X:%08X : IfHcInBadOctets\n",
7110 sblk->stat_IfHCInBadOctets_hi,
7111 sblk->stat_IfHCInBadOctets_lo);
7114 if (sblk->stat_IfHCOutOctets_hi || sblk->stat_IfHCOutOctets_lo) {
7115 if_printf(ifp, "0x%08X:%08X : IfHcOutOctets\n",
7116 sblk->stat_IfHCOutOctets_hi,
7117 sblk->stat_IfHCOutOctets_lo);
7120 if (sblk->stat_IfHCOutBadOctets_hi || sblk->stat_IfHCOutBadOctets_lo) {
7121 if_printf(ifp, "0x%08X:%08X : IfHcOutBadOctets\n",
7122 sblk->stat_IfHCOutBadOctets_hi,
7123 sblk->stat_IfHCOutBadOctets_lo);
7126 if (sblk->stat_IfHCInUcastPkts_hi || sblk->stat_IfHCInUcastPkts_lo) {
7127 if_printf(ifp, "0x%08X:%08X : IfHcInUcastPkts\n",
7128 sblk->stat_IfHCInUcastPkts_hi,
7129 sblk->stat_IfHCInUcastPkts_lo);
7132 if (sblk->stat_IfHCInBroadcastPkts_hi ||
7133 sblk->stat_IfHCInBroadcastPkts_lo) {
7134 if_printf(ifp, "0x%08X:%08X : IfHcInBroadcastPkts\n",
7135 sblk->stat_IfHCInBroadcastPkts_hi,
7136 sblk->stat_IfHCInBroadcastPkts_lo);
7139 if (sblk->stat_IfHCInMulticastPkts_hi ||
7140 sblk->stat_IfHCInMulticastPkts_lo) {
7141 if_printf(ifp, "0x%08X:%08X : IfHcInMulticastPkts\n",
7142 sblk->stat_IfHCInMulticastPkts_hi,
7143 sblk->stat_IfHCInMulticastPkts_lo);
7146 if (sblk->stat_IfHCOutUcastPkts_hi || sblk->stat_IfHCOutUcastPkts_lo) {
7147 if_printf(ifp, "0x%08X:%08X : IfHcOutUcastPkts\n",
7148 sblk->stat_IfHCOutUcastPkts_hi,
7149 sblk->stat_IfHCOutUcastPkts_lo);
7152 if (sblk->stat_IfHCOutBroadcastPkts_hi ||
7153 sblk->stat_IfHCOutBroadcastPkts_lo) {
7154 if_printf(ifp, "0x%08X:%08X : IfHcOutBroadcastPkts\n",
7155 sblk->stat_IfHCOutBroadcastPkts_hi,
7156 sblk->stat_IfHCOutBroadcastPkts_lo);
7159 if (sblk->stat_IfHCOutMulticastPkts_hi ||
7160 sblk->stat_IfHCOutMulticastPkts_lo) {
7161 if_printf(ifp, "0x%08X:%08X : IfHcOutMulticastPkts\n",
7162 sblk->stat_IfHCOutMulticastPkts_hi,
7163 sblk->stat_IfHCOutMulticastPkts_lo);
7166 if (sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors) {
7167 if_printf(ifp, " 0x%08X : "
7168 "emac_tx_stat_dot3statsinternalmactransmiterrors\n",
7169 sblk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors);
7172 if (sblk->stat_Dot3StatsCarrierSenseErrors) {
7173 if_printf(ifp, " 0x%08X : "
7174 "Dot3StatsCarrierSenseErrors\n",
7175 sblk->stat_Dot3StatsCarrierSenseErrors);
7178 if (sblk->stat_Dot3StatsFCSErrors) {
7179 if_printf(ifp, " 0x%08X : Dot3StatsFCSErrors\n",
7180 sblk->stat_Dot3StatsFCSErrors);
7183 if (sblk->stat_Dot3StatsAlignmentErrors) {
7184 if_printf(ifp, " 0x%08X : Dot3StatsAlignmentErrors\n",
7185 sblk->stat_Dot3StatsAlignmentErrors);
7188 if (sblk->stat_Dot3StatsSingleCollisionFrames) {
7189 if_printf(ifp, " 0x%08X : "
7190 "Dot3StatsSingleCollisionFrames\n",
7191 sblk->stat_Dot3StatsSingleCollisionFrames);
7194 if (sblk->stat_Dot3StatsMultipleCollisionFrames) {
7195 if_printf(ifp, " 0x%08X : "
7196 "Dot3StatsMultipleCollisionFrames\n",
7197 sblk->stat_Dot3StatsMultipleCollisionFrames);
7200 if (sblk->stat_Dot3StatsDeferredTransmissions) {
7201 if_printf(ifp, " 0x%08X : "
7202 "Dot3StatsDeferredTransmissions\n",
7203 sblk->stat_Dot3StatsDeferredTransmissions);
7206 if (sblk->stat_Dot3StatsExcessiveCollisions) {
7207 if_printf(ifp, " 0x%08X : "
7208 "Dot3StatsExcessiveCollisions\n",
7209 sblk->stat_Dot3StatsExcessiveCollisions);
7212 if (sblk->stat_Dot3StatsLateCollisions) {
7213 if_printf(ifp, " 0x%08X : Dot3StatsLateCollisions\n",
7214 sblk->stat_Dot3StatsLateCollisions);
7217 if (sblk->stat_EtherStatsCollisions) {
7218 if_printf(ifp, " 0x%08X : EtherStatsCollisions\n",
7219 sblk->stat_EtherStatsCollisions);
7222 if (sblk->stat_EtherStatsFragments) {
7223 if_printf(ifp, " 0x%08X : EtherStatsFragments\n",
7224 sblk->stat_EtherStatsFragments);
7227 if (sblk->stat_EtherStatsJabbers) {
7228 if_printf(ifp, " 0x%08X : EtherStatsJabbers\n",
7229 sblk->stat_EtherStatsJabbers);
7232 if (sblk->stat_EtherStatsUndersizePkts) {
7233 if_printf(ifp, " 0x%08X : EtherStatsUndersizePkts\n",
7234 sblk->stat_EtherStatsUndersizePkts);
7237 if (sblk->stat_EtherStatsOverrsizePkts) {
7238 if_printf(ifp, " 0x%08X : EtherStatsOverrsizePkts\n",
7239 sblk->stat_EtherStatsOverrsizePkts);
7242 if (sblk->stat_EtherStatsPktsRx64Octets) {
7243 if_printf(ifp, " 0x%08X : EtherStatsPktsRx64Octets\n",
7244 sblk->stat_EtherStatsPktsRx64Octets);
7247 if (sblk->stat_EtherStatsPktsRx65Octetsto127Octets) {
7248 if_printf(ifp, " 0x%08X : "
7249 "EtherStatsPktsRx65Octetsto127Octets\n",
7250 sblk->stat_EtherStatsPktsRx65Octetsto127Octets);
7253 if (sblk->stat_EtherStatsPktsRx128Octetsto255Octets) {
7254 if_printf(ifp, " 0x%08X : "
7255 "EtherStatsPktsRx128Octetsto255Octets\n",
7256 sblk->stat_EtherStatsPktsRx128Octetsto255Octets);
7259 if (sblk->stat_EtherStatsPktsRx256Octetsto511Octets) {
7260 if_printf(ifp, " 0x%08X : "
7261 "EtherStatsPktsRx256Octetsto511Octets\n",
7262 sblk->stat_EtherStatsPktsRx256Octetsto511Octets);
7265 if (sblk->stat_EtherStatsPktsRx512Octetsto1023Octets) {
7266 if_printf(ifp, " 0x%08X : "
7267 "EtherStatsPktsRx512Octetsto1023Octets\n",
7268 sblk->stat_EtherStatsPktsRx512Octetsto1023Octets);
7271 if (sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets) {
7272 if_printf(ifp, " 0x%08X : "
7273 "EtherStatsPktsRx1024Octetsto1522Octets\n",
7274 sblk->stat_EtherStatsPktsRx1024Octetsto1522Octets);
7277 if (sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets) {
7278 if_printf(ifp, " 0x%08X : "
7279 "EtherStatsPktsRx1523Octetsto9022Octets\n",
7280 sblk->stat_EtherStatsPktsRx1523Octetsto9022Octets);
7283 if (sblk->stat_EtherStatsPktsTx64Octets) {
7284 if_printf(ifp, " 0x%08X : EtherStatsPktsTx64Octets\n",
7285 sblk->stat_EtherStatsPktsTx64Octets);
7288 if (sblk->stat_EtherStatsPktsTx65Octetsto127Octets) {
7289 if_printf(ifp, " 0x%08X : "
7290 "EtherStatsPktsTx65Octetsto127Octets\n",
7291 sblk->stat_EtherStatsPktsTx65Octetsto127Octets);
7294 if (sblk->stat_EtherStatsPktsTx128Octetsto255Octets) {
7295 if_printf(ifp, " 0x%08X : "
7296 "EtherStatsPktsTx128Octetsto255Octets\n",
7297 sblk->stat_EtherStatsPktsTx128Octetsto255Octets);
7300 if (sblk->stat_EtherStatsPktsTx256Octetsto511Octets) {
7301 if_printf(ifp, " 0x%08X : "
7302 "EtherStatsPktsTx256Octetsto511Octets\n",
7303 sblk->stat_EtherStatsPktsTx256Octetsto511Octets);
7306 if (sblk->stat_EtherStatsPktsTx512Octetsto1023Octets) {
7307 if_printf(ifp, " 0x%08X : "
7308 "EtherStatsPktsTx512Octetsto1023Octets\n",
7309 sblk->stat_EtherStatsPktsTx512Octetsto1023Octets);
7312 if (sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets) {
7313 if_printf(ifp, " 0x%08X : "
7314 "EtherStatsPktsTx1024Octetsto1522Octets\n",
7315 sblk->stat_EtherStatsPktsTx1024Octetsto1522Octets);
7318 if (sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets) {
7319 if_printf(ifp, " 0x%08X : "
7320 "EtherStatsPktsTx1523Octetsto9022Octets\n",
7321 sblk->stat_EtherStatsPktsTx1523Octetsto9022Octets);
7324 if (sblk->stat_XonPauseFramesReceived) {
7325 if_printf(ifp, " 0x%08X : XonPauseFramesReceived\n",
7326 sblk->stat_XonPauseFramesReceived);
7329 if (sblk->stat_XoffPauseFramesReceived) {
7330 if_printf(ifp, " 0x%08X : XoffPauseFramesReceived\n",
7331 sblk->stat_XoffPauseFramesReceived);
7334 if (sblk->stat_OutXonSent) {
7335 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7336 sblk->stat_OutXonSent);
7339 if (sblk->stat_OutXoffSent) {
7340 if_printf(ifp, " 0x%08X : OutXoffSent\n",
7341 sblk->stat_OutXoffSent);
7344 if (sblk->stat_FlowControlDone) {
7345 if_printf(ifp, " 0x%08X : FlowControlDone\n",
7346 sblk->stat_FlowControlDone);
7349 if (sblk->stat_MacControlFramesReceived) {
7350 if_printf(ifp, " 0x%08X : MacControlFramesReceived\n",
7351 sblk->stat_MacControlFramesReceived);
7354 if (sblk->stat_XoffStateEntered) {
7355 if_printf(ifp, " 0x%08X : XoffStateEntered\n",
7356 sblk->stat_XoffStateEntered);
7359 if (sblk->stat_IfInFramesL2FilterDiscards) {
7360 if_printf(ifp, " 0x%08X : IfInFramesL2FilterDiscards\n", sblk->stat_IfInFramesL2FilterDiscards);
7363 if (sblk->stat_IfInRuleCheckerDiscards) {
7364 if_printf(ifp, " 0x%08X : IfInRuleCheckerDiscards\n",
7365 sblk->stat_IfInRuleCheckerDiscards);
7368 if (sblk->stat_IfInFTQDiscards) {
7369 if_printf(ifp, " 0x%08X : IfInFTQDiscards\n",
7370 sblk->stat_IfInFTQDiscards);
7373 if (sblk->stat_IfInMBUFDiscards) {
7374 if_printf(ifp, " 0x%08X : IfInMBUFDiscards\n",
7375 sblk->stat_IfInMBUFDiscards);
7378 if (sblk->stat_IfInRuleCheckerP4Hit) {
7379 if_printf(ifp, " 0x%08X : IfInRuleCheckerP4Hit\n",
7380 sblk->stat_IfInRuleCheckerP4Hit);
7383 if (sblk->stat_CatchupInRuleCheckerDiscards) {
7384 if_printf(ifp, " 0x%08X : "
7385 "CatchupInRuleCheckerDiscards\n",
7386 sblk->stat_CatchupInRuleCheckerDiscards);
7389 if (sblk->stat_CatchupInFTQDiscards) {
7390 if_printf(ifp, " 0x%08X : CatchupInFTQDiscards\n",
7391 sblk->stat_CatchupInFTQDiscards);
7394 if (sblk->stat_CatchupInMBUFDiscards) {
7395 if_printf(ifp, " 0x%08X : CatchupInMBUFDiscards\n",
7396 sblk->stat_CatchupInMBUFDiscards);
7399 if (sblk->stat_CatchupInRuleCheckerP4Hit) {
7400 if_printf(ifp, " 0x%08X : CatchupInRuleCheckerP4Hit\n",
7401 sblk->stat_CatchupInRuleCheckerP4Hit);
7405 "----------------------------"
7407 "----------------------------\n");
7411 /****************************************************************************/
7412 /* Prints out a summary of the driver state. */
7416 /****************************************************************************/
7418 bce_dump_driver_state(struct bce_softc *sc)
7420 struct ifnet *ifp = &sc->arpcom.ac_if;
7421 uint32_t val_hi, val_lo;
7424 "-----------------------------"
7426 "-----------------------------\n");
7428 val_hi = BCE_ADDR_HI(sc);
7429 val_lo = BCE_ADDR_LO(sc);
7430 if_printf(ifp, "0x%08X:%08X - (sc) driver softc structure "
7431 "virtual address\n", val_hi, val_lo);
7433 val_hi = BCE_ADDR_HI(sc->status_block);
7434 val_lo = BCE_ADDR_LO(sc->status_block);
7435 if_printf(ifp, "0x%08X:%08X - (sc->status_block) status block "
7436 "virtual address\n", val_hi, val_lo);
7438 val_hi = BCE_ADDR_HI(sc->stats_block);
7439 val_lo = BCE_ADDR_LO(sc->stats_block);
7440 if_printf(ifp, "0x%08X:%08X - (sc->stats_block) statistics block "
7441 "virtual address\n", val_hi, val_lo);
7443 val_hi = BCE_ADDR_HI(sc->tx_bd_chain);
7444 val_lo = BCE_ADDR_LO(sc->tx_bd_chain);
7445 if_printf(ifp, "0x%08X:%08X - (sc->tx_bd_chain) tx_bd chain "
7446 "virtual address\n", val_hi, val_lo);
7448 val_hi = BCE_ADDR_HI(sc->rx_bd_chain);
7449 val_lo = BCE_ADDR_LO(sc->rx_bd_chain);
7450 if_printf(ifp, "0x%08X:%08X - (sc->rx_bd_chain) rx_bd chain "
7451 "virtual address\n", val_hi, val_lo);
7453 val_hi = BCE_ADDR_HI(sc->tx_mbuf_ptr);
7454 val_lo = BCE_ADDR_LO(sc->tx_mbuf_ptr);
7455 if_printf(ifp, "0x%08X:%08X - (sc->tx_mbuf_ptr) tx mbuf chain "
7456 "virtual address\n", val_hi, val_lo);
7458 val_hi = BCE_ADDR_HI(sc->rx_mbuf_ptr);
7459 val_lo = BCE_ADDR_LO(sc->rx_mbuf_ptr);
7460 if_printf(ifp, "0x%08X:%08X - (sc->rx_mbuf_ptr) rx mbuf chain "
7461 "virtual address\n", val_hi, val_lo);
7463 if_printf(ifp, " 0x%08X - (sc->interrupts_generated) "
7464 "h/w intrs\n", sc->interrupts_generated);
7466 if_printf(ifp, " 0x%08X - (sc->rx_interrupts) "
7467 "rx interrupts handled\n", sc->rx_interrupts);
7469 if_printf(ifp, " 0x%08X - (sc->tx_interrupts) "
7470 "tx interrupts handled\n", sc->tx_interrupts);
7472 if_printf(ifp, " 0x%08X - (sc->last_status_idx) "
7473 "status block index\n", sc->last_status_idx);
7475 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_prod) "
7476 "tx producer index\n",
7477 sc->tx_prod, (uint16_t)TX_CHAIN_IDX(sc, sc->tx_prod));
7479 if_printf(ifp, " 0x%04X(0x%04X) - (sc->tx_cons) "
7480 "tx consumer index\n",
7481 sc->tx_cons, (uint16_t)TX_CHAIN_IDX(sc, sc->tx_cons));
7483 if_printf(ifp, " 0x%08X - (sc->tx_prod_bseq) "
7484 "tx producer bseq index\n", sc->tx_prod_bseq);
7486 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_prod) "
7487 "rx producer index\n",
7488 sc->rx_prod, (uint16_t)RX_CHAIN_IDX(sc, sc->rx_prod));
7490 if_printf(ifp, " 0x%04X(0x%04X) - (sc->rx_cons) "
7491 "rx consumer index\n",
7492 sc->rx_cons, (uint16_t)RX_CHAIN_IDX(sc, sc->rx_cons));
7494 if_printf(ifp, " 0x%08X - (sc->rx_prod_bseq) "
7495 "rx producer bseq index\n", sc->rx_prod_bseq);
7497 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7498 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7500 if_printf(ifp, " 0x%08X - (sc->free_rx_bd) "
7501 "free rx_bd's\n", sc->free_rx_bd);
7503 if_printf(ifp, "0x%08X/%08X - (sc->rx_low_watermark) rx "
7504 "low watermark\n", sc->rx_low_watermark, sc->max_rx_bd);
7506 if_printf(ifp, " 0x%08X - (sc->txmbuf_alloc) "
7507 "tx mbufs allocated\n", sc->tx_mbuf_alloc);
7509 if_printf(ifp, " 0x%08X - (sc->rx_mbuf_alloc) "
7510 "rx mbufs allocated\n", sc->rx_mbuf_alloc);
7512 if_printf(ifp, " 0x%08X - (sc->used_tx_bd) used tx_bd's\n",
7515 if_printf(ifp, "0x%08X/%08X - (sc->tx_hi_watermark) tx hi watermark\n",
7516 sc->tx_hi_watermark, sc->max_tx_bd);
7518 if_printf(ifp, " 0x%08X - (sc->mbuf_alloc_failed) "
7519 "failed mbuf alloc\n", sc->mbuf_alloc_failed);
7522 "----------------------------"
7524 "----------------------------\n");
7528 /****************************************************************************/
7529 /* Prints out the hardware state through a summary of important registers, */
7530 /* followed by a complete register dump. */
7534 /****************************************************************************/
7536 bce_dump_hw_state(struct bce_softc *sc)
7538 struct ifnet *ifp = &sc->arpcom.ac_if;
7543 "----------------------------"
7545 "----------------------------\n");
7547 if_printf(ifp, "%s - bootcode version\n", sc->bce_bc_ver);
7549 val1 = REG_RD(sc, BCE_MISC_ENABLE_STATUS_BITS);
7550 if_printf(ifp, "0x%08X - (0x%06X) misc_enable_status_bits\n",
7551 val1, BCE_MISC_ENABLE_STATUS_BITS);
7553 val1 = REG_RD(sc, BCE_DMA_STATUS);
7554 if_printf(ifp, "0x%08X - (0x%04X) dma_status\n", val1, BCE_DMA_STATUS);
7556 val1 = REG_RD(sc, BCE_CTX_STATUS);
7557 if_printf(ifp, "0x%08X - (0x%04X) ctx_status\n", val1, BCE_CTX_STATUS);
7559 val1 = REG_RD(sc, BCE_EMAC_STATUS);
7560 if_printf(ifp, "0x%08X - (0x%04X) emac_status\n",
7561 val1, BCE_EMAC_STATUS);
7563 val1 = REG_RD(sc, BCE_RPM_STATUS);
7564 if_printf(ifp, "0x%08X - (0x%04X) rpm_status\n", val1, BCE_RPM_STATUS);
7566 val1 = REG_RD(sc, BCE_TBDR_STATUS);
7567 if_printf(ifp, "0x%08X - (0x%04X) tbdr_status\n",
7568 val1, BCE_TBDR_STATUS);
7570 val1 = REG_RD(sc, BCE_TDMA_STATUS);
7571 if_printf(ifp, "0x%08X - (0x%04X) tdma_status\n",
7572 val1, BCE_TDMA_STATUS);
7574 val1 = REG_RD(sc, BCE_HC_STATUS);
7575 if_printf(ifp, "0x%08X - (0x%06X) hc_status\n", val1, BCE_HC_STATUS);
7577 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7578 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7579 val1, BCE_TXP_CPU_STATE);
7581 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7582 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7583 val1, BCE_TPAT_CPU_STATE);
7585 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7586 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7587 val1, BCE_RXP_CPU_STATE);
7589 val1 = REG_RD_IND(sc, BCE_COM_CPU_STATE);
7590 if_printf(ifp, "0x%08X - (0x%06X) com_cpu_state\n",
7591 val1, BCE_COM_CPU_STATE);
7593 val1 = REG_RD_IND(sc, BCE_MCP_CPU_STATE);
7594 if_printf(ifp, "0x%08X - (0x%06X) mcp_cpu_state\n",
7595 val1, BCE_MCP_CPU_STATE);
7597 val1 = REG_RD_IND(sc, BCE_CP_CPU_STATE);
7598 if_printf(ifp, "0x%08X - (0x%06X) cp_cpu_state\n",
7599 val1, BCE_CP_CPU_STATE);
7602 "----------------------------"
7604 "----------------------------\n");
7607 "----------------------------"
7609 "----------------------------\n");
7611 for (i = 0x400; i < 0x8000; i += 0x10) {
7612 if_printf(ifp, "0x%04X: 0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7614 REG_RD(sc, i + 0x4),
7615 REG_RD(sc, i + 0x8),
7616 REG_RD(sc, i + 0xc));
7620 "----------------------------"
7622 "----------------------------\n");
7626 /****************************************************************************/
7627 /* Prints out the TXP state. */
7631 /****************************************************************************/
7633 bce_dump_txp_state(struct bce_softc *sc)
7635 struct ifnet *ifp = &sc->arpcom.ac_if;
7640 "----------------------------"
7642 "----------------------------\n");
7644 val1 = REG_RD_IND(sc, BCE_TXP_CPU_MODE);
7645 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_mode\n",
7646 val1, BCE_TXP_CPU_MODE);
7648 val1 = REG_RD_IND(sc, BCE_TXP_CPU_STATE);
7649 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_state\n",
7650 val1, BCE_TXP_CPU_STATE);
7652 val1 = REG_RD_IND(sc, BCE_TXP_CPU_EVENT_MASK);
7653 if_printf(ifp, "0x%08X - (0x%06X) txp_cpu_event_mask\n",
7654 val1, BCE_TXP_CPU_EVENT_MASK);
7657 "----------------------------"
7659 "----------------------------\n");
7661 for (i = BCE_TXP_CPU_MODE; i < 0x68000; i += 0x10) {
7662 /* Skip the big blank spaces */
7663 if (i < 0x454000 && i > 0x5ffff) {
7664 if_printf(ifp, "0x%04X: "
7665 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7667 REG_RD_IND(sc, i + 0x4),
7668 REG_RD_IND(sc, i + 0x8),
7669 REG_RD_IND(sc, i + 0xc));
7674 "----------------------------"
7676 "----------------------------\n");
7680 /****************************************************************************/
7681 /* Prints out the RXP state. */
7685 /****************************************************************************/
7687 bce_dump_rxp_state(struct bce_softc *sc)
7689 struct ifnet *ifp = &sc->arpcom.ac_if;
7694 "----------------------------"
7696 "----------------------------\n");
7698 val1 = REG_RD_IND(sc, BCE_RXP_CPU_MODE);
7699 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_mode\n",
7700 val1, BCE_RXP_CPU_MODE);
7702 val1 = REG_RD_IND(sc, BCE_RXP_CPU_STATE);
7703 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_state\n",
7704 val1, BCE_RXP_CPU_STATE);
7706 val1 = REG_RD_IND(sc, BCE_RXP_CPU_EVENT_MASK);
7707 if_printf(ifp, "0x%08X - (0x%06X) rxp_cpu_event_mask\n",
7708 val1, BCE_RXP_CPU_EVENT_MASK);
7711 "----------------------------"
7713 "----------------------------\n");
7715 for (i = BCE_RXP_CPU_MODE; i < 0xe8fff; i += 0x10) {
7716 /* Skip the big blank sapces */
7717 if (i < 0xc5400 || i > 0xdffff) {
7718 if_printf(ifp, "0x%04X: "
7719 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7721 REG_RD_IND(sc, i + 0x4),
7722 REG_RD_IND(sc, i + 0x8),
7723 REG_RD_IND(sc, i + 0xc));
7728 "----------------------------"
7730 "----------------------------\n");
7734 /****************************************************************************/
7735 /* Prints out the TPAT state. */
7739 /****************************************************************************/
7741 bce_dump_tpat_state(struct bce_softc *sc)
7743 struct ifnet *ifp = &sc->arpcom.ac_if;
7748 "----------------------------"
7750 "----------------------------\n");
7752 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_MODE);
7753 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_mode\n",
7754 val1, BCE_TPAT_CPU_MODE);
7756 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_STATE);
7757 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_state\n",
7758 val1, BCE_TPAT_CPU_STATE);
7760 val1 = REG_RD_IND(sc, BCE_TPAT_CPU_EVENT_MASK);
7761 if_printf(ifp, "0x%08X - (0x%06X) tpat_cpu_event_mask\n",
7762 val1, BCE_TPAT_CPU_EVENT_MASK);
7765 "----------------------------"
7767 "----------------------------\n");
7769 for (i = BCE_TPAT_CPU_MODE; i < 0xa3fff; i += 0x10) {
7770 /* Skip the big blank spaces */
7771 if (i < 0x854000 && i > 0x9ffff) {
7772 if_printf(ifp, "0x%04X: "
7773 "0x%08X 0x%08X 0x%08X 0x%08X\n", i,
7775 REG_RD_IND(sc, i + 0x4),
7776 REG_RD_IND(sc, i + 0x8),
7777 REG_RD_IND(sc, i + 0xc));
7782 "----------------------------"
7784 "----------------------------\n");
7788 /****************************************************************************/
7789 /* Prints out the driver state and then enters the debugger. */
7793 /****************************************************************************/
7795 bce_breakpoint(struct bce_softc *sc)
7798 bce_freeze_controller(sc);
7801 bce_dump_driver_state(sc);
7802 bce_dump_status_block(sc);
7803 bce_dump_tx_chain(sc, 0, TOTAL_TX_BD(sc));
7804 bce_dump_hw_state(sc);
7805 bce_dump_txp_state(sc);
7808 bce_unfreeze_controller(sc);
7811 /* Call the debugger. */
7815 #endif /* BCE_DEBUG */
7818 bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS)
7820 struct bce_softc *sc = arg1;
7822 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7823 &sc->bce_tx_quick_cons_trip_int,
7824 BCE_COALMASK_TX_BDS_INT);
7828 bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS)
7830 struct bce_softc *sc = arg1;
7832 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7833 &sc->bce_tx_quick_cons_trip,
7834 BCE_COALMASK_TX_BDS);
7838 bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS)
7840 struct bce_softc *sc = arg1;
7842 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7843 &sc->bce_tx_ticks_int,
7844 BCE_COALMASK_TX_TICKS_INT);
7848 bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS)
7850 struct bce_softc *sc = arg1;
7852 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7854 BCE_COALMASK_TX_TICKS);
7858 bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS)
7860 struct bce_softc *sc = arg1;
7862 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7863 &sc->bce_rx_quick_cons_trip_int,
7864 BCE_COALMASK_RX_BDS_INT);
7868 bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS)
7870 struct bce_softc *sc = arg1;
7872 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7873 &sc->bce_rx_quick_cons_trip,
7874 BCE_COALMASK_RX_BDS);
7878 bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS)
7880 struct bce_softc *sc = arg1;
7882 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7883 &sc->bce_rx_ticks_int,
7884 BCE_COALMASK_RX_TICKS_INT);
7888 bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS)
7890 struct bce_softc *sc = arg1;
7892 return bce_sysctl_coal_change(oidp, arg1, arg2, req,
7894 BCE_COALMASK_RX_TICKS);
7898 bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS, uint32_t *coal,
7899 uint32_t coalchg_mask)
7901 struct bce_softc *sc = arg1;
7902 struct ifnet *ifp = &sc->arpcom.ac_if;
7905 lwkt_serialize_enter(ifp->if_serializer);
7908 error = sysctl_handle_int(oidp, &v, 0, req);
7909 if (!error && req->newptr != NULL) {
7914 sc->bce_coalchg_mask |= coalchg_mask;
7918 lwkt_serialize_exit(ifp->if_serializer);
7923 bce_coal_change(struct bce_softc *sc)
7925 struct ifnet *ifp = &sc->arpcom.ac_if;
7927 ASSERT_SERIALIZED(ifp->if_serializer);
7929 if ((ifp->if_flags & IFF_RUNNING) == 0) {
7930 sc->bce_coalchg_mask = 0;
7934 if (sc->bce_coalchg_mask &
7935 (BCE_COALMASK_TX_BDS | BCE_COALMASK_TX_BDS_INT)) {
7936 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
7937 (sc->bce_tx_quick_cons_trip_int << 16) |
7938 sc->bce_tx_quick_cons_trip);
7940 if_printf(ifp, "tx_bds %u, tx_bds_int %u\n",
7941 sc->bce_tx_quick_cons_trip,
7942 sc->bce_tx_quick_cons_trip_int);
7946 if (sc->bce_coalchg_mask &
7947 (BCE_COALMASK_TX_TICKS | BCE_COALMASK_TX_TICKS_INT)) {
7948 REG_WR(sc, BCE_HC_TX_TICKS,
7949 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
7951 if_printf(ifp, "tx_ticks %u, tx_ticks_int %u\n",
7952 sc->bce_tx_ticks, sc->bce_tx_ticks_int);
7956 if (sc->bce_coalchg_mask &
7957 (BCE_COALMASK_RX_BDS | BCE_COALMASK_RX_BDS_INT)) {
7958 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
7959 (sc->bce_rx_quick_cons_trip_int << 16) |
7960 sc->bce_rx_quick_cons_trip);
7962 if_printf(ifp, "rx_bds %u, rx_bds_int %u\n",
7963 sc->bce_rx_quick_cons_trip,
7964 sc->bce_rx_quick_cons_trip_int);
7968 if (sc->bce_coalchg_mask &
7969 (BCE_COALMASK_RX_TICKS | BCE_COALMASK_RX_TICKS_INT)) {
7970 REG_WR(sc, BCE_HC_RX_TICKS,
7971 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
7973 if_printf(ifp, "rx_ticks %u, rx_ticks_int %u\n",
7974 sc->bce_rx_ticks, sc->bce_rx_ticks_int);
7978 sc->bce_coalchg_mask = 0;
7982 bce_tso_setup(struct bce_softc *sc, struct mbuf **mp,
7983 uint16_t *flags0, uint16_t *mss0)
7987 int thoff, iphlen, hoff;
7990 KASSERT(M_WRITABLE(m), ("TSO mbuf not writable"));
7992 hoff = m->m_pkthdr.csum_lhlen;
7993 iphlen = m->m_pkthdr.csum_iphlen;
7994 thoff = m->m_pkthdr.csum_thlen;
7996 KASSERT(hoff >= sizeof(struct ether_header),
7997 ("invalid ether header len %d", hoff));
7998 KASSERT(iphlen >= sizeof(struct ip),
7999 ("invalid ip header len %d", iphlen));
8000 KASSERT(thoff >= sizeof(struct tcphdr),
8001 ("invalid tcp header len %d", thoff));
8003 if (__predict_false(m->m_len < hoff + iphlen + thoff)) {
8004 m = m_pullup(m, hoff + iphlen + thoff);
8012 /* Set the LSO flag in the TX BD */
8013 flags = TX_BD_FLAGS_SW_LSO;
8015 /* Set the length of IP + TCP options (in 32 bit words) */
8016 flags |= (((iphlen + thoff -
8017 sizeof(struct ip) - sizeof(struct tcphdr)) >> 2) << 8);
8019 *mss0 = htole16(m->m_pkthdr.tso_segsz);