2 * Copyright (c) 2006-2007 Broadcom Corporation
3 * David Christensen <davidch@broadcom.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Broadcom Corporation nor the name of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written consent.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/dev/bce/if_bce.c,v 1.31 2007/05/16 23:34:11 davidch Exp $
34 * The following controllers are supported by this driver:
42 * The following controllers are not supported by this driver:
48 * BCM5709S A0, A1, B0, B1, B2, C0
52 #include "opt_polling.h"
54 #include <sys/param.h>
56 #include <sys/endian.h>
57 #include <sys/kernel.h>
58 #include <sys/interrupt.h>
60 #include <sys/malloc.h>
61 #include <sys/queue.h>
63 #include <sys/random.h>
66 #include <sys/serialize.h>
67 #include <sys/socket.h>
68 #include <sys/sockio.h>
69 #include <sys/sysctl.h>
72 #include <net/ethernet.h>
74 #include <net/if_arp.h>
75 #include <net/if_dl.h>
76 #include <net/if_media.h>
77 #include <net/if_types.h>
78 #include <net/ifq_var.h>
79 #include <net/vlan/if_vlan_var.h>
80 #include <net/vlan/if_vlan_ether.h>
82 #include <dev/netif/mii_layer/mii.h>
83 #include <dev/netif/mii_layer/miivar.h>
85 #include <bus/pci/pcireg.h>
86 #include <bus/pci/pcivar.h>
88 #include "miibus_if.h"
90 #include <dev/netif/bce/if_bcereg.h>
91 #include <dev/netif/bce/if_bcefw.h>
93 /****************************************************************************/
94 /* BCE Debug Options */
95 /****************************************************************************/
98 static uint32_t bce_debug = BCE_WARN;
102 * 1 = 1 in 2,147,483,648
103 * 256 = 1 in 8,388,608
104 * 2048 = 1 in 1,048,576
105 * 65536 = 1 in 32,768
106 * 1048576 = 1 in 2,048
109 * 1073741824 = 1 in 2
111 * bce_debug_l2fhdr_status_check:
112 * How often the l2_fhdr frame error check will fail.
114 * bce_debug_unexpected_attention:
115 * How often the unexpected attention check will fail.
117 * bce_debug_mbuf_allocation_failure:
118 * How often to simulate an mbuf allocation failure.
120 * bce_debug_dma_map_addr_failure:
121 * How often to simulate a DMA mapping failure.
123 * bce_debug_bootcode_running_failure:
124 * How often to simulate a bootcode failure.
126 static int bce_debug_l2fhdr_status_check = 0;
127 static int bce_debug_unexpected_attention = 0;
128 static int bce_debug_mbuf_allocation_failure = 0;
129 static int bce_debug_dma_map_addr_failure = 0;
130 static int bce_debug_bootcode_running_failure = 0;
132 #endif /* BCE_DEBUG */
135 /****************************************************************************/
136 /* PCI Device ID Table */
138 /* Used by bce_probe() to identify the devices supported by this driver. */
139 /****************************************************************************/
140 #define BCE_DEVDESC_MAX 64
142 static struct bce_type bce_devs[] = {
143 /* BCM5706C Controllers and OEM boards. */
144 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3101,
145 "HP NC370T Multifunction Gigabit Server Adapter" },
146 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3106,
147 "HP NC370i Multifunction Gigabit Server Adapter" },
148 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x3070,
149 "HP NC380T PCIe DP Multifunc Gig Server Adapter" },
150 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, HP_VENDORID, 0x1709,
151 "HP NC371i Multifunction Gigabit Server Adapter" },
152 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706, PCI_ANY_ID, PCI_ANY_ID,
153 "Broadcom NetXtreme II BCM5706 1000Base-T" },
155 /* BCM5706S controllers and OEM boards. */
156 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, HP_VENDORID, 0x3102,
157 "HP NC370F Multifunction Gigabit Server Adapter" },
158 { BRCM_VENDORID, BRCM_DEVICEID_BCM5706S, PCI_ANY_ID, PCI_ANY_ID,
159 "Broadcom NetXtreme II BCM5706 1000Base-SX" },
161 /* BCM5708C controllers and OEM boards. */
162 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7037,
163 "HP NC373T PCIe Multifunction Gig Server Adapter" },
164 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7038,
165 "HP NC373i Multifunction Gigabit Server Adapter" },
166 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, HP_VENDORID, 0x7045,
167 "HP NC374m PCIe Multifunction Adapter" },
168 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708, PCI_ANY_ID, PCI_ANY_ID,
169 "Broadcom NetXtreme II BCM5708 1000Base-T" },
171 /* BCM5708S controllers and OEM boards. */
172 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x1706,
173 "HP NC373m Multifunction Gigabit Server Adapter" },
174 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703b,
175 "HP NC373i Multifunction Gigabit Server Adapter" },
176 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, HP_VENDORID, 0x703d,
177 "HP NC373F PCIe Multifunc Giga Server Adapter" },
178 { BRCM_VENDORID, BRCM_DEVICEID_BCM5708S, PCI_ANY_ID, PCI_ANY_ID,
179 "Broadcom NetXtreme II BCM5708S 1000Base-T" },
181 /* BCM5709C controllers and OEM boards. */
182 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7055,
183 "HP NC382i DP Multifunction Gigabit Server Adapter" },
184 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, HP_VENDORID, 0x7059,
185 "HP NC382T PCIe DP Multifunction Gigabit Server Adapter" },
186 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709, PCI_ANY_ID, PCI_ANY_ID,
187 "Broadcom NetXtreme II BCM5709 1000Base-T" },
189 /* BCM5709S controllers and OEM boards. */
190 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x171d,
191 "HP NC382m DP 1GbE Multifunction BL-c Adapter" },
192 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, HP_VENDORID, 0x7056,
193 "HP NC382i DP Multifunction Gigabit Server Adapter" },
194 { BRCM_VENDORID, BRCM_DEVICEID_BCM5709S, PCI_ANY_ID, PCI_ANY_ID,
195 "Broadcom NetXtreme II BCM5709 1000Base-SX" },
197 /* BCM5716 controllers and OEM boards. */
198 { BRCM_VENDORID, BRCM_DEVICEID_BCM5716, PCI_ANY_ID, PCI_ANY_ID,
199 "Broadcom NetXtreme II BCM5716 1000Base-T" },
205 /****************************************************************************/
206 /* Supported Flash NVRAM device data. */
207 /****************************************************************************/
208 static const struct flash_spec flash_table[] =
210 #define BUFFERED_FLAGS (BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
211 #define NONBUFFERED_FLAGS (BCE_NV_WREN)
214 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
215 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
216 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
218 /* Expansion entry 0001 */
219 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
220 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
221 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
223 /* Saifun SA25F010 (non-buffered flash) */
224 /* strap, cfg1, & write1 need updates */
225 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
226 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
227 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
228 "Non-buffered flash (128kB)"},
229 /* Saifun SA25F020 (non-buffered flash) */
230 /* strap, cfg1, & write1 need updates */
231 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
232 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
233 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
234 "Non-buffered flash (256kB)"},
235 /* Expansion entry 0100 */
236 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
237 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
238 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
240 /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
241 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
242 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
243 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
244 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
245 /* Entry 0110: ST M45PE20 (non-buffered flash)*/
246 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
247 NONBUFFERED_FLAGS, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
248 ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
249 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
250 /* Saifun SA25F005 (non-buffered flash) */
251 /* strap, cfg1, & write1 need updates */
252 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
253 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
254 SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
255 "Non-buffered flash (64kB)"},
257 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
258 BUFFERED_FLAGS, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
259 SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
261 /* Expansion entry 1001 */
262 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
263 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
264 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
266 /* Expansion entry 1010 */
267 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
268 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
269 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
271 /* ATMEL AT45DB011B (buffered flash) */
272 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
273 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
274 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
275 "Buffered flash (128kB)"},
276 /* Expansion entry 1100 */
277 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
278 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
279 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
281 /* Expansion entry 1101 */
282 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
283 NONBUFFERED_FLAGS, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
284 SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
286 /* Ateml Expansion entry 1110 */
287 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
288 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
289 BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
290 "Entry 1110 (Atmel)"},
291 /* ATMEL AT45DB021B (buffered flash) */
292 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
293 BUFFERED_FLAGS, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
294 BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
295 "Buffered flash (256kB)"},
299 * The BCM5709 controllers transparently handle the
300 * differences between Atmel 264 byte pages and all
301 * flash devices which use 256 byte pages, so no
302 * logical-to-physical mapping is required in the
305 static struct flash_spec flash_5709 = {
306 .flags = BCE_NV_BUFFERED,
307 .page_bits = BCM5709_FLASH_PAGE_BITS,
308 .page_size = BCM5709_FLASH_PAGE_SIZE,
309 .addr_mask = BCM5709_FLASH_BYTE_ADDR_MASK,
310 .total_size = BUFFERED_FLASH_TOTAL_SIZE * 2,
311 .name = "5709/5716 buffered flash (256kB)",
315 /****************************************************************************/
316 /* DragonFly device entry points. */
317 /****************************************************************************/
318 static int bce_probe(device_t);
319 static int bce_attach(device_t);
320 static int bce_detach(device_t);
321 static void bce_shutdown(device_t);
323 /****************************************************************************/
324 /* BCE Debug Data Structure Dump Routines */
325 /****************************************************************************/
327 static void bce_dump_mbuf(struct bce_softc *, struct mbuf *);
328 static void bce_dump_tx_mbuf_chain(struct bce_softc *, int, int);
329 static void bce_dump_rx_mbuf_chain(struct bce_softc *, int, int);
330 static void bce_dump_txbd(struct bce_softc *, int, struct tx_bd *);
331 static void bce_dump_rxbd(struct bce_softc *, int, struct rx_bd *);
332 static void bce_dump_l2fhdr(struct bce_softc *, int,
333 struct l2_fhdr *) __unused;
334 static void bce_dump_tx_chain(struct bce_softc *, int, int);
335 static void bce_dump_rx_chain(struct bce_softc *, int, int);
336 static void bce_dump_status_block(struct bce_softc *);
337 static void bce_dump_driver_state(struct bce_softc *);
338 static void bce_dump_stats_block(struct bce_softc *) __unused;
339 static void bce_dump_hw_state(struct bce_softc *);
340 static void bce_dump_txp_state(struct bce_softc *);
341 static void bce_dump_rxp_state(struct bce_softc *) __unused;
342 static void bce_dump_tpat_state(struct bce_softc *) __unused;
343 static void bce_freeze_controller(struct bce_softc *) __unused;
344 static void bce_unfreeze_controller(struct bce_softc *) __unused;
345 static void bce_breakpoint(struct bce_softc *);
346 #endif /* BCE_DEBUG */
349 /****************************************************************************/
350 /* BCE Register/Memory Access Routines */
351 /****************************************************************************/
352 static uint32_t bce_reg_rd_ind(struct bce_softc *, uint32_t);
353 static void bce_reg_wr_ind(struct bce_softc *, uint32_t, uint32_t);
354 static void bce_shmem_wr(struct bce_softc *, uint32_t, uint32_t);
355 static uint32_t bce_shmem_rd(struct bce_softc *, u32);
356 static void bce_ctx_wr(struct bce_softc *, uint32_t, uint32_t, uint32_t);
357 static int bce_miibus_read_reg(device_t, int, int);
358 static int bce_miibus_write_reg(device_t, int, int, int);
359 static void bce_miibus_statchg(device_t);
362 /****************************************************************************/
363 /* BCE NVRAM Access Routines */
364 /****************************************************************************/
365 static int bce_acquire_nvram_lock(struct bce_softc *);
366 static int bce_release_nvram_lock(struct bce_softc *);
367 static void bce_enable_nvram_access(struct bce_softc *);
368 static void bce_disable_nvram_access(struct bce_softc *);
369 static int bce_nvram_read_dword(struct bce_softc *, uint32_t, uint8_t *,
371 static int bce_init_nvram(struct bce_softc *);
372 static int bce_nvram_read(struct bce_softc *, uint32_t, uint8_t *, int);
373 static int bce_nvram_test(struct bce_softc *);
375 /****************************************************************************/
376 /* BCE DMA Allocate/Free Routines */
377 /****************************************************************************/
378 static int bce_dma_alloc(struct bce_softc *);
379 static void bce_dma_free(struct bce_softc *);
380 static void bce_dma_map_addr(void *, bus_dma_segment_t *, int, int);
382 /****************************************************************************/
383 /* BCE Firmware Synchronization and Load */
384 /****************************************************************************/
385 static int bce_fw_sync(struct bce_softc *, uint32_t);
386 static void bce_load_rv2p_fw(struct bce_softc *, uint32_t *,
388 static void bce_load_cpu_fw(struct bce_softc *, struct cpu_reg *,
390 static void bce_start_cpu(struct bce_softc *, struct cpu_reg *);
391 static void bce_halt_cpu(struct bce_softc *, struct cpu_reg *);
392 static void bce_start_rxp_cpu(struct bce_softc *);
393 static void bce_init_rxp_cpu(struct bce_softc *);
394 static void bce_init_txp_cpu(struct bce_softc *);
395 static void bce_init_tpat_cpu(struct bce_softc *);
396 static void bce_init_cp_cpu(struct bce_softc *);
397 static void bce_init_com_cpu(struct bce_softc *);
398 static void bce_init_cpus(struct bce_softc *);
400 static void bce_stop(struct bce_softc *);
401 static int bce_reset(struct bce_softc *, uint32_t);
402 static int bce_chipinit(struct bce_softc *);
403 static int bce_blockinit(struct bce_softc *);
404 static int bce_newbuf_std(struct bce_softc *, uint16_t *, uint16_t *,
406 static void bce_setup_rxdesc_std(struct bce_softc *, uint16_t, uint32_t *);
407 static void bce_probe_pci_caps(struct bce_softc *);
408 static void bce_print_adapter_info(struct bce_softc *);
409 static void bce_get_media(struct bce_softc *);
411 static void bce_init_tx_context(struct bce_softc *);
412 static int bce_init_tx_chain(struct bce_softc *);
413 static void bce_init_rx_context(struct bce_softc *);
414 static int bce_init_rx_chain(struct bce_softc *);
415 static void bce_free_rx_chain(struct bce_softc *);
416 static void bce_free_tx_chain(struct bce_softc *);
418 static int bce_encap(struct bce_softc *, struct mbuf **);
419 static void bce_start(struct ifnet *);
420 static int bce_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
421 static void bce_watchdog(struct ifnet *);
422 static int bce_ifmedia_upd(struct ifnet *);
423 static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
424 static void bce_init(void *);
425 static void bce_mgmt_init(struct bce_softc *);
427 static void bce_init_ctx(struct bce_softc *);
428 static void bce_get_mac_addr(struct bce_softc *);
429 static void bce_set_mac_addr(struct bce_softc *);
430 static void bce_phy_intr(struct bce_softc *);
431 static void bce_rx_intr(struct bce_softc *, int);
432 static void bce_tx_intr(struct bce_softc *);
433 static void bce_disable_intr(struct bce_softc *);
434 static void bce_enable_intr(struct bce_softc *, int);
436 #ifdef DEVICE_POLLING
437 static void bce_poll(struct ifnet *, enum poll_cmd, int);
439 static void bce_intr(void *);
440 static void bce_set_rx_mode(struct bce_softc *);
441 static void bce_stats_update(struct bce_softc *);
442 static void bce_tick(void *);
443 static void bce_tick_serialized(struct bce_softc *);
444 static void bce_pulse(void *);
445 static void bce_add_sysctls(struct bce_softc *);
447 static void bce_coal_change(struct bce_softc *);
448 static int bce_sysctl_tx_bds_int(SYSCTL_HANDLER_ARGS);
449 static int bce_sysctl_tx_bds(SYSCTL_HANDLER_ARGS);
450 static int bce_sysctl_tx_ticks_int(SYSCTL_HANDLER_ARGS);
451 static int bce_sysctl_tx_ticks(SYSCTL_HANDLER_ARGS);
452 static int bce_sysctl_rx_bds_int(SYSCTL_HANDLER_ARGS);
453 static int bce_sysctl_rx_bds(SYSCTL_HANDLER_ARGS);
454 static int bce_sysctl_rx_ticks_int(SYSCTL_HANDLER_ARGS);
455 static int bce_sysctl_rx_ticks(SYSCTL_HANDLER_ARGS);
456 static int bce_sysctl_coal_change(SYSCTL_HANDLER_ARGS,
457 uint32_t *, uint32_t);
461 * Don't set bce_tx_ticks_int/bce_tx_ticks to 1023. Linux's bnx2
462 * takes 1023 as the TX ticks limit. However, using 1023 will
463 * cause 5708(B2) to generate extra interrupts (~2000/s) even when
464 * there is _no_ network activity on the NIC.
466 static uint32_t bce_tx_bds_int = 255; /* bcm: 20 */
467 static uint32_t bce_tx_bds = 255; /* bcm: 20 */
468 static uint32_t bce_tx_ticks_int = 1022; /* bcm: 80 */
469 static uint32_t bce_tx_ticks = 1022; /* bcm: 80 */
470 static uint32_t bce_rx_bds_int = 128; /* bcm: 6 */
471 static uint32_t bce_rx_bds = 128; /* bcm: 6 */
472 static uint32_t bce_rx_ticks_int = 125; /* bcm: 18 */
473 static uint32_t bce_rx_ticks = 125; /* bcm: 18 */
475 TUNABLE_INT("hw.bce.tx_bds_int", &bce_tx_bds_int);
476 TUNABLE_INT("hw.bce.tx_bds", &bce_tx_bds);
477 TUNABLE_INT("hw.bce.tx_ticks_int", &bce_tx_ticks_int);
478 TUNABLE_INT("hw.bce.tx_ticks", &bce_tx_ticks);
479 TUNABLE_INT("hw.bce.rx_bds_int", &bce_rx_bds_int);
480 TUNABLE_INT("hw.bce.rx_bds", &bce_rx_bds);
481 TUNABLE_INT("hw.bce.rx_ticks_int", &bce_rx_ticks_int);
482 TUNABLE_INT("hw.bce.rx_ticks", &bce_rx_ticks);
484 /****************************************************************************/
485 /* DragonFly device dispatch table. */
486 /****************************************************************************/
487 static device_method_t bce_methods[] = {
488 /* Device interface */
489 DEVMETHOD(device_probe, bce_probe),
490 DEVMETHOD(device_attach, bce_attach),
491 DEVMETHOD(device_detach, bce_detach),
492 DEVMETHOD(device_shutdown, bce_shutdown),
495 DEVMETHOD(bus_print_child, bus_generic_print_child),
496 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
499 DEVMETHOD(miibus_readreg, bce_miibus_read_reg),
500 DEVMETHOD(miibus_writereg, bce_miibus_write_reg),
501 DEVMETHOD(miibus_statchg, bce_miibus_statchg),
506 static driver_t bce_driver = {
509 sizeof(struct bce_softc)
512 static devclass_t bce_devclass;
515 DECLARE_DUMMY_MODULE(if_bce);
516 MODULE_DEPEND(bce, miibus, 1, 1, 1);
517 DRIVER_MODULE(if_bce, pci, bce_driver, bce_devclass, NULL, NULL);
518 DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
521 /****************************************************************************/
522 /* Device probe function. */
524 /* Compares the device to the driver's list of supported devices and */
525 /* reports back to the OS whether this is the right driver for the device. */
528 /* BUS_PROBE_DEFAULT on success, positive value on failure. */
529 /****************************************************************************/
531 bce_probe(device_t dev)
534 uint16_t vid, did, svid, sdid;
536 /* Get the data for the device to be probed. */
537 vid = pci_get_vendor(dev);
538 did = pci_get_device(dev);
539 svid = pci_get_subvendor(dev);
540 sdid = pci_get_subdevice(dev);
542 /* Look through the list of known devices for a match. */
543 for (t = bce_devs; t->bce_name != NULL; ++t) {
544 if (vid == t->bce_vid && did == t->bce_did &&
545 (svid == t->bce_svid || t->bce_svid == PCI_ANY_ID) &&
546 (sdid == t->bce_sdid || t->bce_sdid == PCI_ANY_ID)) {
547 uint32_t revid = pci_read_config(dev, PCIR_REVID, 4);
550 descbuf = kmalloc(BCE_DEVDESC_MAX, M_TEMP, M_WAITOK);
552 /* Print out the device identity. */
553 ksnprintf(descbuf, BCE_DEVDESC_MAX, "%s (%c%d)",
555 ((revid & 0xf0) >> 4) + 'A', revid & 0xf);
557 device_set_desc_copy(dev, descbuf);
558 kfree(descbuf, M_TEMP);
566 /****************************************************************************/
567 /* PCI Capabilities Probe Function. */
569 /* Walks the PCI capabiites list for the device to find what features are */
574 /****************************************************************************/
576 bce_print_adapter_info(struct bce_softc *sc)
578 device_printf(sc->bce_dev, "ASIC (0x%08X); ", sc->bce_chipid);
580 kprintf("Rev (%c%d); ", ((BCE_CHIP_ID(sc) & 0xf000) >> 12) + 'A',
581 ((BCE_CHIP_ID(sc) & 0x0ff0) >> 4));
584 if (sc->bce_flags & BCE_PCIE_FLAG) {
585 kprintf("Bus (PCIe x%d, ", sc->link_width);
586 switch (sc->link_speed) {
588 kprintf("2.5Gbps); ");
594 kprintf("Unknown link speed); ");
598 kprintf("Bus (PCI%s, %s, %dMHz); ",
599 ((sc->bce_flags & BCE_PCIX_FLAG) ? "-X" : ""),
600 ((sc->bce_flags & BCE_PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
604 /* Firmware version and device features. */
605 kprintf("B/C (%s)", sc->bce_bc_ver);
607 if ((sc->bce_flags & BCE_MFW_ENABLE_FLAG) ||
608 (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) {
610 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG)
611 kprintf("MFW[%s]", sc->bce_mfw_ver);
612 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
620 /****************************************************************************/
621 /* PCI Capabilities Probe Function. */
623 /* Walks the PCI capabiites list for the device to find what features are */
628 /****************************************************************************/
630 bce_probe_pci_caps(struct bce_softc *sc)
632 device_t dev = sc->bce_dev;
635 if (pci_is_pcix(dev))
636 sc->bce_cap_flags |= BCE_PCIX_CAPABLE_FLAG;
638 ptr = pci_get_pciecap_ptr(dev);
640 uint16_t link_status = pci_read_config(dev, ptr + 0x12, 2);
642 sc->link_speed = link_status & 0xf;
643 sc->link_width = (link_status >> 4) & 0x3f;
644 sc->bce_cap_flags |= BCE_PCIE_CAPABLE_FLAG;
645 sc->bce_flags |= BCE_PCIE_FLAG;
650 /****************************************************************************/
651 /* Device attach function. */
653 /* Allocates device resources, performs secondary chip identification, */
654 /* resets and initializes the hardware, and initializes driver instance */
658 /* 0 on success, positive value on failure. */
659 /****************************************************************************/
661 bce_attach(device_t dev)
663 struct bce_softc *sc = device_get_softc(dev);
664 struct ifnet *ifp = &sc->arpcom.ac_if;
673 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
675 pci_enable_busmaster(dev);
677 bce_probe_pci_caps(sc);
679 /* Allocate PCI memory resources. */
681 sc->bce_res_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
682 RF_ACTIVE | PCI_RF_DENSE);
683 if (sc->bce_res_mem == NULL) {
684 device_printf(dev, "PCI memory allocation failed\n");
687 sc->bce_btag = rman_get_bustag(sc->bce_res_mem);
688 sc->bce_bhandle = rman_get_bushandle(sc->bce_res_mem);
690 /* Allocate PCI IRQ resources. */
692 count = pci_msi_count(dev);
693 if (count == 1 && pci_alloc_msi(dev, &count) == 0) {
695 sc->bce_flags |= BCE_USING_MSI_FLAG;
699 sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
700 RF_SHAREABLE | RF_ACTIVE);
701 if (sc->bce_res_irq == NULL) {
702 device_printf(dev, "PCI map interrupt failed\n");
708 * Configure byte swap and enable indirect register access.
709 * Rely on CPU to do target byte swapping on big endian systems.
710 * Access to registers outside of PCI configurtion space are not
711 * valid until this is done.
713 pci_write_config(dev, BCE_PCICFG_MISC_CONFIG,
714 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
715 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP, 4);
717 /* Save ASIC revsion info. */
718 sc->bce_chipid = REG_RD(sc, BCE_MISC_ID);
720 /* Weed out any non-production controller revisions. */
721 switch (BCE_CHIP_ID(sc)) {
722 case BCE_CHIP_ID_5706_A0:
723 case BCE_CHIP_ID_5706_A1:
724 case BCE_CHIP_ID_5708_A0:
725 case BCE_CHIP_ID_5708_B0:
726 case BCE_CHIP_ID_5709_A0:
727 case BCE_CHIP_ID_5709_B0:
728 case BCE_CHIP_ID_5709_B1:
730 /* 5709C B2 seems to work fine */
731 case BCE_CHIP_ID_5709_B2:
733 device_printf(dev, "Unsupported chip id 0x%08x!\n",
740 * Find the base address for shared memory access.
741 * Newer versions of bootcode use a signature and offset
742 * while older versions use a fixed address.
744 val = REG_RD_IND(sc, BCE_SHM_HDR_SIGNATURE);
745 if ((val & BCE_SHM_HDR_SIGNATURE_SIG_MASK) ==
746 BCE_SHM_HDR_SIGNATURE_SIG) {
747 /* Multi-port devices use different offsets in shared memory. */
748 sc->bce_shmem_base = REG_RD_IND(sc,
749 BCE_SHM_HDR_ADDR_0 + (pci_get_function(sc->bce_dev) << 2));
751 sc->bce_shmem_base = HOST_VIEW_SHMEM_BASE;
753 DBPRINT(sc, BCE_INFO, "bce_shmem_base = 0x%08X\n", sc->bce_shmem_base);
755 /* Fetch the bootcode revision. */
756 val = bce_shmem_rd(sc, BCE_DEV_INFO_BC_REV);
757 for (i = 0, j = 0; i < 3; i++) {
761 num = (uint8_t)(val >> (24 - (i * 8)));
762 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
763 if (num >= k || !skip0 || k == 1) {
764 sc->bce_bc_ver[j++] = (num / k) + '0';
769 sc->bce_bc_ver[j++] = '.';
772 /* Check if any management firwmare is running. */
773 val = bce_shmem_rd(sc, BCE_PORT_FEATURE);
774 if (val & BCE_PORT_FEATURE_ASF_ENABLED) {
775 sc->bce_flags |= BCE_MFW_ENABLE_FLAG;
777 /* Allow time for firmware to enter the running state. */
778 for (i = 0; i < 30; i++) {
779 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION);
780 if (val & BCE_CONDITION_MFW_RUN_MASK)
786 /* Check the current bootcode state. */
787 val = bce_shmem_rd(sc, BCE_BC_STATE_CONDITION) &
788 BCE_CONDITION_MFW_RUN_MASK;
789 if (val != BCE_CONDITION_MFW_RUN_UNKNOWN &&
790 val != BCE_CONDITION_MFW_RUN_NONE) {
791 uint32_t addr = bce_shmem_rd(sc, BCE_MFW_VER_PTR);
793 for (i = 0, j = 0; j < 3; j++) {
794 val = bce_reg_rd_ind(sc, addr + j * 4);
796 memcpy(&sc->bce_mfw_ver[i], &val, 4);
801 /* Get PCI bus information (speed and type). */
802 val = REG_RD(sc, BCE_PCICFG_MISC_STATUS);
803 if (val & BCE_PCICFG_MISC_STATUS_PCIX_DET) {
806 sc->bce_flags |= BCE_PCIX_FLAG;
808 clkreg = REG_RD(sc, BCE_PCICFG_PCI_CLOCK_CONTROL_BITS) &
809 BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
811 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
812 sc->bus_speed_mhz = 133;
815 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
816 sc->bus_speed_mhz = 100;
819 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
820 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
821 sc->bus_speed_mhz = 66;
824 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
825 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
826 sc->bus_speed_mhz = 50;
829 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
830 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
831 case BCE_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
832 sc->bus_speed_mhz = 33;
836 if (val & BCE_PCICFG_MISC_STATUS_M66EN)
837 sc->bus_speed_mhz = 66;
839 sc->bus_speed_mhz = 33;
842 if (val & BCE_PCICFG_MISC_STATUS_32BIT_DET)
843 sc->bce_flags |= BCE_PCI_32BIT_FLAG;
845 /* Reset the controller. */
846 rc = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
850 /* Initialize the controller. */
851 rc = bce_chipinit(sc);
853 device_printf(dev, "Controller initialization failed!\n");
857 /* Perform NVRAM test. */
858 rc = bce_nvram_test(sc);
860 device_printf(dev, "NVRAM test failed!\n");
864 /* Fetch the permanent Ethernet MAC address. */
865 bce_get_mac_addr(sc);
868 * Trip points control how many BDs
869 * should be ready before generating an
870 * interrupt while ticks control how long
871 * a BD can sit in the chain before
872 * generating an interrupt. Set the default
873 * values for the RX and TX rings.
877 /* Force more frequent interrupts. */
878 sc->bce_tx_quick_cons_trip_int = 1;
879 sc->bce_tx_quick_cons_trip = 1;
880 sc->bce_tx_ticks_int = 0;
881 sc->bce_tx_ticks = 0;
883 sc->bce_rx_quick_cons_trip_int = 1;
884 sc->bce_rx_quick_cons_trip = 1;
885 sc->bce_rx_ticks_int = 0;
886 sc->bce_rx_ticks = 0;
888 sc->bce_tx_quick_cons_trip_int = bce_tx_bds_int;
889 sc->bce_tx_quick_cons_trip = bce_tx_bds;
890 sc->bce_tx_ticks_int = bce_tx_ticks_int;
891 sc->bce_tx_ticks = bce_tx_ticks;
893 sc->bce_rx_quick_cons_trip_int = bce_rx_bds_int;
894 sc->bce_rx_quick_cons_trip = bce_rx_bds;
895 sc->bce_rx_ticks_int = bce_rx_ticks_int;
896 sc->bce_rx_ticks = bce_rx_ticks;
899 /* Update statistics once every second. */
900 sc->bce_stats_ticks = 1000000 & 0xffff00;
902 /* Find the media type for the adapter. */
905 /* Allocate DMA memory resources. */
906 rc = bce_dma_alloc(sc);
908 device_printf(dev, "DMA resource allocation failed!\n");
912 /* Initialize the ifnet interface. */
914 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
915 ifp->if_ioctl = bce_ioctl;
916 ifp->if_start = bce_start;
917 ifp->if_init = bce_init;
918 ifp->if_watchdog = bce_watchdog;
919 #ifdef DEVICE_POLLING
920 ifp->if_poll = bce_poll;
922 ifp->if_mtu = ETHERMTU;
923 ifp->if_hwassist = BCE_IF_HWASSIST;
924 ifp->if_capabilities = BCE_IF_CAPABILITIES;
925 ifp->if_capenable = ifp->if_capabilities;
926 ifq_set_maxlen(&ifp->if_snd, USABLE_TX_BD);
927 ifq_set_ready(&ifp->if_snd);
929 if (sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)
930 ifp->if_baudrate = IF_Gbps(2.5);
932 ifp->if_baudrate = IF_Gbps(1);
934 /* Assume a standard 1500 byte MTU size for mbuf allocations. */
935 sc->mbuf_alloc_size = MCLBYTES;
937 /* Look for our PHY. */
938 rc = mii_phy_probe(dev, &sc->bce_miibus,
939 bce_ifmedia_upd, bce_ifmedia_sts);
941 device_printf(dev, "PHY probe failed!\n");
945 /* Attach to the Ethernet interface list. */
946 ether_ifattach(ifp, sc->eaddr, NULL);
948 callout_init(&sc->bce_tick_callout);
949 callout_init(&sc->bce_pulse_callout);
951 /* Hookup IRQ last. */
952 rc = bus_setup_intr(dev, sc->bce_res_irq, INTR_MPSAFE, bce_intr, sc,
953 &sc->bce_intrhand, ifp->if_serializer);
955 device_printf(dev, "Failed to setup IRQ!\n");
960 ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->bce_res_irq));
961 KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
963 /* Print some important debugging info. */
964 DBRUN(BCE_INFO, bce_dump_driver_state(sc));
966 /* Add the supported sysctls to the kernel. */
970 * The chip reset earlier notified the bootcode that
971 * a driver is present. We now need to start our pulse
972 * routine so that the bootcode is reminded that we're
977 /* Get the firmware running so IPMI still works */
980 bce_print_adapter_info(sc);
989 /****************************************************************************/
990 /* Device detach function. */
992 /* Stops the controller, resets the controller, and releases resources. */
995 /* 0 on success, positive value on failure. */
996 /****************************************************************************/
998 bce_detach(device_t dev)
1000 struct bce_softc *sc = device_get_softc(dev);
1002 if (device_is_attached(dev)) {
1003 struct ifnet *ifp = &sc->arpcom.ac_if;
1006 /* Stop and reset the controller. */
1007 lwkt_serialize_enter(ifp->if_serializer);
1008 callout_stop(&sc->bce_pulse_callout);
1010 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1011 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1013 msg = BCE_DRV_MSG_CODE_UNLOAD;
1015 bus_teardown_intr(dev, sc->bce_res_irq, sc->bce_intrhand);
1016 lwkt_serialize_exit(ifp->if_serializer);
1018 ether_ifdetach(ifp);
1021 /* If we have a child device on the MII bus remove it too. */
1023 device_delete_child(dev, sc->bce_miibus);
1024 bus_generic_detach(dev);
1026 if (sc->bce_res_irq != NULL) {
1027 bus_release_resource(dev, SYS_RES_IRQ,
1028 sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0,
1033 if (sc->bce_flags & BCE_USING_MSI_FLAG)
1034 pci_release_msi(dev);
1037 if (sc->bce_res_mem != NULL) {
1038 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1044 if (sc->bce_sysctl_tree != NULL)
1045 sysctl_ctx_free(&sc->bce_sysctl_ctx);
1051 /****************************************************************************/
1052 /* Device shutdown function. */
1054 /* Stops and resets the controller. */
1058 /****************************************************************************/
1060 bce_shutdown(device_t dev)
1062 struct bce_softc *sc = device_get_softc(dev);
1063 struct ifnet *ifp = &sc->arpcom.ac_if;
1066 lwkt_serialize_enter(ifp->if_serializer);
1068 if (sc->bce_flags & BCE_NO_WOL_FLAG)
1069 msg = BCE_DRV_MSG_CODE_UNLOAD_LNK_DN;
1071 msg = BCE_DRV_MSG_CODE_UNLOAD;
1073 lwkt_serialize_exit(ifp->if_serializer);
1077 /****************************************************************************/
1078 /* Indirect register read. */
1080 /* Reads NetXtreme II registers using an index/data register pair in PCI */
1081 /* configuration space. Using this mechanism avoids issues with posted */
1082 /* reads but is much slower than memory-mapped I/O. */
1085 /* The value of the register. */
1086 /****************************************************************************/
1088 bce_reg_rd_ind(struct bce_softc *sc, uint32_t offset)
1090 device_t dev = sc->bce_dev;
1092 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1096 val = pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1097 DBPRINT(sc, BCE_EXCESSIVE,
1098 "%s(); offset = 0x%08X, val = 0x%08X\n",
1099 __func__, offset, val);
1103 return pci_read_config(dev, BCE_PCICFG_REG_WINDOW, 4);
1108 /****************************************************************************/
1109 /* Indirect register write. */
1111 /* Writes NetXtreme II registers using an index/data register pair in PCI */
1112 /* configuration space. Using this mechanism avoids issues with posted */
1113 /* writes but is muchh slower than memory-mapped I/O. */
1117 /****************************************************************************/
1119 bce_reg_wr_ind(struct bce_softc *sc, uint32_t offset, uint32_t val)
1121 device_t dev = sc->bce_dev;
1123 DBPRINT(sc, BCE_EXCESSIVE, "%s(); offset = 0x%08X, val = 0x%08X\n",
1124 __func__, offset, val);
1126 pci_write_config(dev, BCE_PCICFG_REG_WINDOW_ADDRESS, offset, 4);
1127 pci_write_config(dev, BCE_PCICFG_REG_WINDOW, val, 4);
1131 /****************************************************************************/
1132 /* Shared memory write. */
1134 /* Writes NetXtreme II shared memory region. */
1138 /****************************************************************************/
1140 bce_shmem_wr(struct bce_softc *sc, uint32_t offset, uint32_t val)
1142 bce_reg_wr_ind(sc, sc->bce_shmem_base + offset, val);
1146 /****************************************************************************/
1147 /* Shared memory read. */
1149 /* Reads NetXtreme II shared memory region. */
1152 /* The 32 bit value read. */
1153 /****************************************************************************/
1155 bce_shmem_rd(struct bce_softc *sc, uint32_t offset)
1157 return bce_reg_rd_ind(sc, sc->bce_shmem_base + offset);
1161 /****************************************************************************/
1162 /* Context memory write. */
1164 /* The NetXtreme II controller uses context memory to track connection */
1165 /* information for L2 and higher network protocols. */
1169 /****************************************************************************/
1171 bce_ctx_wr(struct bce_softc *sc, uint32_t cid_addr, uint32_t ctx_offset,
1174 uint32_t idx, offset = ctx_offset + cid_addr;
1175 uint32_t val, retry_cnt = 5;
1177 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1178 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1179 REG_WR(sc, BCE_CTX_CTX_DATA, ctx_val);
1180 REG_WR(sc, BCE_CTX_CTX_CTRL, (offset | BCE_CTX_CTX_CTRL_WRITE_REQ));
1182 for (idx = 0; idx < retry_cnt; idx++) {
1183 val = REG_RD(sc, BCE_CTX_CTX_CTRL);
1184 if ((val & BCE_CTX_CTX_CTRL_WRITE_REQ) == 0)
1189 if (val & BCE_CTX_CTX_CTRL_WRITE_REQ) {
1190 device_printf(sc->bce_dev,
1191 "Unable to write CTX memory: "
1192 "cid_addr = 0x%08X, offset = 0x%08X!\n",
1193 cid_addr, ctx_offset);
1196 REG_WR(sc, BCE_CTX_DATA_ADR, offset);
1197 REG_WR(sc, BCE_CTX_DATA, ctx_val);
1202 /****************************************************************************/
1203 /* PHY register read. */
1205 /* Implements register reads on the MII bus. */
1208 /* The value of the register. */
1209 /****************************************************************************/
1211 bce_miibus_read_reg(device_t dev, int phy, int reg)
1213 struct bce_softc *sc = device_get_softc(dev);
1217 /* Make sure we are accessing the correct PHY address. */
1218 if (phy != sc->bce_phy_addr) {
1219 DBPRINT(sc, BCE_VERBOSE,
1220 "Invalid PHY address %d for PHY read!\n", phy);
1224 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1225 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1226 val &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1228 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1229 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1234 val = BCE_MIPHY(phy) | BCE_MIREG(reg) |
1235 BCE_EMAC_MDIO_COMM_COMMAND_READ | BCE_EMAC_MDIO_COMM_DISEXT |
1236 BCE_EMAC_MDIO_COMM_START_BUSY;
1237 REG_WR(sc, BCE_EMAC_MDIO_COMM, val);
1239 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1242 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1243 if (!(val & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1246 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1247 val &= BCE_EMAC_MDIO_COMM_DATA;
1252 if (val & BCE_EMAC_MDIO_COMM_START_BUSY) {
1253 if_printf(&sc->arpcom.ac_if,
1254 "Error: PHY read timeout! phy = %d, reg = 0x%04X\n",
1258 val = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1261 DBPRINT(sc, BCE_EXCESSIVE,
1262 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1263 __func__, phy, (uint16_t)reg & 0xffff, (uint16_t) val & 0xffff);
1265 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1266 val = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1267 val |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1269 REG_WR(sc, BCE_EMAC_MDIO_MODE, val);
1270 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1274 return (val & 0xffff);
1278 /****************************************************************************/
1279 /* PHY register write. */
1281 /* Implements register writes on the MII bus. */
1284 /* The value of the register. */
1285 /****************************************************************************/
1287 bce_miibus_write_reg(device_t dev, int phy, int reg, int val)
1289 struct bce_softc *sc = device_get_softc(dev);
1293 /* Make sure we are accessing the correct PHY address. */
1294 if (phy != sc->bce_phy_addr) {
1295 DBPRINT(sc, BCE_WARN,
1296 "Invalid PHY address %d for PHY write!\n", phy);
1300 DBPRINT(sc, BCE_EXCESSIVE,
1301 "%s(): phy = %d, reg = 0x%04X, val = 0x%04X\n",
1302 __func__, phy, (uint16_t)(reg & 0xffff),
1303 (uint16_t)(val & 0xffff));
1305 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1306 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1307 val1 &= ~BCE_EMAC_MDIO_MODE_AUTO_POLL;
1309 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1310 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1315 val1 = BCE_MIPHY(phy) | BCE_MIREG(reg) | val |
1316 BCE_EMAC_MDIO_COMM_COMMAND_WRITE |
1317 BCE_EMAC_MDIO_COMM_START_BUSY | BCE_EMAC_MDIO_COMM_DISEXT;
1318 REG_WR(sc, BCE_EMAC_MDIO_COMM, val1);
1320 for (i = 0; i < BCE_PHY_TIMEOUT; i++) {
1323 val1 = REG_RD(sc, BCE_EMAC_MDIO_COMM);
1324 if (!(val1 & BCE_EMAC_MDIO_COMM_START_BUSY)) {
1330 if (val1 & BCE_EMAC_MDIO_COMM_START_BUSY)
1331 if_printf(&sc->arpcom.ac_if, "PHY write timeout!\n");
1333 if (sc->bce_phy_flags & BCE_PHY_INT_MODE_AUTO_POLLING_FLAG) {
1334 val1 = REG_RD(sc, BCE_EMAC_MDIO_MODE);
1335 val1 |= BCE_EMAC_MDIO_MODE_AUTO_POLL;
1337 REG_WR(sc, BCE_EMAC_MDIO_MODE, val1);
1338 REG_RD(sc, BCE_EMAC_MDIO_MODE);
1346 /****************************************************************************/
1347 /* MII bus status change. */
1349 /* Called by the MII bus driver when the PHY establishes link to set the */
1350 /* MAC interface registers. */
1354 /****************************************************************************/
1356 bce_miibus_statchg(device_t dev)
1358 struct bce_softc *sc = device_get_softc(dev);
1359 struct mii_data *mii = device_get_softc(sc->bce_miibus);
1361 DBPRINT(sc, BCE_INFO, "mii_media_active = 0x%08X\n",
1362 mii->mii_media_active);
1365 /* Decode the interface media flags. */
1366 if_printf(&sc->arpcom.ac_if, "Media: ( ");
1367 switch(IFM_TYPE(mii->mii_media_active)) {
1369 kprintf("Ethernet )");
1372 kprintf("Unknown )");
1376 kprintf(" Media Options: ( ");
1377 switch(IFM_SUBTYPE(mii->mii_media_active)) {
1379 kprintf("Autoselect )");
1382 kprintf("Manual )");
1388 kprintf("10Base-T )");
1391 kprintf("100Base-TX )");
1394 kprintf("1000Base-SX )");
1397 kprintf("1000Base-T )");
1404 kprintf(" Global Options: (");
1405 if (mii->mii_media_active & IFM_FDX)
1406 kprintf(" FullDuplex");
1407 if (mii->mii_media_active & IFM_HDX)
1408 kprintf(" HalfDuplex");
1409 if (mii->mii_media_active & IFM_LOOP)
1410 kprintf(" Loopback");
1411 if (mii->mii_media_active & IFM_FLAG0)
1413 if (mii->mii_media_active & IFM_FLAG1)
1415 if (mii->mii_media_active & IFM_FLAG2)
1420 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT);
1423 * Set MII or GMII interface based on the speed negotiated
1426 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T ||
1427 IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) {
1428 DBPRINT(sc, BCE_INFO, "Setting GMII interface.\n");
1429 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_GMII);
1431 DBPRINT(sc, BCE_INFO, "Setting MII interface.\n");
1432 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_PORT_MII);
1436 * Set half or full duplex based on the duplicity negotiated
1439 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
1440 DBPRINT(sc, BCE_INFO, "Setting Full-Duplex interface.\n");
1441 BCE_CLRBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1443 DBPRINT(sc, BCE_INFO, "Setting Half-Duplex interface.\n");
1444 BCE_SETBIT(sc, BCE_EMAC_MODE, BCE_EMAC_MODE_HALF_DUPLEX);
1449 /****************************************************************************/
1450 /* Acquire NVRAM lock. */
1452 /* Before the NVRAM can be accessed the caller must acquire an NVRAM lock. */
1453 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1454 /* for use by the driver. */
1457 /* 0 on success, positive value on failure. */
1458 /****************************************************************************/
1460 bce_acquire_nvram_lock(struct bce_softc *sc)
1465 DBPRINT(sc, BCE_VERBOSE, "Acquiring NVRAM lock.\n");
1467 /* Request access to the flash interface. */
1468 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_SET2);
1469 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1470 val = REG_RD(sc, BCE_NVM_SW_ARB);
1471 if (val & BCE_NVM_SW_ARB_ARB_ARB2)
1477 if (j >= NVRAM_TIMEOUT_COUNT) {
1478 DBPRINT(sc, BCE_WARN, "Timeout acquiring NVRAM lock!\n");
1485 /****************************************************************************/
1486 /* Release NVRAM lock. */
1488 /* When the caller is finished accessing NVRAM the lock must be released. */
1489 /* Locks 0 and 2 are reserved, lock 1 is used by firmware and lock 2 is */
1490 /* for use by the driver. */
1493 /* 0 on success, positive value on failure. */
1494 /****************************************************************************/
1496 bce_release_nvram_lock(struct bce_softc *sc)
1501 DBPRINT(sc, BCE_VERBOSE, "Releasing NVRAM lock.\n");
1504 * Relinquish nvram interface.
1506 REG_WR(sc, BCE_NVM_SW_ARB, BCE_NVM_SW_ARB_ARB_REQ_CLR2);
1508 for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
1509 val = REG_RD(sc, BCE_NVM_SW_ARB);
1510 if (!(val & BCE_NVM_SW_ARB_ARB_ARB2))
1516 if (j >= NVRAM_TIMEOUT_COUNT) {
1517 DBPRINT(sc, BCE_WARN, "Timeout reeasing NVRAM lock!\n");
1524 /****************************************************************************/
1525 /* Enable NVRAM access. */
1527 /* Before accessing NVRAM for read or write operations the caller must */
1528 /* enabled NVRAM access. */
1532 /****************************************************************************/
1534 bce_enable_nvram_access(struct bce_softc *sc)
1538 DBPRINT(sc, BCE_VERBOSE, "Enabling NVRAM access.\n");
1540 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1541 /* Enable both bits, even on read. */
1542 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1543 val | BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN);
1547 /****************************************************************************/
1548 /* Disable NVRAM access. */
1550 /* When the caller is finished accessing NVRAM access must be disabled. */
1554 /****************************************************************************/
1556 bce_disable_nvram_access(struct bce_softc *sc)
1560 DBPRINT(sc, BCE_VERBOSE, "Disabling NVRAM access.\n");
1562 val = REG_RD(sc, BCE_NVM_ACCESS_ENABLE);
1564 /* Disable both bits, even after read. */
1565 REG_WR(sc, BCE_NVM_ACCESS_ENABLE,
1566 val & ~(BCE_NVM_ACCESS_ENABLE_EN | BCE_NVM_ACCESS_ENABLE_WR_EN));
1570 /****************************************************************************/
1571 /* Read a dword (32 bits) from NVRAM. */
1573 /* Read a 32 bit word from NVRAM. The caller is assumed to have already */
1574 /* obtained the NVRAM lock and enabled the controller for NVRAM access. */
1577 /* 0 on success and the 32 bit value read, positive value on failure. */
1578 /****************************************************************************/
1580 bce_nvram_read_dword(struct bce_softc *sc, uint32_t offset, uint8_t *ret_val,
1586 /* Build the command word. */
1587 cmd = BCE_NVM_COMMAND_DOIT | cmd_flags;
1589 /* Calculate the offset for buffered flash. */
1590 if (sc->bce_flash_info->flags & BCE_NV_TRANSLATE) {
1591 offset = ((offset / sc->bce_flash_info->page_size) <<
1592 sc->bce_flash_info->page_bits) +
1593 (offset % sc->bce_flash_info->page_size);
1597 * Clear the DONE bit separately, set the address to read,
1598 * and issue the read.
1600 REG_WR(sc, BCE_NVM_COMMAND, BCE_NVM_COMMAND_DONE);
1601 REG_WR(sc, BCE_NVM_ADDR, offset & BCE_NVM_ADDR_NVM_ADDR_VALUE);
1602 REG_WR(sc, BCE_NVM_COMMAND, cmd);
1604 /* Wait for completion. */
1605 for (i = 0; i < NVRAM_TIMEOUT_COUNT; i++) {
1610 val = REG_RD(sc, BCE_NVM_COMMAND);
1611 if (val & BCE_NVM_COMMAND_DONE) {
1612 val = REG_RD(sc, BCE_NVM_READ);
1615 memcpy(ret_val, &val, 4);
1620 /* Check for errors. */
1621 if (i >= NVRAM_TIMEOUT_COUNT) {
1622 if_printf(&sc->arpcom.ac_if,
1623 "Timeout error reading NVRAM at offset 0x%08X!\n",
1631 /****************************************************************************/
1632 /* Initialize NVRAM access. */
1634 /* Identify the NVRAM device in use and prepare the NVRAM interface to */
1635 /* access that device. */
1638 /* 0 on success, positive value on failure. */
1639 /****************************************************************************/
1641 bce_init_nvram(struct bce_softc *sc)
1644 int j, entry_count, rc = 0;
1645 const struct flash_spec *flash;
1647 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
1649 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1650 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1651 sc->bce_flash_info = &flash_5709;
1652 goto bce_init_nvram_get_flash_size;
1655 /* Determine the selected interface. */
1656 val = REG_RD(sc, BCE_NVM_CFG1);
1658 entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
1661 * Flash reconfiguration is required to support additional
1662 * NVRAM devices not directly supported in hardware.
1663 * Check if the flash interface was reconfigured
1667 if (val & 0x40000000) {
1668 /* Flash interface reconfigured by bootcode. */
1670 DBPRINT(sc, BCE_INFO_LOAD,
1671 "%s(): Flash WAS reconfigured.\n", __func__);
1673 for (j = 0, flash = flash_table; j < entry_count;
1675 if ((val & FLASH_BACKUP_STRAP_MASK) ==
1676 (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
1677 sc->bce_flash_info = flash;
1682 /* Flash interface not yet reconfigured. */
1685 DBPRINT(sc, BCE_INFO_LOAD,
1686 "%s(): Flash was NOT reconfigured.\n", __func__);
1688 if (val & (1 << 23))
1689 mask = FLASH_BACKUP_STRAP_MASK;
1691 mask = FLASH_STRAP_MASK;
1693 /* Look for the matching NVRAM device configuration data. */
1694 for (j = 0, flash = flash_table; j < entry_count;
1696 /* Check if the device matches any of the known devices. */
1697 if ((val & mask) == (flash->strapping & mask)) {
1698 /* Found a device match. */
1699 sc->bce_flash_info = flash;
1701 /* Request access to the flash interface. */
1702 rc = bce_acquire_nvram_lock(sc);
1706 /* Reconfigure the flash interface. */
1707 bce_enable_nvram_access(sc);
1708 REG_WR(sc, BCE_NVM_CFG1, flash->config1);
1709 REG_WR(sc, BCE_NVM_CFG2, flash->config2);
1710 REG_WR(sc, BCE_NVM_CFG3, flash->config3);
1711 REG_WR(sc, BCE_NVM_WRITE1, flash->write1);
1712 bce_disable_nvram_access(sc);
1713 bce_release_nvram_lock(sc);
1719 /* Check if a matching device was found. */
1720 if (j == entry_count) {
1721 sc->bce_flash_info = NULL;
1722 if_printf(&sc->arpcom.ac_if, "Unknown Flash NVRAM found!\n");
1726 bce_init_nvram_get_flash_size:
1727 /* Write the flash config data to the shared memory interface. */
1728 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG2) &
1729 BCE_SHARED_HW_CFG2_NVM_SIZE_MASK;
1731 sc->bce_flash_size = val;
1733 sc->bce_flash_size = sc->bce_flash_info->total_size;
1735 DBPRINT(sc, BCE_INFO_LOAD, "%s() flash->total_size = 0x%08X\n",
1736 __func__, sc->bce_flash_info->total_size);
1738 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
1744 /****************************************************************************/
1745 /* Read an arbitrary range of data from NVRAM. */
1747 /* Prepares the NVRAM interface for access and reads the requested data */
1748 /* into the supplied buffer. */
1751 /* 0 on success and the data read, positive value on failure. */
1752 /****************************************************************************/
1754 bce_nvram_read(struct bce_softc *sc, uint32_t offset, uint8_t *ret_buf,
1757 uint32_t cmd_flags, offset32, len32, extra;
1763 /* Request access to the flash interface. */
1764 rc = bce_acquire_nvram_lock(sc);
1768 /* Enable access to flash interface */
1769 bce_enable_nvram_access(sc);
1777 /* XXX should we release nvram lock if read_dword() fails? */
1783 pre_len = 4 - (offset & 3);
1785 if (pre_len >= len32) {
1787 cmd_flags = BCE_NVM_COMMAND_FIRST | BCE_NVM_COMMAND_LAST;
1789 cmd_flags = BCE_NVM_COMMAND_FIRST;
1792 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1796 memcpy(ret_buf, buf + (offset & 3), pre_len);
1804 extra = 4 - (len32 & 3);
1805 len32 = (len32 + 4) & ~3;
1812 cmd_flags = BCE_NVM_COMMAND_LAST;
1814 cmd_flags = BCE_NVM_COMMAND_FIRST |
1815 BCE_NVM_COMMAND_LAST;
1817 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1819 memcpy(ret_buf, buf, 4 - extra);
1820 } else if (len32 > 0) {
1823 /* Read the first word. */
1827 cmd_flags = BCE_NVM_COMMAND_FIRST;
1829 rc = bce_nvram_read_dword(sc, offset32, ret_buf, cmd_flags);
1831 /* Advance to the next dword. */
1836 while (len32 > 4 && rc == 0) {
1837 rc = bce_nvram_read_dword(sc, offset32, ret_buf, 0);
1839 /* Advance to the next dword. */
1846 goto bce_nvram_read_locked_exit;
1848 cmd_flags = BCE_NVM_COMMAND_LAST;
1849 rc = bce_nvram_read_dword(sc, offset32, buf, cmd_flags);
1851 memcpy(ret_buf, buf, 4 - extra);
1854 bce_nvram_read_locked_exit:
1855 /* Disable access to flash interface and release the lock. */
1856 bce_disable_nvram_access(sc);
1857 bce_release_nvram_lock(sc);
1863 /****************************************************************************/
1864 /* Verifies that NVRAM is accessible and contains valid data. */
1866 /* Reads the configuration data from NVRAM and verifies that the CRC is */
1870 /* 0 on success, positive value on failure. */
1871 /****************************************************************************/
1873 bce_nvram_test(struct bce_softc *sc)
1875 uint32_t buf[BCE_NVRAM_SIZE / 4];
1876 uint32_t magic, csum;
1877 uint8_t *data = (uint8_t *)buf;
1881 * Check that the device NVRAM is valid by reading
1882 * the magic value at offset 0.
1884 rc = bce_nvram_read(sc, 0, data, 4);
1888 magic = be32toh(buf[0]);
1889 if (magic != BCE_NVRAM_MAGIC) {
1890 if_printf(&sc->arpcom.ac_if,
1891 "Invalid NVRAM magic value! Expected: 0x%08X, "
1892 "Found: 0x%08X\n", BCE_NVRAM_MAGIC, magic);
1897 * Verify that the device NVRAM includes valid
1898 * configuration data.
1900 rc = bce_nvram_read(sc, 0x100, data, BCE_NVRAM_SIZE);
1904 csum = ether_crc32_le(data, 0x100);
1905 if (csum != BCE_CRC32_RESIDUAL) {
1906 if_printf(&sc->arpcom.ac_if,
1907 "Invalid Manufacturing Information NVRAM CRC! "
1908 "Expected: 0x%08X, Found: 0x%08X\n",
1909 BCE_CRC32_RESIDUAL, csum);
1913 csum = ether_crc32_le(data + 0x100, 0x100);
1914 if (csum != BCE_CRC32_RESIDUAL) {
1915 if_printf(&sc->arpcom.ac_if,
1916 "Invalid Feature Configuration Information "
1917 "NVRAM CRC! Expected: 0x%08X, Found: 08%08X\n",
1918 BCE_CRC32_RESIDUAL, csum);
1925 /****************************************************************************/
1926 /* Identifies the current media type of the controller and sets the PHY */
1931 /****************************************************************************/
1933 bce_get_media(struct bce_softc *sc)
1937 sc->bce_phy_addr = 1;
1939 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
1940 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
1941 uint32_t val = REG_RD(sc, BCE_MISC_DUAL_MEDIA_CTRL);
1942 uint32_t bond_id = val & BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID;
1946 * The BCM5709S is software configurable
1947 * for Copper or SerDes operation.
1949 if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_C) {
1951 } else if (bond_id == BCE_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
1952 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1956 if (val & BCE_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE) {
1957 strap = (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
1960 (val & BCE_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
1963 if (pci_get_function(sc->bce_dev) == 0) {
1968 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1976 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1980 } else if (BCE_CHIP_BOND_ID(sc) & BCE_CHIP_BOND_ID_SERDES_BIT) {
1981 sc->bce_phy_flags |= BCE_PHY_SERDES_FLAG;
1984 if (sc->bce_phy_flags & BCE_PHY_SERDES_FLAG) {
1985 sc->bce_flags |= BCE_NO_WOL_FLAG;
1986 if (BCE_CHIP_NUM(sc) != BCE_CHIP_NUM_5706) {
1987 sc->bce_phy_addr = 2;
1988 val = bce_shmem_rd(sc, BCE_SHARED_HW_CFG_CONFIG);
1989 if (val & BCE_SHARED_HW_CFG_PHY_2_5G)
1990 sc->bce_phy_flags |= BCE_PHY_2_5G_CAPABLE_FLAG;
1992 } else if ((BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706) ||
1993 (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)) {
1994 sc->bce_phy_flags |= BCE_PHY_CRC_FIX_FLAG;
1999 /****************************************************************************/
2000 /* Free any DMA memory owned by the driver. */
2002 /* Scans through each data structre that requires DMA memory and frees */
2003 /* the memory if allocated. */
2007 /****************************************************************************/
2009 bce_dma_free(struct bce_softc *sc)
2013 /* Destroy the status block. */
2014 if (sc->status_tag != NULL) {
2015 if (sc->status_block != NULL) {
2016 bus_dmamap_unload(sc->status_tag, sc->status_map);
2017 bus_dmamem_free(sc->status_tag, sc->status_block,
2020 bus_dma_tag_destroy(sc->status_tag);
2024 /* Destroy the statistics block. */
2025 if (sc->stats_tag != NULL) {
2026 if (sc->stats_block != NULL) {
2027 bus_dmamap_unload(sc->stats_tag, sc->stats_map);
2028 bus_dmamem_free(sc->stats_tag, sc->stats_block,
2031 bus_dma_tag_destroy(sc->stats_tag);
2034 /* Destroy the CTX DMA stuffs. */
2035 if (sc->ctx_tag != NULL) {
2036 for (i = 0; i < sc->ctx_pages; i++) {
2037 if (sc->ctx_block[i] != NULL) {
2038 bus_dmamap_unload(sc->ctx_tag, sc->ctx_map[i]);
2039 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2043 bus_dma_tag_destroy(sc->ctx_tag);
2046 /* Destroy the TX buffer descriptor DMA stuffs. */
2047 if (sc->tx_bd_chain_tag != NULL) {
2048 for (i = 0; i < TX_PAGES; i++) {
2049 if (sc->tx_bd_chain[i] != NULL) {
2050 bus_dmamap_unload(sc->tx_bd_chain_tag,
2051 sc->tx_bd_chain_map[i]);
2052 bus_dmamem_free(sc->tx_bd_chain_tag,
2054 sc->tx_bd_chain_map[i]);
2057 bus_dma_tag_destroy(sc->tx_bd_chain_tag);
2060 /* Destroy the RX buffer descriptor DMA stuffs. */
2061 if (sc->rx_bd_chain_tag != NULL) {
2062 for (i = 0; i < RX_PAGES; i++) {
2063 if (sc->rx_bd_chain[i] != NULL) {
2064 bus_dmamap_unload(sc->rx_bd_chain_tag,
2065 sc->rx_bd_chain_map[i]);
2066 bus_dmamem_free(sc->rx_bd_chain_tag,
2068 sc->rx_bd_chain_map[i]);
2071 bus_dma_tag_destroy(sc->rx_bd_chain_tag);
2074 /* Destroy the TX mbuf DMA stuffs. */
2075 if (sc->tx_mbuf_tag != NULL) {
2076 for (i = 0; i < TOTAL_TX_BD; i++) {
2077 /* Must have been unloaded in bce_stop() */
2078 KKASSERT(sc->tx_mbuf_ptr[i] == NULL);
2079 bus_dmamap_destroy(sc->tx_mbuf_tag,
2080 sc->tx_mbuf_map[i]);
2082 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2085 /* Destroy the RX mbuf DMA stuffs. */
2086 if (sc->rx_mbuf_tag != NULL) {
2087 for (i = 0; i < TOTAL_RX_BD; i++) {
2088 /* Must have been unloaded in bce_stop() */
2089 KKASSERT(sc->rx_mbuf_ptr[i] == NULL);
2090 bus_dmamap_destroy(sc->rx_mbuf_tag,
2091 sc->rx_mbuf_map[i]);
2093 bus_dmamap_destroy(sc->rx_mbuf_tag, sc->rx_mbuf_tmpmap);
2094 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2097 /* Destroy the parent tag */
2098 if (sc->parent_tag != NULL)
2099 bus_dma_tag_destroy(sc->parent_tag);
2103 /****************************************************************************/
2104 /* Get DMA memory from the OS. */
2106 /* Validates that the OS has provided DMA buffers in response to a */
2107 /* bus_dmamap_load() call and saves the physical address of those buffers. */
2108 /* When the callback is used the OS will return 0 for the mapping function */
2109 /* (bus_dmamap_load()) so we use the value of map_arg->maxsegs to pass any */
2110 /* failures back to the caller. */
2114 /****************************************************************************/
2116 bce_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2118 bus_addr_t *busaddr = arg;
2121 * Simulate a mapping failure.
2124 DBRUNIF(DB_RANDOMTRUE(bce_debug_dma_map_addr_failure),
2125 kprintf("bce: %s(%d): Simulating DMA mapping error.\n",
2126 __FILE__, __LINE__);
2129 /* Check for an error and signal the caller that an error occurred. */
2133 KASSERT(nseg == 1, ("only one segment is allowed\n"));
2134 *busaddr = segs->ds_addr;
2138 /****************************************************************************/
2139 /* Allocate any DMA memory needed by the driver. */
2141 /* Allocates DMA memory needed for the various global structures needed by */
2144 /* Memory alignment requirements: */
2145 /* -----------------+----------+----------+----------+----------+ */
2146 /* Data Structure | 5706 | 5708 | 5709 | 5716 | */
2147 /* -----------------+----------+----------+----------+----------+ */
2148 /* Status Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2149 /* Statistics Block | 8 bytes | 8 bytes | 16 bytes | 16 bytes | */
2150 /* RX Buffers | 16 bytes | 16 bytes | 16 bytes | 16 bytes | */
2151 /* PG Buffers | none | none | none | none | */
2152 /* TX Buffers | none | none | none | none | */
2153 /* Chain Pages(1) | 4KiB | 4KiB | 4KiB | 4KiB | */
2154 /* Context Pages(1) | N/A | N/A | 4KiB | 4KiB | */
2155 /* -----------------+----------+----------+----------+----------+ */
2157 /* (1) Must align with CPU page size (BCM_PAGE_SZIE). */
2160 /* 0 for success, positive value for failure. */
2161 /****************************************************************************/
2163 bce_dma_alloc(struct bce_softc *sc)
2165 struct ifnet *ifp = &sc->arpcom.ac_if;
2167 bus_addr_t busaddr, max_busaddr;
2168 bus_size_t status_align, stats_align;
2171 * The embedded PCIe to PCI-X bridge (EPB)
2172 * in the 5708 cannot address memory above
2173 * 40 bits (E7_5708CB1_23043 & E6_5708SB1_23043).
2175 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5708)
2176 max_busaddr = BCE_BUS_SPACE_MAXADDR;
2178 max_busaddr = BUS_SPACE_MAXADDR;
2181 * BCM5709 and BCM5716 uses host memory as cache for context memory.
2183 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2184 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2185 sc->ctx_pages = BCE_CTX_BLK_SZ / BCM_PAGE_SIZE;
2186 if (sc->ctx_pages == 0)
2188 if (sc->ctx_pages > BCE_CTX_PAGES) {
2189 device_printf(sc->bce_dev, "excessive ctx pages %d\n",
2201 * Allocate the parent bus DMA tag appropriate for PCI.
2203 rc = bus_dma_tag_create(NULL, 1, BCE_DMA_BOUNDARY,
2204 max_busaddr, BUS_SPACE_MAXADDR,
2206 BUS_SPACE_MAXSIZE_32BIT, 0,
2207 BUS_SPACE_MAXSIZE_32BIT,
2208 0, &sc->parent_tag);
2210 if_printf(ifp, "Could not allocate parent DMA tag!\n");
2215 * Allocate status block.
2217 sc->status_block = bus_dmamem_coherent_any(sc->parent_tag,
2218 status_align, BCE_STATUS_BLK_SZ,
2219 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2220 &sc->status_tag, &sc->status_map,
2221 &sc->status_block_paddr);
2222 if (sc->status_block == NULL) {
2223 if_printf(ifp, "Could not allocate status block!\n");
2228 * Allocate statistics block.
2230 sc->stats_block = bus_dmamem_coherent_any(sc->parent_tag,
2231 stats_align, BCE_STATS_BLK_SZ,
2232 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2233 &sc->stats_tag, &sc->stats_map,
2234 &sc->stats_block_paddr);
2235 if (sc->stats_block == NULL) {
2236 if_printf(ifp, "Could not allocate statistics block!\n");
2241 * Allocate context block, if needed
2243 if (sc->ctx_pages != 0) {
2244 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2245 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2247 BCM_PAGE_SIZE, 1, BCM_PAGE_SIZE,
2250 if_printf(ifp, "Could not allocate "
2251 "context block DMA tag!\n");
2255 for (i = 0; i < sc->ctx_pages; i++) {
2256 rc = bus_dmamem_alloc(sc->ctx_tag,
2257 (void **)&sc->ctx_block[i],
2258 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2262 if_printf(ifp, "Could not allocate %dth context "
2263 "DMA memory!\n", i);
2267 rc = bus_dmamap_load(sc->ctx_tag, sc->ctx_map[i],
2268 sc->ctx_block[i], BCM_PAGE_SIZE,
2269 bce_dma_map_addr, &busaddr,
2272 if (rc == EINPROGRESS) {
2273 panic("%s coherent memory loading "
2274 "is still in progress!", ifp->if_xname);
2276 if_printf(ifp, "Could not map %dth context "
2277 "DMA memory!\n", i);
2278 bus_dmamem_free(sc->ctx_tag, sc->ctx_block[i],
2280 sc->ctx_block[i] = NULL;
2283 sc->ctx_paddr[i] = busaddr;
2288 * Create a DMA tag for the TX buffer descriptor chain,
2289 * allocate and clear the memory, and fetch the
2290 * physical address of the block.
2292 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2293 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2295 BCE_TX_CHAIN_PAGE_SZ, 1, BCE_TX_CHAIN_PAGE_SZ,
2296 0, &sc->tx_bd_chain_tag);
2298 if_printf(ifp, "Could not allocate "
2299 "TX descriptor chain DMA tag!\n");
2303 for (i = 0; i < TX_PAGES; i++) {
2304 rc = bus_dmamem_alloc(sc->tx_bd_chain_tag,
2305 (void **)&sc->tx_bd_chain[i],
2306 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2308 &sc->tx_bd_chain_map[i]);
2310 if_printf(ifp, "Could not allocate %dth TX descriptor "
2311 "chain DMA memory!\n", i);
2315 rc = bus_dmamap_load(sc->tx_bd_chain_tag,
2316 sc->tx_bd_chain_map[i],
2317 sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ,
2318 bce_dma_map_addr, &busaddr,
2321 if (rc == EINPROGRESS) {
2322 panic("%s coherent memory loading "
2323 "is still in progress!", ifp->if_xname);
2325 if_printf(ifp, "Could not map %dth TX descriptor "
2326 "chain DMA memory!\n", i);
2327 bus_dmamem_free(sc->tx_bd_chain_tag,
2329 sc->tx_bd_chain_map[i]);
2330 sc->tx_bd_chain[i] = NULL;
2334 sc->tx_bd_chain_paddr[i] = busaddr;
2335 /* DRC - Fix for 64 bit systems. */
2336 DBPRINT(sc, BCE_INFO, "tx_bd_chain_paddr[%d] = 0x%08X\n",
2337 i, (uint32_t)sc->tx_bd_chain_paddr[i]);
2340 /* Create a DMA tag for TX mbufs. */
2341 rc = bus_dma_tag_create(sc->parent_tag, 1, 0,
2342 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2344 /* BCE_MAX_JUMBO_ETHER_MTU_VLAN */MCLBYTES,
2345 BCE_MAX_SEGMENTS, MCLBYTES,
2346 BUS_DMA_ALLOCNOW | BUS_DMA_WAITOK |
2350 if_printf(ifp, "Could not allocate TX mbuf DMA tag!\n");
2354 /* Create DMA maps for the TX mbufs clusters. */
2355 for (i = 0; i < TOTAL_TX_BD; i++) {
2356 rc = bus_dmamap_create(sc->tx_mbuf_tag,
2357 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE,
2358 &sc->tx_mbuf_map[i]);
2360 for (j = 0; j < i; ++j) {
2361 bus_dmamap_destroy(sc->tx_mbuf_tag,
2362 sc->tx_mbuf_map[i]);
2364 bus_dma_tag_destroy(sc->tx_mbuf_tag);
2365 sc->tx_mbuf_tag = NULL;
2367 if_printf(ifp, "Unable to create "
2368 "%dth TX mbuf DMA map!\n", i);
2374 * Create a DMA tag for the RX buffer descriptor chain,
2375 * allocate and clear the memory, and fetch the physical
2376 * address of the blocks.
2378 rc = bus_dma_tag_create(sc->parent_tag, BCM_PAGE_SIZE, 0,
2379 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2381 BCE_RX_CHAIN_PAGE_SZ, 1, BCE_RX_CHAIN_PAGE_SZ,
2382 0, &sc->rx_bd_chain_tag);
2384 if_printf(ifp, "Could not allocate "
2385 "RX descriptor chain DMA tag!\n");
2389 for (i = 0; i < RX_PAGES; i++) {
2390 rc = bus_dmamem_alloc(sc->rx_bd_chain_tag,
2391 (void **)&sc->rx_bd_chain[i],
2392 BUS_DMA_WAITOK | BUS_DMA_ZERO |
2394 &sc->rx_bd_chain_map[i]);
2396 if_printf(ifp, "Could not allocate %dth RX descriptor "
2397 "chain DMA memory!\n", i);
2401 rc = bus_dmamap_load(sc->rx_bd_chain_tag,
2402 sc->rx_bd_chain_map[i],
2403 sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ,
2404 bce_dma_map_addr, &busaddr,
2407 if (rc == EINPROGRESS) {
2408 panic("%s coherent memory loading "
2409 "is still in progress!", ifp->if_xname);
2411 if_printf(ifp, "Could not map %dth RX descriptor "
2412 "chain DMA memory!\n", i);
2413 bus_dmamem_free(sc->rx_bd_chain_tag,
2415 sc->rx_bd_chain_map[i]);
2416 sc->rx_bd_chain[i] = NULL;
2420 sc->rx_bd_chain_paddr[i] = busaddr;
2421 /* DRC - Fix for 64 bit systems. */
2422 DBPRINT(sc, BCE_INFO, "rx_bd_chain_paddr[%d] = 0x%08X\n",
2423 i, (uint32_t)sc->rx_bd_chain_paddr[i]);
2426 /* Create a DMA tag for RX mbufs. */
2427 rc = bus_dma_tag_create(sc->parent_tag, BCE_DMA_RX_ALIGN, 0,
2428 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
2430 MCLBYTES, 1, MCLBYTES,
2431 BUS_DMA_ALLOCNOW | BUS_DMA_ALIGNED |
2435 if_printf(ifp, "Could not allocate RX mbuf DMA tag!\n");
2439 /* Create tmp DMA map for RX mbuf clusters. */
2440 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2441 &sc->rx_mbuf_tmpmap);
2443 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2444 sc->rx_mbuf_tag = NULL;
2446 if_printf(ifp, "Could not create RX mbuf tmp DMA map!\n");
2450 /* Create DMA maps for the RX mbuf clusters. */
2451 for (i = 0; i < TOTAL_RX_BD; i++) {
2452 rc = bus_dmamap_create(sc->rx_mbuf_tag, BUS_DMA_WAITOK,
2453 &sc->rx_mbuf_map[i]);
2455 for (j = 0; j < i; ++j) {
2456 bus_dmamap_destroy(sc->rx_mbuf_tag,
2457 sc->rx_mbuf_map[j]);
2459 bus_dma_tag_destroy(sc->rx_mbuf_tag);
2460 sc->rx_mbuf_tag = NULL;
2462 if_printf(ifp, "Unable to create "
2463 "%dth RX mbuf DMA map!\n", i);
2471 /****************************************************************************/
2472 /* Firmware synchronization. */
2474 /* Before performing certain events such as a chip reset, synchronize with */
2475 /* the firmware first. */
2478 /* 0 for success, positive value for failure. */
2479 /****************************************************************************/
2481 bce_fw_sync(struct bce_softc *sc, uint32_t msg_data)
2486 /* Don't waste any time if we've timed out before. */
2487 if (sc->bce_fw_timed_out)
2490 /* Increment the message sequence number. */
2491 sc->bce_fw_wr_seq++;
2492 msg_data |= sc->bce_fw_wr_seq;
2494 DBPRINT(sc, BCE_VERBOSE, "bce_fw_sync(): msg_data = 0x%08X\n", msg_data);
2496 /* Send the message to the bootcode driver mailbox. */
2497 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2499 /* Wait for the bootcode to acknowledge the message. */
2500 for (i = 0; i < FW_ACK_TIME_OUT_MS; i++) {
2501 /* Check for a response in the bootcode firmware mailbox. */
2502 val = bce_shmem_rd(sc, BCE_FW_MB);
2503 if ((val & BCE_FW_MSG_ACK) == (msg_data & BCE_DRV_MSG_SEQ))
2508 /* If we've timed out, tell the bootcode that we've stopped waiting. */
2509 if ((val & BCE_FW_MSG_ACK) != (msg_data & BCE_DRV_MSG_SEQ) &&
2510 (msg_data & BCE_DRV_MSG_DATA) != BCE_DRV_MSG_DATA_WAIT0) {
2511 if_printf(&sc->arpcom.ac_if,
2512 "Firmware synchronization timeout! "
2513 "msg_data = 0x%08X\n", msg_data);
2515 msg_data &= ~BCE_DRV_MSG_CODE;
2516 msg_data |= BCE_DRV_MSG_CODE_FW_TIMEOUT;
2518 bce_shmem_wr(sc, BCE_DRV_MB, msg_data);
2520 sc->bce_fw_timed_out = 1;
2527 /****************************************************************************/
2528 /* Load Receive Virtual 2 Physical (RV2P) processor firmware. */
2532 /****************************************************************************/
2534 bce_load_rv2p_fw(struct bce_softc *sc, uint32_t *rv2p_code,
2535 uint32_t rv2p_code_len, uint32_t rv2p_proc)
2540 for (i = 0; i < rv2p_code_len; i += 8) {
2541 REG_WR(sc, BCE_RV2P_INSTR_HIGH, *rv2p_code);
2543 REG_WR(sc, BCE_RV2P_INSTR_LOW, *rv2p_code);
2546 if (rv2p_proc == RV2P_PROC1) {
2547 val = (i / 8) | BCE_RV2P_PROC1_ADDR_CMD_RDWR;
2548 REG_WR(sc, BCE_RV2P_PROC1_ADDR_CMD, val);
2550 val = (i / 8) | BCE_RV2P_PROC2_ADDR_CMD_RDWR;
2551 REG_WR(sc, BCE_RV2P_PROC2_ADDR_CMD, val);
2555 /* Reset the processor, un-stall is done later. */
2556 if (rv2p_proc == RV2P_PROC1)
2557 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC1_RESET);
2559 REG_WR(sc, BCE_RV2P_COMMAND, BCE_RV2P_COMMAND_PROC2_RESET);
2563 /****************************************************************************/
2564 /* Load RISC processor firmware. */
2566 /* Loads firmware from the file if_bcefw.h into the scratchpad memory */
2567 /* associated with a particular processor. */
2571 /****************************************************************************/
2573 bce_load_cpu_fw(struct bce_softc *sc, struct cpu_reg *cpu_reg,
2579 bce_halt_cpu(sc, cpu_reg);
2581 /* Load the Text area. */
2582 offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
2584 for (j = 0; j < (fw->text_len / 4); j++, offset += 4)
2585 REG_WR_IND(sc, offset, fw->text[j]);
2588 /* Load the Data area. */
2589 offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
2591 for (j = 0; j < (fw->data_len / 4); j++, offset += 4)
2592 REG_WR_IND(sc, offset, fw->data[j]);
2595 /* Load the SBSS area. */
2596 offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
2598 for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4)
2599 REG_WR_IND(sc, offset, fw->sbss[j]);
2602 /* Load the BSS area. */
2603 offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
2605 for (j = 0; j < (fw->bss_len/4); j++, offset += 4)
2606 REG_WR_IND(sc, offset, fw->bss[j]);
2609 /* Load the Read-Only area. */
2610 offset = cpu_reg->spad_base +
2611 (fw->rodata_addr - cpu_reg->mips_view_base);
2613 for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4)
2614 REG_WR_IND(sc, offset, fw->rodata[j]);
2617 /* Clear the pre-fetch instruction and set the FW start address. */
2618 REG_WR_IND(sc, cpu_reg->inst, 0);
2619 REG_WR_IND(sc, cpu_reg->pc, fw->start_addr);
2623 /****************************************************************************/
2624 /* Starts the RISC processor. */
2626 /* Assumes the CPU starting address has already been set. */
2630 /****************************************************************************/
2632 bce_start_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2636 /* Start the CPU. */
2637 val = REG_RD_IND(sc, cpu_reg->mode);
2638 val &= ~cpu_reg->mode_value_halt;
2639 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2640 REG_WR_IND(sc, cpu_reg->mode, val);
2644 /****************************************************************************/
2645 /* Halts the RISC processor. */
2649 /****************************************************************************/
2651 bce_halt_cpu(struct bce_softc *sc, struct cpu_reg *cpu_reg)
2656 val = REG_RD_IND(sc, cpu_reg->mode);
2657 val |= cpu_reg->mode_value_halt;
2658 REG_WR_IND(sc, cpu_reg->mode, val);
2659 REG_WR_IND(sc, cpu_reg->state, cpu_reg->state_value_clear);
2663 /****************************************************************************/
2664 /* Start the RX CPU. */
2668 /****************************************************************************/
2670 bce_start_rxp_cpu(struct bce_softc *sc)
2672 struct cpu_reg cpu_reg;
2674 cpu_reg.mode = BCE_RXP_CPU_MODE;
2675 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2676 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2677 cpu_reg.state = BCE_RXP_CPU_STATE;
2678 cpu_reg.state_value_clear = 0xffffff;
2679 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2680 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2681 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2682 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2683 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2684 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2685 cpu_reg.mips_view_base = 0x8000000;
2687 bce_start_cpu(sc, &cpu_reg);
2691 /****************************************************************************/
2692 /* Initialize the RX CPU. */
2696 /****************************************************************************/
2698 bce_init_rxp_cpu(struct bce_softc *sc)
2700 struct cpu_reg cpu_reg;
2703 cpu_reg.mode = BCE_RXP_CPU_MODE;
2704 cpu_reg.mode_value_halt = BCE_RXP_CPU_MODE_SOFT_HALT;
2705 cpu_reg.mode_value_sstep = BCE_RXP_CPU_MODE_STEP_ENA;
2706 cpu_reg.state = BCE_RXP_CPU_STATE;
2707 cpu_reg.state_value_clear = 0xffffff;
2708 cpu_reg.gpr0 = BCE_RXP_CPU_REG_FILE;
2709 cpu_reg.evmask = BCE_RXP_CPU_EVENT_MASK;
2710 cpu_reg.pc = BCE_RXP_CPU_PROGRAM_COUNTER;
2711 cpu_reg.inst = BCE_RXP_CPU_INSTRUCTION;
2712 cpu_reg.bp = BCE_RXP_CPU_HW_BREAKPOINT;
2713 cpu_reg.spad_base = BCE_RXP_SCRATCH;
2714 cpu_reg.mips_view_base = 0x8000000;
2716 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2717 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2718 fw.ver_major = bce_RXP_b09FwReleaseMajor;
2719 fw.ver_minor = bce_RXP_b09FwReleaseMinor;
2720 fw.ver_fix = bce_RXP_b09FwReleaseFix;
2721 fw.start_addr = bce_RXP_b09FwStartAddr;
2723 fw.text_addr = bce_RXP_b09FwTextAddr;
2724 fw.text_len = bce_RXP_b09FwTextLen;
2726 fw.text = bce_RXP_b09FwText;
2728 fw.data_addr = bce_RXP_b09FwDataAddr;
2729 fw.data_len = bce_RXP_b09FwDataLen;
2731 fw.data = bce_RXP_b09FwData;
2733 fw.sbss_addr = bce_RXP_b09FwSbssAddr;
2734 fw.sbss_len = bce_RXP_b09FwSbssLen;
2736 fw.sbss = bce_RXP_b09FwSbss;
2738 fw.bss_addr = bce_RXP_b09FwBssAddr;
2739 fw.bss_len = bce_RXP_b09FwBssLen;
2741 fw.bss = bce_RXP_b09FwBss;
2743 fw.rodata_addr = bce_RXP_b09FwRodataAddr;
2744 fw.rodata_len = bce_RXP_b09FwRodataLen;
2745 fw.rodata_index = 0;
2746 fw.rodata = bce_RXP_b09FwRodata;
2748 fw.ver_major = bce_RXP_b06FwReleaseMajor;
2749 fw.ver_minor = bce_RXP_b06FwReleaseMinor;
2750 fw.ver_fix = bce_RXP_b06FwReleaseFix;
2751 fw.start_addr = bce_RXP_b06FwStartAddr;
2753 fw.text_addr = bce_RXP_b06FwTextAddr;
2754 fw.text_len = bce_RXP_b06FwTextLen;
2756 fw.text = bce_RXP_b06FwText;
2758 fw.data_addr = bce_RXP_b06FwDataAddr;
2759 fw.data_len = bce_RXP_b06FwDataLen;
2761 fw.data = bce_RXP_b06FwData;
2763 fw.sbss_addr = bce_RXP_b06FwSbssAddr;
2764 fw.sbss_len = bce_RXP_b06FwSbssLen;
2766 fw.sbss = bce_RXP_b06FwSbss;
2768 fw.bss_addr = bce_RXP_b06FwBssAddr;
2769 fw.bss_len = bce_RXP_b06FwBssLen;
2771 fw.bss = bce_RXP_b06FwBss;
2773 fw.rodata_addr = bce_RXP_b06FwRodataAddr;
2774 fw.rodata_len = bce_RXP_b06FwRodataLen;
2775 fw.rodata_index = 0;
2776 fw.rodata = bce_RXP_b06FwRodata;
2779 DBPRINT(sc, BCE_INFO_RESET, "Loading RX firmware.\n");
2780 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2781 /* Delay RXP start until initialization is complete. */
2785 /****************************************************************************/
2786 /* Initialize the TX CPU. */
2790 /****************************************************************************/
2792 bce_init_txp_cpu(struct bce_softc *sc)
2794 struct cpu_reg cpu_reg;
2797 cpu_reg.mode = BCE_TXP_CPU_MODE;
2798 cpu_reg.mode_value_halt = BCE_TXP_CPU_MODE_SOFT_HALT;
2799 cpu_reg.mode_value_sstep = BCE_TXP_CPU_MODE_STEP_ENA;
2800 cpu_reg.state = BCE_TXP_CPU_STATE;
2801 cpu_reg.state_value_clear = 0xffffff;
2802 cpu_reg.gpr0 = BCE_TXP_CPU_REG_FILE;
2803 cpu_reg.evmask = BCE_TXP_CPU_EVENT_MASK;
2804 cpu_reg.pc = BCE_TXP_CPU_PROGRAM_COUNTER;
2805 cpu_reg.inst = BCE_TXP_CPU_INSTRUCTION;
2806 cpu_reg.bp = BCE_TXP_CPU_HW_BREAKPOINT;
2807 cpu_reg.spad_base = BCE_TXP_SCRATCH;
2808 cpu_reg.mips_view_base = 0x8000000;
2810 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2811 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2812 fw.ver_major = bce_TXP_b09FwReleaseMajor;
2813 fw.ver_minor = bce_TXP_b09FwReleaseMinor;
2814 fw.ver_fix = bce_TXP_b09FwReleaseFix;
2815 fw.start_addr = bce_TXP_b09FwStartAddr;
2817 fw.text_addr = bce_TXP_b09FwTextAddr;
2818 fw.text_len = bce_TXP_b09FwTextLen;
2820 fw.text = bce_TXP_b09FwText;
2822 fw.data_addr = bce_TXP_b09FwDataAddr;
2823 fw.data_len = bce_TXP_b09FwDataLen;
2825 fw.data = bce_TXP_b09FwData;
2827 fw.sbss_addr = bce_TXP_b09FwSbssAddr;
2828 fw.sbss_len = bce_TXP_b09FwSbssLen;
2830 fw.sbss = bce_TXP_b09FwSbss;
2832 fw.bss_addr = bce_TXP_b09FwBssAddr;
2833 fw.bss_len = bce_TXP_b09FwBssLen;
2835 fw.bss = bce_TXP_b09FwBss;
2837 fw.rodata_addr = bce_TXP_b09FwRodataAddr;
2838 fw.rodata_len = bce_TXP_b09FwRodataLen;
2839 fw.rodata_index = 0;
2840 fw.rodata = bce_TXP_b09FwRodata;
2842 fw.ver_major = bce_TXP_b06FwReleaseMajor;
2843 fw.ver_minor = bce_TXP_b06FwReleaseMinor;
2844 fw.ver_fix = bce_TXP_b06FwReleaseFix;
2845 fw.start_addr = bce_TXP_b06FwStartAddr;
2847 fw.text_addr = bce_TXP_b06FwTextAddr;
2848 fw.text_len = bce_TXP_b06FwTextLen;
2850 fw.text = bce_TXP_b06FwText;
2852 fw.data_addr = bce_TXP_b06FwDataAddr;
2853 fw.data_len = bce_TXP_b06FwDataLen;
2855 fw.data = bce_TXP_b06FwData;
2857 fw.sbss_addr = bce_TXP_b06FwSbssAddr;
2858 fw.sbss_len = bce_TXP_b06FwSbssLen;
2860 fw.sbss = bce_TXP_b06FwSbss;
2862 fw.bss_addr = bce_TXP_b06FwBssAddr;
2863 fw.bss_len = bce_TXP_b06FwBssLen;
2865 fw.bss = bce_TXP_b06FwBss;
2867 fw.rodata_addr = bce_TXP_b06FwRodataAddr;
2868 fw.rodata_len = bce_TXP_b06FwRodataLen;
2869 fw.rodata_index = 0;
2870 fw.rodata = bce_TXP_b06FwRodata;
2873 DBPRINT(sc, BCE_INFO_RESET, "Loading TX firmware.\n");
2874 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2875 bce_start_cpu(sc, &cpu_reg);
2879 /****************************************************************************/
2880 /* Initialize the TPAT CPU. */
2884 /****************************************************************************/
2886 bce_init_tpat_cpu(struct bce_softc *sc)
2888 struct cpu_reg cpu_reg;
2891 cpu_reg.mode = BCE_TPAT_CPU_MODE;
2892 cpu_reg.mode_value_halt = BCE_TPAT_CPU_MODE_SOFT_HALT;
2893 cpu_reg.mode_value_sstep = BCE_TPAT_CPU_MODE_STEP_ENA;
2894 cpu_reg.state = BCE_TPAT_CPU_STATE;
2895 cpu_reg.state_value_clear = 0xffffff;
2896 cpu_reg.gpr0 = BCE_TPAT_CPU_REG_FILE;
2897 cpu_reg.evmask = BCE_TPAT_CPU_EVENT_MASK;
2898 cpu_reg.pc = BCE_TPAT_CPU_PROGRAM_COUNTER;
2899 cpu_reg.inst = BCE_TPAT_CPU_INSTRUCTION;
2900 cpu_reg.bp = BCE_TPAT_CPU_HW_BREAKPOINT;
2901 cpu_reg.spad_base = BCE_TPAT_SCRATCH;
2902 cpu_reg.mips_view_base = 0x8000000;
2904 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2905 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
2906 fw.ver_major = bce_TPAT_b09FwReleaseMajor;
2907 fw.ver_minor = bce_TPAT_b09FwReleaseMinor;
2908 fw.ver_fix = bce_TPAT_b09FwReleaseFix;
2909 fw.start_addr = bce_TPAT_b09FwStartAddr;
2911 fw.text_addr = bce_TPAT_b09FwTextAddr;
2912 fw.text_len = bce_TPAT_b09FwTextLen;
2914 fw.text = bce_TPAT_b09FwText;
2916 fw.data_addr = bce_TPAT_b09FwDataAddr;
2917 fw.data_len = bce_TPAT_b09FwDataLen;
2919 fw.data = bce_TPAT_b09FwData;
2921 fw.sbss_addr = bce_TPAT_b09FwSbssAddr;
2922 fw.sbss_len = bce_TPAT_b09FwSbssLen;
2924 fw.sbss = bce_TPAT_b09FwSbss;
2926 fw.bss_addr = bce_TPAT_b09FwBssAddr;
2927 fw.bss_len = bce_TPAT_b09FwBssLen;
2929 fw.bss = bce_TPAT_b09FwBss;
2931 fw.rodata_addr = bce_TPAT_b09FwRodataAddr;
2932 fw.rodata_len = bce_TPAT_b09FwRodataLen;
2933 fw.rodata_index = 0;
2934 fw.rodata = bce_TPAT_b09FwRodata;
2936 fw.ver_major = bce_TPAT_b06FwReleaseMajor;
2937 fw.ver_minor = bce_TPAT_b06FwReleaseMinor;
2938 fw.ver_fix = bce_TPAT_b06FwReleaseFix;
2939 fw.start_addr = bce_TPAT_b06FwStartAddr;
2941 fw.text_addr = bce_TPAT_b06FwTextAddr;
2942 fw.text_len = bce_TPAT_b06FwTextLen;
2944 fw.text = bce_TPAT_b06FwText;
2946 fw.data_addr = bce_TPAT_b06FwDataAddr;
2947 fw.data_len = bce_TPAT_b06FwDataLen;
2949 fw.data = bce_TPAT_b06FwData;
2951 fw.sbss_addr = bce_TPAT_b06FwSbssAddr;
2952 fw.sbss_len = bce_TPAT_b06FwSbssLen;
2954 fw.sbss = bce_TPAT_b06FwSbss;
2956 fw.bss_addr = bce_TPAT_b06FwBssAddr;
2957 fw.bss_len = bce_TPAT_b06FwBssLen;
2959 fw.bss = bce_TPAT_b06FwBss;
2961 fw.rodata_addr = bce_TPAT_b06FwRodataAddr;
2962 fw.rodata_len = bce_TPAT_b06FwRodataLen;
2963 fw.rodata_index = 0;
2964 fw.rodata = bce_TPAT_b06FwRodata;
2967 DBPRINT(sc, BCE_INFO_RESET, "Loading TPAT firmware.\n");
2968 bce_load_cpu_fw(sc, &cpu_reg, &fw);
2969 bce_start_cpu(sc, &cpu_reg);
2973 /****************************************************************************/
2974 /* Initialize the CP CPU. */
2978 /****************************************************************************/
2980 bce_init_cp_cpu(struct bce_softc *sc)
2982 struct cpu_reg cpu_reg;
2985 cpu_reg.mode = BCE_CP_CPU_MODE;
2986 cpu_reg.mode_value_halt = BCE_CP_CPU_MODE_SOFT_HALT;
2987 cpu_reg.mode_value_sstep = BCE_CP_CPU_MODE_STEP_ENA;
2988 cpu_reg.state = BCE_CP_CPU_STATE;
2989 cpu_reg.state_value_clear = 0xffffff;
2990 cpu_reg.gpr0 = BCE_CP_CPU_REG_FILE;
2991 cpu_reg.evmask = BCE_CP_CPU_EVENT_MASK;
2992 cpu_reg.pc = BCE_CP_CPU_PROGRAM_COUNTER;
2993 cpu_reg.inst = BCE_CP_CPU_INSTRUCTION;
2994 cpu_reg.bp = BCE_CP_CPU_HW_BREAKPOINT;
2995 cpu_reg.spad_base = BCE_CP_SCRATCH;
2996 cpu_reg.mips_view_base = 0x8000000;
2998 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
2999 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3000 fw.ver_major = bce_CP_b09FwReleaseMajor;
3001 fw.ver_minor = bce_CP_b09FwReleaseMinor;
3002 fw.ver_fix = bce_CP_b09FwReleaseFix;
3003 fw.start_addr = bce_CP_b09FwStartAddr;
3005 fw.text_addr = bce_CP_b09FwTextAddr;
3006 fw.text_len = bce_CP_b09FwTextLen;
3008 fw.text = bce_CP_b09FwText;
3010 fw.data_addr = bce_CP_b09FwDataAddr;
3011 fw.data_len = bce_CP_b09FwDataLen;
3013 fw.data = bce_CP_b09FwData;
3015 fw.sbss_addr = bce_CP_b09FwSbssAddr;
3016 fw.sbss_len = bce_CP_b09FwSbssLen;
3018 fw.sbss = bce_CP_b09FwSbss;
3020 fw.bss_addr = bce_CP_b09FwBssAddr;
3021 fw.bss_len = bce_CP_b09FwBssLen;
3023 fw.bss = bce_CP_b09FwBss;
3025 fw.rodata_addr = bce_CP_b09FwRodataAddr;
3026 fw.rodata_len = bce_CP_b09FwRodataLen;
3027 fw.rodata_index = 0;
3028 fw.rodata = bce_CP_b09FwRodata;
3030 fw.ver_major = bce_CP_b06FwReleaseMajor;
3031 fw.ver_minor = bce_CP_b06FwReleaseMinor;
3032 fw.ver_fix = bce_CP_b06FwReleaseFix;
3033 fw.start_addr = bce_CP_b06FwStartAddr;
3035 fw.text_addr = bce_CP_b06FwTextAddr;
3036 fw.text_len = bce_CP_b06FwTextLen;
3038 fw.text = bce_CP_b06FwText;
3040 fw.data_addr = bce_CP_b06FwDataAddr;
3041 fw.data_len = bce_CP_b06FwDataLen;
3043 fw.data = bce_CP_b06FwData;
3045 fw.sbss_addr = bce_CP_b06FwSbssAddr;
3046 fw.sbss_len = bce_CP_b06FwSbssLen;
3048 fw.sbss = bce_CP_b06FwSbss;
3050 fw.bss_addr = bce_CP_b06FwBssAddr;
3051 fw.bss_len = bce_CP_b06FwBssLen;
3053 fw.bss = bce_CP_b06FwBss;
3055 fw.rodata_addr = bce_CP_b06FwRodataAddr;
3056 fw.rodata_len = bce_CP_b06FwRodataLen;
3057 fw.rodata_index = 0;
3058 fw.rodata = bce_CP_b06FwRodata;
3061 DBPRINT(sc, BCE_INFO_RESET, "Loading CP firmware.\n");
3062 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3063 bce_start_cpu(sc, &cpu_reg);
3067 /****************************************************************************/
3068 /* Initialize the COM CPU. */
3072 /****************************************************************************/
3074 bce_init_com_cpu(struct bce_softc *sc)
3076 struct cpu_reg cpu_reg;
3079 cpu_reg.mode = BCE_COM_CPU_MODE;
3080 cpu_reg.mode_value_halt = BCE_COM_CPU_MODE_SOFT_HALT;
3081 cpu_reg.mode_value_sstep = BCE_COM_CPU_MODE_STEP_ENA;
3082 cpu_reg.state = BCE_COM_CPU_STATE;
3083 cpu_reg.state_value_clear = 0xffffff;
3084 cpu_reg.gpr0 = BCE_COM_CPU_REG_FILE;
3085 cpu_reg.evmask = BCE_COM_CPU_EVENT_MASK;
3086 cpu_reg.pc = BCE_COM_CPU_PROGRAM_COUNTER;
3087 cpu_reg.inst = BCE_COM_CPU_INSTRUCTION;
3088 cpu_reg.bp = BCE_COM_CPU_HW_BREAKPOINT;
3089 cpu_reg.spad_base = BCE_COM_SCRATCH;
3090 cpu_reg.mips_view_base = 0x8000000;
3092 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3093 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3094 fw.ver_major = bce_COM_b09FwReleaseMajor;
3095 fw.ver_minor = bce_COM_b09FwReleaseMinor;
3096 fw.ver_fix = bce_COM_b09FwReleaseFix;
3097 fw.start_addr = bce_COM_b09FwStartAddr;
3099 fw.text_addr = bce_COM_b09FwTextAddr;
3100 fw.text_len = bce_COM_b09FwTextLen;
3102 fw.text = bce_COM_b09FwText;
3104 fw.data_addr = bce_COM_b09FwDataAddr;
3105 fw.data_len = bce_COM_b09FwDataLen;
3107 fw.data = bce_COM_b09FwData;
3109 fw.sbss_addr = bce_COM_b09FwSbssAddr;
3110 fw.sbss_len = bce_COM_b09FwSbssLen;
3112 fw.sbss = bce_COM_b09FwSbss;
3114 fw.bss_addr = bce_COM_b09FwBssAddr;
3115 fw.bss_len = bce_COM_b09FwBssLen;
3117 fw.bss = bce_COM_b09FwBss;
3119 fw.rodata_addr = bce_COM_b09FwRodataAddr;
3120 fw.rodata_len = bce_COM_b09FwRodataLen;
3121 fw.rodata_index = 0;
3122 fw.rodata = bce_COM_b09FwRodata;
3124 fw.ver_major = bce_COM_b06FwReleaseMajor;
3125 fw.ver_minor = bce_COM_b06FwReleaseMinor;
3126 fw.ver_fix = bce_COM_b06FwReleaseFix;
3127 fw.start_addr = bce_COM_b06FwStartAddr;
3129 fw.text_addr = bce_COM_b06FwTextAddr;
3130 fw.text_len = bce_COM_b06FwTextLen;
3132 fw.text = bce_COM_b06FwText;
3134 fw.data_addr = bce_COM_b06FwDataAddr;
3135 fw.data_len = bce_COM_b06FwDataLen;
3137 fw.data = bce_COM_b06FwData;
3139 fw.sbss_addr = bce_COM_b06FwSbssAddr;
3140 fw.sbss_len = bce_COM_b06FwSbssLen;
3142 fw.sbss = bce_COM_b06FwSbss;
3144 fw.bss_addr = bce_COM_b06FwBssAddr;
3145 fw.bss_len = bce_COM_b06FwBssLen;
3147 fw.bss = bce_COM_b06FwBss;
3149 fw.rodata_addr = bce_COM_b06FwRodataAddr;
3150 fw.rodata_len = bce_COM_b06FwRodataLen;
3151 fw.rodata_index = 0;
3152 fw.rodata = bce_COM_b06FwRodata;
3155 DBPRINT(sc, BCE_INFO_RESET, "Loading COM firmware.\n");
3156 bce_load_cpu_fw(sc, &cpu_reg, &fw);
3157 bce_start_cpu(sc, &cpu_reg);
3161 /****************************************************************************/
3162 /* Initialize the RV2P, RX, TX, TPAT, COM, and CP CPUs. */
3164 /* Loads the firmware for each CPU and starts the CPU. */
3168 /****************************************************************************/
3170 bce_init_cpus(struct bce_softc *sc)
3172 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3173 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3174 if (BCE_CHIP_REV(sc) == BCE_CHIP_REV_Ax) {
3175 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc1,
3176 sizeof(bce_xi90_rv2p_proc1), RV2P_PROC1);
3177 bce_load_rv2p_fw(sc, bce_xi90_rv2p_proc2,
3178 sizeof(bce_xi90_rv2p_proc2), RV2P_PROC2);
3180 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc1,
3181 sizeof(bce_xi_rv2p_proc1), RV2P_PROC1);
3182 bce_load_rv2p_fw(sc, bce_xi_rv2p_proc2,
3183 sizeof(bce_xi_rv2p_proc2), RV2P_PROC2);
3186 bce_load_rv2p_fw(sc, bce_rv2p_proc1,
3187 sizeof(bce_rv2p_proc1), RV2P_PROC1);
3188 bce_load_rv2p_fw(sc, bce_rv2p_proc2,
3189 sizeof(bce_rv2p_proc2), RV2P_PROC2);
3192 bce_init_rxp_cpu(sc);
3193 bce_init_txp_cpu(sc);
3194 bce_init_tpat_cpu(sc);
3195 bce_init_com_cpu(sc);
3196 bce_init_cp_cpu(sc);
3200 /****************************************************************************/
3201 /* Initialize context memory. */
3203 /* Clears the memory associated with each Context ID (CID). */
3207 /****************************************************************************/
3209 bce_init_ctx(struct bce_softc *sc)
3211 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3212 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3213 /* DRC: Replace this constant value with a #define. */
3214 int i, retry_cnt = 10;
3218 * BCM5709 context memory may be cached
3219 * in host memory so prepare the host memory
3222 val = BCE_CTX_COMMAND_ENABLED | BCE_CTX_COMMAND_MEM_INIT |
3224 val |= (BCM_PAGE_BITS - 8) << 16;
3225 REG_WR(sc, BCE_CTX_COMMAND, val);
3227 /* Wait for mem init command to complete. */
3228 for (i = 0; i < retry_cnt; i++) {
3229 val = REG_RD(sc, BCE_CTX_COMMAND);
3230 if (!(val & BCE_CTX_COMMAND_MEM_INIT))
3235 for (i = 0; i < sc->ctx_pages; i++) {
3239 * Set the physical address of the context
3242 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA0,
3243 BCE_ADDR_LO(sc->ctx_paddr[i] & 0xfffffff0) |
3244 BCE_CTX_HOST_PAGE_TBL_DATA0_VALID);
3245 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_DATA1,
3246 BCE_ADDR_HI(sc->ctx_paddr[i]));
3247 REG_WR(sc, BCE_CTX_HOST_PAGE_TBL_CTRL,
3248 i | BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
3251 * Verify that the context memory write was successful.
3253 for (j = 0; j < retry_cnt; j++) {
3254 val = REG_RD(sc, BCE_CTX_HOST_PAGE_TBL_CTRL);
3256 BCE_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) == 0)
3262 uint32_t vcid_addr, offset;
3265 * For the 5706/5708, context memory is local to
3266 * the controller, so initialize the controller
3270 vcid_addr = GET_CID_ADDR(96);
3272 vcid_addr -= PHY_CTX_SIZE;
3274 REG_WR(sc, BCE_CTX_VIRT_ADDR, 0);
3275 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3277 for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
3278 CTX_WR(sc, 0x00, offset, 0);
3280 REG_WR(sc, BCE_CTX_VIRT_ADDR, vcid_addr);
3281 REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
3287 /****************************************************************************/
3288 /* Fetch the permanent MAC address of the controller. */
3292 /****************************************************************************/
3294 bce_get_mac_addr(struct bce_softc *sc)
3296 uint32_t mac_lo = 0, mac_hi = 0;
3299 * The NetXtreme II bootcode populates various NIC
3300 * power-on and runtime configuration items in a
3301 * shared memory area. The factory configured MAC
3302 * address is available from both NVRAM and the
3303 * shared memory area so we'll read the value from
3304 * shared memory for speed.
3307 mac_hi = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_UPPER);
3308 mac_lo = bce_shmem_rd(sc, BCE_PORT_HW_CFG_MAC_LOWER);
3310 if (mac_lo == 0 && mac_hi == 0) {
3311 if_printf(&sc->arpcom.ac_if, "Invalid Ethernet address!\n");
3313 sc->eaddr[0] = (u_char)(mac_hi >> 8);
3314 sc->eaddr[1] = (u_char)(mac_hi >> 0);
3315 sc->eaddr[2] = (u_char)(mac_lo >> 24);
3316 sc->eaddr[3] = (u_char)(mac_lo >> 16);
3317 sc->eaddr[4] = (u_char)(mac_lo >> 8);
3318 sc->eaddr[5] = (u_char)(mac_lo >> 0);
3321 DBPRINT(sc, BCE_INFO, "Permanent Ethernet address = %6D\n", sc->eaddr, ":");
3325 /****************************************************************************/
3326 /* Program the MAC address. */
3330 /****************************************************************************/
3332 bce_set_mac_addr(struct bce_softc *sc)
3334 const uint8_t *mac_addr = sc->eaddr;
3337 DBPRINT(sc, BCE_INFO, "Setting Ethernet address = %6D\n",
3340 val = (mac_addr[0] << 8) | mac_addr[1];
3341 REG_WR(sc, BCE_EMAC_MAC_MATCH0, val);
3343 val = (mac_addr[2] << 24) |
3344 (mac_addr[3] << 16) |
3345 (mac_addr[4] << 8) |
3347 REG_WR(sc, BCE_EMAC_MAC_MATCH1, val);
3351 /****************************************************************************/
3352 /* Stop the controller. */
3356 /****************************************************************************/
3358 bce_stop(struct bce_softc *sc)
3360 struct ifnet *ifp = &sc->arpcom.ac_if;
3361 struct mii_data *mii = device_get_softc(sc->bce_miibus);
3362 struct ifmedia_entry *ifm;
3365 ASSERT_SERIALIZED(ifp->if_serializer);
3367 callout_stop(&sc->bce_tick_callout);
3369 /* Disable the transmit/receive blocks. */
3370 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS, BCE_MISC_ENABLE_CLR_DEFAULT);
3371 REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3374 bce_disable_intr(sc);
3376 /* Free the RX lists. */
3377 bce_free_rx_chain(sc);
3379 /* Free TX buffers. */
3380 bce_free_tx_chain(sc);
3383 * Isolate/power down the PHY, but leave the media selection
3384 * unchanged so that things will be put back to normal when
3385 * we bring the interface back up.
3387 * 'mii' may be NULL if bce_stop() is called by bce_detach().
3390 itmp = ifp->if_flags;
3391 ifp->if_flags |= IFF_UP;
3392 ifm = mii->mii_media.ifm_cur;
3393 mtmp = ifm->ifm_media;
3394 ifm->ifm_media = IFM_ETHER | IFM_NONE;
3396 ifm->ifm_media = mtmp;
3397 ifp->if_flags = itmp;
3401 sc->bce_coalchg_mask = 0;
3403 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3409 bce_reset(struct bce_softc *sc, uint32_t reset_code)
3414 /* Wait for pending PCI transactions to complete. */
3415 REG_WR(sc, BCE_MISC_ENABLE_CLR_BITS,
3416 BCE_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
3417 BCE_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
3418 BCE_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
3419 BCE_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
3420 val = REG_RD(sc, BCE_MISC_ENABLE_CLR_BITS);
3424 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3425 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3426 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3427 val &= ~BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3428 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3431 /* Assume bootcode is running. */
3432 sc->bce_fw_timed_out = 0;
3434 /* Give the firmware a chance to prepare for the reset. */
3435 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT0 | reset_code);
3437 if_printf(&sc->arpcom.ac_if,
3438 "Firmware is not ready for reset\n");
3442 /* Set a firmware reminder that this is a soft reset. */
3443 bce_shmem_wr(sc, BCE_DRV_RESET_SIGNATURE,
3444 BCE_DRV_RESET_SIGNATURE_MAGIC);
3446 /* Dummy read to force the chip to complete all current transactions. */
3447 val = REG_RD(sc, BCE_MISC_ID);
3450 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3451 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3452 REG_WR(sc, BCE_MISC_COMMAND, BCE_MISC_COMMAND_SW_RESET);
3453 REG_RD(sc, BCE_MISC_COMMAND);
3456 val = BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3457 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3459 pci_write_config(sc->bce_dev, BCE_PCICFG_MISC_CONFIG, val, 4);
3461 val = BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3462 BCE_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
3463 BCE_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
3464 REG_WR(sc, BCE_PCICFG_MISC_CONFIG, val);
3466 /* Allow up to 30us for reset to complete. */
3467 for (i = 0; i < 10; i++) {
3468 val = REG_RD(sc, BCE_PCICFG_MISC_CONFIG);
3469 if ((val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3470 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
3475 /* Check that reset completed successfully. */
3476 if (val & (BCE_PCICFG_MISC_CONFIG_CORE_RST_REQ |
3477 BCE_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
3478 if_printf(&sc->arpcom.ac_if, "Reset failed!\n");
3483 /* Make sure byte swapping is properly configured. */
3484 val = REG_RD(sc, BCE_PCI_SWAP_DIAG0);
3485 if (val != 0x01020304) {
3486 if_printf(&sc->arpcom.ac_if, "Byte swap is incorrect!\n");
3490 /* Just completed a reset, assume that firmware is running again. */
3491 sc->bce_fw_timed_out = 0;
3493 /* Wait for the firmware to finish its initialization. */
3494 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT1 | reset_code);
3496 if_printf(&sc->arpcom.ac_if,
3497 "Firmware did not complete initialization!\n");
3504 bce_chipinit(struct bce_softc *sc)
3509 /* Make sure the interrupt is not active. */
3510 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
3511 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
3514 * Initialize DMA byte/word swapping, configure the number of DMA
3515 * channels and PCI clock compensation delay.
3517 val = BCE_DMA_CONFIG_DATA_BYTE_SWAP |
3518 BCE_DMA_CONFIG_DATA_WORD_SWAP |
3519 #if BYTE_ORDER == BIG_ENDIAN
3520 BCE_DMA_CONFIG_CNTL_BYTE_SWAP |
3522 BCE_DMA_CONFIG_CNTL_WORD_SWAP |
3523 DMA_READ_CHANS << 12 |
3524 DMA_WRITE_CHANS << 16;
3526 val |= (0x2 << 20) | BCE_DMA_CONFIG_CNTL_PCI_COMP_DLY;
3528 if ((sc->bce_flags & BCE_PCIX_FLAG) && sc->bus_speed_mhz == 133)
3529 val |= BCE_DMA_CONFIG_PCI_FAST_CLK_CMP;
3532 * This setting resolves a problem observed on certain Intel PCI
3533 * chipsets that cannot handle multiple outstanding DMA operations.
3534 * See errata E9_5706A1_65.
3536 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5706 &&
3537 BCE_CHIP_ID(sc) != BCE_CHIP_ID_5706_A0 &&
3538 !(sc->bce_flags & BCE_PCIX_FLAG))
3539 val |= BCE_DMA_CONFIG_CNTL_PING_PONG_DMA;
3541 REG_WR(sc, BCE_DMA_CONFIG, val);
3543 /* Enable the RX_V2P and Context state machines before access. */
3544 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3545 BCE_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
3546 BCE_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
3547 BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
3549 /* Initialize context mapping and zero out the quick contexts. */
3552 /* Initialize the on-boards CPUs */
3555 /* Enable management frames (NC-SI) to flow to the MCP. */
3556 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3557 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) |
3558 BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3559 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3562 /* Prepare NVRAM for access. */
3563 rc = bce_init_nvram(sc);
3567 /* Set the kernel bypass block size */
3568 val = REG_RD(sc, BCE_MQ_CONFIG);
3569 val &= ~BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE;
3570 val |= BCE_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
3572 /* Enable bins used on the 5709/5716. */
3573 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3574 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3575 val |= BCE_MQ_CONFIG_BIN_MQ_MODE;
3576 if (BCE_CHIP_ID(sc) == BCE_CHIP_ID_5709_A1)
3577 val |= BCE_MQ_CONFIG_HALT_DIS;
3580 REG_WR(sc, BCE_MQ_CONFIG, val);
3582 val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
3583 REG_WR(sc, BCE_MQ_KNL_BYP_WIND_START, val);
3584 REG_WR(sc, BCE_MQ_KNL_WIND_END, val);
3586 /* Set the page size and clear the RV2P processor stall bits. */
3587 val = (BCM_PAGE_BITS - 8) << 24;
3588 REG_WR(sc, BCE_RV2P_CONFIG, val);
3590 /* Configure page size. */
3591 val = REG_RD(sc, BCE_TBDR_CONFIG);
3592 val &= ~BCE_TBDR_CONFIG_PAGE_SIZE;
3593 val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
3594 REG_WR(sc, BCE_TBDR_CONFIG, val);
3596 /* Set the perfect match control register to default. */
3597 REG_WR_IND(sc, BCE_RXP_PM_CTRL, 0);
3603 /****************************************************************************/
3604 /* Initialize the controller in preparation to send/receive traffic. */
3607 /* 0 for success, positive value for failure. */
3608 /****************************************************************************/
3610 bce_blockinit(struct bce_softc *sc)
3615 /* Load the hardware default MAC address. */
3616 bce_set_mac_addr(sc);
3618 /* Set the Ethernet backoff seed value */
3619 val = sc->eaddr[0] + (sc->eaddr[1] << 8) + (sc->eaddr[2] << 16) +
3620 sc->eaddr[3] + (sc->eaddr[4] << 8) + (sc->eaddr[5] << 16);
3621 REG_WR(sc, BCE_EMAC_BACKOFF_SEED, val);
3623 sc->last_status_idx = 0;
3624 sc->rx_mode = BCE_EMAC_RX_MODE_SORT_MODE;
3626 /* Set up link change interrupt generation. */
3627 REG_WR(sc, BCE_EMAC_ATTENTION_ENA, BCE_EMAC_ATTENTION_ENA_LINK);
3629 /* Program the physical address of the status block. */
3630 REG_WR(sc, BCE_HC_STATUS_ADDR_L, BCE_ADDR_LO(sc->status_block_paddr));
3631 REG_WR(sc, BCE_HC_STATUS_ADDR_H, BCE_ADDR_HI(sc->status_block_paddr));
3633 /* Program the physical address of the statistics block. */
3634 REG_WR(sc, BCE_HC_STATISTICS_ADDR_L,
3635 BCE_ADDR_LO(sc->stats_block_paddr));
3636 REG_WR(sc, BCE_HC_STATISTICS_ADDR_H,
3637 BCE_ADDR_HI(sc->stats_block_paddr));
3639 /* Program various host coalescing parameters. */
3640 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
3641 (sc->bce_tx_quick_cons_trip_int << 16) |
3642 sc->bce_tx_quick_cons_trip);
3643 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
3644 (sc->bce_rx_quick_cons_trip_int << 16) |
3645 sc->bce_rx_quick_cons_trip);
3646 REG_WR(sc, BCE_HC_COMP_PROD_TRIP,
3647 (sc->bce_comp_prod_trip_int << 16) | sc->bce_comp_prod_trip);
3648 REG_WR(sc, BCE_HC_TX_TICKS,
3649 (sc->bce_tx_ticks_int << 16) | sc->bce_tx_ticks);
3650 REG_WR(sc, BCE_HC_RX_TICKS,
3651 (sc->bce_rx_ticks_int << 16) | sc->bce_rx_ticks);
3652 REG_WR(sc, BCE_HC_COM_TICKS,
3653 (sc->bce_com_ticks_int << 16) | sc->bce_com_ticks);
3654 REG_WR(sc, BCE_HC_CMD_TICKS,
3655 (sc->bce_cmd_ticks_int << 16) | sc->bce_cmd_ticks);
3656 REG_WR(sc, BCE_HC_STATS_TICKS, (sc->bce_stats_ticks & 0xffff00));
3657 REG_WR(sc, BCE_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
3658 REG_WR(sc, BCE_HC_CONFIG,
3659 BCE_HC_CONFIG_TX_TMR_MODE |
3660 BCE_HC_CONFIG_COLLECT_STATS);
3662 /* Clear the internal statistics counters. */
3663 REG_WR(sc, BCE_HC_COMMAND, BCE_HC_COMMAND_CLR_STAT_NOW);
3665 /* Verify that bootcode is running. */
3666 reg = bce_shmem_rd(sc, BCE_DEV_INFO_SIGNATURE);
3668 DBRUNIF(DB_RANDOMTRUE(bce_debug_bootcode_running_failure),
3669 if_printf(&sc->arpcom.ac_if,
3670 "%s(%d): Simulating bootcode failure.\n",
3671 __FILE__, __LINE__);
3674 if ((reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
3675 BCE_DEV_INFO_SIGNATURE_MAGIC) {
3676 if_printf(&sc->arpcom.ac_if,
3677 "Bootcode not running! Found: 0x%08X, "
3678 "Expected: 08%08X\n",
3679 reg & BCE_DEV_INFO_SIGNATURE_MAGIC_MASK,
3680 BCE_DEV_INFO_SIGNATURE_MAGIC);
3685 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3686 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3687 val = REG_RD(sc, BCE_MISC_NEW_CORE_CTL);
3688 val |= BCE_MISC_NEW_CORE_CTL_DMA_ENABLE;
3689 REG_WR(sc, BCE_MISC_NEW_CORE_CTL, val);
3692 /* Allow bootcode to apply any additional fixes before enabling MAC. */
3693 rc = bce_fw_sync(sc, BCE_DRV_MSG_DATA_WAIT2 | BCE_DRV_MSG_CODE_RESET);
3695 /* Enable link state change interrupt generation. */
3696 REG_WR(sc, BCE_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
3698 /* Enable the RXP. */
3699 bce_start_rxp_cpu(sc);
3701 /* Disable management frames (NC-SI) from flowing to the MCP. */
3702 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
3703 val = REG_RD(sc, BCE_RPM_MGMT_PKT_CTRL) &
3704 ~BCE_RPM_MGMT_PKT_CTRL_MGMT_EN;
3705 REG_WR(sc, BCE_RPM_MGMT_PKT_CTRL, val);
3708 /* Enable all remaining blocks in the MAC. */
3709 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3710 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3711 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
3712 BCE_MISC_ENABLE_DEFAULT_XI);
3714 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
3716 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
3719 /* Save the current host coalescing block settings. */
3720 sc->hc_command = REG_RD(sc, BCE_HC_COMMAND);
3726 /****************************************************************************/
3727 /* Encapsulate an mbuf cluster into the rx_bd chain. */
3729 /* The NetXtreme II can support Jumbo frames by using multiple rx_bd's. */
3730 /* This routine will map an mbuf cluster into 1 or more rx_bd's as */
3734 /* 0 for success, positive value for failure. */
3735 /****************************************************************************/
3737 bce_newbuf_std(struct bce_softc *sc, uint16_t *prod, uint16_t *chain_prod,
3738 uint32_t *prod_bseq, int init)
3741 bus_dma_segment_t seg;
3745 uint16_t debug_chain_prod = *chain_prod;
3748 /* Make sure the inputs are valid. */
3749 DBRUNIF((*chain_prod > MAX_RX_BD),
3750 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3751 "RX producer out of range: 0x%04X > 0x%04X\n",
3753 *chain_prod, (uint16_t)MAX_RX_BD));
3755 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(enter): prod = 0x%04X, chain_prod = 0x%04X, "
3756 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3758 DBRUNIF(DB_RANDOMTRUE(bce_debug_mbuf_allocation_failure),
3759 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3760 "Simulating mbuf allocation failure.\n",
3761 __FILE__, __LINE__);
3762 sc->mbuf_alloc_failed++;
3765 /* This is a new mbuf allocation. */
3766 m_new = m_getcl(init ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
3769 DBRUNIF(1, sc->rx_mbuf_alloc++);
3771 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
3773 /* Map the mbuf cluster into device memory. */
3774 error = bus_dmamap_load_mbuf_segment(sc->rx_mbuf_tag,
3775 sc->rx_mbuf_tmpmap, m_new, &seg, 1, &nseg,
3780 if_printf(&sc->arpcom.ac_if,
3781 "Error mapping mbuf into RX chain!\n");
3783 DBRUNIF(1, sc->rx_mbuf_alloc--);
3787 if (sc->rx_mbuf_ptr[*chain_prod] != NULL) {
3788 bus_dmamap_unload(sc->rx_mbuf_tag,
3789 sc->rx_mbuf_map[*chain_prod]);
3792 map = sc->rx_mbuf_map[*chain_prod];
3793 sc->rx_mbuf_map[*chain_prod] = sc->rx_mbuf_tmpmap;
3794 sc->rx_mbuf_tmpmap = map;
3796 /* Watch for overflow. */
3797 DBRUNIF((sc->free_rx_bd > USABLE_RX_BD),
3798 if_printf(&sc->arpcom.ac_if, "%s(%d): "
3799 "Too many free rx_bd (0x%04X > 0x%04X)!\n",
3800 __FILE__, __LINE__, sc->free_rx_bd,
3801 (uint16_t)USABLE_RX_BD));
3803 /* Update some debug statistic counters */
3804 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
3805 sc->rx_low_watermark = sc->free_rx_bd);
3806 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
3808 /* Save the mbuf and update our counter. */
3809 sc->rx_mbuf_ptr[*chain_prod] = m_new;
3810 sc->rx_mbuf_paddr[*chain_prod] = seg.ds_addr;
3813 bce_setup_rxdesc_std(sc, *chain_prod, prod_bseq);
3815 DBRUN(BCE_VERBOSE_RECV,
3816 bce_dump_rx_mbuf_chain(sc, debug_chain_prod, 1));
3818 DBPRINT(sc, BCE_VERBOSE_RECV, "%s(exit): prod = 0x%04X, chain_prod = 0x%04X, "
3819 "prod_bseq = 0x%08X\n", __func__, *prod, *chain_prod, *prod_bseq);
3826 bce_setup_rxdesc_std(struct bce_softc *sc, uint16_t chain_prod, uint32_t *prod_bseq)
3832 paddr = sc->rx_mbuf_paddr[chain_prod];
3833 len = sc->rx_mbuf_ptr[chain_prod]->m_len;
3835 /* Setup the rx_bd for the first segment. */
3836 rxbd = &sc->rx_bd_chain[RX_PAGE(chain_prod)][RX_IDX(chain_prod)];
3838 rxbd->rx_bd_haddr_lo = htole32(BCE_ADDR_LO(paddr));
3839 rxbd->rx_bd_haddr_hi = htole32(BCE_ADDR_HI(paddr));
3840 rxbd->rx_bd_len = htole32(len);
3841 rxbd->rx_bd_flags = htole32(RX_BD_FLAGS_START);
3844 rxbd->rx_bd_flags |= htole32(RX_BD_FLAGS_END);
3848 /****************************************************************************/
3849 /* Initialize the TX context memory. */
3853 /****************************************************************************/
3855 bce_init_tx_context(struct bce_softc *sc)
3859 /* Initialize the context ID for an L2 TX chain. */
3860 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
3861 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
3862 /* Set the CID type to support an L2 connection. */
3863 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3864 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE_XI, val);
3865 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3866 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE_XI, val);
3868 /* Point the hardware to the first page in the chain. */
3869 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3870 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3871 BCE_L2CTX_TX_TBDR_BHADDR_HI_XI, val);
3872 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3873 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3874 BCE_L2CTX_TX_TBDR_BHADDR_LO_XI, val);
3876 /* Set the CID type to support an L2 connection. */
3877 val = BCE_L2CTX_TX_TYPE_TYPE_L2 | BCE_L2CTX_TX_TYPE_SIZE_L2;
3878 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_TYPE, val);
3879 val = BCE_L2CTX_TX_CMD_TYPE_TYPE_L2 | (8 << 16);
3880 CTX_WR(sc, GET_CID_ADDR(TX_CID), BCE_L2CTX_TX_CMD_TYPE, val);
3882 /* Point the hardware to the first page in the chain. */
3883 val = BCE_ADDR_HI(sc->tx_bd_chain_paddr[0]);
3884 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3885 BCE_L2CTX_TX_TBDR_BHADDR_HI, val);
3886 val = BCE_ADDR_LO(sc->tx_bd_chain_paddr[0]);
3887 CTX_WR(sc, GET_CID_ADDR(TX_CID),
3888 BCE_L2CTX_TX_TBDR_BHADDR_LO, val);
3893 /****************************************************************************/
3894 /* Allocate memory and initialize the TX data structures. */
3897 /* 0 for success, positive value for failure. */
3898 /****************************************************************************/
3900 bce_init_tx_chain(struct bce_softc *sc)
3905 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3907 /* Set the initial TX producer/consumer indices. */
3910 sc->tx_prod_bseq = 0;
3912 sc->max_tx_bd = USABLE_TX_BD;
3913 DBRUNIF(1, sc->tx_hi_watermark = USABLE_TX_BD);
3914 DBRUNIF(1, sc->tx_full_count = 0);
3917 * The NetXtreme II supports a linked-list structre called
3918 * a Buffer Descriptor Chain (or BD chain). A BD chain
3919 * consists of a series of 1 or more chain pages, each of which
3920 * consists of a fixed number of BD entries.
3921 * The last BD entry on each page is a pointer to the next page
3922 * in the chain, and the last pointer in the BD chain
3923 * points back to the beginning of the chain.
3926 /* Set the TX next pointer chain entries. */
3927 for (i = 0; i < TX_PAGES; i++) {
3930 txbd = &sc->tx_bd_chain[i][USABLE_TX_BD_PER_PAGE];
3932 /* Check if we've reached the last page. */
3933 if (i == (TX_PAGES - 1))
3938 txbd->tx_bd_haddr_hi =
3939 htole32(BCE_ADDR_HI(sc->tx_bd_chain_paddr[j]));
3940 txbd->tx_bd_haddr_lo =
3941 htole32(BCE_ADDR_LO(sc->tx_bd_chain_paddr[j]));
3943 bce_init_tx_context(sc);
3949 /****************************************************************************/
3950 /* Free memory and clear the TX data structures. */
3954 /****************************************************************************/
3956 bce_free_tx_chain(struct bce_softc *sc)
3960 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
3962 /* Unmap, unload, and free any mbufs still in the TX mbuf chain. */
3963 for (i = 0; i < TOTAL_TX_BD; i++) {
3964 if (sc->tx_mbuf_ptr[i] != NULL) {
3965 bus_dmamap_unload(sc->tx_mbuf_tag, sc->tx_mbuf_map[i]);
3966 m_freem(sc->tx_mbuf_ptr[i]);
3967 sc->tx_mbuf_ptr[i] = NULL;
3968 DBRUNIF(1, sc->tx_mbuf_alloc--);
3972 /* Clear each TX chain page. */
3973 for (i = 0; i < TX_PAGES; i++)
3974 bzero(sc->tx_bd_chain[i], BCE_TX_CHAIN_PAGE_SZ);
3977 /* Check if we lost any mbufs in the process. */
3978 DBRUNIF((sc->tx_mbuf_alloc),
3979 if_printf(&sc->arpcom.ac_if,
3980 "%s(%d): Memory leak! "
3981 "Lost %d mbufs from tx chain!\n",
3982 __FILE__, __LINE__, sc->tx_mbuf_alloc));
3984 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
3988 /****************************************************************************/
3989 /* Initialize the RX context memory. */
3993 /****************************************************************************/
3995 bce_init_rx_context(struct bce_softc *sc)
3999 /* Initialize the context ID for an L2 RX chain. */
4000 val = BCE_L2CTX_RX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
4001 BCE_L2CTX_RX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
4004 * Set the level for generating pause frames
4005 * when the number of available rx_bd's gets
4006 * too low (the low watermark) and the level
4007 * when pause frames can be stopped (the high
4010 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4011 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4012 uint32_t lo_water, hi_water;
4014 lo_water = BCE_L2CTX_RX_LO_WATER_MARK_DEFAULT;
4015 hi_water = USABLE_RX_BD / 4;
4017 lo_water /= BCE_L2CTX_RX_LO_WATER_MARK_SCALE;
4018 hi_water /= BCE_L2CTX_RX_HI_WATER_MARK_SCALE;
4022 else if (hi_water == 0)
4025 (hi_water << BCE_L2CTX_RX_HI_WATER_MARK_SHIFT);
4028 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_CTX_TYPE, val);
4030 /* Setup the MQ BIN mapping for l2_ctx_host_bseq. */
4031 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4032 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4033 val = REG_RD(sc, BCE_MQ_MAP_L2_5);
4034 REG_WR(sc, BCE_MQ_MAP_L2_5, val | BCE_MQ_MAP_L2_5_ARM);
4037 /* Point the hardware to the first page in the chain. */
4038 val = BCE_ADDR_HI(sc->rx_bd_chain_paddr[0]);
4039 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_HI, val);
4040 val = BCE_ADDR_LO(sc->rx_bd_chain_paddr[0]);
4041 CTX_WR(sc, GET_CID_ADDR(RX_CID), BCE_L2CTX_RX_NX_BDHADDR_LO, val);
4045 /****************************************************************************/
4046 /* Allocate memory and initialize the RX data structures. */
4049 /* 0 for success, positive value for failure. */
4050 /****************************************************************************/
4052 bce_init_rx_chain(struct bce_softc *sc)
4056 uint16_t prod, chain_prod;
4059 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4061 /* Initialize the RX producer and consumer indices. */
4064 sc->rx_prod_bseq = 0;
4065 sc->free_rx_bd = USABLE_RX_BD;
4066 sc->max_rx_bd = USABLE_RX_BD;
4067 DBRUNIF(1, sc->rx_low_watermark = USABLE_RX_BD);
4068 DBRUNIF(1, sc->rx_empty_count = 0);
4070 /* Initialize the RX next pointer chain entries. */
4071 for (i = 0; i < RX_PAGES; i++) {
4074 rxbd = &sc->rx_bd_chain[i][USABLE_RX_BD_PER_PAGE];
4076 /* Check if we've reached the last page. */
4077 if (i == (RX_PAGES - 1))
4082 /* Setup the chain page pointers. */
4083 rxbd->rx_bd_haddr_hi =
4084 htole32(BCE_ADDR_HI(sc->rx_bd_chain_paddr[j]));
4085 rxbd->rx_bd_haddr_lo =
4086 htole32(BCE_ADDR_LO(sc->rx_bd_chain_paddr[j]));
4089 /* Allocate mbuf clusters for the rx_bd chain. */
4090 prod = prod_bseq = 0;
4091 while (prod < TOTAL_RX_BD) {
4092 chain_prod = RX_CHAIN_IDX(prod);
4093 if (bce_newbuf_std(sc, &prod, &chain_prod, &prod_bseq, 1)) {
4094 if_printf(&sc->arpcom.ac_if,
4095 "Error filling RX chain: rx_bd[0x%04X]!\n",
4100 prod = NEXT_RX_BD(prod);
4103 /* Save the RX chain producer index. */
4105 sc->rx_prod_bseq = prod_bseq;
4107 /* Tell the chip about the waiting rx_bd's. */
4108 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4110 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4113 bce_init_rx_context(sc);
4119 /****************************************************************************/
4120 /* Free memory and clear the RX data structures. */
4124 /****************************************************************************/
4126 bce_free_rx_chain(struct bce_softc *sc)
4130 DBPRINT(sc, BCE_VERBOSE_RESET, "Entering %s()\n", __func__);
4132 /* Free any mbufs still in the RX mbuf chain. */
4133 for (i = 0; i < TOTAL_RX_BD; i++) {
4134 if (sc->rx_mbuf_ptr[i] != NULL) {
4135 bus_dmamap_unload(sc->rx_mbuf_tag, sc->rx_mbuf_map[i]);
4136 m_freem(sc->rx_mbuf_ptr[i]);
4137 sc->rx_mbuf_ptr[i] = NULL;
4138 DBRUNIF(1, sc->rx_mbuf_alloc--);
4142 /* Clear each RX chain page. */
4143 for (i = 0; i < RX_PAGES; i++)
4144 bzero(sc->rx_bd_chain[i], BCE_RX_CHAIN_PAGE_SZ);
4146 /* Check if we lost any mbufs in the process. */
4147 DBRUNIF((sc->rx_mbuf_alloc),
4148 if_printf(&sc->arpcom.ac_if,
4149 "%s(%d): Memory leak! "
4150 "Lost %d mbufs from rx chain!\n",
4151 __FILE__, __LINE__, sc->rx_mbuf_alloc));
4153 DBPRINT(sc, BCE_VERBOSE_RESET, "Exiting %s()\n", __func__);
4157 /****************************************************************************/
4158 /* Set media options. */
4161 /* 0 for success, positive value for failure. */
4162 /****************************************************************************/
4164 bce_ifmedia_upd(struct ifnet *ifp)
4166 struct bce_softc *sc = ifp->if_softc;
4167 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4170 * 'mii' will be NULL, when this function is called on following
4171 * code path: bce_attach() -> bce_mgmt_init()
4174 /* Make sure the MII bus has been enumerated. */
4176 if (mii->mii_instance) {
4177 struct mii_softc *miisc;
4179 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
4180 mii_phy_reset(miisc);
4188 /****************************************************************************/
4189 /* Reports current media status. */
4193 /****************************************************************************/
4195 bce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
4197 struct bce_softc *sc = ifp->if_softc;
4198 struct mii_data *mii = device_get_softc(sc->bce_miibus);
4201 ifmr->ifm_active = mii->mii_media_active;
4202 ifmr->ifm_status = mii->mii_media_status;
4206 /****************************************************************************/
4207 /* Handles PHY generated interrupt events. */
4211 /****************************************************************************/
4213 bce_phy_intr(struct bce_softc *sc)
4215 uint32_t new_link_state, old_link_state;
4216 struct ifnet *ifp = &sc->arpcom.ac_if;
4218 ASSERT_SERIALIZED(ifp->if_serializer);
4220 new_link_state = sc->status_block->status_attn_bits &
4221 STATUS_ATTN_BITS_LINK_STATE;
4222 old_link_state = sc->status_block->status_attn_bits_ack &
4223 STATUS_ATTN_BITS_LINK_STATE;
4225 /* Handle any changes if the link state has changed. */
4226 if (new_link_state != old_link_state) { /* XXX redundant? */
4227 DBRUN(BCE_VERBOSE_INTR, bce_dump_status_block(sc));
4229 /* Update the status_attn_bits_ack field in the status block. */
4230 if (new_link_state) {
4231 REG_WR(sc, BCE_PCICFG_STATUS_BIT_SET_CMD,
4232 STATUS_ATTN_BITS_LINK_STATE);
4234 if_printf(ifp, "Link is now UP.\n");
4236 REG_WR(sc, BCE_PCICFG_STATUS_BIT_CLEAR_CMD,
4237 STATUS_ATTN_BITS_LINK_STATE);
4239 if_printf(ifp, "Link is now DOWN.\n");
4243 * Assume link is down and allow tick routine to
4244 * update the state based on the actual media state.
4247 callout_stop(&sc->bce_tick_callout);
4248 bce_tick_serialized(sc);
4251 /* Acknowledge the link change interrupt. */
4252 REG_WR(sc, BCE_EMAC_STATUS, BCE_EMAC_STATUS_LINK_CHANGE);
4256 /****************************************************************************/
4257 /* Reads the receive consumer value from the status block (skipping over */
4258 /* chain page pointer if necessary). */
4262 /****************************************************************************/
4263 static __inline uint16_t
4264 bce_get_hw_rx_cons(struct bce_softc *sc)
4266 uint16_t hw_cons = sc->status_block->status_rx_quick_consumer_index0;
4268 if ((hw_cons & USABLE_RX_BD_PER_PAGE) == USABLE_RX_BD_PER_PAGE)
4274 /****************************************************************************/
4275 /* Handles received frame interrupt events. */
4279 /****************************************************************************/
4281 bce_rx_intr(struct bce_softc *sc, int count)
4283 struct ifnet *ifp = &sc->arpcom.ac_if;
4284 uint16_t hw_cons, sw_cons, sw_chain_cons, sw_prod, sw_chain_prod;
4285 uint32_t sw_prod_bseq;
4286 struct mbuf_chain chain[MAXCPU];
4288 ASSERT_SERIALIZED(ifp->if_serializer);
4290 ether_input_chain_init(chain);
4292 DBRUNIF(1, sc->rx_interrupts++);
4294 /* Get the hardware's view of the RX consumer index. */
4295 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4297 /* Get working copies of the driver's view of the RX indices. */
4298 sw_cons = sc->rx_cons;
4299 sw_prod = sc->rx_prod;
4300 sw_prod_bseq = sc->rx_prod_bseq;
4302 DBPRINT(sc, BCE_INFO_RECV, "%s(enter): sw_prod = 0x%04X, "
4303 "sw_cons = 0x%04X, sw_prod_bseq = 0x%08X\n",
4304 __func__, sw_prod, sw_cons, sw_prod_bseq);
4306 /* Prevent speculative reads from getting ahead of the status block. */
4307 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4308 BUS_SPACE_BARRIER_READ);
4310 /* Update some debug statistics counters */
4311 DBRUNIF((sc->free_rx_bd < sc->rx_low_watermark),
4312 sc->rx_low_watermark = sc->free_rx_bd);
4313 DBRUNIF((sc->free_rx_bd == 0), sc->rx_empty_count++);
4315 /* Scan through the receive chain as long as there is work to do. */
4316 while (sw_cons != hw_cons) {
4317 struct mbuf *m = NULL;
4318 struct l2_fhdr *l2fhdr = NULL;
4321 uint32_t status = 0;
4323 #ifdef DEVICE_POLLING
4324 if (count >= 0 && count-- == 0) {
4325 sc->hw_rx_cons = sw_cons;
4331 * Convert the producer/consumer indices
4332 * to an actual rx_bd index.
4334 sw_chain_cons = RX_CHAIN_IDX(sw_cons);
4335 sw_chain_prod = RX_CHAIN_IDX(sw_prod);
4337 /* Get the used rx_bd. */
4338 rxbd = &sc->rx_bd_chain[RX_PAGE(sw_chain_cons)]
4339 [RX_IDX(sw_chain_cons)];
4342 DBRUN(BCE_VERBOSE_RECV,
4343 if_printf(ifp, "%s(): ", __func__);
4344 bce_dump_rxbd(sc, sw_chain_cons, rxbd));
4346 /* The mbuf is stored with the last rx_bd entry of a packet. */
4347 if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {
4348 /* Validate that this is the last rx_bd. */
4349 DBRUNIF((!(rxbd->rx_bd_flags & RX_BD_FLAGS_END)),
4350 if_printf(ifp, "%s(%d): "
4351 "Unexpected mbuf found in rx_bd[0x%04X]!\n",
4352 __FILE__, __LINE__, sw_chain_cons);
4353 bce_breakpoint(sc));
4355 if (sw_chain_cons != sw_chain_prod) {
4356 if_printf(ifp, "RX cons(%d) != prod(%d), "
4357 "drop!\n", sw_chain_cons,
4361 bce_setup_rxdesc_std(sc, sw_chain_cons,
4364 goto bce_rx_int_next_rx;
4367 /* Unmap the mbuf from DMA space. */
4368 bus_dmamap_sync(sc->rx_mbuf_tag,
4369 sc->rx_mbuf_map[sw_chain_cons],
4370 BUS_DMASYNC_POSTREAD);
4372 /* Save the mbuf from the driver's chain. */
4373 m = sc->rx_mbuf_ptr[sw_chain_cons];
4376 * Frames received on the NetXteme II are prepended
4377 * with an l2_fhdr structure which provides status
4378 * information about the received frame (including
4379 * VLAN tags and checksum info). The frames are also
4380 * automatically adjusted to align the IP header
4381 * (i.e. two null bytes are inserted before the
4382 * Ethernet header). As a result the data DMA'd by
4383 * the controller into the mbuf is as follows:
4385 * +---------+-----+---------------------+-----+
4386 * | l2_fhdr | pad | packet data | FCS |
4387 * +---------+-----+---------------------+-----+
4389 * The l2_fhdr needs to be checked and skipped and the
4390 * FCS needs to be stripped before sending the packet
4393 l2fhdr = mtod(m, struct l2_fhdr *);
4395 len = l2fhdr->l2_fhdr_pkt_len;
4396 status = l2fhdr->l2_fhdr_status;
4398 DBRUNIF(DB_RANDOMTRUE(bce_debug_l2fhdr_status_check),
4400 "Simulating l2_fhdr status error.\n");
4401 status = status | L2_FHDR_ERRORS_PHY_DECODE);
4403 /* Watch for unusual sized frames. */
4404 DBRUNIF((len < BCE_MIN_MTU ||
4405 len > BCE_MAX_JUMBO_ETHER_MTU_VLAN),
4407 "%s(%d): Unusual frame size found. "
4408 "Min(%d), Actual(%d), Max(%d)\n",
4410 (int)BCE_MIN_MTU, len,
4411 (int)BCE_MAX_JUMBO_ETHER_MTU_VLAN);
4412 bce_dump_mbuf(sc, m);
4413 bce_breakpoint(sc));
4415 len -= ETHER_CRC_LEN;
4417 /* Check the received frame for errors. */
4418 if (status & (L2_FHDR_ERRORS_BAD_CRC |
4419 L2_FHDR_ERRORS_PHY_DECODE |
4420 L2_FHDR_ERRORS_ALIGNMENT |
4421 L2_FHDR_ERRORS_TOO_SHORT |
4422 L2_FHDR_ERRORS_GIANT_FRAME)) {
4424 DBRUNIF(1, sc->l2fhdr_status_errors++);
4426 /* Reuse the mbuf for a new frame. */
4427 bce_setup_rxdesc_std(sc, sw_chain_prod,
4430 goto bce_rx_int_next_rx;
4434 * Get a new mbuf for the rx_bd. If no new
4435 * mbufs are available then reuse the current mbuf,
4436 * log an ierror on the interface, and generate
4437 * an error in the system log.
4439 if (bce_newbuf_std(sc, &sw_prod, &sw_chain_prod,
4440 &sw_prod_bseq, 0)) {
4443 "%s(%d): Failed to allocate new mbuf, "
4444 "incoming frame dropped!\n",
4445 __FILE__, __LINE__));
4449 /* Try and reuse the exisitng mbuf. */
4450 bce_setup_rxdesc_std(sc, sw_chain_prod,
4453 goto bce_rx_int_next_rx;
4457 * Skip over the l2_fhdr when passing
4458 * the data up the stack.
4460 m_adj(m, sizeof(struct l2_fhdr) + ETHER_ALIGN);
4462 m->m_pkthdr.len = m->m_len = len;
4463 m->m_pkthdr.rcvif = ifp;
4465 DBRUN(BCE_VERBOSE_RECV,
4466 struct ether_header *eh;
4467 eh = mtod(m, struct ether_header *);
4468 if_printf(ifp, "%s(): to: %6D, from: %6D, "
4469 "type: 0x%04X\n", __func__,
4470 eh->ether_dhost, ":",
4471 eh->ether_shost, ":",
4472 htons(eh->ether_type)));
4474 /* Validate the checksum if offload enabled. */
4475 if (ifp->if_capenable & IFCAP_RXCSUM) {
4476 /* Check for an IP datagram. */
4477 if (status & L2_FHDR_STATUS_IP_DATAGRAM) {
4478 m->m_pkthdr.csum_flags |=
4481 /* Check if the IP checksum is valid. */
4482 if ((l2fhdr->l2_fhdr_ip_xsum ^
4484 m->m_pkthdr.csum_flags |=
4487 DBPRINT(sc, BCE_WARN_RECV,
4488 "%s(): Invalid IP checksum = 0x%04X!\n",
4489 __func__, l2fhdr->l2_fhdr_ip_xsum);
4493 /* Check for a valid TCP/UDP frame. */
4494 if (status & (L2_FHDR_STATUS_TCP_SEGMENT |
4495 L2_FHDR_STATUS_UDP_DATAGRAM)) {
4497 /* Check for a good TCP/UDP checksum. */
4499 (L2_FHDR_ERRORS_TCP_XSUM |
4500 L2_FHDR_ERRORS_UDP_XSUM)) == 0) {
4501 m->m_pkthdr.csum_data =
4502 l2fhdr->l2_fhdr_tcp_udp_xsum;
4503 m->m_pkthdr.csum_flags |=
4507 DBPRINT(sc, BCE_WARN_RECV,
4508 "%s(): Invalid TCP/UDP checksum = 0x%04X!\n",
4509 __func__, l2fhdr->l2_fhdr_tcp_udp_xsum);
4516 sw_prod = NEXT_RX_BD(sw_prod);
4519 sw_cons = NEXT_RX_BD(sw_cons);
4521 /* If we have a packet, pass it up the stack */
4523 DBPRINT(sc, BCE_VERBOSE_RECV,
4524 "%s(): Passing received frame up.\n", __func__);
4526 if (status & L2_FHDR_STATUS_L2_VLAN_TAG) {
4527 m->m_flags |= M_VLANTAG;
4528 m->m_pkthdr.ether_vlantag =
4529 l2fhdr->l2_fhdr_vlan_tag;
4531 ether_input_chain(ifp, m, NULL, chain);
4533 DBRUNIF(1, sc->rx_mbuf_alloc--);
4537 * If polling(4) is not enabled, refresh hw_cons to see
4538 * whether there's new work.
4540 * If polling(4) is enabled, i.e count >= 0, refreshing
4541 * should not be performed, so that we would not spend
4542 * too much time in RX processing.
4544 if (count < 0 && sw_cons == hw_cons)
4545 hw_cons = sc->hw_rx_cons = bce_get_hw_rx_cons(sc);
4548 * Prevent speculative reads from getting ahead
4549 * of the status block.
4551 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4552 BUS_SPACE_BARRIER_READ);
4555 ether_input_dispatch(chain);
4557 sc->rx_cons = sw_cons;
4558 sc->rx_prod = sw_prod;
4559 sc->rx_prod_bseq = sw_prod_bseq;
4561 REG_WR16(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BDIDX,
4563 REG_WR(sc, MB_GET_CID_ADDR(RX_CID) + BCE_L2MQ_RX_HOST_BSEQ,
4566 DBPRINT(sc, BCE_INFO_RECV, "%s(exit): rx_prod = 0x%04X, "
4567 "rx_cons = 0x%04X, rx_prod_bseq = 0x%08X\n",
4568 __func__, sc->rx_prod, sc->rx_cons, sc->rx_prod_bseq);
4572 /****************************************************************************/
4573 /* Reads the transmit consumer value from the status block (skipping over */
4574 /* chain page pointer if necessary). */
4578 /****************************************************************************/
4579 static __inline uint16_t
4580 bce_get_hw_tx_cons(struct bce_softc *sc)
4582 uint16_t hw_cons = sc->status_block->status_tx_quick_consumer_index0;
4584 if ((hw_cons & USABLE_TX_BD_PER_PAGE) == USABLE_TX_BD_PER_PAGE)
4590 /****************************************************************************/
4591 /* Handles transmit completion interrupt events. */
4595 /****************************************************************************/
4597 bce_tx_intr(struct bce_softc *sc)
4599 struct ifnet *ifp = &sc->arpcom.ac_if;
4600 uint16_t hw_tx_cons, sw_tx_cons, sw_tx_chain_cons;
4602 ASSERT_SERIALIZED(ifp->if_serializer);
4604 DBRUNIF(1, sc->tx_interrupts++);
4606 /* Get the hardware's view of the TX consumer index. */
4607 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4608 sw_tx_cons = sc->tx_cons;
4610 /* Prevent speculative reads from getting ahead of the status block. */
4611 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4612 BUS_SPACE_BARRIER_READ);
4614 /* Cycle through any completed TX chain page entries. */
4615 while (sw_tx_cons != hw_tx_cons) {
4617 struct tx_bd *txbd = NULL;
4619 sw_tx_chain_cons = TX_CHAIN_IDX(sw_tx_cons);
4621 DBPRINT(sc, BCE_INFO_SEND,
4622 "%s(): hw_tx_cons = 0x%04X, sw_tx_cons = 0x%04X, "
4623 "sw_tx_chain_cons = 0x%04X\n",
4624 __func__, hw_tx_cons, sw_tx_cons, sw_tx_chain_cons);
4626 DBRUNIF((sw_tx_chain_cons > MAX_TX_BD),
4627 if_printf(ifp, "%s(%d): "
4628 "TX chain consumer out of range! "
4629 " 0x%04X > 0x%04X\n",
4630 __FILE__, __LINE__, sw_tx_chain_cons,
4632 bce_breakpoint(sc));
4634 DBRUNIF(1, txbd = &sc->tx_bd_chain[TX_PAGE(sw_tx_chain_cons)]
4635 [TX_IDX(sw_tx_chain_cons)]);
4637 DBRUNIF((txbd == NULL),
4638 if_printf(ifp, "%s(%d): "
4639 "Unexpected NULL tx_bd[0x%04X]!\n",
4640 __FILE__, __LINE__, sw_tx_chain_cons);
4641 bce_breakpoint(sc));
4643 DBRUN(BCE_INFO_SEND,
4644 if_printf(ifp, "%s(): ", __func__);
4645 bce_dump_txbd(sc, sw_tx_chain_cons, txbd));
4648 * Free the associated mbuf. Remember
4649 * that only the last tx_bd of a packet
4650 * has an mbuf pointer and DMA map.
4652 if (sc->tx_mbuf_ptr[sw_tx_chain_cons] != NULL) {
4653 /* Validate that this is the last tx_bd. */
4654 DBRUNIF((!(txbd->tx_bd_flags & TX_BD_FLAGS_END)),
4655 if_printf(ifp, "%s(%d): "
4656 "tx_bd END flag not set but "
4657 "txmbuf == NULL!\n", __FILE__, __LINE__);
4658 bce_breakpoint(sc));
4660 DBRUN(BCE_INFO_SEND,
4661 if_printf(ifp, "%s(): Unloading map/freeing mbuf "
4662 "from tx_bd[0x%04X]\n", __func__,
4665 /* Unmap the mbuf. */
4666 bus_dmamap_unload(sc->tx_mbuf_tag,
4667 sc->tx_mbuf_map[sw_tx_chain_cons]);
4669 /* Free the mbuf. */
4670 m_freem(sc->tx_mbuf_ptr[sw_tx_chain_cons]);
4671 sc->tx_mbuf_ptr[sw_tx_chain_cons] = NULL;
4672 DBRUNIF(1, sc->tx_mbuf_alloc--);
4678 sw_tx_cons = NEXT_TX_BD(sw_tx_cons);
4680 if (sw_tx_cons == hw_tx_cons) {
4681 /* Refresh hw_cons to see if there's new work. */
4682 hw_tx_cons = sc->hw_tx_cons = bce_get_hw_tx_cons(sc);
4686 * Prevent speculative reads from getting
4687 * ahead of the status block.
4689 bus_space_barrier(sc->bce_btag, sc->bce_bhandle, 0, 0,
4690 BUS_SPACE_BARRIER_READ);
4693 if (sc->used_tx_bd == 0) {
4694 /* Clear the TX timeout timer. */
4698 /* Clear the tx hardware queue full flag. */
4699 if (sc->max_tx_bd - sc->used_tx_bd >= BCE_TX_SPARE_SPACE) {
4700 DBRUNIF((ifp->if_flags & IFF_OACTIVE),
4701 DBPRINT(sc, BCE_WARN_SEND,
4702 "%s(): Open TX chain! %d/%d (used/total)\n",
4703 __func__, sc->used_tx_bd, sc->max_tx_bd));
4704 ifp->if_flags &= ~IFF_OACTIVE;
4706 sc->tx_cons = sw_tx_cons;
4710 /****************************************************************************/
4711 /* Disables interrupt generation. */
4715 /****************************************************************************/
4717 bce_disable_intr(struct bce_softc *sc)
4719 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD, BCE_PCICFG_INT_ACK_CMD_MASK_INT);
4720 REG_RD(sc, BCE_PCICFG_INT_ACK_CMD);
4721 lwkt_serialize_handler_disable(sc->arpcom.ac_if.if_serializer);
4725 /****************************************************************************/
4726 /* Enables interrupt generation. */
4730 /****************************************************************************/
4732 bce_enable_intr(struct bce_softc *sc, int coal_now)
4734 lwkt_serialize_handler_enable(sc->arpcom.ac_if.if_serializer);
4736 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4737 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID |
4738 BCE_PCICFG_INT_ACK_CMD_MASK_INT | sc->last_status_idx);
4740 REG_WR(sc, BCE_PCICFG_INT_ACK_CMD,
4741 BCE_PCICFG_INT_ACK_CMD_INDEX_VALID | sc->last_status_idx);
4744 REG_WR(sc, BCE_HC_COMMAND,
4745 sc->hc_command | BCE_HC_COMMAND_COAL_NOW);
4750 /****************************************************************************/
4751 /* Handles controller initialization. */
4755 /****************************************************************************/
4759 struct bce_softc *sc = xsc;
4760 struct ifnet *ifp = &sc->arpcom.ac_if;
4764 ASSERT_SERIALIZED(ifp->if_serializer);
4766 /* Check if the driver is still running and bail out if it is. */
4767 if (ifp->if_flags & IFF_RUNNING)
4772 error = bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
4774 if_printf(ifp, "Controller reset failed!\n");
4778 error = bce_chipinit(sc);
4780 if_printf(ifp, "Controller initialization failed!\n");
4784 error = bce_blockinit(sc);
4786 if_printf(ifp, "Block initialization failed!\n");
4790 /* Load our MAC address. */
4791 bcopy(IF_LLADDR(ifp), sc->eaddr, ETHER_ADDR_LEN);
4792 bce_set_mac_addr(sc);
4794 /* Calculate and program the Ethernet MTU size. */
4795 ether_mtu = ETHER_HDR_LEN + EVL_ENCAPLEN + ifp->if_mtu + ETHER_CRC_LEN;
4797 DBPRINT(sc, BCE_INFO, "%s(): setting mtu = %d\n", __func__, ether_mtu);
4800 * Program the mtu, enabling jumbo frame
4801 * support if necessary. Also set the mbuf
4802 * allocation count for RX frames.
4804 if (ether_mtu > ETHER_MAX_LEN + EVL_ENCAPLEN) {
4806 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE,
4807 min(ether_mtu, BCE_MAX_JUMBO_ETHER_MTU) |
4808 BCE_EMAC_RX_MTU_SIZE_JUMBO_ENA);
4809 sc->mbuf_alloc_size = MJUM9BYTES;
4811 panic("jumbo buffer is not supported yet\n");
4814 REG_WR(sc, BCE_EMAC_RX_MTU_SIZE, ether_mtu);
4815 sc->mbuf_alloc_size = MCLBYTES;
4818 /* Calculate the RX Ethernet frame size for rx_bd's. */
4819 sc->max_frame_size = sizeof(struct l2_fhdr) + 2 + ether_mtu + 8;
4821 DBPRINT(sc, BCE_INFO,
4822 "%s(): mclbytes = %d, mbuf_alloc_size = %d, "
4823 "max_frame_size = %d\n",
4824 __func__, (int)MCLBYTES, sc->mbuf_alloc_size,
4825 sc->max_frame_size);
4827 /* Program appropriate promiscuous/multicast filtering. */
4828 bce_set_rx_mode(sc);
4830 /* Init RX buffer descriptor chain. */
4831 bce_init_rx_chain(sc); /* XXX return value */
4833 /* Init TX buffer descriptor chain. */
4834 bce_init_tx_chain(sc); /* XXX return value */
4836 #ifdef DEVICE_POLLING
4837 /* Disable interrupts if we are polling. */
4838 if (ifp->if_flags & IFF_POLLING) {
4839 bce_disable_intr(sc);
4841 REG_WR(sc, BCE_HC_RX_QUICK_CONS_TRIP,
4842 (1 << 16) | sc->bce_rx_quick_cons_trip);
4843 REG_WR(sc, BCE_HC_TX_QUICK_CONS_TRIP,
4844 (1 << 16) | sc->bce_tx_quick_cons_trip);
4847 /* Enable host interrupts. */
4848 bce_enable_intr(sc, 1);
4850 bce_ifmedia_upd(ifp);
4852 ifp->if_flags |= IFF_RUNNING;
4853 ifp->if_flags &= ~IFF_OACTIVE;
4855 callout_reset(&sc->bce_tick_callout, hz, bce_tick, sc);
4862 /****************************************************************************/
4863 /* Initialize the controller just enough so that any management firmware */
4864 /* running on the device will continue to operate corectly. */
4868 /****************************************************************************/
4870 bce_mgmt_init(struct bce_softc *sc)
4872 struct ifnet *ifp = &sc->arpcom.ac_if;
4874 /* Bail out if management firmware is not running. */
4875 if (!(sc->bce_flags & BCE_MFW_ENABLE_FLAG))
4878 /* Enable all critical blocks in the MAC. */
4879 if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
4880 BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5716) {
4881 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS,
4882 BCE_MISC_ENABLE_DEFAULT_XI);
4884 REG_WR(sc, BCE_MISC_ENABLE_SET_BITS, BCE_MISC_ENABLE_DEFAULT);
4886 REG_RD(sc, BCE_MISC_ENABLE_SET_BITS);
4889 bce_ifmedia_upd(ifp);
4893 /****************************************************************************/
4894 /* Encapsultes an mbuf cluster into the tx_bd chain structure and makes the */
4895 /* memory visible to the controller. */
4898 /* 0 for success, positive value for failure. */
4899 /****************************************************************************/
4901 bce_encap(struct bce_softc *sc, struct mbuf **m_head)
4903 bus_dma_segment_t segs[BCE_MAX_SEGMENTS];
4904 bus_dmamap_t map, tmp_map;
4905 struct mbuf *m0 = *m_head;
4906 struct tx_bd *txbd = NULL;
4907 uint16_t vlan_tag = 0, flags = 0;
4908 uint16_t chain_prod, chain_prod_start, prod;
4910 int i, error, maxsegs, nsegs;
4912 uint16_t debug_prod;
4915 /* Transfer any checksum offload flags to the bd. */
4916 if (m0->m_pkthdr.csum_flags) {
4917 if (m0->m_pkthdr.csum_flags & CSUM_IP)
4918 flags |= TX_BD_FLAGS_IP_CKSUM;
4919 if (m0->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
4920 flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
4923 /* Transfer any VLAN tags to the bd. */
4924 if (m0->m_flags & M_VLANTAG) {
4925 flags |= TX_BD_FLAGS_VLAN_TAG;
4926 vlan_tag = m0->m_pkthdr.ether_vlantag;
4930 chain_prod_start = chain_prod = TX_CHAIN_IDX(prod);
4932 /* Map the mbuf into DMAable memory. */
4933 map = sc->tx_mbuf_map[chain_prod_start];
4935 maxsegs = sc->max_tx_bd - sc->used_tx_bd;
4936 KASSERT(maxsegs >= BCE_TX_SPARE_SPACE,
4937 ("not enough segements %d\n", maxsegs));
4938 if (maxsegs > BCE_MAX_SEGMENTS)
4939 maxsegs = BCE_MAX_SEGMENTS;
4941 /* Map the mbuf into our DMA address space. */
4942 error = bus_dmamap_load_mbuf_defrag(sc->tx_mbuf_tag, map, m_head,
4943 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
4946 bus_dmamap_sync(sc->tx_mbuf_tag, map, BUS_DMASYNC_PREWRITE);
4951 /* prod points to an empty tx_bd at this point. */
4952 prod_bseq = sc->tx_prod_bseq;
4955 debug_prod = chain_prod;
4958 DBPRINT(sc, BCE_INFO_SEND,
4959 "%s(): Start: prod = 0x%04X, chain_prod = %04X, "
4960 "prod_bseq = 0x%08X\n",
4961 __func__, prod, chain_prod, prod_bseq);
4964 * Cycle through each mbuf segment that makes up
4965 * the outgoing frame, gathering the mapping info
4966 * for that segment and creating a tx_bd to for
4969 for (i = 0; i < nsegs; i++) {
4970 chain_prod = TX_CHAIN_IDX(prod);
4971 txbd= &sc->tx_bd_chain[TX_PAGE(chain_prod)][TX_IDX(chain_prod)];
4973 txbd->tx_bd_haddr_lo = htole32(BCE_ADDR_LO(segs[i].ds_addr));
4974 txbd->tx_bd_haddr_hi = htole32(BCE_ADDR_HI(segs[i].ds_addr));
4975 txbd->tx_bd_mss_nbytes = htole16(segs[i].ds_len);
4976 txbd->tx_bd_vlan_tag = htole16(vlan_tag);
4977 txbd->tx_bd_flags = htole16(flags);
4978 prod_bseq += segs[i].ds_len;
4980 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_START);
4981 prod = NEXT_TX_BD(prod);
4984 /* Set the END flag on the last TX buffer descriptor. */
4985 txbd->tx_bd_flags |= htole16(TX_BD_FLAGS_END);
4987 DBRUN(BCE_EXCESSIVE_SEND,
4988 bce_dump_tx_chain(sc, debug_prod, nsegs));
4990 DBPRINT(sc, BCE_INFO_SEND,
4991 "%s(): End: prod = 0x%04X, chain_prod = %04X, "
4992 "prod_bseq = 0x%08X\n",
4993 __func__, prod, chain_prod, prod_bseq);
4996 * Ensure that the mbuf pointer for this transmission
4997 * is placed at the array index of the last
4998 * descriptor in this chain. This is done
4999 * because a single map is used for all
5000 * segments of the mbuf and we don't want to
5001 * unload the map before all of the segments
5004 sc->tx_mbuf_ptr[chain_prod] = m0;
5006 tmp_map = sc->tx_mbuf_map[chain_prod];
5007 sc->tx_mbuf_map[chain_prod] = map;
5008 sc->tx_mbuf_map[chain_prod_start] = tmp_map;
5010 sc->used_tx_bd += nsegs;
5012 /* Update some debug statistic counters */
5013 DBRUNIF((sc->used_tx_bd > sc->tx_hi_watermark),
5014 sc->tx_hi_watermark = sc->used_tx_bd);
5015 DBRUNIF((sc->used_tx_bd == sc->max_tx_bd), sc->tx_full_count++);
5016 DBRUNIF(1, sc->tx_mbuf_alloc++);
5018 DBRUN(BCE_VERBOSE_SEND,
5019 bce_dump_tx_mbuf_chain(sc, chain_prod, nsegs));
5021 /* prod points to the next free tx_bd at this point. */
5023 sc->tx_prod_bseq = prod_bseq;
5033 /****************************************************************************/
5034 /* Main transmit routine when called from another routine with a lock. */
5038 /****************************************************************************/
5040 bce_start(struct ifnet *ifp)
5042 struct bce_softc *sc = ifp->if_softc;
5045 ASSERT_SERIALIZED(ifp->if_serializer);
5047 /* If there's no link or the transmit queue is empty then just exit. */
5048 if (!sc->bce_link) {
5049 ifq_purge(&ifp->if_snd);
5053 if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
5056 DBPRINT(sc, BCE_INFO_SEND,
5057 "%s(): Start: tx_prod = 0x%04X, tx_chain_prod = %04zX, "
5058 "tx_prod_bseq = 0x%08X\n",
5060 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
5063 struct mbuf *m_head;
5066 * We keep BCE_TX_SPARE_SPACE entries, so bce_encap() is
5069 if (sc->max_tx_bd - sc->used_tx_bd < BCE_TX_SPARE_SPACE) {
5070 ifp->if_flags |= IFF_OACTIVE;
5074 /* Check for any frames to send. */
5075 m_head = ifq_dequeue(&ifp->if_snd, NULL);
5080 * Pack the data into the transmit ring. If we
5081 * don't have room, place the mbuf back at the
5082 * head of the queue and set the OACTIVE flag
5083 * to wait for the NIC to drain the chain.
5085 if (bce_encap(sc, &m_head)) {
5087 if (sc->used_tx_bd == 0) {
5090 ifp->if_flags |= IFF_OACTIVE;
5097 /* Send a copy of the frame to any BPF listeners. */
5098 ETHER_BPF_MTAP(ifp, m_head);
5102 /* no packets were dequeued */
5103 DBPRINT(sc, BCE_VERBOSE_SEND,
5104 "%s(): No packets were dequeued\n", __func__);
5108 DBPRINT(sc, BCE_INFO_SEND,
5109 "%s(): End: tx_prod = 0x%04X, tx_chain_prod = 0x%04zX, "
5110 "tx_prod_bseq = 0x%08X\n",
5112 sc->tx_prod, TX_CHAIN_IDX(sc->tx_prod), sc->tx_prod_bseq);
5114 REG_WR(sc, BCE_MQ_COMMAND,
5115 REG_RD(sc, BCE_MQ_COMMAND) | BCE_MQ_COMMAND_NO_MAP_ERROR);
5117 /* Start the transmit. */
5118 REG_WR16(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BIDX, sc->tx_prod);
5119 REG_WR(sc, MB_GET_CID_ADDR(TX_CID) + BCE_L2CTX_TX_HOST_BSEQ, sc->tx_prod_bseq);
5121 /* Set the tx timeout. */
5122 ifp->if_timer = BCE_TX_TIMEOUT;
5126 /****************************************************************************/
5127 /* Handles any IOCTL calls from the operating system. */
5130 /* 0 for success, positive value for failure. */
5131 /****************************************************************************/
5133 bce_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
5135 struct bce_softc *sc = ifp->if_softc;
5136 struct ifreq *ifr = (struct ifreq *)data;
5137 struct mii_data *mii;
5138 int mask, error = 0;
5140 ASSERT_SERIALIZED(ifp->if_serializer);
5144 /* Check that the MTU setting is supported. */
5145 if (ifr->ifr_mtu < BCE_MIN_MTU ||
5147 ifr->ifr_mtu > BCE_MAX_JUMBO_MTU
5149 ifr->ifr_mtu > ETHERMTU
5156 DBPRINT(sc, BCE_INFO, "Setting new MTU of %d\n", ifr->ifr_mtu);
5158 ifp->if_mtu = ifr->ifr_mtu;
5159 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5164 if (ifp->if_flags & IFF_UP) {
5165 if (ifp->if_flags & IFF_RUNNING) {
5166 mask = ifp->if_flags ^ sc->bce_if_flags;
5168 if (mask & (IFF_PROMISC | IFF_ALLMULTI))
5169 bce_set_rx_mode(sc);
5173 } else if (ifp->if_flags & IFF_RUNNING) {
5176 /* If MFW is running, restart the controller a bit. */
5177 if (sc->bce_flags & BCE_MFW_ENABLE_FLAG) {
5178 bce_reset(sc, BCE_DRV_MSG_CODE_RESET);
5183 sc->bce_if_flags = ifp->if_flags;
5188 if (ifp->if_flags & IFF_RUNNING)
5189 bce_set_rx_mode(sc);
5194 DBPRINT(sc, BCE_VERBOSE, "bce_phy_flags = 0x%08X\n",
5196 DBPRINT(sc, BCE_VERBOSE, "Copper media set/get\n");
5198 mii = device_get_softc(sc->bce_miibus);
5199 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
5203 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
5204 DBPRINT(sc, BCE_INFO, "Received SIOCSIFCAP = 0x%08X\n",
5207 if (mask & IFCAP_HWCSUM) {
5208 ifp->if_capenable ^= (mask & IFCAP_HWCSUM);
5209 if (IFCAP_HWCSUM & ifp->if_capenable)
5210 ifp->if_hwassist = BCE_IF_HWASSIST;
5212 ifp->if_hwassist = 0;
5217 error = ether_ioctl(ifp, command, data);
5224 /****************************************************************************/
5225 /* Transmit timeout handler. */
5229 /****************************************************************************/
5231 bce_watchdog(struct ifnet *ifp)
5233 struct bce_softc *sc = ifp->if_softc;
5235 ASSERT_SERIALIZED(ifp->if_serializer);
5237 DBRUN(BCE_VERBOSE_SEND,
5238 bce_dump_driver_state(sc);
5239 bce_dump_status_block(sc));
5242 * If we are in this routine because of pause frames, then
5243 * don't reset the hardware.
5245 if (REG_RD(sc, BCE_EMAC_TX_STATUS) & BCE_EMAC_TX_STATUS_XOFFED)
5248 if_printf(ifp, "Watchdog timeout occurred, resetting!\n");
5250 /* DBRUN(BCE_FATAL, bce_breakpoint(sc)); */
5252 ifp->if_flags &= ~IFF_RUNNING; /* Force reinitialize */
5257 if (!ifq_is_empty(&ifp->if_snd))
5262 #ifdef DEVICE_POLLING
5265 bce_poll(struct ifnet&